openharmony 鸿蒙 capi-drawing-text-typography-h

2026-08-25 浏览 (1)

drawing_text_typography.h

Overview

This file declares the functions related to typography in the drawing module.

File to include: <native_drawing/drawing_text_typography.h>

Library: libnative_drawing.so

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 8

Related module: Drawing

Summary

Structs

Nametypedef KeywordDescription
OH_Drawing_PlaceholderSpanOH_Drawing_PlaceholderSpanDescribes the placeholder that acts as a span.
OH_Drawing_FontDescriptorOH_Drawing_FontDescriptorDescribes the detailed information about a system font.
OH_Drawing_LineMetricsOH_Drawing_LineMetricsDescribes the measurement information about a line of text.
OH_Drawing_FontFallbackInfoOH_Drawing_FontFallbackInfoDescribes the information about a font fallback.
OH_Drawing_FontFallbackGroupOH_Drawing_FontFallbackGroupDescribes the information about a font fallback group.
OH_Drawing_FontAdjustInfoOH_Drawing_FontAdjustInfoDescribes the information about a font weight mapping.
OH_Drawing_FontAliasInfoOH_Drawing_FontAliasInfoDescribes the information about a font alias.
OH_Drawing_FontGenericInfoOH_Drawing_FontGenericInfoDescribes the information about generic fonts supported by the system.
OH_Drawing_FontConfigInfoOH_Drawing_FontConfigInfoDescribes the information about a system font configuration.
OH_Drawing_FontStyleStructOH_Drawing_FontStyleStructDescribes a font style.
OH_Drawing_FontFeatureOH_Drawing_FontFeatureDescribes a font feature.
OH_Drawing_StrutStyleOH_Drawing_StrutStyleDescribes a strut style. The strut style determines the line spacing, baseline alignment mode, and other properties related to the line height when drawing texts.
OH_Drawing_RectSizeOH_Drawing_RectSizeDefines a text rectangle structure.

Enums

Nametypedef KeywordDescription
OH_Drawing_TextDirection-Enumerates the text directions.
OH_Drawing_TextAlign-Enumerates the text alignment modes.
OH_Drawing_FontWeight-Enumerates the font weights.
OH_Drawing_TextBaseline-Enumerates the text baselines.
OH_Drawing_TextDecoration-Enumerates the text decorations.
OH_Drawing_FontStyle-Enumerates the font styles.
OH_Drawing_PlaceholderVerticalAlignmentOH_Drawing_PlaceholderVerticalAlignmentEnumerates the vertical alignment modes of placeholders.
OH_Drawing_TextDecorationStyleOH_Drawing_TextDecorationStyleEnumerates the text decoration styles.
OH_Drawing_EllipsisModalOH_Drawing_EllipsisModalEnumerates the ellipsis styles.
OH_Drawing_BreakStrategyOH_Drawing_BreakStrategyEnumerates the text break strategies.
OH_Drawing_WordBreakTypeOH_Drawing_WordBreakTypeEnumerates the word break types.
OH_Drawing_RectHeightStyleOH_Drawing_RectHeightStyleEnumerates the rectangle height styles.
OH_Drawing_RectWidthStyleOH_Drawing_RectWidthStyleEnumerates the rectangle width styles.
OH_Drawing_TextBadgeTypeOH_Drawing_TextBadgeTypeEnumerates the text badge styles.
OH_Drawing_FontConfigInfoErrorCode-Enumerates the error codes that may be used during the obtaining of system font configurations.
OH_Drawing_FontWidth-Enumerates the font widths.
OH_Drawing_TextHeightBehavior-Enumerates the text height modifier patterns.
OH_Drawing_TextStyleType-Enumerates the text style types.
OH_Drawing_TextVerticalAlignmentOH_Drawing_TextVerticalAlignmentEnumerates the vertical alignment modes.
OH_Drawing_LineHeightStyleOH_Drawing_LineHeightStyleEnumerates the scaling base styles of the line height. The default style is TEXT_LINE_HEIGHT_BY_FONT_SIZE.
OH_Drawing_TextStyleAttributeIdOH_Drawing_TextStyleAttributeIdEnumerates the text style attributes.
OH_Drawing_TypographyStyleAttributeIdOH_Drawing_TypographyStyleAttributeIdEnumerates the typography style attributes.
For the common attributes of the typography styles and text styles, you are advised to use the text style attributes, which can be obtained from OH_Drawing_TextStyleAttributeId.

Functions

NameDescription
OH_Drawing_TypographyStyle* OH_Drawing_CreateTypographyStyle(void)Creates an OH_Drawing_TypographyStyle object. Release this pointer by calling OH_Drawing_DestroyTypographyStyle when this object is no longer needed.
void OH_Drawing_DestroyTypographyStyle(OH_Drawing_TypographyStyle* style)Destroys an OH_Drawing_TypographyStyle object and reclaims the memory occupied by the object.
void OH_Drawing_SetTypographyTextDirection(OH_Drawing_TypographyStyle* style, int direction)Sets the text direction in a typography style.
void OH_Drawing_SetTypographyTextAlign(OH_Drawing_TypographyStyle* style, int align)Sets the text alignment mode.
int OH_Drawing_TypographyGetEffectiveAlignment(OH_Drawing_TypographyStyle* style)Obtains the text alignment mode.
void OH_Drawing_SetTypographyTextMaxLines(OH_Drawing_TypographyStyle* style, int lineNumber)Sets the maximum number of lines in the text.
OH_Drawing_TextStyle* OH_Drawing_CreateTextStyle(void)Creates an OH_Drawing_TextStyle object.
OH_Drawing_TextStyle* OH_Drawing_TypographyGetTextStyle(OH_Drawing_TypographyStyle* style)Obtains the default text style of a typography style.
void OH_Drawing_DestroyTextStyle(OH_Drawing_TextStyle* style)Destroys an OH_Drawing_TextStyle object and reclaims the memory occupied by the object.
void OH_Drawing_SetTextStyleColor(OH_Drawing_TextStyle* style, uint32_t color)Sets the color for a text style.
void OH_Drawing_SetTextStyleFontSize(OH_Drawing_TextStyle* style, double fontSize)Sets the font size for a text style.
void OH_Drawing_SetTextStyleFontWeight(OH_Drawing_TextStyle* style, int fontWeight)Sets the font weight for a text style. Currently, only the default system font supports font weight adjustment. For other fonts, if the weight is less than semi-bold, there is no variation in stroke thickness. If the weight is greater than or equal to semi-bold, it might result in a fake bold effect.
void OH_Drawing_SetTextStyleBaseLine(OH_Drawing_TextStyle* style, int baseline)Sets the baseline for a text style.
void OH_Drawing_SetTextStyleDecoration(OH_Drawing_TextStyle* style, int decoration)Sets the decoration for a text style. Only one decoration can be set. To add multiple decorations, use OH_Drawing_AddTextStyleDecoration.
void OH_Drawing_AddTextStyleDecoration(OH_Drawing_TextStyle* style, int decoration)Adds the decoration for a text style. Multiple decoration lines can be displayed.
void OH_Drawing_RemoveTextStyleDecoration(OH_Drawing_TextStyle* style, int decoration)Removes the decoration for a text style.
void OH_Drawing_SetTextStyleDecorationColor(OH_Drawing_TextStyle* style, uint32_t color)Sets the decoration color for a text style. If this API is not called or color is set to 0, the decoration color follows the text color.
void OH_Drawing_SetTextStyleFontHeight(OH_Drawing_TextStyle* style, double fontHeight)Sets the line height based on the multiple of the font size.
void OH_Drawing_SetTextStyleFontFamilies(OH_Drawing_TextStyle* style,int fontFamiliesNumber, const char* fontFamilies[])Sets the font families for a text style.
void OH_Drawing_SetTextStyleFontStyle(OH_Drawing_TextStyle* style, int fontStyle)Sets the font style for a text style.
void OH_Drawing_SetTextStyleLocale(OH_Drawing_TextStyle* style, const char* locale)Sets the locale for a text style.
void OH_Drawing_SetTextStyleForegroundBrush(OH_Drawing_TextStyle* style, OH_Drawing_Brush* foregroundBrush)Sets the foreground brush for a text style.
void OH_Drawing_TextStyleGetForegroundBrush(OH_Drawing_TextStyle* style, OH_Drawing_Brush* foregroundBrush)Obtains the foreground brush of a text style.
void OH_Drawing_SetTextStyleForegroundPen(OH_Drawing_TextStyle* style, OH_Drawing_Pen* foregroundPen)Sets the foreground pen for a text style.
void OH_Drawing_TextStyleGetForegroundPen(OH_Drawing_TextStyle* style, OH_Drawing_Pen* foregroundPen)Obtains the foreground pen of a text style.
void OH_Drawing_SetTextStyleBackgroundBrush(OH_Drawing_TextStyle* style, OH_Drawing_Brush* backgroundBrush)Sets the background brush for a text style.
void OH_Drawing_TextStyleGetBackgroundBrush(OH_Drawing_TextStyle* style, OH_Drawing_Brush* backgroundBrush)Obtains the background brush of a text style.
void OH_Drawing_SetTextStyleBackgroundPen(OH_Drawing_TextStyle* style, OH_Drawing_Pen* backgroundPen)Sets the background pen for a text style.
void OH_Drawing_TextStyleGetBackgroundPen(OH_Drawing_TextStyle* style, OH_Drawing_Pen* backgroundPen)Obtains the background pen of a text style.
OH_Drawing_TypographyCreate* OH_Drawing_CreateTypographyHandler(OH_Drawing_TypographyStyle* style,OH_Drawing_FontCollection* fontCollection)Creates an OH_Drawing_TypographyCreate object. Release this pointer by calling OH_Drawing_DestroyTypographyHandler when this object is no longer needed. You are advised to use the OH_Drawing_CreateSharedFontCollection function to create an OH_Drawing_FontCollection object.
void OH_Drawing_DestroyTypographyHandler(OH_Drawing_TypographyCreate* handler)Reclaims the memory occupied by an OH_Drawing_TypographyCreate object.
void OH_Drawing_TypographyHandlerPushTextStyle(OH_Drawing_TypographyCreate* handler, OH_Drawing_TextStyle* style)Pushes a text style into the text style stack. Any text added afterward will use the style currently on top of the stack.
void OH_Drawing_TypographyHandlerAddText(OH_Drawing_TypographyCreate* handler, const char* text)Adds text.
void OH_Drawing_TypographyHandlerPopTextStyle(OH_Drawing_TypographyCreate* handler)Pops the top text style out of the text style stack.
OH_Drawing_Typography* OH_Drawing_CreateTypography(OH_Drawing_TypographyCreate* handler)Creates an OH_Drawing_Typography object. Release this pointer by calling OH_Drawing_DestroyTypography when this object is no longer needed.
void OH_Drawing_DestroyTypography(OH_Drawing_Typography* typography)Destroys an OH_Drawing_Typography object and reclaims the memory occupied by the object.
void OH_Drawing_TypographyLayout(OH_Drawing_Typography* typography, double maxWidth)Lays out the typography.
void OH_Drawing_TypographyPaint(OH_Drawing_Typography* typography, OH_Drawing_Canvas* canvas,double positionX, double positionY)Draws text from the upper left corner at a specified position. This function must be called after OH_Drawing_TypographyLayout is called and applied.
void OH_Drawing_TypographyPaintOnPath(OH_Drawing_Typography* typography, OH_Drawing_Canvas* canvas,OH_Drawing_Path* path, double hOffset, double vOffset)Draws text along a path. To prevent text overlap caused by the text width exceeding the layout width, you are advised to use OH_Drawing_SetTypographyTextMaxLines to limit the text to a single line.
double OH_Drawing_TypographyGetMaxWidth(OH_Drawing_Typography* typography)Obtains the typography width set by the user. This function must be called after OH_Drawing_TypographyLayout is called.
double OH_Drawing_TypographyGetHeight(OH_Drawing_Typography* typography)Obtains the overall height of a typography object. This function must be called after OH_Drawing_TypographyLayout is called.
double OH_Drawing_TypographyGetLongestLine(OH_Drawing_Typography* typography)Obtains the width of the longest line in a typography object. This function must be called after OH_Drawing_TypographyLayout is called. You are advised to round up the return value. If the text content is empty, 0.0 is returned.
double OH_Drawing_TypographyGetLongestLineWithIndent(OH_Drawing_Typography* typography)Obtains the width of the longest line of a typography object, including its indentation. This function must be called after OH_Drawing_TypographyLayout is called. You are advised to round up the return value. If the text content is empty, 0.0 is returned.
double OH_Drawing_TypographyGetMinIntrinsicWidth(OH_Drawing_Typography* typography)Obtains the minimum intrinsic width in a typography object. This function must be called after OH_Drawing_TypographyLayout is called.
double OH_Drawing_TypographyGetMaxIntrinsicWidth(OH_Drawing_Typography* typography)Obtains the maximum intrinsic width in a typography object. This function must be called after OH_Drawing_TypographyLayout is called.
double OH_Drawing_TypographyGetAlphabeticBaseline(OH_Drawing_Typography* typography)Obtains the alphabetic baseline in a typography object.
double OH_Drawing_TypographyGetIdeographicBaseline(OH_Drawing_Typography* typography)Obtains the ideographic baseline in a typography object.
void OH_Drawing_TypographyHandlerAddPlaceholder(OH_Drawing_TypographyCreate* handler,OH_Drawing_PlaceholderSpan* span)Adds a placeholder.
bool OH_Drawing_TypographyDidExceedMaxLines(OH_Drawing_Typography* typography)Checks whether the text in the typography object exceeds the line limit. This function must be called after OH_Drawing_TypographyLayout is called. It returns false if the line limit is not set using OH_Drawing_SetTypographyTextMaxLines.
OH_Drawing_TextBox* OH_Drawing_TypographyGetRectsForRange(OH_Drawing_Typography* typography,size_t start, size_t end, OH_Drawing_RectHeightStyle heightStyle, OH_Drawing_RectWidthStyle widthStyle)Obtains text boxes in a given range of a typography object. This function must be called after OH_Drawing_TypographyLayout is called. Release this pointer by calling OH_Drawing_TypographyDestroyTextBox when this object is no longer needed.
OH_Drawing_TextBox* OH_Drawing_TypographyGetRectsForPlaceholders(OH_Drawing_Typography* typography)Obtains text boxes for placeholders in a typography object. This function must be called after OH_Drawing_TypographyLayout is called. Release this pointer by calling OH_Drawing_TypographyDestroyTextBox when this object is no longer needed.
float OH_Drawing_GetLeftFromTextBox(OH_Drawing_TextBox* textbox, int index)Obtains the left position of a text box.
float OH_Drawing_GetRightFromTextBox(OH_Drawing_TextBox* textbox, int index)Obtains the right position of a text box.
float OH_Drawing_GetTopFromTextBox(OH_Drawing_TextBox* textbox, int index)Obtains the top position of a text box.
float OH_Drawing_GetBottomFromTextBox(OH_Drawing_TextBox* textbox, int index)Obtains the bottom position of a text box.
int OH_Drawing_GetTextDirectionFromTextBox(OH_Drawing_TextBox* textbox, int index)Obtains the text direction of a text box.
size_t OH_Drawing_GetSizeOfTextBox(OH_Drawing_TextBox* textBox)Obtains the number of text boxes.
OH_Drawing_PositionAndAffinity* OH_Drawing_TypographyGetGlyphPositionAtCoordinate(OH_Drawing_Typography* typography,double dx, double dy)Obtains the position and affinity of the glyph at the given coordinates.
OH_Drawing_PositionAndAffinity* OH_Drawing_TypographyGetGlyphPositionAtCoordinateWithCluster(OH_Drawing_Typography* typography, double dx, double dy)Obtains the position and affinity of the glyph cluster to which the glyph at the given coordinates belongs. The glyph cluster is a container that holds one or more glyphs.
size_t OH_Drawing_GetPositionFromPositionAndAffinity(OH_Drawing_PositionAndAffinity* positionAndAffinity)Obtains the position attribute of an OH_Drawing_PositionAndAffinity object.
int OH_Drawing_GetAffinityFromPositionAndAffinity(OH_Drawing_PositionAndAffinity* positionAndAffinity)Obtains the affinity attribute of an OH_Drawing_PositionAndAffinity object. The affinity determines whether the font is close to the front text or rear text.
OH_Drawing_Range* OH_Drawing_TypographyGetWordBoundary(OH_Drawing_Typography* typography, size_t offset)Obtains the word boundary in a typography object.
size_t OH_Drawing_GetStartFromRange(OH_Drawing_Range* range)Obtains the start position of an OH_Drawing_Range object.
size_t OH_Drawing_GetEndFromRange(OH_Drawing_Range* range)Obtains the end position of an OH_Drawing_Range object.
size_t OH_Drawing_TypographyGetLineCount(OH_Drawing_Typography* typography)Obtains the number of lines in a typography object. This function must be called after OH_Drawing_TypographyLayout is called.
void OH_Drawing_SetTextStyleDecorationStyle(OH_Drawing_TextStyle* style, int decorationStyle)Sets the decoration style for a text style.
void OH_Drawing_SetTextStyleDecorationThicknessScale(OH_Drawing_TextStyle* style, double decorationThicknessScale)Sets the thickness scale factor for the decoration style of a text style.
void OH_Drawing_SetTextStyleLetterSpacing(OH_Drawing_TextStyle* style, double letterSpacing)Sets the letter spacing for a text style.
void OH_Drawing_SetTextStyleWordSpacing(OH_Drawing_TextStyle* style, double wordSpacing)Sets the word spacing for a text style.
void OH_Drawing_SetTextStyleHalfLeading(OH_Drawing_TextStyle* style, bool halfLeading)Sets whether to enable half leading for a text style.
void OH_Drawing_SetTextStyleEllipsis(OH_Drawing_TextStyle* style, const char* ellipsis)Sets the ellipsis content for a text style.
void OH_Drawing_SetTextStyleEllipsisModal(OH_Drawing_TextStyle* style, int ellipsisModal)Sets the ellipsis style for a text style.
void OH_Drawing_SetTypographyTextBreakStrategy(OH_Drawing_TypographyStyle* style, int breakStrategy)Sets the text break strategy.
void OH_Drawing_SetTypographyTextWordBreakType(OH_Drawing_TypographyStyle* style, int wordBreakType)Sets the word break type.
void OH_Drawing_SetTypographyTextEllipsisModal(OH_Drawing_TypographyStyle* style, int ellipsisModal)Sets the ellipsis style for a text style.
void OH_Drawing_SetTypographyTextEllipsis(OH_Drawing_TypographyStyle* style, const char* ellipsis)Sets the ellipsis text for a typography style.
double OH_Drawing_TypographyGetLineHeight(OH_Drawing_Typography* typography, int lineNumber)Obtains the line height in a typography object. This function must be called after OH_Drawing_TypographyLayout is called.
double OH_Drawing_TypographyGetLineWidth(OH_Drawing_Typography* typography, int lineNumber)Obtains the line width of a specified line. This function must be called after OH_Drawing_TypographyLayout is called.
void OH_Drawing_SetTypographyTextSplitRatio(OH_Drawing_TypographyStyle* style, float textSplitRatio)Sets the text split ratio.
bool OH_Drawing_TypographyIsLineUnlimited(OH_Drawing_TypographyStyle* style)Checks whether the maximum number of lines is limited.
bool OH_Drawing_TypographyIsEllipsized(OH_Drawing_TypographyStyle* style)Checks whether an ellipsis is configured for a typography style.
void OH_Drawing_SetTypographyTextLocale(OH_Drawing_TypographyStyle* style, const char* locale)Sets the locale for a typography style.
bool OH_Drawing_TextStyleGetFontMetrics(OH_Drawing_Typography* typography,OH_Drawing_TextStyle* style, OH_Drawing_Font_Metrics* fontmetrics)Obtains the font metrics of a text style.
void OH_Drawing_SetTypographyTextStyle(OH_Drawing_TypographyStyle* handler, OH_Drawing_TextStyle* style)Sets a text style.
OH_Drawing_FontDescriptor* OH_Drawing_CreateFontDescriptor(void)Creates an OH_Drawing_FontDescriptor object to describe the detailed information about a system font.
void OH_Drawing_DestroyFontDescriptor(OH_Drawing_FontDescriptor* descriptor)Destroys an OH_Drawing_FontDescriptor object and reclaims the memory occupied by the object.
OH_Drawing_FontParser* OH_Drawing_CreateFontParser(void)Creates an OH_Drawing_FontParser object to parse a system font.
void OH_Drawing_DestroyFontParser(OH_Drawing_FontParser* parser)Destroys an OH_Drawing_FontParser object and reclaims the memory occupied by the object.
char** OH_Drawing_FontParserGetSystemFontList(OH_Drawing_FontParser* fontParser, size_t* num)Obtains the list of system fonts. This function can be used only on 2-in-1 devices and phones.
void OH_Drawing_DestroySystemFontList(char** fontList, size_t num)Reclaims the memory occupied by the system font list.
OH_Drawing_FontDescriptor* OH_Drawing_FontParserGetFontByName(OH_Drawing_FontParser* fontParser, const char* name)Obtains the descriptor of a system font based on the font name.
OH_Drawing_LineMetrics* OH_Drawing_TypographyGetLineMetrics(OH_Drawing_Typography* typography)Obtains the line metrics in a typography object. This function must be called after OH_Drawing_TypographyLayout is called. Release this pointer by calling OH_Drawing_DestroyLineMetrics when this object is no longer needed.
size_t OH_Drawing_LineMetricsGetSize(OH_Drawing_LineMetrics* lineMetrics)Obtains the number of lines.
void OH_Drawing_DestroyLineMetrics(OH_Drawing_LineMetrics* lineMetrics)Destroys an OH_Drawing_LineMetrics object and reclaims the memory occupied by the object.
bool OH_Drawing_TypographyGetLineMetricsAt(OH_Drawing_Typography* typography,int lineNumber, OH_Drawing_LineMetrics* lineMetric)Obtains the metrics of the given line in a typography object. For details, see the OH_Drawing_LineMetr struct. This function must be called after OH_Drawing_TypographyLayout is called.
bool OH_Drawing_TypographyGetLineInfo(OH_Drawing_Typography* typography, int lineNumber, bool oneLine,bool includeWhitespace, OH_Drawing_LineMetrics* drawingLineMetrics)Obtains the metrics of a given line or the metrics of the first character in a given line in a typography object. This function must be called after OH_Drawing_TypographyLayout is called.
void OH_Drawing_SetTypographyTextFontWeight(OH_Drawing_TypographyStyle* style, int weight)Sets the default font weight for a typography style. Currently, only the default system font supports font weight adjustment. For other fonts, if the weight is less than semi-bold, there is no variation in stroke thickness. If the weight is greater than or equal to semi-bold, it might result in a fake bold effect.
void OH_Drawing_SetTypographyTextFontStyle(OH_Drawing_TypographyStyle* style, int fontStyle)Sets the default font style for a typography style.
void OH_Drawing_SetTypographyTextFontFamily(OH_Drawing_TypographyStyle* style, const char* fontFamily)Sets the font family name for text.
void OH_Drawing_SetTypographyTextFontSize(OH_Drawing_TypographyStyle* style, double fontSize)Sets the font size for text.
void OH_Drawing_SetTypographyTextFontHeight(OH_Drawing_TypographyStyle* style, double fontHeight)Sets the font height for text.
void OH_Drawing_SetTypographyTextHalfLeading(OH_Drawing_TypographyStyle* style, bool halfLeading)Sets whether to enable half leading for text.
void OH_Drawing_SetTypographyTextUseLineStyle(OH_Drawing_TypographyStyle* style, bool useLineStyle)Sets whether to enable the text line style.
void OH_Drawing_SetTypographyTextLineStyleFontWeight(OH_Drawing_TypographyStyle* style, int weight)Sets the text font weight of the strut style in a typography style. Currently, only the default system font supports font weight adjustment. For other fonts, if the weight is less than semi-bold, there is no variation in stroke thickness. If the weight is greater than or equal to semi-bold, it might result in a fake bold effect.
void OH_Drawing_SetTypographyTextLineStyleFontStyle(OH_Drawing_TypographyStyle* style, int fontStyle)Sets the font style of the strut style in a typography style.
void OH_Drawing_SetTypographyTextLineStyleFontFamilies(OH_Drawing_TypographyStyle* style,int fontFamiliesNumber, const char* fontFamilies[])Sets the font families for a text line style.
void OH_Drawing_SetTypographyTextLineStyleFontSize(OH_Drawing_TypographyStyle* style, double lineStyleFontSize)Sets the font size for a text line style.
void OH_Drawing_SetTypographyTextLineStyleFontHeight(OH_Drawing_TypographyStyle* style, double lineStyleFontHeight)Sets the font height for a text line style.
void OH_Drawing_SetTypographyTextLineStyleHalfLeading(OH_Drawing_TypographyStyle* style, bool lineStyleHalfLeading)Sets whether to enable half leading for a text line style.
void OH_Drawing_SetTypographyTextLineStyleSpacingScale(OH_Drawing_TypographyStyle* style, double spacingScale)Sets the spacing scale factor for a text line style.
void OH_Drawing_SetTypographyTextLineStyleOnly(OH_Drawing_TypographyStyle* style, bool lineStyleOnly)Sets whether to enable the text line style only.
OH_Drawing_TextShadow* OH_Drawing_CreateTextShadow(void)Creates an OH_Drawing_TextShadow object. Release this pointer by calling OH_Drawing_DestroyTextShadow when this object is no longer needed.
void OH_Drawing_DestroyTextShadow(OH_Drawing_TextShadow* shadow)Destroys an OH_Drawing_TextShadow object and reclaims the memory occupied by the object.
OH_Drawing_TextShadow* OH_Drawing_TextStyleGetShadows(OH_Drawing_TextStyle* style)Obtains a text shadow container. Release this pointer by calling OH_Drawing_DestroyTextShadows when this object is no longer needed.
int OH_Drawing_TextStyleGetShadowCount(OH_Drawing_TextStyle* style)Obtains the size of a text shadow container.
void OH_Drawing_TextStyleAddShadow(OH_Drawing_TextStyle* style, const OH_Drawing_TextShadow* shadow)Adds a shadow to a text shadow container.
void OH_Drawing_TextStyleClearShadows(OH_Drawing_TextStyle* style)Clears all shadows in a text shadow container.
OH_Drawing_TextShadow* OH_Drawing_TextStyleGetShadowWithIndex(OH_Drawing_TextStyle* style, int index)Obtains a shadow with a given index in a text shadow container.
void OH_Drawing_TypographySetIndents(OH_Drawing_Typography* typography, int indentsNumber, const float indents[])Sets indents for typography. If this function is not called, texts will have no indentation applied.
float OH_Drawing_TypographyGetIndentsWithIndex(OH_Drawing_Typography* typography, int index)Obtains indents with a given index in a typography object. The line index starts from 0.
OH_Drawing_Range* OH_Drawing_TypographyGetLineTextRange(OH_Drawing_Typography* typography,int lineNumber, bool includeSpaces)Obtains the line bounds in a typography object. This function must be called after OH_Drawing_TypographyLayout is called. This function can only be used to obtain the bounds of existing lines. That is, the line index must start from 0, and the maximum index is OH_Drawing_TypographyGetLineCount - 1.
void OH_Drawing_DestroyTextShadows(OH_Drawing_TextShadow* shadow)Reclaims the memory occupied by the vector consisting of the OH_Drawing_TextShadow objects.
OH_Drawing_FontConfigInfo* OH_Drawing_GetSystemFontConfigInfo(OH_Drawing_FontConfigInfoErrorCode* errorCode)Obtains the system font configuration.
void OH_Drawing_DestroySystemFontConfigInfo(OH_Drawing_FontConfigInfo* drawFontCfgInfo)Reclaims the memory occupied by the system font configuration.
void OH_Drawing_SetTextStyleFontStyleStruct(OH_Drawing_TextStyle* drawingTextStyle,OH_Drawing_FontStyleStruct fontStyle)Sets the font style, including the font weight, width, and slant, for a text style.
void OH_Drawing_SetTextStyleBadgeType(OH_Drawing_TextStyle* style, OH_Drawing_TextBadgeType textBadgeType)Sets whether to use superscript or subscript in text layout. If this API is not called, the feature is disabled by default.
OH_Drawing_FontStyleStruct OH_Drawing_TextStyleGetFontStyleStruct(OH_Drawing_TextStyle* drawingTextStyle)Obtains the font style, including the font weight, width, and slant, of a text style.
void OH_Drawing_SetTypographyStyleFontStyleStruct(OH_Drawing_TypographyStyle* drawingStyle,OH_Drawing_FontStyleStruct fontStyle)Sets the font style, including the font weight, width, and slant, for the default text style of a typography style.
OH_Drawing_FontStyleStruct OH_Drawing_TypographyStyleGetFontStyleStruct(OH_Drawing_TypographyStyle* drawingStyle)Obtains the font style, including the font weight, width, and slant, of the default text style of a typography style.
void OH_Drawing_TextStyleSetBackgroundRect(OH_Drawing_TextStyle* style,const OH_Drawing_RectStyle_Info* rectStyleInfo, int styleId)Sets a background rectangle and style ID for a text style. The style ID is valid only when the background box is a rounded rectangle.
void OH_Drawing_TypographyHandlerAddSymbol(OH_Drawing_TypographyCreate* handler, uint32_t symbol)Adds the symbol to use in the typography creation process.
void OH_Drawing_TextStyleAddFontFeature(OH_Drawing_TextStyle* style, const char* tag, int value)Adds a font feature for a text style.
void OH_Drawing_TextStyleAddFontVariation(OH_Drawing_TextStyle* style, const char* axis, const float value)Adds a font variation. This function takes effect only when the corresponding font file (.ttf file) supports variable adjustment. Otherwise, calling this function does not take effect.
OH_Drawing_FontFeature* OH_Drawing_TextStyleGetFontFeatures(OH_Drawing_TextStyle* style)Obtains all the contents in a font feature map container of a text style.
void OH_Drawing_TextStyleDestroyFontFeatures(OH_Drawing_FontFeature* fontFeature, size_t fontFeatureSize)Reclaims the memory occupied by the struct array that holds all the font features.
size_t OH_Drawing_TextStyleGetFontFeatureSize(OH_Drawing_TextStyle* style)Obtains the size of a font feature map container in a text style.
void OH_Drawing_TextStyleClearFontFeature(OH_Drawing_TextStyle* style)Clears all the contents in a font feature map container of a text style.
double OH_Drawing_TextStyleGetBaselineShift(OH_Drawing_TextStyle* style)Obtains the baseline drift of a text style.
void OH_Drawing_TextStyleSetBaselineShift(OH_Drawing_TextStyle* style, double lineShift)Sets a baseline drift for a text style.
void OH_Drawing_TypographyTextSetHeightBehavior(OH_Drawing_TypographyStyle* style,OH_Drawing_TextHeightBehavior heightMode)Sets a text height modifier pattern.
OH_Drawing_TextHeightBehavior OH_Drawing_TypographyTextGetHeightBehavior(OH_Drawing_TypographyStyle* style)Obtains the text height modifier pattern.
OH_Drawing_Font_Metrics* OH_Drawing_TypographyGetLineFontMetrics(OH_Drawing_Typography* typography,size_t lineNumber, size_t* fontMetricsSize)Obtains all font metrics from a given line in a typography object. This function must be called after OH_Drawing_TypographyLayout is called. Otherwise, a null pointer is returned. Release this pointer by calling OH_Drawing_TypographyDestroyLineFontMetrics when this object is no longer needed.
void OH_Drawing_TypographyDestroyLineFontMetrics(OH_Drawing_Font_Metrics* lineFontMetric)Reclaims the memory occupied by the struct array that holds all the font metrics of a given line.
bool OH_Drawing_TextStyleIsEqual(const OH_Drawing_TextStyle* style, const OH_Drawing_TextStyle* comparedStyle)Checks whether two text styles are equal. The word width property is not involved in the comparison.
bool OH_Drawing_TextStyleIsEqualByFont(const OH_Drawing_TextStyle* style, const OH_Drawing_TextStyle* comparedStyle)Checks whether the font style properties of two text styles are equal.
bool OH_Drawing_TextStyleIsAttributeMatched(const OH_Drawing_TextStyle* style,const OH_Drawing_TextStyle* comparedStyle, OH_Drawing_TextStyleType textStyleType)Checks whether two text styles have the same font style type.
void OH_Drawing_TextStyleSetPlaceholder(OH_Drawing_TextStyle* style)Adds a placeholder.
bool OH_Drawing_TextStyleIsPlaceholder(OH_Drawing_TextStyle* style)Checks whether a placeholder is set for a text style.
OH_Drawing_TextAlign OH_Drawing_TypographyStyleGetEffectiveAlignment(OH_Drawing_TypographyStyle* style)Obtains the text alignment mode.
bool OH_Drawing_TypographyStyleIsHintEnabled(OH_Drawing_TypographyStyle* style)Checks whether font hinting is enabled for a typography style. Font hinting is used to improve the readability and appearance of small-sized text when rendering it.
void OH_Drawing_SetTypographyStyleTextStrutStyle(OH_Drawing_TypographyStyle* style, OH_Drawing_StrutStyle* strutstyle)Sets the strut style for a typography style.
OH_Drawing_StrutStyle* OH_Drawing_TypographyStyleGetStrutStyle(OH_Drawing_TypographyStyle* style)Obtains the strut style of a typography style.
void OH_Drawing_TypographyStyleDestroyStrutStyle(OH_Drawing_StrutStyle* strutstyle)Reclaims the memory occupied by a strut style.
bool OH_Drawing_TypographyStyleStrutStyleEquals(OH_Drawing_StrutStyle* from, OH_Drawing_StrutStyle* to)Checks whether two strut styles are equal.
void OH_Drawing_TypographyStyleSetHintsEnabled(OH_Drawing_TypographyStyle* style, bool hintsEnabled)Sets whether to enable font hinting for a typography style. Font hinting is used to improve the readability and appearance of small-sized text when rendering it.
void OH_Drawing_TypographyMarkDirty(OH_Drawing_Typography* typography)Marks a typography object as dirty data. This function is used to initialize the typography state.
int32_t OH_Drawing_TypographyGetUnresolvedGlyphsCount(OH_Drawing_Typography* typography)Obtains the number of unresolved glyphs in a typography object. This function can be called only after OH_Drawing_TypographyLayout is called and applied.
void OH_Drawing_TypographyUpdateFontSize(OH_Drawing_Typography* typography, size_t from, size_t to, float fontSize)Updates the font size in a typography object.
void OH_Drawing_TypographyUpdateFontColor(OH_Drawing_Typography* typography, uint32_t color)Updates the font color in a typography object. This API call also updates the decoration color if it hasn't been set yet. The updated font color takes effect after you call OH_Drawing_TypographyPaint to draw the text.
void OH_Drawing_TypographyUpdateDecoration(OH_Drawing_Typography* typography, OH_Drawing_TextDecoration decoration)Updates the decoration type of a typography object. The updated decoration type takes effect after you call OH_Drawing_TypographyPaint to draw the text.
void OH_Drawing_TypographyUpdateDecorationThicknessScale(OH_Drawing_Typography* typography,double decorationThicknessScale)Updates the decoration thickness scale of a typography object. The updated decoration thickness scale takes effect after you call OH_Drawing_TypographyPaint to draw the text.
void OH_Drawing_TypographyUpdateDecorationStyle(OH_Drawing_Typography* typography,OH_Drawing_TextDecorationStyle decorationStyle)Updates the decoration style of a typography object. The updated decoration style takes effect after you call OH_Drawing_TypographyPaint to draw the text.
bool OH_Drawing_TypographyTextGetLineStyle(OH_Drawing_TypographyStyle* style)Checks whether the text line style is enabled for a typography style.
OH_Drawing_FontWeight OH_Drawing_TypographyTextlineStyleGetFontWeight(OH_Drawing_TypographyStyle* style)Obtains the font weight of a text line style.
OH_Drawing_FontStyle OH_Drawing_TypographyTextlineStyleGetFontStyle(OH_Drawing_TypographyStyle* style)Obtains the font style of the strut style in a typography style.
char** OH_Drawing_TypographyTextlineStyleGetFontFamilies(OH_Drawing_TypographyStyle* style, size_t* num)Obtains the font families of a text line style.
void OH_Drawing_TypographyTextlineStyleDestroyFontFamilies(char** fontFamilies, size_t fontFamiliesNum)Reclaims the memory occupied by the font families.
double OH_Drawing_TypographyTextlineStyleGetFontSize(OH_Drawing_TypographyStyle* style)Obtains the font size of a text line style.
double OH_Drawing_TypographyTextlineStyleGetHeightScale(OH_Drawing_TypographyStyle* style)Obtains the height scale factor of a text line style.
bool OH_Drawing_TypographyTextlineStyleGetHeightOnly(OH_Drawing_TypographyStyle* style)Checks whether only the font height is used for a text line style.
bool OH_Drawing_TypographyTextlineStyleGetHalfLeading(OH_Drawing_TypographyStyle* style)Checks whether half leading is enabled for a text line style.
double OH_Drawing_TypographyTextlineStyleGetSpacingScale(OH_Drawing_TypographyStyle* style)Obtains the spacing scale factor of a text line style.
bool OH_Drawing_TypographyTextlineGetStyleOnly(OH_Drawing_TypographyStyle* style)Checks whether only the text line style is enabled for a typography style.
OH_Drawing_TextAlign OH_Drawing_TypographyGetTextAlign(OH_Drawing_TypographyStyle* style)Obtains the text alignment mode.
OH_Drawing_TextDirection OH_Drawing_TypographyGetTextDirection(OH_Drawing_TypographyStyle* style)Obtains the text direction of a typography style.
size_t OH_Drawing_TypographyGetTextMaxLines(OH_Drawing_TypographyStyle* style)Obtains the maximum number of lines.
char* OH_Drawing_TypographyGetTextEllipsis(OH_Drawing_TypographyStyle* style)Obtains the text ellipsis content of a typography style.
void OH_Drawing_TypographyDestroyEllipsis(char* ellipsis)Reclaims the memory occupied by the text ellipsis names.
bool OH_Drawing_TypographyStyleEquals(OH_Drawing_TypographyStyle* from, OH_Drawing_TypographyStyle* to)Checks whether two typography styles are the same. The text height modifier mode OH_Drawing_TextHeightBehavior is not involved in the comparison.
uint32_t OH_Drawing_TextStyleGetColor(OH_Drawing_TextStyle* style)Obtains the color of a text style.
OH_Drawing_TextDecorationStyle OH_Drawing_TextStyleGetDecorationStyle(OH_Drawing_TextStyle* style)Obtains the decoration style of a text style.
OH_Drawing_FontWeight OH_Drawing_TextStyleGetFontWeight(OH_Drawing_TextStyle* style)Obtains the font weight of a text style.
OH_Drawing_FontStyle OH_Drawing_TextStyleGetFontStyle(OH_Drawing_TextStyle* style)Obtains the font style of a text style.
OH_Drawing_TextBaseline OH_Drawing_TextStyleGetBaseline(OH_Drawing_TextStyle* style)Obtains the baseline of a text style.
char** OH_Drawing_TextStyleGetFontFamilies(OH_Drawing_TextStyle* style, size_t* num)Obtains the font families of a text style.
void OH_Drawing_TextStyleDestroyFontFamilies(char** fontFamilies, size_t num)Reclaims the memory occupied by the font families, where num specifies the number of font families.
double OH_Drawing_TextStyleGetFontSize(OH_Drawing_TextStyle* style)Obtains the font size of a text style.
double OH_Drawing_TextStyleGetLetterSpacing(OH_Drawing_TextStyle* style)Obtains the letter spacing of a text style.
double OH_Drawing_TextStyleGetWordSpacing(OH_Drawing_TextStyle* style)Obtains the word spacing of a text style.
double OH_Drawing_TextStyleGetFontHeight(OH_Drawing_TextStyle* style)Obtains the font height of a text style.
bool OH_Drawing_TextStyleGetHalfLeading(OH_Drawing_TextStyle* style)Checks whether half leading is enabled for a text style.
const char* OH_Drawing_TextStyleGetLocale(OH_Drawing_TextStyle* style)Obtains the locale of a text style.
void OH_Drawing_TypographyDestroyTextBox(OH_Drawing_TextBox* textBox)Releases the memory occupied by a text box.
void OH_Drawing_SetTextShadow(OH_Drawing_TextShadow* shadow, uint32_t color, OH_Drawing_Point* offset,double blurRadius)Sets a text shadow.
OH_Drawing_TextTab* OH_Drawing_CreateTextTab(OH_Drawing_TextAlign alignment, float location)Creates a text tab object.
void OH_Drawing_DestroyTextTab(OH_Drawing_TextTab* tab)Releases the memory occupied by a text tab object.
OH_Drawing_TextAlign OH_Drawing_GetTextTabAlignment(OH_Drawing_TextTab* tab)Obtains the alignment mode of a text tab.
float OH_Drawing_GetTextTabLocation(OH_Drawing_TextTab* tab)Obtains the location of a text tab.
void OH_Drawing_SetTypographyTextTab(OH_Drawing_TypographyStyle* style, OH_Drawing_TextTab* tab)Sets the alignment mode and location of a text tab. When the text alignment mode or ellipsis style is set, the tab does not take effect. When the tab location is less than 1.0, the tab is replaced with a space.
size_t OH_Drawing_GetDrawingArraySize(OH_Drawing_Array* drawingArray)Obtains the number of objects in the input object array OH_Drawing_Array.
void OH_Drawing_SetTypographyTextTrailingSpaceOptimized(OH_Drawing_TypographyStyle* style, bool trailingSpaceOptimized)Sets whether to include the trailing spaces in alignment calculations during text typography.
void OH_Drawing_TypographyHandlerAddEncodedText(OH_Drawing_TypographyCreate* handler, const void* text,size_t byteLength, OH_Drawing_TextEncoding textEncodingType)Adds text encoded in a specified format.
void OH_Drawing_SetTypographyTextAutoSpace(OH_Drawing_TypographyStyle *style, bool enableAutoSpace)Sets whether to enable automatic spacing during text typography.
This feature is disabled by default. If enabled, automatic spacing applies between CJK (Chinese, Japanese, and Korean) and Western characters (Latin, Cyrillic, and Greek), between CJK and digits, between CJK and copyright symbols, between copyright symbols and digits, and between copyright symbols and Western characters.
void OH_Drawing_TypographyUpdateDecorationColor(OH_Drawing_Typography* typography, uint32_t color)Updates the decoration color of a typography object.
The updated decoration color takes effect after you call OH_Drawing_TypographyPaint to draw the text.
void OH_Drawing_SetTypographyVerticalAlignment(OH_Drawing_TypographyStyle* style,OH_Drawing_TextVerticalAlignment align)Sets the vertical alignment mode of the text.
OH_Drawing_TypographyStyle* OH_Drawing_CopyTypographyStyle(OH_Drawing_TypographyStyle* style)Creates a copy of an existing paragraph style object.
OH_Drawing_TextStyle* OH_Drawing_CopyTextStyle(OH_Drawing_TextStyle* style)Creates a copy of an existing text style object.
OH_Drawing_TextShadow* OH_Drawing_CopyTextShadow(OH_Drawing_TextShadow* shadow)Creates a copy of an existing text shadow object.
OH_Drawing_ErrorCode OH_Drawing_SetTextStyleAttributeDouble(OH_Drawing_TextStyle* style, OH_Drawing_TextStyleAttributeId id, double value)Sets the text style attribute of the double type.
OH_Drawing_ErrorCode OH_Drawing_GetTextStyleAttributeDouble(OH_Drawing_TextStyle* style, OH_Drawing_TextStyleAttributeId id, double* value)Obtains the text style attribute of the double type.
OH_Drawing_ErrorCode OH_Drawing_SetTextStyleAttributeInt(OH_Drawing_TextStyle* style, OH_Drawing_TextStyleAttributeId id, int value)Sets the text style attribute of the int type.
OH_Drawing_ErrorCode OH_Drawing_GetTextStyleAttributeInt(OH_Drawing_TextStyle* style, OH_Drawing_TextStyleAttributeId id, int* value)Obtains the text style attribute of the int type.
OH_Drawing_ErrorCode OH_Drawing_SetTypographyStyleAttributeDouble(OH_Drawing_TypographyStyle* style, OH_Drawing_TypographyStyleAttributeId id, double value)Sets the typography style attribute of the double type.
OH_Drawing_ErrorCode OH_Drawing_GetTypographyStyleAttributeDouble(OH_Drawing_TypographyStyle* style, OH_Drawing_TypographyStyleAttributeId id, double* value)Obtains the typography style attribute of the double type.
OH_Drawing_ErrorCode OH_Drawing_SetTypographyStyleAttributeInt(OH_Drawing_TypographyStyle* style, OH_Drawing_TypographyStyleAttributeId id, int value)Sets the typography style attribute of the int type.
OH_Drawing_ErrorCode OH_Drawing_GetTypographyStyleAttributeInt(OH_Drawing_TypographyStyle* style, OH_Drawing_TypographyStyleAttributeId id, int* value)Obtains the typography style attribute of the int type.
OH_Drawing_ErrorCode OH_Drawing_SetTypographyStyleAttributeBool(OH_Drawing_TypographyStyle* style, OH_Drawing_TypographyStyleAttributeId id, bool value)Sets the typography style attribute of the bool type.
OH_Drawing_ErrorCode OH_Drawing_GetTypographyStyleAttributeBool(OH_Drawing_TypographyStyle* style, OH_Drawing_TypographyStyleAttributeId id, bool* value)Obtains the typography style attribute of the bool type.
OH_Drawing_ErrorCode OH_Drawing_SetTypographyStyleAttributeDoubleArray(OH_Drawing_TypographyStyle* style, OH_Drawing_TypographyStyleAttributeId id, double* arrayValue, size_t arrayLength)Sets the typography style attribute of the floating-point array type.
OH_Drawing_ErrorCode OH_Drawing_GetTypographyStyleAttributeDoubleArray(const OH_Drawing_TypographyStyle* style, OH_Drawing_TypographyStyleAttributeId id, double** arrayValue, size_t* arrayLength)Obtains the typography style attribute of the floating-point array type.
void OH_Drawing_DestroyPositionAndAffinity(OH_Drawing_PositionAndAffinity* positionAndAffinity)Destroys an OH_Drawing_PositionAndAffinity object and reclaims the memory occupied by the object.
OH_Drawing_Range* OH_Drawing_TypographyGetCharacterRangeForGlyphRangeWithBuffer(OH_Drawing_Typography* typography, size_t glyphRangeStart, size_t glyphRangeEnd, OH_Drawing_Range** actualGlyphRange, OH_Drawing_TextEncoding textEncodingType)Obtains the character range corresponding to the specified glyph range.
OH_Drawing_PositionAndAffinity* OH_Drawing_TypographyGetCharacterPositionAtCoordinateWithBuffer(OH_Drawing_Typography* typography, double dx, double dy, OH_Drawing_TextEncoding textEncodingType)Obtains the character position information closest to the specified coordinates.
OH_Drawing_Range* OH_Drawing_TypographyGetGlyphRangeForCharacterRangeWithBuffer(OH_Drawing_Typography* typography, size_t characterRangeStart, size_t characterRangeEnd, OH_Drawing_Range** actualCharacterRange, OH_Drawing_TextEncoding textEncodingType)Obtains the glyph range corresponding to the specified character range.
void OH_Drawing_ReleaseRangeBuffer(OH_Drawing_Range* range)Releases the memory occupied by the OH_Drawing_Range object.
OH_Drawing_RectSize OH_Drawing_TypographyLayoutWithConstraintsWithBuffer(OH_Drawing_Typography* typography, OH_Drawing_RectSize constraintsRect, OH_Drawing_Array** fitStrRangeArr, size_t* fitStrRangeArrayLen)Arranges the text in the constraint rectangle.
OH_Drawing_Range* OH_Drawing_GetRangeByArrayIndex(OH_Drawing_Array* array, size_t index)Obtains the pointer to the OH_Drawing_Range object based on the array index.
OH_Drawing_ErrorCode OH_Drawing_ReleaseArrayBuffer(OH_Drawing_Array* array)Releases the memory occupied by the OH_Drawing_Array object.
void OH_Drawing_TextStyleAddFontVariationWithNormalization(OH_Drawing_TextStyle* style, const char* axis, const float normalizedValue)Adds the normalized variable font attributes. This function takes effect only when the corresponding font file (.ttf file) supports variable adjustment.

Enum Description

OH_Drawing_TextDirection

enum OH_Drawing_TextDirection

Description

Enumerates the text directions.

Since: 8

ValueDescription
TEXT_DIRECTION_RTLRight to left (RTL).
TEXT_DIRECTION_LTRLeft to right (LTR).

OH_Drawing_TextAlign

enum OH_Drawing_TextAlign

Description

Enumerates the text alignment modes.

