Skip to content

Commit

Permalink
GH-182 further refinement for text selection regressions.
Browse files Browse the repository at this point in the history
  • Loading branch information
Patrick Corless committed Apr 27, 2021
1 parent b9acbd2 commit 6c90fae
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,10 @@ protected void parseWidth() {
font = font.deriveFont(newWidth, firstchar, missingWidth, ascent, descent, bbox, null);
}
// currently not using afm, instead using font's width table, seems more reliable
else if (afm != null) {
else if (afm != null && !isFontSubstitution) {
font = font.deriveFont(afm.getWidths(), firstchar, missingWidth, ascent, descent, bbox, null);
} else if (bbox != null) {
font = font.deriveFont(new float[0], firstchar, missingWidth, ascent, descent, bbox, null);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,9 @@ public FontFile deriveFont(float[] widths, int firstCh, float missingWidth, floa
font.firstCh = firstCh;
font.ascent = ascent;
font.descent = descent;
font.widths = widths;
if (widths != null && widths.length > 0) {
font.widths = widths;
}
font.cMap = diff;
font.bbox = bbox;
font.maxCharBounds = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,9 @@ public FontFile deriveFont(float[] widths, int firstCh, float missingWidth, floa
font.firstCh = firstCh;
font.ascent = ascent;
font.descent = descent;
font.widths = widths;
if (widths != null && widths.length > 0) {
font.widths = widths;
}
font.cMap = diff != null ? diff : font.cMap;
font.bbox = bbox;
font.maxCharBounds = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,9 @@ public FontFile deriveFont(float[] widths, int firstCh, float missingWidth, floa
font.firstCh = firstCh;
font.ascent = ascent;
font.descent = descent;
font.widths = widths;
if (widths != null && widths.length > 0) {
font.widths = widths;
}
font.cMap = diff != null ? diff : font.cMap;
font.bbox = bbox;
return font;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ public Point2D getAdvance(char ech) {

@Override
protected String codeToName(String estr) {
// might be able to blow this out out some point, but we're in the weeds at this point, not
// a lot of good examples.
// This isn't quite right yet. But if we are using the standard encoding as set in the TypeFont class
// use the font's internal encoding.
if (org.icepdf.core.pobjects.fonts.zfont.Encoding.STANDARD_ENCODING_NAME.equals(encoding.getName())) {
return cffType1Font.getEncoding().getName(estr.charAt(0));
} else {
Expand Down Expand Up @@ -95,7 +95,9 @@ public FontFile deriveFont(float[] widths, int firstCh, float missingWidth, floa
font.firstCh = firstCh;
font.ascent = ascent;
font.descent = descent;
font.widths = widths;
if (widths != null && widths.length > 0) {
font.widths = widths;
}
font.cMap = diff != null ? diff : font.cMap;
font.bbox = bbox;
font.maxCharBounds = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,9 @@ public FontFile deriveFont(float[] widths, int firstCh, float missingWidth, floa
font.descent = descent;
font.cMap = diff;
font.bbox = bbox;
if (widths != null && widths.length > 0) {
font.widths = widths;
}
font.maxCharBounds = null;
return font;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,9 @@ public FontFile deriveFont(Encoding encoding, CMap toUnicode) {
public FontFile deriveFont(float[] widths, int firstCh, float missingWidth, float ascent, float descent, Rectangle2D bbox, char[] diff) {
ZFontType3 font = (ZFontType3) deriveFont(this.size);
font.encoding = encoding;
font.widths = widths;
if (widths != null && widths.length > 0) {
font.widths = widths;
}
font.firstCh = firstCh;
font.missingWidth = missingWidth;
font.ascent = ascent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ public double getAscent() {
if (maxCharBounds == null) {
maxCharBounds = getMaxCharBounds();
}
return -maxCharBounds.getY();
return maxCharBounds.getY();
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,11 @@ public GlyphText addText(String cid, String unicode, float x, float y, float wid
Rectangle2D.Float glyphBounds;
// negative layout
if (width < 0.0f || font.getSize() < 0) {
glyphBounds = new Rectangle2D.Float(x + width, y - (descent), w, h);
glyphBounds = new Rectangle2D.Float(x + width, y - descent, w, h);
}
// inverted layout
else if (font.getFontTransform() != null && font.getFontTransform().getScaleY() < 0) {
glyphBounds = new Rectangle2D.Float(x, y - height - descent, w, h);
glyphBounds = new Rectangle2D.Float(x, y - height, w, h);
}
// standard layout.
else {
Expand Down

0 comments on commit 6c90fae

Please sign in to comment.