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

Commit c672afbd authored by Seigo Nonaka's avatar Seigo Nonaka Committed by Android (Google) Code Review
Browse files

Merge "Change default value of setElegantTextFlag" into main

parents b00814f3 de05ca71
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -61,3 +61,10 @@ flag {
  description: "Feature flag for preventing horizontal clipping."
  bug: "63938206"
}

flag {
  name: "deprecate_ui_fonts"
  namespace: "text"
  description: "Feature flag for deprecating UI fonts. By setting true for this feature flag, the elegant text height of will be turned on by default unless explicitly setting it to false by attribute or Java API call."
  bug: "279646685"
}
+49 −5
Original line number Diff line number Diff line
@@ -27,6 +27,9 @@ import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.Px;
import android.annotation.Size;
import android.app.compat.CompatChanges;
import android.compat.annotation.ChangeId;
import android.compat.annotation.EnabledSince;
import android.compat.annotation.UnsupportedAppUsage;
import android.graphics.fonts.FontVariationAxis;
import android.os.Build;
@@ -614,6 +617,7 @@ public class Paint {
        mCompatScaling = mInvCompatScaling = 1;
        setTextLocales(LocaleList.getAdjustedDefault());
        mColor = Color.pack(Color.BLACK);
        resetElegantTextHeight();
    }

    /**
@@ -654,7 +658,7 @@ public class Paint {

        mBidiFlags = BIDI_DEFAULT_LTR;
        setTextLocales(LocaleList.getAdjustedDefault());
        setElegantTextHeight(false);
        resetElegantTextHeight();
        mFontFeatureSettings = null;
        mFontVariationSettings = null;

@@ -1735,12 +1739,30 @@ public class Paint {
    /**
     * Get the elegant metrics flag.
     *
     * From API {@link Build.VERSION_CODES#VANILLA_ICE_CREAM}, the default value will be true by
     * default if the app has a target SDK of API {@link Build.VERSION_CODES#VANILLA_ICE_CREAM} or
     * later.
     *
     * @return true if elegant metrics are enabled for text drawing.
     */
    public boolean isElegantTextHeight() {
        return nIsElegantTextHeight(mNativePaint);
        int rawValue = nGetElegantTextHeight(mNativePaint);
        switch (rawValue) {
            case ELEGANT_TEXT_HEIGHT_DISABLED:
                return false;
            case ELEGANT_TEXT_HEIGHT_ENABLED:
                return true;
            case ELEGANT_TEXT_HEIGHT_UNSET:
            default:
                return com.android.text.flags.Flags.deprecateUiFonts();
        }
    }

    // Note: the following three values must be equal to the ones in the JNI file: Paint.cpp
    private static final int ELEGANT_TEXT_HEIGHT_UNSET = -1;
    private static final int ELEGANT_TEXT_HEIGHT_ENABLED = 0;
    private static final int ELEGANT_TEXT_HEIGHT_DISABLED = 1;

    /**
     * Set the paint's elegant height metrics flag. This setting selects font
     * variants that have not been compacted to fit Latin-based vertical
@@ -1749,7 +1771,29 @@ public class Paint {
     * @param elegant set the paint's elegant metrics flag for drawing text.
     */
    public void setElegantTextHeight(boolean elegant) {
        nSetElegantTextHeight(mNativePaint, elegant);
        nSetElegantTextHeight(mNativePaint,
                elegant ? ELEGANT_TEXT_HEIGHT_ENABLED : ELEGANT_TEXT_HEIGHT_DISABLED);
    }

    /**
     * A change ID for deprecating UI fonts.
     *
     * From API {@link Build.VERSION_CODES#VANILLA_ICE_CREAM}, the default value will be true by
     * default if the app has a target SDK of API {@link Build.VERSION_CODES#VANILLA_ICE_CREAM} or
     * later.
     *
     * @hide
     */
    @ChangeId
    @EnabledSince(targetSdkVersion = Build.VERSION_CODES.VANILLA_ICE_CREAM)
    public static final long DEPRECATE_UI_FONT = 279646685L;

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

    /**
@@ -3660,9 +3704,9 @@ public class Paint {
    @CriticalNative
    private static native void nSetStrikeThruText(long paintPtr, boolean strikeThruText);
    @CriticalNative
    private static native boolean nIsElegantTextHeight(long paintPtr);
    private static native int nGetElegantTextHeight(long paintPtr);
    @CriticalNative
    private static native void nSetElegantTextHeight(long paintPtr, boolean elegant);
    private static native void nSetElegantTextHeight(long paintPtr, int elegant);
    @CriticalNative
    private static native float nGetTextSize(long paintPtr);
    @CriticalNative
+8 −0
Original line number Diff line number Diff line
@@ -33,6 +33,14 @@ inline bool fix_double_underline() {
#endif  // __ANDROID__
}

inline bool deprecate_ui_fonts() {
#ifdef __ANDROID__
    return com_android_text_flags_deprecate_ui_fonts();
#else
    return true;
#endif  // __ANDROID__
}

}  // namespace text_feature

}  // namespace android
+15 −4
Original line number Diff line number Diff line
@@ -16,12 +16,15 @@

#include "MinikinUtils.h"

#include <string>

#include <log/log.h>

#include <minikin/FamilyVariant.h>
#include <minikin/MeasuredText.h>
#include <minikin/Measurement.h>

#include <optional>
#include <string>

#include "FeatureFlags.h"
#include "Paint.h"
#include "SkPathMeasure.h"
#include "Typeface.h"
@@ -43,9 +46,17 @@ minikin::MinikinPaint MinikinUtils::prepareMinikinPaint(const Paint* paint,
    minikinPaint.wordSpacing = paint->getWordSpacing();
    minikinPaint.fontFlags = MinikinFontSkia::packFontFlags(font);
    minikinPaint.localeListId = paint->getMinikinLocaleListId();
    minikinPaint.familyVariant = paint->getFamilyVariant();
    minikinPaint.fontStyle = resolvedFace->fStyle;
    minikinPaint.fontFeatureSettings = paint->getFontFeatureSettings();

    const std::optional<minikin::FamilyVariant>& familyVariant = paint->getFamilyVariant();
    if (familyVariant.has_value()) {
        minikinPaint.familyVariant = familyVariant.value();
    } else {
        minikinPaint.familyVariant = text_feature::deprecate_ui_fonts()
                                             ? minikin::FamilyVariant::ELEGANT
                                             : minikin::FamilyVariant::DEFAULT;
    }
    return minikinPaint;
}

+3 −2
Original line number Diff line number Diff line
@@ -94,9 +94,10 @@ public:

    uint32_t getMinikinLocaleListId() const { return mMinikinLocaleListId; }

    void resetFamilyVariant() { mFamilyVariant.reset(); }
    void setFamilyVariant(minikin::FamilyVariant variant) { mFamilyVariant = variant; }

    minikin::FamilyVariant getFamilyVariant() const { return mFamilyVariant; }
    std::optional<minikin::FamilyVariant> getFamilyVariant() const { return mFamilyVariant; }

    void setStartHyphenEdit(uint32_t startHyphen) {
        mHyphenEdit = minikin::packHyphenEdit(
@@ -171,7 +172,7 @@ private:
    float mWordSpacing = 0;
    std::string mFontFeatureSettings;
    uint32_t mMinikinLocaleListId;
    minikin::FamilyVariant mFamilyVariant;
    std::optional<minikin::FamilyVariant> mFamilyVariant;
    uint32_t mHyphenEdit = 0;
    // The native Typeface object has the same lifetime of the Java Typeface
    // object. The Java Paint object holds a strong reference to the Java Typeface
Loading