📄 cjkfont.java
字号:
}
public static Object[] getCharacterCollection(String enc) {
for (int k = 0; k < cjk.length; ++k) {
Object obj[] = (Object[])cjk[k];
String tenc[] = (String[])obj[4];
for (int j = 0; j < tenc.length; ++j) {
if (enc.equals(tenc[j])) {
tenc = (String[])obj[2];
return new Object[]{tenc[0], tenc[1], new Integer(((int[])obj[1])[10])};
}
}
}
return null;
}
public int getWidth(String text)
{
int total = 0;
for (int k = 0; k < text.length(); ++k) {
int c = text.charAt(k);
int v = getValueByKey(metrics1, c);
if (v >= 0) {
total += v;
continue;
}
if (metrics2 == null)
total += 1000;
else {
v = getValueByKey(metrics2, c);
if (v >= 0)
total += v;
else
total += 1000;
}
}
return total;
}
protected int getRawWidth(int c, String name)
{
return 0;
}
public int getKerning(char char1, char char2)
{
return 0;
}
public static int getValueByKey(int a[], int key)
{
int low = 0;
int high = a.length / 2 -1;
while (low <= high) {
int mid =(low + high)/2;
int midVal = a[mid << 1];
if (midVal < key)
low = mid + 1;
else if (midVal > key)
high = mid - 1;
else
return a[(mid << 1) + 1]; // key found
}
return -1; // key not found.
}
private PdfDictionary getFontDescriptor() throws DocumentException
{
PdfDictionary dic = new PdfDictionary(new PdfName("FontDescriptor"));
dic.put(new PdfName("Ascent"), new PdfNumber(fdescInt[0]));
dic.put(new PdfName("CapHeight"), new PdfNumber(fdescInt[1]));
dic.put(new PdfName("Descent"), new PdfNumber(fdescInt[2]));
dic.put(new PdfName("Flags"), new PdfNumber(fdescInt[3]));
dic.put(new PdfName("FontBBox"), new PdfRectangle(fdescInt[4], fdescInt[5], fdescInt[6], fdescInt[7]));
dic.put(new PdfName("FontName"), new PdfName(fontName + style));
dic.put(new PdfName("ItalicAngle"), new PdfNumber(fdescInt[8]));
dic.put(new PdfName("StemV"), new PdfNumber(fdescInt[9]));
PdfDictionary pdic = new PdfDictionary();
pdic.put(PdfName.PANOSE, new PdfStringLiteral(panose));
dic.put(new PdfName("Style"), pdic);
return dic;
}
private PdfDictionary getCIDFont(PdfIndirectReference fontDescriptor) throws DocumentException
{
PdfDictionary dic = new PdfDictionary(PdfName.FONT);
dic.put(PdfName.SUBTYPE, new PdfName("CIDFontType0"));
dic.put(new PdfName("BaseFont"), new PdfName(fontName + style));
dic.put(new PdfName("FontDescriptor"), fontDescriptor);
dic.put(new PdfName("DW"), new PdfNumber(1000));
dic.put(new PdfName("W"), new PdfLiteral(fdescStr[2]));
PdfDictionary cdic = new PdfDictionary();
cdic.put(PdfName.REGISTRY, new PdfString(fdescStr[0]));
cdic.put(PdfName.ORDERING, new PdfString(fdescStr[1]));
cdic.put(PdfName.SUPPLEMENT, new PdfNumber(fdescInt[10]));
dic.put(new PdfName("CIDSystemInfo"), cdic);
return dic;
}
private PdfDictionary getFontBaseType(PdfIndirectReference CIDFont) throws DocumentException
{
PdfDictionary dic = new PdfDictionary(PdfName.FONT);
dic.put(PdfName.SUBTYPE, new PdfName("Type0"));
String name = fontName;
if (style.length() > 0)
name += "-" + style.substring(1);
name += "-" + CMap;
dic.put(new PdfName("BaseFont"), new PdfName(name));
dic.put(new PdfName("Encoding"), new PdfName(CMap));
dic.put(new PdfName("DescendantFonts"), new PdfArray(CIDFont));
return dic;
}
/** Generates the dictionary or stream required to represent the font.
* <CODE>index</CODE> will cycle from 0 to 2 with the next cycle beeing fed
* with the indirect reference from the previous cycle.
* @param iobj an indirect reference to a Pdf object. May be null
* @param index the type of object to generate. It may be 0, 1 or 2
* @return the object requested
* @throws DocumentException error in generating the object
*/
void writeFont(PdfWriter writer, PdfIndirectReference ref, Object params[]) throws DocumentException, IOException {
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);
if (pobj != null){
obj = writer.addToBody(pobj);
ind_font = obj.getIndirectReference();
}
pobj = getFontBaseType(ind_font);
writer.addToBody(pobj, ref);
}
/** Gets the font parameter identified by <CODE>key</CODE>. Valid values
* for <CODE>key</CODE> are <CODE>ASCENT</CODE>, <CODE>CAPHEIGHT</CODE>, <CODE>DESCENT</CODE>
* and <CODE>ITALICANGLE</CODE>.
* @param key the parameter to be extracted
* @param fontSize the font size in points
* @return the parameter in points
*/
public float getFontDescriptor(int key, float fontSize) {
switch (key) {
case ASCENT:
return fdescInt[0] * fontSize / 1000;
case CAPHEIGHT:
return fdescInt[1] * fontSize / 1000;
case DESCENT:
return fdescInt[2] * fontSize / 1000;
case ITALICANGLE:
return fdescInt[8];
case BBOXLLX:
return fontSize * fdescInt[4] / 1000;
case BBOXLLY:
return fontSize * fdescInt[5] / 1000;
case BBOXURX:
return fontSize * fdescInt[6] / 1000;
case BBOXURY:
return fontSize * fdescInt[7] / 1000;
}
return 0;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -