Skip to content

Commit

Permalink
Adding support of advanced typography LibrePDF#297
Browse files Browse the repository at this point in the history
  • Loading branch information
codecracker2014 authored Jan 20, 2020
1 parent a80ea5d commit 1ecae93
Showing 1 changed file with 37 additions and 21 deletions.
58 changes: 37 additions & 21 deletions openpdf/src/main/java/com/lowagie/text/pdf/FontDetails.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@

import java.awt.font.GlyphVector;
import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.*;

import com.lowagie.text.Utilities;
import com.lowagie.text.ExceptionConverter;
Expand Down Expand Up @@ -211,29 +211,18 @@ byte[] convertToBytes(String text) {
longTag.put(metrics[0], new int[]{metrics[0], metrics[1], ttu.getUnicodeDifferences(b[k] & 0xff)});
glyph[i++] = (char)metrics[0];
}
String s = new String(glyph, 0, i);
b = s.getBytes(CJKFont.CJK_ENCODING);

}
else {
for (int k = 0; k < len; ++k) {
int val;
if (Utilities.isSurrogatePair(text, k)) {
val = Utilities.convertToUtf32(text, k);
k++;
}
else {
val = text.charAt(k);
}
metrics = ttu.getMetricsTT(val);
if (metrics == null)
continue;
int m0 = metrics[0];
Integer gl = m0;
if (!longTag.containsKey(gl))
longTag.put(gl, new int[]{m0, metrics[1], val});
glyph[i++] = (char)m0;
String fileName = ((TrueTypeFontUnicode)getBaseFont()).fileName;
if (fileName!=null && fileName.length()>0 &&( fileName.contains(".ttf") || fileName.contains(".TTF"))){
return FopGlyphProcessor.convertToBytesWithGlyphs(ttu,text,fileName,longTag);
}else {
return convertToBytesWithGlyphs(text);
}
}
String s = new String(glyph, 0, i);
b = s.getBytes(CJKFont.CJK_ENCODING);
}
catch (UnsupportedEncodingException e) {
throw new ExceptionConverter(e);
Expand All @@ -243,7 +232,34 @@ byte[] convertToBytes(String text) {
}
return b;
}


private byte[] convertToBytesWithGlyphs(String text) throws UnsupportedEncodingException {
int len = text.length();
int[] metrics = null;
char[] glyph = new char[len];
int i = 0;
for (int k = 0; k < len; ++k) {
int val;
if (Utilities.isSurrogatePair(text, k)) {
val = Utilities.convertToUtf32(text, k);
k++;
}
else {
val = text.charAt(k);
}
metrics = ttu.getMetricsTT(val);
if (metrics == null)
continue;
int m0 = metrics[0];
Integer gl = m0;
if (!longTag.containsKey(gl))
longTag.put(gl, new int[]{m0, metrics[1], val});
glyph[i++] = (char)m0;
}
String s = new String(glyph, 0, i);
return s.getBytes(CJKFont.CJK_ENCODING);
}

byte[] convertToBytes(GlyphVector glyphVector) {
if (fontType != BaseFont.FONT_TYPE_TTUNI || symbolic) {
throw new UnsupportedOperationException("Only supported for True Type Unicode fonts");
Expand Down

0 comments on commit 1ecae93

Please sign in to comment.