diff options
Diffstat (limited to 'source/fitz')
-rw-r--r-- | source/fitz/bidi.c | 94 | ||||
-rw-r--r-- | source/fitz/font.c | 2 | ||||
-rw-r--r-- | source/fitz/text.c | 22 |
3 files changed, 25 insertions, 93 deletions
diff --git a/source/fitz/bidi.c b/source/fitz/bidi.c index 74548d4d..979d2f1c 100644 --- a/source/fitz/bidi.c +++ b/source/fitz/bidi.c @@ -170,47 +170,11 @@ static fz_bidi_chartype class_from_ch_n(uint32_t ch) return from_ch_ws; } -static int -is_european_number(const uint32_t *str, unsigned int len) -{ - const uint32_t *end = str + len; - - for ( ; str != end; str++) - { - const uint32_t u = *str; - if ((u >= UNICODE_RTL_START && u < UNICODE_ARABIC_INDIC_DIGIT_ZERO) || - (u > UNICODE_ARABIC_INDIC_DIGIT_NINE && u < UNICODE_EXTENDED_ARABIC_INDIC_DIGIT_ZERO) || - (u > UNICODE_EXTENDED_ARABIC_INDIC_DIGIT_NINE && u <= UNICODE_RTL_END)) - { - /* This is just a normal RTL character or accent */ - return FALSE; - } - else if (!((u >= UNICODE_DIGIT_ZERO && u <= UNICODE_DIGIT_NINE) || - (u == UNICODE_SUPERSCRIPT_TWO) || - (u == UNICODE_SUPERSCRIPT_THREE) || - (u == UNICODE_SUPERSCRIPT_ONE) || - (u >= UNICODE_ARABIC_INDIC_DIGIT_ZERO && u <= UNICODE_ARABIC_INDIC_DIGIT_NINE) || - (u >= UNICODE_EXTENDED_ARABIC_INDIC_DIGIT_ZERO && u <= UNICODE_EXTENDED_ARABIC_INDIC_DIGIT_NINE) || - (u == UNICODE_SUPERSCRIPT_ZERO) || - (u >= UNICODE_SUPERSCRIPT_FOUR && u <= UNICODE_SUPERSCRIPT_NINE) || - (u >= UNICODE_SUBSCRIPT_ZERO && u <= UNICODE_SUBSCRIPT_NINE) || - (u >= UNICODE_CIRCLED_DIGIT_ONE && u <= UNICODE_NUMBER_TWENTY_FULL_STOP) || - (u == UNICODE_CIRCLED_DIGIT_ZERO) || - (u >= UNICODE_FULLWIDTH_DIGIT_ZERO && u <= UNICODE_FULLWIDTH_DIGIT_NINE) || - (u == UNICODE_ZERO_WIDTH_NON_JOINER))) - { - return FALSE; - } - } - return TRUE; -} - /* Split fragments into single scripts (or punctation + single script) */ static void split_at_script(const uint32_t *fragment, size_t fragment_len, - int block_r2l, - int char_r2l, + int level, void *arg, fz_bidi_fragment_callback *callback) { @@ -237,53 +201,17 @@ split_at_script(const uint32_t *fragment, else { /* Change of script. Break the fragment. */ - (*callback)(&fragment[script_start], i - script_start, block_r2l, char_r2l, script, arg); + (*callback)(&fragment[script_start], i - script_start, level, script, arg); script_start = i+1; script = s; } } if (script_start != fragment_len) { - (*callback)(&fragment[script_start], fragment_len - script_start, block_r2l, char_r2l, script, arg); + (*callback)(&fragment[script_start], fragment_len - script_start, level, script, arg); } } -static void -detect_numbers(const uint32_t *fragment, - size_t fragment_len, - size_t start, - size_t end, - const fz_bidi_level *levels, - void *arg, - fz_bidi_fragment_callback *callback) -{ - int block_r2l = ODD(levels[start]); - int char_r2l = block_r2l; - - /* Check to see if we've got a number. Numbers should - * never be block_r2l, so we can avoid the test. */ - if (block_r2l || !is_european_number(&fragment[start], end-start)) - { - /* No number, just split as normal */ - split_at_script(&fragment[start], - end-start, - block_r2l, - char_r2l, - arg, - callback); - return; - } - - /* We have a number. We have to check to see whether this - * should be handled as a block_r2l thing. */ - if (start != 0) - block_r2l = ODD(levels[start-1]); - if (block_r2l && end != fragment_len) - block_r2l = ODD(levels[end]); - - split_at_script(&fragment[start], end-start, block_r2l, char_r2l, arg, callback); -} - /* Determines the character classes for all following * passes of the algorithm. A character class is basically the type of Bidi * behaviour that the character exhibits. @@ -614,11 +542,9 @@ void fz_bidi_fragment_text(fz_context *ctx, * Create a text object for it, then start * a new fragment. */ - detect_numbers(text, - textlen, - startOfFragment, - i, - levels, + split_at_script(&text[startOfFragment], + i - startOfFragment, + levels[startOfFragment], arg, callback); startOfFragment = i; @@ -626,11 +552,9 @@ void fz_bidi_fragment_text(fz_context *ctx, } /* Now i == textlen. Deal with the final (or maybe only) fragment. */ /* otherwise create 1 fragment */ - detect_numbers(text, - textlen, - startOfFragment, - i, - levels, + split_at_script(&text[startOfFragment], + i - startOfFragment, + levels[startOfFragment], arg, callback); } diff --git a/source/fitz/font.c b/source/fitz/font.c index 1bac6efc..8f598be1 100644 --- a/source/fitz/font.c +++ b/source/fitz/font.c @@ -1442,6 +1442,8 @@ fz_encode_character(fz_context *ctx, fz_font *font, int ucs) return ucs; } +/* FIXME: This should take language too eventually, to allow for fonts where we can select different + * languages using opentype features. */ int fz_encode_character_with_fallback(fz_context *ctx, fz_font *user_font, int unicode, int script, fz_font **out_font) { 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); |