Skip to content
pubscout

opentype_shaper

0.3.4, released 13 days ago by an unverified publisher

OpenType text shaping for Dart and Flutter, returning glyph ids with offsets.

$ flutter pub add opentype_shaper
Source repository

What it does

It runs HarfRust to perform GSUB substitutions and GPOS mark positioning, producing glyph ids, advances and offsets in font units. The API exposes a ShaperFont that can be registered, shaped, and disposed, and supports isolate attachment.

AI-written summary of version 0.3.4, based on the package's README and metadata. Report an inaccuracy

Use it when

  • You need accurate mark positioning for scripts like Hebrew or Arabic.
  • You are generating PDFs or custom renderers that require glyph ids and positioning data.
  • You want to subset fonts for PDF by glyph id.
  • You need a pure Dart/Flutter solution without C/C++ dependencies.

Skip it when

  • You only need basic text rendering handled by Flutter’s Text widget.
  • You are targeting only Latin scripts without complex shaping.
  • You need a high-level layout engine that also handles line breaking and shaping together.

Strengths

  • Pure Dart API with no C/C++ runtime; uses precompiled Rust library.
  • Supports isolate attachment and background shaping.
  • Provides glyph ids and offsets suitable for PDF and custom rendering.
  • Offers font subsetting by glyph id for PDFs.

Weaknesses

  • Requires Rust toolchain if building from source; otherwise precompiled binaries needed.
  • No built-in line breaking or full layout engine; only shaping.
  • Limited to shaping; does not handle text layout or rendering.
  • Requires manual disposal of fonts and buffers.

Setup

Kind
FFI (native library)
Effort
Medium
Code generation
No
Direct dependencies
6

Add dependency, run `flutter pub get`. If building from source, Rust must be installed. No special permissions. No build_runner needed.

import 'package:opentype_shaper/opentype_shaper.dart';
final font = ShaperFont.register(fontBytes);
try {
  final run = font.shape('שָׁלוֹם', rtl: true, script: 'hebr');
  for (var i = 0; i < run.glyphCount; i++) {
    // run.glyphId(i), run.xAdvance(i), run.xOffset(i), run.yOffset(i)
  }
} finally {
  font.dispose();
}

Works with

Packages commonly used together with opentype_shaper: ones it builds on, ones built on it, and its own family.