Compare commits

...

3 commits

Author SHA1 Message Date
Simon Bruder 1195287bc8
label: Add Square28 preset
All checks were successful
/ build (push) Successful in 7s
2024-07-20 13:31:03 +02:00
Simon Bruder cf5157c3cf
label: Add text wrapping 2024-07-20 13:31:02 +02:00
Simon Bruder 0f453072ea
Add CI workflow 2024-07-20 13:30:58 +02:00
3 changed files with 95 additions and 7 deletions

View file

@ -0,0 +1,33 @@
# SPDX-FileCopyrightText: 2024 Simon Bruder <simon@sbruder.de>
#
# SPDX-License-Identifier: AGPL-3.0-or-later
on:
push:
branches:
- master
jobs:
build:
runs-on: nix
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Checkout LFS
run: |
# You have the choice:
# Either it sets the Authorization header twice (which git-lfs does not accept)
# or it sets it not at all.
# As the repository is public, the latter case is acceptable.
git config --unset "http.${GITHUB_SERVER_URL}/.extraHeader"
git lfs install --local
git lfs pull
- name: Build
run: nix build -L .#li7y .#li7y-oci
- name: Push OCI image
run: |
nix build .#li7y-oci
podman image load -i ./result
podman tag li7y git.sbruder.de/simon/li7y:latest
podman login --username simon --password "${{ secrets.REGISTRY_PASSWORD }}" git.sbruder.de
podman push git.sbruder.de/simon/li7y:latest

View file

@ -124,6 +124,7 @@ impl Code128Config {
pub struct TextConfig { pub struct TextConfig {
font_size: f32, font_size: f32,
position: (Mm, Mm), position: (Mm, Mm),
wrap: Option<usize>,
} }
impl TextConfig { impl TextConfig {
@ -133,15 +134,38 @@ impl TextConfig {
font: &IndirectFontRef, font: &IndirectFontRef,
text: Option<S>, text: Option<S>,
) -> Result<()> { ) -> Result<()> {
layer.use_text( layer.begin_text_section();
text.ok_or(Error::DataIncomplete("ID text".to_string()))?, layer.set_font(font, self.font_size);
self.font_size, layer.set_line_height(self.font_size);
self.position.0, layer.set_text_cursor(self.position.0, self.position.1);
self.position.1, if let Some(text) = self.wrap(text) {
font, for line in text.split('\n') {
); layer.write_text(line, font);
layer.add_line_break();
}
} else {
return Err(Error::DataIncomplete("ID text".to_string()));
}
layer.end_text_section();
Ok(()) Ok(())
} }
fn wrap<S: Into<String>>(&self, text: Option<S>) -> Option<String> {
if let Some(wrap) = self.wrap {
let mut inserted = 0;
text.map(|s| {
let s = s.into();
let mut chars: Vec<char> = s.chars().collect();
for i in (wrap..s.len()).step_by(wrap) {
chars.insert(i + inserted, '\n');
inserted += 1;
}
chars.iter().collect()
})
} else {
text.map(|s| s.into())
}
}
} }
#[derive(Debug)] #[derive(Debug)]

View file

@ -16,6 +16,7 @@ pub enum LabelPreset {
SeikoSlpMrlDataMatrix, SeikoSlpMrlDataMatrix,
SeikoSlpMrlCode128, SeikoSlpMrlCode128,
SeikoSlpMrl, SeikoSlpMrl,
Square28,
} }
impl fmt::Display for LabelPreset { impl fmt::Display for LabelPreset {
@ -27,6 +28,7 @@ impl fmt::Display for LabelPreset {
Self::SeikoSlpMrlDataMatrix => "Seiko SLP MRL (Data Matrix only)", Self::SeikoSlpMrlDataMatrix => "Seiko SLP MRL (Data Matrix only)",
Self::SeikoSlpMrlCode128 => "Seiko SLP MRL (Code128 only)", Self::SeikoSlpMrlCode128 => "Seiko SLP MRL (Code128 only)",
Self::SeikoSlpMrl => "Seiko SLP MRL", Self::SeikoSlpMrl => "Seiko SLP MRL",
Self::Square28 => "Square 28 × 28mm",
} }
) )
} }
@ -53,14 +55,17 @@ impl Into<LabelConfig> for LabelPreset {
id_text: Some(TextConfig { id_text: Some(TextConfig {
font_size: 7.0, font_size: 7.0,
position: (Mm(0.0), Mm(22.0)), position: (Mm(0.0), Mm(22.0)),
wrap: None,
}), }),
short_id_text: Some(TextConfig { short_id_text: Some(TextConfig {
font_size: 7.0, font_size: 7.0,
position: (Mm(21.0), Mm(0.6)), position: (Mm(21.0), Mm(0.6)),
wrap: None,
}), }),
branding: Some(TextConfig { branding: Some(TextConfig {
font_size: 7.0, font_size: 7.0,
position: (Mm(39.5), Mm(0.6)), position: (Mm(39.5), Mm(0.6)),
wrap: None,
}), }),
}, },
Self::SeikoSlpMrlCode128 => LabelConfig { Self::SeikoSlpMrlCode128 => LabelConfig {
@ -74,14 +79,17 @@ impl Into<LabelConfig> for LabelPreset {
id_text: Some(TextConfig { id_text: Some(TextConfig {
font_size: 7.0, font_size: 7.0,
position: (Mm(0.0), Mm(22.0)), position: (Mm(0.0), Mm(22.0)),
wrap: None,
}), }),
short_id_text: Some(TextConfig { short_id_text: Some(TextConfig {
font_size: 7.0, font_size: 7.0,
position: (Mm(0.0), Mm(0.0)), position: (Mm(0.0), Mm(0.0)),
wrap: None,
}), }),
branding: Some(TextConfig { branding: Some(TextConfig {
font_size: 7.0, font_size: 7.0,
position: (Mm(39.5), Mm(0.6)), position: (Mm(39.5), Mm(0.6)),
wrap: None,
}), }),
}, },
Self::SeikoSlpMrl => LabelConfig { Self::SeikoSlpMrl => LabelConfig {
@ -98,14 +106,37 @@ impl Into<LabelConfig> for LabelPreset {
id_text: Some(TextConfig { id_text: Some(TextConfig {
font_size: 7.0, font_size: 7.0,
position: (Mm(0.0), Mm(22.0)), position: (Mm(0.0), Mm(22.0)),
wrap: None,
}), }),
short_id_text: Some(TextConfig { short_id_text: Some(TextConfig {
font_size: 7.0, font_size: 7.0,
position: (Mm(17.0), Mm(0.0)), position: (Mm(17.0), Mm(0.0)),
wrap: None,
}), }),
branding: Some(TextConfig { branding: Some(TextConfig {
font_size: 7.0, font_size: 7.0,
position: (Mm(39.5), Mm(0.6)), position: (Mm(39.5), Mm(0.6)),
wrap: None,
}),
},
Self::Square28 => LabelConfig {
width: Mm(20.0),
height: Mm(24.0),
data_matrix: Some(DataMatrixConfig {
scale: Mm(20.0),
position: (Mm(0.0), Mm(4.0)),
}),
code128: None,
id_text: Some(TextConfig {
font_size: 5.0,
position: (Mm(0.0), Mm(2.0)),
wrap: Some(19),
}),
short_id_text: None,
branding: Some(TextConfig {
font_size: 4.0,
position: (Mm(17.0), Mm(0.5)),
wrap: None,
}), }),
}, },
} }