A method, device, equipment, medium and product for rendering an image in a document
By calculating the font size ratio of the text in the document and adjusting the image size to make it consistent with the text of the document, the problem of unclear or wasted space during image rendering is solved, and the reading experience is improved.
Patent Information
- Application Number
- CN202411952558.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-27
- Publication Date
- 2025-04-08
AI Technical Summary
In the prior art, when an image is rendered in a document, the fixed size causes the image content to be unclear or waste space, affecting the reading experience.
By obtaining the font information of the first text in the document and the font information of the second text in the target image, the ratio between them is calculated, and the image size of the target image is adjusted, so that the font size of the second text is consistent with the font size of the first text, thereby rendering the adjusted target image in the document.
It improves the conformity between image size and document layout, improves the user's reading experience, and makes the image content clear and no waste of space.
Smart Images

Figure CN119784918A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of image processing technology, and in particular to a method, device, equipment, medium and product for rendering an image in a document. Background Art
[0002] With the rapid development of network technology, online teaching has gradually been applied to teachers' teaching tasks. In the process of online teaching, in order to test students' mastery of knowledge, teachers need to assign homework to students online. Usually, teachers will render the existing questions in the question bank into a document, and then send the document with the rendered questions to students so that students can do their homework.
[0003] Currently, when the image in the title is rendered in the document, it is usually loaded in a static fixed size. If the image size of the loaded image is too small, the image content cannot be guaranteed to be clear and intuitive. If the image size of the loaded image is too large, the document layout space will be wasted, affecting the reading experience of the document reader.
[0004] Based on this, how to improve the consistency between image size and document layout, and thus improve the reading experience of document readers, has become a technical problem that needs to be solved urgently. Summary of the invention In view of this, an embodiment of the present specification provides a method for rendering an image in a document. One or more embodiments of the present specification also relate to an apparatus for rendering an image in a document, a computing device, a computer-readable storage medium, and a computer program product to solve the technical defects existing in the prior art.
[0005] According to a first aspect of an embodiment of this specification, a method for rendering an image in a document is provided, comprising: Get the first font information of the first word in the document; Determine whether the second text exists in the target image to be rendered, and obtain a first determination result; If the first judgment result indicates that the second character exists in the target image, obtaining second font information of the second character in the target image; Determining a ratio between a font size of the first character and a font size of the second character according to the first font information and the second font information; According to the ratio, the image size of the target image is adjusted to obtain an adjusted target image; the font size of the second text in the adjusted target image is consistent with the font size of the first text; The adjusted target image is rendered in the document.
[0006] According to a second aspect of an embodiment of this specification, there is provided a device for rendering an image in a document, comprising: A first acquisition module is configured to acquire first font information of a first word in a document; A judgment module is configured to judge whether there is a second text in the target image to be rendered, and obtain a first judgment result; a second acquisition module, configured to acquire second font information of the second character in the target image if the first judgment result indicates that the second character exists in the target image; a determination module, configured to determine a ratio between a font size of the first character and a font size of the second character according to the first font information and the second font information; an adjustment module, configured to adjust the image size of the target image according to the ratio to obtain an adjusted target image; the font size of the second text in the adjusted target image is consistent with the font size of the first text; The rendering module is configured to render the adjusted target image in the document.
[0007] According to a third aspect of an embodiment of this specification, a computing device is provided, including: Memory and processor; The memory is used to store computer programs or instructions, and the processor is used to execute the computer programs or instructions. When the computer programs or instructions are executed by the processor, the steps of the above-mentioned method for rendering an image in a document are implemented.
[0008] According to a fourth aspect of the embodiments of this specification, a computer-readable storage medium is provided, which stores a computer program or instruction, and when the computer program or instruction is executed by a processor, the steps of the above-mentioned method for rendering an image in a document are implemented.
[0009] According to a fifth aspect of the embodiments of this specification, a computer program product is provided, including a computer program or instructions, which, when executed by a processor, implement the steps of the above-mentioned method for rendering an image in a document.
[0010] An embodiment of the present specification realizes adjusting the image size of a target image based on the ratio between the font size of a first text in a document and the font size of a second text in a target image. By adjusting the image size, the font size of the second text in the adjusted target image can be made consistent with the font size of the first text in the document. On the premise that the font size of the second text in the target image is consistent with the font size of the first text in the document, the consistency between the image size of the target image and the document layout can be improved, thereby improving the reading experience of the user when reading the document. BRIEF DESCRIPTION OF THE DRAWINGS Figure 1 is a flowchart of a method for rendering an image in a document provided by an embodiment of the present specification; Figure 2 A schematic diagram of a process of rendering a target image for explaining a question in a document for displaying a question provided by an embodiment of the present specification; Figure 3 It is a structural schematic diagram of a device for rendering an image in a document provided by an embodiment of the present specification; Figure 4 It is a structural block diagram of a computing device provided by an embodiment of this specification. DETAILED DESCRIPTION
[0011] Many specific details are described in the following description to facilitate a full understanding of this specification. However, this specification can be implemented in many other ways than those described herein, and those skilled in the art can make similar generalizations without violating the connotation of this specification, so this specification is not limited to the specific implementation disclosed below.
[0012] The terms used in one or more embodiments of this specification are only for the purpose of describing specific embodiments, and are not intended to limit one or more embodiments of this specification. The singular forms of "a", "said" and "the" used in one or more embodiments of this specification and the appended claims are also intended to include plural forms, unless the context clearly indicates other meanings. It should also be understood that the term "and / or" used in one or more embodiments of this specification refers to and includes any or all possible combinations of one or more associated listed items.
[0013] It should be understood that although the terms first, second, etc. may be used to describe various information in one or more embodiments of this specification, this information should not be limited to these terms. These terms are only used to distinguish the same type of information from each other. For example, without departing from the scope of one or more embodiments of this specification, the first may also be referred to as the second, and similarly, the second may also be referred to as the first. Depending on the context, the word "if" as used herein may be interpreted as "at the time of" or "when" or "in response to determining".
[0014] In addition, it should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in one or more embodiments of this specification are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with the relevant laws, regulations and standards of the relevant countries and regions, and provide corresponding operation entrances for users to choose to authorize or refuse.
[0015] First, the terms involved in one or more embodiments of this specification are explained.
[0016] Optical Character Recognition (OCR) is a technology that converts text images into machine-readable formats. It uses electronic devices, such as scanners or digital cameras, to capture characters printed on paper, and then uses pattern recognition technology to translate the shapes of these characters into computer text. In short, OCR technology can convert text in paper documents into editable and searchable text formats.
[0017] Currently, when loading an image in a document, the image will be loaded at a fixed size. However, due to the different document sizes and font sizes in the document, when the image is loaded at a fixed size, if the fixed size corresponding to the image does not match the size of the document and the font size in the document, the image content will not be displayed clearly, document space will be wasted, and the aesthetic of the document layout will be affected.
[0018] In this specification, a method for rendering an image in a document is provided. This specification also relates to an apparatus for rendering an image in a document, a computing device, and a computer-readable storage medium, which are described in detail one by one in the following embodiments.
[0019] Figure 1 This is a flow chart of a method for rendering an image in a document provided in an embodiment of this specification. From a hardware perspective, the execution subject of the process may be a device for rendering an image in a document, or, from a software perspective, the execution subject of the process may be an application installed on the device for rendering an image in a document.
[0020] like Figure 1 As shown, the process may include the following steps.
[0021] Step 102: Obtain first font information of a first word in the document.
[0022] In the embodiments of this specification, the document may be a document displayed on a display page of a user terminal. The user terminal may be a tablet computer or a mobile phone, etc. The display page may be a display page of a teaching APP installed on the tablet computer or the mobile phone, such as a display page on an online teaching APP for online homework correction or online question practice, and the document may be a set of electronic test papers displayed on the display page, such as a set of Chinese test papers, mathematics test papers, or English test papers.
[0023] In the embodiments of this specification, the first text may be text that already exists in the document, or the first text may be text that is loaded in the document planning, wherein the first text may include any one or more of Chinese characters, English letters, numbers, punctuation marks, special characters, and text corresponding to other countries. The first font information may include the font size of the first text in the document. In actual applications, the first font information may be the font size information of the first text in the document.
[0024] In the embodiments of this specification, the first font information may be the default font information set by the document developer for the document, for example: for a document of A4 paper size, the developer may set the font information of the text displayed in the document to be 16-point font, or other font size, without limitation. Alternatively, the first font information may also be the adjusted font information after the user using the document adjusts the default font information, for example: the font information set by the developer for the document of A4 paper size is 16-point font, and the user using the document may adjust the 16-point font to 20-point font, or other font size, without limitation.
[0025] In actual applications, the first font information of the first character may be font information that has a matching relationship with the document size of the document, wherein the matching relationship is used to reflect that setting the first character as the first font information in the document can conform to the user's reading habits and enhance the user's reading experience. For example, if the document is a document of A4 paper size, the first font information of the first character is set to 16-point font, etc., and if the document is a document of A3 paper size, the first font information of the first character is set to 20-point font, etc., without specific limitation.
[0026] In the embodiments of this specification, the method of obtaining the first font information may include: querying the first font information of the first character from the configuration information corresponding to the document, or identifying the first font information of the first character from the document based on the OCR algorithm, which is not limited to this.
[0027] In practical applications, if it is not possible to directly obtain the first font information of the first character in the document, the first font information of the first character can be obtained through the OCR algorithm. The document is input into the OCR algorithm model, and the model returns the position information (x, y, w, h) of each first character in the format of a rectangular box, where x and y represent the coordinates of the vertex of the upper left corner of the rectangular box in the pixel coordinate system where the document is located, w represents the width value of the rectangular box in the pixel coordinate system, and h represents the height value of the rectangular box in the pixel coordinate system. The height value h is used as the first font information recognized by the model for the first character.
[0028] Step 104: Determine whether there is a second text in the target image to be rendered, and obtain a first determination result.
[0029] In an embodiment of the present specification, the target image to be rendered may be an image in an electronic test paper displayed in a display page for assisting students in answering questions. For example, the electronic test paper is a Chinese test paper, which includes a composition topic requiring students to write an essay based on a picture. The target image to be rendered may be a picture in the composition topic, such as a family photo, a picture of a scenic spot in a park, etc.
[0030] In the embodiments of this specification, it is possible to determine whether the second text exists in the target image to be rendered by using an OCR algorithm, or it is possible to determine whether the second text exists in the target image to be rendered by using other existing technologies, which is not limited to this.
[0031] In practical applications, the target image to be rendered is input into the OCR algorithm model. If the OCR outputs a rectangular frame for reflecting the position information of the text for the target image to be rendered, it means that the second text exists in the target image to be rendered.
[0032] In the embodiments of this specification, the second text may include any one or more of Chinese characters, English letters, numbers, punctuation marks, special characters and corresponding texts of other countries. The first text and the second text may be texts of the same type, or may be texts of different types, without limitation.
[0033] Step 106: If the first judgment result indicates that the second text exists in the target image, obtain second font information of the second text in the target image.
[0034] In the embodiment of the present specification, the second font information of the second text in the image to be rendered can be obtained by an OCR algorithm or other existing technologies. The second font information may include the font size of the second text in the image to be rendered.
[0035] Step 108: Determine a ratio between the font size of the first character and the font size of the second character according to the first font information and the second font information.
[0036] In the embodiments of this specification, the first font information and the second font information may be the same type of font information. In practical applications, the first font information and the second font information may both be font size information corresponding to the text, or the first font information and the second font information may both be pixel height information of the text in a pixel coordinate system, without limitation.
[0037] In an embodiment of the present specification, the ratio between the font size of the first character and the font size of the second character is determined based on the font size information of the first character and the font size information of the second character; or, the ratio between the font size of the first character and the font size of the second character is determined based on the pixel height value information of the first character in the pixel coordinate system and the pixel height value information of the second character in the pixel coordinate system.
[0038] Step 110: adjusting the image size of the target image according to the ratio to obtain an adjusted target image; the font size of the second text in the adjusted target image is consistent with the font size of the first text.
[0039] In an embodiment of the present specification, the ratio between the font size of the first character and the font size of the second character may include: a first quotient calculated with the font size of the first character as the dividend and the font size of the second character as the divisor; and adjusting the image size of the target image according to the first quotient to obtain an adjusted target image.
[0040] In practical applications, the image size of the target image is adjusted according to the first quotient, including: if the first quotient is greater than 1, performing an image size enlargement operation on the target image according to the first quotient; if the first quotient is less than 1, performing an image size reduction operation on the target image according to the first quotient; specifically, multiplying the image size of the target image by the first quotient to obtain an adjusted image size.
[0041] In the embodiment of the present specification, the ratio between the font size of the first character and the font size of the second character may include: A second quotient is calculated with the font size of the second character as the dividend and the font size of the first character as the divisor; and the image size of the target image is adjusted according to the second quotient to obtain an adjusted target image.
[0042] In practical applications, the image size of the target image is adjusted according to the second quotient, including: if the second quotient is greater than 1, performing an image size reduction operation on the target image according to the second quotient; if the second quotient is less than 1, performing an image size enlargement operation on the target image according to the second quotient; specifically, the image size of the target image is divided by the second quotient to obtain the adjusted image size.
[0043] In the embodiments of the present specification, the font size of the second character is consistent with the font size of the first character, which can be understood as the font size of the second character is exactly the same as the font size of the first character; or it can also be understood as the font size difference between the font size of the second character and the font size of the first character is less than or equal to a preset threshold value, for example: if the font size of the second character is 5 pixels in height, the font size of the first character is 6 pixels in height, and the preset threshold is 2 pixels in height, then the font size of the second character is also considered to be consistent with the font size of the first character.
[0044] Step 112: Rendering the adjusted target image in the document.
[0045] In the embodiment of the present specification, image rendering information is generated based on the adjusted image size of the target image, and the image rendering information is used to render the adjusted target image in the document; and the image rendering information is loaded into the document.
[0046] In actual applications, if the font size of the first text in the document is consistent with the font size of the second text in the target image, there is no need to adjust the image size of the target image; based on the image size of the target image, image rendering information is generated; and the rendering information is loaded into the document.
[0047] In the embodiment of the present specification, a document rendered with the target image or the adjusted target image is output. In practical applications, the method of outputting the document may include: displaying the document on a display page of a user terminal; or printing the document.
[0048] It should be understood that the order of some steps in the methods described in one or more embodiments of this specification can be interchanged according to actual needs, or some steps can be omitted or deleted.
[0049] Figure 1 According to the method, the font size of the second text in the target image after adjustment is consistent with the font size of the first font in the document, so as to improve the consistency between the image size of the target image and the document layout, thereby improving the aesthetics of the document layout, and further improving the reading experience of the user when reading the document.
[0050] based on Figure 1 The present specification also provides some improved implementation methods of the method, which are described below.
[0051] In the embodiments of this specification, an embodiment of adjusting the image size is also proposed for an image to be rendered without any text.
[0052] Optionally, if the first judgment result indicates that the second text does not exist in the target image, the image size of the target image is adjusted based on formula (1) to obtain the adjusted target image; H1=h1×t (1); wherein H1 represents the height value of the adjusted target image, h1 represents the pixel value of the first text, t represents the coefficient value, and t>1.
[0053] In practical applications, the target image to be rendered is input into the OCR algorithm model. If the OCR does not output a rectangular frame for reflecting the position information of the text for the target image to be rendered, it means that the second text does not exist in the target image to be rendered.
[0054] In the embodiment of the present specification, when the second text does not exist in the target image to be rendered, the product of the font height value corresponding to the first text and the adjustment coefficient is determined as the image height value of the adjusted target image; the image width value of the adjusted target image is determined according to the ratio between the image height value of the adjusted target image and the image height value of the target image before adjustment, and the image width value of the target image before adjustment. The adjustment coefficient t is greater than 1, for example, t can be 5, or other values, which are not limited.
[0055] In the embodiments of this specification, a specific embodiment of determining the ratio between the font size of the first character and the font size of the second character according to the pixel values of the characters is also proposed.
[0056] Optionally, the step of acquiring first font information of a first character in a document may include: acquiring a first pixel value of the first character in the document; the step of acquiring second font information of the second character in the target image may include: acquiring a second pixel value of the second character in the target image; and the step of determining the ratio between the font size of the first character and the font size of the second character may include: determining the ratio between the first pixel value and the second pixel value.
[0057] In the embodiment of this specification, the first pixel value and the second pixel value may both be pixel values in the same pixel coordinate system.
[0058] In practical applications, if the first pixel value and the second pixel value are not pixel values in the same pixel coordinate system, based on the conversion relationship between the first pixel coordinate system where the document is located and the second pixel coordinate system where the target image is located, the first pixel value is converted to a pixel value in the second pixel coordinate system; or the second pixel value is converted to a pixel value in the first pixel coordinate system. There is no limitation on this.
[0059] In the embodiment of the present specification, the ratio between the font size of the first character and the font size of the second character is calculated based on the first pixel value and the second pixel value in the same pixel coordinate system, so as to improve the accuracy of data calculation.
[0060] In the embodiments of this specification, a specific embodiment of obtaining a first pixel value of a first character in a document is also proposed.
[0061] Optionally, obtaining the first pixel value of the first text in the document may include: determining the first pixel value of the first text in the document based on optical character recognition (OCR) or formula (2); Px=Pt / 72×d(2); wherein Pt represents the font size of the first text, d represents the resolution corresponding to the document, and Px represents the pixel value of the first text in the document.
[0062] In the embodiment of the present specification, after the first character is recognized based on the OCR algorithm model, the h value in the returned position information (x, y, w, h) is determined as the first pixel value of the first character in the document.
[0063] In the embodiment of the present specification, if the font size value of the first character can be queried from the document, the font size value of the first character can be converted into a first pixel value corresponding to the first character based on formula (2).
[0064] In practical applications, the resolution corresponding to the document may be the resolution of the screen where the document is located. For example, if the font size value of the first character in the document is 14-point font, and the resolution of the screen where the document is located is 96 DPI, then the process of calculating the first pixel value includes: converting the font size value of the first character into an inch value, and the specific calculation process is: pt / 72=14 / 72≈0.1944 inches; converting the inch value corresponding to the first character into a pixel value, and the specific calculation process is: inch value×d≈0.1944×96≈18.6624.
[0065] In the embodiments of this specification, a specific embodiment of obtaining a second pixel value of a second text in a target image is also proposed.
[0066] Optionally, based on optical character recognition (OCR), the second pixel value of the second text in the target image is identified.
[0067] In the embodiment of the present specification, after the second character is recognized based on the OCR algorithm model, the h value in the returned position information (x, y, w, h) is determined as the second pixel value of the second character in the target image.
[0068] In the embodiments of this specification, for a scenario where a target image includes second characters in a variety of font sizes, a specific embodiment of determining the ratio between the font size of the first character and the font size of the second character is also proposed.
[0069] Optionally, if the target image contains the second text in multiple font sizes, determining the ratio between the font size of the first text and the font size of the second text may include: selecting a preset font from the second text in the multiple font sizes; the preset font includes any one of a minimum font, a median font or an average font; the average font is an average font calculated for the second text in the multiple font sizes; determining the ratio between the font size of the first text and the font size of the preset font.
[0070] In an embodiment of the present specification, for second characters in multiple font sizes, they are sorted in order of font size from small to large to obtain a first font sequence, and the first font in the first font sequence is determined as the smallest font; or they are sorted in order of font size from large to small to obtain a second font sequence, and the last font in the second font sequence is determined as the smallest font.
[0071] In an embodiment of the present specification, if the number of types corresponding to the multiple font sizes is an odd value, the middle font of the first font sequence or the second font sequence is determined as the median font; if the number of types corresponding to the multiple font sizes is an even value, one of the middle fonts of the first font sequence or the second font sequence is determined as the median font. In order to facilitate the understanding of this solution by those skilled in the art, the first font sequence is taken as an example for explanation. For example, if the number of types corresponding to the multiple font sizes is an odd value, and the first font sequence is 8, 9, 11, 14, 16, the determined median font is 11; for another example, if the number of types corresponding to the multiple font sizes is an even value, and the first font sequence is 8, 9, 11, 14, 16, 18, the determined median font can be any one of 11 and 14.
[0072] In actual application, if the average font calculated for the multiple font sizes is a non-existent font, the font closest to the average font among all the fonts set during document development is determined as the selected preset font; or the font closest to the average font among the multiple font sizes is determined as the selected preset font. For example: all the fonts set during document development include: 5, 6.5, 7, 8, 9, 10, 11, 12, 14, 16, 18, 20, etc., and the types corresponding to the multiple font sizes include: 7, 16, 18, then the average font determined for the multiple font sizes is 13.7, and font 13.7 is a non-existent font, then font 14 determined based on all the fonts set during document development can be determined as the selected preset font; or font 16 determined based on the multiple font sizes can also be determined as the selected preset font.
[0073] Optionally, the preset font may further include a specific font, and the specific font is a font determined according to the average font.
[0074] In actual application, the average font is calculated for the multiple font sizes, and if the average font does not exist in the multiple font sizes, the font closest to the average font in the multiple font sizes is determined as the specific font. This can improve the consistency between the font size of the second text in the adjusted target image and the font size of the first text in the document, and further improve the consistency between the image size of the target image and the document layout, so as to improve the reading experience of the user when reading the document.
[0075] In the embodiment of the present specification, the image size of the target image is adjusted based on the ratio between the font size of the first character and the font size of the preset font to obtain the adjusted target image.
[0076] In order to improve the accuracy of image size adjustment for the target image, a preset font may be selected according to the number of second characters in the target image and / or the degree of difference between different second characters.
[0077] Optionally, the method may further include: determining whether the font size difference between the smallest font and the largest font in the second text is greater than or equal to a first preset threshold, and obtaining a second judgment result; selecting a preset font from each of the second font information may specifically include: if the second judgment result indicates that the font size difference between the smallest font and the largest font in the second text is greater than or equal to the first preset threshold, then selecting the median font or the average font from each of the second font information.
[0078] In an embodiment of the present specification, when the difference in font size between the minimum font and the maximum font in the second text is greater than or equal to the first preset threshold, the median font or the average font in the second text can be used as a preset font for comparison with the font size of the first text, so that after adjusting the image size of the target image based on the ratio between the font size of the first text and the font size of the median font or the average font, compared to using the minimum font as the preset font, it is possible to avoid the disadvantage of too large an adjustment range of the maximum font by reducing the adjustment range of the minimum font, thereby balancing the display effect between the image size and the text in the image.
[0079] In practical applications, the first preset threshold value can be set according to actual needs. For example, the first preset threshold value can be selected as 5, or other values, which are not limited.
[0080] Optionally, the method may further include: determining whether the number of characters corresponding to the second characters is greater than or equal to a second preset threshold, and obtaining a third judgment result; selecting a preset font from each of the second font information may specifically include: if the third judgment result indicates that the number of characters corresponding to the second characters is greater than or equal to the second preset threshold, then selecting the minimum font from each of the second font information.
[0081] In an embodiment of the present specification, when the number of characters corresponding to the second characters is greater than or equal to the second preset threshold, the smallest font in the second characters can be used as a preset font for comparison with the font size of the first characters, so that after adjusting the image size of the target image based on the ratio between the font size of the first characters and the font size of the smallest font, the effect of clearly displaying each second character in the target image can be achieved on the basis of clearly displaying the smallest font.
[0082] In practical applications, the second preset threshold can be set according to actual needs. For example, the second preset threshold can be selected as 10, or other values, which are not limited.
[0083] In actual applications, when selecting a preset font from the second characters of the multiple font sizes, the selection rules for the preset font may not be limited by the number of second characters and / or the degree of difference between different second characters. Reasonable selection can be made based on the actual needs of the user, and there is no limitation on this.
[0084] Optionally, if the document contains the first characters in a plurality of font sizes, determining the ratio between the font size of the first characters and the font size of the second characters may include: A first preset font is selected from the first characters of the plurality of font sizes; the first preset font includes any one of a minimum font, a median font or an average font; the average font is an average font calculated for the first characters of the plurality of font sizes; and a ratio between the font size of the first preset font and the font size of the second character is determined.
[0085] Optionally, if the document includes the first text in multiple font sizes, and the target image includes the second text in multiple font sizes, determining the ratio between the font size of the first text and the font size of the second text may include: Select a second preset font from the first text of the multiple font sizes; select a third preset font from the second text of the multiple font sizes; the second preset font and the third preset font may both include any one of a minimum font, a median font or an average font; determine the ratio between the font size of the second preset font and the font size of the third preset font.
[0086] In the embodiments of this specification, the selection rules for the first preset font, the second preset font, and the third preset font may all refer to the selection rules for the preset fonts, which will not be described in detail herein.
[0087] Optionally, adjusting the image size of the target image according to the ratio to obtain the adjusted target image may include: adjusting the image size of the target image based on formula (3) and formula (4) to obtain the adjusted target image; H2=H3×K (3); wherein H3 represents the image height value of the target image before adjustment, K represents the ratio, and H2 represents the image height value of the target image after adjustment; W1=W2×(H2 / H3) (4); wherein W2 represents the image width value of the target image before adjustment, and W1 represents the image width value of the target image after adjustment.
[0088] In the embodiment of the present specification, the ratio may be a quotient calculated with the font size of the first character as the dividend and the font size of the second character as the divisor. The process of calculating the image height value of the adjusted target image may include: determining the image height value of the adjusted target image based on the product between the image height value of the target image before adjustment and the ratio. The process of calculating the image width value of the adjusted target image may include: calculating a target ratio between the image height value of the target image before adjustment and the image height value of the adjusted target image; and determining the image width value of the adjusted target image based on the product between the image width value of the target image before adjustment and the target ratio.
[0089] Optionally, the document may be a document for displaying a topic, and the target image to be rendered may be a schematic diagram for explaining the topic to a user who reads the topic.
[0090] In order to facilitate technical personnel in this field to understand the present solution, the embodiments of this specification take the document as a document for displaying a question, and the target image as a schematic diagram for explaining the question to a user reading the question as an example, and also propose a specific embodiment of rendering the target image in the document.
[0091] Figure 2 It is a flowchart of rendering a target image for explaining a topic in a document for displaying the topic provided by an embodiment of the present specification. Figure 2 It may include steps 202 to 222 .
[0092] Step 202: Obtain the pixel height value of the first character in the target document for displaying the title in the target document.
[0093] In the embodiment of the present specification, the target document may be an electronic math test paper, the title may be a math word problem in the math test paper for calculating the speed of a train, and the first text may be a text introduction to the math word problem.
[0094] Step 204: Acquire a target image for explaining the topic.
[0095] In the embodiment of the present specification, the target image may be an image of a train running from one end of a bridge to the other end of the bridge, which is used to explain the meaning of the math word problem in step 202 to students.
[0096] Step 206: Determine whether there is a second character in the target image and obtain a determination result.
[0097] Step 208: If the second text does not exist in the target image, then based on the pixel height value of the first text in the target document, determine the adjusted image height value for the target image.
[0098] Step 210: If there is a second character in the target image, obtain the pixel height value of the second character in the target image.
[0099] In the embodiment of the present specification, the pixel height value of the first character in the target document and the pixel height value of the second character in the target image are pixel values in the same pixel coordinate system.
[0100] Step 212: Determine a first ratio between a pixel height value of the first text in the target document and a pixel height value of the second text in the target image.
[0101] Step 214: Determine an adjusted image height value for the target image based on the first ratio.
[0102] Step 216: Determine a second ratio between the image height value of the target image before adjustment and the image height value of the target image after adjustment.
[0103] Step 218: Determine an adjusted image width value for the target image based on the second ratio.
[0104] Step 220: adjusting the image size of the target image according to the adjusted image width value and the adjusted image height value to obtain the adjusted target image.
[0105] Step 222: Rendering the adjusted target image in the target document.
[0106] In the embodiments of this specification, based on Figure 2 The method can adjust the image size of the target image based on the pixel height value of the first word in the target document to improve the consistency between the image size of the target image and the layout of the target document, thereby improving the reading experience of the user when reading the document.
[0107] Corresponding to the above method embodiment, this specification also provides an apparatus embodiment for rendering an image in a document. Figure 3 FIG. 1 is a schematic diagram showing a structure of a device for rendering an image in a document provided by an embodiment of the present specification. Figure 3 As shown, the device may include: The first acquisition module 302 is configured to acquire first font information of a first word in a document.
[0108] The judgment module 304 is configured to judge whether there is a second text in the target image to be rendered, and obtain a first judgment result.
[0109] The second acquisition module 306 is configured to acquire second font information of the second character in the target image if the first judgment result indicates that the second character exists in the target image.
[0110] The determination module 308 is configured to determine a ratio between a font size of the first character and a font size of the second character according to the first font information and the second font information.
[0111] The adjustment module 310 is configured to adjust the image size of the target image according to the ratio to obtain an adjusted target image; the font size of the second text in the adjusted target image is consistent with the font size of the first text.
[0112] The rendering module 312 is configured to render the adjusted target image in the document.
[0113] Optionally, the device may further include: The first adjustment module is configured to adjust the image size of the target image based on formula (1) to obtain the adjusted target image if the first judgment result indicates that the second text does not exist in the target image.
[0114] H1=h1×t(1).
[0115] Among them, H1 represents the height value of the adjusted target image, h1 represents the pixel value of the first text, t represents the coefficient value, and t>1.
[0116] Optionally, the first acquisition module 302 may include: The first acquisition unit is configured to acquire a first pixel value of the first character in the document.
[0117] The second acquisition module 306 may include: The second acquisition unit is configured to acquire a second pixel value of the second text in the target image.
[0118] The determination module 308 may include: The first determining unit is configured to determine a ratio between the first pixel value and the second pixel value.
[0119] Optionally, the first acquiring unit may include: The determination subunit is configured to determine the first pixel value of the first character in the document based on optical character recognition (OCR) or formula (2).
[0120] Px=Pt / 72×d(2).
[0121] Among them, Pt represents the font size value of the first text, d represents the resolution corresponding to the document, and Px represents the pixel value of the first text in the document.
[0122] The second acquiring unit may include: The recognition subunit is configured to recognize the second pixel value of the second text in the target image based on optical character recognition (OCR).
[0123] Optionally, if the target image includes the second text in multiple font sizes, the determining module 304 may include: A selection unit is configured to select a preset font from the second characters of the plurality of font sizes; the preset font includes any one of a minimum font, a median font, or an average font; the average font is an average font calculated for the second characters of the plurality of font sizes; The second determining unit is configured to determine a ratio between a font size of the first character and a font size of the preset font.
[0124] Optionally, the device may further include: The first judgment module is configured to judge whether the difference in font size between the smallest font and the largest font in the second text is greater than or equal to a first preset threshold, and obtain a second judgment result.
[0125] Optionally, the selection unit may specifically include: The first selection subunit is configured to select the median font or the average font from each of the second font information if the second judgment result indicates that the difference in font size between the smallest font and the largest font in the second text is greater than or equal to the first preset threshold.
[0126] Optionally, the device may further include: The second judgment module is configured to judge whether the number of characters corresponding to the second character is greater than or equal to a second preset threshold, and obtain a third judgment result.
[0127] Optionally, the selection unit may specifically include: The second selection subunit is configured to select the minimum font from each of the second font information if the third judgment result indicates that the number of characters corresponding to the second character is greater than or equal to the second preset threshold.
[0128] Optionally, the adjustment module 310 may include: The adjustment unit is configured to adjust the image size of the target image based on formula (3) and formula (4) to obtain an adjusted target image.
[0129] H2=H3×K(3).
[0130] Among them, H3 represents the image height value of the target image before adjustment, K represents the ratio, and H2 represents the image height value of the target image after adjustment.
[0131] W1=W2×(H2 / H3)(4).
[0132] Wherein, W2 represents the image width value of the target image before adjustment, and W1 represents the image width value of the target image after adjustment.
[0133] Optionally, the document is a document for displaying a topic, and the target image to be rendered is a schematic diagram for explaining the topic to a user who reads the topic.
[0134] The device for rendering an image in a document provided in the present specification can adjust the image size so that the font size of the second text in the adjusted target image is consistent with the font size of the first text in the document. On the premise that the font size of the second text in the target image is consistent with the font size of the first text in the document, the image size of the target image can be made consistent with the document layout, thereby improving the user's reading experience when reading the document.
[0135] The above is a schematic scheme of a device for rendering an image in a document of this embodiment. It should be noted that the technical scheme of the device for rendering an image in a document and the technical scheme of the method for rendering an image in a document belong to the same concept, and the details not described in detail in the technical scheme of the device for rendering an image in a document can be found in the description of the technical scheme of the method for rendering an image in a document.
[0136] Figure 4 The block diagram of a computing device 400 according to one embodiment of the present specification is shown. The components of the computing device 400 include but are not limited to a memory 410 and a processor 420. The processor 420 is connected to the memory 410 via a bus 430, and the database 450 is used to store data.
[0137] The computing device 400 also includes an access device 440 that enables the computing device 400 to communicate via one or more networks 460. Examples of these networks include a public switched telephone network (PSTN), a local area network (LAN), a wide area network (WAN), a personal area network (PAN), or a combination of communication networks such as the Internet. The access device 640 may include one or more of any type of network interface (e.g., a network interface card (NIC)) of wired or wireless, such as an IEEE 802.11 wireless local area network (WLAN) wireless interface, a world-wide interoperability for microwave access (Wi-MAX) interface, an Ethernet interface, a universal serial bus (USB) interface, a cellular network interface, a Bluetooth interface, and a near field communication (NFC).
[0138] In one embodiment of the present specification, the above components of the computing device 400 and Figure 4 Other components not shown in the figure may also be connected to each other, for example, via a bus. It should be understood that Figure 4 The computing device structure block diagram shown is only for the purpose of illustration, and is not intended to limit the scope of this specification. Those skilled in the art can add or replace other components as needed.
[0139] The computing device 400 may be any type of stationary or mobile computing device, including a mobile computer or mobile computing device (e.g., a tablet computer, a personal digital assistant, a laptop computer, a notebook computer, a netbook, etc.), a mobile phone (e.g., a smart phone), a wearable computing device (e.g., a smart watch, smart glasses, etc.), or other types of mobile devices, or a stationary computing device such as a desktop computer or a personal computer (PC). The computing device 400 may also be a mobile or stationary server.
[0140] The processor 420 is used to execute the following computer program / instruction, which, when executed by the processor, implements the steps of the above-mentioned method for rendering an image in a document.
[0141] Each embodiment in this specification is described in a progressive manner, and the same or similar parts between the embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the computing device embodiment, since it is basically similar to the method embodiment for rendering an image in a document, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment for rendering an image in a document.
[0142] An embodiment of the present specification further provides a computer-readable storage medium storing a computer program or instruction, which implements the steps of the above-mentioned method for rendering an image in a document when executed by a processor.
[0143] Each embodiment in this specification is described in a progressive manner, and the same or similar parts between the embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the computer-readable storage medium embodiment, since it is basically similar to the method embodiment for rendering an image in a document, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment for rendering an image in a document.
[0144] An embodiment of the present specification also provides a computer program product, including a computer program / instruction, which implements the steps of the above-mentioned method for rendering an image in a document when executed by a processor.
[0145] The above is a schematic scheme of a computer program product of this embodiment. It should be noted that the technical scheme of the computer program product and the technical scheme of the method for rendering an image in a document described above belong to the same concept, and the details not described in detail in the technical scheme of the computer program product can be referred to the description of the technical scheme of the method for rendering an image in a document described above.
[0146] The above is a description of a specific embodiment of the present specification. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recorded in the claims can be performed in an order different from that in the embodiments and still achieve the desired results. In addition, the processes depicted in the drawings do not necessarily require the specific order or continuous order shown to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.
[0147] The computer instructions include computer program codes, which may be in source code form, object code form, executable files or some intermediate forms, etc. The computer-readable medium may include: any entity or device capable of carrying the computer program code, recording medium, USB flash drive, mobile hard disk, magnetic disk, optical disk, computer memory, read-only memory (ROM), random access memory (RAM), electric carrier signal, telecommunication signal and software distribution medium, etc. It should be noted that the content contained in the computer-readable medium may be appropriately increased or decreased according to the requirements of patent practice. For example, in some regions, according to patent practice, computer-readable media do not include electric carrier signals and telecommunication signals.
[0148] It should be noted that, for the above-mentioned method embodiments, for the sake of simplicity of description, they are all expressed as a series of action combinations, but those skilled in the art should be aware that the embodiments of this specification are not limited by the order of the actions described, because according to the embodiments of this specification, some steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all preferred embodiments, and the actions and modules involved are not necessarily required by the embodiments of this specification.
[0149] In the above embodiments, the description of each embodiment has its own emphasis. For parts that are not described in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.
[0150] The preferred embodiments of this specification disclosed above are only used to help explain this specification. The optional embodiments do not describe all the details in detail, nor do they limit the invention to only the specific implementation methods described. Obviously, many modifications and changes can be made according to the content of the embodiments of this specification. This specification selects and specifically describes these embodiments in order to better explain the principles and practical applications of the embodiments of this specification, so that technicians in the relevant technical field can well understand and use this specification. This specification is only limited by the claims and their full scope and equivalents.
Claims
1. A method for rendering an image in a document, characterized in that: include: Get the first font information of the first word in the document; Determine whether the second text exists in the target image to be rendered, and obtain a first determination result; If the first judgment result indicates that the second character exists in the target image, obtaining second font information of the second character in the target image; Determining a ratio between a font size of the first character and a font size of the second character according to the first font information and the second font information; According to the ratio, adjusting the image size of the target image to obtain an adjusted target image; The font size of the second text in the adjusted target image is consistent with the font size of the first text; The adjusted target image is rendered in the document.
2. The method according to claim 1, characterized in that The method further comprises: If the first judgment result indicates that the second text does not exist in the target image, adjusting the image size of the target image based on formula (1) to obtain the adjusted target image; H1=h1×t(1); Among them, H1 represents the height value of the adjusted target image, h1 represents the pixel value of the first text, t represents the coefficient value, and t>1.
3. The method according to claim 1, characterized in that The step of obtaining first font information of a first character in the document includes: Obtaining a first pixel value of the first character in the document; The acquiring the second font information of the second character in the target image includes: Obtaining a second pixel value of the second character in the target image; The determining the ratio between the font size of the first character and the font size of the second character comprises: A ratio between the first pixel value and the second pixel value is determined.
4. The method according to claim 3, characterized in that The obtaining a first pixel value of the first character in the document includes: Determine the first pixel value of the first character in the document based on optical character recognition (OCR) or formula (2); Px = Pt / 72 × d (2); Wherein, Pt represents the font size of the first character, d represents the resolution corresponding to the document, and Px represents the pixel value of the first character in the document; The obtaining a second pixel value of the second character in the target image includes: Based on optical character recognition (OCR), the second pixel value of the second text in the target image is recognized.
5. The method according to claim 1, characterized in that If the target image includes the second text in a plurality of font sizes, determining the ratio between the font size of the first text and the font size of the second text includes: Selecting a preset font from the second characters of the plurality of font sizes; the preset font includes any one of a minimum font, a median font, or an average font; the average font is an average font calculated for the second characters of the plurality of font sizes; A ratio between a font size of the first character and a font size of the preset font is determined.
6. The method according to claim 5, characterized in that The method further comprises: Determine whether the difference between the font sizes of the smallest font and the largest font in the second character is greater than or equal to a first preset threshold, and obtain a second determination result; The selecting a preset font from each of the second font information specifically includes: If the second judgment result indicates that the difference in font size between the smallest font and the largest font in the second text is greater than or equal to the first preset threshold, the median font or the average font is selected from each of the second font information.
7. The method according to claim 5, characterized in that The method further comprises: Determine whether the number of characters corresponding to the second character is greater than or equal to a second preset threshold, and obtain a third determination result; The selecting a preset font from each of the second font information specifically includes: If the third judgment result indicates that the number of characters corresponding to the second characters is greater than or equal to the second preset threshold, the minimum font is selected from each of the second font information.
8. The method according to claim 1, characterized in that The step of adjusting the image size of the target image according to the ratio to obtain the adjusted target image includes: Based on formula (3) and formula (4), the image size of the target image is adjusted to obtain an adjusted target image; H2=H3×K(3) Wherein, H3 represents the image height value of the target image before adjustment, K represents the ratio, and H2 represents the image height value of the target image after adjustment; W1=W2×(H2 / H3)(4); Wherein, W2 represents the image width value of the target image before adjustment, and W1 represents the image width value of the target image after adjustment.
9. The method according to claim 1, characterized in that The document is a document for displaying a topic, and the target image to be rendered is a schematic diagram for explaining the topic to a user who reads the topic.
10. A device for rendering an image in a document, characterized in that include: A first acquisition module is configured to acquire first font information of a first word in a document; A judgment module is configured to judge whether there is a second text in the target image to be rendered, and obtain a first judgment result; a second acquisition module, configured to acquire second font information of the second character in the target image if the first judgment result indicates that the second character exists in the target image; a determination module, configured to determine a ratio between a font size of the first character and a font size of the second character according to the first font information and the second font information; an adjustment module, configured to adjust the image size of the target image according to the ratio to obtain an adjusted target image; The font size of the second text in the adjusted target image is consistent with the font size of the first text; The rendering module is configured to render the adjusted target image in the document.
11. A computing device, characterized in that: include: Memory and processor; The memory is used to store computer programs or instructions, and the processor is used to execute the computer programs or instructions. When the computer program or instructions are executed by the processor, the steps of the method according to any one of claims 1 to 9 are implemented.
12. A computer-readable storage medium storing a computer program or instruction, characterized in that: When the computer program or instruction is executed by a processor, the steps of the method according to any one of claims 1 to 9 are implemented.
13. A computer program product comprising a computer program or instructions, characterized in that When the computer program or instruction is executed by a processor, the steps of the method according to any one of claims 1 to 9 are implemented.