Text typesetting method and device, equipment and storage medium

By calculating the baseline height and width increment of the italic font, the layout width of the inclined characters is accurately calculated, which solves the problem of inaccurate italic font width calculation in the existing technology, ensures the reasonable setting of the text display area, and improves the accuracy of typesetting and user experience.

CN120671656APending Publication Date: 2025-09-19CTRIP TRAVEL NETWORK TECH SHANGHAI0
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510757568.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-06-06
Publication Date
2025-09-19

AI Technical Summary

Technical Problem

Existing typesetting methods lack the precise calculation of italic font width, resulting in improper setting of the text display area size, affecting the integrity and visual effect of the content.

Method used

By obtaining the style attributes of the input text, including font type, font size, and oblique angle, calculating the baseline height and width increment of oblique characters, and accumulating the typeset width of the characters to obtain the total typeset width, the accurate setting of the display area is ensured.

Benefits of technology

Significantly improves typographic accuracy, avoids text truncation or overflow, and enhances visual effects and user experience.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120671656A_ABST
    Figure CN120671656A_ABST
Patent Text Reader

Abstract

The invention provides a text typesetting method and device, equipment and a storage medium, and the method comprises the steps: obtaining a corresponding baseline height from a font parameter library for an inclined character, calculating the width increment of the inclined character based on the baseline height and a corresponding inclination angle, calculating the typesetting width based on the reference character width and the width increment, and setting the typesetting width according to the typesetting width. And accumulating the typesetting widths of the characters in the input text to obtain the total typesetting width of the input text. According to the method, the width increment of the inclined character is accurately calculated by extracting the style attribute and combining the baseline height and the inclination angle. Wherein the width increment of the inclined character is derived from the geometric inclination of the character contour, is used for quantifying the character horizontal displacement caused by the inclination, remarkably improves the typesetting accuracy, is superior to the estimation mode based on the normal font width in the traditional method, ensures the reasonable size of the text display area, provides an accurate basis for setting the display area, and improves the typesetting accuracy. Text truncation or overflow is avoided, and the visual effect and the user experience are improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer technology, and in particular to a text typesetting method, device, equipment and storage medium. Background Art

[0002] Text is one of the core elements of visual communication. In the field of computer graphics, text layout technology is a crucial step in achieving information display and optimizing user interfaces. The readability, aesthetics, and layout adaptability of text directly impact user experience and visual quality.

[0003] As visual design becomes more complex, text typesetting engines need to support the mixed use of multiple font styles, especially italic fonts. However, because the character outlines of italic fonts are not arranged vertically but tilted at a certain angle, the actual horizontal width occupied by italic fonts is usually larger than the width of the corresponding normal font.

[0004] Existing typesetting methods mostly use the width of normal fonts as a benchmark and lack a precise calculation mechanism for the width of oblique fonts. This deficiency can lead to improper setting of the text display area size, affecting the integrity and visual effect of the content.

[0005] It should be noted that the information disclosed in the above background technology section is only used to enhance the understanding of the background of the present invention, and therefore may include information that does not constitute prior art known to ordinary technicians in this field. Summary of the Invention

[0006] In response to the problems in the prior art, the purpose of the present invention is to provide a text typesetting method, device, equipment and storage medium, which overcome the difficulties of the prior art and are used to solve the technical problems of text typesetting errors in the prior art.

[0007] A first aspect of the present disclosure provides a text typesetting method, comprising:

[0008] Obtaining input text and extracting style attributes of each character in the input text, wherein the style attributes include font type, font size, and tilt angle;

[0009] Obtaining the base character width of each character in a normal font state;

[0010] If the tilt angle of the character is not zero, the character is determined to be an inclined character, a baseline height corresponding to the inclined character is obtained from a font parameter library, and a width increment of the inclined character is calculated based on the baseline height and the corresponding tilt angle;

[0011] If the tilt angle of the character is zero, determining the typesetting width of the character to be the reference character width;

[0012] For the inclined characters, the typeset width is calculated based on the reference character width and the width increment, and the typeset widths of the characters in the input text are accumulated to obtain the total typeset width of the input text.

[0013] Optionally, the input text is in rich text format, and the style attribute of each character is bound to the character content through a style tag.

[0014] Optionally, the base character width is obtained by calling a text measurement interface of a font rendering engine.

[0015] Optionally, the baseline height in the font parameter library is obtained by pre-processing the glyph outline data in the font file, and an index structure is established according to the font type and font size.

[0016] Optionally, the text layout method further includes:

[0017] Performing typeset rendering on the input text based on the total typeset width of the input text;

[0018] The rendered text result after typeset is embedded into dynamic image frames, which constitute a frame animation sequence or a video clip for generating a dynamic poster.

[0019] Optionally, the text layout method further includes:

[0020] The total layout width is passed to the page rendering engine as a rendering parameter, and the rendering engine sets the corresponding text display area based on the width parameter.

[0021] Optionally, the text layout method further includes:

[0022] The total layout width is set as a parameter to the text box component to determine the display width of the text box component and used for layout rendering.

