mirror of
https://github.com/zoriya/react-native-svg.git
synced 2026-05-13 07:41:37 +00:00
Seemingly pixel-perfect rendering of toap examples from svg spec.
Set paint flags for anti-alias, kerning for text, subpixel positioning of text. Add half of width of glyph to distance calculation for mBezierTransformer.getTransformAtDistance and preTranslate the glyph corresponding amount backwards (gives correct angles on glyphs when rendering text on a path) Add magical constant ratios of 1.2 into getBezierTransformer and getGlyphPointFromContext calls (should probably be based on some dpi ratio calculation)
This commit is contained in:
@@ -16,6 +16,7 @@ import android.graphics.Paint;
|
||||
import android.graphics.Point;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.RectF;
|
||||
import android.graphics.Typeface;
|
||||
import android.util.Base64;
|
||||
|
||||
import com.facebook.react.uimanager.DisplayMetricsHolder;
|
||||
@@ -135,6 +136,10 @@ public class SvgViewShadowNode extends LayoutShadowNode {
|
||||
|
||||
Paint paint = new Paint();
|
||||
|
||||
paint.setFlags(Paint.ANTI_ALIAS_FLAG | Paint.DEV_KERN_TEXT_FLAG | Paint.SUBPIXEL_TEXT_FLAG);
|
||||
|
||||
paint.setTypeface(Typeface.DEFAULT);
|
||||
|
||||
for (int i = 0; i < getChildCount(); i++) {
|
||||
if (!(getChildAt(i) instanceof VirtualNode)) {
|
||||
continue;
|
||||
|
||||
@@ -101,12 +101,12 @@ public class TSpanShadowNode extends TextShadowNode {
|
||||
|
||||
paint.getTextPath(letter, 0, 1, 0, 0, glyph);
|
||||
PointF glyphDelta = getGlyphDeltaFromContext();
|
||||
PointF glyphPoint = getGlyphPointFromContext(glyphPosition, width);
|
||||
PointF glyphPoint = getGlyphPointFromContext(glyphPosition * 1.2f, width);
|
||||
glyphPosition += width;
|
||||
Matrix matrix = new Matrix();
|
||||
|
||||
if (mBezierTransformer != null) {
|
||||
matrix = mBezierTransformer.getTransformAtDistance(glyphPoint.x + glyphDelta.x);
|
||||
matrix = mBezierTransformer.getTransformAtDistance(glyphPoint.x + glyphDelta.x + width / 2);
|
||||
|
||||
if (textPathHasReachedEnd()) {
|
||||
break;
|
||||
@@ -114,7 +114,7 @@ public class TSpanShadowNode extends TextShadowNode {
|
||||
continue;
|
||||
}
|
||||
|
||||
matrix.preTranslate(0, glyphDelta.y);
|
||||
matrix.preTranslate(-width / 2, glyphDelta.y);
|
||||
matrix.postTranslate(0, glyphPoint.y);
|
||||
} else {
|
||||
matrix.setTranslate(glyphPoint.x + glyphDelta.x, glyphPoint.y + glyphDelta.y);
|
||||
|
||||
@@ -52,7 +52,7 @@ public class TextPathShadowNode extends TextShadowNode {
|
||||
}
|
||||
|
||||
PathShadowNode path = (PathShadowNode)template;
|
||||
return new BezierTransformer(path.getBezierCurves(), relativeOnWidth(mStartOffset));
|
||||
return new BezierTransformer(path.getBezierCurves(), relativeOnWidth(mStartOffset) / 1.2f);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user