Fix startOfRendering calculation. Fix cursor position calculation. Refactor extractStroke strokeWidth handling.

This commit is contained in:
Mikael Sand
2017-07-29 14:42:06 +03:00
parent 36595c91e2
commit 3825bbd5c8
3 changed files with 16 additions and 12 deletions
@@ -16,8 +16,6 @@ import java.util.ArrayList;
import javax.annotation.Nullable;
import static com.horcrux.svg.FontData.DEFAULT_FONT_SIZE;
// https://www.w3.org/TR/SVG/text.html#TSpanElement
class GlyphContext {
@@ -46,7 +44,7 @@ class GlyphContext {
private final ArrayList<Integer> mRsIndices = new ArrayList<>();
// Calculated on push context, percentage and em length depends on parent font size
private double mFontSize = DEFAULT_FONT_SIZE;
private double mFontSize = FontData.DEFAULT_FONT_SIZE;
private FontData topFont = FontData.Defaults;
// Current accumulated values
@@ -29,7 +29,6 @@ import static android.graphics.Matrix.MTRANS_X;
import static android.graphics.Matrix.MTRANS_Y;
import static android.graphics.PathMeasure.POSITION_MATRIX_FLAG;
import static android.graphics.PathMeasure.TANGENT_MATRIX_FLAG;
import static com.horcrux.svg.TextPathMidLine.sharp;
/**
* Shadow node for virtual TSpan view
@@ -146,7 +145,7 @@ class TSpanShadowNode extends TextShadowNode {
boolean sharpMidLine = false;
final double fontSize = gc.getFontSize();
if (hasTextPath) {
sharpMidLine = textPath.getMidLine() == sharp;
sharpMidLine = textPath.getMidLine() == TextPathMidLine.sharp;
/*
Name
side
@@ -206,9 +205,10 @@ class TSpanShadowNode extends TextShadowNode {
a point on the path equal distance in both directions from the initial position on
the path is reached.
*/
final double absoluteStartOffset = getAbsoluteStartOffset(textPath.getStartOffset(), distance, fontSize);
offset += absoluteStartOffset;
final double halfPathDistance = distance / 2;
offset += getAbsoluteStartOffset(textPath.getStartOffset(), distance, fontSize);
startOfRendering = -offset + (textAnchor == TextAnchor.middle ? -halfPathDistance : 0);
startOfRendering = absoluteStartOffset + (textAnchor == TextAnchor.middle ? -halfPathDistance : 0);
endOfRendering = startOfRendering + distance;
/*
TextPathSpacing spacing = textPath.getSpacing();
@@ -494,9 +494,10 @@ class TSpanShadowNode extends TextShadowNode {
boolean isWordSeparator = currentChar == ' ';
double wordSpace = isWordSeparator ? wordSpacing : 0;
double advance = charWidth + kerning + wordSpace + letterSpacing;
double spacing = wordSpace + letterSpacing;
double advance = charWidth + spacing;
double x = gc.nextX(advance);
double x = gc.nextX(kerning + advance);
double y = gc.nextY();
double dx = gc.nextDeltaX();
double dy = gc.nextDeltaY();
+8 -3
View File
@@ -26,7 +26,7 @@ export default function(props, styleProperties) {
});
const {stroke} = props;
const strokeWidth = props.strokeWidth;
let strokeWidth = props.strokeWidth;
let strokeDasharray = props.strokeDasharray;
if (!strokeDasharray || strokeDasharray === 'none') {
@@ -43,14 +43,19 @@ export default function(props, styleProperties) {
strokeDasharray.concat(strokeDasharray);
}
if (!strokeWidth || typeof strokeWidth !== 'string') {
strokeWidth = `${strokeWidth || 1}`;
}
return {
stroke: extractBrush(stroke),
strokeOpacity: extractOpacity(props.strokeOpacity),
strokeLinecap: caps[props.strokeLinecap] || 0,
strokeLinejoin: joins[props.strokeLinejoin] || 0,
strokeDasharray: strokeDasharray,
strokeWidth: `${strokeWidth || 1}`,
strokeWidth: strokeWidth,
strokeDashoffset: strokeDasharray ? (+props.strokeDashoffset || 0) : null,
strokeMiterlimit: props.strokeMiterlimit || 4
strokeMiterlimit: props.strokeMiterlimit || 4,
};
}