use always trimmed text so that getSelectedFont() works
This commit is contained in:
parent
0f3f8d488a
commit
e81e605887
2 changed files with 12 additions and 10 deletions
|
@ -1,3 +1,3 @@
|
||||||
group = org.xbib.graphics
|
group = org.xbib.graphics
|
||||||
name = graphics
|
name = graphics
|
||||||
version = 5.5.2
|
version = 5.5.3
|
||||||
|
|
|
@ -119,15 +119,14 @@ public class StyledText implements TextFragment {
|
||||||
return getFontDescriptor().getSize();
|
return getFontDescriptor().getSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the ascent of the associated font.
|
|
||||||
* @throws IOException by pdfbox.
|
|
||||||
*/
|
|
||||||
public float getAscent() throws IOException {
|
public float getAscent() throws IOException {
|
||||||
if (text == null || text.isEmpty()) {
|
if (text == null) {
|
||||||
return 0f;
|
return 0f;
|
||||||
}
|
}
|
||||||
return getFontDescriptor().getSize() * getFontDescriptor().getSelectedFont(text).getFontDescriptor().getAscent() / 1000;
|
if (text.trim().isEmpty()) {
|
||||||
|
return 0f;
|
||||||
|
}
|
||||||
|
return getFontDescriptor().getSize() * getFontDescriptor().getSelectedFont(text.trim()).getFontDescriptor().getAscent() / 1000;
|
||||||
}
|
}
|
||||||
|
|
||||||
public float getBaselineOffset() {
|
public float getBaselineOffset() {
|
||||||
|
@ -182,13 +181,16 @@ public class StyledText implements TextFragment {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static float getWidth(FontDescriptor fontDescriptor, String text) {
|
private static float getWidth(FontDescriptor fontDescriptor, String text) {
|
||||||
if (text == null || text.isEmpty()) {
|
if (text == null) {
|
||||||
|
return 0f;
|
||||||
|
}
|
||||||
|
if (text.trim().isEmpty()) {
|
||||||
return 0f;
|
return 0f;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
return fontDescriptor.getSize() * fontDescriptor.getSelectedFont(text).getStringWidth(text) / 1000;
|
return fontDescriptor.getSize() * fontDescriptor.getSelectedFont(text.trim()).getStringWidth(text.trim()) / 1000;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.log(Level.WARNING, "text = " + text + " " + e.getMessage(), e);
|
logger.log(Level.WARNING, "text = '" + text.trim() + "' " + e.getMessage(), e);
|
||||||
return 0f;
|
return 0f;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue