Text line margin adjusting method and device and nonvolatile storage medium
By identifying and adjusting edge characters of text lines, creating range elements to eliminate line edge blanks, solving the layout problem caused by the browser to add extra blanks at the end of the line, improving the visual effect and user experience of the text.
Patent Information
- Application Number
- CN202510442121.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-09
- Publication Date
- 2025-07-22
Smart Images

Figure CN120354826A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular, to a method, apparatus, and non-volatile storage medium for adjusting the margins of text lines. Background Art
[0002] In current front-end development, the adjustment of character spacing (letter-spacing) is a common typesetting requirement, especially playing an important role in precisely controlling text alignment, enhancing visual effects, and design aesthetics. However, when actually rendering, mainstream browsers (such as Chrome, Firefox, Safari) usually add extra whitespace after the last character of each text line, especially prominent in right-aligned layouts or RTL (right-to-left) languages. Developers often rely on CSS to adjust character spacing, but due to the incomplete consistency between browser implementations and specifications, the extra whitespace at the end of the text can lead to misaligned and unaesthetic typesetting, and even cause text dislocation problems.
[0003] In view of the above problems, no effective solution has been proposed yet. Summary of the Invention
[0004] Embodiments of the present invention provide a method, apparatus, and non-volatile storage medium for adjusting the margins of text lines, so as to at least solve the technical problem that currently browsers usually add extra whitespace at the end of a line, resulting in unnecessary white space at the text edge during typesetting and affecting the visual effect.
[0005] According to one aspect of the embodiments of the present invention, a method for adjusting the margins of text lines is provided, including: obtaining an initial text line in a target page, where the initial text line is a text line with whitespace at the line edge; based on a preset starting point, identifying the rectangle information of each character in the initial text line one by one and comparing the rectangle information corresponding to the currently identified character with the rectangle information corresponding to the previously identified character; in the case where the rectangle information corresponding to the currently identified character does not match the rectangle information corresponding to the previously identified character, determining the previously identified character as the edge character in the initial text line; creating a range element based on the edge character; and adjusting the margin of the initial text line based on the range element to obtain a target text line, where the target text line is the initial text line with the whitespace at the line edge removed.
[0006] Optionally, based on the range element, adjust the margin of the initial text line to obtain a target text line, including: splitting the initial text line based on the positions of the edge characters to obtain a plurality of text nodes, where the plurality of text nodes include text nodes corresponding to the line edge blanks and text nodes corresponding to the edge characters; inserting the range element between the text node corresponding to the edge character and the text node corresponding to the line edge blank; adjusting the margin of the initial text line by adjusting the line margin corresponding to the range element to obtain the target text line.
[0007] Optionally, inserting the range element between the text node corresponding to the edge character and the text node corresponding to the line edge blank includes: obtaining the character index corresponding to the edge character; based on the character index, inserting the range element between the text node corresponding to the edge character and the text node corresponding to the line edge blank.
[0008] Optionally, adjusting the margin of the initial text line by adjusting the line margin corresponding to the range element to obtain the target text line includes: determining a margin adjustment value according to the text node corresponding to the line edge blank; adjusting the margin of the initial text line by adjusting the line margin corresponding to the range element to a negative value according to the margin adjustment value to obtain the target text line.
[0009] Optionally, the rectangle information includes the distance of the corresponding character from the upper edge of the target page.
[0010] Optionally, in the Vue framework, set a custom directive; based on the custom directive, start to identify the rectangle information in the initial text line character by character.
[0011] According to another aspect of the embodiments of the present invention, there is also provided an apparatus for adjusting the margin of a text line, including: an acquisition module, configured to acquire an initial text line in a target page, where the initial text line is a text line with blanks at the line edges; an identification module, configured to identify the rectangle information in the initial text line character by character based on a preset starting point and compare the rectangle information corresponding to the currently identified character with the rectangle information corresponding to the previous identified character; a determination module, configured to determine the previous identified character as an edge character in the initial text line when the rectangle information corresponding to the currently identified character does not match the rectangle information corresponding to the previous identified character; a creation module, configured to create a range element based on the edge character; an adjustment module, configured to adjust the margin of the initial text line based on the range element to obtain a target text line, where the target text line is the initial text line with the line edge blanks removed.
[0012] According to still another aspect of the embodiments of the present invention, there is also provided a non-volatile storage medium, where the non-volatile storage medium includes a stored program, and when the program runs, it controls the device where the non-volatile storage medium is located to execute any one of the above text line margin adjustment methods.
[0013] According to another aspect of the embodiments of the present invention, a computer device is further provided. The computer device includes a processor for running a program, and when the program runs, it executes the method for adjusting the text line margin in any one of the above.
[0014] According to another aspect of the embodiments of the present invention, a computer program product is further provided, including a computer program which, when executed by a processor, implements the method for adjusting the text line margin in any one of the above.
[0015] In the embodiments of the present invention, by adopting the method for adjusting the text line margin, the initial text lines in the target page are obtained, where the initial text lines are the text lines with blanks at the line edges; based on a preset starting point, the rectangular information in the initial text lines is recognized character by character and the rectangular information corresponding to the currently recognized character is compared with the rectangular information corresponding to the previous recognized character; in the case where the rectangular information corresponding to the currently recognized character does not match the rectangular information corresponding to the previous recognized character, the previous recognized character is determined as the edge character in the initial text line; based on the edge character, a range element is created; based on the range element, the margin of the initial text line is adjusted to obtain the target text line, where the target text line is the initial text line with the blanks at the line edges removed, achieving the purpose of adjusting the blanks at the line edges, thereby realizing the technical effect of improving the visual effect of the page text, and further solving the technical problem that currently browsers usually add extra blanks at the end of the line, resulting in unnecessary white spaces at the text edges during typesetting and affecting the visual effect. BRIEF DESCRIPTION OF THE DRAWINGS
[0016] The drawings described herein are used to provide a further understanding of the present invention and constitute a part of this application. The schematic embodiments of the present invention and their descriptions are used to explain the present invention and do not constitute an improper limitation to the present invention. In the drawings:
[0017] Figure 1 shows a hardware structure block diagram of a computer terminal for implementing the method for adjusting the text line margin;
[0018] Figure 2 is a flowchart of the method for adjusting the text line margin provided by the embodiments of the present invention;
[0019] Figure 3 is a schematic diagram of the initial text line and the target text line provided by an optional embodiment of the present invention;
[0020] Figure 4 is a structure block diagram of the device for adjusting the text line margin provided by the embodiments of the present invention. DETAILED DESCRIPTION OF THE EMBODIMENTS
[0021] In order to enable those skilled in the art to better understand the solution of the present invention, the technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are only a part of the embodiments of the present invention, rather than all the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those of ordinary skill in the art without making creative efforts shall fall within the protection scope of the present invention.
[0022] It should be noted that the terms "first", "second", etc. in the specification and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects, and do not necessarily need to describe a specific order or sequence. It should be understood that such data can be interchanged under appropriate circumstances so that the embodiments of the present invention described herein can be implemented in an order different from those illustrated or described herein. In addition, the terms "comprising" and "having" and any variations thereof are intended to cover non-exclusive inclusion. For example, a process, method, system, product or device comprising a series of steps or units does not necessarily have to be limited to those steps or units clearly listed, but may include other steps or units not clearly listed or inherent to these processes, methods, products or devices.
[0023] According to an embodiment of the present invention, a method embodiment for adjusting the text line margin is provided. It should be noted that the steps shown in the flowchart of the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions. And although the logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in an order different from that here.
[0024] The method embodiment provided in the first embodiment of the present application can be executed in a mobile terminal, a computer terminal or a similar computing device. Figure 1 A hardware structure block diagram of a computer terminal for implementing the method for adjusting the text line margin is shown. As Figure 1 shown, the computer terminal 10 may include one or more processors (processors may include, but are not limited to, processing devices such as a microprocessor MCU or a programmable logic device FPGA, etc., shown as 102a, 102b,..., 102n in the figure) and a memory 104 for storing data. In addition, it may further include: a display, an input / output interface (I / O interface), a universal serial bus (USB) port (which may be included as one of the ports of the BUS bus), a network interface, a power supply, and / or a camera. Those of ordinary skill in the art can understand that Figure 1 the structure shown is only schematic and does not limit the structure of the above-mentioned electronic device. For example, the computer terminal 10 may further include more or fewer components than Figure 1 shown therein, or have a structure different from thatFigure 1 The different configurations shown.
[0025] It should be noted that one or more of the above-mentioned processors and / or other data processing circuits can generally be referred to as "data processing circuits" herein. The data processing circuit can be embodied in software, hardware, firmware, or any combination thereof, in whole or in part. In addition, the data processing circuit can be a single independent processing module, or be incorporated in whole or in part into any one of other elements in the computer terminal 10. As involved in the embodiments of the present application, the data processing circuit is a kind of processor control (such as the selection of a variable resistor terminal path connected to an interface).
[0026] The memory 104 can be used to store software programs and modules of application software, such as the program instructions / data storage devices corresponding to the method for adjusting the text line margin in the embodiments of the present invention. The processor executes various functional applications and data processing by running the software programs and modules stored in the memory 104, that is, implements the method for adjusting the text line margin of the above application program. The memory 104 can include a high-speed random access memory, and can also include a non-volatile memory, such as one or more magnetic storage devices, flash memories, or other non-volatile solid-state memories. In some instances, the memory 104 can further include a memory remotely set relative to the processor, and these remote memories can be connected to the computer terminal 10 through a network. Examples of the above network include but are not limited to the Internet, enterprise intranets, local area networks, mobile communication networks, and combinations thereof.
[0027] The display can be, for example, a touch-screen liquid crystal display (LCD), which enables the user to interact with the user interface of the computer terminal 10.
[0028] Figure 2 is a schematic flowchart of the method for adjusting the text line margin provided according to the embodiments of the present invention, as Figure 2 shown, the method includes the following steps:
[0029] Step S202, obtain the initial text lines in the target page, where the initial text lines are the text lines with blanks at the line edges.
[0030] In this step, when the browser processes the character spacing, it usually adds extra blanks at the end of the line, which does not conform to the behavior expected by the specification, resulting in unnecessary white spaces at the text edges during typesetting. The initial text lines in the page can be obtained, that is, the text lines with white spaces.
[0031] Step S204, based on a preset starting point, identify the rectangular information in the initial text line character by character and compare the rectangular information corresponding to the current identified character with the rectangular information corresponding to the previous identified character.
[0032] In this step, the starting point can be the first character from left to right in the initial text line. Starting from the starting point, the rectangular information in the initial text line can be recognized character by character. Among them, the rectangular information can be the top attribute of the rectangle. While recognizing, the rectangular information corresponding to the currently recognized character can be compared with the rectangular information corresponding to the previous recognized character to determine whether the edge character, that is, the last character of the line, has been recognized. For example, a Range object can be created. This object will be used to select and analyze text in the DOM. Set the starting point of the Range object to the starting position of the target element, and use the getClientRects() method to obtain the character rectangular information within the current Range selection. Since the initial selection range of the Range only contains the first character, getClientRects() will return a ClientRect object containing the position information of this character. Through a loop, move the end point of the Range one character backward each time, and obtain new rectangular information for comparison after each move. Check the left attribute of each newly obtained character rectangular information. When the left value changes significantly, it means that the Range has moved from the character at the beginning of the line to the next character. Therefore, the previous recognized character is the edge character at the beginning of the line. Check the right attribute of each newly obtained character rectangular information. When the right value is no longer aligned with the right boundary of the element, it means that the Range has moved from the character at the end of the line to a new layout position. In this case, the previous recognized character is the edge character at the end of the line.
[0033] As an optional embodiment, the rectangular information includes the distance of the corresponding character from the upper edge of the target page.
[0034] Optionally, in front-end development and web page layout, Rectangle Information usually refers to the geometric position and size information of web page elements or text fragments on the screen obtained through the API provided by the browser.
[0035] The most common methods to obtain rectangular information are through getBoundingClientRect or getClientRects. The objects returned by these methods contain the following key attributes:
[0036] top: The distance from the upper edge of the element or text fragment to the upper edge of the viewport, that is, the distance of the corresponding character from the upper edge of the target page.
[0037] left: The distance from the left edge of the element or text fragment to the left edge of the viewport.
[0038] bottom: The distance from the lower edge of the element or text fragment to the upper edge of the viewport.
[0039] right: The distance from the right edge of the element or text segment to the left edge of the viewport.
[0040] width: The width of the element or text segment.
[0041] height: The height of the element or text segment.
[0042] Step S206, in the case where the rectangle information corresponding to the currently recognized character does not match the rectangle information corresponding to the previous recognized character, determine that the previous recognized character is the edge character in the initial text line.
[0043] In this step, in the case where the rectangle information corresponding to the currently recognized character does not match the rectangle information corresponding to the previous recognized character, it is considered that the currently recognized character is no longer a character in the previous line of text. Therefore, it can be considered that the previous recognized character is the edge character in the initial text line.
[0044] The rectangle information is usually obtained through the getClientRects() method of the Range object. The Range object allows you to select a part of the text and obtain the layout information of this part of the text, including its position and size on the screen. After moving the end point of the Range each time, calling getClientRects() can obtain the character rectangle information within the current selection range. In the case where the initial text line is horizontal, it can be considered that the distance from the characters within the line to the upper edge of the page should be the same, while the distances from the characters in different lines to the upper edge of the page are different. Therefore, the top property of the rectangle information of the current character can be compared with the top property of the rectangle information of the previous character. If the top properties of the two are significantly different, this usually indicates that the Range has moved from the characters in the initial text line to the characters in the next line. Therefore, the previous recognized character is the edge character in the initial text line.
[0045] Step S208, create a range element based on the edge character.
[0046] In this step, after the position of the edge character is determined, a new HTML inline element can be created at the corresponding position, such as , that is, a range element. This can use DOM operations, such as the insertBefore or insertAfter methods, to insert the newly created HTML element into the target position. Ensure that the insertion of the new element does not disrupt the original text flow and layout. For the created range element, desired effects can be achieved by applying specific styles, such as negative margin, opacity, color, or other CSS properties. For example, if the purpose is to compensate for the extra whitespace at the end of a line, for Set a negative right margin for the element to move it to the left and eliminate the extra whitespace. If the page is dynamic, i.e., the text content or style may change over time, you can also set a listener or a timer to recreate and adjust the position and style of the range element when the position of the edge characters changes.
[0047] Through the above steps, when dealing with issues such as text layout, character spacing, and text alignment, the rendering effect of the text can be more finely controlled, which is extremely useful especially when dealing with the differences between browser default behaviors and design requirements. This method can not only solve typesetting problems but also enhance the visual aesthetics and user experience of the page.
[0048] Step S210: Based on the range element, adjust the margin of the initial text line to obtain the target text line, where the target text line is the initial text line with the line-edge whitespace removed.
[0049] In this step, according to the range element, the margin corresponding to the range element can be adjusted, and then the margin of the initial text line can be adjusted to obtain the target text line. Specifically, when the position of the line-edge whitespace is determined, the splitting function can be used to separate the text node containing the whitespace from the rest of the text content at the end of the line. This step is to more finely control the layout and style of the whitespace part. Insert a range element between the line-end whitespace and the normal text content (such as ) This element will be used to carry out style adjustments for the line edge whitespace, such as negative right margins, to offset the extra whitespace automatically added by the browser during rendering. Based on the recognized width of the line edge whitespace, set the margin-right of the compensation element to a negative value to eliminate the redundant whitespace. This adjustment ensures that the text lines closely adhere to the container boundary, removing the extra whitespace at the end of the line, thus obtaining the target text lines.
[0050] By precisely controlling the line edge whitespace, the precision of text layout in complex layout scenarios can be significantly improved, enabling the text to closely adhere to the container boundary and enhancing the visual effect. Different browsers may handle text layout slightly differently. By leveraging the Range object and the strategy of dynamically adjusting margins, these differences can be effectively addressed to ensure consistent text layout effects across various browsers.
[0051] Through the above technical features, it is possible to precisely control the margins of the initial text lines in the Vue framework by using the Range object and the dynamic margin adjustment of the range elements, eliminate the line edge whitespace, and obtain target text lines with a more aesthetically pleasing and precise layout. This method is particularly effective for handling layout issues of multi-line text, right-aligned text, or RTL languages, and can significantly enhance the visual quality of text layout and the user experience.
[0052] Through the above steps, the margins of the text lines can be effectively adjusted, the line edge whitespace can be eliminated, and the target text lines can be obtained. This has important application value for scenarios that require strict control of text position and spacing, such as typeset-dense documents, precisely aligned lists or tables, etc.
[0053] Figure 3 is a schematic diagram of the initial text lines and target text lines provided according to an alternative embodiment of the present invention, as Figure 3 shown. The upper line is the initial text line before compensation, and the lower line is the target text line after compensation.
[0054] Through the above steps, the purpose of adjusting the line edge whitespace is achieved, thereby realizing the technical effect of improving the visual effect of the page text, and further solving the technical problem that current browsers usually add extra whitespace at the end of the line, resulting in unnecessary white space at the text edge during typesetting and affecting the visual effect.
[0055] As an alternative embodiment, based on the range element, the margins of the initial text line are adjusted to obtain the target text line, including: splitting the initial text line based on the positions of the edge characters to obtain a plurality of text nodes, where the plurality of text nodes include text nodes corresponding to the line edge blanks and text nodes corresponding to the edge characters; inserting the range element between the text nodes corresponding to the edge characters and the text nodes corresponding to the line edge blanks; and adjusting the margins of the initial text line by adjusting the line margins corresponding to the range element to obtain the target text line.
[0056] Optionally, after the positions of the edge characters are determined, the text node splitting technique of the DOM can be used to split the initial text line into multiple text nodes. These text nodes include: text nodes corresponding to the line edge blanks, i.e., the blank parts at the beginning or end of the line. Text nodes corresponding to the edge characters, i.e., the text nodes containing the edge characters. By splitting, these nodes can be processed separately to eliminate the edge blanks. In the split text nodes, a new range element is inserted (such as or )。This element will be placed between the text node corresponding to the edge character and the text node corresponding to the line edge whitespace. The purpose of doing this is to be able to control and adjust the layout of these edge characters individually, especially by modifying the margins of the range element to eliminate the whitespace. For the inserted range element, by modifying its CSS margin property, the layout of the entire text line can be adjusted. Specifically: For the range element inserted before the edge character at the beginning of the line, a negative margin-left property can be set to move the edge character to the left and offset the whitespace at the beginning of the line. For the range element inserted after the edge character at the end of the line, a negative margin-right property can be set to offset the whitespace at the end of the line to the right, making the text fit more closely to the container boundary. After the above steps, each text line will be adjusted to remove the line edge whitespace and fit closely to the container boundary. After such processing, the original "initial text line" containing whitespace is transformed into the "target text line", that is, the text line layout without line edge whitespace.
[0057] Through the above technical features, the text layout can be precisely controlled, the line edge whitespace can be eliminated, and the visual effect and user experience of the page can be improved. This method is not only applicable to static text but also can adapt to dynamically changing text content, ensuring that the text line can achieve an ideal layout effect in any case.
[0058] As an alternative embodiment, inserting the range element between the text node corresponding to the edge character and the text node corresponding to the line edge whitespace includes: obtaining the character index corresponding to the edge character; based on the character index, inserting the range element between the text node corresponding to the edge character and the text node corresponding to the line edge whitespace.
[0059] Optionally, after determining the edge characters of the initial text line, the character indices corresponding to the edge characters can be stored. The character index refers to the position of the character in the text string of the text node, starting from 0. This step is crucial for inserting the range element because it determines the exact position where the element is inserted. Based on the character indices of the edge characters, a range element is inserted in the DOM. Specifically, using DOM manipulation methods such as splitText() and insertBefore() or insertAfter(), the range element is placed between the text node containing the edge characters and the text node containing the line edge whitespace. Specifically, the splitText() method can be used to split the text node containing the edge characters into two parts: from the start to before the edge character, and from the edge character to the end of the text node. Between the split text nodes, the range element is inserted using the insertBefore() or insertAfter() method. If the range element needs to be placed after the edge character, it will be inserted before the new text node after splitting; if it needs to be placed before the edge character, it will be inserted after the text node before splitting. After inserting the range element, the whitespace at the line edge is compensated by modifying its style properties such as margin, padding, or width. This usually includes applying a negative margin to offset the whitespace, or adjusting the width of the element to ensure a seamless connection with the text flow.
[0060] By inserting a range element between the edge characters and the whitespace, the layout of the text line can be precisely controlled, eliminating unnecessary edge whitespace, enhancing the visual effect, and also avoiding the disruption of the text layout caused by redundant whitespace elements.
[0061] Through the above technical features, the text layout in the page can be effectively adjusted, removing the whitespace at the line edges, making the text presentation more precise, enhancing the visual beauty and user experience of the page. This technology is particularly useful when dealing with complex layouts and character spacing adjustments.
[0062] As an optional embodiment, adjusting the line margin of the initial text line by adjusting the line margin corresponding to the range element to obtain the target text line includes: determining the margin adjustment value according to the text node corresponding to the line edge whitespace; adjusting the line margin corresponding to the range element to a negative value according to the margin adjustment value to adjust the line margin of the initial text line and obtain the target text line.
[0063] Optionally, the margin adjustment value can be determined according to the width corresponding to the line edge blank. Adjust the line margin corresponding to the range element according to the margin adjustment value to a negative value to compensate for this part of the blank. Specifically, the width of the edge blank can be calculated and this width can be set as the negative right margin (margin - right) of the compensation element. For example, if the line - end blank is 10px, then the margin - right of the compensation element will be set to - 10px. This step ensures that the line - end blank of the initial text line is accurately compensated, resulting in the target text line. For an element containing multiple lines of text, the above steps need to be repeated for each line to ensure that the line - end blanks of all lines are accurately adjusted. This may involve traversing the DOM tree of the entire text container to identify the end of each line and the edge blank, then inserting a compensation element at the end of each line and setting the corresponding negative margin.
[0064] By inserting a compensation element with a negative margin at the line end, the layout of the text can be precisely controlled, the line edge blank can be eliminated, ensuring that the text closely adheres to the container boundary, enhancing the aesthetics and layout consistency of the page. And this method can dynamically adapt to changes in the text content. When the text increases or decreases, the negative margin of the compensation element will be automatically adjusted according to the new line - end blank to maintain the typesetting accuracy.
[0065] Through the above - mentioned technical features and implementation steps, it is possible to effectively control the layout of text lines, eliminate line edge blanks, achieve the precise layout effect of the target text line, and enhance the visual aesthetics and user experience of the page. This method is particularly useful when dealing with complex text layouts and dense typesetting scenarios.
[0066] As an optional embodiment, in the Vue framework, set a custom directive; based on the custom directive, start to identify the rectangular information in the initial text line character by character.
[0067] Optionally, in the Vue framework, custom directives are directives that developers can customize and bind to DOM elements. They allow developers to add custom behaviors to HTML elements, such as responding to changes in element states, operating on the DOM structure or styles, etc. Defining a custom directive, such as v - fix - letter - spacing, can allow you to add specific logic in the DOM element to handle the problems of character spacing and line edge blanks. Custom directives provide multiple hook functions for performing corresponding operations at different stages. For example, the inserted hook will be executed immediately after the directive is bound to the DOM element. These hook functions can be used to trigger the analysis and processing of the text line layout to ensure that the character spacing and line edge blanks are adjusted immediately after the DOM element is rendered.
[0068] By implementing the above technical key points, custom directives in the Vue framework can effectively handle text layout problems, especially the adjustment of character spacing and line edge whitespace. This method not only simplifies the code but also improves the accuracy and responsiveness of text layout, ensuring consistent and aesthetic presentation of text across different devices and browsers.
[0069] It should be noted that for the foregoing method embodiments, for the sake of simple description, they are all expressed as a series of action combinations. However, those skilled in the art should know that the present invention is not limited by the described action sequence, because according to the present invention, certain steps can be performed in other sequences or simultaneously. Secondly, those skilled in the art should also know that the embodiments described in the specification are all preferred embodiments, and the actions and modules involved are not necessarily essential to the present invention.
[0070] Through the description of the above embodiments, those skilled in the art can clearly understand that the method for adjusting the text line margin according to the above embodiments can be implemented by means of software plus a necessary general hardware platform. Of course, it can also be implemented by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disc) and includes several instructions for causing a terminal device (which can be a mobile phone, computer, server, or network device, etc.) to execute the methods described in various embodiments of the present invention.
[0071] According to an embodiment of the present invention, there is also provided a text line margin adjustment device for implementing the above text line margin adjustment method. Figure 4 It is a structural block diagram of the text line margin adjustment device provided according to an embodiment of the present invention, as Figure 4 shown. The text line margin adjustment device includes: an acquisition module 402, an identification module 404, a determination module 406, a creation module 408, and an adjustment module 410. The text line margin adjustment device will be described below.
[0072] The acquisition module 402 is used to acquire the initial text line in the target page, where the initial text line is a text line with whitespace at the line edge.
[0073] The identification module 404, which is connected to the acquisition module 402, is used to identify the rectangular information in the initial text line character by character based on a preset starting point and compare the rectangular information corresponding to the currently identified character with the rectangular information corresponding to the previous identified character.
[0074] A determination module 406, connected to the recognition module 404, is configured to determine that the previous recognized character is an edge character in the initial text line when the rectangular information corresponding to the currently recognized character does not match the rectangular information corresponding to the previous recognized character.
[0075] A creation module 408, connected to the determination module 406, is configured to create a range element based on the edge character.
[0076] An adjustment module 410, connected to the creation module 408, is configured to adjust the margins of the initial text line based on the range element to obtain a target text line, where the target text line is the initial text line with the blank spaces at the line edges removed.
[0077] Optionally, the adjustment module is configured to adjust the margins of the initial text line based on the range element to obtain a target text line, including: a splitting unit configured to split the initial text line based on the position of the edge character to obtain a plurality of text nodes, where the plurality of text nodes include text nodes corresponding to the blank spaces at the line edges and text nodes corresponding to the edge characters; an insertion unit configured to insert the range element between the text nodes corresponding to the edge characters and the text nodes corresponding to the blank spaces at the line edges; and an adjustment unit configured to adjust the margins of the initial text line by adjusting the line margins corresponding to the range element to obtain a target text line.
[0078] Optionally, the insertion unit is configured to insert the range element between the text nodes corresponding to the edge characters and the text nodes corresponding to the blank spaces at the line edges, including: an acquisition subunit configured to acquire the character index corresponding to the edge character; and an insertion subunit configured to insert the range element between the text nodes corresponding to the edge characters and the text nodes corresponding to the blank spaces at the line edges based on the character index.
[0079] Optionally, the adjustment unit is configured to adjust the margins of the initial text line by adjusting the line margins corresponding to the range element to obtain a target text line, including: a determination subunit configured to determine a margin adjustment value based on the text nodes corresponding to the blank spaces at the line edges; and an adjustment subunit configured to adjust the margins of the initial text line by adjusting the line margins corresponding to the range element to a negative value according to the margin adjustment value to obtain a target text line.
[0080] Optionally, the rectangular information includes the distance of the corresponding character from the upper edge of the target page.
[0081] Optionally, the above device further includes a setting module configured to set a custom directive in the Vue framework; and the recognition module is further configured to start recognizing the rectangular information in the initial text line character by character based on the custom directive.
[0082] It should be noted here that the above-mentioned acquisition module 402, recognition module 404, determination module 406, creation module 408, and adjustment module 410 correspond to steps S202 to S210 in the embodiment. The instances and application scenarios implemented by the multiple modules and the corresponding steps are the same, but are not limited to the content disclosed in the above embodiment. It should be noted that the above modules, as part of the device, can run in the computer terminal 10 provided in the embodiment.
[0083] Embodiments of the present invention can provide a computer device. Optionally, in this embodiment, the above computer device can be located in at least one of multiple network devices in a computer network. The computer device includes a memory and a processor.
[0084] Among them, the memory can be used to store software programs and modules, such as the program instructions / modules corresponding to the text line margin adjustment method and device in the embodiments of the present invention. The processor executes various functional applications and data processing by running the software programs and modules stored in the memory, that is, implements the above-mentioned text line margin adjustment method. The memory can include a high-speed random access memory, and can also include a non-volatile memory, such as one or more magnetic storage devices, flash memories, or other non-volatile solid-state memories. In some instances, the memory can further include a memory remotely set relative to the processor, and these remote memories can be connected to the computer terminal through a network. Examples of the above network include but are not limited to the Internet, enterprise intranet, local area network, mobile communication network, and their combinations.
[0085] The processor can call the information and application programs stored in the memory through a transmission device to execute the following steps: obtain an initial text line in a target page, where the initial text line is a text line with blanks at the line edges; based on a preset starting point, identify the rectangular information in the initial text line character by character and compare the rectangular information corresponding to the current identified character with the rectangular information corresponding to the previous identified character; in the case where the rectangular information corresponding to the current identified character does not match the rectangular information corresponding to the previous identified character, determine the previous identified character as the edge character in the initial text line; create a range element based on the edge character; adjust the margin of the initial text line based on the range element to obtain a target text line, where the target text line is the initial text line with the blanks at the line edges removed.
[0086] By adopting the embodiment of the present invention, a method for adjusting the margin of a text line is provided. The method includes: obtaining an initial text line in a target page, where the initial text line is a text line with blanks at the line edges; based on a preset starting point, identifying the rectangle information of each character in the initial text line one by one and comparing the rectangle information corresponding to the currently identified character with the rectangle information corresponding to the previously identified character; when the rectangle information corresponding to the currently identified character does not match the rectangle information corresponding to the previously identified character, determining the previously identified character as an edge character in the initial text line; creating a range element based on the edge character; and adjusting the margin of the initial text line based on the range element to obtain a target text line, where the target text line is the initial text line with the blanks at the line edges removed. This achieves the purpose of adjusting the blanks at the line edges, thereby realizing the technical effect of improving the visual effect of the page text, and further solving the technical problem that currently browsers usually add extra blanks at the end of a line, resulting in unnecessary white spaces at the text edges during typesetting and affecting the visual effect.
[0087] Those of ordinary skill in the art can understand that all or part of the steps in the various methods of the above embodiments can be completed by instructing the relevant hardware of the terminal device through a program. The program can be stored in a non-volatile storage medium, and the storage medium can include: a flash drive, a read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disc, etc.
[0088] The embodiment of the present invention also provides a non-volatile storage medium. Optionally, in this embodiment, the non-volatile storage medium can be used to store the program code executed by the method for adjusting the margin of the text line provided in the above embodiment.
[0089] Optionally, in this embodiment, the non-volatile storage medium can be located in any one of the computer terminals in a computer terminal group in a computer network, or in any one of the mobile terminals in a mobile terminal group.
[0090] Optionally, in this embodiment, the non-volatile storage medium is set to store the program code for performing the following steps: obtaining an initial text line in a target page, where the initial text line is a text line with blanks at the line edges; based on a preset starting point, identifying the rectangle information of each character in the initial text line one by one and comparing the rectangle information corresponding to the currently identified character with the rectangle information corresponding to the previously identified character; when the rectangle information corresponding to the currently identified character does not match the rectangle information corresponding to the previously identified character, determining the previously identified character as an edge character in the initial text line; creating a range element based on the edge character; and adjusting the margin of the initial text line based on the range element to obtain a target text line, where the target text line is the initial text line with the blanks at the line edges removed.
[0091] An embodiment of the present invention further provides a computer program product, including a computer program. Optionally, in this embodiment, when the computer program is executed by a processor, it can implement: obtaining an initial text line in a target page, where the initial text line is a text line with blanks at the line edges; based on a preset starting point, identifying rectangular information in the initial text line character by character and comparing the rectangular information corresponding to the current identified character with the rectangular information corresponding to the previous identified character; in the case where the rectangular information corresponding to the current identified character does not match the rectangular information corresponding to the previous identified character, determining that the previous identified character is an edge character in the initial text line; creating a range element based on the edge character; and adjusting the margin of the initial text line based on the range element to obtain a target text line, where the target text line is the initial text line with the blanks at the line edges removed.
[0092] The serial numbers of the above embodiments of the present invention are only for description and do not represent the advantages or disadvantages of the embodiments.
[0093] In the above embodiments of the present invention, the descriptions of the various embodiments have their own emphases. For parts not detailed in a certain embodiment, reference may be made to the relevant descriptions of other embodiments.
[0094] In several embodiments provided in the present application, it should be understood that the disclosed technical content can be implemented in other ways. Among them, the device embodiments described above are only illustrative. For example, the division of the units can be a logical function division. In actual implementation, there can be other division methods. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the couplings or direct couplings or communication connections shown or discussed with each other can be through some interfaces. The indirect couplings or communication connections of the units or modules can be in an electrical or other form.
[0095] The units described as separate components may or may not be physically separated. The components shown as units may or may not be physical units, that is, they can be located in one place or distributed to multiple units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0096] In addition, in each embodiment of the present invention, the functional units can be integrated in a processing unit, or each unit can exist physically alone, or two or more units can be integrated in one unit. The above integrated units can be implemented in the form of hardware or in the form of software functional units.
[0097] When the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a non-volatile storage medium. Based on this understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. The computer software product is stored in a storage medium and includes several instructions for causing a computer device (which can be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present invention. The foregoing storage medium includes: various media that can store program codes, such as USB flash drives, read-only memories (ROMs), random access memories (RAMs), mobile hard disks, magnetic disks, or optical discs.
[0098] The foregoing are only the preferred embodiments of the present invention. It should be noted that for those of ordinary skill in the art, without departing from the principle of the present invention, several improvements and refinements can be made, and these improvements and refinements should also be regarded as the protection scope of the present invention.
Claims
1. A method for adjusting the margin of a text line, characterized in that Including: Obtain the initial text line in the target page, where the initial text line is a text line with blanks at the line edges; Based on a preset starting point, identify the rectangular information in the initial text line character by character and compare the rectangular information corresponding to the current identified character with the rectangular information corresponding to the previous identified character; In the case where the rectangular information corresponding to the current identified character does not match the rectangular information corresponding to the previous identified character, determine that the previous identified character is the edge character in the initial text line; Create a range element based on the edge character; Based on the range element, adjust the margin of the initial text line to obtain a target text line, where the target text line is the initial text line with the blanks at the line edges removed.
2. The method according to claim 1, wherein The adjusting the margin of the initial text line based on the range element to obtain a target text line includes: Based on the position of the edge character, split the initial text line to obtain a plurality of text nodes, where the plurality of text nodes include the text nodes corresponding to the blanks at the line edges and the text nodes corresponding to the edge character; Insert the range element between the text node corresponding to the edge character and the text node corresponding to the blank at the line edge; Adjust the margin of the initial text line by adjusting the line margin corresponding to the range element to obtain the target text line.
3. The method according to claim 2, characterized in that, The inserting the range element between the text node corresponding to the edge character and the text node corresponding to the blank at the line edge includes: Obtain the character index corresponding to the edge character; Based on the character index, insert the range element between the text node corresponding to the edge character and the text node corresponding to the blank at the line edge.
4. The method according to claim 2, wherein The adjusting the margin of the initial text line by adjusting the line margin corresponding to the range element to obtain the target text line includes: Determine a margin adjustment value according to the text node corresponding to the blank at the line edge; Adjust the margin of the initial text line by adjusting the line margin corresponding to the range element to a negative value according to the margin adjustment value to obtain the target text line.
5. The method according to any one of claims 1 to 4, characterized in that The rectangular information includes the distance of the corresponding character from the upper edge of the target page.
6. The method according to any one of claims 1 to 4, characterized in that It also includes: In the Vue framework, set a custom directive; Based on the custom directive, start to identify the rectangular information in the initial text line character by character.
7. An adjustment device for the margin of a text line, characterized in that, Including: An obtaining module for obtaining the initial text line in the target page, where the initial text line is a text line with blanks at the line edges; An identifying module for identifying the rectangular information in the initial text line character by character based on a preset starting point and comparing the rectangular information corresponding to the current identified character with the rectangular information corresponding to the previous identified character; A determining module for determining that the previous identified character is the edge character in the initial text line in the case where the rectangular information corresponding to the current identified character does not match the rectangular information corresponding to the previous identified character; A creating module for creating a range element based on the edge character; An adjustment module, configured to adjust the margin of the initial text line based on the range element to obtain a target text line, where the target text line is the initial text line with the blank at the line edge removed.
8. A non-volatile storage medium, characterized in that, The non-volatile storage medium includes a stored program, where, when the program runs, it controls the device where the non-volatile storage medium is located to execute the method for adjusting the margin of the text line according to any one of claims 1 to 6.
9. A computer device, characterized in that, Comprising: A memory and a processor, The memory stores a computer program; The processor is configured to execute the computer program stored in the memory, and when the computer program runs, it causes the processor to execute the method for adjusting the margin of the text line according to any one of claims 1 to 6.
10. A computer program product, comprising a computer program, characterized in that, When the computer program is executed by the processor, it implements the method for adjusting the margin of the text line according to any one of claims 1 to 6.