Text typesetting method and device, equipment, storage medium and program product
By dynamically optimizing the layout strategy for long words using a greedy algorithm, the problem of blank areas caused by line breaks of long words is solved, achieving efficient use of screen space and improving visual aesthetics, thus ensuring smooth reading.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- BEIJING XIAKEHUI INFORMATION TECH CO LTD
- Filing Date
- 2025-12-24
- Publication Date
- 2026-05-08
AI Technical Summary
In existing technologies, long words are directly wrapped to new lines, resulting in a large amount of blank space at the end of the current line, which leads to loose text layout and low screen space utilization.
A greedy algorithm is used to dynamically optimize the layout strategy of long words. By determining the device parameters and user settings of the display area, the greedy algorithm is combined to calculate the optimal layout strategy for each word to be displayed, including partial line breaks or character splitting, and generate the final layout result.
It achieves efficient use of screen space, enhances visual appeal and reading smoothness, reduces blank areas, and adapts to the needs of different devices and users.
Smart Images

Figure CN121997889A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of electronic reading technology, and in particular to a text typesetting method, apparatus, device, storage medium, and program product. Background Technology
[0002] With the widespread adoption of mobile internet and e-reading devices, users' demand for reading e-books, electronic documents, news, and other content is growing daily. Users frequently use e-readers for text reading during commutes, work, and leisure activities.
[0003] In existing technologies, long words to be displayed are simply moved to the next line in their entirety.
[0004] However, in the above method, directly breaking the line will create a large amount of blank space at the end of the current line, resulting in loose text layout and low screen space utilization. Summary of the Invention
[0005] This application provides text typesetting methods, apparatus, devices, storage media, and program products that can dynamically optimize the typesetting effect of long words, achieve efficient use of screen space, enhance visual aesthetics, and ensure reading fluency.
[0006] In a first aspect, embodiments of this application provide a text typesetting method, including:
[0007] Based on the device parameters of the display area, determine the layout parameters for each display row in the display area;
[0008] Based on a greedy algorithm, the optimal layout strategy for each word to be displayed in the target text is determined according to the layout parameters of each displayed line.
[0009] Based on the optimal layout strategy for the words to be displayed, the words to be displayed are formatted to generate a layout result.
[0010] In one possible implementation, determining the layout parameters of each display row in the display area based on the device parameters of the display area includes:
[0011] Based on the device parameters and user settings parameters of the display area, the layout parameters of each display row in the display area are determined.
[0012] In one possible implementation, determining the layout parameters of each display row in the display area based on the device parameters and user setting parameters of the display area includes:
[0013] The layout parameters of the display line are determined based on the screen size and resolution in the device parameters and the font size and character spacing in the user settings parameters.
[0014] In one possible implementation, the step of processing the word to be displayed according to the optimal typesetting strategy to generate a typesetting result includes:
[0015] If the optimal layout strategy for the word to be displayed is determined to be a partial line break strategy, then the word to be displayed is split into characters.
[0016] The first word unit after splitting is placed at the end of the current display line; and the second word unit after splitting is placed at the beginning of the next display line after the current display line.
[0017] The first word unit and the second word unit after splitting are merged to obtain the layout result.
[0018] In one possible implementation, the character splitting of the word to be displayed includes:
[0019] Based on the language type of the word to be displayed, determine the splitting rules for the word to be displayed;
[0020] According to the splitting rules, the word to be displayed is split into characters.
[0021] In one possible implementation, determining the optimal layout strategy for each word to be displayed in the target text based on the layout parameters of each displayed line using a greedy algorithm includes:
[0022] Based on the greedy algorithm, if it is determined that the character width of the word to be displayed is greater than the remaining space in the current layout parameters, then the optimal layout strategy for the word to be displayed is a line break strategy; wherein, the line break strategy is a partial line break strategy or a complete line break strategy.
[0023] In one possible implementation, the typography parameters include the remaining space in the display line, font size, word spacing, and word character width.
[0024] Secondly, embodiments of this application provide a text typesetting device, including:
[0025] The first determining module is used to determine the layout parameters of each display row in the display area based on the device parameters of the display area;
[0026] The second determining module is used to determine the optimal layout strategy for each word to be displayed in the target text based on a greedy algorithm and according to the layout parameters of each display line.
[0027] The layout module is used to process the word to be displayed according to the optimal layout strategy and generate the layout result.
[0028] In one possible implementation, the first determining module is specifically used to: determine the layout parameters of each display row in the display area based on the device parameters and user setting parameters of the display area.
[0029] In one possible implementation, the first determining module is specifically used to: determine the layout parameters of the display line based on the screen size and resolution in the device parameters and the font size and character spacing in the user setting parameters.
[0030] In one possible implementation, the typesetting module is specifically used to: if the optimal typesetting strategy for the word to be displayed is determined to be a partial line break strategy, then split the word to be displayed into characters; place the split first word unit at the end of the current display line; place the split second word unit at the beginning of the next display line after the current display line; and merge the split first word unit and the split second word unit to obtain the typesetting result.
[0031] In one possible implementation, the typesetting module is specifically used to: determine the splitting rules of the word to be displayed based on the language type of the word to be displayed; and split the word to be displayed into characters according to the splitting rules.
[0032] In one possible implementation, the second determining module is specifically used to: based on the greedy algorithm, if it is determined that the character width of the word to be displayed is greater than the remaining space in the current typesetting parameters, then determine that the optimal typesetting strategy for the word to be displayed is a line break strategy; wherein, the line break strategy is a partial line break strategy or a complete line break strategy.
[0033] In one possible implementation, the typography parameters include the remaining space in the display line, font size, word spacing, and word character width.
[0034] Thirdly, embodiments of this application provide an electronic device, including: a memory and a processor;
[0035] The memory stores computer-executed instructions;
[0036] The processor executes computer execution instructions stored in the memory, causing the processor to perform the first aspect and / or various possible implementations of the first aspect as described above.
[0037] Fourthly, embodiments of this application provide a computer-readable storage medium storing computer-executable instructions, which, when executed by a processor, are used to implement the first aspect and / or various possible implementations of the first aspect.
[0038] Fifthly, embodiments of this application provide a computer program product, including a computer program that, when executed by a processor, implements the first aspect and / or various possible implementations of the first aspect.
[0039] The text typesetting method, apparatus, device, storage medium, and program product provided in this application determine the typesetting parameters of each display line in the display area by using the device parameters of the display area. Using a greedy algorithm, the optimal typesetting strategy for each word to be displayed in the target text is determined based on the typesetting parameters of each display line, so as to process the typesetting of each word to be displayed and obtain the final typesetting result. Furthermore, by introducing a dynamic typesetting strategy based on a greedy algorithm, the typesetting effect of each word to be displayed can be optimized, achieving efficient use of screen space, improved visual aesthetics, and guaranteed reading fluency. Attached Figure Description
[0040] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with this application and, together with the description, serve to explain the principles of this application.
[0041] Figure 1 This application provides an illustration of an application scenario.
[0042] Figure 2 A flowchart illustrating a text typesetting method provided in an embodiment of this application;
[0043] Figure 3 A comparison diagram of text layout effects provided for embodiments of this application;
[0044] Figure 4 A flowchart illustrating another text typesetting method provided in an embodiment of this application;
[0045] Figure 5 This is a schematic diagram of the structure of a text typesetting device provided in an embodiment of this application;
[0046] Figure 6 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application.
[0047] The accompanying drawings illustrate specific embodiments of this application, which will be described in more detail below. These drawings and descriptions are not intended to limit the scope of the concept in any way, but rather to illustrate the concept of this application to those skilled in the art through reference to particular embodiments. Detailed Implementation
[0048] Exemplary embodiments will now be described in detail, examples of which are illustrated in the accompanying drawings. When the following description relates to the drawings, unless otherwise indicated, the same numbers in different drawings denote the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with this application. Rather, they are merely examples of apparatuses and methods consistent with some aspects of this application as detailed in the appended claims.
[0049] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, data stored, data displayed, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties. Furthermore, the collection, use, processing, transmission, provision, disclosure, and application of the relevant data all comply with relevant laws, regulations, and standards, necessary confidentiality measures have been taken, they do not violate public order and good morals, and corresponding operation portals are provided for users to choose to authorize or refuse.
[0050] Furthermore, the technical solution involved in this application, which involves big data analysis of user information (including but not limited to personal biometrics, identity data, consumption data, asset data, electronic terminal operation data, etc.) and the use of artificial intelligence technology for automated decision-making, and makes decisions that have a significant impact on user rights based on the results of automated decision-making, provides users with corresponding operation entry points for users to choose to agree to or reject the results of automated decision-making; if the user chooses to reject, the process will proceed to the expert decision-making process.
[0051] Figure 1 This application provides an illustration of an application scenario, such as... Figure 1 As shown, in application scenarios, when users access e-books, academic papers, news and other content through an e-reader, the e-reader can dynamically adjust the optimal layout strategy for the accessed content.
[0052] Based on the above scenarios, it can be seen that when processing long words, the blank areas created by direct line breaks reduce the efficiency of screen space utilization.
[0053] The text typesetting method provided in this application, by introducing a dynamic typesetting strategy based on a greedy algorithm, can optimize the typesetting effect of each word to be displayed, thereby achieving efficient use of screen space, improved visual aesthetics, and guaranteed reading fluency.
[0054] The technical solution of this application and how the technical solution of this application solves the above-mentioned technical problems are described in detail below with specific embodiments. These specific embodiments can be combined with each other, and the same or similar concepts or processes may not be described again in some embodiments. The embodiments of this application will now be described with reference to the accompanying drawings.
[0055] Figure 2 A flowchart illustrating a text typesetting method provided in this application embodiment is shown below. Figure 2 As shown, the method includes:
[0056] 201. Based on the device parameters of the display area, determine the layout parameters of each display row in the display area.
[0057] For example, the execution subject of this embodiment can be an electronic device, hereinafter referred to as a device. The device can be a mobile phone, tablet computer, e-ink reader, or other similar devices. When displaying text, the device can obtain device parameters corresponding to the display area, including the hardware or display characteristics of the device screen where the display area is located, such as, but not limited to, screen size, screen ratio, display quality parameters, and display refresh rate. Based on these device parameters, the layout parameters of each display line in the display area can be determined, including layout-related parameters for each display line, such as, but not limited to, line spacing and maximum character width.
[0058] For example, based on a 7-inch e-ink reader, the line spacing of each displayed line in the reader's display area was determined to be 1.5 times. This dynamic adjustment allows for optimal screen space utilization under various screen conditions.
[0059] 202. Based on a greedy algorithm, determine the optimal layout strategy for each word to be displayed in the target text according to the layout parameters of each display line.
[0060] For example, the device invokes a greedy algorithm, which is an algorithmic strategy that selects the current optimal solution at each decision point for rapid optimization of locally optimal decisions. Using this greedy algorithm, based on the layout parameters of each display line, each word to be displayed in the target text is traversed to determine the optimal layout strategy for each word to be displayed.
[0061] The optimal typesetting strategy includes the word wrapping method for each word to be displayed, calculated by a greedy algorithm, including but not limited to no wrapping, partial wrapping, character splitting, or complete wrapping.
[0062] Furthermore, the optimal typesetting strategy also includes the position of each word in the display line, the character width, the font size, and the spacing between each word.
[0063] For example, the optimal typesetting strategy for the long word "antidisestablishmentarianism" is to break it down into "anti-disestablishmentarianism" and wrap it to a new line. Alternatively, the optimal typesetting strategy for the short word "file" is to place it directly in the corresponding display line according to its position in the target text, without needing a new line.
[0064] Based on a greedy algorithm, at each layout decision point, the algorithm selects the operation that best benefits the overall layout effect under the current state. For example, on small-screen devices, the greedy algorithm arranges long words more compactly, prioritizing the reduction of blank areas; on large-screen devices, where space is relatively ample, the greedy algorithm maintains visual alignment by adjusting character spacing, ensuring the rationality of the layout and avoiding layout imbalance caused by long words. The combination of the greedy algorithm's local optimum decision-making mechanism and dynamic parameter adjustment allows the layout strategy to respond in real time to changes in device and user settings, resulting in a consistent layout outcome.
[0065] 203. Based on the optimal layout strategy for the words to be displayed, perform layout processing on the words to be displayed and generate the layout result.
[0066] For example, the device performs layout processing on each word to be displayed according to the optimal layout strategy of each word to be displayed, and obtains the final layout result of the target text in the display area, so that the processing strategy of each word to be displayed conforms to the optimal match between the display line space and the device parameters.
[0067] The typesetting results include the text layout generated after processing with line break strategies, including but not limited to inline character arrangement, line break position, and character spacing.
[0068] For example, the device parameters of the e-reader are collected as input conditions for a greedy algorithm. Then, the layout parameters of each display line are evaluated based on the greedy algorithm, calculating the optimal layout strategy (such as line breaks or no line breaks) for each word to be displayed on the corresponding display line. Finally, according to the calculated optimal layout strategy, each word to be displayed is processed to generate the final layout result. Figure 3 A text layout effect comparison diagram provided for embodiments of this application, such as... Figure 3 As shown, the layout result presented by the direct line wrapping method has a large blank area in the display line. However, the dynamic layout strategy based on a greedy algorithm in this solution can reduce the blank area in the obtained layout result, achieving efficient use of screen space. Throughout the process, device parameters are used as the basis for dynamic adjustment to ensure that the line wrapping strategy can adapt to different devices and user needs.
[0069] This embodiment provides a text typesetting method. A greedy algorithm selects the optimal operation at each typesetting decision point, and optimizes the global typesetting effect through local optimal decision-making. A dynamic parameter adjustment mechanism adjusts the line wrapping strategy in real time according to device parameters, so that the typesetting effect can adapt to different devices and user needs. Furthermore, by introducing a dynamic typesetting strategy based on a greedy algorithm, the typesetting effect of each word to be displayed can be optimized, achieving efficient use of screen space, improved visual aesthetics, and guaranteed reading fluency.
[0070] Figure 4 A flowchart illustrating another text typesetting method provided in this application embodiment is shown below. Figure 4 As shown, the method includes:
[0071] 301. Determine the layout parameters of each display row in the display area based on the device parameters and user settings parameters of the display area.
[0072] For example, when displaying text, the device can obtain device parameters corresponding to the display area and user-defined layout parameters. Based on these device parameters and user-defined layout parameters, the layout parameters for each display line in the display area can be determined, including layout-related parameters for each display line, such as, but not limited to, line spacing and maximum character width.
[0073] The user-defined parameters include page layout parameters (such as margins), text flow parameters (such as column settings, column spacing, and text direction), paragraph format parameters, character format parameters, and other special typesetting parameters (such as ligature settings and drop caps).
[0074] By dynamically adjusting device parameters and user settings, the layout strategy is ensured to adapt to different devices and user needs. Users can achieve consistent and efficient layout results across different devices and settings, significantly improving the visual experience and readability of e-reading.
[0075] In one example, layout parameters can be adjusted by collecting device sensor data (such as ambient light and screen orientation). Specifically, the ambient light is first measured by a light sensor; if it is below a threshold, the font size and line spacing are automatically increased to improve readability. Secondly, the screen orientation is detected by a gyroscope; if it is in landscape mode, the maximum character width of the currently displayed line is recalculated based on the screen width. This sensor-data-driven parameter adjustment process allows the layout strategy to adapt to the current environmental conditions and device status, ensuring a consistent reading experience for users in different scenarios.
[0076] In one possible implementation, step 301 includes: determining the layout parameters of the display line based on the screen size and resolution in the device parameters and the font size and character spacing in the user settings parameters.
[0077] The layout parameters include the remaining space in the display line, font size, word spacing, and word character width.
[0078] Specifically, device parameters include screen size and resolution, where resolution includes physical resolution, rendering resolution, pixel density, and other parameters. User settings parameters include font size and character spacing. A dynamic space allocation mechanism is introduced, which determines the layout parameters of each display line in the display area based on the device parameters and user settings parameters. This includes layout-related parameters for each display line, including but not limited to the remaining space of the display line, font size, word spacing, and word character width.
[0079] In one example, the maximum character width of the current line is calculated based on the screen size and resolution. This maximum character width is the maximum total width of characters that can be accommodated in the current display line, calculated based on the screen size and resolution. For example, if the screen width is 1448 pixels and the resolution supports 100 characters per display line, each character would be 14.48 pixels wide.
[0080] Furthermore, the total width of the characters already arranged in the current display line is calculated based on the font size and character spacing. This total width of the arranged characters is the total width of all characters arranged in the current display line, including the width of the characters themselves and the character spacing. For example, if the current display line has 20 characters arranged, each character is 14.48 pixels wide, and the character spacing is 1 pixel, the total width is 20 × 14.48 + 19 × 1 = 308.6 pixels.
[0081] Furthermore, by subtracting the total width of the already arranged characters from the maximum character width, the remaining space of the current display line is obtained. This remaining space represents the unused character width in the current display line, which is used to accommodate subsequent characters or line breaks. For example, if the maximum character width is 1448 pixels and the total width of the already arranged characters is 308.6 pixels, the remaining space is 1139.4 pixels.
[0082] By combining the screen size and resolution from the device parameters with the font size and character spacing from the user settings, the maximum character width under the given screen size and resolution is calculated step by step. This is then combined with the total width of the characters already laid out in the current line (including the width of the characters themselves and the character spacing) to determine the remaining space for the current line. This ensures that the calculated remaining space accurately reflects the available layout space for the current display line, providing a basis for subsequent line wrapping strategies. For example, on small-screen devices, accurate calculation of the remaining space avoids increased blank areas due to misjudgment; on large-screen devices, reasonable allocation of the remaining space optimizes character spacing and improves visual alignment. Ultimately, this technique further enhances the dynamic adaptability of layout strategies, ensuring efficient layout results are generated under different devices and user settings.
[0083] In one example, user settings parameters could also include layout priority weights (such as space utilization, visual appeal, and reading smoothness) set by the user through the interface. The device dynamically adjusts the decision weights of the greedy algorithm based on the user's selection. Specifically, based on weight mapping rules, the user's selected priorities are mapped to decision weights in the greedy algorithm (e.g., space utilization weight is 0.6, and visual appeal weight is 0.4). This technique can significantly enhance the reader's flexibility and user engagement, making the layout more closely match the user's actual usage scenarios and preferences.
[0084] For example, during the layout process, the decision logic of the greedy algorithm is dynamically adjusted according to the current priority weight. Users can set "prioritize reducing blank areas" or "prioritize maintaining alignment and aesthetics", and the device will prioritize meeting user needs according to the weight during layout.
[0085] 302. Based on the greedy algorithm, if it is determined that the character width of the word to be displayed is greater than the remaining space in the current layout parameters, then the optimal layout strategy for the word to be displayed is the line break strategy; where the line break strategy is either a partial line break strategy or a complete line break strategy.
[0086] For example, the device calculates the character width of each word to be displayed. For each word to be displayed, based on a greedy algorithm, it evaluates in real time whether the character width of the word to be displayed is greater than the remaining space in the current layout parameters. If it is determined that the character width of the word to be displayed is greater than the remaining space in the current layout parameters, then the word to be displayed is a long word, and the long word cannot be completely placed in the remaining space of the current display line. Then, based on factors such as the character width of the long word, the remaining space of the current display line, the font size, and the character width of the word, the device dynamically evaluates the best processing method for the long word as the optimal line break strategy (such as partial line break or character splitting), including partial line break strategy or full line break strategy, to determine the most suitable line break position of the long word in the current display line in the layout.
[0087] In one example, when encountering a long word, the algorithm attempts to place a portion of the word at the end of the current line, with the remainder automatically extending to the beginning of the next line. For instance, if the remaining space on the current line is 200 pixels, and the long word "antidisestablishmentarianism" is 300 pixels wide, the algorithm calculates that if the word is split into "anti-disestablishmentarianism" and wrapped to a new line, the remaining space on the current line can be filled to 180 pixels (reducing blank areas), and the spacing of the starting character of the next line is reasonable.
[0088] By employing a greedy algorithm for locally optimal decision-making, the algorithm can quickly select a line-breaking strategy (such as partial line breaks or character splitting) with low computational complexity, thereby reducing blank areas and preventing abnormal expansion of word spacing. Ultimately, it can maximize the use of the remaining space of the currently displayed line while maintaining aesthetic appeal, thus improving screen space utilization and maintaining layout consistency. Furthermore, compared to complex global optimization algorithms, the greedy algorithm has low computational complexity, reducing device computing resource consumption and extending battery life while ensuring layout quality.
[0089] 303. If the optimal layout strategy for the word to be displayed is determined to be a partial line break strategy, then the word to be displayed is split into characters.
[0090] For example, regarding the optimal layout strategy for each word to be displayed, if it is determined that the optimal layout strategy for the word to be displayed is a partial line break strategy, then it is determined that the word to be displayed needs to be broken into newer lines, for example, for long words that cannot be placed entirely on the current display line. Based on the intelligent character splitting and merging function, according to the rationality of character combinations, such as character combination rules, the splitting position of the word to be displayed is determined, so as to split the word to be displayed into at least two word units.
[0091] In one possible implementation, the word to be displayed is split into characters, including the following steps:
[0092] The first step is to determine the word splitting rules based on the language type of the word to be displayed.
[0093] The second step is to split the words to be displayed into characters according to the splitting rules.
[0094] Specifically, for words to be displayed that require line breaks, natural language processing technology can be used to identify the language type of the word. Based on the language type, a preset character splitting rule corresponding to that language type is determined as the splitting rule for the word. Then, the word is split into characters according to this splitting rule.
[0095] In one example, for long words that need to be split and broken into new words, the long words are split according to the syllable rules of English words; according to the word segmentation model of Chinese words; and according to the root rules of German words.
[0096] For example, the word "antidisestablishmentarianism" is broken down into "anti-dis-establish-ment-arian-ism" by syllables; the word "electronic reader" is broken down into "electronic / reader / device" by word segmentation model; and the word "Unternehmensentwicklung" is broken down into "Unternehmen-sentwicklung" by root word.
[0097] By dynamically invoking corresponding splitting rules from a multilingual intelligent splitting rule library, this technology can adapt to the processing needs of long words in different languages. For example, in English documents, long words are split based on syllable rules to avoid disrupting semantic coherence; in Chinese documents, words are split based on word segmentation models to ensure the logical integrity of content after line breaks. Ultimately, this technology significantly improves the accuracy of typesetting in cross-language scenarios, meeting the diverse needs of global users.
[0098] 304. Arrange the first word unit after splitting at the end of the current display line; and arrange the second word unit after splitting at the beginning of the next display line after the current display line.
[0099] For example, the first word unit after splitting is placed at the end of the current display line to avoid increasing the blank area caused by direct line breaks. The second word unit after splitting is placed at the beginning of the next display line to effectively reduce interference from line breaks. The first word unit after splitting includes the character sequence at the beginning of the word split; the second word unit after splitting includes the character sequence at the end of the word split.
[0100] For example, the English word "antidisestablishmentarianism" is split into "anti-disestablishmentarianism" according to syllable rules, where "anti-" is placed at the end of the current line and "disestablishmentarianism" is placed at the beginning of the next line. This step-by-step processing of character splitting and placement achieves efficient line breaks for long words.
[0101] 305. Merge the first word unit and the second word unit after splitting to obtain the typesetting result.
[0102] For example, through an automatic merging mechanism, the first and second word units after splitting are merged, maintaining semantic coherence even after line breaks, avoiding reading interruptions caused by line breaks, and ensuring the continuity of the user's reading experience. For each long word, that is, the word to be displayed with the optimal typesetting strategy of partial line breaks, intelligent character splitting and merging are performed to obtain the final typesetting result.
[0103] By splitting long words using character combination rules and placing the two parts at the end of the current line and the beginning of the next line respectively, interference from line breaks can be effectively reduced. The arrangement of the split characters is optimized through an automatic merging mechanism, further improving the visual aesthetics after line breaks, reducing visual fatigue caused by poor layout, and adapting to various reading scenarios. Ultimately, this technique significantly enhances the logical integrity of long word processing, ensuring smooth reading in different language contexts; at the same time, it eliminates the need for users to frequently adjust layout parameters manually, improving reading efficiency.
[0104] In one example, the device can also collect or receive user behavior feedback in real time and adjust the optimal layout strategy based on the user behavior feedback, which includes page turning frequency and dwell time.
[0105] For example, if users frequently flip through pages in a certain section of content and spend a short time on it, analyzing user satisfaction with the current layout and dynamically adjusting the layout strategy can continuously optimize the layout based on user feedback, thereby improving user satisfaction and product stickiness.
[0106] In this embodiment, based on the above embodiments, on the one hand, the dynamic space allocation mechanism based on the core strategy of the greedy algorithm can ensure the natural connection between the two lines and avoid generating excessive blank areas; on the other hand, based on the intelligent character splitting and merging function, it can ensure the continuity of the user's reading.
[0107] Figure 5 This is a schematic diagram of the structure of a text typesetting device provided in an embodiment of this application, as shown below. Figure 5 As shown, the device includes:
[0108] The first determining module 401 is used to determine the layout parameters of each display row in the display area based on the device parameters of the display area;
[0109] The second determining module 402 is used to determine the optimal layout strategy for each word to be displayed in the target text based on a greedy algorithm and the layout parameters of each display line.
[0110] The typesetting module 403 is used to process the text to be displayed according to the optimal typesetting strategy of the text to be displayed and generate the typesetting result.
[0111] In one possible implementation, the first determining module 401 is specifically used to: determine the layout parameters of each display row in the display area based on the device parameters and user setting parameters of the display area.
[0112] In one possible implementation, the first determining module 401 is specifically used to: determine the layout parameters of the display line based on the screen size and resolution in the device parameters and the font size and character spacing in the user setting parameters.
[0113] In one possible implementation, the typesetting module 403 is specifically used to: if the optimal typesetting strategy for the word to be displayed is determined to be a partial line break strategy, then split the word to be displayed into characters; place the split first word unit at the end of the current display line; place the split second word unit at the beginning of the next display line after the current display line; and merge the split first word unit and the split second word unit to obtain the typesetting result.
[0114] In one possible implementation, the typesetting module 403 is specifically used to: determine the splitting rules of the words to be displayed based on the language type of the words to be displayed; and split the words to be displayed into characters according to the splitting rules.
[0115] In one possible implementation, the second determining module 402 is specifically used to: based on a greedy algorithm, if it is determined that the character width of the word to be displayed is greater than the remaining space in the current typesetting parameters, then determine that the optimal typesetting strategy for the word to be displayed is a line break strategy; wherein, the line break strategy is a partial line break strategy or a complete line break strategy.
[0116] In one possible implementation, the typography parameters include the remaining space in the display line, font size, word spacing, and word character width.
[0117] The apparatus in this embodiment can execute the technical solutions in the above method. Its specific implementation process and technical principles are the same, and will not be repeated here.
[0118] Figure 6 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application, such as... Figure 6 As shown, the electronic device includes: a memory 501 and a processor 502; the memory 501 is a memory used to store instructions executable by the processor 502.
[0119] The processor 502 is configured to perform the method provided in the above embodiments.
[0120] The electronic device also includes a receiver 503 and a transmitter 504. The receiver 503 is used to receive instructions and data sent by other devices, and the transmitter 504 is used to send instructions and data to external devices.
[0121] The specific implementation process of the processor can be found in the above method embodiments, and its implementation principle and technical effect are similar, so it will not be repeated here.
[0122] In the above embodiments, it should be understood that the processor can be a Central Processing Unit (CPU), or other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), etc. The general-purpose processor can be a microprocessor or any conventional processor. The steps of the method disclosed in this invention can be directly implemented by a hardware processor, or implemented by a combination of hardware and software modules within the processor.
[0123] This application also provides a computer-readable storage medium storing computer-executable instructions, which, when executed on a computer, cause the computer to perform the technical solutions described above.
[0124] The aforementioned readable storage medium can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory, electrically erasable programmable read-only memory, erasable programmable read-only memory, programmable read-only memory, read-only memory, magnetic storage, flash memory, magnetic disk, or optical disk. The readable storage medium can be any available medium accessible to a general-purpose or special-purpose computer.
[0125] An exemplary readable storage medium is coupled to a processor, enabling the processor to read information from and write information to the readable storage medium. The readable storage medium can also be a component of the processor. The processor and the readable storage medium can reside in an application-specific integrated circuit (ASIC). Alternatively, the processor and the readable storage medium can exist as discrete components in a device.
[0126] This application also provides a computer program product, which includes a computer program stored in a computer-readable storage medium. At least one processor can read the computer program from the computer-readable storage medium, and when the at least one processor executes the computer program, it can implement the technical solutions in the above embodiments.
[0127] Those skilled in the art will understand that all or part of the steps of the above-described method embodiments can be implemented by hardware related to program instructions. The aforementioned program can be stored in a computer-readable storage medium. When executed, the program performs the steps of the above-described method embodiments; and the aforementioned storage medium includes various media capable of storing program code, such as magnetic disks or optical disks.
[0128] Finally, it should be noted that other embodiments of the invention will readily occur to those skilled in the art upon consideration of the specification and practice of the invention disclosed herein. This invention is intended to cover any variations, uses, or adaptations of the invention that follow the general principles of the invention and include common knowledge or customary techniques in the art not disclosed herein, and is not limited to the precise structures described above and shown in the accompanying drawings, and various modifications and changes can be made without departing from its scope. The scope of the invention is limited only by the appended claims.
Claims
1. A text typesetting method, characterized in that, include: Based on the device parameters of the display area, determine the layout parameters for each display row in the display area; Based on a greedy algorithm, the optimal layout strategy for each word to be displayed in the target text is determined according to the layout parameters of each displayed line. Based on the optimal layout strategy for the words to be displayed, the words to be displayed are formatted to generate a layout result.
2. The method according to claim 1, characterized in that, The step of determining the layout parameters of each display row in the display area based on the device parameters of the display area includes: Based on the device parameters and user settings parameters of the display area, the layout parameters of each display row in the display area are determined.
3. The method according to claim 2, characterized in that, The step of determining the layout parameters of each display row in the display area based on the device parameters and user settings parameters of the display area includes: The layout parameters of the display line are determined based on the screen size and resolution in the device parameters and the font size and character spacing in the user settings parameters.
4. The method according to claim 1, characterized in that, The step of processing the text to be displayed according to the optimal layout strategy to generate a layout result includes: If the optimal layout strategy for the word to be displayed is determined to be a partial line break strategy, then the word to be displayed is split into characters. The first word unit after splitting is placed at the end of the current display line; and the second word unit after splitting is placed at the beginning of the next display line after the current display line. The first word unit and the second word unit after splitting are merged to obtain the layout result.
5. The method according to claim 4, characterized in that, The step of splitting the word to be displayed into characters includes: Based on the language type of the word to be displayed, determine the splitting rules for the word to be displayed; According to the splitting rules, the word to be displayed is split into characters.
6. The method according to claim 1, characterized in that, The method based on a greedy algorithm, determining the optimal layout strategy for each word to be displayed in the target text according to the layout parameters of each displayed line, includes: Based on the greedy algorithm, if it is determined that the character width of the word to be displayed is greater than the remaining space in the current layout parameters, then the optimal layout strategy for the word to be displayed is a line break strategy; wherein, the line break strategy is a partial line break strategy or a complete line break strategy.
7. The method according to any one of claims 1-6, characterized in that, The layout parameters include the remaining space in the display line, font size, word spacing, and word character width.
8. A text typesetting device, characterized in that, include: The first determining module is used to determine the layout parameters of each display row in the display area based on the device parameters of the display area; The second determining module is used to determine the optimal layout strategy for each word to be displayed in the target text based on a greedy algorithm and according to the layout parameters of each display line. The layout module is used to process the word to be displayed according to the optimal layout strategy and generate the layout result.
9. An electronic device, characterized in that, include: Memory, processor; The memory stores computer-executed instructions; The processor executes computer execution instructions stored in the memory, causing the processor to perform the method as described in any one of claims 1-7.
10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer-executable instructions, which, when executed by a processor, are used to implement the method as described in any one of claims 1-7.
11. A computer program product, characterized in that, Includes a computer program that, when executed by a processor, implements the method described in any one of claims 1-7.