Files
phy/cosmic_text/index.html
Orion Kindel 0ce894e6b0 doc
2025-03-18 10:30:23 -05:00

54 lines
20 KiB
HTML

<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="COSMIC Text"><title>cosmic_text - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../static.files/rustdoc-42caa33d.css"><meta name="rustdoc-vars" data-root-path="../" data-static-root-path="../static.files/" data-current-crate="cosmic_text" data-themes="" data-resource-suffix="" data-rustdoc-version="1.84.0 (9fc6b4312 2025-01-07)" data-channel="1.84.0" data-search-js="search-92e6798f.js" data-settings-js="settings-0f613d39.js" ><script src="../static.files/storage-59e33391.js"></script><script defer src="../crates.js"></script><script defer src="../static.files/main-5f194d8c.js"></script><noscript><link rel="stylesheet" href="../static.files/noscript-893ab5e7.css"></noscript><link rel="alternate icon" type="image/png" href="../static.files/favicon-32x32-6580c154.png"><link rel="icon" type="image/svg+xml" href="../static.files/favicon-044be391.svg"></head><body class="rustdoc mod crate"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle" title="show sidebar"></button></nav><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../cosmic_text/index.html">cosmic_<wbr>text</a><span class="version">0.12.1</span></h2></div><div class="sidebar-elems"><ul class="block"><li><a id="all-types" href="all.html">All Items</a></li></ul><section id="rustdoc-toc"><h3><a href="#">Sections</a></h3><ul class="block top-toc"><li><a href="#cosmic-text" title="COSMIC Text">COSMIC Text</a></li></ul><h3><a href="#reexports">Crate Items</a></h3><ul class="block"><li><a href="#reexports" title="Re-exports">Re-exports</a></li><li><a href="#structs" title="Structs">Structs</a></li><li><a href="#enums" title="Enums">Enums</a></li><li><a href="#traits" title="Traits">Traits</a></li></ul></section><div id="rustdoc-modnav"></div></div></nav><div class="sidebar-resizer"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><h1>Crate <span>cosmic_text</span><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"><a class="src" href="../src/cosmic_text/lib.rs.html#3-150">Source</a> </span></div><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><h2 id="cosmic-text"><a class="doc-anchor" href="#cosmic-text">§</a>COSMIC Text</h2>
<p>This library provides advanced text handling in a generic way. It provides abstractions for
shaping, font discovery, font fallback, layout, rasterization, and editing. Shaping utilizes
rustybuzz, font discovery utilizes fontdb, and the rasterization is optional and utilizes
swash. The other features are developed internal to this library.</p>
<p>It is recommended that you start by creating a <a href="struct.FontSystem.html" title="struct cosmic_text::FontSystem"><code>FontSystem</code></a>, after which you can create a
<a href="struct.Buffer.html" title="struct cosmic_text::Buffer"><code>Buffer</code></a>, provide it with some text, and then inspect the layout it produces. At this
point, you can use the <code>SwashCache</code> to rasterize glyphs into either images or pixels.</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>cosmic_text::{Attrs, Color, FontSystem, SwashCache, Buffer, Metrics, Shaping};
<span class="comment">// A FontSystem provides access to detected system fonts, create one per application
</span><span class="kw">let </span><span class="kw-2">mut </span>font_system = FontSystem::new();
<span class="comment">// A SwashCache stores rasterized glyphs, create one per application
</span><span class="kw">let </span><span class="kw-2">mut </span>swash_cache = SwashCache::new();
<span class="comment">// Text metrics indicate the font size and line height of a buffer
</span><span class="kw">let </span>metrics = Metrics::new(<span class="number">14.0</span>, <span class="number">20.0</span>);
<span class="comment">// A Buffer provides shaping and layout for a UTF-8 string, create one per text widget
</span><span class="kw">let </span><span class="kw-2">mut </span>buffer = Buffer::new(<span class="kw-2">&amp;mut </span>font_system, metrics);
<span class="comment">// Borrow buffer together with the font system for more convenient method calls
</span><span class="kw">let </span><span class="kw-2">mut </span>buffer = buffer.borrow_with(<span class="kw-2">&amp;mut </span>font_system);
<span class="comment">// Set a size for the text buffer, in pixels
</span>buffer.set_size(<span class="prelude-val">Some</span>(<span class="number">80.0</span>), <span class="prelude-val">Some</span>(<span class="number">25.0</span>));
<span class="comment">// Attributes indicate what font to choose
</span><span class="kw">let </span>attrs = Attrs::new();
<span class="comment">// Add some text!
</span>buffer.set_text(<span class="string">"Hello, Rust! 🦀\n"</span>, attrs, Shaping::Advanced);
<span class="comment">// Perform shaping as desired
</span>buffer.shape_until_scroll(<span class="bool-val">true</span>);
<span class="comment">// Inspect the output runs
</span><span class="kw">for </span>run <span class="kw">in </span>buffer.layout_runs() {
<span class="kw">for </span>glyph <span class="kw">in </span>run.glyphs.iter() {
<span class="macro">println!</span>(<span class="string">"{:#?}"</span>, glyph);
}
}
<span class="comment">// Create a default text color
</span><span class="kw">let </span>text_color = Color::rgb(<span class="number">0xFF</span>, <span class="number">0xFF</span>, <span class="number">0xFF</span>);
<span class="comment">// Draw the buffer (for performance, instead use SwashCache directly)
</span>buffer.draw(<span class="kw-2">&amp;mut </span>swash_cache, text_color, |x, y, w, h, color| {
<span class="comment">// Fill in your code here for drawing rectangles
</span>});</code></pre></div>
</div></details><h2 id="reexports" class="section-header">Re-exports<a href="#reexports" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name" id="reexport.ttf_parser"><code>pub use ttf_parser;</code></div></li><li><div class="item-name" id="reexport.fontdb"><code>pub use <a class="mod" href="../fontdb/index.html" title="mod fontdb">fontdb</a>;</code></div></li><li><div class="item-name" id="reexport.rustybuzz"><code>pub use <a class="mod" href="../rustybuzz/index.html" title="mod rustybuzz">rustybuzz</a>;</code></div></li></ul><h2 id="structs" class="section-header">Structs<a href="#structs" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name"><a class="struct" href="struct.Angle.html" title="struct cosmic_text::Angle">Angle</a></div><div class="desc docblock-short">Represents an angle in degrees or radians.</div></li><li><div class="item-name"><a class="struct" href="struct.Attrs.html" title="struct cosmic_text::Attrs">Attrs</a></div><div class="desc docblock-short">Text attributes</div></li><li><div class="item-name"><a class="struct" href="struct.AttrsList.html" title="struct cosmic_text::AttrsList">Attrs<wbr>List</a></div><div class="desc docblock-short">List of text attributes to apply to a line</div></li><li><div class="item-name"><a class="struct" href="struct.AttrsOwned.html" title="struct cosmic_text::AttrsOwned">Attrs<wbr>Owned</a></div><div class="desc docblock-short">An owned version of <a href="struct.Attrs.html" title="struct cosmic_text::Attrs"><code>Attrs</code></a></div></li><li><div class="item-name"><a class="struct" href="struct.BidiParagraphs.html" title="struct cosmic_text::BidiParagraphs">Bidi<wbr>Paragraphs</a></div><div class="desc docblock-short">An iterator over the paragraphs in the input text.
It is equivalent to <a href="https://doc.rust-lang.org/1.84.0/core/str/iter/struct.Lines.html" title="struct core::str::iter::Lines"><code>core::str::Lines</code></a> but follows <code>unicode-bidi</code> behaviour.</div></li><li><div class="item-name"><a class="struct" href="struct.BorrowedWithFontSystem.html" title="struct cosmic_text::BorrowedWithFontSystem">Borrowed<wbr>With<wbr>Font<wbr>System</a></div><div class="desc docblock-short">A value borrowed together with an <a href="struct.FontSystem.html" title="struct cosmic_text::FontSystem"><code>FontSystem</code></a></div></li><li><div class="item-name"><a class="struct" href="struct.Buffer.html" title="struct cosmic_text::Buffer">Buffer</a></div><div class="desc docblock-short">A buffer of text that is shaped and laid out</div></li><li><div class="item-name"><a class="struct" href="struct.BufferLine.html" title="struct cosmic_text::BufferLine">Buffer<wbr>Line</a></div><div class="desc docblock-short">A line (or paragraph) of text that is shaped and laid out</div></li><li><div class="item-name"><a class="struct" href="struct.CacheKey.html" title="struct cosmic_text::CacheKey">Cache<wbr>Key</a></div><div class="desc docblock-short">Key for building a glyph cache</div></li><li><div class="item-name"><a class="struct" href="struct.CacheKeyFlags.html" title="struct cosmic_text::CacheKeyFlags">Cache<wbr>KeyFlags</a></div><div class="desc docblock-short">Flags that change rendering</div></li><li><div class="item-name"><a class="struct" href="struct.CacheMetrics.html" title="struct cosmic_text::CacheMetrics">Cache<wbr>Metrics</a></div><div class="desc docblock-short">Metrics, but implementing Eq and Hash using u32 representation of f32</div></li><li><div class="item-name"><a class="struct" href="struct.Change.html" title="struct cosmic_text::Change">Change</a></div><div class="desc docblock-short">A set of change items grouped into one logical change</div></li><li><div class="item-name"><a class="struct" href="struct.ChangeItem.html" title="struct cosmic_text::ChangeItem">Change<wbr>Item</a></div><div class="desc docblock-short">A unique change to an editor</div></li><li><div class="item-name"><a class="struct" href="struct.Color.html" title="struct cosmic_text::Color">Color</a></div><div class="desc docblock-short">Text color</div></li><li><div class="item-name"><a class="struct" href="struct.Cursor.html" title="struct cosmic_text::Cursor">Cursor</a></div><div class="desc docblock-short">Current cursor location</div></li><li><div class="item-name"><a class="struct" href="struct.Editor.html" title="struct cosmic_text::Editor">Editor</a></div><div class="desc docblock-short">A wrapper of [<code>Buffer</code>] for easy editing</div></li><li><div class="item-name"><a class="struct" href="struct.Font.html" title="struct cosmic_text::Font">Font</a></div><div class="desc docblock-short">A font</div></li><li><div class="item-name"><a class="struct" href="struct.FontMatchAttrs.html" title="struct cosmic_text::FontMatchAttrs">Font<wbr>Match<wbr>Attrs</a></div><div class="desc docblock-short">Font-specific part of <a href="struct.Attrs.html" title="struct cosmic_text::Attrs"><code>Attrs</code></a> to be used for matching</div></li><li><div class="item-name"><a class="struct" href="struct.FontMatchKey.html" title="struct cosmic_text::FontMatchKey">Font<wbr>Match<wbr>Key</a></div></li><li><div class="item-name"><a class="struct" href="struct.FontSystem.html" title="struct cosmic_text::FontSystem">Font<wbr>System</a></div><div class="desc docblock-short">Access to the system fonts.</div></li><li><div class="item-name"><a class="struct" href="struct.LayoutCursor.html" title="struct cosmic_text::LayoutCursor">Layout<wbr>Cursor</a></div><div class="desc docblock-short">The position of a cursor within a [<code>Buffer</code>].</div></li><li><div class="item-name"><a class="struct" href="struct.LayoutGlyph.html" title="struct cosmic_text::LayoutGlyph">Layout<wbr>Glyph</a></div><div class="desc docblock-short">A laid out glyph</div></li><li><div class="item-name"><a class="struct" href="struct.LayoutLine.html" title="struct cosmic_text::LayoutLine">Layout<wbr>Line</a></div><div class="desc docblock-short">A line of laid out glyphs</div></li><li><div class="item-name"><a class="struct" href="struct.LayoutRun.html" title="struct cosmic_text::LayoutRun">Layout<wbr>Run</a></div><div class="desc docblock-short">A line of visible text for rendering</div></li><li><div class="item-name"><a class="struct" href="struct.LayoutRunIter.html" title="struct cosmic_text::LayoutRunIter">Layout<wbr>RunIter</a></div><div class="desc docblock-short">An iterator of visible text lines, see <a href="struct.LayoutRun.html" title="struct cosmic_text::LayoutRun"><code>LayoutRun</code></a></div></li><li><div class="item-name"><a class="struct" href="struct.LineIter.html" title="struct cosmic_text::LineIter">Line<wbr>Iter</a></div><div class="desc docblock-short">Iterator over lines terminated by <a href="enum.LineEnding.html" title="enum cosmic_text::LineEnding"><code>LineEnding</code></a></div></li><li><div class="item-name"><a class="struct" href="struct.Metrics.html" title="struct cosmic_text::Metrics">Metrics</a></div><div class="desc docblock-short">Metrics of text</div></li><li><div class="item-name"><a class="struct" href="struct.PhysicalGlyph.html" title="struct cosmic_text::PhysicalGlyph">Physical<wbr>Glyph</a></div></li><li><div class="item-name"><a class="struct" href="struct.Placement.html" title="struct cosmic_text::Placement">Placement</a></div><div class="desc docblock-short">Describes the offset and dimensions of a rendered mask.</div></li><li><div class="item-name"><a class="struct" href="struct.Scroll.html" title="struct cosmic_text::Scroll">Scroll</a></div><div class="desc docblock-short">Scroll position in [<code>Buffer</code>]</div></li><li><div class="item-name"><a class="struct" href="struct.ShapeBuffer.html" title="struct cosmic_text::ShapeBuffer">Shape<wbr>Buffer</a></div><div class="desc docblock-short">A set of buffers containing allocations for shaped text.</div></li><li><div class="item-name"><a class="struct" href="struct.ShapeGlyph.html" title="struct cosmic_text::ShapeGlyph">Shape<wbr>Glyph</a></div><div class="desc docblock-short">A shaped glyph</div></li><li><div class="item-name"><a class="struct" href="struct.ShapeLine.html" title="struct cosmic_text::ShapeLine">Shape<wbr>Line</a></div><div class="desc docblock-short">A shaped line (or paragraph)</div></li><li><div class="item-name"><a class="struct" href="struct.ShapeRunCache.html" title="struct cosmic_text::ShapeRunCache">Shape<wbr>RunCache</a></div><div class="desc docblock-short">A helper structure for caching shape runs.</div></li><li><div class="item-name"><a class="struct" href="struct.ShapeRunKey.html" title="struct cosmic_text::ShapeRunKey">Shape<wbr>RunKey</a></div><div class="desc docblock-short">Key for caching shape runs.</div></li><li><div class="item-name"><a class="struct" href="struct.ShapeSpan.html" title="struct cosmic_text::ShapeSpan">Shape<wbr>Span</a></div><div class="desc docblock-short">A shaped span (for bidirectional processing)</div></li><li><div class="item-name"><a class="struct" href="struct.ShapeWord.html" title="struct cosmic_text::ShapeWord">Shape<wbr>Word</a></div><div class="desc docblock-short">A shaped word (for word wrapping)</div></li><li><div class="item-name"><a class="struct" href="struct.SwashCache.html" title="struct cosmic_text::SwashCache">Swash<wbr>Cache</a></div><div class="desc docblock-short">Cache for rasterizing with the swash scaler</div></li><li><div class="item-name"><a class="struct" href="struct.SwashImage.html" title="struct cosmic_text::SwashImage">Swash<wbr>Image</a></div><div class="desc docblock-short">Scaled glyph image.</div></li><li><div class="item-name"><a class="struct" href="struct.Transform.html" title="struct cosmic_text::Transform">Transform</a></div><div class="desc docblock-short">Two dimensional transformation matrix.</div></li><li><div class="item-name"><a class="struct" href="struct.Weight.html" title="struct cosmic_text::Weight">Weight</a></div><div class="desc docblock-short">Specifies the weight of glyphs in the font, their degree of blackness or stroke thickness.</div></li></ul><h2 id="enums" class="section-header">Enums<a href="#enums" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name"><a class="enum" href="enum.Action.html" title="enum cosmic_text::Action">Action</a></div><div class="desc docblock-short">An action to perform on an <a href="struct.Editor.html" title="struct cosmic_text::Editor"><code>Editor</code></a></div></li><li><div class="item-name"><a class="enum" href="enum.Affinity.html" title="enum cosmic_text::Affinity">Affinity</a></div><div class="desc docblock-short">Whether to associate cursors placed at a boundary between runs with the run before or after it.</div></li><li><div class="item-name"><a class="enum" href="enum.Align.html" title="enum cosmic_text::Align">Align</a></div><div class="desc docblock-short">Align or justify</div></li><li><div class="item-name"><a class="enum" href="enum.BufferRef.html" title="enum cosmic_text::BufferRef">Buffer<wbr>Ref</a></div></li><li><div class="item-name"><a class="enum" href="enum.Command.html" title="enum cosmic_text::Command">Command</a></div><div class="desc docblock-short">Path command.</div></li><li><div class="item-name"><a class="enum" href="enum.Family.html" title="enum cosmic_text::Family">Family</a></div><div class="desc docblock-short">A <a href="https://www.w3.org/TR/2018/REC-css-fonts-3-20180920/#propdef-font-family">font family</a>.</div></li><li><div class="item-name"><a class="enum" href="enum.FamilyOwned.html" title="enum cosmic_text::FamilyOwned">Family<wbr>Owned</a></div><div class="desc docblock-short">An owned version of <a href="enum.Family.html" title="enum cosmic_text::Family"><code>Family</code></a></div></li><li><div class="item-name"><a class="enum" href="enum.LineEnding.html" title="enum cosmic_text::LineEnding">Line<wbr>Ending</a></div><div class="desc docblock-short">Line ending</div></li><li><div class="item-name"><a class="enum" href="enum.Motion.html" title="enum cosmic_text::Motion">Motion</a></div><div class="desc docblock-short">A motion to perform on a <a href="struct.Cursor.html" title="struct cosmic_text::Cursor"><code>Cursor</code></a></div></li><li><div class="item-name"><a class="enum" href="enum.Selection.html" title="enum cosmic_text::Selection">Selection</a></div><div class="desc docblock-short">Selection mode</div></li><li><div class="item-name"><a class="enum" href="enum.Shaping.html" title="enum cosmic_text::Shaping">Shaping</a></div><div class="desc docblock-short">The shaping strategy of some text.</div></li><li><div class="item-name"><a class="enum" href="enum.Stretch.html" title="enum cosmic_text::Stretch">Stretch</a></div><div class="desc docblock-short">A face <a href="https://docs.microsoft.com/en-us/typography/opentype/spec/os2#uswidthclass">width</a>.</div></li><li><div class="item-name"><a class="enum" href="enum.Style.html" title="enum cosmic_text::Style">Style</a></div><div class="desc docblock-short">Allows italic or oblique faces to be selected.</div></li><li><div class="item-name"><a class="enum" href="enum.SubpixelBin.html" title="enum cosmic_text::SubpixelBin">Subpixel<wbr>Bin</a></div><div class="desc docblock-short">Binning of subpixel position for cache optimization</div></li><li><div class="item-name"><a class="enum" href="enum.SwashContent.html" title="enum cosmic_text::SwashContent">Swash<wbr>Content</a></div><div class="desc docblock-short">Content of a scaled glyph image.</div></li><li><div class="item-name"><a class="enum" href="enum.Wrap.html" title="enum cosmic_text::Wrap">Wrap</a></div><div class="desc docblock-short">Wrapping mode</div></li></ul><h2 id="traits" class="section-header">Traits<a href="#traits" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name"><a class="trait" href="trait.Edit.html" title="trait cosmic_text::Edit">Edit</a></div><div class="desc docblock-short">A trait to allow easy replacements of <a href="struct.Editor.html" title="struct cosmic_text::Editor"><code>Editor</code></a>, like <code>SyntaxEditor</code></div></li></ul></section></div></main></body></html>