From: Michael D. Lowis Date: Thu, 26 Oct 2017 01:53:49 +0000 (-0400) Subject: implemented scanning portion of scrollmap generation X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=df9f7ffad2e1b6a7222b4baefd5ee48a0028b1a8;p=archive%2Ftide-ocaml.git implemented scanning portion of scrollmap generation --- diff --git a/lib/draw.ml b/lib/draw.ml index 2e9d556..6cae7e6 100644 --- a/lib/draw.ml +++ b/lib/draw.ml @@ -25,9 +25,6 @@ module Cursor = struct csr.y <- csr.starty; csr - let place_glyph csr glyph = - let _ = X11.draw_glyph Cfg.Color.palette.(5) glyph (csr.x, csr.y) in () - let next_line csr = csr.x <- csr.startx; csr.y <- csr.y + font_height @@ -35,19 +32,32 @@ module Cursor = struct let has_next_line csr = ((csr.y + font_height) < csr.height) - let next_glyph csr c draw = - let glyph = (X11.get_glyph font c) in + let draw_tab csr = + let tabsz = ((X11.get_glyph font tabglyph).xoff * tabwidth) in + csr.x <- (csr.startx + ((csr.x - csr.startx + tabsz) / tabsz * tabsz)) + + let place_glyph csr glyph = + let xoff = (let open X11 in glyph.xoff) in + if (csr.x + xoff) > csr.width then (next_line csr); + let _ = X11.draw_glyph Cfg.Color.palette.(5) glyph (csr.x, csr.y) in + csr.x <- csr.x + xoff + + let draw_glyph csr c = match c with | 0x0A -> next_line csr | 0x0D -> () - | 0x09 -> - let tabsz = ((X11.get_glyph font tabglyph).xoff * tabwidth) in - csr.x <- (csr.startx + ((csr.x - csr.startx + tabsz) / tabsz * tabsz)) - | _ -> begin - if (csr.x + glyph.xoff) > csr.width then (next_line csr); - if draw then place_glyph csr glyph; - csr.x <- csr.x + glyph.xoff - end + | 0x09 -> draw_tab csr + | _ -> place_glyph csr (X11.get_glyph font c) + + let next_glyph csr c = + let glyph = (X11.get_glyph font c) in + match c with + | 0x0A -> next_line csr; true + | 0x0D -> false + | 0x09 -> draw_tab csr; false + | _ -> let nl = (if (csr.x + glyph.xoff) > csr.width then + (next_line csr; true) else false) in + csr.x <- csr.x + glyph.xoff; nl end open Cursor @@ -75,7 +85,7 @@ let vrule height csr = let buffer csr buf = let csr = (restart csr 2 0) in let draw_rune c = - next_glyph csr c true; + draw_glyph csr c; has_next_line csr in Buf.iter_from draw_rune buf (Buf.start buf) diff --git a/lib/draw.mli b/lib/draw.mli index 55501d8..11b70b7 100644 --- a/lib/draw.mli +++ b/lib/draw.mli @@ -2,10 +2,10 @@ module Cursor : sig type t val make : (int * int) -> int -> int -> t val restart : t -> int -> int -> t - val place_glyph : t -> X11.glyph -> unit val next_line : t -> unit val has_next_line : t -> bool - val next_glyph : t -> int -> bool -> unit + val draw_glyph : t -> int -> unit + val next_glyph : t -> int -> bool end val font : X11.font diff --git a/lib/scrollmap.ml b/lib/scrollmap.ml index d1a0e2b..d81b6a6 100644 --- a/lib/scrollmap.ml +++ b/lib/scrollmap.ml @@ -4,14 +4,13 @@ type t = { } let make buf width height off = + print_endline "\nfoo:"; let bol = (Rope.to_bol (Buf.rope buf) off) in let lines = ref [bol] in let csr = Draw.Cursor.make (width, 0) 0 0 in let process_glyph i c = - let open Draw.Cursor in - next_glyph csr c false; - (*if csr.startx == csr.x then - lines := i :: !lines;*) + if (Draw.Cursor.next_glyph csr c) then + lines := i :: !lines; ((Rope.is_eol (Buf.rope buf) i) == false) in Buf.iteri_from process_glyph buf off;