summaryrefslogtreecommitdiffstats
path: root/src/3rdparty/freetype/src/autofit/aflatin.c
diff options
context:
space:
mode:
authorLiang Qi <liang.qi@qt.io>2019-08-14 11:13:36 +0200
committerLiang Qi <liang.qi@qt.io>2019-10-30 08:48:18 +0100
commit58f56950848bae9c90da3873090c7698e0128b12 (patch)
tree0b3127cd313aaf34d59355deed2e2acc5341eff3 /src/3rdparty/freetype/src/autofit/aflatin.c
parentc51ca1d1b232ce1d6eaa9c6dd85de127e825d3af (diff)
Update bundled Freetype to 2.10.1
[ChangeLog][Freetype] Upgraded bundled Freetype version to 2.10.1. Fixes: QTBUG-77466 Change-Id: I1de8b8b03e0ffd0b17eeafff1017df7c638c9279 Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>
Diffstat (limited to 'src/3rdparty/freetype/src/autofit/aflatin.c')
-rw-r--r--src/3rdparty/freetype/src/autofit/aflatin.c304
1 files changed, 177 insertions, 127 deletions
diff --git a/src/3rdparty/freetype/src/autofit/aflatin.c b/src/3rdparty/freetype/src/autofit/aflatin.c
index 9f1b54056f..27d4024882 100644
--- a/src/3rdparty/freetype/src/autofit/aflatin.c
+++ b/src/3rdparty/freetype/src/autofit/aflatin.c
@@ -1,19 +1,19 @@
-/***************************************************************************/
-/* */
-/* aflatin.c */
-/* */
-/* Auto-fitter hinting routines for latin writing system (body). */
-/* */
-/* Copyright 2003-2018 by */
-/* David Turner, Robert Wilhelm, and Werner Lemberg. */
-/* */
-/* This file is part of the FreeType project, and may only be used, */
-/* modified, and distributed under the terms of the FreeType project */
-/* license, LICENSE.TXT. By continuing to use, modify, or distribute */
-/* this file you indicate that you have read the license and */
-/* understand and accept it fully. */
-/* */
-/***************************************************************************/
+/****************************************************************************
+ *
+ * aflatin.c
+ *
+ * Auto-fitter hinting routines for latin writing system (body).
+ *
+ * Copyright (C) 2003-2019 by
+ * David Turner, Robert Wilhelm, and Werner Lemberg.
+ *
+ * This file is part of the FreeType project, and may only be used,
+ * modified, and distributed under the terms of the FreeType project
+ * license, LICENSE.TXT. By continuing to use, modify, or distribute
+ * this file you indicate that you have read the license and
+ * understand and accept it fully.
+ *
+ */
#include <ft2build.h>
@@ -21,7 +21,6 @@
#include FT_INTERNAL_DEBUG_H
#include "afglobal.h"
-#include "afpic.h"
#include "aflatin.h"
#include "aferrors.h"
@@ -31,14 +30,14 @@
#endif
- /*************************************************************************/
- /* */
- /* The macro FT_COMPONENT is used in trace mode. It is an implicit */
- /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */
- /* messages during execution. */
- /* */
+ /**************************************************************************
+ *
+ * The macro FT_COMPONENT is used in trace mode. It is an implicit
+ * parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log
+ * messages during execution.
+ */
#undef FT_COMPONENT
-#define FT_COMPONENT trace_aflatin
+#define FT_COMPONENT aflatin
/* needed for computation of round vs. flat segments */
@@ -83,24 +82,30 @@
AF_LatinMetricsRec dummy[1];
AF_Scaler scaler = &dummy->root.scaler;
-#ifdef FT_CONFIG_OPTION_PIC
- AF_FaceGlobals globals = metrics->root.globals;
-#endif
-
AF_StyleClass style_class = metrics->root.style_class;
- AF_ScriptClass script_class = AF_SCRIPT_CLASSES_GET
- [style_class->script];
+ AF_ScriptClass script_class = af_script_classes[style_class->script];
+
+ /* If HarfBuzz is not available, we need a pointer to a single */
+ /* unsigned long value. */
+#ifdef FT_CONFIG_OPTION_USE_HARFBUZZ
+ void* shaper_buf;
+#else
+ FT_ULong shaper_buf_;
+ void* shaper_buf = &shaper_buf_;
+#endif
- void* shaper_buf;
const char* p;
#ifdef FT_DEBUG_LEVEL_TRACE
FT_ULong ch = 0;
#endif
- p = script_class->standard_charstring;
- shaper_buf = af_shaper_buf_create( face );
+ p = script_class->standard_charstring;
+
+#ifdef FT_CONFIG_OPTION_USE_HARFBUZZ
+ shaper_buf = af_shaper_buf_create( face );
+#endif
/*
* We check a list of standard characters to catch features like
* `c2sc' (small caps from caps) that don't contain lowercase letters
@@ -144,7 +149,11 @@
af_shaper_buf_destroy( face, shaper_buf );
if ( !glyph_index )
+ {
+ FT_TRACE5(( "standard character missing;"
+ " using fallback stem widths\n" ));
goto Exit;
+ }
FT_TRACE5(( "standard character: U+%04lX (glyph index %d)\n",
ch, glyph_index ));
@@ -186,10 +195,10 @@
goto Exit;
/*
- * We assume that the glyphs selected for the stem width
- * computation are `featureless' enough so that the linking
- * algorithm works fine without adjustments of its scoring
- * function.
+ * We assume that the glyphs selected for the stem width
+ * computation are `featureless' enough so that the linking
+ * algorithm works fine without adjustments of its scoring
+ * function.
*/
af_latin_hints_link_segments( hints,
0,
@@ -307,7 +316,7 @@
/* Find all blue zones. Flat segments give the reference points, */
/* round segments the overshoot positions. */
- static void
+ static int
af_latin_metrics_init_blues( AF_LatinMetrics metrics,
FT_Face face )
{
@@ -329,7 +338,14 @@
FT_Pos flat_threshold = FLAT_THRESHOLD( metrics->units_per_em );
- void* shaper_buf;
+ /* If HarfBuzz is not available, we need a pointer to a single */
+ /* unsigned long value. */
+#ifdef FT_CONFIG_OPTION_USE_HARFBUZZ
+ void* shaper_buf;
+#else
+ FT_ULong shaper_buf_;
+ void* shaper_buf = &shaper_buf_;
+#endif
/* we walk over the blue character strings as specified in the */
@@ -339,7 +355,9 @@
"============================\n"
"\n" ));
+#ifdef FT_CONFIG_OPTION_USE_HARFBUZZ
shaper_buf = af_shaper_buf_create( face );
+#endif
for ( ; bs->string != AF_BLUE_STRING_MAX; bs++ )
{
@@ -884,8 +902,8 @@
if ( num_flats == 0 && num_rounds == 0 )
{
/*
- * we couldn't find a single glyph to compute this blue zone,
- * we will simply ignore it then
+ * we couldn't find a single glyph to compute this blue zone,
+ * we will simply ignore it then
*/
FT_TRACE5(( " empty\n" ));
continue;
@@ -967,10 +985,11 @@
af_shaper_buf_destroy( face, shaper_buf );
- /* we finally check whether blue zones are ordered; */
- /* `ref' and `shoot' values of two blue zones must not overlap */
if ( axis->blue_count )
{
+ /* we finally check whether blue zones are ordered; */
+ /* `ref' and `shoot' values of two blue zones must not overlap */
+
FT_UInt i;
AF_LatinBlue blue_sorted[AF_BLUE_STRINGSET_MAX_LEN + 2];
@@ -1019,11 +1038,34 @@
*a ));
}
}
+
+ FT_TRACE5(( "\n" ));
+
+ return 0;
}
+ else
+ {
+ /* disable hinting for the current style if there are no blue zones */
- FT_TRACE5(( "\n" ));
+ AF_FaceGlobals globals = metrics->root.globals;
+ FT_UShort* gstyles = globals->glyph_styles;
+
+ FT_Long i;
+
+
+ FT_TRACE5(( "no blue zones found:"
+ " hinting disabled for this style\n" ));
+
+ for ( i = 0; i < globals->glyph_count; i++ )
+ {
+ if ( ( gstyles[i] & AF_STYLE_MASK ) == sc->style )
+ gstyles[i] = AF_STYLE_NONE_DFLT;
+ }
- return;
+ FT_TRACE5(( "\n" ));
+
+ return 1;
+ }
}
@@ -1036,15 +1078,25 @@
FT_Bool started = 0, same_width = 1;
FT_Fixed advance = 0, old_advance = 0;
- void* shaper_buf;
+ /* If HarfBuzz is not available, we need a pointer to a single */
+ /* unsigned long value. */
+#ifdef FT_CONFIG_OPTION_USE_HARFBUZZ
+ void* shaper_buf;
+#else
+ FT_ULong shaper_buf_;
+ void* shaper_buf = &shaper_buf_;
+#endif
/* in all supported charmaps, digits have character codes 0x30-0x39 */
const char digits[] = "0 1 2 3 4 5 6 7 8 9";
const char* p;
- p = digits;
+ p = digits;
+
+#ifdef FT_CONFIG_OPTION_USE_HARFBUZZ
shaper_buf = af_shaper_buf_create( face );
+#endif
while ( *p )
{
@@ -1092,6 +1144,8 @@
af_latin_metrics_init( AF_LatinMetrics metrics,
FT_Face face )
{
+ FT_Error error = FT_Err_Ok;
+
FT_CharMap oldmap = face->charmap;
@@ -1100,12 +1154,18 @@
if ( !FT_Select_Charmap( face, FT_ENCODING_UNICODE ) )
{
af_latin_metrics_init_widths( metrics, face );
- af_latin_metrics_init_blues( metrics, face );
+ if ( af_latin_metrics_init_blues( metrics, face ) )
+ {
+ /* use internal error code to indicate missing blue zones */
+ error = -1;
+ goto Exit;
+ }
af_latin_metrics_check_digits( metrics, face );
}
+ Exit:
FT_Set_Charmap( face, oldmap );
- return FT_Err_Ok;
+ return error;
}
@@ -1283,7 +1343,7 @@
/* an extra-light axis corresponds to a standard width that is */
/* smaller than 5/8 pixels */
axis->extra_light =
- (FT_Bool)( FT_MulFix( axis->standard_width, scale ) < 32 + 8 );
+ FT_BOOL( FT_MulFix( axis->standard_width, scale ) < 32 + 8 );
#ifdef FT_DEBUG_LEVEL_TRACE
if ( axis->extra_light )
@@ -1419,13 +1479,13 @@
nn,
blue->ref.org,
blue->ref.fit / 64.0,
- blue->flags & AF_LATIN_BLUE_ACTIVE ? ""
- : " (inactive)",
+ ( blue->flags & AF_LATIN_BLUE_ACTIVE ) ? ""
+ : " (inactive)",
nn,
blue->shoot.org,
blue->shoot.fit / 64.0,
- blue->flags & AF_LATIN_BLUE_ACTIVE ? ""
- : " (inactive)" ));
+ ( blue->flags & AF_LATIN_BLUE_ACTIVE ) ? ""
+ : " (inactive)" ));
}
#endif
}
@@ -1967,17 +2027,17 @@
if ( len >= len_threshold )
{
/*
- * The score is the sum of two demerits indicating the
- * `badness' of a fit, measured along the segments' main axis
- * and orthogonal to it, respectively.
+ * The score is the sum of two demerits indicating the
+ * `badness' of a fit, measured along the segments' main axis
+ * and orthogonal to it, respectively.
*
- * o The less overlapping along the main axis, the worse it
- * is, causing a larger demerit.
+ * - The less overlapping along the main axis, the worse it
+ * is, causing a larger demerit.
*
- * o The nearer the orthogonal distance to a stem width, the
- * better it is, causing a smaller demerit. For simplicity,
- * however, we only increase the demerit for values that
- * exceed the largest stem width.
+ * - The nearer the orthogonal distance to a stem width, the
+ * better it is, causing a smaller demerit. For simplicity,
+ * however, we only increase the demerit for values that
+ * exceed the largest stem width.
*/
FT_Pos dist = pos2 - pos1;
@@ -2049,13 +2109,8 @@
FT_Memory memory = hints->memory;
AF_LatinAxis laxis = &((AF_LatinMetrics)hints->metrics)->axis[dim];
-#ifdef FT_CONFIG_OPTION_PIC
- AF_FaceGlobals globals = hints->metrics->globals;
-#endif
-
AF_StyleClass style_class = hints->metrics->style_class;
- AF_ScriptClass script_class = AF_SCRIPT_CLASSES_GET
- [style_class->script];
+ AF_ScriptClass script_class = af_script_classes[style_class->script];
FT_Bool top_to_bottom_hinting = 0;
@@ -2086,9 +2141,9 @@
top_to_bottom_hinting = script_class->top_to_bottom_hinting;
/*
- * We ignore all segments that are less than 1 pixel in length
- * to avoid many problems with serif fonts. We compute the
- * corresponding threshold in font units.
+ * We ignore all segments that are less than 1 pixel in length
+ * to avoid many problems with serif fonts. We compute the
+ * corresponding threshold in font units.
*/
if ( dim == AF_DIMENSION_HORZ )
segment_length_threshold = FT_DivFix( 64, hints->y_scale );
@@ -2096,26 +2151,26 @@
segment_length_threshold = 0;
/*
- * Similarly, we ignore segments that have a width delta
- * larger than 0.5px (i.e., a width larger than 1px).
+ * Similarly, we ignore segments that have a width delta
+ * larger than 0.5px (i.e., a width larger than 1px).
*/
segment_width_threshold = FT_DivFix( 32, scale );
- /*********************************************************************/
- /* */
- /* We begin by generating a sorted table of edges for the current */
- /* direction. To do so, we simply scan each segment and try to find */
- /* an edge in our table that corresponds to its position. */
- /* */
- /* If no edge is found, we create and insert a new edge in the */
- /* sorted table. Otherwise, we simply add the segment to the edge's */
- /* list which gets processed in the second step to compute the */
- /* edge's properties. */
- /* */
- /* Note that the table of edges is sorted along the segment/edge */
- /* position. */
- /* */
- /*********************************************************************/
+ /**********************************************************************
+ *
+ * We begin by generating a sorted table of edges for the current
+ * direction. To do so, we simply scan each segment and try to find
+ * an edge in our table that corresponds to its position.
+ *
+ * If no edge is found, we create and insert a new edge in the
+ * sorted table. Otherwise, we simply add the segment to the edge's
+ * list which gets processed in the second step to compute the
+ * edge's properties.
+ *
+ * Note that the table of edges is sorted along the segment/edge
+ * position.
+ *
+ */
/* assure that edge distance threshold is at most 0.25px */
edge_distance_threshold = FT_MulFix( laxis->edge_distance_threshold,
@@ -2237,17 +2292,17 @@
}
- /******************************************************************/
- /* */
- /* Good, we now compute each edge's properties according to the */
- /* segments found on its position. Basically, these are */
- /* */
- /* - the edge's main direction */
- /* - stem edge, serif edge or both (which defaults to stem then) */
- /* - rounded edge, straight or both (which defaults to straight) */
- /* - link for edge */
- /* */
- /******************************************************************/
+ /*******************************************************************
+ *
+ * Good, we now compute each edge's properties according to the
+ * segments found on its position. Basically, these are
+ *
+ * - the edge's main direction
+ * - stem edge, serif edge or both (which defaults to stem then)
+ * - rounded edge, straight or both (which defaults to straight)
+ * - link for edge
+ *
+ */
/* first of all, set the `edge' field in each segment -- this is */
/* required in order to compute edge links */
@@ -2309,9 +2364,9 @@
/* check for links -- if seg->serif is set, then seg->link must */
/* be ignored */
- is_serif = (FT_Bool)( seg->serif &&
- seg->serif->edge &&
- seg->serif->edge != edge );
+ is_serif = FT_BOOL( seg->serif &&
+ seg->serif->edge &&
+ seg->serif->edge != edge );
if ( ( seg->link && seg->link->edge ) || is_serif )
{
@@ -2546,8 +2601,8 @@
af_glyph_hints_rescale( hints, (AF_StyleMetrics)metrics );
/*
- * correct x_scale and y_scale if needed, since they may have
- * been modified by `af_latin_metrics_scale_dim' above
+ * correct x_scale and y_scale if needed, since they may have
+ * been modified by `af_latin_metrics_scale_dim' above
*/
hints->x_scale = metrics->axis[AF_DIMENSION_HORZ].scale;
hints->x_delta = metrics->axis[AF_DIMENSION_HORZ].delta;
@@ -2566,21 +2621,21 @@
other_flags = 0;
/*
- * We snap the width of vertical stems for the monochrome and
- * horizontal LCD rendering targets only.
+ * We snap the width of vertical stems for the monochrome and
+ * horizontal LCD rendering targets only.
*/
if ( mode == FT_RENDER_MODE_MONO || mode == FT_RENDER_MODE_LCD )
other_flags |= AF_LATIN_HINTS_HORZ_SNAP;
/*
- * We snap the width of horizontal stems for the monochrome and
- * vertical LCD rendering targets only.
+ * We snap the width of horizontal stems for the monochrome and
+ * vertical LCD rendering targets only.
*/
if ( mode == FT_RENDER_MODE_MONO || mode == FT_RENDER_MODE_LCD_V )
other_flags |= AF_LATIN_HINTS_VERT_SNAP;
/*
- * We adjust stems to full pixels unless in `light' or `lcd' mode.
+ * We adjust stems to full pixels unless in `light' or `lcd' mode.
*/
if ( mode != FT_RENDER_MODE_LIGHT && mode != FT_RENDER_MODE_LCD )
other_flags |= AF_LATIN_HINTS_STEM_ADJUST;
@@ -2589,11 +2644,11 @@
other_flags |= AF_LATIN_HINTS_MONO;
/*
- * In `light' or `lcd' mode we disable horizontal hinting completely.
- * We also do it if the face is italic.
+ * In `light' or `lcd' mode we disable horizontal hinting completely.
+ * We also do it if the face is italic.
*
- * However, if warping is enabled (which only works in `light' hinting
- * mode), advance widths get adjusted, too.
+ * However, if warping is enabled (which only works in `light' hinting
+ * mode), advance widths get adjusted, too.
*/
if ( mode == FT_RENDER_MODE_LIGHT || mode == FT_RENDER_MODE_LCD ||
( face->style_flags & FT_STYLE_FLAG_ITALIC ) != 0 )
@@ -2936,13 +2991,8 @@
AF_Edge anchor = NULL;
FT_Int has_serifs = 0;
-#ifdef FT_CONFIG_OPTION_PIC
- AF_FaceGlobals globals = hints->metrics->globals;
-#endif
-
AF_StyleClass style_class = hints->metrics->style_class;
- AF_ScriptClass script_class = AF_SCRIPT_CLASSES_GET
- [style_class->script];
+ AF_ScriptClass script_class = af_script_classes[style_class->script];
FT_Bool top_to_bottom_hinting = 0;
@@ -2976,12 +3026,12 @@
edge2 = edge->link;
/*
- * If a stem contains both a neutral and a non-neutral blue zone,
- * skip the neutral one. Otherwise, outlines with different
- * directions might be incorrectly aligned at the same vertical
- * position.
+ * If a stem contains both a neutral and a non-neutral blue zone,
+ * skip the neutral one. Otherwise, outlines with different
+ * directions might be incorrectly aligned at the same vertical
+ * position.
*
- * If we have two neutral blue zones, skip one of them.
+ * If we have two neutral blue zones, skip one of them.
*
*/
if ( edge->blue_edge && edge2 && edge2->blue_edge )
@@ -3344,8 +3394,8 @@
if ( has_serifs || !anchor )
{
/*
- * now hint the remaining edges (serifs and single) in order
- * to complete our processing
+ * now hint the remaining edges (serifs and single) in order
+ * to complete our processing
*/
for ( edge = edges; edge < edge_limit; edge++ )
{