List of usage examples for com.lowagie.text Font isStrikethru
public boolean isStrikethru()
From source file:fr.opensagres.odfdom.converter.pdf.internal.stylable.StylableParagraph.java
License:Open Source License
@SuppressWarnings("unchecked") private void postProcessLineHeightAndBaseline() { // adjust line height and baseline Font font = getMostOftenUsedFont(); if (font == null || font.getBaseFont() == null) { font = this.font; }/*from w w w. j av a 2s . c o m*/ 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; ArrayList<Chunk> 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); } } }
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 w w w .j av a 2s . c o 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; }