[smooth] Use `FT_Outline_Get_CBox'. * src/smooth/ftgrays.c [STANDALONE_]: Duplicate `FT_Outline_Get_CBox'. (gray_compute_cbox): Remove this function. (gray_convert_glyph): Update to use `FT_Outline_Get_CBox'.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
diff --git a/ChangeLog b/ChangeLog
index 08a1885..f9f2523 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2016-06-21 Alexei Podtelezhnikov <apodtele@gmail.com>
+
+ [smooth] Use `FT_Outline_Get_CBox'.
+
+ * src/smooth/ftgrays.c [STANDALONE_]: Duplicate `FT_Outline_Get_CBox'.
+ (gray_compute_cbox): Remove this function.
+ (gray_convert_glyph): Update to use `FT_Outline_Get_CBox'.
+
2016-06-20 Werner Lemberg <wl@gnu.org>
[smooth] Remove compiler warnings.
diff --git a/src/smooth/ftgrays.c b/src/smooth/ftgrays.c
index cf0cd13..c0f7053 100644
--- a/src/smooth/ftgrays.c
+++ b/src/smooth/ftgrays.c
@@ -1516,7 +1516,7 @@ typedef ptrdiff_t FT_PtrDist;
/*************************************************************************/
/* */
- /* The following function should only compile in stand-alone mode, */
+ /* The following functions should only compile in stand-alone mode, */
/* i.e., when building this component without the rest of FreeType. */
/* */
/*************************************************************************/
@@ -1794,52 +1794,83 @@ typedef ptrdiff_t FT_PtrDist;
return FT_THROW( Invalid_Outline );
}
-#endif /* STANDALONE_ */
-
/*************************************************************************/
/* */
- /* Compute the outline bounding box. */
+ /* <Function> */
+ /* FT_Outline_Get_CBox */
+ /* */
+ /* <Description> */
+ /* Return an outline's `control box'. The control box encloses all */
+ /* the outline's points, including Bézier control points. Though it */
+ /* coincides with the exact bounding box for most glyphs, it can be */
+ /* slightly larger in some situations (like when rotating an outline */
+ /* that contains Bézier outside arcs). */
+ /* */
+ /* Computing the control box is very fast, while getting the bounding */
+ /* box can take much more time as it needs to walk over all segments */
+ /* and arcs in the outline. To get the latter, you can use the */
+ /* `ftbbox' component, which is dedicated to this single task. */
+ /* */
+ /* <Input> */
+ /* outline :: A pointer to the source outline descriptor. */
/* */
+ /* <Output> */
+ /* acbox :: The outline's control box. */
+ /* */
+ /* <Note> */
+ /* See @FT_Glyph_Get_CBox for a discussion of tricky fonts. */
+ /* */
+
static void
- gray_compute_cbox( RAS_ARG )
+ FT_Outline_Get_CBox( const FT_Outline* outline,
+ FT_BBox *acbox )
{
- FT_Outline* outline = &ras.outline;
- FT_Vector* vec = outline->points;
- FT_Vector* limit = vec + outline->n_points;
+ TPos xMin, yMin, xMax, yMax;
- if ( outline->n_points <= 0 )
+ if ( outline && acbox )
{
- ras.min_ex = ras.max_ex = 0;
- ras.min_ey = ras.max_ey = 0;
- return;
- }
+ if ( outline->n_points == 0 )
+ {
+ xMin = 0;
+ yMin = 0;
+ xMax = 0;
+ yMax = 0;
+ }
+ else
+ {
+ FT_Vector* vec = outline->points;
+ FT_Vector* limit = vec + outline->n_points;
- ras.min_ex = ras.max_ex = vec->x;
- ras.min_ey = ras.max_ey = vec->y;
- vec++;
+ xMin = xMax = vec->x;
+ yMin = yMax = vec->y;
+ vec++;
- for ( ; vec < limit; vec++ )
- {
- TPos x = vec->x;
- TPos y = vec->y;
+ for ( ; vec < limit; vec++ )
+ {
+ TPos x, y;
- if ( x < ras.min_ex ) ras.min_ex = x;
- if ( x > ras.max_ex ) ras.max_ex = x;
- if ( y < ras.min_ey ) ras.min_ey = y;
- if ( y > ras.max_ey ) ras.max_ey = y;
- }
+ x = vec->x;
+ if ( x < xMin ) xMin = x;
+ if ( x > xMax ) xMax = x;
- /* truncate the bounding box to integer pixels */
- ras.min_ex = ras.min_ex >> 6;
- ras.min_ey = ras.min_ey >> 6;
- ras.max_ex = ( ras.max_ex + 63 ) >> 6;
- ras.max_ey = ( ras.max_ey + 63 ) >> 6;
+ y = vec->y;
+ if ( y < yMin ) yMin = y;
+ if ( y > yMax ) yMax = y;
+ }
+ }
+ acbox->xMin = xMin;
+ acbox->xMax = xMax;
+ acbox->yMin = yMin;
+ acbox->yMax = yMax;
+ }
}
+#endif /* STANDALONE_ */
+
typedef struct gray_TBand_
{
@@ -1886,15 +1917,21 @@ typedef ptrdiff_t FT_PtrDist;
static int
gray_convert_glyph( RAS_ARG )
{
+ FT_BBox cbox;
+ FT_BBox* clip;
gray_TBand bands[40];
gray_TBand* volatile band;
int volatile n, num_bands;
TPos volatile min, max, max_y;
- FT_BBox* clip;
- /* Set up state in the raster object */
- gray_compute_cbox( RAS_VAR );
+ FT_Outline_Get_CBox( &ras.outline, &cbox );
+
+ /* truncate the bounding box to integer pixels */
+ ras.min_ex = cbox.xMin >> 6;
+ ras.min_ey = cbox.yMin >> 6;
+ ras.max_ex = ( cbox.xMax + 63 ) >> 6;
+ ras.max_ey = ( cbox.yMax + 63 ) >> 6;
/* clip to target bitmap, exit if nothing to do */
clip = &ras.clip_box;