diff options
author | Tor Andersson <tor@ghostscript.com> | 2004-10-21 10:51:08 +0200 |
---|---|---|
committer | Tor Andersson <tor@ghostscript.com> | 2004-10-21 10:51:08 +0200 |
commit | ded124f1cc463bac9e076146a4ffb77b8a370e0c (patch) | |
tree | c1b35fe12bd14ed507294b185587b428a92bcbef /tree/text.c | |
parent | 730cf84f6323b977bf7bcde1557d1803a16ad855 (diff) | |
download | mupdf-ded124f1cc463bac9e076146a4ffb77b8a370e0c.tar.xz |
rewrote resource dict handling
Diffstat (limited to 'tree/text.c')
-rw-r--r-- | tree/text.c | 64 |
1 files changed, 61 insertions, 3 deletions
diff --git a/tree/text.c b/tree/text.c index d822ec34..1832df9f 100644 --- a/tree/text.c +++ b/tree/text.c @@ -29,9 +29,67 @@ fz_freetextnode(fz_textnode *text) fz_rect fz_boundtextnode(fz_textnode *text, fz_matrix ctm) { - // FIXME convolve font bbox to all glyph x,y pairs - /* fz_rect bounds = fz_boundglyph(text->font, text->els[0], ctm); */ - return fz_infiniterect(); + fz_matrix trm; + fz_point ul, ur, ll, lr; + fz_rect bbox; + fz_rect fbox; + int i; + + if (text->len == 0) + return fz_infiniterect(); + + /* find bbox of glyph origins in ctm space */ + + bbox.min.x = bbox.max.x = text->els[0].x; + bbox.min.y = bbox.max.y = text->els[0].y; + + for (i = 1; i < text->len; i++) + { + bbox.min.x = MIN(bbox.min.x, text->els[i].x); + bbox.min.y = MIN(bbox.min.y, text->els[i].y); + bbox.max.x = MAX(bbox.max.x, text->els[i].x); + bbox.max.y = MAX(bbox.max.y, text->els[i].y); + } + + ll.x = bbox.min.x; ll.y = bbox.min.y; ll = fz_transformpoint(ctm, ll); + ul.x = bbox.min.x; ul.y = bbox.max.y; ul = fz_transformpoint(ctm, ul); + ur.x = bbox.max.x; ur.y = bbox.max.y; ur = fz_transformpoint(ctm, ur); + lr.x = bbox.max.x; lr.y = bbox.min.y; lr = fz_transformpoint(ctm, lr); + + bbox.min.x = MIN4(ll.x, ul.x, ur.x, lr.x); + bbox.min.y = MIN4(ll.y, ul.y, ur.y, lr.y); + bbox.max.x = MAX4(ll.x, ul.x, ur.x, lr.x); + bbox.max.y = MAX4(ll.y, ul.y, ur.y, lr.y); + + /* find bbox of font in trm * ctm space */ + + trm = fz_concat(text->trm, ctm); + trm.e = 0; + trm.f = 0; + + fbox.min.x = text->font->bbox.min.x * 0.001; + fbox.min.y = text->font->bbox.min.y * 0.001; + fbox.max.x = text->font->bbox.max.x * 0.001; + fbox.max.y = text->font->bbox.max.y * 0.001; + + ll.x = fbox.min.x; ll.y = fbox.min.y; ll = fz_transformpoint(trm, ll); + ul.x = fbox.min.x; ul.y = fbox.max.y; ul = fz_transformpoint(trm, ul); + ur.x = fbox.max.x; ur.y = fbox.max.y; ur = fz_transformpoint(trm, ur); + lr.x = fbox.max.x; lr.y = fbox.min.y; lr = fz_transformpoint(trm, lr); + + fbox.min.x = MIN4(ll.x, ul.x, ur.x, lr.x); + fbox.min.y = MIN4(ll.y, ul.y, ur.y, lr.y); + fbox.max.x = MAX4(ll.x, ul.x, ur.x, lr.x); + fbox.max.y = MAX4(ll.y, ul.y, ur.y, lr.y); + + bbox.min.x += MIN4(ll.x, ul.x, ur.x, lr.x); + bbox.min.y += MIN4(ll.y, ul.y, ur.y, lr.y); + bbox.max.x += MAX4(ll.x, ul.x, ur.x, lr.x); + bbox.max.y += MAX4(ll.y, ul.y, ur.y, lr.y); + +// printf("text [ %g %g %g %g ]\n", bbox.min.x, bbox.min.y, bbox.max.x, bbox.max.y); + + return bbox; } static fz_error * |