Reading layout optimization methods

By analyzing the target font features and multi-dimensional context models, the layout of e-reading devices is dynamically adjusted, solving the problem of layout distortion caused by font scaling in existing technologies and realizing a personalized reading experience under different environments and devices.

CN120276632BActive Publication Date: 2026-01-30BEIJING DUSHANGGAOLOU CULTURAL TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202510358412.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-03-25
Publication Date
2026-01-30
Estimated Expiration
2045-03-25

AI Technical Summary

Technical Problem

In existing technologies, e-reading devices ignore font design characteristics when scaling fonts, resulting in distorted page layout. They cannot dynamically adjust page parameters according to ambient light intensity, device status, and user behavior, and therefore cannot meet users' personalized needs in different scenarios.

Method used

By receiving user input of font switching commands, parsing the target font features, calculating the scaling factor to adjust the character ratio, dynamically updating the page layout parameters, and combining a multi-dimensional context model to recommend reading mode parameters in real time, including adjustments to font size, background color, and line spacing, and introducing a font feature analysis module and anti-aliasing processing technology.

Benefits of technology

It achieves intelligent adaptation based on ambient light intensity, device status, and user behavior, precisely adjusting character spacing and line spacing to ensure consistent display effects on different devices, improving reading comfort and efficiency, and possessing high stability and maintainability.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120276632B_ABST
    Figure CN120276632B_ABST
Patent Text Reader

Abstract

This application relates to the field of digital publication display technology and discloses a method for optimizing reading layout, including the following steps: Step 1: Receiving and parsing a font switching command input by the user; Step 2: Loading the corresponding font file according to the target font to complete the font change of the electronic document; Step 3: Calculating a scaling factor and adjusting the character ratio of the target font based on the character ratio values ​​of the preset font and the target font; Step 4: Updating the layout parameters of the electronic document according to the adjusted character ratio; Step 5: Presenting the adjusted electronic document to the user and saving it; Step 6: Extracting the target font parameters through a font feature analysis module; Step 7: Constructing a multi-dimensional context model. This invention employs multi-dimensional context modeling and dynamic recommendation, achieving the technical effect of intelligently adapting to different reading scenarios and solving the shortcomings of traditional methods that cannot dynamically adjust layout parameters based on ambient light intensity, device status, and user behavior.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of digital publication display technology, specifically a method for optimizing reading layout. Background Technology

[0002] With the popularization of digital reading, e-reading devices have become an important tool for people to obtain information. Users' requirements for reading experience are constantly increasing, especially in terms of font display, page layout, and cross-device adaptation. A good reading experience not only depends on clear font display, but also requires dynamically adjusting page parameters according to environmental conditions, device status, and user behavior to provide the best visual effect and reading comfort.

[0003] In existing technologies, e-reading devices typically adjust font size using a fixed scaling ratio to adapt to different screen sizes and user preferences. For example, users can adjust the font size using a slider, and the system scales the character width and height by a fixed ratio. Furthermore, some technical solutions also support simple line spacing and character spacing adjustments, but these adjustments are usually static and cannot be dynamically optimized based on font design characteristics or the reading environment.

[0004] However, existing technologies have a significant problem: fixed-ratio scaling ignores the design characteristics of the font itself, resulting in severe layout distortion after the font is enlarged or reduced, with unreasonable line spacing and character spacing, affecting reading comfort and efficiency. For example, under the same scaling ratio, the character width and height ratios of sans-serif and serif fonts differ significantly, leading to an uncoordinated layout. Furthermore, existing technologies cannot dynamically adjust layout parameters based on ambient light intensity, device status, and user behavior, making it difficult to meet users' personalized needs in different scenarios. Summary of the Invention

[0005] To address the shortcomings of existing technologies, this invention provides a method for optimizing reading layout, which solves the problems of layout distortion and inability to dynamically adapt to the reading environment caused by fixed-ratio font scaling in existing technologies.

[0006] To achieve the above objectives, the present invention provides the following technical solution: a reading layout optimization method, comprising the following steps:

[0007] Step 1: Receive the font switching command input by the user, and parse the command to determine the target font and its style attributes;

[0008] Step 2: Load the corresponding font file according to the target font to complete the font replacement of the electronic document;

[0009] Step 3: Based on the character ratio values ​​of the preset font and the target font, calculate the scaling factor and adjust the character ratio of the target font. The character ratio is the ratio of the actual display area of ​​the font to the design area.

[0010] Step 4: Update the layout parameters of the electronic document according to the adjusted character ratio, including line spacing, character spacing, and paragraph spacing;

[0011] Step 5: Present the adjusted electronic document to the user and save the user settings for later restoration;

[0012] Step 6: Extract the stroke thickness and slant angle features of the target font through the font feature analysis module, and generate a difference index to fine-tune the layout parameters.

[0013] Step 7: Construct a multi-dimensional context model and dynamically recommend reading mode parameters based on device status data, ambient light intensity data, and user behavior data. The recommendation rules include real-time adjustment of font size, background color, and line spacing.

[0014] Preferably, the scaling factor is determined by the ratio of the literal value of the target font to the literal value of the preset font, and the scaling factor ranges from 0.8 to 1.5, which is determined based on user comfort test data.

[0015] Preferably, the updating of the layout parameters includes:

[0016] Line spacing should be 1.2 to 1.8 times the font height;

[0017] The character spacing should be 0.05 to 0.15 times the font width;

[0018] Paragraph spacing should be 1.0 to 1.5 times the line spacing, and the spacing between the top of the first line of a paragraph and the bottom of the last line of the previous paragraph should be no less than 1.2 times the line spacing.

[0019] Preferably, the font feature analysis module includes:

[0020] The stroke thickness, slant angle, and character structure features of the target font image are extracted using a convolutional neural network. The input to the convolutional neural network is a grayscale font image, and the grayscale processing uses a weighted average method. The calculation formula is as follows:

[0021] Grayscale value = 0.299R + 0.587G + 0.114B;

[0022] Where R, G, and B are the pixel values ​​of the red, green, and blue channels of the font image, respectively;

[0023] The semantic features of the target font are analyzed using natural language processing techniques to generate a semantic vector that includes sentiment and applicable scenarios. The image feature vector and the semantic vector are fused into a comprehensive feature vector, and the Euclidean distance between the comprehensive feature vector and the feature vector of the benchmark font is calculated to generate a difference index.

