What is Pango?
Pango is the industry-standard text layout engine used across the Linux desktop ecosystem. It sits above FreeType and HarfBuzz in the rendering stack and adds everything needed to lay out a full paragraph: line breaking, tab stops, text alignment, ellipsis, font selection by description string, and attribute lists that apply bold, italic, color, or size to arbitrary text spans.
Pango handles the full complexity of internationalized typography: bidirectional (BiDi) paragraphs that mix left-to-right and right-to-left text, Arabic and Hebrew contextual letter forms, Devanagari conjunct clusters, CJK ideographic spacing, automatic font fallback (if a glyph is missing from the primary font Pango transparently selects another installed font that covers that codepoint), and its own markup language for rich-text strings.
Pango is used by GTK 2, GTK 3, GTK 4, GNOME, LibreOffice, Inkscape, GIMP, Evince, and many other Linux applications. Its Cairo backend is the most common rendering path, producing vector output to PNG, PDF, or SVG with full anti-aliasing.
What Pango Adds Beyond FreeType / HarfBuzz
| Layer | Library | Responsibility |
|---|---|---|
| Rasterization | FreeType | Renders individual glyphs into bitmaps at a requested pixel size. Does not know about words, lines, or paragraphs. |
| Shaping | HarfBuzz | Maps Unicode codepoints to the correct glyph IDs with ligatures, kerning, Arabic/Hebrew contextual forms, and OpenType GSUB/GPOS. Does not know about wrapping or alignment. |
| Layout | Pango | Full paragraph layout: line breaking, word/char wrap, font selection from a description string, font fallback across families, attribute lists (bold/italic/color/size on spans), alignment (left/center/right), ellipsis, tab stops, and BiDi paragraph resolution. |
Pango Markup
SetMarkup.
It lets you mix styles inline without managing attribute lists manually.<b>bold</b> — bold weight<i>italic</i> — italic style<u>underline</u> — underline decoration<s>strikethrough</s> — strikethrough decoration<span color="red">red</span> — foreground color (name or #rrggbb)<span size="large">big</span> — relative sizes: xx-small x-small small medium large x-large xx-large<span font="Monospace">code</span> — switch font family inline<span font="Sans Bold 18" color="#3b82f6">heading</span> — combined attributes
Typical Pipeline
2. PangoContext — holds the font map and rendering settings (DPI, language).
3. PangoLayout — the text layout object. Attach font, width, alignment, wrap, ellipsize.
4. SetText / SetMarkup — supply the text content to the layout.
5. ShowLayout (via Cairo) — render the laid-out text to a Cairo surface at the current point.
For Cairo integration, use
CreateCairoLayout(CR) instead of steps 1–3 to create a layout directly
from an existing Cairo context.
Types
| Type | Description |
|---|---|
| TPangoContext | Pango context — holds a font map, rendering settings (DPI, language, base direction). Created once per surface or Cairo context. |
| TPangoLayout | Core text layout object. Holds text content, font, width constraint, alignment, wrap mode, ellipsize mode, and computed line breaks. Reuse and update between frames. |
| TPangoFontDesc | Font description — encodes family, style, weight, and size. Created via ParseFontDesc or NewFontDesc. Serializes back to a human-readable string. |
| TPangoFontMap | Collection of all fonts available to Pango. The Cairo font map (NewCairoFontMap) is the standard choice on Linux desktops. |
| TPangoAttrList | List of styled spans to apply to a layout. Each attribute covers a byte range in the UTF-8 text. Use AttrSetColor/AttrSetSize to populate, then SetAttributes to attach. |
| TCairoContext | Opaque handle to a Cairo drawing context, as returned by the cairo package. Passed to CreateCairoContext, CreateCairoLayout, and the rendering functions. |
| TPangoAlignment | Enum: paLeft=0 (default), paCenter=1, paRight=2. Controls horizontal alignment within the layout width. |
| TPangoWrapMode | Enum: pwWord=0 (wrap at word boundaries), pwChar=1 (wrap at any character), pwWordChar=2 (word-wrap with char fallback for long tokens). |
| TPangoEllipsize | Enum: peNone=0, peStart=1 ("...text"), peMiddle=2 ("te...xt"), peEnd=3 ("text..."). Requires a width constraint to take effect. |
| TPangoWeight | Enum: pwThin=100, pwUltraLight=200, pwLight=300, pwNormal=400, pwMedium=500, pwSemiBold=600, pwBold=700, pwUltraBold=800, pwHeavy=900. |
| TPangoLayoutLine | Record: StartIndex: Integer (byte offset into text), Length: Integer (byte count), IsParagraphStart: Boolean, Width: Integer (in Pango units = 1/1024 pixel). |
| TPangoRectangle | Record: X, Y, W, H: Integer in Pango units. Divide by PANGO_SCALE (1024) to obtain pixels. |
API Reference
Font Map & Context
NewContext when you already have a Cairo context.Font Description
'Sans Bold 12', 'Noto Serif Italic 14', or 'Monospace 10'. Returns a font description handle for use with SetFont.'Sans Bold 12'. Useful for logging or persisting font choices.ParseFontDesc or NewFontDesc.Layout
NewContext or CreateCairoContext.<b>, <i>, and <span color="red"> are parsed and converted to an internal attribute list. Replaces any previously set text or markup.'Noto Sans 14' or 'Monospace Bold 12'. Combines ParseFontDesc and SetFont in one call.-1 to disable wrapping entirely.pwWord (default) wraps at word boundaries; pwChar wraps at any character; pwWordChar tries word-wrap first and falls back to character-wrap for tokens that exceed the width.SetWidth) and optionally a line limit (SetLines).Lines lines. Any overflow is subject to the ellipsize mode. Combine with SetEllipsize(Layout, peEnd) for the classic "show N lines with trailing ellipsis" effect.1.0 is the default; 1.5 gives 150% spacing, 2.0 gives double-spaced text.Measuring
W is the widest line; H is the total height including all lines and inter-line spacing. Use this to position or clip the layout before rendering.GetSize includes.Rendering with Cairo
cairo.MoveTo before calling.(X, Y) in Cairo user-space coordinates. Equivalent to calling cairo.MoveTo(CR, X, Y) followed by ShowLayout.Attributes
AttrSetColor and AttrSetSize, then attach to a layout with SetAttributes. For most use-cases, Pango markup via SetMarkup is simpler.SetAttributes.[StartByte, EndByte). R, G, B are in the range 0–65535 (Pango's 16-bit color space; multiply an 8-bit value by 256).SizePoints is the size in typographic points. The attribute overrides the layout's default font size for the covered span.Attrs afterwards.Font Listing
'Noto Sans', 'DejaVu Serif', 'Monospace'. Useful for building font-picker UIs or verifying that a required font is installed.Info
'1.52.1'.Code Example with Cairo
The typical workflow is to create a Cairo surface and context first (using the
cairo package), then create a Pango layout from the Cairo context with
CreateCairoLayout, configure it, and render with ShowLayoutAt.
uses pango;
var
Layout : TPangoLayout;
CR : TCairoContext; { from cairo package }
W, H : Integer;
begin
{ CR = cairo_create(surface) — created via the cairo package }
Layout := CreateCairoLayout(CR);
SetFontStr(Layout, 'Noto Sans 14');
SetWidth(Layout, 400); { wrap at 400 px }
SetAlignment(Layout, paCenter);
SetEllipsize(Layout, peEnd);
SetLines(Layout, 3); { max 3 lines }
{ Plain text }
SetText(Layout, 'Hello, World!');
GetSize(Layout, W, H);
WriteLn('Layout: ', W, 'x', H, ' px');
ShowLayoutAt(CR, Layout, 10, 20);
{ Markup text }
SetMarkup(Layout, '<b>Bold</b> and <span color="#ff6b6b">red</span> text');
ShowLayoutAt(CR, Layout, 10, 60);
FreeLayout(Layout);
end.
Font Description Syntax
'Family [Style] [Size]'Pango selects the best matching font installed on the system. Style and size are optional.
'Sans Bold 12' — sans-serif, bold, 12 pt'Noto Serif Italic 14' — Noto Serif, italic, 14 pt'Monospace 10' — system monospace, 10 pt'Noto Color Emoji 20' — color emoji font, 20 pt'Noto Sans CJK SC 13' — Chinese (Simplified) text, 13 pt'DejaVu Sans Mono Bold Oblique 11' — bold oblique monospace, 11 ptIf the exact family is not installed, Pango falls back to the closest available alternative. Use
ListFontFamilies to enumerate installed families at runtime.