skip empty texts, add hebrew font
This commit is contained in:
parent
d07aca4465
commit
97ed576828
10 changed files with 37 additions and 13 deletions
|
@ -1,5 +1,5 @@
|
|||
group = org.xbib.graphics
|
||||
name = graphics
|
||||
version = 4.5.1
|
||||
version = 4.5.2
|
||||
|
||||
org.gradle.warning.mode = ALL
|
||||
|
|
|
@ -157,6 +157,14 @@ public class Document implements Element, Closeable, RenderListener {
|
|||
"NotoSans-BoldItalic.ttf");
|
||||
}
|
||||
|
||||
public void registerNotoSansHebrewFont() throws IOException {
|
||||
registerFont("notosanshebrew",
|
||||
"NotoSansHebrew-Regular.ttf",
|
||||
"NotoSansHebrew-Bold.ttf",
|
||||
"NotoSansHebrew-Regular.ttf",
|
||||
"NotoSansHebrew-Bold.ttf");
|
||||
}
|
||||
|
||||
public void registerNotoSansCJKSCFont() throws IOException {
|
||||
registerFont("notosanscjksc",
|
||||
"NotoSansCJKsc-Regular.ttf",
|
||||
|
|
|
@ -78,6 +78,7 @@ public class DocumentCommand implements Command {
|
|||
case "times" -> document.registerFont("times", BaseFont.TIMES);
|
||||
case "courier" -> document.registerFont("courier", BaseFont.COURIER);
|
||||
case "notosans" -> document.registerNotoSansFont();
|
||||
case "notosanshebrew" -> document.registerNotoSansHebrewFont();
|
||||
case "notosanscjksc" -> document.registerNotoSansCJKSCFont();
|
||||
case "opensans" -> document.registerOpenSansFont();
|
||||
case "sourcesans" -> document.registerSourceSansFont();
|
||||
|
|
|
@ -20,6 +20,9 @@ public class MarkupCommand implements Command {
|
|||
@Override
|
||||
public void execute(Engine engine, State state, Settings settings) {
|
||||
String text = settings.get("text");
|
||||
if (text == null) {
|
||||
text = settings.get("value");
|
||||
}
|
||||
TextElement textElement = new TextElement(true, text);
|
||||
String[] fonts = settings.getAsArray("font");
|
||||
float fontsize = settings.getAsFloat("fontsize", 10.0f);
|
||||
|
|
|
@ -17,9 +17,15 @@ import static org.xbib.graphics.pdfbox.layout.util.PdfUtil.mmToPt;
|
|||
|
||||
public class TextCommand implements Command {
|
||||
|
||||
public TextCommand() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(Engine engine, State state, Settings settings) {
|
||||
String text = settings.get("text");
|
||||
if (text == null) {
|
||||
text = settings.get("value");
|
||||
}
|
||||
TextElement textElement = new TextElement(false, text);
|
||||
String[] fonts = settings.getAsArray("font");
|
||||
float fontsize = settings.getAsFloat("fontsize", 10.0f);
|
||||
|
|
|
@ -68,7 +68,7 @@ public class FontDescriptor {
|
|||
}
|
||||
}
|
||||
}
|
||||
throw new IllegalStateException();
|
||||
throw new IllegalStateException("while searching a font for text = '" + text + "'");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -124,6 +124,9 @@ public class StyledText implements TextFragment {
|
|||
* @throws IOException by pdfbox.
|
||||
*/
|
||||
public float getAscent() throws IOException {
|
||||
if (text == null || text.isEmpty()) {
|
||||
return 0f;
|
||||
}
|
||||
return getFontDescriptor().getSize() * getFontDescriptor().getSelectedFont(text).getFontDescriptor().getAscent() / 1000;
|
||||
}
|
||||
|
||||
|
@ -179,6 +182,9 @@ public class StyledText implements TextFragment {
|
|||
}
|
||||
|
||||
private static float getWidth(FontDescriptor fontDescriptor, String text) {
|
||||
if (text == null || text.isEmpty()) {
|
||||
return 0f;
|
||||
}
|
||||
try {
|
||||
return fontDescriptor.getSize() * fontDescriptor.getSelectedFont(text).getStringWidth(text) / 1000;
|
||||
} catch (Exception e) {
|
||||
|
|
|
@ -203,20 +203,20 @@ public class TextLine implements TextSequence {
|
|||
if (transform != null) {
|
||||
matrix = matrix.multiply(transform.getMatrix());
|
||||
}
|
||||
contentStream.beginText();
|
||||
contentStream.setTextMatrix(matrix);
|
||||
if (!styledText.getFontDescriptor().equals(lastFontDesc)) {
|
||||
lastFontDesc = styledText.getFontDescriptor();
|
||||
contentStream.setFont(lastFontDesc.getSelectedFont(styledText.getText()), lastFontDesc.getSize());
|
||||
}
|
||||
if (!styledText.getColor().equals(lastColor)) {
|
||||
lastColor = styledText.getColor();
|
||||
contentStream.setNonStrokingColor(lastColor);
|
||||
}
|
||||
if (!styledText.getText().isEmpty()) {
|
||||
contentStream.beginText();
|
||||
contentStream.setTextMatrix(matrix);
|
||||
if (!styledText.getFontDescriptor().equals(lastFontDesc)) {
|
||||
lastFontDesc = styledText.getFontDescriptor();
|
||||
contentStream.setFont(lastFontDesc.getSelectedFont(styledText.getText()), lastFontDesc.getSize());
|
||||
}
|
||||
if (!styledText.getColor().equals(lastColor)) {
|
||||
lastColor = styledText.getColor();
|
||||
contentStream.setNonStrokingColor(lastColor);
|
||||
}
|
||||
contentStream.showText(styledText.getText());
|
||||
contentStream.endText();
|
||||
}
|
||||
contentStream.endText();
|
||||
if (drawListener != null) {
|
||||
drawListener.drawn(styledText,
|
||||
new Position(x, y + styledText.getAscent()),
|
||||
|
|
Binary file not shown.
Binary file not shown.
Loading…
Reference in a new issue