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

Commit e67f0c97 authored by Dianne Hackborn's avatar Dianne Hackborn Committed by Xavier Ducrohet
Browse files

Hack to fix issue #2125365: Sports Trivia compatability with Eclair (do not merge)

Adds a mechanism to tell Paint the scaling factor its target
canvas will have, for it to compute font metrics based on the
correct font size.  Only TextView uses this, but that is enough
for the large majority of apps.

This is integrated from the Eclair branch.
parent d135b093
Loading
Loading
Loading
Loading
+5 −5
Original line number Original line Diff line number Diff line
@@ -51157,7 +51157,7 @@
<method name="breakText"
<method name="breakText"
 return="int"
 return="int"
 abstract="false"
 abstract="false"
 native="true"
 native="false"
 synchronized="false"
 synchronized="false"
 static="false"
 static="false"
 final="false"
 final="false"
@@ -51201,7 +51201,7 @@
<method name="breakText"
<method name="breakText"
 return="int"
 return="int"
 abstract="false"
 abstract="false"
 native="true"
 native="false"
 synchronized="false"
 synchronized="false"
 static="false"
 static="false"
 final="false"
 final="false"
@@ -51769,7 +51769,7 @@
<method name="measureText"
<method name="measureText"
 return="float"
 return="float"
 abstract="false"
 abstract="false"
 native="true"
 native="false"
 synchronized="false"
 synchronized="false"
 static="false"
 static="false"
 final="false"
 final="false"
@@ -51786,7 +51786,7 @@
<method name="measureText"
<method name="measureText"
 return="float"
 return="float"
 abstract="false"
 abstract="false"
 native="true"
 native="false"
 synchronized="false"
 synchronized="false"
 static="false"
 static="false"
 final="false"
 final="false"
@@ -51803,7 +51803,7 @@
<method name="measureText"
<method name="measureText"
 return="float"
 return="float"
 abstract="false"
 abstract="false"
 native="true"
 native="false"
 synchronized="false"
 synchronized="false"
 static="false"
 static="false"
 final="false"
 final="false"
+5 −0
Original line number Original line Diff line number Diff line
@@ -327,11 +327,16 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
        mText = "";
        mText = "";


        mTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
        mTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
        mTextPaint.setCompatibilityScaling(
                getResources().getCompatibilityInfo().applicationScale);

        // If we get the paint from the skin, we should set it to left, since
        // If we get the paint from the skin, we should set it to left, since
        // the layout always wants it to be left.
        // the layout always wants it to be left.
        // mTextPaint.setTextAlign(Paint.Align.LEFT);
        // mTextPaint.setTextAlign(Paint.Align.LEFT);


        mHighlightPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
        mHighlightPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
        mHighlightPaint.setCompatibilityScaling(
                getResources().getCompatibilityInfo().applicationScale);


        mMovement = getDefaultMovementMethod();
        mMovement = getDefaultMovementMethod();
        mTransformation = null;
        mTransformation = null;
