Example usage for org.apache.pdfbox.text TextPosition getFontSizeInPt

List of usage examples for org.apache.pdfbox.text TextPosition getFontSizeInPt

Introduction

In this page you can find the example usage for org.apache.pdfbox.text TextPosition getFontSizeInPt.

Prototype

public float getFontSizeInPt() 

Source Link

Document

This will get the font size in pt.

Usage

From source file:com.tekstosense.segmenter.data.Text.java

License:Open Source License

public static Text newFor(TextPosition tp, PDGraphicsState gs, String text) {
    Text t = new Text();
    t.x = tp.getXDirAdj();/*from w w  w .  j av a 2s .  c  om*/
    t.baseline = tp.getYDirAdj();
    t.font = tp.getFont();
    t.strokeColor = gs.getStrokingColor();
    t.nonStrokeColor = gs.getNonStrokingColor();
    t.run = tp.getUnicode();
    t.width = tp.getWidth();
    t.height = tp.getHeight();
    t.pointSize = tp.getFontSizeInPt();
    t.fontSize = tp.getYScale();
    t.tempRun = t.run;

    // Bump the width by the word spacing for each space in tp.
    /*      for (int i=0; i<tp.getCharacter().length(); i++) {
              Character c = tp.getCharacter().charAt(i);
              if (c.equals(" ")) {
    t.width -= tp.getWidthOfSpace();
      t.width += tp.getWordSpacing();
              }
          }
    */
    return t;
}

From source file:org.fit.pdfdom.PDFBoxTree.java

License:Open Source License

/**
 * Updates the text style according to a new text position
 * @param bstyle the style to be updated
 * @param text the text position/*from   w  w  w .ja v a 2s .co m*/
 */
protected void updateStyle(BoxStyle bstyle, TextPosition text) {
    String font = text.getFont().getName();
    String family = null;
    String weight = null;
    String fstyle = null;

    bstyle.setFontSize(text.getFontSizeInPt());
    bstyle.setLineHeight(text.getHeight());

    if (font != null) {
        //font style and weight
        for (int i = 0; i < pdFontType.length; i++) {
            if (font.toLowerCase().lastIndexOf(pdFontType[i]) >= 0) {
                weight = cssFontWeight[i];
                fstyle = cssFontStyle[i];
                break;
            }
        }
        if (weight != null)
            bstyle.setFontWeight(weight);
        else
            bstyle.setFontWeight(cssFontWeight[0]);
        if (fstyle != null)
            bstyle.setFontStyle(fstyle);
        else
            bstyle.setFontStyle(cssFontStyle[0]);

        //font family
        //If it's a known common font don't embed in html output to save space
        String knownFontFamily = findKnownFontFamily(font);
        if (!knownFontFamily.equals(""))
            family = knownFontFamily;
        else {
            family = fontTable.getUsedName(font);
            if (family == null)
                family = font;
        }

        if (family != null)
            bstyle.setFontFamily(family);
    }

    updateStyleForRenderingMode();
}