Skip to content

Commit

Permalink
deploy: db1530c
Browse files Browse the repository at this point in the history
  • Loading branch information
jackpot51 committed Jan 19, 2024
1 parent 267bdc8 commit 87eb3e9
Show file tree
Hide file tree
Showing 9 changed files with 79 additions and 63 deletions.
4 changes: 2 additions & 2 deletions cosmic_text/struct.Font.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions cosmic_text/struct.ShapeGlyph.html

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions cosmic_text/struct.ShapeLine.html

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions cosmic_text/struct.ShapeSpan.html

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions cosmic_text/struct.ShapeWord.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion search-index.js

Large diffs are not rendered by default.

42 changes: 14 additions & 28 deletions src/cosmic_text/font/fallback/mod.rs.html
Original file line number Diff line number Diff line change
Expand Up @@ -265,13 +265,6 @@
<a href="#265" id="265">265</a>
<a href="#266" id="266">266</a>
<a href="#267" id="267">267</a>
<a href="#268" id="268">268</a>
<a href="#269" id="269">269</a>
<a href="#270" id="270">270</a>
<a href="#271" id="271">271</a>
<a href="#272" id="272">272</a>
<a href="#273" id="273">273</a>
<a href="#274" id="274">274</a>
</pre></div><pre class="rust"><code><span class="comment">// SPDX-License-Identifier: MIT OR Apache-2.0

</span><span class="kw">use </span>alloc::collections::BTreeSet;
Expand Down Expand Up @@ -312,7 +305,7 @@
</span><span class="attr">#[derive(Debug, PartialEq, Eq, PartialOrd, Ord)]
</span><span class="kw">struct </span>MonospaceFallbackInfo {
weight_offset: <span class="prelude-ty">Option</span>&lt;u16&gt;,
script_non_matches: <span class="prelude-ty">Option</span>&lt;usize&gt;,
codepoint_non_matches: <span class="prelude-ty">Option</span>&lt;usize&gt;,
id: fontdb::ID,
}

Expand All @@ -323,6 +316,7 @@
monospace_fallbacks: BTreeSet&lt;MonospaceFallbackInfo&gt;,
default_i: usize,
scripts: <span class="kw-2">&amp;</span><span class="lifetime">&#39;a </span>[Script],
word: <span class="kw-2">&amp;</span><span class="lifetime">&#39;a </span>str,
script_i: (usize, usize),
common_i: usize,
other_i: usize,
Expand All @@ -335,6 +329,7 @@
font_match_keys: <span class="kw-2">&amp;</span><span class="lifetime">&#39;a </span>[FontMatchKey],
default_families: <span class="kw-2">&amp;</span><span class="lifetime">&#39;a </span>[<span class="kw-2">&amp;</span><span class="lifetime">&#39;a </span>Family&lt;<span class="lifetime">&#39;a</span>&gt;],
scripts: <span class="kw-2">&amp;</span><span class="lifetime">&#39;a </span>[Script],
word: <span class="kw-2">&amp;</span><span class="lifetime">&#39;a </span>str,
) -&gt; <span class="self">Self </span>{
<span class="self">Self </span>{
font_system,
Expand All @@ -343,6 +338,7 @@
monospace_fallbacks: BTreeSet::new(),
default_i: <span class="number">0</span>,
scripts,
word,
script_i: (<span class="number">0</span>, <span class="number">0</span>),
common_i: <span class="number">0</span>,
other_i: <span class="number">0</span>,
Expand Down Expand Up @@ -435,44 +431,34 @@
<span class="comment">// Default font
</span><span class="kw">let </span>fallback_info = MonospaceFallbackInfo {
weight_offset: <span class="prelude-val">None</span>,
script_non_matches: <span class="prelude-val">None</span>,
codepoint_non_matches: <span class="prelude-val">None</span>,
id: m_key.id,
};
<span class="macro">assert_eq!</span>(<span class="self">self</span>.monospace_fallbacks.insert(fallback_info), <span class="bool-val">true</span>);
<span class="macro">assert!</span>(<span class="self">self</span>.monospace_fallbacks.insert(fallback_info));
}
}
}
<span class="comment">// Set a monospace fallback if Monospace family is not found
</span><span class="kw">if </span>is_mono {
<span class="kw">let </span>script_tags = <span class="self">self
</span>.scripts
.iter()
.filter_map(|script| {
<span class="kw">let </span>script_as_lower = script.short_name().to_lowercase();
&lt;[u8; <span class="number">4</span>]&gt;::try_from(script_as_lower.as_bytes()).ok()
})
.collect::&lt;Vec&lt;<span class="kw">_</span>&gt;&gt;();

<span class="kw">if let </span><span class="prelude-val">Some</span>(face_info) = <span class="self">self</span>.font_system.db().face(m_key.id) {
<span class="comment">// Don&#39;t use emoji fonts as Monospace
</span><span class="kw">if </span>face_info.monospaced &amp;&amp; !face_info.post_script_name.contains(<span class="string">&quot;Emoji&quot;</span>) {
<span class="kw">if let </span><span class="prelude-val">Some</span>(font) = <span class="self">self</span>.font_system.get_font(m_key.id) {
<span class="kw">let </span>script_non_matches = <span class="self">self</span>.scripts.len()
- script_tags
.iter()
.filter(|&amp;&amp;script_tag| {
font.scripts()
.iter()
.any(|<span class="kw-2">&amp;</span>tag_bytes| tag_bytes == script_tag)
<span class="kw">let </span>codepoint_non_matches = <span class="self">self</span>.word.chars().count()
- <span class="self">self
</span>.word
.chars()
.filter(|ch| {
font.unicode_codepoints().contains(<span class="kw-2">&amp;</span>u32::from(<span class="kw-2">*</span>ch))
})
.count();

<span class="kw">let </span>fallback_info = MonospaceFallbackInfo {
weight_offset: m_key.weight_offset,
script_non_matches: <span class="prelude-val">Some</span>(script_non_matches),
codepoint_non_matches: <span class="prelude-val">Some</span>(codepoint_non_matches),
id: m_key.id,
};
<span class="macro">assert_eq!</span>(<span class="self">self</span>.monospace_fallbacks.insert(fallback_info), <span class="bool-val">true</span>);
<span class="macro">assert!</span>(<span class="self">self</span>.monospace_fallbacks.insert(fallback_info));
}
}
}
Expand Down
46 changes: 32 additions & 14 deletions src/cosmic_text/font/mod.rs.html
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,15 @@
<a href="#134" id="134">134</a>
<a href="#135" id="135">135</a>
<a href="#136" id="136">136</a>
<a href="#137" id="137">137</a>
<a href="#138" id="138">138</a>
<a href="#139" id="139">139</a>
<a href="#140" id="140">140</a>
<a href="#141" id="141">141</a>
<a href="#142" id="142">142</a>
<a href="#143" id="143">143</a>
<a href="#144" id="144">144</a>
<a href="#145" id="145">145</a>
</pre></div><pre class="rust"><code><span class="comment">// SPDX-License-Identifier: MIT OR Apache-2.0
</span><span class="kw">pub</span>(<span class="kw">crate</span>) <span class="kw">mod </span>fallback;

Expand Down Expand Up @@ -166,7 +175,7 @@
data: Arc&lt;<span class="kw">dyn </span>AsRef&lt;[u8]&gt; + Send + Sync&gt;,
id: fontdb::ID,
monospace_em_width: <span class="prelude-ty">Option</span>&lt;f32&gt;,
scripts: Vec&lt;[u8; <span class="number">4</span>]&gt;,
unicode_codepoints: Vec&lt;u32&gt;,
}

<span class="kw">impl </span>fmt::Debug <span class="kw">for </span>Font {
Expand All @@ -186,8 +195,8 @@
<span class="self">self</span>.monospace_em_width
}

<span class="kw">pub fn </span>scripts(<span class="kw-2">&amp;</span><span class="self">self</span>) -&gt; <span class="kw-2">&amp;</span>[[u8; <span class="number">4</span>]] {
<span class="kw-2">&amp;</span><span class="self">self</span>.scripts
<span class="kw">pub fn </span>unicode_codepoints(<span class="kw-2">&amp;</span><span class="self">self</span>) -&gt; <span class="kw-2">&amp;</span>[u32] {
<span class="kw-2">&amp;</span><span class="self">self</span>.unicode_codepoints
}

<span class="kw">pub fn </span>data(<span class="kw-2">&amp;</span><span class="self">self</span>) -&gt; <span class="kw-2">&amp;</span>[u8] {
Expand All @@ -213,7 +222,7 @@
<span class="kw">pub fn </span>new(db: <span class="kw-2">&amp;</span>fontdb::Database, id: fontdb::ID) -&gt; <span class="prelude-ty">Option</span>&lt;<span class="self">Self</span>&gt; {
<span class="kw">let </span>info = db.face(id)<span class="question-mark">?</span>;

<span class="kw">let </span>(monospace_em_width, scripts) = {
<span class="kw">let </span>(monospace_em_width, unicode_codepoints) = {
db.with_face_data(id, |font_data, face_index| {
<span class="kw">let </span>face = ttf_parser::Face::parse(font_data, face_index).ok()<span class="question-mark">?</span>;
<span class="kw">let </span>monospace_em_width = info
Expand All @@ -229,16 +238,25 @@
<span class="prelude-val">None</span><span class="question-mark">?</span>;
}

<span class="kw">let </span>scripts = face
.tables()
.gpos
<span class="kw">let </span><span class="kw-2">mut </span>unicode_codepoints = Vec::new();

face.tables()
.cmap<span class="question-mark">?
</span>.subtables
.into_iter()
.chain(face.tables().gsub)
.map(|table| table.scripts)
.flatten()
.map(|script| script.tag.to_bytes())
.collect();
<span class="prelude-val">Some</span>((monospace_em_width, scripts))
.filter(|subtable| subtable.is_unicode())
.for_each(|subtable| {
unicode_codepoints.reserve(<span class="number">1024</span>);
subtable.codepoints(|code_point| {
<span class="kw">if </span>subtable.glyph_index(code_point).is_some() {
unicode_codepoints.push(code_point);
}
});
});

unicode_codepoints.shrink_to_fit();

<span class="prelude-val">Some</span>((monospace_em_width, unicode_codepoints))
})<span class="question-mark">?
</span>}<span class="question-mark">?</span>;

Expand All @@ -256,7 +274,7 @@
<span class="prelude-val">Some</span>(<span class="self">Self </span>{
id: info.id,
monospace_em_width,
scripts,
unicode_codepoints,
<span class="attr">#[cfg(feature = <span class="string">&quot;swash&quot;</span>)]
</span>swash: {
<span class="kw">let </span>swash = swash::FontRef::from_index((<span class="kw-2">*</span>data).as_ref(), info.index <span class="kw">as </span>usize)<span class="question-mark">?</span>;
Expand Down
16 changes: 14 additions & 2 deletions src/cosmic_text/shape.rs.html
Original file line number Diff line number Diff line change
Expand Up @@ -1325,6 +1325,12 @@
<a href="#1325" id="1325">1325</a>
<a href="#1326" id="1326">1326</a>
<a href="#1327" id="1327">1327</a>
<a href="#1328" id="1328">1328</a>
<a href="#1329" id="1329">1329</a>
<a href="#1330" id="1330">1330</a>
<a href="#1331" id="1331">1331</a>
<a href="#1332" id="1332">1332</a>
<a href="#1333" id="1333">1333</a>
</pre></div><pre class="rust"><code><span class="comment">// SPDX-License-Identifier: MIT OR Apache-2.0

</span><span class="attr">#![allow(clippy::too_many_arguments)]
Expand Down Expand Up @@ -1546,7 +1552,13 @@
<span class="kw">let </span>fonts = font_system.get_font_matches(attrs);

<span class="kw">let </span>default_families = [<span class="kw-2">&amp;</span>attrs.family];
<span class="kw">let </span><span class="kw-2">mut </span>font_iter = FontFallbackIter::new(font_system, <span class="kw-2">&amp;</span>fonts, <span class="kw-2">&amp;</span>default_families, <span class="kw-2">&amp;</span>scripts);
<span class="kw">let </span><span class="kw-2">mut </span>font_iter = FontFallbackIter::new(
font_system,
<span class="kw-2">&amp;</span>fonts,
<span class="kw-2">&amp;</span>default_families,
<span class="kw-2">&amp;</span>scripts,
<span class="kw-2">&amp;</span>line[start_run..end_run],
);

<span class="kw">let </span>font = font_iter.next().expect(<span class="string">&quot;no default font found&quot;</span>);

Expand Down Expand Up @@ -1668,7 +1680,7 @@
<span class="kw">let </span>fonts = font_system.get_font_matches(attrs);

<span class="kw">let </span>default_families = [<span class="kw-2">&amp;</span>attrs.family];
<span class="kw">let </span><span class="kw-2">mut </span>font_iter = FontFallbackIter::new(font_system, <span class="kw-2">&amp;</span>fonts, <span class="kw-2">&amp;</span>default_families, <span class="kw-2">&amp;</span>[]);
<span class="kw">let </span><span class="kw-2">mut </span>font_iter = FontFallbackIter::new(font_system, <span class="kw-2">&amp;</span>fonts, <span class="kw-2">&amp;</span>default_families, <span class="kw-2">&amp;</span>[], <span class="string">&quot;&quot;</span>);

<span class="kw">let </span>font = font_iter.next().expect(<span class="string">&quot;no default font found&quot;</span>);
<span class="kw">let </span>font_id = font.id();
Expand Down

0 comments on commit 87eb3e9

Please sign in to comment.