com.lowagie.text.ElementTags Java Examples

The following examples show how to use com.lowagie.text.ElementTags. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ElementFactory.java    From itext2 with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Helper method to create a Chapter/Section object.
 * @param attributes
 */
private static void setSectionParameters(Section section,
		Properties attributes) {
	String value;
	value = attributes.getProperty(ElementTags.NUMBERDEPTH);
	if (value != null) {
		section.setNumberDepth(Integer.parseInt(value));
	}
	value = attributes.getProperty(ElementTags.INDENT);
	if (value != null) {
		section.setIndentation(Float.parseFloat(value + "f"));
	}
	value = attributes.getProperty(ElementTags.INDENTATIONLEFT);
	if (value != null) {
		section.setIndentationLeft(Float.parseFloat(value + "f"));
	}
	value = attributes.getProperty(ElementTags.INDENTATIONRIGHT);
	if (value != null) {
		section.setIndentationRight(Float.parseFloat(value + "f"));
	}
}
 
Example #2
Source File: ElementFactory.java    From gcs with Mozilla Public License 2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example #3
Source File: ElementFactory.java    From itext2 with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Creates a Paragraph object based on a list of properties.
 * @param attributes
 * @return a Paragraph
 */
public static Paragraph getParagraph(Properties attributes) {
	Paragraph paragraph = new Paragraph(getPhrase(attributes));
	String value;
	value = attributes.getProperty(ElementTags.ALIGN);
	if (value != null) {
		paragraph.setAlignment(value);
	}
	value = attributes.getProperty(ElementTags.INDENTATIONLEFT);
	if (value != null) {
		paragraph.setIndentationLeft(Float.parseFloat(value + "f"));
	}
	value = attributes.getProperty(ElementTags.INDENTATIONRIGHT);
	if (value != null) {
		paragraph.setIndentationRight(Float.parseFloat(value + "f"));
	}
	return paragraph;
}
 
Example #4
Source File: ElementFactory.java    From gcs with Mozilla Public License 2.0 6 votes vote down vote up
/**
 * Creates a Paragraph object based on a list of properties.
 * 
 * @param attributes
 * @return a Paragraph
 */
public static Paragraph getParagraph(Properties attributes) {
	Paragraph paragraph = new Paragraph(getPhrase(attributes));
	String value;
	value = attributes.getProperty(ElementTags.ALIGN);
	if (value != null) {
		paragraph.setAlignment(value);
	}
	value = attributes.getProperty(ElementTags.INDENTATIONLEFT);
	if (value != null) {
		paragraph.setIndentationLeft(Float.parseFloat(value + "f"));
	}
	value = attributes.getProperty(ElementTags.INDENTATIONRIGHT);
	if (value != null) {
		paragraph.setIndentationRight(Float.parseFloat(value + "f"));
	}
	return paragraph;
}
 
Example #5
Source File: ElementFactory.java    From itext2 with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * 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;
}
 
Example #6
Source File: ElementFactory.java    From gcs with Mozilla Public License 2.0 6 votes vote down vote up
/**
 * Helper method to create a Chapter/Section object.
 * 
 * @param attributes
 */
private static void setSectionParameters(Section section, Properties attributes) {
	String value;
	value = attributes.getProperty(ElementTags.NUMBERDEPTH);
	if (value != null) {
		section.setNumberDepth(Integer.parseInt(value));
	}
	value = attributes.getProperty(ElementTags.INDENT);
	if (value != null) {
		section.setIndentation(Float.parseFloat(value + "f"));
	}
	value = attributes.getProperty(ElementTags.INDENTATIONLEFT);
	if (value != null) {
		section.setIndentationLeft(Float.parseFloat(value + "f"));
	}
	value = attributes.getProperty(ElementTags.INDENTATIONRIGHT);
	if (value != null) {
		section.setIndentationRight(Float.parseFloat(value + "f"));
	}
}
 
Example #7
Source File: HtmlPeer.java    From itext2 with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * @see com.lowagie.text.xml.XmlPeer#getAttributes(org.xml.sax.Attributes)
 */
public Properties getAttributes(Attributes attrs) {
	Properties attributes = new Properties();
	attributes.putAll(attributeValues);
	if (defaultContent != null) {
		attributes.put(ElementTags.ITEXT, defaultContent);
	}
	if (attrs != null) {
		String attribute, value;
		for (int i = 0; i < attrs.getLength(); i++) {
			attribute = getName(attrs.getQName(i).toLowerCase());
			value = attrs.getValue(i);
			attributes.setProperty(attribute, value);
		}
	}
	return attributes;
   }
 
