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