





技术领域technical field
本公开涉及数据处理技术领域,具体而言,涉及一种文本显示方法、设备及存储介质。The present disclosure relates to the technical field of data processing, and in particular, to a text display method, device and storage medium.
背景技术Background technique
随着科技的不断发展和进步,在互联网技术逐渐兴起和成熟的过程中互联网成为了人们生活、工作和学习中不可获取的一部分,人们可以通过互联网进行知识、信息的获取。人们通过互联网进行信息获取,大多是使用终端,通过网页浏览等方式获取信息,在一些网页的界面中会显示出一些简要的标题信息供人们浏览。With the continuous development and progress of science and technology, in the process of the gradual rise and maturity of Internet technology, the Internet has become an inaccessible part of people's life, work and study. People can obtain knowledge and information through the Internet. People acquire information through the Internet, and most of them use terminals to acquire information through web browsing and other means, and some brief title information will be displayed on the interface of some web pages for people to browse.
在进行网页信息浏览时,为了可以在网页上展示更多的信息,大多是对各个信息进行简化,例如通过在网页上展示部分信息或者展示简要标题的方式进行信息展示,因此在一些需要展示的文本内容无法显示完全或文本过长无法显示后半段的情况下,需要对这部分文本进行裁剪。目前对文本进行裁剪,大多是从尾部开始一个字符一个字符的移除,尤其是当文本内容过长时,就需要对文本进行多次的处理,处理时间长,需要消耗大量的处理时间和处理资源,而且在处理的同时会产生较多的处理元素,导致在程序运行的时候会占用很大的内存,容易造成机身卡顿和网页崩溃,从而大大降低处理效率以及加载速度。When browsing webpage information, in order to display more information on the webpage, most of the information is simplified. For example, the information is displayed by displaying part of the information on the webpage or displaying a brief title. When the text content cannot be displayed completely or the text is too long to display the second half, this part of the text needs to be cropped. At present, when cutting text, most of them are removed one character by one from the end. Especially when the text content is too long, the text needs to be processed multiple times, which takes a long time and consumes a lot of processing time and processing time. resources, and more processing elements will be generated during processing, which will cause a lot of memory to be occupied when the program is running, which may easily cause the fuselage to freeze and web pages to crash, thus greatly reducing processing efficiency and loading speed.
发明内容SUMMARY OF THE INVENTION
本公开实施例至少提供一种文本显示方法、装置、设备及存储介质。Embodiments of the present disclosure provide at least a text display method, apparatus, device, and storage medium.
本公开实施例提供了一种文本显示方法,所述方法包括:An embodiment of the present disclosure provides a text display method, the method includes:
获取目标文本、用于显示所述目标文本的文本容器,以及所述文本容器在目标页面中显示文本的容器参数;obtaining target text, a text container for displaying the target text, and a container parameter for the text container to display text in the target page;
基于所述容器参数,确定是否需要对所述目标文本进行裁剪;Based on the container parameter, determining whether the target text needs to be cropped;
若需要对所述目标文本进行裁剪,确定针对所述目标文本的裁剪参数;If the target text needs to be clipped, determine the clipping parameters for the target text;
基于所述裁剪参数以及所述目标文本中字符的排列序号,对所述目标文本进行至少一次裁剪,得到待显示文本;Based on the cropping parameters and the sequence numbers of the characters in the target text, the target text is cropped at least once to obtain the text to be displayed;
将得到的所述待显示文本添加至所述文本容器中,以在所述目标页面中显示所述待显示文本。The obtained text to be displayed is added to the text container to display the text to be displayed in the target page.
一种可选的实施方式中,所述基于所述容器参数,确定是否需要对所述目标文本进行裁剪,包括:In an optional implementation manner, the determining whether the target text needs to be cropped based on the container parameter includes:
初始化所述文本容器;initialize the text container;
基于所述容器参数中预设显示行数和预设单行高度,确定所述文本容器的预设显示高度;determining the preset display height of the text container based on the preset number of displayed lines and the preset single-line height in the container parameters;
将预设字符添加至初始化之后的所述文本容器中的预设位置;adding preset characters to preset positions in the text container after initialization;
将所述目标文本添加至加入所述预设字符的所述文本容器中,得到通过所述文本容器显示所述目标文本的目标显示高度;adding the target text to the text container added with the preset characters to obtain a target display height for displaying the target text through the text container;
若所述目标显示高度大于所述预设显示高度,确定需要对所述目标文本进行裁剪。If the target display height is greater than the preset display height, it is determined that the target text needs to be cropped.
一种可选的实施方式中,所述若需要对所述目标文本进行裁剪,确定针对所述目标文本的裁剪参数,包括:In an optional implementation manner, if the target text needs to be cropped, the cropping parameters for the target text are determined, including:
若需要对所述目标文本进行裁剪,基于所述目标文本中的字符总量和所述容器参数,确定针对所述目标文本的裁剪参数;或者If the target text needs to be cropped, based on the total amount of characters in the target text and the container parameters, determine the cropping parameters for the target text; or
若需要对所述目标文本进行裁剪,获取预设的针对所述目标文本的裁剪参数。If the target text needs to be cropped, the preset cropping parameters for the target text are acquired.
一种可选的实施方式中,所述基于所述裁剪参数以及所述目标文本中字符的排列序号,对所述目标文本进行至少一次裁剪,得到待显示文本,包括:In an optional embodiment, based on the cropping parameters and the sequence number of the characters in the target text, the target text is cropped at least once to obtain the text to be displayed, including:
基于所述目标文本中第一个字符的排列序号和最后一个字符的排列序号,以及所述裁剪参数,确定针对所述目标文本的第一裁剪位置;Based on the sequence number of the first character in the target text and the sequence number of the last character, and the cropping parameters, determine the first cropping position for the target text;
按照所述第一裁剪位置对所述目标文本进行裁剪,得到所述目标文本中第一个字符所在的第一文本段,其中,所述第一文本段包括所述目标文本中的第一个字符以及所述第一裁剪位置处对应的第二字符;The target text is cropped according to the first cropping position to obtain a first text segment where the first character in the target text is located, wherein the first text segment includes the first text segment in the target text character and the second character corresponding to the first cropping position;
基于所述容器参数确定是否需要对所述第一文本段进行裁剪;determining whether the first text segment needs to be cropped based on the container parameter;
若需要,将所述第一文本段作为所述目标文本继续进行裁剪,直至多次裁剪后,将最后裁剪得到的第二文本段添加至所述文本容器中的实时显示高度小于或者等于基于所述容器参数确定的所述文本容器的预设显示高度时停止,将所述第二文本段作为所述待显示文本;If necessary, continue to cut the first text segment as the target text, until after multiple cuts, the real-time display height of adding the last cut second text segment to the text container is less than or equal to the height of the real-time display based on the Stop when the preset display height of the text container is determined by the container parameter, and use the second text segment as the text to be displayed;
若不需要,将第一次裁剪得到的所述第一文本段作为所述待显示文本。If not required, the first text segment obtained by the first cropping is used as the text to be displayed.
一种可选的实施方式中,所述基于所述目标文本中第一个字符的排列序号和最后一个字符的排列序号,以及所述裁剪参数,确定针对所述目标文本的第一裁剪位置,包括:In an optional embodiment, the first trimming position for the target text is determined based on the sequence number of the first character in the target text and the sequence sequence number of the last character, and the trimming parameter, include:
确定所述目标文本中第一个字符的排列序号和最后一个字符的排列序号的数值和;Determine the numerical sum of the sequence number of the first character and the sequence number of the last character in the target text;
计算所述数值和与所述裁剪参数之间的计算结果;calculating a calculation result between the numerical value and the cropping parameter;
对所述计算结果进行取整处理,得到与所述计算结果最接近的目标序号;Rounding is performed on the calculation result to obtain the target sequence number closest to the calculation result;
将所述目标序号确定为第一裁剪位置。The target serial number is determined as the first cutting position.
一种可选的实施方式中,所述方法包括:In an optional embodiment, the method includes:
在将作为待显示文本的所述第一文本段或所述第二文本段添加至所述文本容器中,所述文本容器的实时显示高度小于基于所述容器参数确定出的、所述文本容器的预设显示高度的情况下,将所述第一文本段或所述第二文本段作为待拼接文本段,确定所述目标文本中与所述待拼接文本段相邻的第三文本段,其中,所述第三文本段包括目标字符和所述目标文本中的最后一个字符,所述目标字符为所述目标文本中在所述待拼接文本段的最后一个字符之后的第一个字符;When adding the first text segment or the second text segment as the text to be displayed into the text container, the real-time display height of the text container is smaller than the text container determined based on the container parameter. In the case of the preset display height of The third text segment includes a target character and the last character in the target text, and the target character is the first character in the target text after the last character of the text segment to be spliced;
基于所述第三文本段中字符的排列序号和所述裁剪参数,对所述第三文本段进行至少一次裁剪,得到第四文本段,其中,将所述第四文本段与所述待拼接文本段拼接后的文本段添加至所述文本容器中的实时显示高度等于所述预设显示高度;Based on the sequence numbers of the characters in the third text segment and the trimming parameters, the third text segment is trimmed at least once to obtain a fourth text segment, wherein the fourth text segment is combined with the to-be-spliced text segment. The real-time display height of the text segment spliced into the text container added to the text container is equal to the preset display height;
将所述待拼接文本段和所述第四文本段拼接后的文本段作为所述待显示文本。The text segment obtained by splicing the to-be-spliced text segment and the fourth text segment is used as the to-be-displayed text.
一种可选的实施方式中,所述基于所述第三文本段中字符的排列序号和所述裁剪参数,对所述第三文本段进行至少一次裁剪,得到第四文本段,包括:In an optional implementation manner, the third text segment is trimmed at least once based on the sequence number of the characters in the third text segment and the trimming parameter to obtain a fourth text segment, including:
基于所述第三文本段中第一个字符的排列序号和最后一个字符的排列序号,以及所述裁剪参数,确定针对所述第三文本段的第二裁剪位置;Based on the sequence number of the first character and the sequence number of the last character in the third text segment, and the cropping parameter, determining a second cropping position for the third text segment;
按照所述第二裁剪位置对所述第三文本段进行裁剪,得到第五文本段和第六文本段,其中,所述第五文本段为包括所述第三文本段中的第一个字符的文本段,所述第六文本段为与所述第五文本段相邻并且包括所述第三文本段中最后一个字符的文本段;The third text segment is trimmed according to the second trimming position to obtain a fifth text segment and a sixth text segment, wherein the fifth text segment includes the first character in the third text segment A text segment, the sixth text segment is a text segment adjacent to the fifth text segment and including the last character in the third text segment;
在将所述第五文本段和所述待拼接文本段进行拼接后的文本段添加至所述文本容器中,所述文本容器的实时显示高度仍小于所述预设显示高度的情况下,将所述第六文本段作为所述第三文本段再次进行裁剪,直至将所述待拼接文本段和裁剪得到的至少两个所述第五文本段拼接后的文本段添加至所述文本容器中,所述文本容器的实时显示高度等于所述预设显示高度时停止裁剪;In the case where the text segment obtained by splicing the fifth text segment and the to-be-spliced text segment is added to the text container, and the real-time display height of the text container is still smaller than the preset display height, add The sixth text segment is cut again as the third text segment, until the text segment to be spliced and the cut text segment obtained by splicing at least two of the fifth text segments are added to the text container , and stop cropping when the real-time display height of the text container is equal to the preset display height;
将裁剪得到的至少两个所述第五文本段拼接后的文本段作为所述第四文本段。A text segment obtained by splicing at least two of the fifth text segments obtained by cutting is used as the fourth text segment.
一种可选的实施方式中,在所述按照所述第二裁剪位置对所述第三文本段进行裁剪,得到第五文本段和第六文本段之后,所述方法包括:In an optional implementation manner, after the third text segment is trimmed according to the second trimming position to obtain a fifth text segment and a sixth text segment, the method includes:
在将所述第五文本段和所述待拼接文本段拼接后添加至所述文本容器中,所述文本容器的实时显示高度大于所述预设显示高度的情况下,将所述第五文本段作为所述目标文本进行裁剪,直至多次裁剪后,将最后裁剪得到的第七文本段和所述待拼接文本段拼接后添加至所述文本容器中的实时显示高度等于所述预设高度时停止;After the fifth text segment and the to-be-spliced text segment are spliced and added to the text container, and the real-time display height of the text container is greater than the preset display height, the fifth text segment is added to the text container. The segment is cropped as the target text, until after multiple cropping, the real-time display height added to the text container after splicing the seventh text segment obtained by the final cropping and the text segment to be spliced is equal to the preset height stop when
将所述第七文本段作为所述第四文本段。The seventh text segment is used as the fourth text segment.
一种可选的实施方式中,在对所述目标文本进行裁剪的过程中,所述方法包括:In an optional implementation manner, in the process of cropping the target text, the method includes:
针对每次裁剪得到的文本段,若所述文本段中第一个字符的排列序号和最后一个字符的排列序号相同,停止裁剪。For the text segment obtained by cutting each time, if the sequence number of the first character in the text segment is the same as the sequence number of the last character, the cropping is stopped.
一种可选的实施方式中,在所述基于所述裁剪参数以及所述目标文本中字符的排列序号,对所述目标文本进行至少一次裁剪,得到待显示文本之后,所述方法包括:In an optional implementation manner, after the target text is trimmed at least once based on the cropping parameters and the sequence numbers of characters in the target text to obtain the text to be displayed, the method includes:
检测所述待显示文本中的最后一个字符是否属于预先统计好的、不需要显示的特殊字符;Detecting whether the last character in the to-be-displayed text belongs to a pre-statistical special character that does not need to be displayed;
若是,将所述待显示文本中的最后一个字符裁剪掉,得到处理后的所述待显示文本。If so, the last character in the to-be-displayed text is cut out to obtain the processed to-be-displayed text.
本公开实例还提供一种文本显示装置,所述装置包括:An example of the present disclosure also provides a text display device, the device comprising:
获取模块,用于获取目标文本、用于显示所述目标文本的文本容器,以及所述文本容器在目标页面中显示文本的容器参数;an acquisition module for acquiring target text, a text container for displaying the target text, and a container parameter for the text container to display text in the target page;
第一确定模块,用于基于所述容器参数,确定是否需要对所述目标文本进行裁剪;a first determining module, configured to determine whether the target text needs to be cropped based on the container parameter;
第二确定模块,用于若需要对所述目标文本进行裁剪,确定针对所述目标文本的裁剪参数;a second determining module, configured to determine the cropping parameters for the target text if the target text needs to be cropped;
文本裁剪模块,用于基于所述裁剪参数以及所述目标文本中字符的排列序号,对所述目标文本进行至少一次裁剪,得到待显示文本;a text trimming module, configured to trim the target text at least once based on the trimming parameters and the sequence numbers of characters in the target text to obtain the text to be displayed;
文本显示模块,用于将得到的所述待显示文本添加至所述文本容器中,以在所述目标页面中显示所述待显示文本。A text display module, configured to add the obtained text to be displayed into the text container, so as to display the text to be displayed in the target page.
一种可选的实施方式中,所述第一确定模块具体用于:In an optional implementation manner, the first determining module is specifically configured to:
初始化所述文本容器;initialize the text container;
基于所述容器参数中预设显示行数和预设单行高度,确定所述文本容器的预设显示高度;determining the preset display height of the text container based on the preset number of displayed lines and the preset single-line height in the container parameters;
将预设字符添加至初始化之后的所述文本容器中的预设位置;adding preset characters to preset positions in the text container after initialization;
将所述目标文本添加至加入所述预设字符的所述文本容器中,得到通过所述文本容器显示所述目标文本的目标显示高度;adding the target text to the text container added with the preset characters to obtain a target display height for displaying the target text through the text container;
若所述目标显示高度大于所述预设显示高度,确定需要对所述目标文本进行裁剪。If the target display height is greater than the preset display height, it is determined that the target text needs to be cropped.
一种可选的实施方式中,所述第二确定模块具体用于:In an optional implementation manner, the second determining module is specifically configured to:
若需要对所述目标文本进行裁剪,基于所述目标文本中的字符总量和所述容器参数,确定针对所述目标文本的裁剪参数;或者If the target text needs to be cropped, based on the total amount of characters in the target text and the container parameters, determine the cropping parameters for the target text; or
若需要对所述目标文本进行裁剪,获取预设的针对所述目标文本的裁剪参数。If the target text needs to be cropped, the preset cropping parameters for the target text are acquired.
一种可选的实施方式中,所述文本裁剪模块具体用于:In an optional implementation manner, the text cropping module is specifically used for:
基于所述目标文本中第一个字符的排列序号和最后一个字符的排列序号,以及所述裁剪参数,确定针对所述目标文本的第一裁剪位置;Based on the sequence number of the first character in the target text and the sequence number of the last character, and the cropping parameters, determine the first cropping position for the target text;
按照所述第一裁剪位置对所述目标文本进行裁剪,得到所述目标文本中第一个字符所在的第一文本段,其中,所述第一文本段包括所述目标文本中的第一个字符以及所述第一裁剪位置处对应的第二字符;The target text is cropped according to the first cropping position to obtain a first text segment where the first character in the target text is located, wherein the first text segment includes the first text segment in the target text character and the second character corresponding to the first cropping position;
基于所述容器参数确定是否需要对所述第一文本段进行裁剪;determining whether the first text segment needs to be cropped based on the container parameter;
若需要,将所述第一文本段作为所述目标文本继续进行裁剪,直至多次裁剪后,将最后裁剪得到的第二文本段添加至所述文本容器中的实时显示高度小于或者等于基于所述容器参数确定的所述文本容器的预设显示高度时停止,将所述第二文本段作为所述待显示文本;If necessary, continue to cut the first text segment as the target text, until after multiple cuts, the real-time display height of adding the last cut second text segment to the text container is less than or equal to the height of the real-time display based on the Stop when the preset display height of the text container is determined by the container parameter, and use the second text segment as the text to be displayed;
若不需要,将第一次裁剪得到的所述第一文本段作为所述待显示文本。If not required, the first text segment obtained by the first cropping is used as the text to be displayed.
一种可选的实施方式中,所述文本裁剪模块在用于基于所述目标文本中第一个字符的排列序号和最后一个字符的排列序号,以及所述裁剪参数,确定针对所述目标文本的第一裁剪位置时,具体用于:In an optional embodiment, the text cropping module is used to determine the target text based on the sequence number of the first character and the sequence number of the last character in the target text, and the cropping parameters. The first cropping position of , specifically for:
确定所述目标文本中第一个字符的排列序号和最后一个字符的排列序号的数值和;Determine the numerical sum of the sequence number of the first character and the sequence number of the last character in the target text;
计算所述数值和与所述裁剪参数之间的计算结果;calculating a calculation result between the numerical value and the cropping parameter;
对所述计算结果进行取整处理,得到与所述计算结果最接近的目标序号;Rounding is performed on the calculation result to obtain the target sequence number closest to the calculation result;
将所述目标序号确定为第一裁剪位置。The target serial number is determined as the first cutting position.
一种可选的实施方式中,所述文本裁剪模块还用于:In an optional implementation manner, the text cropping module is also used for:
在将作为待显示文本的所述第一文本段或所述第二文本段添加至所述文本容器中,所述文本容器的实时显示高度小于基于所述容器参数确定出的、所述文本容器的预设显示高度的情况下,将所述第一文本段或所述第二文本段作为待拼接文本段,确定所述目标文本中与所述待拼接文本段相邻的第三文本段,其中,所述第三文本段包括目标字符和所述目标文本中的最后一个字符,所述目标字符为所述目标文本中在所述待拼接文本段的最后一个字符之后的第一个字符;When adding the first text segment or the second text segment as the text to be displayed into the text container, the real-time display height of the text container is smaller than the text container determined based on the container parameter. In the case of the preset display height of The third text segment includes a target character and the last character in the target text, and the target character is the first character in the target text after the last character of the text segment to be spliced;
基于所述第三文本段中字符的排列序号和所述裁剪参数,对所述第三文本段进行至少一次裁剪,得到第四文本段,其中,将所述第四文本段与所述待拼接文本段拼接后的文本段添加至所述文本容器中的实时显示高度等于所述预设显示高度;Based on the sequence numbers of the characters in the third text segment and the trimming parameters, the third text segment is trimmed at least once to obtain a fourth text segment, wherein the fourth text segment is combined with the to-be-spliced text segment. The real-time display height of the text segment spliced into the text container added to the text container is equal to the preset display height;
将所述待拼接文本段和所述第四文本段拼接后的文本段作为所述待显示文本。The text segment obtained by splicing the to-be-spliced text segment and the fourth text segment is used as the to-be-displayed text.
一种可选的实施方式中,所述文本裁剪模块在用于所述基于所述第三文本段中字符的排列序号和所述裁剪参数,对所述第三文本段进行至少一次裁剪,得到第四文本段时,具体用于:In an optional implementation manner, the text cropping module is used to crop the third text segment at least once based on the sequence number of the characters in the third text segment and the cropping parameter, to obtain: When the fourth text paragraph is used, it is specifically used for:
基于所述第三文本段中第一个字符的排列序号和最后一个字符的排列序号,以及所述裁剪参数,确定针对所述第三文本段的第二裁剪位置;Based on the sequence number of the first character and the sequence number of the last character in the third text segment, and the cropping parameter, determining a second cropping position for the third text segment;
按照所述第二裁剪位置对所述第三文本段进行裁剪,得到第五文本段和第六文本段,其中,所述第五文本段为包括所述第三文本段中的第一个字符的文本段,所述第六文本段为与所述第五文本段相邻并且包括所述第三文本段中最后一个字符的文本段;The third text segment is trimmed according to the second trimming position to obtain a fifth text segment and a sixth text segment, wherein the fifth text segment includes the first character in the third text segment A text segment, the sixth text segment is a text segment adjacent to the fifth text segment and including the last character in the third text segment;
在将所述第五文本段和所述待拼接文本段进行拼接后的文本段添加至所述文本容器中,所述文本容器的实时显示高度仍小于所述预设显示高度的情况下,将所述第六文本段作为所述第三文本段再次进行裁剪,直至将所述待拼接文本段和裁剪得到的至少两个所述第五文本段拼接后的文本段添加至所述文本容器中,所述文本容器的实时显示高度等于所述预设显示高度时停止裁剪;In the case where the text segment obtained by splicing the fifth text segment and the to-be-spliced text segment is added to the text container, and the real-time display height of the text container is still smaller than the preset display height, add The sixth text segment is cut again as the third text segment, until the text segment to be spliced and the cut text segment obtained by splicing at least two of the fifth text segments are added to the text container , and stop cropping when the real-time display height of the text container is equal to the preset display height;
将裁剪得到的至少两个所述第五文本段拼接后的文本段作为所述第四文本段。A text segment obtained by splicing at least two of the fifth text segments obtained by cutting is used as the fourth text segment.
一种可选的实施方式中,所述文本裁剪模块还用于:In an optional implementation manner, the text cropping module is also used for:
在将所述第五文本段和所述待拼接文本段拼接后添加至所述文本容器中,所述文本容器的实时显示高度大于所述预设显示高度的情况下,将所述第五文本段作为所述目标文本进行裁剪,直至多次裁剪后,将最后裁剪得到的第七文本段和所述待拼接文本段拼接后添加至所述文本容器中的实时显示高度等于所述预设高度时停止;After the fifth text segment and the to-be-spliced text segment are spliced and added to the text container, and the real-time display height of the text container is greater than the preset display height, the fifth text segment is added to the text container. The segment is cropped as the target text, until after multiple cropping, the real-time display height added to the text container after splicing the seventh text segment obtained by the final cropping and the text segment to be spliced is equal to the preset height stop when
将所述第七文本段作为所述第四文本段。The seventh text segment is used as the fourth text segment.
一种可选的实施方式中,所述文本裁剪模块在对所述目标文本进行裁剪的过程中,具体用于:In an optional implementation manner, in the process of cutting the target text, the text cropping module is specifically used for:
针对每次裁剪得到的文本段,若所述文本段中第一个字符的排列序号和最后一个字符的排列序号相同,停止裁剪。For the text segment obtained by cutting each time, if the sequence number of the first character in the text segment is the same as the sequence number of the last character, the cropping is stopped.
一种可选的实施方式中,所述装置还包括字符检测模块,所述字符检测模块用于:In an optional implementation manner, the device further includes a character detection module, which is used for:
检测所述待显示文本中的最后一个字符是否属于预先统计好的、不需要显示的特殊字符;Detecting whether the last character in the to-be-displayed text belongs to a pre-statistical special character that does not need to be displayed;
若是,将所述待显示文本中的最后一个字符裁剪掉,得到处理后的所述待显示文本。If so, the last character in the to-be-displayed text is cut out to obtain the processed to-be-displayed text.
本公开实施例还提供一种电子设备,包括:处理器、存储器和总线,所述存储器存储有所述处理器可执行的机器可读指令,当电子设备运行时,所述处理器与所述存储器之间通过总线通信,所述机器可读指令被所述处理器执行时执行上述的文本显示方法的步骤。Embodiments of the present disclosure further provide an electronic device, including: a processor, a memory, and a bus, where the memory stores machine-readable instructions executable by the processor, and when the electronic device runs, the processor and the The memories communicate with each other through a bus, and the machine-readable instructions execute the steps of the above-mentioned text display method when executed by the processor.
本公开实施例还提供一种计算机可读存储介质,该计算机可读存储介质上存储有计算机程序,该计算机程序被处理器运行时执行上述的文本显示方法方法的步骤。Embodiments of the present disclosure further provide a computer-readable storage medium, where a computer program is stored on the computer-readable storage medium, and when the computer program is run by a processor, the steps of the above-mentioned text display method are executed.
本公开实施例提供的文本显示方法、装置、设备及存储介质,通过获取目标文本、用于显示所述目标文本的文本容器,以及所述文本容器在目标页面中显示文本的容器参数;基于所述容器参数,确定是否需要对所述目标文本进行裁剪;若需要对所述目标文本进行裁剪,确定针对所述目标文本的裁剪参数;基于所述裁剪参数以及所述目标文本中字符的排列序号,对所述目标文本进行至少一次裁剪,得到待显示文本;将得到的所述待显示文本添加至所述文本容器中,以在所述目标中显示所述待显示文本。The text display method, device, device, and storage medium provided by the embodiments of the present disclosure, by acquiring target text, a text container for displaying the target text, and the container parameters of the text container for displaying text in a target page; The container parameter is used to determine whether the target text needs to be cropped; if the target text needs to be cropped, the cropping parameters for the target text are determined; based on the cropping parameters and the sequence number of the characters in the target text , cutting the target text at least once to obtain the text to be displayed; adding the obtained text to be displayed into the text container to display the text to be displayed in the target.
这样,通过文本容器显示文本时的容器参数,以及针对目标文本的裁剪参数和目标文本中字符的排列序号,可以从目标文本中的相应位置对目标文本进行至少一次裁剪,从而可以大大减少文本裁剪的次数,降低文本处理时间,以提高文本处理的效率和速度,同时还会减少裁剪掉的元素的数量,以减少了机身内存的无效占用,以保证终端运行的流畅度。In this way, the target text can be clipped at least once from the corresponding position in the target text through the container parameters when the text container displays the text, the clipping parameters for the target text and the sequence number of the characters in the target text, thereby greatly reducing text clipping. It reduces the text processing time to improve the efficiency and speed of text processing, and also reduces the number of clipped elements to reduce the ineffective occupation of the fuselage memory to ensure the smoothness of the terminal operation.
为使本公开的上述目的、特征和优点能更明显易懂,下文特举较佳实施例,并配合所附附图,作详细说明如下。In order to make the above-mentioned objects, features and advantages of the present disclosure more obvious and easy to understand, the preferred embodiments are exemplified below, and are described in detail as follows in conjunction with the accompanying drawings.
附图说明Description of drawings
为了更清楚地说明本公开实施例的技术方案,下面将对实施例中所需要使用的附图作简单地介绍,此处的附图被并入说明书中并构成本说明书中的一部分,这些附图示出了符合本公开的实施例,并与说明书一起用于说明本公开的技术方案。应当理解,以下附图仅示出了本公开的某些实施例,因此不应被看作是对范围的限定,对于本领域普通技术人员来讲,在不付出创造性劳动的前提下,还可以根据这些附图获得其他相关的附图。In order to explain the technical solutions of the embodiments of the present disclosure more clearly, the following briefly introduces the accompanying drawings required in the embodiments, which are incorporated into the specification and constitute a part of the specification. The drawings illustrate embodiments consistent with the present disclosure, and together with the description serve to explain the technical solutions of the present disclosure. It should be understood that the following drawings only show some embodiments of the present disclosure, and therefore should not be regarded as limiting the scope. Other related figures are obtained from these figures.
图1示出了本公开实施例所提供的一种文本显示方法的流程图;FIG. 1 shows a flowchart of a text display method provided by an embodiment of the present disclosure;
图2示出了本公开实施例所提供的另一种文本显示方法的流程图;FIG. 2 shows a flowchart of another text display method provided by an embodiment of the present disclosure;
图3为本公开实施例提供的一种文本显示方法的裁剪逻辑示意图;FIG. 3 is a schematic diagram of cropping logic of a text display method provided by an embodiment of the present disclosure;
图4示出了本公开实施例所提供的一种文本显示装置的示意图之一;FIG. 4 shows one of the schematic diagrams of a text display device provided by an embodiment of the present disclosure;
图5示出了本公开实施例所提供的一种文本显示装置的示意图之二;FIG. 5 shows the second schematic diagram of a text display device provided by an embodiment of the present disclosure;
图6示出了本公开实施例所提供的一种电子设备的示意图。FIG. 6 shows a schematic diagram of an electronic device provided by an embodiment of the present disclosure.
具体实施方式Detailed ways
为使本公开实施例的目的、技术方案和优点更加清楚,下面将结合本公开实施例中附图,对本公开实施例中的技术方案进行清楚、完整地描述,显然,所描述的实施例仅仅是本公开一部分实施例,而不是全部的实施例。通常在此处附图中描述和示出的本公开实施例的组件可以以各种不同的配置来布置和设计。因此,以下对在附图中提供的本公开的实施例的详细描述并非旨在限制要求保护的本公开的范围,而是仅仅表示本公开的选定实施例。基于本公开的实施例,本领域技术人员在没有做出创造性劳动的前提下所获得的所有其他实施例,都属于本公开保护的范围。In order to make the purposes, technical solutions and advantages of the embodiments of the present disclosure more clear, the technical solutions in the embodiments of the present disclosure will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present disclosure. Obviously, the described embodiments are only These are some, but not all, embodiments of the present disclosure. The components of the disclosed embodiments generally described and illustrated in the drawings herein may be arranged and designed in a variety of different configurations. Therefore, the following detailed description of the embodiments of the disclosure provided in the accompanying drawings is not intended to limit the scope of the disclosure as claimed, but is merely representative of selected embodiments of the disclosure. Based on the embodiments of the present disclosure, all other embodiments obtained by those skilled in the art without creative work fall within the protection scope of the present disclosure.
应注意到:相似的标号和字母在下面的附图中表示类似项,因此,一旦某一项在一个附图中被定义,则在随后的附图中不需要对其进行进一步定义和解释。It should be noted that like numerals and letters refer to like items in the following figures, so once an item is defined in one figure, it does not require further definition and explanation in subsequent figures.
本文中术语“和/或”,仅仅是描述一种关联关系,表示可以存在三种关系,例如,A和/或B,可以表示:单独存在A,同时存在A和B,单独存在B这三种情况。另外,本文中术语“至少一种”表示多种中的任意一种或多种中的至少两种的任意组合,例如,包括A、B、C中的至少一种,可以表示包括从A、B和C构成的集合中选择的任意一个或多个元素。The term "and/or" in this paper only describes an association relationship, which means that there can be three kinds of relationships, for example, A and/or B, which can mean: the existence of A alone, the existence of A and B at the same time, the existence of B alone. a situation. In addition, the term "at least one" herein refers to any combination of any one of the plurality or at least two of the plurality, for example, including at least one of A, B, and C, and may mean including from A, B, and C. Any one or more elements selected from the set of B and C.
经研究发现,目前对文本进行裁剪,大多是从尾部开始一个字符一个字符的移除,尤其是当文本内容过长时,就需要对文本进行多次的反复处理,处理时间长,需要消耗大量的处理时间和处理资源,而且在处理的同时会产生较多的处理元素,导致在程序运行的时候会占用很大的内存,容易造成机身卡顿和网页崩溃,从而大大降低处理效率以及加载速度。After research, it is found that most of the current cropping of text is to remove one character by one character from the end. Especially when the text content is too long, the text needs to be repeatedly processed many times, which takes a long time and consumes a lot of money. It takes up a lot of memory when the program is running, which can easily cause the fuselage to freeze and the web page to crash, thus greatly reducing the processing efficiency and loading. speed.
基于上述研究,本公开提供了一种文本显示方法,通过获取目标文本、用于显示所述目标文本的文本容器,以及所述文本容器在目标页面中显示文本的容器参数;基于所述容器参数,确定是否需要对所述目标文本进行裁剪;若需要对所述目标文本进行裁剪,确定针对所述目标文本的裁剪参数;基于所述裁剪参数以及所述目标文本中字符的排列序号,对所述目标文本进行至少一次裁剪,得到待显示文本;将得到的所述待显示文本添加至所述文本容器中,以在所述目标中显示所述待显示文本。Based on the above research, the present disclosure provides a text display method, by acquiring target text, a text container for displaying the target text, and container parameters for the text container to display text in a target page; based on the container parameters , determine whether the target text needs to be cropped; if the target text needs to be cropped, determine the cropping parameters for the target text; based on the cropping parameters and the sequence number of the characters in the target text, The target text is cropped at least once to obtain the to-be-displayed text; the obtained to-be-displayed text is added to the text container to display the to-be-displayed text in the target.
这样,通过文本容器显示文本时的容器参数,以及针对目标文本的裁剪参数和目标文本中字符的排列序号,可以从目标文本中的相应位置对目标文本进行至少一次裁剪,从而可以大大减少文本裁剪的次数,降低文本处理时间,以提高文本处理的效率和速度,同时还会减少裁剪掉的元素的数量,以减少了机身内存的无效占用,以保证终端运行的流畅度。In this way, the target text can be cropped at least once from the corresponding position in the target text through the container parameters when the text container displays the text, the cropping parameters for the target text and the sequence number of the characters in the target text, thereby greatly reducing text cropping It reduces the text processing time to improve the efficiency and speed of text processing, and also reduces the number of clipped elements to reduce the ineffective occupation of the fuselage memory to ensure the smoothness of the terminal operation.
为便于对本实施例进行理解,首先对本公开实施例所公开的一种文本显示方法进行详细介绍,本公开实施例所提供的文本显示方法的执行主体一般为具有一定计算能力的计算机设备,该计算机设备例如包括:终端设备或服务器或其它处理设备,终端设备可以为用户设备(User Equipment,UE)、移动设备、用户终端、终端、蜂窝电话、无绳电话、个人数字助理(Personal Digital Assistant,PDA)、手持设备、计算设备、可穿戴设备等。在一些可能的实现方式中,该文本显示方法可以通过处理器调用存储器中存储的计算机可读指令的方式来实现。In order to facilitate the understanding of this embodiment, a text display method disclosed in the embodiment of the present disclosure is first introduced in detail. The equipment includes, for example: terminal equipment or server or other processing equipment, and the terminal equipment may be user equipment (User Equipment, UE), mobile equipment, user terminal, terminal, cellular phone, cordless phone, personal digital assistant (Personal Digital Assistant, PDA) , handheld devices, computing devices, wearable devices, etc. In some possible implementations, the text display method may be implemented by the processor invoking computer-readable instructions stored in the memory.
请参阅图1,图1为本公开实施例提供的一种文本显示方法的流程图。如图1中所示,本公开实施例提供的文本显示方法,包括:Please refer to FIG. 1 , which is a flowchart of a text display method according to an embodiment of the present disclosure. As shown in FIG. 1 , the text display method provided by the embodiment of the present disclosure includes:
S101:获取目标文本、用于显示所述目标文本的文本容器,以及所述文本容器在目标页面中显示文本的容器参数。S101: Acquire target text, a text container for displaying the target text, and a container parameter for the text container to display text in a target page.
该步骤中,用户在需要使用终端去浏览网页中的信息的时候,可以使用终端打开相应的网页,在网页中可以显示各条信息的简要标题,此时,对于需要展示简要标题的一条信息,可以获取到这条信息的目标文本,和通过网页显示所述目标文本所需要使用的文本容器,同时,可以获取到预先设置好的使用所述文本容器在目标页面中显示文本时的容器参数。In this step, when the user needs to use the terminal to browse the information in the webpage, he can use the terminal to open the corresponding webpage, and the brief title of each piece of information can be displayed on the webpage. The target text of this piece of information and the text container required to display the target text through the web page can be obtained, and at the same time, the preset container parameters when using the text container to display text in the target page can be obtained.
其中,预先设置好的容器参数,可以包括所述文本容器在显示所述目标文本时的预设显示行数(总的显示行数)、预设显示字数(总字数)以及预设单行高度,还可以包括所述文本容器在显示所述目标文本时的预设单行字数(每行所能显示的最大字数)、预设显示高度(进行文本显示时的整体高度)等。Wherein, the preset container parameters may include the preset number of displayed lines (total number of displayed lines), the number of preset displayed words (total number of words) and the preset single-line height when the text container displays the target text, The text container may also include a preset number of words in a single line (the maximum number of words that can be displayed in each line), a preset display height (the overall height when displaying the text), and the like when the text container displays the target text.
其中,预先设置好的容器参数,可以是根据用户的浏览需要、页面显示需要等因素,用户去设置的,也可以是网页默认的或者网页实时动态调整的。The preset container parameters may be set by the user according to the user's browsing needs, page display needs, and other factors, or may be the default of the web page or dynamically adjusted in real time on the web page.
S102:基于所述容器参数,确定是否需要对所述目标文本进行裁剪。S102: Based on the container parameter, determine whether the target text needs to be cropped.
该步骤中,在获取到所述容器参数和所述目标文本之后,可以通过所述容器参数和所述目标文本之间的比较、匹配等方式,来检测通过所述文本容器显示所述目标文本时是否超出所述文本容器的显示规格,即是否满足所述文本容器的所述容器参数规定,从而来确定是否需要对所述目标文本进行裁剪。In this step, after the container parameters and the target text are acquired, it is possible to detect that the target text is displayed through the text container by means of comparison and matching between the container parameters and the target text. Whether the display specification of the text container is exceeded, that is, whether the container parameter specification of the text container is satisfied, so as to determine whether the target text needs to be cropped.
其中,所述文本容器的显示规格,可以是在所述容器参数下的显示规格,例如在预设显示行数之内,或者在预设显示字数之内等。The display specification of the text container may be the display specification under the container parameter, for example, within the preset number of displayed lines, or within the preset number of displayed words.
其中,在需要通过所述文本容器在所述目标页面上显示所述目标文本的缩略文本或者简要标题的时候,通常在缩略文本或者简要标题会附带上“略”或者“…”等特殊文字或者字符,以表示仅展示了部分文本,这些特殊文字或者字符,可以作为所述文本容器中添加好的固定显示内容,其可以不占用所述文本容器针对文本的容量,例如,所述文本容器的最大显示字数是100个字符,那么因为特殊文字或者字符的存在,所述文本容器相对文本的最大显示字数则是99。Wherein, when the abbreviated text or abbreviated title of the target text needs to be displayed on the target page through the text container, the abbreviated text or abbreviated title will usually be accompanied by a special "abbreviation" or "..." words or characters, to indicate that only part of the text is displayed. These special words or characters can be used as fixed display content added to the text container, which may not occupy the capacity of the text container for text, for example, the text The maximum number of displayed characters of the container is 100 characters, then because of the existence of special characters or characters, the maximum displayed number of characters relative to the text of the text container is 99.
在确定是否需要对所述目标文本进行裁剪的时候,具体的,可以先初始化所述文本容器,以确保所述文本容器的可实用性,减少可能对后续文本内容裁剪产生影响的因素,进而,可以基于所述容器参数中预设显示行数和预设单行高度,确定所述文本容器的预设显示高度,即借助所述预设显示高度,以预设显示高度作为参考,可以确定在所述目标页面中允许所述目标文本显示的范围或者文本量,然后可以将预设字符添加至初始化之后的所述文本容器中的预设位置,以预先占据一个位置,从而直接在实验阶段即可帮助进一步确定所述目标页面中允许所述目标文本显示的范围或者文本量,所述预设字符可以代表所述目标文本中不能显示出的部分文本,然后可以将所述目标文本添加至加入所述预设字符的所述文本容器中,以通过所述文本容器去尝试显示所述目标文本,从而可以得到通过所述文本容器显示所述目标文本的目标显示高度,即在实际网页显示所述目标文本时的实际高度,进一步的,可以基于所述容器参数中预设显示行数和预设单行高度,确定所述文本容器的预设显示高度,即通过所述预设显示行数和所述预设单行高度,可以得知所述文本容器在所述目标页面中进行文本显示时所被允许的显示规格,即预设显示高度,从而可以通过所述目标显示高度和所述预设显示高度之间的比较,可以去判断实际在显示所述目标文本时是否会超出规格,最后,若所述目标显示高度大于所述预设显示高度,就可以确定需要对所述目标文本进行裁剪。When determining whether to trim the target text, specifically, the text container may be initialized first to ensure the practicability of the text container and reduce factors that may affect subsequent text content trimming, and further, The preset display height of the text container can be determined based on the preset number of display lines and the preset single-line height in the container parameters, that is, with the preset display height and the preset display height as a reference, The range or amount of text allowed to display the target text in the target page, and then preset characters can be added to the preset position in the text container after initialization to pre-occupy a position, so that it can be directly in the experimental stage. To help further determine the range or amount of text allowed to display the target text in the target page, the preset characters can represent the part of the text that cannot be displayed in the target text, and then the target text can be added to the In the text container of the preset characters, try to display the target text through the text container, so that the target display height of displaying the target text through the text container can be obtained, that is, displaying the target text on the actual web page The actual height of the target text, further, the preset display height of the text container can be determined based on the preset display line number and the preset single line height in the container parameters, that is, the preset display line number and the preset display height can be determined. The preset single-line height, you can know the display specification allowed by the text container when the text is displayed in the target page, that is, the preset display height, so that the target display height and the preset display height can be used. By comparing the heights, it can be judged whether the target text will actually exceed the specification when displayed. Finally, if the target display height is greater than the preset display height, it can be determined that the target text needs to be cropped.
相反的,若所述目标显示高度小于或者等于所述预设显示高度,则不需要对此文本进行裁剪。On the contrary, if the target display height is less than or equal to the preset display height, the text need not be cropped.
除上述通过高度去比较之外,还可以通过字数等因素去确定是否需要对所述目标文本进行裁剪,例如可以获取所述目标文本中字符的总数量以及所述容器参数指示的所述文本容器的预设显示字数,如果所述目标文本中字符的总数量大于所述预设显示字数,也可以确定出需要对所述目标文本进行裁剪,此外,还可以通过行数来确定是否需要对所述目标文本进行裁剪,即将目标文本放入文本容器之后需具体显示的行数是否超出最大显示行数。In addition to the above comparison by height, factors such as the number of words can also be used to determine whether the target text needs to be cropped. For example, the total number of characters in the target text and the text container indicated by the container parameter can be obtained. If the total number of characters in the target text is greater than the preset number of displayed characters, it can also be determined that the target text needs to be cropped. In addition, it can also be determined by the number of lines whether it is necessary to The specified target text is cropped, that is, whether the number of lines to be displayed after the target text is placed in the text container exceeds the maximum number of displayed lines.
示例性的,以需要显示的目标文本为“一二三四五六七八九十百千万亿”,用于显示文本的文本容器的预设显示行数为2行、每行预设显示字数为3个字符,预设单行文字高度为20像素为例,由于预设单行文字高度为20像素,预设显示行数为2行,所以通过文本容器在目标页面上显示文本时允许显示的预设显示高度为40像素,而将目标文本添加到文本容器中的情况下,因为文本容器的每行预设显示字数为3个字符,再加上文本容器中绑定的、需要显示的特殊文字“略”,所以实际需要显示出5行的内容,目标显示高度达到了100像素的高度,目标显示高度远远大于预设显示字数,所以需要对此目标文本进行裁剪。Exemplarily, with the target text to be displayed as "one, two, three, four, five, six, seven, eight, nine, ten, trillion, billion", the preset number of displayed lines of the text container used to display the text is 2 lines, and each line is preset to be displayed. The number of characters is 3 characters, and the default single-line text height is 20 pixels. For example, since the default single-line text height is 20 pixels, and the default display line number is 2 lines, it is allowed to display text on the target page through the text container. The default display height is 40 pixels, and the target text is added to the text container, because the default display number of characters per line of the text container is 3 characters, plus the special characters bound in the text container that need to be displayed The text is "omitted", so it actually needs to display 5 lines of content, the target display height reaches 100 pixels, and the target display height is much larger than the preset number of displayed characters, so the target text needs to be cropped.
S103:若需要对所述目标文本进行裁剪,确定针对所述目标文本的裁剪参数。S103: If the target text needs to be cropped, determine cropping parameters for the target text.
其中,所述裁剪参数,可以是指在需要对所述目标文本进行裁剪时,确定出的针对所述目标文本的裁剪位置、裁剪量等相关的参数。The cropping parameter may refer to parameters related to the cropping position and cropping amount of the target text determined when the target text needs to be cropped.
所述裁剪参数,可以是固定的参数,例如与所述文本容器绑定、与所述目标页面绑定的固定参数,也可以是根据所述目标页面、所述文本容器的实际显示情况和所述目标文本的实际文本情况动态调整出的动态参数。The cropping parameter can be a fixed parameter, such as a fixed parameter bound to the text container and the target page, or can be based on the target page, the actual display situation of the text container and all the parameters. The dynamic parameters that are dynamically adjusted to describe the actual text situation of the target text.
具体的,针对于确定所述裁剪参数,可以是在需要对所述目标文本进行裁剪的时候,即若需要对所述目标文本进行裁剪,可以直接获取到预设的针对所述目标文本的裁剪参数,即预先设定好的固定的参数;也可以是在确定出需要对所述目标文本进行裁剪的时候,即若需要对所述目标文本进行裁剪,先确定目标文本中的字符总量,并获取所述容器参数,基于所述目标文本中的字符总量和所述容器参数,即通过所述容器参数中所包括例如预设显示字数等参数,与所述字符总量之间的比较,来动态的确定出针对所述目标文本的裁剪参数。Specifically, for determining the cropping parameter, when the target text needs to be cropped, that is, if the target text needs to be cropped, the preset cropping for the target text can be directly obtained parameter, that is, a preset fixed parameter; it can also be when it is determined that the target text needs to be cropped, that is, if the target text needs to be cropped, first determine the total number of characters in the target text, and obtain the container parameters, based on the total amount of characters in the target text and the container parameters, that is, the comparison between the parameters included in the container parameters, such as the preset number of displayed characters, and the total amount of characters , to dynamically determine the cropping parameters for the target text.
示例性的,例如目标文本中字符总量较大,而在目标页面中允许显示的文本量较少,或者远远小于字符总量,那么可以认为需要裁剪的次数较多,相应的就可以适当增大裁剪参数,相反的,可以适当减小裁剪参数。这里,裁剪参数可以是指从目标文本的文本末端向文本前端方向示意的位置、字数等的参数,例如,裁剪参数是三分之一,可以是从目标文本的文本末端向前大约三分之一的、表示位置和字数等的参数。Exemplarily, for example, the total amount of characters in the target text is large, but the amount of text allowed to be displayed in the target page is small, or is far less than the total amount of characters, then it can be considered that the number of times to be cropped is more, and the corresponding can be appropriate. Increase the cropping parameter, on the contrary, you can appropriately decrease the cropping parameter. Here, the cropping parameter may refer to parameters such as the position and the number of words indicated from the text end of the target text to the front end of the text. For example, if the cropping parameter is one-third, it may be about one-third forward from the text end of the target text. One, indicating the parameters such as position and number of characters.
S104:基于所述裁剪参数以及所述目标文本中字符的排列序号,对所述目标文本进行至少一次裁剪,得到待显示文本。S104: Based on the cropping parameters and the sequence numbers of the characters in the target text, crop the target text at least once to obtain the text to be displayed.
该步骤中,在确定出所述裁剪参数之后,可以使用所述裁剪参数,结合所述目标文本中各字符的排列情况,如各字符的排列序号,以确定出要对所述目标文本进行裁剪时,在文本中单次裁剪的裁剪位置、单次裁剪的字符量等因素,然后即可对所述目标文本进行裁剪,裁剪出可以显示的待显示文本。In this step, after the cropping parameters are determined, the cropping parameters can be used to determine the target text to be cropped in combination with the arrangement of each character in the target text, such as the sequence number of each character When the target text is cropped, the target text can be cropped according to factors such as the cropping position of a single cropping, the amount of characters for a single cropping, and the text to be displayed that can be cropped.
其中,所述目标文本中的字符,可以是指占据一个字符位的文字、数字、符号、英文单词、英文字母等。The characters in the target text may refer to characters, numbers, symbols, English words, English letters, etc. occupying one character position.
其中,每个字符的排列序号,可以是预先根据所述目标文本中的字符量和字符排列情况,按照顺序依次为每个字符设置的标号。The sequence number of each character may be a label set for each character in sequence in advance according to the amount of characters and the arrangement of characters in the target text.
具体的,在对所述目标文本进行裁剪时,可以通过以下过程:Specifically, when the target text is cropped, the following process can be used:
基于所述目标文本中第一个字符的排列序号和最后一个字符的排列序号,以及所述裁剪参数,确定针对所述目标文本的第一裁剪位置。Based on the sequence number of the first character and the sequence number of the last character in the target text, and the cropping parameter, a first cropping position for the target text is determined.
这里,文本中字符的排列序号,可以预先添加好的,也可以是在每次获取到文本后,按照文本中每个字符的排列顺序,为每个字符添加排列序号,其中,相邻两个字符的排列序号为连续的自然数。对于各字符的排列序号,可以是从0开始,依次标注0、1、2、3…,也可以是从1开始,依次表述1、2、3、4…,并不做任何限定。Here, the sequence number of the characters in the text can be pre-added, or after each acquisition of the text, the sequence number is added to each character according to the sequence of each character in the text. The sequence numbers of characters are consecutive natural numbers. For the sequence number of each character, it can start from 0 and mark 0, 1, 2, 3... in order, or start from 1 and express 1, 2, 3, 4... in order, without any limitation.
在获取到各字符添的排列序号后,就可以借助字符的排列序号,如第一个字符的排列序号和最后一个字符的排列序号,以及前面获取到的所述裁剪参数,去计算可以在所述目标文本中进行裁剪的第一裁剪位置。After obtaining the sequence number of each character, you can use the sequence number of the character, such as the sequence number of the first character and the sequence number of the last character, as well as the cutting parameters obtained earlier, to calculate the Describes the first cropping position in the target text for cropping.
具体的,确定所述第一裁剪位置,可以是先获取所述目标文本中第一个字符的排列序号和最后一个字符的排列序号,然后通过第一个字符的排列序号和最后一个字符的排列序号的数值进行计算,以确定所述目标文本中第一个字符的排列序号和最后一个字符的排列序号的数值和,然后计算所述数值和与所述裁剪参数之间的计算结果,由于计算出的计算结果可能存在余数的情况,即可以包含小数点和小数点之后的小数,所说需要对所述计算结果进行取整处理,得到与所述计算结果最接近的目标序号,其中,所述计算结果与所述目标序号之间的差值小于或者等于所述计算结果与其他序号之间的差值,最后将所述目标序号确定为第一裁剪位置。Specifically, to determine the first cutting position, first obtain the sequence number of the first character and the sequence number of the last character in the target text, and then obtain the sequence number of the first character and the sequence number of the last character. The numerical value of the serial number is calculated to determine the numerical sum of the sequence number of the first character and the sequence number of the last character in the target text, and then the calculation result between the numerical sum and the cropping parameter is calculated. The calculated result may have a remainder, that is, it may include the decimal point and the decimal point after the decimal point, and the calculation result needs to be rounded to obtain the target serial number closest to the calculation result, wherein the calculation The difference between the result and the target serial number is less than or equal to the difference between the calculation result and other serial numbers, and finally the target serial number is determined as the first cutting position.
其中,对于所述数值和与所述裁剪参数的计算方式,可以根据所述裁剪参数的表述形式来确定,例如需要对文本进行二分裁剪,即将文本裁剪成2分的情况下,大多数情况下,所述裁剪参数可以表示为1/2,用于表示裁剪一半,此时,对于所述数值和与所述裁剪参数之间的计算,即可将二者相乘得到计算结果,相反的,如果是通过其他方式表示所述裁剪参数,例如还是以二分裁剪为例,当通过二分裁剪中的“二分”来表示所述裁剪参数,即所述裁剪参数为2的情况下,对于所述数值和与所述裁剪参数之间的计算,即需要使用所述数值和除以所述裁剪参数得到所述计算结果。The calculation method of the numerical value and the cropping parameter can be determined according to the expression form of the cropping parameter. For example, when the text needs to be cut into two parts, that is, when the text is cut into two parts, in most cases , the cropping parameter can be expressed as 1/2, which is used to represent the cropping half. At this time, for the calculation between the numerical value and the cropping parameter, the calculation result can be obtained by multiplying the two. On the contrary, If the cropping parameter is represented in other ways, for example, taking bisection cropping as an example, when the cropping parameter is represented by "bisection" in bisection cropping, that is, when the cropping parameter is 2, for the numerical value The calculation between the sum and the clipping parameter, that is, the calculation result needs to be obtained by dividing the numerical sum by the clipping parameter.
其中,所述目标序号为自然数,为所述目标文本中的多个字符的排列序号中的一个。The target sequence number is a natural number, which is one of the sequence sequence numbers of multiple characters in the target text.
对所述计算结果进行取整处理,可以是向上取整,也可以是向下取整,还可以是根据所述计算结果的具体数值,动态决定向上取整还是向下取整,以得到最接近的整数,即所述计算结果与所述目标序号之间的差值小于或者等于所述计算结果与其他序号之间的差值。The calculation result can be rounded up, or it can be rounded down, or it can be dynamically decided to round up or down according to the specific value of the calculation result, so as to obtain the maximum value. A close integer, that is, the difference between the calculation result and the target serial number is less than or equal to the difference between the calculation result and other serial numbers.
其中,将所述目标序号确定为第一裁剪位置,可以是指将与所述目标序号对应的字符所处的位置,确定为第一裁剪位置,即将与所述目标序号对应的字符之前或者之后的位置作为第一裁剪位置,具体的,在裁剪时,是在与所述目标序号对应的字符之前或者之后的位置,可以参考取整的方向、裁剪参数的大小等因素,来决定取哪个裁剪位置。Wherein, determining the target serial number as the first cutting position may refer to determining the position of the character corresponding to the target serial number as the first cutting position, that is, before or after the character corresponding to the target serial number The position is taken as the first cutting position. Specifically, when cutting, it is the position before or after the character corresponding to the target serial number. You can refer to factors such as the direction of rounding, the size of the cutting parameter, etc. to decide which cut to take. Location.
例如,在确定所述目标序号时,是向上取整的,那么取裁剪位置时,可以将相应的在目标序号对应的字符之前的位置,作为第一裁剪位置,以平衡向上取整的影响。For example, when determining the target serial number, it is rounded up, then when taking the cutting position, the corresponding position before the character corresponding to the target serial number can be used as the first cutting position to balance the effect of rounding up.
然后,可以按照所述第一裁剪位置对所述目标文本进行裁剪,得到所述目标文本中第一个字符所在的第一文本段,其中,所述第一文本段包括所述目标文本中的第一个字符以及所述第一裁剪位置处对应的第二字符。Then, the target text may be cropped according to the first cropping position to obtain a first text segment where the first character in the target text is located, wherein the first text segment includes the The first character and the corresponding second character at the first cropping position.
这里,在确定出所述第一裁剪位置后,可以在所述目标文本中的所述第一裁剪位置处对所述目标文本进行裁剪,得到裁剪后的前段文本,作为所述第一文本段。Here, after the first cropping position is determined, the target text may be cropped at the first cropping position in the target text to obtain the cropped front text as the first text segment .
这里,在取第一文本段的时候,是将所述目标文本中的第一个字符、所述第一裁剪位置处对应的第二字符组成的文本内容作为所述第一文本段,即如果所述第一裁剪位置是在所述目标序号对应的第二字符之后的话,那么所述第一文本段可以是包括所述第二字符的,但并不局限于此,在其他实施方式中,例如所述第一裁剪位置是在所述目标序号对应的第二字符之前的话,那么所述第一文本段可以是不包括所述第二字符的,即在裁剪后,所述第一文本段包括所述目标文本中的第一个字符、位于所述第一裁剪位置处对应的第二字符。Here, when taking the first text segment, the text content consisting of the first character in the target text and the second character corresponding to the first cropping position is used as the first text segment, that is, if If the first cropping position is after the second character corresponding to the target sequence number, then the first text segment may include the second character, but is not limited to this. In other embodiments, For example, if the first cropping position is before the second character corresponding to the target serial number, the first text segment may not include the second character, that is, after cropping, the first text segment It includes the first character in the target text and the second character corresponding to the first cropping position.
接着,基于所述容器参数确定是否需要对所述第一文本段进行裁剪,若需要,即基于所述容器参数确定出需要对所述第一文本段进行裁剪的情况下,将所述第一文本段作为所述目标文本继续进行裁剪,直至多次裁剪后,将最后裁剪得到的第二文本段添加至所述文本容器中的实时显示高度小于或者等于基于所述容器参数确定的所述文本容器的预设显示高度时停止,将所述第二文本段作为所述待显示文本;若不需要,将第一次裁剪得到的所述第一文本段作为所述待显示文本。Next, it is determined whether the first text segment needs to be cropped based on the container parameter, and if necessary, that is, if it is determined based on the container parameter that the first text segment needs to be cropped, the first text segment needs to be cropped. The text segment continues to be cropped as the target text, until after multiple cropping, the real-time display height of adding the second text segment obtained by the final cropping to the text container is less than or equal to the text determined based on the container parameters. When the preset display height of the container stops, the second text segment is used as the to-be-displayed text; if not, the first text segment obtained by first cropping is used as the to-be-displayed text.
这里,由于通过一次裁剪,往往不能得出符合显示要求的待显示文本,所以需要进行多次裁剪,相反的,在对所述目标文本第一次裁剪,得到所述第一文本段之后,若所述第一文本段中第一个字符的排列序号和最后一个字符的排列序号相同,即所述第一文本段中仅有一个字符,无法再裁剪,可以直接停止裁剪。Here, since it is often impossible to obtain the text to be displayed that meets the display requirements through one cut, it needs to be cut multiple times. On the contrary, after the first text segment is obtained by cutting the target text for the first time, if The sequence number of the first character in the first text segment is the same as the sequence number of the last character, that is, there is only one character in the first text segment, which cannot be cut any more, and the cutting can be stopped directly.
因此,在第一次裁剪得到所述第一文本段之后,可以基于所述容器参数再次对所述第一文本段进行检测,以检测是否需要对所述第一文本段进行再次裁剪,具体的,可以是将所述第一文本段添加到所述文本容器中,来看实际显示所述第一文本段的实际显示高度,然后可以通过实际显示高度和所述容器参数中指示的预设显示高度进行比较等,如果实际显示高度小于或者等于预设显示高度的话,则可以认为不需要再对所述第一文本段进行裁剪,可以直接将第一次裁剪得到的所述第一文本段作为所述待显示文本。Therefore, after the first text segment is obtained by cutting for the first time, the first text segment may be detected again based on the container parameter to detect whether the first text segment needs to be cut again. , the first text segment can be added to the text container to see the actual display height of the actual display of the first text segment, and then the actual display height and the preset display indicated in the container parameters can be used. If the actual display height is less than or equal to the preset display height, it can be considered that the first text segment does not need to be cut again, and the first text segment obtained by the first cut can be directly used as the text to be displayed.
相反的,如果实际显示高度大于预设显示高度的话,那么可以认为需要对所述第一文本段进行二次裁剪,此时,可以将所述第一文本段作为所述目标文本,通过裁剪参数等再次确定针对所述目标文本,即所述第一文本段的第一裁剪位置,以进行裁剪,在二次裁剪得到第二文本段之后,如果再次确定需要对第二文本段裁剪的话,可以参照上述过程对第二文本段进行裁剪,直至多次裁剪之后,最后一次裁剪得到的第二文本段不需要再裁剪为止,即将最后一次裁剪得到第二文本段添加至所述文本容器中之后,实际的显示高度是小于或者等于基于所述容器参数确定的所述文本容器的预设显示高度的话,就认为是可以停止裁剪了,这时,可以将最后裁剪得到的所述第二文本段作为所述待显示文本。On the contrary, if the actual display height is greater than the preset display height, it can be considered that the first text segment needs to be cut twice. At this time, the first text segment can be used as the target text, and the clipping parameter Once again, determine the first cropping position for the target text, that is, the first text segment, for cropping. After the second text segment is obtained by secondary cropping, if it is determined again that the second text segment needs to be cropped, you can The second text segment is trimmed with reference to the above process, until after multiple trimming, the second text segment obtained by the last trimming does not need to be trimmed again, that is, after the second text segment obtained by the last trimming is added to the text container, If the actual display height is less than or equal to the preset display height of the text container determined based on the container parameters, it is considered that the cropping can be stopped. At this time, the second text segment obtained by the final cropping can be used as the text to be displayed.
在对所述目标文本进行多次裁剪之后,如果恰好裁剪得到的所述第二文本段中的内容,即所述待显示文本的内容与所述文本容器是适配的,例如实际的显示高度等于所述预设显示高度,并且所述第二文本段中的字符量与所述文本容器的预设显示字数是相同的,可以认为是最合适的裁剪结果,但往往在裁剪过程中,由于裁剪过多,裁剪得到所述第二文本段无法恰好适配,即将第二文本段添加至所述文本容器中的实时显示高度小于所述预设高度,或者虽然实时显示高度等于所述预设高度,但最后一行的字数较少,导致在所述目标页面上实际显示的内容较少或者不足,所以可以从第一文本段之后的字符中再裁剪一部分,拼接在所述第一文本段之后,从而使最终的所述待显示文本与所述文本容器是恰好适配的。After the target text is cropped multiple times, if the content in the second text segment is just cropped, that is, the content of the to-be-displayed text is compatible with the text container, such as the actual display height It is equal to the preset display height, and the number of characters in the second text segment is the same as the preset number of characters displayed in the text container, which can be considered as the most suitable cropping result. There is too much cropping, and the second text segment cannot be exactly fitted after cropping, that is, the real-time display height of adding the second text segment to the text container is smaller than the preset height, or although the real-time display height is equal to the preset height height, but the number of characters in the last line is less, resulting in less or insufficient content actually displayed on the target page, so a part of the characters after the first text segment can be cropped and spliced after the first text segment , so that the final text to be displayed exactly fits the text container.
具体的,在对所述目标文本进行多次裁剪时,可以在对所述目标文本进行裁剪的过程中,裁剪得到所述第一文本段或者所述第二文本段之后,可以将作为待显示文本的所述第一文本段或所述第二文本段添加至所述文本容器中,如果在将作为待显示文本的所述第一文本段或所述第二文本段添加至所述文本容器中,所述文本容器的实时显示高度小于基于所述容器参数确定出的、所述文本容器的预设显示高度的情况下,可以认为在所述目标页面中显示的文本不足,此时可以将所述第一文本段或所述第二文本段作为待拼接文本段,进而确定所述目标文本中与所述待拼接文本段相邻的第三文本段,其中,所述第三文本段包括目标字符和所述目标文本中的最后一个字符,所述目标字符为所述目标文本中在所述待拼接文本段的最后一个字符之后的第一个字符。Specifically, when the target text is cropped multiple times, in the process of cropping the target text, after the first text segment or the second text segment is obtained by cropping, the target text can be cut as the to-be-displayed The first text segment or the second text segment of the text is added to the text container, if the first text segment or the second text segment as the text to be displayed is added to the text container In the case where the real-time display height of the text container is smaller than the preset display height of the text container determined based on the container parameters, it can be considered that the text displayed in the target page is insufficient, and at this time, the The first text segment or the second text segment is used as the text segment to be spliced, and then the third text segment adjacent to the text segment to be spliced in the target text is determined, wherein the third text segment includes the target character and the last character in the target text, where the target character is the first character in the target text after the last character of the text segment to be spliced.
然后,基于所述第三文本段中字符的排列序号和所述裁剪参数,对所述第三文本段进行至少一次裁剪,得到第四文本段,最后,将所述待拼接文本段和所述第四文本段拼接后的文本段作为所述待显示文本即可。Then, based on the sequence numbers of the characters in the third text segment and the trimming parameters, the third text segment is trimmed at least once to obtain a fourth text segment, and finally, the to-be-spliced text segment and the The text segment after the splicing of the fourth text segment can be used as the text to be displayed.
其中,将所述第四文本段与所述待拼接文本段拼接后的文本段添加至所述文本容器中的实时显示高度等于所述预设显示高度。Wherein, the real-time display height of adding the fourth text segment and the text segment to be spliced into the text container is equal to the preset display height.
具体的,对于所述第三文本段的至少一次裁剪,可以通过以下过程实现:Specifically, for at least one trimming of the third text segment, the following process may be used:
首先,可以基于所述第三文本段中第一个字符的排列序号和最后一个字符的排列序号,以及所述裁剪参数,确定针对所述第三文本段的第二裁剪位置。First, a second trimming position for the third text segment may be determined based on the sequence number of the first character and the sequence sequence number of the last character in the third text segment, and the trimming parameter.
这里,所述第二裁剪位置的确定方式和具体过程,可以与所述第一裁剪位置的确定方式和具体过程相同。Here, the determination manner and specific process of the second cropping position may be the same as the determination manner and specific process of the first cropping position.
然后,按照所述第二裁剪位置对所述第三文本段进行裁剪,得到第五文本段和第六文本段,其中,所述第五文本段为包括所述第三文本段中的第一个字符的文本段,所述第六文本段为与所述第五文本段相邻并且包括所述第三文本段中最后一个字符的文本段。Then, the third text segment is trimmed according to the second trimming position to obtain a fifth text segment and a sixth text segment, wherein the fifth text segment includes the first text segment in the third text segment A text segment of 2 characters, the sixth text segment is a text segment adjacent to the fifth text segment and including the last character in the third text segment.
这里,在确定出所述第二裁剪位置后,可以在所述第三文本段中的所述第二裁剪位置处对所述第三文本段进行裁剪,得到裁剪后的第五文本段和第六文本段。Here, after the second cropping position is determined, the third text segment may be cropped at the second cropping position in the third text segment to obtain the cropped fifth text segment and the first cropped text segment. Six text segments.
其中,所述第三文本段为包括所述第二文本段中第一个字符的文本段,所述第四文本段为与所述第三文本段相邻并且包括所述第二文本段中最后一个字符的文本段。Wherein, the third text segment is a text segment including the first character in the second text segment, and the fourth text segment is adjacent to the third text segment and includes the last character in the second text segment A text segment of characters.
这里,在取第三文本段的时候,可以是将所述第二文本段中的第一个字符、所述第二裁剪位置处对应的第四字符和位于所述第二文本段中第一个字符与所述第四字符之间的至少一个第五字符组成文本内容,作为所述第三文本段。相应的,如果所述第二裁剪位置是在所述第四字符之后的话,那么所述第三文本段可以是包括所述第四字符的,而如果所述第二裁剪位置是在所述第四字符之前的话,那么所述第三文本段可以是不包括所述第四字符的。Here, when taking the third text segment, the first character in the second text segment, the fourth character corresponding to the second cropping position and the first character in the second text segment At least one fifth character between the first character and the fourth character constitutes text content as the third text segment. Correspondingly, if the second cropping position is after the fourth character, the third text segment may include the fourth character, and if the second cropping position is after the fourth character If it is four characters before, the third text segment may not include the fourth character.
然后,将对第三文本段进行裁剪之后得到第五文本段与待拼接文本段进行拼接,再将所述第五文本段和所述待拼接文本段进行拼接后的文本段添加至所述文本容器中,所述文本容器的实时显示高度仍小于所述预设显示高度的情况下,将所述第六文本段作为所述第三文本段再次进行裁剪,直至将所述待拼接文本段和裁剪得到的至少两个所述第五文本段拼接后的文本段添加至所述文本容器中,所述文本容器的实时显示高度等于所述预设显示高度时停止裁剪,将裁剪得到的至少两个所述第五文本段拼接后的文本段作为所述第四文本段。Then, the fifth text segment obtained after cutting the third text segment is spliced with the text segment to be spliced, and then the text segment obtained by splicing the fifth text segment and the to-be-spliced text segment is added to the text In the container, if the real-time display height of the text container is still smaller than the preset display height, the sixth text segment is used as the third text segment to be cropped again until the to-be-spliced text segment and the The clipped at least two text segments obtained by splicing the fifth text segment are added to the text container, and the clipping is stopped when the real-time display height of the text container is equal to the preset display height, and the at least two clipped text segments are cut. The text segment after the splicing of the fifth text segment is used as the fourth text segment.
这里,在得到所述第五文本段后,可以将得到的所述第五文本段和所述待拼接文本段进行拼接,并对拼接的文本再次进行检测,如果拼接的文本在所述文本容器的实时显示高度仍然是小于所述预设显示高度的话,那么可以认为拼接后的文本还是不足,还需要再添加一些,此时可以将裁剪得到所述第六文本段作为所述第三文本段再次进行裁剪,来为拼接的文本再次补充,具体的,可以是将所述第六文本段作为所述第三文本段,按照上述过程再次对作为所述第三文本段的所述第六文本段进行裁剪,直至多次裁剪之后,将待拼接文本段和裁剪得到的至少两个所述第五文本段拼接后的文本段添加至所述文本容器中,所述文本容器的实时显示高度等于所述预设显示高度时,可以认为所有裁剪出的文本符合所述目标页面的显示要求,即可停止裁剪。Here, after the fifth text segment is obtained, the obtained fifth text segment and the to-be-spliced text segment can be spliced, and the spliced text can be detected again. If the spliced text is in the text container If the real-time display height is still smaller than the preset display height, then it can be considered that the text after splicing is still insufficient, and more needs to be added. At this time, the sixth text segment obtained by cutting can be used as the third text segment. Cut again to supplement the spliced text. Specifically, the sixth text segment can be used as the third text segment, and the sixth text as the third text segment can be used again according to the above process. The segment is clipped until after multiple clipping, the text segment to be spliced and the text segment obtained by splicing at least two of the fifth text segments are added to the text container, and the real-time display height of the text container is equal to When the preset display height is set, it can be considered that all the clipped texts meet the display requirements of the target page, and the clipping can be stopped.
相反的,在得到所述第五文本段后,将得到的所述第五文本段和所述待拼接文本段进行拼接,并将所述第五文本段和所述待拼接文本段拼接后添加至所述文本容器中之后再次进行检测的时候,在将所述第五文本段和所述待拼接文本段拼接后添加至所述文本容器中,所述文本容器的实时显示高度大于所述预设显示高度的情况下,那么可以认为拼接后的文本已经超出,此时可以将所述第五文本段作为所述目标文本进行裁剪,直至多次裁剪后,将最后裁剪得到的第七文本段和所述待拼接文本段拼接后添加至所述文本容器中的实时显示高度等于所述预设高度时停止,此时可以将所述第七文本段作为所述第四文本段。On the contrary, after the fifth text segment is obtained, the obtained fifth text segment and the to-be-spliced text segment are spliced, and the fifth text segment and the to-be-spliced text segment are spliced and added When the detection is performed again in the text container, after the fifth text segment and the to-be-spliced text segment are spliced and added to the text container, the real-time display height of the text container is greater than the preset height. In the case of setting the display height, it can be considered that the text after splicing has exceeded, and the fifth text segment can be cut as the target text at this time, until after multiple cuts, the seventh text segment obtained by the last cut The real-time display height added to the text container after being spliced with the to-be-spliced text segment is stopped when the height is equal to the preset height, and the seventh text segment can be used as the fourth text segment at this time.
更进一步的,为了使最终在所述目标页面显示的内容可以与其他信息对齐,保证所述目标页面中各条信息的整体性,在将所述第六文本段作为所述第三文本段再次进行裁剪的时候,可以是在多次的裁剪过程中,直至所述待拼接文本段和裁剪得到的至少两个所述第五文本段拼接后的文本段中的字符数量,等于基于容器参数确定出的所述文本容器中的预设字符容量时,才停止裁剪。Further, in order to align the content finally displayed on the target page with other information and ensure the integrity of each piece of information in the target page, the sixth text segment is used as the third text segment again. When cutting, it can be in multiple cutting processes, until the number of characters in the text segment to be spliced and the text segment obtained by splicing at least two of the fifth text segments obtained by cutting is equal to the determination based on the container parameters. The cropping is stopped only when the preset character capacity in the text container is output.
再者,由于在裁剪的过程中,每次裁剪,都需要把裁剪出的文本进行拼接,放入所述文本容器中进行检测,为了减少检测的内容和简化检测流程,还可以通过裁剪后的文本中各字符的排列序号作为比对的参考,具体的,可以在裁剪的过程中,将所述第六文本段作为所述第三文本段再次进行裁剪时,直至所述第二裁剪位置对应的排列序号与裁剪得到的第三文本中的最后一个字符的排列序号相同时,停止裁剪。Furthermore, because in the process of cutting, each time cutting, it is necessary to splicing the cut text and put it into the text container for detection. In order to reduce the content of the detection and simplify the detection process, it is also possible to The sequence number of each character in the text is used as a reference for comparison. Specifically, in the process of cutting, the sixth text segment can be used as the third text segment to be cut again until the second cutting position corresponds to When the sequence number is the same as the sequence number of the last character in the trimmed third text, the trimming is stopped.
最后,在将裁剪得到的所述第二文本段作为所述待显示文本时,由于新得到需要补充的第四文本段,因此,可以将所述待拼接文本段和所述第四文本段拼接后的文本段作为所述待显示文本。Finally, when the cut-out second text segment is used as the to-be-displayed text, since the fourth text segment to be supplemented is newly obtained, the to-be-spliced text segment and the fourth text segment can be spliced together The following text segment is used as the text to be displayed.
示例性,仍然以需要显示的目标文本为“一二三四五六七八九十百千万亿”,用于显示文本的文本容器的预设显示行数为2行、每行预设显示字数为3个字符,预设单行文字高度为20像素为例,在确定出需要对目标文本进行裁剪的时候,可以获取针对目标文本的裁剪参数,例如是1/2,以对“一二三四五六七八九十百千万亿”从0开始标号为例,各字符的排列序号依次为0、1、2、3、…、11、12、13,具体的裁剪过程如下:Exemplarily, still take the target text to be displayed as "1234567890 quadrillion", the preset number of displayed lines of the text container used to display the text is 2 lines, and each line is preset to display. The number of words is 3 characters, and the preset single-line text height is 20 pixels. For example, when it is determined that the target text needs to be cropped, the cropping parameters for the target text can be obtained, for example, 1/2, so as to adjust the "one, two, three". For example, the numbering starts from 0, and the sequence number of each character is 0, 1, 2, 3, ..., 11, 12, 13. The specific cutting process is as follows:
第一次裁剪:m=(0+13)/2=6.5,其中,m为第一裁剪位置,0为目标文本中第一个字符“一”的排列序号,13为目标文本中最后一个字符“亿”的排列序号,以向下取整为例,这里m取6,就是以排列序号为6的字符“七”所在的位置作为第一裁剪位置,以在“七”之前裁剪为例,第一次裁剪得到的第一文本段为“一二三四五六”,此时把第一文本段添加到文本容器中,加上预设需要显示的特殊文字“略”,此时实际的显示行数为三行,大于预设显示行数2,因此需要将裁剪得到的第一文本段作为目标文本进行第二次裁剪;The first cropping: m=(0+13)/2=6.5, where m is the first cropping position, 0 is the sequence number of the first character "one" in the target text, and 13 is the last character in the target text For the sequence number of "billion", take the rounding down as an example, where m is taken as 6, that is, the position of the character "seven" with the sequence number of 6 is used as the first cutting position, and cutting before "seven" is an example, The first text segment obtained by the first cropping is "123456". At this time, the first text segment is added to the text container, and the special text "omitted" that needs to be displayed by default is added. At this time, the actual The number of displayed lines is three lines, which is greater than the preset number of displayed lines of 2. Therefore, it is necessary to use the cropped first text segment as the target text for the second cropping;
第二次裁剪:m=(0+5)/2=2.5,m为新的第一裁剪位置,0为新的目标文本,即第一次裁剪后的第一文本段中的第一个字符“一”的排列序号,5为新的目标文本,即第一次裁剪后的第一文本段中的最后一个字符“六”的排列序号,仍然以向下取整为例,这里m取2,就是以排列序号为2的字符“三”所在的位置作为新的第一裁剪位置,以在“三”之前裁剪为例,第二次裁剪得到的第一文本段为“一二”,此时,把新的第一文本段人添加到文本容器中,加上预设需要显示的特殊文字“略”,此时实际的显示行数为一行,小于预设显示行数2,是可以停止裁剪的,但是由于实际在目标页面中显示时,内容过少,因此,可以对得到的第一文本段进行补充,需要从后面的文本裁剪部分文本,以与第一文本段拼接,进行文本补充;Second cropping: m=(0+5)/2=2.5, m is the new first cropping position, 0 is the new target text, that is, the first character in the first text segment after the first cropping The sequence number of "one", 5 is the new target text, that is, the sequence number of the last character "six" in the first text segment after the first cut, still take the rounding down as an example, here m is 2 , that is, the position of the character "three" whose sequence number is 2 is used as the new first cutting position. Taking the cutting before "three" as an example, the first text segment obtained by the second cutting is "one two". When the new first text segment is added to the text container, plus the special text "omitted" that needs to be displayed by default, the actual number of displayed lines is one line, which is less than the preset number of displayed lines of 2, it can be stopped Cropped, but because the content is too small when actually displayed on the target page, the obtained first text segment can be supplemented, and part of the text needs to be cropped from the following text to be spliced with the first text segment for text supplementation ;
第三次裁剪:m=(2+5)/2=3.5,m为第二裁剪位置,2为上述裁剪之后的第二文本中第一个字符“三”的排列序号,5为第一次裁剪时第一裁剪位置对应的字符“六”的排列序号,仍然以向下取整为例,这里m取3,就是以排列序号为3的字符“四”所在的位置作为第二裁剪位置,以在“四”之前裁剪为例,第三次裁剪得到的第三文本段为“三”,第一文本段和第三文本段拼接后,添加到文本容器后,加上特殊文字“略”,实际显示行数是2行,等于预设显示行数2,此时可以停止裁剪,但是为了使最终的所述待显示文本与所述文本容器是恰好适配的,可以再次对第四文本段再次进行裁剪:The third cropping: m=(2+5)/2=3.5, m is the second cropping position, 2 is the sequence number of the first character "three" in the second text after the above cropping, and 5 is the first time When cutting, the sequence number of the character "six" corresponding to the first trimming position is still rounded down as an example, where m is taken as 3, that is, the position of the character "four" whose sequence number is 3 is used as the second trimming position, Taking the cropping before "four" as an example, the third text segment obtained by the third cropping is "three". After the first text segment and the third text segment are spliced, they are added to the text container, and the special text "omitted" is added. , the actual display line number is 2 lines, which is equal to the preset display line number 2. At this time, the cropping can be stopped, but in order to make the final text to be displayed exactly fit the text container, the fourth text can be The segment is cropped again:
第四次裁剪:m=(3+5)/2=4,m为新的第二裁剪位置,3为上述裁剪之后的第四文本中第一个字符“四”的排列序号,5为第一次裁剪时第一裁剪位置对应的字符“六”的排列序号,以排列序号为4的字符“五”所在的位置作为第二裁剪位置,以在“五”之前裁剪为例,第四次裁剪得到的第三文本段为“四”,第一文本段和得到的两个第三文本段拼接后,添加到文本容器后,加上特殊文字“略”,实际显示行数是2行,等于预设显示行数2,但第二行仅有两个字符,还需要添加;Fourth cropping: m=(3+5)/2=4, m is the new second cropping position, 3 is the sequence number of the first character "four" in the fourth text after the above cropping, and 5 is the first The sequence number of the character "six" corresponding to the first trimming position during one trimming, the position where the character "five" with sequence number 4 is located is used as the second trimming position, taking the trimming before "five" as an example, the fourth time The third text segment obtained by cutting is "four". After the first text segment and the two obtained third text segments are spliced, they are added to the text container, and the special text "omitted" is added. The actual number of displayed lines is 2 lines. It is equal to the default display line number 2, but the second line has only two characters and needs to be added;
第五次裁剪:m=(4+5)/2=4.5,m为新的第二裁剪位置,4位上述裁剪之后的第四文本中第一个字符“五”的排列序号,5为第一次裁剪时第一裁剪位置对应的字符“六”的排列序号,以排列序号为4的字符“五”所在的位置作为第二裁剪位置,此时如果仍以在“五”之前裁剪的话,与上次裁剪结果相同,因此,此时可以在“五”之后裁剪,第五次裁剪得到的第三文本段为“五”,第一文本段和得到的三个第三文本段拼接后,添加到文本容器后,加上特殊文字“略”,实际的显示文本为“一二三四五略”,显示行数是2行,等于预设显示行数2,而且总字符数是6,与预设显示字数相同,即可以停止裁剪。The fifth cropping: m=(4+5)/2=4.5, m is the new second cropping position, 4 digits of the sequence number of the first character "five" in the fourth text after the above cropping, and 5 is the first The sequence number of the character "six" corresponding to the first trimming position during one trimming, the position where the character "five" with sequence number 4 is located is used as the second trimming position. The result is the same as the previous cropping result. Therefore, it can be cropped after "five" at this time. The third text segment obtained by the fifth cropping is "five". After the first text segment and the obtained three third text segments are spliced, After adding it to the text container, add the special text "omitted", the actual display text is "one two three four five abbreviated", the number of displayed lines is 2 lines, which is equal to the default number of displayed lines of 2, and the total number of characters is 6, It is the same as the preset display word count, that is, you can stop cropping.
S105:将得到的所述待显示文本添加至所述文本容器中,以在所述目标页面中显示所述待显示文本。S105: Add the obtained text to be displayed into the text container, so as to display the text to be displayed on the target page.
本公开实例提供的文本显示方法,通过获取目标文本、用于显示所述目标文本的文本容器,以及所述文本容器在目标页面中显示文本的容器参数;基于所述容器参数,确定是否需要对所述目标文本进行裁剪;若需要对所述目标文本进行裁剪,确定针对所述目标文本的裁剪参数;基于所述裁剪参数以及所述目标文本中字符的排列序号,对所述目标文本进行至少一次裁剪,得到待显示文本;将得到的所述待显示文本添加至所述文本容器中,以在所述目标页面中显示所述待显示文本。In the text display method provided by an example of the present disclosure, by acquiring target text, a text container for displaying the target text, and a container parameter for the text container to display text in a target page; based on the container parameter, it is determined whether it is necessary to The target text is cropped; if the target text needs to be cropped, the cropping parameters for the target text are determined; based on the cropping parameters and the sequence number of the characters in the target text, at least One cropping is performed to obtain the text to be displayed; the obtained text to be displayed is added to the text container, so as to display the text to be displayed in the target page.
这样,通过文本容器显示文本时的容器参数,以及针对目标文本的裁剪参数和目标文本中字符的排列序号,可以从目标文本中的相应位置对目标文本进行至少一次裁剪,从而可以大大减少文本裁剪的次数,降低文本处理时间,以提高文本处理的效率和速度,同时还会减少裁剪掉的元素的数量,以减少了机身内存的无效占用,以保证终端运行的流畅度。In this way, the target text can be cropped at least once from the corresponding position in the target text through the container parameters when the text container displays the text, the cropping parameters for the target text and the sequence number of the characters in the target text, thereby greatly reducing text cropping It reduces the text processing time to improve the efficiency and speed of text processing, and also reduces the number of clipped elements to reduce the ineffective occupation of the fuselage memory to ensure the smoothness of the terminal operation.
请参阅图2,图2为本公开实例提供的另一种文本显示方法的流程图,如图2中所示,所述方法包括:Please refer to FIG. 2. FIG. 2 is a flowchart of another text display method provided by an example of the present disclosure. As shown in FIG. 2, the method includes:
S201:获取目标文本、用于显示所述目标文本的文本容器,以及所述文本容器在目标页面中显示文本的容器参数。S201: Obtain target text, a text container for displaying the target text, and a container parameter of the text container to display text in a target page.
S202:基于所述容器参数,确定是否需要对所述目标文本进行裁剪。S202: Based on the container parameter, determine whether the target text needs to be cropped.
S203:若需要对所述目标文本进行裁剪,确定针对所述目标文本的裁剪参数。S203: If the target text needs to be cropped, determine cropping parameters for the target text.
S204:基于所述裁剪参数以及所述目标文本中字符的排列序号,对所述目标文本进行至少一次裁剪,得到待显示文本。S204: Based on the trimming parameters and the sequence numbers of the characters in the target text, trim the target text at least once to obtain the text to be displayed.
S205:检测所述待显示文本中的最后一个字符是否属于预先统计好的、不需要显示的特殊字符。S205: Detect whether the last character in the to-be-displayed text belongs to a pre-statistical special character that does not need to be displayed.
该步骤中,在初步得到所述待显示文本后,可以获取预先统计好的、不需要显示的特殊字符,通过所述待显示文本中的最后一个字符与所述特殊字符进行匹配,来检测最后一个字符是不是所述特殊字符。In this step, after the text to be displayed is initially obtained, pre-stated special characters that do not need to be displayed can be obtained, and the last character in the text to be displayed is matched with the special character to detect the last character A character is not the special character.
其中,所述特殊字符可以是指在标题信息等形式中不需要出现的标点符号、特殊符号、计算符号等。Wherein, the special characters may refer to punctuation symbols, special symbols, calculation symbols, etc. that do not need to appear in the form of title information and the like.
S206:若是,将所述待显示文本中的最后一个字符裁剪掉,得到处理后的所述待显示文本。S206: If yes, cut out the last character in the to-be-displayed text to obtain the processed to-be-displayed text.
S207:将得到的所述待显示文本添加至所述文本容器中,以在所述目标页面中显示所述待显示文本。S207: Add the obtained text to be displayed into the text container, so as to display the text to be displayed on the target page.
请同时参阅图3,图3为本公开实施例提供的一种文本显示方法的裁剪逻辑示意图。如图3中所示,在将存放文本的文本容器初始化以后,需要将文本结尾需要显示的预设字符添加到文本容器中,然后将目标文本放入加入预设字符的文本容器中,得到目标文本的目标显示高度,进一步,需要根据容器参数中的预设显示行数和预设单行高度,计算出所述文本容器的预设显示高度,然后通过将目标显示高度与预设显示高度做对比,确定是否需要对目标文本进行裁剪,若目标显示高度小于等于预设显示高度,则当前文本不需要进行裁剪,处理完成;若目标显示高度大于预设显示高度,则说明目标文本字数是超出的,则可以进入裁剪环节,当进入裁剪环节之后的目标文本经过至少一次裁剪之后得到的第一文本段中第一个字符的排列序号小于最后一个字符的排列序号,则进入循环裁剪,若经过至少一次裁剪得到的第一文本段中第一个字符的排列序号等于最后一个字符的排列序号时,则可以跳出循环裁剪阶段,得到待显示文本;同时若将目标文本经至少一次裁剪过后得到的第一文本段中的字符数量远小于预设的字符数量,则可以从与第一文本段相邻的文本段中裁剪文本对第一文本段进行补充,直到补充过后的文本中第一个字符的排列序号等于最后一个字符的排列序号时停止,得到待显示文本,然后对得到的待显示文本进行检测,循环检测待显示文本中最后一个字符是否属于预先统计好的,不需要显示的特殊字符,若是,则将当前文本的最后一个字符裁剪掉,进而得到最终的待显示文本,若不是则直接跳出循环,直接得到最终的待显示文本。Please also refer to FIG. 3 , which is a schematic diagram of cropping logic of a text display method provided by an embodiment of the present disclosure. As shown in Figure 3, after initializing the text container that stores the text, it is necessary to add the preset characters that need to be displayed at the end of the text to the text container, and then put the target text into the text container that adds the preset characters to obtain the target text. The target display height of the text. Further, it is necessary to calculate the preset display height of the text container according to the preset display line number and preset single line height in the container parameters, and then compare the target display height with the preset display height. , to determine whether the target text needs to be cropped. If the target display height is less than or equal to the preset display height, the current text does not need to be cropped and the processing is completed; if the target display height is greater than the preset display height, it means that the number of words in the target text is exceeded. , you can enter the cutting process. When the target text after entering the cutting process has been cut at least once, the sequence number of the first character in the first text segment is smaller than the sequence number of the last character, then it will enter the circular cutting process. When the sequence number of the first character in the first text segment obtained by one cut is equal to the sequence number of the last character, the loop cutting stage can be jumped out to obtain the text to be displayed; The number of characters in a text segment is much smaller than the preset number of characters, then the text can be cut from the text segment adjacent to the first text segment to supplement the first text segment until the sequence number of the first character in the supplemented text is reached Stop when it is equal to the sequence number of the last character, get the text to be displayed, and then test the obtained text to be displayed, and loop to detect whether the last character in the text to be displayed belongs to the pre-stated special characters that do not need to be displayed, if so, Then, the last character of the current text is cut out, and the final text to be displayed is obtained, if not, the loop is directly jumped out, and the final text to be displayed is directly obtained.
本公开实施例提供的文本显示方法,通过获取目标文本、用于显示所述目标文本的文本容器,以及所述文本容器在目标页面中显示文本的容器参数;基于所述容器参数,确定是否需要对所述目标文本进行裁剪;若需要对所述目标文本进行裁剪,确定针对所述目标文本的裁剪参数;基于所述裁剪参数以及所述目标文本中字符的排列序号,对所述目标文本进行至少一次裁剪,得到待显示文本;检测所述待显示文本中的最后一个字符是否属于预先统计好的、不需要显示的特殊字符;若是,将所述待显示文本中的最后一个字符裁剪掉,得到处理后的所述待显示文本;将得到的所述待显示文本添加至所述文本容器中,以在所述目标中显示所述待显示文本。In the text display method provided by the embodiment of the present disclosure, by acquiring target text, a text container for displaying the target text, and container parameters for the text container to display text in a target page; based on the container parameters, it is determined whether it is necessary to The target text is trimmed; if the target text needs to be trimmed, the trimming parameters for the target text are determined; based on the trimming parameters and the sequence number of the characters in the target text, the target text is Cut at least once to obtain the text to be displayed; detect whether the last character in the text to be displayed belongs to a special character that has been counted in advance and does not need to be displayed; if so, cut out the last character in the text to be displayed, The processed text to be displayed is obtained; the obtained text to be displayed is added to the text container to display the text to be displayed in the target.
这样,通过文本容器显示文本时的容器参数,以及针对目标文本的裁剪参数和目标文本中字符的排列序号,可以从目标文本中的相应位置对目标文本进行至少一次裁剪,并且可以在得到待显示文本后对文本中的最后一个字符进行筛选,以去除不需要显示的特殊字符,从而可以大大减少文本裁剪的次数,降低文本处理时间,以提高文本处理的效率和速度,同时还会减少裁剪掉的元素的数量,以减少了机身内存的无效占用,以保证终端运行的流畅度。In this way, by using the container parameters when the text container displays text, the cropping parameters for the target text, and the sequence number of the characters in the target text, the target text can be cropped at least once from the corresponding position in the target text, and the target text can be cropped at least once when the text to be displayed is obtained. After the text, the last character in the text is filtered to remove the special characters that do not need to be displayed, which can greatly reduce the number of text clipping, reduce text processing time, improve the efficiency and speed of text processing, and reduce clipping. In order to reduce the invalid occupation of the fuselage memory and ensure the smoothness of the terminal operation.
本领域技术人员可以理解,在具体实施方式的上述方法中,各步骤的撰写顺序并不意味着严格的执行顺序而对实施过程构成任何限定,各步骤的具体执行顺序应当以其功能和可能的内在逻辑确定。Those skilled in the art can understand that in the above method of the specific implementation, the writing order of each step does not mean a strict execution order but constitutes any limitation on the implementation process, and the specific execution order of each step should be based on its function and possible Internal logic is determined.
基于同一发明构思,本公开实施例中还提供了与文本显示方法对应的文本显示装置,由于本公开实施例中的装置解决问题的原理与本公开实施例上述文本显示方法相似,因此装置的实施可以参见方法的实施,重复之处不再赘述。Based on the same inventive concept, the embodiment of the present disclosure also provides a text display device corresponding to the text display method. Reference may be made to the implementation of the method, and repeated descriptions will not be repeated.
请参阅图4和图5,图4为本公开实施例提供的一种文本显示装置的示意图之一,图5为本公开实例提供的一种文本显示装置的示意图之二。如图4中所示,本公开实例提供的文本显示装置400包括:Please refer to FIG. 4 and FIG. 5 , FIG. 4 is one of the schematic diagrams of a text display device provided by an embodiment of the present disclosure, and FIG. 5 is the second schematic diagram of a text display device provided by an embodiment of the present disclosure. As shown in FIG. 4 , the
获取模块410,用于获取目标文本、用于显示所述目标文本的文本容器,以及所述文本容器在目标页面中显示文本的容器参数。The obtaining
第一确定模块420,用于基于所述容器参数,确定是否需要对所述目标文本进行裁剪。The first determining
第二确定模块430,用于若需要对所述目标文本进行裁剪,确定针对所述目标文本的裁剪参数。The second determining
文本裁剪模块440,用于基于所述裁剪参数以及所述目标文本中字符的排列序号,对所述目标文本进行至少一次裁剪,得到待显示文本。The
文本显示模块450,用于将得到的所述待显示文本添加至所述文本容器中,以在所述目标页面中显示所述待显示文本。The
一种可选的实施方式中,所述第一确定模块420具体用于:In an optional implementation manner, the first determining
初始化所述文本容器;initialize the text container;
基于所述容器参数中预设显示行数和预设单行高度,确定所述文本容器的预设显示高度;determining the preset display height of the text container based on the preset number of displayed lines and the preset single-line height in the container parameters;
将预设字符添加至初始化之后的所述文本容器中的预设位置;adding preset characters to preset positions in the text container after initialization;
将所述目标文本添加至加入所述预设字符的所述文本容器中,得到通过所述文本容器显示所述目标文本的目标显示高度;adding the target text to the text container added with the preset characters to obtain a target display height for displaying the target text through the text container;
若所述目标显示高度大于所述预设显示高度,确定需要对所述目标文本进行裁剪。If the target display height is greater than the preset display height, it is determined that the target text needs to be cropped.
一种可选的实施方式中,所述第二确定模块430具体用于:In an optional implementation manner, the second determining
若需要对所述目标文本进行裁剪,基于所述目标文本中的字符总量和所述容器参数,确定针对所述目标文本的裁剪参数;或者If the target text needs to be cropped, based on the total amount of characters in the target text and the container parameters, determine the cropping parameters for the target text; or
若需要对所述目标文本进行裁剪,获取预设的针对所述目标文本的裁剪参数。If the target text needs to be cropped, the preset cropping parameters for the target text are acquired.
一种可选的实施方式中,所述文本裁剪模块440具体用于:In an optional implementation manner, the
基于所述目标文本中第一个字符的排列序号和最后一个字符的排列序号,以及所述裁剪参数,确定针对所述目标文本的第一裁剪位置;Based on the sequence number of the first character in the target text and the sequence number of the last character, and the cropping parameters, determine the first cropping position for the target text;
按照所述第一裁剪位置对所述目标文本进行裁剪,得到所述目标文本中第一个字符所在的第一文本段,其中,所述第一文本段包括所述目标文本中的第一个字符以及所述第一裁剪位置处对应的第二字符;The target text is cropped according to the first cropping position to obtain a first text segment where the first character in the target text is located, wherein the first text segment includes the first text segment in the target text character and the second character corresponding to the first cropping position;
基于所述容器参数确定是否需要对所述第一文本段进行裁剪;determining whether the first text segment needs to be cropped based on the container parameter;
若需要,将所述第一文本段作为所述目标文本继续进行裁剪,直至多次裁剪后,将最后裁剪得到的第二文本段添加至所述文本容器中的实时显示高度小于或者等于基于所述容器参数确定的所述文本容器的预设显示高度时停止,将所述第二文本段作为所述待显示文本;If necessary, continue to cut the first text segment as the target text, until after multiple cuts, the real-time display height of adding the last cut second text segment to the text container is less than or equal to the height of the real-time display based on the Stop when the preset display height of the text container is determined by the container parameter, and use the second text segment as the text to be displayed;
若不需要,将第一次裁剪得到的所述第一文本段作为所述待显示文本。If not required, the first text segment obtained by the first cropping is used as the text to be displayed.
一种可选的实施方式中,所述文本裁剪模块440在用于基于所述目标文本中第一个字符的排列序号和最后一个字符的排列序号,以及所述裁剪参数,确定针对所述目标文本的第一裁剪位置时,具体用于:In an optional embodiment, the
确定所述目标文本中第一个字符的排列序号和最后一个字符的排列序号的数值和;Determine the numerical sum of the sequence number of the first character and the sequence number of the last character in the target text;
计算所述数值和与所述裁剪参数之间的计算结果;calculating a calculation result between the numerical value and the cropping parameter;
对所述计算结果进行取整处理,得到与所述计算结果最接近的目标序号;Rounding is performed on the calculation result to obtain the target sequence number closest to the calculation result;
将所述目标序号确定为第一裁剪位置。The target serial number is determined as the first cutting position.
一种可选的实施方式中,所述文本裁剪模块440还用于:In an optional implementation manner, the
在将作为待显示文本的所述第一文本段或所述第二文本段添加至所述文本容器中,所述文本容器的实时显示高度小于基于所述容器参数确定出的、所述文本容器的预设显示高度的情况下,将所述第一文本段或所述第二文本段作为待拼接文本段,确定所述目标文本中与所述待拼接文本段相邻的第三文本段,其中,所述第三文本段包括目标字符和所述目标文本中的最后一个字符,所述目标字符为所述目标文本中在所述待拼接文本段的最后一个字符之后的第一个字符;When adding the first text segment or the second text segment as the text to be displayed into the text container, the real-time display height of the text container is smaller than the text container determined based on the container parameter. In the case of the preset display height of The third text segment includes a target character and the last character in the target text, and the target character is the first character in the target text after the last character of the text segment to be spliced;
基于所述第三文本段中字符的排列序号和所述裁剪参数,对所述第三文本段进行至少一次裁剪,得到第四文本段,其中,将所述第四文本段与所述待拼接文本段拼接后的文本段添加至所述文本容器中的实时显示高度等于所述预设显示高度;Based on the sequence numbers of the characters in the third text segment and the trimming parameters, the third text segment is trimmed at least once to obtain a fourth text segment, wherein the fourth text segment is combined with the to-be-spliced text segment. The real-time display height of the text segment spliced into the text container added to the text container is equal to the preset display height;
将所述待拼接文本段和所述第四文本段拼接后的文本段作为所述待显示文本。The text segment obtained by splicing the to-be-spliced text segment and the fourth text segment is used as the to-be-displayed text.
一种可选的实施方式中,所述文本裁剪模块440在用于基于所述第三文本段中字符的排列序号和所述裁剪参数,对所述第三文本段进行至少一次裁剪,得到第四文本段时,具体用于:In an optional implementation manner, the
基于所述第三文本段中第一个字符的排列序号和最后一个字符的排列序号,以及所述裁剪参数,确定针对所述第三文本段的第二裁剪位置;Based on the sequence number of the first character and the sequence number of the last character in the third text segment, and the cropping parameter, determining a second cropping position for the third text segment;
按照所述第二裁剪位置对所述第三文本段进行裁剪,得到第五文本段和第六文本段,其中,所述第五文本段为包括所述第三文本段中的第一个字符的文本段,所述第六文本段为与所述第五文本段相邻并且包括所述第三文本段中最后一个字符的文本段;The third text segment is trimmed according to the second trimming position to obtain a fifth text segment and a sixth text segment, wherein the fifth text segment includes the first character in the third text segment The text segment, the sixth text segment is a text segment adjacent to the fifth text segment and including the last character in the third text segment;
在将所述第五文本段和所述待拼接文本段进行拼接后的文本段添加至所述文本容器中,所述文本容器的实时显示高度仍小于所述预设显示高度的情况下,将所述第六文本段作为所述第三文本段再次进行裁剪,直至将所述待拼接文本段和裁剪得到的至少两个所述第五文本段拼接后的文本段添加至所述文本容器中,所述文本容器的实时显示高度等于所述预设显示高度时停止裁剪;In the case where the text segment obtained by splicing the fifth text segment and the to-be-spliced text segment is added to the text container, and the real-time display height of the text container is still smaller than the preset display height, add The sixth text segment is cut again as the third text segment, until the text segment to be spliced and the cut text segment obtained by splicing at least two of the fifth text segments are added to the text container , and stop cropping when the real-time display height of the text container is equal to the preset display height;
将裁剪得到的至少两个所述第五文本段拼接后的文本段作为所述第四文本段。A text segment obtained by splicing at least two of the fifth text segments obtained by cutting is used as the fourth text segment.
一种可选的实施方式中,所述文本裁剪模块440在用于在所述按照所述第二裁剪位置对所述第三文本段进行裁剪,得到第五文本段和第六文本段之后,具体用于:In an optional implementation manner, after the
在将所述第五文本段和所述待拼接文本段拼接后添加至所述文本容器中,所述文本容器的实时显示高度大于所述预设显示高度的情况下,将所述第五文本段作为所述目标文本进行裁剪,直至多次裁剪后,将最后裁剪得到的第七文本段和所述待拼接文本段拼接后添加至所述文本容器中的实时显示高度等于所述预设高度时停止;After the fifth text segment and the to-be-spliced text segment are spliced and added to the text container, and the real-time display height of the text container is greater than the preset display height, the fifth text segment is added to the text container. The segment is cropped as the target text, until after multiple cropping, the real-time display height added to the text container after splicing the seventh text segment obtained by the final cropping and the text segment to be spliced is equal to the preset height stop when
将所述第七文本段作为所述第四文本段。The seventh text segment is used as the fourth text segment.
一种可选的实施方式中,所述文本裁剪模块440对所述目标文本进行裁剪的过程中,具体用于:In an optional implementation manner, in the process of cutting the target text by the
针对每次裁剪得到的文本段,若所述文本段中第一个字符的排列序号和最后一个字符的排列序号相同,停止裁剪。For the text segment obtained by cutting each time, if the sequence number of the first character in the text segment is the same as the sequence number of the last character, the cropping is stopped.
一种可能的实施方式中,如图5中所示,所述文本显示装置400还包括字符检测模块460,所述字符检测模块460用于:In a possible implementation manner, as shown in FIG. 5 , the
检测所述待显示文本中的最后一个字符是否属于预先统计好的、不需要显示的特殊字符;Detecting whether the last character in the to-be-displayed text belongs to a pre-statistical special character that does not need to be displayed;
若是,将所述待显示文本中的最后一个字符裁剪掉,得到处理后的所述待显示文本。If so, the last character in the to-be-displayed text is cut out to obtain the processed to-be-displayed text.
本公开实例提出的文本显示装置,通过获取目标文本、用于显示所述目标文本的文本容器,以及所述文本容器在目标页面中显示文本的容器参数;基于所述容器参数,确定是否需要对所述目标文本进行裁剪;若需要对所述目标文本进行裁剪,确定针对所述目标文本的裁剪参数;基于所述裁剪参数以及所述目标文本中字符的排列序号,对所述目标文本进行至少一次裁剪,得到待显示文本;将得到的所述待显示文本添加至所述文本容器中,以在所述目标中显示所述待显示文本。The text display device proposed by the example of the present disclosure obtains the target text, the text container for displaying the target text, and the container parameter of the text container to display the text in the target page; based on the container parameter, it is determined whether it is necessary to The target text is cropped; if the target text needs to be cropped, the cropping parameters for the target text are determined; based on the cropping parameters and the sequence number of the characters in the target text, at least One cropping is performed to obtain the text to be displayed; the obtained text to be displayed is added to the text container to display the text to be displayed in the target.
这样,通过文本容器显示文本时的容器参数,以及针对目标文本的裁剪参数和目标文本中字符的排列序号,可以从目标文本中的相应位置对目标文本进行至少一次裁剪,从而可以大大减少文本裁剪的次数,降低文本处理时间,以提高文本处理的效率和速度,同时还会减少裁剪掉的元素的数量,以减少了机身内存的无效占用,以保证终端运行的流畅度。In this way, the target text can be clipped at least once from the corresponding position in the target text through the container parameters when the text container displays the text, the clipping parameters for the target text and the sequence number of the characters in the target text, thereby greatly reducing text clipping. It reduces the text processing time to improve the efficiency and speed of text processing, and also reduces the number of clipped elements to reduce the ineffective occupation of the fuselage memory to ensure the smoothness of the terminal operation.
关于装置中的各模块的处理流程、以及各模块之间的交互流程的描述可以参照上述方法实施例中的相关说明,这里不再详述。For the description of the processing flow of each module in the apparatus and the interaction flow between the modules, reference may be made to the relevant descriptions in the foregoing method embodiments, which will not be described in detail here.
对应于图1和图2中的文本显示方法,本公开实施例还提供了一种电子设备600,如图6所示,为本公开实施例提供的电子设备600结构示意图,包括:Corresponding to the text display methods in FIGS. 1 and 2 , an embodiment of the present disclosure further provides an electronic device 600 . As shown in FIG. 6 , a schematic structural diagram of the electronic device 600 provided by an embodiment of the present disclosure includes:
处理器610、存储器620、和总线630;存储器620用于存储执行指令,包括内存621和外部存储器622;这里的内存621也称内存储器,用于暂时存放处理器610中的运算数据,以及与硬盘等外部存储器622交换的数据,处理器610通过内存621与外部存储器622进行数据交换,当所述电子设备600运行时,所述处理器610与所述存储器620之间通过总线630通信,使得所述处理器610执行时可以执行图1和图2所示的方法实例中文本显示方法的步骤。The
本公开实施例还提供一种计算机可读存储介质,该计算机可读存储介质上存储有计算机程序,该计算机程序被处理器运行时执行上述方法实施例中所述的文本显示方法的步骤。其中,该存储介质可以是易失性或非易失的计算机可读取存储介质。Embodiments of the present disclosure further provide a computer-readable storage medium, where a computer program is stored on the computer-readable storage medium, and when the computer program is run by a processor, the steps of the text display method described in the above method embodiments are executed. Wherein, the storage medium may be a volatile or non-volatile computer-readable storage medium.
本公开实施例还提供一种计算机程序产品,该计算机程序产品承载有程序代码,所述程序代码包括的指令可用于执行上述方法实施例中所述的文本显示方法的步骤,具体可参见上述方法实施例,在此不再赘述。Embodiments of the present disclosure further provide a computer program product, where the computer program product carries program codes, and the instructions included in the program codes can be used to execute the steps of the text display methods described in the foregoing method embodiments. For details, please refer to the foregoing methods. The embodiments are not repeated here.
其中,上述计算机程序产品可以具体通过硬件、软件或其结合的方式实现。在一个可选实施例中,所述计算机程序产品具体体现为计算机存储介质,在另一个可选实施例中,计算机程序产品具体体现为软件产品,例如软件开发包(Software Development Kit,SDK)等等。Wherein, the above-mentioned computer program product can be specifically implemented by means of hardware, software or a combination thereof. In an optional embodiment, the computer program product is embodied as a computer storage medium, and in another optional embodiment, the computer program product is embodied as a software product, such as a software development kit (Software Development Kit, SDK), etc. Wait.
所属领域的技术人员可以清楚地了解到,为描述的方便和简洁,上述描述的系统和装置的具体工作过程,可以参考前述方法实施例中的对应过程,在此不再赘述。在本公开所提供的几个实施例中,应该理解到,所揭露的系统、装置和方法,可以通过其它的方式实现。以上所描述的装置实施例仅仅是示意性的,例如,所述单元的划分,仅仅为一种逻辑功能划分,实际实现时可以有另外的划分方式,又例如,多个单元或组件可以结合或者可以集成到另一个系统,或一些特征可以忽略,或不执行。另一点,所显示或讨论的相互之间的耦合或直接耦合或通信连接可以是通过一些通信接口,装置或单元的间接耦合或通信连接,可以是电性,机械或其它的形式。Those skilled in the art can clearly understand that, for the convenience and brevity of description, for the specific working process of the system and device described above, reference may be made to the corresponding process in the foregoing method embodiments, which will not be repeated here. In the several embodiments provided by the present disclosure, it should be understood that the disclosed system, apparatus and method may be implemented in other manners. The apparatus embodiments described above are only illustrative. For example, the division of the units is only a logical function division. In actual implementation, there may be other division methods. For example, multiple units or components may be combined or Can be integrated into another system, or some features can be ignored, or not implemented. On the other hand, the shown or discussed mutual coupling or direct coupling or communication connection may be through some communication interfaces, indirect coupling or communication connection of devices or units, which may be in electrical, mechanical or other forms.
所述作为分离部件说明的单元可以是或者也可以不是物理上分开的,作为单元显示的部件可以是或者也可以不是物理单元,即可以位于一个地方,或者也可以分布到多个网络单元上。可以根据实际的需要选择其中的部分或者全部单元来实现本实施例方案的目的。The units described as separate components may or may not be physically separated, and components displayed as units may or may not be physical units, that is, may be located in one place, or may be distributed to multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution in this embodiment.
另外,在本公开各个实施例中的各功能单元可以集成在一个处理单元中,也可以是各个单元单独物理存在,也可以两个或两个以上单元集成在一个单元中。In addition, each functional unit in each embodiment of the present disclosure may be integrated into one processing unit, or each unit may exist physically alone, or two or more units may be integrated into one unit.
所述功能如果以软件功能单元的形式实现并作为独立的产品销售或使用时,可以存储在一个处理器可执行的非易失的计算机可读取存储介质中。基于这样的理解,本公开的技术方案本质上或者说对现有技术做出贡献的部分或者该技术方案的部分可以以软件产品的形式体现出来,该计算机软件产品存储在一个存储介质中,包括若干指令用以使得一台计算机设备(可以是个人计算机,服务器,或者网络设备等)执行本公开各个实施例所述方法的全部或部分步骤。而前述的存储介质包括:U盘、移动硬盘、只读存储器(Read-OnlyMemory,ROM)、随机存取存储器(Random Access Memory,RAM)、磁碟或者光盘等各种可以存储程序代码的介质。The functions, if implemented in the form of software functional units and sold or used as stand-alone products, may be stored in a processor-executable non-volatile computer-readable storage medium. Based on this understanding, the technical solutions of the present disclosure can be embodied in the form of software products in essence, or the parts that make contributions to the prior art or the parts of the technical solutions. The computer software products are stored in a storage medium, including Several instructions are used to cause a computer device (which may be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the methods described in various embodiments of the present disclosure. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (Read-Only Memory, ROM), random access memory (Random Access Memory, RAM), magnetic disk or optical disk and other media that can store program codes.
最后应说明的是:以上所述实施例,仅为本公开的具体实施方式,用以说明本公开的技术方案,而非对其限制,本公开的保护范围并不局限于此,尽管参照前述实施例对本公开进行了详细的说明,本领域的普通技术人员应当理解:任何熟悉本技术领域的技术人员在本公开揭露的技术范围内,其依然可以对前述实施例所记载的技术方案进行修改或可轻易想到变化,或者对其中部分技术特征进行等同替换;而这些修改、变化或者替换,并不使相应技术方案的本质脱离本公开实施例技术方案的精神和范围,都应涵盖在本公开的保护范围之内。因此,本公开的保护范围应所述以权利要求的保护范围为准。Finally, it should be noted that the above-mentioned embodiments are only specific implementations of the present disclosure, and are used to illustrate the technical solutions of the present disclosure rather than limit them. The protection scope of the present disclosure is not limited thereto, although referring to the foregoing The embodiments describe the present disclosure in detail, and those skilled in the art should understand that: any person skilled in the art can still modify the technical solutions described in the foregoing embodiments within the technical scope disclosed by the present disclosure. Changes can be easily thought of, or equivalent replacements are made to some of the technical features; and these modifications, changes or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present disclosure, and should be covered in the present disclosure. within the scope of protection. Therefore, the protection scope of the present disclosure should be based on the protection scope of the claims.
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN202111644854.XACN114330232B (en) | 2021-12-29 | 2021-12-29 | A text display method, device, equipment and storage medium |
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN202111644854.XACN114330232B (en) | 2021-12-29 | 2021-12-29 | A text display method, device, equipment and storage medium |
| Publication Number | Publication Date |
|---|---|
| CN114330232Atrue CN114330232A (en) | 2022-04-12 |
| CN114330232B CN114330232B (en) | 2024-12-10 |
| Application Number | Title | Priority Date | Filing Date |
|---|---|---|---|
| CN202111644854.XAActiveCN114330232B (en) | 2021-12-29 | 2021-12-29 | A text display method, device, equipment and storage medium |
| Country | Link |
|---|---|
| CN (1) | CN114330232B (en) |
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN109740073A (en)* | 2018-11-26 | 2019-05-10 | 国云科技股份有限公司 | Image real-time processing system and method based on URL |
| CN112446218A (en)* | 2020-12-01 | 2021-03-05 | 平安科技(深圳)有限公司 | Long and short sentence text semantic matching method and device, computer equipment and storage medium |
| CN112560403A (en)* | 2019-09-26 | 2021-03-26 | 北京国双科技有限公司 | Text processing method and device and electronic equipment |
| CN112861648A (en)* | 2021-01-19 | 2021-05-28 | 平安科技(深圳)有限公司 | Character recognition method and device, electronic equipment and storage medium |
| CN113111624A (en)* | 2021-04-19 | 2021-07-13 | 北京字节跳动网络技术有限公司 | Text display method and device, electronic equipment and storage medium |
| CN113408241A (en)* | 2021-07-16 | 2021-09-17 | 网易(杭州)网络有限公司 | Text data processing method and device, electronic equipment and readable medium |
| CN113591827A (en)* | 2021-01-25 | 2021-11-02 | 腾讯科技(深圳)有限公司 | Text image processing method and device, electronic equipment and readable storage medium |
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN109740073A (en)* | 2018-11-26 | 2019-05-10 | 国云科技股份有限公司 | Image real-time processing system and method based on URL |
| CN112560403A (en)* | 2019-09-26 | 2021-03-26 | 北京国双科技有限公司 | Text processing method and device and electronic equipment |
| CN112446218A (en)* | 2020-12-01 | 2021-03-05 | 平安科技(深圳)有限公司 | Long and short sentence text semantic matching method and device, computer equipment and storage medium |
| CN112861648A (en)* | 2021-01-19 | 2021-05-28 | 平安科技(深圳)有限公司 | Character recognition method and device, electronic equipment and storage medium |
| CN113591827A (en)* | 2021-01-25 | 2021-11-02 | 腾讯科技(深圳)有限公司 | Text image processing method and device, electronic equipment and readable storage medium |
| CN113111624A (en)* | 2021-04-19 | 2021-07-13 | 北京字节跳动网络技术有限公司 | Text display method and device, electronic equipment and storage medium |
| CN113408241A (en)* | 2021-07-16 | 2021-09-17 | 网易(杭州)网络有限公司 | Text data processing method and device, electronic equipment and readable medium |
| Publication number | Publication date |
|---|---|
| CN114330232B (en) | 2024-12-10 |
| Publication | Publication Date | Title |
|---|---|---|
| CN108710613B (en) | Text similarity obtaining method, terminal device and medium | |
| CN111309825A (en) | Data clustering storage method and device and computer readable storage medium | |
| CN107704512B (en) | Financial product recommendation method based on social data, electronic device and medium | |
| EP2829990B1 (en) | Image search device, image search method, program, and computer-readable storage medium | |
| WO2019153612A1 (en) | Question and answer data processing method, electronic device and storage medium | |
| EP2833275B1 (en) | Image search device, image search method, program, and computer-readable storage medium | |
| EP2143021A1 (en) | Text-content features | |
| CN106601256B (en) | Voice recognition method and mobile terminal | |
| CN112732893A (en) | Text information extraction method and device, storage medium and electronic equipment | |
| CN110807213A (en) | Method and related device for constructing three-dimensional BIM model elevation map | |
| CN110599899A (en) | Label display method and device, electronic equipment and storage medium | |
| CN113111624A (en) | Text display method and device, electronic equipment and storage medium | |
| CN113836462A (en) | Method, device, device and storage medium for generating page description file | |
| US20130322759A1 (en) | Method and device for identifying font | |
| CN114969385B (en) | Knowledge graph optimization method and device based on document attribute assignment entity weight | |
| EP2637109A1 (en) | Method for improving rendering speed of browser page | |
| CN114330232A (en) | Text display method, device, equipment and storage medium | |
| CN114239505A (en) | Method, device and equipment for cleaning hidden characters in word document | |
| CN112861504A (en) | Text interaction method, device, equipment, storage medium and program product | |
| CN112464618A (en) | Method and device for paging document data, storage medium and electronic equipment | |
| CN106682243A (en) | Browsing method and device | |
| CN113407684A (en) | Article originality checking method, article originality checking device and storage medium | |
| CN114239562A (en) | Method, device and equipment for identifying program code blocks in document | |
| US9483463B2 (en) | Method and system for motif extraction in electronic documents | |
| CN114911921A (en) | A text content display method, device, computer equipment and storage medium |
| Date | Code | Title | Description |
|---|---|---|---|
| PB01 | Publication | ||
| PB01 | Publication | ||
| SE01 | Entry into force of request for substantive examination | ||
| SE01 | Entry into force of request for substantive examination | ||
| CB02 | Change of applicant information | ||
| CB02 | Change of applicant information | Address after:100041 B-0035, 2 floor, 3 building, 30 Shixing street, Shijingshan District, Beijing. Applicant after:Douyin Vision Co.,Ltd. Address before:100041 B-0035, 2 floor, 3 building, 30 Shixing street, Shijingshan District, Beijing. Applicant before:Tiktok vision (Beijing) Co.,Ltd. Address after:100041 B-0035, 2 floor, 3 building, 30 Shixing street, Shijingshan District, Beijing. Applicant after:Tiktok vision (Beijing) Co.,Ltd. Address before:100041 B-0035, 2 floor, 3 building, 30 Shixing street, Shijingshan District, Beijing. Applicant before:BEIJING BYTEDANCE NETWORK TECHNOLOGY Co.,Ltd. | |
| GR01 | Patent grant | ||
| GR01 | Patent grant |