A text display method, device and medium

By estimating and adjusting the truncation position during text display, the problem of high resource consumption in text omission display is solved, and accurate prediction and dynamic correction of text truncation position are achieved, thus improving display efficiency.

CN122452501APending Publication Date: 2026-07-24FOUNDER SECURITIES CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
FOUNDER SECURITIES CO LTD
Filing Date
2026-06-22
Publication Date
2026-07-24

AI Technical Summary

Technical Problem

Existing technologies consume a lot of resources during text omission display, resulting in low text display efficiency.

Method used

By determining the total character width of the text to be displayed, the initial truncation position is estimated in the hidden container based on preset display parameters, and the target truncation position is adjusted in the rendering container to achieve omission display and reduce the number of rendering times.

Benefits of technology

It achieves accurate prediction and dynamic correction of text truncation positions, reduces rendering overhead, and optimizes text display efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122452501A_ABST
    Figure CN122452501A_ABST
Patent Text Reader

Abstract

The application discloses a text display method and device in the field of computer technology and a medium. The application first determines the total width of characters in the text to be displayed. Then, based on the preset display parameters and the total width of characters, the initial truncation position in the text to be displayed is estimated in the hidden container. Thus, the initial truncation position can be preliminarily estimated as the starting point of the cycle based on the overall size of the text. Based on the initial truncation position, the target truncation position is determined, and the precalculation can be quickly completed without affecting the front-end rendering display. Further, by checking whether the target truncation position is line-wrapped in the rendering container, the position of line-wrapping is adjusted forward, which can effectively prevent the abnormal line-wrapping, character misplacement or non-standard display of ellipsis after text truncation. In addition, the application not only realizes the accurate prediction and dynamic correction of the text truncation position, but also reduces the number of real rendering and the rendering overhead.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of computer technology, and in particular to a text display method, device and medium. Background Technology

[0002] In front-end applications, it's often necessary to omit text and provide an "expand / collapse" ellipsis control after the ellipsis for user interaction. Currently, this can be achieved by repeatedly rendering character by character or using a binary search method to determine the appropriate text truncation position, then displaying the ellipsis and ellipsis control at that position. However, this method can easily increase resource consumption and reduce text display efficiency due to multiple rendering attempts.

[0003] Therefore, how to reduce resource consumption during the text omission display process is a problem that needs to be solved by those skilled in the art. Summary of the Invention

[0004] In view of this, the purpose of this application is to provide a text display method, device and medium to reduce resource consumption during the text omission display process.

[0005] Firstly, this application provides a text display method, including: Get the text to be displayed; Determine the total width of the characters in the text to be displayed; Within the hidden container, based on preset display parameters and the total width of the characters, an initial truncation position is estimated in the text to be displayed, and a target truncation position is determined based on the initial truncation position. In the rendering container, if it is confirmed that a line break occurs at the target truncation position, the target truncation position is moved forward, and the text to be displayed is omitted based on the forward target truncation position.

[0006] Optionally, determining the total width of the characters in the text to be displayed includes: The characters in the text to be displayed are grouped according to preset categories to obtain multiple character groups; wherein, the preset categories are determined based on font type or character type; Determine the equivalent width of each character in each character group; where the equivalent width of each character in the same character group is the same. The total width of the character is obtained by summing the equivalent widths of individual characters in all character groups and the default spacing value.

[0007] Optionally, determine the equivalent width corresponding to a single character in each character group, including: The set width corresponding to the group category of each character group is determined as the equivalent width; Alternatively, the initial width can be determined by setting the group category corresponding to each character group; the initial width can be adjusted according to the character occurrence frequency and / or the character historical width to obtain the equivalent width.

[0008] Optionally, based on preset display parameters and the total width of the characters, the initial truncation position in the text to be displayed is estimated, including: The container width, font size, maximum number of lines to be displayed, total number of characters in the text to be displayed, and width of the ellipsis interactive control placed at the end of the text display are obtained as the display parameters; The initial truncation position is calculated according to the truncation position estimation formula; wherein, the truncation position estimation formula is: ; in, N This is the initial cutoff position. W The width of the container. L To display the maximum number of rows, W ui The width of the omitted interactive control. F For the displayed font size, n The total number of characters, W eq The total width of the characters. K = W eq / n Alternatively, the value can be the average width of the characters.

[0009] Optionally, determining the target truncation position based on the initial truncation position includes: Detect whether the total length of the text to be displayed is greater than a preset length threshold; If the total length is greater than the preset length threshold, the text to be displayed is determined to be long text, and the search step size is calculated based on the set search coefficient and the initial truncation position. If the total length is not greater than the preset length threshold, then the text to be displayed is determined to be short text, and the search step size is set to the target value; The search direction is determined based on the rendering results of the initial truncation position; Starting from the initial cutoff position, the target cutoff position is determined according to the search direction and the search step size.

[0010] Optionally, the search step size is calculated based on the set search coefficients and the initial cutoff position, including: The search step size is calculated using the step size calculation formula; wherein the step size calculation formula is: ; step Let the search step size be , minStep Both β and β are set search coefficients.N This is the initial cutoff position. L This is the maximum number of rows to display.

[0011] Optionally, shifting the target truncation position forward includes: Move the target truncation position forward by one character; Alternatively, the number of characters to be moved forward can be determined based on multiple rendering results of the target truncation position, and the target truncation position can be moved forward according to the number of characters to be moved forward.