Example #8
Source File: HtmlPeer.java    From gcs with Mozilla Public License 2.0 6 votes vote down vote up
/**
 * @see com.lowagie.text.xml.XmlPeer#getAttributes(org.xml.sax.Attributes)
 */
public Properties getAttributes(Attributes attrs) {
	Properties attributes = new Properties();
	attributes.putAll(attributeValues);
	if (defaultContent != null) {
		attributes.put(ElementTags.ITEXT, defaultContent);
	}
	if (attrs != null) {
		String attribute, value;
		for (int i = 0; i < attrs.getLength(); i++) {
			attribute = getName(attrs.getQName(i).toLowerCase());
			value = attrs.getValue(i);
			attributes.setProperty(attribute, value);
		}
	}
	return attributes;
   }
 
Example #9
Source File: HTMLWorker.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
/** Creates a new instance of HTMLWorker */
public HTMLWorker(DocListener document) {
	this.document = document;
	cprops = new ChainedProperties();
	String fontName = ServerConfigurationService.getString("pdf.default.font");
	if (StringUtils.isNotBlank(fontName)) {
		FontFactory.registerDirectories();
		if (FontFactory.isRegistered(fontName)) {
			HashMap fontProps = new HashMap();
			fontProps.put(ElementTags.FACE, fontName);
			fontProps.put("encoding", BaseFont.IDENTITY_H);
			cprops.addToChain("face", fontProps);
		}
	}
}
 
Example #10
Source File: ChainedProperties.java    From itext2 with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void addToChain(String key, HashMap prop) {
	// adjust the font size
	String value = (String) prop.get(ElementTags.SIZE);
	if (value != null) {
		if (value.endsWith("pt")) {
			prop.put(ElementTags.SIZE, value.substring(0,
					value.length() - 2));
		} else {
			int s = 0;
			if (value.startsWith("+") || value.startsWith("-")) {
				String old = getProperty("basefontsize");
				if (old == null)
					old = "12";
				float f = Float.parseFloat(old);
				int c = (int) f;
				for (int k = fontSizes.length - 1; k >= 0; --k) {
					if (c >= fontSizes[k]) {
						s = k;
						break;
					}
				}
				int inc = Integer.parseInt(value.startsWith("+") ? value
						.substring(1) : value);
				s += inc;
			} else {
				try {
					s = Integer.parseInt(value) - 1;
				} catch (NumberFormatException nfe) {
					s = 0;
				}
			}
			if (s < 0)
				s = 0;
			else if (s >= fontSizes.length)
				s = fontSizes.length - 1;
			prop.put(ElementTags.SIZE, Integer.toString(fontSizes[s]));
		}
	}
	chain.add(new Object[] { key, prop });
}
 
Example #11
Source File: FactoryProperties.java    From itext2 with GNU Lesser General Public License v3.0 5 votes vote down vote up
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);
}
 
Example #12
Source File: ElementFactory.java    From itext2 with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Creates a Cell object based on a list of properties.
 * @param attributes
 * @return a Cell
 */
public static Cell getCell(Properties attributes) {
	Cell cell = new Cell();
	String value;

	cell.setHorizontalAlignment(attributes
			.getProperty(ElementTags.HORIZONTALALIGN));
	cell.setVerticalAlignment(attributes
			.getProperty(ElementTags.VERTICALALIGN));

	value = attributes.getProperty(ElementTags.WIDTH);
	if (value != null) {
		cell.setWidth(value);
	}
	value = attributes.getProperty(ElementTags.COLSPAN);
	if (value != null) {
		cell.setColspan(Integer.parseInt(value));
	}
	value = attributes.getProperty(ElementTags.ROWSPAN);
	if (value != null) {
		cell.setRowspan(Integer.parseInt(value));
	}
	value = attributes.getProperty(ElementTags.LEADING);
	if (value != null) {
		cell.setLeading(Float.parseFloat(value + "f"));
	}
	cell.setHeader(Utilities.checkTrueOrFalse(attributes,
			ElementTags.HEADER));
	if (Utilities.checkTrueOrFalse(attributes, ElementTags.NOWRAP)) {
		cell.setMaxLines(1);
	}
	setRectangleProperties(cell, attributes);
	return cell;
}
 
