Skip to content

Commit

Permalink
Text.java: Use getFontDescriptor() from PDCIDFont, as well as PDSimpl…
Browse files Browse the repository at this point in the history
…eFont.
  • Loading branch information
kjw committed Jul 1, 2010
1 parent 7b88e7d commit 42c0732
Showing 1 changed file with 20 additions and 12 deletions.
32 changes: 20 additions & 12 deletions src/org/crossref/pdf2xml/data/Text.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.io.IOException;

import org.apache.pdfbox.pdmodel.font.PDCIDFont;
import org.apache.pdfbox.pdmodel.font.PDFont;
import org.apache.pdfbox.pdmodel.font.PDSimpleFont;
import org.apache.pdfbox.pdmodel.graphics.PDGraphicsState;
Expand Down Expand Up @@ -130,26 +131,33 @@ public float getDescent() {
}

private static float getAscent(PDFont font, float fontSize) {
if (font instanceof PDSimpleFont) {
try {
PDSimpleFont simpleFont = (PDSimpleFont) font;
return (simpleFont.getFontDescriptor().getAscent() / 1000) * fontSize;
} catch (IOException e) {
// fall through
}
try {
if (font instanceof PDSimpleFont) {
PDSimpleFont simpleFont = (PDSimpleFont) font;
return (simpleFont.getFontDescriptor().getAscent() / 1000) * fontSize;
} else if (font instanceof PDCIDFont) {
PDCIDFont cidFont = (PDCIDFont) font;
return (cidFont.getFontDescriptor().getAscent() / 1000) * fontSize;
}
} catch (IOException e) {
// fall through
}
return 0.0f;
}

private static float getDescent(PDFont font, float fontSize) {
if (font instanceof PDSimpleFont) {
try {
System.out.println(font);
try {
if (font instanceof PDSimpleFont) {
PDSimpleFont simpleFont = (PDSimpleFont) font;
return (-Math.abs(simpleFont.getFontDescriptor().getDescent()) / 1000) * fontSize;
} catch (IOException e) {
// fall through
} else if (font instanceof PDCIDFont) {
PDCIDFont cidFont = (PDCIDFont) font;
return (-Math.abs(cidFont.getFontDescriptor().getDescent()) / 1000) * fontSize;
}
}
} catch (IOException e) {
// fall through
}
return 0.0f;
}

Expand Down

0 comments on commit 42c0732

Please sign in to comment.