This is a tool to automate the icons generation from sets of svg files into fonts and atlases.

Related tags

Image Processingbawr
Overview

BAWR

This 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/bawr This project is based on a previous project: https://github.com/mnesarco/ff-batch

Features

  • Generate 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 transformations
    • Font forge supported transformations

Requirements

  • Python 3.6+
  • FontForge 20170924+
  • Inkscape 1.0+

Install

Build from sources

git clone https:://github.com/mnesarco/bawr.git
cd bawr

python3 -m pip install --upgrade build
python3 -m pip install wheel

python3 -m build 
python3 -m pip install dist/bawr-0.0.3-py3-none-any.whl

Or from pypi:

python3 -m pip install bawr

Terminology

Concept Description
Svg Icon It is just a file in .svg format. It must be a square.
Icon set or Collection It is a folder with svg icons
Configuration file It is a python file with all the options to generate your files. By convention it is called config.py

Usage

  1. Create a folder
  2. Put a file named config.py (you can copy the one from examples dir https://github.com/mnesarco/bawr/tree/main/examples)
  3. Add folders with svg icons
  4. Adjust the configuration (edit config.py)
  5. Call bawr
cd examples
python3 -m bawr.tool

Examples

You 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.ttf

Configuration (config.py)

#------------------------------------------------------------------------------
# Import all required stuff:
#------------------------------------------------------------------------------

from bawr.config import *

#------------------------------------------------------------------------------
# Define an environment (Use the name that you want, but extend Environment):
#------------------------------------------------------------------------------

class Env( 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):
#------------------------------------------------------------------------------

class BootstrapIcons( 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 generators
    options = {
        "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 options

class MyIcons( 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)
#------------------------------------------------------------------------------

class MyFont( 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)
#------------------------------------------------------------------------------

class MyCppFontH( CppFontHeader ):

    # [Mandatory] Reference to the font generator to use
    source = 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)
#------------------------------------------------------------------------------

class MyCppFontEmbed( CppEmbedded ):

    # [Mandatory] Reference to the binary file to embed
    source = "${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)
#------------------------------------------------------------------------------

class MyCppFontImGui( ImGuiFontLoader ):

    # [Mandatory] reference to the font
    font = MyFont

    # [Mandatory] reference to the font header
    header = MyCppFontH    

    # [Mandatory] reference to the embedded binary
    data = 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)
#------------------------------------------------------------------------------

class MyAtlas( Atlas ):

    # [Optional] width of the atlas image (default = 512)
    width = 512

    # [Mandatory] sizes of the icons to be generated and included in the atlas
    sizes = (16, 32, 64)

    # [Mandatory] References to collections (icon sets) to be included
    collections = (BootstrapIcons, MyIcons)

    # [Optional] name prefix for the generated files (default = font.name)
    # name = ...

# [Optional] Embed the Atlas png into a C++ source.
class MyCppAtlasEmbed( 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)
#------------------------------------------------------------------------------

class MyAtlasHeader( CppAtlasHeader ):
    source = MyAtlas

How to use with Dear ImGui:

https://github.com/mnesarco/bawr/blob/main/ImGui.md

What is in the name

BAWR in honor of Bertrand Arthur William Russell, a great Logician, Mathematician and Philosopher of the IX and XX centuries.

Owner
Frank David Martínez M
Frank David Martínez M
A Python3 library to generate dynamic SVGs

The Python library for generating dynamic SVGs using Python3

1 Dec 23, 2021
An add to make adding screenshots and copied images to the scene easy

Blender Clipboard to Scene It doesn't work with version 2.93 and higher (I tested it on 2.91 and 2.83) There is an issue with importing the Pillow mod

Mohammad Mehdi Afkhami 3 Dec 29, 2021
Tool made for the FWA Yearbook Team to resize multiple images quickly.

ImageResize Tool Tool made for the FWA Yearbook Team to resize multiple images quickly. Make sure to check this repo for future updates How to Use The

LGobin 1 Jan 07, 2022
Optimize/Compress images using python

Image Optimization Using Python steps to run the script run the command to install the required libraries pip install -r requirements.txt create a dir

Shekhar Gupta 1 Oct 15, 2021
sK1 2.0 cross-platform vector graphics editor

sK1 2.0 sK1 2.0 is a cross-platform open source vector graphics editor similar to CorelDRAW, Adobe Illustrator, or Freehand. sK1 is oriented for prepr

sK1 Project 238 Dec 04, 2022
Art directed cropping, useful for responsive images

Art direction sets a focal point and can be used when you need multiple copies of the same Image but also in in different proportions.

Daniel 1 Aug 16, 2022
Computer art based on quadtrees.

Quads Computer art based on quadtrees. The program targets an input image. The input image is split into four quadrants. Each quadrant is assigned an

Michael Fogleman 1.1k Dec 23, 2022
clesperanto is a graphical user interface for GPU-accelerated image processing.

clesperanto is a graphical user interface for a multi-platform multi-language framework for GPU-accelerated image processing. It is based on napari and the pyclesperanto-prototype.

1 Jan 02, 2022
TRREASURE_IMAGE is python lib by which you can hide anything in a .jpg image with Command-Line Interface[cli] feature

TRREASURE_IMAGE TRREASURE_IMAGE is a python third-party library with Command-Line Interface[cli] feature. Table of Contents General Info Python librar

Fatin Shadab 3 Jun 07, 2022
Collection of SVG diagrams about how UTF-8 works

Diagrams Repository of diagrams made for articles on my blog. All diagrams are created using diagrams.net. UTF-8 Licenses Copyright 2022 Seth Michael

Seth Michael Larson 24 Aug 13, 2022
Nudity detection with Python

nude.py About Nudity detection with Python. Port of nude.js to Python. Installation from pip: $ pip install --upgrade nudepy from easy_install: $ eas

Hideo Hattori 881 Jan 06, 2023
With this simple py script you will be able to get all the .png from a folder and generate a yml for Oraxen

Oraxen-item-to-yml With this simple py script you will be able to get all the .png from a folder and generate a yml for Oraxen How to use Install the

Akex 1 Dec 29, 2021
Simple to use image handler for python sqlite3.

SQLite Image Handler Simple to use image handler for python sqlite3. Functions Function Name Parameters Returns init databasePath : str tableName : st

Mustafa Ozan Çetin 7 Sep 16, 2022
A simple image-level annotation tool supporting multi-channel images for napari.

napari-labelimg4classification A simple image-level annotation tool supporting multi-channel images for napari. This napari plugin was generated with

4 May 16, 2022
This is the official source code of FreeCAD, a free and opensource multiplatform 3D parametric modeler.

Freedom to build what you want FreeCAD is an open-source parametric 3D modeler made primarily to design real-life objects of any size. Parametric modeling allows you to easily modify your design by g

FreeCAD 12.9k Jan 07, 2023
Python Script to generate posters out of the images in directory.

Poster-Maker Python Script to generate posters out of the images in directory. This version is very basic ligthweight code to combine organize images

1 Feb 02, 2022
Python avatar generator for absolute nerds

pagan Welcome to the Python Avatar Generator for Absolute Nerds. Current version: 0.4.3 View the change history here. Remember those good old days whe

David Bothe 280 Dec 16, 2022
Wand is a ctypes-based simple ImageMagick binding for Python

Wand Wand is a ctypes-based simple ImageMagick binding for Python, supporting 2.7, 3.3+, and PyPy. All functionalities of MagickWand API are implement

Eric McConville 1.2k Jan 03, 2023
Pnuemonia Normal detection by using XRay images.

Pnuemonia Normal detection by using XRay images. Got image datas from kaggle(link is given in sources.txt file) also normal xray images from other site (also link is given) in order to avoid data dis

Zarina 1 Feb 28, 2022
3D Model files and source code for rotating turntable. Raspberry Pi, DC servo and PWM modulator required.

3DSimpleTurntable 3D Model files and source code for rotating turntable. Raspberry Pi, DC servo and PWM modulator required. Preview Construction Print

Thomas Boyle 1 Feb 13, 2022