diff --git a/build/bin2cpp.bat b/build/bin2cpp.bat new file mode 100644 index 000000000..93ee1feb1 --- /dev/null +++ b/build/bin2cpp.bat @@ -0,0 +1,7 @@ + +rem @echo off + + +premake4 --file=bin2cpp.lua --binfile="../btgui/FontFiles/OpenSans.ttf" --cppfile="../btgui/FontFiles/OpenSans.cpp" --stringname="OpenSansData" bin2cpp + +pause \ No newline at end of file diff --git a/build/bin2cpp.lua b/build/bin2cpp.lua new file mode 100644 index 000000000..b3d82a4b8 --- /dev/null +++ b/build/bin2cpp.lua @@ -0,0 +1,48 @@ +function convertFile(filenameIn, filenameOut, stringname) + print("\nfilenameOut = " .. filenameOut) + local f = assert(io.open(filenameIn, "rb")) + + local fw = io.open(filenameOut,"w") + fw:write(string.format("char %s[]={", stringname)) + local block = 10 + while true do + local bytes = f:read(block) + if not bytes then break end + for b in string.gfind(bytes, ".") do + fw:write(string.format("char(%u),", string.byte(b))) + end + --io.write(string.rep(" ", block - string.len(bytes) + 1)) + --io.write(string.gsub(bytes, "%c", "."), "\n") + fw:write(string.format("\n")) + end + fw:write(string.format("\n};")) + +end + + + newoption { + trigger = "binfile", + value = "binpath", + description = "full path to the binary input file" + } + + newoption { + trigger = "cppfile", + value = "path", + description = "full path to the cpp output file" + } + + newoption { + trigger = "stringname", + value = "var", + description = "name of the variable name in the cppfile that contains the binary data" + } + + newaction { + trigger = "bin2cpp", + description = "convert binary file into cpp source", + execute = function () + convertFile( _OPTIONS["binfile"] , _OPTIONS["cppfile"], _OPTIONS["stringname"]) + + end +} \ No newline at end of file