[0012] Optionally, after determining the target truncation position based on the initial truncation position, the method further includes: In the rendering container, if it is confirmed that no line break has occurred at the target truncation position, the target truncation position is moved to the right, and the text to be displayed is omitted based on the moved target truncation position; Optionally, shifting the target truncation position backward includes: Move the target truncation position one character to the right; Alternatively, the number of characters to be shifted can be determined based on multiple rendering results of the target truncation position, and the target truncation position can be shifted backward according to the number of characters to be shifted.

[0013] Secondly, this application provides a text display device, comprising: The acquisition module is used to acquire the text to be displayed. The determining module is used to determine the total width of the characters in the text to be displayed; An estimation module is used to estimate the initial truncation position in the text to be displayed within the hidden container, based on preset display parameters and the total width of the characters, and to determine the target truncation position based on the initial truncation position. The display module is used to, in the rendering container, if it is confirmed that a line break occurs at the target truncation position, move the target truncation position forward and omit the text to be displayed based on the forward-moved target truncation position.

[0014] Optionally, the determination module is used for: The characters in the text to be displayed are grouped according to preset categories to obtain multiple character groups; wherein, the preset categories are determined based on font type or character type; Determine the equivalent width of each character in each character group; where the equivalent width of each character in the same character group is the same. The total width of the character is obtained by summing the equivalent widths of individual characters in all character groups and the default spacing value.

[0015] Optionally, the determination module is used for: The set width corresponding to the group category of each character group is determined as the equivalent width; Alternatively, the initial width can be determined by setting the group category corresponding to each character group; the initial width can be adjusted according to the character occurrence frequency and / or the character historical width to obtain the equivalent width.

[0016] Optionally, the estimation module is used for: The container width, font size, maximum number of lines to be displayed, total number of characters in the text to be displayed, and width of the ellipsis interactive control placed at the end of the text display are obtained as the display parameters; The initial truncation position is calculated according to the truncation position estimation formula; wherein, the truncation position estimation formula is: ; in, N This is the initial cutoff position. W The width of the container. L To display the maximum number of rows, W ui The width of the omitted interactive control. F For the displayed font size, n The total number of characters, W eq The total width of the characters. K = W eq / n Alternatively, the value can be the average width of the characters.

[0017] Optionally, the estimation module is used for: Detect whether the total length of the text to be displayed is greater than a preset length threshold; If the total length is greater than the preset length threshold, the text to be displayed is determined to be long text, and the search step size is calculated based on the set search coefficient and the initial truncation position. If the total length is not greater than the preset length threshold, then the text to be displayed is determined to be short text, and the search step size is set to the target value; The search direction is determined based on the rendering results of the initial truncation position; Starting from the initial cutoff position, the target cutoff position is determined according to the search direction and the search step size.

[0018] Optionally, the estimation module is used for: The search step size is calculated using the step size calculation formula; wherein the step size calculation formula is: ; step Let the search step size be , minStep Both β and β are set search coefficients. N This is the initial cutoff position. L This is the maximum number of rows to display.

[0019] Optionally, the display module is used for: Move the target truncation position forward by one character; Alternatively, the number of characters to be moved forward can be determined based on multiple rendering results of the target truncation position, and the target truncation position can be moved forward according to the number of characters to be moved forward.

[0020] Optionally, the display module is also used for: In the rendering container, if it is confirmed that no line break has occurred at the target truncation position, the target truncation position is moved to the right, and the text to be displayed is omitted based on the moved target truncation position; Optionally, the display module is used for: Move the target truncation position one character to the right; Alternatively, the number of characters to be shifted can be determined based on multiple rendering results of the target truncation position, and the target truncation position can be shifted backward according to the number of characters to be shifted.

[0021] Thirdly, this application provides an electronic device, comprising: Memory, used to store computer programs; A processor is configured to execute the computer program to implement the aforementioned disclosed text display method.

[0022] Fourthly, this application provides a non-volatile storage medium for storing a computer program, wherein the computer program, when executed by a processor, implements the aforementioned disclosed text display method.

[0023] Fifthly, this application provides a computer program product, including a computer program / instructions that, when executed by a processor, implement the steps of the aforementioned disclosed text display method.

[0024] As can be seen, this application first determines the total width of the characters in the text to be displayed; then, within the hidden container, based on preset display parameters and the total character width, it estimates the initial truncation position in the text to be displayed. This initial truncation position can be preliminarily estimated based on the overall text size as the loop start point; the target truncation position is determined based on the initial truncation position, allowing for rapid pre-calculation without affecting front-end rendering; furthermore, by verifying whether a line break occurs at the target truncation position in the rendering container, the position where a line break occurs is moved forward, effectively preventing abnormal line breaks, character misalignment, or non-standard ellipsis display after text truncation. This solution can quickly and accurately determine the appropriate text truncation position, achieving both precise prediction and dynamic correction of the text truncation position, reducing the number of actual rendering iterations, lowering rendering overhead, and optimizing text display efficiency. It is suitable for text omission display in different rendering scenarios.

[0025] Correspondingly, the text display device, equipment, medium, and program product provided in this application also have the above-mentioned technical effects. Attached Figure Description

[0026] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of this application. For those skilled in the art, other drawings can be obtained based on the provided drawings without creative effort.

[0027] Figure 1 This is a flowchart of a text display method disclosed in this application; Figure 2 This is a flowchart of another text display method disclosed in this application; Figure 3 This is a schematic diagram of a text display device disclosed in this application; Figure 4 This is a schematic diagram of an electronic device disclosed in this application; Figure 5 A server architecture diagram provided for this application; Figure 6 A terminal structure diagram provided for this application. Detailed Implementation

[0028] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those of ordinary skill in the art without creative effort are within the protection scope of this application.

[0029] It should be noted that, in the description of this application, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. The terms "first," "second," etc., in this application are used to distinguish similar objects and are not used to describe a specific order or sequence.

[0030] To enable those skilled in the art to better understand the present application, the present application will be further described in detail below with reference to the accompanying drawings and specific embodiments.

[0031] See Figure 1 As shown in the figure, this application discloses a text display method, including: S101. Obtain the text to be displayed.

[0032] S102. Determine the total width of the characters in the text to be displayed.

[0033] In this embodiment, the total width of the characters in the text to be displayed can be obtained by summing the equivalent widths of each character. In one implementation, determining the total width of the characters in the text to be displayed includes: grouping the characters in the text to be displayed according to preset categories to obtain multiple character groups; wherein the preset categories are determined based on font type or character type; font types include: KaiTi, HeiTi, etc.; character types include: Chinese characters, English characters, numeric characters, punctuation marks, whitespace characters, etc.; determining the equivalent width corresponding to each character in each character group; wherein the equivalent width of each character in the same character group is the same; and obtaining the total width of the characters based on the sum of the equivalent widths of the individual characters in all character groups and the default spacing value. This method, by grouping all characters in the text according to font type and character type to calculate the total width, can accurately distinguish the display size differences of different fonts and characters, avoiding errors caused by uniform width estimation; classifying different fonts such as KaiTi and HeiTi, and different characters such as Chinese, English, numeric, punctuation, and whitespace makes the width calculation more consistent with the actual rendering effect. Using the same equivalent width for the same group of characters simplifies the calculation logic and ensures consistency and reasonableness in width assessment. Finally, by summing the equivalent widths of each group of characters, the total width and default spacing value are obtained, allowing for quick and accurate prediction of text space usage. The default spacing values ​​include: letter spacing (e.g., the distance between different letters in an English word) and word spacing (e.g., the distance between different English words).

[0034] The process of determining the equivalent width of a single character in each character group includes: determining the set width corresponding to the group category of each character group as the equivalent width, which allows for quick width assignment; or, determining the set width corresponding to the group category of each character group as the initial width; adjusting the initial width based on the character occurrence frequency and / or the character's historical width (determined based on the historical rendering effect of the same character) to obtain the equivalent width. By combining the character occurrence frequency and historical width data to adaptively adjust the equivalent width of a single character, the equivalent width can better match the actual rendering performance, solving the problem of the fixed set value not matching the actual display size. This not only meets the needs of rapid layout but also achieves fine-grained width adaptation, effectively reducing text rendering deviation.

[0035] S103. In the hidden container, based on the preset display parameters and the total character width, estimate the initial truncation position in the text to be displayed, and determine the target truncation position based on the initial truncation position.

[0036] In this embodiment, the initial truncation position is estimated based on the total character width of the entire text and the currently preset display parameters, thereby ensuring that the initial truncation position better meets the display requirements. In one implementation, estimating the initial truncation position in the text to be displayed based on preset display parameters and the total character width includes: obtaining the container width, display font size, maximum number of display lines, total number of characters in the text to be displayed, and the width of the ellipsis interactive control placed at the end of the text display, as display parameters; and calculating the initial truncation position according to the truncation position estimation formula; wherein, the truncation position estimation formula is: ;in, N This is the initial cutoff position. W For container width, L To display the maximum number of rows, W ui The width of the omitted interactive control used to omit display. F To display font size, n The total number of characters. W eq Total character width K = W eq / n Alternatively, the value can be taken as the average character width. The average character width can be obtained by averaging the actual widths of each character in each rendering result. To perform differentiated adaptation estimation for short and long texts, for short texts, the following can be used: K = W eq / n For long texts, make K equal to the average width of the characters.

[0037] It should be noted that this embodiment can perform differentiated processing for long and short text. In one implementation, determining the target truncation position based on the initial truncation position includes: detecting whether the total length of the text to be displayed is greater than a preset length threshold; if the total length is greater than the preset length threshold, the text to be displayed is determined to be long text, and a search step size is calculated based on a set search coefficient and the initial truncation position; for example, the search step size is calculated using a step size calculation formula and the search step size is reduced when a line break occurs during the search; if the total length is not greater than the preset length threshold, the text to be displayed is determined to be short text, and the search step size is set as the target value; for example, the search step size is 1 and remains unchanged during the search; the search direction is determined based on the rendering result of the initial truncation position; starting from the initial truncation position, the target truncation position is determined according to the search direction and the search step size. Thus, by comparing the total length of the text to be displayed with the preset length threshold, long and short text are distinguished, thereby achieving differentiated adaptation of truncation processing and improving the targeting of text processing. For long texts, the search step size is dynamically calculated by combining the set search coefficient and the initial truncation position, making the truncation position search more flexible and reducing the number of search rounds. For short texts, the search step size is directly set as the target value, simplifying the process and improving processing efficiency. Simultaneously, the search direction is determined based on the actual rendering result of the initial truncation position, and the target truncation position is obtained step by step according to the determined direction and step size, effectively avoiding problems such as missing text and layout errors caused by improper truncation, thus improving truncation accuracy.

