2018-06-03 09:01:17 +02:00
|
|
|
/****************************************************************************
|
|
|
|
*
|
|
|
|
* ftbbox.c
|
|
|
|
*
|
|
|
|
* FreeType bbox computation (body).
|
|
|
|
*
|
2020-01-19 17:05:19 +01:00
|
|
|
* Copyright (C) 1996-2020 by
|
2018-06-03 09:01:17 +02:00
|
|
|
* David Turner, Robert Wilhelm, and Werner Lemberg.
|
|
|
|
*
|
|
|
|
* This file is part of the FreeType project, and may only be used
|
|
|
|
* modified and distributed under the terms of the FreeType project
|
|
|
|
* license, LICENSE.TXT. By continuing to use, modify, or distribute
|
|
|
|
* this file you indicate that you have read the license and
|
|
|
|
* understand and accept it fully.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
*
|
|
|
|
* This component has a _single_ role: to compute exact outline bounding
|
|
|
|
* boxes.
|
|
|
|
*
|
|
|
|
*/
|
2000-10-26 02:06:35 +02:00
|
|
|
|
2000-12-08 17:17:16 +01:00
|
|
|
|
2020-06-08 13:31:55 +02:00
|
|
|
#include <freetype/internal/ftdebug.h>
|
2013-03-14 10:27:35 +01:00
|
|
|
|
2020-06-08 13:31:55 +02:00
|
|
|
#include <freetype/ftbbox.h>
|
|
|
|
#include <freetype/ftimage.h>
|
|
|
|
#include <freetype/ftoutln.h>
|
|
|
|
#include <freetype/internal/ftcalc.h>
|
|
|
|
#include <freetype/internal/ftobjs.h>
|
2000-10-26 02:06:35 +02:00
|
|
|
|
2000-10-26 12:04:16 +02:00
|
|
|
|
2000-10-26 02:06:35 +02:00
|
|
|
typedef struct TBBox_Rec_
|
|
|
|
{
|
|
|
|
FT_Vector last;
|
|
|
|
FT_BBox bbox;
|
|
|
|
|
|
|
|
} TBBox_Rec;
|
2001-04-26 15:34:36 +02:00
|
|
|
|
2000-10-26 02:06:35 +02:00
|
|
|
|
2014-12-06 23:28:58 +01:00
|
|
|
#define FT_UPDATE_BBOX( p, bbox ) \
|
|
|
|
FT_BEGIN_STMNT \
|
|
|
|
if ( p->x < bbox.xMin ) \
|
|
|
|
bbox.xMin = p->x; \
|
|
|
|
if ( p->x > bbox.xMax ) \
|
|
|
|
bbox.xMax = p->x; \
|
|
|
|
if ( p->y < bbox.yMin ) \
|
|
|
|
bbox.yMin = p->y; \
|
|
|
|
if ( p->y > bbox.yMax ) \
|
|
|
|
bbox.yMax = p->y; \
|
2014-10-09 04:01:08 +02:00
|
|
|
FT_END_STMNT
|
|
|
|
|
2014-12-06 23:28:58 +01:00
|
|
|
#define CHECK_X( p, bbox ) \
|
2014-10-09 04:01:08 +02:00
|
|
|
( p->x < bbox.xMin || p->x > bbox.xMax )
|
|
|
|
|
2014-12-06 23:28:58 +01:00
|
|
|
#define CHECK_Y( p, bbox ) \
|
2014-10-09 04:01:08 +02:00
|
|
|
( p->y < bbox.yMin || p->y > bbox.yMax )
|
|
|
|
|
|
|
|
|
2018-06-03 09:01:17 +02:00
|
|
|
/**************************************************************************
|
|
|
|
*
|
|
|
|
* @Function:
|
|
|
|
* BBox_Move_To
|
|
|
|
*
|
|
|
|
* @Description:
|
|
|
|
* This function is used as a `move_to' emitter during
|
|
|
|
* FT_Outline_Decompose(). It simply records the destination point
|
|
|
|
* in `user->last'. We also update bbox in case contour starts with
|
|
|
|
* an implicit `on' point.
|
|
|
|
*
|
|
|
|
* @Input:
|
|
|
|
* to ::
|
|
|
|
* A pointer to the destination vector.
|
|
|
|
*
|
|
|
|
* @InOut:
|
|
|
|
* user ::
|
|
|
|
* A pointer to the current walk context.
|
|
|
|
*
|
|
|
|
* @Return:
|
|
|
|
* Always 0. Needed for the interface only.
|
|
|
|
*/
|
2001-06-27 18:18:10 +02:00
|
|
|
static int
|
|
|
|
BBox_Move_To( FT_Vector* to,
|
|
|
|
TBBox_Rec* user )
|
2014-10-09 06:58:14 +02:00
|
|
|
{
|
|
|
|
FT_UPDATE_BBOX( to, user->bbox );
|
2014-11-20 04:10:29 +01:00
|
|
|
|
2014-10-09 06:58:14 +02:00
|
|
|
user->last = *to;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-06-03 09:01:17 +02:00
|
|
|
/**************************************************************************
|
|
|
|
*
|
|
|
|
* @Function:
|
|
|
|
* BBox_Line_To
|
|
|
|
*
|
|
|
|
* @Description:
|
|
|
|
* This function is used as a `line_to' emitter during
|
|
|
|
* FT_Outline_Decompose(). It simply records the destination point
|
|
|
|
* in `user->last'; no further computations are necessary because
|
|
|
|
* bbox already contains both explicit ends of the line segment.
|
|
|
|
*
|
|
|
|
* @Input:
|
|
|
|
* to ::
|
|
|
|
* A pointer to the destination vector.
|
|
|
|
*
|
|
|
|
* @InOut:
|
|
|
|
* user ::
|
|
|
|
* A pointer to the current walk context.
|
|
|
|
*
|
|
|
|
* @Return:
|
|
|
|
* Always 0. Needed for the interface only.
|
|
|
|
*/
|
2014-10-09 06:58:14 +02:00
|
|
|
static int
|
|
|
|
BBox_Line_To( FT_Vector* to,
|
|
|
|
TBBox_Rec* user )
|
2000-10-26 02:06:35 +02:00
|
|
|
{
|
|
|
|
user->last = *to;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-06-03 09:01:17 +02:00
|
|
|
/**************************************************************************
|
|
|
|
*
|
|
|
|
* @Function:
|
|
|
|
* BBox_Conic_Check
|
|
|
|
*
|
|
|
|
* @Description:
|
|
|
|
* Find the extrema of a 1-dimensional conic Bezier curve and update
|
|
|
|
* a bounding range. This version uses direct computation, as it
|
|
|
|
* doesn't need square roots.
|
|
|
|
*
|
|
|
|
* @Input:
|
|
|
|
* y1 ::
|
|
|
|
* The start coordinate.
|
|
|
|
*
|
|
|
|
* y2 ::
|
|
|
|
* The coordinate of the control point.
|
|
|
|
*
|
|
|
|
* y3 ::
|
|
|
|
* The end coordinate.
|
|
|
|
*
|
|
|
|
* @InOut:
|
|
|
|
* min ::
|
|
|
|
* The address of the current minimum.
|
|
|
|
*
|
|
|
|
* max ::
|
|
|
|
* The address of the current maximum.
|
|
|
|
*/
|
2001-06-27 18:18:10 +02:00
|
|
|
static void
|
|
|
|
BBox_Conic_Check( FT_Pos y1,
|
|
|
|
FT_Pos y2,
|
2003-05-15 08:44:09 +02:00
|
|
|
FT_Pos y3,
|
|
|
|
FT_Pos* min,
|
|
|
|
FT_Pos* max )
|
2000-10-26 02:06:35 +02:00
|
|
|
{
|
2013-08-27 21:30:09 +02:00
|
|
|
/* This function is only called when a control off-point is outside */
|
|
|
|
/* the bbox that contains all on-points. It finds a local extremum */
|
|
|
|
/* within the segment, equal to (y1*y3 - y2*y2)/(y1 - 2*y2 + y3). */
|
|
|
|
/* Or, offsetting from y2, we get */
|
2013-08-18 04:19:21 +02:00
|
|
|
|
|
|
|
y1 -= y2;
|
|
|
|
y3 -= y2;
|
|
|
|
y2 += FT_MulDiv( y1, y3, y1 + y3 );
|
|
|
|
|
|
|
|
if ( y2 < *min )
|
|
|
|
*min = y2;
|
|
|
|
if ( y2 > *max )
|
|
|
|
*max = y2;
|
2000-10-26 02:06:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-06-03 09:01:17 +02:00
|
|
|
/**************************************************************************
|
|
|
|
*
|
|
|
|
* @Function:
|
|
|
|
* BBox_Conic_To
|
|
|
|
*
|
|
|
|
* @Description:
|
|
|
|
* This function is used as a `conic_to' emitter during
|
|
|
|
* FT_Outline_Decompose(). It checks a conic Bezier curve with the
|
|
|
|
* current bounding box, and computes its extrema if necessary to
|
|
|
|
* update it.
|
|
|
|
*
|
|
|
|
* @Input:
|
|
|
|
* control ::
|
|
|
|
* A pointer to a control point.
|
|
|
|
*
|
|
|
|
* to ::
|
|
|
|
* A pointer to the destination vector.
|
|
|
|
*
|
|
|
|
* @InOut:
|
|
|
|
* user ::
|
|
|
|
* The address of the current walk context.
|
|
|
|
*
|
|
|
|
* @Return:
|
|
|
|
* Always 0. Needed for the interface only.
|
|
|
|
*
|
|
|
|
* @Note:
|
|
|
|
* In the case of a non-monotonous arc, we compute directly the
|
|
|
|
* extremum coordinates, as it is sufficiently fast.
|
|
|
|
*/
|
2001-06-27 18:18:10 +02:00
|
|
|
static int
|
|
|
|
BBox_Conic_To( FT_Vector* control,
|
|
|
|
FT_Vector* to,
|
|
|
|
TBBox_Rec* user )
|
2000-10-26 02:06:35 +02:00
|
|
|
{
|
2014-10-09 06:58:14 +02:00
|
|
|
/* in case `to' is implicit and not included in bbox yet */
|
|
|
|
FT_UPDATE_BBOX( to, user->bbox );
|
2000-11-04 10:41:45 +01:00
|
|
|
|
|
|
|
if ( CHECK_X( control, user->bbox ) )
|
2000-10-26 02:06:35 +02:00
|
|
|
BBox_Conic_Check( user->last.x,
|
|
|
|
control->x,
|
|
|
|
to->x,
|
|
|
|
&user->bbox.xMin,
|
|
|
|
&user->bbox.xMax );
|
|
|
|
|
2000-11-04 10:41:45 +01:00
|
|
|
if ( CHECK_Y( control, user->bbox ) )
|
2000-10-26 02:06:35 +02:00
|
|
|
BBox_Conic_Check( user->last.y,
|
|
|
|
control->y,
|
|
|
|
to->y,
|
|
|
|
&user->bbox.yMin,
|
|
|
|
&user->bbox.yMax );
|
|
|
|
|
2000-11-03 08:34:29 +01:00
|
|
|
user->last = *to;
|
|
|
|
|
2000-10-26 02:06:35 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-06-03 09:01:17 +02:00
|
|
|
/**************************************************************************
|
|
|
|
*
|
|
|
|
* @Function:
|
|
|
|
* BBox_Cubic_Check
|
|
|
|
*
|
|
|
|
* @Description:
|
|
|
|
* Find the extrema of a 1-dimensional cubic Bezier curve and
|
|
|
|
* update a bounding range. This version uses iterative splitting
|
|
|
|
* because it is faster than the exact solution with square roots.
|
|
|
|
*
|
|
|
|
* @Input:
|
|
|
|
* p1 ::
|
|
|
|
* The start coordinate.
|
|
|
|
*
|
|
|
|
* p2 ::
|
|
|
|
* The coordinate of the first control point.
|
|
|
|
*
|
|
|
|
* p3 ::
|
|
|
|
* The coordinate of the second control point.
|
|
|
|
*
|
|
|
|
* p4 ::
|
|
|
|
* The end coordinate.
|
|
|
|
*
|
|
|
|
* @InOut:
|
|
|
|
* min ::
|
|
|
|
* The address of the current minimum.
|
|
|
|
*
|
|
|
|
* max ::
|
|
|
|
* The address of the current maximum.
|
|
|
|
*/
|
2013-08-14 04:28:57 +02:00
|
|
|
static FT_Pos
|
2014-08-13 05:22:17 +02:00
|
|
|
cubic_peak( FT_Pos q1,
|
|
|
|
FT_Pos q2,
|
|
|
|
FT_Pos q3,
|
|
|
|
FT_Pos q4 )
|
2000-10-26 02:06:35 +02:00
|
|
|
{
|
2014-08-13 05:22:17 +02:00
|
|
|
FT_Pos peak = 0;
|
2014-08-15 04:41:06 +02:00
|
|
|
FT_Int shift;
|
2014-08-13 05:22:17 +02:00
|
|
|
|
2015-02-16 20:05:08 +01:00
|
|
|
|
2014-08-13 05:22:17 +02:00
|
|
|
/* This function finds a peak of a cubic segment if it is above 0 */
|
|
|
|
/* using iterative bisection of the segment, or returns 0. */
|
|
|
|
/* The fixed-point arithmetic of bisection is inherently stable */
|
|
|
|
/* but may loose accuracy in the two lowest bits. To compensate, */
|
|
|
|
/* we upscale the segment if there is room. Large values may need */
|
|
|
|
/* to be downscaled to avoid overflows during bisection. */
|
|
|
|
/* It is called with either q2 or q3 positive, which is necessary */
|
|
|
|
/* for the peak to exist and avoids undefined FT_MSB. */
|
|
|
|
|
2015-02-16 20:05:08 +01:00
|
|
|
shift = 27 - FT_MSB( (FT_UInt32)( FT_ABS( q1 ) |
|
|
|
|
FT_ABS( q2 ) |
|
|
|
|
FT_ABS( q3 ) |
|
|
|
|
FT_ABS( q4 ) ) );
|
2014-08-13 05:22:17 +02:00
|
|
|
|
|
|
|
if ( shift > 0 )
|
|
|
|
{
|
|
|
|
/* upscaling too much just wastes time */
|
|
|
|
if ( shift > 2 )
|
|
|
|
shift = 2;
|
|
|
|
|
2019-07-24 04:38:30 +02:00
|
|
|
q1 *= 1 << shift;
|
|
|
|
q2 *= 1 << shift;
|
|
|
|
q3 *= 1 << shift;
|
|
|
|
q4 *= 1 << shift;
|
2014-08-13 05:22:17 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
q1 >>= -shift;
|
|
|
|
q2 >>= -shift;
|
|
|
|
q3 >>= -shift;
|
|
|
|
q4 >>= -shift;
|
|
|
|
}
|
|
|
|
|
2014-08-15 04:41:06 +02:00
|
|
|
/* for a peak to exist above 0, the cubic segment must have */
|
|
|
|
/* at least one of its control off-points above 0. */
|
2014-08-13 05:22:17 +02:00
|
|
|
while ( q2 > 0 || q3 > 0 )
|
2000-10-26 02:06:35 +02:00
|
|
|
{
|
2013-02-20 03:27:18 +01:00
|
|
|
/* determine which half contains the maximum and split */
|
|
|
|
if ( q1 + q2 > q3 + q4 ) /* first half */
|
2000-10-26 02:06:35 +02:00
|
|
|
{
|
2013-02-20 03:27:18 +01:00
|
|
|
q4 = q4 + q3;
|
|
|
|
q3 = q3 + q2;
|
|
|
|
q2 = q2 + q1;
|
|
|
|
q4 = q4 + q3;
|
|
|
|
q3 = q3 + q2;
|
2019-04-26 04:06:33 +02:00
|
|
|
q4 = ( q4 + q3 ) >> 3;
|
|
|
|
q3 = q3 >> 2;
|
|
|
|
q2 = q2 >> 1;
|
2000-10-26 02:06:35 +02:00
|
|
|
}
|
2013-02-20 03:27:18 +01:00
|
|
|
else /* second half */
|
2000-10-26 02:06:35 +02:00
|
|
|
{
|
2013-02-20 03:27:18 +01:00
|
|
|
q1 = q1 + q2;
|
|
|
|
q2 = q2 + q3;
|
|
|
|
q3 = q3 + q4;
|
|
|
|
q1 = q1 + q2;
|
|
|
|
q2 = q2 + q3;
|
2019-04-26 04:06:33 +02:00
|
|
|
q1 = ( q1 + q2 ) >> 3;
|
|
|
|
q2 = q2 >> 2;
|
|
|
|
q3 = q3 >> 1;
|
2000-10-26 02:06:35 +02:00
|
|
|
}
|
2013-02-20 03:27:18 +01:00
|
|
|
|
2013-08-27 21:30:09 +02:00
|
|
|
/* check whether either end reached the maximum */
|
2013-02-20 03:27:18 +01:00
|
|
|
if ( q1 == q2 && q1 >= q3 )
|
2000-10-26 02:06:35 +02:00
|
|
|
{
|
2014-08-13 05:22:17 +02:00
|
|
|
peak = q1;
|
2013-02-20 03:27:18 +01:00
|
|
|
break;
|
2000-10-26 02:06:35 +02:00
|
|
|
}
|
2013-02-20 03:27:18 +01:00
|
|
|
if ( q3 == q4 && q2 <= q4 )
|
|
|
|
{
|
2014-08-13 05:22:17 +02:00
|
|
|
peak = q4;
|
2013-02-20 03:27:18 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2000-10-26 02:06:35 +02:00
|
|
|
|
2014-08-13 05:22:17 +02:00
|
|
|
if ( shift > 0 )
|
|
|
|
peak >>= shift;
|
|
|
|
else
|
|
|
|
peak <<= -shift;
|
|
|
|
|
|
|
|
return peak;
|
2013-08-14 04:28:57 +02:00
|
|
|
}
|
2000-10-26 02:06:35 +02:00
|
|
|
|
2013-08-27 21:30:09 +02:00
|
|
|
|
2013-08-14 04:28:57 +02:00
|
|
|
static void
|
|
|
|
BBox_Cubic_Check( FT_Pos p1,
|
|
|
|
FT_Pos p2,
|
|
|
|
FT_Pos p3,
|
|
|
|
FT_Pos p4,
|
|
|
|
FT_Pos* min,
|
|
|
|
FT_Pos* max )
|
|
|
|
{
|
2013-08-20 04:57:05 +02:00
|
|
|
/* This function is only called when a control off-point is outside */
|
2014-08-13 05:22:17 +02:00
|
|
|
/* the bbox that contains all on-points. So at least one of the */
|
|
|
|
/* conditions below holds and cubic_peak is called with at least one */
|
|
|
|
/* non-zero argument. */
|
2013-08-16 04:51:42 +02:00
|
|
|
|
2014-08-13 05:22:17 +02:00
|
|
|
if ( p2 > *max || p3 > *max )
|
|
|
|
*max += cubic_peak( p1 - *max, p2 - *max, p3 - *max, p4 - *max );
|
2000-10-26 02:06:35 +02:00
|
|
|
|
2013-08-14 04:28:57 +02:00
|
|
|
/* now flip the signs to update the minimum */
|
2014-08-13 05:22:17 +02:00
|
|
|
if ( p2 < *min || p3 < *min )
|
|
|
|
*min -= cubic_peak( *min - p1, *min - p2, *min - p3, *min - p4 );
|
2000-10-26 02:06:35 +02:00
|
|
|
}
|
2004-05-19 11:22:26 +02:00
|
|
|
|
2000-10-26 02:06:35 +02:00
|
|
|
|
2018-06-03 09:01:17 +02:00
|
|
|
/**************************************************************************
|
|
|
|
*
|
|
|
|
* @Function:
|
|
|
|
* BBox_Cubic_To
|
|
|
|
*
|
|
|
|
* @Description:
|
|
|
|
* This function is used as a `cubic_to' emitter during
|
|
|
|
* FT_Outline_Decompose(). It checks a cubic Bezier curve with the
|
|
|
|
* current bounding box, and computes its extrema if necessary to
|
|
|
|
* update it.
|
|
|
|
*
|
|
|
|
* @Input:
|
|
|
|
* control1 ::
|
|
|
|
* A pointer to the first control point.
|
|
|
|
*
|
|
|
|
* control2 ::
|
|
|
|
* A pointer to the second control point.
|
|
|
|
*
|
|
|
|
* to ::
|
|
|
|
* A pointer to the destination vector.
|
|
|
|
*
|
|
|
|
* @InOut:
|
|
|
|
* user ::
|
|
|
|
* The address of the current walk context.
|
|
|
|
*
|
|
|
|
* @Return:
|
|
|
|
* Always 0. Needed for the interface only.
|
|
|
|
*
|
|
|
|
* @Note:
|
|
|
|
* In the case of a non-monotonous arc, we don't compute directly
|
|
|
|
* extremum coordinates, we subdivide instead.
|
|
|
|
*/
|
2001-06-27 18:18:10 +02:00
|
|
|
static int
|
|
|
|
BBox_Cubic_To( FT_Vector* control1,
|
|
|
|
FT_Vector* control2,
|
|
|
|
FT_Vector* to,
|
|
|
|
TBBox_Rec* user )
|
2000-10-26 02:06:35 +02:00
|
|
|
{
|
2013-08-27 21:30:09 +02:00
|
|
|
/* We don't need to check `to' since it is always an on-point, */
|
|
|
|
/* thus within the bbox. Only segments with an off-point outside */
|
|
|
|
/* the bbox can possibly reach new extreme values. */
|
2000-11-04 10:41:45 +01:00
|
|
|
|
2000-10-26 02:06:35 +02:00
|
|
|
if ( CHECK_X( control1, user->bbox ) ||
|
2000-11-04 10:41:45 +01:00
|
|
|
CHECK_X( control2, user->bbox ) )
|
2004-05-19 11:22:26 +02:00
|
|
|
BBox_Cubic_Check( user->last.x,
|
|
|
|
control1->x,
|
|
|
|
control2->x,
|
|
|
|
to->x,
|
|
|
|
&user->bbox.xMin,
|
|
|
|
&user->bbox.xMax );
|
2000-10-26 02:06:35 +02:00
|
|
|
|
|
|
|
if ( CHECK_Y( control1, user->bbox ) ||
|
2000-11-04 10:41:45 +01:00
|
|
|
CHECK_Y( control2, user->bbox ) )
|
2004-05-19 11:22:26 +02:00
|
|
|
BBox_Cubic_Check( user->last.y,
|
|
|
|
control1->y,
|
|
|
|
control2->y,
|
|
|
|
to->y,
|
|
|
|
&user->bbox.yMin,
|
|
|
|
&user->bbox.yMax );
|
2000-10-26 02:06:35 +02:00
|
|
|
|
2000-11-03 08:34:29 +01:00
|
|
|
user->last = *to;
|
|
|
|
|
2000-10-26 02:06:35 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-12-06 23:28:58 +01:00
|
|
|
|
2016-09-17 17:12:50 +02:00
|
|
|
FT_DEFINE_OUTLINE_FUNCS(
|
|
|
|
bbox_interface,
|
|
|
|
|
|
|
|
(FT_Outline_MoveTo_Func) BBox_Move_To, /* move_to */
|
|
|
|
(FT_Outline_LineTo_Func) BBox_Line_To, /* line_to */
|
|
|
|
(FT_Outline_ConicTo_Func)BBox_Conic_To, /* conic_to */
|
|
|
|
(FT_Outline_CubicTo_Func)BBox_Cubic_To, /* cubic_to */
|
|
|
|
0, /* shift */
|
|
|
|
0 /* delta */
|
2009-04-05 16:59:26 +02:00
|
|
|
)
|
2000-10-26 02:06:35 +02:00
|
|
|
|
2014-12-06 23:28:58 +01:00
|
|
|
|
2000-11-07 18:21:11 +01:00
|
|
|
/* documentation is in ftbbox.h */
|
|
|
|
|
2001-06-27 18:18:10 +02:00
|
|
|
FT_EXPORT_DEF( FT_Error )
|
|
|
|
FT_Outline_Get_BBox( FT_Outline* outline,
|
|
|
|
FT_BBox *abbox )
|
2000-10-26 02:06:35 +02:00
|
|
|
{
|
2014-12-07 09:40:47 +01:00
|
|
|
FT_BBox cbox = { 0x7FFFFFFFL, 0x7FFFFFFFL,
|
|
|
|
-0x7FFFFFFFL, -0x7FFFFFFFL };
|
|
|
|
FT_BBox bbox = { 0x7FFFFFFFL, 0x7FFFFFFFL,
|
|
|
|
-0x7FFFFFFFL, -0x7FFFFFFFL };
|
2000-10-26 12:04:16 +02:00
|
|
|
FT_Vector* vec;
|
|
|
|
FT_UShort n;
|
2000-10-26 02:06:35 +02:00
|
|
|
|
|
|
|
|
2000-10-26 12:04:16 +02:00
|
|
|
if ( !abbox )
|
2013-03-14 10:27:35 +01:00
|
|
|
return FT_THROW( Invalid_Argument );
|
2000-10-26 12:04:16 +02:00
|
|
|
|
2000-10-26 02:06:35 +02:00
|
|
|
if ( !outline )
|
2013-03-14 10:27:35 +01:00
|
|
|
return FT_THROW( Invalid_Outline );
|
2000-10-26 02:06:35 +02:00
|
|
|
|
2000-10-26 12:04:16 +02:00
|
|
|
/* if outline is empty, return (0,0,0,0) */
|
2000-10-26 02:06:35 +02:00
|
|
|
if ( outline->n_points == 0 || outline->n_contours <= 0 )
|
|
|
|
{
|
|
|
|
abbox->xMin = abbox->xMax = 0;
|
|
|
|
abbox->yMin = abbox->yMax = 0;
|
2016-09-17 17:12:50 +02:00
|
|
|
|
2000-10-26 02:06:35 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We compute the control box as well as the bounding box of */
|
|
|
|
/* all `on' points in the outline. Then, if the two boxes */
|
|
|
|
/* coincide, we exit immediately. */
|
|
|
|
|
|
|
|
vec = outline->points;
|
|
|
|
|
2014-10-11 20:40:51 +02:00
|
|
|
for ( n = 0; n < outline->n_points; n++ )
|
2000-10-26 02:06:35 +02:00
|
|
|
{
|
2016-09-17 17:12:50 +02:00
|
|
|
FT_UPDATE_BBOX( vec, cbox );
|
2000-10-26 02:06:35 +02:00
|
|
|
|
* massive re-formatting changes to many, many source files. I don't
want to list them all here. The operations performed were all logical
transformations of the sources:
- trying to convert all enums and constants to CAPITALIZED_STYLE, with
#define definitions like
#define my_old_constants MY_NEW_CONSTANT
- big, big update of the documentation comments
* include/freetype/freetype.h, src/base/ftobjs.c, src/smooth/ftsmooth.c,
include/freetype/ftimage.h: adding support for LCD-optimized rendering
though the new constants/enums:
FT_RENDER_MODE_LCD, FT_RENDER_MODE_LCD_V
FT_PIXEL_MODE_LCD, FT_PIXEL_MODE_LCD_V
this is still work in progress, don't expect everything to work correctly
though most of the features have been implemented.
* adding new FT_LOAD_XXX flags, used to specify both hinting and rendering
targets:
FT_LOAD_TARGET_NORMAL :: anti-aliased hinting & rendering
FT_LOAD_TARGET_MONO :: monochrome bitmaps
FT_LOAD_TARGET_LCD :: horizontal RGB/BGR decimated hinting & rendering
FT_LOAD_TARGET_LCD_V :: vertical RGB/BGR decimated hinting & rendering
note that FT_LOAD_TARGET_NORMAL is 0, which means that the default
behaviour of the font engine is _unchanged_.
2002-08-27 22:20:29 +02:00
|
|
|
if ( FT_CURVE_TAG( outline->tags[n] ) == FT_CURVE_TAG_ON )
|
2016-09-17 17:12:50 +02:00
|
|
|
FT_UPDATE_BBOX( vec, bbox );
|
2000-10-26 02:06:35 +02:00
|
|
|
|
|
|
|
vec++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* test two boxes for equality */
|
|
|
|
if ( cbox.xMin < bbox.xMin || cbox.xMax > bbox.xMax ||
|
|
|
|
cbox.yMin < bbox.yMin || cbox.yMax > bbox.yMax )
|
|
|
|
{
|
|
|
|
/* the two boxes are different, now walk over the outline to */
|
|
|
|
/* get the Bezier arc extrema. */
|
|
|
|
|
|
|
|
FT_Error error;
|
|
|
|
TBBox_Rec user;
|
|
|
|
|
|
|
|
|
|
|
|
user.bbox = bbox;
|
|
|
|
|
2002-04-30 08:37:52 +02:00
|
|
|
error = FT_Outline_Decompose( outline, &bbox_interface, &user );
|
2000-10-26 02:06:35 +02:00
|
|
|
if ( error )
|
|
|
|
return error;
|
|
|
|
|
|
|
|
*abbox = user.bbox;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
*abbox = bbox;
|
|
|
|
|
|
|
|
return FT_Err_Ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* END */
|