Crates.io | line-straddler |
lib.rs | line-straddler |
version | 0.2.3 |
source | src |
created_at | 2023-05-11 01:47:18.209405 |
updated_at | 2024-01-05 19:38:18.409817 |
description | Determine how lines through text (underlines, strikethroughs, etc) should be rendered. |
homepage | https://codeberg.org/notgull/line-straddler |
repository | https://codeberg.org/notgull/line-straddler |
max_upload_size | |
id | 861764 |
size | 50,457 |
Figure out where lines should go when underlining/striking through text.
When you're drawing text, you need to determine where the lines go for text
decorations. This crate provides a renderer-agnostic LineGenerator
that
generates Line
structures for a set of Glyph
s.
The canonical code for this repository is kept on Codeberg. For convenience, a mirror is kept on GitHub.
use line_straddler::{LineGenerator, Line, LineType, Glyph, GlyphStyle, Color};
// Take some glyphs from, e.g, cosmic-text
// For instance, this is two lines of two glyphs.
let style = GlyphStyle {
bold: false,
color: Color::rgba(0, 0, 0, 255),
};
let glyphs = [
Glyph {
line_y: 0.0,
font_size: 4.0,
width: 2.0,
x: 0.0,
style,
},
Glyph {
line_y: 0.0,
font_size: 4.0,
width: 2.0,
x: 3.0,
style,
},
Glyph {
line_y: 5.0,
font_size: 4.0,
width: 2.0,
x: 0.0,
style,
},
Glyph {
line_y: 5.0,
font_size: 4.0,
width: 2.0,
x: 3.0,
style,
},
];
// Create a line generator.
let mut alg = LineGenerator::new(LineType::Underline);
// Generate lines for the glyphs.
let mut lines = Vec::new();
for glyph in glyphs {
lines.extend(alg.add_glyph(glyph));
}
lines.extend(alg.pop_line());
// Draw all of the lines.
for line in lines {
let point_1 = (line.start_x, line.y);
let point_2 = (line.end_x, line.y);
draw_line(point_1, point_2, line.style);
}
line-straddler
is free software: you can redistribute it and/or modify it under
the terms of either:
line-straddler
is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the
Mozilla Public License for more details.
You should have received a copy of the GNU Lesser General Public License and the
Mozilla Public License along with line-straddler
. If not, see
https://www.gnu.org/licenses/.