use of com.mta.tehreer.collections.IntList in project Tehreer-Android by mta452.
the class ShapingResult method getCaretAdvances.
@NonNull
private float[] getCaretAdvances(@Nullable boolean[] caretStops) {
int codeUnitCount = getCharCount();
float[] caretAdvances = new float[codeUnitCount + 1];
boolean isBackward = isBackward();
FloatList glyphAdvances = getGlyphAdvances();
IntList clusterMap = getClusterMap();
int glyphIndex = clusterMap.get(0) + 1;
int refIndex = glyphIndex;
int totalStops = 0;
int clusterStart = 0;
for (int codeUnitIndex = 1; codeUnitIndex <= codeUnitCount; codeUnitIndex++) {
int oldIndex = glyphIndex;
if (codeUnitIndex != codeUnitCount) {
glyphIndex = clusterMap.get(codeUnitIndex) + 1;
if (caretStops != null && !caretStops[codeUnitIndex - 1]) {
continue;
}
totalStops += 1;
} else {
totalStops += 1;
glyphIndex = (isBackward ? 0 : getGlyphCount() + 1);
}
if (glyphIndex != oldIndex) {
float clusterAdvance = 0;
float distance = 0;
int counter = 1;
/* Find the advance of current cluster. */
if (isBackward) {
while (refIndex > glyphIndex) {
clusterAdvance += glyphAdvances.get(refIndex - 1);
refIndex -= 1;
}
} else {
while (refIndex < glyphIndex) {
clusterAdvance += glyphAdvances.get(refIndex - 1);
refIndex += 1;
}
}
/* Divide the advance evenly between cluster length. */
while (clusterStart < codeUnitIndex) {
float advance = 0;
if (caretStops == null || caretStops[clusterStart] || clusterStart == codeUnitCount - 1) {
float previous = distance;
distance = (clusterAdvance * counter) / totalStops;
advance = distance - previous;
counter += 1;
}
caretAdvances[clusterStart] = advance;
clusterStart += 1;
}
totalStops = 0;
}
}
return caretAdvances;
}
use of com.mta.tehreer.collections.IntList in project Tehreer-Android by mta452.
the class OpenTypeInfoActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_opentype_info);
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
}
Intent intent = getIntent();
String typefaceName = intent.getStringExtra(TYPEFACE_NAME);
int typeSize = intent.getIntExtra(TYPE_SIZE, 0);
int scriptTag = intent.getIntExtra(SCRIPT_TAG, 0);
int languageTag = intent.getIntExtra(LANGUAGE_TAG, 0);
String sourceText = intent.getCharSequenceExtra(SOURCE_TEXT).toString();
WritingDirection writingDirection = ShapingEngine.getScriptDirection(scriptTag);
Typeface typeface = TypefaceManager.getTypefaceByName(typefaceName);
DisplayMetrics displayMetrics = getResources().getDisplayMetrics();
float displaySize = 18.0f * displayMetrics.scaledDensity;
float sizeScale = displaySize / typeSize;
Renderer renderer = new Renderer();
renderer.setTypeface(typeface);
renderer.setTypeSize(typeSize);
renderer.setScaleX(sizeScale);
renderer.setScaleY(sizeScale);
ShapingEngine shapingEngine = ShapingEngine.finalizable(new ShapingEngine());
shapingEngine.setTypeface(typeface);
shapingEngine.setTypeSize(typeSize);
shapingEngine.setScriptTag(scriptTag);
shapingEngine.setLanguageTag(languageTag);
shapingEngine.setWritingDirection(writingDirection);
ShapingResult shapingResult = ShapingResult.finalizable(shapingEngine.shapeText(sourceText, 0, sourceText.length()));
IntList clusterMap = shapingResult.getClusterMap();
int length = clusterMap.size();
int[] initials = new int[length + 1];
int cluster = -1;
int previous = -1;
for (int i = 0; i < length; i++) {
int value = clusterMap.get(i);
if (value != previous) {
initials[++cluster] = i;
}
previous = value;
}
initials[++cluster] = length;
ListView infoListView = findViewById(R.id.list_view_info);
infoListView.setAdapter(new ClusterAdapter(this, renderer, sourceText, shapingResult, IntList.of(initials).subList(0, cluster + 1)));
}
Aggregations