[sdf] Added more properties.

Added two properties:
- `flip_y': To flip the generated SDF along the y axis.
- `flip_sign': By default outside is treated to have
   negative sign, setting `flip_sign' to 1 the outside
   pixels will have positive sign.

* src/sdf/ftsdf.* (*): Use the newly added properties.

* src/sdf/ftsdfrend.* (*): Add the newly added properties,
  and add functionality to set them using `FT_Property_Set'.
This commit is contained in:
Anuj Verma 2020-07-13 11:36:30 +05:30 committed by anujverma
parent 6b03b1c57a
commit dd5276601c
5 changed files with 83 additions and 10 deletions

View File

@ -1,3 +1,18 @@
2020-07-13 Anuj Verma <anujv@iitbhilai.ac.in>
[sdf] Added more properties.
Added two properties:
- `flip_y': To flip the generated SDF along the y axis.
- `flip_sign': By default outside is treated to have
negative sign, setting `flip_sign' to 1 the outside
pixels will have positive sign.
* src/sdf/ftsdf.* (*): Use the newly added properties.
* src/sdf/ftsdfrend.* (*): Add the newly added properties,
and add functionality to set them using `FT_Property_Set'.
2020-07-13 Anuj Verma <anujv@iitbhilai.ac.in>
[sdf] Check for left or right fill.

View File

@ -2470,8 +2470,6 @@
contour_list = shape->contours;
index = ( rows - y - 1 ) * width + x;
/* iterate through all the contours manually */
while ( contour_list ) {
SDF_Signed_Distance current_dist = max_sdf;
@ -2500,11 +2498,18 @@
if ( internal_params.orientation == FT_ORIENTATION_FILL_LEFT )
min_dist.sign = -min_dist.sign;
if ( internal_params.flip_sign )
min_dist.sign = -min_dist.sign;
min_dist.distance /= 64; /* convert from 16.16 to 22.10 */
value = min_dist.distance & 0x0000FFFF; /* truncate to 6.10 */
value *= min_dist.sign;
if ( internal_params.flip_y )
index = y * width + x;
else
index = ( rows - y - 1 ) * width + x;
buffer[index] = value;
}
}
@ -2642,8 +2647,6 @@
grid_point.x += FT_INT_26D6( 1 ) / 2;
grid_point.y += FT_INT_26D6( 1 ) / 2;
index = ( rows - y - 1 ) * width + x;
FT_CALL( sdf_edge_get_min_distance( edges,
grid_point,
&dist ) );
@ -2659,6 +2662,11 @@
if ( USE_SQUARED_DISTANCES )
dist.distance = square_root( dist.distance );
if ( internal_params.flip_y )
index = y * width + x;
else
index = ( rows - y - 1 ) * width + x;
/* check weather the pixel is set or not */
if ( dists[index].sign == 0 )
dists[index] = dist;
@ -2704,7 +2712,10 @@
/* convert from 16.16 to 6.10 */
dists[index].distance /= 64;
buffer[index] = (FT_Short)dists[index].distance * current_sign;
if ( internal_params.flip_sign )
buffer[index] = (FT_Short)dists[index].distance * -current_sign;
else
buffer[index] = (FT_Short)dists[index].distance * current_sign;
}
}
@ -2920,7 +2931,7 @@
FT_26D6_Vec current_pos;
SDF_Signed_Distance min_dist = max_sdf;
SDF_Edge* edges = relevant_list;
FT_Int index = ( rows - y - 1 ) * width + x;
FT_Int index;
if ( x < 0 || x >= width ) continue;
@ -2962,11 +2973,18 @@
if ( USE_SQUARED_DISTANCES )
min_dist.distance = square_root( min_dist.distance );
if ( internal_params.orientation == FT_ORIENTATION_FILL_RIGHT )
if ( internal_params.orientation == FT_ORIENTATION_FILL_LEFT )
min_dist.sign = -min_dist.sign;
if ( internal_params.flip_sign )
min_dist.sign = -min_dist.sign;
min_dist.distance /= 64;
if ( internal_params.flip_y )
index = y * width + x;
else
index = ( rows - y - 1 ) * width + x;
buffer[index] = (FT_Short)min_dist.distance * min_dist.sign;
}
@ -3104,8 +3122,8 @@
/* setup the params */
internal_params.orientation = FT_Outline_Get_Orientation( outline );
internal_params.flip_sign = 0;
internal_params.flip_y = 0;
internal_params.flip_sign = sdf_params->flip_sign;
internal_params.flip_y = sdf_params->flip_y;
FT_CALL( sdf_shape_new( memory, &shape ) );

View File

@ -35,6 +35,8 @@ FT_BEGIN_HEADER
{
FT_Raster_Params root;
FT_UInt spread;
FT_Bool flip_sign;
FT_Bool flip_y;
} SDF_Raster_Params;

View File

@ -61,6 +61,24 @@
FT_TRACE7(( "[sdf] sdf_property_set: "
"updated property `spread' to %d\n", val ));
}
else if ( ft_strcmp( property_name, "flip_sign" ) == 0 )
{
FT_Int val = *(const FT_Int*)value;
render->flip_sign = val ? 1 : 0;
FT_TRACE7(( "[sdf] sdf_property_set: "
"updated property `flip_sign' to %d\n", val ));
}
else if ( ft_strcmp( property_name, "flip_y" ) == 0 )
{
FT_Int val = *(const FT_Int*)value;
render->flip_y = val ? 1 : 0;
FT_TRACE7(( "[sdf] sdf_property_set: "
"updated property `flip_y' to %d\n", val ));
}
else
{
FT_TRACE0(( "[sdf] sdf_property_set: "
@ -88,6 +106,20 @@
*val = render->spread;
}
else if ( ft_strcmp( property_name, "flip_sign" ) == 0 )
{
FT_Int* val = (FT_Int*)value;
*val = render->flip_sign;
}
else if ( ft_strcmp( property_name, "flip_y" ) == 0 )
{
FT_Int* val = (FT_Int*)value;
*val = render->flip_y;
}
else
{
FT_TRACE0(( "[sdf] sdf_property_get: "
@ -131,7 +163,9 @@
SDF_Renderer sdf_render = SDF_RENDERER( render );
sdf_render->spread = DEFAULT_SPREAD;
sdf_render->spread = DEFAULT_SPREAD;
sdf_render->flip_sign = 0;
sdf_render->flip_y = 0;
return FT_Err_Ok;
}
@ -243,6 +277,8 @@
params.root.source = outline;
params.root.flags = FT_RASTER_FLAG_SDF;
params.spread = sdf_module->spread;
params.flip_sign = sdf_module->flip_sign;
params.flip_y = sdf_module->flip_y;
/* render the outline */
error = render->raster_render( render->raster, (const FT_Raster_Params*)&params );

View File

@ -26,6 +26,8 @@ FT_BEGIN_HEADER
{
FT_RendererRec root;
FT_UInt spread;
FT_Bool flip_sign;
FT_Bool flip_y;
} SDF_Renderer_Module, *SDF_Renderer;