Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
emoji_segmenter.hpp
Go to the documentation of this file.
1// emoji_segmenter.hpp — Unicode-aware run segmentation for color-emoji
2// fallback.
3//
4// HarfBuzz can only shape a multi-codepoint emoji sequence (ZWJ family,
5// regional flag, keycap, skin-tone modifier, tag sequence, FE0F-promoted
6// base) as a single cluster if the entire sequence lands on one font run.
7// Naive per-codepoint fallback splits 👨 + ZWJ + 👩 + ZWJ + 👧 into five
8// separate font runs and you get five glyphs back — exactly the failure
9// mode the per-codepoint EmojiRasterizer approach has.
10//
11// `segment_emoji_runs(utf8)` walks codepoints, classifies them with a
12// curated subset of the Unicode 16.0 emoji property tables (the ranges
13// that actually contain emoji as of cutoff), forms grapheme clusters
14// according to UAX #29 / UTS #51 cluster-extending rules, and emits a
15// minimal list of runs tagged `Default` or `Emoji`. Adjacent runs of the
16// same role are coalesced. Variation selectors are NEVER stripped:
17// - U+FE0F forces emoji presentation → the containing cluster routes
18// to the emoji font.
19// - U+FE0E forces text presentation → the containing cluster routes to
20// the default font even when the base codepoint is emoji-default.
21//
22// The segmenter is intentionally Skia-free so it can be unit-tested in
23// isolation and reused by both `SkiaCanvas::fill_text` and
24// `text_shaper.cpp::measure_segment` for parity.
25
26#pragma once
27
28#include <cstddef>
29#include <string_view>
30#include <vector>
31
32namespace pulp::canvas {
33
41enum class FontRunRole : unsigned char {
43 Emoji = 1,
44};
45
46struct FontRun {
48 std::size_t byte_start;
50 std::size_t byte_end;
52};
53
61std::vector<FontRun> segment_emoji_runs(std::string_view utf8_text);
62
68bool contains_emoji(std::string_view utf8_text);
69
70} // namespace pulp::canvas
Definition affine_transform.hpp:24
FontRunRole
Which font role a run should resolve against.
Definition emoji_segmenter.hpp:41
@ Emoji
Definition emoji_segmenter.hpp:43
@ Default
Definition emoji_segmenter.hpp:42
std::vector< FontRun > segment_emoji_runs(std::string_view utf8_text)
Segment utf8_text into runs that respect emoji grapheme clusters.
bool contains_emoji(std::string_view utf8_text)
Cheap test: returns true if utf8_text contains at least one codepoint that the segmenter would route ...
Definition emoji_segmenter.hpp:46
std::size_t byte_end
Exclusive byte offset into the input.
Definition emoji_segmenter.hpp:50
FontRunRole role
Definition emoji_segmenter.hpp:51
std::size_t byte_start
Inclusive byte offset into the input.
Definition emoji_segmenter.hpp:48