smallpond

Unnamed repository; edit this file 'description' to name the repository.
git clone git://git.nihaljere.xyz/smallpond
Log | Files | Refs | README | LICENSE

commit d733c9bfa76c787fd01a9b77ccb7040edf884e5a
parent b55eb2a29067ed6c8e7570043a57343f3b6988ae
Author: Nihal Jere <nihal@nihaljere.xyz>
Date:   Tue, 13 Dec 2022 01:11:12 -0600

consider glyph size when calculating glyph extents

this fixes grace note stem offsets

Diffstat:
Mmain.c | 5++++-
Msmallpond.lua | 10+++++-----
2 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/main.c b/main.c @@ -107,10 +107,13 @@ draw_glyph(lua_State *L) int glyph_extents(lua_State *L) { - unsigned int val = lua_tonumber(L, -1); + unsigned int val = lua_tonumber(L, -2); + double size = lua_tonumber(L, -1); unsigned int index = FT_Get_Char_Index(face, val); cairo_glyph_t glyph = {index, 0, 0}; cairo_text_extents_t extents; + cairo_set_font_face(cr, cface); + cairo_set_font_size(cr, size); cairo_glyph_extents(cr, &glyph, 1, &extents); lua_pushnumber(L, extents.width); diff --git a/smallpond.lua b/smallpond.lua @@ -491,7 +491,7 @@ local staff3ify = function(timing, el, staff) glyph = Glyph["noteheadBlack"] end - local w, h = glyph_extents(glyph) + local w, h = glyph_extents(glyph, glyphsize) local preoffset = 0 @@ -583,11 +583,11 @@ local staff3ify = function(timing, el, staff) -- flag if el.length == 8 and not el.beamgroup then if el.stemdir == 1 then - local fx, fy = glyph_extents(Glyph["flag8thDown"]) + local fx, fy = glyph_extents(Glyph["flag8thDown"], glyphsize) table.insert(staff3[staff], {kind="glyph", glyph=Glyph["flag8thDown"], size=glyphsize, x=altoffset + preoffset + rx, y=highheight + 3.5*em, time={start=stemstoptime}}) else -- TODO: move glyph extents to a precalculated table or something - local fx, fy = glyph_extents(Glyph["flag8thUp"]) + local fx, fy = glyph_extents(Glyph["flag8thUp"], glyphsize) table.insert(staff3[staff], {kind="glyph", glyph=Glyph["flag8thUp"], size=glyphsize, x=altoffset + el.stemx - .48, y=lowheight -.168*em - 3.5*em, time={start=stemstoptime}}) xdiff = xdiff + fx end @@ -685,7 +685,7 @@ for _, staff in pairs(stafforder) do extents[staff] = {xmin=0, ymin=0, xmax=0, ymax=0} for i, d in ipairs(items) do if d.kind == "glyph" then - local w, h = glyph_extents(d.glyph) + local w, h = glyph_extents(d.glyph, 32) if d.x - w < extents[staff].xmin then extents[staff].xmin = d.x - w elseif d.x + w > extents[staff].xmax then @@ -797,7 +797,7 @@ for i, staff in pairs(stafforder) do extent.yoff = yoff -- HACK: bring staffs closer together - yoff = yoff + extent.ymax - extent.ymin - 50 + yoff = yoff + extent.ymax - extent.ymin end -- draw beam (and adjust stems) after all previous notes already have set values