Text layout method and electronic device

WO2026218889A1PCT designated stage Publication Date: 2026-10-22HUAWEI TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
PCT/CN2026/083874
Authority / Receiving Office
WO · WO
Patent Type
Applications
Current Assignee / Owner
Priority Date
2025-04-16
Filing Date
2026-03-17
Publication Date
2026-10-22

Smart Images

  • Figure CN2026083874_22102026_PF_FP_ABST
    Figure CN2026083874_22102026_PF_FP_ABST
Patent Text Reader

Abstract

Provided in the present application are a text layout method and an electronic device. The method comprises: acquiring a first text code corresponding to first text; dividing the first text code into N nodes, wherein N is a positive integer greater than or equal to 2; and performing text layout calculation on the N nodes by means of M threads, wherein M is a positive integer greater than or equal to 2, and M is less than N. In the embodiments of the present application, when performing text layout, an electronic device may divide a text code into a plurality of nodes, and may further invoke a plurality of threads to perform parallel text layout calculation on the nodes, thus helping improve the text layout calculation efficiency and shorten the text layout time, and thereby improving the text content loading speed and helping improve the user experience.
Need to check novelty before this filing date? Find Prior Art

Description

A method for text layout and electronic devices

[0001] This application claims priority to Chinese Patent Application No. 202510480959.8, filed on April 16, 2025, entitled "A Method for Text Layout and an Electronic Device", the entire contents of which are incorporated herein by reference. Technical Field

[0002] This application relates to the field of electronic devices, and more specifically, to a method for text layout and an electronic device. Background Technology

[0003] With technological advancements, more and more users are using electronic devices to read novels, news, and other information. When users read novels or view news through reading applications or browsers, the large amount of text content often leads to long loading times, negatively impacting the user experience. Therefore, improving text loading speed has become a pressing technical challenge. Summary of the Invention

[0004] This application provides a method for text layout and an electronic device that can call multiple threads to perform parallel text layout calculations, which helps to improve the calculation efficiency of text layout, shorten the text layout time, and increase the loading speed of text content.

[0005] Firstly, a text layout method is provided, which includes: obtaining the first text code corresponding to the first text; dividing the first text code into N nodes, where N is a positive integer greater than or equal to 2; performing text layout calculations on the N nodes using M threads, where M is a positive integer greater than or equal to 2 and M is less than N; and displaying the first text based on the text layout calculation results of the N nodes.

[0006] In this embodiment of the application, when an electronic device performs text layout, it can divide the text code into multiple nodes, and then call multiple threads to perform text layout calculations on these multiple nodes in parallel. This helps to improve the calculation efficiency of text layout, shorten the text layout time, thereby improving the loading speed of text content and enhancing the user experience.

[0007] In conjunction with the first aspect, in some implementations of the first aspect, before performing text layout calculations on the N nodes using the M threads, the method further includes: determining the M threads based on the N nodes.

[0008] In this embodiment, the electronic device can determine the number of threads used for text layout calculation based on the number of nodes, so that the number of threads can match the number of nodes, which can improve the speed of text layout and avoid excessive load.

[0009] In conjunction with the first aspect, in some implementations of the first aspect, determining the M threads based on the N nodes includes: determining the layout time of each of the N nodes based on the number of characters and attributes of the child nodes in each of the N nodes; determining the total layout time of the N nodes based on the layout time of each of the N nodes; and determining the M threads based on the total layout time of the N nodes.

[0010] In this embodiment, the electronic device can determine the number of threads used for text layout calculation based on the total layout time of the node, so that the number of threads can match the total layout time of the node, which can improve the speed of text layout and avoid excessive load.

[0011] In conjunction with the first aspect, in some implementations of the first aspect, before performing text layout calculations on the N nodes through the M threads, the method further includes: determining the correspondence between the N nodes and the M threads.

[0012] In conjunction with the first aspect, in some implementations of the first aspect, determining the correspondence between the N nodes and the M threads includes: determining the correspondence between the N nodes and the M threads based on the layout time of each of the N nodes.

[0013] In this embodiment, the electronic device can determine the correspondence between threads and nodes based on the layout time of nodes, so that different threads complete the text layout calculation in the same or approximately the same time, which helps to improve the efficiency of text layout calculation.

[0014] In conjunction with the first aspect, in some implementations of the first aspect, determining the correspondence between the N nodes and the M threads includes: determining the correspondence between the N nodes and the M threads based on the position of each of the N nodes in the first text code.

[0015] In this embodiment, the electronic device can determine the correspondence between the thread and the node based on the position of the node in the text code, so that the same thread can process adjacent nodes, ensuring that there is no large time interval between the text layout calculation of adjacent nodes, which helps to improve the efficiency of text layout calculation.

[0016] In conjunction with the first aspect, in some implementations of the first aspect, the method further includes: during the calculation of the text layout of the N nodes, calling the first character layout cache, wherein the first character layout cache includes a layout cache of X characters, where X is a positive integer greater than 2, and the X characters include characters from the first text.

[0017] In this embodiment of the application, the electronic device may include a first character layout cache. When the electronic device is performing text layout calculation, if the character that needs to be calculated is a character in the first character layout cache, the electronic device can directly call the first character layout cache, thereby eliminating the need to perform layout calculation on the character, which improves the efficiency of text layout calculation and helps to enhance the user experience.

[0018] In conjunction with the first aspect, in some implementations of the first aspect, before performing text layout calculations on the N nodes through the M threads, the method further includes: determining that the number of characters in the first text is greater than or equal to a first threshold and / or that the layout time of the first text is greater than or equal to a second threshold.

[0019] In a second aspect, an electronic device is provided, comprising one or more processors; one or more memories; the one or more memories storing one or more computer programs, the one or more computer programs including instructions that, when executed by the one or more processors, cause the foregoing aspects or any possible implementation thereof to be performed.

[0020] Thirdly, a computer-readable storage medium is provided, comprising a computer program or instructions that, when executed on a computer, cause the first aspect and any possible implementation of the method of the first aspect to be performed.

[0021] Fourthly, a computer program product is provided, comprising a computer program or instructions that, when executed on a computer, cause the first aspect and any possible implementation of the method of the first aspect to be performed.

[0022] Fifthly, a computer program is provided that, when run on a computer, causes the methods described in the first aspect and any possible implementation thereof to be executed.

[0023] Sixthly, an electronic device according to an embodiment of this application includes modules / units for performing the above aspects or any possible design of the above aspects; these modules / units can be implemented in hardware or implemented by hardware executing corresponding software.

[0024] For the beneficial effects of aspects two through six, please refer to the beneficial effects of aspect one, which will not be repeated here. Attached Figure Description

[0025] Figure 1 is a schematic diagram of the structure of the electronic device provided in an embodiment of this application.

[0026] Figure 2 is a software structure block diagram of the electronic device provided in an embodiment of this application.

[0027] Figure 3 is a schematic flowchart of a text layout method provided in an embodiment of this application.

[0028] Figure 4 shows a set of GUIs provided in an embodiment of this application.

[0029] Figure 5 is a schematic diagram of the partitioning nodes provided in an embodiment of this application.

[0030] Figure 6 is a set of GUIs according to an embodiment of this application.

[0031] Figure 7 is a set of GUIs according to an embodiment of this application.

[0032] Figure 8 is a schematic diagram of an electronic device provided in an embodiment of this application. Detailed Implementation

[0033] The technical solutions in the embodiments of this application will now be described with reference to the accompanying drawings.

[0034] The terminology used in the following embodiments is for the purpose of describing particular embodiments only and is not intended to be limiting of this application. As used in the specification and appended claims of this application, the singular expressions “a,” “an,” “the,” “the,” “the,” and “this” are intended to also include expressions such as “one or more,” unless the context clearly indicates otherwise. It should also be understood that in the following embodiments of this application, “at least one” and “one or more” refer to one, two, or more than two. The term “and / or” is used to describe the relationship between related objects, indicating that three relationships can exist; for example, A and / or B can indicate: A alone, A and B simultaneously, or B alone, where A and B can be singular or plural. The character “ / ” generally indicates that the preceding and following related objects are in an “or” relationship.

[0035] References to "one embodiment" or "some embodiments" as described in this specification mean that one or more embodiments of this application include a specific feature, structure, or characteristic described in connection with that embodiment. Therefore, the phrases "in one embodiment," "in some embodiments," "in other embodiments," "in still other embodiments," etc., appearing in different parts of this specification do not necessarily refer to the same embodiment, but rather mean "one or more, but not all, embodiments," unless otherwise specifically emphasized. The terms "comprising," "including," "having," and variations thereof mean "including but not limited to," unless otherwise specifically emphasized.

[0036] The following describes an electronic device, a user interface for such an electronic device, and embodiments for using such an electronic device. In some embodiments, the electronic device may be a portable electronic device that also includes other functions such as a personal digital assistant and / or music player, such as a mobile phone, tablet computer, wearable electronic device with wireless communication capabilities (such as a smartwatch), etc. Exemplary embodiments of the portable electronic device include, but are not limited to, carrying... Alternatively, it could be a portable electronic device with another operating system. The aforementioned portable electronic device could also be other portable electronic devices, such as laptops. It should also be understood that in some other embodiments, the aforementioned electronic device may not be a portable electronic device, but rather a desktop computer.

[0037] For example, Figure 1 shows a schematic diagram of the structure of an electronic device 100. The electronic device 100 may include a processor 110, an external memory interface 120, an internal memory 121, a universal serial bus (USB) interface 130, a charging management module 140, a power management module 141, a battery 142, an antenna 1, an antenna 2, a mobile communication module 150, a wireless communication module 160, an audio module 170, a speaker 170A, a receiver 170B, a microphone 170C, a headphone jack 170D, a sensor module 180, buttons 190, a motor 191, an indicator 192, a camera 193, a display screen 194, and a subscriber identification module (SIM) card interface 195, etc. The sensor module 180 may include a pressure sensor 180A, a gyroscope sensor 180B, a barometric pressure sensor 180C, a magnetic sensor 180D, an accelerometer sensor 180E, a distance sensor 180F, a proximity sensor 180G, a fingerprint sensor 180H, a temperature sensor 180J, a touch sensor 180K, an ambient light sensor 180L, a bone conduction sensor 180M, etc.

[0038] It is understood that the structures illustrated in the embodiments of this application do not constitute a specific limitation on the electronic device 100. In other embodiments of this application, the electronic device 100 may include more or fewer components than illustrated, or combine some components, or split some components, or have different component arrangements. The illustrated components may be implemented in hardware, software, or a combination of software and hardware.

[0039] Processor 110 may include one or more processing units, such as: application processor (AP), modem processor, graphics processing unit (GPU), image signal processor (ISP), controller, memory, video codec, digital signal processor (DSP), baseband processor, and / or neural network processing unit (NPU), etc. Different processing units may be independent devices or integrated into one or more processors.

[0040] The controller can be the nerve center and command center of the electronic device 100. The controller can generate operation control signals according to the instruction opcode and timing signals to complete the control of fetching and executing instructions.

[0041] The processor 110 may also include a memory for storing instructions and data. In some embodiments, the memory in the processor 110 is a cache memory. This memory can store instructions or data that the processor 110 has just used or that are used repeatedly. If the processor 110 needs to use the instruction or data again, it can retrieve it directly from the memory. This avoids repeated accesses, reduces the waiting time of the processor 110, and thus improves the efficiency of the system.

[0042] In some embodiments, the processor 110 may include one or more interfaces. Interfaces may include an inter-integrated circuit (I2C) interface, an inter-integrated circuit sound (I2S) interface, a pulse code modulation (PCM) interface, a universal asynchronous receiver / transmitter (UART) interface, a mobile industry processor interface (MIPI), a general-purpose input / output (GPIO) interface, a subscriber identity module (SIM) interface, and / or a universal serial bus (USB) interface, etc.

[0043] Display screen 194 is used to display images, videos, etc. Display screen 194 includes a display panel. The display panel can be a liquid crystal display (LCD), an organic light-emitting diode (OLED), an active-matrix organic light-emitting diode (AMOLED), a flexible light-emitting diode (FLED), a Miniled LED, a MicroLED, a Micro-OLED, a quantum dot light-emitting diode (QLED), etc. In some embodiments, electronic device 100 may include one or N displays 194, where N is a positive integer greater than 1. Display screen 194 can also be referred to as a monitor 194.

[0044] The external storage interface 120 can be used to connect an external memory card, such as a Micro SD card, to expand the storage capacity of the electronic device 100. The external memory card communicates with the processor 110 through the external storage interface 120 to perform data storage functions. For example, music, video, and other files can be saved on the external memory card.

[0045] Internal memory 121 can be used to store computer executable program code, which includes instructions. Processor 110 executes various functional applications and data processing of electronic device 100 by running the instructions stored in internal memory 121. Internal memory 121 may include a program storage area and a data storage area. The program storage area may store the operating system, at least one application program required for a function (such as sound playback, image playback, etc.), etc. The data storage area may store data created during the use of electronic device 100 (such as audio data, phonebook, etc.). Furthermore, internal memory 121 may include high-speed random access memory and may also include non-volatile memory, such as at least one disk storage device, flash memory device, universal flash storage (UFS), etc.

[0046] Figure 2 is a software structure block diagram of an electronic device 100 according to an embodiment of this application. The layered architecture divides the software into several layers, each with a clear role and function. Layers communicate with each other through software interfaces. In some embodiments, the Android system is divided into four layers, from top to bottom: the application layer, the application framework layer, the system library layer, and the kernel layer. The application layer may include a series of application packages.

[0047] As shown in Figure 2, the application layer can include camera, settings, third-party applications, etc. Third-party applications can include gallery, calendar, call, map, navigation, WLAN, Bluetooth, music, video, SMS, etc.

[0048] The application framework layer provides application programming interfaces (APIs) and programming frameworks for applications in the application layer. The application framework layer may include some predefined functions.

[0049] As shown in Figure 2, the application framework layer may include a window manager, content provider, view system, phone manager, resource manager, notification manager, etc.

[0050] The window manager is used to manage windowed applications. It can obtain the screen size, determine if a status bar is present, lock the screen, and capture screenshots. The content provider stores and retrieves data, making this data accessible to applications. This data may include videos, images, audio, made and received phone calls, browsing history and bookmarks, phone books, etc.

[0051] The view system includes visual controls, such as controls for displaying text, controls for displaying images, and such as the indicator information for displaying the virtual shutter button in the embodiments of this application. The view system can be used to build applications. The display interface can consist of one or more views. For example, a display interface including a text message notification icon can include a view for displaying text and a view for displaying images.

