Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4e83698c authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Deprecate Paint#elegantTextHeight" into main

parents aa4aa8ff fbfa91a2
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -16747,7 +16747,7 @@ package android.graphics {
    method public boolean hasGlyph(String);
    method public final boolean isAntiAlias();
    method public final boolean isDither();
    method public boolean isElegantTextHeight();
    method @Deprecated @FlaggedApi("com.android.text.flags.deprecate_elegant_text_height_api") public boolean isElegantTextHeight();
    method public final boolean isFakeBoldText();
    method public final boolean isFilterBitmap();
    method public final boolean isLinearText();
@@ -16768,7 +16768,7 @@ package android.graphics {
    method public void setColor(@ColorLong long);
    method public android.graphics.ColorFilter setColorFilter(android.graphics.ColorFilter);
    method public void setDither(boolean);
    method public void setElegantTextHeight(boolean);
    method @Deprecated @FlaggedApi("com.android.text.flags.deprecate_elegant_text_height_api") public void setElegantTextHeight(boolean);
    method public void setEndHyphenEdit(int);
    method public void setFakeBoldText(boolean);
    method public void setFilterBitmap(boolean);
+7 −0
Original line number Diff line number Diff line
@@ -195,3 +195,10 @@ flag {
  description: "Feature flag for adding a TYPE_DURATION to TtsSpan"
  bug: "337103893"
}

flag {
  name: "deprecate_elegant_text_height_api"
  namespace: "text"
  description: "Deprecate the Paint#elegantTextHeight API and stick it to true"
  bug: "349519475"
}
+46 −0
Original line number Diff line number Diff line
@@ -18,6 +18,8 @@ package android.graphics;

import static com.android.text.flags.Flags.FLAG_FIX_LINE_HEIGHT_FOR_LOCALE;
import static com.android.text.flags.Flags.FLAG_LETTER_SPACING_JUSTIFICATION;
import static com.android.text.flags.Flags.FLAG_DEPRECATE_ELEGANT_TEXT_HEIGHT_API;


import android.annotation.ColorInt;
import android.annotation.ColorLong;
@@ -39,6 +41,7 @@ import android.text.GraphicsOperations;
import android.text.SpannableString;
import android.text.SpannedString;
import android.text.TextUtils;
import android.util.Log;

import com.android.internal.annotations.GuardedBy;
import com.android.text.flags.Flags;
@@ -61,6 +64,7 @@ import java.util.Objects;
 * geometries, text and bitmaps.
 */
public class Paint {
    private static final String TAG = "Paint";

    @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
    private long mNativePaint;
@@ -1803,8 +1807,18 @@ public class Paint {
    /**
     * Get the elegant metrics flag.
     *
     * Note:
     * For applications target API 35 or later, this function returns true by default.
     * For applications target API 36 or later, the function call will be ignored and the elegant
     * text height is always enabled.
     *
     * @return true if elegant metrics are enabled for text drawing.
     * @deprecated The underlying UI fonts are deprecated and will be removed from the system image.
     * Applications supporting scripts with large vertical metrics should adapt their UI by using
     * fonts designed with corresponding vertical metrics.
     */
    @Deprecated
    @FlaggedApi(FLAG_DEPRECATE_ELEGANT_TEXT_HEIGHT_API)
    public boolean isElegantTextHeight() {
        return nGetElegantTextHeight(mNativePaint) != ELEGANT_TEXT_HEIGHT_DISABLED;
    }
@@ -1819,9 +1833,28 @@ public class Paint {
     * variants that have not been compacted to fit Latin-based vertical
     * metrics, and also increases top and bottom bounds to provide more space.
     *
     * <p>
     * Note:
     * For applications target API 35 or later, the default value will be true by default.
     * For applications target API 36 or later, the function call will be ignored and the elegant
     * text height is always enabled.
     *
     * @param elegant set the paint's elegant metrics flag for drawing text.
     * @deprecated This API will be no-op at some point in the future. The underlying UI fonts is
     * deprecated and will be removed from the system image. Applications supporting scripts with
     * large vertical metrics should adapt their UI by using fonts designed with corresponding
     * vertical metrics.
     */
    @Deprecated
    @FlaggedApi(FLAG_DEPRECATE_ELEGANT_TEXT_HEIGHT_API)
    public void setElegantTextHeight(boolean elegant) {
        if (Flags.deprecateElegantTextHeightApi() && !elegant
                && CompatChanges.isChangeEnabled(DEPRECATE_UI_FONT_ENFORCE)) {
            if (!elegant) {
                Log.w(TAG, "The elegant text height cannot be turned off.");
            }
            return;
        }
        nSetElegantTextHeight(mNativePaint,
                elegant ? ELEGANT_TEXT_HEIGHT_ENABLED : ELEGANT_TEXT_HEIGHT_DISABLED);
    }
@@ -1839,6 +1872,19 @@ public class Paint {
    @EnabledSince(targetSdkVersion = Build.VERSION_CODES.VANILLA_ICE_CREAM)
    public static final long DEPRECATE_UI_FONT = 279646685L;

    /**
     * A change ID for deprecating UI fonts enforced.
     *
     * From API 36, the elegant text height will not be able to be overridden and always true if the
     * app has a target SDK of API 36 or later.
     *
     * @hide
     */
    @ChangeId
    @EnabledSince(targetSdkVersion = 36)
    public static final long DEPRECATE_UI_FONT_ENFORCE = 349519475L;


    private void resetElegantTextHeight() {
        if (CompatChanges.isChangeEnabled(DEPRECATE_UI_FONT)) {
            nSetElegantTextHeight(mNativePaint, ELEGANT_TEXT_HEIGHT_UNSET);