summaryrefslogtreecommitdiffstats
path: root/tools/layoutlib/bridge/src/android/graphics
diff options
context:
space:
mode:
authorDeepanshu Gupta <deepanshu@google.com>2015-05-12 12:01:16 -0700
committerDeepanshu Gupta <deepanshu@google.com>2015-05-13 18:15:20 -0700
commitd77b9ed7dcc42efca33b225c4594a30aab9e709c (patch)
tree31e0b5365f9095b7587ec65bffafadea43b303c1 /tools/layoutlib/bridge/src/android/graphics
parenta12ec8f1e28cb5a8601bf606852f1d34d7c91996 (diff)
downloadframeworks_base-d77b9ed7dcc42efca33b225c4594a30aab9e709c.zip
frameworks_base-d77b9ed7dcc42efca33b225c4594a30aab9e709c.tar.gz
frameworks_base-d77b9ed7dcc42efca33b225c4594a30aab9e709c.tar.bz2
Add missing delegates for M preview.
- Remove ICU dependency (use the version bundled with platform). - Restructure intelliJ project to move dependencies to module. - Minor fixes to layoutlib tests. TODO: - Load ICU data. - Hyphenator doesn't work. - High quality line breaker not present. Change-Id: I965e096e17bfc97ee995a649c3f4f6f64bb4f70d
Diffstat (limited to 'tools/layoutlib/bridge/src/android/graphics')
-rw-r--r--tools/layoutlib/bridge/src/android/graphics/BidiRenderer.java13
-rw-r--r--tools/layoutlib/bridge/src/android/graphics/BitmapShader_Delegate.java59
-rw-r--r--tools/layoutlib/bridge/src/android/graphics/Bitmap_Delegate.java51
-rw-r--r--tools/layoutlib/bridge/src/android/graphics/Canvas_Delegate.java32
-rw-r--r--tools/layoutlib/bridge/src/android/graphics/NinePatch_Delegate.java19
-rw-r--r--tools/layoutlib/bridge/src/android/graphics/Paint_Delegate.java102
-rw-r--r--tools/layoutlib/bridge/src/android/graphics/Shader_Delegate.java5
7 files changed, 183 insertions, 98 deletions
diff --git a/tools/layoutlib/bridge/src/android/graphics/BidiRenderer.java b/tools/layoutlib/bridge/src/android/graphics/BidiRenderer.java
index a4a3b7d..21f36ce 100644
--- a/tools/layoutlib/bridge/src/android/graphics/BidiRenderer.java
+++ b/tools/layoutlib/bridge/src/android/graphics/BidiRenderer.java
@@ -19,6 +19,12 @@ package android.graphics;
import com.android.ide.common.rendering.api.LayoutLog;
import com.android.layoutlib.bridge.Bridge;
+import android.graphics.Paint_Delegate.FontInfo;
+import android.icu.lang.UScript;
+import android.icu.lang.UScriptRun;
+import android.icu.text.Bidi;
+import android.icu.text.BidiRun;
+
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.Toolkit;
@@ -29,13 +35,6 @@ import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
-import com.ibm.icu.lang.UScript;
-import com.ibm.icu.lang.UScriptRun;
-import com.ibm.icu.text.Bidi;
-import com.ibm.icu.text.BidiRun;
-
-import android.graphics.Paint_Delegate.FontInfo;
-
/**
* Render the text by breaking it into various scripts and using the right font for each script.
* Can be used to measure the text without actually drawing it.
diff --git a/tools/layoutlib/bridge/src/android/graphics/BitmapShader_Delegate.java b/tools/layoutlib/bridge/src/android/graphics/BitmapShader_Delegate.java
index e9b5d6e..af47aeb 100644
--- a/tools/layoutlib/bridge/src/android/graphics/BitmapShader_Delegate.java
+++ b/tools/layoutlib/bridge/src/android/graphics/BitmapShader_Delegate.java
@@ -23,7 +23,15 @@ import com.android.tools.layoutlib.annotations.LayoutlibDelegate;
import android.graphics.Shader.TileMode;
+import java.awt.PaintContext;
+import java.awt.Rectangle;
+import java.awt.RenderingHints;
+import java.awt.geom.AffineTransform;
+import java.awt.geom.NoninvertibleTransformException;
+import java.awt.geom.Rectangle2D;
+import java.awt.image.BufferedImage;
import java.awt.image.ColorModel;
+import java.awt.image.Raster;
/**
* Delegate implementing the native methods of android.graphics.BitmapShader
@@ -67,9 +75,9 @@ public class BitmapShader_Delegate extends Shader_Delegate {
// ---- native methods ----
@LayoutlibDelegate
- /*package*/ static long nativeCreate(long native_bitmap, int shaderTileModeX,
+ /*package*/ static long nativeCreate(Bitmap androidBitmap, int shaderTileModeX,
int shaderTileModeY) {
- Bitmap_Delegate bitmap = Bitmap_Delegate.getDelegate(native_bitmap);
+ Bitmap_Delegate bitmap = Bitmap_Delegate.getDelegate(androidBitmap);
if (bitmap == null) {
return 0;
}
@@ -83,17 +91,17 @@ public class BitmapShader_Delegate extends Shader_Delegate {
// ---- Private delegate/helper methods ----
- private BitmapShader_Delegate(java.awt.image.BufferedImage image,
+ private BitmapShader_Delegate(BufferedImage image,
TileMode tileModeX, TileMode tileModeY) {
mJavaPaint = new BitmapShaderPaint(image, tileModeX, tileModeY);
}
private class BitmapShaderPaint implements java.awt.Paint {
- private final java.awt.image.BufferedImage mImage;
+ private final BufferedImage mImage;
private final TileMode mTileModeX;
private final TileMode mTileModeY;
- BitmapShaderPaint(java.awt.image.BufferedImage image,
+ BitmapShaderPaint(BufferedImage image,
TileMode tileModeX, TileMode tileModeY) {
mImage = image;
mTileModeX = tileModeX;
@@ -101,29 +109,24 @@ public class BitmapShader_Delegate extends Shader_Delegate {
}
@Override
- public java.awt.PaintContext createContext(
- java.awt.image.ColorModel colorModel,
- java.awt.Rectangle deviceBounds,
- java.awt.geom.Rectangle2D userBounds,
- java.awt.geom.AffineTransform xform,
- java.awt.RenderingHints hints) {
-
- java.awt.geom.AffineTransform canvasMatrix;
+ public PaintContext createContext(ColorModel colorModel, Rectangle deviceBounds,
+ Rectangle2D userBounds, AffineTransform xform, RenderingHints hints) {
+ AffineTransform canvasMatrix;
try {
canvasMatrix = xform.createInverse();
- } catch (java.awt.geom.NoninvertibleTransformException e) {
+ } catch (NoninvertibleTransformException e) {
Bridge.getLog().fidelityWarning(LayoutLog.TAG_MATRIX_INVERSE,
"Unable to inverse matrix in BitmapShader", e, null /*data*/);
- canvasMatrix = new java.awt.geom.AffineTransform();
+ canvasMatrix = new AffineTransform();
}
- java.awt.geom.AffineTransform localMatrix = getLocalMatrix();
+ AffineTransform localMatrix = getLocalMatrix();
try {
localMatrix = localMatrix.createInverse();
- } catch (java.awt.geom.NoninvertibleTransformException e) {
+ } catch (NoninvertibleTransformException e) {
Bridge.getLog().fidelityWarning(LayoutLog.TAG_MATRIX_INVERSE,
"Unable to inverse matrix in BitmapShader", e, null /*data*/);
- localMatrix = new java.awt.geom.AffineTransform();
+ localMatrix = new AffineTransform();
}
if (!colorModel.isCompatibleRaster(mImage.getRaster())) {
@@ -134,16 +137,16 @@ public class BitmapShader_Delegate extends Shader_Delegate {
return new BitmapShaderContext(canvasMatrix, localMatrix, colorModel);
}
- private class BitmapShaderContext implements java.awt.PaintContext {
+ private class BitmapShaderContext implements PaintContext {
- private final java.awt.geom.AffineTransform mCanvasMatrix;
- private final java.awt.geom.AffineTransform mLocalMatrix;
- private final java.awt.image.ColorModel mColorModel;
+ private final AffineTransform mCanvasMatrix;
+ private final AffineTransform mLocalMatrix;
+ private final ColorModel mColorModel;
public BitmapShaderContext(
- java.awt.geom.AffineTransform canvasMatrix,
- java.awt.geom.AffineTransform localMatrix,
- java.awt.image.ColorModel colorModel) {
+ AffineTransform canvasMatrix,
+ AffineTransform localMatrix,
+ ColorModel colorModel) {
mCanvasMatrix = canvasMatrix;
mLocalMatrix = localMatrix;
mColorModel = colorModel;
@@ -154,13 +157,13 @@ public class BitmapShader_Delegate extends Shader_Delegate {
}
@Override
- public java.awt.image.ColorModel getColorModel() {
+ public ColorModel getColorModel() {
return mColorModel;
}
@Override
- public java.awt.image.Raster getRaster(int x, int y, int w, int h) {
- java.awt.image.BufferedImage image = new java.awt.image.BufferedImage(
+ public Raster getRaster(int x, int y, int w, int h) {
+ BufferedImage image = new BufferedImage(
mColorModel, mColorModel.createCompatibleWritableRaster(w, h),
mColorModel.isAlphaPremultiplied(), null);
diff --git a/tools/layoutlib/bridge/src/android/graphics/Bitmap_Delegate.java b/tools/layoutlib/bridge/src/android/graphics/Bitmap_Delegate.java
index 970b9d0..874bc9d 100644
--- a/tools/layoutlib/bridge/src/android/graphics/Bitmap_Delegate.java
+++ b/tools/layoutlib/bridge/src/android/graphics/Bitmap_Delegate.java
@@ -16,6 +16,7 @@
package android.graphics;
+import com.android.annotations.Nullable;
import com.android.ide.common.rendering.api.LayoutLog;
import com.android.layoutlib.bridge.Bridge;
import com.android.layoutlib.bridge.impl.DelegateManager;
@@ -82,6 +83,12 @@ public final class Bitmap_Delegate {
return sManager.getDelegate(native_bitmap);
}
+ @Nullable
+ public static Bitmap_Delegate getDelegate(@Nullable Bitmap bitmap) {
+ // refSkPixelRef is a hack to get the native pointer: see #nativeRefPixelRef()
+ return bitmap == null ? null : getDelegate(bitmap.refSkPixelRef());
+ }
+
/**
* Creates and returns a {@link Bitmap} initialized with the given file content.
*
@@ -180,18 +187,7 @@ public final class Bitmap_Delegate {
return createBitmap(delegate, createFlags, density.getDpiValue());
}
- public static int getBufferedImageType(int nativeBitmapConfig) {
- switch (Config.nativeToConfig(nativeBitmapConfig)) {
- case ALPHA_8:
- return BufferedImage.TYPE_INT_ARGB;
- case RGB_565:
- return BufferedImage.TYPE_INT_ARGB;
- case ARGB_4444:
- return BufferedImage.TYPE_INT_ARGB;
- case ARGB_8888:
- return BufferedImage.TYPE_INT_ARGB;
- }
-
+ private static int getBufferedImageType() {
return BufferedImage.TYPE_INT_ARGB;
}
@@ -218,10 +214,6 @@ public final class Bitmap_Delegate {
return mHasAlpha && mConfig != Config.RGB_565;
}
- public boolean hasMipMap() {
- // TODO: check if more checks are required as in hasAlpha.
- return mHasMipMap;
- }
/**
* Update the generationId.
*
@@ -236,7 +228,7 @@ public final class Bitmap_Delegate {
@LayoutlibDelegate
/*package*/ static Bitmap nativeCreate(int[] colors, int offset, int stride, int width,
int height, int nativeConfig, boolean isMutable) {
- int imageType = getBufferedImageType(nativeConfig);
+ int imageType = getBufferedImageType();
// create the image
BufferedImage image = new BufferedImage(width, height, imageType);
@@ -264,7 +256,7 @@ public final class Bitmap_Delegate {
int width = srcImage.getWidth();
int height = srcImage.getHeight();
- int imageType = getBufferedImageType(nativeConfig);
+ int imageType = getBufferedImageType();
// create the image
BufferedImage image = new BufferedImage(width, height, imageType);
@@ -353,22 +345,16 @@ public final class Bitmap_Delegate {
/*package*/ static boolean nativeHasAlpha(long nativeBitmap) {
// get the delegate from the native int.
Bitmap_Delegate delegate = sManager.getDelegate(nativeBitmap);
- if (delegate == null) {
- return true;
- }
+ return delegate == null || delegate.mHasAlpha;
- return delegate.mHasAlpha;
}
@LayoutlibDelegate
/*package*/ static boolean nativeHasMipMap(long nativeBitmap) {
// get the delegate from the native int.
Bitmap_Delegate delegate = sManager.getDelegate(nativeBitmap);
- if (delegate == null) {
- return true;
- }
+ return delegate == null || delegate.mHasMipMap;
- return delegate.mHasMipMap;
}
@LayoutlibDelegate
@@ -489,11 +475,6 @@ public final class Bitmap_Delegate {
}
@LayoutlibDelegate
- /*package*/ static void nativePrepareToDraw(long nativeBitmap) {
- // nothing to be done here.
- }
-
- @LayoutlibDelegate
/*package*/ static boolean nativeIsPremultiplied(long nativeBitmap) {
// get the delegate from the native int.
Bitmap_Delegate delegate = sManager.getDelegate(nativeBitmap);
@@ -579,6 +560,14 @@ public final class Bitmap_Delegate {
return Arrays.equals(argb1, argb2);
}
+ // Only used by AssetAtlasService, which we don't care about.
+ @LayoutlibDelegate
+ /*package*/ static long nativeRefPixelRef(long nativeBitmap) {
+ // Hack: This is called by Bitmap.refSkPixelRef() and LayoutLib uses that method to get
+ // the native pointer from a Bitmap. So, we return nativeBitmap here.
+ return nativeBitmap;
+ }
+
// ---- Private delegate/helper methods ----
private Bitmap_Delegate(BufferedImage image, Config config) {
diff --git a/tools/layoutlib/bridge/src/android/graphics/Canvas_Delegate.java b/tools/layoutlib/bridge/src/android/graphics/Canvas_Delegate.java
index e1091f0..47acc42 100644
--- a/tools/layoutlib/bridge/src/android/graphics/Canvas_Delegate.java
+++ b/tools/layoutlib/bridge/src/android/graphics/Canvas_Delegate.java
@@ -16,6 +16,7 @@
package android.graphics;
+import com.android.annotations.Nullable;
import com.android.ide.common.rendering.api.LayoutLog;
import com.android.layoutlib.bridge.Bridge;
import com.android.layoutlib.bridge.impl.DelegateManager;
@@ -114,7 +115,11 @@ public final class Canvas_Delegate {
}
@LayoutlibDelegate
- /*package*/ static long initRaster(long nativeBitmapOrZero) {
+ /*package*/ static long initRaster(@Nullable Bitmap bitmap) {
+ long nativeBitmapOrZero = 0;
+ if (bitmap != null) {
+ nativeBitmapOrZero = bitmap.refSkPixelRef();
+ }
if (nativeBitmapOrZero > 0) {
// get the Bitmap from the int
Bitmap_Delegate bitmapDelegate = Bitmap_Delegate.getDelegate(nativeBitmapOrZero);
@@ -132,8 +137,7 @@ public final class Canvas_Delegate {
}
@LayoutlibDelegate
- /*package*/
- static void native_setBitmap(long canvas, long bitmap, boolean copyState) {
+ /*package*/ static void native_setBitmap(long canvas, Bitmap bitmap) {
Canvas_Delegate canvasDelegate = sManager.getDelegate(canvas);
Bitmap_Delegate bitmapDelegate = Bitmap_Delegate.getDelegate(bitmap);
if (canvasDelegate == null || bitmapDelegate==null) {
@@ -427,8 +431,7 @@ public final class Canvas_Delegate {
canvasDelegate.mDrawFilter = DrawFilter_Delegate.getDelegate(nativeFilter);
- if (canvasDelegate.mDrawFilter != null &&
- canvasDelegate.mDrawFilter.isSupported() == false) {
+ if (canvasDelegate.mDrawFilter != null && !canvasDelegate.mDrawFilter.isSupported()) {
Bridge.getLog().fidelityWarning(LayoutLog.TAG_DRAWFILTER,
canvasDelegate.mDrawFilter.getSupportMessage(), null, null /*data*/);
}
@@ -444,7 +447,7 @@ public final class Canvas_Delegate {
}
Rectangle rect = canvasDelegate.getSnapshot().getClip().getBounds();
- if (rect != null && rect.isEmpty() == false) {
+ if (rect != null && !rect.isEmpty()) {
bounds.left = rect.x;
bounds.top = rect.y;
bounds.right = rect.x + rect.width;
@@ -720,7 +723,7 @@ public final class Canvas_Delegate {
}
@LayoutlibDelegate
- /*package*/ static void native_drawBitmap(Canvas thisCanvas, long nativeCanvas, long bitmap,
+ /*package*/ static void native_drawBitmap(Canvas thisCanvas, long nativeCanvas, Bitmap bitmap,
float left, float top,
long nativePaintOrZero,
int canvasDensity,
@@ -742,7 +745,7 @@ public final class Canvas_Delegate {
}
@LayoutlibDelegate
- /*package*/ static void native_drawBitmap(Canvas thisCanvas, long nativeCanvas, long bitmap,
+ /*package*/ static void native_drawBitmap(Canvas thisCanvas, long nativeCanvas, Bitmap bitmap,
float srcLeft, float srcTop, float srcRight, float srcBottom,
float dstLeft, float dstTop, float dstRight, float dstBottom,
long nativePaintOrZero, int screenDensity, int bitmapDensity) {
@@ -783,7 +786,7 @@ public final class Canvas_Delegate {
}
@LayoutlibDelegate
- /*package*/ static void nativeDrawBitmapMatrix(long nCanvas, long nBitmap,
+ /*package*/ static void nativeDrawBitmapMatrix(long nCanvas, Bitmap bitmap,
long nMatrix, long nPaint) {
// get the delegate from the native int.
Canvas_Delegate canvasDelegate = sManager.getDelegate(nCanvas);
@@ -795,7 +798,7 @@ public final class Canvas_Delegate {
Paint_Delegate paintDelegate = Paint_Delegate.getDelegate(nPaint);
// get the delegate from the native int.
- Bitmap_Delegate bitmapDelegate = Bitmap_Delegate.getDelegate(nBitmap);
+ Bitmap_Delegate bitmapDelegate = Bitmap_Delegate.getDelegate(bitmap);
if (bitmapDelegate == null) {
return;
}
@@ -824,7 +827,7 @@ public final class Canvas_Delegate {
}
@LayoutlibDelegate
- /*package*/ static void nativeDrawBitmapMesh(long nCanvas, long nBitmap,
+ /*package*/ static void nativeDrawBitmapMesh(long nCanvas, Bitmap bitmap,
int meshWidth, int meshHeight, float[] verts, int vertOffset, int[] colors,
int colorOffset, long nPaint) {
// FIXME
@@ -1041,8 +1044,7 @@ public final class Canvas_Delegate {
}
/**
- * Restores the {@link GcSnapshot} to <var>saveCount</var>
- * @param saveCount the saveCount
+ * Restores the top {@link GcSnapshot}
*/
private void restore() {
mSnapshot = mSnapshot.restore();
@@ -1105,7 +1107,7 @@ public final class Canvas_Delegate {
// before drawing it.
if (bitmap.getConfig() == Bitmap.Config.ALPHA_8) {
fixAlpha8Bitmap(image);
- } else if (bitmap.hasAlpha() == false) {
+ } else if (!bitmap.hasAlpha()) {
// hasAlpha is merely a rendering hint. There can in fact be alpha values
// in the bitmap but it should be ignored at drawing time.
// There is two ways to do this:
@@ -1125,7 +1127,7 @@ public final class Canvas_Delegate {
}
// if we can't force SRC mode, then create a temp bitmap of TYPE_RGB
- if (forceSrcMode[0] == false) {
+ if (!forceSrcMode[0]) {
image = Bitmap_Delegate.createCopy(image, BufferedImage.TYPE_INT_RGB, 0xFF);
}
}
diff --git a/tools/layoutlib/bridge/src/android/graphics/NinePatch_Delegate.java b/tools/layoutlib/bridge/src/android/graphics/NinePatch_Delegate.java
index e16dbda..e8d34d0 100644
--- a/tools/layoutlib/bridge/src/android/graphics/NinePatch_Delegate.java
+++ b/tools/layoutlib/bridge/src/android/graphics/NinePatch_Delegate.java
@@ -90,7 +90,7 @@ public final class NinePatch_Delegate {
if (oos != null) {
try {
oos.close();
- } catch (IOException e) {
+ } catch (IOException ignored) {
}
}
}
@@ -136,7 +136,7 @@ public final class NinePatch_Delegate {
if (ois != null) {
try {
ois.close();
- } catch (IOException e) {
+ } catch (IOException ignored) {
}
}
}
@@ -150,15 +150,12 @@ public final class NinePatch_Delegate {
@LayoutlibDelegate
/*package*/ static boolean isNinePatchChunk(byte[] chunk) {
NinePatchChunk chunkObject = getChunk(chunk);
- if (chunkObject != null) {
- return true;
- }
+ return chunkObject != null;
- return false;
}
@LayoutlibDelegate
- /*package*/ static long validateNinePatchChunk(long bitmap, byte[] chunk) {
+ /*package*/ static long validateNinePatchChunk(byte[] chunk) {
// the default JNI implementation only checks that the byte[] has the same
// size as the C struct it represent. Since we cannot do the same check (serialization
// will return different size depending on content), we do nothing.
@@ -173,7 +170,7 @@ public final class NinePatch_Delegate {
}
@LayoutlibDelegate
- /*package*/ static void nativeDraw(long canvas_instance, RectF loc, long bitmap_instance,
+ /*package*/ static void nativeDraw(long canvas_instance, RectF loc, Bitmap bitmap_instance,
long chunk, long paint_instance_or_null, int destDensity, int srcDensity) {
draw(canvas_instance,
(int) loc.left, (int) loc.top, (int) loc.right, (int) loc.bottom,
@@ -182,7 +179,7 @@ public final class NinePatch_Delegate {
}
@LayoutlibDelegate
- /*package*/ static void nativeDraw(long canvas_instance, Rect loc, long bitmap_instance,
+ /*package*/ static void nativeDraw(long canvas_instance, Rect loc, Bitmap bitmap_instance,
long chunk, long paint_instance_or_null, int destDensity, int srcDensity) {
draw(canvas_instance,
loc.left, loc.top, loc.right, loc.bottom,
@@ -191,7 +188,7 @@ public final class NinePatch_Delegate {
}
@LayoutlibDelegate
- /*package*/ static long nativeGetTransparentRegion(long bitmap, long chunk, Rect location) {
+ /*package*/ static long nativeGetTransparentRegion(Bitmap bitmap, long chunk, Rect location) {
return 0;
}
@@ -199,7 +196,7 @@ public final class NinePatch_Delegate {
private static void draw(long canvas_instance,
final int left, final int top, final int right, final int bottom,
- long bitmap_instance, long chunk, long paint_instance_or_null,
+ Bitmap bitmap_instance, long chunk, long paint_instance_or_null,
final int destDensity, final int srcDensity) {
// get the delegate from the native int.
final Bitmap_Delegate bitmap_delegate = Bitmap_Delegate.getDelegate(bitmap_instance);
diff --git a/tools/layoutlib/bridge/src/android/graphics/Paint_Delegate.java b/tools/layoutlib/bridge/src/android/graphics/Paint_Delegate.java
index 0c8c0d6..a2e9a85 100644
--- a/tools/layoutlib/bridge/src/android/graphics/Paint_Delegate.java
+++ b/tools/layoutlib/bridge/src/android/graphics/Paint_Delegate.java
@@ -16,6 +16,8 @@
package android.graphics;
+import com.android.annotations.NonNull;
+import com.android.annotations.Nullable;
import com.android.ide.common.rendering.api.LayoutLog;
import com.android.layoutlib.bridge.Bridge;
import com.android.layoutlib.bridge.impl.DelegateManager;
@@ -83,6 +85,8 @@ public class Paint_Delegate {
private float mTextScaleX;
private float mTextSkewX;
private int mHintingMode = Paint.HINTING_ON;
+ private int mHyphenEdit;
+ private float mLetterSpacing; // not used in actual text rendering.
// Variant of the font. A paint's variant can only be compact or elegant.
private FontVariant mFontVariant = FontVariant.COMPACT;
@@ -100,6 +104,7 @@ public class Paint_Delegate {
// ---- Public Helper methods ----
+ @Nullable
public static Paint_Delegate getDelegate(long native_paint) {
return sManager.getDelegate(native_paint);
}
@@ -1088,18 +1093,107 @@ public class Paint_Delegate {
@LayoutlibDelegate
/*package*/ static float native_getLetterSpacing(long nativePaint) {
- // TODO: throw a fidelity warning.
- return 0;
+ Paint_Delegate delegate = sManager.getDelegate(nativePaint);
+ if (delegate == null) {
+ return 0;
+ }
+ return delegate.mLetterSpacing;
}
@LayoutlibDelegate
/*package*/ static void native_setLetterSpacing(long nativePaint, float letterSpacing) {
- // pass.
+ Bridge.getLog().fidelityWarning("textRendering", "Paint.setLetterSpacing() not supported.",
+ null, null);
+ Paint_Delegate delegate = sManager.getDelegate(nativePaint);
+ if (delegate == null) {
+ return;
+ }
+ delegate.mLetterSpacing = letterSpacing;
}
@LayoutlibDelegate
/*package*/ static void native_setFontFeatureSettings(long nativePaint, String settings) {
- // pass.
+ Bridge.getLog().fidelityWarning("textRendering",
+ "Paint.setFontFeatureSettings() not supported.", null, null);
+ }
+
+ @LayoutlibDelegate
+ /*package*/ static int native_getHyphenEdit(long nativePaint) {
+ Paint_Delegate delegate = sManager.getDelegate(nativePaint);
+ if (delegate == null) {
+ return 0;
+ }
+ return delegate.mHyphenEdit;
+ }
+
+ @LayoutlibDelegate
+ /*package*/ static void native_setHyphenEdit(long nativePaint, int hyphen) {
+ Paint_Delegate delegate = sManager.getDelegate(nativePaint);
+ if (delegate == null) {
+ return;
+ }
+ delegate.mHyphenEdit = hyphen;
+ }
+
+ @LayoutlibDelegate
+ /*package*/ static boolean native_hasGlyph(long nativePaint, long nativeTypeface, int bidiFlags,
+ String string) {
+ Paint_Delegate delegate = sManager.getDelegate(nativePaint);
+ if (delegate == null) {
+ return false;
+ }
+ if (string.length() == 0) {
+ return false;
+ }
+ if (string.length() > 1) {
+ Bridge.getLog().fidelityWarning("textRendering",
+ "Paint.hasGlyph() is not supported for ligatures.", null, null);
+ return false;
+ }
+ assert nativeTypeface == delegate.mNativeTypeface;
+ Typeface_Delegate typeface_delegate = Typeface_Delegate.getDelegate(nativeTypeface);
+
+ char c = string.charAt(0);
+ for (Font font : typeface_delegate.getFonts(delegate.mFontVariant)) {
+ if (font.canDisplay(c)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+
+ @LayoutlibDelegate
+ /*package*/ static float native_getRunAdvance(long nativePaint, long nativeTypeface,
+ @NonNull char[] text, int start, int end, int contextStart, int contextEnd,
+ boolean isRtl, int offset) {
+ int count = end - start;
+ float[] advances = new float[count];
+ native_getTextRunAdvances(nativePaint, nativeTypeface, text, start, count,
+ contextStart, contextEnd - contextStart, isRtl, advances, 0);
+ float sum = 0;
+ for (int i = 0; i < offset; i++) {
+ sum += advances[i];
+ }
+ return sum;
+ }
+
+ @LayoutlibDelegate
+ /*package*/ static int native_getOffsetForAdvance(long nativePaint, long nativeTypeface,
+ char[] text, int start, int end, int contextStart, int contextEnd, boolean isRtl,
+ float advance) {
+ int count = end - start;
+ float[] advances = new float[count];
+ native_getTextRunAdvances(nativePaint, nativeTypeface, text, start, count,
+ contextStart, contextEnd - contextStart, isRtl, advances, 0);
+ float sum = 0;
+ int i;
+ for (i = 0; i < count && sum < advance; i++) {
+ sum += advances[i];
+ }
+ float distanceToI = sum - advance;
+ float distanceToIMinus1 = advance - (sum - advances[i]);
+ return distanceToI > distanceToIMinus1 ? i : i - 1;
}
// ---- Private delegate/helper methods ----
diff --git a/tools/layoutlib/bridge/src/android/graphics/Shader_Delegate.java b/tools/layoutlib/bridge/src/android/graphics/Shader_Delegate.java
index 14e9960..0d491a0 100644
--- a/tools/layoutlib/bridge/src/android/graphics/Shader_Delegate.java
+++ b/tools/layoutlib/bridge/src/android/graphics/Shader_Delegate.java
@@ -81,14 +81,15 @@ public abstract class Shader_Delegate {
}
@LayoutlibDelegate
- /*package*/ static void nativeSetLocalMatrix(long native_shader, long matrix_instance) {
+ /*package*/ static long nativeSetLocalMatrix(long native_shader, long matrix_instance) {
// get the delegate from the native int.
Shader_Delegate shaderDelegate = sManager.getDelegate(native_shader);
if (shaderDelegate == null) {
- return;
+ return native_shader;
}
shaderDelegate.mLocalMatrix = Matrix_Delegate.getDelegate(matrix_instance);
+ return native_shader;
}
// ---- Private delegate/helper methods ----