From 0128b867966b3396b8e22f34f1263a7577c62e85 Mon Sep 17 00:00:00 2001 From: whitequark Date: Sat, 16 Apr 2016 01:47:57 +0000 Subject: [PATCH] Improve builtin vector font positioning. First, a larger origin offset is applied in ssglWriteText. This moves the text so that it doesn't overlap the workplane boundary. Second, a different offset is applied in ssglWriteTextRefCenter. After this, the middle stroke of "E" is vertically aligned with the reference point, and the overall label is horizontally aligned with the reference point more precisely. --- src/glhelper.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/glhelper.cpp b/src/glhelper.cpp index 9c6ba4a..9ad7ea3 100644 --- a/src/glhelper.cpp +++ b/src/glhelper.cpp @@ -78,9 +78,8 @@ void ssglWriteTextRefCenter(const std::string &str, double h, Vector t, Vector u t = t.Plus(u.ScaledBy(-fw/2)); t = t.Plus(v.ScaledBy(-fh/2)); - // Undo the (+5, +5) offset that ssglWriteText applies. - t = t.Plus(u.ScaledBy(-5*scale)); - t = t.Plus(v.ScaledBy(-5*scale)); + // Apply additional offset to get an exact center alignment. + t = t.Plus(v.ScaledBy(-18*scale)); ssglWriteText(str, h, t, u, v, fn, fndata); } @@ -153,7 +152,7 @@ void ssglWriteText(const std::string &str, double h, Vector t, Vector u, Vector v = v.WithMagnitude(1); double scale = FONT_SCALE(h) / SS.GW.scale; - Vector o = { 5.0, 5.0 }; + Vector o = { 15.0, 15.0 }; for(char32_t chr : ReadUTF8(str)) { const VectorGlyph &glyph = GetVectorGlyph(chr); o.x += ssglDrawCharacter(glyph, t, o, u, v, scale, fn, fndata);