def Process(self, basicKerning, outputFilename): hppOutputFilename = '%s.%s' % (outputFilename, 'hpp') cppOutputFilename = '%s.%s' % (outputFilename, 'cpp') className = IOUtil.GetFileNameWithoutExtension(outputFilename) hppContent = self.__BuildHPPContent(basicKerning, className) cppContent = self.__BuildCPPContent(basicKerning, className) IOUtil.WriteFileIfChanged(hppOutputFilename, hppContent) IOUtil.WriteFileIfChanged(cppOutputFilename, cppContent)
def Process(self, basicFont: BasicFont, outputFilename: str) -> None: hppOutputFilename = '{}.{}'.format(outputFilename, 'hpp') cppOutputFilename = '{}.{}'.format(outputFilename, 'cpp') className = IOUtil.GetFileNameWithoutExtension(outputFilename) hppContent = self.__BuildHPPContent(basicFont, className) cppContent = self.__BuildCPPContent(basicFont, className) IOUtil.WriteFileIfChanged(hppOutputFilename, hppContent) IOUtil.WriteFileIfChanged(cppOutputFilename, cppContent)
def Process(formatPlugins, inputFilename, outputFilename, formatName): if outputFilename == None: outputFilename = IOUtil.GetFileNameWithoutExtension(inputFilename) formatPlugin = GetEntryByName(formatPlugins, formatName) # Read the json file and convert it into python objects content = IOUtil.ReadFileBinary(inputFilename) jsonDict = json.loads(content) atlas = BasicKerning(jsonDict, outputFilename) formatPlugin.Process(atlas, outputFilename)
def ProcessSourceFile(inputFilename: str, outputFilename: str, bitmapFontType: BitmapFontType) -> BasicFont: inputExt = IOUtil.GetFileNameExtension(inputFilename) if inputExt == '.json': return ProcessSpriteFontCreator2JsonFile(inputFilename, outputFilename) if inputExt == '.fnt': return ProcessAngelCodeFontFile(inputFilename, outputFilename, bitmapFontType) raise Exception("Unsupported input file extension: {}".format(inputExt))
def ProcessBitmapFont(self, bitmapFont: BitmapFont, outputFilename: str) -> None: jsonRootDict = self.__ToJsonDict(bitmapFont) jsonText = str( json.dumps(jsonRootDict, ensure_ascii=False, sort_keys=True, indent=2)) IOUtil.WriteFileIfChanged(outputFilename, jsonText)
def ProcessBitmapFont(self, bitmapFont: BitmapFont, outputFilename: str) -> None: dstBuffer = [] # type: List[int] offsetSize = self.__WriteHeader(dstBuffer) sizeOfHeader = len(dstBuffer) self.__WriteContent(dstBuffer, bitmapFont) content = bytearray(dstBuffer) finalOutputFilename = '{}.{}'.format(outputFilename, 'nbf') IOUtil.WriteBinaryFileIfChanged(finalOutputFilename, content)
def Process(formatPlugins: List[FormatPlugin], inputFilename: str, outputFilename: str, formatName: str, bitmapFontType: BitmapFontType) -> None: formatPlugin = GetEntryByName(formatPlugins, formatName) if outputFilename is None: outputFilename = IOUtil.GetFileNameWithoutExtension(inputFilename) if formatPlugin.PluginType == FormatPluginType.BasicFont: ProcessV1(formatPlugins, inputFilename, outputFilename, bitmapFontType, formatPlugin) else: ProcessV2(formatPlugins, inputFilename, outputFilename, bitmapFontType, formatPlugin)
def Process(self, basicKerning, outputFilename): list = [] offsetSize = self.__WriteHeader(list) sizeOfHeader = len(list) self.__WriteRanges(list, basicKerning.Ranges) self.__WriteRangeGlyphKernings(list, basicKerning.BasicGlyphKerning) self.__WriteDescription(list, basicKerning) AddString(list, basicKerning.Name) AddString(list, basicKerning.Header.PathName) # Write the number of bytes that were written to the extended header bytesWritten = len(list) - sizeOfHeader SetUInt32(list, offsetSize, bytesWritten) content = bytearray(list) finalOutputFilename = '%s.%s' % (outputFilename, 'fbk') IOUtil.WriteBinaryFileIfChanged(finalOutputFilename, content)
def Process(self, basicFont: BasicFont, outputFilename: str) -> None: dst = [] # type: List[int] offsetSize = self.__WriteHeader(dst) sizeOfHeader = len(dst) self.__WriteRanges(dst, basicFont.Ranges) self.__WriteRangeGlyphKernings(dst, basicFont.BasicGlyphKerning) self.__WriteDescription(dst, basicFont) FormatPluginFontBasicKerningUtil.AddString(dst, basicFont.Name) FormatPluginFontBasicKerningUtil.AddString(dst, basicFont.Header.PathName) # Write the number of bytes that were written to the extended header bytesWritten = len(dst) - sizeOfHeader FormatPluginFontBasicKerningUtil.SetUInt32(dst, offsetSize, bytesWritten) content = bytearray(dst) finalOutputFilename = '{}.{}'.format(outputFilename, 'fbk') IOUtil.WriteBinaryFileIfChanged(finalOutputFilename, content)
def ProcessAngelCodeFontFile(inputFilename: str, name: str, bitmapFontType: BitmapFontType) -> BasicFont: content = IOUtil.ReadFile(inputFilename) bitmapFont = AngelCodeFontReader.DecodeAsBitmapFont( content, bitmapFontType) return TypeConverter.ToBasicFont(bitmapFont)
def ProcessSpriteFontCreator2JsonFile(inputFilename: str, name: str) -> BasicFont: # Read the json file and convert it into python objects content = IOUtil.ReadFile(inputFilename) return SpriteFontCreator2Reader.Decode(content, name)
def ProcessAngelCodeFontFileAsBitmapFont( inputFilename: str, name: str, bitmapFontType: BitmapFontType) -> BitmapFont: content = IOUtil.ReadFile(inputFilename) return AngelCodeFontReader.DecodeAsBitmapFont(content, bitmapFontType)