CN-115641590-B - Word rotation positioning method, system and storage medium of OFD document
Abstract
The invention relates to a text rotation positioning method, a text rotation positioning system and a storage medium of an OFD document, which comprise the steps of obtaining a target text box of an OFD text to be rotated at an original position; the method comprises the steps of obtaining a target text box based on a target rotation angle, rotating the target text box according to rotation parameters of the target text box to obtain a first rotation position of an OFD text to be rotated, calculating displacement parameters of the target text box according to a close rectangle of the OFD text to be rotated at an original position and a close rectangle of the OFD text to be rotated at the first rotation position, and moving the target text box containing the OFD text to be rotated according to the displacement parameters to obtain the target rotation position of the OFD text to be rotated. According to the invention, by rotating the characters of the OFD document, errors caused by the fact that the text box is not clung to the characters during rotation are effectively avoided, the characters are rotated independently of codes and a character library interface, and a better visual effect is achieved.
Inventors
- KANG KAI
- Ma Erqun
Assignees
- 福昕鲲鹏(北京)信息科技有限公司
Dates
- Publication Date
- 20260505
- Application Date
- 20220902
Claims (5)
- 1. The word rotation positioning method of the OFD document is characterized by comprising the following steps of: Acquiring a target text box of the OFD text to be rotated at an original position; Based on a target rotation angle, obtaining and rotating the target text box containing the OFD text to be rotated according to rotation parameters of the target text box, and obtaining a first rotation position of the OFD text to be rotated; according to 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, calculating to obtain the displacement parameter of the target text box; According to the displacement parameters, moving the target text box containing the OFD text to be rotated to obtain a target rotation position of the OFD text to be rotated; and rotating the target text box containing the OFD text to be rotated according to the rotation parameters of the target text box to obtain a first rotation position of the OFD text to be rotated, wherein the first rotation position comprises: selecting the upper left corner of the target text box as a rotation point, and controlling the target text box to rotate at the rotation point according to a group of rotation parameters corresponding to the target rotation angle to obtain the first rotation position of the OFD text to be rotated; the displacement parameters comprise a first displacement parameter and a second displacement parameter; The calculating to obtain the displacement parameter of the target text box according to 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 comprises the following steps: according to a first accurate displacement parameter calculation formula, the original close rectangle and the first close rectangle, calculating to obtain a first displacement parameter of the target text box, or according to a first estimated displacement parameter calculation formula, the original close rectangle and the first close rectangle, calculating to obtain a first displacement parameter of the target text box; according to a second accurate displacement parameter calculation formula, the original close rectangle and the first close rectangle, calculating to obtain a second displacement parameter of the target text box, or according to a second estimated displacement parameter calculation formula, the original close rectangle and the first close rectangle, calculating to obtain a second displacement parameter of the target text box; the OFD text to be rotated comprises 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 first accurate displacement parameter calculation formula is e 1 =ptStart.y-Min (metrics [ i ]. BearingY-metrics [ i ]. Height) +ptStart.x+metrics [0]. BearingX, wherein e 1 is a first displacement parameter corresponding to the target rotation angle being 90 degrees, ptStart.y is an X coordinate of a character base point of a first character in the OFD text to be rotated under an object coordinate system, ptStart.x is a Y coordinate of a character base point of the first character in the OFD text to be rotated under the object coordinate system, metrics [ i ] represents a specification of an ith character in the OFD text to be rotated, bearingY represents a character metric value in the Y direction, bearingX represents a character metric value in the X direction, min (metrics [ i ]. 24-i ] represents a character in the Y direction, 62 h [ i ]. 62) represents a character in the first character in the OFD text to be rotated, and Min [ i ]. 62 represents a character in the Y direction; when the target rotation angle is 90 degrees, the second accurate displacement parameter calculation formula is: f 1 = ptstart.y-Max (metrics [ i ]. BearingY) -ptstart.x-metrics [0]. BearingX ], wherein f 1 is a second displacement parameter corresponding to the target rotation angle being 90 degrees, and Max (metrics [ i ]. BearingY) represents the maximum value of bearingY in all characters in the OFD text to be rotated; When the target rotation angle is 90 degrees, the first estimated displacement parameter calculation formula is: e 1 = ptstart.y + ptstart.x + fontSize x alpha x 0 x 0.1, wherein fontSize is the font size of the OFD text to be rotated, alpha x 0 represents the alpha x value of the first character in the OFD text to be rotated, alpha x represents the ratio of the width of the different characters to fontSize of the corresponding character in the OFD text to be rotated; When the target rotation angle is 90 degrees, the second estimated displacement parameter calculation formula is: f 1 = ptstart.y-ptstart.x-fontSize x (α_ymax- α_x0 ]), where α_ymax represents the maximum of the α_y values of all characters in the OFD text to be rotated; When the target rotation angle is 180 degrees, the first accurate displacement parameter calculation formula is: e 2 =ptStart.x+Σ△x[i]+metrics[n-1].bearingX+metrics[n-1].width+ptStart.x +metrics[0].bearingX; Wherein e 2 is a 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, deltax is a double-type numerical value queue in the OFD text to be rotated, each value in the queue represents an offset value between a next character and a previous character in the X direction, and Sigma Deltax [ i ] represents summation of the numerical value queues; When the target rotation angle is 180 degrees, the second accurate displacement parameter calculation formula is: f 2 =-Min(metrics[i].horiBearingY-metrics[i].height)+ptStart.y+ptStart.y–Max(metrics[i].horiBearingY); Wherein f 2 is a second displacement parameter corresponding to the target rotation angle of 180 degrees, max (metrics [ i ]. HoriBearingY) represents a maximum value in horiBearingY of all characters in the OFD text to be rotated, min (metrics [ i ]. HoriBearingY-metrics [ i ]. Height) represents a minimum value in horiBearingY-height of all characters in the OFD text to be rotated; when the target rotation angle is 180 degrees, the first estimated displacement parameter calculation formula is: e 2 = 2 x ptstart. X + ΣΔx [ i ] + fontSize x (α_x [ last ] +α_x0 ]), wherein α_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 second estimated displacement parameter calculation formula is: f 2 =2×ptstart.y-fontSize ×α_y [ max ], wherein α_y [ max ] represents the maximum value of α_y values of all characters in the OFD text to be rotated; when the target rotation angle is 270 degrees, the first accurate displacement parameter calculation formula is: e 3 = - (ptstart.y-Max (metrics [ i ]. BearingY) -ptstart.x-metrics [0]. BearingX), wherein e 3 is a first displacement parameter corresponding to the target rotation angle being 270 degrees; when the target rotation angle is 270 degrees, the second accurate displacement parameter calculation formula is: f 3 =ptStart.x+metrics[0].bearingX+ptStart.y-Min(metrics[i].bearingY-metrics[i].height);f 3 The second displacement parameter is corresponding to the target rotation angle of 270 degrees; When the target rotation angle is 270 degrees, the first estimated displacement parameter calculation formula is: e 3 = - (ptstart.y-ptstart.x-fontSize x (α_x [ max ] +α_x [0 ])), wherein α_x [ max ] represents the maximum value of α_x values of all characters in the OFD text to be rotated; when the target rotation angle is 270 degrees, the second estimated displacement parameter calculation formula is: f 3 =ptStart.y+ptStart.x+fontSize×(α_x[0]+1-α_y[max])。
- 2. The method for locating the rotation of characters of an OFD document according to claim 1, wherein the target text box is a Boundary text box.
- 3. The word rotary positioning system of the OFD document is characterized by comprising an acquisition module, a processing module, a calculation module and an operation module; the acquisition module is used for acquiring a target text box of the OFD text to be rotated at the original position; The processing module is used for obtaining and rotating 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 a first rotation position of the OFD text to be rotated; the calculation module is used for calculating displacement parameters of the target text box according to 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 operation module is used for moving the target text box containing the OFD text to be rotated according to the displacement parameter to obtain a target rotation position of the OFD text to be rotated; Each target rotation angle corresponds to a group of rotation parameters, and the processing module is specifically configured to: selecting the upper left corner of the target text box as a rotation point, and controlling the target text box to rotate at the rotation point according to a group of rotation parameters corresponding to the target rotation angle to obtain the first rotation position of the OFD text to be rotated; the displacement parameters comprise a first displacement parameter and a second displacement parameter; The computing module is specifically configured to: according to a first accurate displacement parameter calculation formula, the original close rectangle and the first close rectangle, calculating to obtain a first displacement parameter of the target text box, or according to a first estimated displacement parameter calculation formula, the original close rectangle and the first close rectangle, calculating to obtain a first displacement parameter of the target text box; according to a second accurate displacement parameter calculation formula, the original close rectangle and the first close rectangle, calculating to obtain a second displacement parameter of the target text box, or according to a second estimated displacement parameter calculation formula, the original close rectangle and the first close rectangle, calculating to obtain a second displacement parameter of the target text box; the OFD text to be rotated comprises 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 first accurate displacement parameter calculation formula is e 1 =ptStart.y-Min (metrics [ i ]. BearingY-metrics [ i ]. Height) +ptStart.x+metrics [0]. BearingX, wherein e 1 is a first displacement parameter corresponding to the target rotation angle being 90 degrees, ptStart.y is an X coordinate of a character base point of a first character in the OFD text to be rotated under an object coordinate system, ptStart.x is a Y coordinate of a character base point of the first character in the OFD text to be rotated under the object coordinate system, metrics [ i ] represents a specification of an ith character in the OFD text to be rotated, bearingY represents a character metric value in the Y direction, bearingX represents a character metric value in the X direction, min (metrics [ i ]. 24-i ] represents a character in the Y direction, 62 h [ i ]. 62) represents a character in the first character in the OFD text to be rotated, and Min [ i ]. 62 represents a character in the Y direction; when the target rotation angle is 90 degrees, the second accurate displacement parameter calculation formula is: f 1 = ptstart.y-Max (metrics [ i ]. BearingY) -ptstart.x-metrics [0]. BearingX ], wherein f 1 is a second displacement parameter corresponding to the target rotation angle being 90 degrees, and Max (metrics [ i ]. BearingY) represents the maximum value of bearingY in all characters in the OFD text to be rotated; When the target rotation angle is 90 degrees, the first estimated displacement parameter calculation formula is: e 1 = ptstart.y + ptstart.x + fontSize x alpha x 0 x 0.1, wherein fontSize is the font size of the OFD text to be rotated, alpha x 0 represents the alpha x value of the first character in the OFD text to be rotated, alpha x represents the ratio of the width of the different characters to fontSize of the corresponding character in the OFD text to be rotated; When the target rotation angle is 90 degrees, the second estimated displacement parameter calculation formula is: f 1 = ptstart.y-ptstart.x-fontSize x (α_ymax- α_x0 ]), where α_ymax represents the maximum of the α_y values of all characters in the OFD text to be rotated; When the target rotation angle is 180 degrees, the first accurate displacement parameter calculation formula is: e 2 =ptStart.x+Σ△x[i]+metrics[n-1].bearingX+metrics[n-1].width+ptStart.x +metrics[0].bearingX; Wherein e 2 is a 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, deltax is a double-type numerical value queue in the OFD text to be rotated, each value in the queue represents an offset value between a next character and a previous character in the X direction, and Sigma Deltax [ i ] represents summation of the numerical value queues; When the target rotation angle is 180 degrees, the second accurate displacement parameter calculation formula is: f 2 =-Min(metrics[i].horiBearingY-metrics[i].height)+ptStart.y+ptStart.y–Max(metrics[i].horiBearingY); Wherein f 2 is a second displacement parameter corresponding to the target rotation angle of 180 degrees, max (metrics [ i ]. HoriBearingY) represents a maximum value in horiBearingY of all characters in the OFD text to be rotated, min (metrics [ i ]. HoriBearingY-metrics [ i ]. Height) represents a minimum value in horiBearingY-height of all characters in the OFD text to be rotated; when the target rotation angle is 180 degrees, the first estimated displacement parameter calculation formula is: e 2 = 2 x ptstart. X + ΣΔx [ i ] + fontSize x (α_x [ last ] +α_x0 ]), wherein α_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 second estimated displacement parameter calculation formula is: f 2 =2×ptstart.y-fontSize ×α_y [ max ], wherein α_y [ max ] represents the maximum value of α_y values of all characters in the OFD text to be rotated; when the target rotation angle is 270 degrees, the first accurate displacement parameter calculation formula is: e 3 = - (ptstart.y-Max (metrics [ i ]. BearingY) -ptstart.x-metrics [0]. BearingX), wherein e 3 is a first displacement parameter corresponding to the target rotation angle being 270 degrees; when the target rotation angle is 270 degrees, the second accurate displacement parameter calculation formula is: f 3 =ptStart.x+metrics[0].bearingX+ptStart.y-Min(metrics[i].bearingY-metrics[i].height);f 3 The second displacement parameter is corresponding to the target rotation angle of 270 degrees; When the target rotation angle is 270 degrees, the first estimated displacement parameter calculation formula is: e 3 = - (ptstart.y-ptstart.x-fontSize x (α_x [ max ] +α_x [0 ])), wherein α_x [ max ] represents the maximum value of α_x values of all characters in the OFD text to be rotated; when the target rotation angle is 270 degrees, the second estimated displacement parameter calculation formula is: f 3 =ptStart.y+ptStart.x+fontSize×(α_x[0]+1-α_y[max])。
- 4. A text rotational positioning system of an OFD document according to claim 3, wherein the target text box is a Boundary text box.
- 5. A storage medium having stored therein instructions which, when read by a computer, cause the computer to perform a text rotation positioning method of an OFD document according to claim 1 or 2.
Description
Word rotation positioning method, system and storage medium of OFD document Technical Field The invention relates to the technical field of IT digitization, in particular to a text rotation positioning method, a text rotation positioning system and a storage medium of an OFD document. Background At present, when characters (character strings) in an OFD document are rotated, two common ways are that one is to combine CharDirection and ReadDirection attributes, and the other is to adjust CTMs in text objects ("current transformation matrix Current Transformation Matrix"). The former is relatively simple but not flexible enough, and the latter is very flexible but somewhat computationally complex. OFD is a plate document that is characterized by ease of viewing but difficult editing (e.g., PDF is a format file that is generally not easily edited). The function of the OFD browsing software for editing the OFD file is usually weak, for example, the OFD browsing software performs editing operations such as rotation and movement on the text, and the OFD browsing software does not usually provide these functions. For professional OFD editors, the characteristic that an OFD file is also a zip compression file is often utilized, the OFD file is decompressed by a decompression tool, and then the (xml) file content is directly modified to adjust the OFD file. In the case of manual modification, the code cannot be relied upon to calculate the individual parameters in the CTM. Accordingly, there is a need to provide a solution to the above-mentioned problems. Disclosure of Invention In order to solve the technical problems, the invention provides a text rotation positioning method, a text rotation positioning system and a storage medium of an OFD document. The technical scheme of the text rotation positioning method of the OFD document is as follows: Acquiring a target text box of the OFD text to be rotated at an original position; Based on a target rotation angle, obtaining and rotating the target text box containing the OFD text to be rotated according to rotation parameters of the target text box, and obtaining a first rotation position of the OFD text to be rotated; according to 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, calculating to obtain the displacement parameter of the target text box; and moving the target text box containing the OFD text to be rotated according to the displacement parameter to obtain a target rotation position of the OFD text to be rotated. The word rotation positioning method of the OFD document has the following beneficial effects: According to the method, the text of the OFD document is rotated, so that errors caused by the fact that the text box is not clung to the text during rotation are effectively avoided. In addition, the text is rotated independently of codes and a word stock interface, and a better visual effect is achieved. On the basis of the scheme, the text rotation positioning method of the OFD document can be improved as follows. Further, the target text box is a Boundary text box. Further, each target rotation angle corresponds to a set of rotation parameters, and the rotating the target text box containing the OFD text to be rotated according to the rotation parameters of the target text box to obtain a first rotation position of the OFD text to be rotated includes: And selecting the upper left corner of the target text box as a rotation point, and controlling the target text box to rotate at the rotation point according to a group of rotation parameters corresponding to the target rotation angle to obtain the first rotation position of the OFD text to be rotated. Further, the displacement parameters comprise a first displacement parameter and a second displacement parameter; The calculating to obtain the displacement parameter of the target text box according to 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 comprises the following steps: according to a first accurate displacement parameter calculation formula, the original close rectangle and the first close rectangle, calculating to obtain a first displacement parameter of the target text box, or according to a first estimated displacement parameter calculation formula, the original close rectangle and the first close rectangle, calculating to obtain a first displacement parameter of the target text box; And calculating to obtain a second displacement parameter of the target text box according to a second accurate displacement parameter calculation formula, the original close rectangle and the first close rectangle, or calculating to obtain a second displacement parameter of the target text box according to a second estimated displacement parameter calculation for