Skip to content

Commit

Permalink
GH-80 fix some toUnicode parsing issues and working a problem with fo…
Browse files Browse the repository at this point in the history
…nt bounding box which is causing some text selection and extraction issues.
  • Loading branch information
Patrick Corless committed Mar 4, 2021
1 parent 474bdd7 commit ab1e916
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public synchronized void init() {

parseDescendantFont();
findFontIfNotEmbedded();
parseToUnicode();
parseEncoding();

inited = true;
Expand All @@ -48,7 +49,7 @@ protected void parseEncoding() {
if (name != null) {
cMap = CMap.getInstance(name);
Encoding encoding = Encoding.getInstance((name).getName());
font = font.deriveFont(encoding, cMap);
font = font.deriveFont(encoding, toUnicodeCMap);
}
if (cMap != null) {
isCMapPredefined = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ protected ZFontTrueType(ZFontTrueType font) {
this.cmapMacRoman = font.cmapMacRoman;
this.horizontalMetricsTable = font.horizontalMetricsTable;
this.fontMatrix = convertFontMatrix(fontBoxFont);
font.missingWidth = this.missingWidth;
}

@Override
Expand Down Expand Up @@ -197,7 +198,6 @@ public FontFile deriveFont(Encoding encoding, CMap toUnicode) {
@Override
public FontFile deriveFont(float[] widths, int firstCh, float missingWidth, float ascent, float descent, Rectangle2D bbox, char[] diff) {
ZFontTrueType font = new ZFontTrueType(this);
font.missingWidth = this.missingWidth;
font.firstCh = firstCh;
font.ascent = ascent;
font.descent = descent;
Expand All @@ -210,7 +210,7 @@ public FontFile deriveFont(float[] widths, int firstCh, float missingWidth, floa
@Override
public FontFile deriveFont(Map<Integer, Float> widths, int firstCh, float missingWidth, float ascent, float descent, Rectangle2D bbox, char[] diff) {
ZFontTrueType font = new ZFontTrueType(this);
font.missingWidth = this.missingWidth;
// todo why aren't we doing anything with widths?????
font.firstCh = firstCh;
font.ascent = ascent;
font.descent = descent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,41 +139,28 @@ public Type2CharString getType2CharString(int cid) throws IOException {

@Override
public FontFile deriveFont(AffineTransform at) {
// if (cidFont != null) {
ZFontType0 font = new ZFontType0(this);
font.setFontTransform(at);
return font;
// } else {
// return this;
// }
}

@Override
public FontFile deriveFont(float pointSize) {
// if (cidFont != null) {
ZFontType0 font = new ZFontType0(this);
font.setPointSize(pointSize);
return font;
// } else {
// return this;
// }
}

@Override
public FontFile deriveFont(Encoding encoding, CMap toUnicode) {
// if (cidFont != null) {
ZFontType0 font = new ZFontType0(this);
font.encoding = encoding;
font.toUnicode = toUnicode;
return font;
// } else {
// return this;
// }
}

@Override
public FontFile deriveFont(float[] widths, int firstCh, float missingWidth, float ascent, float descent, Rectangle2D bbox, char[] diff) {
// if (cidFont != null) {
ZFontType0 font = new ZFontType0(this);
font.missingWidth = this.missingWidth;
font.firstCh = firstCh;
Expand All @@ -183,9 +170,6 @@ public FontFile deriveFont(float[] widths, int firstCh, float missingWidth, floa
font.cMap = diff != null ? diff : font.cMap;
font.bbox = calculateBbox(bbox);
return font;
// } else {
// return this;
// }
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ public FontFile deriveFont(AffineTransform at) {
public FontFile deriveFont(float pointSize) {
ZFontType2 font = new ZFontType2(this);
font.setPointSize(pointSize);
// todo further investigation to try and get text selection bounds working correctly
// font.bbox = calculateBbox(bbox);
return font;
}

Expand All @@ -149,13 +151,22 @@ public FontFile deriveFont(Encoding encoding, CMap toUnicode) {
@Override
public FontFile deriveFont(float[] widths, int firstCh, float missingWidth, float ascent, float descent, Rectangle2D bbox, char[] diff) {
ZFontType2 font = new ZFontType2(this);
font.firstCh = firstCh;
font.ascent = ascent;
font.descent = descent;
font.cMap = diff;
font.bbox = calculateBbox(bbox);
return font;
}

@Override
public FontFile deriveFont(Map<Integer, Float> widths, int firstCh, float missingWidth, float ascent, float descent, Rectangle2D bbox, char[] diff) {
ZFontType2 font = new ZFontType2(this);
// todo widths array, have worked this inanother class, maybe not be applicable here?
font.firstCh = firstCh;
font.ascent = ascent;
font.descent = descent;
font.cMap = diff;
font.bbox = calculateBbox(bbox);
return font;
}

Expand Down Expand Up @@ -199,9 +210,7 @@ public String getName() {
}

private void setCID(CMap cid, CMap uni) {
cid2gid = cid != null ? cid : null;//ur_.c2g_;
// touni_ = uni != null ? uni : /*c2g_==ur_.c2g_? CMap.IDENTITY:=>same as default*/ CMap.IDENTITY;
// spacech_ = Integer.MIN_VALUE;
cid2gid = cid != null ? cid : null;
}

private int getCharToGid(char character) {
Expand All @@ -221,9 +230,6 @@ public int codeToGID(int code) {
if (cid2gid != null) {
return cid2gid.toSelector((char) code);
}
// else {
// return super.codeToGID(code);
// }
return code;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public void drawEstring(Graphics2D g, String estr, float x, float y, long layout

@Override
public Rectangle2D getMaxCharBounds() {
return new Rectangle2D.Double(0.0, 0.0, 1.0, 1.0);
return bbox;
}

@Override
Expand Down

0 comments on commit ab1e916

Please sign in to comment.