]> git.mdlowis.com Git - archive/tide-ocaml.git/commitdiff
removed dead code and fixed types in x11.ml
authorMichael D. Lowis <mike.lowis@gentex.com>
Mon, 18 Dec 2017 14:24:31 +0000 (09:24 -0500)
committerMichael D. Lowis <mike.lowis@gentex.com>
Mon, 18 Dec 2017 14:24:31 +0000 (09:24 -0500)
lib/rope.ml
lib/x11.ml
lib/x11_prims.c

index a73e20cc81583e75abc16af0133b56978194f8c6..402a90022309ba76563adc294728d1b30f97bb77 100644 (file)
@@ -88,7 +88,7 @@ let get_rune rope i =
   else
     let byte = (getc rope i) in
     let len  = (utfseq byte) in
-    try decode rope (i + 1) len (byte land utf8_seqmask.(len))
+    try decode rope (i + 1) (len - 1) (byte land utf8_seqmask.(len))
     with _ -> (0xFFFD, i + 1)
 
 let rec each_rune_rec fn rope pos =
index c6ec306df4d04ec031ea84ae6d115d1561dcfef4..9b7e7343eddd276a87960c2e70a59c0a6d92a544 100644 (file)
@@ -1,7 +1,7 @@
 type xatom (* X interned atom *)
 type xwin (* X window identifier *)
-type xfont (* opaque type for xft font structure *)
-type xfontpatt (* opaque type for fontconfig font pattern structure *)
+type xfont (* opaque type for custom font caching structure *)
+type xftfont (* opaque type for xft font structure *)
 
 (* X event definitions *)
 type xevent =
@@ -40,7 +40,7 @@ type font = {
 }
 
 type glyph = {
-  font: xfont;
+  font: xftfont;
   index: int;
   rune: int;
   width: int;
@@ -110,68 +110,13 @@ external draw_glyph : int -> glyph -> (int * int) -> int
 let (font_cache : font option array) = Array.make 8 None
 let glyph_cache = Hashtbl.create 127
 
-
-(*
-let unbox = function
-| Some v -> v
-| None -> failwith "Expected some got none"
-
-let load_match font rune i =
-  Printf.printf "load_match %d %d\n" rune i;
-  (match font_cache.(i) with
-   | Some f -> font_unload f;
-   | None -> ());
-  let fmatch = (font_match font rune) in
-  Array.set font_cache i (Some fmatch);
-  font_glyph fmatch rune
-
-let rec get_cache_glyph font rune i =
-  if i < 8 then
-    match font_cache.(i) with
-    | None ->
-        load_match font rune i
-    | Some f ->
-        if font_hasglyph f rune then
-          font_glyph f rune
-        else
-          get_cache_glyph font rune (i + 1)
-  else
-    load_match font rune 7
-
-let clear_font_cache () =
-  print_endline "clearing cache";
-  let clear_entry i f = match f with
-    | Some f -> (if i > 0 then (font_unload f)); None
-    | None -> None
-  in Array.mapi clear_entry font_cache
-
-let rec get_font_glyph font rune =
-  match font_cache.(0) with
-  | None ->
-      print_endline "changing root font";
-      Array.set font_cache 0 (Some font);
-      font_glyph font rune
-  | Some f ->
-      if f != font then
-        (clear_font_cache (); get_font_glyph font rune)
-      else
-        get_cache_glyph font rune 0
-*)
-
-
-
-
 let cache_update rune glyph =
   Hashtbl.replace glyph_cache rune glyph;
   glyph
 
 let get_glyph (font : font) rune =
   try
-    let glyph = Hashtbl.find glyph_cache rune in
-    if (glyph.font != font.font) then
-      cache_update rune glyph
-    else
-      glyph
+    Hashtbl.find glyph_cache rune
   with Not_found ->
     cache_update rune (font_glyph font rune)
 
index 3c82d2bd0d15d389b67097555b059484edfc7dc2..8b9762e9615b6c7e3b8a04ba9403186b3e33e74a 100644 (file)
@@ -11,7 +11,10 @@ typedef struct XFont {
         FcFontSet* set;
         FcPattern* pattern;
     } base;
-    XftFont* cache[FontCacheSize];
+    struct {
+        XftFont* font;
+        uint32_t unicodep;
+    } cache[FontCacheSize];
     int ncached;
 } XFont;
 
@@ -245,50 +248,6 @@ CAMLprim value x11_font_load(value fontname) {
             Val_int(font->base.match->ascent + font->base.match->descent)));
 }
 
-/*
-CAMLprim value x11_font_unload(value font) {
-   CAMLparam1(font);
-    XftFontClose(X.display, (XftFont*)Field(font,0));
-    CAMLreturn(Val_unit);
-}
-
-CAMLprim value x11_font_match(value font, value rune) {
-    CAMLparam2(font, rune);
-
-    FcResult result;
-    XftFont* xftfont = (XftFont*)Field(font,0);
-
-    FcFontSet* fcsets[]  = { FcFontSort(0, xftfont->pattern, 1, 0, &result) };
-    FcPattern* fcpattern = FcPatternDuplicate(xftfont->pattern);
-    FcCharSet* fccharset = FcCharSetCreate();
-
-    FcCharSetAddChar(fccharset, rune);
-    FcPatternAddCharSet(fcpattern, FC_CHARSET, fccharset);
-    FcPatternAddBool(fcpattern, FC_SCALABLE, 1);
-    FcConfigSubstitute(0, fcpattern, FcMatchPattern);
-    FcDefaultSubstitute(fcpattern);
-
-    FcPattern* fcmatch = FcFontSetMatch(0, fcsets, 1, fcpattern, &result);
-    XftFont* newfont = XftFontOpenPattern(X.display, fcmatch);
-    //FcPatternPrint(newfont->pattern);
-    fprintf(stderr,"loading match\n");
-
-    FcFontSetDestroy(fcsets[0]);
-    FcPatternDestroy(fcpattern);
-    FcCharSetDestroy(fccharset);
-    FcPatternDestroy(fcmatch);
-
-    CAMLreturn( mkvariant(0, 2, newfont, Field(font,1)) );
-}
-
-CAMLprim value x11_font_hasglyph(value font, value rune) {
-    CAMLparam2(font, rune);
-    XftFont* xfont = (XftFont*)Field(font, 0);
-    int val = XftCharIndex(X.display, xfont, Int_val(rune));
-    CAMLreturn( Val_int(val > 0) );
-}
-*/
-
 void get_glyph(XFont* font, XftGlyphFontSpec* spec, uint32_t rune) {
     /* if the rune is in the base font, set it and return */
     FT_UInt glyphidx = XftCharIndex(X.display, font->base.match, rune);
@@ -299,11 +258,10 @@ void get_glyph(XFont* font, XftGlyphFontSpec* spec, uint32_t rune) {
     }
     /* Otherwise check the cache */
     for (int f = 0; f < font->ncached; f++) {
-        glyphidx = XftCharIndex(X.display, font->cache[f], rune);
+        glyphidx = XftCharIndex(X.display, font->cache[f].font, rune);
         /* Fond a suitable font or found a default font */
-        //if (glyphidx || (!glyphidx && font->cache[f]->unicodep == rune)) {
-        if (glyphidx) {
-            spec->font  = font->cache[f];
+        if (glyphidx || (!glyphidx && font->cache[f].unicodep == rune)) {
+            spec->font  = font->cache[f].font;
             spec->glyph = glyphidx;
             return;
         }
@@ -324,11 +282,12 @@ void get_glyph(XFont* font, XftGlyphFontSpec* spec, uint32_t rune) {
     /* add the font to the cache and use it */
     if (font->ncached >= FontCacheSize) {
         font->ncached = FontCacheSize - 1;
-        XftFontClose(X.display, font->cache[font->ncached]);
+        XftFontClose(X.display, font->cache[font->ncached].font);
     }
-    font->cache[font->ncached] = XftFontOpenPattern(X.display, fontmatch);
-    spec->glyph = XftCharIndex(X.display, font->cache[font->ncached], rune);
-    spec->font  = font->cache[font->ncached];
+    font->cache[font->ncached].font = XftFontOpenPattern(X.display, fontmatch);
+    font->cache[font->ncached].unicodep = rune;
+    spec->glyph = XftCharIndex(X.display, font->cache[font->ncached].font, rune);
+    spec->font  = font->cache[font->ncached].font;
     font->ncached++;
     FcPatternDestroy(fcpattern);
     FcCharSetDestroy(fccharset);