[0023] Optionally, the text layout method further includes:

[0024] When it is detected that the content of the input text is changed or the language is switched, the extraction of the style attribute of each character in the input text is returned to be performed based on the updated input text to update the total layout width of the input text.

[0025] A second aspect of the present disclosure provides a text typesetting device, comprising:

[0026] An extraction module, which obtains input text and extracts style attributes of each character in the input text, wherein the style attributes include font type, font size, and tilt angle;

[0027] An acquisition module is used to acquire a reference character width of each character in a normal font state;

[0028] a calculation module, which determines that the character is an oblique character if the oblique angle of the character is not zero, obtains a baseline height corresponding to the oblique character from a font parameter library, and calculates a width increment of the oblique character based on the baseline height and the corresponding oblique angle;

[0029] a determination module, which determines the typesetting width of the character to be the reference character width if the tilt angle of the character is zero;

[0030] The accumulation module calculates the typesetting width of the inclined character based on the reference character width and the width increment, and accumulates the typesetting width of each character in the input text to obtain the total typesetting width of the input text.

[0031] A third aspect of the present disclosure provides an electronic device, comprising:

[0032] processor;

[0033] a memory storing executable instructions for the processor;

[0034] The processor is configured to execute the steps of the text typesetting method described in any of the above embodiments by executing the executable instructions.

[0035] A fourth aspect of the present disclosure provides a computer-readable storage medium for storing a program, which, when executed, implements the steps of the text typesetting method described in any embodiment.

[0036] The text typesetting method, apparatus, device, and storage medium provided by the embodiments of the present disclosure have the following advantages:

[0037] For inclined characters, the corresponding baseline height is obtained from the font parameter library, and the width increment of the inclined character is calculated based on the baseline height and the corresponding inclination angle. The typeset width is calculated based on the base character width and the width increment, and the typeset widths of each character in the input text are accumulated to obtain the total typeset width of the input text. This method accurately calculates the width increment of inclined characters by extracting style attributes and combining the baseline height and inclination angle. The width increment of the inclined character is derived from the geometric inclination of its character outline, which is used to quantify the horizontal displacement of the character caused by the inclination, significantly improving the accuracy of typesetting. It is superior to the traditional method of estimating the width of the normal font, ensuring that the size of the text display area is reasonable, providing an accurate basis for display area settings, avoiding text truncation or overflow, and improving visual effects and user experience.

[0038] It is to be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the disclosure. BRIEF DESCRIPTION OF THE DRAWINGS

[0039] Other features, objects and advantages of the present invention will become more apparent from the following detailed description of non-limiting embodiments with reference to the accompanying drawings.

[0040] Figure 1 One of the flowcharts of a text typesetting method provided by an embodiment of the present disclosure is shown;

[0041] Figure 2 Hint Figure 1 Schematic diagram comparing normal characters and oblique characters in the text typesetting method shown;

[0042] Figure 3 A second flowchart showing a text typesetting method provided by an embodiment of the present disclosure;

[0043] Figure 4 A third flowchart showing a text typesetting method provided by an embodiment of the present disclosure;

[0044] Figure 5 A fourth flowchart showing a text typesetting method provided by an embodiment of the present disclosure;

[0045] Figure 6 One of the module structure diagrams of a text typesetting device provided by an embodiment of the present disclosure is shown;

[0046] Figure 7 A second schematic diagram showing the module structure of a text typesetting device provided by an embodiment of the present disclosure;

[0047] Figure 8 A third schematic diagram showing the module structure of a text typesetting device provided by an embodiment of the present disclosure;

[0048] Figure 9 A fourth schematic diagram showing the module structure of a text typesetting device provided by an embodiment of the present disclosure;

[0049] Figure 10 A fifth schematic diagram showing the module structure of a text typesetting device provided by an embodiment of the present disclosure;

[0050] Figure 11 A schematic diagram showing the structure of an electronic device provided by an embodiment of the present disclosure;

[0051] Figure 12 It is a schematic diagram of the structure of a computer program product according to an embodiment of the present disclosure. DETAILED DESCRIPTION

[0052] In order to make the technical solution of the present invention clearer and more specific, the exemplary embodiments of the present invention are now described in detail with reference to the accompanying drawings. It should be understood that the following embodiments are only used to illustrate the technical implementation path of the present invention, rather than to limit the scope of protection of the present invention. Those skilled in the art should be able to make various modifications and adjustments based on the basic ideas disclosed in the present invention, and these modifications should also be considered to be included in the scope of protection of the present invention.

[0053] It should be noted that the specific implementations provided in this specification can be implemented in various forms, and the examples given should not be construed as limiting the present invention in any way. The structural features, module divisions, and processing steps in the implementations can be flexibly combined and adjusted according to the system architecture, deployment platform, and operating environment to better adapt to the target application scenario.

