Method and apparatus for calculating data width, and device and storage medium
By traversing the character set to obtain the predicted width or measuring the current width in real time, the problem of low efficiency in calculating string width in existing technologies is solved, and more efficient width calculation is achieved.
Patent Information
- Application Number
- PCT/CN2024/094424
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- Priority Date
- 2023-05-23
- Filing Date
- 2024-05-21
- Publication Date
- 2024-11-28
AI Technical Summary
Existing technologies are inefficient in calculating string width, especially when the string is long or there are highly similar strings, requiring the width of each string to be remeasured, resulting in long calculation times.
By iterating through each character in the data to be measured, it is determined whether the predicted character set includes the character. If it exists, the predicted width is obtained; otherwise, the current width is measured, and the widths of the characters are summed to calculate the total width of the data to be measured.
It improves the efficiency of calculating string width and shortens the calculation time, especially when dealing with a large number of similar strings, thus improving the accuracy and efficiency of measurement.
Smart Images

Figure CN2024094424_28112024_PF_FP_ABST
Abstract
Description
Method, device, equipment and storage medium for calculating data width
[0001] This application claims priority to Chinese Patent Application No. 202310588337.8 filed on May 23, 2023, and the contents of the above-mentioned Chinese patent application disclosure are hereby incorporated by reference in their entirety as a part of this application. Technical Field
[0002] Embodiments of the present disclosure relate to a method, apparatus, device, and storage medium for calculating data width. Background Art
[0003] When plotting chart data, it's sometimes necessary to calculate the text width in order to properly display the text. Related technologies typically calculate the text width of a string by directly measuring the width of the entire string. This results in a long calculation time and low efficiency for long strings. When measuring multiple strings with high similarity, the width of each string must be remeasured each time, resulting in low width measurement efficiency.
[0004] Summary of the Invention
[0005] In view of this, embodiments of the present disclosure provide a method, apparatus, device, and storage medium for calculating data width.
[0006] To achieve the above objectives, the embodiments of the present disclosure provide the following technical solutions:
[0007] An embodiment of the present disclosure provides a method for calculating data width, the method comprising:
[0008] Traversing each character in the data to be measured, for any character, determining whether the character is included in a predicted character set, the predicted character set including a plurality of predicted characters and a predicted width corresponding to each predicted character;
[0009] If yes, obtaining the predicted width of the character in the predicted character set; otherwise, measuring the current width of the character;
[0010] The predicted width or the current width of each character in the data to be measured is summed to obtain the width of the data to be measured.
[0011] In one possible implementation, each predicted character in the predicted character set includes multiple formats, each format of the predicted character corresponds to a predicted width, and the predicted characters include: preset symbols, time series, numbers, English letters, full-width characters, half-width characters and at least one of Chinese characters.
[0012] In a possible implementation, when the pre-measured character includes a number, the process of determining the pre-measured width of the number includes:
[0013] Obtaining a width of a preset digital sequence, wherein the preset digital sequence includes all the numbers 0, 1, 2, ..., 8, and 9;
[0014] The width of the preset digital sequence is divided by the number of numbers included in the preset digital sequence to determine the predicted measurement width of the numbers.
[0015] In a possible implementation, when the pre-measured characters include English letters, the process of determining the pre-measured widths of the English letters includes:
[0016] Obtain the width of a preset letter sequence, where the preset letter sequence includes all English letters A, B, C, ..., X, Y, and Z;
[0017] The predicted width of the English letters is determined by dividing the width of the preset letter sequence by the number of English letters included in the preset letter sequence.
[0018] In a possible implementation, when the data to be measured includes Chinese characters, the process of determining the width of the Chinese characters includes:
[0019] Determining whether the predicted character set includes Chinese characters;
[0020] If yes, then obtaining the predicted width of the Chinese character in the predicted character set; otherwise, measuring the current width of the Chinese character.
[0021] In a possible implementation, the method further includes:
[0022] The Chinese character and the current width of the Chinese character are stored in the pre-measured character set.
[0023] In a possible implementation, measuring the current width of the character includes:
[0024] The current width of the character is calculated using the canvas.
[0025] In a possible implementation, the format of the predicted character includes at least one of: font size, italicization, boldness, and font.
[0026] An embodiment of the present disclosure provides a device for calculating data width, the device comprising:
[0027] a judgment unit, configured to traverse each character in the data to be measured and, for any character, determine whether the character is included in a predicted character set, wherein the predicted character set includes a plurality of predicted characters and a predicted width corresponding to each predicted character;
[0028] an acquiring unit, configured to acquire the predicted width of the character in the predicted character set if yes; otherwise, measure the current width of the character;
[0029] The calculation unit is used to sum the predicted width or current width of each character in the data to be measured to obtain the width of the data to be measured.
[0030] In one possible implementation, each predicted character in the predicted character set includes multiple formats, each format of the predicted character corresponds to a predicted width, and the predicted characters include: preset symbols, time series, numbers, English letters, full-width characters, half-width characters and at least one of Chinese characters.
[0031] In one possible implementation, when the predicted characters include numbers, the process of determining the predicted width of the numbers includes: obtaining the width of a preset number sequence, the preset number sequence including all numbers from 0, 1, 2, ..., 8, 9; and determining the predicted width of the numbers by dividing the width of the preset number sequence by the number of numbers included in the preset number sequence.
[0032] In one possible implementation, when the predicted characters include English letters, the process of determining the predicted width of the English letters includes: obtaining the width of a preset letter sequence, wherein the preset letter sequence includes all English letters in A, B, C,..., X, Y, Z; and determining the predicted width of the English letters by dividing the width of the preset letter sequence by the number of English letters included in the preset letter sequence.
[0033] In one possible implementation, when the data to be measured includes Chinese characters, the process of determining the width of the Chinese characters includes: judging whether the predicted character set includes Chinese characters; if so, obtaining the predicted width of the Chinese characters in the predicted character set; otherwise, measuring the current width of the Chinese characters.
[0034] In a possible implementation, the device further includes: a storage unit;
[0035] The storage unit is used to store the Chinese character and the current width of the Chinese character in the pre-measured character set.
[0036] In a possible implementation, the acquisition unit is specifically configured to calculate the current width of the character using a canvas.
[0037] In a possible implementation, the format of the predicted character includes at least one of: font size, italicization, boldness, and font.
[0038] An embodiment of the present disclosure provides an electronic device, the device comprising: a processor and a memory;
[0039] The memory is used to store instructions or computer programs;
[0040] The processor is configured to execute the instructions or computer program in the memory so that the electronic device executes the method described in the first aspect above.
[0041] An embodiment of the present disclosure provides a computer-readable storage medium, wherein instructions are stored in the computer-readable storage medium. When the instructions are executed on a device, the device executes the method described in the first aspect above.
[0042] An embodiment of the present disclosure provides a computer program product, which includes a computer program / instructions. When the computer program / instructions are executed by a processor, the method described in the first aspect is implemented. BRIEF DESCRIPTION OF THE DRAWINGS
[0043] In order to more clearly illustrate the embodiments of the present disclosure or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. 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 any creative work.
[0044] FIG1 is a flow chart of a method for calculating data width provided by an embodiment of the present disclosure;
[0045] FIG2 is a schematic diagram of a device for calculating data width provided by an embodiment of the present disclosure; and
[0046] FIG3 is a schematic structural diagram of an electronic device provided by an embodiment of the present disclosure. DETAILED DESCRIPTION
[0047] In order to enable those skilled in the art to better understand the solutions of the present disclosure, the technical solutions in the embodiments of the present disclosure will be clearly and completely described below in conjunction with the drawings in the embodiments of the present disclosure. Obviously, the embodiments described are only part of the embodiments of the present disclosure, not all of the embodiments. All other embodiments obtained by ordinary technicians in this field based on the embodiments of the present disclosure without making any creative efforts shall fall within the scope of protection of the present disclosure.
[0048] Related technologies typically calculate the width of a string by directly measuring the width of the entire string. This results in a long calculation time and low efficiency for long strings. When measuring multiple strings with high similarity, the width of each string must be remeasured each time, resulting in low width measurement efficiency.
[0049] Based on this, an embodiment of the present disclosure provides a method for calculating data width to improve the efficiency of width calculation. In specific implementation, when measuring the width of the data to be measured, a method is adopted in which each character in the data to be measured is traversed. For any character, it is determined whether the character is included in the predicted character set. The predicted character set includes multiple predicted characters and the predicted width corresponding to each predicted character. In other words, the width of certain characters can be pre-measured and stored in the predicted character set. When traversing each character in the data to be measured, if the character is included in the predicted character set, the predicted width corresponding to the character is obtained in the predicted character set; otherwise, the current width of the character is obtained in real time. The width of each character in the data to be measured is determined in the above manner, which can be the predicted width or the current width. The width of each character is then summed to obtain the width of the data to be measured. Through the method provided by the present disclosure, the width of certain characters can be measured in advance and stored. In this way, when calculating the width of the data to be measured, the character width can be directly obtained or measured in real time for each character. Compared with the related art of directly measuring the width of the entire string, this improves efficiency.
[0050] To facilitate understanding of the technical solutions provided by the embodiments of the present disclosure, a detailed description will be given below with reference to the accompanying drawings.
[0051] Refer to FIG1 , which is a flowchart of a method for calculating data width provided by an embodiment of the present disclosure.
[0052] The method can be executed by a data processing device, which can be a terminal or a server. The terminal includes but is not limited to a desktop computer, a laptop computer, a tablet computer, and a smartphone. The server can be a cloud server in a cloud environment, such as a central server in a central cloud computing cluster, or an edge server in an edge cloud computing cluster. Of course, the server can also be a server in a local data center, where the so-called local data center refers to the data center to which the user belongs. It should also be noted that the server can be a single server or a server cluster formed by multiple servers.
[0053] The method may include the following steps:
[0054] S101: traverse each character in the data to be measured, and for any character, determine whether the character is included in the predicted measurement character set.
[0055] The data to be measured may be a character string including one or more characters. When calculating the width of the data to be measured, the width of each character in the data to be measured is determined one by one.
[0056] In this embodiment, the widths of certain frequently occurring or formatted characters can be pre-measured and stored in a pre-measurement set. This allows for the character and its corresponding width to be directly retrieved from the pre-measurement set when traversing the characters in the data to be measured. This allows for the character's width to be directly retrieved from the pre-measurement set without requiring a new measurement. In other words, the pre-measurement set includes multiple pre-measurement characters and the pre-measurement width corresponding to each pre-measurement character.
[0057] In one possible implementation, the pre-measured characters may include one or more of preset symbols, time series, numbers, English letters, full-width characters, half-width characters, and Chinese characters. Among them, the preset symbols may be some special symbols, such as "-", " / ", ":", and space "". The time series may be a date or a time point, and time series of different forms may be pre-measured. For example, the date may be expressed as "2023-5-1" or "2023 / 5 / 1", and the time point may be expressed as "hour: minute: second", for example, the time point of 11:25:30 am is expressed as "11:25:30".
[0058] It should be noted that each pre-measured character can include multiple formats, and each format corresponds to a pre-measured width. Formats can include font size, italicization, bolding, font, etc. For example, a number with a font size of 4 may have a different width than a number with a font size of 8. Similarly, a Chinese character with a Songti font may have a different width than a Chinese character with a Kaiti font. In other words, a pre-measured width must be calculated for each pre-measured character with different formats.
[0059] In one possible implementation, the predicted width of a character can be calculated using a canvas. Canvas is a new tag in HTML5 that can be used to generate images in real time on a web page. It defines an application programming interface (API) to support scripted client drawing operations, allowing the client to use JavaScript to draw the graphics, characters, text and other objects it wants to draw onto the Canvas. Then call the built-in function of Canvas, such as the measure Text() method, to calculate the width of the measured character. That is, when using Canvas to calculate the width of a character, you need to draw the character on the canvas first, and then calculate the width of the character. When creating a canvas to draw the character, you can pre-set the format of the character, such as the font size, font, etc., so that the width of characters in different formats can be determined.
[0060] It should be noted that the method for calculating character width provided in the above embodiment is merely an exemplary description and is not limited to the above implementation. Other algorithms for calculating character width are also within the scope of protection of this disclosure. For example, the clientWidth function can also be used to calculate the width of a character, which will not be described in detail here.
[0061] To facilitate understanding of how to determine the pre-measurement width, several different pre-measurement characters will be used for illustration below.
[0062] In one possible implementation, when the predicted characters include numbers, determining the predicted width of the numbers can be achieved by obtaining a preset number sequence and calculating the width of the preset number sequence, wherein the preset number sequence includes all ten numbers from 0, 1, 2, ..., 8, and 9, with each number appearing a number greater than or equal to 1. The width of the preset number sequence is then divided by the number of numbers in the preset number sequence to determine the average width of the numbers, which is used as the predicted width of the numbers. The above measurement is performed for numbers of different formats to obtain the predicted widths corresponding to the numbers of different formats.
[0063] When the data to be measured includes any number, the predicted measurement width of the number in the corresponding format can be obtained from the predicted measurement set according to the format of the number, as the width of each number in the data to be measured.
[0064] Optionally, when high accuracy is required in calculating the width of the data to be measured, the width corresponding to each of the ten digits 0-9 can be pre-measured, and then each digit and its corresponding width can be stored in a pre-measured character set. When the data to be measured includes a digit, the pre-measured width corresponding to the digit can be obtained from the pre-measured character set, thereby improving the accuracy of determining the width of each digit in the data to be measured, and thus improving the accuracy of calculating the width of the data to be measured.
[0065] In one possible implementation, when the predicted characters include English letters, the predicted widths of the English letters can be determined by obtaining a preset letter sequence and calculating the width of the preset letter sequence, wherein the preset letter sequence includes all English letters of the twenty-six English letters A, B, C, ..., X, Y, and Z, and the number of occurrences of each English letter is greater than or equal to 1. The width of the preset letter sequence is then divided by the number of English letters included in the preset letter sequence to determine an average width of the English letters, which is used as the predicted width of the English letters.
[0066] When the data to be measured includes any English letters, the predicted width corresponding to the English letters in the corresponding format can be obtained from the predicted measurement set according to the format of the English letters, as the width of each English letter in the data to be measured.
[0067] Similarly, when higher accuracy is required in calculating the width of the data to be measured, the width corresponding to each of the 26 English letters (A to Z) can be pre-measured, and then each letter and its corresponding width can be stored in a pre-measured character set. When the data to be measured includes English letters, the pre-measured width corresponding to each letter can be obtained from the pre-measured character set, thereby improving the accuracy of determining the width of each English letter in the data to be measured, and thus improving the accuracy of calculating the width of the data to be measured.
[0068] The above embodiment introduces a method for determining the predicted width of uppercase English letters. Optionally, to further improve the accuracy of the width of the data to be measured, the predicted widths of lowercase English letters a, b, c, ..., x, y, and z can also be pre-measured. The principle of measuring the predicted width of lowercase English letters is the same as that of measuring the predicted width of uppercase and lowercase English letters. The specific implementation method can be found in the above steps and will not be repeated here. When the data to be measured includes uppercase English letters or lowercase English letters, the predicted width corresponding to the uppercase English letters or lowercase English letters can be obtained, thereby improving the accuracy of calculating the data to be measured.
[0069] In a possible implementation, when the predicted character includes Chinese characters, any one Chinese character can be selected, and the width of the Chinese character can be measured as the predicted width of each Chinese character. And for Chinese characters in different formats, a predicted width is measured. For example, Chinese characters with different font sizes, different fonts, bold, and italic are all measured with a predicted width and stored in the predicted character set. That is, for the prediction of Chinese characters, only different formats can be distinguished, and the content of Chinese characters is not distinguished. For example, the predicted widths corresponding to the Chinese characters "你" and "我" in the same format are the same.
[0070] When the data to be measured includes any Chinese character, the predicted width corresponding to the Chinese character in the corresponding format can be obtained from the predicted set according to the format of the Chinese character as the width of each Chinese character in the data to be measured.
[0071] S102: If the character is included in the predicted character set, obtain the predicted width of the character from the predicted character set; otherwise, obtain the current width of the character.
[0072] In the above embodiment, the method for determining the predicted width of each character in the predicted character is introduced. When traversing the characters in the data to be measured, if the character is included in the predicted character set, obtain the predicted width of the character from the predicted character set. Among them, since each character can have different formats, the character with the same format can be found in the predicted character set according to the format corresponding to the character, and the predicted width of the character with the same format can be obtained as the width of the character. If the character is not included in the predicted character set, the current width of the character can be measured in real time. For example, the Canvas method can be used to calculate the width of the character.
[0073] Optionally, when the current width of the character is calculated, the character and the current width can be stored in the predicted character set, which is convenient for directly calling in the predicted set when determining the width of the same character later, without having to recalculate.
[0074] When determining the predicted width of Chinese characters in the above embodiment, any one Chinese character can be selected for measurement. Optionally, in order to improve the accuracy of calculating the width of the data to be measured, when the data to be measured includes Chinese characters, both the format of Chinese characters and the content of Chinese characters can be distinguished, that is, only when the Chinese characters are exactly the same, they correspond to the same width.
[0075] For the Chinese characters in the data to be measured, determine whether the predicted character set includes Chinese characters that are exactly the same as the Chinese characters (same format, same content). If included, the predicted width of the Chinese character can be obtained in the predicted character set; otherwise, the current width of the Chinese character is obtained.
[0076] When the data to be measured includes multiple Chinese characters, the same Chinese characters may exist. Optionally, the current width of the measured Chinese character can be stored together with the Chinese character in a pre-measured character set. Therefore, when the same Chinese character is traversed in the data to be measured, there is no need to calculate the width again, and it can be directly obtained in the pre-measured character set, that is, it can be measured and stored in real time, thereby improving the efficiency and accuracy of calculating the width of the data to be measured.
[0077] S103: Sum the predicted width or current width of each character in the data to be measured to obtain the width of the data to be measured.
[0078] After the width of each character in the data to be measured is determined, the width of each character can be summed up to determine the width of the data to be measured, which can be the predicted width or the current width.
[0079] In a possible implementation, when the data to be measured includes unrecognizable characters or emoticons, the unrecognizable characters or emoticons may be converted into one of preset symbols, for example, into “-”, so that the width of the data to be measured can be calculated.
[0080] Through the method provided by the present disclosure, the widths of certain characters can be measured in advance and stored. In this way, when calculating the width of the data to be measured, the character width can be directly obtained for each character or measured in real time. Compared with the related art of directly measuring the width of the entire character string, the calculation efficiency is improved.
[0081] In one possible application scenario, 1,000 character strings can be randomly generated for testing to ensure that the randomly generated character strings include numbers, English letters, and Chinese characters. In this application scenario, the predicted width of numbers in the present disclosure is the average width of numbers, the predicted width of English letters is the average width of letters, and the predicted width of Chinese characters is the width of any Chinese character. The results of calculating the width of the entire character string using the existing technology and the calculation results using the method of this embodiment are shown in Table 1, including the error mean, error variance, and time for calculating the width of the 1,000 character strings, where the unit of width error is pixel px and the unit of time is millisecond ms.
[0082] Table 1
[0083] It can be seen that the method provided by the embodiment of the present disclosure can shorten the calculation time and improve the calculation efficiency while meeting the measurement accuracy.
[0084] Based on the above method embodiment, the present disclosure also provides a device for calculating data width. Referring to FIG2 , FIG2 is a schematic diagram of a device for calculating data width provided by the present disclosure.
[0085] The device 200 may include: a judgment unit 201 , an acquisition unit 202 , and a calculation unit 203 .
[0086] The judgment unit 201 is configured to traverse each character in the data to be measured, and for each character, determine whether the character is included in the predicted character set, the predicted character set including a plurality of predicted characters and a predicted width corresponding to each predicted character;
[0087] The obtaining unit 202 is configured to obtain the predicted width of the character in the predicted character set if yes; otherwise, measure the current width of the character;
[0088] The calculation unit 203 is configured to sum the predicted width or current width of each character in the data to be measured to obtain the width of the data to be measured.
[0089] In one possible implementation, each predicted character in the predicted character set includes multiple formats, each format of the predicted character corresponds to a predicted width, and the predicted characters include: preset symbols, time series, numbers, English letters, full-width characters, half-width characters and at least one of Chinese characters.
[0090] In one possible implementation, when the predicted characters include numbers, the process of determining the predicted width of the numbers includes: obtaining the width of a preset number sequence, the preset number sequence includes all numbers from 0, 1, 2,..., 8, 9; and determining the predicted width of the numbers by dividing the width of the preset number sequence by the number of numbers included in the preset number sequence.
[0091] In one possible implementation, when the predicted characters include English letters, the process of determining the predicted width of the English letters includes: obtaining the width of a preset letter sequence, the preset letter sequence includes all English letters in A, B, C,..., X, Y, Z; and determining the predicted width of the English letters by dividing the width of the preset letter sequence by the number of English letters included in the preset letter sequence.
[0092] In one possible implementation, when the data to be measured includes Chinese characters, the process of determining the width of the Chinese characters includes: determining whether the predicted character set includes Chinese characters; if so, obtaining the predicted width of the Chinese characters in the predicted character set; otherwise, measuring the current width of the Chinese characters.
[0093] In a possible implementation, the apparatus further includes: a storage unit;
[0094] The storage unit is configured to store the Chinese character and the current width of the Chinese character in a pre-measured character set.
[0095] In a possible implementation, the obtaining unit 202 is specifically configured to calculate the current width of the character using the canvas Canvas.
[0096] In a possible implementation, the format of the pre-measured characters includes at least one of: font size, italicization, boldness, and font.
[0097] The beneficial effects of the device for calculating data width provided by the embodiment of the present disclosure can be found in the above method embodiment and will not be described in detail here.
[0098] It should be noted that the specific implementation of each unit in this embodiment can refer to the relevant description in the above-mentioned method embodiment. The division of units in the embodiment of the present disclosure is schematic and is only a logical function division. There may be other division methods in actual implementation. The functional units in the embodiment of the present disclosure can be integrated into a processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. For example, in the above-mentioned embodiment, the processing unit and the sending unit can be the same unit or different units. The above-mentioned integrated units can be implemented in the form of hardware or in the form of software functional units.
[0099] Referring to FIG3 , a schematic diagram of the structure of an electronic device 300 suitable for implementing embodiments of the present disclosure is shown. Terminal devices in embodiments of the present disclosure may include, but are not limited to, mobile terminals such as mobile phones, laptop computers, digital broadcast receivers, PDAs (personal digital assistants), PADs (tablet computers), PMPs (portable multimedia players), in-vehicle terminals (e.g., in-vehicle navigation terminals), and fixed terminals such as digital TVs and desktop computers. The electronic device shown in FIG3 is merely an example and should not limit the functionality or scope of use of embodiments of the present disclosure.
[0100] As shown in Figure 3, the electronic device 300 may include a processing device (e.g., a central processing unit, a graphics processing unit, etc.) 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 a storage device 308 into a random access memory (RAM) 303. Various programs and data required for the operation of the electronic device 300 are also stored in the RAM 303. The processing device 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.
[0101] Typically, the following devices may be connected to the I / O interface 305: an input device 306 including, for example, a touch screen, a touchpad, a keyboard, a mouse, a camera, a microphone, an accelerometer, a gyroscope, etc.; an output device 307 including, for example, a liquid crystal display (LCD), a speaker, a vibrator, etc.; a storage device 308 including, for example, a magnetic tape, a hard disk, etc.; and a communication device 309. The communication device 309 may allow the electronic device 300 to communicate with other devices wirelessly or by wire to exchange data. Although FIG3 shows the electronic device 300 with various devices, it should be understood that not all of the devices shown are required to be implemented or present. More or fewer devices may alternatively be implemented or present.
[0102] In particular, according to an embodiment of the present disclosure, the process described above with reference to the flowchart can be implemented as a computer software program. For example, an embodiment of the present disclosure includes a computer program product, which includes a computer program carried on a non-transitory computer-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 the network through the communication device 309, or installed from the storage device 308, or installed from the ROM 302. When the computer program is executed by the processing device 301, the above-mentioned functions defined in the method of the embodiment of the present disclosure are performed.
[0103] The electronic device provided by the embodiment of the present disclosure and the method provided by the above embodiment belong to the same inventive concept. For technical details not fully described in this embodiment, please refer to the above embodiment, and this embodiment has the same beneficial effects as the above embodiment.
[0104] An embodiment of the present disclosure provides a computer storage medium having a computer program stored thereon. When the program is executed by a processor, the method provided in the above embodiment is implemented.
[0105] It should be noted that the computer-readable medium mentioned above in the present disclosure may be a computer-readable signal medium or a computer-readable storage medium, or any combination of the two. A computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device, or component, 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. In the present disclosure, a computer-readable storage medium may be any tangible medium that contains or stores a program that can be used by or in conjunction with an instruction execution system, device, or component. In the present disclosure, a computer-readable signal medium may include a data signal propagated in baseband or as part of a carrier wave, which carries computer-readable program code. Such a propagated data signal 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 that can transmit, propagate, or transport a program for use by or in conjunction with an instruction execution system, apparatus, or device. The program code contained on the computer-readable medium may be transmitted using any suitable medium, including but not limited to wires, optical cables, RF (radio frequency), etc., or any suitable combination thereof.
[0106] In some embodiments, the client and server can communicate using any currently known or later developed network protocol, such as HTTP (Hypertext Transfer Protocol), and can be interconnected with any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include a local area network ("LAN"), a wide area network ("WAN"), an internet (e.g., the Internet), and a peer-to-peer network (e.g., an ad hoc peer-to-peer network), as well as any currently known or later developed network.
[0107] The computer-readable medium may be included in the electronic device, or may exist independently without being incorporated into the electronic device.
[0108] The computer-readable medium carries one or more programs. When the one or more programs are executed by the electronic device, the electronic device can perform the method.
[0109] Computer program code for performing the operations of the present disclosure may be written in one or more programming languages, or a combination thereof, including, but not limited to, object-oriented programming languages such as Java, Smalltalk, C++, and conventional procedural programming languages such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a stand-alone software package, partially on the user's computer and partially on a remote computer, or entirely on the remote computer or server. In cases involving a remote computer, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., through the Internet using an Internet service provider).
[0110] The flowcharts and block diagrams in the accompanying drawings illustrate the possible implementation architecture, functions and operations of the systems, methods and computer program products according to various embodiments of the present disclosure. In this regard, each box in the flowchart or block diagram can represent a module, program segment, or a part of code, and the module, program segment, or a part of 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 than that 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 system that performs the specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0111] The units involved in the embodiments described in this disclosure may be implemented in software or hardware, wherein the name of a unit / module does not, in some cases, limit the unit itself.
[0112] The functions described above herein may be performed, at least in part, by one or more hardware logic components. For example, and without limitation, exemplary types of hardware logic components that may be used include: field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chip (SOCs), complex programmable logic devices (CPLDs), and the like.
[0113] In the context of the present disclosure, a machine-readable medium can be a tangible medium that can contain or store a program for use by or in conjunction with an instruction execution system, device or equipment. A machine-readable medium can be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium can include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or equipment, or any suitable combination of the foregoing. A more specific example of a machine-readable storage medium can include an electrical connection based on one or more lines, 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 foregoing.
[0114] It should be noted that the various embodiments in this specification are described in a progressive manner, with each embodiment focusing on the differences from other embodiments. Reference can be made to the common and similar parts between the various embodiments. For the systems or devices disclosed in the embodiments, since they correspond to the methods disclosed in the embodiments, the description is relatively simple, and the relevant parts can be referred to the method description.
[0115] It should be understood that in the present disclosure, "at least one (item)" refers to one or more, and "plurality" refers to two or more. "And / or" is used to describe the association relationship of associated objects, indicating that three relationships may exist. For example, "A and / or B" can mean: only A exists, only B exists, and A and B exist at the same time, where A and B can be singular or plural. The character " / " generally indicates that the previous and next associated objects are in an "or" relationship. "At least one of the following items" or similar expressions refers to any combination of these items, including any combination of single items or plural items. For example, at least one of a, b or c can mean: a, b, c, "a and b", "a and c", "b and c", or "a and b and c", where a, b, c can be single or multiple.
[0116] It should also be noted that, in this document, relational terms such as first and second, etc., are used only to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "comprises," "comprising," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or device comprising a series of elements includes not only those elements, but also other elements not explicitly listed, or elements inherent to such process, method, article, or device. In the absence of further limitations, an element defined by the phrase "comprising a ..." does not exclude the presence of additional identical elements in the process, method, article, or device comprising the element.
[0117] The steps of the methods or algorithms described in conjunction with the embodiments disclosed herein may be implemented directly using hardware, a software module executed by a processor, or a combination of the two. The software module may be placed in a random access memory (RAM), internal memory, read-only memory (ROM), electrically programmable ROM, electrically erasable programmable ROM, registers, a hard disk, a removable disk, a CD-ROM, or any other form of storage medium known in the art.
[0118] The above description of the disclosed embodiments is intended to enable one skilled in the art to implement or use the present disclosure. Various modifications to these embodiments will be readily apparent to one skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present disclosure. Therefore, the present disclosure is not limited to the embodiments shown herein, but is intended to be construed in the widest manner consistent with the principles and novel features disclosed herein.
Claims
1. A method for calculating data width, comprising: Traversing each character in the data to be measured, for any character, determining whether the character is included in the predicted measurement character set, wherein the predicted measurement character set includes a plurality of predicted measurement characters and a predicted measurement width corresponding to each predicted measurement character; If the character is included in the predicted character set, the predicted width of the character is obtained in the predicted character set; if the character is not included in the predicted character set, the current width of the character is measured; The predicted width or the current width of each character in the data to be measured is summed to obtain the width of the data to be measured.
2. The method according to claim 1, wherein: Each predicted measurement character in the predicted measurement character set includes multiple formats, each format of the predicted measurement character corresponds to a predicted measurement width, and the predicted measurement characters include: at least one of: preset symbols, time series, numbers, English letters, full-width characters, half-width characters and Chinese characters.
3. The method according to claim 2, wherein: When the pre-measured characters include numbers, the process of determining the pre-measured width of the numbers includes: Obtaining a width of a preset digital sequence, wherein the preset digital sequence includes all the numbers in 0, 1, 2, ..., 8, 9; The predicted measurement width of the numbers is determined by dividing the width of the preset number sequence by the number of numbers included in the preset number sequence.
4. The method according to claim 2, wherein: When the predicted characters include English letters, determining the predicted widths of the English letters comprises: Obtaining the width of a preset letter sequence, wherein the preset letter sequence includes all English letters in A, B, C, ..., X, Y, Z; The predicted width of the English letters is determined by dividing the width of the preset letter sequence by the number of English letters included in the preset letter sequence.
5. The method according to claim 2, wherein: When the data to be measured includes Chinese characters, determining the width of the Chinese characters includes: Determining whether the predicted character set includes Chinese characters; In the case where the predicted character set includes Chinese characters, the predicted width of the Chinese characters in the predicted character set is obtained; in the case where the predicted character set does not include Chinese characters, the current width of the Chinese characters is measured.
6. The method according to claim 5, further comprising: The Chinese character and the current width of the Chinese character are stored in the pre-measured character set.
7. The method according to any one of claims 1 to 6, wherein: The measuring the current width of the character comprises: The current width of the character is calculated using the canvas Canvas.
8. The method according to claim 2, wherein: The format of the predicted character includes at least one of: font size, italicization, bold and font.
9. A device for calculating data width, comprising: A judgment unit is configured to traverse each character in the data to be measured, and for any character, judge whether the character is included in the predicted measurement character set, wherein the predicted measurement character set includes a plurality of predicted measurement characters and a predicted measurement width corresponding to each predicted measurement character; an acquiring unit configured to acquire a predicted width of the character in the predicted character set if the character is included in the predicted character set; and to measure a current width of the character if the character is not included in the predicted character set; and The calculation unit is configured to sum the predicted width or current width of each character in the data to be measured to obtain the width of the data to be measured.
10. An electronic device, comprising: Processor and memory; Wherein, the memory is configured to store instructions or computer programs; The processor is configured to execute the instructions or computer programs in the memory so that the electronic device performs the method according to any one of claims 1 to 8.
11. A computer-readable storage medium, wherein instructions are stored in the computer-readable storage medium, and when the instructions are executed on a device, the device executes the method according to any one of claims 1 to 8.
Citation Information
Patent Citations
Text display method and equipment, storage medium and electronic equipment
CN108710601A
Character length calculation method and device and electronic equipment
CN111626045A
Table-based data display method and device, storage medium and electronic equipment
CN112632903A
Content typesetting method and device, computer equipment and storage medium
CN113569531A
Method and device for calculating data width, equipment and storage medium
CN116629203A
