Typesetting method, typesetting device, electronic equipment and storage medium
By dividing the content to be typed into multiple sub-blocks and calculating their offset contribution, determining the center offset to accurately arrange characters or graphics, the problem of ineffective handling of different character sizes or intervals in the prior art is solved. , improves the visual centering effect.
Patent Information
- Application Number
- CN202411437301.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-14
- Publication Date
- 2025-02-07
AI Technical Summary
When the prior art arranges characters or graphics in a center, it is impossible to effectively deal with the situation where characters are of different sizes or intervals, resulting in the inability to meet the visual perception of center arrangement.
By dividing the content to be typed into multiple sub-blocks, and determining the center offset according to the offset contribution amount of each sub-block, the target center position is then determined based on the center offset.
It realizes the precise determination of the target center position based on the center offset, improves the center arrangement effect of characters or graphics on the display interface, and improves the visual experience.
Smart Images

Figure CN119396510A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a typesetting method, a typesetting device, an electronic device and a storage medium. Background Art
[0002] When displaying characters or graphics, in order to provide users with a better visual experience, the display interface often needs to arrange the characters or graphics in the center. Therefore, it is necessary to determine the center position of the content to be typeset. In related technologies, the center position is usually determined based on the midpoint of the length of the content to be typeset. However, for characters of different sizes or unequal spacing, the center position determined by this method may not meet the perception of centered arrangement. Summary of the invention
[0003] Embodiments of the present application provide a typesetting method, a typesetting device, an electronic device, and a storage medium, which can determine a target center position according to a center offset.
[0004] In a first aspect, an embodiment of the present application provides a typesetting method, characterized in that it includes: determining a center offset of content to be typeset; and determining a target center position of the content to be typeset based on the center offset.
[0005] In some implementations, determining the center offset of the content to be typeset includes: dividing the content to be typeset into a plurality of sub-blocks; and determining the center offset according to an offset contribution of each of the sub-blocks.
[0006] In some implementations, the offset contribution is determined according to the number of valid pixels occupied by the corresponding sub-block.
[0007] In some implementations, the offset contribution of each of the sub-blocks is positively correlated with the color weight of the sub-block, and the color weight is related to at least one of the hue, saturation, or brightness of the content to be typeset in the sub-block.
[0008] In some implementations, the offset contribution of the nth sub-block among the multiple sub-blocks is determined as follows:
[0009]
[0010] Among them, P n represents the offset contribution of the nth sub-block, α n represents the pixel weight of the nth sub-block, γ n represents the color weight of the nth sub-block, J n-1 represents the interval between the nth sub-block and the (n-1)th sub-block, S n represents the center position of the nth sub-block, and S0 represents the reference position.
[0011] In some implementations, dividing the content to be typeset into a plurality of sub-blocks includes: dividing the content to be typeset into the plurality of sub-blocks according to characters, each of the sub-blocks including one character.
[0012] In some implementations, dividing the content to be typeset into a plurality of sub-blocks includes: dividing the content to be typeset into the plurality of sub-blocks according to a preset width or height.
[0013] In some implementations, the method further includes: determining a position of the content to be typeset in a target display area, wherein the target center position is located at a center position of the target display area.
[0014] In a second aspect, an embodiment of the present application provides a typesetting device, characterized in that the device comprises:
[0015] A first determination module is used to determine the center offset of the content to be typeset; and
[0016] The second determination module is used to determine the target center position of the content to be typeset based on the center offset.
[0017] In a third aspect, an embodiment of the present application provides an electronic device, characterized in that it includes a memory, a processor, and a computer program stored in the memory and executable on the processor, and when the processor executes the computer program, it implements the operations in the method described in the first aspect.
[0018] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, characterized in that a computer program is stored on the computer-readable storage medium, and when the computer program is executed by a processor, the operations in the method described in the first aspect are implemented.
[0019] In summary, the embodiments of the present application disclose a typesetting method, a typesetting device, an electronic device, and a storage medium. The typesetting method includes: determining a center offset of content to be typeset; and determining a target center position of the content to be typeset based on the center offset. The typesetting method, typesetting device, electronic device, and storage medium provided in the embodiments of the present application can determine a target center position according to the center offset. BRIEF DESCRIPTION OF THE DRAWINGS
[0020] In order to more clearly illustrate the technical solutions in the embodiments of this specification, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this specification. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0021] Figure 1 A schematic diagram showing a flow chart of a typesetting method provided in some embodiments of the present application;
[0022] Figure 2 A schematic diagram showing a flow chart of a typesetting method provided in some other embodiments of the present application;
[0023] Figure 3 An example diagram showing a typesetting method provided by some embodiments of the present application;
[0024] Figure 4 A schematic diagram showing the structure of a typesetting device provided in some embodiments of the present application is shown;
[0025] Figure 5 A schematic diagram of the structure of an electronic device provided in some embodiments of the present application is shown. DETAILED DESCRIPTION
[0026] The following will be combined with the drawings in this application to clearly and completely describe the technical solutions in this application. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of them. Based on the embodiments in the present invention, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of the present invention.
[0027] In many application scenarios, there is a need to display or arrange the target content in the center, so it is necessary to determine the target center position of the target content. For example, when the display interface displays characters or graphics, in order to provide a symmetrical look and feel, the content to be displayed needs to be displayed in the center. For another example, when the graphic editing software is typesetting text or graphics, it is necessary to center the content to be typeset. In the related art, the default centering method can be used, that is, the center point of the target content to be displayed or typeset is used as the target center position. However, this method has the problem of visual center offset.
[0028] Figure 1 A schematic flow chart of a typesetting method provided by some embodiments of the present application is shown. Although a logical order is shown in the flow chart, in some cases, the operations shown or described may be performed in an order different from that shown in the accompanying drawings. The specific flow of the typesetting method may be as follows:
[0029] S101, determining the center offset of the content to be typeset.
[0030] The content to be typeset may be content for display on a display interface. The content to be typeset may include characters, graphics, or a combination of the two. For example, the content to be typeset may include multiple characters. Different characters may use the same font size or different font sizes, and different characters may use the same color or different colors.
[0031] The center offset can be used to indicate the degree of offset of the target center position of the content to be typeset relative to the reference position. For example, the reference position can be the center position of the circumscribed rectangle or circumscribed circle of the content to be typeset. For example, the reference position can be the midpoint position of the bottom edge or top edge of the content to be typeset arranged horizontally, or the midpoint position of the side edge of the content to be typeset arranged vertically.
[0032] In some embodiments, the content to be typeset may be divided into a plurality of sub-blocks, and the center offset may be determined according to the offset contribution of each sub-block. How to divide the content to be typeset into a plurality of sub-blocks, and determine the center offset according to the offset contribution of each sub-block will be described in detail later.
[0033] In some embodiments, the center offset can be randomly initialized to obtain the distance loss between the target center position and each pixel in the content to be typeset when the center offset is used. The distance loss can be a predefined loss function. The center offset is obtained by optimizing the distance loss and iterating step by step.
[0034] S102: Determine the target center position of the content to be typeset based on the center offset.
[0035] The target center position may be a visual center position that provides a better visual experience for the user. In some embodiments, the reference position is superimposed with the center offset to obtain the target center position. In other embodiments, the target center position is comprehensively determined based on the reference position and user preferences, such as top alignment or bottom alignment after offset. In other embodiments, a center offset threshold is preset. When the center offset exceeds the threshold, the center offset threshold is used as the center offset to determine the target center position.
[0036] Some embodiments of the present application disclose a typesetting method, including: determining a center offset of content to be typeset, and determining a target center position of the content to be typeset based on the center offset. Some embodiments of the present application provide a typesetting method that can determine a target center position based on the center offset.
[0037] Figure 2Schematic flow charts of typesetting methods provided by other embodiments of the present application are shown. Although the logical order is shown in the flow chart, in some cases, the operations shown or described may be performed in an order different from that shown in the drawings. The specific process of the typesetting method may be as follows:
[0038] S201, dividing the content to be typeset into multiple sub-blocks.
[0039] In some embodiments, dividing the content to be typeset into a plurality of sub-blocks may be dividing the content to be typeset into a plurality of sub-blocks according to characters, each sub-block including one character. For example, for the content to be typeset consisting of a plurality of characters, it may be divided into blocks according to the characters, and one sub-block may be a rectangular block including one character. Of course, the sub-blocks may also be blocks having other shapes.
[0040] In some embodiments, dividing the content to be typeset into multiple sub-blocks may be dividing the content to be typeset into multiple sub-blocks according to a preset width or height. For example, for the content to be typeset arranged horizontally, it may be divided into multiple sub-blocks according to a preset width. For example, for the content to be typeset arranged vertically, it may be divided into multiple sub-blocks according to a preset height.
[0041] S202: Determine a center offset according to an offset contribution of each sub-block.
[0042] In some embodiments, the offset contribution of each sub-block can be determined based on the number of valid pixels occupied by the corresponding sub-block. For example, a sub-block may only contain character strokes without background. For another example, a sub-block may contain both foreground character strokes and background. The number of valid pixels is the number of pixels contained in the character strokes.
[0043] For sub-blocks divided according to characters, the number of valid pixels in the sub-blocks can be determined by obtaining the font and font size corresponding to the characters in the font library. For sub-blocks divided according to preset width or height, or sub-blocks where character information cannot be directly obtained, foreground information can be obtained through image processing, and then pixel statistics can be performed. For example, for sub-blocks containing backgrounds, image segmentation methods can be used to separate the foreground character strokes from the background, and then pixel statistics can be performed. For example, for sub-blocks that do not contain background images or contain simple backgrounds, image binarization methods can be used to extract foreground character strokes, and then pixel statistics can be performed.
[0044] The offset contribution of each sub-block can be determined by the number of valid pixels in the sub-block. For example, the number of valid pixels in the sub-block is used as the offset contribution of the sub-block. For example, the number of valid pixels in the sub-block is transformed by a preset transformation to obtain the offset contribution of the sub-block. The offset contribution of each sub-block is positively correlated with the number of valid pixels in the sub-block.
[0045] In some embodiments, the offset contribution of each sub-block can be determined according to the color weight of the sub-block. The color weight can represent the eye-catching degree of the color in the sub-block. The offset contribution of each sub-block is positively correlated with the color weight of the sub-block. That is, the more eye-catching the color of the content to be typeset in the sub-block is, the greater the impact of the sub-block on the visual focus is, and the greater the offset contribution is.
[0046] The color weight may be related to at least one of the hue, saturation or brightness of the content to be typeset in the sub-block. As mentioned above, the content to be typeset in the sub-block may include characters, graphics or a combination of the two. In the HSV color space, the higher the hue, the higher the saturation, and the higher the brightness, the more eye-catching the color. In some embodiments, the color weight may be jointly determined by the hue, saturation and brightness of the content to be typeset in the sub-block. For example, the color weight of the sub-block is obtained by weighted summation of hue, saturation and brightness.
[0047] In some other embodiments, the offset contribution of each sub-block may be determined by both the pixel weight and the color weight. The offset contribution of the nth sub-block among the multiple sub-blocks may be determined as follows:
[0048]
[0049] Among them, P n represents the offset contribution of the nth sub-block, α n represents the pixel weight of the nth sub-block, γ n represents the color weight of the nth sub-block, J n-1 represents the interval between the nth sub-block and the (n-1)th sub-block, S n represents the center position of the nth sub-block, and S0 represents the reference position.
[0050] Among them, the pixel weight α n It can be determined by the number of valid pixels in the sub-block. The determination method is as described above and will not be repeated here.
[0051] Among them, the color weight γ n It can be obtained by weighted summation of hue, saturation and brightness. For example, if the characters in a sub-block use only one color, the hue, saturation and brightness of the color can be used to determine the sub-block color weight. n The determination method can be: n =H*0.2+S*0.4+V*0.4, where H is hue, S is saturation, and V is brightness. If the characters in the sub-block use multiple colors, the color weights of each pixel in the character can be averaged to obtain the color weight of the sub-block. Color weight γ nIn the determination method, the coefficients corresponding to hue, saturation, and brightness can be adjusted according to actual needs.
[0052] Among them, J n-1 Indicates the interval between the nth sub-block and the (n-1th)th sub-block, which can be expressed in pixel distance. The interval value corresponding to the first sub-block defaults to 1. In addition, for sub-blocks divided by a preset height or width, the interval value between sub-blocks also defaults to 1.
[0053] Among them, S n The center position of the nth sub-block may be the center position of the circumscribed rectangle or the circumscribed circle of the nth sub-block. The center position may be the position in a coordinate system with the reference position S0 as the origin.
[0054] Among them, S0 represents the reference position, which can be the center position of the circumscribed rectangle or circumscribed circle of the content to be typeset, the reference position can be the midpoint position of the bottom or top edge of the horizontally arranged content to be typeset, or the midpoint position of the side edge of the vertically arranged content to be typeset.
[0055] After determining the offset contribution corresponding to each sub-block, the center offset can be determined as follows:
[0056]
[0057] Where P represents the center offset, and N represents the number of sub-blocks contained in the content to be typeset. k is the offset contribution P of the kth sub-block k In some embodiments, β k The value of can be 1.
[0058] S203: Determine the target center position of the content to be typeset based on the center offset.
[0059] In some embodiments, the target center position may be determined as follows:
[0060] S1=S0+εP
[0061] Wherein, S1 represents the target center position, and ε represents the coefficient of the center offset. In some embodiments, the value of ε can be 1.
[0062] In some embodiments, the typesetting method may further include:
[0063] S204: Determine the position of the content to be typeset in the target display area, wherein the target center position is located at the center position of the target display area.
[0064] In some application scenarios that require visual centering, placing the target center position of the content to be typeset at the center position of the target display area can achieve a better visual effect.
[0065] Figure 3 An example diagram of a typesetting method provided by some embodiments of the present application is shown. Figure 3 As shown, the content to be typeset is "abcdefgh", wherein "abcd" and "efgh" have different font sizes, causing the visual center of gravity to shift toward the latter. Figure 3 The coordinate system shown in FIG. 1 is based on the center point of the target display area A as the origin, the horizontal direction is the x-axis direction, and the vertical direction is the y-axis direction. Figure 3 As shown in the upper middle part, placing the reference position S0 of the content to be typeset at the center point of the target display area A will give the user a feeling that the visual center is biased to the right.
[0066] After the target center position S1 is determined according to the layout method described above in this application, the target center position S1 is placed at the center point of the target display area A, and the Figure 3 The layout effect shown in the middle and lower part. The adjusted layout makes the visual center located in the center of the display area, which can provide users with a better visual experience.
[0067] Figure 4 The schematic diagram of the structure of the typesetting device provided in some embodiments of the present application is shown. The typesetting device 400 may include:
[0068] The first determination module 401 may be used to determine the center offset of the content to be typeset.
[0069] The second determination module 402 may be used to determine the target center position of the content to be typeset based on the center offset.
[0070] The typesetting device 400 provided in some embodiments of the present application can determine the center offset of the content to be typeset by the first determination module 401. Next, the typesetting device 400 can determine the target center position of the content to be typeset based on the center offset by the second determination module 402. The typesetting device 400 provided in some embodiments of the present application can determine the target center position according to the center offset.
[0071] In some embodiments, the first determination module 401 may include a first block division unit and a first determination unit. The first block division unit may be used to divide the content to be typeset into a plurality of sub-blocks. The first determination unit may determine the center offset according to the offset contribution of each sub-block.
[0072] In some embodiments, in the first determining unit, the offset contribution amount may be determined according to the number of valid pixels occupied by the corresponding sub-block.
[0073] In some embodiments, in the first determining unit, the offset contribution of each sub-block is positively correlated with the color weight of the sub-block, and the color weight is related to at least one of the hue, saturation or brightness of the content to be typeset in the sub-block.
[0074] In some embodiments, in the first determining unit, the offset contribution of the nth sub-block among the multiple sub-blocks is determined as follows:
[0075]
[0076] Among them, P n represents the offset contribution of the nth sub-block, α n represents the pixel weight of the nth sub-block, γ n represents the color weight of the nth sub-block, J n-1 represents the interval between the nth sub-block and the (n-1)th sub-block, S n represents the center position of the nth sub-block, and S0 represents the reference position.
[0077] In some embodiments, the block division unit may include a first block division unit, which may be used to divide the content to be typeset into a plurality of sub-blocks according to characters, each sub-block including one character.
[0078] In some embodiments, the block division unit may include a second block division unit, which may be used to divide the content to be typeset into a plurality of sub-blocks according to a preset width or height.
[0079] In some embodiments, the typesetting device 400 may further include a third determining module. The third determining module may be used to determine the position of the content to be typeset in the target display area, wherein the target center position is located at the center position of the target display area.
[0080] In addition, the present application also provides an electronic device, Figure 5 The following is a schematic diagram of the structure of an electronic device provided by some embodiments of the present application, specifically:
[0081] The electronic device 500 may include one or more processors 501 of processing cores, one or more computer-readable storage media memories 502 and other components. Those skilled in the art will appreciate that Figure 5 The structure of the electronic device 500 shown in the figure does not constitute a limitation on the electronic device, and may include more or fewer components than shown in the figure, or combine certain components, or arrange the components differently.
[0082] The processor 501 is the control center of the electronic device 500. It uses various interfaces and lines to connect various parts of the entire electronic device 500. By running or executing software programs and / or modules stored in the memory 502, and calling data stored in the memory 502, it executes various functions of the electronic device 500 and processes data, thereby monitoring the electronic device 500 as a whole. Optionally, the processor 501 may include one or more processing cores; preferably, the processor 501 may integrate an application processor and a modem processor, wherein the application processor mainly processes the operating system, user interface, and application programs, etc., and the modem processor mainly processes wireless communications. It is understandable that the above-mentioned modem processor may not be integrated into the processor 501.
[0083] The memory 502 can be used to store software programs and modules. The processor 501 executes various functional applications and data processing by running the software programs and modules stored in the memory 502. The memory 502 may mainly include a program storage area and a data storage area, wherein the program storage area may store an operating system, an application required for at least one function, etc.; the data storage area may store data created according to the use of the electronic device 500, etc. In addition, the memory 502 may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, or other volatile solid-state storage devices. Accordingly, the memory 502 may also include a memory controller to provide the processor 501 with access to the memory 502.
[0084] Specifically in this embodiment, the processor 501 in the electronic device 500 will load the executable files corresponding to the processes of one or more applications into the memory 502 according to the following instructions, and the processor 501 will run the applications stored in the memory 502, thereby implementing the operations in any typesetting method provided in the embodiments of the present application.
[0085] The specific process of the electronic device 500 executing the typesetting method can be referred to Figure 1 , Figure 2 The description in , this application will not be repeated here.
[0086] Those skilled in the art will appreciate that all or part of the operations in the various methods of the above embodiments may be accomplished through instructions, or through instruction-controlled related hardware. The instructions may be stored in a computer-readable storage medium and loaded and executed by a processor.
[0087] To this end, the present application provides a computer-readable storage medium, on which a computer program is stored. The computer program can be loaded by a processor to execute operations in any typesetting method provided in the present application.
[0088] The specific implementation of the above operations can be found in the previous embodiments, which will not be described in detail here.
[0089] The computer-readable storage medium may include: a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, etc.
[0090] Since the instructions stored in the computer-readable storage medium can execute the operations in any typesetting method provided in the present application, the beneficial effects that can be achieved by any typesetting method provided in the present application can be achieved. Please refer to the previous embodiments for details and will not be repeated here.
[0091] The above is a detailed introduction to a typesetting method, a typesetting device, an electronic device and a storage medium provided by the present application. Specific examples are used herein to illustrate the principles and implementation methods of the present invention. The description of the above embodiments is only used to help understand the method of the present invention and its core idea. At the same time, for those skilled in the art, according to the idea of the present invention, there will be changes in the specific implementation methods and application scopes. In summary, the content of this specification should not be understood as a limitation on the present invention.
Claims
1. A typesetting method, characterized in that: include: Determine the center offset of the content to be typeset; as well as Based on the center offset, a target center position of the content to be typeset is determined.
2. The method according to claim 1, characterized in that in, The determining of the center offset of the content to be typeset includes: Dividing the content to be typeset into a plurality of sub-blocks; and The center offset is determined according to the offset contribution of each of the sub-blocks.
3. The method according to claim 2, characterized in that The offset contribution is determined according to the number of valid pixels occupied by the corresponding sub-block.
4. The method according to claim 2, characterized in that The offset contribution of each sub-block is positively correlated with the color weight of the sub-block, and the color weight is related to at least one of the hue, saturation or brightness of the content to be typeset in the sub-block.
5. The method according to claim 2, characterized in that The offset contribution of the nth sub-block among the multiple sub-blocks is determined as follows: Among them, P n represents the offset contribution of the nth sub-block, α n represents the pixel weight of the nth sub-block, γ n represents the color weight of the nth sub-block, J n-1 represents the interval between the nth sub-block and the (n-1)th sub-block, S n represents the center position of the nth sub-block, and S0 represents the reference position.
6. The method according to claim 2, characterized in that in, The step of dividing the content to be typeset into a plurality of sub-blocks includes: The content to be typeset is divided into the multiple sub-blocks according to characters, and each sub-block includes one character.
7. The method according to claim 2, characterized in that in, The step of dividing the content to be typeset into a plurality of sub-blocks includes: The content to be typeset is divided into the multiple sub-blocks according to a preset width or height.
8. The method according to claim 1, characterized in that The method further comprises: The position of the content to be typeset in the target display area is determined, wherein the target center position is located at the center position of the target display area.
9. A typesetting device, characterized in that: The device comprises: A first determination module is used to determine the center offset of the content to be typeset; and The second determination module is used to determine the target center position of the content to be typeset based on the center offset.
10. An electronic device, characterized in that: The method comprises a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the operations in the method according to any one of claims 1 to 8 when executing the computer program.
11. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the operations in the method according to any one of claims 1 to 8 are implemented.