Skip to content

Commit

Permalink
GH-234 fix initial offset issue for TJ when leadup is obfuscated.
Browse files Browse the repository at this point in the history
  • Loading branch information
Patrick Corless committed Oct 14, 2023
1 parent ca94041 commit 8540fd8
Showing 1 changed file with 28 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,7 @@ public static void writeTj(ByteArrayOutputStream contentOutputStream, ArrayList<

for (int i = 0, max = glyphTexts.size(); i < max; i++) {
glyphText = glyphTexts.get(i);
if (!glyphText.isRedacted()) {
if (operatorCount == 0) {
writeDelimiterStart(glyphText, contentOutputStream);
}
operatorCount++;
writeCharacterCode(glyphText, contentOutputStream);
} else if (glyphText.isRedacted()) {
if (glyphText.isRedacted()) {
if (operatorCount > 0) {
operatorCount = 0;
// close off the current string object
Expand All @@ -77,6 +71,12 @@ public static void writeTj(ByteArrayOutputStream contentOutputStream, ArrayList<
contentOutputStream.write('0');
contentOutputStream.write(" Td".getBytes());
}
} else {
if (operatorCount == 0) {
writeDelimiterStart(glyphText, contentOutputStream);
}
operatorCount++;
writeCharacterCode(glyphText, contentOutputStream);
}
}
if (operatorCount > 0) {
Expand All @@ -99,6 +99,7 @@ public static void writeTJ(ByteArrayOutputStream contentOutputStream, ArrayList<

// can skip it completely
if (fullyRedacted(glyphTexts)) {
operatorCount++;
continue;
}

Expand All @@ -108,23 +109,7 @@ public static void writeTJ(ByteArrayOutputStream contentOutputStream, ArrayList<
int glyphWrittenCount = 0;
for (int j = 0, glyphTextMax = glyphTexts.size(); j < glyphTextMax; j++) {
glyphText = glyphTexts.get(j);
if (!glyphText.isRedacted()) {
if (j == 0 && operatorCount > 1) {
float advance = glyphText.getX();
float delta = advance - lastTdOffset;
lastTdOffset = advance;
contentOutputStream.write(' ');
contentOutputStream.write(String.valueOf(delta).getBytes());
contentOutputStream.write(' ');
contentOutputStream.write('0');
contentOutputStream.write(" Td ".getBytes());
}
if (glyphWrittenCount == 0) {
writeDelimiterStart(glyphText, contentOutputStream);
}
glyphWrittenCount++;
writeCharacterCode(glyphText, contentOutputStream);
} else if (glyphText.isRedacted()) {
if (glyphText.isRedacted()) {
if (glyphWrittenCount > 0) {
glyphWrittenCount = 0;
// close off the current string object
Expand All @@ -141,6 +126,22 @@ public static void writeTJ(ByteArrayOutputStream contentOutputStream, ArrayList<
contentOutputStream.write('0');
contentOutputStream.write(" Td ".getBytes());
}
} else {
if (j == 0 && operatorCount > 1) {
float advance = glyphText.getX();
float delta = advance - lastTdOffset;
lastTdOffset = advance;
contentOutputStream.write(' ');
contentOutputStream.write(String.valueOf(delta).getBytes());
contentOutputStream.write(' ');
contentOutputStream.write('0');
contentOutputStream.write(" Td ".getBytes());
}
if (glyphWrittenCount == 0) {
writeDelimiterStart(glyphText, contentOutputStream);
}
glyphWrittenCount++;
writeCharacterCode(glyphText, contentOutputStream);
}
}
if (glyphWrittenCount > 0) {
Expand All @@ -158,6 +159,9 @@ public static void writeTJ(ByteArrayOutputStream contentOutputStream, ArrayList<
}

private static void writeCharacterCode(GlyphText glyphText, ByteArrayOutputStream contentOutputStream) throws IOException {
// todo maybe avoid simpl/cid and just go with the StringObject type, and use the byte length in the wrapper
// or keep the parent StringObject and get it write the bytes as it has all the info as to how it was parse?
// probably a bit of both. When we get to variable bye hex strings things get harder to define generically
if (glyphText.getFontSubTypeFormat() == Font.SIMPLE_FORMAT) {
writeSimpleCharacterCode(glyphText, contentOutputStream);
} else {
Expand Down

0 comments on commit 8540fd8

Please sign in to comment.