/** * Creates a Phrase object based on a list of properties. * @param attributes * @return a Phrase */ public static Phrase getPhrase(Properties attributes) { Phrase phrase = new Phrase(); phrase.setFont(FontFactory.getFont(attributes)); String value; value = attributes.getProperty(ElementTags.LEADING); if (value != null) { phrase.setLeading(Float.parseFloat(value + "f")); } value = attributes.getProperty(Markup.CSS_KEY_LINEHEIGHT); if (value != null) { phrase.setLeading(Markup.parseLength(value, Markup.DEFAULT_FONT_SIZE)); } value = attributes.getProperty(ElementTags.ITEXT); if (value != null) { Chunk chunk = new Chunk(value); if ((value = attributes.getProperty(ElementTags.GENERICTAG)) != null) { chunk.setGenericTag(value); } phrase.add(chunk); } return phrase; }
/** * Translates a <CODE>String</CODE> -value of a certain style into the * index value is used for this style in this class. * * @param style * A <CODE>String</CODE> * @return the corresponding value */ public static int getStyleValue(String style) { int s = 0; if (style.indexOf(Markup.CSS_VALUE_NORMAL) != -1) { s |= NORMAL; } if (style.indexOf(Markup.CSS_VALUE_BOLD) != -1) { s |= BOLD; } if (style.indexOf(Markup.CSS_VALUE_ITALIC) != -1) { s |= ITALIC; } if (style.indexOf(Markup.CSS_VALUE_OBLIQUE) != -1) { s |= ITALIC; } if (style.indexOf(Markup.CSS_VALUE_UNDERLINE) != -1) { s |= UNDERLINE; } if (style.indexOf(Markup.CSS_VALUE_LINETHROUGH) != -1) { s |= STRIKETHRU; } return s; }
/** Creates a new instance of IncCell */ public IncCell(String tag, ChainedProperties props) { cell = new PdfPCell((Phrase)null); String value = props.getProperty("colspan"); if (value != null) cell.setColspan(Integer.parseInt(value)); value = props.getProperty("align"); if (tag.equals("th")) cell.setHorizontalAlignment(Element.ALIGN_CENTER); if (value != null) { if ("center".equalsIgnoreCase(value)) cell.setHorizontalAlignment(Element.ALIGN_CENTER); else if ("right".equalsIgnoreCase(value)) cell.setHorizontalAlignment(Element.ALIGN_RIGHT); else if ("left".equalsIgnoreCase(value)) cell.setHorizontalAlignment(Element.ALIGN_LEFT); else if ("justify".equalsIgnoreCase(value)) cell.setHorizontalAlignment(Element.ALIGN_JUSTIFIED); } value = props.getProperty("valign"); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); if (value != null) { if ("top".equalsIgnoreCase(value)) cell.setVerticalAlignment(Element.ALIGN_TOP); else if ("bottom".equalsIgnoreCase(value)) cell.setVerticalAlignment(Element.ALIGN_BOTTOM); } value = props.getProperty("border"); float border = 0; if (value != null) border = Float.parseFloat(value); cell.setBorderWidth(border); value = props.getProperty("cellpadding"); if (value != null) cell.setPadding(Float.parseFloat(value)); cell.setUseDescender(true); value = props.getProperty("bgcolor"); cell.setBackgroundColor(Markup.decodeColor(value)); }
public Font getFont(ChainedProperties props) { String face = props.getProperty(ElementTags.FACE); if (face != null) { StringTokenizer tok = new StringTokenizer(face, ","); while (tok.hasMoreTokens()) { face = tok.nextToken().trim(); if (face.startsWith("\"")) face = face.substring(1); if (face.endsWith("\"")) face = face.substring(0, face.length() - 1); if (fontImp.isRegistered(face)) break; } } int style = 0; if (props.hasProperty(HtmlTags.I)) style |= Font.ITALIC; if (props.hasProperty(HtmlTags.B)) style |= Font.BOLD; if (props.hasProperty(HtmlTags.U)) style |= Font.UNDERLINE; if (props.hasProperty(HtmlTags.S)) style |= Font.STRIKETHRU; String value = props.getProperty(ElementTags.SIZE); float size = 12; if (value != null) size = Float.parseFloat(value); Color color = Markup.decodeColor(props.getProperty("color")); String encoding = props.getProperty("encoding"); if (encoding == null) encoding = BaseFont.WINANSI; return fontImp.getFont(face, encoding, true, size, style, color); }
/** * Constructs a TagMap based on an XML file and/or on XmlPeer objects * that are added. * * @throws IOException */ public RomeoJulietMap() throws IOException { super(new FileInputStream(PdfTestBase.RESOURCES_DIR + "tagmapRomeoJuliet.xml")); XmlPeer peer = new XmlPeer(ElementTags.CHUNK, "SPEAKER"); peer.addValue(Markup.CSS_KEY_FONTSIZE, "10"); peer.addValue(Markup.CSS_KEY_FONTWEIGHT, Markup.CSS_VALUE_BOLD); peer.addValue(ElementTags.GENERICTAG, ""); put(peer.getAlias(), peer); }
/** * Constructs a TagMap based on an XML file and/or on XmlPeer objects * that are added. * * @throws IOException */ public RomeoJulietMap() throws IOException { //Can't use FileInputStream directly //super(new FileInputStream("tagmapRomeoJuliet.xml")); super(PdfTestRunner.getActivity().getResources().openRawResource(R.raw.tagmapromeojuliet)); XmlPeer peer = new XmlPeer(ElementTags.CHUNK, "SPEAKER"); peer.addValue(Markup.CSS_KEY_FONTSIZE, "10"); peer.addValue(Markup.CSS_KEY_FONTWEIGHT, Markup.CSS_VALUE_BOLD); peer.addValue(ElementTags.GENERICTAG, ""); put(peer.getAlias(), peer); }
/** * Creates a Chunk object based on a list of properties. * @param attributes * @return a Chunk */ public static Chunk getChunk(Properties attributes) { Chunk chunk = new Chunk(); chunk.setFont(FontFactory.getFont(attributes)); String value; value = attributes.getProperty(ElementTags.ITEXT); if (value != null) { chunk.append(value); } value = attributes.getProperty(ElementTags.LOCALGOTO); if (value != null) { chunk.setLocalGoto(value); } value = attributes.getProperty(ElementTags.REMOTEGOTO); if (value != null) { String page = attributes.getProperty(ElementTags.PAGE); if (page != null) { chunk.setRemoteGoto(value, Integer.parseInt(page)); } else { String destination = attributes .getProperty(ElementTags.DESTINATION); if (destination != null) { chunk.setRemoteGoto(value, destination); } } } value = attributes.getProperty(ElementTags.LOCALDESTINATION); if (value != null) { chunk.setLocalDestination(value); } value = attributes.getProperty(ElementTags.SUBSUPSCRIPT); if (value != null) { chunk.setTextRise(Float.parseFloat(value + "f")); } value = attributes.getProperty(Markup.CSS_KEY_VERTICALALIGN); if (value != null && value.endsWith("%")) { float p = Float.parseFloat(value.substring(0, value.length() - 1) + "f") / 100f; chunk.setTextRise(p * chunk.getFont().getSize()); } value = attributes.getProperty(ElementTags.GENERICTAG); if (value != null) { chunk.setGenericTag(value); } value = attributes.getProperty(ElementTags.BACKGROUNDCOLOR); if (value != null) { chunk.setBackground(Markup.decodeColor(value)); } return chunk; }