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