List of usage examples for com.itextpdf.text Font getStyle
public int getStyle()
From source file:de.knurt.heinzelmann.util.itext.TextBlock.java
License:Creative Commons License
private List<Chunk> getChunks(String content) { Font italic = new Font(this.font); italic.setStyle(Font.ITALIC); Font normal = new Font(this.font); normal.setStyle(Font.NORMAL); Font bold = new Font(this.font); bold.setStyle(Font.BOLD);//from w w w . ja v a 2 s. c o m Font bolditalic = new Font(this.font); bolditalic.setStyle(Font.BOLDITALIC); Font markfont = null; boolean markModus = false; List<Chunk> result = new ArrayList<Chunk>(); List<Chunk> tmp = new ArrayList<Chunk>(); StringTokenizer tokenizer = new StringTokenizer(content, "\\*", true); while (tokenizer.hasMoreTokens()) { String tok = tokenizer.nextToken(); if (tok.equals("*")) { if (markModus) { if (markfont.getStyle() == Font.ITALIC) { markfont = bold; } else { markfont = bolditalic; } } else { if (markfont == null) { markfont = italic; markModus = true; } else if (markfont.getStyle() == Font.BOLDITALIC) { markfont = bold; } else if (markfont.getStyle() == Font.BOLD) { markfont = italic; } else if (markfont.getStyle() == Font.ITALIC) { markfont = null; } } continue; } if (markfont != null) { tmp.add(new Chunk(tok, markfont)); markModus = false; } else { tmp.add(new Chunk(tok, normal)); } } result.addAll(tmp); return result; }
From source file:fenix.planner.pdf.PDFGenerator.java
License:Open Source License
private void parseAndAddBodyTextLineToParagraph(Paragraph paragraph, String line, Font font) { // TODO add support for additional styles // TODO add better error checking and reporting Font currentFont = new Font(font); StringBuilder sb = new StringBuilder(); for (char c : line.toCharArray()) { if (c == '*') { if (sb.length() > 0) { paragraph.add(new Phrase(sb.toString(), currentFont)); sb = new StringBuilder(); }/*from ww w . ja v a2s . c om*/ if (currentFont.isBold()) { currentFont = deriveWithStyle(currentFont, currentFont.getStyle() & ~Font.BOLD); } else { currentFont = deriveWithStyle(currentFont, currentFont.getStyle() | Font.BOLD); } } else if (c == '_') { if (sb.length() > 0) { paragraph.add(new Phrase(sb.toString(), currentFont)); sb = new StringBuilder(); } if (currentFont.isItalic()) { currentFont = deriveWithStyle(currentFont, currentFont.getStyle() & ~Font.ITALIC); } else { currentFont = deriveWithStyle(currentFont, currentFont.getStyle() | Font.ITALIC); } } else { sb.append(c); } } paragraph.add(new Phrase(sb.toString(), currentFont)); }