Character typesetting method and device and electronic equipment
By constructing text paths of any shape and scaling characters, the problem that the existing Chinese text layout is difficult to meet the needs of complex artistic characters is solved, and effective text layout and artistic effect improvement is achieved.
Patent Information
- Application Number
- CN202411745581.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-29
- Publication Date
- 2025-04-15
AI Technical Summary
Existing text typesetting methods are difficult to meet users' needs for complex artistic characters, especially to avoid the problem that character text length exceeds the text path length.
Ensure the effectiveness of the typography effect by constructing a text path of any shape, scaling a given character to fit the text path, and filling characters along the text path. The specific steps include constructing the Besel curve as the text path, calculating the scaling coefficient, setting the character position and rotation angle, and drawing the background of the character.
It realizes text typesetting along any shape text path, avoids the problem that character text length exceeds the path length, and ensures the effectiveness of the layout effect and improves artistic effect.
Smart Images

Figure CN119830856A_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present application relate to the field of word processing technology, and more specifically, to a word typesetting method, device, and electronic device. Background Art
[0002] With the development of presentations and video editing, there are more and more ways to play with and demands for artistic words, especially the need for more complex text layout to enrich the display effect of artistic words. In the future, there will be more and more text attributes combined with layout to form more complex artistic word effects.
[0003] Existing text typesetting methods mainly include linear text typesetting and curved text typesetting. Linear typesetting is to arrange text in sequence on the same straight line, and curved typesetting is to arrange text in sequence along a curved track. The above typesetting methods each have their own advantages and disadvantages, and it is difficult to meet user needs. Summary of the invention
[0004] In response to the problems existing in the above-mentioned prior art, the embodiments of the present application provide a text typeset method, device, and electronic device, which can typeset text along a text path of any shape and can effectively avoid the text length of a given character exceeding the text path length, thereby ensuring the effectiveness of the typesetting effect.
[0005] In a first aspect, an embodiment of the present application provides a text typesetting method, comprising the following steps:
[0006] Construct text path;
[0007] scaling the given character to fit within the text path; and
[0008] Fill the given characters along the text path.
[0009] Furthermore, constructing the text path includes:
[0010] Constructs a Bezier curve.
[0011] Furthermore, scaling the given character to fit the text path includes:
[0012] Calculate the total width W of the text;
[0013] Calculating the total length L of the text path; and
[0014] If W>L, the given character needs to be scaled, and the scaling factor α=L / W.
[0015] Further, filling the given characters along the text path includes:
[0016] Set the position of the first character as the starting point P(0) of the text path;
[0017] Calculate the center point P of the first character center (s), where w1 is the width of the first character;
[0018] The rotation angle of the first character is set to P center (s) the normal direction of the text path;
[0019] The position of the subsequent character is set to P(s i ),in and
[0020] The rotation angle of each character is set to The normal direction of the text path at .
[0021] Furthermore, the method further includes drawing the background of the given character.
[0022] Furthermore, drawing the background of the given character includes:
[0023] Move the starting point P(0) of the text path downward, and the moving distance is the absolute value of the descending height, so as to obtain the lower edge point of the background;
[0024] The starting point P(0) of the text path is moved upward by the upward height to obtain the upper edge point of the background;
[0025] Move forward a short distance δ along the path, repeat the above steps until the total forward distance S is equal to the scaled text width α·W, and obtain multiple lower edge points and multiple lower edge points of the background;
[0026] connecting the plurality of upper edge points and the plurality of lower edge points to form a polygon; and
[0027] The polygon is filled to draw the background of the given character.
[0028] Furthermore, it also includes a texture filled with text, and the texture filled with text includes the following steps:
[0029] Calculate the minimum bounding rectangle of the text;
[0030] Generate a gradient map in the area of the minimum circumscribed rectangle; and
[0031] The overlapping portion of the gradient image and the text image is extracted to fill the texture of the text.
[0032] In a second aspect, the present application also provides a text typesetting device, including:
[0033] Attribute parsing module, used to parse the basic attributes of a given character;
[0034] Path construction module, used to construct text paths;
[0035] A character scaling module, used for scaling the given character to fit the text path; and
[0036] The character filling module is used to fill the given characters along the text path.
[0037] In a third aspect, an embodiment of the present application further provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor is configured to implement the text typesetting method according to the first aspect when executing the program.
[0038] In a fourth aspect, an embodiment of the present application further provides a computer-readable storage medium on which a computer program is stored, wherein the computer program is used to implement the text typesetting method according to the first aspect described above.
[0039] The embodiments of the present application bring the following beneficial effects:
[0040] In the text typesetting method provided in the embodiment of the present application, when the text path is constructed and the given character is scaled, the given character is filled along the text path, thereby completing the text typesetting operation. Therefore, the text typesetting method provided in the embodiment of the present application can perform text typesetting along a text path of any shape, and can effectively avoid the text length of the given character exceeding the text path length, thereby ensuring the effectiveness of the typesetting effect. BRIEF DESCRIPTION OF THE DRAWINGS
[0041] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on the structures shown in these drawings without paying any creative work.
[0042] Figure 1 A flowchart of a text typesetting method provided in an embodiment of the present application;
[0043] Figure 2 A structural block diagram of a text typesetting device provided in an embodiment of the present application;
[0044] Figure 3 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application.
[0045] The realization of the purpose, functional features and advantages of this application will be further explained in conjunction with embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION
[0046] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments described in the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of this application.
[0047] In the specification and claims of this application and the above-mentioned drawings, the terms "first" and "second" are used for descriptive purposes only and cannot be understood as indicating or implying relative importance or implicitly indicating the number of technical features indicated. Therefore, the features defined as "first" and "second" may explicitly or implicitly include one or more of the features. In the description of this application, unless otherwise specified, "multiple" means two or more. For ordinary technicians in this field, the specific meanings of the above terms in this application can be understood according to the specific circumstances.
[0048] Figure 1 FIG. 1 is a flow chart of a text typesetting method according to an embodiment of the present application. Figure 1 As shown, the text typesetting method of the embodiment of the present application includes the following steps:
[0049] S101: construct text path;
[0050] Specifically, the text path allows given characters to be arranged along a specific path. The text path can be a straight path, a curved path, or a path of any other shape. The specific shape depends on user needs.
[0051] S102: scaling a given character to fit the text path; and
[0052] When typeset a given character according to a text path, the given character needs to be scaled to fit the text path, thereby preventing the text length of the given character from exceeding the length of the text path for ease of typesetting.
[0053] S103: Filling the given characters along the text path.
[0054] As described above, when the text path is constructed and the given characters are scaled, it is necessary to fill the given characters along the text path to complete the text typesetting operation.
[0055] Therefore, in the text typesetting method provided in the embodiment of the present application, when the text path is constructed and the given character is scaled, the given character is filled along the text path, thereby completing the text typesetting operation. Therefore, the text typesetting method provided in the embodiment of the present application can perform text typesetting along a text path of any shape, and can effectively avoid the text length of a given character exceeding the text path length, thereby ensuring the effectiveness of the typesetting effect.
[0056] It should be noted that before constructing a text path, it is necessary to parse or initialize the basic properties of the given characters, including but not limited to: gradient style: including gradient type, gradient color, etc.; background style: background fill color; text maximum and minimum: the ascending and descending heights of the given text, mainly used to determine the background height; text scaling factor: in order to prevent the text length from exceeding the length of the text path and being unable to be typeset, a scaling factor is required to scale the text so that the text can be typeset on the path.
[0057] Further, in some embodiments of the present application, constructing a text path includes:
[0058] Construct a Bezier curve as the text path.
[0059] Specifically, a Bezier curve is composed of line segments and nodes. The nodes are draggable fulcrums, and the line segments are like retractable rubber bands. By adjusting the control points, such as the starting point, the end point, and the middle point, the shape of the Bezier curve will change. Therefore, in the text typesetting method provided in the embodiment of the present application, by constructing a Bezier curve as the text path of a given character, a text path of any shape can be constructed, thereby enhancing the diversity and creativity of text typesetting, and at the same time providing a larger creative space for the design of artistic characters, so that text works can show unique style and creativity.
[0060] Further, in some embodiments of the present application, scaling the given character to fit the text path includes:
[0061] Calculate the total width W of the text;
[0062] Calculating the total length L of the text path; and
[0063] If W>L, the given character needs to be scaled, and the scaling factor α=L / W.
[0064] Further, in some embodiments of the present application, filling the given character along the text path includes:
[0065] Set the position of the first character as the starting point P(0) of the text path;
[0066] Calculate the center point P of the first charactercenter (s), where w1 is the width of the first character;
[0067] The rotation angle of the first character is set to P center (s) the normal direction of the text path;
[0068] The position of the subsequent character is set to P(s i ),in and
[0069] The rotation angle of each character is set to The normal direction of the text path at .
[0070] Therefore, the text typesetting method provided in the embodiment of the present application can scale the given character through the above steps to adapt to the text path, thereby completing the filling operation of the given character, and can effectively avoid the text length of the given character exceeding the text path length, thereby ensuring the effectiveness of the typesetting effect.
[0071] Furthermore, in some embodiments of the present application, the text typesetting method provided in the embodiments of the present application also includes drawing the background of the given character.
[0072] Specifically, the background of a given character refers to the background of the text area where the given character is located. The text typesetting method provided in the embodiment of the present application also includes drawing the background of the given character, thereby further improving the artistic effect of the text typesetting and increasing the visual level of the text.
[0073] Furthermore, in some embodiments of the present application, drawing the background of the given character includes:
[0074] Move the starting point P(0) of the text path downward by the absolute value of the descending height (decent, which is a negative number) to obtain the lower edge point of the background;
[0075] The starting point P(0) of the text path is moved upward by an ascent to obtain the upper edge point of the background;
[0076] Move forward a short distance δ along the path, repeat the above steps until the total forward distance S is equal to the scaled text width α·W, and obtain multiple lower edge points and multiple lower edge points of the background;
[0077] connecting the plurality of upper edge points and the plurality of lower edge points to form a polygon; and
[0078] The polygon is filled to draw the background of the given character.
[0079] That is, the overall idea of drawing the background is to use the cutting method, that is, to divide the curved path into enough small segments, and then each segment can construct a rectangle. Finally, the image formed by all the small rectangles is the background area. After the background area is obtained, the area can be filled, which can further improve the artistic effect of the text layout and increase the visual level of the text.
[0080] Furthermore, in some embodiments of the present application, a texture of filling text is also included, and the texture of filling text includes the following steps:
[0081] Calculate the minimum bounding rectangle of the text;
[0082] Generate a gradient map in the area of the minimum circumscribed rectangle; and
[0083] The overlapping portion of the gradient image and the text image is extracted to fill the texture of the text.
[0084] That is, first calculate the bounding box of the text after typeset along the text path, that is, the minimum circumscribed rectangle of the text. The bounding box will contain the boundaries of all characters and leave enough space to ensure that the gradient map completely covers the text. Then, based on the above bounding box, generate a gradient map. The gradient map can be a linear gradient or a radial gradient, and the specific type can be determined according to the design requirements. Linear gradient refers to the gradual change of color from one starting point to another end point. And radial gradient refers to the gradual change of color from a center point outward. The color range of the gradient map can be customized according to the design requirements to achieve the ideal visual effect. Finally, using image synthesis technology, the generated gradient map is superimposed on the text map, and the part of the overlapping area of the gradient map and the text map is extracted, that is, the color information of the location of the text is retained, so as to obtain text with gradient color filling, so as to achieve a visually smooth transition color effect, so that the gradient effect of the text of a given character is more harmonious and natural, and the visual effect is more beautiful.
[0085] Figure 2 2 is a structural block diagram of a text typesetting device 200 provided in an embodiment of the present application. Figure 2 As shown, the text typesetting device 200 of the embodiment of the present application includes: a path construction module 210, a character scaling module 220 and a character filling module 230, wherein:
[0086] A path construction module 210, used to construct a text path;
[0087] A character scaling module 220, configured to scale the given character to fit the text path; and
[0088] The character filling module 230 is used to fill the given characters along the text path.
[0089] In the text typesetting device provided in the embodiment of the present application, when the text path is constructed and the given character is scaled, the given character is filled along the text path, thereby completing the text typesetting operation. Therefore, the text typesetting method provided in the embodiment of the present application can perform text typesetting along a text path of any shape, and can effectively avoid the text length of the given character exceeding the text path length, thereby ensuring the effectiveness of the typesetting effect.
[0090] It should be noted that the specific implementation method of the text typesetting device in the embodiment of the present application is similar to the specific implementation method of the text typesetting method in the embodiment of the present application. Please refer to the description of the method part for details, and no further details will be given here.
[0091] Figure 3 Schematic diagram of the structure of an electronic device 300 according to an embodiment of the present application.
[0092] like Figure 3 As shown, the electronic device 300 includes a central processing unit (CPU) 301, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 302 or a program loaded from the storage part 302 to a random access memory (RAM) 303. In the RAM 303, various programs and data required for the operation of the electronic device 300 are also stored. The CPU 301, the ROM 302, and the RAM 303 are connected to each other via a bus 304. An input / output (I / O) interface 305 is also connected to the bus 304.
[0093] The following components are connected to the I / O interface 305: an input section 306 including a keyboard, a mouse, etc.; an output section 307 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker, etc.; a storage section 308 including a hard disk, etc.; and a communication section 309 including a network interface card such as a LAN card, a modem, etc. The communication section 309 performs communication processing via a network such as the Internet. A drive 310 is also connected to the I / O interface 305 as needed. A removable medium 311, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 310 as needed, so that a computer program read therefrom is installed into the storage section 308 as needed.
[0094] In particular, according to an embodiment of the present application, the process described above with reference to the flowchart can be implemented as a computer software program. For example, an embodiment of the present application includes a computer program product, which includes a computer program carried on a machine-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network through a communication section 309, and / or installed from a removable medium 311. When the computer program is executed by a central processing unit (CPU) 301, the above-mentioned functions defined in the electronic device of the present application are executed.
[0095] It should be noted that the computer-readable medium shown in the present application may be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium may be, for example, but not limited to, an electronic device, device or device of electricity, magnetism, light, electromagnetic, infrared, or semiconductor, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above.
[0096] In the present application, a computer-readable storage medium may be any tangible medium containing or storing a program that may be used by or in combination with an instruction-executing electronic device, apparatus, or device. In the present application, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, which carries a computer-readable program code. Such propagated data signals may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. A computer-readable signal medium may also be any computer-readable medium other than a computer-readable storage medium, which may send, propagate, or transmit a program for use by or in combination with an instruction-executing electronic device, apparatus, or device. The program code contained on the computer-readable medium may be transmitted using any suitable medium, including but not limited to: wireless, wire, optical cable, RF, etc., or any suitable combination of the above.
[0097] The flowchart and block diagram in the accompanying drawings illustrate the possible architecture, functions and operations of the processing receiving device, method and computer program product according to various embodiments of the present application. In this regard, each box in the flowchart or block diagram can represent a module, a program segment, or a part of the code, and the aforementioned module, program segment, or a part of the code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram and / or flowchart, and the combination of the boxes in the block diagram and / or flowchart can be implemented with a dedicated hardware-based electronic device that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0098] The units or modules involved in the embodiments described in this application may be implemented by software or hardware. The units or modules described may also be set in a processor, and the processor is used to implement the text typesetting method when executing the program:
[0099] Construct text path;
[0100] scaling the given character to fit within the text path; and
[0101] Fill the given characters along the text path.
[0102] As another aspect, the present application further provides a computer-readable storage medium, which may be included in the electronic device described in the above embodiment; or may exist independently and not be assembled into the electronic device. The above computer-readable storage medium stores one or more programs, and when the above programs are used by one or more processors to execute the text typesetting method described in the present application:
[0103] Construct text path;
[0104] scaling the given character to fit within the text path; and
[0105] Fill the given characters along the text path.
[0106] As another aspect, the present application further provides a computer program product, which may be included in the electronic device described in the above embodiment; or may exist independently without being installed in the electronic device. The above computer program product stores one or more programs, and when the above programs are used by one or more processors to execute the text typesetting method described in the present application:
[0107] Construct text path;
[0108] scaling the given character to fit within the text path; and
[0109] Fill the given characters along the text path.
[0110] The above description is only a preferred embodiment of the present application, and does not limit the patent scope of the present application. All equivalent structural changes made by using the contents of the present application specification and drawings under the application concept of the present application, or directly / indirectly used in other related technical fields are included in the patent protection scope of the present application.
Claims
1. A text typesetting method, characterized in that: The following steps are involved: Construct text path; scaling the given character to fit within the text path; and Fill the given characters along the text path.
2. The text typesetting method according to claim 1, characterized in that: The constructing text path includes: Construct a Bezier curve as the text path.
3. The text typesetting method according to claim 2, characterized in that: The step of scaling the given character to fit the text path comprises: Calculate the total width W of the text; Calculating the total length L of the text path; and If W>L, the given character needs to be scaled, and the scaling factor α=L / W.
4. The text typesetting method according to claim 1, characterized in that: Filling the given character along the text path includes: Set the position of the first character as the starting point P(0) of the text path; Calculate the center point P of the first character center (s), where w1 is the width of the first character; The rotation angle of the first character is set to P center (s) the normal direction of the text path; The position of the subsequent character is set to P(s i ),in and The rotation angle of each character is set to The normal direction of the text path at .
5. The text typesetting method according to claim 2, characterized in that: Also included is drawing the background of the given character.
6. The text typesetting method according to claim 5, characterized in that: The step of drawing the background of the given character comprises: Move the starting point P(0) of the text path downward, and the moving distance is the absolute value of the descending height, so as to obtain the lower edge point of the background; The starting point P(0) of the text path is moved upward by the upward height to obtain the upper edge point of the background; Move forward a short distance δ along the path, repeat the above steps until the total forward distance S is equal to the scaled text width α·W, and obtain multiple lower edge points and multiple lower edge points of the background; connecting the plurality of upper edge points and the plurality of lower edge points to form a polygon; and The polygon is filled to draw the background of the given character.
7. The text typesetting method according to claim 1, characterized in that: Also included is a texture filled with text, the texture filled with text comprising the following steps: Calculate the minimum bounding rectangle of the text; Generate a gradient map in the area of the minimum circumscribed rectangle; and The overlapping portion of the gradient image and the text image is extracted to fill the texture of the text.
8. A text typesetting device, characterized in that: include: Path construction module, used to construct text paths; A character scaling module, used for scaling the given character to fit the text path; and The character filling module is used to fill the given characters along the text path.
9. An electronic device, characterized in that: The invention comprises a memory, a processor and a computer program stored in the memory and executable on the processor, wherein the processor is used to implement the text typesetting method according to any one of claims 1 to 7 when executing the program.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and the computer program is used to implement the text typesetting method according to any one of claims 1-7.