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