A text rotation positioning method, system and storage medium of an OFD document
By acquiring and calculating the rotation and displacement parameters of the target text box in an OFD document, the problems of insufficient flexibility and computational complexity in text rotation in OFD documents are solved, enabling flexible text rotation and movement and providing good visual effects.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- AEROSPACE FOXIT SOFTWARE (BEIJING) CO LTD
- Filing Date
- 2022-09-02
- Publication Date
- 2026-05-05
AI Technical Summary
Existing technologies lack flexibility or are computationally complex when rotating text in OFD documents, and OFD viewing software struggles to implement editing functions, especially text rotation and movement operations.
By obtaining the target text box of the OFD text to be rotated, the rotation and displacement parameters are calculated based on the target rotation angle. The CTM and the upper left corner of the text box are used as rotation points to realize the rotation and movement of the text, avoiding the error of the text box not being in close contact with the text.
It enables flexible rotation of text in OFD documents, avoiding errors caused by the text box not being aligned with the text during rotation, providing a better visual effect, and does not rely on code or font library interfaces.
Smart Images

Figure CN115641590B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of IT digitization technology, and in particular to a method, system, and storage medium for text rotation and positioning in OFD documents. Background Technology
[0002] Currently, there are two common methods for rotating text (text strings) in OFD documents: one is to combine the CharDirection and ReadDirection properties; the other is to adjust the CTM ("Current Transformation Matrix") in the text object. The former is relatively simple, but lacks flexibility; the latter is very flexible, but more computationally complex.
[0003] OFD (Optical Document Format) is a type of layout document. A characteristic of layout documents is that they are easy to view but difficult to edit (for example, PDF is a layout file and is generally not easy to edit). OFD viewing software typically has limited editing capabilities for OFD files; for example, operations such as rotating and moving text are usually not provided. Professional OFD editors often utilize the fact that OFD files are also zip-compressed files, using decompression tools to extract them and then directly modifying the contents of the (xml) files to adjust the OFD file. In manual modification scenarios, it is impossible to calculate the various parameters in the CTM (Current Document Format) using code. Therefore, there is an urgent need to provide a technical solution to address these issues. Summary of the Invention
[0004] To address the aforementioned technical problems, this invention provides a method, system, and storage medium for text rotation and positioning in OFD documents.
[0005] The technical solution of the text rotation and positioning method for OFD documents according to the present invention is as follows:
[0006] Get the target text box at the original position of the OFD text to be rotated;
[0007] Based on the target rotation angle, the target text box containing the OFD text to be rotated is rotated according to the rotation parameters of the target text box to obtain the first rotation position of the OFD text to be rotated.
[0008] The displacement parameters of the target text box are calculated based on the original close rectangle of the OFD text to be rotated at the original position and the first close rectangle of the OFD text to be rotated at the first rotation position.
[0009] Based on the displacement parameters, the target text box containing the OFD text to be rotated is moved to obtain the target rotation position of the OFD text to be rotated.
[0010] The beneficial effects of the text rotation and positioning method for OFD documents of the present invention are as follows:
[0011] The method of this invention effectively avoids errors caused by the text box not being properly aligned with the text during rotation by rotating the text in the OFD document. Furthermore, it achieves text rotation without relying on code or font interfaces, and provides good visual effects.
[0012] Based on the above solution, the text rotation and positioning method for OFD documents of the present invention can be further improved as follows.
[0013] Furthermore, the target text box is a Boundary text box.
[0014] Furthermore, each target rotation angle corresponds to a set of rotation parameters; the step of rotating the target text box containing the OFD text to be rotated according to the rotation parameters of the target text box to obtain the first rotation position of the OFD text to be rotated includes:
[0015] The top left corner of the target text box is selected as the rotation point, and the target text box is controlled to rotate around the rotation point according to a set of rotation parameters corresponding to the target rotation angle, so as to obtain the first rotation position of the OFD text to be rotated.
[0016] Furthermore, the displacement parameters include: a first displacement parameter and a second displacement parameter;
[0017] The step of calculating the displacement parameters of the target text box based on the original close rectangle of the OFD text to be rotated at the original position and the first close rectangle of the OFD text to be rotated at the first rotation position includes:
[0018] The first displacement parameter of the target text box is calculated according to the first precise displacement parameter calculation formula, the original close-fitting rectangle and the first close-fitting rectangle; or, the first displacement parameter of the target text box is calculated according to the first estimated displacement parameter calculation formula, the original close-fitting rectangle and the first close-fitting rectangle.
[0019] The second displacement parameter of the target text box is calculated based on the second precise displacement parameter calculation formula, the original close-fitting rectangle, and the first close-fitting rectangle; or, the second displacement parameter of the target text box is calculated based on the second estimated displacement parameter calculation formula, the original close-fitting rectangle, and the first close-fitting rectangle.
[0020] Furthermore, the OFD text to be rotated includes at least one target character, wherein the target rotation angle is 90 degrees, 180 degrees, or 270 degrees.
[0021] When the target rotation angle is 90 degrees, the formula for calculating the first precise displacement parameter is: e1 = ptStart.y - Min(metrics[i].bearingY - metrics[i].height) + ptStart.x + metrics[0].bearingX; where e1 is the first displacement parameter corresponding to the target rotation angle of 90 degrees, ptStart.y is the X coordinate of the font base point of the first character in the OFD text to be rotated in the object coordinate system, and ptStart.x is the X coordinate of the font base point of the first character in the OFD text to be rotated in the object coordinate system. The Y-coordinate is given below, metrics[i] represents the specification of the i-th font in the OFD text to be rotated, bearingY represents the text measurement value in the Y direction, bearingX represents the text measurement value in the X direction, height represents the text measurement height value, Min(metrics[i].bearingY-metrics[i].height) represents the minimum value of the bearingY-height value of each character in the OFD text to be rotated, and metrics[0].bearingX represents the text measurement value of the first character in the OFD text to be rotated in the X direction;
[0022] When the target rotation angle is 90 degrees, the formula for calculating the second precise displacement parameter is:
[0023] f1 = ptStart.y - Max(metrics[i].bearingY) - ptStart.x - metrics[0].bearingX; where f1 is the second displacement parameter corresponding to the target rotation angle of 90 degrees, and Max(metrics[i].bearingY) represents the maximum value of bearingY among all characters in the OFD text to be rotated;
[0024] When the target rotation angle is 90 degrees, the formula for calculating the first estimated displacement parameter is:
[0025] e1 = ptStart.y + ptStart.x + fontSize × α_x[0] × 0.1; where fontSize is the font size of the OFD text to be rotated, α_x[0] represents the α_x value of the first character in the OFD text to be rotated, and α_x represents the ratio of the width of different characters to the fontSize of the corresponding character in the OFD text to be rotated;
[0026] When the target rotation angle is 90 degrees, the formula for calculating the second estimated displacement parameter is:
[0027] f1 = ptStart.y - ptStart.x - fontSize × (α_y[max] - α_x[0]); where α_y[max] represents the maximum value of α_y among all characters in the OFD text to be rotated;
[0028] When the target rotation angle is 180 degrees, the formula for calculating the first precise displacement parameter is:
[0029] e2 = ptStart.x + Σ△x[i] + metrics[n-1].bearingX + metrics[n-1].width + ptStart.x + metrics[0].bearingX; where e2 is the first displacement parameter corresponding to the target rotation angle of 180 degrees, metrics[0] represents the first character of the OFD text to be rotated, metrics[n-1] represents the last character of the OFD text to be rotated, △x is a double-type numerical queue in the OFD text to be rotated, each value in the queue represents the offset value between the next character and the previous character in the X direction, and Σ△x[i] represents the summation of the numerical queue;
[0030] When the target rotation angle is 180 degrees, the formula for calculating the second precise displacement parameter is:
[0031] f2 = -Min(metrics[i].horiBearingY - metrics[i].height) + ptStart.y + ptStart.y – Max(metrics[i].horiBearingY); where f2 is the second displacement parameter corresponding to the target rotation angle of 180 degrees, Max(metrics[i].horiBearingY) represents the maximum value of horiBearingY among all characters in the OFD text to be rotated, and Min(metrics[i].horiBearingY - metrics[i].height) represents the minimum value of horiBearingY – height among all characters in the OFD text to be rotated.
[0032] When the target rotation angle is 180 degrees, the formula for calculating the first estimated displacement parameter is:
[0033] e2=2×ptStart.x+Σ△x[i]+fontSize×(α_x[last]+α_x[0]); where α_y[last] represents the α_y value of the last character in the OFD text to be rotated;
[0034] When the target rotation angle is 180 degrees, the formula for calculating the second estimated displacement parameter is:
[0035] f2 = 2 × ptStart.y - fontSize × α_y[max]; where α_y[max] represents the maximum value of α_y for all characters in the OFD text to be rotated;
[0036] When the target rotation angle is 270 degrees, the formula for calculating the first precise displacement parameter is:
[0037] e3 = -(ptStart.y - Max(metrics[i].bearingY) - ptStart.x - metrics[0].bearingX); where e3 is the first displacement parameter corresponding to the target rotation angle of 270 degrees;
[0038] When the target rotation angle is 270 degrees, the formula for calculating the second precise displacement parameter is:
[0039] f3 = ptStart.x + metrics[0].bearingX + ptStart.y - Min(metrics[i].bearingY - metrics[i].height); f3 is the second displacement parameter corresponding to the target rotation angle of 270 degrees;
[0040] When the target rotation angle is 270 degrees, the formula for calculating the first estimated displacement parameter is:
[0041] e3 = -(ptStart.y – ptStart.x – fontSize × (α_x[max] + α_x[0])); where α_x[max] represents the maximum value of α_x for all characters in the OFD text to be rotated;
[0042] When the target rotation angle is 270 degrees, the formula for calculating the second estimated displacement parameter is:
[0043] f3=ptStart.y+ptStart.x+fontSize×(α_x[0]+1-α_y[max]).
[0044] The technical solution of the OFD document text rotation and positioning system of the present invention is as follows:
[0045] It includes: an acquisition module, a processing module, a calculation module, and an execution module;
[0046] The acquisition module is used to: acquire the target text box of the OFD text to be rotated at its original position;
[0047] The processing module is used to: obtain the target text box containing the OFD text to be rotated based on the target rotation angle and according to the rotation parameters of the target text box, to obtain the first rotation position of the OFD text to be rotated;
[0048] The calculation module is used to: calculate the displacement parameters of the target text box based on the original close rectangle of the OFD text to be rotated at the original position and the first close rectangle of the OFD text to be rotated at the first rotation position;
[0049] The running module is used to: move the target text box containing the OFD text to be rotated according to the displacement parameters, so as to obtain the target rotation position of the OFD text to be rotated.
[0050] The beneficial effects of the OFD document text rotation and positioning system of the present invention are as follows:
[0051] The system of this invention effectively avoids errors caused by the text box not being in close contact with the text during rotation by rotating the text in the OFD document. It achieves text rotation without relying on code and font library interfaces and has a better visual effect.
[0052] Based on the above solution, the OFD document text rotation and positioning system of the present invention can be further improved as follows.
[0053] Furthermore, the target text box is a Boundary text box.
[0054] Furthermore, each target rotation angle corresponds to a set of rotation parameters; the processing module is specifically used for:
[0055] The top left corner of the target text box is selected as the rotation point, and the target text box is controlled to rotate around the rotation point according to a set of rotation parameters corresponding to the target rotation angle, so as to obtain the first rotation position of the OFD text to be rotated.
[0056] Furthermore, the displacement parameters include: a first displacement parameter and a second displacement parameter;
[0057] The calculation module is specifically used for:
[0058] The first displacement parameter of the target text box is calculated according to the first precise displacement parameter calculation formula, the original close-fitting rectangle and the first close-fitting rectangle; or, the first displacement parameter of the target text box is calculated according to the first estimated displacement parameter calculation formula, the original close-fitting rectangle and the first close-fitting rectangle.
[0059] The second displacement parameter of the target text box is calculated based on the second precise displacement parameter calculation formula, the original close-fitting rectangle, and the first close-fitting rectangle; or, the second displacement parameter of the target text box is calculated based on the second estimated displacement parameter calculation formula, the original close-fitting rectangle, and the first close-fitting rectangle.
[0060] The technical solution of a storage medium according to the present invention is as follows:
[0061] The storage medium stores instructions that, when read by a computer, cause the computer to execute the steps of a text rotation and positioning method for an OFD document as described in this invention. Attached Figure Description
[0062] Figure 1 This is a flowchart illustrating a text rotation and positioning method for OFD documents according to an embodiment of the present invention.
[0063] Figure 2 This is a schematic diagram of the Boundary text box in an OFD document text rotation and positioning method according to an embodiment of the present invention.
[0064] Figure 3 This is a schematic diagram of text box parameters in an OFD document text rotation and positioning method according to an embodiment of the present invention;
[0065] Figure 4 This is a schematic diagram of the enclosing matrix in a text rotation and positioning method for OFD documents according to an embodiment of the present invention;
[0066] Figure 5 This is a schematic diagram of a close-fitting rectangle in an OFD document text rotation and positioning method according to an embodiment of the present invention;
[0067] Figure 6 This is a schematic diagram of text rotation in an OFD document text rotation and positioning method according to an embodiment of the present invention;
[0068] Figure 7 This is a schematic diagram of the OFD document text to be rotated when rotated 90 degrees in a text rotation and positioning method of an OFD document according to an embodiment of the present invention.
[0069] Figure 8 This is a schematic diagram of the text corresponding to the precise CTM calculation when rotating 90 degrees in an OFD document text rotation and positioning method according to an embodiment of the present invention.
[0070] Figure 9 This is a schematic diagram of the rotation effect corresponding to the precise CTM calculation when rotating 90 degrees in an OFD document text rotation and positioning method according to an embodiment of the present invention.
[0071] Figure 10 This is a schematic diagram of the text corresponding to the CTM estimation calculation when rotating 90 degrees in an OFD document text rotation and positioning method according to an embodiment of the present invention.
[0072] Figure 11 This is a schematic diagram of the rotation effect corresponding to the CTM estimation calculation when rotating 90 degrees in an OFD document text rotation and positioning method according to an embodiment of the present invention.
[0073] Figure 12 This is a schematic diagram of the OFD document text to be rotated when rotated 180 degrees in an OFD document text rotation and positioning method according to an embodiment of the present invention.
[0074] Figure 13 This is a schematic diagram of the text corresponding to the precise CTM calculation when rotating 180 degrees in an OFD document text rotation and positioning method according to an embodiment of the present invention.
[0075] Figure 14 This is a schematic diagram illustrating the rotation effect corresponding to the precise CTM calculation when rotating 180 degrees in an OFD document text rotation and positioning method according to an embodiment of the present invention.
[0076] Figure 15 This is a schematic diagram of the text corresponding to the CTM estimation calculation when rotating 180 degrees in an OFD document text rotation and positioning method according to an embodiment of the present invention.
[0077] Figure 16 This is a schematic diagram of the rotation effect corresponding to the CTM estimation calculation when rotating 180 degrees in an OFD document text rotation and positioning method according to an embodiment of the present invention.
[0078] Figure 17 This is a schematic diagram of the OFD document text to be rotated when rotated 270 degrees in an OFD document text rotation and positioning method according to an embodiment of the present invention.
[0079] Figure 18 This is a schematic diagram of the text corresponding to the precise CTM calculation when rotating 270 degrees in an OFD document text rotation and positioning method according to an embodiment of the present invention.
[0080] Figure 19 This is a schematic diagram of the rotation effect corresponding to the precise CTM calculation when rotating 270 degrees in an OFD document text rotation and positioning method according to an embodiment of the present invention.
[0081] Figure 20 This is a schematic diagram of the text corresponding to the CTM estimation calculation when rotating 270 degrees in an OFD document text rotation and positioning method according to an embodiment of the present invention.
[0082] Figure 21 This is a schematic diagram of the rotation effect corresponding to the CTM estimation calculation when rotating 270 degrees in an OFD document text rotation and positioning method according to an embodiment of the present invention.
[0083] Figure 22 This is a schematic diagram of the structure of an OFD document text rotation and positioning system according to an embodiment of the present invention. Detailed Implementation
[0084] like Figure 1 As shown, an OFD document text rotation and positioning method according to an embodiment of the present invention includes the following steps:
[0085] S1. Obtain the target text box at the original position of the OFD text to be rotated.
[0086] The OFD text to be rotated is any text selected by the user within the OFD document. The original position is any position within the OFD document. The target text box is the Boundary text box.
[0087] It should be noted that there are three common types of text boxes. One is the bounded text box. For example... Figure 2 As shown, the Boundary text box is defined in the OFD specification as an outer frame around which the text is contained. Figure 3 As shown, the distance between the base point of the Boundary text box and the first text is determined by the X and Y parameters. The definition of the base point can be found in the OFD specification and will not be repeated here. The CTM property of the text applies to the Boundary text box. When the Boundary text box rotates, the text rotates along with the Boundary text box, thus creating a rotation effect. Secondly, there is the enclosing rectangle. For example... Figure 4 As shown, software like FontCreator reveals that each character in the font library has a surrounding rectangle, which is not flush with the strokes of the character. Thirdly, there are rectangles that are flush with the character's strokes. For example... Figure 5As shown, the characteristic of a close-fitting rectangle is that the rectangle is close to the strokes of the text. For a line of text, the close-fitting rectangle of the text line is the union of the close-fitting rectangles of all its characters. In this embodiment, a Boundary text box is used as the text box. Taking the upper left corner of the Boundary text box as the rotation point, firstly, the a, b, c, and d parameters of the CTM are set to rotate it by a certain target angle with the upper left corner of the Boundary text box as the rotation point. Then, by calculating the e and f parameters, the text is adjusted in the horizontal and vertical directions so that the close-fitting rectangle of the OFD text to be rotated is aligned with the upper left corner of the rotation matrix of the rotated text.
[0088] It should be noted that the OFD specification is existing technology and a published national standard, officially titled "Electronic Document Storage and Exchange Format Version Document" (GB / T 33190-2016). In the specification's "Element Object Attribute Definition," the boundary is described as "a bounding rectangle, using the current spatial coordinate system's page coordinates; when an element is drawn outside this rectangular area, it is clipped."
[0089] S2. Based on the target rotation angle, obtain and according to the rotation parameters of the target text box, rotate the target text box containing the OFD text to be rotated to obtain the first rotation position of the OFD text to be rotated.
[0090] The target rotation angle is 90 degrees, 180 degrees, or 270 degrees. The rotation parameters of the target text box are the a, b, c, and d parameters in CTM. The first rotation position is the position obtained by rotating the OFD text to be rotated by the top left corner of the target text box by the target rotation angle (e.g., ...). Figure 6 (As shown).
[0091] S3. Calculate the displacement parameters of the target text box based on the original close rectangle of the OFD text to be rotated at the original position and the first close rectangle of the OFD text to be rotated at the first rotation position.
[0092] Wherein, the original rectangle that the OFD text to be rotated is located at its original position is as follows: Figure 5 As shown. The methods for calculating displacement parameters include: precise displacement calculation and estimated displacement calculation. The displacement parameters of the target text box are: the e and f parameters in CTM.
[0093] S4. Based on the displacement parameters, move the target text box containing the OFD text to be rotated to obtain the target rotation position of the OFD text to be rotated.
[0094] The displacement parameter allows the target text box to move in the x and y directions.
[0095] Ideally, each target rotation angle corresponds to a set of rotation parameters.
[0096] The rotation parameters are a, b, c, and d in the CTM of the target text box. When the target rotation angle is 90 degrees, a1 = 0; b1 = 1; c1 = -1; d1 = 0; when the target rotation angle is 180 degrees, a2 = 0; b2 = -1; c2 = 1; d2 = 0; when the target rotation angle is 270 degrees, a3 = 0; b3 = -1; c3 = 1; d3 = 0.
[0097] S2 includes:
[0098] The top left corner of the target text box is selected as the rotation point, and the target text box is controlled to rotate around the rotation point according to a set of rotation parameters corresponding to the target rotation angle, so as to obtain the first rotation position of the OFD text to be rotated.
[0099] Preferably, the displacement parameters include: a first displacement parameter and a second displacement parameter.
[0100] The first displacement parameter is the parameter obtained by calculation using the first precise displacement parameter calculation formula or the first estimated displacement parameter calculation formula. The second displacement parameter is the parameter obtained by calculation using the second precise displacement parameter calculation formula or the second estimated displacement parameter calculation formula.
[0101] S3 includes:
[0102] S31. Calculate the first displacement parameter of the target text box according to the first precise displacement parameter calculation formula, the original close-fitting rectangle, and the first close-fitting rectangle; or, calculate the first displacement parameter of the target text box according to the first estimated displacement parameter calculation formula, the original close-fitting rectangle, and the first close-fitting rectangle.
[0103] S32. Calculate the second displacement parameter of the target text box according to the second precise displacement parameter calculation formula, the original close-fitting rectangle, and the first close-fitting rectangle; or, calculate the second displacement parameter of the target text box according to the second estimated displacement parameter calculation formula, the original close-fitting rectangle, and the first close-fitting rectangle.
[0104] Preferably, the OFD text to be rotated includes at least one target character.
[0105] When the target rotation angle is 90 degrees, the formula for calculating the first precise displacement parameter is: e1 = ptStart.y - Min(metrics[i].bearingY - metrics[i].height) + ptStart.x + metrics[0].bearingX; where e1 is the first displacement parameter corresponding to the target rotation angle of 90 degrees, ptStart.y is the X coordinate of the font base point of the first character in the OFD text to be rotated in the object coordinate system, and ptStart.x is the X coordinate of the font base point of the first character in the OFD text to be rotated in the object coordinate system. The Y-coordinate is given below, metrics[i] represents the specification of the i-th font in the OFD text to be rotated, bearingY represents the text measurement value in the Y direction, bearingX represents the text measurement value in the X direction, height represents the text measurement height value, Min(metrics[i].bearingY-metrics[i].height) represents the minimum value of the bearingY-height value of each character in the OFD text to be rotated, and metrics[0].bearingX represents the text measurement value of the first character in the OFD text to be rotated in the X direction.
[0106] When the target rotation angle is 90 degrees, the formula for calculating the second precise displacement parameter is:
[0107] f1 = ptStart.y - Max(metrics[i].bearingY) - ptStart.x - metrics[0].bearingX; where f1 is the second displacement parameter corresponding to the target rotation angle of 90 degrees, and Max(metrics[i].bearingY) represents the maximum value of bearingY among all characters in the OFD text to be rotated.
[0108] When the target rotation angle is 90 degrees, the formula for calculating the first estimated displacement parameter is:
[0109] e1 = ptStart.y + ptStart.x + fontSize × α_x[0] × 0.1; where fontSize is the font size of the OFD text to be rotated, α_x[0] represents the α_x value of the first character in the OFD text to be rotated, and α_x represents the ratio of the width of different characters to the fontSize of the corresponding character in the OFD text to be rotated.
[0110] It should be noted that the query method for the α_x table is as follows: According to the "character" and "font" of the character to be queried, find the corresponding level in the value table of α_x, and then the α_x corresponding to the character can be obtained.
[0111] Among them, the steps to obtain the value table of α_x are as follows: ① Statistically calculate the widths of the commonly used characters such as Chinese characters of levels 1 and 2 (6,763 characters), 0-9, a-z, A-Z, and the five commonly used or fonts with large aspect ratio differences such as Song, FangSong, Kai, Hei, and LiShu, at the given font size. Note that here, the horiAdvance value of the character is not statistically calculated, but the width value of the character against the edge is statistically calculated. ② For the Song font, calculate the ratio of the width of each character statistically calculated to the font size used for statistics, that is, α = width / fontSize, and sort α from small to large to obtain the α coefficient value sequence of each character in the Song font. ③ Taking the Song font as a reference, divide the α coefficient values into 5 levels, list the corresponding characters, and obtain Table 1 below. ④ Remove some rare characters, such as 礻, 犭, 扌, etc. Then observe the difference ratio between the a values of other fonts and the Song font. It can be found that except for the FangSong font, the a values of other fonts have little difference from the Song font. Take the a values of some typical characters in the FangSong font, compare them with the Song font, and estimate that a[FangSong] / a[Song] = 0.76. Adjust a[FangSong] according to this ratio and list it in the table to obtain Table 2 below.
[0112] Table 1
[0113]
[0114] Table 2
[0115]
[0116] When the target rotation angle is 90 degrees, the calculation formula for the second estimated displacement parameter is:
[0117] f1 = ptStart.y - ptStart.x - fontSize × (α_y[max] - α_x[0]); where α_y[max] represents the maximum value of the α_y values of all characters in the OFD text to be rotated.
[0118] It should be noted that the query method for the α_y table is as follows: According to the "character" and "font" of the character to be queried, find the corresponding level in the α_y table, and then the α_y corresponding to the character can be obtained.
[0119] Among them, the steps to obtain the value table of α_y are as follows: ① Statistically analyze the heights of common characters such as Chinese characters of levels 1 and 2 (6,763 characters), 0-9, a-z, A-Z, and five common or fonts with large aspect ratio differences such as Song, Fangsong, Regular, Bold, and Lishu at a given font size. ② For the Song font, calculate the ratio of the height of each character obtained from the statistics to the font size used in the statistics, i.e., α = height / fontSize, and sort α from small to large to obtain the α coefficient value sequence of each character in the Song font. ③ Divide the α coefficient values into 5 levels and classify the corresponding characters into them. At the same time, for the 5 characters jpqgy whose lower edges exceed the character baseline, considering that their lower edges will lower the bounding rectangle of the entire text string when mixed with other characters (including Chinese and English), adjust them to level 5. The following Table 3 is obtained. ④ Remove some rare characters, such as 彐, 冫, 氵, 廴, etc. Other fonts are estimated in the same proportion as the Song font, similar to the processing of other fonts when statistically analyzing the α_x table. It can be observed that for the Regular font with a smaller size in the y direction (smaller glyphs) and the Lishu font (flattened glyphs), their α_y has a较大 difference from that of the Song font, while other fonts have a较小 difference from the Song font. Adjust the Regular font and the Lishu font and list them separately to obtain the following Table 4.
[0120] Table 3
[0121]
[0122] Table 4
[0123]
[0124] When the target rotation angle is 180 degrees, the calculation formula for the first precise displacement parameter is as follows:
[0125] e2 = ptStart.x + Σ△x[i] + metrics[n - 1].bearingX + metrics[n - 1].width + ptStart.x + metrics[0].bearingX; where e2 is the first displacement parameter corresponding to the target rotation angle of 180 degrees, metrics[0] represents the first character of the OFD text to be rotated, metrics[n - 1] represents the last character of the OFD text to be rotated, △x is a double-type numerical queue in the OFD text to be rotated, and each value in the queue represents the offset value in the X direction between the subsequent character and the previous character. Σ△x[i] represents the summation of the numerical queue.
[0126] It should be noted that when △x does not appear, it means that the drawing point of the text does not shift in the X direction.
[0127] When the target rotation angle is 180 degrees, the calculation formula for the second precise displacement parameter is as follows:
[0128] f2=-Min(metrics[i].horiBearingY-metrics[i].height)+ptStart.y+ptStart.y–Max(metrics[i].horiBearingY);
[0129] Where f2 is the second displacement parameter corresponding to the target rotation angle of 180 degrees, Max(metrics[i].horiBearingY) represents the maximum value of horiBearingY of all characters in the OFD text to be rotated; Min(metrics[i].horiBearingY-metrics[i].height) represents the minimum value of horiBearingY-height of all characters in the OFD text to be rotated.
[0130] When the target rotation angle is 180 degrees, the formula for calculating the first estimated displacement parameter is:
[0131] e2=2×ptStart.x+Σ△x[i]+fontSize×(α_x[last]+α_x[0]); where α_y[last] represents the α_y value of the last character in the OFD text to be rotated.
[0132] When the target rotation angle is 180 degrees, the formula for calculating the second estimated displacement parameter is:
[0133] f2 = 2 × ptStart.y - fontSize × α_y[max]; where α_y[max] represents the maximum value of α_y for all characters in the OFD text to be rotated.
[0134] When the target rotation angle is 270 degrees, the formula for calculating the first precise displacement parameter is:
[0135] e3 = -(ptStart.y - Max(metrics[i].bearingY) - ptStart.x - metrics[0].bearingX); where e3 is the first displacement parameter corresponding to the target rotation angle of 270 degrees.
[0136] When the target rotation angle is 270 degrees, the formula for calculating the second precise displacement parameter is:
[0137] f3 = ptStart.x + metrics[0].bearingX + ptStart.y - Min(metrics[i].bearingY - metrics[i].height); f3 is the second displacement parameter corresponding to the target rotation angle of 270 degrees.
[0138] When the target rotation angle is 270 degrees, the formula for calculating the first estimated displacement parameter is:
[0139] e3 = -(ptStart.y – ptStart.x – fontSize × (α_x[max] + α_x[0])); where α_x[max] represents the maximum value of α_x for all characters in the OFD text to be rotated.
[0140] When the target rotation angle is 270 degrees, the formula for calculating the second estimated displacement parameter is:
[0141] f3=ptStart.y+ptStart.x+fontSize×(α_x[0]+1-α_y[max]).
[0142] It should be noted that, as Figure 6 As shown, after rotating 90 degrees, the width and height of the Boundary text box are swapped; therefore, the width and height values of the Boundary text box should be swapped accordingly. After rotating 180 degrees, the width and height of the Boundary text box do not change and do not need to be adjusted. After rotating 270 degrees, the width and height values of the Boundary text box should be swapped.
[0143] To better illustrate the technical solution of this embodiment, this embodiment uses a specific OFD text to illustrate the accurate calculation and estimation method of CTM (rotation parameters and displacement parameters) when a single line of text is rotated clockwise by 90 degrees, 180 degrees, and 270 degrees respectively.
[0144] 1. Rotate 90 degrees. See the OFD text to be rotated. Figure 7 The original CTM="1 0 0 1 0 0" enclosing rectangle Boundary="20 50 42.5 20" Font="168" indicates it's in Lishu font, text size Size="8.5", and color is black. ptStart.x=8.5, ptStart.y=12, the △x sequence is 8.5 8.5 8.5, and the text content is "A document".
[0145] ① Calculate CTM parameters.
[0146] Exact calculation formula: For the four values of a, b, c, and d, α = 90° can be directly substituted for calculation: a1 = 0; b1 = 1; c1 = -1; d1 = 0; Call the Api of the font library to obtain the bearingX, bearingY, width, and height values of each character. See Table 5 for details.
[0147] Table 5
[0148] character bearingX bearingY width height one 0.39 3.52 7.84 1.73 Chapter 0.2 5.51 8.1 5.38 arts 0.26 5.37 8.03 5.64 files 0.26 5.44 7.56 5.31
[0149] Calculate the value of e1:
[0150] e1 = ptStart.y – Min(metrics[i].bearingY - metrics[i].height) + ptStart.x + metrics[0].bearingX
[0151] = 12 – (-0.2635) + 8.5 + 0.39
[0152] = 21.15
[0153] Calculate the value of f1:
[0154] f1 = ptStart.y - Max(metrics[i].bearingY - ptStart.x – metrics[0].bearingX
[0155] = 12 - 5.51 – 8.5 – 0.39
[0156] = -2.40
[0157] The rotated OFD text is shown in Figure 8 ; The rotated text is displayed in black, and the result is shown in Figure 9 Figure 9 .
[0158] Estimation calculation formula:
[0159] For the values of a, b, c, and d, the same results as in the exact calculation can be directly obtained.
[0160] Estimate the value of e1, and the formula is: e1 = ptStart.y + ptStart.x + fontSize × α_x[0] × 0.1.
[0161] Looking up the table, it can be seen that "one" belongs to level 5, and the corresponding official script α_x = 0.8, then
[0162] e1 = 12 + 8.5 + 8.5 × 0.8 × 0.1 = 21.18;
[0163] Estimate the f1 value, the formula is: f1 = ptStart.y - ptStart.x – fontSize × (α_y[max] - α_x[0]); by looking up the α_y table, among the characters of "a document" in clerical script, "one" belongs to level 1, and "document" both belong to level 5. α_y[max] is the largest level 5, and the α_y[max] value corresponding to this level in clerical script is 0.6695. By looking up the α_x table, for the character "one" in clerical script, α_x[0] = 0.8 is obtained, and α_90_x[0] = α_x[0] × 0.1 = 0.08
[0164] f2 = 12 - 8.5 – 8.5 × (0.6695 - 0.08)
[0165] = -2.28
[0166] The rotated OFD text is shown in Figure 10 ; The rotated text is shown in red, and the result is shown in Figure 11 .
[0167] ② Adjust the Boundary value of the OFD TextObject object. The Boundary property of the text object: Boundary = "20 50 42.5 20", after swapping the width and height, Boundary = "20 50 20 42.5".
[0168] Second, rotate 180 degrees. The OFD text to be rotated is shown in Figure 12 .
[0169] The original CTM = "1 0 0 1 0 0", the bounding rectangle Boundary = "20 50 42.5 20", Font = "169" indicates Fangsong, the text size Size = "8.5", and the color is black.
[0170] ptStart.x = 8.5, ptStart.y = 12, the △x sequence is 8.5 8.5 8.5, and the text content is the characters "a document".
[0171] ① Calculate the CTM parameters
[0172] The exact calculation formula: for the four values of a2, b2, c2, and d2, it can be seen that α = 180° is directly substituted, and the calculation is: a2 = 0; b2 = -1; c2 = 1; d2 = 0;
[0173] As shown in Table 6, call the Api of the font library to obtain the bearingX, bearingY, width, and height values of each character.
[0174] Table 6
[0175] character bearingX bearingY width height one 0.09 5.91 2.54 5.91 Chapter 0.49 7.22 7.06 8.26 arts 0.66 7.07 7.22 7.79 files 0.58 7.07 7.04 7.95
[0176] Calculate the e2 value:
[0177] e2=ptStart.x+Σ△x[i]+metrics[n-1].bearingX+metrics[n-1].width+ptStart.x+metrics[0].bearingX
[0178] = 8.5 + (8.5 + 8.5 + 8.5) + 0.58 + 7.04 + 8.5 + 0.09
[0179] =50.21
[0180] Calculate the f2 value:
[0181] f2=-Min(metrics[i].horiBearingY-metrics[i].height)+ptStart.y+ptStart.y–Max(metrics[i].horiBearingY)
[0182] = -(-1.0455+12+12–7.22)
[0183] =17.83
[0184] See the rotated OFD text Figure 13 The rotated text is displayed in black; see the result. Figure 14 .
[0185] Estimation calculation formula:
[0186] The values of a, b, c, and d can be obtained directly, just like in the case of precise calculation.
[0187] The formula for e2 is:
[0188] e2=2×ptStart.x+Σ△x[i]+fontSize×(α_x[last]+α_x[0])
[0189] = 2 × 8.5 + 3 × 8.5 + 8.5 × (0.69 + 0.19)
[0190] =49.98
[0191] The formula for estimating the f2 value is:
[0192] f2=2×ptStart.y-fontSize×α_y[max]
[0193] = 2 × 12.5 + 8.5 * 0.85
[0194] =17.78
[0195] See the rotated OFD text Figure 15 The rotated text is displayed in red; see the results below. Figure 16 .
[0196] ② Adjust the Boundary value of the OFD TextObject object. After rotating 180 degrees, the width and height of the Boundary text box do not change and do not need to be adjusted.
[0197] 3. Rotate 270 degrees. See the OFD text to be rotated. Figure 17 .
[0198] The original CTM="1 0 0 1 0 0" enclosing rectangle Boundary="20 50 42.5 75" Font="175" indicates it is in SimSun format, with text size Size="8.5" and color black.
[0199] ptStart.x = 8.5, ptStart.y = 40, the △x sequence is 8.5 8.5 8.5, and the text content is "a document".
[0200] ① Calculate CTM parameters
[0201] Precise calculation formula: For the four values a3, b3, c3, and d3, we can see that α = 270°. Directly substitute the values and calculate: a3 = 0; b3 = -1; c3 = 1; d3 = 0. As shown in Table 7, call the font library's API to obtain the bearingX, bearingY, width, and height values of each character.
[0202] Table 7
[0203] character bearingX bearingY width height one 0.7 3.89 7 0.96 Chapter 0.49 7.22 7.06 8.26 arts 0.66 7.07 7.22 7.79 files 0.58 7.07 7.04 7.95
[0204] Calculate the e3 value:
[0205] e3=-(ptStart.y-Max(metrics[i].bearingY)-ptStart.x-metrics[0].bearingX);
[0206] =-(40–7.22–8.5–0.70)
[0207] = -23.59
[0208] Calculate the f3 value:
[0209] f3=ptStart.x+metrics[0].bearingX+ptStart.y-Min(metrics[i].bearingY-metrics[i].height)
[0210] =8.5 + 0.094 + 40 – (-1.046)
[0211] =49.64
[0212] See the rotated OFD text Figure 18 The rotated text is displayed in black; see the result. Figure 19 .
[0213] Estimation formula: The values of a3, b3, c3, and d3 can be obtained directly, just like in the case of precise calculation.
[0214] The formula for e3 is as follows:
[0215] e3=-(ptStart.y–ptStart.x-fontSize×(α_x[max]+α_x[0]))
[0216] = -(40 – 8.5 – 8.5 × (0.608 + 0.19))
[0217] = -24.72
[0218] The formula for estimating the f3 value is:
[0219] f3=ptStart.y+ptStart.x+fontSize×(α_x[0]+1-α_y[max])
[0220] =40 + 8.5 + 8.5 × (0.19 + 1 - 0.85)
[0221] =51.39
[0222] See the rotated OFD text Figure 20 The rotated text is displayed in red; see the results below. Figure 21 .
[0223] ② Adjust the Boundary value of the OFD TextObject object. For example... Figure 8 As shown, after rotating 270 degrees, the width and height of the Boundary text box should be swapped. Boundary="20 50 42.5 75" becomes Boundary="20 50 75 42.5".
[0224] The technical solution of this embodiment effectively avoids the error caused by the text box not being close to the text during rotation by rotating the text in the OFD document. It realizes text rotation without relying on code and font library interface, and has a better visual effect.
[0225] like Figure 22 As shown, an OFD document text rotation and positioning system 200 according to an embodiment of the present invention includes: an acquisition module 210, a processing module 220, a calculation module 230 and an operation module 240;
[0226] The acquisition module 210 is used to: acquire the target text box of the OFD text to be rotated at its original position;
[0227] The processing module 220 is used to: obtain the target text box containing the OFD text to be rotated based on the target rotation angle and according to the rotation parameters of the target text box, to obtain the first rotation position of the OFD text to be rotated;
[0228] The calculation module 230 is used to: calculate the displacement parameters of the target text box based on the original close rectangle of the OFD text to be rotated at the original position and the first close rectangle of the OFD text to be rotated at the first rotation position;
[0229] The running module 240 is used to: move the target text box containing the OFD text to be rotated according to the displacement parameters, so as to obtain the target rotation position of the OFD text to be rotated.
[0230] Preferably, the target text box is a Boundary text box.
[0231] Preferably, each target rotation angle corresponds to a set of rotation parameters; the processing module 220 is specifically used for:
[0232] The top left corner of the target text box is selected as the rotation point, and the target text box is controlled to rotate around the rotation point according to a set of rotation parameters corresponding to the target rotation angle, so as to obtain the first rotation position of the OFD text to be rotated.
[0233] Preferably, the displacement parameters include: a first displacement parameter and a second displacement parameter;
[0234] The computing module 230 is specifically used for:
[0235] The first displacement parameter of the target text box is calculated according to the first precise displacement parameter calculation formula, the original close-fitting rectangle and the first close-fitting rectangle; or, the first displacement parameter of the target text box is calculated according to the first estimated displacement parameter calculation formula, the original close-fitting rectangle and the first close-fitting rectangle.
[0236] The second displacement parameter of the target text box is calculated based on the second precise displacement parameter calculation formula, the original close-fitting rectangle, and the first close-fitting rectangle; or, the second displacement parameter of the target text box is calculated based on the second estimated displacement parameter calculation formula, the original close-fitting rectangle, and the first close-fitting rectangle.
[0237] The technical solution of this embodiment effectively avoids the error caused by the text box not being close to the text during rotation by rotating the text in the OFD document. It realizes text rotation without relying on code and font library interface, and has a better visual effect.
[0238] The parameters and steps for implementing the corresponding functions of each module in the OFD document text rotation and positioning system 200 described above in this embodiment can be referred to the parameters and steps in the embodiment of the OFD document text rotation and positioning method described above, and will not be repeated here.
[0239] An embodiment of the present invention provides a storage medium, comprising: the storage medium storing instructions, which, when a computer reads the instructions, cause the computer to execute steps such as a text rotation and positioning method for an OFD document. For details, please refer to the parameters and steps in the embodiment of the text rotation and positioning method for an OFD document described above, which will not be repeated here.
[0240] Computer storage media include, for example, USB flash drives and external hard drives.
[0241] Those skilled in the art will know that the present invention can be implemented as a method, system, and storage medium.
[0242] Therefore, the present invention can be implemented in the following forms: it can be entirely hardware, entirely software (including firmware, resident software, microcode, etc.), or a combination of hardware and software, generally referred to herein as a "circuit," "module," or "system." Furthermore, in some embodiments, the present invention can also be implemented as a computer program product contained in one or more computer-readable media, which contains computer-readable program code. Any combination of one or more computer-readable media can be used. The computer-readable medium can be a computer-readable signal medium or a computer-readable storage medium. The computer-readable storage medium can be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination thereof. More specific examples (a non-exhaustive list) of computer-readable storage media include: an electrical connection having one or more wires, a portable computer disk, a hard disk, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage device, magnetic storage device, or any suitable combination thereof. In this document, a computer-readable storage medium can be any tangible medium that contains or stores a program that can be used by or in conjunction with an instruction execution system, apparatus, or device. Although embodiments of the invention have been shown and described above, it is to be understood that these embodiments are exemplary and should not be construed as limiting the invention. Those skilled in the art can make changes, modifications, substitutions, and variations to the above embodiments within the scope of the invention.
Claims
1. A method for rotating and positioning text in an OFD document, characterized in that, include: Get the target text box at the original position of the OFD text to be rotated; Based on the target rotation angle, the target text box containing the OFD text to be rotated is rotated according to the rotation parameters of the target text box to obtain the first rotation position of the OFD text to be rotated. The displacement parameters of the target text box are calculated based on the original close rectangle of the OFD text to be rotated at the original position and the first close rectangle of the OFD text to be rotated at the first rotation position. Based on the displacement parameters, the target text box containing the OFD text to be rotated is moved to obtain the target rotation position of the OFD text to be rotated. Each target rotation angle corresponds to a set of rotation parameters; the step of rotating the target text box containing the OFD text to be rotated according to the rotation parameters of the target text box to obtain the first rotation position of the OFD text to be rotated includes: Select the top left corner of the target text box as the rotation point, and control the target text box to rotate around the rotation point according to a set of rotation parameters corresponding to the target rotation angle, so as to obtain the first rotation position of the OFD text to be rotated; The displacement parameters include: a first displacement parameter and a second displacement parameter; The step of calculating the displacement parameters of the target text box based on the original close rectangle of the OFD text to be rotated at the original position and the first close rectangle of the OFD text to be rotated at the first rotation position includes: The first displacement parameter of the target text box is calculated according to the first precise displacement parameter calculation formula, the original close-fitting rectangle and the first close-fitting rectangle; or, the first displacement parameter of the target text box is calculated according to the first estimated displacement parameter calculation formula, the original close-fitting rectangle and the first close-fitting rectangle. The second displacement parameter of the target text box is calculated according to the second precise displacement parameter calculation formula, the original close-fitting rectangle and the first close-fitting rectangle; or, the second displacement parameter of the target text box is calculated according to the second estimated displacement parameter calculation formula, the original close-fitting rectangle and the first close-fitting rectangle. The OFD text to be rotated includes: at least one target character, wherein the target rotation angle is: 90 degrees, 180 degrees or 270 degrees; When the target rotation angle is 90 degrees, the formula for calculating the first precise displacement parameter is: e1=ptStart.y-Min(metrics[i].bearingY-metrics[i].height)+ptStart.x+metrics[0].bearingX; where e1 is the first displacement parameter corresponding to the target rotation angle of 90 degrees, ptStart.y is the X coordinate of the font base point of the first character in the OFD text to be rotated in the object coordinate system, and ptStart.x is the X coordinate of the font base point of the first character in the OFD text to be rotated in the object coordinate system. The Y-coordinate is given below, metrics[i] represents the specification of the i-th font in the OFD text to be rotated, bearingY represents the text measurement value in the Y direction, bearingX represents the text measurement value in the X direction, height represents the text measurement height value, Min(metrics[i].bearingY-metrics[i].height) represents the minimum value of the bearingY-height value of each character in the OFD text to be rotated, and metrics[0].bearingX represents the text measurement value of the first character in the OFD text to be rotated in the X direction; When the target rotation angle is 90 degrees, the formula for calculating the second precise displacement parameter is: f1 = ptStart.y - Max(metrics[i].bearingY) - ptStart.x - metrics[0].bearingX; where f1 is the second displacement parameter corresponding to the target rotation angle of 90 degrees, and Max(metrics[i].bearingY) represents the maximum value of bearingY among all characters in the OFD text to be rotated; When the target rotation angle is 90 degrees, the formula for calculating the first estimated displacement parameter is: e1=ptStart.y+ptStart.x+fontSize×α_x[0]×0.1; where, fontSize is the font size of the OFD text to be rotated, α_x[0] represents the α_x value of the first character in the OFD text to be rotated, and α_x represents the ratio of the width of different characters to the fontSize of the corresponding character in the OFD text to be rotated; When the target rotation angle is 90 degrees, the formula for calculating the second estimated displacement parameter is: f1 = ptStart.y - ptStart.x - fontSize × (α_y[max] - α_x[0]); where α_y[max] represents the maximum value of α_y among all characters in the OFD text to be rotated; When the target rotation angle is 180 degrees, the formula for calculating the first precise displacement parameter is: e2=ptStart.x+Σ△x[i]+metrics[n-1].bearingX+metrics[n-1].width+ptStart.x +metrics[0].bearingX; where e2 is the first displacement parameter corresponding to the target rotation angle of 180 degrees, metrics[0] represents the first character of the OFD text to be rotated, metrics[n-1] represents the last character of the OFD text to be rotated, △x is a double-type numerical queue in the OFD text to be rotated, each value in the queue represents the offset value between the next character and the previous character in the X direction, and Σ△x[i] represents the summation of the numerical queue; When the target rotation angle is 180 degrees, the formula for calculating the second precise displacement parameter is: f2 = -Min(metrics[i].horiBearingY - metrics[i].height) + ptStart.y + ptStart.y – Max(metrics[i].horiBearingY); where f2 is the second displacement parameter corresponding to the target rotation angle of 180 degrees, Max(metrics[i].horiBearingY) represents the maximum value of horiBearingY among all characters in the OFD text to be rotated, and Min(metrics[i].horiBearingY - metrics[i].height) represents the minimum value of horiBearingY – height among all characters in the OFD text to be rotated. When the target rotation angle is 180 degrees, the formula for calculating the first estimated displacement parameter is: e2=2×ptStart.x+Σ△x[i]+fontSize×(α_x[last]+α_x[0]); where α_y[last] represents the α_y value of the last character in the OFD text to be rotated; When the target rotation angle is 180 degrees, the formula for calculating the second estimated displacement parameter is: f2 = 2 × ptStart.y - fontSize × α_y[max]; where α_y[max] represents the maximum value of α_y for all characters in the OFD text to be rotated; When the target rotation angle is 270 degrees, the formula for calculating the first precise displacement parameter is: e3 = -(ptStart.y - Max(metrics[i].bearingY) - ptStart.x - metrics[0].bearingX); where e3 is the first displacement parameter corresponding to the target rotation angle of 270 degrees; When the target rotation angle is 270 degrees, the formula for calculating the second precise displacement parameter is: f3 = ptStart.x + metrics[0].bearingX + ptStart.y - Min(metrics[i].bearingY - metrics[i].height); f3 is the second displacement parameter corresponding to the target rotation angle of 270 degrees; When the target rotation angle is 270 degrees, the formula for calculating the first estimated displacement parameter is: e3 = -(ptStart.y – ptStart.x – fontSize × (α_x[max] + α_x[0])); where α_x[max] represents the maximum value of α_x for all characters in the OFD text to be rotated; When the target rotation angle is 270 degrees, the formula for calculating the second estimated displacement parameter is: f3=ptStart.y+ptStart.x+fontSize×(α_x[0]+1-α_y[max]).
2. The method for text rotation and positioning in an OFD document according to claim 1, characterized in that, The target text box is the Boundary text box.
3. A text rotation and positioning system for OFD documents, characterized in that, include: The module consists of an acquisition module, a processing module, a calculation module, and an execution module. The acquisition module is used to: acquire the target text box of the OFD text to be rotated at its original position; The processing module is used to: obtain the target text box containing the OFD text to be rotated based on the target rotation angle and according to the rotation parameters of the target text box, to obtain the first rotation position of the OFD text to be rotated; The calculation module is used to: calculate the displacement parameters of the target text box based on the original close rectangle of the OFD text to be rotated at the original position and the first close rectangle of the OFD text to be rotated at the first rotation position; The running module is used to: move the target text box containing the OFD text to be rotated according to the displacement parameters, so as to obtain the target rotation position of the OFD text to be rotated; Each target rotation angle corresponds to a set of rotation parameters; the processing module is specifically used for: Select the top left corner of the target text box as the rotation point, and control the target text box to rotate around the rotation point according to a set of rotation parameters corresponding to the target rotation angle, so as to obtain the first rotation position of the OFD text to be rotated; The displacement parameters include: a first displacement parameter and a second displacement parameter; The calculation module is specifically used for: The first displacement parameter of the target text box is calculated according to the first precise displacement parameter calculation formula, the original close-fitting rectangle and the first close-fitting rectangle; or, the first displacement parameter of the target text box is calculated according to the first estimated displacement parameter calculation formula, the original close-fitting rectangle and the first close-fitting rectangle. The second displacement parameter of the target text box is calculated according to the second precise displacement parameter calculation formula, the original close-fitting rectangle and the first close-fitting rectangle; or, the second displacement parameter of the target text box is calculated according to the second estimated displacement parameter calculation formula, the original close-fitting rectangle and the first close-fitting rectangle. The OFD text to be rotated includes: at least one target character, wherein the target rotation angle is: 90 degrees, 180 degrees or 270 degrees; When the target rotation angle is 90 degrees, the formula for calculating the first precise displacement parameter is: e1=ptStart.y-Min(metrics[i].bearingY-metrics[i].height)+ptStart.x+metrics[0].bearingX; where e1 is the first displacement parameter corresponding to the target rotation angle of 90 degrees, ptStart.y is the X coordinate of the font base point of the first character in the OFD text to be rotated in the object coordinate system, and ptStart.x is the X coordinate of the font base point of the first character in the OFD text to be rotated in the object coordinate system. The Y-coordinate is given below, metrics[i] represents the specification of the i-th font in the OFD text to be rotated, bearingY represents the text measurement value in the Y direction, bearingX represents the text measurement value in the X direction, height represents the text measurement height value, Min(metrics[i].bearingY-metrics[i].height) represents the minimum value of the bearingY-height value of each character in the OFD text to be rotated, and metrics[0].bearingX represents the text measurement value of the first character in the OFD text to be rotated in the X direction; When the target rotation angle is 90 degrees, the formula for calculating the second precise displacement parameter is: f1 = ptStart.y - Max(metrics[i].bearingY) - ptStart.x - metrics[0].bearingX; where f1 is the second displacement parameter corresponding to the target rotation angle of 90 degrees, and Max(metrics[i].bearingY) represents the maximum value of bearingY among all characters in the OFD text to be rotated; When the target rotation angle is 90 degrees, the formula for calculating the first estimated displacement parameter is: e1=ptStart.y+ptStart.x+fontSize×α_x[0]×0.1; where, fontSize is the font size of the OFD text to be rotated, α_x[0] represents the α_x value of the first character in the OFD text to be rotated, and α_x represents the ratio of the width of different characters to the fontSize of the corresponding character in the OFD text to be rotated; When the target rotation angle is 90 degrees, the formula for calculating the second estimated displacement parameter is: f1 = ptStart.y - ptStart.x - fontSize × (α_y[max] - α_x[0]); where α_y[max] represents the maximum value of α_y among all characters in the OFD text to be rotated; When the target rotation angle is 180 degrees, the formula for calculating the first precise displacement parameter is: e2=ptStart.x+Σ△x[i]+metrics[n-1].bearingX+metrics[n-1].width+ptStart.x +metrics[0].bearingX; where e2 is the first displacement parameter corresponding to the target rotation angle of 180 degrees, metrics[0] represents the first character of the OFD text to be rotated, metrics[n-1] represents the last character of the OFD text to be rotated, △x is a double-type numerical queue in the OFD text to be rotated, each value in the queue represents the offset value between the next character and the previous character in the X direction, and Σ△x[i] represents the summation of the numerical queue; When the target rotation angle is 180 degrees, the formula for calculating the second precise displacement parameter is: f2 = -Min(metrics[i].horiBearingY - metrics[i].height) + ptStart.y + ptStart.y – Max(metrics[i].horiBearingY); where f2 is the second displacement parameter corresponding to the target rotation angle of 180 degrees, Max(metrics[i].horiBearingY) represents the maximum value of horiBearingY among all characters in the OFD text to be rotated, and Min(metrics[i].horiBearingY - metrics[i].height) represents the minimum value of horiBearingY – height among all characters in the OFD text to be rotated. When the target rotation angle is 180 degrees, the formula for calculating the first estimated displacement parameter is: e2=2×ptStart.x+Σ△x[i]+fontSize×(α_x[last]+α_x[0]); where α_y[last] represents the α_y value of the last character in the OFD text to be rotated; When the target rotation angle is 180 degrees, the formula for calculating the second estimated displacement parameter is: f2 = 2 × ptStart.y - fontSize × α_y[max]; where α_y[max] represents the maximum value of α_y for all characters in the OFD text to be rotated; When the target rotation angle is 270 degrees, the formula for calculating the first precise displacement parameter is: e3 = -(ptStart.y - Max(metrics[i].bearingY) - ptStart.x - metrics[0].bearingX); where e3 is the first displacement parameter corresponding to the target rotation angle of 270 degrees; When the target rotation angle is 270 degrees, the formula for calculating the second precise displacement parameter is: f3 = ptStart.x + metrics[0].bearingX + ptStart.y - Min(metrics[i].bearingY - metrics[i].height); f3 is the second displacement parameter corresponding to the target rotation angle of 270 degrees; When the target rotation angle is 270 degrees, the formula for calculating the first estimated displacement parameter is: e3 = -(ptStart.y – ptStart.x – fontSize × (α_x[max] + α_x[0])); where α_x[max] represents the maximum value of α_x for all characters in the OFD text to be rotated; When the target rotation angle is 270 degrees, the formula for calculating the second estimated displacement parameter is: f3=ptStart.y+ptStart.x+fontSize×(α_x[0]+1-α_y[max]).
4. The text rotation and positioning system for OFD documents according to claim 3, characterized in that, The target text box is the Boundary text box.
5. A storage medium, characterized in that, The storage medium stores instructions that, when read by a computer, cause the computer to execute a text rotation and positioning method for an OFD document as described in claim 1 or 2.
Citation Information
Patent Citations
Picture information structuring method and device, equipment and medium
CN113850208A
Using a layout engine to display an overflowed textbox
US20120110441A1