[0054] In addition, the accompanying drawings are used to illustrate the principle structure and implementation steps of the present invention and are not necessarily drawn to physical scale. To simplify the description of the drawings, the same reference numerals in the drawings represent the same or functionally similar components or modules, so these same elements are not repeatedly described in multiple figures. The functional entities or processing flows shown in the drawings can be implemented in a variety of ways and are not limited to a specific hardware structure or logical division. The specific implementation can be achieved using software functions, API interfaces, script logic, microservice processes or hardware modules, and can also be completed on a single computing node or in a distributed system.

[0055] like Figure 1 As shown, embodiments of the present disclosure provide a text typesetting method, executed by a typesetting engine system, suitable for typical application scenarios such as multilingual typesetting, dynamic image text embedding, and dynamic poster generation. This method supports character-level style recognition and italic typesetting modeling, dynamically responds to changes in input content, and adapts to real-time rendering requirements on different platforms.

[0056] The method includes but is not limited to the following steps:

[0057] Step 110: Obtain input text and extract style attributes of each character, wherein the style attributes include font type, font size, and tilt angle.

[0058] Step 120: Obtain the reference character width of each character in a normal font state.

[0059] Step 130: If the tilt angle of the character is non-zero, it is determined to be an inclined character, the corresponding baseline height is obtained from the font parameter library, and the width increment is calculated based on the baseline height and the tilt angle.

[0060] Step 140: If the tilt angle of the character is zero, determine the typesetting width of the character as the reference character width.

[0061] Step 150: Based on the typeset width of each character, the total typeset width of the input text is accumulated.

[0062] This method accurately calculates the width increment of tilted characters by extracting style attributes and combining them with baseline height and tilt angle. The width increment of tilted characters is derived from the geometric tilt of their outlines and is used to quantify the horizontal displacement of characters caused by tilt. This significantly improves typesetting accuracy and outperforms traditional methods that estimate the width of normal fonts. It ensures the text display area is appropriately sized, provides a precise basis for display area settings, avoids text truncation or overflow, and improves visual quality and user experience.

[0063] This method automatically calculates the total layout width, reducing the need for manual adjustments and significantly improving layout efficiency. Furthermore, this method supports multiple font types and tilt angles, adapting to diverse text layout requirements.

[0064] As an implementation of step 110, the typesetting engine system receives input text, parses the text content, and extracts style attributes of each character, including at least font type, font size, and tilt angle.

[0065] The input text can be in rich text format, with the style attributes of each character bound to the character content via style tags, enabling fine-grained style control. Rich text formats include, but are not limited to, markup languages ​​or data formats such as HTML, XML, or JSON, where style tags specify the font type (e.g., Latin font, Chinese font), font size, and tilt angle. The tilt angle indicates whether the character is in an italic font and the degree of tilt.

[0066] For example:

[0067] HTML example: <span style="font-family:arial;font-size:24px;font-style:italic"> Text ;

[0068] XML example:<text font="Arial"size="24"angle="15"> Text;

[0069] JSON example: {text:"Text",styles:[{char:'T',font:'Arial',size:24,angle:15},...]}.

[0070] The text parsing process can be implemented through a parser (such as a DOM parser, XML parser or JSON parsing module) to ensure that the style attributes of each character are clear and that character attributes are extracted accurately and in real time.

[0071] Optionally, the parsing process is implemented by regular expressions, DOM tree traversal, or JSON parsing.

[0072] Rich text format supports character-level style control, ensuring that character-level style differences can be expressed and providing a technical foundation for italic character width modeling. At the same time, Rich text format enhances typesetting flexibility and adapts to diverse typesetting needs. Its efficient parsing mechanism ensures rapid extraction of style attributes, making it suitable for real-time applications. In this way, Rich text format achieves fine-grained style control through style tags, providing greater flexibility than single-style text and suitable for complex typesetting scenarios. The binding mechanism ensures a one-to-one correspondence between style attributes and characters, providing accurate input for subsequent width increment calculations.

[0073] In the disclosed embodiments, the normal font state refers to a state in which no italic style is applied to a character. In one implementation of step 120, after the style attribute is parsed, the baseline character width is obtained by calling the text measurement interface of the font rendering engine. The baseline character width refers to the horizontal dimension of the character outline when no italic transformation is applied, and is commonly measured in pixels (px). The font rendering engine provides accurate width data based on the font type and font size of the character.

[0074] The typesetting engine system can choose different measurement methods depending on the deployment platform. For example, in a web environment, the HTML5 Canvas API's context.measureText() method can be used to measure character width. In desktop applications or local typesetting engine systems, the FreeType font engine can be called to parse TrueType or OpenType font files to obtain the horizontal projected bounding box size of the characters.

[0075] In this way, the benchmark character width is obtained through the text measurement interface of the font rendering engine, ensuring that the measurement result is consistent with the actual rendering effect, avoiding the error of empirical estimation, and enhancing cross-platform compatibility and portability.

[0076] To optimize performance, the layout engine system can cache the measurement results of frequently used characters during the initialization phase to avoid the performance loss caused by frequent repeated measurements. The measurement results should retain sub-pixel accuracy to ensure that the final layout accuracy is highly consistent with the rendering results.