[0038] In one implementation, calculating the search step size based on a set search coefficient and an initial cutoff position includes: calculating the search step size using a step size calculation formula; wherein the step size calculation formula is: ; step For the search step size, minStep Both β and β are set search coefficients. N This is the initial cutoff position. LTo display the maximum number of lines; correspondingly, for long texts, during the process of determining the target truncation position, the search step size can be reduced by one for each search until the search step size becomes 1 and remains unchanged. For example: assuming the initial search step size is 8 and the initial index position is N=7; the first search backwards warp(7) without a newline, the search position is N1=7+step=15. If a newline occurs, then step=8 / 2=4; Wrap(15) and Wrap(7) are inconsistent, so the search direction needs to be changed to a forward search. The second search position is N2=N1-step=11. Wrap(11) has a newline, then step=4 / 2=2; since Wrap(11) and Wrap(15) are inconsistent, the search direction needs to be changed to a forward search. The second search position is N2=N1-step=11. Wrap(11) has a newline, then step=4 / 2=2; since Wrap(11) and Wrap(15) are inconsistent, the search direction needs to be changed to a forward search. Since the two are consistent, the search direction remains unchanged and continues to search forward. The third search position is N3=N2–step=11-2=9. After that, step=2 / 2=1. Wrap(9) and Wrap(11) are inconsistent, so the search direction changes to search backward. The fourth search position is N4=N3+step=10. This time, step remains unchanged at 1. Wrap(10) has a newline, but Wrap(9) has not. Therefore, Wrap(9) is the critical position found, which is the target cutoff position.

[0039] In this process, after each reduction in the search step size, a test position is determined based on the reduced step size. The position is then checked for line breaks. If the line break status changes (from a line break to no line break or vice versa), the direction is reversed, and the check continues with the new step size. After each check, the step size is reduced until step=1. At step=1, the step size no longer decreases. The process then moves character by character according to the short text structure until the line break status changes, at which point the critical point corresponding to the target truncation position is determined, indicating whether a line break has occurred.

[0040] This effectively avoids issues such as truncation positions crossing lines and insufficient truncation precision caused by excessively large step sizes. By gradually reducing the search step size, fine-grained iterative optimization can be performed near line break boundaries, making the truncation position more closely match the actual display area and improving the robustness and accuracy of truncation position determination. Simultaneously, a fine-grained step size reduces invalid search attempts, avoids repeated backtracking adjustments, and improves truncation efficiency. This method ensures that long text is displayed omitting within a limited area while also improving layout stability and rendering consistency.

[0041] S104. In the rendering container, if it is confirmed that a line break occurs at the target truncation position, the target truncation position is moved forward, and the text to be displayed is omitted based on the target truncation position after the forward movement.

[0042] In this embodiment, a secondary verification and confirmation is performed in the rendering container to check whether a line break occurs at the target truncation position, thereby improving the accuracy and rationality of the actual truncation position. Specifically, if it is confirmed that no line break occurs at the target truncation position, the text to be displayed is omitted based on the target truncation position; if it is confirmed that a line break occurs at the target truncation position, the target truncation position is moved forward, and the text to be displayed is omitted based on the moved target truncation position. In one implementation, moving the target truncation position forward includes: moving the target truncation position forward by one character; or, determining the number of characters to move forward based on multiple rendering results of the target truncation position, and moving the target truncation position forward according to the number of characters moved forward, so as to finely adapt and adjust the truncation position, thereby improving the accuracy and rationality of the truncation position. The method of omitting text based on the target truncation position after moving forward includes: if it is confirmed that no line break has occurred at the target truncation position after moving forward, the forward movement continues and it is determined whether a line break has occurred. If no line break has occurred, the forward movement continues until a line break position is identified (i.e., the critical point of whether a line break occurs). This line break position is the position where the omission display begins. The specific display method can be: an ellipsis is displayed after this critical point position, followed by an omission interactive control.

[0043] Furthermore, during the secondary verification of whether a line break occurs at the target truncation position in the rendering container, if a line break is confirmed at the target truncation position, the target truncation position is moved to the right, and the text to be displayed is omitted based on the moved target truncation position. Moving the target truncation position to the right includes: moving the target truncation position one character to the right; or, determining the number of characters to move based on multiple rendering results of the target truncation position, and moving the target truncation position according to the number of characters moved. Omitting the text to be displayed based on the moved target truncation position includes: if a line break still occurs at the moved target truncation position, the movement continues and a check is performed to determine if a line break occurs. If a line break occurs, the movement continues until a position where no line break occurs is identified (i.e., the critical point between line breaks and non-line break). This position where no line break occurs is the starting point for omission display. Specifically, an ellipsis is displayed after this critical point, followed by an omission interactive control.

[0044] Therefore, in this embodiment, the target truncation position determined in the hidden container may need to be determined by moving it backward or forward to determine the critical point of whether or not a line break occurs. Specifically, if a line break occurs at the target truncation position, it is moved backward to determine the critical point of whether or not a line break occurs; otherwise, it is moved forward to determine the critical point of whether or not a line break occurs.

[0045] As can be seen, this embodiment effectively avoids abnormal line breaks, character overflows, and layout errors caused by improper truncation boundaries when a line break is detected at the target truncation position in the rendering container. This is achieved by moving the truncation position forward and omitting the text, ensuring a neat and standardized text display. Regarding the forward-moving method, it can either move one character forward for quick adjustment, simplifying calculation logic and improving processing efficiency, or dynamically determine the number of characters to move forward based on multiple rendering results for fine-grained adaptation and adjustment, improving the accuracy and rationality of the truncation position. Furthermore, multiple rendering feedback can fully incorporate the actual display effect, avoiding adaptation deviations caused by fixed offsets, enhancing adaptability to different fonts, character widths, and layout scenarios, and enabling dynamic correction of the text truncation position, thus optimizing text display efficiency.

[0046] Please see Figure 2 A text display method that enables the omission of text, including: Step S1: Obtain the text to be displayed and the display environment parameters.

[0047] Prediction module A obtains the content of the text to be displayed and the following display environment parameters: width of the hidden container, size of the displayed font, maximum number of lines to be displayed, total number of characters in the text to be displayed, and width of the ellipsis interactive control placed at the end of the text display. W ui .

[0048] Calculate the total character width of the text to be displayed: The characters in the text to be displayed are classified according to their character types, which must include at least the following categories: Chinese characters, English characters, numeric characters, punctuation marks, and whitespace characters.

[0049] For different character categories, corresponding equivalent width coefficients are set. w ci (That is, the set width corresponding to the group category of each character group), used to reflect the average display width occupied by each character in the current font and rendering environment. The equivalent width of different types of characters can be set according to the following rules, and can be flexibly adjusted according to font type, font size and rendering environment, etc.: the equivalent width coefficient corresponding to Chinese characters is the maximum value; the equivalent width coefficient corresponding to English characters and numeric characters is less than that of Chinese characters; the equivalent width coefficient corresponding to punctuation marks is further reduced; the equivalent width coefficient corresponding to whitespace characters is the smallest.

[0050] The equivalent widths of each character in the text are summed to obtain the total equivalent width of the text (i.e., the total width of the characters in the text to be displayed). This embodiment provides a character width model... W eq The calculation method is as follows: ; n The total number of characters in the text to be displayed.W eq Total character width c i This represents the i-th character, with a character spacing of . ls And word spacing is ws The number of words is wc , n The total number of characters.

[0051] In the aforementioned embodiments, characters are divided into Chinese, English, numbers, punctuation marks, and whitespace characters, and equivalent width coefficients are set for different character categories. In other alternative embodiments, the equivalent width coefficients can also be determined in the following ways: (1) setting different equivalent width coefficients for characters according to font type or font family; (2) setting equivalent width coefficients according to the frequency of occurrence of characters in the text, for example: the higher the frequency of occurrence of English characters, the smaller the equivalent width coefficient; the higher the frequency of occurrence of Chinese characters, the larger the equivalent width coefficient; (3) adaptively correcting the set equivalent width coefficients based on historical rendering results, for example: the equivalent width coefficient corresponding to a certain character is 0.5, and it can be determined through the historical rendering results of the character that the actual width of the character in the historical rendering results is too different from 0.5, then the average value of the actual width of the character in each rendering result can be calculated, and the original equivalent width coefficient 0.5 can be adjusted based on the difference between the average value and the original equivalent width coefficient 0.5.

[0052] Step S2: Determine whether the text length exceeds the preset length threshold T.

[0053] Prediction module A calculates the length of the text to be displayed to obtain len(content); it compares the text length with a preset length threshold T to distinguish different processing strategies: when len(content)≤T, it is determined to be short text and enters the precise index prediction sub-process (step S3); when len(content)>T, it is determined to be long text and enters the coarse index step convergence prediction sub-process (step S4).

[0054] The preset length threshold T is used to balance prediction accuracy and computational performance, and can be configured or dynamically adjusted according to the device's display performance. Specifically, the better the device's display performance, the larger T will be. Device display performance can be represented based on at least one of the following: operating system type, page load, frame rate, and rendering time. More specifically, the longer the rendering time, the worse the device's display performance, and the smaller T will be accordingly.

[0055] Step S3: Precise index prediction subprocess (len≤T).

[0056] Perform precise index prediction when the text length does not exceed the threshold T, specifically including: S3.1 output based on character width model W eq Predicting line breaks N 1 (i.e., the initial cutoff position). ; N 1 is the initial cutoff position. W For container width, L To display the maximum number of rows, W ui To omit the width of interactive controls, F To display font size, n The total number of characters. W eq This represents the total width of the characters. N 1 is used to indicate the position in the text that is theoretically close to a line break, and serves as the initial reference point for subsequent line break detection and index correction.

[0057] Therefore, by classifying different character types in the text and introducing corresponding equivalent width coefficients, the equivalent character width of the text is calculated. This allows for the prediction of potential line break positions of the text under given viewport width and line number constraints without relying on the actual rendering layout, thus guiding the subsequent line break detection process.

[0058] It should be noted that the initial truncation position can also be determined in the following ways: by predicting based on the rendering results of similar historical text; by estimating the line break boundary interval through multi-point sampling; or by directly giving the initial index interval using heuristic rules.

[0059] S3.2 Line break detection and direction determination.

[0060] Line break guide N 1. Send to line break detection module B so that line break detection module B can detect line break guidelines in the hidden container. N 1. Whether a line break occurs (denoted as wrap(N1)), and based on the line break guide. N The search direction (left or right) is determined by the relative relationship between the predicted line break position and the actual line break position; then, the relevant detection results are returned to the prediction module A. Thus, using the predicted line break guide as the starting point of the search, and based on the monotonicity of the line break state in the index dimension, the true line break boundary index is quickly located through directional detection and step-size convergence, avoiding the need to judge each line break position in the entire text one by one.

[0061] The line break detection module B loads the text into a hidden container and performs layout rendering within the hidden container to determine the line break guide. N1. Whether a line break has occurred. Accordingly, the line break detection module B can also obtain the character or string width through the text measurement interface of the drawing context, and determine whether a line break has occurred by combining the container width and line number limit; or, directly obtain the line number information of the text through the layout calculation interface provided by the browser or system; or, determine the line break status by caching historical layout results or reusing the layout information of rendered nodes.

[0062] The line break detection module B can not only use hidden containers, but also perform line break detection based on the actual DOM layout, text measurement models, or graphics context measurements, thereby reducing rendering overhead and improving overall performance while ensuring functional consistency. Furthermore, this embodiment decouples line break detection from the prediction model, not relying on the actual rendering results during the prediction phase, and only performing a limited number of line break checks when necessary, thus effectively reducing overall rendering and computational overhead.

[0063] S3.3 Detects each character along the direction.

[0064] Prediction module A from line break instructions N Starting from point 1, the index position is adjusted character by character (i.e., step=1) according to the determined search direction, and the line break detection module B is called multiple times to perform wrap detection until the critical position where a line break actually occurs is located, finally obtaining the predicted truncated index. (i.e., the target cutoff position).

[0065] Step S4: Coarse index step size convergence prediction (long text, len>T).

[0066] When the text length exceeds the threshold T, prediction module A adopts a step-based convergent prediction method.

[0067] S4.1 Calculating Equivalent Character Width and Initial Index: Prediction module A calculates the average character width by taking the average of the actual widths of each character in each rendering result. K .

[0068] Based on this, predict line break instructions And initialize the index to: .

[0069] As can be seen, this embodiment can estimate different initial truncation positions for short and long texts, thereby enabling differentiated processing for both short and long texts.

[0070] S4.2 Initialize step size.

[0071] Prediction module A estimates the initial step size: Among them, minStep and β are preset parameters used to control search efficiency and accuracy.

[0072] S4.3 Step-based convergence search.

[0073] Prediction module A calls line break detection module B to perform line break detection on index i and determine the search direction. If step > 1, prediction module A enters the step convergence loop: it updates index i according to the current judgment direction (i + step or i - step), then calls line break detection module B again to check if a line break has occurred after the update; regardless of whether a line break has occurred, the step size is updated to: step = step / 2 Based on this, the detection continues, decreasing the step size with each search until the step size converges to 1. Then, it detects each character as a short text, ultimately obtaining the predicted truncated index. (i.e., the target cutoff position).

[0074] Among them, step size convergence can also adopt: exponential decay step size method; index approximation method based on binary search; multi-point comparison search method based on interval reduction; and adaptive step size adjustment method based on prediction error feedback, so as to quickly approximate the actual line break position and reduce the number of rendering times of line break detection module B.

[0075] Step S5: Render in the actual container to achieve consistency remediation.

[0076] Prediction Module A Submission The remediation module C is given the opportunity to make another judgment in the actual rendering container. Does a line break occur? If so, then... = -1, and based on the truncated index Perform line break detection and complete text rendering and display; if no line break occurs, truncate the index output from the previous step. The text is enlarged (i.e., moved to the back) and line break thresholds are detected to complete text rendering and display. Therefore, when there is a discrepancy between the predicted and actual rendered results, a correction process is triggered to ensure the accuracy and stability of the final text display.

[0077] The remediation module can also adjust based on the difference in the number of rendered lines. Based on the results of multiple tests Perform a rollback or forward movement; confirm by re-triggering the prediction process. This is to ensure consistency between the predicted rendering results and the final rendering results.

[0078] This embodiment employs different calculation methods to estimate the initial truncation position for long and short texts, enabling differentiated searches for truncation positions based on text length. This makes the truncation position search more flexible, reduces search rounds, and achieves fast and accurate determination of the omitted text position. It can also adapt to text content containing a mix of Chinese, English, numbers, and symbols. In scenarios with long text or limited display resources, it ensures that omitted text and interactive controls maintain consistent display effects across different devices and rendering environments, while maintaining high processing efficiency and display accuracy.

[0079] The following describes a text display device provided in an embodiment of this application. The text display device described below can be referred to in conjunction with other embodiments described herein.

[0080] See Figure 3 As shown in the figure, this application discloses a text display device, including: Module 301 is used to acquire the text to be displayed; Determining module 302 is used to determine the total width of characters in the text to be displayed; The estimation module 303 is used to estimate the initial truncation position in the text to be displayed in the hidden container based on preset display parameters and total character width, and to determine the target truncation position based on the initial truncation position. The display module 304 is used to move the target truncation position forward if a line break is confirmed to occur at the target truncation position in the rendering container, and to omit the text to be displayed based on the target truncation position after the forward movement.

[0081] In one implementation, the determining module is used to: The characters in the text to be displayed are grouped according to preset categories to obtain multiple character groups; the preset categories are determined based on font type or character type. Determine the equivalent width of each character in each character group; where the equivalent width of each character in the same character group is the same. The total character width is obtained by summing the equivalent widths of individual characters in all character groups and the default spacing value.

[0082] In one implementation, the determining module is used to: Set the width corresponding to the group category of each character group as the equivalent width; Alternatively, the initial width can be determined by setting the group category of each character group; the initial width can be adjusted according to the frequency of character occurrence and / or the historical width of the character to obtain an equivalent width.

[0083] In one implementation, the estimation module is used to: Get the container width, display font size, maximum number of lines to display, total number of characters in the text to be displayed, and width of the omitted interactive control placed at the end of the text display as display parameters; The initial truncation position is calculated according to the truncation position estimation formula; whereby the truncation position estimation formula is: ;in, N This is the initial cutoff position. W The width of the container. L To display the maximum number of rows, W ui The width of the omitted interactive control. F For the displayed font size, n The total number of characters, W eq The total width of the characters. K = W eq / n Alternatively, the value can be the average width of the characters.

