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