diff options
author | Tor Andersson <tor.andersson@artifex.com> | 2011-04-04 23:35:45 +0200 |
---|---|---|
committer | Tor Andersson <tor.andersson@artifex.com> | 2011-04-04 23:35:45 +0200 |
commit | 7cf6ccee8c6b59d8aac17ab6e4673bcb69f5e8d2 (patch) | |
tree | b329db03bae14fca178add9909b78b050345c140 /fitz/dev_text.c | |
parent | efc46353676c27b24f2933dce78305796951a01e (diff) | |
download | mupdf-7cf6ccee8c6b59d8aac17ab6e4673bcb69f5e8d2.tar.xz |
Le Roi est mort, vive le Roi!
The run-together words are dead! Long live the underscores!
The postscript inspired naming convention of using all run-together
words has served us well, but it is now time for more readable code.
In this commit I have also added the sed script, rename.sed, that I used
to convert the source. Use it on your patches and application code.
Diffstat (limited to 'fitz/dev_text.c')
-rw-r--r-- | fitz/dev_text.c | 200 |
1 files changed, 100 insertions, 100 deletions
diff --git a/fitz/dev_text.c b/fitz/dev_text.c index c59a36f7..139c3eed 100644 --- a/fitz/dev_text.c +++ b/fitz/dev_text.c @@ -1,55 +1,55 @@ #include "fitz.h" -#define LINEDIST 0.9f -#define SPACEDIST 0.2f +#define LINE_DIST 0.9f +#define SPACE_DIST 0.2f #include <ft2build.h> #include FT_FREETYPE_H #include FT_ADVANCES_H -typedef struct fz_textdevice_s fz_textdevice; +typedef struct fz_text_device_s fz_text_device; -struct fz_textdevice_s +struct fz_text_device_s { fz_point point; - fz_textspan *head; - fz_textspan *span; + fz_text_span *head; + fz_text_span *span; }; -fz_textspan * -fz_newtextspan(void) +fz_text_span * +fz_new_text_span(void) { - fz_textspan *span; - span = fz_malloc(sizeof(fz_textspan)); - span->font = nil; + fz_text_span *span; + span = fz_malloc(sizeof(fz_text_span)); + span->font = NULL; span->wmode = 0; span->size = 0; span->len = 0; span->cap = 0; - span->text = nil; - span->next = nil; + span->text = NULL; + span->next = NULL; span->eol = 0; return span; } void -fz_freetextspan(fz_textspan *span) +fz_free_text_span(fz_text_span *span) { if (span->font) - fz_dropfont(span->font); + fz_drop_font(span->font); if (span->next) - fz_freetextspan(span->next); + fz_free_text_span(span->next); fz_free(span->text); fz_free(span); } static void -fz_addtextcharimp(fz_textspan *span, int c, fz_bbox bbox) +fz_add_text_char_imp(fz_text_span *span, int c, fz_bbox bbox) { if (span->len + 1 >= span->cap) { span->cap = span->cap > 1 ? (span->cap * 3) / 2 : 80; - span->text = fz_realloc(span->text, span->cap, sizeof(fz_textchar)); + span->text = fz_realloc(span->text, span->cap, sizeof(fz_text_char)); } span->text[span->len].c = c; span->text[span->len].bbox = bbox; @@ -57,7 +57,7 @@ fz_addtextcharimp(fz_textspan *span, int c, fz_bbox bbox) } static fz_bbox -fz_splitbbox(fz_bbox bbox, int i, int n) +fz_split_bbox(fz_bbox bbox, int i, int n) { float w = (float)(bbox.x1 - bbox.x0) / n; float x0 = bbox.x0; @@ -67,20 +67,20 @@ fz_splitbbox(fz_bbox bbox, int i, int n) } static void -fz_addtextchar(fz_textspan **last, fz_font *font, float size, int wmode, int c, fz_bbox bbox) +fz_add_text_char(fz_text_span **last, fz_font *font, float size, int wmode, int c, fz_bbox bbox) { - fz_textspan *span = *last; + fz_text_span *span = *last; if (!span->font) { - span->font = fz_keepfont(font); + span->font = fz_keep_font(font); span->size = size; } if ((span->font != font || span->size != size || span->wmode != wmode) && c != 32) { - span = fz_newtextspan(); - span->font = fz_keepfont(font); + span = fz_new_text_span(); + span->font = fz_keep_font(font); span->size = size; span->wmode = wmode; (*last)->next = span; @@ -92,55 +92,55 @@ fz_addtextchar(fz_textspan **last, fz_font *font, float size, int wmode, int c, case -1: /* ignore when one unicode character maps to multiple glyphs */ break; case 0xFB00: /* ff */ - fz_addtextcharimp(span, 'f', fz_splitbbox(bbox, 0, 2)); - fz_addtextcharimp(span, 'f', fz_splitbbox(bbox, 1, 2)); + fz_add_text_char_imp(span, 'f', fz_split_bbox(bbox, 0, 2)); + fz_add_text_char_imp(span, 'f', fz_split_bbox(bbox, 1, 2)); break; case 0xFB01: /* fi */ - fz_addtextcharimp(span, 'f', fz_splitbbox(bbox, 0, 2)); - fz_addtextcharimp(span, 'i', fz_splitbbox(bbox, 1, 2)); + fz_add_text_char_imp(span, 'f', fz_split_bbox(bbox, 0, 2)); + fz_add_text_char_imp(span, 'i', fz_split_bbox(bbox, 1, 2)); break; case 0xFB02: /* fl */ - fz_addtextcharimp(span, 'f', fz_splitbbox(bbox, 0, 2)); - fz_addtextcharimp(span, 'l', fz_splitbbox(bbox, 1, 2)); + fz_add_text_char_imp(span, 'f', fz_split_bbox(bbox, 0, 2)); + fz_add_text_char_imp(span, 'l', fz_split_bbox(bbox, 1, 2)); break; case 0xFB03: /* ffi */ - fz_addtextcharimp(span, 'f', fz_splitbbox(bbox, 0, 3)); - fz_addtextcharimp(span, 'f', fz_splitbbox(bbox, 1, 3)); - fz_addtextcharimp(span, 'i', fz_splitbbox(bbox, 2, 3)); + fz_add_text_char_imp(span, 'f', fz_split_bbox(bbox, 0, 3)); + fz_add_text_char_imp(span, 'f', fz_split_bbox(bbox, 1, 3)); + fz_add_text_char_imp(span, 'i', fz_split_bbox(bbox, 2, 3)); break; case 0xFB04: /* ffl */ - fz_addtextcharimp(span, 'f', fz_splitbbox(bbox, 0, 3)); - fz_addtextcharimp(span, 'f', fz_splitbbox(bbox, 1, 3)); - fz_addtextcharimp(span, 'l', fz_splitbbox(bbox, 2, 3)); + fz_add_text_char_imp(span, 'f', fz_split_bbox(bbox, 0, 3)); + fz_add_text_char_imp(span, 'f', fz_split_bbox(bbox, 1, 3)); + fz_add_text_char_imp(span, 'l', fz_split_bbox(bbox, 2, 3)); break; case 0xFB05: /* long st */ case 0xFB06: /* st */ - fz_addtextcharimp(span, 's', fz_splitbbox(bbox, 0, 2)); - fz_addtextcharimp(span, 't', fz_splitbbox(bbox, 1, 2)); + fz_add_text_char_imp(span, 's', fz_split_bbox(bbox, 0, 2)); + fz_add_text_char_imp(span, 't', fz_split_bbox(bbox, 1, 2)); break; default: - fz_addtextcharimp(span, c, bbox); + fz_add_text_char_imp(span, c, bbox); break; } } static void -fz_dividetextchars(fz_textspan **last, int n, fz_bbox bbox) +fz_divide_text_chars(fz_text_span **last, int n, fz_bbox bbox) { - fz_textspan *span = *last; + fz_text_span *span = *last; int i, x; x = span->len - n; if (x >= 0) for (i = 0; i < n; i++) - span->text[x + i].bbox = fz_splitbbox(bbox, i, n); + span->text[x + i].bbox = fz_split_bbox(bbox, i, n); } static void -fz_addtextnewline(fz_textspan **last, fz_font *font, float size, int wmode) +fz_add_text_newline(fz_text_span **last, fz_font *font, float size, int wmode) { - fz_textspan *span; - span = fz_newtextspan(); - span->font = fz_keepfont(font); + fz_text_span *span; + span = fz_new_text_span(); + span->font = fz_keep_font(font); span->size = size; span->wmode = wmode; (*last)->eol = 1; @@ -149,7 +149,7 @@ fz_addtextnewline(fz_textspan **last, fz_font *font, float size, int wmode) } void -fz_debugtextspanxml(fz_textspan *span) +fz_debug_text_span_xml(fz_text_span *span) { char buf[10]; int c, n, k, i; @@ -179,11 +179,11 @@ fz_debugtextspanxml(fz_textspan *span) printf("</span>\n"); if (span->next) - fz_debugtextspanxml(span->next); + fz_debug_text_span_xml(span->next); } void -fz_debugtextspan(fz_textspan *span) +fz_debug_text_span(fz_text_span *span) { char buf[10]; int c, n, k, i; @@ -205,14 +205,14 @@ fz_debugtextspan(fz_textspan *span) putchar('\n'); if (span->next) - fz_debugtextspan(span->next); + fz_debug_text_span(span->next); } static void -fz_textextractspan(fz_textspan **last, fz_text *text, fz_matrix ctm, fz_point *pen) +fz_text_extract_span(fz_text_span **last, fz_text *text, fz_matrix ctm, fz_point *pen) { fz_font *font = text->font; - FT_Face face = font->ftface; + FT_Face face = font->ft_face; fz_matrix tm = text->trm; fz_matrix trm; float size; @@ -229,16 +229,16 @@ fz_textextractspan(fz_textspan **last, fz_text *text, fz_matrix ctm, fz_point *p if (text->len == 0) return; - if (font->ftface) + if (font->ft_face) { - err = FT_Set_Char_Size(font->ftface, 64, 64, 72, 72); + err = FT_Set_Char_Size(font->ft_face, 64, 64, 72, 72); if (err) - fz_warn("freetype set character size: %s", ft_errorstring(err)); + fz_warn("freetype set character size: %s", ft_error_string(err)); ascender = (float)face->ascender / face->units_per_EM; descender = (float)face->descender / face->units_per_EM; } - rect = fz_emptyrect; + rect = fz_empty_rect; if (text->wmode == 0) { @@ -254,29 +254,29 @@ fz_textextractspan(fz_textspan **last, fz_text *text, fz_matrix ctm, fz_point *p tm.e = 0; tm.f = 0; trm = fz_concat(tm, ctm); - dir = fz_transformvector(trm, dir); + dir = fz_transform_vector(trm, dir); dist = sqrtf(dir.x * dir.x + dir.y * dir.y); ndir.x = dir.x / dist; ndir.y = dir.y / dist; - size = fz_matrixexpansion(trm); + size = fz_matrix_expansion(trm); multi = 1; for (i = 0; i < text->len; i++) { - if (text->els[i].gid < 0) + if (text->items[i].gid < 0) { - fz_addtextchar(last, font, size, text->wmode, text->els[i].ucs, fz_roundrect(rect)); + fz_add_text_char(last, font, size, text->wmode, text->items[i].ucs, fz_round_rect(rect)); multi ++; - fz_dividetextchars(last, multi, fz_roundrect(rect)); + fz_divide_text_chars(last, multi, fz_round_rect(rect)); continue; } multi = 1; /* Calculate new pen location and delta */ - tm.e = text->els[i].x; - tm.f = text->els[i].y; + tm.e = text->items[i].x; + tm.f = text->items[i].y; trm = fz_concat(tm, ctm); delta.x = pen->x - trm.e; @@ -293,11 +293,11 @@ fz_textextractspan(fz_textspan **last, fz_text *text, fz_matrix ctm, fz_point *p ndelta.y = delta.y / dist; dot = ndelta.x * ndir.x + ndelta.y * ndir.y; - if (dist > size * LINEDIST) + if (dist > size * LINE_DIST) { - fz_addtextnewline(last, font, size, text->wmode); + fz_add_text_newline(last, font, size, text->wmode); } - else if (fabsf(dot) > 0.95f && dist > size * SPACEDIST) + else if (fabsf(dot) > 0.95f && dist > size * SPACE_DIST) { if ((*last)->len > 0 && (*last)->text[(*last)->len - 1].c != ' ') { @@ -306,14 +306,14 @@ fz_textextractspan(fz_textspan **last, fz_text *text, fz_matrix ctm, fz_point *p spacerect.y0 = 0; spacerect.x1 = 0; spacerect.y1 = 1; - spacerect = fz_transformrect(trm, spacerect); - fz_addtextchar(last, font, size, text->wmode, ' ', fz_roundrect(spacerect)); + spacerect = fz_transform_rect(trm, spacerect); + fz_add_text_char(last, font, size, text->wmode, ' ', fz_round_rect(spacerect)); } } } /* Calculate bounding box and new pen position based on font metrics */ - if (font->ftface) + if (font->ft_face) { FT_Fixed ftadv = 0; int mask = FT_LOAD_NO_BITMAP | FT_LOAD_NO_HINTING | FT_LOAD_IGNORE_TRANSFORM; @@ -321,7 +321,7 @@ fz_textextractspan(fz_textspan **last, fz_text *text, fz_matrix ctm, fz_point *p /* TODO: freetype returns broken vertical metrics */ /* if (text->wmode) mask |= FT_LOAD_VERTICAL_LAYOUT; */ - FT_Get_Advance(font->ftface, text->els[i].gid, mask, &ftadv); + FT_Get_Advance(font->ft_face, text->items[i].gid, mask, &ftadv); adv = ftadv / 65536.0f; rect.x0 = 0; @@ -331,62 +331,62 @@ fz_textextractspan(fz_textspan **last, fz_text *text, fz_matrix ctm, fz_point *p } else { - adv = font->t3widths[text->els[i].gid]; + adv = font->t3widths[text->items[i].gid]; rect.x0 = 0; rect.y0 = descender; rect.x1 = adv; rect.y1 = ascender; } - rect = fz_transformrect(trm, rect); + rect = fz_transform_rect(trm, rect); pen->x = trm.e + dir.x * adv; pen->y = trm.f + dir.y * adv; - fz_addtextchar(last, font, size, text->wmode, text->els[i].ucs, fz_roundrect(rect)); + fz_add_text_char(last, font, size, text->wmode, text->items[i].ucs, fz_round_rect(rect)); } } static void -fz_textfilltext(void *user, fz_text *text, fz_matrix ctm, +fz_text_fill_text(void *user, fz_text *text, fz_matrix ctm, fz_colorspace *colorspace, float *color, float alpha) { - fz_textdevice *tdev = user; - fz_textextractspan(&tdev->span, text, ctm, &tdev->point); + fz_text_device *tdev = user; + fz_text_extract_span(&tdev->span, text, ctm, &tdev->point); } static void -fz_textstroketext(void *user, fz_text *text, fz_strokestate *stroke, fz_matrix ctm, +fz_text_stroke_text(void *user, fz_text *text, fz_stroke_state *stroke, fz_matrix ctm, fz_colorspace *colorspace, float *color, float alpha) { - fz_textdevice *tdev = user; - fz_textextractspan(&tdev->span, text, ctm, &tdev->point); + fz_text_device *tdev = user; + fz_text_extract_span(&tdev->span, text, ctm, &tdev->point); } static void -fz_textcliptext(void *user, fz_text *text, fz_matrix ctm, int accumulate) +fz_text_clip_text(void *user, fz_text *text, fz_matrix ctm, int accumulate) { - fz_textdevice *tdev = user; - fz_textextractspan(&tdev->span, text, ctm, &tdev->point); + fz_text_device *tdev = user; + fz_text_extract_span(&tdev->span, text, ctm, &tdev->point); } static void -fz_textclipstroketext(void *user, fz_text *text, fz_strokestate *stroke, fz_matrix ctm) +fz_text_clip_stroke_text(void *user, fz_text *text, fz_stroke_state *stroke, fz_matrix ctm) { - fz_textdevice *tdev = user; - fz_textextractspan(&tdev->span, text, ctm, &tdev->point); + fz_text_device *tdev = user; + fz_text_extract_span(&tdev->span, text, ctm, &tdev->point); } static void -fz_textignoretext(void *user, fz_text *text, fz_matrix ctm) +fz_text_ignore_text(void *user, fz_text *text, fz_matrix ctm) { - fz_textdevice *tdev = user; - fz_textextractspan(&tdev->span, text, ctm, &tdev->point); + fz_text_device *tdev = user; + fz_text_extract_span(&tdev->span, text, ctm, &tdev->point); } static void -fz_textfreeuser(void *user) +fz_text_free_user(void *user) { - fz_textdevice *tdev = user; + fz_text_device *tdev = user; tdev->span->eol = 1; @@ -397,22 +397,22 @@ fz_textfreeuser(void *user) } fz_device * -fz_newtextdevice(fz_textspan *root) +fz_new_text_device(fz_text_span *root) { fz_device *dev; - fz_textdevice *tdev = fz_malloc(sizeof(fz_textdevice)); + fz_text_device *tdev = fz_malloc(sizeof(fz_text_device)); tdev->head = root; tdev->span = root; tdev->point.x = -1; tdev->point.y = -1; - dev = fz_newdevice(tdev); - dev->hints = FZ_IGNOREIMAGE | FZ_IGNORESHADE; - dev->freeuser = fz_textfreeuser; - dev->filltext = fz_textfilltext; - dev->stroketext = fz_textstroketext; - dev->cliptext = fz_textcliptext; - dev->clipstroketext = fz_textclipstroketext; - dev->ignoretext = fz_textignoretext; + dev = fz_new_device(tdev); + dev->hints = FZ_IGNORE_IMAGE | FZ_IGNORE_SHADE; + dev->free_user = fz_text_free_user; + dev->fill_text = fz_text_fill_text; + dev->stroke_text = fz_text_stroke_text; + dev->clip_text = fz_text_clip_text; + dev->clip_stroke_text = fz_text_clip_stroke_text; + dev->ignore_text = fz_text_ignore_text; return dev; } |