trim text in TextLine drawAligned

This commit is contained in:
Jörg Prante 2024-10-18 14:07:34 +02:00
parent a58f1e6c83
commit 0f3f8d488a
2 changed files with 6 additions and 4 deletions

View file

@ -1,3 +1,3 @@
group = org.xbib.graphics group = org.xbib.graphics
name = graphics name = graphics
version = 5.5.1 version = 5.5.2

View file

@ -210,17 +210,19 @@ public class TextLine implements TextSequence {
if (transform != null) { if (transform != null) {
matrix = matrix.multiply(transform.getMatrix()); matrix = matrix.multiply(transform.getMatrix());
} }
if (!styledText.getText().isEmpty()) { // always trim to prevent leading spaces to allow getSelectedFont() to work
String text = styledText.getText().trim();
if (!text.isEmpty()) {
contentStream.beginText(); contentStream.beginText();
beginText = true; beginText = true;
contentStream.setTextMatrix(matrix); contentStream.setTextMatrix(matrix);
lastFontDesc = styledText.getFontDescriptor(); lastFontDesc = styledText.getFontDescriptor();
contentStream.setFont(lastFontDesc.getSelectedFont(styledText.getText()), lastFontDesc.getSize()); contentStream.setFont(lastFontDesc.getSelectedFont(text), lastFontDesc.getSize());
if (!styledText.getColor().equals(lastColor)) { if (!styledText.getColor().equals(lastColor)) {
lastColor = styledText.getColor(); lastColor = styledText.getColor();
contentStream.setNonStrokingColor(lastColor); contentStream.setNonStrokingColor(lastColor);
} }
contentStream.showText(styledText.getText()); contentStream.showText(text);
contentStream.endText(); contentStream.endText();
beginText = false; beginText = false;
} }