Skip to content

Commit

Permalink
Fixed garbled text
Browse files Browse the repository at this point in the history
  • Loading branch information
nao-ton committed Nov 14, 2023
1 parent 8f0b598 commit 52f6246
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions openpdf/src/main/java/com/lowagie/text/pdf/FontDetails.java
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ byte[] convertToBytes(String text, TextRenderingOptions options) {
private byte[] convertToBytesWithGlyphs(String text) throws UnsupportedEncodingException {
int len = text.length();
int[] metrics = null;
char[] glyph = new char[len];
int[] glyph = new int[len];
int i = 0;
for (int k = 0; k < len; ++k) {
int val;
Expand All @@ -257,10 +257,19 @@ private byte[] convertToBytesWithGlyphs(String text) throws UnsupportedEncodingE
Integer gl = m0;
if (!longTag.containsKey(gl))
longTag.put(gl, new int[]{m0, metrics[1], val});
glyph[i++] = (char)m0;
glyph[i++] = m0;
}
String s = new String(glyph, 0, i);
return s.getBytes(CJKFont.CJK_ENCODING);
return getCJKEncodingBytes(glyph, i);
}

private byte[] getCJKEncodingBytes(int[] glyph, int size) {
byte[] result = new byte[size * 2];
for (int i = 0; i < size; i++) {
int g = glyph[i];
result[i * 2] = (byte)(g >> 8);
result[i * 2 + 1] = (byte)(g & 0xFF);
}
return result;
}

byte[] convertToBytes(GlyphVector glyphVector) {
Expand Down

0 comments on commit 52f6246

Please sign in to comment.