Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package android.graphics; |
| 18 | |
Xavier Ducrohet | 3f9b037 | 2011-01-13 10:59:34 -0800 | [diff] [blame] | 19 | import com.android.ide.common.rendering.api.LayoutLog; |
Xavier Ducrohet | a6e51d5 | 2010-12-23 07:16:21 -0800 | [diff] [blame] | 20 | import com.android.layoutlib.bridge.Bridge; |
Xavier Ducrohet | 3bd9898 | 2010-11-09 18:25:03 -0800 | [diff] [blame] | 21 | import com.android.layoutlib.bridge.impl.DelegateManager; |
Xavier Ducrohet | 94c80bf | 2011-02-09 17:17:49 -0800 | [diff] [blame] | 22 | import com.android.tools.layoutlib.annotations.LayoutlibDelegate; |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 23 | |
Deepanshu Gupta | 5a6b3ab | 2014-05-30 17:43:33 -0700 | [diff] [blame] | 24 | import android.graphics.FontFamily_Delegate.FontVariant; |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 25 | import android.graphics.Paint.FontMetrics; |
| 26 | import android.graphics.Paint.FontMetricsInt; |
Xavier Ducrohet | 37f2180 | 2010-11-01 16:17:18 -0700 | [diff] [blame] | 27 | import android.text.TextUtils; |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 28 | |
Xavier Ducrohet | 37f2180 | 2010-11-01 16:17:18 -0700 | [diff] [blame] | 29 | import java.awt.BasicStroke; |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 30 | import java.awt.Font; |
Xavier Ducrohet | b976124 | 2010-12-23 10:22:14 -0800 | [diff] [blame] | 31 | import java.awt.Shape; |
| 32 | import java.awt.Stroke; |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 33 | import java.awt.Toolkit; |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 34 | import java.awt.geom.AffineTransform; |
| 35 | import java.util.ArrayList; |
| 36 | import java.util.Collections; |
| 37 | import java.util.List; |
Xavier Ducrohet | 43526ab | 2012-04-23 17:41:37 -0700 | [diff] [blame] | 38 | import java.util.Locale; |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 39 | |
| 40 | /** |
| 41 | * Delegate implementing the native methods of android.graphics.Paint |
| 42 | * |
| 43 | * Through the layoutlib_create tool, the original native methods of Paint have been replaced |
| 44 | * by calls to methods of the same name in this delegate class. |
| 45 | * |
| 46 | * This class behaves like the original native implementation, but in Java, keeping previously |
| 47 | * native data into its own objects and mapping them to int that are sent back and forth between |
| 48 | * it and the original Paint class. |
| 49 | * |
| 50 | * @see DelegateManager |
| 51 | * |
| 52 | */ |
| 53 | public class Paint_Delegate { |
| 54 | |
| 55 | /** |
Deepanshu Gupta | 017c062 | 2014-05-19 16:14:23 -0700 | [diff] [blame] | 56 | * Class associating a {@link Font} and its {@link java.awt.FontMetrics}. |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 57 | */ |
Xavier Ducrohet | 37f2180 | 2010-11-01 16:17:18 -0700 | [diff] [blame] | 58 | /*package*/ static final class FontInfo { |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 59 | Font mFont; |
| 60 | java.awt.FontMetrics mMetrics; |
| 61 | } |
| 62 | |
| 63 | // ---- delegate manager ---- |
| 64 | private static final DelegateManager<Paint_Delegate> sManager = |
Xavier Ducrohet | b2de839 | 2011-02-23 16:51:08 -0800 | [diff] [blame] | 65 | new DelegateManager<Paint_Delegate>(Paint_Delegate.class); |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 66 | |
| 67 | // ---- delegate helper data ---- |
Deepanshu Gupta | 382256f | 2014-08-09 14:14:32 -0700 | [diff] [blame] | 68 | |
| 69 | // This list can contain null elements. |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 70 | private List<FontInfo> mFonts; |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 71 | |
| 72 | // ---- delegate data ---- |
| 73 | private int mFlags; |
| 74 | private int mColor; |
| 75 | private int mStyle; |
| 76 | private int mCap; |
| 77 | private int mJoin; |
Xavier Ducrohet | 37f2180 | 2010-11-01 16:17:18 -0700 | [diff] [blame] | 78 | private int mTextAlign; |
Xavier Ducrohet | 9167279 | 2011-02-22 11:54:37 -0800 | [diff] [blame] | 79 | private Typeface_Delegate mTypeface; |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 80 | private float mStrokeWidth; |
| 81 | private float mStrokeMiter; |
| 82 | private float mTextSize; |
| 83 | private float mTextScaleX; |
| 84 | private float mTextSkewX; |
Xavier Ducrohet | b6f7f57 | 2011-08-22 13:13:16 -0700 | [diff] [blame] | 85 | private int mHintingMode = Paint.HINTING_ON; |
Deepanshu Gupta | 8916b21 | 2014-06-11 15:40:47 -0700 | [diff] [blame] | 86 | // Variant of the font. A paint's variant can only be compact or elegant. |
| 87 | private FontVariant mFontVariant = FontVariant.COMPACT; |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 88 | |
Xavier Ducrohet | 9167279 | 2011-02-22 11:54:37 -0800 | [diff] [blame] | 89 | private Xfermode_Delegate mXfermode; |
| 90 | private ColorFilter_Delegate mColorFilter; |
| 91 | private Shader_Delegate mShader; |
| 92 | private PathEffect_Delegate mPathEffect; |
| 93 | private MaskFilter_Delegate mMaskFilter; |
| 94 | private Rasterizer_Delegate mRasterizer; |
Xavier Ducrohet | a313b65 | 2010-11-01 18:45:20 -0700 | [diff] [blame] | 95 | |
Xavier Ducrohet | 43526ab | 2012-04-23 17:41:37 -0700 | [diff] [blame] | 96 | private Locale mLocale = Locale.getDefault(); |
| 97 | |
Deepanshu Gupta | b1ce7c1 | 2014-06-05 14:18:54 -0700 | [diff] [blame] | 98 | // Used only to assert invariants. |
| 99 | public long mNativeTypeface; |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 100 | |
| 101 | // ---- Public Helper methods ---- |
| 102 | |
Narayan Kamath | 633d688 | 2014-01-27 14:24:16 +0000 | [diff] [blame] | 103 | public static Paint_Delegate getDelegate(long native_paint) { |
Xavier Ducrohet | 37f2180 | 2010-11-01 16:17:18 -0700 | [diff] [blame] | 104 | return sManager.getDelegate(native_paint); |
| 105 | } |
| 106 | |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 107 | /** |
Deepanshu Gupta | 017c062 | 2014-05-19 16:14:23 -0700 | [diff] [blame] | 108 | * Returns the list of {@link Font} objects. |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 109 | */ |
| 110 | public List<FontInfo> getFonts() { |
| 111 | return mFonts; |
| 112 | } |
| 113 | |
Xavier Ducrohet | a313b65 | 2010-11-01 18:45:20 -0700 | [diff] [blame] | 114 | public boolean isAntiAliased() { |
| 115 | return (mFlags & Paint.ANTI_ALIAS_FLAG) != 0; |
| 116 | } |
| 117 | |
Xavier Ducrohet | 37f2180 | 2010-11-01 16:17:18 -0700 | [diff] [blame] | 118 | public boolean isFilterBitmap() { |
| 119 | return (mFlags & Paint.FILTER_BITMAP_FLAG) != 0; |
| 120 | } |
| 121 | |
| 122 | public int getStyle() { |
| 123 | return mStyle; |
| 124 | } |
| 125 | |
| 126 | public int getColor() { |
| 127 | return mColor; |
| 128 | } |
| 129 | |
Xavier Ducrohet | 6622522 | 2010-12-21 01:33:04 -0800 | [diff] [blame] | 130 | public int getAlpha() { |
| 131 | return mColor >>> 24; |
| 132 | } |
| 133 | |
Xavier Ducrohet | cf2030c | 2010-12-21 06:20:28 -0800 | [diff] [blame] | 134 | public void setAlpha(int alpha) { |
| 135 | mColor = (alpha << 24) | (mColor & 0x00FFFFFF); |
| 136 | } |
| 137 | |
Xavier Ducrohet | 37f2180 | 2010-11-01 16:17:18 -0700 | [diff] [blame] | 138 | public int getTextAlign() { |
| 139 | return mTextAlign; |
| 140 | } |
| 141 | |
| 142 | public float getStrokeWidth() { |
| 143 | return mStrokeWidth; |
| 144 | } |
| 145 | |
Xavier Ducrohet | 6622522 | 2010-12-21 01:33:04 -0800 | [diff] [blame] | 146 | /** |
| 147 | * returns the value of stroke miter needed by the java api. |
| 148 | */ |
| 149 | public float getJavaStrokeMiter() { |
Xavier Ducrohet | cf2030c | 2010-12-21 06:20:28 -0800 | [diff] [blame] | 150 | float miter = mStrokeMiter * mStrokeWidth; |
| 151 | if (miter < 1.f) { |
| 152 | miter = 1.f; |
| 153 | } |
| 154 | return miter; |
Xavier Ducrohet | 37f2180 | 2010-11-01 16:17:18 -0700 | [diff] [blame] | 155 | } |
| 156 | |
| 157 | public int getJavaCap() { |
| 158 | switch (Paint.sCapArray[mCap]) { |
| 159 | case BUTT: |
| 160 | return BasicStroke.CAP_BUTT; |
| 161 | case ROUND: |
| 162 | return BasicStroke.CAP_ROUND; |
| 163 | default: |
| 164 | case SQUARE: |
| 165 | return BasicStroke.CAP_SQUARE; |
| 166 | } |
| 167 | } |
| 168 | |
| 169 | public int getJavaJoin() { |
| 170 | switch (Paint.sJoinArray[mJoin]) { |
| 171 | default: |
| 172 | case MITER: |
| 173 | return BasicStroke.JOIN_MITER; |
| 174 | case ROUND: |
| 175 | return BasicStroke.JOIN_ROUND; |
| 176 | case BEVEL: |
| 177 | return BasicStroke.JOIN_BEVEL; |
| 178 | } |
| 179 | } |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 180 | |
Xavier Ducrohet | b976124 | 2010-12-23 10:22:14 -0800 | [diff] [blame] | 181 | public Stroke getJavaStroke() { |
Xavier Ducrohet | 9167279 | 2011-02-22 11:54:37 -0800 | [diff] [blame] | 182 | if (mPathEffect != null) { |
| 183 | if (mPathEffect.isSupported()) { |
| 184 | Stroke stroke = mPathEffect.getStroke(this); |
Xavier Ducrohet | b976124 | 2010-12-23 10:22:14 -0800 | [diff] [blame] | 185 | assert stroke != null; |
| 186 | if (stroke != null) { |
| 187 | return stroke; |
| 188 | } |
| 189 | } else { |
Xavier Ducrohet | 3f9b037 | 2011-01-13 10:59:34 -0800 | [diff] [blame] | 190 | Bridge.getLog().fidelityWarning(LayoutLog.TAG_PATHEFFECT, |
Xavier Ducrohet | 9167279 | 2011-02-22 11:54:37 -0800 | [diff] [blame] | 191 | mPathEffect.getSupportMessage(), |
Xavier Ducrohet | f69bb29 | 2011-01-14 16:40:43 -0800 | [diff] [blame] | 192 | null, null /*data*/); |
Xavier Ducrohet | b976124 | 2010-12-23 10:22:14 -0800 | [diff] [blame] | 193 | } |
| 194 | } |
| 195 | |
| 196 | // if no custom stroke as been set, set the default one. |
| 197 | return new BasicStroke( |
| 198 | getStrokeWidth(), |
| 199 | getJavaCap(), |
| 200 | getJavaJoin(), |
| 201 | getJavaStrokeMiter()); |
| 202 | } |
| 203 | |
Xavier Ducrohet | a6e51d5 | 2010-12-23 07:16:21 -0800 | [diff] [blame] | 204 | /** |
| 205 | * Returns the {@link Xfermode} delegate or null if none have been set |
| 206 | * |
| 207 | * @return the delegate or null. |
| 208 | */ |
| 209 | public Xfermode_Delegate getXfermode() { |
Xavier Ducrohet | 9167279 | 2011-02-22 11:54:37 -0800 | [diff] [blame] | 210 | return mXfermode; |
Xavier Ducrohet | f1a17452 | 2010-11-01 22:02:08 -0700 | [diff] [blame] | 211 | } |
| 212 | |
Xavier Ducrohet | a6e51d5 | 2010-12-23 07:16:21 -0800 | [diff] [blame] | 213 | /** |
| 214 | * Returns the {@link ColorFilter} delegate or null if none have been set |
| 215 | * |
| 216 | * @return the delegate or null. |
| 217 | */ |
| 218 | public ColorFilter_Delegate getColorFilter() { |
Xavier Ducrohet | 9167279 | 2011-02-22 11:54:37 -0800 | [diff] [blame] | 219 | return mColorFilter; |
Xavier Ducrohet | f1a17452 | 2010-11-01 22:02:08 -0700 | [diff] [blame] | 220 | } |
| 221 | |
Xavier Ducrohet | a6e51d5 | 2010-12-23 07:16:21 -0800 | [diff] [blame] | 222 | /** |
| 223 | * Returns the {@link Shader} delegate or null if none have been set |
| 224 | * |
| 225 | * @return the delegate or null. |
| 226 | */ |
| 227 | public Shader_Delegate getShader() { |
Xavier Ducrohet | 9167279 | 2011-02-22 11:54:37 -0800 | [diff] [blame] | 228 | return mShader; |
Xavier Ducrohet | f1a17452 | 2010-11-01 22:02:08 -0700 | [diff] [blame] | 229 | } |
| 230 | |
Xavier Ducrohet | a6e51d5 | 2010-12-23 07:16:21 -0800 | [diff] [blame] | 231 | /** |
Xavier Ducrohet | a6e51d5 | 2010-12-23 07:16:21 -0800 | [diff] [blame] | 232 | * Returns the {@link MaskFilter} delegate or null if none have been set |
| 233 | * |
| 234 | * @return the delegate or null. |
| 235 | */ |
| 236 | public MaskFilter_Delegate getMaskFilter() { |
Xavier Ducrohet | 9167279 | 2011-02-22 11:54:37 -0800 | [diff] [blame] | 237 | return mMaskFilter; |
Xavier Ducrohet | a6e51d5 | 2010-12-23 07:16:21 -0800 | [diff] [blame] | 238 | } |
| 239 | |
| 240 | /** |
| 241 | * Returns the {@link Rasterizer} delegate or null if none have been set |
| 242 | * |
| 243 | * @return the delegate or null. |
| 244 | */ |
| 245 | public Rasterizer_Delegate getRasterizer() { |
Xavier Ducrohet | 9167279 | 2011-02-22 11:54:37 -0800 | [diff] [blame] | 246 | return mRasterizer; |
Xavier Ducrohet | f1a17452 | 2010-11-01 22:02:08 -0700 | [diff] [blame] | 247 | } |
| 248 | |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 249 | // ---- native methods ---- |
| 250 | |
Xavier Ducrohet | 94c80bf | 2011-02-09 17:17:49 -0800 | [diff] [blame] | 251 | @LayoutlibDelegate |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 252 | /*package*/ static int getFlags(Paint thisPaint) { |
| 253 | // get the delegate from the native int. |
Derek Sollenberger | 82934b5 | 2014-10-15 13:50:33 -0400 | [diff] [blame] | 254 | Paint_Delegate delegate = sManager.getDelegate(thisPaint.getNativeInstance()); |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 255 | if (delegate == null) { |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 256 | return 0; |
| 257 | } |
| 258 | |
| 259 | return delegate.mFlags; |
| 260 | } |
| 261 | |
Xavier Ducrohet | 43526ab | 2012-04-23 17:41:37 -0700 | [diff] [blame] | 262 | |
| 263 | |
Xavier Ducrohet | 94c80bf | 2011-02-09 17:17:49 -0800 | [diff] [blame] | 264 | @LayoutlibDelegate |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 265 | /*package*/ static void setFlags(Paint thisPaint, int flags) { |
| 266 | // get the delegate from the native int. |
Derek Sollenberger | 82934b5 | 2014-10-15 13:50:33 -0400 | [diff] [blame] | 267 | Paint_Delegate delegate = sManager.getDelegate(thisPaint.getNativeInstance()); |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 268 | if (delegate == null) { |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 269 | return; |
| 270 | } |
| 271 | |
| 272 | delegate.mFlags = flags; |
| 273 | } |
| 274 | |
Xavier Ducrohet | 94c80bf | 2011-02-09 17:17:49 -0800 | [diff] [blame] | 275 | @LayoutlibDelegate |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 276 | /*package*/ static void setFilterBitmap(Paint thisPaint, boolean filter) { |
Xavier Ducrohet | 37f2180 | 2010-11-01 16:17:18 -0700 | [diff] [blame] | 277 | setFlag(thisPaint, Paint.FILTER_BITMAP_FLAG, filter); |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 278 | } |
| 279 | |
Xavier Ducrohet | 94c80bf | 2011-02-09 17:17:49 -0800 | [diff] [blame] | 280 | @LayoutlibDelegate |
Xavier Ducrohet | b6f7f57 | 2011-08-22 13:13:16 -0700 | [diff] [blame] | 281 | /*package*/ static int getHinting(Paint thisPaint) { |
| 282 | // get the delegate from the native int. |
Derek Sollenberger | 82934b5 | 2014-10-15 13:50:33 -0400 | [diff] [blame] | 283 | Paint_Delegate delegate = sManager.getDelegate(thisPaint.getNativeInstance()); |
Xavier Ducrohet | b6f7f57 | 2011-08-22 13:13:16 -0700 | [diff] [blame] | 284 | if (delegate == null) { |
| 285 | return Paint.HINTING_ON; |
| 286 | } |
| 287 | |
| 288 | return delegate.mHintingMode; |
| 289 | } |
| 290 | |
| 291 | @LayoutlibDelegate |
| 292 | /*package*/ static void setHinting(Paint thisPaint, int mode) { |
| 293 | // get the delegate from the native int. |
Derek Sollenberger | 82934b5 | 2014-10-15 13:50:33 -0400 | [diff] [blame] | 294 | Paint_Delegate delegate = sManager.getDelegate(thisPaint.getNativeInstance()); |
Xavier Ducrohet | b6f7f57 | 2011-08-22 13:13:16 -0700 | [diff] [blame] | 295 | if (delegate == null) { |
| 296 | return; |
| 297 | } |
| 298 | |
| 299 | delegate.mHintingMode = mode; |
| 300 | } |
| 301 | |
| 302 | @LayoutlibDelegate |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 303 | /*package*/ static void setAntiAlias(Paint thisPaint, boolean aa) { |
| 304 | setFlag(thisPaint, Paint.ANTI_ALIAS_FLAG, aa); |
| 305 | } |
| 306 | |
Xavier Ducrohet | 94c80bf | 2011-02-09 17:17:49 -0800 | [diff] [blame] | 307 | @LayoutlibDelegate |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 308 | /*package*/ static void setSubpixelText(Paint thisPaint, boolean subpixelText) { |
| 309 | setFlag(thisPaint, Paint.SUBPIXEL_TEXT_FLAG, subpixelText); |
| 310 | } |
| 311 | |
Xavier Ducrohet | 94c80bf | 2011-02-09 17:17:49 -0800 | [diff] [blame] | 312 | @LayoutlibDelegate |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 313 | /*package*/ static void setUnderlineText(Paint thisPaint, boolean underlineText) { |
| 314 | setFlag(thisPaint, Paint.UNDERLINE_TEXT_FLAG, underlineText); |
| 315 | } |
| 316 | |
Xavier Ducrohet | 94c80bf | 2011-02-09 17:17:49 -0800 | [diff] [blame] | 317 | @LayoutlibDelegate |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 318 | /*package*/ static void setStrikeThruText(Paint thisPaint, boolean strikeThruText) { |
| 319 | setFlag(thisPaint, Paint.STRIKE_THRU_TEXT_FLAG, strikeThruText); |
| 320 | } |
| 321 | |
Xavier Ducrohet | 94c80bf | 2011-02-09 17:17:49 -0800 | [diff] [blame] | 322 | @LayoutlibDelegate |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 323 | /*package*/ static void setFakeBoldText(Paint thisPaint, boolean fakeBoldText) { |
| 324 | setFlag(thisPaint, Paint.FAKE_BOLD_TEXT_FLAG, fakeBoldText); |
| 325 | } |
| 326 | |
Xavier Ducrohet | 94c80bf | 2011-02-09 17:17:49 -0800 | [diff] [blame] | 327 | @LayoutlibDelegate |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 328 | /*package*/ static void setDither(Paint thisPaint, boolean dither) { |
| 329 | setFlag(thisPaint, Paint.DITHER_FLAG, dither); |
| 330 | } |
| 331 | |
Xavier Ducrohet | 94c80bf | 2011-02-09 17:17:49 -0800 | [diff] [blame] | 332 | @LayoutlibDelegate |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 333 | /*package*/ static void setLinearText(Paint thisPaint, boolean linearText) { |
| 334 | setFlag(thisPaint, Paint.LINEAR_TEXT_FLAG, linearText); |
| 335 | } |
| 336 | |
Xavier Ducrohet | 94c80bf | 2011-02-09 17:17:49 -0800 | [diff] [blame] | 337 | @LayoutlibDelegate |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 338 | /*package*/ static int getColor(Paint thisPaint) { |
| 339 | // get the delegate from the native int. |
Derek Sollenberger | 82934b5 | 2014-10-15 13:50:33 -0400 | [diff] [blame] | 340 | Paint_Delegate delegate = sManager.getDelegate(thisPaint.getNativeInstance()); |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 341 | if (delegate == null) { |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 342 | return 0; |
| 343 | } |
| 344 | |
| 345 | return delegate.mColor; |
| 346 | } |
| 347 | |
Xavier Ducrohet | 94c80bf | 2011-02-09 17:17:49 -0800 | [diff] [blame] | 348 | @LayoutlibDelegate |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 349 | /*package*/ static void setColor(Paint thisPaint, int color) { |
| 350 | // get the delegate from the native int. |
Derek Sollenberger | 82934b5 | 2014-10-15 13:50:33 -0400 | [diff] [blame] | 351 | Paint_Delegate delegate = sManager.getDelegate(thisPaint.getNativeInstance()); |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 352 | if (delegate == null) { |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 353 | return; |
| 354 | } |
| 355 | |
| 356 | delegate.mColor = color; |
| 357 | } |
| 358 | |
Xavier Ducrohet | 94c80bf | 2011-02-09 17:17:49 -0800 | [diff] [blame] | 359 | @LayoutlibDelegate |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 360 | /*package*/ static int getAlpha(Paint thisPaint) { |
| 361 | // get the delegate from the native int. |
Derek Sollenberger | 82934b5 | 2014-10-15 13:50:33 -0400 | [diff] [blame] | 362 | Paint_Delegate delegate = sManager.getDelegate(thisPaint.getNativeInstance()); |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 363 | if (delegate == null) { |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 364 | return 0; |
| 365 | } |
| 366 | |
Xavier Ducrohet | 6622522 | 2010-12-21 01:33:04 -0800 | [diff] [blame] | 367 | return delegate.getAlpha(); |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 368 | } |
| 369 | |
Xavier Ducrohet | 94c80bf | 2011-02-09 17:17:49 -0800 | [diff] [blame] | 370 | @LayoutlibDelegate |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 371 | /*package*/ static void setAlpha(Paint thisPaint, int a) { |
| 372 | // get the delegate from the native int. |
Derek Sollenberger | 82934b5 | 2014-10-15 13:50:33 -0400 | [diff] [blame] | 373 | Paint_Delegate delegate = sManager.getDelegate(thisPaint.getNativeInstance()); |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 374 | if (delegate == null) { |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 375 | return; |
| 376 | } |
| 377 | |
Xavier Ducrohet | cf2030c | 2010-12-21 06:20:28 -0800 | [diff] [blame] | 378 | delegate.setAlpha(a); |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 379 | } |
| 380 | |
Xavier Ducrohet | 94c80bf | 2011-02-09 17:17:49 -0800 | [diff] [blame] | 381 | @LayoutlibDelegate |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 382 | /*package*/ static float getStrokeWidth(Paint thisPaint) { |
| 383 | // get the delegate from the native int. |
Derek Sollenberger | 82934b5 | 2014-10-15 13:50:33 -0400 | [diff] [blame] | 384 | Paint_Delegate delegate = sManager.getDelegate(thisPaint.getNativeInstance()); |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 385 | if (delegate == null) { |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 386 | return 1.f; |
| 387 | } |
| 388 | |
| 389 | return delegate.mStrokeWidth; |
| 390 | } |
| 391 | |
Xavier Ducrohet | 94c80bf | 2011-02-09 17:17:49 -0800 | [diff] [blame] | 392 | @LayoutlibDelegate |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 393 | /*package*/ static void setStrokeWidth(Paint thisPaint, float width) { |
| 394 | // get the delegate from the native int. |
Derek Sollenberger | 82934b5 | 2014-10-15 13:50:33 -0400 | [diff] [blame] | 395 | Paint_Delegate delegate = sManager.getDelegate(thisPaint.getNativeInstance()); |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 396 | if (delegate == null) { |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 397 | return; |
| 398 | } |
| 399 | |
| 400 | delegate.mStrokeWidth = width; |
| 401 | } |
| 402 | |
Xavier Ducrohet | 94c80bf | 2011-02-09 17:17:49 -0800 | [diff] [blame] | 403 | @LayoutlibDelegate |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 404 | /*package*/ static float getStrokeMiter(Paint thisPaint) { |
| 405 | // get the delegate from the native int. |
Derek Sollenberger | 82934b5 | 2014-10-15 13:50:33 -0400 | [diff] [blame] | 406 | Paint_Delegate delegate = sManager.getDelegate(thisPaint.getNativeInstance()); |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 407 | if (delegate == null) { |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 408 | return 1.f; |
| 409 | } |
| 410 | |
| 411 | return delegate.mStrokeMiter; |
| 412 | } |
| 413 | |
Xavier Ducrohet | 94c80bf | 2011-02-09 17:17:49 -0800 | [diff] [blame] | 414 | @LayoutlibDelegate |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 415 | /*package*/ static void setStrokeMiter(Paint thisPaint, float miter) { |
| 416 | // get the delegate from the native int. |
Derek Sollenberger | 82934b5 | 2014-10-15 13:50:33 -0400 | [diff] [blame] | 417 | Paint_Delegate delegate = sManager.getDelegate(thisPaint.getNativeInstance()); |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 418 | if (delegate == null) { |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 419 | return; |
| 420 | } |
| 421 | |
| 422 | delegate.mStrokeMiter = miter; |
| 423 | } |
| 424 | |
Xavier Ducrohet | 94c80bf | 2011-02-09 17:17:49 -0800 | [diff] [blame] | 425 | @LayoutlibDelegate |
Deepanshu Gupta | 0bec685 | 2014-05-15 09:30:11 -0700 | [diff] [blame] | 426 | /*package*/ static void native_setShadowLayer(long paint, float radius, float dx, float dy, |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 427 | int color) { |
| 428 | // FIXME |
Xavier Ducrohet | 3f9b037 | 2011-01-13 10:59:34 -0800 | [diff] [blame] | 429 | Bridge.getLog().fidelityWarning(LayoutLog.TAG_UNSUPPORTED, |
Xavier Ducrohet | f69bb29 | 2011-01-14 16:40:43 -0800 | [diff] [blame] | 430 | "Paint.setShadowLayer is not supported.", null, null /*data*/); |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 431 | } |
| 432 | |
Xavier Ducrohet | 94c80bf | 2011-02-09 17:17:49 -0800 | [diff] [blame] | 433 | @LayoutlibDelegate |
Deepanshu Gupta | 0bec685 | 2014-05-15 09:30:11 -0700 | [diff] [blame] | 434 | /*package*/ static boolean native_hasShadowLayer(long paint) { |
| 435 | // FIXME |
| 436 | Bridge.getLog().fidelityWarning(LayoutLog.TAG_UNSUPPORTED, |
| 437 | "Paint.hasShadowLayer is not supported.", null, null /*data*/); |
| 438 | return false; |
| 439 | } |
| 440 | |
| 441 | @LayoutlibDelegate |
Deepanshu Gupta | bd49b12 | 2014-04-18 15:43:06 -0700 | [diff] [blame] | 442 | /*package*/ static boolean isElegantTextHeight(Paint thisPaint) { |
Deepanshu Gupta | 017c062 | 2014-05-19 16:14:23 -0700 | [diff] [blame] | 443 | // get the delegate from the native int. |
Derek Sollenberger | 82934b5 | 2014-10-15 13:50:33 -0400 | [diff] [blame] | 444 | Paint_Delegate delegate = sManager.getDelegate(thisPaint.getNativeInstance()); |
Deepanshu Gupta | 5a6b3ab | 2014-05-30 17:43:33 -0700 | [diff] [blame] | 445 | return delegate != null && delegate.mFontVariant == FontVariant.ELEGANT; |
Deepanshu Gupta | bd49b12 | 2014-04-18 15:43:06 -0700 | [diff] [blame] | 446 | } |
| 447 | |
| 448 | @LayoutlibDelegate |
| 449 | /*package*/ static void setElegantTextHeight(Paint thisPaint, boolean elegant) { |
Deepanshu Gupta | 017c062 | 2014-05-19 16:14:23 -0700 | [diff] [blame] | 450 | // get the delegate from the native int. |
Derek Sollenberger | 82934b5 | 2014-10-15 13:50:33 -0400 | [diff] [blame] | 451 | Paint_Delegate delegate = sManager.getDelegate(thisPaint.getNativeInstance()); |
Deepanshu Gupta | 017c062 | 2014-05-19 16:14:23 -0700 | [diff] [blame] | 452 | if (delegate == null) { |
| 453 | return; |
| 454 | } |
| 455 | |
Deepanshu Gupta | 5a6b3ab | 2014-05-30 17:43:33 -0700 | [diff] [blame] | 456 | delegate.mFontVariant = elegant ? FontVariant.ELEGANT : FontVariant.COMPACT; |
Deepanshu Gupta | bd49b12 | 2014-04-18 15:43:06 -0700 | [diff] [blame] | 457 | } |
| 458 | |
| 459 | @LayoutlibDelegate |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 460 | /*package*/ static float getTextSize(Paint thisPaint) { |
| 461 | // get the delegate from the native int. |
Derek Sollenberger | 82934b5 | 2014-10-15 13:50:33 -0400 | [diff] [blame] | 462 | Paint_Delegate delegate = sManager.getDelegate(thisPaint.getNativeInstance()); |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 463 | if (delegate == null) { |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 464 | return 1.f; |
| 465 | } |
| 466 | |
| 467 | return delegate.mTextSize; |
| 468 | } |
| 469 | |
Xavier Ducrohet | 94c80bf | 2011-02-09 17:17:49 -0800 | [diff] [blame] | 470 | @LayoutlibDelegate |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 471 | /*package*/ static void setTextSize(Paint thisPaint, float textSize) { |
| 472 | // get the delegate from the native int. |
Derek Sollenberger | 82934b5 | 2014-10-15 13:50:33 -0400 | [diff] [blame] | 473 | Paint_Delegate delegate = sManager.getDelegate(thisPaint.getNativeInstance()); |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 474 | if (delegate == null) { |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 475 | return; |
| 476 | } |
| 477 | |
| 478 | delegate.mTextSize = textSize; |
Xavier Ducrohet | 42e2b28 | 2010-12-06 11:08:37 -0800 | [diff] [blame] | 479 | delegate.updateFontObject(); |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 480 | } |
| 481 | |
Xavier Ducrohet | 94c80bf | 2011-02-09 17:17:49 -0800 | [diff] [blame] | 482 | @LayoutlibDelegate |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 483 | /*package*/ static float getTextScaleX(Paint thisPaint) { |
| 484 | // get the delegate from the native int. |
Derek Sollenberger | 82934b5 | 2014-10-15 13:50:33 -0400 | [diff] [blame] | 485 | Paint_Delegate delegate = sManager.getDelegate(thisPaint.getNativeInstance()); |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 486 | if (delegate == null) { |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 487 | return 1.f; |
| 488 | } |
| 489 | |
| 490 | return delegate.mTextScaleX; |
| 491 | } |
| 492 | |
Xavier Ducrohet | 94c80bf | 2011-02-09 17:17:49 -0800 | [diff] [blame] | 493 | @LayoutlibDelegate |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 494 | /*package*/ static void setTextScaleX(Paint thisPaint, float scaleX) { |
| 495 | // get the delegate from the native int. |
Derek Sollenberger | 82934b5 | 2014-10-15 13:50:33 -0400 | [diff] [blame] | 496 | Paint_Delegate delegate = sManager.getDelegate(thisPaint.getNativeInstance()); |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 497 | if (delegate == null) { |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 498 | return; |
| 499 | } |
| 500 | |
| 501 | delegate.mTextScaleX = scaleX; |
Xavier Ducrohet | 42e2b28 | 2010-12-06 11:08:37 -0800 | [diff] [blame] | 502 | delegate.updateFontObject(); |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 503 | } |
| 504 | |
Xavier Ducrohet | 94c80bf | 2011-02-09 17:17:49 -0800 | [diff] [blame] | 505 | @LayoutlibDelegate |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 506 | /*package*/ static float getTextSkewX(Paint thisPaint) { |
| 507 | // get the delegate from the native int. |
Derek Sollenberger | 82934b5 | 2014-10-15 13:50:33 -0400 | [diff] [blame] | 508 | Paint_Delegate delegate = sManager.getDelegate(thisPaint.getNativeInstance()); |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 509 | if (delegate == null) { |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 510 | return 1.f; |
| 511 | } |
| 512 | |
| 513 | return delegate.mTextSkewX; |
| 514 | } |
| 515 | |
Xavier Ducrohet | 94c80bf | 2011-02-09 17:17:49 -0800 | [diff] [blame] | 516 | @LayoutlibDelegate |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 517 | /*package*/ static void setTextSkewX(Paint thisPaint, float skewX) { |
| 518 | // get the delegate from the native int. |
Derek Sollenberger | 82934b5 | 2014-10-15 13:50:33 -0400 | [diff] [blame] | 519 | Paint_Delegate delegate = sManager.getDelegate(thisPaint.getNativeInstance()); |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 520 | if (delegate == null) { |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 521 | return; |
| 522 | } |
| 523 | |
| 524 | delegate.mTextSkewX = skewX; |
Xavier Ducrohet | 42e2b28 | 2010-12-06 11:08:37 -0800 | [diff] [blame] | 525 | delegate.updateFontObject(); |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 526 | } |
| 527 | |
Xavier Ducrohet | 94c80bf | 2011-02-09 17:17:49 -0800 | [diff] [blame] | 528 | @LayoutlibDelegate |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 529 | /*package*/ static float ascent(Paint thisPaint) { |
Xavier Ducrohet | df67eab | 2010-12-13 16:42:01 -0800 | [diff] [blame] | 530 | // get the delegate |
Derek Sollenberger | 82934b5 | 2014-10-15 13:50:33 -0400 | [diff] [blame] | 531 | Paint_Delegate delegate = sManager.getDelegate(thisPaint.getNativeInstance()); |
Xavier Ducrohet | df67eab | 2010-12-13 16:42:01 -0800 | [diff] [blame] | 532 | if (delegate == null) { |
Xavier Ducrohet | df67eab | 2010-12-13 16:42:01 -0800 | [diff] [blame] | 533 | return 0; |
| 534 | } |
| 535 | |
| 536 | if (delegate.mFonts.size() > 0) { |
| 537 | java.awt.FontMetrics javaMetrics = delegate.mFonts.get(0).mMetrics; |
| 538 | // Android expects negative ascent so we invert the value from Java. |
| 539 | return - javaMetrics.getAscent(); |
| 540 | } |
| 541 | |
| 542 | return 0; |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 543 | } |
| 544 | |
Xavier Ducrohet | 94c80bf | 2011-02-09 17:17:49 -0800 | [diff] [blame] | 545 | @LayoutlibDelegate |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 546 | /*package*/ static float descent(Paint thisPaint) { |
Xavier Ducrohet | df67eab | 2010-12-13 16:42:01 -0800 | [diff] [blame] | 547 | // get the delegate |
Derek Sollenberger | 82934b5 | 2014-10-15 13:50:33 -0400 | [diff] [blame] | 548 | Paint_Delegate delegate = sManager.getDelegate(thisPaint.getNativeInstance()); |
Xavier Ducrohet | df67eab | 2010-12-13 16:42:01 -0800 | [diff] [blame] | 549 | if (delegate == null) { |
Xavier Ducrohet | df67eab | 2010-12-13 16:42:01 -0800 | [diff] [blame] | 550 | return 0; |
| 551 | } |
| 552 | |
| 553 | if (delegate.mFonts.size() > 0) { |
| 554 | java.awt.FontMetrics javaMetrics = delegate.mFonts.get(0).mMetrics; |
| 555 | return javaMetrics.getDescent(); |
| 556 | } |
| 557 | |
| 558 | return 0; |
| 559 | |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 560 | } |
| 561 | |
Xavier Ducrohet | 94c80bf | 2011-02-09 17:17:49 -0800 | [diff] [blame] | 562 | @LayoutlibDelegate |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 563 | /*package*/ static float getFontMetrics(Paint thisPaint, FontMetrics metrics) { |
Xavier Ducrohet | 37f2180 | 2010-11-01 16:17:18 -0700 | [diff] [blame] | 564 | // get the delegate |
Derek Sollenberger | 82934b5 | 2014-10-15 13:50:33 -0400 | [diff] [blame] | 565 | Paint_Delegate delegate = sManager.getDelegate(thisPaint.getNativeInstance()); |
Xavier Ducrohet | 37f2180 | 2010-11-01 16:17:18 -0700 | [diff] [blame] | 566 | if (delegate == null) { |
Xavier Ducrohet | 37f2180 | 2010-11-01 16:17:18 -0700 | [diff] [blame] | 567 | return 0; |
| 568 | } |
| 569 | |
Xavier Ducrohet | df67eab | 2010-12-13 16:42:01 -0800 | [diff] [blame] | 570 | return delegate.getFontMetrics(metrics); |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 571 | } |
| 572 | |
Xavier Ducrohet | 94c80bf | 2011-02-09 17:17:49 -0800 | [diff] [blame] | 573 | @LayoutlibDelegate |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 574 | /*package*/ static int getFontMetricsInt(Paint thisPaint, FontMetricsInt fmi) { |
Xavier Ducrohet | 37f2180 | 2010-11-01 16:17:18 -0700 | [diff] [blame] | 575 | // get the delegate |
Derek Sollenberger | 82934b5 | 2014-10-15 13:50:33 -0400 | [diff] [blame] | 576 | Paint_Delegate delegate = sManager.getDelegate(thisPaint.getNativeInstance()); |
Xavier Ducrohet | 37f2180 | 2010-11-01 16:17:18 -0700 | [diff] [blame] | 577 | if (delegate == null) { |
Xavier Ducrohet | 37f2180 | 2010-11-01 16:17:18 -0700 | [diff] [blame] | 578 | return 0; |
| 579 | } |
| 580 | |
| 581 | if (delegate.mFonts.size() > 0) { |
| 582 | java.awt.FontMetrics javaMetrics = delegate.mFonts.get(0).mMetrics; |
| 583 | if (fmi != null) { |
| 584 | // Android expects negative ascent so we invert the value from Java. |
| 585 | fmi.top = - javaMetrics.getMaxAscent(); |
| 586 | fmi.ascent = - javaMetrics.getAscent(); |
| 587 | fmi.descent = javaMetrics.getDescent(); |
| 588 | fmi.bottom = javaMetrics.getMaxDescent(); |
| 589 | fmi.leading = javaMetrics.getLeading(); |
| 590 | } |
| 591 | |
| 592 | return javaMetrics.getHeight(); |
| 593 | } |
| 594 | |
| 595 | return 0; |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 596 | } |
| 597 | |
Xavier Ducrohet | 94c80bf | 2011-02-09 17:17:49 -0800 | [diff] [blame] | 598 | @LayoutlibDelegate |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 599 | /*package*/ static float native_measureText(Paint thisPaint, char[] text, int index, |
Deepanshu Gupta | c398f18 | 2013-05-23 15:20:04 -0700 | [diff] [blame] | 600 | int count, int bidiFlags) { |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 601 | // get the delegate |
Derek Sollenberger | 82934b5 | 2014-10-15 13:50:33 -0400 | [diff] [blame] | 602 | Paint_Delegate delegate = sManager.getDelegate(thisPaint.getNativeInstance()); |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 603 | if (delegate == null) { |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 604 | return 0; |
| 605 | } |
| 606 | |
Deepanshu Gupta | 237740b | 2014-06-25 17:47:16 -0700 | [diff] [blame] | 607 | RectF bounds = delegate.measureText(text, index, count, null, 0, bidiFlags); |
Deepanshu Gupta | eb998d3 | 2014-01-07 11:58:44 -0800 | [diff] [blame] | 608 | return bounds.right - bounds.left; |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 609 | } |
| 610 | |
Xavier Ducrohet | 94c80bf | 2011-02-09 17:17:49 -0800 | [diff] [blame] | 611 | @LayoutlibDelegate |
Deepanshu Gupta | c398f18 | 2013-05-23 15:20:04 -0700 | [diff] [blame] | 612 | /*package*/ static float native_measureText(Paint thisPaint, String text, int start, int end, |
| 613 | int bidiFlags) { |
| 614 | return native_measureText(thisPaint, text.toCharArray(), start, end - start, bidiFlags); |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 615 | } |
| 616 | |
Xavier Ducrohet | 94c80bf | 2011-02-09 17:17:49 -0800 | [diff] [blame] | 617 | @LayoutlibDelegate |
Deepanshu Gupta | c398f18 | 2013-05-23 15:20:04 -0700 | [diff] [blame] | 618 | /*package*/ static float native_measureText(Paint thisPaint, String text, int bidiFlags) { |
| 619 | return native_measureText(thisPaint, text.toCharArray(), 0, text.length(), bidiFlags); |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 620 | } |
| 621 | |
Xavier Ducrohet | 94c80bf | 2011-02-09 17:17:49 -0800 | [diff] [blame] | 622 | @LayoutlibDelegate |
Deepanshu Gupta | 237740b | 2014-06-25 17:47:16 -0700 | [diff] [blame] | 623 | /*package*/ static int native_breakText(long nativePaint, long nativeTypeface, char[] text, |
| 624 | int index, int count, float maxWidth, int bidiFlags, float[] measuredWidth) { |
Xavier Ducrohet | f4d52a6 | 2011-02-23 09:53:56 -0800 | [diff] [blame] | 625 | |
| 626 | // get the delegate |
Deepanshu Gupta | 237740b | 2014-06-25 17:47:16 -0700 | [diff] [blame] | 627 | Paint_Delegate delegate = sManager.getDelegate(nativePaint); |
Xavier Ducrohet | f4d52a6 | 2011-02-23 09:53:56 -0800 | [diff] [blame] | 628 | if (delegate == null) { |
| 629 | return 0; |
| 630 | } |
| 631 | |
| 632 | int inc = count > 0 ? 1 : -1; |
| 633 | |
| 634 | int measureIndex = 0; |
Xavier Ducrohet | f4d52a6 | 2011-02-23 09:53:56 -0800 | [diff] [blame] | 635 | for (int i = index; i != index + count; i += inc, measureIndex++) { |
| 636 | int start, end; |
| 637 | if (i < index) { |
| 638 | start = i; |
| 639 | end = index; |
| 640 | } else { |
| 641 | start = index; |
| 642 | end = i; |
| 643 | } |
| 644 | |
| 645 | // measure from start to end |
Deepanshu Gupta | 237740b | 2014-06-25 17:47:16 -0700 | [diff] [blame] | 646 | RectF bounds = delegate.measureText(text, start, end - start + 1, null, 0, bidiFlags); |
Deepanshu Gupta | eb998d3 | 2014-01-07 11:58:44 -0800 | [diff] [blame] | 647 | float res = bounds.right - bounds.left; |
Xavier Ducrohet | f4d52a6 | 2011-02-23 09:53:56 -0800 | [diff] [blame] | 648 | |
| 649 | if (measuredWidth != null) { |
| 650 | measuredWidth[measureIndex] = res; |
| 651 | } |
| 652 | |
Xavier Ducrohet | f4d52a6 | 2011-02-23 09:53:56 -0800 | [diff] [blame] | 653 | if (res > maxWidth) { |
| 654 | // we should not return this char index, but since it's 0-based |
| 655 | // and we need to return a count, we simply return measureIndex; |
| 656 | return measureIndex; |
| 657 | } |
| 658 | |
| 659 | } |
| 660 | |
| 661 | return measureIndex; |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 662 | } |
| 663 | |
Xavier Ducrohet | 94c80bf | 2011-02-09 17:17:49 -0800 | [diff] [blame] | 664 | @LayoutlibDelegate |
Deepanshu Gupta | 237740b | 2014-06-25 17:47:16 -0700 | [diff] [blame] | 665 | /*package*/ static int native_breakText(long nativePaint, long nativeTypeface, String text, |
| 666 | boolean measureForwards, |
Deepanshu Gupta | c398f18 | 2013-05-23 15:20:04 -0700 | [diff] [blame] | 667 | float maxWidth, int bidiFlags, float[] measuredWidth) { |
Deepanshu Gupta | 237740b | 2014-06-25 17:47:16 -0700 | [diff] [blame] | 668 | return native_breakText(nativePaint, nativeTypeface, text.toCharArray(), 0, text.length(), |
| 669 | maxWidth, bidiFlags, measuredWidth); |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 670 | } |
| 671 | |
Xavier Ducrohet | 94c80bf | 2011-02-09 17:17:49 -0800 | [diff] [blame] | 672 | @LayoutlibDelegate |
Narayan Kamath | 633d688 | 2014-01-27 14:24:16 +0000 | [diff] [blame] | 673 | /*package*/ static long native_init() { |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 674 | Paint_Delegate newDelegate = new Paint_Delegate(); |
Xavier Ducrohet | 9167279 | 2011-02-22 11:54:37 -0800 | [diff] [blame] | 675 | return sManager.addNewDelegate(newDelegate); |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 676 | } |
| 677 | |
Xavier Ducrohet | 94c80bf | 2011-02-09 17:17:49 -0800 | [diff] [blame] | 678 | @LayoutlibDelegate |
Narayan Kamath | 633d688 | 2014-01-27 14:24:16 +0000 | [diff] [blame] | 679 | /*package*/ static long native_initWithPaint(long paint) { |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 680 | // get the delegate from the native int. |
| 681 | Paint_Delegate delegate = sManager.getDelegate(paint); |
| 682 | if (delegate == null) { |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 683 | return 0; |
| 684 | } |
| 685 | |
| 686 | Paint_Delegate newDelegate = new Paint_Delegate(delegate); |
Xavier Ducrohet | 9167279 | 2011-02-22 11:54:37 -0800 | [diff] [blame] | 687 | return sManager.addNewDelegate(newDelegate); |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 688 | } |
| 689 | |
Xavier Ducrohet | 94c80bf | 2011-02-09 17:17:49 -0800 | [diff] [blame] | 690 | @LayoutlibDelegate |
Narayan Kamath | 633d688 | 2014-01-27 14:24:16 +0000 | [diff] [blame] | 691 | /*package*/ static void native_reset(long native_object) { |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 692 | // get the delegate from the native int. |
| 693 | Paint_Delegate delegate = sManager.getDelegate(native_object); |
| 694 | if (delegate == null) { |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 695 | return; |
| 696 | } |
| 697 | |
| 698 | delegate.reset(); |
| 699 | } |
| 700 | |
Xavier Ducrohet | 94c80bf | 2011-02-09 17:17:49 -0800 | [diff] [blame] | 701 | @LayoutlibDelegate |
Narayan Kamath | 633d688 | 2014-01-27 14:24:16 +0000 | [diff] [blame] | 702 | /*package*/ static void native_set(long native_dst, long native_src) { |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 703 | // get the delegate from the native int. |
| 704 | Paint_Delegate delegate_dst = sManager.getDelegate(native_dst); |
| 705 | if (delegate_dst == null) { |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 706 | return; |
| 707 | } |
| 708 | |
| 709 | // get the delegate from the native int. |
| 710 | Paint_Delegate delegate_src = sManager.getDelegate(native_src); |
| 711 | if (delegate_src == null) { |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 712 | return; |
| 713 | } |
| 714 | |
| 715 | delegate_dst.set(delegate_src); |
| 716 | } |
| 717 | |
Xavier Ducrohet | 94c80bf | 2011-02-09 17:17:49 -0800 | [diff] [blame] | 718 | @LayoutlibDelegate |
Deepanshu Gupta | f9a8235 | 2014-02-21 16:22:10 -0800 | [diff] [blame] | 719 | /*package*/ static int native_getStyle(long native_object) { |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 720 | // get the delegate from the native int. |
| 721 | Paint_Delegate delegate = sManager.getDelegate(native_object); |
| 722 | if (delegate == null) { |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 723 | return 0; |
| 724 | } |
| 725 | |
| 726 | return delegate.mStyle; |
| 727 | } |
| 728 | |
Xavier Ducrohet | 94c80bf | 2011-02-09 17:17:49 -0800 | [diff] [blame] | 729 | @LayoutlibDelegate |
Narayan Kamath | 633d688 | 2014-01-27 14:24:16 +0000 | [diff] [blame] | 730 | /*package*/ static void native_setStyle(long native_object, int style) { |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 731 | // get the delegate from the native int. |
| 732 | Paint_Delegate delegate = sManager.getDelegate(native_object); |
| 733 | if (delegate == null) { |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 734 | return; |
| 735 | } |
| 736 | |
| 737 | delegate.mStyle = style; |
| 738 | } |
| 739 | |
Xavier Ducrohet | 94c80bf | 2011-02-09 17:17:49 -0800 | [diff] [blame] | 740 | @LayoutlibDelegate |
Deepanshu Gupta | f9a8235 | 2014-02-21 16:22:10 -0800 | [diff] [blame] | 741 | /*package*/ static int native_getStrokeCap(long native_object) { |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 742 | // get the delegate from the native int. |
| 743 | Paint_Delegate delegate = sManager.getDelegate(native_object); |
| 744 | if (delegate == null) { |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 745 | return 0; |
| 746 | } |
| 747 | |
| 748 | return delegate.mCap; |
| 749 | } |
| 750 | |
Xavier Ducrohet | 94c80bf | 2011-02-09 17:17:49 -0800 | [diff] [blame] | 751 | @LayoutlibDelegate |
Narayan Kamath | 633d688 | 2014-01-27 14:24:16 +0000 | [diff] [blame] | 752 | /*package*/ static void native_setStrokeCap(long native_object, int cap) { |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 753 | // get the delegate from the native int. |
| 754 | Paint_Delegate delegate = sManager.getDelegate(native_object); |
| 755 | if (delegate == null) { |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 756 | return; |
| 757 | } |
| 758 | |
| 759 | delegate.mCap = cap; |
| 760 | } |
| 761 | |
Xavier Ducrohet | 94c80bf | 2011-02-09 17:17:49 -0800 | [diff] [blame] | 762 | @LayoutlibDelegate |
Deepanshu Gupta | f9a8235 | 2014-02-21 16:22:10 -0800 | [diff] [blame] | 763 | /*package*/ static int native_getStrokeJoin(long native_object) { |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 764 | // get the delegate from the native int. |
| 765 | Paint_Delegate delegate = sManager.getDelegate(native_object); |
| 766 | if (delegate == null) { |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 767 | return 0; |
| 768 | } |
| 769 | |
| 770 | return delegate.mJoin; |
| 771 | } |
| 772 | |
Xavier Ducrohet | 94c80bf | 2011-02-09 17:17:49 -0800 | [diff] [blame] | 773 | @LayoutlibDelegate |
Narayan Kamath | 633d688 | 2014-01-27 14:24:16 +0000 | [diff] [blame] | 774 | /*package*/ static void native_setStrokeJoin(long native_object, int join) { |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 775 | // get the delegate from the native int. |
| 776 | Paint_Delegate delegate = sManager.getDelegate(native_object); |
| 777 | if (delegate == null) { |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 778 | return; |
| 779 | } |
| 780 | |
| 781 | delegate.mJoin = join; |
| 782 | } |
| 783 | |
Xavier Ducrohet | 94c80bf | 2011-02-09 17:17:49 -0800 | [diff] [blame] | 784 | @LayoutlibDelegate |
Narayan Kamath | 633d688 | 2014-01-27 14:24:16 +0000 | [diff] [blame] | 785 | /*package*/ static boolean native_getFillPath(long native_object, long src, long dst) { |
Xavier Ducrohet | b976124 | 2010-12-23 10:22:14 -0800 | [diff] [blame] | 786 | Paint_Delegate paint = sManager.getDelegate(native_object); |
| 787 | if (paint == null) { |
| 788 | return false; |
| 789 | } |
| 790 | |
| 791 | Path_Delegate srcPath = Path_Delegate.getDelegate(src); |
| 792 | if (srcPath == null) { |
| 793 | return true; |
| 794 | } |
| 795 | |
| 796 | Path_Delegate dstPath = Path_Delegate.getDelegate(dst); |
| 797 | if (dstPath == null) { |
| 798 | return true; |
| 799 | } |
| 800 | |
| 801 | Stroke stroke = paint.getJavaStroke(); |
| 802 | Shape strokeShape = stroke.createStrokedShape(srcPath.getJavaShape()); |
| 803 | |
| 804 | dstPath.setJavaShape(strokeShape); |
| 805 | |
| 806 | // FIXME figure out the return value? |
| 807 | return true; |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 808 | } |
| 809 | |
Xavier Ducrohet | 94c80bf | 2011-02-09 17:17:49 -0800 | [diff] [blame] | 810 | @LayoutlibDelegate |
Narayan Kamath | 633d688 | 2014-01-27 14:24:16 +0000 | [diff] [blame] | 811 | /*package*/ static long native_setShader(long native_object, long shader) { |
Xavier Ducrohet | a313b65 | 2010-11-01 18:45:20 -0700 | [diff] [blame] | 812 | // get the delegate from the native int. |
| 813 | Paint_Delegate delegate = sManager.getDelegate(native_object); |
| 814 | if (delegate == null) { |
Xavier Ducrohet | a313b65 | 2010-11-01 18:45:20 -0700 | [diff] [blame] | 815 | return shader; |
| 816 | } |
| 817 | |
Xavier Ducrohet | 9167279 | 2011-02-22 11:54:37 -0800 | [diff] [blame] | 818 | delegate.mShader = Shader_Delegate.getDelegate(shader); |
| 819 | |
| 820 | return shader; |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 821 | } |
| 822 | |
Xavier Ducrohet | 94c80bf | 2011-02-09 17:17:49 -0800 | [diff] [blame] | 823 | @LayoutlibDelegate |
Narayan Kamath | 633d688 | 2014-01-27 14:24:16 +0000 | [diff] [blame] | 824 | /*package*/ static long native_setColorFilter(long native_object, long filter) { |
Xavier Ducrohet | a313b65 | 2010-11-01 18:45:20 -0700 | [diff] [blame] | 825 | // get the delegate from the native int. |
| 826 | Paint_Delegate delegate = sManager.getDelegate(native_object); |
| 827 | if (delegate == null) { |
Xavier Ducrohet | a313b65 | 2010-11-01 18:45:20 -0700 | [diff] [blame] | 828 | return filter; |
| 829 | } |
| 830 | |
Deepanshu Gupta | 017c062 | 2014-05-19 16:14:23 -0700 | [diff] [blame] | 831 | delegate.mColorFilter = ColorFilter_Delegate.getDelegate(filter); |
Xavier Ducrohet | a6e51d5 | 2010-12-23 07:16:21 -0800 | [diff] [blame] | 832 | |
Deepanshu Gupta | 1128e78 | 2014-06-21 19:45:30 -0700 | [diff] [blame] | 833 | // Log warning if it's not supported. |
| 834 | if (delegate.mColorFilter != null && !delegate.mColorFilter.isSupported()) { |
Xavier Ducrohet | 3f9b037 | 2011-01-13 10:59:34 -0800 | [diff] [blame] | 835 | Bridge.getLog().fidelityWarning(LayoutLog.TAG_COLORFILTER, |
Xavier Ducrohet | 9167279 | 2011-02-22 11:54:37 -0800 | [diff] [blame] | 836 | delegate.mColorFilter.getSupportMessage(), null, null /*data*/); |
Xavier Ducrohet | a6e51d5 | 2010-12-23 07:16:21 -0800 | [diff] [blame] | 837 | } |
| 838 | |
| 839 | return filter; |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 840 | } |
| 841 | |
Xavier Ducrohet | 94c80bf | 2011-02-09 17:17:49 -0800 | [diff] [blame] | 842 | @LayoutlibDelegate |
Narayan Kamath | 633d688 | 2014-01-27 14:24:16 +0000 | [diff] [blame] | 843 | /*package*/ static long native_setXfermode(long native_object, long xfermode) { |
Xavier Ducrohet | a313b65 | 2010-11-01 18:45:20 -0700 | [diff] [blame] | 844 | // get the delegate from the native int. |
| 845 | Paint_Delegate delegate = sManager.getDelegate(native_object); |
| 846 | if (delegate == null) { |
Xavier Ducrohet | a313b65 | 2010-11-01 18:45:20 -0700 | [diff] [blame] | 847 | return xfermode; |
| 848 | } |
| 849 | |
Xavier Ducrohet | 9167279 | 2011-02-22 11:54:37 -0800 | [diff] [blame] | 850 | delegate.mXfermode = Xfermode_Delegate.getDelegate(xfermode); |
| 851 | |
| 852 | return xfermode; |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 853 | } |
| 854 | |
Xavier Ducrohet | 94c80bf | 2011-02-09 17:17:49 -0800 | [diff] [blame] | 855 | @LayoutlibDelegate |
Narayan Kamath | 633d688 | 2014-01-27 14:24:16 +0000 | [diff] [blame] | 856 | /*package*/ static long native_setPathEffect(long native_object, long effect) { |
Xavier Ducrohet | a313b65 | 2010-11-01 18:45:20 -0700 | [diff] [blame] | 857 | // get the delegate from the native int. |
| 858 | Paint_Delegate delegate = sManager.getDelegate(native_object); |
| 859 | if (delegate == null) { |
Xavier Ducrohet | a313b65 | 2010-11-01 18:45:20 -0700 | [diff] [blame] | 860 | return effect; |
| 861 | } |
| 862 | |
Xavier Ducrohet | 9167279 | 2011-02-22 11:54:37 -0800 | [diff] [blame] | 863 | delegate.mPathEffect = PathEffect_Delegate.getDelegate(effect); |
| 864 | |
| 865 | return effect; |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 866 | } |
| 867 | |
Xavier Ducrohet | 94c80bf | 2011-02-09 17:17:49 -0800 | [diff] [blame] | 868 | @LayoutlibDelegate |
Narayan Kamath | 633d688 | 2014-01-27 14:24:16 +0000 | [diff] [blame] | 869 | /*package*/ static long native_setMaskFilter(long native_object, long maskfilter) { |
Xavier Ducrohet | a313b65 | 2010-11-01 18:45:20 -0700 | [diff] [blame] | 870 | // get the delegate from the native int. |
| 871 | Paint_Delegate delegate = sManager.getDelegate(native_object); |
| 872 | if (delegate == null) { |
Xavier Ducrohet | a313b65 | 2010-11-01 18:45:20 -0700 | [diff] [blame] | 873 | return maskfilter; |
| 874 | } |
| 875 | |
Xavier Ducrohet | 9167279 | 2011-02-22 11:54:37 -0800 | [diff] [blame] | 876 | delegate.mMaskFilter = MaskFilter_Delegate.getDelegate(maskfilter); |
Xavier Ducrohet | a6e51d5 | 2010-12-23 07:16:21 -0800 | [diff] [blame] | 877 | |
| 878 | // since none of those are supported, display a fidelity warning right away |
Deepanshu Gupta | 1128e78 | 2014-06-21 19:45:30 -0700 | [diff] [blame] | 879 | if (delegate.mMaskFilter != null && !delegate.mMaskFilter.isSupported()) { |
Xavier Ducrohet | 3f9b037 | 2011-01-13 10:59:34 -0800 | [diff] [blame] | 880 | Bridge.getLog().fidelityWarning(LayoutLog.TAG_MASKFILTER, |
Xavier Ducrohet | 9167279 | 2011-02-22 11:54:37 -0800 | [diff] [blame] | 881 | delegate.mMaskFilter.getSupportMessage(), null, null /*data*/); |
Xavier Ducrohet | a6e51d5 | 2010-12-23 07:16:21 -0800 | [diff] [blame] | 882 | } |
| 883 | |
| 884 | return maskfilter; |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 885 | } |
| 886 | |
Xavier Ducrohet | 94c80bf | 2011-02-09 17:17:49 -0800 | [diff] [blame] | 887 | @LayoutlibDelegate |
Narayan Kamath | 633d688 | 2014-01-27 14:24:16 +0000 | [diff] [blame] | 888 | /*package*/ static long native_setTypeface(long native_object, long typeface) { |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 889 | // get the delegate from the native int. |
| 890 | Paint_Delegate delegate = sManager.getDelegate(native_object); |
| 891 | if (delegate == null) { |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 892 | return 0; |
| 893 | } |
| 894 | |
Xavier Ducrohet | 9167279 | 2011-02-22 11:54:37 -0800 | [diff] [blame] | 895 | delegate.mTypeface = Typeface_Delegate.getDelegate(typeface); |
Deepanshu Gupta | b1ce7c1 | 2014-06-05 14:18:54 -0700 | [diff] [blame] | 896 | delegate.mNativeTypeface = typeface; |
Xavier Ducrohet | 42e2b28 | 2010-12-06 11:08:37 -0800 | [diff] [blame] | 897 | delegate.updateFontObject(); |
Xavier Ducrohet | 9167279 | 2011-02-22 11:54:37 -0800 | [diff] [blame] | 898 | return typeface; |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 899 | } |
| 900 | |
Xavier Ducrohet | 94c80bf | 2011-02-09 17:17:49 -0800 | [diff] [blame] | 901 | @LayoutlibDelegate |
Narayan Kamath | 633d688 | 2014-01-27 14:24:16 +0000 | [diff] [blame] | 902 | /*package*/ static long native_setRasterizer(long native_object, long rasterizer) { |
Xavier Ducrohet | a6e51d5 | 2010-12-23 07:16:21 -0800 | [diff] [blame] | 903 | // get the delegate from the native int. |
| 904 | Paint_Delegate delegate = sManager.getDelegate(native_object); |
| 905 | if (delegate == null) { |
| 906 | return rasterizer; |
| 907 | } |
| 908 | |
Xavier Ducrohet | 9167279 | 2011-02-22 11:54:37 -0800 | [diff] [blame] | 909 | delegate.mRasterizer = Rasterizer_Delegate.getDelegate(rasterizer); |
Xavier Ducrohet | a6e51d5 | 2010-12-23 07:16:21 -0800 | [diff] [blame] | 910 | |
| 911 | // since none of those are supported, display a fidelity warning right away |
Deepanshu Gupta | 1128e78 | 2014-06-21 19:45:30 -0700 | [diff] [blame] | 912 | if (delegate.mRasterizer != null && !delegate.mRasterizer.isSupported()) { |
Xavier Ducrohet | 3f9b037 | 2011-01-13 10:59:34 -0800 | [diff] [blame] | 913 | Bridge.getLog().fidelityWarning(LayoutLog.TAG_RASTERIZER, |
Xavier Ducrohet | 9167279 | 2011-02-22 11:54:37 -0800 | [diff] [blame] | 914 | delegate.mRasterizer.getSupportMessage(), null, null /*data*/); |
Xavier Ducrohet | a6e51d5 | 2010-12-23 07:16:21 -0800 | [diff] [blame] | 915 | } |
| 916 | |
| 917 | return rasterizer; |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 918 | } |
| 919 | |
Xavier Ducrohet | 94c80bf | 2011-02-09 17:17:49 -0800 | [diff] [blame] | 920 | @LayoutlibDelegate |
Deepanshu Gupta | f9a8235 | 2014-02-21 16:22:10 -0800 | [diff] [blame] | 921 | /*package*/ static int native_getTextAlign(long native_object) { |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 922 | // get the delegate from the native int. |
| 923 | Paint_Delegate delegate = sManager.getDelegate(native_object); |
| 924 | if (delegate == null) { |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 925 | return 0; |
| 926 | } |
| 927 | |
Xavier Ducrohet | 37f2180 | 2010-11-01 16:17:18 -0700 | [diff] [blame] | 928 | return delegate.mTextAlign; |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 929 | } |
| 930 | |
Xavier Ducrohet | 94c80bf | 2011-02-09 17:17:49 -0800 | [diff] [blame] | 931 | @LayoutlibDelegate |
Narayan Kamath | 633d688 | 2014-01-27 14:24:16 +0000 | [diff] [blame] | 932 | /*package*/ static void native_setTextAlign(long native_object, int align) { |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 933 | // get the delegate from the native int. |
| 934 | Paint_Delegate delegate = sManager.getDelegate(native_object); |
| 935 | if (delegate == null) { |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 936 | return; |
| 937 | } |
| 938 | |
Xavier Ducrohet | 37f2180 | 2010-11-01 16:17:18 -0700 | [diff] [blame] | 939 | delegate.mTextAlign = align; |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 940 | } |
| 941 | |
Xavier Ducrohet | 94c80bf | 2011-02-09 17:17:49 -0800 | [diff] [blame] | 942 | @LayoutlibDelegate |
Narayan Kamath | 633d688 | 2014-01-27 14:24:16 +0000 | [diff] [blame] | 943 | /*package*/ static void native_setTextLocale(long native_object, String locale) { |
Xavier Ducrohet | 43526ab | 2012-04-23 17:41:37 -0700 | [diff] [blame] | 944 | // get the delegate from the native int. |
| 945 | Paint_Delegate delegate = sManager.getDelegate(native_object); |
| 946 | if (delegate == null) { |
| 947 | return; |
| 948 | } |
| 949 | |
| 950 | delegate.setTextLocale(locale); |
| 951 | } |
| 952 | |
| 953 | @LayoutlibDelegate |
Deepanshu Gupta | 017c062 | 2014-05-19 16:14:23 -0700 | [diff] [blame] | 954 | /*package*/ static int native_getTextWidths(long native_object, long native_typeface, |
| 955 | char[] text, int index, int count, int bidiFlags, float[] widths) { |
Deepanshu Gupta | 237740b | 2014-06-25 17:47:16 -0700 | [diff] [blame] | 956 | |
| 957 | if (widths != null) { |
| 958 | for (int i = 0; i< count; i++) { |
| 959 | widths[i]=0; |
| 960 | } |
| 961 | } |
| 962 | // get the delegate from the native int. |
| 963 | Paint_Delegate delegate = sManager.getDelegate(native_object); |
| 964 | if (delegate == null) { |
| 965 | return 0; |
| 966 | } |
| 967 | |
| 968 | // native_typeface is passed here since Framework's old implementation did not have the |
| 969 | // typeface object associated with the Paint. Since, we follow the new framework way, |
| 970 | // we store the typeface with the paint and use it directly. |
| 971 | assert (native_typeface == delegate.mNativeTypeface); |
| 972 | |
| 973 | RectF bounds = delegate.measureText(text, index, count, widths, 0, bidiFlags); |
| 974 | return ((int) (bounds.right - bounds.left)); |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 975 | } |
| 976 | |
Xavier Ducrohet | 94c80bf | 2011-02-09 17:17:49 -0800 | [diff] [blame] | 977 | @LayoutlibDelegate |
Deepanshu Gupta | 017c062 | 2014-05-19 16:14:23 -0700 | [diff] [blame] | 978 | /*package*/ static int native_getTextWidths(long native_object, long native_typeface, |
| 979 | String text, int start, int end, int bidiFlags, float[] widths) { |
| 980 | return native_getTextWidths(native_object, native_typeface, text.toCharArray(), start, |
| 981 | end - start, bidiFlags, widths); |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 982 | } |
| 983 | |
Xavier Ducrohet | 94c80bf | 2011-02-09 17:17:49 -0800 | [diff] [blame] | 984 | @LayoutlibDelegate |
Deepanshu Gupta | f9a8235 | 2014-02-21 16:22:10 -0800 | [diff] [blame] | 985 | /* package */static int native_getTextGlyphs(long native_object, String text, int start, |
Xavier Ducrohet | 81efa7f | 2011-06-15 14:43:42 -0700 | [diff] [blame] | 986 | int end, int contextStart, int contextEnd, int flags, char[] glyphs) { |
| 987 | // FIXME |
| 988 | return 0; |
| 989 | } |
| 990 | |
| 991 | @LayoutlibDelegate |
Deepanshu Gupta | b1ce7c1 | 2014-06-05 14:18:54 -0700 | [diff] [blame] | 992 | /*package*/ static float native_getTextRunAdvances(long native_object, long native_typeface, |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 993 | char[] text, int index, int count, int contextIndex, int contextCount, |
Deepanshu Gupta | 237740b | 2014-06-25 17:47:16 -0700 | [diff] [blame] | 994 | boolean isRtl, float[] advances, int advancesIndex) { |
Deepanshu Gupta | a6b207a | 2013-07-12 11:38:05 -0700 | [diff] [blame] | 995 | |
| 996 | if (advances != null) |
| 997 | for (int i = advancesIndex; i< advancesIndex+count; i++) |
| 998 | advances[i]=0; |
Xavier Ducrohet | 37f2180 | 2010-11-01 16:17:18 -0700 | [diff] [blame] | 999 | // get the delegate from the native int. |
| 1000 | Paint_Delegate delegate = sManager.getDelegate(native_object); |
Deepanshu Gupta | 017c062 | 2014-05-19 16:14:23 -0700 | [diff] [blame] | 1001 | if (delegate == null) { |
Xavier Ducrohet | 37f2180 | 2010-11-01 16:17:18 -0700 | [diff] [blame] | 1002 | return 0.f; |
| 1003 | } |
Deepanshu Gupta | b1ce7c1 | 2014-06-05 14:18:54 -0700 | [diff] [blame] | 1004 | |
| 1005 | // native_typeface is passed here since Framework's old implementation did not have the |
| 1006 | // typeface object associated with the Paint. Since, we follow the new framework way, |
| 1007 | // we store the typeface with the paint and use it directly. |
| 1008 | assert (native_typeface == delegate.mNativeTypeface); |
| 1009 | |
Deepanshu Gupta | 237740b | 2014-06-25 17:47:16 -0700 | [diff] [blame] | 1010 | RectF bounds = delegate.measureText(text, index, count, advances, advancesIndex, isRtl); |
Deepanshu Gupta | eb998d3 | 2014-01-07 11:58:44 -0800 | [diff] [blame] | 1011 | return bounds.right - bounds.left; |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 1012 | } |
| 1013 | |
Xavier Ducrohet | 94c80bf | 2011-02-09 17:17:49 -0800 | [diff] [blame] | 1014 | @LayoutlibDelegate |
Deepanshu Gupta | 017c062 | 2014-05-19 16:14:23 -0700 | [diff] [blame] | 1015 | /*package*/ static float native_getTextRunAdvances(long native_object, long native_typeface, |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 1016 | String text, int start, int end, int contextStart, int contextEnd, |
Deepanshu Gupta | 237740b | 2014-06-25 17:47:16 -0700 | [diff] [blame] | 1017 | boolean isRtl, float[] advances, int advancesIndex) { |
Deepanshu Gupta | a6b207a | 2013-07-12 11:38:05 -0700 | [diff] [blame] | 1018 | // FIXME: support contextStart and contextEnd |
Xavier Ducrohet | 37f2180 | 2010-11-01 16:17:18 -0700 | [diff] [blame] | 1019 | int count = end - start; |
| 1020 | char[] buffer = TemporaryBuffer.obtain(count); |
| 1021 | TextUtils.getChars(text, start, end, buffer, 0); |
| 1022 | |
Deepanshu Gupta | 017c062 | 2014-05-19 16:14:23 -0700 | [diff] [blame] | 1023 | return native_getTextRunAdvances(native_object, native_typeface, buffer, 0, count, |
Deepanshu Gupta | 237740b | 2014-06-25 17:47:16 -0700 | [diff] [blame] | 1024 | contextStart, contextEnd - contextStart, isRtl, advances, advancesIndex); |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 1025 | } |
| 1026 | |
Xavier Ducrohet | 94c80bf | 2011-02-09 17:17:49 -0800 | [diff] [blame] | 1027 | @LayoutlibDelegate |
Deepanshu Gupta | f9a8235 | 2014-02-21 16:22:10 -0800 | [diff] [blame] | 1028 | /*package*/ static int native_getTextRunCursor(Paint thisPaint, long native_object, char[] text, |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 1029 | int contextStart, int contextLength, int flags, int offset, int cursorOpt) { |
| 1030 | // FIXME |
Xavier Ducrohet | 1eeaea0 | 2011-02-09 19:39:52 -0800 | [diff] [blame] | 1031 | Bridge.getLog().fidelityWarning(LayoutLog.TAG_UNSUPPORTED, |
| 1032 | "Paint.getTextRunCursor is not supported.", null, null /*data*/); |
| 1033 | return 0; |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 1034 | } |
| 1035 | |
Xavier Ducrohet | 94c80bf | 2011-02-09 17:17:49 -0800 | [diff] [blame] | 1036 | @LayoutlibDelegate |
Deepanshu Gupta | f9a8235 | 2014-02-21 16:22:10 -0800 | [diff] [blame] | 1037 | /*package*/ static int native_getTextRunCursor(Paint thisPaint, long native_object, String text, |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 1038 | int contextStart, int contextEnd, int flags, int offset, int cursorOpt) { |
| 1039 | // FIXME |
Xavier Ducrohet | 1eeaea0 | 2011-02-09 19:39:52 -0800 | [diff] [blame] | 1040 | Bridge.getLog().fidelityWarning(LayoutLog.TAG_UNSUPPORTED, |
| 1041 | "Paint.getTextRunCursor is not supported.", null, null /*data*/); |
| 1042 | return 0; |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 1043 | } |
| 1044 | |
Xavier Ducrohet | 94c80bf | 2011-02-09 17:17:49 -0800 | [diff] [blame] | 1045 | @LayoutlibDelegate |
Deepanshu Gupta | 5a6b3ab | 2014-05-30 17:43:33 -0700 | [diff] [blame] | 1046 | /*package*/ static void native_getTextPath(long native_object, long native_typeface, |
| 1047 | int bidiFlags, char[] text, int index, int count, float x, float y, long path) { |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 1048 | // FIXME |
Xavier Ducrohet | 1eeaea0 | 2011-02-09 19:39:52 -0800 | [diff] [blame] | 1049 | Bridge.getLog().fidelityWarning(LayoutLog.TAG_UNSUPPORTED, |
| 1050 | "Paint.getTextPath is not supported.", null, null /*data*/); |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 1051 | } |
| 1052 | |
Xavier Ducrohet | 94c80bf | 2011-02-09 17:17:49 -0800 | [diff] [blame] | 1053 | @LayoutlibDelegate |
Deepanshu Gupta | 5a6b3ab | 2014-05-30 17:43:33 -0700 | [diff] [blame] | 1054 | /*package*/ static void native_getTextPath(long native_object, long native_typeface, |
| 1055 | int bidiFlags, String text, int start, int end, float x, float y, long path) { |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 1056 | // FIXME |
Xavier Ducrohet | 1eeaea0 | 2011-02-09 19:39:52 -0800 | [diff] [blame] | 1057 | Bridge.getLog().fidelityWarning(LayoutLog.TAG_UNSUPPORTED, |
| 1058 | "Paint.getTextPath is not supported.", null, null /*data*/); |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 1059 | } |
| 1060 | |
Xavier Ducrohet | 94c80bf | 2011-02-09 17:17:49 -0800 | [diff] [blame] | 1061 | @LayoutlibDelegate |
Deepanshu Gupta | 5a6b3ab | 2014-05-30 17:43:33 -0700 | [diff] [blame] | 1062 | /*package*/ static void nativeGetStringBounds(long nativePaint, long native_typeface, |
| 1063 | String text, int start, int end, int bidiFlags, Rect bounds) { |
| 1064 | nativeGetCharArrayBounds(nativePaint, native_typeface, text.toCharArray(), start, |
| 1065 | end - start, bidiFlags, bounds); |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 1066 | } |
| 1067 | |
Xavier Ducrohet | 94c80bf | 2011-02-09 17:17:49 -0800 | [diff] [blame] | 1068 | @LayoutlibDelegate |
Deepanshu Gupta | 5a6b3ab | 2014-05-30 17:43:33 -0700 | [diff] [blame] | 1069 | /*package*/ static void nativeGetCharArrayBounds(long nativePaint, long native_typeface, |
| 1070 | char[] text, int index, int count, int bidiFlags, Rect bounds) { |
Xavier Ducrohet | f4d52a6 | 2011-02-23 09:53:56 -0800 | [diff] [blame] | 1071 | |
| 1072 | // get the delegate from the native int. |
| 1073 | Paint_Delegate delegate = sManager.getDelegate(nativePaint); |
Deepanshu Gupta | 017c062 | 2014-05-19 16:14:23 -0700 | [diff] [blame] | 1074 | if (delegate == null) { |
Xavier Ducrohet | f4d52a6 | 2011-02-23 09:53:56 -0800 | [diff] [blame] | 1075 | return; |
| 1076 | } |
Deepanshu Gupta | b1ce7c1 | 2014-06-05 14:18:54 -0700 | [diff] [blame] | 1077 | |
| 1078 | // assert that the typeface passed is actually the one that we had stored. |
| 1079 | assert (native_typeface == delegate.mNativeTypeface); |
| 1080 | |
Deepanshu Gupta | 237740b | 2014-06-25 17:47:16 -0700 | [diff] [blame] | 1081 | delegate.measureText(text, index, count, null, 0, bidiFlags).roundOut(bounds); |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 1082 | } |
| 1083 | |
Xavier Ducrohet | 94c80bf | 2011-02-09 17:17:49 -0800 | [diff] [blame] | 1084 | @LayoutlibDelegate |
Narayan Kamath | 633d688 | 2014-01-27 14:24:16 +0000 | [diff] [blame] | 1085 | /*package*/ static void finalizer(long nativePaint) { |
Xavier Ducrohet | 9167279 | 2011-02-22 11:54:37 -0800 | [diff] [blame] | 1086 | sManager.removeJavaReferenceFor(nativePaint); |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 1087 | } |
| 1088 | |
Deepanshu Gupta | a74fdf0 | 2014-07-30 20:18:48 -0700 | [diff] [blame] | 1089 | @LayoutlibDelegate |
| 1090 | /*package*/ static float native_getLetterSpacing(long nativePaint) { |
| 1091 | // TODO: throw a fidelity warning. |
| 1092 | return 0; |
| 1093 | } |
| 1094 | |
| 1095 | @LayoutlibDelegate |
| 1096 | /*package*/ static void native_setLetterSpacing(long nativePaint, float letterSpacing) { |
| 1097 | // pass. |
| 1098 | } |
| 1099 | |
| 1100 | @LayoutlibDelegate |
| 1101 | /*package*/ static void native_setFontFeatureSettings(long nativePaint, String settings) { |
| 1102 | // pass. |
| 1103 | } |
| 1104 | |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 1105 | // ---- Private delegate/helper methods ---- |
| 1106 | |
Xavier Ducrohet | cf2030c | 2010-12-21 06:20:28 -0800 | [diff] [blame] | 1107 | /*package*/ Paint_Delegate() { |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 1108 | reset(); |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 1109 | } |
| 1110 | |
| 1111 | private Paint_Delegate(Paint_Delegate paint) { |
| 1112 | set(paint); |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 1113 | } |
| 1114 | |
| 1115 | private void set(Paint_Delegate paint) { |
| 1116 | mFlags = paint.mFlags; |
| 1117 | mColor = paint.mColor; |
| 1118 | mStyle = paint.mStyle; |
| 1119 | mCap = paint.mCap; |
| 1120 | mJoin = paint.mJoin; |
Xavier Ducrohet | 37f2180 | 2010-11-01 16:17:18 -0700 | [diff] [blame] | 1121 | mTextAlign = paint.mTextAlign; |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 1122 | mTypeface = paint.mTypeface; |
Deepanshu Gupta | b1ce7c1 | 2014-06-05 14:18:54 -0700 | [diff] [blame] | 1123 | mNativeTypeface = paint.mNativeTypeface; |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 1124 | mStrokeWidth = paint.mStrokeWidth; |
| 1125 | mStrokeMiter = paint.mStrokeMiter; |
| 1126 | mTextSize = paint.mTextSize; |
| 1127 | mTextScaleX = paint.mTextScaleX; |
| 1128 | mTextSkewX = paint.mTextSkewX; |
Xavier Ducrohet | a313b65 | 2010-11-01 18:45:20 -0700 | [diff] [blame] | 1129 | mXfermode = paint.mXfermode; |
| 1130 | mColorFilter = paint.mColorFilter; |
| 1131 | mShader = paint.mShader; |
| 1132 | mPathEffect = paint.mPathEffect; |
| 1133 | mMaskFilter = paint.mMaskFilter; |
Xavier Ducrohet | a6e51d5 | 2010-12-23 07:16:21 -0800 | [diff] [blame] | 1134 | mRasterizer = paint.mRasterizer; |
Xavier Ducrohet | b6f7f57 | 2011-08-22 13:13:16 -0700 | [diff] [blame] | 1135 | mHintingMode = paint.mHintingMode; |
Xavier Ducrohet | 42e2b28 | 2010-12-06 11:08:37 -0800 | [diff] [blame] | 1136 | updateFontObject(); |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 1137 | } |
| 1138 | |
| 1139 | private void reset() { |
Chris Craik | f2437d3 | 2015-05-13 13:09:50 -0700 | [diff] [blame^] | 1140 | mFlags = Paint.HIDDEN_DEFAULT_PAINT_FLAGS; |
Xavier Ducrohet | cf2030c | 2010-12-21 06:20:28 -0800 | [diff] [blame] | 1141 | mColor = 0xFF000000; |
Xavier Ducrohet | 6622522 | 2010-12-21 01:33:04 -0800 | [diff] [blame] | 1142 | mStyle = Paint.Style.FILL.nativeInt; |
| 1143 | mCap = Paint.Cap.BUTT.nativeInt; |
| 1144 | mJoin = Paint.Join.MITER.nativeInt; |
Xavier Ducrohet | 37f2180 | 2010-11-01 16:17:18 -0700 | [diff] [blame] | 1145 | mTextAlign = 0; |
Xavier Ducrohet | 9167279 | 2011-02-22 11:54:37 -0800 | [diff] [blame] | 1146 | mTypeface = Typeface_Delegate.getDelegate(Typeface.sDefaults[0].native_instance); |
Deepanshu Gupta | b1ce7c1 | 2014-06-05 14:18:54 -0700 | [diff] [blame] | 1147 | mNativeTypeface = 0; |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 1148 | mStrokeWidth = 1.f; |
Xavier Ducrohet | cf2030c | 2010-12-21 06:20:28 -0800 | [diff] [blame] | 1149 | mStrokeMiter = 4.f; |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 1150 | mTextSize = 20.f; |
| 1151 | mTextScaleX = 1.f; |
| 1152 | mTextSkewX = 0.f; |
Xavier Ducrohet | 9167279 | 2011-02-22 11:54:37 -0800 | [diff] [blame] | 1153 | mXfermode = null; |
| 1154 | mColorFilter = null; |
| 1155 | mShader = null; |
| 1156 | mPathEffect = null; |
| 1157 | mMaskFilter = null; |
| 1158 | mRasterizer = null; |
Xavier Ducrohet | 42e2b28 | 2010-12-06 11:08:37 -0800 | [diff] [blame] | 1159 | updateFontObject(); |
Xavier Ducrohet | b6f7f57 | 2011-08-22 13:13:16 -0700 | [diff] [blame] | 1160 | mHintingMode = Paint.HINTING_ON; |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 1161 | } |
| 1162 | |
| 1163 | /** |
| 1164 | * Update the {@link Font} object from the typeface, text size and scaling |
| 1165 | */ |
Xavier Ducrohet | a6e51d5 | 2010-12-23 07:16:21 -0800 | [diff] [blame] | 1166 | @SuppressWarnings("deprecation") |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 1167 | private void updateFontObject() { |
Xavier Ducrohet | 9167279 | 2011-02-22 11:54:37 -0800 | [diff] [blame] | 1168 | if (mTypeface != null) { |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 1169 | // Get the fonts from the TypeFace object. |
Deepanshu Gupta | 5a6b3ab | 2014-05-30 17:43:33 -0700 | [diff] [blame] | 1170 | List<Font> fonts = mTypeface.getFonts(mFontVariant); |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 1171 | |
| 1172 | // create new font objects as well as FontMetrics, based on the current text size |
| 1173 | // and skew info. |
| 1174 | ArrayList<FontInfo> infoList = new ArrayList<FontInfo>(fonts.size()); |
| 1175 | for (Font font : fonts) { |
Deepanshu Gupta | 382256f | 2014-08-09 14:14:32 -0700 | [diff] [blame] | 1176 | if (font == null) { |
| 1177 | // If the font is null, add null to infoList. When rendering the text, if this |
| 1178 | // null is reached, a warning will be logged. |
| 1179 | infoList.add(null); |
| 1180 | continue; |
| 1181 | } |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 1182 | FontInfo info = new FontInfo(); |
| 1183 | info.mFont = font.deriveFont(mTextSize); |
| 1184 | if (mTextScaleX != 1.0 || mTextSkewX != 0) { |
| 1185 | // TODO: support skew |
| 1186 | info.mFont = info.mFont.deriveFont(new AffineTransform( |
Xavier Ducrohet | 8f10910 | 2011-10-04 19:39:18 -0700 | [diff] [blame] | 1187 | mTextScaleX, mTextSkewX, 0, 1, 0, 0)); |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 1188 | } |
Deepanshu Gupta | a6b207a | 2013-07-12 11:38:05 -0700 | [diff] [blame] | 1189 | // The metrics here don't have anti-aliasing set. |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 1190 | info.mMetrics = Toolkit.getDefaultToolkit().getFontMetrics(info.mFont); |
| 1191 | |
| 1192 | infoList.add(info); |
| 1193 | } |
| 1194 | |
| 1195 | mFonts = Collections.unmodifiableList(infoList); |
| 1196 | } |
| 1197 | } |
| 1198 | |
Deepanshu Gupta | 237740b | 2014-06-25 17:47:16 -0700 | [diff] [blame] | 1199 | /*package*/ RectF measureText(char[] text, int index, int count, float[] advances, |
| 1200 | int advancesIndex, int bidiFlags) { |
| 1201 | return new BidiRenderer(null, this, text) |
| 1202 | .renderText(index, index + count, bidiFlags, advances, advancesIndex, false); |
| 1203 | } |
| 1204 | |
| 1205 | /*package*/ RectF measureText(char[] text, int index, int count, float[] advances, |
| 1206 | int advancesIndex, boolean isRtl) { |
| 1207 | return new BidiRenderer(null, this, text) |
| 1208 | .renderText(index, index + count, isRtl, advances, advancesIndex, false); |
Xavier Ducrohet | 37f2180 | 2010-11-01 16:17:18 -0700 | [diff] [blame] | 1209 | } |
| 1210 | |
Xavier Ducrohet | df67eab | 2010-12-13 16:42:01 -0800 | [diff] [blame] | 1211 | private float getFontMetrics(FontMetrics metrics) { |
| 1212 | if (mFonts.size() > 0) { |
| 1213 | java.awt.FontMetrics javaMetrics = mFonts.get(0).mMetrics; |
| 1214 | if (metrics != null) { |
| 1215 | // Android expects negative ascent so we invert the value from Java. |
| 1216 | metrics.top = - javaMetrics.getMaxAscent(); |
| 1217 | metrics.ascent = - javaMetrics.getAscent(); |
| 1218 | metrics.descent = javaMetrics.getDescent(); |
| 1219 | metrics.bottom = javaMetrics.getMaxDescent(); |
| 1220 | metrics.leading = javaMetrics.getLeading(); |
| 1221 | } |
| 1222 | |
| 1223 | return javaMetrics.getHeight(); |
| 1224 | } |
| 1225 | |
| 1226 | return 0; |
| 1227 | } |
| 1228 | |
Xavier Ducrohet | 43526ab | 2012-04-23 17:41:37 -0700 | [diff] [blame] | 1229 | private void setTextLocale(String locale) { |
| 1230 | mLocale = new Locale(locale); |
| 1231 | } |
Xavier Ducrohet | df67eab | 2010-12-13 16:42:01 -0800 | [diff] [blame] | 1232 | |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 1233 | private static void setFlag(Paint thisPaint, int flagMask, boolean flagValue) { |
| 1234 | // get the delegate from the native int. |
Derek Sollenberger | 82934b5 | 2014-10-15 13:50:33 -0400 | [diff] [blame] | 1235 | Paint_Delegate delegate = sManager.getDelegate(thisPaint.getNativeInstance()); |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 1236 | if (delegate == null) { |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 1237 | return; |
| 1238 | } |
| 1239 | |
| 1240 | if (flagValue) { |
| 1241 | delegate.mFlags |= flagMask; |
| 1242 | } else { |
| 1243 | delegate.mFlags &= ~flagMask; |
| 1244 | } |
| 1245 | } |
Xavier Ducrohet | ef44aea | 2010-10-28 11:52:00 -0700 | [diff] [blame] | 1246 | } |