[0024] Preferably, the construction of the multi-dimensional context model includes:

[0025] Real-time acquisition of device status data, including screen size, resolution, and DPI;

[0026] Real-time acquisition of ambient light intensity data, and conversion into a percentage coefficient of standard illuminance value;

[0027] The user's reading speed and page-turning frequency are modeled temporally using a Long Short-Term Memory (LSTM) network. The LSM network has 3 hidden layers, the activation function is ReLU, and the loss function is mean squared error.

[0028] Output dynamic reading mode parameters, including adjustment rules for font size, background color, and line spacing.

[0029] Preferably, the dynamic reading mode parameter adjustment rules include:

[0030] Font size = Base font size × Ambient light intensity factor;

[0031] The ambient light intensity coefficient is the ratio of ambient light intensity to 100 lux.

[0032] The background color automatically switches between dark and light modes based on the ambient light intensity. In dark mode, the background brightness decreases exponentially as the user reads.

[0033] Preferably, step seven specifically includes:

[0034] The responsive layout algorithm calculates the ratio of the available screen width to the character width in real time. When the ratio is lower than a preset threshold, it automatically reduces the number of characters per line and triggers paragraph reflow.

[0035] For high-resolution screens, subpixel rendering technology is used to perform anti-aliasing on the adjusted fonts, and the anti-aliasing algorithm is Lanczos interpolation.

[0036] Preferably, the saving and optimization of user settings includes:

[0037] Store users' historical font selections, layout parameter adjustment records, and comfort scores in a relational database;

[0038] The weight parameters of the convolutional neural network and long short-term memory network models are iteratively updated using the gradient descent algorithm. The objective function is optimized to be the total loss. The total loss is calculated by quantifying the layout distortion through the structural similarity index and combining it with the frequency of user operation interruptions.

[0039] Preferably, the literal value adjustment needs to meet the following precision requirements:

[0040] The absolute value of the ratio error between the adjusted character width and the preset font character width does not exceed 3%;

[0041] The absolute value of the ratio error between the adjusted character height and the preset font character height shall not exceed 2%;

[0042] If three consecutive adjustments fail to meet the accuracy requirements, an exception handling process is triggered, reverting to the preset font and generating a system log alarm.

[0043] Preferably, the compensatory adjustment of the difference index includes:

[0044] When the difference index exceeds the preset threshold, the adjustment range of the character spacing is a linear function of the difference index;

[0045] The adjustment range of line spacing is a quadratic function of the difference index.

[0046] This invention provides a method for optimizing reading layout. It has the following beneficial effects:

[0047] 1. This invention employs multi-dimensional contextual modeling and dynamic recommendation to achieve intelligent adaptation to different reading scenarios. Compared to existing technologies that use fixed-ratio font scaling, it overcomes the limitation of dynamically adjusting layout parameters based on ambient light intensity, device status, and user behavior. For example, the system can automatically switch to dark mode based on ambient light, making nighttime reading more eye-friendly.

[0048] 2. This invention introduces font feature analysis and a difference compensation mechanism, achieving the technical effect of precisely adjusting character spacing and line spacing. Compared to existing technologies that ignore font design characteristics, it solves the problem of layout distortion after font scaling. For example, after switching between bold and Song fonts, the character width and height ratio remains consistent.

[0049] 3. This invention achieves a consistent display effect across multiple devices through cross-device adaptation and anti-aliasing processing. Compared to existing technologies that only support single-device adaptation, it solves the problem of inconsistent display effects across different screen resolutions. For example, the visual experience is seamless when reading the same document on a mobile phone and a tablet.

[0050] 4. This invention employs exception handling and logging to achieve high stability and maintainability. Compared to existing technologies that lack exception recovery mechanisms, it solves the problem of slow recovery after system crashes. For example, when font loading fails, the system automatically retryes and recovers from a backup library, ensuring an unaffected user experience. Attached Figure Description

[0051] Figure 1 This is a schematic diagram of the method flow of the present invention. Detailed Implementation

[0052] The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings of the present invention. Obviously, the described embodiments are only a part of the embodiments of the present invention, rather than all the embodiments. All other embodiments obtained by those of ordinary skill in the art based on the embodiments of the present invention without any creative efforts shall fall within the protection scope of the present invention.

[0053] Please refer to the attached Figure 1 , the embodiments of the present invention provide a reading layout optimization method, including the following steps:

[0054] In the embodiments of the present invention, the reception and parsing of font switching instructions are the initial steps of the reading layout optimization process. Its function is to convert the user's interaction operations into font replacement instructions executable by the system, and provide necessary inputs for subsequent font loading, em-square ratio adjustment, and layout update. This step needs to ensure the accuracy and robustness of instruction parsing, and at the same time realize data linkage with the font library management module and the user preference database, laying a foundation for the coordinated operation of the overall technical solution.

[0055] The user triggers a font switching operation through the interaction control on the e-reading interface. The interaction control includes, but is not limited to, a drop-down menu, a floating button, or a voice command input module. When the user selects the target font name and style attributes, the interface event listener captures the operation event in real time and generates an original instruction data packet containing the font identification code and style code. The font identification code adopts a globally unique coding rule. For example, "Bold SimHei" is mapped to "HT-BOLD-001" to ensure an exact match with the index key values in the local or cloud font library.

[0056] The system performs a validity check on the font name input by the user through a preset font metadata table. The metadata table is stored in a relational database and includes font family names, style variants, compatibility identifiers, and cache status flags. For example, when the user selects "STKaiti-Italic", the system queries the metadata table to check if there is a corresponding font file (such as "HWKT-Italic.ttf"). If the check passes, a formatted instruction is generated; if the check fails, a "font unavailable" prompt is returned to the user and a log is recorded.

[0057] In some embodiments, the instruction parsing process involves multi-level data processing. After the original instruction data packet is processed by the decryption module to remove redundant information, key parameters are extracted, including the target font identification code, style attributes, and priority marks. The priority mark is used to control the order of the font loading queue. For example, the priority of an instruction actively triggered by the user is higher than that of an instruction automatically recommended by the system. The parsed structured instruction format is as follows:

[0058] In some embodiments, grayscale conversion is used as a preprocessing step for font feature analysis, and its calculation formula is as follows:

[0059] Grayscale value = 0.299R + 0.587G + 0.114B;

