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
View images in the terminal using ansi escape codes and python

terminal-photo-viewer view images in the terminal using ansi escape codes and python !! Only tested on Ubuntu 20.04.3 LTS with python version 3.8.10 D

1 Nov 30, 2021
Gallery written in Python to manage your photos

GalleryMan Gallery written in Python to manage your photos Installation

Asian Cat 24 Dec 18, 2022
Hacking github graph with a easy python script

Hacking-Github-Graph Hacking github graph with a easy python script Requirements git latest version installed. A text editor (eg: vs code, sublime tex

SENPAI LEGEND 1 Nov 01, 2021
The following program is used to swap the faces from two images.

Face-Swapping The following program is used to swap the faces from two images. In today's world deep fake technology has become really popular . As a

1 Jan 19, 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
Fast batch image resizer and rotator for JPEG and PNG images.

imgp is a command line image resizer and rotator for JPEG and PNG images.

Terminator X 921 Dec 25, 2022
利用近邻法的弱点实现图片缩小后变成另一张图

这是我一个视频的配套代码。 视频是:利用近邻法的弱点实现图片缩小后变成另一张图 https://www.bilibili.com/video/BV1Lf4y1r7dZ 配套代码中,仅generate.py是核心文件,其余的图片神马的,都是赠品。 这个核心文件利用了近邻法缩放的弱点,可以将图a的像素按

偶尔有点小迷糊 182 Dec 19, 2022
Python Image Morpher (PIM) is a program that can take two images and blend them to whatever extent or precision that you like

Python Image Morpher (PIM) is a program that can take two images and blend them to whatever extent or precision that you like! It is designed to emulate some of Python's OpenCV image processing from

David Dowd 108 Dec 19, 2022
Pixel art as well as various sets for hand crafting

Pixel art as well as various sets for hand crafting

1 Nov 09, 2021
Multiparametric Image Analysis

Documentation The documentation is available on populse_mia's website here Installation From PyPI, for users By cloning the package, for developers Fr

Populse 9 Dec 14, 2022
Simple Python / ImageMagick script to package images into WAD3s for use as GoldSrc textures.

WADs Out For [The] Ladies Simple Python / ImageMagick script to package images into WAD3s for use as GoldSrc textures. Development mostly focused on L

5 Apr 09, 2022
A Robust Avatar Generator with a huge number of templates

CoolAvatars Welcome to this repository of CoolAvatars. Using this project, you can generate cool avatars not only from the samples present in my image

RAVI PRAKASH 5 Oct 12, 2021
Make GIFs from time-stacked xarray.DataArrays (time, [optional band], y, x), dead-simple.

GeoGIF Make GIFs from time-stacked xarray.DataArrays (time, [optional band], y, x), dead-simple. from geogif import gif, dgif gif(data_array) dgif(das

Gabe Joseph 47 Dec 22, 2022
impy is an all-in-one image analysis library, equipped with parallel processing, GPU support, GUI based tools and so on.

impy is All You Need in Image Analysis impy is an all-in-one image analysis library, equipped with parallel processing, GPU support, GUI based tools a

24 Dec 20, 2022
Validate arbitrary image uploads from incoming data urls while preserving file integrity but removing EXIF and unwanted artifacts and RCE exploit potential

Validate arbitrary base64-encoded image uploads as incoming data urls while preserving image integrity but removing EXIF and unwanted artifacts and mitigating RCE-exploit potential.

A3R0 1 Jan 10, 2022
A script to generate a profile picture and a banner that show the same image on Discord.

Discord profile picture & banner generator A script to generate a profile picture and a banner that show the same image on Discord. Installation / Upd

Victor B. 9 Nov 27, 2022
Convert bitmap images to seeds for Tiny-83 NFT project.

What is this? This tool allows you to convert any 14p high and 22p wide Bitmap (.bmp) to the seed needed for the Tiny-83 NFT project. Project Twitter:

shib_maximalist 1 Oct 31, 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
Using P5.js, Processing and Python to create generative art

Experiments in Generative Art Using Python, Processing, and P5.js Quick Links Daily Sketches March 2021. | Gallery | Repo | Done using P5.js Genuary 2

Ram Narasimhan 33 Jul 06, 2022
An API that renders HTML/CSS content to PNG using Chromium

html_png An API that renders HTML/CSS content to PNG using Chromium Disclaimer I am not responsible if you happen to make your own instance of this AP

10 Aug 08, 2022