Hash :
515bdfef
Author :
Date :
2023-01-04T19:15:38
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
/****************************************************************************
*
* ftsdfcommon.h
*
* Auxiliary data for Signed Distance Field support (specification).
*
* Copyright (C) 2020-2023 by
* David Turner, Robert Wilhelm, and Werner Lemberg.
*
* Written by Anuj Verma.
*
* 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 file contains common functions and properties
* for both the 'sdf' and 'bsdf' renderers.
*
*/
#ifndef FTSDFCOMMON_H_
#define FTSDFCOMMON_H_
#include <ft2build.h>
#include FT_CONFIG_CONFIG_H
#include <freetype/internal/ftobjs.h>
FT_BEGIN_HEADER
/**************************************************************************
*
* default values (cannot be set individually for each renderer)
*
*/
/* default spread value */
#define DEFAULT_SPREAD 8
/* minimum spread supported by the renderer */
#define MIN_SPREAD 2
/* maximum spread supported by the renderer */
#define MAX_SPREAD 32
/* pixel size in 26.6 */
#define ONE_PIXEL ( 1 << 6 )
/**************************************************************************
*
* common definitions (cannot be set individually for each renderer)
*
*/
/* If this macro is set to 1 the rasterizer uses squared distances for */
/* computation. It can greatly improve the performance but there is a */
/* chance of overflow and artifacts. You can safely use it up to a */
/* pixel size of 128. */
#ifndef USE_SQUARED_DISTANCES
#define USE_SQUARED_DISTANCES 0
#endif
/**************************************************************************
*
* common macros
*
*/
/* convert int to 26.6 fixed-point */
#define FT_INT_26D6( x ) ( x * 64 )
/* convert int to 16.16 fixed-point */
#define FT_INT_16D16( x ) ( x * 65536 )
/* convert 26.6 to 16.16 fixed-point */
#define FT_26D6_16D16( x ) ( x * 1024 )
/* Convenience macro to call a function; it */
/* jumps to label `Exit` if an error occurs. */
#define FT_CALL( x ) do \
{ \
error = ( x ); \
if ( error != FT_Err_Ok ) \
goto Exit; \
} while ( 0 )
/*
* The macro `VECTOR_LENGTH_16D16` computes either squared distances or
* actual distances, depending on the value of `USE_SQUARED_DISTANCES`.
*
* By using squared distances the performance can be greatly improved but
* there is a risk of overflow.
*/
#if USE_SQUARED_DISTANCES
#define VECTOR_LENGTH_16D16( v ) ( FT_MulFix( v.x, v.x ) + \
FT_MulFix( v.y, v.y ) )
#else
#define VECTOR_LENGTH_16D16( v ) FT_Vector_Length( &v )
#endif
/**************************************************************************
*
* common typedefs
*
*/
typedef FT_Vector FT_26D6_Vec; /* with 26.6 fixed-point components */
typedef FT_Vector FT_16D16_Vec; /* with 16.16 fixed-point components */
typedef FT_Int32 FT_16D16; /* 16.16 fixed-point representation */
typedef FT_Int32 FT_26D6; /* 26.6 fixed-point representation */
typedef FT_Byte FT_SDFFormat; /* format to represent SDF data */
typedef FT_BBox FT_CBox; /* control box of a curve */
FT_LOCAL( FT_16D16 )
square_root( FT_16D16 val );
FT_LOCAL( FT_SDFFormat )
map_fixed_to_sdf( FT_16D16 dist,
FT_16D16 max_value );
FT_LOCAL( FT_SDFFormat )
invert_sign( FT_SDFFormat dist );
FT_END_HEADER
#endif /* FTSDFCOMMON_H_ */
/* END */