Package: bawr
BAWRThis is a tool to automate the icons generation from sets of svg files into fonts and atlases.The main purpose of this tool is to add it to the build process of your c++ project and let it do all the work, then you can use your svg icons as fonts
or as spritesheets.The project url is:https://github.com/mnesarco/bawrThis project is based on a previous project:https://github.com/mnesarco/ff-batchFeaturesGenerate TrueType fonts from svg collections.Generate png textures from svg collections.Embed binaries into c++ sources ready to link.Generate ImGui Font Loaders (c++). (howto)Generate c++ Atlas Maps.Generate c++ Font constants as Macros and/or as const/constexpr.Apply transformation to svg files during the generation.Textual transformationsFont forge supported transformationsRequirementsPython 3.6+FontForge 20170924+Inkscape 1.0+InstallBuild from sourcesgitclonehttps:://github.com/mnesarco/bawr.gitcdbawr

python3-mpipinstall--upgradebuild
python3-mpipinstallwheel

python3-mbuildpython3-mpipinstalldist/bawr-0.0.3-py3-none-any.whlOr from pypi:python3-mpipinstallbawrTerminologyConceptDescriptionSvg IconIt is just a file in .svg format. It must be a square.Icon set or CollectionIt is a folder with svg iconsConfiguration fileIt is a python file with all the options to generate your files. By convention it is called config.pyUsageCreate a folderPut a file namedconfig.py(you can copy the one from examples dirhttps://github.com/mnesarco/bawr/tree/main/examples)Add folders with svg iconsAdjust the configuration (edit config.py)Call bawrcdexamples
python3-mbawr.toolExamplesYou can use the examples dir (https://github.com/mnesarco/bawr/tree/main/examples) as a template for your project:examples/
├──config.py
├──icons/
└──bootstrap-icons/Result (generated files):examples/build/
├──atlas_cells.hpp
├──atlas.cpp
├──atlas.hpp
├──atlas.png
├──my-icons_codes.hpp
├──my-icons.cpp
├──my-icons.hpp
├──my-icons_loader.hpp
└──my-icons.ttfConfiguration (config.py)#------------------------------------------------------------------------------# Import all required stuff:#------------------------------------------------------------------------------frombawr.configimport*#------------------------------------------------------------------------------# Define an environment (Use the name that you want, but extend Environment):#------------------------------------------------------------------------------classEnv(Environment):# [Optional] FONTFORGE_PATH = Path to fontforge executable, deduced if it is in PATH# FONTFORGE_PATH = ...# [Optional] INKSCAPE_PATH = Path to inkscape executable, deduced if it is in PATH# INKSCAPE_PATH = ...# [Optional] BAWR_OUTPUT_DIR = Where all the output will be generated. Default = ./build# BAWR_OUTPUT_DIR = ...# [Optional] BAWR_SOURCE_DIR = Where all the icon folders will be found. Default = ./#  BAWR_SOURCE_DIR = ...pass#------------------------------------------------------------------------------# Define your icon sets (extend IconSet):#------------------------------------------------------------------------------classBootstrapIcons(IconSet):# [Mandatory] src = directory name (which contains svg icons)src='bootstrap-icons'# [Optional] select = selection of icons from the directory: list( tuple(file-name, glyph-name) )select=[('info-circle','infoCircle'),('file-earmark','fileEarmark'),('folder2-open','folderOpen'),('hdd','save'),('file-earmark-arrow-up','fileImport'),('file-earmark-arrow-down','fileExport'),('folder','folder'),('sliders','sliders'),('eye','eye'),('layers','layers'),]# [Optional] options = Special options for generatorsoptions={"font_transformation":[('scale',0.75,0.75)],"atlas_preprocessors":[RegexReplacePreprocessor({"currentColor":"#ffffff",'width="1em"':'width="16"','height="1em"':'height="16"',})],"atlas_margin":0.0625}# Another icon set with different optionsclassMyIcons(IconSet):src='icons'options={"atlas_preprocessors":[RegexReplacePreprocessor({'fill:#000000':"fill:#ffffff",'stroke:#000000':'stroke:#ffffff',})]}#------------------------------------------------------------------------------# [Optional]# Define Font generator to generate truetype fonts using FontForge# (extend Font)#------------------------------------------------------------------------------classMyFont(Font):# Generated font copyright notice [Mandatory]copyright="Copyright 2020 Frank D. Martinez M."# Font name [Mandatory]name="my-icons"# Font family [Mandatory]family="my-icons"# First font glyph code [Optional] (default = 0xe000)# start_code = 0xe000# List ot tuple of the icon sets included in this font [Mandatory]collections=(BootstrapIcons,MyIcons)# Global font transformation [Optiona] (See: Font transformations)# transformation = []# Output format [Optional] (default = ['ttf'])# output_formats = ['ttf']# Verbose output. Shows glyph generation details [Optional] (default = False)# verbose = False#------------------------------------------------------------------------------# [Optional]# You can generate a C++ font header file with glyph codes ready to use in C++.# (extend CppFontHeader)#------------------------------------------------------------------------------classMyCppFontH(CppFontHeader):# [Mandatory] Reference to the font generator to usesource=MyFont# [Optional] Generate constexpr values (default = false)constexpr=True# [Optional] name of the generated c++ file (default = source.name)# name = ...# [Optional] namespace of the generated c++ file (default = icons)# namespace = ...# [Optional] Generate macros (default = True)# macros = ...# [Optional] Prefix for all macros (default = Icon_)# macro_prefix = ...#------------------------------------------------------------------------------# [Optional]# You can Embed your font binary into a C++ source file to be linked.# (extend CppEmbedded)#------------------------------------------------------------------------------classMyCppFontEmbed(CppEmbedded):# [Mandatory] Reference to the binary file to embedsource="${BAWR_OUTPUT_DIR}/my-icons.ttf"# [Optional] name prefix for the generated files (default = source name)# name = ...# [Optional] namespace for the generated files (default = icons)# namespace = ...#------------------------------------------------------------------------------# [Optional]# You can generate C++ code to load your font into Dear ImGui.# (extend CppEmbedded)#------------------------------------------------------------------------------classMyCppFontImGui(ImGuiFontLoader):# [Mandatory] reference to the fontfont=MyFont# [Mandatory] reference to the font headerheader=MyCppFontH# [Mandatory] reference to the embedded binarydata=MyCppFontEmbed# [Optional] name prefix for the generated files (default = font.name)# name = ...# [Optional] namespace for the generated files (default = icons)# namespace = ...#------------------------------------------------------------------------------# [Optional]# You can generate an optimized png atlas with all your icons in different sizes.# (extend Atlas)#------------------------------------------------------------------------------classMyAtlas(Atlas):# [Optional] width of the atlas image (default = 512)width=512# [Mandatory] sizes of the icons to be generated and included in the atlassizes=(16,32,64)# [Mandatory] References to collections (icon sets) to be includedcollections=(BootstrapIcons,MyIcons)# [Optional] name prefix for the generated files (default = font.name)# name = ...# [Optional] Embed the Atlas png into a C++ source.classMyCppAtlasEmbed(CppEmbedded):source="${BAWR_OUTPUT_DIR}/atlas.png"#------------------------------------------------------------------------------# [Optional]# Generate a C++ header file with the atlas cells (frames) to be used in your code.# (extend CppAtlasHeader)#------------------------------------------------------------------------------classMyAtlasHeader(CppAtlasHeader):source=MyAtlasHow to use with Dear ImGui:https://github.com/mnesarco/bawr/blob/main/ImGui.mdWhat is in the nameBAWRin honor ofBertrand Arthur William Russell, a great Logician, Mathematician and Philosopher of the IX and XX centuries.