forked from minhngoc25a/freetype2
[sdf] Added `SDF_Raster_Params'.
This commit is contained in:
parent
3ebcbd7066
commit
6d4e00ae37
@ -1,3 +1,22 @@
|
||||
2020-06-26 Anuj Verma <anujv@iitbhilai.ac.in>
|
||||
|
||||
[sdf] Added `SDF_Raster_Params' struct which extends
|
||||
`FT_Raster_Params' and has a few extra fields. This is done
|
||||
to pass extra data to the sdf rasterzier which is required
|
||||
while rastersizing.
|
||||
|
||||
* src/sdf/ftsdf.h (SDF_Raster_Params): Added a struct which
|
||||
extends `FT_Raster_Params' and has the `spread' parameter.
|
||||
Also moved the max, min and default spread values to this
|
||||
header file.
|
||||
|
||||
* src/sdf/ftsdf.c (sdf_raster_render): Added parameter and
|
||||
attribute checking in order to pick errors and return
|
||||
early.
|
||||
|
||||
* src//sdf/ftsdfrend.c (ft_sdf_render): Setup the `SDF_Raster_Params'
|
||||
and pass it to the rasterizer instead of `FT_Raster_Params'.
|
||||
|
||||
2020-06-26 Anuj Verma <anujv@iitbhilai.ac.in>
|
||||
|
||||
* include/freetype/ftimage.h (FT_RASTER_FLAG_): Added
|
||||
|
@ -125,7 +125,7 @@
|
||||
FT_FREE( *edge );
|
||||
}
|
||||
|
||||
/* Used in `FT_List_Finalize' */
|
||||
/* Used in `FT_List_Finalize'. */
|
||||
static void
|
||||
sdf_edge_destructor( FT_Memory memory,
|
||||
void* data,
|
||||
@ -137,9 +137,8 @@
|
||||
sdf_edge_done( memory, &edge );
|
||||
}
|
||||
|
||||
/* Creates a new `SDF_Contour' on the heap and assigns the `contour' */
|
||||
/* pointer to the newly allocated memory. Note that the function also */
|
||||
/* allocate the `contour.edges' list variable and sets to empty list. */
|
||||
/* Creates a new `SDF_Contour' on the heap and assigns */
|
||||
/* the `contour' pointer to the newly allocated memory. */
|
||||
static FT_Error
|
||||
sdf_contour_new( FT_Memory memory,
|
||||
SDF_Contour** contour )
|
||||
@ -181,7 +180,7 @@
|
||||
FT_FREE( *contour );
|
||||
}
|
||||
|
||||
/* Used in `FT_List_Finalize' */
|
||||
/* Used in `FT_List_Finalize'. */
|
||||
static void
|
||||
sdf_contour_destructor( FT_Memory memory,
|
||||
void* data,
|
||||
@ -193,9 +192,8 @@
|
||||
sdf_contour_done( memory, &contour );
|
||||
}
|
||||
|
||||
/* Creates a new `SDF_Shape' on the heap and assigns the `shape' */
|
||||
/* pointer to the newly allocated memory. Note that the function also */
|
||||
/* allocate the `shape.contours' list variable and sets to empty list. */
|
||||
/* Creates a new `SDF_Shape' on the heap and assigns */
|
||||
/* the `shape' pointer to the newly allocated memory. */
|
||||
static FT_Error
|
||||
sdf_shape_new( FT_Memory memory,
|
||||
SDF_Shape** shape )
|
||||
@ -246,12 +244,12 @@
|
||||
*
|
||||
*/
|
||||
|
||||
/* This function is called when walking along a new contour */
|
||||
/* so add a new contour to the shape's list. */
|
||||
static FT_Error
|
||||
sdf_move_to( const FT_26D6_Vec* to,
|
||||
void* user )
|
||||
{
|
||||
/* This function is called when walking along a new contour */
|
||||
/* so add a new contour to the shape's list. */
|
||||
SDF_Shape* shape = ( SDF_Shape* )user;
|
||||
SDF_Contour* contour = NULL;
|
||||
FT_ListNode node = NULL;
|
||||
@ -541,8 +539,8 @@
|
||||
|
||||
FT_TRACE5(( "\n" ));
|
||||
FT_TRACE5(( "*note: the above values are in 26.6 fixed point format*\n" ));
|
||||
FT_TRACE5(( "[sdf] total number of contours = %d\n", num_contours ));
|
||||
FT_TRACE5(( "[sdf] total number of edges = %d\n", total_edges ));
|
||||
FT_TRACE5(( "total number of contours = %d\n", num_contours ));
|
||||
FT_TRACE5(( "total number of edges = %d\n", total_edges ));
|
||||
FT_TRACE5(( "[sdf] sdf_shape_dump complete\n" ));
|
||||
FT_TRACE5(( "-------------------------------------------------\n" ));
|
||||
}
|
||||
@ -601,17 +599,63 @@
|
||||
sdf_raster_render( FT_Raster raster,
|
||||
const FT_Raster_Params* params )
|
||||
{
|
||||
FT_UNUSED( raster );
|
||||
FT_UNUSED( params );
|
||||
FT_Error error = FT_Err_Ok;
|
||||
SDF_TRaster* sdf_raster = (SDF_TRaster*)raster;
|
||||
FT_Outline* outline = NULL;
|
||||
const SDF_Raster_Params* sdf_params = (const SDF_Raster_Params*)params;
|
||||
|
||||
|
||||
/* check for valid arguments */
|
||||
if ( !sdf_raster || !sdf_params )
|
||||
{
|
||||
error = FT_THROW( Invalid_Argument );
|
||||
goto Exit;
|
||||
}
|
||||
|
||||
outline = (FT_Outline*)sdf_params->root.source;
|
||||
|
||||
/* check if the outline is valid or not */
|
||||
if ( !outline )
|
||||
{
|
||||
error = FT_THROW( Invalid_Outline );
|
||||
goto Exit;
|
||||
}
|
||||
|
||||
/* if the outline is empty, return */
|
||||
if ( outline->n_points <= 0 || outline->n_contours <= 0 )
|
||||
goto Exit;
|
||||
|
||||
/* check if the outline has valid fields */
|
||||
if ( !outline->contours || !outline->points )
|
||||
{
|
||||
error = FT_THROW( Invalid_Outline );
|
||||
goto Exit;
|
||||
}
|
||||
|
||||
/* check if spread is set properly */
|
||||
if ( sdf_params->spread > MAX_SPREAD ||
|
||||
sdf_params->spread < MIN_SPREAD )
|
||||
{
|
||||
FT_TRACE0((
|
||||
"[sdf] sdf_raster_render:\n"
|
||||
" The `spread' field of `SDF_Raster_Params' is invalid,\n"
|
||||
" the value of this field must be within [%d, %d].\n"
|
||||
" Also, you must pass `SDF_Raster_Params' instead of the\n"
|
||||
" default `FT_Raster_Params' while calling this function\n"
|
||||
" and set the fields properly.\n"
|
||||
, MIN_SPREAD, MAX_SPREAD) );
|
||||
error = FT_THROW( Invalid_Argument );
|
||||
goto Exit;
|
||||
}
|
||||
|
||||
/* temporary */
|
||||
|
||||
FT_Memory memory = (FT_Memory)((SDF_TRaster*)raster)->memory;
|
||||
FT_Memory memory = sdf_raster->memory;
|
||||
|
||||
SDF_Shape * shape = NULL;
|
||||
sdf_shape_new( memory, &shape );
|
||||
|
||||
sdf_outline_decompose( params->source, shape );
|
||||
sdf_outline_decompose( outline, shape );
|
||||
|
||||
sdf_shape_dump( shape );
|
||||
|
||||
@ -619,7 +663,9 @@
|
||||
|
||||
/* --------- */
|
||||
|
||||
return FT_THROW( Unimplemented_Feature );
|
||||
Exit:
|
||||
error = FT_THROW( Unimplemented_Feature );
|
||||
return error;
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -8,6 +8,36 @@
|
||||
|
||||
FT_BEGIN_HEADER
|
||||
|
||||
/* default spread value */
|
||||
#define DEFAULT_SPREAD 8
|
||||
|
||||
/* minimum spread supported by the rasterizer. */
|
||||
#define MIN_SPREAD 2
|
||||
|
||||
/* maximum spread supported by the rasterizer. */
|
||||
#define MAX_SPREAD 32
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* @struct:
|
||||
* SDF_Raster_Params
|
||||
*
|
||||
* @description:
|
||||
* This struct must be used for the raster render function
|
||||
* `FT_Raster_Render_Func' instead of `FT_Raster_Params' because
|
||||
* the rasterizer require some addition information to render properly.
|
||||
*
|
||||
* @fields:
|
||||
* [TODO]
|
||||
*
|
||||
*/
|
||||
typedef struct SDF_Raster_Params_
|
||||
{
|
||||
FT_Raster_Params root;
|
||||
FT_UInt spread;
|
||||
|
||||
} SDF_Raster_Params;
|
||||
|
||||
FT_EXPORT_VAR( const FT_Raster_Funcs ) ft_sdf_raster;
|
||||
|
||||
FT_END_HEADER
|
||||
|
@ -23,9 +23,6 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#define DEFAULT_SPREAD 8
|
||||
#define MAX_SPREAD 32
|
||||
|
||||
#define SDF_RENDERER( rend ) ( (SDF_Renderer)rend )
|
||||
|
||||
/**************************************************************************
|
||||
@ -51,22 +48,22 @@
|
||||
FT_Int val = *(const FT_Int*)value;
|
||||
|
||||
|
||||
if ( val > MAX_SPREAD || val <= 0 )
|
||||
if ( val > MAX_SPREAD || val < MIN_SPREAD )
|
||||
{
|
||||
FT_TRACE0(( "[sdf module] sdf_property_set: "
|
||||
FT_TRACE0(( "[sdf] sdf_property_set: "
|
||||
"the `spread' property can have a "
|
||||
"value within range [1, %d] "
|
||||
"(value provided %d)\n", MAX_SPREAD, val ));
|
||||
"value within range [%d, %d] (value provided %d)\n",
|
||||
MIN_SPREAD, MAX_SPREAD, val ));
|
||||
error = FT_THROW( Invalid_Argument );
|
||||
goto Exit;
|
||||
}
|
||||
render->spread = (FT_UInt)val;
|
||||
FT_TRACE7(( "[sdf module] sdf_property_set: "
|
||||
FT_TRACE7(( "[sdf] sdf_property_set: "
|
||||
"updated property `spread' to %d\n", val ));
|
||||
}
|
||||
else
|
||||
{
|
||||
FT_TRACE0(( "[sdf module] sdf_property_set: "
|
||||
FT_TRACE0(( "[sdf] sdf_property_set: "
|
||||
"missing property `%s'\n", property_name ));
|
||||
error = FT_THROW( Missing_Property );
|
||||
}
|
||||
@ -93,7 +90,7 @@
|
||||
}
|
||||
else
|
||||
{
|
||||
FT_TRACE0(( "[sdf module] sdf_property_get: "
|
||||
FT_TRACE0(( "[sdf] sdf_property_get: "
|
||||
"missing property `%s'\n", property_name ));
|
||||
error = FT_THROW( Missing_Property );
|
||||
}
|
||||
@ -166,8 +163,8 @@
|
||||
FT_UInt x_pad = 0;
|
||||
FT_UInt y_pad = 0;
|
||||
|
||||
FT_Raster_Params params;
|
||||
SDF_Renderer sdf_module = SDF_RENDERER( module );
|
||||
SDF_Raster_Params params;
|
||||
SDF_Renderer sdf_module = SDF_RENDERER( module );
|
||||
|
||||
|
||||
render = &sdf_module->root;
|
||||
@ -176,15 +173,16 @@
|
||||
/* check if slot format is correct before rendering */
|
||||
if ( slot->format != render->glyph_format )
|
||||
{
|
||||
error = FT_THROW( Invalid_Argument );
|
||||
error = FT_THROW( Invalid_Glyph_Format );
|
||||
goto Exit;
|
||||
}
|
||||
|
||||
/* check if render mode is correct */
|
||||
if ( mode != FT_RENDER_MODE_SDF )
|
||||
{
|
||||
FT_ERROR(( "ft_sdf_render: sdf module only"
|
||||
"render when using `FT_RENDER_MODE_SDF'" ));
|
||||
FT_ERROR(( "[sdf] ft_sdf_render: "
|
||||
"sdf module only render when "
|
||||
"using `FT_RENDER_MODE_SDF'\n" ));
|
||||
error = FT_THROW( Cannot_Render_Glyph );
|
||||
goto Exit;
|
||||
}
|
||||
@ -242,12 +240,13 @@
|
||||
FT_Outline_Translate( outline, x_shift, y_shift );
|
||||
|
||||
/* set up parameters */
|
||||
params.target = bitmap;
|
||||
params.source = outline;
|
||||
params.flags = FT_RASTER_FLAG_SDF;
|
||||
params.root.target = bitmap;
|
||||
params.root.source = outline;
|
||||
params.root.flags = FT_RASTER_FLAG_SDF;
|
||||
params.spread = sdf_module->spread;
|
||||
|
||||
/* render the outline */
|
||||
error = render->raster_render( render->raster, ¶ms );
|
||||
error = render->raster_render( render->raster, (const FT_Raster_Params*)¶ms );
|
||||
|
||||
Exit:
|
||||
if ( !error )
|
||||
@ -340,7 +339,7 @@
|
||||
(FT_Renderer_GetCBoxFunc) ft_sdf_get_cbox, /* get_glyph_cbox */
|
||||
(FT_Renderer_SetModeFunc) ft_sdf_set_mode, /* set_mode */
|
||||
|
||||
(FT_Raster_Funcs*)&ft_sdf_raster /* raster_class */
|
||||
(FT_Raster_Funcs*)&ft_sdf_raster /* raster_class */
|
||||
)
|
||||
|
||||
/* END */
|
||||
|
Loading…
x
Reference in New Issue
Block a user