Uploaded image for project: 'PDFBox'
  1. PDFBox
  2. PDFBOX-611

PDSimpleFont. Font height reported as zero.

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 0.8.0-incubator
    • 1.7.0
    • PDModel
    • Win and Linux

    Description

      The logic for PDSimpleFont.getFontHeight() can return a value of zero.
      This will corrupt or compromise text extraction and layout.
      In particular, test with 'http://www.encana.com/investor/financial/shareholder/pdfs/info-circular-french.pdf', pg 12

      When a PDFontDescriptor is used, the current logic uses:
      1) an average of xHeight and capHeight.
      xHeight is the height from the baseline to the top of a lower case letter like 'x'.
      CapHeight is the height from the baseline to the top of an upper case latin char.
      2) xHeight
      3) capHeight
      4) ascent
      5) zero

      This is really bizarre. 'xHeight' is an optional parameter, and 'capHeight' is often missing.

      The font bounding box is a required parameter and is the height that is used by Acrobat Reader when you select a line of text.
      The bounding box is not perfect, because it often overlaps the line above, but it is a consistent value. The problem with the
      current logic is that the reported height varies way too much, and a zero value can be reported.

      I have modified the logic as follows. The goal was to make the nominal values the same as the current logic,
      but return a very similar number when parameters go missing.

      PDFontDescriptor desc = getFontDescriptor();
      if( desc != null ) {
      float height = desc.getCapHeight(); // Top of Cap to baseline (eg 715)
      if (height==0) {
      height=desc.getAscent(); // Max height from baseline (eg 715);
      if (height==0) {
      PDRectangle bbox = desc.getFontBoundingBox();
      height = bbox.getHeight()/2; // Max height less max depth (eg (1006-(-325))=1331/2=665)
      if (height==0)

      { height=desc.getXHeight(); // Top of lower-case to baseline (eg 518) height-=desc.getDescent(); // Depth below baseline (eg 209, to get total of 727) }

      }
      }
      retval=height;
      }

      Attachments

        Activity

          People

            lehmi Andreas Lehmkühler
            petercostello Peter Costello
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

                Estimated:
                Original Estimate - 1h
                1h
                Remaining:
                Remaining Estimate - 1h
                1h
                Logged:
                Time Spent - Not Specified
                Not Specified