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 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286
/***************************************************************************/
/* */
/* ftoutln.c */
/* */
/* FreeType outline management (body). */
/* */
/* Copyright 1996-1999 by */
/* 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. */
/* */
/***************************************************************************/
/*************************************************************************/
/* */
/* All functions are declared in freetype.h. */
/* */
/*************************************************************************/
#include <freetype.h>
#include <ftconfig.h>
#include <ftobjs.h>
#include <ftimage.h>
#include <ftoutln.h>
/*************************************************************************/
/* */
/* <Function> */
/* FT_Copy_Outline */
/* */
/* <Description> */
/* Copies an outline into another one. Both objects must have the */
/* same sizes (number of points & number of contours) when this */
/* function is called. */
/* */
/* <Input> */
/* source :: A handle to the source outline. */
/* target :: A handle to the target outline. */
/* */
/* <Return> */
/* FreeType error code. 0 means success. */
/* */
BASE_FUNC
FT_Error FT_Copy_Outline( FT_Outline* source,
FT_Outline* target )
{
if ( !source || !target ||
source->n_points != target->n_points ||
source->n_contours != target->n_contours )
return FT_Err_Invalid_Argument;
MEM_Copy( target->points, source->points,
source->n_points * 2 * sizeof ( FT_Pos ) );
MEM_Copy( target->flags, source->flags,
source->n_points * sizeof ( FT_Byte ) );
MEM_Copy( target->contours, source->contours,
source->n_contours * sizeof ( FT_Short ) );
target->high_precision = source->high_precision;
target->second_pass = target->second_pass;
target->dropout_mode = source->dropout_mode;
return FT_Err_Ok;
}
/*************************************************************************/
/* */
/* <Function> */
/* FT_Get_Outline_Bitmap */
/* */
/* <Description> */
/* Renders an outline within a bitmap. The outline's image is simply */
/* or-ed to the target bitmap. */
/* */
/* */
/* <Input> */
/* library :: A handle to a FreeType library object. */
/* outline :: A pointer to the source outline descriptor. */
/* map :: A pointer to the target bitmap descriptor. */
/* */
/* <Return> */
/* FreeType error code. 0 means success. */
/* */
/* <MT-Note> */
/* YES. Rendering is synchronized, so that concurrent calls to the */
/* scan-line converter will be serialized. */
/* */
/* <Note> */
/* This function does NOT CREATE the bitmap, it only renders an */
/* outline image within the one you pass to it! */
/* */
/* It will use the raster correponding to the default glyph format. */
/* */
BASE_FUNC
FT_Error FT_Get_Outline_Bitmap( FT_Library library,
FT_Outline* outline,
FT_Bitmap* map )
{
FT_Error error;
FT_Glyph_Format* format;
error = FT_Err_Invalid_Glyph_Format;
format = FT_Get_Glyph_Format( library, ft_glyph_format_outline );
if (!format) goto Exit;
error = FT_Err_Invalid_Glyph_Format;
if (!format->raster) goto Exit;
error = format->raster_interface->render( format->raster, outline, map );
Exit:
return error;
}
/*************************************************************************/
/* */
/* <Function> */
/* FT_Transform_Outline */
/* */
/* <Description> */
/* Applies a simple 2x2 matrix to all of an outline's points. Useful */
/* for applying rotations, slanting, flipping, etc. */
/* */
/* <Input> */
/* outline :: A pointer to the target outline descriptor. */
/* matrix :: A pointer to the transformation matrix. */
/* */
/* <MT-Note> */
/* Yes. */
/* */
/* <Note> */
/* You can use FT_Translate_Outline() if you need to translate the */
/* outline's points. */
/* */
BASE_FUNC
void FT_Transform_Outline( FT_Outline* outline,
FT_Matrix* matrix )
{
FT_UShort n;
FT_Vector* vec;
vec = outline->points;
for ( n = 0; n < outline->n_points; n++ )
{
FT_Pos x, y;
x = FT_MulFix( vec->x, matrix->xx ) +
FT_MulFix( vec->y, matrix->xy );
y = FT_MulFix( vec->x, matrix->yx ) +
FT_MulFix( vec->y, matrix->yy );
vec->x = x;
vec->y = y;
vec++;
}
}
/*************************************************************************/
/* */
/* <Function> */
/* FT_Transform_Vector */
/* */
/* <Description> */
/* Transforms a single vector through a 2x2 matrix. */
/* */
/* <InOut> */
/* x :: The horizontal vector coordinate. */
/* y :: The vertical vector coordinate. */
/* */
/* <Input> */
/* matrix :: A pointer to the source 2x2 matrix. */
/* */
/* <MT-Note> */
/* Yes. */
/* */
BASE_FUNC
void FT_Transform_Vector( FT_Pos* x,
FT_Pos* y,
FT_Matrix* matrix )
{
FT_Pos xz, yz;
xz = FT_MulFix( *x, matrix->xx ) +
FT_MulFix( *y, matrix->xy );
yz = FT_MulFix( *x, matrix->yx ) +
FT_MulFix( *y, matrix->yy );
*x = xz;
*y = yz;
}
/*************************************************************************/
/* */
/* <Function> */
/* FT_Matrix_Multiply */
/* */
/* <Description> */
/* Performs the matrix operation `b = a*b'. */
/* */
/* <Input> */
/* a :: A pointer to matrix `a'. */
/* */
/* <InOut> */
/* b :: A pointer to matrix `b'. */
/* */
/* <MT-Note> */
/* Yes. */
/* */
BASE_FUNC
void FT_Matrix_Multiply( FT_Matrix* a,
FT_Matrix* b )
{
FT_Fixed xx, xy, yx, yy;
xx = FT_MulFix( a->xx, b->xx ) + FT_MulFix( a->xy, b->yx );
xy = FT_MulFix( a->xx, b->xy ) + FT_MulFix( a->xy, b->yy );
yx = FT_MulFix( a->yx, b->xx ) + FT_MulFix( a->yy, b->yx );
yy = FT_MulFix( a->yx, b->xy ) + FT_MulFix( a->yy, b->yy );
b->xx = xx; b->xy = xy;
b->yx = yx; b->yy = yy;
}
/*************************************************************************/
/* */
/* <Function> */
/* FT_Matrix_Invert */
/* */
/* <Description> */
/* Inverts a 2x2 matrix. Returns an error if it can't be inverted. */
/* */
/* <InOut> */
/* matrix :: A pointer to the target matrix. Remains untouched in */
/* case of error. */
/* */
/* <Return> */
/* FreeType error code. 0 means success. */
/* */
/* <MT-Note> */
/* Yes. */
/* */
BASE_FUNC
FT_Error FT_Matrix_Invert( FT_Matrix* matrix )
{
FT_Pos delta, xx, yy;
/* compute discriminant */
delta = FT_MulFix( matrix->xx, matrix->yy ) -
FT_MulFix( matrix->xy, matrix->yx );
if ( !delta )
return FT_Err_Invalid_Argument; /* matrix can't be inverted */
matrix->xy = - FT_DivFix( matrix->xy, delta );
matrix->yx = - FT_DivFix( matrix->yx, delta );
xx = matrix->xx;
yy = matrix->yy;
matrix->xx = FT_DivFix( yy, delta );
matrix->yy = FT_DivFix( xx, delta );
return FT_Err_Ok;
}
/* END */