Skip to content

Commit

Permalink
Merge pull request #281 from metanorma/fix/char_replacement
Browse files Browse the repository at this point in the history
patch from FOP-2529 applied, metanorma/mn-samples-plateau#168
  • Loading branch information
Intelligent2013 authored Sep 9, 2024
2 parents 6ae2ebb + 36adf80 commit b6c044a
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/main/java/org/apache/fop/fonts/MultiByteFont.java
Original file line number Diff line number Diff line change
Expand Up @@ -310,14 +310,16 @@ private int createPrivateUseMapping(int gi) {
* @return unicode scalar value
*/
// [TBD] - needs optimization, i.e., change from linear search to binary search
private int findCharacterFromGlyphIndex(int gi, boolean augment) {
private int findCharacterFromGlyphIndex(int gi, boolean augment, int origChar) {
int cc = 0;
for (CMapSegment segment : cmap) {
int s = segment.getGlyphStartIndex();
int e = s + (segment.getUnicodeEnd() - segment.getUnicodeStart());
if ((gi >= s) && (gi <= e)) {
cc = segment.getUnicodeStart() + (gi - s);
break;
if (origChar == -1 || cc == origChar) {
break;
}
}
}
if ((cc == 0) && augment) {
Expand All @@ -327,7 +329,7 @@ private int findCharacterFromGlyphIndex(int gi, boolean augment) {
}

private int findCharacterFromGlyphIndex(int gi) {
return findCharacterFromGlyphIndex(gi, true);
return findCharacterFromGlyphIndex(gi, true, -1);
}

protected BitSet getGlyphIndices() {
Expand Down Expand Up @@ -711,11 +713,13 @@ private GlyphSequence mapCharsToGlyphs(CharSequence cs, List associations) {
private CharSequence mapGlyphsToChars(GlyphSequence gs) {
int ng = gs.getGlyphCount();
int ccMissing = Typeface.NOT_FOUND;
int[] charArr = gs.getCharacterArray(false);
List<Character> chars = new ArrayList<Character>(gs.getUTF16CharacterCount());

for (int i = 0, n = ng; i < n; i++) {
int gi = gs.getGlyph(i);
int cc = findCharacterFromGlyphIndex(gi);
//int cc = findCharacterFromGlyphIndex(gi);
int cc = findCharacterFromGlyphIndex(gi, true, charArr[i]);
if ((cc == 0) || (cc > 0x10FFFF)) {
cc = ccMissing;
log.warn("Unable to map glyph index " + gi
Expand Down

0 comments on commit b6c044a

Please sign in to comment.