[0060] Where R, G, and B represent the red, green, and blue channel intensity values ​​of the font image pixels, respectively, ranging from 0 to 255. For example, for a pure red pixel (R=255, G=0, B=0), its grayscale value is calculated as follows:

[0061] 0.299×255+0.587×0+0.114×0=76.245≈76

[0062] The system manages concurrent font switching requests through a dynamic priority queue. When multiple users or processes initiate requests simultaneously, the queue scheduling algorithm allocates processing resources based on priority markers and timestamps. For example, high-priority instructions (such as real-time user operations) can interrupt low-priority tasks (such as background preloading), ensuring that the interaction response latency is less than 200 milliseconds.

[0063] The mapping between font identifiers and physical font files is implemented using a hash table. The hash function uses the SHA-256 algorithm to generate unique keys, with a key-value collision rate of less than 1×102. -6 For example, the font identifier "HT-BOLD-001" is mapped to the storage path " / fonts / HT / BOLD / 001.ttf" after hashing. If the path does not exist, an asynchronous download process is triggered.

[0064] The instruction parsing module works in conjunction with the exception handling subsystem. When an illegal character or a style parameter exceeding the preset range is detected, the system triggers the exception state machine, performs a rollback operation, and generates an error code. For example, if the user enters "font size = 200%", and this exceeds the system's maximum supported range (150%), the system returns the error code "E102-OVERSIZE" and maintains the current font setting.

[0065] To improve parsing efficiency, the system uses pre-compiled regular expressions to match font names and style parameters.

[0066] This pattern matches font names with a length of 2 to 10 characters and can contain up to two style suffixes. Inputs that fail the regular expression validation will be discarded directly to prevent invalid commands from entering the subsequent processing flow.

[0067] The parsed instruction data packet is passed to the font loading module via a message queue. The message queue adopts a publish-subscribe pattern, supporting multiple modules to consume the same instruction in parallel. For example, the font rendering engine subscribes to the "font ready" event, and the layout analysis module subscribes to the "font switching complete" event, realizing decoupling and asynchronous communication between modules.

[0068] The system maintenance command execution state machine records the current font switching progress and resource usage. The state machine includes the following state transitions:

[0069] Pending: The instruction has been received but no resources have been allocated;

[0070] Loading: Font files are loading or downloading;

[0071] Ready: The font is available for rendering;

[0072] Failure: An unrecoverable error occurred during instruction execution.

[0073] Status change events are synchronized to the user interface in real time; for example, a progress bar is displayed when the status is loading, and an error icon is displayed when the status is failing.

[0074] In this embodiment of the invention, the loading and replacement of font files are subsequent execution steps to the font switching instruction. Their function is to dynamically acquire the target font resource based on the parsed instruction data and complete the font mapping update of the electronic document rendering engine. This step must ensure efficient loading of font files, reasonable allocation of storage resources, and data coordination with the character literal calculation module, providing basic glyph data support for the dynamic adjustment of the page layout.

[0075] The system queries the local font cache directory based on the font identifier (e.g., "HT-BOLD-001"). If the target font file is already cached (e.g., " / cache / fonts / HT-BOLD-001.ttf"), the file is loaded into the rendering engine's shared memory area using memory mapping technology. The physical address offset for memory mapping is calculated as follows:

[0076] Offset=BaseAddr+(FontID modN)×BlockSize

[0077] Where BaseAddr is the base address of the memory pool, NN is the number of memory blocks, and BlockSize is the maximum reserved space for a single font file (e.g., 4MB). If the font is not cached, an asynchronous download process is triggered, and an encrypted font package is obtained from the cloud font library via the HTTPS protocol. The decryption key is dynamically generated by the Hardware Security Module (HSM).

[0078] The font file decryption process employs a hybrid encryption algorithm. The font package delivered from the cloud contains symmetric-encrypted font data and asymmetric-encrypted key data. Decryption begins with the device's private key K. private Decrypting the key data yields the symmetric key K. sym Then, the font data is decrypted using the AES-256 algorithm:

[0079] FontData = AES256_Decrypt(C encrypted ,K sym IV);

[0080] Among them, C encrypted The font data is encrypted, and the IV is the initialization vector. After decryption, the integrity of the font file is verified, and its SHA-256 hash value H is calculated. file It is then compared with the pre-stored hash value in the cloud. If they do not match, the file is deemed corrupted, triggering a retry mechanism.

[0081] In some embodiments, the font loading module employs a multi-threaded parallel strategy to improve efficiency. The main thread is responsible for instruction parsing and resource allocation, while sub-threads perform file I / O and memory mapping operations. For example, when loading large font files (such as Unicode fonts containing 10,000+ characters), sub-threads load them in segments according to character encoding, prioritizing the loading of the character set of the currently visible area (such as the ASCII range 0x20-0x7E), while non-critical characters (such as rare Chinese characters) are loaded later.

[0082] Font replacement in the rendering engine is achieved by updating the glyph mapping table. This table is a hash structure where the keys are the Unicode encoding of the character, and the values ​​are the storage addresses of the glyph data. During replacement, the glyph index table of the target font is traversed, and key-value pairs in the original font mapping table are replaced one by one. For example, the glyph pointer of the character "A" (Unicode U+0041) is updated from address 0x7F89A in "SimSun.ttf" to address 0x9B2C0 in "HeiTi-Bold.ttf".

[0083] Font replacement in the rendering engine is achieved by updating the glyph mapping table. This table is a hash structure where the keys are the Unicode encoding of the character, and the values ​​are the storage addresses of the glyph data. During replacement, the glyph index table of the target font is traversed, and key-value pairs in the original font mapping table are replaced one by one. For example, the glyph pointer of the character "A" (Unicode U+0041) is updated from address 0x7F89A in "SimSun.ttf" to address 0x9B2C0 in "HeiTi-Bold.ttf".

[0084] In some embodiments, the system maintains a status flag for the font cache to optimize resource utilization. Each font file in the cache directory is associated with a metadata file that records the last access time T. access Frequency of use F usage and file size S file When cache space is insufficient, fonts will be evicted according to the following priority:

[0085]

[0086] α and β are weighting coefficients (default values ​​α = 0.7, β = 0.3), T current This is the current system time.

