List of usage examples for com.lowagie.text Font getFamily
public int getFamily()
From source file:FontGlyphTableRender.java
License:Open Source License
private void run() throws Exception { frame = new JFrame("Flying Saucer: Show Font Glyphs"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel optionsPanel = new JPanel(new BorderLayout()); // TODO: don't know a good way to determine path where fonts are stored, per-os // otherwise we could display a drop-down of installed fonts on the machine // "/usr/share/fonts/truetype/freefont/FreeMono.ttf" fontPathTF = new JTextField(); fontPathTF.setColumns(40);/*from w w w .ja v a 2 s. c om*/ familyNameFieldAwt = new JTextField(); familyNameFieldAwt.setEnabled(true); familyNameFieldAwt.setEditable(false); familyNameFieldAwt.setColumns(20); familyNameFieldIText = new JTextField(); familyNameFieldIText.setEnabled(true); familyNameFieldIText.setEditable(false); familyNameFieldIText.setColumns(20); JPanel top1 = new JPanel(new FlowLayout(FlowLayout.LEFT)); top1.add(new JLabel("Enter font path: ")); top1.add(fontPathTF); JButton chooseFontFileBtn = new JButton("..."); chooseFontFileBtn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { String filename = File.separator + "tmp"; String famPath = fontPathTF.getText(); if (currentFont != null && famPath.length() > 0) { filename = new File(famPath).getParent(); } JFileChooser fc = new JFileChooser(new File(filename)); fc.showOpenDialog(frame); File selFile = fc.getSelectedFile(); Font font = null; String msg = ""; try { font = loadFont(selFile.getPath()); } catch (IOException e1) { // swallow, just allow font to be null msg = e1.getMessage(); } if (font == null) { JOptionPane.showMessageDialog(frame, "Can't load file--is it a valid Font file? " + msg); } else { fontPathTF.setText(selFile.getPath()); familyNameFieldAwt.setText(font.getFamily()); familyNameFieldIText.setText(getITextFontFamilyName(selFile)); } } }); top1.add(chooseFontFileBtn); ActionListener outputSelection = new ActionListener() { public void actionPerformed(ActionEvent e) { outputType = e.getActionCommand(); enableButtons(); if (currentFont != null) { deferredChangePage(curFrom); } } }; JRadioButton jrbCodePoint = new JRadioButton("Codepoints"); jrbCodePoint.setActionCommand(OUTPUT_CODEPOINTS); jrbCodePoint.addActionListener(outputSelection); jrbCodePoint.setSelected(true); JRadioButton jrbEntities = new JRadioButton("Entities"); jrbEntities.setActionCommand(OUTPUT_ENTITIES); jrbEntities.addActionListener(outputSelection); ButtonGroup bg = new ButtonGroup(); bg.add(jrbCodePoint); bg.add(jrbEntities); top1.add(jrbCodePoint); top1.add(jrbEntities); JPanel top2 = new JPanel(new FlowLayout(FlowLayout.LEFT)); top2.add(new JLabel("Family (AWT): ")); top2.add(familyNameFieldAwt); top2.add(new JLabel("Family (iText): ")); top2.add(familyNameFieldIText); JPanel top = new JPanel(new BorderLayout()); top.add(top1, BorderLayout.NORTH); top.add(top2, BorderLayout.CENTER); JPanel mid = new JPanel(new FlowLayout(FlowLayout.LEFT)); prevBtn = new JButton("Prev"); nextBtn = new JButton("Next"); JButton pdfBtn = new JButton("PDF"); JButton renderBtn = new JButton("Render"); prevBtn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { deferredChangePage(curFrom - ENT_PER_PAGE); } }); nextBtn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { deferredChangePage(curFrom + ENT_PER_PAGE); } }); renderBtn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { deferredChangePage(curFrom); } }); pdfBtn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { resolveCurrentFont(); if (currentFont == null) { JOptionPane.showMessageDialog(frame, "Need a valid font file path"); fontPathTF.requestFocus(); return; } deferredLoadAndRender(curFrom, TO_PDF); } }); mid.add(prevBtn); mid.add(nextBtn); mid.add(renderBtn); mid.add(pdfBtn); optionsPanel.add(top, BorderLayout.NORTH); optionsPanel.add(mid, BorderLayout.CENTER); fontPathTF.addActionListener(new AbstractAction() { public void actionPerformed(ActionEvent actionEvent) { deferredChangePage(curFrom); } }); // Create a JPanel subclass to render the page xpanel = new XHTMLPanel(); xpanel.addDocumentListener(new DefaultDocumentListener() { public void documentLoaded() { frame.setCursor(Cursor.getDefaultCursor()); } }); resetMouseListeners(); // Put our xpanel in a scrolling pane. You can use // a regular JScrollPane here, or our FSScrollPane. // FSScrollPane is already set up to move the correct // amount when scrolling 1 line or 1 page FSScrollPane scroll = new FSScrollPane(xpanel); scroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED); scroll.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); JPanel cont = new JPanel(new BorderLayout()); cont.add(optionsPanel, BorderLayout.NORTH); cont.add(scroll, BorderLayout.CENTER); frame.getContentPane().add(cont); frame.pack(); frame.setSize(1024, 730); enableButtons(); frame.setVisible(true); }
From source file:mesquite.lib.MesquitePDFFile.java
License:Open Source License
/** @arg s String holds the text that the pdf file will contain @arg font java.awt.Font the font is specified this way for compatibility with the similar method in MesquitePrintJob *///w w w . j a v a2s .c o m public void printText(String s, java.awt.Font font) { final String exceptionMessage = "Error, an exception occurred while creating the pdf text document: "; if (s == null || font == null) return; //do the translation from logical to physical font here //currently, the only font this method ever gets called with is "Monospaced",PLAIN,10. So the //translation effort here will be minimal int desiredFontFamily; // "Monospaced" isn't defined in com.lowagie.text.Font if (font.getFamily().equals("Monospaced")) desiredFontFamily = com.lowagie.text.Font.COURIER; else desiredFontFamily = com.lowagie.text.Font.TIMES_ROMAN; com.lowagie.text.Font textFont; switch (font.getStyle()) { case java.awt.Font.BOLD: { textFont = new com.lowagie.text.Font(desiredFontFamily, font.getSize(), com.lowagie.text.Font.BOLD); break; } case java.awt.Font.ITALIC: { textFont = new com.lowagie.text.Font(desiredFontFamily, font.getSize(), com.lowagie.text.Font.ITALIC); break; } case java.awt.Font.PLAIN: { textFont = new com.lowagie.text.Font(desiredFontFamily, font.getSize(), com.lowagie.text.Font.NORMAL); break; } default: { textFont = new com.lowagie.text.Font(desiredFontFamily, font.getSize(), com.lowagie.text.Font.BOLDITALIC); } } document = new Document(); try { PdfWriter.getInstance(document, new FileOutputStream(pdfPathString)); addMetaData(document); document.open(); document.add(new Paragraph(s, textFont)); } catch (DocumentException de) { MesquiteTrunk.mesquiteTrunk.alert(exceptionMessage + de.getMessage()); } catch (IOException ioe) { MesquiteTrunk.mesquiteTrunk.alert(exceptionMessage + ioe.getMessage()); } this.end(); }
From source file:mpv5.utils.xdocreport.YabsFontFactoryImpl.java
License:Open Source License
@Override public void register(String path, String alias) { try {//from ww w . ja v a2 s .c om java.awt.Font cf = java.awt.Font.createFont(java.awt.Font.TRUETYPE_FONT, new File(path)); paths.put(cf.getFamily(), path); } catch (FontFormatException ex) { try { java.awt.Font cf = java.awt.Font.createFont(java.awt.Font.TYPE1_FONT, new File(path)); paths.put(cf.getFontName(), path); Log.Debug(this, ex.getLocalizedMessage()); } catch (FontFormatException ex1) { Log.Debug(this, ex1.getLocalizedMessage()); } catch (IOException ex1) { Log.Debug(this, ex1.getLocalizedMessage()); } } catch (IOException ex) { Log.Debug(this, ex.getLocalizedMessage()); } catch (Exception e) { Log.Debug(this, e.getLocalizedMessage()); } }