mirror of
https://github.com/chatmail/core.git
synced 2026-04-17 21:46:35 +03:00
tweak qr svg (#2842)
* repl: allow groupname arguments with more than one word (came over that when testing qr codes) * calcualte text-size from the real number of lines * shift text and watermark apart when text get longer * make clippy happy
This commit is contained in:
@@ -755,7 +755,12 @@ pub async fn cmdline(context: Context, line: &str, chat_id: &mut ChatId) -> Resu
|
|||||||
"groupname" => {
|
"groupname" => {
|
||||||
ensure!(sel_chat.is_some(), "No chat selected.");
|
ensure!(sel_chat.is_some(), "No chat selected.");
|
||||||
ensure!(!arg1.is_empty(), "Argument <name> missing.");
|
ensure!(!arg1.is_empty(), "Argument <name> missing.");
|
||||||
chat::set_chat_name(&context, sel_chat.as_ref().unwrap().get_id(), arg1).await?;
|
chat::set_chat_name(
|
||||||
|
&context,
|
||||||
|
sel_chat.as_ref().unwrap().get_id(),
|
||||||
|
&format!("{} {}", arg1, arg2).trim(),
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
|
||||||
println!("Chat name set");
|
println!("Chat name set");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -80,11 +80,6 @@ fn inner_generate_secure_join_qr_code(
|
|||||||
let qr_code_size = 400.0;
|
let qr_code_size = 400.0;
|
||||||
let qr_translate_up = 40.0;
|
let qr_translate_up = 40.0;
|
||||||
let text_y_pos = ((height - qr_code_size) / 2.0) + qr_code_size;
|
let text_y_pos = ((height - qr_code_size) / 2.0) + qr_code_size;
|
||||||
let (text_font_size, max_text_width) = if qrcode_description.len() <= 75 {
|
|
||||||
(27.0, 32)
|
|
||||||
} else {
|
|
||||||
(19.0, 38)
|
|
||||||
};
|
|
||||||
let avatar_border_size = 9.0;
|
let avatar_border_size = 9.0;
|
||||||
let card_border_size = 2.0;
|
let card_border_size = 2.0;
|
||||||
let card_roundness = 40.0;
|
let card_roundness = 40.0;
|
||||||
@@ -142,13 +137,25 @@ fn inner_generate_secure_join_qr_code(
|
|||||||
.attr("transform", format!("scale({})", scale));
|
.attr("transform", format!("scale({})", scale));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// Text
|
// Text
|
||||||
for (count, line) in textwrap::fill(qrcode_description, max_text_width)
|
const BIG_TEXT_CHARS_PER_LINE: usize = 32;
|
||||||
.split('\n')
|
const SMALL_TEXT_CHARS_PER_LINE: usize = 38;
|
||||||
.enumerate()
|
let chars_per_line = if qrcode_description.len() > SMALL_TEXT_CHARS_PER_LINE*2 {
|
||||||
|
SMALL_TEXT_CHARS_PER_LINE
|
||||||
|
} else {
|
||||||
|
BIG_TEXT_CHARS_PER_LINE
|
||||||
|
};
|
||||||
|
let lines = textwrap::fill(qrcode_description, chars_per_line);
|
||||||
|
let (text_font_size, text_y_shift) = if lines.split('\n').count() <= 2 {
|
||||||
|
(27.0, 0.0)
|
||||||
|
} else {
|
||||||
|
(19.0, -10.0)
|
||||||
|
};
|
||||||
|
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)
|
d.attr("y", (count as f32 * (text_font_size * 1.2)) + text_y_pos + text_y_shift)
|
||||||
.attr("x", width / 2.0)
|
.attr("x", width / 2.0)
|
||||||
.attr("text-anchor", "middle")
|
.attr("text-anchor", "middle")
|
||||||
.attr(
|
.attr(
|
||||||
@@ -249,7 +256,7 @@ fn inner_generate_secure_join_qr_code(
|
|||||||
format!(
|
format!(
|
||||||
"translate({},{})",
|
"translate({},{})",
|
||||||
(width - FOOTER_WIDTH) / 2.0,
|
(width - FOOTER_WIDTH) / 2.0,
|
||||||
height - logo_offset - FOOTER_HEIGHT
|
height - logo_offset - FOOTER_HEIGHT - text_y_shift
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user