Example #13
Source File: ElementFactory.java    From itext2 with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Creates an Anchor object based on a list of properties.
 * @param attributes
 * @return an Anchor
 */
public static Anchor getAnchor(Properties attributes) {
	Anchor anchor = new Anchor(getPhrase(attributes));
	String value;
	value = attributes.getProperty(ElementTags.NAME);
	if (value != null) {
		anchor.setName(value);
	}
	value = (String) attributes.remove(ElementTags.REFERENCE);
	if (value != null) {
		anchor.setReference(value);
	}
	return anchor;
}
 
Example #14
Source File: XmlPeer.java    From itext2 with GNU Lesser General Public License v3.0 5 votes vote down vote up
/** Gets the list of attributes of the peer. 
* @param attrs the user defined set of attributes
* @return the set of attributes translated to iText attributes
*/
   public Properties getAttributes(Attributes attrs) {
       Properties attributes = new Properties();
       attributes.putAll(attributeValues);
       if (defaultContent != null) {
           attributes.put(ElementTags.ITEXT, defaultContent);
       }
       if (attrs != null) {
           for (int i = 0; i < attrs.getLength(); i++) {
               String attribute = getName(attrs.getQName(i));
               attributes.setProperty(attribute, attrs.getValue(i));
           }
       }
       return attributes;
   }
 
Example #15
Source File: EventsTest.java    From itext2 with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * 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);
}
 
Example #16
Source File: ChainedProperties.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
public void addToChain(String key, HashMap prop) {
	// adjust the font size
	String value = (String) prop.get(ElementTags.SIZE);
	if (value != null) {
		if (value.endsWith("pt")) {
			prop.put(ElementTags.SIZE, value.substring(0, value.length() - 2));
		} else {
			int s = 0;
			if (value.startsWith("+") || value.startsWith("-")) {
				String old = getProperty("basefontsize");
				if (old == null) {
					old = "12";
				}
				float f = Float.parseFloat(old);
				int c = (int) f;
				for (int k = fontSizes.length - 1; k >= 0; --k) {
					if (c >= fontSizes[k]) {
						s = k;
						break;
					}
				}
				int inc = Integer.parseInt(value.startsWith("+") ? value.substring(1) : value);
				s += inc;
			} else {
				try {
					s = Integer.parseInt(value) - 1;
				} catch (NumberFormatException nfe) {
					s = 0;
				}
			}
			if (s < 0) {
				s = 0;
			} else if (s >= fontSizes.length) {
				s = fontSizes.length - 1;
			}
			prop.put(ElementTags.SIZE, Integer.toString(fontSizes[s]));
		}
	}
	chain.add(new Object[] { key, prop });
}
 
Example #17
Source File: HTMLWorker.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
/** Creates a new instance of HTMLWorker */
public HTMLWorker(DocListener document) {
	this.document = document;
	cprops = new ChainedProperties();
	String fontName = ServerConfigurationService.getString("pdf.default.font");
	if (StringUtils.isNotBlank(fontName)) {
		FontFactory.registerDirectories();
		if (FontFactory.isRegistered(fontName)) {
			HashMap fontProps = new HashMap();
			fontProps.put(ElementTags.FACE, fontName);
			fontProps.put("encoding", BaseFont.IDENTITY_H);
			cprops.addToChain("face", fontProps);
		}
	}
}
 
Example #18
Source File: XmlPeer.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
/** Gets the list of attributes of the peer. 
* @param attrs the user defined set of attributes
* @return the set of attributes translated to iText attributes
*/
   public Properties getAttributes(Attributes attrs) {
       Properties attributes = new Properties();
       attributes.putAll(attributeValues);
       if (defaultContent != null) {
           attributes.put(ElementTags.ITEXT, defaultContent);
       }
       if (attrs != null) {
           for (int i = 0; i < attrs.getLength(); i++) {
               String attribute = getName(attrs.getQName(i));
               attributes.setProperty(attribute, attrs.getValue(i));
           }
       }
       return attributes;
   }
 
Example #19
Source File: ElementFactory.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * Creates a Cell object based on a list of properties.
 * 
 * @param attributes
 * @return a Cell
 */
