Package com.sun.pdfview.font.ttf

Examples of com.sun.pdfview.font.ttf.CMapFormat4


     * @param ttf the font
     * @param cmap the CMap table
     * @return true if the font was changed, or false if it was left as-is
     */
    private boolean fixCMapTable (TrueTypeFont ttf, CmapTable cmap) {
        CMapFormat4 fourMap = null;
        CMapFormat0 zeroMap = null;

        for (int i = 0; i < mapIDs.length; i += 2) {
            CMap map = cmapTable.getCMap (mapIDs[i], mapIDs[i + 1]);
            if (map != null) {
                if (fourMap == null && map instanceof CMapFormat4) {
                    fourMap = (CMapFormat4) map;
                } else if (zeroMap == null && map instanceof CMapFormat0) {
                    zeroMap = (CMapFormat0) map;
                }
            }
        }

        // if there were no maps, we could have problems.  Just try creating
        // an identity map
        if (zeroMap == null && fourMap == null) {
            fourMap = (CMapFormat4) CMap.createMap ((short) 4, (short) 0);
            fourMap.addSegment ((short) getFirstChar (),
                    (short) getLastChar (),
                    (short) 0);
        }

        // create our map based on the type 0 map, since PDF seems
        // to prefer a type 0 map (Java prefers a unicode map)
        if (zeroMap != null) {
            fourMap = (CMapFormat4) CMap.createMap ((short) 4, (short) 0);

            // add the mappings from 0 to null and 1 to notdef
            fourMap.addSegment ((short) 0, (short) 1, (short) 0);

            for (int i = getFirstChar (); i <= getLastChar (); i++) {
                short value = (short) (zeroMap.map ((byte) i) & 0xff);
                if (value != 0) {
                    fourMap.addSegment ((short) i, (short) i,
                            (short) (value - i));
                }
            }
        }

        // now that we have a type four map, remap control characters
        for (int i = 0; i < controlChars.length; i++) {
            short idx = (short) (0xf000 | controlChars[i]);
            short value = (short) fourMap.map (controlChars[i]);

            fourMap.addSegment (idx, idx, (short) (value - idx));
        }

        // create a whole new table with just our map
        cmap = (CmapTable) TrueTypeTable.createTable (ttf, "cmap");
        cmap.addCMap ((short) 3, (short) 1, fourMap);
View Full Code Here


     * @param ttf the font
     * @param cmap the CMap table
     * @return true if the font was changed, or false if it was left as-is
     */
    private boolean fixCMapTable (TrueTypeFont ttf, CmapTable cmap) {
        CMapFormat4 fourMap = null;
        CMapFormat0 zeroMap = null;

        for (int i = 0; i < mapIDs.length; i += 2) {
            CMap map = this.cmapTable.getCMap (mapIDs[i], mapIDs[i + 1]);
            if (map != null) {
                if (fourMap == null && map instanceof CMapFormat4) {
                    fourMap = (CMapFormat4) map;
                } else if (zeroMap == null && map instanceof CMapFormat0) {
                    zeroMap = (CMapFormat0) map;
                }
            }
        }

        // if there were no maps, we could have problems.  Just try creating
        // an identity map
        if (zeroMap == null && fourMap == null) {
            fourMap = (CMapFormat4) CMap.createMap ((short) 4, (short) 0);
            fourMap.addSegment ((short) getFirstChar (),
                    (short) getLastChar (),
                    (short) 0);
        }

        // create our map based on the type 0 map, since PDF seems
        // to prefer a type 0 map (Java prefers a unicode map)
        if (zeroMap != null) {
            fourMap = (CMapFormat4) CMap.createMap ((short) 4, (short) 0);

            // add the mappings from 0 to null and 1 to notdef
            fourMap.addSegment ((short) 0, (short) 1, (short) 0);

            for (int i = getFirstChar (); i <= getLastChar (); i++) {
                short value = (short) (zeroMap.map ((byte) i) & 0xff);
                if (value != 0) {
                    fourMap.addSegment ((short) i, (short) i,
                            (short) (value - i));
                }
            }
        }

        // now that we have a type four map, remap control characters
        for (int i = 0; i < controlChars.length; i++) {
            short idx = (short) (0xf000 | controlChars[i]);
            short value = (short) fourMap.map (controlChars[i]);

            fourMap.addSegment (idx, idx, (short) (value - idx));
        }

        // create a whole new table with just our map
        cmap = (CmapTable) TrueTypeTable.createTable (ttf, "cmap");
        cmap.addCMap ((short) 3, (short) 1, fourMap);
View Full Code Here

    public void addSegment(short startCode, short endCode, char[] map) {
        if (map.length != (endCode - startCode) + 1) {
            throw new IllegalArgumentException("Wrong number of entries in map");
        }
       
        Segment s = new Segment(startCode, endCode, true);
        // make sure we remove any old entries
        this.segments.remove(s);
        this.segments.put(s, map);
    }
View Full Code Here

   
    /**
     * Add a segment with an idDelta
     */
    public void addSegment(short startCode, short endCode, short idDelta) {
        Segment s = new Segment(startCode, endCode, false);
        // make sure we remove any old entries
        this.segments.remove(s);
        this.segments.put(s, Integer.valueOf(idDelta));
    }
View Full Code Here

   
    /**
     * Remove a segment
     */
    public void removeSegment(short startCode, short endCode) {
        Segment s = new Segment(startCode, endCode, true);
        this.segments.remove(s);
    }
View Full Code Here

        // add the size of each segment header
        size += this.segments.size() * 8;
       
        // add the total number of mappings times the size of a mapping
        for (Iterator i = this.segments.keySet().iterator(); i.hasNext();) {
            Segment s = (Segment) i.next();
           
            // see if there's a map
            if (s.hasMap) {
                // if there is, add its size
                char[] map = (char[]) this.segments.get(s);
View Full Code Here

     */
    @Override
  public char map(char src) {
        // find first segment with endcode > src
        for (Iterator i = this.segments.keySet().iterator(); i.hasNext();) {
            Segment s = (Segment) i.next();
           
            if (s.endCode >= src) {
                // are we within range?
                if (s.startCode <= src) {
                    if (s.hasMap) {
View Full Code Here

     */
    @Override
  public char reverseMap(short glyphID) {
        // look at each segment
        for (Iterator i = this.segments.keySet().iterator(); i.hasNext();) {
            Segment s = (Segment) i.next();
           
            // see if we have a map or a delta
            if (s.hasMap) {
                char[] map = (char[]) this.segments.get(s);
               
View Full Code Here

        buf.putShort(getEntrySelector());
        buf.putShort(getRangeShift());
       
        // write the endCodes
        for (Iterator<Segment> i = this.segments.keySet().iterator(); i.hasNext();) {
            Segment s = i.next();
            buf.putShort((short) s.endCode);
        }
       
        // write the pad
        buf.putShort((short) 0);
       
        // write the startCodes
        for (Iterator<Segment> i = this.segments.keySet().iterator(); i.hasNext();) {
            Segment s = i.next();
            buf.putShort((short) s.startCode);
        }
       
        // write the idDeltas for segments using deltas
        for (Iterator<Segment> i = this.segments.keySet().iterator(); i.hasNext();) {
            Segment s = i.next();
           
            if (!s.hasMap) {
                Integer idDelta = (Integer) this.segments.get(s);
                buf.putShort(idDelta.shortValue());
            } else {
                buf.putShort((short) 0);
            }
        }
       
        // the start of the glyph array
        int glyphArrayOffset = 16 + (8 * getSegmentCount());
       
        // write the idRangeOffsets and maps for segments using maps
        for (Iterator<Segment> i = this.segments.keySet().iterator(); i.hasNext();) {
            Segment s = i.next();
           
            if (s.hasMap) {
                // first set the offset, which is the number of bytes from the
                // current position to the current offset
                buf.putShort((short) (glyphArrayOffset - buf.position()));
View Full Code Here

        buf.append(indent + "SearchRange  : " + getSearchRange() + "\n");
        buf.append(indent + "EntrySelector: " + getEntrySelector() + "\n");
        buf.append(indent + "RangeShift   : " + getRangeShift() + "\n");
       
        for (Iterator<Segment> i = this.segments.keySet().iterator(); i.hasNext();) {
            Segment s = i.next();
           
            buf.append(indent);
            buf.append("Segment: " + Integer.toHexString(s.startCode));
            buf.append("-" + Integer.toHexString(s.endCode) + " ");
            buf.append("hasMap: " + s.hasMap + " ");
View Full Code Here

TOP

Related Classes of com.sun.pdfview.font.ttf.CMapFormat4

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.