You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
COLR glyphs take their colors from the font's CPAL palette table. Many color fonts ship more than one palette, such as a default and a dark-background variant. [`TextOptions.FontPalette`](xref:SixLabors.Fonts.TextOptions.FontPalette) selects the palette that resolves the colors. Leave the value `null` to keep the font's default palette.
// Resolve COLR glyph colors with the font's second palette.
58
+
// Palette indexes are zero-based; null keeps the font's default.
59
+
FontPalette=newFontPalette(1)
60
+
};
61
+
```
62
+
63
+
A palette selection can also override individual entries. Each [`FontPaletteOverride`](xref:SixLabors.Fonts.FontPaletteOverride) replaces the palette color at one index:
64
+
65
+
```csharp
66
+
// Start from the default palette, then replace entry 2 with opaque red.
[`TextRun.FontPalette`](xref:SixLabors.Fonts.TextRun.FontPalette) replaces the selection over a range of text. [`GlyphOptions.FontPalette`](xref:SixLabors.Fonts.GlyphOptions.FontPalette) applies the same selection when rendering or measuring by glyph ID.
74
+
47
75
## What happens in custom renderers
48
76
49
77
When a resolved glyph is a painted color glyph, Fonts streams it through [`IGlyphRenderer`](xref:SixLabors.Fonts.Rendering.IGlyphRenderer) as one or more layers.
@@ -52,9 +80,10 @@ That means custom renderers should pay attention to:
-[`BeginGroup(...)`](xref:SixLabors.Fonts.Rendering.IGlyphRenderer.BeginGroup*) and [`EndGroup()`](xref:SixLabors.Fonts.Rendering.IGlyphRenderer.EndGroup*)
COLR v1 paint graphs can also form composite groups. Fonts wraps such content in [`BeginGroup(...)`](xref:SixLabors.Fonts.Rendering.IGlyphRenderer.BeginGroup*) and [`EndGroup()`](xref:SixLabors.Fonts.Rendering.IGlyphRenderer.EndGroup*) calls. Layers inside a group compose as one isolated unit. The finished group then blends onto the content below it with the [`CompositeMode`](xref:SixLabors.Fonts.Rendering.CompositeMode) given to `BeginGroup(...)`. A clip for the glyph arrives through [`GlyphRendererParameters.ClipBounds`](xref:SixLabors.Fonts.Rendering.GlyphRendererParameters.ClipBounds).
96
+
66
97
If your renderer ignores paint information, the glyph can still be drawn, but it will no longer preserve the font's intended color presentation.
Copy file name to clipboardExpand all lines: articles/fonts/customrendering.md
+10-2Lines changed: 10 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -27,7 +27,7 @@ For monochrome outline glyphs, the path callbacks are delivered inside [`BeginGl
27
27
5.`SetDecoration(...)` for any decorations requested by `EnabledDecorations()`
28
28
6.`EndText()`
29
29
30
-
Painted color glyphs add [`BeginLayer(...)`](xref:SixLabors.Fonts.Rendering.IGlyphRenderer.BeginLayer*) / [`EndLayer()`](xref:SixLabors.Fonts.Rendering.IGlyphRenderer.EndLayer*) around each painted layer between [`BeginGlyph(...)`](xref:SixLabors.Fonts.Rendering.IGlyphRenderer.BeginGlyph*) and [`EndGlyph()`](xref:SixLabors.Fonts.Rendering.IGlyphRenderer.EndGlyph*).
30
+
Painted color glyphs add [`BeginLayer(...)`](xref:SixLabors.Fonts.Rendering.IGlyphRenderer.BeginLayer*) / [`EndLayer()`](xref:SixLabors.Fonts.Rendering.IGlyphRenderer.EndLayer*) around each painted layer between [`BeginGlyph(...)`](xref:SixLabors.Fonts.Rendering.IGlyphRenderer.BeginGlyph*) and [`EndGlyph()`](xref:SixLabors.Fonts.Rendering.IGlyphRenderer.EndGlyph*). COLR v1 composite content adds [`BeginGroup(...)`](xref:SixLabors.Fonts.Rendering.IGlyphRenderer.BeginGroup*) / [`EndGroup()`](xref:SixLabors.Fonts.Rendering.IGlyphRenderer.EndGroup*) around layers that must compose as one isolated unit before they blend onto the content below.
31
31
32
32
[`BeginGlyph(...)`](xref:SixLabors.Fonts.Rendering.IGlyphRenderer.BeginGlyph*) receives [`GlyphRendererParameters`](xref:SixLabors.Fonts.Rendering.GlyphRendererParameters), which identify the glyph instance being rendered, including the glyph ID, the glyph's [`CodePoint`](xref:SixLabors.Fonts.Unicode.CodePoint) value, font style, point size, DPI, layout mode, hinting mode, and active [`TextRun`](xref:SixLabors.Fonts.TextRun). Return `false` from `BeginGlyph(...)` if you want to skip rendering that glyph. The parameters include everything that changes glyph geometry, so a renderer can use them as a cache key.
33
33
@@ -57,14 +57,22 @@ public sealed class RecordingGlyphRenderer : IGlyphRenderer
Copy file name to clipboardExpand all lines: articles/fonts/fallbackfonts.md
+22Lines changed: 22 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -34,6 +34,28 @@ Fallback families are searched in the order you provide them.
34
34
- Put emoji fonts after your normal text families unless you explicitly want them to win earlier.
35
35
- Keep the fallback list as small and intentional as possible so the selection stays predictable.
36
36
37
+
## Resolver-based fallback
38
+
39
+
[`FallbackFontFamilies`](xref:SixLabors.Fonts.TextOptions.FallbackFontFamilies) is a fixed list. [`TextOptions.FontFallbackResolver`](xref:SixLabors.Fonts.TextOptions.FontFallbackResolver) adds a dynamic last step behind it. Shaping consults the resolver only for code points that neither the primary font nor any fallback family can shape. It asks at most once per distinct unresolved code point per shaping operation. Leave the value `null` to render such code points as the missing-glyph outline.
40
+
41
+
[`SystemFonts.FallbackResolver`](xref:SixLabors.Fonts.SystemFonts.FallbackResolver) is a built-in resolver that selects from the fonts installed on the current machine:
42
+
43
+
```csharp
44
+
usingSixLabors.Fonts;
45
+
46
+
Fontfont=SystemFonts.CreateFont("Segoe UI", 18);
47
+
TextOptionsoptions=new(font)
48
+
{
49
+
// Ask the operating system for a family when no configured font
50
+
// can shape a code point.
51
+
FontFallbackResolver=SystemFonts.FallbackResolver
52
+
};
53
+
```
54
+
55
+
Installed fonts differ between machines, so output rendered with the system resolver can differ too. Pin `FallbackFontFamilies` for output that must stay identical everywhere, and use the resolver as a safety net behind them.
56
+
57
+
Implement [`IFontFallbackResolver`](xref:SixLabors.Fonts.IFontFallbackResolver) for a custom policy. The resolver receives the code point, the requested family, the style, and the culture. It returns the family that contains a glyph for the code point.
58
+
37
59
## Mixed-script example
38
60
39
61
This pattern works well for text that mixes Latin, Arabic, and emoji:
Copy file name to clipboardExpand all lines: articles/fonts/shaping.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -53,7 +53,7 @@ At a high level, Fonts does the following:
53
53
5. Applies right-to-left mirrored forms and vertical alternates where the layout requires them.
54
54
6. Applies OpenType GSUB substitutions through the appropriate script shaper.
55
55
7. Applies GPOS positioning for kerning, marks, cursive attachment, and related placement behavior.
56
-
8. Retries unmapped code points with the configured fallback font families.
56
+
8. Retries unmapped code points with the configured fallback font families, then with families from [`FontFallbackResolver`](xref:SixLabors.Fonts.TextOptions.FontFallbackResolver) when one is set.
57
57
9. Updates final glyph positions for every font involved in the shaped result.
58
58
59
59
The first shaping result is independent of wrapping width. Line composition and alignment happen after shaping, so the same shaped text can be measured, wrapped, rendered, or inspected without changing which glyphs were chosen.
@@ -127,7 +127,7 @@ Mirrored forms, such as paired punctuation in right-to-left runs, are part of th
127
127
128
128
Fallback is not just a missing-glyph replacement step at the end of rendering. It participates in shaping because each font has its own glyph coverage, metrics, OpenType tables, script tags, and mark positioning behavior.
129
129
130
-
When the primary text-run font cannot map every code point, Fonts retries unresolved text against [`FallbackFontFamilies`](xref:SixLabors.Fonts.TextOptions.FallbackFontFamilies). The fallback font supplies the glyphs and positions for the code points it covers.
130
+
When the primary text-run font cannot map every code point, Fonts retries unresolved text against [`FallbackFontFamilies`](xref:SixLabors.Fonts.TextOptions.FallbackFontFamilies). The fallback font supplies the glyphs and positions for the code points it covers. A configured [`FontFallbackResolver`](xref:SixLabors.Fonts.TextOptions.FontFallbackResolver) is consulted last, for code points that no listed family can shape. See [Fallback Fonts and Multilingual Text](fallbackfonts.md).
131
131
132
132
For multilingual text, emoji, and complex scripts, validate fallback with real production strings. A font can contain the individual code points but still lack the OpenType data needed for correct shaping.
Copy file name to clipboardExpand all lines: articles/fonts/systemfonts.md
+2Lines changed: 2 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -12,6 +12,8 @@ The main entry points are:
12
12
-[`SystemFonts.Get(...)`](xref:SixLabors.Fonts.SystemFonts.Get*) and [`SystemFonts.TryGet(...)`](xref:SixLabors.Fonts.SystemFonts.TryGet*) to resolve a family by invariant name
13
13
-[`SystemFonts.CreateFont(...)`](xref:SixLabors.Fonts.SystemFonts.CreateFont*) to create a [`Font`](xref:SixLabors.Fonts.Font) directly
14
14
-[`SystemFonts.Collection`](xref:SixLabors.Fonts.SystemFonts.Collection) when you also need access to the searched directories
15
+
-[`SystemFonts.TryMatchCharacter(...)`](xref:SixLabors.Fonts.SystemFonts.TryMatchCharacter*) to ask the operating system which installed font covers a code point
16
+
-[`SystemFonts.FallbackResolver`](xref:SixLabors.Fonts.SystemFonts.FallbackResolver) to let text shaping consult the system for unresolved code points; see [Fallback Fonts and Multilingual Text](fallbackfonts.md)
Copy file name to clipboardExpand all lines: articles/imagesharp.drawing/canvas.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -220,7 +220,7 @@ Layer bounds limit the isolated target and final composition area. They do not m
220
220
221
221
A layer is useful when a group of commands must be blended as one result. Without a layer, each command is blended into the parent independently. With a layer, commands first render into an isolated target, then that whole target is composited back once.
222
222
223
-
`SaveLayer(...)` overloads also accept a [`LayerEffect`](xref:SixLabors.ImageSharp.Drawing.Processing.LayerEffect), such as blur, drop shadow, glow, or a backdrop filter, that transforms the layer when it is restored. See [Clipping, Regions, and Layers](clippingregionslayers.md) for the effect model.
223
+
`SaveLayer(...)` overloads also accept a [`LayerEffect`](xref:SixLabors.ImageSharp.Drawing.Processing.LayerEffect), such as blur, drop shadow, glow, or a backdrop filter, that transforms the layer when it is restored. See [Layer and Backdrop Effects](layereffects.md) for the effect model.
Copy file name to clipboardExpand all lines: articles/imagesharp.drawing/clippingregionslayers.md
+2-71Lines changed: 2 additions & 71 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -114,83 +114,14 @@ Use layers when a group of commands should blend back as one result. Without a l
114
114
115
115
## Layer Effects
116
116
117
-
`SaveLayer(...)` overloads accept a [`LayerEffect`](xref:SixLabors.ImageSharp.Drawing.Processing.LayerEffect) that transforms the layer content when the layer is restored. The layer isolates the content, so the effect operates on exactly what was drawn between `SaveLayer(...)` and `Restore()`, against transparency, before the result composites onto the canvas.
118
-
119
-
The built-in content effects are:
120
-
121
-
-[`BlurLayerEffect`](xref:SixLabors.ImageSharp.Drawing.Processing.BlurLayerEffect) blurs the layer content with a Gaussian sigma.
122
-
-[`DropShadowLayerEffect`](xref:SixLabors.ImageSharp.Drawing.Processing.DropShadowLayerEffect) slots a blurred, offset shadow beneath the layer content.
123
-
-[`GlowLayerEffect`](xref:SixLabors.ImageSharp.Drawing.Processing.GlowLayerEffect) surrounds the content with a colored glow.
124
-
-[`InnerShadowLayerEffect`](xref:SixLabors.ImageSharp.Drawing.Processing.InnerShadowLayerEffect) shades the content inside its own edges.
125
-
-[`ColorMatrixLayerEffect`](xref:SixLabors.ImageSharp.Drawing.Processing.ColorMatrixLayerEffect) transforms the content colors through a `ColorMatrix`.
126
-
127
-
The layer bounds are expanded internally by the effect's reach, so blurred or offset output is not cut off.
An overload accepts an `IPath` region instead of a rectangle. The effect then processes only pixels covered by the path, and its output lands on the path translated by the effect's offset.
150
-
151
-
## Backdrop Effects
152
-
153
-
A [`BackdropLayerEffect`](xref:SixLabors.ImageSharp.Drawing.Processing.BackdropLayerEffect) filters the pixels already on the canvas beneath the layer's region. The filter runs when the layer is opened, the filtered result is clipped to the region, and the layer's content then renders above it. This is the CSS `backdrop-filter` model.
154
-
155
-
The built-in backdrop effects are:
156
-
157
-
-[`BackdropBlurLayerEffect`](xref:SixLabors.ImageSharp.Drawing.Processing.BackdropBlurLayerEffect) blurs the backdrop, the classic frosted-glass base.
158
-
-[`BackdropAcrylicLayerEffect`](xref:SixLabors.ImageSharp.Drawing.Processing.BackdropAcrylicLayerEffect) combines a blur with a tint color for acrylic panels.
159
-
-[`BackdropDropShadowLayerEffect`](xref:SixLabors.ImageSharp.Drawing.Processing.BackdropDropShadowLayerEffect) casts a shadow from the backdrop content.
160
-
-[`BackdropColorMatrixLayerEffect`](xref:SixLabors.ImageSharp.Drawing.Processing.BackdropColorMatrixLayerEffect) transforms backdrop colors through a `ColorMatrix`. Prebuilt variants cover brightness, contrast, grayscale, hue rotation, inversion, opacity, sepia, and saturation.
// The backdrop inside the panel is already blurred and tinted.
180
-
// Content drawn here renders above the filtered backdrop.
181
-
canvas.Draw(Pens.Solid(Color.White, 2), panel);
182
-
canvas.Restore();
183
-
}));
184
-
```
185
-
186
-
Content effects and backdrop effects answer different questions. Use a content effect when the drawing inside the layer needs the treatment. Use a backdrop effect when the pixels behind a panel need the treatment and the panel content must stay sharp.
117
+
`SaveLayer(...)` overloads accept effects that transform the layer when it is restored: blur, drop shadow, glow, inner shadow, color matrix, and CSS-style backdrop filters. The built-in set, the GPU shader implementations, and custom effect authoring have a dedicated page. See [Layer and Backdrop Effects](layereffects.md).
187
118
188
119
## Practical Guidance
189
120
190
121
- Use clips when geometry should constrain later commands in the current coordinate space.
191
122
- Use regions when a child layout should have its own local origin.
192
123
- Use layers when several commands should blend back as one grouped result.
193
-
- Use a `LayerEffect` when the layer content needs blur, shadow, glow, or color treatment as a group.
124
+
- Use a `LayerEffect` when the layer content needs blur, shadow, glow, or color treatment as a group. See [Layer and Backdrop Effects](layereffects.md).
194
125
- Use a `BackdropLayerEffect` when the pixels behind a region need treatment while the content on top stays sharp.
195
126
- Remember that layer bounds constrain composition but do not move the coordinate system.
196
127
- Restore saved state as soon as the scoped work is complete.
0 commit comments