SVG Icon processing tool for C++

Related tags

Deep Learning bawr
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.

You might also like...
Apache Spark - A unified analytics engine for large-scale data processing

Apache Spark Spark is a unified analytics engine for large-scale data processing. It provides high-level APIs in Scala, Java, Python, and R, and an op

Data manipulation and transformation for audio signal processing, powered by PyTorch

torchaudio: an audio library for PyTorch The aim of torchaudio is to apply PyTorch to the audio domain. By supporting PyTorch, torchaudio follows the

Official implementation of YOGO for Point-Cloud Processing
Official implementation of YOGO for Point-Cloud Processing

You Only Group Once: Efficient Point-Cloud Processing with Token Representation and Relation Inference Module By Chenfeng Xu, Bohan Zhai, Bichen Wu, T

git《Pseudo-ISP: Learning Pseudo In-camera Signal Processing Pipeline from A Color Image Denoiser》(2021) GitHub: [fig5]
git《Pseudo-ISP: Learning Pseudo In-camera Signal Processing Pipeline from A Color Image Denoiser》(2021) GitHub: [fig5]

Pseudo-ISP: Learning Pseudo In-camera Signal Processing Pipeline from A Color Image Denoiser Abstract The success of deep denoisers on real-world colo

[CVPR2021] Invertible Image Signal Processing
[CVPR2021] Invertible Image Signal Processing

Invertible Image Signal Processing This repository includes official codes for "Invertible Image Signal Processing (CVPR2021)". Figure: Our framework

A list of papers about point cloud based place recognition, also known as loop closure detection in SLAM (processing)

A list of papers about point cloud based place recognition, also known as loop closure detection in SLAM (processing)

Source codes of CenterTrack++ in 2021 ICME Workshop on Big Surveillance Data Processing and Analysis
Source codes of CenterTrack++ in 2021 ICME Workshop on Big Surveillance Data Processing and Analysis

MOT Tracked object bounding box association (CenterTrack++) New association method based on CenterTrack. Two new branches (Tracked Size and IOU) are a

Advances in Neural Information Processing Systems (NeurIPS), 2020.

What is being transferred in transfer learning? This repo contains the code for the following paper: Behnam Neyshabur*, Hanie Sedghi*, Chiyuan Zhang*.

Provide partial dates and retain the date precision through processing

Prefix date parser This is a helper class to parse dates with varied degrees of precision. For example, a data source might state a date as 2001, 2001

Comments
  • Add additional check if Font.collections is iterable

    Add additional check if Font.collections is iterable

    First of all, thank you very much for this awesome tool. I'm creating this PR, because I've run into this problem myself and just wanted to add a heads-up for other people that forgot to add a comma in a single-element tuple.

    opened by cloud11665 2
Owner
Frank David Martínez M
Frank David Martínez M
ICON: Implicit Clothed humans Obtained from Normals (CVPR 2022)

ICON: Implicit Clothed humans Obtained from Normals Yuliang Xiu · Jinlong Yang · Dimitrios Tzionas · Michael J. Black CVPR 2022 News ?? [2022/04/26] H

Yuliang Xiu 1.1k Jan 4, 2023
Annotated notes and summaries of the TensorFlow white paper, along with SVG figures and links to documentation

TensorFlow White Paper Notes Features Notes broken down section by section, as well as subsection by subsection Relevant links to documentation, resou

Sam Abrahams 437 Oct 9, 2022
Agile SVG maker for python

Agile SVG Maker Need to draw hundreds of frames for a GIF? Need to change the style of all pictures in a PPT? Need to draw similar images with differe

SemiWaker 4 Sep 25, 2022
Third party Pytorch implement of Image Processing Transformer (Pre-Trained Image Processing Transformer arXiv:2012.00364v2)

ImageProcessingTransformer Third party Pytorch implement of Image Processing Transformer (Pre-Trained Image Processing Transformer arXiv:2012.00364v2)

null 61 Jan 1, 2023
Point cloud processing tool library.

Point Cloud ToolBox This point cloud processing tool library can be used to process point clouds, 3d meshes, and voxels. Environment python 3.7.5 Dep

ZhangXinyun 40 Dec 9, 2022
Image processing in Python

scikit-image: Image processing in Python Website (including documentation): https://scikit-image.org/ Mailing list: https://mail.python.org/mailman3/l

Image Processing Toolbox for SciPy 5.2k Dec 31, 2022
A series of convenience functions to make basic image processing operations such as translation, rotation, resizing, skeletonization, and displaying Matplotlib images easier with OpenCV and Python.

imutils A series of convenience functions to make basic image processing functions such as translation, rotation, resizing, skeletonization, and displ

Adrian Rosebrock 4.3k Jan 8, 2023
Web mining module for Python, with tools for scraping, natural language processing, machine learning, network analysis and visualization.

Pattern Pattern is a web mining module for Python. It has tools for: Data Mining: web services (Google, Twitter, Wikipedia), web crawler, HTML DOM par

Computational Linguistics Research Group 8.4k Jan 3, 2023
PIKA: a lightweight speech processing toolkit based on Pytorch and (Py)Kaldi

PIKA: a lightweight speech processing toolkit based on Pytorch and (Py)Kaldi PIKA is a lightweight speech processing toolkit based on Pytorch and (Py)

null 336 Nov 25, 2022