[0052] The phone manager is used to provide communication functions for electronic device 100. For example, it manages call status (including connection and disconnection).

[0053] The file explorer provides applications with various resources, such as localized strings, icons, images, layout files, video files, and more.

[0054] The notification manager allows applications to display notifications in the status bar. These notifications can be used to deliver informational messages and can disappear automatically after a short pause, requiring no user interaction. For example, the notification manager can be used to notify users of completed downloads or message alerts. The notification manager can also display notifications as icons or scrolling text in the top status bar, such as notifications from background applications, or as dialog boxes on the screen. Examples include displaying text messages in the status bar, emitting sounds, vibrating electronic devices, and flashing indicator lights.

[0055] The application layer and application framework layer run in a virtual machine. The virtual machine is used to perform functions such as object lifecycle management, stack management, thread management, security and exception management, and garbage collection.

[0056] System libraries can include multiple functional modules. For example: surface manager, media libraries, 3D graphics processing libraries (e.g., OpenGL ES), 2D graphics engines (e.g., SGL), etc.

[0057] The Surface Manager is used to manage the display subsystem and provides the blending of 2D and 3D layers for multiple applications.

[0058] The media library supports playback and recording of various common audio and video formats, as well as still image files. It supports multiple audio and video encoding formats, such as MPEG4, H.264, MP3, AAC, AMR, JPG, and PNG.

[0059] The 3D graphics processing library is used to implement 3D graphics drawing, image rendering, compositing, and layer processing.

[0060] A 2D graphics engine is a graphics engine for 2D drawing.

[0061] In addition, the system library may also include status monitoring service modules, such as a physical status recognition module for analyzing and recognizing user gestures; and a sensor service module for monitoring sensor data uploaded by various sensors at the hardware layer to determine the physical status of the electronic device 100.

[0062] The kernel layer is the layer between hardware and software. The kernel layer contains at least the display driver, camera driver, audio driver, and sensor driver.

[0063] The hardware layer may include various types of sensors, such as the various sensors shown in Figure 1, including accelerometers, gyroscopes, and touch sensors involved in the embodiments of this application.

[0064] It should be noted that Figure 2 only illustrates one way of dividing the system framework and should not be construed as a specific limitation on the embodiments of this application. In the embodiments of this application, different frameworks can be used for different operating systems when the electronic device is equipped with different operating systems. It is understood that when different frameworks are adopted, the way the framework is divided into layers, the specific naming, and the specific layer in which each of the above modules is located can be different.

[0065] With technological advancements, more and more users are using electronic devices to read novels, news, and other information. When users read novels or view news through reading applications or browsers, the large amount of text content often results in long loading times, negatively impacting the user experience.

[0066] Figure 3 shows a schematic flowchart of a text layout method provided in an embodiment of this application. This method can be executed by an electronic device or by a component of the electronic device (such as a processor, chip system, etc.). The following description will take an electronic device as the executing entity. As shown in Figure 3, the method 300 includes:

[0067] S301, retrieve the first text code corresponding to the first text.

[0068] Before displaying the first text, the electronic device needs to obtain the code of the first text, and then perform layout calculations, rendering and other operations on the code of the first text to finally display the first text.

[0069] It should be understood that the language used for the first text code in this application embodiment is not specifically limited. For example, the first text code may be code written in Hypertext Markup Language (HTML).

[0070] For ease of explanation, the first text code in this embodiment is assumed to be as follows:

[0071]

[0072] Text <span style=”font-size”:40px>Parallelization 1 Text Parallelization 2 Text Parallelization 2 Text Parallelization 2 Text Parallelization

[0073] Text Parallelization 3 Text Parallelization 3 Text Parallelization 3 Text Parallelization

[0074] Text Parallelization 4 Text Parallelization 4 Text Parallelization 4 Text Parallelization

[0075] When determining the DOM tree, the electronic device can identify four paragraph nodes as the main node, denoted as paragraph node 501, paragraph node 502, paragraph node 503, and paragraph node 504. Paragraph node 501 can be associated with the first paragraph node from top to bottom in the first text code.

[0076]

[0077] The first text code Paragraph tags are used to distinguish different paragraphs. A span tag is also inserted within the first paragraph tag from top to bottom. This span tag is used to adjust the style of the text after "Text Parallelization 1" (e.g., font size). The first text corresponding to this first text code is ultimately displayed in the graphical user interface (GUI) of the electronic device, as shown in Figure 4.

[0078] Figure 4 illustrates a set of GUIs provided in an embodiment of this application.

[0079] As shown in Figure 4, the electronic device can display a first text, which includes four paragraphs: the first paragraph is "text parallelization 1 text parallelization span1", the second paragraph is "text parallelization 2 text parallelization 2 text parallelization 2 text parallelization", the third paragraph is "text parallelization 3 text parallelization 3 text parallelization 3 text parallelization", and the fourth paragraph is "text parallelization 4 text parallelization 4 text parallelization 4 text parallelization". Because a span tag is inserted into the first paragraph tag of the first text code, the font size of "text parallelization span1" in the first paragraph is 40px. The font sizes of the remaining text in the first text can be the same, such as the default font size.

[0080] S302, divide the first text code into N nodes, where N is a positive integer greater than or equal to 2.

[0081] After the electronic device obtains the first text code, it can determine the document object model (DOM) tree corresponding to the first text code, then determine the layout node tree based on the DOM tree, and finally determine the N nodes of the first text code based on the layout node tree.

[0082] It should be noted that the method of dividing nodes may differ for different languages, and this application does not impose specific limitations on this.

[0083] For example, in this embodiment of the application, the first text is code written in HTML. The N nodes can be N block-level elements (or block-level nodes) in the first text code.

[0084] Figure 5 shows a schematic diagram of the partitioning nodes provided in an embodiment of this application.

[0085] Taking the first text code mentioned above as an example, after the electronic device obtains the first text code, it can determine the meaning of the first text code based on the... The tags define the DOM tree, and the generated DOM tree can be shown in Figure 5(a).

[0086] As shown in Figure 5(a), since the first text code includes 4 The tag corresponds to paragraph node 502, which can be associated with the second one. The tag corresponds to paragraph node 503, which can be associated with the third one. The tag corresponds to the paragraph node 504, which can be associated with the fourth one. ​ Tag correspondence.

[0087] Continuing to refer to Figure 5(a), due to the first text code in the first text... If the tag also includes a cross tag, then paragraph node 501 can also include a cross node.

[0088] Referring again to Figure 5(a), each paragraph node may include a text node, and the spanning node may include a text node.

[0089] The electronic device determines the DOM tree, and can determine the layout node tree based on the DOM tree, as shown in Figure 5(b).

[0090] As shown in Figure 5(b), the electronic device can determine the nodes corresponding to paragraph nodes 501, 502, 503, and 504 based on the DOM tree, and denot them as nodes 505, 506, 507, and 508, respectively. In this embodiment, the N nodes refer to the N nodes corresponding to the paragraph nodes in the DOM tree.

[0091] Continuing to refer to Figure 5(b), since each paragraph node in the DOM tree includes one or more child nodes, each node can include one or more child nodes. Specifically, node 505 includes 3 child nodes, node 506 includes 1 child node, node 507 includes 1 child node, and node 508 includes 1 child node.

[0092] For example, if the first text is code written in HTML, each node may include inline elements (or inline nodes) as its child nodes.

[0093] S303 uses M threads to perform text layout calculations on N nodes, where M is a positive integer greater than 2.

[0094] The electronic device determines the N nodes corresponding to the first text code and can invoke M threads to perform parallel text layout calculations on the N nodes. This involves assigning the N nodes to the M threads, with each of the M threads performing text layout calculations on one or more nodes. When assigning the N nodes to the M threads, the electronic device can distribute them evenly or unevenly.

[0095] S304, based on the text layout calculation results of N nodes, display the first text.

[0096] After the electronic device completes the text layout calculation for N nodes, it can call the text layout calculation result to display the first text.

[0097] In this embodiment of the application, when an electronic device performs text layout, it can divide the text code into multiple nodes, and then call multiple threads to perform text layout calculations on these multiple nodes in parallel. This helps to improve the calculation efficiency of text layout, shorten the text layout time, thereby improving the loading speed of text content and enhancing the user experience.

[0098] In some possible embodiments, the M threads are pre-defined, that is, the number of threads used for text layout calculation is fixed, and the M threads can be invoked when the electronic device determines to perform parallel text layout calculation.

[0099] For example, an electronic device divides text code into 20 nodes. The electronic device can perform parallel text layout calculations on these 20 nodes using 4 threads. Each thread can process multiple nodes, such as 5 nodes per thread.

[0100] For example, if an electronic device divides text code into 60 nodes, the electronic device can still perform parallel text layout calculations on these 60 nodes using 4 threads. Each thread can process multiple nodes, such as 15 nodes per thread.

[0101] In some possible embodiments, the electronic device can determine the M threads based on the N nodes before performing text layout calculations on the N nodes using M threads. That is, the number of threads used for text layout calculations can be determined before performing text layout calculations on the N nodes.

[0102] When an electronic device determines M threads based on N nodes, it may include the following possible implementation methods;

[0103] One possible implementation is that the electronic device determines the size of M based on the size of N.

[0104] For example, when an electronic device divides text code into 20 nodes, it can determine to perform text layout calculations on those 20 nodes using 2 threads. When an electronic device divides text code into 40 nodes, it can determine to perform text layout calculations on those 40 nodes using 4 threads.

[0105] In this embodiment, the electronic device can determine the number of threads used for text layout calculation based on the number of nodes, so that the number of threads can match the number of nodes, which can improve the speed of text layout and avoid excessive load.