+5 −5
Original line number Original line Diff line number Diff line
@@ -564,11 +564,11 @@ static JNINativeMethod methods[] = {
    {"descent","()F", (void*) SkPaintGlue::descent},
    {"descent","()F", (void*) SkPaintGlue::descent},
    {"getFontMetrics", "(Landroid/graphics/Paint$FontMetrics;)F", (void*)SkPaintGlue::getFontMetrics},
    {"getFontMetrics", "(Landroid/graphics/Paint$FontMetrics;)F", (void*)SkPaintGlue::getFontMetrics},
    {"getFontMetricsInt", "(Landroid/graphics/Paint$FontMetricsInt;)I", (void*)SkPaintGlue::getFontMetricsInt},
    {"getFontMetricsInt", "(Landroid/graphics/Paint$FontMetricsInt;)I", (void*)SkPaintGlue::getFontMetricsInt},
    {"measureText","([CII)F", (void*) SkPaintGlue::measureText_CII},
    {"native_measureText","([CII)F", (void*) SkPaintGlue::measureText_CII},
    {"measureText","(Ljava/lang/String;)F", (void*) SkPaintGlue::measureText_String},
    {"native_measureText","(Ljava/lang/String;)F", (void*) SkPaintGlue::measureText_String},
    {"measureText","(Ljava/lang/String;II)F", (void*) SkPaintGlue::measureText_StringII},
    {"native_measureText","(Ljava/lang/String;II)F", (void*) SkPaintGlue::measureText_StringII},
    {"breakText","([CIIF[F)I", (void*) SkPaintGlue::breakTextC},
    {"native_breakText","([CIIF[F)I", (void*) SkPaintGlue::breakTextC},
    {"breakText","(Ljava/lang/String;ZF[F)I", (void*) SkPaintGlue::breakTextS},
    {"native_breakText","(Ljava/lang/String;ZF[F)I", (void*) SkPaintGlue::breakTextS},
    {"native_getTextWidths","(I[CII[F)I", (void*) SkPaintGlue::getTextWidths___CII_F},
    {"native_getTextWidths","(I[CII[F)I", (void*) SkPaintGlue::getTextWidths___CII_F},
    {"native_getTextWidths","(ILjava/lang/String;II[F)I", (void*) SkPaintGlue::getTextWidths__StringII_F},
    {"native_getTextWidths","(ILjava/lang/String;II[F)I", (void*) SkPaintGlue::getTextWidths__StringII_F},
    {"native_getTextPath","(I[CIIFFI)V", (void*) SkPaintGlue::getTextPath___CIIFFPath},
    {"native_getTextPath","(I[CIIFFI)V", (void*) SkPaintGlue::getTextPath___CIIFFPath},
+114 −12
Original line number Original line Diff line number Diff line
@@ -36,6 +36,10 @@ public class Paint {
    private Typeface    mTypeface;
    private Typeface    mTypeface;
    private Xfermode    mXfermode;
    private Xfermode    mXfermode;


    private boolean     mHasCompatScaling;
    private float       mCompatScaling;
    private float       mInvCompatScaling;
    
    private static final Style[] sStyleArray = {
    private static final Style[] sStyleArray = {
        Style.FILL, Style.STROKE, Style.FILL_AND_STROKE
        Style.FILL, Style.STROKE, Style.FILL_AND_STROKE
    };
    };
@@ -189,6 +193,7 @@ public class Paint {
    public Paint(int flags) {
    public Paint(int flags) {
        mNativePaint = native_init();
        mNativePaint = native_init();
        setFlags(flags | DEFAULT_PAINT_FLAGS);
        setFlags(flags | DEFAULT_PAINT_FLAGS);
        mCompatScaling = mInvCompatScaling = 1;
    }
    }


    /**
    /**
@@ -200,12 +205,17 @@ public class Paint {
     */
     */
    public Paint(Paint paint) {
    public Paint(Paint paint) {
        mNativePaint = native_initWithPaint(paint.mNativePaint);
        mNativePaint = native_initWithPaint(paint.mNativePaint);
        mHasCompatScaling = paint.mHasCompatScaling;
        mCompatScaling = paint.mCompatScaling;
        mInvCompatScaling = paint.mInvCompatScaling;
    }
    }


    /** Restores the paint to its default settings. */
    /** Restores the paint to its default settings. */
    public void reset() {
    public void reset() {
        native_reset(mNativePaint);
        native_reset(mNativePaint);
        setFlags(DEFAULT_PAINT_FLAGS);
        setFlags(DEFAULT_PAINT_FLAGS);
        mHasCompatScaling = false;
        mCompatScaling = mInvCompatScaling = 1;
    }
    }
    
    
    /**
    /**
@@ -225,6 +235,21 @@ public class Paint {
            mShader         = src.mShader;
            mShader         = src.mShader;
            mTypeface       = src.mTypeface;
            mTypeface       = src.mTypeface;
            mXfermode       = src.mXfermode;
            mXfermode       = src.mXfermode;
            mHasCompatScaling = src.mHasCompatScaling;
            mCompatScaling    = src.mCompatScaling;
            mInvCompatScaling = src.mInvCompatScaling;
        }
    }

    /** @hide */
    public void setCompatibilityScaling(float factor) {
        if (factor == 1.0) {
            mHasCompatScaling = false;
            mCompatScaling = mInvCompatScaling = 1.0f;
        } else {
            mHasCompatScaling = true;
            mCompatScaling = factor;
            mInvCompatScaling = 1.0f/factor;
        }
        }
    }
    }
    
    
@@ -972,7 +997,16 @@ public class Paint {
     * @param count THe number of characters to measure, beginning with start
     * @param count THe number of characters to measure, beginning with start
     * @return      The width of the text
     * @return      The width of the text
     */
     */
    public native float measureText(char[] text, int index, int count);
    public float measureText(char[] text, int index, int count) {
        if (!mHasCompatScaling) return native_measureText(text, index, count);
        final float oldSize = getTextSize();
        setTextSize(oldSize*mCompatScaling);
        float w = native_measureText(text, index, count);
        setTextSize(oldSize);
        return w*mInvCompatScaling;
    }

    private native float native_measureText(char[] text, int index, int count);
    
    
    /**
    /**
     * Return the width of the text.
     * Return the width of the text.
@@ -982,7 +1016,16 @@ public class Paint {
     * @param end   1 beyond the index of the last character to measure
     * @param end   1 beyond the index of the last character to measure
     * @return      The width of the text
     * @return      The width of the text
     */
     */
    public native float measureText(String text, int start, int end);
    public float measureText(String text, int start, int end) {
        if (!mHasCompatScaling) return native_measureText(text, start, end);
        final float oldSize = getTextSize();
        setTextSize(oldSize*mCompatScaling);
        float w = native_measureText(text, start, end);
        setTextSize(oldSize);
        return w*mInvCompatScaling;
    }

    private native float native_measureText(String text, int start, int end);
    
    
    /**
    /**
     * Return the width of the text.
     * Return the width of the text.
@@ -990,7 +1033,16 @@ public class Paint {
     * @param text  The text to measure
     * @param text  The text to measure
     * @return      The width of the text
     * @return      The width of the text
     */
     */
    public native float measureText(String text);
    public float measureText(String text) {
        if (!mHasCompatScaling) return native_measureText(text);
        final float oldSize = getTextSize();
        setTextSize(oldSize*mCompatScaling);
        float w = native_measureText(text);
        setTextSize(oldSize);
        return w*mInvCompatScaling;
    }

    private native float native_measureText(String text);
    
    
    /**
    /**
     * Return the width of the text.
     * Return the width of the text.
@@ -1036,7 +1088,21 @@ public class Paint {
     * @return The number of chars that were measured. Will always be <=
     * @return The number of chars that were measured. Will always be <=
     *         abs(count).
     *         abs(count).
     */
     */
    public native int breakText(char[] text, int index, int count,
    public int breakText(char[] text, int index, int count,
                                float maxWidth, float[] measuredWidth) {
        if (!mHasCompatScaling) {
            return native_breakText(text, index, count, maxWidth, measuredWidth);
        }
        final float oldSize = getTextSize();
        setTextSize(oldSize*mCompatScaling);
        int res = native_breakText(text, index, count, maxWidth*mCompatScaling,
                measuredWidth);
        setTextSize(oldSize);
        if (measuredWidth != null) measuredWidth[0] *= mInvCompatScaling;
        return res;
    }

    private native int native_breakText(char[] text, int index, int count,
                                        float maxWidth, float[] measuredWidth);
                                        float maxWidth, float[] measuredWidth);


    /**
    /**
@@ -1094,7 +1160,21 @@ public class Paint {
     * @return The number of chars that were measured. Will always be <=
     * @return The number of chars that were measured. Will always be <=
     *         abs(count).
     *         abs(count).
     */
     */
    public native int breakText(String text, boolean measureForwards,
    public int breakText(String text, boolean measureForwards,
                                float maxWidth, float[] measuredWidth) {
        if (!mHasCompatScaling) {
            return native_breakText(text, measureForwards, maxWidth, measuredWidth);
        }
        final float oldSize = getTextSize();
        setTextSize(oldSize*mCompatScaling);
        int res = native_breakText(text, measureForwards, maxWidth*mCompatScaling,
                measuredWidth);
        setTextSize(oldSize);
        if (measuredWidth != null) measuredWidth[0] *= mInvCompatScaling;
        return res;
    }

    private native int native_breakText(String text, boolean measureForwards,
                                        float maxWidth, float[] measuredWidth);
                                        float maxWidth, float[] measuredWidth);


    /**
    /**
@@ -1113,8 +1193,19 @@ public class Paint {
                || count > widths.length) {
                || count > widths.length) {
            throw new ArrayIndexOutOfBoundsException();
            throw new ArrayIndexOutOfBoundsException();
        }
        }
        
        if (!mHasCompatScaling) {
            return native_getTextWidths(mNativePaint, text, index, count, widths);
            return native_getTextWidths(mNativePaint, text, index, count, widths);
        }
        }
        final float oldSize = getTextSize();
        setTextSize(oldSize*mCompatScaling);
        int res = native_getTextWidths(mNativePaint, text, index, count, widths);
        setTextSize(oldSize);
        for (int i=0; i<res; i++) {
            widths[i] *= mInvCompatScaling;
        }
        return res;
    }


    /**
    /**
     * Return the advance widths for the characters in the string.
     * Return the advance widths for the characters in the string.
@@ -1164,8 +1255,19 @@ public class Paint {
        if (end - start > widths.length) {
        if (end - start > widths.length) {
            throw new ArrayIndexOutOfBoundsException();
            throw new ArrayIndexOutOfBoundsException();
        }
        }
        
        if (!mHasCompatScaling) {
            return native_getTextWidths(mNativePaint, text, start, end, widths);
            return native_getTextWidths(mNativePaint, text, start, end, widths);
        }
        }
        final float oldSize = getTextSize();
        setTextSize(oldSize*mCompatScaling);
        int res = native_getTextWidths(mNativePaint, text, start, end, widths);
        setTextSize(oldSize);
        for (int i=0; i<res; i++) {
            widths[i] *= mInvCompatScaling;
        }
        return res;
    }
    
    
    /**
    /**
     * Return the advance widths for the characters in the string.
     * Return the advance widths for the characters in the string.