def _setupTable_hhea_or_vhea(self, tag):
        if tag not in self.tables:
            return
        if tag == "hhea":
            isHhea = True
        else:
            isHhea = False
        self.otf[tag] = table = newTable(tag)
        mtxTable = self.otf.get(tag[0] + "mtx")
        font = self.ufo
        if isHhea:
            table.tableVersion = 0x00010000
        else:
            table.tableVersion = 0x00011000
        commonPrefix = "openType%s" % tag.title()
        if isHhea:
            metricsPrefix = commonPrefix
        else:
            metricsPrefix = "openType%sVertTypo" % tag.title()
        metricsDict = {
            "ascent": "%sAscender" % metricsPrefix,
            "descent": "%sDescender" % metricsPrefix,
            "lineGap": "%sLineGap" % metricsPrefix,
            "caretSlopeRise": "%sCaretSlopeRise" % commonPrefix,
            "caretSlopeRun": "%sCaretSlopeRun" % commonPrefix,
            "caretOffset": "%sCaretOffset" % commonPrefix,
        }
        for otfName, ufoName in metricsDict.items():
            setattr(table, otfName,
                    otRound(getAttrWithFallback(font.info, ufoName)))
        advances = []
        firstSideBearings = []
        secondSideBearings = []
        extents = []
        if mtxTable is not None:
            for glyphName in self.allGlyphs:
                advance, firstSideBearing = mtxTable[glyphName]
                advances.append(advance)
                bounds = self.glyphBoundingBoxes[glyphName]
                if bounds is None:
                    continue
                if isHhea:
                    boundsAdvance = (bounds.xMax - bounds.xMin)
                    extent = firstSideBearing + boundsAdvance
                else:
                    boundsAdvance = (bounds.yMax - bounds.yMin)
                    extent = firstSideBearing + boundsAdvance
                secondSideBearing = advance - firstSideBearing - boundsAdvance
                firstSideBearings.append(firstSideBearing)
                secondSideBearings.append(secondSideBearing)
                extents.append(extent)
        setattr(table,
                "advance%sMax" % ("Width" if isHhea else "Height"),
                max(advances) if advances else 0)
        setattr(table,
                "min%sSideBearing" % ("Left" if isHhea else "Top"),
                min(firstSideBearings) if firstSideBearings else 0)
        setattr(table,
                "min%sSideBearing" % ("Right" if isHhea else "Bottom"),
                min(secondSideBearings) if secondSideBearings else 0)
        setattr(table,
                "%sMaxExtent" % ("x" if isHhea else "y"),
                max(extents) if extents else 0)
        if isHhea:
            reserved = range(4)
        else:
            reserved = range(1, 5)
        for i in reserved:
            setattr(table, "reserved%i" % i, 0)
        table.metricDataFormat = 0
        setattr(table,
                "numberOf%sMetrics" % ("H" if isHhea else "V"),
                len(self.allGlyphs))