Class PDFGlyphWidthTable


  • public class PDFGlyphWidthTable
    extends java.lang.Object
    This class is used to map cids to widths. Widths are always indexed by character code. For single byte fonts, we allocate a single 256 entry array for quick character code -> width lookup. Instead of using a 64K entry array for 2 byte fonts, widths are represented by a sorted array of WidthTableEntries.

    The pdf format for widths looks like: [cid [w1 w2 w3] cidfirst cidlast w4 cid2 [w5 w6 w7 w8]]

    so the widths for a range of cids can be specified as an array of widths, or by a single width that applies to every cid in the range.

    All WidthTableEntries have a startcid & endcid range and can then hold either a) an array of endcid-startcid+1 floats b) a single float

    The widthtable can then do a binary search through the table to find the specific widthtable entry. The worst possible case would be a table of 64k entries, each describing a single glyph, and a search for a glyph through this would take log2(65536) = 16 hops through a huge table. Any fontlist this large would actually just revert to a single entry with 64k widths, so there would be no searching. Average case would be a much smaller, especially since this is often used for font subsets.

    • Constructor Summary

      Constructors 
      Constructor Description
      PDFGlyphWidthTable​(java.util.List pdfwidths, java.lang.Object defwidth)
      Main constructor.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      float getWidth​(int cid)
      Binary search the list and return the width
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • PDFGlyphWidthTable

        public PDFGlyphWidthTable​(java.util.List pdfwidths,
                                  java.lang.Object defwidth)
        Main constructor. pdfwidths is the array from the CIDfont's /W entry, and defwidth is the /DW entry. Both entries are optional, in which case all the widths are 1000.
    • Method Detail

      • getWidth

        public float getWidth​(int cid)
        Binary search the list and return the width