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); } }
static void measure_word(fz_context *ctx, fz_html_flow *node, float em) { fz_font *font; const char *s; int c, g; float w; em = fz_from_css_number(node->style->font_size, em, em); node->x = 0; node->y = 0; node->h = fz_from_css_number_scale(node->style->line_height, em, em, em); w = 0; s = node->content.text; while (*s) { s += fz_chartorune(&c, s); g = fz_encode_character_with_fallback(ctx, node->style->font, c, 0, &font); w += fz_advance_glyph(ctx, font, g) * em; } node->w = w; node->em = em; }
static void draw_flow_box(fz_context *ctx, fz_html *box, float page_top, float page_bot, fz_device *dev, const fz_matrix *ctm) { fz_font *font; fz_html_flow *node; fz_text *text; fz_matrix trm; const char *s; float color[3]; int c, g; for (node = box->flow_head; node; node = node->next) { if (node->type == FLOW_IMAGE) { if (node->y >= page_bot || node->y + node->h <= page_top) continue; } else { if (node->y > page_bot || node->y < page_top) continue; } if (node->type == FLOW_WORD) { fz_scale(&trm, node->em, -node->em); color[0] = node->style->color.r / 255.0f; color[1] = node->style->color.g / 255.0f; color[2] = node->style->color.b / 255.0f; /* TODO: reuse text object if color is unchanged */ text = fz_new_text(ctx); trm.e = node->x; trm.f = node->y; s = node->content.text; if (node->char_r2l) { float w = 0; const char *t = s; while (*t) { t += fz_chartorune(&c, t); if (node->mirror) c = ucdn_mirror(c); g = fz_encode_character_with_fallback(ctx, node->style->font, c, 0, &font); w += fz_advance_glyph(ctx, font, g) * node->em; } trm.e += w; while (*s) { s += fz_chartorune(&c, s); if (node->mirror) c = ucdn_mirror(c); g = fz_encode_character_with_fallback(ctx, node->style->font, c, 0, &font); trm.e -= fz_advance_glyph(ctx, font, g) * node->em; if (node->style->visibility == V_VISIBLE) fz_add_text(ctx, text, font, 0, &trm, g, c); } trm.e += w; } else { while (*s) { s += fz_chartorune(&c, s); g = fz_encode_character_with_fallback(ctx, node->style->font, c, 0, &font); if (node->style->visibility == V_VISIBLE) fz_add_text(ctx, text, font, 0, &trm, g, c); trm.e += fz_advance_glyph(ctx, font, g) * node->em; } } if (text) { fz_fill_text(ctx, dev, text, ctm, fz_device_rgb(ctx), color, 1); fz_drop_text(ctx, text); } } else if (node->type == FLOW_IMAGE) { if (node->style->visibility == V_VISIBLE) { fz_matrix local_ctm = *ctm; fz_pre_translate(&local_ctm, node->x, node->y); fz_pre_scale(&local_ctm, node->w, node->h); fz_fill_image(ctx, dev, node->content.image, &local_ctm, 1); } } } }
static void draw_list_mark(fz_context *ctx, fz_html *box, float page_top, float page_bot, fz_device *dev, const fz_matrix *ctm, int n) { fz_font *font; fz_text *text; fz_matrix trm; fz_html_flow *line; float y, w; float color[3]; const char *s; char buf[40]; int c, g; fz_scale(&trm, box->em, -box->em); text = fz_new_text(ctx); line = find_list_mark_anchor(ctx, box); if (line) { y = line->y; } else { float h = fz_from_css_number_scale(box->style.line_height, box->em, box->em, box->em); float a = box->em * 0.8; float d = box->em * 0.2; if (a + d > h) h = a + d; y = box->y + a + (h - a - d) / 2; } if (y > page_bot || y < page_top) return; format_list_number(ctx, box->style.list_style_type, n, buf, sizeof buf); s = buf; w = 0; while (*s) { 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; } s = buf; trm.e = box->x - w; trm.f = y; while (*s) { s += fz_chartorune(&c, s); g = fz_encode_character_with_fallback(ctx, box->style.font, c, UCDN_SCRIPT_LATIN, &font); fz_add_text(ctx, text, font, 0, &trm, g, c); trm.e += fz_advance_glyph(ctx, font, g) * box->em; } color[0] = box->style.color.r / 255.0f; color[1] = box->style.color.g / 255.0f; color[2] = box->style.color.b / 255.0f; fz_fill_text(ctx, dev, text, ctm, fz_device_rgb(ctx), color, 1); fz_drop_text(ctx, text); }
float ui_draw_character(fz_context *ctx, int ucs, float x, float y) { fz_font *font; int gid = fz_encode_character_with_fallback(ctx, g_font, ucs, 0, &font); return ui_draw_glyph(font, gid, x, y); }
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, 0) * g_font_size; }