Skip to content

Commit 546b1d7

Browse files
committed
m92: Update modules/paragraph/
1 parent 39dfd68 commit 546b1d7

File tree

5 files changed

+73
-27
lines changed

5 files changed

+73
-27
lines changed

skia-bindings/src/paragraph.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,10 @@ extern "C" {
236236
void C_Paragraph_markDirty(Paragraph* self) {
237237
self->markDirty();
238238
}
239+
240+
int32_t C_Paragraph_unresolvedGlyphs(Paragraph* self) {
241+
return self->unresolvedGlyphs();
242+
}
239243
}
240244

241245
//

skia-safe/src/modules/paragraph/paragraph.rs

Lines changed: 36 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,14 @@ impl Paragraph {
163163
pub fn mark_dirty(&mut self) {
164164
unsafe { sb::C_Paragraph_markDirty(self.native_mut()) }
165165
}
166+
167+
pub fn unresolved_glyphs(&mut self) -> Option<usize> {
168+
unsafe { sb::C_Paragraph_unresolvedGlyphs(self.native_mut()) }
169+
.try_into()
170+
.ok()
171+
}
172+
173+
// TODO: wrap visit()
166174
}
167175

168176
#[deprecated(since = "0.0.0", note = "Use Vec<TextBox>")]
@@ -171,30 +179,34 @@ pub type TextBoxes = Vec<TextBox>;
171179
#[deprecated(since = "0.0.0", note = "Use Vec<LineMetrics>")]
172180
pub type LineMetricsVector<'a> = Vec<LineMetrics<'a>>;
173181

174-
#[test]
175-
#[serial_test::serial]
176-
fn test_line_metrics() {
177-
// note: some of the following code is copied from the skparagraph skia-org example.
178-
use crate::icu;
179-
use crate::textlayout::{FontCollection, ParagraphBuilder, ParagraphStyle, TextStyle};
180-
use crate::FontMgr;
181-
182-
icu::init();
183-
184-
let mut font_collection = FontCollection::new();
185-
font_collection.set_default_font_manager(FontMgr::new(), None);
186-
let paragraph_style = ParagraphStyle::new();
187-
let mut paragraph_builder = ParagraphBuilder::new(&paragraph_style, font_collection);
188-
let ts = TextStyle::new();
189-
paragraph_builder.push_style(&ts);
190-
paragraph_builder.add_text(LOREM_IPSUM);
191-
let mut paragraph = paragraph_builder.build();
192-
paragraph.layout(256.0);
182+
#[cfg(test)]
183+
mod tests {
184+
use crate::{
185+
icu,
186+
textlayout::{FontCollection, ParagraphBuilder, ParagraphStyle, TextStyle},
187+
FontMgr,
188+
};
189+
190+
#[test]
191+
#[serial_test::serial]
192+
fn test_line_metrics() {
193+
icu::init();
194+
195+
let mut font_collection = FontCollection::new();
196+
font_collection.set_default_font_manager(FontMgr::new(), None);
197+
let paragraph_style = ParagraphStyle::new();
198+
let mut paragraph_builder = ParagraphBuilder::new(&paragraph_style, font_collection);
199+
let ts = TextStyle::new();
200+
paragraph_builder.push_style(&ts);
201+
paragraph_builder.add_text(LOREM_IPSUM);
202+
let mut paragraph = paragraph_builder.build();
203+
paragraph.layout(256.0);
204+
205+
let line_metrics = paragraph.get_line_metrics();
206+
for (line, lm) in line_metrics.iter().enumerate() {
207+
println!("line {}: width: {}", line + 1, lm.width)
208+
}
193209

194-
let line_metrics = paragraph.get_line_metrics();
195-
for (line, lm) in line_metrics.iter().enumerate() {
196-
println!("line {}: width: {}", line + 1, lm.width)
210+
static LOREM_IPSUM: &str = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur at leo at nulla tincidunt placerat. Proin eget purus augue. Quisque et est ullamcorper, pellentesque felis nec, pulvinar massa. Aliquam imperdiet, nulla ut dictum euismod, purus dui pulvinar risus, eu suscipit elit neque ac est. Nullam eleifend justo quis placerat ultricies. Vestibulum ut elementum velit. Praesent et dolor sit amet purus bibendum mattis. Aliquam erat volutpat.";
197211
}
198-
199-
static LOREM_IPSUM: &str = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur at leo at nulla tincidunt placerat. Proin eget purus augue. Quisque et est ullamcorper, pellentesque felis nec, pulvinar massa. Aliquam imperdiet, nulla ut dictum euismod, purus dui pulvinar risus, eu suscipit elit neque ac est. Nullam eleifend justo quis placerat ultricies. Vestibulum ut elementum velit. Praesent et dolor sit amet purus bibendum mattis. Aliquam erat volutpat.";
200212
}

skia-safe/src/modules/paragraph/paragraph_style.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ impl fmt::Debug for StrutStyle {
4747
.field("leading", &self.leading())
4848
.field("strut_enabled", &self.strut_enabled())
4949
.field("force_strut_height", &self.force_strut_height())
50+
.field("height_override", &self.height_override())
51+
.field("half_leading", &self.half_leading())
5052
.finish()
5153
}
5254
}
@@ -126,6 +128,24 @@ impl StrutStyle {
126128
self.native_mut().fForceHeight = force_height;
127129
self
128130
}
131+
132+
pub fn height_override(&self) -> bool {
133+
self.native().fHeightOverride
134+
}
135+
136+
pub fn set_height_override(&mut self, height_override: bool) -> &mut Self {
137+
self.native_mut().fHeightOverride = height_override;
138+
self
139+
}
140+
141+
pub fn half_leading(&self) -> bool {
142+
self.native().fHalfLeading
143+
}
144+
145+
pub fn set_half_leading(&mut self, half_leading: bool) -> &mut Self {
146+
self.native_mut().fHalfLeading = half_leading;
147+
self
148+
}
129149
}
130150

131151
// Can't use Handle<> here, std::u16string maintains an interior pointer.

skia-safe/src/modules/paragraph/text_shadow.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use skia_bindings as sb;
66
pub struct TextShadow {
77
pub color: Color,
88
pub offset: Point,
9-
pub blur_radius: f64,
9+
pub blur_sigma: f64,
1010
}
1111

1212
impl NativeTransmutable<sb::skia_textlayout_TextShadow> for TextShadow {}
@@ -29,12 +29,12 @@ impl PartialEq for TextShadow {
2929
}
3030

3131
impl TextShadow {
32-
pub fn new(color: impl Into<Color>, offset: impl Into<Point>, blur_radius: f64) -> Self {
32+
pub fn new(color: impl Into<Color>, offset: impl Into<Point>, blur_sigma: f64) -> Self {
3333
TextShadow::from_native_c(unsafe {
3434
sb::skia_textlayout_TextShadow::new1(
3535
color.into().into_native(),
3636
offset.into().into_native(),
37-
blur_radius,
37+
blur_sigma,
3838
)
3939
})
4040
}

skia-safe/src/modules/paragraph/text_style.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ impl fmt::Debug for TextStyle {
197197
.field("font_families", &self.font_families())
198198
.field("height", &self.height())
199199
.field("height_override", &self.height_override())
200+
.field("half_leading", &self.half_leading())
200201
.field("letter_spacing", &self.letter_spacing())
201202
.field("word_spacing", &self.word_spacing())
202203
.field("typeface", &self.typeface())
@@ -368,6 +369,15 @@ impl TextStyle {
368369
self.native().fHeightOverride
369370
}
370371

372+
pub fn set_half_leading(&mut self, half_leading: bool) -> &mut Self {
373+
self.native_mut().fHalfLeading = half_leading;
374+
self
375+
}
376+
377+
pub fn half_leading(&self) -> bool {
378+
self.native().fHalfLeading
379+
}
380+
371381
pub fn set_letter_spacing(&mut self, letter_spacing: scalar) -> &mut Self {
372382
self.native_mut().fLetterSpacing = letter_spacing;
373383
self

0 commit comments

Comments
 (0)