diff options
author | Xavier Ducrohet <xav@android.com> | 2010-01-14 19:19:06 -0800 |
---|---|---|
committer | Xavier Ducrohet <xav@android.com> | 2010-01-14 19:43:54 -0800 |
commit | 5ac8f409f52b4b121614a8797d289f01f96c6527 (patch) | |
tree | 11bef17011fb08ef634e26b84aa50919d4a6ae3c /tools/layoutlib | |
parent | 79f05bb4a502d5768f84cf975f791f3ba981e0e5 (diff) | |
download | frameworks_base-5ac8f409f52b4b121614a8797d289f01f96c6527.zip frameworks_base-5ac8f409f52b4b121614a8797d289f01f96c6527.tar.gz frameworks_base-5ac8f409f52b4b121614a8797d289f01f96c6527.tar.bz2 |
ADT/Layoutlib: properly handle stroke information.
Change-Id: Iec9284d0e65d1313739e361d1fd5a522646fd1fd
Diffstat (limited to 'tools/layoutlib')
-rw-r--r-- | tools/layoutlib/bridge/src/android/graphics/Canvas.java | 16 | ||||
-rw-r--r-- | tools/layoutlib/bridge/src/android/graphics/Paint.java | 27 |
2 files changed, 41 insertions, 2 deletions
diff --git a/tools/layoutlib/bridge/src/android/graphics/Canvas.java b/tools/layoutlib/bridge/src/android/graphics/Canvas.java index c49e11e..9111286 100644 --- a/tools/layoutlib/bridge/src/android/graphics/Canvas.java +++ b/tools/layoutlib/bridge/src/android/graphics/Canvas.java @@ -31,6 +31,7 @@ import android.graphics.Paint.Style; import android.graphics.Region.Op; import java.awt.AlphaComposite; +import java.awt.BasicStroke; import java.awt.Color; import java.awt.Composite; import java.awt.Graphics2D; @@ -104,12 +105,23 @@ public class Canvas extends _Original_Canvas { * <p/>The object must be disposed ({@link Graphics2D#dispose()}) after being used. */ private Graphics2D getNewGraphics(Paint paint, Graphics2D g) { + // make new one g = (Graphics2D)g.create(); g.setColor(new Color(paint.getColor())); int alpha = paint.getAlpha(); float falpha = alpha / 255.f; + if (paint.getStyle() == Style.STROKE) { + g.setStroke(new BasicStroke( + paint.getStrokeWidth(), + paint.getStrokeCap().getJavaCap(), + paint.getStrokeJoin().getJavaJoin(), + paint.getStrokeMiter() + // FIXME: add dash info. + )); + } + Xfermode xfermode = paint.getXfermode(); if (xfermode instanceof PorterDuffXfermode) { PorterDuff.Mode mode = ((PorterDuffXfermode)xfermode).getMode(); @@ -784,7 +796,7 @@ public class Canvas extends _Original_Canvas { private final void doDrawRect(int left, int top, int width, int height, Paint paint) { // get current graphisc - if (width != 0 && height != 0) { + if (width > 0 && height > 0) { Graphics2D g = getGraphics2d(); g = getNewGraphics(paint, g); @@ -811,7 +823,7 @@ public class Canvas extends _Original_Canvas { @Override public void drawRoundRect(RectF rect, float rx, float ry, Paint paint) { // get current graphisc - if (rect.width() != 0 && rect.height() != 0) { + if (rect.width() > 0 && rect.height() > 0) { Graphics2D g = getGraphics2d(); g = getNewGraphics(paint, g); diff --git a/tools/layoutlib/bridge/src/android/graphics/Paint.java b/tools/layoutlib/bridge/src/android/graphics/Paint.java index 312dab3..2d03618 100644 --- a/tools/layoutlib/bridge/src/android/graphics/Paint.java +++ b/tools/layoutlib/bridge/src/android/graphics/Paint.java @@ -21,6 +21,7 @@ import android.text.SpannableStringBuilder; import android.text.SpannedString; import android.text.TextUtils; +import java.awt.BasicStroke; import java.awt.Font; import java.awt.Toolkit; import java.awt.font.FontRenderContext; @@ -127,6 +128,19 @@ public class Paint extends _Original_Paint { this.nativeInt = nativeInt; } final int nativeInt; + + /** custom for layoutlib */ + public int getJavaCap() { + switch (this) { + case BUTT: + return BasicStroke.CAP_BUTT; + case ROUND: + return BasicStroke.CAP_ROUND; + default: + case SQUARE: + return BasicStroke.CAP_SQUARE; + } + } } /** @@ -151,6 +165,19 @@ public class Paint extends _Original_Paint { this.nativeInt = nativeInt; } final int nativeInt; + + /** custom for layoutlib */ + public int getJavaJoin() { + switch (this) { + default: + case MITER: + return BasicStroke.JOIN_MITER; + case ROUND: + return BasicStroke.JOIN_ROUND; + case BEVEL: + return BasicStroke.JOIN_BEVEL; + } + } } /** |