diff --git a/Project.toml b/Project.toml index b5889f7..05fa993 100644 --- a/Project.toml +++ b/Project.toml @@ -12,10 +12,12 @@ Dates = "ade2ca70-3891-5945-98fb-dc099432e06a" FixedPointNumbers = "53c48c17-4a7d-5ca2-90c5-79b7896eea93" GeometryExperiments = "1147bd75-18e1-436d-adda-d58e854f897d" HarfBuzz_jll = "2e76f6c2-a576-52d4-95c1-20adfe4de566" +Meshes = "eacbb407-ea5a-433e-ab97-5258b1ca43fa" Reexport = "189a3867-3050-52da-a836-e630ba90ab69" StaticArrays = "90137ffa-7385-5640-81b9-e52037218182" StyledStrings = "f489334b-da3d-4c2e-b8f0-e476e12c162b" SwapStreams = "0b152c4a-7e29-418b-9258-223db38db9d9" +Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d" [compat] BinaryParsingTools = "0.1" @@ -29,6 +31,7 @@ Reexport = "1" StaticArrays = "1" StyledStrings = "1" SwapStreams = "0.2" +Unitful = "1.21.0" julia = "1.11" [extras] diff --git a/src/OpenType.jl b/src/OpenType.jl index c688553..726414b 100644 --- a/src/OpenType.jl +++ b/src/OpenType.jl @@ -12,6 +12,10 @@ using StaticArrays using Reexport using HarfBuzz_jll: libharfbuzz using .Meta: isexpr +using Meshes: Box +using Unitful: @u_str + +const cm = u"cm" const Vec = SVector const Vec2 = SVector{2,Float64} diff --git a/src/text.jl b/src/text.jl index 27ae4fa..d393b04 100644 --- a/src/text.jl +++ b/src/text.jl @@ -257,7 +257,7 @@ function segment_geometry(line::Line, segment::LineSegment) xmin, _ = line.positions[first(segment.indices)] width = sum(first, @view line.advances[segment.indices]; init = 0.0) xmax = xmin + width - Box(Point2(xmin, ymin), Point2(xmax, ymax)) + Box((xmin, ymin) .* cm, (xmax, ymax) .* cm) end function line_geometry(line::Line) @@ -267,7 +267,7 @@ function line_geometry(line::Line) ymax = ascender(line) width = sum(first, line.advances; init = 0.0) xmax = xmin + width - Box(Point2(xmin, ymin), Point2(xmax, ymax)) + Box((xmin, ymin) .* cm, (xmax, ymax) .* cm) end function has_outlines(line::Line, segment::LineSegment) diff --git a/test/runtests.jl b/test/runtests.jl index 4998e7f..659a17b 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,10 +1,10 @@ using OpenType, Test using OpenType: Text, lines, extract_style_from_text, CharacterStyle, hb_shape, Vec, Vec2, cm using BinaryParsingTools -using GeometryExperiments: Point2 using Accessors: @set, @reset using StyledStrings using Colors +using Meshes: Point, coords include("utils.jl") diff --git a/test/text.jl b/test/text.jl index 48e7fb0..c2b632a 100644 --- a/test/text.jl +++ b/test/text.jl @@ -73,9 +73,10 @@ @test sprint(show, MIME"text/plain"(), segment) isa String @test segment.indices == eachindex(t.chars) box = text_geometry(t, [font => options]) - @test box.min === Point2(0, 0) - @test 1.82 < box.max[1] < 1.83 - @test 0.096 < box.max[2] < 0.097 + @test box.min == Point(0, 0) + cs = coords(box.max) + @test 1.82cm < cs.x < 1.83cm + @test 0.096cm < cs.y < 0.097cm t = Text(styled"The {bold:brown} {red:fox {italic:jumps}} over the {italic:lazy} dog.", TextOptions()) box2 = text_geometry(t, [font => options])