class HexaPDF::Type::CIDFont

See: PDF2.0 s9.7.4
font.
Represents a generic CIDFont which can only be used as a descendant font of a composite PDF

def set_widths(widths, default_width: DEFAULT_WIDTH)

See: PDF2.0 s9.7.4.3

width.
Sets the /W and /DW keys using the given array of [CID, width] pairs and an optional default
def set_widths(widths, default_width: DEFAULT_WIDTH)
  if widths.empty?
    (default_width == DEFAULT_WIDTH ? delete(:DW) : self[:DW] = default_width)
    delete(:W)
  else
    self[:DW] = default_width.to_i unless default_width == DEFAULT_WIDTH
    self[:W] = w = []
    last_cid = -10
    cur_widths = nil
    widths.each do |cid, width|
      if last_cid + 1 != cid
        cur_widths = []
        w << cid << cur_widths
      end
      cur_widths << width.to_i
      last_cid = cid
    end
  end
end

def width(cid)

Note that in contrast to other fonts, the argument must *not* be a code point but a CID!

missing.
Returns the unscaled width of the given CID in glyph units, or 0 if the width for the CID is
def width(cid)
  widths[cid] || value[:DW] || DEFAULT_WIDTH
end

def widths

See: PDF2.0 s9.7.4.3

Note that the hash is cached internally when accessed the first time.

Returns a hash mapping CIDs to their respective width.
def widths
  cache(:widths) do
    result = {}
    index = 0
    array = self[:W] || []
    while index < array.size
      entry = array[index]
      value = array[index + 1]
      if value.kind_of?(Array)
        value.each_with_index {|width, i| result[entry + i] = width }
        index += 2
      else
        width = array[index + 2]
        entry.upto(value) {|cid| result[cid] = width }
        index += 3
      end
    end
    result
  end
end