[0077] As an implementation of step 130, if the tilt angle θ of the character is ≠ 0°, it is determined to be an italic character. The typesetting engine system will obtain the baseline height h corresponding to the character from the font parameter library and calculate the horizontal width increment Δω based on the baseline height and the tilt angle to represent the typesetting width expansion caused by the tilt deformation:

[0078] Δω=h·tanθ

[0079] in:

[0080] h is the baseline height of the character in the font type and size;

[0081] θ is the tilt angle;

[0082] Δω is the width increment, and its unit is consistent with the base character width (such as px).

[0083] For tilted characters (non-zero tilt angles), the typesetting engine system queries a pre-built font parameter library for the baseline height corresponding to the character's font type and size. The font parameter library is stored in an indexed structure, allowing for quick query of the corresponding baseline height based on the font type and size.

[0084] Combine Figure 2 As shown in the figure, a black "H" represents a normal character, and a red "H" represents an oblique character. Baseline B is the horizontal guide for typesetting. It is located at the bottom of the character and is usually the alignment line of the character base. Baseline B is represented by a horizontal solid line.

[0085] The baseline height h is defined as the vertical distance from the baseline B to the highest point of the character glyph. This corresponds to the ascender height and reflects the effective vertical structural height of the character. It is used to model horizontal expansion under skew transformations. This baseline height h is obtained by preprocessing the outline data in the font file. It is constructed during the system initialization phase and a hash index structure is established using the font type and size as keys for fast search.

[0086] The preprocessing is completed during the initialization phase of the typesetting engine system, independent of the input text acquisition process. The preprocessing uses a font parsing tool (such as FreeType) to extract the glyph outlines of the TrueType or OpenType font file, calculate the vertical distance from the baseline to the highest point of the glyph, and generate an index structure.

[0087] Table 1 is an example of a font parameter library:

[0088]

[0089]

[0090] Before startup or during initialization, the font file is parsed, glyph outline data is extracted, baseline height is calculated, and a hash table index is constructed, with the key being the "font type-size" pair and the value being the baseline height. This index structure supports fast lookups, and the hash table uses open addressing to resolve conflicts. Therefore, while the input text provides dynamic character and style information, the baseline height, as a static font property, is extracted from the font file through preprocessing. This avoids repeated parsing at runtime and improves system performance.

[0091] It should be noted that although some characters have descenders, such as g, p, y, etc., the typesetting width expansion is due to the tilt displacement of the upper right corner (or upper left corner). Therefore, the descender does not affect the modeling of Δω and does not participate in the width calculation.

[0092] The tilt angle θ is based on the vertical center line of the character, and is the angle between the main stem of the red tilted character "H" and the vertical center.

[0093] The base character width W_normal represents the horizontal width of a normal character, from the left side to the right side of the character.

[0094] The width increment Δω represents the additional horizontal width occupied by the red slanted characters.

[0095] As an implementation manner, for non-inclined characters (inclined angle is zero), the typesetting width thereof directly adopts the reference character width W_normal obtained in step 120 without additional incremental calculation.

[0096] When executing step 150, the typesetting engine accumulates the typesetting width of each character (the base character width plus the width increment for oblique characters and the base character width for non-oblique characters) one by one, where:

[0097] For non-italic characters, the typesetting width is W_normal;

[0098] For italic characters, the typesetting width is W=W_normal+Δw.

[0099] Add up the typeset widths of all the above characters to get the total typeset width W of the input text italic :

[0100]

[0101] The total layout width is used to set the size of the text display area to ensure that the text is displayed completely without truncation or overflow.

[0102] This method extracts style attributes and combines them with the baseline height to quantify the horizontal displacement caused by tilt using the aforementioned formula. The baseline height is obtained from the font parameter library to ensure calculation consistency and accuracy. The total width is calculated by summing the typesetting widths of each character, providing a precise basis for display area settings, improving visual quality and user experience.

[0103] Get the total layout width W italic After that, the typesetting engine system can use it as a typesetting parameter for subsequent rendering processing, specifically including the following two methods.

[0104] In one embodiment of the present disclosure, the total layout width can be set as a parameter to the text box component to determine the display width of the text box component and used for layout rendering. Specifically, in componentized frameworks (such as Flutter, React, Electron, etc.), W italic Assign the width property of the text box component as the binding value of style.width, TextField.width, or box.width to achieve adaptive layout area, thereby supporting real-time width adjustment of the text box in response to style or content changes.

[0105] In this implementation, the text box component directly uses the total layout width, ensuring that the rendering result is consistent with the calculation, simplifying the development process, and improving user interface consistency. Therefore, the text box component is based on the precise width setting, avoiding layout misalignment and improving adjustment efficiency.

[0106] As another implementation, Figure 3 As shown, the text typesetting method includes but is not limited to the following steps:

[0107] Step 310: Obtain input text and extract style attributes of each character in the input text, wherein the style attributes include font type, font size, and tilt angle;

[0108] Step 320: Obtaining the reference character width of each character in a normal font state;

[0109] Step 330: If the tilt angle of the character is not zero, the character is determined to be an inclined character, and the baseline height corresponding to the inclined character is obtained from a font parameter library, and a width increment of the inclined character is calculated based on the baseline height and the corresponding tilt angle;

