code: def lib_convertCFFToCFF2(cff, otFont):
      # This assumes a decompiled CFF table.
      cff2GetGlyphOrder = cff.otFont.getGlyphOrder
      topDictData = TopDictIndex(None, cff2GetGlyphOrder, None)
      topDictData.items = cff.topDictIndex.items
      cff.topDictIndex = topDictData
      topDict = topDictData[0]
      if hasattr(topDict, "Private"):
          privateDict = topDict.Private
      else:
          privateDict = None
      opOrder = buildOrder(topDictOperators2)
      topDict.order = opOrder
      topDict.cff2GetGlyphOrder = cff2GetGlyphOrder
      if not hasattr(topDict, "FDArray"):
          fdArray = topDict.FDArray = FDArrayIndex()
          fdArray.strings = None
          fdArray.GlobalSubrs = topDict.GlobalSubrs
          topDict.GlobalSubrs.fdArray = fdArray
          charStrings = topDict.CharStrings
          if charStrings.charStringsAreIndexed:
              charStrings.charStringsIndex.fdArray = fdArray
          else:
              charStrings.fdArray = fdArray
          fontDict = FontDict()
          fontDict.setCFF2(True)
          fdArray.append(fontDict)
          fontDict.Private = privateDict
          privateOpOrder = buildOrder(privateDictOperators2)
          if privateDict is not None:
              for entry in privateDictOperators:
                  key = entry[1]
                  if key not in privateOpOrder:
                      if key in privateDict.rawDict:
                          # print "Removing private dict", key
                          del privateDict.rawDict[key]
                      if hasattr(privateDict, key):
                          delattr(privateDict, key)
                          # print "Removing privateDict attr", key
      else:
          # clean up the PrivateDicts in the fdArray
          fdArray = topDict.FDArray
          privateOpOrder = buildOrder(privateDictOperators2)
          for fontDict in fdArray:
              fontDict.setCFF2(True)
              for key in list(fontDict.rawDict.keys()):
                  if key not in fontDict.order:
                      del fontDict.rawDict[key]
                      if hasattr(fontDict, key):
                          delattr(fontDict, key)
  
              privateDict = fontDict.Private
              for entry in privateDictOperators:
                  key = entry[1]
                  if key not in privateOpOrder:
                      if key in privateDict.rawDict:
                          # print "Removing private dict", key
                          del privateDict.rawDict[key]
                      if hasattr(privateDict, key):
                          delattr(privateDict, key)
                          # print "Removing privateDict attr", key
      # Now delete up the deprecated topDict operators from CFF 1.0
      for entry in topDictOperators:
          key = entry[1]
          if key not in opOrder:
              if key in topDict.rawDict:
                  del topDict.rawDict[key]
              if hasattr(topDict, key):
                  delattr(topDict, key)
  
      # At this point, the Subrs and Charstrings are all still T2Charstring class
      # easiest to fix this by compiling, then decompiling again
      cff.major = 2
      file = BytesIO()
      cff.compile(file, otFont, isCFF2=True)
      file.seek(0)
      cff.decompile(file, otFont, isCFF2=True)
  
imports: from collections import namedtuple
  from fontTools.cffLib import maxStackLimit, TopDictIndex, buildOrder, topDictOperators, topDictOperators2, privateDictOperators, privateDictOperators2, FDArrayIndex, FontDict, VarStoreData
  from io import BytesIO
  from fontTools.cffLib.specializer import specializeCommands, commandsToProgram
  from fontTools.ttLib import newTable
  from fontTools import varLib
  from fontTools.varLib.models import allEqual
  from fontTools.misc.roundTools import roundFunc
  from fontTools.misc.psCharStrings import T2CharString, T2OutlineExtractor
  from fontTools.pens.t2CharStringPen import T2CharStringPen
  from functools import partial
  from .errors import VarLibCFFDictMergeError, VarLibCFFPointTypeMergeError, VarLibCFFHintTypeMergeError, VarLibMergeError
label_desc: Use image node_id 2 for calling a global function with example usage: lib_convertCFFToCFF2(cff, otFont) without return types