summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnuj Verma <anujv@iitbhilai.ac.in>2020-08-06 11:42:26 +0530
committerAnuj Verma <anujv@iitbhilai.ac.in>2020-08-06 11:42:26 +0530
commit06bbff76b9e23c4b4cbb8541f4f330d3c922ad91 (patch)
tree6efc9ff076310b4e1ccb8e0e96ab9413eab66d1a
parent5014394b3eda62f9bde865778c0889b30afac8fa (diff)
downloadfreetype2-06bbff76b9e23c4b4cbb8541f4f330d3c922ad91.tar.gz
[sdf] Added function to get contour orientation.
* src/sdf/ftsdf.c (SDF_Contour_Orientation): Added enum to hold the different orientations of a contour. * src/sdf/ftsdf.c (get_contour_orientation): Added function which can be used to compute the orientation of a contour. * src/sdf/ftbsdf.c (*): Remove completed `[TODO]'s.
-rw-r--r--[GSoC]ChangeLog13
-rw-r--r--src/sdf/ftbsdf.c2
-rw-r--r--src/sdf/ftsdf.c73
3 files changed, 85 insertions, 3 deletions
diff --git a/[GSoC]ChangeLog b/[GSoC]ChangeLog
index f84edf3ac..41eb62b98 100644
--- a/[GSoC]ChangeLog
+++ b/[GSoC]ChangeLog
@@ -1,5 +1,18 @@
2020-08-6 Anuj Verma <anujv@iitbhilai.ac.in>
+ [sdf] Added function to get contour orientation.
+
+ * src/sdf/ftsdf.c (SDF_Contour_Orientation): Added
+ enum to hold the different orientations of a contour.
+
+ * src/sdf/ftsdf.c (get_contour_orientation): Added
+ function which can be used to compute the orientation
+ of a contour.
+
+ * src/sdf/ftbsdf.c (*): Remove completed `[TODO]'s.
+
+2020-08-6 Anuj Verma <anujv@iitbhilai.ac.in>
+
[sdf -> bsdf] Added documentation for functions of the `bsdf' renderer.
* src/sdf/ftbsdf.c (*) Added function documentation for
diff --git a/src/sdf/ftbsdf.c b/src/sdf/ftbsdf.c
index d5ec2b797..805feea3d 100644
--- a/src/sdf/ftbsdf.c
+++ b/src/sdf/ftbsdf.c
@@ -308,7 +308,6 @@
/* approximate direction of the edge, we can */
/* approximate the edge distance much better. */
- /* [TODO]: Add squared distance support. */
if ( g.x == 0 || g.y == 0 )
dist = ONE / 2 - alphas[4];
else
@@ -509,7 +508,6 @@
/* convert the source bitmap to desired bpp. */
switch ( source->pixel_mode ) {
case FT_PIXEL_MODE_MONO:
- /* [TODO] */
{
FT_Int t_width = worker->width;
FT_Int t_rows = worker->rows;
diff --git a/src/sdf/ftsdf.c b/src/sdf/ftsdf.c
index e0ba9a728..605c4465f 100644
--- a/src/sdf/ftsdf.c
+++ b/src/sdf/ftsdf.c
@@ -151,7 +151,7 @@
*
*/
- #define MUL_26D6( a, b ) ( ( a * b ) / 64 )
+ #define MUL_26D6( a, b ) ( ( ( a ) * ( b ) ) / 64 )
#define VEC_26D6_DOT( p, q ) ( MUL_26D6( p.x, q.x ) + \
MUL_26D6( p.y, q.y ) )
@@ -177,6 +177,16 @@
} SDF_Edge_Type;
+ /* Enumeration for the orientation of a contour, remember */
+ /* the orientation is independent of the fill rule. */
+ typedef enum SDF_Contour_Orientation_
+ {
+ SDF_ORIENTATION_NONE = 0, /* undefined, used to initialize */
+ SDF_ORIENTATION_CW = 0, /* clockwise orientation */
+ SDF_ORIENTATION_ACW = 0, /* anti-clockwise orientation */
+
+ } SDF_Contour_Orientation;
+
/* represent a single edge in a contour */
typedef struct SDF_Edge_
{
@@ -694,6 +704,67 @@
return cbox;
}
+ /* The function returns the orientation for a single contour. */
+ /* Note that the orientation is independent of the fill rule. */
+ /* So, for ttf the clockwise has to be filled and the opposite */
+ /* for otf fonts. */
+ static SDF_Contour_Orientation
+ get_contour_orientation ( SDF_Contour* contour )
+ {
+ SDF_Edge* head = NULL;
+ FT_26D6 area = 0;
+
+
+ /* return none if invalid parameters */
+ if ( !contour || !contour->edges )
+ return SDF_ORIENTATION_NONE;
+
+ head = contour->edges;
+
+ /* Simply calculate the area of the control box for */
+ /* all the edges. */
+ while ( head )
+ {
+ switch ( head->edge_type ) {
+ case SDF_EDGE_LINE:
+ {
+ area += MUL_26D6( ( head->end_pos.x - head->start_pos.x ),
+ ( head->end_pos.y + head->start_pos.y ) );
+ break;
+ }
+ case SDF_EDGE_CONIC:
+ {
+ area += MUL_26D6( head->control_a.x - head->start_pos.x,
+ head->control_a.y + head->start_pos.y );
+ area += MUL_26D6( head->end_pos.x - head->control_a.x,
+ head->end_pos.y + head->control_a.y );
+ break;
+ }
+ case SDF_EDGE_CUBIC:
+ {
+ area += MUL_26D6( head->control_a.x - head->start_pos.x,
+ head->control_a.y + head->start_pos.y );
+ area += MUL_26D6( head->control_b.x - head->control_a.x,
+ head->control_b.y + head->control_a.y );
+ area += MUL_26D6( head->end_pos.x - head->control_b.x,
+ head->end_pos.y + head->control_b.y );
+ break;
+ }
+ default:
+ return SDF_ORIENTATION_NONE;
+ }
+
+ head = head->next;
+ }
+
+ /* Clockwise contour cover a positive area, and Anti-Clockwise */
+ /* contour cover a negitive area. */
+ if ( area > 0 )
+ return SDF_ORIENTATION_CW;
+ else
+ return SDF_ORIENTATION_ACW;
+ }
+
/* The function is exactly same as the one */
/* in the smooth renderer. It splits a conic */
/* into two conic exactly half way at t = 0.5 */