public static Cell getCell(Properties attributes) {
	Cell cell = new Cell();
	String value;

	cell.setHorizontalAlignment(attributes.getProperty(ElementTags.HORIZONTALALIGN));
	cell.setVerticalAlignment(attributes.getProperty(ElementTags.VERTICALALIGN));

	value = attributes.getProperty(ElementTags.WIDTH);
	if (value != null) {
		cell.setWidth(value);
	}
	value = attributes.getProperty(ElementTags.COLSPAN);
	if (value != null) {
		cell.setColspan(Integer.parseInt(value));
	}
	value = attributes.getProperty(ElementTags.ROWSPAN);
	if (value != null) {
		cell.setRowspan(Integer.parseInt(value));
	}
	value = attributes.getProperty(ElementTags.LEADING);
	if (value != null) {
		cell.setLeading(Float.parseFloat(value + "f"));
	}
	cell.setHeader(Utilities.checkTrueOrFalse(attributes, ElementTags.HEADER));
	if (Utilities.checkTrueOrFalse(attributes, ElementTags.NOWRAP)) {
		cell.setMaxLines(1);
	}
	setRectangleProperties(cell, attributes);
	return cell;
}
 
Example #20
Source File: ElementFactory.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * Creates an Anchor object based on a list of properties.
 * 
 * @param attributes
 * @return an Anchor
 */
public static Anchor getAnchor(Properties attributes) {
	Anchor anchor = new Anchor(getPhrase(attributes));
	String value;
	value = attributes.getProperty(ElementTags.NAME);
	if (value != null) {
		anchor.setName(value);
	}
	value = (String) attributes.remove(ElementTags.REFERENCE);
	if (value != null) {
		anchor.setReference(value);
	}
	return anchor;
}
 
Example #21
Source File: SAXmyHtmlHandler.java    From gcs with Mozilla Public License 2.0 4 votes vote down vote up
/**
 * This method gets called when an end tag is encountered.
 * 
 * @param uri
 *            the Uniform Resource Identifier
 * @param lname
 *            the local name (without prefix), or the empty string if
 *            Namespace processing is not being performed.
 * @param name
 *            the name of the tag that ends
 */

public void endElement(String uri, String lname, String name) {
    // System.err.println("End: " + name);
	name = name.toLowerCase();
    if (ElementTags.PARAGRAPH.equals(name)) {
        try {
            document.add((Element) stack.pop());
            return;
        } catch (DocumentException e) {
            throw new ExceptionConverter(e);
        }
    }
    if (HtmlTagMap.isHead(name)) {
        // we do nothing
        return;
    }
    if (HtmlTagMap.isTitle(name)) {
        if (currentChunk != null) {
            bodyAttributes.put(ElementTags.TITLE, currentChunk.getContent());
        }
        return;
    }
    if (HtmlTagMap.isMeta(name)) {
        // we do nothing
        return;
    }
    if (HtmlTagMap.isLink(name)) {
        // we do nothing
        return;
    }
    if (HtmlTagMap.isBody(name)) {
        // we do nothing
        return;
    }
    if (myTags.containsKey(name)) {
        XmlPeer peer = (XmlPeer) myTags.get(name);
        if (ElementTags.TABLE.equals(peer.getTag())) {
            tableBorder = false;
        }
        super.handleEndingTags(peer.getTag());
        return;
    }
    // super.handleEndingTags is replaced with handleEndingTags
    // suggestion by Ken Auer
    handleEndingTags(name);
}
 
Example #22
Source File: ElementFactory.java    From itext2 with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Creates an Annotation object based on a list of properties.
 * @param attributes
 * @return an Annotation
 */
public static Annotation getAnnotation(Properties attributes) {
	float llx = 0, lly = 0, urx = 0, ury = 0;
	String value;

	value = attributes.getProperty(ElementTags.LLX);
	if (value != null) {
		llx = Float.parseFloat(value + "f");
	}
	value = attributes.getProperty(ElementTags.LLY);
	if (value != null) {
		lly = Float.parseFloat(value + "f");
	}
	value = attributes.getProperty(ElementTags.URX);
	if (value != null) {
		urx = Float.parseFloat(value + "f");
	}
	value = attributes.getProperty(ElementTags.URY);
	if (value != null) {
		ury = Float.parseFloat(value + "f");
	}

	String title = attributes.getProperty(ElementTags.TITLE);
	String text = attributes.getProperty(ElementTags.CONTENT);
	if (title != null || text != null) {
		return new Annotation(title, text, llx, lly, urx, ury);
	}
	value = attributes.getProperty(ElementTags.URL);
	if (value != null) {
		return new Annotation(llx, lly, urx, ury, value);
	}
	value = attributes.getProperty(ElementTags.NAMED);
	if (value != null) {
		return new Annotation(llx, lly, urx, ury, Integer.parseInt(value));
	}
	String file = attributes.getProperty(ElementTags.FILE);
	String destination = attributes.getProperty(ElementTags.DESTINATION);
	String page = (String) attributes.remove(ElementTags.PAGE);
	if (file != null) {
		if (destination != null) {
			return new Annotation(llx, lly, urx, ury, file, destination);
		}
		if (page != null) {
			return new Annotation(llx, lly, urx, ury, file, Integer
					.parseInt(page));
		}
	}
	return new Annotation("", "", llx, lly, urx, ury);
}
 
Example #23
Source File: ElementFactory.java    From itext2 with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Creates an Image object based on a list of properties.
 * @param attributes
 * @return an Image
 */
public static Image getImage(Properties attributes)
		throws BadElementException, MalformedURLException, IOException {
	String value;

	value = attributes.getProperty(ElementTags.URL);
	if (value == null)
		throw new MalformedURLException("The URL of the image is missing.");
	Image image = Image.getInstance(value);

	value = attributes.getProperty(ElementTags.ALIGN);
	int align = 0;
	if (value != null) {
		if (ElementTags.ALIGN_LEFT.equalsIgnoreCase(value))
			align |= Image.LEFT;
		else if (ElementTags.ALIGN_RIGHT.equalsIgnoreCase(value))
			align |= Image.RIGHT;
		else if (ElementTags.ALIGN_MIDDLE.equalsIgnoreCase(value))
			align |= Image.MIDDLE;
	}
	if ("true".equalsIgnoreCase(attributes
			.getProperty(ElementTags.UNDERLYING)))
		align |= Image.UNDERLYING;
	if ("true".equalsIgnoreCase(attributes
			.getProperty(ElementTags.TEXTWRAP)))
		align |= Image.TEXTWRAP;
	image.setAlignment(align);

	value = attributes.getProperty(ElementTags.ALT);
	if (value != null) {
		image.setAlt(value);
	}

	String x = attributes.getProperty(ElementTags.ABSOLUTEX);
	String y = attributes.getProperty(ElementTags.ABSOLUTEY);
	if ((x != null) && (y != null)) {
		image.setAbsolutePosition(Float.parseFloat(x + "f"), Float
				.parseFloat(y + "f"));
	}
	value = attributes.getProperty(ElementTags.PLAINWIDTH);
	if (value != null) {
		image.scaleAbsoluteWidth(Float.parseFloat(value + "f"));
	}
	value = attributes.getProperty(ElementTags.PLAINHEIGHT);
	if (value != null) {
		image.scaleAbsoluteHeight(Float.parseFloat(value + "f"));
	}
	value = attributes.getProperty(ElementTags.ROTATION);
	if (value != null) {
		image.setRotation(Float.parseFloat(value + "f"));
	}
	return image;
}
 
Example #24
Source File: ElementFactory.java    From gcs with Mozilla Public License 2.0 4 votes vote down vote up
/**
 * 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;
}
 
Example #25
Source File: ElementFactory.java    From itext2 with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Creates a List object based on a list of properties.
 * @param attributes
 * @return the List
 */
public static List getList(Properties attributes) {
	List list = new List();

	list.setNumbered(Utilities.checkTrueOrFalse(attributes,
			ElementTags.NUMBERED));
	list.setLettered(Utilities.checkTrueOrFalse(attributes,
			ElementTags.LETTERED));
	list.setLowercase(Utilities.checkTrueOrFalse(attributes,
			ElementTags.LOWERCASE));
	list.setAutoindent(Utilities.checkTrueOrFalse(attributes,
			ElementTags.AUTO_INDENT_ITEMS));
	list.setAlignindent(Utilities.checkTrueOrFalse(attributes,
			ElementTags.ALIGN_INDENTATION_ITEMS));

	String value;

	value = attributes.getProperty(ElementTags.FIRST);
	if (value != null) {
		char character = value.charAt(0);
		if (Character.isLetter(character)) {
			list.setFirst(character);
		} else {
			list.setFirst(Integer.parseInt(value));
		}
	}

	value = attributes.getProperty(ElementTags.LISTSYMBOL);
	if (value != null) {
		list
				.setListSymbol(new Chunk(value, FontFactory
						.getFont(attributes)));
	}

	value = attributes.getProperty(ElementTags.INDENTATIONLEFT);
	if (value != null) {
		list.setIndentationLeft(Float.parseFloat(value + "f"));
	}

	value = attributes.getProperty(ElementTags.INDENTATIONRIGHT);
	if (value != null) {
		list.setIndentationRight(Float.parseFloat(value + "f"));
	}

	value = attributes.getProperty(ElementTags.SYMBOLINDENT);
	if (value != null) {
		list.setSymbolIndent(Float.parseFloat(value));
	}

	return list;
}
 
