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

📄 pfm2afm.java

📁 源码包含生成 PDF 和 HTML 的类库
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/* * $Id: Pfm2afm.java 3514 2008-06-27 09:26:36Z blowagie $ * * Copyright 1991 Ken Borgendale * * 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-2007 by Bruno Lowagie. * All Rights Reserved. * Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer * are Copyright (C) 2000-2007 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/ *//******************************************************************** *                                                                  * *  Title:  pfm2afm - Convert Windows .pfm files to .afm files      * *                                                                  * *  Author: Ken Borgendale   10/9/91  Version 1.0                   * *                                                                  * *  Function:                                                       * *      Convert a Windows .pfm (Printer Font Metrics) file to a     * *      .afm (Adobe Font Metrics) file.  The purpose of this is     * *      to allow fonts put out for Windows to be used with OS/2.    * *                                                                  * *  Syntax:                                                         * *      pfm2afm  infile  [outfile] -a                               * *                                                                  * *  Copyright:                                                      * *      pfm2afm - Copyright (C) IBM Corp., 1991                     * *                                                                  * *      This code is released for public use as long as the         * *      copyright remains intact.  This code is provided asis       * *      without any warrenties, express or implied.                 * *                                                                  * *  Notes:                                                          * *      1. Much of the information in the original .afm file is     * *         lost when the .pfm file is created, and thus cannot be   * *         reconstructed by this utility.  This is especially true  * *         of data for characters not in the Windows character set. * *                                                                  * *      2. This module is coded to be compiled by the MSC 6.0.      * *         For other compilers, be careful of the packing of the    * *         PFM structure.                                           * *                                                                  * ********************************************************************//******************************************************************** *                                                                  * *  Modifications by Rod Smith, 5/22/96                             * *                                                                  * *  These changes look for the strings "italic", "bold", "black",   * *  and "light" in the font's name and set the weight accordingly   * *  and adds an ItalicAngle line with a value of "0" or "-12.00".   * *  This allows OS/2 programs such as DeScribe to handle the bold   * *  and italic attributes appropriately, which was not the case     * *  when I used the original version on fonts from the KeyFonts     * *  Pro 2002 font CD.                                               * *                                                                  * *  I've also increased the size of the buffer used to load the     * *  .PFM file; the old size was inadequate for most of the fonts    * *  from the SoftKey collection.                                    * *                                                                  * *  Compiled with Watcom C 10.6                                     * *                                                                  * ********************************************************************/ /******************************************************************** *                                                                  * *  Further modifications, 4/21/98, by Rod Smith                    * *                                                                  * *  Minor changes to get the program to compile with gcc under      * *  Linux (Red Hat 5.0, to be precise).  I had to add an itoa       * *  function from the net (the function was buggy, so I had to fix  * *  it, too!).  I also made the program more friendly towards       * *  files with mixed-case filenames.                                * *                                                                  * ********************************************************************//******************************************************************** *                                                                  * *  1/31/2005, by Paulo Soares                                      * *                                                                  * *  This code was integrated into iText.                            *  *  Note that the itoa function mentioned in the comment by Rod     * *  Smith is no longer in the code because Java has native support  * *  in PrintWriter to convert integers to strings                   * *                                                                  * ********************************************************************//******************************************************************** *                                                                  * *  7/16/2005, by Bruno Lowagie                                     * *                                                                  * *  I solved an Eclipse Warning.                                    * *                                                                  * ********************************************************************//******************************************************************** *                                                                  * *  9/14/2006, by Xavier Le Vourch                                  * *                                                                  * *  expand import clauses (import java.io.*)                        *                                            *  the removal of an exception in readString was restored on 9/16  * *                                                                  * ********************************************************************/package com.lowagie.text.pdf;import java.io.FileOutputStream;import java.io.IOException;import java.io.OutputStream;import java.io.OutputStreamWriter;import java.io.PrintWriter;/** * Converts a PFM file into an AFM file. */public final class Pfm2afm {    private RandomAccessFileOrArray in;    private PrintWriter out;        /** Creates a new instance of Pfm2afm */    private Pfm2afm(RandomAccessFileOrArray in, OutputStream out) throws IOException {        this.in = in;        this.out = new PrintWriter(new OutputStreamWriter(out, "ISO-8859-1"));    }        /**     * Converts a PFM file into an AFM file.     * @param in the PFM file     * @param out the AFM file     * @throws IOException on error     */        public static void convert(RandomAccessFileOrArray in, OutputStream out) throws IOException {        Pfm2afm p = new Pfm2afm(in, out);        p.openpfm();        p.putheader();        p.putchartab();        p.putkerntab();        p.puttrailer();        p.out.flush();    }        public static void main(String[] args) {        try {            RandomAccessFileOrArray in = new RandomAccessFileOrArray(args[0]);            OutputStream out = new FileOutputStream(args[1]);            convert(in, out);            in.close();            out.close();        }        catch (Exception e) {            e.printStackTrace();        }    }        private String readString(int n) throws IOException {        byte b[] = new byte[n];        in.readFully(b);        int k;        for (k = 0; k < b.length; ++k) {            if (b[k] == 0)                break;        }        return new String(b, 0, k, "ISO-8859-1");    }        private String readString() throws IOException {        StringBuffer buf = new StringBuffer();        while (true) {            int c = in.read();            if (c <= 0)                break;            buf.append((char)c);        }        return buf.toString();    }        private void outval(int n) {        out.print(' ');        out.print(n);    }        /*     *  Output a character entry     */    private void  outchar(int code, int width, String name) {        out.print("C ");        outval(code);        out.print(" ; WX ");        outval(width);        if (name != null) {            out.print(" ; N ");            out.print(name);        }        out.print(" ;\n");    }        private void openpfm() throws IOException {        in.seek(0);        vers = in.readShortLE();        h_len = in.readIntLE();        copyright = readString(60);        type = in.readShortLE();        points = in.readShortLE();        verres = in.readShortLE();        horres = in.readShortLE();        ascent = in.readShortLE();        intleading = in.readShortLE();        extleading = in.readShortLE();        italic = (byte)in.read();        uline = (byte)in.read();        overs = (byte)in.read();        weight = in.readShortLE();        charset = (byte)in.read();        pixwidth = in.readShortLE();        pixheight = in.readShortLE();        kind = (byte)in.read();        avgwidth = in.readShortLE();        maxwidth = in.readShortLE();        firstchar = in.read();        lastchar = in.read();        defchar = (byte)in.read();        brkchar = (byte)in.read();        widthby = in.readShortLE();        device = in.readIntLE();        face = in.readIntLE();        bits = in.readIntLE();        bitoff = in.readIntLE();        extlen = in.readShortLE();        psext = in.readIntLE();        chartab = in.readIntLE();        res1 = in.readIntLE();        kernpairs = in.readIntLE();        res2 = in.readIntLE();        fontname = in.readIntLE();

⌨️ 快捷键说明

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