JFLib

text/colr.rs#

Source: lib/text/colr.rs

colr -- colour glyphs: COLR v0 / CPAL layers and CBDT / CBLC PNG bitmaps  [src/text/colr.s]

  open(ctx)                         validate COLR + CPAL (palette 0) and CBDT + CBLC; sets
                                    TFF_COLR / TFF_CBDT
  layers(ctx, glyph, cap) -> {glyph | LAYER_FG, argb (straight)}   (empty = none)
  bitmap(ctx, glyph, size_fx, png, scale) -> Bitmap   the strike's PNG decoded and scaled
       to size_fx (area average when shrinking, bilinear when enlarging)

COLR v1 paint graphs are not supported: v1 fonts that keep v0 base glyph records use
those, otherwise the monochrome glyph is drawn.  Palette 0 only; palette index 0xFFFF =
the current text colour.  CBDT: index subtable formats 1..5, glyph image formats 17, 18,
19 (PNG); strike = the smallest ppem >= the requested size, else the largest.  The PNG
decoder and the enlarging scaler come from the image crates through hooks (Text).
LAYER_FG: u32 = 0x8000_0000
  • type PngDecode = fn(&[u8]) -> Option<Surface> decode a PNG into a PARGB surface

  • type ImgScale = fn(&Surface, i32, i32) -> Option<Surface> bilinear resize of a PARGB surface to w x h (img_scale mode 1)

  • struct Bitmap a colour glyph bitmap: placement relative to pen x / baseline, PARGB pixels (stride 4 w)

    • left: i32
    • top: i32
    • w: i32
    • h: i32
    • px: Vec<u8>
  • fn open(f: &mut TtFont) validate COLR + CPAL and CBDT + CBLC [colr_open]

  • fn layers(f: &TtFont, glyph: u32, cap: usize, out: &mut Vec<(u32, u32)>) layers of a COLR base glyph (empty = none), at most cap [colr_layers]

  • fn bitmap(f: &TtFont, glyph: u32, size_fx: i32, png: Option<PngDecode>, scale: Option<ImgScale>, metrics: &mut [u8; 5]) -> Option<Bitmap> the colour bitmap of glyph at size_fx (24.8 px) [cbdt_bitmap]

Source: docs/API.md in the JFLib repository.