Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
text_raster_policy.hpp
Go to the documentation of this file.
1#pragma once
2
3// How a render surface maps glyph coverage to pixels.
4//
5// Skia applies a contrast and gamma "preblend" to glyph masks, and it reads
6// both values from the surface the text is drawn into: SkFont has no gamma
7// field, a saveLayer inherits its parent's values, and the strike cache keys
8// glyphs on them. A text-raster choice is therefore a property of a SURFACE,
9// fixed when the surface is created, and every surface a frame's text can pass
10// through (the frame target, offscreen and scene targets, retained layers) has
11// to be created with the same one, or text painted through a cached layer
12// comes out a different weight from the same text painted directly.
13//
14// Measured on macOS (CoreText through Skia, raster and DPR 2) against Chrome:
15// - `legacy` (Skia's defaults: contrast 0.5, sRGB gamma) with hinting slight
16// reproduces Chromium's `-webkit-font-smoothing: auto` exactly.
17// - `chromium` (contrast 0, gamma 1) with hinting none reproduces
18// `-webkit-font-smoothing: antialiased` exactly, about 23% lighter than
19// `legacy`. An `auto` node drawn on a `chromium` surface is about 2% heavier
20// than Chromium's.
21// No single surface reproduces both modes, so a surface that holds any
22// `antialiased` text is created `chromium` (select_text_raster_policy).
23//
24// Hinting is per font, not per surface, and is chosen by the text painter.
25
26#include <cstdint>
27#include <span>
28
29namespace pulp::canvas {
30
33enum class TextRasterPolicy : std::uint8_t {
36};
37
40enum class FontSmoothing : std::uint8_t {
43};
44
50 float contrast;
51 float gamma;
52};
53
55inline constexpr TextRasterTuple kLegacyTextRaster{0.5f, 0.0f};
56inline constexpr TextRasterTuple kChromiumTextRaster{0.0f, 1.0f};
57
61
69constexpr TextRasterPolicy select_text_raster_policy(std::span<const FontSmoothing> nodes) {
70 for (const FontSmoothing smoothing : nodes) {
71 if (smoothing == FontSmoothing::antialiased)
73 }
75}
76
77} // namespace pulp::canvas
Definition affine_transform.hpp:24
constexpr TextRasterPolicy select_text_raster_policy(std::span< const FontSmoothing > nodes)
The policy for a surface holding text nodes with these smoothing modes: chromium when ANY node is ant...
Definition text_raster_policy.hpp:69
FontSmoothing
CSS -webkit-font-smoothing as it affects glyph rasterization on macOS.
Definition text_raster_policy.hpp:40
@ antialiased
Definition text_raster_policy.hpp:42
@ auto_smoothing
Definition text_raster_policy.hpp:41
constexpr TextRasterTuple kChromiumTextRaster
Definition text_raster_policy.hpp:56
constexpr TextRasterTuple kLegacyTextRaster
Skia's compile-time defaults (SK_GAMMA_CONTRAST, SK_GAMMA_EXPONENT = sRGB).
Definition text_raster_policy.hpp:55
constexpr TextRasterTuple text_raster_tuple(TextRasterPolicy policy)
Definition text_raster_policy.hpp:58
TextRasterPolicy
Glyph preblend a surface is created with.
Definition text_raster_policy.hpp:33
@ legacy
Definition text_raster_policy.hpp:34
@ chromium
Definition text_raster_policy.hpp:35
Surface text contrast and gamma for a policy, the two values SkSurfaceProps carries.
Definition text_raster_policy.hpp:49
float contrast
Definition text_raster_policy.hpp:50
float gamma
Definition text_raster_policy.hpp:51