diff options
| author | 2023-10-11 03:08:54 +0000 | |
|---|---|---|
| committer | 2023-10-11 03:08:54 +0000 | |
| commit | 8330a6562425dbe8ce77140ef780cb665fcfa956 (patch) | |
| tree | 46c41fc82d2ab421f7e0874d53b2d38be977a8bc /graphics/java | |
| parent | bfdb56993d2396901a534eb3aea2e9384d808146 (diff) | |
| parent | 59a0baffc7cf9e4083782ddb60ddbc891b0b0354 (diff) | |
Merge "Add new API useful for determining text height for empty text field" into main
Diffstat (limited to 'graphics/java')
| -rw-r--r-- | graphics/java/android/graphics/Paint.java | 65 |
1 files changed, 61 insertions, 4 deletions
diff --git a/graphics/java/android/graphics/Paint.java b/graphics/java/android/graphics/Paint.java index 9d32272755c0..db1cc446b2d6 100644 --- a/graphics/java/android/graphics/Paint.java +++ b/graphics/java/android/graphics/Paint.java @@ -16,8 +16,11 @@ package android.graphics; +import static com.android.text.flags.Flags.FLAG_FIX_LINE_HEIGHT_FOR_LOCALE; + import android.annotation.ColorInt; import android.annotation.ColorLong; +import android.annotation.FlaggedApi; import android.annotation.IntDef; import android.annotation.IntRange; import android.annotation.NonNull; @@ -2125,7 +2128,7 @@ public class Paint { * @return the font's recommended interline spacing. */ public float getFontMetrics(FontMetrics metrics) { - return nGetFontMetrics(mNativePaint, metrics); + return nGetFontMetrics(mNativePaint, metrics, false); } /** @@ -2139,6 +2142,32 @@ public class Paint { } /** + * Get the font metrics used for the locale + * + * Obtain the metrics of the font that is used for the specified locale by + * {@link #setTextLocales(LocaleList)}. If multiple locales are specified, the minimum ascent + * and maximum descent will be set. + * + * This API is useful for determining the default line height of the empty text field, e.g. + * {@link android.widget.EditText}. + * + * Note, if the {@link android.graphics.Typeface} is created from the custom font files, its + * metrics are reserved, i.e. the ascent will be the custom font's ascent or smaller, the + * descent will be the custom font's descent or larger. + * + * Note, if the {@link android.graphics.Typeface} is a system fallback, e.g. + * {@link android.graphics.Typeface#SERIF}, the default font's metrics are reserved, i.e. the + * ascent will be the serif font's ascent or smaller, the descent will be the serif font's + * descent or larger. + * + * @param metrics an output parameter. All members will be set by calling this function. + */ + @FlaggedApi(FLAG_FIX_LINE_HEIGHT_FOR_LOCALE) + public void getFontMetricsForLocale(@NonNull FontMetrics metrics) { + nGetFontMetrics(mNativePaint, metrics, true); + } + + /** * Returns the font metrics value for the given text. * * If the text is rendered with multiple font files, this function returns the large ascent and @@ -2318,7 +2347,7 @@ public class Paint { * @return the font's interline spacing. */ public int getFontMetricsInt(FontMetricsInt fmi) { - return nGetFontMetricsInt(mNativePaint, fmi); + return nGetFontMetricsInt(mNativePaint, fmi, false); } public FontMetricsInt getFontMetricsInt() { @@ -2328,6 +2357,32 @@ public class Paint { } /** + * Get the font metrics used for the locale + * + * Obtain the metrics of the font that is used for the specified locale by + * {@link #setTextLocales(LocaleList)}. If multiple locales are specified, the minimum ascent + * and maximum descent will be set. + * + * This API is useful for determining the default line height of the empty text field, e.g. + * {@link android.widget.EditText}. + * + * Note, if the {@link android.graphics.Typeface} is created from the custom font files, its + * metrics are reserved, i.e. the ascent will be the custom font's ascent or smaller, the + * descent will be the custom font's descent or larger. + * + * Note, if the {@link android.graphics.Typeface} is a system fallback, e.g. + * {@link android.graphics.Typeface#SERIF}, the default font's metrics are reserved, i.e. the + * ascent will be the serif font's ascent or smaller, the descent will be the serif font's + * descent or larger. + * + * @param metrics an output parameter. All members will be set by calling this function. + */ + @FlaggedApi(FLAG_FIX_LINE_HEIGHT_FOR_LOCALE) + public void getFontMetricsIntForLocale(@NonNull FontMetricsInt metrics) { + nGetFontMetricsInt(mNativePaint, metrics, true); + } + + /** * Return the recommend line spacing based on the current typeface and * text size. * @@ -3446,9 +3501,11 @@ public class Paint { @FastNative private static native void nSetFontFeatureSettings(long paintPtr, String settings); @FastNative - private static native float nGetFontMetrics(long paintPtr, FontMetrics metrics); + private static native float nGetFontMetrics(long paintPtr, FontMetrics metrics, + boolean useLocale); @FastNative - private static native int nGetFontMetricsInt(long paintPtr, FontMetricsInt fmi); + private static native int nGetFontMetricsInt(long paintPtr, FontMetricsInt fmi, + boolean useLocale); // ---------------- @CriticalNative ------------------------ |