public long getMaxHeight() { return getMaxAscent() + getMaxDescent() + getLeading(); }
public long getStrikeThroughPosition() { return getMaxAscent() - (long) ( LibFontsDefaults.DEFAULT_STRIKETHROUGH_POSITION * getXHeight() ); }
public long getUnderlinePosition() { return ( getLeading() + getMaxAscent() ) + Math.max( 1000, sizeScaled / 20 ); }
metaData.getBaseFontFontMetrics( fontName, fontSize, bold, italic, null, metaData .isFeatureSupported( OutputProcessorFeature.EMBED_ALL_FONTS ), false ); final FontNativeContext nativeContext = fontMetrics.getNativeContext(); lastBaseFont = fontMetrics.getBaseFont(); if ( fontMetrics.isTrueTypeFont() && bold && nativeContext.isNativeBold() == false ) { final float strokeWidth = font.getSize2D() / 30.0f; // right from iText ... if ( strokeWidth == 1 ) {
public BaselineInfo getBaselines( final int c, BaselineInfo info ) { if ( cachedBaselineInfo != null ) { if ( info == null ) { info = new BaselineInfo(); } info.update( cachedBaselineInfo ); return info; } if ( info == null ) { info = new BaselineInfo(); } // If we had more data, we could surely create something better. Well, this has to be enough .. final long maxAscent = getMaxAscent(); info.setBaseline( BaselineInfo.MATHEMATICAL, maxAscent - getXHeight() ); info.setBaseline( BaselineInfo.IDEOGRAPHIC, getMaxHeight() ); info.setBaseline( BaselineInfo.MIDDLE, maxAscent / 2 ); info.setBaseline( BaselineInfo.ALPHABETIC, maxAscent ); info.setBaseline( BaselineInfo.CENTRAL, maxAscent / 2 ); info.setBaseline( BaselineInfo.HANGING, maxAscent - getXHeight() ); info.setDominantBaseline( BaselineInfo.ALPHABETIC ); final BaselineInfo cached = new BaselineInfo(); cached.update( info ); cachedBaselineInfo = cached; return info; }
public void add( final String text ) { int style = Font.NORMAL; if ( bold ) { style |= Font.BOLD; } if ( italic ) { style |= Font.ITALIC; } if ( strikethrough ) { style |= Font.STRIKETHRU; } if ( underline ) { style |= Font.UNDERLINE; } final BaseFontFontMetrics fontMetrics = metaData.getBaseFontFontMetrics( fontName, fontSize, bold, italic, "utf-8", false, false ); final BaseFont baseFont = fontMetrics.getBaseFont(); final Font font = new Font( baseFont, (float) fontSize, style, textColor ); final Chunk c = new Chunk( text, font ); if ( backgroundColor != null ) { c.setBackground( backgroundColor ); } target.add( c ); } }
public long getOverlinePosition() { return getLeading() - Math.max( 1000, sizeScaled / 20 ); }
private int computeStyle( final TypedMapWrapper<Attribute, Object> attributes, final PdfTextSpec pdfTextSpec ) { final Float weight = attributes.get( TextAttribute.WEIGHT, TextAttribute.WEIGHT_REGULAR, Float.class ); final Float italics = attributes.get( TextAttribute.POSTURE, TextAttribute.POSTURE_OBLIQUE, Float.class ); final boolean underlined = attributes.exists( TextAttribute.UNDERLINE ); final boolean strikethrough = attributes.exists( TextAttribute.STRIKETHROUGH ); FontNativeContext nativeContext = pdfTextSpec.getFontMetrics().getNativeContext(); int style = 0; if ( nativeContext.isNativeBold() == false && weight >= TextAttribute.WEIGHT_DEMIBOLD ) { style |= Font.BOLD; } if ( nativeContext.isNativeItalics() == false && italics >= TextAttribute.POSTURE_OBLIQUE ) { style |= Font.ITALIC; } if ( underlined ) { style |= Font.UNDERLINE; } if ( strikethrough ) { style |= Font.STRIKETHRU; } return style; }
public BaseFontFontMetrics( final FontNativeContext record, final BaseFont baseFont, final float size ) { if ( baseFont == null ) { throw new NullPointerException( "BaseFont is invalid." ); } 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; }
( fontName, bold, italic, context.getEncoding(), context.isEmbedded() ); return new BaseFontFontMetrics ( new DefaultFontNativeContext( bold, italic ), baseFont, (float) context.getFontSize() );
cb.setFontAndSize( fontMetrics.getBaseFont(), fontSize ); } else { cb = textSpec.getContentByte(); final BaseFont baseFont = baseFontRecord.getBaseFont(); final float ascent; if ( legacyLineHeightCalc ) { final float translateX = (float) affineTransform.getTranslateX(); final FontNativeContext nativeContext = baseFontRecord.getNativeContext(); if ( baseFontRecord.isTrueTypeFont() && textSpec.isBold() && nativeContext.isNativeBold() == false ) { final float strokeWidth = textSpec.getFontSize() / 30.0f; // right from iText ... if ( strokeWidth == 1 ) { if ( baseFontRecord.isTrueTypeFont() && textSpec.isItalics() && nativeContext.isNativeItalics() == false ) { final float italicAngle = baseFont.getFontDescriptor( BaseFont.ITALICANGLE, textSpec.getFontSize() ); if ( italicAngle == 0 ) {
private Phrase createPhrase( final RenderableComplexText node ) { Phrase p = new Phrase(); RichTextSpec text = node.getRichText(); for ( RichTextSpec.StyledChunk c : text.getStyleChunks() ) { TypedMapWrapper<Attribute, Object> attributes = new TypedMapWrapper<Attribute, Object>( c.getAttributes() ); final Number size = attributes.get( TextAttribute.SIZE, 10f, Number.class ); final PdfTextSpec pdfTextSpec = computeFont( c ); final int style = computeStyle( attributes, pdfTextSpec ); final Color paint = (Color) c.getStyleSheet().getStyleProperty( ElementStyleKeys.PAINT ); // add chunks BaseFont baseFont = pdfTextSpec.getFontMetrics().getBaseFont(); Font font = new Font( baseFont, size.floatValue(), style, paint ); if ( c.getOriginatingTextNode() instanceof RenderableReplacedContentBox ) { RenderableReplacedContentBox content = (RenderableReplacedContentBox) c.getOriginatingTextNode(); com.lowagie.text.Image image = imageHandler.createImage( content ); if ( image != null ) { Chunk chunk = new Chunk( image, 0, 0 ); // chunk.setFont(font); p.add( chunk ); } } else { String textToPrint = c.getText(); Chunk chunk = new Chunk( textToPrint, font ); p.add( chunk ); } } return p; }