summaryrefslogtreecommitdiff
path: root/Build/source/libs/freetype2/freetype-src/src/sdf
diff options
context:
space:
mode:
authorAkira Kakuto <kakuto@fuk.kindai.ac.jp>2022-05-07 06:06:35 +0000
committerAkira Kakuto <kakuto@fuk.kindai.ac.jp>2022-05-07 06:06:35 +0000
commita056f660b41815752ccb53f2182f24de721393aa (patch)
tree30eec2d7fde35ce87c344e67cf37677be4c4bbd7 /Build/source/libs/freetype2/freetype-src/src/sdf
parent2f0167f2576a7c29b556a8f15e44b062d4750f46 (diff)
freetype 2.12.1 (trial)
git-svn-id: svn://tug.org/texlive/trunk@63245 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build/source/libs/freetype2/freetype-src/src/sdf')
-rw-r--r--Build/source/libs/freetype2/freetype-src/src/sdf/ftbsdf.c36
-rw-r--r--Build/source/libs/freetype2/freetype-src/src/sdf/ftsdf.c101
-rw-r--r--Build/source/libs/freetype2/freetype-src/src/sdf/ftsdf.h2
-rw-r--r--Build/source/libs/freetype2/freetype-src/src/sdf/ftsdfcommon.c2
-rw-r--r--Build/source/libs/freetype2/freetype-src/src/sdf/ftsdfcommon.h4
-rw-r--r--Build/source/libs/freetype2/freetype-src/src/sdf/ftsdferrs.h2
-rw-r--r--Build/source/libs/freetype2/freetype-src/src/sdf/ftsdfrend.c20
-rw-r--r--Build/source/libs/freetype2/freetype-src/src/sdf/ftsdfrend.h2
-rw-r--r--Build/source/libs/freetype2/freetype-src/src/sdf/module.mk2
-rw-r--r--Build/source/libs/freetype2/freetype-src/src/sdf/rules.mk2
-rw-r--r--Build/source/libs/freetype2/freetype-src/src/sdf/sdf.c2
11 files changed, 110 insertions, 65 deletions
diff --git a/Build/source/libs/freetype2/freetype-src/src/sdf/ftbsdf.c b/Build/source/libs/freetype2/freetype-src/src/sdf/ftbsdf.c
index 8da5c9d9e07..1328ac49880 100644
--- a/Build/source/libs/freetype2/freetype-src/src/sdf/ftbsdf.c
+++ b/Build/source/libs/freetype2/freetype-src/src/sdf/ftbsdf.c
@@ -4,7 +4,7 @@
*
* Signed Distance Field support for bitmap fonts (body only).
*
- * Copyright (C) 2020-2021 by
+ * Copyright (C) 2020-2022 by
* David Turner, Robert Wilhelm, and Werner Lemberg.
*
* Written by Anuj Verma.
@@ -177,11 +177,11 @@
*
* @Fields:
* dist ::
- * Vector length of the `near` parameter. Can be squared or absolute
+ * Vector length of the `prox` parameter. Can be squared or absolute
* depending on the `USE_SQUARED_DISTANCES` macro defined in file
* `ftsdfcommon.h`.
*
- * near ::
+ * prox ::
* Vector to the nearest edge. Can also be interpreted as shortest
* distance of a point.
*
@@ -194,7 +194,7 @@
typedef struct ED_
{
FT_16D16 dist;
- FT_16D16_Vec near;
+ FT_16D16_Vec prox;
FT_Byte alpha;
} ED;
@@ -595,18 +595,18 @@
worker->rows ) )
{
/* approximate the edge distance for edge pixels */
- ed[index].near = compute_edge_distance( ed + index,
+ ed[index].prox = compute_edge_distance( ed + index,
i, j,
worker->width,
worker->rows );
- ed[index].dist = VECTOR_LENGTH_16D16( ed[index].near );
+ ed[index].dist = VECTOR_LENGTH_16D16( ed[index].prox );
}
else
{
/* for non-edge pixels assign far away distances */
ed[index].dist = 400 * ONE;
- ed[index].near.x = 200 * ONE;
- ed[index].near.y = 200 * ONE;
+ ed[index].prox.x = 200 * ONE;
+ ed[index].prox.y = 200 * ONE;
}
}
}
@@ -756,8 +756,6 @@
byte = (FT_Byte)( 1 << mod );
t[t_index].alpha = pixel & byte ? 255 : 0;
-
- pixel = 0;
}
}
}
@@ -873,7 +871,7 @@
if ( dist < current->dist )
{
- dist_vec = to_check->near;
+ dist_vec = to_check->prox;
dist_vec.x += x_offset * ONE;
dist_vec.y += y_offset * ONE;
@@ -882,7 +880,7 @@
if ( dist < current->dist )
{
current->dist = dist;
- current->near = dist_vec;
+ current->prox = dist_vec;
}
}
}
@@ -1098,7 +1096,7 @@
FT_Int i, j;
FT_SDFFormat* t_buffer;
- FT_16D16 spread;
+ FT_16D16 sp_sq, spread;
if ( !worker || !target )
@@ -1118,11 +1116,13 @@
goto Exit;
}
+ spread = FT_INT_16D16( worker->params.spread );
+
#if USE_SQUARED_DISTANCES
- spread = FT_INT_16D16( worker->params.spread *
- worker->params.spread );
+ sp_sq = FT_INT_16D16( worker->params.spread *
+ worker->params.spread );
#else
- spread = FT_INT_16D16( worker->params.spread );
+ sp_sq = FT_INT_16D16( worker->params.spread );
#endif
for ( j = 0; j < r; j++ )
@@ -1138,8 +1138,8 @@
index = j * w + i;
dist = worker->distance_map[index].dist;
- if ( dist < 0 || dist > spread )
- dist = spread;
+ if ( dist < 0 || dist > sp_sq )
+ dist = sp_sq;
#if USE_SQUARED_DISTANCES
dist = square_root( dist );
diff --git a/Build/source/libs/freetype2/freetype-src/src/sdf/ftsdf.c b/Build/source/libs/freetype2/freetype-src/src/sdf/ftsdf.c
index f69cf49b471..ffac8bf4659 100644
--- a/Build/source/libs/freetype2/freetype-src/src/sdf/ftsdf.c
+++ b/Build/source/libs/freetype2/freetype-src/src/sdf/ftsdf.c
@@ -4,7 +4,7 @@
*
* Signed Distance Field support for outline fonts (body).
*
- * Copyright (C) 2020-2021 by
+ * Copyright (C) 2020-2022 by
* David Turner, Robert Wilhelm, and Werner Lemberg.
*
* Written by Anuj Verma.
@@ -497,7 +497,7 @@
goto Exit;
}
- if ( !FT_QALLOC( ptr, sizeof ( *ptr ) ) )
+ if ( !FT_QNEW( ptr ) )
{
*ptr = null_edge;
*edge = ptr;
@@ -536,7 +536,7 @@
goto Exit;
}
- if ( !FT_QALLOC( ptr, sizeof ( *ptr ) ) )
+ if ( !FT_QNEW( ptr ) )
{
*ptr = null_contour;
*contour = ptr;
@@ -591,7 +591,7 @@
goto Exit;
}
- if ( !FT_QALLOC( ptr, sizeof ( *ptr ) ) )
+ if ( !FT_QNEW( ptr ) )
{
*ptr = null_shape;
ptr->memory = memory;
@@ -738,6 +738,18 @@
contour = shape->contours;
+ /* If the control point coincides with any of the end points */
+ /* then it is a line and should be treated as one to avoid */
+ /* unnecessary complexity later in the algorithm. */
+ if ( ( contour->last_pos.x == control_1->x &&
+ contour->last_pos.y == control_1->y ) ||
+ ( control_1->x == to->x &&
+ control_1->y == to->y ) )
+ {
+ sdf_line_to( to, user );
+ goto Exit;
+ }
+
FT_CALL( sdf_edge_new( memory, &edge ) );
edge->edge_type = SDF_EDGE_CONIC;
@@ -764,9 +776,9 @@
const FT_26D6_Vec* to,
void* user )
{
- SDF_Shape* shape = ( SDF_Shape* )user;
- SDF_Edge* edge = NULL;
- SDF_Contour* contour = NULL;
+ SDF_Shape* shape = ( SDF_Shape* )user;
+ SDF_Edge* edge = NULL;
+ SDF_Contour* contour = NULL;
FT_Error error = FT_Err_Ok;
FT_Memory memory = shape->memory;
@@ -1065,7 +1077,7 @@
static FT_Error
split_sdf_conic( FT_Memory memory,
FT_26D6_Vec* control_points,
- FT_Int max_splits,
+ FT_UInt max_splits,
SDF_Edge** out )
{
FT_Error error = FT_Err_Ok;
@@ -1134,26 +1146,41 @@
static FT_Error
split_sdf_cubic( FT_Memory memory,
FT_26D6_Vec* control_points,
- FT_Int max_splits,
+ FT_UInt max_splits,
SDF_Edge** out )
{
- FT_Error error = FT_Err_Ok;
- FT_26D6_Vec cpos[7];
- SDF_Edge* left,* right;
+ FT_Error error = FT_Err_Ok;
+ FT_26D6_Vec cpos[7];
+ SDF_Edge* left, *right;
+ const FT_26D6 threshold = ONE_PIXEL / 4;
- if ( !memory || !out )
+ if ( !memory || !out )
{
error = FT_THROW( Invalid_Argument );
goto Exit;
}
- /* split the conic */
+ /* split the cubic */
cpos[0] = control_points[0];
cpos[1] = control_points[1];
cpos[2] = control_points[2];
cpos[3] = control_points[3];
+ /* If the segment is flat enough we won't get any benefit by */
+ /* splitting it further, so we can just stop splitting. */
+ /* */
+ /* Check the deviation of the Bezier curve and stop if it is */
+ /* smaller than the pre-defined `threshold` value. */
+ if ( FT_ABS( 2 * cpos[0].x - 3 * cpos[1].x + cpos[3].x ) < threshold &&
+ FT_ABS( 2 * cpos[0].y - 3 * cpos[1].y + cpos[3].y ) < threshold &&
+ FT_ABS( cpos[0].x - 3 * cpos[2].x + 2 * cpos[3].x ) < threshold &&
+ FT_ABS( cpos[0].y - 3 * cpos[2].y + 2 * cpos[3].y ) < threshold )
+ {
+ split_cubic( cpos );
+ goto Append;
+ }
+
split_cubic( cpos );
/* If max number of splits is done */
@@ -1250,13 +1277,32 @@
/* Subdivide the curve and add it to the list. */
{
FT_26D6_Vec ctrls[3];
+ FT_26D6 dx, dy;
+ FT_UInt num_splits;
ctrls[0] = edge->start_pos;
ctrls[1] = edge->control_a;
ctrls[2] = edge->end_pos;
- error = split_sdf_conic( memory, ctrls, 32, &new_edges );
+ dx = FT_ABS( ctrls[2].x + ctrls[0].x - 2 * ctrls[1].x );
+ dy = FT_ABS( ctrls[2].y + ctrls[0].y - 2 * ctrls[1].y );
+ if ( dx < dy )
+ dx = dy;
+
+ /* Calculate the number of necessary bisections. Each */
+ /* bisection causes a four-fold reduction of the deviation, */
+ /* hence we bisect the Bezier curve until the deviation */
+ /* becomes less than 1/8th of a pixel. For more details */
+ /* check file `ftgrays.c`. */
+ num_splits = 1;
+ while ( dx > ONE_PIXEL / 8 )
+ {
+ dx >>= 2;
+ num_splits <<= 1;
+ }
+
+ error = split_sdf_conic( memory, ctrls, num_splits, &new_edges );
}
break;
@@ -1277,9 +1323,11 @@
default:
error = FT_THROW( Invalid_Argument );
- goto Exit;
}
+ if ( error != FT_Err_Ok )
+ goto Exit;
+
edges = edges->next;
}
@@ -2966,7 +3014,7 @@
diff = current_dist.distance - min_dist.distance;
- if ( FT_ABS(diff ) < CORNER_CHECK_EPSILON )
+ if ( FT_ABS( diff ) < CORNER_CHECK_EPSILON )
min_dist = resolve_corner( min_dist, current_dist );
else if ( diff < 0 )
min_dist = current_dist;
@@ -3240,7 +3288,7 @@
buffer = (FT_SDFFormat*)bitmap->buffer;
if ( USE_SQUARED_DISTANCES )
- sp_sq = fixed_spread * fixed_spread;
+ sp_sq = FT_INT_16D16( (FT_Int)( spread * spread ) );
else
sp_sq = fixed_spread;
@@ -3284,6 +3332,7 @@
FT_26D6_Vec grid_point = zero_vector;
SDF_Signed_Distance dist = max_sdf;
FT_UInt index = 0;
+ FT_16D16 diff = 0;
if ( x < 0 || x >= width )
@@ -3311,7 +3360,7 @@
if ( dist.distance > sp_sq )
continue;
- /* square_root the values and fit in a 6.10 fixed-point */
+ /* take the square root of the distance if required */
if ( USE_SQUARED_DISTANCES )
dist.distance = square_root( dist.distance );
@@ -3323,11 +3372,15 @@
/* check whether the pixel is set or not */
if ( dists[index].sign == 0 )
dists[index] = dist;
- else if ( dists[index].distance > dist.distance )
- dists[index] = dist;
- else if ( FT_ABS( dists[index].distance - dist.distance )
- < CORNER_CHECK_EPSILON )
- dists[index] = resolve_corner( dists[index], dist );
+ else
+ {
+ diff = FT_ABS( dists[index].distance - dist.distance );
+
+ if ( diff <= CORNER_CHECK_EPSILON )
+ dists[index] = resolve_corner( dists[index], dist );
+ else if ( dists[index].distance > dist.distance )
+ dists[index] = dist;
+ }
}
}
diff --git a/Build/source/libs/freetype2/freetype-src/src/sdf/ftsdf.h b/Build/source/libs/freetype2/freetype-src/src/sdf/ftsdf.h
index 187b418af3c..5f6b3f52aaf 100644
--- a/Build/source/libs/freetype2/freetype-src/src/sdf/ftsdf.h
+++ b/Build/source/libs/freetype2/freetype-src/src/sdf/ftsdf.h
@@ -4,7 +4,7 @@
*
* Signed Distance Field support (specification).
*
- * Copyright (C) 2020-2021 by
+ * Copyright (C) 2020-2022 by
* David Turner, Robert Wilhelm, and Werner Lemberg.
*
* Written by Anuj Verma.
diff --git a/Build/source/libs/freetype2/freetype-src/src/sdf/ftsdfcommon.c b/Build/source/libs/freetype2/freetype-src/src/sdf/ftsdfcommon.c
index 91aa521bb31..072a36ea6c2 100644
--- a/Build/source/libs/freetype2/freetype-src/src/sdf/ftsdfcommon.c
+++ b/Build/source/libs/freetype2/freetype-src/src/sdf/ftsdfcommon.c
@@ -4,7 +4,7 @@
*
* Auxiliary data for Signed Distance Field support (body).
*
- * Copyright (C) 2020-2021 by
+ * Copyright (C) 2020-2022 by
* David Turner, Robert Wilhelm, and Werner Lemberg.
*
* Written by Anuj Verma.
diff --git a/Build/source/libs/freetype2/freetype-src/src/sdf/ftsdfcommon.h b/Build/source/libs/freetype2/freetype-src/src/sdf/ftsdfcommon.h
index 44f6bba53f8..af4490bbca2 100644
--- a/Build/source/libs/freetype2/freetype-src/src/sdf/ftsdfcommon.h
+++ b/Build/source/libs/freetype2/freetype-src/src/sdf/ftsdfcommon.h
@@ -4,7 +4,7 @@
*
* Auxiliary data for Signed Distance Field support (specification).
*
- * Copyright (C) 2020-2021 by
+ * Copyright (C) 2020-2022 by
* David Turner, Robert Wilhelm, and Werner Lemberg.
*
* Written by Anuj Verma.
@@ -48,6 +48,8 @@ FT_BEGIN_HEADER
#define MIN_SPREAD 2
/* maximum spread supported by the renderer */
#define MAX_SPREAD 32
+ /* pixel size in 26.6 */
+#define ONE_PIXEL ( 1 << 6 )
/**************************************************************************
diff --git a/Build/source/libs/freetype2/freetype-src/src/sdf/ftsdferrs.h b/Build/source/libs/freetype2/freetype-src/src/sdf/ftsdferrs.h
index dbb113d5379..b28867609a6 100644
--- a/Build/source/libs/freetype2/freetype-src/src/sdf/ftsdferrs.h
+++ b/Build/source/libs/freetype2/freetype-src/src/sdf/ftsdferrs.h
@@ -4,7 +4,7 @@
*
* Signed Distance Field error codes (specification only).
*
- * Copyright (C) 2020-2021 by
+ * Copyright (C) 2020-2022 by
* David Turner, Robert Wilhelm, and Werner Lemberg.
*
* Written by Anuj Verma.
diff --git a/Build/source/libs/freetype2/freetype-src/src/sdf/ftsdfrend.c b/Build/source/libs/freetype2/freetype-src/src/sdf/ftsdfrend.c
index 30f2e62a4fe..b0213a40d35 100644
--- a/Build/source/libs/freetype2/freetype-src/src/sdf/ftsdfrend.c
+++ b/Build/source/libs/freetype2/freetype-src/src/sdf/ftsdfrend.c
@@ -4,7 +4,7 @@
*
* Signed Distance Field renderer interface (body).
*
- * Copyright (C) 2020-2021 by
+ * Copyright (C) 2020-2022 by
* David Turner, Robert Wilhelm, and Werner Lemberg.
*
* Written by Anuj Verma.
@@ -298,15 +298,9 @@
goto Exit;
}
- /* the rows and pitch must be valid after presetting the */
- /* bitmap using outline */
+ /* nothing to render */
if ( !bitmap->rows || !bitmap->pitch )
- {
- FT_ERROR(( "ft_sdf_render: failed to preset bitmap\n" ));
-
- error = FT_THROW( Cannot_Render_Glyph );
- goto Exit;
- }
+ return FT_Err_Ok;
/* the padding will simply be equal to the `spread' */
x_pad = sdf_module->spread;
@@ -525,13 +519,9 @@
goto Exit;
}
+ /* nothing to render */
if ( !bitmap->rows || !bitmap->pitch )
- {
- FT_ERROR(( "ft_bsdf_render: invalid bitmap size\n" ));
-
- error = FT_THROW( Invalid_Argument );
- goto Exit;
- }
+ return FT_Err_Ok;
FT_Bitmap_New( &target );
diff --git a/Build/source/libs/freetype2/freetype-src/src/sdf/ftsdfrend.h b/Build/source/libs/freetype2/freetype-src/src/sdf/ftsdfrend.h
index bc88707ec24..cdb9c5f02f0 100644
--- a/Build/source/libs/freetype2/freetype-src/src/sdf/ftsdfrend.h
+++ b/Build/source/libs/freetype2/freetype-src/src/sdf/ftsdfrend.h
@@ -4,7 +4,7 @@
*
* Signed Distance Field renderer interface (specification).
*
- * Copyright (C) 2020-2021 by
+ * Copyright (C) 2020-2022 by
* David Turner, Robert Wilhelm, and Werner Lemberg.
*
* Written by Anuj Verma.
diff --git a/Build/source/libs/freetype2/freetype-src/src/sdf/module.mk b/Build/source/libs/freetype2/freetype-src/src/sdf/module.mk
index 6be4b0c6d47..772bc48bf7a 100644
--- a/Build/source/libs/freetype2/freetype-src/src/sdf/module.mk
+++ b/Build/source/libs/freetype2/freetype-src/src/sdf/module.mk
@@ -3,7 +3,7 @@
#
-# Copyright (C) 2020-2021 by
+# Copyright (C) 2020-2022 by
# David Turner, Robert Wilhelm, and Werner Lemberg.
#
# This file is part of the FreeType project, and may only be used, modified,
diff --git a/Build/source/libs/freetype2/freetype-src/src/sdf/rules.mk b/Build/source/libs/freetype2/freetype-src/src/sdf/rules.mk
index 7e7e4fbe860..5239d643ffb 100644
--- a/Build/source/libs/freetype2/freetype-src/src/sdf/rules.mk
+++ b/Build/source/libs/freetype2/freetype-src/src/sdf/rules.mk
@@ -3,7 +3,7 @@
#
-# Copyright (C) 2020-2021 by
+# Copyright (C) 2020-2022 by
# David Turner, Robert Wilhelm, and Werner Lemberg.
#
# This file is part of the FreeType project, and may only be used, modified,
diff --git a/Build/source/libs/freetype2/freetype-src/src/sdf/sdf.c b/Build/source/libs/freetype2/freetype-src/src/sdf/sdf.c
index 1bc3fc385cc..297ba9ab021 100644
--- a/Build/source/libs/freetype2/freetype-src/src/sdf/sdf.c
+++ b/Build/source/libs/freetype2/freetype-src/src/sdf/sdf.c
@@ -4,7 +4,7 @@
*
* FreeType Signed Distance Field renderer module component (body only).
*
- * Copyright (C) 2020-2021 by
+ * Copyright (C) 2020-2022 by
* David Turner, Robert Wilhelm, and Werner Lemberg.
*
* Written by Anuj Verma.