Skip to content

Commit 3d0b337

Browse files
authored
Merge pull request #133 from kas-gui/push-zpypnvkvysop
Remove num_glyphs, deprecate `Effect` type tokens and highlighting functions
2 parents dc34ef6 + 1de07c7 commit 3d0b337

File tree

8 files changed

+32
-48
lines changed

8 files changed

+32
-48
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,4 @@ jobs:
6363
- name: Test (reduced features)
6464
run: cargo test --all-targets --features markdown
6565
- name: Test (all features except GAT)
66-
run: cargo test --features markdown,shaping,serde,num_glyphs
66+
run: cargo test --features markdown,shaping,serde

Cargo.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@ all-features = true
2020
rustdoc-args = ["--cfg", "docsrs"]
2121

2222
[features]
23-
# Support num_glyphs method
24-
num_glyphs = []
25-
2623
# Enable shaping with the default dependency.
2724
shaping = ["rustybuzz"]
2825
# Enable shaping via rustybuzz.

src/display/glyph_pos.rs

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -365,17 +365,6 @@ impl TextDisplay {
365365
MarkerPosIter { v, a, b }
366366
}
367367

368-
/// Get the number of glyphs
369-
///
370-
/// [Requires status][Self#status-of-preparation]: lines have been wrapped.
371-
///
372-
/// This method is a simple memory-read.
373-
#[inline]
374-
#[cfg(feature = "num_glyphs")]
375-
pub fn num_glyphs(&self) -> usize {
376-
to_usize(self.num_glyphs)
377-
}
378-
379368
/// Iterate over runs of positioned glyphs
380369
///
381370
/// All glyphs are translated by the given `offset` (this is practically
@@ -390,8 +379,7 @@ impl TextDisplay {
390379
/// where `i` is the largest value such that `effects[i].0 <= j`, or the
391380
/// default value of `E` if no such `i` exists.
392381
///
393-
/// Runs are yielded in undefined order. The total number of
394-
/// glyphs yielded will equal [`TextDisplay::num_glyphs`].
382+
/// Runs are yielded in undefined order.
395383
///
396384
/// [Requires status][Self#status-of-preparation]:
397385
/// text is fully prepared for display.
@@ -441,6 +429,10 @@ impl TextDisplay {
441429
/// text is fully prepared for display.
442430
///
443431
/// Calls `f(top_left, bottom_right)` for each highlighting rectangle.
432+
#[deprecated(
433+
since = "0.10.0",
434+
note = "Since the same result may be achieved using text background colors this will likely be removed in the future."
435+
)]
444436
pub fn highlight_range(&self, range: std::ops::Range<usize>, f: &mut dyn FnMut(Vec2, Vec2)) {
445437
for line in &self.lines {
446438
let line_range = line.text_range();
@@ -453,6 +445,7 @@ impl TextDisplay {
453445
let br = Vec2(self.r_bound, line.bottom);
454446
f(tl, br);
455447
} else {
448+
#[allow(deprecated)]
456449
self.highlight_line(line.clone(), range.clone(), f);
457450
}
458451
}
@@ -465,6 +458,10 @@ impl TextDisplay {
465458
///
466459
/// Warning: runs are in logical order which does not correspond to display
467460
/// order. As a result, the order of results (on a line) is not known.
461+
#[deprecated(
462+
since = "0.10.0",
463+
note = "Since the same result may be achieved using text background colors this will likely be removed in the future."
464+
)]
468465
fn highlight_line(
469466
&self,
470467
line: Line,

src/display/mod.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,6 @@ pub struct TextDisplay {
114114
wrapped_runs: TinyVec<[RunPart; 1]>,
115115
/// Visual (wrapped) lines, in visual and logical order
116116
lines: TinyVec<[Line; 1]>,
117-
#[cfg(feature = "num_glyphs")]
118-
num_glyphs: u32,
119117
l_bound: f32,
120118
r_bound: f32,
121119
}
@@ -128,10 +126,7 @@ fn size_of_elts() {
128126
assert_eq!(size_of::<shaper::GlyphRun>(), 112);
129127
assert_eq!(size_of::<RunPart>(), 24);
130128
assert_eq!(size_of::<Line>(), 24);
131-
#[cfg(not(feature = "num_glyphs"))]
132129
assert_eq!(size_of::<TextDisplay>(), 200);
133-
#[cfg(feature = "num_glyphs")]
134-
assert_eq!(size_of::<TextDisplay>(), 208);
135130
}
136131

137132
impl Default for TextDisplay {
@@ -140,8 +135,6 @@ impl Default for TextDisplay {
140135
runs: Default::default(),
141136
wrapped_runs: Default::default(),
142137
lines: Default::default(),
143-
#[cfg(feature = "num_glyphs")]
144-
num_glyphs: 0,
145138
l_bound: 0.0,
146139
r_bound: 0.0,
147140
}

src/display/wrap_lines.rs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -217,10 +217,6 @@ impl TextDisplay {
217217

218218
self.wrapped_runs = adder.wrapped_runs;
219219
self.lines = adder.lines;
220-
#[cfg(feature = "num_glyphs")]
221-
{
222-
self.num_glyphs = adder.num_glyphs;
223-
}
224220
self.l_bound = adder.l_bound.min(adder.r_bound);
225221
self.r_bound = adder.r_bound;
226222
adder.vcaret
@@ -403,8 +399,6 @@ struct LineAdder {
403399
l_bound: f32,
404400
r_bound: f32,
405401
vcaret: f32,
406-
#[cfg(feature = "num_glyphs")]
407-
num_glyphs: u32,
408402
h_align: Align,
409403
width_bound: f32,
410404
}
@@ -684,11 +678,6 @@ impl PartAccumulator for LineAdder {
684678
for (i, part) in parts.iter().enumerate() {
685679
let run = &runs[to_usize(part.run)];
686680

687-
#[cfg(feature = "num_glyphs")]
688-
{
689-
self.num_glyphs += to_u32(part.glyph_range.len());
690-
}
691-
692681
let mut text_end = run.range.end;
693682
let mut offset = 0.0;
694683
if run.level.is_ltr() {

src/format.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
//! Parsers for formatted text
77
8+
#![allow(deprecated)]
9+
810
use crate::fonts::FontSelector;
911
#[allow(unused)]
1012
use crate::{Text, TextDisplay};
@@ -20,6 +22,10 @@ pub use markdown::{Error as MarkdownError, Markdown};
2022
/// A possible effect formatting marker
2123
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
2224
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
25+
#[deprecated(
26+
since = "0.10.0",
27+
note = "Since the effects type is generic, a more appropriate type may be defined downstream."
28+
)]
2329
pub struct Effect {
2430
/// User-specified value
2531
///
@@ -34,6 +40,10 @@ bitflags::bitflags! {
3440
/// Text effects
3541
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
3642
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
43+
#[deprecated(
44+
since = "0.10.0",
45+
note = "Since the effects type is generic, a more appropriate type may be defined downstream."
46+
)]
3747
pub struct EffectFlags: u16 {
3848
/// Glyph is underlined
3949
const UNDERLINE = 1 << 0;

src/format/markdown.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ pub enum Error {
4545
/// - Tables
4646
/// - Task lists
4747
#[derive(Clone, Debug, Default, PartialEq)]
48+
#[deprecated(
49+
since = "0.10.0",
50+
note = "Since the effects type is generic and this requires a fixed Effect token it is likely to be removed."
51+
)]
4852
pub struct Markdown {
4953
text: String,
5054
fmt: Vec<Fmt>,

src/text.rs

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -540,24 +540,14 @@ impl<T: FormattableText + ?Sized> Text<T> {
540540
Ok(self.display()?.text_glyph_pos(index))
541541
}
542542

543-
/// Get the number of glyphs
544-
///
545-
/// See [`TextDisplay::num_glyphs`].
546-
#[inline]
547-
#[cfg(feature = "num_glyphs")]
548-
pub fn num_glyphs(&self) -> Result<usize, NotReady> {
549-
Ok(self.wrapped_display()?.num_glyphs())
550-
}
551-
552543
/// Iterate over runs of positioned glyphs
553544
///
554545
/// All glyphs are translated by the given `offset` (this is practically
555546
/// free).
556547
///
557548
/// Uses effect tokens supplied by [`FormattableText::effect_tokens`].
558549
///
559-
/// Runs are yielded in undefined order. The total number of
560-
/// glyphs yielded will equal [`TextDisplay::num_glyphs`].
550+
/// Runs are yielded in undefined order.
561551
pub fn runs<'a>(
562552
&'a self,
563553
offset: Vec2,
@@ -578,8 +568,7 @@ impl<T: FormattableText + ?Sized> Text<T> {
578568
/// where `i` is the largest value such that `effects[i].0 <= j`, or the
579569
/// default value of `E` if no such `i` exists.
580570
///
581-
/// Runs are yielded in undefined order. The total number of
582-
/// glyphs yielded will equal [`TextDisplay::num_glyphs`].
571+
/// Runs are yielded in undefined order.
583572
pub fn runs_with_effects<'a, E: Copy + Debug + Default>(
584573
&'a self,
585574
offset: Vec2,
@@ -591,6 +580,10 @@ impl<T: FormattableText + ?Sized> Text<T> {
591580
/// Yield a sequence of rectangles to highlight a given text range
592581
///
593582
/// Calls `f(top_left, bottom_right)` for each highlighting rectangle.
583+
#[deprecated(
584+
since = "0.10.0",
585+
note = "Since the same result may be achieved using text background colors this will likely be removed in the future."
586+
)]
594587
pub fn highlight_range<F>(
595588
&self,
596589
range: std::ops::Range<usize>,
@@ -599,6 +592,7 @@ impl<T: FormattableText + ?Sized> Text<T> {
599592
where
600593
F: FnMut(Vec2, Vec2),
601594
{
595+
#[allow(deprecated)]
602596
Ok(self.display()?.highlight_range(range, &mut f))
603597
}
604598
}

0 commit comments

Comments
 (0)