forked from minhngoc25a/freetype2
[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:
parent
6b03b1c57a
commit
dd5276601c
|
@ -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>
|
2020-07-13 Anuj Verma <anujv@iitbhilai.ac.in>
|
||||||
|
|
||||||
[sdf] Check for left or right fill.
|
[sdf] Check for left or right fill.
|
||||||
|
|
|
@ -2470,8 +2470,6 @@
|
||||||
|
|
||||||
contour_list = shape->contours;
|
contour_list = shape->contours;
|
||||||
|
|
||||||
index = ( rows - y - 1 ) * width + x;
|
|
||||||
|
|
||||||
/* iterate through all the contours manually */
|
/* iterate through all the contours manually */
|
||||||
while ( contour_list ) {
|
while ( contour_list ) {
|
||||||
SDF_Signed_Distance current_dist = max_sdf;
|
SDF_Signed_Distance current_dist = max_sdf;
|
||||||
|
@ -2500,11 +2498,18 @@
|
||||||
|
|
||||||
if ( internal_params.orientation == FT_ORIENTATION_FILL_LEFT )
|
if ( internal_params.orientation == FT_ORIENTATION_FILL_LEFT )
|
||||||
min_dist.sign = -min_dist.sign;
|
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 */
|
min_dist.distance /= 64; /* convert from 16.16 to 22.10 */
|
||||||
value = min_dist.distance & 0x0000FFFF; /* truncate to 6.10 */
|
value = min_dist.distance & 0x0000FFFF; /* truncate to 6.10 */
|
||||||
value *= min_dist.sign;
|
value *= min_dist.sign;
|
||||||
|
|
||||||
|
if ( internal_params.flip_y )
|
||||||
|
index = y * width + x;
|
||||||
|
else
|
||||||
|
index = ( rows - y - 1 ) * width + x;
|
||||||
|
|
||||||
buffer[index] = value;
|
buffer[index] = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2642,8 +2647,6 @@
|
||||||
grid_point.x += FT_INT_26D6( 1 ) / 2;
|
grid_point.x += FT_INT_26D6( 1 ) / 2;
|
||||||
grid_point.y += 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,
|
FT_CALL( sdf_edge_get_min_distance( edges,
|
||||||
grid_point,
|
grid_point,
|
||||||
&dist ) );
|
&dist ) );
|
||||||
|
@ -2659,6 +2662,11 @@
|
||||||
if ( USE_SQUARED_DISTANCES )
|
if ( USE_SQUARED_DISTANCES )
|
||||||
dist.distance = square_root( dist.distance );
|
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 */
|
/* check weather the pixel is set or not */
|
||||||
if ( dists[index].sign == 0 )
|
if ( dists[index].sign == 0 )
|
||||||
dists[index] = dist;
|
dists[index] = dist;
|
||||||
|
@ -2704,7 +2712,10 @@
|
||||||
/* convert from 16.16 to 6.10 */
|
/* convert from 16.16 to 6.10 */
|
||||||
dists[index].distance /= 64;
|
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;
|
FT_26D6_Vec current_pos;
|
||||||
SDF_Signed_Distance min_dist = max_sdf;
|
SDF_Signed_Distance min_dist = max_sdf;
|
||||||
SDF_Edge* edges = relevant_list;
|
SDF_Edge* edges = relevant_list;
|
||||||
FT_Int index = ( rows - y - 1 ) * width + x;
|
FT_Int index;
|
||||||
|
|
||||||
|
|
||||||
if ( x < 0 || x >= width ) continue;
|
if ( x < 0 || x >= width ) continue;
|
||||||
|
@ -2962,11 +2973,18 @@
|
||||||
if ( USE_SQUARED_DISTANCES )
|
if ( USE_SQUARED_DISTANCES )
|
||||||
min_dist.distance = square_root( min_dist.distance );
|
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.sign = -min_dist.sign;
|
||||||
|
|
||||||
min_dist.distance /= 64;
|
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;
|
buffer[index] = (FT_Short)min_dist.distance * min_dist.sign;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -3104,8 +3122,8 @@
|
||||||
|
|
||||||
/* setup the params */
|
/* setup the params */
|
||||||
internal_params.orientation = FT_Outline_Get_Orientation( outline );
|
internal_params.orientation = FT_Outline_Get_Orientation( outline );
|
||||||
internal_params.flip_sign = 0;
|
internal_params.flip_sign = sdf_params->flip_sign;
|
||||||
internal_params.flip_y = 0;
|
internal_params.flip_y = sdf_params->flip_y;
|
||||||
|
|
||||||
FT_CALL( sdf_shape_new( memory, &shape ) );
|
FT_CALL( sdf_shape_new( memory, &shape ) );
|
||||||
|
|
||||||
|
|
|
@ -35,6 +35,8 @@ FT_BEGIN_HEADER
|
||||||
{
|
{
|
||||||
FT_Raster_Params root;
|
FT_Raster_Params root;
|
||||||
FT_UInt spread;
|
FT_UInt spread;
|
||||||
|
FT_Bool flip_sign;
|
||||||
|
FT_Bool flip_y;
|
||||||
|
|
||||||
} SDF_Raster_Params;
|
} SDF_Raster_Params;
|
||||||
|
|
||||||
|
|
|
@ -61,6 +61,24 @@
|
||||||
FT_TRACE7(( "[sdf] sdf_property_set: "
|
FT_TRACE7(( "[sdf] sdf_property_set: "
|
||||||
"updated property `spread' to %d\n", val ));
|
"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
|
else
|
||||||
{
|
{
|
||||||
FT_TRACE0(( "[sdf] sdf_property_set: "
|
FT_TRACE0(( "[sdf] sdf_property_set: "
|
||||||
|
@ -88,6 +106,20 @@
|
||||||
|
|
||||||
*val = render->spread;
|
*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
|
else
|
||||||
{
|
{
|
||||||
FT_TRACE0(( "[sdf] sdf_property_get: "
|
FT_TRACE0(( "[sdf] sdf_property_get: "
|
||||||
|
@ -131,7 +163,9 @@
|
||||||
SDF_Renderer sdf_render = SDF_RENDERER( render );
|
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;
|
return FT_Err_Ok;
|
||||||
}
|
}
|
||||||
|
@ -243,6 +277,8 @@
|
||||||
params.root.source = outline;
|
params.root.source = outline;
|
||||||
params.root.flags = FT_RASTER_FLAG_SDF;
|
params.root.flags = FT_RASTER_FLAG_SDF;
|
||||||
params.spread = sdf_module->spread;
|
params.spread = sdf_module->spread;
|
||||||
|
params.flip_sign = sdf_module->flip_sign;
|
||||||
|
params.flip_y = sdf_module->flip_y;
|
||||||
|
|
||||||
/* render the outline */
|
/* render the outline */
|
||||||
error = render->raster_render( render->raster, (const FT_Raster_Params*)¶ms );
|
error = render->raster_render( render->raster, (const FT_Raster_Params*)¶ms );
|
||||||
|
|
|
@ -26,6 +26,8 @@ FT_BEGIN_HEADER
|
||||||
{
|
{
|
||||||
FT_RendererRec root;
|
FT_RendererRec root;
|
||||||
FT_UInt spread;
|
FT_UInt spread;
|
||||||
|
FT_Bool flip_sign;
|
||||||
|
FT_Bool flip_y;
|
||||||
|
|
||||||
} SDF_Renderer_Module, *SDF_Renderer;
|
} SDF_Renderer_Module, *SDF_Renderer;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue