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

📄 cfffont.java

📁 iText是一个能够快速产生PDF文件的java类库。iText的java类对于那些要产生包含文本
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
        
        while (!gotKey) {
            char b0 = getCard8();
            if (b0 == 29) {
                int item = getInt();
                args[arg_count] = new Integer(item);
                arg_count++;
                //System.err.println(item+" ");
                continue;
            }
            if (b0 == 28) {
                short item = getShort();
                args[arg_count] = new Integer(item);
                arg_count++;
                //System.err.println(item+" ");
                continue;
            }
            if (b0 >= 32 && b0 <= 246) {
                byte item = (byte) (b0-139);
                args[arg_count] = new Integer(item);
                arg_count++;
                //System.err.println(item+" ");
                continue;
            }
            if (b0 >= 247 && b0 <= 250) {
                char b1 = getCard8();
                short item = (short) ((b0-247)*256+b1+108);
                args[arg_count] = new Integer(item);
                arg_count++;
                //System.err.println(item+" ");
                continue;
            }
            if (b0 >= 251 && b0 <= 254) {
                char b1 = getCard8();
                short item = (short) (-(b0-251)*256-b1-108);
                args[arg_count] = new Integer(item);
                arg_count++;
                //System.err.println(item+" ");
                continue;
            }
            if (b0 == 30) {
                String item = "";
                boolean done = false;
                char buffer = 0;
                byte avail = 0;
                int  nibble = 0;
                while (!done) {
                    // get a nibble
                    if (avail==0) { buffer = getCard8(); avail=2; }
                    if (avail==1) { nibble = (buffer / 16); avail--; }
                    if (avail==2) { nibble = (buffer % 16); avail--; }
                    switch (nibble) {
                        case 0xa: item += "." ; break;
                        case 0xb: item += "E" ; break;
                        case 0xc: item += "E-"; break;
                        case 0xe: item += "-" ; break;
                        case 0xf: done=true   ; break;
                        default:
                            if (nibble >= 0 && nibble <= 9)
                                item += String.valueOf(nibble);
                            else {
                                item += "<NIBBLE ERROR: " + nibble + '>';
                                done = true;
                            }
                            break;
                    }
                }
                args[arg_count] = item;
                arg_count++;
                //System.err.println(" real=["+item+"]");
                continue;
            }
            if (b0 <= 21) {
                gotKey=true;
                if (b0 != 12) key = operatorNames[b0];
                else key = operatorNames[32 + getCard8()];
                //for (int i=0; i<arg_count; i++)
                //  System.err.print(args[i].toString()+" ");
                //System.err.println(key+" ;");
                continue;
            }
        }
    }
    
    /** List items for the linked list that builds the new CID font.
     */
    
    protected static abstract class Item {
        protected int myOffset = -1;
        /** remember the current offset and increment by item's size in bytes. */
        public void increment(int[] currentOffset) {
            myOffset = currentOffset[0];
        }
        /** Emit the byte stream for this item. */
        public void emit(byte[] buffer) {}
        /** Fix up cross references to this item (applies only to markers). */
        public void xref() {}
    }
    
    protected static abstract class OffsetItem extends Item {
        public int value;
        /** set the value of an offset item that was initially unknown.
         * It will be fixed up latex by a call to xref on some marker.
         */
        public void set(int offset) { this.value = offset; }
    }
    
    
    /** A range item.
     */
    
    protected static final class RangeItem extends Item {
        public int offset, length;
        private RandomAccessFileOrArray buf;
        public RangeItem(RandomAccessFileOrArray buf, int offset, int length) {
            this.offset = offset;
            this.length = length;
            this.buf = buf;
        }
        public void increment(int[] currentOffset) {
            super.increment(currentOffset);
            currentOffset[0] += length;
        }
        public void emit(byte[] buffer) {
            //System.err.println("range emit offset "+offset+" size="+length);
            try {
                buf.seek(offset);
                for (int i=myOffset; i<myOffset+length; i++)
                    buffer[i] = buf.readByte();
            }
            catch (Exception e) {
                throw new ExceptionConverter(e);
            }
            //System.err.println("finished range emit");
        }
    }
    
    /** An index-offset item for the list.
     * The size denotes the required size in the CFF. A positive
     * value means that we need a specific size in bytes (for offset arrays)
     * and a negative value means that this is a dict item that uses a
     * variable-size representation.
     */
    static protected final class IndexOffsetItem extends OffsetItem {
        public final int size;
        public IndexOffsetItem(int size, int value) {this.size=size; this.value=value;}
        public IndexOffsetItem(int size) {this.size=size; }
        
        public void increment(int[] currentOffset) {
            super.increment(currentOffset);
            currentOffset[0] += size;
        }
        public void emit(byte[] buffer) {
            int i=0;
            switch (size) {
                case 4:
                    buffer[myOffset+i] = (byte) ((value >>> 24) & 0xff);
                    i++;
                case 3:
                    buffer[myOffset+i] = (byte) ((value >>> 16) & 0xff);
                    i++;
                case 2:
                    buffer[myOffset+i] = (byte) ((value >>>  8) & 0xff);
                    i++;
                case 1:
                    buffer[myOffset+i] = (byte) ((value >>>  0) & 0xff);
                    i++;
            }
            /*
            int mask = 0xff;
            for (int i=size-1; i>=0; i--) {
                buffer[myOffset+i] = (byte) (value & mask);
                mask <<= 8;
            }
             */
        }
    }
    
    static protected final class IndexBaseItem extends Item {
        public IndexBaseItem() {}
    }
    
    static protected final class IndexMarkerItem extends Item {
        private OffsetItem offItem;
        private IndexBaseItem indexBase;
        public IndexMarkerItem(OffsetItem offItem, IndexBaseItem indexBase) {
            this.offItem   = offItem;
            this.indexBase = indexBase;
        }
        public void xref() {
            //System.err.println("index marker item, base="+indexBase.myOffset+" my="+this.myOffset);
            offItem.set(this.myOffset-indexBase.myOffset+1);
        }
    }
    /**
     * TODO To change the template for this generated type comment go to
     * Window - Preferences - Java - Code Generation - Code and Comments
     */
    static protected final class SubrMarkerItem extends Item {
        private OffsetItem offItem;
        private IndexBaseItem indexBase;
        public SubrMarkerItem(OffsetItem offItem, IndexBaseItem indexBase) {
            this.offItem   = offItem;
            this.indexBase = indexBase;
        }
        public void xref() {
            //System.err.println("index marker item, base="+indexBase.myOffset+" my="+this.myOffset);
            offItem.set(this.myOffset-indexBase.myOffset);
        }
    }
    
    
    /** an unknown offset in a dictionary for the list.
     * We will fix up the offset later; for now, assume it's large.
     */
    static protected final class DictOffsetItem extends OffsetItem {
        public final int size;
        public DictOffsetItem() {this.size=5; }
        
        public void increment(int[] currentOffset) {
            super.increment(currentOffset);
            currentOffset[0] += size;
        }
        // this is incomplete!
        public void emit(byte[] buffer) {
            if (size==5) {
                buffer[myOffset]   = 29;
                buffer[myOffset+1] = (byte) ((value >>> 24) & 0xff);
                buffer[myOffset+2] = (byte) ((value >>> 16) & 0xff);
                buffer[myOffset+3] = (byte) ((value >>>  8) & 0xff);
                buffer[myOffset+4] = (byte) ((value >>>  0) & 0xff);
            }
        }
    }
    
	/** Card24 item.
     */
    
    static protected final class UInt24Item extends Item {
        public int value;
        public UInt24Item(int value) {this.value=value;}
        
        public void increment(int[] currentOffset) {
            super.increment(currentOffset);
            currentOffset[0] += 3;
        }
        // this is incomplete!
        public void emit(byte[] buffer) {
        	buffer[myOffset+0] = (byte) ((value >>> 16) & 0xff);
            buffer[myOffset+1] = (byte) ((value >>> 8) & 0xff);
            buffer[myOffset+2] = (byte) ((value >>> 0) & 0xff);
        }
    }
    
    /** Card32 item.
     */
    
    static protected final class UInt32Item extends Item {
        public int value;
        public UInt32Item(int value) {this.value=value;}
        
        public void increment(int[] currentOffset) {
            super.increment(currentOffset);
            currentOffset[0] += 4;
        }
        // this is incomplete!
        public void emit(byte[] buffer) {
        	buffer[myOffset+0] = (byte) ((value >>> 24) & 0xff);
        	buffer[myOffset+1] = (byte) ((value >>> 16) & 0xff);
            buffer[myOffset+2] = (byte) ((value >>> 8) & 0xff);
            buffer[myOffset+3] = (byte) ((value >>> 0) & 0xff);
        }
    }

    /** A SID or Card16 item.
     */
    
    static protected final class UInt16Item extends Item {
        public char value;
        public UInt16Item(char value) {this.value=value;}
        
        public void increment(int[] currentOffset) {
            super.increment(currentOffset);
            currentOffset[0] += 2;
        }
        // this is incomplete!
        public void emit(byte[] buffer) {
            buffer[myOffset+0] = (byte) ((value >>> 8) & 0xff);
            buffer[myOffset+1] = (byte) ((value >>> 0) & 0xff);
        }
    }
    
    /** A Card8 item.
     */

⌨️ 快捷键说明

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