Commit 37a94bdb authored by Nico Mack's avatar Nico Mack

Implemented handling of newlines in label

parent 3c0bf2e4
......@@ -55,8 +55,7 @@ public class TextStroke implements Stroke {
// ---------------------------------------------------------------------------
/**
* Creates a new instance of a TextStroke rendering the specified text and using the specified
* font
* Creates a new instance of a TextStroke rendering the specified text and using the specified font
*
* @param text
* specifies the text this stroke shall render
......@@ -71,16 +70,15 @@ public class TextStroke implements Stroke {
// ---------------------------------------------------------------------------
/**
* Creates a new instance of a TextStroke rendering the specified text and using the specified
* font. Additional parameters allow controlling how the text is renderered
* Creates a new instance of a TextStroke rendering the specified text and using the specified font.
* Additional parameters allow controlling how the text is renderered
*
* @param text
* specifies the text this stroke shall render
* @param font
* specifies the font used to render the specified text
* @param stretchToFit
* controls whether the text is stretched to fit the extend of the path it is rendered
* along.
* controls whether the text is stretched to fit the extend of the path it is rendered along.
* @param centered
* controls whether the text is centered relative to the path it is rendered along.
* @param repeat
......@@ -110,8 +108,8 @@ public class TextStroke implements Stroke {
* Controls whether the text is to be flipped, i.e. rendered upside down.
*
* @param flipIt
* specify <code>true</code> to render text upside down, <code>false</code> if text is to
* be rendered normally
* specify <code>true</code> to render text upside down, <code>false</code> if text is to be
* rendered normally
*/
// ---------------------------------------------------------------------------
......@@ -154,11 +152,8 @@ public class TextStroke implements Stroke {
float lengthOfText = (float) glyphVector.getLogicalBounds().getWidth();
float factor = stretchToFit ? lengthOfPath / lengthOfText : 1.0f;
float advance = (glyphVector.getNumGlyphs() > 0) ? glyphVector.getGlyphMetrics(0).getAdvance() : 0;
float advance;
float offset = centered ? ((lengthOfPath - lengthOfText) / 2) : 0.0f;
// float offset = centered ? (1.2f * (lengthOfPath - lengthOfText)) / 2 : 0.0f;
// float offset = centered ? ((lengthOfPath - lengthOfText)) / 2: 0.0f;
float nextAdvance = 0;
......@@ -186,6 +181,7 @@ public class TextStroke implements Stroke {
thisY = points[1];
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) {
......@@ -197,12 +193,21 @@ public class TextStroke implements Stroke {
Shape glyph = glyphVector.getGlyphOutline(currentChar);
Point2D p = glyphVector.getGlyphPosition(currentChar);
float px = (float) p.getX();
float py = (float) p.getY();
float py = (float) p.getY() - lineHeight;
if (flipped)
py -= (metrics.getAscent() * 0.9f);
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;
continue;
}
advance = nextAdvance;
nextAdvance = currentChar < length - 1 ? glyphVector.getGlyphMetrics(currentChar + 1).getAdvance() * 0.5f : 0;
t.setToTranslation(x, y);
......
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