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