summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTor Andersson <tor.andersson@artifex.com>2016-02-24 13:35:11 +0100
committerTor Andersson <tor.andersson@artifex.com>2016-02-24 13:41:56 +0100
commit07b0e5e758d77e6b9b3049e13cb386128be1592c (patch)
treec68e3d6d66ffc919ba751a83958d73b924e5849a
parenta76adb3dce6360d08aa5eeb7a23da50c3af81c10 (diff)
downloadmupdf-07b0e5e758d77e6b9b3049e13cb386128be1592c.tar.xz
Add fz_show_string function and move wmode argument to end.
-rw-r--r--include/mupdf/fitz/font.h2
-rw-r--r--include/mupdf/fitz/text.h3
-rw-r--r--platform/gl/gl-font.c4
-rw-r--r--source/fitz/font.c14
-rw-r--r--source/fitz/stext-device.c2
-rw-r--r--source/fitz/text.c22
-rw-r--r--source/html/html-layout.c12
-rw-r--r--source/pdf/pdf-appearance.c4
-rw-r--r--source/pdf/pdf-op-run.c4
-rw-r--r--source/xps/xps-glyphs.c2
10 files changed, 46 insertions, 23 deletions
diff --git a/include/mupdf/fitz/font.h b/include/mupdf/fitz/font.h
index ebd792e9..51aa201e 100644
--- a/include/mupdf/fitz/font.h
+++ b/include/mupdf/fitz/font.h
@@ -120,7 +120,7 @@ void fz_run_t3_glyph(fz_context *ctx, fz_font *font, int gid, const fz_matrix *t
void fz_decouple_type3_font(fz_context *ctx, fz_font *font, void *t3doc);
-float fz_advance_glyph(fz_context *ctx, fz_font *font, int glyph);
+float fz_advance_glyph(fz_context *ctx, fz_font *font, int glyph, int wmode);
int fz_encode_character(fz_context *ctx, fz_font *font, int unicode);
int fz_encode_character_with_fallback(fz_context *ctx, fz_font *font, int unicode, int script, fz_font **out_font);
diff --git a/include/mupdf/fitz/text.h b/include/mupdf/fitz/text.h
index 1a14fb83..2d96ce02 100644
--- a/include/mupdf/fitz/text.h
+++ b/include/mupdf/fitz/text.h
@@ -49,7 +49,8 @@ fz_text *fz_new_text(fz_context *ctx);
fz_text *fz_keep_text(fz_context *ctx, const fz_text *text);
void fz_drop_text(fz_context *ctx, const fz_text *text);
-void fz_show_glyph(fz_context *ctx, fz_text *text, fz_font *font, int wmode, const fz_matrix *trm, int glyph, int unicode);
+void fz_show_glyph(fz_context *ctx, fz_text *text, fz_font *font, const fz_matrix *trm, int glyph, int unicode, int wmode);
+void fz_show_string(fz_context *ctx, fz_text *text, fz_font *font, fz_matrix *trm, const char *s, int wmode);
fz_rect *fz_bound_text(fz_context *ctx, const fz_text *text, const fz_stroke_state *stroke, const fz_matrix *ctm, fz_rect *r);
fz_text *fz_clone_text(fz_context *ctx, const fz_text *text);
diff --git a/platform/gl/gl-font.c b/platform/gl/gl-font.c
index 94076eae..9756489e 100644
--- a/platform/gl/gl-font.c
+++ b/platform/gl/gl-font.c
@@ -239,14 +239,14 @@ static float ui_draw_glyph(fz_font *font, int gid, float x, float y)
glTexCoord2f(s1, t1); glVertex2f(xc + glyph->w, yc);
glTexCoord2f(s0, t1); glVertex2f(xc, yc);
- return fz_advance_glyph(ctx, font, gid) * g_font_size;
+ return fz_advance_glyph(ctx, font, gid, 0) * g_font_size;
}
float ui_measure_character(fz_context *ctx, int ucs)
{
fz_font *font;
int gid = fz_encode_character_with_fallback(ctx, g_font, ucs, 0, &font);
- return fz_advance_glyph(ctx, font, gid) * g_font_size;
+ return fz_advance_glyph(ctx, font, gid, 0) * g_font_size;
}
float ui_draw_character(fz_context *ctx, int ucs, float x, float y)
diff --git a/source/fitz/font.c b/source/fitz/font.c
index b3403229..db07e890 100644
--- a/source/fitz/font.c
+++ b/source/fitz/font.c
@@ -1378,7 +1378,7 @@ int fz_glyph_cacheable(fz_context *ctx, fz_font *font, int gid)
}
static float
-fz_advance_ft_glyph(fz_context *ctx, fz_font *font, int gid)
+fz_advance_ft_glyph(fz_context *ctx, fz_font *font, int gid, int wmode)
{
FT_Fixed adv;
int mask;
@@ -1392,8 +1392,8 @@ fz_advance_ft_glyph(fz_context *ctx, fz_font *font, int gid)
}
mask = FT_LOAD_NO_SCALE | FT_LOAD_NO_HINTING | FT_LOAD_IGNORE_TRANSFORM;
- /* if (font->wmode)
- mask |= FT_LOAD_VERTICAL_LAYOUT; */
+ if (wmode)
+ mask |= FT_LOAD_VERTICAL_LAYOUT;
fz_lock(ctx, FZ_LOCK_FREETYPE);
FT_Get_Advance(font->ft_face, gid, mask, &adv);
fz_unlock(ctx, FZ_LOCK_FREETYPE);
@@ -1409,10 +1409,12 @@ fz_advance_t3_glyph(fz_context *ctx, fz_font *font, int gid)
}
float
-fz_advance_glyph(fz_context *ctx, fz_font *font, int gid)
+fz_advance_glyph(fz_context *ctx, fz_font *font, int gid, int wmode)
{
if (font->ft_face)
{
+ if (wmode)
+ return fz_advance_ft_glyph(ctx, font, gid, 1);
if (gid >= 0 && gid < font->glyph_count && gid < MAX_ADVANCE_CACHE)
{
if (!font->advance_cache)
@@ -1420,12 +1422,12 @@ fz_advance_glyph(fz_context *ctx, fz_font *font, int gid)
int i;
font->advance_cache = fz_malloc_array(ctx, font->glyph_count, sizeof(float));
for (i = 0; i < font->glyph_count; ++i)
- font->advance_cache[i] = fz_advance_ft_glyph(ctx, font, i);
+ font->advance_cache[i] = fz_advance_ft_glyph(ctx, font, i, 0);
}
return font->advance_cache[gid];
}
- return fz_advance_ft_glyph(ctx, font, gid);
+ return fz_advance_ft_glyph(ctx, font, gid, 0);
}
if (font->t3procs)
return fz_advance_t3_glyph(ctx, font, gid);
diff --git a/source/fitz/stext-device.c b/source/fitz/stext-device.c
index 1decf5af..83bde371 100644
--- a/source/fitz/stext-device.c
+++ b/source/fitz/stext-device.c
@@ -800,7 +800,7 @@ fz_stext_extract(fz_context *ctx, fz_stext_device *dev, fz_text_span *span, cons
fz_concat(&trm, &tm, ctm);
/* Calculate bounding box and new pen position based on font metrics */
- adv = fz_advance_glyph(ctx, font, span->items[i].gid);
+ adv = fz_advance_glyph(ctx, font, span->items[i].gid, style->wmode);
/* Check for one glyph to many char mapping */
for (j = i + 1; j < span->len; j++)
diff --git a/source/fitz/text.c b/source/fitz/text.c
index 87aa2e79..735b3a5b 100644
--- a/source/fitz/text.c
+++ b/source/fitz/text.c
@@ -80,7 +80,7 @@ fz_grow_text_span(fz_context *ctx, fz_text_span *span, int n)
}
void
-fz_show_glyph(fz_context *ctx, fz_text *text, fz_font *font, int wmode, const fz_matrix *trm, int gid, int ucs)
+fz_show_glyph(fz_context *ctx, fz_text *text, fz_font *font, const fz_matrix *trm, int gid, int ucs, int wmode)
{
fz_text_span *span;
@@ -98,6 +98,26 @@ fz_show_glyph(fz_context *ctx, fz_text *text, fz_font *font, int wmode, const fz
span->len++;
}
+void
+fz_show_string(fz_context *ctx, fz_text *text, fz_font *user_font, fz_matrix *trm, const char *s, int wmode)
+{
+ fz_font *font;
+ int gid, ucs;
+ float adv;
+
+ while (*s)
+ {
+ s += fz_chartorune(&ucs, s);
+ gid = fz_encode_character_with_fallback(ctx, user_font, ucs, 0, &font);
+ fz_show_glyph(ctx, text, font, trm, gid, ucs, wmode);
+ adv = fz_advance_glyph(ctx, font, gid, wmode);
+ if (wmode == 0)
+ fz_pre_translate(trm, adv, 0);
+ else
+ fz_pre_translate(trm, 0, -adv);
+ }
+}
+
fz_rect *
fz_bound_text(fz_context *ctx, const fz_text *text, const fz_stroke_state *stroke, const fz_matrix *ctm, fz_rect *bbox)
{
diff --git a/source/html/html-layout.c b/source/html/html-layout.c
index c738ff21..2749587f 100644
--- a/source/html/html-layout.c
+++ b/source/html/html-layout.c
@@ -1274,7 +1274,7 @@ static void draw_flow_box(fz_context *ctx, fz_html *box, float page_top, float p
continue;
trm.e = *(float *)&p->x_offset;
trm.f = *(float *)&p->y_offset;
- fz_show_glyph(ctx, text, walker.font, 0, &trm, g->codepoint, c);
+ fz_show_glyph(ctx, text, walker.font, &trm, g->codepoint, c, 0);
break;
}
if (gp == walker.glyph_count)
@@ -1283,7 +1283,7 @@ static void draw_flow_box(fz_context *ctx, fz_html *box, float page_top, float p
* because we've been shaped away into another. We can't afford
* to just drop the codepoint as this will upset text extraction.
*/
- fz_show_glyph(ctx, text, walker.font, 0, &trm, -1, c);
+ fz_show_glyph(ctx, text, walker.font, &trm, -1, c, 0);
}
else
{
@@ -1297,7 +1297,7 @@ static void draw_flow_box(fz_context *ctx, fz_html *box, float page_top, float p
continue;
trm.e = *(float *)&p->x_offset;
trm.f = *(float *)&p->y_offset;
- fz_show_glyph(ctx, text, walker.font, 0, &trm, g->codepoint, -1);
+ fz_show_glyph(ctx, text, walker.font, &trm, g->codepoint, -1, 0);
}
}
idx += l;
@@ -1476,7 +1476,7 @@ static void draw_list_mark(fz_context *ctx, fz_html *box, float page_top, float
{
s += fz_chartorune(&c, s);
g = fz_encode_character_with_fallback(ctx, box->style.font, c, UCDN_SCRIPT_LATIN, &font);
- w += fz_advance_glyph(ctx, font, g) * box->em;
+ w += fz_advance_glyph(ctx, font, g, 0) * box->em;
}
s = buf;
@@ -1486,8 +1486,8 @@ static void draw_list_mark(fz_context *ctx, fz_html *box, float page_top, float
{
s += fz_chartorune(&c, s);
g = fz_encode_character_with_fallback(ctx, box->style.font, c, UCDN_SCRIPT_LATIN, &font);
- fz_show_glyph(ctx, text, font, 0, &trm, g, c);
- trm.e += fz_advance_glyph(ctx, font, g) * box->em;
+ fz_show_glyph(ctx, text, font, &trm, g, c, 0);
+ trm.e += fz_advance_glyph(ctx, font, g, 0) * box->em;
}
color[0] = box->style.color.r / 255.0f;
diff --git a/source/pdf/pdf-appearance.c b/source/pdf/pdf-appearance.c
index 5754c2e5..1ac3a68f 100644
--- a/source/pdf/pdf-appearance.c
+++ b/source/pdf/pdf-appearance.c
@@ -1908,8 +1908,8 @@ static void add_text(fz_context *ctx, font_info *font_rec, fz_text *text, char *
str += n;
str_len -= n;
gid = fz_encode_character(ctx, font, ucs);
- fz_show_glyph(ctx, text, font, 0, &tm, gid, ucs);
- tm.e += fz_advance_glyph(ctx, font, gid) * font_rec->da_rec.font_size;
+ fz_show_glyph(ctx, text, font, &tm, gid, ucs, 0);
+ tm.e += fz_advance_glyph(ctx, font, gid, 0) * font_rec->da_rec.font_size;
}
}
diff --git a/source/pdf/pdf-op-run.c b/source/pdf/pdf-op-run.c
index 0bd72b63..8c9f0639 100644
--- a/source/pdf/pdf-op-run.c
+++ b/source/pdf/pdf-op-run.c
@@ -943,11 +943,11 @@ pdf_show_char(fz_context *ctx, pdf_run_processor *pr, int cid)
fz_union_rect(&pr->text_bbox, &bbox);
/* add glyph to textobject */
- fz_show_glyph(ctx, pr->text, fontdesc->font, fontdesc->wmode, &trm, gid, ucsbuf[0]);
+ fz_show_glyph(ctx, pr->text, fontdesc->font, &trm, gid, ucsbuf[0], fontdesc->wmode);
/* add filler glyphs for one-to-many unicode mapping */
for (i = 1; i < ucslen; i++)
- fz_show_glyph(ctx, pr->text, fontdesc->font, fontdesc->wmode, &trm, -1, ucsbuf[i]);
+ fz_show_glyph(ctx, pr->text, fontdesc->font, &trm, -1, ucsbuf[i], fontdesc->wmode);
if (fontdesc->wmode == 0)
{
diff --git a/source/xps/xps-glyphs.c b/source/xps/xps-glyphs.c
index 689209cd..624276f8 100644
--- a/source/xps/xps-glyphs.c
+++ b/source/xps/xps-glyphs.c
@@ -450,7 +450,7 @@ xps_parse_glyphs_imp(fz_context *ctx, xps_document *doc, const fz_matrix *ctm,
tm.f = y - v_offset;
}
- fz_show_glyph(ctx, text, font, is_sideways, &tm, glyph_index, char_code);
+ fz_show_glyph(ctx, text, font, &tm, glyph_index, char_code, is_sideways);
x += advance * 0.01f * size;
}