| Method from com.lowagie.text.pdf.CJKFont Detail: |
public boolean charExists(int c) {
return translationMap[c] != 0;
}
Checks if a character exists in this font. |
static String convertToHCIDMetrics(int[] keys,
IntHashtable h) {
if (keys.length == 0)
return null;
int lastCid = 0;
int lastValue = 0;
int start;
for (start = 0; start < keys.length; ++start) {
lastCid = keys[start];
lastValue = h.get(lastCid);
if (lastValue != 0) {
++start;
break;
}
}
if (lastValue == 0)
return null;
StringBuffer buf = new StringBuffer();
buf.append('[");
buf.append(lastCid);
int state = FIRST;
for (int k = start; k < keys.length; ++k) {
int cid = keys[k];
int value = h.get(cid);
if (value == 0)
continue;
switch (state) {
case FIRST: {
if (cid == lastCid + 1 && value == lastValue) {
state = SERIAL;
}
else if (cid == lastCid + 1) {
state = BRACKET;
buf.append('[").append(lastValue);
}
else {
buf.append('[").append(lastValue).append(']").append(cid);
}
break;
}
case BRACKET: {
if (cid == lastCid + 1 && value == lastValue) {
state = SERIAL;
buf.append(']").append(lastCid);
}
else if (cid == lastCid + 1) {
buf.append(' ").append(lastValue);
}
else {
state = FIRST;
buf.append(' ").append(lastValue).append(']").append(cid);
}
break;
}
case SERIAL: {
if (cid != lastCid + 1 || value != lastValue) {
buf.append(' ").append(lastCid).append(' ").append(lastValue).append(' ").append(cid);
state = FIRST;
}
break;
}
}
lastValue = value;
lastCid = cid;
}
switch (state) {
case FIRST: {
buf.append('[").append(lastValue).append("]]");
break;
}
case BRACKET: {
buf.append(' ").append(lastValue).append("]]");
break;
}
case SERIAL: {
buf.append(' ").append(lastCid).append(' ").append(lastValue).append(']");
break;
}
}
return buf.toString();
}
|
static String convertToVCIDMetrics(int[] keys,
IntHashtable v,
IntHashtable h) {
if (keys.length == 0)
return null;
int lastCid = 0;
int lastValue = 0;
int lastHValue = 0;
int start;
for (start = 0; start < keys.length; ++start) {
lastCid = keys[start];
lastValue = v.get(lastCid);
if (lastValue != 0) {
++start;
break;
}
else
lastHValue = h.get(lastCid);
}
if (lastValue == 0)
return null;
if (lastHValue == 0)
lastHValue = 1000;
StringBuffer buf = new StringBuffer();
buf.append('[");
buf.append(lastCid);
int state = FIRST;
for (int k = start; k < keys.length; ++k) {
int cid = keys[k];
int value = v.get(cid);
if (value == 0)
continue;
int hValue = h.get(lastCid);
if (hValue == 0)
hValue = 1000;
switch (state) {
case FIRST: {
if (cid == lastCid + 1 && value == lastValue && hValue == lastHValue) {
state = SERIAL;
}
else {
buf.append(' ").append(lastCid).append(' ").append(-lastValue).append(' ").append(lastHValue / 2).append(' ").append(V1Y).append(' ").append(cid);
}
break;
}
case SERIAL: {
if (cid != lastCid + 1 || value != lastValue || hValue != lastHValue) {
buf.append(' ").append(lastCid).append(' ").append(-lastValue).append(' ").append(lastHValue / 2).append(' ").append(V1Y).append(' ").append(cid);
state = FIRST;
}
break;
}
}
lastValue = value;
lastCid = cid;
lastHValue = hValue;
}
buf.append(' ").append(lastCid).append(' ").append(-lastValue).append(' ").append(lastHValue / 2).append(' ").append(V1Y).append(" ]");
return buf.toString();
}
|
static IntHashtable createMetric(String s) {
IntHashtable h = new IntHashtable();
StringTokenizer tk = new StringTokenizer(s);
while (tk.hasMoreTokens()) {
int n1 = Integer.parseInt(tk.nextToken());
h.put(n1, Integer.parseInt(tk.nextToken()));
}
return h;
}
|
public String[][] getAllNameEntries() {
return new String[][]{{"4", "", "", "", fontName}};
}
Gets all the entries of the names-table. If it is a True Type font
each array element will have {Name ID, Platform ID, Platform Encoding ID,
Language ID, font name}. The interpretation of this values can be
found in the Open Type specification, chapter 2, in the 'name' table.
For the other fonts the array has a single element with {"4", "", "", "",
font name}. |
public int[] getCharBBox(int c) {
return null;
}
|
public int getCidCode(int c) {
if (cidDirect)
return c;
return translationMap[c];
}
|
public String[][] getFamilyFontName() {
return getFullFontName();
}
Gets the family name of the font. If it is a True Type font
each array element will have {Platform ID, Platform Encoding ID,
Language ID, font name}. The interpretation of this values can be
found in the Open Type specification, chapter 2, in the 'name' table.
For the other fonts the array has a single element with {"", "", "",
font name}. |
public float getFontDescriptor(int key,
float fontSize) {
switch (key) {
case AWT_ASCENT:
case ASCENT:
return getDescNumber("Ascent") * fontSize / 1000;
case CAPHEIGHT:
return getDescNumber("CapHeight") * fontSize / 1000;
case AWT_DESCENT:
case DESCENT:
return getDescNumber("Descent") * fontSize / 1000;
case ITALICANGLE:
return getDescNumber("ItalicAngle");
case BBOXLLX:
return fontSize * getBBox(0) / 1000;
case BBOXLLY:
return fontSize * getBBox(1) / 1000;
case BBOXURX:
return fontSize * getBBox(2) / 1000;
case BBOXURY:
return fontSize * getBBox(3) / 1000;
case AWT_LEADING:
return 0;
case AWT_MAXADVANCE:
return fontSize * (getBBox(2) - getBBox(0)) / 1000;
}
return 0;
}
Gets the font parameter identified by key. Valid values
for key are ASCENT, CAPHEIGHT, DESCENT
and ITALICANGLE. |
public String[][] getFullFontName() {
return new String[][]{{"", "", "", fontName}};
}
Gets the full name of the font. If it is a True Type font
each array element will have {Platform ID, Platform Encoding ID,
Language ID, font name}. The interpretation of this values can be
found in the Open Type specification, chapter 2, in the 'name' table.
For the other fonts the array has a single element with {"", "", "",
font name}. |
public PdfStream getFullFontStream() {
return null;
}
You can't get the FontStream of a CJK font (CJK fonts are never embedded),
so this method always returns null. |
public int getKerning(int char1,
int char2) {
return 0;
}
|
public String getPostscriptFontName() {
return fontName;
}
|
protected int[] getRawCharBBox(int c,
String name) {
return null;
}
|
int getRawWidth(int c,
String name) {
return 0;
}
|
public int getUnicodeEquivalent(int c) {
if (cidDirect)
return translationMap[c];
return c;
}
|
public int getWidth(int char1) {
int c = char1;
if (!cidDirect)
c = translationMap[c];
int v;
if (vertical)
v = vMetrics.get(c);
else
v = hMetrics.get(c);
if (v > 0)
return v;
else
return 1000;
}
Gets the width of a char in normalized 1000 units. |
public int getWidth(String text) {
int total = 0;
for (int k = 0; k < text.length(); ++k) {
int c = text.charAt(k);
if (!cidDirect)
c = translationMap[c];
int v;
if (vertical)
v = vMetrics.get(c);
else
v = hMetrics.get(c);
if (v > 0)
total += v;
else
total += 1000;
}
return total;
}
|
public boolean hasKernPairs() {
return false;
}
Checks if the font has any kerning pairs. |
public static boolean isCJKFont(String fontName,
String enc) {
loadProperties();
String encodings = cjkFonts.getProperty(fontName);
return (encodings != null && (enc.equals("Identity-H") || enc.equals("Identity-V") || encodings.indexOf("_" + enc + "_") >= 0));
}
Checks if its a valid CJK font. |
static char[] readCMap(String name) {
try {
name = name + ".cmap";
InputStream is = getResourceStream(RESOURCE_PATH + name);
char c[] = new char[0x10000];
for (int k = 0; k < 0x10000; ++k)
c[k] = (char)((is.read() < < 8) + is.read());
return c;
}
catch (Exception e) {
// empty on purpose
}
return null;
}
|
static HashMap readFontProperties(String name) {
try {
name += ".properties";
InputStream is = getResourceStream(RESOURCE_PATH + name);
Properties p = new Properties();
p.load(is);
is.close();
IntHashtable W = createMetric(p.getProperty("W"));
p.remove("W");
IntHashtable W2 = createMetric(p.getProperty("W2"));
p.remove("W2");
HashMap map = new HashMap();
for (Enumeration e = p.keys(); e.hasMoreElements();) {
Object obj = e.nextElement();
map.put(obj, p.getProperty((String)obj));
}
map.put("W", W);
map.put("W2", W2);
return map;
}
catch (Exception e) {
// empty on purpose
}
return null;
}
|
public boolean setCharAdvance(int c,
int advance) {
return false;
}
Sets the character advance. |
public boolean setKerning(int char1,
int char2,
int kern) {
return false;
}
|
public void setPostscriptFontName(String name) {
fontName = name;
}
Sets the font name that will appear in the pdf font dictionary.
Use with care as it can easily make a font unreadable if not embedded. |
void writeFont(PdfWriter writer,
PdfIndirectReference ref,
Object[] params) throws IOException, DocumentException {
IntHashtable cjkTag = (IntHashtable)params[0];
PdfIndirectReference ind_font = null;
PdfObject pobj = null;
PdfIndirectObject obj = null;
pobj = getFontDescriptor();
if (pobj != null){
obj = writer.addToBody(pobj);
ind_font = obj.getIndirectReference();
}
pobj = getCIDFont(ind_font, cjkTag);
if (pobj != null){
obj = writer.addToBody(pobj);
ind_font = obj.getIndirectReference();
}
pobj = getFontBaseType(ind_font);
writer.addToBody(pobj, ref);
}
|