JuliaGraphics / FreeTypeAbstraction.jl

A Julian abstraction layer over FreeType.jl
Other
25 stars 20 forks source link

Fix character spacing in `renderstring!` #64

Closed ffreyer closed 2 years ago

ffreyer commented 2 years ago

Running

# render a string into an existing matrix
face = findfont("Dejavu Sans")
pixelsize = 64
x0, y0 = 2, 0
myarray = zeros(UInt8, pixelsize+2, 23pixelsize)
renderstring!(
    myarray, "0123456789qwertzuiopasdfghjklyxcvbnm,.-", face, pixelsize, 
    x0, y0, valign = :vtop
)

scene = Scene(resolution = (size(myarray, 2), size(myarray, 1)))
campixel!(scene)
heatmap!(scene, myarray'[:, end:-1:1], colormap = (:white, :black))
Makie.save("/home/frederic/Desktop/old.png", scene)

currently generates

old

because the horizontal bearings are applied in the wrong direction. With these changes I get

new

codecov[bot] commented 2 years ago

Codecov Report

Merging #64 (bf43e8c) into master (4db586e) will increase coverage by 0.33%. The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #64      +/-   ##
==========================================
+ Coverage   75.25%   75.58%   +0.33%     
==========================================
  Files           6        6              
  Lines         299      299              
==========================================
+ Hits          225      226       +1     
+ Misses         74       73       -1     
Impacted Files Coverage Δ
src/rendering.jl 93.15% <100.00%> (ø)
src/types.jl 67.96% <0.00%> (+0.97%) :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 4db586e...bf43e8c. Read the comment docs.

SimonDanisch commented 2 years ago

Interesting, that this creates some artifacts: image

ffreyer commented 2 years ago

I've noticed that too, but I don't think that's because of this change. If you look at x or v you can see artifacts in both, but they move a little between the two versions.

ffreyer commented 2 years ago

Saving just v from a 64px render with FileIO: v_fileio with Makie heatmap: v_makie

SimonDanisch commented 2 years ago

Interesting...

ffreyer commented 2 years ago

Oh right - that's because heatmaps are shifted by 0.5. Translating the plot to integer values removes these artifacts. new_shifted