summaryrefslogtreecommitdiff
path: root/fitz/dev_draw.c
diff options
context:
space:
mode:
authorTor Andersson <tor@ghostscript.com>2010-01-07 01:18:52 +0100
committerTor Andersson <tor@ghostscript.com>2010-01-07 01:18:52 +0100
commitff2530fce783480d985a286bc8da3c3d001ed650 (patch)
tree6822864bc3fd609fa12157060e1f2a76535b3d0e /fitz/dev_draw.c
parent662c6a3a0fe8bd09e90b877095f52a062eb92f22 (diff)
downloadmupdf-ff2530fce783480d985a286bc8da3c3d001ed650.tar.xz
Render text.
Diffstat (limited to 'fitz/dev_draw.c')
-rw-r--r--fitz/dev_draw.c68
1 files changed, 65 insertions, 3 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)