[0106] One possible implementation is that the electronic device determines the layout time of each of the N nodes based on the number of characters and attributes of the child nodes in each of the N nodes. The electronic device then determines the total layout time of the N nodes based on the layout time of each of the N nodes. Finally, the electronic device determines the number of M threads based on the total layout time of the N nodes.

[0107] For example, if an electronic device determines that the total layout time for N nodes is 300ms, it can determine to perform parallel text layout calculations for those N nodes using 3 threads. If the electronic device determines that the total layout time for those N nodes is 500ms, it can determine to perform parallel text layout calculations for those N nodes using 6 threads.

[0108] For example, the attributes of child nodes include, but are not limited to, character size, italics, bold, custom font, etc.

[0109] In this embodiment, the electronic device can determine the number of threads used for text layout calculation based on the total layout time of the node, so that the number of threads can match the total layout time of the node, which can improve the speed of text layout and avoid excessive load.

[0110] In some possible embodiments, before the electronic device performs text layout calculations on N nodes through M threads, it can also determine the correspondence between the N nodes and the M threads, that is, the electronic device can determine which of the N nodes each of the M threads processes.

[0111] The method for determining the correspondence between N nodes and M threads in this application embodiment is not specifically limited. Several possible implementation methods are exemplified below:

[0112] One possible implementation is that the electronic device can randomly assign N nodes to M threads.

[0113] One possible implementation is that the electronic device determines the correspondence between the N nodes and the M threads based on the layout time of each of the N nodes.

[0114] For example, with N=4 and M=2, the N nodes include node #1, node #2, node #3, and node #4, and the M threads include thread #1 and thread #2. The electronic device determines that the layout time for node #1 is 40ms, the layout time for node #2 is 40ms, the layout time for node #3 is 30ms, and the layout time for node #4 is 100ms. Therefore, the electronic device can assign node #1, node #2, and node #3 to thread #1, and assign node #4 to thread #2.

[0115] For example, with N=4 and M=2, the N nodes include node #1, node #2, node #3, and node #4, and the M threads include thread #1 and thread #2. If the electronic device determines that the layout time for node #1 is 150ms, the layout time for node #2 is 150ms, the layout time for node #3 is 30ms, and the layout time for node #4 is 30ms, then the electronic device can assign node #1 and node #3 to thread #1, and assign node #2 and node #4 to thread #2.

[0116] In this embodiment, the electronic device can determine the correspondence between threads and nodes based on the layout time of nodes, so that different threads complete the text layout calculation in the same or approximately the same time, which helps to improve the efficiency of text layout calculation.

[0117] One possible implementation is that the electronic device can determine the correspondence between N nodes and M threads based on the positions of N nodes in the first text code.

[0118] For example, taking the first text code as shown above, and M=2, the electronic device can divide the first text code into multiple nodes, namely nodes 505, 506, 507, and 508 as shown in Figure 5. These M threads include thread #1 and thread #2. Since nodes 505 and 506 are adjacent in the first text code, and nodes 507 and 508 are adjacent in the first text code, the electronic device can assign nodes 505 and 506 to thread #1, and assign nodes 507 and 508 to thread #2.

[0119] In this embodiment, the electronic device can determine the correspondence between the thread and the node based on the position of the node in the text code, so that the same thread can process adjacent nodes, ensuring that there is no large time interval between the text layout calculation of adjacent nodes, which helps to improve the efficiency of text layout calculation.

[0120] In some possible embodiments, the method 300 further includes: during the calculation of the text layout of N nodes, calling a first character layout cache, the first character layout cache including a layout cache of X characters, where X is a positive integer greater than or equal to 2, and the X characters include characters from the first text.

[0121] The electronic device can be configured with a first character layout cache, which can include layout caches for multiple characters. When the electronic device performs text layout calculations on N nodes, if the first character layout cache includes layout caches for the characters in the N nodes, the electronic device can directly call the first character layout cache.

[0122] For example, taking the first text as the text shown above as an example, the first character layout cache includes the character layout caches of "char" and "acter", then when the electronic device performs text layout calculation on the first text code and calculates the layouts of "char" and "acter", it can directly call the character layout caches of "char" and "acter" in the first character layout cache, without the need for the electronic device to perform text layout calculation on "char" and "acter" again.

[0123] In the embodiments of the present application, the electronic device may include a first character layout cache. When the electronic device performs text layout calculation, if the character that needs layout calculation is a character in the first character layout cache, the electronic device can directly call the first character layout cache, so that it is not necessary to perform layout calculation on the character, which improves the efficiency of text layout calculation and helps to enhance user experience.

[0124] In some possible embodiments, the first character layout cache is pre-configured in the electronic device.

[0125] In some possible embodiments, the electronic device may update the first character layout cache.

[0126] In some possible embodiments, a large amount of news information and literary works may be collected to determine frequently occurring characters, and the first character layout cache is established according to the frequently occurring characters in the large amount of news information and literary works.

[0127] In some possible embodiments, before the electronic device performs text layout calculation on N nodes through M threads, the method 300 further includes:

