Methods, apparatus, and storage media for processing garbled fonts in formatted documents
By analyzing different fonts in layout documents and utilizing Unicode conversion tables and optical character recognition technology, garbled fonts can be quickly identified and replaced, solving rendering errors during layout document conversion and copying, and improving processing efficiency.
Patent Information
- Application Number
- CN202210464872.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-04-29
- Publication Date
- 2026-11-17
- Estimated Expiration
- 2042-04-29
AI Technical Summary
Existing technologies, when converting formatted documents into streaming documents or copying content, suffer from rendering errors due to the lack of or incorrect Unicode, and optical character recognition technology requires recognizing each character individually, which is time-consuming.
By analyzing different fonts in the layout document, selecting the glyph images of some characters, and using a preset Unicode conversion table and optical character recognition technology, the matching results and confidence levels of the Unicode are compared to quickly identify and replace fonts with garbled characters.
It improves the speed and accuracy of handling garbled characters in formatted documents, avoids the need to identify each character individually, and enhances the efficiency of the conversion and copying process.
Smart Images

Figure CN117010333B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of document processing technology, such as a method, apparatus, and storage medium for processing garbled fonts in layout documents. Background Technology
[0002] Common formatted documents include PDF and OFD documents, while common streaming documents include Word documents. When converting formatted documents to other streaming formats or copying their content to the clipboard, it's necessary to obtain the Unicode encoding of the glyphs in the formatted document. However, formatted documents often contain glyphs without provided Unicode encoding, or they may provide incorrect Unicode encoding, leading to rendering errors when converting PDFs to other formats. Therefore, before converting formatted documents to other streaming formats or copying their content to the clipboard, it's necessary to identify and correct any garbled characters in the Unicode encoding of the formatted document.
[0003] In the process of implementing the embodiments of this disclosure, at least the following problems were found in the related art:
[0004] The existing solution is to use OCR (Optical Character Recognition) technology to determine the Unicode of the glyph image of each character and replace the Unicode of that character provided in the layout document. However, this method requires recognizing each character in the entire layout document one by one, which is time-consuming. Summary of the Invention
[0005] To provide a basic understanding of some aspects of the disclosed embodiments, a brief summary is given below. This summary is not intended as a general commentary, nor is it intended to identify key / important components or describe the scope of protection of these embodiments, but rather as a prelude to the detailed description that follows.
[0006] This disclosure provides a method, apparatus, and storage medium for processing garbled fonts in layout documents, enabling faster processing of garbled characters in layout documents.
[0007] In some embodiments, the method for handling garbled fonts in a layout document includes: analyzing the layout document to determine various fonts in the layout document; analyzing a portion of the text corresponding to each font to determine the fonts containing garbled characters; and replacing the text containing garbled characters with Unicode.
[0008] In some embodiments, analyzing a portion of the text in each font to determine fonts containing garbled characters includes: performing the following processing for each font: selecting glyph images of a portion of the text as candidate glyph images; obtaining a first Unicode and a second Unicode corresponding to each candidate glyph image; the first Unicode is a Unicode obtained by matching the glyph image in a preset Unicode conversion table; the second Unicode is a Unicode obtained by character recognition of the glyph image; comparing the second Unicode and the first Unicode of each candidate glyph image, and determining that the font contains garbled characters if the comparison result meets a first preset condition.
[0009] In some embodiments, determining that the font contains garbled characters when the comparison result meets a first preset condition includes: determining a first number of candidate glyph images in the font whose first Unicode and second Unicode are the same; if the first number is less than or equal to a first preset threshold, obtaining a second number. The second number is the number of candidate glyph images in the font whose first Unicode and second Unicode are different and whose confidence level is greater than the second preset threshold. The confidence level is obtained by character recognition of the candidate glyph images. If the second number meets a second preset condition, determining that the font contains garbled characters.
[0010] In some embodiments, determining that garbled characters exist in the font when the second quantity meets a second preset condition includes: determining that garbled characters exist in the font when the second quantity is greater than or equal to a third preset threshold; and determining that garbled characters do not exist in the font when the second quantity is less than the third preset threshold.
[0011] In some embodiments, Unicode replacement for characters in fonts with garbled text includes: replacing the first Unicode of all glyph images of the font with garbled text with the corresponding second Unicode. The first Unicode is a Unicode obtained by matching the glyph images in a preset Unicode conversion table, and the second Unicode is a Unicode obtained by character recognition of the glyph images.
[0012] In some embodiments, Unicode replacement for characters in fonts containing garbled text includes: identifying garbled glyph images within the garbled font. The garbled glyph image is a glyph image whose first Unicode and second Unicode differ, and whose confidence level is greater than a second preset threshold. The first Unicode is a Unicode obtained by matching the glyph image in a preset Unicode conversion table. The second Unicode is a Unicode obtained by character recognition of the glyph image. The first Unicode of the garbled glyph image is replaced with the corresponding second Unicode.
[0013] In some embodiments, analyzing a portion of the text in each font includes: extracting a portion of the text from each font using a preset sampling method for analysis.
[0014] In some embodiments, analyzing a subset of text from each font using a preset sampling method includes: randomly selecting a subset of text from each font for analysis. Alternatively, analyzing a subset of text from each font using a preset sampling method includes: selecting a subset of text from each font in the order of their appearance for analysis. Alternatively, analyzing a subset of text from each font using a preset sampling method includes: selecting text from each font whose appearance number is odd for analysis. Alternatively, analyzing a subset of text from each font using a preset sampling method includes: selecting text from each font whose appearance number is even for analysis.
[0015] In some embodiments, the apparatus for processing garbled fonts in a layout document includes: a font determination module configured to analyze the layout document and determine various fonts in the layout document; a judgment module configured to analyze a portion of the text corresponding to each font and determine the fonts containing garbled characters; and a replacement module configured to replace the text containing garbled characters with Unicode.
[0016] In some embodiments, the determination module is configured to analyze a portion of the text in each font to determine the font containing garbled characters by performing the following processing for each font: selecting glyph images of a portion of the text as candidate glyph images; obtaining a first Unicode and a second Unicode corresponding to each candidate glyph image; the first Unicode is a Unicode obtained by matching the glyph image in a preset Unicode conversion table; the second Unicode is a Unicode obtained by character recognition of the glyph image; comparing the second Unicode and the first Unicode of each candidate glyph image, and determining that the font contains garbled characters if the comparison result meets a first preset condition.
[0017] In some embodiments, the determination module is configured to determine that the font contains garbled characters if the comparison result meets a first preset condition by: determining a first number of candidate glyph images in the font whose first Unicode and second Unicode are the same; and obtaining a second number if the first number is less than or equal to a first preset threshold. The second number is the number of candidate glyph images in the font whose first Unicode and second Unicode are different and whose confidence level is greater than the second preset threshold. The confidence level is obtained by character recognition of the candidate glyph images. If the second number meets a second preset condition, the font is determined to contain garbled characters.
[0018] In some embodiments, the determination module is configured to determine that garbled characters exist in the font when the second quantity meets a second preset condition by determining that garbled characters exist in the font when the second quantity is greater than or equal to a third preset threshold. The determination module is also configured to determine that garbled characters do not exist in the font when the second quantity is less than the third preset threshold.
[0019] In some embodiments, the replacement module is configured to perform Unicode replacement on characters in fonts containing garbled text by replacing the first Unicode of all glyph images of the font containing garbled text with the corresponding second Unicode. The first Unicode is a Unicode obtained by matching the glyph images in a preset Unicode conversion table, and the second Unicode is a Unicode obtained by character recognition of the glyph images.
[0020] In some embodiments, the replacement module is configured to perform Unicode replacement on text in fonts containing garbled characters by: identifying garbled glyph images in the garbled fonts; the garbled glyph images being glyph images whose first Unicode and second Unicode are different and whose confidence level is greater than a second preset threshold; the first Unicode being a Unicode obtained by matching the glyph image in a preset Unicode conversion table; and the second Unicode being a Unicode obtained by character recognition of the glyph image; and replacing the first Unicode of the garbled glyph image with the corresponding second Unicode.
[0021] In some embodiments, the judgment module is configured to analyze a portion of the text in each font by extracting a portion of the text from each font using a preset sampling method.
[0022] In some embodiments, the judgment module is configured to analyze a portion of text from each font using a preset sampling method by: randomly selecting a portion of text from each font for analysis; or, analyzing a portion of text from each font using a preset sampling method by: selecting a portion of text from each font in the order in which the text appears for analysis; or, analyzing a portion of text from each font using a preset sampling method by: selecting text from each font whose appearance number is odd for analysis; or, analyzing a portion of text from each font using a preset sampling method by: selecting text from each font whose appearance number is even for analysis.
[0023] In some embodiments, the storage medium stores program instructions that, when executed, perform the method described above for handling garbled fonts in layout documents.
[0024] The method, apparatus, and storage medium for processing garbled fonts in layout documents provided in this disclosure can achieve the following technical effects: Most garbled characters in layout documents are in units of fonts. This embodiment only extracts and analyzes parts of the text in different fonts in the layout document, which can quickly locate the fonts with garbled characters, thereby improving the speed of garbled character processing in layout documents.
[0025] The above general description and the description below are exemplary and illustrative only and are not intended to limit this application. Attached Figure Description
[0026] One or more embodiments are illustrated by way of example with reference to the accompanying drawings. These illustrations and drawings do not constitute a limitation on the embodiments. Elements having the same reference numerals in the drawings are shown as similar elements. The drawings are not to be scaled. And wherein:
[0027] Figure 1 This is a schematic diagram of a method for processing garbled fonts in a layout document, provided by an embodiment of this disclosure;
[0028] Figure 2 This is a schematic diagram of another method for processing garbled fonts in a layout document provided in this embodiment of the disclosure;
[0029] Figure 3 This is a schematic diagram of a method for processing garbled fonts in PDF documents provided in an embodiment of this disclosure;
[0030] Figure 4 This is a schematic diagram of an apparatus for processing garbled fonts in a layout document, provided in an embodiment of this disclosure;
[0031] Figure 5 This is a schematic diagram of another apparatus for processing garbled fonts in layout documents, provided in an embodiment of this disclosure. Detailed Implementation
[0032] To provide a more detailed understanding of the features and technical content of the embodiments of this disclosure, the implementation of the embodiments of this disclosure will be described in detail below with reference to the accompanying drawings. The accompanying drawings are for illustrative purposes only and are not intended to limit the embodiments of this disclosure. In the following technical description, for ease of explanation, several details are used to provide a full understanding of the disclosed embodiments. However, one or more embodiments may still be implemented without these details. In other cases, well-known structures and devices may be simplified in their depiction to simplify the drawings.
[0033] The terms "first," "second," etc., used in the specification, claims, and accompanying drawings of this disclosure are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate for the embodiments of this disclosure described herein. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion.
[0034] Unless otherwise stated, the term "multiple" means two or more.
[0035] In this embodiment of the disclosure, the character " / " indicates that the objects before and after it are in an "or" relationship. For example, A / B means: A or B.
[0036] The term "and / or" describes an association between objects, indicating that three relationships can exist. For example, A and / or B means: A or B, or A and B.
[0037] The term "correspondence" can refer to an association or binding relationship. The correspondence between A and B means that there is an association or binding relationship between A and B.
[0038] When converting a layout document to a streaming document in other formats, or copying the content of a layout document to the clipboard, it is necessary to obtain the Unicode of the glyphs in the layout document. However, layout documents often contain glyphs without Unicode, or the layout document provides incorrect Unicode, which leads to rendering errors when converting PDFs to other formats. Therefore, before converting a layout document to a streaming document in other formats, or copying the content of a layout document to the clipboard, it is necessary to identify and correct any garbled characters in the layout document's Unicode.
[0039] The executing entity in this embodiment of the invention can be an application running on a browser. An application is a web application of a browser on a terminal device. The executing entity in this embodiment of the invention can also be an application deployed on a terminal device. The terminal devices involved in this embodiment of the invention may include, but are not limited to, mobile phones, personal digital assistants (PDAs), wireless handheld devices, tablet computers, personal computers (PCs), and PDAs (personal digital assistants).
[0040] Combination Figure 1 As shown in the embodiments of this disclosure, a method for processing garbled fonts in layout documents is provided, including:
[0041] Step S101: Analyze the layout document and determine the various fonts in the layout document.
[0042] Step S102: Analyze the partial text corresponding to each font to determine the fonts containing garbled characters.
[0043] Step S103: Replace the Unicode characters in the characters with garbled text.
[0044] The method for handling garbled fonts in layout documents, as provided in this embodiment, addresses the issue that most garbled text in layout documents is font-based. This embodiment analyzes only extracted text from different fonts within the layout document, enabling rapid identification of the fonts containing garbled text and thus improving the speed of garbled text processing in layout documents.
[0045] In step S102, a portion of the text in each font is analyzed to identify the fonts containing garbled characters, including performing the following processing for each font:
[0046] Select glyph images of selected characters as candidate glyph images. Obtain the first Unicode and the second Unicode corresponding to each candidate glyph image. Compare the second Unicode and the first Unicode of each candidate glyph image. If the comparison result meets the first preset condition, it is determined that the font contains garbled characters. The first Unicode is obtained by matching the glyph image in a preset Unicode conversion table, and the second Unicode is obtained by character recognition of the glyph image. By comparing the Unicode obtained from the same glyph image using two different Unicode acquisition methods, it is possible to intuitively and conveniently determine whether the Unicode of the same glyph image is incorrect by checking whether the Unicode is consistent, thus realizing the detection of garbled characters in the font.
[0047] Layout documents typically embed font libraries to ensure accurate text display. Font libraries include glyph images and their corresponding glyph codes. When copying text from a layout document, it needs to be converted to Unicode using a Unicode conversion table based on the glyph codes of the glyph images. Then, the obtained Unicode is copied to the clipboard, thus completing the text copying. Further, obtaining the Unicode by matching the glyph images in a preset Unicode conversion table includes: obtaining the glyph codes of the glyph images and matching them with the corresponding Unicode codes in the preset Unicode conversion table.
[0048] Furthermore, obtaining a Unicode code point from a glyph image through character recognition includes: inputting the glyph image into a pre-trained OCR (Optical Character Recognition) text recognition model for recognition, and obtaining the Unicode code point corresponding to the glyph image. When outputting the Unicode code point corresponding to the glyph image, the OCR text recognition model also outputs the confidence level of that Unicode code point. In this embodiment, the confidence level is the probability that the Unicode code point of the glyph image is the Unicode code point output by the OCR text recognition model, representing the reliability of the Unicode code point output by the OCR text recognition model. A higher confidence level indicates a more accurate Unicode code point output by the OCR text recognition model. A lower confidence level indicates a greater possibility of an error in the Unicode code point output by the OCR text recognition model.
[0049] Furthermore, if the comparison result meets the first preset condition, it is determined that the font contains garbled characters, including: determining a first number of candidate glyph images in the font whose first Unicode and second Unicode are the same. If the first number is less than or equal to the first preset threshold, a second number is obtained. If the second number meets the second preset condition, it is determined that the font contains garbled characters. The second number is the number of candidate glyph images in the font whose first Unicode and second Unicode are different and whose confidence level is greater than the second preset threshold. The confidence level of the candidate glyph images is obtained by performing character recognition on the candidate glyph images. In this way, glyph images with a satisfactory confidence level can be determined through the second preset threshold, i.e., glyph images with more reliable OCR recognition results. Combined with the condition that the first Unicode and second Unicode are different, it is possible to more accurately determine whether the Unicode of the text is incorrect, thus improving the accuracy of detecting whether the font contains garbled characters.
[0050] Furthermore, if the second quantity meets the second preset condition, it is determined that the font contains garbled characters, including: if the second quantity is greater than or equal to the third preset threshold, it is determined that the font contains garbled characters.
[0051] In some embodiments, if the second quantity is less than a third preset threshold, it is determined that the font does not contain garbled characters. A larger second quantity means a greater likelihood of Unicode errors in the text. Thus, by comparing the second quantity with the preset third threshold, fonts containing garbled characters can be identified more accurately.
[0052] The first and second preset thresholds are pre-set positive numbers. In some embodiments, the first preset threshold is 0.6 times the number of candidate glyph images in the font. That is, if the number of candidate glyph images in various fonts with the same first Unicode and second Unicode is greater than 0.6 times the total number of candidate glyph images in the font, then it is determined that there is no garbled text in the font. In some embodiments, the second preset threshold is 0.6. In some embodiments, the third preset threshold is half the number of candidate glyph images in the font with different first Unicode and second Unicode. That is, if the second preset threshold is greater than or equal to half the number of candidate glyph images in the font with different first Unicode and second Unicode, then it is determined that there is garbled text in the font.
[0053] Furthermore, character recognition is performed on the candidate character images to obtain their confidence levels. This includes: performing OCR recognition on the candidate character images to obtain a second Unicode corresponding to the candidate character image and the confidence level corresponding to the second Unicode. The confidence level corresponding to the second Unicode is the confidence level of the candidate character image.
[0054] Furthermore, the OCR recognition of the candidate character images includes: inputting the candidate character images into a pre-trained OCR text recognition model for recognition, and obtaining the second Unicode corresponding to the candidate character images and the confidence level corresponding to the second Unicode.
[0055] The OCR text recognition model is trained as follows: Sample glyph images and their corresponding sample labels are input into the OCR model for training, resulting in the OCR text recognition model. The sample labels are the Unicode and confidence level corresponding to the sample glyph image, where 0 < confidence level < 1.
[0056] Step S102, analyzing a portion of the text in each font, includes: extracting a portion of the text from each font using a preset sampling method for analysis. This allows for flexible extraction of a portion of the text from each font using different preset sampling methods.
[0057] Optionally, a portion of text can be extracted from each font for analysis using a preset sampling method, including randomly extracting a portion of text from each font for analysis. Because the extracted text is random, it is easier to detect potential garbled characters compared to extracting fixed text, thus improving the accuracy of identifying and processing garbled fonts in layout documents.
[0058] Optionally, a subset of characters can be extracted from each font for analysis using a preset sampling method, including: extracting a subset of characters from each font in the order they appear. For example, extracting the first 5 characters from each font. This extraction method is suitable for scenarios where errors are easily made at fixed positions.
[0059] Optionally, a preset sampling method is used to extract part of the characters from each font for analysis, which includes: extracting characters with odd occurrence sequence numbers from each font for analysis. The occurrence sequence number of a character is the serial number of the occurrence order of the character in the layout document. For example, the text content "the weather is very good today" in the layout document belongs to the same font, the occurrence sequence number of the character "to" is 1, the occurrence sequence number of the character "wea" is 3, and the occurrence sequence number of the character "ver" is 5. Then, in the text content "the weather is very good today", the characters with odd occurrence sequence numbers are "to", "wea" and "ver", and "to", "wea" and "ver" are extracted for analysis. Since extraction is performed every other character, the detection range is relatively wide, and this method has a relatively high possibility of finding garbled characters in the text.
[0060] Optionally, a preset sampling method is used to extract part of the characters from each font for analysis, which includes: extracting characters with even occurrence sequence numbers from each font for analysis. For example, the text content "the weather is very good today" in the layout document belongs to the same font, the occurrence sequence number of the character "day" is 2, the occurrence sequence number of the character "ther" is 4, and the occurrence sequence number of the character "good" is 6. Then, in the text content "the weather is very good today", the characters with even occurrence sequence numbers are "day", "ther" and "good", and "day", "ther" and "good" are extracted for analysis. Since extraction is performed every other character, the detection range is relatively wide, and this method has a relatively high possibility of finding garbled characters in the text.
[0061] Optionally, a preset sampling method is used to extract part of the characters from each font for analysis, including:
[0062] Extracting part of the characters from each font for analysis according to a preset Unicode range. For example, the preset Unicode range is U+0000 to U+007F, and part of the characters are extracted from each font, where the first Unicode of these extracted characters is within the preset range from U+0000 to U+007F. Since characters that are prone to garbling are often relatively concentrated, the Unicode of these characters that are prone to garbling can be set in advance to perform targeted detection. This extraction method facilitates targeted discovery of garbled characters.
[0063] The number of part of the characters extracted from each font is less than the total number of characters of the corresponding font type extracted. In this way, taking the font type as a unit, part of the characters of each font are analyzed to determine whether there is garbling in this font. This avoids analyzing each character in the layout document, and can locate the garbled font more quickly.
[0064] Optionally, in step S103, the Unicode replacement for characters with garbled text includes: replacing the first Unicode of all glyph images of the garbled characters with the corresponding second Unicode. The first Unicode is obtained by matching the glyph images in a preset Unicode conversion table, and the second Unicode is obtained by character recognition of the glyph images.
[0065] Since most garbled characters in layout documents are at the font type level, analyzing the glyph images of a subset of characters within each font type determines whether garbled characters exist for that font. This avoids analyzing the glyph image of every single character in the layout document, enabling faster identification of garbled characters in published documents. Furthermore, Unicode replacement is applied to all characters in the font containing garbled characters, improving the efficiency of handling garbled fonts in layout documents.
[0066] Optionally, in step S103, Unicode replacement for characters in fonts containing garbled text includes: identifying garbled character images in the fonts containing garbled text; replacing the first Unicode of the garbled character image with the corresponding second Unicode. The garbled character image is defined as a character image whose first and second Unicode are different and whose confidence level is greater than a second preset threshold. The first Unicode is obtained by matching the character image in a preset Unicode conversion table. The second Unicode is obtained by character recognition of the character image. The confidence level is obtained by character recognition of the candidate character images. This Unicode replacement method only performs Unicode replacement on characters in fonts containing garbled text, resulting in higher processing efficiency.
[0067] Combination Figure 2 As shown in the embodiments of this disclosure, another method for processing garbled fonts in layout documents is provided, including:
[0068] Step S201: Analyze the layout document and determine the various fonts in the layout document.
[0069] Step S202: Analyze the partial text corresponding to each font to determine the fonts containing garbled characters.
[0070] Step S203: Identify the font containing garbled characters as the font to be replaced, perform OCR recognition on all glyph images of the font to be replaced, and obtain the second Unicode for each glyph image corresponding to the font to be replaced.
[0071] Step S204: Replace the first Unicode of each glyph image corresponding to the font to be replaced with the second Unicode corresponding to that glyph image.
[0072] This approach analyzes only a subset of characters within each font type to identify the font to be replaced. This avoids analyzing the glyph image of every single character in the document, enabling faster and more accurate identification of garbled text in published documents. OCR is then performed on all glyph images corresponding to the font to be replaced, yielding a second Unicode for each image. This Unicode is then used to replace the garbled text in each glyph image. Since only a subset of characters is used to detect garbled text, the probability of undetected characters also being garbled is high. Therefore, replacing all characters in characters with garbled text with Unicode improves the accuracy of handling garbled fonts in published documents.
[0073] Combination Figure 3 As shown, in some embodiments, a method for processing garbled fonts in a PDF document is provided, comprising: analyzing the PDF document, determining various fonts in the PDF document, and then sequentially performing the following steps for each type of font in the PDF document:
[0074] Step S301: Extract glyph images of some characters from all characters belonging to the current font as candidate glyph images.
[0075] Step S302: Obtain the first Unicode of each candidate glyph image in the PDF document, i.e., PDF-Unicode. Then, perform OCR recognition on each candidate glyph image to obtain the second Unicode corresponding to each candidate glyph image, i.e., OCR-Unicode and confidence level.
[0076] Step S303: Compare the OCR-Unicode and PDF-Unicode of each candidate glyph image to obtain a first number of candidate glyph images with the same PDF-Unicode and OCR-Unicode. Determine if the first number is greater than a first preset threshold. If the first number is greater than the first preset threshold, determine that the current font does not contain garbled characters. If the first number is less than or equal to the first preset threshold, proceed to step S304.
[0077] Step S304: Obtain a second number of candidate glyph images that are different between PDF-Unicode and OCR-Unicode and have a confidence level greater than a second preset threshold. Determine if the second number is less than a third preset threshold. If the second number is less than the third preset threshold, determine that the current font does not contain garbled characters. If the second number is greater than or equal to the third preset threshold, determine that the current font contains garbled characters and proceed to step S305.
[0078] Step S305: Perform OCR recognition on the glyph images of all characters belonging to the current font to obtain the second Unicode for each glyph image corresponding to the current font.
[0079] Step S306: Replace the first Unicode of each glyph image corresponding to the current font with the second Unicode corresponding to that glyph image.
[0080] Although the text displayed on the current PDF document page is correct, some characters may contain characters with incorrect Unicode encoding in this document. After converting the PDF document, copying and pasting the text, or searching, the text with incorrect Unicode encoding will appear as garbled characters. Therefore, it is necessary to identify and correct garbled characters before document conversion or copying and pasting to ensure correct text display after conversion or copying and pasting. This embodiment identifies various font types in the PDF document and extracts glyph images from each font type as candidate glyph images. These candidate glyph images are input into an OCR text recognition model for recognition, obtaining the OCR-Unicode and confidence score of each candidate glyph image for each font type. The comparison result between the OCR-Unicode of each candidate glyph image and its PDF-Unicode in the PDF document is obtained. The comparison result and the confidence score of each candidate glyph image are used to determine whether garbled characters exist in that font type, and all characters in the font with garbled characters are replaced with their Unicode encoding. This method quickly identifies the font of garbled text, avoiding the need for OCR recognition of all Glyphs in a PDF. It allows for faster and more accurate identification of Unicode errors in PDF documents. Furthermore, it eliminates the need for OCR recognition of all fonts when converting or copying / pasting PDF content, thus improving the speed of these processes.
[0081] Combination Figure 4 As shown, this disclosure provides an apparatus for processing garbled fonts in layout documents, including a font determination module 401, a judgment module 402, and a replacement module 403. The font determination module 401 is configured to analyze the layout document and determine various fonts within it. The judgment module 402 is configured to analyze a portion of the text corresponding to each font and determine the fonts containing garbled characters. The replacement module 403 is configured to perform Unicode replacement on the text containing the garbled characters.
[0082] Most garbled characters in layout documents are at the font level. The apparatus for processing garbled fonts in layout documents provided in this disclosure analyzes only portions of text in different fonts within the layout document. This allows for rapid identification of the fonts containing garbled characters, thereby improving the speed of garbled character processing in layout documents.
[0083] The judgment module 402 is configured to analyze a portion of the text in each font to determine the font containing garbled characters using the following method: For each font, the following processing is performed: Select glyph images of a portion of the text as candidate glyph images. Obtain the first Unicode and the second Unicode corresponding to each candidate glyph image. The first Unicode is obtained by matching the glyph image in a preset Unicode conversion table. The second Unicode is obtained by character recognition of the glyph image. Compare the second Unicode and the first Unicode of each candidate glyph image. If the comparison result meets the first preset condition, it is determined that the font contains garbled characters.
[0084] The judgment module 402 is configured to determine that the font contains garbled characters if the comparison result meets a first preset condition by: determining a first number of candidate glyph images in the font whose first Unicode and second Unicode are the same; if the first number is less than or equal to a first preset threshold, obtaining a second number. The second number is the number of candidate glyph images in the font whose first Unicode and second Unicode are different and whose confidence level is greater than the second preset threshold. The confidence level is obtained by character recognition of the candidate glyph images. If the second number meets a second preset condition, the font is determined to contain garbled characters.
[0085] The judgment module 402 is configured to determine that garbled characters exist in the font when the second quantity meets the second preset condition: the font contains garbled characters when the second quantity is greater than or equal to a third preset threshold. The judgment module 402 is also configured to determine that no garbled characters exist in the font when the second quantity is less than the third preset threshold.
[0086] Optionally, the replacement module 403 is configured to perform Unicode replacement on characters in fonts containing garbled text by replacing the first Unicode of all glyph images of the fonts containing garbled text with the corresponding second Unicode. The first Unicode is a Unicode obtained by matching the glyph images in a preset Unicode conversion table, and the second Unicode is a Unicode obtained by character recognition of the glyph images.
[0087] Optionally, the replacement module 403 is configured to perform Unicode replacement on characters in fonts containing garbled text in the following manner: In the fonts containing garbled text, identify garbled glyph images. Replace the first Unicode of the garbled glyph image with the corresponding second Unicode. The garbled glyph image is a glyph image whose first Unicode and second Unicode are different, and whose confidence level is greater than a second preset threshold. The first Unicode is a Unicode obtained by matching the glyph image in a preset Unicode conversion table. The second Unicode is a Unicode obtained by character recognition of the glyph image.
[0088] The judgment module 402 is configured to analyze a portion of the text in each font by using a preset sampling method to extract a portion of the text from each font for analysis.
[0089] Furthermore, the judgment module 402 is configured to analyze a portion of text from each font using a preset sampling method in the following ways: Randomly selecting a portion of text from each font for analysis. Alternatively, analyzing a portion of text from each font using a preset sampling method includes: selecting a portion of text from each font according to the order in which the text appears. Alternatively, analyzing a portion of text from each font using a preset sampling method includes: selecting text from each font whose appearance number is odd for analysis. Alternatively, analyzing a portion of text from each font using a preset sampling method includes: selecting text from each font whose appearance number is even for analysis.
[0090] Combination Figure 5 As shown, this disclosure provides an apparatus for processing garbled fonts in layout documents, including a processor 500 and a memory 501 storing program instructions. Optionally, the apparatus may further include a communication interface 502 and a bus 503. The processor 500, communication interface 502, and memory 501 can communicate with each other via the bus 503. The communication interface 502 can be used for information transmission. The processor 500 can call logical instructions in the memory 501 to execute the method for processing garbled fonts in layout documents described in the above embodiment.
[0091] Furthermore, the program instructions in the aforementioned memory 501 can be implemented as software functional units and, when sold or used as independent products, can be stored in a computer-readable storage medium.
[0092] The memory 501, as a computer-readable storage medium, can be used to store software programs and computer-executable programs, such as program instructions / modules corresponding to the methods in the embodiments of this disclosure. The processor 500 executes functional applications and data processing by running the program instructions / modules stored in the memory 501, that is, it implements the method for processing garbled fonts in layout documents in the above embodiments.
[0093] The memory 501 may include a program storage area and a data storage area. The program storage area may store the operating system and applications required for at least one function; the data storage area may store data created based on the use of the terminal device. Furthermore, the memory 501 may include high-speed random access memory and may also include non-volatile memory.
[0094] This disclosure provides an electronic device that includes the aforementioned apparatus for processing garbled fonts in layout documents.
[0095] Optionally, electronic devices include computers, servers, smartphones, tablets, etc.
[0096] This disclosure provides a storage medium storing program instructions that, when executed, perform the aforementioned method for handling garbled fonts in layout documents.
[0097] This disclosure provides a computer program product, which includes a computer program stored on a computer-readable storage medium. The computer program includes program instructions, which, when executed by a computer, cause the computer to perform the above-described method for processing garbled fonts in a layout document.
[0098] The aforementioned computer-readable storage medium may be a transient computer-readable storage medium or a non-transitory computer-readable storage medium.
[0099] The technical solutions of this disclosure can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes one or more instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the method described in this disclosure. The aforementioned storage medium can be a non-transitory storage medium, including: a USB flash drive, a portable hard drive, a read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disk, and other media capable of storing program code; it can also be a transient storage medium.
[0100] The foregoing description and accompanying drawings fully illustrate embodiments of this disclosure to enable those skilled in the art to practice them. Other embodiments may include structural, logical, electrical, procedural, and other changes. The embodiments represent only possible variations. Individual components and functions are optional unless explicitly required, and the order of operation may vary. Parts and features of some embodiments may be included in or replace parts and features of other embodiments. Moreover, the terminology used in this application is for describing embodiments only and is not intended to limit the claims. As used in the description of embodiments and claims, the singular forms “a,” “an,” and “the” are intended to equally include the plural forms unless the context clearly indicates otherwise. Similarly, the term “and / or” as used in this application means including one or more of the associated listed items and all possible combinations thereof. Additionally, when used in this application, the term "comprise" and its variations "comprises" and / or "comprising" refer to the presence of stated features, integrals, steps, operations, elements, and / or components, but do not exclude the presence or addition of one or more other features, integrals, steps, operations, elements, components, and / or groups thereof. Without further limitations, an element defined by the phrase "comprises a..." does not exclude the presence of other identical elements in the process, method, or apparatus that includes said element. In this document, each embodiment may focus on the differences from other embodiments, and similar or identical parts between embodiments can be referred to mutually. For methods, products, etc., disclosed in the embodiments, if they correspond to the method section disclosed in the embodiments, the relevant parts can be referred to the description of the method section.
[0101] Those skilled in the art will recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of the embodiments of this disclosure. Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working processes of the systems, devices, and units described above can be referred to the corresponding processes in the foregoing method embodiments, and will not be repeated here.
[0102] The methods and products (including but not limited to devices and equipment) disclosed in the embodiments herein can be implemented in other ways. For example, the device embodiments described above are merely illustrative. For instance, the division of units may be merely a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. In addition, the coupling or direct coupling or communication connection between the shown or discussed units may be through some interfaces, and the indirect coupling or communication connection between devices or units may be electrical, mechanical, or other forms. The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units, that is, they may be located in one place or distributed across multiple network units. Some or all of the units may be selected to implement this embodiment according to actual needs. Furthermore, the functional units in the embodiments of this disclosure may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit.
[0103] The flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of systems, methods, and computer program products according to embodiments of this disclosure. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code containing one or more executable instructions for implementing a specified logical function. In some alternative implementations, the functions marked in the blocks may occur in a different order than that shown in the drawings. For example, two consecutive blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. In the descriptions corresponding to the flowcharts and block diagrams in the accompanying drawings, the operations or steps corresponding to different blocks may also occur in a different order than disclosed in the description, and sometimes there is no specific order between different operations or steps. For example, two consecutive operations or steps may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. Each block in a block diagram and / or flowchart, and combinations of blocks in a block diagram and / or flowchart, can be implemented using a dedicated hardware-based system that performs the specified function or action, or using a combination of dedicated hardware and computer instructions.
Claims
1. A method for processing garbled fonts in formatted documents, characterized in that, include: Analyze the layout document to determine the various fonts in the layout document; Analyze the text corresponding to each font to identify the fonts containing garbled characters; Replace characters with Unicode characters in fonts containing garbled text. This involved analyzing a portion of the text in each font to identify fonts containing garbled characters, including: Perform the following processing for each of the fonts: Select glyph images of some characters as candidate glyph images; Obtain a first Unicode code and a second Unicode code corresponding to each of the candidate glyph images; the first Unicode code is obtained by matching the glyph image in a preset Unicode conversion table; the second Unicode code is obtained by character recognition of the glyph image. Compare the second Unicode and the first Unicode of each of the candidate glyph images; Determine the first number of candidate glyph images in the font that have the same first Unicode and second Unicode; If the first quantity is less than or equal to the first preset threshold, a second quantity is obtained; the second quantity is the number of candidate glyph images in the font whose first Unicode and second Unicode are different and whose confidence level is greater than the second preset threshold; wherein, the confidence level is obtained by performing character recognition on the candidate glyph images; If the second quantity meets the second preset condition, it is determined that the font contains garbled characters.
2. The method according to claim 1, characterized in that, If the second quantity meets the second preset condition, it is determined that the font contains garbled characters, including: If the second quantity is greater than or equal to the third preset threshold, it is determined that the font contains garbled characters; The method further includes: If the second quantity is less than the third preset threshold, it is determined that the font does not contain garbled characters.
3. The method according to any one of claims 1 to 2, characterized in that, For text with garbled characters, perform Unicode replacement, including: The first Unicode of all glyph images of fonts containing garbled characters is replaced with the corresponding second Unicode; the first Unicode is obtained by matching the glyph images in a preset Unicode conversion table, and the second Unicode is obtained by character recognition of the glyph images.
4. The method according to any one of claims 1 to 2, characterized in that, For text with garbled characters, perform Unicode replacement, including: In fonts containing garbled characters, garbled character images are identified; the garbled character images are those whose first Unicode and second Unicode are different, and whose confidence level is greater than a second preset threshold; the first Unicode is a Unicode obtained by matching the character images in a preset Unicode conversion table; the second Unicode is a Unicode obtained by character recognition of the character images; Replace the first Unicode of the garbled character image with the corresponding second Unicode.
5. The method according to claim 1, characterized in that, Analysis of selected characters in each font, including: The system uses a preset sampling method to extract a portion of the text from each font for analysis.
6. The method according to claim 5, characterized in that, Using a preset sampling method, a portion of text is extracted from each font for analysis, including: Randomly select a portion of text from each font for analysis; or, For each font, extract portions of text according to the order in which they appear for analysis; or, Extract and analyze characters with odd-numbered sequences from each font; or, We extract and analyze characters with even-numbered sequences from each font.
7. An apparatus for processing garbled fonts in formatted documents, characterized in that, The apparatus comprising the method for processing garbled fonts in a layout document as described in claim 1, wherein the apparatus comprises: The font determination module is configured to analyze the layout document and determine the various fonts in the layout document. The judgment module is configured to analyze a portion of the text corresponding to each font to determine the font containing garbled characters; The replacement module is configured to replace text with Unicode characters if there are garbled characters in the font.
8. A storage medium storing program instructions, characterized in that, The program instructions execute the method for handling garbled fonts in layout documents as described in any one of claims 1 to 6 during runtime.
Citation Information
Patent Citations
Messy code detection method and system for text documents
CN104424165A
Messy code recognition method and device for document content and electronic equipment
CN110728115A
Messy code repairing method and device, electronic equipment and readable storage medium
CN111695327A