Since: 8

ValueDescription
TEXT_ALIGN_LEFTLeft-aligned.
TEXT_ALIGN_RIGHTRight-aligned.
TEXT_ALIGN_CENTERCenter-aligned.
TEXT_ALIGN_JUSTIFYJustified, which means that each line (except the last line) is stretched so that every line has equal width, and the left and right margins are straight.
TEXT_ALIGN_STARTWhen OH_Drawing_TextDirection is set to TEXT_DIRECTION_LTR, TEXT_ALIGN_START and TEXT_ALIGN_LEFT are the same.
Similarly, when OH_Drawing_TextDirection is set to TEXT_DIRECTION_RTL, TEXT_ALIGN_START and TEXT_ALIGN_RIGHT are the same.
TEXT_ALIGN_ENDWhen OH_Drawing_TextDirection is set to TEXT_DIRECTION_LTR, TEXT_ALIGN_END and TEXT_ALIGN_RIGHT are the same.
Similarly, when OH_Drawing_TextDirection is set to TEXT_DIRECTION_RTL, TEXT_ALIGN_END and TEXT_ALIGN_LEFT are the same.

OH_Drawing_FontWeight

enum OH_Drawing_FontWeight

Description

Enumerates the font weights.

Since: 8

ValueDescription
FONT_WEIGHT_100Thin.
FONT_WEIGHT_200Extra-light.
FONT_WEIGHT_300Light.
FONT_WEIGHT_400Normal/Regular.
FONT_WEIGHT_500Medium.
FONT_WEIGHT_600Semi-bold.
FONT_WEIGHT_700Bold.
FONT_WEIGHT_800Extra-bold.
FONT_WEIGHT_900Black.

OH_Drawing_TextBaseline

enum OH_Drawing_TextBaseline

Description

Enumerates the text baselines.

Since: 8

ValueDescription
TEXT_BASELINE_ALPHABETICAlphabetic, where the letters in alphabets like English sit on.
TEXT_BASELINE_IDEOGRAPHICIdeographic, where the baseline is at the bottom of the text area.

OH_Drawing_TextDecoration

enum OH_Drawing_TextDecoration

Description

Enumerates the text decorations.

Since: 8

ValueDescription
TEXT_DECORATION_NONE = 0x0No decoration.
TEXT_DECORATION_UNDERLINE = 0x1An underline is used for decoration.
TEXT_DECORATION_OVERLINE = 0x2An overline is used for decoration.
TEXT_DECORATION_LINE_THROUGH = 0x4A strikethrough is used for decoration.

OH_Drawing_FontStyle

enum OH_Drawing_FontStyle

Description

Enumerates the font styles.

Since: 8

ValueDescription
FONT_STYLE_NORMALNormal style.
FONT_STYLE_ITALICItalic.
FONT_STYLE_OBLIQUEOblique.

OH_Drawing_PlaceholderVerticalAlignment

enum OH_Drawing_PlaceholderVerticalAlignment

Description

Enumerates the vertical alignment modes of placeholders.

Since: 11

ValueDescription
ALIGNMENT_OFFSET_AT_BASELINEAligned to the baseline.
ALIGNMENT_ABOVE_BASELINEAligned above the baseline.
ALIGNMENT_BELOW_BASELINEAligned below the baseline.
ALIGNMENT_TOP_OF_ROW_BOXAligned to the top of the row box.
ALIGNMENT_BOTTOM_OF_ROW_BOXAligned to the bottom of the row box.
ALIGNMENT_CENTER_OF_ROW_BOXAligned to the center of the row box.
ALIGNMENT_FOLLOW_PARAGRAPH20+Follows the vertical alignment mode of the text.

OH_Drawing_TextVerticalAlignment

enum OH_Drawing_TextVerticalAlignment

Description

Enumerates the vertical alignment modes.

Since: 20

ValueDescription
TEXT_VERTICAL_ALIGNMENT_BASELINEAligned to the baseline.
TEXT_VERTICAL_ALIGNMENT_BOTTOMBottom aligned.
TEXT_VERTICAL_ALIGNMENT_CENTERCenter-aligned.
TEXT_VERTICAL_ALIGNMENT_TOPTop aligned.

OH_Drawing_TextDecorationStyle

enum OH_Drawing_TextDecorationStyle

Description

Enumerates the text decoration styles.

Since: 11

ValueDescription
TEXT_DECORATION_STYLE_SOLIDSolid style.
TEXT_DECORATION_STYLE_DOUBLEDouble style.
TEXT_DECORATION_STYLE_DOTTEDDotted style.
TEXT_DECORATION_STYLE_DASHEDDashed style.
TEXT_DECORATION_STYLE_WAVYWavy style.

OH_Drawing_EllipsisModal

enum OH_Drawing_EllipsisModal

Description

Enumerates the ellipsis styles.

Since: 11

ValueDescription
ELLIPSIS_MODAL_HEAD = 0Header ellipsis mode, that is, the ellipsis appears at the beginning of a line. This enumerated value is valid only when the maximum number of text lines is set to 1 by calling OH_Drawing_SetTypographyTextMaxLines.
ELLIPSIS_MODAL_MIDDLE = 1Middle ellipsis mode, that is, the ellipsis appears in the middle of a line. This enumerated value is valid only when the maximum number of text lines is set to 1 by calling OH_Drawing_SetTypographyTextMaxLines.
ELLIPSIS_MODAL_TAIL = 2End ellipsis mode, that is, the ellipsis appears at the end of a line. This enumerated value is valid when the maximum number of text lines is set to any value by calling OH_Drawing_SetTypographyTextMaxLines.
ELLIPSIS_MODAL_MULTILINE_HEAD = 3Header ellipsis mode, that is, the ellipsis appears at the beginning of a line. This enumerated value is valid when the maximum number of text lines is set to any value by calling OH_Drawing_SetTypographyTextMaxLines.
Since: 24
ELLIPSIS_MODAL_MULTILINE_MIDDLE = 4Middle ellipsis mode, that is, the ellipsis appears in the middle of a line. This enumerated value is valid when the maximum number of text lines is set to any value by calling OH_Drawing_SetTypographyTextMaxLines.
Since: 24

OH_Drawing_BreakStrategy

enum OH_Drawing_BreakStrategy

Description

Enumerates the text break strategies.

Since: 11

ValueDescription
BREAK_STRATEGY_GREEDY = 0Each line is filled as much as possible during line break.
BREAK_STRATEGY_HIGH_QUALITY = 1Text continuity is preferentially considered during line break.
BREAK_STRATEGY_BALANCED = 2Line breaks are performed at the word boundary.

OH_Drawing_WordBreakType

enum OH_Drawing_WordBreakType

Description

Enumerates the word break types.

Since: 11

ValueDescription
WORD_BREAK_TYPE_NORMAL = 0Normal mode.
WORD_BREAK_TYPE_BREAK_ALL = 1Breaks the words at any character to prevent overflow.
WORD_BREAK_TYPE_BREAK_WORD = 2Breaks the words at arbitrary points to prevent overflow.
WORD_BREAK_TYPE_BREAK_HYPHEN = 3Uses a hyphen (-) to break a word at the end of each line. If adding a hyphen is not possible, it will behave the same as WORD_BREAK_TYPE_BREAK_WORD.
Since: 18

OH_Drawing_RectHeightStyle

enum OH_Drawing_RectHeightStyle

Description

Enumerates the rectangle height styles.

Since: 11

ValueDescription
RECT_HEIGHT_STYLE_TIGHTTight style.
RECT_HEIGHT_STYLE_MAXMaximum style.
RECT_HEIGHT_STYLE_INCLUDELINESPACEMIDDLEMiddle style that includes the line spacing.
RECT_HEIGHT_STYLE_INCLUDELINESPACETOPTop style that includes the line spacing.
RECT_HEIGHT_STYLE_INCLUDELINESPACEBOTTOMBottom style that includes the line spacing.
RECT_HEIGHT_STYLE_STRUCTStructure style.

OH_Drawing_RectWidthStyle

enum OH_Drawing_RectWidthStyle

Description

Enumerates the rectangle width styles.

Since: 11

ValueDescription
RECT_WIDTH_STYLE_TIGHTTight style.
RECT_WIDTH_STYLE_MAXMaximum style.

OH_Drawing_TextBadgeType

enum OH_Drawing_TextBadgeType

Description

Enumerates the text badge styles.

Since: 20

ValueDescription
TEXT_BADGE_NONEDisables the superscript and subscript.
TEXT_SUPERSCRIPTEnables the superscript.
TEXT_SUBSCRIPTEnables the subscript.

OH_Drawing_FontConfigInfoErrorCode

enum OH_Drawing_FontConfigInfoErrorCode

Description

Enumerates the error codes that may be used during the obtaining of system font configurations.

Since: 12

ValueDescription
SUCCESS_FONT_CONFIG_INFO = 0Operation successful.
ERROR_FONT_CONFIG_INFO_UNKNOWN = 1Unknown error.
ERROR_FONT_CONFIG_INFO_PARSE_FILE = 2Failed to parse the system configuration file.
ERROR_FONT_CONFIG_INFO_ALLOC_MEMORY = 3Memory allocation fails.
ERROR_FONT_CONFIG_INFO_COPY_STRING_DATA = 4Failed to copy the string data.

OH_Drawing_FontWidth

enum OH_Drawing_FontWidth

Description

Enumerates the font widths.

Since: 12

ValueDescription
FONT_WIDTH_ULTRA_CONDENSED = 1Ultra condensed font.
FONT_WIDTH_EXTRA_CONDENSED = 2Extra condensed font.
FONT_WIDTH_CONDENSED = 3Condensed font.
FONT_WIDTH_SEMI_CONDENSED = 4Semi-condensed font.
FONT_WIDTH_NORMAL = 5Normal font.
FONT_WIDTH_SEMI_EXPANDED = 6Semi-expanded font.
FONT_WIDTH_EXPANDED = 7Expanded font.
FONT_WIDTH_EXTRA_EXPANDED = 8Extra expanded font.
FONT_WIDTH_ULTRA_EXPANDED = 9Ultra expanded font.

OH_Drawing_TextHeightBehavior

enum OH_Drawing_TextHeightBehavior

Description

Enumerates the text height modifier patterns.

Since: 12

ValueDescription
TEXT_HEIGHT_ALL = 0x0Enables the height set by calling OH_Drawing_SetTextStyleFontHeight for the top of the first line and the bottom of the last line in a paragraph.
TEXT_HEIGHT_DISABLE_FIRST_ASCENT = 0x1Disables the height set by calling OH_Drawing_SetTextStyleFontHeight for the top of the first line in a paragraph.
TEXT_HEIGHT_DISABLE_LAST_ASCENT = 0x2Disables the height set by calling OH_Drawing_SetTextStyleFontHeight for the bottom of the last line in a paragraph.
TEXT_HEIGHT_DISABLE_ALL = 0x1 |0x2Disables the height set by calling OH_Drawing_SetTextStyleFontHeight for both the top of the first line and the bottom of the last line in a paragraph.

OH_Drawing_TextStyleType

enum OH_Drawing_TextStyleType

Description

Enumerates the text style types.

Since: 12

ValueDescription
TEXT_STYLE_NONENo text style.
TEXT_STYLE_ALL_ATTRIBUTESAll text styles.
TEXT_STYLE_FONTFont style.
TEXT_STYLE_FOREGROUNDText foreground style.
TEXT_STYLE_BACKGROUNDText background style.
TEXT_STYLE_SHADOWText shadow style.
TEXT_STYLE_DECORATIONSText decoration style.
TEXT_STYLE_LETTER_SPACINGText letter spacing style.
TEXT_STYLE_WORD_SPACINGText word spacing style.

OH_Drawing_LineHeightStyle

enum OH_Drawing_LineHeightStyle

Description

Enumerates the scaling base styles of the line height. The default style is TEXT_LINE_HEIGHT_BY_FONT_SIZE.

Since: 21

ValueDescription
TEXT_LINE_HEIGHT_BY_FONT_SIZE = 0Uses the font size as the scaling base.
Formula for calculating the line height: FontSize x FontHeight.
FontSize can be obtained from the OH_Drawing_TextStyleGetFontSize API.
FontHeight can be obtained from the OH_Drawing_TextStyleGetFontHeight API.
TEXT_LINE_HEIGHT_BY_FONT_HEIGHT = 1Uses the font height as the scaling base.
Formula for calculating the line height: font height x FontHeight.
The font height is obtained after the text is shaped using the font file.
FontHeight can be obtained from the OH_Drawing_TextStyleGetFontHeight API.

OH_Drawing_TextStyleAttributeId

enum OH_Drawing_TextStyleAttributeId

Description

Enumerates the text style attributes.

Since: 21

ValueDescription
TEXT_STYLE_ATTR_D_LINE_HEIGHT_MAXIMUM = 0Maximum line height.
If line height scaling is enabled, the maximum line height takes effect only when FontHeight (which can be obtained from OH_Drawing_TextStyleGetFontHeight) is greater than 0.
The value is the positive part of a single-precision floating point number. By default, it equals the maximum possible value for such a number.
TEXT_STYLE_ATTR_D_LINE_HEIGHT_MINIMUM = 1Minimum line height.
If line height scaling is enabled, the minimum line height takes effect only when FontHeight (which can be obtained from OH_Drawing_TextStyleGetFontHeight) is greater than 0.
The value is the non-negative part of a single-precision floating point number. The default value is 0.
TEXT_STYLE_ATTR_I_LINE_HEIGHT_STYLE = 2Scaling base style of the line height. For details, see OH_Drawing_LineHeightStyle.
TEXT_STYLE_ATTR_I_FONT_WIDTH = 3Font width.
TEXT_STYLE_ATTR_I_FONT_EDGING = 4Font edge processing mode. Anti-aliasing is used by default. For details about how to process font edges, see OH_Drawing_FontEdging.
Since: 24

OH_Drawing_TypographyStyleAttributeId

enum OH_Drawing_TypographyStyleAttributeId

Description

Enumerates the typography style attributes.
For the common attributes of the typography styles and text styles, you are advised to use the text style attributes, which can be obtained from OH_Drawing_TextStyleAttributeId.

Since: 21

ValueDescription
TYPOGRAPHY_STYLE_ATTR_D_LINE_HEIGHT_MAXIMUM = 0Maximum line height.
If line height scaling is enabled, the maximum line height takes effect only when FontHeight (which can be obtained from OH_Drawing_TextStyleGetFontHeight) is greater than 0.
The value is the positive part of a single-precision floating point number.
TYPOGRAPHY_STYLE_ATTR_D_LINE_HEIGHT_MINIMUM = 1Minimum line height.
If line height scaling is enabled, the minimum line height takes effect only when FontHeight (which can be obtained from OH_Drawing_TextStyleGetFontHeight) is greater than 0.
The value is the non-negative part of a single-precision floating point number. The default value is 0.
TYPOGRAPHY_STYLE_ATTR_D_LINE_SPACING = 2Interline spacing.
lineSpacing is not restricted by the maximum and minimum line heights.
By default, line spacing is added to the last line.
You can set textHeightBehavior to DISABLE_LAST_ASCENT in OH_Drawing_TypographyTextSetHeightBehavior to disable the line spacing of the last line.
The default value is 0.
TYPOGRAPHY_STYLE_ATTR_I_LINE_HEIGHT_STYLE = 3Scaling base style of the line height. For details, see OH_Drawing_LineHeightStyle.
TYPOGRAPHY_STYLE_ATTR_I_FONT_WIDTH = 4Font width.
TYPOGRAPHY_STYLE_ATTR_B_COMPRESS_HEAD_PUNCTUATION = 5Sets whether to use punctuation compression at the beginning of a line in text layout.
NOTE
1. The font file must support the ss08 feature in OH_Drawing_FontFeature. Otherwise, compression cannot be performed.
2. Only the punctuations within the punctuation compression range at the beginning of a line are in the scope of this feature.
Since: 23
TYPOGRAPHY_STYLE_ATTR_B_INCLUDE_FONT_PADDING = 6Sets whether to enable the built-in padding of the font during text typography.
Since: 23
TYPOGRAPHY_STYLE_ATTR_B_FALLBACK_LINE_SPACING = 7Sets whether to enable the line spacing rollback mechanism during text typography.
Since: 23
TYPOGRAPHY_STYLE_ATTR_I_ELLIPSIS_MODAL = 8Ellipsis style. For details about the ellipsis style, see OH_Drawing_EllipsisModal.
Since: 24
TYPOGRAPHY_STYLE_ATTR_DA_LINE_HEAD_INDENT = 9First-line indent array.
All values in the indent array must be greater than or equal to 0. Each element in the array represents the indentation value of a single line. If the actual number of text lines exceeds the length of the indent array, the last value of the array is applied to the extra lines.
Since: 26.0.0
TYPOGRAPHY_STYLE_ATTR_D_FIRST_LINE_HEAD_INDENT = 10First-line indent of a paragraph. The indent value must be greater than or equal to 0.
Since: 26.0.0
TYPOGRAPHY_STYLE_ATTR_DA_LINE_TAIL_INDENT = 11Last-line indent array.
All values in the indent array must be greater than or equal to 0. Each element in the array represents the indentation value of a single line. If the actual number of text lines exceeds the length of the indent array, the last value of the array is applied to the extra lines.
Since: 26.0.0

Function Description

OH_Drawing_CreateTypographyStyle()

OH_Drawing_TypographyStyle* OH_Drawing_CreateTypographyStyle(void)

Description

Creates an OH_Drawing_TypographyStyle object. Release this pointer by calling OH_Drawing_DestroyTypographyStyle when this object is no longer needed.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 8

Returns

TypeDescription
OH_Drawing_TypographyStyle*Pointer to the created OH_Drawing_TypographyStyle object.

OH_Drawing_DestroyTypographyStyle()

void OH_Drawing_DestroyTypographyStyle(OH_Drawing_TypographyStyle* style)

Description

Destroys an OH_Drawing_TypographyStyle object and reclaims the memory occupied by the object.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 8

Parameters

NameDescription
OH_Drawing_TypographyStyle* stylePointer to the OH_Drawing_TypographyStyle object, which is obtained from OH_Drawing_CreateTypographyStyle.

OH_Drawing_SetTypographyTextDirection()

void OH_Drawing_SetTypographyTextDirection(OH_Drawing_TypographyStyle* style, int direction)

Description

Sets the text direction in a typography style.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 8

Parameters

NameDescription
OH_Drawing_TypographyStyle* stylePointer to the OH_Drawing_TypographyStyle object, which is obtained from OH_Drawing_CreateTypographyStyle.
int directionText direction. For details about the available options, see OH_Drawing_TextDirection.

OH_Drawing_SetTypographyTextAlign()

void OH_Drawing_SetTypographyTextAlign(OH_Drawing_TypographyStyle* style, int align)

Description

Text alignment mode.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 8

Parameters

NameDescription
OH_Drawing_TypographyStyle* stylePointer to the OH_Drawing_TypographyStyle object, which is obtained from OH_Drawing_CreateTypographyStyle.
int alignText alignment mode. For details about the available options, see OH_Drawing_TextAlign.

OH_Drawing_TypographyGetEffectiveAlignment()

int OH_Drawing_TypographyGetEffectiveAlignment(OH_Drawing_TypographyStyle* style)

Description

Obtains the text alignment mode.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Deprecated from: 18

Replaced by: OH_Drawing_TypographyStyleGetEffectiveAlignment

Parameters

NameDescription
OH_Drawing_TypographyStyle* stylePointer to the OH_Drawing_TypographyStyle object, which is obtained from OH_Drawing_CreateTypographyStyle.

Returns

TypeDescription
intText alignment mode.

OH_Drawing_SetTypographyTextMaxLines()

void OH_Drawing_SetTypographyTextMaxLines(OH_Drawing_TypographyStyle* style, int lineNumber)

Description

Sets the maximum number of lines in the text.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 8

Parameters

NameDescription
OH_Drawing_TypographyStyle* stylePointer to the OH_Drawing_TypographyStyle object, which is obtained from OH_Drawing_CreateTypographyStyle.
int lineNumberMaximum number of lines.

OH_Drawing_CreateTextStyle()

OH_Drawing_TextStyle* OH_Drawing_CreateTextStyle(void)

Description

Creates an OH_Drawing_TextStyle object.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 8

Returns

TypeDescription
OH_Drawing_TextStyle*Pointer to the created OH_Drawing_TextStyle object.

OH_Drawing_TypographyGetTextStyle()

OH_Drawing_TextStyle* OH_Drawing_TypographyGetTextStyle(OH_Drawing_TypographyStyle* style)

Description

Obtains the default text style of a typography style.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_TypographyStyle* stylePointer to the OH_Drawing_TypographyStyle object, which is obtained from OH_Drawing_CreateTypographyStyle.

Returns

TypeDescription
OH_Drawing_TextStyle*Pointer to the OH_Drawing_TextStyle object. Release this pointer by calling OH_Drawing_DestroyTextStyle when this object is no longer needed.

OH_Drawing_DestroyTextStyle()

void OH_Drawing_DestroyTextStyle(OH_Drawing_TextStyle* style)

Description

Destroys an OH_Drawing_TextStyle object and reclaims the memory occupied by the object.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 8

Parameters

NameDescription
OH_Drawing_TextStyle* stylePointer to the OH_Drawing_TextStyle object, which is obtained from OH_Drawing_CreateTextStyle.

OH_Drawing_SetTextStyleColor()

void OH_Drawing_SetTextStyleColor(OH_Drawing_TextStyle* style, uint32_t color)

Description

Sets the color for a text style.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 8

Parameters

NameDescription
OH_Drawing_TextStyle* stylePointer to the OH_Drawing_TextStyle object, which is obtained from OH_Drawing_CreateTextStyle.
uint32_t colorColor.

OH_Drawing_SetTextStyleFontSize()

void OH_Drawing_SetTextStyleFontSize(OH_Drawing_TextStyle* style, double fontSize)

Description

Sets the font size for a text style.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 8

Parameters

NameDescription
OH_Drawing_TextStyle* stylePointer to the OH_Drawing_TextStyle object, which is obtained from OH_Drawing_CreateTextStyle.
double fontSizeFont size to set.

OH_Drawing_SetTextStyleFontWeight()

void OH_Drawing_SetTextStyleFontWeight(OH_Drawing_TextStyle* style, int fontWeight)

Description

Sets the font weight for a text style. Currently, only the default system font supports font weight adjustment. For other fonts, if the weight is less than semi-bold, there is no variation in stroke thickness. If the weight is greater than or equal to semi-bold, it might result in a fake bold effect.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 8

Parameters

NameDescription
OH_Drawing_TextStyle* stylePointer to the OH_Drawing_TextStyle object, which is obtained from OH_Drawing_CreateTextStyle.
int fontWeightFont weight.
For details about the available options, see OH_Drawing_FontWeight.

OH_Drawing_SetTextStyleBaseLine()

void OH_Drawing_SetTextStyleBaseLine(OH_Drawing_TextStyle* style, int baseline)

Description

Sets the baseline for a text style.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 8

Parameters

NameDescription
OH_Drawing_TextStyle* stylePointer to the OH_Drawing_TextStyle object, which is obtained from OH_Drawing_CreateTextStyle.
int baselineText baseline. For details about the available options, see OH_Drawing_TextBaseline.

OH_Drawing_SetTextStyleDecoration()

void OH_Drawing_SetTextStyleDecoration(OH_Drawing_TextStyle* style, int decoration)

Description

Sets the decoration for a text style. Only one decoration can be set. To add multiple decorations, use OH_Drawing_AddTextStyleDecoration.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 8

Parameters

NameDescription
OH_Drawing_TextStyle* stylePointer to the OH_Drawing_TextStyle object, which is obtained from OH_Drawing_CreateTextStyle.
int decorationText decoration. For details about the available options, see OH_Drawing_TextDecoration.

OH_Drawing_AddTextStyleDecoration()

void OH_Drawing_AddTextStyleDecoration(OH_Drawing_TextStyle* style, int decoration)

Description

Adds the decoration for a text style. Multiple decoration lines can be displayed.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 18

Parameters

NameDescription
OH_Drawing_TextStyle* stylePointer to the OH_Drawing_TextStyle object, which is obtained from OH_Drawing_CreateTextStyle.
int decorationDecoration to add. The value 1 means to add an underline, 2 means to add an overline, and 4 means to add a strikethrough. You can add various decoration lines at a time via bitwise OR operations.
If a decoration style that is not in the OH_Drawing_TextDecoration enumeration is set, the original decoration is retained.

OH_Drawing_RemoveTextStyleDecoration()

