Skip to content

Commit 5bfb781

Browse files
committed
[lib] Replaced char extents with caret edges
1 parent 698257b commit 5bfb781

File tree

4 files changed

+28
-27
lines changed

4 files changed

+28
-27
lines changed

tehreer-android/src/main/java/com/mta/tehreer/internal/layout/CaretEdgeList.java

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2018 Muhammad Tayyab Akram
2+
* Copyright (C) 2018-2019 Muhammad Tayyab Akram
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -22,30 +22,25 @@
2222
import com.mta.tehreer.internal.Exceptions;
2323

2424
public final class CaretEdgeList extends FloatList {
25-
private final @NonNull float[] extentArray;
25+
private final @NonNull FloatList allEdges;
2626
private final int offset;
2727
private final int edgeCount;
2828
private final float pivotDistance;
2929

30-
public CaretEdgeList(@NonNull float[] charExtents, boolean backward) {
31-
this(charExtents, 0, charExtents.length, 0, 0, backward, false);
30+
public CaretEdgeList(@NonNull FloatList allEdges) {
31+
this(allEdges, 0, allEdges.size(), 0, 0, false);
3232
}
3333

34-
public CaretEdgeList(@NonNull float[] charExtents, int chunkOffset, int chunkLength,
35-
int startExtra, int endExtra, boolean backward, boolean visuallyRTL) {
36-
this.extentArray = charExtents;
37-
this.offset = chunkOffset + (backward ? 0 : -1);
34+
public CaretEdgeList(@NonNull FloatList allEdges, int chunkOffset, int chunkLength,
35+
int startExtra, int endExtra, boolean visuallyRTL) {
36+
this.allEdges = allEdges;
37+
this.offset = chunkOffset;
3838
this.edgeCount = chunkLength + 1;
3939
this.pivotDistance = edgeAt(visuallyRTL ? chunkLength - endExtra : startExtra);
4040
}
4141

4242
private float edgeAt(int index) {
43-
int relativeIndex = index + offset;
44-
if (relativeIndex == -1 || relativeIndex == extentArray.length) {
45-
return 0.0f;
46-
}
47-
48-
return extentArray[relativeIndex];
43+
return allEdges.get(index + offset);
4944
}
5045

5146
public float distance(int fromIndex, int toIndex, boolean visuallyRTL) {

tehreer-android/src/main/java/com/mta/tehreer/internal/layout/IntrinsicRun.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2016-2018 Muhammad Tayyab Akram
2+
* Copyright (C) 2016-2019 Muhammad Tayyab Akram
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -19,6 +19,7 @@
1919
import androidx.annotation.NonNull;
2020
import androidx.annotation.Size;
2121

22+
import com.mta.tehreer.collections.FloatList;
2223
import com.mta.tehreer.graphics.Typeface;
2324
import com.mta.tehreer.internal.util.Clusters;
2425
import com.mta.tehreer.sfnt.WritingDirection;
@@ -38,15 +39,16 @@ public class IntrinsicRun {
3839
public final @NonNull float[] glyphOffsets;
3940
public final @NonNull float[] glyphAdvances;
4041
public final @NonNull int[] clusterMap;
41-
public final @NonNull float[] charExtents;
42+
public final @NonNull FloatList caretEdges;
4243

4344
public IntrinsicRun(int charStart, int charEnd, boolean isBackward, byte bidiLevel,
4445
@NonNull WritingDirection writingDirection,
4546
@NonNull Typeface typeface, float typeSize,
4647
float ascent, float descent, float leading,
4748
@NonNull int[] glyphIds,
4849
@NonNull float[] offsets, @NonNull float[] advances,
49-
@NonNull int[] clusterMap) {
50+
@NonNull int[] clusterMap,
51+
@NonNull FloatList caretEdges) {
5052
this.charStart = charStart;
5153
this.charEnd = charEnd;
5254
this.isBackward = isBackward;
@@ -61,8 +63,7 @@ public IntrinsicRun(int charStart, int charEnd, boolean isBackward, byte bidiLev
6163
this.glyphOffsets = offsets;
6264
this.glyphAdvances = advances;
6365
this.clusterMap = clusterMap;
64-
this.charExtents = new float[clusterMap.length];
65-
Clusters.loadCharExtents(clusterMap, isBackward, isVisuallyRTL(), glyphIds, advances, charExtents);
66+
this.caretEdges = caretEdges;
6667
}
6768

6869
public boolean isVisuallyRTL() {
@@ -87,7 +88,7 @@ public int clusterEnd(int charIndex) {
8788
}
8889

8990
public float measureChars(int fromIndex, int toIndex) {
90-
CaretEdgeList caretEdges = new CaretEdgeList(charExtents, isBackward);
91-
return caretEdges.distance(fromIndex - charStart, toIndex - charStart, isVisuallyRTL());
91+
CaretEdgeList edgeList = new CaretEdgeList(caretEdges);
92+
return edgeList.distance(fromIndex - charStart, toIndex - charStart, isVisuallyRTL());
9293
}
9394
}

tehreer-android/src/main/java/com/mta/tehreer/internal/layout/ShapeResolver.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2018 Muhammad Tayyab Akram
2+
* Copyright (C) 2018-2019 Muhammad Tayyab Akram
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -22,6 +22,7 @@
2222

2323
import androidx.annotation.NonNull;
2424

25+
import com.mta.tehreer.collections.FloatList;
2526
import com.mta.tehreer.graphics.Typeface;
2627
import com.mta.tehreer.sfnt.ShapingEngine;
2728
import com.mta.tehreer.sfnt.ShapingOrder;
@@ -135,6 +136,7 @@ private static void resolveTypefaces(@NonNull String text, @NonNull Spanned span
135136
float[] offsets = shapingResult.getGlyphOffsets().toArray();
136137
float[] advances = shapingResult.getGlyphAdvances().toArray();
137138
int[] clusterMap = shapingResult.getClusterMap().toArray();
139+
FloatList caretEdges = shapingResult.getCaretEdges(null);
138140

139141
float scaleX = locator.getScaleX();
140142
if (Float.compare(scaleX, 1.0f) != 0) {
@@ -154,7 +156,8 @@ private static void resolveTypefaces(@NonNull String text, @NonNull Spanned span
154156
intrinsicRun = new IntrinsicRun(runStart, runEnd, isBackward, bidiLevel,
155157
writingDirection, typeface, typeSize,
156158
ascent, descent, leading,
157-
glyphIds, offsets, advances, clusterMap);
159+
glyphIds, offsets, advances,
160+
clusterMap, caretEdges);
158161
} finally {
159162
if (shapingResult != null) {
160163
shapingResult.dispose();
@@ -177,11 +180,13 @@ private static void resolveTypefaces(@NonNull String text, @NonNull Spanned span
177180
float[] offsets = new float[] { 0.0f, 0.0f };
178181
float[] advances = new float[] { replacementSize };
179182
int[] clusterMap = new int[runEnd - runStart];
183+
FloatList caretEdges = FloatList.of(new float[runEnd - runStart + 1]);
180184

181185
intrinsicRun = new IntrinsicRun(runStart, runEnd, false, bidiLevel,
182186
writingDirection, typeface, typeSize,
183187
-metrics.ascent, metrics.descent, metrics.leading,
184-
glyphIds, offsets, advances, clusterMap);
188+
glyphIds, offsets, advances,
189+
clusterMap, caretEdges);
185190
}
186191

187192
runs.add(intrinsicRun);

tehreer-android/src/main/java/com/mta/tehreer/layout/LineResolver.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2018 Muhammad Tayyab Akram
2+
* Copyright (C) 2018-2019 Muhammad Tayyab Akram
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -76,8 +76,8 @@ static GlyphRun createGlyphRun(@NonNull IntrinsicRun intrinsicRun, int spanStart
7676
new JFloatArrayPointList(intrinsicRun.glyphOffsets, glyphOffset, glyphCount),
7777
new JFloatArrayList(intrinsicRun.glyphAdvances, glyphOffset, glyphCount),
7878
new ClusterMap(intrinsicRun.clusterMap, chunkOffset, chunkLength, glyphOffset),
79-
new CaretEdgeList(intrinsicRun.charExtents, chunkOffset, chunkLength,
80-
startExtra, endExtra, intrinsicRun.isBackward, intrinsicRun.isVisuallyRTL()));
79+
new CaretEdgeList(intrinsicRun.caretEdges, chunkOffset, chunkLength,
80+
startExtra, endExtra, intrinsicRun.isVisuallyRTL()));
8181
}
8282

8383
static @NonNull ComposedLine createComposedLine(@NonNull CharSequence text, int charStart, int charEnd,

0 commit comments

Comments
 (0)