Reading layout optimization method
By analyzing the target font features and building a multi-dimensional situational model, dynamically adjusting the layout parameters of the electronic reading equipment, the layout layout distortion caused by font scaling in the existing technology is solved, intelligent adaptation and consistent display across devices are realized, and reading comfort and efficiency are improved.
Patent Information
- Application Number
- CN202510358412.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-03-25
- Publication Date
- 2025-07-08
- Estimated Expiration
- 2045-03-25
AI Technical Summary
In the prior art, electronic reading equipment ignores the font design characteristics when font zooming, resulting in distortion of layout and the inability to dynamically adjust layout parameters according to ambient light intensity, equipment status and user behavior, affecting reading comfort and efficiency.
By receiving the font switching instructions input by the user, analyzing the target font features, calculating the scale factor to adjust the literal ratio, dynamically updating the layout parameters of the layout, and building a multi-dimensional situational model real-time recommended reading mode, combining font feature analysis and situational modeling to optimize font size, background color and line spacing.
It realizes intelligent adaptation according to different reading scenarios, accurately adjusts word spacing and line spacing, ensuring consistent display effect across devices, high system stability, and strong fluency in user experience, solving the problem of layout distortion caused by fixed proportion scaling.
Smart Images

Figure CN120276632A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of digital publication display, and specifically to a method for optimizing reading layout. Background Art
[0002] With the popularization of digital reading, electronic 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, layout, and cross-device adaptation. A good reading experience not only depends on clear font display, but also requires dynamically adjusting layout parameters according to environmental conditions, device status, and user behavior to provide the best visual effect and reading comfort.
[0003] In the prior art, electronic reading devices usually adjust the font size by fixed-scale zooming to adapt to different screen sizes and user preferences. For example, users can adjust the font size through a slider, and the system zooms the character width and height by a fixed ratio. In addition, some technical solutions also support simple line spacing and character spacing adjustments, but these adjustments are usually static and cannot be dynamically optimized according to font design characteristics or reading environment.
[0004] However, there is a significant problem in the prior art: fixed-scale zooming ignores the design characteristics of the font itself, resulting in serious distortion of the layout after the font is enlarged or reduced, unreasonable line spacing and character spacing, and affecting the reading comfort and efficiency. For example, for boldface and Song typeface, the ratio of character width to height is quite different under the same zoom ratio, resulting in an uncoordinated layout. In addition, the prior art cannot dynamically adjust layout parameters according to ambient light intensity, device status, and user behavior, and it is difficult to meet the personalized needs of users in different scenarios. Summary of the Invention
[0005] In view of the deficiencies of the prior art, the present invention provides a method for optimizing reading layout, which solves the problems of layout distortion caused by fixed-scale zooming of fonts in the prior art and the inability to dynamically adapt to the reading environment.
[0006] To achieve the above object, the present invention is realized through the following technical solutions: A method for optimizing reading layout, including the following steps: Step 1: Receive a font switching instruction input by the user, and parse the instruction to determine the target font and its style attributes; Step 2: Load the corresponding font file according to the target font to complete the font replacement of the electronic document; Step 3: Calculate a scale factor based on the literality values of the preset font and the target font, and adjust the literality of the target font, where the literality is the ratio of the actual display area of the font to the design area; Step 4: Update the layout parameters of the electronic document according to the adjusted literal ratio, including line spacing, character spacing, and paragraph spacing; Step 5: Present the adjusted electronic document to the user and save the user settings for subsequent restoration; 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; 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.
[0007] Preferably, the scale factor is determined by the ratio of the literal ratio value of the target font to the literal ratio value of the preset font, and the value range of the scale factor is 0.8 to 1.5, which is determined based on user comfort test data.
[0008] Preferably, the update of the layout parameters includes: The line spacing is 1.2 to 1.8 times the font height; The character 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 distance 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.
[0009] Preferably, the font feature analysis module includes: Extract the stroke thickness, slant angle, and glyph structure features of the target font image through a convolutional neural network. The input of the convolutional neural network is the grayscale font image, and the grayscale processing uses the weighted average method. The calculation formula is: Gray value = 0.299R + 0.587G + 0.114B; where R, G, and B are the pixel values of the red, green, and blue channels of the font image respectively; Analyze the semantic features of the target font through natural language processing technology to generate a semantic vector containing sentiment tendency and applicable scenarios; fuse the image feature vector and the semantic vector into a comprehensive feature vector, and calculate the Euclidean distance based on the comprehensive feature vector and the feature vector of the reference font to generate a difference index.
[0010] Preferably, the construction of the multi-dimensional context model includes: Real-time collect device status data, including screen size, resolution, DPI; Real-time collect ambient light intensity data and convert it into a percentage coefficient of the standard light value; Model the user's reading speed and page - turning frequency in time series through a long short - term memory network. The long short - term memory network has 3 hidden layers, the activation function is ReLU, and the loss function is mean squared error; Output dynamic reading mode parameters, including the adjustment rules for font size, background color, and line spacing.
[0011] Preferably, the adjustment rules for the dynamic reading mode parameters include: Font size = base font size × ambient light intensity coefficient; Where the ambient light intensity coefficient is the ratio of the ambient light intensity to 100 lux; The background color automatically switches to the dark mode or the light mode according to the ambient light intensity. The background brightness value in the dark mode decays exponentially with the user's reading duration.
[0012] Preferably, step seven specifically includes: Real - time calculate the ratio of the available screen width to the character width through a responsive layout algorithm. When the ratio is lower than the preset threshold, automatically reduce the number of characters per line and trigger a paragraph rearrangement; For high - resolution screens, use sub - pixel rendering technology to perform anti - aliasing processing on the adjusted font. The anti - aliasing algorithm is the Lanczos interpolation method.
[0013] Preferably, the saving and optimization of the user settings include: Store the user's historical font selections, layout parameter adjustments, and comfort scores in a relational database; Iteratively update the weight parameters of the convolutional neural network and the long short - term memory network model through the gradient descent algorithm. The optimization objective function is the total loss. The total loss quantifies the layout distortion degree through the structural similarity index and is calculated in combination with the user operation interruption frequency.
[0014] Preferably, the adjustment of the literal rate needs to meet the following accuracy requirements: The absolute value of the proportional error between the adjusted character width and the preset font character width does not exceed 3%; The absolute value of the proportional error between the adjusted character height and the preset font character height does not exceed 2%; When three consecutive adjustments cannot meet the accuracy requirements, trigger an exception handling process, roll back to the preset font, and generate a system log warning.
[0015] Preferably, the compensatory adjustment of the difference index includes: When the difference index exceeds the preset threshold, the adjustment amplitude of the character spacing is a linear function of the difference index; The adjustment amplitude of the line spacing is a quadratic function of the difference index.
[0016] The present invention provides a method for optimizing reading layout, which has the following beneficial effects: 1. The present invention adopts multi-dimensional scenario modeling and dynamic recommendation, achieving the technical effect of intelligent adaptation to different reading scenarios. Compared with the existing solution of scaling fonts at a fixed ratio, it solves the problem that it cannot dynamically adjust layout parameters according to ambient light intensity, device status, and user behavior. For example, the system can automatically switch to the dark mode according to the ambient light, which is more eye-friendly for night reading.
[0017] 2. The present invention introduces font feature analysis and differential compensation mechanism, achieving the technical effect of accurately adjusting character spacing and line spacing. Compared with the existing solution that ignores font design characteristics, it solves the problem of distorted layout after font scaling. For example, after switching between boldface and Song typeface, the proportion of character width and height remains coordinated.
[0018] 3. The present invention achieves the technical effect of consistent display on multiple devices through cross-device adaptation and anti-aliasing processing. Compared with the existing solution that only supports single-device adaptation, it solves the problem of inconsistent display effects under different screen resolutions. For example, when reading the same document on a mobile phone and a tablet, the visual effects are seamlessly connected.
[0019] 4. The present invention adopts exception handling and log recording, achieving the technical effects of high stability and maintainability. Compared with the existing solution lacking an exception recovery mechanism, it solves the problem that the system cannot be quickly restored after a crash. For example, when font loading fails, the system automatically retries and restores from the backup library, and the user experience is not affected. Brief Description of the Drawings
[0020] Figure 1 It is a schematic flowchart of the method of the present invention. Detailed Embodiments
[0021] Next, the technical solutions in the embodiments of the present invention will be clearly and completely described in conjunction with 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 creative efforts shall fall within the protection scope of the present invention.
[0022] Please refer to the attached Figure 1 , the embodiments of the present invention provide a method for optimizing reading layout, including the following steps: In the embodiments of the present invention, the reception and parsing of the font switching instruction is the initial step of the reading layout optimization process. Its function is to convert the user's interaction operation into a font replacement instruction executable by the system, and provide necessary input for subsequent font loading, literal rate 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.
[0023] The user triggers the 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 instruction 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 SimSun" is mapped to "HT-BOLD-001" to ensure an exact match with the index key values in the local or cloud font library.
[0024] The system validates the font name input by the user through a pre-set 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 validation passes, a formatted instruction is generated; if the validation fails, a "font unavailable" prompt is returned to the user and a log is recorded.
[0025] 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: In some embodiments, grayscale processing is a preprocessing step for font feature analysis, and its calculation formula is: Grayscale value = 0.299R + 0.587G + 0.114B; where R, G, and B respectively represent the red, green, and blue channel intensity values of the font image pixels, and the value range is from 0 to 255. For example, for a pure red pixel (R = 255, G = 0, B = 0), its grayscale value is calculated as: 0.299×255 + 0.587×0 + 0.114×0 = 76.245 ≈ 76 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 tags and timestamps. For example, high-priority instructions (such as real-time user operations) can interrupt low-priority tasks (such as background preloading) to ensure that the interaction response latency is less than 200 milliseconds.
[0026] The mapping relationship between font identification codes and physical font files is implemented through a hash table. The hash function uses the SHA-256 algorithm to generate unique key values, and the key value conflict rate is less than 1×10 -6 . For example, the font identification code "HT-BOLD-001" is mapped to the storage path " / fonts / HT / BOLD / 001.ttf" after hash operation. If the path does not exist, an asynchronous download process is triggered.
[0027] The instruction parsing module is linked with the exception handling subsystem. When illegal characters or style parameters beyond the preset range are detected, the system triggers an exception state machine, performs a rollback operation, and generates an error code. For example, when the user enters "font size = 200%", if it exceeds the maximum supported range of the system (150%), the error code "E102 - OVERSIZE" is returned and the current font settings remain unchanged.
[0028] To improve parsing efficiency, the system uses pre-compiled regular expressions to match font names and style parameters.
[0029] This pattern matches font names with a length of 2 to 10 characters and can contain at most two style suffixes. Input that fails regular verification will be directly discarded to avoid invalid instructions from entering the subsequent processing flow.
[0030] The parsed instruction data packet is passed to the font loading module through a message queue. The message queue uses a publish-subscribe pattern and supports 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 completed" event to achieve decoupling and asynchronous communication between modules.
[0031] The system maintains an instruction execution state machine to record the current font switching progress and resource occupancy. The state machine includes the following state transitions: Pending: The instruction has been received but no resources have been allocated; Loading: The font file is being loaded or downloaded; Ready: The font is available for rendering; Failed: An irrecoverable error occurred during the instruction execution.
[0032] State change events are synchronized to the user interface in real time. For example, a progress bar is displayed in the loading state, and an error icon is displayed in the failed state.
[0033] In the embodiments of the present invention, the loading and replacement of font files are subsequent execution steps of the font switching instruction. Its function is to dynamically obtain the target font resources according to the parsed instruction data and complete the font mapping update of the electronic document rendering engine. This step needs to ensure the efficient loading of font files, the reasonable allocation of storage resources, and the data collaboration with the typographic rate calculation module to provide basic glyph data support for the dynamic adjustment of the layout.
[0034] The system queries the local font cache directory according to the font identification code (such as "HT-BOLD-001"). If the target font file is already cached (such as " / cache / fonts / HT-BOLD-001.ttf"), the file is loaded into the shared memory area of the rendering engine through the memory mapping technology. The physical address offset of the memory mapping is calculated as: Offset = BaseAddr + (FontID mod N) × BlockSize where BaseAddr is the base address of the memory pool, N is the number of memory blocks, and BlockSize is the maximum reserved space for a single font file (for example, 4MB). If the font is not cached, an asynchronous download process is triggered, and the encrypted font package is obtained from the cloud font library through the HTTPS protocol. The decryption key is dynamically generated by the hardware security module (HSM).
[0035] The decryption process of the font file uses a hybrid encryption algorithm. The font package sent from the cloud contains symmetrically encrypted font data and asymmetrically encrypted key data. During decryption, first use the device private key K private to decrypt the key data to obtain the symmetric key K sym , and then decrypt the font data through the AES-256 algorithm: FontData = AES256_Decrypt(C encrypted , K sym , IV); where C encrypted is the ciphertext font data, and IV is the initialization vector. After decryption, verify the integrity of the font file, calculate its SHA-256 hash value H file and compare it with the pre-stored hash value in the cloud. If they are inconsistent, it is determined that the file is damaged, and a retry mechanism is triggered.
[0036] In some embodiments, the font loading module adopts a multi-threaded parallel strategy to improve efficiency. The main thread is responsible for instruction parsing and resource allocation, and the sub-threads perform file I / O and memory mapping operations. For example, when loading a large font file (such as a Unicode font containing 10,000+ characters), the sub-threads load in segments according to the character encoding, and preferentially load the character set of the current visible area (such as the ASCII range 0x20 - 0x7E), and delay the loading of non-critical characters (such as rare Chinese characters).
[0037] The font replacement of the rendering engine is achieved by updating the glyph mapping table. The mapping table is a hash structure, where the key is the Unicode encoding of the character and the value is the storage address of the glyph data. When replacing, traverse the glyph index table of the target font and replace each key-value pair in the original font mapping table one by one. For example, update the glyph pointer of the character 'A' (Unicode U+0041) from the address 0x7F89A in "SimSun.ttf" to the address 0x9B2C0 in "HeiTi-Bold.ttf".
[0038] The font replacement of the rendering engine is achieved by updating the glyph mapping table. The mapping table is a hash structure, where the key is the Unicode encoding of the character and the value is the storage address of the glyph data. When replacing, traverse the glyph index table of the target font and replace each key-value pair in the original font mapping table one by one. For example, update the glyph pointer of the character 'A' (Unicode U+0041) from the address 0x7F89A in "SimSun.ttf" to the address 0x9B2C0 in "HeiTi-Bold.ttf".
[0039] In some embodiments, the system maintains status flags 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 , the usage frequency F usage and the file size S file . When the cache space is insufficient, fonts are eliminated according to the following priority: α and β are weight coefficients (default values: α = 0.7, β = 0.3), and T current is the current system time.
[0040] For high-concurrency scenarios, the system adopts a font preloading mechanism. Predict the fonts that may be used based on the user's historical behavior. For example, if the user frequently switches to "HeiTi-Bold", then preload this font into the memory cache area during idle periods. The triggering conditions for preloading are: where N access is the number of font accesses within the statistical period T period (such as 24 hours), and θ is the threshold (such as 5 times / day).
[0041] Asynchronous download of font files supports resume from breakpoint. The download task is divided into multiple data blocks (such as 1MB / block), and each data block contains a checksum. If the network is interrupted and then restored, only the data blocks that failed the check need to be redownloaded. For example, if the total file size is 5MB, 3MB has been downloaded and passed the check, then the resume download starts from the 4th data block.
[0042] The memory mapping area is set to have read-write permission isolation. The glyph data area has read-only permission to prevent accidental tampering; the font metadata area has read-write permission to support dynamic update of usage frequency and timestamp. Permission isolation is implemented through the operating system's memory management unit (MMU), for example, calling the mprotect() function in the Linux kernel to set the PROT_READ flag.
[0043] When the system detects a font loading timeout (e.g. >5 seconds), it starts the degraded rendering mode. In degraded mode, the target font is temporarily replaced with the system default font (e.g. Songti), and a notification is pushed to the user. At the same time, the background continues to retry the loading process, and automatically switches back to the target font after success to ensure the continuity of the user experience.
[0044] Through the above embodiments, the font file loading and replacement module realizes efficient resource management, secure transmission mechanism and abnormal fault tolerance processing, ensures the smoothness and data integrity of the font switching process, and provides reliable input for subsequent font rate adjustment and layout rendering.
[0045] In the embodiment of the present invention, the character rate calculation and scale factor adjustment are the core steps of layout optimization after font switching. Their function is to quantify the difference in display characteristics between the target font and the preset font, and dynamically adjust the character size parameters based on this to ensure that the line width, character height and layout ratio after font scaling meet the reading aesthetic standards. This step needs to be linked with the glyph data output by the font loading module, and provide a scale benchmark for the subsequent update of line spacing and paragraph spacing.
[0046] In some embodiments, the font rate is defined as the normalized ratio of the actual display area of the character to the design area, which is used to measure the change in the 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 graphic. The specific calculation formula is: Among them, A display Indicates the total number of non-transparent pixels actually occupied by the character on the screen. design is the width W of the vector bounding box bbox With height H bbox The product of, that is: A design =W bbox ×H bbox ; For example, the vector bounding box of the character "国" is 24 units wide and 28 units high, so the design area is 672 square units; if it occupies 580 non-transparent pixels after actual rendering, the character rate is
[0047] In some embodiments, the scaling factor k is determined by the ratio of the literal rate of the target font to the literal rate of 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: where R target is the original literal rate of the target font, and R preset is the literal rate of the preset font. For example, if the preset font is Song typeface (R preset = 80%), and the target font is Boldface (R target = 90%), then the adjusted literal rate R adjusted needs to satisfy: R adjusted = R preset × k; In this example, R adjusted = 80% × 1.125 = 90%, that is, after the Boldface is scaled by this scaling factor, its visual density is the same as the original typesetting effect of the Song typeface.
[0048] For the dynamic adjustment of the character width of non-uniform-width fonts, a compensation coefficient δ is introduced to eliminate the cumulative error in the calculation of the scaling factor. The compensation coefficient is calculated according to the character width deviation ΔW = W target - W pereset : The adjusted character width W final is: W final = W preset × k × δ; For example, if the character width W preset of the preset font is 10px, and the original width W target of the target font is 11px, then ΔW = 1px, if k = 1.125, then the final width W final = 10 × 1.125 × 1.1 = 12.375px.
[0049] In some embodiments, the system maintains a literal rate parameter table to support multi-font mixed typesetting scenarios. The parameter table stores the original literal rate R raw of each font, the scaling factor k, and the historical adjustment records. When the user uses multiple fonts simultaneously (such as using Boldface for the title and Song typeface for the body text), the system dynamically calculates the global scaling factor k global based on the parameter table: where w iis the weight of the i-th font in the document (calculated based on the proportion of the number of characters), and n is the number of font types. For example, if the bold font accounts for 30% and the Song typeface accounts for 70% in the document, then k global The scaling factor biased towards the Song typeface.
[0050] The typographic ratio 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 typographic ratio module counts the number of non-transparent pixels A display and calculates A in combination with the vector metadata design . To avoid the impact of rendering latency on calculation efficiency, the system adopts a double-buffer mechanism: the foreground buffer is used for real-time display, and the background buffer asynchronously updates the typographic ratio parameters.
[0051] In some embodiments, for complex glyphs (such as ligatures, decorative symbols), the typographic ratio calculation adopts a regional weighting strategy. The character is decomposed into multiple geometric regions (such as the main body part, decorative lines), and different weights λ j (∑λ j = 1) are assigned to each region, and the final typographic ratio is calculated according to the weighted sum: For example, a ligature character is decomposed into two regions, the weight of the main body part λ1 = 0.8, and the weight of the connecting stroke part λ2 = 0.2. After separate calculations, they are combined into the overall typographic ratio.
[0052] The system sets a dynamic adjustment threshold for the scaling factor to prevent excessive scaling. When |k - 1| > 0.2, the user confirmation process is triggered, prompting "The scaling ratio exceeds the recommended range", and manual correction is allowed. For example, if k = 1.25 is calculated, the system pops up a window to ask if the adjustment is accepted. If the user refuses, it will roll back to k = 1.0 and maintain the original layout.
[0053] In some embodiments, the scaling factor adjustment is synergistically optimized with the character anti-aliasing rendering. The edges of the scaled characters are smoothed using the Lanczos interpolation algorithm, and the interpolation kernel function is: where a is the window size (usually taken as 3), and x is the pixel position offset. By adjusting the value of a, the balance between the smoothing intensity and the calculation overhead can be controlled.
[0054] In the embodiments of the present invention, the dynamic update of the layout parameters is based on the adjusted typographic ratio and scaling factor, and 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 is aesthetically consistent with the original design. This step needs to be precisely linked with the scaling factor output by the typographic ratio calculation module and provide formatted layout instructions for the rendering engine to achieve the overall optimization from character-level adjustment to paragraph-level layout.
[0055] The dynamic adjustment of line spacing is achieved through the functional relationship between the literal ratio and the font height. The line spacing L line is calculated by the formula: L line = α × H font × k; where H font is the baseline height of the current font (unit: pixel), k is the scale factor, and α is the line spacing coefficient (default value 1.5). For example, when H font = 16px and k = 1.125, the line spacing is updated to: L line = 1.5 × 16 × 1.125 = 27px The adjustment of character spacing introduces a character width compensation mechanism. After the basic character spacing S base is scaled by the scale factor, the differential index compensation value ΔS output by the font feature analysis module is superimposed. The final character spacing formula is: S char = β × W font × k + ΔS where W font is the character baseline width, β is the character spacing coefficient (default value 0.1), and ΔS is calculated according to the differential index D: For example, if D = 1.8, then ΔS = 0.5 × 1.8 = 0.9px.
[0056] The line spacing compensation value ΔL is calculated by a quadratic function to avoid over-adjustment: ΔL = 0.1 × D 2 For example, if D = 1.8, then ΔL = 0.1 × 1.8 2 = 0.324px.
[0057] In some embodiments, for complex glyphs (such as ligatures, decorative symbols), the feature analysis module adopts a regional weighting strategy. The character is decomposed into multiple geometric regions (such as the main body part, decorative line), and different weights λ j (∑λ j = 1) are assigned to each region. The final feature vector is calculated as the weighted sum: For example, for the ligature "fi", the weight of the main body part λ1 = 0.8, and the weight of the connecting stroke part λ2 = 0.2.
[0058] In some embodiments, the system monitors the accuracy of feature extraction in real time and triggers exception handling. When the Euclidean distance D of the feature vector exceeds a preset threshold (such as 3.0), it is determined as an abnormal font, and it reverts to the preset font and generates a log: In some embodiments, the feature analysis module supports multi-language font adaptation. For non-Latin character sets (such as Chinese and Japanese), the glyph structure complexity factor C is introduced, and the difference index calculation formula is adjusted to: D adjusted =D×(1+0.1×C); Where C is the number of strokes or components of the character. For example, the Chinese character “国” has C=8, then D adjusted =D×1.8.
[0059] 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, batch size 32) are determined through cross-validation. The training loss function is the mean square error (MSE), and the optimization goal is to minimize the reconstruction error of the feature vector.
[0060] Through the above embodiments, the font feature analysis and difference compensation module realizes high-precision feature extraction, dynamic compensation adjustment and multi-language adaptation capabilities, ensuring that the layout after font switching remains visually consistent, while having strong robustness and scalability.
[0061] In the embodiment of the present invention, multi-dimensional situation modeling and dynamic recommendation serve as the intelligent core of the reading layout optimization process. Its function is to comprehensively analyze the device status, environmental conditions and user behavior data, and generate reading mode parameters adapted to the current situation in real time to ensure that the electronic document can provide the best reading experience in different usage scenarios. This step needs to be linked with the difference index output by the font feature analysis module, and provide dynamic adjustment instructions for the layout update module to achieve closed-loop optimization from data collection to parameter recommendation.
[0062] The situation modeling module builds a comprehensive situation model by fusing multi-source data. 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, gaze area heat map). For example, device status data is obtained in real time through the system API, ambient light intensity is collected through light sensors, and user behavior data is recorded through touch screens or eye trackers.
[0063] In some embodiments, the normalization process 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: For example, when I=50, η=90 / 50-10≈0.444.
[0064] User reading speed V read By turning the page interval time T page calculate: Among them, N words is 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 per second.
[0065] The long short - term memory network (LSTM) is used to model time - series data. The input sequence is X = [x1, x2, …, x T , where x t contains ambient light intensity, reading speed, and device status data. The hidden state h t of the LSTM is updated according to the formula: h t = LSTM(x t , h t-1 ); The output layer predicts the reading - mode parameter p t : P t = W·h t + b; Among them, W is the weight matrix and b is the bias vector.
[0066] F size = F base × 0.5 + 0.5 × η; For example, if the base font size F base = 12pt and the ambient light intensity coefficient η = 0.444, then: F size = 12 × (0.5 + 0.5 × 0.444) ≈ 8.67pt; The background - color switching rule is based on the ambient light intensity and user preferences. When η < 0.5, the dark - mode is enabled, and the background brightness B decays according to the exponential function: B(t)= B0×e -λt ; Among them, B0 is the initial brightness (such as RGB(30, 30, 30)), λ is the decay coefficient (default 0.01), and t is the reading duration (in minutes). For example, when t = 30 minutes, B(30)= 30×e -0.01×30 ≈ 22.2.
[0067] The dynamic adjustment of the line - spacing combines with the change rate of the reading speed ΔV. The line - spacing formula is: L line = L base × (1 + α×ΔV); Among them, L base is the base line - spacing, and α is the adjustment coefficient (default 0.2). For example, if L base= 24px, ΔV = 0.5, then: L line = 24 × (1 + 0.2 × 0.5) = 26.4px; The system optimizes the hyperparameters of the LSTM model through experimental data. Using a training set containing 10,000+ samples, the number of hidden layers (such as 3 layers), learning rate (such as 0.001), and batch size (such as 32) are determined through cross-validation. The training loss function is the mean squared error (MSE), and the optimization goal is to minimize the deviation between the recommended parameters and the user's actual preferences.
[0068] The context modeling module supports multi-device data synchronization. By sharing user preferences and context parameters in real time through the cloud database, it ensures the consistency of the reading experience across different devices. For example, the dark mode parameters set on the tablet are automatically synchronized to the mobile phone, reducing the number of manual adjustments.
[0069] The system monitors context changes in real time and triggers dynamic adjustments. When significant changes occur in the ambient light intensity or reading speed (such as |Δη| > 0.2 or |ΔV| > 0.5), the recommended parameters are immediately updated and the document is re-rendered, with the response latency controlled within 200 milliseconds.
[0070] In the embodiments of the present invention, cross-device adaptation and anti-aliasing processing are key links in the reading layout optimization process. Their function is to ensure that electronic documents can present consistent visual effects on different devices (such as mobile phones, tablets, and computers), and at the same time eliminate the edge jaggedness after font scaling through advanced rendering technology, 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 for the rendering engine to achieve seamless connection from device adaptation to visual optimization.
[0071] Cross-device adaptation is achieved through a responsive layout algorithm. The algorithm dynamically adjusts the number of characters per line N according to the available screen width W available and the character width W char : where W available is the screen width minus the margins (such as 16px on both the left and right), and W char is 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: For high-resolution devices (such as Retina displays), the system uses sub-pixel rendering technology to eliminate font edge jaggedness. Sub-pixel rendering calculates the brightness values of the pixels at the character edges through an interpolation algorithm, and the interpolation kernel function is the Lanczos function: Among them, x is the pixel position offset, and a is the window size (default 3). For example, for the character edge pixel p, its brightness value I p is calculated as: where I p+i is the brightness value of adjacent pixels.
[0072] In some embodiments, the system dynamically adjusts the anti-aliasing strength according to the device DPI. The relationship between the anti-aliasing smoothness σ and the DPI value D is: where σ base is the base smoothness (default 1.0), 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 enhance the smoothness effect.
[0073] The cross-device adaptation module supports dynamic adjustment of multiple screen ratios. For wide-screen devices (such as 16:9), the system increases the paragraph spacing to balance the visual center of gravity; for narrow-screen devices (such as 4:3), the system compresses the character spacing to avoid frequent line breaks. For example, the paragraph spacing adjustment formula is: where W available is the available width, and H available is the available height.
[0074] In some embodiments, the system monitors the device performance in real time and triggers the degraded rendering mode. When the device CPU load exceeds 80% or the memory occupancy exceeds 90%, sub-pixel rendering is turned off and a fast anti-aliasing algorithm (such as bilinear interpolation) is enabled to ensure that the rendering frame rate is not lower than 30fps.
[0075] The cross-device adaptation module is linked with the cloud database to store user preferences and device configurations. For example, the font size and line spacing parameters set by the user on the tablet are automatically synchronized to the mobile phone, reducing the number of manual adjustments. The synchronized data is transmitted through encryption to ensure user privacy and security.
[0076] The system optimizes the interaction experience for touch devices. By detecting the touch screen click coordinates (x, y), the character spacing and line spacing within the click area are dynamically adjusted to improve the operation accuracy. For example, the character spacing within the click area is adjusted to: where d is the distance between the click point and the character center, and r is the character radius.
[0077] The anti-aliasing processing module supports edge optimization of multi-language fonts. For non-Latin character sets (such as Chinese and Japanese), the glyph complexity factor C is introduced and the smoothness formula is adjusted as follows: σ adjusted =σ×(1+0.1×C); Where C is the number of strokes or components of the character. For example, the Chinese character “国” has C=8, then σ adjusted =σ×1.8.
[0078] The system optimizes the parameters of the anti-aliasing algorithm through experimental data. Using a training set containing more than 10,000 font samples, the optimal values of Lanczos window size a and smoothness σ are determined through cross-validation. The training loss function is the visual perceptual error (VPE), and the optimization goal is to minimize the user's subjective score of font edge jaggedness.
[0079] In the embodiment of the present invention, user data storage and model optimization serve as a closed-loop link in 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 the reading habits and needs of different users. 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, so as to achieve a complete closed loop from data collection to model optimization.
[0080] In some embodiments, user behavior data includes font selection records, layout parameter adjustment records, and reading time 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: 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 parameters set by the user on the tablet are automatically synchronized to the mobile phone, reducing the number of manual adjustments.
[0081] The model optimization module iteratively updates the weight parameters of the convolutional neural network (CNN) and the long short-term memory network (LSTM) through the gradient descent algorithm. The loss function Loss comprehensively considers the layout distortion and the frequency of user operation interruption: Among them, SSIM is the structural similarity index (range 0-1), N interrupt The number of times the user manually adjusts the parameters, T total is the total number of operations.
[0082] The structural similarity index SSIM is calculated by comparing the image similarity of the document before and after the adjustment: Among them, μ x and μ y are the means of images x and y, σ x and σ y are variances, σ xy is the covariance, and C1 and C2 are stable constants (by default, C1 = 0.01 and C2 = 0.03).
[0083] The model is trained using the Adam optimizer, and the learning rate η is dynamically adjusted as follows: Among them, η base is the base learning rate (by default, 0.001), and t is the number of training steps. For example, at the 100th step, the learning rate is 0.001 × 1 / 100 = 0.0001.
[0084] The system optimizes the model hyperparameters through experimental data. Using a training set containing 10,000+ samples, the number of hidden layers (such as 3 layers), batch size (such as 32), and regularization coefficient (such as 0.01) are determined through cross-validation. The training loss function is the mean squared error (MSE), and the optimization goal is to minimize the deviation between the recommended parameters and the user's actual preferences.
[0085] User feedback data is collected through A / B testing. The system randomly assigns users to different experimental groups, and each group uses different combinations of recommended parameters (such as font size, line spacing), and records the user satisfaction score S (range 0 - 5). The score data is used to optimize the loss function weight as follows: Loss adjusted = Loss × (1 + 0.1 × (5 - S)); For example, if the user score S = 4, the adjusted loss function is Loss × 1.1.
[0086] In some embodiments, the system monitors the model performance in real time and triggers a retraining mechanism. When the model prediction error E exceeds a preset threshold (such as 0.1), a new round of training process is automatically started. The prediction error is calculated as follows: Among them, P predicted is the model recommended parameter, and P actual is the user's actual selected parameter.
[0087] The model optimization module supports incremental learning. New user data updates the model weights in real time through an online learning algorithm, avoiding the computational overhead of full-scale training. For example, using the Stochastic Gradient Descent (SGD) algorithm, only a single sample is processed for each update: Among them, θ tis a model parameter, η is the learning rate, is the gradient of the loss function.
[0088] The system displays the model optimization process through a visualization tool. The training loss curve, prediction error distribution, and user satisfaction score are presented in the form of charts, facilitating developers to analyze the model performance. For example, the loss curve shows the change in the loss value for each round of training, helping to identify overfitting or underfitting problems.
[0089] In the embodiments of the present invention, exception handling and logging are used as safeguard mechanisms for the reading layout optimization process. Its function is to monitor the system operation status in real time, capture and handle various exception events, and record detailed logs for subsequent analysis and optimization. This step needs to be linked with modules such as font loading, layout update, and model optimization to ensure that the system can still provide stable services in case of exceptions and provide data support for developers to troubleshoot problems and optimize performance.
[0090] The anomaly detection module monitors the system status in real time through multi-dimensional metrics. The metrics include CPU usage U CPU , memory occupancy U memU , network latency L net , and rendering frame rate F render . When any metric exceeds the preset threshold, the anomaly state machine is triggered. For example, if U CPU > 80% or F render < 30fps, it is determined as a performance anomaly.
[0091] The exception handling strategy is dynamically adjusted according to the exception type. For the font loading failure exception, the system attempts to reload from the backup font library; for the layout overflow exception, the system automatically compresses the character spacing or triggers forced line breaks. For example, when the total width W total of the in-line characters exceeds the available line width W available , the character spacing S char is adjusted as: where S base is the base character spacing, W available is the available screen width minus the margins (such as 16px on each side), and W total is the sum of the widths of all characters in the current line. For example, if S base = 1.8px, W available = 360px, and W total = 400px, the adjusted character spacing is: The logging module stores exception events and operation records in a structured format. Log entries include timestamps, event types, error codes, device information, and context data.
[0092] In some embodiments, the system detects the suddenness of abnormal events through a sliding window algorithm. The window size WW is the most recent NN log records, and the abnormal frequency F anomaly is calculated as: where N error is the number of error logs in the window, and N is the window size (default 100). If F anomaly > 0.1, the system alarm is triggered and a diagnostic report is generated. For example, if there are 15 error logs among the most recent 100 logs, then F anomaly = 15 / 100 = 0.15, and the alarm is triggered.
[0093] The exception handling module supports a multi-level recovery mechanism. For recoverable exceptions (such as network timeouts), the system automatically retries the operation, and the retry count R increases according to the exponential backoff strategy: R = R base × 2 k ; where R base is the base retry interval (such as 1 second), and k is the retry count. For example, the third retry interval is 1 × 2^3 = 8 seconds. If the retry count exceeds the maximum limit (such as 5 times), it is determined as an unrecoverable exception and a rollback operation is triggered.
[0094] The log data is transmitted and stored in the cloud database through encryption to ensure data security and privacy protection. The encryption algorithm uses AES-256, and the key is dynamically generated by the Hardware Security Module (HSM). For example, the encrypted log entry is stored as: C = AES256_Encrypt(P, K, IV); where P is the plaintext log, K is the symmetric key, and IV is the initialization vector. When decrypting, the same key and initialization vector are used to restore the plaintext: P = AES256_Decrypt(C, K, IV); The system displays the log data and exception trends through a visualization tool. The log analysis dashboard shows the error type distribution, the change in abnormal frequency, and the device performance metrics, which is convenient for developers to quickly locate problems. For example, the dashboard can highlight the high-frequency error types (such as font loading failure) and related context information.
[0095] The exception handling module is linked 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 the submission of a feedback report. The feedback data is used to optimize the exception handling strategy and model parameters. For example, the problem of "slow font loading" feedback by the user can trigger the priority adjustment of the network optimization module.
[0096] The system optimizes the parameters of the anomaly detection algorithm through experimental data. Using a training set containing 10,000+ anomaly samples, the sliding window size W and the anomaly frequency threshold F are determined through cross-validation. threshold The training loss function is the weighted sum of the false positive rate (FPR) and the false negative rate (FNR): Loss = 0.7×FPR + 0.3×FNR; Among them, FPR is the false positive rate (the proportion of normal events misjudged as anomalies), and FNR is the false negative rate (the proportion of anomaly events not detected). The optimization goal is to minimize the overall detection error.
[0097] The system supports real-time streaming processing of log data. Log entries are collected through a distributed message queue (such as Kafka), and the anomaly frequency is calculated in real-time to trigger an alarm. For example, when a certain type of anomaly event occurs more than 10 times within 1 minute, an alarm notification is immediately pushed to the operations and maintenance team.
[0098] The logging module supports multiple log levels (such as DEBUG, INFO, WARN, ERROR). Logs at different levels are stored in different database tables for easy query and analysis as needed. For example, DEBUG-level logs are only used for development and debugging, and ERROR-level logs are used for troubleshooting.
[0099] Through the above embodiments, the anomaly handling and logging module realizes high-precision anomaly detection, an intelligent recovery mechanism, and secure data storage, ensuring the stability and maintainability of the system in complex scenarios, and at the same time providing reliable data support for performance optimization.
[0100] Although the embodiments of the present invention have been shown and described, for those of ordinary skill in the art, it can be understood that various changes, modifications, substitutions, and variations can be made to these embodiments without departing from the principles and spirit of the present invention. The scope of the present invention is defined by the appended claims and their equivalents.
Claims
1. A method for optimizing a reading layout, characterized in that, It includes the following steps: Step 1: Receive the font switching instruction input by the user, and parse the instruction to determine the target font and its style attributes; Step 2: Load the corresponding font file according to the target font to complete the font replacement of the electronic document; Step 3: Calculate the scale factor based on the typographic ratio values of the preset font and the target font, and adjust the typographic ratio of the target font. The typographic ratio is the ratio of the actual display area of the font to the designed area; Step 4: Update the layout parameters of the electronic document according to the adjusted typographic ratio, including line spacing, character spacing, and paragraph spacing; Step 5: Present the adjusted electronic document to the user and save the user settings for subsequent restoration; 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; 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.
2. The reading layout optimization method according to claim 1, wherein The scale factor is determined by the ratio of the typographic ratio value of the target font to the typographic ratio value of the preset font, and the value range of the scale factor is 0.8 to 1.5, which is determined based on user comfort test data.
3. The reading layout optimization method according to claim 1, wherein The update of the layout parameters includes: the line spacing is 1.2 to 1.8 times the font height; The character 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 according to claim 1, wherein The font feature analysis module includes: Extract the stroke thickness, slant angle, and glyph structure features of the target font image through a convolutional neural network. The input of the convolutional neural network is the grayscale font image, and the grayscale processing uses the weighted average method. The calculation formula is: Gray value = 0.299R + 0.587G + 0.114B; where R, G, and B are the pixel values of the red, green, and blue channels of the font image respectively; Analyze the semantic features of the target font through natural language processing technology to generate a semantic vector containing emotional tendency and applicable scenarios; fuse the image feature vector and the semantic vector into a comprehensive feature vector, and calculate the Euclidean distance based on the comprehensive feature vector and the feature vector of the reference font to generate a difference index.
5. The reading layout optimization method according to claim 1, wherein The construction of the multi-dimensional context model includes: real-time collecting device status data, including screen size, resolution, DPI; Real-time collecting ambient light intensity data and converting it into a percentage coefficient of the standard light value; Perform time series modeling on the user's reading speed and page turning frequency through a long short-term memory network. The hidden layer of the long short-term memory network is 3 layers, the activation function is ReLU, and the loss function is the mean square error; Output dynamic reading mode parameters, including adjustment rules for font size, background color, and line spacing.
6. The reading layout optimization method according to claim 5, wherein The adjustment rules of the dynamic reading mode parameters include: Font size = basic font size × ambient light intensity coefficient; where the ambient light intensity coefficient is the ratio of the ambient light intensity to 100 lux. The background color automatically switches to the dark mode or the light mode according to the ambient light intensity, and the background brightness value in the dark mode decays exponentially with the user's reading duration.
7. The reading layout optimization method according to claim 1, characterized in that Step 7 specifically includes: Real-time calculate the ratio of the available screen width to the character width through the responsive layout algorithm. When the ratio is lower than the preset threshold, automatically reduce the number of characters per line and trigger a paragraph rearrangement; For high-resolution screens, use sub-pixel rendering technology to perform anti-aliasing processing on the adjusted font, and the anti-aliasing algorithm is the Lanczos interpolation method.
8. The reading layout optimization method according to claim 1, characterized in that, The saving and optimization of the user settings include: Store the user's historical font selections, layout parameter adjustment records, and comfort scores in a relational database; Iteratively update the weight parameters of the convolutional neural network and the long short-term memory network model through the gradient descent algorithm. The optimization objective function is the total loss, and the total loss quantifies the layout distortion degree through the structural similarity index and is calculated in combination with the user operation interruption frequency.
9. The reading layout optimization method according to claim 1, wherein The adjustment of the literal rate needs to meet the following accuracy requirements: The absolute value of the proportional error between the adjusted character width and the preset font character width does not exceed 3%; The absolute value of the proportional error between the adjusted character height and the preset font character height does not exceed 2%; When three consecutive adjustments cannot meet the accuracy requirements, trigger an exception handling process, roll back to the preset font, and generate a system log warning.
10. The reading layout optimization method according to claim 4, wherein The compensatory adjustment of the difference index includes: When the difference index exceeds the preset threshold, the adjustment amplitude of the character spacing is a linear function of the difference index; The adjustment amplitude of the line spacing is a quadratic function of the difference index.
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
Internet automatic identification method and system for special fonts
CN116403225A
Calligraphy scoring method with both form and spirit
CN117690151A
Method and system for identifying handwritten fonts based on AI technology
CN118314588A