[0087] For high-concurrency scenarios, the system employs a font preloading mechanism. Based on user behavior history, it predicts the fonts that might be used. For example, if a user frequently switches to "Bold," the font is preloaded into the memory cache during idle periods. The preloading is triggered by the following conditions:

[0088]

[0089] Where, N access For the statistical period T period The number of font accesses within 24 hours (e.g., θ is the threshold (e.g., 5 times / day).

[0090] Asynchronous downloads of font files support resuming interrupted downloads. Download tasks are divided into multiple data blocks (e.g., 1MB / block), each containing a checksum. If the network is interrupted and then resumed, only the blocks that failed the checksum verification need to be downloaded again. For example, if the total file size is 5MB, and 3MB has been downloaded and the checksum has passed, the download will resume from the 4th block.

[0091] The memory-mapped regions are configured with read / write permission isolation. The glyph data area is read-only to prevent accidental tampering; the font metadata area is read-write, supporting dynamic updates of usage frequency and timestamps. Permission isolation is implemented through the operating system's Memory Management Unit (MMU), for example, by calling the mprotect() function in the Linux kernel to set the PROT_READ flag.

[0092] When the system detects a font loading timeout (e.g., >5 seconds), it initiates a degraded rendering mode. In degraded mode, the system's default font (e.g., "SimSun") is temporarily used to replace the target font, and a notification is pushed to the user. Simultaneously, the background continuously retryes the loading process, automatically switching back to the target font upon successful retry to ensure a continuous user experience.

[0093] Through the above embodiments, the font file loading and replacement module achieves efficient resource management, secure transmission mechanism and fault tolerance, ensuring the smoothness of the font switching process and data integrity, and providing reliable input for subsequent character literal adjustment and layout rendering.

[0094] In this embodiment of the invention, the literal ratio calculation and scaling factor adjustment are core steps in the layout optimization after font switching. Their function is to quantify the differences in display characteristics between the target font and the preset font, and based on this, dynamically adjust character size parameters to ensure that the line width, character height, and layout ratio after font scaling meet reading aesthetic standards. This step needs to be linked with the glyph data output by the font loading module and provides a scaling benchmark for subsequent updates to line spacing and paragraph spacing.

[0095] In some embodiments, the literal ratio is defined as the normalized ratio of the actual display area of characters to the design area, which is used to measure the change in visual density of the font during the scaling process. The actual display area is calculated by a pixel filling algorithm, excluding the interference of transparent areas and edge jaggedness; the design area is the area of the geometric bounding box of the font vector graph. The specific calculation formula is:

[0096]

[0097] where A display represents the total number of non-transparent pixels actually occupied by the character on the screen, and A design is the product of the width W bbox and the height H bbox of the vector bounding box, that is:

[0098] A design =W bbox ×H bbox ;

[0099] For example, if the width of the vector bounding box of the character "国" is 24 units and the height is 28 units, then the design area is 672 square units; if 580 non-transparent pixels are occupied after actual rendering, then the literal ratio

[0100] In some embodiments, the scale factor k is determined by the ratio of the literal ratio of the target font to the preset font, and is used to adjust the display ratio of the target font to match the visual consistency of the preset layout. The calculation formula is:

[0101]

[0102] where R target is the original literal ratio of the target font, and R preset is the literal ratio of the preset font. For example, the preset font is Song typeface (R preset =80%), and the target font is Boldface (R target =90%), then the adjusted literal ratio R adjusted needs to satisfy:

[0103] R adjusted =R preset ×k;

[0104] In this example, R adjusted =80%×1.125 = 90%, that is, after the Boldface is scaled by this scale factor, its visual density is consistent with the original typesetting effect of the Song typeface.

[0105] For dynamic character width adjustment of non-monospace fonts, a compensation coefficient δ is introduced to eliminate the cumulative error in the scaling factor calculation. The compensation coefficient is based on the character width deviation ΔW = W. target -W pereset calculate:

[0106]

[0107] Adjusted character width W final for:

[0108] W final =W preset ×k×δ;

[0109] For example, the preset font character width W preset =10px, the original width W of the target font target =11px, then ΔW = 1px. If k = 1.125, then the final width W final =10×1.125×1.1=12.375px.

[0110] In some embodiments, the system maintains a literal value parameter table to support multi-font mixed typesetting scenarios. The parameter table stores the original literal value R of each font. raw Adjusting the scaling factor k and its historical adjustment records. When a user uses multiple fonts simultaneously (e.g., bold for headings and serif for body text), the system dynamically calculates the global scaling factor k based on the parameter table. global :

[0111]

[0112] Among them, w i Let k be the weight of the i-th font in the document (calculated based on the percentage of characters), and n be the number of font types. For example, if boldface accounts for 30% and serifface accounts for 70% in the document, then k... global A scaling factor biased towards Song typeface.

[0113] The literal value calculation module interacts with the rendering engine in real time to obtain pixel-level data. The rendering engine outputs the bitmap data and bounding box coordinates of the characters, and the literal value module counts the number of non-transparent pixels (A). display And calculate A by combining vector metadata. design To avoid rendering delays affecting computational efficiency, the system employs a dual-buffering mechanism: a foreground buffer for real-time display and a background buffer for asynchronously updating literal values.

[0114] In some embodiments, for complex glyphs (such as ligatures and decorative symbols), the literal value calculation employs a region-based weighting strategy. The character is decomposed into multiple geometric regions (such as the main body and decorative lines), and each region is assigned a different weight λ. j (∑λj =1), the final literal value is calculated using a weighted sum:

[0115]

[0116] For example, a ligature character is decomposed into two regions: the main part has a weight of λ1 = 0.8, and the ligature part has a weight of λ2 = 0.2. These are calculated separately and then combined into the overall character literal value.

[0117] The system sets a dynamic adjustment threshold for the scaling factor to prevent over-scaling. When |k-1| > 0.2|, a user confirmation process is triggered, displaying the message "Scaling ratio exceeds the recommended range," and allowing manual correction. For example, if k = 1.25 is calculated, the system will pop up a window asking if the user accepts the adjustment. If the user refuses, the system will revert to k = 1.0 and maintain the original layout.

[0118] In some embodiments, scaling factor adjustment and character anti-aliasing rendering are optimized together. The scaled character edges are smoothed using the Lanczos interpolation algorithm, with the following interpolation kernel function:

[0119]

[0120] Where 'a' is the window size (usually 3), and 'x' is the pixel position offset. Adjusting the value of 'a' controls the balance between smoothing intensity and computational cost.

[0121] In this embodiment of the invention, the dynamic updating of layout parameters is based on the adjusted character ratio and scaling factor. The line spacing, character spacing, and paragraph spacing of the electronic document are recalculated in real time to ensure that the layout structure after font switching maintains aesthetic consistency with the original design. This step needs to be precisely linked with the scaling factor output by the character ratio calculation module and provide formatting instructions to the rendering engine, achieving overall optimization from character-level adjustment to paragraph-level layout.

[0122] The dynamic adjustment of line spacing is achieved through a functional relationship between the character width and font height. Line spacing L line The calculation formula is:

[0123] L line =α×H font ×k;

[0124] Among them, H font Here, H is the base height of the current font (in pixels), k is the scaling factor, and α is the line spacing coefficient (default value 1.5). For example, when H... font When =16px and k=1.125, the line spacing is updated as follows:

[0125] L line =1.5×16×1.125=27px

[0126] The adjustment of character spacing introduces a character width compensation mechanism. Basic character spacing S base After scaling by a scaling factor and overlaying the difference index compensation value ΔS output by the font feature analysis module, the final character spacing formula is:

[0127] S char =β×W font ×k+ΔS

[0128] Among them, W font β is the base character width, β is the character spacing coefficient (default value 0.1), and ΔS is calculated based on the difference index D:

[0129] For example, if D = 1.8, then ΔS = 0.5 × 1.8 = 0.9px.

[0130] The line spacing compensation value ΔL is calculated using a quadratic function to avoid over-adjustment.

[0131] ΔL=0.1×D 2

[0132] For example, if D = 1.8, then ΔL = 0.1 × 1.8 2 =0.324px.

[0133] In some embodiments, for complex glyphs (such as connected characters and decorative symbols), the feature analysis module employs a region-based weighting strategy. The character is decomposed into multiple geometric regions (such as the main body and decorative lines), and each region is assigned a different weight λ. j (∑λ j =1), the final eigenvectors are calculated using a weighted sum:

[0134]

[0135] For example, the weight of the main body of the connected character “fi” is λ1 = 0.8, and the weight of the connected part is λ2 = 0.2.

[0136] In some embodiments, the system monitors the accuracy of feature extraction in real time and triggers anomaly handling. When the Euclidean distance D of the feature vectors exceeds a preset threshold (e.g., 3.0), it is determined to be an abnormal font, reverts to a preset font, and generates a log.

[0137] In some embodiments, the feature analysis module supports multilingual font adaptation. For non-Latin character sets (such as Chinese and Japanese), a glyph structure complexity factor C is introduced, and the formula for calculating the difference index is adjusted as follows:

[0138] D adjusted =D×(1+0.1×C);

[0139] Among them, C is the number of strokes or components of a character. For example, for the Chinese character "国", C = 8, then D adjusted = D × 1.8.

[0140] The system optimizes the parameters of the feature extraction model through experimental data. Using a training set containing 10,000+ font samples, the hyperparameters of the CNN model (such as learning rate 0.001 and batch size 32) are determined through cross-validation. The training loss function is the mean squared error (MSE), and the optimization goal is to minimize the reconstruction error of the feature vector.

[0141] Through the above embodiments, the font feature analysis and differential compensation module realizes high-precision feature extraction, dynamic compensation adjustment and multi-language adaptation capabilities, ensuring that the layout after font switching remains visually coordinated, and at the same time has strong robustness and scalability.

[0142] In the embodiments of the present invention, multi-dimensional context modeling and dynamic recommendation, as the intelligent core of the reading layout optimization process, functions to comprehensively analyze device status, environmental conditions and user behavior data, and generate reading mode parameters adapted to the current context in real time, ensuring that electronic documents can provide the best reading experience in different usage scenarios. This step needs to be linked with the differential index output by the font feature analysis module and provide dynamic adjustment instructions for the layout update module to achieve a closed-loop optimization from data collection to parameter recommendation.

[0143] The context modeling module constructs a comprehensive context model through multi-source data fusion. The data includes device status data (such as screen size, resolution, DPI), environmental condition data (such as ambient light intensity, noise level) and user behavior data (such as reading speed, heat map of the fixation area). For example, device status data is obtained in real time through the system API, ambient light intensity is collected by a light sensor, and user behavior data is recorded by a touch screen or an eye tracker.

[0144] In some embodiments, the normalization processing of the ambient light intensity adopts piecewise linear mapping. The formula for converting the light intensity value I (unit: lux) into the percentage coefficient η is:

[0145]

[0146] For example, when I = 50, η = 90 / 50 - 10 ≈ 0.444.

[0147] The user's reading speed V read is calculated through the page turning interval time T page as follows:

[0148]

[0149] where N wordsThis represents the number of words per page. For example, if each page contains 300 words and the page-turning interval is 2 minutes, then V... read =120 / 300=2.5 ​​words / second.

[0150] Long Short-Term Memory (LSTM) networks are used to model time-series data. The input sequence is X = [x1, x2, ..., x...]. T ], where x t Includes ambient light intensity, reading speed, and device status data. The LSTM's hidden state h t The updated formula is: h t =LSTM(x t h t-1 );