[0110] Step 340: If the tilt angle of the character is zero, determining the typesetting width of the character to be the reference character width;

[0111] Step 350: For the inclined character, calculate the typesetting width based on the reference character width and the width increment, and add up the typesetting widths of the characters in the input text to obtain the total typesetting width of the input text.

[0112] Step 360: Formatting and rendering the input text based on the total formatting width of the input text;

[0113] Step 370: Embed the rendered text result after typeset formation into a dynamic image frame, where the dynamic image frame constitutes a frame animation sequence or a video clip for generating a dynamic poster.

[0114] In the application scenario of this embodiment, a rendering engine (such as Canvas or Skia) is used to draw text based on the total layout width, setting the display area size to ensure no truncation. The rendered text is then composited with the background graphics to generate a single frame image, which in turn forms an animation sequence or video. Incremental rendering is used in this process, updating only the changed text areas, reducing rendering overhead.

[0115] As an application scenario, the specific process includes:

[0116] Draw a text layer on the background layer or canvas;

[0117] Generate multiple time frames to form a frame animation sequence (such as GIF) or encode it into a video clip (such as MP4);

[0118] Embed rendered text into video systems, social media presentation components, or design preview tools.

[0119] In this implementation, dynamic image frames combine input text with graphic elements. Dynamic image embedding supports complex visual effects and high rendering efficiency, adapting to the needs of dynamic content generation and meeting the requirements of complex typesetting scenarios. The rendering results based on precise width calculations ensure visual consistency and enhance the user experience.

[0120] In one application scenario, this process is suitable for application scenarios such as travel copy templates, promotional activity pages, and mobile animation banners.

[0121] Figure 4 A flowchart of a text typesetting method provided in an embodiment of the present disclosure is shown in FIG. Figure 4 As shown, the text typesetting method includes but is not limited to the following steps:

[0122] Step 410: Obtain input text and extract style attributes of each character in the input text, wherein the style attributes include font type, font size, and tilt angle;

[0123] Step 420: Obtain the reference character width of each character in a normal font state;

[0124] Step 430: If the tilt angle of the character is not zero, the character is determined to be an inclined character, and the baseline height corresponding to the inclined character is obtained from a font parameter library, and a width increment of the inclined character is calculated based on the baseline height and the corresponding tilt angle;

[0125] Step 440: If the tilt angle of the character is zero, determining the typesetting width of the character to be the reference character width;

[0126] Step 450: For the inclined character, calculate the typesetting width based on the reference character width and the width increment, and accumulate the typesetting widths of each character in the input text to obtain the total typesetting width of the input text;

[0127] Step 460: The total layout width is passed as a rendering parameter to the page rendering engine, and the rendering engine sets the corresponding text display area based on the width parameter.

[0128] Specifically, the above W italic It can be passed as a parameter to the page rendering engine (such as Skia, Blink, Canvas), which sets the width property of the text container component (such as div, TextBox, Canvas Layer) to ensure that the text is displayed completely without truncation or automatic line wrapping.

[0129] For example, the total layout width is passed to the rendering engine (such as Webkit or Blink) through the API (Application Programming Interface), and CSS properties (such as width) or canvas size are set. The rendering engine dynamically adjusts the display area based on the width parameter to prevent text overflow.

[0130] This implementation is compatible with web, mobile, and native applications. For example, in a React app, updating the text box width via setState triggers a re-render. On low-power devices, using a lightweight rendering engine, adjusting the display area is quick and easy.

[0131] Using this implementation, the width parameter is passed through the page rendering engine interface to ensure that the typesetting result is consistent with the calculation. The page rendering engine integration ensures that the width parameter is seamlessly applied to the display area, with strong cross-platform compatibility and high rendering efficiency.

[0132] Figure 5 A flowchart showing a text typesetting method provided by an optional embodiment of the present disclosure is shown as follows: Figure 5 As shown, the text typesetting method may include but is not limited to the following steps:

[0133] Step 510: Obtain input text and extract style attributes of each character in the input text, wherein the style attributes include font type, font size, and tilt angle;

[0134] Step 520: Obtain the reference character width of each character in a normal font state;

[0135] Step 530: If the tilt angle of the character is not zero, the character is determined to be an inclined character, and the baseline height corresponding to the inclined character is obtained from a font parameter library, and the width increment of the inclined character is calculated based on the baseline height and the corresponding tilt angle;

[0136] Step 540: If the tilt angle of the character is zero, determining the typesetting width of the character to be the reference character width;

[0137] Step 550: For the inclined character, calculate the typesetting width based on the reference character width and the width increment, and accumulate the typesetting widths of each character in the input text to obtain the total typesetting width of the input text;

[0138] Step 560: When it is detected that the content of the input text is changed or the language is switched, return to step 510 based on the updated input text to update the total layout width of the input text.

[0139] Specifically, the typesetting engine system has a dynamic response mechanism. If it detects a change in the input text content (such as user input, language switching, style editing), it will automatically re-trigger the process of steps 510 to 550, update the total typesetting width in real time, and refresh the rendering area.

