[autofit] Improve Hebrew rendering. This change introduces a new blue zone property `AF_BLUE_PROPERTY_LATIN_LONG' to make the auto-hinter ignore short top segments. * src/autofit/afblue.dat: Fix Hebrew blue strings. Use AF_BLUE_PROPERTY_LATIN_LONG for AF_BLUE_STRING_HEBREW_TOP. * src/autofit/afblue.hin (AF_BLUE_PROPERTY_LATIN_LONG): New macro. * src/autofit/afblue.c, src/autofit/afblue.h: Updated. * src/autofit/aflatin.c (af_latin_metrics_init_blues): Handle `AF_LATIN_IS_LONG_BLUE'. * src/autofit/aflatin.h (AF_LATIN_IS_LONG_BLUE): New macro.
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 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354
diff --git a/ChangeLog b/ChangeLog
index 3ec7f09..79d1e37 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,23 @@
+2013-09-11 Werner Lemberg <wl@gnu.org>
+
+ [autofit] Improve Hebrew rendering.
+
+ This change introduces a new blue zone property
+ `AF_BLUE_PROPERTY_LATIN_LONG' to make the auto-hinter ignore short
+ top segments.
+
+ * src/autofit/afblue.dat: Fix Hebrew blue strings.
+ Use AF_BLUE_PROPERTY_LATIN_LONG for AF_BLUE_STRING_HEBREW_TOP.
+
+ * src/autofit/afblue.hin (AF_BLUE_PROPERTY_LATIN_LONG): New macro.
+
+ * src/autofit/afblue.c, src/autofit/afblue.h: Updated.
+
+ * src/autofit/aflatin.c (af_latin_metrics_init_blues): Handle
+ `AF_LATIN_IS_LONG_BLUE'.
+
+ * src/autofit/aflatin.h (AF_LATIN_IS_LONG_BLUE): New macro.
+
2013-08-28 Behdad Esfahbod <behdad@google.com>
[sfnt] Fix frame access while reading WOFF table directory.
diff --git a/src/autofit/afblue.c b/src/autofit/afblue.c
index 0947d2a..f025e1b 100644
--- a/src/autofit/afblue.c
+++ b/src/autofit/afblue.c
@@ -36,9 +36,9 @@
'\0',
'p', 'q', 'g', 'j', 'y', /* pqgjy */
'\0',
- '\xD7', '\x90', '\xD7', '\x91', '\xD7', '\x9D', '\xD7', '\xA4', '\xD7', '\xA9', '\xD7', '\x93', '\xD7', '\x92', /* אבםפשדג */
+ '\xD7', '\x91', '\xD7', '\x93', '\xD7', '\x94', '\xD7', '\x97', '\xD7', '\x9A', '\xD7', '\x9B', '\xD7', '\x9D', '\xD7', '\xA1', /* בדהחךכםס */
'\0',
- '\xD7', '\x90', '\xD7', '\x94', '\xD7', '\x97', '\xD7', '\x9B', '\xD7', '\x9E', '\xD7', '\xA1', /* אהחכמס */
+ '\xD7', '\x91', '\xD7', '\x98', '\xD7', '\x9B', '\xD7', '\x9D', '\xD7', '\xA1', '\xD7', '\xA6', /* בטכםסצ */
'\0',
'\xD7', '\xA7', '\xD7', '\x9A', '\xD7', '\x9F', '\xD7', '\xA3', '\xD7', '\xA5', /* קךןףץ */
#ifdef AF_CONFIG_OPTION_CJK
@@ -103,10 +103,11 @@
{ AF_BLUE_STRING_LATIN_SMALL, 0 },
{ AF_BLUE_STRING_LATIN_SMALL_MINOR, 0 },
{ AF_BLUE_STRING_MAX, 0 },
- { AF_BLUE_STRING_HEBREW_TOP, AF_BLUE_PROPERTY_LATIN_TOP },
- { AF_BLUE_STRING_HEBREW_BOTTOM, 0 },
- { AF_BLUE_STRING_HEBREW_DESCENDER, 0 },
- { AF_BLUE_STRING_MAX, 0 },
+ { AF_BLUE_STRING_HEBREW_TOP, AF_BLUE_PROPERTY_LATIN_TOP |
+ AF_BLUE_PROPERTY_LATIN_LONG },
+ { AF_BLUE_STRING_HEBREW_BOTTOM, 0 },
+ { AF_BLUE_STRING_HEBREW_DESCENDER, 0 },
+ { AF_BLUE_STRING_MAX, 0 },
#ifdef AF_CONFIG_OPTION_CJK
{ AF_BLUE_STRING_CJK_TOP_FILL, AF_BLUE_PROPERTY_CJK_TOP |
AF_BLUE_PROPERTY_CJK_FILL },
diff --git a/src/autofit/afblue.dat b/src/autofit/afblue.dat
index 5527b2c..af85fc3 100644
--- a/src/autofit/afblue.dat
+++ b/src/autofit/afblue.dat
@@ -77,9 +77,9 @@ AF_BLUE_STRING_ENUM AF_BLUE_STRINGS_ARRAY AF_BLUE_STRING_MAX_LEN:
"pqgjy"
AF_BLUE_STRING_HEBREW_TOP
- "אבםפשדג"
+ "בדהחךכםס"
AF_BLUE_STRING_HEBREW_BOTTOM
- "אהחכמס"
+ "בטכםסצ"
AF_BLUE_STRING_HEBREW_DESCENDER
"קךןףץ"
@@ -147,10 +147,11 @@ AF_BLUE_STRINGSET_ENUM AF_BLUE_STRINGSETS_ARRAY AF_BLUE_STRINGSET_MAX_LEN:
{ AF_BLUE_STRING_MAX, 0 }
AF_BLUE_STRINGSET_HEBR
- { AF_BLUE_STRING_HEBREW_TOP, AF_BLUE_PROPERTY_LATIN_TOP }
- { AF_BLUE_STRING_HEBREW_BOTTOM, 0 }
- { AF_BLUE_STRING_HEBREW_DESCENDER, 0 }
- { AF_BLUE_STRING_MAX, 0 }
+ { AF_BLUE_STRING_HEBREW_TOP, AF_BLUE_PROPERTY_LATIN_TOP |
+ AF_BLUE_PROPERTY_LATIN_LONG }
+ { AF_BLUE_STRING_HEBREW_BOTTOM, 0 }
+ { AF_BLUE_STRING_HEBREW_DESCENDER, 0 }
+ { AF_BLUE_STRING_MAX, 0 }
#ifdef AF_CONFIG_OPTION_CJK
diff --git a/src/autofit/afblue.h b/src/autofit/afblue.h
index 67f6777..cbe46b1 100644
--- a/src/autofit/afblue.h
+++ b/src/autofit/afblue.h
@@ -80,9 +80,9 @@ FT_BEGIN_HEADER
AF_BLUE_STRING_LATIN_SMALL = 26,
AF_BLUE_STRING_LATIN_SMALL_MINOR = 34,
AF_BLUE_STRING_HEBREW_TOP = 40,
- AF_BLUE_STRING_HEBREW_BOTTOM = 55,
- AF_BLUE_STRING_HEBREW_DESCENDER = 68,
- af_blue_1_1 = 78,
+ AF_BLUE_STRING_HEBREW_BOTTOM = 57,
+ AF_BLUE_STRING_HEBREW_DESCENDER = 70,
+ af_blue_1_1 = 80,
#ifdef AF_CONFIG_OPTION_CJK
AF_BLUE_STRING_CJK_TOP_FILL = af_blue_1_1 + 1,
AF_BLUE_STRING_CJK_TOP_UNFILL = af_blue_1_1 + 77,
@@ -129,6 +129,7 @@ FT_BEGIN_HEADER
/* is a safe bet. */
#define AF_BLUE_PROPERTY_LATIN_TOP ( 1 << 0 )
#define AF_BLUE_PROPERTY_LATIN_SMALL_TOP ( 1 << 1 )
+#define AF_BLUE_PROPERTY_LATIN_LONG ( 1 << 2 )
#define AF_BLUE_PROPERTY_CJK_HORIZ ( 1 << 0 )
#define AF_BLUE_PROPERTY_CJK_TOP ( 1 << 1 )
diff --git a/src/autofit/afblue.hin b/src/autofit/afblue.hin
index 424ca7e..a9f1ae1 100644
--- a/src/autofit/afblue.hin
+++ b/src/autofit/afblue.hin
@@ -98,6 +98,7 @@ FT_BEGIN_HEADER
/* is a safe bet. */
#define AF_BLUE_PROPERTY_LATIN_TOP ( 1 << 0 )
#define AF_BLUE_PROPERTY_LATIN_SMALL_TOP ( 1 << 1 )
+#define AF_BLUE_PROPERTY_LATIN_LONG ( 1 << 2 )
#define AF_BLUE_PROPERTY_CJK_HORIZ ( 1 << 0 )
#define AF_BLUE_PROPERTY_CJK_TOP ( 1 << 1 )
diff --git a/src/autofit/aflatin.c b/src/autofit/aflatin.c
index 93c9f31..7243fb9 100644
--- a/src/autofit/aflatin.c
+++ b/src/autofit/aflatin.c
@@ -219,9 +219,7 @@
/* we walk over the blue character strings as specified in the */
- /* script's entry in the `af_blue_stringset' array, finding its */
- /* top-most or bottom-most points (depending on the string */
- /* properties) */
+ /* script's entry in the `af_blue_stringset' array */
FT_TRACE5(( "latin blue zones computation\n"
"============================\n"
@@ -290,7 +288,7 @@
/* Avoid single-point contours since they are never rasterized. */
/* In some fonts, they correspond to mark attachment points */
- /* which are way outside of the glyph's real outline. */
+ /* that are way outside of the glyph's real outline. */
if ( last <= first )
continue;
@@ -319,8 +317,6 @@
best_contour_last = last;
}
}
-
- FT_TRACE5(( " U+%04lX: best_y = %5ld", ch, best_y ));
}
/* now check whether the point belongs to a straight or round */
@@ -403,6 +399,178 @@
} while ( next != best_point );
+ if ( AF_LATIN_IS_LONG_BLUE( bs ) )
+ {
+ /* If this flag is set, we have an additional constraint to */
+ /* get the blue zone distance: Find a segment of the topmost */
+ /* (or bottommost) contour that is longer than a heuristic */
+ /* threshold. This ensures that small bumps in the outline */
+ /* are ignored (for example, the `vertical serifs' found in */
+ /* many Hebrew glyph designs). */
+
+ /* If this segment is long enough, we are done. Otherwise, */
+ /* search the segment next to the extremum that is long */
+ /* enough, has the same direction, and a not too large */
+ /* vertical distance from the extremum. Note that the */
+ /* algorithm doesn't check whether the found segment is */
+ /* actually the one (vertically) nearest to the extremum. */
+
+ /* heuristic threshold value */
+ FT_Pos length_threshold = metrics->units_per_em / 25;
+
+
+ dist = FT_ABS( points[best_segment_last].x -
+ points[best_segment_first].x );
+
+ if ( dist < length_threshold &&
+ best_segment_last - best_segment_first + 2 <=
+ best_contour_last - best_contour_first )
+ {
+ /* heuristic threshold value */
+ FT_Pos height_threshold = metrics->units_per_em / 4;
+
+ FT_Int first;
+ FT_Int last;
+ FT_Bool hit;
+
+ FT_Bool left2right;
+
+
+ /* compute direction */
+ prev = best_point;
+
+ do
+ {
+ if ( prev > best_contour_first )
+ prev--;
+ else
+ prev = best_contour_last;
+
+ if ( points[prev].x != best_x )
+ break;
+
+ } while ( prev != best_point );
+
+ /* skip glyph for the degenerate case */
+ if ( prev == best_point )
+ continue;
+
+ left2right = FT_BOOL( points[prev].x < points[best_point].x );
+
+ first = best_segment_last;
+ last = first;
+ hit = 0;
+
+ do
+ {
+ FT_Bool l2r;
+ FT_Pos d;
+ FT_Int p_first, p_last;
+
+
+ if ( !hit )
+ {
+ /* no hit; adjust first point */
+ first = last;
+
+ /* also adjust first and last on point */
+ if ( FT_CURVE_TAG( outline.tags[first] ) ==
+ FT_CURVE_TAG_ON )
+ {
+ p_first = first;
+ p_last = first;
+ }
+ else
+ {
+ p_first = -1;
+ p_last = -1;
+ }
+
+ hit = 1;
+ }
+
+ if ( last < best_contour_last )
+ last++;
+ else
+ last = best_contour_first;
+
+ if ( FT_ABS( best_y - points[first].y ) > height_threshold )
+ {
+ /* vertical distance too large */
+ hit = 0;
+ continue;
+ }
+
+ /* same test as above */
+ dist = FT_ABS( points[last].y - points[first].y );
+ if ( dist > 5 )
+ if ( FT_ABS( points[last].x - points[first].x ) <=
+ 20 * dist )
+ {
+ hit = 0;
+ continue;
+ }
+
+ if ( FT_CURVE_TAG( outline.tags[last] ) == FT_CURVE_TAG_ON )
+ {
+ p_last = last;
+ if ( p_first < 0 )
+ p_first = last;
+ }
+
+ l2r = FT_BOOL( points[first].x < points[last].x );
+ d = FT_ABS( points[last].x - points[first].x );
+
+ if ( l2r == left2right &&
+ d >= length_threshold )
+ {
+ /* all constraints are met; update segment after finding */
+ /* its end */
+ do
+ {
+ if ( last < best_contour_last )
+ last++;
+ else
+ last = best_contour_first;
+
+ d = FT_ABS( points[last].y - points[first].y );
+ if ( d > 5 )
+ if ( FT_ABS( points[next].x - points[first].x ) <=
+ 20 * dist )
+ {
+ last--;
+ break;
+ }
+
+ p_last = last;
+
+ if ( FT_CURVE_TAG( outline.tags[last] ) ==
+ FT_CURVE_TAG_ON )
+ {
+ p_last = last;
+ if ( p_first < 0 )
+ p_first = last;
+ }
+
+ } while ( last != best_segment_first );
+
+ best_y = points[first].y;
+
+ best_segment_first = first;
+ best_segment_last = last;
+
+ best_on_point_first = p_first;
+ best_on_point_last = p_last;
+
+ break;
+ }
+
+ } while ( last != best_segment_first );
+ }
+ }
+
+ FT_TRACE5(( " U+%04lX: best_y = %5ld", ch, best_y ));
+
/* now set the `round' flag depending on the segment's kind: */
/* */
/* - if the horizontal distance between the first and last */
diff --git a/src/autofit/aflatin.h b/src/autofit/aflatin.h
index 8581fe5..7d294aa 100644
--- a/src/autofit/aflatin.h
+++ b/src/autofit/aflatin.h
@@ -65,6 +65,8 @@ FT_BEGIN_HEADER
( (b)->properties & AF_BLUE_PROPERTY_LATIN_TOP )
#define AF_LATIN_IS_SMALL_TOP_BLUE( b ) \
( (b)->properties & AF_BLUE_PROPERTY_LATIN_SMALL_TOP )
+#define AF_LATIN_IS_LONG_BLUE( b ) \
+ ( (b)->properties & AF_BLUE_PROPERTY_LATIN_LONG )
#define AF_LATIN_MAX_WIDTHS 16