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>> { ) -> SourceResult<Vec<u8>> {
let validator = configuration.validator(); 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() { match document.finish() {
Ok(r) => Ok(r), Ok(r) => Ok(r),
Err(e) => match e { Err(e) => match e {
@ -343,11 +348,6 @@ fn finish(
KrillaError::Validation(ve) => { KrillaError::Validation(ve) => {
let prefix = format!("{} error:", validator.as_str()); 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| { let errors = ve.iter().map(|e| {
match e { match e {
ValidationError::TooLongString => { ValidationError::TooLongString => {
@ -548,9 +548,9 @@ fn finish(
Err(errors) Err(errors)
} }
KrillaError::Image(i) => { KrillaError::Image(_, loc) => {
let span = gc.image_to_spans.get(&i).unwrap(); let span = get_span(loc);
bail!(*span, "failed to process image"); bail!(span, "failed to process image");
} }
KrillaError::SixteenBitImage(image, _) => { KrillaError::SixteenBitImage(image, _) => {
let span = gc.image_to_spans.get(&image).unwrap(); 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()); surface.push_transform(&fc.state().transform().to_krilla());
if let Some(path) = convert_geometry(&shape.geometry) { if let Some(path) = convert_geometry(&shape.geometry) {
if let Some(paint) = &shape.fill { let fill = if let Some(paint) = &shape.fill {
let fill = paint::convert_fill( Some(paint::convert_fill(
gc, gc,
paint, paint,
shape.fill_rule, shape.fill_rule,
@ -28,11 +28,10 @@ pub(crate) fn handle_shape(
surface, surface,
fc.state(), fc.state(),
shape.geometry.bbox_size(), shape.geometry.bbox_size(),
)?; )?)
} else {
surface.set_fill(fill); None
surface.fill_path(&path); };
}
let stroke = shape.stroke.as_ref().and_then(|stroke| { let stroke = shape.stroke.as_ref().and_then(|stroke| {
if stroke.thickness.to_f32() > 0.0 { 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( let stroke = paint::convert_stroke(
gc, gc,
stroke, stroke,
@ -52,9 +51,14 @@ pub(crate) fn handle_shape(
shape.geometry.bbox_size(), shape.geometry.bbox_size(),
)?; )?;
surface.set_stroke(stroke); Some(stroke)
surface.stroke_path(&path); } else {
} None
};
surface.set_fill(fill);
surface.set_stroke(stroke);
surface.draw_path(&path);
} }
surface.pop(); surface.pop();

View File

@ -32,13 +32,22 @@ pub(crate) fn handle_text(
fc.state(), fc.state(),
Size::zero(), 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 text = t.text.as_str();
let size = t.size; let size = t.size;
let glyphs: &[PdfGlyph] = TransparentWrapper::wrap_slice(t.glyphs.as_slice()); let glyphs: &[PdfGlyph] = TransparentWrapper::wrap_slice(t.glyphs.as_slice());
surface.push_transform(&fc.state().transform().to_krilla()); surface.push_transform(&fc.state().transform().to_krilla());
surface.set_fill(fill); surface.set_fill(Some(fill));
surface.fill_glyphs( surface.set_stroke(stroke);
surface.draw_glyphs(
krilla::geom::Point::from_xy(0.0, 0.0), krilla::geom::Point::from_xy(0.0, 0.0),
glyphs, glyphs,
font.clone(), font.clone(),
@ -47,25 +56,6 @@ pub(crate) fn handle_text(
false, 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(); surface.pop();
Ok(()) Ok(())