List of usage examples for com.lowagie.text.pdf BaseFont FONT_TYPE_TTUNI
int FONT_TYPE_TTUNI
To view the source code for com.lowagie.text.pdf BaseFont FONT_TYPE_TTUNI.
Click Source Link
From source file:org.eclipse.birt.report.engine.emitter.pdf.PDFPage.java
License:Open Source License
private void drawText(String text, float textX, float textY, FontInfo fontInfo, float characterSpacing, float wordSpacing, Color color, CSSValue align) { contentByte.saveState();/*from w w w . j a v a 2 s. co m*/ // start drawing the text content contentByte.beginText(); if (null != color && !Color.BLACK.equals(color)) { contentByte.setColorFill(color); contentByte.setColorStroke(color); } BaseFont font = getBaseFont(fontInfo); float fontSize = fontInfo.getFontSize(); try { contentByte.setFontAndSize(font, fontSize); } catch (IllegalArgumentException e) { logger.log(Level.WARNING, e.getMessage()); // close to zero , increase by one MIN_FONT_SIZE step contentByte.setFontAndSize(font, MIN_FONT_SIZE * 2); } if (characterSpacing != 0) { contentByte.setCharacterSpacing(characterSpacing); } if (wordSpacing != 0) { contentByte.setWordSpacing(wordSpacing); } setTextMatrix(contentByte, fontInfo, textX, transformY(textY, 0, containerHeight)); if ((font.getFontType() == BaseFont.FONT_TYPE_TTUNI) && IStyle.JUSTIFY_VALUE.equals(align) && wordSpacing > 0) { int idx = text.indexOf(' '); if (idx >= 0) { float spaceCorrection = -wordSpacing * 1000 / fontSize; PdfTextArray textArray = new PdfTextArray(text.substring(0, idx)); int lastIdx = idx; while ((idx = text.indexOf(' ', lastIdx + 1)) >= 0) { textArray.add(spaceCorrection); textArray.add(text.substring(lastIdx, idx)); lastIdx = idx; } textArray.add(spaceCorrection); textArray.add(text.substring(lastIdx)); contentByte.showText(textArray); } else { contentByte.showText(text); } } else { contentByte.showText(text); } contentByte.endText(); contentByte.restoreState(); }
From source file:org.pentaho.reporting.libraries.fonts.itext.BaseFontFontMetrics.java
License:Open Source License
public BaseFontFontMetrics(final FontNativeContext record, final BaseFont baseFont, final float size) { if (baseFont == null) { throw new NullPointerException("BaseFont is invalid."); }/* www . ja va 2 s. co m*/ this.record = record; this.baseFont = baseFont; this.size = size; this.cpBuffer = new char[4]; this.cachedWidths = new long[256 - 32]; Arrays.fill(cachedWidths, -1); sizeScaled = FontStrictGeomUtility.toInternalValue(size); this.ascent = (long) baseFont.getFontDescriptor(BaseFont.AWT_ASCENT, sizeScaled); this.descent = (long) -baseFont.getFontDescriptor(BaseFont.AWT_DESCENT, sizeScaled); this.leading = (long) baseFont.getFontDescriptor(BaseFont.AWT_LEADING, sizeScaled); italicsAngle = FontStrictGeomUtility .toInternalValue(baseFont.getFontDescriptor(BaseFont.ITALICANGLE, size)); maxAscent = (long) baseFont.getFontDescriptor(BaseFont.BBOXURY, sizeScaled); maxDescent = (long) -baseFont.getFontDescriptor(BaseFont.BBOXLLY, sizeScaled); maxCharAdvance = (long) baseFont.getFontDescriptor(BaseFont.AWT_MAXADVANCE, sizeScaled); final int[] charBBox = this.baseFont.getCharBBox('x'); if (charBBox != null) { this.xHeight = (long) (charBBox[3] * size); } if (this.xHeight == 0) { this.xHeight = getAscent() / 2; } this.trueTypeFont = baseFont.getFontType() == BaseFont.FONT_TYPE_TT || baseFont.getFontType() == BaseFont.FONT_TYPE_TTUNI; }