2000-08-23 19:32:42 +02:00
|
|
|
/***************************************************************************/
|
|
|
|
/* */
|
|
|
|
/* ftsynth.c */
|
|
|
|
/* */
|
|
|
|
/* FreeType synthesizing code for emboldening and slanting (body). */
|
|
|
|
/* */
|
2001-06-28 19:49:10 +02:00
|
|
|
/* Copyright 2000-2001 by */
|
2000-08-23 19:32:42 +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-12-08 17:17:16 +01:00
|
|
|
|
|
|
|
#include <ft2build.h>
|
|
|
|
#include FT_INTERNAL_OBJECTS_H
|
2001-07-13 00:41:08 +02:00
|
|
|
#include FT_INTERNAL_CALC_H
|
2000-12-08 17:17:16 +01:00
|
|
|
#include FT_OUTLINE_H
|
2002-07-01 23:33:48 +02:00
|
|
|
#include FT_TRIGONOMETRY_H
|
2000-12-08 17:17:16 +01:00
|
|
|
#include FT_SYNTHESIS_H
|
2000-08-23 00:53:03 +02:00
|
|
|
|
2000-08-23 19:32:42 +02:00
|
|
|
|
2000-08-23 00:53:03 +02:00
|
|
|
#define FT_BOLD_THRESHOLD 0x0100
|
|
|
|
|
2000-08-23 19:32:42 +02:00
|
|
|
|
2000-08-23 00:53:03 +02:00
|
|
|
/*************************************************************************/
|
|
|
|
/*************************************************************************/
|
|
|
|
/**** ****/
|
|
|
|
/**** EXPERIMENTAL OBLIQUING SUPPORT ****/
|
|
|
|
/**** ****/
|
|
|
|
/*************************************************************************/
|
|
|
|
/*************************************************************************/
|
|
|
|
|
2002-07-01 23:33:48 +02:00
|
|
|
FT_EXPORT_DEF( void )
|
|
|
|
FT_GlyphSlot_Oblique( FT_GlyphSlot slot )
|
2000-08-23 00:53:03 +02:00
|
|
|
{
|
2002-07-01 23:33:48 +02:00
|
|
|
FT_Matrix transform;
|
|
|
|
FT_Outline* outline = &slot->outline;
|
2000-08-23 19:32:42 +02:00
|
|
|
|
2002-07-26 11:09:10 +02:00
|
|
|
|
2002-07-01 23:33:48 +02:00
|
|
|
/* only oblique outline glyphs */
|
|
|
|
if ( slot->format != ft_glyph_format_outline )
|
|
|
|
return;
|
2000-10-31 21:42:18 +01:00
|
|
|
|
2002-07-01 23:33:48 +02:00
|
|
|
/* we don't touch the advance width */
|
2000-08-23 19:32:42 +02:00
|
|
|
|
2000-08-23 00:53:03 +02:00
|
|
|
/* For italic, simply apply a shear transform, with an angle */
|
2000-08-23 19:32:42 +02:00
|
|
|
/* of about 12 degrees. */
|
2000-10-31 21:42:18 +01:00
|
|
|
|
2000-10-15 23:59:58 +02:00
|
|
|
transform.xx = 0x10000L;
|
|
|
|
transform.yx = 0x00000L;
|
2000-10-31 21:42:18 +01:00
|
|
|
|
2000-10-15 23:59:58 +02:00
|
|
|
transform.xy = 0x06000L;
|
|
|
|
transform.yy = 0x10000L;
|
2000-10-31 21:42:18 +01:00
|
|
|
|
2000-10-15 23:59:58 +02:00
|
|
|
FT_Outline_Transform( outline, &transform );
|
2000-08-23 00:53:03 +02:00
|
|
|
}
|
|
|
|
|
2000-08-23 19:32:42 +02:00
|
|
|
|
2000-08-23 00:53:03 +02:00
|
|
|
/*************************************************************************/
|
|
|
|
/*************************************************************************/
|
|
|
|
/**** ****/
|
|
|
|
/**** EXPERIMENTAL EMBOLDENING/OUTLINING SUPPORT ****/
|
|
|
|
/**** ****/
|
|
|
|
/*************************************************************************/
|
|
|
|
/*************************************************************************/
|
|
|
|
|
2000-08-23 19:32:42 +02:00
|
|
|
|
2000-08-23 00:53:03 +02:00
|
|
|
|
2001-06-27 18:18:10 +02:00
|
|
|
static int
|
|
|
|
ft_test_extrema( FT_Outline* outline,
|
|
|
|
int n )
|
2000-08-23 00:53:03 +02:00
|
|
|
{
|
|
|
|
FT_Vector *prev, *cur, *next;
|
|
|
|
FT_Pos product;
|
|
|
|
FT_Int c, first, last;
|
|
|
|
|
|
|
|
|
|
|
|
/* we need to compute the `previous' and `next' point */
|
|
|
|
/* for these extrema. */
|
|
|
|
cur = outline->points + n;
|
|
|
|
prev = cur - 1;
|
|
|
|
next = cur + 1;
|
|
|
|
|
|
|
|
first = 0;
|
|
|
|
for ( c = 0; c < outline->n_contours; c++ )
|
|
|
|
{
|
|
|
|
last = outline->contours[c];
|
|
|
|
|
|
|
|
if ( n == first )
|
|
|
|
prev = outline->points + last;
|
|
|
|
|
|
|
|
if ( n == last )
|
|
|
|
next = outline->points + first;
|
|
|
|
|
|
|
|
first = last + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
product = FT_MulDiv( cur->x - prev->x, /* in.x */
|
|
|
|
next->y - cur->y, /* out.y */
|
|
|
|
0x40 )
|
|
|
|
-
|
|
|
|
FT_MulDiv( cur->y - prev->y, /* in.y */
|
|
|
|
next->x - cur->x, /* out.x */
|
|
|
|
0x40 );
|
|
|
|
|
|
|
|
if ( product )
|
|
|
|
product = product > 0 ? 1 : -1;
|
|
|
|
|
|
|
|
return product;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Compute the orientation of path filling. It differs between TrueType */
|
|
|
|
/* and Type1 formats. We could use the `ft_outline_reverse_fill' flag, */
|
|
|
|
/* but it is better to re-compute it directly (it seems that this flag */
|
|
|
|
/* isn't correctly set for some weird composite glyphs currently). */
|
|
|
|
/* */
|
|
|
|
/* We do this by computing bounding box points, and computing their */
|
|
|
|
/* curvature. */
|
|
|
|
/* */
|
|
|
|
/* The function returns either 1 or -1. */
|
|
|
|
/* */
|
2001-06-27 18:18:10 +02:00
|
|
|
static int
|
|
|
|
ft_get_orientation( FT_Outline* outline )
|
2000-08-23 00:53:03 +02:00
|
|
|
{
|
|
|
|
FT_BBox box;
|
|
|
|
FT_BBox indices;
|
|
|
|
int n, last;
|
|
|
|
|
|
|
|
|
|
|
|
indices.xMin = -1;
|
|
|
|
indices.yMin = -1;
|
|
|
|
indices.xMax = -1;
|
|
|
|
indices.yMax = -1;
|
|
|
|
|
|
|
|
box.xMin = box.yMin = 32767;
|
|
|
|
box.xMax = box.yMax = -32768;
|
|
|
|
|
|
|
|
/* is it empty ? */
|
|
|
|
if ( outline->n_contours < 1 )
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
last = outline->contours[outline->n_contours - 1];
|
|
|
|
|
|
|
|
for ( n = 0; n <= last; n++ )
|
|
|
|
{
|
|
|
|
FT_Pos x, y;
|
|
|
|
|
|
|
|
|
|
|
|
x = outline->points[n].x;
|
|
|
|
if ( x < box.xMin )
|
|
|
|
{
|
|
|
|
box.xMin = x;
|
|
|
|
indices.xMin = n;
|
|
|
|
}
|
|
|
|
if ( x > box.xMax )
|
|
|
|
{
|
|
|
|
box.xMax = x;
|
|
|
|
indices.xMax = n;
|
|
|
|
}
|
|
|
|
|
|
|
|
y = outline->points[n].y;
|
|
|
|
if ( y < box.yMin )
|
|
|
|
{
|
|
|
|
box.yMin = y;
|
|
|
|
indices.yMin = n;
|
|
|
|
}
|
|
|
|
if ( y > box.yMax )
|
|
|
|
{
|
|
|
|
box.yMax = y;
|
|
|
|
indices.yMax = n;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* test orientation of the xmin */
|
|
|
|
n = ft_test_extrema( outline, indices.xMin );
|
2000-08-23 19:32:42 +02:00
|
|
|
if ( n )
|
2000-08-23 00:53:03 +02:00
|
|
|
goto Exit;
|
2000-10-31 21:42:18 +01:00
|
|
|
|
2000-08-23 00:53:03 +02:00
|
|
|
n = ft_test_extrema( outline, indices.yMin );
|
2000-08-23 19:32:42 +02:00
|
|
|
if ( n )
|
2000-08-23 00:53:03 +02:00
|
|
|
goto Exit;
|
2000-10-31 21:42:18 +01:00
|
|
|
|
2000-08-23 00:53:03 +02:00
|
|
|
n = ft_test_extrema( outline, indices.xMax );
|
2000-08-23 19:32:42 +02:00
|
|
|
if ( n )
|
2000-08-23 00:53:03 +02:00
|
|
|
goto Exit;
|
2000-10-31 21:42:18 +01:00
|
|
|
|
2000-08-23 00:53:03 +02:00
|
|
|
n = ft_test_extrema( outline, indices.yMax );
|
2000-08-23 19:32:42 +02:00
|
|
|
if ( !n )
|
2000-08-23 00:53:03 +02:00
|
|
|
n = 1;
|
|
|
|
|
|
|
|
Exit:
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-07-01 23:33:48 +02:00
|
|
|
FT_EXPORT_DEF( void )
|
|
|
|
FT_GlyphSlot_Embolden( FT_GlyphSlot slot )
|
2000-08-23 00:53:03 +02:00
|
|
|
{
|
2002-07-01 23:33:48 +02:00
|
|
|
FT_Vector* points;
|
|
|
|
FT_Vector v_prev, v_first, v_next, v_cur;
|
|
|
|
FT_Pos distance;
|
|
|
|
FT_Outline* outline = &slot->outline;
|
|
|
|
FT_Face face = FT_SLOT_FACE( slot );
|
|
|
|
FT_Angle rotate, angle_in, angle_out;
|
|
|
|
FT_Int c, n, first, orientation;
|
|
|
|
|
2002-07-26 11:09:10 +02:00
|
|
|
|
2002-07-01 23:33:48 +02:00
|
|
|
/* only embolden outline glyph images */
|
|
|
|
if ( slot->format != ft_glyph_format_outline )
|
|
|
|
return;
|
2000-08-23 00:53:03 +02:00
|
|
|
|
|
|
|
/* compute control distance */
|
|
|
|
distance = FT_MulFix( face->units_per_EM / 60,
|
|
|
|
face->size->metrics.y_scale );
|
|
|
|
|
2002-07-01 23:33:48 +02:00
|
|
|
orientation = ft_get_orientation( outline );
|
|
|
|
rotate = FT_ANGLE_PI2*orientation;
|
2000-08-23 00:53:03 +02:00
|
|
|
|
2002-07-01 23:33:48 +02:00
|
|
|
points = outline->points;
|
2000-08-23 00:53:03 +02:00
|
|
|
|
|
|
|
first = 0;
|
|
|
|
for ( c = 0; c < outline->n_contours; c++ )
|
|
|
|
{
|
|
|
|
int last = outline->contours[c];
|
|
|
|
|
|
|
|
|
2002-07-01 23:33:48 +02:00
|
|
|
v_first = points[first];
|
|
|
|
v_prev = points[last];
|
2000-08-23 00:53:03 +02:00
|
|
|
|
|
|
|
for ( n = first; n <= last; n++ )
|
|
|
|
{
|
2002-07-01 23:33:48 +02:00
|
|
|
FT_Pos d;
|
2000-08-23 00:53:03 +02:00
|
|
|
FT_Vector in, out;
|
2002-07-01 23:33:48 +02:00
|
|
|
FT_Fixed scale;
|
|
|
|
FT_Angle angle_diff;
|
2000-08-23 00:53:03 +02:00
|
|
|
|
|
|
|
|
2002-07-01 23:33:48 +02:00
|
|
|
if ( n < last ) v_next = points[n + 1];
|
|
|
|
else v_next = v_first;
|
2000-08-23 00:53:03 +02:00
|
|
|
|
|
|
|
/* compute the in and out vectors */
|
2002-07-01 23:33:48 +02:00
|
|
|
in.x = v_cur.x - v_prev.x;
|
|
|
|
in.y = v_cur.y - v_prev.y;
|
2000-08-23 00:53:03 +02:00
|
|
|
|
2002-07-01 23:33:48 +02:00
|
|
|
out.x = v_next.x - v_cur.x;
|
|
|
|
out.y = v_next.y - v_cur.y;
|
2000-08-23 00:53:03 +02:00
|
|
|
|
2002-07-01 23:33:48 +02:00
|
|
|
angle_in = FT_Atan2( in.x, in.y );
|
|
|
|
angle_out = FT_Atan2( out.x, out.y );
|
|
|
|
angle_diff = FT_Angle_Diff( angle_in, angle_out );
|
|
|
|
scale = FT_Cos( angle_diff/2 );
|
2000-08-23 00:53:03 +02:00
|
|
|
|
2002-07-01 23:33:48 +02:00
|
|
|
if ( scale < 0x4000L )
|
|
|
|
scale = 0x4000L;
|
2000-08-23 00:53:03 +02:00
|
|
|
|
2002-07-01 23:33:48 +02:00
|
|
|
d = FT_DivFix( distance, scale );
|
2000-08-23 00:53:03 +02:00
|
|
|
|
2002-07-01 23:33:48 +02:00
|
|
|
FT_Vector_From_Polar( &in, d, (angle_in+angle_out)/2 + rotate );
|
2000-08-23 00:53:03 +02:00
|
|
|
|
2002-07-01 23:33:48 +02:00
|
|
|
outline->points[n].x = v_cur.x + distance + in.x;
|
|
|
|
outline->points[n].y = v_cur.y + distance + in.y;
|
2000-08-23 00:53:03 +02:00
|
|
|
|
2002-07-01 23:33:48 +02:00
|
|
|
v_prev = v_cur;
|
|
|
|
v_cur = v_next;
|
2000-08-23 00:53:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
first = last + 1;
|
|
|
|
}
|
|
|
|
|
2002-07-01 23:33:48 +02:00
|
|
|
slot->metrics.horiAdvance = ( slot->metrics.horiAdvance + distance*4 ) & -64;
|
2000-08-23 00:53:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-08-23 19:32:42 +02:00
|
|
|
/* END */
|