Skip to content

Commit

Permalink
Merge branch 'master' into fransbouwmans/master
Browse files Browse the repository at this point in the history
  • Loading branch information
rototor committed Jun 25, 2023
2 parents 2581111 + 331376a commit d2973b5
Showing 1 changed file with 45 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,51 @@ public void draw(Graphics2D gfx) throws IOException, FontFormatException
});
}

@Test
public void testStyledAttributeSubAndSup() throws IOException, FontFormatException
{
final Font antonioRegular = Font.createFont(Font.TRUETYPE_FONT,
PdfBoxGraphics2dTest.class.getResourceAsStream("antonio/Antonio-Regular.ttf"))
.deriveFont(15f);
exportGraphic("fonts", "attributed_text", new GraphicsExporter()
{
@Override
public void draw(Graphics2D gfx) throws IOException, FontFormatException
{
gfx.setColor(Color.BLACK);
gfx.setFont(antonioRegular);
AttributedString str = new AttributedString(
"This is some funny text with some attributes.");
str.addAttribute(TextAttribute.SIZE, 20f, 0, 4);

str.addAttribute(TextAttribute.FOREGROUND, Color.RED, 0, 4);

str.addAttribute(TextAttribute.FOREGROUND, Color.green, 13, 23);
str.addAttribute(TextAttribute.SIZE, 18f, 13, 23);
str.addAttribute(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON, 13, 23);
str.addAttribute(TextAttribute.SUPERSCRIPT, TextAttribute.SUPERSCRIPT_SUB, 15, 20);
str.addAttribute(TextAttribute.SUPERSCRIPT, TextAttribute.SUPERSCRIPT_SUPER, 21, 23);

str.addAttribute(TextAttribute.FOREGROUND, Color.MAGENTA, 34, 44);
str.addAttribute(TextAttribute.SIZE, 22f, 34, 44);
str.addAttribute(TextAttribute.STRIKETHROUGH, TextAttribute.STRIKETHROUGH_ON, 34,
44);
str.addAttribute(TextAttribute.SUPERSCRIPT, TextAttribute.SUPERSCRIPT_SUPER, 36, 40);

gfx.drawString(str.getIterator(), 10, 50);

Font font = new Font("SansSerif", Font.PLAIN, 12);
Font font2 = Font.createFont(Font.TRUETYPE_FONT,
PdfBoxGraphics2dTest.class.getResourceAsStream("DejaVuSerifCondensed.ttf"))
.deriveFont(13f);
str.addAttribute(TextAttribute.FONT, font);
gfx.drawString(str.getIterator(), 10, 100);
str.addAttribute(TextAttribute.FONT, font2);
gfx.drawString(str.getIterator(), 10, 150);
}
});
}

@Test
public void testTransformedFont() throws IOException, FontFormatException
{
Expand Down

0 comments on commit d2973b5

Please sign in to comment.