A method for implementing text layout
Patent Information
- Application Number
- CN202311171172.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-09-12
- Publication Date
- 2026-08-18
- Estimated Expiration
- 2043-09-12
AI Technical Summary
[0003]不同的文字处理软件,在处理行高时各有各的方法,如word中可以直接设置行高值,不过,在针对不同类型文字进行布局并正确绘制,以达到期望的效果方面,还存在不足,单一的处理行高方法也会出现与实际行高存在较大误差的问题
[0042] Based on the layout height coefficient and font metric of different fonts, this invention obtains the font layout height and font layout baseline, then obtains the layout height and layout baseline of the leaf view, and then obtains the layout height and layout baseline of the row view, so as to accurately set the layout and determine the drawing position of each character.
Smart Images

Figure CN117217166B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of font processing, and more specifically to a method for implementing text layout. Background Technology
[0002] Word processing software, such as Word, Notepad, and WordPad, is commonly used in daily office work. When processing text, whether it's layout or drawing, the line height must be known for correct processing.
[0003] Different word processing software have their own methods for handling line height. For example, Word allows you to directly set the line height value. However, it is still insufficient in terms of laying out and drawing correctly for different types of text to achieve the desired effect. A single method of handling line height can also result in a large error between the actual line height and the actual line height. Summary of the Invention
[0004] This invention provides a method for implementing text layout.
[0005] The technical solution of the present invention is as follows:
[0006] A method for implementing text layout includes laying out text and drawing text based on the text layout, wherein the text layout includes the following steps:
[0007] Based on the layout height coefficient and font metric of different fonts, after obtaining the font layout height and font layout baseline, the layout height and layout baseline of the leaf view are then obtained.
[0008] Based on the layout height and layout baseline of the leaf view, obtain the layout height and layout baseline of the down-view for both the gridless and gridded scenarios.
[0009] Adjust the slot information based on the layout height and layout baseline of the downview when there is a grid.
[0010] The text drawing includes the following steps:
[0011] Based on the layout height of the row view, obtain the drawing height of the row view. Based on the drawing height of the row view and the starting Y coordinate of the segment view, obtain the starting Y coordinate of the row view. Based on the starting Y coordinate of the row view, the drawing height, and the slot information, obtain the starting Y coordinate of the leaf view, the drawing height, and the drawing baseline.
[0012] The method for obtaining the layout height of a leaf view as described in this invention specifically includes the following steps:
[0013] For text-based leaf views, the font height is obtained based on the layout height coefficient of the current font, according to the formula: font height = font upslope + font downslope + font line spacing.
[0014] The font layout height is calculated as: font layout height = font height * font layout height coefficient.
[0015] The leaf view layout height is obtained by calculating the leaf view layout height as equal to the font layout height.
[0016] The method for implementing text layout according to the present invention includes the following steps for obtaining the layout baseline of the leaf view:
[0017] For text-based leaf views, the font layout baseline is obtained based on the formula: font layout baseline = font layout height – font height + font slope.
[0018] The leaf view layout baseline is obtained by assuming that the leaf view layout baseline equals the font layout baseline.
[0019] In the gridless scenario described in this invention, determining the layout height and layout baseline of a row view specifically includes the following steps:
[0020] Obtain the layout height and layout baseline of the leaf view to be processed. If the layout height of the row view is less than the layout height of the leaf view, then determine the layout height of the row view as the layout height of the leaf view.
[0021] If the row view layout baseline is less than the leaf view layout baseline, then the row view layout baseline is determined to be the leaf view layout baseline.
[0022] In the case of a grid, the present invention determines the layout height and layout baseline of the row view and adjusts the slot information, specifically including the following steps:
[0023] In the case of a grid, obtain the height of a single grid cell to get the number of grid cells occupied by the row view layout height, and then obtain the occupied grid height according to the formula: occupied grid height = single grid cell height * number of grid cells occupied by the row view layout height.
[0024] The total height of a slot is calculated as follows: Total slot height = Occupied grid height - Layout height of row view. The height of slots in the upper row view and slots in the lower row view are both half of the total slot height.
[0025] The present invention describes obtaining the number of grid cells occupied by the row view layout height, specifically including the following steps: after obtaining the row spacing setting value, the row view layout height is compared with the height of a single grid cell, and the result is rounded down to obtain the number of grid cells occupied by the row view layout height.
[0026] Take the larger value between the line spacing setting and the number of grid cells occupied by the line view layout height, and redetermine the number of grid cells occupied by the line view layout height.
[0027] The method for obtaining the starting Y-coordinate for drawing a row view as described in this invention specifically includes the following steps:
[0028] The paragraph drawing height is calculated as follows: Paragraph drawing height = (paragraph's floating-point starting Y-coordinate + paragraph's floating-point height) - (paragraph's floating-point starting Y-coordinate, rounded to the nearest integer) = Paragraph drawing height.
[0029] The starting Y-coordinate for drawing the row view is obtained by rounding it to the nearest whole number. Then, the row view to be processed is acquired. After obtaining the drawing height of the row view, the starting Y-coordinate of the row view is used as the starting Y-coordinate of the drawn row view, and the drawing height of the row view is used as the height of the drawn row view. The current row view is then drawn.
[0030] After the current row view is drawn, the updated starting Y coordinate of the row view is obtained based on the sum of the starting Y coordinate of the drawn current row view and the height of the drawn current row view.
[0031] The method for obtaining the drawing height of a row view as described in this invention specifically includes the following steps:
[0032] The total height of the row view can be calculated as follows: (Row view layout height + Row view top slot height + Row view bottom slot height).
[0033] The updated drawn floating-point height is obtained by calculating the updated drawn floating-point height as the sum of the drawn floating-point height and the total height of the row view.
[0034] If the current process is the last row view, the multi-line height of the row view is the paragraph drawing height. If the current process is not the last row view, the multi-line height of the row view is the rounded and updated drawn floating-point height.
[0035] The updated drawing height of the row view is obtained by calculating the updated drawing height as follows: = row view multi-row height - updated drawn integer height.
[0036] The method for obtaining the starting Y-coordinate and drawing height of the leaf view as described in this invention includes the following steps: obtaining the starting Y-coordinate of the leaf view drawing based on the formula: starting Y-coordinate of the leaf view drawing = starting Y-coordinate of the row view drawing + rounded up to the height of the slot on the row view.
[0037] The leaf view drawing height 1 is calculated by rounding the leaf view layout height to the nearest integer. The leaf view drawing height 2 is calculated by rounding the row view drawing height to the nearest integer (upper row view slot height minus the lower row view slot height).
[0038] Take the larger of the leaf view drawing height 1 and leaf view drawing height 2 as the leaf view drawing height.
[0039] The method for obtaining the baseline for drawing a leaf view as described in this invention specifically includes the following steps:
[0040] The drawing baseline of the leaf view is obtained by calculating the starting Y coordinate of the leaf view drawing plus the drawing height of the leaf view minus the drawing baseline of the rounded row view. The text is then drawn using the drawing baseline of the leaf view as the starting Y coordinate.
[0041] Beneficial effects
[0042] Based on the layout height coefficient and font metric of different fonts, this invention obtains the font layout height and font layout baseline, then obtains the layout height and layout baseline of the leaf view, and then obtains the layout height and layout baseline of the row view, so as to accurately set the layout and determine the drawing position of each character.
[0043] This invention obtains the drawing height of the row view based on the row view layout height, obtains the drawing start Y coordinate of the row view based on the drawing height of the row view and the segment view drawing start Y coordinate, obtains the drawing start Y coordinate of the row view based on the drawing start Y coordinate, drawing height and slot information of the row view, and obtains the drawing start Y coordinate, drawing height and drawing baseline of the leaf view, thereby correctly drawing text and achieving an aesthetic effect.
[0044] When obtaining the drawing height of a row view, this invention uses floating-point numbers to obtain the full height of the row view and integers to obtain the height of multiple rows of the row view. This avoids the consequence of using integers for calculations during text drawing, which would lead to increasingly larger errors. Attached Figure Description
[0045] Figure 1 This is a simplified flowchart illustrating the process of obtaining the layout height of the leaf view according to the present invention.
[0046] Figure 2 This is a simplified flowchart illustrating the process of determining the layout height and layout baseline of a row view in the absence of a grid.
[0047] Figure 3 A simplified flowchart illustrating the process of adjusting slots in a grid-based row view.
[0048] Figure 4 This is a simplified flowchart illustrating the drawing of the Y-coordinate and height for a row view.
[0049] Figure 5 A simplified flowchart for obtaining the drawing height of a row view. Detailed Implementation
[0050] The following examples are intended to illustrate the present invention, and not to further limit the invention.
[0051] For the sake of accuracy and convenience, the following conventions and explanations apply:
[0052] 1. This patent relates to an algorithm and implementation method for processing row height. Irrelevant content will not be described.
[0053] 2. Font baseline: The font is divided by the baseline. Leading and ascent are located above the font baseline, while descent is located below the font baseline.
[0054] 3. Font height: Composed of leading, ascent, and descent. Ascent represents the font's upward slope, which is the distance from the font baseline to the highest point of the font; descent represents the font's downward slope, which is the recommended distance from the font baseline to the lowest point of the font; leading represents the font's line spacing, which is the distance between the descent of the previous line and the ascent of the next line. The font's line spacing here is different from the spacing between lines in the paragraph attribute.
[0055] 4. Description of combined elements in data items. Within a single data item, there can only be one element of a particular type.
[0056] a) y represents the vertical coordinate; height represents the height.
[0057] b) int represents an integer; float represents a floating-point number.
[0058] c) font indicates font-related, layout indicates layout-related, view indicates view-related, paint indicates drawing-related, and full / total indicates total.
[0059] d) Para represents a paragraph, line represents a line, and leaf represents a leaf.
[0060] 5. Align with grid: A feature in word processing. It allows you to set the number of grid lines on a page, with each line of text occupying one or more grid lines.
[0061] 6. Font Metric: The width and height information of each font instance (font name + font size) is different, so each font instance will correspond to a font metric to record the width and height information of the font instance.
[0062] For convenience, each text-based leaf view comes with a font metric.
[0063] 7. Paragraph View: A paragraph in the article corresponds to one or more paragraph views.
[0064] 8. Line view: One line view corresponds to one line of text.
[0065] 9. Leaf View: View elements with the same attribute, specifically, a collection of characters with the same font and size attributes in the same row. For example, if a row's view content is "View elements with the same attribute", there are three leaf views: "Same", "Attribute", and "View Element".
[0066] 10. Slot: If a subview cannot fill its parent view, there will be blank space. This blank space is what the child view refers to.
[0067] The slots are referred to as slots. To center the view, they are divided into upper slots, lower slots, left slots, and right slots. The technical solutions provided by the embodiments of the present invention are described below with reference to the accompanying drawings.
[0068] This invention provides a method for implementing font layout, including text layout and text drawing based on the text layout, wherein the text layout includes the following steps:
[0069] Set layout height coefficients for different fonts. Based on these coefficients and the font metric, obtain the font layout height and baseline. Then, obtain the layout height and baseline of the leaf view. Finally, based on the layout height and baseline of the leaf view, obtain the layout height and baseline of the downview for both grid-free and grid-enabled scenarios.
[0070] Adjust the slot information based on the layout height and layout baseline of the downview when there is a grid.
[0071] When laying out fonts, the font height used differs from the font's intrinsic height (i.e., font height) due to differences in font size. To facilitate layout settings, a font layout height coefficient needs to be set for different fonts to ensure consistent font layout heights for the same font. If the font being processed has not had its font layout height coefficient set, the default value is used.
[0072] To ensure accurate layout settings, a font metric was used when obtaining the layout height of the leaf view, specifically:
[0073] For text-based leaf views, the font height is obtained based on the layout height coefficient of the current font, according to the formula: font height = font upslope + font downslope + font line spacing.
[0074] The font layout height is calculated as: font layout height = font height * font layout height coefficient.
[0075] The leaf view layout height is obtained by calculating the leaf view layout height as equal to the font layout height.
[0076] If it is not a text-based leaf view, but rather an image, then the leaf view layout height is the height of the image content.
[0077] like Figure 1 As shown, the simplified process for obtaining the layout height of the leaf view is as follows:
[0078] Step 1: Begin.
[0079] Step 2: Obtain the layout height coefficient setting list.
[0080] Step 3: Obtain the font name corresponding to the font metric of this view.
[0081] Step 4: Determine if the list contains the current font name. If yes, proceed to step 5; otherwise, proceed to step 6.
[0082] Step 5: Set the font layout height factor (floatLayoutHeightFactor) to the value corresponding to the font name in the list. Proceed to Step 7.
[0083] Step 6: Set the font layout height factor floatLayoutHeightFactor to the default value.
[0084] Step 7: Calculate the font height (floatFontHeight) using a font metric. The formula is: Font Height (floatFontHeight) = Font Ascent + Font Descent + Font Leading.
[0085] Step 8: Calculate the font layout height (floatLayoutFontHeight) using the font metric. Calculation formula:
[0086] Font layout height floatLayoutFontHeight = Font height floatFontHeight * Font layout height factor floatLayoutHeightFactor.
[0087] Step 9: Calculate the leaf view layout height (floatLayoutLeafHeight). Calculation formula: Leaf view layout height (floatLayoutLeafHeight) = Font layout height (floatLayoutFontHeight).
[0088] Step 10: End.
[0089] Similarly, when obtaining the layout baseline of the leaf view, the font metric was also used. For text-type leaf views, the font layout baseline was obtained according to the formula: font layout baseline = font layout height – font height + font downslope.
[0090] The leaf view layout baseline is obtained by assuming that the leaf view layout baseline equals the font layout baseline.
[0091] After setting the layout for the leaf view, set the layout for the row view based on the leaf view's layout height and baseline. The row view's layout height and baseline need to take into account both grid-free and grid-enabled scenarios.
[0092] In the case of no grid, determining the layout height and layout baseline of the row view specifically includes the following steps:
[0093] Obtain the layout height and layout baseline of the leaf view to be processed. If the layout height of the row view is less than the layout height of the leaf view, then determine the layout height of the row view as the layout height of the leaf view.
[0094] If the row view layout baseline is less than the leaf view layout baseline, then the row view layout baseline is determined to be the leaf view layout baseline.
[0095] like Figure 2 As shown, in the case of no grid, the simplified process for determining the layout height and layout baseline of the row view is as follows:
[0096] Step 1: Begin.
[0097] Step 2: Set the ratio of row view layout height to layout baseline (floatLayoutLineHeight / floatLayoutLineBaseline) to 0.
[0098] Step 3: Determine if there are any unprocessed leaf views. If yes, proceed to step 4; otherwise, proceed to step 10.
[0099] Step 4: Obtain a leaf view.
[0100] Step 5: Obtain the layout height of the leaf view (floatLayoutLeafHeight) and the layout baseline of the leaf view (floatLayoutLeafBaseline).
[0101] Step 6: Determine if the row view layout height (floatLayoutLineHeight) is less than the leaf view layout height (floatLayoutLeafHeight). If yes, proceed to step 7; otherwise, proceed to step 8.
[0102] Step 7: Set the row view layout height (floatLayoutLineHeight) to the leaf view layout height (floatLayoutLeafHeight).
[0103] Step 8: Determine if the row view layout baseline (floatLayoutLineBaseline) is smaller than the leaf view layout baseline (floatLayoutLeafBaseline). If yes, proceed to step 9; otherwise, proceed to step 3.
[0104] Step 9: Set the value of the row view layout baseline floatLayoutLineBaseline to the leaf view layout baseline floatLayoutLeafBaseline. Proceed to Step 3.
[0105] Step 10: End.
[0106] In the case of a grid, the layout height and layout baseline of the row view are determined. To ensure the correct layout position, the slot information also needs to be adjusted, which includes the following steps:
[0107] In the case of a grid, obtain the height of a single grid cell to get the number of grid cells occupied by the row view layout height, and then obtain the occupied grid height according to the formula: occupied grid height = single grid cell height * number of grid cells occupied by the row view layout height.
[0108] The total height of a slot is calculated as follows: Total slot height = Occupied grid height - Layout height of row view. The height of slots in the upper row view and slots in the lower row view are both half of the total slot height.
[0109] like Figure 3 As shown, the simplified process for adjusting slots in a grid-based configuration is as follows:
[0110] Step 1: Begin.
[0111] Step 2: Obtain the height of a single grid unit (floatGridUnitHeight).
[0112] Step 3: Calculate the number of grid cells occupied by the row view layout height (intGridCount).
[0113] Step 4: Calculate the occupied grid height (floatGridHeight). Calculation formula: Occupied grid height (floatGridHeight) = Single grid height (floatGridUnitHeight) * Number of grids occupied by the row view layout (intGridCount).
[0114] Step 5: Calculate the total height of the slot using `floatLayoutLineInsetFullHeight`. Calculation formula: Total slot height `floatLayoutLineInsetFullHeight` = Occupied grid height `floatGridHeight` –
[0115] The layout height of the row view is floatLayoutLineHeight.
[0116] Step 6: Calculate the height of the upper slot using floatLayoutLineInsetTop. Calculation formula: Upper slot height floatLayoutLineInsetTop = (Total slot height floatLayoutLineInsetFullHeight / 2).
[0117] Step 7: Calculate the lower slot height floatLayoutLineInsetBottom. Calculation formula: Lower slot height floatLayoutLineInsetBottom = (Total slot height floatLayoutLineInsetFullHeight / 2).
[0118] Step 8: End.
[0119] In the process of calculating the slot information described above, obtaining the number of grid cells occupied by the row view layout height specifically includes the following steps:
[0120] After obtaining the line spacing setting value, the height of the row view layout is compared with the height of a single grid cell, and then rounded down to obtain the number of grid cells occupied by the row view layout height.
[0121] Take the larger value between the line spacing setting and the number of grid cells occupied by the line view layout height, and redetermine the number of grid cells occupied by the line view layout height.
[0122] The specific process is as follows:
[0123] Step 1: Begin.
[0124] Step 2: Obtain the line spacing setting value floatLineTimes.
[0125] Step 3: Calculate the number of grid cells occupied by the layout height (intGridCount). Calculation formula: (Layout line height of row view (floatLayoutLineHeight) / Individual grid height (floatGridUnitHeight)).
[0126] Step 4: Calculate the number of grid cells occupied (intGridCount). Calculation formula: Maximum value (line spacing setting value floatLineTimes, number of grid cells occupied by layout height intGridCount).
[0127] Step 5, End.
[0128] This invention provides a method for implementing text layout, which, after accurately setting the text layout, also includes text drawing. The text drawing includes the following steps:
[0129] Based on the layout height of the row view, obtain the drawing height of the row view. Based on the drawing height of the row view and the starting Y-coordinate of the segment view, obtain the starting Y-coordinate of the row view. Based on the starting Y-coordinate, drawing height, and slot information of the row view, obtain the starting Y-coordinate, drawing height, and drawing baseline of the leaf view. For a line of text with different font sizes, the font can be top-aligned, center-aligned, bottom-aligned, or baseline-aligned during drawing (e.g., baseline alignment in Office). The starting Y-coordinate of the leaf view drawing will differ depending on the alignment method. Based on the Y-coordinate of the leaf view's drawing position, determine the starting position of the text drawing in the vertical direction; based on the sum of the drawing heights of multiple drawn row views, update the starting Y-coordinate of the row view to be drawn.
[0130] In the process of text drawing, the method of uniformly using integers for calculations during text drawing was changed to avoid the error from getting bigger and bigger.
[0131] The process of obtaining the starting Y-coordinate and drawing height of the line view involves first calculating the paragraph drawing height, and then, within the paragraph, calculating the height line by line relative to the starting Y-coordinate of the paragraph view, starting from 0. Specifically, this includes the following steps:
[0132] The paragraph drawing height is calculated as follows: Paragraph drawing height = (paragraph's floating-point starting Y-coordinate + paragraph's floating-point height) - (paragraph's floating-point starting Y-coordinate, rounded to the nearest integer) = Paragraph drawing height.
[0133] The starting Y-coordinate for drawing the row view is obtained by rounding the Y-coordinate to the nearest integer for the entire view segment.
[0134] Obtain the row view to be processed. After obtaining the drawing height of the row view, use the starting Y coordinate of the row view as the starting Y coordinate of the drawn row view, and use the drawing height of the row view as the height of the drawn row view to draw the current row view.
[0135] After the current row view is drawn, the updated starting Y coordinate of the row view is obtained based on the sum of the starting Y coordinate of the drawn current row view and the height of the drawn current row view.
[0136] At this point, the drawn integer height of the row view is obtained by summing the updated drawn integer height with the height of the drawn row view.
[0137] Continue to obtain the row view to be processed, draw the starting Y coordinate and the drawn integer height of the row view based on the updated row view, calculate the starting Y coordinate and drawing height of the row view to be processed, and draw the row view to be processed.
[0138] like Figure 4 As shown, the process of obtaining the starting Y-coordinate and drawing height of the row view is briefly as follows:
[0139] Step 1: Begin.
[0140] Step 2: Calculate the paragraph drawing height intPaintParaHeight. Calculation formula: Paragraph drawing height intPaintParaHeight = (paragraph's floating-point starting Y-coordinate floatParaY + paragraph's floating-point height floatParaHeight) – (paragraph's floating-point starting Y-coordinate floatParaY).
[0141] Step 3: Set the ratio of drawn floating-point height to drawn integer height (floatHeightPainted / intHeightPainted) to 0.
[0142] Step 4: Calculate the starting Y-coordinate for drawing the row view, intYPainted. Calculation formula: intYPainted =
[0143] Rounding (starting Y coordinate for segment view drawing).
[0144] Step 5: Determine if there are any unprocessed row views. If yes, proceed to step 6; otherwise, proceed to step 11.
[0145] Step 6: Obtain a row view.
[0146] Step 7: Calculate the drawing height of the line view, intPaintLineHeight.
[0147] Step 8: Draw the current row view, where the starting Y coordinate of the current row view is intYPainted and the height of the current row view is intPaintLineHeight.
[0148] Step 9: Calculate the starting Y-coordinate for drawing the updated row view, intYPainted. Calculation formula:
[0149] intYPainted = the starting Y coordinate of the current line view being drawn intLineYPainted + the height of the current line view being drawn intPaintLineHeight.
[0150] Step 10: Calculate the drawn integer height (intHeightPainted) of the row view. The calculation formula is:
[0151] intHeightPainted = Updated drawn integer height + Height of the drawn row view intPaintLineHeight. Go to step 5.
[0152] Step 11, End.
[0153] Calculating the drawing height of the row view to be processed, as obtained above, requires considering the full height and multi-row height of the row view. The full height of the row view is calculated based on the row view layout height and row view slot information, specifically:
[0154] The total height of the row view is calculated as follows: Total height = Row view layout height + Row view top slot height + Row view bottom slot height. The updated drawn floating-point height is then calculated as follows: Updated drawn floating-point height = Drawn floating-point height + Row view total height.
[0155] If the current process is the last row view, the multi-line height of the row view is the paragraph drawing height. If the current process is not the last row view, the multi-line height of the row view is the rounded and updated drawn floating-point height.
[0156] The updated drawing height of the row view is obtained by calculating the updated drawing height as follows: = row view multi-row height - updated drawn integer height.
[0157] like Figure 5 As shown, the process of obtaining the drawing height of the row view is briefly as follows:
[0158] Step 1: Begin.
[0159] Step 2: Calculate the full height of the row view, floatFullLineHeight. Calculation formula: Full height of the row view, floatFullLineHeight = Row view layout height, floatLayoutLineHeight + Row view top slot height, floatLayoutLineInsetTop + Row view bottom slot height, floatLayoutLineInsetBottom.
[0160] Step 3: Calculate the updated drawn floating-point height (floatHeightPainted). Calculation formula:
[0161] floatHeightPainted = drawn floating-point height floatHeightPainted + full height of the row view floatFullLineHeight.
[0162] Step 4: Determine if the row view is the last one. If yes, proceed to step 5; otherwise, proceed to step 6.
[0163] Step 5: Calculate the multi-line height of the line view, intPaintLinesHeight. Calculation formula: Multi-line height of the line view, intPaintLinesHeight = Paragraph drawing height, intPaintParaHeight. Proceed to Step 7.
[0164] Step 6: Calculate the multi-line height of the row view, intPaintLinesHeight. Calculation formula:
[0165] intPaintLinesHeight = Rounding (floatHeightPainted).
[0166] Step 7: Calculate the updated line view's drawing height (intPaintLineHeight). Calculation formula:
[0167] intPaintLineHeight = Multiline height of the row view; intPaintLinesHeight – Updated drawn integer height; intHeightPainted.
[0168] Step 8: End.
[0169] In the segment view, after calculating the starting Y-coordinate and drawing height of the row view, and based on this, combined with the row view slot information, the starting Y-coordinate and drawing height of the leaf view are obtained, the row view background is drawn, and then the leaf view is drawn. Specifically:
[0170] The starting Y-coordinate for drawing the leaf view is obtained by calculating the starting Y-coordinate for drawing the row view plus the rounded height of the slot on the row view.
[0171] The leaf view drawing height 1 is calculated by rounding the leaf view layout height to the nearest integer. The leaf view drawing height 2 is calculated by rounding the row view drawing height to the nearest integer (upper row view slot height minus the lower row view slot height).
[0172] Take the larger of the leaf view drawing height 1 and leaf view drawing height 2 as the leaf view drawing height.
[0173] Draw the row view background using the starting Y coordinate as the background and the height as the background.
[0174] To draw text correctly, in addition to obtaining the starting Y-coordinate and drawing height of the leaf view, it is also necessary to obtain the drawing baseline of the leaf view, specifically including:
[0175] The drawing baseline of the leaf view is obtained by calculating the starting Y coordinate of the leaf view drawing plus the drawing height of the leaf view minus the drawing baseline of the rounded row view. The text is then drawn using the drawing baseline of the leaf view as the starting Y coordinate.
[0176] The simplified process is as follows:
[0177] Step 1: Begin.
[0178] Step 2: Calculate the paintleaf baseline (intPaintLeafBaseline). Calculation formula: Paintleaf baseline.
[0179] Baseline intPaintLeafBaseline = Starting Y coordinate of leaf view drawing intPaintLeafY + Leaf view drawing height intPaintLeafHeight - Drawing baseline of the row view, rounded to the nearest integer.
[0180] Step 3: Draw the text. The starting Y-coordinate for text drawing is intPaintLeafBaseline.
[0181] Step 4, End.
Claims
1. A method for implementing text layout, characterized in that, This includes text layout and text drawing based on the text layout, wherein the text layout includes the following steps: Based on the layout height coefficient and font metric of different fonts, after obtaining the font layout height and font layout baseline, the layout height and layout baseline of the leaf view are then obtained. Based on the layout height and layout baseline of the leaf view, obtain the layout height and layout baseline of the down-view for both the gridless and gridded scenarios. Adjust the slot information based on the layout height and layout baseline of the downview when there is a grid. The text drawing includes the following steps: Based on the layout height of the row view, obtain the drawing height of the row view. Based on the drawing height of the row view and the starting Y coordinate of the segment view, obtain the starting Y coordinate of the row view. Based on the starting Y coordinate of the row view, the drawing height, and the slot information, obtain the starting Y coordinate of the leaf view, the drawing height, and the drawing baseline. Obtaining the starting Y-coordinate for drawing the row view specifically includes the following steps: The paragraph drawing height is calculated as follows: Paragraph drawing height = (paragraph's floating-point starting Y-coordinate + paragraph's floating-point height) - (paragraph's floating-point starting Y-coordinate, rounded to the nearest integer) = Paragraph drawing height. The starting Y-coordinate for drawing the row view is obtained by rounding the Y-coordinate to the nearest integer for the entire row view. Obtain the row view to be processed. After obtaining the drawing height of the row view, use the starting Y coordinate of the row view as the starting Y coordinate of the drawn row view, and use the drawing height of the row view as the height of the drawn row view to draw the current row view. After the current row view is drawn, the updated starting Y coordinate of the row view is obtained based on the sum of the starting Y coordinate of the drawn current row view and the height of the drawn current row view; Obtaining the drawing height of the row view specifically includes the following steps: The total height of the row view can be calculated as follows: (Row view layout height + Row view top slot height + Row view bottom slot height). The updated drawn floating-point height is obtained by calculating the updated drawn floating-point height as the sum of the drawn floating-point height and the total height of the row view. If the current processing is the last row view, then the multi-line height of the row view is the paragraph drawing height. If the current processing is not the last row view, then the multi-row height of the row view is the rounded and updated drawn floating-point height. The updated drawing height of the row view is obtained by calculating the updated drawing height as follows: = row view multi-row height - updated drawn integer height.
2. The method for implementing text layout according to claim 1, characterized in that, Obtaining the layout height of the leaf view specifically includes the following steps: For text-based leaf views, the font height is obtained based on the layout height coefficient of the current font, according to the formula: font height = font upslope + font downslope + font line spacing. The font layout height is calculated as: font layout height = font height * font layout height coefficient. The leaf view layout height is obtained by calculating the leaf view layout height as equal to the font layout height.
3. The method for implementing text layout according to claim 1, characterized in that, The process of obtaining the layout baseline of the leaf view specifically includes the following steps: For text-based leaf views, the font layout baseline is obtained based on the formula: font layout baseline = font layout height – font height + font slope. The leaf view layout baseline is obtained by setting the leaf view layout baseline to the font layout baseline.
4. The method for implementing text layout according to claim 1, characterized in that, In the case of no grid, determining the layout height and layout baseline of the row view specifically includes the following steps: Obtain the layout height and layout baseline of the leaf view to be processed. If the layout height of the row view is less than the layout height of the leaf view, then determine the layout height of the row view as the layout height of the leaf view. If the row view layout baseline is less than the leaf view layout baseline, then the row view layout baseline is determined to be the leaf view layout baseline.
5. The method for implementing text layout according to claim 1, characterized in that, In the case of a grid, determining the layout height and layout baseline of the row view and adjusting the slot information specifically includes the following steps: In the case of a grid, obtain the height of a single grid cell to get the number of grid cells occupied by the row view layout height, and then obtain the occupied grid height according to the formula: occupied grid height = single grid cell height * number of grid cells occupied by the row view layout height. The total height of a slot is calculated as follows: Total slot height = Occupied grid height - Layout height of row view. The height of slots in the upper row view and slots in the lower row view are both half of the total slot height.
6. A method for implementing text layout according to claim 5, characterized in that, The process of obtaining the grid number occupied by the row view layout height includes the following steps: After obtaining the line spacing setting value, the height of the row view layout is compared with the height of a single grid cell, and then rounded down to obtain the number of grid cells occupied by the row view layout height. Take the larger value between the line spacing setting and the number of grid cells occupied by the line view layout height, and redetermine the number of grid cells occupied by the line view layout height.
7. A method for implementing text layout according to claim 1, characterized in that, The To obtain the starting Y-coordinate and drawing height for the leaf view, the following steps are involved: The starting Y-coordinate for drawing the leaf view is obtained by calculating the starting Y-coordinate for drawing the row view plus the rounded height of the slot on the row view. The leaf view drawing height 1 is calculated by rounding down the leaf view layout height. The leaf view drawing height 2 is calculated as follows: = Row view drawing height - (Rounded row view upper slot height) - (Rounded row view lower slot height). Take the larger of the leaf view drawing height 1 and leaf view drawing height 2 as the leaf view drawing height.
8. A method for implementing text layout according to claim 1, characterized in that, The process of obtaining the baseline for drawing the leaf view specifically includes the following steps: The drawing baseline of the leaf view is obtained by calculating the starting Y coordinate of the leaf view drawing plus the drawing height of the leaf view minus the drawing baseline of the rounded row view. The text is then drawn using the drawing baseline of the leaf view as the starting Y coordinate.
Citation Information
Patent Citations
Interface control arrangement device and interface control arrangement method
CN102929603A
Method, device and equipment for realizing mixed layout of characters with different attributes
CN115455905A