Giter VIP home page Giter VIP logo

msdfgen-rs's Introduction

Safe bindings to msdfgen library

License: MIT Crates.io Package Docs.rs API Docs Travis-CI Status

Crates

  • msdfgen-sys Low-level unsafe bindings generated using bindgen.
  • msdfgen-lib Bundled library which can be build and link with application.
  • msdfgen High-level safe bindings which should be used by applications.

Features

  • ttf-parse Enables ttf-parser crate integration which allows create shapes for glyphs of specific font.
  • font Enables font crate integration which allows create shapes for glyphs of specific font.
  • freetype-rs Enables freetype-rs crate integration which allows create shapes for glyphs of specific font.
  • png Enables png crate integration which allows load and save bitmaps from/as PNG images.
  • all Meta-feature which enables all supported features.

Usage

use msdfgen_lib as _; // forces linking with msdfgen library

use std::fs::File;
use notosans::REGULAR_TTF as FONT;
use ttf_parser::Font;

use msdfgen::{FontExt, Bitmap, Range, EDGE_THRESHOLD, OVERLAP_SUPPORT};

fn main() {
    let font = Font::from_data(&FONT, 0).unwrap();
    let glyph = font.glyph_index('A').unwrap();
    let mut shape = font.glyph_shape(glyph).unwrap();

    if !shape.validate() {
        panic!("Invalid shape");
    }
    shape.normalize();

    let bounds = shape.get_bounds();

    let width = 32;
    let height = 32;

    let mut bitmap = Bitmap::new(width, height);

    println!("bounds: {:?}", bounds);

    shape.edge_coloring_simple(3.0, 0);

    let framing = bounds.autoframe(width, height, Range::Px(4.0), None).unwrap();

    println!("framing: {:?}", framing);

    shape.generate_msdf(&mut bitmap, &framing, EDGE_THRESHOLD, OVERLAP_SUPPORT);

    let mut output = File::create("A-msdf.png").unwrap();
    bitmap.write_png(&mut output).unwrap();
}

msdfgen-rs's People

Contributors

katyo avatar johnoneil avatar solrabizna avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.