Java Code Examples for com.lowagie.text.pdf.BaseFont#getFontDescriptor()

The following examples show how to use com.lowagie.text.pdf.BaseFont#getFontDescriptor() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BaseFontFontMetrics.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
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;
}
 
Example 2
Source File: MetaDo.java    From gcs with Mozilla Public License 2.0 4 votes vote down vote up
public void outputText(int x, int y, int flag, int x1, int y1, int x2, int y2, String text) {
    MetaFont font = state.getCurrentFont();
    float refX = state.transformX(x);
    float refY = state.transformY(y);
    float angle = state.transformAngle(font.getAngle());
    float sin = (float)Math.sin(angle);
    float cos = (float)Math.cos(angle);
    float fontSize = font.getFontSize(state);
    BaseFont bf = font.getFont();
    int align = state.getTextAlign();
    float textWidth = bf.getWidthPoint(text, fontSize);
    float tx = 0;
    float ty = 0;
    float descender = bf.getFontDescriptor(BaseFont.DESCENT, fontSize);
    float ury = bf.getFontDescriptor(BaseFont.BBOXURY, fontSize);
    cb.saveState();
    cb.concatCTM(cos, sin, -sin, cos, refX, refY);
    if ((align & MetaState.TA_CENTER) == MetaState.TA_CENTER)
        tx = -textWidth / 2;
    else if ((align & MetaState.TA_RIGHT) == MetaState.TA_RIGHT)
        tx = -textWidth;
    if ((align & MetaState.TA_BASELINE) == MetaState.TA_BASELINE)
        ty = 0;
    else if ((align & MetaState.TA_BOTTOM) == MetaState.TA_BOTTOM)
        ty = -descender;
    else
        ty = -ury;
    Color textColor;
    if (state.getBackgroundMode() == MetaState.OPAQUE) {
        textColor = state.getCurrentBackgroundColor();
        cb.setColorFill(textColor);
        cb.rectangle(tx, ty + descender, textWidth, ury - descender);
        cb.fill();
    }
    textColor = state.getCurrentTextColor();
    cb.setColorFill(textColor);
    cb.beginText();
    cb.setFontAndSize(bf, fontSize);
    cb.setTextMatrix(tx, ty);
    cb.showText(text);
    cb.endText();
    if (font.isUnderline()) {
        cb.rectangle(tx, ty - fontSize / 4, textWidth, fontSize / 15);
        cb.fill();
    }
    if (font.isStrikeout()) {
        cb.rectangle(tx, ty + fontSize / 3, textWidth, fontSize / 15);
        cb.fill();
    }
    cb.restoreState();
}
 
Example 3
Source File: MetaDo.java    From itext2 with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void outputText(int x, int y, int flag, int x1, int y1, int x2, int y2, String text) {
    MetaFont font = state.getCurrentFont();
    float refX = state.transformX(x);
    float refY = state.transformY(y);
    float angle = state.transformAngle(font.getAngle());
    float sin = (float)Math.sin(angle);
    float cos = (float)Math.cos(angle);
    float fontSize = font.getFontSize(state);
    BaseFont bf = font.getFont();
    int align = state.getTextAlign();
    float textWidth = bf.getWidthPoint(text, fontSize);
    float tx = 0;
    float ty = 0;
    float descender = bf.getFontDescriptor(BaseFont.DESCENT, fontSize);
    float ury = bf.getFontDescriptor(BaseFont.BBOXURY, fontSize);
    cb.saveState();
    cb.concatCTM(cos, sin, -sin, cos, refX, refY);
    if ((align & MetaState.TA_CENTER) == MetaState.TA_CENTER)
        tx = -textWidth / 2;
    else if ((align & MetaState.TA_RIGHT) == MetaState.TA_RIGHT)
        tx = -textWidth;
    if ((align & MetaState.TA_BASELINE) == MetaState.TA_BASELINE)
        ty = 0;
    else if ((align & MetaState.TA_BOTTOM) == MetaState.TA_BOTTOM)
        ty = -descender;
    else
        ty = -ury;
    Color textColor;
    if (state.getBackgroundMode() == MetaState.OPAQUE) {
        textColor = state.getCurrentBackgroundColor();
        cb.setColorFill(textColor);
        cb.rectangle(tx, ty + descender, textWidth, ury - descender);
        cb.fill();
    }
    textColor = state.getCurrentTextColor();
    cb.setColorFill(textColor);
    cb.beginText();
    cb.setFontAndSize(bf, fontSize);
    cb.setTextMatrix(tx, ty);
    cb.showText(text);
    cb.endText();
    if (font.isUnderline()) {
        cb.rectangle(tx, ty - fontSize / 4, textWidth, fontSize / 15);
        cb.fill();
    }
    if (font.isStrikeout()) {
        cb.rectangle(tx, ty + fontSize / 3, textWidth, fontSize / 15);
        cb.fill();
    }
    cb.restoreState();
}