void OH_Drawing_RemoveTextStyleDecoration(OH_Drawing_TextStyle* style, int decoration)

Description

Removes the decoration for a text style.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 18

Parameters

NameDescription
OH_Drawing_TextStyle* stylePointer to the OH_Drawing_TextStyle object, which is obtained from OH_Drawing_CreateTextStyle.
int decorationDecoration to remove. The value 1 means to remove an underline, 2 means to remove an overline, and 4 means to remove a strikethrough. You can remove various text decorations at a time via bitwise OR operations.
If a decoration style that is not in the OH_Drawing_TextDecoration enumeration is set, the original decoration is retained.

OH_Drawing_SetTextStyleDecorationColor()

void OH_Drawing_SetTextStyleDecorationColor(OH_Drawing_TextStyle* style, uint32_t color)

Description

Sets the decoration color for a text style. If this API is not called or color is set to 0, the decoration color follows the text color.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 8

Parameters

NameDescription
OH_Drawing_TextStyle* stylePointer to the OH_Drawing_TextStyle object, which is obtained from OH_Drawing_CreateTextStyle.
uint32_t colorColor.

OH_Drawing_SetTextStyleFontHeight()

void OH_Drawing_SetTextStyleFontHeight(OH_Drawing_TextStyle* style, double fontHeight)

Description

Sets the line height based on the multiple of the font size.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 8

Parameters

NameDescription
OH_Drawing_TextStyle* stylePointer to the OH_Drawing_TextStyle object, which is obtained from OH_Drawing_CreateTextStyle.
double fontHeightMultiple of the font size.

OH_Drawing_SetTextStyleFontFamilies()

void OH_Drawing_SetTextStyleFontFamilies(OH_Drawing_TextStyle* style,int fontFamiliesNumber, const char* fontFamilies[])

Description

Sets the font families for a text style.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 8

Parameters

NameDescription
OH_Drawing_TextStyle* stylePointer to the OH_Drawing_TextStyle object, which is obtained from OH_Drawing_CreateTextStyle.
int fontFamiliesNumberNumber of font families. A negative number is not allowed.
fontFamiliesPointer to the font families.

OH_Drawing_SetTextStyleFontStyle()

void OH_Drawing_SetTextStyleFontStyle(OH_Drawing_TextStyle* style, int fontStyle)

Description

Sets the font style for a text style.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 8

Parameters

NameDescription
OH_Drawing_TextStyle* stylePointer to the OH_Drawing_TextStyle object, which is obtained from OH_Drawing_CreateTextStyle.
int fontStyleFont style. For details about the available options, see OH_Drawing_FontStyle.

OH_Drawing_SetTextStyleLocale()

void OH_Drawing_SetTextStyleLocale(OH_Drawing_TextStyle* style, const char* locale)

Description

Sets the locale for a text style.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 8

Parameters

NameDescription
OH_Drawing_TextStyle* stylePointer to the OH_Drawing_TextStyle object, which is obtained from OH_Drawing_CreateTextStyle.
const char* localePointer to the locale. For example, 'en' indicates English, 'zh-Hans' indicates Simplified Chinese, and 'zh-Hant' indicates Traditional Chinese. If it is not specified, the default locale is 'zh-Hans'.

OH_Drawing_SetTextStyleForegroundBrush()

void OH_Drawing_SetTextStyleForegroundBrush(OH_Drawing_TextStyle* style, OH_Drawing_Brush* foregroundBrush)

Description

Sets the foreground brush for a text style.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_TextStyle* stylePointer to the OH_Drawing_TextStyle object, which is obtained from OH_Drawing_CreateTextStyle.
OH_Drawing_Brush* foregroundBrushPointer to the OH_Drawing_Brush object, which is obtained from OH_Drawing_BrushCreate.

OH_Drawing_TextStyleGetForegroundBrush()

void OH_Drawing_TextStyleGetForegroundBrush(OH_Drawing_TextStyle* style, OH_Drawing_Brush* foregroundBrush)

Description

Obtains the foreground brush of a text style.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_TextStyle* stylePointer to the OH_Drawing_TextStyle object, which is obtained from OH_Drawing_CreateTextStyle.
OH_Drawing_Brush* foregroundBrushPointer to the OH_Drawing_Brush object, which is obtained from OH_Drawing_BrushCreate.

OH_Drawing_SetTextStyleForegroundPen()

void OH_Drawing_SetTextStyleForegroundPen(OH_Drawing_TextStyle* style, OH_Drawing_Pen* foregroundPen)

Description

Sets the foreground pen for a text style.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_TextStyle* stylePointer to the OH_Drawing_TextStyle object, which is obtained from OH_Drawing_CreateTextStyle.
OH_Drawing_Pen* foregroundPenPointer to the OH_Drawing_Pen object, which is obtained from OH_Drawing_PenCreate.

OH_Drawing_TextStyleGetForegroundPen()

void OH_Drawing_TextStyleGetForegroundPen(OH_Drawing_TextStyle* style, OH_Drawing_Pen* foregroundPen)

Description

Obtains the foreground pen of a text style.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_TextStyle* stylePointer to the OH_Drawing_TextStyle object, which is obtained from OH_Drawing_CreateTextStyle.
OH_Drawing_Pen* foregroundPenPointer to the OH_Drawing_Pen object, which is obtained from OH_Drawing_PenCreate.

OH_Drawing_SetTextStyleBackgroundBrush()

void OH_Drawing_SetTextStyleBackgroundBrush(OH_Drawing_TextStyle* style, OH_Drawing_Brush* backgroundBrush)

Description

Sets the background brush for a text style.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_TextStyle* stylePointer to the OH_Drawing_TextStyle object, which is obtained from OH_Drawing_CreateTextStyle.
OH_Drawing_Brush* backgroundBrushPointer to the OH_Drawing_Brush object, which is obtained from OH_Drawing_BrushCreate.

OH_Drawing_TextStyleGetBackgroundBrush()

void OH_Drawing_TextStyleGetBackgroundBrush(OH_Drawing_TextStyle* style, OH_Drawing_Brush* backgroundBrush)

Description

Obtains the background brush of a text style.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_TextStyle* stylePointer to the OH_Drawing_TextStyle object, which is obtained from OH_Drawing_CreateTextStyle.
OH_Drawing_Brush* backgroundBrushPointer to the OH_Drawing_Brush object, which is obtained from OH_Drawing_BrushCreate.

OH_Drawing_SetTextStyleBackgroundPen()

void OH_Drawing_SetTextStyleBackgroundPen(OH_Drawing_TextStyle* style, OH_Drawing_Pen* backgroundPen)

Description

Sets the background pen for a text style.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_TextStyle* stylePointer to the OH_Drawing_TextStyle object, which is obtained from OH_Drawing_CreateTextStyle.
OH_Drawing_Pen* backgroundPenPointer to the OH_Drawing_Pen object, which is obtained from OH_Drawing_PenCreate.

OH_Drawing_TextStyleGetBackgroundPen()

void OH_Drawing_TextStyleGetBackgroundPen(OH_Drawing_TextStyle* style, OH_Drawing_Pen* backgroundPen)

Description

Obtains the background pen of a text style.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_TextStyle* stylePointer to the OH_Drawing_TextStyle object, which is obtained from OH_Drawing_CreateTextStyle.
OH_Drawing_Pen* backgroundPenPointer to the OH_Drawing_Pen object, which is obtained from OH_Drawing_PenCreate.

OH_Drawing_CreateTypographyHandler()

OH_Drawing_TypographyCreate* OH_Drawing_CreateTypographyHandler(OH_Drawing_TypographyStyle* style,OH_Drawing_FontCollection* fontCollection)

Description

Creates an OH_Drawing_TypographyCreate object. Release this pointer by calling OH_Drawing_DestroyTypographyHandler when this object is no longer needed. You are advised to use the OH_Drawing_CreateSharedFontCollection function to create an OH_Drawing_FontCollection object.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 8

Parameters

NameDescription
OH_Drawing_TypographyStyle* stylePointer to the OH_Drawing_TypographyStyle object, which is obtained from OH_Drawing_CreateTypographyStyle.
OH_Drawing_FontCollection* fontCollectionPointer to the OH_Drawing_FontCollection object, which is obtained from OH_Drawing_CreateFontCollection.

Returns

TypeDescription
OH_Drawing_TypographyCreate*Pointer to the OH_Drawing_TypographyCreate object created.

OH_Drawing_DestroyTypographyHandler()

void OH_Drawing_DestroyTypographyHandler(OH_Drawing_TypographyCreate* handler)

Description

Destroys an OH_Drawing_TypographyCreate object and reclaims the memory occupied by the object.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 8

Parameters

NameDescription
OH_Drawing_TypographyCreate* handlerPointer to the OH_Drawing_TypographyCreate object, which is obtained from OH_Drawing_CreateTypographyHandler.

OH_Drawing_TypographyHandlerPushTextStyle()

void OH_Drawing_TypographyHandlerPushTextStyle(OH_Drawing_TypographyCreate* handler, OH_Drawing_TextStyle* style)

Description

Pushes a text style into the text style stack. Any text added afterward will use the style currently on top of the stack.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 8

Parameters

NameDescription
OH_Drawing_TypographyCreate* handlerPointer to the OH_Drawing_TypographyCreate object, which is obtained from OH_Drawing_CreateTypographyHandler.
OH_Drawing_TextStyle* stylePointer to the OH_Drawing_TextStyle object, which is obtained from OH_Drawing_CreateTextStyle.

OH_Drawing_TypographyHandlerAddText()

void OH_Drawing_TypographyHandlerAddText(OH_Drawing_TypographyCreate* handler, const char* text)

Description

Adds text.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 8

Parameters

NameDescription
OH_Drawing_TypographyCreate* handlerPointer to the OH_Drawing_TypographyCreate object, which is obtained from OH_Drawing_CreateTypographyHandler.
const char* textPointer to the text content.

OH_Drawing_TypographyHandlerPopTextStyle()

void OH_Drawing_TypographyHandlerPopTextStyle(OH_Drawing_TypographyCreate* handler)

Description

Pops the top text style out of the text style stack.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 8

Parameters

NameDescription
OH_Drawing_TypographyCreate* handlerPointer to the OH_Drawing_TypographyCreate object, which is obtained from OH_Drawing_CreateTypographyHandler.

OH_Drawing_CreateTypography()

OH_Drawing_Typography* OH_Drawing_CreateTypography(OH_Drawing_TypographyCreate* handler)

Description

Creates an OH_Drawing_Typography object. Release this pointer by calling OH_Drawing_DestroyTypography when this object is no longer needed.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 8

Parameters

NameDescription
OH_Drawing_TypographyCreate* handlerPointer to the OH_Drawing_TypographyCreate object, which is obtained from OH_Drawing_CreateTypographyHandler.

Returns

TypeDescription
OH_Drawing_Typography*Pointer to the OH_Drawing_Typography object created.

OH_Drawing_DestroyTypography()

void OH_Drawing_DestroyTypography(OH_Drawing_Typography* typography)

Description

Destroys an OH_Drawing_Typography object and reclaims the memory occupied by the object.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 8

Parameters

NameDescription
OH_Drawing_Typography* typographyPointer to the OH_Drawing_Typography object, which is obtained from OH_Drawing_CreateTypography.

OH_Drawing_TypographyLayout()

void OH_Drawing_TypographyLayout(OH_Drawing_Typography* typography, double maxWidth)

Description

Lays out the typography.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 8

Parameters

NameDescription
OH_Drawing_Typography* typographyPointer to the OH_Drawing_Typography object, which is obtained from OH_Drawing_CreateTypography.
double maxWidthMaximum text width.

OH_Drawing_TypographyPaint()

void OH_Drawing_TypographyPaint(OH_Drawing_Typography* typography, OH_Drawing_Canvas* canvas,double positionX, double positionY)

Description

Draws text from the upper left corner at a specified position. This function must be called after OH_Drawing_TypographyLayout is called and applied.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 8

Parameters

NameDescription
OH_Drawing_Typography* typographyPointer to the OH_Drawing_Typography object, which is obtained from OH_Drawing_CreateTypography.
OH_Drawing_Canvas* canvasPointer to the OH_Drawing_Canvas object, which is obtained from OH_Drawing_CanvasCreate.
double positionXX coordinate.
double positionYY coordinate.

OH_Drawing_TypographyPaintOnPath()

void OH_Drawing_TypographyPaintOnPath(OH_Drawing_Typography* typography, OH_Drawing_Canvas* canvas,OH_Drawing_Path* path, double hOffset, double vOffset)

Description

Draws text along a path. To prevent text overlap caused by the text width exceeding the layout width, you are advised to use OH_Drawing_SetTypographyTextMaxLines to limit the text to a single line.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_Typography* typographyPointer to the OH_Drawing_Typography object, which is obtained from OH_Drawing_CreateTypography.
OH_Drawing_Canvas* canvasPointer to the OH_Drawing_Canvas object, which is obtained from OH_Drawing_CanvasCreate.
OH_Drawing_Path* pathPointer to the OH_Drawing_Path object, which is obtained from OH_Drawing_PathCreate.
double hOffsetHorizontal offset of the text along the path (X axis). A positive number indicates that the text is moved forward, and a negative number indicates that the text is moved backward.
double vOffsetVertical offset of the text along the path (Y axis). A positive number indicates that the text is moved downward, and a negative number indicates that the text is moved upward.

OH_Drawing_TypographyGetMaxWidth()

double OH_Drawing_TypographyGetMaxWidth(OH_Drawing_Typography* typography)

Description

Obtains the typography width set by the user. This function must be called after OH_Drawing_TypographyLayout is called.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 9

Parameters

NameDescription
OH_Drawing_Typography* typographyPointer to the OH_Drawing_Typography object, which is obtained from OH_Drawing_CreateTypography.

Returns

TypeDescription
doubleMaximum width.

OH_Drawing_TypographyGetHeight()

double OH_Drawing_TypographyGetHeight(OH_Drawing_Typography* typography)

Description

Obtains the overall height of a typography object. This function must be called after OH_Drawing_TypographyLayout is called.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 9

Parameters

NameDescription
OH_Drawing_Typography* typographyPointer to the OH_Drawing_Typography object, which is obtained from OH_Drawing_CreateTypography.

Returns

TypeDescription
doubleHeight.

OH_Drawing_TypographyGetLongestLine()

double OH_Drawing_TypographyGetLongestLine(OH_Drawing_Typography* typography)

Description

Obtains the width of the longest line in a typography object. This function must be called after OH_Drawing_TypographyLayout is called. You are advised to round up the return value. If the text content is empty, 0.0 is returned.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 9

Parameters

NameDescription
OH_Drawing_Typography* typographyPointer to the OH_Drawing_Typography object, which is obtained from OH_Drawing_CreateTypography.

Returns

TypeDescription
doubleWidth of the longest line.

OH_Drawing_TypographyGetLongestLineWithIndent()

double OH_Drawing_TypographyGetLongestLineWithIndent(OH_Drawing_Typography* typography)

Description

Obtains the width of the longest line of a typography object, including its indentation. This function must be called after OH_Drawing_TypographyLayout is called. You are advised to round up the return value. If the text content is empty, 0.0 is returned.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 13

Parameters

NameDescription
OH_Drawing_Typography* typographyPointer to the OH_Drawing_Typography object, which is obtained from OH_Drawing_CreateTypography.

Returns

TypeDescription
doubleWidth of the longest line, including its indentation, in px.

OH_Drawing_TypographyGetMinIntrinsicWidth()

double OH_Drawing_TypographyGetMinIntrinsicWidth(OH_Drawing_Typography* typography)

Description

Obtains the minimum intrinsic width in a typography object. This function must be called after OH_Drawing_TypographyLayout is called.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 9

Parameters

NameDescription
OH_Drawing_Typography* typographyPointer to the OH_Drawing_Typography object, which is obtained from OH_Drawing_CreateTypography.

Returns

TypeDescription
doubleMinimum intrinsic width.

OH_Drawing_TypographyGetMaxIntrinsicWidth()

double OH_Drawing_TypographyGetMaxIntrinsicWidth(OH_Drawing_Typography* typography)

Description

Obtains the maximum intrinsic width in a typography object. This function must be called after OH_Drawing_TypographyLayout is called.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 9

Parameters

NameDescription
OH_Drawing_Typography* typographyPointer to the OH_Drawing_Typography object, which is obtained from OH_Drawing_CreateTypography.

Returns

TypeDescription
doubleMaximum intrinsic width.

OH_Drawing_TypographyGetAlphabeticBaseline()

double OH_Drawing_TypographyGetAlphabeticBaseline(OH_Drawing_Typography* typography)

Description

Obtains the alphabetic baseline in a typography object.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 9

Parameters

NameDescription
OH_Drawing_Typography* typographyPointer to the OH_Drawing_Typography object, which is obtained from OH_Drawing_CreateTypography.

Returns

TypeDescription
doubleAlphabetic baseline.

OH_Drawing_TypographyGetIdeographicBaseline()

double OH_Drawing_TypographyGetIdeographicBaseline(OH_Drawing_Typography* typography)

Description

Obtains the ideographic baseline in a typography object.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 9

Parameters

NameDescription
OH_Drawing_Typography* typographyPointer to the OH_Drawing_Typography object, which is obtained from OH_Drawing_CreateTypography.

Returns

TypeDescription
doubleIdeographic baseline.

OH_Drawing_TypographyHandlerAddPlaceholder()

void OH_Drawing_TypographyHandlerAddPlaceholder(OH_Drawing_TypographyCreate* handler,OH_Drawing_PlaceholderSpan* span)

Description

Adds a placeholder.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 11

Parameters

NameDescription
OH_Drawing_TypographyCreate* handlerPointer to the OH_Drawing_TypographyCreate object, which is obtained from OH_Drawing_CreateTypographyHandler.
OH_Drawing_PlaceholderSpan* spanPointer to the OH_Drawing_PlaceholderSpan object.

OH_Drawing_TypographyDidExceedMaxLines()

bool OH_Drawing_TypographyDidExceedMaxLines(OH_Drawing_Typography* typography)

Description

Checks whether the text in the typography object exceeds the line limit. This function must be called after OH_Drawing_TypographyLayout is called. It returns false if the line limit is not set using OH_Drawing_SetTypographyTextMaxLines.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 11

Parameters

NameDescription
OH_Drawing_Typography* typographyPointer to the OH_Drawing_Typography object, which is obtained from OH_Drawing_CreateTypography.

Returns

TypeDescription
boolReturns true if the maximum number of lines is exceeded; returns false otherwise.

OH_Drawing_TypographyGetRectsForRange()

OH_Drawing_TextBox* OH_Drawing_TypographyGetRectsForRange(OH_Drawing_Typography* typography,size_t start, size_t end, OH_Drawing_RectHeightStyle heightStyle, OH_Drawing_RectWidthStyle widthStyle)

Description

Obtains text boxes in a given range of a typography object. This function must be called after OH_Drawing_TypographyLayout is called. Release this pointer by calling OH_Drawing_TypographyDestroyTextBox when this object is no longer needed.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 11

Parameters

NameDescription
OH_Drawing_Typography* typographyPointer to the OH_Drawing_Typography object, which is obtained from OH_Drawing_CreateTypography.
size_t startStart position.
size_t endEnd position.
OH_Drawing_RectHeightStyle heightStyleHeight style. For details about the available options, see OH_Drawing_RectHeightStyle.
OH_Drawing_RectWidthStyle widthStyleWidth style. For details about the available options, see OH_Drawing_RectWidthStyle.

Returns

TypeDescription
OH_Drawing_TextBox*Text box in the specified range. For details, see OH_Drawing_TextBox.

OH_Drawing_TypographyGetRectsForPlaceholders()

OH_Drawing_TextBox* OH_Drawing_TypographyGetRectsForPlaceholders(OH_Drawing_Typography* typography)

Description

Obtains text boxes for placeholders in a typography object. This function must be called after OH_Drawing_TypographyLayout is called. Release this pointer by calling OH_Drawing_TypographyDestroyTextBox when this object is no longer needed.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 11

Parameters

NameDescription
OH_Drawing_Typography* typographyPointer to the OH_Drawing_Typography object, which is obtained from OH_Drawing_CreateTypography.

Returns

TypeDescription
OH_Drawing_TextBox*Placeholder text box. The return type is OH_Drawing_TextBox.

OH_Drawing_GetLeftFromTextBox()

float OH_Drawing_GetLeftFromTextBox(OH_Drawing_TextBox* textbox, int index)

Description

Obtains the left position of a text box.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 11

Parameters

NameDescription
OH_Drawing_TextBox* textboxPointer to the OH_Drawing_TextBox object, which is obtained from OH_Drawing_TypographyGetRectsForRange or OH_Drawing_TypographyGetRectsForPlaceholders.
int indexIndex of the text box.

Returns

TypeDescription
floatLeft position.

OH_Drawing_GetRightFromTextBox()

float OH_Drawing_GetRightFromTextBox(OH_Drawing_TextBox* textbox, int index)

Description

Obtains the right position of a text box.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 11

Parameters

NameDescription
OH_Drawing_TextBox* textboxPointer to the OH_Drawing_TextBox object, which is obtained from OH_Drawing_TypographyGetRectsForRange or OH_Drawing_TypographyGetRectsForPlaceholders.
int indexIndex of the text box.

Returns

TypeDescription
floatRight position.

OH_Drawing_GetTopFromTextBox()

float OH_Drawing_GetTopFromTextBox(OH_Drawing_TextBox* textbox, int index)

Description

Obtains the top position of a text box.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 11

Parameters

NameDescription
OH_Drawing_TextBox* textboxPointer to the OH_Drawing_TextBox object, which is obtained from OH_Drawing_TypographyGetRectsForRange or OH_Drawing_TypographyGetRectsForPlaceholders.
int indexIndex of the text box.

Returns

TypeDescription
floatTop position.

OH_Drawing_GetBottomFromTextBox()

float OH_Drawing_GetBottomFromTextBox(OH_Drawing_TextBox* textbox, int index)

Description

Obtains the bottom position of a text box.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 11

Parameters

NameDescription
OH_Drawing_TextBox* textboxPointer to the OH_Drawing_TextBox object, which is obtained from OH_Drawing_TypographyGetRectsForRange or OH_Drawing_TypographyGetRectsForPlaceholders.
int indexIndex of the text box.

Returns

TypeDescription
floatBottom position.

OH_Drawing_GetTextDirectionFromTextBox()

int OH_Drawing_GetTextDirectionFromTextBox(OH_Drawing_TextBox* textbox, int index)

Description

Obtains the text direction of a text box.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 11

Parameters

NameDescription
OH_Drawing_TextBox* textboxPointer to the OH_Drawing_TextBox object, which is obtained from OH_Drawing_TypographyGetRectsForRange or OH_Drawing_TypographyGetRectsForPlaceholders.
int indexIndex of the text box.

Returns

TypeDescription
intText direction.

OH_Drawing_GetSizeOfTextBox()

size_t OH_Drawing_GetSizeOfTextBox(OH_Drawing_TextBox* textBox)

Description

Obtains the number of text boxes.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 11

Parameters

NameDescription
OH_Drawing_TextBox* textBoxPointer to the OH_Drawing_TextBox object, which is obtained from OH_Drawing_TypographyGetRectsForRange or OH_Drawing_TypographyGetRectsForPlaceholders.

Returns

TypeDescription
size_tNumber of text boxes.

OH_Drawing_TypographyGetGlyphPositionAtCoordinate()

OH_Drawing_PositionAndAffinity* OH_Drawing_TypographyGetGlyphPositionAtCoordinate(OH_Drawing_Typography* typography,double dx, double dy)

Description

Obtains the position and affinity of the glyph at the given coordinates.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 11

Deprecated from: 18

Replaced by: OH_Drawing_TypographyGetGlyphPositionAtCoordinateWithCluster

Parameters

NameDescription
OH_Drawing_Typography* typographyPointer to the OH_Drawing_Typography object, which is obtained from OH_Drawing_CreateTypography.
double dxX coordinate.
double dyY coordinate.

Returns

TypeDescription
OH_Drawing_PositionAndAffinity*OH_Drawing_PositionAndAffinity struct that holds the position and affinity of the glyph cluster.

OH_Drawing_TypographyGetGlyphPositionAtCoordinateWithCluster()

OH_Drawing_PositionAndAffinity* OH_Drawing_TypographyGetGlyphPositionAtCoordinateWithCluster(OH_Drawing_Typography* typography, double dx, double dy)

Description

Obtains the position and affinity of the glyph cluster to which the glyph at the given coordinates belongs. The glyph cluster is a container that holds one or more glyphs.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 11

Parameters