[0140] Among them, dynamic detection can be implemented based on mechanisms such as DOM monitoring, data binding, and input event subscription (such as onInput and onChange). It is suitable for high-frequency change scenarios such as online editors, visual typesetting platforms, and mobile content generation systems.

[0141] The above triggering mechanism based on DOM monitoring can be implemented through the event monitoring module, for example:

[0142] Monitor DOM tree structure changes on the Web side;

[0143] Subscribe to user input events in the editor;

[0144] Bind data change notification in the rich text component.

[0145] For example, when switching from English to Chinese, the width is recalculated and the text box is updated. Another example is that in an online editor, when the user modifies the text content, the layout width is updated in real time.

[0146] The dynamic update mechanism of this embodiment can support scenarios with high-frequency text content changes by re-executing the width calculation process, and ensure that the layout width is always consistent with the current input content. It has high response efficiency, can avoid layout misalignment or visual anomalies, and improve the flexibility of the system and user experience.

[0147] In this embodiment, step 510 may also be triggered to execute in response to a user operation (eg, a text input action) or in response to monitoring of new input text or text style changes.

[0148] The present disclosure provides a text typesetting method for a specific application scenario, which includes but is not limited to the following steps:

[0149] Get the input text "Romantic Trip to Paris" (6 characters) and parse the style attributes: the font is Arial, the font size is 24px, and the tilt angle is 15°;

[0150] Get the base character width and measure it with the font rendering engine. The total base character width is about 107px (based on Arial font, 24px font size).

[0151] All characters are identified as tilted characters (tilt angle 15°), and the baseline height is obtained from the font parameter library as 7px (based on 5pt×1.333≈6.665px, rounded to 7px).

[0152] Calculate the width increment, the width increment of each character is Δω=7·tan15≈7·0.2679≈1.88px (based on Arial font, 24px font size).

[0153] Adding up the layout width, the total layout width is 107+11.28=118.28px, rounded up to 119px.

[0154] Set the text box width to 119px, render the text "Romantic Trip to Paris", embed the dynamic image frame or pass it to the page rendering engine.

[0155] This implementation ensures complete text display without truncation or line break errors. Automated typesetting reduces manual adjustments, significantly improving efficiency. Furthermore, it supports multiple languages ​​and dynamic updates, making it suitable for complex typesetting scenarios.

[0156] Figure 6 This is a module diagram of an embodiment of a text typesetting device provided by the present disclosure. Figure 6 As shown, the text typesetting device 600 of the present disclosure includes but is not limited to:

[0157] Extraction module 610, which obtains input text and extracts style attributes of each character in the input text, wherein the style attributes include font type, font size, and tilt angle;

[0158] An acquisition module 620 acquires a reference character width of each character in a normal font state;

[0159] A calculation module 630 determines that the character is an oblique character if the oblique angle of the character is not zero, obtains a baseline height corresponding to the oblique character from a font parameter library, and calculates a width increment of the oblique character based on the baseline height and the corresponding oblique angle;

[0160] Determining module 640, if the tilt angle of the character is zero, determining the typesetting width of the character to be the reference character width;

[0161] The accumulation module 650 calculates the typesetting width of the inclined character based on the reference character width and the width increment, and accumulates the typesetting widths of the characters in the input text to obtain the total typesetting width of the input text.

[0162] In an optional embodiment, the input text is in rich text format, and the style attribute of each character is bound to the character content through a style tag.

[0163] In an optional embodiment, the reference character width is obtained by calling a text measurement interface of a font rendering engine.

[0164] In an optional embodiment, the baseline height in the font parameter library is obtained by pre-processing the glyph outline data in the font file, and an index structure is established according to the font type and font size.

[0165] In an alternative embodiment, Figure 6 As shown, Figure 7 The text layout module shown also includes:

[0166] A rendering module 710 performs typeset rendering on the input text based on the total typeset width of the input text;

[0167] The embedding module 720 embeds the text rendering result after typeset into a dynamic image frame, where the dynamic image frame constitutes a frame animation sequence or a video clip for generating a dynamic poster.

[0168] In an alternative embodiment, Figure 6 As shown, Figure 8 The text layout module shown also includes:

[0169] The transmission module 810 transmits the total layout width as a rendering parameter to the page rendering engine, and the rendering engine sets the corresponding text display area based on the width parameter.

[0170] In an alternative embodiment, Figure 6 As shown, Figure 9 The text layout module shown also includes:

[0171] The setting module 910 sets the total typesetting width as a parameter to the text box component to determine the display width of the text box component and use it for typesetting rendering.

[0172] In an alternative embodiment, Figure 6 As shown, Figure 10 The text layout module shown also includes:

[0173] The detection module 1010 returns to extracting the style attribute of each character in the input text based on the updated input text when detecting that the content of the input text has changed or the language has been switched, so as to update the total layout width of the input text.

