added glyph zone objects
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274
diff --git a/src/base/ftobjs.c b/src/base/ftobjs.c
index 908e27b..cc46ac2 100644
--- a/src/base/ftobjs.c
+++ b/src/base/ftobjs.c
@@ -2409,46 +2409,50 @@
FT_Error FT_Get_Outline_CBox( FT_Outline* outline,
FT_BBox* cbox )
{
+ FT_Pos xMin, yMin, xMax, yMax;
+
if ( outline && cbox )
{
if ( outline->n_points == 0 )
{
- cbox->xMin = 0;
- cbox->yMin = 0;
- cbox->xMax = 0;
- cbox->yMax = 0;
+ xMin = 0;
+ yMin = 0;
+ xMax = 0;
+ yMax = 0;
}
else
{
- FT_UShort k;
- FT_Vector* vec = outline->points;
-
+ FT_Vector* vec = outline->points;
+ FT_Vector* limit = vec + outline->n_points;
- cbox->xMin = cbox->xMax = vec->x;
- cbox->yMin = cbox->yMax = vec->y;
+ xMin = xMax = vec->x;
+ yMin = yMax = vec->y;
vec++;
- for ( k = 1; k < outline->n_points; k++ )
+ for ( ; vec < limit; vec++ )
{
FT_Pos x, y;
-
x = vec->x;
- if ( x < cbox->xMin ) cbox->xMin = x;
- if ( x > cbox->xMax ) cbox->xMax = x;
+ if ( x < xMin ) xMin = x;
+ if ( x > xMax ) xMax = x;
y = vec->y;
- if ( y < cbox->yMin ) cbox->yMin = y;
- if ( y > cbox->yMax ) cbox->yMax = y;
- vec++;
+ if ( y < yMin ) yMin = y;
+ if ( y > yMax ) yMax = y;
}
}
+ cbox->xMin = xMin;
+ cbox->xMax = xMax;
+ cbox->yMin = yMin;
+ cbox->yMax = yMax;
return FT_Err_Ok;
}
else
return FT_Err_Invalid_Argument;
}
+
/*************************************************************************/
/* */
@@ -2474,7 +2478,6 @@
FT_UShort n;
FT_Vector* vec = outline->points;
-
for ( n = 0; n < outline->n_points; n++ )
{
vec->x += xOffset;
@@ -2484,6 +2487,130 @@
}
+ /*************************************************************************/
+ /* */
+ /* <Function> */
+ /* FT_Done_GlyphZone */
+ /* */
+ /* <Description> */
+ /* Deallocates a glyph zone. */
+ /* */
+ /* <Input> */
+ /* zone :: pointer to the target glyph zone. */
+ /* */
+ BASE_FUNC
+ void FT_Done_GlyphZone( FT_GlyphZone* zone )
+ {
+ FT_Memory memory = zone->memory;
+
+ FREE( zone->contours );
+ FREE( zone->flags );
+ FREE( zone->cur );
+ FREE( zone->org );
+
+ zone->max_points = zone->n_points = 0;
+ zone->max_contours = zone->n_contours = 0;
+ }
+
+ /*************************************************************************/
+ /* */
+ /* <Function> */
+ /* FT_New_GlyphZone */
+ /* */
+ /* <Description> */
+ /* Allocates a new glyph zone. */
+ /* */
+ /* <Input> */
+ /* memory :: A handle to the current memory object. */
+ /* */
+ /* maxPoints :: The capacity of glyph zone in points. */
+ /* */
+ /* maxContours :: The capacity of glyph zone in contours. */
+ /* */
+ /* <Output> */
+ /* zone :: A pointer to the target glyph zone record. */
+ /* */
+ /* <Return> */
+ /* FreeType error code. 0 means success. */
+ /* */
+ BASE_FUNC
+ FT_Error FT_New_GlyphZone( FT_Memory memory,
+ FT_UShort maxPoints,
+ FT_Short maxContours,
+ FT_GlyphZone* zone )
+ {
+ FT_Error error;
+
+ if (maxPoints > 0)
+ maxPoints += 2;
+
+ MEM_Set( zone, 0, sizeof(*zone) );
+ zone->memory = memory;
+
+ if ( ALLOC_ARRAY( zone->org, maxPoints*2, FT_F26Dot6 ) ||
+ ALLOC_ARRAY( zone->cur, maxPoints*2, FT_F26Dot6 ) ||
+ ALLOC_ARRAY( zone->flags, maxPoints, FT_Byte ) ||
+ ALLOC_ARRAY( zone->contours, maxContours, FT_UShort ) )
+ {
+ FT_Done_GlyphZone(zone);
+ }
+ return error;
+ }
+
+ /*************************************************************************/
+ /* */
+ /* <Function> */
+ /* FT_Update_GlyphZone */
+ /* */
+ /* <Description> */
+ /* Checks the size of a zone and reallocates it if necessary. */
+ /* */
+ /* <Input> */
+ /* newPoints :: The new capacity for points. We add two slots for */
+ /* phantom points. */
+ /* */
+ /* newContours :: The new capacity for contours. */
+ /* */
+ /* <InOut> */
+ /* zone :: The address of the target zone. */
+ /* */
+ /* maxPoints :: The address of the zone's current capacity for */
+ /* points. */
+ /* */
+ /* maxContours :: The address of the zone's current capacity for */
+ /* contours. */
+ /* */
+ BASE_FUNC
+ FT_Error FT_Update_GlyphZone( FT_GlyphZone* zone,
+ FT_UShort newPoints,
+ FT_Short newContours )
+ {
+ FT_Error error = FT_Err_Ok;
+ FT_Memory memory = zone->memory;
+
+ newPoints += 2;
+ if ( zone->max_points < newPoints )
+ {
+ /* reallocate the points arrays */
+ if ( REALLOC_ARRAY( zone->org, zone->max_points*2, newPoints*2, FT_F26Dot6 ) ||
+ REALLOC_ARRAY( zone->cur, zone->max_points*2, newPoints*2, FT_F26Dot6 ) ||
+ REALLOC_ARRAY( zone->flags, zone->max_points*2, newPoints, FT_Byte ) )
+ goto Exit;
+
+ zone->max_points = newPoints;
+ }
+
+ if ( zone->max_contours < newContours )
+ {
+ /* reallocate the contours array */
+ if ( REALLOC_ARRAY( zone->contours, zone->max_contours, newContours, FT_UShort ) )
+ goto Exit;
+
+ zone->max_contours = newContours;
+ }
+ Exit:
+ return error;
+ }
diff --git a/src/base/ftobjs.h b/src/base/ftobjs.h
index 8dc90ec..629aba4 100644
--- a/src/base/ftobjs.h
+++ b/src/base/ftobjs.h
@@ -319,6 +319,59 @@
#ifdef FT_CONFIG_OPTION_ALTERNATE_GLYPH_FORMATS
+ /************************************************************************
+ *
+ * <Struct>
+ * FT_GlyphZone
+ *
+ * <Description>
+ * A glyph zone is used to load, scale and hint glyph outline
+ * coordinates.
+ *
+ * <Fields>
+ * memory :: handle to memory manager
+ * max_points :: max size in points of zone
+ * max_contours :: max size in contours of zone
+ * n_points :: current number of points in zone
+ * n_contours :: current number of contours in zone
+ * org :: original glyph coordinates (font units/scaled)
+ * cur :: current glyph coordinates (scaled/hinted)
+ * flags :: point control flags
+ * contours :: contour end points
+ *
+ ***********************************************************************/
+
+ typedef struct FT_GlyphZone_
+ {
+ FT_Memory memory;
+ FT_UShort max_points;
+ FT_UShort max_contours;
+ FT_UShort n_points; /* number of points in zone */
+ FT_Short n_contours; /* number of contours */
+
+ FT_Vector* org; /* original point coordinates */
+ FT_Vector* cur; /* current point coordinates */
+
+ FT_Byte* flags; /* current touch flags */
+ FT_UShort* contours; /* contour end points */
+
+ } FT_GlyphZone;
+
+ BASE_DEF
+ FT_Error FT_New_GlyphZone( FT_Memory memory,
+ FT_UShort maxPoints,
+ FT_Short maxContours,
+ FT_GlyphZone* zone );
+
+ BASE_DEF
+ void FT_Done_GlyphZone( FT_GlyphZone* zone );
+
+ BASE_DEF
+ FT_Error FT_Update_GlyphZone( FT_GlyphZone* zone,
+ FT_UShort num_points,
+ FT_Short num_contours );
+
+
/*************************************************************************/
/*************************************************************************/
/*************************************************************************/