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
|
group = org.xbib.graphics
|
||||||
name = graphics
|
name = graphics
|
||||||
version = 4.5.1
|
version = 4.5.2
|
||||||
|
|
||||||
org.gradle.warning.mode = ALL
|
org.gradle.warning.mode = ALL
|
||||||
|
|
|
@ -157,6 +157,14 @@ public class Document implements Element, Closeable, RenderListener {
|
||||||
"NotoSans-BoldItalic.ttf");
|
"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 {
|
public void registerNotoSansCJKSCFont() throws IOException {
|
||||||
registerFont("notosanscjksc",
|
registerFont("notosanscjksc",
|
||||||
"NotoSansCJKsc-Regular.ttf",
|
"NotoSansCJKsc-Regular.ttf",
|
||||||
|
|
|
@ -78,6 +78,7 @@ public class DocumentCommand implements Command {
|
||||||
case "times" -> document.registerFont("times", BaseFont.TIMES);
|
case "times" -> document.registerFont("times", BaseFont.TIMES);
|
||||||
case "courier" -> document.registerFont("courier", BaseFont.COURIER);
|
case "courier" -> document.registerFont("courier", BaseFont.COURIER);
|
||||||
case "notosans" -> document.registerNotoSansFont();
|
case "notosans" -> document.registerNotoSansFont();
|
||||||
|
case "notosanshebrew" -> document.registerNotoSansHebrewFont();
|
||||||
case "notosanscjksc" -> document.registerNotoSansCJKSCFont();
|
case "notosanscjksc" -> document.registerNotoSansCJKSCFont();
|
||||||
case "opensans" -> document.registerOpenSansFont();
|
case "opensans" -> document.registerOpenSansFont();
|
||||||
case "sourcesans" -> document.registerSourceSansFont();
|
case "sourcesans" -> document.registerSourceSansFont();
|
||||||
|
|
|
@ -20,6 +20,9 @@ public class MarkupCommand implements Command {
|
||||||
@Override
|
@Override
|
||||||
public void execute(Engine engine, State state, Settings settings) {
|
public void execute(Engine engine, State state, Settings settings) {
|
||||||
String text = settings.get("text");
|
String text = settings.get("text");
|
||||||
|
if (text == null) {
|
||||||
|
text = settings.get("value");
|
||||||
|
}
|
||||||
TextElement textElement = new TextElement(true, text);
|
TextElement textElement = new TextElement(true, text);
|
||||||
String[] fonts = settings.getAsArray("font");
|
String[] fonts = settings.getAsArray("font");
|
||||||
float fontsize = settings.getAsFloat("fontsize", 10.0f);
|
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 class TextCommand implements Command {
|
||||||
|
|
||||||
|
public TextCommand() {
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(Engine engine, State state, Settings settings) {
|
public void execute(Engine engine, State state, Settings settings) {
|
||||||
String text = settings.get("text");
|
String text = settings.get("text");
|
||||||
|
if (text == null) {
|
||||||
|
text = settings.get("value");
|
||||||
|
}
|
||||||
TextElement textElement = new TextElement(false, text);
|
TextElement textElement = new TextElement(false, text);
|
||||||
String[] fonts = settings.getAsArray("font");
|
String[] fonts = settings.getAsArray("font");
|
||||||
float fontsize = settings.getAsFloat("fontsize", 10.0f);
|
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
|
@Override
|
||||||
|
|
|
@ -124,6 +124,9 @@ public class StyledText implements TextFragment {
|
||||||
* @throws IOException by pdfbox.
|
* @throws IOException by pdfbox.
|
||||||
*/
|
*/
|
||||||
public float getAscent() throws IOException {
|
public float getAscent() throws IOException {
|
||||||
|
if (text == null || text.isEmpty()) {
|
||||||
|
return 0f;
|
||||||
|
}
|
||||||
return getFontDescriptor().getSize() * getFontDescriptor().getSelectedFont(text).getFontDescriptor().getAscent() / 1000;
|
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) {
|
private static float getWidth(FontDescriptor fontDescriptor, String text) {
|
||||||
|
if (text == null || text.isEmpty()) {
|
||||||
|
return 0f;
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
return fontDescriptor.getSize() * fontDescriptor.getSelectedFont(text).getStringWidth(text) / 1000;
|
return fontDescriptor.getSize() * fontDescriptor.getSelectedFont(text).getStringWidth(text) / 1000;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|
|
@ -203,20 +203,20 @@ public class TextLine implements TextSequence {
|
||||||
if (transform != null) {
|
if (transform != null) {
|
||||||
matrix = matrix.multiply(transform.getMatrix());
|
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()) {
|
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.showText(styledText.getText());
|
||||||
|
contentStream.endText();
|
||||||
}
|
}
|
||||||
contentStream.endText();
|
|
||||||
if (drawListener != null) {
|
if (drawListener != null) {
|
||||||
drawListener.drawn(styledText,
|
drawListener.drawn(styledText,
|
||||||
new Position(x, y + styledText.getAscent()),
|
new Position(x, y + styledText.getAscent()),
|
||||||
|
|
Binary file not shown.
Binary file not shown.
Loading…
Reference in a new issue