diff options
author | Tor Andersson <tor.andersson@artifex.com> | 2011-03-28 23:26:45 +0200 |
---|---|---|
committer | Tor Andersson <tor.andersson@artifex.com> | 2011-03-28 23:26:45 +0200 |
commit | 8fdbf5b37b59cb3a6df34ed1b81fe08cd9bcc8b9 (patch) | |
tree | e58b7e284cd0c1cd725adee7c0ccb92c5f521584 | |
parent | 5fc4bcb1f361a2b60e6841472afaf4a3cbd82ea8 (diff) | |
download | mupdf-8fdbf5b37b59cb3a6df34ed1b81fe08cd9bcc8b9.tar.xz |
xps: Draw Glyphs elements.
-rw-r--r-- | xps/xpsfont.c | 21 | ||||
-rw-r--r-- | xps/xpsglyphs.c | 110 | ||||
-rw-r--r-- | xps/xpspath.c | 8 |
3 files changed, 34 insertions, 105 deletions
diff --git a/xps/xpsfont.c b/xps/xpsfont.c index ecedfabb..e983df35 100644 --- a/xps/xpsfont.c +++ b/xps/xpsfont.c @@ -3,6 +3,7 @@ #include <ft2build.h> #include FT_FREETYPE_H +#include FT_ADVANCES_H int xps_count_font_encodings(fz_font *font) @@ -39,16 +40,12 @@ xps_encode_font_char(fz_font *font, int code) void xps_measure_font_glyph(xps_context_t *ctx, fz_font *font, int gid, xps_glyph_metrics_t *mtx) { - - int hadv, vadv, vorg; - int scale; - - scale = 1000; /* units-per-em */ - hadv = 500; - vadv = -1000; - vorg = 1000; - - mtx->hadv = hadv / (float) scale; - mtx->vadv = vadv / (float) scale; - mtx->vorg = vorg / (float) scale; + int mask = FT_LOAD_NO_BITMAP | FT_LOAD_NO_HINTING | FT_LOAD_IGNORE_TRANSFORM; + FT_Fixed adv; + + FT_Set_Char_Size(font->ftface, 64, 64, 72, 72); + FT_Get_Advance(font->ftface, gid, mask, &adv); + mtx->hadv = adv / 65536.0f; + mtx->vadv = -1000 / 1000.0f; + mtx->vorg = 880 / 1000.0f; } diff --git a/xps/xpsglyphs.c b/xps/xpsglyphs.c index 29ab1e02..c7431440 100644 --- a/xps/xpsglyphs.c +++ b/xps/xpsglyphs.c @@ -3,18 +3,6 @@ #include <ctype.h> /* for tolower() */ -#define XPS_TEXT_BUFFER_SIZE 300 - -typedef struct xps_text_buffer_s xps_text_buffer_t; - -struct xps_text_buffer_s -{ - int count; - float x[XPS_TEXT_BUFFER_SIZE + 1]; - float y[XPS_TEXT_BUFFER_SIZE + 1]; - int g[XPS_TEXT_BUFFER_SIZE]; -}; - static inline int unhex(int i) { if (isdigit(i)) @@ -98,60 +86,6 @@ xps_select_best_font_encoding(fz_font *font) } /* - * Call text drawing primitives. - */ - -static void -xps_flush_text_buffer(xps_context_t *ctx, fz_font *font, - xps_text_buffer_t *buf, int is_charpath) -{ -#if 0 - gs_text_params_t params; - gs_text_enum_t *textenum; - float x = buf->x[0]; - float y = buf->y[0]; - int code; - int i; - - // dprintf1("flushing text buffer (%d glyphs)\n", buf->count); - gs_moveto(ctx->pgs, x, y); - - params.operation = TEXT_FROM_GLYPHS | TEXT_REPLACE_WIDTHS; - if (is_charpath) - params.operation |= TEXT_DO_FALSE_CHARPATH; - else - params.operation |= TEXT_DO_DRAW; - params.data.glyphs = buf->g; - params.size = buf->count; - params.x_widths = buf->x + 1; - params.y_widths = buf->y + 1; - params.widths_size = buf->count; - - for (i = 0; i < buf->count; i++) - { - buf->x[i] = buf->x[i] - x; - buf->y[i] = buf->y[i] - y; - x += buf->x[i]; - y += buf->y[i]; - } - buf->x[buf->count] = 0; - buf->y[buf->count] = 0; - - code = gs_text_begin(ctx->pgs, ¶ms, ctx->memory, &textenum); - if (code != 0) - return fz_throw("cannot gs_text_begin() (%d)", code); - - code = gs_text_process(textenum); - - if (code != 0) - return fz_throw("cannot gs_text_process() (%d)", code); - - gs_text_release(textenum, "gslt font render"); -#endif - buf->count = 0; -} - -/* * Parse and draw an XPS <Glyphs> element. * * Indices syntax: @@ -238,20 +172,18 @@ xps_parse_glyph_metrics(char *s, float *advance, float *uofs, float *vofs) * Calculate metrics for positioning. */ static void -xps_parse_glyphs_imp(xps_context_t *ctx, fz_font *font, float size, +xps_parse_glyphs_imp(xps_context_t *ctx, fz_matrix ctm, fz_font *font, float size, float originx, float originy, int is_sideways, int bidi_level, char *indices, char *unicode, int is_charpath) { - xps_text_buffer_t buf; xps_glyph_metrics_t mtx; + float e, f; float x = originx; float y = originy; char *us = unicode; char *is = indices; int un = 0; - buf.count = 0; - if (!unicode && !indices) return; @@ -262,6 +194,8 @@ xps_parse_glyphs_imp(xps_context_t *ctx, fz_font *font, float size, un = strlen(us); } + ctx->text = fz_newtext(font, fz_scale(size, -size), is_sideways); + while ((us && un > 0) || (is && *is)) { int code_count = 1; @@ -332,32 +266,23 @@ xps_parse_glyphs_imp(xps_context_t *ctx, fz_font *font, float size, u_offset = u_offset * 0.01 * size; v_offset = v_offset * 0.01 * size; - if (buf.count == XPS_TEXT_BUFFER_SIZE) - { - xps_flush_text_buffer(ctx, font, &buf, is_charpath); - } - if (is_sideways) { - buf.x[buf.count] = x + u_offset + (mtx.vorg * size); - buf.y[buf.count] = y - v_offset + (mtx.hadv * 0.5 * size); + e = x + u_offset + (mtx.vorg * size); + f = y - v_offset + (mtx.hadv * 0.5 * size); } else { - buf.x[buf.count] = x + u_offset; - buf.y[buf.count] = y - v_offset; + e = x + u_offset; + f = y - v_offset; } - buf.g[buf.count] = glyph_index; - buf.count ++; + + fz_addtext(ctx->text, glyph_index, char_code, e, f); + // TODO: cluster mapping x += advance * 0.01 * size; } } - - if (buf.count > 0) - { - xps_flush_text_buffer(ctx, font, &buf, is_charpath); - } } void @@ -556,10 +481,15 @@ xps_parse_glyphs(xps_context_t *ctx, fz_matrix ctm, samples[0] = atof(fill_opacity_att); xps_set_color(ctx, colorspace, samples); - xps_parse_glyphs_imp(ctx, font, font_size, + xps_parse_glyphs_imp(ctx, ctm, font, font_size, atof(origin_x_att), atof(origin_y_att), is_sideways, bidi_level, indices_att, unicode_att, 0); + + ctx->dev->filltext(ctx->dev->user, ctx->text, ctm, + ctx->colorspace, ctx->color, ctx->alpha); + fz_freetext(ctx->text); + ctx->text = nil; } /* @@ -568,14 +498,10 @@ xps_parse_glyphs(xps_context_t *ctx, fz_matrix ctm, if (fill_tag) { - fz_warn("glyphs filled with general brushes not implemented!"); -#if 0 - ctx->fill_rule = 1; /* always use non-zero winding rule for char paths */ - xps_parse_glyphs_imp(ctx, font, font_size, + xps_parse_glyphs_imp(ctx, ctm, font, font_size, atof(origin_x_att), atof(origin_y_att), is_sideways, bidi_level, indices_att, unicode_att, 1); xps_parse_brush(ctx, ctm, fill_uri, dict, fill_tag); -#endif } xps_end_opacity(ctx, opacity_mask_uri, dict, opacity_att, opacity_mask_tag); diff --git a/xps/xpspath.c b/xps/xpspath.c index 78925a8b..bc1d3e34 100644 --- a/xps/xpspath.c +++ b/xps/xpspath.c @@ -44,9 +44,15 @@ xps_clip(xps_context_t *ctx, fz_matrix ctm) fz_freepath(ctx->path); ctx->path = NULL; } + else if (ctx->text) + { + ctx->dev->cliptext(ctx->dev->user, ctx->text, ctm, 0); + fz_freetext(ctx->text); + ctx->text = nil; + } else { - printf("clip not a path! (maybe a glyph, or image?)\n"); + fz_warn("clip not a path nor text"); } } |