# `OS/2`: OS/2 and Windows Metrics table

The `OS/2` table is an OpenType table.

class fontTools.ttLib.tables.O_S_2f_2.Panose(**kwargs)

  Bases: `object`

  toXML(writer, ttFont)
  fromXML(name, attrs, content, ttFont)

class fontTools.ttLib.tables.O_S_2f_2.table_O_S_2f_2(tag=None)

  Bases: `DefaultTable`

  OS/2 and Windows Metrics table

  The `OS/2` table contains a variety of font-wide metrics and parameters that may be useful to an operating system or other software for system-integration purposes.

  See also https://learn.microsoft.com/en-us/typography/opentype/spec/os2

  dependencies = ['head']
  decompile(data, ttFont)
  compile(ttFont)
  toXML(writer, ttFont)
  fromXML(name, attrs, content, ttFont)
  updateFirstAndLastCharIndex(ttFont)
  property usMaxContex
  property fsFirstCharIndex
  property fsLastCharIndex
  getUnicodeRanges()

    Return the set of ‘ulUnicodeRange*’ bits currently enabled.

  setUnicodeRanges(bits)

    Set the ‘ulUnicodeRange*’ fields to the specified ‘bits’.

  recalcUnicodeRanges(ttFont, pruneOnly=False)

    Intersect the codepoints in the font’s Unicode cmap subtables with the Unicode block ranges defined in the OpenType specification (v1.7), and set the respective ‘ulUnicodeRange*’ bits if there is at least ONE intersection. If ‘pruneOnly’ is True, only clear unused bits with NO intersection.

  getCodePageRanges()

    Return the set of ‘ulCodePageRange*’ bits currently enabled.

  setCodePageRanges(bits)

    Set the ‘ulCodePageRange*’ fields to the specified ‘bits’.

  recalcCodePageRanges(ttFont, pruneOnly=False)
  recalcAvgCharWidth(ttFont)

    Recalculate xAvgCharWidth using metrics from ttFont’s ‘hmtx’ table.

    Set it to 0 if the unlikely event ‘hmtx’ table is not found.

  merge(m, tables)
  mergeMap = {'*': <function first>, 'fsFirstCharIndex': <built-in function min>, 'fsLastCharIndex': <built-in function max>, 'fsType': <function mergeOs2FsType>, 'panose': <function first>, 'sCapHeight': <function onlyExisting.<locals>.wrapper>, 'sTypoAscender': <built-in function max>, 'sTypoDescender': <built-in function min>, 'sTypoLineGap': <built-in function max>, 'sxHeight': <function onlyExisting.<locals>.wrapper>, 'tableTag': <function equal>, 'ulCodePageRange1': <function onlyExisting.<locals>.wrapper>, 'ulCodePageRange2': <function onlyExisting.<locals>.wrapper>, 'ulUnicodeRange1': <function bitwise_or>, 'ulUnicodeRange2': <function bitwise_or>, 'ulUnicodeRange3': <function bitwise_or>, 'ulUnicodeRange4': <function bitwise_or>, 'usBreakChar': <function onlyExisting.<locals>.wrapper>, 'usDefaultChar': <function onlyExisting.<locals>.wrapper>, 'usLowerOpticalPointSize': <function onlyExisting.<locals>.wrapper>, 'usMaxContext': <function onlyExisting.<locals>.wrapper>, 'usUpperOpticalPointSize': <function onlyExisting.<locals>.wrapper>, 'usWinAscent': <built-in function max>, 'usWinDescent': <built-in function max>, 'version': <built-in function max>, 'xAvgCharWidth': <function first>}

fontTools.ttLib.tables.O_S_2f_2.intersectUnicodeRanges(unicodes, inverse=False)

  Intersect a sequence of (int) Unicode codepoints with the Unicode block ranges defined in the OpenType specification v1.7, and return the set of ‘ulUnicodeRanges’ bits for which there is at least ONE intersection. If ‘inverse’ is True, return the the bits for which there is NO intersection.

      >>> intersectUnicodeRanges([0x0410]) == {9}
      True
      >>> intersectUnicodeRanges([0x0410, 0x1F000]) == {9, 57, 122}
      True
      >>> intersectUnicodeRanges([0x0410, 0x1F000], inverse=True) == (
      ...     set(range(len(OS2_UNICODE_RANGES))) - {9, 57, 122})
      True

fontTools.ttLib.tables.O_S_2f_2.calcCodePageRanges(unicodes)

  Given a set of Unicode codepoints (integers), calculate the corresponding OS/2 CodePage range bits. This is a direct translation of FontForge implementation: https://github.com/fontforge/fontforge/blob/7b2c074/fontforge/tottf.c#L3158