[android] Cache text groups. Refactor Svg root group structure.

This commit is contained in:
Mikael Sand
2019-01-06 20:02:14 +02:00
parent 35dca0d98f
commit b559e73dbc
3 changed files with 17 additions and 18 deletions
@@ -44,7 +44,6 @@ class TSpanView extends TextView {
private static final String OTF = ".otf"; private static final String OTF = ".otf";
private static final String TTF = ".ttf"; private static final String TTF = ".ttf";
private Path mCache;
@Nullable String mContent; @Nullable String mContent;
private TextPathView textPath; private TextPathView textPath;
@@ -68,29 +67,24 @@ class TSpanView extends TextView {
} }
} }
@Override
void releaseCachedPath() {
mCache = null;
mPath = null;
}
@Override @Override
Path getPath(Canvas canvas, Paint paint) { Path getPath(Canvas canvas, Paint paint) {
if (mCache != null) { if (mPath != null) {
return mCache; return mPath;
} }
if (mContent == null) { if (mContent == null) {
return getGroupPath(canvas, paint); mPath = getGroupPath(canvas, paint);
return mPath;
} }
setupTextPath(); setupTextPath();
pushGlyphContext(); pushGlyphContext();
mCache = getLinePath(mContent, paint, canvas); mPath = getLinePath(mContent, paint, canvas);
popGlyphContext(); popGlyphContext();
return mCache; return mPath;
} }
@SuppressWarnings("ConstantConditions") @SuppressWarnings("ConstantConditions")
@@ -137,6 +137,9 @@ class TextView extends GroupView {
@Override @Override
Path getPath(Canvas canvas, Paint paint) { Path getPath(Canvas canvas, Paint paint) {
if (mPath != null) {
return mPath;
}
setupGlyphContext(canvas); setupGlyphContext(canvas);
return getGroupPath(canvas, paint); return getGroupPath(canvas, paint);
} }
@@ -186,11 +189,14 @@ class TextView extends GroupView {
} }
Path getGroupPath(Canvas canvas, Paint paint) { Path getGroupPath(Canvas canvas, Paint paint) {
if (mPath != null) {
return mPath;
}
pushGlyphContext(); pushGlyphContext();
Path groupPath = super.getPath(canvas, paint); mPath = super.getPath(canvas, paint);
popGlyphContext(); popGlyphContext();
return groupPath; return mPath;
} }
@Override @Override
+3 -4
View File
@@ -124,8 +124,9 @@ class Svg extends Shape {
]} ]}
> >
<G <G
style={style}
{...{ {...{
children,
style,
font, font,
transform, transform,
fill, fill,
@@ -140,9 +141,7 @@ class Svg extends Shape {
strokeLinejoin, strokeLinejoin,
strokeMiterlimit, strokeMiterlimit,
}} }}
> />
{children}
</G>
</NativeSvgView> </NativeSvgView>
); );
} }