@@ -42,11 +42,13 @@ This file is part of the iText (R) project.
42
42
*/
43
43
package com .itextpdf .layout ;
44
44
45
+ import com .itextpdf .io .font .FontConstants ;
45
46
import com .itextpdf .io .font .PdfEncodings ;
46
47
import com .itextpdf .kernel .colors .ColorConstants ;
47
48
import com .itextpdf .kernel .pdf .PdfDocument ;
48
49
import com .itextpdf .kernel .pdf .PdfWriter ;
49
50
import com .itextpdf .kernel .utils .CompareTool ;
51
+ import com .itextpdf .layout .element .Div ;
50
52
import com .itextpdf .layout .element .Paragraph ;
51
53
import com .itextpdf .layout .element .Text ;
52
54
import com .itextpdf .layout .font .FontInfo ;
@@ -146,6 +148,59 @@ public void latinAndNotdefGroup() throws Exception {
146
148
Assert .assertNull (new CompareTool ().compareByContent (outFileName , cmpFileName , destinationFolder , "diff" ));
147
149
}
148
150
151
+ @ Test
152
+ public void customFontWeight () throws Exception {
153
+ String outFileName = destinationFolder + "customFontWeight.pdf" ;
154
+ String cmpFileName = sourceFolder + "cmp_customFontWeight.pdf" ;
155
+
156
+ FontProvider sel = new FontProvider ();
157
+ sel .getFontSet ().addFont (FontConstants .HELVETICA );
158
+ sel .getFontSet ().addFont (FontConstants .HELVETICA_BOLD );
159
+ sel .getFontSet ().addFont (FontConstants .TIMES_ROMAN );
160
+ sel .getFontSet ().addFont (FontConstants .TIMES_BOLD );
161
+
162
+ PdfDocument pdfDoc = new PdfDocument (new PdfWriter (new FileOutputStream (outFileName )));
163
+ Document doc = new Document (pdfDoc );
164
+ doc .setFontProvider (sel );
165
+
166
+ Div div = new Div ().setFont (FontConstants .TIMES_ROMAN );
167
+ Paragraph paragraph = new Paragraph ("Times Roman Bold text" );
168
+ paragraph .setProperty (Property .FONT_WEIGHT , "bold" );
169
+ div .add (paragraph );
170
+ doc .add (div );
171
+
172
+ doc .close ();
173
+
174
+ Assert .assertNull (new CompareTool ().compareByContent (outFileName , cmpFileName , destinationFolder , "diff" ));
175
+ }
176
+
177
+ @ Test
178
+ public void customFontWeight2 () throws Exception {
179
+ String outFileName = destinationFolder + "customFontWeight2.pdf" ;
180
+ String cmpFileName = sourceFolder + "cmp_customFontWeight2.pdf" ;
181
+
182
+ FontProvider sel = new FontProvider ();
183
+ sel .getFontSet ().addFont (FontConstants .HELVETICA );
184
+ sel .getFontSet ().addFont (FontConstants .HELVETICA_BOLD );
185
+ sel .getFontSet ().addFont (FontConstants .TIMES_ROMAN );
186
+ //sel.getFontSet().addFont(FontConstants.TIMES_BOLD);
187
+
188
+ PdfDocument pdfDoc = new PdfDocument (new PdfWriter (new FileOutputStream (outFileName )));
189
+ Document doc = new Document (pdfDoc );
190
+ doc .setFontProvider (sel );
191
+
192
+ Div div = new Div ().setFont (FontConstants .TIMES_ROMAN );
193
+ Paragraph paragraph = new Paragraph ("Times Roman Bold text" );
194
+ paragraph .setProperty (Property .FONT_WEIGHT , "bold" );
195
+ div .add (paragraph );
196
+ doc .add (div );
197
+
198
+ doc .close ();
199
+
200
+ Assert .assertNull (new CompareTool ().compareByContent (outFileName , cmpFileName , destinationFolder , "diff" ));
201
+ }
202
+
203
+
149
204
@ Test
150
205
public void standardPdfFonts () throws Exception {
151
206
String outFileName = destinationFolder + "standardPdfFonts.pdf" ;
0 commit comments