Disclosure of Invention
In view of this, embodiments of the present application at least provide a text display method and apparatus, an electronic device, and a readable storage medium, which can flexibly select a truncation position according to a customized width of a truncated text, and implement automatic addition of the truncated text.
The application mainly comprises the following aspects:
in a first aspect, an embodiment of the present application provides a text display method, where the display method includes:
determining a target line of a target text in a text display area based on the display width and the display height of the text display area, wherein the target line is the last line of the target text displayed in the text display area;
determining a first position of the target text corresponding to the last character of the target line, and acquiring a second position corresponding to the last character in the target text;
if the first position is not matched with the second position, determining a truncation starting position for adding the truncated text to the target line according to a first width of the truncated text, a second width of the target text positioned on the target line and a display width of the text display area;
and replacing the target text behind the truncation initial position with the truncation text.
In one possible embodiment, the determining a target line of target text in the text display area based on the display width and the display height of the text display area includes:
acquiring preset font types, font sizes, line intervals and non-text sizes;
and determining the target line of the target text in the text display area according to the preset font type, the font size, the line spacing, the non-text size, the display width and the display height.
In a possible implementation manner, if the first position does not match the second position, determining a truncation start position for adding the truncated text to the target line according to a first width of the truncated text, a second width of the target text located in the target line, and a display width of the text display area includes:
if the first position is not matched with the second position, adding the first width and the second width to obtain a target width; the second width comprises a text width and a non-text width of the target text of the target line;
and if the target width is less than or equal to the display width, determining a position which is behind the first position and adjacent to the first position as a truncation starting position for adding the truncation text to the target line.
In a possible implementation, the display method further comprises determining the second width according to the following steps:
acquiring target content of the target text of the target line;
determining whether the target content contains non-text content or not based on a preset non-text content library;
if the target content comprises the non-text content, determining the non-text width of the non-text content, and determining the width sum of the non-text width and the text width as the second width;
and if the target content does not contain the non-text content, determining the text width as the second width.
In one possible implementation, the display method further includes:
if the target width is larger than the display width, removing at least one last character of the target text in the target line;
and when the target width after the at least one character is removed is smaller than or equal to the display width, determining a position which is adjacent to the first position after the at least one character is removed as a truncation starting position for adding the truncated text to the target line.
In a possible implementation manner, before the replacing the target text after the truncation starting position with the truncated text, the display method further includes:
judging whether a line feed character exists at the truncation starting position;
if a line break exists at the truncation starting position, the line break is removed.
In a possible implementation manner, after the determining a first position of the target text corresponding to a last character of the target line and acquiring a second position corresponding to the last character of the target text, the display method further includes:
and if the first position is matched with the second position, the truncated text is not added, and the whole content of the target text is displayed on the text display area.
In a second aspect, an embodiment of the present application further provides a display device for text, where the display device includes:
the device comprises a first determination module, a second determination module and a display module, wherein the first determination module is used for determining a target line of a target text in a text display area based on the display width and the display height of the text display area, and the target line is the last line of the target text displayed in the text display area;
the second determining module is used for determining a first position of the target text corresponding to the last character of the target line and acquiring a second position corresponding to the last character in the target text;
a third determining module, configured to determine, if the first position does not match the second position, a truncation starting position at which the truncated text is added to the target line according to a first width of the truncated text, a second width of the target text located in the target line, and a display width of the text display area;
and the replacing module is used for replacing the target text after the truncation starting position with the truncated text.
In a possible implementation manner, the first determining module is further configured to determine a target line of the target text in the text display area according to the following steps:
acquiring preset font types, font sizes, line intervals and non-text sizes;
and determining the target line of the target text in the text display area according to the preset font type, the font size, the line spacing, the non-text size, the display width and the display height.
In one possible implementation, the third determining module includes:
the generating unit is used for adding the first width and the second width to obtain a target width if the first position is not matched with the second position; the second width comprises a text width and a non-text width of the target text of the target line;
a first determining unit, configured to determine, if the target width is less than or equal to the display width, a position that is after the first position and adjacent to the first position as a truncation start position at which the truncated text is added to the target line.
In a possible implementation, the third determining module further comprises a second determining unit; the second determining unit is configured to determine the second width according to the following steps:
acquiring target content of the target text of the target line;
determining whether the target content contains non-text content or not based on a preset non-text content library;
if the target content comprises the non-text content, determining the non-text width of the non-text content, and determining the width sum of the non-text width and the text width as the second width;
and if the target content does not contain the non-text content, determining the text width as the second width.
In one possible implementation, the third determining module further includes:
the removing unit is used for removing at least one last character of the target text in the target line if the target width is larger than the display width;
a third determining unit, configured to determine, when the target width after the at least one character is removed is smaller than or equal to the display width, a position after the first position after the at least one character is removed and adjacent to the first position as a truncation start position at which the truncated text is added to the target line.
In one possible embodiment, the display device further includes:
the judging module is used for judging whether a line feed character exists at the truncation starting position;
and the rejecting module is used for rejecting the line break character if the line break character exists at the truncation starting position.
In one possible implementation, the display device further includes a display module:
and the display module is used for not adding the truncated text and displaying all contents of the target text on the text display area if the first position is matched with the second position.
In a third aspect, an embodiment of the present application further provides an electronic device, including: a processor, a memory and a bus, wherein the memory stores machine-readable instructions executable by the processor, the processor and the memory communicate with each other through the bus when the electronic device is operated, and the machine-readable instructions are executed by the processor to perform the steps of the text display method according to the first aspect or any one of the possible implementation manners of the first aspect.
In a fourth aspect, the present application further provides a computer-readable storage medium, where a computer program is stored on the computer-readable storage medium, and when the computer program is executed by a processor, the steps of the text display method according to the first aspect or any one of the possible implementation manners of the first aspect are performed.
In the embodiment of the application, the target line of the target text in the text display area can be determined through the display width and the display height of the text display area, if the first position of the last character of the target line is not matched with the second position of the last character in the target text, it is indicated that the target text cannot be completely displayed in the text display area, automatically determining a truncation start position according to the customized first width of the truncated text, the second width of the target text positioned on the target line and the display width, namely, the truncation position can be flexibly selected according to the first width of the user-defined truncation text, so that automatic addition of the truncation text can be realized without manually setting a truncation mode and searching the truncation position, and the truncated text is adopted to replace the target text after the truncation initial position for display, so that the target text can be displayed in a matching text display area.
In order to make the aforementioned objects, features and advantages of the present application more comprehensible, preferred embodiments accompanied with figures are described in detail below.
Detailed Description
To make the purpose, technical solutions and advantages of the embodiments of the present application clearer, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application, and it should be understood that the drawings in the present application are for illustrative and descriptive purposes only and are not used to limit the scope of protection of the present application. Additionally, it should be understood that the schematic drawings are not necessarily drawn to scale. The flowcharts used in this application illustrate operations implemented according to some embodiments of the present application. It should be understood that the operations of the flow diagrams may be performed out of order, and that steps without logical context may be performed in reverse order or concurrently. One skilled in the art, under the guidance of this application, may add one or more other operations to, or remove one or more operations from, the flowchart.
In addition, the described embodiments are only a part of the embodiments of the present application, and not all of the embodiments. The components of the embodiments of the present application, generally described and illustrated in the figures herein, can be arranged and designed in a wide variety of different configurations. Thus, the following detailed description of the embodiments of the present application, presented in the accompanying drawings, is not intended to limit the scope of the claimed application, but is merely representative of selected embodiments of the application. All other embodiments, which can be derived by a person skilled in the art from the embodiments of the present application without making any creative effort, shall fall within the protection scope of the present application.
To enable those skilled in the art to utilize the present disclosure, the following embodiments are presented in conjunction with a specific application scenario, "text display," which will enable those skilled in the art to apply the general principles defined herein to other embodiments and application scenarios without departing from the spirit and scope of the present disclosure.
The method, apparatus, electronic device or computer-readable storage medium described in the embodiments of the present application may be applied to any scenario where text display is required, and the embodiments of the present application do not limit specific application scenarios, and any scheme using the text display method and apparatus provided in the embodiments of the present application is within the scope of the present application.
It is worth noting that before the application is provided, a truncation mode needs to be set manually and a truncation position needs to be searched for adding the truncated text, and the adding mode is complicated and inflexible, and cannot meet the display requirement of information.
In view of the above problems, in the embodiment of the present application, a target line of a target text in a text display area may be determined by a display width and a display height of the text display area, and if a first position of a last character of the target line does not match a second position of the last character in the target text, which indicates that the target text cannot be completely displayed in the text display area, a truncation starting position may be automatically determined according to a first width of a user-defined truncated text, a second width of the target text located in the target line, and the display width, that is, a truncation position may be flexibly selected according to the first width of the user-defined truncated text, so that automatic addition of the truncated text may be implemented without manually setting a truncation mode and searching the truncation position, and the target text after the truncation starting position is replaced with the truncated text for display, the target text may be displayed in match with the text display area.
For the convenience of understanding of the present application, the technical solutions provided in the present application will be described in detail below with reference to specific embodiments.
Fig. 1 is a flowchart of a text display method according to an embodiment of the present application. As shown in fig. 1, a method for displaying a text provided in an embodiment of the present application includes the following steps:
s101: and determining a target line of a target text in the text display area based on the display width and the display height of the text display area, wherein the target line is the last line of the target text displayed in the text display area.
In the implementation of the application, with the rapid development of the internet technology, a plurality of app applications for information and news appear, and people can view information such as real-time news and social hotspots around the world through the app applications. However, the screen size of the terminal device is limited, and in order to display more pieces of information on the limited screen, the size of the text display area of each piece of information, that is, the display width and the display height of the text display area, is generally specified.
Here, each piece of information may be a target text, and after the size of the text display area for displaying the target text is obtained, that is, after the display width and the display height of the text display area are obtained, a target line on which the target text can be displayed on the text display area is determined, where the target line is a last line of the target text displayed on the text display area. Here, if the text display area can accommodate the entire contents of the target text, the target lines are determined collectively according to the size of the text display area and the amount of the contents of the target text; if the text display area can not hold the whole content of the target text, only part of the content of the target text can be displayed in the text display area, and the target line is determined according to the size of the text display area.
The display width of the text display area is generally preset, and may be set based on an interface of the app application program or based on an interaction scene in the app application program.
Further, a method for determining a target line of a target text in a text display area is explained, that is, the step S101 of determining the target line of the target text in the text display area based on the display width and the display height of the text display area includes the following steps:
acquiring preset font types, font sizes, line intervals and non-text sizes; and determining the target line of the target text in the text display area according to the preset font type, the font size, the line spacing, the non-text size, the display width and the display height.
In specific implementation, after the display width and the display height of the text display area are determined, a target line of the target text in the text display area can be determined according to a preset font type, a font size, a line spacing and a non-text size, wherein the target line is a last line of the target text displayed in the text display area. Here, the preset font type, size of font size, line space, and non-text size may be the font type, size of font size, line space, and non-text size in the target text, may also be the preset font type, size of font size, line space, and non-text size displayed in the text display area, and may also be preset according to a scene in the app application program or a corresponding interface, and the like.
S102: and determining a first position of the target text corresponding to the last character of the target line, and acquiring a second position corresponding to the last character in the target text.
In the specific implementation, after the target line of the target text in the text display area is determined, according to the text content of the target text, the last character in the target line in the target text is determined, the first position of the last character in the target text is determined, and the second position of the last character in the target text is obtained, that is, the first position of the last character in the target line in the target text and the second position of the last character in the entire text are respectively determined. Here, each character in the target text is position-coded, and thus, the position of each character can be known.
Further, the determining the first position of the target text corresponding to the last character of the target line in step S102 includes the following steps:
acquiring the content corresponding to the target line from the target text; and determining the first position of the last character in the target line according to the content corresponding to the target line.
In a specific implementation, after a target line of the target text in the text display area is determined, the content in the target line is obtained from the target text, the last character in the content in the target line is determined from the content in the target line, and further, the first position of the last character in the content in the target line is determined.
S103: and if the first position is not matched with the second position, determining a truncation starting position for adding the truncated text to the target line according to the first width of the truncated text, the second width of the target text positioned on the target line and the display width of the text display area.
In a specific implementation, if the first position of the last character in the target line in the target text does not match the second position of the last character in the entire text, i.e., the position of the target text in the last character in the target line is encoded, unlike the position encoding of the last character in the target text, indicating that the two characters are different characters, that is, the target text cannot be displayed in the text display area completely, and the target text can be displayed in the text display area only partially, and at this time, truncated text may be added at the end of the text display area to replace the target text after the truncation start position, where, based on the sum of the width of the first width of the truncated text and the width of the second width of the target text of the target line, and the size relation with the display width of the text display area to determine the truncation starting position for adding the truncated text on the target line.
It should be noted that, whether the truncated text is to be displayed is determined by finding the first position of the last character in the content of the target line and determining whether the character is the last character of the whole target text, and if the character is the last character of the whole target text, the truncated text is not displayed, otherwise, the truncated text is displayed; here, the content of the target line is the content of the last line in the text display area.
Specifically, each character in the target text has a position code, and therefore, the position of each character can be known, so that, in determining whether the last character in the text content of the target line is the last character in the full text of the target text, instead of comparing whether two characters are the same, the second position of the last character in the full text of the target text is determined by the text length of the full text of the target text, for example, the full text length is 100, the second position of the last character in the full text of the target text is the code 99 (the code is generally encoded from 0), and in step S102, the first position of the last character of the target line is determined, the first position is the code 23, whether the code 99 is equal to the code 23, if equal, it is determined that the first position of the last character in the target line in the target text is the same as the second position of the last character in the whole text, otherwise, it is different.
Here, the content of the truncated text may be set by a user, and the truncated text may be, for example, ". full text", so that the width of the truncated text may also be set by a user, and a hyperlink may be made on the truncated text, and when the ". once.full text" is clicked, the user may jump to another interface displaying the entire content of the target text.
Further, the first position of the last character of the target line in the target text and the second position of the last character of the whole text are the same, that is, the first position and the second position are the same, and for this case, that is, if the first position and the second position match, the truncated text is not added, and the whole content of the target text is displayed on the text display area.
In the specific implementation, if the first position of the last character in the target line in the target text is the same as the second position of the last character in the whole text, it is indicated that the two characters are the characters at the same position, that is, the target text can be completely displayed in the text display area, and at this time, the whole content of the target text can be directly displayed in the text display area without adding a truncated text in the text display area.
S104: and replacing the target text behind the truncation initial position with the truncation text.
In the specific implementation, after the first position of the last character of the target line in the target text is determined to be different from the second position of the last character of the whole text, it is indicated that the two characters are not the characters at the same position, that is, the target text cannot be completely displayed in the text display area, a truncated text is added at the end of the text display area, and after the truncation starting position of the truncated text added at the content corresponding to the target line is determined, the content in the target text after the truncation starting position is replaced by the truncated text, and further, part of the content and the truncated text in the target text are displayed in the text display area.
Generally, under a Core Text framework, a position of adding a truncated Text can be automatically identified, but for an IOS mobile operating system of a mobile terminal, an IOS development mostly uses an object-oriented programming language (OC), and the Core Text framework provides a Text layout and rendering interface in a C language API manner, the C language and the OC language are two different languages, so that the difficulty of a maintenance program of a programmer is high by using the Core Text framework. The Text Kit framework (Text layout tool) is friendly to IOS OC developers, and is particularly embodied in that the Text Kit framework encapsulates a Core Text framework, an object-oriented OC language API which is more friendly to developers is provided externally, and the maintenance cost is lower, so that the Text layout at an IOS end is generally laid out by using the Text Kit framework, but the Text Kit framework does not support automatic creation truncation, and the adding mode is tedious and inflexible, but needs manual adding. Therefore, under the IOS mobile operating system, the method provided by the application can be adopted, the truncated Text can be added in a user-defined mode under the Text Kit framework, and the truncated Text can be displayed at a proper position at the tail of the display content correctly.
In the embodiment of the application, the target line of the target text in the text display area can be determined through the display width and the display height of the text display area, if the first position of the last character of the target line is not matched with the second position of the last character in the target text, it indicates that the target text cannot be completely displayed in the text display area, automatically determining a truncation start position according to the customized first width of the truncated text, the second width of the target text positioned on the target line and the display width, namely, the truncation position can be flexibly selected according to the first width of the user-defined truncation text, so that automatic addition of the truncation text can be realized without manually setting a truncation mode and searching the truncation position, and the truncated text is adopted to replace the target text after the truncation initial position for display, so that the target text can be displayed in a matching text display area.
Fig. 2 is a flowchart of another text display method according to an embodiment of the present disclosure. As shown in fig. 2, a method for displaying a text provided in an embodiment of the present application includes the following steps:
s201: and determining a target line of a target text in the text display area based on the display width and the display height of the text display area, wherein the target line is the last line of the target text displayed in the text display area.
S202: and determining a first position of the target text corresponding to the last character of the target line, and acquiring a second position corresponding to the last character in the target text.
S203: if the first position is not matched with the second position, adding the first width and the second width to obtain a target width; the second width includes a text width and a non-text width of the target text of the target line.
In a specific implementation, if the first position of the last character of the target line in the target text is not matched with the second position of the last character of the entire text, which indicates that the target text cannot be completely displayed in the text display area, and the target text can only be partially displayed in the text display area, a truncated text may be added at the end of the text display area, specifically, the addition position of the truncated text, that is, the truncation starting position, needs to be determined first, and the first width of the truncated text and the second width of the target text located in the target line are added first to obtain the target width, where the content of the target text includes, but is not limited to, text content and non-text content, where the non-text content may be an emoticon, and when the second width of the target text located in the target line is specifically calculated, the text widths of the text content corresponding to the target line are respectively obtained, and the non-text width in the non-text content corresponding to the target line, so that the second width of the target text in the target line is equal to the sum of the text width and the non-text width.
Further, the step of determining the second width of the target text on the target line is explained, specifically, the second width of the target text on the target line is determined according to the following steps:
acquiring target content of the target text of the target line; determining whether the target content contains non-text content or not based on a preset non-text content library; if the target content comprises the non-text content, determining the non-text width of the non-text content, and determining the width sum of the non-text width and the text width as the second width; and if the target content does not contain the non-text content, determining the text width as the second width.
In the specific implementation, the target content of the target text in the target row is obtained first, and then the non-text content and the text content are identified from the target content, where a non-text content library may be preset in advance, a large number of non-texts are stored in the non-text content library, when the non-text content is identified from the target content, the non-text in the non-text content library may be directly matched with each symbol in the target content, if the target content contains the non-text in the non-text content library, the non-text width of the non-text content is determined, the text width of the text content in the target content is determined according to the font type, the size of the word number and the number of the word, and the sum of the text width and the width of the non-text width is determined as the second width of the target text in the target row; and if the target content has no non-text content, directly determining the text width as the second width.
S204: and if the target width is less than or equal to the display width, determining a position which is behind the first position and adjacent to the first position as a truncation starting position for adding the truncation text to the target line.
In a specific implementation, if the first width of the truncated text and the second width of the target text in the target line are added to obtain a target width smaller than or equal to the display width, it indicates that the display width does not exceed the display width of the text display area after the addition of the truncated text after the target content corresponding to the target line, that is, the target content corresponding to the target line to which the truncated text is added can still be normally displayed in the text display area, and at this time, a position adjacent to the first position after the first position is directly determined as a truncation start position at which the truncated text is added to the target line.
It should be noted that, for a case that the target text cannot be completely displayed in the text display area and the target width is less than or equal to the display width, it is indicated that the target content corresponding to the target line may be the content of the last line of a certain section in the target text, so that there is a case where the first width of the truncated text and the second width of the target text corresponding to the target line are added to obtain the target width less than or equal to the display width.
Further, of course, in addition to the case where the first width and the second width of the truncated text are added to make the target width smaller than or equal to the display width, where the second width is the width of the target text located on the target line, there is also a case where the first width and the second width of the truncated text are added to make the target width larger than the display width, and for this case, the following description is made:
if the target width is larger than the display width, removing at least one last character of the target text in the target line; and when the target width after the at least one character is removed is smaller than or equal to the display width, determining a position which is adjacent to the first position after the at least one character is removed as a truncation starting position for adding the truncated text to the target line.
In a specific implementation, if the first width and the second width of the truncated text are added to obtain a target width greater than the display width, it is indicated that the target width exceeds the display width of the text display area after the truncated text is added to the target line, that is, after the truncated text is added, the target text and the truncated text corresponding to the target line cannot be normally displayed in the text display area together, at this time, a last character of the target text in the target line may be removed, and if the target width after the character is removed is less than or equal to the display width, a position after the first position after the character is removed and adjacent to the first position is determined as a truncation starting position for adding the truncated text to the target line; and if the target width after the character is removed is still larger than the display width, continuously removing the last character corresponding to the target line at present until the target width after the character is removed is smaller than or equal to the display width, and determining the truncation starting position of the text to be added.
S205: and replacing the target text behind the truncation initial position with the truncation text.
Further, in the case where a line break is present at the truncation start position, if the truncated text is directly added at the truncation start position, the truncated text is present in a line below the target line due to the presence of the line break, and the text display area displays the target line at the maximum, so that the truncated text cannot be displayed in the text display area. Before replacing the target text after the truncation starting position with the truncated text in step S205, the method further includes the following steps:
judging whether a line feed character exists at the truncation starting position; if a line break exists at the truncation starting position, the line break is removed.
In the specific implementation, after the truncation initial position of adding the truncated text to the target line is determined, whether a line break exists at the truncation initial position is judged, if the line break exists at the truncation initial position, the line break is removed, the target text after the truncation initial position is replaced by the truncated text, and partial text content and the truncated text in the target text are displayed in a text display area; and if the line feed character does not exist at the truncation starting position, directly replacing the target text after the truncation starting position with the truncation text, and displaying part of text content and the truncation text in the target text in the text display area.
The descriptions of steps S201, S202, and S205 may refer to the descriptions of steps S101, S102, and S104, and the same technical effect can be achieved, and therefore, no further explanation is provided.
3a, 3b show schematic diagrams of displaying target text in a text display area; fig. 3a shows a schematic diagram of a target text after adding a truncated text ". text", displayed in a text display area, and an interface of an information app application includes a text display area and a picture display area; fig. 3b is a schematic diagram illustrating the display of the target text in the full-text display area, where a hyperlink is added to the ". multidot.text" in fig. 3a, and after the user clicks the ". multidot.text", the user can jump to the interface displaying the full-text of the target text, that is, the full-text display area in fig. 3b can display the entire content of the target text.
In an example, with reference to fig. 3a and 3b, an implementation process of a text display method provided in the present application is illustrated, and includes the following steps:
step a: determining a target behavior 3 of a target text in a text display area;
step b: the target text corresponding to the target line is' good scene,
numerous and numerous;
step c: the last character of the target text corresponding to the target line is "No", and it is determined that "No" corresponds to the last character of the entire target text "! "do not match, so, need to show the truncation text" in the text display area.
Step d: calculating the sum of a first width of a truncated text ". multidot.text" and a second width of a target text positioned on a target line, namely a target width, and judging whether the target width exceeds the display width of a text display area; wherein the second width comprises a text width and a non-text width of the target text of the target line, wherein the non-text is identified as
Step e: judging whether a line break character exists at the end of the target text corresponding to the target line, wherein the line break character does not exist, and the line break condition does not need to be considered;
step f: if the target width exceeds the display width of the text display area, a suitable position needs to be found and a truncated text is added, the position of the last character of the target text of the target line is found forward, and the process is circulated until the target width after the truncated text is added is found not to exceed the display width, and the position is determined as the truncation starting position of the added truncated text;
' in the good wind and light,
full text ";
' in the good wind and light,
full text ";
...
' in the good wind and light,
full text ";
step g: until a truncation starting position for correctly displaying the truncation text is found, the content in the target text after the truncation starting position is replaced by the truncation text in the position, namely, the content corresponding to the target line is in 'good scene',
full text ".
In the embodiment of the application, the target line of the target text in the text display area can be determined through the display width and the display height of the text display area, if the first position of the last character of the target line is not matched with the second position of the last character in the target text, it indicates that the target text cannot be completely displayed in the text display area, automatically determining a truncation start position according to the customized first width of the truncated text, the second width of the target text positioned on the target line and the display width, namely, the truncation position can be flexibly selected according to the first width of the user-defined truncation text, so that automatic addition of the truncation text can be realized without manually setting a truncation mode and searching the truncation position, and the truncated text is adopted to replace the target text after the truncation initial position for display, so that the target text can be displayed in a matching text display area.
Based on the same application concept, a text display device corresponding to the text display method provided by the embodiment is also provided in the embodiment of the present application, and as the principle of solving the problem of the device in the embodiment of the present application is similar to the text display method provided by the embodiment of the present application, the implementation of the device can refer to the implementation of the method, and repeated details are not repeated.
As shown in fig. 4 to 6, fig. 4 is a functional block diagram of a text display device 400 according to an embodiment of the present application; FIG. 5 illustrates a functional block diagram of the third determination module 430 of FIG. 4; fig. 6 shows a second functional block diagram of a text display apparatus 400 according to an embodiment of the present application.
As shown in fig. 4, the text display apparatus 400 includes:
a first determining module 410, configured to determine, based on a display width and a display height of a text display area, a target line of a target text in the text display area, where the target line is a last line of the target text displayed in the text display area;
a second determining module 420, configured to determine a first position of the target text corresponding to a last character of the target line, and obtain a second position corresponding to the last character in the target text;
a third determining module 430, configured to determine, if the first position does not match the second position, a truncation starting position at which the truncated text is added to the target line according to a first width of the truncated text, a second width of the target text located in the target line, and a display width of the text display area;
a replacing module 440, configured to replace the target text after the truncation starting position with the truncated text.
In a possible implementation, as shown in fig. 4, the first determining module 410 is further configured to determine a target line of the target text in the text display area according to the following steps:
acquiring preset font types, font sizes, line intervals and non-text sizes;
and determining the target line of the target text in the text display area according to the preset font type, the font size, the line spacing, the non-text size, the display width and the display height.
In one possible implementation, as shown in fig. 5, the third determining module 430 includes:
a generating unit 431, configured to add the first width and the second width to obtain a target width if the first position does not match the second position; the second width comprises a text width and a non-text width of the target text of the target line;
a first determining unit 432, configured to determine, if the target width is less than or equal to the display width, a position that is adjacent to the first position after the first position as a truncation starting position for adding the truncated text to the target line.
In a possible implementation, as shown in fig. 5, the third determining module 430 further includes a second determining unit 433; the second determining unit 433 is configured to determine the second width according to the following steps:
acquiring target content of the target text of the target line;
determining whether the target content contains non-text content or not based on a preset non-text content library;
if the target content comprises the non-text content, determining the non-text width of the non-text content, and determining the width sum of the non-text width and the text width as the second width;
and if the target content does not contain the non-text content, determining the text width as the second width.
In a possible implementation, as shown in fig. 5, the third determining module 430 further includes:
a removing unit 434, configured to remove at least one last character of the target text in the target line if the target width is greater than the display width;
a third determining unit 435, configured to, when the target width after the at least one character is removed is smaller than or equal to the display width, determine a position after the first position after the at least one character is removed and adjacent to the first position as a truncation starting position where the truncated text is added to the target line.
In a possible implementation, as shown in fig. 6, the text display apparatus 400 further includes:
a judging module 450, configured to judge whether a line break exists at the truncation starting position;
a culling module 460, configured to cull a line break if the line break exists at the truncation starting position.
In one possible implementation, as shown in fig. 6, the text display apparatus 400 further includes a display module 470:
the display module 470 is configured to, if the first position matches the second position, not add the truncated text, and display the entire content of the target text on the text display area.
In the embodiment of the application, the target line of the target text in the text display area can be determined through the display width and the display height of the text display area, if the first position of the last character of the target line is not matched with the second position of the last character in the target text, it indicates that the target text cannot be completely displayed in the text display area, automatically determining a truncation start position according to the customized first width of the truncated text, the second width of the target text positioned on the target line and the display width, namely, the truncation position can be flexibly selected according to the first width of the user-defined truncation text, so that automatic addition of the truncation text can be realized without manually setting a truncation mode and searching the truncation position, and the truncated text is adopted to replace the target text after the truncation initial position for display, so that the target text can be displayed in a matching text display area.
Based on the same application concept, referring to fig. 7, a schematic structural diagram of an electronic device 700 provided in the embodiment of the present application includes: a processor 710, a memory 720 and a bus 730, wherein the memory 720 stores machine-readable instructions executable by the processor 710, when the electronic device 700 is operated, the processor 710 communicates with the memory 720 through the bus 730, and the machine-readable instructions are executed by the processor 710 to perform the steps of the text display method according to any of the above embodiments.
In particular, the machine readable instructions, when executed by the processor 710, may perform the following:
determining a target line of a target text in a text display area based on the display width and the display height of the text display area, wherein the target line is the last line of the target text displayed in the text display area;
determining a first position of the target text corresponding to the last character of the target line, and acquiring a second position corresponding to the last character in the target text;
if the first position is not matched with the second position, determining a truncation starting position for adding the truncated text to the target line according to a first width of the truncated text, a second width of the target text positioned on the target line and a display width of the text display area;
and replacing the target text behind the truncation initial position with the truncation text.
In the embodiment of the application, the target line of the target text in the text display area can be determined through the display width and the display height of the text display area, if the first position of the last character of the target line is not matched with the second position of the last character in the target text, it is indicated that the target text cannot be completely displayed in the text display area, automatically determining a truncation start position according to the customized first width of the truncated text, the second width of the target text positioned on the target line and the display width, namely, the truncation position can be flexibly selected according to the first width of the user-defined truncation text, so that automatic addition of the truncation text can be realized without manually setting a truncation mode and searching the truncation position, and the truncated text is adopted to replace the target text after the truncation initial position for display, so that the target text can be displayed in a matching text display area.
Based on the same application concept, the embodiment of the present application further provides a computer-readable storage medium, where a computer program is stored on the computer-readable storage medium, and when the computer program is executed by a processor, the steps of the text display method provided by the above embodiment are performed.
Specifically, the storage medium can be a general storage medium, such as a removable disk, a hard disk, or the like, and when a computer program on the storage medium is executed, the method for displaying the text can be executed, and the truncated position can be flexibly selected according to the width of the user-defined truncated text, so as to implement automatic addition of the truncated text.
It is clear to those skilled in the art that, for convenience and brevity of description, the specific working processes of the system and the apparatus described above may refer to the corresponding processes in the foregoing method embodiments, and are not described herein again. In the several embodiments provided in the present application, it should be understood that the disclosed system, apparatus and method may be implemented in other ways. The above-described embodiments of the apparatus are merely illustrative, and for example, the division of the units is only one logical division, and there may be other divisions when actually implemented, and for example, a plurality of units or components may be combined or integrated into another system, or some features may be omitted, or not executed. In addition, the shown or discussed mutual coupling or direct coupling or communication connection may be an indirect coupling or communication connection of devices or units through some communication interfaces, and may be in an electrical, mechanical or other form.
The units described as separate parts may or may not be physically separate, and parts displayed as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of the embodiment.
In addition, functional units in the embodiments of the present application may be integrated into one processing unit, or each unit may exist alone physically, or two or more units are integrated into one unit.
The functions, if implemented in the form of software functional units and sold or used as a stand-alone product, may be stored in a non-volatile computer-readable storage medium executable by a processor. Based on such understanding, the technical solutions of the present application may be embodied in the form of a software product, which is stored in a storage medium and includes several instructions for causing a computer device (which may be a personal computer, a server, or a network device) to execute all or part of the steps of the methods described in the embodiments of the present application. And the aforementioned storage medium includes: various media capable of storing program codes, such as a usb disk, a removable hard disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a magnetic disk, or an optical disk.
The above description is only for the specific embodiments of the present application, but the scope of the present application is not limited thereto, and any person skilled in the art can easily conceive of the changes or substitutions within the technical scope of the present application, and shall be covered by the scope of the present application. Therefore, the protection scope of the present application shall be subject to the protection scope of the claims.