code: def compile(self, ttFont):
      metrics = []
      hasNegativeAdvances = False
      for glyphName in ttFont.getGlyphOrder():
          advanceWidth, sideBearing = self.metrics[glyphName]
          if advanceWidth < 0:
              log.error(
                  "Glyph %r has negative advance %s"
                  % (glyphName, self.advanceName)
              )
              hasNegativeAdvances = True
          metrics.append([advanceWidth, sideBearing])
  
      headerTable = ttFont.get(self.headerTag)
      if headerTable is not None:
          lastAdvance = metrics[-1][0]
          lastIndex = len(metrics)
          while metrics[lastIndex - 2][0] == lastAdvance:
              lastIndex -= 1
              if lastIndex <= 1:
                  # all advances are equal
                  lastIndex = 1
                  break
          additionalMetrics = metrics[lastIndex:]
          additionalMetrics = [
              otRound(sb) for _, sb in additionalMetrics
          ]
          metrics = metrics[:lastIndex]
          numberOfMetrics = len(metrics)
          setattr(
              headerTable, self.numberOfMetricsName, numberOfMetrics
          )
      else:
          # no hhea/vhea, can't store numberOfMetrics; assume == numGlyphs
          numberOfMetrics = ttFont["maxp"].numGlyphs
          additionalMetrics = []
  
      allMetrics = []
      for advance, sb in metrics:
          allMetrics.extend([otRound(advance), otRound(sb)])
      metricsFmt = ">" + self.longMetricFormat * numberOfMetrics
      try:
          data = struct.pack(metricsFmt, *allMetrics)
      except struct.error as e:
          if "out of range" in str(e) and hasNegativeAdvances:
              raise ttLib.TTLibError(
                  "'%s' table can't contain negative advance %ss"
                  % (self.tableTag, self.advanceName)
              )
          else:
              raise
      additionalMetrics = array.array("h", additionalMetrics)
      if sys.byteorder != "big":
          additionalMetrics.byteswap()
      data = data + additionalMetrics.tobytes()
      return data
  
file_path: catboost/contrib/python/fonttools/fontTools/ttLib/tables/_h_m_t_x.py
imports: from fontTools.misc.roundTools import otRound
  from fontTools import ttLib
  from fontTools.misc.textTools import safeEval
  from .None import DefaultTable
  import sys
  import struct
  import array
  import logging
label_desc: Use image node_id 2 for calling the table__h_m_t_x obj's underlying member method code with example usage: obj.compile(ttFont) and returns: data