[0084] In one implementation, the estimation module is used to: Check if the total length of the text to be displayed is greater than a preset length threshold; If the total length is greater than the preset length threshold, the text to be displayed is determined to be long text, and the search step size is calculated based on the set search coefficient and the initial truncation position. If the total length is not greater than the preset length threshold, the text to be displayed is determined to be short text, and the search step size is set to the target value. The search direction is determined based on the rendering results at the initial truncation position; Starting from the initial cutoff position, determine the target cutoff position according to the search direction and search step size.

[0085] In one implementation, the estimation module is used to: The search step size is calculated using the step size calculation formula; where the step size calculation formula is: ; step For the search step size, minStep Both β and β are set search coefficients. N This is the initial cutoff position. L This is the maximum number of rows to display.

[0086] In one implementation, the display module is used for: Move the target truncation position forward by one character; Alternatively, the number of characters to move forward can be determined based on multiple rendering results of the target truncation position, and the target truncation position can be moved forward according to the number of characters to move forward.

[0087] For more detailed information on the working process of each module and unit in this embodiment, please refer to the relevant content disclosed in the foregoing embodiments, which will not be repeated here.

[0088] As can be seen, this embodiment provides a text display device that can quickly and accurately determine the appropriate text truncation position. It not only achieves accurate prediction and dynamic correction of the text truncation position, but also reduces the number of actual renderings, lowers rendering overhead, and optimizes text display efficiency. It is suitable for text omission display in different rendering scenarios.

[0089] The following describes an electronic device provided by an embodiment of this application. The electronic device described below can be referred to in conjunction with other embodiments described herein.

[0090] See Figure 4 As shown in the figure, an embodiment of this application discloses an electronic device, including: Memory 401 is used to store computer programs; Processor 402 is configured to execute the computer program to implement the method disclosed in any of the above embodiments.

[0091] Furthermore, embodiments of this application also provide an electronic device. The aforementioned electronic device can be, for example,... Figure 5 The server shown can also be as follows: Figure 6 The terminal shown. Figure 5 and Figure 6 These are all diagrams illustrating the structure of an electronic device according to an exemplary embodiment. The content in the diagrams should not be considered as any limitation on the scope of this application.

[0092] Figure 5 This is a schematic diagram of a server structure provided in an embodiment of this application. The server may specifically include: at least one processor, at least one memory, a power supply, a communication interface, an input / output interface, and a communication bus. The memory stores a computer program, which is loaded and executed by the processor to implement the relevant steps in the text display disclosed in any of the foregoing embodiments.

[0093] In this embodiment, the power supply is used to provide operating voltage for each hardware device on the server; the communication interface can create a data transmission channel between the server and external devices, and the communication protocol it follows can be any communication protocol applicable to the technical solution of this application, and is not specifically limited here; the input / output interface is used to acquire external input data or output data to the outside world, and its specific interface type can be selected according to specific application needs, and is not specifically limited here.

[0094] In addition, the memory, as a carrier for resource storage, can be a read-only memory, random access memory, disk or optical disk, etc. The resources stored on it include operating system, computer programs and data, etc., and the storage method can be temporary storage or permanent storage.

[0095] The operating system manages and controls the various hardware devices and computer programs on the server to enable the processor to perform operations and processes on the data in the memory. It can be Windows Server, Netware, Unix, Linux, etc. In addition to computer programs capable of performing the text display method disclosed in any of the foregoing embodiments, the computer programs may further include computer programs capable of performing other specific tasks. The data may include application update information and application developer information.

[0096] Figure 6 This is a schematic diagram of the structure of a terminal provided in an embodiment of this application. The terminal may include, but is not limited to, a smartphone, tablet computer, laptop computer, or desktop computer.

[0097] Typically, the terminal in this embodiment includes a processor and a memory.

[0098] The processor may include one or more processing cores, such as a quad-core processor or an octa-core processor. The processor can be implemented using at least one hardware form of DSP (Digital Signal Processing), FPGA (Field-Programmable Gate Array), or PLA (Programmable Logic Array). The processor may also include a main processor and coprocessors. The main processor, also known as the CPU (Central Processing Unit), is used to process data in the wake-up state; the coprocessor is a low-power processor used to process data in the standby state. In some embodiments, the processor may integrate a GPU (Graphics Processing Unit), which is responsible for rendering and drawing the content to be displayed on the screen. In some embodiments, the processor may also include an AI (Artificial Intelligence) processor, which handles computational operations related to machine learning.

[0099] The memory may include one or more computer non-volatile storage media, which may be non-transitory. The memory may also include high-speed random access memory and non-volatile memory, such as one or more disk storage devices or flash memory devices. In this embodiment, the memory is used to store at least the following computer program, which, after being loaded and executed by the processor, is capable of implementing the relevant steps in the text display method executed by the terminal side as disclosed in any of the foregoing embodiments. In addition, the resources stored in the memory may also include operating systems and data, and the storage method may be temporary or permanent storage. The operating system may include Windows, Unix, Linux, etc. The data may include, but is not limited to, application update information.

[0100] In some embodiments, the terminal may further include a display screen, an input / output interface, a communication interface, a sensor, a power supply, and a communication bus.

[0101] Those skilled in the art will understand that Figure 6 The structure shown does not constitute a limitation on the terminal and may include more or fewer components than illustrated.

