diff options
| author | Martin <mhaug@live.de> | 2021-03-19 22:36:13 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-03-19 22:36:13 +0100 |
| commit | 6cb9fe9064a037224b6560b69b441b72e787fa94 (patch) | |
| tree | 9a5474758e37199c7a01c6d22383ede225deab4d /src/export/pdf.rs | |
| parent | 898dc38ec153709929d2513fb9d040dd2c1ce0fe (diff) | |
Text colors 🦩 (#18)
Diffstat (limited to 'src/export/pdf.rs')
| -rw-r--r-- | src/export/pdf.rs | 33 |
1 files changed, 21 insertions, 12 deletions
diff --git a/src/export/pdf.rs b/src/export/pdf.rs index 43c58403..d8391e2d 100644 --- a/src/export/pdf.rs +++ b/src/export/pdf.rs @@ -133,6 +133,22 @@ impl<'a> PdfExporter<'a> { // do that, we need to remember the active face. let mut face = FaceId::MAX; let mut size = Length::ZERO; + let mut fill: Option<Fill> = None; + let mut change_color = |content: &mut Content, new_fill: Fill| { + if fill != Some(new_fill) { + match new_fill { + Fill::Color(Color::Rgba(c)) => { + content.fill_rgb( + c.r as f32 / 255.0, + c.g as f32 / 255.0, + c.b as f32 / 255.0, + ); + } + Fill::Image(_) => todo!(), + } + fill = Some(new_fill); + } + }; for (pos, element) in &page.elements { let x = pos.x.to_pt() as f32; @@ -152,17 +168,7 @@ impl<'a> PdfExporter<'a> { Element::Geometry(geometry) => { content.save_state(); - - match geometry.fill { - Fill::Color(Color::Rgba(c)) => { - content.fill_rgb( - c.r as f32 / 255.0, - c.g as f32 / 255.0, - c.b as f32 / 255.0, - ); - } - Fill::Image(_) => todo!(), - } + change_color(&mut content, geometry.fill); match &geometry.shape { Shape::Rect(r) => { @@ -179,9 +185,12 @@ impl<'a> PdfExporter<'a> { } Element::Text(shaped) => { + change_color(&mut content, shaped.color); + let mut text = content.text(); - // Check if we need to issue a font switching action. + // Then, also check if we need to + // issue a font switching action. if shaped.face != face || shaped.font_size != size { face = shaped.face; size = shaped.font_size; |