NameDescription
OH_Drawing_Typography* typographyPointer to the OH_Drawing_Typography object, which is obtained from OH_Drawing_CreateTypography.
double dxX coordinate.
double dyY coordinate.

Returns

TypeDescription
OH_Drawing_PositionAndAffinity*OH_Drawing_PositionAndAffinity struct that holds the position and affinity of the glyph cluster.

OH_Drawing_GetPositionFromPositionAndAffinity()

size_t OH_Drawing_GetPositionFromPositionAndAffinity(OH_Drawing_PositionAndAffinity* positionAndAffinity)

Description

Obtains the position attribute of an OH_Drawing_PositionAndAffinity object.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 11

Parameters

NameDescription
OH_Drawing_PositionAndAffinity* positionAndAffinityPointer to the OH_Drawing_PositionAndAffinity object, which is obtained from OH_Drawing_TypographyGetGlyphPositionAtCoordinate or OH_Drawing_TypographyGetGlyphPositionAtCoordinateWithCluster.

Returns

TypeDescription
size_tPosition attribute.

OH_Drawing_GetAffinityFromPositionAndAffinity()

int OH_Drawing_GetAffinityFromPositionAndAffinity(OH_Drawing_PositionAndAffinity* positionAndAffinity)

Description

Obtains the affinity attribute of an OH_Drawing_PositionAndAffinity object. The affinity determines whether the font is close to the front text or rear text.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 11

Parameters

NameDescription
OH_Drawing_PositionAndAffinity* positionAndAffinityPointer to the OH_Drawing_PositionAndAffinity object, which is obtained from OH_Drawing_TypographyGetGlyphPositionAtCoordinate or OH_Drawing_TypographyGetGlyphPositionAtCoordinateWithCluster.

Returns

TypeDescription
intAffinity attribute.

OH_Drawing_TypographyGetWordBoundary()

OH_Drawing_Range* OH_Drawing_TypographyGetWordBoundary(OH_Drawing_Typography* typography, size_t offset)

Description

Obtains the word boundary in a typography object.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 11

Parameters

NameDescription
OH_Drawing_Typography* typographyPointer to the OH_Drawing_Typography object, which is obtained from OH_Drawing_CreateTypography.
size_t offsetIndex of the word.

Returns

TypeDescription
OH_Drawing_Range*OH_Drawing_Range struct that holds the word boundary.

OH_Drawing_GetStartFromRange()

size_t OH_Drawing_GetStartFromRange(OH_Drawing_Range* range)

Description

Obtains the start position of an OH_Drawing_Range object.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 11

Parameters

NameDescription
OH_Drawing_Range* rangePointer to the OH_Drawing_Range object, which is obtained from OH_Drawing_TypographyGetWordBoundary.

Returns

TypeDescription
size_tStart position.

OH_Drawing_GetEndFromRange()

size_t OH_Drawing_GetEndFromRange(OH_Drawing_Range* range)

Description

Obtains the end position of an OH_Drawing_Range object.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 11

Parameters

NameDescription
OH_Drawing_Range* rangePointer to the OH_Drawing_Range object, which is obtained from OH_Drawing_TypographyGetWordBoundary.

Returns

TypeDescription
size_tEnd position.

OH_Drawing_TypographyGetLineCount()

size_t OH_Drawing_TypographyGetLineCount(OH_Drawing_Typography* typography)

Description

Obtains the number of lines in a typography object. This function must be called after OH_Drawing_TypographyLayout is called.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 11

Parameters

NameDescription
OH_Drawing_Typography* typographyPointer to the OH_Drawing_Typography object, which is obtained from OH_Drawing_CreateTypography.

Returns

TypeDescription
size_tNumber of rows obtained.

OH_Drawing_SetTextStyleDecorationStyle()

void OH_Drawing_SetTextStyleDecorationStyle(OH_Drawing_TextStyle* style, int decorationStyle)

Description

Sets the decoration style for a text style.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 11

Parameters

NameDescription
OH_Drawing_TextStyle* stylePointer to the OH_Drawing_TextStyle object, which is obtained from OH_Drawing_CreateTextStyle.
int decorationStyleText decoration style. For details about the available options, see OH_Drawing_TextDecorationStyle.

OH_Drawing_SetTextStyleDecorationThicknessScale()

void OH_Drawing_SetTextStyleDecorationThicknessScale(OH_Drawing_TextStyle* style, double decorationThicknessScale)

Description

Sets the thickness scale factor for the decoration style of a text style.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 11

Parameters

NameDescription
OH_Drawing_TextStyle* stylePointer to the OH_Drawing_TextStyle object, which is obtained from OH_Drawing_CreateTextStyle.
double decorationThicknessScaleThickness scaling ratio. The default value is 1. If the value is less than or equal to 0, no decoration line is drawn.

OH_Drawing_SetTextStyleLetterSpacing()

void OH_Drawing_SetTextStyleLetterSpacing(OH_Drawing_TextStyle* style, double letterSpacing)

Description

Sets the letter spacing for a text style.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 11

Parameters

NameDescription
OH_Drawing_TextStyle* stylePointer to the OH_Drawing_TextStyle object, which is obtained from OH_Drawing_CreateTextStyle.
double letterSpacingLetter spacing.

OH_Drawing_SetTextStyleWordSpacing()

void OH_Drawing_SetTextStyleWordSpacing(OH_Drawing_TextStyle* style, double wordSpacing)

Description

Sets the word spacing for a text style.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 11

Parameters

NameDescription
OH_Drawing_TextStyle* stylePointer to the OH_Drawing_TextStyle object, which is obtained from OH_Drawing_CreateTextStyle.
double wordSpacingLetter spacing.

OH_Drawing_SetTextStyleHalfLeading()

void OH_Drawing_SetTextStyleHalfLeading(OH_Drawing_TextStyle* style, bool halfLeading)

Description

Sets whether to enable half leading for a text style.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 11

Parameters

NameDescription
OH_Drawing_TextStyle* stylePointer to the OH_Drawing_TextStyle object, which is obtained from OH_Drawing_CreateTextStyle.
bool halfLeadingWhether the half leading takes effect. true means yes; false otherwise.

OH_Drawing_SetTextStyleEllipsis()

void OH_Drawing_SetTextStyleEllipsis(OH_Drawing_TextStyle* style, const char* ellipsis)

Description

Sets the ellipsis content for a text style.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 11

Deprecated from: 18

Replaced by: OH_Drawing_SetTypographyTextEllipsis

Parameters

NameDescription
OH_Drawing_TextStyle* stylePointer to the OH_Drawing_TextStyle object, which is obtained from OH_Drawing_CreateTextStyle.
const char* ellipsisPointer to the ellipsis content. The data type is a pointer pointing to char.

OH_Drawing_SetTextStyleEllipsisModal()

void OH_Drawing_SetTextStyleEllipsisModal(OH_Drawing_TextStyle* style, int ellipsisModal)

Description

Sets the ellipsis style for a text style.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 11

Deprecated from: 18

Replaced by: OH_Drawing_SetTypographyTextEllipsisModal

Parameters

NameDescription
OH_Drawing_TextStyle* stylePointer to the OH_Drawing_TextStyle object, which is obtained from OH_Drawing_CreateTextStyle.
int ellipsisModalEllipsis style. For details about the available options, see OH_Drawing_EllipsisModal.

OH_Drawing_SetTypographyTextBreakStrategy()

void OH_Drawing_SetTypographyTextBreakStrategy(OH_Drawing_TypographyStyle* style, int breakStrategy)

Description

Sets the text break strategy.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 11

Parameters

NameDescription
OH_Drawing_TypographyStyle* stylePointer to the OH_Drawing_TypographyStyle object, which is obtained from OH_Drawing_CreateTypographyStyle.
int breakStrategyBreak strategy. For details about the available options, see OH_Drawing_BreakStrategy.

OH_Drawing_SetTypographyTextWordBreakType()

void OH_Drawing_SetTypographyTextWordBreakType(OH_Drawing_TypographyStyle* style, int wordBreakType)

Description

Sets the word break type.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 11

Parameters

NameDescription
OH_Drawing_TypographyStyle* stylePointer to the OH_Drawing_TypographyStyle object, which is obtained from OH_Drawing_CreateTypographyStyle.
int wordBreakTypeWord break type. For details about the available options, see OH_Drawing_WordBreakType.

OH_Drawing_SetTypographyTextEllipsisModal()

void OH_Drawing_SetTypographyTextEllipsisModal(OH_Drawing_TypographyStyle* style, int ellipsisModal)

Description

Sets the ellipsis style for a text style.

This API supports only the ellipsis styles ELLIPSIS_MODAL_HEAD, ELLIPSIS_MODAL_MIDDLE, and ELLIPSIS_MODAL_TAIL. For details, see the OH_Drawing_EllipsisModal enumeration.

NOTE

Since API version 24, you are advised to use the OH_Drawing_SetTypographyStyleAttributeInt API to set the ellipsis style to support more ellipsis-style enumerated values.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 11

Parameters

NameDescription
OH_Drawing_TypographyStyle* stylePointer to the OH_Drawing_TypographyStyle object, which is obtained from OH_Drawing_CreateTypographyStyle.
int ellipsisModalEllipsis style. For details about the available options, see OH_Drawing_EllipsisModal.

OH_Drawing_SetTypographyTextEllipsis()

void OH_Drawing_SetTypographyTextEllipsis(OH_Drawing_TypographyStyle* style, const char* ellipsis)

Description

Sets the ellipsis text for a typography style.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_TypographyStyle* stylePointer to the OH_Drawing_TypographyStyle object, which is obtained from OH_Drawing_CreateTypographyStyle.
const char* ellipsisEllipsis text.

OH_Drawing_TypographyGetLineHeight()

double OH_Drawing_TypographyGetLineHeight(OH_Drawing_Typography* typography, int lineNumber)

Description

Obtains the line height in a typography object. This function must be called after OH_Drawing_TypographyLayout is called.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 11

Parameters

NameDescription
OH_Drawing_Typography* typographyPointer to the OH_Drawing_Typography object, which is obtained from OH_Drawing_CreateTypography.
int lineNumberTarget line.

Returns

TypeDescription
doubleObtains the height of a given line.

OH_Drawing_TypographyGetLineWidth()

double OH_Drawing_TypographyGetLineWidth(OH_Drawing_Typography* typography, int lineNumber)

Description

Obtains the line width of a specified line. This function must be called after OH_Drawing_TypographyLayout is called.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 11

Parameters

NameDescription
OH_Drawing_Typography* typographyPointer to the OH_Drawing_Typography object, which is obtained from OH_Drawing_CreateTypography.
int lineNumberTarget line.

Returns

TypeDescription
doubleObtains the width of a given line.

OH_Drawing_SetTypographyTextSplitRatio()

void OH_Drawing_SetTypographyTextSplitRatio(OH_Drawing_TypographyStyle* style, float textSplitRatio)

Description

Sets the text split ratio.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_TypographyStyle* stylePointer to the OH_Drawing_TypographyStyle object, which is obtained from OH_Drawing_CreateTypographyStyle.
float textSplitRatioText split ratio.

OH_Drawing_TypographyIsLineUnlimited()

bool OH_Drawing_TypographyIsLineUnlimited(OH_Drawing_TypographyStyle* style)

Description

Checks whether the maximum number of lines is limited for text.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_TypographyStyle* stylePointer to the OH_Drawing_TypographyStyle object, which is obtained from OH_Drawing_CreateTypographyStyle.

Returns

TypeDescription
boolReturns true if that the maximum number of lines is limited; returns false otherwise.

OH_Drawing_TypographyIsEllipsized()

bool OH_Drawing_TypographyIsEllipsized(OH_Drawing_TypographyStyle* style)

Description

Checks whether an ellipsis is configured for a typography style.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_TypographyStyle* stylePointer to the OH_Drawing_TypographyStyle object, which is obtained from OH_Drawing_CreateTypographyStyle.

Returns

TypeDescription
boolWhether ellipsis is configured for the specified typography style. true means yes; false otherwise.

OH_Drawing_SetTypographyTextLocale()

void OH_Drawing_SetTypographyTextLocale(OH_Drawing_TypographyStyle* style, const char* locale)

Description

Sets the locale for a typography style.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_TypographyStyle* stylePointer to the OH_Drawing_TypographyStyle object, which is obtained from OH_Drawing_CreateTypographyStyle.
const char* localePointer to the locale. For example, 'en' indicates English, 'zh-Hans' indicates Simplified Chinese, and 'zh-Hant' indicates Traditional Chinese.

OH_Drawing_TextStyleGetFontMetrics()

bool OH_Drawing_TextStyleGetFontMetrics(OH_Drawing_Typography* typography,OH_Drawing_TextStyle* style, OH_Drawing_Font_Metrics* fontmetrics)

Description

Obtains the font metrics of a text style.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_Typography* typographyPointer to the OH_Drawing_Typography object, which is obtained from OH_Drawing_CreateTypography.
OH_Drawing_TextStyle* stylePointer to the OH_Drawing_TextStyle object, which is obtained from OH_Drawing_CreateTextStyle.
OH_Drawing_Font_Metrics* fontmetricsPointer to the OH_Drawing_Font_Metrics object, which is obtained from OH_Drawing_Font_Metrics.

Returns

TypeDescription
boolWhether the font attributes are obtained. true means yes; false otherwise.

OH_Drawing_SetTypographyTextStyle()

void OH_Drawing_SetTypographyTextStyle(OH_Drawing_TypographyStyle* handler, OH_Drawing_TextStyle* style)

Description

Sets a text style.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_TypographyStyle* handlerPointer to the OH_Drawing_TypographyStyle object, which is obtained from OH_Drawing_CreateTypographyStyle.
OH_Drawing_TextStyle* stylePointer to the OH_Drawing_TextStyle object, which is obtained from OH_Drawing_CreateTextStyle.

OH_Drawing_CreateFontDescriptor()

OH_Drawing_FontDescriptor* OH_Drawing_CreateFontDescriptor(void)

Description

Creates an OH_Drawing_FontDescriptor object to describe the detailed information about a system font.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Returns

TypeDescription
OH_Drawing_FontDescriptor*Pointer to the created OH_Drawing_FontDescriptor object.

OH_Drawing_DestroyFontDescriptor()

void OH_Drawing_DestroyFontDescriptor(OH_Drawing_FontDescriptor* descriptor)

Description

Destroys an OH_Drawing_FontDescriptor object and reclaims the memory occupied by the object.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_FontDescriptor* descriptorPointer to the OH_Drawing_FontDescriptor object, which is obtained from OH_Drawing_CreateFontDescriptor.

OH_Drawing_CreateFontParser()

OH_Drawing_FontParser* OH_Drawing_CreateFontParser(void)

Description

Creates an OH_Drawing_FontParser object to parse a system font.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Returns

TypeDescription
OH_Drawing_FontParser*Pointer to the created OH_Drawing_FontParser object.

OH_Drawing_DestroyFontParser()

void OH_Drawing_DestroyFontParser(OH_Drawing_FontParser* parser)

Description

Destroys an OH_Drawing_FontParser object and reclaims the memory occupied by the object.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_FontParser* parserPointer to the OH_Drawing_FontParser object, which is obtained from OH_Drawing_CreateFontParser.

OH_Drawing_FontParserGetSystemFontList()

char** OH_Drawing_FontParserGetSystemFontList(OH_Drawing_FontParser* fontParser, size_t* num)

Description

Obtains the list of system fonts. This function can be used only on 2-in-1 devices and phones.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_FontParser* fontParserPointer to the OH_Drawing_FontParser object, which is obtained from OH_Drawing_CreateFontParser.
size_t* numPointer to the number of system font names.

Returns

TypeDescription
char**System font list.

OH_Drawing_DestroySystemFontList()

void OH_Drawing_DestroySystemFontList(char** fontList, size_t num)

Description

Reclaims the memory occupied by the system font list.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
char** fontListDouble pointer to the list of system font names.
size_t numNumber of system font names.

OH_Drawing_FontParserGetFontByName()

OH_Drawing_FontDescriptor* OH_Drawing_FontParserGetFontByName(OH_Drawing_FontParser* fontParser, const char* name)

Description

Obtains the descriptor of a system font based on the font name.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_FontParser* fontParserPointer to the OH_Drawing_FontParser object, which is obtained from OH_Drawing_CreateFontParser.
const char* namePointer to the system font name.

Returns

TypeDescription
OH_Drawing_FontDescriptor*Font descriptor object. Release this pointer by calling OH_Drawing_DestroyFontParser when this object is no longer needed.

OH_Drawing_TypographyGetLineMetrics()

OH_Drawing_LineMetrics* OH_Drawing_TypographyGetLineMetrics(OH_Drawing_Typography* typography)

Description

Obtains the line metrics in a typography object. This function must be called after OH_Drawing_TypographyLayout is called. Release this pointer by calling OH_Drawing_DestroyLineMetrics when this object is no longer needed.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_Typography* typographyPointer to the OH_Drawing_Typography object, which is obtained from OH_Drawing_CreateTypography.

Returns

TypeDescription
OH_Drawing_LineMetrics*Pointer to the OH_Drawing_LineMetrics object.

OH_Drawing_LineMetricsGetSize()

size_t OH_Drawing_LineMetricsGetSize(OH_Drawing_LineMetrics* lineMetrics)

Description

Obtains the number of lines.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_LineMetrics* lineMetricsPointer to the OH_Drawing_LineMetrics object, which is obtained from OH_Drawing_LineMetrics.

Returns

TypeDescription
size_tNumber of lines.

OH_Drawing_DestroyLineMetrics()

void OH_Drawing_DestroyLineMetrics(OH_Drawing_LineMetrics* lineMetrics)

Description

Destroys an OH_Drawing_LineMetrics object and reclaims the memory occupied by the object.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_LineMetrics* lineMetricsPointer to the OH_Drawing_LineMetrics object, which is obtained from OH_Drawing_LineMetrics.

OH_Drawing_TypographyGetLineMetricsAt()

bool OH_Drawing_TypographyGetLineMetricsAt(OH_Drawing_Typography* typography,int lineNumber, OH_Drawing_LineMetrics* lineMetric)

Description

Obtains the metrics of the given line in a typography object. For details, see the OH_Drawing_LineMetr struct. This function must be called after OH_Drawing_TypographyLayout is called.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_Typography* typographyPointer to the OH_Drawing_Typography object, which is obtained from OH_Drawing_CreateTypography.
int lineNumberLine No.
OH_Drawing_LineMetrics* lineMetricPointer to the OH_Drawing_LineMetrics object, which is obtained from OH_Drawing_LineMetrics.

Returns

TypeDescription
boolWhether the metrics of the given line is obtained. true means yes; false otherwise.

OH_Drawing_TypographyGetLineInfo()

bool OH_Drawing_TypographyGetLineInfo(OH_Drawing_Typography* typography, int lineNumber, bool oneLine,bool includeWhitespace, OH_Drawing_LineMetrics* drawingLineMetrics)

Description

Obtains the metrics of a given line or the metrics of the first character in a given line in a typography object. This function must be called after OH_Drawing_TypographyLayout is called.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_Typography* typographyPointer to the OH_Drawing_Typography object, which is obtained from OH_Drawing_CreateTypography.
int lineNumberRow No.
bool oneLineWhether to obtain the metrics of the entire line. The value true means to obtain the metrics of the entire line, and false means to obtain the metrics of the first character in the line.
bool includeWhitespaceWhether the text width includes the whitespace. true means yes; false otherwise.
OH_Drawing_LineMetrics* drawingLineMetricsPointer to the OH_Drawing_LineMetrics object, which is obtained from OH_Drawing_LineMetrics.

Returns

TypeDescription
boolReturns true if the metrics of the given line or the metrics of the first character in the given line is obtained; returns false otherwise.

OH_Drawing_SetTypographyTextFontWeight()

void OH_Drawing_SetTypographyTextFontWeight(OH_Drawing_TypographyStyle* style, int weight)

Description

Sets the default font weight for a typography style. Currently, only the default system font supports font weight adjustment. For other fonts, if the weight is less than semi-bold, there is no variation in stroke thickness. If the weight is greater than or equal to semi-bold, it might result in a fake bold effect.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_TypographyStyle* stylePointer to the OH_Drawing_TypographyStyle object, which is obtained from OH_Drawing_CreateTypographyStyle.
int weightFont weight.
For details about the available options, see OH_Drawing_FontWeight.

OH_Drawing_SetTypographyTextFontStyle()

void OH_Drawing_SetTypographyTextFontStyle(OH_Drawing_TypographyStyle* style, int fontStyle)

Description

Sets the default font style for a typography style.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_TypographyStyle* stylePointer to the OH_Drawing_TypographyStyle object, which is obtained from OH_Drawing_CreateTypographyStyle.
int fontStyleFont style. For details about the available options, see OH_Drawing_FontStyle.

OH_Drawing_SetTypographyTextFontFamily()

void OH_Drawing_SetTypographyTextFontFamily(OH_Drawing_TypographyStyle* style, const char* fontFamily)

Description

Sets the font family name for text.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_TypographyStyle* stylePointer to the OH_Drawing_TypographyStyle object, which is obtained from OH_Drawing_CreateTypographyStyle.
const char* fontFamilyPointer to the name of the font family.

OH_Drawing_SetTypographyTextFontSize()

void OH_Drawing_SetTypographyTextFontSize(OH_Drawing_TypographyStyle* style, double fontSize)

Description

Sets the font size for text.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_TypographyStyle* stylePointer to the OH_Drawing_TypographyStyle object, which is obtained from OH_Drawing_CreateTypographyStyle.
double fontSizeFont size, which must be greater than 0.

OH_Drawing_SetTypographyTextFontHeight()

void OH_Drawing_SetTypographyTextFontHeight(OH_Drawing_TypographyStyle* style, double fontHeight)

Description

Sets the font height for text.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_TypographyStyle* stylePointer to the OH_Drawing_TypographyStyle object, which is obtained from OH_Drawing_CreateTypographyStyle.
double fontHeightFont height.

OH_Drawing_SetTypographyTextHalfLeading()

void OH_Drawing_SetTypographyTextHalfLeading(OH_Drawing_TypographyStyle* style, bool halfLeading)

Description

Sets whether to enable half leading for text.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_TypographyStyle* stylePointer to the OH_Drawing_TypographyStyle object, which is obtained from OH_Drawing_CreateTypographyStyle.
bool halfLeadingWhether to enable half leading. The value true means to enable half lading, and false means the opposite.

OH_Drawing_SetTypographyTextUseLineStyle()

void OH_Drawing_SetTypographyTextUseLineStyle(OH_Drawing_TypographyStyle* style, bool useLineStyle)

Description

Sets whether to enable the text line style.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_TypographyStyle* stylePointer to the OH_Drawing_TypographyStyle object, which is obtained from OH_Drawing_CreateTypographyStyle.
bool useLineStyleWhether to enable the line style. The value true means to enable the line style, and false means the opposite.

OH_Drawing_SetTypographyTextLineStyleFontWeight()

void OH_Drawing_SetTypographyTextLineStyleFontWeight(OH_Drawing_TypographyStyle* style, int weight)

Description

Sets the text font weight of the strut style in a typography style. Currently, only the default system font supports font weight adjustment. For other fonts, if the weight is less than semi-bold, there is no variation in stroke thickness. If the weight is greater than or equal to semi-bold, it might result in a fake bold effect.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_TypographyStyle* stylePointer to the OH_Drawing_TypographyStyle object, which is obtained from OH_Drawing_CreateTypographyStyle.
int weightFont weight. For details about the available options, see OH_Drawing_FontWeight.

OH_Drawing_SetTypographyTextLineStyleFontStyle()

void OH_Drawing_SetTypographyTextLineStyleFontStyle(OH_Drawing_TypographyStyle* style, int fontStyle)

Description

Sets the font style of the strut style in a typography style.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_TypographyStyle* stylePointer to the OH_Drawing_TypographyStyle object, which is obtained from OH_Drawing_CreateTypographyStyle.
int fontStyleFont style. For details about the available options, see OH_Drawing_FontStyle.

OH_Drawing_SetTypographyTextLineStyleFontFamilies()

void OH_Drawing_SetTypographyTextLineStyleFontFamilies(OH_Drawing_TypographyStyle* style,int fontFamiliesNumber, const char* fontFamilies[])

Description

Sets the font families for a text line style.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_TypographyStyle* stylePointer to the OH_Drawing_TypographyStyle object, which is obtained from OH_Drawing_CreateTypographyStyle.
int fontFamiliesNumberNumber of font families.
fontFamiliesPointer to the font families.

OH_Drawing_SetTypographyTextLineStyleFontSize()