[0174] This device extracts style attributes and combines them with baseline height and tilt angle to accurately calculate the width increment of tilted characters. The width increment of tilted characters is derived from the geometric tilt of their outlines. This is used to quantify the horizontal displacement of characters caused by tilt, significantly improving typesetting accuracy. This method outperforms traditional methods that estimate the width of normal fonts, ensuring the appropriate size of the text display area, providing a precise basis for display area settings, avoiding text truncation or overflow, and improving visual effects and user experience.

[0175] The modules of this device can be interconnected through data interfaces to collaboratively implement text typesetting. The device can be embedded in front-end development tools as an independent software module, or it can be used as a cloud service to provide an interface for developers to call remotely.

[0176] An embodiment of the present invention further provides a text typesetting device, comprising a processor and a memory storing executable instructions of the processor, wherein the processor is configured to execute the steps of the text typesetting method by executing the executable instructions.

[0177] As shown above, the text typesetting device of the present invention can accurately calculate the width increment of tilted characters by extracting style attributes and combining baseline height and tilt angle. The width increment of tilted characters is derived from the geometric tilt of their character outlines and is used to quantify the horizontal displacement of characters caused by tilt, significantly improving typesetting accuracy. It is superior to traditional methods based on the estimation of normal font width, ensuring the reasonable size of the text display area, providing an accurate basis for display area settings, avoiding text truncation or overflow, and improving visual effects and user experience.

[0178] Those skilled in the art will appreciate that various aspects of the present invention may be implemented as systems, methods, or program products. Accordingly, various aspects of the present invention may be implemented in the following forms: entirely in hardware, entirely in software (including firmware, microcode, etc.), or in a combination of hardware and software, collectively referred to herein as "circuits," "modules," or "platforms."

[0179] Figure 11 This is a schematic diagram of the structure of the text typesetting device of the present invention. Figure 11 An electronic device 1100 according to this embodiment of the present invention will be described. Figure 11 The electronic device 1100 shown is merely an example and should not limit the functions and scope of use of the embodiments of the present invention.

[0180] like Figure 11 As shown, electronic device 1100 is implemented as a general-purpose computing device. Components of electronic device 1100 may include, but are not limited to, at least one processing unit 1110, at least one storage unit 1120, a bus 1130 connecting various platform components (including storage unit 1120 and processing unit 1110), and a display unit 1140.

[0181] The storage unit stores program codes, which can be executed by the processing unit 1110, so that the processing unit 1110 performs the steps according to various exemplary embodiments of the present invention described in the above text typesetting method section of this specification. For example, the processing unit 1110 can perform the following steps: Figure 1-Figure 5 Follow the steps shown in .

[0182] The storage unit 1120 may include a readable medium in the form of a volatile storage unit, such as a random access memory unit (RAM) 1121 and / or a cache memory unit 1122 , and may further include a read-only memory unit (ROM) 1123 .

[0183] The storage unit 1120 may also include a program / utility 1124 having a set (at least one) of program modules 1125, such program modules 1125 including but not limited to: a processing system, one or more application programs, other program modules, and program data, each of which or some combination may include an implementation of a network environment.

[0184] The bus 1130 may represent one or more of several types of bus structures, including a memory bus or memory controller, a peripheral bus, an accelerated graphics port, a processing unit, or a local bus using any of a variety of bus architectures.

[0185] The electronic device 1100 can also communicate with one or more external devices 1101 (e.g., a keyboard, a pointing device, a Bluetooth device, etc.), one or more devices that enable a user to interact with the electronic device 1100, and / or any device that enables the electronic device 1100 to communicate with one or more other computing devices (e.g., a router, a modem, etc.). Such communication can occur via an input / output (I / O) interface 1150. Furthermore, the electronic device 1100 can communicate with one or more networks (e.g., a local area network (LAN), a wide area network (WAN), and / or a public network such as the Internet) via a network adapter 1160. The network adapter 1160 can communicate with other modules of the electronic device 1100 via a bus 1130. It should be understood that, although not shown in the figures, other hardware and / or software modules can be used in conjunction with the electronic device 1100, including but not limited to microcode, device drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives, and data backup storage platforms.

[0186] The present disclosure also provides a computer-readable storage medium for storing a program that, when executed, implements the steps of the text typesetting method. In some possible implementations, various aspects of the present invention may also be implemented in the form of a program product, which includes program code. When the program product is executed on a terminal device, the program code is used to cause the terminal device to execute the steps according to various exemplary embodiments of the present invention described in the above text typesetting method section of this specification.

[0187] like Figure 12 As shown, a computer program product 1200 for implementing the above method according to an embodiment of the present invention can be implemented in a portable compact disk read-only memory (CD-ROM) and include program code, and can be run on a terminal device, such as a personal computer. However, the computer program product of the present invention is not limited thereto. In this document, a readable storage medium can be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system, apparatus, or device.

[0188] The computer program product can employ any combination of one or more readable media. The readable medium can be a readable signal medium or a readable storage medium. The readable storage medium can be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or component, or any combination thereof. More specific examples (a non-exhaustive list) of readable storage media include: an electrical connection with one or more wires, a portable disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination thereof.