[0128] Determining that the first text content satisfies a preset condition, that is, the electronic device may perform parallel text layout calculation on the N nodes through the M threads when the first text content satisfies the preset condition.

[0129] In some possible embodiments, when the number of characters in the first text content is greater than or equal to a first threshold, the electronic device may perform parallel text layout calculation on the N nodes through the M threads.

[0130] For example, when the electronic device determines that the number of characters in the first text content is less than 5000 characters, it may perform serial text layout calculation on the N nodes corresponding to the first text content, that is, perform text layout calculation on the N nodes one by one. When the electronic device determines that the number of characters in the first text content is greater than or equal to 5000 characters, it may perform parallel text layout calculation on the N nodes corresponding to the first text content through M threads.

[0131] In some possible embodiments, when the layout time of the first text content is greater than or equal to the second threshold, the electronic device can perform parallel text layout calculations on the N nodes through the M threads.

[0132] For example, if an electronic device determines that the layout of the first text content takes more than or equal to 500ms, it can use the M threads to perform parallel text layout calculations on the N nodes. The layout time of the first text content can be either the time required for serial text layout of the N nodes or the time required for parallel text layout of the N nodes. In other words, if the electronic device determines that serial text layout is too time-consuming, it can use parallel text layout to shorten the layout time; conversely, if the electronic device determines that parallel text layout is too time-consuming, it indicates that serial text layout would take even longer, and therefore parallel text layout can be used.

[0133] The text layout method provided by the embodiments of this application has been introduced above. The following will exemplarily introduce several scenarios that may be applicable to the embodiments of this application.

[0134] Figure 6 illustrates a set of GUIs according to an embodiment of this application.

[0135] As shown in Figure 6(a), the electronic device displays an interface 601, which is a desktop. The electronic device can display icons for multiple applications on interface 601, such as icon 602, which is the icon for a reading application. When the electronic device detects a user clicking on icon 602, in response to this action, it can display the GUI shown in Figure 6(b).

[0136] As shown in Figure 6(b), in response to a user clicking icon 602, the electronic device can display interface 603, which is the main interface of the reading application. The electronic device can display thumbnails of multiple books on interface 603, such as thumbnail 604, where the book title is "Journey to the West". When the electronic device detects a user clicking thumbnail 604, it can open the book corresponding to thumbnail 604. During the opening process, the text layout method provided in this embodiment can be used to perform parallel text layout calculations on multiple block-level text nodes in the book to accelerate the opening speed.

[0137] Figure 7 illustrates a set of GUIs according to an embodiment of this application.

[0138] As shown in Figure 7(a), the electronic device displays an interface 701, which is the desktop. The electronic device can display icons for multiple applications on the interface 701, such as icon 702, which is the browser icon. When the electronic device detects that the user clicks on icon 702, in response to the operation, it can display the GUI shown in Figure 7(b).

[0139] As shown in Figure 7(b), in response to a user clicking icon 702, the electronic device can display interface 703, which is the main interface of the browser. The electronic device can display the titles of multiple news articles on interface 703, such as title 704. When the electronic device detects a user clicking title 704, it can open the news article corresponding to title 704. During the process of opening the news article, the text layout method provided in this application embodiment can be used to perform parallel text layout calculations on multiple block-level text nodes in the news article to accelerate the opening speed of the news article.

[0140] The text layout method provided in the embodiments of this application has been described in detail above. In the various embodiments of this application, unless otherwise specified or in case of logical conflict, the terminology and / or descriptions between the various embodiments are consistent and can be referenced by each other. The technical features in different embodiments can be combined to form new embodiments according to their inherent logical relationships.

[0141] The foregoing primarily describes the text layout method provided in the embodiments of this application from the perspective of an electronic device. It is understood that, in order to achieve the above functions, the electronic device includes corresponding hardware structures and / or software modules for executing each function. Those skilled in the art should readily recognize that, based on the algorithm steps of the examples described in conjunction with the embodiments disclosed herein, this application can be implemented in hardware or a combination of hardware and computer software. Whether a function is executed in hardware or by computer software driving hardware depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.

[0142] With the adoption of the division of each function into different modules (or units) corresponding to each function, Figure 8 shows a schematic diagram of the composition of an electronic device 800 provided in an embodiment of this application. As shown in Figure 8, the electronic device 800 includes: a frame scheduler 810, a text pre-layout management module 820, a text layout collection module 830, a text layout thread pool 840, and a text layout engine 850.

[0143] In some possible embodiments, the frame scheduler 810 can be FrameScheduler, the text prelayout management module 820 can be named PrelayoutTextManager, the text layout collection module 830 can be named LayoutTextCollector, the text layout thread pool 840 can be named EwTextShaperThreadPool, and the text layout engine 850 can be EwHarfbuzzTextShaper.

[0144] Frame scheduler 810 is used to send the first text code to text pre-layout management module 820.

[0145] The text pre-layout management module 820 is used to collect the text and corresponding attributes of N nodes through the text layout collection module 830.

[0146] The text pre-layout management module 820 is also used to assign N nodes to M threads in the text layout thread pool 840.

[0147] It should be understood that the description of determining the size of M for the text pre-layout management module 820, and determining the correspondence between N nodes and M threads, can be found above, and will not be repeated here for the sake of brevity.

[0148] The text layout thread pool 840 is used to manage M threads to perform text layout calculations on N nodes through the text layout engine 850, so as to generate the text layout calculation results of N nodes.

[0149] The frame scheduler 810 is also used to obtain the text layout calculation results of N nodes when performing text layout.

[0150] In some possible embodiments, the frame scheduler 810 is also used to generate a first character layout cache.

[0151] This application provides a computer program product that, when run on an electronic device, causes the electronic device to execute the technical solutions described in the above embodiments. Its implementation principle and technical effects are similar to those of the related embodiments described above, and will not be repeated here.

[0152] This application provides a readable storage medium containing instructions that, when executed by an electronic device, cause the electronic device to perform the technical solution described in the above embodiments. The implementation principle and technical effects are similar and will not be repeated here.

[0153] This application provides a chip for executing instructions. When the chip is running, it executes the technical solutions described in the above embodiments. Its implementation principle and technical effects are similar and will not be repeated here.

[0154] Those skilled in the art will recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementations should not be considered beyond the scope of the embodiments of this application.

[0155] Those skilled in the art will understand that, for the sake of convenience and brevity, the specific working processes of the systems, devices, and units described above can be referred to the corresponding processes in the foregoing method embodiments, and will not be repeated here.

[0156] In the several embodiments provided in this application, it should be understood that the disclosed systems, apparatuses, and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be through some interfaces; the indirect coupling or communication connection between apparatuses or units may be electrical, mechanical, or other forms.

[0157] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.

[0158] In addition, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit.

[0159] If the aforementioned functions are implemented as software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solutions of the embodiments of this application, essentially, or the parts that contribute to the prior art, or parts of the technical solutions, can be embodied in the form of software products. These computer software products are stored in a storage medium and include several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.

[0160] The above description is merely a specific implementation of the embodiments of this application, but the protection scope of the embodiments of this application is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the technical scope disclosed in the embodiments of this application should be included within the protection scope of the embodiments of this application. Therefore, the protection scope of the embodiments of this application should be determined by the protection scope of the claims.

Claims

1. A method for text layout, characterized in that, The method includes: Get the code corresponding to the first text; Divide the first text code into N nodes, where N is a positive integer greater than or equal to 2; The text layout of the N nodes is calculated using M threads, where M is a positive integer greater than or equal to 2 and M is less than N; Based on the text layout calculation results of the N nodes, the first text is displayed.

2. The method according to claim 1, characterized in that, Before performing text layout calculations on the N nodes using the M threads, the method further includes: Based on the N nodes, determine the M threads.

3. The method according to claim 2, characterized in that, The step of determining the M threads based on the N nodes includes: Based on the number of characters and attributes of the child nodes in each of the N nodes, determine the layout time of each of the N nodes; Determine the total layout time of the N nodes based on the layout time of each of the N nodes. The M threads are determined based on the total layout time of the N nodes.

4. The method according to any one of claims 1 to 3, characterized in that, Before performing text layout calculations on the N nodes using the M threads, the method further includes: Determine the correspondence between the N nodes and the M threads.

5. The method according to claim 4, characterized in that, Determining the correspondence between the N nodes and the M threads includes: Based on the layout time of each of the N nodes, determine the correspondence between the N nodes and the M threads.

6. The method according to claim 4, characterized in that, Determining the correspondence between the N nodes and the M threads includes: Based on the position of each of the N nodes in the first text code, determine the correspondence between the N nodes and the M threads.

7. The method according to any one of claims 1 to 6, characterized in that, The method further includes: During the calculation of the text layout for the N nodes, the first character layout cache is invoked, wherein the first character layout cache includes layout caches for X characters, where X is a positive integer greater than 2, and the X characters include characters from the first text.

8. The method according to any one of claims 1 to 7, characterized in that, Before performing text layout calculations on the N nodes using the M threads, the method further includes: The number of characters in the first text is determined to be greater than or equal to a first threshold and / or the layout time of the first text is greater than or equal to a second threshold.

9. An electronic device, characterized in that, It includes one or more processors; one or more memories; said one or more memories storing one or more computer programs, said one or more computer programs including instructions that, when executed by said one or more processors, cause the method of any one of claims 1 to 8 to be performed.

10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer instructions that, when executed on a computer, cause the method as described in any one of claims 1 to 8 to be performed.

11. A chip, characterized in that, The chip includes a processor and a communication interface, the communication interface being used to receive signals and transmit the signals to the processor, the processor processing the signals such that the method as described in any one of claims 1 to 8 is executed.

12. A computer program product, characterized in that, When the computer program product is run on a computer, it causes the computer to perform the method as described in any one of claims 1 to 8.