Loading tools/layoutlib/bridge/src/android/graphics/Canvas_Delegate.java +49 −17 Original line number Diff line number Diff line Loading @@ -170,7 +170,8 @@ public class Canvas_Delegate { } /*package*/ static boolean clipRect(Canvas thisCanvas, RectF rect) { return clipRect(thisCanvas, rect.left, rect.top, rect.right, rect.bottom); return clipRect(thisCanvas, (int) rect.left, (int) rect.top, (int) rect.right, (int) rect.bottom); } /*package*/ static boolean clipRect(Canvas thisCanvas, Rect rect) { Loading @@ -179,16 +180,7 @@ public class Canvas_Delegate { /*package*/ static boolean clipRect(Canvas thisCanvas, float left, float top, float right, float bottom) { // get the delegate from the native int. Canvas_Delegate canvasDelegate = sManager.getDelegate(thisCanvas.mNativeCanvas); if (canvasDelegate == null) { assert false; return false; } canvasDelegate.getGraphics2d().clipRect((int)left, (int)top, (int)(right-left), (int)(bottom-top)); return true; return clipRect(thisCanvas, (int) left, (int) top, (int) right, (int) bottom); } /*package*/ static boolean clipRect(Canvas thisCanvas, int left, int top, int right, Loading @@ -200,8 +192,7 @@ public class Canvas_Delegate { return false; } canvasDelegate.getGraphics2d().clipRect(left, top, right - left, bottom - top); return true; return canvasDelegate.clipRect(left, top, right, bottom, Region.Op.INTERSECT.nativeInt); } /*package*/ static int save(Canvas thisCanvas) { Loading Loading @@ -277,8 +268,31 @@ public class Canvas_Delegate { /*package*/ static void drawLines(Canvas thisCanvas, float[] pts, int offset, int count, Paint paint) { // FIXME throw new UnsupportedOperationException(); // get the delegate from the native int. Canvas_Delegate canvasDelegate = sManager.getDelegate(thisCanvas.mNativeCanvas); if (canvasDelegate == null) { assert false; return; } Paint_Delegate paintDelegate = Paint_Delegate.getDelegate(paint.mNativePaint); if (paintDelegate == null) { assert false; return; } // get a Graphics2D object configured with the drawing parameters. Graphics2D g = canvasDelegate.getCustomGraphics(paintDelegate); try { for (int i = 0 ; i < count ; i += 4) { g.drawLine((int)pts[i + offset], (int)pts[i + offset + 1], (int)pts[i + offset + 2], (int)pts[i + offset + 3]); } } finally { // dispose Graphics2D object g.dispose(); } } /*package*/ static void freeCaches() { Loading Loading @@ -410,8 +424,16 @@ public class Canvas_Delegate { float left, float top, float right, float bottom, int regionOp) { // FIXME throw new UnsupportedOperationException(); // get the delegate from the native int. Canvas_Delegate canvasDelegate = sManager.getDelegate(nCanvas); if (canvasDelegate == null) { assert false; } return canvasDelegate.clipRect( (int) left, (int) top, (int) right, (int) bottom, regionOp); } /*package*/ static boolean native_clipPath(int nativeCanvas, Loading Loading @@ -1001,6 +1023,16 @@ public class Canvas_Delegate { } } private boolean clipRect(int left, int top, int right, int bottom, int regionOp) { if (regionOp == Region.Op.INTERSECT.nativeInt) { Graphics2D gc = getGraphics2d(); gc.clipRect(left, top, right - left, bottom - top); return gc.getClip().getBounds().isEmpty() == false; } else { throw new UnsupportedOperationException(); } } private void setBitmap(BufferedImage image) { mBufferedImage = image; mGraphicsStack.push(mBufferedImage.createGraphics()); Loading tools/layoutlib/bridge/src/android/graphics/Paint_Delegate.java +54 −19 Original line number Diff line number Diff line Loading @@ -390,16 +390,23 @@ public class Paint_Delegate { } /*package*/ static float ascent(Paint thisPaint) { // FIXME throw new UnsupportedOperationException(); // get the delegate Paint_Delegate delegate = sManager.getDelegate(thisPaint.mNativePaint); if (delegate == null) { assert false; return 0; } /*package*/ static float descent(Paint thisPaint) { // FIXME throw new UnsupportedOperationException(); if (delegate.mFonts.size() > 0) { java.awt.FontMetrics javaMetrics = delegate.mFonts.get(0).mMetrics; // Android expects negative ascent so we invert the value from Java. return - javaMetrics.getAscent(); } /*package*/ static float getFontMetrics(Paint thisPaint, FontMetrics metrics) { return 0; } /*package*/ static float descent(Paint thisPaint) { // get the delegate Paint_Delegate delegate = sManager.getDelegate(thisPaint.mNativePaint); if (delegate == null) { Loading @@ -409,21 +416,24 @@ public class Paint_Delegate { if (delegate.mFonts.size() > 0) { java.awt.FontMetrics javaMetrics = delegate.mFonts.get(0).mMetrics; if (metrics != null) { // Android expects negative ascent so we invert the value from Java. metrics.top = - javaMetrics.getMaxAscent(); metrics.ascent = - javaMetrics.getAscent(); metrics.descent = javaMetrics.getDescent(); metrics.bottom = javaMetrics.getMaxDescent(); metrics.leading = javaMetrics.getLeading(); return javaMetrics.getDescent(); } return javaMetrics.getHeight(); return 0; } /*package*/ static float getFontMetrics(Paint thisPaint, FontMetrics metrics) { // get the delegate Paint_Delegate delegate = sManager.getDelegate(thisPaint.mNativePaint); if (delegate == null) { assert false; return 0; } return delegate.getFontMetrics(metrics); } /*package*/ static int getFontMetricsInt(Paint thisPaint, FontMetricsInt fmi) { // get the delegate Paint_Delegate delegate = sManager.getDelegate(thisPaint.mNativePaint); Loading Loading @@ -698,8 +708,14 @@ public class Paint_Delegate { } /*package*/ static float native_getFontMetrics(int native_paint, FontMetrics metrics) { // FIXME throw new UnsupportedOperationException(); // get the delegate from the native int. Paint_Delegate delegate = sManager.getDelegate(native_paint); if (delegate == null) { assert false; return 0.f; } return delegate.getFontMetrics(metrics); } /*package*/ static int native_getTextWidths(int native_object, char[] text, int index, Loading Loading @@ -941,9 +957,28 @@ public class Paint_Delegate { } return 0; } private float getFontMetrics(FontMetrics metrics) { if (mFonts.size() > 0) { java.awt.FontMetrics javaMetrics = mFonts.get(0).mMetrics; if (metrics != null) { // Android expects negative ascent so we invert the value from Java. metrics.top = - javaMetrics.getMaxAscent(); metrics.ascent = - javaMetrics.getAscent(); metrics.descent = javaMetrics.getDescent(); metrics.bottom = javaMetrics.getMaxDescent(); metrics.leading = javaMetrics.getLeading(); } return javaMetrics.getHeight(); } return 0; } private static void setFlag(Paint thisPaint, int flagMask, boolean flagValue) { // get the delegate from the native int. Paint_Delegate delegate = sManager.getDelegate(thisPaint.mNativePaint); Loading Loading
tools/layoutlib/bridge/src/android/graphics/Canvas_Delegate.java +49 −17 Original line number Diff line number Diff line Loading @@ -170,7 +170,8 @@ public class Canvas_Delegate { } /*package*/ static boolean clipRect(Canvas thisCanvas, RectF rect) { return clipRect(thisCanvas, rect.left, rect.top, rect.right, rect.bottom); return clipRect(thisCanvas, (int) rect.left, (int) rect.top, (int) rect.right, (int) rect.bottom); } /*package*/ static boolean clipRect(Canvas thisCanvas, Rect rect) { Loading @@ -179,16 +180,7 @@ public class Canvas_Delegate { /*package*/ static boolean clipRect(Canvas thisCanvas, float left, float top, float right, float bottom) { // get the delegate from the native int. Canvas_Delegate canvasDelegate = sManager.getDelegate(thisCanvas.mNativeCanvas); if (canvasDelegate == null) { assert false; return false; } canvasDelegate.getGraphics2d().clipRect((int)left, (int)top, (int)(right-left), (int)(bottom-top)); return true; return clipRect(thisCanvas, (int) left, (int) top, (int) right, (int) bottom); } /*package*/ static boolean clipRect(Canvas thisCanvas, int left, int top, int right, Loading @@ -200,8 +192,7 @@ public class Canvas_Delegate { return false; } canvasDelegate.getGraphics2d().clipRect(left, top, right - left, bottom - top); return true; return canvasDelegate.clipRect(left, top, right, bottom, Region.Op.INTERSECT.nativeInt); } /*package*/ static int save(Canvas thisCanvas) { Loading Loading @@ -277,8 +268,31 @@ public class Canvas_Delegate { /*package*/ static void drawLines(Canvas thisCanvas, float[] pts, int offset, int count, Paint paint) { // FIXME throw new UnsupportedOperationException(); // get the delegate from the native int. Canvas_Delegate canvasDelegate = sManager.getDelegate(thisCanvas.mNativeCanvas); if (canvasDelegate == null) { assert false; return; } Paint_Delegate paintDelegate = Paint_Delegate.getDelegate(paint.mNativePaint); if (paintDelegate == null) { assert false; return; } // get a Graphics2D object configured with the drawing parameters. Graphics2D g = canvasDelegate.getCustomGraphics(paintDelegate); try { for (int i = 0 ; i < count ; i += 4) { g.drawLine((int)pts[i + offset], (int)pts[i + offset + 1], (int)pts[i + offset + 2], (int)pts[i + offset + 3]); } } finally { // dispose Graphics2D object g.dispose(); } } /*package*/ static void freeCaches() { Loading Loading @@ -410,8 +424,16 @@ public class Canvas_Delegate { float left, float top, float right, float bottom, int regionOp) { // FIXME throw new UnsupportedOperationException(); // get the delegate from the native int. Canvas_Delegate canvasDelegate = sManager.getDelegate(nCanvas); if (canvasDelegate == null) { assert false; } return canvasDelegate.clipRect( (int) left, (int) top, (int) right, (int) bottom, regionOp); } /*package*/ static boolean native_clipPath(int nativeCanvas, Loading Loading @@ -1001,6 +1023,16 @@ public class Canvas_Delegate { } } private boolean clipRect(int left, int top, int right, int bottom, int regionOp) { if (regionOp == Region.Op.INTERSECT.nativeInt) { Graphics2D gc = getGraphics2d(); gc.clipRect(left, top, right - left, bottom - top); return gc.getClip().getBounds().isEmpty() == false; } else { throw new UnsupportedOperationException(); } } private void setBitmap(BufferedImage image) { mBufferedImage = image; mGraphicsStack.push(mBufferedImage.createGraphics()); Loading
tools/layoutlib/bridge/src/android/graphics/Paint_Delegate.java +54 −19 Original line number Diff line number Diff line Loading @@ -390,16 +390,23 @@ public class Paint_Delegate { } /*package*/ static float ascent(Paint thisPaint) { // FIXME throw new UnsupportedOperationException(); // get the delegate Paint_Delegate delegate = sManager.getDelegate(thisPaint.mNativePaint); if (delegate == null) { assert false; return 0; } /*package*/ static float descent(Paint thisPaint) { // FIXME throw new UnsupportedOperationException(); if (delegate.mFonts.size() > 0) { java.awt.FontMetrics javaMetrics = delegate.mFonts.get(0).mMetrics; // Android expects negative ascent so we invert the value from Java. return - javaMetrics.getAscent(); } /*package*/ static float getFontMetrics(Paint thisPaint, FontMetrics metrics) { return 0; } /*package*/ static float descent(Paint thisPaint) { // get the delegate Paint_Delegate delegate = sManager.getDelegate(thisPaint.mNativePaint); if (delegate == null) { Loading @@ -409,21 +416,24 @@ public class Paint_Delegate { if (delegate.mFonts.size() > 0) { java.awt.FontMetrics javaMetrics = delegate.mFonts.get(0).mMetrics; if (metrics != null) { // Android expects negative ascent so we invert the value from Java. metrics.top = - javaMetrics.getMaxAscent(); metrics.ascent = - javaMetrics.getAscent(); metrics.descent = javaMetrics.getDescent(); metrics.bottom = javaMetrics.getMaxDescent(); metrics.leading = javaMetrics.getLeading(); return javaMetrics.getDescent(); } return javaMetrics.getHeight(); return 0; } /*package*/ static float getFontMetrics(Paint thisPaint, FontMetrics metrics) { // get the delegate Paint_Delegate delegate = sManager.getDelegate(thisPaint.mNativePaint); if (delegate == null) { assert false; return 0; } return delegate.getFontMetrics(metrics); } /*package*/ static int getFontMetricsInt(Paint thisPaint, FontMetricsInt fmi) { // get the delegate Paint_Delegate delegate = sManager.getDelegate(thisPaint.mNativePaint); Loading Loading @@ -698,8 +708,14 @@ public class Paint_Delegate { } /*package*/ static float native_getFontMetrics(int native_paint, FontMetrics metrics) { // FIXME throw new UnsupportedOperationException(); // get the delegate from the native int. Paint_Delegate delegate = sManager.getDelegate(native_paint); if (delegate == null) { assert false; return 0.f; } return delegate.getFontMetrics(metrics); } /*package*/ static int native_getTextWidths(int native_object, char[] text, int index, Loading Loading @@ -941,9 +957,28 @@ public class Paint_Delegate { } return 0; } private float getFontMetrics(FontMetrics metrics) { if (mFonts.size() > 0) { java.awt.FontMetrics javaMetrics = mFonts.get(0).mMetrics; if (metrics != null) { // Android expects negative ascent so we invert the value from Java. metrics.top = - javaMetrics.getMaxAscent(); metrics.ascent = - javaMetrics.getAscent(); metrics.descent = javaMetrics.getDescent(); metrics.bottom = javaMetrics.getMaxDescent(); metrics.leading = javaMetrics.getLeading(); } return javaMetrics.getHeight(); } return 0; } private static void setFlag(Paint thisPaint, int flagMask, boolean flagValue) { // get the delegate from the native int. Paint_Delegate delegate = sManager.getDelegate(thisPaint.mNativePaint); Loading