FontEco is a Python tool for creating eco-friendly fonts
This process reduces the amount of ink needed to print text while maintaining readability.
- Making your fonts more "eco-friendly"
- Different dithering modes:
- Blue Noize
- Shape
- Line
- Customizable applications
FontEco uses a sophisticated pipeline to create eco-friendly fonts by intelligently removing dots from glyphs while maintaining readability. Here's how the process works:
-
Glyph Rendering:
- Each glyph from the input font is rendered to a high-resolution image (512x512)
- Special handling for composite glyphs and Cyrillic characters
- Automatic scaling to maintain proper proportions
- Uses PIL (Python Imaging Library) for high-quality glyph rendering
-
Dithering:
- Several different algorithms implemented
- Uses Sobol' sequence algorithm to generate a uniform distribution of points
- Applies Floyd-Steinberg dithering with blue noise pattern
- Configurable reduction percentage (default: 20%)
- Ensures visually pleasing distribution of removed dots
-
Vectorization:
- Converts the dithered image back to vector outlines using Potrace algorithm
- Multiple rendering modes available for different use cases:
- Original: Uses Potrace's default path tracing
- Simplified: Reduces the number of transparency levels (optimal: 4 levels)
- Optimized: Uses point clustering and path optimization (optimal: 100 grid size)
- Optimized Masked: Like optimized but ensures paths stay within glyph boundaries
- Applies Douglas-Peucker algorithm for path simplification
- Uses Bézier curve fitting for smooth outlines
- Optimizes control points using distance-based filtering
-
Font Generation:
- Scales the glyphs to match the original font metrics
- Updates font metadata and naming
- Preserves font features and compatibility
- Uses fontTools for font manipulation and optimization
graph TD
A[Input Font] --> B[Load Font]
B --> C[Process Each Glyph]
C --> D[Render Glyph to Image]
D --> E[Apply Dithering]
E --> F[Vectorize with Potrace]
F --> I[Output Eco Font]
The library supports three main dithering modes:
Uses Sobol' sequences to create a blue noise pattern for removing dots from glyphs. This creates a visually pleasing, random-looking pattern that maintains readability.
A mode that removes dots in specific shapes (circles or rectangles) while maintaining readability. This mode offers more control over the visual appearance of the perforation.
A mode that removes dots by drawing lines across the glyphs. This mode offers several options for creating different line patterns.
- Clone the repository:
git clone https://github.com/yourusername/FontEco.git
cd FontEco- Install system dependencies:
sudo apt-get update
sudo apt-get install -y build-essential python3-dev libagg-dev libpotrace-dev pkg-config- Install dependencies:
pip install -r requirements.txt- Create a subset of your font (optional):
from fonteco.font_utils import create_subset_font
create_subset_font('fonts/Times.ttf', 'fonts/Times_subset.ttf')- Perforate the font:
from fonteco.fonts import perforate_font
perforate_font(
input_font_path='fonts/Times.ttf',
output_font_path='fonts/EcoTimes.ttf',
reduction_percentage=20 # Default: 20%
)input_font_path(str): Path to the input font fileoutput_font_path(str): Path where the perforated font will be savedreduction_percentage(float): Percentage of dots to remove (0-100). Default: 20with_bug(bool): Enable special coordinate transformation (bug mode). Default: Falsedraw_images(bool): Save debug images of perforated glyphs. Default: Falsescale_factor(float or str): Scaling factor for glyph coordinates. Use "AUTO" for automatic scaling. Default: "AUTO"test(bool): Process only first 20 glyphs for testing. Default: Falsedebug(bool): Print detailed debug information. Default: Falserender_mode(str): Rendering mode to use for glyph conversion:- "original": Uses Potrace's default path tracing
- "simplified": Reduces the number of transparency levels (optimal: 4 levels)
- "optimized": Uses point clustering and path optimization (optimal: 100 grid size)
- "optimized_masked": Like optimized but ensures paths stay within glyph boundaries
dithering_mode(str):- "blue_noise": Uses Sobol' sequence and blue noise dithering for natural-looking dot patterns
- "shape": Uses shape-based dithering with circles or rectangles
- "line": Uses line-based dithering with parallel or random lines
shape_type(str): Type of shape to use for shape dithering ("circle" or "rectangle"). Default: "circle"shape_size(int or str): Size of shapes for shape dithering:- int: exact size in pixels
- "random": random size between margin*2 and maximum possible
- "biggest": biggest possible size that fits
margin(int): Minimum margin between shapes and edges for shape dithering. Default: 1num_levels(int): Number of transparency levels for simplified mode (optimal: 4) or grid size for optimized mode (optimal: 100). Default: 2line_type(str): Type of line pattern for line-based ditheringcurve_type(str): Type of curve for line-based ditheringline_width(int): Width of the lines in pixels for line-based ditheringcurve(int): Curvature amount for curved lines in line-based dithering
- Automatic Scaling: When
scale_factor="AUTO", the tool automatically calculates the optimal scaling factor based on font metrics - Cyrillic Support: Handles both Latin and Cyrillic characters, including composite glyphs
- Progress Tracking: Shows a progress bar during font processing
- Debug Mode: Optional detailed logging of glyph processing steps
- Multiple Rendering Modes: Choose the best rendering approach for your needs:
- Original mode for standard perforation
- Simplified mode for reduced complexity
- Optimized mode for better path construction
- Optimized masked mode for boundary-aware perforation
- Python 3.6+
- fontTools
- Pillow
- NumPy
- OpenCV
- potrace + pypotrace
- scipy (for dithering)
- tqdm (for progress bar)
MIT License
Contributions are welcome! Please feel free to submit a Pull Request.
