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