Skip to content

Commit

Permalink
#51 Added test for super and sub script - which is just ignored.
Browse files Browse the repository at this point in the history
  • Loading branch information
rototor committed Jun 25, 2023
1 parent cbc3c45 commit 331376a
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 331376a

Please sign in to comment.