Text paging typesetting method and device, electronic equipment and storage medium
By obtaining and utilizing reading typesetting parameters, determining the character width and height in combination with character types, and performing pagination typesetting, the problem of empty lines at the end of the page caused by traditional methods is solved, and the page utilization and user experience are improved.
Patent Information
- Application Number
- CN202411786867.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-06
- Publication Date
- 2025-04-18
AI Technical Summary
When traditional paging and layout methods deal with text in different locale environments, they can easily lead to blank lines at the end of the page, resulting in low page utilization, poor display effect, and affecting the user experience.
By obtaining the reading layout parameters of the text to be displayed, including the text size, word spacing, line spacing and segment spacing, and determining the width and height of the text reading area on the display screen of the reading device. For each character, determine the character width and height according to its character type, and combine other parameters for pagination to avoid blank lines at the end of the page.
Improve page utilization, improve display effect, improve user experience, and accurately determine the width of each character, avoiding the problem of empty lines at the end of the page.
Smart Images

Figure CN119849445A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to data display technology, and in particular to a text paging typesetting method, device, electronic device and storage medium. Background Art
[0002] With the popularization of electronic products and the development of computer technology, more and more users use portable electronic reading devices (mobile phones, readers, tablet computers, etc.) to read electronic books, which makes it more convenient for people to read in their daily life. When displaying the content of electronic books through electronic reading devices, it is necessary to paginate the book content and draw pages according to the result of pagination, so as to display the content.
[0003] The traditional pagination typesetting method first determines the character environment of the article. For example, if the article is in a Chinese environment, all characters in the article are regarded as Chinese characters, and the space that each character should occupy is calculated according to the correspondence between the Chinese character font size and pixels, so as to obtain the number of characters that can be accommodated in each line, the number of lines that can accommodate characters in each page, and the number of display pages. In this way, the pagination typesetting of the article content is realized.
[0004] However, in actual applications, various language environments may have unequal character widths. For example, in a Chinese environment, the width of half-width punctuation marks or English letters is half the width of Chinese characters; while in an English environment, letters themselves are unequal in width. Therefore, when typeset articles using traditional page typesetting methods, after all characters are inserted into the page, it is easy to cause blank lines at the end of some pages, resulting in low page utilization, poor display effects, and poor user experience. Summary of the invention
[0005] The purpose of the embodiments of the present application is to provide a text paging typesetting method, device, electronic device and storage medium to solve the problem that when typesetting an article according to the traditional page typesetting method, after all characters are inserted into the page, blank lines are easily caused at the end of some pages, resulting in low page utilization, poor display effect, and affecting user experience. The specific technical solution is as follows:
[0006] In a first aspect, the present application provides a text paging typesetting method, comprising:
[0007] Obtaining reading layout parameters corresponding to the text to be displayed, wherein the reading layout parameters include text size, character spacing, line spacing within a paragraph, and paragraph spacing;
[0008] Determine a text reading area on a display screen of a reading device, and determine an area width and an area height of the text reading area;
[0009] For each character in the to-be-displayed text, determine the character width corresponding to the character according to the character type of the character, and determine the character height corresponding to the character according to the text size;
[0010] The text to be displayed is paged and typeset according to the area width, the area height, the intra-segment line spacing, the segment spacing, and the character width and character height corresponding to each character to obtain corresponding text typesetting data.
[0011] In a possible implementation, determining the character width corresponding to the character according to the character type of the character includes:
[0012] In the case where the character type is a fixed-width character, the sum of the font width corresponding to the text size and the character spacing is determined as the character width corresponding to the character;
[0013] In the case that the character type is a non-uniform-width character, the width of the character is measured to obtain a measured width, and the sum of the measured width and the character spacing is determined as the character width corresponding to the character.
[0014] In a possible implementation, the paging layout of the text to be displayed according to the area width, the area height, the line spacing within the segment, the segment spacing, and the character width and character height corresponding to each character includes:
[0015] Traversing the text to be displayed character by character starting from the first character, and taking the sum of the character widths of all traversed characters as the current width of the current text line;
[0016] If the current character traversed is a line break character, or the current width is greater than the area width, the text height of the traversed text on the current page is determined according to the intra-segment line spacing, the segment spacing, and the character height;
[0017] If the text height is less than or equal to the area height, a line break operation is performed;
[0018] If the text height is greater than the region height, a page change operation is performed, and after the page change, traversal continues from the current character, word by word, until the last character of the text to be displayed is traversed.
[0019] In a possible implementation manner, determining the text height of the traversed text on the current page according to the intra-segment line spacing, the segment spacing, and the character height includes:
[0020] Determine the number of text lines and line breaks in the traversed text of the current page;
[0021] Calculating the sum of the character height and the line spacing to obtain the line height;
[0022] The product of the line height and the number of text lines and the product of the paragraph spacing and the number of line breaks are added together to obtain the text height of the traversed text on the current page.
[0023] In a possible implementation, determining a text reading area on a display screen of a reading device includes:
[0024] Determining a display screen width and a display screen height of the reading device display screen;
[0025] Obtain the height of the title bar above the display screen of the reading device and the height of the function bar below the display screen;
[0026] Get the preset top, bottom, left and right margins;
[0027] The middle area located in the middle of the display screen of the reading device is obtained by subtracting the left margin and the right margin from the width of the display screen, and subtracting the title bar height, the function bar height, the top margin and the bottom margin from the height of the display screen;
[0028] The middle area is determined as the text reading area.
[0029] In a possible implementation, the reading layout parameter further includes a title area height, and the method further includes:
[0030] When the current page is the first page of a chapter, the height of the title area is subtracted from the top of the middle area to obtain the text reading area.
[0031] In a possible implementation, the method further includes:
[0032] Create a child thread;
[0033] The sub-thread is used to execute the step of obtaining the reading layout parameters corresponding to the text to be displayed, and performing paging layout on the text to be displayed to obtain the corresponding text layout data;
[0034] The text layout data is transferred to the main thread, so that the main thread performs page rendering according to the text layout data.
[0035] In a second aspect, the present application provides a text paging and typesetting device, comprising:
[0036] A parameter acquisition module, used to acquire reading typesetting parameters corresponding to the text to be displayed, wherein the reading typesetting parameters include text size, character spacing, line spacing within a paragraph, and paragraph spacing;
[0037] An area determination module, used to determine a text reading area on a display screen of a reading device, and to determine an area width and an area height of the text reading area;
[0038] A size determination module, for determining, for each character in the to-be-displayed text, a character width corresponding to the character according to the character type of the character, and determining a character height corresponding to the character according to the text size;
[0039] The paging layout module is used to paginate the text to be displayed according to the area width, the area height, the line spacing within the paragraph, the paragraph spacing, and the character width and character height corresponding to each character to obtain corresponding text layout data.
[0040] In a possible implementation manner, the size determination module is specifically used to:
[0041] In the case where the character type is a fixed-width character, the sum of the font width corresponding to the text size and the character spacing is determined as the character width corresponding to the character;
[0042] In the case that the character type is a non-uniform-width character, the width of the character is measured to obtain a measured width, and the sum of the measured width and the character spacing is determined as the character width corresponding to the character.
[0043] In a possible implementation, the paging layout module is specifically used to:
[0044] Traversing the text to be displayed character by character starting from the first character, and taking the sum of the character widths of all traversed characters as the current width of the current text line;
[0045] If the current character traversed is a line break character, or the current width is greater than the area width, the text height of the traversed text on the current page is determined according to the intra-segment line spacing, the segment spacing, and the character height;
[0046] If the text height is less than or equal to the area height, a line break operation is performed;
[0047] If the text height is greater than the region height, a page change operation is performed, and after the page change, traversal continues from the current character, word by word, until the last character of the text to be displayed is traversed.
[0048] In a possible implementation, the paging layout module is further used to:
[0049] Determine the number of text lines and line breaks in the traversed text of the current page;
[0050] Calculating the sum of the character height and the line spacing to obtain the line height;
[0051] The product of the line height and the number of text lines and the product of the paragraph spacing and the number of line breaks are added together to obtain the text height of the traversed text on the current page.
[0052] In a possible implementation manner, the region determination module is specifically configured to:
[0053] Determining a display screen width and a display screen height of the reading device display screen;
[0054] Obtain the height of the title bar above the display screen of the reading device and the height of the function bar below the display screen;
[0055] Get the preset top, bottom, left and right margins;
[0056] The middle area located in the middle of the display screen of the reading device is obtained by subtracting the left margin and the right margin from the width of the display screen, and subtracting the title bar height, the function bar height, the top margin and the bottom margin from the height of the display screen;
[0057] The middle area is determined as the text reading area.
[0058] In a possible implementation manner, the reading layout parameter further includes a title area height, and the area determination module is further used to:
[0059] When the current page is the first page of a chapter, the height of the title area is subtracted from the top of the middle area to obtain the text reading area.
[0060] In a possible implementation manner, the device further includes an execution module, configured to:
[0061] Create a child thread;
[0062] The sub-thread is used to execute the step of obtaining the reading layout parameters corresponding to the text to be displayed, and performing paging layout on the text to be displayed to obtain the corresponding text layout data;
[0063] The text layout data is transferred to the main thread, so that the main thread performs page rendering according to the text layout data.
[0064] In a third aspect, an electronic device is provided, comprising a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory communicate with each other via the communication bus;
[0065] Memory, used to store computer programs;
[0066] The processor is used to implement any method step described in the first aspect when executing a program stored in the memory.
[0067] In a fourth aspect, a computer-readable storage medium is provided, characterized in that a computer program is stored in the computer-readable storage medium, and when the computer program is executed by a processor, any method step described in the first aspect is implemented.
[0068] In a fifth aspect, a computer program product comprising instructions is provided, which, when executed on a computer, enables the computer to execute any of the above-mentioned text pagination and typesetting methods.
[0069] Beneficial effects of the embodiments of the present application:
[0070] The embodiment of the present application provides a text paging and typesetting method, device, electronic device and storage medium. In the present application, first, the reading and typesetting parameters corresponding to the text to be displayed are obtained, and the reading and typesetting parameters include the text size, character spacing, line spacing within a paragraph and paragraph spacing. Then, the text reading area is determined on the display screen of the reading device, and the area width and area height of the text reading area are determined. Then, for each character in the text to be displayed, the character width corresponding to the character is determined according to the character type of the character, and the character height corresponding to the character is determined according to the text size. Finally, according to the area width, the area height, the line spacing within a paragraph, the paragraph spacing and the character width and character height corresponding to each character, the text to be displayed is paginated and typeset to obtain the corresponding text typesetting data. Through this scheme, the character width of each character can be determined according to its character type, so as to improve the accuracy of character width confirmation. In this way, when paginating and typesetting is performed according to the character width and other parameters, the situation of blank lines at the end of the page can be avoided, the page utilization rate is improved, the display effect is improved, and the user experience is enhanced.
[0071] Of course, implementing any product or method of the present application does not necessarily require achieving all of the advantages described above at the same time. BRIEF DESCRIPTION OF THE DRAWINGS
[0072] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the invention and, together with the description, serve to explain the principles of the invention.
[0073] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.
[0074] One or more embodiments are exemplarily described by pictures in the corresponding drawings, and these exemplified descriptions do not constitute limitations on the embodiments. Elements with the same reference numerals in the drawings represent similar elements, and unless otherwise stated, the figures in the drawings do not constitute proportional limitations.
[0075] Figure 1 A flowchart of a text paging and typesetting method provided in an embodiment of the present application;
[0076] Figure 2 An example of a text reading area provided in an embodiment of the present application;
[0077] Figure 3 An example of a text reading area on the first page of a chapter provided in an embodiment of the present application;
[0078] Figure 4 A flowchart of another text paging and typesetting method provided in an embodiment of the present application;
[0079] Figure 5 A structural schematic diagram of a text paging and typesetting device provided in an embodiment of the present application;
[0080] Figure 6 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0081] In order to make the purpose, technical solution and advantages of the embodiments of the present application clearer, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of this application.
[0082] The disclosure below provides many different embodiments or examples to implement different structures of the present invention. In order to simplify the disclosure of the present invention, the parts and settings of specific examples are described below. Of course, they are only examples, and the purpose is not to limit the present invention. In addition, the present invention can repeat reference numbers and / or letters in different examples. This repetition is for the purpose of simplification and clarity, and does not itself indicate the relationship between the various embodiments and / or settings discussed.
[0083] Figure 1A flow chart of a text paging and typesetting method provided for an embodiment of the present application. The method can be applied to one or more electronic devices such as smart phones, laptops, desktop computers, portable computers, servers, etc. In addition, the execution subject of the method can be hardware or software. When the above-mentioned execution subject is hardware, the execution subject can be one or more of the above-mentioned electronic devices. For example, a single electronic device can execute the method, or multiple electronic devices can cooperate with each other to execute the method. When the above-mentioned execution subject is software, the method can be implemented as multiple software or software modules, or as a single software or software module. No specific limitation is made here.
[0084] like Figure 1 As shown, the method specifically includes:
[0085] S101. Obtain reading layout parameters corresponding to the text to be displayed, wherein the reading layout parameters include text size, character spacing, line spacing within a paragraph, and paragraph spacing.
[0086] The text to be displayed refers to the text that needs to be displayed, for example, electronic documents such as electronic books and electronic manuals.
[0087] The text size refers to the font size and style used to display the text content in the document.
[0088] Character spacing refers to the distance between characters, which affects the density of text in a line or paragraph.
[0089] Line spacing refers to the distance between lines of text in a paragraph. By adjusting the line spacing, you can make the document reading experience more comfortable and the layout more beautiful.
[0090] Paragraph spacing refers to the distance between paragraphs in a document.
[0091] In one embodiment, the reading layout parameters can be set by the user according to actual needs.
[0092] In another embodiment, if the user does not set the reading layout parameters, the preset default parameters can be used as the reading layout parameters.
[0093] S102: Determine a text reading area on a display screen of a reading device, and determine an area width and an area height of the text reading area.
[0094] The reading device display screen refers to the display screen of a mobile electronic device (for example, a mobile phone, tablet computer, or other electronic reader) used to display text to be displayed.
[0095] The text reading area refers to the area on the display screen of the reading device used to display the text to be displayed. Correspondingly, the area width is the width of the text reading area, and the area height is the height of the text reading area.
[0096] In one embodiment, the specific implementation of determining the text reading area on the display screen of the reading device may include the following steps:
[0097] Step A1, determining the display screen width and display screen height of the reading device display screen;
[0098] Step A2, obtaining the height of the title bar above the display screen of the reading device and the height of the function bar below the display screen;
[0099] Step A3, obtaining the preset top margin, bottom margin, left margin and right margin;
[0100] Step A4, subtracting the left margin and the right margin from the width of the display screen, and subtracting the title bar height, the function bar height, the top margin and the bottom margin from the height of the display screen, to obtain a middle area located in the middle of the display screen of the reading device;
[0101] Step A5: determine the middle area as the text reading area.
[0102] In the application, the top margin, bottom margin, left margin and right margin can be set by the user according to actual needs. If the user does not set them, the preset default values can be used as the top margin, bottom margin, left margin and right margin.
[0103] From the above description, it can be seen that in this embodiment, the left margin and the right margin are subtracted from the display screen width of the reading device display screen, and the title bar height, the function bar height, the top margin and the bottom margin are subtracted from the display screen height to obtain the following: Figure 2 The middle area in the middle of the display screen of the reading device is the text reading area. In this way, after paging and typesetting based on the text reading area, the typesetting page can be displayed just in the middle area in the middle of the display screen of the reading device, and the text content will not be blocked by the upper title bar and the lower function bar.
[0104] In another embodiment, the reading layout parameters also include the height of the title area. The specific implementation of determining the text reading area on the display screen of the reading device may also include the following steps: when the current page is the first page of the chapter, subtract the height of the title area from the top of the middle area to obtain the text reading area.
[0105] In the application, the text to be displayed may be a chapter in a complete e-book document. In this case, the first page of the chapter is the first page of the paginated layout.
[0106] Figure 3 The following is an example of a text reading area on the first page of a chapter. Figure 3 As shown, the left and right margins are subtracted from the width of the display screen of the reading device, and the title bar height, function bar height (i.e., bottom information area), top margin, bottom margin, and title area height of the chapter homepage title area are subtracted from the display screen height to obtain the middle area in the middle of the display screen of the reading device, i.e., the text reading area. In this way, after pagination layout based on the text reading area, the main text content will not be blocked by the chapter homepage title area.
[0107] S103. For each character in the to-be-displayed text, determine the character width corresponding to the character according to the character type of the character, and determine the character height corresponding to the character according to the text size.
[0108] Character type, including fixed-width characters and non-fixed-width characters. Fixed-width characters include Chinese characters and full-width characters; non-fixed-width characters include English characters, numbers, half-width characters, special characters, etc.
[0109] In one embodiment, the specific implementation of determining the character width corresponding to the character according to the character type of the character may include the following steps: when the character type is a fixed-width character, the sum of the font width corresponding to the text size and the character spacing is determined as the character width corresponding to the character; when the character type is a non-fixed-width character, the width of the character is measured to obtain a measured width, and the sum of the measured width and the character spacing is determined as the character width corresponding to the character.
[0110] From the above description, we can know that the width of each character of a monospaced character is the font size width + character spacing, and the width of each character of a non-monospaced character is the actual measured width + character spacing. Taking the application scenario of the Hongmeng Next system as an example, the measureText method provided by the Hongmeng Next system can be used to measure the character width in real time. In this way, the character width of each character can be determined according to its character type, thereby improving the accuracy of character width confirmation.
[0111] In another embodiment, the character height of each character is the font size height of the main text.
[0112] S104, paging the text to be displayed according to the area width, the area height, the intra-segment line spacing, the segment spacing, and the character width and character height corresponding to each character to obtain corresponding text layout data.
[0113] The text layout data includes at least one page obtained after paging the text to be displayed and the layout data corresponding to each page.
[0114] In the embodiment of the present application, the text to be displayed can be paged and laid out according to the reading layout parameters of the text to be displayed, as well as the area width and area height of the text reading area, to obtain text layout data. In this way, each page in the text layout data can display as much text content as possible, thereby avoiding the occurrence of blank lines at the end of the page, improving page utilization, improving display effects, and enhancing user experience.
[0115] As for how to perform page layout on the displayed text, it will be described in detail through the embodiments below and will not be described in detail here.
[0116] In the embodiment of the present application, first, the reading typesetting parameters corresponding to the text to be displayed are obtained, and the reading typesetting parameters include the text size, character spacing, line spacing within a paragraph, and paragraph spacing. Then, the text reading area is determined on the display screen of the reading device, and the area width and area height of the text reading area are determined. Then, for each character in the text to be displayed, the character width corresponding to the character is determined according to the character type of the character, and the character height corresponding to the character is determined according to the text size. Finally, according to the area width, the area height, the line spacing within a paragraph, the paragraph spacing, and the character width and character height corresponding to each character, the text to be displayed is paged and typeset to obtain the corresponding text typesetting data. Through this solution, the character width of each character can be determined according to its character type, thereby improving the accuracy of character width confirmation. In this way, when paged and typeset according to the character width and other parameters, blank lines at the end of the page can be avoided, thereby improving page utilization, improving display effects, and enhancing user experience.
[0117] See also Figure 4 , is a flow chart of another embodiment of a text paging typesetting method provided in an embodiment of the present application. Figure 4 The process shown in the above Figure 1 Based on the process shown in the figure, it is described how to perform page layout for the text to be displayed according to the area width, the area height, the line spacing within the segment, the segment spacing, and the character width and character height corresponding to each character. Figure 4 As shown, the process may include the following steps:
[0118] S401, traversing the text to be displayed character by character starting from the first character, and taking the sum of the character widths of all traversed characters as the current width of the current text line;
[0119] S402: if the current traversed character is a line break character, or the current width is greater than the region width, determine the text height of the traversed text on the current page according to the intra-segment line spacing, the segment spacing, and the character height;
[0120] S403: If the text height is less than or equal to the region height, a line break operation is performed;
[0121] S404: If the text height is greater than the region height, a page change operation is performed, and after the page change, traversal continues from the current character, word by word, until the last character of the text to be displayed is traversed.
[0122] For ease of understanding, S401-S404 are described in a unified manner as follows:
[0123] Among them, the specific implementation of determining the text height of the traversed text on the current page according to the intra-segment line spacing, the segment spacing and the character height may include the following steps: determining the number of text lines and the number of line breaks on the traversed text on the current page; summing the character height and the line spacing to obtain the line height; adding the product of the line height and the number of text lines and the product of the segment spacing and the number of line breaks to obtain the text height of the traversed text on the current page. In this way, the height of the traversed text on the current page can be intelligently calculated.
[0124] In the application, the technical solution provided in the embodiment of the present application can be implemented based on the Hongmeng Next system. Specifically, the Hongmeng Next system development language Arkts is used to customize the Hongmeng Next system, thereby implementing the paging typesetting algorithm and layout drawing of the mobile text reader on the Hongmeng Next system. The following is an explanation of the implementation process of this solution based on the Hongmeng Next system development language Arkts:
[0125] First, define the ReaderTxtPageInfo class to store page information, which contains the following fields:
[0126] linesContent: string[] = ["]; / / Store the content of each line;
[0127] lineIndexes:number[][]=[]; / / Store the start character position index and end position index of each line;
[0128] wordCount:number=0; / / Store the number of words per page;
[0129] firstIndex:number=0; / / Store the index of the first word on each page;
[0130] lastIndex:number=0; / / Store the index of the last word on each page;
[0131] pageNum:number=0; / / Store the current page number;
[0132] Define the input text (ie, the text to be displayed) as text, the traversal index as textIndex, traverse the text, and take the current character char=text[textIndex], where char is a variable, referring to the character currently obtained in the text that needs to be processed.
[0133] Next, the specific pagination layout steps:
[0134] Step 1: First, determine whether the current character char is 32≤ascii code value≤126. If so, it means that the current letter is English, number or other non-equal-width characters. Use the MeasureText.measureText method provided by Arkui, pass the current character char and fontSize (font size) as parameters, measure the width of the character, and assign the value to fontWidth (character width). If it is not the above non-equal-width characters, it is an equal-width character, and fontSize is directly assigned to fontWidth.
[0135] Step 2: Assume that the text line width after the current character is appended to the current line is: lineWidth = currentLineWidth + measureFontWidth (char, fontSize) - letterSpacing, where lineWidth is the text line width, currentLineWidth is the actual width of the current line, measureFontWidth (char, fontSize) is the character width of the current character, and letterSpacing is the character spacing, that is, the meaning of this formula is: the actual width of the current line plus the character width of the current character minus the last extra character spacing. If lineWidth is greater than the reading area width readerWidth (that is, the area width of the text reading area), it means that the current text line width has exceeded the reading area width and needs to be wrapped, or char == '\n', that is, the current character is a line break character and also needs to be wrapped. Otherwise, no line break is required, and the char character is directly appended after the current text line, and the current text line width is updated currentLineWidth = currentLineWidth + measureFontWidth (char, fontSize), and then the next character is traversed.
[0136] Step 3: If line break processing is required, it is necessary to measure whether the current reading area height (i.e., the area height of the text reading area) has been exceeded after line break. The measurement and judgment method is if((currentLineCount+1)*(fontSize+lineSpacing)+(paragraphCount*paragraphSpacing)+(char==='\n'?paragraphSpacing:0)>(isFirstPage?(currentPageHeight-chapterNameHeight):currentPageHeight)); the meaning of this formula is: the total number of lines obtained after the current number of lines is increased by 1 line*(font size+line spacing)+(current number of line breaks in this page*paragraph spacing)>reading area height. If the judgment is true, it indicates that page turning is required; if the judgment is false, it indicates that page turning is not required, and the content of this line is recorded in the linesContent array of the content of this page, and at the same time, the starting index of this line is recorded in the lineIndexes array, and the current character is listed as the first character of the line content of the new line, and the character width is set to the current line width of the new line, currentLineWidth, and then continue to traverse the next character.
[0137] Step 4: If you need to turn the page, write the current line content into the linesContent array of the page content. At the same time, record the starting index of the line into the lineIndexes array, create a new page object ReaderTxtPageInfo, and store the linesContent array, lineIndexes array, wordCount count, firstIndex of this page, lastIndex of this page, and pageNum of this page into ReaderTxtPageInfo, and store the newly created page object ReaderTxtPageInfo into the ReaderTxtPageInfo page array. At the same time, add 1 to pageNum, set the other temporary variables to their original state, and start a new page to record again.
[0138] Step 5: If the end of the line and the end of the page have not been reached when traversing to the last character (that is, if the current line content length is greater than 0 after the last character is processed and the loop is exited, that is, there is still content that has not been written into the lineConent array), the line break operation and page turning operation are not triggered. At this time, determine whether the length of the last line is greater than 0. If it is greater than 0, it means that there is text content in the line. The last line of text needs to be written into the linesContent array, and the first and last indexes of the line are written into lineIndexes. Then, determine the number of lines on the current page, that is, linesContent.length. If it is greater than 0, it means that there is text content on the page. Create a new ReaderTxtPageInfo object for the last page, and store the linesContent array, lineIndexes array, wordCount, firstIndex, lastIndex, and pageNum of the last page in ReaderTxtPageInfo, and store ReaderTxtPageInfo in the page array. At this point, the text content is paginated, and the ReaderTxtPageInfo array stores all the typeset page content.
[0139] Through this solution, the text to be displayed can be paged and laid out according to the reading layout parameters of the text to be displayed, as well as the area width and area height of the text reading area, to obtain text layout data. In this way, each page in the text layout data can display as much text content as possible, thereby avoiding the occurrence of blank lines at the end of the page, improving page utilization, improving display effects, and enhancing user experience.
[0140] In the application, the paging algorithm corresponding to the above S101-S104 is a computationally intensive algorithm. To ensure that the paging algorithm does not affect the front-end page rendering and cause page freeze, in another embodiment of the present application, the method may further include the following steps:
[0141] Create a child thread; use the child thread to execute the step of obtaining the reading layout parameters corresponding to the text to be displayed, and perform paging layout on the text to be displayed to obtain corresponding text layout data; pass the text layout data to the main thread, so that the main thread can render the page according to the text layout data.
[0142] In an embodiment of the present application, the process corresponding to S101-S104 can be executed in a separately created child thread, and the execution result (i.e., text layout data, which can be a ReaderTxtPageInfo array in the application) can be serialized as a string in json format. Then, the serialized execution result can be passed to the main thread through inter-thread communication, and the page information in the execution result can be saved in the ReaderTxtPageInfo array of the main thread after reverse json serialization for page rendering.
[0143] Specifically, the rendering process is as follows:
[0144] In the page drawing page TxtPageView, the page is drawn through Canvas, and the linesContent array in each page is traversed. Each item of linesContent represents the line text that needs to be rendered in that line. The fillText method of Arkui is used to combine the word spacing, line spacing, paragraph spacing, and font size to position and render each character of the line content. Specifically:
[0145] First, the position of the next character in the horizontal direction is positioned: currentX=currentX+measureFontWidth(char,fontSize), that is, the rendering position of the next character in the horizontal direction is the rendering position of the current character plus the width occupied by the current character. The width occupied by the current character includes the measured width of the current character and the letterSpacing. Then, the position of the next line in the vertical direction is positioned: currentY=(this.page.txtPageInfo?.pageNum==0?chapterNameHeight:0)+topMargin+(index*lineSpacing)+((index+1)*fontSize)+(paragraphCount*paragraphSpacing), that is, the rendering position of the next line in the vertical direction is: the top margin plus the line spacing and line height of all current lines, and then the total paragraph spacing. If the current page is the first page, the height of the title needs to be increased. In this way, the rendering of the text layout data is realized.
[0146] Through this solution, the sub-thread can be used to execute the paging layout algorithm, thereby ensuring that the paging layout algorithm does not affect the front-end page rendering process and avoiding page freeze problems.
[0147] Based on the same technical concept, the present application also provides a text paging typesetting device, such as Figure 5 As shown, the device comprises:
[0148] The parameter acquisition module 51 is used to acquire the reading typesetting parameters corresponding to the text to be displayed, wherein the reading typesetting parameters include the text size, character spacing, line spacing within a paragraph, and paragraph spacing;
[0149] An area determination module 52, used to determine a text reading area on a display screen of a reading device, and to determine an area width and an area height of the text reading area;
[0150] A size determination module 53 is used to determine, for each character in the to-be-displayed text, a character width corresponding to the character according to the character type of the character, and to determine a character height corresponding to the character according to the text size;
[0151] The page layout module 54 is used to page layout the text to be displayed according to the area width, the area height, the line spacing within the segment, the segment spacing, and the character width and character height corresponding to each character to obtain corresponding text layout data.
[0152] In a possible implementation manner, the size determination module is specifically used to:
[0153] In the case where the character type is a fixed-width character, the sum of the font width corresponding to the text size and the character spacing is determined as the character width corresponding to the character;
[0154] In the case that the character type is a non-uniform-width character, the width of the character is measured to obtain a measured width, and the sum of the measured width and the character spacing is determined as the character width corresponding to the character.
[0155] In a possible implementation, the paging layout module is specifically used to:
[0156] Traversing the text to be displayed character by character starting from the first character, and taking the sum of the character widths of all traversed characters as the current width of the current text line;
[0157] If the current character traversed is a line break character, or the current width is greater than the area width, the text height of the traversed text on the current page is determined according to the intra-segment line spacing, the segment spacing, and the character height;
[0158] If the text height is less than or equal to the area height, a line break operation is performed;
[0159] If the text height is greater than the region height, a page change operation is performed, and after the page change, traversal continues from the current character, word by word, until the last character of the text to be displayed is traversed.
[0160] In a possible implementation, the paging layout module is further used to:
[0161] Determine the number of text lines and line breaks in the traversed text of the current page;
[0162] Calculating the sum of the character height and the line spacing to obtain the line height;
[0163] The product of the line height and the number of text lines and the product of the paragraph spacing and the number of line breaks are added together to obtain the text height of the traversed text on the current page.
[0164] In a possible implementation manner, the region determination module is specifically configured to:
[0165] Determining a display screen width and a display screen height of the reading device display screen;
[0166] Obtain the height of the title bar above the display screen of the reading device and the height of the function bar below the display screen;
[0167] Get the preset top, bottom, left and right margins;
[0168] The middle area located in the middle of the display screen of the reading device is obtained by subtracting the left margin and the right margin from the width of the display screen, and subtracting the title bar height, the function bar height, the top margin and the bottom margin from the height of the display screen;
[0169] The middle area is determined as the text reading area.
[0170] In a possible implementation manner, the reading layout parameter further includes a title area height, and the area determination module is further used to:
[0171] When the current page is the first page of a chapter, the height of the title area is subtracted from the top of the middle area to obtain the text reading area.
[0172] In a possible implementation manner, the device further includes an execution module, configured to:
[0173] Create a child thread;
[0174] The sub-thread is used to execute the step of obtaining the reading layout parameters corresponding to the text to be displayed, and performing paging layout on the text to be displayed to obtain the corresponding text layout data;
[0175] The text layout data is transferred to the main thread, so that the main thread performs page rendering according to the text layout data.
[0176] In the embodiment of the present application, first, the reading typesetting parameters corresponding to the text to be displayed are obtained, and the reading typesetting parameters include the text size, character spacing, line spacing within a paragraph, and paragraph spacing. Then, the text reading area is determined on the display screen of the reading device, and the area width and area height of the text reading area are determined. Then, for each character in the text to be displayed, the character width corresponding to the character is determined according to the character type of the character, and the character height corresponding to the character is determined according to the text size. Finally, according to the area width, the area height, the line spacing within a paragraph, the paragraph spacing, and the character width and character height corresponding to each character, the text to be displayed is paged and typeset to obtain the corresponding text typesetting data. Through this solution, the character width of each character can be determined according to its character type, thereby improving the accuracy of character width confirmation. In this way, when paged and typeset according to the character width and other parameters, blank lines at the end of the page can be avoided, thereby improving page utilization, improving display effects, and enhancing user experience.
[0177] Based on the same technical concept, the embodiment of the present application also provides an electronic device, such as Figure 6 As shown, it includes a processor 111, a communication interface 112, a memory 113 and a communication bus 114, wherein the processor 111, the communication interface 112, and the memory 113 communicate with each other through the communication bus 114.
[0178] Memory 113, used for storing computer programs;
[0179] The processor 111 is used to execute the program stored in the memory 113 to implement the following steps:
[0180] Obtaining reading layout parameters corresponding to the text to be displayed, wherein the reading layout parameters include text size, character spacing, line spacing within a paragraph, and paragraph spacing;
[0181] Determine a text reading area on a display screen of a reading device, and determine an area width and an area height of the text reading area;
[0182] For each character in the to-be-displayed text, determine the character width corresponding to the character according to the character type of the character, and determine the character height corresponding to the character according to the text size;
[0183] The text to be displayed is paged and typeset according to the area width, the area height, the intra-segment line spacing, the segment spacing, and the character width and character height corresponding to each character to obtain corresponding text typesetting data.
[0184] The communication bus mentioned in the above electronic device can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. The communication bus can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, only one thick line is used in the figure, but it does not mean that there is only one bus or one type of bus.
[0185] The communication interface is used for communication between the above electronic device and other devices.
[0186] The memory may include a random access memory (RAM) or a non-volatile memory (NVM), such as at least one disk memory. Optionally, the memory may also be at least one storage device located away from the aforementioned processor.
[0187] The above-mentioned processor can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components.
[0188] In another embodiment provided in the present application, a computer-readable storage medium is provided, in which a computer program is stored. When the computer program is executed by a processor, the steps of any of the above-mentioned text paging and typesetting methods are implemented.
[0189] In another embodiment provided in the present application, a computer program product including instructions is also provided, which, when executed on a computer, enables the computer to execute any of the text paging and typesetting methods in the above embodiments.
[0190] The device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0191] Through the description of the above implementation methods, those skilled in the art can clearly understand that each implementation method can be implemented by means of software plus a general hardware platform, and of course, by hardware. Based on this understanding, the above technical solution is essentially or the part that contributes to the relevant technology can be embodied in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, a disk, an optical disk, etc., including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment or some parts of the embodiments.
[0192] It should be understood that the terms used herein are only for the purpose of describing specific example embodiments and are not intended to be limiting. Unless the context clearly indicates otherwise, the singular forms "one", "an" and "said" as used herein may also be meant to include plural forms. The terms "include", "comprise", "contain", and "have" are inclusive, and therefore specify the existence of stated features, steps, operations, elements and / or parts, but do not exclude the existence or addition of one or more other features, steps, operations, elements, parts, and / or combinations thereof. The method steps, processes, and operations described herein are not interpreted as necessarily requiring them to be performed in the specific order described or illustrated, unless the execution order is clearly indicated. It should also be understood that additional or alternative steps may be used.
[0193] The foregoing is merely a specific embodiment of the present invention, which enables those skilled in the art to understand or implement the present invention. Various modifications to these embodiments will be apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present invention. Therefore, the present invention will not be limited to the embodiments shown herein, but rather to the widest scope consistent with the principles and novel features claimed herein.
Claims
1. A text paging typesetting method, characterized in that: The method comprises: Obtaining reading layout parameters corresponding to the text to be displayed, wherein the reading layout parameters include text size, character spacing, line spacing within a paragraph, and paragraph spacing; Determine a text reading area on a display screen of a reading device, and determine an area width and an area height of the text reading area; For each character in the to-be-displayed text, determine the character width corresponding to the character according to the character type of the character, and determine the character height corresponding to the character according to the text size; The text to be displayed is paged and typeset according to the area width, the area height, the intra-segment line spacing, the segment spacing, and the character width and character height corresponding to each character to obtain corresponding text typesetting data.
2. The method according to claim 1, characterized in that The determining the character width corresponding to the character according to the character type of the character includes: In the case where the character type is a fixed-width character, the sum of the font width corresponding to the text size and the character spacing is determined as the character width corresponding to the character; In the case that the character type is a non-uniform-width character, the width of the character is measured to obtain a measured width, and the sum of the measured width and the character spacing is determined as the character width corresponding to the character.
3. The method according to claim 1, characterized in that The paging layout of the text to be displayed according to the area width, the area height, the line spacing within the segment, the segment spacing, and the character width and character height corresponding to each character includes: Traversing the text to be displayed character by character starting from the first character, and taking the sum of the character widths of all traversed characters as the current width of the current text line; If the current character traversed is a line break character, or the current width is greater than the area width, the text height of the traversed text on the current page is determined according to the intra-segment line spacing, the segment spacing, and the character height; If the text height is less than or equal to the area height, a line break operation is performed; If the text height is greater than the region height, a page change operation is performed, and after the page change, traversal continues from the current character, word by word, until the last character of the text to be displayed is traversed.
4. The method according to claim 3, characterized in that The determining the text height of the traversed text on the current page according to the intra-segment line spacing, the segment spacing, and the character height includes: Determine the number of text lines and line breaks in the traversed text of the current page; Calculating the sum of the character height and the line spacing to obtain the line height; The product of the line height and the number of text lines and the product of the paragraph spacing and the number of line breaks are added together to obtain the text height of the traversed text on the current page.
5. The method according to claim 1, characterized in that Determining a text reading area on a display screen of a reading device includes: Determining a display screen width and a display screen height of the reading device display screen; Obtain the height of the title bar above the display screen of the reading device and the height of the function bar below the display screen; Get the preset top, bottom, left and right margins; The middle area located in the middle of the display screen of the reading device is obtained by subtracting the left margin and the right margin from the width of the display screen, and subtracting the title bar height, the function bar height, the top margin and the bottom margin from the height of the display screen; The middle area is determined as the text reading area.
6. The method according to claim 5, characterized in that The reading layout parameter also includes the height of the title area, and the method further includes: When the current page is the first page of a chapter, the height of the title area is subtracted from the top of the middle area to obtain the text reading area.
7. The method according to claim 1, characterized in that The method further comprises: Create a child thread; The sub-thread is used to execute the step of obtaining the reading layout parameters corresponding to the text to be displayed, and performing paging layout on the text to be displayed to obtain the corresponding text layout data; The text layout data is transferred to the main thread, so that the main thread performs page rendering according to the text layout data.
8. A text paging and typesetting device, characterized in that: The device comprises: A parameter acquisition module, used to acquire reading typesetting parameters corresponding to the text to be displayed, wherein the reading typesetting parameters include text size, character spacing, line spacing within a paragraph, and paragraph spacing; An area determination module, used to determine a text reading area on a display screen of a reading device, and to determine an area width and an area height of the text reading area; A size determination module, for determining, for each character in the to-be-displayed text, a character width corresponding to the character according to the character type of the character, and determining a character height corresponding to the character according to the text size; The paging layout module is used to paginate the text to be displayed according to the area width, the area height, the line spacing within the paragraph, the paragraph spacing, and the character width and character height corresponding to each character to obtain corresponding text layout data.
9. An electronic device, characterized in that: It includes a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory communicate with each other through the communication bus; Memory, used to store computer programs; The processor is used to implement the text paging and typesetting method described in any one of claims 1 to 7 when executing the program stored in the memory.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the text paging and typesetting method according to any one of claims 1 to 7 is implemented.
Citation Information
Patent Citations
Text type-setting method and type-setting engine
CN102147790A
Page layout method and page layout device
CN105224540A
Text display method and equipment, storage medium and electronic equipment
CN108710601A
Paging method and device of webpage content, electronic equipment and readable storage medium
CN114625996A
Content typesetting method and device, equipment and storage medium
CN115146608A