[0151] Output layer predicted reading mode parameter p t :

[0152] P t =W·h t +b;

[0153] Where W is the weight matrix and b is the bias vector.

[0154] F size =F base ×0.5+0.5×η;

[0155] For example, the base font size F base =12pt, ambient light intensity coefficient η=0.444, then:

[0156] F size =12×(0.5+0.5×0.444)≈8.67pt;

[0157] Background color switching rules are based on ambient light intensity and user preferences. When η < 0.5, dark mode is enabled, and the background brightness B decreases exponentially.

[0158] B(t) = B0 × e -λt ;

[0159] Where B0 is the initial brightness (e.g., RGB(30,30,30)), λ is the attenuation coefficient (default 0.01), and t is the reading time (minutes). For example, when t = 30 minutes, B(30) = 30 × e -0.01×30 ≈22.2.

[0160] The dynamic adjustment of line spacing is combined with the rate of change of reading speed ΔV. The line spacing formula is:

[0161] L line =L base ×(1+α×ΔV);

[0162] Among them, L base This is the base line spacing, with α being an adjustment factor (default 0.2). For example, if L... base =24px, ΔV=0.5, then: L line =24×(1+0.2×0.5)=26.4px;

[0163] The system optimizes the hyperparameters of the LSTM model using experimental data. A training set containing 10,000+ samples is used, and cross-validation is employed to determine the number of hidden layers (e.g., 3 layers), learning rate (e.g., 0.001), and batch size (e.g., 32). The training loss function is the mean squared error (MSE), and the optimization objective is to minimize the deviation between the recommended parameters and the user's actual preferences.

