public void startElement(String tag, java.util.HashMap h) { if (tag.equals("hyphen-char")) { String hh = (String) h.get("value"); if (hh != null && hh.length() == 1) { hyphenChar = hh.charAt(0); } } else if (tag.equals("classes")) { currElement = ELEM_CLASSES; } else if (tag.equals("patterns")) { currElement = ELEM_PATTERNS; } else if (tag.equals("exceptions")) { currElement = ELEM_EXCEPTIONS; exception = new ArrayList(); } else if (tag.equals("hyphen")) { if (token.length() > 0) { exception.add(token.toString()); } exception.add(new Hyphen((String) h.get(HtmlTags.PRE), (String) h .get("no"), (String) h.get("post"))); currElement = ELEM_HYPHEN; } token.setLength(0); }
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); }
/** * Creates a document with Named Actions. * */ @Test public void main() throws Exception { // step 1: creation of a document-object Document document = new Document(); // step 2: HtmlWriter.getInstance(document, PdfTestBase.getOutputStream("JavaScriptAction.html")); // step 3: we add Javascript as Metadata and we open the document StringBuffer javaScriptSection = new StringBuffer(); javaScriptSection.append("\t\tfunction load() {\n"); javaScriptSection.append("\t\t alert('Page has been loaded.');\n"); javaScriptSection.append("\t\t}\n"); javaScriptSection.append("\t\tfunction unload(){\n"); javaScriptSection.append("\t\t alert('Page has been unloaded.');\n"); javaScriptSection.append("\t\t}\n"); javaScriptSection.append("\t\tfunction sayHi(){\n"); javaScriptSection.append("\t\t alert('Hi !!!');\n"); javaScriptSection.append("\t\t}"); document.add(new Header(HtmlTags.JAVASCRIPT, javaScriptSection.toString())); document.setJavaScript_onLoad("load()"); document.setJavaScript_onUnLoad("unload()"); document.open(); // step 4: we add some content Phrase phrase1 = new Phrase( "There are 3 JavaScript functions in the HTML page, load(), unload() and sayHi().\n\n" + "The first one will be called when the HTML page has been loaded by your browser.\n" + "The second one will be called when the HTML page is being unloaded,\n" + "for example when you go to another page.\n"); document.add(phrase1); // add a HTML link <A HREF="..."> Anchor anchor = new Anchor("Click here to execute the third JavaScript function."); anchor.setReference("JavaScript:sayHi()"); document.add(anchor); // step 5: we close the document document.close(); }