List of usage examples for com.lowagie.text Chunk getFont
public Font getFont()
Chunk
. From source file:org.gtdfree.addons.PDFExportAddOn.java
License:Open Source License
private Chunk newStalledChunk() throws DocumentException, IOException { Chunk c = newChunk(CHECK_STALLED); c.getFont().setSize(baseFontSize + 2); c.getFont().setColor(COLOR_DELETED); return c;/*from ww w. j a va 2s .com*/ }
From source file:org.gtdfree.addons.PDFExportAddOn.java
License:Open Source License
private Chunk newDeletedChunk() throws DocumentException, IOException { Chunk c = newChunk(CHECK_DELETED); c.getFont().setSize(baseFontSize + 2); c.getFont().setColor(COLOR_DELETED); return c;/*from w ww . j av a 2 s .co m*/ }
From source file:org.gtdfree.addons.PDFExportAddOn.java
License:Open Source License
private Chunk newHighStarChunk() throws DocumentException, IOException { Chunk c = newChunk(FULL_STAR); //c.getFont().setSize(defaultFontSize+2); c.getFont().setColor(COLOR_PRIORITY_HIGH); return c;//w ww.j a v a2s . c o m }
From source file:org.gtdfree.addons.PDFExportAddOn.java
License:Open Source License
private Chunk newMediumStarChunk() throws DocumentException, IOException { Chunk c = newChunk(FULL_STAR); //c.getFont().setSize(defaultFontSize+2); c.getFont().setColor(COLOR_PRIORITY_MEDIUM); return c;/* w ww . jav a 2s . c om*/ }
From source file:org.gtdfree.addons.PDFExportAddOn.java
License:Open Source License
private Chunk newLowStarChunk() throws DocumentException, IOException { Chunk c = newChunk(FULL_STAR); //c.getFont().setSize(defaultFontSize+2); c.getFont().setColor(COLOR_PRIORITY_LOW); return c;// w ww . jav a 2 s .co m }
From source file:org.gtdfree.addons.PDFExportAddOn.java
License:Open Source License
private Chunk newNoneStarChunk() throws DocumentException, IOException { Chunk c = newChunk(HOLLOW_STAR); //c.getFont().setSize(defaultFontSize+2); c.getFont().setColor(Color.BLACK); return c;//from www . j a v a 2s .c o m }
From source file:org.odftoolkit.odfdom.converter.internal.itext.stylable.StylableList.java
License:Open Source License
public void applyStyles(Style style) { this.lastStyleApplied = style; Map<Integer, StyleListProperties> listPropertiesMap = style.getListPropertiesMap(); if (listPropertiesMap != null) { StyleListProperties listProperties = null; for (int i = listLevel; i >= 0 && listProperties == null; i--) { // find style for current or nearest lower list level listProperties = listPropertiesMap.get(i); }/*from ww w. ja v a 2 s . c om*/ if (listProperties != null) { String bulletChar = listProperties.getBulletChar(); if (bulletChar != null) { // list item label is a char Chunk symbol = new Chunk(bulletChar); StyleTextProperties textProperties = style.getTextProperties(); if (textProperties != null) { Font font = textProperties.getFont(); if (font != null) { symbol.setFont(font); } } super.setListSymbol(symbol); } Image image = listProperties.getImage(); if (image != null) { // list item label is an image Float width = listProperties.getWidth(); if (width != null) { image.scaleAbsoluteWidth(width); } Float height = listProperties.getHeight(); if (height != null) { image.scaleAbsoluteHeight(height); } super.setListSymbol(new Chunk(image, 0.0f, 0.0f)); } if (bulletChar == null && image == null) { // list item label is a number Chunk symbol = new Chunk(""); StyleTextProperties textProperties = style.getTextProperties(); if (textProperties != null) { Font font = textProperties.getFont(); if (font != null) { symbol.setFont(font); } } Integer startValue = listProperties.getStartValue(); if (startValue != null) { super.setFirst(startValue); } String numPrefix = listProperties.getNumPrefix(); if (numPrefix != null) { super.setPreSymbol(numPrefix); symbol = new Chunk(numPrefix, symbol.getFont()); } String numSuffix = listProperties.getNumSuffix(); if (numSuffix != null) { super.setPostSymbol(numSuffix); symbol.append(numSuffix); } StyleNumFormat numFormat = listProperties.getNumFormat(); if (numFormat != null) { super.setNumbered(true); super.setLettered(numFormat.isAlphabetical()); this.romanNumbered = numFormat.isRoman(); super.setLowercase(numFormat.isLowercase()); } super.setListSymbol(symbol); } Float marginLeft = listProperties.getMarginLeft(); Float textIndent = listProperties.getTextIndent(); if (marginLeft != null && textIndent != null) { super.setIndentationLeft(Math.max(marginLeft + textIndent, 0.0f)); super.setSymbolIndent(Math.max(-textIndent, 0.0f)); super.setAutoindent(false); } } } }
From source file:org.odftoolkit.odfdom.converter.internal.itext.stylable.StylableListItem.java
License:Open Source License
@Override public void setListSymbol(Chunk symbol) { Chunk chunk = new Chunk(symbol); // adjust chunk attributes like text rise // use StylableParagraph mechanism StylableParagraph p = new StylableParagraph(null, null); p.setFont(chunk.getFont()); p.addElement(chunk);/*from ww w. j a v a2 s .com*/ p.getElement(); // post-processing here chunk = (Chunk) p.getChunks().get(0); super.setListSymbol(chunk); }
From source file:org.odftoolkit.odfdom.converter.internal.itext.stylable.StylableParagraph.java
License:Open Source License
@SuppressWarnings("unchecked") public Element getElement() { if (!elementPostProcessed) { elementPostProcessed = true;/*from www . ja v a 2 s.co m*/ // add space if this paragraph is empty // otherwise it's height will be zero boolean empty = true; ArrayList<Chunk> chunks = getChunks(); for (Chunk chunk : chunks) { if (chunk.getImage() == null && chunk.getContent() != null && chunk.getContent().length() > 0) { empty = false; break; } } if (empty) { super.add(new Chunk("\u00A0")); // non breaking space } // adjust line height and baseline if (font != null && font.getBaseFont() != null) { // iText and open office computes proportional line height differently // [iText] line height = coefficient * font size // [open office] line height = coefficient * (font ascender + font descender + font extra margin) // we have to increase paragraph line height to generate pdf similar to open office document // this algorithm may be inaccurate if fonts with different multipliers are used in this paragraph float size = font.getSize(); float ascender = font.getBaseFont().getFontDescriptor(BaseFont.AWT_ASCENT, size); float descender = -font.getBaseFont().getFontDescriptor(BaseFont.AWT_DESCENT, size); // negative value float margin = font.getBaseFont().getFontDescriptor(BaseFont.AWT_LEADING, size); float multiplier = (ascender + descender + margin) / size; if (multipliedLeading > 0.0f) { setMultipliedLeading(getMultipliedLeading() * multiplier); } // iText seems to output text with baseline lower than open office // we raise all paragraph text by some amount // again this may be inaccurate if fonts with different size are used in this paragraph float itextdescender = -font.getBaseFont().getFontDescriptor(BaseFont.DESCENT, size); // negative float textRise = itextdescender + getTotalLeading() - font.getSize() * multiplier; chunks = getChunks(); for (Chunk chunk : chunks) { Font f = chunk.getFont(); if (f != null) { // have to raise underline and strikethru as well float s = f.getSize(); if (f.isUnderlined()) { f.setStyle(f.getStyle() & ~Font.UNDERLINE); chunk.setUnderline(s * 1 / 17, s * -1 / 7 + textRise); } if (f.isStrikethru()) { f.setStyle(f.getStyle() & ~Font.STRIKETHRU); chunk.setUnderline(s * 1 / 17, s * 1 / 4 + textRise); } } chunk.setTextRise(chunk.getTextRise() + textRise); } } // wrap this paragraph into a table if necessary if (wrapperCell != null) { // background color or borders were set wrapperCell.addElement(this); wrapperTable = createTable(wrapperCell); if (getIndentationLeft() > 0.0f || getIndentationRight() > 0.0f || getSpacingBefore() > 0.0f || getSpacingAfter() > 0.0f) { // margins were set, have to wrap the cell again PdfPCell outerCell = createCell(); outerCell.setPaddingLeft(getIndentationLeft()); setIndentationLeft(0.0f); outerCell.setPaddingRight(getIndentationRight()); setIndentationRight(0.0f); outerCell.setPaddingTop(getSpacingBefore()); setSpacingBefore(0.0f); outerCell.setPaddingBottom(getSpacingAfter()); setSpacingAfter(0.0f); outerCell.addElement(wrapperTable); wrapperTable = createTable(outerCell); } } } return wrapperTable != null ? wrapperTable : this; }
From source file:org.sakaiproject.tool.assessment.pdf.itext.HTMLWorker.java
License:Mozilla Public License
public void startElement(String tag, HashMap h) { if (!tagsSupported.containsKey(tag)) return;/*from w w w .j a v a 2s. c o m*/ try { style.applyStyle(tag, h); String follow = (String) FactoryProperties.followTags.get(tag); if (follow != null) { HashMap prop = new HashMap(); prop.put(follow, null); cprops.addToChain(follow, prop); return; } FactoryProperties.insertStyle(h); if (tag.equals("a")) { cprops.addToChain(tag, h); if (currentParagraph == null) currentParagraph = new Paragraph(); stack.push(currentParagraph); currentParagraph = new Paragraph(); return; } if (tag.equals("br")) { if (currentParagraph == null) currentParagraph = new Paragraph(); currentParagraph.add(factoryProperties.createChunk("\n", cprops)); return; } if (tag.equals("hr")) { PdfPTable hr = new PdfPTable(1); hr.setHorizontalAlignment(Element.ALIGN_CENTER); hr.setWidthPercentage(100f); hr.setSpacingAfter(0f); hr.setSpacingBefore(0f); PdfPCell cell = new PdfPCell(); cell.setUseVariableBorders(true); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBorder(PdfPCell.BOTTOM); cell.setBorderWidth(1f); cell.setPadding(0); cell.addElement(factoryProperties.createChunk("\n", cprops)); hr.addCell(cell); // paragraphs can't have tables? really? without it hr's may be rendered a bit early.. //if (currentParagraph != null) // currentParagraph.add(hr); //else document.add(hr); return; } if (tag.equals("font") || tag.equals("span")) { cprops.addToChain(tag, h); return; } if (tag.equals("img")) { String src = (String) h.get("src"); if (src == null) return; cprops.addToChain(tag, h); Image img = null; if (interfaceProps != null) { HashMap images = (HashMap) interfaceProps.get("img_static"); if (images != null) { Image tim = (Image) images.get(src); if (tim != null) img = Image.getInstance(tim); } else { if (!src.startsWith("http")) { // relative src references only String baseurl = (String) interfaceProps.get("img_baseurl"); if (baseurl != null) { src = baseurl + src; img = Image.getInstance(src); } } } } if (img == null) { if (!src.startsWith("http")) { String path = cprops.getProperty("image_path"); if (path == null) path = ""; src = new File(path, src).getPath(); img = Image.getInstance(src); } else { byte[] buffer; String srcResource = src.substring(src.indexOf("/content", 0)).replaceAll("/content", ""); buffer = getImageStream(URLDecoder.decode(srcResource)); img = Image.getInstance(buffer); } } String align = (String) h.get("align"); String width = (String) h.get("width"); String height = (String) h.get("height"); String border = (String) h.get("border"); String hspace = (String) h.get("hspace"); String vspace = (String) h.get("vspace"); String before = cprops.getProperty("before"); String after = cprops.getProperty("after"); float wp = 0.0f; float lp = 0.0f; if (maxWidth > 0 && ((width != null && Integer.parseInt(width) > maxWidth) || (width == null && (int) img.getWidth() > maxWidth))) { wp = lengthParse(String.valueOf(maxWidth), (int) img.getWidth()); lp = wp; } else { wp = lengthParse(width, (int) img.getWidth()); lp = lengthParse(height, (int) img.getHeight()); } if (wp > 0 && lp > 0) img.scalePercent(wp, lp); else if (wp > 0) img.scalePercent(wp); else if (lp > 0) img.scalePercent(lp); img.setWidthPercentage(0); // border if (border != null && !"".equals(border)) { try { img.setBorderWidth(Integer.parseInt(border)); img.setBorder(Image.BOX); } catch (Exception e) { e.printStackTrace(); } } // horizonatal space if (hspace != null && !"".equals(hspace)) { try { img.setSpacingAfter(Float.parseFloat(hspace)); img.setSpacingBefore(Float.parseFloat(hspace)); } catch (Exception e) { e.printStackTrace(); } } // horizontal alignment if (align != null && (align.equalsIgnoreCase("left") || align.equalsIgnoreCase("right"))) { endElement("p"); int ralign = Image.LEFT; if (align.equalsIgnoreCase("right")) ralign = Image.RIGHT; img.setAlignment(ralign | Image.TEXTWRAP); Img i = null; boolean skip = false; if (interfaceProps != null) { i = (Img) interfaceProps.get("img_interface"); if (i != null) skip = i.process(img, h, cprops, document); } if (!skip) document.add(img); cprops.removeChain(tag); } // vertical alignment (or none) else { img.setAlignment(Image.TEXTWRAP); float bottom = 0.0f; float top = img.getTop(); float prevHeight = 0.0f; float prevRise = 0.0f; if (currentParagraph != null) { ArrayList chunks = currentParagraph.getChunks(); Chunk sibling = null; for (int k = chunks.size() - 1; k >= 0; k--) { if (chunks.get(k) != null) sibling = (Chunk) chunks.get(k); } if (sibling != null) { if (sibling.hasAttributes()) prevRise = sibling.getTextRise(); prevHeight = 0.0f; if (sibling.getFont() != null) { prevHeight = sibling.getFont().getCalculatedSize(); } } } if ("absMiddle".equalsIgnoreCase(align)) { if (prevHeight > 0) bottom += (img.getScaledHeight() / 2.0f) - (prevHeight / 2.0f); else if (img.getScaledHeight() > 0) bottom += img.getScaledHeight() / 2.0f; } else if ("middle".equalsIgnoreCase(align)) { if (img.getScaledHeight() > 0) bottom += (img.getScaledHeight() / 2.0f); } else if ("bottom".equalsIgnoreCase(align) || "baseline".equalsIgnoreCase(align) || "absbottom".equalsIgnoreCase(align)) { //baseline and absbottom should have some slight tweeking from bottom, but not sure what?? } else if ("top".equalsIgnoreCase(align)) { bottom += img.getScaledHeight() - prevHeight; } else if ("texttop".equalsIgnoreCase(align)) { bottom += img.getScaledHeight() - (prevHeight - prevRise); } cprops.removeChain(tag); if (currentParagraph == null) { currentParagraph = FactoryProperties.createParagraph(cprops); bottom = 0f; } else if (currentParagraph.isEmpty()) { bottom = 0f; } currentParagraph.setLeading(2f + bottom, 1.00f); currentParagraph.add(new Chunk(img, 0, 0 - bottom)); } return; } if (tag.equals("blockquote")) { cprops.addToChain(tag, h); inBLOCK = true; if (currentParagraph != null) endElement("p"); currentParagraph = FactoryProperties.createParagraph(cprops); currentParagraph.add(factoryProperties.createChunk("\n", cprops)); return; } endElement("p"); if (tag.equals("h1") || tag.equals("h2") || tag.equals("h3") || tag.equals("h4") || tag.equals("h5") || tag.equals("h6")) { if (!h.containsKey("size")) { int v = 8 - Integer.parseInt(tag.substring(1)); h.put("size", Integer.toString(v)); } cprops.addToChain(tag, h); return; } if (tag.equals("ul")) { if (pendingLI) endElement("li"); skipText = true; cprops.addToChain(tag, h); com.lowagie.text.List list = new com.lowagie.text.List(false, 10); list.setListSymbol("\u2022"); stack.push(list); return; } if (tag.equals("ol")) { if (pendingLI) endElement("li"); skipText = true; cprops.addToChain(tag, h); com.lowagie.text.List list = new com.lowagie.text.List(true, 10); stack.push(list); return; } if (tag.equals("li")) { if (pendingLI) endElement("li"); skipText = false; pendingLI = true; cprops.addToChain(tag, h); stack.push(FactoryProperties.createListItem(cprops)); return; } if (tag.equals("div") || tag.equals("body")) { cprops.addToChain(tag, h); return; } if (tag.equals("pre")) { if (!h.containsKey("face")) { h.put("face", "Courier"); } cprops.addToChain(tag, h); isPRE = true; return; } if (tag.equals("p")) { cprops.addToChain(tag, h); currentParagraph = FactoryProperties.createParagraph(cprops); if (inBLOCK) { currentParagraph.setIndentationLeft(currentParagraph.getIndentationLeft() + 40.0F); } return; } if (tag.equals("tr")) { if (pendingTR) endElement("tr"); skipText = true; pendingTR = true; cprops.addToChain("tr", h); return; } if (tag.equals("td") || tag.equals("th")) { if (pendingTD) endElement(tag); skipText = false; pendingTD = true; cprops.addToChain("td", h); stack.push(new IncCell(tag, cprops)); return; } if (tag.equals("table")) { cprops.addToChain("table", h); IncTable table = new IncTable(h); stack.push(table); tableState.push(new boolean[] { pendingTR, pendingTD }); pendingTR = pendingTD = false; skipText = true; return; } } catch (Exception e) { e.printStackTrace(); //throw new ExceptionConverter(e); } }