All Projects → libcala → fonterator

libcala / fonterator

Licence: other
Load fonts as vector graphics in pure Rust with advanced text layout.

Programming Languages

rust
11053 projects

Projects that are alternatives of or similar to fonterator

Tehreer-Cocoa
Standalone text engine for iOS
Stars: ✭ 31 (-8.82%)
Mutual labels:  opentype, text-layout
Tehreer-Android
Standalone text engine for Android aimed to be free from platform limitations
Stars: ✭ 61 (+79.41%)
Mutual labels:  opentype, text-layout
ttf-explorer
A simple tool to explore a TrueType font content as a tree
Stars: ✭ 22 (-35.29%)
Mutual labels:  opentype, truetype
bitsnpicas
Bits'N'Picas - Bitmap & Emoji Font Creation & Conversion Tools
Stars: ✭ 171 (+402.94%)
Mutual labels:  opentype, truetype
typedesigner
Unified Font Object Editor for macOS
Stars: ✭ 20 (-41.18%)
Mutual labels:  opentype, truetype
Opentype.js
Read and write OpenType fonts using JavaScript.
Stars: ✭ 3,393 (+9879.41%)
Mutual labels:  opentype, truetype
pixel font
All-in-one tool for creating TrueType outline fonts from bitmap glyph data, purely written in Elixir.
Stars: ✭ 16 (-52.94%)
Mutual labels:  opentype, truetype
Font Spider
Smart webfont compression and format conversion tool
Stars: ✭ 4,550 (+13282.35%)
Mutual labels:  opentype, truetype
Source Han Serif
Source Han Serif | 思源宋体 | 思源宋體 | 思源宋體 香港 | 源ノ明朝 | 본명조
Stars: ✭ 5,920 (+17311.76%)
Mutual labels:  opentype
Adobe Variable Font Prototype
Variable font example in OpenType-CFF2 & TrueType formats
Stars: ✭ 116 (+241.18%)
Mutual labels:  opentype
Rusttype
Mirror of https://gitlab.redox-os.org/redox-os/rusttype
Stars: ✭ 521 (+1432.35%)
Mutual labels:  opentype
Satysfi
A statically-typed, functional typesetting system
Stars: ✭ 815 (+2297.06%)
Mutual labels:  opentype
Warcraft Font Merger
Warcraft Font Merger,魔兽世界字体合并/补全工具。
Stars: ✭ 118 (+247.06%)
Mutual labels:  opentype
Source Han Mono
Source Han Mono | 思源等宽 | 思源等寬 | 思源等寬 香港 | 源ノ等幅 | 본모노
Stars: ✭ 591 (+1638.24%)
Mutual labels:  opentype
Harfbuzz
HarfBuzz text shaping engine
Stars: ✭ 2,206 (+6388.24%)
Mutual labels:  opentype
Libertinus
The Libertinus font family
Stars: ✭ 518 (+1423.53%)
Mutual labels:  opentype
Fontdue
The fastest font renderer in the world, written in pure rust.
Stars: ✭ 499 (+1367.65%)
Mutual labels:  opentype
Ptex Ng
Asiatic pTeX
Stars: ✭ 239 (+602.94%)
Mutual labels:  opentype
Source Han Super Otc
Source Han & Noto CJK Mega/Ultra OTCs
Stars: ✭ 153 (+350%)
Mutual labels:  opentype
Source Han Sans
Source Han Sans | 思源黑体 | 思源黑體 | 思源黑體 香港 | 源ノ角ゴシック | 본고딕
Stars: ✭ 10,181 (+29844.12%)
Mutual labels:  opentype

fonterator

Load fonts as vector graphics in pure Rust with advanced text layout.

Build Status Docs crates.io

