Method, device, storage medium and electronic device for setting rich text spacing
Creating a rich text object and setting its width through preset types of spaces solves the problem of cumbersome and inaccurate character spacing settings in the existing technology, achieving precise control of spacing and improving the display effect.
Patent Information
- Application Number
- CN202111039256.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-09-06
- Publication Date
- 2024-10-22
- Estimated Expiration
- 2041-09-06
AI Technical Summary
In the existing technology, the setting of character spacing is cumbersome and the control is imprecise, making it difficult to achieve a good display effect especially when images and texts are mixed.
Use a preset type of space to create a rich text object, and set its width according to the required spacing value. The spacing setting is achieved by splicing the object, which simplifies the parameter adjustment process.
It achieves precise control of rich text spacing, simplifies the setting steps, and improves the display effect.
Smart Images

Figure CN113723048B_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of computer technology, and in particular to a method, device, storage medium and electronic device for setting rich text spacing. Background Art
[0002] With the development of technology, various electronic products can display richer content to users, or present content through more diversified display forms. Usually, when displaying pictures, text and other content, the spacing between characters is set to ensure a good display effect. However, the current method of setting the spacing between characters is usually to use the word spacing (kern) method or to manually enter spaces. Especially for the text-image spacing between text content and image content, when setting it through word spacing, it is necessary to set the rich text range where the image of the text-image boundary is located, such as parameters such as rich text word spacing attributes. The setting process is cumbersome and inconvenient to use; and although the form of manually entering spaces is convenient, it is impossible to achieve precise spacing control, especially when displaying content in multiple rows or columns, the different character spacing will cause the displayed content to be messy and the display effect to be poor. Summary of the invention
[0003] The purpose of the embodiments of the present disclosure is to provide a method, device, storage medium and electronic device for setting rich text spacing, so as to solve the problem of complicated character spacing setting or inaccurate control in the prior art.
[0004] The embodiment of the present disclosure adopts the following technical solution: a method for setting rich text spacing, the method comprising the following steps: creating a first rich text object using a preset type space, wherein the width of the preset type space is associated with the font size; setting the width of the first rich text object according to the required spacing value; and splicing the first rich text object after the current rich text object to form the spacing after the current rich text object.
[0005] In some embodiments, the preset type of space is any one of the following: a full-width space encoded as U+3000; or, a half-width space encoded as U+2002; a third-width space encoded as U+2004; a quarter-width space encoded as U+2005; or a sixth-width space encoded as U+2006.
[0006] In some embodiments, setting the width of the first rich text object according to the required spacing value includes: determining a first font size according to the preset type space and the required spacing value: setting the width of the first rich text object to the width of at least one of the preset type spaces under the first font size.
[0007] In some embodiments, when the preset type of space is a full-width space, determining the first font size includes: determining a font size having the same font size as the required spacing value as the first font size.
[0008] In some embodiments, it also includes: when the preset type space is a half-width space, determining the first font size includes: determining a font size that is the same as twice the required spacing value as the first font size.
[0009] In some embodiments, the method further includes: encapsulating the aforementioned method steps into a method object; when it is necessary to set the spacing after the current rich text object, calling the method object and passing the required spacing value to the method object, and then the method object executes the aforementioned method steps.
[0010] An embodiment of the present disclosure also provides a device for setting rich text spacing, including: a creation module, configured to create a first rich text object using a preset type space, wherein the width of the preset type space is related to the font size but is not affected by the font type; a setting module, configured to set the width of the first rich text object according to a required spacing value; and a splicing module, configured to splice the first rich text object to after the current rich text object to form a spacing after the current rich text object.
[0011] In some embodiments, the setting module is specifically used to: determine the first font size according to the preset type space and the required spacing value: set the width of the first rich text object to the width of at least one of the preset type spaces under the first font size.
[0012] An embodiment of the present disclosure further provides a storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps of the above-mentioned method for setting the character spacing are performed.
[0013] An embodiment of the present disclosure further provides an electronic device, comprising at least a memory and a processor, wherein the memory stores a computer program, and the processor implements the steps of the above-mentioned method for setting the character spacing when executing the computer program on the memory.
[0014] The beneficial effects of the embodiments of the present disclosure are as follows: when spacing setting is required, by calling the method provided by the embodiments of the present disclosure, precise control of the required spacing can be achieved by setting the width of the first rich text object, and the spacing setting can be achieved by directly splicing the first rich text object after the current rich text object, without the need for cumbersome parameter adjustments, and accurate spacing setting can be achieved on the basis of simplifying the spacing setting steps, thereby achieving a better display effect. BRIEF DESCRIPTION OF THE DRAWINGS
[0015] In order to more clearly illustrate the embodiments of the present disclosure 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 recorded in the present disclosure. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative labor.
[0016] Figure 1 A flowchart of a method for setting rich text spacing in the first embodiment of the present disclosure;
[0017] Figure 2 This is a schematic diagram of a rich text in the first embodiment of the present disclosure;
[0018] Figure 3 It is a structural schematic diagram of a device for setting rich text spacing in the second embodiment of the present disclosure;
[0019] Figure 4 Schematic diagram of the structure of an electronic device in the fourth embodiment of the present disclosure. DETAILED DESCRIPTION
[0020] Various aspects and features of the present disclosure are described herein with reference to the drawings.
[0021] It should be understood that various modifications may be made to the embodiments of the present application. Therefore, the above description should not be considered as limiting, but only as an example of an embodiment. Other modifications within the scope and spirit of the present disclosure will occur to those skilled in the art.
[0022] The accompanying drawings, which are incorporated in and constitute a part of the specification, illustrate embodiments of the present disclosure and, together with the general description of the present disclosure given above and the detailed description of the embodiments given below, serve to explain the principles of the present disclosure.
[0023] These and other characteristics of the present disclosure will become apparent from the following description of a preferred form of embodiment given as a non-limiting example, with reference to the attached drawings.
[0024] It should also be understood that, although the present disclosure has been described with reference to some specific examples, those skilled in the art will be able to realize many other equivalent forms of the present disclosure that have the features of the claims and are therefore within the scope of protection defined thereby.
[0025] The above and other aspects, features and advantages of the present disclosure will become more apparent from the following detailed description when taken in conjunction with the accompanying drawings.
[0026] Specific embodiments of the present disclosure are described hereinafter with reference to the accompanying drawings; however, it should be understood that the embodiments claimed are merely examples of the present disclosure, which may be implemented in a variety of ways. Well-known and / or repeated functions and structures are not described in detail to avoid obscuring the present disclosure with unnecessary or redundant details. Therefore, the specific structural and functional details claimed herein are not intended to be limiting, but merely serve as a basis and representative basis for the claims to teach those skilled in the art to use the present disclosure in a variety of ways with substantially any suitable detailed structure.
[0027] This specification may use the phrases "in one embodiment," "in another embodiment," "in a further embodiment," or "in other embodiments," all of which may refer to one or more of the same or different embodiments according to the present disclosure.
[0028] In order to solve the problems that arise when setting character spacing in the prior art, the first embodiment of the present disclosure provides a method for setting rich text spacing. The method can be mainly applied to the operating systems of various electronic devices when editing rich text, and the spacing can be quickly set by the developer's active call. Figure 1 A flow chart of a method for setting rich text spacing is shown, which mainly includes steps S10 to S30:
[0029] S10, creating a first rich text object using a preset type space.
[0030] The first rich text object is an object set between two adjacent rich text objects, and is used to set the spacing between adjacent rich texts, especially the spacing between adjacent rich text objects in the same row. The specific content of the first rich text object is a space with the same width as the spacing currently required by the user. Specifically, the first rich text object created in this embodiment is a mutable rich text object (NSMutableAttributedString). In addition, all objects edited by the user in the page are rich text objects, which are used to specifically display various elements such as pictures and texts.
[0031] In the present embodiment, the first rich text object is created by using a preset type of space. The preset type of space mainly refers to a space with a fixed width, the size of which will not change with the font when the font size is determined. In other words, the width of the preset type of space is related to the font size, but is not affected by the font type, such as a full-width space encoded as U+3000, a half-width space encoded as U+2000, etc., which facilitates the setting of fixed spacing.
[0032] S20: Setting the width of the first rich text object according to the required spacing value.
[0033] The required spacing value is the spacing size that the user currently wants to set. Its specific value can be entered into the method object as an input parameter when calling the setting method of this embodiment. That is, each time the method object encapsulated based on the method is called, the required spacing value required for this spacing setting needs to be entered, which is convenient for flexible spacing control; when editing the current page, all the unified spacing that needs to be set in the page can be pre-set, and the spacing can be set according to the pre-set distance at the location where the spacing needs to be set, which is more suitable for page editing processes with unified regulations.
[0034] After determining the required spacing, the width of the first rich text object is adjusted to make it the same as the required spacing, ensuring that the spacing between the rich text objects meets the user's spacing requirements during subsequent splicing, and the spacing value can be accurate, fully meeting the user's spacing setting requirements.
[0035] In this embodiment, when setting the width of the first rich text object, a first font size can be first determined according to the currently required spacing value, and combined with the specific width of the first font size, the width of the first rich text object is set to the width of at least one preset type space under the first font size. It should be noted that the width of the first font size can usually be set to be the same as the required spacing value, or an integer multiple of the required spacing value, so as to facilitate the realization of satisfying the specific value of the required spacing through the width of an integer number of preset type spaces.
[0036] In some embodiments, when the preset type space is a full-width space, the first font size is the font size with the same font size as the required spacing value, that is, when a full-width space is input under the first font size, the width of the full-width space is the same as the width of a Chinese character under the first font size, and the value of its width does not change according to the type of font. At this time, when setting the width of the first rich text object, the width of the first rich text object can be set to the width of a full-width space, ensuring that the width of the full-width space is exactly the same as the required spacing value.
[0037] In some embodiments, when the preset type space is a half-width space, since the width of the half-width space is half of the font size under the current font size, the first font size determined at this time is the font size that is twice the required spacing. In this case, when setting the width of the first rich text object, the width of the first rich text object can be set to the width of the half-width space under the first font size. Since the font size of the first font size is twice the required spacing at this time, the width of the corresponding half-width space should be exactly the value of the required spacing.
[0038] In actual implementation, the method for determining the first font size and the method for setting the width of the first rich text object are not limited to the above methods. For example, when the first font size is a font size with the same font size as the required spacing, when setting the width of the first rich text object, it can also be achieved by setting the width of two half-width spaces under the first font size; or, the first font size can be a font size with a font size that is half of the required spacing, and when setting the width of the first rich text object, it can be achieved by setting two full-width spaces or four half-width spaces. In addition, the preset type of space can also include a one-third width space (encoded as U+2004), a one-quarter width space (encoded as U+2005), and a one-sixth width space (encoded as U+2006), etc. When the preset type of space currently used is different, the corresponding method for determining the first font size and adjusting the first rich text object is also different, but its implementation principle is the same as that of the full-width space or the half-width space, and this embodiment will not be repeated here.
[0039] S30: splice the first rich text object to the end of the current rich text object to form a space after the current rich text object.
[0040] The current rich text object can be any text object and / or image object edited by the user during the page editing process. After the user has finished editing the current rich text object and needs to insert spacing, the user calls the setting method provided in this embodiment. After the width of the first rich text object is adjusted to the required spacing, the first rich text object can be directly spliced after the current rich text object to form the spacing after the current rich text object, and other character objects can continue to be spliced after the first rich text object, finally achieving the spacing effect between rich text objects.
[0041] In some embodiments, for ease of use, the above method steps can be encapsulated into a method object, for example, the method object can be named addTextSpace; when the spacing after the current rich text object needs to be set, the method object is called and the required spacing value is passed into the method object, and then the method object executes the above method steps to achieve precise spacing control.
[0042] When spacing needs to be set, by calling the setting method provided in this embodiment, precise control of the required spacing can be achieved by setting the width of the first rich text object, and the spacing setting can be achieved by directly splicing the first rich text object after the current rich text object. There is no need for cumbersome parameter adjustments, and accurate spacing setting can be achieved on the basis of simplifying the spacing setting steps, thereby achieving better display effects.
[0043] Figure 2A schematic diagram of rich text using the setting method described in this embodiment to set the character spacing is shown. Among them, "Total Transaction" is a text object, and the pattern containing the letter "B" on its right is a picture object. When editing through rich text, after the text object is edited, the setting method of this embodiment can be called to set the first rich text object according to actual needs and splice it after the text object (that is, the right side of the text object in the figure), and continue to splice the picture object after the first rich text object, and the setting method can be called again according to needs to achieve spacing settings of different widths, and finally achieve rich text with mixed text and pictures. Through the method provided by this embodiment, when it is necessary to edit pictures and texts at the same time, it can be simply and quickly realized through the splicing of rich text objects, avoiding the effect of simultaneously arranging pictures and texts by stacking multiple view elements during the page compilation process, simplifying the overall process of page editing.
[0044] A second embodiment of the present disclosure provides a device for setting rich text spacing, which can be installed in an electronic device of any operating system, and the setting of rich text spacing can be achieved by calling the device. Figure 3 This is a structural schematic diagram of the device for setting rich text spacing in this embodiment, which mainly includes a creation module 10, a setting module 20 and a splicing module 30; wherein the creation module 10 is configured to create a first rich text object using a preset type of space; the setting module 20 is configured to set the width of the first rich text object according to the required spacing value; the splicing module 30 is configured to splice the first rich text object to after the current rich text object to form a spacing after the current rich text object.
[0045] Specifically, the preset type space can be any one of the following: full-width space encoded as U+3000; half-width space encoded as U+2002; one-third-width space encoded as U+2004; one-quarter-width space encoded as U+2005; one-sixth-width space encoded as U+2006. In addition, the width of the preset type space is only related to the current font size, and has nothing to do with the type of font.
[0046] In some embodiments, the setting module 20 is specifically configured to: determine the first font size according to the preset type space and the required spacing value: set the width of the first rich text object to the width of at least one of the preset type spaces under the first font size.
[0047] In some embodiments, the setting module 20 is specifically configured to: when the preset type space is a full-width space, determine the font size having the same font size as the required spacing value as the first font size.
[0048] In some embodiments, the setting module 20 is specifically configured to: when the preset type space is a half-width space, determine a font size that is twice the required spacing value as the first font size.
[0049] When spacing needs to be set, by calling the setting device provided in this embodiment, precise control of the required spacing can be achieved by setting the width of the first rich text object, and the spacing setting can be achieved by directly splicing the first rich text object after the current rich text object. There is no need for cumbersome parameter adjustments, and accurate spacing setting can be achieved on the basis of simplifying the spacing setting steps, thereby achieving better display effects.
[0050] The third embodiment of the present disclosure provides a storage medium, which can be installed in any electronic device, and is specifically a computer-readable medium, storing a computer program, and when the computer program is executed by a processor, the method provided by any embodiment of the present disclosure is implemented, including the following steps S31 to S33:
[0051] S31, creating a first rich text object using a preset type space, wherein the width of the preset type space is associated with the font size;
[0052] S32, setting the width of the first rich text object according to the required spacing value;
[0053] S33: splice the first rich text object to the end of the current rich text object to form a space after the current rich text object.
[0054] Specifically, the preset type space is: a full-width space encoded as U+3000; or a half-width space encoded as U+2002. Alternatively, the preset type space can be any one of a one-third-width space encoded as U+2004, a one-quarter-width space encoded as U+2005, and a one-sixth-width space encoded as U+2006.
[0055] When the computer program is executed by the processor to set the width of the first rich text object according to the required spacing value, the processor specifically executes the following steps: determining the first font size based on the preset type space and the required spacing value: setting the width of the first rich text object to the width of at least one preset type space under the first font size.
[0056] In the case where the preset type space is a full-width space, when the computer program is executed by the processor to determine the first font size, the processor specifically executes the following steps: determining a font size having the same font size as the required spacing value as the first font size.
[0057] In the case where the preset type space is a half-width space, when the computer program is executed by the processor to determine the first font size, the processor specifically executes the following steps: determining a font size that is the same as twice the required spacing value as the first font size.
[0058] The computer program is also executed by the processor as follows: encapsulating the aforementioned method steps into a method object; when the spacing after the current rich text object needs to be set, calling the method object and passing the required spacing value to the method object, and then the method object executes the aforementioned method steps.
[0059] When spacing needs to be set, by calling the setting method provided in this embodiment, precise control of the required spacing can be achieved by setting the width of the first rich text object, and the spacing setting can be achieved by directly splicing the first rich text object after the current rich text object. There is no need for cumbersome parameter adjustments, and accurate spacing setting can be achieved on the basis of simplifying the spacing setting steps, thereby achieving better display effects.
[0060] The fourth embodiment of the present disclosure provides an electronic device, which can have any operating system such as iOS, Android, Windows, Linux, etc., and its structural diagram is as follows: Figure 4 As shown, at least a memory 100 and a processor 200 are included. The memory 100 stores a computer program. The processor 200 implements the method provided by any embodiment of the present disclosure when executing the computer program on the memory 100. Exemplarily, the steps of the electronic device computer program are as follows S41 to S43:
[0061] S41, creating a first rich text object using a preset type space, wherein the width of the preset type space is associated with the font size;
[0062] S42, setting the width of the first rich text object according to the required spacing value;
[0063] S43: splice the first rich text object to the end of the current rich text object to form a space after the current rich text object.
[0064] Specifically, the preset type space is: a full-width space encoded as U+3000; or, a half-width space encoded as U+2002. Alternatively, the preset type space can be any one of a one-third-width space encoded as U+2004, a one-quarter-width space encoded as U+2005, and a one-sixth-width space encoded as U+2006. When the processor sets the width of the first rich text object according to the required spacing value stored in the execution memory, the processor specifically executes the following computer program: determine the first font size according to the preset type space and the required spacing value: set the width of the first rich text object to the width of at least one preset type space under the first font size.
[0065] When the preset type space is a full-width space, the processor specifically executes the following computer program when executing the determination of the first font size stored in the memory: determining the font size having the same font size as the required spacing value as the first font size.
[0066] When the preset type space is a half-width space, the processor, when executing the determination of the first font size stored in the memory, specifically executes the following computer program: determining a font size that is the same as twice the required spacing value as the first font size.
[0067] The processor also executes the following computer program stored in the memory: encapsulating the aforementioned method steps into a method object; when the spacing after the current rich text object needs to be set, calling the method object and passing the required spacing value to the method object, and then the method object executes the aforementioned method steps.
[0068] When spacing needs to be set, by calling the setting method provided in this embodiment, precise control of the required spacing can be achieved by setting the width of the first rich text object, and the spacing setting can be achieved by directly splicing the first rich text object after the current character object. There is no need for cumbersome parameter adjustments, and accurate spacing setting can be achieved on the basis of simplifying the spacing setting steps, thereby achieving better display effects.
[0069] Multiple embodiments of the present disclosure are described in detail above, but the present disclosure is not limited to these specific embodiments. Those skilled in the art can make various variations and modifications to the embodiments based on the concepts of the present disclosure, and these variations and modifications should all fall within the scope of protection required by the present disclosure.
Claims
1. A method for setting rich text spacing, characterized in that: The method comprises the following steps: Creating a first rich text object using a preset type space, wherein the width of the preset type space is associated with the font size; Setting the width of the first rich text object according to a required spacing value, where the required spacing value is an integer multiple of the width of the preset type of space; splicing the first rich text object to the end of the current rich text object to form a space after the current rich text object; The step of setting the width of the first rich text object according to the required spacing value includes: Determining a first font size according to the preset type of space and the required spacing value; The width of the first rich text object is set to the width of at least one of the preset type spaces under the first font size.
2. The method according to claim 1, characterized in that The preset type space is any one of the following: The full-width space is encoded as U+3000; Encoded as U+2002 Half-width Space; Encoded as U+2004 ONE-THIRD WIDTH SPACE; Encoded as U+2005 Quarter Width Space; Encoded as U+2006 6th-width SPACE 3. The method according to claim 1, characterized in that When the preset type of space is a full-width space, determining the first font size includes: A font size having the same font size as the required spacing value is determined as the first font size.
4. The method according to claim 1, characterized in that: Also includes: When the preset type of space is a half-width space, determining the first font size includes: A font size that is the same as twice the required spacing value is determined as the first font size.
5. The method according to any one of claims 1 to 4, characterized in that The method further includes: Encapsulate the above method steps into a method object; When it is necessary to set the spacing after the current rich text object, the method object is called and the required spacing value is passed to the method object, and then the method object executes the above method steps.
6. A device for setting rich text spacing, characterized in that: include: A creation module is configured to create a first rich text object using a preset type space, wherein the width of the preset type space is associated with the font size; A setting module, configured to set the width of the first rich text object according to a required spacing value, where the required spacing value is an integer multiple of the width of the preset type of space; A splicing module, configured to splice the first rich text object to the back of the current rich text object to form a space after the current rich text object; The setting module is specifically used for: Determining a first font size according to the preset type of space and the required spacing value; The width of the first rich text object is set to the width of at least one of the preset type spaces under the first font size.
7. A storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the steps of the method for setting rich text spacing according to any one of claims 1 to 5 are implemented.
8. An electronic device comprising at least a memory and a processor, wherein a computer program is stored in the memory, wherein: The processor implements the steps of the method for setting rich text spacing according to any one of claims 1 to 5 when executing the computer program on the memory.
