From: Peter Golde Date: Tue, 15 Mar 2016 17:27:40 +0000 (-0700) Subject: Add C API for getting font metrics from an sk_paint_t. X-Git-Tag: submit/tizen/20180928.044319~174^2~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a4049c724ff869706f026e38dd07f634b7d18256;p=platform%2Fupstream%2FlibSkiaSharp.git Add C API for getting font metrics from an sk_paint_t. --- diff --git a/include/c/sk_paint.h b/include/c/sk_paint.h index e5e1cc46cd..2f189aef44 100644 --- a/include/c/sk_paint.h +++ b/include/c/sk_paint.h @@ -206,7 +206,10 @@ SK_API float sk_paint_measure_text(const sk_paint_t* cpaint, const void* text, s * Return the width of the UTF16 encoded text */ SK_API float sk_paint_measure_utf16_text(sk_paint_t* cpaint, const void* text, size_t length, sk_rect_t* cbounds); - +/** + * Get the font metrics for the current typeface and type size. + */ +SK_API void sk_paint_get_fontmetrics(sk_paint_t* cpaint, sk_fontmetrics_t* cfontmetrics); SK_C_PLUS_PLUS_END_GUARD diff --git a/include/c/sk_types.h b/include/c/sk_types.h index 6c6b7546e4..76897c426b 100644 --- a/include/c/sk_types.h +++ b/include/c/sk_types.h @@ -128,6 +128,27 @@ typedef struct { float mat[9]; } sk_matrix_t; +typedef struct { + uint32_t fFlags; // Bit field to identify which values are unknown + float fTop; // The greatest distance above the baseline for any glyph (will be <= 0) + float fAscent; // The recommended distance above the baseline (will be <= 0) + float fDescent; // The recommended distance below the baseline (will be >= 0) + float fBottom; // The greatest distance below the baseline for any glyph (will be >= 0) + float fLeading; // The recommended distance to add between lines of text (will be >= 0) + float fAvgCharWidth; // the average character width (>= 0) + float fMaxCharWidth; // the max character width (>= 0) + float fXMin; // The minimum bounding box x value for all glyphs + float fXMax; // The maximum bounding box x value for all glyphs + float fXHeight; // The height of an 'x' in px, or 0 if no 'x' in face + float fCapHeight; // The cap height (> 0), or 0 if cannot be determined. + float fUnderlineThickness; // underline thickness, or 0 if cannot be determined + float fUnderlinePosition; // underline position, or 0 if cannot be determined +} sk_fontmetrics_t; + +// Flags for fFlags member of sk_fontmetrics_t +#define FONTMETRICS_FLAGS_UNDERLINE_THICKNESS_IS_VALID (1U << 0) +#define FONTMETRICS_FLAGS_UNDERLINE_POSITION_IS_VALID (1U << 1) + /** A sk_canvas_t encapsulates all of the state about drawing into a destination This includes a reference to the destination itself, diff --git a/src/c/sk_paint.cpp b/src/c/sk_paint.cpp index ed49808068..fd47672129 100644 --- a/src/c/sk_paint.cpp +++ b/src/c/sk_paint.cpp @@ -250,3 +250,9 @@ float sk_paint_measure_utf16_text(sk_paint_t* cpaint, const void* text, size_t l return ret; } +void sk_paint_get_fontmetrics(sk_paint_t* cpaint, sk_fontmetrics_t* cfontmetrics) +{ + SkPaint *paint = AsPaint(cpaint); + paint->getFontMetrics(AsFontMetrics(cfontmetrics)); +} + diff --git a/src/c/sk_types_priv.h b/src/c/sk_types_priv.h index 86da45736b..02684d51ce 100644 --- a/src/c/sk_types_priv.h +++ b/src/c/sk_types_priv.h @@ -256,6 +256,14 @@ static inline const SkImageFilter::CropRect* AsImageFilterCropRect(const sk_imag return reinterpret_cast(p); } +static inline SkPaint::FontMetrics* AsFontMetrics(sk_fontmetrics_t* p) { + return reinterpret_cast(p); +} + +static inline sk_fontmetrics_t* ToFontMetrics(SkPaint::FontMetrics* p) { + return reinterpret_cast(p); +} + const struct { sk_xfermode_mode_t fC; SkXfermode::Mode fSK;