From a45b3a21c67476c703ddd5d5b4755364671c26c1 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Tue, 5 Apr 2016 12:31:26 +0200 Subject: Clean up bidi enum names. And use the same enum for both the internal bidi code and the layout code. --- source/fitz/bidi-impl.h | 8 ++++++++ source/fitz/bidi.c | 22 +++++++++++----------- source/fitz/text.c | 8 ++++---- source/html/html-layout.c | 28 +++++++++++----------------- source/pdf/pdf-appearance.c | 2 +- source/pdf/pdf-op-run.c | 4 ++-- source/tools/murun.c | 4 ++-- source/xps/xps-glyphs.c | 2 +- 8 files changed, 40 insertions(+), 38 deletions(-) (limited to 'source') diff --git a/source/fitz/bidi-impl.h b/source/fitz/bidi-impl.h index 0de3458b..e9a5b3b4 100644 --- a/source/fitz/bidi-impl.h +++ b/source/fitz/bidi-impl.h @@ -64,6 +64,14 @@ enum BDI_N = BDI_ON /* alias, where ON, WS and S are treated the same */ }; +typedef int fz_bidi_level; /* Note: Max level is 125 */ +typedef uint8_t fz_bidi_chartype; + +enum +{ + BIDI_LEVEL_MAX = 125 /* Updated for 6.3.0 */ +}; + void fz_bidi_resolve_neutrals(fz_bidi_level baselevel, fz_bidi_chartype *pcls, const fz_bidi_level *plevel, int cch); void fz_bidi_resolve_implicit(const fz_bidi_chartype *pcls, fz_bidi_level *plevel, int cch); void fz_bidi_resolve_weak(fz_context *ctx, fz_bidi_level baselevel, fz_bidi_chartype *pcls, fz_bidi_level *plevel, int cch); diff --git a/source/fitz/bidi.c b/source/fitz/bidi.c index 979d2f1c..1fda5656 100644 --- a/source/fitz/bidi.c +++ b/source/fitz/bidi.c @@ -274,15 +274,15 @@ static fz_bidi_level base_level_from_text(fz_bidi_chartype *types, int len) { /* strong left */ case BDI_L: - return BIDI_LEFT_TO_RIGHT; + return FZ_BIDI_LTR; /* strong right */ case BDI_R: case BDI_AL: - return BIDI_RIGHT_TO_LEFT; + return FZ_BIDI_RTL; } } - return BIDI_LEFT_TO_RIGHT; + return FZ_BIDI_LTR; } static fz_bidi_direction direction_from_type(fz_bidi_chartype type) @@ -291,14 +291,14 @@ static fz_bidi_direction direction_from_type(fz_bidi_chartype type) { case BDI_L: case BDI_EN: - return BIDI_LEFT_TO_RIGHT; + return FZ_BIDI_LTR; case BDI_R: case BDI_AL: - return BIDI_RIGHT_TO_LEFT; + return FZ_BIDI_RTL; default: - return BIDI_NEUTRAL; + return FZ_BIDI_NEUTRAL; } } @@ -320,11 +320,11 @@ classify_quoted_blocks(const uint32_t *text, { switch (direction_from_type(types[i])) { - case BIDI_LEFT_TO_RIGHT: + case FZ_BIDI_LTR: ltrFound = TRUE; break; - case BIDI_RIGHT_TO_LEFT: + case FZ_BIDI_RTL: rtlFound = TRUE; break; @@ -428,13 +428,13 @@ create_levels(fz_context *ctx, classify_characters(text, types, len, flags); - if (*baseDir != BIDI_LEFT_TO_RIGHT && *baseDir != BIDI_RIGHT_TO_LEFT) + if (*baseDir != FZ_BIDI_LTR && *baseDir != FZ_BIDI_RTL) { /* Derive the base level from the text and * update *baseDir in case the caller wants to know. */ baseLevel = base_level_from_text(types, len); - *baseDir = ODD(baseLevel)==1 ? BIDI_RIGHT_TO_LEFT : BIDI_LEFT_TO_RIGHT; + *baseDir = ODD(baseLevel)==1 ? FZ_BIDI_RTL : FZ_BIDI_LTR; } else { @@ -453,7 +453,7 @@ create_levels(fz_context *ctx, { if (text[i]=='\t') { - types[i] = (*baseDir == BIDI_RIGHT_TO_LEFT) ? BDI_R : BDI_L; + types[i] = (*baseDir == FZ_BIDI_RTL) ? BDI_R : BDI_L; } } } diff --git a/source/fitz/text.c b/source/fitz/text.c index 512c671c..76838fe8 100644 --- a/source/fitz/text.c +++ b/source/fitz/text.c @@ -37,7 +37,7 @@ 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, int bidi_level, fz_text_direction markup_dir, fz_text_language language, const fz_matrix *trm) +fz_new_text_span(fz_context *ctx, fz_font *font, int wmode, int bidi_level, fz_bidi_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); @@ -52,7 +52,7 @@ fz_new_text_span(fz_context *ctx, fz_font *font, int wmode, int bidi_level, fz_t } static fz_text_span * -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) +fz_add_text_span(fz_context *ctx, fz_text *text, fz_font *font, int wmode, int bidi_level, fz_bidi_direction markup_dir, fz_text_language language, const fz_matrix *trm) { if (!text->tail) { @@ -86,7 +86,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, const fz_matrix *trm, int gid, int ucs, int wmode, int bidi_level, fz_text_direction markup_dir, fz_text_language lang) +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_bidi_direction markup_dir, fz_text_language lang) { fz_text_span *span; @@ -105,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, int bidi_level, fz_text_direction markup_dir, fz_text_language language) +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_bidi_direction markup_dir, fz_text_language language) { fz_font *font; int gid, ucs; diff --git a/source/html/html-layout.c b/source/html/html-layout.c index 140577fd..bbd8a161 100644 --- a/source/html/html-layout.c +++ b/source/html/html-layout.c @@ -108,7 +108,7 @@ static fz_html_flow *add_flow(fz_context *ctx, fz_pool *pool, fz_html *top, fz_c flow->type = type; flow->expand = 0; flow->bidi_level = 0; - flow->markup_dir = FZ_DIR_UNSET; + flow->markup_dir = FZ_BIDI_NEUTRAL; flow->breaks_line = 0; flow->style = style; *top->flow_tail = flow; @@ -390,7 +390,7 @@ static void init_box(fz_context *ctx, fz_html *box) box->flow_head = NULL; box->flow_tail = &box->flow_head; - box->flow_dir = FZ_DIR_UNSET; + box->flow_dir = FZ_BIDI_NEUTRAL; fz_default_css_style(ctx, &box->style); } @@ -641,7 +641,7 @@ typedef struct string_walker { fz_context *ctx; hb_buffer_t *hb_buf; - int r2l; + int rtl; const char *start; const char *end; const char *s; @@ -700,11 +700,11 @@ static int quick_ligature(fz_context *ctx, string_walker *walker, unsigned int i return walker->glyph_info[i].codepoint; } -static void init_string_walker(fz_context *ctx, string_walker *walker, hb_buffer_t *hb_buf, int r2l, fz_font *font, int script, const char *text) +static void init_string_walker(fz_context *ctx, string_walker *walker, hb_buffer_t *hb_buf, int rtl, fz_font *font, int script, const char *text) { walker->ctx = ctx; walker->hb_buf = hb_buf; - walker->r2l = r2l; + walker->rtl = rtl; walker->start = text; walker->end = text; walker->s = text; @@ -747,7 +747,7 @@ static int walk_string(string_walker *walker) /* Disable harfbuzz shaping if script is common or LGC and there are no opentype tables. */ quickshape = 0; - if (walker->script <= 3 && !walker->r2l && !walker->font->has_opentype) + if (walker->script <= 3 && !walker->rtl && !walker->font->has_opentype) quickshape = 1; hb_lock(ctx); @@ -760,7 +760,7 @@ static int walk_string(string_walker *walker) fz_throw(ctx, FZ_ERROR_GENERIC, "freetype setting character size: %s", ft_error_string(fterr)); hb_buffer_clear_contents(walker->hb_buf); - hb_buffer_set_direction(walker->hb_buf, walker->r2l ? HB_DIRECTION_RTL : HB_DIRECTION_LTR); + hb_buffer_set_direction(walker->hb_buf, walker->rtl ? HB_DIRECTION_RTL : HB_DIRECTION_LTR); /* hb_buffer_set_script(hb_buf, hb_ucdn_script_translate(script)); */ /* hb_buffer_set_language(hb_buf, hb_language_from_string("en", strlen("en"))); */ /* hb_buffer_set_cluster_level(hb_buf, HB_BUFFER_CLUSTER_LEVEL_CHARACTERS); */ @@ -920,7 +920,7 @@ static void layout_line(fz_context *ctx, float indent, float page_w, float line_ /* Do we need to do any reordering? */ if (min_level != max_level || (min_level & 1)) { - /* The lowest level we swap is always a r2l one */ + /* The lowest level we swap is always a rtl one */ min_level |= 1; /* Each time around the loop we swap runs of fragments that have * levels >= max_level (and decrement max_level). */ @@ -1038,7 +1038,7 @@ static void layout_flow(fz_context *ctx, fz_html *box, fz_html *top, float em, f indent = box->is_first_flow ? fz_from_css_number(top->style.text_indent, em, top->w) : 0; align = top->style.text_align; - if (box->flow_dir == FZ_DIR_R2L) + if (box->flow_dir == FZ_BIDI_RTL) { if (align == TA_LEFT) align = TA_RIGHT; @@ -1545,7 +1545,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); - fz_show_glyph(ctx, text, font, &trm, g, c, 0, 0, FZ_DIR_UNSET, FZ_LANG_UNSET); + fz_show_glyph(ctx, text, font, &trm, g, c, 0, 0, FZ_BIDI_NEUTRAL, FZ_LANG_UNSET); trm.e += fz_advance_glyph(ctx, font, g, 0) * box->em; } @@ -1915,17 +1915,11 @@ static void fragment_cb(const uint32_t *fragment, } static void -detect_flow_directionality(fz_context *ctx, fz_pool *pool, uni_buf *buffer, int baseDir, fz_html_flow *flow) +detect_flow_directionality(fz_context *ctx, fz_pool *pool, uni_buf *buffer, fz_bidi_direction bidi_dir, fz_html_flow *flow) { fz_html_flow *end = flow; const char *text; bidi_data data; - fz_bidi_direction bidi_dir = BIDI_NEUTRAL; - - if (baseDir == FZ_DIR_L2R) - bidi_dir = BIDI_LEFT_TO_RIGHT; - else if (baseDir == FZ_DIR_R2L) - bidi_dir = BIDI_RIGHT_TO_LEFT; while (end) { diff --git a/source/pdf/pdf-appearance.c b/source/pdf/pdf-appearance.c index c64e73af..45d81c63 100644 --- a/source/pdf/pdf-appearance.c +++ b/source/pdf/pdf-appearance.c @@ -1916,7 +1916,7 @@ 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, &tm, gid, ucs, 0, 0, FZ_DIR_UNSET, FZ_LANG_UNSET); + fz_show_glyph(ctx, text, font, &tm, gid, ucs, 0, 0, FZ_BIDI_NEUTRAL, FZ_LANG_UNSET); 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 962c1845..cb83aa8b 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, &trm, gid, ucsbuf[0], fontdesc->wmode, 0, FZ_DIR_UNSET, FZ_LANG_UNSET); + fz_show_glyph(ctx, pr->text, fontdesc->font, &trm, gid, ucsbuf[0], fontdesc->wmode, 0, FZ_BIDI_NEUTRAL, FZ_LANG_UNSET); /* add filler glyphs for one-to-many unicode mapping */ for (i = 1; i < ucslen; i++) - fz_show_glyph(ctx, pr->text, fontdesc->font, &trm, -1, ucsbuf[i], fontdesc->wmode, 0, FZ_DIR_UNSET, FZ_LANG_UNSET); + fz_show_glyph(ctx, pr->text, fontdesc->font, &trm, -1, ucsbuf[i], fontdesc->wmode, 0, FZ_BIDI_NEUTRAL, FZ_LANG_UNSET); if (fontdesc->wmode == 0) { diff --git a/source/tools/murun.c b/source/tools/murun.c index b7e328e7..2e11014e 100644 --- a/source/tools/murun.c +++ b/source/tools/murun.c @@ -1970,7 +1970,7 @@ static void ffi_Text_showGlyph(js_State *J) int wmode = js_isdefined(J, 5) ? js_toboolean(J, 5) : 0; fz_try(ctx) - fz_show_glyph(ctx, text, font, &trm, glyph, unicode, wmode, 0, FZ_DIR_UNSET, FZ_LANG_UNSET); + fz_show_glyph(ctx, text, font, &trm, glyph, unicode, wmode, 0, FZ_BIDI_NEUTRAL, FZ_LANG_UNSET); fz_catch(ctx) rethrow(J); } @@ -1985,7 +1985,7 @@ static void ffi_Text_showString(js_State *J) int wmode = js_isdefined(J, 4) ? js_toboolean(J, 4) : 0; fz_try(ctx) - fz_show_string(ctx, text, font, &trm, s, wmode, 0, FZ_DIR_UNSET, FZ_LANG_UNSET); + fz_show_string(ctx, text, font, &trm, s, wmode, 0, FZ_BIDI_NEUTRAL, FZ_LANG_UNSET); fz_catch(ctx) rethrow(J); diff --git a/source/xps/xps-glyphs.c b/source/xps/xps-glyphs.c index 3d0ebfd0..9110c169 100644 --- a/source/xps/xps-glyphs.c +++ b/source/xps/xps-glyphs.c @@ -451,7 +451,7 @@ xps_parse_glyphs_imp(fz_context *ctx, xps_document *doc, const fz_matrix *ctm, tm.f = y - v_offset; } - dir = bidi_level & 1 ? FZ_DIR_R2L : FZ_DIR_L2R; + dir = bidi_level & 1 ? FZ_BIDI_RTL : FZ_BIDI_LTR; fz_show_glyph(ctx, text, font, &tm, glyph_index, char_code, is_sideways, bidi_level, dir, FZ_LANG_UNSET); x += advance * 0.01f * size; -- cgit v1.2.3