Page generation method and device, equipment and storage medium
By obtaining character types and baseline widths to predict text width, determining text overflow positions and wrapping lines, the problem of low efficiency in determining text overflow positions in the prior art is solved, and page generation efficiency is improved.
Patent Information
- Application Number
- CN202410036572.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-01-10
- Publication Date
- 2025-07-11
AI Technical Summary
In the prior art, the efficiency of determining the location of text overflow is low, resulting in a low efficiency of page generation.
By obtaining the character type and baseline width of the initial input text, the text width prediction is performed, the text overflow position is determined, and the line breaking operation is performed to generate the target page.
It improves the efficiency of determining text overflow locations, broadens the usage scenarios of text width prediction, reduces resource consumption, and improves page generation efficiency.
Smart Images

Figure CN120296269A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the technical field of page processing, and particularly to a page generation method, apparatus, device, and storage medium. Background Art
[0002] In modern web design, text is one of the important contents of a web page. For a text container set by a web page designer or developer, if the input text content exceeds the size of the text container, then a text overflow problem will occur. Text overflow usually results in the truncation of the text content, which not only affects the appearance of the web page but also affects the readability and usability of the web page. To solve the text overflow problem, the text overflow position can be determined and the text can be wrapped based on the text overflow position; however, in the prior art, the efficiency of determining the text overflow position is low, which in turn leads to a low page generation efficiency. Summary of the Invention
[0003] The technical problem to be solved by this application is to provide a page generation method, apparatus, device, and storage medium, which can improve the efficiency and flexibility of determining the text overflow position, and thus improve the page generation efficiency.
[0004] To solve the above technical problem, on the one hand, this application provides a page generation method, including:
[0005] Obtain an initial input text for a target container; the initial input text includes characters of at least one character type;
[0006] Based on the number of characters of the character type in the initial input text and the baseline width corresponding to the character type, predict the text width of the initial input text to obtain the predicted text width of the initial input text;
[0007] When the predicted text width is greater than the container width of the target container, determine the first text overflow position of the initial input text based on the predicted text width and the container width;
[0008] Perform a line break operation on the initial input text based on the first text overflow position to obtain a target input text;
[0009] Render a page based on the target container into which the target input text has been input to generate a target page.
[0010] On the other hand, this application provides a page generation apparatus, including:
[0011] A text acquisition module, configured to obtain an initial input text for a target container; the initial input text includes characters of at least one character type;
[0012] A width prediction module for predicting the text width of the initial input text based on the number of characters of each character type in the initial input text and the baseline width corresponding to the character type, to obtain the predicted text width of the initial input text;
[0013] A first overflow position determination module for determining the first text overflow position of the initial input text based on the predicted text width and the container width when the predicted text width is greater than the container width of the target container;
[0014] A line break operation module for performing a line break operation on the initial input text based on the first text overflow position to obtain a target input text;
[0015] A page generation module for rendering a page based on the target container into which the target input text has been input to generate a target page.
[0016] On the other hand, the present application provides a computer device, which includes a processor and a memory. At least one instruction or at least one program segment is stored in the memory, and the at least one instruction or the at least one program segment is loaded and executed by the processor to implement the page generation method as described above.
[0017] On the other hand, the present application provides a computer storage medium, in which at least one instruction or at least one program segment is stored, and the at least one instruction or the at least one program segment is loaded and executed by a processor to implement the page generation method as described above.
[0018] Implementing the embodiments of the present application has the following beneficial effects:
[0019] The present application predicts the text width of the initial input text based on the number of characters of each character type in the initial input text and the baseline width corresponding to each character type, to obtain the predicted text width of the initial input text; thus, it can flexibly predict the text width of the initial input text according to the character type of the characters in the initial input text, avoiding restrictions on the character type and broadening the usage scenarios of text width prediction; on the other hand, when the number of each character type in the initial input text and the baseline width corresponding to each character type are determined, the predicted text width of the initial input text can be directly predicted, avoiding the problem of excessive resource consumption caused by calculating the text width by character width accumulation and the need to cross-engine call the corresponding width calculation method during each accumulation process. Therefore, the present application can improve the text width prediction efficiency and reduce the resource consumption during the text width prediction process; on this basis, the efficiency of determining the text overflow position can be improved, and further the generation efficiency of the target page can be improved. Description of the Drawings
[0020] To more clearly illustrate the technical solutions and advantages in the embodiments of the present application or the prior art, the following will briefly introduce the drawings required for the description of the embodiments or the prior art. Obviously, the drawings in the following description are only some embodiments of the present application. For those of ordinary skill in the art, without creative efforts, other drawings can also be obtained based on these drawings.
[0021] Figure 1 It is a schematic diagram of the implementation environment provided by the embodiments of the present application;
[0022] Figure 2 It is a flowchart of a page generation method provided by the embodiments of the present application;
[0023] Figure 3 It is a flowchart of a method for determining the first text overflow position provided by the embodiments of the present application;
[0024] Figure 4 It is a flowchart of a method for determining a target text sequence provided by the embodiments of the present application;
[0025] Figure 5 It is a flowchart of a text sequence fine-tuning method provided by the embodiments of the present application;
[0026] Figure 6 It is a flowchart of a method for generating a target input text based on a fixed-width character type provided by the embodiments of the present application;
[0027] Figure 7 It is a flowchart of a method for generating a target input text based on a non-fixed-width character type provided by the embodiments of the present application;
[0028] Figure 8 It is a schematic diagram of a page generation device provided by the embodiments of the present application;
[0029] Figure 9 It is a schematic diagram of the structure of a computer device provided by the embodiments of the present application;
[0030] Figure 10 It is another schematic diagram of the structure of a computer device provided by the embodiments of the present application. Detailed implementation manners
[0031] To make the objectives, technical solutions, and advantages of the present application clearer, the following will further describe the present application in detail with reference to the drawings. Obviously, the described embodiments are only some of the embodiments of the present application, rather than all embodiments. All other embodiments obtained by those of ordinary skill in the art based on the embodiments of the present application without creative efforts fall within the scope of protection of the present application.
[0032] It should be noted that the terms "first", "second", etc. in the description, claims and the above drawings of the present application are used to distinguish similar objects, and do not necessarily have to be used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged under appropriate circumstances, so that the embodiments of the present application described here can be implemented in an order other than those illustrated or described here. In addition, the terms "comprising" and "having" and any variations thereof are intended to cover non-exclusive inclusion. For example, a process, method, system, product or server comprising a series of steps or units does not necessarily have to be limited to those steps or units clearly listed, but may include other steps or units not clearly listed or inherent to these processes, methods, products or devices.
[0033] In the embodiments of the present application, the term "module" or "unit" refers to a computer program with a predetermined function or a part of a computer program, which works together with other relevant parts to achieve a predetermined goal, and can be implemented in whole or in part by using software, hardware (such as a processing circuit or a memory), or a combination thereof. Similarly, a processor (or multiple processors or memories) can be used to implement one or more modules or units. In addition, each module or unit can be a part of the overall module or unit that includes the function of that module or unit.
[0034] First, the following explanations are made for the relevant terms involved in the embodiments of this specification:
[0035] Canvas: Canvas is a newly added element in HTML5. It provides a canvas on which graphics, images, and animations can be drawn using JavaScript. The Canvas element is a two-dimensional grid, and each cell has a coordinate (x, y), which can be accessed and modified through JavaScript. On the Canvas, various graphics such as lines, shapes, gradients, text, and images can be created, and animation effects can be achieved. The methods in the Canvas API can be used to draw and manipulate graphic elements, such as drawing paths, filling and stroking colors, setting line widths and styles, etc. Canvas is widely used in games, graphic editors, data visualization, etc. in web development. By using Canvas, dynamic and interactive web effects can be achieved, enhancing the user experience and page attractiveness.
[0036] Please refer to Figure 1 , which shows a schematic diagram of the implementation environment provided by the embodiments of the present application. The implementation environment may include: at least one development client 110, a page server 120, and a display client 130. The development client 110 and the page server 120 can communicate data through a network, and the page server 120 and the display client 130 can communicate data through a network.
[0037] Specifically, a web page designer or developer can create a web page based on the development client 110. Specifically, the development client 110 can search for the text overflow position based on the initial input text, perform a line break operation based on the overflow position to obtain the target input text, render a target page based on the target container into which the target input text has been input, and then send the target page to the page server 120. The page server 120 can receive the target page sent by the development client 110 and store the target page. Alternatively, the development client 110 can send the initial input text to the page server 120. The page server 120 can search for the text overflow position based on the initial input text, perform a line break operation based on the overflow position to obtain the target input text, and render a target page based on the target container into which the target input text has been input.
[0038] When the page server 120 receives a page display request sent by the display client 130, it can send the page data of the target page to the display client 130 so that the display client 130 can display the target page.
[0039] Both the development client 110 and the display client 130 can communicate with the page server 120 based on the Browser / Server (B / S) mode or the Client / Server (C / S) mode. Both the development client 110 and the display client 130 can include entity devices such as smart phones, tablet computers, laptop computers, digital assistants, smart wearable devices, vehicle-mounted terminals, servers, etc., and can also include software running on the entity devices, such as application programs. The operating systems running on both the development client 110 and the display client 130 in the embodiments of the present application can include, but are not limited to, Android system, IOS system, linux, windows, etc.
[0040] The page server 120 can establish a communication connection with the development client 110 and the page server 120 can establish a communication connection with the display client 130 through wired or wireless means. The page server 120 can include an independently operating server, or a distributed server, or a server cluster composed of multiple servers, where the server can be a cloud server.
[0041] To solve the technical problem in the prior art that the efficiency of determining the text overflow position is relatively low, which in turn leads to a relatively low page generation efficiency, the present application provides a page generation method. The execution subject of this method can be the above-mentioned development client or page server, and the embodiments of the present application do not make specific limitations. Accordingly, please refer to Figure 2 , and this method can include:
[0042] S210. Obtain an initial input text for a target container; the initial input text includes characters of at least one character type.
[0043] In this embodiment, a page can be drawn based on a canvas, and relevant containers can be set in the canvas. The containers can be used to hold materials such as text and images. In this embodiment, when making a target page containing text content, a target container capable of holding text can be set; further, the target container can be used to hold text, or can be used to hold text and images, etc. Correspondingly, the initial input text can be the text content to be input into the target container.
[0044] When the initial input text is obtained, the characters included in the initial input text can be first identified in terms of character type to obtain the characters of at least one character type included in the initial input text and the number of characters of at least one character type. The character types in this embodiment can include monospace character types and non - monospace character types, where the non - monospace character types include non - monospace Chinese character types, non - monospace English character types, non - monospace numeric types, non - monospace punctuation types, etc. By traversing each character in the initial input text, the character types in the initial input text and the number of characters corresponding to each character type can be determined.
[0045] In this embodiment, a cache mechanism can also be introduced, such as the LRU (Least Recently Used) cache mechanism. The LRU cache mechanism is a common cache replacement strategy. The LRU cache mechanism is based on the principle of temporal locality, that is, the data that has been recently used is likely to be used again in the short term. According to this principle, the LRU cache assumes that the data that has been recently accessed is the most likely to be accessed in the future, so the data that has not been used for the longest time is replaced out of the cache to make room for new data. The LRU cache mechanism is implemented using a doubly linked list and a hash table; the doubly linked list is used to record the access order of data, and the hash table is used to achieve fast lookup. The relevant data of the historical input text after text width prediction can be stored in the cache, specifically, the text characters of the historical input text and the predicted text width of the historical input text can be stored; thus, after the initial input text is obtained, it can further include:
[0046] Perform a text comparison between the initial input text and the historical input text in the cache to obtain a text comparison result;
[0047] When the text comparison result indicates that the initial input text is the same as the historical input text, determine the predicted text width of the historical input text as the predicted text width of the initial input text.
[0048] The initial input text being the same as the historical input text may mean that the characters contained in the initial input text and the historical input text are the same and the character order is also the same. When the initial input text is the same as the historical input text, the text prediction width of the historical input text can be directly determined as the text prediction width of the initial input text without repeatedly performing text width prediction on the initial input text; this avoids the resource consumption caused by repeatedly performing text width prediction and can shorten the processing time, thereby improving the rendering performance.
[0049] When the text comparison result indicates that the initial input text is not the same as the historical input text, it means that there has been no text identical to the initial input text, and it is necessary to continue to execute step S220 to perform text width prediction on the initial input text.
[0050] S220. Perform text width prediction based on the number of characters of the character type in the initial input text and the baseline width corresponding to the character type to obtain the text prediction width of the initial input text.
[0051] In this embodiment, when text width prediction is required, text width prediction can be performed for a specified character type. The specified character types in this embodiment may include fixed-width character types and non-fixed-width character types, where non-fixed-width character types include non-fixed-width Chinese character types, non-fixed-width English character types, non-fixed-width numeric character types, non-fixed-width punctuation character types, etc.; thus, text width prediction can be performed on the characters of the specified character type in the initial input text, and character filtering can be performed on the characters of other character types other than the specified character type, that is, text width prediction is not performed on the characters of other character types; furthermore, the text prediction width obtained by prediction is the text prediction width of the characters of the specified character type in the initial input text and does not include the text prediction width of the characters of other character types.
[0052] In a specific example, the initial input text may contain one or more character types among the above-mentioned fixed-width character types, non-fixed-width Chinese character types, non-fixed-width English character types, non-fixed-width numeric character types, non-fixed-width punctuation character types. At the same time, the initial input text may also contain garbled characters, and the garbled characters are other character types. Therefore, when performing text width prediction, text width prediction can be performed on the characters of the specified character type, and text width prediction is not performed on the garbled characters.
[0053] For each character type in the specified character type, there is a corresponding baseline width. The baseline width of each character type can represent the average width of the character width of this character type in different application scenarios, or the baseline width of each character type can represent the application width of this character type in different application scenarios. The baseline width can be directly applied to the calculation process of text width prediction; for each character type, the character width corresponding to this character type can be obtained based on the product of the number of characters of this character type and the baseline width of this character type; the sum of the character widths corresponding to each character type in the initial input text is used to obtain the text prediction width of the initial input text.
[0054] In this embodiment, when the characters in the initial input text are all of the equal-width character type, text width prediction is performed based on the number of characters in the initial input text and the baseline width corresponding to the equal-width character type to obtain the text prediction width of the initial input text. For characters of the equal-width character type, the baseline width corresponding to each character is generally the same, so the text prediction width of the initial input text can be directly obtained based on the product of the number of characters in the initial input text and the baseline width corresponding to the equal-width character type.
[0055] Each character of a fixed-width font occupies the same horizontal space. For a fixed-width font, the total width of the initial input text can be directly calculated using the number of characters and the fixed width of the font, realizing fast prediction of the text width of the initial input text.
[0056] Furthermore, for characters in full-width state and characters in half-width state, their corresponding character widths may be different. Therefore, in this embodiment, a method for determining the indication width of the equal-width character type in different states is provided, which may specifically include:
[0057] Obtain the first character width corresponding to the equal-width character type in the full-width state and the second character width corresponding to the equal-width character type in the half-width state;
[0058] Determine the first character width as the baseline width corresponding to the equal-width character type in the full-width state, and determine the second character width as the baseline width corresponding to the equal-width character type in the half-width state.
[0059] A character of the equal-width character type in the full-width state and a character of the equal-width character type in the half-width state can be selected, and the character widths of the character of the equal-width character type in the full-width state and the character of the equal-width character type in the half-width state can be measured respectively, and then the baseline width of the character of the equal-width character type in the full-width state and the baseline width of the character of the equal-width character type in the half-width state can be determined.
[0060] By measuring the character widths of characters of the equal-width character type in different states respectively, the baseline width of the equal-width character type is determined, ensuring that the indication width of the equal-width character type can cover different states. Furthermore, when predicting the width of the equal-width character, according to the baseline width required by the actual state of the equal-width character, the accuracy of predicting the width of the equal-width character type is improved.
[0061] This embodiment also provides a method for determining the baseline width of non-equal-width character types, which may include:
[0062] Measure the widths of multiple characters corresponding to each non-equal-width character type to obtain the measured widths corresponding to each of the multiple characters;
[0063] Based on the average value of the measured widths corresponding to each of the multiple characters, determine the baseline width corresponding to each non-equal-width character type.
[0064] Non-equal-width character types include non-equal-width Chinese types, non-equal-width English types, non-equal-width numeric types, non-equal-width punctuation types, etc. For each non-equal-width character type, multiple characters of the corresponding non-equal-width character type can be selected. For example, multiple non-equal-width Chinese characters can be selected, the measured widths of the multiple non-equal-width Chinese characters are measured respectively, and the average value of the measured widths of the multiple non-equal-width Chinese characters is calculated, and this average value is used as the baseline width corresponding to the non-equal-width Chinese type. For multiple non-equal-width English characters, multiple non-equal-width numeric characters, and multiple non-equal-width punctuation characters, the method for determining their baseline widths is the same as that for determining the baseline width of the non-equal-width Chinese type, and will not be elaborated here.
[0065] By selecting corresponding multiple characters for each non-equal-width character type and determining the baseline width of the non-equal-width character based on the average value of the measured widths of the multiple characters, it is possible to determine the baseline width by combining the character widths of each non-equal-width character type in multiple usage scenarios, improving the versatility of the non-equal-width character type.
[0066] S230. In the case where the predicted width of the text is greater than the container width of the target container, determine the first text overflow position of the initial input text based on the predicted width of the text and the container width.
[0067] In the case where the predicted width of the initial input text is less than or equal to the container width of the target container, at this time, the predicted width of the initial input text does not exceed the container width of the target container, there is no need to predict the text overflow position of the initial input text, nor is there a need to perform a line break operation on the initial input text. The initial input text can be displayed in one line in the target container; in the case where the predicted width of the initial input text is less than or equal to the container width of the target container, the initial input text can be determined as the target input text.
[0068] In the case where the text prediction width of the initial input text is greater than the container width of the target container, at this time the text prediction width of the initial input text has exceeded the container width of the target container, and there will be a problem of text overflow when the initial input text is displayed in the target container. It is necessary to determine the first text overflow position of the initial input text based on the text prediction width and the container width of the target container. The characters before the first text overflow position are displayed in the same text line in the target container, and the characters after the first text overflow position need to be displayed on a new line in the target container, that is, the characters before the first text overflow position and the characters after the first text overflow position are in different text lines in the target container.
[0069] S240. Perform a line break operation on the initial input text based on the first text overflow position to obtain the target input text.
[0070] The first text overflow position can indicate the position where text truncation and line break are required. Thus, a text truncation operation can be performed on the initial input text at the first text overflow position, and a line break operation can be performed on the truncated text after text truncation to obtain the target input text. Therefore, the target input text can be a text including at least two text lines.
[0071] S250. Perform page rendering based on the target container in which the target input text has been input to generate a target page.
[0072] The sum of the character widths of the characters in each text line of the target input text except the last text line is adapted to the container width of the target container, and the sum of the character widths of the characters in the last text line can be less than or equal to the container width of the target container. Thus, there will be no text overflow problem in the target page generated by performing page rendering based on the target container in which the target input text has been input.
[0073] This application predicts the text width of the initial input text based on the number of characters of each character type and the corresponding baseline width of each character type in the initial input text, obtaining the text prediction width of the initial input text; thus, it can flexibly predict the text width of the initial input text according to the character types of the characters in the initial input text, avoiding restrictions on character types and broadening the usage scenarios of text width prediction; on the other hand, when determining the number of each character type and the corresponding baseline width of each character type in the initial input text, the text prediction width of the initial input text can be directly predicted, avoiding the problem of excessive resource consumption caused by calculating the text width by accumulating character widths and the need to cross-engine call the corresponding width calculation method in each accumulation process. Therefore, this application can improve the efficiency of text width prediction and reduce resource consumption during text width prediction; on this basis, it can improve the efficiency of determining the text overflow position and further improve the generation efficiency of the target page.
[0074] In this embodiment, when the text prediction width is greater than the container width, there may be a problem of text overflow, that is, the text exceeding the container width will overflow the target container; please refer to Figure 3 , which shows a method for determining the first text overflow position. The method may include:
[0075] S310. Perform a width search based on the text prediction width to obtain a target width corresponding to the container width.
[0076] The target width in this embodiment refers to a width close to the container width. The target width can be greater than the container width, less than the container width, or equal to the container width.
[0077] During the process of performing a width search based on the text prediction width, methods such as binary search or interpolation search can be used for the width search until the target width equal to the container width is found, or until the left boundary width left and the right boundary width right in the search process coincide.
[0078] S320. Determine the target text sequence corresponding to the target width; the target text sequence is a sequence formed by a continuous segment of characters starting from the first character of the initial input text; the text width of the target text sequence satisfies a preset condition with the target width.
[0079] A continuous character segment starting from the first character of the initial input text can form multiple text sequences. Each of the multiple text sequences corresponds to a text width, and the text width of a text sequence is the sum of the character widths of each character in the text sequence. The target text sequence that meets the preset condition can be the text sequence in the multiple text sequences whose text width is closest to the target width, or the text width of the target text sequence is equal to the target width.
[0080] In one example, a continuous character segment starting from the first character of the initial input text can form multiple text sequences. The text width of each of the multiple text sequences can be predicted to obtain the predicted text widths corresponding to the multiple text sequences respectively. Thus, the target text sequence can be determined from the multiple text sequences based on the predicted text widths corresponding to the multiple text sequences respectively. The text width of the target text sequence is the same as the target width, or the text width of the target text sequence is closest to the target width. For example, the initial input text is: abcdefg, and the multiple text sequences obtained accordingly can include: a, ab, abc, abcd, abcde, abcdef, abcdefg; when predicting the text width of each text sequence, the text prediction method in step S220 can be used respectively, which will not be elaborated here. By pre-forming multiple text sequences corresponding to the initial input text, when the target width is determined, the text widths of the multiple text sequences can be directly matched with the target width to determine the target text sequence, improving the convenience of determining the target text sequence.
[0081] In another example, it can be searched based on the total number of characters included in the initial input text. For details, please refer to Figure 4 , which shows a method for determining a target text sequence. The method can include:
[0082] S410. Search for the current middle character of the current input text.
[0083] In the initial state, the current input text is the initial input text, and the current middle character is the character at the middle position of the current input text. For example, if the current input text is abcdefg, the current middle character can be d.
[0084] S420. Generate a current text sequence based on the first character of the initial input text, the characters between the first character and the current middle character, and the current middle character.
[0085] A current text sequence can be formed based on the characters from the first character to the current middle character of the initial input text; continuing with the previous example, the current text sequence can be abcd.
[0086] S430. Predict the text width of the current text sequence based on the text prediction method in step S220 to obtain the current predicted text width;
[0087] S440. Determine whether the current predicted text width and the target width meet a preset condition; if so, execute step S480; if not, execute step S450.
[0088] S450. Determine whether the current predicted text width is less than the target width; if so, execute step S460; if not, execute step S470.
[0089] S460. In the case where the current predicted text width is less than the target width, determine the current input text based on the next character of the current middle character to the last character in the current input text; repeatedly execute step S410.
[0090] Continuing with the previous example, the re - determined current input text is efg, the current middle character can be f, and the current text sequence can be abcdef.
[0091] S470. In the case where the current predicted text width is greater than the target width, determine the current input text based on the first character in the current input text to the character before the current middle character; repeatedly execute step S410.
[0092] Continuing with the previous example, the re - determined current input text is abc, the current middle character can be b, and the current text sequence can be ab.
[0093] S480. Determine the current text sequence at the end of the loop as the target text sequence.
[0094] The target text sequence that meets the preset condition can be the text sequence with the text width closest to the target width, or the text width of the target text sequence is equal to the target width.
[0095] Search based on the total number of characters included in the initial input text. Taking the number of characters as the search basis, determine the search direction according to the relationship between the text width of the current text sequence formed during the search and the target width, and then determine the target text sequence, which improves the efficiency of determining the target text sequence.
[0096] S330. In the case where the text width of the target text sequence does not match the container width, perform a fine - tuning operation on the characters in the target text sequence based on the text width of the target text sequence and the container width to obtain an operated text sequence; the text width of the operated text sequence matches the container width.
[0097] The text width of the target text sequence determined based on the above operations may be close to the container width of the target container, but the matching degree is not very high; in this embodiment, the mismatch between the text width of the target text sequence and the container width may mean that the text width of the target text sequence is less than the container width, and the difference between the text width of the target text sequence and the container width is greater than a preset value; or the text width of the target text sequence is greater than the container width, and the difference between the text width of the target text sequence and the container width is greater than a preset value. By performing a fine-tuning operation on the characters in the formed target text sequence, the difference between the text width of the adjusted text sequence and the container width can be made less than or equal to the preset value, that is, the text width of the operated text sequence after the fine-tuning operation matches the container width.
[0098] S340. Determine the first text overflow position based on the position corresponding to the last character of the operated text sequence.
[0099] In this embodiment, the position corresponding to the last character of the operated text sequence can be determined as the first text overflow position, or the position between the last character and the next character can be determined as the first text overflow position, where the next character can be the character adjacent to and following the last character in the initial input text.
[0100] In this embodiment, a width search is performed based on the predicted text width to determine a target text sequence that fits the container width of the target container, and in the case where the target text sequence does not match the container width, the characters in the target text sequence are fine-tuned to obtain an operated text sequence that fits the container width, and then the text overflow position is determined based on the position corresponding to the last character of the operated text sequence, improving the accuracy of determining the text overflow position.
[0101] Further, please refer to Figure 5 , which shows a text sequence fine-tuning method, and the method may include:
[0102] S510. In the case where the text width of the target text sequence does not match the container width, determine the target text sequence as the current text sequence.
[0103] In this embodiment, the mismatch between the text width of the target text sequence and the container width may mean that the text width of the target text sequence is less than the container width, and the difference between the text width of the target text sequence and the container width is greater than a preset value; or the text width of the target text sequence is greater than the container width, and the difference between the text width of the target text sequence and the container width is greater than a preset value.
[0104] S520. Determine whether the text width of the current text sequence is greater than the container width; if so, execute step S530; if not, execute step S540.
[0105] The text width of the current text sequence can be the sum of the character widths of each character in the current text sequence. Correspondingly, the text width prediction method in step S220 can be used to determine the text width of the current text sequence, which will not be elaborated here.
[0106] S530. In the case where the text width of the current text sequence is greater than the container width, perform a character deletion operation on the last character of the current text sequence to obtain the current text sequence after the operation.
[0107] Performing a character deletion operation on the last character of the current text sequence can mean deleting the last character from the current text sequence to obtain the current text sequence after deletion.
[0108] S540. In the case where the text width of the current text sequence is less than the container width, add a character after the last character of the current text sequence to obtain the current text sequence after the operation; the added character is the character in the initial input text that is after the last character of the current text sequence and adjacent to the last character.
[0109] Adding a character after the last character of the current text sequence, and the added character is the next character of the last character of the current text sequence in the initial input text.
[0110] S550. Determine whether the text width of the current text sequence matches the container width; if so, execute step S560; if not, execute step S520.
[0111] After performing the corresponding operation on the current text sequence and updating, it can be determined whether the text width of the updated current text sequence matches the container width. The text width of the current text sequence can be the sum of the character widths of each character in the current text sequence. Correspondingly, the text width prediction method in step S220 can be used to determine the text width of the current text sequence, which will not be elaborated here.
[0112] By performing fine-tuning operations on the characters in the formed target text sequence, the difference between the text width of the adjusted text sequence and the container width can be made less than or equal to the preset value, that is, the text width of the text sequence after the operation after fine-tuning matches the container width.
[0113] S560. Determine the current text sequence at the end of the loop as the text sequence after the operation.
[0114] In the case where the text width of the target text sequence determined based on a wide range of width searches does not match the container width, fine-tuning operations such as deleting or adding characters to the characters in the target text sequence can be performed based on character-level operations. The fine-tuning operations are simple and easy to implement; and the sequence width of the fine-tuned text sequence is made to match the container width, which can maximize the utilization of the space of the target container on the basis of avoiding text overflow problems.
[0115] For fixed-width character types, due to the characteristic that each character occupies the same space, when the characters in the first text line of the target container are determined, the characters in subsequent text lines can be directly determined; for details, please refer to Figure 6 , which shows a method for generating a target input text based on a fixed-width character type. The method may include:
[0116] S610. When all the characters in the initial input text are of the fixed-width character type and the text width of the remaining text is greater than the container width, obtain the number of characters in the already-operated text sequence; the remaining text is the text formed by the characters after the first text overflow position of the initial input text; the already-operated text sequence is the sequence formed by the characters before the first text overflow position of the initial input text.
[0117] In this embodiment, the remaining text may be the text formed by the characters after the first text overflow position of the initial input text; it can also be understood that the remaining text is the text formed by the characters in the initial input text except for the already-operated text sequence, that is, the characters from the first text overflow position to the start position of the initial input text in the initial input text form the already-operated text sequence, and the characters after the first text overflow position form the remaining text.
[0118] When the text width of the remaining text is greater than the container width, it means that one text line of the target container cannot accommodate all the characters in the remaining text, and it is necessary to further judge the text overflow positions of the characters in the remaining text.
[0119] S620. Based on the order of the characters in the remaining text in the initial input text, divide the characters in the remaining text to obtain multiple character sequences with an order; the number of characters in the last character sequence among the multiple character sequences with an order is less than or equal to the number of characters in the already-operated text sequence; the number of characters in each character sequence except the last character sequence among the multiple character sequences with an order is equal to the number of characters in the already-operated text sequence.
[0120] According to the characteristic that each character of the equal-width character type occupies the same space, each character in the remaining text can be serially divided to obtain a character sequence corresponding to each text line; except for the last text line, the number of characters contained in other text lines in the target container is the same. Therefore, after determining the number of characters in the determined first text line, the number of characters in the subsequent text lines can be correspondingly determined, and the character sequence is divided based on the order of each character in the initial input text; the number of characters in the last text line can be the same as the number of characters in each previous text line, or less than the number of characters in each previous text line, which specifically needs to be determined based on the total number of characters contained in the initial input text.
[0121] S630. Generate the target input text based on the operated text sequence and the multiple character sequences with a sequence; the target input text includes multiple lines of text, and the operated text sequence, the multiple character sequences with a sequence correspond to the multiple lines of text one by one.
[0122] The character sequences obtained after sequence division correspond to the text lines one by one; for example, the initial input text of the equal-width character type is abcdefg. The first text line of the target container, that is, the characters of the operated text sequence, include ab. Correspondingly, the second text line of the target container should be cd, the third text line should be ef, and the fourth text line, that is, the last text line, should be g; it can be seen that the number of characters contained in the first text line, the second text line, and the third text line is the same, all 2, and the number of characters in the last text line is 1, which is determined based on the total number of characters contained in the initial input text.
[0123] In this embodiment, for the equal-width character type, when the number of characters contained in the first text line is determined, the number of characters in the subsequent text lines can be directly determined, and then the initial input text is line-wrapped based on the number of characters contained in each text line to determine the corresponding target input text, which improves the processing efficiency of the initial input text of the equal-width character type.
[0124] For non-equal-width character types, please refer to Figure 7 , which shows a method for generating a target input text based on non-equal-width character types. The method may include:
[0125] S710. When the characters in the initial input text are not of the equal-width character type and the text width of the remaining text is greater than the container width, determine the second text overflow position of the remaining text based on the text width of the remaining text and the container width; the remaining text is the text formed by the characters after the first text overflow position of the initial input text.
[0126] In this embodiment, the remaining text may be the text formed by the characters after the first text overflow position of the initial input text; it can also be understood that the remaining text is the text formed by the characters in the initial input text except for the already-operated text sequence. That is, the characters corresponding to the starting position of the initial input text from the first text overflow position form the already-operated text sequence, and the characters after the first text overflow position form the remaining text.
[0127] When the text width of the remaining text is greater than the container width, it indicates that one text line of the target container cannot accommodate all the characters in the remaining text, and it is necessary to further judge the text overflow positions of the characters in the remaining text. In this embodiment, the prediction of the text width of the remaining text can be implemented based on the method of step S220, and the determination of the second text overflow position can be implemented based on the method of step S230, which will not be elaborated here.
[0128] S720. Update the remaining text to obtain the updated remaining text; the updated remaining text is the text formed by the characters after the second text overflow position of the current input text.
[0129] After determining the second text overflow position, the remaining text can be updated, and the number of characters included in the updated remaining text is less than the number of characters included in the remaining text before the update.
[0130] S730. Judge whether the text width of the updated remaining text is less than or equal to the container width; if so, execute step S740; if not, execute step S710.
[0131] If the text width of the updated remaining text is less than or equal to the container width, it indicates that one text line of the target container can accommodate all the characters in the updated remaining text, and there is no need to judge the text overflow position, and the loop ends; if the text width of the updated remaining text is greater than the container width, it indicates that one text line of the target container cannot accommodate all the characters in the updated remaining text, and it is necessary to further judge the text overflow positions of the characters in the remaining text, and enter the next loop.
[0132] S740. Perform a line break operation on the initial input text based on the first text overflow position and the second text overflow position to obtain the target input text.
[0133] It should be noted that in this embodiment, a second text overflow position can be determined in each loop, that is, the number of second text overflow positions is the same as the number of loops, and the second text overflow position may include one or more text overflow positions.
[0134] Specifically, for the initial input text "abcdefg" with non-uniform-width fonts, the first text overflow position is after the character 'b', so the remaining text is "cdefg"; the text width of the remaining text "cdefg" is greater than the container width, and the second text overflow position of the remaining text "cdefg" is determined to be after 'c'; the remaining text is updated, and the updated remaining text is "defg"; the text width of the updated remaining text "defg" is greater than the container width, and the second overflow position of the remaining text "defg" is determined to be after 'e'; the remaining text is updated, and the updated remaining text is "fg"; the text width of the updated remaining text "fg" is equal to the container width, and the loop ends. It can be seen that in this example, the number of the second text overflow positions is 2; the corresponding target input text is "ab\nc\nde\nfg".
[0135] In this embodiment, when the characters in the initial input text are not of the uniform-width character type, the related operations of text width prediction and text overflow position determination can be repeatedly executed until the text width of the remaining text is less than or equal to the container width; thus, the line break operation for the text of the non-uniform-width character type is realized, and the processing efficiency of the text of the non-uniform-width character type is improved.
[0136] In the rendering scenario based on the Canvas canvas, the Canvas layout emphasizes imperative operations and requires precise control of the drawing and positioning processes of each element. This embodiment provides a rendering solution, and the specific implementation steps may include:
[0137] 1. Input preparation: First, receive the input string text and prepare for subsequent text overflow position search processing.
[0138] 2. Cache fast retrieval: Before starting the search, try to retrieve the width data of the characters from an efficient LRU cache. The LRU cache mechanism can quickly store and retrieve the recently used data, which can greatly reduce unnecessary calculation time. If the required data is in the cache, it can be directly used.
[0139] 3. Special processing for uniform-width fonts: If the required data is not found in the cache, check whether the font used for the text is a uniform-width font. Uniform-width fonts are often used in code and terminal displays, and the width of each character is the same. For uniform-width fonts, an efficient strategy is adopted: directly calculate the total width of the text using the number of characters and the fixed width of the font, and quickly find the possible overflow positions.
[0140] 4. Width prediction for non-uniform-width fonts: If the text is not a uniform-width font, a width prediction method based on the character type baseline is used to estimate the width of the text. This method can perform width prediction for different types of characters and provide a strong reference for subsequent precise search.
[0141] 1) Measure the baseline widths of different types of characters (such as Chinese, English, numbers, punctuation marks, etc.) in advance, and record the relevant data as the baseline widths of each type of character.
[0142] 2) Based on the above baseline widths and the number of each type of character in the string, the approximate width of the string can be estimated, enabling an understanding of whether the text may exceed the width of its container and providing a strong basis for accurately finding the overflow position subsequently.
[0143] 5. Determine the approximate text overflow position based on the baseline width and an efficient algorithm: After obtaining the predicted text width, use an efficient search algorithm, such as binary search or interpolation search, to locate the approximate position of text overflow.
[0144] 6. Fine-tune the approximate text overflow position by comparing the measured text width with the width of the container to accurately locate the text overflow position.
[0145] 7. Cache the results for future use: After finding the overflow position, store the character width data calculated this time back into the LRU cache. In this way, when the width of the same characters needs to be calculated next time, it can be directly retrieved from the cache, greatly improving the processing speed.
[0146] 8. Output the results: Finally, return the located text overflow position to the user to complete the entire processing flow. The user can make further adjustments or processing to the text, such as line breaks or truncation, based on this result.
[0147] Compared with the traditional method of measuring and comparing widths by accumulating characters one by one, the present invention significantly reduces the number of calls to the measureText method of CanvasRenderingContext2D by combining strategies, cache mechanisms, and algorithm optimization, thereby greatly reducing the performance overhead of cross-language calls. This improvement not only significantly reduces the time required to find the text overflow position but also enhances the overall rendering performance, enabling users to enjoy a smoother and more natural experience when browsing the web. Compared with the solution that limits the use of monospace fonts, the present invention does not restrict the font types used by users, thus providing users with a wider range of font selection spaces. This flexibility not only meets users' needs for font diversity but also enhances the overall user experience, enabling users to freely choose and use their favorite fonts without affecting performance. Generally speaking, the present invention has significant advantages in reducing performance overhead, improving search efficiency, and meeting user experience requirements, providing users with a more efficient and flexible solution for finding text overflow positions.
[0148] It should be noted that any of the above methods in this embodiment can be combined based on the actual implementation situation and have corresponding beneficial effects, which will not be elaborated here.
[0149] Please refer to Figure 8 , which shows a page generation device, including:
[0150] A text acquisition module 810, configured to acquire an initial input text for a target container; the initial input text includes characters of at least one character type;
[0151] A width prediction module 820, configured to perform text width prediction based on the number of characters of the character type in the initial input text and the baseline width corresponding to the character type, to obtain the text prediction width of the initial input text;
[0152] A first overflow position determination module 830, configured to, when the text prediction width is greater than the container width of the target container, determine a first text overflow position of the initial input text based on the text prediction width and the container width;
[0153] A line break operation module 840, configured to perform a line break operation on the initial input text based on the first text overflow position to obtain a target input text;
[0154] A page generation module 850, configured to perform page rendering based on the target container into which the target input text has been input to generate a target page.
[0155] Further, the first overflow position determination module 830 includes:
[0156] A search module, configured to perform width search based on the text prediction width to obtain a target width corresponding to the container width; the target width is equal to the container width or the target width is close to the container width;
[0157] A target text sequence determination module, configured to determine a target text sequence corresponding to the target width; the target text sequence is a sequence formed by a continuous segment of characters starting from the first character of the initial input text; the text width of the target text sequence satisfies a preset condition with the target width;
[0158] A fine-tuning operation module, configured to, when the text width of the target text sequence does not match the container width, perform a fine-tuning operation on the characters in the target text sequence based on the text width of the target text sequence and the container width to obtain an operated text sequence; the text width of the operated text sequence matches the container width;
[0159] A first determination module, configured to determine the first text overflow position based on the position corresponding to the last character of the operated text sequence.
[0160] Further, the fine-tuning operation module includes:
[0161] A second determination module, configured to determine the target text sequence as the current text sequence when the text width of the target text sequence does not match the container width;
[0162] A character deletion module, configured to perform a character deletion operation on the last character of the current text sequence to obtain an operated current text sequence when the text width of the current text sequence is greater than the container width;
[0163] A character addition module, configured to add a character after the last character of the current text sequence to obtain an operated current text sequence when the text width of the current text sequence is less than the container width; the added character is the character in the initial input text that is after the last character of the current text sequence and adjacent to the last character;
[0164] A first repeated execution module, configured to repeatedly execute the steps when the text width of the current text sequence does not match the container width: when the text width of the current text sequence is greater than the container width, perform a character deletion operation on the last character of the current text sequence to obtain an operated current text sequence; when the text width of the current text sequence is less than the container width, add a character after the last character of the current text sequence to obtain an operated current text sequence; until the text width of the target text sequence matches the container width;
[0165] A third determination module, configured to determine the current text sequence at the end of the loop as the operated text sequence.
[0166] Further, the line break operation module 840 includes:
[0167] A quantity acquisition module, configured to acquire the quantity of characters in the operated text sequence when all characters in the initial input text are of an equal-width character type and the text width of the remaining text is greater than the container width; the remaining text is the text formed by the characters after the first text overflow position of the initial input text; the operated text sequence is the sequence formed by the characters before the first text overflow position of the initial input text;
[0168] A partitioning module, configured to partition each character in the remaining text based on the order of each character in the initial input text, to obtain a plurality of character sequences with an order; the number of characters in the last character sequence among the plurality of character sequences with an order is less than or equal to the number of characters in the processed text sequence; the number of characters in each character sequence except the last character sequence among the plurality of character sequences with an order is equal to the number of characters in the processed text sequence;
[0169] A text generation module, configured to generate the target input text based on the processed text sequence and the plurality of character sequences with an order; the target input text includes multiple lines of text, and the processed text sequence, the plurality of character sequences with an order, and the multiple lines of text correspond one by one.
[0170] Further, the line break operation module 840 includes:
[0171] A fourth determination module, configured to, when the character in the initial input text is not an equal-width character type and the text width of the remaining text is greater than the container width, determine a second text overflow position of the remaining text based on the text width of the remaining text and the container width; the remaining text is the text formed by the characters after the first text overflow position of the initial input text;
[0172] A text update module, configured to update the remaining text to obtain updated remaining text; the updated remaining text is the text formed by the characters after the second text overflow position of the current input text;
[0173] A second repeated execution module, configured to repeatedly execute the steps: determining the second text overflow position of the remaining text based on the text width of the remaining text and the container width, until the remaining text is updated to obtain updated remaining text, until the text width of the updated remaining text is less than or equal to the container width;
[0174] A text line break module, configured to perform a line break operation on the initial input text based on the first text overflow position and the second text overflow position to obtain the target input text.
[0175] Further, the apparatus further includes:
[0176] A text comparison module, configured to compare the initial input text with a historical input text in a cache to obtain a text comparison result;
[0177] A fifth determination module, configured to, when the text comparison result indicates that the initial input text is the same as the historical input text, determine the text prediction width of the historical input text as the text prediction width of the initial input text.
[0178] Further, the width prediction module 820 is further configured to, when all characters in the initial input text are of an equal-width character type, perform text width prediction based on the number of characters in the initial input text and the baseline width corresponding to the equal-width character type, to obtain the text prediction width of the initial input text.
[0179] Further, the character types include multiple non-equal-width character types;
[0180] The apparatus further includes:
[0181] A width measurement module, configured to measure the widths of multiple characters corresponding to each non-equal-width character type, to obtain the measurement widths corresponding to the multiple characters respectively;
[0182] A sixth determination module, configured to determine the baseline width corresponding to each non-equal-width character type based on the average value of the measurement widths corresponding to the multiple characters respectively.
[0183] Further, the character types include an equal-width character type;
[0184] The apparatus further includes:
[0185] A character width acquisition module, configured to acquire a first character width corresponding to the equal-width character type in full-width state and a second character width corresponding to the equal-width character type in half-width state;
[0186] A baseline width determination module, configured to determine the first character width as the baseline width corresponding to the equal-width character type in full-width state, and determine the second character width as the baseline width corresponding to the equal-width character type in half-width state.
[0187] The apparatus provided in the above embodiments can execute the method provided in any embodiment of the present application, and has corresponding functional modules and beneficial effects for executing the method. Technical details not described in detail in the above embodiments can be referred to the method provided in any embodiment of the present application.
[0188] This embodiment further provides a computer-readable storage medium, in which at least one instruction or at least one program segment is stored, and the at least one instruction or the at least one program segment is loaded and executed by a processor to execute any one of the methods as described above in this embodiment.
[0189] According to one aspect of the present application, there is provided a computer program product or a computer program, which includes computer instructions stored in a computer-readable storage medium. The processor of the computer device reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions, so that the computer device executes any of the above methods.
[0190] Figure 9 FIG. is a block diagram of an electronic device for page generation shown according to an exemplary embodiment. The electronic device may be a terminal, and its internal structure diagram may be as Figure 9 shown. The electronic device includes a processor, a memory, a network interface, a display screen, and an input device connected through a system bus. Among them, the processor of the electronic device is used to provide computing and control capabilities. The memory of the electronic device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The network interface of the electronic device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, it implements a page generation method. The display screen of the electronic device may be a liquid crystal display screen or an electronic ink display screen. The input device of the electronic device may be a touch layer covering the display screen, or a button, a trackball, or a touchpad provided on the housing of the electronic device, or an external keyboard, a touchpad, or a mouse, etc.
[0191] Figure 10 FIG. is a block diagram of an electronic device for page generation shown according to an exemplary embodiment. The electronic device may be a server, and its internal structure diagram may be as Figure 10 shown. The electronic device includes a processor, a memory, and a network interface connected through a system bus. Among them, the processor of the electronic device is used to provide computing and control capabilities. The memory of the electronic device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The network interface of the electronic device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, it implements a page generation method.
[0192] Those skilled in the art can understand that Figure 9 and Figure 10 the structures shown in are only block diagrams of some structures related to the solution of the present disclosure, and do not constitute a limitation on the electronic devices to which the solution of the present disclosure is applied. The specific electronic device may include more or fewer components than those shown in the figure, or combine some components, or have different component arrangements.
[0193] This specification provides the method operation steps as described in the embodiments or flowcharts, but may include more or fewer operation steps based on routine or non-creative labor. The steps and sequences listed in the embodiments are only one way among the execution sequences of numerous steps and do not represent the only execution sequence. When the actual system or interrupt product is executed, it can be executed in the method sequence shown in the embodiments or the drawings or executed in parallel (e.g., in an environment of parallel processors or multi-threaded processing).
[0194] The structure shown in this embodiment is only a part of the structure related to the solution of this application and does not constitute a limitation on the device to which the solution of this application is applied. The specific device may include more or fewer components than those shown, or combine certain components, or have a different arrangement of components. It should be understood that the methods, devices, etc. disclosed in this embodiment can be implemented in other ways. For example, the device embodiments described above are only illustrative. For example, the division of the modules is only a logical function division, and there may be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the displayed or discussed coupling or direct coupling or communication connection to each other can be through some interfaces, indirect coupling or communication connection of the device or unit module.
[0195] Based on such an understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or all or part of this technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to enable a computer device (which can be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the methods described in various embodiments of this application. And the foregoing storage medium includes: various media such as USB flash drives, mobile hard disks, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), magnetic disks, or optical discs that can store program codes.
[0196] Those skilled in the art can further realize that the units and algorithm steps of each example described in combination with the embodiments disclosed in this specification can be implemented by electronic hardware, computer software, or a combination of both. To clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described according to functions in the above description. Whether these functions are executed in a hardware or software manner depends on the specific application and design constraints of the technical solution. Professional technicians can use different methods to implement the described functions for each specific application, but such implementation should not be considered to exceed the scope of this application.
[0197] As described above, the above embodiments are only used to illustrate the technical solutions of the present application, rather than limiting them; although the present application has been described in detail with reference to the foregoing embodiments, those of ordinary skill in the art should understand that they can still modify the technical solutions described in the foregoing embodiments, or perform equivalent replacements on some of the technical features; and these modifications or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present application.
Claims
1. A page generation method, characterized in that, Including: Obtain the initial input text for the target container; The initial input text includes characters of at least one character type; Based on the number of characters of the character type in the initial input text and the baseline width corresponding to the character type, perform text width prediction to obtain the text prediction width of the initial input text; When the text prediction width is greater than the container width of the target container, determine the first text overflow position of the initial input text based on the text prediction width and the container width; Perform a line break operation on the initial input text based on the first text overflow position to obtain the target input text; Based on the target container into which the target input text has been input, perform page rendering to generate a target page.
2. The method according to claim 1, wherein The determining the first text overflow position of the initial input text based on the text prediction width and the container width includes: Perform width lookup based on the text prediction width to obtain a target width corresponding to the container width; the target width is equal to the container width, or the target width is close to the container width; Determine the target text sequence corresponding to the target width; the target text sequence is a sequence formed by a continuous string of characters starting from the first character of the initial input text; the text width of the target text sequence and the target width meet a preset condition; When the text width of the target text sequence does not match the container width, based on the text width of the target text sequence and the container width, perform a fine-tuning operation on the characters in the target text sequence to obtain an operated text sequence; the text width of the operated text sequence matches the container width; Determine the first text overflow position based on the position corresponding to the last character of the operated text sequence.
3. The method according to claim 2, wherein The performing a fine-tuning operation on the characters in the target text sequence based on the text width of the target text sequence and the container width to obtain an operated text sequence includes: When the text width of the target text sequence does not match the container width, determine the target text sequence as the current text sequence; When the text width of the current text sequence is greater than the container width, perform a character deletion operation on the last character of the current text sequence to obtain the operated current text sequence; When the text width of the current text sequence is less than the container width, add a character after the last character of the current text sequence to obtain the operated current text sequence; the added character is the character in the initial input text that is located after the last character of the current text sequence and is adjacent to the last character; When the text width of the current text sequence does not match the container width, repeat the steps: when the text width of the current text sequence is greater than the container width, perform a character deletion operation on the last character of the current text sequence to obtain the current text sequence after the operation; when the text width of the current text sequence is less than the container width, add a character after the last character of the current text sequence to obtain the current text sequence after the operation; until the text width of the target text sequence matches the container width; Determine the current text sequence at the end of the loop as the processed text sequence.
4. The method according to claim 1 or 2, characterized in that, The line break operation on the initial input text based on the first text overflow position to obtain the target input text includes: When all characters in the initial input text are of the same-width character type and the text width of the remaining text is greater than the container width, obtain the number of characters in the processed text sequence; the remaining text is the text formed by the characters after the first text overflow position of the initial input text; the processed text sequence is the sequence formed by the characters before the first text overflow position of the initial input text; Based on the order of each character in the remaining text in the initial input text, divide the characters in the remaining text to obtain multiple character sequences with an order; the number of characters in the last character sequence among the multiple character sequences with an order is less than or equal to the number of characters in the processed text sequence; the number of characters in each character sequence except the last character sequence among the multiple character sequences with an order is equal to the number of characters in the processed text sequence; Generate the target input text based on the processed text sequence and the multiple character sequences with an order; the target input text includes multiple lines of text, and the processed text sequence, the multiple character sequences with an order, and the multiple lines of text correspond one by one.
5. The method according to claim 1 or 2, characterized in that The line break operation on the initial input text based on the first text overflow position to obtain the target input text includes: When the characters in the initial input text are not of the same-width character type and the text width of the remaining text is greater than the container width, determine the second text overflow position of the remaining text based on the text width of the remaining text and the container width; the remaining text is the text formed by the characters after the first text overflow position of the initial input text; Update the remaining text to obtain the updated remaining text; the updated remaining text is the text formed by the characters after the second text overflow position of the current input text; Repeat the steps: determine the second text overflow position of the remaining text based on the text width of the remaining text and the container width, until the remaining text is updated to obtain the updated remaining text, until the text width of the updated remaining text is less than or equal to the container width; Perform a line break operation on the initial input text based on the first text overflow position and the second text overflow position to obtain the target input text.
6. The method according to claim 1, wherein After obtaining the initial input text for the target container, the method further includes: Compare the initial input text with the historical input text in the cache to obtain a text comparison result; When the text comparison result indicates that the initial input text is the same as the historical input text, determine the text prediction width of the historical input text as the text prediction width of the initial input text.
7. The method according to claim 1, wherein The predicting the text width of the initial input text based on the number of characters of a character type in the initial input text and the baseline width corresponding to the character type includes: When all the characters in the initial input text are of an equal-width character type, predict the text width of the initial input text based on the number of characters in the initial input text and the baseline width corresponding to the equal-width character type.
8. The method according to claim 1, wherein The character type includes multiple non-equal-width character types; The method further includes: Measure the widths of multiple characters corresponding to each non-equal-width character type to obtain the measured widths corresponding to the multiple characters respectively; Determine the baseline width corresponding to each non-equal-width character type based on the average value of the measured widths corresponding to the multiple characters respectively.
9. The method according to claim 1 or 7, characterized in that, The character type includes an equal-width character type; The method further includes: Obtain the first character width corresponding to the equal-width character type in the full-width state and the second character width corresponding to the equal-width character type in the half-width state; Determine the first character width as the baseline width corresponding to the equal-width character type in the full-width state, and determine the second character width as the baseline width corresponding to the equal-width character type in the half-width state.
10. A page generation device, characterized in that, including: A text acquisition module, configured to acquire an initial input text for a target container; The initial input text includes characters of at least one character type; A width prediction module, configured to predict the text width of the initial input text based on the number of characters of a character type in the initial input text and the baseline width corresponding to the character type, to obtain the text prediction width of the initial input text; A first overflow position determination module, configured to, when the text prediction width is greater than the container width of the target container, determine a first text overflow position of the initial input text based on the text prediction width and the container width; A line break operation module, configured to perform a line break operation on the initial input text based on the first text overflow position to obtain a target input text; A page generation module, configured to perform page rendering based on the target container into which the target input text has been input to generate a target page.
11. A computer device, characterized in that, The device includes a processor and a memory, and at least one instruction or at least one program segment is stored in the memory, and the at least one instruction or the at least one program segment is loaded and executed by the processor to implement the page generation method according to any one of claims 1 to 9.
12. A computer storage medium, characterized in that, At least one instruction or at least one program segment is stored in the storage medium, and the at least one instruction or the at least one program segment is loaded and executed by a processor to perform the page generation method according to any one of claims 1 to 9.
Citation Information
Cited By
Text display method and device and medium
CN122452501A
A text display method, device and medium
CN122452501B