When you want to render text, fonterator gives you an iterator over footile PathOps, which you can easily pass right into footile.

  • Loads TTF/OTF fonts and font collections.
  • Automatic kerning and font layout.
  • Horizontal and vertical text layout.
  • Left-to-right and right-to-left text layout.
  • Uses fallback fonts if a character is not available from one font.
  • Can Align text left/center/right/vertical
  • Line Wrapping

Todo

Table of Contents

Getting Started

Add the following to your Cargo.toml.

[dependencies]
fonterator = "0.8"

Example

use fonterator as font; // For parsing font file.
// For rendering text
use footile::{FillRule, Plotter, PathOp, Transform};
use png_pong::Encoder; // For saving PNG
use pix::{
    Raster,
    rgb::{Rgba8p, SRgba8},
    matte::{Matte8},
    ops::{SrcOver}
};

const FONT_SIZE: f32 = 32.0;

fn main() {
    // Example Text
    let english = "Raster Text With Font";
    let korean = "글꼴로 래스터 텍스트 사용";
    let japanese = "フォント付きラスタテキスト";

    // Init font, and paths.
    let font = font::monospace_font();

    // Render English Left Aligned.
    let mut p = Plotter::new(Raster::with_clear(512, 512));
    let mut r = Raster::with_clear(512, 512);
    p.set_transform(Transform::with_scale(FONT_SIZE, FONT_SIZE));
    let path = font.render(
        english,
        (512.0 - 64.0) / FONT_SIZE,
        font::TextAlign::Left
    ).0;
    r.composite_matte(
        (64, 0, 512, 512),
        p.fill(FillRule::NonZero, path, Matte8::new(255)),
        (),
        Rgba8p::new(0, 0, 0, 255),
        SrcOver,
    );

    // Render Korean Vertically
    let mut pr = p.raster();
    pr.clear();
    p = Plotter::new(pr);
    p.set_transform(Transform::with_scale(FONT_SIZE, FONT_SIZE));
    let path = font.render(
        korean,
        512.0 / FONT_SIZE,
        font::TextAlign::Vertical
    ).0;
    r.composite_matte(
        (0, 0, 512, 512),
        p.fill(FillRule::NonZero, path, Matte8::new(255)),
        (),
        Rgba8p::new(0, 0, 0, 255),
        SrcOver,
    );

    // Render Japanese Vertically
    let mut pr = p.raster();
    pr.clear();
    p = Plotter::new(pr);
    p.set_transform(Transform::with_scale(FONT_SIZE, FONT_SIZE));
    let path = font.render(
        japanese,
        (512.0 - 32.0 * 7.0) / FONT_SIZE,
        font::TextAlign::Vertical
    ).0;
    r.composite_matte(
        (32, 0, 512, 512),
        p.fill(FillRule::NonZero, path, Matte8::new(255)),
        (),
        Rgba8p::new(0, 0, 0, 255),
        SrcOver,
    );

    // Save PNG
    let raster = Raster::<SRgba8>::with_raster(&r);
    let mut out_data = Vec::new();
    let mut encoder = Encoder::new(&mut out_data).into_step_enc();
    encoder.still(&raster).expect("Failed to add frame");
    std::fs::write("out.png", out_data).expect("Failed to save image");
}

API

API documentation can be found on docs.rs.

Features

monospace-font

Embeds a monospace font accessible with the monospace_font() public API in the root of the crate.

normal-font

Embeds a variable-width font accessible with the normal_font() public API in the root of the crate.

Upgrade

You can use the changelog to facilitate upgrading this crate as a dependency.

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Contributors are always welcome (thank you for being interested!), whether it be a bug report, bug fix, feature request, feature implementation or whatever. Don't be shy about getting involved. I always make time to fix bugs, so usually a patched version of the library will be out a few days after a report. Features requests will not complete as fast. If you have any questions, design critques, or want me to find you something to work on based on your skill level, you can email me at [email protected]. Otherwise, here's a link to the issues on GitHub. Before contributing, check out the contribution guidelines, and, as always, make sure to follow the code of conduct.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].