added experimental emboldening/outlining code. This is incomplete and will not compile so turned off
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 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310
diff --git a/src/base/ftglyph.c b/src/base/ftglyph.c
index c7ffe8c..248c386 100644
--- a/src/base/ftglyph.c
+++ b/src/base/ftglyph.c
@@ -498,3 +498,305 @@
;
}
}
+
+
+ /***************************************************************************/
+ /***************************************************************************/
+ /**** ****/
+ /**** EXPERIMENTAL EMBOLDENING/OUTLINING SUPPORT ****/
+ /**** ****/
+ /***************************************************************************/
+ /***************************************************************************/
+
+#if 0
+
+/* Compute the norm of a vector */
+#ifdef FT_CONFIG_OPTION_OLD_CALCS
+ static
+ FT_Pos ft_norm( FT_Vector* vec )
+ {
+ FT_Int64 t1, t2;
+
+ MUL_64( vec->x, vec->x, t1 );
+ MUL_64( vec->y, vec->y, t2 );
+ ADD_64( t1, t2, t1 );
+ return (FT_Pos)SQRT_64(t1);
+ }
+#else
+ static
+ FT_Pos ft_norm( FT_Vector* vec )
+ {
+ FT_F26Dot6 u, v, d;
+ FT_Int shift;
+ FT_ULong H, L, L2, hi, lo, med;
+
+ u = vec->x; if (u < 0) u = -u;
+ v = vec->y; if (v < 0) v = -v;
+
+ if (u < v)
+ {
+ d = u;
+ u = v;
+ v = d;
+ }
+
+ /* check that we're not trying to normalise zero !! */
+ if (u==0) return 0;
+
+ /* compute (u*u+v*v) on 64 bits with two 32-bit registers [H:L] */
+ hi = (FT_ULong)u >> 16;
+ lo = (FT_ULong)u & 0xFFFF;
+ med = hi*lo;
+
+ H = hi*hi + (med >> 15);
+ med <<= 17;
+ L = lo*lo + med;
+ if (L < med) H++;
+
+ hi = (FT_ULong)v >> 16;
+ lo = (FT_ULong)v & 0xFFFF;
+ med = hi*lo;
+
+ H += hi*hi + (med >> 15);
+ med <<= 17;
+ L2 = lo*lo + med;
+ if (L2 < med) H++;
+
+ L += L2;
+ if (L < L2) H++;
+
+ /* if the value is smaller than 32-bits */
+ shift = 0;
+ if (H == 0)
+ {
+ while ((L & 0xC0000000) == 0)
+ {
+ L <<= 2;
+ shift++;
+ }
+ return (FT_Sqrt32(L) >> shift);
+ }
+ else
+ {
+ while (H)
+ {
+ L = (L >> 2) | (H << 30);
+ H >>= 2;
+ shift++;
+ }
+ return (FT_Sqrt32(L) << shift);
+ }
+ }
+#endif
+
+ static
+ int ft_test_extrema( FT_Outline* outline,
+ int n )
+ {
+ FT_Vector *prev, *cur, *next;
+ FT_Pos product;
+ FT_Int first, last;
+
+ /* we need to compute the "previous" and "next" point */
+ /* for this extrema.. */
+ cur = outline->points + n;
+ prev = cur - 1;
+ next = cur + 1;
+
+ first = 0;
+ for ( c = 0; c < outline->n_contours; c++ )
+ {
+ last = outline->contours[c];
+
+ if ( n == first )
+ prev = outline->points + last;
+
+ if ( n == last )
+ next = outline->points + first;
+
+ first = last + 1;
+ }
+
+ product = FT_MulDiv( cur->x - prev->x, /* in.x */
+ next->y - cur->y, /* out.y */
+ 0x40 ) -
+
+ FT_MulDiv( cur->y - prev->y, /* in.y */
+ next->x - cur->x, /* out.x */
+ 0x40 );
+
+ if (product)
+ product = ( product > 0 ? 1 : -1 );
+
+ return product;
+ }
+
+
+/* Compute the orientation of path filling. It differs between TrueType */
+/* and Type1 formats. We could use the 'ft_outline_reverse_fill' flag, */
+/* but it's better to re-compute it directly (it seems that this flag */
+/* isn't correctly set for some weird composite glyphs for now).. */
+/* */
+/* We do this by computing bounding box points, and computing their */
+/* curvature.. the function returns either 1 or -1 */
+/* */
+ static
+ int ft_get_orientation( FT_Outline* outline )
+ {
+ FT_BBox box;
+ FT_BBox indexes;
+ int n, last;
+
+ indexes.xMin = -1;
+ indexes.yMin = -1;
+ indexes.xMax = -1;
+ indexes.yMax = -1;
+
+ box.xMin = box.yMin = 32767;
+ box.xMax = box.yMax = -32768;
+
+ /* is it empty ? */
+ if ( outline->n_contours < 1 )
+ return 1;
+
+ last = outline->contours[outline->n_contours-1];
+
+ for ( n = 0; n <= last; n++ )
+ {
+ FT_Pos x, y;
+
+ x = outline->points[n].x;
+ if ( x < box.xMin )
+ {
+ box.xMin = x;
+ indexes.xMin = n;
+ }
+
+ if ( x > box.xMax )
+ {
+ box.xMax = x;
+ indexes.xMax = n;
+ }
+
+ y = outline->points[n].y;
+ if ( y < box.yMin )
+ {
+ box.yMin = y;
+ indexes.yMin = n;
+ }
+
+ if ( y > box.yMax )
+ {
+ box.yMax = y;
+ indexes.yMax = n;
+ }
+ }
+
+ /* test orientation of the xmin */
+ return ft_test_extrema( outline, indexes.xMin ) ||
+ ft_test_extrema( outline, indexes.yMin ) ||
+ ft_test_extrema( outline, indexes.xMax ) ||
+ ft_test_extrema( outline, indexes.yMax ) ||
+ 1; /* this is an empty glyph ?? */
+ }
+
+
+ static
+ FT_Error ft_embolden( FT_Face original,
+ FT_Outline* outline,
+ FT_Pos* advance )
+ {
+ FT_Vector u, v;
+ FT_Vector* points;
+ FT_Vector cur, prev, next;
+ FT_Pos distance;
+ int c, n, first, orientation;
+
+ (void)advance;
+
+ /* compute control distance */
+ distance = FT_MulFix( original->em_size/60,
+ original->size->metrics.y_scale );
+
+ orientation = ft_get_orientation( &original->glyph->outline );
+
+ points = original->glyph->outline.points;
+
+ first = 0;
+ for ( c = 0; c < outline->n_contours; c++ )
+ {
+ int last = outline->contours[c];
+
+ prev = points[last];
+
+ for ( n = first; n <= last; n++ )
+ {
+ FT_Pos norme, delta, d;
+ FT_Vector in, out;
+
+ cur = points[n];
+ if ( n < last ) next = points[n+1];
+ else next = points[first];
+
+ /* compute the in and out vectors */
+ in.x = cur.x - prev.x;
+ in.y = cur.y - prev.y;
+
+ out.x = next.x - cur.x;
+ out.y = next.y - cur.y;
+
+ /* compute U and V */
+ norme = ft_norm( &in );
+ u.x = orientation * FT_DivFix( in.y, norme );
+ u.y = orientation * - FT_DivFix( in.x, norme );
+
+ norme = ft_norm( &out );
+ v.x = orientation * FT_DivFix( out.y, norme );
+ v.y = orientation * - FT_DivFix( out.x, norme );
+
+ d = distance;
+
+ if ( (outline->flags[n] & FT_Curve_Tag_On) == 0 )
+ d *= 2;
+
+ /* Check discriminant for parallel vectors */
+ delta = FT_MulFix( u.x, v.y ) - FT_MulFix( u.y, v.x );
+ if ( delta > FT_BOLD_THRESHOLD || delta < - FT_BOLD_THRESHOLD )
+ {
+ /* Move point - compute A and B */
+ FT_Pos x, y, A, B;
+
+ A = d + FT_MulFix( cur.x, u.x ) + FT_MulFix( cur.y, u.y );
+ B = d + FT_MulFix( cur.x, v.x ) + FT_MulFix( cur.y, v.y );
+
+ x = FT_MulFix( A, v.y ) - FT_MulFix( B, u.y );
+ y = FT_MulFix( B, u.x ) - FT_MulFix( A, v.x );
+
+ outline->points[n].x = distance + FT_DivFix( x, delta );
+ outline->points[n].y = distance + FT_DivFix( y, delta );
+ }
+ else
+ {
+ /* Vectors are nearly parallel */
+ FT_Pos x, y;
+
+ x = distance + cur.x + FT_MulFix( d, u.x + v.x )/2;
+ y = distance + cur.y + FT_MulFix( d, u.y + v.y )/2;
+
+ outline->points[n].x = x;
+ outline->points[n].y = y;
+ }
+
+ prev = cur;
+ }
+
+ first = last+1;
+ }
+
+ if (advance)
+ *advance = (*advance + distance*4) & -64;
+
+ return 0;
+ }
+
+#endif /* 0 - EXPERIMENTAL STUFF !! */