void OH_Drawing_SetTypographyTextLineStyleFontSize(OH_Drawing_TypographyStyle* style, double lineStyleFontSize)

Description

Sets the font size for a text line style.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_TypographyStyle* stylePointer to the OH_Drawing_TypographyStyle object, which is obtained from OH_Drawing_CreateTypographyStyle.
double lineStyleFontSizeFont size, which must be greater than 0.

OH_Drawing_SetTypographyTextLineStyleFontHeight()

void OH_Drawing_SetTypographyTextLineStyleFontHeight(OH_Drawing_TypographyStyle* style, double lineStyleFontHeight)

Description

Sets the font height for a text line style.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_TypographyStyle* stylePointer to the OH_Drawing_TypographyStyle object, which is obtained from OH_Drawing_CreateTypographyStyle.
double lineStyleFontHeightFont height.

OH_Drawing_SetTypographyTextLineStyleHalfLeading()

void OH_Drawing_SetTypographyTextLineStyleHalfLeading(OH_Drawing_TypographyStyle* style, bool lineStyleHalfLeading)

Description

Sets whether to enable half leading for a text line style.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_TypographyStyle* stylePointer to the OH_Drawing_TypographyStyle object, which is obtained from OH_Drawing_CreateTypographyStyle.
bool lineStyleHalfLeadingWhether the half leading takes effect. true means yes; false otherwise.

OH_Drawing_SetTypographyTextLineStyleSpacingScale()

void OH_Drawing_SetTypographyTextLineStyleSpacingScale(OH_Drawing_TypographyStyle* style, double spacingScale)

Description

Sets the spacing scale factor for a text line style.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_TypographyStyle* stylePointer to the OH_Drawing_TypographyStyle object, which is obtained from OH_Drawing_CreateTypographyStyle.
double spacingScaleSpacing ratio.

OH_Drawing_SetTypographyTextLineStyleOnly()

void OH_Drawing_SetTypographyTextLineStyleOnly(OH_Drawing_TypographyStyle* style, bool lineStyleOnly)

Description

Sets whether to enable the text line style only.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_TypographyStyle* stylePointer to the OH_Drawing_TypographyStyle object, which is obtained from OH_Drawing_CreateTypographyStyle.
bool lineStyleOnlyWhether to enable the line style only. true means yes; false otherwise.

OH_Drawing_CreateTextShadow()

OH_Drawing_TextShadow* OH_Drawing_CreateTextShadow(void)

Description

Creates an OH_Drawing_TextShadow object. Release this pointer by calling OH_Drawing_DestroyTextShadow when this object is no longer needed.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Returns

TypeDescription
OH_Drawing_TextShadow*Pointer to the OH_Drawing_TextShadow object created.

OH_Drawing_DestroyTextShadow()

void OH_Drawing_DestroyTextShadow(OH_Drawing_TextShadow* shadow)

Description

Destroys an OH_Drawing_TextShadow object and reclaims the memory occupied by the object.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_TextShadow* shadowPointer to the OH_Drawing_TextShadow object, which is obtained from OH_Drawing_CreateTextShadow.

OH_Drawing_TextStyleGetShadows()

OH_Drawing_TextShadow* OH_Drawing_TextStyleGetShadows(OH_Drawing_TextStyle* style)

Description

Obtains a text shadow container. Release this pointer by calling OH_Drawing_DestroyTextShadows when this object is no longer needed.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_TextStyle* stylePointer to the OH_Drawing_TextStyle object, which is obtained from OH_Drawing_CreateTextStyle.

Returns

TypeDescription
OH_Drawing_TextShadow*Pointer to the OH_Drawing_TextShadow object.

OH_Drawing_TextStyleGetShadowCount()

int OH_Drawing_TextStyleGetShadowCount(OH_Drawing_TextStyle* style)

Description

Obtains the size of a text shadow container.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_TextStyle* stylePointer to the OH_Drawing_TextStyle object, which is obtained from OH_Drawing_CreateTextStyle.

Returns

TypeDescription
intSize of a text shadow container.

OH_Drawing_TextStyleAddShadow()

void OH_Drawing_TextStyleAddShadow(OH_Drawing_TextStyle* style, const OH_Drawing_TextShadow* shadow)

Description

Adds a shadow to a text shadow container.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_TextStyle* stylePointer to the OH_Drawing_TextStyle object, which is obtained from OH_Drawing_CreateTextStyle.
const OH_Drawing_TextShadow* shadowPointer to the OH_Drawing_TextShadow object, which is obtained from OH_Drawing_CreateTextShadow.

OH_Drawing_TextStyleClearShadows()

void OH_Drawing_TextStyleClearShadows(OH_Drawing_TextStyle* style)

Description

Clears all shadows in a text shadow container.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_TextStyle* stylePointer to the OH_Drawing_TextStyle object, which is obtained from OH_Drawing_CreateTextStyle.

OH_Drawing_TextStyleGetShadowWithIndex()

OH_Drawing_TextShadow* OH_Drawing_TextStyleGetShadowWithIndex(OH_Drawing_TextStyle* style, int index)

Description

Obtains a shadow with a given index in a text shadow container.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_TextStyle* stylePointer to the OH_Drawing_TextStyle object, which is obtained from OH_Drawing_CreateTextStyle.
int indexIndex.

Returns

TypeDescription
OH_Drawing_TextShadow*Pointer to the OH_Drawing_TextShadow object.

OH_Drawing_TypographySetIndents()

void OH_Drawing_TypographySetIndents(OH_Drawing_Typography* typography, int indentsNumber, const float indents[])

Description

Sets indents for typography. If this function is not called, texts will have no indentation applied.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_Typography* typographyPointer to the OH_Drawing_Typography object, which is obtained from OH_Drawing_CreateTypography.
int indentsNumberNumber of indents. The value must be less than or equal to the length of the indents array to avoid display exceptions caused by access to the out-of-bounds array.
indentsPointer to a floating-point array, in which each element indicates an indentation width, in px. Before calling OH_Drawing_Typography API, you need to declare and initialize the floating-point array.

OH_Drawing_TypographyGetIndentsWithIndex()

float OH_Drawing_TypographyGetIndentsWithIndex(OH_Drawing_Typography* typography, int index)

Description

Obtains indents with a given index in a typography object. The line index starts from 0.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_Typography* typographyPointer to the OH_Drawing_Typography object, which is obtained from OH_Drawing_CreateTypography.
int indexIndex.

Returns

TypeDescription
floatIndents.

OH_Drawing_TypographyGetLineTextRange()

OH_Drawing_Range* OH_Drawing_TypographyGetLineTextRange(OH_Drawing_Typography* typography,int lineNumber, bool includeSpaces)

Description

Obtains the line bounds in a typography object. This function must be called after OH_Drawing_TypographyLayout is called. This function can only be used to obtain the bounds of existing lines. That is, the line index must start from 0, and the maximum index is OH_Drawing_TypographyGetLineCount – 1.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_Typography* typographyPointer to the OH_Drawing_Typography object, which is obtained from OH_Drawing_CreateTypography.
int lineNumberRow index.
bool includeSpacesWhether the returned bounds contain spaces. The value true means that the bounds contain spaces, and false means the opposite.

Returns

TypeDescription
OH_Drawing_Range*Pointer to the OH_Drawing_Range object. If the line index is invalid, start and end in the result value are both 0.

OH_Drawing_DestroyTextShadows()

void OH_Drawing_DestroyTextShadows(OH_Drawing_TextShadow* shadow)

Description

Reclaims the memory occupied by the vector consisting of the OH_Drawing_TextShadow objects.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_TextShadow* shadowPointer to the OH_Drawing_TextShadow object, which is obtained from OH_Drawing_CreateTextShadow.

OH_Drawing_GetSystemFontConfigInfo()

OH_Drawing_FontConfigInfo* OH_Drawing_GetSystemFontConfigInfo(OH_Drawing_FontConfigInfoErrorCode* errorCode)

Description

Obtains the system font configuration.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_FontConfigInfoErrorCode* errorCodeError code. For details, see OH_Drawing_FontConfigInfoErrorCode.

Returns

TypeDescription
OH_Drawing_FontConfigInfo*Pointer to the system font configuration. When it is no longer required, call OH_Drawing_DestroySystemFontConfigInfo to release the pointer to the object.

OH_Drawing_DestroySystemFontConfigInfo()

void OH_Drawing_DestroySystemFontConfigInfo(OH_Drawing_FontConfigInfo* drawFontCfgInfo)

Description

Reclaims the memory occupied by the system font configuration.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_FontConfigInfo* drawFontCfgInfoPointer to the OH_Drawing_FontConfigInfo object, which is obtained from OH_Drawing_GetSystemFontConfigInfo.

OH_Drawing_SetTextStyleFontStyleStruct()

void OH_Drawing_SetTextStyleFontStyleStruct(OH_Drawing_TextStyle* drawingTextStyle,OH_Drawing_FontStyleStruct fontStyle)

Description

Sets the font style, including the font weight, width, and slant, for a text style.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_TextStyle* drawingTextStylePointer to the OH_Drawing_TextStyle object, which is obtained from OH_Drawing_CreateTextStyle.
OH_Drawing_FontStyleStruct fontStyleFont style, including the font weight, width, and slant.

OH_Drawing_SetTextStyleBadgeType()

void OH_Drawing_SetTextStyleBadgeType(OH_Drawing_TextStyle* style, OH_Drawing_TextBadgeType textBadgeType)

Description

Sets whether to use superscript or subscript in text layout. If this API is not called, the feature is disabled by default.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 20

Parameters

NameDescription
OH_Drawing_TextStyle* stylePointer to the OH_Drawing_TextStyle object, which is obtained from OH_Drawing_CreateTextStyle.
OH_Drawing_TextBadgeType textBadgeTypeSets whether to use superscript or subscript in text layout. TEXT_SUPERSCRIPT indicates that superscript is enabled, and TEXT_SUBSCRIPT indicates that subscript is enabled. The default value is TEXT_BADGE_NONE, indicating that neither superscript nor subscript is enabled.

OH_Drawing_TextStyleGetFontStyleStruct()

OH_Drawing_FontStyleStruct OH_Drawing_TextStyleGetFontStyleStruct(OH_Drawing_TextStyle* drawingTextStyle)

Description

Obtains the font style, including the font weight, width, and slant, of a text style.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_TextStyle* drawingTextStylePointer to the OH_Drawing_TextStyle object, which is obtained from OH_Drawing_CreateTextStyle.

Returns

TypeDescription
OH_Drawing_FontStyleStructFont style, including the font weight, width, and slant.

OH_Drawing_SetTypographyStyleFontStyleStruct()

void OH_Drawing_SetTypographyStyleFontStyleStruct(OH_Drawing_TypographyStyle* drawingStyle,OH_Drawing_FontStyleStruct fontStyle)

Description

Sets the font style, including the font weight, width, and slant, for the default text style of a typography style.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_TypographyStyle* drawingStylePointer to the OH_Drawing_TypographyStyle object, which is obtained from OH_Drawing_CreateTypographyStyle.
OH_Drawing_FontStyleStruct fontStyleFont style, including the font weight, width, and slant.

OH_Drawing_TypographyStyleGetFontStyleStruct()

OH_Drawing_FontStyleStruct OH_Drawing_TypographyStyleGetFontStyleStruct(OH_Drawing_TypographyStyle* drawingStyle)

Description

Obtains the font style, including the font weight, width, and slant, of the default text style of a typography style.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_TypographyStyle* drawingStylePointer to the OH_Drawing_TypographyStyle object, which is obtained from OH_Drawing_CreateTypographyStyle.

Returns

TypeDescription
OH_Drawing_FontStyleStructFont style, including the font weight, width, and slant.

OH_Drawing_TextStyleSetBackgroundRect()

void OH_Drawing_TextStyleSetBackgroundRect(OH_Drawing_TextStyle* style,const OH_Drawing_RectStyle_Info* rectStyleInfo, int styleId)

Description

Sets a background rectangle and style ID for a text style. The style ID is valid only when the background box is a rounded rectangle.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_TextStyle* stylePointer to the OH_Drawing_TextStyle object, which is obtained from OH_Drawing_CreateTextStyle.
const OH_Drawing_RectStyle_Info* rectStyleInfoPointer to the OH_Drawing_RectStyle_Info object.
int styleIdStyle ID. The style ID is valid only when the background box is a rounded rectangle. Text processing is divided into multiple segments. Each segment has its own text style. id indicates the sequence number of the background box in which the segment is drawn.
If the ID of each segment in a row is 0, all segments are drawn in the same background box. If a row contains segments with IDs 0 and 1, the segment with ID 0 is drawn in a background box, and the segment with ID 1 is drawn in another background box. Other cases can be deduced in the same way.

OH_Drawing_TypographyHandlerAddSymbol()

void OH_Drawing_TypographyHandlerAddSymbol(OH_Drawing_TypographyCreate* handler, uint32_t symbol)

Description

Adds the symbol to use in the typography creation process.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_TypographyCreate* handlerPointer to the OH_Drawing_TypographyCreate object, which is obtained from OH_Drawing_CreateTypographyHandler.
uint32_t symbolSymbol value. For details, see the Unicode value in the HarmonyOS Symbol library.

OH_Drawing_TextStyleAddFontFeature()

void OH_Drawing_TextStyleAddFontFeature(OH_Drawing_TextStyle* style, const char* tag, int value)

Description

Adds a font feature for a text style.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_TextStyle* stylePointer to the OH_Drawing_TextStyle object, which is obtained from OH_Drawing_CreateTextStyle.
const char* tagPointer to the string identified by the keyword in the font feature key-value pair.
int valueValue of the font feature key-value pair.

OH_Drawing_TextStyleAddFontVariation()

void OH_Drawing_TextStyleAddFontVariation(OH_Drawing_TextStyle* style, const char* axis, const float value)

Description

Adds a font variation. This function takes effect only when the corresponding font file (.ttf file) supports variable adjustment. Otherwise, calling this function does not take effect.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_TextStyle* stylePointer to the OH_Drawing_TextStyle object, which is obtained from OH_Drawing_CreateTextStyle.
const char* axisPointer to the key in the font variation key-value pair. Currently, only 'wght' is supported, indicating the font weight.
const float valueValue of the font variation key-value pair. Currently, the value range of 'wght' for the default font is [0,900].

OH_Drawing_TextStyleGetFontFeatures()

OH_Drawing_FontFeature* OH_Drawing_TextStyleGetFontFeatures(OH_Drawing_TextStyle* style)

Description

Obtains all the contents in a font feature map container of a text style.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_TextStyle* stylePointer to the OH_Drawing_TextStyle object, which is obtained from OH_Drawing_CreateTextStyle.

Returns

TypeDescription
OH_Drawing_FontFeature*Pointer to the font feature struct, which stores all the contents obtained.

OH_Drawing_TextStyleDestroyFontFeatures()

void OH_Drawing_TextStyleDestroyFontFeatures(OH_Drawing_FontFeature* fontFeature, size_t fontFeatureSize)

Description

Reclaims the memory occupied by the struct array that holds all the font features.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_FontFeature* fontFeaturePointer to the struct array that holds all the font features, which is obtained from OH_Drawing_TextStyleGetFontFeatures.
size_t fontFeatureSizeSize of the struct array that holds all the font features.

OH_Drawing_TextStyleGetFontFeatureSize()

size_t OH_Drawing_TextStyleGetFontFeatureSize(OH_Drawing_TextStyle* style)

Description

Obtains the size of a font feature map container in a text style.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_TextStyle* stylePointer to the OH_Drawing_TextStyle object, which is obtained from OH_Drawing_CreateTextStyle.

Returns

TypeDescription
size_tSize of a font feature map container.

OH_Drawing_TextStyleClearFontFeature()

void OH_Drawing_TextStyleClearFontFeature(OH_Drawing_TextStyle* style)

Description

Clears all the contents in a font feature map container of a text style.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_TextStyle* stylePointer to the OH_Drawing_TextStyle object, which is obtained from OH_Drawing_CreateTextStyle.

OH_Drawing_TextStyleGetBaselineShift()

double OH_Drawing_TextStyleGetBaselineShift(OH_Drawing_TextStyle* style)

Description

Obtains the baseline drift of a text style.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_TextStyle* stylePointer to the OH_Drawing_TextStyle object, which is obtained from OH_Drawing_CreateTextStyle.

Returns

TypeDescription
doubleBaseline shift.

OH_Drawing_TextStyleSetBaselineShift()

void OH_Drawing_TextStyleSetBaselineShift(OH_Drawing_TextStyle* style, double lineShift)

Description

Sets a baseline drift for a text style.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_TextStyle* stylePointer to the OH_Drawing_TextStyle object, which is obtained from OH_Drawing_CreateTextStyle.
double lineShiftBaseline drift of the text style.

OH_Drawing_TypographyTextSetHeightBehavior()

void OH_Drawing_TypographyTextSetHeightBehavior(OH_Drawing_TypographyStyle* style,OH_Drawing_TextHeightBehavior heightMode)

Description

Sets a text height modifier pattern.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_TypographyStyle* stylePointer to the OH_Drawing_TypographyStyle object, which is obtained from OH_Drawing_CreateTypographyStyle.
OH_Drawing_TextHeightBehavior heightModeText height modifier mode. The value is an enumerated value of the OH_Drawing_TextHeightBehavior type.

OH_Drawing_TypographyTextGetHeightBehavior()

OH_Drawing_TextHeightBehavior OH_Drawing_TypographyTextGetHeightBehavior(OH_Drawing_TypographyStyle* style)

Description

Obtains the text height modifier pattern.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_TypographyStyle* stylePointer to the OH_Drawing_TypographyStyle object, which is obtained from OH_Drawing_CreateTypographyStyle.

Returns

TypeDescription
OH_Drawing_TextHeightBehaviorText height modifier mode, which is an enumerated value of the OH_Drawing_TextHeightBehavior type.

OH_Drawing_TypographyGetLineFontMetrics()

OH_Drawing_Font_Metrics* OH_Drawing_TypographyGetLineFontMetrics(OH_Drawing_Typography* typography,size_t lineNumber, size_t* fontMetricsSize)

Description

Obtains all font metrics from a given line in a typography object. This function must be called after OH_Drawing_TypographyLayout is called. Otherwise, a null pointer is returned. Release this pointer by calling OH_Drawing_TypographyDestroyLineFontMetrics when this object is no longer needed.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_Typography* typographyPointer to the OH_Drawing_Typography object, which is obtained from OH_Drawing_CreateTypography.
size_t lineNumberLine number, which is an integer. The minimum value is 1, and the maximum value depends on the number of lines parsed by the font engine after text input. If a value greater than the maximum number is passed in, an error value is returned and an error message is printed.
size_t* fontMetricsSizePointer to the size of the struct.

Returns

TypeDescription
OH_Drawing_Font_Metrics*Returns all the font metrics.

OH_Drawing_TypographyDestroyLineFontMetrics()

void OH_Drawing_TypographyDestroyLineFontMetrics(OH_Drawing_Font_Metrics* lineFontMetric)

Description

Reclaims the memory occupied by the struct array that holds all the font metrics of a given line.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_Font_Metrics* lineFontMetricPointer to the first address of the struct array.

OH_Drawing_TextStyleIsEqual()

bool OH_Drawing_TextStyleIsEqual(const OH_Drawing_TextStyle* style, const OH_Drawing_TextStyle* comparedStyle)

Description

Checks whether two text styles are equal. The word width property is not involved in the comparison.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
const OH_Drawing_TextStyle* stylePointer to the first text style.
const OH_Drawing_TextStyle* comparedStylePointer to the first text style.

Returns

TypeDescription
boolWhether two text style objects are equal. true if the source rectangle is equal to the destination rectangle; false otherwise.

OH_Drawing_TextStyleIsEqualByFont()

bool OH_Drawing_TextStyleIsEqualByFont(const OH_Drawing_TextStyle* style, const OH_Drawing_TextStyle* comparedStyle)

Description

Checks whether the font style properties of two text styles are equal.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
const OH_Drawing_TextStyle* stylePointer to the first text style.
const OH_Drawing_TextStyle* comparedStylePointer to the first text style.

Returns

TypeDescription
boolReturns true if the two are equal; returns false otherwise.

OH_Drawing_TextStyleIsAttributeMatched()

bool OH_Drawing_TextStyleIsAttributeMatched(const OH_Drawing_TextStyle* style,const OH_Drawing_TextStyle* comparedStyle, OH_Drawing_TextStyleType textStyleType)

Description

Checks whether two text styles have the same font style type.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
const OH_Drawing_TextStyle* stylePointer to the first text style.
const OH_Drawing_TextStyle* comparedStylePointer to the first text style.
OH_Drawing_TextStyleType textStyleTypeText style types as in OH_Drawing_TextStyleType.

Returns

TypeDescription
boolWhether two text styles have the same font style type. true means yes; false otherwise.

OH_Drawing_TextStyleSetPlaceholder()

void OH_Drawing_TextStyleSetPlaceholder(OH_Drawing_TextStyle* style)

Description

Adds a placeholder.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_TextStyle* stylePointer to the OH_Drawing_TextStyle object, which is obtained from OH_Drawing_CreateTextStyle.

OH_Drawing_TextStyleIsPlaceholder()

bool OH_Drawing_TextStyleIsPlaceholder(OH_Drawing_TextStyle* style)

Description

Checks whether a placeholder is set for a text style.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_TextStyle* stylePointer to the OH_Drawing_TextStyle object, which is obtained from OH_Drawing_CreateTextStyle.

Returns

TypeDescription
boolChecks whether a placeholder is set for a text style. true means yes; false otherwise.

OH_Drawing_TypographyStyleGetEffectiveAlignment()

OH_Drawing_TextAlign OH_Drawing_TypographyStyleGetEffectiveAlignment(OH_Drawing_TypographyStyle* style)

Description

Obtains the text alignment mode.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_TypographyStyle* stylePointer to the OH_Drawing_TypographyStyle object, which is obtained from OH_Drawing_CreateTypographyStyle.

Returns

TypeDescription
OH_Drawing_TextAlignText alignment modes as in OH_Drawing_TextAlign.

OH_Drawing_TypographyStyleIsHintEnabled()

bool OH_Drawing_TypographyStyleIsHintEnabled(OH_Drawing_TypographyStyle* style)

Description

Checks whether font hinting is enabled for a typography style. Font hinting is used to improve the readability and appearance of small-sized text when rendering it.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_TypographyStyle* stylePointer to the OH_Drawing_TypographyStyle object, which is obtained from OH_Drawing_CreateTypographyStyle.

Returns

TypeDescription
boolWhether to enable font hinting for a typography style. true: enabled; false: disabled.

OH_Drawing_SetTypographyStyleTextStrutStyle()

void OH_Drawing_SetTypographyStyleTextStrutStyle(OH_Drawing_TypographyStyle* style, OH_Drawing_StrutStyle* strutstyle)

Description

Sets the strut style for a typography style.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_TypographyStyle* stylePointer to the OH_Drawing_TypographyStyle object, which is obtained from OH_Drawing_CreateTypographyStyle.
OH_Drawing_StrutStyle* strutstylePointer to the OH_Drawing_StrutStyle object, which is obtained from OH_Drawing_TypographyStyleGetStrutStyle.

OH_Drawing_TypographyStyleGetStrutStyle()

OH_Drawing_StrutStyle* OH_Drawing_TypographyStyleGetStrutStyle(OH_Drawing_TypographyStyle* style)

Description

Obtains the strut style of a typography style.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_TypographyStyle* stylePointer to the OH_Drawing_TypographyStyle object, which is obtained from OH_Drawing_CreateTypographyStyle.

Returns

TypeDescription
OH_Drawing_StrutStyle*Pointer to the OH_Drawing_StrutStyle object.

OH_Drawing_TypographyStyleDestroyStrutStyle()

void OH_Drawing_TypographyStyleDestroyStrutStyle(OH_Drawing_StrutStyle* strutstyle)

Description

Reclaims the memory occupied by a strut style.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_StrutStyle* strutstylePointer to the OH_Drawing_StrutStyle object, which is obtained from OH_Drawing_TypographyStyleGetStrutStyle.

OH_Drawing_TypographyStyleStrutStyleEquals()

bool OH_Drawing_TypographyStyleStrutStyleEquals(OH_Drawing_StrutStyle* from, OH_Drawing_StrutStyle* to)

Description

Checks whether two strut styles are equal.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_StrutStyle* fromPointer to the first strut style.
OH_Drawing_StrutStyle* toPointer to the second strut style.

OH_Drawing_TypographyStyleSetHintsEnabled()

