line-straddler

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 Glyphs.

Example

```rust 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 { liney: 0.0, fontsize: 4.0, width: 2.0, x: 0.0, style, }, Glyph { liney: 0.0, fontsize: 4.0, width: 2.0, x: 3.0, style, }, Glyph { liney: 5.0, fontsize: 4.0, width: 2.0, x: 0.0, style, }, Glyph { liney: 5.0, fontsize: 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.addglyph(glyph)); } lines.extend(alg.popline());

// Draw all of the lines. for line in lines { let point1 = (line.startx, line.y); let point2 = (line.endx, line.y); drawline(point1, point_2, line.style); } ```

License

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/.