Example #26
Source File: ElementFactory.java    From gcs with Mozilla Public License 2.0 4 votes vote down vote up
/**
 * Creates a List object based on a list of properties.
 * 
 * @param attributes
 * @return the List
 */
public static List getList(Properties attributes) {
	List list = new List();

	list.setNumbered(Utilities.checkTrueOrFalse(attributes, ElementTags.NUMBERED));
	list.setLettered(Utilities.checkTrueOrFalse(attributes, ElementTags.LETTERED));
	list.setLowercase(Utilities.checkTrueOrFalse(attributes, ElementTags.LOWERCASE));
	list.setAutoindent(Utilities.checkTrueOrFalse(attributes, ElementTags.AUTO_INDENT_ITEMS));
	list.setAlignindent(Utilities.checkTrueOrFalse(attributes, ElementTags.ALIGN_INDENTATION_ITEMS));

	String value;

	value = attributes.getProperty(ElementTags.FIRST);
	if (value != null) {
		char character = value.charAt(0);
		if (Character.isLetter(character)) {
			list.setFirst(character);
		} else {
			list.setFirst(Integer.parseInt(value));
		}
	}

	value = attributes.getProperty(ElementTags.LISTSYMBOL);
	if (value != null) {
		list.setListSymbol(new Chunk(value, FontFactory.getFont(attributes)));
	}

	value = attributes.getProperty(ElementTags.INDENTATIONLEFT);
	if (value != null) {
		list.setIndentationLeft(Float.parseFloat(value + "f"));
	}

	value = attributes.getProperty(ElementTags.INDENTATIONRIGHT);
	if (value != null) {
		list.setIndentationRight(Float.parseFloat(value + "f"));
	}

	value = attributes.getProperty(ElementTags.SYMBOLINDENT);
	if (value != null) {
		list.setSymbolIndent(Float.parseFloat(value));
	}

	return list;
}
 
Example #27
Source File: ElementFactory.java    From itext2 with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * 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;
}
 
Example #28
Source File: ElementFactory.java    From gcs with Mozilla Public License 2.0 4 votes vote down vote up
/**
 * Creates an Image object based on a list of properties.
 * 
 * @param attributes
 * @return an Image
 */
public static Image getImage(Properties attributes) throws BadElementException, MalformedURLException, IOException {
	String value;

	value = attributes.getProperty(ElementTags.URL);
	if (value == null) {
		throw new MalformedURLException("The URL of the image is missing.");
	}
	Image image = Image.getInstance(value);

	value = attributes.getProperty(ElementTags.ALIGN);
	int align = 0;
	if (value != null) {
		if (ElementTags.ALIGN_LEFT.equalsIgnoreCase(value)) {
			align |= Image.LEFT;
		} else if (ElementTags.ALIGN_RIGHT.equalsIgnoreCase(value)) {
			align |= Image.RIGHT;
		} else if (ElementTags.ALIGN_MIDDLE.equalsIgnoreCase(value)) {
			align |= Image.MIDDLE;
		}
	}
	if ("true".equalsIgnoreCase(attributes.getProperty(ElementTags.UNDERLYING))) {
		align |= Image.UNDERLYING;
	}
	if ("true".equalsIgnoreCase(attributes.getProperty(ElementTags.TEXTWRAP))) {
		align |= Image.TEXTWRAP;
	}
	image.setAlignment(align);

	value = attributes.getProperty(ElementTags.ALT);
	if (value != null) {
		image.setAlt(value);
	}

	String x = attributes.getProperty(ElementTags.ABSOLUTEX);
	String y = attributes.getProperty(ElementTags.ABSOLUTEY);
	if (x != null && y != null) {
		image.setAbsolutePosition(Float.parseFloat(x + "f"), Float.parseFloat(y + "f"));
	}
	value = attributes.getProperty(ElementTags.PLAINWIDTH);
	if (value != null) {
		image.scaleAbsoluteWidth(Float.parseFloat(value + "f"));
	}
	value = attributes.getProperty(ElementTags.PLAINHEIGHT);
	if (value != null) {
		image.scaleAbsoluteHeight(Float.parseFloat(value + "f"));
	}
	value = attributes.getProperty(ElementTags.ROTATION);
	if (value != null) {
		image.setRotation(Float.parseFloat(value + "f"));
	}
	return image;
}
 
