1 import java.io.*; 2 import java.awt.Color ; 3 import org.faceless.pdf2.*; 4 5 9 public class Fonts 10 { 11 public static void main(String [] args) 12 throws IOException 13 { 14 PDF pdf = new PDF(); 16 17 PDFPage page = pdf.newPage(PDF.PAGESIZE_A4); 20 21 PDFStyle plain = new PDFStyle(); 24 plain.setFont(new StandardFont(StandardFont.HELVETICA), 12); 25 plain.setFillColor(Color.black); 26 27 PDFStyle italic = new PDFStyle(plain); 30 italic.setFont(new StandardFont(StandardFont.HELVETICAOBLIQUE), 12); 31 32 PDFStyle bold = new PDFStyle(plain); 35 bold.setFont(new StandardFont(StandardFont.HELVETICABOLD), 12); 36 37 PDFStyle truetype = new PDFStyle(plain); 41 PDFStyle type1 = new PDFStyle(plain); 42 43 truetype.setFont(new OpenTypeFont(new FileInputStream("resources/fonts/bluehigh.ttf"), 1), 12); 47 48 type1.setFont(new Type1Font(new FileInputStream("resources/fonts/bchr.afm"), new FileInputStream("resources/fonts/bchr.pfb")), 12); 51 52 page.beginText(50, 50, page.getWidth()-100, page.getHeight()-100); 55 56 page.setStyle(plain); 59 page.drawText("This text is in "); 60 page.setStyle(italic); 61 page.drawText("Helvetica Oblique "); 62 page.setStyle(plain); 63 page.drawText("and this text is in "); 64 page.setStyle(bold); 65 page.drawText("Helvetica Bold. "); 66 page.setStyle(plain); 67 page.drawText("You can even mix TrueType fonts, "); 68 page.setStyle(truetype); 69 page.drawText("like \"Blue Highway\" from Larabie fonts, "); 70 page.setStyle(plain); 71 page.drawText("and Type 1 fonts "); 72 page.setStyle(type1); 73 page.drawText("like \"Bitstream Charter\" from Bitstream Corporation "); 74 page.setStyle(plain); 75 page.drawText("on the same line.\n\n"); 76 77 page.setStyle(type1); 78 page.drawText("For an example of kerning, look closely at the spaces between the letters in the following phrase: \"AWAWAWA\". Notice how the top of the 'W' overlaps the Bottom of the 'A'. We also support ligatures, which you can see by carefully examining the letters 'f' and 'i' in the word \"difficult\".\n\n"); 79 80 page.setStyle(plain); 81 page.drawText("Since version 1.1 of the library, we support TrueType subsetting, which results in much smaller files. For instance, this document is 60Kb without subsetting and 47k with subsetting, and the difference is even more noticable with larger fonts.\n\n"); 82 83 page.drawText("We've also added \"Track Kerning\", for "); 89 90 PDFStyle narrow = new PDFStyle(plain); 91 narrow.setTrackKerning(-100); 92 page.setStyle(narrow); 93 page.drawText("cramped text"); 94 95 PDFStyle wide = new PDFStyle(plain); 96 wide.setTrackKerning(200); 97 page.setStyle(wide); 98 page.drawText(" or spaced-out text.\n"); 99 100 page.endText(false); 101 102 103 104 OutputStream fo = new FileOutputStream("Fonts.pdf"); 107 pdf.render(fo); 108 fo.close(); 109 } 110 } 111 | Popular Tags |