@nativescript-community/ui-label 1.1.23 → 1.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. package/CHANGELOG.md +35 -0
  2. package/label.android.d.ts +0 -1
  3. package/label.android.js +29 -9
  4. package/label.ios.d.ts +6 -9
  5. package/label.ios.js +91 -223
  6. package/package.json +3 -3
  7. package/platforms/android/include.gradle +1 -1
  8. package/platforms/android/native-api-usage.json +15 -0
  9. package/pnpm-global/5/node_modules/.modules.yaml +0 -22
  10. package/pnpm-global/5/node_modules/.pnpm/@nativescript-community+text@1.4.11/node_modules/@nativescript-community/text/CHANGELOG.md +0 -212
  11. package/pnpm-global/5/node_modules/.pnpm/@nativescript-community+text@1.4.11/node_modules/@nativescript-community/text/LICENSE +0 -201
  12. package/pnpm-global/5/node_modules/.pnpm/@nativescript-community+text@1.4.11/node_modules/@nativescript-community/text/README.md +0 -14
  13. package/pnpm-global/5/node_modules/.pnpm/@nativescript-community+text@1.4.11/node_modules/@nativescript-community/text/index-common.d.ts +0 -40
  14. package/pnpm-global/5/node_modules/.pnpm/@nativescript-community+text@1.4.11/node_modules/@nativescript-community/text/index-common.js +0 -208
  15. package/pnpm-global/5/node_modules/.pnpm/@nativescript-community+text@1.4.11/node_modules/@nativescript-community/text/index.android.d.ts +0 -27
  16. package/pnpm-global/5/node_modules/.pnpm/@nativescript-community+text@1.4.11/node_modules/@nativescript-community/text/index.android.js +0 -298
  17. package/pnpm-global/5/node_modules/.pnpm/@nativescript-community+text@1.4.11/node_modules/@nativescript-community/text/index.d.ts +0 -1
  18. package/pnpm-global/5/node_modules/.pnpm/@nativescript-community+text@1.4.11/node_modules/@nativescript-community/text/index.ios.d.ts +0 -14
  19. package/pnpm-global/5/node_modules/.pnpm/@nativescript-community+text@1.4.11/node_modules/@nativescript-community/text/index.ios.js +0 -189
  20. package/pnpm-global/5/node_modules/.pnpm/@nativescript-community+text@1.4.11/node_modules/@nativescript-community/text/index.js +0 -25
  21. package/pnpm-global/5/node_modules/.pnpm/@nativescript-community+text@1.4.11/node_modules/@nativescript-community/text/package.json +0 -34
  22. package/pnpm-global/5/node_modules/.pnpm/@nativescript-community+text@1.4.11/node_modules/@nativescript-community/text/platforms/android/AndroidManifest.xml +0 -3
  23. package/pnpm-global/5/node_modules/.pnpm/@nativescript-community+text@1.4.11/node_modules/@nativescript-community/text/platforms/android/java/com/nativescript/text/BaselineAdjustedSpan.java +0 -71
  24. package/pnpm-global/5/node_modules/.pnpm/@nativescript-community+text@1.4.11/node_modules/@nativescript-community/text/platforms/android/java/com/nativescript/text/CustomBackgroundSpan.java +0 -70
  25. package/pnpm-global/5/node_modules/.pnpm/@nativescript-community+text@1.4.11/node_modules/@nativescript-community/text/platforms/android/java/com/nativescript/text/CustomTypefaceSpan.java +0 -37
  26. package/pnpm-global/5/node_modules/.pnpm/@nativescript-community+text@1.4.11/node_modules/@nativescript-community/text/platforms/android/java/com/nativescript/text/Font.java +0 -431
  27. package/pnpm-global/5/node_modules/.pnpm/@nativescript-community+text@1.4.11/node_modules/@nativescript-community/text/platforms/android/java/com/nativescript/text/HeightSpan.java +0 -81
  28. package/pnpm-global/5/node_modules/.pnpm/@nativescript-community+text@1.4.11/node_modules/@nativescript-community/text/platforms/android/java/com/nativescript/text/HtmlToSpannedConverter.java +0 -690
  29. package/pnpm-global/5/node_modules/.pnpm/@nativescript-community+text@1.4.11/node_modules/@nativescript-community/text/platforms/android/java/com/nativescript/text/URLSpanNoUnderline.java +0 -24
  30. package/pnpm-global/5/node_modules/.pnpm/@nativescript-community+text@1.4.11/node_modules/@nativescript-community/text/typings/DTCoreText.ios.d.ts +0 -22
  31. package/pnpm-global/5/node_modules/.pnpm/@nativescript-community+text@1.4.11/node_modules/@nativescript-community/text/typings/android.d.ts +0 -32
  32. package/pnpm-global/5/node_modules/.pnpm/lock.yaml +0 -13
  33. package/pnpm-global/5/pnpm-lock.yaml +0 -13
@@ -1,431 +0,0 @@
1
- package com.nativescript.text;
2
-
3
- import android.content.Context;
4
- import android.content.res.AssetManager;
5
- import android.graphics.Typeface;
6
- import android.os.Build;
7
- import android.text.SpannableStringBuilder;
8
- import android.text.style.AbsoluteSizeSpan;
9
- import android.text.style.BackgroundColorSpan;
10
- import android.text.style.ForegroundColorSpan;
11
- import android.text.style.TypefaceSpan;
12
- import android.util.Log;
13
-
14
- import org.xml.sax.InputSource;
15
-
16
- import java.io.File;
17
- import java.io.StringReader;
18
- import java.util.ArrayList;
19
- import java.util.HashMap;
20
- import java.util.StringTokenizer;
21
-
22
- import javax.xml.parsers.SAXParser;
23
- import javax.xml.parsers.SAXParserFactory;
24
-
25
- public class Font {
26
- static AssetManager appAssets;
27
- static HashMap<String, Typeface> typefaceCache = new HashMap<String, Typeface>();
28
- static HashMap<String, Typeface> typefaceCreatedCache = new HashMap<String, Typeface>();
29
-
30
- static final String TAG = "Font";
31
-
32
- public static Typeface loadFontFromFile(Context context, String fontFolder, String fontFamily) {
33
- if (typefaceCache.containsKey(fontFamily)) {
34
- return typefaceCache.get(fontFamily);
35
- }
36
- if (fontFamily.startsWith("res/")) {
37
- int fontID = context.getResources().getIdentifier(fontFamily.substring(4), "font",
38
- context.getPackageName());
39
- Typeface result = androidx.core.content.res.ResourcesCompat.getFont(context, fontID);
40
- if (result != null) {
41
- typefaceCache.put(fontFamily, result);
42
- }
43
- return result;
44
- }
45
-
46
- if (appAssets == null) {
47
- appAssets = context.getAssets();
48
- }
49
- if (appAssets == null) {
50
- return null;
51
- }
52
-
53
- Typeface result = typefaceCache.get(fontFamily);
54
- // Check for undefined explicitly as null mean we tried to load the font, but
55
- // failed.
56
- File file = new File(fontFolder, fontFamily + ".ttf");
57
- // const basePath = fs.path.join(fs.knownFolders.currentApp().path, "fonts",
58
- // fontFamily);
59
-
60
- if (!file.exists()) {
61
- file = new File(fontFolder, fontFamily + ".otf");
62
- if (!file.exists()) {
63
- Log.w(TAG, "Could not find font file for " + fontFamily + " in folder " + fontFolder);
64
- return null;
65
- }
66
-
67
- }
68
-
69
- try {
70
- result = Typeface.createFromFile(file.getAbsolutePath());
71
- } catch (Exception e) {
72
- Log.w(TAG, "\"Error loading font asset: " + file.getAbsolutePath() + "," + e.getLocalizedMessage());
73
- }
74
- typefaceCache.put(fontFamily, result);
75
-
76
- return result;
77
- }
78
-
79
- public interface FontWeight {
80
- String THIN = "thin";
81
- String EXTRA_LIGHT = "extralight";
82
- String LIGHT = "light";
83
- String NORMAL = "normal";
84
- String MEDIUM = "medium";
85
- String SEMI_BOLD = "semibold";
86
- String BOLD = "bold";
87
- String EXTRA_BOLD = "extrabold";
88
- String BLACK = "black";
89
- }
90
-
91
- public interface genericFontFamilies {
92
- String serif = "serif";
93
- String sansSerif = "sans-serif";
94
- String monospace = "monospace";
95
- String system = "system";
96
- }
97
-
98
- public static int getIntFontWeight(String fontWeight) {
99
- if (fontWeight == null) {
100
- return 400;
101
- }
102
- switch (fontWeight) {
103
- case FontWeight.THIN:
104
- return 100;
105
- case FontWeight.EXTRA_LIGHT:
106
- return 200;
107
- case FontWeight.LIGHT:
108
- return 300;
109
- case FontWeight.NORMAL:
110
- return 400;
111
- case FontWeight.MEDIUM:
112
- return 500;
113
- case FontWeight.SEMI_BOLD:
114
- return 600;
115
- case FontWeight.BOLD:
116
- return 700;
117
- case FontWeight.EXTRA_BOLD:
118
- return 800;
119
- case FontWeight.BLACK:
120
- return 900;
121
- default:
122
- return Integer.parseInt(fontWeight, 10);
123
- }
124
- }
125
-
126
- public static String getFontWeightSuffix(int fontWeight) {
127
-
128
- switch (fontWeight) {
129
- case 100:
130
- return Build.VERSION.SDK_INT >= 16 ? "-thin" : "";
131
- case 200:
132
- case 300:
133
- return Build.VERSION.SDK_INT >= 16 ? "-light" : "";
134
- case 400:
135
- return "";
136
- case 500:
137
- case 600:
138
- return Build.VERSION.SDK_INT >= 21 ? "-medium" : "";
139
- case 700:
140
- case 800:
141
- return Build.VERSION.SDK_INT >= 21 ? "-bold" : "";
142
- case 900:
143
- return Build.VERSION.SDK_INT >= 21 ? "-black" : "";
144
- default:
145
- throw new Error("Invalid font weight:" + fontWeight);
146
- }
147
- }
148
-
149
- public static ArrayList<String> parseFontFamily(String value) {
150
- ArrayList<String> result = new ArrayList<String>();
151
- if (value == null) {
152
- return result;
153
- }
154
- if (!value.contains(",")) {
155
- result.add(value.replace("'", "").replace("\"", ""));
156
- return result;
157
- }
158
-
159
- // not removing the "['\"]+" and not trimming make the parseFontFamily much
160
- // faster!
161
- // should be done in span/text properties
162
- StringTokenizer st = new StringTokenizer(value, ",");
163
- while (st.hasMoreTokens()) {
164
- result.add(st.nextToken().replace("'", "").replace("\"", "").trim());
165
- }
166
- return result;
167
- }
168
-
169
- public static Typeface createTypeface(Context context, String fontFolder, String fontFamily, String fontWeight,
170
- boolean isBold, boolean isItalic) {
171
-
172
- int fontStyle = 0;
173
- if (isBold) {
174
- fontStyle |= Typeface.BOLD;
175
- }
176
- if (isItalic) {
177
- fontStyle |= Typeface.ITALIC;
178
- }
179
- int fontWeightInt = getIntFontWeight(fontWeight);
180
- final String cacheKey = fontFamily + fontWeightInt + isItalic;
181
- // Log.d("JS", "Font createTypeface: " + fontFamily + ",fontFolder " +
182
- // fontFolder + ",fontWeight " + fontWeight
183
- // + ",fontWeightInt " + fontWeightInt);
184
- if (typefaceCreatedCache.containsKey(cacheKey)) {
185
- return typefaceCreatedCache.get(cacheKey);
186
- }
187
- // http://stackoverflow.com/questions/19691530/valid-values-for-androidfontfamily-and-what-they-map-to
188
- ArrayList<String> fonts = parseFontFamily(fontFamily);
189
- // Log.d(TAG, "createTypeface1: " + fonts.toString());
190
- Typeface result = null;
191
- for (int i = 0; i < fonts.size(); i++) {
192
- switch (fonts.get(i).toLowerCase()) {
193
- case genericFontFamilies.serif:
194
- result = Typeface.create("serif" + getFontWeightSuffix(fontWeightInt), fontStyle);
195
- break;
196
-
197
- case genericFontFamilies.sansSerif:
198
- case genericFontFamilies.system:
199
- result = Typeface.create("sans-serif" + getFontWeightSuffix(fontWeightInt), fontStyle);
200
- break;
201
-
202
- case genericFontFamilies.monospace:
203
- result = Typeface.create("monospace" + getFontWeightSuffix(fontWeightInt), fontStyle);
204
- break;
205
-
206
- default:
207
- result = loadFontFromFile(context, fontFolder, fonts.get(i));
208
-
209
- if (result != null && (fontStyle != 0 || isItalic || fontWeightInt != 400)) {
210
- if (Build.VERSION.SDK_INT >= 28) {
211
- result = Typeface.create(result, fontWeightInt, isItalic);
212
- } else {
213
- // Log.d("JS", "Font loading font style found: " + fonts.get(i) + ",fontStyle "
214
- // + fontStyle + ",fontWeightInt " + fontWeightInt);
215
- result = Typeface.create(result, fontStyle);
216
- }
217
- }
218
- break;
219
- }
220
-
221
- if (result != null) {
222
- // Found the font!
223
- // Log.d("JS", "Font found: " + fonts.get(i) + ",fontStyle " + fontStyle +
224
- // ",fontWeightInt " + fontWeightInt);
225
- break;
226
- }
227
- }
228
-
229
- if (result == null) {
230
- result = Typeface.create("sans-serif" + getFontWeightSuffix(fontWeightInt), fontStyle);
231
- }
232
- typefaceCreatedCache.put(cacheKey, result);
233
- return result;
234
- }
235
-
236
- public static SpannableStringBuilder stringBuilderFromHtmlString(Context context, String fontFolder,
237
- String htmlString) {
238
- if (htmlString == null) {
239
- return null;
240
- }
241
- // Spanned spannedString = HtmlCompat.fromHtml(htmlString,
242
- // HtmlCompat.FROM_HTML_MODE_COMPACT);
243
-
244
- CharSequence spannedString = fromHtml(htmlString, context, fontFolder, false);
245
- SpannableStringBuilder builder = new SpannableStringBuilder(spannedString);
246
-
247
- // TypefaceSpan[] spans = builder.getSpans(0, builder.length(),
248
- // android.text.style.TypefaceSpan.class);
249
- // for (int index = 0; index < spans.length; index++) {
250
- // TypefaceSpan span = spans[index];
251
- // int start = builder.getSpanStart(span);
252
- // int end = builder.getSpanEnd(span);
253
- // String fontFamily = span.getFamily();
254
- // String[] split = fontFamily.split("-");
255
- // String style = null;
256
- // if (split.length > 1) {
257
- // style = split[1];
258
- // }
259
- // Typeface typeface = createTypeface(context, fontFolder, fontFamily,
260
- // (style != null) && style.equals("bold") ? "bold" : "normal", (style != null)
261
- // && style.equals("bold"), (style != null) && style.equals("italic"));
262
-
263
- // if (typeface == null) {
264
- // typeface = Typeface.create(fontFamily, Typeface.NORMAL);
265
- // }
266
- // if (typeface != null) {
267
- // TypefaceSpan typefaceSpan = new CustomTypefaceSpan(fontFamily, typeface);
268
- // builder.setSpan(typefaceSpan, start, end,
269
- // android.text.Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
270
- // }
271
- // }
272
-
273
- return builder;
274
- }
275
-
276
- static char SpanSeparator = (char) 0x1F;
277
- static char PropertySeparator = (char) 0x1E;
278
-
279
- static ArrayList<ArrayList<String>> parseFormattedString(String formattedString) {
280
- ArrayList<ArrayList<String>> result = new ArrayList<ArrayList<String>>();
281
-
282
- final int len = formattedString.length();
283
- String buffer = "";
284
- ArrayList<String> spanProps = new ArrayList<String>();
285
- for (int i = 0; i < len; i++) {
286
- char c = formattedString.charAt(i);
287
- if (c == PropertySeparator) {
288
- spanProps.add(buffer);
289
- buffer = "";
290
- } else if (c == SpanSeparator) {
291
- spanProps.add(buffer);
292
- result.add(spanProps);
293
- buffer = "";
294
- spanProps = new ArrayList<String>();
295
- } else {
296
- buffer += c;
297
- }
298
- }
299
- spanProps.add(buffer);
300
- result.add(spanProps);
301
-
302
- return result;
303
- }
304
-
305
- public static void setSpanModifiers(Context context, String fontFolder, SpannableStringBuilder ssb,
306
- ArrayList<String> span, int start, int end) {
307
- boolean bold = span.get(2).equals("bold") || span.get(2).equals("700");
308
- boolean italic = span.get(3).equals("1");
309
-
310
- // if (android.os.Build.VERSION.SDK_INT < 28) {
311
- if (bold && italic) {
312
- ssb.setSpan(new android.text.style.StyleSpan(android.graphics.Typeface.BOLD_ITALIC), start, end,
313
- android.text.Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
314
- } else if (bold) {
315
- ssb.setSpan(new android.text.style.StyleSpan(android.graphics.Typeface.BOLD), start, end,
316
- android.text.Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
317
- } else if (italic) {
318
- ssb.setSpan(new android.text.style.StyleSpan(android.graphics.Typeface.ITALIC), start, end,
319
- android.text.Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
320
- }
321
- // }
322
-
323
- String fontFamily = span.get(0);
324
- if (!fontFamily.equals("0")) {
325
- Typeface typeface = createTypeface(context, fontFolder, fontFamily, span.get(2), bold, italic);
326
- TypefaceSpan typefaceSpan = new CustomTypefaceSpan(fontFamily, typeface);
327
- ssb.setSpan(typefaceSpan, start, end, android.text.Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
328
- }
329
- Float fontSize = Float.parseFloat(span.get(1));
330
- Float maxFontSize = Float.parseFloat(span.get(5));
331
- String verticalTextAlignment = span.get(6);
332
- if (verticalTextAlignment.length() > 0 && !verticalTextAlignment.equals("initial")) {
333
- ssb.setSpan(new BaselineAdjustedSpan(fontSize, verticalTextAlignment, maxFontSize), start, end,
334
- android.text.Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
335
- }
336
- if (fontSize != -1) {
337
- ssb.setSpan(new AbsoluteSizeSpan(fontSize.intValue()), start, end,
338
- android.text.Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
339
- }
340
-
341
- Float letterSpacing = Float.parseFloat(span.get(8));
342
- if (letterSpacing != 9) {
343
- ssb.setSpan(new android.text.style.ScaleXSpan((letterSpacing + 1) / 10), start, end,
344
- android.text.Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
345
- }
346
- Float lineHeight = Float.parseFloat(span.get(7));
347
- if (lineHeight != -1) {
348
- ssb.setSpan(new HeightSpan(lineHeight.intValue()), start, end,
349
- android.text.Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
350
- }
351
-
352
- String color = span.get(9);
353
- if (!color.equals("-1")) {
354
- ssb.setSpan(new ForegroundColorSpan(Integer.parseInt(color)), start, end,
355
- android.text.Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
356
- }
357
-
358
- String backgroundColor = span.get(10);
359
- if (!backgroundColor.equals("-1")) {
360
- ssb.setSpan(new BackgroundColorSpan(Integer.parseInt(backgroundColor)), start, end,
361
- android.text.Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
362
- }
363
-
364
- String textDecoration = span.get(4);
365
- if (!textDecoration.equals("0")) {
366
- if (textDecoration.contains("underline")) {
367
- ssb.setSpan(new android.text.style.UnderlineSpan(), start, end,
368
- android.text.Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
369
- }
370
-
371
- if (textDecoration.contains("line-through")) {
372
- ssb.setSpan(new android.text.style.StrikethroughSpan(), start, end,
373
- android.text.Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
374
- }
375
- }
376
- }
377
-
378
- public static SpannableStringBuilder stringBuilderFromFormattedString(Context context, String fontFolder,
379
- String formattedString) {
380
- if (formattedString == null) {
381
- return null;
382
- }
383
- ArrayList<ArrayList<String>> parsedFormattedString = parseFormattedString(formattedString);
384
- SpannableStringBuilder ssb = new SpannableStringBuilder();
385
- for (int i = 0, spanStart = 0, spanLength = 0, length = parsedFormattedString.size(); i < length; i++) {
386
- ArrayList<String> span = parsedFormattedString.get(i);
387
- String text = span.get(11);
388
- spanLength = text.length();
389
- if (spanLength > 0) {
390
- ssb.insert(spanStart, text);
391
- setSpanModifiers(context, fontFolder, ssb, span, spanStart, spanStart + spanLength);
392
- spanStart += spanLength;
393
- }
394
- }
395
-
396
- return ssb;
397
- }
398
-
399
- static SAXParser saxParser = null;
400
- static HtmlToSpannedConverter converter = null;
401
-
402
- public static CharSequence fromHtml(CharSequence html, Context context, String fontFolder,
403
- final boolean disableLinkStyle) {
404
- // long startTime = System.nanoTime();
405
- // XMLReader xmlReader;
406
- try {
407
- if (saxParser == null) {
408
- SAXParserFactory factory = SAXParserFactory.newInstance();
409
- saxParser = factory.newSAXParser();
410
- }
411
- if (converter == null) {
412
- converter = new HtmlToSpannedConverter(context, fontFolder, null, null, disableLinkStyle);
413
- } else {
414
- converter.reset();
415
- converter.disableLinkStyle = disableLinkStyle;
416
- }
417
- // Log.d(TAG, "parse: " +html);
418
- final String toParse = "<doc>" + ((String) html).replaceAll("<br>", "<br></br>") + "</doc>";
419
- saxParser.parse(new InputSource(new StringReader(toParse)), converter);
420
- // Log.d(TAG, "fromHtml: " + ((System.nanoTime() - startTime)/1000000) + "ms");
421
- return converter.spannable();
422
- } catch (Exception e) {
423
- e.printStackTrace();
424
- }
425
- return html;
426
- }
427
-
428
- public static CharSequence fromHtml(Context context, String fontFolder, CharSequence html) {
429
- return fromHtml(html, context, fontFolder, false);
430
- }
431
- }
@@ -1,81 +0,0 @@
1
- package com.nativescript.text;
2
-
3
- import android.annotation.SuppressLint;
4
- import android.graphics.Paint;
5
- import android.graphics.Rect;
6
- import android.text.TextPaint;
7
- import android.text.style.LineHeightSpan;
8
- import java.lang.CharSequence;
9
-
10
- @SuppressLint("ParcelCreator")
11
- public class HeightSpan implements LineHeightSpan.WithDensity {
12
- private int mSize;
13
- private static float sProportion = 0;
14
-
15
- public HeightSpan(int size) {
16
- mSize = size;
17
- }
18
-
19
- public void chooseHeight(CharSequence text, int start, int end,
20
- int spanstartv, int v,
21
- Paint.FontMetricsInt fm) {
22
- // Should not get called, at least not by StaticLayout.
23
- chooseHeight(text, start, end, spanstartv, v, fm, null);
24
- }
25
-
26
- public void chooseHeight(CharSequence text, int start, int end,
27
- int spanstartv, int v,
28
- Paint.FontMetricsInt fm, TextPaint paint) {
29
- int size = mSize;
30
- if (paint != null) {
31
- size *= paint.density;
32
- }
33
-
34
- if (fm.bottom - fm.top < size) {
35
- fm.top = fm.bottom - size;
36
- fm.ascent = fm.ascent - size;
37
- } else {
38
- if (sProportion == 0) {
39
- /*
40
- * Calculate what fraction of the nominal ascent
41
- * the height of a capital letter actually is,
42
- * so that we won't reduce the ascent to less than
43
- * that unless we absolutely have to.
44
- */
45
-
46
- Paint p = new Paint();
47
- p.setTextSize(100);
48
- Rect r = new Rect();
49
- p.getTextBounds("ABCDEFG", 0, 7, r);
50
-
51
- sProportion = (r.top) / p.ascent();
52
- }
53
-
54
- int need = (int) Math.ceil(-fm.top * sProportion);
55
-
56
- if (size - fm.descent >= need) {
57
- /*
58
- * It is safe to shrink the ascent this much.
59
- */
60
-
61
- fm.top = fm.bottom - size;
62
- fm.ascent = fm.descent - size;
63
- } else if (size >= need) {
64
- /*
65
- * We can't show all the descent, but we can at least
66
- * show all the ascent.
67
- */
68
-
69
- fm.top = fm.ascent = -need;
70
- fm.bottom = fm.descent = fm.top + size;
71
- } else {
72
- /*
73
- * Show as much of the ascent as we can, and no descent.
74
- */
75
-
76
- fm.top = fm.ascent = -size;
77
- fm.bottom = fm.descent = 0;
78
- }
79
- }
80
- }
81
- }