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

Commit a19b8c11 authored by Deepanshu Gupta's avatar Deepanshu Gupta
Browse files

LayoutLib: Add assertions for typeface.

Framework passes typeface along with the paint object at many places.
Paint_Delegate is supposed to have the typeface object with it. Add
assertions to ensure that the two typefaces are indeed the same.

Change-Id: I68193513c2d99f269c0458d6493f23025bbda385
parent ad69aee5
Loading
Loading
Loading
Loading
+6 −1
Original line number Diff line number Diff line
@@ -977,7 +977,7 @@ public final class Canvas_Delegate {
    /*package*/ static void native_drawText(long nativeCanvas,
            final char[] text, final int index, final int count,
            final float startX, final float startY, final int flags, long paint,
            long typeface) {
            final long typeface) {

        draw(nativeCanvas, paint, false /*compositeOnly*/, false /*forceSrcMode*/,
                new GcSnapshot.Drawable() {
@@ -985,6 +985,11 @@ public final class Canvas_Delegate {
            public void draw(Graphics2D graphics, Paint_Delegate paintDelegate) {
                // WARNING: the logic in this method is similar to Paint_Delegate.measureText.
                // Any change to this method should be reflected in Paint.measureText

                // assert that the typeface passed is actually the one stored in paint.
                assert (typeface == paintDelegate.mNativeTypeface);


                // Paint.TextAlign indicates how the text is positioned relative to X.
                // LEFT is the default and there's nothing to do.
                float x = startX;
+16 −6
Original line number Diff line number Diff line
@@ -93,6 +93,8 @@ public class Paint_Delegate {

    private Locale mLocale = Locale.getDefault();

    // Used only to assert invariants.
    public long mNativeTypeface;

    // ---- Public Helper methods ----

@@ -888,6 +890,7 @@ public class Paint_Delegate {
        }

        delegate.mTypeface = Typeface_Delegate.getDelegate(typeface);
        delegate.mNativeTypeface = typeface;
        delegate.updateFontObject();
        return typeface;
    }
@@ -966,15 +969,10 @@ public class Paint_Delegate {
    }

    @LayoutlibDelegate
    /*package*/ static float native_getTextRunAdvances(long native_object,
            long native_typeface /*ignored*/,
    /*package*/ static float native_getTextRunAdvances(long native_object, long native_typeface,
            char[] text, int index, int count, int contextIndex, int contextCount,
            int flags, float[] advances, int advancesIndex) {

        // native_typeface is passed here since Framework's old implementation did not have the
        // typeface object associated with the Paint. Since, we follow the new framework way,
        // we store the typeface with the paint and use it directly.

        if (advances != null)
            for (int i = advancesIndex; i< advancesIndex+count; i++)
                advances[i]=0;
@@ -983,6 +981,12 @@ public class Paint_Delegate {
        if (delegate == null) {
            return 0.f;
        }

        // native_typeface is passed here since Framework's old implementation did not have the
        // typeface object associated with the Paint. Since, we follow the new framework way,
        // we store the typeface with the paint and use it directly.
        assert (native_typeface == delegate.mNativeTypeface);

        boolean isRtl = isRtl(flags);

        int limit = index + count;
@@ -1054,6 +1058,10 @@ public class Paint_Delegate {
        if (delegate == null) {
            return;
        }

        // assert that the typeface passed is actually the one that we had stored.
        assert (native_typeface == delegate.mNativeTypeface);

        delegate.measureText(text, index, count, isRtl(bidiFlags)).roundOut(bounds);
    }

@@ -1080,6 +1088,7 @@ public class Paint_Delegate {
        mJoin = paint.mJoin;
        mTextAlign = paint.mTextAlign;
        mTypeface = paint.mTypeface;
        mNativeTypeface = paint.mNativeTypeface;
        mStrokeWidth = paint.mStrokeWidth;
        mStrokeMiter = paint.mStrokeMiter;
        mTextSize = paint.mTextSize;
@@ -1103,6 +1112,7 @@ public class Paint_Delegate {
        mJoin = Paint.Join.MITER.nativeInt;
        mTextAlign = 0;
        mTypeface = Typeface_Delegate.getDelegate(Typeface.sDefaults[0].native_instance);
        mNativeTypeface = 0;
        mStrokeWidth = 1.f;
        mStrokeMiter = 4.f;
        mTextSize = 20.f;