From 79fcb76530aa447e6235a8e58db5a32d37d8683a Mon Sep 17 00:00:00 2001 From: Werner Lemberg Date: Thu, 29 Dec 2011 00:23:10 +0100 Subject: [PATCH] Cosmetics: Don't store end points but the number of points (and point sums). --- src/ta.h | 6 +++--- src/tabytecode.c | 9 ++++----- src/tafont.c | 2 +- src/taglyf.c | 60 ++++++++++++++++++++++++++------------------------------ src/tagpos.c | 9 ++++----- 5 files changed, 40 insertions(+), 46 deletions(-) diff --git a/src/ta.h b/src/ta.h index fddccb6..3b605a1 100644 --- a/src/ta.h +++ b/src/ta.h @@ -104,13 +104,13 @@ typedef struct GLYPH_ FT_Byte* ins_buf; /* new instruction data */ FT_Short num_contours; /* >= 0 for simple glyphs */ - FT_UShort endpoint; /* last point in a simple glyph */ + FT_UShort num_points; /* number of points in a simple glyph */ FT_UShort num_components; FT_UShort* components; /* the subglyph indices of a composite glyph */ - FT_UShort num_endpoints; - FT_UShort* endpoints; /* the endpoints of all composite elements */ + FT_UShort num_pointsums; + FT_UShort* pointsums; /* the pointsums of all composite elements */ /* (after walking recursively over all subglyphs) */ } GLYPH; diff --git a/src/tabytecode.c b/src/tabytecode.c index 0591359..cf467b4 100644 --- a/src/tabytecode.c +++ b/src/tabytecode.c @@ -67,11 +67,10 @@ typedef struct Recorder_ { /* We add a subglyph for each composite glyph. */ /* Since subglyphs must contain at least one point, */ /* we have to adjust all point indices accordingly. */ -/* Using the `endpoints' array of the `GLYPH' structure */ -/* (which actually stores `endpoint + 1' values), */ +/* Using the `pointsums' array of the `GLYPH' structure */ /* it is straightforward to do that: */ /* Assuming that point with index x is in the interval */ -/* endpoints[n] <= x < endpoints[n + 1], */ +/* pointsums[n] <= x < pointsums[n + 1], */ /* the new point index is x + n. */ static FT_UInt @@ -85,8 +84,8 @@ TA_adjust_point_index(Recorder* recorder, if (!glyph->num_components) return idx; /* not a composite glyph */ - for (i = 0; i < glyph->num_endpoints; i++) - if (idx < glyph->endpoints[i]) + for (i = 0; i < glyph->num_pointsums; i++) + if (idx < glyph->pointsums[i]) break; return idx + i; diff --git a/src/tafont.c b/src/tafont.c index 3c96d75..b71a681 100644 --- a/src/tafont.c +++ b/src/tafont.c @@ -84,7 +84,7 @@ TA_font_unload(FONT* font, free(data->glyphs[j].buf); free(data->glyphs[j].ins_buf); free(data->glyphs[j].components); - free(data->glyphs[j].endpoints); + free(data->glyphs[j].pointsums); } free(data->glyphs); free(data); diff --git a/src/taglyf.c b/src/taglyf.c index 47ffce8..008b099 100644 --- a/src/taglyf.c +++ b/src/taglyf.c @@ -195,7 +195,6 @@ TA_glyph_parse_simple(GLYPH* glyph, FT_Byte* flags_start; FT_UShort num_ins; - FT_UShort num_pts; FT_ULong flags_size; /* size of the flags array */ FT_ULong xy_size; /* size of x and y coordinate arrays together */ @@ -225,13 +224,11 @@ TA_glyph_parse_simple(GLYPH* glyph, if (p > endp) return FT_Err_Invalid_Table; - num_pts = glyph->endpoint + 1; - flags_start = p; xy_size = 0; i = 0; - while (i < num_pts) + while (i < glyph->num_points) { FT_Byte flags; FT_Byte x_short; @@ -261,7 +258,7 @@ TA_glyph_parse_simple(GLYPH* glyph, count += *(p++); - if (i + count > num_pts) + if (i + count > glyph->num_points) return FT_Err_Invalid_Table; } @@ -296,30 +293,30 @@ static FT_Error TA_iterate_composite_glyph(glyf_Data* data, FT_UShort* components, FT_UShort num_components, - FT_UShort** endpoints, - FT_UShort* num_endpoints, + FT_UShort** pointsums, + FT_UShort* num_pointsums, FT_UShort* num_composite_contours, FT_UShort* num_composite_points) { - FT_UShort* endpoints_new; + FT_UShort* pointsums_new; FT_UShort i; /* save current state */ - (*num_endpoints)++; - endpoints_new = (FT_UShort*)realloc(*endpoints, - *num_endpoints + (*num_pointsums)++; + pointsums_new = (FT_UShort*)realloc(*pointsums, + *num_pointsums * sizeof (FT_UShort)); - if (!endpoints_new) + if (!pointsums_new) { - (*num_endpoints)--; + (*num_pointsums)--; return FT_Err_Out_Of_Memory; } else - *endpoints = endpoints_new; + *pointsums = pointsums_new; - (*endpoints)[*num_endpoints - 1] = *num_composite_points; + (*pointsums)[*num_pointsums - 1] = *num_composite_points; for (i = 0; i < num_components; i++) { @@ -338,8 +335,8 @@ TA_iterate_composite_glyph(glyf_Data* data, error = TA_iterate_composite_glyph(data, glyph->components, glyph->num_components, - endpoints, - num_endpoints, + pointsums, + num_pointsums, num_composite_contours, num_composite_points); if (error) @@ -348,7 +345,7 @@ TA_iterate_composite_glyph(glyf_Data* data, else { *num_composite_contours += glyph->num_contours; - *num_composite_points += glyph->endpoint + 1; + *num_composite_points += glyph->num_points; } } @@ -356,10 +353,8 @@ TA_iterate_composite_glyph(glyf_Data* data, } -/* this function actually stores `endpoint + 1' values */ - static FT_Error -TA_sfnt_compute_composite_endpoints(SFNT* sfnt, +TA_sfnt_compute_composite_pointsums(SFNT* sfnt, FONT* font) { SFNT_Table* glyf_table = &font->tables[sfnt->glyf_idx]; @@ -383,8 +378,8 @@ TA_sfnt_compute_composite_endpoints(SFNT* sfnt, error = TA_iterate_composite_glyph(data, glyph->components, glyph->num_components, - &glyph->endpoints, - &glyph->num_endpoints, + &glyph->pointsums, + &glyph->num_pointsums, &num_composite_contours, &num_composite_points); if (error) @@ -393,14 +388,14 @@ TA_sfnt_compute_composite_endpoints(SFNT* sfnt, /* update maximum values, */ /* including the subglyphs not in `components' array */ /* (each of them has a single point in a single contour) */ - if (num_composite_points + glyph->num_endpoints + if (num_composite_points + glyph->num_pointsums > sfnt->max_composite_points) sfnt->max_composite_points = num_composite_points - + glyph->num_endpoints; - if (num_composite_contours + glyph->num_endpoints + + glyph->num_pointsums; + if (num_composite_contours + glyph->num_pointsums > sfnt->max_composite_contours) sfnt->max_composite_contours = num_composite_contours - + glyph->num_endpoints; + + glyph->num_pointsums; } } @@ -511,8 +506,8 @@ TA_sfnt_split_glyf_table(SFNT* sfnt, if (len < 10) return FT_Err_Invalid_Table; - /* we need number of contours and the last point for */ - /* `TA_sfnt_compute_composite_endpoints' */ + /* we need the number of contours and points for */ + /* `TA_sfnt_compute_composite_pointsums' */ buf = glyf_table->buf + offset; glyph->num_contours = (FT_Short)((buf[0] << 8) + buf[1]); @@ -527,16 +522,17 @@ TA_sfnt_split_glyf_table(SFNT* sfnt, FT_ULong off; + /* use the last contour's end point to compute number of points */ off = 10 + (glyph->num_contours - 1) * 2; - glyph->endpoint = buf[off] << 8; - glyph->endpoint += buf[off + 1]; + glyph->num_points = buf[off] << 8; + glyph->num_points += buf[off + 1] + 1; } } } if (sfnt->max_components) { - error = TA_sfnt_compute_composite_endpoints(sfnt, font); + error = TA_sfnt_compute_composite_pointsums(sfnt, font); if (error) return error; } diff --git a/src/tagpos.c b/src/tagpos.c index 4b24772..e610a65 100644 --- a/src/tagpos.c +++ b/src/tagpos.c @@ -153,11 +153,10 @@ TA_read_coverage_table(FT_Byte* p, /* We add a subglyph for each composite glyph. */ /* Since subglyphs must contain at least one point, */ /* we have to adjust all AnchorPoints in GPOS AnchorTables accordingly. */ -/* Using the `endpoints' array of the `GLYPH' structure */ -/* (which actually stores `endpoint + 1' values), */ +/* Using the `pointsums' array of the `GLYPH' structure */ /* it is straightforward to do that: */ /* Assuming that anchor point x is in the interval */ -/* endpoints[n] <= x < endpoints[n + 1], */ +/* pointsums[n] <= x < pointsums[n + 1], */ /* the new point index is x + n. */ static FT_Error @@ -194,8 +193,8 @@ TA_update_anchor(FT_Byte* p, return FT_Err_Invalid_Table; /* search point offset */ - for (i = 0; i < glyph->num_endpoints; i++) - if (AnchorPoint < glyph->endpoints[i]) + for (i = 0; i < glyph->num_pointsums; i++) + if (AnchorPoint < glyph->pointsums[i]) break; *(p - 2) = HIGH(AnchorPoint + i); -- 2.11.4.GIT