@nativescript-community/text 1.4.29 → 1.4.30
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.
package/CHANGELOG.md
CHANGED
@@ -3,6 +3,17 @@
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
5
5
|
|
6
|
+
## [1.4.30](https://github.com/nativescript-community/text/compare/v1.4.29...v1.4.30) (2022-01-11)
|
7
|
+
|
8
|
+
|
9
|
+
### Bug Fixes
|
10
|
+
|
11
|
+
* **android:** span lineHeight fix ([ef0d20c](https://github.com/nativescript-community/text/commit/ef0d20c93d6059401f1b24468f1a4c16cb63c0aa))
|
12
|
+
|
13
|
+
|
14
|
+
|
15
|
+
|
16
|
+
|
6
17
|
## [1.4.29](https://github.com/nativescript-community/text/compare/v1.4.28...v1.4.29) (2022-01-02)
|
7
18
|
|
8
19
|
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@nativescript-community/text",
|
3
|
-
"version": "1.4.
|
3
|
+
"version": "1.4.30",
|
4
4
|
"description": "Expands the capabilities of NativeScript's text property.",
|
5
5
|
"main": "./index",
|
6
6
|
"sideEffects": false,
|
@@ -30,5 +30,5 @@
|
|
30
30
|
},
|
31
31
|
"license": "Apache-2.0",
|
32
32
|
"readmeFilename": "README.md",
|
33
|
-
"gitHead": "
|
33
|
+
"gitHead": "50020c9c198665fe7860d022d775bbb2e4872341"
|
34
34
|
}
|
@@ -0,0 +1,43 @@
|
|
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 DensityLineHeightSpan 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
|
+
final int originHeight = fm.descent - fm.ascent;
|
35
|
+
// If original height is not positive, do nothing.
|
36
|
+
if (originHeight <= 0) {
|
37
|
+
return;
|
38
|
+
}
|
39
|
+
final float ratio = size * 1.0f / originHeight;
|
40
|
+
fm.descent = Math.round(fm.descent * ratio);
|
41
|
+
fm.ascent = fm.descent - size;
|
42
|
+
}
|
43
|
+
}
|
@@ -377,7 +377,9 @@ public class Font {
|
|
377
377
|
}
|
378
378
|
Double lineHeight = span.optDouble("lineHeight");
|
379
379
|
if (!Double.isNaN(lineHeight)) {
|
380
|
-
|
380
|
+
// we use standard for now though it does not take density into account
|
381
|
+
// is this what we want?
|
382
|
+
ssb.setSpan(new android.text.style.LineHeightSpan.Standard(lineHeight.intValue()), start, end,
|
381
383
|
android.text.Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
382
384
|
}
|
383
385
|
|
@@ -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
|
-
}
|