Skip to content

Fix middle-anchoring for lines of multiple TSpans #1206

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 35 additions & 4 deletions android/src/main/java/com/horcrux/svg/TSpanView.java
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,36 @@ Path getPath(Canvas canvas, Paint paint) {
return advance;
}

GlyphContext gc = getTextRootGlyphContext();
FontData font = gc.getFont();

ViewParent parent = getParent();

if (parent instanceof TextView) {
TextView textView = (TextView) parent;

for (int i = 0; i < textView.getChildCount(); i++) {
View child = textView.getChildAt(i);
if (child instanceof TSpanView && child != this) {
TSpanView text = (TSpanView) child;
String spanContent = text.mContent;
int spanLength = spanContent.length();

if (spanLength == 0) {
continue;
}

ReadableMap fontMap = text.mFont;
FontData fontData = new FontData(fontMap, font, textView.mScale);
applyTextPropertiesToPaint(paint, fontData);

applySpacingAndFeatures(paint, fontData);

advance += paint.measureText(spanContent);
}
}
}

String line = mContent;
final int length = line.length();

Expand All @@ -221,14 +251,15 @@ Path getPath(Canvas canvas, Paint paint) {
return advance;
}

GlyphContext gc = getTextRootGlyphContext();
FontData font = gc.getFont();
applyTextPropertiesToPaint(paint, font);

applySpacingAndFeatures(paint, font);

cachedAdvance = paint.measureText(line);
return cachedAdvance;
advance += paint.measureText(line);

cachedAdvance = advance;

return advance;
}

final static String requiredFontFeatures = "'rlig', 'liga', 'clig', 'calt', 'locl', 'ccmp', 'mark', 'mkmk',";
Expand Down