void OH_Drawing_TypographyStyleSetHintsEnabled(OH_Drawing_TypographyStyle* style, bool hintsEnabled)

Description

Sets whether to enable font hinting for a typography style. Font hinting is used to improve the readability and appearance of small-sized text when rendering it.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_TypographyStyle* stylePointer to the OH_Drawing_TypographyStyle object, which is obtained from OH_Drawing_CreateTypographyStyle.
bool hintsEnabledWhether to enable font hinting. true: enabled; false: disabled.

OH_Drawing_TypographyMarkDirty()

void  OH_Drawing_TypographyMarkDirty(OH_Drawing_Typography* typography)

Description

Marks a typography object as dirty data. This function is used to initialize the typography state.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_Typography* typographyPointer to the OH_Drawing_Typography object, which is obtained from OH_Drawing_CreateTypography.

OH_Drawing_TypographyGetUnresolvedGlyphsCount()

int32_t OH_Drawing_TypographyGetUnresolvedGlyphsCount(OH_Drawing_Typography* typography)

Description

Obtains the number of unresolved glyphs in a typography object. This function can be called only after OH_Drawing_TypographyLayout is called and applied.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_Typography* typographyPointer to the OH_Drawing_Typography object, which is obtained from OH_Drawing_CreateTypography.

Returns

TypeDescription
int32_tNumber of unresolved glyphs.

OH_Drawing_TypographyUpdateFontSize()

void OH_Drawing_TypographyUpdateFontSize(OH_Drawing_Typography* typography, size_t from, size_t to, float fontSize)

Description

Updates the font size in a typography object.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_Typography* typographyPointer to the OH_Drawing_Typography object, which is obtained from OH_Drawing_CreateTypography.
size_t fromReserved field, which is not used.
size_t toReserved field, which is not used.
float fontSizeNew font size.

OH_Drawing_TypographyUpdateFontColor()

void OH_Drawing_TypographyUpdateFontColor(OH_Drawing_Typography* typography, uint32_t color)

Description

Updates the font color in a typography object. This API call also updates the decoration color if it hasn't been set yet. The updated font color takes effect after you call OH_Drawing_TypographyPaint to draw the text.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 20

Parameters

NameDescription
OH_Drawing_Typography* typographyPointer to the OH_Drawing_Typography object, which is obtained from OH_Drawing_CreateTypography.
uint32_t colorNew font color.

OH_Drawing_TypographyUpdateDecoration()

void OH_Drawing_TypographyUpdateDecoration(OH_Drawing_Typography* typography, OH_Drawing_TextDecoration decoration)

Description

Updates the decoration type of a typography object. The updated decoration type takes effect after you call OH_Drawing_TypographyPaint to draw the text.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 20

Parameters

NameDescription
OH_Drawing_Typography* typographyPointer to the OH_Drawing_Typography object, which is obtained from OH_Drawing_CreateTypography.
OH_Drawing_TextDecoration decorationUpdated decoration type. For details, see OH_Drawing_TextDecoration. You can set multiple text decoration types at a time via bitwise OR operations. If a decoration type that is not in the OH_Drawing_TextDecoration enumeration is set, the original decoration is retained.

OH_Drawing_TypographyUpdateDecorationThicknessScale()

void OH_Drawing_TypographyUpdateDecorationThicknessScale(OH_Drawing_Typography* typography,double decorationThicknessScale)

Description

Updates the decoration thickness scale of a typography object. The updated decoration thickness scale takes effect after you call OH_Drawing_TypographyPaint to draw the text.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 20

Parameters

NameDescription
OH_Drawing_Typography* typographyPointer to the OH_Drawing_Typography object, which is obtained from OH_Drawing_CreateTypography.
double decorationThicknessScaleThickness scaling ratio of the updated text decoration line. The thickness of the decoration line increases as the ratio increases. If the value is less than or equal to 0, the decoration line will not be drawn.

OH_Drawing_TypographyUpdateDecorationStyle()

void OH_Drawing_TypographyUpdateDecorationStyle(OH_Drawing_Typography* typography,OH_Drawing_TextDecorationStyle decorationStyle)

Description

Updates the decoration style of a typography object. The updated decoration style takes effect after you call OH_Drawing_TypographyPaint to draw the text.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 20

Parameters

NameDescription
OH_Drawing_Typography* typographyPointer to the OH_Drawing_Typography object, which is obtained from OH_Drawing_CreateTypography.
OH_Drawing_TextDecorationStyle decorationStyleUpdated text decoration style. For details about the available options, see OH_Drawing_TextDecorationStyle.

OH_Drawing_TypographyTextGetLineStyle()

bool OH_Drawing_TypographyTextGetLineStyle(OH_Drawing_TypographyStyle* style)

Description

Checks whether the text line style is enabled for a typography style.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_TypographyStyle* stylePointer to the OH_Drawing_TypographyStyle object, which is obtained from OH_Drawing_CreateTypographyStyle.

Returns

TypeDescription
boolWhether the line style is enabled. true: enabled; false: disabled.

OH_Drawing_TypographyTextlineStyleGetFontWeight()

OH_Drawing_FontWeight OH_Drawing_TypographyTextlineStyleGetFontWeight(OH_Drawing_TypographyStyle* style)

Description

Obtains the font weight of a text line style.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_TypographyStyle* stylePointer to the OH_Drawing_TypographyStyle object, which is obtained from OH_Drawing_CreateTypographyStyle.

Returns

TypeDescription
OH_Drawing_FontWeightFont weight.
For details about the available options, see OH_Drawing_FontWeight.

OH_Drawing_TypographyTextlineStyleGetFontStyle()

OH_Drawing_FontStyle OH_Drawing_TypographyTextlineStyleGetFontStyle(OH_Drawing_TypographyStyle* style)

Description

Obtains the font style of the strut style in a typography style.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_TypographyStyle* stylePointer to the OH_Drawing_TypographyStyle object, which is obtained from OH_Drawing_CreateTypographyStyle.

Returns

TypeDescription
OH_Drawing_FontStyleFont style of the strut style in a typography style. 1 indicates italic, and 0 or others indicate non-italic. For details, see the OH_Drawing_FontStyle enumeration.

OH_Drawing_TypographyTextlineStyleGetFontFamilies()

char** OH_Drawing_TypographyTextlineStyleGetFontFamilies(OH_Drawing_TypographyStyle* style, size_t* num)

Description

Obtains the font families of a text line style.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_TypographyStyle* stylePointer to the OH_Drawing_TypographyStyle object, which is obtained from OH_Drawing_CreateTypographyStyle.
size_t* numPointer to the number of font families.

Returns

TypeDescription
char**Font families.

OH_Drawing_TypographyTextlineStyleDestroyFontFamilies()

void OH_Drawing_TypographyTextlineStyleDestroyFontFamilies(char** fontFamilies, size_t fontFamiliesNum)

Description

Reclaims the memory occupied by the font families.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
char** fontFamiliesDouble pointer to the font families.
size_t fontFamiliesNumNumber of font families.

OH_Drawing_TypographyTextlineStyleGetFontSize()

double OH_Drawing_TypographyTextlineStyleGetFontSize(OH_Drawing_TypographyStyle* style)

Description

Obtains the font size of a text line style.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_TypographyStyle* stylePointer to the OH_Drawing_TypographyStyle object, which is obtained from OH_Drawing_CreateTypographyStyle.

Returns

TypeDescription
doubleFont size.

OH_Drawing_TypographyTextlineStyleGetHeightScale()

double OH_Drawing_TypographyTextlineStyleGetHeightScale(OH_Drawing_TypographyStyle* style)

Description

Obtains the height scale factor of a text line style.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_TypographyStyle* stylePointer to the OH_Drawing_TypographyStyle object, which is obtained from OH_Drawing_CreateTypographyStyle.

Returns

TypeDescription
doubleHeight scale factor.

OH_Drawing_TypographyTextlineStyleGetHeightOnly()

bool OH_Drawing_TypographyTextlineStyleGetHeightOnly(OH_Drawing_TypographyStyle* style)

Description

Checks whether only the font height is used for a text line style.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_TypographyStyle* stylePointer to the OH_Drawing_TypographyStyle object, which is obtained from OH_Drawing_CreateTypographyStyle.

Returns

TypeDescription
boolMethod for calculating the height of a font block. true means that the height is calculated based on the font size; false means that the height is calculated based on the line spacing.

OH_Drawing_TypographyTextlineStyleGetHalfLeading()

bool OH_Drawing_TypographyTextlineStyleGetHalfLeading(OH_Drawing_TypographyStyle* style)

Description

Checks whether half leading is enabled for a text line style.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_TypographyStyle* stylePointer to the OH_Drawing_TypographyStyle object, which is obtained from OH_Drawing_CreateTypographyStyle.

Returns

TypeDescription
booltrue if half leading is enabled; returns false otherwise.

OH_Drawing_TypographyTextlineStyleGetSpacingScale()

double OH_Drawing_TypographyTextlineStyleGetSpacingScale(OH_Drawing_TypographyStyle* style)

Description

Obtains the spacing scale factor of a text line style.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_TypographyStyle* stylePointer to the OH_Drawing_TypographyStyle object, which is obtained from OH_Drawing_CreateTypographyStyle.

Returns

TypeDescription
doubleSpacing scale factor.

OH_Drawing_TypographyTextlineGetStyleOnly()

bool OH_Drawing_TypographyTextlineGetStyleOnly(OH_Drawing_TypographyStyle* style)

Description

Checks whether only the text line style is enabled for a typography style.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_TypographyStyle* stylePointer to the OH_Drawing_TypographyStyle object, which is obtained from OH_Drawing_CreateTypographyStyle.

Returns

TypeDescription
boolWhether only the text line style is enabled for a typography style. true: enabled; false: disabled.

OH_Drawing_TypographyGetTextAlign()

OH_Drawing_TextAlign OH_Drawing_TypographyGetTextAlign(OH_Drawing_TypographyStyle* style)

Description

Obtains the text alignment mode.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_TypographyStyle* stylePointer to the OH_Drawing_TypographyStyle object, which is obtained from OH_Drawing_CreateTypographyStyle.

Returns

TypeDescription
OH_Drawing_TextAlignAlignment mode. For details about the available options, see OH_Drawing_TextAlign.

OH_Drawing_TypographyGetTextDirection()

OH_Drawing_TextDirection OH_Drawing_TypographyGetTextDirection(OH_Drawing_TypographyStyle* style)

Description

Obtains the text direction of a typography style.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_TypographyStyle* stylePointer to the OH_Drawing_TypographyStyle object, which is obtained from OH_Drawing_CreateTypographyStyle.

Returns

TypeDescription
OH_Drawing_TextDirectionText direction. 0 means right-to-left; 1 means left-to-right. For details, see OH_Drawing_TextDirection.

OH_Drawing_TypographyGetTextMaxLines()

size_t OH_Drawing_TypographyGetTextMaxLines(OH_Drawing_TypographyStyle* style)

Description

Obtains the maximum number of lines.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_TypographyStyle* stylePointer to the OH_Drawing_TypographyStyle object, which is obtained from OH_Drawing_CreateTypographyStyle.

Returns

TypeDescription
size_tMaximum number of lines.

OH_Drawing_TypographyGetTextEllipsis()

char* OH_Drawing_TypographyGetTextEllipsis(OH_Drawing_TypographyStyle* style)

Description

Obtains the text ellipsis content of a typography style.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_TypographyStyle* stylePointer to the OH_Drawing_TypographyStyle object, which is obtained from OH_Drawing_CreateTypographyStyle.

Returns

TypeDescription
char*Ellipsis text.

OH_Drawing_TypographyDestroyEllipsis()

void OH_Drawing_TypographyDestroyEllipsis(char* ellipsis)

Description

Reclaims the memory occupied by the text ellipsis names.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
char* ellipsisPointer to the text ellipsis names.

OH_Drawing_TypographyStyleEquals()

bool OH_Drawing_TypographyStyleEquals(OH_Drawing_TypographyStyle* from, OH_Drawing_TypographyStyle* to)

Description

Checks whether two typography styles are the same. The text height modifier mode OH_Drawing_TextHeightBehavior is not involved in the comparison.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_TypographyStyle* fromPointer to the first typography style.
OH_Drawing_TypographyStyle* toPointer to the second typography style.

Returns

TypeDescription
boolReturns true if the two are the same; returns false otherwise.

OH_Drawing_TextStyleGetColor()

uint32_t OH_Drawing_TextStyleGetColor(OH_Drawing_TextStyle* style)

Description

Obtains the color of a text style.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_TextStyle* stylePointer to the OH_Drawing_TextStyle object, which is obtained from OH_Drawing_CreateTextStyle.

Returns

TypeDescription
uint32_tText color.

OH_Drawing_TextStyleGetDecorationStyle()

OH_Drawing_TextDecorationStyle OH_Drawing_TextStyleGetDecorationStyle(OH_Drawing_TextStyle* style)

Description

Obtains the decoration style of a text style.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_TextStyle* stylePointer to the OH_Drawing_TextStyle object, which is obtained from OH_Drawing_CreateTextStyle.

Returns

TypeDescription
OH_Drawing_TextDecorationStyleText decoration style. For details, see OH_Drawing_TextDecorationStyle.

OH_Drawing_TextStyleGetFontWeight()

OH_Drawing_FontWeight OH_Drawing_TextStyleGetFontWeight(OH_Drawing_TextStyle* style)

Description

Obtains the font weight of a text style.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_TextStyle* stylePointer to the OH_Drawing_TextStyle object, which is obtained from OH_Drawing_CreateTextStyle.

Returns

TypeDescription
OH_Drawing_FontWeightFont weight. For details, see OH_Drawing_FontWeight.

OH_Drawing_TextStyleGetFontStyle()

OH_Drawing_FontStyle OH_Drawing_TextStyleGetFontStyle(OH_Drawing_TextStyle* style)

Description

Obtains the font style of a text style.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_TextStyle* stylePointer to the OH_Drawing_TextStyle object, which is obtained from OH_Drawing_CreateTextStyle.

Returns

TypeDescription
OH_Drawing_FontStyleFont style. For details, see OH_Drawing_FontStyle.

OH_Drawing_TextStyleGetBaseline()

OH_Drawing_TextBaseline OH_Drawing_TextStyleGetBaseline(OH_Drawing_TextStyle* style)

Description

Obtains the baseline of a text style.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_TextStyle* stylePointer to the OH_Drawing_TextStyle object, which is obtained from OH_Drawing_CreateTextStyle.

Returns

TypeDescription
OH_Drawing_TextBaselineFont baseline position. For details, see OH_Drawing_TextBaseline.

OH_Drawing_TextStyleGetFontFamilies()

char** OH_Drawing_TextStyleGetFontFamilies(OH_Drawing_TextStyle* style, size_t* num)

Description

Obtains the font families of a text style.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_TextStyle* stylePointer to the OH_Drawing_TextStyle object, which is obtained from OH_Drawing_CreateTextStyle.
size_t* numPointer to the number of font families.

Returns

TypeDescription
char**Font families.

OH_Drawing_TextStyleDestroyFontFamilies()

void OH_Drawing_TextStyleDestroyFontFamilies(char** fontFamilies, size_t num)

Description

Reclaims the memory occupied by the font families, where num specifies the number of font families.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
char** fontFamiliesDouble pointer to the font families.
size_t numNumber of font families.

OH_Drawing_TextStyleGetFontSize()

double OH_Drawing_TextStyleGetFontSize(OH_Drawing_TextStyle* style)

Description

Obtains the font size of a text style.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_TextStyle* stylePointer to the OH_Drawing_TextStyle object, which is obtained from OH_Drawing_CreateTextStyle.

Returns

TypeDescription
doubleFont size.

OH_Drawing_TextStyleGetLetterSpacing()

double OH_Drawing_TextStyleGetLetterSpacing(OH_Drawing_TextStyle* style)

Description

Obtains the letter spacing of a text style.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_TextStyle* stylePointer to the OH_Drawing_TextStyle object, which is obtained from OH_Drawing_CreateTextStyle.

Returns

TypeDescription
doubleLetter spacing.

OH_Drawing_TextStyleGetWordSpacing()

double OH_Drawing_TextStyleGetWordSpacing(OH_Drawing_TextStyle* style)

Description

Obtains the word spacing of a text style.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_TextStyle* stylePointer to the OH_Drawing_TextStyle object, which is obtained from OH_Drawing_CreateTextStyle.

Returns

TypeDescription
doubleWord spacing.

OH_Drawing_TextStyleGetFontHeight()

double OH_Drawing_TextStyleGetFontHeight(OH_Drawing_TextStyle* style)

Description

Obtains the font height of a text style.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_TextStyle* stylePointer to the OH_Drawing_TextStyle object, which is obtained from OH_Drawing_CreateTextStyle.

Returns

TypeDescription
doubleFont height of a text style.

OH_Drawing_TextStyleGetHalfLeading()

bool OH_Drawing_TextStyleGetHalfLeading(OH_Drawing_TextStyle* style)

Description

Checks whether half leading is enabled for a text style.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_TextStyle* stylePointer to the OH_Drawing_TextStyle object, which is obtained from OH_Drawing_CreateTextStyle.

Returns

TypeDescription
boolWhether half leading is enabled for a text style. true means enabled; false otherwise.

OH_Drawing_TextStyleGetLocale()

const char* OH_Drawing_TextStyleGetLocale(OH_Drawing_TextStyle* style)

Description

Obtains the locale of a text style.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_TextStyle* stylePointer to the OH_Drawing_TextStyle object, which is obtained from OH_Drawing_CreateTextStyle.

Returns

TypeDescription
const char*Pointer to the locale in the format of language-country. For example, zh-CN indicates Chinese (China), and en-US indicates English (United States). For details, see BCP 47.

OH_Drawing_TypographyDestroyTextBox()

void OH_Drawing_TypographyDestroyTextBox(OH_Drawing_TextBox* textBox)

Description

Releases the memory occupied by a text box.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_TextBox* textBoxPointer to the OH_Drawing_TextBox object.

OH_Drawing_SetTextShadow()

void OH_Drawing_SetTextShadow(OH_Drawing_TextShadow* shadow, uint32_t color, OH_Drawing_Point* offset,double blurRadius)

Description

Sets a text shadow.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 12

Parameters

NameDescription
OH_Drawing_TextShadow* shadowPointer to the OH_Drawing_TextShadow object, which is obtained from OH_Drawing_CreateTextShadow.
uint32_t colorColor of the text shadow. For example, if the input parameter is 0xAABBCCDD, AA indicates opacity, BB indicates the value of the red component, CC indicates the value of the green component, and DD indicates the value of the blue component.
OH_Drawing_Point* offsetPointer to the OH_Drawing_Point object, which is the offset of the text shadow relative to the text.
double blurRadiusBlur radius. The value is a floating point number and has no unit. The value 0.0 means that there is no blur effect.

OH_Drawing_CreateTextTab()

OH_Drawing_TextTab* OH_Drawing_CreateTextTab(OH_Drawing_TextAlign alignment, float location)

Description

Creates a text tab object.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 18

Parameters

NameDescription
OH_Drawing_TextAlign alignmentAlignment mode of the text following the tab character. The value 1 means right alignment, 2 means center alignment, and 0 or other values mean left alignment.
float locationAlignment position of the text following the tab character. The unit is px. The minimum value is 1.0.

Returns

TypeDescription
OH_Drawing_TextTab*Pointer to the OH_Drawing_TextTab object created. If a null pointer is returned, the creation fails. A possible cause is that no memory is available.

OH_Drawing_DestroyTextTab()

void OH_Drawing_DestroyTextTab(OH_Drawing_TextTab* tab)

Description

Releases the memory occupied by a text tab object.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 18

Parameters

NameDescription
OH_Drawing_TextTab* tabPointer to an OH_Drawing_TextTab object.

OH_Drawing_GetTextTabAlignment()

OH_Drawing_TextAlign OH_Drawing_GetTextTabAlignment(OH_Drawing_TextTab* tab)

Description

Obtains the alignment mode of a text tab.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 18

Parameters

NameDescription
OH_Drawing_TextTab* tabPointer to an OH_Drawing_TextTab object.

Returns

TypeDescription
OH_Drawing_TextAlignAlignment mode. The value 1 means right alignment, 2 means center alignment, and 0 or other values mean left alignment.

OH_Drawing_GetTextTabLocation()

float OH_Drawing_GetTextTabLocation(OH_Drawing_TextTab* tab)

Description

Obtains the location of a text tab.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 18

Parameters

NameDescription
OH_Drawing_TextTab* tabPointer to an OH_Drawing_TextTab object.

Returns

TypeDescription
floatPosition of the text tab.

OH_Drawing_SetTypographyTextTab()

void OH_Drawing_SetTypographyTextTab(OH_Drawing_TypographyStyle* style, OH_Drawing_TextTab* tab)

Description

Sets the alignment mode and location of a text tab. When the text alignment mode or ellipsis style is set, the tab does not take effect. When the tab location is less than 1.0, the tab is replaced with a space.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 18

Parameters

NameDescription
OH_Drawing_TypographyStyle* stylePointer to the OH_Drawing_TypographyStyle object.
OH_Drawing_TextTab* tabPointer to an OH_Drawing_TextTab object.

OH_Drawing_GetDrawingArraySize()

size_t OH_Drawing_GetDrawingArraySize(OH_Drawing_Array* drawingArray)

Description

Obtains the number of objects in the input object array OH_Drawing_Array.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 14

Parameters

NameDescription
OH_Drawing_Array* drawingArrayPointer to the OH_Drawing_Array object array.

Returns

TypeDescription
size_tNumber of objects in the array.

OH_Drawing_SetTypographyTextTrailingSpaceOptimized()

void OH_Drawing_SetTypographyTextTrailingSpaceOptimized(OH_Drawing_TypographyStyle* style, bool trailingSpaceOptimized)

Description

Sets whether to include the trailing spaces in alignment calculations during text typography.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 20

Parameters

NameDescription
OH_Drawing_TypographyStylePointer to the OH_Drawing_TypographyStyle object.
boolSets whether to include the trailing spaces in alignment calculations during text typography. true means not to include; false (default) means to include. You are advised to set this parameter to true for center-aligned text.

OH_Drawing_TypographyHandlerAddEncodedText()

void OH_Drawing_TypographyHandlerAddEncodedText(OH_Drawing_TypographyCreate* handler, const void* text,size_t byteLength, OH_Drawing_TextEncoding textEncodingType)

Description

Adds text encoded in a specified format.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 20

Parameters

NameDescription
OH_Drawing_TypographyCreate* handlerPointer to the OH_Drawing_TypographyCreate object, which is obtained from OH_Drawing_CreateTypographyHandler.
const void* textPointer to the text content.
size_t byteLengthLength of the text, in bytes.
OH_Drawing_TextEncoding textEncodingTypeText encoding type, which is an enumerated value of OH_Drawing_TextEncoding. Only TEXT_ENCODING_UTF8, TEXT_ENCODING_UTF16, and TEXT_ENCODING_UTF32 are supported.

OH_Drawing_SetTypographyTextAutoSpace()

void OH_Drawing_SetTypographyTextAutoSpace(OH_Drawing_TypographyStyle *style, bool enableAutoSpace)

Description

Sets whether to enable automatic spacing during text typography.
This feature is disabled by default. If enabled, automatic spacing applies between CJK (Chinese, Japanese, and Korean) and Western characters (Latin, Cyrillic, and Greek), between CJK and digits, between CJK and copyright symbols, between copyright symbols and digits, and between copyright symbols and Western characters.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 20

Parameters

NameDescription
OH_Drawing_TypographyStyle *stylePointer to the OH_Drawing_TypographyStyle object, which is obtained from OH_Drawing_CreateTypographyStyle.
bool enableAutoSpaceSets whether to enable automatic spacing during text typography. true means enabled; false (default) means disabled.

OH_Drawing_TypographyUpdateDecorationColor()

void OH_Drawing_TypographyUpdateDecorationColor(OH_Drawing_Typography* typography, uint32_t color)

Description

Updates the decoration color of a typography object.
The updated decoration color takes effect after you call OH_Drawing_TypographyPaint to draw the text.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 20

Parameters

NameDescription
OH_Drawing_Typography* typographyPointer to the OH_Drawing_Typography object, which is obtained from OH_Drawing_CreateTypography.
uint32_t colorUpdated text decoration color.

OH_Drawing_SetTypographyVerticalAlignment()

void OH_Drawing_SetTypographyVerticalAlignment(OH_Drawing_TypographyStyle* style,OH_Drawing_TextVerticalAlignment align)

Description

Vertical alignment mode of the text.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 20

Parameters

