📄 basefont.java
字号:
* @return an array of <CODE>byte</CODE> representing the conversion according to the font's encoding */ byte[] convertToBytes(String text) { if (directTextToByte) return PdfEncodings.convertToBytes(text, null); return PdfEncodings.convertToBytes(text, encoding); } /** Outputs to the writer the font dictionaries and streams. * @param writer the writer for this document * @param ref the font indirect reference * @param params several parameters that depend on the font type * @throws IOException on error * @throws DocumentException error in generating the object */ abstract void writeFont(PdfWriter writer, PdfIndirectReference ref, Object params[]) throws DocumentException, IOException; /** Gets the encoding used to convert <CODE>String</CODE> into <CODE>byte[]</CODE>. * @return the encoding name */ public String getEncoding() { return encoding; } /** 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>, * <CODE>ITALICANGLE</CODE>, <CODE>BBOXLLX</CODE>, <CODE>BBOXLLY</CODE>, <CODE>BBOXURX</CODE> * and <CODE>BBOXURY</CODE>. * @param key the parameter to be extracted * @param fontSize the font size in points * @return the parameter in points */ public abstract float getFontDescriptor(int key, float fontSize); /** Gets the font type. The font types can be: FONT_TYPE_T1, * FONT_TYPE_TT, FONT_TYPE_CJK and FONT_TYPE_TTUNI. * @return the font type */ public int getFontType() { return fontType; } /** Gets the embedded flag. * @return <CODE>true</CODE> if the font is embedded. */ public boolean isEmbedded() { return embedded; } /** Gets the symbolic flag of the font. * @return <CODE>true</CODE> if the font is symbolic */ public boolean isFontSpecific() { return fontSpecific; } /** Creates a unique subset prefix to be added to the font name when the font is embedded and subset. * @return the subset prefix */ String createSubsetPrefix() { synchronized(subsetPrefix) { for (int k = 0; k < subsetPrefix.length - 1; ++k) { int c = subsetPrefix[k]; if (c == 'Z') subsetPrefix[k] = 'A'; else { subsetPrefix[k] = (char)(c + 1); break; } } return new String(subsetPrefix); } } /** Gets the Unicode character corresponding to the byte output to the pdf stream. * @param index the byte index * @return the Unicode character */ char getUnicodeDifferences(int index) { return unicodeDifferences[index]; } /** Gets the postscript font name. * @return the postscript font name */ public abstract String getPostscriptFontName(); /** 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.<br> * For the other fonts the array has a single element with {"", "", "", * font name}. * @return the full name of the font */ public abstract String[][] getFullFontName(); /** 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.<br> * For the other fonts the array has a single element with {"", "", "", * font name}. * @param name the name of the font * @param encoding the encoding of the font * @param ttfAfm the true type font or the afm in a byte array * @throws DocumentException on error * @throws IOException on error * @return the full name of the font */ public static String[][] getFullFontName(String name, String encoding, byte ttfAfm[]) throws DocumentException, IOException { String nameBase = getBaseName(name); BaseFont fontBuilt = null; if (nameBase.toLowerCase().endsWith(".ttf") || nameBase.toLowerCase().endsWith(".otf") || nameBase.toLowerCase().indexOf(".ttc,") > 0) fontBuilt = new TrueTypeFont(name, CP1252, false, ttfAfm, true); else fontBuilt = createFont(name, encoding, false, false, ttfAfm, null); return fontBuilt.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.<br> * For the other fonts the array has a single element with {"", "", "", * font name}. * @return the family name of the font */ public abstract String[][] getFamilyFontName(); /** Gets the code pages supported by the font. This has only meaning * with True Type fonts. * @return the code pages supported by the font */ public String[] getCodePagesSupported() { return new String[0]; } /** Enumerates the postscript font names present inside a * True Type Collection. * @param ttcFile the file name of the font * @throws DocumentException on error * @throws IOException on error * @return the postscript font names */ public static String[] enumerateTTCNames(String ttcFile) throws DocumentException, IOException { return new EnumerateTTC(ttcFile).getNames(); } /** Enumerates the postscript font names present inside a * True Type Collection. * @param ttcArray the font as a <CODE>byte</CODE> array * @throws DocumentException on error * @throws IOException on error * @return the postscript font names */ public static String[] enumerateTTCNames(byte ttcArray[]) throws DocumentException, IOException { return new EnumerateTTC(ttcArray).getNames(); } /** Gets the font width array. * @return the font width array */ public int[] getWidths() { return widths; } /** Gets the array with the names of the characters. * @return the array with the names of the characters */ public String[] getDifferences() { return differences; } /** Gets the array with the unicode characters. * @return the array with the unicode characters */ public char[] getUnicodeDifferences() { return unicodeDifferences; } /** Gets the state of the property. * @return value of property forceWidthsOutput */ public boolean isForceWidthsOutput() { return forceWidthsOutput; } /** Set to <CODE>true</CODE> to force the generation of the * widths array. * @param forceWidthsOutput <CODE>true</CODE> to force the generation of the * widths array */ public void setForceWidthsOutput(boolean forceWidthsOutput) { this.forceWidthsOutput = forceWidthsOutput; } /** Gets the direct conversion of <CODE>char</CODE> to <CODE>byte</CODE>. * @return value of property directTextToByte. * @see #setDirectTextToByte(boolean directTextToByte) */ public boolean isDirectTextToByte() { return directTextToByte; } /** Sets the conversion of <CODE>char</CODE> directly to <CODE>byte</CODE> * by casting. This is a low level feature to put the bytes directly in * the content stream without passing through String.getBytes(). * @param directTextToByte New value of property directTextToByte. */ public void setDirectTextToByte(boolean directTextToByte) { this.directTextToByte = directTextToByte; } /** Indicates if all the glyphs and widths for that particular * encoding should be included in the document. * @return <CODE>false</CODE> to include all the glyphs and widths. */ public boolean isSubset() { return subset; } /** Indicates if all the glyphs and widths for that particular * encoding should be included in the document. Set to <CODE>false</CODE> * to include all. * @param subset new value of property subset */ public void setSubset(boolean subset) { this.subset = subset; } /** Gets the font resources. * @param key the name of the resource * @return the <CODE>InputStream</CODE> to get the resource or * <CODE>null</CODE> if not found */ public static InputStream getResourceStream(String key) { InputStream is = null; // Try to use Context Class Loader to load the properties file. try { java.lang.reflect.Method getCCL = Thread.class.getMethod("getContextClassLoader", new Class[0]); if (getCCL != null) { ClassLoader contextClassLoader = (ClassLoader)getCCL.invoke(Thread.currentThread(), new Object[0]); is = contextClassLoader.getResourceAsStream("fonts/" + key); } } catch (Exception e) {} if (is == null) { is = BaseFont.class.getResourceAsStream("fonts/" + key); } return is; } /** Gets the Unicode equivalent to a CID. * The (inexistent) CID <FF00> is translated as '\n'. * It has only meaning with CJK fonts with Identity encoding. * @param c the CID code * @return the Unicode equivalent */ public char getUnicodeEquivalent(char c) { return c; } /** Gets the CID code given an Unicode. * It has only meaning with CJK fonts. * @param c the Unicode * @return the CID equivalent */ public char getCidCode(char c) { return c; } /** Checks if the font has any kerning pairs. * @return <CODE>true</CODE> if the font has any kerning pairs */ public abstract boolean hasKernPairs();}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -