]> git.mdlowis.com Git - archive/tide-ocaml.git/commitdiff
implemented glyph retrieval primitive for loaded font
authorMichael D. Lowis <mike@mdlowis.com>
Tue, 12 Sep 2017 01:28:48 +0000 (21:28 -0400)
committerMichael D. Lowis <mike@mdlowis.com>
Tue, 12 Sep 2017 01:28:48 +0000 (21:28 -0400)
edit.ml
lib/x11.ml
lib/x11_prims.c

diff --git a/edit.ml b/edit.ml
index 40c16ea6d3b072438a6083b7a9b114beeca217a2..afbbe9b09938484750f652fea121798c4c1a8b55 100644 (file)
--- a/edit.ml
+++ b/edit.ml
@@ -34,8 +34,21 @@ let onevent = function
   | Update e         -> onupdate e.width e.height
   | Shutdown         -> onshutdown ()
 
+let test_glyph () =
+  let font = X11.font_load "Monaco:size=10" in
+  let glyph = X11.font_glyph font 0x30 in
+  Printf.printf "%d %d %d %d %d %d %d\n"
+    glyph.index
+    glyph.rune
+    glyph.width
+    glyph.x
+    glyph.y
+    glyph.xoff
+    glyph.yoff
+
 let () =
   let win = make_window 640 480 in
+  test_glyph ();
   show_window win true;
   event_loop 50 onevent
 
index ed7ed4a2e02ae91254f27dc8c15c24555141b84f..aab97343dc9fa1e970b76ee3e540ebe27dfc3ad5 100644 (file)
@@ -44,9 +44,14 @@ type font =
   }
 
 type glyph = {
+  font: xfont;
+  index: int;
   rune: int;
   width: int;
-  font: font;
+  x: int;
+  y: int;
+  xoff: int;
+  yoff: int;
 }
 
 external connect : unit -> unit
index 00f3ca68d97396b4598d476314fe928e17c16dda..cfb9ab97b0d1b510f03cc28b718168bd0e297581 100644 (file)
@@ -230,9 +230,26 @@ CAMLprim value x11_font_load(value fontname) {
     CAMLreturn(font);
 }
 
-CAMLprim value x11_font_glyph(value name) {
-    CAMLparam1(name);
-    CAMLreturn(Val_unit);
+CAMLprim value x11_font_glyph(value font, value rune) {
+    CAMLparam2(font, rune);
+    CAMLlocal1(glyph);
+    /* search for the rune in currently loaded fonts */
+    FcChar32 codept = Int_val(rune);
+    XftFont* xfont = (XftFont*)Field(font, 0);
+    FT_UInt glyphidx = XftCharIndex(X.display, xfont, codept);
+    XGlyphInfo extents;
+    XftTextExtents32 (X.display, xfont, &codept, 1, &extents);
+    /* create the glyph structure */
+    glyph = caml_alloc(8, 0);
+    Store_field(glyph, 0, (value)xfont);
+    Store_field(glyph, 1, Val_int(glyphidx));
+    Store_field(glyph, 2, rune);
+    Store_field(glyph, 3, Val_int(extents.width));
+    Store_field(glyph, 4, Val_int(extents.x));
+    Store_field(glyph, 5, Val_int(extents.y));
+    Store_field(glyph, 6, Val_int(extents.xOff));
+    Store_field(glyph, 7, Val_int(extents.yOff));
+    CAMLreturn(glyph);
 }
 
 /* X11 Event Handlers and Utilities