⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 basefont.java

📁 处理PDF
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
     * @return the kerning to be applied in normalized 1000 units     */    public abstract int getKerning(int char1, int char2);    /**     * Sets the kerning between two Unicode chars.     * @param char1 the first char     * @param char2 the second char     * @param kern the kerning to apply in normalized 1000 units     * @return <code>true</code> if the kerning was applied, <code>false</code> otherwise     */    public abstract boolean setKerning(int char1, int char2, int kern);        /**     * Gets the width of a <CODE>char</CODE> in normalized 1000 units.     * @param char1 the unicode <CODE>char</CODE> to get the width of     * @return the width in normalized 1000 units     */    public int getWidth(int char1) {        if (fastWinansi) {            if (char1 < 128 || (char1 >= 160 && char1 <= 255))                return widths[char1];            else                return widths[PdfEncodings.winansi.get(char1)];        }        else {            int total = 0;            byte mbytes[] = convertToBytes((char)char1);            for (int k = 0; k < mbytes.length; ++k)                total += widths[0xff & mbytes[k]];            return total;        }    }        /**     * Gets the width of a <CODE>String</CODE> in normalized 1000 units.     * @param text the <CODE>String</CODE> to get the witdth of     * @return the width in normalized 1000 units     */    public int getWidth(String text) {        int total = 0;        if (fastWinansi) {            int len = text.length();            for (int k = 0; k < len; ++k) {                char char1 = text.charAt(k);                if (char1 < 128 || (char1 >= 160 && char1 <= 255))                    total += widths[char1];                else                    total += widths[PdfEncodings.winansi.get(char1)];            }            return total;        }        else {            byte mbytes[] = convertToBytes(text);            for (int k = 0; k < mbytes.length; ++k)                total += widths[0xff & mbytes[k]];        }        return total;    }    /** * Gets the descent of a <CODE>String</CODE> in normalized 1000 units. The descent will always be * less than or equal to zero even if all the characters have an higher descent. * @param text the <CODE>String</CODE> to get the descent of * @return the descent in normalized 1000 units */    public int getDescent(String text) {        int min = 0;        char chars[] = text.toCharArray();        for (int k = 0; k < chars.length; ++k) {            int bbox[] = getCharBBox(chars[k]);            if (bbox != null && bbox[1] < min)                min = bbox[1];        }        return min;    }    /** * Gets the ascent of a <CODE>String</CODE> in normalized 1000 units. The ascent will always be * greater than or equal to zero even if all the characters have a lower ascent. * @param text the <CODE>String</CODE> to get the ascent of * @return the ascent in normalized 1000 units */    public int getAscent(String text) {        int max = 0;        char chars[] = text.toCharArray();        for (int k = 0; k < chars.length; ++k) {            int bbox[] = getCharBBox(chars[k]);            if (bbox != null && bbox[3] > max)                max = bbox[3];        }        return max;    }/** * Gets the descent of a <CODE>String</CODE> in points. The descent will always be * less than or equal to zero even if all the characters have an higher descent. * @param text the <CODE>String</CODE> to get the descent of * @param fontSize the size of the font * @return the descent in points */    public float getDescentPoint(String text, float fontSize)    {        return getDescent(text) * 0.001f * fontSize;    }    /** * Gets the ascent of a <CODE>String</CODE> in points. The ascent will always be * greater than or equal to zero even if all the characters have a lower ascent. * @param text the <CODE>String</CODE> to get the ascent of * @param fontSize the size of the font * @return the ascent in points */    public float getAscentPoint(String text, float fontSize)    {        return getAscent(text) * 0.001f * fontSize;    }// ia>            /**     * Gets the width of a <CODE>String</CODE> in points taking kerning     * into account.     * @param text the <CODE>String</CODE> to get the witdth of     * @param fontSize the font size     * @return the width in points     */    public float getWidthPointKerned(String text, float fontSize) {        float size = getWidth(text) * 0.001f * fontSize;        if (!hasKernPairs())            return size;        int len = text.length() - 1;        int kern = 0;        char c[] = text.toCharArray();        for (int k = 0; k < len; ++k) {            kern += getKerning(c[k], c[k + 1]);        }        return size + kern * 0.001f * fontSize;    }        /**     * Gets the width of a <CODE>String</CODE> in points.     * @param text the <CODE>String</CODE> to get the width of     * @param fontSize the font size     * @return the width in points     */    public float getWidthPoint(String text, float fontSize) {        return getWidth(text) * 0.001f * fontSize;    }        /**     * Gets the width of a <CODE>char</CODE> in points.     * @param char1 the <CODE>char</CODE> to get the width of     * @param fontSize the font size     * @return the width in points     */    public float getWidthPoint(int char1, float fontSize) {        return getWidth(char1) * 0.001f * fontSize;    }        /**     * Converts a <CODE>String</CODE> to a </CODE>byte</CODE> array according     * to the font's encoding.     * @param text the <CODE>String</CODE> to be converted     * @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);        if (specialMap != null) {            byte[] b = new byte[text.length()];            int ptr = 0;            int length = text.length();            for (int k = 0; k < length; ++k) {                char c = text.charAt(k);                if (specialMap.containsKey(c))                    b[ptr++] = (byte)specialMap.get(c);            }            if (ptr < length) {                byte[] b2 = new byte[ptr];                System.arraycopy(b, 0, b2, 0, ptr);                return b2;            }            else                return b;        }        return PdfEncodings.convertToBytes(text, encoding);    }        /**     * Converts a <CODE>char</CODE> to a </CODE>byte</CODE> array according     * to the font's encoding.     * @param char1 the <CODE>char</CODE> to be converted     * @return an array of <CODE>byte</CODE> representing the conversion according to the font's encoding     */    byte[] convertToBytes(int char1) {        if (directTextToByte)            return PdfEncodings.convertToBytes((char)char1, null);        if (specialMap != null) {            if (specialMap.containsKey(char1))                return new byte[]{(byte)specialMap.get(char1)};            else                return new byte[0];        }        return PdfEncodings.convertToBytes((char)char1, 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;        /**     * Returns a PdfStream object with the full font program (if possible).     * This method will return null for some types of fonts (CJKFont, Type3Font)     * or if there is no font program available (standard Type 1 fonts).     * @return	a PdfStream with the font program     * @since	2.1.3     */    abstract PdfStream getFullFontStream() throws IOException, DocumentException;        /** 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>AWT_ASCENT</CODE>, <CODE>CAPHEIGHT</CODE>,      * <CODE>DESCENT</CODE>, <CODE>AWT_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     */    public static String createSubsetPrefix() {        String s = "";        for (int k = 0; k < 6; ++k)            s += (char)(Math.random() * 26 + 'A');        return s + "+";    }        /** 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();        /**     * 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.     * @param name the new font name     */        public abstract void setPostscriptFontName(String name);        /** 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 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.<br>     * For the other fonts the array has a single element with {"4", "", "", "",     * font name}.     * @return the full name of the font     * @since 2.0.8     */    public abstract String[][] getAllNameEntries();     /** 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 all the names from the font. Only the required tables are read.     * @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 an array of Object[] built with {getPostscriptFontName(), getFamilyFontName(), getFullFontName()}     */        public static Object[] getAllFontNames(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 new Object[]{fontBuilt.getPostscriptFontName(), fontBuilt.getFamilyFontName(), fontBuilt.getFullFontName()};    }        /** Gets all the entries of the namestable from the font. Only the required tables are read.     * @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 an array of Object[] built with {getPostscriptFontName(), getFamilyFontName(), getFullFontName()}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -