|
1 | 1 | /* |
2 | | - * Copyright (C) 2018 Muhammad Tayyab Akram |
| 2 | + * Copyright (C) 2018-2019 Muhammad Tayyab Akram |
3 | 3 | * |
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | 5 | * you may not use this file except in compliance with the License. |
|
21 | 21 | import com.mta.tehreer.collections.IntList; |
22 | 22 |
|
23 | 23 | public final class Clusters { |
24 | | - public static void loadCharExtents(@NonNull int[] clusterMap, |
25 | | - boolean isBackward, boolean visuallyRTL, |
26 | | - @NonNull int[] glyphIds, @NonNull float[] glyphAdvances, |
27 | | - @NonNull float[] charExtents) { |
28 | | - if (!isBackward) { |
29 | | - loadForwardExtents(clusterMap, visuallyRTL, glyphIds, glyphAdvances, charExtents); |
30 | | - } else { |
31 | | - loadBackwardExtents(clusterMap, visuallyRTL, glyphIds, glyphAdvances, charExtents); |
32 | | - } |
33 | | - } |
34 | | - |
35 | | - private static void loadForwardExtents(@NonNull int[] clusterMap, boolean visuallyRTL, |
36 | | - @NonNull int[] glyphIds, @NonNull float[] glyphAdvances, |
37 | | - @NonNull float[] charExtents) { |
38 | | - int clusterStart = 0; |
39 | | - int runLength = clusterMap.length; |
40 | | - |
41 | | - int glyphStart = clusterMap[0]; |
42 | | - float distance = 0.0f; |
43 | | - |
44 | | - for (int i = 0; i <= runLength; i++) { |
45 | | - int glyphIndex = (i < runLength ? clusterMap[i] : glyphIds.length); |
46 | | - if (glyphIndex == glyphStart) { |
47 | | - continue; |
48 | | - } |
49 | | - |
50 | | - // Find the advance of current cluster. |
51 | | - float clusterAdvance = 0.0f; |
52 | | - for (int j = glyphStart; j < glyphIndex; j++) { |
53 | | - clusterAdvance += glyphAdvances[j]; |
54 | | - } |
55 | | - |
56 | | - // Divide the advance evenly between cluster length. |
57 | | - int clusterLength = i - clusterStart; |
58 | | - float charAdvance = clusterAdvance / clusterLength; |
59 | | - |
60 | | - for (int j = clusterStart; j < i; j++) { |
61 | | - distance += (visuallyRTL ? -charAdvance : charAdvance); |
62 | | - charExtents[j] = distance; |
63 | | - } |
64 | | - |
65 | | - clusterStart = i; |
66 | | - glyphStart = glyphIndex; |
67 | | - } |
68 | | - } |
69 | | - |
70 | | - private static void loadBackwardExtents(@NonNull int[] clusterMap, boolean visuallyRTL, |
71 | | - @NonNull int[] glyphIds, @NonNull float[] glyphAdvances, |
72 | | - @NonNull float[] charExtents) { |
73 | | - int clusterEnd = clusterMap.length; |
74 | | - int glyphStart = clusterMap[clusterEnd - 1]; |
75 | | - float distance = 0.0f; |
76 | | - |
77 | | - for (int i = clusterEnd; i >= 0; i--) { |
78 | | - int glyphIndex = (i > 0 ? clusterMap[i - 1] : glyphIds.length); |
79 | | - if (glyphIndex == glyphStart) { |
80 | | - continue; |
81 | | - } |
82 | | - |
83 | | - // Find the advance of current cluster. |
84 | | - float clusterAdvance = 0.0f; |
85 | | - for (int j = glyphStart; j < glyphIndex; j++) { |
86 | | - clusterAdvance += glyphAdvances[j]; |
87 | | - } |
88 | | - |
89 | | - // Divide the advance evenly between cluster length. |
90 | | - int clusterLength = clusterEnd - i; |
91 | | - float charAdvance = clusterAdvance / clusterLength; |
92 | | - |
93 | | - for (int j = clusterEnd; j > i; j--) { |
94 | | - distance += (visuallyRTL ? charAdvance : -charAdvance); |
95 | | - charExtents[j - 1] = distance; |
96 | | - } |
97 | | - |
98 | | - clusterEnd = i; |
99 | | - glyphStart = glyphIndex; |
100 | | - } |
101 | | - } |
102 | | - |
103 | 24 | public static void loadGlyphRange(@NonNull int[] clusterMap, int startIndex, int endIndex, |
104 | 25 | boolean isBackward, int glyphCount, @NonNull int[] glyphRange) { |
105 | 26 | if (!isBackward) { |
|
0 commit comments