List of usage examples for com.lowagie.text.pdf BaseFont DESCENT
int DESCENT
To view the source code for com.lowagie.text.pdf BaseFont DESCENT.
Click Source Link
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; }/*w w w. j a v a2s . 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.eclipse.birt.report.engine.emitter.odp.device.OdpPage.java
License:Open Source License
protected void drawText(String text, float textX, float textY, float baseline, float width, float height, TextStyle textStyle) {// w w w.jav a 2s . c o m // width of text is enlarged by 1 point because the text will be // automatically wrapped if the width of textbox equals to the width of // text exactly. FontInfo fontInfo = textStyle.getFontInfo(); float descend = fontInfo.getBaseFont().getFontDescriptor(BaseFont.DESCENT, fontInfo.getFontSize()); StyleEntry style = StyleBuilder.createEmptyStyleEntry(StyleConstant.TYPE_TEXT); style.setProperty(StyleConstant.DIRECTION_PROP, textStyle.getDirection()); style.setProperty(StyleConstant.COLOR_PROP, OdpUtil.getColorString(textStyle.getColor())); style.setProperty(StyleConstant.LETTER_SPACING, new FloatValue(FloatValue.CSS_PT, textStyle.getLetterSpacing() / PDFConstants.LAYOUT_TO_PDF_RATIO)); if (fontInfo != null) { BaseFont baseFont = fontInfo.getBaseFont(); String fontName = OdpUtil.getFontName(baseFont); style.setProperty(StyleConstant.FONT_FAMILY_PROP, fontName); style.setProperty(StyleConstant.FONT_SIZE_PROP, Double.valueOf(fontInfo.getFontSize())); if ((fontInfo.getFontStyle() & Font.BOLD) != 0) { style.setProperty(StyleConstant.FONT_WEIGHT_PROP, "bold"); } if ((fontInfo.getFontStyle() & Font.ITALIC) != 0) { style.setProperty(StyleConstant.FONT_STYLE_PROP, "italic"); } if (textStyle.isLinethrough()) { style.setProperty(StyleConstant.TEXT_LINE_THROUGH_PROP, true); } if (textStyle.isOverline()) { style.setProperty(StyleConstant.TEXT_OVERLINE_PROP, true); } if (textStyle.isUnderline()) { style.setProperty(StyleConstant.TEXT_UNDERLINE_PROP, true); } } // TODO: hyperlink context.addStyle(style); writer.drawText(text, textX, textY, width, height + descend * 0.6f, textFrameStyle, style, link); }
From source file:org.eclipse.birt.report.engine.emitter.ppt.PPTWriter.java
License:Open Source License
/** * Draws a chunk of text on the PPT.//from w w w . jav a 2s.c om * * @param text * the textArea to be drawn. * @param textX * the X position of the textArea relative to current page. * @param textY * the Y position of the textArea relative to current page. * @param width * the Width of the textArea * @param height * the height of the textArea * @param textStyle * the style of the textArea * @param link * the hyperlink of the textArea */ public void drawText(String text, float textX, float textY, float width, float height, TextStyle textStyle, HyperlinkDef link) { FontInfo fontInfo = textStyle.getFontInfo(); Color color = textStyle.getColor(); boolean rtl = textStyle.isRtl(); if (fontInfo == null) { return; } float descend = fontInfo.getBaseFont().getFontDescriptor(BaseFont.DESCENT, fontInfo.getFontSize()); height = height + descend * 0.6f; BaseFont baseFont = fontInfo.getBaseFont(); String fontName = getFontName(baseFont); println("<v:shape id=3D\"_x0000_s" + (++shapeCount) + "\" type=3D\"#_x0000_t202\""); //$NON-NLS-1$ //$NON-NLS-2$ println(" style=3D'position:absolute;left:" + textX + "pt;top:" + textY + "pt;width:" + width + "pt;height:" //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$//$NON-NLS-4$ + height + "pt;v-text-anchor:bottom-baseline;mso-wrap-style:none;'"); //$NON-NLS-1$ println(" filled=3D'f' stroked=3D'f'>"); //$NON-NLS-1$ println("<v:textbox style=3D'mso-fit-shape-to-text:f;' inset=3D'0.00pt 0.00pt 0.00pt 0.00pt'/>"); //$NON-NLS-1$ println("</v:shape>"); //$NON-NLS-1$ println("<div v:shape=3D\"_x0000_s" + shapeCount + "\">"); //$NON-NLS-1$ //$NON-NLS-2$ println("<div style=3D'mso-text-indent-alt:" //$NON-NLS-1$ + 0 + ";text-align:left;'>" //$NON-NLS-1$ + "<span style=3D'font-family:" //$NON-NLS-1$ + fontName + ";font-size:" //$NON-NLS-1$ + fontInfo.getFontSize() + "pt;color:#" //$NON-NLS-1$ + getColorString(color) + ";'" + buildI18nAttributes(text, rtl) + ">"); //$NON-NLS-2$ boolean isItalic = fontInfo != null && (fontInfo.getFontStyle() & Font.ITALIC) != 0; boolean isBold = fontInfo != null && (fontInfo.getFontStyle() & Font.BOLD) != 0; boolean isUnderline = textStyle.isUnderline(); if (isItalic) { print("<i>"); } if (isBold) { print("<b>"); } if (isUnderline) { print("<u>"); } if (link != null) { String hyperlink = link.getLink(); String tooltip = link.getTooltip(); if (hyperlink != null) { hyperlink = codeLink(hyperlink); print("<p:onmouseclick hyperlinktype=3D\"url\" href=3D\"" + hyperlink + "\""); if (tooltip != null) { tooltip = codeLink(tooltip); print(" tips=3D\"" + tooltip + "\""); } println("/><a href=3D\"" + hyperlink + "/\" target=3D\"_parent\" onclick=3D\"window.event.cancelBubble=3Dtrue;\">"); } } print(getEscapedStr(text)); if (link != null) { print("</a>"); } if (isUnderline) { print("</u>"); } if (isBold) { print("</b>"); } if (isItalic) { print("</i>"); } println("</span></div>"); //$NON-NLS-1$ println("</div>"); //$NON-NLS-1$ }
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 . java 2s . 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; }