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

📄 basefont.java

📁 一个java操作pdf文件的开发包,很好用的.
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/* * $Id: BaseFont.java,v 1.33 2002/11/19 08:33:35 blowagie Exp $ * $Name:  $ * * Copyright 2000, 2001, 2002 by Paulo Soares. * * The contents of this file are subject to the Mozilla Public License Version 1.1 * (the "License"); you may not use this file except in compliance with the License. * You may obtain a copy of the License at http://www.mozilla.org/MPL/ * * Software distributed under the License is distributed on an "AS IS" basis, * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License * for the specific language governing rights and limitations under the License. * * The Original Code is 'iText, a free JAVA-PDF library'. * * The Initial Developer of the Original Code is Bruno Lowagie. Portions created by * the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie. * All Rights Reserved. * Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer * are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved. * * Contributor(s): all the names of the contributors are added in the source code * where applicable. * * Alternatively, the contents of this file may be used under the terms of the * LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the * provisions of LGPL are applicable instead of those above.  If you wish to * allow use of your version of this file only under the terms of the LGPL * License and not to allow others to use your version of this file under * the MPL, indicate your decision by deleting the provisions above and * replace them with the notice and other provisions required by the LGPL. * If you do not delete the provisions above, a recipient may use your version * of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE. * * This library is free software; you can redistribute it and/or modify it * under the terms of the MPL as stated above or under the terms of the GNU * Library General Public License as published by the Free Software Foundation; * either version 2 of the License, or any later version. * * This library is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU Library general Public License for more * details. * * If you didn't download this code from the following link, you should check if * you aren't using an obsolete version: * http://www.lowagie.com/iText/ */package com.lowagie.text.pdf;import java.io.*;import com.lowagie.text.DocumentException;import java.util.HashMap;/** * Base class for the several font types supported * * @author Paulo Soares (psoares@consiste.pt) */public abstract class BaseFont {        /** This is a possible value of a base 14 type 1 font */    public static final String COURIER = "Courier";        /** This is a possible value of a base 14 type 1 font */    public static final String COURIER_BOLD = "Courier-Bold";        /** This is a possible value of a base 14 type 1 font */    public static final String COURIER_OBLIQUE = "Courier-Oblique";        /** This is a possible value of a base 14 type 1 font */    public static final String COURIER_BOLDOBLIQUE = "Courier-BoldOblique";        /** This is a possible value of a base 14 type 1 font */    public static final String HELVETICA = "Helvetica";        /** This is a possible value of a base 14 type 1 font */    public static final String HELVETICA_BOLD = "Helvetica-Bold";        /** This is a possible value of a base 14 type 1 font */    public static final String HELVETICA_OBLIQUE = "Helvetica-Oblique";        /** This is a possible value of a base 14 type 1 font */    public static final String HELVETICA_BOLDOBLIQUE = "Helvetica-BoldOblique";        /** This is a possible value of a base 14 type 1 font */    public static final String SYMBOL = "Symbol";        /** This is a possible value of a base 14 type 1 font */    public static final String TIMES_ROMAN = "Times-Roman";        /** This is a possible value of a base 14 type 1 font */    public static final String TIMES_BOLD = "Times-Bold";        /** This is a possible value of a base 14 type 1 font */    public static final String TIMES_ITALIC = "Times-Italic";        /** This is a possible value of a base 14 type 1 font */    public static final String TIMES_BOLDITALIC = "Times-BoldItalic";        /** This is a possible value of a base 14 type 1 font */    public static final String ZAPFDINGBATS = "ZapfDingbats";        /** The maximum height above the baseline reached by glyphs in this     * font, excluding the height of glyphs for accented characters.     */        public static final int ASCENT = 1;        /** The y coordinate of the top of flat capital letters, measured from     * the baseline.     */        public static final int CAPHEIGHT = 2;    /** The maximum depth below the baseline reached by glyphs in this     * font. The value is a negative number.     */        public static final int DESCENT = 3;    /** The angle, expressed in degrees counterclockwise from the vertical,     * of the dominant vertical strokes of the font. The value is     * negative for fonts that slope to the right, as almost all italic fonts do.     */        public static final int ITALICANGLE = 4;    /** The lower left x glyph coordinate.     */        public static final int BBOXLLX = 5;    /** The lower left y glyph coordinate.     */        public static final int BBOXLLY = 6;    /** The upper right x glyph coordinate.     */        public static final int BBOXURX = 7;    /** The upper right y glyph coordinate.     */        public static final int BBOXURY = 8;        public static final int AWT_ASCENT = 9;    public static final int AWT_DESCENT = 10;    public static final int AWT_LEADING = 11;    public static final int AWT_MAXADVANCE = 12;        /** The font is Type 1.     */        public static final int FONT_TYPE_T1 = 0;    /** The font is True Type with a standard encoding.     */        public static final int FONT_TYPE_TT = 1;    /** The font is CJK.     */        public static final int FONT_TYPE_CJK = 2;    /** The font is True Type with a Unicode encoding.     */        public static final int FONT_TYPE_TTUNI = 3;    /** The Unicode encoding with horizontal writing.     */        public static final String IDENTITY_H = "Identity-H";    /** The Unicode encoding with vertical writing.     */        public static final String IDENTITY_V = "Identity-V";        /** A possible encoding. */        public static final String CP1250 = "Cp1250";        /** A possible encoding. */        public static final String CP1252 = "Cp1252";        /** A possible encoding. */        public static final String CP1257 = "Cp1257";        /** A possible encoding. */        public static final String WINANSI = "Cp1252";        /** A possible encoding. */        public static final String MACROMAN = "MacRoman";        /** if the font has to be embedded */    public static final boolean EMBEDDED = true;    /** if the font doesn't have to be embedded */    public static final boolean NOT_EMBEDDED = false;/** if the font has to be cached */    public static final boolean CACHED = true;/** if the font doesn't have to be cached */    public static final boolean NOT_CACHED = false;        /** The font type.     */        int fontType;/** a not defined character in a custom PDF encoding */    public static final String notdef = ".notdef";    /** table of characters widths for this encoding */    protected int widths[] = new int[256];    /** encoding names */    protected String differences[] = new String[256];/** same as differences but with the unicode codes */    protected char unicodeDifferences[] = new char[256];    /** encoding used with this font */    protected String encoding;    /** true if the font is to be embedded in the PDF */    protected boolean embedded;    /** * true if the font must use it's built in encoding. In that case the * <CODE>encoding</CODE> is only used to map a char to the position inside * the font, not to the expected char name. */    protected boolean fontSpecific = true;    /** cache for the fonts already used. */    protected static HashMap fontCache = new HashMap();    /** list of the 14 built in fonts. */    protected static final HashMap BuiltinFonts14 = new HashMap();        /** The subset prefix to be added to the font name when the font is embedded.     */        protected static char subsetPrefix[] = {'A', 'B', 'C', 'D', 'E', 'E', '+'};        /** Forces the output of the width array. Only matters for the 14     * built-in fonts.     */    protected boolean forceWidthsOutput = false;        /** Converts <CODE>char</CODE> directly to <CODE>byte</CODE>     * by casting.     */    protected boolean directTextToByte = false;        /** Indicates if all the glyphs and widths for that particular     * encoding should be included in the document.     */    protected boolean subset = true;        protected boolean fastWinansi = false;        static {        BuiltinFonts14.put(COURIER, PdfName.COURIER);        BuiltinFonts14.put(COURIER_BOLD, PdfName.COURIER_BOLD);        BuiltinFonts14.put(COURIER_BOLDOBLIQUE, PdfName.COURIER_BOLDOBLIQUE);        BuiltinFonts14.put(COURIER_OBLIQUE, PdfName.COURIER_OBLIQUE);        BuiltinFonts14.put(HELVETICA, PdfName.HELVETICA);        BuiltinFonts14.put(HELVETICA_BOLD, PdfName.HELVETICA_BOLD);        BuiltinFonts14.put(HELVETICA_BOLDOBLIQUE, PdfName.HELVETICA_BOLDOBLIQUE);        BuiltinFonts14.put(HELVETICA_OBLIQUE, PdfName.HELVETICA_OBLIQUE);        BuiltinFonts14.put(SYMBOL, PdfName.SYMBOL);        BuiltinFonts14.put(TIMES_ROMAN, PdfName.TIMES_ROMAN);        BuiltinFonts14.put(TIMES_BOLD, PdfName.TIMES_BOLD);        BuiltinFonts14.put(TIMES_BOLDITALIC, PdfName.TIMES_BOLDITALIC);        BuiltinFonts14.put(TIMES_ITALIC, PdfName.TIMES_ITALIC);        BuiltinFonts14.put(ZAPFDINGBATS, PdfName.ZAPFDINGBATS);    }        /** Generates the PDF stream with the Type1 and Truetype fonts returning     * a PdfStream.     */    class StreamFont extends PdfStream {                /** Generates the PDF stream with the Type1 and Truetype fonts returning         * a PdfStream.         * @param contents the content of the stream         * @param lengths an array of int that describes the several lengths of each part of the font         * @throws DocumentException error in the stream compression         */        public StreamFont(byte contents[], int lengths[]) throws DocumentException {            try {                bytes = contents;                put(PdfName.LENGTH, new PdfNumber(bytes.length));                for (int k = 0; k < lengths.length; ++k) {                    put(new PdfName("Length" + (k + 1)), new PdfNumber(lengths[k]));                }                flateCompress();            }            catch (Exception e) {                throw new DocumentException(e.getMessage());            }        }                public StreamFont(byte contents[], String subType) throws DocumentException {            try {

⌨️ 快捷键说明

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