[0164] The context modeling module supports multi-device data synchronization. User preferences and context parameters are shared in real-time via a cloud database, ensuring a consistent reading experience across different devices. For example, dark mode settings on a tablet are automatically synchronized to the phone, reducing the need for manual adjustments.

[0165] The system monitors changes in the environment in real time and triggers dynamic adjustments. When there are significant changes in ambient light intensity or reading speed (such as |Δη|>0.2 or |ΔV|>0.5), the recommended parameters are updated immediately and the document is re-rendered, with the response latency controlled within 200 milliseconds.

[0166] In this embodiment of the invention, cross-device adaptation and anti-aliasing are key steps in the reading layout optimization process. Their function is to ensure that electronic documents present a consistent visual effect on different devices (such as mobile phones, tablets, and computers), while simultaneously eliminating jagged edges after font scaling through advanced rendering technology, thus improving the clarity and comfort of the reading experience. This step needs to be linked with the character size parameters output by the layout update module and provide adaptation instructions and anti-aliasing parameters to the rendering engine, achieving a seamless connection from device adaptation to visual optimization.

[0167] Cross-device adaptation is achieved through a responsive layout algorithm. This algorithm is based on the available screen width W. available With character width W char Dynamically adjust the number of characters N per line:

[0168]

[0169] Among them, W available Subtract the margins (e.g., 16px on each side) from the screen width, W char This represents the average character width of the current font. For example, if the screen width is 360px and the character width is 8px, then the number of characters per line is:

[0170]

[0171] For high-resolution devices (such as Retina displays), the system employs subpixel rendering technology to eliminate jagged edges on fonts. Subpixel rendering calculates the brightness values ​​of character edge pixels using an interpolation algorithm, with the Lanczos function as the interpolation kernel.

[0172]

[0173] Where x is the pixel position offset, and a is the window size (default 3). For example, for a pixel p at the edge of a character, its brightness value I... p The calculation is as follows:

[0174]

[0175] Among them, I p+i This represents the brightness value of adjacent pixels.

[0176] In some embodiments, the system dynamically adjusts the anti-aliasing intensity based on the device's DPI. The relationship between anti-aliasing smoothness σ and the DPI value D is as follows:

[0177]

[0178] Where, σ base The base smoothness is 1.0 (default), and 96 is the standard DPI value. For example, when D = 192, σ = 1.0 × 2 ≈ 1.414, and the rendering engine increases the Gaussian blur radius to improve the smoothing effect.

[0179] The cross-device adaptation module supports dynamic adjustment of multiple screen ratios. For widescreen devices (such as 16:9), the system increases paragraph spacing to balance the visual center of gravity; for narrowscreen devices (such as 4:3), the system compresses character spacing to avoid frequent line breaks. For example, the paragraph spacing adjustment formula is:

[0180]

[0181] Among them, W available H is the available width. available This is the available height.

[0182] In some embodiments, the system monitors device performance in real time and triggers a degraded rendering mode. When the device CPU load exceeds 80% or memory usage exceeds 90%, subpixel rendering is disabled and a fast anti-aliasing algorithm (such as bilinear interpolation) is enabled to ensure that the rendering frame rate is not lower than 30fps.

[0183] The cross-device adaptation module works in conjunction with a cloud database to store user preferences and device configurations. For example, font size and line spacing settings configured on a tablet are automatically synchronized to the phone, reducing the need for manual adjustments. Synchronized data is transmitted encrypted to ensure user privacy and security.

[0184] The system optimizes the interaction experience for touch devices. By detecting the touch screen click coordinates (x, y), it dynamically adjusts the character spacing and line spacing within the click area to improve the operation accuracy. For example, the character spacing within the click area is adjusted to:

[0185]

[0186] where d is the distance between the click point and the character center, and r is the character radius.

[0187] The anti - aliasing processing module supports the edge optimization of multi - language fonts. For non - Latin character sets (such as Chinese and Japanese), a glyph complexity factor C is introduced, and the smoothing formula is adjusted to:

[0188] σ adjusted = σ×(1 + 0.1×C);

[0189] where C is the number of strokes or components of the character. For example, for the Chinese character "国", C = 8, then σ adjusted = σ×1.8.

[0190] The system optimizes the parameters of the anti - aliasing algorithm through experimental data. Using a training set containing 10,000 + font samples, the optimal values of the Lanczos window size a and the smoothness σ are determined through cross - validation. The training loss function is the visual perception error (VPE), and the optimization goal is to minimize the user's subjective score for the font edge jaggedness.

[0191] In the embodiments of the present invention, user data storage and model optimization are the closed - loop links of the reading layout optimization process. Its function is to iteratively optimize the parameters of the font feature analysis model and the context recommendation model by collecting user behavior data and preference settings, ensuring that the system can adapt to different users' reading habits and needs. This step needs to be linked with the recommended parameters output by the multi - dimensional context modeling module and provide training data for the font feature analysis module to achieve a complete closed - loop from data collection to model optimization.

[0192] In some embodiments, user behavior data includes font selection records, layout parameter adjustment records, and reading duration statistics. The data is stored in a relational database (such as MySQL) in a structured format, and the table structure includes fields: user ID, timestamp, operation type, parameter value. For example, the record of a user adjusting the font size is stored as:

[0193] User preference data is synchronized across multiple devices through a cloud database. The synchronization protocol uses encrypted transmission based on OAuth2.0 to ensure data security. For example, the dark mode parameter set by the user on the tablet is automatically synchronized to the mobile phone, reducing the number of manual adjustments.

[0194] The model optimization module iteratively updates the weight parameters of the Convolutional Neural Network (CNN) and the Long Short-Term Memory Network (LSTM) using the gradient descent algorithm. The loss function, Loss, comprehensively considers layout distortion and the frequency of user operation interruptions.

[0195]

[0196] Where SSIM is the structural similarity index (range 0-1), N interrupt T represents the number of times the user manually adjusts the parameters. total This represents the total number of operations.

[0197] The Structural Similarity Index (SSIM) is calculated by comparing the image similarity between documents before and after adjustment.

[0198]

[0199] Where, μ x μ y Let σ be the mean of the x and y values ​​of the image. x σ y Variance, σ xy The covariance is represented by C1 and C2, which are stability constants (default C1 = 0.01, C2 = 0.03).

[0200] The model is trained using the Adam optimizer, with the learning rate η dynamically adjusted.

[0201]

[0202] Where, η base The base learning rate is 0.001 (default), and t is the number of training steps. For example, the learning rate at step 100 is 0.001 × 1100 = 0.0001.

[0203] The system optimizes model hyperparameters using experimental data. A training set containing 10,000+ samples is used, and cross-validation is employed to determine the number of hidden layers (e.g., 3 layers), batch size (e.g., 32), and regularization coefficient (e.g., 0.01). The training loss function is mean squared error (MSE), and the optimization objective is to minimize the deviation between the recommended parameters and the user's actual preferences.

[0204] User feedback data was collected through A / B testing. The system randomly assigned users to different experimental groups, each using a different combination of recommendation parameters (such as font size and line spacing), and recorded user satisfaction scores S (range 0-5). The score data was used to optimize the weights of the loss function.

[0205] Loss adjusted =Loss×(1+0.1×(5-S));

[0206] For example, if the user rating S = 4, then the adjusted loss function is Loss × 1.1.

[0207] In some embodiments, the system monitors model performance in real time and triggers a retraining mechanism. When the model prediction error E exceeds a preset threshold (e.g., 0.1), a new round of training is automatically started. The prediction error is calculated as follows:

[0208]

[0209] Among them, P predicted Recommend parameters for the model, P actual The user actually selects the parameters.

[0210] The model optimization module supports incremental learning. New user data is used to update model weights in real time via an online learning algorithm, avoiding the computational overhead of full training. For example, using the stochastic gradient descent (SGD) algorithm, each update processes only a single sample:

[0211]

[0212] Where, θ t Here are the model parameters, and η is the learning rate. This is the gradient of the loss function.

[0213] The system uses visualization tools to showcase the model optimization process. Training loss curves, prediction error distributions, and user satisfaction ratings are presented in chart form, facilitating developers' analysis of model performance. For example, the loss curve shows the change in loss value for each training round, helping to identify overfitting or underfitting issues.

[0214] In this embodiment of the invention, exception handling and logging serve as a safeguard mechanism for the reading layout optimization process. Their function is to monitor the system's operational status in real time, capture and handle various abnormal events, and record detailed logs for subsequent analysis and optimization. This step needs to be coordinated with modules such as font loading, layout updates, and model optimization to ensure the system can still provide stable service under abnormal conditions and to provide developers with data support for troubleshooting and performance optimization.

[0215] The anomaly detection module monitors the system status in real time using multi-dimensional indicators. These indicators include CPU utilization (U). CPU Memory usage U memU Network latency L net and rendering frame rate F render When any indicator exceeds a preset threshold, an abnormal state machine is triggered. For example, if U... CPU >80% or F render <30fps is considered a performance anomaly.

[0216] The exception handling strategy is dynamically adjusted based on the exception type. For font loading failure exceptions, the system attempts to reload from a backup font library; for layout overflow exceptions, the system automatically compresses character spacing or triggers a forced line break. For example, when the total width of characters in a line is W... total Exceeding the available line width W available When adjusting the character spacing S char for:

[0217]

[0218] Among them, S base Based on character spacing, W available W is the available screen width minus the margins (e.g., 16px on each side). total This is the sum of the widths of all characters in the current line. For example, if S... base =1.8px, W available =360px, W total = 400px, then the adjusted letter spacing is:

[0219]

[0220] The logging module uses a structured format to store exception events and operation records. Log entries include timestamps, event types, error codes, device information, and context data.

[0221] In some embodiments, the system uses a sliding window algorithm to detect the suddenness of anomalous events. The window size WW is the number of the most recent NN log records, and the anomaly frequency F anomaly The calculation is as follows:

[0222]

[0223] Where, N error N represents the number of error logs in the window, and N is the window size (default 100). If F anomaly A value >0.1 triggers a system alarm and generates a diagnostic report. For example, if 15 of the last 100 log entries are error logs, then F... anomaly =15 / 100=0.15, triggering an alarm.

[0224] The exception handling module supports a multi-level recovery mechanism. For recoverable exceptions (such as network timeouts), the system automatically retrys the operation, with the number of retries R increasing exponentially using a backoff strategy.

[0225] R = R base ×2 k ;

[0226] Among them, R baseThe base retry interval is k (e.g., 1 second), and k is the number of retries. For example, the interval for the third retry is 1 × 2^3 = 8 seconds. If the number of retries exceeds the maximum limit (e.g., 5 times), it is determined to be an unrecoverable exception, triggering a rollback operation.

[0227] Log data is transmitted and stored in a cloud database using encryption to ensure data security and privacy protection. The encryption algorithm used is AES-256, and the key is dynamically generated by the Hardware Security Module (HSM). For example, an encrypted log entry is stored as: C = AES256_Encrypt(P,K,IV);

[0228] Where P is the plaintext log, K is the symmetric key, and IV is the initialization vector. During decryption, the plaintext is recovered using the same key and initialization vector.

[0229] P = AES256_Decrypt(C,K,IV);

[0230] The system uses visualization tools to display log data and anomaly trends. The log analysis dashboard displays the distribution of error types, changes in anomaly frequency, and device performance indicators, making it easier for developers to quickly locate problems. For example, the dashboard can highlight high-frequency error types (such as font loading failures) and related contextual information.

[0231] The exception handling module works in conjunction with the user feedback system. When a serious exception is detected (such as three consecutive font loading failures), the system pushes a notification to the user and guides them to submit a feedback report. The feedback data is used to optimize exception handling strategies and model parameters. For example, user feedback on "slow font loading" can trigger a priority adjustment in the network optimization module.

[0232] The system optimizes the parameters of the anomaly detection algorithm using experimental data. Using a training set containing over 10,000 anomaly samples, cross-validation is used to determine the sliding window size W and the anomaly frequency threshold F. threshold The training loss function is a weighted sum of the false positive rate (FPR) and the false negative rate (FNR):

