diff options
author | Tor Andersson <tor@ghostscript.com> | 2010-01-07 01:18:52 +0100 |
---|---|---|
committer | Tor Andersson <tor@ghostscript.com> | 2010-01-07 01:18:52 +0100 |
commit | ff2530fce783480d985a286bc8da3c3d001ed650 (patch) | |
tree | 6822864bc3fd609fa12157060e1f2a76535b3d0e | |
parent | 662c6a3a0fe8bd09e90b877095f52a062eb92f22 (diff) | |
download | mupdf-ff2530fce783480d985a286bc8da3c3d001ed650.tar.xz |
Render text.
-rw-r--r-- | fitz/dev_draw.c | 68 | ||||
-rw-r--r-- | fitz/fitz_draw.h | 6 | ||||
-rw-r--r-- | fitz/fitz_res.h | 1 | ||||
-rw-r--r-- | fitz/node_text.c | 1 | ||||
-rw-r--r-- | fitz/res_font.c | 7 | ||||
-rw-r--r-- | fitzdraw/glyphcache.c | 19 | ||||
-rw-r--r-- | mupdf/pdf_build.c | 2 |
7 files changed, 81 insertions, 23 deletions
diff --git a/fitz/dev_draw.c b/fitz/dev_draw.c index 0719766d..92663a5c 100644 --- a/fitz/dev_draw.c +++ b/fitz/dev_draw.c @@ -1,5 +1,9 @@ #include "fitz.h" +#define QUANT(x,a) (((int)((x) * (a))) / (a)) +#define HSUBPIX 5.0 +#define VSUBPIX 5.0 + typedef struct fz_drawdevice_s fz_drawdevice; struct fz_drawdevice_s @@ -103,11 +107,51 @@ void fz_drawclippath(void *user, fz_path *path) printf("clippath\n"); } +static void drawglyph(unsigned char *argb, fz_pixmap *dst, fz_glyph *src, int xorig, int yorig) +{ + unsigned char *dp, *sp; + int w, h; + + int dx0 = dst->x; + int dy0 = dst->y; + int dx1 = dst->x + dst->w; + int dy1 = dst->y + dst->h; + + int x0 = xorig + src->x; + int y0 = yorig + src->y; + int x1 = x0 + src->w; + int y1 = y0 + src->h; + + int sx0 = 0; + int sy0 = 0; + int sx1 = src->w; + int sy1 = src->h; + + if (x1 <= dx0 || x0 >= dx1) return; + if (y1 <= dy0 || y0 >= dy1) return; + if (x0 < dx0) { sx0 += dx0 - x0; x0 = dx0; } + if (y0 < dy0) { sy0 += dy0 - y0; y0 = dy0; } + if (x1 > dx1) { sx1 += dx1 - x1; x1 = dx1; } + if (y1 > dy1) { sy1 += dy1 - y1; y1 = dy1; } + + sp = src->samples + (sy0 * src->w + sx0); + dp = dst->samples + ((y0 - dst->y) * dst->w + (x0 - dst->x)) * dst->n; + + w = sx1 - sx0; + h = sy1 - sy0; + + fz_text_w4i1o4(argb, sp, src->w, dp, dst->w * 4, w, h); +} + void fz_drawfilltext(void *user, fz_text *text, fz_colorspace *colorspace, float *color, float alpha) { fz_drawdevice *dev = user; unsigned char argb[7]; float rgb[3]; + fz_irect clip; + fz_matrix tm, trm; + fz_glyph glyph; + int i, x, y, gid; fz_convertcolor(colorspace, color, dev->model, rgb); argb[0] = alpha * 255; @@ -118,9 +162,27 @@ void fz_drawfilltext(void *user, fz_text *text, fz_colorspace *colorspace, float argb[5] = rgb[1] * 255; argb[6] = rgb[2] * 255; - printf("/%s setfont\n", text->font->name); - fz_debugtext(text, 0); - printf("show\n"); + clip.x0 = dev->dest->x; + clip.y0 = dev->dest->y; + clip.x1 = dev->dest->x + dev->dest->w; + clip.y1 = dev->dest->y + dev->dest->h; + + tm = text->trm; + + for (i = 0; i < text->len; i++) + { + gid = text->els[i].gid; + tm.e = text->els[i].x; + tm.f = text->els[i].y; + trm = fz_concat(tm, text->ctm); + x = fz_floor(trm.e); + y = fz_floor(trm.f); + trm.e = QUANT(trm.e - fz_floor(trm.e), HSUBPIX); + trm.f = QUANT(trm.f - fz_floor(trm.f), VSUBPIX); + + fz_renderglyph(dev->cache, &glyph, text->font, gid, trm); + drawglyph(argb, dev->dest, &glyph, x, y); + } } void fz_drawstroketext(void *user, fz_text *text, fz_colorspace *colorspace, float *color, float alpha) diff --git a/fitz/fitz_draw.h b/fitz/fitz_draw.h index e3dc75ee..9fb093b1 100644 --- a/fitz/fitz_draw.h +++ b/fitz/fitz_draw.h @@ -15,9 +15,9 @@ typedef struct fz_glyphcache_s fz_glyphcache; fz_device *fz_newdrawdevice(fz_colorspace *colorspace, fz_pixmap *dest); fz_glyphcache * fz_newglyphcache(int slots, int size); -fz_error fz_renderftglyph(fz_glyph *glyph, fz_font *font, int cid, fz_matrix trm); -fz_error fz_rendert3glyph(fz_glyph *glyph, fz_font *font, int cid, fz_matrix trm); -fz_error fz_renderglyph(fz_glyphcache*, fz_glyph*, fz_font*, int, fz_matrix); +void fz_renderftglyph(fz_glyph *glyph, fz_font *font, int cid, fz_matrix trm); +void fz_rendert3glyph(fz_glyph *glyph, fz_font *font, int cid, fz_matrix trm); +void fz_renderglyph(fz_glyphcache*, fz_glyph*, fz_font*, int, fz_matrix); void fz_debugglyphcache(fz_glyphcache *); void fz_freeglyphcache(fz_glyphcache *); diff --git a/fitz/fitz_res.h b/fitz/fitz_res.h index d6120fcd..5d789cd8 100644 --- a/fitz/fitz_res.h +++ b/fitz/fitz_res.h @@ -148,6 +148,7 @@ struct fz_text_s { fz_font *font; fz_matrix trm; + fz_matrix ctm; int len, cap; fz_textel *els; }; diff --git a/fitz/node_text.c b/fitz/node_text.c index d94f3de3..a21cb3fc 100644 --- a/fitz/node_text.c +++ b/fitz/node_text.c @@ -8,6 +8,7 @@ fz_newtext(fz_font *font) text = fz_malloc(sizeof(fz_text)); text->font = fz_keepfont(font); text->trm = fz_identity(); + text->ctm = fz_identity(); text->len = 0; text->cap = 0; text->els = nil; diff --git a/fitz/res_font.c b/fitz/res_font.c index 5eb33225..ade28f76 100644 --- a/fitz/res_font.c +++ b/fitz/res_font.c @@ -203,7 +203,7 @@ fz_newfontfrombuffer(fz_font **fontp, unsigned char *data, int len, int index) return fz_okay; } -fz_error +void fz_renderftglyph(fz_glyph *glyph, fz_font *font, int gid, fz_matrix trm) { FT_Face face = font->ftface; @@ -323,8 +323,6 @@ fz_renderftglyph(fz_glyph *glyph, fz_font *font, int gid, fz_matrix trm) glyph->samples[(glyph->h - y - 1) * glyph->w + x] = a; } } - - return fz_okay; } @@ -356,7 +354,7 @@ fz_newtype3font(char *name, fz_matrix matrix) /* XXX UGLY HACK XXX */ extern fz_colorspace *pdf_devicegray; -fz_error +void fz_rendert3glyph(fz_glyph *glyph, fz_font *font, int gid, fz_matrix trm) { #if 0 // XXX @@ -404,7 +402,6 @@ fz_rendert3glyph(fz_glyph *glyph, fz_font *font, int gid, fz_matrix trm) glyph->h = pixmap->h; glyph->samples = pixmap->samples; #endif - return fz_okay; } void diff --git a/fitzdraw/glyphcache.c b/fitzdraw/glyphcache.c index 776b3e4c..dd06d2d3 100644 --- a/fitzdraw/glyphcache.c +++ b/fitzdraw/glyphcache.c @@ -294,7 +294,7 @@ evictall(fz_glyphcache *arena) arena->used = 0; } -fz_error +void fz_renderglyph(fz_glyphcache *arena, fz_glyph *glyph, fz_font *font, int cid, fz_matrix ctm) { fz_error error; @@ -325,7 +325,7 @@ fz_renderglyph(fz_glyphcache *arena, fz_glyph *glyph, fz_font *font, int cid, fz ghits++; - return fz_okay; + return; } gmisses++; @@ -335,25 +335,22 @@ fz_renderglyph(fz_glyphcache *arena, fz_glyph *glyph, fz_font *font, int cid, fz if (font->ftface) { - error = fz_renderftglyph(glyph, font, cid, ctm); - if (error) - return error; + fz_renderftglyph(glyph, font, cid, ctm); } else if (font->t3procs) { - error = fz_rendert3glyph(glyph, font, cid, ctm); - if (error) - return error; + fz_rendert3glyph(glyph, font, cid, ctm); } else { - return fz_throw("uninitialized font structure"); + fz_warn("assert: uninitialized font structure"); + return; } size = glyph->w * glyph->h; if (size > arena->size / 6) - return fz_okay; + return; while (arena->load > arena->slots * 75 / 100) { @@ -381,7 +378,5 @@ fz_renderglyph(fz_glyphcache *arena, fz_glyph *glyph, fz_font *font, int cid, fz glyph->samples = val->samples; hashinsert(arena, &key, val); - - return fz_okay; } diff --git a/mupdf/pdf_build.c b/mupdf/pdf_build.c index 43593f12..cdf133de 100644 --- a/mupdf/pdf_build.c +++ b/mupdf/pdf_build.c @@ -274,6 +274,8 @@ pdf_flushtext(pdf_csi *csi) if (!csi->text) return; + csi->text->ctm = gstate->ctm; + switch (csi->textmode) { case 0: |