Merge pull request #2872 from deltachat/dependabot/cargo/tagger-3.3.0

This commit is contained in:
dependabot[bot]
2021-12-11 11:58:39 +00:00
committed by GitHub
3 changed files with 90 additions and 94 deletions

4
Cargo.lock generated
View File

@@ -3650,9 +3650,9 @@ dependencies = [
[[package]] [[package]]
name = "tagger" name = "tagger"
version = "3.2.1" version = "3.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c933e626196d509b053f49573e35ad237c0ff6a36c23c1aa61ffeab49251d24f" checksum = "7ebdb5588f490ba960dea65d7a6dc05fb788e2df62fe3f4cc2f0d53ca7473e66"
[[package]] [[package]]
name = "tap" name = "tap"

View File

@@ -74,7 +74,7 @@ uuid = { version = "0.8", features = ["serde", "v4"] }
fast-socks5 = "0.4" fast-socks5 = "0.4"
humansize = "1" humansize = "1"
qrcodegen = "1.7.0" qrcodegen = "1.7.0"
tagger = "3.2.1" tagger = "3.3.0"
textwrap = "0.14.2" textwrap = "0.14.2"
[dev-dependencies] [dev-dependencies]

View File

@@ -89,21 +89,23 @@ fn inner_generate_secure_join_qr_code(
let mut w = tagger::new(&mut svg); let mut w = tagger::new(&mut svg);
w.elem("svg", |d| { w.elem("svg", |d| {
d.attr("xmlns", "http://www.w3.org/2000/svg") d.attr("xmlns", "http://www.w3.org/2000/svg")?;
.attr("viewBox", format_args!("0 0 {} {}", width, height)); d.attr("viewBox", format_args!("0 0 {} {}", width, height))?;
}) Ok(())
})?
.build(|w| { .build(|w| {
// White Background apears like a card // White Background apears like a card
w.single("rect", |d| { w.single("rect", |d| {
d.attr("x", card_border_size) d.attr("x", card_border_size)?;
.attr("y", card_border_size) d.attr("y", card_border_size)?;
.attr("rx", card_roundness) d.attr("rx", card_roundness)?;
.attr("stroke", "#c6c6c6") d.attr("stroke", "#c6c6c6")?;
.attr("stroke-width", card_border_size) d.attr("stroke-width", card_border_size)?;
.attr("width", width - (card_border_size * 2.0)) d.attr("width", width - (card_border_size * 2.0))?;
.attr("height", height - (card_border_size * 2.0)) d.attr("height", height - (card_border_size * 2.0))?;
.attr("style", "fill:#f2f2f2"); d.attr("style", "fill:#f2f2f2")?;
}); Ok(())
})?;
// Qrcode // Qrcode
w.elem("g", |d| { w.elem("g", |d| {
d.attr( d.attr(
@@ -113,12 +115,12 @@ fn inner_generate_secure_join_qr_code(
(width - qr_code_size) / 2.0, (width - qr_code_size) / 2.0,
((height - qr_code_size) / 2.0) - qr_translate_up ((height - qr_code_size) / 2.0) - qr_translate_up
), ),
); )
// If the qr code should be in the wrong place, // If the qr code should be in the wrong place,
// we could also translate and scale the points in the path already, // we could also translate and scale the points in the path already,
// but that would make the resulting svg way bigger in size and might bring up rounding issues, // but that would make the resulting svg way bigger in size and might bring up rounding issues,
// so better avoid doing it manually if possible // so better avoid doing it manually if possible
}) })?
.build(|w| { .build(|w| {
w.single("path", |d| { w.single("path", |d| {
let mut path_data = String::with_capacity(0); let mut path_data = String::with_capacity(0);
@@ -132,16 +134,16 @@ fn inner_generate_secure_join_qr_code(
} }
} }
d.attr("style", "fill:#000000") d.attr("style", "fill:#000000")?;
.attr("d", path_data) d.attr("d", path_data)?;
.attr("transform", format!("scale({})", scale)); d.attr("transform", format!("scale({})", scale))
}); })
}); })?;
// Text // Text
const BIG_TEXT_CHARS_PER_LINE: usize = 32; const BIG_TEXT_CHARS_PER_LINE: usize = 32;
const SMALL_TEXT_CHARS_PER_LINE: usize = 38; const SMALL_TEXT_CHARS_PER_LINE: usize = 38;
let chars_per_line = if qrcode_description.len() > SMALL_TEXT_CHARS_PER_LINE*2 { let chars_per_line = if qrcode_description.len() > SMALL_TEXT_CHARS_PER_LINE * 2 {
SMALL_TEXT_CHARS_PER_LINE SMALL_TEXT_CHARS_PER_LINE
} else { } else {
BIG_TEXT_CHARS_PER_LINE BIG_TEXT_CHARS_PER_LINE
@@ -152,27 +154,27 @@ fn inner_generate_secure_join_qr_code(
} else { } else {
(19.0, -10.0) (19.0, -10.0)
}; };
for (count, line) in lines.split('\n').enumerate() for (count, line) in lines.split('\n').enumerate() {
{
w.elem("text", |d| { w.elem("text", |d| {
d.attr("y", (count as f32 * (text_font_size * 1.2)) + text_y_pos + text_y_shift) d.attr(
.attr("x", width / 2.0) "y",
.attr("text-anchor", "middle") (count as f32 * (text_font_size * 1.2)) + text_y_pos + text_y_shift,
.attr( )?;
"style", d.attr("x", width / 2.0)?;
format!( d.attr("text-anchor", "middle")?;
"font-family:sans-serif;\ d.attr(
"style",
format!(
"font-family:sans-serif;\
font-weight:bold;\ font-weight:bold;\
font-size:{}px;\ font-size:{}px;\
fill:#000000;\ fill:#000000;\
stroke:none", stroke:none",
text_font_size text_font_size
), ),
); )
}) })?
.build(|w| { .build(|w| w.put_raw(line))?;
w.put_raw(line);
});
} }
// contact avatar in middle of qrcode // contact avatar in middle of qrcode
const LOGO_SIZE: f32 = 94.4; const LOGO_SIZE: f32 = 94.4;
@@ -183,68 +185,64 @@ fn inner_generate_secure_join_qr_code(
((height - qr_code_size) / 2.0) - qr_translate_up + logo_position_in_qr; ((height - qr_code_size) / 2.0) - qr_translate_up + logo_position_in_qr;
w.single("circle", |d| { w.single("circle", |d| {
d.attr("cx", logo_position_x + HALF_LOGO_SIZE) d.attr("cx", logo_position_x + HALF_LOGO_SIZE)?;
.attr("cy", logo_position_y + HALF_LOGO_SIZE) d.attr("cy", logo_position_y + HALF_LOGO_SIZE)?;
.attr("r", HALF_LOGO_SIZE + avatar_border_size) d.attr("r", HALF_LOGO_SIZE + avatar_border_size)?;
.attr("style", "fill:#f2f2f2"); d.attr("style", "fill:#f2f2f2")
}); })?;
if let Some(img) = avatar { if let Some(img) = avatar {
w.elem("defs", |_| {}).build(|w| { w.elem("defs", tagger::no_attr())?.build(|w| {
w.elem("clipPath", |d| { w.elem("clipPath", |d| d.attr("id", "avatar-cut"))?
d.attr("id", "avatar-cut"); .build(|w| {
}) w.single("circle", |d| {
.build(|w| { d.attr("cx", logo_position_x + HALF_LOGO_SIZE)?;
w.single("circle", |d| { d.attr("cy", logo_position_y + HALF_LOGO_SIZE)?;
d.attr("cx", logo_position_x + HALF_LOGO_SIZE) d.attr("r", HALF_LOGO_SIZE)
.attr("cy", logo_position_y + HALF_LOGO_SIZE) })
.attr("r", HALF_LOGO_SIZE); })
}); })?;
});
});
w.single("image", |d| { w.single("image", |d| {
d.attr("x", logo_position_x) d.attr("x", logo_position_x)?;
.attr("y", logo_position_y) d.attr("y", logo_position_y)?;
.attr("width", HALF_LOGO_SIZE * 2.0) d.attr("width", HALF_LOGO_SIZE * 2.0)?;
.attr("height", HALF_LOGO_SIZE * 2.0) d.attr("height", HALF_LOGO_SIZE * 2.0)?;
.attr("preserveAspectRatio", "none") d.attr("preserveAspectRatio", "none")?;
.attr("clip-path", "url(#avatar-cut)") d.attr("clip-path", "url(#avatar-cut)")?;
.attr( d.attr(
"href" /*might need xlink:href instead if it doesn't work on older devices?*/, "href", /*might need xlink:href instead if it doesn't work on older devices?*/
format!("data:image/jpeg;base64,{}", base64::encode(img)), format!("data:image/jpeg;base64,{}", base64::encode(img)),
); )
}); })?;
} else { } else {
w.single("circle", |d| { w.single("circle", |d| {
d.attr("cx", logo_position_x + HALF_LOGO_SIZE) d.attr("cx", logo_position_x + HALF_LOGO_SIZE)?;
.attr("cy", logo_position_y + HALF_LOGO_SIZE) d.attr("cy", logo_position_y + HALF_LOGO_SIZE)?;
.attr("r", HALF_LOGO_SIZE) d.attr("r", HALF_LOGO_SIZE)?;
.attr("style", format!("fill:{}", &color)); d.attr("style", format!("fill:{}", &color))
}); })?;
let avatar_font_size = LOGO_SIZE * 0.65; let avatar_font_size = LOGO_SIZE * 0.65;
let font_offset = avatar_font_size * 0.1; let font_offset = avatar_font_size * 0.1;
w.elem("text", |d| { w.elem("text", |d| {
d.attr("y", logo_position_y + HALF_LOGO_SIZE + font_offset) d.attr("y", logo_position_y + HALF_LOGO_SIZE + font_offset)?;
.attr("x", logo_position_x + HALF_LOGO_SIZE) d.attr("x", logo_position_x + HALF_LOGO_SIZE)?;
.attr("text-anchor", "middle") d.attr("text-anchor", "middle")?;
.attr("dominant-baseline", "central") d.attr("dominant-baseline", "central")?;
.attr("alignment-baseline", "middle") d.attr("alignment-baseline", "middle")?;
.attr( d.attr(
"style", "style",
format!( format!(
"font-family:sans-serif;\ "font-family:sans-serif;\
font-weight:400;\ font-weight:400;\
font-size:{}px;\ font-size:{}px;\
fill:#ffffff;", fill:#ffffff;",
avatar_font_size avatar_font_size
), ),
); )
}) })?
.build(|w| { .build(|w| w.put_raw(avatar_letter.to_uppercase()))?;
w.put_raw(avatar_letter.to_uppercase());
});
} }
// Footer logo // Footer logo
@@ -258,12 +256,10 @@ fn inner_generate_secure_join_qr_code(
(width - FOOTER_WIDTH) / 2.0, (width - FOOTER_WIDTH) / 2.0,
height - logo_offset - FOOTER_HEIGHT - text_y_shift height - logo_offset - FOOTER_HEIGHT - text_y_shift
), ),
); )
}) })?
.build(|w| { .build(|w| w.put_raw(include_str!("../assets/qrcode_logo_footer.svg")))
w.put_raw(include_str!("../assets/qrcode_logo_footer.svg")); })?;
});
});
Ok(svg) Ok(svg)
} }