NameDescription
OH_Drawing_TypographyStyle* stylePointer to the OH_Drawing_TypographyStyle object, which is obtained from OH_Drawing_CreateTypographyStyle.
OH_Drawing_TextVerticalAlignment alignVertical alignment mode of the text. The default mode is baseline alignment. For details about other options, see OH_Drawing_TextVerticalAlignment.

OH_Drawing_CopyTypographyStyle()

OH_Drawing_TypographyStyle* OH_Drawing_CopyTypographyStyle(OH_Drawing_TypographyStyle* style)

Description

Creates a copy of an existing paragraph style object.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 20

Parameters

NameDescription
OH_Drawing_TypographyStyle* stylePointer to the OH_Drawing_TypographyStyle object to be copied.

Returns

TypeDescription
OH_Drawing_TypographyStyle*Pointer to the copied OH_Drawing_TypographyStyle object. If a null pointer is returned, the creation fails. The possible cause is that no memory is available or style is a null pointer. Release this pointer by calling OH_Drawing_DestroyTypographyStyle when this object is no longer needed.

OH_Drawing_CopyTextStyle()

OH_Drawing_TextStyle* OH_Drawing_CopyTextStyle(OH_Drawing_TextStyle* style)

Description

Creates a copy of an existing text style object.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 20

Parameters

NameDescription
OH_Drawing_TextStyle* stylePointer to the OH_Drawing_TextStyle object to be copied.

Returns

TypeDescription
OH_Drawing_TextStyle*Pointer to the copied OH_Drawing_TextStyle object. If a null pointer is returned, the creation fails. The possible cause is that no memory is available or style is a null pointer. Release this pointer by calling OH_Drawing_DestroyTextStyle when this object is no longer needed.

OH_Drawing_CopyTextShadow()

OH_Drawing_TextShadow* OH_Drawing_CopyTextShadow(OH_Drawing_TextShadow* shadow)

Description

Creates a copy of an existing text shadow object.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 20

Parameters

NameDescription
OH_Drawing_TextShadow* shadowPointer to the OH_Drawing_TextShadow object to be copied.

Returns

TypeDescription
OH_Drawing_TextShadow*Pointer to the copied OH_Drawing_TextShadow object. If a null pointer is returned, the creation fails. The possible cause is that no memory is available or shadow is a null pointer. Release this pointer by calling OH_Drawing_DestroyTextShadow when this object is no longer needed.

OH_Drawing_SetTextStyleAttributeDouble()

OH_Drawing_ErrorCode OH_Drawing_SetTextStyleAttributeDouble(OH_Drawing_TextStyle* style, OH_Drawing_TextStyleAttributeId id, double value)

Description

Sets the text style attribute of the double type.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 21

Parameters

NameDescription
OH_Drawing_TextStyle* stylePointer to an OH_Drawing_TextStyle object.
OH_Drawing_TextStyleAttributeId idText style attribute ID.
double valueText style attribute value.

Returns

TypeDescription
OH_Drawing_ErrorCodeReturns the execution result.
OH_DRAWING_SUCCESS if the operation is successful.
OH_DRAWING_ERROR_INVALID_PARAMETER if style is NULL.
OH_DRAWING_ERROR_ATTRIBUTE_ID_MISMATCH if the input attribute ID does not match the called function.

OH_Drawing_GetTextStyleAttributeDouble()

OH_Drawing_ErrorCode OH_Drawing_GetTextStyleAttributeDouble(OH_Drawing_TextStyle* style, OH_Drawing_TextStyleAttributeId id, double* value)

Description

Obtains the text style attribute of the double type.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 21

Parameters

NameDescription
OH_Drawing_TextStyle* stylePointer to an OH_Drawing_TextStyle object.
OH_Drawing_TextStyleAttributeId idText style attribute ID.
double* valuePointer to the attribute of the double type. It is used as an output parameter.

Returns

TypeDescription
OH_Drawing_ErrorCodeReturns the execution result.
OH_DRAWING_SUCCESS if the operation is successful.
OH_DRAWING_ERROR_INVALID_PARAMETER if style is NULL.
OH_DRAWING_ERROR_ATTRIBUTE_ID_MISMATCH if the input attribute ID does not match the called function.

OH_Drawing_SetTextStyleAttributeInt()

OH_Drawing_ErrorCode OH_Drawing_SetTextStyleAttributeInt(OH_Drawing_TextStyle* style, OH_Drawing_TextStyleAttributeId id, int value)

Description

Sets the text style attribute of the int type.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 21

Parameters

NameDescription
OH_Drawing_TextStyle* stylePointer to an OH_Drawing_TextStyle object.
OH_Drawing_TextStyleAttributeId idText style attribute ID.
int valueAttribute value to set.

Returns

TypeDescription
OH_Drawing_ErrorCodeReturns the execution result.
OH_DRAWING_SUCCESS if the operation is successful.
OH_DRAWING_ERROR_INVALID_PARAMETER if style is NULL.
OH_DRAWING_ERROR_ATTRIBUTE_ID_MISMATCH if the input attribute ID does not match the called function.
OH_DRAWING_ERROR_PARAMETER_OUT_OF_RANGE if the input value exceeds the value range of the attribute to be set.

OH_Drawing_GetTextStyleAttributeInt()

OH_Drawing_ErrorCode OH_Drawing_GetTextStyleAttributeInt(OH_Drawing_TextStyle* style, OH_Drawing_TextStyleAttributeId id, int* value)

Description

Obtains the text style attribute of the int type.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 21

Parameters

NameDescription
OH_Drawing_TextStyle* stylePointer to an OH_Drawing_TextStyle object.
OH_Drawing_TextStyleAttributeId idText style attribute ID.
int* valuePointer to the attribute of the int type. It is used as an output parameter.

Returns

TypeDescription
OH_Drawing_ErrorCodeReturns the execution result.
OH_DRAWING_SUCCESS if the operation is successful.
OH_DRAWING_ERROR_INVALID_PARAMETER if style is NULL.
OH_DRAWING_ERROR_ATTRIBUTE_ID_MISMATCH if the input attribute ID does not match the called function.

OH_Drawing_SetTypographyStyleAttributeDouble()

OH_Drawing_ErrorCode OH_Drawing_SetTypographyStyleAttributeDouble(OH_Drawing_TypographyStyle* style, OH_Drawing_TypographyStyleAttributeId id, double value)

Description

Sets the typography style attribute of the double type.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 21

Parameters

NameDescription
OH_Drawing_TypographyStyle* stylePointer to an OH_Drawing_TypographyStyle object.
OH_Drawing_TypographyStyleAttributeId idAttribute ID of the text style.
double valueAttribute value to set.

Returns

TypeDescription
OH_Drawing_ErrorCodeReturns the execution result.
OH_DRAWING_SUCCESS if the operation is successful.
OH_DRAWING_ERROR_INVALID_PARAMETER if style is NULL.
OH_DRAWING_ERROR_ATTRIBUTE_ID_MISMATCH if the input attribute ID does not match the called function.

OH_Drawing_GetTypographyStyleAttributeDouble()

OH_Drawing_ErrorCode OH_Drawing_GetTypographyStyleAttributeDouble(OH_Drawing_TypographyStyle* style, OH_Drawing_TypographyStyleAttributeId id, double* value)

Description

Obtains the typography style attribute of the double type.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 21

Parameters

NameDescription
OH_Drawing_TypographyStyle* stylePointer to an OH_Drawing_TypographyStyle object.
OH_Drawing_TypographyStyleAttributeId idAttribute ID of the text style.
double* valuePointer to the attribute of the double type. It is used as an output parameter.

Returns

TypeDescription
OH_Drawing_ErrorCodeReturns the execution result.
OH_DRAWING_SUCCESS if the operation is successful.
OH_DRAWING_ERROR_INVALID_PARAMETER if style is NULL.
OH_DRAWING_ERROR_ATTRIBUTE_ID_MISMATCH if the input attribute ID does not match the called function.

OH_Drawing_SetTypographyStyleAttributeInt()

OH_Drawing_ErrorCode OH_Drawing_SetTypographyStyleAttributeInt(OH_Drawing_TypographyStyle* style, OH_Drawing_TypographyStyleAttributeId id, int value)

Description

Sets the typography style attribute of the int type.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 21

Parameters

NameDescription
OH_Drawing_TypographyStyle* stylePointer to an OH_Drawing_TypographyStyle object.
OH_Drawing_TypographyStyleAttributeId idAttribute ID of the text style.
int valueAttribute value to set.

Returns

TypeDescription
OH_Drawing_ErrorCodeReturns the execution result.
OH_DRAWING_SUCCESS if the operation is successful.
OH_DRAWING_ERROR_INVALID_PARAMETER if style is NULL.
OH_DRAWING_ERROR_ATTRIBUTE_ID_MISMATCH if the input attribute ID does not match the called function.
OH_DRAWING_ERROR_PARAMETER_OUT_OF_RANGE if the input value exceeds the value range of the attribute to be set.

OH_Drawing_GetTypographyStyleAttributeInt()

OH_Drawing_ErrorCode OH_Drawing_GetTypographyStyleAttributeInt(OH_Drawing_TypographyStyle* style, OH_Drawing_TypographyStyleAttributeId id, int* value)

Description

Obtains the typography style attribute of the int type.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 21

Parameters

NameDescription
OH_Drawing_TypographyStyle* stylePointer to an OH_Drawing_TypographyStyle object.
OH_Drawing_TypographyStyleAttributeId idAttribute ID of the text style.
int* valuePointer to the attribute of the int type. It is used as an output parameter.

Returns

TypeDescription
OH_Drawing_ErrorCodeReturns the execution result.
OH_DRAWING_SUCCESS if the operation is successful.
OH_DRAWING_ERROR_INVALID_PARAMETER if style is NULL.
OH_DRAWING_ERROR_ATTRIBUTE_ID_MISMATCH if the input attribute ID does not match the called function.

OH_Drawing_SetTypographyStyleAttributeBool()

OH_Drawing_ErrorCode OH_Drawing_SetTypographyStyleAttributeBool(OH_Drawing_TypographyStyle* style, OH_Drawing_TypographyStyleAttributeId id, bool value)

Description

Sets the typography style attribute of the bool type.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 23

Parameters

NameDescription
OH_Drawing_TypographyStyle* stylePointer to an OH_Drawing_TypographyStyle object.
OH_Drawing_TypographyStyleAttributeId idAttribute ID of the text style.
bool valueAttribute value to set.

Returns

TypeDescription
OH_Drawing_ErrorCodeReturns the execution result.
OH_DRAWING_SUCCESS if the operation is successful.
OH_DRAWING_ERROR_INCORRECT_PARAMETER if style is NULL.
OH_DRAWING_ERROR_ATTRIBUTE_ID_MISMATCH if the input attribute ID does not match the called function.

OH_Drawing_GetTypographyStyleAttributeBool()

OH_Drawing_ErrorCode OH_Drawing_GetTypographyStyleAttributeBool(OH_Drawing_TypographyStyle* style, OH_Drawing_TypographyStyleAttributeId id, bool* value)

Description

Obtains the typography style attribute of the bool type.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 23

Parameters

NameDescription
OH_Drawing_TypographyStyle* stylePointer to an OH_Drawing_TypographyStyle object.
OH_Drawing_TypographyStyleAttributeId idAttribute ID of the text style.
bool* valuePointer to the bool attribute. It is used as an output parameter.

Returns

TypeDescription
OH_Drawing_ErrorCodeReturns the execution result.
OH_DRAWING_SUCCESS if the operation is successful.
OH_DRAWING_ERROR_INCORRECT_PARAMETER if style or value is NULL.
OH_DRAWING_ERROR_ATTRIBUTE_ID_MISMATCH if the input attribute ID does not match the called function.

OH_Drawing_SetTypographyStyleAttributeDoubleArray()

OH_Drawing_ErrorCode OH_Drawing_SetTypographyStyleAttributeDoubleArray(OH_Drawing_TypographyStyle* style, OH_Drawing_TypographyStyleAttributeId id, double* arrayValue, size_t arrayLength)

Description

Sets the typography style attribute of the floating-point array type.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 26.0.0

Parameters

NameDescription
OH_Drawing_TypographyStyle* stylePointer to an OH_Drawing_TypographyStyle object.
OH_Drawing_TypographyStyleAttributeId idAttribute ID of the text style.
double* arrayValuePointer to the floating-point array.
size_t arrayLengthLength of the floating-point array.

Returns

TypeDescription
OH_Drawing_ErrorCodeReturns the execution result.
OH_DRAWING_SUCCESS if the operation is successful.
OH_DRAWING_ERROR_INCORRECT_PARAMETER if the parameter style or arrayValue is a null pointer or arrayLength is 0.
OH_DRAWING_ERROR_ATTRIBUTE_ID_MISMATCH if the input attribute ID does not match the called function.

OH_Drawing_GetTypographyStyleAttributeDoubleArray()

OH_Drawing_ErrorCode OH_Drawing_GetTypographyStyleAttributeDoubleArray(const OH_Drawing_TypographyStyle* style, OH_Drawing_TypographyStyleAttributeId id, double** arrayValue, size_t* arrayLength)

Description

Obtains the typography style attribute of the floating-point array type.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 26.0.0

Parameters

NameDescription
const OH_Drawing_TypographyStyle* stylePointer to an OH_Drawing_TypographyStyle object.
OH_Drawing_TypographyStyleAttributeId idAttribute ID of the text style.
double** arrayValuePointer to the floating-point array. It is used as an output parameter.
size_t* arrayLengthLength of the floating-point array. It is used as an output parameter.

Returns

TypeDescription
OH_Drawing_ErrorCodeReturns the execution result.
OH_DRAWING_SUCCESS if the operation is successful.
OH_DRAWING_ERROR_INCORRECT_PARAMETER if the parameter style or arrayValue is a null pointer or arrayLength is 0.
OH_DRAWING_ERROR_ATTRIBUTE_ID_MISMATCH if the input attribute ID does not match the called function.

OH_Drawing_DestroyPositionAndAffinity()

void OH_Drawing_DestroyPositionAndAffinity(OH_Drawing_PositionAndAffinity* positionAndAffinity)

Description

Destroys an OH_Drawing_PositionAndAffinity object and reclaims the memory occupied by the object.

Since: 23

Parameters

NameDescription
OH_Drawing_PositionAndAffinity* positionAndAffinityPointer to the OH_Drawing_PositionAndAffinity object.

OH_Drawing_TypographyGetCharacterRangeForGlyphRangeWithBuffer()

OH_Drawing_Range* OH_Drawing_TypographyGetCharacterRangeForGlyphRangeWithBuffer(OH_Drawing_Typography* typography, size_t glyphRangeStart, size_t glyphRangeEnd, OH_Drawing_Range** actualGlyphRange, OH_Drawing_TextEncoding textEncodingType)

Description

Obtains the character range corresponding to the specified glyph range.

Since: 24

Parameters

NameDescription
OH_Drawing_Typography* typographyPointer to the OH_Drawing_Typography object, which is obtained from OH_Drawing_CreateTypography.
size_t glyphRangeStartStart position of the glyph range.
size_t glyphRangeEndEnd position of the glyph range.
OH_Drawing_Range** actualGlyphRangeReturns the actual font range, indicating the level-2 pointer to OH_Drawing_Range. It is used as an output parameter.
When the requested glyph range contains only a part of a complex glyph sequence, this parameter returns the corresponding complete glyph range.
For example, ligatures and combined emojis may consist of multiple atomic glyphs and must be processed as a whole.
If this parameter is NULL, the actual glyph range is not returned, indicating that the caller does not care about the actual glyph range information.
After use, release the object through the OH_Drawing_ReleaseRangeBuffer API.
OH_Drawing_TextEncoding textEncodingTypeText encoding type OH_Drawing_TextEncoding.
Currently, only UTF-8 and UTF-16 encoding types are supported.
For UTF-8 encoding, the returned character range indicates the byte range.
For UTF-16 encoding, the returned character range indicates the UTF-16 code unit range.

Returns

TypeDescription
OH_Drawing_Range*Returns the OH_Drawing_Range object pointer that indicates the character range. When the object is no longer needed, use the OH_Drawing_ReleaseRangeBuffer API to release it.

OH_Drawing_TypographyGetCharacterPositionAtCoordinateWithBuffer()

OH_Drawing_PositionAndAffinity* OH_Drawing_TypographyGetCharacterPositionAtCoordinateWithBuffer(OH_Drawing_Typography* typography, double dx, double dy, OH_Drawing_TextEncoding textEncodingType)

Description

Obtains the character position information closest to the specified coordinates.

Since: 24

Parameters

NameDescription
OH_Drawing_Typography* typographyPointer to the OH_Drawing_Typography object, which is obtained from OH_Drawing_CreateTypography.
double dxHorizontal coordinate in the text layout area, in physical pixels (px).
X offset relative to the top-left corner of the text layout area, with the right direction as positive.
Supports floating-point values and accepts negative values, which indicate positions to the left of the text layout area.
If the coordinates are beyond the text layout area, the nearest character position is returned. It can be obtained through a touch event or click event.
double dyVertical coordinate in the text layout area, in physical pixels (px).
Y offset relative to the top-left corner of the text layout area, with the downward direction as positive.
Supports floating-point values and accepts negative values, which indicate positions above the text layout area.
If the coordinates are beyond the text layout area, the nearest character position is returned. It can be obtained through a touch event or click event.
OH_Drawing_TextEncoding textEncodingTypeText encoding type OH_Drawing_TextEncoding.
Currently, only UTF-8 and UTF-16 encoding types are supported.
For UTF-8 encoding, the returned position indicates the byte offset. For UTF-16 encoding, the returned position indicates the UTF-16 code unit offset.

Returns

TypeDescription
OH_Drawing_PositionAndAffinity*Returns the character index position and affinity at the coordinate. The return type is the OH_Drawing_PositionAndAffinity structure.
When the object is no longer needed, call OH_Drawing_DestroyPositionAndAffinity to release it.

OH_Drawing_TypographyGetGlyphRangeForCharacterRangeWithBuffer()

OH_Drawing_Range* OH_Drawing_TypographyGetGlyphRangeForCharacterRangeWithBuffer(OH_Drawing_Typography* typography, size_t characterRangeStart, size_t characterRangeEnd, OH_Drawing_Range** actualCharacterRange, OH_Drawing_TextEncoding textEncodingType)

Description

Obtains the glyph range corresponding to the specified character range.

Since: 24

Parameters

NameDescription
OH_Drawing_Typography* typographyPointer to the OH_Drawing_Typography object, which is obtained from OH_Drawing_CreateTypography.
size_t characterRangeStartStart position of the character range.
size_t characterRangeEndEnd position of the character range.
OH_Drawing_Range** actualCharacterRangeReturns the actual character range, indicating the level-2 pointer to OH_Drawing_Range. It is used as an output parameter.
When the requested character range contains only a part of the combined character sequence, this parameter returns the corresponding complete character range.
For example, a combined character consisting of a base character and a diacritical mark must be processed as a whole.
If this parameter is NULL, the actual character range is not returned, indicating that the caller does not care about the actual character range information.
After use, release the object through the OH_Drawing_ReleaseRangeBuffer API.
OH_Drawing_TextEncoding textEncodingTypeText encoding type OH_Drawing_TextEncoding.
Currently, only UTF-8 and UTF-16 encoding types are supported.
For UTF-8 encoding, the input character range should be interpreted as a byte range. For UTF-16 encoding, the input character range should be interpreted as a UTF-16 code unit range.

Returns

TypeDescription
OH_Drawing_Range*Returns the OH_Drawing_Range object pointer that indicates the font range. If the object is no longer needed, use the OH_Drawing_ReleaseRangeBuffer API to release it.

OH_Drawing_ReleaseRangeBuffer()

void OH_Drawing_ReleaseRangeBuffer(OH_Drawing_Range* range)

Description

Releases the memory occupied by the OH_Drawing_Range object.

Since: 24

Parameters

NameDescription
OH_Drawing_Range* rangePointer to the OH_Drawing_Range object.

OH_Drawing_TypographyLayoutWithConstraintsWithBuffer()

OH_Drawing_RectSize OH_Drawing_TypographyLayoutWithConstraintsWithBuffer(OH_Drawing_Typography* typography, OH_Drawing_RectSize constraintsRect, OH_Drawing_Array** fitStrRangeArr, size_t* fitStrRangeArrayLen)

Description

Arranges the text in the constraint rectangle.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 24

Parameters

NameDescription
OH_Drawing_Typography* typographyPointer to the OH_Drawing_Typography object, which is obtained from OH_Drawing_CreateTypography.
OH_Drawing_RectSize constraintsRectHeight and width of the constrained layout.
OH_Drawing_Array** fitStrRangeArrAs an output parameter, it contains the character range of the paragraph text that is actually contained. Pointer to array object OH_Drawing_Array.
Releases the memory through OH_Drawing_ReleaseArrayBuffer.
size_t* fitStrRangeArrayLenAs an output parameter, it indicates the size of the contained string array.

Returns

TypeDescription
OH_Drawing_RectSizeReturns the OH_Drawing_RectSize object, indicating the actual rectangle of the paragraph text.

OH_Drawing_GetRangeByArrayIndex()

OH_Drawing_Range* OH_Drawing_GetRangeByArrayIndex(OH_Drawing_Array* array, size_t index)

Description

Obtains the pointer to the OH_Drawing_Range object based on the array index.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 24

Parameters

NameDescription
OH_Drawing_Array* arrayPointer to array object OH_Drawing_Array.
size_t indexIndex of the target OH_Drawing_Range object in the array.

Returns

TypeDescription
OH_Drawing_Range*Returns the pointer to the OH_Drawing_Range object.

OH_Drawing_ReleaseArrayBuffer()

OH_Drawing_ErrorCode OH_Drawing_ReleaseArrayBuffer(OH_Drawing_Array* array)

Description

Releases the memory occupied by the OH_Drawing_Array object.

System capability: SystemCapability.Graphic.Graphic2D.NativeDrawing

Since: 24

Parameters

NameDescription
OH_Drawing_Array* arrayPointer to array object OH_Drawing_Array.
Supported array types:
Array of full font names, which is obtained through OH_Drawing_GetSystemFontFullNamesByType.
Array of text lines, which is obtained through OH_Drawing_TypographyGetTextLines.
Array of string indexes, which is obtained through OH_Drawing_GetRunStringIndices.
Array of rectangles, which is obtained through OH_Drawing_RectCreateArray.
Array of font descriptors, which is obtained through OH_Drawing_GetFontFullDescriptorsFromStream or OH_Drawing_GetFontFullDescriptorsFromPath.
Array of text ranges, which is obtained through OH_Drawing_TypographyLayoutWithConstraintsWithBuffer.

Returns

TypeDescription
OH_Drawing_ErrorCodeReturns the execution result.
OH_DRAWING_SUCCESS if the operation is successful.
OH_DRAWING_ERROR_INCORRECT_PARAMETER if array is a null pointer or the type is not supported.

OH_Drawing_TextStyleAddFontVariationWithNormalization()

void OH_Drawing_TextStyleAddFontVariationWithNormalization(OH_Drawing_TextStyle* style, const char* axis, const float normalizedValue)

Description

Adds the normalized variable font attributes. This function takes effect only when the corresponding font file (.ttf file) supports variable adjustment.

Since: 24

Parameters

NameDescription
OH_Drawing_TextStyle* stylePointer to the OH_Drawing_TextStyle object, which is obtained from OH_Drawing_CreateTextStyle.
const char* axisPointer to the key in the font variation key-value pair.
const float normalizedValueValue of the font variation key-value pair. The normalized value range is [-1,1], mapping the range from the minimum value to the maximum value configured in the font file. 0 indicates the default value configured in the font file.

你可能感兴趣的鸿蒙文章

openharmony 鸿蒙 capi-drawing-gpu-context-h

openharmony 鸿蒙 capi-drawing-nativepixelmap-

openharmony 鸿蒙 capi-nativevsync-oh-nativevsync-expectedraterange

openharmony 鸿蒙 capi-drawing-oh-drawing-brush

openharmony 鸿蒙 capi-drawing-oh-drawing-image-info

openharmony 鸿蒙 capi-drawing-text-linetypography-h

openharmony 鸿蒙 capi-oh-nativeimage-oh-nativeimage

openharmony 鸿蒙 capi-drawing-typeface-h

openharmony 鸿蒙 capi-drawing-brush-h

openharmony 鸿蒙 capi-nativewindow

  • 所属分类: 后端技术
  • 本文标签: 软件 鸿蒙
  • 版权声明: 本文链接 https://seaxiang.com/blog/nVaCOcKQ