[0189] Computer-readable storage media may include a data signal propagated in baseband or as part of a carrier wave, which carries readable program code. Such propagated data signals may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. The readable storage medium may also be any readable medium other than a readable storage medium, which may send, propagate, or transmit a program for use by or in conjunction with an instruction execution system, apparatus, or device. The program code contained on the readable storage medium may be transmitted using any appropriate medium, including but not limited to wireless, wired, optical cable, RF, etc., or any suitable combination thereof.

[0190] The program code for performing the processes of the present invention can be written in any combination of one or more programming languages, including object-oriented programming languages ​​such as Java, C++, and the like, as well as conventional procedural programming languages ​​such as "C" or similar programming languages. The program code can be executed entirely on the user computing device, partially on the user device, as a stand-alone software package, partially on the user computing device and partially on a remote computing device, or entirely on a remote computing device or server. In the case of a remote computing device, the remote computing device can be connected to the user computing device through any type of network, including a local area network (LAN) or a wide area network (WAN), or can be connected to an external computing device (e.g., through the Internet using an Internet service provider).

[0191] In summary, the purpose of the present invention is to provide a text typesetting method, apparatus, device and storage medium, which can accurately calculate the width increment of tilted characters by extracting style attributes and combining baseline height and tilt angle. The width increment of tilted characters is derived from the geometric tilt of their character outlines, which is used to quantify the horizontal displacement of characters caused by tilt, significantly improving typesetting accuracy. It is superior to the traditional method of estimating the width of normal fonts, ensuring that the size of the text display area is reasonable, providing an accurate basis for display area settings, avoiding text truncation or overflow, and improving visual effects and user experience.

[0192] The above is a further detailed description of the present invention in conjunction with specific preferred embodiments, and the specific implementation of the present invention should not be considered to be limited to these descriptions. For those skilled in the art of the present invention, without departing from the concept of the present invention, several simple deductions or substitutions can be made, which should be considered to fall within the scope of protection of the present invention.

Claims

1. A text typesetting method, characterized in that: include: Obtaining input text and extracting style attributes of each character in the input text, wherein the style attributes include font type, font size, and tilt angle; Obtaining the base character width of each character in a normal font state; If the tilt angle of the character is not zero, the character is determined to be an inclined character, a baseline height corresponding to the inclined character is obtained from a font parameter library, and a width increment of the inclined character is calculated based on the baseline height and the corresponding tilt angle; If the tilt angle of the character is zero, determining the typesetting width of the character to be the reference character width; For the inclined characters, the typeset width is calculated based on the reference character width and the width increment, and the typeset widths of the characters in the input text are accumulated to obtain the total typeset width of the input text.

2. The text typesetting method according to claim 1, wherein: The input text is in rich text format, and the style attribute of each character is bound to the character content through a style tag.

3. The text typesetting method according to claim 1, wherein: The reference character width is obtained by calling a text measurement interface of a font rendering engine.

4. The text typesetting method according to claim 1, wherein: The baseline height in the font parameter library is obtained by pre-processing the glyph outline data in the font file, and an index structure is established according to the font type and font size.

5. The text typesetting method according to claim 1, wherein: The text typesetting method further includes: Performing typeset rendering on the input text based on the total typeset width of the input text; The rendered text result after typeset is embedded into dynamic image frames, which constitute a frame animation sequence or a video clip for generating a dynamic poster.

6. The text typesetting method according to claim 1, wherein: The text typesetting method further includes: The total layout width is passed to the page rendering engine as a rendering parameter, and the rendering engine sets the corresponding text display area based on the width parameter.

7. The text typesetting method according to claim 1, wherein: The text typesetting method further includes: The total layout width is set as a parameter to the text box component to determine the display width of the text box component and used for layout rendering.

8. The text typesetting method according to claim 1, wherein: The text typesetting method further includes: When it is detected that the content of the input text is changed or the language is switched, the extraction of the style attribute of each character in the input text is returned to be performed based on the updated input text to update the total layout width of the input text.

9. A text typesetting device, characterized in that: include: An extraction module, which obtains input text and extracts style attributes of each character in the input text, wherein the style attributes include font type, font size, and tilt angle; An acquisition module is used to acquire a reference character width of each character in a normal font state; a calculation module, which determines that the character is an oblique character if the oblique angle of the character is not zero, obtains a baseline height corresponding to the oblique character from a font parameter library, and calculates a width increment of the oblique character based on the baseline height and the corresponding oblique angle; a determination module, which determines the typesetting width of the character to be the reference character width if the tilt angle of the character is zero; The accumulation module calculates the typesetting width of the inclined character based on the reference character width and the width increment, and accumulates the typesetting width of each character in the input text to obtain the total typesetting width of the input text.

10. An electronic device, characterized in that: include: processor; a memory storing executable instructions for the processor; The processor is configured to execute the steps of the text typesetting method according to any one of claims 1 to 8 by executing the executable instructions.

11. A computer-readable storage medium for storing a program, characterized in that: When the program is executed, the steps of the text typesetting method according to any one of claims 1 to 8 are implemented.