/*
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef C_INCLUDE_DRAWING_FONT_H
#define C_INCLUDE_DRAWING_FONT_H
/**
* @addtogroup Drawing
* @{
*
* @brief Provides functions such as 2D graphics rendering, text drawing, and image display.
*
* @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
*
* @since 11
* @version 1.0
*/
/**
* @file drawing_font.h
*
* @brief Declares functions related to the font object in the drawing module.
*
* @kit ArkGraphics2D
* @library libnative_drawing.so
* @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
* @since 11
* @version 1.0
*/
#include "drawing_error_code.h"
#include "drawing_types.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Creates an OH_Drawing_Font object.
*
* @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
* @return Returns the pointer to the OH_Drawing_Font object created.
* @since 11
* @version 1.0
*/
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.
*
* @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
* @param OH_Drawing_Font Indicates the pointer to an OH_Drawing_Font object.
* @param OH_Drawing_Typeface Indicates the pointer to an OH_Drawing_Typeface object.
* @since 11
* @version 1.0
*/
void OH_Drawing_FontSetTypeface(OH_Drawing_Font*, OH_Drawing_Typeface*);
/**
* @brief Gets an OH_Drawing_Typeface object from the OH_Drawing_Typeface object.
*
* @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
* @param OH_Drawing_Font Indicates the pointer to an OH_Drawing_Font object.
* @return OH_Drawing_Typeface Indicates the pointer to an OH_Drawing_Typeface object.
* @since 12
* @version 1.0
*/
OH_Drawing_Typeface* OH_Drawing_FontGetTypeface(OH_Drawing_Font*);
/**
* @brief Sets 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.
* @param textSize Indicates the text size.
* @since 11
* @version 1.0
*/
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.
*
* @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.
* @since 12
* @version 1.0
*/
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 Measures the width of a single character.
*
* @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
* @param font Indicates the pointer to an OH_Drawing_Font object.
* @param str Indicates the single character encoded in UTF-8.
* @param textWidth Indicates the width of the single character.
* @return Returns the error code.
* Returns {@link OH_DRAWING_SUCCESS} if the operation is successful.
* Returns {@link OH_DRAWING_ERROR_INVALID_PARAMETER} if any of font, str
* and textWidth is nullptr or strlen(str) is 0.
* @since 12
* @version 1.0
*/
OH_Drawing_ErrorCode OH_Drawing_FontMeasureSingleCharacter(const OH_Drawing_Font* font, const char* str,
float* textWidth);
/**
* @brief Measures the width of text.
*
* @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
* @param 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 bounds Gets the bounding box relative to (0, 0) if not nullptr.
* @param textWidth Indicates the width of text.
* @return Returns the error code.
* Returns {@link OH_DRAWING_SUCCESS} if the operation is successful.
* Returns {@link OH_DRAWING_ERROR_INVALID_PARAMETER} if any of font, text
* and textWidth is nullptr or byteLength is 0.
* @since 12
* @version 1.0
*/
OH_Drawing_ErrorCode OH_Drawing_FontMeasureText(const OH_Drawing_Font* font, const void* text, size_t byteLength,
OH_Drawing_TextEncoding encoding, OH_Drawing_Rect* bounds, float* textWidth);
/**
* @brief Enables or disables linearly scalable font 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 isLinearText Indicates whether to enable linearly scalable font.
* @since 11
* @version 1.0
*/
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.
*
* @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
* @param OH_Drawing_Font Indicates the pointer to an OH_Drawing_Font object.
* @param skewX Indicates the additional shear on x-axis relative to y-axis.
* @since 11
* @version 1.0
*/
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.
*
* @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
* @param OH_Drawing_Font Indicates the pointer to an OH_Drawing_Font object.
* @param isFakeBoldText Indicates whether to enable to increase stroke width.
* @since 11
* @version 1.0
*/
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.
*
* @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
* @param OH_Drawing_Font Indicates the pointer to an OH_Drawing_Font object.
* @since 11
* @version 1.0
*/
void OH_Drawing_FontDestroy(OH_Drawing_Font*);
/**
* @brief Defines a run, supplies storage for the metrics of an OH_Drawing_Font.
*
* @since 12
* @version 1.0
*/
typedef struct OH_Drawing_Font_Metrics {
/** Indicating which metrics are valid */
uint32_t flags;
/** storage for top in font metrics */
float top;
/** storage for ascent in font metrics */
float ascent;
/** storage for descent in font metrics */
float descent;
/** storage for bottom in font metrics */
float bottom;
/** storage for leading in font metrics */
float leading;
/** Average character width, zero if unknown */
float avgCharWidth;
/** Maximum character width, zero if unknown */
float maxCharWidth;
/** Greatest extent to left of origin of any glyph bounding box, typically negative; deprecated with variable fonts */
float xMin;
/** Greatest extent to right of origin of any glyph bounding box, typically positive; deprecated with variable fonts */
float xMax;
/** Height of lower-case letter, zero if unknown, typically negative */
float xHeight;
/** Height of an upper-case letter, zero if unknown, typically negative */
float capHeight;
/** @brief Underline thickness */
float underlineThickness;
/** Distance from baseline to top of stroke, typically positive */
float underlinePosition;
/** Strikeout thickness */
float strikeoutThickness;
/** Distance from baseline to bottom of stroke, typically negative */
float strikeoutPosition;
} OH_Drawing_Font_Metrics;
/**
* @brief Obtains the metrics of a font.
*
* @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
* @param OH_Drawing_Font Indicates the pointer to an OH_Drawing_Font object.
* @param OH_Drawing_Font_Metrics Indicates the pointer to an OH_Drawing_Font_Metrics object.
* @return Returns a float variable that recommended spacing between lines.
* @since 12
* @version 1.0
*/
float OH_Drawing_FontGetMetrics(OH_Drawing_Font*, OH_Drawing_Font_Metrics*);
#ifdef __cplusplus
}
#endif
/** @} */
#endif