Dear users, Please note that, from Monday, August 16, 2019, RSA keys shorter than 2048bit will no longer be accepted for security reasons. Please update your keys as needed before this date. If you need assistance with regard to this process, please contact sia@list.lu

Thank you for your understanding.

Commit 013aa9ca authored by Nico Mack's avatar Nico Mack

Fixed inconsistent centering behavior

parent 7be513a7
......@@ -139,13 +139,15 @@ public class TextStroke implements Stroke {
float moveX = 0, moveY = 0;
float lastX = 0, lastY = 0;
float thisX = 0, thisY = 0;
float totX = 0, totY = 0;
float pathLength = 0;
boolean offsetHandled = !centered;
int type = 0;
float next = 0;
int currentChar = 0;
int length = glyphVector.getNumGlyphs();
int numberOfCharacters = glyphVector.getNumGlyphs();
if (length == 0)
if (numberOfCharacters == 0)
return result;
float lengthOfPath = measurePathLength(shape);
......@@ -157,7 +159,7 @@ public class TextStroke implements Stroke {
float nextAdvance = 0;
while (currentChar < length && !it.isDone()) {
while (currentChar < numberOfCharacters && !it.isDone()) {
type = it.currentSegment(points);
switch (type) {
case PathIterator.SEG_MOVETO:
......@@ -182,34 +184,44 @@ public class TextStroke implements Stroke {
float dx = thisX - lastX;
float dy = thisY - lastY;
float lineHeight = 0;
totX += Math.abs(dx);
totY += Math.abs(dy);
if (Math.sqrt(totX * totX + totY * totY) >= offset) {
float distance = (float) Math.sqrt(dx * dx + dy * dy);
if (distance >= next) {
float r = 1.0f / distance;
double angle = Math.atan2(dy, dx);
while (currentChar < length && distance >= next) {
float segmentLength = (float) Math.sqrt(dx * dx + dy * dy);
pathLength += segmentLength;
if (pathLength >= offset || offsetHandled) {
double angle = Math.atan2(dy, dx);
if (!offsetHandled) {
offset = offset - (pathLength - segmentLength);
float ox = offset * (float) Math.cos(angle);
float oy = offset * (float) Math.sin(angle);
dx -= ox;
dy -= oy;
lastX += ox;
lastY += oy;
segmentLength = (float) Math.sqrt(dx * dx + dy * dy);
offsetHandled = true;
}
if (segmentLength >= next) {
float r = 1.0f / segmentLength; // 1 / hypotenuse
while (currentChar < numberOfCharacters && segmentLength >= next) {
Shape glyph = glyphVector.getGlyphOutline(currentChar);
Point2D p = glyphVector.getGlyphPosition(currentChar);
float px = (float) p.getX();
float py = (float) p.getY() - lineHeight;
Point2D pos = glyphVector.getGlyphPosition(currentChar);
float px = (float) pos.getX();
float py = (float) pos.getY() - lineHeight;
if (flipped)
py -= (metrics.getAscent() * 0.9f);
float x = lastX + next * dx * r;
float y = lastY + next * dy * r;
float x = lastX + (next * dx * r);
float y = lastY + (next * dy * r);
int codePoint = text.codePointAt(currentChar);
if (codePoint == '\n') {
lineHeight += metrics.getHeight();
currentChar++;
next = glyphVector.getGlyphMetrics(currentChar).getAdvance() * 0.5f;
nextAdvance = currentChar < length - 1 ? glyphVector.getGlyphMetrics(currentChar + 1).getAdvance() * 0.5f : 0;
nextAdvance = currentChar < numberOfCharacters - 1 ? glyphVector.getGlyphMetrics(currentChar + 1).getAdvance() * 0.5f : 0;
continue;
}
advance = nextAdvance;
nextAdvance = currentChar < length - 1 ? glyphVector.getGlyphMetrics(currentChar + 1).getAdvance() * 0.5f : 0;
nextAdvance = currentChar < numberOfCharacters - 1 ? glyphVector.getGlyphMetrics(currentChar + 1).getAdvance() * 0.5f : 0;
t.setToTranslation(x, y);
t.rotate(angle);
t.translate(-px - advance, -py);
......@@ -217,10 +229,10 @@ public class TextStroke implements Stroke {
next += (advance + nextAdvance) * factor;
currentChar++;
if (repeat)
currentChar %= length;
currentChar %= numberOfCharacters;
}
}
next -= distance;
next -= segmentLength;
}
lastX = thisX;
lastY = thisY;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment