| Crates.io | svg2glif |
| lib.rs | svg2glif |
| version | 0.3.1 |
| created_at | 2025-12-06 10:29:12.518346+00 |
| updated_at | 2025-12-12 10:59:07.14717+00 |
| description | Convert SVG to UFO glif file |
| homepage | |
| repository | https://github.com/santhoshtr/svg2glif |
| max_upload_size | |
| id | 1969962 |
| size | 39,385 |
Convert SVG-based glyph drawings to UFO's GLIF format.
svg2glif is a Rust library and command-line tool that converts SVG vector graphics into UFO (Unified Font Object) GLIF format, making it easy to incorporate SVG artwork into font development workflows.
cargo install svg2glif
Add to your Cargo.toml:
[dependencies]
svg2glif = "0.1"
svg2glif -i input.svg -o output.glif -e 1000 -d 200 -u 0041
Arguments:
-i, --input <INPUT>: Input SVG file-o, --output <OUTPUT>: Output GLIF file-e, --em-size <EM_SIZE>: Units per em (typically 1000 or 2048)-d, --descent <DESCENT>: Descent value to position glyph above baseline-u, --unicode <HEX>: Optional Unicode codepoint in hex (e.g., 0041 for 'A')use svg2glif::{convert_svg_to_glif_file, ConversionConfig};
use std::path::Path;
let config = ConversionConfig::new(1000.0, 200.0)
.with_unicode("0041".to_string());
convert_svg_to_glif_file(
Path::new("input.svg"),
Path::new("output.glif"),
&config
)?;
Or convert from SVG string:
use svg2glif::{convert_svg_string_to_glyph, ConversionConfig};
use std::path::Path;
let svg_data = r#"<?xml version="1.0" encoding="UTF-8"?>
<svg width="100" height="100" xmlns="http://www.w3.org/2000/svg">
<path d="M 10 10 L 90 10 L 90 90 L 10 90 Z" fill="black"/>
</svg>"#;
let config = ConversionConfig::new(1000.0, 200.0);
let glyph = convert_svg_string_to_glyph(
svg_data,
Path::new("example.svg"),
&config
)?;
SVG text elements are automatically converted to GLIF anchors. The text content becomes the anchor name, and the position is determined by the text element's transform. This is particularly useful for defining attachment points for mark positioning in fonts.
For example, an SVG text element like:
<g transform="translate(250, 700)">
<text>top</text>
</g>
Will be converted to a GLIF anchor:
<anchor x="250" y="800" name="top"/>
<path> elements (shapes like circles, rectangles must be converted to paths)MIT