Skip to content

Commit

Permalink
Make PDF export of node label box larger than text
Browse files Browse the repository at this point in the history
Previously would not include the descenders.
  • Loading branch information
nathanal committed Sep 2, 2023
1 parent 01268b2 commit c321370
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,7 @@ public void renderPDF(PDFTarget target, Node node, String label, float x, float

try {
float textHeight = PDFUtils.getTextHeight(pdFont, fontSize);
float textMaxHeight = PDFUtils.getMaxTextHeight(pdFont, fontSize);
float textWidth = PDFUtils.getTextWidth(pdFont, fontSize, label);

if (showBox) {
Expand All @@ -379,9 +380,9 @@ public void renderPDF(PDFTarget target, Node node, String label, float x, float
}

contentStream.addRect(x - (textWidth + outlineSize + boxStrokeSize) / 2f,
-y - (textHeight + outlineSize + boxStrokeSize) / 2f,
-y - (textMaxHeight + outlineSize + boxStrokeSize) / 2f,
textWidth + outlineSize + boxStrokeSize,
textHeight + outlineSize + boxStrokeSize);
textMaxHeight + outlineSize + boxStrokeSize);

contentStream.stroke();
if (boxColor.getAlpha() < 255) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ public static float getTextHeight(PDFont pdFont, float fontSize) throws IOExcept
return pdFont.getFontDescriptor().getCapHeight() / 1000 * fontSize;
}

public static float getMaxTextHeight(PDFont pdFont, float fontSize) throws IOException {
return pdFont.getBoundingBox().getHeight() / 1000 * fontSize;
}

public static float getTextWidth(PDFont pdFont, float fontSize, String text) throws IOException {
return pdFont.getStringWidth(text) / 1000 * fontSize;
}
Expand Down

0 comments on commit c321370

Please sign in to comment.