[0233] Loss = 0.7 × FPR + 0.3 × FNR;

[0234] Here, FPR is the false positive rate (the proportion of normal events that are mistakenly identified as abnormal), and FNR is the false negative rate (the proportion of abnormal events that are not detected). The optimization objective is to minimize the overall detection error.

[0235] The system supports real-time streaming processing of log data. Log entries are collected through a distributed message queue (such as Kafka), and the frequency of anomalies is calculated in real time to trigger alarms. For example, if a certain type of anomaly occurs more than 10 times within one minute, an alarm notification is immediately pushed to the operations team.

[0236] The logging module supports multiple log levels (such as DEBUG, INFO, WARN, ERROR). Different log levels are stored in different database tables for easy querying and analysis. For example, DEBUG level logs are used only for development and debugging, while ERROR level logs are used for troubleshooting.

[0237] Through the above embodiments, the anomaly handling and logging module achieves high-precision anomaly detection, intelligent recovery mechanism and secure data storage, ensuring the stability and maintainability of the system in complex scenarios, while providing reliable data support for performance optimization.

[0238] Although embodiments of the invention have been shown and described, it will be understood by those skilled in the art that various changes, modifications, substitutions and alterations can be made to these embodiments without departing from the principles and spirit of the invention, the scope of which is defined by the appended claims and their equivalents.

Claims

1. A method of reading layout optimization, characterized by, The method comprises the following steps: Step 1: receiving a font switching instruction input by a user, and analyzing the instruction to determine a target font and its style attribute; Step 2: loading a corresponding font file according to the target font to complete font replacement of the electronic document; Step 3: calculating a scaling factor and adjusting the x-height of the target font based on the x-height values of the preset font and the target font, wherein the x-height is the ratio of the actual display area of the font to the design area; Step 4: updating the layout parameters of the electronic document according to the adjusted x-height, including line spacing, word spacing and paragraph spacing; Step 5: presenting the adjusted electronic document to the user and saving the user settings for subsequent recovery; Step 6: extracting stroke thickness and slant angle features of the target font through a font feature analysis module, and generating a difference index to fine-tune the layout parameters; The font feature analysis module comprises: extracting stroke thickness, slant angle and glyph structure features of the target font image through a convolutional neural network, wherein the input of the convolutional neural network is a grayscale font image, and the grayscale processing adopts a weighted average method, and the calculation formula is: Gray value = 0.299R + 0.587G + 0.114B; wherein R, G and B are the pixel values of the red, green and blue channels of the font image, respectively; analyzing the semantic features of the target font through natural language processing technology to generate a semantic vector containing emotional tendency and application scenario; fusing the image feature vector and the semantic vector into a comprehensive feature vector, and calculating the Euclidean distance between the comprehensive feature vector and the feature vector of the reference font to generate a difference index; The compensatory adjustment of the difference index comprises: when the difference index exceeds a preset threshold, the adjustment range of the word spacing is a linear function of the difference index; the adjustment range of the line spacing is a quadratic function of the difference index Step 7: constructing a multi-dimensional context model, dynamically recommending reading mode parameters based on device state data, ambient light intensity data and user behavior data, and the recommendation rules include real-time adjustment of font size, background color and line spacing.

2. The reading layout optimization method of claim 1, wherein, The scaling factor is determined by the ratio of the x-height value of the target font to the x-height value of the preset font, and the value range of the scaling factor is 0.8 to 1.5, which is determined based on user comfort test data.

3. The reading layout optimization method of claim 1, wherein, The update of the layout parameters comprises: the line spacing is 1.2 to 1.8 times the font height; the word spacing is 0.05 to 0.15 times the font width; the paragraph spacing is 1.0 to 1.5 times the line spacing, and the spacing between the top of the first line of the paragraph and the bottom of the last line of the previous paragraph is not less than 1.2 times the line spacing.

4. The reading layout optimization method of claim 1, wherein, The multi-dimensional context model construction comprises: real-time acquisition of device state data, including screen size, resolution and DPI; real-time acquisition of ambient light intensity data and conversion into a percentage coefficient of standard light value; time series modeling of user reading speed and page turning frequency through a long short-term memory network, wherein the number of hidden layers of the long short-term memory network is 3, the activation function is ReLU, and the loss function is mean square error; outputting dynamic reading mode parameters, including adjustment rules of font size, background color and line spacing.

5. The reading layout optimization method of claim 4, wherein, The adjustment rule of the dynamic reading mode parameter comprises: Font size = base font size × ambient light intensity coefficient; The ambient light intensity coefficient is a ratio of ambient light intensity to 100 lux; The background color is automatically switched to a dark mode or a light mode according to the ambient light intensity, and the background brightness value of the dark mode is exponentially attenuated with the user reading time.

6. The reading layout optimization method of claim 1, wherein, Step seven specifically comprises: The ratio of the available width of the screen to the character width is calculated in real time through a responsive layout algorithm, and when the ratio is lower than a preset threshold, the number of characters per line is automatically reduced and the paragraph rearrangement is triggered; For high-resolution screens, the sub-pixel rendering technology is used to perform anti-aliasing processing on the adjusted font, and the anti-aliasing algorithm is the Lanczos interpolation method.

7. The reading layout optimization method of claim 1, wherein, The saving and optimization of the user settings comprise: The user's historical font selection, layout parameter adjustment record and comfort score are stored in a relational database; The weight parameters of the convolutional neural network and the long short-term memory network model are iteratively updated through a gradient descent algorithm, and the optimization objective function is the total loss, which is quantified by the structural similarity index to measure the layout distortion, and combined with the user operation interruption frequency.

8. The reading layout optimization method of claim 1, wherein, The following accuracy requirements must be met for the adjustment of the character rate: The absolute value of the proportional error between the adjusted character width and the preset font character width is not more than 3%; The absolute value of the proportional error between the adjusted character height and the preset font character height is not more than 2%; When the accuracy requirements cannot be met for three consecutive adjustments, an abnormal processing procedure is triggered, the preset font is returned, and a system log alarm is generated.

Citation Information

Patent Citations

  • A method and device for proportional setting of font attributes

    CA2666471A1

  • Reading page optimization method and device and electronic reading terminal

    CN107122197A