Skip to main content

Crate typf_core

Crate typf_core 

Source
Expand description

§typf-core: The Engine Room

Six stages from text to pixels. No magic, just engineering.

Text enters as Unicode chaos, exits as perfect pixels. This crate is the engine room that makes text rendering work when half your characters are Arabic and the other half are emoji.

§The Pipeline: Brutal Simplicity

Every text walks this path, no shortcuts:

  1. Input Parsing - Raw strings → structured data. We don’t guess encoding.
  2. Unicode Processing - Bidi, scripts, segmentation. The hard stuff.
  3. Font Selection - Right font for each character, period. Fallback that actually works.
  4. Shaping - Characters → positioned glyphs. Where HarfBuzz lives.
  5. Rendering - Glyphs → pixels/vectors. SIMD or die.
  6. Export - Your format, ready to ship.

§Build Your First Pipeline

use typf_core::{Pipeline, RenderParams, ShapingParams};
use std::sync::Arc;


let pipeline = Pipeline::builder()
    .shaper(Arc::new(MyShaper))
    .renderer(Arc::new(MyRenderer))
    .exporter(Arc::new(MyExporter))
    .build()?;

let font = load_font();
let output = pipeline.process(
    "Hello, World!",
    font,
    &ShapingParams::default(),
    &RenderParams::default(),
)?;

§The Traits That Power Everything

Want to add your own backend? Implement one of these:

  • Stage - The foundation every pipeline component builds upon.
  • Shaper - Where characters become glyphs.
  • Renderer - Where glyphs become images.
  • Exporter - Where images become files.
  • traits::FontRef - Your window into font data.

Data flows through the types in types - these structures carry the results from one stage to the next.

Re-exports§

pub use context::PipelineContext;
pub use error::Result;
pub use error::TypfError;
pub use pipeline::Pipeline;
pub use pipeline::PipelineBuilder;
pub use traits::Exporter;
pub use traits::Renderer;
pub use traits::Shaper;
pub use traits::Stage;

Modules§

cache
Scan-resistant caching with TinyLFU and byte-weighted eviction
cache_config
Global cache configuration
context
The traveling container that carries data through pipeline stages
error
When things go wrong in the pipeline
ffi
C-ABI compatible types for FFI consumers.
glyph_cache
Backend-neutral glyph/render cache with byte-weighted eviction
linra
Linra rendering: shape and render in a single pass
pipeline
The engine that drives text through six stages to become images
shaping_cache
Backend-agnostic shaping cache
traits
The contracts that bind every backend together
types
The data structures that power the pipeline.

Structs§

Color
Simple RGBA color that works everywhere
GlyphSourcePreference
Preference ordering and deny list for glyph sources
RenderParams
How rendering should look
ShapingParams
How shaping should behave

Enums§

GlyphSource
Which glyph data sources are allowed and in what order
RenderMode
Target output for rendering operations

Constants§

DEFAULT_MAX_BITMAP_HEIGHT
Default maximum bitmap height: 16k pixels
DEFAULT_MAX_BITMAP_PIXELS
Default maximum total bitmap pixels: 1 Gpix
DEFAULT_MAX_BITMAP_WIDTH
Default maximum bitmap dimension (width): 16,777,216 pixels (16M)
MAX_FONT_SIZE
Maximum font size in pixels to prevent DoS attacks.
MAX_GLYPH_COUNT
Maximum number of glyphs to render in a single operation.

Functions§

get_max_bitmap_height
Get max bitmap height from environment or use default (16384).
get_max_bitmap_pixels
Get max bitmap pixels from environment or use default (1 Gpix).
get_max_bitmap_width
Get max bitmap width from environment or use default (16,777,216).
validate_glyph_count
Validate glyph count against security limits