Skip to content

PdfCraft: An open-source PDF reader and editor written by scratch in pure Rust

M8: Redaction Properties: overlay text font (Helvetica, Times, Courier), size or auto-size, colour, alignment and repeat, written as /DA, /Q and /Repeat and drawn on apply; overlay fonts are added to the page only when used

Brandon Thomas17e3eb255d67
diff --git a/crates/annot/src/lib.rs b/crates/annot/src/lib.rs
index 809efc315..8e86e49b9 100644
--- a/crates/annot/src/lib.rs
+++ b/crates/annot/src/lib.rs
@@ -328,10 +328,11 @@ pub enum Shape {
by: Option<String>,
},
/// A redaction mark (§12.5.6.23) over quadrilaterals (text) or one rectangle as a quad
- /// (areas, pages). `overlay` is the text shown on the box once applied.
+ /// (areas, pages). `overlay` is the text shown on the box once applied, drawn with `look`.
Redact {
quads: Vec<[f64; 8]>,
overlay: String,
+ look: OverlayLook,
},
/// A closed polygon (Polygon tool); with `cloud`, Acrobat's Cloud tool: the same polygon
/// with a cloudy border (`/BE /S /C`, `/IT /PolygonCloud`).
@@ -383,6 +384,63 @@ impl Shape {
}
}
+/// The standard fonts of redaction overlay text.
+#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
+pub enum OverlayFont {
+ #[default]
+ Helvetica,
+ Times,
+ Courier,
+}
+
+impl OverlayFont {
+ pub const ALL: [OverlayFont; 3] = [OverlayFont::Helvetica, OverlayFont::Times, OverlayFont::Courier];
+
+ pub fn name(self) -> &'static str {
+ match self {
+ OverlayFont::Helvetica => "Helvetica",
+ OverlayFont::Times => "Times Roman",
+ OverlayFont::Courier => "Courier",
+ }
+ }
+
+ /// The `/DA` font resource name (Acrobat's form font names).
+ pub fn resource(self) -> &'static str {
+ match self {
+ OverlayFont::Helvetica => "Helv",
+ OverlayFont::Times => "TiRo",
+ OverlayFont::Courier => "Cour",
+ }
+ }
+
+ pub fn from_resource(n: &str) -> OverlayFont {
+ match n {
+ "TiRo" | "Times-Roman" | "TimesRoman" => OverlayFont::Times,
+ "Cour" | "Courier" => OverlayFont::Courier,
+ _ => OverlayFont::Helvetica,
+ }
+ }
+}
+
+/// How redaction overlay text is drawn (Redaction Properties ▸ Appearance).
+#[derive(Clone, Copy, Debug, PartialEq)]
+pub struct OverlayLook {
+ pub font: OverlayFont,
+ /// Points; 0 = auto-size to fit the area.
+ pub size: f64,
+ pub color: Rgb,
+ /// 0 left, 1 centre, 2 right.
+ pub align: u8,
+ /// Repeat the text to fill the area.
+ pub repeat: bool,
+}
+
+impl Default for OverlayLook {
+ fn default() -> Self {
+ Self { font: OverlayFont::Helvetica, size: 0.0, color: [1.0, 0.0, 0.0], align: 1, repeat: false }
+ }
+}
+
/// How a comment looks.
#[derive(Clone, Debug, PartialEq)]
pub struct Style {
@@ -763,14 +821,22 @@ pub fn add_annotation(doc: &mut Document, new: &NewAnnotation, meta: &Meta) -> R
d.set(b"C".to_vec(), rgb(style.color));
d.set(b"QuadPoints".to_vec(), num_array(&quads.concat()));
}
- Shape::Redact { quads, overlay } => {
+ Shape::Redact { quads, overlay, look } => {
d.set(b"C".to_vec(), rgb(style.color));
d.set(b"IC".to_vec(), rgb(style.fill.unwrap_or([0.0, 0.0, 0.0])));
d.set(b"QuadPoints".to_vec(), num_array(&quads.concat()));
if !overlay.is_empty() {
d.set(b"OverlayText".to_vec(), PdfString::text(overlay));
- d.set(b"DA".to_vec(), PdfString::literal(b"1 0 0 rg /Helv 10 Tf".to_vec()));
- d.set(b"Q".to_vec(), Object::Int(1));
+ let [r, g, b] = look.color.map(|x| x.clamp(0.0, 1.0));
+ let size = if look.size > 0.0 { look.size.min(400.0) } else { 0.0 };
+ d.set(
+ b"DA".to_vec(),
+ PdfString::literal(format!("{} {} {} rg /{} {} Tf", n(r), n(g), n(b), look.font.resource(), n(size)).into_bytes()),
+ );
+ d.set(b"Q".to_vec(), Object::Int(look.align.min(2) as i64));
+ if look.repeat {
+ d.set(b"Repeat".to_vec(), Object::Bool(true));
+ }
}
}
Shape::Rectangle { .. } | Shape::Oval { .. } => {
diff --git a/crates/automation/src/redact.rs b/crates/automation/src/redact.rs
index 9c7f137e2..b0a9ffd6c 100644
--- a/crates/automation/src/redact.rs
+++ b/crates/automation/src/redact.rs
@@ -17,7 +17,7 @@ impl Automation {
};
let overlay = a.opt_str("overlay")?.unwrap_or("").to_string();
let author = a.opt_str("author")?.unwrap_or(DEFAULT_AUTHOR).to_string();
- let mut style = Style::default_for(&Shape::Redact { quads: Vec::new(), overlay: String::new() });
+ let mut style = Style::default_for(&Shape::Redact { quads: Vec::new(), overlay: String::new(), look: Default::default() });
if let Some(c) = a.opt_str("fill")? {
style.fill = Some(parse_color(c)?);
}
@@ -69,7 +69,7 @@ impl Automation {
let edits: Vec<Edit> = marks
.iter()
.map(|(page, quads)| {
- let shape = Shape::Redact { quads: quads.clone(), overlay: overlay.clone() };
+ let shape = Shape::Redact { quads: quads.clone(), overlay: overlay.clone(), look: Default::default() };
Edit::AddAnnotation(NewAnnotation { page: *page, shape, style: style.clone(), contents: String::new(), author: author.clone() })
})
.collect();
diff --git a/crates/edit/src/lib.rs b/crates/edit/src/lib.rs
index 9017b94ce..0646b37e9 100644
--- a/crates/edit/src/lib.rs
+++ b/crates/edit/src/lib.rs
@@ -201,15 +201,21 @@ fn contents(doc: &mut Document, page: &printcraft_model::Page) -> Result<Vec<Obj
}
/// Add the font (and an opacity state) to the page's own resources.
-fn add_resources(doc: &mut Document, page: &printcraft_model::Page, opacity: Option<f64>) -> Result<(), EditError> {
+fn add_resources(doc: &mut Document, page: &printcraft_model::Page, opacity: Option<f64>, content: Option<&[u8]>) -> Result<(), EditError> {
let mut res = page.dict.get(b"Resources").map(|r| doc.resolve(r)).and_then(|r| r.as_dict().cloned()).unwrap_or_default();
let mut fonts = res.get(b"Font").map(|f| doc.resolve(f)).and_then(|f| f.as_dict().cloned()).unwrap_or_default();
- let mut font = Dict::new();
- font.set(b"Type".to_vec(), Object::name("Font"));
- font.set(b"Subtype".to_vec(), Object::name("Type1"));
- font.set(b"BaseFont".to_vec(), Object::name("Helvetica"));
- font.set(b"Encoding".to_vec(), Object::name("WinAnsiEncoding"));
- fonts.set(b"PCHelv".to_vec(), Object::Dict(font));
+ for (name, base) in [(&b"PCHelv"[..], "Helvetica"), (b"PCTimes", "Times-Roman"), (b"PCCour", "Courier")] {
+ // Helvetica always (marks use it); the others only when the content names them.
+ if name != b"PCHelv" && !content.is_some_and(|c| c.windows(name.len() + 1).any(|w| w[0] == b'/' && &w[1..] == name)) {
+ continue;
+ }
+ let mut font = Dict::new();
+ font.set(b"Type".to_vec(), Object::name("Font"));
+ font.set(b"Subtype".to_vec(), Object::name("Type1"));
+ font.set(b"BaseFont".to_vec(), Object::name(base));
+ font.set(b"Encoding".to_vec(), Object::name("WinAnsiEncoding"));
+ fonts.set(name.to_vec(), Object::Dict(font));
+ }
res.set(b"Font".to_vec(), Object::Dict(fonts));
if let Some(o) = opacity {
let mut gs = res.get(b"ExtGState").map(|g| doc.resolve(g)).and_then(|g| g.as_dict().cloned()).unwrap_or_default();
@@ -285,7 +291,7 @@ fn place_tagged(doc: &mut Document, page: &printcraft_model::Page, tag: &str, co
pub fn stamp(doc: &mut Document, page: usize, tag: &str, content: Vec<u8>) -> Result<(), EditError> {
let all = page_list(doc);
check(&[page], all.len())?;
- add_resources(doc, &all[page], None)?;
+ add_resources(doc, &all[page], None, Some(&content))?;
let p = page_list(doc).swap_remove(page);
place_tagged(doc, &p, tag, content, false)
}
@@ -367,7 +373,7 @@ pub fn add_header_footer(doc: &mut Document, pages: &[usize], hf: &HeaderFooter,
let mut content = begin(MarkKind::HeaderFooter, "Header", page.view_matrix(doc)).into_bytes();
content.extend(body);
content.extend_from_slice(END.as_bytes());
- add_resources(doc, page, None)?;
+ add_resources(doc, page, None, None)?;
let page = &page_list(doc)[i];
place(doc, page, MarkKind::HeaderFooter, content, false)?;
}
@@ -421,7 +427,7 @@ pub fn add_watermark(doc: &mut Document, pages: &[usize], wm: &Watermark, replac
}
content.extend_from_slice(b"ET\n");
content.extend_from_slice(END.as_bytes());
- add_resources(doc, &page, Some(opacity))?;
+ add_resources(doc, &page, Some(opacity), None)?;
let page = &page_list(doc)[i];
place(doc, page, MarkKind::Watermark, content, wm.behind)?;
}
@@ -442,7 +448,7 @@ pub fn add_background(doc: &mut Document, pages: &[usize], bg: &Background, repl
let mut content = begin(MarkKind::Background, "Background", page.view_matrix(doc));
content.push_str(&format!("/PCGS{} gs\n{}\n0 0 {} {} re f\n", (opacity * 100.0).round() as i64, rgb(bg.color), n(w), n(h)));
content.push_str(END);
- add_resources(doc, &page, Some(opacity))?;
+ add_resources(doc, &page, Some(opacity), None)?;
let page = &page_list(doc)[i];
place(doc, page, MarkKind::Background, content.into_bytes(), true)?;
}
diff --git a/crates/engine/src/lib.rs b/crates/engine/src/lib.rs
index c5d549240..2c24d63f1 100644
--- a/crates/engine/src/lib.rs
+++ b/crates/engine/src/lib.rs
@@ -33,7 +33,8 @@ pub use printcraft_forms::{
pub use printcraft_annot::appearance as annot_text;
pub use printcraft_annot::links::{Highlight as LinkHighlight, LinkAction, LinkItem, LinkStyle};
pub use printcraft_annot::{
- FillMark, Markup, NewAnnotation, NoteIcon, Props as CommentProps, ReviewState, Rgb, Shape, StampGroup, StampKind, Style, rect_quad,
+ FillMark, Markup, NewAnnotation, NoteIcon, OverlayFont, OverlayLook, Props as CommentProps, ReviewState, Rgb, Shape, StampGroup, StampKind,
+ Style, rect_quad,
};
pub use printcraft_optimize as optimize;
pub use printcraft_print as print;
diff --git a/crates/engine/src/tests.rs b/crates/engine/src/tests.rs
index 5777bc6e2..47b40b08e 100644
--- a/crates/engine/src/tests.rs
+++ b/crates/engine/src/tests.rs
@@ -697,7 +697,8 @@ fn preparing_a_form_adds_renames_and_deletes_fields() {
fn redaction_marks_apply_for_good_and_undo() {
let (mut s, id) = session_with(2);
// "Page 1" at 24 pt from x 20: the "1" starts near x 82.7 (Helvetica widths).
- let shape = Shape::Redact { quads: vec![printcraft_annot::rect_quad([80.0, 140.0, 100.0, 180.0])], overlay: String::new() };
+ let shape =
+ Shape::Redact { quads: vec![printcraft_annot::rect_quad([80.0, 140.0, 100.0, 180.0])], overlay: String::new(), look: Default::default() };
let mark =
Edit::AddAnnotation(NewAnnotation { page: 0, style: Style::default_for(&shape), shape, contents: String::new(), author: "Ada".into() });
s.apply(id, mark).unwrap();
diff --git a/crates/redact/Cargo.toml b/crates/redact/Cargo.toml
index 6822106b4..64b0d2ba1 100644
--- a/crates/redact/Cargo.toml
+++ b/crates/redact/Cargo.toml
@@ -15,7 +15,7 @@ printcraft-fonts = { workspace = true }
printcraft-model = { workspace = true }
printcraft-forms = { workspace = true }
printcraft-edit = { workspace = true }
+printcraft-annot = { workspace = true }
thiserror = { workspace = true }
[dev-dependencies]
-printcraft-annot = { workspace = true }
diff --git a/crates/redact/src/lib.rs b/crates/redact/src/lib.rs
index 74707a04d..1ca84454c 100644
--- a/crates/redact/src/lib.rs
+++ b/crates/redact/src/lib.rs
@@ -53,6 +53,39 @@ pub struct Mark {
/// The box colour once applied (`/IC`; none = no box).
pub fill: Option<Rgb>,
pub overlay: String,
+ /// How the overlay text is drawn (`/DA`, `/Q`, `/Repeat`).
+ pub look: printcraft_annot::OverlayLook,
+}
+
+/// The overlay look of a Redact annotation: font, size and colour from `/DA`, alignment from
+/// `/Q`, repetition from `/Repeat`.
+fn overlay_look(doc: &Document, d: &Dict) -> printcraft_annot::OverlayLook {
+ let mut look = printcraft_annot::OverlayLook::default();
+ if let Some(da) = d.get(b"DA").and_then(|o| doc.resolve(o).as_string().map(|s| String::from_utf8_lossy(&s.bytes).into_owned())) {
+ let t: Vec<&str> = da.split_whitespace().collect();
+ for (i, w) in t.iter().enumerate() {
+ match *w {
+ "rg" if i >= 3 => {
+ if let (Ok(r), Ok(g), Ok(b)) = (t[i - 3].parse::<f64>(), t[i - 2].parse::<f64>(), t[i - 1].parse::<f64>()) {
+ look.color = [r, g, b];
+ }
+ }
+ "g" if i >= 1 => {
+ if let Ok(g) = t[i - 1].parse::<f64>() {
+ look.color = [g; 3];
+ }
+ }
+ "Tf" if i >= 2 => {
+ look.font = printcraft_annot::OverlayFont::from_resource(t[i - 2].trim_start_matches('/'));
+ look.size = t[i - 1].parse::<f64>().unwrap_or(0.0).max(0.0);
+ }
+ _ => {}
+ }
+ }
+ }
+ look.align = d.int(b"Q").unwrap_or(1).clamp(0, 2) as u8;
+ look.repeat = matches!(d.get(b"Repeat"), Some(Object::Bool(true)));
+ look
}
/// What [`apply`] removed.
@@ -128,7 +161,7 @@ pub fn marks(doc: &Document) -> Vec<Mark> {
continue;
}
let overlay = d.get(b"OverlayText").and_then(|t| doc.resolve(t).as_string().map(|s| s.to_text())).unwrap_or_default();
- out.push(Mark { page: pi, obj: r, rects, fill: color(doc, d, b"IC"), overlay });
+ out.push(Mark { page: pi, obj: r, rects, fill: color(doc, d, b"IC"), overlay, look: overlay_look(doc, d) });
}
}
out
@@ -171,23 +204,53 @@ fn overlay_content(marks: &[&Mark]) -> Vec<u8> {
if m.overlay.is_empty() {
continue;
}
- // The overlay text, centred in each area and shrunk to fit.
- let text = printcraft_fonts::literal(&printcraft_fonts::win_ansi(&m.overlay));
+ // The overlay text: its font, colour and alignment; auto-sized to fit unless a size is
+ // set; repeated to fill the area when asked.
+ let look = &m.look;
+ let (res, width): (&str, fn(&str, f64) -> f64) = match look.font {
+ printcraft_annot::OverlayFont::Helvetica => ("PCHelv", printcraft_fonts::helvetica_width),
+ // Approximations of the standard metrics (no font program is bundled).
+ printcraft_annot::OverlayFont::Times => ("PCTimes", |s, size| printcraft_fonts::helvetica_width(s, size) * 0.9),
+ printcraft_annot::OverlayFont::Courier => ("PCCour", |s, size| s.chars().count() as f64 * size * 0.6),
+ };
+ let [cr, cg, cb] = look.color.map(|v| v.clamp(0.0, 1.0));
for r in &m.rects {
let (w, h) = (r[2] - r[0], r[3] - r[1]);
- let mut size = (h * 0.7).min(12.0);
- let tw = printcraft_fonts::helvetica_width(&m.overlay, size);
- if tw > w - 2.0 && tw > 0.0 {
+ let mut size = if look.size > 0.0 { look.size } else { (h * 0.7).min(12.0) };
+ let tw = width(&m.overlay, size);
+ if look.size <= 0.0 && tw > w - 2.0 && tw > 0.0 {
size *= (w - 2.0).max(0.0) / tw;
}
if size < 2.0 {
continue;
}
- let tw = printcraft_fonts::helvetica_width(&m.overlay, size);
- let (x, y) = (r[0] + (w - tw) / 2.0, r[1] + (h - size * 0.7) / 2.0);
- c.extend(format!("q BT 1 0 0 rg /PCHelv {} Tf {} {} Td ", n(size), n(x), n(y)).bytes());
- c.extend_from_slice(&text);
- c.extend_from_slice(b" Tj ET Q\n");
+ // One line, or as many repeated lines as fit (each line the text repeated across).
+ let lines: Vec<String> = if look.repeat {
+ let unit = width(&format!("{} ", m.overlay), size).max(0.01);
+ let per_line = ((w - 2.0) / unit).floor().max(1.0) as usize;
+ let count = ((h / (size * 1.2)).floor() as usize).max(1);
+ vec![vec![m.overlay.as_str(); per_line].join(" "); count]
+ } else {
+ vec![m.overlay.clone()]
+ };
+ let block = lines.len() as f64 * size * 1.2;
+ let mut y = r[1] + (h + block) / 2.0 - size * 0.95;
+ c.extend(
+ format!("q {} {} {} {} re W n BT {} {} {} rg /{res} {} Tf ", n(r[0]), n(r[1]), n(w), n(h), n(cr), n(cg), n(cb), n(size)).bytes(),
+ );
+ for line in &lines {
+ let lw = width(line, size);
+ let x = match look.align {
+ 0 => r[0] + 1.0,
+ 2 => r[2] - 1.0 - lw,
+ _ => r[0] + (w - lw) / 2.0,
+ };
+ c.extend(format!("1 0 0 1 {} {} Tm ", n(x), n(y)).bytes());
+ c.extend_from_slice(&printcraft_fonts::literal(&printcraft_fonts::win_ansi(line)));
+ c.extend_from_slice(b" Tj ");
+ y -= size * 1.2;
+ }
+ c.extend_from_slice(b"ET Q\n");
}
}
c
diff --git a/crates/redact/src/tests.rs b/crates/redact/src/tests.rs
index 1b788f9bf..4ca27394f 100644
--- a/crates/redact/src/tests.rs
+++ b/crates/redact/src/tests.rs
@@ -53,7 +53,7 @@ fn one_page(content: &[u8], extra_res: &str, extra: Vec<Vec<u8>>) -> Document {
}
fn mark(doc: &mut Document, page: usize, rects: &[[f64; 4]], overlay: &str) {
- let shape = Shape::Redact { quads: rects.iter().map(|r| rect_quad(*r)).collect(), overlay: overlay.into() };
+ let shape = Shape::Redact { quads: rects.iter().map(|r| rect_quad(*r)).collect(), overlay: overlay.into(), look: Default::default() };
let style = Style::default_for(&shape);
add_annotation(doc, &NewAnnotation { page, shape, style, contents: String::new(), author: "Tester".into() }, &Meta::default()).unwrap();
}
@@ -348,3 +348,31 @@ fn hidden_information_is_counted_and_removed() {
});
assert!(shown, "the field's value stays visible as page content");
}
+
+#[test]
+fn overlay_text_takes_its_font_size_colour_alignment_and_repeats() {
+ let mut doc = one_page(b"BT /F1 12 Tf 20 250 Td (Secret salary figures) Tj ET", "", Vec::new());
+ let look =
+ printcraft_annot::OverlayLook { font: printcraft_annot::OverlayFont::Courier, size: 8.0, color: [0.0, 0.0, 1.0], align: 0, repeat: true };
+ let shape = Shape::Redact { quads: vec![rect_quad([10.0, 200.0, 290.0, 270.0])], overlay: "REDACTED".into(), look };
+ let style = Style::default_for(&shape);
+ add_annotation(&mut doc, &NewAnnotation { page: 0, shape, style, contents: String::new(), author: "T".into() }, &Meta::default()).unwrap();
+ // Written as Acrobat writes it.
+ let m = &marks(&doc)[0];
+ assert_eq!(m.look, look, "the look round-trips through /DA, /Q and /Repeat");
+ apply(&mut doc, None).unwrap();
+ let doc = reopen(&doc);
+ let c = content(&doc, 0);
+ assert!(c.contains("0 0 1 rg /PCCour 8 Tf"), "{c}");
+ // 70 pt high at 8 pt × 1.2 leading: several lines, each the word repeated.
+ assert!(c.matches(" Tm (REDACTED REDACTED").count() >= 5, "{c}");
+ assert!(c.contains("1 0 0 1 11 "), "left aligned at the area's edge: {c}");
+ let p = &printcraft_model::pages(&doc)[0];
+ let fonts = p
+ .dict
+ .get(b"Resources")
+ .and_then(|r| doc.resolve(r).as_dict().cloned())
+ .and_then(|r| r.get(b"Font").and_then(|f| doc.resolve(f).as_dict().cloned()))
+ .unwrap();
+ assert!(fonts.contains(b"PCCour") && !fonts.contains(b"PCTimes"));
+}
diff --git a/crates/ui-egui/src/redact_ui.rs b/crates/ui-egui/src/redact_ui.rs
index 0f7034682..caf39275b 100644
--- a/crates/ui-egui/src/redact_ui.rs
+++ b/crates/ui-egui/src/redact_ui.rs
@@ -20,17 +20,19 @@ pub struct RedactPrefs {
pub fill: Option<Rgb>,
pub use_overlay: bool,
pub overlay: String,
+ /// Overlay text font, size (0 = auto), colour, alignment and repetition.
+ pub look: printcraft_engine::OverlayLook,
}
impl Default for RedactPrefs {
fn default() -> Self {
- Self { fill: Some([0.0, 0.0, 0.0]), use_overlay: false, overlay: String::new() }
+ Self { fill: Some([0.0, 0.0, 0.0]), use_overlay: false, overlay: String::new(), look: Default::default() }
}
}
impl RedactPrefs {
pub fn mark(&self, page: usize, quads: Vec<[f64; 8]>, author: &str) -> Edit {
- let shape = Shape::Redact { quads, overlay: if self.use_overlay { self.overlay.clone() } else { String::new() } };
+ let shape = Shape::Redact { quads, overlay: if self.use_overlay { self.overlay.clone() } else { String::new() }, look: self.look };
let mut style = Style::default_for(&shape);
style.fill = self.fill;
Edit::AddAnnotation(NewAnnotation { page, shape, style, contents: String::new(), author: author.to_string() })
@@ -272,6 +274,49 @@ pub(crate) fn props_body(ui: &mut egui::Ui, d: &mut RedactPrefs, _t: &Tokens) ->
let l = ui.label("Custom text:");
ui.add_enabled(d.use_overlay, egui::TextEdit::singleline(&mut d.overlay).desired_width(220.0)).labelled_by(l.id);
ui.end_row();
+ let on = d.use_overlay;
+ let look = &mut d.look;
+ ui.label("Font:");
+ ui.add_enabled_ui(on, |ui| {
+ egui::ComboBox::from_id_salt("overlay-font").selected_text(look.font.name()).show_ui(ui, |ui| {
+ for f in printcraft_engine::OverlayFont::ALL {
+ ui.selectable_value(&mut look.font, f, f.name());
+ }
+ });
+ });
+ ui.end_row();
+ ui.label("Font size:");
+ ui.add_enabled_ui(on, |ui| {
+ ui.horizontal(|ui| {
+ let mut auto = look.size <= 0.0;
+ if ui.checkbox(&mut auto, "Auto-size text to fit redaction region").changed() {
+ look.size = if auto { 0.0 } else { 10.0 };
+ }
+ if !auto {
+ ui.add(egui::DragValue::new(&mut look.size).range(2.0..=144.0).suffix(" pt"));
+ }
+ });
+ });
+ ui.end_row();
+ ui.label("Font colour:");
+ ui.add_enabled_ui(on, |ui| {
+ if let Some(c) = crate::comments::swatch_grid(ui, Some(look.color)) {
+ look.color = c;
+ }
+ });
+ ui.end_row();
+ ui.label("");
+ ui.add_enabled(on, egui::Checkbox::new(&mut look.repeat, "Repeat overlay text"));
+ ui.end_row();
+ ui.label("Text alignment:");
+ ui.add_enabled_ui(on, |ui| {
+ ui.horizontal(|ui| {
+ for (a, label) in [(0u8, "Left"), (1, "Center"), (2, "Right")] {
+ ui.radio_value(&mut look.align, a, label);
+ }
+ });
+ });
+ ui.end_row();
});
ui.add_space(12.0);
buttons(ui, "OK", true)
diff --git a/crates/ui-egui/tests/commands.rs b/crates/ui-egui/tests/commands.rs
index 070e63aac..f141a1f02 100644
--- a/crates/ui-egui/tests/commands.rs
+++ b/crates/ui-egui/tests/commands.rs
@@ -85,7 +85,11 @@ fn every_registered_command_is_implemented() {
}
if spec.id.starts_with("redact.") {
use printcraft_engine::{Edit, NewAnnotation, Shape, Style};
- let shape = Shape::Redact { quads: vec![printcraft_engine::rect_quad([10.0, 10.0, 50.0, 50.0])], overlay: String::new() };
+ let shape = Shape::Redact {
+ quads: vec![printcraft_engine::rect_quad([10.0, 10.0, 50.0, 50.0])],
+ overlay: String::new(),
+ look: Default::default(),
+ };
app.apply_edit(Edit::AddAnnotation(NewAnnotation {
page: 0,
style: Style::default_for(&shape),
diff --git a/parity/acrobat-features.toml b/parity/acrobat-features.toml
index 52d404a77..947b75cc8 100644
--- a/parity/acrobat-features.toml
+++ b/parity/acrobat-features.toml
@@ -5530,8 +5530,8 @@ milestone = "M8"
status = "partial"
commands = ["redact.properties"]
tools = ["redact_mark"]
-evidence = ["crates/ui-egui/tests/redact.rs::marking_applying_and_clearing"]
-notes = "fill colour or none, custom overlay text; fonts, repeat, codes pending"
+evidence = ["crates/ui-egui/tests/redact.rs::marking_applying_and_clearing", "crates/redact/src/tests.rs::overlay_text_takes_its_font_size_colour_alignment_and_repeats"]
+notes = "fill colour or none; overlay text with font, size or auto-size, colour, alignment and repeat; redaction codes pending"
[[feature]]
id = "protect.redaction-codes"