[0102] The following describes a non-volatile storage medium provided in an embodiment of this application. The non-volatile storage medium described below can be referred to in conjunction with other embodiments described herein.

[0103] A non-volatile storage medium is provided for storing a computer program, wherein the computer program, when executed by a processor, implements the text display method disclosed in the foregoing embodiments. The non-volatile storage medium is a computer-readable non-volatile storage medium, which, as a carrier of resource storage, can be a read-only memory, random access memory, disk, or optical disk, etc. The resources stored thereon include an operating system, computer programs, and data, and the storage method can be temporary storage or permanent storage.

[0104] The following describes a computer program product provided by an embodiment of this application. The computer program product described below can be referred to in conjunction with other embodiments described herein.

[0105] A computer program product includes a computer program / instructions that, when executed by a processor, implement the steps of the aforementioned disclosed text display method.

[0106] Embodiments of this application also provide another computer program product, including a non-volatile computer-readable storage medium for storing a computer program that, when executed by a processor, implements the steps in any of the above embodiments.

[0107] The various embodiments in this specification are described in a progressive manner. Each embodiment focuses on the differences from other embodiments. The same or similar parts between the various embodiments can be referred to each other.

[0108] The steps of the methods or algorithms described in conjunction with the embodiments disclosed herein can be implemented directly by hardware, a software module executed by a processor, or a combination of both. The software module can be located in random access memory (RAM), main memory, read-only memory (ROM), electrically programmable ROM, electrically erasable programmable ROM, registers, hard disk, removable disk, CD-ROM, or any other form of non-volatile storage medium known in the art.

[0109] This document uses specific examples to illustrate the principles and implementation methods of this application. The descriptions of the above embodiments are only intended to help understand the methods and core ideas of this application. At the same time, for those skilled in the art, there will be changes in the specific implementation methods and application scope based on the ideas of this application. Therefore, the content of this specification should not be construed as a limitation of this application.

Claims

1. A text display method, characterized in that, include: Get the text to be displayed; Determine the total width of the characters in the text to be displayed; Within the hidden container, based on preset display parameters and the total width of the characters, an initial truncation position is estimated in the text to be displayed, and a target truncation position is determined based on the initial truncation position. In the rendering container, if it is confirmed that a line break occurs at the target truncation position, the target truncation position is moved forward, and the text to be displayed is omitted based on the forward target truncation position.

2. The method according to claim 1, characterized in that, Determining the total width of the characters in the text to be displayed includes: The characters in the text to be displayed are grouped according to preset categories to obtain multiple character groups; wherein, the preset categories are determined based on font type or character type; Determine the equivalent width of each character in each character group; where the equivalent width of each character in the same character group is the same. The total width of the character is obtained by summing the equivalent widths of individual characters in all character groups and the default spacing value.

3. The method according to claim 2, characterized in that, Determine the equivalent width of each character in each character group, including: The set width corresponding to the group category of each character group is determined as the equivalent width; Alternatively, the initial width can be determined by setting the group category corresponding to each character group; the initial width can be adjusted according to the character occurrence frequency and / or the character historical width to obtain the equivalent width.

4. The method according to claim 1, characterized in that, Based on preset display parameters and the total width of the characters, the initial truncation position is estimated in the text to be displayed, including: The container width, font size, maximum number of lines to be displayed, total number of characters in the text to be displayed, and width of the ellipsis interactive control placed at the end of the text display are obtained as the display parameters; The initial truncation position is calculated according to the truncation position estimation formula; wherein, the truncation position estimation formula is: ; in, N This is the initial cutoff position. W The width of the container. L The maximum number of rows to display. W ui The width of the omitted interactive control. F For the displayed font size, K = W eq / n Alternatively, the value can be the average width of the characters. n The total number of characters, W eq The total width of the characters.

5. The method according to claim 1, characterized in that, Determining the target truncation position based on the initial truncation position includes: Detect whether the total length of the text to be displayed is greater than a preset length threshold; If the total length is greater than the preset length threshold, the text to be displayed is determined to be long text, and the search step size is calculated based on the set search coefficient and the initial truncation position. If the total length is not greater than the preset length threshold, then the text to be displayed is determined to be short text, and the search step size is set to the target value; The search direction is determined based on the rendering results of the initial truncation position; Starting from the initial cutoff position, the target cutoff position is determined according to the search direction and the search step size.

6. The method according to claim 5, characterized in that, The search step size is calculated based on the set search coefficients and the initial cutoff position, including: The search step size is calculated using the step size calculation formula; wherein the step size calculation formula is: ; step Let the search step size be , minStep Both β and β are set search coefficients. N This is the initial cutoff position. L This is the maximum number of rows to display.

7. The method according to any one of claims 1 to 6, characterized in that, Moving the target truncation position forward includes: Move the target truncation position forward by one character; Alternatively, the number of characters to be moved forward can be determined based on multiple rendering results of the target truncation position, and the target truncation position can be moved forward according to the number of characters to be moved forward.

8. The method according to any one of claims 1 to 6, characterized in that, After determining the target truncation position based on the initial truncation position, the process further includes: In the rendering container, if it is confirmed that no line break has occurred at the target truncation position, the target truncation position is moved to the right, and the text to be displayed is omitted based on the moved target truncation position.

9. An electronic device, characterized in that, include: Memory, used to store computer programs; A processor for executing the computer program to implement the method as described in any one of claims 1 to 8.

10. A non-volatile storage medium, characterized in that, Used to store a computer program, wherein the computer program, when executed by a processor, implements the method as described in any one of claims 1 to 8.