Example #29
Source File: ElementFactory.java    From gcs with Mozilla Public License 2.0 4 votes vote down vote up
/**
 * Creates an Annotation object based on a list of properties.
 * 
 * @param attributes
 * @return an Annotation
 */
public static Annotation getAnnotation(Properties attributes) {
	float llx = 0, lly = 0, urx = 0, ury = 0;
	String value;

	value = attributes.getProperty(ElementTags.LLX);
	if (value != null) {
		llx = Float.parseFloat(value + "f");
	}
	value = attributes.getProperty(ElementTags.LLY);
	if (value != null) {
		lly = Float.parseFloat(value + "f");
	}
	value = attributes.getProperty(ElementTags.URX);
	if (value != null) {
		urx = Float.parseFloat(value + "f");
	}
	value = attributes.getProperty(ElementTags.URY);
	if (value != null) {
		ury = Float.parseFloat(value + "f");
	}

	String title = attributes.getProperty(ElementTags.TITLE);
	String text = attributes.getProperty(ElementTags.CONTENT);
	if (title != null || text != null) {
		return new Annotation(title, text, llx, lly, urx, ury);
	}
	value = attributes.getProperty(ElementTags.URL);
	if (value != null) {
		return new Annotation(llx, lly, urx, ury, value);
	}
	value = attributes.getProperty(ElementTags.NAMED);
	if (value != null) {
		return new Annotation(llx, lly, urx, ury, Integer.parseInt(value));
	}
	String file = attributes.getProperty(ElementTags.FILE);
	String destination = attributes.getProperty(ElementTags.DESTINATION);
	String page = (String) attributes.remove(ElementTags.PAGE);
	if (file != null) {
		if (destination != null) {
			return new Annotation(llx, lly, urx, ury, file, destination);
		}
		if (page != null) {
			return new Annotation(llx, lly, urx, ury, file, Integer.parseInt(page));
		}
	}
	return new Annotation("", "", llx, lly, urx, ury);
}
 
Example #30
Source File: SAXmyHtmlHandler.java    From itext2 with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * This method gets called when an end tag is encountered.
 * 
 * @param uri
 *            the Uniform Resource Identifier
 * @param lname
 *            the local name (without prefix), or the empty string if
 *            Namespace processing is not being performed.
 * @param name
 *            the name of the tag that ends
 */

public void endElement(String uri, String lname, String name) {
    // System.err.println("End: " + name);
	name = name.toLowerCase();
    if (ElementTags.PARAGRAPH.equals(name)) {
        try {
            document.add((Element) stack.pop());
            return;
        } catch (DocumentException e) {
            throw new ExceptionConverter(e);
        }
    }
    if (HtmlTagMap.isHead(name)) {
        // we do nothing
        return;
    }
    if (HtmlTagMap.isTitle(name)) {
        if (currentChunk != null) {
            bodyAttributes.put(ElementTags.TITLE, currentChunk.getContent());
        }
        return;
    }
    if (HtmlTagMap.isMeta(name)) {
        // we do nothing
        return;
    }
    if (HtmlTagMap.isLink(name)) {
        // we do nothing
        return;
    }
    if (HtmlTagMap.isBody(name)) {
        // we do nothing
        return;
    }
    if (myTags.containsKey(name)) {
        XmlPeer peer = (XmlPeer) myTags.get(name);
        if (ElementTags.TABLE.equals(peer.getTag())) {
            tableBorder = false;
        }
        super.handleEndingTags(peer.getTag());
        return;
    }
    // super.handleEndingTags is replaced with handleEndingTags
    // suggestion by Ken Auer
    handleEndingTags(name);
}