Skip to content

Commit 51535f6

Browse files
committed
Update FontProgram#setBold method.
1 parent d15dc90 commit 51535f6

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

io/src/main/java/com/itextpdf/io/font/FontProgram.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,11 @@ protected void setFixedPitch(boolean isFixedPitch) {
215215
}
216216

217217
protected void setBold(boolean isBold) {
218-
fontNames.setMacStyle(fontNames.getMacStyle() | FontNames.BOLD_FLAG);
218+
if (isBold) {
219+
fontNames.setMacStyle(fontNames.getMacStyle() | FontNames.BOLD_FLAG);
220+
} else {
221+
fontNames.setMacStyle(fontNames.getMacStyle() & (~FontNames.BOLD_FLAG));
222+
}
219223
}
220224

221225
protected void setBbox(int[] bbox) {

io/src/test/java/com/itextpdf/io/font/FontFactoryTest.java renamed to io/src/test/java/com/itextpdf/io/font/FontProgramTest.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import java.io.IOException;
99

1010
@Category(UnitTest.class)
11-
public class FontFactoryTest {
11+
public class FontProgramTest {
1212

1313
@Test
1414
public void exceptionMessageTest() throws IOException {
@@ -18,4 +18,13 @@ public void exceptionMessageTest() throws IOException {
1818
Assert.assertEquals("font.file some-font.ttf not.found", ex.getMessage());
1919
}
2020
}
21+
22+
@Test
23+
public void boldTest() throws IOException {
24+
FontProgram fp = FontFactory.createFont(FontConstants.HELVETICA);
25+
fp.setBold(true);
26+
Assert.assertTrue("Bold expected", (fp.getPdfFontFlags() & (1 << 18)) != 0);
27+
fp.setBold(false);
28+
Assert.assertTrue("Not Bold expected", (fp.getPdfFontFlags() & (1 << 18)) == 0);
29+
}
2130
}

0 commit comments

Comments
 (0)