mirror of
https://github.com/zoriya/react-native-svg.git
synced 2026-06-07 08:45:00 +00:00
Implement extending the path beyond its end points with a straight line that is parallel to the tangent at the path at its end point.
Fix lengthAdjust=spacing.
This commit is contained in:
@@ -273,7 +273,7 @@ class TSpanShadowNode extends TextShadowNode {
|
|||||||
* */
|
* */
|
||||||
double kerning = font.kerning;
|
double kerning = font.kerning;
|
||||||
double wordSpacing = font.wordSpacing;
|
double wordSpacing = font.wordSpacing;
|
||||||
final double letterSpacing = font.letterSpacing;
|
double letterSpacing = font.letterSpacing;
|
||||||
final boolean autoKerning = !font.manualKerning;
|
final boolean autoKerning = !font.manualKerning;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -327,8 +327,7 @@ class TSpanShadowNode extends TextShadowNode {
|
|||||||
switch (mLengthAdjust) {
|
switch (mLengthAdjust) {
|
||||||
default:
|
default:
|
||||||
case spacing:
|
case spacing:
|
||||||
int numSpaces = getNumSpaces(length, chars);
|
letterSpacing += (author - textMeasure) / (length - 1);
|
||||||
wordSpacing += (author - textMeasure) / numSpaces;
|
|
||||||
break;
|
break;
|
||||||
case spacingAndGlyphs:
|
case spacingAndGlyphs:
|
||||||
scaleSpacingAndGlyphs = author / textMeasure;
|
scaleSpacingAndGlyphs = author / textMeasure;
|
||||||
@@ -544,12 +543,16 @@ class TSpanShadowNode extends TextShadowNode {
|
|||||||
for a chrome/firefox/opera/safari compatible sharp text path rendering,
|
for a chrome/firefox/opera/safari compatible sharp text path rendering,
|
||||||
which doesn't bend text smoothly along a right angle curve, (like Edge does)
|
which doesn't bend text smoothly along a right angle curve, (like Edge does)
|
||||||
but keeps the mid-line orthogonal to the mid-point tangent at all times instead.
|
but keeps the mid-line orthogonal to the mid-point tangent at all times instead.
|
||||||
|
https://github.com/w3c/svgwg/issues/337
|
||||||
*/
|
*/
|
||||||
if (startPoint < 0 || endPoint > distance || sharpMidLine) {
|
final int posAndTanFlags = POSITION_MATRIX_FLAG | TANGENT_MATRIX_FLAG;
|
||||||
|
if (sharpMidLine) {
|
||||||
|
pm.getMatrix((float) midPoint, mid, posAndTanFlags);
|
||||||
|
} else {
|
||||||
/*
|
/*
|
||||||
In the calculation above, if either the startpoint-on-the-path
|
In the calculation above, if either the startpoint-on-the-path
|
||||||
or the endpoint-on-the-path is off the end of the path,
|
or the endpoint-on-the-path is off the end of the path,
|
||||||
TODO then extend the path beyond its end points with a straight line
|
then extend the path beyond its end points with a straight line
|
||||||
that is parallel to the tangent at the path at its end point
|
that is parallel to the tangent at the path at its end point
|
||||||
so that the midpoint-on-the-path can still be calculated.
|
so that the midpoint-on-the-path can still be calculated.
|
||||||
|
|
||||||
@@ -560,13 +563,23 @@ class TSpanShadowNode extends TextShadowNode {
|
|||||||
or
|
or
|
||||||
so that the line through the startpoint-on-the-path and the
|
so that the line through the startpoint-on-the-path and the
|
||||||
endpoint-on-the-path can still be calculated.
|
endpoint-on-the-path can still be calculated.
|
||||||
|
https://github.com/w3c/svgwg/issues/337#issuecomment-318056199
|
||||||
*/
|
*/
|
||||||
final int flags = POSITION_MATRIX_FLAG | TANGENT_MATRIX_FLAG;
|
if (startPoint < 0) {
|
||||||
pm.getMatrix((float) midPoint, mid, flags);
|
pm.getMatrix(0, start, posAndTanFlags);
|
||||||
} else {
|
start.preTranslate((float) startPoint, 0);
|
||||||
pm.getMatrix((float) startPoint, start, POSITION_MATRIX_FLAG);
|
} else {
|
||||||
|
pm.getMatrix((float) startPoint, start, POSITION_MATRIX_FLAG);
|
||||||
|
}
|
||||||
|
|
||||||
pm.getMatrix((float) midPoint, mid, POSITION_MATRIX_FLAG);
|
pm.getMatrix((float) midPoint, mid, POSITION_MATRIX_FLAG);
|
||||||
pm.getMatrix((float) endPoint, end, POSITION_MATRIX_FLAG);
|
|
||||||
|
if (endPoint > distance) {
|
||||||
|
pm.getMatrix((float) distance, end, posAndTanFlags);
|
||||||
|
end.preTranslate((float) (endPoint - distance), 0);
|
||||||
|
} else {
|
||||||
|
pm.getMatrix((float) endPoint, end, POSITION_MATRIX_FLAG);
|
||||||
|
}
|
||||||
|
|
||||||
start.getValues(startPointMatrixData);
|
start.getValues(startPointMatrixData);
|
||||||
end.getValues(endPointMatrixData);
|
end.getValues(endPointMatrixData);
|
||||||
@@ -608,16 +621,6 @@ class TSpanShadowNode extends TextShadowNode {
|
|||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getNumSpaces(int length, char[] chars) {
|
|
||||||
int numSpaces = 0;
|
|
||||||
for (int index = 0; index < length; index++) {
|
|
||||||
if (chars[index] == ' ') {
|
|
||||||
numSpaces++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return numSpaces;
|
|
||||||
}
|
|
||||||
|
|
||||||
private double getAbsoluteStartOffset(String startOffset, double distance, double fontSize) {
|
private double getAbsoluteStartOffset(String startOffset, double distance, double fontSize) {
|
||||||
return PropHelper.fromRelative(startOffset, distance, 0, mScale, fontSize);
|
return PropHelper.fromRelative(startOffset, distance, 0, mScale, fontSize);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user