From 11611dc48612218882171cd16e525eec888e00fb Mon Sep 17 00:00:00 2001 From: malc Date: Fri, 9 Jul 2010 13:23:56 +0400 Subject: [PATCH] Partial and flawed solution to rotation problem --- link.c | 56 ++++++++++++++++++++++++++++++++++++++++---------------- main.ml | 39 +++++++++++++++++++++++++++------------ 2 files changed, 67 insertions(+), 28 deletions(-) diff --git a/link.c b/link.c index bb1a860..99d4715 100644 --- a/link.c +++ b/link.c @@ -122,7 +122,7 @@ struct pagedim { int rotate; fz_rect box; fz_bbox bbox; - fz_matrix ctm; + fz_matrix ctm, ctm1; }; struct { @@ -538,6 +538,7 @@ static void layout (void) ctm = fz_identity (); ctm = fz_concat (ctm, fz_translate (0, -box.y1)); ctm = fz_concat (ctm, fz_scale (zoom, -zoom)); + memcpy (&p->ctm1, &ctm, sizeof (ctm)); ctm = fz_concat (ctm, fz_rotate (p->rotate)); p->bbox = fz_roundrect (fz_transformrect (ctm, box)); memcpy (&p->ctm, &ctm, sizeof (ctm)); @@ -640,6 +641,7 @@ static void search (regex_t *re, int pageno, int y, int forward) int ret; char *p; char buf[256]; + fz_matrix ctm; fz_error error; fz_obj *pageobj; fz_device *tdev; @@ -691,9 +693,11 @@ static void search (regex_t *re, int pageno, int y, int forward) if (error) die (error); + ctm = fz_rotate (pdim->rotate); + text = fz_newtextspan (); tdev = fz_newtextdevice (text); - error = pdf_runcontentstream (tdev, pdim->ctm, state.xref, + error = pdf_runcontentstream (tdev, pdim->ctm1, state.xref, drawpage->resources, drawpage->contents); if (error) die (error); @@ -758,29 +762,49 @@ static void search (regex_t *re, int pageno, int y, int forward) } } else { - fz_rect r; - - r.x0 = span->text[rm.rm_so].bbox.x0 - pdim->bbox.x0; - r.y0 = span->text[rm.rm_so].bbox.y0; - r.x1 = span->text[rm.rm_eo - 1].bbox.x1 - pdim->bbox.x0; - r.y1 = span->text[rm.rm_eo - 1].bbox.y1; + int xoff, yoff; + fz_bbox *sb, *eb; + fz_point p1, p2, p3, p4; + + xoff = -pdim->bbox.x0; + yoff = -pdim->bbox.y0; + + sb = &span->text[rm.rm_so].bbox; + eb = &span->text[rm.rm_eo - 1].bbox; + + p1.x = sb->x0; + p1.y = sb->y0; + p2.x = eb->x1; + p2.y = sb->y0; + p3.x = eb->x1; + p3.y = eb->y1; + p4.x = sb->x0; + p4.y = eb->y1; + + p1 = fz_transformpoint (ctm, p1); + p2 = fz_transformpoint (ctm, p2); + p3 = fz_transformpoint (ctm, p3); + p4 = fz_transformpoint (ctm, p4); if (!stop) { - printd (state.sock, "F %d %d %f %f %f %f", + printd (state.sock, "F %d %d %f %f %f %f %f %f %f %f", pageno, 1, - r.x0, r.y0, - r.x1, r.y1); + p1.x + xoff, p1.y + yoff, + p2.x + xoff, p2.y + yoff, + p3.x + xoff, p3.y + yoff, + p4.x + xoff, p4.y + yoff); - printd (state.sock, "T found at %d `%.*s' %f in %f sec", + printd (state.sock, "T found at %d `%.*s' in %f sec", pageno, rm.rm_eo - rm.rm_so, &buf[rm.rm_so], - span->text[0].bbox.y0 - drawpage->mediabox.y0, now () - start); } else { - printd (state.sock, "R %d %d %f %f %f %f", + printd (state.sock, "R %d %d %f %f %f %f %f %f %f %f", pageno, 2, - r.x0, r.y0, - r.x1, r.y1); + p1.x + xoff, p1.y + yoff, + p2.x + xoff, p2.y + yoff, + p3.x + xoff, p3.y + yoff, + p4.x + xoff, p4.y + yoff); } stop = 1; } diff --git a/main.ml b/main.ml index a921b2b..bdee6a4 100644 --- a/main.ml +++ b/main.ml @@ -100,6 +100,8 @@ type outlines = | Onarrow of outline array * outline array ;; +type rect = (float * float * float * float * float * float * float * float);; + type state = { mutable csock : Unix.file_descr ; mutable ssock : Unix.file_descr @@ -118,8 +120,8 @@ type state = ; mutable inflight : int ; mutable mstate : mstate ; mutable searchpattern : string - ; mutable rects : (int * int * Gl.point2 * Gl.point2) list - ; mutable rects1 : (int * int * Gl.point2 * Gl.point2) list + ; mutable rects : (int * int * rect) list + ; mutable rects1 : (int * int * rect) list ; mutable text : string ; mutable fullscreen : (int * int) option ; mutable textentry : textentry option @@ -127,6 +129,7 @@ type state = ; mutable outline : (bool * int * int * outline array * string) option ; mutable bookmarks : outline list ; mutable path : string + ; mutable sconty : float ; hists : hists } and hists = @@ -181,6 +184,7 @@ let state = ; outline = None ; bookmarks = [] ; path = "" + ; sconty = 0.0 ; hists = { nav = cbnew 100 0.0 ; pat = cbnew 20 "" @@ -534,21 +538,24 @@ let act cmd = Glut.swapBuffers (); | 'F' -> - let pageno, c, x0, y0, x1, y1 = - Scanf.sscanf cmd "F %d %d %f %f %f %f" - (fun p c x0 y0 x1 y1 -> (p, c, x0, y0, x1, y1)) + let pageno, c, x0, y0, x1, y1, x2, y2, x3, y3 = + Scanf.sscanf cmd "F %d %d %f %f %f %f %f %f %f %f" + (fun p c x0 y0 x1 y1 x2 y2 x3 y3 -> + (p, c, x0, y0, x1, y1, x2, y2, x3, y3)) in let y = (getpagey pageno) + truncate y0 in addnav (); gotoy y; - state.rects1 <- [pageno, c, (x0, y0), (x1, y1)] + state.rects1 <- [pageno, c, (x0, y0, x1, y1, x2, y2, x3, y3)] | 'R' -> - let pageno, c, x0, y0, x1, y1 = - Scanf.sscanf cmd "R %d %d %f %f %f %f" - (fun pageno c x0 y0 x1 y1 -> (pageno, c, x0, y0, x1, y1)) + let pageno, c, x0, y0, x1, y1, x2, y2, x3, y3 = + Scanf.sscanf cmd "R %d %d %f %f %f %f %f %f %f %f" + (fun p c x0 y0 x1 y1 x2 y2 x3 y3 -> + (p, c, x0, y0, x1, y1, x2, y2, x3, y3)) in - state.rects1 <- (pageno, c, (x0, y0), (x1, y1)) :: state.rects1 + state.rects1 <- + (pageno, c, (x0, y0, x1, y1, x2, y2, x3, y3)) :: state.rects1 | 'r' -> let n, w, h, r, p = @@ -1449,13 +1456,21 @@ let showrects () = GlDraw.color (0.0, 0.0, 1.0) ~alpha:0.5; GlFunc.blend_func `src_alpha `one_minus_src_alpha; List.iter - (fun (pageno, c, (x0, y0), (x1, y1)) -> + (fun (pageno, c, (x0, y0, x1, y1, x2, y2, x3, y3)) -> List.iter (fun l -> if l.pageno = pageno then ( let d = float (l.pagedispy - l.pagey) in GlDraw.color (0.0, 0.0, 1.0 /. float c) ~alpha:0.5; - GlDraw.rect (x0, y0 +. d) (x1, y1 +. d) + GlDraw.begins `quads; + ( + GlDraw.vertex2 (x0, y0+.d); + GlDraw.vertex2 (x1, y1+.d); + GlDraw.vertex2 (x2, y2+.d); + GlDraw.vertex2 (x3, y3+.d); + ); + GlDraw.ends (); + (* GlDraw.rect (x0, y0 +. d) (x1, y1 +. d) *) ) ) state.layout ) state.rects -- 2.11.4.GIT