Update to newest

This commit is contained in:
Laurenz Stampfl 2025-03-26 19:29:04 +01:00
parent 24e4decb56
commit f18b84011a
3 changed files with 34 additions and 40 deletions

View File

@ -330,6 +330,11 @@ fn finish(
) -> SourceResult<Vec<u8>> {
let validator = configuration.validator();
let get_span = |loc: Option<krilla::surface::Location>| {
loc.map(|l| Span::from_raw(NonZeroU64::new(l).unwrap()))
.unwrap_or(Span::detached())
};
match document.finish() {
Ok(r) => Ok(r),
Err(e) => match e {
@ -343,11 +348,6 @@ fn finish(
KrillaError::Validation(ve) => {
let prefix = format!("{} error:", validator.as_str());
let get_span = |loc: Option<krilla::surface::Location>| {
loc.map(|l| Span::from_raw(NonZeroU64::new(l).unwrap()))
.unwrap_or(Span::detached())
};
let errors = ve.iter().map(|e| {
match e {
ValidationError::TooLongString => {
@ -548,9 +548,9 @@ fn finish(
Err(errors)
}
KrillaError::Image(i) => {
let span = gc.image_to_spans.get(&i).unwrap();
bail!(*span, "failed to process image");
KrillaError::Image(_, loc) => {
let span = get_span(loc);
bail!(span, "failed to process image");
}
KrillaError::SixteenBitImage(image, _) => {
let span = gc.image_to_spans.get(&image).unwrap();

View File

@ -19,8 +19,8 @@ pub(crate) fn handle_shape(
surface.push_transform(&fc.state().transform().to_krilla());
if let Some(path) = convert_geometry(&shape.geometry) {
if let Some(paint) = &shape.fill {
let fill = paint::convert_fill(
let fill = if let Some(paint) = &shape.fill {
Some(paint::convert_fill(
gc,
paint,
shape.fill_rule,
@ -28,11 +28,10 @@ pub(crate) fn handle_shape(
surface,
fc.state(),
shape.geometry.bbox_size(),
)?;
surface.set_fill(fill);
surface.fill_path(&path);
}
)?)
} else {
None
};
let stroke = shape.stroke.as_ref().and_then(|stroke| {
if stroke.thickness.to_f32() > 0.0 {
@ -42,7 +41,7 @@ pub(crate) fn handle_shape(
}
});
if let Some(stroke) = &stroke {
let stroke = if let Some(stroke) = &stroke {
let stroke = paint::convert_stroke(
gc,
stroke,
@ -52,9 +51,14 @@ pub(crate) fn handle_shape(
shape.geometry.bbox_size(),
)?;
Some(stroke)
} else {
None
};
surface.set_fill(fill);
surface.set_stroke(stroke);
surface.stroke_path(&path);
}
surface.draw_path(&path);
}
surface.pop();

View File

@ -32,13 +32,22 @@ pub(crate) fn handle_text(
fc.state(),
Size::zero(),
)?;
let stroke =
if let Some(stroke) = t.stroke.as_ref().map(|s| {
paint::convert_stroke(gc, s, true, surface, fc.state(), Size::zero())
}) {
Some(stroke?)
} else {
None
};
let text = t.text.as_str();
let size = t.size;
let glyphs: &[PdfGlyph] = TransparentWrapper::wrap_slice(t.glyphs.as_slice());
surface.push_transform(&fc.state().transform().to_krilla());
surface.set_fill(fill);
surface.fill_glyphs(
surface.set_fill(Some(fill));
surface.set_stroke(stroke);
surface.draw_glyphs(
krilla::geom::Point::from_xy(0.0, 0.0),
glyphs,
font.clone(),
@ -47,25 +56,6 @@ pub(crate) fn handle_text(
false,
);
if let Some(stroke) = t
.stroke
.as_ref()
.map(|s| paint::convert_stroke(gc, s, true, surface, fc.state(), Size::zero()))
{
let stroke = stroke?;
surface.set_stroke(stroke);
surface.stroke_glyphs(
krilla::geom::Point::from_xy(0.0, 0.0),
glyphs,
font,
text,
size.to_f32(),
// To prevent text from being embedded twice, we outline it instead if a stroke exists.
true,
);
}
surface.pop();
Ok(())