GiovineItalia / Compose.jl

Declarative vector graphics
http://giovineitalia.github.io/Compose.jl/latest/
Other
248 stars 81 forks source link

fix line spacing for sub/superscripts #392

Closed bjarthur closed 4 years ago

bjarthur commented 4 years ago

fixes this problem:

julia> using Compose
[ Info: Precompiling Compose [a81c6b42-2e10-5240-aca2-a61377ecd94b]

julia> img = SVG("text.svg", 400px, 400px)
SVG(105.82010582010584mm, 105.82010582010584mm, IOStream(<file text.svg>), nothing, "img-a0c68168", 0, Compose.SVGPropertyFrame[], Dict{Type,Union{Nothing, Compose.Property}}(), OrderedCollections.OrderedDict{Compose.ClipPrimitive,String}(), Tuple{Compose.FormPrimitive,String}[], Set(AbstractString[]), false, true, "text.svg", true, "", false, 0, Set(AbstractString[]), Set(Tuple{AbstractString,AbstractString}[("Snap.svg", "Snap")]), AbstractString[], false, :none, ())

julia> c = compose(compose(context(),
                                  text(150px, 200px,
                                       "hello &amp; goodbye\nFoo<sub>Sub</sub>Bar<sup>Sup</sup>\nA Third Line\nFoo<sub>Sub</sub>Bar<sup>Sup</sup>Pooh\nAFourth Line\nA Fifth Line")),
                          fill("tomato"))
Context(Measures.BoundingBox{Tuple{Measures.Length{:w,Float64},Measures.Length{:h,Float64}},Tuple{Measures.Length{:w,Float64},Measures.Length{:h,Float64}}}((0.0w, 0.0h), (1.0w, 1.0h)), nothing, nothing, nothing, nothing, List([]), List([Compose.Form{Compose.TextPrimitive{Tuple{Measures.Length{:mm,Float64},Measures.Length{:mm,Float64}},Rotation{Tuple{Measures.Length{:w,Float64},Measures.Length{:h,Float64}}},Tuple{Measures.Length{:mm,Float64},Measures.Length{:mm,Float64}}}}(Compose.TextPrimitive{Tuple{Measures.Length{:mm,Float64},Measures.Length{:mm,Float64}},Rotation{Tuple{Measures.Length{:w,Float64},Measures.Length{:h,Float64}}},Tuple{Measures.Length{:mm,Float64},Measures.Length{:mm,Float64}}}[Compose.TextPrimitive{Tuple{Measures.Length{:mm,Float64},Measures.Length{:mm,Float64}},Rotation{Tuple{Measures.Length{:w,Float64},Measures.Length{:h,Float64}}},Tuple{Measures.Length{:mm,Float64},Measures.Length{:mm,Float64}}}((39.68253968253969mm, 52.91005291005292mm), "hello &amp; goodbye\nFoo<sub>Sub</sub>Bar<sup>Sup</sup>\nA Third Line\nFoo<sub>Sub</sub>Bar<sup>Sup</sup>Pooh\nAFourth Line\nA Fifth Line", Compose.HLeft(), Compose.VBottom(), Rotation{Tuple{Measures.Length{:w,Float64},Measures.Length{:h,Float64}}}(0.0, (0.5w, 0.5h)), (0.0mm, 0.0mm))], Symbol(""))]), List([Compose.Property{Compose.FillPrimitive}(Compose.FillPrimitive[Compose.FillPrimitive(RGBA{Float64}(1.0,0.38823529411764707,0.2784313725490196,1.0))])]), 0, false, false, false, false, nothing, nothing, 0.0, Symbol(""))

julia> draw(img, c)
false
Screen Shot 2020-03-24 at 8 40 36 PM
codecov-io commented 4 years ago

Codecov Report

Merging #392 into master will decrease coverage by 0.04%. The diff coverage is 30.23%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #392      +/-   ##
==========================================
- Coverage   43.05%   43.01%   -0.05%     
==========================================
  Files          18       18              
  Lines        3226     3229       +3     
==========================================
  Hits         1389     1389              
- Misses       1837     1840       +3
Impacted Files Coverage Δ
src/svg.jl 73.85% <100%> (-0.09%) :arrow_down:
src/fontfallback.jl 53.57% <28.57%> (+0.17%) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 1749b92...55ddc75. Read the comment docs.

bjarthur commented 4 years ago

this might be good to go. output now looks like this:

Screen Shot 2020-04-08 at 11 46 28 AM

moreover, the output is now identical irrespective of whether Fontconfig is imported or not. one caveat here is that to make them the same, the vertical shift specified by pango is now ignored because it is in absolute points, and seemingly it doesn't know the font size at that line in the code. so i changed it to use the same relative shift used by fontfallback, which is in "em" units.

also, to make sure that the output remains the same with or without Fontconfig i refactored the unit tests to run each example in a separate julia process. hard to test for this in the same session as once you've imported Fontconfig you can't unimport it.