summaryrefslogtreecommitdiff
path: root/source/fitz/text.c
diff options
context:
space:
mode:
authorRobin Watts <Robin.Watts@artifex.com>2016-03-02 08:03:53 -0800
committerRobin Watts <robin.watts@artifex.com>2016-03-11 11:57:48 +0000
commita3785935df081674d048655048984bcba09f8387 (patch)
tree31f6a63292d9f3d11be9c4b7003001c700b9b3c5 /source/fitz/text.c
parentc5b80367dfcd3d3df09068b7f31119a400cfe241 (diff)
downloadmupdf-a3785935df081674d048655048984bcba09f8387.tar.xz
Rejig Bidirectional and Text code.
We move to using bidirectional "levels" throughout. This should give us better behaviour vis-a-vis nested l2r/l2r text. This also allows us to carry xps levels throughout with no loss of information. This also avoids the need to special case numbers. We accordingly carry more information into fz_text. As well as wmode, also hold additional details about the text spans. We now include the directionality of the bidi level text (either as derived from bidi code, or from the original document (e.g. xps)), the directionality of text (as specified in the original document (e.g. html)), and the language of the text (if specified in the original document).
Diffstat (limited to 'source/fitz/text.c')
-rw-r--r--source/fitz/text.c22
1 files changed, 14 insertions, 8 deletions
diff --git a/source/fitz/text.c b/source/fitz/text.c
index 735b3a5b..29a4506e 100644
--- a/source/fitz/text.c
+++ b/source/fitz/text.c
@@ -37,11 +37,14 @@ fz_drop_text(fz_context *ctx, const fz_text *textc)
}
static fz_text_span *
-fz_new_text_span(fz_context *ctx, fz_font *font, int wmode, const fz_matrix *trm)
+fz_new_text_span(fz_context *ctx, fz_font *font, int wmode, int bidi_level, fz_text_direction markup_dir, fz_text_language language, const fz_matrix *trm)
{
fz_text_span *span = fz_malloc_struct(ctx, fz_text_span);
span->font = fz_keep_font(ctx, font);
span->wmode = wmode;
+ span->bidi_level = bidi_level;
+ span->markup_dir = markup_dir;
+ span->language = language;
span->trm = *trm;
span->trm.e = 0;
span->trm.f = 0;
@@ -49,20 +52,23 @@ fz_new_text_span(fz_context *ctx, fz_font *font, int wmode, const fz_matrix *trm
}
static fz_text_span *
-fz_add_text_span(fz_context *ctx, fz_text *text, fz_font *font, int wmode, const fz_matrix *trm)
+fz_add_text_span(fz_context *ctx, fz_text *text, fz_font *font, int wmode, int bidi_level, fz_text_direction markup_dir, fz_text_language language, const fz_matrix *trm)
{
if (!text->tail)
{
- text->head = text->tail = fz_new_text_span(ctx, font, wmode, trm);
+ text->head = text->tail = fz_new_text_span(ctx, font, wmode, bidi_level, markup_dir, language, trm);
}
else if (text->tail->font != font ||
text->tail->wmode != wmode ||
+ text->tail->bidi_level != bidi_level ||
+ text->tail->markup_dir != markup_dir ||
+ text->tail->language != language ||
text->tail->trm.a != trm->a ||
text->tail->trm.b != trm->b ||
text->tail->trm.c != trm->c ||
text->tail->trm.d != trm->d)
{
- text->tail = text->tail->next = fz_new_text_span(ctx, font, wmode, trm);
+ text->tail = text->tail->next = fz_new_text_span(ctx, font, wmode, bidi_level, markup_dir, language, trm);
}
return text->tail;
}
@@ -80,14 +86,14 @@ 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, const fz_matrix *trm, int gid, int ucs, int wmode)
+fz_show_glyph(fz_context *ctx, fz_text *text, fz_font *font, const fz_matrix *trm, int gid, int ucs, int wmode, int bidi_level, fz_text_direction markup_dir, fz_text_language lang)
{
fz_text_span *span;
if (text->refs != 1)
fz_throw(ctx, FZ_ERROR_GENERIC, "cannot modify shared text objects");
- span = fz_add_text_span(ctx, text, font, wmode, trm);
+ span = fz_add_text_span(ctx, text, font, wmode, bidi_level, markup_dir, lang, trm);
fz_grow_text_span(ctx, span, 1);
@@ -99,7 +105,7 @@ fz_show_glyph(fz_context *ctx, fz_text *text, fz_font *font, const fz_matrix *tr
}
void
-fz_show_string(fz_context *ctx, fz_text *text, fz_font *user_font, fz_matrix *trm, const char *s, int wmode)
+fz_show_string(fz_context *ctx, fz_text *text, fz_font *user_font, fz_matrix *trm, const char *s, int wmode, int bidi_level, fz_text_direction markup_dir, fz_text_language language)
{
fz_font *font;
int gid, ucs;
@@ -109,7 +115,7 @@ fz_show_string(fz_context *ctx, fz_text *text, fz_font *user_font, fz_matrix *tr
{
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);
+ fz_show_glyph(ctx, text, font, trm, gid, ucs, wmode, bidi_level, markup_dir, language);
adv = fz_advance_glyph(ctx, font, gid, wmode);
if (wmode == 0)
fz_pre_translate(trm, adv, 0);