From d546453880721d7a12ea228e5c1ed6c65b653ca2 Mon Sep 17 00:00:00 2001 From: Martin Date: Mon, 23 Aug 2021 23:56:33 +0200 Subject: Links! (#43) Co-authored-by: Laurenz --- tests/ref/text/links.png | Bin 0 -> 6947 bytes tests/typ/text/links.typ | 12 ++++++++++++ tests/typeset.rs | 7 ++++++- 3 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 tests/ref/text/links.png create mode 100644 tests/typ/text/links.typ (limited to 'tests') diff --git a/tests/ref/text/links.png b/tests/ref/text/links.png new file mode 100644 index 00000000..5ac7ee00 Binary files /dev/null and b/tests/ref/text/links.png differ diff --git a/tests/typ/text/links.typ b/tests/typ/text/links.typ new file mode 100644 index 00000000..eabb316a --- /dev/null +++ b/tests/typ/text/links.typ @@ -0,0 +1,12 @@ +// Link without body. +#link("https://example.com/") + +// Link with body. +#link("https://typst.app/")[Some text text text] + +// With line break. +This link appears #link("https://google.com/")[in the middle of] a paragraph. + +// Styled with underline and color. +#let link(url, body) = link(url, [#font(fill: rgb("283663")) #underline(body)]) +You could also make the #link("https://html5zombo.com/")[link look way more typical.] diff --git a/tests/typeset.rs b/tests/typeset.rs index 80eb9da4..b788f74d 100644 --- a/tests/typeset.rs +++ b/tests/typeset.rs @@ -9,7 +9,7 @@ use tiny_skia as sk; use ttf_parser::{GlyphId, OutlineBuilder}; use walkdir::WalkDir; -use typst::color::Color; +use typst::color::{Color, RgbaColor}; use typst::diag::Error; use typst::eval::{State, Value}; use typst::geom::{self, Length, PathElement, Point, Sides, Size}; @@ -428,6 +428,11 @@ fn draw(ctx: &Context, frames: &[Rc], dpi: f32) -> sk::Pixmap { Element::Image(id, size) => { draw_image(&mut canvas, ts, ctx, id, size); } + Element::Link(_, s) => { + let outline = Geometry::Rect(s); + let paint = Paint::Color(Color::Rgba(RgbaColor::new(40, 54, 99, 40))); + draw_geometry(&mut canvas, ts, &outline, paint); + } } } -- cgit v1.2.3