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

📄 fontfactory.java

📁 iText可以制作中文PDF文件的JAVA源程序
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                    Object o = e.nextElement();                    attributes.put(o, styleAttributes.get(o));                }            }        }        if ((value = (String)attributes.remove(ElementTags.ENCODING)) != null) {            encoding = value;        }        if ("false".equals((String) attributes.remove(ElementTags.EMBEDDED))) {            embedded = false;        }        if ((value = (String)attributes.remove(ElementTags.FONT)) != null) {            fontname = value;        }        if ((value = (String)attributes.remove(ElementTags.SIZE)) != null) {            size = Float.valueOf(value + "f").floatValue();        }        if ((value = (String)attributes.remove(MarkupTags.STYLE)) != null) {            style |= Font.getStyleValue(value);        }        if ((value = (String)attributes.remove(ElementTags.STYLE)) != null) {            style |= Font.getStyleValue(value);        }        String r = (String)attributes.remove(ElementTags.RED);        String g = (String)attributes.remove(ElementTags.GREEN);        String b = (String)attributes.remove(ElementTags.BLUE);        if (r != null || g != null || b != null) {            int red = 0;            int green = 0;            int blue = 0;            if (r != null) red = Integer.parseInt(r);            if (g != null) green = Integer.parseInt(g);            if (b != null) blue = Integer.parseInt(b);            color = new Color(red, green, blue);        }        else if ((value = (String)attributes.remove(ElementTags.COLOR)) != null) {            color = MarkupParser.decodeColor(value);        }        if (fontname == null) {            return getFont(null, encoding, embedded, size, style, color);        }        return getFont(fontname, encoding, embedded, size, style, color);    }    /** * Constructs a <CODE>Font</CODE>-object. * * @param	fontname    the name of the font * @param	encoding    the encoding of the font * @param       embedded    true if the font is to be embedded in the PDF * @param	size	    the size of this font * @param	style	    the style of this font */        public static Font getFont(String fontname, String encoding, boolean embedded, float size, int style) {        return getFont(fontname, encoding, embedded, size, style, null);    }    /** * Constructs a <CODE>Font</CODE>-object. * * @param	fontname    the name of the font * @param	encoding    the encoding of the font * @param       embedded    true if the font is to be embedded in the PDF * @param	size	    the size of this font */        public static Font getFont(String fontname, String encoding, boolean embedded, float size) {        return getFont(fontname, encoding, embedded, size, Font.UNDEFINED, null);    }    /** * Constructs a <CODE>Font</CODE>-object. * * @param	fontname    the name of the font * @param	encoding    the encoding of the font * @param       embedded    true if the font is to be embedded in the PDF */        public static Font getFont(String fontname, String encoding, boolean embedded) {        return getFont(fontname, encoding, embedded, Font.UNDEFINED, Font.UNDEFINED, null);    }    /** * Constructs a <CODE>Font</CODE>-object. * * @param	fontname    the name of the font * @param	encoding    the encoding of the font * @param	size	    the size of this font * @param	style	    the style of this font * @param	color	    the <CODE>Color</CODE> of this font. */        public static Font getFont(String fontname, String encoding, float size, int style, Color color) {        return getFont(fontname, encoding, defaultEmbedding, size, style, color);    }    /** * Constructs a <CODE>Font</CODE>-object. * * @param	fontname    the name of the font * @param	encoding    the encoding of the font * @param	size	    the size of this font * @param	style	    the style of this font */        public static Font getFont(String fontname, String encoding, float size, int style) {        return getFont(fontname, encoding, defaultEmbedding, size, style, null);    }    /** * Constructs a <CODE>Font</CODE>-object. * * @param	fontname    the name of the font * @param	encoding    the encoding of the font * @param	size	    the size of this font */        public static Font getFont(String fontname, String encoding, float size) {        return getFont(fontname, encoding, defaultEmbedding, size, Font.UNDEFINED, null);    }    /** * Constructs a <CODE>Font</CODE>-object. * * @param	fontname    the name of the font * @param	encoding    the encoding of the font */        public static Font getFont(String fontname, String encoding) {        return getFont(fontname, encoding, defaultEmbedding, Font.UNDEFINED, Font.UNDEFINED, null);    }    /** * Constructs a <CODE>Font</CODE>-object. * * @param	fontname    the name of the font * @param	size	    the size of this font * @param	style	    the style of this font * @param	color	    the <CODE>Color</CODE> of this font. */        public static Font getFont(String fontname, float size, int style, Color color) {        return getFont(fontname, defaultEncoding, defaultEmbedding, size, style, color);    }    /** * Constructs a <CODE>Font</CODE>-object. * * @param	fontname    the name of the font * @param	size	    the size of this font * @param	style	    the style of this font */        public static Font getFont(String fontname, float size, int style) {        return getFont(fontname, defaultEncoding, defaultEmbedding, size, style, null);    }    /** * Constructs a <CODE>Font</CODE>-object. * * @param	fontname    the name of the font * @param	size	    the size of this font */        public static Font getFont(String fontname, float size) {        return getFont(fontname, defaultEncoding, defaultEmbedding, size, Font.UNDEFINED, null);    }    /** * Constructs a <CODE>Font</CODE>-object. * * @param	fontname    the name of the font */        public static Font getFont(String fontname) {        return getFont(fontname, defaultEncoding, defaultEmbedding, Font.UNDEFINED, Font.UNDEFINED, null);    }    /** * Register a ttf- or a ttc-file. * * @param   path    the path to a ttf- or ttc-file */        public static void register(String path) {        register(path, null);    }    /** * Register a ttf- or a ttc-file and use an alias for the font contained in the ttf-file. * * @param   path    the path to a ttf- or ttc-file * @param   alias   the alias you want to use for the font */        public static void register(String path, String alias) {        try {            if (path.toLowerCase().endsWith(".ttf")) {                BaseFont bf = BaseFont.createFont(path, BaseFont.WINANSI, false, false, null, null);                trueTypeFonts.setProperty(bf.getPostscriptFontName(), path);                if (alias != null) {                    trueTypeFonts.setProperty(alias, path);                }                String fullName = null;                String familyName = null;                String[][] names = bf.getFullFontName();                for (int i = 0; i < names.length; i++) {                    if ("0".equals(names[i][2])) {                        fullName = names[i][3];                        trueTypeFonts.setProperty(fullName, path);                        break;                    }                }                if (fullName != null) {                    names = bf.getFamilyFontName();                    for (int i = 0; i < names.length; i++) {                        if ("0".equals(names[i][2])) {                            familyName = names[i][3];                            HashSet tmp = (HashSet) fontFamilies.get(familyName);                            if (tmp == null) {                                tmp = new HashSet();                            }                            tmp.add(fullName);                            fontFamilies.put(familyName, tmp);                            break;                        }                    }                }            }            else if (path.toLowerCase().endsWith(".ttc")) {                String[] names = BaseFont.enumerateTTCNames(path);                for (int i = 0; i < names.length; i++) {                    trueTypeFonts.setProperty(names[i], path + "," + (i + 1));                }                if (alias != null) {                    System.err.println("class FontFactory: You can't define an alias for a true type collection.");                }            }        }        catch(DocumentException de) {            // this shouldn't happen            throw new ExceptionConverter(de);        }        catch(IOException ioe) {            throw new ExceptionConverter(ioe);        }    }    /** * Gets a set of registered fontnames. */        public static Set getRegisteredFonts() {        return Chunk.getKeySet(trueTypeFonts);    }    /** * Gets a set of registered fontnames. */        public static Set getRegisteredFamilies() {        return Chunk.getKeySet(fontFamilies);    }    /** * Gets a set of registered fontnames. */        public static boolean contains(String fontname) {        return trueTypeFonts.containsKey(fontname);    }    /** * Checks if a certain font is registered. * * @param   fontname    the name of the font that has to be checked. * @return  true if the font is found */        public static boolean isRegistered(String fontname) {        String tmp;        for (Enumeration e = trueTypeFonts.propertyNames(); e.hasMoreElements(); ) {            tmp = (String) e.nextElement();            if (fontname.equalsIgnoreCase(tmp)) {                return true;            }        }        return false;    }}

⌨️ 快捷键说明

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