mirror of
https://github.com/penpot/penpot.git
synced 2025-12-11 22:14:05 +01:00
🐛 Fix default font size in text spans
This commit is contained in:
@@ -221,21 +221,16 @@ fn draw_text(
|
||||
|
||||
for paragraph_builder_group in paragraph_builder_groups {
|
||||
let mut group_offset_y = global_offset_y;
|
||||
let total_paragraphs = paragraph_builder_group.len();
|
||||
let group_len = paragraph_builder_group.len();
|
||||
|
||||
for (paragraph_index, paragraph_builder) in paragraph_builder_group.iter_mut().enumerate() {
|
||||
let mut paragraph = paragraph_builder.build();
|
||||
paragraph.layout(text_width);
|
||||
let _paragraph_height = paragraph.height();
|
||||
// FIXME: I've kept the _paragraph_height variable to have
|
||||
// a reminder in the future to keep digging why the ideographic_baseline
|
||||
// works so well and not the paragraph_height. I think we should test
|
||||
// this more.
|
||||
let xy = (shape.selrect().x(), shape.selrect().y() + group_offset_y);
|
||||
paragraph.paint(canvas, xy);
|
||||
|
||||
if paragraph_index == total_paragraphs - 1 {
|
||||
group_offset_y += paragraph.ideographic_baseline();
|
||||
if paragraph_index == group_len - 1 {
|
||||
group_offset_y += paragraph.height();
|
||||
}
|
||||
|
||||
for line_metrics in paragraph.get_line_metrics().iter() {
|
||||
|
||||
@@ -630,6 +630,7 @@ pub struct TextSpan {
|
||||
text: String,
|
||||
font_family: FontFamily,
|
||||
font_size: f32,
|
||||
line_height: f32,
|
||||
letter_spacing: f32,
|
||||
font_weight: i32,
|
||||
font_variant_id: Uuid,
|
||||
@@ -645,6 +646,7 @@ impl TextSpan {
|
||||
text: String,
|
||||
font_family: FontFamily,
|
||||
font_size: f32,
|
||||
line_height: f32,
|
||||
letter_spacing: f32,
|
||||
text_decoration: Option<TextDecoration>,
|
||||
text_transform: Option<TextTransform>,
|
||||
@@ -657,6 +659,7 @@ impl TextSpan {
|
||||
text,
|
||||
font_family,
|
||||
font_size,
|
||||
line_height,
|
||||
letter_spacing,
|
||||
text_decoration,
|
||||
text_transform,
|
||||
@@ -680,10 +683,9 @@ impl TextSpan {
|
||||
content_bounds: &Rect,
|
||||
fallback_fonts: &HashSet<String>,
|
||||
remove_alpha: bool,
|
||||
paragraph_line_height: f32, // Add this parameter
|
||||
paragraph_line_height: f32,
|
||||
) -> skia::textlayout::TextStyle {
|
||||
let mut style = skia::textlayout::TextStyle::default();
|
||||
|
||||
let mut paint = paint::Paint::default();
|
||||
|
||||
if remove_alpha {
|
||||
@@ -693,9 +695,14 @@ impl TextSpan {
|
||||
paint = merge_fills(&self.fills, *content_bounds);
|
||||
}
|
||||
|
||||
style.set_height(paragraph_line_height);
|
||||
style.set_height_override(true);
|
||||
// FIXME
|
||||
if self.line_height <= 0.0 {
|
||||
style.set_height(paragraph_line_height);
|
||||
} else {
|
||||
style.set_height(self.line_height);
|
||||
}
|
||||
|
||||
style.set_height_override(true);
|
||||
style.set_foreground_paint(&paint);
|
||||
style.set_decoration_type(match self.text_decoration {
|
||||
Some(text_decoration) => text_decoration,
|
||||
|
||||
@@ -75,6 +75,7 @@ pub extern "C" fn set_shape_fills() {
|
||||
// Skip the first 4 bytes (header with fill count) and parse only the actual fills
|
||||
let fills = parse_fills_from_bytes(&bytes[4..], num_fills);
|
||||
shape.set_fills(fills);
|
||||
mem::free_bytes();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -130,6 +130,7 @@ pub struct RawTextSpan {
|
||||
text_transform: RawTextTransform,
|
||||
text_direction: RawTextDirection,
|
||||
font_size: f32,
|
||||
line_height: f32,
|
||||
letter_spacing: f32,
|
||||
font_weight: i32,
|
||||
font_id: [u32; 4],
|
||||
@@ -178,6 +179,7 @@ impl From<RawTextSpan> for shapes::TextSpan {
|
||||
text,
|
||||
font_family,
|
||||
value.font_size,
|
||||
value.line_height,
|
||||
value.letter_spacing,
|
||||
value.text_decoration.into(),
|
||||
value.text_transform.into(),
|
||||
@@ -193,7 +195,7 @@ impl From<RawTextSpan> for shapes::TextSpan {
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct RawParagraph {
|
||||
attrs: RawParagraphData,
|
||||
leaves: Vec<RawTextSpan>,
|
||||
spans: Vec<RawTextSpan>,
|
||||
text_buffer: Vec<u8>,
|
||||
}
|
||||
|
||||
@@ -204,19 +206,19 @@ impl TryFrom<&Vec<u8>> for RawParagraph {
|
||||
fn try_from(bytes: &Vec<u8>) -> Result<Self, Self::Error> {
|
||||
let attrs = RawParagraphData::try_from(&bytes[..RAW_PARAGRAPH_DATA_SIZE])?;
|
||||
let mut offset = RAW_PARAGRAPH_DATA_SIZE;
|
||||
let mut raw_text_leaves: Vec<RawTextSpan> = Vec::new();
|
||||
let mut raw_text_spans: Vec<RawTextSpan> = Vec::new();
|
||||
|
||||
for _ in 0..attrs.span_count {
|
||||
let text_span = RawTextSpan::try_from(&bytes[offset..(offset + RAW_SPAN_DATA_SIZE)])?;
|
||||
offset += RAW_SPAN_DATA_SIZE;
|
||||
raw_text_leaves.push(text_span);
|
||||
raw_text_spans.push(text_span);
|
||||
}
|
||||
|
||||
let text_buffer = &bytes[offset..];
|
||||
|
||||
Ok(Self {
|
||||
attrs,
|
||||
leaves: raw_text_leaves,
|
||||
spans: raw_text_spans,
|
||||
text_buffer: text_buffer.to_vec(),
|
||||
})
|
||||
}
|
||||
@@ -227,10 +229,10 @@ impl From<RawParagraph> for shapes::Paragraph {
|
||||
let typography_ref_file = uuid_from_u32(value.attrs.typography_ref_file);
|
||||
let typography_ref_id = uuid_from_u32(value.attrs.typography_ref_id);
|
||||
|
||||
let mut leaves = vec![];
|
||||
let mut spans = vec![];
|
||||
|
||||
let mut offset = 0;
|
||||
for raw_span in value.leaves.into_iter() {
|
||||
for raw_span in value.spans.into_iter() {
|
||||
let delta = raw_span.text_length as usize;
|
||||
let text_buffer = &value.text_buffer[offset..offset + delta];
|
||||
|
||||
@@ -239,7 +241,7 @@ impl From<RawParagraph> for shapes::Paragraph {
|
||||
span.set_text(String::from_utf8_lossy(text_buffer).to_string());
|
||||
}
|
||||
|
||||
leaves.push(span);
|
||||
spans.push(span);
|
||||
offset += delta;
|
||||
}
|
||||
|
||||
@@ -252,7 +254,7 @@ impl From<RawParagraph> for shapes::Paragraph {
|
||||
value.attrs.letter_spacing,
|
||||
typography_ref_file,
|
||||
typography_ref_id,
|
||||
leaves,
|
||||
spans,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user