2000-10-26 02:06:35 +02:00
|
|
|
/***************************************************************************/
|
|
|
|
/* */
|
|
|
|
/* ftbbox.c */
|
|
|
|
/* */
|
|
|
|
/* FreeType bbox computation (body). */
|
|
|
|
/* */
|
2004-05-19 11:22:26 +02:00
|
|
|
/* Copyright 1996-2001, 2002, 2004 by */
|
2000-10-26 02:06:35 +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. */
|
|
|
|
/* */
|
|
|
|
/***************************************************************************/
|
|
|
|
|
2000-10-26 12:04:16 +02:00
|
|
|
|
2000-10-26 02:06:35 +02:00
|
|
|
/*************************************************************************/
|
|
|
|
/* */
|
|
|
|
/* This component has a _single_ role: to compute exact outline bounding */
|
|
|
|
/* boxes. */
|
|
|
|
/* */
|
|
|
|
/*************************************************************************/
|
|
|
|
|
2000-12-08 17:17:16 +01:00
|
|
|
|
|
|
|
#include <ft2build.h>
|
|
|
|
#include FT_BBOX_H
|
|
|
|
#include FT_IMAGE_H
|
|
|
|
#include FT_OUTLINE_H
|
2001-04-26 15:34:36 +02:00
|
|
|
#include FT_INTERNAL_CALC_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
|
|
|
|
|
|
|
/*************************************************************************/
|
|
|
|
/* */
|
|
|
|
/* <Function> */
|
|
|
|
/* BBox_Move_To */
|
|
|
|
/* */
|
|
|
|
/* <Description> */
|
|
|
|
/* This function is used as a `move_to' and `line_to' emitter during */
|
2000-10-26 12:04:16 +02:00
|
|
|
/* FT_Outline_Decompose(). It simply records the destination point */
|
2000-11-03 08:34:29 +01:00
|
|
|
/* in `user->last'; no further computations are necessary since we */
|
2004-05-19 11:22:26 +02:00
|
|
|
/* use the cbox as the starting bbox which must be refined. */
|
2000-10-26 02:06:35 +02:00
|
|
|
/* */
|
|
|
|
/* <Input> */
|
|
|
|
/* to :: A pointer to the destination vector. */
|
|
|
|
/* */
|
|
|
|
/* <InOut> */
|
|
|
|
/* user :: A pointer to the current walk context. */
|
|
|
|
/* */
|
|
|
|
/* <Return> */
|
2000-10-26 12:04:16 +02:00
|
|
|
/* Always 0. Needed for the interface only. */
|
2000-10-26 02:06:35 +02:00
|
|
|
/* */
|
2001-06-27 18:18:10 +02:00
|
|
|
static int
|
|
|
|
BBox_Move_To( FT_Vector* to,
|
|
|
|
TBBox_Rec* user )
|
2000-10-26 02:06:35 +02:00
|
|
|
{
|
|
|
|
user->last = *to;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#define CHECK_X( p, bbox ) \
|
|
|
|
( p->x < bbox.xMin || p->x > bbox.xMax )
|
|
|
|
|
|
|
|
#define CHECK_Y( p, bbox ) \
|
|
|
|
( p->y < bbox.yMin || p->y > bbox.yMax )
|
|
|
|
|
|
|
|
|
|
|
|
/*************************************************************************/
|
|
|
|
/* */
|
|
|
|
/* <Function> */
|
|
|
|
/* BBox_Conic_Check */
|
|
|
|
/* */
|
|
|
|
/* <Description> */
|
|
|
|
/* Finds 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. */
|
2004-05-19 11:22:26 +02:00
|
|
|
/* */
|
2000-10-26 02:06:35 +02:00
|
|
|
/* y2 :: The coordinate of the control point. */
|
2004-05-19 11:22:26 +02:00
|
|
|
/* */
|
2000-10-26 02:06:35 +02:00
|
|
|
/* y3 :: The end coordinate. */
|
|
|
|
/* */
|
|
|
|
/* <InOut> */
|
|
|
|
/* min :: The address of the current minimum. */
|
2004-05-19 11:22:26 +02:00
|
|
|
/* */
|
2000-10-26 02:06:35 +02:00
|
|
|
/* 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
|
|
|
{
|
2004-05-19 11:22:26 +02:00
|
|
|
if ( y1 <= y3 && y2 == y1 ) /* flat arc */
|
|
|
|
goto Suite;
|
|
|
|
|
|
|
|
if ( y1 < y3 )
|
2000-10-26 02:06:35 +02:00
|
|
|
{
|
2004-05-19 11:22:26 +02:00
|
|
|
if ( y2 >= y1 && y2 <= y3 ) /* ascending arc */
|
2000-10-26 02:06:35 +02:00
|
|
|
goto Suite;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-05-19 11:22:26 +02:00
|
|
|
if ( y2 >= y3 && y2 <= y1 ) /* descending arc */
|
2000-10-26 02:06:35 +02:00
|
|
|
{
|
|
|
|
y2 = y1;
|
|
|
|
y1 = y3;
|
|
|
|
y3 = y2;
|
|
|
|
goto Suite;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-11-30 00:59:08 +01:00
|
|
|
y1 = y3 = y1 - FT_MulDiv( y2 - y1, y2 - y1, y1 - 2*y2 + y3 );
|
2000-10-26 02:06:35 +02:00
|
|
|
|
|
|
|
Suite:
|
|
|
|
if ( y1 < *min ) *min = y1;
|
|
|
|
if ( y3 > *max ) *max = y3;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*************************************************************************/
|
|
|
|
/* */
|
|
|
|
/* <Function> */
|
|
|
|
/* BBox_Conic_To */
|
|
|
|
/* */
|
|
|
|
/* <Description> */
|
|
|
|
/* This function is used as a `conic_to' emitter during */
|
|
|
|
/* FT_Raster_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. */
|
2004-05-19 11:22:26 +02:00
|
|
|
/* */
|
2000-10-26 02:06:35 +02:00
|
|
|
/* to :: A pointer to the destination vector. */
|
|
|
|
/* */
|
|
|
|
/* <InOut> */
|
|
|
|
/* user :: The address of the current walk context. */
|
|
|
|
/* */
|
|
|
|
/* <Return> */
|
2000-10-26 12:04:16 +02:00
|
|
|
/* Always 0. Needed for the interface only. */
|
2000-10-26 02:06:35 +02:00
|
|
|
/* */
|
|
|
|
/* <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
|
|
|
{
|
2000-11-04 10:41:45 +01:00
|
|
|
/* we don't need to check `to' since it is always an `on' point, thus */
|
|
|
|
/* within the bbox */
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*************************************************************************/
|
|
|
|
/* */
|
|
|
|
/* <Function> */
|
|
|
|
/* BBox_Cubic_Check */
|
|
|
|
/* */
|
|
|
|
/* <Description> */
|
|
|
|
/* Finds the extrema of a 1-dimensional cubic Bezier curve and */
|
|
|
|
/* updates a bounding range. This version uses splitting because we */
|
2004-05-19 11:22:26 +02:00
|
|
|
/* don't want to use square roots and extra accuracy. */
|
2000-10-26 02:06:35 +02:00
|
|
|
/* */
|
|
|
|
/* <Input> */
|
|
|
|
/* p1 :: The start coordinate. */
|
2004-05-19 11:22:26 +02:00
|
|
|
/* */
|
2000-10-26 02:06:35 +02:00
|
|
|
/* p2 :: The coordinate of the first control point. */
|
2004-05-19 11:22:26 +02:00
|
|
|
/* */
|
2000-10-26 02:06:35 +02:00
|
|
|
/* p3 :: The coordinate of the second control point. */
|
2004-05-19 11:22:26 +02:00
|
|
|
/* */
|
2000-10-26 02:06:35 +02:00
|
|
|
/* p4 :: The end coordinate. */
|
|
|
|
/* */
|
|
|
|
/* <InOut> */
|
|
|
|
/* min :: The address of the current minimum. */
|
2004-05-19 11:22:26 +02:00
|
|
|
/* */
|
2000-10-26 02:06:35 +02:00
|
|
|
/* max :: The address of the current maximum. */
|
|
|
|
/* */
|
2004-05-19 11:22:26 +02:00
|
|
|
|
2001-04-25 20:11:16 +02:00
|
|
|
#if 0
|
2004-05-19 11:22:26 +02:00
|
|
|
|
2001-06-27 18:18:10 +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 )
|
2000-10-26 02:06:35 +02:00
|
|
|
{
|
2001-04-26 15:34:36 +02:00
|
|
|
FT_Pos stack[32*3 + 1], *arc;
|
2000-10-26 02:06:35 +02:00
|
|
|
|
|
|
|
|
|
|
|
arc = stack;
|
|
|
|
|
|
|
|
arc[0] = p1;
|
|
|
|
arc[1] = p2;
|
|
|
|
arc[2] = p3;
|
|
|
|
arc[3] = p4;
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
FT_Pos y1 = arc[0];
|
|
|
|
FT_Pos y2 = arc[1];
|
|
|
|
FT_Pos y3 = arc[2];
|
|
|
|
FT_Pos y4 = arc[3];
|
|
|
|
|
|
|
|
|
|
|
|
if ( y1 == y4 )
|
|
|
|
{
|
2004-05-19 11:22:26 +02:00
|
|
|
if ( y1 == y2 && y1 == y3 ) /* flat */
|
2000-10-26 02:06:35 +02:00
|
|
|
goto Test;
|
|
|
|
}
|
|
|
|
else if ( y1 < y4 )
|
|
|
|
{
|
2004-05-19 11:22:26 +02:00
|
|
|
if ( y2 >= y1 && y2 <= y4 && y3 >= y1 && y3 <= y4 ) /* ascending */
|
2000-10-26 02:06:35 +02:00
|
|
|
goto Test;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-05-19 11:22:26 +02:00
|
|
|
if ( y2 >= y4 && y2 <= y1 && y3 >= y4 && y3 <= y1 ) /* descending */
|
2000-10-26 02:06:35 +02:00
|
|
|
{
|
|
|
|
y2 = y1;
|
|
|
|
y1 = y4;
|
|
|
|
y4 = y2;
|
|
|
|
goto Test;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-05-19 11:22:26 +02:00
|
|
|
/* unknown direction -- split the arc in two */
|
2000-10-26 02:06:35 +02:00
|
|
|
arc[6] = y4;
|
|
|
|
arc[1] = y1 = ( y1 + y2 ) / 2;
|
|
|
|
arc[5] = y4 = ( y4 + y3 ) / 2;
|
|
|
|
y2 = ( y2 + y3 ) / 2;
|
|
|
|
arc[2] = y1 = ( y1 + y2 ) / 2;
|
|
|
|
arc[4] = y4 = ( y4 + y2 ) / 2;
|
|
|
|
arc[3] = ( y1 + y4 ) / 2;
|
|
|
|
|
|
|
|
arc += 3;
|
|
|
|
goto Suite;
|
|
|
|
|
|
|
|
Test:
|
|
|
|
if ( y1 < *min ) *min = y1;
|
|
|
|
if ( y4 > *max ) *max = y4;
|
|
|
|
arc -= 3;
|
|
|
|
|
|
|
|
Suite:
|
|
|
|
;
|
2000-10-26 12:04:16 +02:00
|
|
|
} while ( arc >= stack );
|
2000-10-26 02:06:35 +02:00
|
|
|
}
|
2004-05-19 11:22:26 +02:00
|
|
|
|
2001-04-25 20:11:16 +02:00
|
|
|
#else
|
|
|
|
|
|
|
|
static void
|
* include/freetype/fttrigon.h, src/base/fttrigon.c, src/base/ftbase.c,
src/base/Jamfile, src/base/rules.mk: adding trigonometric functions
to the core API (using Cordic algorithms).
* builds/top_level.mk, builds/newline, builds/detect.mk: fixed problems
with Make on Windows 2000, as well as problems when "make distclean" is
invoked on a non-Unix platform when there is no "config.mk" in the
current directory..
* builds/freetype.mk: fixed a problem with object deletions under
Dos/Windows/OS/2 systems
* src/tools: added new directory to hold tools and test programs
moved docmaker.py, glnames.py to it..
* src/tools/docmaker.py: improved the script to add the current date
at the footer of each web page (useful to distinguish between versions)
* Jamfile: fixed incorrect HDRMACRO argument.
* TODO: removed the cubic arc bbox computation note, since it has been
fixed recently..
* include/freetype/t1tables.h, include/freetype/config/ftoption.h:
formatting
2001-05-11 16:25:57 +02:00
|
|
|
test_cubic_extrema( FT_Pos y1,
|
|
|
|
FT_Pos y2,
|
|
|
|
FT_Pos y3,
|
|
|
|
FT_Pos y4,
|
|
|
|
FT_Fixed u,
|
|
|
|
FT_Pos* min,
|
|
|
|
FT_Pos* max )
|
2001-04-25 20:11:16 +02:00
|
|
|
{
|
2001-04-26 15:34:36 +02:00
|
|
|
/* FT_Pos a = y4 - 3*y3 + 3*y2 - y1; */
|
|
|
|
FT_Pos b = y3 - 2*y2 + y1;
|
|
|
|
FT_Pos c = y2 - y1;
|
|
|
|
FT_Pos d = y1;
|
|
|
|
FT_Pos y;
|
|
|
|
FT_Fixed uu;
|
|
|
|
|
|
|
|
FT_UNUSED ( y4 );
|
|
|
|
|
|
|
|
|
2004-05-19 11:22:26 +02:00
|
|
|
/* The polynom is */
|
|
|
|
/* */
|
|
|
|
/* P(x) = a*x^3 + 3b*x^2 + 3c*x + d , */
|
|
|
|
/* */
|
|
|
|
/* dP/dx = 3a*x^2 + 6b*x + 3c . */
|
|
|
|
/* */
|
|
|
|
/* However, we also have */
|
|
|
|
/* */
|
|
|
|
/* dP/dx(u) = 0 , */
|
|
|
|
/* */
|
|
|
|
/* which implies by subtraction that */
|
|
|
|
/* */
|
|
|
|
/* P(u) = b*u^2 + 2c*u + d . */
|
2001-04-26 15:34:36 +02:00
|
|
|
|
2001-04-25 20:11:16 +02:00
|
|
|
if ( u > 0 && u < 0x10000L )
|
|
|
|
{
|
|
|
|
uu = FT_MulFix( u, u );
|
|
|
|
y = d + FT_MulFix( c, 2*u ) + FT_MulFix( b, uu );
|
|
|
|
|
|
|
|
if ( y < *min ) *min = y;
|
|
|
|
if ( y > *max ) *max = y;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-27 18:18:10 +02:00
|
|
|
static void
|
|
|
|
BBox_Cubic_Check( FT_Pos y1,
|
|
|
|
FT_Pos y2,
|
|
|
|
FT_Pos y3,
|
|
|
|
FT_Pos y4,
|
|
|
|
FT_Pos* min,
|
|
|
|
FT_Pos* max )
|
2001-04-25 20:11:16 +02:00
|
|
|
{
|
|
|
|
/* always compare first and last points */
|
|
|
|
if ( y1 < *min ) *min = y1;
|
|
|
|
else if ( y1 > *max ) *max = y1;
|
2001-04-26 15:34:36 +02:00
|
|
|
|
2001-04-25 20:11:16 +02:00
|
|
|
if ( y4 < *min ) *min = y4;
|
|
|
|
else if ( y4 > *max ) *max = y4;
|
|
|
|
|
|
|
|
/* now, try to see if there are split points here */
|
|
|
|
if ( y1 <= y4 )
|
|
|
|
{
|
|
|
|
/* flat or ascending arc test */
|
|
|
|
if ( y1 <= y2 && y2 <= y4 && y1 <= y3 && y3 <= y4 )
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else /* y1 > y4 */
|
|
|
|
{
|
|
|
|
/* descending arc test */
|
|
|
|
if ( y1 >= y2 && y2 >= y4 && y1 >= y3 && y3 >= y4 )
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-04-26 15:34:36 +02:00
|
|
|
/* There are some split points. Find them. */
|
2001-04-25 20:11:16 +02:00
|
|
|
{
|
|
|
|
FT_Pos a = y4 - 3*y3 + 3*y2 - y1;
|
|
|
|
FT_Pos b = y3 - 2*y2 + y1;
|
|
|
|
FT_Pos c = y2 - y1;
|
2001-04-26 15:34:36 +02:00
|
|
|
FT_Pos d;
|
2001-04-25 20:11:16 +02:00
|
|
|
FT_Fixed t;
|
2001-04-26 15:34:36 +02:00
|
|
|
|
|
|
|
|
2004-05-19 11:22:26 +02:00
|
|
|
/* We need to solve `ax^2+2bx+c' here, without floating points! */
|
2001-04-26 15:34:36 +02:00
|
|
|
/* The trick is to normalize to a different representation in order */
|
|
|
|
/* to use our 16.16 fixed point routines. */
|
2001-04-25 20:11:16 +02:00
|
|
|
/* */
|
2004-05-19 11:22:26 +02:00
|
|
|
/* We compute FT_MulFix(b,b) and FT_MulFix(a,c) after normalization. */
|
|
|
|
/* These values must fit into a single 16.16 value. */
|
2001-04-25 20:11:16 +02:00
|
|
|
/* */
|
2004-05-19 11:22:26 +02:00
|
|
|
/* We normalize a, b, and c to `8.16' fixed float values to ensure */
|
|
|
|
/* that its product is held in a `16.16' value. */
|
|
|
|
|
2001-04-25 20:11:16 +02:00
|
|
|
{
|
|
|
|
FT_ULong t1, t2;
|
|
|
|
int shift = 0;
|
2001-04-26 15:34:36 +02:00
|
|
|
|
|
|
|
|
2004-05-19 11:22:26 +02:00
|
|
|
/* The following computation is based on the fact that for */
|
|
|
|
/* any value `y', if `n' is the position of the most */
|
|
|
|
/* significant bit of `abs(y)' (starting from 0 for the */
|
|
|
|
/* least significant bit), then `y' is in the range */
|
|
|
|
/* */
|
|
|
|
/* -2^n..2^n-1 */
|
|
|
|
/* */
|
|
|
|
/* We want to shift `a', `b', and `c' concurrently in order */
|
|
|
|
/* to ensure that they all fit in 8.16 values, which maps */
|
|
|
|
/* to the integer range `-2^23..2^23-1'. */
|
|
|
|
/* */
|
|
|
|
/* Necessarily, we need to shift `a', `b', and `c' so that */
|
|
|
|
/* the most significant bit of its absolute values is at */
|
|
|
|
/* _most_ at position 23. */
|
|
|
|
/* */
|
|
|
|
/* We begin by computing `t1' as the bitwise `OR' of the */
|
|
|
|
/* absolute values of `a', `b', `c'. */
|
|
|
|
|
|
|
|
t1 = (FT_ULong)( ( a >= 0 ) ? a : -a );
|
|
|
|
t2 = (FT_ULong)( ( b >= 0 ) ? b : -b );
|
2001-04-25 20:11:16 +02:00
|
|
|
t1 |= t2;
|
2004-05-19 11:22:26 +02:00
|
|
|
t2 = (FT_ULong)( ( c >= 0 ) ? c : -c );
|
2001-04-25 20:11:16 +02:00
|
|
|
t1 |= t2;
|
2001-04-26 15:34:36 +02:00
|
|
|
|
2004-05-19 11:22:26 +02:00
|
|
|
/* Now we can be sure that the most significant bit of `t1' */
|
|
|
|
/* is the most significant bit of either `a', `b', or `c', */
|
|
|
|
/* depending on the greatest integer range of the particular */
|
|
|
|
/* variable. */
|
|
|
|
/* */
|
|
|
|
/* Next, we compute the `shift', by shifting `t1' as many */
|
|
|
|
/* times as necessary to move its MSB to position 23. This */
|
|
|
|
/* corresponds to a value of `t1' that is in the range */
|
|
|
|
/* 0x40_0000..0x7F_FFFF. */
|
|
|
|
/* */
|
|
|
|
/* Finally, we shift `a', `b', and `c' by the same amount. */
|
|
|
|
/* This ensures that all values are now in the range */
|
|
|
|
/* -2^23..2^23, i.e., they are now expressed as 8.16 */
|
|
|
|
/* fixed-float numbers. This also means that we are using */
|
|
|
|
/* 24 bits of precision to compute the zeros, independently */
|
|
|
|
/* of the range of the original polynomial coefficients. */
|
|
|
|
/* */
|
|
|
|
/* This algorithm should ensure reasonably accurate values */
|
|
|
|
/* for the zeros. Note that they are only expressed with */
|
|
|
|
/* 16 bits when computing the extrema (the zeros need to */
|
|
|
|
/* be in 0..1 exclusive to be considered part of the arc). */
|
|
|
|
|
2001-04-26 15:34:36 +02:00
|
|
|
if ( t1 == 0 ) /* all coefficients are 0! */
|
2001-04-25 20:11:16 +02:00
|
|
|
return;
|
2001-04-26 15:34:36 +02:00
|
|
|
|
* include/freetype/fttrigon.h, src/base/fttrigon.c, src/base/ftbase.c,
src/base/Jamfile, src/base/rules.mk: adding trigonometric functions
to the core API (using Cordic algorithms).
* builds/top_level.mk, builds/newline, builds/detect.mk: fixed problems
with Make on Windows 2000, as well as problems when "make distclean" is
invoked on a non-Unix platform when there is no "config.mk" in the
current directory..
* builds/freetype.mk: fixed a problem with object deletions under
Dos/Windows/OS/2 systems
* src/tools: added new directory to hold tools and test programs
moved docmaker.py, glnames.py to it..
* src/tools/docmaker.py: improved the script to add the current date
at the footer of each web page (useful to distinguish between versions)
* Jamfile: fixed incorrect HDRMACRO argument.
* TODO: removed the cubic arc bbox computation note, since it has been
fixed recently..
* include/freetype/t1tables.h, include/freetype/config/ftoption.h:
formatting
2001-05-11 16:25:57 +02:00
|
|
|
if ( t1 > 0x7FFFFFUL )
|
2001-04-25 20:11:16 +02:00
|
|
|
{
|
|
|
|
do
|
|
|
|
{
|
2001-04-27 11:49:27 +02:00
|
|
|
shift++;
|
2001-04-25 20:11:16 +02:00
|
|
|
t1 >>= 1;
|
2004-05-19 11:22:26 +02:00
|
|
|
|
* include/freetype/fttrigon.h, src/base/fttrigon.c, src/base/ftbase.c,
src/base/Jamfile, src/base/rules.mk: adding trigonometric functions
to the core API (using Cordic algorithms).
* builds/top_level.mk, builds/newline, builds/detect.mk: fixed problems
with Make on Windows 2000, as well as problems when "make distclean" is
invoked on a non-Unix platform when there is no "config.mk" in the
current directory..
* builds/freetype.mk: fixed a problem with object deletions under
Dos/Windows/OS/2 systems
* src/tools: added new directory to hold tools and test programs
moved docmaker.py, glnames.py to it..
* src/tools/docmaker.py: improved the script to add the current date
at the footer of each web page (useful to distinguish between versions)
* Jamfile: fixed incorrect HDRMACRO argument.
* TODO: removed the cubic arc bbox computation note, since it has been
fixed recently..
* include/freetype/t1tables.h, include/freetype/config/ftoption.h:
formatting
2001-05-11 16:25:57 +02:00
|
|
|
} while ( t1 > 0x7FFFFFUL );
|
2001-04-26 15:34:36 +02:00
|
|
|
|
2004-05-19 11:22:26 +02:00
|
|
|
/* this loses some bits of precision, but we use 24 of them */
|
|
|
|
/* for the computation anyway */
|
2001-04-25 20:11:16 +02:00
|
|
|
a >>= shift;
|
|
|
|
b >>= shift;
|
|
|
|
c >>= shift;
|
|
|
|
}
|
* include/freetype/fttrigon.h, src/base/fttrigon.c, src/base/ftbase.c,
src/base/Jamfile, src/base/rules.mk: adding trigonometric functions
to the core API (using Cordic algorithms).
* builds/top_level.mk, builds/newline, builds/detect.mk: fixed problems
with Make on Windows 2000, as well as problems when "make distclean" is
invoked on a non-Unix platform when there is no "config.mk" in the
current directory..
* builds/freetype.mk: fixed a problem with object deletions under
Dos/Windows/OS/2 systems
* src/tools: added new directory to hold tools and test programs
moved docmaker.py, glnames.py to it..
* src/tools/docmaker.py: improved the script to add the current date
at the footer of each web page (useful to distinguish between versions)
* Jamfile: fixed incorrect HDRMACRO argument.
* TODO: removed the cubic arc bbox computation note, since it has been
fixed recently..
* include/freetype/t1tables.h, include/freetype/config/ftoption.h:
formatting
2001-05-11 16:25:57 +02:00
|
|
|
else if ( t1 < 0x400000UL )
|
2001-04-25 20:11:16 +02:00
|
|
|
{
|
|
|
|
do
|
|
|
|
{
|
|
|
|
shift++;
|
|
|
|
t1 <<= 1;
|
2004-05-19 11:22:26 +02:00
|
|
|
|
* include/freetype/fttrigon.h, src/base/fttrigon.c, src/base/ftbase.c,
src/base/Jamfile, src/base/rules.mk: adding trigonometric functions
to the core API (using Cordic algorithms).
* builds/top_level.mk, builds/newline, builds/detect.mk: fixed problems
with Make on Windows 2000, as well as problems when "make distclean" is
invoked on a non-Unix platform when there is no "config.mk" in the
current directory..
* builds/freetype.mk: fixed a problem with object deletions under
Dos/Windows/OS/2 systems
* src/tools: added new directory to hold tools and test programs
moved docmaker.py, glnames.py to it..
* src/tools/docmaker.py: improved the script to add the current date
at the footer of each web page (useful to distinguish between versions)
* Jamfile: fixed incorrect HDRMACRO argument.
* TODO: removed the cubic arc bbox computation note, since it has been
fixed recently..
* include/freetype/t1tables.h, include/freetype/config/ftoption.h:
formatting
2001-05-11 16:25:57 +02:00
|
|
|
} while ( t1 < 0x400000UL );
|
2001-04-26 15:34:36 +02:00
|
|
|
|
2001-04-25 20:11:16 +02:00
|
|
|
a <<= shift;
|
|
|
|
b <<= shift;
|
|
|
|
c <<= shift;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* handle a == 0 */
|
|
|
|
if ( a == 0 )
|
|
|
|
{
|
|
|
|
if ( b != 0 )
|
|
|
|
{
|
2001-04-26 15:34:36 +02:00
|
|
|
t = - FT_DivFix( c, b ) / 2;
|
* include/freetype/fttrigon.h, src/base/fttrigon.c, src/base/ftbase.c,
src/base/Jamfile, src/base/rules.mk: adding trigonometric functions
to the core API (using Cordic algorithms).
* builds/top_level.mk, builds/newline, builds/detect.mk: fixed problems
with Make on Windows 2000, as well as problems when "make distclean" is
invoked on a non-Unix platform when there is no "config.mk" in the
current directory..
* builds/freetype.mk: fixed a problem with object deletions under
Dos/Windows/OS/2 systems
* src/tools: added new directory to hold tools and test programs
moved docmaker.py, glnames.py to it..
* src/tools/docmaker.py: improved the script to add the current date
at the footer of each web page (useful to distinguish between versions)
* Jamfile: fixed incorrect HDRMACRO argument.
* TODO: removed the cubic arc bbox computation note, since it has been
fixed recently..
* include/freetype/t1tables.h, include/freetype/config/ftoption.h:
formatting
2001-05-11 16:25:57 +02:00
|
|
|
test_cubic_extrema( y1, y2, y3, y4, t, min, max );
|
2001-04-25 20:11:16 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* solve the equation now */
|
|
|
|
d = FT_MulFix( b, b ) - FT_MulFix( a, c );
|
|
|
|
if ( d < 0 )
|
|
|
|
return;
|
|
|
|
|
|
|
|
if ( d == 0 )
|
|
|
|
{
|
2001-04-26 15:34:36 +02:00
|
|
|
/* there is a single split point at -b/a */
|
2001-04-25 20:11:16 +02:00
|
|
|
t = - FT_DivFix( b, a );
|
* include/freetype/fttrigon.h, src/base/fttrigon.c, src/base/ftbase.c,
src/base/Jamfile, src/base/rules.mk: adding trigonometric functions
to the core API (using Cordic algorithms).
* builds/top_level.mk, builds/newline, builds/detect.mk: fixed problems
with Make on Windows 2000, as well as problems when "make distclean" is
invoked on a non-Unix platform when there is no "config.mk" in the
current directory..
* builds/freetype.mk: fixed a problem with object deletions under
Dos/Windows/OS/2 systems
* src/tools: added new directory to hold tools and test programs
moved docmaker.py, glnames.py to it..
* src/tools/docmaker.py: improved the script to add the current date
at the footer of each web page (useful to distinguish between versions)
* Jamfile: fixed incorrect HDRMACRO argument.
* TODO: removed the cubic arc bbox computation note, since it has been
fixed recently..
* include/freetype/t1tables.h, include/freetype/config/ftoption.h:
formatting
2001-05-11 16:25:57 +02:00
|
|
|
test_cubic_extrema( y1, y2, y3, y4, t, min, max );
|
2001-04-25 20:11:16 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-05-19 11:22:26 +02:00
|
|
|
/* there are two solutions; we need to filter them */
|
2001-04-25 20:11:16 +02:00
|
|
|
d = FT_SqrtFixed( (FT_Int32)d );
|
|
|
|
t = - FT_DivFix( b - d, a );
|
* include/freetype/fttrigon.h, src/base/fttrigon.c, src/base/ftbase.c,
src/base/Jamfile, src/base/rules.mk: adding trigonometric functions
to the core API (using Cordic algorithms).
* builds/top_level.mk, builds/newline, builds/detect.mk: fixed problems
with Make on Windows 2000, as well as problems when "make distclean" is
invoked on a non-Unix platform when there is no "config.mk" in the
current directory..
* builds/freetype.mk: fixed a problem with object deletions under
Dos/Windows/OS/2 systems
* src/tools: added new directory to hold tools and test programs
moved docmaker.py, glnames.py to it..
* src/tools/docmaker.py: improved the script to add the current date
at the footer of each web page (useful to distinguish between versions)
* Jamfile: fixed incorrect HDRMACRO argument.
* TODO: removed the cubic arc bbox computation note, since it has been
fixed recently..
* include/freetype/t1tables.h, include/freetype/config/ftoption.h:
formatting
2001-05-11 16:25:57 +02:00
|
|
|
test_cubic_extrema( y1, y2, y3, y4, t, min, max );
|
2001-04-26 15:34:36 +02:00
|
|
|
|
2001-04-25 20:11:16 +02:00
|
|
|
t = - FT_DivFix( b + d, a );
|
* include/freetype/fttrigon.h, src/base/fttrigon.c, src/base/ftbase.c,
src/base/Jamfile, src/base/rules.mk: adding trigonometric functions
to the core API (using Cordic algorithms).
* builds/top_level.mk, builds/newline, builds/detect.mk: fixed problems
with Make on Windows 2000, as well as problems when "make distclean" is
invoked on a non-Unix platform when there is no "config.mk" in the
current directory..
* builds/freetype.mk: fixed a problem with object deletions under
Dos/Windows/OS/2 systems
* src/tools: added new directory to hold tools and test programs
moved docmaker.py, glnames.py to it..
* src/tools/docmaker.py: improved the script to add the current date
at the footer of each web page (useful to distinguish between versions)
* Jamfile: fixed incorrect HDRMACRO argument.
* TODO: removed the cubic arc bbox computation note, since it has been
fixed recently..
* include/freetype/t1tables.h, include/freetype/config/ftoption.h:
formatting
2001-05-11 16:25:57 +02:00
|
|
|
test_cubic_extrema( y1, y2, y3, y4, t, min, max );
|
2001-04-25 20:11:16 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2001-04-26 15:34:36 +02:00
|
|
|
}
|
2001-04-25 20:11:16 +02:00
|
|
|
|
|
|
|
#endif
|
2000-10-26 02:06:35 +02:00
|
|
|
|
|
|
|
|
|
|
|
/*************************************************************************/
|
|
|
|
/* */
|
|
|
|
/* <Function> */
|
|
|
|
/* BBox_Cubic_To */
|
|
|
|
/* */
|
|
|
|
/* <Description> */
|
|
|
|
/* This function is used as a `cubic_to' emitter during */
|
|
|
|
/* FT_Raster_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. */
|
2004-05-19 11:22:26 +02:00
|
|
|
/* */
|
2000-10-26 02:06:35 +02:00
|
|
|
/* control2 :: A pointer to the second control point. */
|
2004-05-19 11:22:26 +02:00
|
|
|
/* */
|
2000-10-26 02:06:35 +02:00
|
|
|
/* to :: A pointer to the destination vector. */
|
|
|
|
/* */
|
|
|
|
/* <InOut> */
|
|
|
|
/* user :: The address of the current walk context. */
|
|
|
|
/* */
|
|
|
|
/* <Return> */
|
2000-10-26 12:04:16 +02:00
|
|
|
/* Always 0. Needed for the interface only. */
|
2000-10-26 02:06:35 +02:00
|
|
|
/* */
|
|
|
|
/* <Note> */
|
|
|
|
/* In the case of a non-monotonous arc, we don't compute directly */
|
2004-05-19 11:22:26 +02:00
|
|
|
/* extremum coordinates, we subdivide instead. */
|
2000-10-26 02:06:35 +02:00
|
|
|
/* */
|
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
|
|
|
{
|
2000-11-04 10:41:45 +01:00
|
|
|
/* we don't need to check `to' since it is always an `on' point, thus */
|
|
|
|
/* within the bbox */
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
{
|
2000-10-26 12:04:16 +02:00
|
|
|
FT_BBox cbox;
|
|
|
|
FT_BBox bbox;
|
|
|
|
FT_Vector* vec;
|
|
|
|
FT_UShort n;
|
2000-10-26 02:06:35 +02:00
|
|
|
|
|
|
|
|
2000-10-26 12:04:16 +02:00
|
|
|
if ( !abbox )
|
|
|
|
return FT_Err_Invalid_Argument;
|
|
|
|
|
2000-10-26 02:06:35 +02:00
|
|
|
if ( !outline )
|
|
|
|
return FT_Err_Invalid_Outline;
|
|
|
|
|
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;
|
|
|
|
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;
|
|
|
|
bbox.xMin = bbox.xMax = cbox.xMin = cbox.xMax = vec->x;
|
|
|
|
bbox.yMin = bbox.yMax = cbox.yMin = cbox.yMax = vec->y;
|
2001-04-25 20:11:16 +02:00
|
|
|
vec++;
|
2000-10-26 02:06:35 +02:00
|
|
|
|
|
|
|
for ( n = 1; n < outline->n_points; n++ )
|
|
|
|
{
|
|
|
|
FT_Pos x = vec->x;
|
|
|
|
FT_Pos y = vec->y;
|
|
|
|
|
|
|
|
|
|
|
|
/* update control box */
|
|
|
|
if ( x < cbox.xMin ) cbox.xMin = x;
|
|
|
|
if ( x > cbox.xMax ) cbox.xMax = x;
|
|
|
|
|
|
|
|
if ( y < cbox.yMin ) cbox.yMin = y;
|
|
|
|
if ( y > cbox.yMax ) cbox.yMax = y;
|
|
|
|
|
* 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 )
|
2000-10-26 02:06:35 +02:00
|
|
|
{
|
|
|
|
/* update bbox for `on' points only */
|
|
|
|
if ( x < bbox.xMin ) bbox.xMin = x;
|
|
|
|
if ( x > bbox.xMax ) bbox.xMax = x;
|
|
|
|
|
|
|
|
if ( y < bbox.yMin ) bbox.yMin = y;
|
|
|
|
if ( y > bbox.yMax ) bbox.yMax = y;
|
|
|
|
}
|
|
|
|
|
|
|
|
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. */
|
|
|
|
|
2002-04-30 08:37:52 +02:00
|
|
|
static const FT_Outline_Funcs bbox_interface =
|
2000-10-26 02:06:35 +02:00
|
|
|
{
|
|
|
|
(FT_Outline_MoveTo_Func) BBox_Move_To,
|
|
|
|
(FT_Outline_LineTo_Func) BBox_Move_To,
|
|
|
|
(FT_Outline_ConicTo_Func)BBox_Conic_To,
|
2000-11-06 00:41:08 +01:00
|
|
|
(FT_Outline_CubicTo_Func)BBox_Cubic_To,
|
|
|
|
0, 0
|
2000-10-26 02:06:35 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
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 */
|