diff --git a/graphic/graphic_2d/native_drawing/drawing_font.h b/graphic/graphic_2d/native_drawing/drawing_font.h index cbbec950c9737b44aeb3cac1d7b5e8b87151a8e6..0fe56c1d5f23a2f4eaa43e7d222b5669450d38f4 100644 --- a/graphic/graphic_2d/native_drawing/drawing_font.h +++ b/graphic/graphic_2d/native_drawing/drawing_font.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2023-2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -53,6 +53,104 @@ extern "C" { */ OH_Drawing_Font* OH_Drawing_FontCreate(void); +/** + * @brief Enumerates font hinting pattern. + * + * @since 12 + * @version 1.0 + */ +typedef enum { + /** glyph outlines unchanged */ + FONT_HINTING_NONE, + /** minimal modification to improve contrast */ + FONT_HINTING_SLIGHT, + /** glyph outlines modified to improve contrast */ + FONT_HINTING_NORMAL, + /** modifies glyph outlines for maximum contrast */ + FONT_HINTING_FULL, +} OH_Drawing_FontHinting; + +/** + * @brief Enumerates font edging effect. + * + * @since 12 + * @version 1.0 + */ +typedef enum { + /** no transparent pixels on glyph edges */ + FONT_EDGING_ALIAS, + /** may have transparent pixels on glyph edges */ + FONT_EDGING_ANTI_ALIAS, + /** glyph positioned in pixel using transparency */ + FONT_EDGING_SUBPIXEL_ANTI_ALIAS, +} OH_Drawing_FontEdging; + +/** + * @brief Sets whether the font baselines and pixels alignment when the transformation matrix is ​​axis aligned. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param OH_Drawing_Font Indicates the pointer to an OH_Drawing_Font object. + * @param baselineSnap Indicates whether the font baselines and pixels alignment. + * @since 12 + * @version 1.0 + */ +void OH_Drawing_FontSetBaselineSnap(OH_Drawing_Font*, bool baselineSnap); + +/** + * @brief Gets whether the font baselines and pixels alignment when the transformation matrix is ​​axis aligned. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param OH_Drawing_Font Indicates the pointer to an OH_Drawing_Font object. + * @return Returns true if the font baselines and pixels alignment; returns false otherwise. + * @since 12 + * @version 1.0 + */ +bool OH_Drawing_FontIsBaselineSnap(const OH_Drawing_Font*); + +/** + * @brief Sets whether the font uses sub-pixel rendering. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param OH_Drawing_Font Indicates the pointer to an OH_Drawing_Font object. + * @param isSubpixel Indicates whether the font uses sub-pixel rendering. + * @since 12 + * @version 1.0 + */ +void OH_Drawing_FontSetSubpixel(OH_Drawing_Font*, bool isSubpixel); + +/** + * @brief Gets whether the font uses sub-pixel rendering. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param OH_Drawing_Font Indicates the pointer to an OH_Drawing_Font object. + * @return Returns true if the font uses sub-pixel rendering; returns false otherwise. + * @since 12 + * @version 1.0 + */ +bool OH_Drawing_FontIsSubpixel(const OH_Drawing_Font*); + +/** + * @brief Sets whether the font outline is automatically adjusted. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param OH_Drawing_Font Indicates the pointer to an OH_Drawing_Font object. + * @param isForceAutoHinting Indicates whether the font outline is automatically adjusted. + * @since 12 + * @version 1.0 + */ +void OH_Drawing_FontSetForceAutoHinting(OH_Drawing_Font*, bool isForceAutoHinting); + +/** + * @brief Gets whether the font outline is automatically adjusted. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param OH_Drawing_Font Indicates the pointer to an OH_Drawing_Font object. + * @return Returns true if the font outline is automatically adjusted; returns false otherwise. + * @since 12 + * @version 1.0 + */ +bool OH_Drawing_FontIsForceAutoHinting(const OH_Drawing_Font*); + /** * @brief Sets an OH_Drawing_Typeface object for an OH_Drawing_Font object. * @@ -86,6 +184,17 @@ OH_Drawing_Typeface* OH_Drawing_FontGetTypeface(OH_Drawing_Font*); */ void OH_Drawing_FontSetTextSize(OH_Drawing_Font*, float textSize); +/** + * @brief Gets text size for an OH_Drawing_Font object. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param OH_Drawing_Font Indicates the pointer to an OH_Drawing_Font object. + * @return Returns the size of text. + * @since 12 + * @version 1.0 + */ +float OH_Drawing_FontGetTextSize(const OH_Drawing_Font*); + /** * @brief Calculate number of glyphs represented by text. * @@ -100,6 +209,36 @@ void OH_Drawing_FontSetTextSize(OH_Drawing_Font*, float textSize); int OH_Drawing_FontCountText(OH_Drawing_Font*, const void* text, size_t byteLength, OH_Drawing_TextEncoding encoding); +/** + * @brief Converts text into glyph indices. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param OH_Drawing_Font Indicates the pointer to an OH_Drawing_Font object. + * @param text Indicates the character storage encoded with text encoding. + * @param byteLength Indicates the text length in bytes. + * @param encoding Indicates the text encoding. + * @param glyphs Indicates the storage for glyph indices. + * @param maxGlyphCount Indicates the storage capacity. + * @return Returns the number of glyph indices represented by text. + * @since 12 + * @version 1.0 + */ +uint32_t OH_Drawing_FontTextToGlyphs(const OH_Drawing_Font*, const void* text, uint32_t byteLength, + OH_Drawing_TextEncoding encoding, uint16_t* glyphs, int maxGlyphCount); + +/** + * @brief Retrieves the advance for each glyph in glyphs. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param OH_Drawing_Font Indicates the pointer to an OH_Drawing_Font object. + * @param glyphs Indicates the array of glyph indices to be measured. + * @param count Indicates the number of glyphs. + * @param widths Indicates the text advances for each glyph returned to the caller. + * @since 12 + * @version 1.0 + */ +void OH_Drawing_FontGetWidths(const OH_Drawing_Font*, const uint16_t* glyphs, int count, float* widths); + /** * @brief Enables or disables linearly scalable font for an OH_Drawing_Font object. * @@ -111,6 +250,17 @@ int OH_Drawing_FontCountText(OH_Drawing_Font*, const void* text, size_t byteLeng */ void OH_Drawing_FontSetLinearText(OH_Drawing_Font*, bool isLinearText); +/** + * @brief Gets whether the font is linearly scalable. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param OH_Drawing_Font Indicates the pointer to an OH_Drawing_Font object. + * @return Returns true if the font is linearly scalable; returns false otherwise. + * @since 12 + * @version 1.0 + */ +bool OH_Drawing_FontIsLinearText(const OH_Drawing_Font*); + /** * @brief Sets text skew on x-axis for an OH_Drawing_Font object. * @@ -122,6 +272,17 @@ void OH_Drawing_FontSetLinearText(OH_Drawing_Font*, bool isLinearText); */ void OH_Drawing_FontSetTextSkewX(OH_Drawing_Font*, float skewX); +/** + * @brief Gets text skew on x-axis for an OH_Drawing_Font object. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param OH_Drawing_Font Indicates the pointer to an OH_Drawing_Font object. + * @return Returns additional skew on x-axis relative to y-axis. + * @since 12 + * @version 1.0 + */ +float OH_Drawing_FontGetTextSkewX(const OH_Drawing_Font*); + /** * @brief Enables or disables to increase stroke width to approximate bold fonts for an OH_Drawing_Font object. * @@ -133,6 +294,105 @@ void OH_Drawing_FontSetTextSkewX(OH_Drawing_Font*, float skewX); */ void OH_Drawing_FontSetFakeBoldText(OH_Drawing_Font*, bool isFakeBoldText); +/** + * @brief Gets whether to increase the stroke width to approximate bold fonts. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param OH_Drawing_Font Indicates the pointer to an OH_Drawing_Font object. + * @return Returns true to increase the stroke width to approximate bold fonts; returns false otherwise. + * @since 12 + * @version 1.0 + */ +bool OH_Drawing_FontIsFakeBoldText(const OH_Drawing_Font*); + +/** + * @brief Sets text scale on x-axis for an OH_Drawing_Font object. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param OH_Drawing_Font Indicates the pointer to an OH_Drawing_Font object. + * @param scaleX Indicates the text horizontal scale. + * @since 12 + * @version 1.0 + */ +void OH_Drawing_FontSetScaleX(OH_Drawing_Font*, float scaleX); + +/** + * @brief Gets text scale on x-axis from an OH_Drawing_Font object. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param OH_Drawing_Font Indicates the pointer to an OH_Drawing_Font object. + * @return Returns text horizontal scale on x-axis. + * @since 12 + * @version 1.0 + */ +float OH_Drawing_FontGetScaleX(const OH_Drawing_Font*); + +/** + * @brief Sets hinting pattern for an OH_Drawing_Font object. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param OH_Drawing_Font Indicates the pointer to an OH_Drawing_Font object. + * @param OH_Drawing_FontHinting Indicates the font hinting pattern. + * @since 12 + * @version 1.0 + */ +void OH_Drawing_FontSetHinting(OH_Drawing_Font*, OH_Drawing_FontHinting); + +/** + * @brief Gets hinting pattern from an OH_Drawing_Font object. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param OH_Drawing_Font Indicates the pointer to an OH_Drawing_Font object. + * @return Returns the font hinting pattern. + * @since 12 + * @version 1.0 + */ +OH_Drawing_FontHinting OH_Drawing_FontGetHinting(const OH_Drawing_Font*); + +/** + * @brief Sets whether to use bitmaps instead of outlines in the OH_Drawing_Font object. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param OH_Drawing_Font Indicates the pointer to an OH_Drawing_Font object. + * @param isEmbeddedBitmaps Indicates whether to use bitmaps instead of outlines. + * @since 12 + * @version 1.0 + */ +void OH_Drawing_FontSetEmbeddedBitmaps(OH_Drawing_Font*, bool isEmbeddedBitmaps); + +/** + * @brief Gets whether to use bitmaps instead of outlines in the OH_Drawing_Font object. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param OH_Drawing_Font Indicates the pointer to an OH_Drawing_Font object. + * @return Returns true if using bitmaps instead of outlines; returns false otherwise. + * @since 12 + * @version 1.0 + */ +bool OH_Drawing_FontIsEmbeddedBitmaps(const OH_Drawing_Font*); + +/** + * @brief Sets the font edging effect for an OH_Drawing_Font object. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param OH_Drawing_Font Indicates the pointer to an OH_Drawing_Font object. + * @param OH_Drawing_FontEdging Indicates the font edging effect. + * @since 12 + * @version 1.0 + */ +void OH_Drawing_FontSetEdging(OH_Drawing_Font*, OH_Drawing_FontEdging); + +/** + * @brief Gets the font edging effect from an OH_Drawing_Font object. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param OH_Drawing_Font Indicates the pointer to an OH_Drawing_Font object. + * @return Returns the font edging effect. + * @since 12 + * @version 1.0 + */ +OH_Drawing_FontEdging OH_Drawing_FontGetEdging(const OH_Drawing_Font*); + /** * @brief Destroys an OH_Drawing_Font object and reclaims the memory occupied by the object. * diff --git a/graphic/graphic_2d/native_drawing/drawing_text_blob.h b/graphic/graphic_2d/native_drawing/drawing_text_blob.h index 1ba92f61ba77ad10c8966634265d1f6f57303db8..67c7931a4de6524aa0170050b30f22126d406e6b 100644 --- a/graphic/graphic_2d/native_drawing/drawing_text_blob.h +++ b/graphic/graphic_2d/native_drawing/drawing_text_blob.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2023-2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -109,6 +109,17 @@ OH_Drawing_TextBlob* OH_Drawing_TextBlobCreateFromString(const char* str, */ void OH_Drawing_TextBlobGetBounds(OH_Drawing_TextBlob*, OH_Drawing_Rect*); +/** + * @brief Gets a non-zero value unique among all OH_Drawing_TextBlob objects. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param OH_Drawing_TextBlob Indicates the pointer to an OH_Drawing_TextBlob object. + * @return Returns identifier for the OH_Drawing_TextBlob object. + * @since 12 + * @version 1.0 + */ +uint32_t OH_Drawing_TextBlobUniqueID(const OH_Drawing_TextBlob*); + /** * @brief Defines a run, supplies storage for glyphs and positions. * diff --git a/graphic/graphic_2d/native_drawing/libnative_drawing.ndk.json b/graphic/graphic_2d/native_drawing/libnative_drawing.ndk.json index b2a73b331f14115a1769e34304da64f05a17f31f..73a3ba7f2598ea465be3b044b6a59767d32cbde0 100644 --- a/graphic/graphic_2d/native_drawing/libnative_drawing.ndk.json +++ b/graphic/graphic_2d/native_drawing/libnative_drawing.ndk.json @@ -138,8 +138,88 @@ { "name": "OH_Drawing_FilterDestroy" }, { "name": "OH_Drawing_FontCreate" }, { "name": "OH_Drawing_FontDestroy" }, + { + "first_introduced": "12", + "name": "OH_Drawing_FontGetEdging" + }, + { + "first_introduced": "12", + "name": "OH_Drawing_FontGetHinting" + }, + { + "first_introduced": "12", + "name": "OH_Drawing_FontGetScaleX" + }, + { + "first_introduced": "12", + "name": "OH_Drawing_FontGetSize" + }, + { + "first_introduced": "12", + "name": "OH_Drawing_FontGetSkewX" + }, + { + "first_introduced": "12", + "name": "OH_Drawing_FontGetWidths" + }, + { + "first_introduced": "12", + "name": "OH_Drawing_FontIsBaselineSnap" + }, + { + "first_introduced": "12", + "name": "OH_Drawing_FontIsEmbeddedBitmaps" + }, + { + "first_introduced": "12", + "name": "OH_Drawing_FontIsEmbolden" + }, + { + "first_introduced": "12", + "name": "OH_Drawing_FontIsForceAutoHinting" + }, + { + "first_introduced": "12", + "name": "OH_Drawing_FontIsLinearMetrics" + }, + { + "first_introduced": "12", + "name": "OH_Drawing_FontIsSubpixel" + }, + { + "first_introduced": "12", + "name": "OH_Drawing_FontSetBaselineSnap" + }, + { + "first_introduced": "12", + "name": "OH_Drawing_FontSetEdging" + }, + { + "first_introduced": "12", + "name": "OH_Drawing_FontSetEmbeddedBitmaps" + }, { "name": "OH_Drawing_FontSetFakeBoldText" }, + { + "first_introduced": "12", + "name": "OH_Drawing_FontSetForceAutoHinting" + }, + { + "first_introduced": "12", + "name": "OH_Drawing_FontSetHinting" + }, { "name": "OH_Drawing_FontSetLinearText" }, + { + "first_introduced": "12", + "name": "OH_Drawing_FontSetScaleX" + }, + { + "first_introduced": "12", + "name": "OH_Drawing_FontSetSubpixel" + }, + { + "first_introduced": "12", + "name": "OH_Drawing_FontTextToGlyphs" + }, { "name": "OH_Drawing_FontSetTextSize" }, { "name": "OH_Drawing_FontCountText" }, { "name": "OH_Drawing_FontSetTextSkewX" }, @@ -444,6 +524,10 @@ { "name": "OH_Drawing_TextBlobCreateFromPosText" }, { "name": "OH_Drawing_TextBlobCreateFromString" }, { "name": "OH_Drawing_TextBlobGetBounds" }, + { + "first_introduced": "12", + "name": "OH_Drawing_TextBlobUniqueID" + }, { "name": "OH_Drawing_TextBlobBuilderAllocRunPos" }, { "name": "OH_Drawing_TextBlobBuilderCreate" }, { "name": "OH_Drawing_TextBlobBuilderDestroy" },