From 9b37144cf61878bc7d2878b08aa3f41cda759dca Mon Sep 17 00:00:00 2001 From: "Michael D. Lowis" Date: Tue, 12 Sep 2017 22:13:27 -0400 Subject: [PATCH] tweaked draw_glyph to align proportional font glyphs --- edit.ml | 7 ++++--- lib/x11_prims.c | 10 ++++++++-- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/edit.ml b/edit.ml index 6b19d41..97862d0 100644 --- 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 () diff --git a/lib/x11_prims.c b/lib/x11_prims.c index 9bcc87f..0b22879 100644 --- a/lib/x11_prims.c +++ b/lib/x11_prims.c @@ -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); -- 2.52.0