]> git.mdlowis.com Git - archive/tide-ocaml.git/commitdiff
tweaked draw_glyph to align proportional font glyphs
authorMichael D. Lowis <mike@mdlowis.com>
Wed, 13 Sep 2017 02:13:27 +0000 (22:13 -0400)
committerMichael D. Lowis <mike@mdlowis.com>
Wed, 13 Sep 2017 02:13:27 +0000 (22:13 -0400)
edit.ml
lib/x11_prims.c

diff --git a/edit.ml b/edit.ml
index 6b19d41b5d276a06da45c0ede79ac2250d44beff..97862d0e1effc480199117a20785a42540e17aac 100644 (file)
--- a/edit.ml
+++ b/edit.ml
@@ -1,7 +1,7 @@
 open X11
 
 (*let font = font_load "Times New Roman:pixelsize=14"*)
-let font = font_load "Liberation Mono:pixelsize=14"
+let font = font_load "Helvetica:pixelsize=48"
 
 let onfocus focused =
   print_endline "onfocus"
@@ -16,10 +16,11 @@ let onmousemove mods x y =
   print_endline "onmousemove"
 
 let onupdate width height =
+  let text = "FooBarBazYay" in
   Printf.printf "onupdate: %d %d\n" width height;
   draw_rect { x = 2; y = 2; w = width; h = height; c = Cfg.Color.palette.(0) };
-  draw_string font Cfg.Color.palette.(5) "FooBarBaz\tYay\r\n" (2,2);
-  draw_string font Cfg.Color.palette.(5) "FooBarBaz\tYay\r\n" (2,2+font.height);
+  draw_string font Cfg.Color.palette.(5) text (2,2);
+  draw_string font Cfg.Color.palette.(5) text (2,2+font.height);
   draw_rect { x = 2; y = 2; w = 1; h = font.height; c = Cfg.Color.palette.(3) };
   flip ()
 
index 9bcc87f07b0c4878fb8dd100b57bbe6b163bf559..0b228791af47f886279b340d747c6e441fc5e64f 100644 (file)
@@ -258,10 +258,16 @@ CAMLprim value x11_draw_glyph(value color, value glyph, value coord) {
     XftGlyphFontSpec spec = {
         .font  = font,
         .glyph = intfield(glyph,1),
-        .x     = intfield(coord,0),
+        .x     = intfield(coord,0) + intfield(glyph,4),
         .y     = intfield(coord,1) + font->ascent
     };
-    //printf("x: %d y: %d xoff: %d yoff: %d\n", spec.x, spec.y, intfield(glyph,6), intfield(glyph,7));
+    printf("c: '%c' w: %d x: %d y: %d xoff: %d yoff: %d\n",
+        intfield(glyph,2),
+        intfield(glyph,3),
+        intfield(glyph,4),
+        intfield(glyph,5),
+        intfield(glyph,6),
+        intfield(glyph,7));
     XftColor fgc;
     xftcolor(&fgc, Int_val(color));
     XftDrawGlyphFontSpec(X.xft, &fgc, &spec, 1);