49 lines
25 KiB
HTML
49 lines
25 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::iced::daemon::program::graphics::text::cosmic_text - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Italic-81dc35de.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-MediumItalic-ccf7e434.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-aa0817cf.css"><meta name="rustdoc-vars" data-root-path="../../../../../../../" data-static-root-path="../../../../../../../static.files/" data-current-crate="cosmic" data-themes="" data-resource-suffix="" data-rustdoc-version="1.90.0-nightly (3048886e5 2025-07-30)" data-channel="nightly" data-search-js="search-fa3e91e5.js" data-settings-js="settings-5514c975.js" ><script src="../../../../../../../static.files/storage-68b7e25d.js"></script><script defer src="../../../../../../../crates.js"></script><script defer src="../../../../../../../static.files/main-eebb9057.js"></script><noscript><link rel="stylesheet" href="../../../../../../../static.files/noscript-32bb7600.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/index.html">cosmic</a><span class="version">1.0.0</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="#modules">Crate Items</a></h3><ul class="block"><li><a href="#modules" title="Modules">Modules</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><li><a href="#functions" title="Functions">Functions</a></li></ul></section><div id="rustdoc-modnav"><h2><a href="../index.html">In cosmic::<wbr>iced::<wbr>daemon::<wbr>program::<wbr>graphics::<wbr>text</a></h2></div></div></nav><div class="sidebar-resizer" title="Drag to resize sidebar"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><div class="rustdoc-breadcrumbs"><a href="../../../../../../index.html">cosmic</a>::<wbr><a href="../../../../../index.html">iced</a>::<wbr><a href="../../../../index.html">daemon</a>::<wbr><a href="../../../index.html">program</a>::<wbr><a href="../../index.html">graphics</a>::<wbr><a href="../index.html">text</a></div><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"></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
|
||
|
|
harfrust, 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::iced::daemon::program::graphics::text::cosmic_text::FontSystem"><code>FontSystem</code></a>, after which you can create a
|
||
|
|
<a href="struct.Buffer.html" title="struct cosmic::iced::daemon::program::graphics::text::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">&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">&mut </span>font_system);
|
||
|
|
|
||
|
|
<span class="comment">// Attributes indicate what font to choose
|
||
|
|
</span><span class="kw">let </span>attrs = Attrs::new();
|
||
|
|
|
||
|
|
<span class="comment">// Set size and text
|
||
|
|
</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>));
|
||
|
|
buffer.set_text(<span class="string">"Hello, Rust! 🦀\n"</span>, <span class="kw-2">&</span>attrs, Shaping::Advanced, <span class="prelude-val">None</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">&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="modules" class="section-header">Modules<a href="#modules" class="anchor">§</a></h2><dl class="item-table"><dt><a class="mod" href="fallback/index.html" title="mod cosmic::iced::daemon::program::graphics::text::cosmic_text::fallback">fallback</a></dt><dt><a class="mod" href="fontdb/index.html" title="mod cosmic::iced::daemon::program::graphics::text::cosmic_text::fontdb">fontdb</a></dt><dd><code>fontdb</code> is a simple, in-memory font database with CSS-like queries.</dd><dt><a class="mod" href="harfrust/index.html" title="mod cosmic::iced::daemon::program::graphics::text::cosmic_text::harfrust">harfrust</a></dt><dd>A complete <a href="https://github.com/harfbuzz/harfbuzz">harfbuzz</a> shaping algorithm port to Rust.</dd><dt><a class="mod" href="skrifa/index.html" title="mod cosmic::iced::daemon::program::graphics::text::cosmic_text::skrifa">skrifa</a></dt><dd>A robust, ergonomic, high performance crate for OpenType fonts.</dd></dl><h2 id="structs" class="section-header">Structs<a href="#structs" class="anchor">§</a></h2><dl class="item-table"><dt><a class="struct" href="struct.Angle.html" title="struct cosmic::iced::daemon::program::graphics::text::cosmic_text::Angle">Angle</a></dt><dd>Represents an angle in degrees or radians.</dd><dt><a class="struct" href="struct.Attrs.html" title="struct cosmic::iced::daemon::program::graphics::text::cosmic_text::Attrs">Attrs</a></dt><dd>Text attributes</dd><dt><a class="struct" href="struct.AttrsList.html" title="struct cosmic::iced::daemon::program::graphics::text::cosmic_text::AttrsList">Attrs<wbr>List</a></dt><dd>List of text attributes to apply to a line</dd><dt><a class="struct" href="struct.AttrsOwned.html" title="struct cosmic::iced::daemon::program::graphics::text::cosmic_text::AttrsOwned">Attrs<wbr>Owned</a></dt><dd>An owned version of <a href="struct.Attrs.html" title="struct cosmic::iced::daemon::program::graphics::text::cosmic_text::Attrs"><code>Attrs</code></a></dd><dt><a class="struct" href="struct.BidiParagraphs.html" title="struct cosmic::iced::daemon::program::graphics::text::cosmic_text::BidiParagraphs">Bidi<wbr>Paragraphs</a></dt><dd>An iterator over the paragraphs in the input text.
|
||
|
|
It is equivalent to <a href="../../../../../../cctk/sctk/reexports/client/backend/smallvec/alloc/str/struct.Lines.html" title="struct cosmic::cctk::sctk::reexports::client::backend::smallvec::alloc::str::Lines"><code>core::str::Lines</code></a> but follows <code>unicode-bidi</code> behaviour.</dd><dt><a class="struct" href="struct.BorrowedWithFontSystem.html" title="struct cosmic::iced::daemon::program::graphics::text::cosmic_text::BorrowedWithFontSystem">Borrowed<wbr>With<wbr>Font<wbr>System</a></dt><dd>A value borrowed together with an <a href="struct.FontSystem.html" title="struct cosmic::iced::daemon::program::graphics::text::cosmic_text::FontSystem"><code>FontSystem</code></a></dd><dt><a class="struct" href="struct.Buffer.html" title="struct cosmic::iced::daemon::program::graphics::text::cosmic_text::Buffer">Buffer</a></dt><dd>A buffer of text that is shaped and laid out</dd><dt><a class="struct" href="struct.BufferLine.html" title="struct cosmic::iced::daemon::program::graphics::text::cosmic_text::BufferLine">Buffer<wbr>Line</a></dt><dd>A line (or paragraph) of text that is shaped and laid out</dd><dt><a class="struct" href="struct.CacheKey.html" title="struct cosmic::iced::daemon::program::graphics::text::cosmic_text::CacheKey">Cache<wbr>Key</a></dt><dd>Key for building a glyph cache</dd><dt><a class="struct" href="struct.CacheKeyFlags.html" title="struct cosmic::iced::daemon::program::graphics::text::cosmic_text::CacheKeyFlags">Cache<wbr>KeyFlags</a></dt><dd>Flags that change rendering</dd><dt><a class="struct" href="struct.CacheMetrics.html" title="struct cosmic::iced::daemon::program::graphics::text::cosmic_text::CacheMetrics">Cache<wbr>Metrics</a></dt><dd>Metrics, but implementing Eq and Hash using u32 representation of f32</dd><dt><a class="struct" href="struct.Change.html" title="struct cosmic::iced::daemon::program::graphics::text::cosmic_text::Change">Change</a></dt><dd>A set of change items grouped into one logical change</dd><dt><a class="struct" href="struct.ChangeItem.html" title="struct cosmic::iced::daemon::program::graphics::text::cosmic_text::ChangeItem">Change<wbr>Item</a></dt><dd>A unique change to an editor</dd><dt><a class="struct" href="struct.Color.html" title="struct cosmic::iced::daemon::program::graphics::text::cosmic_text::Color">Color</a></dt><dd>Text color</dd><dt><a class="struct" href="struct.Cursor.html" title="struct cosmic::iced::daemon::program::graphics::text::cosmic_text::Cursor">Cursor</a></dt><dd>Current cursor location</dd><dt><a class="struct" href="struct.DecorationMetrics.html" title="struct cosmic::iced::daemon::program::graphics::text::cosmic_text::DecorationMetrics">Decoration<wbr>Metrics</a></dt><dd>Offset and thickness for a text decoration line, in EM units.</dd><dt><a class="struct" href="struct.DecorationSpan.html" title="struct cosmic::iced::daemon::program::graphics::text::cosmic_text::DecorationSpan">Decoration<wbr>Span</a></dt><dd>A span of consecutive glyphs sharing the same text decoration.</dd><dt><a class="struct" href="struct.Editor.html" title="struct cosmic::iced::daemon::program::graphics::text::cosmic_text::Editor">Editor</a></dt><dd>A wrapper of [<code>Buffer</code>] for easy editing</dd><dt><a class="struct" href="struct.Feature.html" title="struct cosmic::iced::daemon::program::graphics::text::cosmic_text::Feature">Feature</a></dt><dt><a class="struct" href="struct.FeatureTag.html" title="struct cosmic::iced::daemon::program::graphics::text::cosmic_text::FeatureTag">Feature<wbr>Tag</a></dt><dd>A 4-byte <code>OpenType</code> feature tag identifier</dd><dt><a class="struct" href="struct.Font.html" title="struct cosmic::iced::daemon::program::graphics::text::cosmic_text::Font">Font</a></dt><dd>A font</dd><dt><a class="struct" href="struct.FontFeatures.html" title="struct cosmic::iced::daemon::program::graphics::text::cosmic_text::FontFeatures">Font<wbr>Features</a></dt><dt><a class="struct" href="struct.FontMatchAttrs.html" title="struct cosmic::iced::daemon::program::graphics::text::cosmic_text::FontMatchAttrs">Font<wbr>Match<wbr>Attrs</a></dt><dd>Fo
|