code stringlengths 1 1.05M | repo_name stringlengths 6 83 | path stringlengths 3 242 | language stringclasses 222
values | license stringclasses 20
values | size int64 1 1.05M |
|---|---|---|---|---|---|
/***************************************************************************/
/* */
/* ftvalid.h */
/* */
/* FreeType validation support (specification). */
/* */
/* Copyright 2004, 2013 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. */
/* */
/***************************************************************************/
#ifndef __FTVALID_H__
#define __FTVALID_H__
#include <ft2build.h>
#include FT_CONFIG_STANDARD_LIBRARY_H /* for ft_setjmp and ft_longjmp */
FT_BEGIN_HEADER
/*************************************************************************/
/*************************************************************************/
/*************************************************************************/
/**** ****/
/**** ****/
/**** V A L I D A T I O N ****/
/**** ****/
/**** ****/
/*************************************************************************/
/*************************************************************************/
/*************************************************************************/
/* handle to a validation object */
typedef struct FT_ValidatorRec_ volatile* FT_Validator;
/*************************************************************************/
/* */
/* There are three distinct validation levels defined here: */
/* */
/* FT_VALIDATE_DEFAULT :: */
/* A table that passes this validation level can be used reliably by */
/* FreeType. It generally means that all offsets have been checked to */
/* prevent out-of-bound reads, that array counts are correct, etc. */
/* */
/* FT_VALIDATE_TIGHT :: */
/* A table that passes this validation level can be used reliably and */
/* doesn't contain invalid data. For example, a charmap table that */
/* returns invalid glyph indices will not pass, even though it can */
/* be used with FreeType in default mode (the library will simply */
/* return an error later when trying to load the glyph). */
/* */
/* It also checks that fields which must be a multiple of 2, 4, or 8, */
/* don't have incorrect values, etc. */
/* */
/* FT_VALIDATE_PARANOID :: */
/* Only for font debugging. Checks that a table follows the */
/* specification by 100%. Very few fonts will be able to pass this */
/* level anyway but it can be useful for certain tools like font */
/* editors/converters. */
/* */
typedef enum FT_ValidationLevel_
{
FT_VALIDATE_DEFAULT = 0,
FT_VALIDATE_TIGHT,
FT_VALIDATE_PARANOID
} FT_ValidationLevel;
#if defined( _MSC_VER ) /* Visual C++ (and Intel C++) */
/* We disable the warning `structure was padded due to */
/* __declspec(align())' in order to compile cleanly with */
/* the maximum level of warnings. */
#pragma warning( push )
#pragma warning( disable : 4324 )
#endif /* _MSC_VER */
/* validator structure */
typedef struct FT_ValidatorRec_
{
const FT_Byte* base; /* address of table in memory */
const FT_Byte* limit; /* `base' + sizeof(table) in memory */
FT_ValidationLevel level; /* validation level */
FT_Error error; /* error returned. 0 means success */
ft_jmp_buf jump_buffer; /* used for exception handling */
} FT_ValidatorRec;
#if defined( _MSC_VER )
#pragma warning( pop )
#endif
#define FT_VALIDATOR( x ) ( (FT_Validator)( x ) )
FT_BASE( void )
ft_validator_init( FT_Validator valid,
const FT_Byte* base,
const FT_Byte* limit,
FT_ValidationLevel level );
/* Do not use this. It's broken and will cause your validator to crash */
/* if you run it on an invalid font. */
FT_BASE( FT_Int )
ft_validator_run( FT_Validator valid );
/* Sets the error field in a validator, then calls `longjmp' to return */
/* to high-level caller. Using `setjmp/longjmp' avoids many stupid */
/* error checks within the validation routines. */
/* */
FT_BASE( void )
ft_validator_error( FT_Validator valid,
FT_Error error );
/* Calls ft_validate_error. Assumes that the `valid' local variable */
/* holds a pointer to the current validator object. */
/* */
/* Use preprocessor prescan to pass FT_ERR_PREFIX. */
/* */
#define FT_INVALID( _prefix, _error ) FT_INVALID_( _prefix, _error )
#define FT_INVALID_( _prefix, _error ) \
ft_validator_error( valid, _prefix ## _error )
/* called when a broken table is detected */
#define FT_INVALID_TOO_SHORT \
FT_INVALID( FT_ERR_PREFIX, Invalid_Table )
/* called when an invalid offset is detected */
#define FT_INVALID_OFFSET \
FT_INVALID( FT_ERR_PREFIX, Invalid_Offset )
/* called when an invalid format/value is detected */
#define FT_INVALID_FORMAT \
FT_INVALID( FT_ERR_PREFIX, Invalid_Table )
/* called when an invalid glyph index is detected */
#define FT_INVALID_GLYPH_ID \
FT_INVALID( FT_ERR_PREFIX, Invalid_Glyph_Index )
/* called when an invalid field value is detected */
#define FT_INVALID_DATA \
FT_INVALID( FT_ERR_PREFIX, Invalid_Table )
FT_END_HEADER
#endif /* __FTVALID_H__ */
/* END */
| YifuLiu/AliOS-Things | components/freetype/include/internal/ftvalid.h | C | apache-2.0 | 7,489 |
/***************************************************************************/
/* */
/* internal.h */
/* */
/* Internal header files (specification only). */
/* */
/* Copyright 1996-2004, 2013 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. */
/* */
/***************************************************************************/
/*************************************************************************/
/* */
/* This file is automatically included by `ft2build.h'. */
/* Do not include it manually! */
/* */
/*************************************************************************/
#define FT_INTERNAL_OBJECTS_H <internal/ftobjs.h>
#define FT_INTERNAL_PIC_H <internal/ftpic.h>
#define FT_INTERNAL_STREAM_H <internal/ftstream.h>
#define FT_INTERNAL_MEMORY_H <internal/ftmemory.h>
#define FT_INTERNAL_DEBUG_H <internal/ftdebug.h>
#define FT_INTERNAL_CALC_H <internal/ftcalc.h>
#define FT_INTERNAL_DRIVER_H <internal/ftdriver.h>
#define FT_INTERNAL_TRACE_H <internal/fttrace.h>
#define FT_INTERNAL_GLYPH_LOADER_H <internal/ftgloadr.h>
#define FT_INTERNAL_SFNT_H <internal/sfnt.h>
#define FT_INTERNAL_SERVICE_H <internal/ftserv.h>
#define FT_INTERNAL_RFORK_H <internal/ftrfork.h>
#define FT_INTERNAL_VALIDATE_H <internal/ftvalid.h>
#define FT_INTERNAL_TRUETYPE_TYPES_H <internal/tttypes.h>
#define FT_INTERNAL_TYPE1_TYPES_H <internal/t1types.h>
#define FT_INTERNAL_POSTSCRIPT_AUX_H <internal/psaux.h>
#define FT_INTERNAL_POSTSCRIPT_HINTS_H <internal/pshints.h>
#define FT_INTERNAL_POSTSCRIPT_GLOBALS_H <internal/psglobal.h>
#define FT_INTERNAL_AUTOHINT_H <internal/autohint.h>
#if defined( _MSC_VER ) /* Visual C++ (and Intel C++) */
/* We disable the warning `conditional expression is constant' here */
/* in order to compile cleanly with the maximum level of warnings. */
/* In particular, the warning complains about stuff like `while(0)' */
/* which is very useful in macro definitions. There is no benefit */
/* in having it enabled. */
#pragma warning( disable : 4127 )
#endif /* _MSC_VER */
/* END */
| YifuLiu/AliOS-Things | components/freetype/include/internal/internal.h | C | apache-2.0 | 3,415 |
/***************************************************************************/
/* */
/* psaux.h */
/* */
/* Auxiliary functions and data structures related to PostScript fonts */
/* (specification). */
/* */
/* Copyright 1996-2004, 2006, 2008, 2009, 2012 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. */
/* */
/***************************************************************************/
#ifndef __PSAUX_H__
#define __PSAUX_H__
#include <ft2build.h>
#include FT_INTERNAL_OBJECTS_H
#include FT_INTERNAL_TYPE1_TYPES_H
#include FT_SERVICE_POSTSCRIPT_CMAPS_H
FT_BEGIN_HEADER
/*************************************************************************/
/*************************************************************************/
/***** *****/
/***** T1_TABLE *****/
/***** *****/
/*************************************************************************/
/*************************************************************************/
typedef struct PS_TableRec_* PS_Table;
typedef const struct PS_Table_FuncsRec_* PS_Table_Funcs;
/*************************************************************************/
/* */
/* <Struct> */
/* PS_Table_FuncsRec */
/* */
/* <Description> */
/* A set of function pointers to manage PS_Table objects. */
/* */
/* <Fields> */
/* table_init :: Used to initialize a table. */
/* */
/* table_done :: Finalizes resp. destroy a given table. */
/* */
/* table_add :: Adds a new object to a table. */
/* */
/* table_release :: Releases table data, then finalizes it. */
/* */
typedef struct PS_Table_FuncsRec_
{
FT_Error
(*init)( PS_Table table,
FT_Int count,
FT_Memory memory );
void
(*done)( PS_Table table );
FT_Error
(*add)( PS_Table table,
FT_Int idx,
void* object,
FT_PtrDist length );
void
(*release)( PS_Table table );
} PS_Table_FuncsRec;
/*************************************************************************/
/* */
/* <Struct> */
/* PS_TableRec */
/* */
/* <Description> */
/* A PS_Table is a simple object used to store an array of objects in */
/* a single memory block. */
/* */
/* <Fields> */
/* block :: The address in memory of the growheap's block. This */
/* can change between two object adds, due to */
/* reallocation. */
/* */
/* cursor :: The current top of the grow heap within its block. */
/* */
/* capacity :: The current size of the heap block. Increments by */
/* 1kByte chunks. */
/* */
/* init :: Set to 0xDEADBEEF if `elements' and `lengths' have */
/* been allocated. */
/* */
/* max_elems :: The maximum number of elements in table. */
/* */
/* num_elems :: The current number of elements in table. */
/* */
/* elements :: A table of element addresses within the block. */
/* */
/* lengths :: A table of element sizes within the block. */
/* */
/* memory :: The object used for memory operations */
/* (alloc/realloc). */
/* */
/* funcs :: A table of method pointers for this object. */
/* */
typedef struct PS_TableRec_
{
FT_Byte* block; /* current memory block */
FT_Offset cursor; /* current cursor in memory block */
FT_Offset capacity; /* current size of memory block */
FT_Long init;
FT_Int max_elems;
FT_Int num_elems;
FT_Byte** elements; /* addresses of table elements */
FT_PtrDist* lengths; /* lengths of table elements */
FT_Memory memory;
PS_Table_FuncsRec funcs;
} PS_TableRec;
/*************************************************************************/
/*************************************************************************/
/***** *****/
/***** T1 FIELDS & TOKENS *****/
/***** *****/
/*************************************************************************/
/*************************************************************************/
typedef struct PS_ParserRec_* PS_Parser;
typedef struct T1_TokenRec_* T1_Token;
typedef struct T1_FieldRec_* T1_Field;
/* simple enumeration type used to identify token types */
typedef enum T1_TokenType_
{
T1_TOKEN_TYPE_NONE = 0,
T1_TOKEN_TYPE_ANY,
T1_TOKEN_TYPE_STRING,
T1_TOKEN_TYPE_ARRAY,
T1_TOKEN_TYPE_KEY, /* aka `name' */
/* do not remove */
T1_TOKEN_TYPE_MAX
} T1_TokenType;
/* a simple structure used to identify tokens */
typedef struct T1_TokenRec_
{
FT_Byte* start; /* first character of token in input stream */
FT_Byte* limit; /* first character after the token */
T1_TokenType type; /* type of token */
} T1_TokenRec;
/* enumeration type used to identify object fields */
typedef enum T1_FieldType_
{
T1_FIELD_TYPE_NONE = 0,
T1_FIELD_TYPE_BOOL,
T1_FIELD_TYPE_INTEGER,
T1_FIELD_TYPE_FIXED,
T1_FIELD_TYPE_FIXED_1000,
T1_FIELD_TYPE_STRING,
T1_FIELD_TYPE_KEY,
T1_FIELD_TYPE_BBOX,
T1_FIELD_TYPE_MM_BBOX,
T1_FIELD_TYPE_INTEGER_ARRAY,
T1_FIELD_TYPE_FIXED_ARRAY,
T1_FIELD_TYPE_CALLBACK,
/* do not remove */
T1_FIELD_TYPE_MAX
} T1_FieldType;
typedef enum T1_FieldLocation_
{
T1_FIELD_LOCATION_CID_INFO,
T1_FIELD_LOCATION_FONT_DICT,
T1_FIELD_LOCATION_FONT_EXTRA,
T1_FIELD_LOCATION_FONT_INFO,
T1_FIELD_LOCATION_PRIVATE,
T1_FIELD_LOCATION_BBOX,
T1_FIELD_LOCATION_LOADER,
T1_FIELD_LOCATION_FACE,
T1_FIELD_LOCATION_BLEND,
/* do not remove */
T1_FIELD_LOCATION_MAX
} T1_FieldLocation;
typedef void
(*T1_Field_ParseFunc)( FT_Face face,
FT_Pointer parser );
/* structure type used to model object fields */
typedef struct T1_FieldRec_
{
const char* ident; /* field identifier */
T1_FieldLocation location;
T1_FieldType type; /* type of field */
T1_Field_ParseFunc reader;
FT_UInt offset; /* offset of field in object */
FT_Byte size; /* size of field in bytes */
FT_UInt array_max; /* maximum number of elements for */
/* array */
FT_UInt count_offset; /* offset of element count for */
/* arrays; must not be zero if in */
/* use -- in other words, a */
/* `num_FOO' element must not */
/* start the used structure if we */
/* parse a `FOO' array */
FT_UInt dict; /* where we expect it */
} T1_FieldRec;
#define T1_FIELD_DICT_FONTDICT ( 1 << 0 ) /* also FontInfo and FDArray */
#define T1_FIELD_DICT_PRIVATE ( 1 << 1 )
#define T1_NEW_SIMPLE_FIELD( _ident, _type, _fname, _dict ) \
{ \
_ident, T1CODE, _type, \
0, \
FT_FIELD_OFFSET( _fname ), \
FT_FIELD_SIZE( _fname ), \
0, 0, \
_dict \
},
#define T1_NEW_CALLBACK_FIELD( _ident, _reader, _dict ) \
{ \
_ident, T1CODE, T1_FIELD_TYPE_CALLBACK, \
(T1_Field_ParseFunc)_reader, \
0, 0, \
0, 0, \
_dict \
},
#define T1_NEW_TABLE_FIELD( _ident, _type, _fname, _max, _dict ) \
{ \
_ident, T1CODE, _type, \
0, \
FT_FIELD_OFFSET( _fname ), \
FT_FIELD_SIZE_DELTA( _fname ), \
_max, \
FT_FIELD_OFFSET( num_ ## _fname ), \
_dict \
},
#define T1_NEW_TABLE_FIELD2( _ident, _type, _fname, _max, _dict ) \
{ \
_ident, T1CODE, _type, \
0, \
FT_FIELD_OFFSET( _fname ), \
FT_FIELD_SIZE_DELTA( _fname ), \
_max, 0, \
_dict \
},
#define T1_FIELD_BOOL( _ident, _fname, _dict ) \
T1_NEW_SIMPLE_FIELD( _ident, T1_FIELD_TYPE_BOOL, _fname, _dict )
#define T1_FIELD_NUM( _ident, _fname, _dict ) \
T1_NEW_SIMPLE_FIELD( _ident, T1_FIELD_TYPE_INTEGER, _fname, _dict )
#define T1_FIELD_FIXED( _ident, _fname, _dict ) \
T1_NEW_SIMPLE_FIELD( _ident, T1_FIELD_TYPE_FIXED, _fname, _dict )
#define T1_FIELD_FIXED_1000( _ident, _fname, _dict ) \
T1_NEW_SIMPLE_FIELD( _ident, T1_FIELD_TYPE_FIXED_1000, _fname, \
_dict )
#define T1_FIELD_STRING( _ident, _fname, _dict ) \
T1_NEW_SIMPLE_FIELD( _ident, T1_FIELD_TYPE_STRING, _fname, _dict )
#define T1_FIELD_KEY( _ident, _fname, _dict ) \
T1_NEW_SIMPLE_FIELD( _ident, T1_FIELD_TYPE_KEY, _fname, _dict )
#define T1_FIELD_BBOX( _ident, _fname, _dict ) \
T1_NEW_SIMPLE_FIELD( _ident, T1_FIELD_TYPE_BBOX, _fname, _dict )
#define T1_FIELD_NUM_TABLE( _ident, _fname, _fmax, _dict ) \
T1_NEW_TABLE_FIELD( _ident, T1_FIELD_TYPE_INTEGER_ARRAY, \
_fname, _fmax, _dict )
#define T1_FIELD_FIXED_TABLE( _ident, _fname, _fmax, _dict ) \
T1_NEW_TABLE_FIELD( _ident, T1_FIELD_TYPE_FIXED_ARRAY, \
_fname, _fmax, _dict )
#define T1_FIELD_NUM_TABLE2( _ident, _fname, _fmax, _dict ) \
T1_NEW_TABLE_FIELD2( _ident, T1_FIELD_TYPE_INTEGER_ARRAY, \
_fname, _fmax, _dict )
#define T1_FIELD_FIXED_TABLE2( _ident, _fname, _fmax, _dict ) \
T1_NEW_TABLE_FIELD2( _ident, T1_FIELD_TYPE_FIXED_ARRAY, \
_fname, _fmax, _dict )
#define T1_FIELD_CALLBACK( _ident, _name, _dict ) \
T1_NEW_CALLBACK_FIELD( _ident, _name, _dict )
/*************************************************************************/
/*************************************************************************/
/***** *****/
/***** T1 PARSER *****/
/***** *****/
/*************************************************************************/
/*************************************************************************/
typedef const struct PS_Parser_FuncsRec_* PS_Parser_Funcs;
typedef struct PS_Parser_FuncsRec_
{
void
(*init)( PS_Parser parser,
FT_Byte* base,
FT_Byte* limit,
FT_Memory memory );
void
(*done)( PS_Parser parser );
void
(*skip_spaces)( PS_Parser parser );
void
(*skip_PS_token)( PS_Parser parser );
FT_Long
(*to_int)( PS_Parser parser );
FT_Fixed
(*to_fixed)( PS_Parser parser,
FT_Int power_ten );
FT_Error
(*to_bytes)( PS_Parser parser,
FT_Byte* bytes,
FT_Offset max_bytes,
FT_Long* pnum_bytes,
FT_Bool delimiters );
FT_Int
(*to_coord_array)( PS_Parser parser,
FT_Int max_coords,
FT_Short* coords );
FT_Int
(*to_fixed_array)( PS_Parser parser,
FT_Int max_values,
FT_Fixed* values,
FT_Int power_ten );
void
(*to_token)( PS_Parser parser,
T1_Token token );
void
(*to_token_array)( PS_Parser parser,
T1_Token tokens,
FT_UInt max_tokens,
FT_Int* pnum_tokens );
FT_Error
(*load_field)( PS_Parser parser,
const T1_Field field,
void** objects,
FT_UInt max_objects,
FT_ULong* pflags );
FT_Error
(*load_field_table)( PS_Parser parser,
const T1_Field field,
void** objects,
FT_UInt max_objects,
FT_ULong* pflags );
} PS_Parser_FuncsRec;
/*************************************************************************/
/* */
/* <Struct> */
/* PS_ParserRec */
/* */
/* <Description> */
/* A PS_Parser is an object used to parse a Type 1 font very quickly. */
/* */
/* <Fields> */
/* cursor :: The current position in the text. */
/* */
/* base :: Start of the processed text. */
/* */
/* limit :: End of the processed text. */
/* */
/* error :: The last error returned. */
/* */
/* memory :: The object used for memory operations (alloc/realloc). */
/* */
/* funcs :: A table of functions for the parser. */
/* */
typedef struct PS_ParserRec_
{
FT_Byte* cursor;
FT_Byte* base;
FT_Byte* limit;
FT_Error error;
FT_Memory memory;
PS_Parser_FuncsRec funcs;
} PS_ParserRec;
/*************************************************************************/
/*************************************************************************/
/***** *****/
/***** T1 BUILDER *****/
/***** *****/
/*************************************************************************/
/*************************************************************************/
typedef struct T1_BuilderRec_* T1_Builder;
typedef FT_Error
(*T1_Builder_Check_Points_Func)( T1_Builder builder,
FT_Int count );
typedef void
(*T1_Builder_Add_Point_Func)( T1_Builder builder,
FT_Pos x,
FT_Pos y,
FT_Byte flag );
typedef FT_Error
(*T1_Builder_Add_Point1_Func)( T1_Builder builder,
FT_Pos x,
FT_Pos y );
typedef FT_Error
(*T1_Builder_Add_Contour_Func)( T1_Builder builder );
typedef FT_Error
(*T1_Builder_Start_Point_Func)( T1_Builder builder,
FT_Pos x,
FT_Pos y );
typedef void
(*T1_Builder_Close_Contour_Func)( T1_Builder builder );
typedef const struct T1_Builder_FuncsRec_* T1_Builder_Funcs;
typedef struct T1_Builder_FuncsRec_
{
void
(*init)( T1_Builder builder,
FT_Face face,
FT_Size size,
FT_GlyphSlot slot,
FT_Bool hinting );
void
(*done)( T1_Builder builder );
T1_Builder_Check_Points_Func check_points;
T1_Builder_Add_Point_Func add_point;
T1_Builder_Add_Point1_Func add_point1;
T1_Builder_Add_Contour_Func add_contour;
T1_Builder_Start_Point_Func start_point;
T1_Builder_Close_Contour_Func close_contour;
} T1_Builder_FuncsRec;
/* an enumeration type to handle charstring parsing states */
typedef enum T1_ParseState_
{
T1_Parse_Start,
T1_Parse_Have_Width,
T1_Parse_Have_Moveto,
T1_Parse_Have_Path
} T1_ParseState;
/*************************************************************************/
/* */
/* <Structure> */
/* T1_BuilderRec */
/* */
/* <Description> */
/* A structure used during glyph loading to store its outline. */
/* */
/* <Fields> */
/* memory :: The current memory object. */
/* */
/* face :: The current face object. */
/* */
/* glyph :: The current glyph slot. */
/* */
/* loader :: XXX */
/* */
/* base :: The base glyph outline. */
/* */
/* current :: The current glyph outline. */
/* */
/* max_points :: maximum points in builder outline */
/* */
/* max_contours :: Maximum number of contours in builder outline. */
/* */
/* pos_x :: The horizontal translation (if composite glyph). */
/* */
/* pos_y :: The vertical translation (if composite glyph). */
/* */
/* left_bearing :: The left side bearing point. */
/* */
/* advance :: The horizontal advance vector. */
/* */
/* bbox :: Unused. */
/* */
/* parse_state :: An enumeration which controls the charstring */
/* parsing state. */
/* */
/* load_points :: If this flag is not set, no points are loaded. */
/* */
/* no_recurse :: Set but not used. */
/* */
/* metrics_only :: A boolean indicating that we only want to compute */
/* the metrics of a given glyph, not load all of its */
/* points. */
/* */
/* funcs :: An array of function pointers for the builder. */
/* */
typedef struct T1_BuilderRec_
{
FT_Memory memory;
FT_Face face;
FT_GlyphSlot glyph;
FT_GlyphLoader loader;
FT_Outline* base;
FT_Outline* current;
FT_Pos pos_x;
FT_Pos pos_y;
FT_Vector left_bearing;
FT_Vector advance;
FT_BBox bbox; /* bounding box */
T1_ParseState parse_state;
FT_Bool load_points;
FT_Bool no_recurse;
FT_Bool metrics_only;
void* hints_funcs; /* hinter-specific */
void* hints_globals; /* hinter-specific */
T1_Builder_FuncsRec funcs;
} T1_BuilderRec;
/*************************************************************************/
/*************************************************************************/
/***** *****/
/***** T1 DECODER *****/
/***** *****/
/*************************************************************************/
/*************************************************************************/
#if 0
/*************************************************************************/
/* */
/* T1_MAX_SUBRS_CALLS details the maximum number of nested sub-routine */
/* calls during glyph loading. */
/* */
#define T1_MAX_SUBRS_CALLS 8
/*************************************************************************/
/* */
/* T1_MAX_CHARSTRING_OPERANDS is the charstring stack's capacity. A */
/* minimum of 16 is required. */
/* */
#define T1_MAX_CHARSTRINGS_OPERANDS 32
#endif /* 0 */
typedef struct T1_Decoder_ZoneRec_
{
FT_Byte* cursor;
FT_Byte* base;
FT_Byte* limit;
} T1_Decoder_ZoneRec, *T1_Decoder_Zone;
typedef struct T1_DecoderRec_* T1_Decoder;
typedef const struct T1_Decoder_FuncsRec_* T1_Decoder_Funcs;
typedef FT_Error
(*T1_Decoder_Callback)( T1_Decoder decoder,
FT_UInt glyph_index );
typedef struct T1_Decoder_FuncsRec_
{
FT_Error
(*init)( T1_Decoder decoder,
FT_Face face,
FT_Size size,
FT_GlyphSlot slot,
FT_Byte** glyph_names,
PS_Blend blend,
FT_Bool hinting,
FT_Render_Mode hint_mode,
T1_Decoder_Callback callback );
void
(*done)( T1_Decoder decoder );
FT_Error
(*parse_charstrings)( T1_Decoder decoder,
FT_Byte* base,
FT_UInt len );
} T1_Decoder_FuncsRec;
typedef struct T1_DecoderRec_
{
T1_BuilderRec builder;
FT_Long stack[T1_MAX_CHARSTRINGS_OPERANDS];
FT_Long* top;
T1_Decoder_ZoneRec zones[T1_MAX_SUBRS_CALLS + 1];
T1_Decoder_Zone zone;
FT_Service_PsCMaps psnames; /* for seac */
FT_UInt num_glyphs;
FT_Byte** glyph_names;
FT_Int lenIV; /* internal for sub routine calls */
FT_UInt num_subrs;
FT_Byte** subrs;
FT_PtrDist* subrs_len; /* array of subrs length (optional) */
FT_Matrix font_matrix;
FT_Vector font_offset;
FT_Int flex_state;
FT_Int num_flex_vectors;
FT_Vector flex_vectors[7];
PS_Blend blend; /* for multiple master support */
FT_Render_Mode hint_mode;
T1_Decoder_Callback parse_callback;
T1_Decoder_FuncsRec funcs;
FT_Long* buildchar;
FT_UInt len_buildchar;
FT_Bool seac;
} T1_DecoderRec;
/*************************************************************************/
/*************************************************************************/
/***** *****/
/***** AFM PARSER *****/
/***** *****/
/*************************************************************************/
/*************************************************************************/
typedef struct AFM_ParserRec_* AFM_Parser;
typedef struct AFM_Parser_FuncsRec_
{
FT_Error
(*init)( AFM_Parser parser,
FT_Memory memory,
FT_Byte* base,
FT_Byte* limit );
void
(*done)( AFM_Parser parser );
FT_Error
(*parse)( AFM_Parser parser );
} AFM_Parser_FuncsRec;
typedef struct AFM_StreamRec_* AFM_Stream;
/*************************************************************************/
/* */
/* <Struct> */
/* AFM_ParserRec */
/* */
/* <Description> */
/* An AFM_Parser is a parser for the AFM files. */
/* */
/* <Fields> */
/* memory :: The object used for memory operations (alloc and */
/* realloc). */
/* */
/* stream :: This is an opaque object. */
/* */
/* FontInfo :: The result will be stored here. */
/* */
/* get_index :: A user provided function to get a glyph index by its */
/* name. */
/* */
typedef struct AFM_ParserRec_
{
FT_Memory memory;
AFM_Stream stream;
AFM_FontInfo FontInfo;
FT_Int
(*get_index)( const char* name,
FT_Offset len,
void* user_data );
void* user_data;
} AFM_ParserRec;
/*************************************************************************/
/*************************************************************************/
/***** *****/
/***** TYPE1 CHARMAPS *****/
/***** *****/
/*************************************************************************/
/*************************************************************************/
typedef const struct T1_CMap_ClassesRec_* T1_CMap_Classes;
typedef struct T1_CMap_ClassesRec_
{
FT_CMap_Class standard;
FT_CMap_Class expert;
FT_CMap_Class custom;
FT_CMap_Class unicode;
} T1_CMap_ClassesRec;
/*************************************************************************/
/*************************************************************************/
/***** *****/
/***** PSAux Module Interface *****/
/***** *****/
/*************************************************************************/
/*************************************************************************/
typedef struct PSAux_ServiceRec_
{
/* don't use `PS_Table_Funcs' and friends to avoid compiler warnings */
const PS_Table_FuncsRec* ps_table_funcs;
const PS_Parser_FuncsRec* ps_parser_funcs;
const T1_Builder_FuncsRec* t1_builder_funcs;
const T1_Decoder_FuncsRec* t1_decoder_funcs;
void
(*t1_decrypt)( FT_Byte* buffer,
FT_Offset length,
FT_UShort seed );
T1_CMap_Classes t1_cmap_classes;
/* fields after this comment line were added after version 2.1.10 */
const AFM_Parser_FuncsRec* afm_parser_funcs;
} PSAux_ServiceRec, *PSAux_Service;
/* backwards-compatible type definition */
typedef PSAux_ServiceRec PSAux_Interface;
/*************************************************************************/
/*************************************************************************/
/***** *****/
/***** Some convenience functions *****/
/***** *****/
/*************************************************************************/
/*************************************************************************/
#define IS_PS_NEWLINE( ch ) \
( (ch) == '\r' || \
(ch) == '\n' )
#define IS_PS_SPACE( ch ) \
( (ch) == ' ' || \
IS_PS_NEWLINE( ch ) || \
(ch) == '\t' || \
(ch) == '\f' || \
(ch) == '\0' )
#define IS_PS_SPECIAL( ch ) \
( (ch) == '/' || \
(ch) == '(' || (ch) == ')' || \
(ch) == '<' || (ch) == '>' || \
(ch) == '[' || (ch) == ']' || \
(ch) == '{' || (ch) == '}' || \
(ch) == '%' )
#define IS_PS_DELIM( ch ) \
( IS_PS_SPACE( ch ) || \
IS_PS_SPECIAL( ch ) )
#define IS_PS_DIGIT( ch ) \
( (ch) >= '0' && (ch) <= '9' )
#define IS_PS_XDIGIT( ch ) \
( IS_PS_DIGIT( ch ) || \
( (ch) >= 'A' && (ch) <= 'F' ) || \
( (ch) >= 'a' && (ch) <= 'f' ) )
#define IS_PS_BASE85( ch ) \
( (ch) >= '!' && (ch) <= 'u' )
#define IS_PS_TOKEN( cur, limit, token ) \
( (char)(cur)[0] == (token)[0] && \
( (cur) + sizeof ( (token) ) == (limit) || \
( (cur) + sizeof( (token) ) < (limit) && \
IS_PS_DELIM( (cur)[sizeof ( (token) ) - 1] ) ) ) && \
ft_strncmp( (char*)(cur), (token), sizeof ( (token) ) - 1 ) == 0 )
FT_END_HEADER
#endif /* __PSAUX_H__ */
/* END */
| YifuLiu/AliOS-Things | components/freetype/include/internal/psaux.h | C | apache-2.0 | 36,206 |
/***************************************************************************/
/* */
/* pshints.h */
/* */
/* Interface to Postscript-specific (Type 1 and Type 2) hints */
/* recorders (specification only). These are used to support native */
/* T1/T2 hints in the `type1', `cid', and `cff' font drivers. */
/* */
/* Copyright 2001-2003, 2005-2007, 2009, 2012 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. */
/* */
/***************************************************************************/
#ifndef __PSHINTS_H__
#define __PSHINTS_H__
#include <ft2build.h>
#include FT_FREETYPE_H
#include FT_TYPE1_TABLES_H
FT_BEGIN_HEADER
/*************************************************************************/
/*************************************************************************/
/***** *****/
/***** INTERNAL REPRESENTATION OF GLOBALS *****/
/***** *****/
/*************************************************************************/
/*************************************************************************/
typedef struct PSH_GlobalsRec_* PSH_Globals;
typedef FT_Error
(*PSH_Globals_NewFunc)( FT_Memory memory,
T1_Private* private_dict,
PSH_Globals* aglobals );
typedef FT_Error
(*PSH_Globals_SetScaleFunc)( PSH_Globals globals,
FT_Fixed x_scale,
FT_Fixed y_scale,
FT_Fixed x_delta,
FT_Fixed y_delta );
typedef void
(*PSH_Globals_DestroyFunc)( PSH_Globals globals );
typedef struct PSH_Globals_FuncsRec_
{
PSH_Globals_NewFunc create;
PSH_Globals_SetScaleFunc set_scale;
PSH_Globals_DestroyFunc destroy;
} PSH_Globals_FuncsRec, *PSH_Globals_Funcs;
/*************************************************************************/
/*************************************************************************/
/***** *****/
/***** PUBLIC TYPE 1 HINTS RECORDER *****/
/***** *****/
/*************************************************************************/
/*************************************************************************/
/*************************************************************************
*
* @type:
* T1_Hints
*
* @description:
* This is a handle to an opaque structure used to record glyph hints
* from a Type 1 character glyph character string.
*
* The methods used to operate on this object are defined by the
* @T1_Hints_FuncsRec structure. Recording glyph hints is normally
* achieved through the following scheme:
*
* - Open a new hint recording session by calling the `open' method.
* This rewinds the recorder and prepare it for new input.
*
* - For each hint found in the glyph charstring, call the corresponding
* method (`stem', `stem3', or `reset'). Note that these functions do
* not return an error code.
*
* - Close the recording session by calling the `close' method. It
* returns an error code if the hints were invalid or something
* strange happened (e.g., memory shortage).
*
* The hints accumulated in the object can later be used by the
* PostScript hinter.
*
*/
typedef struct T1_HintsRec_* T1_Hints;
/*************************************************************************
*
* @type:
* T1_Hints_Funcs
*
* @description:
* A pointer to the @T1_Hints_FuncsRec structure that defines the API of
* a given @T1_Hints object.
*
*/
typedef const struct T1_Hints_FuncsRec_* T1_Hints_Funcs;
/*************************************************************************
*
* @functype:
* T1_Hints_OpenFunc
*
* @description:
* A method of the @T1_Hints class used to prepare it for a new Type 1
* hints recording session.
*
* @input:
* hints ::
* A handle to the Type 1 hints recorder.
*
* @note:
* You should always call the @T1_Hints_CloseFunc method in order to
* close an opened recording session.
*
*/
typedef void
(*T1_Hints_OpenFunc)( T1_Hints hints );
/*************************************************************************
*
* @functype:
* T1_Hints_SetStemFunc
*
* @description:
* A method of the @T1_Hints class used to record a new horizontal or
* vertical stem. This corresponds to the Type 1 `hstem' and `vstem'
* operators.
*
* @input:
* hints ::
* A handle to the Type 1 hints recorder.
*
* dimension ::
* 0 for horizontal stems (hstem), 1 for vertical ones (vstem).
*
* coords ::
* Array of 2 coordinates in 16.16 format, used as (position,length)
* stem descriptor.
*
* @note:
* Use vertical coordinates (y) for horizontal stems (dim=0). Use
* horizontal coordinates (x) for vertical stems (dim=1).
*
* `coords[0]' is the absolute stem position (lowest coordinate);
* `coords[1]' is the length.
*
* The length can be negative, in which case it must be either -20 or
* -21. It is interpreted as a `ghost' stem, according to the Type 1
* specification.
*
* If the length is -21 (corresponding to a bottom ghost stem), then
* the real stem position is `coords[0]+coords[1]'.
*
*/
typedef void
(*T1_Hints_SetStemFunc)( T1_Hints hints,
FT_UInt dimension,
FT_Fixed* coords );
/*************************************************************************
*
* @functype:
* T1_Hints_SetStem3Func
*
* @description:
* A method of the @T1_Hints class used to record three
* counter-controlled horizontal or vertical stems at once.
*
* @input:
* hints ::
* A handle to the Type 1 hints recorder.
*
* dimension ::
* 0 for horizontal stems, 1 for vertical ones.
*
* coords ::
* An array of 6 values in 16.16 format, holding 3 (position,length)
* pairs for the counter-controlled stems.
*
* @note:
* Use vertical coordinates (y) for horizontal stems (dim=0). Use
* horizontal coordinates (x) for vertical stems (dim=1).
*
* The lengths cannot be negative (ghost stems are never
* counter-controlled).
*
*/
typedef void
(*T1_Hints_SetStem3Func)( T1_Hints hints,
FT_UInt dimension,
FT_Fixed* coords );
/*************************************************************************
*
* @functype:
* T1_Hints_ResetFunc
*
* @description:
* A method of the @T1_Hints class used to reset the stems hints in a
* recording session.
*
* @input:
* hints ::
* A handle to the Type 1 hints recorder.
*
* end_point ::
* The index of the last point in the input glyph in which the
* previously defined hints apply.
*
*/
typedef void
(*T1_Hints_ResetFunc)( T1_Hints hints,
FT_UInt end_point );
/*************************************************************************
*
* @functype:
* T1_Hints_CloseFunc
*
* @description:
* A method of the @T1_Hints class used to close a hint recording
* session.
*
* @input:
* hints ::
* A handle to the Type 1 hints recorder.
*
* end_point ::
* The index of the last point in the input glyph.
*
* @return:
* FreeType error code. 0 means success.
*
* @note:
* The error code is set to indicate that an error occurred during the
* recording session.
*
*/
typedef FT_Error
(*T1_Hints_CloseFunc)( T1_Hints hints,
FT_UInt end_point );
/*************************************************************************
*
* @functype:
* T1_Hints_ApplyFunc
*
* @description:
* A method of the @T1_Hints class used to apply hints to the
* corresponding glyph outline. Must be called once all hints have been
* recorded.
*
* @input:
* hints ::
* A handle to the Type 1 hints recorder.
*
* outline ::
* A pointer to the target outline descriptor.
*
* globals ::
* The hinter globals for this font.
*
* hint_mode ::
* Hinting information.
*
* @return:
* FreeType error code. 0 means success.
*
* @note:
* On input, all points within the outline are in font coordinates. On
* output, they are in 1/64th of pixels.
*
* The scaling transformation is taken from the `globals' object which
* must correspond to the same font as the glyph.
*
*/
typedef FT_Error
(*T1_Hints_ApplyFunc)( T1_Hints hints,
FT_Outline* outline,
PSH_Globals globals,
FT_Render_Mode hint_mode );
/*************************************************************************
*
* @struct:
* T1_Hints_FuncsRec
*
* @description:
* The structure used to provide the API to @T1_Hints objects.
*
* @fields:
* hints ::
* A handle to the T1 Hints recorder.
*
* open ::
* The function to open a recording session.
*
* close ::
* The function to close a recording session.
*
* stem ::
* The function to set a simple stem.
*
* stem3 ::
* The function to set counter-controlled stems.
*
* reset ::
* The function to reset stem hints.
*
* apply ::
* The function to apply the hints to the corresponding glyph outline.
*
*/
typedef struct T1_Hints_FuncsRec_
{
T1_Hints hints;
T1_Hints_OpenFunc open;
T1_Hints_CloseFunc close;
T1_Hints_SetStemFunc stem;
T1_Hints_SetStem3Func stem3;
T1_Hints_ResetFunc reset;
T1_Hints_ApplyFunc apply;
} T1_Hints_FuncsRec;
/*************************************************************************/
/*************************************************************************/
/***** *****/
/***** PUBLIC TYPE 2 HINTS RECORDER *****/
/***** *****/
/*************************************************************************/
/*************************************************************************/
/*************************************************************************
*
* @type:
* T2_Hints
*
* @description:
* This is a handle to an opaque structure used to record glyph hints
* from a Type 2 character glyph character string.
*
* The methods used to operate on this object are defined by the
* @T2_Hints_FuncsRec structure. Recording glyph hints is normally
* achieved through the following scheme:
*
* - Open a new hint recording session by calling the `open' method.
* This rewinds the recorder and prepare it for new input.
*
* - For each hint found in the glyph charstring, call the corresponding
* method (`stems', `hintmask', `counters'). Note that these
* functions do not return an error code.
*
* - Close the recording session by calling the `close' method. It
* returns an error code if the hints were invalid or something
* strange happened (e.g., memory shortage).
*
* The hints accumulated in the object can later be used by the
* Postscript hinter.
*
*/
typedef struct T2_HintsRec_* T2_Hints;
/*************************************************************************
*
* @type:
* T2_Hints_Funcs
*
* @description:
* A pointer to the @T2_Hints_FuncsRec structure that defines the API of
* a given @T2_Hints object.
*
*/
typedef const struct T2_Hints_FuncsRec_* T2_Hints_Funcs;
/*************************************************************************
*
* @functype:
* T2_Hints_OpenFunc
*
* @description:
* A method of the @T2_Hints class used to prepare it for a new Type 2
* hints recording session.
*
* @input:
* hints ::
* A handle to the Type 2 hints recorder.
*
* @note:
* You should always call the @T2_Hints_CloseFunc method in order to
* close an opened recording session.
*
*/
typedef void
(*T2_Hints_OpenFunc)( T2_Hints hints );
/*************************************************************************
*
* @functype:
* T2_Hints_StemsFunc
*
* @description:
* A method of the @T2_Hints class used to set the table of stems in
* either the vertical or horizontal dimension. Equivalent to the
* `hstem', `vstem', `hstemhm', and `vstemhm' Type 2 operators.
*
* @input:
* hints ::
* A handle to the Type 2 hints recorder.
*
* dimension ::
* 0 for horizontal stems (hstem), 1 for vertical ones (vstem).
*
* count ::
* The number of stems.
*
* coords ::
* An array of `count' (position,length) pairs in 16.16 format.
*
* @note:
* Use vertical coordinates (y) for horizontal stems (dim=0). Use
* horizontal coordinates (x) for vertical stems (dim=1).
*
* There are `2*count' elements in the `coords' array. Each even
* element is an absolute position in font units, each odd element is a
* length in font units.
*
* A length can be negative, in which case it must be either -20 or
* -21. It is interpreted as a `ghost' stem, according to the Type 1
* specification.
*
*/
typedef void
(*T2_Hints_StemsFunc)( T2_Hints hints,
FT_UInt dimension,
FT_UInt count,
FT_Fixed* coordinates );
/*************************************************************************
*
* @functype:
* T2_Hints_MaskFunc
*
* @description:
* A method of the @T2_Hints class used to set a given hintmask (this
* corresponds to the `hintmask' Type 2 operator).
*
* @input:
* hints ::
* A handle to the Type 2 hints recorder.
*
* end_point ::
* The glyph index of the last point to which the previously defined
* or activated hints apply.
*
* bit_count ::
* The number of bits in the hint mask.
*
* bytes ::
* An array of bytes modelling the hint mask.
*
* @note:
* If the hintmask starts the charstring (before any glyph point
* definition), the value of `end_point' should be 0.
*
* `bit_count' is the number of meaningful bits in the `bytes' array; it
* must be equal to the total number of hints defined so far (i.e.,
* horizontal+verticals).
*
* The `bytes' array can come directly from the Type 2 charstring and
* respects the same format.
*
*/
typedef void
(*T2_Hints_MaskFunc)( T2_Hints hints,
FT_UInt end_point,
FT_UInt bit_count,
const FT_Byte* bytes );
/*************************************************************************
*
* @functype:
* T2_Hints_CounterFunc
*
* @description:
* A method of the @T2_Hints class used to set a given counter mask
* (this corresponds to the `hintmask' Type 2 operator).
*
* @input:
* hints ::
* A handle to the Type 2 hints recorder.
*
* end_point ::
* A glyph index of the last point to which the previously defined or
* active hints apply.
*
* bit_count ::
* The number of bits in the hint mask.
*
* bytes ::
* An array of bytes modelling the hint mask.
*
* @note:
* If the hintmask starts the charstring (before any glyph point
* definition), the value of `end_point' should be 0.
*
* `bit_count' is the number of meaningful bits in the `bytes' array; it
* must be equal to the total number of hints defined so far (i.e.,
* horizontal+verticals).
*
* The `bytes' array can come directly from the Type 2 charstring and
* respects the same format.
*
*/
typedef void
(*T2_Hints_CounterFunc)( T2_Hints hints,
FT_UInt bit_count,
const FT_Byte* bytes );
/*************************************************************************
*
* @functype:
* T2_Hints_CloseFunc
*
* @description:
* A method of the @T2_Hints class used to close a hint recording
* session.
*
* @input:
* hints ::
* A handle to the Type 2 hints recorder.
*
* end_point ::
* The index of the last point in the input glyph.
*
* @return:
* FreeType error code. 0 means success.
*
* @note:
* The error code is set to indicate that an error occurred during the
* recording session.
*
*/
typedef FT_Error
(*T2_Hints_CloseFunc)( T2_Hints hints,
FT_UInt end_point );
/*************************************************************************
*
* @functype:
* T2_Hints_ApplyFunc
*
* @description:
* A method of the @T2_Hints class used to apply hints to the
* corresponding glyph outline. Must be called after the `close'
* method.
*
* @input:
* hints ::
* A handle to the Type 2 hints recorder.
*
* outline ::
* A pointer to the target outline descriptor.
*
* globals ::
* The hinter globals for this font.
*
* hint_mode ::
* Hinting information.
*
* @return:
* FreeType error code. 0 means success.
*
* @note:
* On input, all points within the outline are in font coordinates. On
* output, they are in 1/64th of pixels.
*
* The scaling transformation is taken from the `globals' object which
* must correspond to the same font than the glyph.
*
*/
typedef FT_Error
(*T2_Hints_ApplyFunc)( T2_Hints hints,
FT_Outline* outline,
PSH_Globals globals,
FT_Render_Mode hint_mode );
/*************************************************************************
*
* @struct:
* T2_Hints_FuncsRec
*
* @description:
* The structure used to provide the API to @T2_Hints objects.
*
* @fields:
* hints ::
* A handle to the T2 hints recorder object.
*
* open ::
* The function to open a recording session.
*
* close ::
* The function to close a recording session.
*
* stems ::
* The function to set the dimension's stems table.
*
* hintmask ::
* The function to set hint masks.
*
* counter ::
* The function to set counter masks.
*
* apply ::
* The function to apply the hints on the corresponding glyph outline.
*
*/
typedef struct T2_Hints_FuncsRec_
{
T2_Hints hints;
T2_Hints_OpenFunc open;
T2_Hints_CloseFunc close;
T2_Hints_StemsFunc stems;
T2_Hints_MaskFunc hintmask;
T2_Hints_CounterFunc counter;
T2_Hints_ApplyFunc apply;
} T2_Hints_FuncsRec;
/* */
typedef struct PSHinter_Interface_
{
PSH_Globals_Funcs (*get_globals_funcs)( FT_Module module );
T1_Hints_Funcs (*get_t1_funcs) ( FT_Module module );
T2_Hints_Funcs (*get_t2_funcs) ( FT_Module module );
} PSHinter_Interface;
typedef PSHinter_Interface* PSHinter_Service;
#ifndef FT_CONFIG_OPTION_PIC
#define FT_DEFINE_PSHINTER_INTERFACE( \
class_, \
get_globals_funcs_, \
get_t1_funcs_, \
get_t2_funcs_ ) \
static const PSHinter_Interface class_ = \
{ \
get_globals_funcs_, \
get_t1_funcs_, \
get_t2_funcs_ \
};
#else /* FT_CONFIG_OPTION_PIC */
#define FT_DEFINE_PSHINTER_INTERFACE( \
class_, \
get_globals_funcs_, \
get_t1_funcs_, \
get_t2_funcs_ ) \
void \
FT_Init_Class_ ## class_( FT_Library library, \
PSHinter_Interface* clazz ) \
{ \
FT_UNUSED( library ); \
\
clazz->get_globals_funcs = get_globals_funcs_; \
clazz->get_t1_funcs = get_t1_funcs_; \
clazz->get_t2_funcs = get_t2_funcs_; \
}
#endif /* FT_CONFIG_OPTION_PIC */
FT_END_HEADER
#endif /* __PSHINTS_H__ */
/* END */
| YifuLiu/AliOS-Things | components/freetype/include/internal/pshints.h | C | apache-2.0 | 22,535 |
/***************************************************************************/
/* */
/* svbdf.h */
/* */
/* The FreeType BDF services (specification). */
/* */
/* Copyright 2003, 2009, 2012 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. */
/* */
/***************************************************************************/
#ifndef __SVBDF_H__
#define __SVBDF_H__
#include FT_BDF_H
#include FT_INTERNAL_SERVICE_H
FT_BEGIN_HEADER
#define FT_SERVICE_ID_BDF "bdf"
typedef FT_Error
(*FT_BDF_GetCharsetIdFunc)( FT_Face face,
const char* *acharset_encoding,
const char* *acharset_registry );
typedef FT_Error
(*FT_BDF_GetPropertyFunc)( FT_Face face,
const char* prop_name,
BDF_PropertyRec *aproperty );
FT_DEFINE_SERVICE( BDF )
{
FT_BDF_GetCharsetIdFunc get_charset_id;
FT_BDF_GetPropertyFunc get_property;
};
#ifndef FT_CONFIG_OPTION_PIC
#define FT_DEFINE_SERVICE_BDFRec( class_, \
get_charset_id_, \
get_property_ ) \
static const FT_Service_BDFRec class_ = \
{ \
get_charset_id_, get_property_ \
};
#else /* FT_CONFIG_OPTION_PIC */
#define FT_DEFINE_SERVICE_BDFRec( class_, \
get_charset_id_, \
get_property_ ) \
void \
FT_Init_Class_ ## class_( FT_Service_BDFRec* clazz ) \
{ \
clazz->get_charset_id = get_charset_id_; \
clazz->get_property = get_property_; \
}
#endif /* FT_CONFIG_OPTION_PIC */
/* */
FT_END_HEADER
#endif /* __SVBDF_H__ */
/* END */
| YifuLiu/AliOS-Things | components/freetype/include/internal/services/svbdf.h | C | apache-2.0 | 3,133 |
/***************************************************************************/
/* */
/* svcid.h */
/* */
/* The FreeType CID font services (specification). */
/* */
/* Copyright 2007, 2009, 2012 by Derek Clegg, Michael Toftdal. */
/* */
/* 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. */
/* */
/***************************************************************************/
#ifndef __SVCID_H__
#define __SVCID_H__
#include FT_INTERNAL_SERVICE_H
FT_BEGIN_HEADER
#define FT_SERVICE_ID_CID "CID"
typedef FT_Error
(*FT_CID_GetRegistryOrderingSupplementFunc)( FT_Face face,
const char* *registry,
const char* *ordering,
FT_Int *supplement );
typedef FT_Error
(*FT_CID_GetIsInternallyCIDKeyedFunc)( FT_Face face,
FT_Bool *is_cid );
typedef FT_Error
(*FT_CID_GetCIDFromGlyphIndexFunc)( FT_Face face,
FT_UInt glyph_index,
FT_UInt *cid );
FT_DEFINE_SERVICE( CID )
{
FT_CID_GetRegistryOrderingSupplementFunc get_ros;
FT_CID_GetIsInternallyCIDKeyedFunc get_is_cid;
FT_CID_GetCIDFromGlyphIndexFunc get_cid_from_glyph_index;
};
#ifndef FT_CONFIG_OPTION_PIC
#define FT_DEFINE_SERVICE_CIDREC( class_, \
get_ros_, \
get_is_cid_, \
get_cid_from_glyph_index_ ) \
static const FT_Service_CIDRec class_ = \
{ \
get_ros_, get_is_cid_, get_cid_from_glyph_index_ \
};
#else /* FT_CONFIG_OPTION_PIC */
#define FT_DEFINE_SERVICE_CIDREC( class_, \
get_ros_, \
get_is_cid_, \
get_cid_from_glyph_index_ ) \
void \
FT_Init_Class_ ## class_( FT_Library library, \
FT_Service_CIDRec* clazz ) \
{ \
FT_UNUSED( library ); \
\
clazz->get_ros = get_ros_; \
clazz->get_is_cid = get_is_cid_; \
clazz->get_cid_from_glyph_index = get_cid_from_glyph_index_; \
}
#endif /* FT_CONFIG_OPTION_PIC */
/* */
FT_END_HEADER
#endif /* __SVCID_H__ */
/* END */
| YifuLiu/AliOS-Things | components/freetype/include/internal/services/svcid.h | C | apache-2.0 | 3,884 |
/***************************************************************************/
/* */
/* svgldict.h */
/* */
/* The FreeType glyph dictionary services (specification). */
/* */
/* Copyright 2003, 2009, 2012 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. */
/* */
/***************************************************************************/
#ifndef __SVGLDICT_H__
#define __SVGLDICT_H__
#include FT_INTERNAL_SERVICE_H
FT_BEGIN_HEADER
/*
* A service used to retrieve glyph names, as well as to find the
* index of a given glyph name in a font.
*
*/
#define FT_SERVICE_ID_GLYPH_DICT "glyph-dict"
typedef FT_Error
(*FT_GlyphDict_GetNameFunc)( FT_Face face,
FT_UInt glyph_index,
FT_Pointer buffer,
FT_UInt buffer_max );
typedef FT_UInt
(*FT_GlyphDict_NameIndexFunc)( FT_Face face,
FT_String* glyph_name );
FT_DEFINE_SERVICE( GlyphDict )
{
FT_GlyphDict_GetNameFunc get_name;
FT_GlyphDict_NameIndexFunc name_index; /* optional */
};
#ifndef FT_CONFIG_OPTION_PIC
#define FT_DEFINE_SERVICE_GLYPHDICTREC( class_, \
get_name_, \
name_index_) \
static const FT_Service_GlyphDictRec class_ = \
{ \
get_name_, name_index_ \
};
#else /* FT_CONFIG_OPTION_PIC */
#define FT_DEFINE_SERVICE_GLYPHDICTREC( class_, \
get_name_, \
name_index_) \
void \
FT_Init_Class_ ## class_( FT_Library library, \
FT_Service_GlyphDictRec* clazz ) \
{ \
FT_UNUSED( library ); \
\
clazz->get_name = get_name_; \
clazz->name_index = name_index_; \
}
#endif /* FT_CONFIG_OPTION_PIC */
/* */
FT_END_HEADER
#endif /* __SVGLDICT_H__ */
| YifuLiu/AliOS-Things | components/freetype/include/internal/services/svgldict.h | C | apache-2.0 | 3,442 |
/***************************************************************************/
/* */
/* svgxval.h */
/* */
/* FreeType API for validating TrueTypeGX/AAT tables (specification). */
/* */
/* Copyright 2004, 2005 by */
/* Masatake YAMATO, Red Hat K.K., */
/* 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. */
/* */
/***************************************************************************/
/***************************************************************************/
/* */
/* gxvalid is derived from both gxlayout module and otvalid module. */
/* Development of gxlayout is supported by the Information-technology */
/* Promotion Agency(IPA), Japan. */
/* */
/***************************************************************************/
#ifndef __SVGXVAL_H__
#define __SVGXVAL_H__
#include FT_GX_VALIDATE_H
#include FT_INTERNAL_VALIDATE_H
FT_BEGIN_HEADER
#define FT_SERVICE_ID_GX_VALIDATE "truetypegx-validate"
#define FT_SERVICE_ID_CLASSICKERN_VALIDATE "classickern-validate"
typedef FT_Error
(*gxv_validate_func)( FT_Face face,
FT_UInt gx_flags,
FT_Bytes tables[FT_VALIDATE_GX_LENGTH],
FT_UInt table_length );
typedef FT_Error
(*ckern_validate_func)( FT_Face face,
FT_UInt ckern_flags,
FT_Bytes *ckern_table );
FT_DEFINE_SERVICE( GXvalidate )
{
gxv_validate_func validate;
};
FT_DEFINE_SERVICE( CKERNvalidate )
{
ckern_validate_func validate;
};
/* */
FT_END_HEADER
#endif /* __SVGXVAL_H__ */
/* END */
| YifuLiu/AliOS-Things | components/freetype/include/internal/services/svgxval.h | C | apache-2.0 | 2,739 |
/***************************************************************************/
/* */
/* svkern.h */
/* */
/* The FreeType Kerning service (specification). */
/* */
/* Copyright 2006 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. */
/* */
/***************************************************************************/
#ifndef __SVKERN_H__
#define __SVKERN_H__
#include FT_INTERNAL_SERVICE_H
#include FT_TRUETYPE_TABLES_H
FT_BEGIN_HEADER
#define FT_SERVICE_ID_KERNING "kerning"
typedef FT_Error
(*FT_Kerning_TrackGetFunc)( FT_Face face,
FT_Fixed point_size,
FT_Int degree,
FT_Fixed* akerning );
FT_DEFINE_SERVICE( Kerning )
{
FT_Kerning_TrackGetFunc get_track;
};
/* */
FT_END_HEADER
#endif /* __SVKERN_H__ */
/* END */
| YifuLiu/AliOS-Things | components/freetype/include/internal/services/svkern.h | C | apache-2.0 | 1,783 |
/***************************************************************************/
/* */
/* svmm.h */
/* */
/* The FreeType Multiple Masters and GX var services (specification). */
/* */
/* Copyright 2003, 2004, 2009, 2012 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. */
/* */
/***************************************************************************/
#ifndef __SVMM_H__
#define __SVMM_H__
#include FT_INTERNAL_SERVICE_H
FT_BEGIN_HEADER
/*
* A service used to manage multiple-masters data in a given face.
*
* See the related APIs in `ftmm.h' (FT_MULTIPLE_MASTERS_H).
*
*/
#define FT_SERVICE_ID_MULTI_MASTERS "multi-masters"
typedef FT_Error
(*FT_Get_MM_Func)( FT_Face face,
FT_Multi_Master* master );
typedef FT_Error
(*FT_Get_MM_Var_Func)( FT_Face face,
FT_MM_Var* *master );
typedef FT_Error
(*FT_Set_MM_Design_Func)( FT_Face face,
FT_UInt num_coords,
FT_Long* coords );
typedef FT_Error
(*FT_Set_Var_Design_Func)( FT_Face face,
FT_UInt num_coords,
FT_Fixed* coords );
typedef FT_Error
(*FT_Set_MM_Blend_Func)( FT_Face face,
FT_UInt num_coords,
FT_Long* coords );
FT_DEFINE_SERVICE( MultiMasters )
{
FT_Get_MM_Func get_mm;
FT_Set_MM_Design_Func set_mm_design;
FT_Set_MM_Blend_Func set_mm_blend;
FT_Get_MM_Var_Func get_mm_var;
FT_Set_Var_Design_Func set_var_design;
};
#ifndef FT_CONFIG_OPTION_PIC
#define FT_DEFINE_SERVICE_MULTIMASTERSREC( class_, \
get_mm_, \
set_mm_design_, \
set_mm_blend_, \
get_mm_var_, \
set_var_design_ ) \
static const FT_Service_MultiMastersRec class_ = \
{ \
get_mm_, set_mm_design_, set_mm_blend_, get_mm_var_, set_var_design_ \
};
#else /* FT_CONFIG_OPTION_PIC */
#define FT_DEFINE_SERVICE_MULTIMASTERSREC( class_, \
get_mm_, \
set_mm_design_, \
set_mm_blend_, \
get_mm_var_, \
set_var_design_ ) \
void \
FT_Init_Class_ ## class_( FT_Service_MultiMastersRec* clazz ) \
{ \
clazz->get_mm = get_mm_; \
clazz->set_mm_design = set_mm_design_; \
clazz->set_mm_blend = set_mm_blend_; \
clazz->get_mm_var = get_mm_var_; \
clazz->set_var_design = set_var_design_; \
}
#endif /* FT_CONFIG_OPTION_PIC */
/* */
FT_END_HEADER
#endif /* __SVMM_H__ */
/* END */
| YifuLiu/AliOS-Things | components/freetype/include/internal/services/svmm.h | C | apache-2.0 | 4,484 |
/***************************************************************************/
/* */
/* svotval.h */
/* */
/* The FreeType OpenType validation service (specification). */
/* */
/* Copyright 2004, 2006 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. */
/* */
/***************************************************************************/
#ifndef __SVOTVAL_H__
#define __SVOTVAL_H__
#include FT_OPENTYPE_VALIDATE_H
#include FT_INTERNAL_VALIDATE_H
FT_BEGIN_HEADER
#define FT_SERVICE_ID_OPENTYPE_VALIDATE "opentype-validate"
typedef FT_Error
(*otv_validate_func)( FT_Face volatile face,
FT_UInt ot_flags,
FT_Bytes *base,
FT_Bytes *gdef,
FT_Bytes *gpos,
FT_Bytes *gsub,
FT_Bytes *jstf );
FT_DEFINE_SERVICE( OTvalidate )
{
otv_validate_func validate;
};
/* */
FT_END_HEADER
#endif /* __SVOTVAL_H__ */
/* END */
| YifuLiu/AliOS-Things | components/freetype/include/internal/services/svotval.h | C | apache-2.0 | 1,946 |
/***************************************************************************/
/* */
/* svpfr.h */
/* */
/* Internal PFR service functions (specification). */
/* */
/* Copyright 2003, 2006 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. */
/* */
/***************************************************************************/
#ifndef __SVPFR_H__
#define __SVPFR_H__
#include FT_PFR_H
#include FT_INTERNAL_SERVICE_H
FT_BEGIN_HEADER
#define FT_SERVICE_ID_PFR_METRICS "pfr-metrics"
typedef FT_Error
(*FT_PFR_GetMetricsFunc)( FT_Face face,
FT_UInt *aoutline,
FT_UInt *ametrics,
FT_Fixed *ax_scale,
FT_Fixed *ay_scale );
typedef FT_Error
(*FT_PFR_GetKerningFunc)( FT_Face face,
FT_UInt left,
FT_UInt right,
FT_Vector *avector );
typedef FT_Error
(*FT_PFR_GetAdvanceFunc)( FT_Face face,
FT_UInt gindex,
FT_Pos *aadvance );
FT_DEFINE_SERVICE( PfrMetrics )
{
FT_PFR_GetMetricsFunc get_metrics;
FT_PFR_GetKerningFunc get_kerning;
FT_PFR_GetAdvanceFunc get_advance;
};
/* */
FT_END_HEADER
#endif /* __SVPFR_H__ */
/* END */
| YifuLiu/AliOS-Things | components/freetype/include/internal/services/svpfr.h | C | apache-2.0 | 2,270 |
/***************************************************************************/
/* */
/* svpostnm.h */
/* */
/* The FreeType PostScript name services (specification). */
/* */
/* Copyright 2003, 2007, 2009, 2012 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. */
/* */
/***************************************************************************/
#ifndef __SVPOSTNM_H__
#define __SVPOSTNM_H__
#include FT_INTERNAL_SERVICE_H
FT_BEGIN_HEADER
/*
* A trivial service used to retrieve the PostScript name of a given
* font when available. The `get_name' field should never be NULL.
*
* The corresponding function can return NULL to indicate that the
* PostScript name is not available.
*
* The name is owned by the face and will be destroyed with it.
*/
#define FT_SERVICE_ID_POSTSCRIPT_FONT_NAME "postscript-font-name"
typedef const char*
(*FT_PsName_GetFunc)( FT_Face face );
FT_DEFINE_SERVICE( PsFontName )
{
FT_PsName_GetFunc get_ps_font_name;
};
#ifndef FT_CONFIG_OPTION_PIC
#define FT_DEFINE_SERVICE_PSFONTNAMEREC( class_, get_ps_font_name_ ) \
static const FT_Service_PsFontNameRec class_ = \
{ \
get_ps_font_name_ \
};
#else /* FT_CONFIG_OPTION_PIC */
#define FT_DEFINE_SERVICE_PSFONTNAMEREC( class_, get_ps_font_name_ ) \
void \
FT_Init_Class_ ## class_( FT_Library library, \
FT_Service_PsFontNameRec* clazz ) \
{ \
FT_UNUSED( library ); \
\
clazz->get_ps_font_name = get_ps_font_name_; \
}
#endif /* FT_CONFIG_OPTION_PIC */
/* */
FT_END_HEADER
#endif /* __SVPOSTNM_H__ */
/* END */
| YifuLiu/AliOS-Things | components/freetype/include/internal/services/svpostnm.h | C | apache-2.0 | 2,937 |
/***************************************************************************/
/* */
/* svprop.h */
/* */
/* The FreeType property service (specification). */
/* */
/* Copyright 2012 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. */
/* */
/***************************************************************************/
#ifndef __SVPROP_H__
#define __SVPROP_H__
FT_BEGIN_HEADER
#define FT_SERVICE_ID_PROPERTIES "properties"
typedef FT_Error
(*FT_Properties_SetFunc)( FT_Module module,
const char* property_name,
const void* value );
typedef FT_Error
(*FT_Properties_GetFunc)( FT_Module module,
const char* property_name,
void* value );
FT_DEFINE_SERVICE( Properties )
{
FT_Properties_SetFunc set_property;
FT_Properties_GetFunc get_property;
};
#ifndef FT_CONFIG_OPTION_PIC
#define FT_DEFINE_SERVICE_PROPERTIESREC( class_, \
set_property_, \
get_property_ ) \
static const FT_Service_PropertiesRec class_ = \
{ \
set_property_, \
get_property_ \
};
#else /* FT_CONFIG_OPTION_PIC */
#define FT_DEFINE_SERVICE_PROPERTIESREC( class_, \
set_property_, \
get_property_ ) \
void \
FT_Init_Class_ ## class_( FT_Service_PropertiesRec* clazz ) \
{ \
clazz->set_property = set_property_; \
clazz->get_property = get_property_; \
}
#endif /* FT_CONFIG_OPTION_PIC */
/* */
FT_END_HEADER
#endif /* __SVPROP_H__ */
/* END */
| YifuLiu/AliOS-Things | components/freetype/include/internal/services/svprop.h | C | apache-2.0 | 2,961 |
/***************************************************************************/
/* */
/* svpscmap.h */
/* */
/* The FreeType PostScript charmap service (specification). */
/* */
/* Copyright 2003, 2006, 2009, 2012 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. */
/* */
/***************************************************************************/
#ifndef __SVPSCMAP_H__
#define __SVPSCMAP_H__
#include FT_INTERNAL_OBJECTS_H
FT_BEGIN_HEADER
#define FT_SERVICE_ID_POSTSCRIPT_CMAPS "postscript-cmaps"
/*
* Adobe glyph name to unicode value.
*/
typedef FT_UInt32
(*PS_Unicode_ValueFunc)( const char* glyph_name );
/*
* Macintosh name id to glyph name. NULL if invalid index.
*/
typedef const char*
(*PS_Macintosh_NameFunc)( FT_UInt name_index );
/*
* Adobe standard string ID to glyph name. NULL if invalid index.
*/
typedef const char*
(*PS_Adobe_Std_StringsFunc)( FT_UInt string_index );
/*
* Simple unicode -> glyph index charmap built from font glyph names
* table.
*/
typedef struct PS_UniMap_
{
FT_UInt32 unicode; /* bit 31 set: is glyph variant */
FT_UInt glyph_index;
} PS_UniMap;
typedef struct PS_UnicodesRec_* PS_Unicodes;
typedef struct PS_UnicodesRec_
{
FT_CMapRec cmap;
FT_UInt num_maps;
PS_UniMap* maps;
} PS_UnicodesRec;
/*
* A function which returns a glyph name for a given index. Returns
* NULL if invalid index.
*/
typedef const char*
(*PS_GetGlyphNameFunc)( FT_Pointer data,
FT_UInt string_index );
/*
* A function used to release the glyph name returned by
* PS_GetGlyphNameFunc, when needed
*/
typedef void
(*PS_FreeGlyphNameFunc)( FT_Pointer data,
const char* name );
typedef FT_Error
(*PS_Unicodes_InitFunc)( FT_Memory memory,
PS_Unicodes unicodes,
FT_UInt num_glyphs,
PS_GetGlyphNameFunc get_glyph_name,
PS_FreeGlyphNameFunc free_glyph_name,
FT_Pointer glyph_data );
typedef FT_UInt
(*PS_Unicodes_CharIndexFunc)( PS_Unicodes unicodes,
FT_UInt32 unicode );
typedef FT_UInt32
(*PS_Unicodes_CharNextFunc)( PS_Unicodes unicodes,
FT_UInt32 *unicode );
FT_DEFINE_SERVICE( PsCMaps )
{
PS_Unicode_ValueFunc unicode_value;
PS_Unicodes_InitFunc unicodes_init;
PS_Unicodes_CharIndexFunc unicodes_char_index;
PS_Unicodes_CharNextFunc unicodes_char_next;
PS_Macintosh_NameFunc macintosh_name;
PS_Adobe_Std_StringsFunc adobe_std_strings;
const unsigned short* adobe_std_encoding;
const unsigned short* adobe_expert_encoding;
};
#ifndef FT_CONFIG_OPTION_PIC
#define FT_DEFINE_SERVICE_PSCMAPSREC( class_, \
unicode_value_, \
unicodes_init_, \
unicodes_char_index_, \
unicodes_char_next_, \
macintosh_name_, \
adobe_std_strings_, \
adobe_std_encoding_, \
adobe_expert_encoding_ ) \
static const FT_Service_PsCMapsRec class_ = \
{ \
unicode_value_, unicodes_init_, \
unicodes_char_index_, unicodes_char_next_, macintosh_name_, \
adobe_std_strings_, adobe_std_encoding_, adobe_expert_encoding_ \
};
#else /* FT_CONFIG_OPTION_PIC */
#define FT_DEFINE_SERVICE_PSCMAPSREC( class_, \
unicode_value_, \
unicodes_init_, \
unicodes_char_index_, \
unicodes_char_next_, \
macintosh_name_, \
adobe_std_strings_, \
adobe_std_encoding_, \
adobe_expert_encoding_ ) \
void \
FT_Init_Class_ ## class_( FT_Library library, \
FT_Service_PsCMapsRec* clazz ) \
{ \
FT_UNUSED( library ); \
\
clazz->unicode_value = unicode_value_; \
clazz->unicodes_init = unicodes_init_; \
clazz->unicodes_char_index = unicodes_char_index_; \
clazz->unicodes_char_next = unicodes_char_next_; \
clazz->macintosh_name = macintosh_name_; \
clazz->adobe_std_strings = adobe_std_strings_; \
clazz->adobe_std_encoding = adobe_std_encoding_; \
clazz->adobe_expert_encoding = adobe_expert_encoding_; \
}
#endif /* FT_CONFIG_OPTION_PIC */
/* */
FT_END_HEADER
#endif /* __SVPSCMAP_H__ */
/* END */
| YifuLiu/AliOS-Things | components/freetype/include/internal/services/svpscmap.h | C | apache-2.0 | 6,871 |
/***************************************************************************/
/* */
/* svpsinfo.h */
/* */
/* The FreeType PostScript info service (specification). */
/* */
/* Copyright 2003, 2004, 2009, 2011, 2012 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. */
/* */
/***************************************************************************/
#ifndef __SVPSINFO_H__
#define __SVPSINFO_H__
#include FT_INTERNAL_SERVICE_H
#include FT_INTERNAL_TYPE1_TYPES_H
FT_BEGIN_HEADER
#define FT_SERVICE_ID_POSTSCRIPT_INFO "postscript-info"
typedef FT_Error
(*PS_GetFontInfoFunc)( FT_Face face,
PS_FontInfoRec* afont_info );
typedef FT_Error
(*PS_GetFontExtraFunc)( FT_Face face,
PS_FontExtraRec* afont_extra );
typedef FT_Int
(*PS_HasGlyphNamesFunc)( FT_Face face );
typedef FT_Error
(*PS_GetFontPrivateFunc)( FT_Face face,
PS_PrivateRec* afont_private );
typedef FT_Long
(*PS_GetFontValueFunc)( FT_Face face,
PS_Dict_Keys key,
FT_UInt idx,
void *value,
FT_Long value_len );
FT_DEFINE_SERVICE( PsInfo )
{
PS_GetFontInfoFunc ps_get_font_info;
PS_GetFontExtraFunc ps_get_font_extra;
PS_HasGlyphNamesFunc ps_has_glyph_names;
PS_GetFontPrivateFunc ps_get_font_private;
PS_GetFontValueFunc ps_get_font_value;
};
#ifndef FT_CONFIG_OPTION_PIC
#define FT_DEFINE_SERVICE_PSINFOREC( class_, \
get_font_info_, \
ps_get_font_extra_, \
has_glyph_names_, \
get_font_private_, \
get_font_value_ ) \
static const FT_Service_PsInfoRec class_ = \
{ \
get_font_info_, ps_get_font_extra_, has_glyph_names_, \
get_font_private_, get_font_value_ \
};
#else /* FT_CONFIG_OPTION_PIC */
#define FT_DEFINE_SERVICE_PSINFOREC( class_, \
get_font_info_, \
ps_get_font_extra_, \
has_glyph_names_, \
get_font_private_, \
get_font_value_ ) \
void \
FT_Init_Class_ ## class_( FT_Library library, \
FT_Service_PsInfoRec* clazz ) \
{ \
FT_UNUSED( library ); \
\
clazz->ps_get_font_info = get_font_info_; \
clazz->ps_get_font_extra = ps_get_font_extra_; \
clazz->ps_has_glyph_names = has_glyph_names_; \
clazz->ps_get_font_private = get_font_private_; \
clazz->ps_get_font_value = get_font_value_; \
}
#endif /* FT_CONFIG_OPTION_PIC */
/* */
FT_END_HEADER
#endif /* __SVPSINFO_H__ */
/* END */
| YifuLiu/AliOS-Things | components/freetype/include/internal/services/svpsinfo.h | C | apache-2.0 | 4,402 |
/***************************************************************************/
/* */
/* svsfnt.h */
/* */
/* The FreeType SFNT table loading service (specification). */
/* */
/* Copyright 2003, 2004, 2009, 2012 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. */
/* */
/***************************************************************************/
#ifndef __SVSFNT_H__
#define __SVSFNT_H__
#include FT_INTERNAL_SERVICE_H
#include FT_TRUETYPE_TABLES_H
FT_BEGIN_HEADER
/*
* SFNT table loading service.
*/
#define FT_SERVICE_ID_SFNT_TABLE "sfnt-table"
/*
* Used to implement FT_Load_Sfnt_Table().
*/
typedef FT_Error
(*FT_SFNT_TableLoadFunc)( FT_Face face,
FT_ULong tag,
FT_Long offset,
FT_Byte* buffer,
FT_ULong* length );
/*
* Used to implement FT_Get_Sfnt_Table().
*/
typedef void*
(*FT_SFNT_TableGetFunc)( FT_Face face,
FT_Sfnt_Tag tag );
/*
* Used to implement FT_Sfnt_Table_Info().
*/
typedef FT_Error
(*FT_SFNT_TableInfoFunc)( FT_Face face,
FT_UInt idx,
FT_ULong *tag,
FT_ULong *offset,
FT_ULong *length );
FT_DEFINE_SERVICE( SFNT_Table )
{
FT_SFNT_TableLoadFunc load_table;
FT_SFNT_TableGetFunc get_table;
FT_SFNT_TableInfoFunc table_info;
};
#ifndef FT_CONFIG_OPTION_PIC
#define FT_DEFINE_SERVICE_SFNT_TABLEREC( class_, load_, get_, info_ ) \
static const FT_Service_SFNT_TableRec class_ = \
{ \
load_, get_, info_ \
};
#else /* FT_CONFIG_OPTION_PIC */
#define FT_DEFINE_SERVICE_SFNT_TABLEREC( class_, load_, get_, info_ ) \
void \
FT_Init_Class_ ## class_( FT_Service_SFNT_TableRec* clazz ) \
{ \
clazz->load_table = load_; \
clazz->get_table = get_; \
clazz->table_info = info_; \
}
#endif /* FT_CONFIG_OPTION_PIC */
/* */
FT_END_HEADER
#endif /* __SVSFNT_H__ */
/* END */
| YifuLiu/AliOS-Things | components/freetype/include/internal/services/svsfnt.h | C | apache-2.0 | 3,380 |
/***************************************************************************/
/* */
/* svttcmap.h */
/* */
/* The FreeType TrueType/sfnt cmap extra information service. */
/* */
/* Copyright 2003 by */
/* Masatake YAMATO, Redhat K.K. */
/* */
/* Copyright 2003, 2008, 2009, 2012, 2013 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. */
/* */
/***************************************************************************/
/* Development of this service is support of
Information-technology Promotion Agency, Japan. */
#ifndef __SVTTCMAP_H__
#define __SVTTCMAP_H__
#include FT_INTERNAL_SERVICE_H
#include FT_TRUETYPE_TABLES_H
FT_BEGIN_HEADER
#define FT_SERVICE_ID_TT_CMAP "tt-cmaps"
/*************************************************************************/
/* */
/* <Struct> */
/* TT_CMapInfo */
/* */
/* <Description> */
/* A structure used to store TrueType/sfnt specific cmap information */
/* which is not covered by the generic @FT_CharMap structure. This */
/* structure can be accessed with the @FT_Get_TT_CMap_Info function. */
/* */
/* <Fields> */
/* language :: */
/* The language ID used in Mac fonts. Definitions of values are in */
/* `ttnameid.h'. */
/* */
/* format :: */
/* The cmap format. OpenType 1.5 defines the formats 0 (byte */
/* encoding table), 2~(high-byte mapping through table), 4~(segment */
/* mapping to delta values), 6~(trimmed table mapping), 8~(mixed */
/* 16-bit and 32-bit coverage), 10~(trimmed array), 12~(segmented */
/* coverage), and 14 (Unicode Variation Sequences). */
/* */
typedef struct TT_CMapInfo_
{
FT_ULong language;
FT_Long format;
} TT_CMapInfo;
typedef FT_Error
(*TT_CMap_Info_GetFunc)( FT_CharMap charmap,
TT_CMapInfo *cmap_info );
FT_DEFINE_SERVICE( TTCMaps )
{
TT_CMap_Info_GetFunc get_cmap_info;
};
#ifndef FT_CONFIG_OPTION_PIC
#define FT_DEFINE_SERVICE_TTCMAPSREC( class_, get_cmap_info_ ) \
static const FT_Service_TTCMapsRec class_ = \
{ \
get_cmap_info_ \
};
#else /* FT_CONFIG_OPTION_PIC */
#define FT_DEFINE_SERVICE_TTCMAPSREC( class_, get_cmap_info_ ) \
void \
FT_Init_Class_ ## class_( FT_Library library, \
FT_Service_TTCMapsRec* clazz ) \
{ \
FT_UNUSED( library ); \
\
clazz->get_cmap_info = get_cmap_info_; \
}
#endif /* FT_CONFIG_OPTION_PIC */
/* */
FT_END_HEADER
#endif /* __SVTTCMAP_H__ */
/* END */
| YifuLiu/AliOS-Things | components/freetype/include/internal/services/svttcmap.h | C | apache-2.0 | 4,746 |
/***************************************************************************/
/* */
/* svtteng.h */
/* */
/* The FreeType TrueType engine query service (specification). */
/* */
/* Copyright 2006 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. */
/* */
/***************************************************************************/
#ifndef __SVTTENG_H__
#define __SVTTENG_H__
#include FT_INTERNAL_SERVICE_H
#include FT_MODULE_H
FT_BEGIN_HEADER
/*
* SFNT table loading service.
*/
#define FT_SERVICE_ID_TRUETYPE_ENGINE "truetype-engine"
/*
* Used to implement FT_Get_TrueType_Engine_Type
*/
FT_DEFINE_SERVICE( TrueTypeEngine )
{
FT_TrueTypeEngineType engine_type;
};
/* */
FT_END_HEADER
#endif /* __SVTTENG_H__ */
/* END */
| YifuLiu/AliOS-Things | components/freetype/include/internal/services/svtteng.h | C | apache-2.0 | 1,687 |
/***************************************************************************/
/* */
/* svttglyf.h */
/* */
/* The FreeType TrueType glyph service. */
/* */
/* Copyright 2007, 2009, 2012 by David Turner. */
/* */
/* 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. */
/* */
/***************************************************************************/
#ifndef __SVTTGLYF_H__
#define __SVTTGLYF_H__
#include FT_INTERNAL_SERVICE_H
#include FT_TRUETYPE_TABLES_H
FT_BEGIN_HEADER
#define FT_SERVICE_ID_TT_GLYF "tt-glyf"
typedef FT_ULong
(*TT_Glyf_GetLocationFunc)( FT_Face face,
FT_UInt gindex,
FT_ULong *psize );
FT_DEFINE_SERVICE( TTGlyf )
{
TT_Glyf_GetLocationFunc get_location;
};
#ifndef FT_CONFIG_OPTION_PIC
#define FT_DEFINE_SERVICE_TTGLYFREC( class_, get_location_ ) \
static const FT_Service_TTGlyfRec class_ = \
{ \
get_location_ \
};
#else /* FT_CONFIG_OPTION_PIC */
#define FT_DEFINE_SERVICE_TTGLYFREC( class_, get_location_ ) \
void \
FT_Init_Class_ ## class_( FT_Service_TTGlyfRec* clazz ) \
{ \
clazz->get_location = get_location_; \
}
#endif /* FT_CONFIG_OPTION_PIC */
/* */
FT_END_HEADER
#endif /* __SVTTGLYF_H__ */
/* END */
| YifuLiu/AliOS-Things | components/freetype/include/internal/services/svttglyf.h | C | apache-2.0 | 2,343 |
/***************************************************************************/
/* */
/* svwinfnt.h */
/* */
/* The FreeType Windows FNT/FONT service (specification). */
/* */
/* Copyright 2003 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. */
/* */
/***************************************************************************/
#ifndef __SVWINFNT_H__
#define __SVWINFNT_H__
#include FT_INTERNAL_SERVICE_H
#include FT_WINFONTS_H
FT_BEGIN_HEADER
#define FT_SERVICE_ID_WINFNT "winfonts"
typedef FT_Error
(*FT_WinFnt_GetHeaderFunc)( FT_Face face,
FT_WinFNT_HeaderRec *aheader );
FT_DEFINE_SERVICE( WinFnt )
{
FT_WinFnt_GetHeaderFunc get_header;
};
/* */
FT_END_HEADER
#endif /* __SVWINFNT_H__ */
/* END */
| YifuLiu/AliOS-Things | components/freetype/include/internal/services/svwinfnt.h | C | apache-2.0 | 1,702 |
/***************************************************************************/
/* */
/* svxf86nm.h */
/* */
/* The FreeType XFree86 services (specification only). */
/* */
/* Copyright 2003 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. */
/* */
/***************************************************************************/
#ifndef __SVXF86NM_H__
#define __SVXF86NM_H__
#include FT_INTERNAL_SERVICE_H
FT_BEGIN_HEADER
/*
* A trivial service used to return the name of a face's font driver,
* according to the XFree86 nomenclature. Note that the service data
* is a simple constant string pointer.
*/
#define FT_SERVICE_ID_XF86_NAME "xf86-driver-name"
#define FT_XF86_FORMAT_TRUETYPE "TrueType"
#define FT_XF86_FORMAT_TYPE_1 "Type 1"
#define FT_XF86_FORMAT_BDF "BDF"
#define FT_XF86_FORMAT_PCF "PCF"
#define FT_XF86_FORMAT_TYPE_42 "Type 42"
#define FT_XF86_FORMAT_CID "CID Type 1"
#define FT_XF86_FORMAT_CFF "CFF"
#define FT_XF86_FORMAT_PFR "PFR"
#define FT_XF86_FORMAT_WINFNT "Windows FNT"
/* */
FT_END_HEADER
#endif /* __SVXF86NM_H__ */
/* END */
| YifuLiu/AliOS-Things | components/freetype/include/internal/services/svxf86nm.h | C | apache-2.0 | 2,047 |
/***************************************************************************/
/* */
/* sfnt.h */
/* */
/* High-level `sfnt' driver interface (specification). */
/* */
/* Copyright 1996-2006, 2009, 2012-2013 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. */
/* */
/***************************************************************************/
#ifndef __SFNT_H__
#define __SFNT_H__
#include <ft2build.h>
#include FT_INTERNAL_DRIVER_H
#include FT_INTERNAL_TRUETYPE_TYPES_H
FT_BEGIN_HEADER
/*************************************************************************/
/* */
/* <FuncType> */
/* TT_Init_Face_Func */
/* */
/* <Description> */
/* First part of the SFNT face object initialization. This finds */
/* the face in a SFNT file or collection, and load its format tag in */
/* face->format_tag. */
/* */
/* <Input> */
/* stream :: The input stream. */
/* */
/* face :: A handle to the target face object. */
/* */
/* face_index :: The index of the TrueType font, if we are opening a */
/* collection. */
/* */
/* num_params :: The number of additional parameters. */
/* */
/* params :: Optional additional parameters. */
/* */
/* <Return> */
/* FreeType error code. 0 means success. */
/* */
/* <Note> */
/* The stream cursor must be at the font file's origin. */
/* */
/* This function recognizes fonts embedded in a `TrueType */
/* collection'. */
/* */
/* Once the format tag has been validated by the font driver, it */
/* should then call the TT_Load_Face_Func() callback to read the rest */
/* of the SFNT tables in the object. */
/* */
typedef FT_Error
(*TT_Init_Face_Func)( FT_Stream stream,
TT_Face face,
FT_Int face_index,
FT_Int num_params,
FT_Parameter* params );
/*************************************************************************/
/* */
/* <FuncType> */
/* TT_Load_Face_Func */
/* */
/* <Description> */
/* Second part of the SFNT face object initialization. This loads */
/* the common SFNT tables (head, OS/2, maxp, metrics, etc.) in the */
/* face object. */
/* */
/* <Input> */
/* stream :: The input stream. */
/* */
/* face :: A handle to the target face object. */
/* */
/* face_index :: The index of the TrueType font, if we are opening a */
/* collection. */
/* */
/* num_params :: The number of additional parameters. */
/* */
/* params :: Optional additional parameters. */
/* */
/* <Return> */
/* FreeType error code. 0 means success. */
/* */
/* <Note> */
/* This function must be called after TT_Init_Face_Func(). */
/* */
typedef FT_Error
(*TT_Load_Face_Func)( FT_Stream stream,
TT_Face face,
FT_Int face_index,
FT_Int num_params,
FT_Parameter* params );
/*************************************************************************/
/* */
/* <FuncType> */
/* TT_Done_Face_Func */
/* */
/* <Description> */
/* A callback used to delete the common SFNT data from a face. */
/* */
/* <Input> */
/* face :: A handle to the target face object. */
/* */
/* <Note> */
/* This function does NOT destroy the face object. */
/* */
typedef void
(*TT_Done_Face_Func)( TT_Face face );
/*************************************************************************/
/* */
/* <FuncType> */
/* TT_Load_Any_Func */
/* */
/* <Description> */
/* Load any font table into client memory. */
/* */
/* <Input> */
/* face :: The face object to look for. */
/* */
/* tag :: The tag of table to load. Use the value 0 if you want */
/* to access the whole font file, else set this parameter */
/* to a valid TrueType table tag that you can forge with */
/* the MAKE_TT_TAG macro. */
/* */
/* offset :: The starting offset in the table (or the file if */
/* tag == 0). */
/* */
/* length :: The address of the decision variable: */
/* */
/* If length == NULL: */
/* Loads the whole table. Returns an error if */
/* `offset' == 0! */
/* */
/* If *length == 0: */
/* Exits immediately; returning the length of the given */
/* table or of the font file, depending on the value of */
/* `tag'. */
/* */
/* If *length != 0: */
/* Loads the next `length' bytes of table or font, */
/* starting at offset `offset' (in table or font too). */
/* */
/* <Output> */
/* buffer :: The address of target buffer. */
/* */
/* <Return> */
/* TrueType error code. 0 means success. */
/* */
typedef FT_Error
(*TT_Load_Any_Func)( TT_Face face,
FT_ULong tag,
FT_Long offset,
FT_Byte *buffer,
FT_ULong* length );
/*************************************************************************/
/* */
/* <FuncType> */
/* TT_Find_SBit_Image_Func */
/* */
/* <Description> */
/* Check whether an embedded bitmap (an `sbit') exists for a given */
/* glyph, at a given strike. */
/* */
/* <Input> */
/* face :: The target face object. */
/* */
/* glyph_index :: The glyph index. */
/* */
/* strike_index :: The current strike index. */
/* */
/* <Output> */
/* arange :: The SBit range containing the glyph index. */
/* */
/* astrike :: The SBit strike containing the glyph index. */
/* */
/* aglyph_offset :: The offset of the glyph data in `EBDT' table. */
/* */
/* <Return> */
/* FreeType error code. 0 means success. Returns */
/* SFNT_Err_Invalid_Argument if no sbit exists for the requested */
/* glyph. */
/* */
typedef FT_Error
(*TT_Find_SBit_Image_Func)( TT_Face face,
FT_UInt glyph_index,
FT_ULong strike_index,
TT_SBit_Range *arange,
TT_SBit_Strike *astrike,
FT_ULong *aglyph_offset );
/*************************************************************************/
/* */
/* <FuncType> */
/* TT_Load_SBit_Metrics_Func */
/* */
/* <Description> */
/* Get the big metrics for a given embedded bitmap. */
/* */
/* <Input> */
/* stream :: The input stream. */
/* */
/* range :: The SBit range containing the glyph. */
/* */
/* <Output> */
/* big_metrics :: A big SBit metrics structure for the glyph. */
/* */
/* <Return> */
/* FreeType error code. 0 means success. */
/* */
/* <Note> */
/* The stream cursor must be positioned at the glyph's offset within */
/* the `EBDT' table before the call. */
/* */
/* If the image format uses variable metrics, the stream cursor is */
/* positioned just after the metrics header in the `EBDT' table on */
/* function exit. */
/* */
typedef FT_Error
(*TT_Load_SBit_Metrics_Func)( FT_Stream stream,
TT_SBit_Range range,
TT_SBit_Metrics metrics );
/*************************************************************************/
/* */
/* <FuncType> */
/* TT_Load_SBit_Image_Func */
/* */
/* <Description> */
/* Load a given glyph sbit image from the font resource. This also */
/* returns its metrics. */
/* */
/* <Input> */
/* face :: */
/* The target face object. */
/* */
/* strike_index :: */
/* The strike index. */
/* */
/* glyph_index :: */
/* The current glyph index. */
/* */
/* load_flags :: */
/* The current load flags. */
/* */
/* stream :: */
/* The input stream. */
/* */
/* <Output> */
/* amap :: */
/* The target pixmap. */
/* */
/* ametrics :: */
/* A big sbit metrics structure for the glyph image. */
/* */
/* <Return> */
/* FreeType error code. 0 means success. Returns an error if no */
/* glyph sbit exists for the index. */
/* */
/* <Note> */
/* The `map.buffer' field is always freed before the glyph is loaded. */
/* */
typedef FT_Error
(*TT_Load_SBit_Image_Func)( TT_Face face,
FT_ULong strike_index,
FT_UInt glyph_index,
FT_UInt load_flags,
FT_Stream stream,
FT_Bitmap *amap,
TT_SBit_MetricsRec *ametrics );
/*************************************************************************/
/* */
/* <FuncType> */
/* TT_Set_SBit_Strike_Func */
/* */
/* <Description> */
/* Select an sbit strike for a given size request. */
/* */
/* <Input> */
/* face :: The target face object. */
/* */
/* req :: The size request. */
/* */
/* <Output> */
/* astrike_index :: The index of the sbit strike. */
/* */
/* <Return> */
/* FreeType error code. 0 means success. Returns an error if no */
/* sbit strike exists for the selected ppem values. */
/* */
typedef FT_Error
(*TT_Set_SBit_Strike_Func)( TT_Face face,
FT_Size_Request req,
FT_ULong* astrike_index );
/*************************************************************************/
/* */
/* <FuncType> */
/* TT_Load_Strike_Metrics_Func */
/* */
/* <Description> */
/* Load the metrics of a given strike. */
/* */
/* <Input> */
/* face :: The target face object. */
/* */
/* strike_index :: The strike index. */
/* */
/* <Output> */
/* metrics :: the metrics of the strike. */
/* */
/* <Return> */
/* FreeType error code. 0 means success. Returns an error if no */
/* such sbit strike exists. */
/* */
typedef FT_Error
(*TT_Load_Strike_Metrics_Func)( TT_Face face,
FT_ULong strike_index,
FT_Size_Metrics* metrics );
/*************************************************************************/
/* */
/* <FuncType> */
/* TT_Get_PS_Name_Func */
/* */
/* <Description> */
/* Get the PostScript glyph name of a glyph. */
/* */
/* <Input> */
/* idx :: The glyph index. */
/* */
/* PSname :: The address of a string pointer. Will be NULL in case */
/* of error, otherwise it is a pointer to the glyph name. */
/* */
/* You must not modify the returned string! */
/* */
/* <Output> */
/* FreeType error code. 0 means success. */
/* */
typedef FT_Error
(*TT_Get_PS_Name_Func)( TT_Face face,
FT_UInt idx,
FT_String** PSname );
/*************************************************************************/
/* */
/* <FuncType> */
/* TT_Load_Metrics_Func */
/* */
/* <Description> */
/* Load a metrics table, which is a table with a horizontal and a */
/* vertical version. */
/* */
/* <Input> */
/* face :: A handle to the target face object. */
/* */
/* stream :: The input stream. */
/* */
/* vertical :: A boolean flag. If set, load the vertical one. */
/* */
/* <Return> */
/* FreeType error code. 0 means success. */
/* */
typedef FT_Error
(*TT_Load_Metrics_Func)( TT_Face face,
FT_Stream stream,
FT_Bool vertical );
/*************************************************************************/
/* */
/* <FuncType> */
/* TT_Get_Metrics_Func */
/* */
/* <Description> */
/* Load the horizontal or vertical header in a face object. */
/* */
/* <Input> */
/* face :: A handle to the target face object. */
/* */
/* stream :: The input stream. */
/* */
/* vertical :: A boolean flag. If set, load vertical metrics. */
/* */
/* <Return> */
/* FreeType error code. 0 means success. */
/* */
typedef FT_Error
(*TT_Get_Metrics_Func)( TT_Face face,
FT_Bool vertical,
FT_UInt gindex,
FT_Short* abearing,
FT_UShort* aadvance );
/*************************************************************************/
/* */
/* <FuncType> */
/* TT_Load_Table_Func */
/* */
/* <Description> */
/* Load a given TrueType table. */
/* */
/* <Input> */
/* face :: A handle to the target face object. */
/* */
/* stream :: The input stream. */
/* */
/* <Return> */
/* FreeType error code. 0 means success. */
/* */
/* <Note> */
/* The function uses `face->goto_table' to seek the stream to the */
/* start of the table, except while loading the font directory. */
/* */
typedef FT_Error
(*TT_Load_Table_Func)( TT_Face face,
FT_Stream stream );
/*************************************************************************/
/* */
/* <FuncType> */
/* TT_Free_Table_Func */
/* */
/* <Description> */
/* Free a given TrueType table. */
/* */
/* <Input> */
/* face :: A handle to the target face object. */
/* */
typedef void
(*TT_Free_Table_Func)( TT_Face face );
/*
* @functype:
* TT_Face_GetKerningFunc
*
* @description:
* Return the horizontal kerning value between two glyphs.
*
* @input:
* face :: A handle to the source face object.
* left_glyph :: The left glyph index.
* right_glyph :: The right glyph index.
*
* @return:
* The kerning value in font units.
*/
typedef FT_Int
(*TT_Face_GetKerningFunc)( TT_Face face,
FT_UInt left_glyph,
FT_UInt right_glyph );
/*************************************************************************/
/* */
/* <Struct> */
/* SFNT_Interface */
/* */
/* <Description> */
/* This structure holds pointers to the functions used to load and */
/* free the basic tables that are required in a `sfnt' font file. */
/* */
/* <Fields> */
/* Check the various xxx_Func() descriptions for details. */
/* */
typedef struct SFNT_Interface_
{
TT_Loader_GotoTableFunc goto_table;
TT_Init_Face_Func init_face;
TT_Load_Face_Func load_face;
TT_Done_Face_Func done_face;
FT_Module_Requester get_interface;
TT_Load_Any_Func load_any;
/* these functions are called by `load_face' but they can also */
/* be called from external modules, if there is a need to do so */
TT_Load_Table_Func load_head;
TT_Load_Metrics_Func load_hhea;
TT_Load_Table_Func load_cmap;
TT_Load_Table_Func load_maxp;
TT_Load_Table_Func load_os2;
TT_Load_Table_Func load_post;
TT_Load_Table_Func load_name;
TT_Free_Table_Func free_name;
/* this field was called `load_kerning' up to version 2.1.10 */
TT_Load_Table_Func load_kern;
TT_Load_Table_Func load_gasp;
TT_Load_Table_Func load_pclt;
/* see `ttload.h'; this field was called `load_bitmap_header' up to */
/* version 2.1.10 */
TT_Load_Table_Func load_bhed;
TT_Load_SBit_Image_Func load_sbit_image;
/* see `ttpost.h' */
TT_Get_PS_Name_Func get_psname;
TT_Free_Table_Func free_psnames;
/* starting here, the structure differs from version 2.1.7 */
/* this field was introduced in version 2.1.8, named `get_psname' */
TT_Face_GetKerningFunc get_kerning;
/* new elements introduced after version 2.1.10 */
/* load the font directory, i.e., the offset table and */
/* the table directory */
TT_Load_Table_Func load_font_dir;
TT_Load_Metrics_Func load_hmtx;
TT_Load_Table_Func load_eblc;
TT_Free_Table_Func free_eblc;
TT_Set_SBit_Strike_Func set_sbit_strike;
TT_Load_Strike_Metrics_Func load_strike_metrics;
TT_Get_Metrics_Func get_metrics;
} SFNT_Interface;
/* transitional */
typedef SFNT_Interface* SFNT_Service;
#ifndef FT_CONFIG_OPTION_PIC
#define FT_DEFINE_SFNT_INTERFACE( \
class_, \
goto_table_, \
init_face_, \
load_face_, \
done_face_, \
get_interface_, \
load_any_, \
load_head_, \
load_hhea_, \
load_cmap_, \
load_maxp_, \
load_os2_, \
load_post_, \
load_name_, \
free_name_, \
load_kern_, \
load_gasp_, \
load_pclt_, \
load_bhed_, \
load_sbit_image_, \
get_psname_, \
free_psnames_, \
get_kerning_, \
load_font_dir_, \
load_hmtx_, \
load_eblc_, \
free_eblc_, \
set_sbit_strike_, \
load_strike_metrics_, \
get_metrics_ ) \
static const SFNT_Interface class_ = \
{ \
goto_table_, \
init_face_, \
load_face_, \
done_face_, \
get_interface_, \
load_any_, \
load_head_, \
load_hhea_, \
load_cmap_, \
load_maxp_, \
load_os2_, \
load_post_, \
load_name_, \
free_name_, \
load_kern_, \
load_gasp_, \
load_pclt_, \
load_bhed_, \
load_sbit_image_, \
get_psname_, \
free_psnames_, \
get_kerning_, \
load_font_dir_, \
load_hmtx_, \
load_eblc_, \
free_eblc_, \
set_sbit_strike_, \
load_strike_metrics_, \
get_metrics_, \
};
#else /* FT_CONFIG_OPTION_PIC */
#define FT_INTERNAL( a, a_ ) \
clazz->a = a_;
#define FT_DEFINE_SFNT_INTERFACE( \
class_, \
goto_table_, \
init_face_, \
load_face_, \
done_face_, \
get_interface_, \
load_any_, \
load_head_, \
load_hhea_, \
load_cmap_, \
load_maxp_, \
load_os2_, \
load_post_, \
load_name_, \
free_name_, \
load_kern_, \
load_gasp_, \
load_pclt_, \
load_bhed_, \
load_sbit_image_, \
get_psname_, \
free_psnames_, \
get_kerning_, \
load_font_dir_, \
load_hmtx_, \
load_eblc_, \
free_eblc_, \
set_sbit_strike_, \
load_strike_metrics_, \
get_metrics_ ) \
void \
FT_Init_Class_ ## class_( FT_Library library, \
SFNT_Interface* clazz ) \
{ \
FT_UNUSED( library ); \
\
clazz->goto_table = goto_table_; \
clazz->init_face = init_face_; \
clazz->load_face = load_face_; \
clazz->done_face = done_face_; \
clazz->get_interface = get_interface_; \
clazz->load_any = load_any_; \
clazz->load_head = load_head_; \
clazz->load_hhea = load_hhea_; \
clazz->load_cmap = load_cmap_; \
clazz->load_maxp = load_maxp_; \
clazz->load_os2 = load_os2_; \
clazz->load_post = load_post_; \
clazz->load_name = load_name_; \
clazz->free_name = free_name_; \
clazz->load_kern = load_kern_; \
clazz->load_gasp = load_gasp_; \
clazz->load_pclt = load_pclt_; \
clazz->load_bhed = load_bhed_; \
clazz->load_sbit_image = load_sbit_image_; \
clazz->get_psname = get_psname_; \
clazz->free_psnames = free_psnames_; \
clazz->get_kerning = get_kerning_; \
clazz->load_font_dir = load_font_dir_; \
clazz->load_hmtx = load_hmtx_; \
clazz->load_eblc = load_eblc_; \
clazz->free_eblc = free_eblc_; \
clazz->set_sbit_strike = set_sbit_strike_; \
clazz->load_strike_metrics = load_strike_metrics_; \
clazz->get_metrics = get_metrics_; \
}
#endif /* FT_CONFIG_OPTION_PIC */
FT_END_HEADER
#endif /* __SFNT_H__ */
/* END */
| YifuLiu/AliOS-Things | components/freetype/include/internal/sfnt.h | C | apache-2.0 | 41,080 |
/***************************************************************************/
/* */
/* t1types.h */
/* */
/* Basic Type1/Type2 type definitions and interface (specification */
/* only). */
/* */
/* Copyright 1996-2004, 2006, 2008, 2009, 2011, 2013 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. */
/* */
/***************************************************************************/
#ifndef __T1TYPES_H__
#define __T1TYPES_H__
#include <ft2build.h>
#include FT_TYPE1_TABLES_H
#include FT_INTERNAL_POSTSCRIPT_HINTS_H
#include FT_INTERNAL_SERVICE_H
#include FT_SERVICE_POSTSCRIPT_CMAPS_H
FT_BEGIN_HEADER
/*************************************************************************/
/*************************************************************************/
/*************************************************************************/
/*** ***/
/*** ***/
/*** REQUIRED TYPE1/TYPE2 TABLES DEFINITIONS ***/
/*** ***/
/*** ***/
/*************************************************************************/
/*************************************************************************/
/*************************************************************************/
/*************************************************************************/
/* */
/* <Struct> */
/* T1_EncodingRec */
/* */
/* <Description> */
/* A structure modeling a custom encoding. */
/* */
/* <Fields> */
/* num_chars :: The number of character codes in the encoding. */
/* Usually 256. */
/* */
/* code_first :: The lowest valid character code in the encoding. */
/* */
/* code_last :: The highest valid character code in the encoding */
/* + 1. When equal to code_first there are no valid */
/* character codes. */
/* */
/* char_index :: An array of corresponding glyph indices. */
/* */
/* char_name :: An array of corresponding glyph names. */
/* */
typedef struct T1_EncodingRecRec_
{
FT_Int num_chars;
FT_Int code_first;
FT_Int code_last;
FT_UShort* char_index;
FT_String** char_name;
} T1_EncodingRec, *T1_Encoding;
/* used to hold extra data of PS_FontInfoRec that
* cannot be stored in the publicly defined structure.
*
* Note these can't be blended with multiple-masters.
*/
typedef struct PS_FontExtraRec_
{
FT_UShort fs_type;
} PS_FontExtraRec;
typedef struct T1_FontRec_
{
PS_FontInfoRec font_info; /* font info dictionary */
PS_FontExtraRec font_extra; /* font info extra fields */
PS_PrivateRec private_dict; /* private dictionary */
FT_String* font_name; /* top-level dictionary */
T1_EncodingType encoding_type;
T1_EncodingRec encoding;
FT_Byte* subrs_block;
FT_Byte* charstrings_block;
FT_Byte* glyph_names_block;
FT_Int num_subrs;
FT_Byte** subrs;
FT_PtrDist* subrs_len;
FT_Int num_glyphs;
FT_String** glyph_names; /* array of glyph names */
FT_Byte** charstrings; /* array of glyph charstrings */
FT_PtrDist* charstrings_len;
FT_Byte paint_type;
FT_Byte font_type;
FT_Matrix font_matrix;
FT_Vector font_offset;
FT_BBox font_bbox;
FT_Long font_id;
FT_Fixed stroke_width;
} T1_FontRec, *T1_Font;
typedef struct CID_SubrsRec_
{
FT_UInt num_subrs;
FT_Byte** code;
} CID_SubrsRec, *CID_Subrs;
/*************************************************************************/
/*************************************************************************/
/*************************************************************************/
/*** ***/
/*** ***/
/*** AFM FONT INFORMATION STRUCTURES ***/
/*** ***/
/*** ***/
/*************************************************************************/
/*************************************************************************/
/*************************************************************************/
typedef struct AFM_TrackKernRec_
{
FT_Int degree;
FT_Fixed min_ptsize;
FT_Fixed min_kern;
FT_Fixed max_ptsize;
FT_Fixed max_kern;
} AFM_TrackKernRec, *AFM_TrackKern;
typedef struct AFM_KernPairRec_
{
FT_Int index1;
FT_Int index2;
FT_Int x;
FT_Int y;
} AFM_KernPairRec, *AFM_KernPair;
typedef struct AFM_FontInfoRec_
{
FT_Bool IsCIDFont;
FT_BBox FontBBox;
FT_Fixed Ascender;
FT_Fixed Descender;
AFM_TrackKern TrackKerns; /* free if non-NULL */
FT_Int NumTrackKern;
AFM_KernPair KernPairs; /* free if non-NULL */
FT_Int NumKernPair;
} AFM_FontInfoRec, *AFM_FontInfo;
/*************************************************************************/
/*************************************************************************/
/*************************************************************************/
/*** ***/
/*** ***/
/*** ORIGINAL T1_FACE CLASS DEFINITION ***/
/*** ***/
/*** ***/
/*************************************************************************/
/*************************************************************************/
/*************************************************************************/
typedef struct T1_FaceRec_* T1_Face;
typedef struct CID_FaceRec_* CID_Face;
typedef struct T1_FaceRec_
{
FT_FaceRec root;
T1_FontRec type1;
const void* psnames;
const void* psaux;
const void* afm_data;
FT_CharMapRec charmaprecs[2];
FT_CharMap charmaps[2];
/* support for Multiple Masters fonts */
PS_Blend blend;
/* undocumented, optional: indices of subroutines that express */
/* the NormalizeDesignVector and the ConvertDesignVector procedure, */
/* respectively, as Type 2 charstrings; -1 if keywords not present */
FT_Int ndv_idx;
FT_Int cdv_idx;
/* undocumented, optional: has the same meaning as len_buildchar */
/* for Type 2 fonts; manipulated by othersubrs 19, 24, and 25 */
FT_UInt len_buildchar;
FT_Long* buildchar;
/* since version 2.1 - interface to PostScript hinter */
const void* pshinter;
} T1_FaceRec;
typedef struct CID_FaceRec_
{
FT_FaceRec root;
void* psnames;
void* psaux;
CID_FaceInfoRec cid;
PS_FontExtraRec font_extra;
#if 0
void* afm_data;
#endif
CID_Subrs subrs;
/* since version 2.1 - interface to PostScript hinter */
void* pshinter;
/* since version 2.1.8, but was originally positioned after `afm_data' */
FT_Byte* binary_data; /* used if hex data has been converted */
FT_Stream cid_stream;
} CID_FaceRec;
FT_END_HEADER
#endif /* __T1TYPES_H__ */
/* END */
| YifuLiu/AliOS-Things | components/freetype/include/internal/t1types.h | C | apache-2.0 | 9,851 |
/***************************************************************************/
/* */
/* tttypes.h */
/* */
/* Basic SFNT/TrueType type definitions and interface (specification */
/* only). */
/* */
/* Copyright 1996-2002, 2004-2008, 2012-2013 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. */
/* */
/***************************************************************************/
#ifndef __TTTYPES_H__
#define __TTTYPES_H__
#include <ft2build.h>
#include FT_TRUETYPE_TABLES_H
#include FT_INTERNAL_OBJECTS_H
#ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT
#include FT_MULTIPLE_MASTERS_H
#endif
FT_BEGIN_HEADER
/*************************************************************************/
/*************************************************************************/
/*************************************************************************/
/*** ***/
/*** ***/
/*** REQUIRED TRUETYPE/OPENTYPE TABLES DEFINITIONS ***/
/*** ***/
/*** ***/
/*************************************************************************/
/*************************************************************************/
/*************************************************************************/
/*************************************************************************/
/* */
/* <Struct> */
/* TTC_HeaderRec */
/* */
/* <Description> */
/* TrueType collection header. This table contains the offsets of */
/* the font headers of each distinct TrueType face in the file. */
/* */
/* <Fields> */
/* tag :: Must be `ttc ' to indicate a TrueType collection. */
/* */
/* version :: The version number. */
/* */
/* count :: The number of faces in the collection. The */
/* specification says this should be an unsigned long, but */
/* we use a signed long since we need the value -1 for */
/* specific purposes. */
/* */
/* offsets :: The offsets of the font headers, one per face. */
/* */
typedef struct TTC_HeaderRec_
{
FT_ULong tag;
FT_Fixed version;
FT_Long count;
FT_ULong* offsets;
} TTC_HeaderRec;
/*************************************************************************/
/* */
/* <Struct> */
/* SFNT_HeaderRec */
/* */
/* <Description> */
/* SFNT file format header. */
/* */
/* <Fields> */
/* format_tag :: The font format tag. */
/* */
/* num_tables :: The number of tables in file. */
/* */
/* search_range :: Must be `16 * (max power of 2 <= num_tables)'. */
/* */
/* entry_selector :: Must be log2 of `search_range / 16'. */
/* */
/* range_shift :: Must be `num_tables * 16 - search_range'. */
/* */
typedef struct SFNT_HeaderRec_
{
FT_ULong format_tag;
FT_UShort num_tables;
FT_UShort search_range;
FT_UShort entry_selector;
FT_UShort range_shift;
FT_ULong offset; /* not in file */
} SFNT_HeaderRec, *SFNT_Header;
/*************************************************************************/
/* */
/* <Struct> */
/* TT_TableRec */
/* */
/* <Description> */
/* This structure describes a given table of a TrueType font. */
/* */
/* <Fields> */
/* Tag :: A four-bytes tag describing the table. */
/* */
/* CheckSum :: The table checksum. This value can be ignored. */
/* */
/* Offset :: The offset of the table from the start of the TrueType */
/* font in its resource. */
/* */
/* Length :: The table length (in bytes). */
/* */
typedef struct TT_TableRec_
{
FT_ULong Tag; /* table type */
FT_ULong CheckSum; /* table checksum */
FT_ULong Offset; /* table file offset */
FT_ULong Length; /* table length */
} TT_TableRec, *TT_Table;
/*************************************************************************/
/* */
/* <Struct> */
/* WOFF_HeaderRec */
/* */
/* <Description> */
/* WOFF file format header. */
/* */
/* <Fields> */
/* See */
/* */
/* http://www.w3.org/TR/WOFF/#WOFFHeader */
/* */
typedef struct WOFF_HeaderRec_
{
FT_ULong signature;
FT_ULong flavor;
FT_ULong length;
FT_UShort num_tables;
FT_UShort reserved;
FT_ULong totalSfntSize;
FT_UShort majorVersion;
FT_UShort minorVersion;
FT_ULong metaOffset;
FT_ULong metaLength;
FT_ULong metaOrigLength;
FT_ULong privOffset;
FT_ULong privLength;
} WOFF_HeaderRec, *WOFF_Header;
/*************************************************************************/
/* */
/* <Struct> */
/* WOFF_TableRec */
/* */
/* <Description> */
/* This structure describes a given table of a WOFF font. */
/* */
/* <Fields> */
/* Tag :: A four-bytes tag describing the table. */
/* */
/* Offset :: The offset of the table from the start of the WOFF */
/* font in its resource. */
/* */
/* CompLength :: Compressed table length (in bytes). */
/* */
/* OrigLength :: Unompressed table length (in bytes). */
/* */
/* CheckSum :: The table checksum. This value can be ignored. */
/* */
/* OrigOffset :: The uncompressed table file offset. This value gets */
/* computed while constructing the (uncompressed) SFNT */
/* header. It is not contained in the WOFF file. */
/* */
typedef struct WOFF_TableRec_
{
FT_ULong Tag; /* table ID */
FT_ULong Offset; /* table file offset */
FT_ULong CompLength; /* compressed table length */
FT_ULong OrigLength; /* uncompressed table length */
FT_ULong CheckSum; /* uncompressed checksum */
FT_ULong OrigOffset; /* uncompressed table file offset */
/* (not in the WOFF file) */
} WOFF_TableRec, *WOFF_Table;
/*************************************************************************/
/* */
/* <Struct> */
/* TT_LongMetricsRec */
/* */
/* <Description> */
/* A structure modeling the long metrics of the `hmtx' and `vmtx' */
/* TrueType tables. The values are expressed in font units. */
/* */
/* <Fields> */
/* advance :: The advance width or height for the glyph. */
/* */
/* bearing :: The left-side or top-side bearing for the glyph. */
/* */
typedef struct TT_LongMetricsRec_
{
FT_UShort advance;
FT_Short bearing;
} TT_LongMetricsRec, *TT_LongMetrics;
/*************************************************************************/
/* */
/* <Type> */
/* TT_ShortMetrics */
/* */
/* <Description> */
/* A simple type to model the short metrics of the `hmtx' and `vmtx' */
/* tables. */
/* */
typedef FT_Short TT_ShortMetrics;
/*************************************************************************/
/* */
/* <Struct> */
/* TT_NameEntryRec */
/* */
/* <Description> */
/* A structure modeling TrueType name records. Name records are used */
/* to store important strings like family name, style name, */
/* copyright, etc. in _localized_ versions (i.e., language, encoding, */
/* etc). */
/* */
/* <Fields> */
/* platformID :: The ID of the name's encoding platform. */
/* */
/* encodingID :: The platform-specific ID for the name's encoding. */
/* */
/* languageID :: The platform-specific ID for the name's language. */
/* */
/* nameID :: The ID specifying what kind of name this is. */
/* */
/* stringLength :: The length of the string in bytes. */
/* */
/* stringOffset :: The offset to the string in the `name' table. */
/* */
/* string :: A pointer to the string's bytes. Note that these */
/* are usually UTF-16 encoded characters. */
/* */
typedef struct TT_NameEntryRec_
{
FT_UShort platformID;
FT_UShort encodingID;
FT_UShort languageID;
FT_UShort nameID;
FT_UShort stringLength;
FT_ULong stringOffset;
/* this last field is not defined in the spec */
/* but used by the FreeType engine */
FT_Byte* string;
} TT_NameEntryRec, *TT_NameEntry;
/*************************************************************************/
/* */
/* <Struct> */
/* TT_NameTableRec */
/* */
/* <Description> */
/* A structure modeling the TrueType name table. */
/* */
/* <Fields> */
/* format :: The format of the name table. */
/* */
/* numNameRecords :: The number of names in table. */
/* */
/* storageOffset :: The offset of the name table in the `name' */
/* TrueType table. */
/* */
/* names :: An array of name records. */
/* */
/* stream :: the file's input stream. */
/* */
typedef struct TT_NameTableRec_
{
FT_UShort format;
FT_UInt numNameRecords;
FT_UInt storageOffset;
TT_NameEntryRec* names;
FT_Stream stream;
} TT_NameTableRec, *TT_NameTable;
/*************************************************************************/
/*************************************************************************/
/*************************************************************************/
/*** ***/
/*** ***/
/*** OPTIONAL TRUETYPE/OPENTYPE TABLES DEFINITIONS ***/
/*** ***/
/*** ***/
/*************************************************************************/
/*************************************************************************/
/*************************************************************************/
/*************************************************************************/
/* */
/* <Struct> */
/* TT_GaspRangeRec */
/* */
/* <Description> */
/* A tiny structure used to model a gasp range according to the */
/* TrueType specification. */
/* */
/* <Fields> */
/* maxPPEM :: The maximum ppem value to which `gaspFlag' applies. */
/* */
/* gaspFlag :: A flag describing the grid-fitting and anti-aliasing */
/* modes to be used. */
/* */
typedef struct TT_GaspRangeRec_
{
FT_UShort maxPPEM;
FT_UShort gaspFlag;
} TT_GaspRangeRec, *TT_GaspRange;
#define TT_GASP_GRIDFIT 0x01
#define TT_GASP_DOGRAY 0x02
/*************************************************************************/
/* */
/* <Struct> */
/* TT_GaspRec */
/* */
/* <Description> */
/* A structure modeling the TrueType `gasp' table used to specify */
/* grid-fitting and anti-aliasing behaviour. */
/* */
/* <Fields> */
/* version :: The version number. */
/* */
/* numRanges :: The number of gasp ranges in table. */
/* */
/* gaspRanges :: An array of gasp ranges. */
/* */
typedef struct TT_Gasp_
{
FT_UShort version;
FT_UShort numRanges;
TT_GaspRange gaspRanges;
} TT_GaspRec;
/*************************************************************************/
/*************************************************************************/
/*************************************************************************/
/*** ***/
/*** ***/
/*** EMBEDDED BITMAPS SUPPORT ***/
/*** ***/
/*** ***/
/*************************************************************************/
/*************************************************************************/
/*************************************************************************/
/*************************************************************************/
/* */
/* <Struct> */
/* TT_SBit_MetricsRec */
/* */
/* <Description> */
/* A structure used to hold the big metrics of a given glyph bitmap */
/* in a TrueType or OpenType font. These are usually found in the */
/* `EBDT' (Microsoft) or `bloc' (Apple) table. */
/* */
/* <Fields> */
/* height :: The glyph height in pixels. */
/* */
/* width :: The glyph width in pixels. */
/* */
/* horiBearingX :: The horizontal left bearing. */
/* */
/* horiBearingY :: The horizontal top bearing. */
/* */
/* horiAdvance :: The horizontal advance. */
/* */
/* vertBearingX :: The vertical left bearing. */
/* */
/* vertBearingY :: The vertical top bearing. */
/* */
/* vertAdvance :: The vertical advance. */
/* */
typedef struct TT_SBit_MetricsRec_
{
FT_UShort height;
FT_UShort width;
FT_Short horiBearingX;
FT_Short horiBearingY;
FT_UShort horiAdvance;
FT_Short vertBearingX;
FT_Short vertBearingY;
FT_UShort vertAdvance;
} TT_SBit_MetricsRec, *TT_SBit_Metrics;
/*************************************************************************/
/* */
/* <Struct> */
/* TT_SBit_SmallMetricsRec */
/* */
/* <Description> */
/* A structure used to hold the small metrics of a given glyph bitmap */
/* in a TrueType or OpenType font. These are usually found in the */
/* `EBDT' (Microsoft) or the `bdat' (Apple) table. */
/* */
/* <Fields> */
/* height :: The glyph height in pixels. */
/* */
/* width :: The glyph width in pixels. */
/* */
/* bearingX :: The left-side bearing. */
/* */
/* bearingY :: The top-side bearing. */
/* */
/* advance :: The advance width or height. */
/* */
typedef struct TT_SBit_Small_Metrics_
{
FT_Byte height;
FT_Byte width;
FT_Char bearingX;
FT_Char bearingY;
FT_Byte advance;
} TT_SBit_SmallMetricsRec, *TT_SBit_SmallMetrics;
/*************************************************************************/
/* */
/* <Struct> */
/* TT_SBit_LineMetricsRec */
/* */
/* <Description> */
/* A structure used to describe the text line metrics of a given */
/* bitmap strike, for either a horizontal or vertical layout. */
/* */
/* <Fields> */
/* ascender :: The ascender in pixels. */
/* */
/* descender :: The descender in pixels. */
/* */
/* max_width :: The maximum glyph width in pixels. */
/* */
/* caret_slope_enumerator :: Rise of the caret slope, typically set */
/* to 1 for non-italic fonts. */
/* */
/* caret_slope_denominator :: Rise of the caret slope, typically set */
/* to 0 for non-italic fonts. */
/* */
/* caret_offset :: Offset in pixels to move the caret for */
/* proper positioning. */
/* */
/* min_origin_SB :: Minimum of horiBearingX (resp. */
/* vertBearingY). */
/* min_advance_SB :: Minimum of */
/* */
/* horizontal advance - */
/* ( horiBearingX + width ) */
/* */
/* resp. */
/* */
/* vertical advance - */
/* ( vertBearingY + height ) */
/* */
/* max_before_BL :: Maximum of horiBearingY (resp. */
/* vertBearingY). */
/* */
/* min_after_BL :: Minimum of */
/* */
/* horiBearingY - height */
/* */
/* resp. */
/* */
/* vertBearingX - width */
/* */
/* pads :: Unused (to make the size of the record */
/* a multiple of 32 bits. */
/* */
typedef struct TT_SBit_LineMetricsRec_
{
FT_Char ascender;
FT_Char descender;
FT_Byte max_width;
FT_Char caret_slope_numerator;
FT_Char caret_slope_denominator;
FT_Char caret_offset;
FT_Char min_origin_SB;
FT_Char min_advance_SB;
FT_Char max_before_BL;
FT_Char min_after_BL;
FT_Char pads[2];
} TT_SBit_LineMetricsRec, *TT_SBit_LineMetrics;
/*************************************************************************/
/* */
/* <Struct> */
/* TT_SBit_RangeRec */
/* */
/* <Description> */
/* A TrueType/OpenType subIndexTable as defined in the `EBLC' */
/* (Microsoft) or `bloc' (Apple) tables. */
/* */
/* <Fields> */
/* first_glyph :: The first glyph index in the range. */
/* */
/* last_glyph :: The last glyph index in the range. */
/* */
/* index_format :: The format of index table. Valid values are 1 */
/* to 5. */
/* */
/* image_format :: The format of `EBDT' image data. */
/* */
/* image_offset :: The offset to image data in `EBDT'. */
/* */
/* image_size :: For index formats 2 and 5. This is the size in */
/* bytes of each glyph bitmap. */
/* */
/* big_metrics :: For index formats 2 and 5. This is the big */
/* metrics for each glyph bitmap. */
/* */
/* num_glyphs :: For index formats 4 and 5. This is the number of */
/* glyphs in the code array. */
/* */
/* glyph_offsets :: For index formats 1 and 3. */
/* */
/* glyph_codes :: For index formats 4 and 5. */
/* */
/* table_offset :: The offset of the index table in the `EBLC' */
/* table. Only used during strike loading. */
/* */
typedef struct TT_SBit_RangeRec_
{
FT_UShort first_glyph;
FT_UShort last_glyph;
FT_UShort index_format;
FT_UShort image_format;
FT_ULong image_offset;
FT_ULong image_size;
TT_SBit_MetricsRec metrics;
FT_ULong num_glyphs;
FT_ULong* glyph_offsets;
FT_UShort* glyph_codes;
FT_ULong table_offset;
} TT_SBit_RangeRec, *TT_SBit_Range;
/*************************************************************************/
/* */
/* <Struct> */
/* TT_SBit_StrikeRec */
/* */
/* <Description> */
/* A structure used describe a given bitmap strike in the `EBLC' */
/* (Microsoft) or `bloc' (Apple) tables. */
/* */
/* <Fields> */
/* num_index_ranges :: The number of index ranges. */
/* */
/* index_ranges :: An array of glyph index ranges. */
/* */
/* color_ref :: Unused. `color_ref' is put in for future */
/* enhancements, but these fields are already */
/* in use by other platforms (e.g. Newton). */
/* For details, please see */
/* */
/* http://fonts.apple.com/ */
/* TTRefMan/RM06/Chap6bloc.html */
/* */
/* hori :: The line metrics for horizontal layouts. */
/* */
/* vert :: The line metrics for vertical layouts. */
/* */
/* start_glyph :: The lowest glyph index for this strike. */
/* */
/* end_glyph :: The highest glyph index for this strike. */
/* */
/* x_ppem :: The number of horizontal pixels per EM. */
/* */
/* y_ppem :: The number of vertical pixels per EM. */
/* */
/* bit_depth :: The bit depth. Valid values are 1, 2, 4, */
/* and 8. */
/* */
/* flags :: Is this a vertical or horizontal strike? For */
/* details, please see */
/* */
/* http://fonts.apple.com/ */
/* TTRefMan/RM06/Chap6bloc.html */
/* */
typedef struct TT_SBit_StrikeRec_
{
FT_Int num_ranges;
TT_SBit_Range sbit_ranges;
FT_ULong ranges_offset;
FT_ULong color_ref;
TT_SBit_LineMetricsRec hori;
TT_SBit_LineMetricsRec vert;
FT_UShort start_glyph;
FT_UShort end_glyph;
FT_Byte x_ppem;
FT_Byte y_ppem;
FT_Byte bit_depth;
FT_Char flags;
} TT_SBit_StrikeRec, *TT_SBit_Strike;
/*************************************************************************/
/* */
/* <Struct> */
/* TT_SBit_ComponentRec */
/* */
/* <Description> */
/* A simple structure to describe a compound sbit element. */
/* */
/* <Fields> */
/* glyph_code :: The element's glyph index. */
/* */
/* x_offset :: The element's left bearing. */
/* */
/* y_offset :: The element's top bearing. */
/* */
typedef struct TT_SBit_ComponentRec_
{
FT_UShort glyph_code;
FT_Char x_offset;
FT_Char y_offset;
} TT_SBit_ComponentRec, *TT_SBit_Component;
/*************************************************************************/
/* */
/* <Struct> */
/* TT_SBit_ScaleRec */
/* */
/* <Description> */
/* A structure used describe a given bitmap scaling table, as defined */
/* in the `EBSC' table. */
/* */
/* <Fields> */
/* hori :: The horizontal line metrics. */
/* */
/* vert :: The vertical line metrics. */
/* */
/* x_ppem :: The number of horizontal pixels per EM. */
/* */
/* y_ppem :: The number of vertical pixels per EM. */
/* */
/* x_ppem_substitute :: Substitution x_ppem value. */
/* */
/* y_ppem_substitute :: Substitution y_ppem value. */
/* */
typedef struct TT_SBit_ScaleRec_
{
TT_SBit_LineMetricsRec hori;
TT_SBit_LineMetricsRec vert;
FT_Byte x_ppem;
FT_Byte y_ppem;
FT_Byte x_ppem_substitute;
FT_Byte y_ppem_substitute;
} TT_SBit_ScaleRec, *TT_SBit_Scale;
/*************************************************************************/
/*************************************************************************/
/*************************************************************************/
/*** ***/
/*** ***/
/*** POSTSCRIPT GLYPH NAMES SUPPORT ***/
/*** ***/
/*** ***/
/*************************************************************************/
/*************************************************************************/
/*************************************************************************/
/*************************************************************************/
/* */
/* <Struct> */
/* TT_Post_20Rec */
/* */
/* <Description> */
/* Postscript names sub-table, format 2.0. Stores the PS name of */
/* each glyph in the font face. */
/* */
/* <Fields> */
/* num_glyphs :: The number of named glyphs in the table. */
/* */
/* num_names :: The number of PS names stored in the table. */
/* */
/* glyph_indices :: The indices of the glyphs in the names arrays. */
/* */
/* glyph_names :: The PS names not in Mac Encoding. */
/* */
typedef struct TT_Post_20Rec_
{
FT_UShort num_glyphs;
FT_UShort num_names;
FT_UShort* glyph_indices;
FT_Char** glyph_names;
} TT_Post_20Rec, *TT_Post_20;
/*************************************************************************/
/* */
/* <Struct> */
/* TT_Post_25Rec */
/* */
/* <Description> */
/* Postscript names sub-table, format 2.5. Stores the PS name of */
/* each glyph in the font face. */
/* */
/* <Fields> */
/* num_glyphs :: The number of glyphs in the table. */
/* */
/* offsets :: An array of signed offsets in a normal Mac */
/* Postscript name encoding. */
/* */
typedef struct TT_Post_25_
{
FT_UShort num_glyphs;
FT_Char* offsets;
} TT_Post_25Rec, *TT_Post_25;
/*************************************************************************/
/* */
/* <Struct> */
/* TT_Post_NamesRec */
/* */
/* <Description> */
/* Postscript names table, either format 2.0 or 2.5. */
/* */
/* <Fields> */
/* loaded :: A flag to indicate whether the PS names are loaded. */
/* */
/* format_20 :: The sub-table used for format 2.0. */
/* */
/* format_25 :: The sub-table used for format 2.5. */
/* */
typedef struct TT_Post_NamesRec_
{
FT_Bool loaded;
union
{
TT_Post_20Rec format_20;
TT_Post_25Rec format_25;
} names;
} TT_Post_NamesRec, *TT_Post_Names;
/*************************************************************************/
/*************************************************************************/
/*************************************************************************/
/*** ***/
/*** ***/
/*** GX VARIATION TABLE SUPPORT ***/
/*** ***/
/*** ***/
/*************************************************************************/
/*************************************************************************/
/*************************************************************************/
#ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT
typedef struct GX_BlendRec_ *GX_Blend;
#endif
/*************************************************************************/
/*************************************************************************/
/*************************************************************************/
/*** ***/
/*** ***/
/*** EMBEDDED BDF PROPERTIES TABLE SUPPORT ***/
/*** ***/
/*** ***/
/*************************************************************************/
/*************************************************************************/
/*************************************************************************/
/*
* These types are used to support a `BDF ' table that isn't part of the
* official TrueType specification. It is mainly used in SFNT-based
* bitmap fonts that were generated from a set of BDF fonts.
*
* The format of the table is as follows.
*
* USHORT version `BDF ' table version number, should be 0x0001.
* USHORT strikeCount Number of strikes (bitmap sizes) in this table.
* ULONG stringTable Offset (from start of BDF table) to string
* table.
*
* This is followed by an array of `strikeCount' descriptors, having the
* following format.
*
* USHORT ppem Vertical pixels per EM for this strike.
* USHORT numItems Number of items for this strike (properties and
* atoms). Maximum is 255.
*
* This array in turn is followed by `strikeCount' value sets. Each
* `value set' is an array of `numItems' items with the following format.
*
* ULONG item_name Offset in string table to item name.
* USHORT item_type The item type. Possible values are
* 0 => string (e.g., COMMENT)
* 1 => atom (e.g., FONT or even SIZE)
* 2 => int32
* 3 => uint32
* 0x10 => A flag to indicate a properties. This
* is ORed with the above values.
* ULONG item_value For strings => Offset into string table without
* the corresponding double quotes.
* For atoms => Offset into string table.
* For integers => Direct value.
*
* All strings in the string table consist of bytes and are
* zero-terminated.
*
*/
#ifdef TT_CONFIG_OPTION_BDF
typedef struct TT_BDFRec_
{
FT_Byte* table;
FT_Byte* table_end;
FT_Byte* strings;
FT_ULong strings_size;
FT_UInt num_strikes;
FT_Bool loaded;
} TT_BDFRec, *TT_BDF;
#endif /* TT_CONFIG_OPTION_BDF */
/*************************************************************************/
/*************************************************************************/
/*************************************************************************/
/*** ***/
/*** ***/
/*** ORIGINAL TT_FACE CLASS DEFINITION ***/
/*** ***/
/*** ***/
/*************************************************************************/
/*************************************************************************/
/*************************************************************************/
/*************************************************************************/
/* */
/* This structure/class is defined here because it is common to the */
/* following formats: TTF, OpenType-TT, and OpenType-CFF. */
/* */
/* Note, however, that the classes TT_Size and TT_GlyphSlot are not */
/* shared between font drivers, and are thus defined in `ttobjs.h'. */
/* */
/*************************************************************************/
/*************************************************************************/
/* */
/* <Type> */
/* TT_Face */
/* */
/* <Description> */
/* A handle to a TrueType face/font object. A TT_Face encapsulates */
/* the resolution and scaling independent parts of a TrueType font */
/* resource. */
/* */
/* <Note> */
/* The TT_Face structure is also used as a `parent class' for the */
/* OpenType-CFF class (T2_Face). */
/* */
typedef struct TT_FaceRec_* TT_Face;
/* a function type used for the truetype bytecode interpreter hooks */
typedef FT_Error
(*TT_Interpreter)( void* exec_context );
/* forward declaration */
typedef struct TT_LoaderRec_* TT_Loader;
/*************************************************************************/
/* */
/* <FuncType> */
/* TT_Loader_GotoTableFunc */
/* */
/* <Description> */
/* Seeks a stream to the start of a given TrueType table. */
/* */
/* <Input> */
/* face :: A handle to the target face object. */
/* */
/* tag :: A 4-byte tag used to name the table. */
/* */
/* stream :: The input stream. */
/* */
/* <Output> */
/* length :: The length of the table in bytes. Set to 0 if not */
/* needed. */
/* */
/* <Return> */
/* FreeType error code. 0 means success. */
/* */
/* <Note> */
/* The stream cursor must be at the font file's origin. */
/* */
typedef FT_Error
(*TT_Loader_GotoTableFunc)( TT_Face face,
FT_ULong tag,
FT_Stream stream,
FT_ULong* length );
/*************************************************************************/
/* */
/* <FuncType> */
/* TT_Loader_StartGlyphFunc */
/* */
/* <Description> */
/* Seeks a stream to the start of a given glyph element, and opens a */
/* frame for it. */
/* */
/* <Input> */
/* loader :: The current TrueType glyph loader object. */
/* */
/* glyph index :: The index of the glyph to access. */
/* */
/* offset :: The offset of the glyph according to the */
/* `locations' table. */
/* */
/* byte_count :: The size of the frame in bytes. */
/* */
/* <Return> */
/* FreeType error code. 0 means success. */
/* */
/* <Note> */
/* This function is normally equivalent to FT_STREAM_SEEK(offset) */
/* followed by FT_FRAME_ENTER(byte_count) with the loader's stream, */
/* but alternative formats (e.g. compressed ones) might use something */
/* different. */
/* */
typedef FT_Error
(*TT_Loader_StartGlyphFunc)( TT_Loader loader,
FT_UInt glyph_index,
FT_ULong offset,
FT_UInt byte_count );
/*************************************************************************/
/* */
/* <FuncType> */
/* TT_Loader_ReadGlyphFunc */
/* */
/* <Description> */
/* Reads one glyph element (its header, a simple glyph, or a */
/* composite) from the loader's current stream frame. */
/* */
/* <Input> */
/* loader :: The current TrueType glyph loader object. */
/* */
/* <Return> */
/* FreeType error code. 0 means success. */
/* */
typedef FT_Error
(*TT_Loader_ReadGlyphFunc)( TT_Loader loader );
/*************************************************************************/
/* */
/* <FuncType> */
/* TT_Loader_EndGlyphFunc */
/* */
/* <Description> */
/* Closes the current loader stream frame for the glyph. */
/* */
/* <Input> */
/* loader :: The current TrueType glyph loader object. */
/* */
typedef void
(*TT_Loader_EndGlyphFunc)( TT_Loader loader );
typedef enum TT_SbitTableType_
{
TT_SBIT_TABLE_TYPE_NONE = 0,
TT_SBIT_TABLE_TYPE_EBLC, /* `EBLC' (Microsoft), */
/* `bloc' (Apple) */
TT_SBIT_TABLE_TYPE_CBLC, /* `CBLC' (Google) */
TT_SBIT_TABLE_TYPE_SBIX, /* `sbix' (Apple) */
/* do not remove */
TT_SBIT_TABLE_TYPE_MAX
} TT_SbitTableType;
/*************************************************************************/
/* */
/* TrueType Face Type */
/* */
/* <Struct> */
/* TT_Face */
/* */
/* <Description> */
/* The TrueType face class. These objects model the resolution and */
/* point-size independent data found in a TrueType font file. */
/* */
/* <Fields> */
/* root :: The base FT_Face structure, managed by the */
/* base layer. */
/* */
/* ttc_header :: The TrueType collection header, used when */
/* the file is a `ttc' rather than a `ttf'. */
/* For ordinary font files, the field */
/* `ttc_header.count' is set to 0. */
/* */
/* format_tag :: The font format tag. */
/* */
/* num_tables :: The number of TrueType tables in this font */
/* file. */
/* */
/* dir_tables :: The directory of TrueType tables for this */
/* font file. */
/* */
/* header :: The font's font header (`head' table). */
/* Read on font opening. */
/* */
/* horizontal :: The font's horizontal header (`hhea' */
/* table). This field also contains the */
/* associated horizontal metrics table */
/* (`hmtx'). */
/* */
/* max_profile :: The font's maximum profile table. Read on */
/* font opening. Note that some maximum */
/* values cannot be taken directly from this */
/* table. We thus define additional fields */
/* below to hold the computed maxima. */
/* */
/* vertical_info :: A boolean which is set when the font file */
/* contains vertical metrics. If not, the */
/* value of the `vertical' field is */
/* undefined. */
/* */
/* vertical :: The font's vertical header (`vhea' table). */
/* This field also contains the associated */
/* vertical metrics table (`vmtx'), if found. */
/* IMPORTANT: The contents of this field is */
/* undefined if the `verticalInfo' field is */
/* unset. */
/* */
/* num_names :: The number of name records within this */
/* TrueType font. */
/* */
/* name_table :: The table of name records (`name'). */
/* */
/* os2 :: The font's OS/2 table (`OS/2'). */
/* */
/* postscript :: The font's PostScript table (`post' */
/* table). The PostScript glyph names are */
/* not loaded by the driver on face opening. */
/* See the `ttpost' module for more details. */
/* */
/* cmap_table :: Address of the face's `cmap' SFNT table */
/* in memory (it's an extracted frame). */
/* */
/* cmap_size :: The size in bytes of the `cmap_table' */
/* described above. */
/* */
/* goto_table :: A function called by each TrueType table */
/* loader to position a stream's cursor to */
/* the start of a given table according to */
/* its tag. It defaults to TT_Goto_Face but */
/* can be different for strange formats (e.g. */
/* Type 42). */
/* */
/* access_glyph_frame :: A function used to access the frame of a */
/* given glyph within the face's font file. */
/* */
/* forget_glyph_frame :: A function used to forget the frame of a */
/* given glyph when all data has been loaded. */
/* */
/* read_glyph_header :: A function used to read a glyph header. */
/* It must be called between an `access' and */
/* `forget'. */
/* */
/* read_simple_glyph :: A function used to read a simple glyph. */
/* It must be called after the header was */
/* read, and before the `forget'. */
/* */
/* read_composite_glyph :: A function used to read a composite glyph. */
/* It must be called after the header was */
/* read, and before the `forget'. */
/* */
/* sfnt :: A pointer to the SFNT service. */
/* */
/* psnames :: A pointer to the PostScript names service. */
/* */
/* hdmx :: The face's horizontal device metrics */
/* (`hdmx' table). This table is optional in */
/* TrueType/OpenType fonts. */
/* */
/* gasp :: The grid-fitting and scaling properties */
/* table (`gasp'). This table is optional in */
/* TrueType/OpenType fonts. */
/* */
/* pclt :: The `pclt' SFNT table. */
/* */
/* num_sbit_scales :: The number of sbit scales for this font. */
/* */
/* sbit_scales :: Array of sbit scales embedded in this */
/* font. This table is optional in a */
/* TrueType/OpenType font. */
/* */
/* postscript_names :: A table used to store the Postscript names */
/* of the glyphs for this font. See the */
/* file `ttconfig.h' for comments on the */
/* TT_CONFIG_OPTION_POSTSCRIPT_NAMES option. */
/* */
/* num_locations :: The number of glyph locations in this */
/* TrueType file. This should be */
/* identical to the number of glyphs. */
/* Ignored for Type 2 fonts. */
/* */
/* glyph_locations :: An array of longs. These are offsets to */
/* glyph data within the `glyf' table. */
/* Ignored for Type 2 font faces. */
/* */
/* glyf_len :: The length of the `glyf' table. Needed */
/* for malformed `loca' tables. */
/* */
/* font_program_size :: Size in bytecodes of the face's font */
/* program. 0 if none defined. Ignored for */
/* Type 2 fonts. */
/* */
/* font_program :: The face's font program (bytecode stream) */
/* executed at load time, also used during */
/* glyph rendering. Comes from the `fpgm' */
/* table. Ignored for Type 2 font fonts. */
/* */
/* cvt_program_size :: The size in bytecodes of the face's cvt */
/* program. Ignored for Type 2 fonts. */
/* */
/* cvt_program :: The face's cvt program (bytecode stream) */
/* executed each time an instance/size is */
/* changed/reset. Comes from the `prep' */
/* table. Ignored for Type 2 fonts. */
/* */
/* cvt_size :: Size of the control value table (in */
/* entries). Ignored for Type 2 fonts. */
/* */
/* cvt :: The face's original control value table. */
/* Coordinates are expressed in unscaled font */
/* units. Comes from the `cvt ' table. */
/* Ignored for Type 2 fonts. */
/* */
/* num_kern_pairs :: The number of kerning pairs present in the */
/* font file. The engine only loads the */
/* first horizontal format 0 kern table it */
/* finds in the font file. Ignored for */
/* Type 2 fonts. */
/* */
/* kern_table_index :: The index of the kerning table in the font */
/* kerning directory. Ignored for Type 2 */
/* fonts. */
/* */
/* interpreter :: A pointer to the TrueType bytecode */
/* interpreters field is also used to hook */
/* the debugger in `ttdebug'. */
/* */
/* unpatented_hinting :: If true, use only unpatented methods in */
/* the bytecode interpreter. */
/* */
/* doblend :: A boolean which is set if the font should */
/* be blended (this is for GX var). */
/* */
/* blend :: Contains the data needed to control GX */
/* variation tables (rather like Multiple */
/* Master data). */
/* */
/* extra :: Reserved for third-party font drivers. */
/* */
/* postscript_name :: The PS name of the font. Used by the */
/* postscript name service. */
/* */
typedef struct TT_FaceRec_
{
FT_FaceRec root;
TTC_HeaderRec ttc_header;
FT_ULong format_tag;
FT_UShort num_tables;
TT_Table dir_tables;
TT_Header header; /* TrueType header table */
TT_HoriHeader horizontal; /* TrueType horizontal header */
TT_MaxProfile max_profile;
FT_Bool vertical_info;
TT_VertHeader vertical; /* TT Vertical header, if present */
FT_UShort num_names; /* number of name records */
TT_NameTableRec name_table; /* name table */
TT_OS2 os2; /* TrueType OS/2 table */
TT_Postscript postscript; /* TrueType Postscript table */
FT_Byte* cmap_table; /* extracted `cmap' table */
FT_ULong cmap_size;
TT_Loader_GotoTableFunc goto_table;
TT_Loader_StartGlyphFunc access_glyph_frame;
TT_Loader_EndGlyphFunc forget_glyph_frame;
TT_Loader_ReadGlyphFunc read_glyph_header;
TT_Loader_ReadGlyphFunc read_simple_glyph;
TT_Loader_ReadGlyphFunc read_composite_glyph;
/* a typeless pointer to the SFNT_Interface table used to load */
/* the basic TrueType tables in the face object */
void* sfnt;
/* a typeless pointer to the FT_Service_PsCMapsRec table used to */
/* handle glyph names <-> unicode & Mac values */
void* psnames;
/***********************************************************************/
/* */
/* Optional TrueType/OpenType tables */
/* */
/***********************************************************************/
/* grid-fitting and scaling table */
TT_GaspRec gasp; /* the `gasp' table */
/* PCL 5 table */
TT_PCLT pclt;
/* embedded bitmaps support */
FT_ULong num_sbit_scales;
TT_SBit_Scale sbit_scales;
/* postscript names table */
TT_Post_NamesRec postscript_names;
/***********************************************************************/
/* */
/* TrueType-specific fields (ignored by the OTF-Type2 driver) */
/* */
/***********************************************************************/
/* the font program, if any */
FT_ULong font_program_size;
FT_Byte* font_program;
/* the cvt program, if any */
FT_ULong cvt_program_size;
FT_Byte* cvt_program;
/* the original, unscaled, control value table */
FT_ULong cvt_size;
FT_Short* cvt;
/* A pointer to the bytecode interpreter to use. This is also */
/* used to hook the debugger for the `ttdebug' utility. */
TT_Interpreter interpreter;
#ifdef TT_CONFIG_OPTION_UNPATENTED_HINTING
/* Use unpatented hinting only. */
FT_Bool unpatented_hinting;
#endif
/***********************************************************************/
/* */
/* Other tables or fields. This is used by derivative formats like */
/* OpenType. */
/* */
/***********************************************************************/
FT_Generic extra;
const char* postscript_name;
FT_ULong glyf_len;
#ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT
FT_Bool doblend;
GX_Blend blend;
#endif
/* since version 2.2 */
FT_Byte* horz_metrics;
FT_ULong horz_metrics_size;
FT_Byte* vert_metrics;
FT_ULong vert_metrics_size;
FT_ULong num_locations; /* in broken TTF, gid > 0xFFFF */
FT_Byte* glyph_locations;
FT_Byte* hdmx_table;
FT_ULong hdmx_table_size;
FT_UInt hdmx_record_count;
FT_ULong hdmx_record_size;
FT_Byte* hdmx_record_sizes;
FT_Byte* sbit_table;
FT_ULong sbit_table_size;
TT_SbitTableType sbit_table_type;
FT_UInt sbit_num_strikes;
FT_Byte* kern_table;
FT_ULong kern_table_size;
FT_UInt num_kern_tables;
FT_UInt32 kern_avail_bits;
FT_UInt32 kern_order_bits;
#ifdef TT_CONFIG_OPTION_BDF
TT_BDFRec bdf;
#endif /* TT_CONFIG_OPTION_BDF */
/* since 2.3.0 */
FT_ULong horz_metrics_offset;
FT_ULong vert_metrics_offset;
#ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING
/* since 2.4.12 */
FT_ULong sph_found_func_flags; /* special functions found */
/* for this face */
FT_Bool sph_compatibility_mode;
#endif /* TT_CONFIG_OPTION_SUBPIXEL_HINTING */
} TT_FaceRec;
/*************************************************************************/
/* */
/* <Struct> */
/* TT_GlyphZoneRec */
/* */
/* <Description> */
/* A glyph zone is used to load, scale and hint glyph outline */
/* coordinates. */
/* */
/* <Fields> */
/* memory :: A handle to the memory manager. */
/* */
/* max_points :: The maximum size in points of the zone. */
/* */
/* max_contours :: Max size in links contours of the zone. */
/* */
/* n_points :: The current number of points in the zone. */
/* */
/* n_contours :: The current number of contours in the zone. */
/* */
/* org :: The original glyph coordinates (font */
/* units/scaled). */
/* */
/* cur :: The current glyph coordinates (scaled/hinted). */
/* */
/* tags :: The point control tags. */
/* */
/* contours :: The contours end points. */
/* */
/* first_point :: Offset of the current subglyph's first point. */
/* */
typedef struct TT_GlyphZoneRec_
{
FT_Memory memory;
FT_UShort max_points;
FT_UShort max_contours;
FT_UShort n_points; /* number of points in zone */
FT_Short n_contours; /* number of contours */
FT_Vector* org; /* original point coordinates */
FT_Vector* cur; /* current point coordinates */
FT_Vector* orus; /* original (unscaled) point coordinates */
FT_Byte* tags; /* current touch flags */
FT_UShort* contours; /* contour end points */
FT_UShort first_point; /* offset of first (#0) point */
} TT_GlyphZoneRec, *TT_GlyphZone;
/* handle to execution context */
typedef struct TT_ExecContextRec_* TT_ExecContext;
/* glyph loader structure */
typedef struct TT_LoaderRec_
{
FT_Face face;
FT_Size size;
FT_GlyphSlot glyph;
FT_GlyphLoader gloader;
FT_ULong load_flags;
FT_UInt glyph_index;
FT_Stream stream;
FT_Int byte_len;
FT_Short n_contours;
FT_BBox bbox;
FT_Int left_bearing;
FT_Int advance;
FT_Int linear;
FT_Bool linear_def;
FT_Vector pp1;
FT_Vector pp2;
FT_ULong glyf_offset;
/* the zone where we load our glyphs */
TT_GlyphZoneRec base;
TT_GlyphZoneRec zone;
TT_ExecContext exec;
FT_Byte* instructions;
FT_ULong ins_pos;
/* for possible extensibility in other formats */
void* other;
/* since version 2.1.8 */
FT_Int top_bearing;
FT_Int vadvance;
FT_Vector pp3;
FT_Vector pp4;
/* since version 2.2.1 */
FT_Byte* cursor;
FT_Byte* limit;
} TT_LoaderRec;
FT_END_HEADER
#endif /* __TTTYPES_H__ */
/* END */
| YifuLiu/AliOS-Things | components/freetype/include/internal/tttypes.h | C | apache-2.0 | 85,113 |
/***************************************************************************/
/* */
/* t1tables.h */
/* */
/* Basic Type 1/Type 2 tables definitions and interface (specification */
/* only). */
/* */
/* Copyright 1996-2004, 2006, 2008, 2009, 2011 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. */
/* */
/***************************************************************************/
#ifndef __T1TABLES_H__
#define __T1TABLES_H__
#include <ft2build.h>
#include FT_FREETYPE_H
#ifdef FREETYPE_H
#error "freetype.h of FreeType 1 has been loaded!"
#error "Please fix the directory search order for header files"
#error "so that freetype.h of FreeType 2 is found first."
#endif
FT_BEGIN_HEADER
/*************************************************************************/
/* */
/* <Section> */
/* type1_tables */
/* */
/* <Title> */
/* Type 1 Tables */
/* */
/* <Abstract> */
/* Type~1 (PostScript) specific font tables. */
/* */
/* <Description> */
/* This section contains the definition of Type 1-specific tables, */
/* including structures related to other PostScript font formats. */
/* */
/*************************************************************************/
/* Note that we separate font data in PS_FontInfoRec and PS_PrivateRec */
/* structures in order to support Multiple Master fonts. */
/*************************************************************************/
/* */
/* <Struct> */
/* PS_FontInfoRec */
/* */
/* <Description> */
/* A structure used to model a Type~1 or Type~2 FontInfo dictionary. */
/* Note that for Multiple Master fonts, each instance has its own */
/* FontInfo dictionary. */
/* */
typedef struct PS_FontInfoRec_
{
FT_String* version;
FT_String* notice;
FT_String* full_name;
FT_String* family_name;
FT_String* weight;
FT_Long italic_angle;
FT_Bool is_fixed_pitch;
FT_Short underline_position;
FT_UShort underline_thickness;
} PS_FontInfoRec;
/*************************************************************************/
/* */
/* <Struct> */
/* PS_FontInfo */
/* */
/* <Description> */
/* A handle to a @PS_FontInfoRec structure. */
/* */
typedef struct PS_FontInfoRec_* PS_FontInfo;
/*************************************************************************/
/* */
/* <Struct> */
/* T1_FontInfo */
/* */
/* <Description> */
/* This type is equivalent to @PS_FontInfoRec. It is deprecated but */
/* kept to maintain source compatibility between various versions of */
/* FreeType. */
/* */
typedef PS_FontInfoRec T1_FontInfo;
/*************************************************************************/
/* */
/* <Struct> */
/* PS_PrivateRec */
/* */
/* <Description> */
/* A structure used to model a Type~1 or Type~2 private dictionary. */
/* Note that for Multiple Master fonts, each instance has its own */
/* Private dictionary. */
/* */
typedef struct PS_PrivateRec_
{
FT_Int unique_id;
FT_Int lenIV;
FT_Byte num_blue_values;
FT_Byte num_other_blues;
FT_Byte num_family_blues;
FT_Byte num_family_other_blues;
FT_Short blue_values[14];
FT_Short other_blues[10];
FT_Short family_blues [14];
FT_Short family_other_blues[10];
FT_Fixed blue_scale;
FT_Int blue_shift;
FT_Int blue_fuzz;
FT_UShort standard_width[1];
FT_UShort standard_height[1];
FT_Byte num_snap_widths;
FT_Byte num_snap_heights;
FT_Bool force_bold;
FT_Bool round_stem_up;
FT_Short snap_widths [13]; /* including std width */
FT_Short snap_heights[13]; /* including std height */
FT_Fixed expansion_factor;
FT_Long language_group;
FT_Long password;
FT_Short min_feature[2];
} PS_PrivateRec;
/*************************************************************************/
/* */
/* <Struct> */
/* PS_Private */
/* */
/* <Description> */
/* A handle to a @PS_PrivateRec structure. */
/* */
typedef struct PS_PrivateRec_* PS_Private;
/*************************************************************************/
/* */
/* <Struct> */
/* T1_Private */
/* */
/* <Description> */
/* This type is equivalent to @PS_PrivateRec. It is deprecated but */
/* kept to maintain source compatibility between various versions of */
/* FreeType. */
/* */
typedef PS_PrivateRec T1_Private;
/*************************************************************************/
/* */
/* <Enum> */
/* T1_Blend_Flags */
/* */
/* <Description> */
/* A set of flags used to indicate which fields are present in a */
/* given blend dictionary (font info or private). Used to support */
/* Multiple Masters fonts. */
/* */
typedef enum T1_Blend_Flags_
{
/*# required fields in a FontInfo blend dictionary */
T1_BLEND_UNDERLINE_POSITION = 0,
T1_BLEND_UNDERLINE_THICKNESS,
T1_BLEND_ITALIC_ANGLE,
/*# required fields in a Private blend dictionary */
T1_BLEND_BLUE_VALUES,
T1_BLEND_OTHER_BLUES,
T1_BLEND_STANDARD_WIDTH,
T1_BLEND_STANDARD_HEIGHT,
T1_BLEND_STEM_SNAP_WIDTHS,
T1_BLEND_STEM_SNAP_HEIGHTS,
T1_BLEND_BLUE_SCALE,
T1_BLEND_BLUE_SHIFT,
T1_BLEND_FAMILY_BLUES,
T1_BLEND_FAMILY_OTHER_BLUES,
T1_BLEND_FORCE_BOLD,
/*# never remove */
T1_BLEND_MAX
} T1_Blend_Flags;
/* */
/*# backwards compatible definitions */
#define t1_blend_underline_position T1_BLEND_UNDERLINE_POSITION
#define t1_blend_underline_thickness T1_BLEND_UNDERLINE_THICKNESS
#define t1_blend_italic_angle T1_BLEND_ITALIC_ANGLE
#define t1_blend_blue_values T1_BLEND_BLUE_VALUES
#define t1_blend_other_blues T1_BLEND_OTHER_BLUES
#define t1_blend_standard_widths T1_BLEND_STANDARD_WIDTH
#define t1_blend_standard_height T1_BLEND_STANDARD_HEIGHT
#define t1_blend_stem_snap_widths T1_BLEND_STEM_SNAP_WIDTHS
#define t1_blend_stem_snap_heights T1_BLEND_STEM_SNAP_HEIGHTS
#define t1_blend_blue_scale T1_BLEND_BLUE_SCALE
#define t1_blend_blue_shift T1_BLEND_BLUE_SHIFT
#define t1_blend_family_blues T1_BLEND_FAMILY_BLUES
#define t1_blend_family_other_blues T1_BLEND_FAMILY_OTHER_BLUES
#define t1_blend_force_bold T1_BLEND_FORCE_BOLD
#define t1_blend_max T1_BLEND_MAX
/* maximum number of Multiple Masters designs, as defined in the spec */
#define T1_MAX_MM_DESIGNS 16
/* maximum number of Multiple Masters axes, as defined in the spec */
#define T1_MAX_MM_AXIS 4
/* maximum number of elements in a design map */
#define T1_MAX_MM_MAP_POINTS 20
/* this structure is used to store the BlendDesignMap entry for an axis */
typedef struct PS_DesignMap_
{
FT_Byte num_points;
FT_Long* design_points;
FT_Fixed* blend_points;
} PS_DesignMapRec, *PS_DesignMap;
/* backwards-compatible definition */
typedef PS_DesignMapRec T1_DesignMap;
typedef struct PS_BlendRec_
{
FT_UInt num_designs;
FT_UInt num_axis;
FT_String* axis_names[T1_MAX_MM_AXIS];
FT_Fixed* design_pos[T1_MAX_MM_DESIGNS];
PS_DesignMapRec design_map[T1_MAX_MM_AXIS];
FT_Fixed* weight_vector;
FT_Fixed* default_weight_vector;
PS_FontInfo font_infos[T1_MAX_MM_DESIGNS + 1];
PS_Private privates [T1_MAX_MM_DESIGNS + 1];
FT_ULong blend_bitflags;
FT_BBox* bboxes [T1_MAX_MM_DESIGNS + 1];
/* since 2.3.0 */
/* undocumented, optional: the default design instance; */
/* corresponds to default_weight_vector -- */
/* num_default_design_vector == 0 means it is not present */
/* in the font and associated metrics files */
FT_UInt default_design_vector[T1_MAX_MM_DESIGNS];
FT_UInt num_default_design_vector;
} PS_BlendRec, *PS_Blend;
/* backwards-compatible definition */
typedef PS_BlendRec T1_Blend;
/*************************************************************************/
/* */
/* <Struct> */
/* CID_FaceDictRec */
/* */
/* <Description> */
/* A structure used to represent data in a CID top-level dictionary. */
/* */
typedef struct CID_FaceDictRec_
{
PS_PrivateRec private_dict;
FT_UInt len_buildchar;
FT_Fixed forcebold_threshold;
FT_Pos stroke_width;
FT_Fixed expansion_factor;
FT_Byte paint_type;
FT_Byte font_type;
FT_Matrix font_matrix;
FT_Vector font_offset;
FT_UInt num_subrs;
FT_ULong subrmap_offset;
FT_Int sd_bytes;
} CID_FaceDictRec;
/*************************************************************************/
/* */
/* <Struct> */
/* CID_FaceDict */
/* */
/* <Description> */
/* A handle to a @CID_FaceDictRec structure. */
/* */
typedef struct CID_FaceDictRec_* CID_FaceDict;
/* */
/* backwards-compatible definition */
typedef CID_FaceDictRec CID_FontDict;
/*************************************************************************/
/* */
/* <Struct> */
/* CID_FaceInfoRec */
/* */
/* <Description> */
/* A structure used to represent CID Face information. */
/* */
typedef struct CID_FaceInfoRec_
{
FT_String* cid_font_name;
FT_Fixed cid_version;
FT_Int cid_font_type;
FT_String* registry;
FT_String* ordering;
FT_Int supplement;
PS_FontInfoRec font_info;
FT_BBox font_bbox;
FT_ULong uid_base;
FT_Int num_xuid;
FT_ULong xuid[16];
FT_ULong cidmap_offset;
FT_Int fd_bytes;
FT_Int gd_bytes;
FT_ULong cid_count;
FT_Int num_dicts;
CID_FaceDict font_dicts;
FT_ULong data_offset;
} CID_FaceInfoRec;
/*************************************************************************/
/* */
/* <Struct> */
/* CID_FaceInfo */
/* */
/* <Description> */
/* A handle to a @CID_FaceInfoRec structure. */
/* */
typedef struct CID_FaceInfoRec_* CID_FaceInfo;
/*************************************************************************/
/* */
/* <Struct> */
/* CID_Info */
/* */
/* <Description> */
/* This type is equivalent to @CID_FaceInfoRec. It is deprecated but */
/* kept to maintain source compatibility between various versions of */
/* FreeType. */
/* */
typedef CID_FaceInfoRec CID_Info;
/************************************************************************
*
* @function:
* FT_Has_PS_Glyph_Names
*
* @description:
* Return true if a given face provides reliable PostScript glyph
* names. This is similar to using the @FT_HAS_GLYPH_NAMES macro,
* except that certain fonts (mostly TrueType) contain incorrect
* glyph name tables.
*
* When this function returns true, the caller is sure that the glyph
* names returned by @FT_Get_Glyph_Name are reliable.
*
* @input:
* face ::
* face handle
*
* @return:
* Boolean. True if glyph names are reliable.
*
*/
FT_EXPORT( FT_Int )
FT_Has_PS_Glyph_Names( FT_Face face );
/************************************************************************
*
* @function:
* FT_Get_PS_Font_Info
*
* @description:
* Retrieve the @PS_FontInfoRec structure corresponding to a given
* PostScript font.
*
* @input:
* face ::
* PostScript face handle.
*
* @output:
* afont_info ::
* Output font info structure pointer.
*
* @return:
* FreeType error code. 0~means success.
*
* @note:
* The string pointers within the font info structure are owned by
* the face and don't need to be freed by the caller.
*
* If the font's format is not PostScript-based, this function will
* return the `FT_Err_Invalid_Argument' error code.
*
*/
FT_EXPORT( FT_Error )
FT_Get_PS_Font_Info( FT_Face face,
PS_FontInfo afont_info );
/************************************************************************
*
* @function:
* FT_Get_PS_Font_Private
*
* @description:
* Retrieve the @PS_PrivateRec structure corresponding to a given
* PostScript font.
*
* @input:
* face ::
* PostScript face handle.
*
* @output:
* afont_private ::
* Output private dictionary structure pointer.
*
* @return:
* FreeType error code. 0~means success.
*
* @note:
* The string pointers within the @PS_PrivateRec structure are owned by
* the face and don't need to be freed by the caller.
*
* If the font's format is not PostScript-based, this function returns
* the `FT_Err_Invalid_Argument' error code.
*
*/
FT_EXPORT( FT_Error )
FT_Get_PS_Font_Private( FT_Face face,
PS_Private afont_private );
/*************************************************************************/
/* */
/* <Enum> */
/* T1_EncodingType */
/* */
/* <Description> */
/* An enumeration describing the `Encoding' entry in a Type 1 */
/* dictionary. */
/* */
typedef enum T1_EncodingType_
{
T1_ENCODING_TYPE_NONE = 0,
T1_ENCODING_TYPE_ARRAY,
T1_ENCODING_TYPE_STANDARD,
T1_ENCODING_TYPE_ISOLATIN1,
T1_ENCODING_TYPE_EXPERT
} T1_EncodingType;
/*************************************************************************/
/* */
/* <Enum> */
/* PS_Dict_Keys */
/* */
/* <Description> */
/* An enumeration used in calls to @FT_Get_PS_Font_Value to identify */
/* the Type~1 dictionary entry to retrieve. */
/* */
typedef enum PS_Dict_Keys_
{
/* conventionally in the font dictionary */
PS_DICT_FONT_TYPE, /* FT_Byte */
PS_DICT_FONT_MATRIX, /* FT_Fixed */
PS_DICT_FONT_BBOX, /* FT_Fixed */
PS_DICT_PAINT_TYPE, /* FT_Byte */
PS_DICT_FONT_NAME, /* FT_String* */
PS_DICT_UNIQUE_ID, /* FT_Int */
PS_DICT_NUM_CHAR_STRINGS, /* FT_Int */
PS_DICT_CHAR_STRING_KEY, /* FT_String* */
PS_DICT_CHAR_STRING, /* FT_String* */
PS_DICT_ENCODING_TYPE, /* T1_EncodingType */
PS_DICT_ENCODING_ENTRY, /* FT_String* */
/* conventionally in the font Private dictionary */
PS_DICT_NUM_SUBRS, /* FT_Int */
PS_DICT_SUBR, /* FT_String* */
PS_DICT_STD_HW, /* FT_UShort */
PS_DICT_STD_VW, /* FT_UShort */
PS_DICT_NUM_BLUE_VALUES, /* FT_Byte */
PS_DICT_BLUE_VALUE, /* FT_Short */
PS_DICT_BLUE_FUZZ, /* FT_Int */
PS_DICT_NUM_OTHER_BLUES, /* FT_Byte */
PS_DICT_OTHER_BLUE, /* FT_Short */
PS_DICT_NUM_FAMILY_BLUES, /* FT_Byte */
PS_DICT_FAMILY_BLUE, /* FT_Short */
PS_DICT_NUM_FAMILY_OTHER_BLUES, /* FT_Byte */
PS_DICT_FAMILY_OTHER_BLUE, /* FT_Short */
PS_DICT_BLUE_SCALE, /* FT_Fixed */
PS_DICT_BLUE_SHIFT, /* FT_Int */
PS_DICT_NUM_STEM_SNAP_H, /* FT_Byte */
PS_DICT_STEM_SNAP_H, /* FT_Short */
PS_DICT_NUM_STEM_SNAP_V, /* FT_Byte */
PS_DICT_STEM_SNAP_V, /* FT_Short */
PS_DICT_FORCE_BOLD, /* FT_Bool */
PS_DICT_RND_STEM_UP, /* FT_Bool */
PS_DICT_MIN_FEATURE, /* FT_Short */
PS_DICT_LEN_IV, /* FT_Int */
PS_DICT_PASSWORD, /* FT_Long */
PS_DICT_LANGUAGE_GROUP, /* FT_Long */
/* conventionally in the font FontInfo dictionary */
PS_DICT_VERSION, /* FT_String* */
PS_DICT_NOTICE, /* FT_String* */
PS_DICT_FULL_NAME, /* FT_String* */
PS_DICT_FAMILY_NAME, /* FT_String* */
PS_DICT_WEIGHT, /* FT_String* */
PS_DICT_IS_FIXED_PITCH, /* FT_Bool */
PS_DICT_UNDERLINE_POSITION, /* FT_Short */
PS_DICT_UNDERLINE_THICKNESS, /* FT_UShort */
PS_DICT_FS_TYPE, /* FT_UShort */
PS_DICT_ITALIC_ANGLE, /* FT_Long */
PS_DICT_MAX = PS_DICT_ITALIC_ANGLE
} PS_Dict_Keys;
/************************************************************************
*
* @function:
* FT_Get_PS_Font_Value
*
* @description:
* Retrieve the value for the supplied key from a PostScript font.
*
* @input:
* face ::
* PostScript face handle.
*
* key ::
* An enumeration value representing the dictionary key to retrieve.
*
* idx ::
* For array values, this specifies the index to be returned.
*
* value ::
* A pointer to memory into which to write the value.
*
* valen_len ::
* The size, in bytes, of the memory supplied for the value.
*
* @output:
* value ::
* The value matching the above key, if it exists.
*
* @return:
* The amount of memory (in bytes) required to hold the requested
* value (if it exists, -1 otherwise).
*
* @note:
* The values returned are not pointers into the internal structures of
* the face, but are `fresh' copies, so that the memory containing them
* belongs to the calling application. This also enforces the
* `read-only' nature of these values, i.e., this function cannot be
* used to manipulate the face.
*
* `value' is a void pointer because the values returned can be of
* various types.
*
* If either `value' is NULL or `value_len' is too small, just the
* required memory size for the requested entry is returned.
*
* The `idx' parameter is used, not only to retrieve elements of, for
* example, the FontMatrix or FontBBox, but also to retrieve name keys
* from the CharStrings dictionary, and the charstrings themselves. It
* is ignored for atomic values.
*
* PS_DICT_BLUE_SCALE returns a value that is scaled up by 1000. To
* get the value as in the font stream, you need to divide by
* 65536000.0 (to remove the FT_Fixed scale, and the x1000 scale).
*
* IMPORTANT: Only key/value pairs read by the FreeType interpreter can
* be retrieved. So, for example, PostScript procedures such as NP,
* ND, and RD are not available. Arbitrary keys are, obviously, not be
* available either.
*
* If the font's format is not PostScript-based, this function returns
* the `FT_Err_Invalid_Argument' error code.
*
*/
FT_EXPORT( FT_Long )
FT_Get_PS_Font_Value( FT_Face face,
PS_Dict_Keys key,
FT_UInt idx,
void *value,
FT_Long value_len );
/* */
FT_END_HEADER
#endif /* __T1TABLES_H__ */
/* END */
| YifuLiu/AliOS-Things | components/freetype/include/t1tables.h | C | apache-2.0 | 27,036 |
/***************************************************************************/
/* */
/* ttnameid.h */
/* */
/* TrueType name ID definitions (specification only). */
/* */
/* Copyright 1996-2004, 2006-2008, 2012, 2013 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. */
/* */
/***************************************************************************/
#ifndef __TTNAMEID_H__
#define __TTNAMEID_H__
#include <ft2build.h>
FT_BEGIN_HEADER
/*************************************************************************/
/* */
/* <Section> */
/* truetype_tables */
/* */
/*************************************************************************/
/* */
/* Possible values for the `platform' identifier code in the name */
/* records of the TTF `name' table. */
/* */
/*************************************************************************/
/***********************************************************************
*
* @enum:
* TT_PLATFORM_XXX
*
* @description:
* A list of valid values for the `platform_id' identifier code in
* @FT_CharMapRec and @FT_SfntName structures.
*
* @values:
* TT_PLATFORM_APPLE_UNICODE ::
* Used by Apple to indicate a Unicode character map and/or name entry.
* See @TT_APPLE_ID_XXX for corresponding `encoding_id' values. Note
* that name entries in this format are coded as big-endian UCS-2
* character codes _only_.
*
* TT_PLATFORM_MACINTOSH ::
* Used by Apple to indicate a MacOS-specific charmap and/or name entry.
* See @TT_MAC_ID_XXX for corresponding `encoding_id' values. Note that
* most TrueType fonts contain an Apple roman charmap to be usable on
* MacOS systems (even if they contain a Microsoft charmap as well).
*
* TT_PLATFORM_ISO ::
* This value was used to specify ISO/IEC 10646 charmaps. It is however
* now deprecated. See @TT_ISO_ID_XXX for a list of corresponding
* `encoding_id' values.
*
* TT_PLATFORM_MICROSOFT ::
* Used by Microsoft to indicate Windows-specific charmaps. See
* @TT_MS_ID_XXX for a list of corresponding `encoding_id' values.
* Note that most fonts contain a Unicode charmap using
* (TT_PLATFORM_MICROSOFT, @TT_MS_ID_UNICODE_CS).
*
* TT_PLATFORM_CUSTOM ::
* Used to indicate application-specific charmaps.
*
* TT_PLATFORM_ADOBE ::
* This value isn't part of any font format specification, but is used
* by FreeType to report Adobe-specific charmaps in an @FT_CharMapRec
* structure. See @TT_ADOBE_ID_XXX.
*/
#define TT_PLATFORM_APPLE_UNICODE 0
#define TT_PLATFORM_MACINTOSH 1
#define TT_PLATFORM_ISO 2 /* deprecated */
#define TT_PLATFORM_MICROSOFT 3
#define TT_PLATFORM_CUSTOM 4
#define TT_PLATFORM_ADOBE 7 /* artificial */
/***********************************************************************
*
* @enum:
* TT_APPLE_ID_XXX
*
* @description:
* A list of valid values for the `encoding_id' for
* @TT_PLATFORM_APPLE_UNICODE charmaps and name entries.
*
* @values:
* TT_APPLE_ID_DEFAULT ::
* Unicode version 1.0.
*
* TT_APPLE_ID_UNICODE_1_1 ::
* Unicode 1.1; specifies Hangul characters starting at U+34xx.
*
* TT_APPLE_ID_ISO_10646 ::
* Deprecated (identical to preceding).
*
* TT_APPLE_ID_UNICODE_2_0 ::
* Unicode 2.0 and beyond (UTF-16 BMP only).
*
* TT_APPLE_ID_UNICODE_32 ::
* Unicode 3.1 and beyond, using UTF-32.
*
* TT_APPLE_ID_VARIANT_SELECTOR ::
* From Adobe, not Apple. Not a normal cmap. Specifies variations
* on a real cmap.
*/
#define TT_APPLE_ID_DEFAULT 0 /* Unicode 1.0 */
#define TT_APPLE_ID_UNICODE_1_1 1 /* specify Hangul at U+34xx */
#define TT_APPLE_ID_ISO_10646 2 /* deprecated */
#define TT_APPLE_ID_UNICODE_2_0 3 /* or later */
#define TT_APPLE_ID_UNICODE_32 4 /* 2.0 or later, full repertoire */
#define TT_APPLE_ID_VARIANT_SELECTOR 5 /* variation selector data */
/***********************************************************************
*
* @enum:
* TT_MAC_ID_XXX
*
* @description:
* A list of valid values for the `encoding_id' for
* @TT_PLATFORM_MACINTOSH charmaps and name entries.
*
* @values:
* TT_MAC_ID_ROMAN ::
* TT_MAC_ID_JAPANESE ::
* TT_MAC_ID_TRADITIONAL_CHINESE ::
* TT_MAC_ID_KOREAN ::
* TT_MAC_ID_ARABIC ::
* TT_MAC_ID_HEBREW ::
* TT_MAC_ID_GREEK ::
* TT_MAC_ID_RUSSIAN ::
* TT_MAC_ID_RSYMBOL ::
* TT_MAC_ID_DEVANAGARI ::
* TT_MAC_ID_GURMUKHI ::
* TT_MAC_ID_GUJARATI ::
* TT_MAC_ID_ORIYA ::
* TT_MAC_ID_BENGALI ::
* TT_MAC_ID_TAMIL ::
* TT_MAC_ID_TELUGU ::
* TT_MAC_ID_KANNADA ::
* TT_MAC_ID_MALAYALAM ::
* TT_MAC_ID_SINHALESE ::
* TT_MAC_ID_BURMESE ::
* TT_MAC_ID_KHMER ::
* TT_MAC_ID_THAI ::
* TT_MAC_ID_LAOTIAN ::
* TT_MAC_ID_GEORGIAN ::
* TT_MAC_ID_ARMENIAN ::
* TT_MAC_ID_MALDIVIAN ::
* TT_MAC_ID_SIMPLIFIED_CHINESE ::
* TT_MAC_ID_TIBETAN ::
* TT_MAC_ID_MONGOLIAN ::
* TT_MAC_ID_GEEZ ::
* TT_MAC_ID_SLAVIC ::
* TT_MAC_ID_VIETNAMESE ::
* TT_MAC_ID_SINDHI ::
* TT_MAC_ID_UNINTERP ::
*/
#define TT_MAC_ID_ROMAN 0
#define TT_MAC_ID_JAPANESE 1
#define TT_MAC_ID_TRADITIONAL_CHINESE 2
#define TT_MAC_ID_KOREAN 3
#define TT_MAC_ID_ARABIC 4
#define TT_MAC_ID_HEBREW 5
#define TT_MAC_ID_GREEK 6
#define TT_MAC_ID_RUSSIAN 7
#define TT_MAC_ID_RSYMBOL 8
#define TT_MAC_ID_DEVANAGARI 9
#define TT_MAC_ID_GURMUKHI 10
#define TT_MAC_ID_GUJARATI 11
#define TT_MAC_ID_ORIYA 12
#define TT_MAC_ID_BENGALI 13
#define TT_MAC_ID_TAMIL 14
#define TT_MAC_ID_TELUGU 15
#define TT_MAC_ID_KANNADA 16
#define TT_MAC_ID_MALAYALAM 17
#define TT_MAC_ID_SINHALESE 18
#define TT_MAC_ID_BURMESE 19
#define TT_MAC_ID_KHMER 20
#define TT_MAC_ID_THAI 21
#define TT_MAC_ID_LAOTIAN 22
#define TT_MAC_ID_GEORGIAN 23
#define TT_MAC_ID_ARMENIAN 24
#define TT_MAC_ID_MALDIVIAN 25
#define TT_MAC_ID_SIMPLIFIED_CHINESE 25
#define TT_MAC_ID_TIBETAN 26
#define TT_MAC_ID_MONGOLIAN 27
#define TT_MAC_ID_GEEZ 28
#define TT_MAC_ID_SLAVIC 29
#define TT_MAC_ID_VIETNAMESE 30
#define TT_MAC_ID_SINDHI 31
#define TT_MAC_ID_UNINTERP 32
/***********************************************************************
*
* @enum:
* TT_ISO_ID_XXX
*
* @description:
* A list of valid values for the `encoding_id' for
* @TT_PLATFORM_ISO charmaps and name entries.
*
* Their use is now deprecated.
*
* @values:
* TT_ISO_ID_7BIT_ASCII ::
* ASCII.
* TT_ISO_ID_10646 ::
* ISO/10646.
* TT_ISO_ID_8859_1 ::
* Also known as Latin-1.
*/
#define TT_ISO_ID_7BIT_ASCII 0
#define TT_ISO_ID_10646 1
#define TT_ISO_ID_8859_1 2
/***********************************************************************
*
* @enum:
* TT_MS_ID_XXX
*
* @description:
* A list of valid values for the `encoding_id' for
* @TT_PLATFORM_MICROSOFT charmaps and name entries.
*
* @values:
* TT_MS_ID_SYMBOL_CS ::
* Corresponds to Microsoft symbol encoding. See
* @FT_ENCODING_MS_SYMBOL.
*
* TT_MS_ID_UNICODE_CS ::
* Corresponds to a Microsoft WGL4 charmap, matching Unicode. See
* @FT_ENCODING_UNICODE.
*
* TT_MS_ID_SJIS ::
* Corresponds to SJIS Japanese encoding. See @FT_ENCODING_SJIS.
*
* TT_MS_ID_GB2312 ::
* Corresponds to Simplified Chinese as used in Mainland China. See
* @FT_ENCODING_GB2312.
*
* TT_MS_ID_BIG_5 ::
* Corresponds to Traditional Chinese as used in Taiwan and Hong Kong.
* See @FT_ENCODING_BIG5.
*
* TT_MS_ID_WANSUNG ::
* Corresponds to Korean Wansung encoding. See @FT_ENCODING_WANSUNG.
*
* TT_MS_ID_JOHAB ::
* Corresponds to Johab encoding. See @FT_ENCODING_JOHAB.
*
* TT_MS_ID_UCS_4 ::
* Corresponds to UCS-4 or UTF-32 charmaps. This has been added to
* the OpenType specification version 1.4 (mid-2001.)
*/
#define TT_MS_ID_SYMBOL_CS 0
#define TT_MS_ID_UNICODE_CS 1
#define TT_MS_ID_SJIS 2
#define TT_MS_ID_GB2312 3
#define TT_MS_ID_BIG_5 4
#define TT_MS_ID_WANSUNG 5
#define TT_MS_ID_JOHAB 6
#define TT_MS_ID_UCS_4 10
/***********************************************************************
*
* @enum:
* TT_ADOBE_ID_XXX
*
* @description:
* A list of valid values for the `encoding_id' for
* @TT_PLATFORM_ADOBE charmaps. This is a FreeType-specific extension!
*
* @values:
* TT_ADOBE_ID_STANDARD ::
* Adobe standard encoding.
* TT_ADOBE_ID_EXPERT ::
* Adobe expert encoding.
* TT_ADOBE_ID_CUSTOM ::
* Adobe custom encoding.
* TT_ADOBE_ID_LATIN_1 ::
* Adobe Latin~1 encoding.
*/
#define TT_ADOBE_ID_STANDARD 0
#define TT_ADOBE_ID_EXPERT 1
#define TT_ADOBE_ID_CUSTOM 2
#define TT_ADOBE_ID_LATIN_1 3
/*************************************************************************/
/* */
/* Possible values of the language identifier field in the name records */
/* of the TTF `name' table if the `platform' identifier code is */
/* TT_PLATFORM_MACINTOSH. These values are also used as return values */
/* for function @FT_Get_CMap_Language_ID. */
/* */
/* The canonical source for the Apple assigned Language ID's is at */
/* */
/* https://developer.apple.com/fonts/TTRefMan/RM06/Chap6name.html */
/* */
#define TT_MAC_LANGID_ENGLISH 0
#define TT_MAC_LANGID_FRENCH 1
#define TT_MAC_LANGID_GERMAN 2
#define TT_MAC_LANGID_ITALIAN 3
#define TT_MAC_LANGID_DUTCH 4
#define TT_MAC_LANGID_SWEDISH 5
#define TT_MAC_LANGID_SPANISH 6
#define TT_MAC_LANGID_DANISH 7
#define TT_MAC_LANGID_PORTUGUESE 8
#define TT_MAC_LANGID_NORWEGIAN 9
#define TT_MAC_LANGID_HEBREW 10
#define TT_MAC_LANGID_JAPANESE 11
#define TT_MAC_LANGID_ARABIC 12
#define TT_MAC_LANGID_FINNISH 13
#define TT_MAC_LANGID_GREEK 14
#define TT_MAC_LANGID_ICELANDIC 15
#define TT_MAC_LANGID_MALTESE 16
#define TT_MAC_LANGID_TURKISH 17
#define TT_MAC_LANGID_CROATIAN 18
#define TT_MAC_LANGID_CHINESE_TRADITIONAL 19
#define TT_MAC_LANGID_URDU 20
#define TT_MAC_LANGID_HINDI 21
#define TT_MAC_LANGID_THAI 22
#define TT_MAC_LANGID_KOREAN 23
#define TT_MAC_LANGID_LITHUANIAN 24
#define TT_MAC_LANGID_POLISH 25
#define TT_MAC_LANGID_HUNGARIAN 26
#define TT_MAC_LANGID_ESTONIAN 27
#define TT_MAC_LANGID_LETTISH 28
#define TT_MAC_LANGID_SAAMISK 29
#define TT_MAC_LANGID_FAEROESE 30
#define TT_MAC_LANGID_FARSI 31
#define TT_MAC_LANGID_RUSSIAN 32
#define TT_MAC_LANGID_CHINESE_SIMPLIFIED 33
#define TT_MAC_LANGID_FLEMISH 34
#define TT_MAC_LANGID_IRISH 35
#define TT_MAC_LANGID_ALBANIAN 36
#define TT_MAC_LANGID_ROMANIAN 37
#define TT_MAC_LANGID_CZECH 38
#define TT_MAC_LANGID_SLOVAK 39
#define TT_MAC_LANGID_SLOVENIAN 40
#define TT_MAC_LANGID_YIDDISH 41
#define TT_MAC_LANGID_SERBIAN 42
#define TT_MAC_LANGID_MACEDONIAN 43
#define TT_MAC_LANGID_BULGARIAN 44
#define TT_MAC_LANGID_UKRAINIAN 45
#define TT_MAC_LANGID_BYELORUSSIAN 46
#define TT_MAC_LANGID_UZBEK 47
#define TT_MAC_LANGID_KAZAKH 48
#define TT_MAC_LANGID_AZERBAIJANI 49
#define TT_MAC_LANGID_AZERBAIJANI_CYRILLIC_SCRIPT 49
#define TT_MAC_LANGID_AZERBAIJANI_ARABIC_SCRIPT 50
#define TT_MAC_LANGID_ARMENIAN 51
#define TT_MAC_LANGID_GEORGIAN 52
#define TT_MAC_LANGID_MOLDAVIAN 53
#define TT_MAC_LANGID_KIRGHIZ 54
#define TT_MAC_LANGID_TAJIKI 55
#define TT_MAC_LANGID_TURKMEN 56
#define TT_MAC_LANGID_MONGOLIAN 57
#define TT_MAC_LANGID_MONGOLIAN_MONGOLIAN_SCRIPT 57
#define TT_MAC_LANGID_MONGOLIAN_CYRILLIC_SCRIPT 58
#define TT_MAC_LANGID_PASHTO 59
#define TT_MAC_LANGID_KURDISH 60
#define TT_MAC_LANGID_KASHMIRI 61
#define TT_MAC_LANGID_SINDHI 62
#define TT_MAC_LANGID_TIBETAN 63
#define TT_MAC_LANGID_NEPALI 64
#define TT_MAC_LANGID_SANSKRIT 65
#define TT_MAC_LANGID_MARATHI 66
#define TT_MAC_LANGID_BENGALI 67
#define TT_MAC_LANGID_ASSAMESE 68
#define TT_MAC_LANGID_GUJARATI 69
#define TT_MAC_LANGID_PUNJABI 70
#define TT_MAC_LANGID_ORIYA 71
#define TT_MAC_LANGID_MALAYALAM 72
#define TT_MAC_LANGID_KANNADA 73
#define TT_MAC_LANGID_TAMIL 74
#define TT_MAC_LANGID_TELUGU 75
#define TT_MAC_LANGID_SINHALESE 76
#define TT_MAC_LANGID_BURMESE 77
#define TT_MAC_LANGID_KHMER 78
#define TT_MAC_LANGID_LAO 79
#define TT_MAC_LANGID_VIETNAMESE 80
#define TT_MAC_LANGID_INDONESIAN 81
#define TT_MAC_LANGID_TAGALOG 82
#define TT_MAC_LANGID_MALAY_ROMAN_SCRIPT 83
#define TT_MAC_LANGID_MALAY_ARABIC_SCRIPT 84
#define TT_MAC_LANGID_AMHARIC 85
#define TT_MAC_LANGID_TIGRINYA 86
#define TT_MAC_LANGID_GALLA 87
#define TT_MAC_LANGID_SOMALI 88
#define TT_MAC_LANGID_SWAHILI 89
#define TT_MAC_LANGID_RUANDA 90
#define TT_MAC_LANGID_RUNDI 91
#define TT_MAC_LANGID_CHEWA 92
#define TT_MAC_LANGID_MALAGASY 93
#define TT_MAC_LANGID_ESPERANTO 94
#define TT_MAC_LANGID_WELSH 128
#define TT_MAC_LANGID_BASQUE 129
#define TT_MAC_LANGID_CATALAN 130
#define TT_MAC_LANGID_LATIN 131
#define TT_MAC_LANGID_QUECHUA 132
#define TT_MAC_LANGID_GUARANI 133
#define TT_MAC_LANGID_AYMARA 134
#define TT_MAC_LANGID_TATAR 135
#define TT_MAC_LANGID_UIGHUR 136
#define TT_MAC_LANGID_DZONGKHA 137
#define TT_MAC_LANGID_JAVANESE 138
#define TT_MAC_LANGID_SUNDANESE 139
#if 0 /* these seem to be errors that have been dropped */
#define TT_MAC_LANGID_SCOTTISH_GAELIC 140
#define TT_MAC_LANGID_IRISH_GAELIC 141
#endif
/* The following codes are new as of 2000-03-10 */
#define TT_MAC_LANGID_GALICIAN 140
#define TT_MAC_LANGID_AFRIKAANS 141
#define TT_MAC_LANGID_BRETON 142
#define TT_MAC_LANGID_INUKTITUT 143
#define TT_MAC_LANGID_SCOTTISH_GAELIC 144
#define TT_MAC_LANGID_MANX_GAELIC 145
#define TT_MAC_LANGID_IRISH_GAELIC 146
#define TT_MAC_LANGID_TONGAN 147
#define TT_MAC_LANGID_GREEK_POLYTONIC 148
#define TT_MAC_LANGID_GREELANDIC 149
#define TT_MAC_LANGID_AZERBAIJANI_ROMAN_SCRIPT 150
/*************************************************************************/
/* */
/* Possible values of the language identifier field in the name records */
/* of the TTF `name' table if the `platform' identifier code is */
/* TT_PLATFORM_MICROSOFT. */
/* */
/* The canonical source for the MS assigned LCIDs is */
/* */
/* http://www.microsoft.com/globaldev/reference/lcid-all.mspx */
/* */
#define TT_MS_LANGID_ARABIC_GENERAL 0x0001
#define TT_MS_LANGID_ARABIC_SAUDI_ARABIA 0x0401
#define TT_MS_LANGID_ARABIC_IRAQ 0x0801
#define TT_MS_LANGID_ARABIC_EGYPT 0x0c01
#define TT_MS_LANGID_ARABIC_LIBYA 0x1001
#define TT_MS_LANGID_ARABIC_ALGERIA 0x1401
#define TT_MS_LANGID_ARABIC_MOROCCO 0x1801
#define TT_MS_LANGID_ARABIC_TUNISIA 0x1c01
#define TT_MS_LANGID_ARABIC_OMAN 0x2001
#define TT_MS_LANGID_ARABIC_YEMEN 0x2401
#define TT_MS_LANGID_ARABIC_SYRIA 0x2801
#define TT_MS_LANGID_ARABIC_JORDAN 0x2c01
#define TT_MS_LANGID_ARABIC_LEBANON 0x3001
#define TT_MS_LANGID_ARABIC_KUWAIT 0x3401
#define TT_MS_LANGID_ARABIC_UAE 0x3801
#define TT_MS_LANGID_ARABIC_BAHRAIN 0x3c01
#define TT_MS_LANGID_ARABIC_QATAR 0x4001
#define TT_MS_LANGID_BULGARIAN_BULGARIA 0x0402
#define TT_MS_LANGID_CATALAN_SPAIN 0x0403
#define TT_MS_LANGID_CHINESE_GENERAL 0x0004
#define TT_MS_LANGID_CHINESE_TAIWAN 0x0404
#define TT_MS_LANGID_CHINESE_PRC 0x0804
#define TT_MS_LANGID_CHINESE_HONG_KONG 0x0c04
#define TT_MS_LANGID_CHINESE_SINGAPORE 0x1004
#if 1 /* this looks like the correct value */
#define TT_MS_LANGID_CHINESE_MACAU 0x1404
#else /* but beware, Microsoft may change its mind...
the most recent Word reference has the following: */
#define TT_MS_LANGID_CHINESE_MACAU TT_MS_LANGID_CHINESE_HONG_KONG
#endif
#if 0 /* used only with .NET `cultures'; commented out */
#define TT_MS_LANGID_CHINESE_TRADITIONAL 0x7C04
#endif
#define TT_MS_LANGID_CZECH_CZECH_REPUBLIC 0x0405
#define TT_MS_LANGID_DANISH_DENMARK 0x0406
#define TT_MS_LANGID_GERMAN_GERMANY 0x0407
#define TT_MS_LANGID_GERMAN_SWITZERLAND 0x0807
#define TT_MS_LANGID_GERMAN_AUSTRIA 0x0c07
#define TT_MS_LANGID_GERMAN_LUXEMBOURG 0x1007
#define TT_MS_LANGID_GERMAN_LIECHTENSTEI 0x1407
#define TT_MS_LANGID_GREEK_GREECE 0x0408
/* don't ask what this one means... It is commented out currently. */
#if 0
#define TT_MS_LANGID_GREEK_GREECE2 0x2008
#endif
#define TT_MS_LANGID_ENGLISH_GENERAL 0x0009
#define TT_MS_LANGID_ENGLISH_UNITED_STATES 0x0409
#define TT_MS_LANGID_ENGLISH_UNITED_KINGDOM 0x0809
#define TT_MS_LANGID_ENGLISH_AUSTRALIA 0x0c09
#define TT_MS_LANGID_ENGLISH_CANADA 0x1009
#define TT_MS_LANGID_ENGLISH_NEW_ZEALAND 0x1409
#define TT_MS_LANGID_ENGLISH_IRELAND 0x1809
#define TT_MS_LANGID_ENGLISH_SOUTH_AFRICA 0x1c09
#define TT_MS_LANGID_ENGLISH_JAMAICA 0x2009
#define TT_MS_LANGID_ENGLISH_CARIBBEAN 0x2409
#define TT_MS_LANGID_ENGLISH_BELIZE 0x2809
#define TT_MS_LANGID_ENGLISH_TRINIDAD 0x2c09
#define TT_MS_LANGID_ENGLISH_ZIMBABWE 0x3009
#define TT_MS_LANGID_ENGLISH_PHILIPPINES 0x3409
#define TT_MS_LANGID_ENGLISH_INDONESIA 0x3809
#define TT_MS_LANGID_ENGLISH_HONG_KONG 0x3c09
#define TT_MS_LANGID_ENGLISH_INDIA 0x4009
#define TT_MS_LANGID_ENGLISH_MALAYSIA 0x4409
#define TT_MS_LANGID_ENGLISH_SINGAPORE 0x4809
#define TT_MS_LANGID_SPANISH_SPAIN_TRADITIONAL_SORT 0x040a
#define TT_MS_LANGID_SPANISH_MEXICO 0x080a
#define TT_MS_LANGID_SPANISH_SPAIN_INTERNATIONAL_SORT 0x0c0a
#define TT_MS_LANGID_SPANISH_GUATEMALA 0x100a
#define TT_MS_LANGID_SPANISH_COSTA_RICA 0x140a
#define TT_MS_LANGID_SPANISH_PANAMA 0x180a
#define TT_MS_LANGID_SPANISH_DOMINICAN_REPUBLIC 0x1c0a
#define TT_MS_LANGID_SPANISH_VENEZUELA 0x200a
#define TT_MS_LANGID_SPANISH_COLOMBIA 0x240a
#define TT_MS_LANGID_SPANISH_PERU 0x280a
#define TT_MS_LANGID_SPANISH_ARGENTINA 0x2c0a
#define TT_MS_LANGID_SPANISH_ECUADOR 0x300a
#define TT_MS_LANGID_SPANISH_CHILE 0x340a
#define TT_MS_LANGID_SPANISH_URUGUAY 0x380a
#define TT_MS_LANGID_SPANISH_PARAGUAY 0x3c0a
#define TT_MS_LANGID_SPANISH_BOLIVIA 0x400a
#define TT_MS_LANGID_SPANISH_EL_SALVADOR 0x440a
#define TT_MS_LANGID_SPANISH_HONDURAS 0x480a
#define TT_MS_LANGID_SPANISH_NICARAGUA 0x4c0a
#define TT_MS_LANGID_SPANISH_PUERTO_RICO 0x500a
#define TT_MS_LANGID_SPANISH_UNITED_STATES 0x540a
/* The following ID blatantly violate MS specs by using a */
/* sublanguage > 0x1F. */
#define TT_MS_LANGID_SPANISH_LATIN_AMERICA 0xE40aU
#define TT_MS_LANGID_FINNISH_FINLAND 0x040b
#define TT_MS_LANGID_FRENCH_FRANCE 0x040c
#define TT_MS_LANGID_FRENCH_BELGIUM 0x080c
#define TT_MS_LANGID_FRENCH_CANADA 0x0c0c
#define TT_MS_LANGID_FRENCH_SWITZERLAND 0x100c
#define TT_MS_LANGID_FRENCH_LUXEMBOURG 0x140c
#define TT_MS_LANGID_FRENCH_MONACO 0x180c
#define TT_MS_LANGID_FRENCH_WEST_INDIES 0x1c0c
#define TT_MS_LANGID_FRENCH_REUNION 0x200c
#define TT_MS_LANGID_FRENCH_CONGO 0x240c
/* which was formerly: */
#define TT_MS_LANGID_FRENCH_ZAIRE TT_MS_LANGID_FRENCH_CONGO
#define TT_MS_LANGID_FRENCH_SENEGAL 0x280c
#define TT_MS_LANGID_FRENCH_CAMEROON 0x2c0c
#define TT_MS_LANGID_FRENCH_COTE_D_IVOIRE 0x300c
#define TT_MS_LANGID_FRENCH_MALI 0x340c
#define TT_MS_LANGID_FRENCH_MOROCCO 0x380c
#define TT_MS_LANGID_FRENCH_HAITI 0x3c0c
/* and another violation of the spec (see 0xE40aU) */
#define TT_MS_LANGID_FRENCH_NORTH_AFRICA 0xE40cU
#define TT_MS_LANGID_HEBREW_ISRAEL 0x040d
#define TT_MS_LANGID_HUNGARIAN_HUNGARY 0x040e
#define TT_MS_LANGID_ICELANDIC_ICELAND 0x040f
#define TT_MS_LANGID_ITALIAN_ITALY 0x0410
#define TT_MS_LANGID_ITALIAN_SWITZERLAND 0x0810
#define TT_MS_LANGID_JAPANESE_JAPAN 0x0411
#define TT_MS_LANGID_KOREAN_EXTENDED_WANSUNG_KOREA 0x0412
#define TT_MS_LANGID_KOREAN_JOHAB_KOREA 0x0812
#define TT_MS_LANGID_DUTCH_NETHERLANDS 0x0413
#define TT_MS_LANGID_DUTCH_BELGIUM 0x0813
#define TT_MS_LANGID_NORWEGIAN_NORWAY_BOKMAL 0x0414
#define TT_MS_LANGID_NORWEGIAN_NORWAY_NYNORSK 0x0814
#define TT_MS_LANGID_POLISH_POLAND 0x0415
#define TT_MS_LANGID_PORTUGUESE_BRAZIL 0x0416
#define TT_MS_LANGID_PORTUGUESE_PORTUGAL 0x0816
#define TT_MS_LANGID_RHAETO_ROMANIC_SWITZERLAND 0x0417
#define TT_MS_LANGID_ROMANIAN_ROMANIA 0x0418
#define TT_MS_LANGID_MOLDAVIAN_MOLDAVIA 0x0818
#define TT_MS_LANGID_RUSSIAN_RUSSIA 0x0419
#define TT_MS_LANGID_RUSSIAN_MOLDAVIA 0x0819
#define TT_MS_LANGID_CROATIAN_CROATIA 0x041a
#define TT_MS_LANGID_SERBIAN_SERBIA_LATIN 0x081a
#define TT_MS_LANGID_SERBIAN_SERBIA_CYRILLIC 0x0c1a
#if 0 /* this used to be this value, but it looks like we were wrong */
#define TT_MS_LANGID_BOSNIAN_BOSNIA_HERZEGOVINA 0x101a
#else /* current sources say */
#define TT_MS_LANGID_CROATIAN_BOSNIA_HERZEGOVINA 0x101a
#define TT_MS_LANGID_BOSNIAN_BOSNIA_HERZEGOVINA 0x141a
/* and XPsp2 Platform SDK added (2004-07-26) */
/* Names are shortened to be significant within 40 chars. */
#define TT_MS_LANGID_SERBIAN_BOSNIA_HERZ_LATIN 0x181a
#define TT_MS_LANGID_SERBIAN_BOSNIA_HERZ_CYRILLIC 0x181a
#endif
#define TT_MS_LANGID_SLOVAK_SLOVAKIA 0x041b
#define TT_MS_LANGID_ALBANIAN_ALBANIA 0x041c
#define TT_MS_LANGID_SWEDISH_SWEDEN 0x041d
#define TT_MS_LANGID_SWEDISH_FINLAND 0x081d
#define TT_MS_LANGID_THAI_THAILAND 0x041e
#define TT_MS_LANGID_TURKISH_TURKEY 0x041f
#define TT_MS_LANGID_URDU_PAKISTAN 0x0420
#define TT_MS_LANGID_URDU_INDIA 0x0820
#define TT_MS_LANGID_INDONESIAN_INDONESIA 0x0421
#define TT_MS_LANGID_UKRAINIAN_UKRAINE 0x0422
#define TT_MS_LANGID_BELARUSIAN_BELARUS 0x0423
#define TT_MS_LANGID_SLOVENE_SLOVENIA 0x0424
#define TT_MS_LANGID_ESTONIAN_ESTONIA 0x0425
#define TT_MS_LANGID_LATVIAN_LATVIA 0x0426
#define TT_MS_LANGID_LITHUANIAN_LITHUANIA 0x0427
#define TT_MS_LANGID_CLASSIC_LITHUANIAN_LITHUANIA 0x0827
#define TT_MS_LANGID_TAJIK_TAJIKISTAN 0x0428
#define TT_MS_LANGID_FARSI_IRAN 0x0429
#define TT_MS_LANGID_VIETNAMESE_VIET_NAM 0x042a
#define TT_MS_LANGID_ARMENIAN_ARMENIA 0x042b
#define TT_MS_LANGID_AZERI_AZERBAIJAN_LATIN 0x042c
#define TT_MS_LANGID_AZERI_AZERBAIJAN_CYRILLIC 0x082c
#define TT_MS_LANGID_BASQUE_SPAIN 0x042d
#define TT_MS_LANGID_SORBIAN_GERMANY 0x042e
#define TT_MS_LANGID_MACEDONIAN_MACEDONIA 0x042f
#define TT_MS_LANGID_SUTU_SOUTH_AFRICA 0x0430
#define TT_MS_LANGID_TSONGA_SOUTH_AFRICA 0x0431
#define TT_MS_LANGID_TSWANA_SOUTH_AFRICA 0x0432
#define TT_MS_LANGID_VENDA_SOUTH_AFRICA 0x0433
#define TT_MS_LANGID_XHOSA_SOUTH_AFRICA 0x0434
#define TT_MS_LANGID_ZULU_SOUTH_AFRICA 0x0435
#define TT_MS_LANGID_AFRIKAANS_SOUTH_AFRICA 0x0436
#define TT_MS_LANGID_GEORGIAN_GEORGIA 0x0437
#define TT_MS_LANGID_FAEROESE_FAEROE_ISLANDS 0x0438
#define TT_MS_LANGID_HINDI_INDIA 0x0439
#define TT_MS_LANGID_MALTESE_MALTA 0x043a
/* Added by XPsp2 Platform SDK (2004-07-26) */
#define TT_MS_LANGID_SAMI_NORTHERN_NORWAY 0x043b
#define TT_MS_LANGID_SAMI_NORTHERN_SWEDEN 0x083b
#define TT_MS_LANGID_SAMI_NORTHERN_FINLAND 0x0C3b
#define TT_MS_LANGID_SAMI_LULE_NORWAY 0x103b
#define TT_MS_LANGID_SAMI_LULE_SWEDEN 0x143b
#define TT_MS_LANGID_SAMI_SOUTHERN_NORWAY 0x183b
#define TT_MS_LANGID_SAMI_SOUTHERN_SWEDEN 0x1C3b
#define TT_MS_LANGID_SAMI_SKOLT_FINLAND 0x203b
#define TT_MS_LANGID_SAMI_INARI_FINLAND 0x243b
/* ... and we also keep our old identifier... */
#define TT_MS_LANGID_SAAMI_LAPONIA 0x043b
#if 0 /* this seems to be a previous inversion */
#define TT_MS_LANGID_IRISH_GAELIC_IRELAND 0x043c
#define TT_MS_LANGID_SCOTTISH_GAELIC_UNITED_KINGDOM 0x083c
#else
#define TT_MS_LANGID_SCOTTISH_GAELIC_UNITED_KINGDOM 0x083c
#define TT_MS_LANGID_IRISH_GAELIC_IRELAND 0x043c
#endif
#define TT_MS_LANGID_YIDDISH_GERMANY 0x043d
#define TT_MS_LANGID_MALAY_MALAYSIA 0x043e
#define TT_MS_LANGID_MALAY_BRUNEI_DARUSSALAM 0x083e
#define TT_MS_LANGID_KAZAK_KAZAKSTAN 0x043f
#define TT_MS_LANGID_KIRGHIZ_KIRGHIZSTAN /* Cyrillic*/ 0x0440
/* alias declared in Windows 2000 */
#define TT_MS_LANGID_KIRGHIZ_KIRGHIZ_REPUBLIC \
TT_MS_LANGID_KIRGHIZ_KIRGHIZSTAN
#define TT_MS_LANGID_SWAHILI_KENYA 0x0441
#define TT_MS_LANGID_TURKMEN_TURKMENISTAN 0x0442
#define TT_MS_LANGID_UZBEK_UZBEKISTAN_LATIN 0x0443
#define TT_MS_LANGID_UZBEK_UZBEKISTAN_CYRILLIC 0x0843
#define TT_MS_LANGID_TATAR_TATARSTAN 0x0444
#define TT_MS_LANGID_BENGALI_INDIA 0x0445
#define TT_MS_LANGID_BENGALI_BANGLADESH 0x0845
#define TT_MS_LANGID_PUNJABI_INDIA 0x0446
#define TT_MS_LANGID_PUNJABI_ARABIC_PAKISTAN 0x0846
#define TT_MS_LANGID_GUJARATI_INDIA 0x0447
#define TT_MS_LANGID_ORIYA_INDIA 0x0448
#define TT_MS_LANGID_TAMIL_INDIA 0x0449
#define TT_MS_LANGID_TELUGU_INDIA 0x044a
#define TT_MS_LANGID_KANNADA_INDIA 0x044b
#define TT_MS_LANGID_MALAYALAM_INDIA 0x044c
#define TT_MS_LANGID_ASSAMESE_INDIA 0x044d
#define TT_MS_LANGID_MARATHI_INDIA 0x044e
#define TT_MS_LANGID_SANSKRIT_INDIA 0x044f
#define TT_MS_LANGID_MONGOLIAN_MONGOLIA /* Cyrillic */ 0x0450
#define TT_MS_LANGID_MONGOLIAN_MONGOLIA_MONGOLIAN 0x0850
#define TT_MS_LANGID_TIBETAN_CHINA 0x0451
/* Don't use the next constant! It has */
/* (1) the wrong spelling (Dzonghka) */
/* (2) Microsoft doesn't officially define it -- */
/* at least it is not in the List of Local */
/* ID Values. */
/* (3) Dzongkha is not the same language as */
/* Tibetan, so merging it is wrong anyway. */
/* */
/* TT_MS_LANGID_TIBETAN_BHUTAN is correct, BTW. */
#define TT_MS_LANGID_DZONGHKA_BHUTAN 0x0851
#if 0
/* the following used to be defined */
#define TT_MS_LANGID_TIBETAN_BHUTAN 0x0451
/* ... but it was changed; */
#else
/* So we will continue to #define it, but with the correct value */
#define TT_MS_LANGID_TIBETAN_BHUTAN TT_MS_LANGID_DZONGHKA_BHUTAN
#endif
#define TT_MS_LANGID_WELSH_WALES 0x0452
#define TT_MS_LANGID_KHMER_CAMBODIA 0x0453
#define TT_MS_LANGID_LAO_LAOS 0x0454
#define TT_MS_LANGID_BURMESE_MYANMAR 0x0455
#define TT_MS_LANGID_GALICIAN_SPAIN 0x0456
#define TT_MS_LANGID_KONKANI_INDIA 0x0457
#define TT_MS_LANGID_MANIPURI_INDIA /* Bengali */ 0x0458
#define TT_MS_LANGID_SINDHI_INDIA /* Arabic */ 0x0459
#define TT_MS_LANGID_SINDHI_PAKISTAN 0x0859
/* Missing a LCID for Sindhi in Devanagari script */
#define TT_MS_LANGID_SYRIAC_SYRIA 0x045a
#define TT_MS_LANGID_SINHALESE_SRI_LANKA 0x045b
#define TT_MS_LANGID_CHEROKEE_UNITED_STATES 0x045c
#define TT_MS_LANGID_INUKTITUT_CANADA 0x045d
#define TT_MS_LANGID_AMHARIC_ETHIOPIA 0x045e
#define TT_MS_LANGID_TAMAZIGHT_MOROCCO /* Arabic */ 0x045f
#define TT_MS_LANGID_TAMAZIGHT_MOROCCO_LATIN 0x085f
/* Missing a LCID for Tifinagh script */
#define TT_MS_LANGID_KASHMIRI_PAKISTAN /* Arabic */ 0x0460
/* Spelled this way by XPsp2 Platform SDK (2004-07-26) */
/* script is yet unclear... might be Arabic, Nagari or Sharada */
#define TT_MS_LANGID_KASHMIRI_SASIA 0x0860
/* ... and aliased (by MS) for compatibility reasons. */
#define TT_MS_LANGID_KASHMIRI_INDIA TT_MS_LANGID_KASHMIRI_SASIA
#define TT_MS_LANGID_NEPALI_NEPAL 0x0461
#define TT_MS_LANGID_NEPALI_INDIA 0x0861
#define TT_MS_LANGID_FRISIAN_NETHERLANDS 0x0462
#define TT_MS_LANGID_PASHTO_AFGHANISTAN 0x0463
#define TT_MS_LANGID_FILIPINO_PHILIPPINES 0x0464
#define TT_MS_LANGID_DHIVEHI_MALDIVES 0x0465
/* alias declared in Windows 2000 */
#define TT_MS_LANGID_DIVEHI_MALDIVES TT_MS_LANGID_DHIVEHI_MALDIVES
#define TT_MS_LANGID_EDO_NIGERIA 0x0466
#define TT_MS_LANGID_FULFULDE_NIGERIA 0x0467
#define TT_MS_LANGID_HAUSA_NIGERIA 0x0468
#define TT_MS_LANGID_IBIBIO_NIGERIA 0x0469
#define TT_MS_LANGID_YORUBA_NIGERIA 0x046a
#define TT_MS_LANGID_QUECHUA_BOLIVIA 0x046b
#define TT_MS_LANGID_QUECHUA_ECUADOR 0x086b
#define TT_MS_LANGID_QUECHUA_PERU 0x0c6b
#define TT_MS_LANGID_SEPEDI_SOUTH_AFRICA 0x046c
/* Also spelled by XPsp2 Platform SDK (2004-07-26) */
#define TT_MS_LANGID_SOTHO_SOUTHERN_SOUTH_AFRICA \
TT_MS_LANGID_SEPEDI_SOUTH_AFRICA
/* language codes 0x046d, 0x046e and 0x046f are (still) unknown. */
#define TT_MS_LANGID_IGBO_NIGERIA 0x0470
#define TT_MS_LANGID_KANURI_NIGERIA 0x0471
#define TT_MS_LANGID_OROMO_ETHIOPIA 0x0472
#define TT_MS_LANGID_TIGRIGNA_ETHIOPIA 0x0473
#define TT_MS_LANGID_TIGRIGNA_ERYTHREA 0x0873
/* also spelled in the `Passport SDK' list as: */
#define TT_MS_LANGID_TIGRIGNA_ERYTREA TT_MS_LANGID_TIGRIGNA_ERYTHREA
#define TT_MS_LANGID_GUARANI_PARAGUAY 0x0474
#define TT_MS_LANGID_HAWAIIAN_UNITED_STATES 0x0475
#define TT_MS_LANGID_LATIN 0x0476
#define TT_MS_LANGID_SOMALI_SOMALIA 0x0477
/* Note: Yi does not have a (proper) ISO 639-2 code, since it is mostly */
/* not written (but OTOH the peculiar writing system is worth */
/* studying). */
#define TT_MS_LANGID_YI_CHINA 0x0478
#define TT_MS_LANGID_PAPIAMENTU_NETHERLANDS_ANTILLES 0x0479
/* language codes from 0x047a to 0x047f are (still) unknown. */
#define TT_MS_LANGID_UIGHUR_CHINA 0x0480
#define TT_MS_LANGID_MAORI_NEW_ZEALAND 0x0481
#if 0 /* not deemed useful for fonts */
#define TT_MS_LANGID_HUMAN_INTERFACE_DEVICE 0x04ff
#endif
/*************************************************************************/
/* */
/* Possible values of the `name' identifier field in the name records of */
/* the TTF `name' table. These values are platform independent. */
/* */
#define TT_NAME_ID_COPYRIGHT 0
#define TT_NAME_ID_FONT_FAMILY 1
#define TT_NAME_ID_FONT_SUBFAMILY 2
#define TT_NAME_ID_UNIQUE_ID 3
#define TT_NAME_ID_FULL_NAME 4
#define TT_NAME_ID_VERSION_STRING 5
#define TT_NAME_ID_PS_NAME 6
#define TT_NAME_ID_TRADEMARK 7
/* the following values are from the OpenType spec */
#define TT_NAME_ID_MANUFACTURER 8
#define TT_NAME_ID_DESIGNER 9
#define TT_NAME_ID_DESCRIPTION 10
#define TT_NAME_ID_VENDOR_URL 11
#define TT_NAME_ID_DESIGNER_URL 12
#define TT_NAME_ID_LICENSE 13
#define TT_NAME_ID_LICENSE_URL 14
/* number 15 is reserved */
#define TT_NAME_ID_PREFERRED_FAMILY 16
#define TT_NAME_ID_PREFERRED_SUBFAMILY 17
#define TT_NAME_ID_MAC_FULL_NAME 18
/* The following code is new as of 2000-01-21 */
#define TT_NAME_ID_SAMPLE_TEXT 19
/* This is new in OpenType 1.3 */
#define TT_NAME_ID_CID_FINDFONT_NAME 20
/* This is new in OpenType 1.5 */
#define TT_NAME_ID_WWS_FAMILY 21
#define TT_NAME_ID_WWS_SUBFAMILY 22
/*************************************************************************/
/* */
/* Bit mask values for the Unicode Ranges from the TTF `OS2 ' table. */
/* */
/* Updated 08-Nov-2008. */
/* */
/* Bit 0 Basic Latin */
#define TT_UCR_BASIC_LATIN (1L << 0) /* U+0020-U+007E */
/* Bit 1 C1 Controls and Latin-1 Supplement */
#define TT_UCR_LATIN1_SUPPLEMENT (1L << 1) /* U+0080-U+00FF */
/* Bit 2 Latin Extended-A */
#define TT_UCR_LATIN_EXTENDED_A (1L << 2) /* U+0100-U+017F */
/* Bit 3 Latin Extended-B */
#define TT_UCR_LATIN_EXTENDED_B (1L << 3) /* U+0180-U+024F */
/* Bit 4 IPA Extensions */
/* Phonetic Extensions */
/* Phonetic Extensions Supplement */
#define TT_UCR_IPA_EXTENSIONS (1L << 4) /* U+0250-U+02AF */
/* U+1D00-U+1D7F */
/* U+1D80-U+1DBF */
/* Bit 5 Spacing Modifier Letters */
/* Modifier Tone Letters */
#define TT_UCR_SPACING_MODIFIER (1L << 5) /* U+02B0-U+02FF */
/* U+A700-U+A71F */
/* Bit 6 Combining Diacritical Marks */
/* Combining Diacritical Marks Supplement */
#define TT_UCR_COMBINING_DIACRITICS (1L << 6) /* U+0300-U+036F */
/* U+1DC0-U+1DFF */
/* Bit 7 Greek and Coptic */
#define TT_UCR_GREEK (1L << 7) /* U+0370-U+03FF */
/* Bit 8 Coptic */
#define TT_UCR_COPTIC (1L << 8) /* U+2C80-U+2CFF */
/* Bit 9 Cyrillic */
/* Cyrillic Supplement */
/* Cyrillic Extended-A */
/* Cyrillic Extended-B */
#define TT_UCR_CYRILLIC (1L << 9) /* U+0400-U+04FF */
/* U+0500-U+052F */
/* U+2DE0-U+2DFF */
/* U+A640-U+A69F */
/* Bit 10 Armenian */
#define TT_UCR_ARMENIAN (1L << 10) /* U+0530-U+058F */
/* Bit 11 Hebrew */
#define TT_UCR_HEBREW (1L << 11) /* U+0590-U+05FF */
/* Bit 12 Vai */
#define TT_UCR_VAI (1L << 12) /* U+A500-U+A63F */
/* Bit 13 Arabic */
/* Arabic Supplement */
#define TT_UCR_ARABIC (1L << 13) /* U+0600-U+06FF */
/* U+0750-U+077F */
/* Bit 14 NKo */
#define TT_UCR_NKO (1L << 14) /* U+07C0-U+07FF */
/* Bit 15 Devanagari */
#define TT_UCR_DEVANAGARI (1L << 15) /* U+0900-U+097F */
/* Bit 16 Bengali */
#define TT_UCR_BENGALI (1L << 16) /* U+0980-U+09FF */
/* Bit 17 Gurmukhi */
#define TT_UCR_GURMUKHI (1L << 17) /* U+0A00-U+0A7F */
/* Bit 18 Gujarati */
#define TT_UCR_GUJARATI (1L << 18) /* U+0A80-U+0AFF */
/* Bit 19 Oriya */
#define TT_UCR_ORIYA (1L << 19) /* U+0B00-U+0B7F */
/* Bit 20 Tamil */
#define TT_UCR_TAMIL (1L << 20) /* U+0B80-U+0BFF */
/* Bit 21 Telugu */
#define TT_UCR_TELUGU (1L << 21) /* U+0C00-U+0C7F */
/* Bit 22 Kannada */
#define TT_UCR_KANNADA (1L << 22) /* U+0C80-U+0CFF */
/* Bit 23 Malayalam */
#define TT_UCR_MALAYALAM (1L << 23) /* U+0D00-U+0D7F */
/* Bit 24 Thai */
#define TT_UCR_THAI (1L << 24) /* U+0E00-U+0E7F */
/* Bit 25 Lao */
#define TT_UCR_LAO (1L << 25) /* U+0E80-U+0EFF */
/* Bit 26 Georgian */
/* Georgian Supplement */
#define TT_UCR_GEORGIAN (1L << 26) /* U+10A0-U+10FF */
/* U+2D00-U+2D2F */
/* Bit 27 Balinese */
#define TT_UCR_BALINESE (1L << 27) /* U+1B00-U+1B7F */
/* Bit 28 Hangul Jamo */
#define TT_UCR_HANGUL_JAMO (1L << 28) /* U+1100-U+11FF */
/* Bit 29 Latin Extended Additional */
/* Latin Extended-C */
/* Latin Extended-D */
#define TT_UCR_LATIN_EXTENDED_ADDITIONAL (1L << 29) /* U+1E00-U+1EFF */
/* U+2C60-U+2C7F */
/* U+A720-U+A7FF */
/* Bit 30 Greek Extended */
#define TT_UCR_GREEK_EXTENDED (1L << 30) /* U+1F00-U+1FFF */
/* Bit 31 General Punctuation */
/* Supplemental Punctuation */
#define TT_UCR_GENERAL_PUNCTUATION (1L << 31) /* U+2000-U+206F */
/* U+2E00-U+2E7F */
/* Bit 32 Superscripts And Subscripts */
#define TT_UCR_SUPERSCRIPTS_SUBSCRIPTS (1L << 0) /* U+2070-U+209F */
/* Bit 33 Currency Symbols */
#define TT_UCR_CURRENCY_SYMBOLS (1L << 1) /* U+20A0-U+20CF */
/* Bit 34 Combining Diacritical Marks For Symbols */
#define TT_UCR_COMBINING_DIACRITICS_SYMB (1L << 2) /* U+20D0-U+20FF */
/* Bit 35 Letterlike Symbols */
#define TT_UCR_LETTERLIKE_SYMBOLS (1L << 3) /* U+2100-U+214F */
/* Bit 36 Number Forms */
#define TT_UCR_NUMBER_FORMS (1L << 4) /* U+2150-U+218F */
/* Bit 37 Arrows */
/* Supplemental Arrows-A */
/* Supplemental Arrows-B */
/* Miscellaneous Symbols and Arrows */
#define TT_UCR_ARROWS (1L << 5) /* U+2190-U+21FF */
/* U+27F0-U+27FF */
/* U+2900-U+297F */
/* U+2B00-U+2BFF */
/* Bit 38 Mathematical Operators */
/* Supplemental Mathematical Operators */
/* Miscellaneous Mathematical Symbols-A */
/* Miscellaneous Mathematical Symbols-B */
#define TT_UCR_MATHEMATICAL_OPERATORS (1L << 6) /* U+2200-U+22FF */
/* U+2A00-U+2AFF */
/* U+27C0-U+27EF */
/* U+2980-U+29FF */
/* Bit 39 Miscellaneous Technical */
#define TT_UCR_MISCELLANEOUS_TECHNICAL (1L << 7) /* U+2300-U+23FF */
/* Bit 40 Control Pictures */
#define TT_UCR_CONTROL_PICTURES (1L << 8) /* U+2400-U+243F */
/* Bit 41 Optical Character Recognition */
#define TT_UCR_OCR (1L << 9) /* U+2440-U+245F */
/* Bit 42 Enclosed Alphanumerics */
#define TT_UCR_ENCLOSED_ALPHANUMERICS (1L << 10) /* U+2460-U+24FF */
/* Bit 43 Box Drawing */
#define TT_UCR_BOX_DRAWING (1L << 11) /* U+2500-U+257F */
/* Bit 44 Block Elements */
#define TT_UCR_BLOCK_ELEMENTS (1L << 12) /* U+2580-U+259F */
/* Bit 45 Geometric Shapes */
#define TT_UCR_GEOMETRIC_SHAPES (1L << 13) /* U+25A0-U+25FF */
/* Bit 46 Miscellaneous Symbols */
#define TT_UCR_MISCELLANEOUS_SYMBOLS (1L << 14) /* U+2600-U+26FF */
/* Bit 47 Dingbats */
#define TT_UCR_DINGBATS (1L << 15) /* U+2700-U+27BF */
/* Bit 48 CJK Symbols and Punctuation */
#define TT_UCR_CJK_SYMBOLS (1L << 16) /* U+3000-U+303F */
/* Bit 49 Hiragana */
#define TT_UCR_HIRAGANA (1L << 17) /* U+3040-U+309F */
/* Bit 50 Katakana */
/* Katakana Phonetic Extensions */
#define TT_UCR_KATAKANA (1L << 18) /* U+30A0-U+30FF */
/* U+31F0-U+31FF */
/* Bit 51 Bopomofo */
/* Bopomofo Extended */
#define TT_UCR_BOPOMOFO (1L << 19) /* U+3100-U+312F */
/* U+31A0-U+31BF */
/* Bit 52 Hangul Compatibility Jamo */
#define TT_UCR_HANGUL_COMPATIBILITY_JAMO (1L << 20) /* U+3130-U+318F */
/* Bit 53 Phags-Pa */
#define TT_UCR_CJK_MISC (1L << 21) /* U+A840-U+A87F */
#define TT_UCR_KANBUN TT_UCR_CJK_MISC /* deprecated */
#define TT_UCR_PHAGSPA
/* Bit 54 Enclosed CJK Letters and Months */
#define TT_UCR_ENCLOSED_CJK_LETTERS_MONTHS (1L << 22) /* U+3200-U+32FF */
/* Bit 55 CJK Compatibility */
#define TT_UCR_CJK_COMPATIBILITY (1L << 23) /* U+3300-U+33FF */
/* Bit 56 Hangul Syllables */
#define TT_UCR_HANGUL (1L << 24) /* U+AC00-U+D7A3 */
/* Bit 57 High Surrogates */
/* High Private Use Surrogates */
/* Low Surrogates */
/* */
/* According to OpenType specs v.1.3+, */
/* setting bit 57 implies that there is */
/* at least one codepoint beyond the */
/* Basic Multilingual Plane that is */
/* supported by this font. So it really */
/* means >= U+10000 */
#define TT_UCR_SURROGATES (1L << 25) /* U+D800-U+DB7F */
/* U+DB80-U+DBFF */
/* U+DC00-U+DFFF */
#define TT_UCR_NON_PLANE_0 TT_UCR_SURROGATES
/* Bit 58 Phoenician */
#define TT_UCR_PHOENICIAN (1L << 26) /*U+10900-U+1091F*/
/* Bit 59 CJK Unified Ideographs */
/* CJK Radicals Supplement */
/* Kangxi Radicals */
/* Ideographic Description Characters */
/* CJK Unified Ideographs Extension A */
/* CJK Unified Ideographs Extension B */
/* Kanbun */
#define TT_UCR_CJK_UNIFIED_IDEOGRAPHS (1L << 27) /* U+4E00-U+9FFF */
/* U+2E80-U+2EFF */
/* U+2F00-U+2FDF */
/* U+2FF0-U+2FFF */
/* U+3400-U+4DB5 */
/*U+20000-U+2A6DF*/
/* U+3190-U+319F */
/* Bit 60 Private Use */
#define TT_UCR_PRIVATE_USE (1L << 28) /* U+E000-U+F8FF */
/* Bit 61 CJK Strokes */
/* CJK Compatibility Ideographs */
/* CJK Compatibility Ideographs Supplement */
#define TT_UCR_CJK_COMPATIBILITY_IDEOGRAPHS (1L << 29) /* U+31C0-U+31EF */
/* U+F900-U+FAFF */
/*U+2F800-U+2FA1F*/
/* Bit 62 Alphabetic Presentation Forms */
#define TT_UCR_ALPHABETIC_PRESENTATION_FORMS (1L << 30) /* U+FB00-U+FB4F */
/* Bit 63 Arabic Presentation Forms-A */
#define TT_UCR_ARABIC_PRESENTATIONS_A (1L << 31) /* U+FB50-U+FDFF */
/* Bit 64 Combining Half Marks */
#define TT_UCR_COMBINING_HALF_MARKS (1L << 0) /* U+FE20-U+FE2F */
/* Bit 65 Vertical forms */
/* CJK Compatibility Forms */
#define TT_UCR_CJK_COMPATIBILITY_FORMS (1L << 1) /* U+FE10-U+FE1F */
/* U+FE30-U+FE4F */
/* Bit 66 Small Form Variants */
#define TT_UCR_SMALL_FORM_VARIANTS (1L << 2) /* U+FE50-U+FE6F */
/* Bit 67 Arabic Presentation Forms-B */
#define TT_UCR_ARABIC_PRESENTATIONS_B (1L << 3) /* U+FE70-U+FEFE */
/* Bit 68 Halfwidth and Fullwidth Forms */
#define TT_UCR_HALFWIDTH_FULLWIDTH_FORMS (1L << 4) /* U+FF00-U+FFEF */
/* Bit 69 Specials */
#define TT_UCR_SPECIALS (1L << 5) /* U+FFF0-U+FFFD */
/* Bit 70 Tibetan */
#define TT_UCR_TIBETAN (1L << 6) /* U+0F00-U+0FFF */
/* Bit 71 Syriac */
#define TT_UCR_SYRIAC (1L << 7) /* U+0700-U+074F */
/* Bit 72 Thaana */
#define TT_UCR_THAANA (1L << 8) /* U+0780-U+07BF */
/* Bit 73 Sinhala */
#define TT_UCR_SINHALA (1L << 9) /* U+0D80-U+0DFF */
/* Bit 74 Myanmar */
#define TT_UCR_MYANMAR (1L << 10) /* U+1000-U+109F */
/* Bit 75 Ethiopic */
/* Ethiopic Supplement */
/* Ethiopic Extended */
#define TT_UCR_ETHIOPIC (1L << 11) /* U+1200-U+137F */
/* U+1380-U+139F */
/* U+2D80-U+2DDF */
/* Bit 76 Cherokee */
#define TT_UCR_CHEROKEE (1L << 12) /* U+13A0-U+13FF */
/* Bit 77 Unified Canadian Aboriginal Syllabics */
#define TT_UCR_CANADIAN_ABORIGINAL_SYLLABICS (1L << 13) /* U+1400-U+167F */
/* Bit 78 Ogham */
#define TT_UCR_OGHAM (1L << 14) /* U+1680-U+169F */
/* Bit 79 Runic */
#define TT_UCR_RUNIC (1L << 15) /* U+16A0-U+16FF */
/* Bit 80 Khmer */
/* Khmer Symbols */
#define TT_UCR_KHMER (1L << 16) /* U+1780-U+17FF */
/* U+19E0-U+19FF */
/* Bit 81 Mongolian */
#define TT_UCR_MONGOLIAN (1L << 17) /* U+1800-U+18AF */
/* Bit 82 Braille Patterns */
#define TT_UCR_BRAILLE (1L << 18) /* U+2800-U+28FF */
/* Bit 83 Yi Syllables */
/* Yi Radicals */
#define TT_UCR_YI (1L << 19) /* U+A000-U+A48F */
/* U+A490-U+A4CF */
/* Bit 84 Tagalog */
/* Hanunoo */
/* Buhid */
/* Tagbanwa */
#define TT_UCR_PHILIPPINE (1L << 20) /* U+1700-U+171F */
/* U+1720-U+173F */
/* U+1740-U+175F */
/* U+1760-U+177F */
/* Bit 85 Old Italic */
#define TT_UCR_OLD_ITALIC (1L << 21) /*U+10300-U+1032F*/
/* Bit 86 Gothic */
#define TT_UCR_GOTHIC (1L << 22) /*U+10330-U+1034F*/
/* Bit 87 Deseret */
#define TT_UCR_DESERET (1L << 23) /*U+10400-U+1044F*/
/* Bit 88 Byzantine Musical Symbols */
/* Musical Symbols */
/* Ancient Greek Musical Notation */
#define TT_UCR_MUSICAL_SYMBOLS (1L << 24) /*U+1D000-U+1D0FF*/
/*U+1D100-U+1D1FF*/
/*U+1D200-U+1D24F*/
/* Bit 89 Mathematical Alphanumeric Symbols */
#define TT_UCR_MATH_ALPHANUMERIC_SYMBOLS (1L << 25) /*U+1D400-U+1D7FF*/
/* Bit 90 Private Use (plane 15) */
/* Private Use (plane 16) */
#define TT_UCR_PRIVATE_USE_SUPPLEMENTARY (1L << 26) /*U+F0000-U+FFFFD*/
/*U+100000-U+10FFFD*/
/* Bit 91 Variation Selectors */
/* Variation Selectors Supplement */
#define TT_UCR_VARIATION_SELECTORS (1L << 27) /* U+FE00-U+FE0F */
/*U+E0100-U+E01EF*/
/* Bit 92 Tags */
#define TT_UCR_TAGS (1L << 28) /*U+E0000-U+E007F*/
/* Bit 93 Limbu */
#define TT_UCR_LIMBU (1L << 29) /* U+1900-U+194F */
/* Bit 94 Tai Le */
#define TT_UCR_TAI_LE (1L << 30) /* U+1950-U+197F */
/* Bit 95 New Tai Lue */
#define TT_UCR_NEW_TAI_LUE (1L << 31) /* U+1980-U+19DF */
/* Bit 96 Buginese */
#define TT_UCR_BUGINESE (1L << 0) /* U+1A00-U+1A1F */
/* Bit 97 Glagolitic */
#define TT_UCR_GLAGOLITIC (1L << 1) /* U+2C00-U+2C5F */
/* Bit 98 Tifinagh */
#define TT_UCR_TIFINAGH (1L << 2) /* U+2D30-U+2D7F */
/* Bit 99 Yijing Hexagram Symbols */
#define TT_UCR_YIJING (1L << 3) /* U+4DC0-U+4DFF */
/* Bit 100 Syloti Nagri */
#define TT_UCR_SYLOTI_NAGRI (1L << 4) /* U+A800-U+A82F */
/* Bit 101 Linear B Syllabary */
/* Linear B Ideograms */
/* Aegean Numbers */
#define TT_UCR_LINEAR_B (1L << 5) /*U+10000-U+1007F*/
/*U+10080-U+100FF*/
/*U+10100-U+1013F*/
/* Bit 102 Ancient Greek Numbers */
#define TT_UCR_ANCIENT_GREEK_NUMBERS (1L << 6) /*U+10140-U+1018F*/
/* Bit 103 Ugaritic */
#define TT_UCR_UGARITIC (1L << 7) /*U+10380-U+1039F*/
/* Bit 104 Old Persian */
#define TT_UCR_OLD_PERSIAN (1L << 8) /*U+103A0-U+103DF*/
/* Bit 105 Shavian */
#define TT_UCR_SHAVIAN (1L << 9) /*U+10450-U+1047F*/
/* Bit 106 Osmanya */
#define TT_UCR_OSMANYA (1L << 10) /*U+10480-U+104AF*/
/* Bit 107 Cypriot Syllabary */
#define TT_UCR_CYPRIOT_SYLLABARY (1L << 11) /*U+10800-U+1083F*/
/* Bit 108 Kharoshthi */
#define TT_UCR_KHAROSHTHI (1L << 12) /*U+10A00-U+10A5F*/
/* Bit 109 Tai Xuan Jing Symbols */
#define TT_UCR_TAI_XUAN_JING (1L << 13) /*U+1D300-U+1D35F*/
/* Bit 110 Cuneiform */
/* Cuneiform Numbers and Punctuation */
#define TT_UCR_CUNEIFORM (1L << 14) /*U+12000-U+123FF*/
/*U+12400-U+1247F*/
/* Bit 111 Counting Rod Numerals */
#define TT_UCR_COUNTING_ROD_NUMERALS (1L << 15) /*U+1D360-U+1D37F*/
/* Bit 112 Sundanese */
#define TT_UCR_SUNDANESE (1L << 16) /* U+1B80-U+1BBF */
/* Bit 113 Lepcha */
#define TT_UCR_LEPCHA (1L << 17) /* U+1C00-U+1C4F */
/* Bit 114 Ol Chiki */
#define TT_UCR_OL_CHIKI (1L << 18) /* U+1C50-U+1C7F */
/* Bit 115 Saurashtra */
#define TT_UCR_SAURASHTRA (1L << 19) /* U+A880-U+A8DF */
/* Bit 116 Kayah Li */
#define TT_UCR_KAYAH_LI (1L << 20) /* U+A900-U+A92F */
/* Bit 117 Rejang */
#define TT_UCR_REJANG (1L << 21) /* U+A930-U+A95F */
/* Bit 118 Cham */
#define TT_UCR_CHAM (1L << 22) /* U+AA00-U+AA5F */
/* Bit 119 Ancient Symbols */
#define TT_UCR_ANCIENT_SYMBOLS (1L << 23) /*U+10190-U+101CF*/
/* Bit 120 Phaistos Disc */
#define TT_UCR_PHAISTOS_DISC (1L << 24) /*U+101D0-U+101FF*/
/* Bit 121 Carian */
/* Lycian */
/* Lydian */
#define TT_UCR_OLD_ANATOLIAN (1L << 25) /*U+102A0-U+102DF*/
/*U+10280-U+1029F*/
/*U+10920-U+1093F*/
/* Bit 122 Domino Tiles */
/* Mahjong Tiles */
#define TT_UCR_GAME_TILES (1L << 26) /*U+1F030-U+1F09F*/
/*U+1F000-U+1F02F*/
/* Bit 123-127 Reserved for process-internal usage */
/*************************************************************************/
/* */
/* Some compilers have a very limited length of identifiers. */
/* */
#if defined( __TURBOC__ ) && __TURBOC__ < 0x0410 || defined( __PACIFIC__ )
#define HAVE_LIMIT_ON_IDENTS
#endif
#ifndef HAVE_LIMIT_ON_IDENTS
/*************************************************************************/
/* */
/* Here some alias #defines in order to be clearer. */
/* */
/* These are not always #defined to stay within the 31~character limit, */
/* which some compilers have. */
/* */
/* Credits go to Dave Hoo <dhoo@flash.net> for pointing out that modern */
/* Borland compilers (read: from BC++ 3.1 on) can increase this limit. */
/* If you get a warning with such a compiler, use the -i40 switch. */
/* */
#define TT_UCR_ARABIC_PRESENTATION_FORMS_A \
TT_UCR_ARABIC_PRESENTATIONS_A
#define TT_UCR_ARABIC_PRESENTATION_FORMS_B \
TT_UCR_ARABIC_PRESENTATIONS_B
#define TT_UCR_COMBINING_DIACRITICAL_MARKS \
TT_UCR_COMBINING_DIACRITICS
#define TT_UCR_COMBINING_DIACRITICAL_MARKS_SYMB \
TT_UCR_COMBINING_DIACRITICS_SYMB
#endif /* !HAVE_LIMIT_ON_IDENTS */
FT_END_HEADER
#endif /* __TTNAMEID_H__ */
/* END */
| YifuLiu/AliOS-Things | components/freetype/include/ttnameid.h | C | apache-2.0 | 61,390 |
/***************************************************************************/
/* */
/* tttables.h */
/* */
/* Basic SFNT/TrueType tables definitions and interface */
/* (specification only). */
/* */
/* Copyright 1996-2005, 2008-2013 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. */
/* */
/***************************************************************************/
#ifndef __TTTABLES_H__
#define __TTTABLES_H__
#include <ft2build.h>
#include FT_FREETYPE_H
#ifdef FREETYPE_H
#error "freetype.h of FreeType 1 has been loaded!"
#error "Please fix the directory search order for header files"
#error "so that freetype.h of FreeType 2 is found first."
#endif
FT_BEGIN_HEADER
/*************************************************************************/
/* */
/* <Section> */
/* truetype_tables */
/* */
/* <Title> */
/* TrueType Tables */
/* */
/* <Abstract> */
/* TrueType specific table types and functions. */
/* */
/* <Description> */
/* This section contains the definition of TrueType-specific tables */
/* as well as some routines used to access and process them. */
/* */
/*************************************************************************/
/*************************************************************************/
/* */
/* <Struct> */
/* TT_Header */
/* */
/* <Description> */
/* A structure used to model a TrueType font header table. All */
/* fields follow the TrueType specification. */
/* */
typedef struct TT_Header_
{
FT_Fixed Table_Version;
FT_Fixed Font_Revision;
FT_Long CheckSum_Adjust;
FT_Long Magic_Number;
FT_UShort Flags;
FT_UShort Units_Per_EM;
FT_Long Created [2];
FT_Long Modified[2];
FT_Short xMin;
FT_Short yMin;
FT_Short xMax;
FT_Short yMax;
FT_UShort Mac_Style;
FT_UShort Lowest_Rec_PPEM;
FT_Short Font_Direction;
FT_Short Index_To_Loc_Format;
FT_Short Glyph_Data_Format;
} TT_Header;
/*************************************************************************/
/* */
/* <Struct> */
/* TT_HoriHeader */
/* */
/* <Description> */
/* A structure used to model a TrueType horizontal header, the `hhea' */
/* table, as well as the corresponding horizontal metrics table, */
/* i.e., the `hmtx' table. */
/* */
/* <Fields> */
/* Version :: The table version. */
/* */
/* Ascender :: The font's ascender, i.e., the distance */
/* from the baseline to the top-most of all */
/* glyph points found in the font. */
/* */
/* This value is invalid in many fonts, as */
/* it is usually set by the font designer, */
/* and often reflects only a portion of the */
/* glyphs found in the font (maybe ASCII). */
/* */
/* You should use the `sTypoAscender' field */
/* of the OS/2 table instead if you want */
/* the correct one. */
/* */
/* Descender :: The font's descender, i.e., the distance */
/* from the baseline to the bottom-most of */
/* all glyph points found in the font. It */
/* is negative. */
/* */
/* This value is invalid in many fonts, as */
/* it is usually set by the font designer, */
/* and often reflects only a portion of the */
/* glyphs found in the font (maybe ASCII). */
/* */
/* You should use the `sTypoDescender' */
/* field of the OS/2 table instead if you */
/* want the correct one. */
/* */
/* Line_Gap :: The font's line gap, i.e., the distance */
/* to add to the ascender and descender to */
/* get the BTB, i.e., the */
/* baseline-to-baseline distance for the */
/* font. */
/* */
/* advance_Width_Max :: This field is the maximum of all advance */
/* widths found in the font. It can be */
/* used to compute the maximum width of an */
/* arbitrary string of text. */
/* */
/* min_Left_Side_Bearing :: The minimum left side bearing of all */
/* glyphs within the font. */
/* */
/* min_Right_Side_Bearing :: The minimum right side bearing of all */
/* glyphs within the font. */
/* */
/* xMax_Extent :: The maximum horizontal extent (i.e., the */
/* `width' of a glyph's bounding box) for */
/* all glyphs in the font. */
/* */
/* caret_Slope_Rise :: The rise coefficient of the cursor's */
/* slope of the cursor (slope=rise/run). */
/* */
/* caret_Slope_Run :: The run coefficient of the cursor's */
/* slope. */
/* */
/* Reserved :: 8~reserved bytes. */
/* */
/* metric_Data_Format :: Always~0. */
/* */
/* number_Of_HMetrics :: Number of HMetrics entries in the `hmtx' */
/* table -- this value can be smaller than */
/* the total number of glyphs in the font. */
/* */
/* long_metrics :: A pointer into the `hmtx' table. */
/* */
/* short_metrics :: A pointer into the `hmtx' table. */
/* */
/* <Note> */
/* IMPORTANT: The TT_HoriHeader and TT_VertHeader structures should */
/* be identical except for the names of their fields, */
/* which are different. */
/* */
/* This ensures that a single function in the `ttload' */
/* module is able to read both the horizontal and vertical */
/* headers. */
/* */
typedef struct TT_HoriHeader_
{
FT_Fixed Version;
FT_Short Ascender;
FT_Short Descender;
FT_Short Line_Gap;
FT_UShort advance_Width_Max; /* advance width maximum */
FT_Short min_Left_Side_Bearing; /* minimum left-sb */
FT_Short min_Right_Side_Bearing; /* minimum right-sb */
FT_Short xMax_Extent; /* xmax extents */
FT_Short caret_Slope_Rise;
FT_Short caret_Slope_Run;
FT_Short caret_Offset;
FT_Short Reserved[4];
FT_Short metric_Data_Format;
FT_UShort number_Of_HMetrics;
/* The following fields are not defined by the TrueType specification */
/* but they are used to connect the metrics header to the relevant */
/* `HMTX' table. */
void* long_metrics;
void* short_metrics;
} TT_HoriHeader;
/*************************************************************************/
/* */
/* <Struct> */
/* TT_VertHeader */
/* */
/* <Description> */
/* A structure used to model a TrueType vertical header, the `vhea' */
/* table, as well as the corresponding vertical metrics table, i.e., */
/* the `vmtx' table. */
/* */
/* <Fields> */
/* Version :: The table version. */
/* */
/* Ascender :: The font's ascender, i.e., the distance */
/* from the baseline to the top-most of */
/* all glyph points found in the font. */
/* */
/* This value is invalid in many fonts, as */
/* it is usually set by the font designer, */
/* and often reflects only a portion of */
/* the glyphs found in the font (maybe */
/* ASCII). */
/* */
/* You should use the `sTypoAscender' */
/* field of the OS/2 table instead if you */
/* want the correct one. */
/* */
/* Descender :: The font's descender, i.e., the */
/* distance from the baseline to the */
/* bottom-most of all glyph points found */
/* in the font. It is negative. */
/* */
/* This value is invalid in many fonts, as */
/* it is usually set by the font designer, */
/* and often reflects only a portion of */
/* the glyphs found in the font (maybe */
/* ASCII). */
/* */
/* You should use the `sTypoDescender' */
/* field of the OS/2 table instead if you */
/* want the correct one. */
/* */
/* Line_Gap :: The font's line gap, i.e., the distance */
/* to add to the ascender and descender to */
/* get the BTB, i.e., the */
/* baseline-to-baseline distance for the */
/* font. */
/* */
/* advance_Height_Max :: This field is the maximum of all */
/* advance heights found in the font. It */
/* can be used to compute the maximum */
/* height of an arbitrary string of text. */
/* */
/* min_Top_Side_Bearing :: The minimum top side bearing of all */
/* glyphs within the font. */
/* */
/* min_Bottom_Side_Bearing :: The minimum bottom side bearing of all */
/* glyphs within the font. */
/* */
/* yMax_Extent :: The maximum vertical extent (i.e., the */
/* `height' of a glyph's bounding box) for */
/* all glyphs in the font. */
/* */
/* caret_Slope_Rise :: The rise coefficient of the cursor's */
/* slope of the cursor (slope=rise/run). */
/* */
/* caret_Slope_Run :: The run coefficient of the cursor's */
/* slope. */
/* */
/* caret_Offset :: The cursor's offset for slanted fonts. */
/* This value is `reserved' in vmtx */
/* version 1.0. */
/* */
/* Reserved :: 8~reserved bytes. */
/* */
/* metric_Data_Format :: Always~0. */
/* */
/* number_Of_HMetrics :: Number of VMetrics entries in the */
/* `vmtx' table -- this value can be */
/* smaller than the total number of glyphs */
/* in the font. */
/* */
/* long_metrics :: A pointer into the `vmtx' table. */
/* */
/* short_metrics :: A pointer into the `vmtx' table. */
/* */
/* <Note> */
/* IMPORTANT: The TT_HoriHeader and TT_VertHeader structures should */
/* be identical except for the names of their fields, */
/* which are different. */
/* */
/* This ensures that a single function in the `ttload' */
/* module is able to read both the horizontal and vertical */
/* headers. */
/* */
typedef struct TT_VertHeader_
{
FT_Fixed Version;
FT_Short Ascender;
FT_Short Descender;
FT_Short Line_Gap;
FT_UShort advance_Height_Max; /* advance height maximum */
FT_Short min_Top_Side_Bearing; /* minimum left-sb or top-sb */
FT_Short min_Bottom_Side_Bearing; /* minimum right-sb or bottom-sb */
FT_Short yMax_Extent; /* xmax or ymax extents */
FT_Short caret_Slope_Rise;
FT_Short caret_Slope_Run;
FT_Short caret_Offset;
FT_Short Reserved[4];
FT_Short metric_Data_Format;
FT_UShort number_Of_VMetrics;
/* The following fields are not defined by the TrueType specification */
/* but they're used to connect the metrics header to the relevant */
/* `HMTX' or `VMTX' table. */
void* long_metrics;
void* short_metrics;
} TT_VertHeader;
/*************************************************************************/
/* */
/* <Struct> */
/* TT_OS2 */
/* */
/* <Description> */
/* A structure used to model a TrueType OS/2 table. All fields */
/* comply to the OpenType specification. */
/* */
/* Note that we now support old Mac fonts that do not include an OS/2 */
/* table. In this case, the `version' field is always set to 0xFFFF. */
/* */
typedef struct TT_OS2_
{
FT_UShort version; /* 0x0001 - more or 0xFFFF */
FT_Short xAvgCharWidth;
FT_UShort usWeightClass;
FT_UShort usWidthClass;
FT_Short fsType;
FT_Short ySubscriptXSize;
FT_Short ySubscriptYSize;
FT_Short ySubscriptXOffset;
FT_Short ySubscriptYOffset;
FT_Short ySuperscriptXSize;
FT_Short ySuperscriptYSize;
FT_Short ySuperscriptXOffset;
FT_Short ySuperscriptYOffset;
FT_Short yStrikeoutSize;
FT_Short yStrikeoutPosition;
FT_Short sFamilyClass;
FT_Byte panose[10];
FT_ULong ulUnicodeRange1; /* Bits 0-31 */
FT_ULong ulUnicodeRange2; /* Bits 32-63 */
FT_ULong ulUnicodeRange3; /* Bits 64-95 */
FT_ULong ulUnicodeRange4; /* Bits 96-127 */
FT_Char achVendID[4];
FT_UShort fsSelection;
FT_UShort usFirstCharIndex;
FT_UShort usLastCharIndex;
FT_Short sTypoAscender;
FT_Short sTypoDescender;
FT_Short sTypoLineGap;
FT_UShort usWinAscent;
FT_UShort usWinDescent;
/* only version 1 and higher: */
FT_ULong ulCodePageRange1; /* Bits 0-31 */
FT_ULong ulCodePageRange2; /* Bits 32-63 */
/* only version 2 and higher: */
FT_Short sxHeight;
FT_Short sCapHeight;
FT_UShort usDefaultChar;
FT_UShort usBreakChar;
FT_UShort usMaxContext;
/* only version 5 and higher: */
FT_UShort usLowerOpticalPointSize; /* in twips (1/20th points) */
FT_UShort usUpperOpticalPointSize; /* in twips (1/20th points) */
} TT_OS2;
/*************************************************************************/
/* */
/* <Struct> */
/* TT_Postscript */
/* */
/* <Description> */
/* A structure used to model a TrueType PostScript table. All fields */
/* comply to the TrueType specification. This structure does not */
/* reference the PostScript glyph names, which can be nevertheless */
/* accessed with the `ttpost' module. */
/* */
typedef struct TT_Postscript_
{
FT_Fixed FormatType;
FT_Fixed italicAngle;
FT_Short underlinePosition;
FT_Short underlineThickness;
FT_ULong isFixedPitch;
FT_ULong minMemType42;
FT_ULong maxMemType42;
FT_ULong minMemType1;
FT_ULong maxMemType1;
/* Glyph names follow in the file, but we don't */
/* load them by default. See the ttpost.c file. */
} TT_Postscript;
/*************************************************************************/
/* */
/* <Struct> */
/* TT_PCLT */
/* */
/* <Description> */
/* A structure used to model a TrueType PCLT table. All fields */
/* comply to the TrueType specification. */
/* */
typedef struct TT_PCLT_
{
FT_Fixed Version;
FT_ULong FontNumber;
FT_UShort Pitch;
FT_UShort xHeight;
FT_UShort Style;
FT_UShort TypeFamily;
FT_UShort CapHeight;
FT_UShort SymbolSet;
FT_Char TypeFace[16];
FT_Char CharacterComplement[8];
FT_Char FileName[6];
FT_Char StrokeWeight;
FT_Char WidthType;
FT_Byte SerifStyle;
FT_Byte Reserved;
} TT_PCLT;
/*************************************************************************/
/* */
/* <Struct> */
/* TT_MaxProfile */
/* */
/* <Description> */
/* The maximum profile is a table containing many max values, which */
/* can be used to pre-allocate arrays. This ensures that no memory */
/* allocation occurs during a glyph load. */
/* */
/* <Fields> */
/* version :: The version number. */
/* */
/* numGlyphs :: The number of glyphs in this TrueType */
/* font. */
/* */
/* maxPoints :: The maximum number of points in a */
/* non-composite TrueType glyph. See also */
/* the structure element */
/* `maxCompositePoints'. */
/* */
/* maxContours :: The maximum number of contours in a */
/* non-composite TrueType glyph. See also */
/* the structure element */
/* `maxCompositeContours'. */
/* */
/* maxCompositePoints :: The maximum number of points in a */
/* composite TrueType glyph. See also the */
/* structure element `maxPoints'. */
/* */
/* maxCompositeContours :: The maximum number of contours in a */
/* composite TrueType glyph. See also the */
/* structure element `maxContours'. */
/* */
/* maxZones :: The maximum number of zones used for */
/* glyph hinting. */
/* */
/* maxTwilightPoints :: The maximum number of points in the */
/* twilight zone used for glyph hinting. */
/* */
/* maxStorage :: The maximum number of elements in the */
/* storage area used for glyph hinting. */
/* */
/* maxFunctionDefs :: The maximum number of function */
/* definitions in the TrueType bytecode for */
/* this font. */
/* */
/* maxInstructionDefs :: The maximum number of instruction */
/* definitions in the TrueType bytecode for */
/* this font. */
/* */
/* maxStackElements :: The maximum number of stack elements used */
/* during bytecode interpretation. */
/* */
/* maxSizeOfInstructions :: The maximum number of TrueType opcodes */
/* used for glyph hinting. */
/* */
/* maxComponentElements :: The maximum number of simple (i.e., non- */
/* composite) glyphs in a composite glyph. */
/* */
/* maxComponentDepth :: The maximum nesting depth of composite */
/* glyphs. */
/* */
/* <Note> */
/* This structure is only used during font loading. */
/* */
typedef struct TT_MaxProfile_
{
FT_Fixed version;
FT_UShort numGlyphs;
FT_UShort maxPoints;
FT_UShort maxContours;
FT_UShort maxCompositePoints;
FT_UShort maxCompositeContours;
FT_UShort maxZones;
FT_UShort maxTwilightPoints;
FT_UShort maxStorage;
FT_UShort maxFunctionDefs;
FT_UShort maxInstructionDefs;
FT_UShort maxStackElements;
FT_UShort maxSizeOfInstructions;
FT_UShort maxComponentElements;
FT_UShort maxComponentDepth;
} TT_MaxProfile;
/*************************************************************************/
/* */
/* <Enum> */
/* FT_Sfnt_Tag */
/* */
/* <Description> */
/* An enumeration used to specify the index of an SFNT table. */
/* Used in the @FT_Get_Sfnt_Table API function. */
/* */
typedef enum FT_Sfnt_Tag_
{
ft_sfnt_head = 0, /* TT_Header */
ft_sfnt_maxp = 1, /* TT_MaxProfile */
ft_sfnt_os2 = 2, /* TT_OS2 */
ft_sfnt_hhea = 3, /* TT_HoriHeader */
ft_sfnt_vhea = 4, /* TT_VertHeader */
ft_sfnt_post = 5, /* TT_Postscript */
ft_sfnt_pclt = 6, /* TT_PCLT */
sfnt_max /* internal end mark */
} FT_Sfnt_Tag;
/* */
/*************************************************************************/
/* */
/* <Function> */
/* FT_Get_Sfnt_Table */
/* */
/* <Description> */
/* Return a pointer to a given SFNT table within a face. */
/* */
/* <Input> */
/* face :: A handle to the source. */
/* */
/* tag :: The index of the SFNT table. */
/* */
/* <Return> */
/* A type-less pointer to the table. This will be~0 in case of */
/* error, or if the corresponding table was not found *OR* loaded */
/* from the file. */
/* */
/* Use a typecast according to `tag' to access the structure */
/* elements. */
/* */
/* <Note> */
/* The table is owned by the face object and disappears with it. */
/* */
/* This function is only useful to access SFNT tables that are loaded */
/* by the sfnt, truetype, and opentype drivers. See @FT_Sfnt_Tag for */
/* a list. */
/* */
/* Here an example how to access the `vhea' table: */
/* */
/* { */
/* TT_VertHeader* vert_header; */
/* */
/* */
/* vert_header = */
/* (TT_VertHeader*)FT_Get_Sfnt_Table( face, ft_sfnt_vhea ); */
/* } */
/* */
FT_EXPORT( void* )
FT_Get_Sfnt_Table( FT_Face face,
FT_Sfnt_Tag tag );
/**************************************************************************
*
* @function:
* FT_Load_Sfnt_Table
*
* @description:
* Load any font table into client memory.
*
* @input:
* face ::
* A handle to the source face.
*
* tag ::
* The four-byte tag of the table to load. Use the value~0 if you want
* to access the whole font file. Otherwise, you can use one of the
* definitions found in the @FT_TRUETYPE_TAGS_H file, or forge a new
* one with @FT_MAKE_TAG.
*
* offset ::
* The starting offset in the table (or file if tag == 0).
*
* @output:
* buffer ::
* The target buffer address. The client must ensure that the memory
* array is big enough to hold the data.
*
* @inout:
* length ::
* If the `length' parameter is NULL, then try to load the whole table.
* Return an error code if it fails.
*
* Else, if `*length' is~0, exit immediately while returning the
* table's (or file) full size in it.
*
* Else the number of bytes to read from the table or file, from the
* starting offset.
*
* @return:
* FreeType error code. 0~means success.
*
* @note:
* If you need to determine the table's length you should first call this
* function with `*length' set to~0, as in the following example:
*
* {
* FT_ULong length = 0;
*
*
* error = FT_Load_Sfnt_Table( face, tag, 0, NULL, &length );
* if ( error ) { ... table does not exist ... }
*
* buffer = malloc( length );
* if ( buffer == NULL ) { ... not enough memory ... }
*
* error = FT_Load_Sfnt_Table( face, tag, 0, buffer, &length );
* if ( error ) { ... could not load table ... }
* }
*
* Note that structures like @TT_Header or @TT_OS2 can't be used with
* this function; they are limited to @FT_Get_Sfnt_Table. Reason is that
* those structures depend on the processor architecture, with varying
* size (e.g. 32bit vs. 64bit) or order (big endian vs. little endian).
*
*/
FT_EXPORT( FT_Error )
FT_Load_Sfnt_Table( FT_Face face,
FT_ULong tag,
FT_Long offset,
FT_Byte* buffer,
FT_ULong* length );
/**************************************************************************
*
* @function:
* FT_Sfnt_Table_Info
*
* @description:
* Return information on an SFNT table.
*
* @input:
* face ::
* A handle to the source face.
*
* table_index ::
* The index of an SFNT table. The function returns
* FT_Err_Table_Missing for an invalid value.
*
* @inout:
* tag ::
* The name tag of the SFNT table. If the value is NULL, `table_index'
* is ignored, and `length' returns the number of SFNT tables in the
* font.
*
* @output:
* length ::
* The length of the SFNT table (or the number of SFNT tables, depending
* on `tag').
*
* @return:
* FreeType error code. 0~means success.
*
* @note:
* While parsing fonts, FreeType handles SFNT tables with length zero as
* missing.
*
*/
FT_EXPORT( FT_Error )
FT_Sfnt_Table_Info( FT_Face face,
FT_UInt table_index,
FT_ULong *tag,
FT_ULong *length );
/*************************************************************************/
/* */
/* <Function> */
/* FT_Get_CMap_Language_ID */
/* */
/* <Description> */
/* Return TrueType/sfnt specific cmap language ID. Definitions of */
/* language ID values are in `ttnameid.h'. */
/* */
/* <Input> */
/* charmap :: */
/* The target charmap. */
/* */
/* <Return> */
/* The language ID of `charmap'. If `charmap' doesn't belong to a */
/* TrueType/sfnt face, just return~0 as the default value. */
/* */
/* For a format~14 cmap (to access Unicode IVS), the return value is */
/* 0xFFFFFFFF. */
/* */
FT_EXPORT( FT_ULong )
FT_Get_CMap_Language_ID( FT_CharMap charmap );
/*************************************************************************/
/* */
/* <Function> */
/* FT_Get_CMap_Format */
/* */
/* <Description> */
/* Return TrueType/sfnt specific cmap format. */
/* */
/* <Input> */
/* charmap :: */
/* The target charmap. */
/* */
/* <Return> */
/* The format of `charmap'. If `charmap' doesn't belong to a */
/* TrueType/sfnt face, return -1. */
/* */
FT_EXPORT( FT_Long )
FT_Get_CMap_Format( FT_CharMap charmap );
/* */
FT_END_HEADER
#endif /* __TTTABLES_H__ */
/* END */
| YifuLiu/AliOS-Things | components/freetype/include/tttables.h | C | apache-2.0 | 41,566 |
/***************************************************************************/
/* */
/* tttags.h */
/* */
/* Tags for TrueType and OpenType tables (specification only). */
/* */
/* Copyright 1996-2001, 2004, 2005, 2007, 2008, 2013 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. */
/* */
/***************************************************************************/
#ifndef __TTAGS_H__
#define __TTAGS_H__
#include <ft2build.h>
#include FT_FREETYPE_H
#ifdef FREETYPE_H
#error "freetype.h of FreeType 1 has been loaded!"
#error "Please fix the directory search order for header files"
#error "so that freetype.h of FreeType 2 is found first."
#endif
FT_BEGIN_HEADER
#define TTAG_avar FT_MAKE_TAG( 'a', 'v', 'a', 'r' )
#define TTAG_BASE FT_MAKE_TAG( 'B', 'A', 'S', 'E' )
#define TTAG_bdat FT_MAKE_TAG( 'b', 'd', 'a', 't' )
#define TTAG_BDF FT_MAKE_TAG( 'B', 'D', 'F', ' ' )
#define TTAG_bhed FT_MAKE_TAG( 'b', 'h', 'e', 'd' )
#define TTAG_bloc FT_MAKE_TAG( 'b', 'l', 'o', 'c' )
#define TTAG_bsln FT_MAKE_TAG( 'b', 's', 'l', 'n' )
#define TTAG_CBDT FT_MAKE_TAG( 'C', 'B', 'D', 'T' )
#define TTAG_CBLC FT_MAKE_TAG( 'C', 'B', 'L', 'C' )
#define TTAG_CFF FT_MAKE_TAG( 'C', 'F', 'F', ' ' )
#define TTAG_CID FT_MAKE_TAG( 'C', 'I', 'D', ' ' )
#define TTAG_cmap FT_MAKE_TAG( 'c', 'm', 'a', 'p' )
#define TTAG_cvar FT_MAKE_TAG( 'c', 'v', 'a', 'r' )
#define TTAG_cvt FT_MAKE_TAG( 'c', 'v', 't', ' ' )
#define TTAG_DSIG FT_MAKE_TAG( 'D', 'S', 'I', 'G' )
#define TTAG_EBDT FT_MAKE_TAG( 'E', 'B', 'D', 'T' )
#define TTAG_EBLC FT_MAKE_TAG( 'E', 'B', 'L', 'C' )
#define TTAG_EBSC FT_MAKE_TAG( 'E', 'B', 'S', 'C' )
#define TTAG_feat FT_MAKE_TAG( 'f', 'e', 'a', 't' )
#define TTAG_FOND FT_MAKE_TAG( 'F', 'O', 'N', 'D' )
#define TTAG_fpgm FT_MAKE_TAG( 'f', 'p', 'g', 'm' )
#define TTAG_fvar FT_MAKE_TAG( 'f', 'v', 'a', 'r' )
#define TTAG_gasp FT_MAKE_TAG( 'g', 'a', 's', 'p' )
#define TTAG_GDEF FT_MAKE_TAG( 'G', 'D', 'E', 'F' )
#define TTAG_glyf FT_MAKE_TAG( 'g', 'l', 'y', 'f' )
#define TTAG_GPOS FT_MAKE_TAG( 'G', 'P', 'O', 'S' )
#define TTAG_GSUB FT_MAKE_TAG( 'G', 'S', 'U', 'B' )
#define TTAG_gvar FT_MAKE_TAG( 'g', 'v', 'a', 'r' )
#define TTAG_hdmx FT_MAKE_TAG( 'h', 'd', 'm', 'x' )
#define TTAG_head FT_MAKE_TAG( 'h', 'e', 'a', 'd' )
#define TTAG_hhea FT_MAKE_TAG( 'h', 'h', 'e', 'a' )
#define TTAG_hmtx FT_MAKE_TAG( 'h', 'm', 't', 'x' )
#define TTAG_JSTF FT_MAKE_TAG( 'J', 'S', 'T', 'F' )
#define TTAG_just FT_MAKE_TAG( 'j', 'u', 's', 't' )
#define TTAG_kern FT_MAKE_TAG( 'k', 'e', 'r', 'n' )
#define TTAG_lcar FT_MAKE_TAG( 'l', 'c', 'a', 'r' )
#define TTAG_loca FT_MAKE_TAG( 'l', 'o', 'c', 'a' )
#define TTAG_LTSH FT_MAKE_TAG( 'L', 'T', 'S', 'H' )
#define TTAG_LWFN FT_MAKE_TAG( 'L', 'W', 'F', 'N' )
#define TTAG_MATH FT_MAKE_TAG( 'M', 'A', 'T', 'H' )
#define TTAG_maxp FT_MAKE_TAG( 'm', 'a', 'x', 'p' )
#define TTAG_META FT_MAKE_TAG( 'M', 'E', 'T', 'A' )
#define TTAG_MMFX FT_MAKE_TAG( 'M', 'M', 'F', 'X' )
#define TTAG_MMSD FT_MAKE_TAG( 'M', 'M', 'S', 'D' )
#define TTAG_mort FT_MAKE_TAG( 'm', 'o', 'r', 't' )
#define TTAG_morx FT_MAKE_TAG( 'm', 'o', 'r', 'x' )
#define TTAG_name FT_MAKE_TAG( 'n', 'a', 'm', 'e' )
#define TTAG_opbd FT_MAKE_TAG( 'o', 'p', 'b', 'd' )
#define TTAG_OS2 FT_MAKE_TAG( 'O', 'S', '/', '2' )
#define TTAG_OTTO FT_MAKE_TAG( 'O', 'T', 'T', 'O' )
#define TTAG_PCLT FT_MAKE_TAG( 'P', 'C', 'L', 'T' )
#define TTAG_POST FT_MAKE_TAG( 'P', 'O', 'S', 'T' )
#define TTAG_post FT_MAKE_TAG( 'p', 'o', 's', 't' )
#define TTAG_prep FT_MAKE_TAG( 'p', 'r', 'e', 'p' )
#define TTAG_prop FT_MAKE_TAG( 'p', 'r', 'o', 'p' )
#define TTAG_sbix FT_MAKE_TAG( 's', 'b', 'i', 'x' )
#define TTAG_sfnt FT_MAKE_TAG( 's', 'f', 'n', 't' )
#define TTAG_SING FT_MAKE_TAG( 'S', 'I', 'N', 'G' )
#define TTAG_trak FT_MAKE_TAG( 't', 'r', 'a', 'k' )
#define TTAG_true FT_MAKE_TAG( 't', 'r', 'u', 'e' )
#define TTAG_ttc FT_MAKE_TAG( 't', 't', 'c', ' ' )
#define TTAG_ttcf FT_MAKE_TAG( 't', 't', 'c', 'f' )
#define TTAG_TYP1 FT_MAKE_TAG( 'T', 'Y', 'P', '1' )
#define TTAG_typ1 FT_MAKE_TAG( 't', 'y', 'p', '1' )
#define TTAG_VDMX FT_MAKE_TAG( 'V', 'D', 'M', 'X' )
#define TTAG_vhea FT_MAKE_TAG( 'v', 'h', 'e', 'a' )
#define TTAG_vmtx FT_MAKE_TAG( 'v', 'm', 't', 'x' )
#define TTAG_wOFF FT_MAKE_TAG( 'w', 'O', 'F', 'F' )
FT_END_HEADER
#endif /* __TTAGS_H__ */
/* END */
| YifuLiu/AliOS-Things | components/freetype/include/tttags.h | C | apache-2.0 | 5,214 |
/***************************************************************************/
/* */
/* ttunpat.h */
/* */
/* Definitions for the unpatented TrueType hinting system */
/* */
/* Copyright 2003, 2006 by */
/* David Turner, Robert Wilhelm, and Werner Lemberg. */
/* */
/* Written by Graham Asher <graham.asher@btinternet.com> */
/* */
/* 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. */
/* */
/***************************************************************************/
#ifndef __TTUNPAT_H__
#define __TTUNPAT_H__
#include <ft2build.h>
#include FT_FREETYPE_H
#ifdef FREETYPE_H
#error "freetype.h of FreeType 1 has been loaded!"
#error "Please fix the directory search order for header files"
#error "so that freetype.h of FreeType 2 is found first."
#endif
FT_BEGIN_HEADER
/***************************************************************************
*
* @constant:
* FT_PARAM_TAG_UNPATENTED_HINTING
*
* @description:
* A constant used as the tag of an @FT_Parameter structure to indicate
* that unpatented methods only should be used by the TrueType bytecode
* interpreter for a typeface opened by @FT_Open_Face.
*
*/
#define FT_PARAM_TAG_UNPATENTED_HINTING FT_MAKE_TAG( 'u', 'n', 'p', 'a' )
/* */
FT_END_HEADER
#endif /* __TTUNPAT_H__ */
/* END */
| YifuLiu/AliOS-Things | components/freetype/include/ttunpat.h | C | apache-2.0 | 2,229 |
/***************************************************************************/
/* */
/* afangles.c */
/* */
/* Routines used to compute vector angles with limited accuracy */
/* and very high speed. It also contains sorting routines (body). */
/* */
/* Copyright 2003-2006, 2011-2012 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. */
/* */
/***************************************************************************/
#include "aftypes.h"
#if 0
FT_LOCAL_DEF( FT_Int )
af_corner_is_flat( FT_Pos x_in,
FT_Pos y_in,
FT_Pos x_out,
FT_Pos y_out )
{
FT_Pos ax = x_in;
FT_Pos ay = y_in;
FT_Pos d_in, d_out, d_corner;
if ( ax < 0 )
ax = -ax;
if ( ay < 0 )
ay = -ay;
d_in = ax + ay;
ax = x_out;
if ( ax < 0 )
ax = -ax;
ay = y_out;
if ( ay < 0 )
ay = -ay;
d_out = ax + ay;
ax = x_out + x_in;
if ( ax < 0 )
ax = -ax;
ay = y_out + y_in;
if ( ay < 0 )
ay = -ay;
d_corner = ax + ay;
return ( d_in + d_out - d_corner ) < ( d_corner >> 4 );
}
FT_LOCAL_DEF( FT_Int )
af_corner_orientation( FT_Pos x_in,
FT_Pos y_in,
FT_Pos x_out,
FT_Pos y_out )
{
FT_Pos delta;
delta = x_in * y_out - y_in * x_out;
if ( delta == 0 )
return 0;
else
return 1 - 2 * ( delta < 0 );
}
#endif /* 0 */
/*
* We are not using `af_angle_atan' anymore, but we keep the source
* code below just in case...
*/
#if 0
/*
* The trick here is to realize that we don't need a very accurate angle
* approximation. We are going to use the result of `af_angle_atan' to
* only compare the sign of angle differences, or check whether its
* magnitude is very small.
*
* The approximation
*
* dy * PI / (|dx|+|dy|)
*
* should be enough, and much faster to compute.
*/
FT_LOCAL_DEF( AF_Angle )
af_angle_atan( FT_Fixed dx,
FT_Fixed dy )
{
AF_Angle angle;
FT_Fixed ax = dx;
FT_Fixed ay = dy;
if ( ax < 0 )
ax = -ax;
if ( ay < 0 )
ay = -ay;
ax += ay;
if ( ax == 0 )
angle = 0;
else
{
angle = ( AF_ANGLE_PI2 * dy ) / ( ax + ay );
if ( dx < 0 )
{
if ( angle >= 0 )
angle = AF_ANGLE_PI - angle;
else
angle = -AF_ANGLE_PI - angle;
}
}
return angle;
}
#elif 0
/* the following table has been automatically generated with */
/* the `mather.py' Python script */
#define AF_ATAN_BITS 8
static const FT_Byte af_arctan[1L << AF_ATAN_BITS] =
{
0, 0, 1, 1, 1, 2, 2, 2,
3, 3, 3, 3, 4, 4, 4, 5,
5, 5, 6, 6, 6, 7, 7, 7,
8, 8, 8, 9, 9, 9, 10, 10,
10, 10, 11, 11, 11, 12, 12, 12,
13, 13, 13, 14, 14, 14, 14, 15,
15, 15, 16, 16, 16, 17, 17, 17,
18, 18, 18, 18, 19, 19, 19, 20,
20, 20, 21, 21, 21, 21, 22, 22,
22, 23, 23, 23, 24, 24, 24, 24,
25, 25, 25, 26, 26, 26, 26, 27,
27, 27, 28, 28, 28, 28, 29, 29,
29, 30, 30, 30, 30, 31, 31, 31,
31, 32, 32, 32, 33, 33, 33, 33,
34, 34, 34, 34, 35, 35, 35, 35,
36, 36, 36, 36, 37, 37, 37, 38,
38, 38, 38, 39, 39, 39, 39, 40,
40, 40, 40, 41, 41, 41, 41, 42,
42, 42, 42, 42, 43, 43, 43, 43,
44, 44, 44, 44, 45, 45, 45, 45,
46, 46, 46, 46, 46, 47, 47, 47,
47, 48, 48, 48, 48, 48, 49, 49,
49, 49, 50, 50, 50, 50, 50, 51,
51, 51, 51, 51, 52, 52, 52, 52,
52, 53, 53, 53, 53, 53, 54, 54,
54, 54, 54, 55, 55, 55, 55, 55,
56, 56, 56, 56, 56, 57, 57, 57,
57, 57, 57, 58, 58, 58, 58, 58,
59, 59, 59, 59, 59, 59, 60, 60,
60, 60, 60, 61, 61, 61, 61, 61,
61, 62, 62, 62, 62, 62, 62, 63,
63, 63, 63, 63, 63, 64, 64, 64
};
FT_LOCAL_DEF( AF_Angle )
af_angle_atan( FT_Fixed dx,
FT_Fixed dy )
{
AF_Angle angle;
/* check trivial cases */
if ( dy == 0 )
{
angle = 0;
if ( dx < 0 )
angle = AF_ANGLE_PI;
return angle;
}
else if ( dx == 0 )
{
angle = AF_ANGLE_PI2;
if ( dy < 0 )
angle = -AF_ANGLE_PI2;
return angle;
}
angle = 0;
if ( dx < 0 )
{
dx = -dx;
dy = -dy;
angle = AF_ANGLE_PI;
}
if ( dy < 0 )
{
FT_Pos tmp;
tmp = dx;
dx = -dy;
dy = tmp;
angle -= AF_ANGLE_PI2;
}
if ( dx == 0 && dy == 0 )
return 0;
if ( dx == dy )
angle += AF_ANGLE_PI4;
else if ( dx > dy )
angle += af_arctan[FT_DivFix( dy, dx ) >> ( 16 - AF_ATAN_BITS )];
else
angle += AF_ANGLE_PI2 -
af_arctan[FT_DivFix( dx, dy ) >> ( 16 - AF_ATAN_BITS )];
if ( angle > AF_ANGLE_PI )
angle -= AF_ANGLE_2PI;
return angle;
}
#endif /* 0 */
FT_LOCAL_DEF( void )
af_sort_pos( FT_UInt count,
FT_Pos* table )
{
FT_UInt i, j;
FT_Pos swap;
for ( i = 1; i < count; i++ )
{
for ( j = i; j > 0; j-- )
{
if ( table[j] >= table[j - 1] )
break;
swap = table[j];
table[j] = table[j - 1];
table[j - 1] = swap;
}
}
}
FT_LOCAL_DEF( void )
af_sort_and_quantize_widths( FT_UInt* count,
AF_Width table,
FT_Pos threshold )
{
FT_UInt i, j;
FT_UInt cur_idx;
FT_Pos cur_val;
FT_Pos sum;
AF_WidthRec swap;
if ( *count == 1 )
return;
/* sort */
for ( i = 1; i < *count; i++ )
{
for ( j = i; j > 0; j-- )
{
if ( table[j].org >= table[j - 1].org )
break;
swap = table[j];
table[j] = table[j - 1];
table[j - 1] = swap;
}
}
cur_idx = 0;
cur_val = table[cur_idx].org;
/* compute and use mean values for clusters not larger than */
/* `threshold'; this is very primitive and might not yield */
/* the best result, but normally, using reference character */
/* `o', `*count' is 2, so the code below is fully sufficient */
for ( i = 1; i < *count; i++ )
{
if ( table[i].org - cur_val > threshold ||
i == *count - 1 )
{
sum = 0;
/* fix loop for end of array */
if ( table[i].org - cur_val <= threshold &&
i == *count - 1 )
i++;
for ( j = cur_idx; j < i; j++ )
{
sum += table[j].org;
table[j].org = 0;
}
table[cur_idx].org = sum / j;
if ( i < *count - 1 )
{
cur_idx = i + 1;
cur_val = table[cur_idx].org;
}
}
}
cur_idx = 1;
/* compress array to remove zero values */
for ( i = 1; i < *count; i++ )
{
if ( table[i].org )
table[cur_idx++] = table[i];
}
*count = cur_idx;
}
/* END */
| YifuLiu/AliOS-Things | components/freetype/src/autofit/afangles.c | C | apache-2.0 | 8,016 |
/*
* afangles.h
*
* This is a dummy file, used to please the build system. It is never
* included by the auto-fitter sources.
*
*/
| YifuLiu/AliOS-Things | components/freetype/src/autofit/afangles.h | C | apache-2.0 | 141 |
/***************************************************************************/
/* */
/* afcjk.c */
/* */
/* Auto-fitter hinting routines for CJK writing system (body). */
/* */
/* Copyright 2006-2013 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. */
/* */
/***************************************************************************/
/*
* The algorithm is based on akito's autohint patch, available here:
*
* http://www.kde.gr.jp/~akito/patch/freetype2/
*
*/
#include <ft2build.h>
#include FT_ADVANCES_H
#include FT_INTERNAL_DEBUG_H
#include "afglobal.h"
#include "afpic.h"
#include "aflatin.h"
#ifdef AF_CONFIG_OPTION_CJK
#undef AF_CONFIG_OPTION_CJK_BLUE_HANI_VERT
#include "afcjk.h"
#include "aferrors.h"
#ifdef AF_CONFIG_OPTION_USE_WARPER
#include "afwarp.h"
#endif
/*************************************************************************/
/* */
/* The macro FT_COMPONENT is used in trace mode. It is an implicit */
/* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */
/* messages during execution. */
/* */
#undef FT_COMPONENT
#define FT_COMPONENT trace_afcjk
/*************************************************************************/
/*************************************************************************/
/***** *****/
/***** C J K G L O B A L M E T R I C S *****/
/***** *****/
/*************************************************************************/
/*************************************************************************/
/* Basically the Latin version with AF_CJKMetrics */
/* to replace AF_LatinMetrics. */
FT_LOCAL_DEF( void )
af_cjk_metrics_init_widths( AF_CJKMetrics metrics,
FT_Face face )
{
/* scan the array of segments in each direction */
AF_GlyphHintsRec hints[1];
FT_TRACE5(( "\n"
"cjk standard widths computation (style `%s')\n"
"===================================================\n"
"\n",
af_style_names[metrics->root.style_class->style] ));
af_glyph_hints_init( hints, face->memory );
metrics->axis[AF_DIMENSION_HORZ].width_count = 0;
metrics->axis[AF_DIMENSION_VERT].width_count = 0;
{
FT_Error error;
FT_ULong glyph_index;
FT_Long y_offset;
int dim;
AF_CJKMetricsRec dummy[1];
AF_Scaler scaler = &dummy->root.scaler;
#ifdef FT_CONFIG_OPTION_PIC
AF_FaceGlobals globals = metrics->root.globals;
#endif
AF_StyleClass style_class = metrics->root.style_class;
AF_ScriptClass script_class = AF_SCRIPT_CLASSES_GET
[style_class->script];
FT_UInt32 standard_char;
standard_char = script_class->standard_char1;
af_get_char_index( &metrics->root,
standard_char,
&glyph_index,
&y_offset );
if ( !glyph_index )
{
if ( script_class->standard_char2 )
{
standard_char = script_class->standard_char2;
af_get_char_index( &metrics->root,
standard_char,
&glyph_index,
&y_offset );
if ( !glyph_index )
{
if ( script_class->standard_char3 )
{
standard_char = script_class->standard_char3;
af_get_char_index( &metrics->root,
standard_char,
&glyph_index,
&y_offset );
if ( !glyph_index )
goto Exit;
}
else
goto Exit;
}
}
else
goto Exit;
}
FT_TRACE5(( "standard character: U+%04lX (glyph index %d)\n",
standard_char, glyph_index ));
error = FT_Load_Glyph( face, glyph_index, FT_LOAD_NO_SCALE );
if ( error || face->glyph->outline.n_points <= 0 )
goto Exit;
FT_ZERO( dummy );
dummy->units_per_em = metrics->units_per_em;
scaler->x_scale = 0x10000L;
scaler->y_scale = 0x10000L;
scaler->x_delta = 0;
scaler->y_delta = 0;
scaler->face = face;
scaler->render_mode = FT_RENDER_MODE_NORMAL;
scaler->flags = 0;
af_glyph_hints_rescale( hints, (AF_StyleMetrics)dummy );
error = af_glyph_hints_reload( hints, &face->glyph->outline );
if ( error )
goto Exit;
for ( dim = 0; dim < AF_DIMENSION_MAX; dim++ )
{
AF_CJKAxis axis = &metrics->axis[dim];
AF_AxisHints axhints = &hints->axis[dim];
AF_Segment seg, limit, link;
FT_UInt num_widths = 0;
error = af_latin_hints_compute_segments( hints,
(AF_Dimension)dim );
if ( error )
goto Exit;
af_latin_hints_link_segments( hints,
(AF_Dimension)dim );
seg = axhints->segments;
limit = seg + axhints->num_segments;
for ( ; seg < limit; seg++ )
{
link = seg->link;
/* we only consider stem segments there! */
if ( link && link->link == seg && link > seg )
{
FT_Pos dist;
dist = seg->pos - link->pos;
if ( dist < 0 )
dist = -dist;
if ( num_widths < AF_CJK_MAX_WIDTHS )
axis->widths[num_widths++].org = dist;
}
}
/* this also replaces multiple almost identical stem widths */
/* with a single one (the value 100 is heuristic) */
af_sort_and_quantize_widths( &num_widths, axis->widths,
dummy->units_per_em / 100 );
axis->width_count = num_widths;
}
Exit:
for ( dim = 0; dim < AF_DIMENSION_MAX; dim++ )
{
AF_CJKAxis axis = &metrics->axis[dim];
FT_Pos stdw;
stdw = ( axis->width_count > 0 ) ? axis->widths[0].org
: AF_LATIN_CONSTANT( metrics, 50 );
/* let's try 20% of the smallest width */
axis->edge_distance_threshold = stdw / 5;
axis->standard_width = stdw;
axis->extra_light = 0;
#ifdef FT_DEBUG_LEVEL_TRACE
{
FT_UInt i;
FT_TRACE5(( "%s widths:\n",
dim == AF_DIMENSION_VERT ? "horizontal"
: "vertical" ));
FT_TRACE5(( " %d (standard)", axis->standard_width ));
for ( i = 1; i < axis->width_count; i++ )
FT_TRACE5(( " %d", axis->widths[i].org ));
FT_TRACE5(( "\n" ));
}
#endif
}
}
FT_TRACE5(( "\n" ));
af_glyph_hints_done( hints );
}
/* Find all blue zones. */
static void
af_cjk_metrics_init_blues( AF_CJKMetrics metrics,
FT_Face face )
{
FT_Pos fills[AF_BLUE_STRING_MAX_LEN];
FT_Pos flats[AF_BLUE_STRING_MAX_LEN];
FT_Int num_fills;
FT_Int num_flats;
AF_CJKBlue blue;
FT_Error error;
AF_CJKAxis axis;
FT_Outline outline;
AF_StyleClass sc = metrics->root.style_class;
AF_Blue_Stringset bss = sc->blue_stringset;
const AF_Blue_StringRec* bs = &af_blue_stringsets[bss];
#ifdef FT_DEBUG_LEVEL_TRACE
FT_String* cjk_blue_name[4] =
{
(FT_String*)"bottom", /* -- , -- */
(FT_String*)"top", /* -- , TOP */
(FT_String*)"left", /* HORIZ, -- */
(FT_String*)"right" /* HORIZ, TOP */
};
FT_String* cjk_blue_type_name[2] =
{
(FT_String*)"unfilled", /* -- */
(FT_String*)"filled" /* FILL */
};
#endif
/* we walk over the blue character strings as specified in the */
/* style's entry in the `af_blue_stringset' array, computing its */
/* extremum points (depending on the string properties) */
FT_TRACE5(( "cjk blue zones computation\n"
"==========================\n"
"\n" ));
for ( ; bs->string != AF_BLUE_STRING_MAX; bs++ )
{
const char* p = &af_blue_strings[bs->string];
FT_Pos* blue_ref;
FT_Pos* blue_shoot;
if ( AF_CJK_IS_HORIZ_BLUE( bs ) )
axis = &metrics->axis[AF_DIMENSION_HORZ];
else
axis = &metrics->axis[AF_DIMENSION_VERT];
FT_TRACE5(( "blue zone %d:\n", axis->blue_count ));
num_fills = 0;
num_flats = 0;
FT_TRACE5(( " cjk blue %s/%s\n",
cjk_blue_name[AF_CJK_IS_HORIZ_BLUE( bs ) |
AF_CJK_IS_TOP_BLUE( bs ) ],
cjk_blue_type_name[!!AF_CJK_IS_FILLED_BLUE( bs )] ));
while ( *p )
{
FT_ULong ch;
FT_ULong glyph_index;
FT_Long y_offset;
FT_Pos best_pos; /* same as points.y or points.x, resp. */
FT_Int best_point;
FT_Vector* points;
GET_UTF8_CHAR( ch, p );
/* load the character in the face -- skip unknown or empty ones */
af_get_char_index( &metrics->root, ch, &glyph_index, &y_offset );
if ( glyph_index == 0 )
{
FT_TRACE5(( " U+%04lX unavailable\n", ch ));
continue;
}
error = FT_Load_Glyph( face, glyph_index, FT_LOAD_NO_SCALE );
outline = face->glyph->outline;
if ( error || outline.n_points <= 0 )
{
FT_TRACE5(( " U+%04lX contains no outlines\n", ch ));
continue;
}
/* now compute min or max point indices and coordinates */
points = outline.points;
best_point = -1;
best_pos = 0; /* make compiler happy */
{
FT_Int nn;
FT_Int first = 0;
FT_Int last = -1;
for ( nn = 0; nn < outline.n_contours; first = last + 1, nn++ )
{
FT_Int pp;
last = outline.contours[nn];
/* Avoid single-point contours since they are never rasterized. */
/* In some fonts, they correspond to mark attachment points */
/* which are way outside of the glyph's real outline. */
if ( last <= first )
continue;
if ( AF_CJK_IS_HORIZ_BLUE( bs ) )
{
if ( AF_CJK_IS_RIGHT_BLUE( bs ) )
{
for ( pp = first; pp <= last; pp++ )
if ( best_point < 0 || points[pp].x > best_pos )
{
best_point = pp;
best_pos = points[pp].x;
}
}
else
{
for ( pp = first; pp <= last; pp++ )
if ( best_point < 0 || points[pp].x < best_pos )
{
best_point = pp;
best_pos = points[pp].x;
}
}
}
else
{
if ( AF_CJK_IS_TOP_BLUE( bs ) )
{
for ( pp = first; pp <= last; pp++ )
if ( best_point < 0 || points[pp].y > best_pos )
{
best_point = pp;
best_pos = points[pp].y;
}
}
else
{
for ( pp = first; pp <= last; pp++ )
if ( best_point < 0 || points[pp].y < best_pos )
{
best_point = pp;
best_pos = points[pp].y;
}
}
}
}
FT_TRACE5(( " U+%04lX: best_pos = %5ld\n", ch, best_pos ));
}
if ( AF_CJK_IS_FILLED_BLUE( bs ) )
fills[num_fills++] = best_pos;
else
flats[num_flats++] = best_pos;
}
if ( num_flats == 0 && num_fills == 0 )
{
/*
* we couldn't find a single glyph to compute this blue zone,
* we will simply ignore it then
*/
FT_TRACE5(( " empty\n" ));
continue;
}
/* we have computed the contents of the `fill' and `flats' tables, */
/* now determine the reference position of the blue zone -- */
/* we simply take the median value after a simple sort */
af_sort_pos( num_flats, flats );
af_sort_pos( num_fills, fills );
blue = &axis->blues[axis->blue_count];
blue_ref = &blue->ref.org;
blue_shoot = &blue->shoot.org;
axis->blue_count++;
if ( num_flats == 0 )
{
*blue_ref =
*blue_shoot = fills[num_fills / 2];
}
else if ( num_fills == 0 )
{
*blue_ref =
*blue_shoot = flats[num_flats / 2];
}
else
{
*blue_ref = fills[num_fills / 2];
*blue_shoot = flats[num_flats / 2];
}
/* make sure blue_ref >= blue_shoot for top/right or */
/* vice versa for bottom/left */
if ( *blue_shoot != *blue_ref )
{
FT_Pos ref = *blue_ref;
FT_Pos shoot = *blue_shoot;
FT_Bool under_ref = FT_BOOL( shoot < ref );
/* AF_CJK_IS_TOP_BLUE covers `right' and `top' */
if ( AF_CJK_IS_TOP_BLUE( bs ) ^ under_ref )
{
*blue_ref =
*blue_shoot = ( shoot + ref ) / 2;
FT_TRACE5(( " [overshoot smaller than reference,"
" taking mean value]\n" ));
}
}
blue->flags = 0;
if ( AF_CJK_IS_TOP_BLUE( bs ) )
blue->flags |= AF_CJK_BLUE_TOP;
FT_TRACE5(( " -> reference = %ld\n"
" overshoot = %ld\n",
*blue_ref, *blue_shoot ));
}
FT_TRACE5(( "\n" ));
return;
}
/* Basically the Latin version with type AF_CJKMetrics for metrics. */
FT_LOCAL_DEF( void )
af_cjk_metrics_check_digits( AF_CJKMetrics metrics,
FT_Face face )
{
FT_UInt i;
FT_Bool started = 0, same_width = 1;
FT_Fixed advance, old_advance = 0;
/* digit `0' is 0x30 in all supported charmaps */
for ( i = 0x30; i <= 0x39; i++ )
{
FT_ULong glyph_index;
FT_Long y_offset;
af_get_char_index( &metrics->root, i, &glyph_index, &y_offset );
if ( glyph_index == 0 )
continue;
if ( FT_Get_Advance( face, glyph_index,
FT_LOAD_NO_SCALE |
FT_LOAD_NO_HINTING |
FT_LOAD_IGNORE_TRANSFORM,
&advance ) )
continue;
if ( started )
{
if ( advance != old_advance )
{
same_width = 0;
break;
}
}
else
{
old_advance = advance;
started = 1;
}
}
metrics->root.digits_have_same_width = same_width;
}
/* Initialize global metrics. */
FT_LOCAL_DEF( FT_Error )
af_cjk_metrics_init( AF_CJKMetrics metrics,
FT_Face face )
{
FT_CharMap oldmap = face->charmap;
metrics->units_per_em = face->units_per_EM;
if ( !FT_Select_Charmap( face, FT_ENCODING_UNICODE ) )
{
af_cjk_metrics_init_widths( metrics, face );
af_cjk_metrics_init_blues( metrics, face );
af_cjk_metrics_check_digits( metrics, face );
}
FT_Set_Charmap( face, oldmap );
return FT_Err_Ok;
}
/* Adjust scaling value, then scale and shift widths */
/* and blue zones (if applicable) for given dimension. */
static void
af_cjk_metrics_scale_dim( AF_CJKMetrics metrics,
AF_Scaler scaler,
AF_Dimension dim )
{
FT_Fixed scale;
FT_Pos delta;
AF_CJKAxis axis;
FT_UInt nn;
if ( dim == AF_DIMENSION_HORZ )
{
scale = scaler->x_scale;
delta = scaler->x_delta;
}
else
{
scale = scaler->y_scale;
delta = scaler->y_delta;
}
axis = &metrics->axis[dim];
if ( axis->org_scale == scale && axis->org_delta == delta )
return;
axis->org_scale = scale;
axis->org_delta = delta;
axis->scale = scale;
axis->delta = delta;
/* scale the blue zones */
for ( nn = 0; nn < axis->blue_count; nn++ )
{
AF_CJKBlue blue = &axis->blues[nn];
FT_Pos dist;
blue->ref.cur = FT_MulFix( blue->ref.org, scale ) + delta;
blue->ref.fit = blue->ref.cur;
blue->shoot.cur = FT_MulFix( blue->shoot.org, scale ) + delta;
blue->shoot.fit = blue->shoot.cur;
blue->flags &= ~AF_CJK_BLUE_ACTIVE;
/* a blue zone is only active if it is less than 3/4 pixels tall */
dist = FT_MulFix( blue->ref.org - blue->shoot.org, scale );
if ( dist <= 48 && dist >= -48 )
{
FT_Pos delta1, delta2;
blue->ref.fit = FT_PIX_ROUND( blue->ref.cur );
/* shoot is under shoot for cjk */
delta1 = FT_DivFix( blue->ref.fit, scale ) - blue->shoot.org;
delta2 = delta1;
if ( delta1 < 0 )
delta2 = -delta2;
delta2 = FT_MulFix( delta2, scale );
FT_TRACE5(( "delta: %d", delta1 ));
if ( delta2 < 32 )
delta2 = 0;
#if 0
else if ( delta2 < 64 )
delta2 = 32 + ( ( ( delta2 - 32 ) + 16 ) & ~31 );
#endif
else
delta2 = FT_PIX_ROUND( delta2 );
FT_TRACE5(( "/%d\n", delta2 ));
if ( delta1 < 0 )
delta2 = -delta2;
blue->shoot.fit = blue->ref.fit - delta2;
FT_TRACE5(( ">> active cjk blue zone %c%d[%ld/%ld]:\n"
" ref: cur=%.2f fit=%.2f\n"
" shoot: cur=%.2f fit=%.2f\n",
( dim == AF_DIMENSION_HORZ ) ? 'H' : 'V',
nn, blue->ref.org, blue->shoot.org,
blue->ref.cur / 64.0, blue->ref.fit / 64.0,
blue->shoot.cur / 64.0, blue->shoot.fit / 64.0 ));
blue->flags |= AF_CJK_BLUE_ACTIVE;
}
}
}
/* Scale global values in both directions. */
FT_LOCAL_DEF( void )
af_cjk_metrics_scale( AF_CJKMetrics metrics,
AF_Scaler scaler )
{
/* we copy the whole structure since the x and y scaling values */
/* are not modified, contrary to e.g. the `latin' auto-hinter */
metrics->root.scaler = *scaler;
af_cjk_metrics_scale_dim( metrics, scaler, AF_DIMENSION_HORZ );
af_cjk_metrics_scale_dim( metrics, scaler, AF_DIMENSION_VERT );
}
/*************************************************************************/
/*************************************************************************/
/***** *****/
/***** C J K G L Y P H A N A L Y S I S *****/
/***** *****/
/*************************************************************************/
/*************************************************************************/
/* Walk over all contours and compute its segments. */
static FT_Error
af_cjk_hints_compute_segments( AF_GlyphHints hints,
AF_Dimension dim )
{
AF_AxisHints axis = &hints->axis[dim];
AF_Segment segments = axis->segments;
AF_Segment segment_limit = segments + axis->num_segments;
FT_Error error;
AF_Segment seg;
error = af_latin_hints_compute_segments( hints, dim );
if ( error )
return error;
/* a segment is round if it doesn't have successive */
/* on-curve points. */
for ( seg = segments; seg < segment_limit; seg++ )
{
AF_Point pt = seg->first;
AF_Point last = seg->last;
AF_Flags f0 = (AF_Flags)( pt->flags & AF_FLAG_CONTROL );
AF_Flags f1;
seg->flags &= ~AF_EDGE_ROUND;
for ( ; pt != last; f0 = f1 )
{
pt = pt->next;
f1 = (AF_Flags)( pt->flags & AF_FLAG_CONTROL );
if ( !f0 && !f1 )
break;
if ( pt == last )
seg->flags |= AF_EDGE_ROUND;
}
}
return FT_Err_Ok;
}
static void
af_cjk_hints_link_segments( AF_GlyphHints hints,
AF_Dimension dim )
{
AF_AxisHints axis = &hints->axis[dim];
AF_Segment segments = axis->segments;
AF_Segment segment_limit = segments + axis->num_segments;
AF_Direction major_dir = axis->major_dir;
AF_Segment seg1, seg2;
FT_Pos len_threshold;
FT_Pos dist_threshold;
len_threshold = AF_LATIN_CONSTANT( hints->metrics, 8 );
dist_threshold = ( dim == AF_DIMENSION_HORZ ) ? hints->x_scale
: hints->y_scale;
dist_threshold = FT_DivFix( 64 * 3, dist_threshold );
/* now compare each segment to the others */
for ( seg1 = segments; seg1 < segment_limit; seg1++ )
{
/* the fake segments are for metrics hinting only */
if ( seg1->first == seg1->last )
continue;
if ( seg1->dir != major_dir )
continue;
for ( seg2 = segments; seg2 < segment_limit; seg2++ )
if ( seg2 != seg1 && seg1->dir + seg2->dir == 0 )
{
FT_Pos dist = seg2->pos - seg1->pos;
if ( dist < 0 )
continue;
{
FT_Pos min = seg1->min_coord;
FT_Pos max = seg1->max_coord;
FT_Pos len;
if ( min < seg2->min_coord )
min = seg2->min_coord;
if ( max > seg2->max_coord )
max = seg2->max_coord;
len = max - min;
if ( len >= len_threshold )
{
if ( dist * 8 < seg1->score * 9 &&
( dist * 8 < seg1->score * 7 || seg1->len < len ) )
{
seg1->score = dist;
seg1->len = len;
seg1->link = seg2;
}
if ( dist * 8 < seg2->score * 9 &&
( dist * 8 < seg2->score * 7 || seg2->len < len ) )
{
seg2->score = dist;
seg2->len = len;
seg2->link = seg1;
}
}
}
}
}
/*
* now compute the `serif' segments
*
* In Hanzi, some strokes are wider on one or both of the ends.
* We either identify the stems on the ends as serifs or remove
* the linkage, depending on the length of the stems.
*
*/
{
AF_Segment link1, link2;
for ( seg1 = segments; seg1 < segment_limit; seg1++ )
{
link1 = seg1->link;
if ( !link1 || link1->link != seg1 || link1->pos <= seg1->pos )
continue;
if ( seg1->score >= dist_threshold )
continue;
for ( seg2 = segments; seg2 < segment_limit; seg2++ )
{
if ( seg2->pos > seg1->pos || seg1 == seg2 )
continue;
link2 = seg2->link;
if ( !link2 || link2->link != seg2 || link2->pos < link1->pos )
continue;
if ( seg1->pos == seg2->pos && link1->pos == link2->pos )
continue;
if ( seg2->score <= seg1->score || seg1->score * 4 <= seg2->score )
continue;
/* seg2 < seg1 < link1 < link2 */
if ( seg1->len >= seg2->len * 3 )
{
AF_Segment seg;
for ( seg = segments; seg < segment_limit; seg++ )
{
AF_Segment link = seg->link;
if ( link == seg2 )
{
seg->link = 0;
seg->serif = link1;
}
else if ( link == link2 )
{
seg->link = 0;
seg->serif = seg1;
}
}
}
else
{
seg1->link = link1->link = 0;
break;
}
}
}
}
for ( seg1 = segments; seg1 < segment_limit; seg1++ )
{
seg2 = seg1->link;
if ( seg2 )
{
seg2->num_linked++;
if ( seg2->link != seg1 )
{
seg1->link = 0;
if ( seg2->score < dist_threshold || seg1->score < seg2->score * 4 )
seg1->serif = seg2->link;
else
seg2->num_linked--;
}
}
}
}
static FT_Error
af_cjk_hints_compute_edges( AF_GlyphHints hints,
AF_Dimension dim )
{
AF_AxisHints axis = &hints->axis[dim];
FT_Error error = FT_Err_Ok;
FT_Memory memory = hints->memory;
AF_CJKAxis laxis = &((AF_CJKMetrics)hints->metrics)->axis[dim];
AF_Segment segments = axis->segments;
AF_Segment segment_limit = segments + axis->num_segments;
AF_Segment seg;
FT_Fixed scale;
FT_Pos edge_distance_threshold;
axis->num_edges = 0;
scale = ( dim == AF_DIMENSION_HORZ ) ? hints->x_scale
: hints->y_scale;
/*********************************************************************/
/* */
/* We begin by generating a sorted table of edges for the current */
/* direction. To do so, we simply scan each segment and try to find */
/* an edge in our table that corresponds to its position. */
/* */
/* If no edge is found, we create and insert a new edge in the */
/* sorted table. Otherwise, we simply add the segment to the edge's */
/* list which is then processed in the second step to compute the */
/* edge's properties. */
/* */
/* Note that the edges table is sorted along the segment/edge */
/* position. */
/* */
/*********************************************************************/
edge_distance_threshold = FT_MulFix( laxis->edge_distance_threshold,
scale );
if ( edge_distance_threshold > 64 / 4 )
edge_distance_threshold = FT_DivFix( 64 / 4, scale );
else
edge_distance_threshold = laxis->edge_distance_threshold;
for ( seg = segments; seg < segment_limit; seg++ )
{
AF_Edge found = NULL;
FT_Pos best = 0xFFFFU;
FT_Int ee;
/* look for an edge corresponding to the segment */
for ( ee = 0; ee < axis->num_edges; ee++ )
{
AF_Edge edge = axis->edges + ee;
FT_Pos dist;
if ( edge->dir != seg->dir )
continue;
dist = seg->pos - edge->fpos;
if ( dist < 0 )
dist = -dist;
if ( dist < edge_distance_threshold && dist < best )
{
AF_Segment link = seg->link;
/* check whether all linked segments of the candidate edge */
/* can make a single edge. */
if ( link )
{
AF_Segment seg1 = edge->first;
FT_Pos dist2 = 0;
do
{
AF_Segment link1 = seg1->link;
if ( link1 )
{
dist2 = AF_SEGMENT_DIST( link, link1 );
if ( dist2 >= edge_distance_threshold )
break;
}
} while ( ( seg1 = seg1->edge_next ) != edge->first );
if ( dist2 >= edge_distance_threshold )
continue;
}
best = dist;
found = edge;
}
}
if ( !found )
{
AF_Edge edge;
/* insert a new edge in the list and */
/* sort according to the position */
error = af_axis_hints_new_edge( axis, seg->pos,
(AF_Direction)seg->dir,
memory, &edge );
if ( error )
goto Exit;
/* add the segment to the new edge's list */
FT_ZERO( edge );
edge->first = seg;
edge->last = seg;
edge->fpos = seg->pos;
edge->opos = edge->pos = FT_MulFix( seg->pos, scale );
seg->edge_next = seg;
edge->dir = seg->dir;
}
else
{
/* if an edge was found, simply add the segment to the edge's */
/* list */
seg->edge_next = found->first;
found->last->edge_next = seg;
found->last = seg;
}
}
/******************************************************************/
/* */
/* Good, we now compute each edge's properties according to the */
/* segments found on its position. Basically, these are */
/* */
/* - the edge's main direction */
/* - stem edge, serif edge or both (which defaults to stem then) */
/* - rounded edge, straight or both (which defaults to straight) */
/* - link for edge */
/* */
/******************************************************************/
/* first of all, set the `edge' field in each segment -- this is */
/* required in order to compute edge links */
/*
* Note that removing this loop and setting the `edge' field of each
* segment directly in the code above slows down execution speed for
* some reasons on platforms like the Sun.
*/
{
AF_Edge edges = axis->edges;
AF_Edge edge_limit = edges + axis->num_edges;
AF_Edge edge;
for ( edge = edges; edge < edge_limit; edge++ )
{
seg = edge->first;
if ( seg )
do
{
seg->edge = edge;
seg = seg->edge_next;
} while ( seg != edge->first );
}
/* now compute each edge properties */
for ( edge = edges; edge < edge_limit; edge++ )
{
FT_Int is_round = 0; /* does it contain round segments? */
FT_Int is_straight = 0; /* does it contain straight segments? */
seg = edge->first;
do
{
FT_Bool is_serif;
/* check for roundness of segment */
if ( seg->flags & AF_EDGE_ROUND )
is_round++;
else
is_straight++;
/* check for links -- if seg->serif is set, then seg->link must */
/* be ignored */
is_serif = (FT_Bool)( seg->serif && seg->serif->edge != edge );
if ( seg->link || is_serif )
{
AF_Edge edge2;
AF_Segment seg2;
edge2 = edge->link;
seg2 = seg->link;
if ( is_serif )
{
seg2 = seg->serif;
edge2 = edge->serif;
}
if ( edge2 )
{
FT_Pos edge_delta;
FT_Pos seg_delta;
edge_delta = edge->fpos - edge2->fpos;
if ( edge_delta < 0 )
edge_delta = -edge_delta;
seg_delta = AF_SEGMENT_DIST( seg, seg2 );
if ( seg_delta < edge_delta )
edge2 = seg2->edge;
}
else
edge2 = seg2->edge;
if ( is_serif )
{
edge->serif = edge2;
edge2->flags |= AF_EDGE_SERIF;
}
else
edge->link = edge2;
}
seg = seg->edge_next;
} while ( seg != edge->first );
/* set the round/straight flags */
edge->flags = AF_EDGE_NORMAL;
if ( is_round > 0 && is_round >= is_straight )
edge->flags |= AF_EDGE_ROUND;
/* get rid of serifs if link is set */
/* XXX: This gets rid of many unpleasant artefacts! */
/* Example: the `c' in cour.pfa at size 13 */
if ( edge->serif && edge->link )
edge->serif = 0;
}
}
Exit:
return error;
}
/* Detect segments and edges for given dimension. */
static FT_Error
af_cjk_hints_detect_features( AF_GlyphHints hints,
AF_Dimension dim )
{
FT_Error error;
error = af_cjk_hints_compute_segments( hints, dim );
if ( !error )
{
af_cjk_hints_link_segments( hints, dim );
error = af_cjk_hints_compute_edges( hints, dim );
}
return error;
}
/* Compute all edges which lie within blue zones. */
FT_LOCAL_DEF( void )
af_cjk_hints_compute_blue_edges( AF_GlyphHints hints,
AF_CJKMetrics metrics,
AF_Dimension dim )
{
AF_AxisHints axis = &hints->axis[dim];
AF_Edge edge = axis->edges;
AF_Edge edge_limit = edge + axis->num_edges;
AF_CJKAxis cjk = &metrics->axis[dim];
FT_Fixed scale = cjk->scale;
FT_Pos best_dist0; /* initial threshold */
/* compute the initial threshold as a fraction of the EM size */
best_dist0 = FT_MulFix( metrics->units_per_em / 40, scale );
if ( best_dist0 > 64 / 2 ) /* maximum 1/2 pixel */
best_dist0 = 64 / 2;
/* compute which blue zones are active, i.e. have their scaled */
/* size < 3/4 pixels */
/* If the distant between an edge and a blue zone is shorter than */
/* best_dist0, set the blue zone for the edge. Then search for */
/* the blue zone with the smallest best_dist to the edge. */
for ( ; edge < edge_limit; edge++ )
{
FT_UInt bb;
AF_Width best_blue = NULL;
FT_Pos best_dist = best_dist0;
for ( bb = 0; bb < cjk->blue_count; bb++ )
{
AF_CJKBlue blue = cjk->blues + bb;
FT_Bool is_top_right_blue, is_major_dir;
/* skip inactive blue zones (i.e., those that are too small) */
if ( !( blue->flags & AF_CJK_BLUE_ACTIVE ) )
continue;
/* if it is a top zone, check for right edges -- if it is a bottom */
/* zone, check for left edges */
/* */
/* of course, that's for TrueType */
is_top_right_blue = FT_BOOL( blue->flags & AF_CJK_BLUE_TOP );
is_major_dir = FT_BOOL( edge->dir == axis->major_dir );
/* if it is a top zone, the edge must be against the major */
/* direction; if it is a bottom zone, it must be in the major */
/* direction */
if ( is_top_right_blue ^ is_major_dir )
{
FT_Pos dist;
AF_Width compare;
/* Compare the edge to the closest blue zone type */
if ( FT_ABS( edge->fpos - blue->ref.org ) >
FT_ABS( edge->fpos - blue->shoot.org ) )
compare = &blue->shoot;
else
compare = &blue->ref;
dist = edge->fpos - compare->org;
if ( dist < 0 )
dist = -dist;
dist = FT_MulFix( dist, scale );
if ( dist < best_dist )
{
best_dist = dist;
best_blue = compare;
}
}
}
if ( best_blue )
edge->blue_edge = best_blue;
}
}
/* Initalize hinting engine. */
FT_LOCAL_DEF( FT_Error )
af_cjk_hints_init( AF_GlyphHints hints,
AF_CJKMetrics metrics )
{
FT_Render_Mode mode;
FT_UInt32 scaler_flags, other_flags;
af_glyph_hints_rescale( hints, (AF_StyleMetrics)metrics );
/*
* correct x_scale and y_scale when needed, since they may have
* been modified af_cjk_scale_dim above
*/
hints->x_scale = metrics->axis[AF_DIMENSION_HORZ].scale;
hints->x_delta = metrics->axis[AF_DIMENSION_HORZ].delta;
hints->y_scale = metrics->axis[AF_DIMENSION_VERT].scale;
hints->y_delta = metrics->axis[AF_DIMENSION_VERT].delta;
/* compute flags depending on render mode, etc. */
mode = metrics->root.scaler.render_mode;
#ifdef AF_CONFIG_OPTION_USE_WARPER
if ( mode == FT_RENDER_MODE_LCD || mode == FT_RENDER_MODE_LCD_V )
metrics->root.scaler.render_mode = mode = FT_RENDER_MODE_NORMAL;
#endif
scaler_flags = hints->scaler_flags;
other_flags = 0;
/*
* We snap the width of vertical stems for the monochrome and
* horizontal LCD rendering targets only.
*/
if ( mode == FT_RENDER_MODE_MONO || mode == FT_RENDER_MODE_LCD )
other_flags |= AF_LATIN_HINTS_HORZ_SNAP;
/*
* We snap the width of horizontal stems for the monochrome and
* vertical LCD rendering targets only.
*/
if ( mode == FT_RENDER_MODE_MONO || mode == FT_RENDER_MODE_LCD_V )
other_flags |= AF_LATIN_HINTS_VERT_SNAP;
/*
* We adjust stems to full pixels only if we don't use the `light' mode.
*/
if ( mode != FT_RENDER_MODE_LIGHT )
other_flags |= AF_LATIN_HINTS_STEM_ADJUST;
if ( mode == FT_RENDER_MODE_MONO )
other_flags |= AF_LATIN_HINTS_MONO;
scaler_flags |= AF_SCALER_FLAG_NO_ADVANCE;
hints->scaler_flags = scaler_flags;
hints->other_flags = other_flags;
return FT_Err_Ok;
}
/*************************************************************************/
/*************************************************************************/
/***** *****/
/***** C J K G L Y P H G R I D - F I T T I N G *****/
/***** *****/
/*************************************************************************/
/*************************************************************************/
/* Snap a given width in scaled coordinates to one of the */
/* current standard widths. */
static FT_Pos
af_cjk_snap_width( AF_Width widths,
FT_Int count,
FT_Pos width )
{
int n;
FT_Pos best = 64 + 32 + 2;
FT_Pos reference = width;
FT_Pos scaled;
for ( n = 0; n < count; n++ )
{
FT_Pos w;
FT_Pos dist;
w = widths[n].cur;
dist = width - w;
if ( dist < 0 )
dist = -dist;
if ( dist < best )
{
best = dist;
reference = w;
}
}
scaled = FT_PIX_ROUND( reference );
if ( width >= reference )
{
if ( width < scaled + 48 )
width = reference;
}
else
{
if ( width > scaled - 48 )
width = reference;
}
return width;
}
/* Compute the snapped width of a given stem. */
/* There is a lot of voodoo in this function; changing the hard-coded */
/* parameters influence the whole hinting process. */
static FT_Pos
af_cjk_compute_stem_width( AF_GlyphHints hints,
AF_Dimension dim,
FT_Pos width,
AF_Edge_Flags base_flags,
AF_Edge_Flags stem_flags )
{
AF_CJKMetrics metrics = (AF_CJKMetrics)hints->metrics;
AF_CJKAxis axis = &metrics->axis[dim];
FT_Pos dist = width;
FT_Int sign = 0;
FT_Bool vertical = FT_BOOL( dim == AF_DIMENSION_VERT );
FT_UNUSED( base_flags );
FT_UNUSED( stem_flags );
if ( !AF_LATIN_HINTS_DO_STEM_ADJUST( hints ) )
return width;
if ( dist < 0 )
{
dist = -width;
sign = 1;
}
if ( ( vertical && !AF_LATIN_HINTS_DO_VERT_SNAP( hints ) ) ||
( !vertical && !AF_LATIN_HINTS_DO_HORZ_SNAP( hints ) ) )
{
/* smooth hinting process: very lightly quantize the stem width */
if ( axis->width_count > 0 )
{
if ( FT_ABS( dist - axis->widths[0].cur ) < 40 )
{
dist = axis->widths[0].cur;
if ( dist < 48 )
dist = 48;
goto Done_Width;
}
}
if ( dist < 54 )
dist += ( 54 - dist ) / 2 ;
else if ( dist < 3 * 64 )
{
FT_Pos delta;
delta = dist & 63;
dist &= -64;
if ( delta < 10 )
dist += delta;
else if ( delta < 22 )
dist += 10;
else if ( delta < 42 )
dist += delta;
else if ( delta < 54 )
dist += 54;
else
dist += delta;
}
}
else
{
/* strong hinting process: snap the stem width to integer pixels */
dist = af_cjk_snap_width( axis->widths, axis->width_count, dist );
if ( vertical )
{
/* in the case of vertical hinting, always round */
/* the stem heights to integer pixels */
if ( dist >= 64 )
dist = ( dist + 16 ) & ~63;
else
dist = 64;
}
else
{
if ( AF_LATIN_HINTS_DO_MONO( hints ) )
{
/* monochrome horizontal hinting: snap widths to integer pixels */
/* with a different threshold */
if ( dist < 64 )
dist = 64;
else
dist = ( dist + 32 ) & ~63;
}
else
{
/* for horizontal anti-aliased hinting, we adopt a more subtle */
/* approach: we strengthen small stems, round stems whose size */
/* is between 1 and 2 pixels to an integer, otherwise nothing */
if ( dist < 48 )
dist = ( dist + 64 ) >> 1;
else if ( dist < 128 )
dist = ( dist + 22 ) & ~63;
else
/* round otherwise to prevent color fringes in LCD mode */
dist = ( dist + 32 ) & ~63;
}
}
}
Done_Width:
if ( sign )
dist = -dist;
return dist;
}
/* Align one stem edge relative to the previous stem edge. */
static void
af_cjk_align_linked_edge( AF_GlyphHints hints,
AF_Dimension dim,
AF_Edge base_edge,
AF_Edge stem_edge )
{
FT_Pos dist = stem_edge->opos - base_edge->opos;
FT_Pos fitted_width = af_cjk_compute_stem_width(
hints, dim, dist,
(AF_Edge_Flags)base_edge->flags,
(AF_Edge_Flags)stem_edge->flags );
stem_edge->pos = base_edge->pos + fitted_width;
}
/* Shift the coordinates of the `serif' edge by the same amount */
/* as the corresponding `base' edge has been moved already. */
static void
af_cjk_align_serif_edge( AF_GlyphHints hints,
AF_Edge base,
AF_Edge serif )
{
FT_UNUSED( hints );
serif->pos = base->pos + ( serif->opos - base->opos );
}
/*************************************************************************/
/*************************************************************************/
/*************************************************************************/
/**** ****/
/**** E D G E H I N T I N G ****/
/**** ****/
/*************************************************************************/
/*************************************************************************/
/*************************************************************************/
#define AF_LIGHT_MODE_MAX_HORZ_GAP 9
#define AF_LIGHT_MODE_MAX_VERT_GAP 15
#define AF_LIGHT_MODE_MAX_DELTA_ABS 14
static FT_Pos
af_hint_normal_stem( AF_GlyphHints hints,
AF_Edge edge,
AF_Edge edge2,
FT_Pos anchor,
AF_Dimension dim )
{
FT_Pos org_len, cur_len, org_center;
FT_Pos cur_pos1, cur_pos2;
FT_Pos d_off1, u_off1, d_off2, u_off2, delta;
FT_Pos offset;
FT_Pos threshold = 64;
if ( !AF_LATIN_HINTS_DO_STEM_ADJUST( hints ) )
{
if ( ( edge->flags & AF_EDGE_ROUND ) &&
( edge2->flags & AF_EDGE_ROUND ) )
{
if ( dim == AF_DIMENSION_VERT )
threshold = 64 - AF_LIGHT_MODE_MAX_HORZ_GAP;
else
threshold = 64 - AF_LIGHT_MODE_MAX_VERT_GAP;
}
else
{
if ( dim == AF_DIMENSION_VERT )
threshold = 64 - AF_LIGHT_MODE_MAX_HORZ_GAP / 3;
else
threshold = 64 - AF_LIGHT_MODE_MAX_VERT_GAP / 3;
}
}
org_len = edge2->opos - edge->opos;
cur_len = af_cjk_compute_stem_width( hints, dim, org_len,
(AF_Edge_Flags)edge->flags,
(AF_Edge_Flags)edge2->flags );
org_center = ( edge->opos + edge2->opos ) / 2 + anchor;
cur_pos1 = org_center - cur_len / 2;
cur_pos2 = cur_pos1 + cur_len;
d_off1 = cur_pos1 - FT_PIX_FLOOR( cur_pos1 );
d_off2 = cur_pos2 - FT_PIX_FLOOR( cur_pos2 );
u_off1 = 64 - d_off1;
u_off2 = 64 - d_off2;
delta = 0;
if ( d_off1 == 0 || d_off2 == 0 )
goto Exit;
if ( cur_len <= threshold )
{
if ( d_off2 < cur_len )
{
if ( u_off1 <= d_off2 )
delta = u_off1;
else
delta = -d_off2;
}
goto Exit;
}
if ( threshold < 64 )
{
if ( d_off1 >= threshold || u_off1 >= threshold ||
d_off2 >= threshold || u_off2 >= threshold )
goto Exit;
}
offset = cur_len & 63;
if ( offset < 32 )
{
if ( u_off1 <= offset || d_off2 <= offset )
goto Exit;
}
else
offset = 64 - threshold;
d_off1 = threshold - u_off1;
u_off1 = u_off1 - offset;
u_off2 = threshold - d_off2;
d_off2 = d_off2 - offset;
if ( d_off1 <= u_off1 )
u_off1 = -d_off1;
if ( d_off2 <= u_off2 )
u_off2 = -d_off2;
if ( FT_ABS( u_off1 ) <= FT_ABS( u_off2 ) )
delta = u_off1;
else
delta = u_off2;
Exit:
#if 1
if ( !AF_LATIN_HINTS_DO_STEM_ADJUST( hints ) )
{
if ( delta > AF_LIGHT_MODE_MAX_DELTA_ABS )
delta = AF_LIGHT_MODE_MAX_DELTA_ABS;
else if ( delta < -AF_LIGHT_MODE_MAX_DELTA_ABS )
delta = -AF_LIGHT_MODE_MAX_DELTA_ABS;
}
#endif
cur_pos1 += delta;
if ( edge->opos < edge2->opos )
{
edge->pos = cur_pos1;
edge2->pos = cur_pos1 + cur_len;
}
else
{
edge->pos = cur_pos1 + cur_len;
edge2->pos = cur_pos1;
}
return delta;
}
/* The main grid-fitting routine. */
static void
af_cjk_hint_edges( AF_GlyphHints hints,
AF_Dimension dim )
{
AF_AxisHints axis = &hints->axis[dim];
AF_Edge edges = axis->edges;
AF_Edge edge_limit = edges + axis->num_edges;
FT_PtrDist n_edges;
AF_Edge edge;
AF_Edge anchor = 0;
FT_Pos delta = 0;
FT_Int skipped = 0;
FT_Bool has_last_stem = FALSE;
FT_Pos last_stem_pos = 0;
#ifdef FT_DEBUG_LEVEL_TRACE
FT_UInt num_actions = 0;
#endif
FT_TRACE5(( "cjk %s edge hinting (style `%s')\n",
dim == AF_DIMENSION_VERT ? "horizontal" : "vertical",
af_style_names[hints->metrics->style_class->style] ));
/* we begin by aligning all stems relative to the blue zone */
if ( AF_HINTS_DO_BLUES( hints ) )
{
for ( edge = edges; edge < edge_limit; edge++ )
{
AF_Width blue;
AF_Edge edge1, edge2;
if ( edge->flags & AF_EDGE_DONE )
continue;
blue = edge->blue_edge;
edge1 = NULL;
edge2 = edge->link;
if ( blue )
{
edge1 = edge;
}
else if ( edge2 && edge2->blue_edge )
{
blue = edge2->blue_edge;
edge1 = edge2;
edge2 = edge;
}
if ( !edge1 )
continue;
#ifdef FT_DEBUG_LEVEL_TRACE
FT_TRACE5(( " CJKBLUE: edge %d @%d (opos=%.2f) snapped to %.2f,"
" was %.2f\n",
edge1 - edges, edge1->fpos, edge1->opos / 64.0,
blue->fit / 64.0, edge1->pos / 64.0 ));
num_actions++;
#endif
edge1->pos = blue->fit;
edge1->flags |= AF_EDGE_DONE;
if ( edge2 && !edge2->blue_edge )
{
af_cjk_align_linked_edge( hints, dim, edge1, edge2 );
edge2->flags |= AF_EDGE_DONE;
#ifdef FT_DEBUG_LEVEL_TRACE
num_actions++;
#endif
}
if ( !anchor )
anchor = edge;
}
}
/* now we align all stem edges. */
for ( edge = edges; edge < edge_limit; edge++ )
{
AF_Edge edge2;
if ( edge->flags & AF_EDGE_DONE )
continue;
/* skip all non-stem edges */
edge2 = edge->link;
if ( !edge2 )
{
skipped++;
continue;
}
/* Some CJK characters have so many stems that
* the hinter is likely to merge two adjacent ones.
* To solve this problem, if either edge of a stem
* is too close to the previous one, we avoid
* aligning the two edges, but rather interpolate
* their locations at the end of this function in
* order to preserve the space between the stems.
*/
if ( has_last_stem &&
( edge->pos < last_stem_pos + 64 ||
edge2->pos < last_stem_pos + 64 ) )
{
skipped++;
continue;
}
/* now align the stem */
/* this should not happen, but it's better to be safe */
if ( edge2->blue_edge )
{
FT_TRACE5(( "ASSERTION FAILED for edge %d\n", edge2-edges ));
af_cjk_align_linked_edge( hints, dim, edge2, edge );
edge->flags |= AF_EDGE_DONE;
#ifdef FT_DEBUG_LEVEL_TRACE
num_actions++;
#endif
continue;
}
if ( edge2 < edge )
{
af_cjk_align_linked_edge( hints, dim, edge2, edge );
edge->flags |= AF_EDGE_DONE;
#ifdef FT_DEBUG_LEVEL_TRACE
num_actions++;
#endif
/* We rarely reaches here it seems;
* usually the two edges belonging
* to one stem are marked as DONE together
*/
has_last_stem = TRUE;
last_stem_pos = edge->pos;
continue;
}
if ( dim != AF_DIMENSION_VERT && !anchor )
{
#if 0
if ( fixedpitch )
{
AF_Edge left = edge;
AF_Edge right = edge_limit - 1;
AF_EdgeRec left1, left2, right1, right2;
FT_Pos target, center1, center2;
FT_Pos delta1, delta2, d1, d2;
while ( right > left && !right->link )
right--;
left1 = *left;
left2 = *left->link;
right1 = *right->link;
right2 = *right;
delta = ( ( ( hinter->pp2.x + 32 ) & -64 ) - hinter->pp2.x ) / 2;
target = left->opos + ( right->opos - left->opos ) / 2 + delta - 16;
delta1 = delta;
delta1 += af_hint_normal_stem( hints, left, left->link,
delta1, 0 );
if ( left->link != right )
af_hint_normal_stem( hints, right->link, right, delta1, 0 );
center1 = left->pos + ( right->pos - left->pos ) / 2;
if ( center1 >= target )
delta2 = delta - 32;
else
delta2 = delta + 32;
delta2 += af_hint_normal_stem( hints, &left1, &left2, delta2, 0 );
if ( delta1 != delta2 )
{
if ( left->link != right )
af_hint_normal_stem( hints, &right1, &right2, delta2, 0 );
center2 = left1.pos + ( right2.pos - left1.pos ) / 2;
d1 = center1 - target;
d2 = center2 - target;
if ( FT_ABS( d2 ) < FT_ABS( d1 ) )
{
left->pos = left1.pos;
left->link->pos = left2.pos;
if ( left->link != right )
{
right->link->pos = right1.pos;
right->pos = right2.pos;
}
delta1 = delta2;
}
}
delta = delta1;
right->link->flags |= AF_EDGE_DONE;
right->flags |= AF_EDGE_DONE;
}
else
#endif /* 0 */
delta = af_hint_normal_stem( hints, edge, edge2, 0,
AF_DIMENSION_HORZ );
}
else
af_hint_normal_stem( hints, edge, edge2, delta, dim );
#if 0
printf( "stem (%d,%d) adjusted (%.1f,%.1f)\n",
edge - edges, edge2 - edges,
( edge->pos - edge->opos ) / 64.0,
( edge2->pos - edge2->opos ) / 64.0 );
#endif
anchor = edge;
edge->flags |= AF_EDGE_DONE;
edge2->flags |= AF_EDGE_DONE;
has_last_stem = TRUE;
last_stem_pos = edge2->pos;
}
/* make sure that lowercase m's maintain their symmetry */
/* In general, lowercase m's have six vertical edges if they are sans */
/* serif, or twelve if they are with serifs. This implementation is */
/* based on that assumption, and seems to work very well with most */
/* faces. However, if for a certain face this assumption is not */
/* true, the m is just rendered like before. In addition, any stem */
/* correction will only be applied to symmetrical glyphs (even if the */
/* glyph is not an m), so the potential for unwanted distortion is */
/* relatively low. */
/* We don't handle horizontal edges since we can't easily assure that */
/* the third (lowest) stem aligns with the base line; it might end up */
/* one pixel higher or lower. */
n_edges = edge_limit - edges;
if ( dim == AF_DIMENSION_HORZ && ( n_edges == 6 || n_edges == 12 ) )
{
AF_Edge edge1, edge2, edge3;
FT_Pos dist1, dist2, span;
if ( n_edges == 6 )
{
edge1 = edges;
edge2 = edges + 2;
edge3 = edges + 4;
}
else
{
edge1 = edges + 1;
edge2 = edges + 5;
edge3 = edges + 9;
}
dist1 = edge2->opos - edge1->opos;
dist2 = edge3->opos - edge2->opos;
span = dist1 - dist2;
if ( span < 0 )
span = -span;
if ( edge1->link == edge1 + 1 &&
edge2->link == edge2 + 1 &&
edge3->link == edge3 + 1 && span < 8 )
{
delta = edge3->pos - ( 2 * edge2->pos - edge1->pos );
edge3->pos -= delta;
if ( edge3->link )
edge3->link->pos -= delta;
/* move the serifs along with the stem */
if ( n_edges == 12 )
{
( edges + 8 )->pos -= delta;
( edges + 11 )->pos -= delta;
}
edge3->flags |= AF_EDGE_DONE;
if ( edge3->link )
edge3->link->flags |= AF_EDGE_DONE;
}
}
if ( !skipped )
goto Exit;
/*
* now hint the remaining edges (serifs and single) in order
* to complete our processing
*/
for ( edge = edges; edge < edge_limit; edge++ )
{
if ( edge->flags & AF_EDGE_DONE )
continue;
if ( edge->serif )
{
af_cjk_align_serif_edge( hints, edge->serif, edge );
edge->flags |= AF_EDGE_DONE;
skipped--;
}
}
if ( !skipped )
goto Exit;
for ( edge = edges; edge < edge_limit; edge++ )
{
AF_Edge before, after;
if ( edge->flags & AF_EDGE_DONE )
continue;
before = after = edge;
while ( --before >= edges )
if ( before->flags & AF_EDGE_DONE )
break;
while ( ++after < edge_limit )
if ( after->flags & AF_EDGE_DONE )
break;
if ( before >= edges || after < edge_limit )
{
if ( before < edges )
af_cjk_align_serif_edge( hints, after, edge );
else if ( after >= edge_limit )
af_cjk_align_serif_edge( hints, before, edge );
else
{
if ( after->fpos == before->fpos )
edge->pos = before->pos;
else
edge->pos = before->pos +
FT_MulDiv( edge->fpos - before->fpos,
after->pos - before->pos,
after->fpos - before->fpos );
}
}
}
Exit:
#ifdef FT_DEBUG_LEVEL_TRACE
if ( !num_actions )
FT_TRACE5(( " (none)\n" ));
FT_TRACE5(( "\n" ));
#endif
return;
}
static void
af_cjk_align_edge_points( AF_GlyphHints hints,
AF_Dimension dim )
{
AF_AxisHints axis = & hints->axis[dim];
AF_Edge edges = axis->edges;
AF_Edge edge_limit = edges + axis->num_edges;
AF_Edge edge;
FT_Bool snapping;
snapping = FT_BOOL( ( dim == AF_DIMENSION_HORZ &&
AF_LATIN_HINTS_DO_HORZ_SNAP( hints ) ) ||
( dim == AF_DIMENSION_VERT &&
AF_LATIN_HINTS_DO_VERT_SNAP( hints ) ) );
for ( edge = edges; edge < edge_limit; edge++ )
{
/* move the points of each segment */
/* in each edge to the edge's position */
AF_Segment seg = edge->first;
if ( snapping )
{
do
{
AF_Point point = seg->first;
for (;;)
{
if ( dim == AF_DIMENSION_HORZ )
{
point->x = edge->pos;
point->flags |= AF_FLAG_TOUCH_X;
}
else
{
point->y = edge->pos;
point->flags |= AF_FLAG_TOUCH_Y;
}
if ( point == seg->last )
break;
point = point->next;
}
seg = seg->edge_next;
} while ( seg != edge->first );
}
else
{
FT_Pos delta = edge->pos - edge->opos;
do
{
AF_Point point = seg->first;
for (;;)
{
if ( dim == AF_DIMENSION_HORZ )
{
point->x += delta;
point->flags |= AF_FLAG_TOUCH_X;
}
else
{
point->y += delta;
point->flags |= AF_FLAG_TOUCH_Y;
}
if ( point == seg->last )
break;
point = point->next;
}
seg = seg->edge_next;
} while ( seg != edge->first );
}
}
}
/* Apply the complete hinting algorithm to a CJK glyph. */
FT_LOCAL_DEF( FT_Error )
af_cjk_hints_apply( AF_GlyphHints hints,
FT_Outline* outline,
AF_CJKMetrics metrics )
{
FT_Error error;
int dim;
FT_UNUSED( metrics );
error = af_glyph_hints_reload( hints, outline );
if ( error )
goto Exit;
/* analyze glyph outline */
if ( AF_HINTS_DO_HORIZONTAL( hints ) )
{
error = af_cjk_hints_detect_features( hints, AF_DIMENSION_HORZ );
if ( error )
goto Exit;
af_cjk_hints_compute_blue_edges( hints, metrics, AF_DIMENSION_HORZ );
}
if ( AF_HINTS_DO_VERTICAL( hints ) )
{
error = af_cjk_hints_detect_features( hints, AF_DIMENSION_VERT );
if ( error )
goto Exit;
af_cjk_hints_compute_blue_edges( hints, metrics, AF_DIMENSION_VERT );
}
/* grid-fit the outline */
for ( dim = 0; dim < AF_DIMENSION_MAX; dim++ )
{
if ( ( dim == AF_DIMENSION_HORZ && AF_HINTS_DO_HORIZONTAL( hints ) ) ||
( dim == AF_DIMENSION_VERT && AF_HINTS_DO_VERTICAL( hints ) ) )
{
#ifdef AF_CONFIG_OPTION_USE_WARPER
if ( dim == AF_DIMENSION_HORZ &&
metrics->root.scaler.render_mode == FT_RENDER_MODE_NORMAL )
{
AF_WarperRec warper;
FT_Fixed scale;
FT_Pos delta;
af_warper_compute( &warper, hints, (AF_Dimension)dim,
&scale, &delta );
af_glyph_hints_scale_dim( hints, (AF_Dimension)dim,
scale, delta );
continue;
}
#endif /* AF_CONFIG_OPTION_USE_WARPER */
af_cjk_hint_edges( hints, (AF_Dimension)dim );
af_cjk_align_edge_points( hints, (AF_Dimension)dim );
af_glyph_hints_align_strong_points( hints, (AF_Dimension)dim );
af_glyph_hints_align_weak_points( hints, (AF_Dimension)dim );
}
}
#if 0
af_glyph_hints_dump_points( hints );
af_glyph_hints_dump_segments( hints );
af_glyph_hints_dump_edges( hints );
#endif
af_glyph_hints_save( hints, outline );
Exit:
return error;
}
/*************************************************************************/
/*************************************************************************/
/***** *****/
/***** C J K S C R I P T C L A S S *****/
/***** *****/
/*************************************************************************/
/*************************************************************************/
AF_DEFINE_WRITING_SYSTEM_CLASS(
af_cjk_writing_system_class,
AF_WRITING_SYSTEM_CJK,
sizeof ( AF_CJKMetricsRec ),
(AF_WritingSystem_InitMetricsFunc) af_cjk_metrics_init,
(AF_WritingSystem_ScaleMetricsFunc)af_cjk_metrics_scale,
(AF_WritingSystem_DoneMetricsFunc) NULL,
(AF_WritingSystem_InitHintsFunc) af_cjk_hints_init,
(AF_WritingSystem_ApplyHintsFunc) af_cjk_hints_apply
)
#else /* !AF_CONFIG_OPTION_CJK */
AF_DEFINE_WRITING_SYSTEM_CLASS(
af_cjk_writing_system_class,
AF_WRITING_SYSTEM_CJK,
sizeof ( AF_CJKMetricsRec ),
(AF_WritingSystem_InitMetricsFunc) NULL,
(AF_WritingSystem_ScaleMetricsFunc)NULL,
(AF_WritingSystem_DoneMetricsFunc) NULL,
(AF_WritingSystem_InitHintsFunc) NULL,
(AF_WritingSystem_ApplyHintsFunc) NULL
)
#endif /* !AF_CONFIG_OPTION_CJK */
/* END */
| YifuLiu/AliOS-Things | components/freetype/src/autofit/afcjk.c | C | apache-2.0 | 65,068 |
/***************************************************************************/
/* */
/* afcjk.h */
/* */
/* Auto-fitter hinting routines for CJK writing system (specification). */
/* */
/* Copyright 2006, 2007, 2011-2013 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. */
/* */
/***************************************************************************/
#ifndef __AFCJK_H__
#define __AFCJK_H__
#include "afhints.h"
#include "aflatin.h"
FT_BEGIN_HEADER
/* the CJK-specific writing system */
AF_DECLARE_WRITING_SYSTEM_CLASS( af_cjk_writing_system_class )
/*************************************************************************/
/*************************************************************************/
/***** *****/
/***** C J K G L O B A L M E T R I C S *****/
/***** *****/
/*************************************************************************/
/*************************************************************************/
/*
* CJK glyphs tend to fill the square. So we have both vertical and
* horizontal blue zones. But some glyphs have flat bounding strokes that
* leave some space between neighbour glyphs.
*/
#define AF_CJK_IS_TOP_BLUE( b ) \
( (b)->properties & AF_BLUE_PROPERTY_CJK_TOP )
#define AF_CJK_IS_HORIZ_BLUE( b ) \
( (b)->properties & AF_BLUE_PROPERTY_CJK_HORIZ )
#define AF_CJK_IS_FILLED_BLUE( b ) \
( (b)->properties & AF_BLUE_PROPERTY_CJK_FILL )
#define AF_CJK_IS_RIGHT_BLUE AF_CJK_IS_TOP_BLUE
#define AF_CJK_MAX_WIDTHS 16
enum
{
AF_CJK_BLUE_ACTIVE = 1 << 0, /* set if zone height is <= 3/4px */
AF_CJK_BLUE_TOP = 1 << 1, /* result of AF_CJK_IS_TOP_BLUE */
AF_CJK_BLUE_ADJUSTMENT = 1 << 2, /* used for scale adjustment */
/* optimization */
AF_CJK_BLUE_FLAG_MAX
};
typedef struct AF_CJKBlueRec_
{
AF_WidthRec ref;
AF_WidthRec shoot; /* undershoot */
FT_UInt flags;
} AF_CJKBlueRec, *AF_CJKBlue;
typedef struct AF_CJKAxisRec_
{
FT_Fixed scale;
FT_Pos delta;
FT_UInt width_count; /* number of used widths */
AF_WidthRec widths[AF_CJK_MAX_WIDTHS]; /* widths array */
FT_Pos edge_distance_threshold; /* used for creating edges */
FT_Pos standard_width; /* the default stem thickness */
FT_Bool extra_light; /* is standard width very light? */
/* used for horizontal metrics too for CJK */
FT_Bool control_overshoot;
FT_UInt blue_count;
AF_CJKBlueRec blues[AF_BLUE_STRINGSET_MAX];
FT_Fixed org_scale;
FT_Pos org_delta;
} AF_CJKAxisRec, *AF_CJKAxis;
typedef struct AF_CJKMetricsRec_
{
AF_StyleMetricsRec root;
FT_UInt units_per_em;
AF_CJKAxisRec axis[AF_DIMENSION_MAX];
} AF_CJKMetricsRec, *AF_CJKMetrics;
#ifdef AF_CONFIG_OPTION_CJK
FT_LOCAL( FT_Error )
af_cjk_metrics_init( AF_CJKMetrics metrics,
FT_Face face );
FT_LOCAL( void )
af_cjk_metrics_scale( AF_CJKMetrics metrics,
AF_Scaler scaler );
FT_LOCAL( FT_Error )
af_cjk_hints_init( AF_GlyphHints hints,
AF_CJKMetrics metrics );
FT_LOCAL( FT_Error )
af_cjk_hints_apply( AF_GlyphHints hints,
FT_Outline* outline,
AF_CJKMetrics metrics );
/* shared; called from afindic.c */
FT_LOCAL( void )
af_cjk_metrics_check_digits( AF_CJKMetrics metrics,
FT_Face face );
FT_LOCAL( void )
af_cjk_metrics_init_widths( AF_CJKMetrics metrics,
FT_Face face );
#endif /* AF_CONFIG_OPTION_CJK */
/* */
FT_END_HEADER
#endif /* __AFCJK_H__ */
/* END */
| YifuLiu/AliOS-Things | components/freetype/src/autofit/afcjk.h | C | apache-2.0 | 4,953 |
/***************************************************************************/
/* */
/* afcover.h */
/* */
/* Auto-fitter coverages (specification only). */
/* */
/* Copyright 2013, 2014 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. */
/* */
/***************************************************************************/
/* This header file can be included multiple times. */
/* Define `COVERAGE' as needed. */
/* Add new coverages here. The first and second arguments are the */
/* coverage name in lowercase and uppercase, respectively, followed */
/* by a description string. The last four arguments are the four */
/* characters defining the corresponding OpenType feature. */
#if 0
/* XXX: It's not possible to define blue zone characters in advance. */
COVERAGE( alternative_fractions, ALTERNATIVE_FRACTIONS,
"alternative fractions",
'a', 'f', 'r', 'c' )
#endif
COVERAGE( petite_capitals_from_capitals, PETITE_CAPITALS_FROM_CAPITALS,
"petite capitals from capitals",
'c', '2', 'c', 'p' )
COVERAGE( small_capitals_from_capitals, SMALL_CAPITALS_FROM_CAPITALS,
"small capitals from capitals",
'c', '2', 's', 'c' )
#if 0
/* XXX: Only digits are in this coverage, however, both normal style */
/* and oldstyle representation forms are possible. */
COVERAGE( denominators, DENOMINATORS,
"denominators",
'd', 'n', 'o', 'm' )
#endif
#if 0
/* XXX: It's not possible to define blue zone characters in advance. */
COVERAGE( fractions, FRACTIONS,
"fractions",
'f', 'r', 'a', 'c' )
#endif
#if 0
/* XXX: Only digits are in this coverage, however, both normal style */
/* and oldstyle representation forms are possible. */
COVERAGE( numerators, NUMERATORS,
"numerators",
'n', 'u', 'm', 'r' )
#endif
COVERAGE( ordinals, ORDINALS,
"ordinals",
'o', 'r', 'd', 'n' )
COVERAGE( petite_capitals, PETITE_CAPITALS,
"petite capitals",
'p', 'c', 'a', 'p' )
COVERAGE( ruby, RUBY,
"ruby",
'r', 'u', 'b', 'y' )
COVERAGE( scientific_inferiors, SCIENTIFIC_INFERIORS,
"scientific inferiors",
's', 'i', 'n', 'f' )
COVERAGE( small_capitals, SMALL_CAPITALS,
"small capitals",
's', 'm', 'c', 'p' )
COVERAGE( subscript, SUBSCRIPT,
"subscript",
's', 'u', 'b', 's' )
COVERAGE( superscript, SUPERSCRIPT,
"superscript",
's', 'u', 'p', 's' )
COVERAGE( titling, TITLING,
"titling",
't', 'i', 't', 'l' )
#if 0
/* to be always excluded */
COVERAGE(nalt, 'n', 'a', 'l', 't'); /* Alternate Annotation Forms (?) */
COVERAGE(ornm, 'o', 'r', 'n', 'm'); /* Ornaments (?) */
#endif
/* END */
| YifuLiu/AliOS-Things | components/freetype/src/autofit/afcover.h | C | apache-2.0 | 3,862 |
/***************************************************************************/
/* */
/* afdummy.c */
/* */
/* Auto-fitter dummy routines to be used if no hinting should be */
/* performed (body). */
/* */
/* Copyright 2003-2005, 2011, 2013 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. */
/* */
/***************************************************************************/
#include "afdummy.h"
#include "afhints.h"
#include "aferrors.h"
static FT_Error
af_dummy_hints_init( AF_GlyphHints hints,
AF_StyleMetrics metrics )
{
af_glyph_hints_rescale( hints, metrics );
hints->x_scale = metrics->scaler.x_scale;
hints->y_scale = metrics->scaler.y_scale;
hints->x_delta = metrics->scaler.x_delta;
hints->y_delta = metrics->scaler.y_delta;
return FT_Err_Ok;
}
static FT_Error
af_dummy_hints_apply( AF_GlyphHints hints,
FT_Outline* outline )
{
FT_Error error;
error = af_glyph_hints_reload( hints, outline );
if ( !error )
af_glyph_hints_save( hints, outline );
return error;
}
AF_DEFINE_WRITING_SYSTEM_CLASS(
af_dummy_writing_system_class,
AF_WRITING_SYSTEM_DUMMY,
sizeof ( AF_StyleMetricsRec ),
(AF_WritingSystem_InitMetricsFunc) NULL,
(AF_WritingSystem_ScaleMetricsFunc)NULL,
(AF_WritingSystem_DoneMetricsFunc) NULL,
(AF_WritingSystem_InitHintsFunc) af_dummy_hints_init,
(AF_WritingSystem_ApplyHintsFunc) af_dummy_hints_apply
)
/* END */
| YifuLiu/AliOS-Things | components/freetype/src/autofit/afdummy.c | C | apache-2.0 | 2,462 |
/***************************************************************************/
/* */
/* afdummy.h */
/* */
/* Auto-fitter dummy routines to be used if no hinting should be */
/* performed (specification). */
/* */
/* Copyright 2003-2005, 2011, 2013 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. */
/* */
/***************************************************************************/
#ifndef __AFDUMMY_H__
#define __AFDUMMY_H__
#include "aftypes.h"
FT_BEGIN_HEADER
/* A dummy writing system used when no hinting should be performed. */
AF_DECLARE_WRITING_SYSTEM_CLASS( af_dummy_writing_system_class )
/* */
FT_END_HEADER
#endif /* __AFDUMMY_H__ */
/* END */
| YifuLiu/AliOS-Things | components/freetype/src/autofit/afdummy.h | C | apache-2.0 | 1,617 |
/***************************************************************************/
/* */
/* aferrors.h */
/* */
/* Autofitter error codes (specification only). */
/* */
/* Copyright 2005, 2012 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. */
/* */
/***************************************************************************/
/*************************************************************************/
/* */
/* This file is used to define the Autofitter error enumeration */
/* constants. */
/* */
/*************************************************************************/
#ifndef __AFERRORS_H__
#define __AFERRORS_H__
#include FT_MODULE_ERRORS_H
#undef __FTERRORS_H__
#undef FT_ERR_PREFIX
#define FT_ERR_PREFIX AF_Err_
#define FT_ERR_BASE FT_Mod_Err_Autofit
#include FT_ERRORS_H
#endif /* __AFERRORS_H__ */
/* END */
| YifuLiu/AliOS-Things | components/freetype/src/autofit/aferrors.h | C | apache-2.0 | 1,975 |
/***************************************************************************/
/* */
/* afglobal.c */
/* */
/* Auto-fitter routines to compute global hinting values (body). */
/* */
/* Copyright 2003-2014 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. */
/* */
/***************************************************************************/
#include "afglobal.h"
#include "afranges.h"
#include "hbshim.h"
#include FT_INTERNAL_DEBUG_H
/*************************************************************************/
/* */
/* The macro FT_COMPONENT is used in trace mode. It is an implicit */
/* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */
/* messages during execution. */
/* */
#undef FT_COMPONENT
#define FT_COMPONENT trace_afglobal
/* get writing system specific header files */
#undef WRITING_SYSTEM
#define WRITING_SYSTEM( ws, WS ) /* empty */
#include "afwrtsys.h"
#include "aferrors.h"
#include "afpic.h"
#undef SCRIPT
#define SCRIPT( s, S, d, h, sc1, sc2, sc3 ) \
AF_DEFINE_SCRIPT_CLASS( \
af_ ## s ## _script_class, \
AF_SCRIPT_ ## S, \
af_ ## s ## _uniranges, \
sc1, sc2, sc3 )
#include "afscript.h"
#undef STYLE
#define STYLE( s, S, d, ws, sc, ss, c ) \
AF_DEFINE_STYLE_CLASS( \
af_ ## s ## _style_class, \
AF_STYLE_ ## S, \
ws, \
sc, \
ss, \
c )
#include "afstyles.h"
#ifndef FT_CONFIG_OPTION_PIC
#undef WRITING_SYSTEM
#define WRITING_SYSTEM( ws, WS ) \
&af_ ## ws ## _writing_system_class,
FT_LOCAL_ARRAY_DEF( AF_WritingSystemClass )
af_writing_system_classes[] =
{
#include "afwrtsys.h"
NULL /* do not remove */
};
#undef SCRIPT
#define SCRIPT( s, S, d, h, sc1, sc2, sc3 ) \
&af_ ## s ## _script_class,
FT_LOCAL_ARRAY_DEF( AF_ScriptClass )
af_script_classes[] =
{
#include "afscript.h"
NULL /* do not remove */
};
#undef STYLE
#define STYLE( s, S, d, ws, sc, ss, c ) \
&af_ ## s ## _style_class,
FT_LOCAL_ARRAY_DEF( AF_StyleClass )
af_style_classes[] =
{
#include "afstyles.h"
NULL /* do not remove */
};
#endif /* !FT_CONFIG_OPTION_PIC */
#ifdef FT_DEBUG_LEVEL_TRACE
#undef STYLE
#define STYLE( s, S, d, ws, sc, ss, c ) #s,
FT_LOCAL_ARRAY_DEF( char* )
af_style_names[] =
{
#include "afstyles.h"
};
#endif /* FT_DEBUG_LEVEL_TRACE */
/* Compute the style index of each glyph within a given face. */
static FT_Error
af_face_globals_compute_style_coverage( AF_FaceGlobals globals )
{
FT_Error error;
FT_Face face = globals->face;
FT_CharMap old_charmap = face->charmap;
FT_Byte* gstyles = globals->glyph_styles;
FT_UInt ss;
FT_UInt i;
FT_UInt dflt = -1;
/* the value AF_STYLE_UNASSIGNED means `uncovered glyph' */
FT_MEM_SET( globals->glyph_styles,
AF_STYLE_UNASSIGNED,
globals->glyph_count );
error = FT_Select_Charmap( face, FT_ENCODING_UNICODE );
if ( error )
{
/*
* Ignore this error; we simply use the fallback style.
* XXX: Shouldn't we rather disable hinting?
*/
error = FT_Err_Ok;
goto Exit;
}
/* scan each style in a Unicode charmap */
for ( ss = 0; AF_STYLE_CLASSES_GET[ss]; ss++ )
{
AF_StyleClass style_class =
AF_STYLE_CLASSES_GET[ss];
AF_ScriptClass script_class =
AF_SCRIPT_CLASSES_GET[style_class->script];
AF_Script_UniRange range;
if ( script_class->script_uni_ranges == NULL )
continue;
/*
* Scan all Unicode points in the range and set the corresponding
* glyph style index.
*/
if ( style_class->coverage == AF_COVERAGE_DEFAULT )
{
if ( style_class->script == globals->module->default_script )
dflt = ss;
for ( range = script_class->script_uni_ranges;
range->first != 0;
range++ )
{
FT_ULong charcode = range->first;
FT_UInt gindex;
gindex = FT_Get_Char_Index( face, charcode );
if ( gindex != 0 &&
gindex < (FT_ULong)globals->glyph_count &&
gstyles[gindex] == AF_STYLE_UNASSIGNED )
gstyles[gindex] = (FT_Byte)ss;
for (;;)
{
charcode = FT_Get_Next_Char( face, charcode, &gindex );
if ( gindex == 0 || charcode > range->last )
break;
if ( gindex < (FT_ULong)globals->glyph_count &&
gstyles[gindex] == AF_STYLE_UNASSIGNED )
gstyles[gindex] = (FT_Byte)ss;
}
}
}
else
{
/* get glyphs not directly addressable by cmap */
af_get_coverage( globals, style_class, gstyles );
}
}
/* handle the default OpenType features of the default script ... */
af_get_coverage( globals, AF_STYLE_CLASSES_GET[dflt], gstyles );
/* ... and the remaining default OpenType features */
for ( ss = 0; AF_STYLE_CLASSES_GET[ss]; ss++ )
{
AF_StyleClass style_class = AF_STYLE_CLASSES_GET[ss];
if ( ss != dflt && style_class->coverage == AF_COVERAGE_DEFAULT )
af_get_coverage( globals, style_class, gstyles );
}
/* mark ASCII digits */
for ( i = 0x30; i <= 0x39; i++ )
{
FT_UInt gindex = FT_Get_Char_Index( face, i );
if ( gindex != 0 && gindex < (FT_ULong)globals->glyph_count )
gstyles[gindex] |= AF_DIGIT;
}
Exit:
/*
* By default, all uncovered glyphs are set to the fallback style.
* XXX: Shouldn't we disable hinting or do something similar?
*/
if ( globals->module->fallback_style != AF_STYLE_UNASSIGNED )
{
FT_Long nn;
for ( nn = 0; nn < globals->glyph_count; nn++ )
{
if ( ( gstyles[nn] & ~AF_DIGIT ) == AF_STYLE_UNASSIGNED )
{
gstyles[nn] &= ~AF_STYLE_UNASSIGNED;
gstyles[nn] |= globals->module->fallback_style;
}
}
}
#ifdef FT_DEBUG_LEVEL_TRACE
FT_TRACE4(( "\n"
"style coverage\n"
"==============\n"
"\n" ));
for ( ss = 0; AF_STYLE_CLASSES_GET[ss]; ss++ )
{
AF_StyleClass style_class = AF_STYLE_CLASSES_GET[ss];
FT_UInt count = 0;
FT_Long idx;
FT_TRACE4(( "%s:\n", af_style_names[style_class->style] ));
for ( idx = 0; idx < globals->glyph_count; idx++ )
{
if ( ( gstyles[idx] & ~AF_DIGIT ) == style_class->style )
{
if ( !( count % 10 ) )
FT_TRACE4(( " " ));
FT_TRACE4(( " %d", idx ));
count++;
if ( !( count % 10 ) )
FT_TRACE4(( "\n" ));
}
}
if ( !count )
FT_TRACE4(( " (none)\n" ));
if ( count % 10 )
FT_TRACE4(( "\n" ));
}
#endif /* FT_DEBUG_LEVEL_TRACE */
FT_Set_Charmap( face, old_charmap );
return error;
}
FT_LOCAL_DEF( FT_Error )
af_face_globals_new( FT_Face face,
AF_FaceGlobals *aglobals,
AF_Module module )
{
FT_Error error;
FT_Memory memory;
AF_FaceGlobals globals = NULL;
memory = face->memory;
if ( FT_ALLOC( globals, sizeof ( *globals ) +
face->num_glyphs * sizeof ( FT_Byte ) ) )
goto Exit;
globals->face = face;
globals->glyph_count = face->num_glyphs;
globals->glyph_styles = (FT_Byte*)( globals + 1 );
globals->module = module;
#ifdef FT_CONFIG_OPTION_USE_HARFBUZZ
globals->hb_font = hb_ft_font_create( face, NULL );
#endif
error = af_face_globals_compute_style_coverage( globals );
if ( error )
{
af_face_globals_free( globals );
globals = NULL;
}
if (globals != NULL)
{
globals->increase_x_height = AF_PROP_INCREASE_X_HEIGHT_MAX;
}
Exit:
*aglobals = globals;
return error;
}
FT_LOCAL_DEF( void )
af_face_globals_free( AF_FaceGlobals globals )
{
if ( globals )
{
FT_Memory memory = globals->face->memory;
FT_UInt nn;
for ( nn = 0; nn < AF_STYLE_MAX; nn++ )
{
if ( globals->metrics[nn] )
{
AF_StyleClass style_class =
AF_STYLE_CLASSES_GET[nn];
AF_WritingSystemClass writing_system_class =
AF_WRITING_SYSTEM_CLASSES_GET[style_class->writing_system];
if ( writing_system_class->style_metrics_done )
writing_system_class->style_metrics_done( globals->metrics[nn] );
FT_FREE( globals->metrics[nn] );
}
}
#ifdef FT_CONFIG_OPTION_USE_HARFBUZZ
hb_font_destroy( globals->hb_font );
globals->hb_font = NULL;
#endif
globals->glyph_count = 0;
globals->glyph_styles = NULL; /* no need to free this one! */
globals->face = NULL;
FT_FREE( globals );
}
}
FT_LOCAL_DEF( FT_Error )
af_face_globals_get_metrics( AF_FaceGlobals globals,
FT_UInt gindex,
FT_UInt options,
AF_StyleMetrics *ametrics )
{
AF_StyleMetrics metrics = NULL;
AF_Style style = (AF_Style)options;
AF_WritingSystemClass writing_system_class;
AF_StyleClass style_class;
FT_Error error = FT_Err_Ok;
if ( gindex >= (FT_ULong)globals->glyph_count )
{
error = FT_THROW( Invalid_Argument );
goto Exit;
}
/* if we have a forced style (via `options'), use it, */
/* otherwise look into `glyph_styles' array */
if ( style == AF_STYLE_NONE_DFLT || style + 1 >= AF_STYLE_MAX )
style = (AF_Style)( globals->glyph_styles[gindex] &
AF_STYLE_UNASSIGNED );
style_class = AF_STYLE_CLASSES_GET[style];
writing_system_class = AF_WRITING_SYSTEM_CLASSES_GET
[style_class->writing_system];
metrics = globals->metrics[style];
if ( metrics == NULL )
{
/* create the global metrics object if necessary */
FT_Memory memory = globals->face->memory;
if ( FT_ALLOC( metrics, writing_system_class->style_metrics_size ) )
goto Exit;
metrics->style_class = style_class;
metrics->globals = globals;
if ( writing_system_class->style_metrics_init )
{
error = writing_system_class->style_metrics_init( metrics,
globals->face );
if ( error )
{
if ( writing_system_class->style_metrics_done )
writing_system_class->style_metrics_done( metrics );
FT_FREE( metrics );
goto Exit;
}
}
globals->metrics[style] = metrics;
}
Exit:
*ametrics = metrics;
return error;
}
FT_LOCAL_DEF( FT_Bool )
af_face_globals_is_digit( AF_FaceGlobals globals,
FT_UInt gindex )
{
if ( gindex < (FT_ULong)globals->glyph_count )
return (FT_Bool)( globals->glyph_styles[gindex] & AF_DIGIT );
return (FT_Bool)0;
}
/* END */
| YifuLiu/AliOS-Things | components/freetype/src/autofit/afglobal.c | C | apache-2.0 | 12,700 |
/***************************************************************************/
/* */
/* afglobal.h */
/* */
/* Auto-fitter routines to compute global hinting values */
/* (specification). */
/* */
/* Copyright 2003-2005, 2007, 2009, 2011-2014 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. */
/* */
/***************************************************************************/
#ifndef __AFGLOBAL_H__
#define __AFGLOBAL_H__
#include "aftypes.h"
#include "afmodule.h"
#include "hbshim.h"
FT_BEGIN_HEADER
FT_LOCAL_ARRAY( AF_WritingSystemClass )
af_writing_system_classes[];
#undef SCRIPT
#define SCRIPT( s, S, d, h, sc1, sc2, sc3 ) \
AF_DECLARE_SCRIPT_CLASS( af_ ## s ## _script_class )
#include "afscript.h"
FT_LOCAL_ARRAY( AF_ScriptClass )
af_script_classes[];
#undef STYLE
#define STYLE( s, S, d, ws, sc, ss, c ) \
AF_DECLARE_STYLE_CLASS( af_ ## s ## _style_class )
#include "afstyles.h"
FT_LOCAL_ARRAY( AF_StyleClass )
af_style_classes[];
#ifdef FT_DEBUG_LEVEL_TRACE
FT_LOCAL_ARRAY( char* )
af_style_names[];
#endif
/*
* Default values and flags for both autofitter globals (found in
* AF_ModuleRec) and face globals (in AF_FaceGlobalsRec).
*/
/* index of fallback style in `af_style_classes' */
#ifdef AF_CONFIG_OPTION_CJK
#define AF_STYLE_FALLBACK AF_STYLE_HANI_DFLT
#else
#define AF_STYLE_FALLBACK AF_STYLE_NONE_DFLT
#endif
/* default script for OpenType; ignored if HarfBuzz isn't used */
#define AF_SCRIPT_DEFAULT AF_SCRIPT_LATN
/* a bit mask indicating an uncovered glyph */
#define AF_STYLE_UNASSIGNED 0x7F
/* if this flag is set, we have an ASCII digit */
#define AF_DIGIT 0x80
/* `increase-x-height' property */
#define AF_PROP_INCREASE_X_HEIGHT_MIN 6
#define AF_PROP_INCREASE_X_HEIGHT_MAX 0
/************************************************************************/
/************************************************************************/
/***** *****/
/***** F A C E G L O B A L S *****/
/***** *****/
/************************************************************************/
/************************************************************************/
/*
* Note that glyph_styles[] maps each glyph to an index into the
* `af_style_classes' array.
*
*/
typedef struct AF_FaceGlobalsRec_
{
FT_Face face;
FT_Long glyph_count; /* same as face->num_glyphs */
FT_Byte* glyph_styles;
#ifdef FT_CONFIG_OPTION_USE_HARFBUZZ
hb_font_t* hb_font;
#endif
/* per-face auto-hinter properties */
FT_UInt increase_x_height;
AF_StyleMetrics metrics[AF_STYLE_MAX];
AF_Module module; /* to access global properties */
} AF_FaceGlobalsRec;
/*
* model the global hints data for a given face, decomposed into
* style-specific items
*/
FT_LOCAL( FT_Error )
af_face_globals_new( FT_Face face,
AF_FaceGlobals *aglobals,
AF_Module module );
FT_LOCAL( FT_Error )
af_face_globals_get_metrics( AF_FaceGlobals globals,
FT_UInt gindex,
FT_UInt options,
AF_StyleMetrics *ametrics );
FT_LOCAL( void )
af_face_globals_free( AF_FaceGlobals globals );
FT_LOCAL_DEF( FT_Bool )
af_face_globals_is_digit( AF_FaceGlobals globals,
FT_UInt gindex );
/* */
FT_END_HEADER
#endif /* __AFGLOBAL_H__ */
/* END */
| YifuLiu/AliOS-Things | components/freetype/src/autofit/afglobal.h | C | apache-2.0 | 4,740 |
/***************************************************************************/
/* */
/* afhints.c */
/* */
/* Auto-fitter hinting routines (body). */
/* */
/* Copyright 2003-2007, 2009-2014 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. */
/* */
/***************************************************************************/
#include "afhints.h"
#include "aferrors.h"
#include FT_INTERNAL_CALC_H
#include FT_INTERNAL_DEBUG_H
/*************************************************************************/
/* */
/* The macro FT_COMPONENT is used in trace mode. It is an implicit */
/* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */
/* messages during execution. */
/* */
#undef FT_COMPONENT
#define FT_COMPONENT trace_afhints
/* Get new segment for given axis. */
FT_LOCAL_DEF( FT_Error )
af_axis_hints_new_segment( AF_AxisHints axis,
FT_Memory memory,
AF_Segment *asegment )
{
FT_Error error = FT_Err_Ok;
AF_Segment segment = NULL;
if ( axis->num_segments >= axis->max_segments )
{
FT_Int old_max = axis->max_segments;
FT_Int new_max = old_max;
FT_Int big_max = (FT_Int)( FT_INT_MAX / sizeof ( *segment ) );
if ( old_max >= big_max )
{
error = FT_THROW( Out_Of_Memory );
goto Exit;
}
new_max += ( new_max >> 2 ) + 4;
if ( new_max < old_max || new_max > big_max )
new_max = big_max;
if ( FT_RENEW_ARRAY( axis->segments, old_max, new_max ) )
goto Exit;
axis->max_segments = new_max;
}
segment = axis->segments + axis->num_segments++;
Exit:
*asegment = segment;
return error;
}
/* Get new edge for given axis, direction, and position. */
FT_LOCAL( FT_Error )
af_axis_hints_new_edge( AF_AxisHints axis,
FT_Int fpos,
AF_Direction dir,
FT_Memory memory,
AF_Edge *anedge )
{
FT_Error error = FT_Err_Ok;
AF_Edge edge = NULL;
AF_Edge edges;
if ( axis->num_edges >= axis->max_edges )
{
FT_Int old_max = axis->max_edges;
FT_Int new_max = old_max;
FT_Int big_max = (FT_Int)( FT_INT_MAX / sizeof ( *edge ) );
if ( old_max >= big_max )
{
error = FT_THROW( Out_Of_Memory );
goto Exit;
}
new_max += ( new_max >> 2 ) + 4;
if ( new_max < old_max || new_max > big_max )
new_max = big_max;
if ( FT_RENEW_ARRAY( axis->edges, old_max, new_max ) )
goto Exit;
axis->max_edges = new_max;
}
edges = axis->edges;
edge = edges + axis->num_edges;
while ( edge > edges )
{
if ( edge[-1].fpos < fpos )
break;
/* we want the edge with same position and minor direction */
/* to appear before those in the major one in the list */
if ( edge[-1].fpos == fpos && dir == axis->major_dir )
break;
edge[0] = edge[-1];
edge--;
}
axis->num_edges++;
FT_ZERO( edge );
edge->fpos = (FT_Short)fpos;
edge->dir = (FT_Char)dir;
Exit:
*anedge = edge;
return error;
}
#ifdef FT_DEBUG_AUTOFIT
#include FT_CONFIG_STANDARD_LIBRARY_H
/* The dump functions are used in the `ftgrid' demo program, too. */
#define AF_DUMP( varformat ) \
do \
{ \
if ( to_stdout ) \
printf varformat; \
else \
FT_TRACE7( varformat ); \
} while ( 0 )
static const char*
af_dir_str( AF_Direction dir )
{
const char* result;
switch ( dir )
{
case AF_DIR_UP:
result = "up";
break;
case AF_DIR_DOWN:
result = "down";
break;
case AF_DIR_LEFT:
result = "left";
break;
case AF_DIR_RIGHT:
result = "right";
break;
default:
result = "none";
}
return result;
}
#define AF_INDEX_NUM( ptr, base ) ( (ptr) ? ( (ptr) - (base) ) : -1 )
#ifdef __cplusplus
extern "C" {
#endif
void
af_glyph_hints_dump_points( AF_GlyphHints hints,
FT_Bool to_stdout )
{
AF_Point points = hints->points;
AF_Point limit = points + hints->num_points;
AF_Point point;
AF_DUMP(( "Table of points:\n"
" [ index | xorg | yorg | xscale | yscale"
" | xfit | yfit | flags ]\n" ));
for ( point = points; point < limit; point++ )
AF_DUMP(( " [ %5d | %5d | %5d | %6.2f | %6.2f"
" | %5.2f | %5.2f | %c%c%c%c%c%c ]\n",
point - points,
point->fx,
point->fy,
point->ox / 64.0,
point->oy / 64.0,
point->x / 64.0,
point->y / 64.0,
( point->flags & AF_FLAG_WEAK_INTERPOLATION ) ? 'w' : ' ',
( point->flags & AF_FLAG_INFLECTION ) ? 'i' : ' ',
( point->flags & AF_FLAG_EXTREMA_X ) ? '<' : ' ',
( point->flags & AF_FLAG_EXTREMA_Y ) ? 'v' : ' ',
( point->flags & AF_FLAG_ROUND_X ) ? '(' : ' ',
( point->flags & AF_FLAG_ROUND_Y ) ? 'u' : ' '));
AF_DUMP(( "\n" ));
}
#ifdef __cplusplus
}
#endif
static const char*
af_edge_flags_to_string( AF_Edge_Flags flags )
{
static char temp[32];
int pos = 0;
if ( flags & AF_EDGE_ROUND )
{
ft_memcpy( temp + pos, "round", 5 );
pos += 5;
}
if ( flags & AF_EDGE_SERIF )
{
if ( pos > 0 )
temp[pos++] = ' ';
ft_memcpy( temp + pos, "serif", 5 );
pos += 5;
}
if ( pos == 0 )
return "normal";
temp[pos] = '\0';
return temp;
}
/* Dump the array of linked segments. */
#ifdef __cplusplus
extern "C" {
#endif
void
af_glyph_hints_dump_segments( AF_GlyphHints hints,
FT_Bool to_stdout )
{
FT_Int dimension;
for ( dimension = 1; dimension >= 0; dimension-- )
{
AF_AxisHints axis = &hints->axis[dimension];
AF_Point points = hints->points;
AF_Edge edges = axis->edges;
AF_Segment segments = axis->segments;
AF_Segment limit = segments + axis->num_segments;
AF_Segment seg;
AF_DUMP(( "Table of %s segments:\n",
dimension == AF_DIMENSION_HORZ ? "vertical"
: "horizontal" ));
if ( axis->num_segments )
AF_DUMP(( " [ index | pos | dir | from"
" | to | link | serif | edge"
" | height | extra | flags ]\n" ));
else
AF_DUMP(( " (none)\n" ));
for ( seg = segments; seg < limit; seg++ )
AF_DUMP(( " [ %5d | %5.2g | %5s | %4d"
" | %4d | %4d | %5d | %4d"
" | %6d | %5d | %11s ]\n",
seg - segments,
dimension == AF_DIMENSION_HORZ
? (int)seg->first->ox / 64.0
: (int)seg->first->oy / 64.0,
af_dir_str( (AF_Direction)seg->dir ),
AF_INDEX_NUM( seg->first, points ),
AF_INDEX_NUM( seg->last, points ),
AF_INDEX_NUM( seg->link, segments ),
AF_INDEX_NUM( seg->serif, segments ),
AF_INDEX_NUM( seg->edge, edges ),
seg->height,
seg->height - ( seg->max_coord - seg->min_coord ),
af_edge_flags_to_string( (AF_Edge_Flags)seg->flags ) ));
AF_DUMP(( "\n" ));
}
}
#ifdef __cplusplus
}
#endif
/* Fetch number of segments. */
#ifdef __cplusplus
extern "C" {
#endif
FT_Error
af_glyph_hints_get_num_segments( AF_GlyphHints hints,
FT_Int dimension,
FT_Int* num_segments )
{
AF_Dimension dim;
AF_AxisHints axis;
dim = ( dimension == 0 ) ? AF_DIMENSION_HORZ : AF_DIMENSION_VERT;
axis = &hints->axis[dim];
*num_segments = axis->num_segments;
return FT_Err_Ok;
}
#ifdef __cplusplus
}
#endif
/* Fetch offset of segments into user supplied offset array. */
#ifdef __cplusplus
extern "C" {
#endif
FT_Error
af_glyph_hints_get_segment_offset( AF_GlyphHints hints,
FT_Int dimension,
FT_Int idx,
FT_Pos *offset,
FT_Bool *is_blue,
FT_Pos *blue_offset )
{
AF_Dimension dim;
AF_AxisHints axis;
AF_Segment seg;
if ( !offset )
return FT_THROW( Invalid_Argument );
dim = ( dimension == 0 ) ? AF_DIMENSION_HORZ : AF_DIMENSION_VERT;
axis = &hints->axis[dim];
if ( idx < 0 || idx >= axis->num_segments )
return FT_THROW( Invalid_Argument );
seg = &axis->segments[idx];
*offset = ( dim == AF_DIMENSION_HORZ ) ? seg->first->ox
: seg->first->oy;
if ( seg->edge )
*is_blue = (FT_Bool)( seg->edge->blue_edge != 0 );
else
*is_blue = FALSE;
if ( *is_blue )
*blue_offset = seg->edge->blue_edge->cur;
else
*blue_offset = 0;
return FT_Err_Ok;
}
#ifdef __cplusplus
}
#endif
/* Dump the array of linked edges. */
#ifdef __cplusplus
extern "C" {
#endif
void
af_glyph_hints_dump_edges( AF_GlyphHints hints,
FT_Bool to_stdout )
{
FT_Int dimension;
for ( dimension = 1; dimension >= 0; dimension-- )
{
AF_AxisHints axis = &hints->axis[dimension];
AF_Edge edges = axis->edges;
AF_Edge limit = edges + axis->num_edges;
AF_Edge edge;
/*
* note: AF_DIMENSION_HORZ corresponds to _vertical_ edges
* since they have a constant X coordinate.
*/
AF_DUMP(( "Table of %s edges:\n",
dimension == AF_DIMENSION_HORZ ? "vertical"
: "horizontal" ));
if ( axis->num_edges )
AF_DUMP(( " [ index | pos | dir | link"
" | serif | blue | opos | pos | flags ]\n" ));
else
AF_DUMP(( " (none)\n" ));
for ( edge = edges; edge < limit; edge++ )
AF_DUMP(( " [ %5d | %5.2g | %5s | %4d"
" | %5d | %c | %5.2f | %5.2f | %11s ]\n",
edge - edges,
(int)edge->opos / 64.0,
af_dir_str( (AF_Direction)edge->dir ),
AF_INDEX_NUM( edge->link, edges ),
AF_INDEX_NUM( edge->serif, edges ),
edge->blue_edge ? 'y' : 'n',
edge->opos / 64.0,
edge->pos / 64.0,
af_edge_flags_to_string( (AF_Edge_Flags)edge->flags ) ));
AF_DUMP(( "\n" ));
}
}
#ifdef __cplusplus
}
#endif
#undef AF_DUMP
#endif /* !FT_DEBUG_AUTOFIT */
/* Compute the direction value of a given vector. */
FT_LOCAL_DEF( AF_Direction )
af_direction_compute( FT_Pos dx,
FT_Pos dy )
{
FT_Pos ll, ss; /* long and short arm lengths */
AF_Direction dir; /* candidate direction */
if ( dy >= dx )
{
if ( dy >= -dx )
{
dir = AF_DIR_UP;
ll = dy;
ss = dx;
}
else
{
dir = AF_DIR_LEFT;
ll = -dx;
ss = dy;
}
}
else /* dy < dx */
{
if ( dy >= -dx )
{
dir = AF_DIR_RIGHT;
ll = dx;
ss = dy;
}
else
{
dir = AF_DIR_DOWN;
ll = dy;
ss = dx;
}
}
/* return no direction if arm lengths differ too much */
/* (value 14 is heuristic, corresponding to approx. 4.1 degrees) */
ss *= 14;
if ( FT_ABS( ll ) <= FT_ABS( ss ) )
dir = AF_DIR_NONE;
return dir;
}
FT_LOCAL_DEF( void )
af_glyph_hints_init( AF_GlyphHints hints,
FT_Memory memory )
{
FT_ZERO( hints );
hints->memory = memory;
}
FT_LOCAL_DEF( void )
af_glyph_hints_done( AF_GlyphHints hints )
{
FT_Memory memory = hints->memory;
int dim;
if ( !( hints && hints->memory ) )
return;
/*
* note that we don't need to free the segment and edge
* buffers since they are really within the hints->points array
*/
for ( dim = 0; dim < AF_DIMENSION_MAX; dim++ )
{
AF_AxisHints axis = &hints->axis[dim];
axis->num_segments = 0;
axis->max_segments = 0;
FT_FREE( axis->segments );
axis->num_edges = 0;
axis->max_edges = 0;
FT_FREE( axis->edges );
}
FT_FREE( hints->contours );
hints->max_contours = 0;
hints->num_contours = 0;
FT_FREE( hints->points );
hints->num_points = 0;
hints->max_points = 0;
hints->memory = NULL;
}
/* Reset metrics. */
FT_LOCAL_DEF( void )
af_glyph_hints_rescale( AF_GlyphHints hints,
AF_StyleMetrics metrics )
{
hints->metrics = metrics;
hints->scaler_flags = metrics->scaler.flags;
}
/* Recompute all AF_Point in AF_GlyphHints from the definitions */
/* in a source outline. */
FT_LOCAL_DEF( FT_Error )
af_glyph_hints_reload( AF_GlyphHints hints,
FT_Outline* outline )
{
FT_Error error = FT_Err_Ok;
AF_Point points;
FT_UInt old_max, new_max;
FT_Fixed x_scale = hints->x_scale;
FT_Fixed y_scale = hints->y_scale;
FT_Pos x_delta = hints->x_delta;
FT_Pos y_delta = hints->y_delta;
FT_Memory memory = hints->memory;
hints->num_points = 0;
hints->num_contours = 0;
hints->axis[0].num_segments = 0;
hints->axis[0].num_edges = 0;
hints->axis[1].num_segments = 0;
hints->axis[1].num_edges = 0;
/* first of all, reallocate the contours array if necessary */
new_max = (FT_UInt)outline->n_contours;
old_max = hints->max_contours;
if ( new_max > old_max )
{
new_max = ( new_max + 3 ) & ~3; /* round up to a multiple of 4 */
if ( FT_RENEW_ARRAY( hints->contours, old_max, new_max ) )
goto Exit;
hints->max_contours = new_max;
}
/*
* then reallocate the points arrays if necessary --
* note that we reserve two additional point positions, used to
* hint metrics appropriately
*/
new_max = (FT_UInt)( outline->n_points + 2 );
old_max = hints->max_points;
if ( new_max > old_max )
{
new_max = ( new_max + 2 + 7 ) & ~7; /* round up to a multiple of 8 */
if ( FT_RENEW_ARRAY( hints->points, old_max, new_max ) )
goto Exit;
hints->max_points = new_max;
}
hints->num_points = outline->n_points;
hints->num_contours = outline->n_contours;
/* We can't rely on the value of `FT_Outline.flags' to know the fill */
/* direction used for a glyph, given that some fonts are broken (e.g., */
/* the Arphic ones). We thus recompute it each time we need to. */
/* */
hints->axis[AF_DIMENSION_HORZ].major_dir = AF_DIR_UP;
hints->axis[AF_DIMENSION_VERT].major_dir = AF_DIR_LEFT;
if ( FT_Outline_Get_Orientation( outline ) == FT_ORIENTATION_POSTSCRIPT )
{
hints->axis[AF_DIMENSION_HORZ].major_dir = AF_DIR_DOWN;
hints->axis[AF_DIMENSION_VERT].major_dir = AF_DIR_RIGHT;
}
hints->x_scale = x_scale;
hints->y_scale = y_scale;
hints->x_delta = x_delta;
hints->y_delta = y_delta;
hints->xmin_delta = 0;
hints->xmax_delta = 0;
points = hints->points;
if ( hints->num_points == 0 )
goto Exit;
{
AF_Point point;
AF_Point point_limit = points + hints->num_points;
/* compute coordinates & Bezier flags, next and prev */
{
FT_Vector* vec = outline->points;
char* tag = outline->tags;
AF_Point end = points + outline->contours[0];
AF_Point prev = end;
FT_Int contour_index = 0;
for ( point = points; point < point_limit; point++, vec++, tag++ )
{
point->fx = (FT_Short)vec->x;
point->fy = (FT_Short)vec->y;
point->ox = point->x = FT_MulFix( vec->x, x_scale ) + x_delta;
point->oy = point->y = FT_MulFix( vec->y, y_scale ) + y_delta;
switch ( FT_CURVE_TAG( *tag ) )
{
case FT_CURVE_TAG_CONIC:
point->flags = AF_FLAG_CONIC;
break;
case FT_CURVE_TAG_CUBIC:
point->flags = AF_FLAG_CUBIC;
break;
default:
point->flags = AF_FLAG_NONE;
}
point->prev = prev;
prev->next = point;
prev = point;
if ( point == end )
{
if ( ++contour_index < outline->n_contours )
{
end = points + outline->contours[contour_index];
prev = end;
}
}
}
}
/* set up the contours array */
{
AF_Point* contour = hints->contours;
AF_Point* contour_limit = contour + hints->num_contours;
short* end = outline->contours;
short idx = 0;
for ( ; contour < contour_limit; contour++, end++ )
{
contour[0] = points + idx;
idx = (short)( end[0] + 1 );
}
}
/* compute directions of in & out vectors */
{
AF_Point first = points;
AF_Point prev = NULL;
FT_Pos in_x = 0;
FT_Pos in_y = 0;
AF_Direction in_dir = AF_DIR_NONE;
FT_Pos last_good_in_x = 0;
FT_Pos last_good_in_y = 0;
FT_UInt units_per_em = hints->metrics->scaler.face->units_per_EM;
FT_Int near_limit = 20 * units_per_em / 2048;
for ( point = points; point < point_limit; point++ )
{
AF_Point next;
FT_Pos out_x, out_y;
if ( point == first )
{
prev = first->prev;
in_x = first->fx - prev->fx;
in_y = first->fy - prev->fy;
last_good_in_x = in_x;
last_good_in_y = in_y;
if ( FT_ABS( in_x ) + FT_ABS( in_y ) < near_limit )
{
/* search first non-near point to get a good `in_dir' value */
AF_Point point_ = prev;
while ( point_ != first )
{
AF_Point prev_ = point_->prev;
FT_Pos in_x_ = point_->fx - prev_->fx;
FT_Pos in_y_ = point_->fy - prev_->fy;
if ( FT_ABS( in_x_ ) + FT_ABS( in_y_ ) >= near_limit )
{
last_good_in_x = in_x_;
last_good_in_y = in_y_;
break;
}
point_ = prev_;
}
}
in_dir = af_direction_compute( in_x, in_y );
first = prev + 1;
}
point->in_dir = (FT_Char)in_dir;
/* check whether the current point is near to the previous one */
/* (value 20 in `near_limit' is heuristic; we use Taxicab */
/* metrics for the test) */
if ( FT_ABS( in_x ) + FT_ABS( in_y ) < near_limit )
point->flags |= AF_FLAG_NEAR;
else
{
last_good_in_x = in_x;
last_good_in_y = in_y;
}
next = point->next;
out_x = next->fx - point->fx;
out_y = next->fy - point->fy;
in_dir = af_direction_compute( out_x, out_y );
point->out_dir = (FT_Char)in_dir;
/* Check for weak points. The remaining points not collected */
/* in edges are then implicitly classified as strong points. */
if ( point->flags & AF_FLAG_CONTROL )
{
/* control points are always weak */
Is_Weak_Point:
point->flags |= AF_FLAG_WEAK_INTERPOLATION;
}
else if ( point->out_dir == point->in_dir )
{
if ( point->out_dir != AF_DIR_NONE )
{
/* current point lies on a horizontal or */
/* vertical segment (but doesn't start or end it) */
goto Is_Weak_Point;
}
/* test whether `in' and `out' direction is approximately */
/* the same (and use the last good `in' vector in case */
/* the current point is near to the previous one) */
if ( ft_corner_is_flat(
point->flags & AF_FLAG_NEAR ? last_good_in_x : in_x,
point->flags & AF_FLAG_NEAR ? last_good_in_y : in_y,
out_x,
out_y ) )
{
/* current point lies on a straight, diagonal line */
/* (more or less) */
goto Is_Weak_Point;
}
}
else if ( point->in_dir == -point->out_dir )
{
/* current point forms a spike */
goto Is_Weak_Point;
}
in_x = out_x;
in_y = out_y;
}
}
}
Exit:
return error;
}
/* Store the hinted outline in an FT_Outline structure. */
FT_LOCAL_DEF( void )
af_glyph_hints_save( AF_GlyphHints hints,
FT_Outline* outline )
{
AF_Point point = hints->points;
AF_Point limit = point + hints->num_points;
FT_Vector* vec = outline->points;
char* tag = outline->tags;
for ( ; point < limit; point++, vec++, tag++ )
{
vec->x = point->x;
vec->y = point->y;
if ( point->flags & AF_FLAG_CONIC )
tag[0] = FT_CURVE_TAG_CONIC;
else if ( point->flags & AF_FLAG_CUBIC )
tag[0] = FT_CURVE_TAG_CUBIC;
else
tag[0] = FT_CURVE_TAG_ON;
}
}
/****************************************************************
*
* EDGE POINT GRID-FITTING
*
****************************************************************/
/* Align all points of an edge to the same coordinate value, */
/* either horizontally or vertically. */
FT_LOCAL_DEF( void )
af_glyph_hints_align_edge_points( AF_GlyphHints hints,
AF_Dimension dim )
{
AF_AxisHints axis = & hints->axis[dim];
AF_Segment segments = axis->segments;
AF_Segment segment_limit = segments + axis->num_segments;
AF_Segment seg;
if ( dim == AF_DIMENSION_HORZ )
{
for ( seg = segments; seg < segment_limit; seg++ )
{
AF_Edge edge = seg->edge;
AF_Point point, first, last;
if ( edge == NULL )
continue;
first = seg->first;
last = seg->last;
point = first;
for (;;)
{
point->x = edge->pos;
point->flags |= AF_FLAG_TOUCH_X;
if ( point == last )
break;
point = point->next;
}
}
}
else
{
for ( seg = segments; seg < segment_limit; seg++ )
{
AF_Edge edge = seg->edge;
AF_Point point, first, last;
if ( edge == NULL )
continue;
first = seg->first;
last = seg->last;
point = first;
for (;;)
{
point->y = edge->pos;
point->flags |= AF_FLAG_TOUCH_Y;
if ( point == last )
break;
point = point->next;
}
}
}
}
/****************************************************************
*
* STRONG POINT INTERPOLATION
*
****************************************************************/
/* Hint the strong points -- this is equivalent to the TrueType `IP' */
/* hinting instruction. */
FT_LOCAL_DEF( void )
af_glyph_hints_align_strong_points( AF_GlyphHints hints,
AF_Dimension dim )
{
AF_Point points = hints->points;
AF_Point point_limit = points + hints->num_points;
AF_AxisHints axis = &hints->axis[dim];
AF_Edge edges = axis->edges;
AF_Edge edge_limit = edges + axis->num_edges;
AF_Flags touch_flag;
if ( dim == AF_DIMENSION_HORZ )
touch_flag = AF_FLAG_TOUCH_X;
else
touch_flag = AF_FLAG_TOUCH_Y;
if ( edges < edge_limit )
{
AF_Point point;
AF_Edge edge;
for ( point = points; point < point_limit; point++ )
{
FT_Pos u, ou, fu; /* point position */
FT_Pos delta;
if ( point->flags & touch_flag )
continue;
/* if this point is candidate to weak interpolation, we */
/* interpolate it after all strong points have been processed */
if ( ( point->flags & AF_FLAG_WEAK_INTERPOLATION ) &&
!( point->flags & AF_FLAG_INFLECTION ) )
continue;
if ( dim == AF_DIMENSION_VERT )
{
u = point->fy;
ou = point->oy;
}
else
{
u = point->fx;
ou = point->ox;
}
fu = u;
/* is the point before the first edge? */
edge = edges;
delta = edge->fpos - u;
if ( delta >= 0 )
{
u = edge->pos - ( edge->opos - ou );
goto Store_Point;
}
/* is the point after the last edge? */
edge = edge_limit - 1;
delta = u - edge->fpos;
if ( delta >= 0 )
{
u = edge->pos + ( ou - edge->opos );
goto Store_Point;
}
{
FT_PtrDist min, max, mid;
FT_Pos fpos;
/* find enclosing edges */
min = 0;
max = edge_limit - edges;
#if 1
/* for a small number of edges, a linear search is better */
if ( max <= 8 )
{
FT_PtrDist nn;
for ( nn = 0; nn < max; nn++ )
if ( edges[nn].fpos >= u )
break;
if ( edges[nn].fpos == u )
{
u = edges[nn].pos;
goto Store_Point;
}
min = nn;
}
else
#endif
while ( min < max )
{
mid = ( max + min ) >> 1;
edge = edges + mid;
fpos = edge->fpos;
if ( u < fpos )
max = mid;
else if ( u > fpos )
min = mid + 1;
else
{
/* we are on the edge */
u = edge->pos;
goto Store_Point;
}
}
/* point is not on an edge */
{
AF_Edge before = edges + min - 1;
AF_Edge after = edges + min + 0;
/* assert( before && after && before != after ) */
if ( before->scale == 0 )
before->scale = FT_DivFix( after->pos - before->pos,
after->fpos - before->fpos );
u = before->pos + FT_MulFix( fu - before->fpos,
before->scale );
}
}
Store_Point:
/* save the point position */
if ( dim == AF_DIMENSION_HORZ )
point->x = u;
else
point->y = u;
point->flags |= touch_flag;
}
}
}
/****************************************************************
*
* WEAK POINT INTERPOLATION
*
****************************************************************/
/* Shift the original coordinates of all points between `p1' and */
/* `p2' to get hinted coordinates, using the same difference as */
/* given by `ref'. */
static void
af_iup_shift( AF_Point p1,
AF_Point p2,
AF_Point ref )
{
AF_Point p;
FT_Pos delta = ref->u - ref->v;
if ( delta == 0 )
return;
for ( p = p1; p < ref; p++ )
p->u = p->v + delta;
for ( p = ref + 1; p <= p2; p++ )
p->u = p->v + delta;
}
/* Interpolate the original coordinates of all points between `p1' and */
/* `p2' to get hinted coordinates, using `ref1' and `ref2' as the */
/* reference points. The `u' and `v' members are the current and */
/* original coordinate values, respectively. */
/* */
/* Details can be found in the TrueType bytecode specification. */
static void
af_iup_interp( AF_Point p1,
AF_Point p2,
AF_Point ref1,
AF_Point ref2 )
{
AF_Point p;
FT_Pos u;
FT_Pos v1 = ref1->v;
FT_Pos v2 = ref2->v;
FT_Pos d1 = ref1->u - v1;
FT_Pos d2 = ref2->u - v2;
if ( p1 > p2 )
return;
if ( v1 == v2 )
{
for ( p = p1; p <= p2; p++ )
{
u = p->v;
if ( u <= v1 )
u += d1;
else
u += d2;
p->u = u;
}
return;
}
if ( v1 < v2 )
{
for ( p = p1; p <= p2; p++ )
{
u = p->v;
if ( u <= v1 )
u += d1;
else if ( u >= v2 )
u += d2;
else
u = ref1->u + FT_MulDiv( u - v1, ref2->u - ref1->u, v2 - v1 );
p->u = u;
}
}
else
{
for ( p = p1; p <= p2; p++ )
{
u = p->v;
if ( u <= v2 )
u += d2;
else if ( u >= v1 )
u += d1;
else
u = ref1->u + FT_MulDiv( u - v1, ref2->u - ref1->u, v2 - v1 );
p->u = u;
}
}
}
/* Hint the weak points -- this is equivalent to the TrueType `IUP' */
/* hinting instruction. */
FT_LOCAL_DEF( void )
af_glyph_hints_align_weak_points( AF_GlyphHints hints,
AF_Dimension dim )
{
AF_Point points = hints->points;
AF_Point point_limit = points + hints->num_points;
AF_Point* contour = hints->contours;
AF_Point* contour_limit = contour + hints->num_contours;
AF_Flags touch_flag;
AF_Point point;
AF_Point end_point;
AF_Point first_point;
/* PASS 1: Move segment points to edge positions */
if ( dim == AF_DIMENSION_HORZ )
{
touch_flag = AF_FLAG_TOUCH_X;
for ( point = points; point < point_limit; point++ )
{
point->u = point->x;
point->v = point->ox;
}
}
else
{
touch_flag = AF_FLAG_TOUCH_Y;
for ( point = points; point < point_limit; point++ )
{
point->u = point->y;
point->v = point->oy;
}
}
for ( ; contour < contour_limit; contour++ )
{
AF_Point first_touched, last_touched;
point = *contour;
end_point = point->prev;
first_point = point;
/* find first touched point */
for (;;)
{
if ( point > end_point ) /* no touched point in contour */
goto NextContour;
if ( point->flags & touch_flag )
break;
point++;
}
first_touched = point;
for (;;)
{
FT_ASSERT( point <= end_point &&
( point->flags & touch_flag ) != 0 );
/* skip any touched neighbours */
while ( point < end_point &&
( point[1].flags & touch_flag ) != 0 )
point++;
last_touched = point;
/* find the next touched point, if any */
point++;
for (;;)
{
if ( point > end_point )
goto EndContour;
if ( ( point->flags & touch_flag ) != 0 )
break;
point++;
}
/* interpolate between last_touched and point */
af_iup_interp( last_touched + 1, point - 1,
last_touched, point );
}
EndContour:
/* special case: only one point was touched */
if ( last_touched == first_touched )
af_iup_shift( first_point, end_point, first_touched );
else /* interpolate the last part */
{
if ( last_touched < end_point )
af_iup_interp( last_touched + 1, end_point,
last_touched, first_touched );
if ( first_touched > points )
af_iup_interp( first_point, first_touched - 1,
last_touched, first_touched );
}
NextContour:
;
}
/* now save the interpolated values back to x/y */
if ( dim == AF_DIMENSION_HORZ )
{
for ( point = points; point < point_limit; point++ )
point->x = point->u;
}
else
{
for ( point = points; point < point_limit; point++ )
point->y = point->u;
}
}
#ifdef AF_CONFIG_OPTION_USE_WARPER
/* Apply (small) warp scale and warp delta for given dimension. */
FT_LOCAL_DEF( void )
af_glyph_hints_scale_dim( AF_GlyphHints hints,
AF_Dimension dim,
FT_Fixed scale,
FT_Pos delta )
{
AF_Point points = hints->points;
AF_Point points_limit = points + hints->num_points;
AF_Point point;
if ( dim == AF_DIMENSION_HORZ )
{
for ( point = points; point < points_limit; point++ )
point->x = FT_MulFix( point->fx, scale ) + delta;
}
else
{
for ( point = points; point < points_limit; point++ )
point->y = FT_MulFix( point->fy, scale ) + delta;
}
}
#endif /* AF_CONFIG_OPTION_USE_WARPER */
/* END */
| YifuLiu/AliOS-Things | components/freetype/src/autofit/afhints.c | C | apache-2.0 | 35,766 |
/***************************************************************************/
/* */
/* afhints.h */
/* */
/* Auto-fitter hinting routines (specification). */
/* */
/* Copyright 2003-2008, 2010-2012 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. */
/* */
/***************************************************************************/
#ifndef __AFHINTS_H__
#define __AFHINTS_H__
#include "aftypes.h"
#define xxAF_SORT_SEGMENTS
FT_BEGIN_HEADER
/*
* The definition of outline glyph hints. These are shared by all
* writing system analysis routines (until now).
*/
typedef enum AF_Dimension_
{
AF_DIMENSION_HORZ = 0, /* x coordinates, */
/* i.e., vertical segments & edges */
AF_DIMENSION_VERT = 1, /* y coordinates, */
/* i.e., horizontal segments & edges */
AF_DIMENSION_MAX /* do not remove */
} AF_Dimension;
/* hint directions -- the values are computed so that two vectors are */
/* in opposite directions iff `dir1 + dir2 == 0' */
typedef enum AF_Direction_
{
AF_DIR_NONE = 4,
AF_DIR_RIGHT = 1,
AF_DIR_LEFT = -1,
AF_DIR_UP = 2,
AF_DIR_DOWN = -2
} AF_Direction;
/*
* The following explanations are mostly taken from the article
*
* Real-Time Grid Fitting of Typographic Outlines
*
* by David Turner and Werner Lemberg
*
* http://www.tug.org/TUGboat/Articles/tb24-3/lemberg.pdf
*
* with appropriate updates.
*
*
* Segments
*
* `af_{cjk,latin,...}_hints_compute_segments' are the functions to
* find segments in an outline.
*
* A segment is a series of consecutive points that are approximately
* aligned along a coordinate axis. The analysis to do so is specific
* to a writing system.
*
* A segment must have at least two points, except in the case of
* `fake' segments that are generated to hint metrics appropriately,
* and which consist of a single point.
*
*
* Edges
*
* `af_{cjk,latin,...}_hints_compute_edges' are the functions to find
* edges.
*
* As soon as segments are defined, the auto-hinter groups them into
* edges. An edge corresponds to a single position on the main
* dimension that collects one or more segments (allowing for a small
* threshold).
*
* As an example, the `latin' writing system first tries to grid-fit
* edges, then to align segments on the edges unless it detects that
* they form a serif.
*
*
* A H
* | |
* | |
* | |
* | |
* C | | F
* +------<-----+ +-----<------+
* | B G |
* | |
* | |
* +--------------->------------------+
* D E
*
*
* Stems
*
* Stems are detected by `af_{cjk,latin,...}_hint_edges'.
*
* Segments need to be `linked' to other ones in order to detect stems.
* A stem is made of two segments that face each other in opposite
* directions and that are sufficiently close to each other. Using
* vocabulary from the TrueType specification, stem segments form a
* `black distance'.
*
* In the above ASCII drawing, the horizontal segments are BC, DE, and
* FG; the vertical segments are AB, CD, EF, and GH.
*
* Each segment has at most one `best' candidate to form a black
* distance, or no candidate at all. Notice that two distinct segments
* can have the same candidate, which frequently means a serif.
*
* A stem is recognized by the following condition:
*
* best segment_1 = segment_2 && best segment_2 = segment_1
*
* The best candidate is stored in field `link' in structure
* `AF_Segment'.
*
* In the above ASCII drawing, the best candidate for both AB and CD is
* GH, while the best candidate for GH is AB. Similarly, the best
* candidate for EF and GH is AB, while the best candidate for AB is
* GH.
*
* The detection and handling of stems is dependent on the writing
* system.
*
*
* Serifs
*
* Serifs are detected by `af_{cjk,latin,...}_hint_edges'.
*
* In comparison to a stem, a serif (as handled by the auto-hinter
* module which takes care of the `latin' writing system) has
*
* best segment_1 = segment_2 && best segment_2 != segment_1
*
* where segment_1 corresponds to the serif segment (CD and EF in the
* above ASCII drawing).
*
* The best candidate is stored in field `serif' in structure
* `AF_Segment' (and `link' is set to NULL).
*
*
* Touched points
*
* A point is called `touched' if it has been processed somehow by the
* auto-hinter. It basically means that it shouldn't be moved again
* (or moved only under certain constraints to preserve the already
* applied processing).
*
*
* Flat and round segments
*
* Segments are `round' or `flat', depending on the series of points
* that define them. A segment is round if the next and previous point
* of an extremum (which can be either a single point or sequence of
* points) are both conic or cubic control points. Otherwise, a
* segment with an extremum is flat.
*
*
* Strong Points
*
* Experience has shown that points which are not part of an edge need
* to be interpolated linearly between their two closest edges, even if
* these are not part of the contour of those particular points.
* Typical candidates for this are
*
* - angle points (i.e., points where the `in' and `out' direction
* differ greatly)
*
* - inflection points (i.e., where the `in' and `out' angles are the
* same, but the curvature changes sign) [currently, such points
* aren't handled in the auto-hinter]
*
* `af_glyph_hints_align_strong_points' is the function which takes
* care of such situations; it is equivalent to the TrueType `IP'
* hinting instruction.
*
*
* Weak Points
*
* Other points in the outline must be interpolated using the
* coordinates of their previous and next unfitted contour neighbours.
* These are called `weak points' and are touched by the function
* `af_glyph_hints_align_weak_points', equivalent to the TrueType `IUP'
* hinting instruction. Typical candidates are control points and
* points on the contour without a major direction.
*
* The major effect is to reduce possible distortion caused by
* alignment of edges and strong points, thus weak points are processed
* after strong points.
*/
/* point hint flags */
typedef enum AF_Flags_
{
AF_FLAG_NONE = 0,
/* point type flags */
AF_FLAG_CONIC = 1 << 0,
AF_FLAG_CUBIC = 1 << 1,
AF_FLAG_CONTROL = AF_FLAG_CONIC | AF_FLAG_CUBIC,
/* point extremum flags */
AF_FLAG_EXTREMA_X = 1 << 2,
AF_FLAG_EXTREMA_Y = 1 << 3,
/* point roundness flags */
AF_FLAG_ROUND_X = 1 << 4,
AF_FLAG_ROUND_Y = 1 << 5,
/* point touch flags */
AF_FLAG_TOUCH_X = 1 << 6,
AF_FLAG_TOUCH_Y = 1 << 7,
/* candidates for weak interpolation have this flag set */
AF_FLAG_WEAK_INTERPOLATION = 1 << 8,
/* all inflection points in the outline have this flag set */
AF_FLAG_INFLECTION = 1 << 9,
/* the current point is very near to another one */
AF_FLAG_NEAR = 1 << 10
} AF_Flags;
/* edge hint flags */
typedef enum AF_Edge_Flags_
{
AF_EDGE_NORMAL = 0,
AF_EDGE_ROUND = 1 << 0,
AF_EDGE_SERIF = 1 << 1,
AF_EDGE_DONE = 1 << 2
} AF_Edge_Flags;
typedef struct AF_PointRec_* AF_Point;
typedef struct AF_SegmentRec_* AF_Segment;
typedef struct AF_EdgeRec_* AF_Edge;
typedef struct AF_PointRec_
{
FT_UShort flags; /* point flags used by hinter */
FT_Char in_dir; /* direction of inwards vector */
FT_Char out_dir; /* direction of outwards vector */
FT_Pos ox, oy; /* original, scaled position */
FT_Short fx, fy; /* original, unscaled position (in font units) */
FT_Pos x, y; /* current position */
FT_Pos u, v; /* current (x,y) or (y,x) depending on context */
AF_Point next; /* next point in contour */
AF_Point prev; /* previous point in contour */
} AF_PointRec;
typedef struct AF_SegmentRec_
{
FT_Byte flags; /* edge/segment flags for this segment */
FT_Char dir; /* segment direction */
FT_Short pos; /* position of segment */
FT_Short min_coord; /* minimum coordinate of segment */
FT_Short max_coord; /* maximum coordinate of segment */
FT_Short height; /* the hinted segment height */
AF_Edge edge; /* the segment's parent edge */
AF_Segment edge_next; /* link to next segment in parent edge */
AF_Segment link; /* (stem) link segment */
AF_Segment serif; /* primary segment for serifs */
FT_Pos num_linked; /* number of linked segments */
FT_Pos score; /* used during stem matching */
FT_Pos len; /* used during stem matching */
AF_Point first; /* first point in edge segment */
AF_Point last; /* last point in edge segment */
} AF_SegmentRec;
typedef struct AF_EdgeRec_
{
FT_Short fpos; /* original, unscaled position (in font units) */
FT_Pos opos; /* original, scaled position */
FT_Pos pos; /* current position */
FT_Byte flags; /* edge flags */
FT_Char dir; /* edge direction */
FT_Fixed scale; /* used to speed up interpolation between edges */
AF_Width blue_edge; /* non-NULL if this is a blue edge */
AF_Edge link; /* link edge */
AF_Edge serif; /* primary edge for serifs */
FT_Short num_linked; /* number of linked edges */
FT_Int score; /* used during stem matching */
AF_Segment first; /* first segment in edge */
AF_Segment last; /* last segment in edge */
} AF_EdgeRec;
typedef struct AF_AxisHintsRec_
{
FT_Int num_segments; /* number of used segments */
FT_Int max_segments; /* number of allocated segments */
AF_Segment segments; /* segments array */
#ifdef AF_SORT_SEGMENTS
FT_Int mid_segments;
#endif
FT_Int num_edges; /* number of used edges */
FT_Int max_edges; /* number of allocated edges */
AF_Edge edges; /* edges array */
AF_Direction major_dir; /* either vertical or horizontal */
} AF_AxisHintsRec, *AF_AxisHints;
typedef struct AF_GlyphHintsRec_
{
FT_Memory memory;
FT_Fixed x_scale;
FT_Pos x_delta;
FT_Fixed y_scale;
FT_Pos y_delta;
FT_Int max_points; /* number of allocated points */
FT_Int num_points; /* number of used points */
AF_Point points; /* points array */
FT_Int max_contours; /* number of allocated contours */
FT_Int num_contours; /* number of used contours */
AF_Point* contours; /* contours array */
AF_AxisHintsRec axis[AF_DIMENSION_MAX];
FT_UInt32 scaler_flags; /* copy of scaler flags */
FT_UInt32 other_flags; /* free for style-specific */
/* implementations */
AF_StyleMetrics metrics;
FT_Pos xmin_delta; /* used for warping */
FT_Pos xmax_delta;
} AF_GlyphHintsRec;
#define AF_HINTS_TEST_SCALER( h, f ) ( (h)->scaler_flags & (f) )
#define AF_HINTS_TEST_OTHER( h, f ) ( (h)->other_flags & (f) )
#ifdef FT_DEBUG_AUTOFIT
#define AF_HINTS_DO_HORIZONTAL( h ) \
( !_af_debug_disable_horz_hints && \
!AF_HINTS_TEST_SCALER( h, AF_SCALER_FLAG_NO_HORIZONTAL ) )
#define AF_HINTS_DO_VERTICAL( h ) \
( !_af_debug_disable_vert_hints && \
!AF_HINTS_TEST_SCALER( h, AF_SCALER_FLAG_NO_VERTICAL ) )
#define AF_HINTS_DO_ADVANCE( h ) \
!AF_HINTS_TEST_SCALER( h, AF_SCALER_FLAG_NO_ADVANCE )
#define AF_HINTS_DO_BLUES( h ) ( !_af_debug_disable_blue_hints )
#else /* !FT_DEBUG_AUTOFIT */
#define AF_HINTS_DO_HORIZONTAL( h ) \
!AF_HINTS_TEST_SCALER( h, AF_SCALER_FLAG_NO_HORIZONTAL )
#define AF_HINTS_DO_VERTICAL( h ) \
!AF_HINTS_TEST_SCALER( h, AF_SCALER_FLAG_NO_VERTICAL )
#define AF_HINTS_DO_ADVANCE( h ) \
!AF_HINTS_TEST_SCALER( h, AF_SCALER_FLAG_NO_ADVANCE )
#define AF_HINTS_DO_BLUES( h ) 1
#endif /* !FT_DEBUG_AUTOFIT */
FT_LOCAL( AF_Direction )
af_direction_compute( FT_Pos dx,
FT_Pos dy );
FT_LOCAL( FT_Error )
af_axis_hints_new_segment( AF_AxisHints axis,
FT_Memory memory,
AF_Segment *asegment );
FT_LOCAL( FT_Error)
af_axis_hints_new_edge( AF_AxisHints axis,
FT_Int fpos,
AF_Direction dir,
FT_Memory memory,
AF_Edge *edge );
FT_LOCAL( void )
af_glyph_hints_init( AF_GlyphHints hints,
FT_Memory memory );
FT_LOCAL( void )
af_glyph_hints_rescale( AF_GlyphHints hints,
AF_StyleMetrics metrics );
FT_LOCAL( FT_Error )
af_glyph_hints_reload( AF_GlyphHints hints,
FT_Outline* outline );
FT_LOCAL( void )
af_glyph_hints_save( AF_GlyphHints hints,
FT_Outline* outline );
FT_LOCAL( void )
af_glyph_hints_align_edge_points( AF_GlyphHints hints,
AF_Dimension dim );
FT_LOCAL( void )
af_glyph_hints_align_strong_points( AF_GlyphHints hints,
AF_Dimension dim );
FT_LOCAL( void )
af_glyph_hints_align_weak_points( AF_GlyphHints hints,
AF_Dimension dim );
#ifdef AF_CONFIG_OPTION_USE_WARPER
FT_LOCAL( void )
af_glyph_hints_scale_dim( AF_GlyphHints hints,
AF_Dimension dim,
FT_Fixed scale,
FT_Pos delta );
#endif
FT_LOCAL( void )
af_glyph_hints_done( AF_GlyphHints hints );
/* */
#define AF_SEGMENT_LEN( seg ) ( (seg)->max_coord - (seg)->min_coord )
#define AF_SEGMENT_DIST( seg1, seg2 ) ( ( (seg1)->pos > (seg2)->pos ) \
? (seg1)->pos - (seg2)->pos \
: (seg2)->pos - (seg1)->pos )
FT_END_HEADER
#endif /* __AFHINTS_H__ */
/* END */
| YifuLiu/AliOS-Things | components/freetype/src/autofit/afhints.h | C | apache-2.0 | 16,884 |
/***************************************************************************/
/* */
/* afindic.c */
/* */
/* Auto-fitter hinting routines for Indic writing system (body). */
/* */
/* Copyright 2007, 2011-2013 by */
/* Rahul Bhalerao <rahul.bhalerao@redhat.com>, <b.rahul.pm@gmail.com>. */
/* */
/* 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. */
/* */
/***************************************************************************/
#include "aftypes.h"
#include "aflatin.h"
#ifdef AF_CONFIG_OPTION_INDIC
#include "afindic.h"
#include "aferrors.h"
#include "afcjk.h"
#ifdef AF_CONFIG_OPTION_USE_WARPER
#include "afwarp.h"
#endif
static FT_Error
af_indic_metrics_init( AF_CJKMetrics metrics,
FT_Face face )
{
/* skip blue zone init in CJK routines */
FT_CharMap oldmap = face->charmap;
metrics->units_per_em = face->units_per_EM;
if ( FT_Select_Charmap( face, FT_ENCODING_UNICODE ) )
face->charmap = NULL;
else
{
af_cjk_metrics_init_widths( metrics, face );
#if 0
/* either need indic specific blue_chars[] or just skip blue zones */
af_cjk_metrics_init_blues( metrics, face, af_cjk_blue_chars );
#endif
af_cjk_metrics_check_digits( metrics, face );
}
FT_Set_Charmap( face, oldmap );
return FT_Err_Ok;
}
static void
af_indic_metrics_scale( AF_CJKMetrics metrics,
AF_Scaler scaler )
{
/* use CJK routines */
af_cjk_metrics_scale( metrics, scaler );
}
static FT_Error
af_indic_hints_init( AF_GlyphHints hints,
AF_CJKMetrics metrics )
{
/* use CJK routines */
return af_cjk_hints_init( hints, metrics );
}
static FT_Error
af_indic_hints_apply( AF_GlyphHints hints,
FT_Outline* outline,
AF_CJKMetrics metrics )
{
/* use CJK routines */
return af_cjk_hints_apply( hints, outline, metrics );
}
/*************************************************************************/
/*************************************************************************/
/***** *****/
/***** I N D I C S C R I P T C L A S S *****/
/***** *****/
/*************************************************************************/
/*************************************************************************/
AF_DEFINE_WRITING_SYSTEM_CLASS(
af_indic_writing_system_class,
AF_WRITING_SYSTEM_INDIC,
sizeof ( AF_CJKMetricsRec ),
(AF_WritingSystem_InitMetricsFunc) af_indic_metrics_init,
(AF_WritingSystem_ScaleMetricsFunc)af_indic_metrics_scale,
(AF_WritingSystem_DoneMetricsFunc) NULL,
(AF_WritingSystem_InitHintsFunc) af_indic_hints_init,
(AF_WritingSystem_ApplyHintsFunc) af_indic_hints_apply
)
#else /* !AF_CONFIG_OPTION_INDIC */
AF_DEFINE_WRITING_SYSTEM_CLASS(
af_indic_writing_system_class,
AF_WRITING_SYSTEM_INDIC,
sizeof ( AF_CJKMetricsRec ),
(AF_WritingSystem_InitMetricsFunc) NULL,
(AF_WritingSystem_ScaleMetricsFunc)NULL,
(AF_WritingSystem_DoneMetricsFunc) NULL,
(AF_WritingSystem_InitHintsFunc) NULL,
(AF_WritingSystem_ApplyHintsFunc) NULL
)
#endif /* !AF_CONFIG_OPTION_INDIC */
/* END */
| YifuLiu/AliOS-Things | components/freetype/src/autofit/afindic.c | C | apache-2.0 | 4,221 |
/***************************************************************************/
/* */
/* afindic.h */
/* */
/* Auto-fitter hinting routines for Indic writing system */
/* (specification). */
/* */
/* Copyright 2007, 2012, 2013 by */
/* Rahul Bhalerao <rahul.bhalerao@redhat.com>, <b.rahul.pm@gmail.com>. */
/* */
/* 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. */
/* */
/***************************************************************************/
#ifndef __AFINDIC_H__
#define __AFINDIC_H__
#include "afhints.h"
FT_BEGIN_HEADER
/* the `indic' writing system */
AF_DECLARE_WRITING_SYSTEM_CLASS( af_indic_writing_system_class )
/* */
FT_END_HEADER
#endif /* __AFINDIC_H__ */
/* END */
| YifuLiu/AliOS-Things | components/freetype/src/autofit/afindic.h | C | apache-2.0 | 1,580 |
/***************************************************************************/
/* */
/* aflatin.c */
/* */
/* Auto-fitter hinting routines for latin writing system (body). */
/* */
/* Copyright 2003-2014 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. */
/* */
/***************************************************************************/
#include <ft2build.h>
#include FT_ADVANCES_H
#include FT_INTERNAL_DEBUG_H
#include "afglobal.h"
#include "afpic.h"
#include "aflatin.h"
#include "aferrors.h"
#ifdef AF_CONFIG_OPTION_USE_WARPER
#include "afwarp.h"
#endif
/*************************************************************************/
/* */
/* The macro FT_COMPONENT is used in trace mode. It is an implicit */
/* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */
/* messages during execution. */
/* */
#undef FT_COMPONENT
#define FT_COMPONENT trace_aflatin
/*************************************************************************/
/*************************************************************************/
/***** *****/
/***** L A T I N G L O B A L M E T R I C S *****/
/***** *****/
/*************************************************************************/
/*************************************************************************/
/* Find segments and links, compute all stem widths, and initialize */
/* standard width and height for the glyph with given charcode. */
FT_LOCAL_DEF( void )
af_latin_metrics_init_widths( AF_LatinMetrics metrics,
FT_Face face )
{
/* scan the array of segments in each direction */
AF_GlyphHintsRec hints[1];
FT_TRACE5(( "\n"
"latin standard widths computation (style `%s')\n"
"=====================================================\n"
"\n",
af_style_names[metrics->root.style_class->style] ));
af_glyph_hints_init( hints, face->memory );
metrics->axis[AF_DIMENSION_HORZ].width_count = 0;
metrics->axis[AF_DIMENSION_VERT].width_count = 0;
{
FT_Error error;
FT_ULong glyph_index;
FT_Long y_offset;
int dim;
AF_LatinMetricsRec dummy[1];
AF_Scaler scaler = &dummy->root.scaler;
#ifdef FT_CONFIG_OPTION_PIC
AF_FaceGlobals globals = metrics->root.globals;
#endif
AF_StyleClass style_class = metrics->root.style_class;
AF_ScriptClass script_class = AF_SCRIPT_CLASSES_GET
[style_class->script];
FT_UInt32 standard_char;
/*
* We check more than a single standard character to catch features
* like `c2sc' (small caps from caps) that don't contain lowercase
* letters by definition, or other features that mainly operate on
* numerals.
*/
standard_char = script_class->standard_char1;
af_get_char_index( &metrics->root,
standard_char,
&glyph_index,
&y_offset );
if ( !glyph_index )
{
if ( script_class->standard_char2 )
{
standard_char = script_class->standard_char2;
af_get_char_index( &metrics->root,
standard_char,
&glyph_index,
&y_offset );
if ( !glyph_index )
{
if ( script_class->standard_char3 )
{
standard_char = script_class->standard_char3;
af_get_char_index( &metrics->root,
standard_char,
&glyph_index,
&y_offset );
if ( !glyph_index )
goto Exit;
}
else
goto Exit;
}
}
else
goto Exit;
}
FT_TRACE5(( "standard character: U+%04lX (glyph index %d)\n",
standard_char, glyph_index ));
error = FT_Load_Glyph( face, glyph_index, FT_LOAD_NO_SCALE );
if ( error || face->glyph->outline.n_points <= 0 )
goto Exit;
FT_ZERO( dummy );
dummy->units_per_em = metrics->units_per_em;
scaler->x_scale = 0x10000L;
scaler->y_scale = 0x10000L;
scaler->x_delta = 0;
scaler->y_delta = 0;
scaler->face = face;
scaler->render_mode = FT_RENDER_MODE_NORMAL;
scaler->flags = 0;
af_glyph_hints_rescale( hints, (AF_StyleMetrics)dummy );
error = af_glyph_hints_reload( hints, &face->glyph->outline );
if ( error )
goto Exit;
for ( dim = 0; dim < AF_DIMENSION_MAX; dim++ )
{
AF_LatinAxis axis = &metrics->axis[dim];
AF_AxisHints axhints = &hints->axis[dim];
AF_Segment seg, limit, link;
FT_UInt num_widths = 0;
error = af_latin_hints_compute_segments( hints,
(AF_Dimension)dim );
if ( error )
goto Exit;
af_latin_hints_link_segments( hints,
(AF_Dimension)dim );
seg = axhints->segments;
limit = seg + axhints->num_segments;
for ( ; seg < limit; seg++ )
{
link = seg->link;
/* we only consider stem segments there! */
if ( link && link->link == seg && link > seg )
{
FT_Pos dist;
dist = seg->pos - link->pos;
if ( dist < 0 )
dist = -dist;
if ( num_widths < AF_LATIN_MAX_WIDTHS )
axis->widths[num_widths++].org = dist;
}
}
/* this also replaces multiple almost identical stem widths */
/* with a single one (the value 100 is heuristic) */
af_sort_and_quantize_widths( &num_widths, axis->widths,
dummy->units_per_em / 100 );
axis->width_count = num_widths;
}
Exit:
for ( dim = 0; dim < AF_DIMENSION_MAX; dim++ )
{
AF_LatinAxis axis = &metrics->axis[dim];
FT_Pos stdw;
stdw = ( axis->width_count > 0 ) ? axis->widths[0].org
: AF_LATIN_CONSTANT( metrics, 50 );
/* let's try 20% of the smallest width */
axis->edge_distance_threshold = stdw / 5;
axis->standard_width = stdw;
axis->extra_light = 0;
#ifdef FT_DEBUG_LEVEL_TRACE
{
FT_UInt i;
FT_TRACE5(( "%s widths:\n",
dim == AF_DIMENSION_VERT ? "horizontal"
: "vertical" ));
FT_TRACE5(( " %d (standard)", axis->standard_width ));
for ( i = 1; i < axis->width_count; i++ )
FT_TRACE5(( " %d", axis->widths[i].org ));
FT_TRACE5(( "\n" ));
}
#endif
}
}
FT_TRACE5(( "\n" ));
af_glyph_hints_done( hints );
}
/* Find all blue zones. Flat segments give the reference points, */
/* round segments the overshoot positions. */
static void
af_latin_metrics_init_blues( AF_LatinMetrics metrics,
FT_Face face )
{
FT_Pos flats [AF_BLUE_STRING_MAX_LEN];
FT_Pos rounds[AF_BLUE_STRING_MAX_LEN];
FT_Int num_flats;
FT_Int num_rounds;
AF_LatinBlue blue;
FT_Error error;
AF_LatinAxis axis = &metrics->axis[AF_DIMENSION_VERT];
FT_Outline outline;
AF_StyleClass sc = metrics->root.style_class;
AF_Blue_Stringset bss = sc->blue_stringset;
const AF_Blue_StringRec* bs = &af_blue_stringsets[bss];
/* we walk over the blue character strings as specified in the */
/* style's entry in the `af_blue_stringset' array */
FT_TRACE5(( "latin blue zones computation\n"
"============================\n"
"\n" ));
for ( ; bs->string != AF_BLUE_STRING_MAX; bs++ )
{
const char* p = &af_blue_strings[bs->string];
FT_Pos* blue_ref;
FT_Pos* blue_shoot;
#ifdef FT_DEBUG_LEVEL_TRACE
{
FT_Bool have_flag = 0;
FT_TRACE5(( "blue zone %d", axis->blue_count ));
if ( bs->properties )
{
FT_TRACE5(( " (" ));
if ( AF_LATIN_IS_TOP_BLUE( bs ) )
{
FT_TRACE5(( "top" ));
have_flag = 1;
}
if ( AF_LATIN_IS_X_HEIGHT_BLUE( bs ) )
{
if ( have_flag )
FT_TRACE5(( ", " ));
FT_TRACE5(( "small top" ));
have_flag = 1;
}
if ( AF_LATIN_IS_LONG_BLUE( bs ) )
{
if ( have_flag )
FT_TRACE5(( ", " ));
FT_TRACE5(( "long" ));
}
FT_TRACE5(( ")" ));
}
FT_TRACE5(( ":\n" ));
}
#endif /* FT_DEBUG_LEVEL_TRACE */
num_flats = 0;
num_rounds = 0;
while ( *p )
{
FT_ULong ch;
FT_ULong glyph_index;
FT_Long y_offset;
FT_Pos best_y; /* same as points.y */
FT_Int best_point, best_contour_first, best_contour_last;
FT_Vector* points;
FT_Bool round = 0;
GET_UTF8_CHAR( ch, p );
/* load the character in the face -- skip unknown or empty ones */
af_get_char_index( &metrics->root, ch, &glyph_index, &y_offset );
if ( glyph_index == 0 )
{
FT_TRACE5(( " U+%04lX unavailable\n", ch ));
continue;
}
error = FT_Load_Glyph( face, glyph_index, FT_LOAD_NO_SCALE );
outline = face->glyph->outline;
if ( error || outline.n_points <= 0 )
{
FT_TRACE5(( " U+%04lX contains no outlines\n", ch ));
continue;
}
/* now compute min or max point indices and coordinates */
points = outline.points;
best_point = -1;
best_y = 0; /* make compiler happy */
best_contour_first = 0; /* ditto */
best_contour_last = 0; /* ditto */
{
FT_Int nn;
FT_Int first = 0;
FT_Int last = -1;
for ( nn = 0; nn < outline.n_contours; first = last + 1, nn++ )
{
FT_Int old_best_point = best_point;
FT_Int pp;
last = outline.contours[nn];
/* Avoid single-point contours since they are never rasterized. */
/* In some fonts, they correspond to mark attachment points */
/* that are way outside of the glyph's real outline. */
if ( last <= first )
continue;
if ( AF_LATIN_IS_TOP_BLUE( bs ) )
{
for ( pp = first; pp <= last; pp++ )
if ( best_point < 0 || points[pp].y > best_y )
{
best_point = pp;
best_y = points[pp].y;
}
}
else
{
for ( pp = first; pp <= last; pp++ )
if ( best_point < 0 || points[pp].y < best_y )
{
best_point = pp;
best_y = points[pp].y;
}
}
if ( best_point != old_best_point )
{
best_contour_first = first;
best_contour_last = last;
}
}
}
/* now check whether the point belongs to a straight or round */
/* segment; we first need to find in which contour the extremum */
/* lies, then inspect its previous and next points */
if ( best_point >= 0 )
{
FT_Pos best_x = points[best_point].x;
FT_Int prev, next;
FT_Int best_segment_first, best_segment_last;
FT_Int best_on_point_first, best_on_point_last;
FT_Pos dist;
best_segment_first = best_point;
best_segment_last = best_point;
if ( FT_CURVE_TAG( outline.tags[best_point] ) == FT_CURVE_TAG_ON )
{
best_on_point_first = best_point;
best_on_point_last = best_point;
}
else
{
best_on_point_first = -1;
best_on_point_last = -1;
}
/* look for the previous and next points on the contour */
/* that are not on the same Y coordinate, then threshold */
/* the `closeness'... */
prev = best_point;
next = prev;
do
{
if ( prev > best_contour_first )
prev--;
else
prev = best_contour_last;
dist = FT_ABS( points[prev].y - best_y );
/* accept a small distance or a small angle (both values are */
/* heuristic; value 20 corresponds to approx. 2.9 degrees) */
if ( dist > 5 )
if ( FT_ABS( points[prev].x - best_x ) <= 20 * dist )
break;
best_segment_first = prev;
if ( FT_CURVE_TAG( outline.tags[prev] ) == FT_CURVE_TAG_ON )
{
best_on_point_first = prev;
if ( best_on_point_last < 0 )
best_on_point_last = prev;
}
} while ( prev != best_point );
do
{
if ( next < best_contour_last )
next++;
else
next = best_contour_first;
dist = FT_ABS( points[next].y - best_y );
if ( dist > 5 )
if ( FT_ABS( points[next].x - best_x ) <= 20 * dist )
break;
best_segment_last = next;
if ( FT_CURVE_TAG( outline.tags[next] ) == FT_CURVE_TAG_ON )
{
best_on_point_last = next;
if ( best_on_point_first < 0 )
best_on_point_first = next;
}
} while ( next != best_point );
if ( AF_LATIN_IS_LONG_BLUE( bs ) )
{
/* If this flag is set, we have an additional constraint to */
/* get the blue zone distance: Find a segment of the topmost */
/* (or bottommost) contour that is longer than a heuristic */
/* threshold. This ensures that small bumps in the outline */
/* are ignored (for example, the `vertical serifs' found in */
/* many Hebrew glyph designs). */
/* If this segment is long enough, we are done. Otherwise, */
/* search the segment next to the extremum that is long */
/* enough, has the same direction, and a not too large */
/* vertical distance from the extremum. Note that the */
/* algorithm doesn't check whether the found segment is */
/* actually the one (vertically) nearest to the extremum. */
/* heuristic threshold value */
FT_Pos length_threshold = metrics->units_per_em / 25;
dist = FT_ABS( points[best_segment_last].x -
points[best_segment_first].x );
if ( dist < length_threshold &&
best_segment_last - best_segment_first + 2 <=
best_contour_last - best_contour_first )
{
/* heuristic threshold value */
FT_Pos height_threshold = metrics->units_per_em / 4;
FT_Int first;
FT_Int last;
FT_Bool hit;
FT_Bool left2right;
/* compute direction */
prev = best_point;
do
{
if ( prev > best_contour_first )
prev--;
else
prev = best_contour_last;
if ( points[prev].x != best_x )
break;
} while ( prev != best_point );
/* skip glyph for the degenerate case */
if ( prev == best_point )
continue;
left2right = FT_BOOL( points[prev].x < points[best_point].x );
first = best_segment_last;
last = first;
hit = 0;
do
{
FT_Bool l2r;
FT_Pos d;
FT_Int p_first, p_last;
if ( !hit )
{
/* no hit; adjust first point */
first = last;
/* also adjust first and last on point */
if ( FT_CURVE_TAG( outline.tags[first] ) ==
FT_CURVE_TAG_ON )
{
p_first = first;
p_last = first;
}
else
{
p_first = -1;
p_last = -1;
}
hit = 1;
}
if ( last < best_contour_last )
last++;
else
last = best_contour_first;
if ( FT_ABS( best_y - points[first].y ) > height_threshold )
{
/* vertical distance too large */
hit = 0;
continue;
}
/* same test as above */
dist = FT_ABS( points[last].y - points[first].y );
if ( dist > 5 )
if ( FT_ABS( points[last].x - points[first].x ) <=
20 * dist )
{
hit = 0;
continue;
}
if ( FT_CURVE_TAG( outline.tags[last] ) == FT_CURVE_TAG_ON )
{
p_last = last;
if ( p_first < 0 )
p_first = last;
}
l2r = FT_BOOL( points[first].x < points[last].x );
d = FT_ABS( points[last].x - points[first].x );
if ( l2r == left2right &&
d >= length_threshold )
{
/* all constraints are met; update segment after finding */
/* its end */
do
{
if ( last < best_contour_last )
last++;
else
last = best_contour_first;
d = FT_ABS( points[last].y - points[first].y );
if ( d > 5 )
if ( FT_ABS( points[next].x - points[first].x ) <=
20 * dist )
{
if ( last > best_contour_first )
last--;
else
last = best_contour_last;
break;
}
p_last = last;
if ( FT_CURVE_TAG( outline.tags[last] ) ==
FT_CURVE_TAG_ON )
{
p_last = last;
if ( p_first < 0 )
p_first = last;
}
} while ( last != best_segment_first );
best_y = points[first].y;
best_segment_first = first;
best_segment_last = last;
best_on_point_first = p_first;
best_on_point_last = p_last;
break;
}
} while ( last != best_segment_first );
}
}
/* for computing blue zones, we add the y offset as returned */
/* by the currently used OpenType feature -- for example, */
/* superscript glyphs might be identical to subscript glyphs */
/* with a vertical shift */
best_y += y_offset;
FT_TRACE5(( " U+%04lX: best_y = %5ld", ch, best_y ));
/* now set the `round' flag depending on the segment's kind: */
/* */
/* - if the horizontal distance between the first and last */
/* `on' point is larger than upem/8 (value 8 is heuristic) */
/* we have a flat segment */
/* - if either the first or the last point of the segment is */
/* an `off' point, the segment is round, otherwise it is */
/* flat */
if ( best_on_point_first >= 0 &&
best_on_point_last >= 0 &&
(FT_UInt)( FT_ABS( points[best_on_point_last].x -
points[best_on_point_first].x ) ) >
metrics->units_per_em / 8 )
round = 0;
else
round = FT_BOOL(
FT_CURVE_TAG( outline.tags[best_segment_first] ) !=
FT_CURVE_TAG_ON ||
FT_CURVE_TAG( outline.tags[best_segment_last] ) !=
FT_CURVE_TAG_ON );
FT_TRACE5(( " (%s)\n", round ? "round" : "flat" ));
}
if ( round )
rounds[num_rounds++] = best_y;
else
flats[num_flats++] = best_y;
}
if ( num_flats == 0 && num_rounds == 0 )
{
/*
* we couldn't find a single glyph to compute this blue zone,
* we will simply ignore it then
*/
FT_TRACE5(( " empty\n" ));
continue;
}
/* we have computed the contents of the `rounds' and `flats' tables, */
/* now determine the reference and overshoot position of the blue -- */
/* we simply take the median value after a simple sort */
af_sort_pos( num_rounds, rounds );
af_sort_pos( num_flats, flats );
blue = &axis->blues[axis->blue_count];
blue_ref = &blue->ref.org;
blue_shoot = &blue->shoot.org;
axis->blue_count++;
if ( num_flats == 0 )
{
*blue_ref =
*blue_shoot = rounds[num_rounds / 2];
}
else if ( num_rounds == 0 )
{
*blue_ref =
*blue_shoot = flats[num_flats / 2];
}
else
{
*blue_ref = flats [num_flats / 2];
*blue_shoot = rounds[num_rounds / 2];
}
/* there are sometimes problems: if the overshoot position of top */
/* zones is under its reference position, or the opposite for bottom */
/* zones. We must thus check everything there and correct the errors */
if ( *blue_shoot != *blue_ref )
{
FT_Pos ref = *blue_ref;
FT_Pos shoot = *blue_shoot;
FT_Bool over_ref = FT_BOOL( shoot > ref );
if ( AF_LATIN_IS_TOP_BLUE( bs ) ^ over_ref )
{
*blue_ref =
*blue_shoot = ( shoot + ref ) / 2;
FT_TRACE5(( " [overshoot smaller than reference,"
" taking mean value]\n" ));
}
}
blue->flags = 0;
if ( AF_LATIN_IS_TOP_BLUE( bs ) )
blue->flags |= AF_LATIN_BLUE_TOP;
/*
* The following flag is used later to adjust the y and x scales
* in order to optimize the pixel grid alignment of the top of small
* letters.
*/
if ( AF_LATIN_IS_X_HEIGHT_BLUE( bs ) )
blue->flags |= AF_LATIN_BLUE_ADJUSTMENT;
FT_TRACE5(( " -> reference = %ld\n"
" overshoot = %ld\n",
*blue_ref, *blue_shoot ));
}
FT_TRACE5(( "\n" ));
return;
}
/* Check whether all ASCII digits have the same advance width. */
FT_LOCAL_DEF( void )
af_latin_metrics_check_digits( AF_LatinMetrics metrics,
FT_Face face )
{
FT_UInt i;
FT_Bool started = 0, same_width = 1;
FT_Fixed advance, old_advance = 0;
/* digit `0' is 0x30 in all supported charmaps */
for ( i = 0x30; i <= 0x39; i++ )
{
FT_ULong glyph_index;
FT_Long y_offset;
af_get_char_index( &metrics->root, i, &glyph_index, &y_offset );
if ( glyph_index == 0 )
continue;
if ( FT_Get_Advance( face, glyph_index,
FT_LOAD_NO_SCALE |
FT_LOAD_NO_HINTING |
FT_LOAD_IGNORE_TRANSFORM,
&advance ) )
continue;
if ( started )
{
if ( advance != old_advance )
{
same_width = 0;
break;
}
}
else
{
old_advance = advance;
started = 1;
}
}
metrics->root.digits_have_same_width = same_width;
}
/* Initialize global metrics. */
FT_LOCAL_DEF( FT_Error )
af_latin_metrics_init( AF_LatinMetrics metrics,
FT_Face face )
{
FT_CharMap oldmap = face->charmap;
metrics->units_per_em = face->units_per_EM;
if ( !FT_Select_Charmap( face, FT_ENCODING_UNICODE ) )
{
af_latin_metrics_init_widths( metrics, face );
af_latin_metrics_init_blues( metrics, face );
af_latin_metrics_check_digits( metrics, face );
}
FT_Set_Charmap( face, oldmap );
return FT_Err_Ok;
}
/* Adjust scaling value, then scale and shift widths */
/* and blue zones (if applicable) for given dimension. */
static void
af_latin_metrics_scale_dim( AF_LatinMetrics metrics,
AF_Scaler scaler,
AF_Dimension dim )
{
FT_Fixed scale;
FT_Pos delta;
AF_LatinAxis axis;
FT_UInt nn;
if ( dim == AF_DIMENSION_HORZ )
{
scale = scaler->x_scale;
delta = scaler->x_delta;
}
else
{
scale = scaler->y_scale;
delta = scaler->y_delta;
}
axis = &metrics->axis[dim];
if ( axis->org_scale == scale && axis->org_delta == delta )
return;
axis->org_scale = scale;
axis->org_delta = delta;
/*
* correct X and Y scale to optimize the alignment of the top of small
* letters to the pixel grid
*/
{
AF_LatinAxis Axis = &metrics->axis[AF_DIMENSION_VERT];
AF_LatinBlue blue = NULL;
for ( nn = 0; nn < Axis->blue_count; nn++ )
{
if ( Axis->blues[nn].flags & AF_LATIN_BLUE_ADJUSTMENT )
{
blue = &Axis->blues[nn];
break;
}
}
if ( blue )
{
FT_Pos scaled;
FT_Pos threshold;
FT_Pos fitted;
FT_UInt limit;
FT_UInt ppem;
scaled = FT_MulFix( blue->shoot.org, scaler->y_scale );
ppem = metrics->root.scaler.face->size->metrics.x_ppem;
limit = metrics->root.globals->increase_x_height;
threshold = 40;
/* if the `increase-x-height' property is active, */
/* we round up much more often */
if ( limit &&
ppem <= limit &&
ppem >= AF_PROP_INCREASE_X_HEIGHT_MIN )
threshold = 52;
fitted = ( scaled + threshold ) & ~63;
if ( scaled != fitted )
{
#if 0
if ( dim == AF_DIMENSION_HORZ )
{
if ( fitted < scaled )
scale -= scale / 50; /* scale *= 0.98 */
}
else
#endif
if ( dim == AF_DIMENSION_VERT )
{
scale = FT_MulDiv( scale, fitted, scaled );
FT_TRACE5((
"af_latin_metrics_scale_dim:"
" x height alignment (style `%s'):\n"
" "
" vertical scaling changed from %.4f to %.4f (by %d%%)\n"
"\n",
af_style_names[metrics->root.style_class->style],
axis->org_scale / 65536.0,
scale / 65536.0,
( fitted - scaled ) * 100 / scaled ));
}
}
}
}
axis->scale = scale;
axis->delta = delta;
if ( dim == AF_DIMENSION_HORZ )
{
metrics->root.scaler.x_scale = scale;
metrics->root.scaler.x_delta = delta;
}
else
{
metrics->root.scaler.y_scale = scale;
metrics->root.scaler.y_delta = delta;
}
FT_TRACE5(( "%s widths (style `%s')\n",
dim == AF_DIMENSION_HORZ ? "horizontal" : "vertical",
af_style_names[metrics->root.style_class->style] ));
/* scale the widths */
for ( nn = 0; nn < axis->width_count; nn++ )
{
AF_Width width = axis->widths + nn;
width->cur = FT_MulFix( width->org, scale );
width->fit = width->cur;
FT_TRACE5(( " %d scaled to %.2f\n",
width->org,
width->cur / 64.0 ));
}
FT_TRACE5(( "\n" ));
/* an extra-light axis corresponds to a standard width that is */
/* smaller than 5/8 pixels */
axis->extra_light =
(FT_Bool)( FT_MulFix( axis->standard_width, scale ) < 32 + 8 );
#ifdef FT_DEBUG_LEVEL_TRACE
if ( axis->extra_light )
FT_TRACE5(( "`%s' style is extra light (at current resolution)\n"
"\n",
af_style_names[metrics->root.style_class->style] ));
#endif
if ( dim == AF_DIMENSION_VERT )
{
FT_TRACE5(( "blue zones (style `%s')\n",
af_style_names[metrics->root.style_class->style] ));
/* scale the blue zones */
for ( nn = 0; nn < axis->blue_count; nn++ )
{
AF_LatinBlue blue = &axis->blues[nn];
FT_Pos dist;
blue->ref.cur = FT_MulFix( blue->ref.org, scale ) + delta;
blue->ref.fit = blue->ref.cur;
blue->shoot.cur = FT_MulFix( blue->shoot.org, scale ) + delta;
blue->shoot.fit = blue->shoot.cur;
blue->flags &= ~AF_LATIN_BLUE_ACTIVE;
/* a blue zone is only active if it is less than 3/4 pixels tall */
dist = FT_MulFix( blue->ref.org - blue->shoot.org, scale );
if ( dist <= 48 && dist >= -48 )
{
#if 0
FT_Pos delta1;
#endif
FT_Pos delta2;
/* use discrete values for blue zone widths */
#if 0
/* generic, original code */
delta1 = blue->shoot.org - blue->ref.org;
delta2 = delta1;
if ( delta1 < 0 )
delta2 = -delta2;
delta2 = FT_MulFix( delta2, scale );
if ( delta2 < 32 )
delta2 = 0;
else if ( delta2 < 64 )
delta2 = 32 + ( ( ( delta2 - 32 ) + 16 ) & ~31 );
else
delta2 = FT_PIX_ROUND( delta2 );
if ( delta1 < 0 )
delta2 = -delta2;
blue->ref.fit = FT_PIX_ROUND( blue->ref.cur );
blue->shoot.fit = blue->ref.fit + delta2;
#else
/* simplified version due to abs(dist) <= 48 */
delta2 = dist;
if ( dist < 0 )
delta2 = -delta2;
if ( delta2 < 32 )
delta2 = 0;
else if ( delta2 < 48 )
delta2 = 32;
else
delta2 = 64;
if ( dist < 0 )
delta2 = -delta2;
blue->ref.fit = FT_PIX_ROUND( blue->ref.cur );
blue->shoot.fit = blue->ref.fit - delta2;
#endif
blue->flags |= AF_LATIN_BLUE_ACTIVE;
FT_TRACE5(( " reference %d: %d scaled to %.2f%s\n"
" overshoot %d: %d scaled to %.2f%s\n",
nn,
blue->ref.org,
blue->ref.fit / 64.0,
blue->flags & AF_LATIN_BLUE_ACTIVE ? ""
: " (inactive)",
nn,
blue->shoot.org,
blue->shoot.fit / 64.0,
blue->flags & AF_LATIN_BLUE_ACTIVE ? ""
: " (inactive)" ));
}
}
}
}
/* Scale global values in both directions. */
FT_LOCAL_DEF( void )
af_latin_metrics_scale( AF_LatinMetrics metrics,
AF_Scaler scaler )
{
metrics->root.scaler.render_mode = scaler->render_mode;
metrics->root.scaler.face = scaler->face;
metrics->root.scaler.flags = scaler->flags;
af_latin_metrics_scale_dim( metrics, scaler, AF_DIMENSION_HORZ );
af_latin_metrics_scale_dim( metrics, scaler, AF_DIMENSION_VERT );
}
/*************************************************************************/
/*************************************************************************/
/***** *****/
/***** L A T I N G L Y P H A N A L Y S I S *****/
/***** *****/
/*************************************************************************/
/*************************************************************************/
/* Walk over all contours and compute its segments. */
FT_LOCAL_DEF( FT_Error )
af_latin_hints_compute_segments( AF_GlyphHints hints,
AF_Dimension dim )
{
AF_AxisHints axis = &hints->axis[dim];
FT_Memory memory = hints->memory;
FT_Error error = FT_Err_Ok;
AF_Segment segment = NULL;
AF_SegmentRec seg0;
AF_Point* contour = hints->contours;
AF_Point* contour_limit = contour + hints->num_contours;
AF_Direction major_dir, segment_dir;
FT_ZERO( &seg0 );
seg0.score = 32000;
seg0.flags = AF_EDGE_NORMAL;
major_dir = (AF_Direction)FT_ABS( axis->major_dir );
segment_dir = major_dir;
axis->num_segments = 0;
/* set up (u,v) in each point */
if ( dim == AF_DIMENSION_HORZ )
{
AF_Point point = hints->points;
AF_Point limit = point + hints->num_points;
for ( ; point < limit; point++ )
{
point->u = point->fx;
point->v = point->fy;
}
}
else
{
AF_Point point = hints->points;
AF_Point limit = point + hints->num_points;
for ( ; point < limit; point++ )
{
point->u = point->fy;
point->v = point->fx;
}
}
/* do each contour separately */
for ( ; contour < contour_limit; contour++ )
{
AF_Point point = contour[0];
AF_Point last = point->prev;
int on_edge = 0;
FT_Pos min_pos = 32000; /* minimum segment pos != min_coord */
FT_Pos max_pos = -32000; /* maximum segment pos != max_coord */
FT_Bool passed;
if ( point == last ) /* skip singletons -- just in case */
continue;
if ( FT_ABS( last->out_dir ) == major_dir &&
FT_ABS( point->out_dir ) == major_dir )
{
/* we are already on an edge, try to locate its start */
last = point;
for (;;)
{
point = point->prev;
if ( FT_ABS( point->out_dir ) != major_dir )
{
point = point->next;
break;
}
if ( point == last )
break;
}
}
last = point;
passed = 0;
for (;;)
{
FT_Pos u, v;
if ( on_edge )
{
u = point->u;
if ( u < min_pos )
min_pos = u;
if ( u > max_pos )
max_pos = u;
if ( point->out_dir != segment_dir || point == last )
{
/* we are just leaving an edge; record a new segment! */
segment->last = point;
segment->pos = (FT_Short)( ( min_pos + max_pos ) >> 1 );
/* a segment is round if either its first or last point */
/* is a control point */
if ( ( segment->first->flags | point->flags ) &
AF_FLAG_CONTROL )
segment->flags |= AF_EDGE_ROUND;
/* compute segment size */
min_pos = max_pos = point->v;
v = segment->first->v;
if ( v < min_pos )
min_pos = v;
if ( v > max_pos )
max_pos = v;
segment->min_coord = (FT_Short)min_pos;
segment->max_coord = (FT_Short)max_pos;
segment->height = (FT_Short)( segment->max_coord -
segment->min_coord );
on_edge = 0;
segment = NULL;
/* fall through */
}
}
/* now exit if we are at the start/end point */
if ( point == last )
{
if ( passed )
break;
passed = 1;
}
if ( !on_edge && FT_ABS( point->out_dir ) == major_dir )
{
/* this is the start of a new segment! */
segment_dir = (AF_Direction)point->out_dir;
/* clear all segment fields */
error = af_axis_hints_new_segment( axis, memory, &segment );
if ( error )
goto Exit;
segment[0] = seg0;
segment->dir = (FT_Char)segment_dir;
min_pos = max_pos = point->u;
segment->first = point;
segment->last = point;
on_edge = 1;
}
point = point->next;
}
} /* contours */
/* now slightly increase the height of segments if this makes */
/* sense -- this is used to better detect and ignore serifs */
{
AF_Segment segments = axis->segments;
AF_Segment segments_end = segments + axis->num_segments;
for ( segment = segments; segment < segments_end; segment++ )
{
AF_Point first = segment->first;
AF_Point last = segment->last;
FT_Pos first_v = first->v;
FT_Pos last_v = last->v;
if ( first == last )
continue;
if ( first_v < last_v )
{
AF_Point p;
p = first->prev;
if ( p->v < first_v )
segment->height = (FT_Short)( segment->height +
( ( first_v - p->v ) >> 1 ) );
p = last->next;
if ( p->v > last_v )
segment->height = (FT_Short)( segment->height +
( ( p->v - last_v ) >> 1 ) );
}
else
{
AF_Point p;
p = first->prev;
if ( p->v > first_v )
segment->height = (FT_Short)( segment->height +
( ( p->v - first_v ) >> 1 ) );
p = last->next;
if ( p->v < last_v )
segment->height = (FT_Short)( segment->height +
( ( last_v - p->v ) >> 1 ) );
}
}
}
Exit:
return error;
}
/* Link segments to form stems and serifs. */
FT_LOCAL_DEF( void )
af_latin_hints_link_segments( AF_GlyphHints hints,
AF_Dimension dim )
{
AF_AxisHints axis = &hints->axis[dim];
AF_Segment segments = axis->segments;
AF_Segment segment_limit = segments + axis->num_segments;
FT_Pos len_threshold, len_score;
AF_Segment seg1, seg2;
len_threshold = AF_LATIN_CONSTANT( hints->metrics, 8 );
if ( len_threshold == 0 )
len_threshold = 1;
len_score = AF_LATIN_CONSTANT( hints->metrics, 6000 );
/* now compare each segment to the others */
for ( seg1 = segments; seg1 < segment_limit; seg1++ )
{
/* the fake segments are introduced to hint the metrics -- */
/* we must never link them to anything */
if ( seg1->dir != axis->major_dir || seg1->first == seg1->last )
continue;
/* search for stems having opposite directions, */
/* with seg1 to the `left' of seg2 */
for ( seg2 = segments; seg2 < segment_limit; seg2++ )
{
FT_Pos pos1 = seg1->pos;
FT_Pos pos2 = seg2->pos;
if ( seg1->dir + seg2->dir == 0 && pos2 > pos1 )
{
/* compute distance between the two segments */
FT_Pos dist = pos2 - pos1;
FT_Pos min = seg1->min_coord;
FT_Pos max = seg1->max_coord;
FT_Pos len, score;
if ( min < seg2->min_coord )
min = seg2->min_coord;
if ( max > seg2->max_coord )
max = seg2->max_coord;
/* compute maximum coordinate difference of the two segments */
len = max - min;
if ( len >= len_threshold )
{
/* small coordinate differences cause a higher score, and */
/* segments with a greater distance cause a higher score also */
score = dist + len_score / len;
/* and we search for the smallest score */
/* of the sum of the two values */
if ( score < seg1->score )
{
seg1->score = score;
seg1->link = seg2;
}
if ( score < seg2->score )
{
seg2->score = score;
seg2->link = seg1;
}
}
}
}
}
/* now compute the `serif' segments, cf. explanations in `afhints.h' */
for ( seg1 = segments; seg1 < segment_limit; seg1++ )
{
seg2 = seg1->link;
if ( seg2 )
{
if ( seg2->link != seg1 )
{
seg1->link = 0;
seg1->serif = seg2->link;
}
}
}
}
/* Link segments to edges, using feature analysis for selection. */
FT_LOCAL_DEF( FT_Error )
af_latin_hints_compute_edges( AF_GlyphHints hints,
AF_Dimension dim )
{
AF_AxisHints axis = &hints->axis[dim];
FT_Error error = FT_Err_Ok;
FT_Memory memory = hints->memory;
AF_LatinAxis laxis = &((AF_LatinMetrics)hints->metrics)->axis[dim];
AF_Segment segments = axis->segments;
AF_Segment segment_limit = segments + axis->num_segments;
AF_Segment seg;
#if 0
AF_Direction up_dir;
#endif
FT_Fixed scale;
FT_Pos edge_distance_threshold;
FT_Pos segment_length_threshold;
axis->num_edges = 0;
scale = ( dim == AF_DIMENSION_HORZ ) ? hints->x_scale
: hints->y_scale;
#if 0
up_dir = ( dim == AF_DIMENSION_HORZ ) ? AF_DIR_UP
: AF_DIR_RIGHT;
#endif
/*
* We ignore all segments that are less than 1 pixel in length
* to avoid many problems with serif fonts. We compute the
* corresponding threshold in font units.
*/
if ( dim == AF_DIMENSION_HORZ )
segment_length_threshold = FT_DivFix( 64, hints->y_scale );
else
segment_length_threshold = 0;
/*********************************************************************/
/* */
/* We begin by generating a sorted table of edges for the current */
/* direction. To do so, we simply scan each segment and try to find */
/* an edge in our table that corresponds to its position. */
/* */
/* If no edge is found, we create and insert a new edge in the */
/* sorted table. Otherwise, we simply add the segment to the edge's */
/* list which gets processed in the second step to compute the */
/* edge's properties. */
/* */
/* Note that the table of edges is sorted along the segment/edge */
/* position. */
/* */
/*********************************************************************/
/* assure that edge distance threshold is at most 0.25px */
edge_distance_threshold = FT_MulFix( laxis->edge_distance_threshold,
scale );
if ( edge_distance_threshold > 64 / 4 )
edge_distance_threshold = 64 / 4;
edge_distance_threshold = FT_DivFix( edge_distance_threshold,
scale );
for ( seg = segments; seg < segment_limit; seg++ )
{
AF_Edge found = NULL;
FT_Int ee;
if ( seg->height < segment_length_threshold )
continue;
/* A special case for serif edges: If they are smaller than */
/* 1.5 pixels we ignore them. */
if ( seg->serif &&
2 * seg->height < 3 * segment_length_threshold )
continue;
/* look for an edge corresponding to the segment */
for ( ee = 0; ee < axis->num_edges; ee++ )
{
AF_Edge edge = axis->edges + ee;
FT_Pos dist;
dist = seg->pos - edge->fpos;
if ( dist < 0 )
dist = -dist;
if ( dist < edge_distance_threshold && edge->dir == seg->dir )
{
found = edge;
break;
}
}
if ( !found )
{
AF_Edge edge;
/* insert a new edge in the list and */
/* sort according to the position */
error = af_axis_hints_new_edge( axis, seg->pos,
(AF_Direction)seg->dir,
memory, &edge );
if ( error )
goto Exit;
/* add the segment to the new edge's list */
FT_ZERO( edge );
edge->first = seg;
edge->last = seg;
edge->dir = seg->dir;
edge->fpos = seg->pos;
edge->opos = FT_MulFix( seg->pos, scale );
edge->pos = edge->opos;
seg->edge_next = seg;
}
else
{
/* if an edge was found, simply add the segment to the edge's */
/* list */
seg->edge_next = found->first;
found->last->edge_next = seg;
found->last = seg;
}
}
/******************************************************************/
/* */
/* Good, we now compute each edge's properties according to the */
/* segments found on its position. Basically, these are */
/* */
/* - the edge's main direction */
/* - stem edge, serif edge or both (which defaults to stem then) */
/* - rounded edge, straight or both (which defaults to straight) */
/* - link for edge */
/* */
/******************************************************************/
/* first of all, set the `edge' field in each segment -- this is */
/* required in order to compute edge links */
/*
* Note that removing this loop and setting the `edge' field of each
* segment directly in the code above slows down execution speed for
* some reasons on platforms like the Sun.
*/
{
AF_Edge edges = axis->edges;
AF_Edge edge_limit = edges + axis->num_edges;
AF_Edge edge;
for ( edge = edges; edge < edge_limit; edge++ )
{
seg = edge->first;
if ( seg )
do
{
seg->edge = edge;
seg = seg->edge_next;
} while ( seg != edge->first );
}
/* now compute each edge properties */
for ( edge = edges; edge < edge_limit; edge++ )
{
FT_Int is_round = 0; /* does it contain round segments? */
FT_Int is_straight = 0; /* does it contain straight segments? */
#if 0
FT_Pos ups = 0; /* number of upwards segments */
FT_Pos downs = 0; /* number of downwards segments */
#endif
seg = edge->first;
do
{
FT_Bool is_serif;
/* check for roundness of segment */
if ( seg->flags & AF_EDGE_ROUND )
is_round++;
else
is_straight++;
#if 0
/* check for segment direction */
if ( seg->dir == up_dir )
ups += seg->max_coord - seg->min_coord;
else
downs += seg->max_coord - seg->min_coord;
#endif
/* check for links -- if seg->serif is set, then seg->link must */
/* be ignored */
is_serif = (FT_Bool)( seg->serif &&
seg->serif->edge &&
seg->serif->edge != edge );
if ( ( seg->link && seg->link->edge != NULL ) || is_serif )
{
AF_Edge edge2;
AF_Segment seg2;
edge2 = edge->link;
seg2 = seg->link;
if ( is_serif )
{
seg2 = seg->serif;
edge2 = edge->serif;
}
if ( edge2 )
{
FT_Pos edge_delta;
FT_Pos seg_delta;
edge_delta = edge->fpos - edge2->fpos;
if ( edge_delta < 0 )
edge_delta = -edge_delta;
seg_delta = seg->pos - seg2->pos;
if ( seg_delta < 0 )
seg_delta = -seg_delta;
if ( seg_delta < edge_delta )
edge2 = seg2->edge;
}
else
edge2 = seg2->edge;
if ( is_serif )
{
edge->serif = edge2;
edge2->flags |= AF_EDGE_SERIF;
}
else
edge->link = edge2;
}
seg = seg->edge_next;
} while ( seg != edge->first );
/* set the round/straight flags */
edge->flags = AF_EDGE_NORMAL;
if ( is_round > 0 && is_round >= is_straight )
edge->flags |= AF_EDGE_ROUND;
#if 0
/* set the edge's main direction */
edge->dir = AF_DIR_NONE;
if ( ups > downs )
edge->dir = (FT_Char)up_dir;
else if ( ups < downs )
edge->dir = (FT_Char)-up_dir;
else if ( ups == downs )
edge->dir = 0; /* both up and down! */
#endif
/* get rid of serifs if link is set */
/* XXX: This gets rid of many unpleasant artefacts! */
/* Example: the `c' in cour.pfa at size 13 */
if ( edge->serif && edge->link )
edge->serif = 0;
}
}
Exit:
return error;
}
/* Detect segments and edges for given dimension. */
FT_LOCAL_DEF( FT_Error )
af_latin_hints_detect_features( AF_GlyphHints hints,
AF_Dimension dim )
{
FT_Error error;
error = af_latin_hints_compute_segments( hints, dim );
if ( !error )
{
af_latin_hints_link_segments( hints, dim );
error = af_latin_hints_compute_edges( hints, dim );
}
return error;
}
/* Compute all edges which lie within blue zones. */
FT_LOCAL_DEF( void )
af_latin_hints_compute_blue_edges( AF_GlyphHints hints,
AF_LatinMetrics metrics )
{
AF_AxisHints axis = &hints->axis[AF_DIMENSION_VERT];
AF_Edge edge = axis->edges;
AF_Edge edge_limit = edge + axis->num_edges;
AF_LatinAxis latin = &metrics->axis[AF_DIMENSION_VERT];
FT_Fixed scale = latin->scale;
/* compute which blue zones are active, i.e. have their scaled */
/* size < 3/4 pixels */
/* for each horizontal edge search the blue zone which is closest */
for ( ; edge < edge_limit; edge++ )
{
FT_UInt bb;
AF_Width best_blue = NULL;
FT_Pos best_dist; /* initial threshold */
/* compute the initial threshold as a fraction of the EM size */
/* (the value 40 is heuristic) */
best_dist = FT_MulFix( metrics->units_per_em / 40, scale );
/* assure a minimum distance of 0.5px */
if ( best_dist > 64 / 2 )
best_dist = 64 / 2;
for ( bb = 0; bb < latin->blue_count; bb++ )
{
AF_LatinBlue blue = latin->blues + bb;
FT_Bool is_top_blue, is_major_dir;
/* skip inactive blue zones (i.e., those that are too large) */
if ( !( blue->flags & AF_LATIN_BLUE_ACTIVE ) )
continue;
/* if it is a top zone, check for right edges -- if it is a bottom */
/* zone, check for left edges */
/* */
/* of course, that's for TrueType */
is_top_blue = (FT_Byte)( ( blue->flags & AF_LATIN_BLUE_TOP ) != 0 );
is_major_dir = FT_BOOL( edge->dir == axis->major_dir );
/* if it is a top zone, the edge must be against the major */
/* direction; if it is a bottom zone, it must be in the major */
/* direction */
if ( is_top_blue ^ is_major_dir )
{
FT_Pos dist;
/* first of all, compare it to the reference position */
dist = edge->fpos - blue->ref.org;
if ( dist < 0 )
dist = -dist;
dist = FT_MulFix( dist, scale );
if ( dist < best_dist )
{
best_dist = dist;
best_blue = &blue->ref;
}
/* now compare it to the overshoot position and check whether */
/* the edge is rounded, and whether the edge is over the */
/* reference position of a top zone, or under the reference */
/* position of a bottom zone */
if ( edge->flags & AF_EDGE_ROUND && dist != 0 )
{
FT_Bool is_under_ref = FT_BOOL( edge->fpos < blue->ref.org );
if ( is_top_blue ^ is_under_ref )
{
dist = edge->fpos - blue->shoot.org;
if ( dist < 0 )
dist = -dist;
dist = FT_MulFix( dist, scale );
if ( dist < best_dist )
{
best_dist = dist;
best_blue = &blue->shoot;
}
}
}
}
}
if ( best_blue )
edge->blue_edge = best_blue;
}
}
/* Initalize hinting engine. */
static FT_Error
af_latin_hints_init( AF_GlyphHints hints,
AF_LatinMetrics metrics )
{
FT_Render_Mode mode;
FT_UInt32 scaler_flags, other_flags;
FT_Face face = metrics->root.scaler.face;
af_glyph_hints_rescale( hints, (AF_StyleMetrics)metrics );
/*
* correct x_scale and y_scale if needed, since they may have
* been modified by `af_latin_metrics_scale_dim' above
*/
hints->x_scale = metrics->axis[AF_DIMENSION_HORZ].scale;
hints->x_delta = metrics->axis[AF_DIMENSION_HORZ].delta;
hints->y_scale = metrics->axis[AF_DIMENSION_VERT].scale;
hints->y_delta = metrics->axis[AF_DIMENSION_VERT].delta;
/* compute flags depending on render mode, etc. */
mode = metrics->root.scaler.render_mode;
#if 0 /* #ifdef AF_CONFIG_OPTION_USE_WARPER */
if ( mode == FT_RENDER_MODE_LCD || mode == FT_RENDER_MODE_LCD_V )
metrics->root.scaler.render_mode = mode = FT_RENDER_MODE_NORMAL;
#endif
scaler_flags = hints->scaler_flags;
other_flags = 0;
/*
* We snap the width of vertical stems for the monochrome and
* horizontal LCD rendering targets only.
*/
if ( mode == FT_RENDER_MODE_MONO || mode == FT_RENDER_MODE_LCD )
other_flags |= AF_LATIN_HINTS_HORZ_SNAP;
/*
* We snap the width of horizontal stems for the monochrome and
* vertical LCD rendering targets only.
*/
if ( mode == FT_RENDER_MODE_MONO || mode == FT_RENDER_MODE_LCD_V )
other_flags |= AF_LATIN_HINTS_VERT_SNAP;
/*
* We adjust stems to full pixels only if we don't use the `light' mode.
*/
if ( mode != FT_RENDER_MODE_LIGHT )
other_flags |= AF_LATIN_HINTS_STEM_ADJUST;
if ( mode == FT_RENDER_MODE_MONO )
other_flags |= AF_LATIN_HINTS_MONO;
/*
* In `light' hinting mode we disable horizontal hinting completely.
* We also do it if the face is italic.
*/
if ( mode == FT_RENDER_MODE_LIGHT ||
( face->style_flags & FT_STYLE_FLAG_ITALIC ) != 0 )
scaler_flags |= AF_SCALER_FLAG_NO_HORIZONTAL;
hints->scaler_flags = scaler_flags;
hints->other_flags = other_flags;
return FT_Err_Ok;
}
/*************************************************************************/
/*************************************************************************/
/***** *****/
/***** L A T I N G L Y P H G R I D - F I T T I N G *****/
/***** *****/
/*************************************************************************/
/*************************************************************************/
/* Snap a given width in scaled coordinates to one of the */
/* current standard widths. */
static FT_Pos
af_latin_snap_width( AF_Width widths,
FT_Int count,
FT_Pos width )
{
int n;
FT_Pos best = 64 + 32 + 2;
FT_Pos reference = width;
FT_Pos scaled;
for ( n = 0; n < count; n++ )
{
FT_Pos w;
FT_Pos dist;
w = widths[n].cur;
dist = width - w;
if ( dist < 0 )
dist = -dist;
if ( dist < best )
{
best = dist;
reference = w;
}
}
scaled = FT_PIX_ROUND( reference );
if ( width >= reference )
{
if ( width < scaled + 48 )
width = reference;
}
else
{
if ( width > scaled - 48 )
width = reference;
}
return width;
}
/* Compute the snapped width of a given stem, ignoring very thin ones. */
/* There is a lot of voodoo in this function; changing the hard-coded */
/* parameters influence the whole hinting process. */
static FT_Pos
af_latin_compute_stem_width( AF_GlyphHints hints,
AF_Dimension dim,
FT_Pos width,
AF_Edge_Flags base_flags,
AF_Edge_Flags stem_flags )
{
AF_LatinMetrics metrics = (AF_LatinMetrics)hints->metrics;
AF_LatinAxis axis = &metrics->axis[dim];
FT_Pos dist = width;
FT_Int sign = 0;
FT_Int vertical = ( dim == AF_DIMENSION_VERT );
if ( !AF_LATIN_HINTS_DO_STEM_ADJUST( hints ) ||
axis->extra_light )
return width;
if ( dist < 0 )
{
dist = -width;
sign = 1;
}
if ( ( vertical && !AF_LATIN_HINTS_DO_VERT_SNAP( hints ) ) ||
( !vertical && !AF_LATIN_HINTS_DO_HORZ_SNAP( hints ) ) )
{
/* smooth hinting process: very lightly quantize the stem width */
/* leave the widths of serifs alone */
if ( ( stem_flags & AF_EDGE_SERIF ) &&
vertical &&
( dist < 3 * 64 ) )
goto Done_Width;
else if ( base_flags & AF_EDGE_ROUND )
{
if ( dist < 80 )
dist = 64;
}
else if ( dist < 56 )
dist = 56;
if ( axis->width_count > 0 )
{
FT_Pos delta;
/* compare to standard width */
delta = dist - axis->widths[0].cur;
if ( delta < 0 )
delta = -delta;
if ( delta < 40 )
{
dist = axis->widths[0].cur;
if ( dist < 48 )
dist = 48;
goto Done_Width;
}
if ( dist < 3 * 64 )
{
delta = dist & 63;
dist &= -64;
if ( delta < 10 )
dist += delta;
else if ( delta < 32 )
dist += 10;
else if ( delta < 54 )
dist += 54;
else
dist += delta;
}
else
dist = ( dist + 32 ) & ~63;
}
}
else
{
/* strong hinting process: snap the stem width to integer pixels */
FT_Pos org_dist = dist;
dist = af_latin_snap_width( axis->widths, axis->width_count, dist );
if ( vertical )
{
/* in the case of vertical hinting, always round */
/* the stem heights to integer pixels */
if ( dist >= 64 )
dist = ( dist + 16 ) & ~63;
else
dist = 64;
}
else
{
if ( AF_LATIN_HINTS_DO_MONO( hints ) )
{
/* monochrome horizontal hinting: snap widths to integer pixels */
/* with a different threshold */
if ( dist < 64 )
dist = 64;
else
dist = ( dist + 32 ) & ~63;
}
else
{
/* for horizontal anti-aliased hinting, we adopt a more subtle */
/* approach: we strengthen small stems, round stems whose size */
/* is between 1 and 2 pixels to an integer, otherwise nothing */
if ( dist < 48 )
dist = ( dist + 64 ) >> 1;
else if ( dist < 128 )
{
/* We only round to an integer width if the corresponding */
/* distortion is less than 1/4 pixel. Otherwise this */
/* makes everything worse since the diagonals, which are */
/* not hinted, appear a lot bolder or thinner than the */
/* vertical stems. */
FT_Pos delta;
dist = ( dist + 22 ) & ~63;
delta = dist - org_dist;
if ( delta < 0 )
delta = -delta;
if ( delta >= 16 )
{
dist = org_dist;
if ( dist < 48 )
dist = ( dist + 64 ) >> 1;
}
}
else
/* round otherwise to prevent color fringes in LCD mode */
dist = ( dist + 32 ) & ~63;
}
}
}
Done_Width:
if ( sign )
dist = -dist;
return dist;
}
/* Align one stem edge relative to the previous stem edge. */
static void
af_latin_align_linked_edge( AF_GlyphHints hints,
AF_Dimension dim,
AF_Edge base_edge,
AF_Edge stem_edge )
{
FT_Pos dist = stem_edge->opos - base_edge->opos;
FT_Pos fitted_width = af_latin_compute_stem_width(
hints, dim, dist,
(AF_Edge_Flags)base_edge->flags,
(AF_Edge_Flags)stem_edge->flags );
stem_edge->pos = base_edge->pos + fitted_width;
FT_TRACE5(( " LINK: edge %d (opos=%.2f) linked to %.2f,"
" dist was %.2f, now %.2f\n",
stem_edge-hints->axis[dim].edges, stem_edge->opos / 64.0,
stem_edge->pos / 64.0, dist / 64.0, fitted_width / 64.0 ));
}
/* Shift the coordinates of the `serif' edge by the same amount */
/* as the corresponding `base' edge has been moved already. */
static void
af_latin_align_serif_edge( AF_GlyphHints hints,
AF_Edge base,
AF_Edge serif )
{
FT_UNUSED( hints );
serif->pos = base->pos + ( serif->opos - base->opos );
}
/*************************************************************************/
/*************************************************************************/
/*************************************************************************/
/**** ****/
/**** E D G E H I N T I N G ****/
/**** ****/
/*************************************************************************/
/*************************************************************************/
/*************************************************************************/
/* The main grid-fitting routine. */
FT_LOCAL_DEF( void )
af_latin_hint_edges( AF_GlyphHints hints,
AF_Dimension dim )
{
AF_AxisHints axis = &hints->axis[dim];
AF_Edge edges = axis->edges;
AF_Edge edge_limit = edges + axis->num_edges;
FT_PtrDist n_edges;
AF_Edge edge;
AF_Edge anchor = NULL;
FT_Int has_serifs = 0;
#ifdef FT_DEBUG_LEVEL_TRACE
FT_UInt num_actions = 0;
#endif
FT_TRACE5(( "latin %s edge hinting (style `%s')\n",
dim == AF_DIMENSION_VERT ? "horizontal" : "vertical",
af_style_names[hints->metrics->style_class->style] ));
/* we begin by aligning all stems relative to the blue zone */
/* if needed -- that's only for horizontal edges */
if ( dim == AF_DIMENSION_VERT && AF_HINTS_DO_BLUES( hints ) )
{
for ( edge = edges; edge < edge_limit; edge++ )
{
AF_Width blue;
AF_Edge edge1, edge2; /* these edges form the stem to check */
if ( edge->flags & AF_EDGE_DONE )
continue;
blue = edge->blue_edge;
edge1 = NULL;
edge2 = edge->link;
if ( blue )
edge1 = edge;
/* flip edges if the other stem is aligned to a blue zone */
else if ( edge2 && edge2->blue_edge )
{
blue = edge2->blue_edge;
edge1 = edge2;
edge2 = edge;
}
if ( !edge1 )
continue;
#ifdef FT_DEBUG_LEVEL_TRACE
if ( !anchor )
FT_TRACE5(( " BLUE_ANCHOR: edge %d (opos=%.2f) snapped to %.2f,"
" was %.2f (anchor=edge %d)\n",
edge1 - edges, edge1->opos / 64.0, blue->fit / 64.0,
edge1->pos / 64.0, edge - edges ));
else
FT_TRACE5(( " BLUE: edge %d (opos=%.2f) snapped to %.2f,"
" was %.2f\n",
edge1 - edges, edge1->opos / 64.0, blue->fit / 64.0,
edge1->pos / 64.0 ));
num_actions++;
#endif
edge1->pos = blue->fit;
edge1->flags |= AF_EDGE_DONE;
if ( edge2 && !edge2->blue_edge )
{
af_latin_align_linked_edge( hints, dim, edge1, edge2 );
edge2->flags |= AF_EDGE_DONE;
#ifdef FT_DEBUG_LEVEL_TRACE
num_actions++;
#endif
}
if ( !anchor )
anchor = edge;
}
}
/* now we align all other stem edges, trying to maintain the */
/* relative order of stems in the glyph */
for ( edge = edges; edge < edge_limit; edge++ )
{
AF_Edge edge2;
if ( edge->flags & AF_EDGE_DONE )
continue;
/* skip all non-stem edges */
edge2 = edge->link;
if ( !edge2 )
{
has_serifs++;
continue;
}
/* now align the stem */
/* this should not happen, but it's better to be safe */
if ( edge2->blue_edge )
{
FT_TRACE5(( " ASSERTION FAILED for edge %d\n", edge2-edges ));
af_latin_align_linked_edge( hints, dim, edge2, edge );
edge->flags |= AF_EDGE_DONE;
#ifdef FT_DEBUG_LEVEL_TRACE
num_actions++;
#endif
continue;
}
if ( !anchor )
{
/* if we reach this if clause, no stem has been aligned yet */
FT_Pos org_len, org_center, cur_len;
FT_Pos cur_pos1, error1, error2, u_off, d_off;
org_len = edge2->opos - edge->opos;
cur_len = af_latin_compute_stem_width(
hints, dim, org_len,
(AF_Edge_Flags)edge->flags,
(AF_Edge_Flags)edge2->flags );
/* some voodoo to specially round edges for small stem widths; */
/* the idea is to align the center of a stem, then shifting */
/* the stem edges to suitable positions */
if ( cur_len <= 64 )
{
/* width <= 1px */
u_off = 32;
d_off = 32;
}
else
{
/* 1px < width < 1.5px */
u_off = 38;
d_off = 26;
}
if ( cur_len < 96 )
{
org_center = edge->opos + ( org_len >> 1 );
cur_pos1 = FT_PIX_ROUND( org_center );
error1 = org_center - ( cur_pos1 - u_off );
if ( error1 < 0 )
error1 = -error1;
error2 = org_center - ( cur_pos1 + d_off );
if ( error2 < 0 )
error2 = -error2;
if ( error1 < error2 )
cur_pos1 -= u_off;
else
cur_pos1 += d_off;
edge->pos = cur_pos1 - cur_len / 2;
edge2->pos = edge->pos + cur_len;
}
else
edge->pos = FT_PIX_ROUND( edge->opos );
anchor = edge;
edge->flags |= AF_EDGE_DONE;
FT_TRACE5(( " ANCHOR: edge %d (opos=%.2f) and %d (opos=%.2f)"
" snapped to %.2f and %.2f\n",
edge - edges, edge->opos / 64.0,
edge2 - edges, edge2->opos / 64.0,
edge->pos / 64.0, edge2->pos / 64.0 ));
af_latin_align_linked_edge( hints, dim, edge, edge2 );
#ifdef FT_DEBUG_LEVEL_TRACE
num_actions += 2;
#endif
}
else
{
FT_Pos org_pos, org_len, org_center, cur_len;
FT_Pos cur_pos1, cur_pos2, delta1, delta2;
org_pos = anchor->pos + ( edge->opos - anchor->opos );
org_len = edge2->opos - edge->opos;
org_center = org_pos + ( org_len >> 1 );
cur_len = af_latin_compute_stem_width(
hints, dim, org_len,
(AF_Edge_Flags)edge->flags,
(AF_Edge_Flags)edge2->flags );
if ( edge2->flags & AF_EDGE_DONE )
{
FT_TRACE5(( " ADJUST: edge %d (pos=%.2f) moved to %.2f\n",
edge - edges, edge->pos / 64.0,
( edge2->pos - cur_len ) / 64.0 ));
edge->pos = edge2->pos - cur_len;
}
else if ( cur_len < 96 )
{
FT_Pos u_off, d_off;
cur_pos1 = FT_PIX_ROUND( org_center );
if ( cur_len <= 64 )
{
u_off = 32;
d_off = 32;
}
else
{
u_off = 38;
d_off = 26;
}
delta1 = org_center - ( cur_pos1 - u_off );
if ( delta1 < 0 )
delta1 = -delta1;
delta2 = org_center - ( cur_pos1 + d_off );
if ( delta2 < 0 )
delta2 = -delta2;
if ( delta1 < delta2 )
cur_pos1 -= u_off;
else
cur_pos1 += d_off;
edge->pos = cur_pos1 - cur_len / 2;
edge2->pos = cur_pos1 + cur_len / 2;
FT_TRACE5(( " STEM: edge %d (opos=%.2f) linked to %d (opos=%.2f)"
" snapped to %.2f and %.2f\n",
edge - edges, edge->opos / 64.0,
edge2 - edges, edge2->opos / 64.0,
edge->pos / 64.0, edge2->pos / 64.0 ));
}
else
{
org_pos = anchor->pos + ( edge->opos - anchor->opos );
org_len = edge2->opos - edge->opos;
org_center = org_pos + ( org_len >> 1 );
cur_len = af_latin_compute_stem_width(
hints, dim, org_len,
(AF_Edge_Flags)edge->flags,
(AF_Edge_Flags)edge2->flags );
cur_pos1 = FT_PIX_ROUND( org_pos );
delta1 = cur_pos1 + ( cur_len >> 1 ) - org_center;
if ( delta1 < 0 )
delta1 = -delta1;
cur_pos2 = FT_PIX_ROUND( org_pos + org_len ) - cur_len;
delta2 = cur_pos2 + ( cur_len >> 1 ) - org_center;
if ( delta2 < 0 )
delta2 = -delta2;
edge->pos = ( delta1 < delta2 ) ? cur_pos1 : cur_pos2;
edge2->pos = edge->pos + cur_len;
FT_TRACE5(( " STEM: edge %d (opos=%.2f) linked to %d (opos=%.2f)"
" snapped to %.2f and %.2f\n",
edge - edges, edge->opos / 64.0,
edge2 - edges, edge2->opos / 64.0,
edge->pos / 64.0, edge2->pos / 64.0 ));
}
#ifdef FT_DEBUG_LEVEL_TRACE
num_actions++;
#endif
edge->flags |= AF_EDGE_DONE;
edge2->flags |= AF_EDGE_DONE;
if ( edge > edges && edge->pos < edge[-1].pos )
{
#ifdef FT_DEBUG_LEVEL_TRACE
FT_TRACE5(( " BOUND: edge %d (pos=%.2f) moved to %.2f\n",
edge - edges, edge->pos / 64.0, edge[-1].pos / 64.0 ));
num_actions++;
#endif
edge->pos = edge[-1].pos;
}
}
}
/* make sure that lowercase m's maintain their symmetry */
/* In general, lowercase m's have six vertical edges if they are sans */
/* serif, or twelve if they are with serifs. This implementation is */
/* based on that assumption, and seems to work very well with most */
/* faces. However, if for a certain face this assumption is not */
/* true, the m is just rendered like before. In addition, any stem */
/* correction will only be applied to symmetrical glyphs (even if the */
/* glyph is not an m), so the potential for unwanted distortion is */
/* relatively low. */
/* We don't handle horizontal edges since we can't easily assure that */
/* the third (lowest) stem aligns with the base line; it might end up */
/* one pixel higher or lower. */
n_edges = edge_limit - edges;
if ( dim == AF_DIMENSION_HORZ && ( n_edges == 6 || n_edges == 12 ) )
{
AF_Edge edge1, edge2, edge3;
FT_Pos dist1, dist2, span, delta;
if ( n_edges == 6 )
{
edge1 = edges;
edge2 = edges + 2;
edge3 = edges + 4;
}
else
{
edge1 = edges + 1;
edge2 = edges + 5;
edge3 = edges + 9;
}
dist1 = edge2->opos - edge1->opos;
dist2 = edge3->opos - edge2->opos;
span = dist1 - dist2;
if ( span < 0 )
span = -span;
if ( span < 8 )
{
delta = edge3->pos - ( 2 * edge2->pos - edge1->pos );
edge3->pos -= delta;
if ( edge3->link )
edge3->link->pos -= delta;
/* move the serifs along with the stem */
if ( n_edges == 12 )
{
( edges + 8 )->pos -= delta;
( edges + 11 )->pos -= delta;
}
edge3->flags |= AF_EDGE_DONE;
if ( edge3->link )
edge3->link->flags |= AF_EDGE_DONE;
}
}
if ( has_serifs || !anchor )
{
/*
* now hint the remaining edges (serifs and single) in order
* to complete our processing
*/
for ( edge = edges; edge < edge_limit; edge++ )
{
FT_Pos delta;
if ( edge->flags & AF_EDGE_DONE )
continue;
delta = 1000;
if ( edge->serif )
{
delta = edge->serif->opos - edge->opos;
if ( delta < 0 )
delta = -delta;
}
if ( delta < 64 + 16 )
{
af_latin_align_serif_edge( hints, edge->serif, edge );
FT_TRACE5(( " SERIF: edge %d (opos=%.2f) serif to %d (opos=%.2f)"
" aligned to %.2f\n",
edge - edges, edge->opos / 64.0,
edge->serif - edges, edge->serif->opos / 64.0,
edge->pos / 64.0 ));
}
else if ( !anchor )
{
edge->pos = FT_PIX_ROUND( edge->opos );
anchor = edge;
FT_TRACE5(( " SERIF_ANCHOR: edge %d (opos=%.2f)"
" snapped to %.2f\n",
edge-edges, edge->opos / 64.0, edge->pos / 64.0 ));
}
else
{
AF_Edge before, after;
for ( before = edge - 1; before >= edges; before-- )
if ( before->flags & AF_EDGE_DONE )
break;
for ( after = edge + 1; after < edge_limit; after++ )
if ( after->flags & AF_EDGE_DONE )
break;
if ( before >= edges && before < edge &&
after < edge_limit && after > edge )
{
if ( after->opos == before->opos )
edge->pos = before->pos;
else
edge->pos = before->pos +
FT_MulDiv( edge->opos - before->opos,
after->pos - before->pos,
after->opos - before->opos );
FT_TRACE5(( " SERIF_LINK1: edge %d (opos=%.2f) snapped to %.2f"
" from %d (opos=%.2f)\n",
edge - edges, edge->opos / 64.0,
edge->pos / 64.0,
before - edges, before->opos / 64.0 ));
}
else
{
edge->pos = anchor->pos +
( ( edge->opos - anchor->opos + 16 ) & ~31 );
FT_TRACE5(( " SERIF_LINK2: edge %d (opos=%.2f)"
" snapped to %.2f\n",
edge - edges, edge->opos / 64.0, edge->pos / 64.0 ));
}
}
#ifdef FT_DEBUG_LEVEL_TRACE
num_actions++;
#endif
edge->flags |= AF_EDGE_DONE;
if ( edge > edges && edge->pos < edge[-1].pos )
{
#ifdef FT_DEBUG_LEVEL_TRACE
FT_TRACE5(( " BOUND: edge %d (pos=%.2f) moved to %.2f\n",
edge - edges, edge->pos / 64.0, edge[-1].pos / 64.0 ));
num_actions++;
#endif
edge->pos = edge[-1].pos;
}
if ( edge + 1 < edge_limit &&
edge[1].flags & AF_EDGE_DONE &&
edge->pos > edge[1].pos )
{
#ifdef FT_DEBUG_LEVEL_TRACE
FT_TRACE5(( " BOUND: edge %d (pos=%.2f) moved to %.2f\n",
edge - edges, edge->pos / 64.0, edge[1].pos / 64.0 ));
num_actions++;
#endif
edge->pos = edge[1].pos;
}
}
}
#ifdef FT_DEBUG_LEVEL_TRACE
if ( !num_actions )
FT_TRACE5(( " (none)\n" ));
FT_TRACE5(( "\n" ));
#endif
}
/* Apply the complete hinting algorithm to a latin glyph. */
static FT_Error
af_latin_hints_apply( AF_GlyphHints hints,
FT_Outline* outline,
AF_LatinMetrics metrics )
{
FT_Error error;
int dim;
error = af_glyph_hints_reload( hints, outline );
if ( error )
goto Exit;
/* analyze glyph outline */
#ifdef AF_CONFIG_OPTION_USE_WARPER
if ( metrics->root.scaler.render_mode == FT_RENDER_MODE_LIGHT ||
AF_HINTS_DO_HORIZONTAL( hints ) )
#else
if ( AF_HINTS_DO_HORIZONTAL( hints ) )
#endif
{
error = af_latin_hints_detect_features( hints, AF_DIMENSION_HORZ );
if ( error )
goto Exit;
}
if ( AF_HINTS_DO_VERTICAL( hints ) )
{
error = af_latin_hints_detect_features( hints, AF_DIMENSION_VERT );
if ( error )
goto Exit;
af_latin_hints_compute_blue_edges( hints, metrics );
}
/* grid-fit the outline */
for ( dim = 0; dim < AF_DIMENSION_MAX; dim++ )
{
#ifdef AF_CONFIG_OPTION_USE_WARPER
if ( dim == AF_DIMENSION_HORZ &&
metrics->root.scaler.render_mode == FT_RENDER_MODE_LIGHT )
{
AF_WarperRec warper;
FT_Fixed scale;
FT_Pos delta;
af_warper_compute( &warper, hints, (AF_Dimension)dim,
&scale, &delta );
af_glyph_hints_scale_dim( hints, (AF_Dimension)dim,
scale, delta );
continue;
}
#endif
if ( ( dim == AF_DIMENSION_HORZ && AF_HINTS_DO_HORIZONTAL( hints ) ) ||
( dim == AF_DIMENSION_VERT && AF_HINTS_DO_VERTICAL( hints ) ) )
{
af_latin_hint_edges( hints, (AF_Dimension)dim );
af_glyph_hints_align_edge_points( hints, (AF_Dimension)dim );
af_glyph_hints_align_strong_points( hints, (AF_Dimension)dim );
af_glyph_hints_align_weak_points( hints, (AF_Dimension)dim );
}
}
af_glyph_hints_save( hints, outline );
Exit:
return error;
}
/*************************************************************************/
/*************************************************************************/
/***** *****/
/***** L A T I N S C R I P T C L A S S *****/
/***** *****/
/*************************************************************************/
/*************************************************************************/
AF_DEFINE_WRITING_SYSTEM_CLASS(
af_latin_writing_system_class,
AF_WRITING_SYSTEM_LATIN,
sizeof ( AF_LatinMetricsRec ),
(AF_WritingSystem_InitMetricsFunc) af_latin_metrics_init,
(AF_WritingSystem_ScaleMetricsFunc)af_latin_metrics_scale,
(AF_WritingSystem_DoneMetricsFunc) NULL,
(AF_WritingSystem_InitHintsFunc) af_latin_hints_init,
(AF_WritingSystem_ApplyHintsFunc) af_latin_hints_apply
)
/* END */
| YifuLiu/AliOS-Things | components/freetype/src/autofit/aflatin.c | C | apache-2.0 | 84,547 |
/***************************************************************************/
/* */
/* aflatin.h */
/* */
/* Auto-fitter hinting routines for latin writing system */
/* (specification). */
/* */
/* Copyright 2003-2007, 2009, 2011-2013 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. */
/* */
/***************************************************************************/
#ifndef __AFLATIN_H__
#define __AFLATIN_H__
#include "afhints.h"
FT_BEGIN_HEADER
/* the `latin' writing system */
AF_DECLARE_WRITING_SYSTEM_CLASS( af_latin_writing_system_class )
/* constants are given with units_per_em == 2048 in mind */
#define AF_LATIN_CONSTANT( metrics, c ) \
( ( (c) * (FT_Long)( (AF_LatinMetrics)(metrics) )->units_per_em ) / 2048 )
/*************************************************************************/
/*************************************************************************/
/***** *****/
/***** L A T I N G L O B A L M E T R I C S *****/
/***** *****/
/*************************************************************************/
/*************************************************************************/
/*
* The following declarations could be embedded in the file `aflatin.c';
* they have been made semi-public to allow alternate writing system
* hinters to re-use some of them.
*/
#define AF_LATIN_IS_TOP_BLUE( b ) \
( (b)->properties & AF_BLUE_PROPERTY_LATIN_TOP )
#define AF_LATIN_IS_X_HEIGHT_BLUE( b ) \
( (b)->properties & AF_BLUE_PROPERTY_LATIN_X_HEIGHT )
#define AF_LATIN_IS_LONG_BLUE( b ) \
( (b)->properties & AF_BLUE_PROPERTY_LATIN_LONG )
#define AF_LATIN_MAX_WIDTHS 16
enum
{
AF_LATIN_BLUE_ACTIVE = 1 << 0, /* set if zone height is <= 3/4px */
AF_LATIN_BLUE_TOP = 1 << 1, /* result of AF_LATIN_IS_TOP_BLUE */
AF_LATIN_BLUE_ADJUSTMENT = 1 << 2, /* used for scale adjustment */
/* optimization */
AF_LATIN_BLUE_FLAG_MAX
};
typedef struct AF_LatinBlueRec_
{
AF_WidthRec ref;
AF_WidthRec shoot;
FT_UInt flags;
} AF_LatinBlueRec, *AF_LatinBlue;
typedef struct AF_LatinAxisRec_
{
FT_Fixed scale;
FT_Pos delta;
FT_UInt width_count; /* number of used widths */
AF_WidthRec widths[AF_LATIN_MAX_WIDTHS]; /* widths array */
FT_Pos edge_distance_threshold; /* used for creating edges */
FT_Pos standard_width; /* the default stem thickness */
FT_Bool extra_light; /* is standard width very light? */
/* ignored for horizontal metrics */
FT_UInt blue_count;
AF_LatinBlueRec blues[AF_BLUE_STRINGSET_MAX];
FT_Fixed org_scale;
FT_Pos org_delta;
} AF_LatinAxisRec, *AF_LatinAxis;
typedef struct AF_LatinMetricsRec_
{
AF_StyleMetricsRec root;
FT_UInt units_per_em;
AF_LatinAxisRec axis[AF_DIMENSION_MAX];
} AF_LatinMetricsRec, *AF_LatinMetrics;
FT_LOCAL( FT_Error )
af_latin_metrics_init( AF_LatinMetrics metrics,
FT_Face face );
FT_LOCAL( void )
af_latin_metrics_scale( AF_LatinMetrics metrics,
AF_Scaler scaler );
FT_LOCAL( void )
af_latin_metrics_init_widths( AF_LatinMetrics metrics,
FT_Face face );
FT_LOCAL( void )
af_latin_metrics_check_digits( AF_LatinMetrics metrics,
FT_Face face );
/*************************************************************************/
/*************************************************************************/
/***** *****/
/***** L A T I N G L Y P H A N A L Y S I S *****/
/***** *****/
/*************************************************************************/
/*************************************************************************/
enum
{
AF_LATIN_HINTS_HORZ_SNAP = 1 << 0, /* enable stem width snapping */
AF_LATIN_HINTS_VERT_SNAP = 1 << 1, /* enable stem height snapping */
AF_LATIN_HINTS_STEM_ADJUST = 1 << 2, /* enable stem width/height */
/* adjustment */
AF_LATIN_HINTS_MONO = 1 << 3 /* indicate monochrome */
/* rendering */
};
#define AF_LATIN_HINTS_DO_HORZ_SNAP( h ) \
AF_HINTS_TEST_OTHER( h, AF_LATIN_HINTS_HORZ_SNAP )
#define AF_LATIN_HINTS_DO_VERT_SNAP( h ) \
AF_HINTS_TEST_OTHER( h, AF_LATIN_HINTS_VERT_SNAP )
#define AF_LATIN_HINTS_DO_STEM_ADJUST( h ) \
AF_HINTS_TEST_OTHER( h, AF_LATIN_HINTS_STEM_ADJUST )
#define AF_LATIN_HINTS_DO_MONO( h ) \
AF_HINTS_TEST_OTHER( h, AF_LATIN_HINTS_MONO )
/*
* The next functions shouldn't normally be exported. However, other
* writing systems might like to use these functions as-is.
*/
FT_LOCAL( FT_Error )
af_latin_hints_compute_segments( AF_GlyphHints hints,
AF_Dimension dim );
FT_LOCAL( void )
af_latin_hints_link_segments( AF_GlyphHints hints,
AF_Dimension dim );
FT_LOCAL( FT_Error )
af_latin_hints_compute_edges( AF_GlyphHints hints,
AF_Dimension dim );
FT_LOCAL( FT_Error )
af_latin_hints_detect_features( AF_GlyphHints hints,
AF_Dimension dim );
/* */
FT_END_HEADER
#endif /* __AFLATIN_H__ */
/* END */
| YifuLiu/AliOS-Things | components/freetype/src/autofit/aflatin.h | C | apache-2.0 | 6,948 |
/***************************************************************************/
/* */
/* aflatin2.c */
/* */
/* Auto-fitter hinting routines for latin writing system (body). */
/* */
/* Copyright 2003-2013 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. */
/* */
/***************************************************************************/
#include FT_ADVANCES_H
#include "afglobal.h"
#include "aflatin.h"
#include "aflatin2.h"
#include "aferrors.h"
#ifdef AF_CONFIG_OPTION_USE_WARPER
#include "afwarp.h"
#endif
/*************************************************************************/
/* */
/* The macro FT_COMPONENT is used in trace mode. It is an implicit */
/* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */
/* messages during execution. */
/* */
#undef FT_COMPONENT
#define FT_COMPONENT trace_aflatin2
FT_LOCAL_DEF( FT_Error )
af_latin2_hints_compute_segments( AF_GlyphHints hints,
AF_Dimension dim );
FT_LOCAL_DEF( void )
af_latin2_hints_link_segments( AF_GlyphHints hints,
AF_Dimension dim );
/*************************************************************************/
/*************************************************************************/
/***** *****/
/***** L A T I N G L O B A L M E T R I C S *****/
/***** *****/
/*************************************************************************/
/*************************************************************************/
FT_LOCAL_DEF( void )
af_latin2_metrics_init_widths( AF_LatinMetrics metrics,
FT_Face face )
{
/* scan the array of segments in each direction */
AF_GlyphHintsRec hints[1];
af_glyph_hints_init( hints, face->memory );
metrics->axis[AF_DIMENSION_HORZ].width_count = 0;
metrics->axis[AF_DIMENSION_VERT].width_count = 0;
{
FT_Error error;
FT_UInt glyph_index;
int dim;
AF_LatinMetricsRec dummy[1];
AF_Scaler scaler = &dummy->root.scaler;
glyph_index = FT_Get_Char_Index(
face,
metrics->root.style_class->standard_char );
if ( glyph_index == 0 )
goto Exit;
error = FT_Load_Glyph( face, glyph_index, FT_LOAD_NO_SCALE );
if ( error || face->glyph->outline.n_points <= 0 )
goto Exit;
FT_ZERO( dummy );
dummy->units_per_em = metrics->units_per_em;
scaler->x_scale = scaler->y_scale = 0x10000L;
scaler->x_delta = scaler->y_delta = 0;
scaler->face = face;
scaler->render_mode = FT_RENDER_MODE_NORMAL;
scaler->flags = 0;
af_glyph_hints_rescale( hints, (AF_StyleMetrics)dummy );
error = af_glyph_hints_reload( hints, &face->glyph->outline );
if ( error )
goto Exit;
for ( dim = 0; dim < AF_DIMENSION_MAX; dim++ )
{
AF_LatinAxis axis = &metrics->axis[dim];
AF_AxisHints axhints = &hints->axis[dim];
AF_Segment seg, limit, link;
FT_UInt num_widths = 0;
error = af_latin2_hints_compute_segments( hints,
(AF_Dimension)dim );
if ( error )
goto Exit;
af_latin2_hints_link_segments( hints,
(AF_Dimension)dim );
seg = axhints->segments;
limit = seg + axhints->num_segments;
for ( ; seg < limit; seg++ )
{
link = seg->link;
/* we only consider stem segments there! */
if ( link && link->link == seg && link > seg )
{
FT_Pos dist;
dist = seg->pos - link->pos;
if ( dist < 0 )
dist = -dist;
if ( num_widths < AF_LATIN_MAX_WIDTHS )
axis->widths[num_widths++].org = dist;
}
}
af_sort_widths( num_widths, axis->widths );
axis->width_count = num_widths;
}
Exit:
for ( dim = 0; dim < AF_DIMENSION_MAX; dim++ )
{
AF_LatinAxis axis = &metrics->axis[dim];
FT_Pos stdw;
stdw = ( axis->width_count > 0 )
? axis->widths[0].org
: AF_LATIN_CONSTANT( metrics, 50 );
/* let's try 20% of the smallest width */
axis->edge_distance_threshold = stdw / 5;
axis->standard_width = stdw;
axis->extra_light = 0;
}
}
af_glyph_hints_done( hints );
}
#define AF_LATIN_MAX_TEST_CHARACTERS 12
static const char af_latin2_blue_chars[AF_LATIN_MAX_BLUES]
[AF_LATIN_MAX_TEST_CHARACTERS+1] =
{
"THEZOCQS",
"HEZLOCUS",
"fijkdbh",
"xzroesc",
"xzroesc",
"pqgjy"
};
static void
af_latin2_metrics_init_blues( AF_LatinMetrics metrics,
FT_Face face )
{
FT_Pos flats [AF_LATIN_MAX_TEST_CHARACTERS];
FT_Pos rounds[AF_LATIN_MAX_TEST_CHARACTERS];
FT_Int num_flats;
FT_Int num_rounds;
FT_Int bb;
AF_LatinBlue blue;
FT_Error error;
AF_LatinAxis axis = &metrics->axis[AF_DIMENSION_VERT];
FT_GlyphSlot glyph = face->glyph;
/* we compute the blues simply by loading each character from the */
/* 'af_latin2_blue_chars[blues]' string, then compute its top-most or */
/* bottom-most points (depending on `AF_IS_TOP_BLUE') */
FT_TRACE5(( "blue zones computation\n"
"======================\n\n" ));
for ( bb = 0; bb < AF_LATIN_BLUE_MAX; bb++ )
{
const char* p = af_latin2_blue_chars[bb];
const char* limit = p + AF_LATIN_MAX_TEST_CHARACTERS;
FT_Pos* blue_ref;
FT_Pos* blue_shoot;
FT_TRACE5(( "blue zone %d:\n", bb ));
num_flats = 0;
num_rounds = 0;
for ( ; p < limit && *p; p++ )
{
FT_UInt glyph_index;
FT_Int best_point, best_y, best_first, best_last;
FT_Vector* points;
FT_Bool round;
/* load the character in the face -- skip unknown or empty ones */
glyph_index = FT_Get_Char_Index( face, (FT_UInt)*p );
if ( glyph_index == 0 )
continue;
error = FT_Load_Glyph( face, glyph_index, FT_LOAD_NO_SCALE );
if ( error || glyph->outline.n_points <= 0 )
continue;
/* now compute min or max point indices and coordinates */
points = glyph->outline.points;
best_point = -1;
best_y = 0; /* make compiler happy */
best_first = 0; /* ditto */
best_last = 0; /* ditto */
{
FT_Int nn;
FT_Int first = 0;
FT_Int last = -1;
for ( nn = 0; nn < glyph->outline.n_contours; first = last+1, nn++ )
{
FT_Int old_best_point = best_point;
FT_Int pp;
last = glyph->outline.contours[nn];
/* Avoid single-point contours since they are never rasterized. */
/* In some fonts, they correspond to mark attachment points */
/* which are way outside of the glyph's real outline. */
if ( last == first )
continue;
if ( AF_LATIN_IS_TOP_BLUE( bb ) )
{
for ( pp = first; pp <= last; pp++ )
if ( best_point < 0 || points[pp].y > best_y )
{
best_point = pp;
best_y = points[pp].y;
}
}
else
{
for ( pp = first; pp <= last; pp++ )
if ( best_point < 0 || points[pp].y < best_y )
{
best_point = pp;
best_y = points[pp].y;
}
}
if ( best_point != old_best_point )
{
best_first = first;
best_last = last;
}
}
FT_TRACE5(( " %c %d", *p, best_y ));
}
/* now check whether the point belongs to a straight or round */
/* segment; we first need to find in which contour the extremum */
/* lies, then inspect its previous and next points */
{
FT_Pos best_x = points[best_point].x;
FT_Int start, end, prev, next;
FT_Pos dist;
/* now look for the previous and next points that are not on the */
/* same Y coordinate. Threshold the `closeness'... */
start = end = best_point;
do
{
prev = start - 1;
if ( prev < best_first )
prev = best_last;
dist = FT_ABS( points[prev].y - best_y );
/* accept a small distance or a small angle (both values are */
/* heuristic; value 20 corresponds to approx. 2.9 degrees) */
if ( dist > 5 )
if ( FT_ABS( points[prev].x - best_x ) <= 20 * dist )
break;
start = prev;
} while ( start != best_point );
do
{
next = end + 1;
if ( next > best_last )
next = best_first;
dist = FT_ABS( points[next].y - best_y );
if ( dist > 5 )
if ( FT_ABS( points[next].x - best_x ) <= 20 * dist )
break;
end = next;
} while ( end != best_point );
/* now, set the `round' flag depending on the segment's kind */
round = FT_BOOL(
FT_CURVE_TAG( glyph->outline.tags[start] ) != FT_CURVE_TAG_ON ||
FT_CURVE_TAG( glyph->outline.tags[ end ] ) != FT_CURVE_TAG_ON );
FT_TRACE5(( " (%s)\n", round ? "round" : "flat" ));
}
if ( round )
rounds[num_rounds++] = best_y;
else
flats[num_flats++] = best_y;
}
if ( num_flats == 0 && num_rounds == 0 )
{
/*
* we couldn't find a single glyph to compute this blue zone,
* we will simply ignore it then
*/
FT_TRACE5(( " empty\n" ));
continue;
}
/* we have computed the contents of the `rounds' and `flats' tables, */
/* now determine the reference and overshoot position of the blue -- */
/* we simply take the median value after a simple sort */
af_sort_pos( num_rounds, rounds );
af_sort_pos( num_flats, flats );
blue = & axis->blues[axis->blue_count];
blue_ref = & blue->ref.org;
blue_shoot = & blue->shoot.org;
axis->blue_count++;
if ( num_flats == 0 )
{
*blue_ref =
*blue_shoot = rounds[num_rounds / 2];
}
else if ( num_rounds == 0 )
{
*blue_ref =
*blue_shoot = flats[num_flats / 2];
}
else
{
*blue_ref = flats[num_flats / 2];
*blue_shoot = rounds[num_rounds / 2];
}
/* there are sometimes problems: if the overshoot position of top */
/* zones is under its reference position, or the opposite for bottom */
/* zones. We must thus check everything there and correct the errors */
if ( *blue_shoot != *blue_ref )
{
FT_Pos ref = *blue_ref;
FT_Pos shoot = *blue_shoot;
FT_Bool over_ref = FT_BOOL( shoot > ref );
if ( AF_LATIN_IS_TOP_BLUE( bb ) ^ over_ref )
{
*blue_ref =
*blue_shoot = ( shoot + ref ) / 2;
FT_TRACE5(( " [overshoot smaller than reference,"
" taking mean value]\n" ));
}
}
blue->flags = 0;
if ( AF_LATIN_IS_TOP_BLUE( bb ) )
blue->flags |= AF_LATIN_BLUE_TOP;
/*
* The following flag is used later to adjust the y and x scales
* in order to optimize the pixel grid alignment of the top of small
* letters.
*/
if ( AF_LATIN_IS_X_HEIGHT_BLUE( bb ) )
blue->flags |= AF_LATIN_BLUE_ADJUSTMENT;
FT_TRACE5(( " -> reference = %ld\n"
" overshoot = %ld\n",
*blue_ref, *blue_shoot ));
}
return;
}
FT_LOCAL_DEF( void )
af_latin2_metrics_check_digits( AF_LatinMetrics metrics,
FT_Face face )
{
FT_UInt i;
FT_Bool started = 0, same_width = 1;
FT_Fixed advance, old_advance = 0;
/* check whether all ASCII digits have the same advance width; */
/* digit `0' is 0x30 in all supported charmaps */
for ( i = 0x30; i <= 0x39; i++ )
{
FT_UInt glyph_index;
glyph_index = FT_Get_Char_Index( face, i );
if ( glyph_index == 0 )
continue;
if ( FT_Get_Advance( face, glyph_index,
FT_LOAD_NO_SCALE |
FT_LOAD_NO_HINTING |
FT_LOAD_IGNORE_TRANSFORM,
&advance ) )
continue;
if ( started )
{
if ( advance != old_advance )
{
same_width = 0;
break;
}
}
else
{
old_advance = advance;
started = 1;
}
}
metrics->root.digits_have_same_width = same_width;
}
FT_LOCAL_DEF( FT_Error )
af_latin2_metrics_init( AF_LatinMetrics metrics,
FT_Face face )
{
FT_Error error = FT_Err_Ok;
FT_CharMap oldmap = face->charmap;
FT_UInt ee;
static const FT_Encoding latin_encodings[] =
{
FT_ENCODING_UNICODE,
FT_ENCODING_APPLE_ROMAN,
FT_ENCODING_ADOBE_STANDARD,
FT_ENCODING_ADOBE_LATIN_1,
FT_ENCODING_NONE /* end of list */
};
metrics->units_per_em = face->units_per_EM;
/* do we have a latin charmap in there? */
for ( ee = 0; latin_encodings[ee] != FT_ENCODING_NONE; ee++ )
{
error = FT_Select_Charmap( face, latin_encodings[ee] );
if ( !error )
break;
}
if ( !error )
{
af_latin2_metrics_init_widths( metrics, face );
af_latin2_metrics_init_blues( metrics, face );
af_latin2_metrics_check_digits( metrics, face );
}
FT_Set_Charmap( face, oldmap );
return FT_Err_Ok;
}
static void
af_latin2_metrics_scale_dim( AF_LatinMetrics metrics,
AF_Scaler scaler,
AF_Dimension dim )
{
FT_Fixed scale;
FT_Pos delta;
AF_LatinAxis axis;
FT_UInt nn;
if ( dim == AF_DIMENSION_HORZ )
{
scale = scaler->x_scale;
delta = scaler->x_delta;
}
else
{
scale = scaler->y_scale;
delta = scaler->y_delta;
}
axis = &metrics->axis[dim];
if ( axis->org_scale == scale && axis->org_delta == delta )
return;
axis->org_scale = scale;
axis->org_delta = delta;
/*
* correct Y scale to optimize the alignment of the top of small
* letters to the pixel grid
*/
if ( dim == AF_DIMENSION_VERT )
{
AF_LatinAxis vaxis = &metrics->axis[AF_DIMENSION_VERT];
AF_LatinBlue blue = NULL;
for ( nn = 0; nn < vaxis->blue_count; nn++ )
{
if ( vaxis->blues[nn].flags & AF_LATIN_BLUE_ADJUSTMENT )
{
blue = &vaxis->blues[nn];
break;
}
}
if ( blue )
{
FT_Pos scaled;
FT_Pos threshold;
FT_Pos fitted;
FT_UInt limit;
FT_UInt ppem;
scaled = FT_MulFix( blue->shoot.org, scaler->y_scale );
ppem = metrics->root.scaler.face->size->metrics.x_ppem;
limit = metrics->root.globals->increase_x_height;
threshold = 40;
/* if the `increase-x-height' property is active, */
/* we round up much more often */
if ( limit &&
ppem <= limit &&
ppem >= AF_PROP_INCREASE_X_HEIGHT_MIN )
threshold = 52;
fitted = ( scaled + threshold ) & ~63;
#if 1
if ( scaled != fitted )
{
scale = FT_MulDiv( scale, fitted, scaled );
FT_TRACE5(( "== scaled x-top = %.2g"
" fitted = %.2g, scaling = %.4g\n",
scaled / 64.0, fitted / 64.0,
( fitted * 1.0 ) / scaled ));
}
#endif
}
}
axis->scale = scale;
axis->delta = delta;
if ( dim == AF_DIMENSION_HORZ )
{
metrics->root.scaler.x_scale = scale;
metrics->root.scaler.x_delta = delta;
}
else
{
metrics->root.scaler.y_scale = scale;
metrics->root.scaler.y_delta = delta;
}
/* scale the standard widths */
for ( nn = 0; nn < axis->width_count; nn++ )
{
AF_Width width = axis->widths + nn;
width->cur = FT_MulFix( width->org, scale );
width->fit = width->cur;
}
/* an extra-light axis corresponds to a standard width that is */
/* smaller than 5/8 pixels */
axis->extra_light =
(FT_Bool)( FT_MulFix( axis->standard_width, scale ) < 32 + 8 );
if ( dim == AF_DIMENSION_VERT )
{
/* scale the blue zones */
for ( nn = 0; nn < axis->blue_count; nn++ )
{
AF_LatinBlue blue = &axis->blues[nn];
FT_Pos dist;
blue->ref.cur = FT_MulFix( blue->ref.org, scale ) + delta;
blue->ref.fit = blue->ref.cur;
blue->shoot.cur = FT_MulFix( blue->shoot.org, scale ) + delta;
blue->shoot.fit = blue->shoot.cur;
blue->flags &= ~AF_LATIN_BLUE_ACTIVE;
/* a blue zone is only active if it is less than 3/4 pixels tall */
dist = FT_MulFix( blue->ref.org - blue->shoot.org, scale );
if ( dist <= 48 && dist >= -48 )
{
FT_Pos delta1, delta2;
delta1 = blue->shoot.org - blue->ref.org;
delta2 = delta1;
if ( delta1 < 0 )
delta2 = -delta2;
delta2 = FT_MulFix( delta2, scale );
if ( delta2 < 32 )
delta2 = 0;
else if ( delta2 < 64 )
delta2 = 32 + ( ( ( delta2 - 32 ) + 16 ) & ~31 );
else
delta2 = FT_PIX_ROUND( delta2 );
if ( delta1 < 0 )
delta2 = -delta2;
blue->ref.fit = FT_PIX_ROUND( blue->ref.cur );
blue->shoot.fit = blue->ref.fit + delta2;
FT_TRACE5(( ">> activating blue zone %d:"
" ref.cur=%.2g ref.fit=%.2g"
" shoot.cur=%.2g shoot.fit=%.2g\n",
nn, blue->ref.cur / 64.0, blue->ref.fit / 64.0,
blue->shoot.cur / 64.0, blue->shoot.fit / 64.0 ));
blue->flags |= AF_LATIN_BLUE_ACTIVE;
}
}
}
}
FT_LOCAL_DEF( void )
af_latin2_metrics_scale( AF_LatinMetrics metrics,
AF_Scaler scaler )
{
metrics->root.scaler.render_mode = scaler->render_mode;
metrics->root.scaler.face = scaler->face;
metrics->root.scaler.flags = scaler->flags;
af_latin2_metrics_scale_dim( metrics, scaler, AF_DIMENSION_HORZ );
af_latin2_metrics_scale_dim( metrics, scaler, AF_DIMENSION_VERT );
}
/*************************************************************************/
/*************************************************************************/
/***** *****/
/***** L A T I N G L Y P H A N A L Y S I S *****/
/***** *****/
/*************************************************************************/
/*************************************************************************/
#define SORT_SEGMENTS
FT_LOCAL_DEF( FT_Error )
af_latin2_hints_compute_segments( AF_GlyphHints hints,
AF_Dimension dim )
{
AF_AxisHints axis = &hints->axis[dim];
FT_Memory memory = hints->memory;
FT_Error error = FT_Err_Ok;
AF_Segment segment = NULL;
AF_SegmentRec seg0;
AF_Point* contour = hints->contours;
AF_Point* contour_limit = contour + hints->num_contours;
AF_Direction major_dir, segment_dir;
FT_ZERO( &seg0 );
seg0.score = 32000;
seg0.flags = AF_EDGE_NORMAL;
major_dir = (AF_Direction)FT_ABS( axis->major_dir );
segment_dir = major_dir;
axis->num_segments = 0;
/* set up (u,v) in each point */
if ( dim == AF_DIMENSION_HORZ )
{
AF_Point point = hints->points;
AF_Point limit = point + hints->num_points;
for ( ; point < limit; point++ )
{
point->u = point->fx;
point->v = point->fy;
}
}
else
{
AF_Point point = hints->points;
AF_Point limit = point + hints->num_points;
for ( ; point < limit; point++ )
{
point->u = point->fy;
point->v = point->fx;
}
}
/* do each contour separately */
for ( ; contour < contour_limit; contour++ )
{
AF_Point point = contour[0];
AF_Point start = point;
AF_Point last = point->prev;
if ( point == last ) /* skip singletons -- just in case */
continue;
/* already on an edge ?, backtrack to find its start */
if ( FT_ABS( point->in_dir ) == major_dir )
{
point = point->prev;
while ( point->in_dir == start->in_dir )
point = point->prev;
}
else /* otherwise, find first segment start, if any */
{
while ( FT_ABS( point->out_dir ) != major_dir )
{
point = point->next;
if ( point == start )
goto NextContour;
}
}
start = point;
for (;;)
{
AF_Point first;
FT_Pos min_u, min_v, max_u, max_v;
/* we're at the start of a new segment */
FT_ASSERT( FT_ABS( point->out_dir ) == major_dir &&
point->in_dir != point->out_dir );
first = point;
min_u = max_u = point->u;
min_v = max_v = point->v;
point = point->next;
while ( point->out_dir == first->out_dir )
{
point = point->next;
if ( point->u < min_u )
min_u = point->u;
if ( point->u > max_u )
max_u = point->u;
}
if ( point->v < min_v )
min_v = point->v;
if ( point->v > max_v )
max_v = point->v;
/* record new segment */
error = af_axis_hints_new_segment( axis, memory, &segment );
if ( error )
goto Exit;
segment[0] = seg0;
segment->dir = first->out_dir;
segment->first = first;
segment->last = point;
segment->pos = (FT_Short)( ( min_u + max_u ) >> 1 );
segment->min_coord = (FT_Short) min_v;
segment->max_coord = (FT_Short) max_v;
segment->height = (FT_Short)( max_v - min_v );
/* a segment is round if it doesn't have successive */
/* on-curve points. */
{
AF_Point pt = first;
AF_Point last = point;
AF_Flags f0 = (AF_Flags)( pt->flags & AF_FLAG_CONTROL );
AF_Flags f1;
segment->flags &= ~AF_EDGE_ROUND;
for ( ; pt != last; f0 = f1 )
{
pt = pt->next;
f1 = (AF_Flags)( pt->flags & AF_FLAG_CONTROL );
if ( !f0 && !f1 )
break;
if ( pt == last )
segment->flags |= AF_EDGE_ROUND;
}
}
/* this can happen in the case of a degenerate contour
* e.g. a 2-point vertical contour
*/
if ( point == start )
break;
/* jump to the start of the next segment, if any */
while ( FT_ABS( point->out_dir ) != major_dir )
{
point = point->next;
if ( point == start )
goto NextContour;
}
}
NextContour:
;
} /* contours */
/* now slightly increase the height of segments when this makes */
/* sense -- this is used to better detect and ignore serifs */
{
AF_Segment segments = axis->segments;
AF_Segment segments_end = segments + axis->num_segments;
for ( segment = segments; segment < segments_end; segment++ )
{
AF_Point first = segment->first;
AF_Point last = segment->last;
AF_Point p;
FT_Pos first_v = first->v;
FT_Pos last_v = last->v;
if ( first == last )
continue;
if ( first_v < last_v )
{
p = first->prev;
if ( p->v < first_v )
segment->height = (FT_Short)( segment->height +
( ( first_v - p->v ) >> 1 ) );
p = last->next;
if ( p->v > last_v )
segment->height = (FT_Short)( segment->height +
( ( p->v - last_v ) >> 1 ) );
}
else
{
p = first->prev;
if ( p->v > first_v )
segment->height = (FT_Short)( segment->height +
( ( p->v - first_v ) >> 1 ) );
p = last->next;
if ( p->v < last_v )
segment->height = (FT_Short)( segment->height +
( ( last_v - p->v ) >> 1 ) );
}
}
}
#ifdef AF_SORT_SEGMENTS
/* place all segments with a negative direction to the start
* of the array, used to speed up segment linking later...
*/
{
AF_Segment segments = axis->segments;
FT_UInt count = axis->num_segments;
FT_UInt ii, jj;
for ( ii = 0; ii < count; ii++ )
{
if ( segments[ii].dir > 0 )
{
for ( jj = ii + 1; jj < count; jj++ )
{
if ( segments[jj].dir < 0 )
{
AF_SegmentRec tmp;
tmp = segments[ii];
segments[ii] = segments[jj];
segments[jj] = tmp;
break;
}
}
if ( jj == count )
break;
}
}
axis->mid_segments = ii;
}
#endif
Exit:
return error;
}
FT_LOCAL_DEF( void )
af_latin2_hints_link_segments( AF_GlyphHints hints,
AF_Dimension dim )
{
AF_AxisHints axis = &hints->axis[dim];
AF_Segment segments = axis->segments;
AF_Segment segment_limit = segments + axis->num_segments;
#ifdef AF_SORT_SEGMENTS
AF_Segment segment_mid = segments + axis->mid_segments;
#endif
FT_Pos len_threshold, len_score;
AF_Segment seg1, seg2;
len_threshold = AF_LATIN_CONSTANT( hints->metrics, 8 );
if ( len_threshold == 0 )
len_threshold = 1;
len_score = AF_LATIN_CONSTANT( hints->metrics, 6000 );
#ifdef AF_SORT_SEGMENTS
for ( seg1 = segments; seg1 < segment_mid; seg1++ )
{
if ( seg1->dir != axis->major_dir || seg1->first == seg1->last )
continue;
for ( seg2 = segment_mid; seg2 < segment_limit; seg2++ )
#else
/* now compare each segment to the others */
for ( seg1 = segments; seg1 < segment_limit; seg1++ )
{
/* the fake segments are introduced to hint the metrics -- */
/* we must never link them to anything */
if ( seg1->dir != axis->major_dir || seg1->first == seg1->last )
continue;
for ( seg2 = segments; seg2 < segment_limit; seg2++ )
if ( seg1->dir + seg2->dir == 0 && seg2->pos > seg1->pos )
#endif
{
FT_Pos pos1 = seg1->pos;
FT_Pos pos2 = seg2->pos;
FT_Pos dist = pos2 - pos1;
if ( dist < 0 )
continue;
{
FT_Pos min = seg1->min_coord;
FT_Pos max = seg1->max_coord;
FT_Pos len, score;
if ( min < seg2->min_coord )
min = seg2->min_coord;
if ( max > seg2->max_coord )
max = seg2->max_coord;
len = max - min;
if ( len >= len_threshold )
{
score = dist + len_score / len;
if ( score < seg1->score )
{
seg1->score = score;
seg1->link = seg2;
}
if ( score < seg2->score )
{
seg2->score = score;
seg2->link = seg1;
}
}
}
}
}
#if 0
}
#endif
/* now, compute the `serif' segments */
for ( seg1 = segments; seg1 < segment_limit; seg1++ )
{
seg2 = seg1->link;
if ( seg2 )
{
if ( seg2->link != seg1 )
{
seg1->link = 0;
seg1->serif = seg2->link;
}
}
}
}
FT_LOCAL_DEF( FT_Error )
af_latin2_hints_compute_edges( AF_GlyphHints hints,
AF_Dimension dim )
{
AF_AxisHints axis = &hints->axis[dim];
FT_Error error = FT_Err_Ok;
FT_Memory memory = hints->memory;
AF_LatinAxis laxis = &((AF_LatinMetrics)hints->metrics)->axis[dim];
AF_Segment segments = axis->segments;
AF_Segment segment_limit = segments + axis->num_segments;
AF_Segment seg;
AF_Direction up_dir;
FT_Fixed scale;
FT_Pos edge_distance_threshold;
FT_Pos segment_length_threshold;
axis->num_edges = 0;
scale = ( dim == AF_DIMENSION_HORZ ) ? hints->x_scale
: hints->y_scale;
up_dir = ( dim == AF_DIMENSION_HORZ ) ? AF_DIR_UP
: AF_DIR_RIGHT;
/*
* We want to ignore very small (mostly serif) segments, we do that
* by ignoring those that whose length is less than a given fraction
* of the standard width. If there is no standard width, we ignore
* those that are less than a given size in pixels
*
* also, unlink serif segments that are linked to segments farther
* than 50% of the standard width
*/
if ( dim == AF_DIMENSION_HORZ )
{
if ( laxis->width_count > 0 )
segment_length_threshold = ( laxis->standard_width * 10 ) >> 4;
else
segment_length_threshold = FT_DivFix( 64, hints->y_scale );
}
else
segment_length_threshold = 0;
/*********************************************************************/
/* */
/* We will begin by generating a sorted table of edges for the */
/* current direction. To do so, we simply scan each segment and try */
/* to find an edge in our table that corresponds to its position. */
/* */
/* If no edge is found, we create and insert a new edge in the */
/* sorted table. Otherwise, we simply add the segment to the edge's */
/* list which will be processed in the second step to compute the */
/* edge's properties. */
/* */
/* Note that the edges table is sorted along the segment/edge */
/* position. */
/* */
/*********************************************************************/
edge_distance_threshold = FT_MulFix( laxis->edge_distance_threshold,
scale );
if ( edge_distance_threshold > 64 / 4 )
edge_distance_threshold = 64 / 4;
edge_distance_threshold = FT_DivFix( edge_distance_threshold,
scale );
for ( seg = segments; seg < segment_limit; seg++ )
{
AF_Edge found = 0;
FT_Int ee;
if ( seg->height < segment_length_threshold )
continue;
/* A special case for serif edges: If they are smaller than */
/* 1.5 pixels we ignore them. */
if ( seg->serif )
{
FT_Pos dist = seg->serif->pos - seg->pos;
if ( dist < 0 )
dist = -dist;
if ( dist >= laxis->standard_width >> 1 )
{
/* unlink this serif, it is too distant from its reference stem */
seg->serif = NULL;
}
else if ( 2*seg->height < 3 * segment_length_threshold )
continue;
}
/* look for an edge corresponding to the segment */
for ( ee = 0; ee < axis->num_edges; ee++ )
{
AF_Edge edge = axis->edges + ee;
FT_Pos dist;
dist = seg->pos - edge->fpos;
if ( dist < 0 )
dist = -dist;
if ( dist < edge_distance_threshold && edge->dir == seg->dir )
{
found = edge;
break;
}
}
if ( !found )
{
AF_Edge edge;
/* insert a new edge in the list and */
/* sort according to the position */
error = af_axis_hints_new_edge( axis, seg->pos, seg->dir,
memory, &edge );
if ( error )
goto Exit;
/* add the segment to the new edge's list */
FT_ZERO( edge );
edge->first = seg;
edge->last = seg;
edge->fpos = seg->pos;
edge->dir = seg->dir;
edge->opos = edge->pos = FT_MulFix( seg->pos, scale );
seg->edge_next = seg;
}
else
{
/* if an edge was found, simply add the segment to the edge's */
/* list */
seg->edge_next = found->first;
found->last->edge_next = seg;
found->last = seg;
}
}
/*********************************************************************/
/* */
/* Good, we will now compute each edge's properties according to */
/* segments found on its position. Basically, these are: */
/* */
/* - edge's main direction */
/* - stem edge, serif edge or both (which defaults to stem then) */
/* - rounded edge, straight or both (which defaults to straight) */
/* - link for edge */
/* */
/*********************************************************************/
/* first of all, set the `edge' field in each segment -- this is */
/* required in order to compute edge links */
/*
* Note that removing this loop and setting the `edge' field of each
* segment directly in the code above slows down execution speed for
* some reasons on platforms like the Sun.
*/
{
AF_Edge edges = axis->edges;
AF_Edge edge_limit = edges + axis->num_edges;
AF_Edge edge;
for ( edge = edges; edge < edge_limit; edge++ )
{
seg = edge->first;
if ( seg )
do
{
seg->edge = edge;
seg = seg->edge_next;
} while ( seg != edge->first );
}
/* now, compute each edge properties */
for ( edge = edges; edge < edge_limit; edge++ )
{
FT_Int is_round = 0; /* does it contain round segments? */
FT_Int is_straight = 0; /* does it contain straight segments? */
#if 0
FT_Pos ups = 0; /* number of upwards segments */
FT_Pos downs = 0; /* number of downwards segments */
#endif
seg = edge->first;
do
{
FT_Bool is_serif;
/* check for roundness of segment */
if ( seg->flags & AF_EDGE_ROUND )
is_round++;
else
is_straight++;
#if 0
/* check for segment direction */
if ( seg->dir == up_dir )
ups += seg->max_coord-seg->min_coord;
else
downs += seg->max_coord-seg->min_coord;
#endif
/* check for links -- if seg->serif is set, then seg->link must */
/* be ignored */
is_serif = (FT_Bool)( seg->serif &&
seg->serif->edge &&
seg->serif->edge != edge );
if ( ( seg->link && seg->link->edge != NULL ) || is_serif )
{
AF_Edge edge2;
AF_Segment seg2;
edge2 = edge->link;
seg2 = seg->link;
if ( is_serif )
{
seg2 = seg->serif;
edge2 = edge->serif;
}
if ( edge2 )
{
FT_Pos edge_delta;
FT_Pos seg_delta;
edge_delta = edge->fpos - edge2->fpos;
if ( edge_delta < 0 )
edge_delta = -edge_delta;
seg_delta = seg->pos - seg2->pos;
if ( seg_delta < 0 )
seg_delta = -seg_delta;
if ( seg_delta < edge_delta )
edge2 = seg2->edge;
}
else
edge2 = seg2->edge;
if ( is_serif )
{
edge->serif = edge2;
edge2->flags |= AF_EDGE_SERIF;
}
else
edge->link = edge2;
}
seg = seg->edge_next;
} while ( seg != edge->first );
/* set the round/straight flags */
edge->flags = AF_EDGE_NORMAL;
if ( is_round > 0 && is_round >= is_straight )
edge->flags |= AF_EDGE_ROUND;
#if 0
/* set the edge's main direction */
edge->dir = AF_DIR_NONE;
if ( ups > downs )
edge->dir = (FT_Char)up_dir;
else if ( ups < downs )
edge->dir = (FT_Char)-up_dir;
else if ( ups == downs )
edge->dir = 0; /* both up and down! */
#endif
/* gets rid of serifs if link is set */
/* XXX: This gets rid of many unpleasant artefacts! */
/* Example: the `c' in cour.pfa at size 13 */
if ( edge->serif && edge->link )
edge->serif = 0;
}
}
Exit:
return error;
}
FT_LOCAL_DEF( FT_Error )
af_latin2_hints_detect_features( AF_GlyphHints hints,
AF_Dimension dim )
{
FT_Error error;
error = af_latin2_hints_compute_segments( hints, dim );
if ( !error )
{
af_latin2_hints_link_segments( hints, dim );
error = af_latin2_hints_compute_edges( hints, dim );
}
return error;
}
FT_LOCAL_DEF( void )
af_latin2_hints_compute_blue_edges( AF_GlyphHints hints,
AF_LatinMetrics metrics )
{
AF_AxisHints axis = &hints->axis[AF_DIMENSION_VERT];
AF_Edge edge = axis->edges;
AF_Edge edge_limit = edge + axis->num_edges;
AF_LatinAxis latin = &metrics->axis[AF_DIMENSION_VERT];
FT_Fixed scale = latin->scale;
FT_Pos best_dist0; /* initial threshold */
/* compute the initial threshold as a fraction of the EM size */
best_dist0 = FT_MulFix( metrics->units_per_em / 40, scale );
if ( best_dist0 > 64 / 2 )
best_dist0 = 64 / 2;
/* compute which blue zones are active, i.e. have their scaled */
/* size < 3/4 pixels */
/* for each horizontal edge search the blue zone which is closest */
for ( ; edge < edge_limit; edge++ )
{
FT_Int bb;
AF_Width best_blue = NULL;
FT_Pos best_dist = best_dist0;
for ( bb = 0; bb < AF_LATIN_BLUE_MAX; bb++ )
{
AF_LatinBlue blue = latin->blues + bb;
FT_Bool is_top_blue, is_major_dir;
/* skip inactive blue zones (i.e., those that are too small) */
if ( !( blue->flags & AF_LATIN_BLUE_ACTIVE ) )
continue;
/* if it is a top zone, check for right edges -- if it is a bottom */
/* zone, check for left edges */
/* */
/* of course, that's for TrueType */
is_top_blue = (FT_Byte)( ( blue->flags & AF_LATIN_BLUE_TOP ) != 0 );
is_major_dir = FT_BOOL( edge->dir == axis->major_dir );
/* if it is a top zone, the edge must be against the major */
/* direction; if it is a bottom zone, it must be in the major */
/* direction */
if ( is_top_blue ^ is_major_dir )
{
FT_Pos dist;
AF_Width compare;
/* if it's a rounded edge, compare it to the overshoot position */
/* if it's a flat edge, compare it to the reference position */
if ( edge->flags & AF_EDGE_ROUND )
compare = &blue->shoot;
else
compare = &blue->ref;
dist = edge->fpos - compare->org;
if ( dist < 0 )
dist = -dist;
dist = FT_MulFix( dist, scale );
if ( dist < best_dist )
{
best_dist = dist;
best_blue = compare;
}
#if 0
/* now, compare it to the overshoot position if the edge is */
/* rounded, and if the edge is over the reference position of a */
/* top zone, or under the reference position of a bottom zone */
if ( edge->flags & AF_EDGE_ROUND && dist != 0 )
{
FT_Bool is_under_ref = FT_BOOL( edge->fpos < blue->ref.org );
if ( is_top_blue ^ is_under_ref )
{
blue = latin->blues + bb;
dist = edge->fpos - blue->shoot.org;
if ( dist < 0 )
dist = -dist;
dist = FT_MulFix( dist, scale );
if ( dist < best_dist )
{
best_dist = dist;
best_blue = & blue->shoot;
}
}
}
#endif
}
}
if ( best_blue )
edge->blue_edge = best_blue;
}
}
static FT_Error
af_latin2_hints_init( AF_GlyphHints hints,
AF_LatinMetrics metrics )
{
FT_Render_Mode mode;
FT_UInt32 scaler_flags, other_flags;
FT_Face face = metrics->root.scaler.face;
af_glyph_hints_rescale( hints, (AF_StyleMetrics)metrics );
/*
* correct x_scale and y_scale if needed, since they may have
* been modified `af_latin2_metrics_scale_dim' above
*/
hints->x_scale = metrics->axis[AF_DIMENSION_HORZ].scale;
hints->x_delta = metrics->axis[AF_DIMENSION_HORZ].delta;
hints->y_scale = metrics->axis[AF_DIMENSION_VERT].scale;
hints->y_delta = metrics->axis[AF_DIMENSION_VERT].delta;
/* compute flags depending on render mode, etc. */
mode = metrics->root.scaler.render_mode;
#if 0 /* #ifdef AF_CONFIG_OPTION_USE_WARPER */
if ( mode == FT_RENDER_MODE_LCD || mode == FT_RENDER_MODE_LCD_V )
{
metrics->root.scaler.render_mode = mode = FT_RENDER_MODE_NORMAL;
}
#endif
scaler_flags = hints->scaler_flags;
other_flags = 0;
/*
* We snap the width of vertical stems for the monochrome and
* horizontal LCD rendering targets only.
*/
if ( mode == FT_RENDER_MODE_MONO || mode == FT_RENDER_MODE_LCD )
other_flags |= AF_LATIN_HINTS_HORZ_SNAP;
/*
* We snap the width of horizontal stems for the monochrome and
* vertical LCD rendering targets only.
*/
if ( mode == FT_RENDER_MODE_MONO || mode == FT_RENDER_MODE_LCD_V )
other_flags |= AF_LATIN_HINTS_VERT_SNAP;
/*
* We adjust stems to full pixels only if we don't use the `light' mode.
*/
if ( mode != FT_RENDER_MODE_LIGHT )
other_flags |= AF_LATIN_HINTS_STEM_ADJUST;
if ( mode == FT_RENDER_MODE_MONO )
other_flags |= AF_LATIN_HINTS_MONO;
/*
* In `light' hinting mode we disable horizontal hinting completely.
* We also do it if the face is italic.
*/
if ( mode == FT_RENDER_MODE_LIGHT ||
( face->style_flags & FT_STYLE_FLAG_ITALIC ) != 0 )
scaler_flags |= AF_SCALER_FLAG_NO_HORIZONTAL;
hints->scaler_flags = scaler_flags;
hints->other_flags = other_flags;
return 0;
}
/*************************************************************************/
/*************************************************************************/
/***** *****/
/***** L A T I N G L Y P H G R I D - F I T T I N G *****/
/***** *****/
/*************************************************************************/
/*************************************************************************/
/* snap a given width in scaled coordinates to one of the */
/* current standard widths */
static FT_Pos
af_latin2_snap_width( AF_Width widths,
FT_Int count,
FT_Pos width )
{
int n;
FT_Pos best = 64 + 32 + 2;
FT_Pos reference = width;
FT_Pos scaled;
for ( n = 0; n < count; n++ )
{
FT_Pos w;
FT_Pos dist;
w = widths[n].cur;
dist = width - w;
if ( dist < 0 )
dist = -dist;
if ( dist < best )
{
best = dist;
reference = w;
}
}
scaled = FT_PIX_ROUND( reference );
if ( width >= reference )
{
if ( width < scaled + 48 )
width = reference;
}
else
{
if ( width > scaled - 48 )
width = reference;
}
return width;
}
/* compute the snapped width of a given stem */
static FT_Pos
af_latin2_compute_stem_width( AF_GlyphHints hints,
AF_Dimension dim,
FT_Pos width,
AF_Edge_Flags base_flags,
AF_Edge_Flags stem_flags )
{
AF_LatinMetrics metrics = (AF_LatinMetrics) hints->metrics;
AF_LatinAxis axis = & metrics->axis[dim];
FT_Pos dist = width;
FT_Int sign = 0;
FT_Int vertical = ( dim == AF_DIMENSION_VERT );
FT_UNUSED( base_flags );
if ( !AF_LATIN_HINTS_DO_STEM_ADJUST( hints ) ||
axis->extra_light )
return width;
if ( dist < 0 )
{
dist = -width;
sign = 1;
}
if ( ( vertical && !AF_LATIN_HINTS_DO_VERT_SNAP( hints ) ) ||
( !vertical && !AF_LATIN_HINTS_DO_HORZ_SNAP( hints ) ) )
{
/* smooth hinting process: very lightly quantize the stem width */
/* leave the widths of serifs alone */
if ( ( stem_flags & AF_EDGE_SERIF ) && vertical && ( dist < 3 * 64 ) )
goto Done_Width;
#if 0
else if ( ( base_flags & AF_EDGE_ROUND ) )
{
if ( dist < 80 )
dist = 64;
}
else if ( dist < 56 )
dist = 56;
#endif
if ( axis->width_count > 0 )
{
FT_Pos delta;
/* compare to standard width */
if ( axis->width_count > 0 )
{
delta = dist - axis->widths[0].cur;
if ( delta < 0 )
delta = -delta;
if ( delta < 40 )
{
dist = axis->widths[0].cur;
if ( dist < 48 )
dist = 48;
goto Done_Width;
}
}
if ( dist < 3 * 64 )
{
delta = dist & 63;
dist &= -64;
if ( delta < 10 )
dist += delta;
else if ( delta < 32 )
dist += 10;
else if ( delta < 54 )
dist += 54;
else
dist += delta;
}
else
dist = ( dist + 32 ) & ~63;
}
}
else
{
/* strong hinting process: snap the stem width to integer pixels */
FT_Pos org_dist = dist;
dist = af_latin2_snap_width( axis->widths, axis->width_count, dist );
if ( vertical )
{
/* in the case of vertical hinting, always round */
/* the stem heights to integer pixels */
if ( dist >= 64 )
dist = ( dist + 16 ) & ~63;
else
dist = 64;
}
else
{
if ( AF_LATIN_HINTS_DO_MONO( hints ) )
{
/* monochrome horizontal hinting: snap widths to integer pixels */
/* with a different threshold */
if ( dist < 64 )
dist = 64;
else
dist = ( dist + 32 ) & ~63;
}
else
{
/* for horizontal anti-aliased hinting, we adopt a more subtle */
/* approach: we strengthen small stems, round stems whose size */
/* is between 1 and 2 pixels to an integer, otherwise nothing */
if ( dist < 48 )
dist = ( dist + 64 ) >> 1;
else if ( dist < 128 )
{
/* We only round to an integer width if the corresponding */
/* distortion is less than 1/4 pixel. Otherwise this */
/* makes everything worse since the diagonals, which are */
/* not hinted, appear a lot bolder or thinner than the */
/* vertical stems. */
FT_Int delta;
dist = ( dist + 22 ) & ~63;
delta = dist - org_dist;
if ( delta < 0 )
delta = -delta;
if ( delta >= 16 )
{
dist = org_dist;
if ( dist < 48 )
dist = ( dist + 64 ) >> 1;
}
}
else
/* round otherwise to prevent color fringes in LCD mode */
dist = ( dist + 32 ) & ~63;
}
}
}
Done_Width:
if ( sign )
dist = -dist;
return dist;
}
/* align one stem edge relative to the previous stem edge */
static void
af_latin2_align_linked_edge( AF_GlyphHints hints,
AF_Dimension dim,
AF_Edge base_edge,
AF_Edge stem_edge )
{
FT_Pos dist = stem_edge->opos - base_edge->opos;
FT_Pos fitted_width = af_latin2_compute_stem_width(
hints, dim, dist,
(AF_Edge_Flags)base_edge->flags,
(AF_Edge_Flags)stem_edge->flags );
stem_edge->pos = base_edge->pos + fitted_width;
FT_TRACE5(( "LINK: edge %d (opos=%.2f) linked to (%.2f), "
"dist was %.2f, now %.2f\n",
stem_edge-hints->axis[dim].edges, stem_edge->opos / 64.0,
stem_edge->pos / 64.0, dist / 64.0, fitted_width / 64.0 ));
}
static void
af_latin2_align_serif_edge( AF_GlyphHints hints,
AF_Edge base,
AF_Edge serif )
{
FT_UNUSED( hints );
serif->pos = base->pos + ( serif->opos - base->opos );
}
/*************************************************************************/
/*************************************************************************/
/*************************************************************************/
/**** ****/
/**** E D G E H I N T I N G ****/
/**** ****/
/*************************************************************************/
/*************************************************************************/
/*************************************************************************/
FT_LOCAL_DEF( void )
af_latin2_hint_edges( AF_GlyphHints hints,
AF_Dimension dim )
{
AF_AxisHints axis = &hints->axis[dim];
AF_Edge edges = axis->edges;
AF_Edge edge_limit = edges + axis->num_edges;
AF_Edge edge;
AF_Edge anchor = 0;
FT_Int has_serifs = 0;
FT_Pos anchor_drift = 0;
FT_TRACE5(( "==== hinting %s edges =====\n",
dim == AF_DIMENSION_HORZ ? "vertical" : "horizontal" ));
/* we begin by aligning all stems relative to the blue zone */
/* if needed -- that's only for horizontal edges */
if ( dim == AF_DIMENSION_VERT && AF_HINTS_DO_BLUES( hints ) )
{
for ( edge = edges; edge < edge_limit; edge++ )
{
AF_Width blue;
AF_Edge edge1, edge2;
if ( edge->flags & AF_EDGE_DONE )
continue;
blue = edge->blue_edge;
edge1 = NULL;
edge2 = edge->link;
if ( blue )
{
edge1 = edge;
}
else if ( edge2 && edge2->blue_edge )
{
blue = edge2->blue_edge;
edge1 = edge2;
edge2 = edge;
}
if ( !edge1 )
continue;
FT_TRACE5(( "BLUE: edge %d (opos=%.2f) snapped to (%.2f), "
"was (%.2f)\n",
edge1-edges, edge1->opos / 64.0, blue->fit / 64.0,
edge1->pos / 64.0 ));
edge1->pos = blue->fit;
edge1->flags |= AF_EDGE_DONE;
if ( edge2 && !edge2->blue_edge )
{
af_latin2_align_linked_edge( hints, dim, edge1, edge2 );
edge2->flags |= AF_EDGE_DONE;
}
if ( !anchor )
{
anchor = edge;
anchor_drift = ( anchor->pos - anchor->opos );
if ( edge2 )
anchor_drift = ( anchor_drift +
( edge2->pos - edge2->opos ) ) >> 1;
}
}
}
/* now we will align all stem edges, trying to maintain the */
/* relative order of stems in the glyph */
for ( edge = edges; edge < edge_limit; edge++ )
{
AF_Edge edge2;
if ( edge->flags & AF_EDGE_DONE )
continue;
/* skip all non-stem edges */
edge2 = edge->link;
if ( !edge2 )
{
has_serifs++;
continue;
}
/* now align the stem */
/* this should not happen, but it's better to be safe */
if ( edge2->blue_edge )
{
FT_TRACE5(( "ASSERTION FAILED for edge %d\n", edge2-edges ));
af_latin2_align_linked_edge( hints, dim, edge2, edge );
edge->flags |= AF_EDGE_DONE;
continue;
}
if ( !anchor )
{
FT_Pos org_len, org_center, cur_len;
FT_Pos cur_pos1, error1, error2, u_off, d_off;
org_len = edge2->opos - edge->opos;
cur_len = af_latin2_compute_stem_width(
hints, dim, org_len,
(AF_Edge_Flags)edge->flags,
(AF_Edge_Flags)edge2->flags );
if ( cur_len <= 64 )
u_off = d_off = 32;
else
{
u_off = 38;
d_off = 26;
}
if ( cur_len < 96 )
{
org_center = edge->opos + ( org_len >> 1 );
cur_pos1 = FT_PIX_ROUND( org_center );
error1 = org_center - ( cur_pos1 - u_off );
if ( error1 < 0 )
error1 = -error1;
error2 = org_center - ( cur_pos1 + d_off );
if ( error2 < 0 )
error2 = -error2;
if ( error1 < error2 )
cur_pos1 -= u_off;
else
cur_pos1 += d_off;
edge->pos = cur_pos1 - cur_len / 2;
edge2->pos = edge->pos + cur_len;
}
else
edge->pos = FT_PIX_ROUND( edge->opos );
FT_TRACE5(( "ANCHOR: edge %d (opos=%.2f) and %d (opos=%.2f)"
" snapped to (%.2f) (%.2f)\n",
edge-edges, edge->opos / 64.0,
edge2-edges, edge2->opos / 64.0,
edge->pos / 64.0, edge2->pos / 64.0 ));
anchor = edge;
edge->flags |= AF_EDGE_DONE;
af_latin2_align_linked_edge( hints, dim, edge, edge2 );
edge2->flags |= AF_EDGE_DONE;
anchor_drift = ( ( anchor->pos - anchor->opos ) +
( edge2->pos - edge2->opos ) ) >> 1;
FT_TRACE5(( "DRIFT: %.2f\n", anchor_drift/64.0 ));
}
else
{
FT_Pos org_pos, org_len, org_center, cur_center, cur_len;
FT_Pos org_left, org_right;
org_pos = edge->opos + anchor_drift;
org_len = edge2->opos - edge->opos;
org_center = org_pos + ( org_len >> 1 );
cur_len = af_latin2_compute_stem_width(
hints, dim, org_len,
(AF_Edge_Flags)edge->flags,
(AF_Edge_Flags)edge2->flags );
org_left = org_pos + ( ( org_len - cur_len ) >> 1 );
org_right = org_pos + ( ( org_len + cur_len ) >> 1 );
FT_TRACE5(( "ALIGN: left=%.2f right=%.2f ",
org_left / 64.0, org_right / 64.0 ));
cur_center = org_center;
if ( edge2->flags & AF_EDGE_DONE )
{
FT_TRACE5(( "\n" ));
edge->pos = edge2->pos - cur_len;
}
else
{
/* we want to compare several displacement, and choose
* the one that increases fitness while minimizing
* distortion as well
*/
FT_Pos displacements[6], scores[6], org, fit, delta;
FT_UInt count = 0;
/* note: don't even try to fit tiny stems */
if ( cur_len < 32 )
{
FT_TRACE5(( "tiny stem\n" ));
goto AlignStem;
}
/* if the span is within a single pixel, don't touch it */
if ( FT_PIX_FLOOR( org_left ) == FT_PIX_CEIL( org_right ) )
{
FT_TRACE5(( "single pixel stem\n" ));
goto AlignStem;
}
if ( cur_len <= 96 )
{
/* we want to avoid the absolute worst case which is
* when the left and right edges of the span each represent
* about 50% of the gray. we'd better want to change this
* to 25/75%, since this is much more pleasant to the eye with
* very acceptable distortion
*/
FT_Pos frac_left = org_left & 63;
FT_Pos frac_right = org_right & 63;
if ( frac_left >= 22 && frac_left <= 42 &&
frac_right >= 22 && frac_right <= 42 )
{
org = frac_left;
fit = ( org <= 32 ) ? 16 : 48;
delta = FT_ABS( fit - org );
displacements[count] = fit - org;
scores[count++] = delta;
FT_TRACE5(( "dispA=%.2f (%d) ", ( fit - org ) / 64.0, delta ));
org = frac_right;
fit = ( org <= 32 ) ? 16 : 48;
delta = FT_ABS( fit - org );
displacements[count] = fit - org;
scores[count++] = delta;
FT_TRACE5(( "dispB=%.2f (%d) ", ( fit - org ) / 64.0, delta ));
}
}
/* snapping the left edge to the grid */
org = org_left;
fit = FT_PIX_ROUND( org );
delta = FT_ABS( fit - org );
displacements[count] = fit - org;
scores[count++] = delta;
FT_TRACE5(( "dispC=%.2f (%d) ", ( fit - org ) / 64.0, delta ));
/* snapping the right edge to the grid */
org = org_right;
fit = FT_PIX_ROUND( org );
delta = FT_ABS( fit - org );
displacements[count] = fit - org;
scores[count++] = delta;
FT_TRACE5(( "dispD=%.2f (%d) ", ( fit - org ) / 64.0, delta ));
/* now find the best displacement */
{
FT_Pos best_score = scores[0];
FT_Pos best_disp = displacements[0];
FT_UInt nn;
for ( nn = 1; nn < count; nn++ )
{
if ( scores[nn] < best_score )
{
best_score = scores[nn];
best_disp = displacements[nn];
}
}
cur_center = org_center + best_disp;
}
FT_TRACE5(( "\n" ));
}
AlignStem:
edge->pos = cur_center - ( cur_len >> 1 );
edge2->pos = edge->pos + cur_len;
FT_TRACE5(( "STEM1: %d (opos=%.2f) to %d (opos=%.2f)"
" snapped to (%.2f) and (%.2f),"
" org_len=%.2f cur_len=%.2f\n",
edge-edges, edge->opos / 64.0,
edge2-edges, edge2->opos / 64.0,
edge->pos / 64.0, edge2->pos / 64.0,
org_len / 64.0, cur_len / 64.0 ));
edge->flags |= AF_EDGE_DONE;
edge2->flags |= AF_EDGE_DONE;
if ( edge > edges && edge->pos < edge[-1].pos )
{
FT_TRACE5(( "BOUND: %d (pos=%.2f) to (%.2f)\n",
edge-edges, edge->pos / 64.0, edge[-1].pos / 64.0 ));
edge->pos = edge[-1].pos;
}
}
}
/* make sure that lowercase m's maintain their symmetry */
/* In general, lowercase m's have six vertical edges if they are sans */
/* serif, or twelve if they are with serifs. This implementation is */
/* based on that assumption, and seems to work very well with most */
/* faces. However, if for a certain face this assumption is not */
/* true, the m is just rendered like before. In addition, any stem */
/* correction will only be applied to symmetrical glyphs (even if the */
/* glyph is not an m), so the potential for unwanted distortion is */
/* relatively low. */
/* We don't handle horizontal edges since we can't easily assure that */
/* the third (lowest) stem aligns with the base line; it might end up */
/* one pixel higher or lower. */
#if 0
{
FT_Int n_edges = edge_limit - edges;
if ( dim == AF_DIMENSION_HORZ && ( n_edges == 6 || n_edges == 12 ) )
{
AF_Edge edge1, edge2, edge3;
FT_Pos dist1, dist2, span, delta;
if ( n_edges == 6 )
{
edge1 = edges;
edge2 = edges + 2;
edge3 = edges + 4;
}
else
{
edge1 = edges + 1;
edge2 = edges + 5;
edge3 = edges + 9;
}
dist1 = edge2->opos - edge1->opos;
dist2 = edge3->opos - edge2->opos;
span = dist1 - dist2;
if ( span < 0 )
span = -span;
if ( span < 8 )
{
delta = edge3->pos - ( 2 * edge2->pos - edge1->pos );
edge3->pos -= delta;
if ( edge3->link )
edge3->link->pos -= delta;
/* move the serifs along with the stem */
if ( n_edges == 12 )
{
( edges + 8 )->pos -= delta;
( edges + 11 )->pos -= delta;
}
edge3->flags |= AF_EDGE_DONE;
if ( edge3->link )
edge3->link->flags |= AF_EDGE_DONE;
}
}
}
#endif
if ( has_serifs || !anchor )
{
/*
* now hint the remaining edges (serifs and single) in order
* to complete our processing
*/
for ( edge = edges; edge < edge_limit; edge++ )
{
FT_Pos delta;
if ( edge->flags & AF_EDGE_DONE )
continue;
delta = 1000;
if ( edge->serif )
{
delta = edge->serif->opos - edge->opos;
if ( delta < 0 )
delta = -delta;
}
if ( delta < 64 + 16 )
{
af_latin2_align_serif_edge( hints, edge->serif, edge );
FT_TRACE5(( "SERIF: edge %d (opos=%.2f) serif to %d (opos=%.2f)"
" aligned to (%.2f)\n",
edge-edges, edge->opos / 64.0,
edge->serif - edges, edge->serif->opos / 64.0,
edge->pos / 64.0 ));
}
else if ( !anchor )
{
FT_TRACE5(( "SERIF_ANCHOR: edge %d (opos=%.2f)"
" snapped to (%.2f)\n",
edge-edges, edge->opos / 64.0, edge->pos / 64.0 ));
edge->pos = FT_PIX_ROUND( edge->opos );
anchor = edge;
}
else
{
AF_Edge before, after;
for ( before = edge - 1; before >= edges; before-- )
if ( before->flags & AF_EDGE_DONE )
break;
for ( after = edge + 1; after < edge_limit; after++ )
if ( after->flags & AF_EDGE_DONE )
break;
if ( before >= edges && before < edge &&
after < edge_limit && after > edge )
{
if ( after->opos == before->opos )
edge->pos = before->pos;
else
edge->pos = before->pos +
FT_MulDiv( edge->opos - before->opos,
after->pos - before->pos,
after->opos - before->opos );
FT_TRACE5(( "SERIF_LINK1: edge %d (opos=%.2f) snapped to (%.2f)"
" from %d (opos=%.2f)\n",
edge-edges, edge->opos / 64.0, edge->pos / 64.0,
before - edges, before->opos / 64.0 ));
}
else
{
edge->pos = anchor->pos +
( ( edge->opos - anchor->opos + 16 ) & ~31 );
FT_TRACE5(( "SERIF_LINK2: edge %d (opos=%.2f)"
" snapped to (%.2f)\n",
edge-edges, edge->opos / 64.0, edge->pos / 64.0 ));
}
}
edge->flags |= AF_EDGE_DONE;
if ( edge > edges && edge->pos < edge[-1].pos )
edge->pos = edge[-1].pos;
if ( edge + 1 < edge_limit &&
edge[1].flags & AF_EDGE_DONE &&
edge->pos > edge[1].pos )
edge->pos = edge[1].pos;
}
}
}
static FT_Error
af_latin2_hints_apply( AF_GlyphHints hints,
FT_Outline* outline,
AF_LatinMetrics metrics )
{
FT_Error error;
int dim;
error = af_glyph_hints_reload( hints, outline );
if ( error )
goto Exit;
/* analyze glyph outline */
#ifdef AF_CONFIG_OPTION_USE_WARPER
if ( metrics->root.scaler.render_mode == FT_RENDER_MODE_LIGHT ||
AF_HINTS_DO_HORIZONTAL( hints ) )
#else
if ( AF_HINTS_DO_HORIZONTAL( hints ) )
#endif
{
error = af_latin2_hints_detect_features( hints, AF_DIMENSION_HORZ );
if ( error )
goto Exit;
}
if ( AF_HINTS_DO_VERTICAL( hints ) )
{
error = af_latin2_hints_detect_features( hints, AF_DIMENSION_VERT );
if ( error )
goto Exit;
af_latin2_hints_compute_blue_edges( hints, metrics );
}
/* grid-fit the outline */
for ( dim = 0; dim < AF_DIMENSION_MAX; dim++ )
{
#ifdef AF_CONFIG_OPTION_USE_WARPER
if ( ( dim == AF_DIMENSION_HORZ &&
metrics->root.scaler.render_mode == FT_RENDER_MODE_LIGHT ) )
{
AF_WarperRec warper;
FT_Fixed scale;
FT_Pos delta;
af_warper_compute( &warper, hints, dim, &scale, &delta );
af_glyph_hints_scale_dim( hints, dim, scale, delta );
continue;
}
#endif
if ( ( dim == AF_DIMENSION_HORZ && AF_HINTS_DO_HORIZONTAL( hints ) ) ||
( dim == AF_DIMENSION_VERT && AF_HINTS_DO_VERTICAL( hints ) ) )
{
af_latin2_hint_edges( hints, (AF_Dimension)dim );
af_glyph_hints_align_edge_points( hints, (AF_Dimension)dim );
af_glyph_hints_align_strong_points( hints, (AF_Dimension)dim );
af_glyph_hints_align_weak_points( hints, (AF_Dimension)dim );
}
}
af_glyph_hints_save( hints, outline );
Exit:
return error;
}
/*************************************************************************/
/*************************************************************************/
/***** *****/
/***** L A T I N S C R I P T C L A S S *****/
/***** *****/
/*************************************************************************/
/*************************************************************************/
AF_DEFINE_WRITING_SYSTEM_CLASS(
af_latin2_writing_system_class,
AF_WRITING_SYSTEM_LATIN2,
sizeof ( AF_LatinMetricsRec ),
(AF_WritingSystem_InitMetricsFunc) af_latin2_metrics_init,
(AF_WritingSystem_ScaleMetricsFunc)af_latin2_metrics_scale,
(AF_WritingSystem_DoneMetricsFunc) NULL,
(AF_WritingSystem_InitHintsFunc) af_latin2_hints_init,
(AF_WritingSystem_ApplyHintsFunc) af_latin2_hints_apply
)
/* END */
| YifuLiu/AliOS-Things | components/freetype/src/autofit/aflatin2.c | C | apache-2.0 | 71,485 |
/***************************************************************************/
/* */
/* aflatin2.h */
/* */
/* Auto-fitter hinting routines for latin writing system */
/* (specification). */
/* */
/* Copyright 2003-2007, 2012, 2013 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. */
/* */
/***************************************************************************/
#ifndef __AFLATIN2_H__
#define __AFLATIN2_H__
#include "afhints.h"
FT_BEGIN_HEADER
/* the `latin' writing system */
AF_DECLARE_WRITING_SYSTEM_CLASS( af_latin2_writing_system_class )
/* */
FT_END_HEADER
#endif /* __AFLATIN_H__ */
/* END */
| YifuLiu/AliOS-Things | components/freetype/src/autofit/aflatin2.h | C | apache-2.0 | 1,583 |
/***************************************************************************/
/* */
/* afloader.c */
/* */
/* Auto-fitter glyph loading routines (body). */
/* */
/* Copyright 2003-2009, 2011-2014 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. */
/* */
/***************************************************************************/
#include "afglobal.h"
#include "afloader.h"
#include "afhints.h"
#include "aferrors.h"
#include "afmodule.h"
#include "afpic.h"
/* Initialize glyph loader. */
FT_LOCAL_DEF( FT_Error )
af_loader_init( AF_Module module )
{
AF_Loader loader = module->loader;
FT_Memory memory = module->root.library->memory;
FT_ZERO( loader );
af_glyph_hints_init( &loader->hints, memory );
#ifdef FT_DEBUG_AUTOFIT
_af_debug_hints = &loader->hints;
#endif
return FT_GlyphLoader_New( memory, &loader->gloader );
}
/* Reset glyph loader and compute globals if necessary. */
FT_LOCAL_DEF( FT_Error )
af_loader_reset( AF_Module module,
FT_Face face )
{
FT_Error error = FT_Err_Ok;
AF_Loader loader = module->loader;
loader->face = face;
loader->globals = (AF_FaceGlobals)face->autohint.data;
FT_GlyphLoader_Rewind( loader->gloader );
if ( loader->globals == NULL )
{
error = af_face_globals_new( face, &loader->globals, module );
if ( !error )
{
face->autohint.data =
(FT_Pointer)loader->globals;
face->autohint.finalizer =
(FT_Generic_Finalizer)af_face_globals_free;
}
}
return error;
}
/* Finalize glyph loader. */
FT_LOCAL_DEF( void )
af_loader_done( AF_Module module )
{
AF_Loader loader = module->loader;
af_glyph_hints_done( &loader->hints );
loader->face = NULL;
loader->globals = NULL;
#ifdef FT_DEBUG_AUTOFIT
_af_debug_hints = NULL;
#endif
FT_GlyphLoader_Done( loader->gloader );
loader->gloader = NULL;
}
/* Load a single glyph component. This routine calls itself */
/* recursively, if necessary, and does the main work of */
/* `af_loader_load_glyph.' */
static FT_Error
af_loader_load_g( AF_Loader loader,
AF_Scaler scaler,
FT_UInt glyph_index,
FT_Int32 load_flags,
FT_UInt depth )
{
FT_Error error;
FT_Face face = loader->face;
FT_GlyphLoader gloader = loader->gloader;
AF_StyleMetrics metrics = loader->metrics;
AF_GlyphHints hints = &loader->hints;
FT_GlyphSlot slot = face->glyph;
FT_Slot_Internal internal = slot->internal;
FT_Int32 flags;
flags = load_flags | FT_LOAD_LINEAR_DESIGN;
error = FT_Load_Glyph( face, glyph_index, flags );
if ( error )
goto Exit;
loader->transformed = internal->glyph_transformed;
if ( loader->transformed )
{
FT_Matrix inverse;
loader->trans_matrix = internal->glyph_matrix;
loader->trans_delta = internal->glyph_delta;
inverse = loader->trans_matrix;
FT_Matrix_Invert( &inverse );
FT_Vector_Transform( &loader->trans_delta, &inverse );
}
switch ( slot->format )
{
case FT_GLYPH_FORMAT_OUTLINE:
/* translate the loaded glyph when an internal transform is needed */
if ( loader->transformed )
FT_Outline_Translate( &slot->outline,
loader->trans_delta.x,
loader->trans_delta.y );
/* copy the outline points in the loader's current */
/* extra points which are used to keep original glyph coordinates */
error = FT_GLYPHLOADER_CHECK_POINTS( gloader,
slot->outline.n_points + 4,
slot->outline.n_contours );
if ( error )
goto Exit;
FT_ARRAY_COPY( gloader->current.outline.points,
slot->outline.points,
slot->outline.n_points );
FT_ARRAY_COPY( gloader->current.outline.contours,
slot->outline.contours,
slot->outline.n_contours );
FT_ARRAY_COPY( gloader->current.outline.tags,
slot->outline.tags,
slot->outline.n_points );
gloader->current.outline.n_points = slot->outline.n_points;
gloader->current.outline.n_contours = slot->outline.n_contours;
/* compute original horizontal phantom points (and ignore */
/* vertical ones) */
loader->pp1.x = hints->x_delta;
loader->pp1.y = hints->y_delta;
loader->pp2.x = FT_MulFix( slot->metrics.horiAdvance,
hints->x_scale ) + hints->x_delta;
loader->pp2.y = hints->y_delta;
/* be sure to check for spacing glyphs */
if ( slot->outline.n_points == 0 )
goto Hint_Metrics;
/* now load the slot image into the auto-outline and run the */
/* automatic hinting process */
{
#ifdef FT_CONFIG_OPTION_PIC
AF_FaceGlobals globals = loader->globals;
#endif
AF_StyleClass style_class = metrics->style_class;
AF_WritingSystemClass writing_system_class =
AF_WRITING_SYSTEM_CLASSES_GET[style_class->writing_system];
if ( writing_system_class->style_hints_apply )
writing_system_class->style_hints_apply( hints,
&gloader->current.outline,
metrics );
}
/* we now need to adjust the metrics according to the change in */
/* width/positioning that occurred during the hinting process */
if ( scaler->render_mode != FT_RENDER_MODE_LIGHT )
{
FT_Pos old_rsb, old_lsb, new_lsb;
FT_Pos pp1x_uh, pp2x_uh;
AF_AxisHints axis = &hints->axis[AF_DIMENSION_HORZ];
AF_Edge edge1 = axis->edges; /* leftmost edge */
AF_Edge edge2 = edge1 +
axis->num_edges - 1; /* rightmost edge */
if ( axis->num_edges > 1 && AF_HINTS_DO_ADVANCE( hints ) )
{
old_rsb = loader->pp2.x - edge2->opos;
old_lsb = edge1->opos;
new_lsb = edge1->pos;
/* remember unhinted values to later account */
/* for rounding errors */
pp1x_uh = new_lsb - old_lsb;
pp2x_uh = edge2->pos + old_rsb;
/* prefer too much space over too little space */
/* for very small sizes */
if ( old_lsb < 24 )
pp1x_uh -= 8;
if ( old_rsb < 24 )
pp2x_uh += 8;
loader->pp1.x = FT_PIX_ROUND( pp1x_uh );
loader->pp2.x = FT_PIX_ROUND( pp2x_uh );
if ( loader->pp1.x >= new_lsb && old_lsb > 0 )
loader->pp1.x -= 64;
if ( loader->pp2.x <= edge2->pos && old_rsb > 0 )
loader->pp2.x += 64;
slot->lsb_delta = loader->pp1.x - pp1x_uh;
slot->rsb_delta = loader->pp2.x - pp2x_uh;
}
else
{
FT_Pos pp1x = loader->pp1.x;
FT_Pos pp2x = loader->pp2.x;
loader->pp1.x = FT_PIX_ROUND( pp1x );
loader->pp2.x = FT_PIX_ROUND( pp2x );
slot->lsb_delta = loader->pp1.x - pp1x;
slot->rsb_delta = loader->pp2.x - pp2x;
}
}
else
{
FT_Pos pp1x = loader->pp1.x;
FT_Pos pp2x = loader->pp2.x;
loader->pp1.x = FT_PIX_ROUND( pp1x + hints->xmin_delta );
loader->pp2.x = FT_PIX_ROUND( pp2x + hints->xmax_delta );
slot->lsb_delta = loader->pp1.x - pp1x;
slot->rsb_delta = loader->pp2.x - pp2x;
}
/* good, we simply add the glyph to our loader's base */
FT_GlyphLoader_Add( gloader );
break;
case FT_GLYPH_FORMAT_COMPOSITE:
{
FT_UInt nn, num_subglyphs = slot->num_subglyphs;
FT_UInt num_base_subgs, start_point;
FT_SubGlyph subglyph;
start_point = gloader->base.outline.n_points;
/* first of all, copy the subglyph descriptors in the glyph loader */
error = FT_GlyphLoader_CheckSubGlyphs( gloader, num_subglyphs );
if ( error )
goto Exit;
FT_ARRAY_COPY( gloader->current.subglyphs,
slot->subglyphs,
num_subglyphs );
gloader->current.num_subglyphs = num_subglyphs;
num_base_subgs = gloader->base.num_subglyphs;
/* now read each subglyph independently */
for ( nn = 0; nn < num_subglyphs; nn++ )
{
FT_Vector pp1, pp2;
FT_Pos x, y;
FT_UInt num_points, num_new_points, num_base_points;
/* gloader.current.subglyphs can change during glyph loading due */
/* to re-allocation -- we must recompute the current subglyph on */
/* each iteration */
subglyph = gloader->base.subglyphs + num_base_subgs + nn;
pp1 = loader->pp1;
pp2 = loader->pp2;
num_base_points = gloader->base.outline.n_points;
error = af_loader_load_g( loader, scaler, subglyph->index,
load_flags, depth + 1 );
if ( error )
goto Exit;
/* recompute subglyph pointer */
subglyph = gloader->base.subglyphs + num_base_subgs + nn;
if ( !( subglyph->flags & FT_SUBGLYPH_FLAG_USE_MY_METRICS ) )
{
loader->pp1 = pp1;
loader->pp2 = pp2;
}
num_points = gloader->base.outline.n_points;
num_new_points = num_points - num_base_points;
/* now perform the transformation required for this subglyph */
if ( subglyph->flags & ( FT_SUBGLYPH_FLAG_SCALE |
FT_SUBGLYPH_FLAG_XY_SCALE |
FT_SUBGLYPH_FLAG_2X2 ) )
{
FT_Vector* cur = gloader->base.outline.points +
num_base_points;
FT_Vector* limit = cur + num_new_points;
for ( ; cur < limit; cur++ )
FT_Vector_Transform( cur, &subglyph->transform );
}
/* apply offset */
if ( !( subglyph->flags & FT_SUBGLYPH_FLAG_ARGS_ARE_XY_VALUES ) )
{
FT_Int k = subglyph->arg1;
FT_UInt l = subglyph->arg2;
FT_Vector* p1;
FT_Vector* p2;
if ( start_point + k >= num_base_points ||
l >= (FT_UInt)num_new_points )
{
error = FT_THROW( Invalid_Composite );
goto Exit;
}
l += num_base_points;
/* for now, only use the current point coordinates; */
/* we eventually may consider another approach */
p1 = gloader->base.outline.points + start_point + k;
p2 = gloader->base.outline.points + start_point + l;
x = p1->x - p2->x;
y = p1->y - p2->y;
}
else
{
x = FT_MulFix( subglyph->arg1, hints->x_scale ) + hints->x_delta;
y = FT_MulFix( subglyph->arg2, hints->y_scale ) + hints->y_delta;
x = FT_PIX_ROUND( x );
y = FT_PIX_ROUND( y );
}
{
FT_Outline dummy = gloader->base.outline;
dummy.points += num_base_points;
dummy.n_points = (short)num_new_points;
FT_Outline_Translate( &dummy, x, y );
}
}
}
break;
default:
/* we don't support other formats (yet?) */
error = FT_THROW( Unimplemented_Feature );
}
Hint_Metrics:
if ( depth == 0 )
{
FT_BBox bbox;
FT_Vector vvector;
vvector.x = slot->metrics.vertBearingX - slot->metrics.horiBearingX;
vvector.y = slot->metrics.vertBearingY - slot->metrics.horiBearingY;
vvector.x = FT_MulFix( vvector.x, metrics->scaler.x_scale );
vvector.y = FT_MulFix( vvector.y, metrics->scaler.y_scale );
/* transform the hinted outline if needed */
if ( loader->transformed )
{
FT_Outline_Transform( &gloader->base.outline, &loader->trans_matrix );
FT_Vector_Transform( &vvector, &loader->trans_matrix );
}
#if 1
/* we must translate our final outline by -pp1.x and compute */
/* the new metrics */
if ( loader->pp1.x )
FT_Outline_Translate( &gloader->base.outline, -loader->pp1.x, 0 );
#endif
FT_Outline_Get_CBox( &gloader->base.outline, &bbox );
bbox.xMin = FT_PIX_FLOOR( bbox.xMin );
bbox.yMin = FT_PIX_FLOOR( bbox.yMin );
bbox.xMax = FT_PIX_CEIL( bbox.xMax );
bbox.yMax = FT_PIX_CEIL( bbox.yMax );
slot->metrics.width = bbox.xMax - bbox.xMin;
slot->metrics.height = bbox.yMax - bbox.yMin;
slot->metrics.horiBearingX = bbox.xMin;
slot->metrics.horiBearingY = bbox.yMax;
slot->metrics.vertBearingX = FT_PIX_FLOOR( bbox.xMin + vvector.x );
slot->metrics.vertBearingY = FT_PIX_FLOOR( bbox.yMax + vvector.y );
/* for mono-width fonts (like Andale, Courier, etc.) we need */
/* to keep the original rounded advance width; ditto for */
/* digits if all have the same advance width */
#if 0
if ( !FT_IS_FIXED_WIDTH( slot->face ) )
slot->metrics.horiAdvance = loader->pp2.x - loader->pp1.x;
else
slot->metrics.horiAdvance = FT_MulFix( slot->metrics.horiAdvance,
x_scale );
#else
if ( scaler->render_mode != FT_RENDER_MODE_LIGHT &&
( FT_IS_FIXED_WIDTH( slot->face ) ||
( af_face_globals_is_digit( loader->globals, glyph_index ) &&
metrics->digits_have_same_width ) ) )
{
slot->metrics.horiAdvance = FT_MulFix( slot->metrics.horiAdvance,
metrics->scaler.x_scale );
/* Set delta values to 0. Otherwise code that uses them is */
/* going to ruin the fixed advance width. */
slot->lsb_delta = 0;
slot->rsb_delta = 0;
}
else
{
/* non-spacing glyphs must stay as-is */
if ( slot->metrics.horiAdvance )
slot->metrics.horiAdvance = loader->pp2.x - loader->pp1.x;
}
#endif
slot->metrics.vertAdvance = FT_MulFix( slot->metrics.vertAdvance,
metrics->scaler.y_scale );
slot->metrics.horiAdvance = FT_PIX_ROUND( slot->metrics.horiAdvance );
slot->metrics.vertAdvance = FT_PIX_ROUND( slot->metrics.vertAdvance );
/* now copy outline into glyph slot */
FT_GlyphLoader_Rewind( internal->loader );
error = FT_GlyphLoader_CopyPoints( internal->loader, gloader );
if ( error )
goto Exit;
/* reassign all outline fields except flags to protect them */
slot->outline.n_contours = internal->loader->base.outline.n_contours;
slot->outline.n_points = internal->loader->base.outline.n_points;
slot->outline.points = internal->loader->base.outline.points;
slot->outline.tags = internal->loader->base.outline.tags;
slot->outline.contours = internal->loader->base.outline.contours;
slot->format = FT_GLYPH_FORMAT_OUTLINE;
}
Exit:
return error;
}
/* Load a glyph. */
FT_LOCAL_DEF( FT_Error )
af_loader_load_glyph( AF_Module module,
FT_Face face,
FT_UInt gindex,
FT_Int32 load_flags )
{
FT_Error error;
FT_Size size = face->size;
AF_Loader loader = module->loader;
AF_ScalerRec scaler;
if ( !size )
return FT_THROW( Invalid_Argument );
FT_ZERO( &scaler );
scaler.face = face;
scaler.x_scale = size->metrics.x_scale;
scaler.x_delta = 0; /* XXX: TODO: add support for sub-pixel hinting */
scaler.y_scale = size->metrics.y_scale;
scaler.y_delta = 0; /* XXX: TODO: add support for sub-pixel hinting */
scaler.render_mode = FT_LOAD_TARGET_MODE( load_flags );
scaler.flags = 0; /* XXX: fix this */
error = af_loader_reset( module, face );
if ( !error )
{
AF_StyleMetrics metrics;
FT_UInt options = AF_STYLE_NONE_DFLT;
#ifdef FT_OPTION_AUTOFIT2
/* XXX: undocumented hook to activate the latin2 writing system */
if ( load_flags & ( 1UL << 20 ) )
options = AF_STYLE_LTN2_DFLT;
#endif
error = af_face_globals_get_metrics( loader->globals, gindex,
options, &metrics );
if ( !error )
{
#ifdef FT_CONFIG_OPTION_PIC
AF_FaceGlobals globals = loader->globals;
#endif
AF_StyleClass style_class = metrics->style_class;
AF_WritingSystemClass writing_system_class =
AF_WRITING_SYSTEM_CLASSES_GET[style_class->writing_system];
loader->metrics = metrics;
if ( writing_system_class->style_metrics_scale )
writing_system_class->style_metrics_scale( metrics, &scaler );
else
metrics->scaler = scaler;
load_flags |= FT_LOAD_NO_SCALE | FT_LOAD_IGNORE_TRANSFORM;
load_flags &= ~FT_LOAD_RENDER;
if ( writing_system_class->style_hints_init )
{
error = writing_system_class->style_hints_init( &loader->hints,
metrics );
if ( error )
goto Exit;
}
error = af_loader_load_g( loader, &scaler, gindex, load_flags, 0 );
}
}
Exit:
return error;
}
/* END */
| YifuLiu/AliOS-Things | components/freetype/src/autofit/afloader.c | C | apache-2.0 | 19,179 |
/***************************************************************************/
/* */
/* afloader.h */
/* */
/* Auto-fitter glyph loading routines (specification). */
/* */
/* Copyright 2003-2005, 2011-2013 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. */
/* */
/***************************************************************************/
#ifndef __AFLOADER_H__
#define __AFLOADER_H__
#include "afhints.h"
#include "afglobal.h"
FT_BEGIN_HEADER
typedef struct AF_ModuleRec_* AF_Module;
/*
* The autofitter module's (global) data structure to communicate with
* actual fonts. If necessary, `local' data like the current face, the
* current face's auto-hint data, or the current glyph's parameters
* relevant to auto-hinting are `swapped in'. Cf. functions like
* `af_loader_reset' and `af_loader_load_g'.
*/
typedef struct AF_LoaderRec_
{
/* current face data */
FT_Face face;
AF_FaceGlobals globals;
/* current glyph data */
FT_GlyphLoader gloader;
AF_GlyphHintsRec hints;
AF_StyleMetrics metrics;
FT_Bool transformed;
FT_Matrix trans_matrix;
FT_Vector trans_delta;
FT_Vector pp1;
FT_Vector pp2;
/* we don't handle vertical phantom points */
} AF_LoaderRec, *AF_Loader;
FT_LOCAL( FT_Error )
af_loader_init( AF_Module module );
FT_LOCAL( FT_Error )
af_loader_reset( AF_Module module,
FT_Face face );
FT_LOCAL( void )
af_loader_done( AF_Module module );
FT_LOCAL( FT_Error )
af_loader_load_glyph( AF_Module module,
FT_Face face,
FT_UInt gindex,
FT_Int32 load_flags );
/* */
FT_END_HEADER
#endif /* __AFLOADER_H__ */
/* END */
| YifuLiu/AliOS-Things | components/freetype/src/autofit/afloader.h | C | apache-2.0 | 2,728 |
/***************************************************************************/
/* */
/* afmodule.c */
/* */
/* Auto-fitter module implementation (body). */
/* */
/* Copyright 2003-2006, 2009, 2011-2014 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. */
/* */
/***************************************************************************/
#include "afglobal.h"
#include "afmodule.h"
#include "afloader.h"
#include "aferrors.h"
#include "afpic.h"
#ifdef FT_DEBUG_AUTOFIT
int _af_debug_disable_horz_hints;
int _af_debug_disable_vert_hints;
int _af_debug_disable_blue_hints;
void* _af_debug_hints;
#endif
#include FT_INTERNAL_OBJECTS_H
#include FT_INTERNAL_DEBUG_H
#include FT_AUTOHINTER_H
#include FT_SERVICE_PROPERTIES_H
/*************************************************************************/
/* */
/* The macro FT_COMPONENT is used in trace mode. It is an implicit */
/* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */
/* messages during execution. */
/* */
#undef FT_COMPONENT
#define FT_COMPONENT trace_afmodule
static FT_Error
af_property_get_face_globals( FT_Face face,
AF_FaceGlobals* aglobals,
AF_Module module )
{
FT_Error error = FT_Err_Ok;
AF_FaceGlobals globals;
if ( !face )
return FT_THROW( Invalid_Argument );
globals = (AF_FaceGlobals)face->autohint.data;
if ( !globals )
{
/* trigger computation of the global style data */
/* in case it hasn't been done yet */
error = af_face_globals_new( face, &globals, module );
if ( !error )
{
face->autohint.data =
(FT_Pointer)globals;
face->autohint.finalizer =
(FT_Generic_Finalizer)af_face_globals_free;
}
}
if ( !error )
*aglobals = globals;
return error;
}
static FT_Error
af_property_set( FT_Module ft_module,
const char* property_name,
const void* value )
{
FT_Error error = FT_Err_Ok;
AF_Module module = (AF_Module)ft_module;
if ( !ft_strcmp( property_name, "fallback-script" ) )
{
FT_UInt* fallback_script = (FT_UInt*)value;
FT_UInt ss;
/* We translate the fallback script to a fallback style that uses */
/* `fallback-script' as its script and `AF_COVERAGE_NONE' as its */
/* coverage value. */
for ( ss = 0; AF_STYLE_CLASSES_GET[ss]; ss++ )
{
AF_StyleClass style_class = AF_STYLE_CLASSES_GET[ss];
if ( style_class->script == *fallback_script &&
style_class->coverage == AF_COVERAGE_DEFAULT )
{
module->fallback_style = ss;
break;
}
}
if ( !AF_STYLE_CLASSES_GET[ss] )
{
FT_TRACE0(( "af_property_set: Invalid value %d for property `%s'\n",
fallback_script, property_name ));
return FT_THROW( Invalid_Argument );
}
return error;
}
else if ( !ft_strcmp( property_name, "default-script" ) )
{
FT_UInt* default_script = (FT_UInt*)value;
module->default_script = *default_script;
return error;
}
else if ( !ft_strcmp( property_name, "increase-x-height" ) )
{
FT_Prop_IncreaseXHeight* prop = (FT_Prop_IncreaseXHeight*)value;
AF_FaceGlobals globals;
error = af_property_get_face_globals( prop->face, &globals, module );
if ( !error )
globals->increase_x_height = prop->limit;
return error;
}
FT_TRACE0(( "af_property_set: missing property `%s'\n",
property_name ));
return FT_THROW( Missing_Property );
}
static FT_Error
af_property_get( FT_Module ft_module,
const char* property_name,
void* value )
{
FT_Error error = FT_Err_Ok;
AF_Module module = (AF_Module)ft_module;
FT_UInt fallback_style = module->fallback_style;
FT_UInt default_script = module->default_script;
if ( !ft_strcmp( property_name, "glyph-to-script-map" ) )
{
FT_Prop_GlyphToScriptMap* prop = (FT_Prop_GlyphToScriptMap*)value;
AF_FaceGlobals globals;
error = af_property_get_face_globals( prop->face, &globals, module );
if ( !error )
prop->map = globals->glyph_styles;
return error;
}
else if ( !ft_strcmp( property_name, "fallback-script" ) )
{
FT_UInt* val = (FT_UInt*)value;
AF_StyleClass style_class = AF_STYLE_CLASSES_GET[fallback_style];
*val = style_class->script;
return error;
}
else if ( !ft_strcmp( property_name, "default-script" ) )
{
FT_UInt* val = (FT_UInt*)value;
*val = default_script;
return error;
}
else if ( !ft_strcmp( property_name, "increase-x-height" ) )
{
FT_Prop_IncreaseXHeight* prop = (FT_Prop_IncreaseXHeight*)value;
AF_FaceGlobals globals;
error = af_property_get_face_globals( prop->face, &globals, module );
if ( !error )
prop->limit = globals->increase_x_height;
return error;
}
FT_TRACE0(( "af_property_get: missing property `%s'\n",
property_name ));
return FT_THROW( Missing_Property );
}
FT_DEFINE_SERVICE_PROPERTIESREC(
af_service_properties,
(FT_Properties_SetFunc)af_property_set,
(FT_Properties_GetFunc)af_property_get )
FT_DEFINE_SERVICEDESCREC1(
af_services,
FT_SERVICE_ID_PROPERTIES, &AF_SERVICE_PROPERTIES_GET )
FT_CALLBACK_DEF( FT_Module_Interface )
af_get_interface( FT_Module module,
const char* module_interface )
{
/* AF_SERVICES_GET derefers `library' in PIC mode */
#ifdef FT_CONFIG_OPTION_PIC
FT_Library library;
if ( !module )
return NULL;
library = module->library;
if ( !library )
return NULL;
#else
FT_UNUSED( module );
#endif
return ft_service_list_lookup( AF_SERVICES_GET, module_interface );
}
FT_CALLBACK_DEF( FT_Error )
af_autofitter_init( FT_Module ft_module ) /* AF_Module */
{
AF_Module module = (AF_Module)ft_module;
module->fallback_style = AF_STYLE_FALLBACK;
module->default_script = AF_SCRIPT_DEFAULT;
return af_loader_init( module );
}
FT_CALLBACK_DEF( void )
af_autofitter_done( FT_Module ft_module ) /* AF_Module */
{
AF_Module module = (AF_Module)ft_module;
af_loader_done( module );
}
FT_CALLBACK_DEF( FT_Error )
af_autofitter_load_glyph( AF_Module module,
FT_GlyphSlot slot,
FT_Size size,
FT_UInt glyph_index,
FT_Int32 load_flags )
{
FT_UNUSED( size );
return af_loader_load_glyph( module, slot->face,
glyph_index, load_flags );
}
FT_DEFINE_AUTOHINTER_INTERFACE(
af_autofitter_interface,
NULL, /* reset_face */
NULL, /* get_global_hints */
NULL, /* done_global_hints */
(FT_AutoHinter_GlyphLoadFunc)af_autofitter_load_glyph ) /* load_glyph */
FT_DEFINE_MODULE(
autofit_module_class,
FT_MODULE_HINTER,
sizeof ( AF_ModuleRec ),
"autofitter",
0x10000L, /* version 1.0 of the autofitter */
0x20000L, /* requires FreeType 2.0 or above */
(const void*)&AF_INTERFACE_GET,
(FT_Module_Constructor)af_autofitter_init,
(FT_Module_Destructor) af_autofitter_done,
(FT_Module_Requester) af_get_interface )
/* END */
| YifuLiu/AliOS-Things | components/freetype/src/autofit/afmodule.c | C | apache-2.0 | 8,958 |
/***************************************************************************/
/* */
/* afmodule.h */
/* */
/* Auto-fitter module implementation (specification). */
/* */
/* Copyright 2003-2005, 2009, 2012, 2013 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. */
/* */
/***************************************************************************/
#ifndef __AFMODULE_H__
#define __AFMODULE_H__
#include <ft2build.h>
#include FT_INTERNAL_OBJECTS_H
#include FT_MODULE_H
#include "afloader.h"
FT_BEGIN_HEADER
/*
* This is the `extended' FT_Module structure which holds the
* autofitter's global data. Right before hinting a glyph, the data
* specific to the glyph's face (blue zones, stem widths, etc.) are
* loaded into `loader' (see function `af_loader_reset').
*/
typedef struct AF_ModuleRec_
{
FT_ModuleRec root;
FT_UInt fallback_style;
FT_UInt default_script;
AF_LoaderRec loader[1];
} AF_ModuleRec;
FT_DECLARE_MODULE(autofit_module_class)
FT_END_HEADER
#endif /* __AFMODULE_H__ */
/* END */
| YifuLiu/AliOS-Things | components/freetype/src/autofit/afmodule.h | C | apache-2.0 | 1,972 |
/***************************************************************************/
/* */
/* afpic.c */
/* */
/* The FreeType position independent code services for autofit module. */
/* */
/* Copyright 2009-2014 by */
/* Oran Agra and Mickey Gabel. */
/* */
/* 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. */
/* */
/***************************************************************************/
#include <ft2build.h>
#include FT_FREETYPE_H
#include FT_INTERNAL_OBJECTS_H
#include "afpic.h"
#include "afglobal.h"
#include "aferrors.h"
#ifdef FT_CONFIG_OPTION_PIC
/* forward declaration of PIC init functions from afmodule.c */
FT_Error
FT_Create_Class_af_services( FT_Library library,
FT_ServiceDescRec** output_class );
void
FT_Destroy_Class_af_services( FT_Library library,
FT_ServiceDescRec* clazz );
void
FT_Init_Class_af_service_properties( FT_Service_PropertiesRec* clazz );
void FT_Init_Class_af_autofitter_interface(
FT_Library library,
FT_AutoHinter_InterfaceRec* clazz );
/* forward declaration of PIC init functions from writing system classes */
#undef WRITING_SYSTEM
#define WRITING_SYSTEM( ws, WS ) /* empty */
#include "afwrtsys.h"
void
autofit_module_class_pic_free( FT_Library library )
{
FT_PIC_Container* pic_container = &library->pic_container;
FT_Memory memory = library->memory;
if ( pic_container->autofit )
{
AFModulePIC* container = (AFModulePIC*)pic_container->autofit;
if ( container->af_services )
FT_Destroy_Class_af_services( library,
container->af_services );
container->af_services = NULL;
FT_FREE( container );
pic_container->autofit = NULL;
}
}
FT_Error
autofit_module_class_pic_init( FT_Library library )
{
FT_PIC_Container* pic_container = &library->pic_container;
FT_UInt ss;
FT_Error error = FT_Err_Ok;
AFModulePIC* container = NULL;
FT_Memory memory = library->memory;
/* allocate pointer, clear and set global container pointer */
if ( FT_ALLOC ( container, sizeof ( *container ) ) )
return error;
FT_MEM_SET( container, 0, sizeof ( *container ) );
pic_container->autofit = container;
/* initialize pointer table - */
/* this is how the module usually expects this data */
error = FT_Create_Class_af_services( library,
&container->af_services );
if ( error )
goto Exit;
FT_Init_Class_af_service_properties( &container->af_service_properties );
for ( ss = 0; ss < AF_WRITING_SYSTEM_MAX; ss++ )
container->af_writing_system_classes[ss] =
&container->af_writing_system_classes_rec[ss];
container->af_writing_system_classes[AF_WRITING_SYSTEM_MAX] = NULL;
for ( ss = 0; ss < AF_SCRIPT_MAX; ss++ )
container->af_script_classes[ss] =
&container->af_script_classes_rec[ss];
container->af_script_classes[AF_SCRIPT_MAX] = NULL;
for ( ss = 0; ss < AF_STYLE_MAX; ss++ )
container->af_style_classes[ss] =
&container->af_style_classes_rec[ss];
container->af_style_classes[AF_STYLE_MAX] = NULL;
#undef WRITING_SYSTEM
#define WRITING_SYSTEM( ws, WS ) \
FT_Init_Class_af_ ## ws ## _writing_system_class( \
&container->af_writing_system_classes_rec[ss++] );
ss = 0;
#include "afwrtsys.h"
#undef SCRIPT
#define SCRIPT( s, S, d, h, sc1, sc2, sc3 ) \
FT_Init_Class_af_ ## s ## _script_class( \
&container->af_script_classes_rec[ss++] );
ss = 0;
#include "afscript.h"
#undef STYLE
#define STYLE( s, S, d, ws, sc, bss, c ) \
FT_Init_Class_af_ ## s ## _style_class( \
&container->af_style_classes_rec[ss++] );
ss = 0;
#include "afstyles.h"
FT_Init_Class_af_autofitter_interface(
library, &container->af_autofitter_interface );
Exit:
if ( error )
autofit_module_class_pic_free( library );
return error;
}
#endif /* FT_CONFIG_OPTION_PIC */
/* END */
| YifuLiu/AliOS-Things | components/freetype/src/autofit/afpic.c | C | apache-2.0 | 5,125 |
/***************************************************************************/
/* */
/* afpic.h */
/* */
/* The FreeType position independent code services for autofit module. */
/* */
/* Copyright 2009, 2011-2013 by */
/* Oran Agra and Mickey Gabel. */
/* */
/* 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. */
/* */
/***************************************************************************/
#ifndef __AFPIC_H__
#define __AFPIC_H__
FT_BEGIN_HEADER
#include FT_INTERNAL_PIC_H
#ifndef FT_CONFIG_OPTION_PIC
#define AF_SERVICES_GET af_services
#define AF_SERVICE_PROPERTIES_GET af_service_properties
#define AF_WRITING_SYSTEM_CLASSES_GET af_writing_system_classes
#define AF_SCRIPT_CLASSES_GET af_script_classes
#define AF_STYLE_CLASSES_GET af_style_classes
#define AF_INTERFACE_GET af_autofitter_interface
#else /* FT_CONFIG_OPTION_PIC */
/* some include files required for members of AFModulePIC */
#include FT_SERVICE_PROPERTIES_H
#include "aftypes.h"
typedef struct AFModulePIC_
{
FT_ServiceDescRec* af_services;
FT_Service_PropertiesRec af_service_properties;
AF_WritingSystemClass af_writing_system_classes
[AF_WRITING_SYSTEM_MAX + 1];
AF_WritingSystemClassRec af_writing_system_classes_rec
[AF_WRITING_SYSTEM_MAX];
AF_ScriptClass af_script_classes
[AF_SCRIPT_MAX + 1];
AF_ScriptClassRec af_script_classes_rec
[AF_SCRIPT_MAX];
AF_StyleClass af_style_classes
[AF_STYLE_MAX + 1];
AF_StyleClassRec af_style_classes_rec
[AF_STYLE_MAX];
FT_AutoHinter_InterfaceRec af_autofitter_interface;
} AFModulePIC;
#define GET_PIC( lib ) \
( (AFModulePIC*)((lib)->pic_container.autofit) )
#define AF_SERVICES_GET \
( GET_PIC( library )->af_services )
#define AF_SERVICE_PROPERTIES_GET \
( GET_PIC( library )->af_service_properties )
#define AF_WRITING_SYSTEM_CLASSES_GET \
( GET_PIC( FT_FACE_LIBRARY( globals->face ) )->af_writing_system_classes )
#define AF_SCRIPT_CLASSES_GET \
( GET_PIC( FT_FACE_LIBRARY( globals->face ) )->af_script_classes )
#define AF_STYLE_CLASSES_GET \
( GET_PIC( FT_FACE_LIBRARY( globals->face ) )->af_style_classes )
#define AF_INTERFACE_GET \
( GET_PIC( library )->af_autofitter_interface )
/* see afpic.c for the implementation */
void
autofit_module_class_pic_free( FT_Library library );
FT_Error
autofit_module_class_pic_init( FT_Library library );
#endif /* FT_CONFIG_OPTION_PIC */
/* */
FT_END_HEADER
#endif /* __AFPIC_H__ */
/* END */
| YifuLiu/AliOS-Things | components/freetype/src/autofit/afpic.h | C | apache-2.0 | 3,706 |
/***************************************************************************/
/* */
/* afranges.c */
/* */
/* Auto-fitter Unicode script ranges (body). */
/* */
/* Copyright 2013, 2014 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. */
/* */
/***************************************************************************/
#include "afranges.h"
const AF_Script_UniRangeRec af_cyrl_uniranges[] =
{
AF_UNIRANGE_REC( 0x0400UL, 0x04FFUL ), /* Cyrillic */
AF_UNIRANGE_REC( 0x0500UL, 0x052FUL ), /* Cyrillic Supplement */
AF_UNIRANGE_REC( 0x2DE0UL, 0x2DFFUL ), /* Cyrillic Extended-A */
AF_UNIRANGE_REC( 0xA640UL, 0xA69FUL ), /* Cyrillic Extended-B */
AF_UNIRANGE_REC( 0UL, 0UL )
};
const AF_Script_UniRangeRec af_grek_uniranges[] =
{
AF_UNIRANGE_REC( 0x0370UL, 0x03FFUL ), /* Greek and Coptic */
AF_UNIRANGE_REC( 0x1F00UL, 0x1FFFUL ), /* Greek Extended */
AF_UNIRANGE_REC( 0UL, 0UL )
};
const AF_Script_UniRangeRec af_hebr_uniranges[] =
{
AF_UNIRANGE_REC( 0x0590UL, 0x05FFUL ), /* Hebrew */
AF_UNIRANGE_REC( 0xFB1DUL, 0xFB4FUL ), /* Alphab. Present. Forms (Hebrew) */
AF_UNIRANGE_REC( 0UL, 0UL )
};
const AF_Script_UniRangeRec af_latn_uniranges[] =
{
AF_UNIRANGE_REC( 0x0020UL, 0x007FUL ), /* Basic Latin (no control chars) */
AF_UNIRANGE_REC( 0x00A0UL, 0x00FFUL ), /* Latin-1 Supplement (no control chars) */
AF_UNIRANGE_REC( 0x0100UL, 0x017FUL ), /* Latin Extended-A */
AF_UNIRANGE_REC( 0x0180UL, 0x024FUL ), /* Latin Extended-B */
AF_UNIRANGE_REC( 0x0250UL, 0x02AFUL ), /* IPA Extensions */
AF_UNIRANGE_REC( 0x02B0UL, 0x02FFUL ), /* Spacing Modifier Letters */
AF_UNIRANGE_REC( 0x0300UL, 0x036FUL ), /* Combining Diacritical Marks */
AF_UNIRANGE_REC( 0x1D00UL, 0x1D7FUL ), /* Phonetic Extensions */
AF_UNIRANGE_REC( 0x1D80UL, 0x1DBFUL ), /* Phonetic Extensions Supplement */
AF_UNIRANGE_REC( 0x1DC0UL, 0x1DFFUL ), /* Combining Diacritical Marks Supplement */
AF_UNIRANGE_REC( 0x1E00UL, 0x1EFFUL ), /* Latin Extended Additional */
AF_UNIRANGE_REC( 0x2000UL, 0x206FUL ), /* General Punctuation */
AF_UNIRANGE_REC( 0x2070UL, 0x209FUL ), /* Superscripts and Subscripts */
AF_UNIRANGE_REC( 0x20A0UL, 0x20CFUL ), /* Currency Symbols */
AF_UNIRANGE_REC( 0x2150UL, 0x218FUL ), /* Number Forms */
AF_UNIRANGE_REC( 0x2460UL, 0x24FFUL ), /* Enclosed Alphanumerics */
AF_UNIRANGE_REC( 0x2C60UL, 0x2C7FUL ), /* Latin Extended-C */
AF_UNIRANGE_REC( 0x2E00UL, 0x2E7FUL ), /* Supplemental Punctuation */
AF_UNIRANGE_REC( 0xA720UL, 0xA7FFUL ), /* Latin Extended-D */
AF_UNIRANGE_REC( 0xFB00UL, 0xFB06UL ), /* Alphab. Present. Forms (Latin Ligs) */
AF_UNIRANGE_REC( 0x1D400UL, 0x1D7FFUL ), /* Mathematical Alphanumeric Symbols */
AF_UNIRANGE_REC( 0x1F100UL, 0x1F1FFUL ), /* Enclosed Alphanumeric Supplement */
AF_UNIRANGE_REC( 0UL, 0UL )
};
const AF_Script_UniRangeRec af_none_uniranges[] =
{
AF_UNIRANGE_REC( 0UL, 0UL )
};
#ifdef AF_CONFIG_OPTION_INDIC
const AF_Script_UniRangeRec af_beng_uniranges[] =
{
AF_UNIRANGE_REC( 0x0980UL, 0x09FFUL ), /* Bengali */
AF_UNIRANGE_REC( 0UL, 0UL )
};
const AF_Script_UniRangeRec af_deva_uniranges[] =
{
AF_UNIRANGE_REC( 0x0900UL, 0x097FUL ), /* Devanagari */
AF_UNIRANGE_REC( 0UL, 0UL )
};
const AF_Script_UniRangeRec af_gujr_uniranges[] =
{
AF_UNIRANGE_REC( 0x0A80UL, 0x0AFFUL ), /* Gujarati */
AF_UNIRANGE_REC( 0UL, 0UL )
};
const AF_Script_UniRangeRec af_guru_uniranges[] =
{
AF_UNIRANGE_REC( 0x0A00UL, 0x0A7FUL ), /* Gurmukhi */
AF_UNIRANGE_REC( 0UL, 0UL )
};
const AF_Script_UniRangeRec af_knda_uniranges[] =
{
AF_UNIRANGE_REC( 0x0C80UL, 0x0CFFUL ), /* Kannada */
AF_UNIRANGE_REC( 0UL, 0UL )
};
const AF_Script_UniRangeRec af_limb_uniranges[] =
{
AF_UNIRANGE_REC( 0x1900UL, 0x194FUL ), /* Limbu */
AF_UNIRANGE_REC( 0UL, 0UL )
};
const AF_Script_UniRangeRec af_mlym_uniranges[] =
{
AF_UNIRANGE_REC( 0x0D00UL, 0x0D7FUL ), /* Malayalam */
AF_UNIRANGE_REC( 0UL, 0UL )
};
const AF_Script_UniRangeRec af_orya_uniranges[] =
{
AF_UNIRANGE_REC( 0x0B00UL, 0x0B7FUL ), /* Oriya */
AF_UNIRANGE_REC( 0UL, 0UL )
};
const AF_Script_UniRangeRec af_sinh_uniranges[] =
{
AF_UNIRANGE_REC( 0x0D80UL, 0x0DFFUL ), /* Sinhala */
AF_UNIRANGE_REC( 0UL, 0UL )
};
const AF_Script_UniRangeRec af_sund_uniranges[] =
{
AF_UNIRANGE_REC( 0x1B80UL, 0x1BBFUL ), /* Sundanese */
AF_UNIRANGE_REC( 0UL, 0UL )
};
const AF_Script_UniRangeRec af_sylo_uniranges[] =
{
AF_UNIRANGE_REC( 0xA800UL, 0xA82FUL ), /* Syloti Nagri */
AF_UNIRANGE_REC( 0UL, 0UL )
};
const AF_Script_UniRangeRec af_taml_uniranges[] =
{
AF_UNIRANGE_REC( 0x0B80UL, 0x0BFFUL ), /* Tamil */
AF_UNIRANGE_REC( 0UL, 0UL )
};
const AF_Script_UniRangeRec af_telu_uniranges[] =
{
AF_UNIRANGE_REC( 0x0C00UL, 0x0C7FUL ), /* Telugu */
AF_UNIRANGE_REC( 0UL, 0UL )
};
const AF_Script_UniRangeRec af_tibt_uniranges[] =
{
AF_UNIRANGE_REC( 0x0F00UL, 0x0FFFUL ), /* Tibetan */
AF_UNIRANGE_REC( 0UL, 0UL )
};
#endif /* !AF_CONFIG_OPTION_INDIC */
#ifdef AF_CONFIG_OPTION_CJK
/* this corresponds to Unicode 6.0 */
const AF_Script_UniRangeRec af_hani_uniranges[] =
{
AF_UNIRANGE_REC( 0x1100UL, 0x11FFUL ), /* Hangul Jamo */
AF_UNIRANGE_REC( 0x2E80UL, 0x2EFFUL ), /* CJK Radicals Supplement */
AF_UNIRANGE_REC( 0x2F00UL, 0x2FDFUL ), /* Kangxi Radicals */
AF_UNIRANGE_REC( 0x2FF0UL, 0x2FFFUL ), /* Ideographic Description Characters */
AF_UNIRANGE_REC( 0x3000UL, 0x303FUL ), /* CJK Symbols and Punctuation */
AF_UNIRANGE_REC( 0x3040UL, 0x309FUL ), /* Hiragana */
AF_UNIRANGE_REC( 0x30A0UL, 0x30FFUL ), /* Katakana */
AF_UNIRANGE_REC( 0x3100UL, 0x312FUL ), /* Bopomofo */
AF_UNIRANGE_REC( 0x3130UL, 0x318FUL ), /* Hangul Compatibility Jamo */
AF_UNIRANGE_REC( 0x3190UL, 0x319FUL ), /* Kanbun */
AF_UNIRANGE_REC( 0x31A0UL, 0x31BFUL ), /* Bopomofo Extended */
AF_UNIRANGE_REC( 0x31C0UL, 0x31EFUL ), /* CJK Strokes */
AF_UNIRANGE_REC( 0x31F0UL, 0x31FFUL ), /* Katakana Phonetic Extensions */
AF_UNIRANGE_REC( 0x3200UL, 0x32FFUL ), /* Enclosed CJK Letters and Months */
AF_UNIRANGE_REC( 0x3300UL, 0x33FFUL ), /* CJK Compatibility */
AF_UNIRANGE_REC( 0x3400UL, 0x4DBFUL ), /* CJK Unified Ideographs Extension A */
AF_UNIRANGE_REC( 0x4DC0UL, 0x4DFFUL ), /* Yijing Hexagram Symbols */
AF_UNIRANGE_REC( 0x4E00UL, 0x9FFFUL ), /* CJK Unified Ideographs */
AF_UNIRANGE_REC( 0xA960UL, 0xA97FUL ), /* Hangul Jamo Extended-A */
AF_UNIRANGE_REC( 0xAC00UL, 0xD7AFUL ), /* Hangul Syllables */
AF_UNIRANGE_REC( 0xD7B0UL, 0xD7FFUL ), /* Hangul Jamo Extended-B */
AF_UNIRANGE_REC( 0xF900UL, 0xFAFFUL ), /* CJK Compatibility Ideographs */
AF_UNIRANGE_REC( 0xFE10UL, 0xFE1FUL ), /* Vertical forms */
AF_UNIRANGE_REC( 0xFE30UL, 0xFE4FUL ), /* CJK Compatibility Forms */
AF_UNIRANGE_REC( 0xFF00UL, 0xFFEFUL ), /* Halfwidth and Fullwidth Forms */
AF_UNIRANGE_REC( 0x1B000UL, 0x1B0FFUL ), /* Kana Supplement */
AF_UNIRANGE_REC( 0x1D300UL, 0x1D35FUL ), /* Tai Xuan Hing Symbols */
AF_UNIRANGE_REC( 0x1F200UL, 0x1F2FFUL ), /* Enclosed Ideographic Supplement */
AF_UNIRANGE_REC( 0x20000UL, 0x2A6DFUL ), /* CJK Unified Ideographs Extension B */
AF_UNIRANGE_REC( 0x2A700UL, 0x2B73FUL ), /* CJK Unified Ideographs Extension C */
AF_UNIRANGE_REC( 0x2B740UL, 0x2B81FUL ), /* CJK Unified Ideographs Extension D */
AF_UNIRANGE_REC( 0x2F800UL, 0x2FA1FUL ), /* CJK Compatibility Ideographs Supplement */
AF_UNIRANGE_REC( 0UL, 0UL )
};
#endif /* !AF_CONFIG_OPTION_CJK */
/* END */
| YifuLiu/AliOS-Things | components/freetype/src/autofit/afranges.c | C | apache-2.0 | 9,628 |
/***************************************************************************/
/* */
/* afranges.h */
/* */
/* Auto-fitter Unicode script ranges (specification). */
/* */
/* Copyright 2013, 2014 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. */
/* */
/***************************************************************************/
#ifndef __AFRANGES_H__
#define __AFRANGES_H__
#include "aftypes.h"
FT_BEGIN_HEADER
#undef SCRIPT
#define SCRIPT( s, S, d, h, sc1, sc2, sc3 ) \
extern const AF_Script_UniRangeRec af_ ## s ## _uniranges[];
#include "afscript.h"
/* */
FT_END_HEADER
#endif /* __AFRANGES_H__ */
/* END */
| YifuLiu/AliOS-Things | components/freetype/src/autofit/afranges.h | C | apache-2.0 | 1,586 |
/***************************************************************************/
/* */
/* afscript.h */
/* */
/* Auto-fitter scripts (specification only). */
/* */
/* Copyright 2013, 2014 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. */
/* */
/***************************************************************************/
/* The following part can be included multiple times. */
/* Define `SCRIPT' as needed. */
/* Add new scripts here. The first and second arguments are the */
/* script name in lowercase and uppercase, respectively, followed */
/* by a description string. Then comes the corresponding HarfBuzz */
/* script name tag, followed by a string of standard characters (to */
/* derive the standard width and height of stems). */
SCRIPT( cyrl, CYRL,
"Cyrillic",
HB_SCRIPT_CYRILLIC,
0x43E, 0x41E, 0x0 ) /* оО */
SCRIPT( grek, GREK,
"Greek",
HB_SCRIPT_GREEK,
0x3BF, 0x39F, 0x0 ) /* οΟ */
SCRIPT( hebr, HEBR,
"Hebrew",
HB_SCRIPT_HEBREW,
0x5DD, 0x0, 0x0 ) /* ם */
SCRIPT( latn, LATN,
"Latin",
HB_SCRIPT_LATIN,
'o', 'O', '0' )
SCRIPT( none, NONE,
"no script",
HB_SCRIPT_INVALID,
0x0, 0x0, 0x0 )
#ifdef AF_CONFIG_OPTION_INDIC
SCRIPT( beng, BENG,
"Bengali",
HB_SCRIPT_BENGALI,
'o', 0x0, 0x0 ) /* XXX */
SCRIPT( deva, DEVA,
"Devanagari",
HB_SCRIPT_DEVANAGARI,
'o', 0x0, 0x0 ) /* XXX */
SCRIPT( gujr, GUJR,
"Gujarati",
HB_SCRIPT_GUJARATI,
'o', 0x0, 0x0 ) /* XXX */
SCRIPT( guru, GURU,
"Gurmukhi",
HB_SCRIPT_GURMUKHI,
'o', 0x0, 0x0 ) /* XXX */
SCRIPT( knda, KNDA,
"Kannada",
HB_SCRIPT_KANNADA,
'o', 0x0, 0x0 ) /* XXX */
SCRIPT( limb, LIMB,
"Limbu",
HB_SCRIPT_LIMBU,
'o', 0x0, 0x0 ) /* XXX */
SCRIPT( mlym, MLYM,
"Malayalam",
HB_SCRIPT_MALAYALAM,
'o', 0x0, 0x0 ) /* XXX */
SCRIPT( orya, ORYA,
"Oriya",
HB_SCRIPT_ORIYA,
'o', 0x0, 0x0 ) /* XXX */
SCRIPT( sinh, SINH,
"Sinhala",
HB_SCRIPT_SINHALA,
'o', 0x0, 0x0 ) /* XXX */
SCRIPT( sund, SUND,
"Sundanese",
HB_SCRIPT_SUNDANESE,
'o', 0x0, 0x0 ) /* XXX */
SCRIPT( sylo, SYLO,
"Syloti Nagri",
HB_SCRIPT_SYLOTI_NAGRI,
'o', 0x0, 0x0 ) /* XXX */
SCRIPT( taml, TAML,
"Tamil",
HB_SCRIPT_TAMIL,
'o', 0x0, 0x0 ) /* XXX */
SCRIPT( telu, TELU,
"Telugu",
HB_SCRIPT_TELUGU,
'o', 0x0, 0x0 ) /* XXX */
SCRIPT( tibt, TIBT,
"Tibetan",
HB_SCRIPT_TIBETAN,
'o', 0x0, 0x0 ) /* XXX */
#endif /* AF_CONFIG_OPTION_INDIC */
#ifdef AF_CONFIG_OPTION_CJK
SCRIPT( hani, HANI,
"CJKV ideographs",
HB_SCRIPT_HAN,
0x7530, 0x56D7, 0x0 ) /* 田囗 */
#endif /* AF_CONFIG_OPTION_CJK */
/* END */
| YifuLiu/AliOS-Things | components/freetype/src/autofit/afscript.h | C | apache-2.0 | 4,071 |
/***************************************************************************/
/* */
/* afstyles.h */
/* */
/* Auto-fitter styles (specification only). */
/* */
/* Copyright 2013, 2014 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. */
/* */
/***************************************************************************/
/* The following part can be included multiple times. */
/* Define `STYLE' as needed. */
/* Add new styles here. The first and second arguments are the */
/* style name in lowercase and uppercase, respectively, followed */
/* by a description string. The next arguments are the */
/* corresponding writing system, script, blue stringset, and */
/* coverage. */
/* */
/* Note that styles using `AF_COVERAGE_DEFAULT' should always */
/* come after styles with other coverages. */
/* */
/* Example: */
/* */
/* STYLE( cyrl_dflt, CYRL_DFLT, */
/* "Cyrillic default style", */
/* AF_WRITING_SYSTEM_LATIN, */
/* AF_SCRIPT_CYRL, */
/* AF_BLUE_STRINGSET_CYRL, */
/* AF_COVERAGE_DEFAULT ) */
#undef STYLE_LATIN
#define STYLE_LATIN( s, S, f, F, ds, df, C ) \
STYLE( s ## _ ## f, S ## _ ## F, \
ds " " df " style", \
AF_WRITING_SYSTEM_LATIN, \
AF_SCRIPT_ ## S, \
AF_BLUE_STRINGSET_ ## S, \
AF_COVERAGE_ ## C )
#undef META_STYLE_LATIN
#define META_STYLE_LATIN( s, S, ds ) \
STYLE_LATIN( s, S, c2cp, C2CP, ds, \
"petite capticals from capitals", \
PETITE_CAPITALS_FROM_CAPITALS ) \
STYLE_LATIN( s, S, c2sc, C2SC, ds, \
"small capticals from capitals", \
SMALL_CAPITALS_FROM_CAPITALS ) \
STYLE_LATIN( s, S, ordn, ORDN, ds, \
"ordinals", \
ORDINALS ) \
STYLE_LATIN( s, S, pcap, PCAP, ds, \
"petite capitals", \
PETITE_CAPITALS ) \
STYLE_LATIN( s, S, sinf, SINF, ds, \
"scientific inferiors", \
SCIENTIFIC_INFERIORS ) \
STYLE_LATIN( s, S, smcp, SMCP, ds, \
"small capitals", \
SMALL_CAPITALS ) \
STYLE_LATIN( s, S, subs, SUBS, ds, \
"subscript", \
SUBSCRIPT ) \
STYLE_LATIN( s, S, sups, SUPS, ds, \
"superscript", \
SUPERSCRIPT ) \
STYLE_LATIN( s, S, titl, TITL, ds, \
"titling", \
TITLING ) \
STYLE_LATIN( s, S, dflt, DFLT, ds, \
"default", \
DEFAULT )
META_STYLE_LATIN( cyrl, CYRL, "Cyrillic" )
META_STYLE_LATIN( grek, GREK, "Greek" )
STYLE( hebr_dflt, HEBR_DFLT,
"Hebrew default style",
AF_WRITING_SYSTEM_LATIN,
AF_SCRIPT_HEBR,
AF_BLUE_STRINGSET_HEBR,
AF_COVERAGE_DEFAULT )
META_STYLE_LATIN( latn, LATN, "Latin" )
#ifdef FT_OPTION_AUTOFIT2
STYLE( ltn2_dflt, LTN2_DFLT,
"Latin 2 default style",
AF_WRITING_SYSTEM_LATIN2,
AF_SCRIPT_LATN,
AF_BLUE_STRINGSET_LATN,
AF_COVERAGE_DEFAULT )
#endif
STYLE( none_dflt, NONE_DFLT,
"no style",
AF_WRITING_SYSTEM_DUMMY,
AF_SCRIPT_NONE,
(AF_Blue_Stringset)0,
AF_COVERAGE_DEFAULT )
#ifdef AF_CONFIG_OPTION_INDIC
/* no blue stringset support for the Indic writing system yet */
#undef STYLE_DEFAULT_INDIC
#define STYLE_DEFAULT_INDIC( s, S, d ) \
STYLE( s ## _dflt, S ## _DFLT, \
d " default style", \
AF_WRITING_SYSTEM_INDIC, \
AF_SCRIPT_ ## S, \
(AF_Blue_Stringset)0, \
AF_COVERAGE_DEFAULT )
STYLE_DEFAULT_INDIC( beng, BENG, "Bengali" )
STYLE_DEFAULT_INDIC( deva, DEVA, "Devanagari" )
STYLE_DEFAULT_INDIC( gujr, GUJR, "Gujarati" )
STYLE_DEFAULT_INDIC( guru, GURU, "Gurmukhi" )
STYLE_DEFAULT_INDIC( knda, KNDA, "Kannada" )
STYLE_DEFAULT_INDIC( limb, LIMB, "Limbu" )
STYLE_DEFAULT_INDIC( mlym, MLYM, "Malayalam" )
STYLE_DEFAULT_INDIC( orya, ORYA, "Oriya" )
STYLE_DEFAULT_INDIC( sinh, SINH, "Sinhala" )
STYLE_DEFAULT_INDIC( sund, SUND, "Sundanese" )
STYLE_DEFAULT_INDIC( sylo, SYLO, "Syloti Nagri" )
STYLE_DEFAULT_INDIC( taml, TAML, "Tamil" )
STYLE_DEFAULT_INDIC( telu, TELU, "Telugu" )
STYLE_DEFAULT_INDIC( tibt, TIBT, "Tibetan" )
#endif /* AF_CONFIG_OPTION_INDIC */
#ifdef AF_CONFIG_OPTION_CJK
STYLE( hani_dflt, HANI_DFLT,
"CJKV ideographs default style",
AF_WRITING_SYSTEM_CJK,
AF_SCRIPT_HANI,
AF_BLUE_STRINGSET_HANI,
AF_COVERAGE_DEFAULT )
#endif /* AF_CONFIG_OPTION_CJK */
/* END */
| YifuLiu/AliOS-Things | components/freetype/src/autofit/afstyles.h | C | apache-2.0 | 6,847 |
/***************************************************************************/
/* */
/* aftypes.h */
/* */
/* Auto-fitter types (specification only). */
/* */
/* Copyright 2003-2009, 2011-2014 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. */
/* */
/***************************************************************************/
/*************************************************************************
*
* The auto-fitter is a complete rewrite of the old auto-hinter.
* Its main feature is the ability to differentiate between different
* writing systems and scripts in order to apply specific rules.
*
* The code has also been compartmentized into several entities that
* should make algorithmic experimentation easier than with the old
* code.
*
*************************************************************************/
#ifndef __AFTYPES_H__
#define __AFTYPES_H__
#include <ft2build.h>
#include FT_FREETYPE_H
#include FT_OUTLINE_H
#include FT_INTERNAL_OBJECTS_H
#include FT_INTERNAL_DEBUG_H
#include "afblue.h"
FT_BEGIN_HEADER
/*************************************************************************/
/*************************************************************************/
/***** *****/
/***** D E B U G G I N G *****/
/***** *****/
/*************************************************************************/
/*************************************************************************/
#ifdef FT_DEBUG_AUTOFIT
#include FT_CONFIG_STANDARD_LIBRARY_H
extern int _af_debug_disable_horz_hints;
extern int _af_debug_disable_vert_hints;
extern int _af_debug_disable_blue_hints;
extern void* _af_debug_hints;
#endif /* FT_DEBUG_AUTOFIT */
/*************************************************************************/
/*************************************************************************/
/***** *****/
/***** U T I L I T Y S T U F F *****/
/***** *****/
/*************************************************************************/
/*************************************************************************/
typedef struct AF_WidthRec_
{
FT_Pos org; /* original position/width in font units */
FT_Pos cur; /* current/scaled position/width in device sub-pixels */
FT_Pos fit; /* current/fitted position/width in device sub-pixels */
} AF_WidthRec, *AF_Width;
FT_LOCAL( void )
af_sort_pos( FT_UInt count,
FT_Pos* table );
FT_LOCAL( void )
af_sort_and_quantize_widths( FT_UInt* count,
AF_Width widths,
FT_Pos threshold );
/*************************************************************************/
/*************************************************************************/
/***** *****/
/***** A N G L E T Y P E S *****/
/***** *****/
/*************************************************************************/
/*************************************************************************/
/*
* The auto-fitter doesn't need a very high angular accuracy;
* this allows us to speed up some computations considerably with a
* light Cordic algorithm (see afangles.c).
*/
typedef FT_Int AF_Angle;
#define AF_ANGLE_PI 256
#define AF_ANGLE_2PI ( AF_ANGLE_PI * 2 )
#define AF_ANGLE_PI2 ( AF_ANGLE_PI / 2 )
#define AF_ANGLE_PI4 ( AF_ANGLE_PI / 4 )
#if 0
/*
* compute the angle of a given 2-D vector
*/
FT_LOCAL( AF_Angle )
af_angle_atan( FT_Pos dx,
FT_Pos dy );
/*
* compute `angle2 - angle1'; the result is always within
* the range [-AF_ANGLE_PI .. AF_ANGLE_PI - 1]
*/
FT_LOCAL( AF_Angle )
af_angle_diff( AF_Angle angle1,
AF_Angle angle2 );
#endif /* 0 */
#define AF_ANGLE_DIFF( result, angle1, angle2 ) \
FT_BEGIN_STMNT \
AF_Angle _delta = (angle2) - (angle1); \
\
\
_delta %= AF_ANGLE_2PI; \
if ( _delta < 0 ) \
_delta += AF_ANGLE_2PI; \
\
if ( _delta > AF_ANGLE_PI ) \
_delta -= AF_ANGLE_2PI; \
\
result = _delta; \
FT_END_STMNT
/* opaque handle to glyph-specific hints -- see `afhints.h' for more
* details
*/
typedef struct AF_GlyphHintsRec_* AF_GlyphHints;
/*************************************************************************/
/*************************************************************************/
/***** *****/
/***** S C A L E R S *****/
/***** *****/
/*************************************************************************/
/*************************************************************************/
/*
* A scaler models the target pixel device that will receive the
* auto-hinted glyph image.
*/
typedef enum AF_ScalerFlags_
{
AF_SCALER_FLAG_NO_HORIZONTAL = 1, /* disable horizontal hinting */
AF_SCALER_FLAG_NO_VERTICAL = 2, /* disable vertical hinting */
AF_SCALER_FLAG_NO_ADVANCE = 4 /* disable advance hinting */
} AF_ScalerFlags;
typedef struct AF_ScalerRec_
{
FT_Face face; /* source font face */
FT_Fixed x_scale; /* from font units to 1/64th device pixels */
FT_Fixed y_scale; /* from font units to 1/64th device pixels */
FT_Pos x_delta; /* in 1/64th device pixels */
FT_Pos y_delta; /* in 1/64th device pixels */
FT_Render_Mode render_mode; /* monochrome, anti-aliased, LCD, etc. */
FT_UInt32 flags; /* additional control flags, see above */
} AF_ScalerRec, *AF_Scaler;
#define AF_SCALER_EQUAL_SCALES( a, b ) \
( (a)->x_scale == (b)->x_scale && \
(a)->y_scale == (b)->y_scale && \
(a)->x_delta == (b)->x_delta && \
(a)->y_delta == (b)->y_delta )
typedef struct AF_StyleMetricsRec_* AF_StyleMetrics;
/* This function parses an FT_Face to compute global metrics for
* a specific style.
*/
typedef FT_Error
(*AF_WritingSystem_InitMetricsFunc)( AF_StyleMetrics metrics,
FT_Face face );
typedef void
(*AF_WritingSystem_ScaleMetricsFunc)( AF_StyleMetrics metrics,
AF_Scaler scaler );
typedef void
(*AF_WritingSystem_DoneMetricsFunc)( AF_StyleMetrics metrics );
typedef FT_Error
(*AF_WritingSystem_InitHintsFunc)( AF_GlyphHints hints,
AF_StyleMetrics metrics );
typedef void
(*AF_WritingSystem_ApplyHintsFunc)( AF_GlyphHints hints,
FT_Outline* outline,
AF_StyleMetrics metrics );
/*************************************************************************/
/*************************************************************************/
/***** *****/
/***** W R I T I N G S Y S T E M S *****/
/***** *****/
/*************************************************************************/
/*************************************************************************/
/*
* For the auto-hinter, a writing system consists of multiple scripts that
* can be handled similarly *in a typographical way*; the relationship is
* not based on history. For example, both the Greek and the unrelated
* Armenian scripts share the same features like ascender, descender,
* x-height, etc. Essentially, a writing system is covered by a
* submodule of the auto-fitter; it contains
*
* - a specific global analyzer that computes global metrics specific to
* the script (based on script-specific characters to identify ascender
* height, x-height, etc.),
*
* - a specific glyph analyzer that computes segments and edges for each
* glyph covered by the script,
*
* - a specific grid-fitting algorithm that distorts the scaled glyph
* outline according to the results of the glyph analyzer.
*/
#define __AFWRTSYS_H__ /* don't load header files */
#undef WRITING_SYSTEM
#define WRITING_SYSTEM( ws, WS ) \
AF_WRITING_SYSTEM_ ## WS,
/* The list of known writing systems. */
typedef enum AF_WritingSystem_
{
#include "afwrtsys.h"
AF_WRITING_SYSTEM_MAX /* do not remove */
} AF_WritingSystem;
#undef __AFWRTSYS_H__
typedef struct AF_WritingSystemClassRec_
{
AF_WritingSystem writing_system;
FT_Offset style_metrics_size;
AF_WritingSystem_InitMetricsFunc style_metrics_init;
AF_WritingSystem_ScaleMetricsFunc style_metrics_scale;
AF_WritingSystem_DoneMetricsFunc style_metrics_done;
AF_WritingSystem_InitHintsFunc style_hints_init;
AF_WritingSystem_ApplyHintsFunc style_hints_apply;
} AF_WritingSystemClassRec;
typedef const AF_WritingSystemClassRec* AF_WritingSystemClass;
/*************************************************************************/
/*************************************************************************/
/***** *****/
/***** S C R I P T S *****/
/***** *****/
/*************************************************************************/
/*************************************************************************/
/*
* Each script is associated with a set of Unicode ranges that gets used
* to test whether the font face supports the script.
*
* We use four-letter script tags from the OpenType specification,
* extended by `NONE', which indicates `no script'.
*/
#undef SCRIPT
#define SCRIPT( s, S, d, h, sc1, sc2, sc3 ) \
AF_SCRIPT_ ## S,
/* The list of known scripts. */
typedef enum AF_Script_
{
#include "afscript.h"
AF_SCRIPT_MAX /* do not remove */
} AF_Script;
typedef struct AF_Script_UniRangeRec_
{
FT_UInt32 first;
FT_UInt32 last;
} AF_Script_UniRangeRec;
#define AF_UNIRANGE_REC( a, b ) { (FT_UInt32)(a), (FT_UInt32)(b) }
typedef const AF_Script_UniRangeRec* AF_Script_UniRange;
typedef struct AF_ScriptClassRec_
{
AF_Script script;
AF_Script_UniRange script_uni_ranges; /* last must be { 0, 0 } */
FT_UInt32 standard_char1; /* for default width and height */
FT_UInt32 standard_char2; /* ditto */
FT_UInt32 standard_char3; /* ditto */
} AF_ScriptClassRec;
typedef const AF_ScriptClassRec* AF_ScriptClass;
/*************************************************************************/
/*************************************************************************/
/***** *****/
/***** C O V E R A G E S *****/
/***** *****/
/*************************************************************************/
/*************************************************************************/
/*
* Usually, a font contains more glyphs than can be addressed by its
* character map.
*
* In the PostScript font world, encoding vectors specific to a given
* task are used to select such glyphs, and these glyphs can be often
* recognized by having a suffix in its glyph names. For example, a
* superscript glyph `A' might be called `A.sup'. Unfortunately, this
* naming scheme is not standardized and thus unusable for us.
*
* In the OpenType world, a better solution was invented, namely
* `features', which cleanly separate a character's input encoding from
* the corresponding glyph's appearance, and which don't use glyph names
* at all. For our purposes, and slightly generalized, an OpenType
* feature is a name of a mapping that maps character codes to
* non-standard glyph indices (features get used for other things also).
* For example, the `sups' feature provides superscript glyphs, thus
* mapping character codes like `A' or `B' to superscript glyph
* representation forms. How this mapping happens is completely
* uninteresting to us.
*
* For the auto-hinter, a `coverage' represents all glyphs of an OpenType
* feature collected in a set (as listed below) that can be hinted
* together. To continue the above example, superscript glyphs must not
* be hinted together with normal glyphs because the blue zones
* completely differ.
*
* Note that FreeType itself doesn't compute coverages; it only provides
* the glyphs addressable by the default Unicode character map. Instead,
* we use the HarfBuzz library (if available), which has many functions
* exactly for this purpose.
*
* AF_COVERAGE_DEFAULT is special: It should cover everything that isn't
* listed separately (including the glyphs addressable by the character
* map). In case HarfBuzz isn't available, it exactly covers the glyphs
* addressable by the character map.
*
*/
#undef COVERAGE
#define COVERAGE( name, NAME, description, \
tag1, tag2, tag3, tag4 ) \
AF_COVERAGE_ ## NAME,
typedef enum AF_Coverage_
{
#include "afcover.h"
AF_COVERAGE_DEFAULT
} AF_Coverage;
/*************************************************************************/
/*************************************************************************/
/***** *****/
/***** S T Y L E S *****/
/***** *****/
/*************************************************************************/
/*************************************************************************/
/*
* The topmost structure for modelling the auto-hinter glyph input data
* is a `style class', grouping everything together.
*/
#undef STYLE
#define STYLE( s, S, d, ws, sc, ss, c ) \
AF_STYLE_ ## S,
/* The list of known styles. */
typedef enum AF_Style_
{
#include "afstyles.h"
AF_STYLE_MAX /* do not remove */
} AF_Style;
typedef struct AF_StyleClassRec_
{
AF_Style style;
AF_WritingSystem writing_system;
AF_Script script;
AF_Blue_Stringset blue_stringset;
AF_Coverage coverage;
} AF_StyleClassRec;
typedef const AF_StyleClassRec* AF_StyleClass;
/*************************************************************************/
/*************************************************************************/
/***** *****/
/***** S T Y L E M E T R I C S *****/
/***** *****/
/*************************************************************************/
/*************************************************************************/
typedef struct AF_FaceGlobalsRec_* AF_FaceGlobals;
/* This is the main structure that combines everything. Autofit modules */
/* specific to writing systems derive their structures from it, for */
/* example `AF_LatinMetrics'. */
typedef struct AF_StyleMetricsRec_
{
AF_StyleClass style_class;
AF_ScalerRec scaler;
FT_Bool digits_have_same_width;
AF_FaceGlobals globals; /* to access properties */
} AF_StyleMetricsRec;
/* Declare and define vtables for classes */
#ifndef FT_CONFIG_OPTION_PIC
#define AF_DECLARE_WRITING_SYSTEM_CLASS( writing_system_class ) \
FT_CALLBACK_TABLE const AF_WritingSystemClassRec \
writing_system_class;
#define AF_DEFINE_WRITING_SYSTEM_CLASS( \
writing_system_class, \
system, \
m_size, \
m_init, \
m_scale, \
m_done, \
h_init, \
h_apply ) \
FT_CALLBACK_TABLE_DEF \
const AF_WritingSystemClassRec writing_system_class = \
{ \
system, \
\
m_size, \
\
m_init, \
m_scale, \
m_done, \
\
h_init, \
h_apply \
};
#define AF_DECLARE_SCRIPT_CLASS( script_class ) \
FT_CALLBACK_TABLE const AF_ScriptClassRec \
script_class;
#define AF_DEFINE_SCRIPT_CLASS( \
script_class, \
script, \
ranges, \
std_char1, \
std_char2, \
std_char3 ) \
FT_CALLBACK_TABLE_DEF \
const AF_ScriptClassRec script_class = \
{ \
script, \
ranges, \
std_char1, \
std_char2, \
std_char3 \
};
#define AF_DECLARE_STYLE_CLASS( style_class ) \
FT_CALLBACK_TABLE const AF_StyleClassRec \
style_class;
#define AF_DEFINE_STYLE_CLASS( \
style_class, \
style, \
writing_system, \
script, \
blue_stringset, \
coverage ) \
FT_CALLBACK_TABLE_DEF \
const AF_StyleClassRec style_class = \
{ \
style, \
writing_system, \
script, \
blue_stringset, \
coverage \
};
#else /* FT_CONFIG_OPTION_PIC */
#define AF_DECLARE_WRITING_SYSTEM_CLASS( writing_system_class ) \
FT_LOCAL( void ) \
FT_Init_Class_ ## writing_system_class( AF_WritingSystemClassRec* ac );
#define AF_DEFINE_WRITING_SYSTEM_CLASS( \
writing_system_class, \
system, \
m_size, \
m_init, \
m_scale, \
m_done, \
h_init, \
h_apply ) \
FT_LOCAL_DEF( void ) \
FT_Init_Class_ ## writing_system_class( AF_WritingSystemClassRec* ac ) \
{ \
ac->writing_system = system; \
\
ac->style_metrics_size = m_size; \
\
ac->style_metrics_init = m_init; \
ac->style_metrics_scale = m_scale; \
ac->style_metrics_done = m_done; \
\
ac->style_hints_init = h_init; \
ac->style_hints_apply = h_apply; \
}
#define AF_DECLARE_SCRIPT_CLASS( script_class ) \
FT_LOCAL( void ) \
FT_Init_Class_ ## script_class( AF_ScriptClassRec* ac );
#define AF_DEFINE_SCRIPT_CLASS( \
script_class, \
script_, \
ranges, \
std_char1, \
std_char2, \
std_char3 ) \
FT_LOCAL_DEF( void ) \
FT_Init_Class_ ## script_class( AF_ScriptClassRec* ac ) \
{ \
ac->script = script_; \
ac->script_uni_ranges = ranges; \
ac->standard_char1 = std_char1; \
ac->standard_char2 = std_char2; \
ac->standard_char3 = std_char3; \
}
#define AF_DECLARE_STYLE_CLASS( style_class ) \
FT_LOCAL( void ) \
FT_Init_Class_ ## style_class( AF_StyleClassRec* ac );
#define AF_DEFINE_STYLE_CLASS( \
style_class, \
style_, \
writing_system_, \
script_, \
blue_stringset_, \
coverage_ ) \
FT_LOCAL_DEF( void ) \
FT_Init_Class_ ## style_class( AF_StyleClassRec* ac ) \
{ \
ac->style = style_; \
ac->writing_system = writing_system_; \
ac->script = script_; \
ac->blue_stringset = blue_stringset_; \
ac->coverage = coverage_; \
}
#endif /* FT_CONFIG_OPTION_PIC */
/* */
FT_END_HEADER
#endif /* __AFTYPES_H__ */
/* END */
| YifuLiu/AliOS-Things | components/freetype/src/autofit/aftypes.h | C | apache-2.0 | 25,124 |
/***************************************************************************/
/* */
/* afwarp.c */
/* */
/* Auto-fitter warping algorithm (body). */
/* */
/* Copyright 2006, 2007, 2011 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. */
/* */
/***************************************************************************/
/*
* The idea of the warping code is to slightly scale and shift a glyph
* within a single dimension so that as much of its segments are aligned
* (more or less) on the grid. To find out the optimal scaling and
* shifting value, various parameter combinations are tried and scored.
*/
#include "afwarp.h"
#ifdef AF_CONFIG_OPTION_USE_WARPER
/*************************************************************************/
/* */
/* The macro FT_COMPONENT is used in trace mode. It is an implicit */
/* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */
/* messages during execution. */
/* */
#undef FT_COMPONENT
#define FT_COMPONENT trace_afwarp
/* The weights cover the range 0/64 - 63/64 of a pixel. Obviously, */
/* values around a half pixel (which means exactly between two grid */
/* lines) gets the worst weight. */
#if 1
static const AF_WarpScore
af_warper_weights[64] =
{
35, 32, 30, 25, 20, 15, 12, 10, 5, 1, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, -1, -2, -5, -8,-10,-10,-20,-20,-30,-30,
-30,-30,-20,-20,-10,-10, -8, -5, -2, -1, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 1, 5, 10, 12, 15, 20, 25, 30, 32,
};
#else
static const AF_WarpScore
af_warper_weights[64] =
{
30, 20, 10, 5, 4, 4, 3, 2, 1, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, -1, -2, -2, -5, -5,-10,-10,-15,-20,
-20,-15,-15,-10,-10, -5, -5, -2, -2, -1, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 4, 5, 10, 20,
};
#endif
/* Score segments for a given `scale' and `delta' in the range */
/* `xx1' to `xx2', and store the best result in `warper'. If */
/* the new best score is equal to the old one, prefer the */
/* value with a smaller distortion (around `base_distort'). */
static void
af_warper_compute_line_best( AF_Warper warper,
FT_Fixed scale,
FT_Pos delta,
FT_Pos xx1,
FT_Pos xx2,
AF_WarpScore base_distort,
AF_Segment segments,
FT_UInt num_segments )
{
FT_Int idx_min, idx_max, idx0;
FT_UInt nn;
AF_WarpScore scores[65];
for ( nn = 0; nn < 65; nn++ )
scores[nn] = 0;
idx0 = xx1 - warper->t1;
/* compute minimum and maximum indices */
{
FT_Pos xx1min = warper->x1min;
FT_Pos xx1max = warper->x1max;
FT_Pos w = xx2 - xx1;
if ( xx1min + w < warper->x2min )
xx1min = warper->x2min - w;
xx1max = warper->x1max;
if ( xx1max + w > warper->x2max )
xx1max = warper->x2max - w;
idx_min = xx1min - warper->t1;
idx_max = xx1max - warper->t1;
if ( idx_min < 0 || idx_min > idx_max || idx_max > 64 )
{
FT_TRACE5(( "invalid indices:\n"
" min=%d max=%d, xx1=%ld xx2=%ld,\n"
" x1min=%ld x1max=%ld, x2min=%ld x2max=%ld\n",
idx_min, idx_max, xx1, xx2,
warper->x1min, warper->x1max,
warper->x2min, warper->x2max ));
return;
}
}
for ( nn = 0; nn < num_segments; nn++ )
{
FT_Pos len = segments[nn].max_coord - segments[nn].min_coord;
FT_Pos y0 = FT_MulFix( segments[nn].pos, scale ) + delta;
FT_Pos y = y0 + ( idx_min - idx0 );
FT_Int idx;
/* score the length of the segments for the given range */
for ( idx = idx_min; idx <= idx_max; idx++, y++ )
scores[idx] += af_warper_weights[y & 63] * len;
}
/* find best score */
{
FT_Int idx;
for ( idx = idx_min; idx <= idx_max; idx++ )
{
AF_WarpScore score = scores[idx];
AF_WarpScore distort = base_distort + ( idx - idx0 );
if ( score > warper->best_score ||
( score == warper->best_score &&
distort < warper->best_distort ) )
{
warper->best_score = score;
warper->best_distort = distort;
warper->best_scale = scale;
warper->best_delta = delta + ( idx - idx0 );
}
}
}
}
/* Compute optimal scaling and delta values for a given glyph and */
/* dimension. */
FT_LOCAL_DEF( void )
af_warper_compute( AF_Warper warper,
AF_GlyphHints hints,
AF_Dimension dim,
FT_Fixed *a_scale,
FT_Pos *a_delta )
{
AF_AxisHints axis;
AF_Point points;
FT_Fixed org_scale;
FT_Pos org_delta;
FT_UInt nn, num_points, num_segments;
FT_Int X1, X2;
FT_Int w;
AF_WarpScore base_distort;
AF_Segment segments;
/* get original scaling transformation */
if ( dim == AF_DIMENSION_VERT )
{
org_scale = hints->y_scale;
org_delta = hints->y_delta;
}
else
{
org_scale = hints->x_scale;
org_delta = hints->x_delta;
}
warper->best_scale = org_scale;
warper->best_delta = org_delta;
warper->best_score = INT_MIN;
warper->best_distort = 0;
axis = &hints->axis[dim];
segments = axis->segments;
num_segments = axis->num_segments;
points = hints->points;
num_points = hints->num_points;
*a_scale = org_scale;
*a_delta = org_delta;
/* get X1 and X2, minimum and maximum in original coordinates */
if ( num_segments < 1 )
return;
#if 1
X1 = X2 = points[0].fx;
for ( nn = 1; nn < num_points; nn++ )
{
FT_Int X = points[nn].fx;
if ( X < X1 )
X1 = X;
if ( X > X2 )
X2 = X;
}
#else
X1 = X2 = segments[0].pos;
for ( nn = 1; nn < num_segments; nn++ )
{
FT_Int X = segments[nn].pos;
if ( X < X1 )
X1 = X;
if ( X > X2 )
X2 = X;
}
#endif
if ( X1 >= X2 )
return;
warper->x1 = FT_MulFix( X1, org_scale ) + org_delta;
warper->x2 = FT_MulFix( X2, org_scale ) + org_delta;
warper->t1 = AF_WARPER_FLOOR( warper->x1 );
warper->t2 = AF_WARPER_CEIL( warper->x2 );
/* examine a half pixel wide range around the maximum coordinates */
warper->x1min = warper->x1 & ~31;
warper->x1max = warper->x1min + 32;
warper->x2min = warper->x2 & ~31;
warper->x2max = warper->x2min + 32;
if ( warper->x1max > warper->x2 )
warper->x1max = warper->x2;
if ( warper->x2min < warper->x1 )
warper->x2min = warper->x1;
warper->w0 = warper->x2 - warper->x1;
if ( warper->w0 <= 64 )
{
warper->x1max = warper->x1;
warper->x2min = warper->x2;
}
/* examine (at most) a pixel wide range around the natural width */
warper->wmin = warper->x2min - warper->x1max;
warper->wmax = warper->x2max - warper->x1min;
#if 1
/* some heuristics to reduce the number of widths to be examined */
{
int margin = 16;
if ( warper->w0 <= 128 )
{
margin = 8;
if ( warper->w0 <= 96 )
margin = 4;
}
if ( warper->wmin < warper->w0 - margin )
warper->wmin = warper->w0 - margin;
if ( warper->wmax > warper->w0 + margin )
warper->wmax = warper->w0 + margin;
}
if ( warper->wmin < warper->w0 * 3 / 4 )
warper->wmin = warper->w0 * 3 / 4;
if ( warper->wmax > warper->w0 * 5 / 4 )
warper->wmax = warper->w0 * 5 / 4;
#else
/* no scaling, just translation */
warper->wmin = warper->wmax = warper->w0;
#endif
for ( w = warper->wmin; w <= warper->wmax; w++ )
{
FT_Fixed new_scale;
FT_Pos new_delta;
FT_Pos xx1, xx2;
/* compute min and max positions for given width, */
/* assuring that they stay within the coordinate ranges */
xx1 = warper->x1;
xx2 = warper->x2;
if ( w >= warper->w0 )
{
xx1 -= w - warper->w0;
if ( xx1 < warper->x1min )
{
xx2 += warper->x1min - xx1;
xx1 = warper->x1min;
}
}
else
{
xx1 -= w - warper->w0;
if ( xx1 > warper->x1max )
{
xx2 -= xx1 - warper->x1max;
xx1 = warper->x1max;
}
}
if ( xx1 < warper->x1 )
base_distort = warper->x1 - xx1;
else
base_distort = xx1 - warper->x1;
if ( xx2 < warper->x2 )
base_distort += warper->x2 - xx2;
else
base_distort += xx2 - warper->x2;
/* give base distortion a greater weight while scoring */
base_distort *= 10;
new_scale = org_scale + FT_DivFix( w - warper->w0, X2 - X1 );
new_delta = xx1 - FT_MulFix( X1, new_scale );
af_warper_compute_line_best( warper, new_scale, new_delta, xx1, xx2,
base_distort,
segments, num_segments );
}
{
FT_Fixed best_scale = warper->best_scale;
FT_Pos best_delta = warper->best_delta;
hints->xmin_delta = FT_MulFix( X1, best_scale - org_scale )
+ best_delta;
hints->xmax_delta = FT_MulFix( X2, best_scale - org_scale )
+ best_delta;
*a_scale = best_scale;
*a_delta = best_delta;
}
}
#else /* !AF_CONFIG_OPTION_USE_WARPER */
/* ANSI C doesn't like empty source files */
typedef int _af_warp_dummy;
#endif /* !AF_CONFIG_OPTION_USE_WARPER */
/* END */
| YifuLiu/AliOS-Things | components/freetype/src/autofit/afwarp.c | C | apache-2.0 | 11,198 |
/***************************************************************************/
/* */
/* afwarp.h */
/* */
/* Auto-fitter warping algorithm (specification). */
/* */
/* Copyright 2006, 2007 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. */
/* */
/***************************************************************************/
#ifndef __AFWARP_H__
#define __AFWARP_H__
#include "afhints.h"
FT_BEGIN_HEADER
#define AF_WARPER_SCALE
#define AF_WARPER_FLOOR( x ) ( (x) & ~63 )
#define AF_WARPER_CEIL( x ) AF_WARPER_FLOOR( (x) + 63 )
typedef FT_Int32 AF_WarpScore;
typedef struct AF_WarperRec_
{
FT_Pos x1, x2;
FT_Pos t1, t2;
FT_Pos x1min, x1max;
FT_Pos x2min, x2max;
FT_Pos w0, wmin, wmax;
FT_Fixed best_scale;
FT_Pos best_delta;
AF_WarpScore best_score;
AF_WarpScore best_distort;
} AF_WarperRec, *AF_Warper;
FT_LOCAL( void )
af_warper_compute( AF_Warper warper,
AF_GlyphHints hints,
AF_Dimension dim,
FT_Fixed *a_scale,
FT_Fixed *a_delta );
FT_END_HEADER
#endif /* __AFWARP_H__ */
/* END */
| YifuLiu/AliOS-Things | components/freetype/src/autofit/afwarp.h | C | apache-2.0 | 2,133 |
/***************************************************************************/
/* */
/* afwrtsys.h */
/* */
/* Auto-fitter writing systems (specification only). */
/* */
/* Copyright 2013 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. */
/* */
/***************************************************************************/
#ifndef __AFWRTSYS_H__
#define __AFWRTSYS_H__
/* Since preprocessor directives can't create other preprocessor */
/* directives, we have to include the header files manually. */
#include "afdummy.h"
#include "aflatin.h"
#include "afcjk.h"
#include "afindic.h"
#ifdef FT_OPTION_AUTOFIT2
#include "aflatin2.h"
#endif
#endif /* __AFWRTSYS_H__ */
/* The following part can be included multiple times. */
/* Define `WRITING_SYSTEM' as needed. */
/* Add new writing systems here. The arguments are the writing system */
/* name in lowercase and uppercase, respectively. */
WRITING_SYSTEM( dummy, DUMMY )
WRITING_SYSTEM( latin, LATIN )
WRITING_SYSTEM( cjk, CJK )
WRITING_SYSTEM( indic, INDIC )
#ifdef FT_OPTION_AUTOFIT2
WRITING_SYSTEM( latin2, LATIN2 )
#endif
/* END */
| YifuLiu/AliOS-Things | components/freetype/src/autofit/afwrtsys.h | C | apache-2.0 | 2,099 |
/***************************************************************************/
/* */
/* autofit.c */
/* */
/* Auto-fitter module (body). */
/* */
/* Copyright 2003-2007, 2011, 2013 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. */
/* */
/***************************************************************************/
#define FT_MAKE_OPTION_SINGLE_OBJECT
#include <ft2build.h>
#include "afpic.c"
#include "afangles.c"
#include "afblue.c"
#include "afglobal.c"
#include "afhints.c"
#include "afranges.c"
#include "afdummy.c"
#include "aflatin.c"
#ifdef FT_OPTION_AUTOFIT2
#include "aflatin2.c"
#endif
#include "afcjk.c"
#include "afindic.c"
#include "hbshim.c"
#include "afloader.c"
#include "afmodule.c"
#ifdef AF_CONFIG_OPTION_USE_WARPER
#include "afwarp.c"
#endif
/* END */
| YifuLiu/AliOS-Things | components/freetype/src/autofit/autofit.c | C | apache-2.0 | 1,714 |
/***************************************************************************/
/* */
/* hbshim.c */
/* */
/* HarfBuzz interface for accessing OpenType features (body). */
/* */
/* Copyright 2013, 2014 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. */
/* */
/***************************************************************************/
#include <ft2build.h>
#include FT_FREETYPE_H
#include "afglobal.h"
#include "aftypes.h"
#include "hbshim.h"
#ifdef FT_CONFIG_OPTION_USE_HARFBUZZ
/*************************************************************************/
/* */
/* The macro FT_COMPONENT is used in trace mode. It is an implicit */
/* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */
/* messages during execution. */
/* */
#undef FT_COMPONENT
#define FT_COMPONENT trace_afharfbuzz
/*
* We use `sets' (in the HarfBuzz sense, which comes quite near to the
* usual mathematical meaning) to manage both lookups and glyph indices.
*
* 1. For each coverage, collect lookup IDs in a set. Note that an
* auto-hinter `coverage' is represented by one `feature', and a
* feature consists of an arbitrary number of (font specific) `lookup's
* that actually do the mapping job. Please check the OpenType
* specification for more details on features and lookups.
*
* 2. Create glyph ID sets from the corresponding lookup sets.
*
* 3. The glyph set corresponding to AF_COVERAGE_DEFAULT is computed
* with all lookups specific to the OpenType script activated. It
* relies on the order of AF_DEFINE_STYLE_CLASS entries so that
* special coverages (like `oldstyle figures') don't get overwritten.
*
*/
/* load coverage tags */
#undef COVERAGE
#define COVERAGE( name, NAME, description, \
tag1, tag2, tag3, tag4 ) \
static const hb_tag_t name ## _coverage[] = \
{ \
HB_TAG( tag1, tag2, tag3, tag4 ), \
HB_TAG_NONE \
};
#include "afcover.h"
/* define mapping between coverage tags and AF_Coverage */
#undef COVERAGE
#define COVERAGE( name, NAME, description, \
tag1, tag2, tag3, tag4 ) \
name ## _coverage,
static const hb_tag_t* coverages[] =
{
#include "afcover.h"
NULL /* AF_COVERAGE_DEFAULT */
};
/* load HarfBuzz script tags */
#undef SCRIPT
#define SCRIPT( s, S, d, h, sc1, sc2, sc3 ) h,
static const hb_script_t scripts[] =
{
#include "afscript.h"
};
FT_Error
af_get_coverage( AF_FaceGlobals globals,
AF_StyleClass style_class,
FT_Byte* gstyles )
{
hb_face_t* face;
hb_set_t* gsub_lookups; /* GSUB lookups for a given script */
hb_set_t* gsub_glyphs; /* glyphs covered by GSUB lookups */
hb_set_t* gpos_lookups; /* GPOS lookups for a given script */
hb_set_t* gpos_glyphs; /* glyphs covered by GPOS lookups */
hb_script_t script;
const hb_tag_t* coverage_tags;
hb_tag_t script_tags[] = { HB_TAG_NONE,
HB_TAG_NONE,
HB_TAG_NONE,
HB_TAG_NONE };
hb_codepoint_t idx;
#ifdef FT_DEBUG_LEVEL_TRACE
int count;
#endif
if ( !globals || !style_class || !gstyles )
return FT_THROW( Invalid_Argument );
face = hb_font_get_face( globals->hb_font );
gsub_lookups = hb_set_create();
gsub_glyphs = hb_set_create();
gpos_lookups = hb_set_create();
gpos_glyphs = hb_set_create();
coverage_tags = coverages[style_class->coverage];
script = scripts[style_class->script];
/* Convert a HarfBuzz script tag into the corresponding OpenType */
/* tag or tags -- some Indic scripts like Devanagari have an old */
/* and a new set of features. */
hb_ot_tags_from_script( script,
&script_tags[0],
&script_tags[1] );
/* `hb_ot_tags_from_script' usually returns HB_OT_TAG_DEFAULT_SCRIPT */
/* as the second tag. We change that to HB_TAG_NONE except for the */
/* default script. */
if ( style_class->script == globals->module->default_script &&
style_class->coverage == AF_COVERAGE_DEFAULT )
{
if ( script_tags[0] == HB_TAG_NONE )
script_tags[0] = HB_OT_TAG_DEFAULT_SCRIPT;
else
{
if ( script_tags[1] == HB_TAG_NONE )
script_tags[1] = HB_OT_TAG_DEFAULT_SCRIPT;
else if ( script_tags[1] != HB_OT_TAG_DEFAULT_SCRIPT )
script_tags[2] = HB_OT_TAG_DEFAULT_SCRIPT;
}
}
else
{
if ( script_tags[1] == HB_OT_TAG_DEFAULT_SCRIPT )
script_tags[1] = HB_TAG_NONE;
}
hb_ot_layout_collect_lookups( face,
HB_OT_TAG_GSUB,
script_tags,
NULL,
coverage_tags,
gsub_lookups );
if ( hb_set_is_empty( gsub_lookups ) )
goto Exit; /* nothing to do */
hb_ot_layout_collect_lookups( face,
HB_OT_TAG_GPOS,
script_tags,
NULL,
coverage_tags,
gpos_lookups );
FT_TRACE4(( "GSUB lookups (style `%s'):\n"
" ",
af_style_names[style_class->style] ));
#ifdef FT_DEBUG_LEVEL_TRACE
count = 0;
#endif
for ( idx = -1; hb_set_next( gsub_lookups, &idx ); )
{
#ifdef FT_DEBUG_LEVEL_TRACE
FT_TRACE4(( " %d", idx ));
count++;
#endif
/* get output coverage of GSUB feature */
hb_ot_layout_lookup_collect_glyphs( face,
HB_OT_TAG_GSUB,
idx,
NULL,
NULL,
NULL,
gsub_glyphs );
}
#ifdef FT_DEBUG_LEVEL_TRACE
if ( !count )
FT_TRACE4(( " (none)" ));
FT_TRACE4(( "\n\n" ));
#endif
FT_TRACE4(( "GPOS lookups (style `%s'):\n"
" ",
af_style_names[style_class->style] ));
#ifdef FT_DEBUG_LEVEL_TRACE
count = 0;
#endif
for ( idx = -1; hb_set_next( gpos_lookups, &idx ); )
{
#ifdef FT_DEBUG_LEVEL_TRACE
FT_TRACE4(( " %d", idx ));
count++;
#endif
/* get input coverage of GPOS feature */
hb_ot_layout_lookup_collect_glyphs( face,
HB_OT_TAG_GPOS,
idx,
NULL,
gpos_glyphs,
NULL,
NULL );
}
#ifdef FT_DEBUG_LEVEL_TRACE
if ( !count )
FT_TRACE4(( " (none)" ));
FT_TRACE4(( "\n\n" ));
#endif
/*
* We now check whether we can construct blue zones, using glyphs
* covered by the feature only. In case there is not a single zone
* (this is, not a single character is covered), we skip this coverage.
*
*/
{
AF_Blue_Stringset bss = style_class->blue_stringset;
const AF_Blue_StringRec* bs = &af_blue_stringsets[bss];
FT_Bool found = 0;
for ( ; bs->string != AF_BLUE_STRING_MAX; bs++ )
{
const char* p = &af_blue_strings[bs->string];
while ( *p )
{
hb_codepoint_t ch;
GET_UTF8_CHAR( ch, p );
for ( idx = -1; hb_set_next( gsub_lookups, &idx ); )
{
hb_codepoint_t gidx = FT_Get_Char_Index( globals->face, ch );
if ( hb_ot_layout_lookup_would_substitute( face, idx,
&gidx, 1, 1 ) )
{
found = 1;
break;
}
}
}
}
if ( !found )
{
FT_TRACE4(( " no blue characters found; style skipped\n" ));
goto Exit;
}
}
/*
* Various OpenType features might use the same glyphs at different
* vertical positions; for example, superscript and subscript glyphs
* could be the same. However, the auto-hinter is completely
* agnostic of OpenType features after the feature analysis has been
* completed: The engine then simply receives a glyph index and returns a
* hinted and usually rendered glyph.
*
* Consider the superscript feature of font `pala.ttf': Some of the
* glyphs are `real', this is, they have a zero vertical offset, but
* most of them are small caps glyphs shifted up to the superscript
* position (this is, the `sups' feature is present in both the GSUB and
* GPOS tables). The code for blue zones computation actually uses a
* feature's y offset so that the `real' glyphs get correct hints. But
* later on it is impossible to decide whether a glyph index belongs to,
* say, the small caps or superscript feature.
*
* For this reason, we don't assign a style to a glyph if the current
* feature covers the glyph in both the GSUB and the GPOS tables. This
* is quite a broad condition, assuming that
*
* (a) glyphs that get used in multiple features are present in a
* feature without vertical shift,
*
* and
*
* (b) a feature's GPOS data really moves the glyph vertically.
*
* Not fulfilling condition (a) makes a font larger; it would also
* reduce the number of glyphs that could be addressed directly without
* using OpenType features, so this assumption is rather strong.
*
* Condition (b) is much weaker, and there might be glyphs which get
* missed. However, the OpenType features we are going to handle are
* primarily located in GSUB, and HarfBuzz doesn't provide an API to
* directly get the necessary information from the GPOS table. A
* possible solution might be to directly parse the GPOS table to find
* out whether a glyph gets shifted vertically, but this is something I
* would like to avoid if not really necessary.
*
*/
hb_set_subtract( gsub_glyphs, gpos_glyphs );
#ifdef FT_DEBUG_LEVEL_TRACE
FT_TRACE4(( " glyphs without GPOS data (`*' means already assigned)" ));
count = 0;
#endif
for ( idx = -1; hb_set_next( gsub_glyphs, &idx ); )
{
#ifdef FT_DEBUG_LEVEL_TRACE
if ( !( count % 10 ) )
FT_TRACE4(( "\n"
" " ));
FT_TRACE4(( " %d", idx ));
count++;
#endif
if ( gstyles[idx] == AF_STYLE_UNASSIGNED )
gstyles[idx] = (FT_Byte)style_class->style;
#ifdef FT_DEBUG_LEVEL_TRACE
else
FT_TRACE4(( "*" ));
#endif
}
#ifdef FT_DEBUG_LEVEL_TRACE
if ( !count )
FT_TRACE4(( "\n"
" (none)" ));
FT_TRACE4(( "\n\n" ));
#endif
Exit:
hb_set_destroy( gsub_lookups );
hb_set_destroy( gsub_glyphs );
hb_set_destroy( gpos_lookups );
hb_set_destroy( gpos_glyphs );
return FT_Err_Ok;
}
/* construct HarfBuzz features */
#undef COVERAGE
#define COVERAGE( name, NAME, description, \
tag1, tag2, tag3, tag4 ) \
static const hb_feature_t name ## _feature[] = \
{ \
{ \
HB_TAG( tag1, tag2, tag3, tag4 ), \
1, 0, (unsigned int)-1 \
} \
};
#include "afcover.h"
/* define mapping between HarfBuzz features and AF_Coverage */
#undef COVERAGE
#define COVERAGE( name, NAME, description, \
tag1, tag2, tag3, tag4 ) \
name ## _feature,
static const hb_feature_t* features[] =
{
#include "afcover.h"
NULL /* AF_COVERAGE_DEFAULT */
};
FT_Error
af_get_char_index( AF_StyleMetrics metrics,
FT_ULong charcode,
FT_ULong *codepoint,
FT_Long *y_offset )
{
AF_StyleClass style_class;
const hb_feature_t* feature;
FT_ULong in_idx, out_idx;
if ( !metrics )
return FT_THROW( Invalid_Argument );
in_idx = FT_Get_Char_Index( metrics->globals->face, charcode );
style_class = metrics->style_class;
feature = features[style_class->coverage];
if ( feature )
{
FT_UInt upem = metrics->globals->face->units_per_EM;
hb_font_t* font = metrics->globals->hb_font;
hb_buffer_t* buf = hb_buffer_create();
uint32_t c = (uint32_t)charcode;
hb_glyph_info_t* ginfo;
hb_glyph_position_t* gpos;
unsigned int gcount;
/* we shape at a size of units per EM; this means font units */
hb_font_set_scale( font, upem, upem );
/* XXX: is this sufficient for a single character of any script? */
hb_buffer_set_direction( buf, HB_DIRECTION_LTR );
hb_buffer_set_script( buf, scripts[style_class->script] );
/* we add one character to `buf' ... */
hb_buffer_add_utf32( buf, &c, 1, 0, 1 );
/* ... and apply one feature */
hb_shape( font, buf, feature, 1 );
ginfo = hb_buffer_get_glyph_infos( buf, &gcount );
gpos = hb_buffer_get_glyph_positions( buf, &gcount );
out_idx = ginfo[0].codepoint;
/* getting the same index indicates no substitution, */
/* which means that the glyph isn't available in the feature */
if ( in_idx == out_idx )
{
*codepoint = 0;
*y_offset = 0;
}
else
{
*codepoint = out_idx;
*y_offset = gpos[0].y_offset;
}
hb_buffer_destroy( buf );
#ifdef FT_DEBUG_LEVEL_TRACE
if ( gcount > 1 )
FT_TRACE1(( "af_get_char_index:"
" input character mapped to multiple glyphs\n" ));
#endif
}
else
{
*codepoint = in_idx;
*y_offset = 0;
}
return FT_Err_Ok;
}
#else /* !FT_CONFIG_OPTION_USE_HARFBUZZ */
FT_Error
af_get_coverage( AF_FaceGlobals globals,
AF_StyleClass style_class,
FT_Byte* gstyles )
{
FT_UNUSED( globals );
FT_UNUSED( style_class );
FT_UNUSED( gstyles );
return FT_Err_Ok;
}
FT_Error
af_get_char_index( AF_StyleMetrics metrics,
FT_ULong charcode,
FT_ULong *codepoint,
FT_Long *y_offset )
{
FT_Face face;
if ( !metrics )
return FT_THROW( Invalid_Argument );
face = metrics->globals->face;
*codepoint = FT_Get_Char_Index( face, charcode );
*y_offset = 0;
return FT_Err_Ok;
}
#endif /* !FT_CONFIG_OPTION_USE_HARFBUZZ */
/* END */
| YifuLiu/AliOS-Things | components/freetype/src/autofit/hbshim.c | C | apache-2.0 | 16,455 |
/***************************************************************************/
/* */
/* hbshim.h */
/* */
/* HarfBuzz interface for accessing OpenType features (specification). */
/* */
/* Copyright 2013 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. */
/* */
/***************************************************************************/
#ifndef __HBSHIM_H__
#define __HBSHIM_H__
#include <ft2build.h>
#include FT_FREETYPE_H
#ifdef FT_CONFIG_OPTION_USE_HARFBUZZ
#include <hb.h>
#include <hb-ot.h>
#include <hb-ft.h>
#endif
FT_BEGIN_HEADER
FT_Error
af_get_coverage( AF_FaceGlobals globals,
AF_StyleClass style_class,
FT_Byte* gstyles );
FT_Error
af_get_char_index( AF_StyleMetrics metrics,
FT_ULong charcode,
FT_ULong *codepoint,
FT_Long *y_offset );
/* */
FT_END_HEADER
#endif /* __HBSHIM_H__ */
/* END */
| YifuLiu/AliOS-Things | components/freetype/src/autofit/hbshim.h | C | apache-2.0 | 1,877 |
#
# FreeType 2 auto-fitter module definition
#
# Copyright 2003, 2004, 2005, 2006 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.
FTMODULE_H_COMMANDS += AUTOFIT_MODULE
define AUTOFIT_MODULE
$(OPEN_DRIVER) FT_Module_Class, autofit_module_class $(CLOSE_DRIVER)
$(ECHO_DRIVER)autofit $(ECHO_DRIVER_DESC)automatic hinting module$(ECHO_DRIVER_DONE)
endef
# EOF
| YifuLiu/AliOS-Things | components/freetype/src/autofit/module.mk | Makefile | apache-2.0 | 671 |
#
# FreeType 2 auto-fitter module configuration rules
#
# Copyright 2003-2007, 2011, 2013 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.
# AUTOF driver directory
#
AUTOF_DIR := $(SRC_DIR)/autofit
# compilation flags for the driver
#
AUTOF_COMPILE := $(FT_COMPILE) $I$(subst /,$(COMPILER_SEP),$(AUTOF_DIR))
# AUTOF driver sources (i.e., C files)
#
AUTOF_DRV_SRC := $(AUTOF_DIR)/afangles.c \
$(AUTOF_DIR)/afblue.c \
$(AUTOF_DIR)/afcjk.c \
$(AUTOF_DIR)/afdummy.c \
$(AUTOF_DIR)/afglobal.c \
$(AUTOF_DIR)/afhints.c \
$(AUTOF_DIR)/afindic.c \
$(AUTOF_DIR)/aflatin.c \
$(AUTOF_DIR)/afloader.c \
$(AUTOF_DIR)/afmodule.c \
$(AUTOF_DIR)/afpic.c \
$(AUTOF_DIR)/afranges.c \
$(AUTOF_DIR)/afwarp.c \
$(AUTOF_DIR)/hbshim.c
# AUTOF driver headers
#
AUTOF_DRV_H := $(AUTOF_DRV_SRC:%c=%h) \
$(AUTOF_DIR)/afcover.h \
$(AUTOF_DIR)/aferrors.h \
$(AUTOF_DIR)/afscript.h \
$(AUTOF_DIR)/afstyles.h \
$(AUTOF_DIR)/aftypes.h \
$(AUTOF_DIR)/afwrtsys.h
# AUTOF driver object(s)
#
# AUTOF_DRV_OBJ_M is used during `multi' builds.
# AUTOF_DRV_OBJ_S is used during `single' builds.
#
AUTOF_DRV_OBJ_M := $(AUTOF_DRV_SRC:$(AUTOF_DIR)/%.c=$(OBJ_DIR)/%.$O)
AUTOF_DRV_OBJ_S := $(OBJ_DIR)/autofit.$O
# AUTOF driver source file for single build
#
AUTOF_DRV_SRC_S := $(AUTOF_DIR)/autofit.c
# AUTOF driver - single object
#
$(AUTOF_DRV_OBJ_S): $(AUTOF_DRV_SRC_S) $(AUTOF_DRV_SRC) \
$(FREETYPE_H) $(AUTOF_DRV_H)
$(AUTOF_COMPILE) $T$(subst /,$(COMPILER_SEP),$@ $(AUTOF_DRV_SRC_S))
# AUTOF driver - multiple objects
#
$(OBJ_DIR)/%.$O: $(AUTOF_DIR)/%.c $(FREETYPE_H) $(AUTOF_DRV_H)
$(AUTOF_COMPILE) $T$(subst /,$(COMPILER_SEP),$@ $<)
# update main driver object lists
#
DRV_OBJS_S += $(AUTOF_DRV_OBJ_S)
DRV_OBJS_M += $(AUTOF_DRV_OBJ_M)
# EOF
| YifuLiu/AliOS-Things | components/freetype/src/autofit/rules.mk | Makefile | apache-2.0 | 2,381 |
/***************************************************************************/
/* */
/* basepic.c */
/* */
/* The FreeType position independent code services for base. */
/* */
/* Copyright 2009, 2012, 2013 by */
/* Oran Agra and Mickey Gabel. */
/* */
/* 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. */
/* */
/***************************************************************************/
#include <ft2build.h>
#include FT_FREETYPE_H
#include FT_INTERNAL_OBJECTS_H
#include "basepic.h"
#ifdef FT_CONFIG_OPTION_PIC
/* forward declaration of PIC init functions from ftglyph.c */
void
FT_Init_Class_ft_outline_glyph_class( FT_Glyph_Class* clazz );
void
FT_Init_Class_ft_bitmap_glyph_class( FT_Glyph_Class* clazz );
#ifdef FT_CONFIG_OPTION_MAC_FONTS
/* forward declaration of PIC init function from ftrfork.c */
/* (not modularized) */
void
FT_Init_Table_ft_raccess_guess_table( ft_raccess_guess_rec* record );
#endif
/* forward declaration of PIC init functions from ftinit.c */
FT_Error
ft_create_default_module_classes( FT_Library library );
void
ft_destroy_default_module_classes( FT_Library library );
void
ft_base_pic_free( FT_Library library )
{
FT_PIC_Container* pic_container = &library->pic_container;
FT_Memory memory = library->memory;
if ( pic_container->base )
{
/* destroy default module classes */
/* (in case FT_Add_Default_Modules was used) */
ft_destroy_default_module_classes( library );
FT_FREE( pic_container->base );
pic_container->base = NULL;
}
}
FT_Error
ft_base_pic_init( FT_Library library )
{
FT_PIC_Container* pic_container = &library->pic_container;
FT_Error error = FT_Err_Ok;
BasePIC* container = NULL;
FT_Memory memory = library->memory;
/* allocate pointer, clear and set global container pointer */
if ( FT_ALLOC( container, sizeof ( *container ) ) )
return error;
FT_MEM_SET( container, 0, sizeof ( *container ) );
pic_container->base = container;
/* initialize default modules list and pointers */
error = ft_create_default_module_classes( library );
if ( error )
goto Exit;
/* initialize pointer table - */
/* this is how the module usually expects this data */
FT_Init_Class_ft_outline_glyph_class(
&container->ft_outline_glyph_class );
FT_Init_Class_ft_bitmap_glyph_class(
&container->ft_bitmap_glyph_class );
#ifdef FT_CONFIG_OPTION_MAC_FONTS
FT_Init_Table_ft_raccess_guess_table(
(ft_raccess_guess_rec*)&container->ft_raccess_guess_table );
#endif
Exit:
if ( error )
ft_base_pic_free( library );
return error;
}
#endif /* FT_CONFIG_OPTION_PIC */
/* END */
| YifuLiu/AliOS-Things | components/freetype/src/base/basepic.c | C | apache-2.0 | 3,726 |
/***************************************************************************/
/* */
/* basepic.h */
/* */
/* The FreeType position independent code services for base. */
/* */
/* Copyright 2009 by */
/* Oran Agra and Mickey Gabel. */
/* */
/* 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. */
/* */
/***************************************************************************/
#ifndef __BASEPIC_H__
#define __BASEPIC_H__
FT_BEGIN_HEADER
#include FT_INTERNAL_PIC_H
#ifndef FT_CONFIG_OPTION_PIC
#define FT_OUTLINE_GLYPH_CLASS_GET &ft_outline_glyph_class
#define FT_BITMAP_GLYPH_CLASS_GET &ft_bitmap_glyph_class
#define FT_DEFAULT_MODULES_GET ft_default_modules
#ifdef FT_CONFIG_OPTION_GUESSING_EMBEDDED_RFORK
#define FT_RACCESS_GUESS_TABLE_GET ft_raccess_guess_table
#endif
#else /* FT_CONFIG_OPTION_PIC */
#include FT_GLYPH_H
#ifdef FT_CONFIG_OPTION_GUESSING_EMBEDDED_RFORK
#include FT_INTERNAL_RFORK_H
#endif
typedef struct BasePIC_
{
FT_Module_Class** default_module_classes;
FT_Glyph_Class ft_outline_glyph_class;
FT_Glyph_Class ft_bitmap_glyph_class;
#ifdef FT_CONFIG_OPTION_GUESSING_EMBEDDED_RFORK
ft_raccess_guess_rec ft_raccess_guess_table[FT_RACCESS_N_RULES];
#endif
} BasePIC;
#define GET_PIC( lib ) ( (BasePIC*)( (lib)->pic_container.base ) )
#define FT_OUTLINE_GLYPH_CLASS_GET \
( &GET_PIC( library )->ft_outline_glyph_class )
#define FT_BITMAP_GLYPH_CLASS_GET \
( &GET_PIC( library )->ft_bitmap_glyph_class )
#define FT_DEFAULT_MODULES_GET \
( GET_PIC( library )->default_module_classes )
#ifdef FT_CONFIG_OPTION_GUESSING_EMBEDDED_RFORK
#define FT_RACCESS_GUESS_TABLE_GET \
( GET_PIC( library )->ft_raccess_guess_table )
#endif
/* see basepic.c for the implementation */
void
ft_base_pic_free( FT_Library library );
FT_Error
ft_base_pic_init( FT_Library library );
#endif /* FT_CONFIG_OPTION_PIC */
/* */
FT_END_HEADER
#endif /* __BASEPIC_H__ */
/* END */
| YifuLiu/AliOS-Things | components/freetype/src/base/basepic.h | C | apache-2.0 | 2,955 |
/***************************************************************************/
/* */
/* ftadvanc.c */
/* */
/* Quick computation of advance widths (body). */
/* */
/* Copyright 2008, 2009, 2011, 2013 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. */
/* */
/***************************************************************************/
#include <ft2build.h>
#include FT_INTERNAL_DEBUG_H
#include FT_ADVANCES_H
#include FT_INTERNAL_OBJECTS_H
static FT_Error
_ft_face_scale_advances( FT_Face face,
FT_Fixed* advances,
FT_UInt count,
FT_Int32 flags )
{
FT_Fixed scale;
FT_UInt nn;
if ( flags & FT_LOAD_NO_SCALE )
return FT_Err_Ok;
if ( face->size == NULL )
return FT_THROW( Invalid_Size_Handle );
if ( flags & FT_LOAD_VERTICAL_LAYOUT )
scale = face->size->metrics.y_scale;
else
scale = face->size->metrics.x_scale;
/* this must be the same scaling as to get linear{Hori,Vert}Advance */
/* (see `FT_Load_Glyph' implementation in src/base/ftobjs.c) */
for ( nn = 0; nn < count; nn++ )
advances[nn] = FT_MulDiv( advances[nn], scale, 64 );
return FT_Err_Ok;
}
/* at the moment, we can perform fast advance retrieval only in */
/* the following cases: */
/* */
/* - unscaled load */
/* - unhinted load */
/* - light-hinted load */
#define LOAD_ADVANCE_FAST_CHECK( flags ) \
( flags & ( FT_LOAD_NO_SCALE | FT_LOAD_NO_HINTING ) || \
FT_LOAD_TARGET_MODE( flags ) == FT_RENDER_MODE_LIGHT )
/* documentation is in ftadvanc.h */
FT_EXPORT_DEF( FT_Error )
FT_Get_Advance( FT_Face face,
FT_UInt gindex,
FT_Int32 flags,
FT_Fixed *padvance )
{
FT_Face_GetAdvancesFunc func;
if ( !face )
return FT_THROW( Invalid_Face_Handle );
if ( gindex >= (FT_UInt)face->num_glyphs )
return FT_THROW( Invalid_Glyph_Index );
func = face->driver->clazz->get_advances;
if ( func && LOAD_ADVANCE_FAST_CHECK( flags ) )
{
FT_Error error;
error = func( face, gindex, 1, flags, padvance );
if ( !error )
return _ft_face_scale_advances( face, padvance, 1, flags );
if ( FT_ERR_NEQ( error, Unimplemented_Feature ) )
return error;
}
return FT_Get_Advances( face, gindex, 1, flags, padvance );
}
/* documentation is in ftadvanc.h */
FT_EXPORT_DEF( FT_Error )
FT_Get_Advances( FT_Face face,
FT_UInt start,
FT_UInt count,
FT_Int32 flags,
FT_Fixed *padvances )
{
FT_Face_GetAdvancesFunc func;
FT_UInt num, end, nn;
FT_Error error = FT_Err_Ok;
if ( !face )
return FT_THROW( Invalid_Face_Handle );
num = (FT_UInt)face->num_glyphs;
end = start + count;
if ( start >= num || end < start || end > num )
return FT_THROW( Invalid_Glyph_Index );
if ( count == 0 )
return FT_Err_Ok;
func = face->driver->clazz->get_advances;
if ( func && LOAD_ADVANCE_FAST_CHECK( flags ) )
{
error = func( face, start, count, flags, padvances );
if ( !error )
return _ft_face_scale_advances( face, padvances, count, flags );
if ( FT_ERR_NEQ( error, Unimplemented_Feature ) )
return error;
}
error = FT_Err_Ok;
if ( flags & FT_ADVANCE_FLAG_FAST_ONLY )
return FT_THROW( Unimplemented_Feature );
flags |= (FT_UInt32)FT_LOAD_ADVANCE_ONLY;
for ( nn = 0; nn < count; nn++ )
{
error = FT_Load_Glyph( face, start + nn, flags );
if ( error )
break;
/* scale from 26.6 to 16.16 */
padvances[nn] = ( flags & FT_LOAD_VERTICAL_LAYOUT )
? face->glyph->advance.y << 10
: face->glyph->advance.x << 10;
}
return error;
}
/* END */
| YifuLiu/AliOS-Things | components/freetype/src/base/ftadvanc.c | C | apache-2.0 | 5,176 |
/***************************************************************************/
/* */
/* ftapi.c */
/* */
/* The FreeType compatibility functions (body). */
/* */
/* Copyright 2002 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. */
/* */
/***************************************************************************/
#include <ft2build.h>
#include FT_LIST_H
#include FT_OUTLINE_H
#include FT_INTERNAL_OBJECTS_H
#include FT_INTERNAL_DEBUG_H
#include FT_INTERNAL_STREAM_H
#include FT_TRUETYPE_TABLES_H
#include FT_OUTLINE_H
/*************************************************************************/
/*************************************************************************/
/*************************************************************************/
/**** ****/
/**** ****/
/**** C O M P A T I B I L I T Y ****/
/**** ****/
/**** ****/
/*************************************************************************/
/*************************************************************************/
/*************************************************************************/
/* backwards compatibility API */
FT_BASE_DEF( void )
FT_New_Memory_Stream( FT_Library library,
FT_Byte* base,
FT_ULong size,
FT_Stream stream )
{
FT_UNUSED( library );
FT_Stream_OpenMemory( stream, base, size );
}
FT_BASE_DEF( FT_Error )
FT_Seek_Stream( FT_Stream stream,
FT_ULong pos )
{
return FT_Stream_Seek( stream, pos );
}
FT_BASE_DEF( FT_Error )
FT_Skip_Stream( FT_Stream stream,
FT_Long distance )
{
return FT_Stream_Skip( stream, distance );
}
FT_BASE_DEF( FT_Error )
FT_Read_Stream( FT_Stream stream,
FT_Byte* buffer,
FT_ULong count )
{
return FT_Stream_Read( stream, buffer, count );
}
FT_BASE_DEF( FT_Error )
FT_Read_Stream_At( FT_Stream stream,
FT_ULong pos,
FT_Byte* buffer,
FT_ULong count )
{
return FT_Stream_ReadAt( stream, pos, buffer, count );
}
FT_BASE_DEF( FT_Error )
FT_Extract_Frame( FT_Stream stream,
FT_ULong count,
FT_Byte** pbytes )
{
return FT_Stream_ExtractFrame( stream, count, pbytes );
}
FT_BASE_DEF( void )
FT_Release_Frame( FT_Stream stream,
FT_Byte** pbytes )
{
FT_Stream_ReleaseFrame( stream, pbytes );
}
FT_BASE_DEF( FT_Error )
FT_Access_Frame( FT_Stream stream,
FT_ULong count )
{
return FT_Stream_EnterFrame( stream, count );
}
FT_BASE_DEF( void )
FT_Forget_Frame( FT_Stream stream )
{
FT_Stream_ExitFrame( stream );
}
/* END */
| YifuLiu/AliOS-Things | components/freetype/src/base/ftapi.c | C | apache-2.0 | 4,042 |
/***************************************************************************/
/* */
/* ftbase.c */
/* */
/* Single object library component (body only). */
/* */
/* Copyright 1996-2001, 2002, 2003, 2004, 2006, 2007, 2008, 2009 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. */
/* */
/***************************************************************************/
#include <ft2build.h>
#define FT_MAKE_OPTION_SINGLE_OBJECT
#include "ftpic.c"
#include "basepic.c"
#include "ftadvanc.c"
#include "ftcalc.c"
#include "ftdbgmem.c"
#include "ftgloadr.c"
#include "ftobjs.c"
#include "ftoutln.c"
#include "ftrfork.c"
#include "ftsnames.c"
#include "ftstream.c"
#include "fttrigon.c"
#include "ftutil.c"
#ifdef FT_MACINTOSH
#include "ftmac.c"
#endif
/* END */
| YifuLiu/AliOS-Things | components/freetype/src/base/ftbase.c | C | apache-2.0 | 1,644 |
/***************************************************************************/
/* */
/* ftbase.h */
/* */
/* The FreeType private functions used in base module (specification). */
/* */
/* Copyright 2008, 2010 by */
/* David Turner, Robert Wilhelm, Werner Lemberg, and suzuki toshiya. */
/* */
/* 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. */
/* */
/***************************************************************************/
#ifndef __FTBASE_H__
#define __FTBASE_H__
#include <ft2build.h>
#include FT_INTERNAL_OBJECTS_H
FT_BEGIN_HEADER
/* Assume the stream is sfnt-wrapped PS Type1 or sfnt-wrapped CID-keyed */
/* font, and try to load a face specified by the face_index. */
FT_LOCAL( FT_Error )
open_face_PS_from_sfnt_stream( FT_Library library,
FT_Stream stream,
FT_Long face_index,
FT_Int num_params,
FT_Parameter *params,
FT_Face *aface );
/* Create a new FT_Face given a buffer and a driver name. */
/* From ftmac.c. */
FT_LOCAL( FT_Error )
open_face_from_buffer( FT_Library library,
FT_Byte* base,
FT_ULong size,
FT_Long face_index,
const char* driver_name,
FT_Face *aface );
#if defined( FT_CONFIG_OPTION_GUESSING_EMBEDDED_RFORK ) && \
!defined( FT_MACINTOSH )
/* Mac OS X/Darwin kernel often changes recommended method to access */
/* the resource fork and older methods makes the kernel issue the */
/* warning of deprecated method. To calm it down, the methods based */
/* on Darwin VFS should be grouped and skip the rest methods after */
/* the case the resource is opened but found to lack a font in it. */
FT_LOCAL( FT_Bool )
ft_raccess_rule_by_darwin_vfs( FT_Library library, FT_UInt rule_index );
#endif
FT_END_HEADER
#endif /* __FTBASE_H__ */
/* END */
| YifuLiu/AliOS-Things | components/freetype/src/base/ftbase.h | C | apache-2.0 | 2,947 |
/***************************************************************************/
/* */
/* ftbbox.c */
/* */
/* FreeType bbox computation (body). */
/* */
/* Copyright 1996-2002, 2004, 2006, 2010, 2013 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. */
/* */
/***************************************************************************/
/*************************************************************************/
/* */
/* This component has a _single_ role: to compute exact outline bounding */
/* boxes. */
/* */
/*************************************************************************/
#include <ft2build.h>
#include FT_INTERNAL_DEBUG_H
#include FT_BBOX_H
#include FT_IMAGE_H
#include FT_OUTLINE_H
#include FT_INTERNAL_CALC_H
#include FT_INTERNAL_OBJECTS_H
typedef struct TBBox_Rec_
{
FT_Vector last;
FT_BBox bbox;
} TBBox_Rec;
/*************************************************************************/
/* */
/* <Function> */
/* BBox_Move_To */
/* */
/* <Description> */
/* This function is used as a `move_to' and `line_to' emitter during */
/* FT_Outline_Decompose(). It simply records the destination point */
/* in `user->last'; no further computations are necessary since we */
/* use the cbox as the starting bbox which must be refined. */
/* */
/* <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. */
/* */
static int
BBox_Move_To( FT_Vector* to,
TBBox_Rec* user )
{
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> */
/* 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. */
/* */
static void
BBox_Conic_Check( FT_Pos y1,
FT_Pos y2,
FT_Pos y3,
FT_Pos* min,
FT_Pos* max )
{
/* 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 */
y1 -= y2;
y3 -= y2;
y2 += FT_MulDiv( y1, y3, y1 + y3 );
if ( y2 < *min )
*min = y2;
if ( y2 > *max )
*max = y2;
}
/*************************************************************************/
/* */
/* <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. */
/* */
static int
BBox_Conic_To( FT_Vector* control,
FT_Vector* to,
TBBox_Rec* user )
{
/* we don't need to check `to' since it is always an `on' point, thus */
/* within the bbox */
if ( CHECK_X( control, user->bbox ) )
BBox_Conic_Check( user->last.x,
control->x,
to->x,
&user->bbox.xMin,
&user->bbox.xMax );
if ( CHECK_Y( control, user->bbox ) )
BBox_Conic_Check( user->last.y,
control->y,
to->y,
&user->bbox.yMin,
&user->bbox.yMax );
user->last = *to;
return 0;
}
/*************************************************************************/
/* */
/* <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. */
/* */
static FT_Pos
update_cubic_max( FT_Pos q1,
FT_Pos q2,
FT_Pos q3,
FT_Pos q4,
FT_Pos max )
{
/* for a cubic segment to possibly reach new maximum, at least */
/* one of its off-points must stay above the current value */
while ( q2 > max || q3 > max )
{
/* determine which half contains the maximum and split */
if ( q1 + q2 > q3 + q4 ) /* first half */
{
q4 = q4 + q3;
q3 = q3 + q2;
q2 = q2 + q1;
q4 = q4 + q3;
q3 = q3 + q2;
q4 = ( q4 + q3 ) / 8;
q3 = q3 / 4;
q2 = q2 / 2;
}
else /* second half */
{
q1 = q1 + q2;
q2 = q2 + q3;
q3 = q3 + q4;
q1 = q1 + q2;
q2 = q2 + q3;
q1 = ( q1 + q2 ) / 8;
q2 = q2 / 4;
q3 = q3 / 2;
}
/* check whether either end reached the maximum */
if ( q1 == q2 && q1 >= q3 )
{
max = q1;
break;
}
if ( q3 == q4 && q2 <= q4 )
{
max = q4;
break;
}
}
return max;
}
static void
BBox_Cubic_Check( FT_Pos p1,
FT_Pos p2,
FT_Pos p3,
FT_Pos p4,
FT_Pos* min,
FT_Pos* max )
{
FT_Pos nmin, nmax;
FT_Int shift;
/* 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 using iterative bisection of the segment. */
/* 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. */
/* The control off-point outside the bbox is likely to have the top */
/* absolute value among arguments. */
shift = 27 - FT_MSB( FT_ABS( p2 ) | FT_ABS( p3 ) );
if ( shift > 0 )
{
/* upscaling too much just wastes time */
if ( shift > 2 )
shift = 2;
p1 <<= shift;
p2 <<= shift;
p3 <<= shift;
p4 <<= shift;
nmin = *min << shift;
nmax = *max << shift;
}
else
{
p1 >>= -shift;
p2 >>= -shift;
p3 >>= -shift;
p4 >>= -shift;
nmin = *min >> -shift;
nmax = *max >> -shift;
}
nmax = update_cubic_max( p1, p2, p3, p4, nmax );
/* now flip the signs to update the minimum */
nmin = -update_cubic_max( -p1, -p2, -p3, -p4, -nmin );
if ( shift > 0 )
{
nmin >>= shift;
nmax >>= shift;
}
else
{
nmin <<= -shift;
nmax <<= -shift;
}
if ( nmin < *min )
*min = nmin;
if ( nmax > *max )
*max = nmax;
}
/*************************************************************************/
/* */
/* <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. */
/* */
static int
BBox_Cubic_To( FT_Vector* control1,
FT_Vector* control2,
FT_Vector* to,
TBBox_Rec* user )
{
/* 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. */
if ( CHECK_X( control1, user->bbox ) ||
CHECK_X( control2, user->bbox ) )
BBox_Cubic_Check( user->last.x,
control1->x,
control2->x,
to->x,
&user->bbox.xMin,
&user->bbox.xMax );
if ( CHECK_Y( control1, user->bbox ) ||
CHECK_Y( control2, user->bbox ) )
BBox_Cubic_Check( user->last.y,
control1->y,
control2->y,
to->y,
&user->bbox.yMin,
&user->bbox.yMax );
user->last = *to;
return 0;
}
FT_DEFINE_OUTLINE_FUNCS(bbox_interface,
(FT_Outline_MoveTo_Func) BBox_Move_To,
(FT_Outline_LineTo_Func) BBox_Move_To,
(FT_Outline_ConicTo_Func)BBox_Conic_To,
(FT_Outline_CubicTo_Func)BBox_Cubic_To,
0, 0
)
/* documentation is in ftbbox.h */
FT_EXPORT_DEF( FT_Error )
FT_Outline_Get_BBox( FT_Outline* outline,
FT_BBox *abbox )
{
FT_BBox cbox;
FT_BBox bbox;
FT_Vector* vec;
FT_UShort n;
if ( !abbox )
return FT_THROW( Invalid_Argument );
if ( !outline )
return FT_THROW( Invalid_Outline );
/* if outline is empty, return (0,0,0,0) */
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;
vec++;
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;
if ( FT_CURVE_TAG( outline->tags[n] ) == FT_CURVE_TAG_ON )
{
/* 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. */
FT_Error error;
TBBox_Rec user;
#ifdef FT_CONFIG_OPTION_PIC
FT_Outline_Funcs bbox_interface;
Init_Class_bbox_interface(&bbox_interface);
#endif
user.bbox = bbox;
error = FT_Outline_Decompose( outline, &bbox_interface, &user );
if ( error )
return error;
*abbox = user.bbox;
}
else
*abbox = bbox;
return FT_Err_Ok;
}
/* END */
| YifuLiu/AliOS-Things | components/freetype/src/base/ftbbox.c | C | apache-2.0 | 19,667 |
/***************************************************************************/
/* */
/* ftbdf.c */
/* */
/* FreeType API for accessing BDF-specific strings (body). */
/* */
/* Copyright 2002-2004, 2013 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. */
/* */
/***************************************************************************/
#include <ft2build.h>
#include FT_INTERNAL_OBJECTS_H
#include FT_SERVICE_BDF_H
/* documentation is in ftbdf.h */
FT_EXPORT_DEF( FT_Error )
FT_Get_BDF_Charset_ID( FT_Face face,
const char* *acharset_encoding,
const char* *acharset_registry )
{
FT_Error error;
const char* encoding = NULL;
const char* registry = NULL;
error = FT_ERR( Invalid_Argument );
if ( face )
{
FT_Service_BDF service;
FT_FACE_FIND_SERVICE( face, service, BDF );
if ( service && service->get_charset_id )
error = service->get_charset_id( face, &encoding, ®istry );
}
if ( acharset_encoding )
*acharset_encoding = encoding;
if ( acharset_registry )
*acharset_registry = registry;
return error;
}
/* documentation is in ftbdf.h */
FT_EXPORT_DEF( FT_Error )
FT_Get_BDF_Property( FT_Face face,
const char* prop_name,
BDF_PropertyRec *aproperty )
{
FT_Error error;
error = FT_ERR( Invalid_Argument );
aproperty->type = BDF_PROPERTY_TYPE_NONE;
if ( face )
{
FT_Service_BDF service;
FT_FACE_FIND_SERVICE( face, service, BDF );
if ( service && service->get_property )
error = service->get_property( face, prop_name, aproperty );
}
return error;
}
/* END */
| YifuLiu/AliOS-Things | components/freetype/src/base/ftbdf.c | C | apache-2.0 | 2,682 |
/***************************************************************************/
/* */
/* ftbitmap.c */
/* */
/* FreeType utility functions for bitmaps (body). */
/* */
/* Copyright 2004-2009, 2011, 2013, 2014 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. */
/* */
/***************************************************************************/
#include <ft2build.h>
#include FT_INTERNAL_DEBUG_H
#include FT_BITMAP_H
#include FT_IMAGE_H
#include FT_INTERNAL_OBJECTS_H
static
const FT_Bitmap null_bitmap = { 0, 0, 0, 0, 0, 0, 0, 0 };
/* documentation is in ftbitmap.h */
FT_EXPORT_DEF( void )
FT_Bitmap_New( FT_Bitmap *abitmap )
{
*abitmap = null_bitmap;
}
/* documentation is in ftbitmap.h */
FT_EXPORT_DEF( FT_Error )
FT_Bitmap_Copy( FT_Library library,
const FT_Bitmap *source,
FT_Bitmap *target)
{
FT_Memory memory = library->memory;
FT_Error error = FT_Err_Ok;
FT_Int pitch = source->pitch;
FT_ULong size;
if ( source == target )
return FT_Err_Ok;
if ( source->buffer == NULL )
{
*target = *source;
return FT_Err_Ok;
}
if ( pitch < 0 )
pitch = -pitch;
size = (FT_ULong)( pitch * source->rows );
if ( target->buffer )
{
FT_Int target_pitch = target->pitch;
FT_ULong target_size;
if ( target_pitch < 0 )
target_pitch = -target_pitch;
target_size = (FT_ULong)( target_pitch * target->rows );
if ( target_size != size )
(void)FT_QREALLOC( target->buffer, target_size, size );
}
else
(void)FT_QALLOC( target->buffer, size );
if ( !error )
{
unsigned char *p;
p = target->buffer;
*target = *source;
target->buffer = p;
FT_MEM_COPY( target->buffer, source->buffer, size );
}
return error;
}
static FT_Error
ft_bitmap_assure_buffer( FT_Memory memory,
FT_Bitmap* bitmap,
FT_UInt xpixels,
FT_UInt ypixels )
{
FT_Error error;
int pitch;
int new_pitch;
FT_UInt bpp;
FT_Int i, width, height;
unsigned char* buffer = NULL;
width = bitmap->width;
height = bitmap->rows;
pitch = bitmap->pitch;
if ( pitch < 0 )
pitch = -pitch;
switch ( bitmap->pixel_mode )
{
case FT_PIXEL_MODE_MONO:
bpp = 1;
new_pitch = ( width + xpixels + 7 ) >> 3;
break;
case FT_PIXEL_MODE_GRAY2:
bpp = 2;
new_pitch = ( width + xpixels + 3 ) >> 2;
break;
case FT_PIXEL_MODE_GRAY4:
bpp = 4;
new_pitch = ( width + xpixels + 1 ) >> 1;
break;
case FT_PIXEL_MODE_GRAY:
case FT_PIXEL_MODE_LCD:
case FT_PIXEL_MODE_LCD_V:
bpp = 8;
new_pitch = ( width + xpixels );
break;
default:
return FT_THROW( Invalid_Glyph_Format );
}
/* if no need to allocate memory */
if ( ypixels == 0 && new_pitch <= pitch )
{
/* zero the padding */
FT_Int bit_width = pitch * 8;
FT_Int bit_last = ( width + xpixels ) * bpp;
if ( bit_last < bit_width )
{
FT_Byte* line = bitmap->buffer + ( bit_last >> 3 );
FT_Byte* end = bitmap->buffer + pitch;
FT_Int shift = bit_last & 7;
FT_UInt mask = 0xFF00U >> shift;
FT_Int count = height;
for ( ; count > 0; count--, line += pitch, end += pitch )
{
FT_Byte* write = line;
if ( shift > 0 )
{
write[0] = (FT_Byte)( write[0] & mask );
write++;
}
if ( write < end )
FT_MEM_ZERO( write, end-write );
}
}
return FT_Err_Ok;
}
if ( FT_QALLOC_MULT( buffer, new_pitch, bitmap->rows + ypixels ) )
return error;
if ( bitmap->pitch > 0 )
{
FT_Int len = ( width * bpp + 7 ) >> 3;
for ( i = 0; i < bitmap->rows; i++ )
FT_MEM_COPY( buffer + new_pitch * ( ypixels + i ),
bitmap->buffer + pitch * i, len );
}
else
{
FT_Int len = ( width * bpp + 7 ) >> 3;
for ( i = 0; i < bitmap->rows; i++ )
FT_MEM_COPY( buffer + new_pitch * i,
bitmap->buffer + pitch * i, len );
}
FT_FREE( bitmap->buffer );
bitmap->buffer = buffer;
if ( bitmap->pitch < 0 )
new_pitch = -new_pitch;
/* set pitch only, width and height are left untouched */
bitmap->pitch = new_pitch;
return FT_Err_Ok;
}
/* documentation is in ftbitmap.h */
FT_EXPORT_DEF( FT_Error )
FT_Bitmap_Embolden( FT_Library library,
FT_Bitmap* bitmap,
FT_Pos xStrength,
FT_Pos yStrength )
{
FT_Error error;
unsigned char* p;
FT_Int i, x, y, pitch;
FT_Int xstr, ystr;
if ( !library )
return FT_THROW( Invalid_Library_Handle );
if ( !bitmap || !bitmap->buffer )
return FT_THROW( Invalid_Argument );
if ( ( ( FT_PIX_ROUND( xStrength ) >> 6 ) > FT_INT_MAX ) ||
( ( FT_PIX_ROUND( yStrength ) >> 6 ) > FT_INT_MAX ) )
return FT_THROW( Invalid_Argument );
xstr = (FT_Int)FT_PIX_ROUND( xStrength ) >> 6;
ystr = (FT_Int)FT_PIX_ROUND( yStrength ) >> 6;
if ( xstr == 0 && ystr == 0 )
return FT_Err_Ok;
else if ( xstr < 0 || ystr < 0 )
return FT_THROW( Invalid_Argument );
switch ( bitmap->pixel_mode )
{
case FT_PIXEL_MODE_GRAY2:
case FT_PIXEL_MODE_GRAY4:
{
FT_Bitmap tmp;
FT_Int align;
if ( bitmap->pixel_mode == FT_PIXEL_MODE_GRAY2 )
align = ( bitmap->width + xstr + 3 ) / 4;
else
align = ( bitmap->width + xstr + 1 ) / 2;
FT_Bitmap_New( &tmp );
error = FT_Bitmap_Convert( library, bitmap, &tmp, align );
if ( error )
return error;
FT_Bitmap_Done( library, bitmap );
*bitmap = tmp;
}
break;
case FT_PIXEL_MODE_MONO:
if ( xstr > 8 )
xstr = 8;
break;
case FT_PIXEL_MODE_LCD:
xstr *= 3;
break;
case FT_PIXEL_MODE_LCD_V:
ystr *= 3;
break;
case FT_PIXEL_MODE_BGRA:
/* We don't embolden color glyphs. */
return FT_Err_Ok;
}
error = ft_bitmap_assure_buffer( library->memory, bitmap, xstr, ystr );
if ( error )
return error;
pitch = bitmap->pitch;
if ( pitch > 0 )
p = bitmap->buffer + pitch * ystr;
else
{
pitch = -pitch;
p = bitmap->buffer + pitch * ( bitmap->rows - 1 );
}
/* for each row */
for ( y = 0; y < bitmap->rows ; y++ )
{
/*
* Horizontally:
*
* From the last pixel on, make each pixel or'ed with the
* `xstr' pixels before it.
*/
for ( x = pitch - 1; x >= 0; x-- )
{
unsigned char tmp;
tmp = p[x];
for ( i = 1; i <= xstr; i++ )
{
if ( bitmap->pixel_mode == FT_PIXEL_MODE_MONO )
{
p[x] |= tmp >> i;
/* the maximum value of 8 for `xstr' comes from here */
if ( x > 0 )
p[x] |= p[x - 1] << ( 8 - i );
#if 0
if ( p[x] == 0xff )
break;
#endif
}
else
{
if ( x - i >= 0 )
{
if ( p[x] + p[x - i] > bitmap->num_grays - 1 )
{
p[x] = (unsigned char)(bitmap->num_grays - 1);
break;
}
else
{
p[x] = (unsigned char)(p[x] + p[x-i]);
if ( p[x] == bitmap->num_grays - 1 )
break;
}
}
else
break;
}
}
}
/*
* Vertically:
*
* Make the above `ystr' rows or'ed with it.
*/
for ( x = 1; x <= ystr; x++ )
{
unsigned char* q;
q = p - bitmap->pitch * x;
for ( i = 0; i < pitch; i++ )
q[i] |= p[i];
}
p += bitmap->pitch;
}
bitmap->width += xstr;
bitmap->rows += ystr;
return FT_Err_Ok;
}
static FT_Byte
ft_gray_for_premultiplied_srgb_bgra( const FT_Byte* bgra )
{
FT_Long a = bgra[3];
FT_Long b = bgra[0];
FT_Long g = bgra[1];
FT_Long r = bgra[2];
FT_Long l;
/* Short-circuit transparent color to avoid div-by-zero. */
if ( !a )
return 0;
/*
* Luminosity for sRGB is defined using ~0.2126,0.7152,0.0722
* coefficients for RGB channels *on the linear colors*.
* A gamma of 2.2 is fair to assume. And then, we need to
* undo the premultiplication too.
*
* http://accessibility.kde.org/hsl-adjusted.php
*
* We do the computation with integers only.
*/
/* Undo premultification, get the number in a 16.16 form. */
b = FT_MulDiv( b, 65536, a );
g = FT_MulDiv( g, 65536, a );
r = FT_MulDiv( r, 65536, a );
a = a * 256;
/* Apply gamma of 2.0 instead of 2.2. */
b = FT_MulFix( b, b );
g = FT_MulFix( g, g );
r = FT_MulFix( r, r );
/* Apply coefficients. */
b = FT_MulFix( b, 4731 /* 0.0722 * 65536 */ );
g = FT_MulFix( g, 46871 /* 0.7152 * 65536 */ );
r = FT_MulFix( r, 13933 /* 0.2126 * 65536 */ );
l = r + g + b;
/*
* Final transparency can be determined this way:
*
* - If alpha is zero, we want 0.
* - If alpha is zero and luminosity is zero, we want 255.
* - If alpha is zero and luminosity is one, we want 0.
*
* So the formula is a * (1 - l).
*/
return (FT_Byte)( FT_MulFix( 65535 - l, a ) >> 8 );
}
/* documentation is in ftbitmap.h */
FT_EXPORT_DEF( FT_Error )
FT_Bitmap_Convert( FT_Library library,
const FT_Bitmap *source,
FT_Bitmap *target,
FT_Int alignment )
{
FT_Error error = FT_Err_Ok;
FT_Memory memory;
if ( !library )
return FT_THROW( Invalid_Library_Handle );
memory = library->memory;
switch ( source->pixel_mode )
{
case FT_PIXEL_MODE_MONO:
case FT_PIXEL_MODE_GRAY:
case FT_PIXEL_MODE_GRAY2:
case FT_PIXEL_MODE_GRAY4:
case FT_PIXEL_MODE_LCD:
case FT_PIXEL_MODE_LCD_V:
case FT_PIXEL_MODE_BGRA:
{
FT_Int pad;
FT_Long old_size;
old_size = target->rows * target->pitch;
if ( old_size < 0 )
old_size = -old_size;
target->pixel_mode = FT_PIXEL_MODE_GRAY;
target->rows = source->rows;
target->width = source->width;
pad = 0;
if ( alignment > 0 )
{
pad = source->width % alignment;
if ( pad != 0 )
pad = alignment - pad;
}
target->pitch = source->width + pad;
if ( target->pitch > 0 &&
(FT_ULong)target->rows > FT_ULONG_MAX / target->pitch )
return FT_THROW( Invalid_Argument );
if ( target->rows * target->pitch > old_size &&
FT_QREALLOC( target->buffer,
old_size, target->rows * target->pitch ) )
return error;
}
break;
default:
error = FT_THROW( Invalid_Argument );
}
switch ( source->pixel_mode )
{
case FT_PIXEL_MODE_MONO:
{
FT_Byte* s = source->buffer;
FT_Byte* t = target->buffer;
FT_Int i;
target->num_grays = 2;
for ( i = source->rows; i > 0; i-- )
{
FT_Byte* ss = s;
FT_Byte* tt = t;
FT_Int j;
/* get the full bytes */
for ( j = source->width >> 3; j > 0; j-- )
{
FT_Int val = ss[0]; /* avoid a byte->int cast on each line */
tt[0] = (FT_Byte)( ( val & 0x80 ) >> 7 );
tt[1] = (FT_Byte)( ( val & 0x40 ) >> 6 );
tt[2] = (FT_Byte)( ( val & 0x20 ) >> 5 );
tt[3] = (FT_Byte)( ( val & 0x10 ) >> 4 );
tt[4] = (FT_Byte)( ( val & 0x08 ) >> 3 );
tt[5] = (FT_Byte)( ( val & 0x04 ) >> 2 );
tt[6] = (FT_Byte)( ( val & 0x02 ) >> 1 );
tt[7] = (FT_Byte)( val & 0x01 );
tt += 8;
ss += 1;
}
/* get remaining pixels (if any) */
j = source->width & 7;
if ( j > 0 )
{
FT_Int val = *ss;
for ( ; j > 0; j-- )
{
tt[0] = (FT_Byte)( ( val & 0x80 ) >> 7);
val <<= 1;
tt += 1;
}
}
s += source->pitch;
t += target->pitch;
}
}
break;
case FT_PIXEL_MODE_GRAY:
case FT_PIXEL_MODE_LCD:
case FT_PIXEL_MODE_LCD_V:
{
FT_Int width = source->width;
FT_Byte* s = source->buffer;
FT_Byte* t = target->buffer;
FT_Int s_pitch = source->pitch;
FT_Int t_pitch = target->pitch;
FT_Int i;
target->num_grays = 256;
for ( i = source->rows; i > 0; i-- )
{
FT_ARRAY_COPY( t, s, width );
s += s_pitch;
t += t_pitch;
}
}
break;
case FT_PIXEL_MODE_GRAY2:
{
FT_Byte* s = source->buffer;
FT_Byte* t = target->buffer;
FT_Int i;
target->num_grays = 4;
for ( i = source->rows; i > 0; i-- )
{
FT_Byte* ss = s;
FT_Byte* tt = t;
FT_Int j;
/* get the full bytes */
for ( j = source->width >> 2; j > 0; j-- )
{
FT_Int val = ss[0];
tt[0] = (FT_Byte)( ( val & 0xC0 ) >> 6 );
tt[1] = (FT_Byte)( ( val & 0x30 ) >> 4 );
tt[2] = (FT_Byte)( ( val & 0x0C ) >> 2 );
tt[3] = (FT_Byte)( ( val & 0x03 ) );
ss += 1;
tt += 4;
}
j = source->width & 3;
if ( j > 0 )
{
FT_Int val = ss[0];
for ( ; j > 0; j-- )
{
tt[0] = (FT_Byte)( ( val & 0xC0 ) >> 6 );
val <<= 2;
tt += 1;
}
}
s += source->pitch;
t += target->pitch;
}
}
break;
case FT_PIXEL_MODE_GRAY4:
{
FT_Byte* s = source->buffer;
FT_Byte* t = target->buffer;
FT_Int i;
target->num_grays = 16;
for ( i = source->rows; i > 0; i-- )
{
FT_Byte* ss = s;
FT_Byte* tt = t;
FT_Int j;
/* get the full bytes */
for ( j = source->width >> 1; j > 0; j-- )
{
FT_Int val = ss[0];
tt[0] = (FT_Byte)( ( val & 0xF0 ) >> 4 );
tt[1] = (FT_Byte)( ( val & 0x0F ) );
ss += 1;
tt += 2;
}
if ( source->width & 1 )
tt[0] = (FT_Byte)( ( ss[0] & 0xF0 ) >> 4 );
s += source->pitch;
t += target->pitch;
}
}
break;
case FT_PIXEL_MODE_BGRA:
{
FT_Byte* s = source->buffer;
FT_Byte* t = target->buffer;
FT_Int s_pitch = source->pitch;
FT_Int t_pitch = target->pitch;
FT_Int i;
target->num_grays = 256;
for ( i = source->rows; i > 0; i-- )
{
FT_Byte* ss = s;
FT_Byte* tt = t;
FT_Int j;
for ( j = source->width; j > 0; j-- )
{
tt[0] = ft_gray_for_premultiplied_srgb_bgra( ss );
ss += 4;
tt += 1;
}
s += s_pitch;
t += t_pitch;
}
}
break;
default:
;
}
return error;
}
/* documentation is in ftbitmap.h */
FT_EXPORT_DEF( FT_Error )
FT_GlyphSlot_Own_Bitmap( FT_GlyphSlot slot )
{
if ( slot && slot->format == FT_GLYPH_FORMAT_BITMAP &&
!( slot->internal->flags & FT_GLYPH_OWN_BITMAP ) )
{
FT_Bitmap bitmap;
FT_Error error;
FT_Bitmap_New( &bitmap );
error = FT_Bitmap_Copy( slot->library, &slot->bitmap, &bitmap );
if ( error )
return error;
slot->bitmap = bitmap;
slot->internal->flags |= FT_GLYPH_OWN_BITMAP;
}
return FT_Err_Ok;
}
/* documentation is in ftbitmap.h */
FT_EXPORT_DEF( FT_Error )
FT_Bitmap_Done( FT_Library library,
FT_Bitmap *bitmap )
{
FT_Memory memory;
if ( !library )
return FT_THROW( Invalid_Library_Handle );
if ( !bitmap )
return FT_THROW( Invalid_Argument );
memory = library->memory;
FT_FREE( bitmap->buffer );
*bitmap = null_bitmap;
return FT_Err_Ok;
}
/* END */
| YifuLiu/AliOS-Things | components/freetype/src/base/ftbitmap.c | C | apache-2.0 | 18,012 |
/***************************************************************************/
/* */
/* ftcalc.c */
/* */
/* Arithmetic computations (body). */
/* */
/* Copyright 1996-2006, 2008, 2012-2014 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. */
/* */
/***************************************************************************/
/*************************************************************************/
/* */
/* Support for 1-complement arithmetic has been totally dropped in this */
/* release. You can still write your own code if you need it. */
/* */
/*************************************************************************/
/*************************************************************************/
/* */
/* Implementing basic computation routines. */
/* */
/* FT_MulDiv(), FT_MulFix(), FT_DivFix(), FT_RoundFix(), FT_CeilFix(), */
/* and FT_FloorFix() are declared in freetype.h. */
/* */
/*************************************************************************/
#include <ft2build.h>
#include FT_GLYPH_H
#include FT_TRIGONOMETRY_H
#include FT_INTERNAL_CALC_H
#include FT_INTERNAL_DEBUG_H
#include FT_INTERNAL_OBJECTS_H
#ifdef FT_MULFIX_INLINED
#undef FT_MulFix
#endif
/* we need to emulate a 64-bit data type if a real one isn't available */
#ifndef FT_LONG64
typedef struct FT_Int64_
{
FT_UInt32 lo;
FT_UInt32 hi;
} FT_Int64;
#endif /* !FT_LONG64 */
/*************************************************************************/
/* */
/* The macro FT_COMPONENT is used in trace mode. It is an implicit */
/* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */
/* messages during execution. */
/* */
#undef FT_COMPONENT
#define FT_COMPONENT trace_calc
/* The following three functions are available regardless of whether */
/* FT_LONG64 is defined. */
/* documentation is in freetype.h */
FT_EXPORT_DEF( FT_Fixed )
FT_RoundFix( FT_Fixed a )
{
return ( a >= 0 ) ? ( a + 0x8000L ) & ~0xFFFFL
: -((-a + 0x8000L ) & ~0xFFFFL );
}
/* documentation is in freetype.h */
FT_EXPORT_DEF( FT_Fixed )
FT_CeilFix( FT_Fixed a )
{
return ( a >= 0 ) ? ( a + 0xFFFFL ) & ~0xFFFFL
: -((-a + 0xFFFFL ) & ~0xFFFFL );
}
/* documentation is in freetype.h */
FT_EXPORT_DEF( FT_Fixed )
FT_FloorFix( FT_Fixed a )
{
return ( a >= 0 ) ? a & ~0xFFFFL
: -((-a) & ~0xFFFFL );
}
FT_BASE_DEF ( FT_Int )
FT_MSB( FT_UInt32 z )
{
FT_Int shift = 0;
/* determine msb bit index in `shift' */
if ( z >= ( 1L << 16 ) )
{
z >>= 16;
shift += 16;
}
if ( z >= ( 1L << 8 ) )
{
z >>= 8;
shift += 8;
}
if ( z >= ( 1L << 4 ) )
{
z >>= 4;
shift += 4;
}
if ( z >= ( 1L << 2 ) )
{
z >>= 2;
shift += 2;
}
if ( z >= ( 1L << 1 ) )
{
/* z >>= 1; */
shift += 1;
}
return shift;
}
/* documentation is in ftcalc.h */
FT_BASE_DEF( FT_Fixed )
FT_Hypot( FT_Fixed x,
FT_Fixed y )
{
FT_Vector v;
v.x = x;
v.y = y;
return FT_Vector_Length( &v );
}
#ifdef FT_LONG64
/* documentation is in freetype.h */
FT_EXPORT_DEF( FT_Long )
FT_MulDiv( FT_Long a,
FT_Long b,
FT_Long c )
{
FT_Int s;
FT_Long d;
s = 1;
if ( a < 0 ) { a = -a; s = -1; }
if ( b < 0 ) { b = -b; s = -s; }
if ( c < 0 ) { c = -c; s = -s; }
d = (FT_Long)( c > 0 ? ( (FT_Int64)a * b + ( c >> 1 ) ) / c
: 0x7FFFFFFFL );
return ( s > 0 ) ? d : -d;
}
/* documentation is in ftcalc.h */
FT_BASE_DEF( FT_Long )
FT_MulDiv_No_Round( FT_Long a,
FT_Long b,
FT_Long c )
{
FT_Int s;
FT_Long d;
s = 1;
if ( a < 0 ) { a = -a; s = -1; }
if ( b < 0 ) { b = -b; s = -s; }
if ( c < 0 ) { c = -c; s = -s; }
d = (FT_Long)( c > 0 ? (FT_Int64)a * b / c
: 0x7FFFFFFFL );
return ( s > 0 ) ? d : -d;
}
/* documentation is in freetype.h */
FT_EXPORT_DEF( FT_Long )
FT_MulFix( FT_Long a,
FT_Long b )
{
#ifdef FT_MULFIX_ASSEMBLER
return FT_MULFIX_ASSEMBLER( a, b );
#else
FT_Int s = 1;
FT_Long c;
if ( a < 0 )
{
a = -a;
s = -1;
}
if ( b < 0 )
{
b = -b;
s = -s;
}
c = (FT_Long)( ( (FT_Int64)a * b + 0x8000L ) >> 16 );
return ( s > 0 ) ? c : -c;
#endif /* FT_MULFIX_ASSEMBLER */
}
/* documentation is in freetype.h */
FT_EXPORT_DEF( FT_Long )
FT_DivFix( FT_Long a,
FT_Long b )
{
FT_Int32 s;
FT_UInt32 q;
s = 1;
if ( a < 0 )
{
a = -a;
s = -1;
}
if ( b < 0 )
{
b = -b;
s = -s;
}
if ( b == 0 )
/* check for division by 0 */
q = 0x7FFFFFFFL;
else
/* compute result directly */
q = (FT_UInt32)( ( ( (FT_UInt64)a << 16 ) + ( b >> 1 ) ) / b );
return ( s < 0 ? -(FT_Long)q : (FT_Long)q );
}
#else /* !FT_LONG64 */
static void
ft_multo64( FT_UInt32 x,
FT_UInt32 y,
FT_Int64 *z )
{
FT_UInt32 lo1, hi1, lo2, hi2, lo, hi, i1, i2;
lo1 = x & 0x0000FFFFU; hi1 = x >> 16;
lo2 = y & 0x0000FFFFU; hi2 = y >> 16;
lo = lo1 * lo2;
i1 = lo1 * hi2;
i2 = lo2 * hi1;
hi = hi1 * hi2;
/* Check carry overflow of i1 + i2 */
i1 += i2;
hi += (FT_UInt32)( i1 < i2 ) << 16;
hi += i1 >> 16;
i1 = i1 << 16;
/* Check carry overflow of i1 + lo */
lo += i1;
hi += ( lo < i1 );
z->lo = lo;
z->hi = hi;
}
static FT_UInt32
ft_div64by32( FT_UInt32 hi,
FT_UInt32 lo,
FT_UInt32 y )
{
FT_UInt32 r, q;
FT_Int i;
q = 0;
r = hi;
if ( r >= y )
return (FT_UInt32)0x7FFFFFFFL;
i = 32;
do
{
r <<= 1;
q <<= 1;
r |= lo >> 31;
if ( r >= y )
{
r -= y;
q |= 1;
}
lo <<= 1;
} while ( --i );
return q;
}
static void
FT_Add64( FT_Int64* x,
FT_Int64* y,
FT_Int64 *z )
{
register FT_UInt32 lo, hi;
lo = x->lo + y->lo;
hi = x->hi + y->hi + ( lo < x->lo );
z->lo = lo;
z->hi = hi;
}
/* documentation is in freetype.h */
/* The FT_MulDiv function has been optimized thanks to ideas from */
/* Graham Asher. The trick is to optimize computation when everything */
/* fits within 32-bits (a rather common case). */
/* */
/* we compute 'a*b+c/2', then divide it by 'c'. (positive values) */
/* */
/* 46340 is FLOOR(SQRT(2^31-1)). */
/* */
/* if ( a <= 46340 && b <= 46340 ) then ( a*b <= 0x7FFEA810 ) */
/* */
/* 0x7FFFFFFF - 0x7FFEA810 = 0x157F0 */
/* */
/* if ( c < 0x157F0*2 ) then ( a*b+c/2 <= 0x7FFFFFFF ) */
/* */
/* and 2*0x157F0 = 176096 */
/* */
FT_EXPORT_DEF( FT_Long )
FT_MulDiv( FT_Long a,
FT_Long b,
FT_Long c )
{
long s;
/* XXX: this function does not allow 64-bit arguments */
if ( a == 0 || b == c )
return a;
s = a; a = FT_ABS( a );
s ^= b; b = FT_ABS( b );
s ^= c; c = FT_ABS( c );
if ( a <= 46340L && b <= 46340L && c <= 176095L && c > 0 )
a = ( a * b + ( c >> 1 ) ) / c;
else if ( (FT_Int32)c > 0 )
{
FT_Int64 temp, temp2;
ft_multo64( (FT_Int32)a, (FT_Int32)b, &temp );
temp2.hi = 0;
temp2.lo = (FT_UInt32)(c >> 1);
FT_Add64( &temp, &temp2, &temp );
a = ft_div64by32( temp.hi, temp.lo, (FT_Int32)c );
}
else
a = 0x7FFFFFFFL;
return ( s < 0 ? -a : a );
}
FT_BASE_DEF( FT_Long )
FT_MulDiv_No_Round( FT_Long a,
FT_Long b,
FT_Long c )
{
long s;
if ( a == 0 || b == c )
return a;
s = a; a = FT_ABS( a );
s ^= b; b = FT_ABS( b );
s ^= c; c = FT_ABS( c );
if ( a <= 46340L && b <= 46340L && c > 0 )
a = a * b / c;
else if ( (FT_Int32)c > 0 )
{
FT_Int64 temp;
ft_multo64( (FT_Int32)a, (FT_Int32)b, &temp );
a = ft_div64by32( temp.hi, temp.lo, (FT_Int32)c );
}
else
a = 0x7FFFFFFFL;
return ( s < 0 ? -a : a );
}
/* documentation is in freetype.h */
FT_EXPORT_DEF( FT_Long )
FT_MulFix( FT_Long a,
FT_Long b )
{
#ifdef FT_MULFIX_ASSEMBLER
return FT_MULFIX_ASSEMBLER( a, b );
#elif 0
/*
* This code is nonportable. See comment below.
*
* However, on a platform where right-shift of a signed quantity fills
* the leftmost bits by copying the sign bit, it might be faster.
*/
FT_Long sa, sb;
FT_ULong ua, ub;
if ( a == 0 || b == 0x10000L )
return a;
/*
* This is a clever way of converting a signed number `a' into its
* absolute value (stored back into `a') and its sign. The sign is
* stored in `sa'; 0 means `a' was positive or zero, and -1 means `a'
* was negative. (Similarly for `b' and `sb').
*
* Unfortunately, it doesn't work (at least not portably).
*
* It makes the assumption that right-shift on a negative signed value
* fills the leftmost bits by copying the sign bit. This is wrong.
* According to K&R 2nd ed, section `A7.8 Shift Operators' on page 206,
* the result of right-shift of a negative signed value is
* implementation-defined. At least one implementation fills the
* leftmost bits with 0s (i.e., it is exactly the same as an unsigned
* right shift). This means that when `a' is negative, `sa' ends up
* with the value 1 rather than -1. After that, everything else goes
* wrong.
*/
sa = ( a >> ( sizeof ( a ) * 8 - 1 ) );
a = ( a ^ sa ) - sa;
sb = ( b >> ( sizeof ( b ) * 8 - 1 ) );
b = ( b ^ sb ) - sb;
ua = (FT_ULong)a;
ub = (FT_ULong)b;
if ( ua <= 2048 && ub <= 1048576L )
ua = ( ua * ub + 0x8000U ) >> 16;
else
{
FT_ULong al = ua & 0xFFFFU;
ua = ( ua >> 16 ) * ub + al * ( ub >> 16 ) +
( ( al * ( ub & 0xFFFFU ) + 0x8000U ) >> 16 );
}
sa ^= sb,
ua = (FT_ULong)(( ua ^ sa ) - sa);
return (FT_Long)ua;
#else /* 0 */
FT_Long s;
FT_ULong ua, ub;
if ( a == 0 || b == 0x10000L )
return a;
s = a; a = FT_ABS( a );
s ^= b; b = FT_ABS( b );
ua = (FT_ULong)a;
ub = (FT_ULong)b;
if ( ua <= 2048 && ub <= 1048576L )
ua = ( ua * ub + 0x8000UL ) >> 16;
else
{
FT_ULong al = ua & 0xFFFFUL;
ua = ( ua >> 16 ) * ub + al * ( ub >> 16 ) +
( ( al * ( ub & 0xFFFFUL ) + 0x8000UL ) >> 16 );
}
return ( s < 0 ? -(FT_Long)ua : (FT_Long)ua );
#endif /* 0 */
}
/* documentation is in freetype.h */
FT_EXPORT_DEF( FT_Long )
FT_DivFix( FT_Long a,
FT_Long b )
{
FT_Int32 s;
FT_UInt32 q;
/* XXX: this function does not allow 64-bit arguments */
s = (FT_Int32)a; a = FT_ABS( a );
s ^= (FT_Int32)b; b = FT_ABS( b );
if ( (FT_UInt32)b == 0 )
{
/* check for division by 0 */
q = (FT_UInt32)0x7FFFFFFFL;
}
else if ( ( a >> 16 ) == 0 )
{
/* compute result directly */
q = (FT_UInt32)( ( (FT_ULong)a << 16 ) + ( b >> 1 ) ) / (FT_UInt32)b;
}
else
{
/* we need more bits; we have to do it by hand */
FT_Int64 temp, temp2;
temp.hi = (FT_Int32)( a >> 16 );
temp.lo = (FT_UInt32)a << 16;
temp2.hi = 0;
temp2.lo = (FT_UInt32)( b >> 1 );
FT_Add64( &temp, &temp2, &temp );
q = ft_div64by32( temp.hi, temp.lo, (FT_Int32)b );
}
return ( s < 0 ? -(FT_Int32)q : (FT_Int32)q );
}
#if 0
/* documentation is in ftcalc.h */
FT_EXPORT_DEF( void )
FT_MulTo64( FT_Int32 x,
FT_Int32 y,
FT_Int64 *z )
{
FT_Int32 s;
s = x; x = FT_ABS( x );
s ^= y; y = FT_ABS( y );
ft_multo64( x, y, z );
if ( s < 0 )
{
z->lo = (FT_UInt32)-(FT_Int32)z->lo;
z->hi = ~z->hi + !( z->lo );
}
}
/* apparently, the second version of this code is not compiled correctly */
/* on Mac machines with the MPW C compiler.. tsk, tsk, tsk... */
#if 1
FT_EXPORT_DEF( FT_Int32 )
FT_Div64by32( FT_Int64* x,
FT_Int32 y )
{
FT_Int32 s;
FT_UInt32 q, r, i, lo;
s = x->hi;
if ( s < 0 )
{
x->lo = (FT_UInt32)-(FT_Int32)x->lo;
x->hi = ~x->hi + !x->lo;
}
s ^= y; y = FT_ABS( y );
/* Shortcut */
if ( x->hi == 0 )
{
if ( y > 0 )
q = x->lo / y;
else
q = 0x7FFFFFFFL;
return ( s < 0 ? -(FT_Int32)q : (FT_Int32)q );
}
r = x->hi;
lo = x->lo;
if ( r >= (FT_UInt32)y ) /* we know y is to be treated as unsigned here */
return ( s < 0 ? 0x80000001UL : 0x7FFFFFFFUL );
/* Return Max/Min Int32 if division overflow. */
/* This includes division by zero! */
q = 0;
for ( i = 0; i < 32; i++ )
{
r <<= 1;
q <<= 1;
r |= lo >> 31;
if ( r >= (FT_UInt32)y )
{
r -= y;
q |= 1;
}
lo <<= 1;
}
return ( s < 0 ? -(FT_Int32)q : (FT_Int32)q );
}
#else /* 0 */
FT_EXPORT_DEF( FT_Int32 )
FT_Div64by32( FT_Int64* x,
FT_Int32 y )
{
FT_Int32 s;
FT_UInt32 q;
s = x->hi;
if ( s < 0 )
{
x->lo = (FT_UInt32)-(FT_Int32)x->lo;
x->hi = ~x->hi + !x->lo;
}
s ^= y; y = FT_ABS( y );
/* Shortcut */
if ( x->hi == 0 )
{
if ( y > 0 )
q = ( x->lo + ( y >> 1 ) ) / y;
else
q = 0x7FFFFFFFL;
return ( s < 0 ? -(FT_Int32)q : (FT_Int32)q );
}
q = ft_div64by32( x->hi, x->lo, y );
return ( s < 0 ? -(FT_Int32)q : (FT_Int32)q );
}
#endif /* 0 */
#endif /* 0 */
#endif /* FT_LONG64 */
/* documentation is in ftglyph.h */
FT_EXPORT_DEF( void )
FT_Matrix_Multiply( const FT_Matrix* a,
FT_Matrix *b )
{
FT_Fixed xx, xy, yx, yy;
if ( !a || !b )
return;
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;
}
/* documentation is in ftglyph.h */
FT_EXPORT_DEF( FT_Error )
FT_Matrix_Invert( FT_Matrix* matrix )
{
FT_Pos delta, xx, yy;
if ( !matrix )
return FT_THROW( Invalid_Argument );
/* compute discriminant */
delta = FT_MulFix( matrix->xx, matrix->yy ) -
FT_MulFix( matrix->xy, matrix->yx );
if ( !delta )
return FT_THROW( 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;
}
/* documentation is in ftcalc.h */
FT_BASE_DEF( void )
FT_Matrix_Multiply_Scaled( const FT_Matrix* a,
FT_Matrix *b,
FT_Long scaling )
{
FT_Fixed xx, xy, yx, yy;
FT_Long val = 0x10000L * scaling;
if ( !a || !b )
return;
xx = FT_MulDiv( a->xx, b->xx, val ) + FT_MulDiv( a->xy, b->yx, val );
xy = FT_MulDiv( a->xx, b->xy, val ) + FT_MulDiv( a->xy, b->yy, val );
yx = FT_MulDiv( a->yx, b->xx, val ) + FT_MulDiv( a->yy, b->yx, val );
yy = FT_MulDiv( a->yx, b->xy, val ) + FT_MulDiv( a->yy, b->yy, val );
b->xx = xx; b->xy = xy;
b->yx = yx; b->yy = yy;
}
/* documentation is in ftcalc.h */
FT_BASE_DEF( void )
FT_Vector_Transform_Scaled( FT_Vector* vector,
const FT_Matrix* matrix,
FT_Long scaling )
{
FT_Pos xz, yz;
FT_Long val = 0x10000L * scaling;
if ( !vector || !matrix )
return;
xz = FT_MulDiv( vector->x, matrix->xx, val ) +
FT_MulDiv( vector->y, matrix->xy, val );
yz = FT_MulDiv( vector->x, matrix->yx, val ) +
FT_MulDiv( vector->y, matrix->yy, val );
vector->x = xz;
vector->y = yz;
}
#if 0
/* documentation is in ftcalc.h */
FT_BASE_DEF( FT_Int32 )
FT_SqrtFixed( FT_Int32 x )
{
FT_UInt32 root, rem_hi, rem_lo, test_div;
FT_Int count;
root = 0;
if ( x > 0 )
{
rem_hi = 0;
rem_lo = x;
count = 24;
do
{
rem_hi = ( rem_hi << 2 ) | ( rem_lo >> 30 );
rem_lo <<= 2;
root <<= 1;
test_div = ( root << 1 ) + 1;
if ( rem_hi >= test_div )
{
rem_hi -= test_div;
root += 1;
}
} while ( --count );
}
return (FT_Int32)root;
}
#endif /* 0 */
/* documentation is in ftcalc.h */
FT_BASE_DEF( FT_Int )
ft_corner_orientation( FT_Pos in_x,
FT_Pos in_y,
FT_Pos out_x,
FT_Pos out_y )
{
FT_Long result; /* avoid overflow on 16-bit system */
/* deal with the trivial cases quickly */
if ( in_y == 0 )
{
if ( in_x >= 0 )
result = out_y;
else
result = -out_y;
}
else if ( in_x == 0 )
{
if ( in_y >= 0 )
result = -out_x;
else
result = out_x;
}
else if ( out_y == 0 )
{
if ( out_x >= 0 )
result = in_y;
else
result = -in_y;
}
else if ( out_x == 0 )
{
if ( out_y >= 0 )
result = -in_x;
else
result = in_x;
}
else /* general case */
{
#ifdef FT_LONG64
FT_Int64 delta = (FT_Int64)in_x * out_y - (FT_Int64)in_y * out_x;
if ( delta == 0 )
result = 0;
else
result = 1 - 2 * ( delta < 0 );
#else
FT_Int64 z1, z2;
/* XXX: this function does not allow 64-bit arguments */
ft_multo64( (FT_Int32)in_x, (FT_Int32)out_y, &z1 );
ft_multo64( (FT_Int32)in_y, (FT_Int32)out_x, &z2 );
if ( z1.hi > z2.hi )
result = +1;
else if ( z1.hi < z2.hi )
result = -1;
else if ( z1.lo > z2.lo )
result = +1;
else if ( z1.lo < z2.lo )
result = -1;
else
result = 0;
#endif
}
/* XXX: only the sign of return value, +1/0/-1 must be used */
return (FT_Int)result;
}
/* documentation is in ftcalc.h */
FT_BASE_DEF( FT_Int )
ft_corner_is_flat( FT_Pos in_x,
FT_Pos in_y,
FT_Pos out_x,
FT_Pos out_y )
{
FT_Pos ax = in_x;
FT_Pos ay = in_y;
FT_Pos d_in, d_out, d_corner;
/* We approximate the Euclidean metric (sqrt(x^2 + y^2)) with */
/* the Taxicab metric (|x| + |y|), which can be computed much */
/* faster. If one of the two vectors is much longer than the */
/* other one, the direction of the shorter vector doesn't */
/* influence the result any more. */
/* */
/* corner */
/* x---------------------------x */
/* \ / */
/* \ / */
/* in \ / out */
/* \ / */
/* o */
/* Point */
/* */
if ( ax < 0 )
ax = -ax;
if ( ay < 0 )
ay = -ay;
d_in = ax + ay; /* d_in = || in || */
ax = out_x;
if ( ax < 0 )
ax = -ax;
ay = out_y;
if ( ay < 0 )
ay = -ay;
d_out = ax + ay; /* d_out = || out || */
ax = out_x + in_x;
if ( ax < 0 )
ax = -ax;
ay = out_y + in_y;
if ( ay < 0 )
ay = -ay;
d_corner = ax + ay; /* d_corner = || in + out || */
/* now do a simple length comparison: */
/* */
/* d_in + d_out < 17/16 d_corner */
return ( d_in + d_out - d_corner ) < ( d_corner >> 4 );
}
/* END */
| YifuLiu/AliOS-Things | components/freetype/src/base/ftcalc.c | C | apache-2.0 | 23,107 |
/***************************************************************************/
/* */
/* ftcid.c */
/* */
/* FreeType API for accessing CID font information. */
/* */
/* Copyright 2007, 2009, 2013 by Derek Clegg, Michael Toftdal. */
/* */
/* 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. */
/* */
/***************************************************************************/
#include <ft2build.h>
#include FT_CID_H
#include FT_INTERNAL_OBJECTS_H
#include FT_SERVICE_CID_H
/* documentation is in ftcid.h */
FT_EXPORT_DEF( FT_Error )
FT_Get_CID_Registry_Ordering_Supplement( FT_Face face,
const char* *registry,
const char* *ordering,
FT_Int *supplement)
{
FT_Error error;
const char* r = NULL;
const char* o = NULL;
FT_Int s = 0;
error = FT_ERR( Invalid_Argument );
if ( face )
{
FT_Service_CID service;
FT_FACE_FIND_SERVICE( face, service, CID );
if ( service && service->get_ros )
error = service->get_ros( face, &r, &o, &s );
}
if ( registry )
*registry = r;
if ( ordering )
*ordering = o;
if ( supplement )
*supplement = s;
return error;
}
FT_EXPORT_DEF( FT_Error )
FT_Get_CID_Is_Internally_CID_Keyed( FT_Face face,
FT_Bool *is_cid )
{
FT_Error error = FT_ERR( Invalid_Argument );
FT_Bool ic = 0;
if ( face )
{
FT_Service_CID service;
FT_FACE_FIND_SERVICE( face, service, CID );
if ( service && service->get_is_cid )
error = service->get_is_cid( face, &ic);
}
if ( is_cid )
*is_cid = ic;
return error;
}
FT_EXPORT_DEF( FT_Error )
FT_Get_CID_From_Glyph_Index( FT_Face face,
FT_UInt glyph_index,
FT_UInt *cid )
{
FT_Error error = FT_ERR( Invalid_Argument );
FT_UInt c = 0;
if ( face )
{
FT_Service_CID service;
FT_FACE_FIND_SERVICE( face, service, CID );
if ( service && service->get_cid_from_glyph_index )
error = service->get_cid_from_glyph_index( face, glyph_index, &c);
}
if ( cid )
*cid = c;
return error;
}
/* END */
| YifuLiu/AliOS-Things | components/freetype/src/base/ftcid.c | C | apache-2.0 | 3,164 |
/***************************************************************************/
/* */
/* ftdbgmem.c */
/* */
/* Memory debugger (body). */
/* */
/* Copyright 2001-2006, 2009, 2013 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. */
/* */
/***************************************************************************/
#include <ft2build.h>
#include FT_CONFIG_CONFIG_H
#include FT_INTERNAL_DEBUG_H
#include FT_INTERNAL_MEMORY_H
#include FT_SYSTEM_H
#include FT_ERRORS_H
#include FT_TYPES_H
#ifdef FT_DEBUG_MEMORY
#define KEEPALIVE /* `Keep alive' means that freed blocks aren't released
* to the heap. This is useful to detect double-frees
* or weird heap corruption, but it uses large amounts of
* memory, however.
*/
#include FT_CONFIG_STANDARD_LIBRARY_H
FT_BASE_DEF( const char* ) _ft_debug_file = 0;
FT_BASE_DEF( long ) _ft_debug_lineno = 0;
extern void
FT_DumpMemory( FT_Memory memory );
typedef struct FT_MemSourceRec_* FT_MemSource;
typedef struct FT_MemNodeRec_* FT_MemNode;
typedef struct FT_MemTableRec_* FT_MemTable;
#define FT_MEM_VAL( addr ) ((FT_PtrDist)(FT_Pointer)( addr ))
/*
* This structure holds statistics for a single allocation/release
* site. This is useful to know where memory operations happen the
* most.
*/
typedef struct FT_MemSourceRec_
{
const char* file_name;
long line_no;
FT_Long cur_blocks; /* current number of allocated blocks */
FT_Long max_blocks; /* max. number of allocated blocks */
FT_Long all_blocks; /* total number of blocks allocated */
FT_Long cur_size; /* current cumulative allocated size */
FT_Long max_size; /* maximum cumulative allocated size */
FT_Long all_size; /* total cumulative allocated size */
FT_Long cur_max; /* current maximum allocated size */
FT_UInt32 hash;
FT_MemSource link;
} FT_MemSourceRec;
/*
* We don't need a resizable array for the memory sources, because
* their number is pretty limited within FreeType.
*/
#define FT_MEM_SOURCE_BUCKETS 128
/*
* This structure holds information related to a single allocated
* memory block. If KEEPALIVE is defined, blocks that are freed by
* FreeType are never released to the system. Instead, their `size'
* field is set to -size. This is mainly useful to detect double frees,
* at the price of large memory footprint during execution.
*/
typedef struct FT_MemNodeRec_
{
FT_Byte* address;
FT_Long size; /* < 0 if the block was freed */
FT_MemSource source;
#ifdef KEEPALIVE
const char* free_file_name;
FT_Long free_line_no;
#endif
FT_MemNode link;
} FT_MemNodeRec;
/*
* The global structure, containing compound statistics and all hash
* tables.
*/
typedef struct FT_MemTableRec_
{
FT_ULong size;
FT_ULong nodes;
FT_MemNode* buckets;
FT_ULong alloc_total;
FT_ULong alloc_current;
FT_ULong alloc_max;
FT_ULong alloc_count;
FT_Bool bound_total;
FT_ULong alloc_total_max;
FT_Bool bound_count;
FT_ULong alloc_count_max;
FT_MemSource sources[FT_MEM_SOURCE_BUCKETS];
FT_Bool keep_alive;
FT_Memory memory;
FT_Pointer memory_user;
FT_Alloc_Func alloc;
FT_Free_Func free;
FT_Realloc_Func realloc;
} FT_MemTableRec;
#define FT_MEM_SIZE_MIN 7
#define FT_MEM_SIZE_MAX 13845163
#define FT_FILENAME( x ) ((x) ? (x) : "unknown file")
/*
* Prime numbers are ugly to handle. It would be better to implement
* L-Hashing, which is 10% faster and doesn't require divisions.
*/
static const FT_UInt ft_mem_primes[] =
{
7,
11,
19,
37,
73,
109,
163,
251,
367,
557,
823,
1237,
1861,
2777,
4177,
6247,
9371,
14057,
21089,
31627,
47431,
71143,
106721,
160073,
240101,
360163,
540217,
810343,
1215497,
1823231,
2734867,
4102283,
6153409,
9230113,
13845163,
};
static FT_ULong
ft_mem_closest_prime( FT_ULong num )
{
FT_UInt i;
for ( i = 0;
i < sizeof ( ft_mem_primes ) / sizeof ( ft_mem_primes[0] ); i++ )
if ( ft_mem_primes[i] > num )
return ft_mem_primes[i];
return FT_MEM_SIZE_MAX;
}
extern void
ft_mem_debug_panic( const char* fmt,
... )
{
va_list ap;
printf( "FreeType.Debug: " );
va_start( ap, fmt );
vprintf( fmt, ap );
va_end( ap );
printf( "\n" );
exit( EXIT_FAILURE );
}
static FT_Pointer
ft_mem_table_alloc( FT_MemTable table,
FT_Long size )
{
FT_Memory memory = table->memory;
FT_Pointer block;
memory->user = table->memory_user;
block = table->alloc( memory, size );
memory->user = table;
return block;
}
static void
ft_mem_table_free( FT_MemTable table,
FT_Pointer block )
{
FT_Memory memory = table->memory;
memory->user = table->memory_user;
table->free( memory, block );
memory->user = table;
}
static void
ft_mem_table_resize( FT_MemTable table )
{
FT_ULong new_size;
new_size = ft_mem_closest_prime( table->nodes );
if ( new_size != table->size )
{
FT_MemNode* new_buckets;
FT_ULong i;
new_buckets = (FT_MemNode *)
ft_mem_table_alloc( table,
new_size * sizeof ( FT_MemNode ) );
if ( new_buckets == NULL )
return;
FT_ARRAY_ZERO( new_buckets, new_size );
for ( i = 0; i < table->size; i++ )
{
FT_MemNode node, next, *pnode;
FT_PtrDist hash;
node = table->buckets[i];
while ( node )
{
next = node->link;
hash = FT_MEM_VAL( node->address ) % new_size;
pnode = new_buckets + hash;
node->link = pnode[0];
pnode[0] = node;
node = next;
}
}
if ( table->buckets )
ft_mem_table_free( table, table->buckets );
table->buckets = new_buckets;
table->size = new_size;
}
}
static FT_MemTable
ft_mem_table_new( FT_Memory memory )
{
FT_MemTable table;
table = (FT_MemTable)memory->alloc( memory, sizeof ( *table ) );
if ( table == NULL )
goto Exit;
FT_ZERO( table );
table->size = FT_MEM_SIZE_MIN;
table->nodes = 0;
table->memory = memory;
table->memory_user = memory->user;
table->alloc = memory->alloc;
table->realloc = memory->realloc;
table->free = memory->free;
table->buckets = (FT_MemNode *)
memory->alloc( memory,
table->size * sizeof ( FT_MemNode ) );
if ( table->buckets )
FT_ARRAY_ZERO( table->buckets, table->size );
else
{
memory->free( memory, table );
table = NULL;
}
Exit:
return table;
}
static void
ft_mem_table_destroy( FT_MemTable table )
{
FT_ULong i;
FT_Long leak_count = 0;
FT_ULong leaks = 0;
FT_DumpMemory( table->memory );
/* remove all blocks from the table, revealing leaked ones */
for ( i = 0; i < table->size; i++ )
{
FT_MemNode *pnode = table->buckets + i, next, node = *pnode;
while ( node )
{
next = node->link;
node->link = 0;
if ( node->size > 0 )
{
printf(
"leaked memory block at address %p, size %8ld in (%s:%ld)\n",
node->address, node->size,
FT_FILENAME( node->source->file_name ),
node->source->line_no );
leak_count++;
leaks += node->size;
ft_mem_table_free( table, node->address );
}
node->address = NULL;
node->size = 0;
ft_mem_table_free( table, node );
node = next;
}
table->buckets[i] = 0;
}
ft_mem_table_free( table, table->buckets );
table->buckets = NULL;
table->size = 0;
table->nodes = 0;
/* remove all sources */
for ( i = 0; i < FT_MEM_SOURCE_BUCKETS; i++ )
{
FT_MemSource source, next;
for ( source = table->sources[i]; source != NULL; source = next )
{
next = source->link;
ft_mem_table_free( table, source );
}
table->sources[i] = NULL;
}
printf( "FreeType: total memory allocations = %ld\n",
table->alloc_total );
printf( "FreeType: maximum memory footprint = %ld\n",
table->alloc_max );
ft_mem_table_free( table, table );
if ( leak_count > 0 )
ft_mem_debug_panic(
"FreeType: %ld bytes of memory leaked in %ld blocks\n",
leaks, leak_count );
printf( "FreeType: no memory leaks detected\n" );
}
static FT_MemNode*
ft_mem_table_get_nodep( FT_MemTable table,
FT_Byte* address )
{
FT_PtrDist hash;
FT_MemNode *pnode, node;
hash = FT_MEM_VAL( address );
pnode = table->buckets + ( hash % table->size );
for (;;)
{
node = pnode[0];
if ( !node )
break;
if ( node->address == address )
break;
pnode = &node->link;
}
return pnode;
}
static FT_MemSource
ft_mem_table_get_source( FT_MemTable table )
{
FT_UInt32 hash;
FT_MemSource node, *pnode;
/* cast to FT_PtrDist first since void* can be larger */
/* than FT_UInt32 and GCC 4.1.1 emits a warning */
hash = (FT_UInt32)(FT_PtrDist)(void*)_ft_debug_file +
(FT_UInt32)( 5 * _ft_debug_lineno );
pnode = &table->sources[hash % FT_MEM_SOURCE_BUCKETS];
for ( ;; )
{
node = *pnode;
if ( node == NULL )
break;
if ( node->file_name == _ft_debug_file &&
node->line_no == _ft_debug_lineno )
goto Exit;
pnode = &node->link;
}
node = (FT_MemSource)ft_mem_table_alloc( table, sizeof ( *node ) );
if ( node == NULL )
ft_mem_debug_panic(
"not enough memory to perform memory debugging\n" );
node->file_name = _ft_debug_file;
node->line_no = _ft_debug_lineno;
node->cur_blocks = 0;
node->max_blocks = 0;
node->all_blocks = 0;
node->cur_size = 0;
node->max_size = 0;
node->all_size = 0;
node->cur_max = 0;
node->link = NULL;
node->hash = hash;
*pnode = node;
Exit:
return node;
}
static void
ft_mem_table_set( FT_MemTable table,
FT_Byte* address,
FT_ULong size,
FT_Long delta )
{
FT_MemNode *pnode, node;
if ( table )
{
FT_MemSource source;
pnode = ft_mem_table_get_nodep( table, address );
node = *pnode;
if ( node )
{
if ( node->size < 0 )
{
/* This block was already freed. Our memory is now completely */
/* corrupted! */
/* This can only happen in keep-alive mode. */
ft_mem_debug_panic(
"memory heap corrupted (allocating freed block)" );
}
else
{
/* This block was already allocated. This means that our memory */
/* is also corrupted! */
ft_mem_debug_panic(
"memory heap corrupted (re-allocating allocated block at"
" %p, of size %ld)\n"
"org=%s:%d new=%s:%d\n",
node->address, node->size,
FT_FILENAME( node->source->file_name ), node->source->line_no,
FT_FILENAME( _ft_debug_file ), _ft_debug_lineno );
}
}
/* we need to create a new node in this table */
node = (FT_MemNode)ft_mem_table_alloc( table, sizeof ( *node ) );
if ( node == NULL )
ft_mem_debug_panic( "not enough memory to run memory tests" );
node->address = address;
node->size = size;
node->source = source = ft_mem_table_get_source( table );
if ( delta == 0 )
{
/* this is an allocation */
source->all_blocks++;
source->cur_blocks++;
if ( source->cur_blocks > source->max_blocks )
source->max_blocks = source->cur_blocks;
}
if ( size > (FT_ULong)source->cur_max )
source->cur_max = size;
if ( delta != 0 )
{
/* we are growing or shrinking a reallocated block */
source->cur_size += delta;
table->alloc_current += delta;
}
else
{
/* we are allocating a new block */
source->cur_size += size;
table->alloc_current += size;
}
source->all_size += size;
if ( source->cur_size > source->max_size )
source->max_size = source->cur_size;
node->free_file_name = NULL;
node->free_line_no = 0;
node->link = pnode[0];
pnode[0] = node;
table->nodes++;
table->alloc_total += size;
if ( table->alloc_current > table->alloc_max )
table->alloc_max = table->alloc_current;
if ( table->nodes * 3 < table->size ||
table->size * 3 < table->nodes )
ft_mem_table_resize( table );
}
}
static void
ft_mem_table_remove( FT_MemTable table,
FT_Byte* address,
FT_Long delta )
{
if ( table )
{
FT_MemNode *pnode, node;
pnode = ft_mem_table_get_nodep( table, address );
node = *pnode;
if ( node )
{
FT_MemSource source;
if ( node->size < 0 )
ft_mem_debug_panic(
"freeing memory block at %p more than once at (%s:%ld)\n"
"block allocated at (%s:%ld) and released at (%s:%ld)",
address,
FT_FILENAME( _ft_debug_file ), _ft_debug_lineno,
FT_FILENAME( node->source->file_name ), node->source->line_no,
FT_FILENAME( node->free_file_name ), node->free_line_no );
/* scramble the node's content for additional safety */
FT_MEM_SET( address, 0xF3, node->size );
if ( delta == 0 )
{
source = node->source;
source->cur_blocks--;
source->cur_size -= node->size;
table->alloc_current -= node->size;
}
if ( table->keep_alive )
{
/* we simply invert the node's size to indicate that the node */
/* was freed. */
node->size = -node->size;
node->free_file_name = _ft_debug_file;
node->free_line_no = _ft_debug_lineno;
}
else
{
table->nodes--;
*pnode = node->link;
node->size = 0;
node->source = NULL;
ft_mem_table_free( table, node );
if ( table->nodes * 3 < table->size ||
table->size * 3 < table->nodes )
ft_mem_table_resize( table );
}
}
else
ft_mem_debug_panic(
"trying to free unknown block at %p in (%s:%ld)\n",
address,
FT_FILENAME( _ft_debug_file ), _ft_debug_lineno );
}
}
extern FT_Pointer
ft_mem_debug_alloc( FT_Memory memory,
FT_Long size )
{
FT_MemTable table = (FT_MemTable)memory->user;
FT_Byte* block;
if ( size <= 0 )
ft_mem_debug_panic( "negative block size allocation (%ld)", size );
/* return NULL if the maximum number of allocations was reached */
if ( table->bound_count &&
table->alloc_count >= table->alloc_count_max )
return NULL;
/* return NULL if this allocation would overflow the maximum heap size */
if ( table->bound_total &&
table->alloc_total_max - table->alloc_current > (FT_ULong)size )
return NULL;
block = (FT_Byte *)ft_mem_table_alloc( table, size );
if ( block )
{
ft_mem_table_set( table, block, (FT_ULong)size, 0 );
table->alloc_count++;
}
_ft_debug_file = "<unknown>";
_ft_debug_lineno = 0;
return (FT_Pointer)block;
}
extern void
ft_mem_debug_free( FT_Memory memory,
FT_Pointer block )
{
FT_MemTable table = (FT_MemTable)memory->user;
if ( block == NULL )
ft_mem_debug_panic( "trying to free NULL in (%s:%ld)",
FT_FILENAME( _ft_debug_file ),
_ft_debug_lineno );
ft_mem_table_remove( table, (FT_Byte*)block, 0 );
if ( !table->keep_alive )
ft_mem_table_free( table, block );
table->alloc_count--;
_ft_debug_file = "<unknown>";
_ft_debug_lineno = 0;
}
extern FT_Pointer
ft_mem_debug_realloc( FT_Memory memory,
FT_Long cur_size,
FT_Long new_size,
FT_Pointer block )
{
FT_MemTable table = (FT_MemTable)memory->user;
FT_MemNode node, *pnode;
FT_Pointer new_block;
FT_Long delta;
const char* file_name = FT_FILENAME( _ft_debug_file );
FT_Long line_no = _ft_debug_lineno;
/* unlikely, but possible */
if ( new_size == cur_size )
return block;
/* the following is valid according to ANSI C */
#if 0
if ( block == NULL || cur_size == 0 )
ft_mem_debug_panic( "trying to reallocate NULL in (%s:%ld)",
file_name, line_no );
#endif
/* while the following is allowed in ANSI C also, we abort since */
/* such case should be handled by FreeType. */
if ( new_size <= 0 )
ft_mem_debug_panic(
"trying to reallocate %p to size 0 (current is %ld) in (%s:%ld)",
block, cur_size, file_name, line_no );
/* check `cur_size' value */
pnode = ft_mem_table_get_nodep( table, (FT_Byte*)block );
node = *pnode;
if ( !node )
ft_mem_debug_panic(
"trying to reallocate unknown block at %p in (%s:%ld)",
block, file_name, line_no );
if ( node->size <= 0 )
ft_mem_debug_panic(
"trying to reallocate freed block at %p in (%s:%ld)",
block, file_name, line_no );
if ( node->size != cur_size )
ft_mem_debug_panic( "invalid ft_realloc request for %p. cur_size is "
"%ld instead of %ld in (%s:%ld)",
block, cur_size, node->size, file_name, line_no );
/* return NULL if the maximum number of allocations was reached */
if ( table->bound_count &&
table->alloc_count >= table->alloc_count_max )
return NULL;
delta = (FT_Long)( new_size - cur_size );
/* return NULL if this allocation would overflow the maximum heap size */
if ( delta > 0 &&
table->bound_total &&
table->alloc_current + (FT_ULong)delta > table->alloc_total_max )
return NULL;
new_block = (FT_Byte *)ft_mem_table_alloc( table, new_size );
if ( new_block == NULL )
return NULL;
ft_mem_table_set( table, (FT_Byte*)new_block, new_size, delta );
ft_memcpy( new_block, block, cur_size < new_size ? cur_size : new_size );
ft_mem_table_remove( table, (FT_Byte*)block, delta );
_ft_debug_file = "<unknown>";
_ft_debug_lineno = 0;
if ( !table->keep_alive )
ft_mem_table_free( table, block );
return new_block;
}
extern FT_Int
ft_mem_debug_init( FT_Memory memory )
{
FT_MemTable table;
FT_Int result = 0;
if ( getenv( "FT2_DEBUG_MEMORY" ) )
{
table = ft_mem_table_new( memory );
if ( table )
{
const char* p;
memory->user = table;
memory->alloc = ft_mem_debug_alloc;
memory->realloc = ft_mem_debug_realloc;
memory->free = ft_mem_debug_free;
p = getenv( "FT2_ALLOC_TOTAL_MAX" );
if ( p != NULL )
{
FT_Long total_max = ft_atol( p );
if ( total_max > 0 )
{
table->bound_total = 1;
table->alloc_total_max = (FT_ULong)total_max;
}
}
p = getenv( "FT2_ALLOC_COUNT_MAX" );
if ( p != NULL )
{
FT_Long total_count = ft_atol( p );
if ( total_count > 0 )
{
table->bound_count = 1;
table->alloc_count_max = (FT_ULong)total_count;
}
}
p = getenv( "FT2_KEEP_ALIVE" );
if ( p != NULL )
{
FT_Long keep_alive = ft_atol( p );
if ( keep_alive > 0 )
table->keep_alive = 1;
}
result = 1;
}
}
return result;
}
extern void
ft_mem_debug_done( FT_Memory memory )
{
FT_MemTable table = (FT_MemTable)memory->user;
if ( table )
{
memory->free = table->free;
memory->realloc = table->realloc;
memory->alloc = table->alloc;
ft_mem_table_destroy( table );
memory->user = NULL;
}
}
static int
ft_mem_source_compare( const void* p1,
const void* p2 )
{
FT_MemSource s1 = *(FT_MemSource*)p1;
FT_MemSource s2 = *(FT_MemSource*)p2;
if ( s2->max_size > s1->max_size )
return 1;
else if ( s2->max_size < s1->max_size )
return -1;
else
return 0;
}
extern void
FT_DumpMemory( FT_Memory memory )
{
FT_MemTable table = (FT_MemTable)memory->user;
if ( table )
{
FT_MemSource* bucket = table->sources;
FT_MemSource* limit = bucket + FT_MEM_SOURCE_BUCKETS;
FT_MemSource* sources;
FT_UInt nn, count;
const char* fmt;
count = 0;
for ( ; bucket < limit; bucket++ )
{
FT_MemSource source = *bucket;
for ( ; source; source = source->link )
count++;
}
sources = (FT_MemSource*)ft_mem_table_alloc(
table, sizeof ( *sources ) * count );
count = 0;
for ( bucket = table->sources; bucket < limit; bucket++ )
{
FT_MemSource source = *bucket;
for ( ; source; source = source->link )
sources[count++] = source;
}
ft_qsort( sources, count, sizeof ( *sources ), ft_mem_source_compare );
printf( "FreeType Memory Dump: "
"current=%ld max=%ld total=%ld count=%ld\n",
table->alloc_current, table->alloc_max,
table->alloc_total, table->alloc_count );
printf( " block block sizes sizes sizes source\n" );
printf( " count high sum highsum max location\n" );
printf( "-------------------------------------------------\n" );
fmt = "%6ld %6ld %8ld %8ld %8ld %s:%d\n";
for ( nn = 0; nn < count; nn++ )
{
FT_MemSource source = sources[nn];
printf( fmt,
source->cur_blocks, source->max_blocks,
source->cur_size, source->max_size, source->cur_max,
FT_FILENAME( source->file_name ),
source->line_no );
}
printf( "------------------------------------------------\n" );
ft_mem_table_free( table, sources );
}
}
#else /* !FT_DEBUG_MEMORY */
/* ANSI C doesn't like empty source files */
typedef int _debug_mem_dummy;
#endif /* !FT_DEBUG_MEMORY */
/* END */
| YifuLiu/AliOS-Things | components/freetype/src/base/ftdbgmem.c | C | apache-2.0 | 24,925 |
/***************************************************************************/
/* */
/* ftdebug.c */
/* */
/* Debugging and logging component (body). */
/* */
/* Copyright 1996-2001, 2002, 2004, 2008, 2013 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. */
/* */
/***************************************************************************/
/*************************************************************************/
/* */
/* This component contains various macros and functions used to ease the */
/* debugging of the FreeType engine. Its main purpose is in assertion */
/* checking, tracing, and error detection. */
/* */
/* There are now three debugging modes: */
/* */
/* - trace mode */
/* */
/* Error and trace messages are sent to the log file (which can be the */
/* standard error output). */
/* */
/* - error mode */
/* */
/* Only error messages are generated. */
/* */
/* - release mode: */
/* */
/* No error message is sent or generated. The code is free from any */
/* debugging parts. */
/* */
/*************************************************************************/
#include <ft2build.h>
#include FT_FREETYPE_H
#include FT_INTERNAL_DEBUG_H
#ifdef FT_DEBUG_LEVEL_ERROR
/* documentation is in ftdebug.h */
FT_BASE_DEF( void )
FT_Message( const char* fmt,
... )
{
va_list ap;
va_start( ap, fmt );
vfprintf( stderr, fmt, ap );
va_end( ap );
}
/* documentation is in ftdebug.h */
FT_BASE_DEF( void )
FT_Panic( const char* fmt,
... )
{
va_list ap;
va_start( ap, fmt );
vfprintf( stderr, fmt, ap );
va_end( ap );
exit( EXIT_FAILURE );
}
/* documentation is in ftdebug.h */
FT_BASE_DEF( int )
FT_Throw( FT_Error error,
int line,
const char* file )
{
FT_UNUSED( error );
FT_UNUSED( line );
FT_UNUSED( file );
return 0;
}
#endif /* FT_DEBUG_LEVEL_ERROR */
#ifdef FT_DEBUG_LEVEL_TRACE
/* array of trace levels, initialized to 0 */
int ft_trace_levels[trace_count];
/* define array of trace toggle names */
#define FT_TRACE_DEF( x ) #x ,
static const char* ft_trace_toggles[trace_count + 1] =
{
#include FT_INTERNAL_TRACE_H
NULL
};
#undef FT_TRACE_DEF
/* documentation is in ftdebug.h */
FT_BASE_DEF( FT_Int )
FT_Trace_Get_Count( void )
{
return trace_count;
}
/* documentation is in ftdebug.h */
FT_BASE_DEF( const char * )
FT_Trace_Get_Name( FT_Int idx )
{
int max = FT_Trace_Get_Count();
if ( idx < max )
return ft_trace_toggles[idx];
else
return NULL;
}
/*************************************************************************/
/* */
/* Initialize the tracing sub-system. This is done by retrieving the */
/* value of the `FT2_DEBUG' environment variable. It must be a list of */
/* toggles, separated by spaces, `;', or `,'. Example: */
/* */
/* export FT2_DEBUG="any:3 memory:7 stream:5" */
/* */
/* This requests that all levels be set to 3, except the trace level for */
/* the memory and stream components which are set to 7 and 5, */
/* respectively. */
/* */
/* See the file <include/internal/fttrace.h> for details of the */
/* available toggle names. */
/* */
/* The level must be between 0 and 7; 0 means quiet (except for serious */
/* runtime errors), and 7 means _very_ verbose. */
/* */
FT_BASE_DEF( void )
ft_debug_init( void )
{
const char* ft2_debug = getenv( "FT2_DEBUG" );
if ( ft2_debug )
{
const char* p = ft2_debug;
const char* q;
for ( ; *p; p++ )
{
/* skip leading whitespace and separators */
if ( *p == ' ' || *p == '\t' || *p == ',' || *p == ';' || *p == '=' )
continue;
/* read toggle name, followed by ':' */
q = p;
while ( *p && *p != ':' )
p++;
if ( !*p )
break;
if ( *p == ':' && p > q )
{
FT_Int n, i, len = (FT_Int)( p - q );
FT_Int level = -1, found = -1;
for ( n = 0; n < trace_count; n++ )
{
const char* toggle = ft_trace_toggles[n];
for ( i = 0; i < len; i++ )
{
if ( toggle[i] != q[i] )
break;
}
if ( i == len && toggle[i] == 0 )
{
found = n;
break;
}
}
/* read level */
p++;
if ( *p )
{
level = *p - '0';
if ( level < 0 || level > 7 )
level = -1;
}
if ( found >= 0 && level >= 0 )
{
if ( found == trace_any )
{
/* special case for `any' */
for ( n = 0; n < trace_count; n++ )
ft_trace_levels[n] = level;
}
else
ft_trace_levels[found] = level;
}
}
}
}
}
#else /* !FT_DEBUG_LEVEL_TRACE */
FT_BASE_DEF( void )
ft_debug_init( void )
{
/* nothing */
}
FT_BASE_DEF( FT_Int )
FT_Trace_Get_Count( void )
{
return 0;
}
FT_BASE_DEF( const char * )
FT_Trace_Get_Name( FT_Int idx )
{
FT_UNUSED( idx );
return NULL;
}
#endif /* !FT_DEBUG_LEVEL_TRACE */
/* END */
| YifuLiu/AliOS-Things | components/freetype/src/base/ftdebug.c | C | apache-2.0 | 7,920 |
/***************************************************************************/
/* */
/* ftfstype.c */
/* */
/* FreeType utility file to access FSType data (body). */
/* */
/* Copyright 2008, 2009 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. */
/* */
/***************************************************************************/
#include <ft2build.h>
#include FT_TYPE1_TABLES_H
#include FT_TRUETYPE_TABLES_H
#include FT_INTERNAL_SERVICE_H
#include FT_SERVICE_POSTSCRIPT_INFO_H
/* documentation is in freetype.h */
FT_EXPORT_DEF( FT_UShort )
FT_Get_FSType_Flags( FT_Face face )
{
TT_OS2* os2;
/* first, try to get the fs_type directly from the font */
if ( face )
{
FT_Service_PsInfo service = NULL;
FT_FACE_FIND_SERVICE( face, service, POSTSCRIPT_INFO );
if ( service && service->ps_get_font_extra )
{
PS_FontExtraRec extra;
if ( !service->ps_get_font_extra( face, &extra ) &&
extra.fs_type != 0 )
return extra.fs_type;
}
}
/* look at FSType before fsType for Type42 */
if ( ( os2 = (TT_OS2*)FT_Get_Sfnt_Table( face, ft_sfnt_os2 ) ) != NULL &&
os2->version != 0xFFFFU )
return os2->fsType;
return 0;
}
/* END */
| YifuLiu/AliOS-Things | components/freetype/src/base/ftfstype.c | C | apache-2.0 | 2,244 |
/***************************************************************************/
/* */
/* ftgasp.c */
/* */
/* Access of TrueType's `gasp' table (body). */
/* */
/* Copyright 2007 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. */
/* */
/***************************************************************************/
#include <ft2build.h>
#include FT_GASP_H
#include FT_INTERNAL_TRUETYPE_TYPES_H
FT_EXPORT_DEF( FT_Int )
FT_Get_Gasp( FT_Face face,
FT_UInt ppem )
{
FT_Int result = FT_GASP_NO_TABLE;
if ( face && FT_IS_SFNT( face ) )
{
TT_Face ttface = (TT_Face)face;
if ( ttface->gasp.numRanges > 0 )
{
TT_GaspRange range = ttface->gasp.gaspRanges;
TT_GaspRange range_end = range + ttface->gasp.numRanges;
while ( ppem > range->maxPPEM )
{
range++;
if ( range >= range_end )
goto Exit;
}
result = range->gaspFlag;
/* ensure that we don't have spurious bits */
if ( ttface->gasp.version == 0 )
result &= 3;
}
}
Exit:
return result;
}
/* END */
| YifuLiu/AliOS-Things | components/freetype/src/base/ftgasp.c | C | apache-2.0 | 2,072 |
/***************************************************************************/
/* */
/* ftgloadr.c */
/* */
/* The FreeType glyph loader (body). */
/* */
/* Copyright 2002-2006, 2010, 2013 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. */
/* */
/***************************************************************************/
#include <ft2build.h>
#include FT_INTERNAL_DEBUG_H
#include FT_INTERNAL_GLYPH_LOADER_H
#include FT_INTERNAL_MEMORY_H
#include FT_INTERNAL_OBJECTS_H
#undef FT_COMPONENT
#define FT_COMPONENT trace_gloader
/*************************************************************************/
/*************************************************************************/
/*************************************************************************/
/***** *****/
/***** *****/
/***** G L Y P H L O A D E R *****/
/***** *****/
/***** *****/
/*************************************************************************/
/*************************************************************************/
/*************************************************************************/
/*************************************************************************/
/* */
/* The glyph loader is a simple object which is used to load a set of */
/* glyphs easily. It is critical for the correct loading of composites. */
/* */
/* Ideally, one can see it as a stack of abstract `glyph' objects. */
/* */
/* loader.base Is really the bottom of the stack. It describes a */
/* single glyph image made of the juxtaposition of */
/* several glyphs (those `in the stack'). */
/* */
/* loader.current Describes the top of the stack, on which a new */
/* glyph can be loaded. */
/* */
/* Rewind Clears the stack. */
/* Prepare Set up `loader.current' for addition of a new glyph */
/* image. */
/* Add Add the `current' glyph image to the `base' one, */
/* and prepare for another one. */
/* */
/* The glyph loader is now a base object. Each driver used to */
/* re-implement it in one way or the other, which wasted code and */
/* energy. */
/* */
/*************************************************************************/
/* create a new glyph loader */
FT_BASE_DEF( FT_Error )
FT_GlyphLoader_New( FT_Memory memory,
FT_GlyphLoader *aloader )
{
FT_GlyphLoader loader = NULL;
FT_Error error = FT_Err_Ok;
if ( !FT_NEW( loader ) )
{
loader->memory = memory;
*aloader = loader;
}
return error;
}
/* rewind the glyph loader - reset counters to 0 */
FT_BASE_DEF( void )
FT_GlyphLoader_Rewind( FT_GlyphLoader loader )
{
FT_GlyphLoad base = &loader->base;
FT_GlyphLoad current = &loader->current;
base->outline.n_points = 0;
base->outline.n_contours = 0;
base->num_subglyphs = 0;
*current = *base;
}
/* reset the glyph loader, frees all allocated tables */
/* and starts from zero */
FT_BASE_DEF( void )
FT_GlyphLoader_Reset( FT_GlyphLoader loader )
{
FT_Memory memory = loader->memory;
FT_FREE( loader->base.outline.points );
FT_FREE( loader->base.outline.tags );
FT_FREE( loader->base.outline.contours );
FT_FREE( loader->base.extra_points );
FT_FREE( loader->base.subglyphs );
loader->base.extra_points2 = NULL;
loader->max_points = 0;
loader->max_contours = 0;
loader->max_subglyphs = 0;
FT_GlyphLoader_Rewind( loader );
}
/* delete a glyph loader */
FT_BASE_DEF( void )
FT_GlyphLoader_Done( FT_GlyphLoader loader )
{
if ( loader )
{
FT_Memory memory = loader->memory;
FT_GlyphLoader_Reset( loader );
FT_FREE( loader );
}
}
/* re-adjust the `current' outline fields */
static void
FT_GlyphLoader_Adjust_Points( FT_GlyphLoader loader )
{
FT_Outline* base = &loader->base.outline;
FT_Outline* current = &loader->current.outline;
current->points = base->points + base->n_points;
current->tags = base->tags + base->n_points;
current->contours = base->contours + base->n_contours;
/* handle extra points table - if any */
if ( loader->use_extra )
{
loader->current.extra_points = loader->base.extra_points +
base->n_points;
loader->current.extra_points2 = loader->base.extra_points2 +
base->n_points;
}
}
FT_BASE_DEF( FT_Error )
FT_GlyphLoader_CreateExtra( FT_GlyphLoader loader )
{
FT_Error error = FT_Err_Ok;
FT_Memory memory = loader->memory;
if ( !FT_NEW_ARRAY( loader->base.extra_points, 2 * loader->max_points ) )
{
loader->use_extra = 1;
loader->base.extra_points2 = loader->base.extra_points +
loader->max_points;
FT_GlyphLoader_Adjust_Points( loader );
}
return error;
}
/* re-adjust the `current' subglyphs field */
static void
FT_GlyphLoader_Adjust_Subglyphs( FT_GlyphLoader loader )
{
FT_GlyphLoad base = &loader->base;
FT_GlyphLoad current = &loader->current;
current->subglyphs = base->subglyphs + base->num_subglyphs;
}
/* Ensure that we can add `n_points' and `n_contours' to our glyph. */
/* This function reallocates its outline tables if necessary. Note that */
/* it DOESN'T change the number of points within the loader! */
/* */
FT_BASE_DEF( FT_Error )
FT_GlyphLoader_CheckPoints( FT_GlyphLoader loader,
FT_UInt n_points,
FT_UInt n_contours )
{
FT_Memory memory = loader->memory;
FT_Error error = FT_Err_Ok;
FT_Outline* base = &loader->base.outline;
FT_Outline* current = &loader->current.outline;
FT_Bool adjust = 0;
FT_UInt new_max, old_max;
/* check points & tags */
new_max = base->n_points + current->n_points + n_points;
old_max = loader->max_points;
if ( new_max > old_max )
{
new_max = FT_PAD_CEIL( new_max, 8 );
if ( new_max > FT_OUTLINE_POINTS_MAX )
return FT_THROW( Array_Too_Large );
if ( FT_RENEW_ARRAY( base->points, old_max, new_max ) ||
FT_RENEW_ARRAY( base->tags, old_max, new_max ) )
goto Exit;
if ( loader->use_extra )
{
if ( FT_RENEW_ARRAY( loader->base.extra_points,
old_max * 2, new_max * 2 ) )
goto Exit;
FT_ARRAY_MOVE( loader->base.extra_points + new_max,
loader->base.extra_points + old_max,
old_max );
loader->base.extra_points2 = loader->base.extra_points + new_max;
}
adjust = 1;
loader->max_points = new_max;
}
/* check contours */
old_max = loader->max_contours;
new_max = base->n_contours + current->n_contours +
n_contours;
if ( new_max > old_max )
{
new_max = FT_PAD_CEIL( new_max, 4 );
if ( new_max > FT_OUTLINE_CONTOURS_MAX )
return FT_THROW( Array_Too_Large );
if ( FT_RENEW_ARRAY( base->contours, old_max, new_max ) )
goto Exit;
adjust = 1;
loader->max_contours = new_max;
}
if ( adjust )
FT_GlyphLoader_Adjust_Points( loader );
Exit:
if ( error )
FT_GlyphLoader_Reset( loader );
return error;
}
/* Ensure that we can add `n_subglyphs' to our glyph. this function */
/* reallocates its subglyphs table if necessary. Note that it DOES */
/* NOT change the number of subglyphs within the loader! */
/* */
FT_BASE_DEF( FT_Error )
FT_GlyphLoader_CheckSubGlyphs( FT_GlyphLoader loader,
FT_UInt n_subs )
{
FT_Memory memory = loader->memory;
FT_Error error = FT_Err_Ok;
FT_UInt new_max, old_max;
FT_GlyphLoad base = &loader->base;
FT_GlyphLoad current = &loader->current;
new_max = base->num_subglyphs + current->num_subglyphs + n_subs;
old_max = loader->max_subglyphs;
if ( new_max > old_max )
{
new_max = FT_PAD_CEIL( new_max, 2 );
if ( FT_RENEW_ARRAY( base->subglyphs, old_max, new_max ) )
goto Exit;
loader->max_subglyphs = new_max;
FT_GlyphLoader_Adjust_Subglyphs( loader );
}
Exit:
return error;
}
/* prepare loader for the addition of a new glyph on top of the base one */
FT_BASE_DEF( void )
FT_GlyphLoader_Prepare( FT_GlyphLoader loader )
{
FT_GlyphLoad current = &loader->current;
current->outline.n_points = 0;
current->outline.n_contours = 0;
current->num_subglyphs = 0;
FT_GlyphLoader_Adjust_Points ( loader );
FT_GlyphLoader_Adjust_Subglyphs( loader );
}
/* add current glyph to the base image -- and prepare for another */
FT_BASE_DEF( void )
FT_GlyphLoader_Add( FT_GlyphLoader loader )
{
FT_GlyphLoad base = &loader->base;
FT_GlyphLoad current = &loader->current;
FT_UInt n_curr_contours = 0;
FT_UInt n_base_points = 0;
FT_UInt n = 0;
if ( !loader )
return;
base = &loader->base;
current = &loader->current;
n_curr_contours = current->outline.n_contours;
n_base_points = base->outline.n_points;
base->outline.n_points =
(short)( base->outline.n_points + current->outline.n_points );
base->outline.n_contours =
(short)( base->outline.n_contours + current->outline.n_contours );
base->num_subglyphs += current->num_subglyphs;
/* adjust contours count in newest outline */
for ( n = 0; n < n_curr_contours; n++ )
current->outline.contours[n] =
(short)( current->outline.contours[n] + n_base_points );
/* prepare for another new glyph image */
FT_GlyphLoader_Prepare( loader );
}
FT_BASE_DEF( FT_Error )
FT_GlyphLoader_CopyPoints( FT_GlyphLoader target,
FT_GlyphLoader source )
{
FT_Error error = FT_Err_Ok;
FT_UInt num_points = source->base.outline.n_points;
FT_UInt num_contours = source->base.outline.n_contours;
error = FT_GlyphLoader_CheckPoints( target, num_points, num_contours );
if ( !error )
{
FT_Outline* out = &target->base.outline;
FT_Outline* in = &source->base.outline;
FT_ARRAY_COPY( out->points, in->points,
num_points );
FT_ARRAY_COPY( out->tags, in->tags,
num_points );
FT_ARRAY_COPY( out->contours, in->contours,
num_contours );
/* do we need to copy the extra points? */
if ( target->use_extra && source->use_extra )
{
FT_ARRAY_COPY( target->base.extra_points, source->base.extra_points,
num_points );
FT_ARRAY_COPY( target->base.extra_points2, source->base.extra_points2,
num_points );
}
out->n_points = (short)num_points;
out->n_contours = (short)num_contours;
FT_GlyphLoader_Adjust_Points( target );
}
return error;
}
/* END */
| YifuLiu/AliOS-Things | components/freetype/src/base/ftgloadr.c | C | apache-2.0 | 13,435 |
/***************************************************************************/
/* */
/* ftglyph.c */
/* */
/* FreeType convenience functions to handle glyphs (body). */
/* */
/* Copyright 1996-2005, 2007, 2008, 2010, 2012, 2013 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. */
/* */
/***************************************************************************/
/*************************************************************************/
/* */
/* This file contains the definition of several convenience functions */
/* that can be used by client applications to easily retrieve glyph */
/* bitmaps and outlines from a given face. */
/* */
/* These functions should be optional if you are writing a font server */
/* or text layout engine on top of FreeType. However, they are pretty */
/* handy for many other simple uses of the library. */
/* */
/*************************************************************************/
#include <ft2build.h>
#include FT_INTERNAL_DEBUG_H
#include FT_GLYPH_H
#include FT_OUTLINE_H
#include FT_BITMAP_H
#include FT_INTERNAL_OBJECTS_H
#include "basepic.h"
/*************************************************************************/
/* */
/* The macro FT_COMPONENT is used in trace mode. It is an implicit */
/* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */
/* messages during execution. */
/* */
#undef FT_COMPONENT
#define FT_COMPONENT trace_glyph
/*************************************************************************/
/*************************************************************************/
/**** ****/
/**** FT_BitmapGlyph support ****/
/**** ****/
/*************************************************************************/
/*************************************************************************/
FT_CALLBACK_DEF( FT_Error )
ft_bitmap_glyph_init( FT_Glyph bitmap_glyph,
FT_GlyphSlot slot )
{
FT_BitmapGlyph glyph = (FT_BitmapGlyph)bitmap_glyph;
FT_Error error = FT_Err_Ok;
FT_Library library = FT_GLYPH( glyph )->library;
if ( slot->format != FT_GLYPH_FORMAT_BITMAP )
{
error = FT_THROW( Invalid_Glyph_Format );
goto Exit;
}
glyph->left = slot->bitmap_left;
glyph->top = slot->bitmap_top;
/* do lazy copying whenever possible */
if ( slot->internal->flags & FT_GLYPH_OWN_BITMAP )
{
glyph->bitmap = slot->bitmap;
slot->internal->flags &= ~FT_GLYPH_OWN_BITMAP;
}
else
{
FT_Bitmap_New( &glyph->bitmap );
error = FT_Bitmap_Copy( library, &slot->bitmap, &glyph->bitmap );
}
Exit:
return error;
}
FT_CALLBACK_DEF( FT_Error )
ft_bitmap_glyph_copy( FT_Glyph bitmap_source,
FT_Glyph bitmap_target )
{
FT_Library library = bitmap_source->library;
FT_BitmapGlyph source = (FT_BitmapGlyph)bitmap_source;
FT_BitmapGlyph target = (FT_BitmapGlyph)bitmap_target;
target->left = source->left;
target->top = source->top;
return FT_Bitmap_Copy( library, &source->bitmap, &target->bitmap );
}
FT_CALLBACK_DEF( void )
ft_bitmap_glyph_done( FT_Glyph bitmap_glyph )
{
FT_BitmapGlyph glyph = (FT_BitmapGlyph)bitmap_glyph;
FT_Library library = FT_GLYPH( glyph )->library;
FT_Bitmap_Done( library, &glyph->bitmap );
}
FT_CALLBACK_DEF( void )
ft_bitmap_glyph_bbox( FT_Glyph bitmap_glyph,
FT_BBox* cbox )
{
FT_BitmapGlyph glyph = (FT_BitmapGlyph)bitmap_glyph;
cbox->xMin = glyph->left << 6;
cbox->xMax = cbox->xMin + ( glyph->bitmap.width << 6 );
cbox->yMax = glyph->top << 6;
cbox->yMin = cbox->yMax - ( glyph->bitmap.rows << 6 );
}
FT_DEFINE_GLYPH(ft_bitmap_glyph_class,
sizeof ( FT_BitmapGlyphRec ),
FT_GLYPH_FORMAT_BITMAP,
ft_bitmap_glyph_init,
ft_bitmap_glyph_done,
ft_bitmap_glyph_copy,
0, /* FT_Glyph_TransformFunc */
ft_bitmap_glyph_bbox,
0 /* FT_Glyph_PrepareFunc */
)
/*************************************************************************/
/*************************************************************************/
/**** ****/
/**** FT_OutlineGlyph support ****/
/**** ****/
/*************************************************************************/
/*************************************************************************/
FT_CALLBACK_DEF( FT_Error )
ft_outline_glyph_init( FT_Glyph outline_glyph,
FT_GlyphSlot slot )
{
FT_OutlineGlyph glyph = (FT_OutlineGlyph)outline_glyph;
FT_Error error = FT_Err_Ok;
FT_Library library = FT_GLYPH( glyph )->library;
FT_Outline* source = &slot->outline;
FT_Outline* target = &glyph->outline;
/* check format in glyph slot */
if ( slot->format != FT_GLYPH_FORMAT_OUTLINE )
{
error = FT_THROW( Invalid_Glyph_Format );
goto Exit;
}
/* allocate new outline */
error = FT_Outline_New( library, source->n_points, source->n_contours,
&glyph->outline );
if ( error )
goto Exit;
FT_Outline_Copy( source, target );
Exit:
return error;
}
FT_CALLBACK_DEF( void )
ft_outline_glyph_done( FT_Glyph outline_glyph )
{
FT_OutlineGlyph glyph = (FT_OutlineGlyph)outline_glyph;
FT_Outline_Done( FT_GLYPH( glyph )->library, &glyph->outline );
}
FT_CALLBACK_DEF( FT_Error )
ft_outline_glyph_copy( FT_Glyph outline_source,
FT_Glyph outline_target )
{
FT_OutlineGlyph source = (FT_OutlineGlyph)outline_source;
FT_OutlineGlyph target = (FT_OutlineGlyph)outline_target;
FT_Error error;
FT_Library library = FT_GLYPH( source )->library;
error = FT_Outline_New( library, source->outline.n_points,
source->outline.n_contours, &target->outline );
if ( !error )
FT_Outline_Copy( &source->outline, &target->outline );
return error;
}
FT_CALLBACK_DEF( void )
ft_outline_glyph_transform( FT_Glyph outline_glyph,
const FT_Matrix* matrix,
const FT_Vector* delta )
{
FT_OutlineGlyph glyph = (FT_OutlineGlyph)outline_glyph;
if ( matrix )
FT_Outline_Transform( &glyph->outline, matrix );
if ( delta )
FT_Outline_Translate( &glyph->outline, delta->x, delta->y );
}
FT_CALLBACK_DEF( void )
ft_outline_glyph_bbox( FT_Glyph outline_glyph,
FT_BBox* bbox )
{
FT_OutlineGlyph glyph = (FT_OutlineGlyph)outline_glyph;
FT_Outline_Get_CBox( &glyph->outline, bbox );
}
FT_CALLBACK_DEF( FT_Error )
ft_outline_glyph_prepare( FT_Glyph outline_glyph,
FT_GlyphSlot slot )
{
FT_OutlineGlyph glyph = (FT_OutlineGlyph)outline_glyph;
slot->format = FT_GLYPH_FORMAT_OUTLINE;
slot->outline = glyph->outline;
slot->outline.flags &= ~FT_OUTLINE_OWNER;
return FT_Err_Ok;
}
FT_DEFINE_GLYPH( ft_outline_glyph_class,
sizeof ( FT_OutlineGlyphRec ),
FT_GLYPH_FORMAT_OUTLINE,
ft_outline_glyph_init,
ft_outline_glyph_done,
ft_outline_glyph_copy,
ft_outline_glyph_transform,
ft_outline_glyph_bbox,
ft_outline_glyph_prepare
)
/*************************************************************************/
/*************************************************************************/
/**** ****/
/**** FT_Glyph class and API ****/
/**** ****/
/*************************************************************************/
/*************************************************************************/
static FT_Error
ft_new_glyph( FT_Library library,
const FT_Glyph_Class* clazz,
FT_Glyph* aglyph )
{
FT_Memory memory = library->memory;
FT_Error error = FT_Err_Ok;
FT_Glyph glyph = NULL;
*aglyph = 0;
if ( !FT_ALLOC( glyph, clazz->glyph_size ) )
{
glyph->library = library;
glyph->clazz = clazz;
glyph->format = clazz->glyph_format;
*aglyph = glyph;
}
return error;
}
/* documentation is in ftglyph.h */
FT_EXPORT_DEF( FT_Error )
FT_Glyph_Copy( FT_Glyph source,
FT_Glyph *target )
{
FT_Glyph copy;
FT_Error error;
const FT_Glyph_Class* clazz;
/* check arguments */
if ( !target )
{
error = FT_THROW( Invalid_Argument );
goto Exit;
}
*target = 0;
if ( !source || !source->clazz )
{
error = FT_THROW( Invalid_Argument );
goto Exit;
}
clazz = source->clazz;
error = ft_new_glyph( source->library, clazz, © );
if ( error )
goto Exit;
copy->advance = source->advance;
copy->format = source->format;
if ( clazz->glyph_copy )
error = clazz->glyph_copy( source, copy );
if ( error )
FT_Done_Glyph( copy );
else
*target = copy;
Exit:
return error;
}
/* documentation is in ftglyph.h */
FT_EXPORT_DEF( FT_Error )
FT_Get_Glyph( FT_GlyphSlot slot,
FT_Glyph *aglyph )
{
FT_Library library;
FT_Error error;
FT_Glyph glyph;
const FT_Glyph_Class* clazz = 0;
if ( !slot )
return FT_THROW( Invalid_Slot_Handle );
library = slot->library;
if ( !aglyph )
return FT_THROW( Invalid_Argument );
/* if it is a bitmap, that's easy :-) */
if ( slot->format == FT_GLYPH_FORMAT_BITMAP )
clazz = FT_BITMAP_GLYPH_CLASS_GET;
/* if it is an outline */
else if ( slot->format == FT_GLYPH_FORMAT_OUTLINE )
clazz = FT_OUTLINE_GLYPH_CLASS_GET;
else
{
/* try to find a renderer that supports the glyph image format */
FT_Renderer render = FT_Lookup_Renderer( library, slot->format, 0 );
if ( render )
clazz = &render->glyph_class;
}
if ( !clazz )
{
error = FT_THROW( Invalid_Glyph_Format );
goto Exit;
}
/* create FT_Glyph object */
error = ft_new_glyph( library, clazz, &glyph );
if ( error )
goto Exit;
/* copy advance while converting it to 16.16 format */
glyph->advance.x = slot->advance.x << 10;
glyph->advance.y = slot->advance.y << 10;
/* now import the image from the glyph slot */
error = clazz->glyph_init( glyph, slot );
/* if an error occurred, destroy the glyph */
if ( error )
FT_Done_Glyph( glyph );
else
*aglyph = glyph;
Exit:
return error;
}
/* documentation is in ftglyph.h */
FT_EXPORT_DEF( FT_Error )
FT_Glyph_Transform( FT_Glyph glyph,
FT_Matrix* matrix,
FT_Vector* delta )
{
FT_Error error = FT_Err_Ok;
if ( !glyph || !glyph->clazz )
error = FT_THROW( Invalid_Argument );
else
{
const FT_Glyph_Class* clazz = glyph->clazz;
if ( clazz->glyph_transform )
{
/* transform glyph image */
clazz->glyph_transform( glyph, matrix, delta );
/* transform advance vector */
if ( matrix )
FT_Vector_Transform( &glyph->advance, matrix );
}
else
error = FT_THROW( Invalid_Glyph_Format );
}
return error;
}
/* documentation is in ftglyph.h */
FT_EXPORT_DEF( void )
FT_Glyph_Get_CBox( FT_Glyph glyph,
FT_UInt bbox_mode,
FT_BBox *acbox )
{
const FT_Glyph_Class* clazz;
if ( !acbox )
return;
acbox->xMin = acbox->yMin = acbox->xMax = acbox->yMax = 0;
if ( !glyph || !glyph->clazz )
return;
clazz = glyph->clazz;
if ( !clazz->glyph_bbox )
return;
/* retrieve bbox in 26.6 coordinates */
clazz->glyph_bbox( glyph, acbox );
/* perform grid fitting if needed */
if ( bbox_mode == FT_GLYPH_BBOX_GRIDFIT ||
bbox_mode == FT_GLYPH_BBOX_PIXELS )
{
acbox->xMin = FT_PIX_FLOOR( acbox->xMin );
acbox->yMin = FT_PIX_FLOOR( acbox->yMin );
acbox->xMax = FT_PIX_CEIL( acbox->xMax );
acbox->yMax = FT_PIX_CEIL( acbox->yMax );
}
/* convert to integer pixels if needed */
if ( bbox_mode == FT_GLYPH_BBOX_TRUNCATE ||
bbox_mode == FT_GLYPH_BBOX_PIXELS )
{
acbox->xMin >>= 6;
acbox->yMin >>= 6;
acbox->xMax >>= 6;
acbox->yMax >>= 6;
}
}
/* documentation is in ftglyph.h */
FT_EXPORT_DEF( FT_Error )
FT_Glyph_To_Bitmap( FT_Glyph* the_glyph,
FT_Render_Mode render_mode,
FT_Vector* origin,
FT_Bool destroy )
{
FT_GlyphSlotRec dummy;
FT_GlyphSlot_InternalRec dummy_internal;
FT_Error error = FT_Err_Ok;
FT_Glyph b, glyph;
FT_BitmapGlyph bitmap = NULL;
const FT_Glyph_Class* clazz;
/* FT_BITMAP_GLYPH_CLASS_GET derefers `library' in PIC mode */
FT_Library library;
/* check argument */
if ( !the_glyph )
goto Bad;
glyph = *the_glyph;
if ( !glyph )
goto Bad;
clazz = glyph->clazz;
library = glyph->library;
if ( !library || !clazz )
goto Bad;
/* when called with a bitmap glyph, do nothing and return successfully */
if ( clazz == FT_BITMAP_GLYPH_CLASS_GET )
goto Exit;
if ( !clazz->glyph_prepare )
goto Bad;
/* we render the glyph into a glyph bitmap using a `dummy' glyph slot */
/* then calling FT_Render_Glyph_Internal() */
FT_MEM_ZERO( &dummy, sizeof ( dummy ) );
FT_MEM_ZERO( &dummy_internal, sizeof ( dummy_internal ) );
dummy.internal = &dummy_internal;
dummy.library = library;
dummy.format = clazz->glyph_format;
/* create result bitmap glyph */
error = ft_new_glyph( library, FT_BITMAP_GLYPH_CLASS_GET, &b );
if ( error )
goto Exit;
bitmap = (FT_BitmapGlyph)b;
#if 1
/* if `origin' is set, translate the glyph image */
if ( origin )
FT_Glyph_Transform( glyph, 0, origin );
#else
FT_UNUSED( origin );
#endif
/* prepare dummy slot for rendering */
error = clazz->glyph_prepare( glyph, &dummy );
if ( !error )
error = FT_Render_Glyph_Internal( glyph->library, &dummy, render_mode );
#if 1
if ( !destroy && origin )
{
FT_Vector v;
v.x = -origin->x;
v.y = -origin->y;
FT_Glyph_Transform( glyph, 0, &v );
}
#endif
if ( error )
goto Exit;
/* in case of success, copy the bitmap to the glyph bitmap */
error = ft_bitmap_glyph_init( (FT_Glyph)bitmap, &dummy );
if ( error )
goto Exit;
/* copy advance */
bitmap->root.advance = glyph->advance;
if ( destroy )
FT_Done_Glyph( glyph );
*the_glyph = FT_GLYPH( bitmap );
Exit:
if ( error && bitmap )
FT_Done_Glyph( FT_GLYPH( bitmap ) );
return error;
Bad:
error = FT_THROW( Invalid_Argument );
goto Exit;
}
/* documentation is in ftglyph.h */
FT_EXPORT_DEF( void )
FT_Done_Glyph( FT_Glyph glyph )
{
if ( glyph )
{
FT_Memory memory = glyph->library->memory;
const FT_Glyph_Class* clazz = glyph->clazz;
if ( clazz->glyph_done )
clazz->glyph_done( glyph );
FT_FREE( glyph );
}
}
/* END */
| YifuLiu/AliOS-Things | components/freetype/src/base/ftglyph.c | C | apache-2.0 | 17,478 |
/***************************************************************************/
/* */
/* ftgxval.c */
/* */
/* FreeType API for validating TrueTyepGX/AAT tables (body). */
/* */
/* Copyright 2004-2006, 2010, 2013 by */
/* Masatake YAMATO, Redhat K.K, */
/* 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. */
/* */
/***************************************************************************/
/***************************************************************************/
/* */
/* gxvalid is derived from both gxlayout module and otvalid module. */
/* Development of gxlayout is supported by the Information-technology */
/* Promotion Agency(IPA), Japan. */
/* */
/***************************************************************************/
#include <ft2build.h>
#include FT_INTERNAL_DEBUG_H
#include FT_INTERNAL_OBJECTS_H
#include FT_SERVICE_GX_VALIDATE_H
/* documentation is in ftgxval.h */
FT_EXPORT_DEF( FT_Error )
FT_TrueTypeGX_Validate( FT_Face face,
FT_UInt validation_flags,
FT_Bytes tables[FT_VALIDATE_GX_LENGTH],
FT_UInt table_length )
{
FT_Service_GXvalidate service;
FT_Error error;
if ( !face )
{
error = FT_THROW( Invalid_Face_Handle );
goto Exit;
}
if ( tables == NULL )
{
error = FT_THROW( Invalid_Argument );
goto Exit;
}
FT_FACE_FIND_GLOBAL_SERVICE( face, service, GX_VALIDATE );
if ( service )
error = service->validate( face,
validation_flags,
tables,
table_length );
else
error = FT_THROW( Unimplemented_Feature );
Exit:
return error;
}
FT_EXPORT_DEF( void )
FT_TrueTypeGX_Free( FT_Face face,
FT_Bytes table )
{
FT_Memory memory;
if ( !face )
return;
memory = FT_FACE_MEMORY( face );
FT_FREE( table );
}
FT_EXPORT_DEF( FT_Error )
FT_ClassicKern_Validate( FT_Face face,
FT_UInt validation_flags,
FT_Bytes *ckern_table )
{
FT_Service_CKERNvalidate service;
FT_Error error;
if ( !face )
{
error = FT_THROW( Invalid_Face_Handle );
goto Exit;
}
if ( ckern_table == NULL )
{
error = FT_THROW( Invalid_Argument );
goto Exit;
}
FT_FACE_FIND_GLOBAL_SERVICE( face, service, CLASSICKERN_VALIDATE );
if ( service )
error = service->validate( face,
validation_flags,
ckern_table );
else
error = FT_THROW( Unimplemented_Feature );
Exit:
return error;
}
FT_EXPORT_DEF( void )
FT_ClassicKern_Free( FT_Face face,
FT_Bytes table )
{
FT_Memory memory;
if ( !face )
return;
memory = FT_FACE_MEMORY( face );
FT_FREE( table );
}
/* END */
| YifuLiu/AliOS-Things | components/freetype/src/base/ftgxval.c | C | apache-2.0 | 4,152 |
/***************************************************************************/
/* */
/* ftinit.c */
/* */
/* FreeType initialization layer (body). */
/* */
/* Copyright 1996-2002, 2005, 2007, 2009, 2012, 2013 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. */
/* */
/***************************************************************************/
/*************************************************************************/
/* */
/* The purpose of this file is to implement the following two */
/* functions: */
/* */
/* FT_Add_Default_Modules(): */
/* This function is used to add the set of default modules to a */
/* fresh new library object. The set is taken from the header file */
/* `config/ftmodule.h'. See the document `FreeType 2.0 Build */
/* System' for more information. */
/* */
/* FT_Init_FreeType(): */
/* This function creates a system object for the current platform, */
/* builds a library out of it, then calls FT_Default_Drivers(). */
/* */
/* Note that even if FT_Init_FreeType() uses the implementation of the */
/* system object defined at build time, client applications are still */
/* able to provide their own `ftsystem.c'. */
/* */
/*************************************************************************/
#include <ft2build.h>
#include FT_CONFIG_CONFIG_H
#include FT_INTERNAL_OBJECTS_H
#include FT_INTERNAL_DEBUG_H
#include FT_MODULE_H
#include "basepic.h"
/*************************************************************************/
/* */
/* The macro FT_COMPONENT is used in trace mode. It is an implicit */
/* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */
/* messages during execution. */
/* */
#undef FT_COMPONENT
#define FT_COMPONENT trace_init
#ifndef FT_CONFIG_OPTION_PIC
#undef FT_USE_MODULE
#ifdef __cplusplus
#define FT_USE_MODULE( type, x ) extern "C" const type x;
#else
#define FT_USE_MODULE( type, x ) extern const type x;
#endif
#include FT_CONFIG_MODULES_H
#undef FT_USE_MODULE
#define FT_USE_MODULE( type, x ) (const FT_Module_Class*)&(x),
static
const FT_Module_Class* const ft_default_modules[] =
{
#include FT_CONFIG_MODULES_H
0
};
#else /* FT_CONFIG_OPTION_PIC */
#ifdef __cplusplus
#define FT_EXTERNC extern "C"
#else
#define FT_EXTERNC extern
#endif
/* declare the module's class creation/destruction functions */
#undef FT_USE_MODULE
#define FT_USE_MODULE( type, x ) \
FT_EXTERNC FT_Error \
FT_Create_Class_ ## x( FT_Library library, \
FT_Module_Class* *output_class ); \
FT_EXTERNC void \
FT_Destroy_Class_ ## x( FT_Library library, \
FT_Module_Class* clazz );
#include FT_CONFIG_MODULES_H
/* count all module classes */
#undef FT_USE_MODULE
#define FT_USE_MODULE( type, x ) MODULE_CLASS_ ## x,
enum
{
#include FT_CONFIG_MODULES_H
FT_NUM_MODULE_CLASSES
};
/* destroy all module classes */
#undef FT_USE_MODULE
#define FT_USE_MODULE( type, x ) \
if ( classes[i] ) \
{ \
FT_Destroy_Class_ ## x( library, classes[i] ); \
} \
i++;
FT_BASE_DEF( void )
ft_destroy_default_module_classes( FT_Library library )
{
FT_Module_Class* *classes;
FT_Memory memory;
FT_UInt i;
BasePIC* pic_container = (BasePIC*)library->pic_container.base;
if ( !pic_container->default_module_classes )
return;
memory = library->memory;
classes = pic_container->default_module_classes;
i = 0;
#include FT_CONFIG_MODULES_H
FT_FREE( classes );
pic_container->default_module_classes = 0;
}
/* initialize all module classes and the pointer table */
#undef FT_USE_MODULE
#define FT_USE_MODULE( type, x ) \
error = FT_Create_Class_ ## x( library, &clazz ); \
if ( error ) \
goto Exit; \
classes[i++] = clazz;
FT_BASE_DEF( FT_Error )
ft_create_default_module_classes( FT_Library library )
{
FT_Error error;
FT_Memory memory;
FT_Module_Class* *classes = NULL;
FT_Module_Class* clazz;
FT_UInt i;
BasePIC* pic_container = (BasePIC*)library->pic_container.base;
memory = library->memory;
pic_container->default_module_classes = 0;
if ( FT_ALLOC( classes, sizeof ( FT_Module_Class* ) *
( FT_NUM_MODULE_CLASSES + 1 ) ) )
return error;
/* initialize all pointers to 0, especially the last one */
for ( i = 0; i < FT_NUM_MODULE_CLASSES; i++ )
classes[i] = 0;
classes[FT_NUM_MODULE_CLASSES] = 0;
i = 0;
#include FT_CONFIG_MODULES_H
Exit:
if ( error )
ft_destroy_default_module_classes( library );
else
pic_container->default_module_classes = classes;
return error;
}
#endif /* FT_CONFIG_OPTION_PIC */
/* documentation is in ftmodapi.h */
FT_EXPORT_DEF( void )
FT_Add_Default_Modules( FT_Library library )
{
FT_Error error;
const FT_Module_Class* const* cur;
/* FT_DEFAULT_MODULES_GET dereferences `library' in PIC mode */
#ifdef FT_CONFIG_OPTION_PIC
if ( !library )
return;
#endif
/* GCC 4.6 warns the type difference:
* FT_Module_Class** != const FT_Module_Class* const*
*/
cur = (const FT_Module_Class* const*)FT_DEFAULT_MODULES_GET;
/* test for valid `library' delayed to FT_Add_Module() */
while ( *cur )
{
error = FT_Add_Module( library, *cur );
/* notify errors, but don't stop */
if ( error )
FT_TRACE0(( "FT_Add_Default_Module:"
" Cannot install `%s', error = 0x%x\n",
(*cur)->module_name, error ));
cur++;
}
}
/* documentation is in freetype.h */
FT_EXPORT_DEF( FT_Error )
FT_Init_FreeType( FT_Library *alibrary )
{
FT_Error error;
FT_Memory memory;
/* First of all, allocate a new system object -- this function is part */
/* of the system-specific component, i.e. `ftsystem.c'. */
memory = FT_New_Memory();
if ( !memory )
{
FT_ERROR(( "FT_Init_FreeType: cannot find memory manager\n" ));
return FT_THROW( Unimplemented_Feature );
}
/* build a library out of it, then fill it with the set of */
/* default drivers. */
error = FT_New_Library( memory, alibrary );
if ( error )
FT_Done_Memory( memory );
else
FT_Add_Default_Modules( *alibrary );
return error;
}
/* documentation is in freetype.h */
FT_EXPORT_DEF( FT_Error )
FT_Done_FreeType( FT_Library library )
{
if ( library )
{
FT_Memory memory = library->memory;
/* Discard the library object */
FT_Done_Library( library );
/* discard memory manager */
FT_Done_Memory( memory );
}
return FT_Err_Ok;
}
/* END */
| YifuLiu/AliOS-Things | components/freetype/src/base/ftinit.c | C | apache-2.0 | 8,990 |
/***************************************************************************/
/* */
/* ftlcdfil.c */
/* */
/* FreeType API for color filtering of subpixel bitmap glyphs (body). */
/* */
/* Copyright 2006, 2008-2010, 2013 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. */
/* */
/***************************************************************************/
#include <ft2build.h>
#include FT_INTERNAL_DEBUG_H
#include FT_LCD_FILTER_H
#include FT_IMAGE_H
#include FT_INTERNAL_OBJECTS_H
#ifdef FT_CONFIG_OPTION_SUBPIXEL_RENDERING
/* define USE_LEGACY to implement the legacy filter */
#define USE_LEGACY
/* FIR filter used by the default and light filters */
static void
_ft_lcd_filter_fir( FT_Bitmap* bitmap,
FT_Render_Mode mode,
FT_Library library )
{
FT_Byte* weights = library->lcd_weights;
FT_UInt width = (FT_UInt)bitmap->width;
FT_UInt height = (FT_UInt)bitmap->rows;
/* horizontal in-place FIR filter */
if ( mode == FT_RENDER_MODE_LCD && width >= 4 )
{
FT_Byte* line = bitmap->buffer;
for ( ; height > 0; height--, line += bitmap->pitch )
{
FT_UInt fir[5];
FT_UInt val1, xx;
val1 = line[0];
fir[0] = weights[2] * val1;
fir[1] = weights[3] * val1;
fir[2] = weights[4] * val1;
fir[3] = 0;
fir[4] = 0;
val1 = line[1];
fir[0] += weights[1] * val1;
fir[1] += weights[2] * val1;
fir[2] += weights[3] * val1;
fir[3] += weights[4] * val1;
for ( xx = 2; xx < width; xx++ )
{
FT_UInt val, pix;
val = line[xx];
pix = fir[0] + weights[0] * val;
fir[0] = fir[1] + weights[1] * val;
fir[1] = fir[2] + weights[2] * val;
fir[2] = fir[3] + weights[3] * val;
fir[3] = weights[4] * val;
pix >>= 8;
pix |= -( pix >> 8 );
line[xx - 2] = (FT_Byte)pix;
}
{
FT_UInt pix;
pix = fir[0] >> 8;
pix |= -( pix >> 8 );
line[xx - 2] = (FT_Byte)pix;
pix = fir[1] >> 8;
pix |= -( pix >> 8 );
line[xx - 1] = (FT_Byte)pix;
}
}
}
/* vertical in-place FIR filter */
else if ( mode == FT_RENDER_MODE_LCD_V && height >= 4 )
{
FT_Byte* column = bitmap->buffer;
FT_Int pitch = bitmap->pitch;
for ( ; width > 0; width--, column++ )
{
FT_Byte* col = column;
FT_UInt fir[5];
FT_UInt val1, yy;
val1 = col[0];
fir[0] = weights[2] * val1;
fir[1] = weights[3] * val1;
fir[2] = weights[4] * val1;
fir[3] = 0;
fir[4] = 0;
col += pitch;
val1 = col[0];
fir[0] += weights[1] * val1;
fir[1] += weights[2] * val1;
fir[2] += weights[3] * val1;
fir[3] += weights[4] * val1;
col += pitch;
for ( yy = 2; yy < height; yy++ )
{
FT_UInt val, pix;
val = col[0];
pix = fir[0] + weights[0] * val;
fir[0] = fir[1] + weights[1] * val;
fir[1] = fir[2] + weights[2] * val;
fir[2] = fir[3] + weights[3] * val;
fir[3] = weights[4] * val;
pix >>= 8;
pix |= -( pix >> 8 );
col[-2 * pitch] = (FT_Byte)pix;
col += pitch;
}
{
FT_UInt pix;
pix = fir[0] >> 8;
pix |= -( pix >> 8 );
col[-2 * pitch] = (FT_Byte)pix;
pix = fir[1] >> 8;
pix |= -( pix >> 8 );
col[-pitch] = (FT_Byte)pix;
}
}
}
}
#ifdef USE_LEGACY
/* intra-pixel filter used by the legacy filter */
static void
_ft_lcd_filter_legacy( FT_Bitmap* bitmap,
FT_Render_Mode mode,
FT_Library library )
{
FT_UInt width = (FT_UInt)bitmap->width;
FT_UInt height = (FT_UInt)bitmap->rows;
FT_Int pitch = bitmap->pitch;
static const int filters[3][3] =
{
{ 65538 * 9/13, 65538 * 1/6, 65538 * 1/13 },
{ 65538 * 3/13, 65538 * 4/6, 65538 * 3/13 },
{ 65538 * 1/13, 65538 * 1/6, 65538 * 9/13 }
};
FT_UNUSED( library );
/* horizontal in-place intra-pixel filter */
if ( mode == FT_RENDER_MODE_LCD && width >= 3 )
{
FT_Byte* line = bitmap->buffer;
for ( ; height > 0; height--, line += pitch )
{
FT_UInt xx;
for ( xx = 0; xx < width; xx += 3 )
{
FT_UInt r = 0;
FT_UInt g = 0;
FT_UInt b = 0;
FT_UInt p;
p = line[xx];
r += filters[0][0] * p;
g += filters[0][1] * p;
b += filters[0][2] * p;
p = line[xx + 1];
r += filters[1][0] * p;
g += filters[1][1] * p;
b += filters[1][2] * p;
p = line[xx + 2];
r += filters[2][0] * p;
g += filters[2][1] * p;
b += filters[2][2] * p;
line[xx] = (FT_Byte)( r / 65536 );
line[xx + 1] = (FT_Byte)( g / 65536 );
line[xx + 2] = (FT_Byte)( b / 65536 );
}
}
}
else if ( mode == FT_RENDER_MODE_LCD_V && height >= 3 )
{
FT_Byte* column = bitmap->buffer;
for ( ; width > 0; width--, column++ )
{
FT_Byte* col = column;
FT_Byte* col_end = col + height * pitch;
for ( ; col < col_end; col += 3 * pitch )
{
FT_UInt r = 0;
FT_UInt g = 0;
FT_UInt b = 0;
FT_UInt p;
p = col[0];
r += filters[0][0] * p;
g += filters[0][1] * p;
b += filters[0][2] * p;
p = col[pitch];
r += filters[1][0] * p;
g += filters[1][1] * p;
b += filters[1][2] * p;
p = col[pitch * 2];
r += filters[2][0] * p;
g += filters[2][1] * p;
b += filters[2][2] * p;
col[0] = (FT_Byte)( r / 65536 );
col[pitch] = (FT_Byte)( g / 65536 );
col[2 * pitch] = (FT_Byte)( b / 65536 );
}
}
}
}
#endif /* USE_LEGACY */
FT_EXPORT_DEF( FT_Error )
FT_Library_SetLcdFilterWeights( FT_Library library,
unsigned char *weights )
{
if ( !library || !weights )
return FT_THROW( Invalid_Argument );
ft_memcpy( library->lcd_weights, weights, 5 );
return FT_Err_Ok;
}
FT_EXPORT_DEF( FT_Error )
FT_Library_SetLcdFilter( FT_Library library,
FT_LcdFilter filter )
{
static const FT_Byte light_filter[5] =
{ 0x00, 0x55, 0x56, 0x55, 0x00 };
/* the values here sum up to a value larger than 256, */
/* providing a cheap gamma correction */
static const FT_Byte default_filter[5] =
{ 0x10, 0x40, 0x70, 0x40, 0x10 };
if ( !library )
return FT_THROW( Invalid_Argument );
switch ( filter )
{
case FT_LCD_FILTER_NONE:
library->lcd_filter_func = NULL;
library->lcd_extra = 0;
break;
case FT_LCD_FILTER_DEFAULT:
#if defined( FT_FORCE_LEGACY_LCD_FILTER )
library->lcd_filter_func = _ft_lcd_filter_legacy;
library->lcd_extra = 0;
#elif defined( FT_FORCE_LIGHT_LCD_FILTER )
ft_memcpy( library->lcd_weights, light_filter, 5 );
library->lcd_filter_func = _ft_lcd_filter_fir;
library->lcd_extra = 2;
#else
ft_memcpy( library->lcd_weights, default_filter, 5 );
library->lcd_filter_func = _ft_lcd_filter_fir;
library->lcd_extra = 2;
#endif
break;
case FT_LCD_FILTER_LIGHT:
ft_memcpy( library->lcd_weights, light_filter, 5 );
library->lcd_filter_func = _ft_lcd_filter_fir;
library->lcd_extra = 2;
break;
#ifdef USE_LEGACY
case FT_LCD_FILTER_LEGACY:
library->lcd_filter_func = _ft_lcd_filter_legacy;
library->lcd_extra = 0;
break;
#endif
default:
return FT_THROW( Invalid_Argument );
}
library->lcd_filter = filter;
return FT_Err_Ok;
}
#else /* !FT_CONFIG_OPTION_SUBPIXEL_RENDERING */
FT_EXPORT_DEF( FT_Error )
FT_Library_SetLcdFilterWeights( FT_Library library,
unsigned char *weights )
{
FT_UNUSED( library );
FT_UNUSED( weights );
return FT_THROW( Unimplemented_Feature );
}
FT_EXPORT_DEF( FT_Error )
FT_Library_SetLcdFilter( FT_Library library,
FT_LcdFilter filter )
{
FT_UNUSED( library );
FT_UNUSED( filter );
return FT_THROW( Unimplemented_Feature );
}
#endif /* !FT_CONFIG_OPTION_SUBPIXEL_RENDERING */
/* END */
| YifuLiu/AliOS-Things | components/freetype/src/base/ftlcdfil.c | C | apache-2.0 | 9,929 |
/***************************************************************************/
/* */
/* ftmac.c */
/* */
/* Mac FOND support. Written by just@letterror.com. */
/* Heavily modified by mpsuzuki, George Williams, and Sean McBride. */
/* */
/* This file is for Mac OS X only; see builds/mac/ftoldmac.c for */
/* classic platforms built by MPW. */
/* */
/* Copyright 1996-2009, 2013 by */
/* Just van Rossum, 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. */
/* */
/***************************************************************************/
/*
Notes
Mac suitcase files can (and often do!) contain multiple fonts. To
support this I use the face_index argument of FT_(Open|New)_Face()
functions, and pretend the suitcase file is a collection.
Warning: fbit and NFNT bitmap resources are not supported yet. In old
sfnt fonts, bitmap glyph data for each size is stored in each `NFNT'
resources instead of the `bdat' table in the sfnt resource. Therefore,
face->num_fixed_sizes is set to 0, because bitmap data in `NFNT'
resource is unavailable at present.
The Mac FOND support works roughly like this:
- Check whether the offered stream points to a Mac suitcase file. This
is done by checking the file type: it has to be 'FFIL' or 'tfil'. The
stream that gets passed to our init_face() routine is a stdio stream,
which isn't usable for us, since the FOND resources live in the
resource fork. So we just grab the stream->pathname field.
- Read the FOND resource into memory, then check whether there is a
TrueType font and/or(!) a Type 1 font available.
- If there is a Type 1 font available (as a separate `LWFN' file), read
its data into memory, massage it slightly so it becomes PFB data, wrap
it into a memory stream, load the Type 1 driver and delegate the rest
of the work to it by calling FT_Open_Face(). (XXX TODO: after this
has been done, the kerning data from the FOND resource should be
appended to the face: On the Mac there are usually no AFM files
available. However, this is tricky since we need to map Mac char
codes to ps glyph names to glyph ID's...)
- If there is a TrueType font (an `sfnt' resource), read it into memory,
wrap it into a memory stream, load the TrueType driver and delegate
the rest of the work to it, by calling FT_Open_Face().
- Some suitcase fonts (notably Onyx) might point the `LWFN' file to
itself, even though it doesn't contains `POST' resources. To handle
this special case without opening the file an extra time, we just
ignore errors from the `LWFN' and fallback to the `sfnt' if both are
available.
*/
#include <ft2build.h>
#include FT_FREETYPE_H
#include FT_TRUETYPE_TAGS_H
#include FT_INTERNAL_STREAM_H
#include "ftbase.h"
/* This is for Mac OS X. Without redefinition, OS_INLINE */
/* expands to `static inline' which doesn't survive the */
/* -ansi compilation flag of GCC. */
#if !HAVE_ANSI_OS_INLINE
#undef OS_INLINE
#define OS_INLINE static __inline__
#endif
/* `configure' checks the availability of `ResourceIndex' strictly */
/* and sets HAVE_TYPE_RESOURCE_INDEX 1 or 0 always. If it is */
/* not set (e.g., a build without `configure'), the availability */
/* is guessed from the SDK version. */
#ifndef HAVE_TYPE_RESOURCE_INDEX
#if !defined( MAC_OS_X_VERSION_10_5 ) || \
( MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5 )
#define HAVE_TYPE_RESOURCE_INDEX 0
#else
#define HAVE_TYPE_RESOURCE_INDEX 1
#endif
#endif /* !HAVE_TYPE_RESOURCE_INDEX */
#if ( HAVE_TYPE_RESOURCE_INDEX == 0 )
typedef short ResourceIndex;
#endif
#include <CoreServices/CoreServices.h>
#include <ApplicationServices/ApplicationServices.h>
#include <sys/syslimits.h> /* PATH_MAX */
/* Don't want warnings about our own use of deprecated functions. */
#define FT_DEPRECATED_ATTRIBUTE
#include FT_MAC_H
#ifndef kATSOptionFlagsUnRestrictedScope /* since Mac OS X 10.1 */
#define kATSOptionFlagsUnRestrictedScope kATSOptionFlagsDefault
#endif
/* Set PREFER_LWFN to 1 if LWFN (Type 1) is preferred over
TrueType in case *both* are available (this is not common,
but it *is* possible). */
#ifndef PREFER_LWFN
#define PREFER_LWFN 1
#endif
#ifdef FT_MACINTOSH
/* This function is deprecated because FSSpec is deprecated in Mac OS X */
FT_EXPORT_DEF( FT_Error )
FT_GetFile_From_Mac_Name( const char* fontName,
FSSpec* pathSpec,
FT_Long* face_index )
{
FT_UNUSED( fontName );
FT_UNUSED( pathSpec );
FT_UNUSED( face_index );
return FT_THROW( Unimplemented_Feature );
}
/* Private function. */
/* The FSSpec type has been discouraged for a long time, */
/* unfortunately an FSRef replacement API for */
/* ATSFontGetFileSpecification() is only available in */
/* Mac OS X 10.5 and later. */
static OSStatus
FT_ATSFontGetFileReference( ATSFontRef ats_font_id,
FSRef* ats_font_ref )
{
#if defined( MAC_OS_X_VERSION_10_5 ) && \
( MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5 )
OSStatus err;
err = ATSFontGetFileReference( ats_font_id, ats_font_ref );
return err;
#elif __LP64__ /* No 64bit Carbon API on legacy platforms */
FT_UNUSED( ats_font_id );
FT_UNUSED( ats_font_ref );
return fnfErr;
#else /* 32bit Carbon API on legacy platforms */
OSStatus err;
FSSpec spec;
err = ATSFontGetFileSpecification( ats_font_id, &spec );
if ( noErr == err )
err = FSpMakeFSRef( &spec, ats_font_ref );
return err;
#endif
}
static FT_Error
FT_GetFileRef_From_Mac_ATS_Name( const char* fontName,
FSRef* ats_font_ref,
FT_Long* face_index )
{
CFStringRef cf_fontName;
ATSFontRef ats_font_id;
*face_index = 0;
cf_fontName = CFStringCreateWithCString( NULL, fontName,
kCFStringEncodingMacRoman );
ats_font_id = ATSFontFindFromName( cf_fontName,
kATSOptionFlagsUnRestrictedScope );
CFRelease( cf_fontName );
if ( ats_font_id == 0 || ats_font_id == 0xFFFFFFFFUL )
return FT_THROW( Unknown_File_Format );
if ( noErr != FT_ATSFontGetFileReference( ats_font_id, ats_font_ref ) )
return FT_THROW( Unknown_File_Format );
/* face_index calculation by searching preceding fontIDs */
/* with same FSRef */
{
ATSFontRef id2 = ats_font_id - 1;
FSRef ref2;
while ( id2 > 0 )
{
if ( noErr != FT_ATSFontGetFileReference( id2, &ref2 ) )
break;
if ( noErr != FSCompareFSRefs( ats_font_ref, &ref2 ) )
break;
id2 --;
}
*face_index = ats_font_id - ( id2 + 1 );
}
return FT_Err_Ok;
}
FT_EXPORT_DEF( FT_Error )
FT_GetFilePath_From_Mac_ATS_Name( const char* fontName,
UInt8* path,
UInt32 maxPathSize,
FT_Long* face_index )
{
FSRef ref;
FT_Error err;
err = FT_GetFileRef_From_Mac_ATS_Name( fontName, &ref, face_index );
if ( err )
return err;
if ( noErr != FSRefMakePath( &ref, path, maxPathSize ) )
return FT_THROW( Unknown_File_Format );
return FT_Err_Ok;
}
/* This function is deprecated because FSSpec is deprecated in Mac OS X */
FT_EXPORT_DEF( FT_Error )
FT_GetFile_From_Mac_ATS_Name( const char* fontName,
FSSpec* pathSpec,
FT_Long* face_index )
{
#if ( __LP64__ ) || ( defined( MAC_OS_X_VERSION_10_5 ) && \
( MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5 ) )
FT_UNUSED( fontName );
FT_UNUSED( pathSpec );
FT_UNUSED( face_index );
return FT_THROW( Unimplemented_Feature );
#else
FSRef ref;
FT_Error err;
err = FT_GetFileRef_From_Mac_ATS_Name( fontName, &ref, face_index );
if ( err )
return err;
if ( noErr != FSGetCatalogInfo( &ref, kFSCatInfoNone, NULL, NULL,
pathSpec, NULL ) )
return FT_THROW( Unknown_File_Format );
return FT_Err_Ok;
#endif
}
static OSErr
FT_FSPathMakeRes( const UInt8* pathname,
ResFileRefNum* res )
{
OSErr err;
FSRef ref;
if ( noErr != FSPathMakeRef( pathname, &ref, FALSE ) )
return FT_THROW( Cannot_Open_Resource );
/* at present, no support for dfont format */
err = FSOpenResourceFile( &ref, 0, NULL, fsRdPerm, res );
if ( noErr == err )
return err;
/* fallback to original resource-fork font */
*res = FSOpenResFile( &ref, fsRdPerm );
err = ResError();
return err;
}
/* Return the file type for given pathname */
static OSType
get_file_type_from_path( const UInt8* pathname )
{
FSRef ref;
FSCatalogInfo info;
if ( noErr != FSPathMakeRef( pathname, &ref, FALSE ) )
return ( OSType ) 0;
if ( noErr != FSGetCatalogInfo( &ref, kFSCatInfoFinderInfo, &info,
NULL, NULL, NULL ) )
return ( OSType ) 0;
return ((FInfo *)(info.finderInfo))->fdType;
}
/* Given a PostScript font name, create the Macintosh LWFN file name. */
static void
create_lwfn_name( char* ps_name,
Str255 lwfn_file_name )
{
int max = 5, count = 0;
FT_Byte* p = lwfn_file_name;
FT_Byte* q = (FT_Byte*)ps_name;
lwfn_file_name[0] = 0;
while ( *q )
{
if ( ft_isupper( *q ) )
{
if ( count )
max = 3;
count = 0;
}
if ( count < max && ( ft_isalnum( *q ) || *q == '_' ) )
{
*++p = *q;
lwfn_file_name[0]++;
count++;
}
q++;
}
}
static short
count_faces_sfnt( char* fond_data )
{
/* The count is 1 greater than the value in the FOND. */
/* Isn't that cute? :-) */
return EndianS16_BtoN( *( (short*)( fond_data +
sizeof ( FamRec ) ) ) ) + 1;
}
static short
count_faces_scalable( char* fond_data )
{
AsscEntry* assoc;
short i, face, face_all;
face_all = EndianS16_BtoN( *( (short *)( fond_data +
sizeof ( FamRec ) ) ) ) + 1;
assoc = (AsscEntry*)( fond_data + sizeof ( FamRec ) + 2 );
face = 0;
for ( i = 0; i < face_all; i++ )
{
if ( 0 == EndianS16_BtoN( assoc[i].fontSize ) )
face++;
}
return face;
}
/* Look inside the FOND data, answer whether there should be an SFNT
resource, and answer the name of a possible LWFN Type 1 file.
Thanks to Paul Miller (paulm@profoundeffects.com) for the fix
to load a face OTHER than the first one in the FOND!
*/
static void
parse_fond( char* fond_data,
short* have_sfnt,
ResID* sfnt_id,
Str255 lwfn_file_name,
short face_index )
{
AsscEntry* assoc;
AsscEntry* base_assoc;
FamRec* fond;
*sfnt_id = 0;
*have_sfnt = 0;
lwfn_file_name[0] = 0;
fond = (FamRec*)fond_data;
assoc = (AsscEntry*)( fond_data + sizeof ( FamRec ) + 2 );
base_assoc = assoc;
/* the maximum faces in a FOND is 48, size of StyleTable.indexes[] */
if ( 47 < face_index )
return;
/* Let's do a little range checking before we get too excited here */
if ( face_index < count_faces_sfnt( fond_data ) )
{
assoc += face_index; /* add on the face_index! */
/* if the face at this index is not scalable,
fall back to the first one (old behavior) */
if ( EndianS16_BtoN( assoc->fontSize ) == 0 )
{
*have_sfnt = 1;
*sfnt_id = EndianS16_BtoN( assoc->fontID );
}
else if ( base_assoc->fontSize == 0 )
{
*have_sfnt = 1;
*sfnt_id = EndianS16_BtoN( base_assoc->fontID );
}
}
if ( EndianS32_BtoN( fond->ffStylOff ) )
{
unsigned char* p = (unsigned char*)fond_data;
StyleTable* style;
unsigned short string_count;
char ps_name[256];
unsigned char* names[64];
int i;
p += EndianS32_BtoN( fond->ffStylOff );
style = (StyleTable*)p;
p += sizeof ( StyleTable );
string_count = EndianS16_BtoN( *(short*)(p) );
p += sizeof ( short );
for ( i = 0; i < string_count && i < 64; i++ )
{
names[i] = p;
p += names[i][0];
p++;
}
{
size_t ps_name_len = (size_t)names[0][0];
if ( ps_name_len != 0 )
{
ft_memcpy(ps_name, names[0] + 1, ps_name_len);
ps_name[ps_name_len] = 0;
}
if ( style->indexes[face_index] > 1 &&
style->indexes[face_index] <= FT_MIN( string_count, 64 ) )
{
unsigned char* suffixes = names[style->indexes[face_index] - 1];
for ( i = 1; i <= suffixes[0]; i++ )
{
unsigned char* s;
size_t j = suffixes[i] - 1;
if ( j < string_count && ( s = names[j] ) != NULL )
{
size_t s_len = (size_t)s[0];
if ( s_len != 0 && ps_name_len + s_len < sizeof ( ps_name ) )
{
ft_memcpy( ps_name + ps_name_len, s + 1, s_len );
ps_name_len += s_len;
ps_name[ps_name_len] = 0;
}
}
}
}
}
create_lwfn_name( ps_name, lwfn_file_name );
}
}
static FT_Error
lookup_lwfn_by_fond( const UInt8* path_fond,
ConstStr255Param base_lwfn,
UInt8* path_lwfn,
size_t path_size )
{
FSRef ref, par_ref;
size_t dirname_len;
/* Pathname for FSRef can be in various formats: HFS, HFS+, and POSIX. */
/* We should not extract parent directory by string manipulation. */
if ( noErr != FSPathMakeRef( path_fond, &ref, FALSE ) )
return FT_THROW( Invalid_Argument );
if ( noErr != FSGetCatalogInfo( &ref, kFSCatInfoNone,
NULL, NULL, NULL, &par_ref ) )
return FT_THROW( Invalid_Argument );
if ( noErr != FSRefMakePath( &par_ref, path_lwfn, path_size ) )
return FT_THROW( Invalid_Argument );
if ( ft_strlen( (char *)path_lwfn ) + 1 + base_lwfn[0] > path_size )
return FT_THROW( Invalid_Argument );
/* now we have absolute dirname in path_lwfn */
ft_strcat( (char *)path_lwfn, "/" );
dirname_len = ft_strlen( (char *)path_lwfn );
ft_strcat( (char *)path_lwfn, (char *)base_lwfn + 1 );
path_lwfn[dirname_len + base_lwfn[0]] = '\0';
if ( noErr != FSPathMakeRef( path_lwfn, &ref, FALSE ) )
return FT_THROW( Cannot_Open_Resource );
if ( noErr != FSGetCatalogInfo( &ref, kFSCatInfoNone,
NULL, NULL, NULL, NULL ) )
return FT_THROW( Cannot_Open_Resource );
return FT_Err_Ok;
}
static short
count_faces( Handle fond,
const UInt8* pathname )
{
ResID sfnt_id;
short have_sfnt, have_lwfn;
Str255 lwfn_file_name;
UInt8 buff[PATH_MAX];
FT_Error err;
short num_faces;
have_sfnt = have_lwfn = 0;
parse_fond( *fond, &have_sfnt, &sfnt_id, lwfn_file_name, 0 );
if ( lwfn_file_name[0] )
{
err = lookup_lwfn_by_fond( pathname, lwfn_file_name,
buff, sizeof ( buff ) );
if ( !err )
have_lwfn = 1;
}
if ( have_lwfn && ( !have_sfnt || PREFER_LWFN ) )
num_faces = 1;
else
num_faces = count_faces_scalable( *fond );
return num_faces;
}
/* Read Type 1 data from the POST resources inside the LWFN file,
return a PFB buffer. This is somewhat convoluted because the FT2
PFB parser wants the ASCII header as one chunk, and the LWFN
chunks are often not organized that way, so we glue chunks
of the same type together. */
static FT_Error
read_lwfn( FT_Memory memory,
ResFileRefNum res,
FT_Byte** pfb_data,
FT_ULong* size )
{
FT_Error error = FT_Err_Ok;
ResID res_id;
unsigned char *buffer, *p, *size_p = NULL;
FT_ULong total_size = 0;
FT_ULong old_total_size = 0;
FT_ULong post_size, pfb_chunk_size;
Handle post_data;
char code, last_code;
UseResFile( res );
/* First pass: load all POST resources, and determine the size of */
/* the output buffer. */
res_id = 501;
last_code = -1;
for (;;)
{
post_data = Get1Resource( TTAG_POST, res_id++ );
if ( post_data == NULL )
break; /* we are done */
code = (*post_data)[0];
if ( code != last_code )
{
if ( code == 5 )
total_size += 2; /* just the end code */
else
total_size += 6; /* code + 4 bytes chunk length */
}
total_size += GetHandleSize( post_data ) - 2;
last_code = code;
/* detect integer overflows */
if ( total_size < old_total_size )
{
error = FT_THROW( Array_Too_Large );
goto Error;
}
old_total_size = total_size;
}
if ( FT_ALLOC( buffer, (FT_Long)total_size ) )
goto Error;
/* Second pass: append all POST data to the buffer, add PFB fields. */
/* Glue all consecutive chunks of the same type together. */
p = buffer;
res_id = 501;
last_code = -1;
pfb_chunk_size = 0;
for (;;)
{
post_data = Get1Resource( TTAG_POST, res_id++ );
if ( post_data == NULL )
break; /* we are done */
post_size = (FT_ULong)GetHandleSize( post_data ) - 2;
code = (*post_data)[0];
if ( code != last_code )
{
if ( last_code != -1 )
{
/* we are done adding a chunk, fill in the size field */
if ( size_p != NULL )
{
*size_p++ = (FT_Byte)( pfb_chunk_size & 0xFF );
*size_p++ = (FT_Byte)( ( pfb_chunk_size >> 8 ) & 0xFF );
*size_p++ = (FT_Byte)( ( pfb_chunk_size >> 16 ) & 0xFF );
*size_p++ = (FT_Byte)( ( pfb_chunk_size >> 24 ) & 0xFF );
}
pfb_chunk_size = 0;
}
*p++ = 0x80;
if ( code == 5 )
*p++ = 0x03; /* the end */
else if ( code == 2 )
*p++ = 0x02; /* binary segment */
else
*p++ = 0x01; /* ASCII segment */
if ( code != 5 )
{
size_p = p; /* save for later */
p += 4; /* make space for size field */
}
}
ft_memcpy( p, *post_data + 2, post_size );
pfb_chunk_size += post_size;
p += post_size;
last_code = code;
}
*pfb_data = buffer;
*size = total_size;
Error:
CloseResFile( res );
return error;
}
/* Create a new FT_Face from a file path to an LWFN file. */
static FT_Error
FT_New_Face_From_LWFN( FT_Library library,
const UInt8* pathname,
FT_Long face_index,
FT_Face* aface )
{
FT_Byte* pfb_data;
FT_ULong pfb_size;
FT_Error error;
ResFileRefNum res;
if ( noErr != FT_FSPathMakeRes( pathname, &res ) )
return FT_THROW( Cannot_Open_Resource );
pfb_data = NULL;
pfb_size = 0;
error = read_lwfn( library->memory, res, &pfb_data, &pfb_size );
CloseResFile( res ); /* PFB is already loaded, useless anymore */
if ( error )
return error;
return open_face_from_buffer( library,
pfb_data,
pfb_size,
face_index,
"type1",
aface );
}
/* Create a new FT_Face from an SFNT resource, specified by res ID. */
static FT_Error
FT_New_Face_From_SFNT( FT_Library library,
ResID sfnt_id,
FT_Long face_index,
FT_Face* aface )
{
Handle sfnt = NULL;
FT_Byte* sfnt_data;
size_t sfnt_size;
FT_Error error = FT_Err_Ok;
FT_Memory memory = library->memory;
int is_cff, is_sfnt_ps;
sfnt = GetResource( TTAG_sfnt, sfnt_id );
if ( sfnt == NULL )
return FT_THROW( Invalid_Handle );
sfnt_size = (FT_ULong)GetHandleSize( sfnt );
if ( FT_ALLOC( sfnt_data, (FT_Long)sfnt_size ) )
{
ReleaseResource( sfnt );
return error;
}
ft_memcpy( sfnt_data, *sfnt, sfnt_size );
ReleaseResource( sfnt );
is_cff = sfnt_size > 4 && !ft_memcmp( sfnt_data, "OTTO", 4 );
is_sfnt_ps = sfnt_size > 4 && !ft_memcmp( sfnt_data, "typ1", 4 );
if ( is_sfnt_ps )
{
FT_Stream stream;
if ( FT_NEW( stream ) )
goto Try_OpenType;
FT_Stream_OpenMemory( stream, sfnt_data, sfnt_size );
if ( !open_face_PS_from_sfnt_stream( library,
stream,
face_index,
0, NULL,
aface ) )
{
FT_Stream_Close( stream );
FT_FREE( stream );
FT_FREE( sfnt_data );
goto Exit;
}
FT_FREE( stream );
}
Try_OpenType:
error = open_face_from_buffer( library,
sfnt_data,
sfnt_size,
face_index,
is_cff ? "cff" : "truetype",
aface );
Exit:
return error;
}
/* Create a new FT_Face from a file path to a suitcase file. */
static FT_Error
FT_New_Face_From_Suitcase( FT_Library library,
const UInt8* pathname,
FT_Long face_index,
FT_Face* aface )
{
FT_Error error = FT_ERR( Cannot_Open_Resource );
ResFileRefNum res_ref;
ResourceIndex res_index;
Handle fond;
short num_faces_in_res;
if ( noErr != FT_FSPathMakeRes( pathname, &res_ref ) )
return FT_THROW( Cannot_Open_Resource );
UseResFile( res_ref );
if ( ResError() )
return FT_THROW( Cannot_Open_Resource );
num_faces_in_res = 0;
for ( res_index = 1; ; ++res_index )
{
short num_faces_in_fond;
fond = Get1IndResource( TTAG_FOND, res_index );
if ( ResError() )
break;
num_faces_in_fond = count_faces( fond, pathname );
num_faces_in_res += num_faces_in_fond;
if ( 0 <= face_index && face_index < num_faces_in_fond && error )
error = FT_New_Face_From_FOND( library, fond, face_index, aface );
face_index -= num_faces_in_fond;
}
CloseResFile( res_ref );
if ( !error && aface && *aface )
(*aface)->num_faces = num_faces_in_res;
return error;
}
/* documentation is in ftmac.h */
FT_EXPORT_DEF( FT_Error )
FT_New_Face_From_FOND( FT_Library library,
Handle fond,
FT_Long face_index,
FT_Face* aface )
{
short have_sfnt, have_lwfn = 0;
ResID sfnt_id, fond_id;
OSType fond_type;
Str255 fond_name;
Str255 lwfn_file_name;
UInt8 path_lwfn[PATH_MAX];
OSErr err;
FT_Error error = FT_Err_Ok;
GetResInfo( fond, &fond_id, &fond_type, fond_name );
if ( ResError() != noErr || fond_type != TTAG_FOND )
return FT_THROW( Invalid_File_Format );
parse_fond( *fond, &have_sfnt, &sfnt_id, lwfn_file_name, face_index );
if ( lwfn_file_name[0] )
{
ResFileRefNum res;
res = HomeResFile( fond );
if ( noErr != ResError() )
goto found_no_lwfn_file;
{
UInt8 path_fond[PATH_MAX];
FSRef ref;
err = FSGetForkCBInfo( res, kFSInvalidVolumeRefNum,
NULL, NULL, NULL, &ref, NULL );
if ( noErr != err )
goto found_no_lwfn_file;
err = FSRefMakePath( &ref, path_fond, sizeof ( path_fond ) );
if ( noErr != err )
goto found_no_lwfn_file;
error = lookup_lwfn_by_fond( path_fond, lwfn_file_name,
path_lwfn, sizeof ( path_lwfn ) );
if ( !error )
have_lwfn = 1;
}
}
if ( have_lwfn && ( !have_sfnt || PREFER_LWFN ) )
error = FT_New_Face_From_LWFN( library,
path_lwfn,
face_index,
aface );
else
error = FT_THROW( Unknown_File_Format );
found_no_lwfn_file:
if ( have_sfnt && error )
error = FT_New_Face_From_SFNT( library,
sfnt_id,
face_index,
aface );
return error;
}
/* Common function to load a new FT_Face from a resource file. */
static FT_Error
FT_New_Face_From_Resource( FT_Library library,
const UInt8* pathname,
FT_Long face_index,
FT_Face* aface )
{
OSType file_type;
FT_Error error;
/* LWFN is a (very) specific file format, check for it explicitly */
file_type = get_file_type_from_path( pathname );
if ( file_type == TTAG_LWFN )
return FT_New_Face_From_LWFN( library, pathname, face_index, aface );
/* Otherwise the file type doesn't matter (there are more than */
/* `FFIL' and `tfil'). Just try opening it as a font suitcase; */
/* if it works, fine. */
error = FT_New_Face_From_Suitcase( library, pathname, face_index, aface );
if ( error == 0 )
return error;
/* let it fall through to normal loader (.ttf, .otf, etc.); */
/* we signal this by returning no error and no FT_Face */
*aface = NULL;
return 0;
}
/*************************************************************************/
/* */
/* <Function> */
/* FT_New_Face */
/* */
/* <Description> */
/* This is the Mac-specific implementation of FT_New_Face. In */
/* addition to the standard FT_New_Face() functionality, it also */
/* accepts pathnames to Mac suitcase files. For further */
/* documentation see the original FT_New_Face() in freetype.h. */
/* */
FT_EXPORT_DEF( FT_Error )
FT_New_Face( FT_Library library,
const char* pathname,
FT_Long face_index,
FT_Face* aface )
{
FT_Open_Args args;
FT_Error error;
/* test for valid `library' and `aface' delayed to FT_Open_Face() */
if ( !pathname )
return FT_THROW( Invalid_Argument );
*aface = NULL;
/* try resourcefork based font: LWFN, FFIL */
error = FT_New_Face_From_Resource( library, (UInt8 *)pathname,
face_index, aface );
if ( error != 0 || *aface != NULL )
return error;
/* let it fall through to normal loader (.ttf, .otf, etc.) */
args.flags = FT_OPEN_PATHNAME;
args.pathname = (char*)pathname;
return FT_Open_Face( library, &args, face_index, aface );
}
/*************************************************************************/
/* */
/* <Function> */
/* FT_New_Face_From_FSRef */
/* */
/* <Description> */
/* FT_New_Face_From_FSRef is identical to FT_New_Face except it */
/* accepts an FSRef instead of a path. */
/* */
/* This function is deprecated because Carbon data types (FSRef) */
/* are not cross-platform, and thus not suitable for the freetype API. */
FT_EXPORT_DEF( FT_Error )
FT_New_Face_From_FSRef( FT_Library library,
const FSRef* ref,
FT_Long face_index,
FT_Face* aface )
{
FT_Error error;
FT_Open_Args args;
OSErr err;
UInt8 pathname[PATH_MAX];
if ( !ref )
return FT_THROW( Invalid_Argument );
err = FSRefMakePath( ref, pathname, sizeof ( pathname ) );
if ( err )
error = FT_THROW( Cannot_Open_Resource );
error = FT_New_Face_From_Resource( library, pathname, face_index, aface );
if ( error != 0 || *aface != NULL )
return error;
/* fallback to datafork font */
args.flags = FT_OPEN_PATHNAME;
args.pathname = (char*)pathname;
return FT_Open_Face( library, &args, face_index, aface );
}
/*************************************************************************/
/* */
/* <Function> */
/* FT_New_Face_From_FSSpec */
/* */
/* <Description> */
/* FT_New_Face_From_FSSpec is identical to FT_New_Face except it */
/* accepts an FSSpec instead of a path. */
/* */
/* This function is deprecated because FSSpec is deprecated in Mac OS X */
FT_EXPORT_DEF( FT_Error )
FT_New_Face_From_FSSpec( FT_Library library,
const FSSpec* spec,
FT_Long face_index,
FT_Face* aface )
{
#if ( __LP64__ ) || ( defined( MAC_OS_X_VERSION_10_5 ) && \
( MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5 ) )
FT_UNUSED( library );
FT_UNUSED( spec );
FT_UNUSED( face_index );
FT_UNUSED( aface );
return FT_THROW( Unimplemented_Feature );
#else
FSRef ref;
if ( !spec || FSpMakeFSRef( spec, &ref ) != noErr )
return FT_THROW( Invalid_Argument );
else
return FT_New_Face_From_FSRef( library, &ref, face_index, aface );
#endif
}
#endif /* FT_MACINTOSH */
/* END */
| YifuLiu/AliOS-Things | components/freetype/src/base/ftmac.c | C | apache-2.0 | 32,963 |
/***************************************************************************/
/* */
/* ftmm.c */
/* */
/* Multiple Master font support (body). */
/* */
/* Copyright 1996-2001, 2003, 2004, 2009, 2013 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. */
/* */
/***************************************************************************/
#include <ft2build.h>
#include FT_INTERNAL_DEBUG_H
#include FT_MULTIPLE_MASTERS_H
#include FT_INTERNAL_OBJECTS_H
#include FT_SERVICE_MULTIPLE_MASTERS_H
/*************************************************************************/
/* */
/* The macro FT_COMPONENT is used in trace mode. It is an implicit */
/* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */
/* messages during execution. */
/* */
#undef FT_COMPONENT
#define FT_COMPONENT trace_mm
static FT_Error
ft_face_get_mm_service( FT_Face face,
FT_Service_MultiMasters *aservice )
{
FT_Error error;
*aservice = NULL;
if ( !face )
return FT_THROW( Invalid_Face_Handle );
error = FT_ERR( Invalid_Argument );
if ( FT_HAS_MULTIPLE_MASTERS( face ) )
{
FT_FACE_LOOKUP_SERVICE( face,
*aservice,
MULTI_MASTERS );
if ( *aservice )
error = FT_Err_Ok;
}
return error;
}
/* documentation is in ftmm.h */
FT_EXPORT_DEF( FT_Error )
FT_Get_Multi_Master( FT_Face face,
FT_Multi_Master *amaster )
{
FT_Error error;
FT_Service_MultiMasters service;
error = ft_face_get_mm_service( face, &service );
if ( !error )
{
error = FT_ERR( Invalid_Argument );
if ( service->get_mm )
error = service->get_mm( face, amaster );
}
return error;
}
/* documentation is in ftmm.h */
FT_EXPORT_DEF( FT_Error )
FT_Get_MM_Var( FT_Face face,
FT_MM_Var* *amaster )
{
FT_Error error;
FT_Service_MultiMasters service;
error = ft_face_get_mm_service( face, &service );
if ( !error )
{
error = FT_ERR( Invalid_Argument );
if ( service->get_mm_var )
error = service->get_mm_var( face, amaster );
}
return error;
}
/* documentation is in ftmm.h */
FT_EXPORT_DEF( FT_Error )
FT_Set_MM_Design_Coordinates( FT_Face face,
FT_UInt num_coords,
FT_Long* coords )
{
FT_Error error;
FT_Service_MultiMasters service;
error = ft_face_get_mm_service( face, &service );
if ( !error )
{
error = FT_ERR( Invalid_Argument );
if ( service->set_mm_design )
error = service->set_mm_design( face, num_coords, coords );
}
return error;
}
/* documentation is in ftmm.h */
FT_EXPORT_DEF( FT_Error )
FT_Set_Var_Design_Coordinates( FT_Face face,
FT_UInt num_coords,
FT_Fixed* coords )
{
FT_Error error;
FT_Service_MultiMasters service;
error = ft_face_get_mm_service( face, &service );
if ( !error )
{
error = FT_ERR( Invalid_Argument );
if ( service->set_var_design )
error = service->set_var_design( face, num_coords, coords );
}
return error;
}
/* documentation is in ftmm.h */
FT_EXPORT_DEF( FT_Error )
FT_Set_MM_Blend_Coordinates( FT_Face face,
FT_UInt num_coords,
FT_Fixed* coords )
{
FT_Error error;
FT_Service_MultiMasters service;
error = ft_face_get_mm_service( face, &service );
if ( !error )
{
error = FT_ERR( Invalid_Argument );
if ( service->set_mm_blend )
error = service->set_mm_blend( face, num_coords, coords );
}
return error;
}
/* documentation is in ftmm.h */
/* This is exactly the same as the previous function. It exists for */
/* orthogonality. */
FT_EXPORT_DEF( FT_Error )
FT_Set_Var_Blend_Coordinates( FT_Face face,
FT_UInt num_coords,
FT_Fixed* coords )
{
FT_Error error;
FT_Service_MultiMasters service;
error = ft_face_get_mm_service( face, &service );
if ( !error )
{
error = FT_ERR( Invalid_Argument );
if ( service->set_mm_blend )
error = service->set_mm_blend( face, num_coords, coords );
}
return error;
}
/* END */
| YifuLiu/AliOS-Things | components/freetype/src/base/ftmm.c | C | apache-2.0 | 5,782 |
/***************************************************************************/
/* */
/* ftobjs.c */
/* */
/* The FreeType private base classes (body). */
/* */
/* Copyright 1996-2014 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. */
/* */
/***************************************************************************/
#include <ft2build.h>
#include FT_LIST_H
#include FT_OUTLINE_H
#include FT_INTERNAL_VALIDATE_H
#include FT_INTERNAL_OBJECTS_H
#include FT_INTERNAL_DEBUG_H
#include FT_INTERNAL_RFORK_H
#include FT_INTERNAL_STREAM_H
#include FT_INTERNAL_SFNT_H /* for SFNT_Load_Table_Func */
#include FT_TRUETYPE_TABLES_H
#include FT_TRUETYPE_TAGS_H
#include FT_TRUETYPE_IDS_H
#include FT_SERVICE_PROPERTIES_H
#include FT_SERVICE_SFNT_H
#include FT_SERVICE_POSTSCRIPT_NAME_H
#include FT_SERVICE_GLYPH_DICT_H
#include FT_SERVICE_TT_CMAP_H
#include FT_SERVICE_KERNING_H
#include FT_SERVICE_TRUETYPE_ENGINE_H
#ifdef FT_CONFIG_OPTION_MAC_FONTS
#include "ftbase.h"
#endif
#ifdef FT_DEBUG_LEVEL_TRACE
#include FT_BITMAP_H
#if defined( _MSC_VER ) /* Visual C++ (and Intel C++) */
/* We disable the warning `conversion from XXX to YYY, */
/* possible loss of data' in order to compile cleanly with */
/* the maximum level of warnings: `md5.c' is non-FreeType */
/* code, and it gets used during development builds only. */
#pragma warning( push )
#pragma warning( disable : 4244 )
#endif /* _MSC_VER */
/* it's easiest to include `md5.c' directly */
#include "md5.c"
#if defined( _MSC_VER )
#pragma warning( pop )
#endif
#endif /* FT_DEBUG_LEVEL_TRACE */
#define GRID_FIT_METRICS
FT_BASE_DEF( FT_Pointer )
ft_service_list_lookup( FT_ServiceDesc service_descriptors,
const char* service_id )
{
FT_Pointer result = NULL;
FT_ServiceDesc desc = service_descriptors;
if ( desc && service_id )
{
for ( ; desc->serv_id != NULL; desc++ )
{
if ( ft_strcmp( desc->serv_id, service_id ) == 0 )
{
result = (FT_Pointer)desc->serv_data;
break;
}
}
}
return result;
}
FT_BASE_DEF( void )
ft_validator_init( FT_Validator valid,
const FT_Byte* base,
const FT_Byte* limit,
FT_ValidationLevel level )
{
valid->base = base;
valid->limit = limit;
valid->level = level;
valid->error = FT_Err_Ok;
}
FT_BASE_DEF( FT_Int )
ft_validator_run( FT_Validator valid )
{
/* This function doesn't work! None should call it. */
FT_UNUSED( valid );
return -1;
}
FT_BASE_DEF( void )
ft_validator_error( FT_Validator valid,
FT_Error error )
{
/* since the cast below also disables the compiler's */
/* type check, we introduce a dummy variable, which */
/* will be optimized away */
volatile ft_jmp_buf* jump_buffer = &valid->jump_buffer;
valid->error = error;
/* throw away volatileness; use `jump_buffer' or the */
/* compiler may warn about an unused local variable */
ft_longjmp( *(ft_jmp_buf*) jump_buffer, 1 );
}
/*************************************************************************/
/*************************************************************************/
/*************************************************************************/
/**** ****/
/**** ****/
/**** S T R E A M ****/
/**** ****/
/**** ****/
/*************************************************************************/
/*************************************************************************/
/*************************************************************************/
/* create a new input stream from an FT_Open_Args structure */
/* */
FT_BASE_DEF( FT_Error )
FT_Stream_New( FT_Library library,
const FT_Open_Args* args,
FT_Stream *astream )
{
FT_Error error = FT_Err_Ok;
FT_Memory memory;
FT_Stream stream = NULL;
*astream = 0;
if ( !library )
return FT_THROW( Invalid_Library_Handle );
if ( !args )
return FT_THROW( Invalid_Argument );
memory = library->memory;
if ( FT_NEW( stream ) )
goto Exit;
stream->memory = memory;
if ( args->flags & FT_OPEN_MEMORY )
{
/* create a memory-based stream */
FT_Stream_OpenMemory( stream,
(const FT_Byte*)args->memory_base,
args->memory_size );
}
#ifndef FT_CONFIG_OPTION_DISABLE_STREAM_SUPPORT
else if ( args->flags & FT_OPEN_PATHNAME )
{
/* create a normal system stream */
error = FT_Stream_Open( stream, args->pathname );
stream->pathname.pointer = args->pathname;
}
else if ( ( args->flags & FT_OPEN_STREAM ) && args->stream )
{
/* use an existing, user-provided stream */
/* in this case, we do not need to allocate a new stream object */
/* since the caller is responsible for closing it himself */
FT_FREE( stream );
stream = args->stream;
}
#endif
else
error = FT_THROW( Invalid_Argument );
if ( error )
FT_FREE( stream );
else
stream->memory = memory; /* just to be certain */
*astream = stream;
Exit:
return error;
}
FT_BASE_DEF( void )
FT_Stream_Free( FT_Stream stream,
FT_Int external )
{
if ( stream )
{
FT_Memory memory = stream->memory;
FT_Stream_Close( stream );
if ( !external )
FT_FREE( stream );
}
}
/*************************************************************************/
/* */
/* The macro FT_COMPONENT is used in trace mode. It is an implicit */
/* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */
/* messages during execution. */
/* */
#undef FT_COMPONENT
#define FT_COMPONENT trace_objs
/*************************************************************************/
/*************************************************************************/
/*************************************************************************/
/**** ****/
/**** ****/
/**** FACE, SIZE & GLYPH SLOT OBJECTS ****/
/**** ****/
/**** ****/
/*************************************************************************/
/*************************************************************************/
/*************************************************************************/
static FT_Error
ft_glyphslot_init( FT_GlyphSlot slot )
{
FT_Driver driver = slot->face->driver;
FT_Driver_Class clazz = driver->clazz;
FT_Memory memory = driver->root.memory;
FT_Error error = FT_Err_Ok;
FT_Slot_Internal internal = NULL;
slot->library = driver->root.library;
if ( FT_NEW( internal ) )
goto Exit;
slot->internal = internal;
if ( FT_DRIVER_USES_OUTLINES( driver ) )
error = FT_GlyphLoader_New( memory, &internal->loader );
if ( !error && clazz->init_slot )
error = clazz->init_slot( slot );
Exit:
return error;
}
FT_BASE_DEF( void )
ft_glyphslot_free_bitmap( FT_GlyphSlot slot )
{
if ( slot->internal && ( slot->internal->flags & FT_GLYPH_OWN_BITMAP ) )
{
FT_Memory memory = FT_FACE_MEMORY( slot->face );
FT_FREE( slot->bitmap.buffer );
slot->internal->flags &= ~FT_GLYPH_OWN_BITMAP;
}
else
{
/* assume that the bitmap buffer was stolen or not */
/* allocated from the heap */
slot->bitmap.buffer = NULL;
}
}
FT_BASE_DEF( void )
ft_glyphslot_set_bitmap( FT_GlyphSlot slot,
FT_Byte* buffer )
{
ft_glyphslot_free_bitmap( slot );
slot->bitmap.buffer = buffer;
FT_ASSERT( (slot->internal->flags & FT_GLYPH_OWN_BITMAP) == 0 );
}
FT_BASE_DEF( FT_Error )
ft_glyphslot_alloc_bitmap( FT_GlyphSlot slot,
FT_ULong size )
{
FT_Memory memory = FT_FACE_MEMORY( slot->face );
FT_Error error = FT_Err_Ok;
if ( slot->internal->flags & FT_GLYPH_OWN_BITMAP )
FT_FREE( slot->bitmap.buffer );
else
slot->internal->flags |= FT_GLYPH_OWN_BITMAP;
(void)FT_ALLOC( slot->bitmap.buffer, size );
return error;
}
static void
ft_glyphslot_clear( FT_GlyphSlot slot )
{
/* free bitmap if needed */
ft_glyphslot_free_bitmap( slot );
/* clear all public fields in the glyph slot */
FT_ZERO( &slot->metrics );
FT_ZERO( &slot->outline );
slot->bitmap.width = 0;
slot->bitmap.rows = 0;
slot->bitmap.pitch = 0;
slot->bitmap.pixel_mode = 0;
/* `slot->bitmap.buffer' has been handled by ft_glyphslot_free_bitmap */
slot->bitmap_left = 0;
slot->bitmap_top = 0;
slot->num_subglyphs = 0;
slot->subglyphs = 0;
slot->control_data = 0;
slot->control_len = 0;
slot->other = 0;
slot->format = FT_GLYPH_FORMAT_NONE;
slot->linearHoriAdvance = 0;
slot->linearVertAdvance = 0;
slot->lsb_delta = 0;
slot->rsb_delta = 0;
}
static void
ft_glyphslot_done( FT_GlyphSlot slot )
{
FT_Driver driver = slot->face->driver;
FT_Driver_Class clazz = driver->clazz;
FT_Memory memory = driver->root.memory;
if ( clazz->done_slot )
clazz->done_slot( slot );
/* free bitmap buffer if needed */
ft_glyphslot_free_bitmap( slot );
/* slot->internal might be NULL in out-of-memory situations */
if ( slot->internal )
{
/* free glyph loader */
if ( FT_DRIVER_USES_OUTLINES( driver ) )
{
FT_GlyphLoader_Done( slot->internal->loader );
slot->internal->loader = 0;
}
FT_FREE( slot->internal );
}
}
/* documentation is in ftobjs.h */
FT_BASE_DEF( FT_Error )
FT_New_GlyphSlot( FT_Face face,
FT_GlyphSlot *aslot )
{
FT_Error error;
FT_Driver driver;
FT_Driver_Class clazz;
FT_Memory memory;
FT_GlyphSlot slot = NULL;
if ( !face || !face->driver )
return FT_THROW( Invalid_Argument );
driver = face->driver;
clazz = driver->clazz;
memory = driver->root.memory;
FT_TRACE4(( "FT_New_GlyphSlot: Creating new slot object\n" ));
if ( !FT_ALLOC( slot, clazz->slot_object_size ) )
{
slot->face = face;
error = ft_glyphslot_init( slot );
if ( error )
{
ft_glyphslot_done( slot );
FT_FREE( slot );
goto Exit;
}
slot->next = face->glyph;
face->glyph = slot;
if ( aslot )
*aslot = slot;
}
else if ( aslot )
*aslot = 0;
Exit:
FT_TRACE4(( "FT_New_GlyphSlot: Return %d\n", error ));
return error;
}
/* documentation is in ftobjs.h */
FT_BASE_DEF( void )
FT_Done_GlyphSlot( FT_GlyphSlot slot )
{
if ( slot )
{
FT_Driver driver = slot->face->driver;
FT_Memory memory = driver->root.memory;
FT_GlyphSlot prev;
FT_GlyphSlot cur;
/* Remove slot from its parent face's list */
prev = NULL;
cur = slot->face->glyph;
while ( cur )
{
if ( cur == slot )
{
if ( !prev )
slot->face->glyph = cur->next;
else
prev->next = cur->next;
/* finalize client-specific data */
if ( slot->generic.finalizer )
slot->generic.finalizer( slot );
ft_glyphslot_done( slot );
FT_FREE( slot );
break;
}
prev = cur;
cur = cur->next;
}
}
}
/* documentation is in freetype.h */
FT_EXPORT_DEF( void )
FT_Set_Transform( FT_Face face,
FT_Matrix* matrix,
FT_Vector* delta )
{
FT_Face_Internal internal;
if ( !face )
return;
internal = face->internal;
internal->transform_flags = 0;
if ( !matrix )
{
internal->transform_matrix.xx = 0x10000L;
internal->transform_matrix.xy = 0;
internal->transform_matrix.yx = 0;
internal->transform_matrix.yy = 0x10000L;
matrix = &internal->transform_matrix;
}
else
internal->transform_matrix = *matrix;
/* set transform_flags bit flag 0 if `matrix' isn't the identity */
if ( ( matrix->xy | matrix->yx ) ||
matrix->xx != 0x10000L ||
matrix->yy != 0x10000L )
internal->transform_flags |= 1;
if ( !delta )
{
internal->transform_delta.x = 0;
internal->transform_delta.y = 0;
delta = &internal->transform_delta;
}
else
internal->transform_delta = *delta;
/* set transform_flags bit flag 1 if `delta' isn't the null vector */
if ( delta->x | delta->y )
internal->transform_flags |= 2;
}
static FT_Renderer
ft_lookup_glyph_renderer( FT_GlyphSlot slot );
#ifdef GRID_FIT_METRICS
static void
ft_glyphslot_grid_fit_metrics( FT_GlyphSlot slot,
FT_Bool vertical )
{
FT_Glyph_Metrics* metrics = &slot->metrics;
FT_Pos right, bottom;
if ( vertical )
{
metrics->horiBearingX = FT_PIX_FLOOR( metrics->horiBearingX );
metrics->horiBearingY = FT_PIX_CEIL ( metrics->horiBearingY );
right = FT_PIX_CEIL( metrics->vertBearingX + metrics->width );
bottom = FT_PIX_CEIL( metrics->vertBearingY + metrics->height );
metrics->vertBearingX = FT_PIX_FLOOR( metrics->vertBearingX );
metrics->vertBearingY = FT_PIX_FLOOR( metrics->vertBearingY );
metrics->width = right - metrics->vertBearingX;
metrics->height = bottom - metrics->vertBearingY;
}
else
{
metrics->vertBearingX = FT_PIX_FLOOR( metrics->vertBearingX );
metrics->vertBearingY = FT_PIX_FLOOR( metrics->vertBearingY );
right = FT_PIX_CEIL ( metrics->horiBearingX + metrics->width );
bottom = FT_PIX_FLOOR( metrics->horiBearingY - metrics->height );
metrics->horiBearingX = FT_PIX_FLOOR( metrics->horiBearingX );
metrics->horiBearingY = FT_PIX_CEIL ( metrics->horiBearingY );
metrics->width = right - metrics->horiBearingX;
metrics->height = metrics->horiBearingY - bottom;
}
metrics->horiAdvance = FT_PIX_ROUND( metrics->horiAdvance );
metrics->vertAdvance = FT_PIX_ROUND( metrics->vertAdvance );
}
#endif /* GRID_FIT_METRICS */
/* documentation is in freetype.h */
FT_EXPORT_DEF( FT_Error )
FT_Load_Glyph( FT_Face face,
FT_UInt glyph_index,
FT_Int32 load_flags )
{
FT_Error error;
FT_Driver driver;
FT_GlyphSlot slot;
FT_Library library;
FT_Bool autohint = FALSE;
FT_Module hinter;
TT_Face ttface = (TT_Face)face;
if ( !face || !face->size || !face->glyph )
return FT_THROW( Invalid_Face_Handle );
/* The validity test for `glyph_index' is performed by the */
/* font drivers. */
slot = face->glyph;
ft_glyphslot_clear( slot );
driver = face->driver;
library = driver->root.library;
hinter = library->auto_hinter;
/* resolve load flags dependencies */
if ( load_flags & FT_LOAD_NO_RECURSE )
load_flags |= FT_LOAD_NO_SCALE |
FT_LOAD_IGNORE_TRANSFORM;
if ( load_flags & FT_LOAD_NO_SCALE )
{
load_flags |= FT_LOAD_NO_HINTING |
FT_LOAD_NO_BITMAP;
load_flags &= ~FT_LOAD_RENDER;
}
/*
* Determine whether we need to auto-hint or not.
* The general rules are:
*
* - Do only auto-hinting if we have a hinter module, a scalable font
* format dealing with outlines, and no transforms except simple
* slants and/or rotations by integer multiples of 90 degrees.
*
* - Then, auto-hint if FT_LOAD_FORCE_AUTOHINT is set or if we don't
* have a native font hinter.
*
* - Otherwise, auto-hint for LIGHT hinting mode or if there isn't
* any hinting bytecode in the TrueType/OpenType font.
*
* - Exception: The font is `tricky' and requires the native hinter to
* load properly.
*/
if ( hinter &&
!( load_flags & FT_LOAD_NO_HINTING ) &&
!( load_flags & FT_LOAD_NO_AUTOHINT ) &&
FT_DRIVER_IS_SCALABLE( driver ) &&
FT_DRIVER_USES_OUTLINES( driver ) &&
!FT_IS_TRICKY( face ) &&
( ( load_flags & FT_LOAD_IGNORE_TRANSFORM ) ||
( face->internal->transform_matrix.yx == 0 &&
face->internal->transform_matrix.xx != 0 ) ||
( face->internal->transform_matrix.xx == 0 &&
face->internal->transform_matrix.yx != 0 ) ) )
{
if ( ( load_flags & FT_LOAD_FORCE_AUTOHINT ) ||
!FT_DRIVER_HAS_HINTER( driver ) )
autohint = TRUE;
else
{
FT_Render_Mode mode = FT_LOAD_TARGET_MODE( load_flags );
/* the check for `num_locations' assures that we actually */
/* test for instructions in a TTF and not in a CFF-based OTF */
/* */
/* since `maxSizeOfInstructions' might be unreliable, we */
/* check the size of the `fpgm' and `prep' tables, too -- */
/* the assumption is that there don't exist real TTFs where */
/* both `fpgm' and `prep' tables are missing */
if ( mode == FT_RENDER_MODE_LIGHT ||
face->internal->ignore_unpatented_hinter ||
( FT_IS_SFNT( face ) &&
ttface->num_locations &&
ttface->max_profile.maxSizeOfInstructions == 0 &&
ttface->font_program_size == 0 &&
ttface->cvt_program_size == 0 ) )
autohint = TRUE;
}
}
if ( autohint )
{
FT_AutoHinter_Interface hinting;
/* try to load embedded bitmaps first if available */
/* */
/* XXX: This is really a temporary hack that should disappear */
/* promptly with FreeType 2.1! */
/* */
if ( FT_HAS_FIXED_SIZES( face ) &&
( load_flags & FT_LOAD_NO_BITMAP ) == 0 )
{
error = driver->clazz->load_glyph( slot, face->size,
glyph_index,
load_flags | FT_LOAD_SBITS_ONLY );
if ( !error && slot->format == FT_GLYPH_FORMAT_BITMAP )
goto Load_Ok;
}
{
FT_Face_Internal internal = face->internal;
FT_Int transform_flags = internal->transform_flags;
/* since the auto-hinter calls FT_Load_Glyph by itself, */
/* make sure that glyphs aren't transformed */
internal->transform_flags = 0;
/* load auto-hinted outline */
hinting = (FT_AutoHinter_Interface)hinter->clazz->module_interface;
error = hinting->load_glyph( (FT_AutoHinter)hinter,
slot, face->size,
glyph_index, load_flags );
internal->transform_flags = transform_flags;
}
}
else
{
error = driver->clazz->load_glyph( slot,
face->size,
glyph_index,
load_flags );
if ( error )
goto Exit;
if ( slot->format == FT_GLYPH_FORMAT_OUTLINE )
{
/* check that the loaded outline is correct */
error = FT_Outline_Check( &slot->outline );
if ( error )
goto Exit;
#ifdef GRID_FIT_METRICS
if ( !( load_flags & FT_LOAD_NO_HINTING ) )
ft_glyphslot_grid_fit_metrics( slot,
FT_BOOL( load_flags & FT_LOAD_VERTICAL_LAYOUT ) );
#endif
}
}
Load_Ok:
/* compute the advance */
if ( load_flags & FT_LOAD_VERTICAL_LAYOUT )
{
slot->advance.x = 0;
slot->advance.y = slot->metrics.vertAdvance;
}
else
{
slot->advance.x = slot->metrics.horiAdvance;
slot->advance.y = 0;
}
/* compute the linear advance in 16.16 pixels */
if ( ( load_flags & FT_LOAD_LINEAR_DESIGN ) == 0 &&
( FT_IS_SCALABLE( face ) ) )
{
FT_Size_Metrics* metrics = &face->size->metrics;
/* it's tricky! */
slot->linearHoriAdvance = FT_MulDiv( slot->linearHoriAdvance,
metrics->x_scale, 64 );
slot->linearVertAdvance = FT_MulDiv( slot->linearVertAdvance,
metrics->y_scale, 64 );
}
if ( ( load_flags & FT_LOAD_IGNORE_TRANSFORM ) == 0 )
{
FT_Face_Internal internal = face->internal;
/* now, transform the glyph image if needed */
if ( internal->transform_flags )
{
/* get renderer */
FT_Renderer renderer = ft_lookup_glyph_renderer( slot );
if ( renderer )
error = renderer->clazz->transform_glyph(
renderer, slot,
&internal->transform_matrix,
&internal->transform_delta );
else if ( slot->format == FT_GLYPH_FORMAT_OUTLINE )
{
/* apply `standard' transformation if no renderer is available */
if ( internal->transform_flags & 1 )
FT_Outline_Transform( &slot->outline,
&internal->transform_matrix );
if ( internal->transform_flags & 2 )
FT_Outline_Translate( &slot->outline,
internal->transform_delta.x,
internal->transform_delta.y );
}
/* transform advance */
FT_Vector_Transform( &slot->advance, &internal->transform_matrix );
}
}
FT_TRACE5(( " x advance: %d\n" , slot->advance.x ));
FT_TRACE5(( " y advance: %d\n" , slot->advance.y ));
FT_TRACE5(( " linear x advance: %d\n" , slot->linearHoriAdvance ));
FT_TRACE5(( " linear y advance: %d\n" , slot->linearVertAdvance ));
/* do we need to render the image now? */
if ( !error &&
slot->format != FT_GLYPH_FORMAT_BITMAP &&
slot->format != FT_GLYPH_FORMAT_COMPOSITE &&
load_flags & FT_LOAD_RENDER )
{
FT_Render_Mode mode = FT_LOAD_TARGET_MODE( load_flags );
if ( mode == FT_RENDER_MODE_NORMAL &&
(load_flags & FT_LOAD_MONOCHROME ) )
mode = FT_RENDER_MODE_MONO;
error = FT_Render_Glyph( slot, mode );
}
Exit:
return error;
}
/* documentation is in freetype.h */
FT_EXPORT_DEF( FT_Error )
FT_Load_Char( FT_Face face,
FT_ULong char_code,
FT_Int32 load_flags )
{
FT_UInt glyph_index;
if ( !face )
return FT_THROW( Invalid_Face_Handle );
glyph_index = (FT_UInt)char_code;
if ( face->charmap )
glyph_index = FT_Get_Char_Index( face, char_code );
return FT_Load_Glyph( face, glyph_index, load_flags );
}
/* destructor for sizes list */
static void
destroy_size( FT_Memory memory,
FT_Size size,
FT_Driver driver )
{
/* finalize client-specific data */
if ( size->generic.finalizer )
size->generic.finalizer( size );
/* finalize format-specific stuff */
if ( driver->clazz->done_size )
driver->clazz->done_size( size );
FT_FREE( size->internal );
FT_FREE( size );
}
static void
ft_cmap_done_internal( FT_CMap cmap );
static void
destroy_charmaps( FT_Face face,
FT_Memory memory )
{
FT_Int n;
if ( !face )
return;
for ( n = 0; n < face->num_charmaps; n++ )
{
FT_CMap cmap = FT_CMAP( face->charmaps[n] );
ft_cmap_done_internal( cmap );
face->charmaps[n] = NULL;
}
FT_FREE( face->charmaps );
face->num_charmaps = 0;
}
/* destructor for faces list */
static void
destroy_face( FT_Memory memory,
FT_Face face,
FT_Driver driver )
{
FT_Driver_Class clazz = driver->clazz;
/* discard auto-hinting data */
if ( face->autohint.finalizer )
face->autohint.finalizer( face->autohint.data );
/* Discard glyph slots for this face. */
/* Beware! FT_Done_GlyphSlot() changes the field `face->glyph' */
while ( face->glyph )
FT_Done_GlyphSlot( face->glyph );
/* discard all sizes for this face */
FT_List_Finalize( &face->sizes_list,
(FT_List_Destructor)destroy_size,
memory,
driver );
face->size = 0;
/* now discard client data */
if ( face->generic.finalizer )
face->generic.finalizer( face );
/* discard charmaps */
destroy_charmaps( face, memory );
/* finalize format-specific stuff */
if ( clazz->done_face )
clazz->done_face( face );
/* close the stream for this face if needed */
FT_Stream_Free(
face->stream,
( face->face_flags & FT_FACE_FLAG_EXTERNAL_STREAM ) != 0 );
face->stream = 0;
/* get rid of it */
if ( face->internal )
{
FT_FREE( face->internal );
}
FT_FREE( face );
}
static void
Destroy_Driver( FT_Driver driver )
{
FT_List_Finalize( &driver->faces_list,
(FT_List_Destructor)destroy_face,
driver->root.memory,
driver );
/* check whether we need to drop the driver's glyph loader */
if ( FT_DRIVER_USES_OUTLINES( driver ) )
FT_GlyphLoader_Done( driver->glyph_loader );
}
/*************************************************************************/
/* */
/* <Function> */
/* find_unicode_charmap */
/* */
/* <Description> */
/* This function finds a Unicode charmap, if there is one. */
/* And if there is more than one, it tries to favour the more */
/* extensive one, i.e., one that supports UCS-4 against those which */
/* are limited to the BMP (said UCS-2 encoding.) */
/* */
/* This function is called from open_face() (just below), and also */
/* from FT_Select_Charmap( ..., FT_ENCODING_UNICODE ). */
/* */
static FT_Error
find_unicode_charmap( FT_Face face )
{
FT_CharMap* first;
FT_CharMap* cur;
/* caller should have already checked that `face' is valid */
FT_ASSERT( face );
first = face->charmaps;
if ( !first )
return FT_THROW( Invalid_CharMap_Handle );
/*
* The original TrueType specification(s) only specified charmap
* formats that are capable of mapping 8 or 16 bit character codes to
* glyph indices.
*
* However, recent updates to the Apple and OpenType specifications
* introduced new formats that are capable of mapping 32-bit character
* codes as well. And these are already used on some fonts, mainly to
* map non-BMP Asian ideographs as defined in Unicode.
*
* For compatibility purposes, these fonts generally come with
* *several* Unicode charmaps:
*
* - One of them in the "old" 16-bit format, that cannot access
* all glyphs in the font.
*
* - Another one in the "new" 32-bit format, that can access all
* the glyphs.
*
* This function has been written to always favor a 32-bit charmap
* when found. Otherwise, a 16-bit one is returned when found.
*/
/* Since the `interesting' table, with IDs (3,10), is normally the */
/* last one, we loop backwards. This loses with type1 fonts with */
/* non-BMP characters (<.0001%), this wins with .ttf with non-BMP */
/* chars (.01% ?), and this is the same about 99.99% of the time! */
cur = first + face->num_charmaps; /* points after the last one */
for ( ; --cur >= first; )
{
if ( cur[0]->encoding == FT_ENCODING_UNICODE )
{
/* XXX If some new encodings to represent UCS-4 are added, */
/* they should be added here. */
if ( ( cur[0]->platform_id == TT_PLATFORM_MICROSOFT &&
cur[0]->encoding_id == TT_MS_ID_UCS_4 ) ||
( cur[0]->platform_id == TT_PLATFORM_APPLE_UNICODE &&
cur[0]->encoding_id == TT_APPLE_ID_UNICODE_32 ) )
{
#ifdef FT_MAX_CHARMAP_CACHEABLE
if ( cur - first > FT_MAX_CHARMAP_CACHEABLE )
{
FT_ERROR(( "find_unicode_charmap: UCS-4 cmap is found "
"at too late position (%d)\n", cur - first ));
continue;
}
#endif
face->charmap = cur[0];
return FT_Err_Ok;
}
}
}
/* We do not have any UCS-4 charmap. */
/* Do the loop again and search for UCS-2 charmaps. */
cur = first + face->num_charmaps;
for ( ; --cur >= first; )
{
if ( cur[0]->encoding == FT_ENCODING_UNICODE )
{
#ifdef FT_MAX_CHARMAP_CACHEABLE
if ( cur - first > FT_MAX_CHARMAP_CACHEABLE )
{
FT_ERROR(( "find_unicode_charmap: UCS-2 cmap is found "
"at too late position (%d)\n", cur - first ));
continue;
}
#endif
face->charmap = cur[0];
return FT_Err_Ok;
}
}
return FT_THROW( Invalid_CharMap_Handle );
}
/*************************************************************************/
/* */
/* <Function> */
/* find_variant_selector_charmap */
/* */
/* <Description> */
/* This function finds the variant selector charmap, if there is one. */
/* There can only be one (platform=0, specific=5, format=14). */
/* */
static FT_CharMap
find_variant_selector_charmap( FT_Face face )
{
FT_CharMap* first;
FT_CharMap* end;
FT_CharMap* cur;
/* caller should have already checked that `face' is valid */
FT_ASSERT( face );
first = face->charmaps;
if ( !first )
return NULL;
end = first + face->num_charmaps; /* points after the last one */
for ( cur = first; cur < end; ++cur )
{
if ( cur[0]->platform_id == TT_PLATFORM_APPLE_UNICODE &&
cur[0]->encoding_id == TT_APPLE_ID_VARIANT_SELECTOR &&
FT_Get_CMap_Format( cur[0] ) == 14 )
{
#ifdef FT_MAX_CHARMAP_CACHEABLE
if ( cur - first > FT_MAX_CHARMAP_CACHEABLE )
{
FT_ERROR(( "find_unicode_charmap: UVS cmap is found "
"at too late position (%d)\n", cur - first ));
continue;
}
#endif
return cur[0];
}
}
return NULL;
}
/*************************************************************************/
/* */
/* <Function> */
/* open_face */
/* */
/* <Description> */
/* This function does some work for FT_Open_Face(). */
/* */
static FT_Error
open_face( FT_Driver driver,
FT_Stream *astream,
FT_Bool external_stream,
FT_Long face_index,
FT_Int num_params,
FT_Parameter* params,
FT_Face *aface )
{
FT_Memory memory;
FT_Driver_Class clazz;
FT_Face face = NULL;
FT_Face_Internal internal = NULL;
FT_Error error = FT_Err_Ok;
FT_Error error2 = FT_Err_Ok;
clazz = driver->clazz;
memory = driver->root.memory;
/* allocate the face object and perform basic initialization */
if ( FT_ALLOC( face, clazz->face_object_size ) )
goto Fail;
face->driver = driver;
face->memory = memory;
face->stream = *astream;
/* set the FT_FACE_FLAG_EXTERNAL_STREAM bit for FT_Done_Face */
if ( external_stream )
face->face_flags |= FT_FACE_FLAG_EXTERNAL_STREAM;
if ( FT_NEW( internal ) )
goto Fail;
face->internal = internal;
#ifdef FT_CONFIG_OPTION_INCREMENTAL
{
int i;
face->internal->incremental_interface = 0;
for ( i = 0; i < num_params && !face->internal->incremental_interface;
i++ )
if ( params[i].tag == FT_PARAM_TAG_INCREMENTAL )
face->internal->incremental_interface =
(FT_Incremental_Interface)params[i].data;
}
#endif
if ( clazz->init_face )
error = clazz->init_face( *astream,
face,
(FT_Int)face_index,
num_params,
params );
*astream = face->stream; /* Stream may have been changed. */
if ( error )
goto Fail;
/* select Unicode charmap by default */
error2 = find_unicode_charmap( face );
/* if no Unicode charmap can be found, FT_Err_Invalid_CharMap_Handle */
/* is returned. */
/* no error should happen, but we want to play safe */
if ( error2 && FT_ERR_NEQ( error2, Invalid_CharMap_Handle ) )
{
error = error2;
goto Fail;
}
*aface = face;
Fail:
if ( error )
{
destroy_charmaps( face, memory );
if ( clazz->done_face )
clazz->done_face( face );
FT_FREE( internal );
FT_FREE( face );
*aface = 0;
}
return error;
}
/* there's a Mac-specific extended implementation of FT_New_Face() */
/* in src/base/ftmac.c */
#ifndef FT_MACINTOSH
/* documentation is in freetype.h */
FT_EXPORT_DEF( FT_Error )
FT_New_Face( FT_Library library,
const char* pathname,
FT_Long face_index,
FT_Face *aface )
{
FT_Open_Args args;
/* test for valid `library' and `aface' delayed to FT_Open_Face() */
if ( !pathname )
return FT_THROW( Invalid_Argument );
args.flags = FT_OPEN_PATHNAME;
args.pathname = (char*)pathname;
args.stream = NULL;
return FT_Open_Face( library, &args, face_index, aface );
}
#endif
/* documentation is in freetype.h */
FT_EXPORT_DEF( FT_Error )
FT_New_Memory_Face( FT_Library library,
const FT_Byte* file_base,
FT_Long file_size,
FT_Long face_index,
FT_Face *aface )
{
FT_Open_Args args;
/* test for valid `library' and `face' delayed to FT_Open_Face() */
if ( !file_base )
return FT_THROW( Invalid_Argument );
args.flags = FT_OPEN_MEMORY;
args.memory_base = file_base;
args.memory_size = file_size;
args.stream = NULL;
return FT_Open_Face( library, &args, face_index, aface );
}
#ifdef FT_CONFIG_OPTION_MAC_FONTS
/* The behavior here is very similar to that in base/ftmac.c, but it */
/* is designed to work on non-mac systems, so no mac specific calls. */
/* */
/* We look at the file and determine if it is a mac dfont file or a mac */
/* resource file, or a macbinary file containing a mac resource file. */
/* */
/* Unlike ftmac I'm not going to look at a `FOND'. I don't really see */
/* the point, especially since there may be multiple `FOND' resources. */
/* Instead I'll just look for `sfnt' and `POST' resources, ordered as */
/* they occur in the file. */
/* */
/* Note that multiple `POST' resources do not mean multiple postscript */
/* fonts; they all get jammed together to make what is essentially a */
/* pfb file. */
/* */
/* We aren't interested in `NFNT' or `FONT' bitmap resources. */
/* */
/* As soon as we get an `sfnt' load it into memory and pass it off to */
/* FT_Open_Face. */
/* */
/* If we have a (set of) `POST' resources, massage them into a (memory) */
/* pfb file and pass that to FT_Open_Face. (As with ftmac.c I'm not */
/* going to try to save the kerning info. After all that lives in the */
/* `FOND' which isn't in the file containing the `POST' resources so */
/* we don't really have access to it. */
/* Finalizer for a memory stream; gets called by FT_Done_Face(). */
/* It frees the memory it uses. */
/* From ftmac.c. */
static void
memory_stream_close( FT_Stream stream )
{
FT_Memory memory = stream->memory;
FT_FREE( stream->base );
stream->size = 0;
stream->base = 0;
stream->close = 0;
}
/* Create a new memory stream from a buffer and a size. */
/* From ftmac.c. */
static FT_Error
new_memory_stream( FT_Library library,
FT_Byte* base,
FT_ULong size,
FT_Stream_CloseFunc close,
FT_Stream *astream )
{
FT_Error error;
FT_Memory memory;
FT_Stream stream = NULL;
if ( !library )
return FT_THROW( Invalid_Library_Handle );
if ( !base )
return FT_THROW( Invalid_Argument );
*astream = 0;
memory = library->memory;
if ( FT_NEW( stream ) )
goto Exit;
FT_Stream_OpenMemory( stream, base, size );
stream->close = close;
*astream = stream;
Exit:
return error;
}
/* Create a new FT_Face given a buffer and a driver name. */
/* from ftmac.c */
FT_LOCAL_DEF( FT_Error )
open_face_from_buffer( FT_Library library,
FT_Byte* base,
FT_ULong size,
FT_Long face_index,
const char* driver_name,
FT_Face *aface )
{
FT_Open_Args args;
FT_Error error;
FT_Stream stream = NULL;
FT_Memory memory = library->memory;
error = new_memory_stream( library,
base,
size,
memory_stream_close,
&stream );
if ( error )
{
FT_FREE( base );
return error;
}
args.flags = FT_OPEN_STREAM;
args.stream = stream;
if ( driver_name )
{
args.flags = args.flags | FT_OPEN_DRIVER;
args.driver = FT_Get_Module( library, driver_name );
}
#ifdef FT_MACINTOSH
/* At this point, face_index has served its purpose; */
/* whoever calls this function has already used it to */
/* locate the correct font data. We should not propagate */
/* this index to FT_Open_Face() (unless it is negative). */
if ( face_index > 0 )
face_index = 0;
#endif
error = FT_Open_Face( library, &args, face_index, aface );
if ( error == FT_Err_Ok )
(*aface)->face_flags &= ~FT_FACE_FLAG_EXTERNAL_STREAM;
else
#ifdef FT_MACINTOSH
FT_Stream_Free( stream, 0 );
#else
{
FT_Stream_Close( stream );
FT_FREE( stream );
}
#endif
return error;
}
/* Look up `TYP1' or `CID ' table from sfnt table directory. */
/* `offset' and `length' must exclude the binary header in tables. */
/* Type 1 and CID-keyed font drivers should recognize sfnt-wrapped */
/* format too. Here, since we can't expect that the TrueType font */
/* driver is loaded unconditially, we must parse the font by */
/* ourselves. We are only interested in the name of the table and */
/* the offset. */
static FT_Error
ft_lookup_PS_in_sfnt_stream( FT_Stream stream,
FT_Long face_index,
FT_ULong* offset,
FT_ULong* length,
FT_Bool* is_sfnt_cid )
{
FT_Error error;
FT_UShort numTables;
FT_Long pstable_index;
FT_ULong tag;
int i;
*offset = 0;
*length = 0;
*is_sfnt_cid = FALSE;
/* TODO: support for sfnt-wrapped PS/CID in TTC format */
/* version check for 'typ1' (should be ignored?) */
if ( FT_READ_ULONG( tag ) )
return error;
if ( tag != TTAG_typ1 )
return FT_THROW( Unknown_File_Format );
if ( FT_READ_USHORT( numTables ) )
return error;
if ( FT_STREAM_SKIP( 2 * 3 ) ) /* skip binary search header */
return error;
pstable_index = -1;
*is_sfnt_cid = FALSE;
for ( i = 0; i < numTables; i++ )
{
if ( FT_READ_ULONG( tag ) || FT_STREAM_SKIP( 4 ) ||
FT_READ_ULONG( *offset ) || FT_READ_ULONG( *length ) )
return error;
if ( tag == TTAG_CID )
{
pstable_index++;
*offset += 22;
*length -= 22;
*is_sfnt_cid = TRUE;
if ( face_index < 0 )
return FT_Err_Ok;
}
else if ( tag == TTAG_TYP1 )
{
pstable_index++;
*offset += 24;
*length -= 24;
*is_sfnt_cid = FALSE;
if ( face_index < 0 )
return FT_Err_Ok;
}
if ( face_index >= 0 && pstable_index == face_index )
return FT_Err_Ok;
}
return FT_THROW( Table_Missing );
}
FT_LOCAL_DEF( FT_Error )
open_face_PS_from_sfnt_stream( FT_Library library,
FT_Stream stream,
FT_Long face_index,
FT_Int num_params,
FT_Parameter *params,
FT_Face *aface )
{
FT_Error error;
FT_Memory memory = library->memory;
FT_ULong offset, length;
FT_Long pos;
FT_Bool is_sfnt_cid;
FT_Byte* sfnt_ps = NULL;
FT_UNUSED( num_params );
FT_UNUSED( params );
pos = FT_Stream_Pos( stream );
error = ft_lookup_PS_in_sfnt_stream( stream,
face_index,
&offset,
&length,
&is_sfnt_cid );
if ( error )
goto Exit;
if ( FT_Stream_Seek( stream, pos + offset ) )
goto Exit;
if ( FT_ALLOC( sfnt_ps, (FT_Long)length ) )
goto Exit;
error = FT_Stream_Read( stream, (FT_Byte *)sfnt_ps, length );
if ( error )
goto Exit;
error = open_face_from_buffer( library,
sfnt_ps,
length,
FT_MIN( face_index, 0 ),
is_sfnt_cid ? "cid" : "type1",
aface );
Exit:
{
FT_Error error1;
if ( FT_ERR_EQ( error, Unknown_File_Format ) )
{
error1 = FT_Stream_Seek( stream, pos );
if ( error1 )
return error1;
}
return error;
}
}
#ifndef FT_MACINTOSH
/* The resource header says we've got resource_cnt `POST' (type1) */
/* resources in this file. They all need to be coalesced into */
/* one lump which gets passed on to the type1 driver. */
/* Here can be only one PostScript font in a file so face_index */
/* must be 0 (or -1). */
/* */
static FT_Error
Mac_Read_POST_Resource( FT_Library library,
FT_Stream stream,
FT_Long *offsets,
FT_Long resource_cnt,
FT_Long face_index,
FT_Face *aface )
{
FT_Error error = FT_ERR( Cannot_Open_Resource );
FT_Memory memory = library->memory;
FT_Byte* pfb_data = NULL;
int i, type, flags;
FT_Long len;
FT_Long pfb_len, pfb_pos, pfb_lenpos;
FT_Long rlen, temp;
if ( face_index == -1 )
face_index = 0;
if ( face_index != 0 )
return error;
/* Find the length of all the POST resources, concatenated. Assume */
/* worst case (each resource in its own section). */
pfb_len = 0;
for ( i = 0; i < resource_cnt; ++i )
{
error = FT_Stream_Seek( stream, offsets[i] );
if ( error )
goto Exit;
if ( FT_READ_LONG( temp ) )
goto Exit;
pfb_len += temp + 6;
}
if ( FT_ALLOC( pfb_data, (FT_Long)pfb_len + 2 ) )
goto Exit;
pfb_data[0] = 0x80;
pfb_data[1] = 1; /* Ascii section */
pfb_data[2] = 0; /* 4-byte length, fill in later */
pfb_data[3] = 0;
pfb_data[4] = 0;
pfb_data[5] = 0;
pfb_pos = 6;
pfb_lenpos = 2;
len = 0;
type = 1;
for ( i = 0; i < resource_cnt; ++i )
{
error = FT_Stream_Seek( stream, offsets[i] );
if ( error )
goto Exit2;
if ( FT_READ_LONG( rlen ) )
goto Exit;
if ( FT_READ_USHORT( flags ) )
goto Exit;
FT_TRACE3(( "POST fragment[%d]: offsets=0x%08x, rlen=0x%08x, flags=0x%04x\n",
i, offsets[i], rlen, flags ));
/* postpone the check of rlen longer than buffer until FT_Stream_Read() */
if ( ( flags >> 8 ) == 0 ) /* Comment, should not be loaded */
continue;
/* the flags are part of the resource, so rlen >= 2. */
/* but some fonts declare rlen = 0 for empty fragment */
if ( rlen > 2 )
rlen -= 2;
else
rlen = 0;
if ( ( flags >> 8 ) == type )
len += rlen;
else
{
if ( pfb_lenpos + 3 > pfb_len + 2 )
goto Exit2;
pfb_data[pfb_lenpos ] = (FT_Byte)( len );
pfb_data[pfb_lenpos + 1] = (FT_Byte)( len >> 8 );
pfb_data[pfb_lenpos + 2] = (FT_Byte)( len >> 16 );
pfb_data[pfb_lenpos + 3] = (FT_Byte)( len >> 24 );
if ( ( flags >> 8 ) == 5 ) /* End of font mark */
break;
if ( pfb_pos + 6 > pfb_len + 2 )
goto Exit2;
pfb_data[pfb_pos++] = 0x80;
type = flags >> 8;
len = rlen;
pfb_data[pfb_pos++] = (FT_Byte)type;
pfb_lenpos = pfb_pos;
pfb_data[pfb_pos++] = 0; /* 4-byte length, fill in later */
pfb_data[pfb_pos++] = 0;
pfb_data[pfb_pos++] = 0;
pfb_data[pfb_pos++] = 0;
}
error = FT_ERR( Cannot_Open_Resource );
if ( pfb_pos > pfb_len || pfb_pos + rlen > pfb_len )
goto Exit2;
error = FT_Stream_Read( stream, (FT_Byte *)pfb_data + pfb_pos, rlen );
if ( error )
goto Exit2;
pfb_pos += rlen;
}
if ( pfb_pos + 2 > pfb_len + 2 )
goto Exit2;
pfb_data[pfb_pos++] = 0x80;
pfb_data[pfb_pos++] = 3;
if ( pfb_lenpos + 3 > pfb_len + 2 )
goto Exit2;
pfb_data[pfb_lenpos ] = (FT_Byte)( len );
pfb_data[pfb_lenpos + 1] = (FT_Byte)( len >> 8 );
pfb_data[pfb_lenpos + 2] = (FT_Byte)( len >> 16 );
pfb_data[pfb_lenpos + 3] = (FT_Byte)( len >> 24 );
return open_face_from_buffer( library,
pfb_data,
pfb_pos,
face_index,
"type1",
aface );
Exit2:
FT_FREE( pfb_data );
Exit:
return error;
}
/* The resource header says we've got resource_cnt `sfnt' */
/* (TrueType/OpenType) resources in this file. Look through */
/* them for the one indicated by face_index, load it into mem, */
/* pass it on the the truetype driver and return it. */
/* */
static FT_Error
Mac_Read_sfnt_Resource( FT_Library library,
FT_Stream stream,
FT_Long *offsets,
FT_Long resource_cnt,
FT_Long face_index,
FT_Face *aface )
{
FT_Memory memory = library->memory;
FT_Byte* sfnt_data = NULL;
FT_Error error;
FT_Long flag_offset;
FT_Long rlen;
int is_cff;
FT_Long face_index_in_resource = 0;
if ( face_index == -1 )
face_index = 0;
if ( face_index >= resource_cnt )
return FT_THROW( Cannot_Open_Resource );
flag_offset = offsets[face_index];
error = FT_Stream_Seek( stream, flag_offset );
if ( error )
goto Exit;
if ( FT_READ_LONG( rlen ) )
goto Exit;
if ( rlen == -1 )
return FT_THROW( Cannot_Open_Resource );
error = open_face_PS_from_sfnt_stream( library,
stream,
face_index,
0, NULL,
aface );
if ( !error )
goto Exit;
/* rewind sfnt stream before open_face_PS_from_sfnt_stream() */
if ( FT_Stream_Seek( stream, flag_offset + 4 ) )
goto Exit;
if ( FT_ALLOC( sfnt_data, (FT_Long)rlen ) )
return error;
error = FT_Stream_Read( stream, (FT_Byte *)sfnt_data, rlen );
if ( error )
goto Exit;
is_cff = rlen > 4 && !ft_memcmp( sfnt_data, "OTTO", 4 );
error = open_face_from_buffer( library,
sfnt_data,
rlen,
face_index_in_resource,
is_cff ? "cff" : "truetype",
aface );
Exit:
return error;
}
/* Check for a valid resource fork header, or a valid dfont */
/* header. In a resource fork the first 16 bytes are repeated */
/* at the location specified by bytes 4-7. In a dfont bytes */
/* 4-7 point to 16 bytes of zeroes instead. */
/* */
static FT_Error
IsMacResource( FT_Library library,
FT_Stream stream,
FT_Long resource_offset,
FT_Long face_index,
FT_Face *aface )
{
FT_Memory memory = library->memory;
FT_Error error;
FT_Long map_offset, rdara_pos;
FT_Long *data_offsets;
FT_Long count;
error = FT_Raccess_Get_HeaderInfo( library, stream, resource_offset,
&map_offset, &rdara_pos );
if ( error )
return error;
/* POST resources must be sorted to concatenate properly */
error = FT_Raccess_Get_DataOffsets( library, stream,
map_offset, rdara_pos,
TTAG_POST, TRUE,
&data_offsets, &count );
if ( !error )
{
error = Mac_Read_POST_Resource( library, stream, data_offsets, count,
face_index, aface );
FT_FREE( data_offsets );
/* POST exists in an LWFN providing a single face */
if ( !error )
(*aface)->num_faces = 1;
return error;
}
/* sfnt resources should not be sorted to preserve the face order by
QuickDraw API */
error = FT_Raccess_Get_DataOffsets( library, stream,
map_offset, rdara_pos,
TTAG_sfnt, FALSE,
&data_offsets, &count );
if ( !error )
{
FT_Long face_index_internal = face_index % count;
error = Mac_Read_sfnt_Resource( library, stream, data_offsets, count,
face_index_internal, aface );
FT_FREE( data_offsets );
if ( !error )
(*aface)->num_faces = count;
}
return error;
}
/* Check for a valid macbinary header, and if we find one */
/* check that the (flattened) resource fork in it is valid. */
/* */
static FT_Error
IsMacBinary( FT_Library library,
FT_Stream stream,
FT_Long face_index,
FT_Face *aface )
{
unsigned char header[128];
FT_Error error;
FT_Long dlen, offset;
if ( NULL == stream )
return FT_THROW( Invalid_Stream_Operation );
error = FT_Stream_Seek( stream, 0 );
if ( error )
goto Exit;
error = FT_Stream_Read( stream, (FT_Byte*)header, 128 );
if ( error )
goto Exit;
if ( header[ 0] != 0 ||
header[74] != 0 ||
header[82] != 0 ||
header[ 1] == 0 ||
header[ 1] > 33 ||
header[63] != 0 ||
header[2 + header[1]] != 0 )
return FT_THROW( Unknown_File_Format );
dlen = ( header[0x53] << 24 ) |
( header[0x54] << 16 ) |
( header[0x55] << 8 ) |
header[0x56];
#if 0
rlen = ( header[0x57] << 24 ) |
( header[0x58] << 16 ) |
( header[0x59] << 8 ) |
header[0x5a];
#endif /* 0 */
offset = 128 + ( ( dlen + 127 ) & ~127 );
return IsMacResource( library, stream, offset, face_index, aface );
Exit:
return error;
}
static FT_Error
load_face_in_embedded_rfork( FT_Library library,
FT_Stream stream,
FT_Long face_index,
FT_Face *aface,
const FT_Open_Args *args )
{
#undef FT_COMPONENT
#define FT_COMPONENT trace_raccess
FT_Memory memory = library->memory;
FT_Error error = FT_ERR( Unknown_File_Format );
int i;
char * file_names[FT_RACCESS_N_RULES];
FT_Long offsets[FT_RACCESS_N_RULES];
FT_Error errors[FT_RACCESS_N_RULES];
FT_Bool is_darwin_vfs, vfs_rfork_has_no_font = FALSE; /* not tested */
FT_Open_Args args2;
FT_Stream stream2 = 0;
FT_Raccess_Guess( library, stream,
args->pathname, file_names, offsets, errors );
for ( i = 0; i < FT_RACCESS_N_RULES; i++ )
{
is_darwin_vfs = ft_raccess_rule_by_darwin_vfs( library, i );
if ( is_darwin_vfs && vfs_rfork_has_no_font )
{
FT_TRACE3(( "Skip rule %d: darwin vfs resource fork"
" is already checked and"
" no font is found\n", i ));
continue;
}
if ( errors[i] )
{
FT_TRACE3(( "Error[%d] has occurred in rule %d\n", errors[i], i ));
continue;
}
args2.flags = FT_OPEN_PATHNAME;
args2.pathname = file_names[i] ? file_names[i] : args->pathname;
FT_TRACE3(( "Try rule %d: %s (offset=%d) ...",
i, args2.pathname, offsets[i] ));
error = FT_Stream_New( library, &args2, &stream2 );
if ( is_darwin_vfs && FT_ERR_EQ( error, Cannot_Open_Stream ) )
vfs_rfork_has_no_font = TRUE;
if ( error )
{
FT_TRACE3(( "failed\n" ));
continue;
}
error = IsMacResource( library, stream2, offsets[i],
face_index, aface );
FT_Stream_Free( stream2, 0 );
FT_TRACE3(( "%s\n", error ? "failed": "successful" ));
if ( !error )
break;
else if ( is_darwin_vfs )
vfs_rfork_has_no_font = TRUE;
}
for (i = 0; i < FT_RACCESS_N_RULES; i++)
{
if ( file_names[i] )
FT_FREE( file_names[i] );
}
/* Caller (load_mac_face) requires FT_Err_Unknown_File_Format. */
if ( error )
error = FT_ERR( Unknown_File_Format );
return error;
#undef FT_COMPONENT
#define FT_COMPONENT trace_objs
}
/* Check for some macintosh formats without Carbon framework. */
/* Is this a macbinary file? If so look at the resource fork. */
/* Is this a mac dfont file? */
/* Is this an old style resource fork? (in data) */
/* Else call load_face_in_embedded_rfork to try extra rules */
/* (defined in `ftrfork.c'). */
/* */
static FT_Error
load_mac_face( FT_Library library,
FT_Stream stream,
FT_Long face_index,
FT_Face *aface,
const FT_Open_Args *args )
{
FT_Error error;
FT_UNUSED( args );
error = IsMacBinary( library, stream, face_index, aface );
if ( FT_ERR_EQ( error, Unknown_File_Format ) )
{
#undef FT_COMPONENT
#define FT_COMPONENT trace_raccess
FT_TRACE3(( "Try as dfont: %s ...", args->pathname ));
error = IsMacResource( library, stream, 0, face_index, aface );
FT_TRACE3(( "%s\n", error ? "failed" : "successful" ));
#undef FT_COMPONENT
#define FT_COMPONENT trace_objs
}
if ( ( FT_ERR_EQ( error, Unknown_File_Format ) ||
FT_ERR_EQ( error, Invalid_Stream_Operation ) ) &&
( args->flags & FT_OPEN_PATHNAME ) )
error = load_face_in_embedded_rfork( library, stream,
face_index, aface, args );
return error;
}
#endif
#endif /* !FT_MACINTOSH && FT_CONFIG_OPTION_MAC_FONTS */
/* documentation is in freetype.h */
FT_EXPORT_DEF( FT_Error )
FT_Open_Face( FT_Library library,
const FT_Open_Args* args,
FT_Long face_index,
FT_Face *aface )
{
FT_Error error;
FT_Driver driver = NULL;
FT_Memory memory = NULL;
FT_Stream stream = NULL;
FT_Face face = NULL;
FT_ListNode node = NULL;
FT_Bool external_stream;
FT_Module* cur;
FT_Module* limit;
/* test for valid `library' delayed to */
/* FT_Stream_New() */
if ( ( !aface && face_index >= 0 ) || !args )
return FT_THROW( Invalid_Argument );
external_stream = FT_BOOL( ( args->flags & FT_OPEN_STREAM ) &&
args->stream );
/* create input stream */
error = FT_Stream_New( library, args, &stream );
if ( error )
goto Fail3;
memory = library->memory;
/* If the font driver is specified in the `args' structure, use */
/* it. Otherwise, we scan the list of registered drivers. */
if ( ( args->flags & FT_OPEN_DRIVER ) && args->driver )
{
driver = FT_DRIVER( args->driver );
/* not all modules are drivers, so check... */
if ( FT_MODULE_IS_DRIVER( driver ) )
{
FT_Int num_params = 0;
FT_Parameter* params = 0;
if ( args->flags & FT_OPEN_PARAMS )
{
num_params = args->num_params;
params = args->params;
}
error = open_face( driver, &stream, external_stream, face_index,
num_params, params, &face );
if ( !error )
goto Success;
}
else
error = FT_THROW( Invalid_Handle );
FT_Stream_Free( stream, external_stream );
goto Fail;
}
else
{
error = FT_ERR( Missing_Module );
/* check each font driver for an appropriate format */
cur = library->modules;
limit = cur + library->num_modules;
for ( ; cur < limit; cur++ )
{
/* not all modules are font drivers, so check... */
if ( FT_MODULE_IS_DRIVER( cur[0] ) )
{
FT_Int num_params = 0;
FT_Parameter* params = 0;
driver = FT_DRIVER( cur[0] );
if ( args->flags & FT_OPEN_PARAMS )
{
num_params = args->num_params;
params = args->params;
}
error = open_face( driver, &stream, external_stream, face_index,
num_params, params, &face );
if ( !error )
goto Success;
#ifdef FT_CONFIG_OPTION_MAC_FONTS
if ( ft_strcmp( cur[0]->clazz->module_name, "truetype" ) == 0 &&
FT_ERR_EQ( error, Table_Missing ) )
{
/* TrueType but essential tables are missing */
if ( FT_Stream_Seek( stream, 0 ) )
break;
error = open_face_PS_from_sfnt_stream( library,
stream,
face_index,
num_params,
params,
aface );
if ( !error )
{
FT_Stream_Free( stream, external_stream );
return error;
}
}
#endif
if ( FT_ERR_NEQ( error, Unknown_File_Format ) )
goto Fail3;
}
}
Fail3:
/* If we are on the mac, and we get an */
/* FT_Err_Invalid_Stream_Operation it may be because we have an */
/* empty data fork, so we need to check the resource fork. */
if ( FT_ERR_NEQ( error, Cannot_Open_Stream ) &&
FT_ERR_NEQ( error, Unknown_File_Format ) &&
FT_ERR_NEQ( error, Invalid_Stream_Operation ) )
goto Fail2;
#if !defined( FT_MACINTOSH ) && defined( FT_CONFIG_OPTION_MAC_FONTS )
error = load_mac_face( library, stream, face_index, aface, args );
if ( !error )
{
/* We don't want to go to Success here. We've already done that. */
/* On the other hand, if we succeeded we still need to close this */
/* stream (we opened a different stream which extracted the */
/* interesting information out of this stream here. That stream */
/* will still be open and the face will point to it). */
FT_Stream_Free( stream, external_stream );
return error;
}
if ( FT_ERR_NEQ( error, Unknown_File_Format ) )
goto Fail2;
#endif /* !FT_MACINTOSH && FT_CONFIG_OPTION_MAC_FONTS */
/* no driver is able to handle this format */
error = FT_THROW( Unknown_File_Format );
Fail2:
FT_Stream_Free( stream, external_stream );
goto Fail;
}
Success:
FT_TRACE4(( "FT_Open_Face: New face object, adding to list\n" ));
/* add the face object to its driver's list */
if ( FT_NEW( node ) )
goto Fail;
node->data = face;
/* don't assume driver is the same as face->driver, so use */
/* face->driver instead. */
FT_List_Add( &face->driver->faces_list, node );
/* now allocate a glyph slot object for the face */
FT_TRACE4(( "FT_Open_Face: Creating glyph slot\n" ));
if ( face_index >= 0 )
{
error = FT_New_GlyphSlot( face, NULL );
if ( error )
goto Fail;
/* finally, allocate a size object for the face */
{
FT_Size size;
FT_TRACE4(( "FT_Open_Face: Creating size object\n" ));
error = FT_New_Size( face, &size );
if ( error )
goto Fail;
face->size = size;
}
}
/* some checks */
if ( FT_IS_SCALABLE( face ) )
{
if ( face->height < 0 )
face->height = (FT_Short)-face->height;
if ( !FT_HAS_VERTICAL( face ) )
face->max_advance_height = (FT_Short)face->height;
}
if ( FT_HAS_FIXED_SIZES( face ) )
{
FT_Int i;
for ( i = 0; i < face->num_fixed_sizes; i++ )
{
FT_Bitmap_Size* bsize = face->available_sizes + i;
if ( bsize->height < 0 )
bsize->height = (FT_Short)-bsize->height;
if ( bsize->x_ppem < 0 )
bsize->x_ppem = (FT_Short)-bsize->x_ppem;
if ( bsize->y_ppem < 0 )
bsize->y_ppem = -bsize->y_ppem;
}
}
/* initialize internal face data */
{
FT_Face_Internal internal = face->internal;
internal->transform_matrix.xx = 0x10000L;
internal->transform_matrix.xy = 0;
internal->transform_matrix.yx = 0;
internal->transform_matrix.yy = 0x10000L;
internal->transform_delta.x = 0;
internal->transform_delta.y = 0;
internal->refcount = 1;
}
if ( aface )
*aface = face;
else
FT_Done_Face( face );
goto Exit;
Fail:
if ( node )
FT_Done_Face( face ); /* face must be in the driver's list */
else if ( face )
destroy_face( memory, face, driver );
Exit:
FT_TRACE4(( "FT_Open_Face: Return %d\n", error ));
return error;
}
/* documentation is in freetype.h */
FT_EXPORT_DEF( FT_Error )
FT_Attach_File( FT_Face face,
const char* filepathname )
{
FT_Open_Args open;
/* test for valid `face' delayed to FT_Attach_Stream() */
if ( !filepathname )
return FT_THROW( Invalid_Argument );
open.stream = NULL;
open.flags = FT_OPEN_PATHNAME;
open.pathname = (char*)filepathname;
return FT_Attach_Stream( face, &open );
}
/* documentation is in freetype.h */
FT_EXPORT_DEF( FT_Error )
FT_Attach_Stream( FT_Face face,
FT_Open_Args* parameters )
{
FT_Stream stream;
FT_Error error;
FT_Driver driver;
FT_Driver_Class clazz;
/* test for valid `parameters' delayed to FT_Stream_New() */
if ( !face )
return FT_THROW( Invalid_Face_Handle );
driver = face->driver;
if ( !driver )
return FT_THROW( Invalid_Driver_Handle );
error = FT_Stream_New( driver->root.library, parameters, &stream );
if ( error )
goto Exit;
/* we implement FT_Attach_Stream in each driver through the */
/* `attach_file' interface */
error = FT_ERR( Unimplemented_Feature );
clazz = driver->clazz;
if ( clazz->attach_file )
error = clazz->attach_file( face, stream );
/* close the attached stream */
FT_Stream_Free( stream,
(FT_Bool)( parameters->stream &&
( parameters->flags & FT_OPEN_STREAM ) ) );
Exit:
return error;
}
/* documentation is in freetype.h */
FT_EXPORT_DEF( FT_Error )
FT_Reference_Face( FT_Face face )
{
face->internal->refcount++;
return FT_Err_Ok;
}
/* documentation is in freetype.h */
FT_EXPORT_DEF( FT_Error )
FT_Done_Face( FT_Face face )
{
FT_Error error;
FT_Driver driver;
FT_Memory memory;
FT_ListNode node;
error = FT_ERR( Invalid_Face_Handle );
if ( face && face->driver )
{
face->internal->refcount--;
if ( face->internal->refcount > 0 )
error = FT_Err_Ok;
else
{
driver = face->driver;
memory = driver->root.memory;
/* find face in driver's list */
node = FT_List_Find( &driver->faces_list, face );
if ( node )
{
/* remove face object from the driver's list */
FT_List_Remove( &driver->faces_list, node );
FT_FREE( node );
/* now destroy the object proper */
destroy_face( memory, face, driver );
error = FT_Err_Ok;
}
}
}
return error;
}
/* documentation is in ftobjs.h */
FT_EXPORT_DEF( FT_Error )
FT_New_Size( FT_Face face,
FT_Size *asize )
{
FT_Error error = FT_Err_Ok;
FT_Memory memory;
FT_Driver driver;
FT_Driver_Class clazz;
FT_Size size = 0;
FT_ListNode node = 0;
if ( !face )
return FT_THROW( Invalid_Face_Handle );
if ( !asize )
return FT_THROW( Invalid_Size_Handle );
if ( !face->driver )
return FT_THROW( Invalid_Driver_Handle );
*asize = 0;
driver = face->driver;
clazz = driver->clazz;
memory = face->memory;
/* Allocate new size object and perform basic initialisation */
if ( FT_ALLOC( size, clazz->size_object_size ) || FT_NEW( node ) )
goto Exit;
size->face = face;
/* for now, do not use any internal fields in size objects */
size->internal = 0;
if ( clazz->init_size )
error = clazz->init_size( size );
/* in case of success, add to the face's list */
if ( !error )
{
*asize = size;
node->data = size;
FT_List_Add( &face->sizes_list, node );
}
Exit:
if ( error )
{
FT_FREE( node );
FT_FREE( size );
}
return error;
}
/* documentation is in ftobjs.h */
FT_EXPORT_DEF( FT_Error )
FT_Done_Size( FT_Size size )
{
FT_Error error;
FT_Driver driver;
FT_Memory memory;
FT_Face face;
FT_ListNode node;
if ( !size )
return FT_THROW( Invalid_Size_Handle );
face = size->face;
if ( !face )
return FT_THROW( Invalid_Face_Handle );
driver = face->driver;
if ( !driver )
return FT_THROW( Invalid_Driver_Handle );
memory = driver->root.memory;
error = FT_Err_Ok;
node = FT_List_Find( &face->sizes_list, size );
if ( node )
{
FT_List_Remove( &face->sizes_list, node );
FT_FREE( node );
if ( face->size == size )
{
face->size = 0;
if ( face->sizes_list.head )
face->size = (FT_Size)(face->sizes_list.head->data);
}
destroy_size( memory, size, driver );
}
else
error = FT_THROW( Invalid_Size_Handle );
return error;
}
/* documentation is in ftobjs.h */
FT_BASE_DEF( FT_Error )
FT_Match_Size( FT_Face face,
FT_Size_Request req,
FT_Bool ignore_width,
FT_ULong* size_index )
{
FT_Int i;
FT_Long w, h;
if ( !FT_HAS_FIXED_SIZES( face ) )
return FT_THROW( Invalid_Face_Handle );
/* FT_Bitmap_Size doesn't provide enough info... */
if ( req->type != FT_SIZE_REQUEST_TYPE_NOMINAL )
return FT_THROW( Unimplemented_Feature );
w = FT_REQUEST_WIDTH ( req );
h = FT_REQUEST_HEIGHT( req );
if ( req->width && !req->height )
h = w;
else if ( !req->width && req->height )
w = h;
w = FT_PIX_ROUND( w );
h = FT_PIX_ROUND( h );
for ( i = 0; i < face->num_fixed_sizes; i++ )
{
FT_Bitmap_Size* bsize = face->available_sizes + i;
if ( h != FT_PIX_ROUND( bsize->y_ppem ) )
continue;
if ( w == FT_PIX_ROUND( bsize->x_ppem ) || ignore_width )
{
FT_TRACE3(( "FT_Match_Size: bitmap strike %d matches\n", i ));
if ( size_index )
*size_index = (FT_ULong)i;
return FT_Err_Ok;
}
}
return FT_THROW( Invalid_Pixel_Size );
}
/* documentation is in ftobjs.h */
FT_BASE_DEF( void )
ft_synthesize_vertical_metrics( FT_Glyph_Metrics* metrics,
FT_Pos advance )
{
FT_Pos height = metrics->height;
/* compensate for glyph with bbox above/below the baseline */
if ( metrics->horiBearingY < 0 )
{
if ( height < metrics->horiBearingY )
height = metrics->horiBearingY;
}
else if ( metrics->horiBearingY > 0 )
height -= metrics->horiBearingY;
/* the factor 1.2 is a heuristical value */
if ( !advance )
advance = height * 12 / 10;
metrics->vertBearingX = metrics->horiBearingX - metrics->horiAdvance / 2;
metrics->vertBearingY = ( advance - height ) / 2;
metrics->vertAdvance = advance;
}
static void
ft_recompute_scaled_metrics( FT_Face face,
FT_Size_Metrics* metrics )
{
/* Compute root ascender, descender, test height, and max_advance */
#ifdef GRID_FIT_METRICS
metrics->ascender = FT_PIX_CEIL( FT_MulFix( face->ascender,
metrics->y_scale ) );
metrics->descender = FT_PIX_FLOOR( FT_MulFix( face->descender,
metrics->y_scale ) );
metrics->height = FT_PIX_ROUND( FT_MulFix( face->height,
metrics->y_scale ) );
metrics->max_advance = FT_PIX_ROUND( FT_MulFix( face->max_advance_width,
metrics->x_scale ) );
#else /* !GRID_FIT_METRICS */
metrics->ascender = FT_MulFix( face->ascender,
metrics->y_scale );
metrics->descender = FT_MulFix( face->descender,
metrics->y_scale );
metrics->height = FT_MulFix( face->height,
metrics->y_scale );
metrics->max_advance = FT_MulFix( face->max_advance_width,
metrics->x_scale );
#endif /* !GRID_FIT_METRICS */
}
FT_BASE_DEF( void )
FT_Select_Metrics( FT_Face face,
FT_ULong strike_index )
{
FT_Size_Metrics* metrics;
FT_Bitmap_Size* bsize;
metrics = &face->size->metrics;
bsize = face->available_sizes + strike_index;
metrics->x_ppem = (FT_UShort)( ( bsize->x_ppem + 32 ) >> 6 );
metrics->y_ppem = (FT_UShort)( ( bsize->y_ppem + 32 ) >> 6 );
if ( FT_IS_SCALABLE( face ) )
{
metrics->x_scale = FT_DivFix( bsize->x_ppem,
face->units_per_EM );
metrics->y_scale = FT_DivFix( bsize->y_ppem,
face->units_per_EM );
ft_recompute_scaled_metrics( face, metrics );
}
else
{
metrics->x_scale = 1L << 16;
metrics->y_scale = 1L << 16;
metrics->ascender = bsize->y_ppem;
metrics->descender = 0;
metrics->height = bsize->height << 6;
metrics->max_advance = bsize->x_ppem;
}
FT_TRACE5(( "FT_Select_Metrics:\n" ));
FT_TRACE5(( " x scale: %d (%f)\n",
metrics->x_scale, metrics->x_scale / 65536.0 ));
FT_TRACE5(( " y scale: %d (%f)\n",
metrics->y_scale, metrics->y_scale / 65536.0 ));
FT_TRACE5(( " ascender: %f\n", metrics->ascender / 64.0 ));
FT_TRACE5(( " descender: %f\n", metrics->descender / 64.0 ));
FT_TRACE5(( " height: %f\n", metrics->height / 64.0 ));
FT_TRACE5(( " max advance: %f\n", metrics->max_advance / 64.0 ));
FT_TRACE5(( " x ppem: %d\n", metrics->x_ppem ));
FT_TRACE5(( " y ppem: %d\n", metrics->y_ppem ));
}
FT_BASE_DEF( void )
FT_Request_Metrics( FT_Face face,
FT_Size_Request req )
{
FT_Size_Metrics* metrics;
metrics = &face->size->metrics;
if ( FT_IS_SCALABLE( face ) )
{
FT_Long w = 0, h = 0, scaled_w = 0, scaled_h = 0;
switch ( req->type )
{
case FT_SIZE_REQUEST_TYPE_NOMINAL:
w = h = face->units_per_EM;
break;
case FT_SIZE_REQUEST_TYPE_REAL_DIM:
w = h = face->ascender - face->descender;
break;
case FT_SIZE_REQUEST_TYPE_BBOX:
w = face->bbox.xMax - face->bbox.xMin;
h = face->bbox.yMax - face->bbox.yMin;
break;
case FT_SIZE_REQUEST_TYPE_CELL:
w = face->max_advance_width;
h = face->ascender - face->descender;
break;
case FT_SIZE_REQUEST_TYPE_SCALES:
metrics->x_scale = (FT_Fixed)req->width;
metrics->y_scale = (FT_Fixed)req->height;
if ( !metrics->x_scale )
metrics->x_scale = metrics->y_scale;
else if ( !metrics->y_scale )
metrics->y_scale = metrics->x_scale;
goto Calculate_Ppem;
case FT_SIZE_REQUEST_TYPE_MAX:
break;
}
/* to be on the safe side */
if ( w < 0 )
w = -w;
if ( h < 0 )
h = -h;
scaled_w = FT_REQUEST_WIDTH ( req );
scaled_h = FT_REQUEST_HEIGHT( req );
/* determine scales */
if ( req->width )
{
metrics->x_scale = FT_DivFix( scaled_w, w );
if ( req->height )
{
metrics->y_scale = FT_DivFix( scaled_h, h );
if ( req->type == FT_SIZE_REQUEST_TYPE_CELL )
{
if ( metrics->y_scale > metrics->x_scale )
metrics->y_scale = metrics->x_scale;
else
metrics->x_scale = metrics->y_scale;
}
}
else
{
metrics->y_scale = metrics->x_scale;
scaled_h = FT_MulDiv( scaled_w, h, w );
}
}
else
{
metrics->x_scale = metrics->y_scale = FT_DivFix( scaled_h, h );
scaled_w = FT_MulDiv( scaled_h, w, h );
}
Calculate_Ppem:
/* calculate the ppems */
if ( req->type != FT_SIZE_REQUEST_TYPE_NOMINAL )
{
scaled_w = FT_MulFix( face->units_per_EM, metrics->x_scale );
scaled_h = FT_MulFix( face->units_per_EM, metrics->y_scale );
}
metrics->x_ppem = (FT_UShort)( ( scaled_w + 32 ) >> 6 );
metrics->y_ppem = (FT_UShort)( ( scaled_h + 32 ) >> 6 );
ft_recompute_scaled_metrics( face, metrics );
}
else
{
FT_ZERO( metrics );
metrics->x_scale = 1L << 16;
metrics->y_scale = 1L << 16;
}
FT_TRACE5(( "FT_Request_Metrics:\n" ));
FT_TRACE5(( " x scale: %d (%f)\n",
metrics->x_scale, metrics->x_scale / 65536.0 ));
FT_TRACE5(( " y scale: %d (%f)\n",
metrics->y_scale, metrics->y_scale / 65536.0 ));
FT_TRACE5(( " ascender: %f\n", metrics->ascender / 64.0 ));
FT_TRACE5(( " descender: %f\n", metrics->descender / 64.0 ));
FT_TRACE5(( " height: %f\n", metrics->height / 64.0 ));
FT_TRACE5(( " max advance: %f\n", metrics->max_advance / 64.0 ));
FT_TRACE5(( " x ppem: %d\n", metrics->x_ppem ));
FT_TRACE5(( " y ppem: %d\n", metrics->y_ppem ));
}
/* documentation is in freetype.h */
FT_EXPORT_DEF( FT_Error )
FT_Select_Size( FT_Face face,
FT_Int strike_index )
{
FT_Driver_Class clazz;
if ( !face || !FT_HAS_FIXED_SIZES( face ) )
return FT_THROW( Invalid_Face_Handle );
if ( strike_index < 0 || strike_index >= face->num_fixed_sizes )
return FT_THROW( Invalid_Argument );
clazz = face->driver->clazz;
if ( clazz->select_size )
{
FT_Error error;
error = clazz->select_size( face->size, (FT_ULong)strike_index );
#ifdef FT_DEBUG_LEVEL_TRACE
{
FT_Size_Metrics* metrics = &face->size->metrics;
FT_TRACE5(( "FT_Select_Size (font driver's `select_size'):\n" ));
FT_TRACE5(( " x scale: %d (%f)\n",
metrics->x_scale, metrics->x_scale / 65536.0 ));
FT_TRACE5(( " y scale: %d (%f)\n",
metrics->y_scale, metrics->y_scale / 65536.0 ));
FT_TRACE5(( " ascender: %f\n", metrics->ascender / 64.0 ));
FT_TRACE5(( " descender: %f\n", metrics->descender / 64.0 ));
FT_TRACE5(( " height: %f\n", metrics->height / 64.0 ));
FT_TRACE5(( " max advance: %f\n", metrics->max_advance / 64.0 ));
FT_TRACE5(( " x ppem: %d\n", metrics->x_ppem ));
FT_TRACE5(( " y ppem: %d\n", metrics->y_ppem ));
}
#endif
return error;
}
FT_Select_Metrics( face, (FT_ULong)strike_index );
return FT_Err_Ok;
}
/* documentation is in freetype.h */
FT_EXPORT_DEF( FT_Error )
FT_Request_Size( FT_Face face,
FT_Size_Request req )
{
FT_Driver_Class clazz;
FT_ULong strike_index;
if ( !face )
return FT_THROW( Invalid_Face_Handle );
if ( !req || req->width < 0 || req->height < 0 ||
req->type >= FT_SIZE_REQUEST_TYPE_MAX )
return FT_THROW( Invalid_Argument );
clazz = face->driver->clazz;
if ( clazz->request_size )
{
FT_Error error;
error = clazz->request_size( face->size, req );
#ifdef FT_DEBUG_LEVEL_TRACE
{
FT_Size_Metrics* metrics = &face->size->metrics;
FT_TRACE5(( "FT_Request_Size (font driver's `request_size'):\n" ));
FT_TRACE5(( " x scale: %d (%f)\n",
metrics->x_scale, metrics->x_scale / 65536.0 ));
FT_TRACE5(( " y scale: %d (%f)\n",
metrics->y_scale, metrics->y_scale / 65536.0 ));
FT_TRACE5(( " ascender: %f\n", metrics->ascender / 64.0 ));
FT_TRACE5(( " descender: %f\n", metrics->descender / 64.0 ));
FT_TRACE5(( " height: %f\n", metrics->height / 64.0 ));
FT_TRACE5(( " max advance: %f\n", metrics->max_advance / 64.0 ));
FT_TRACE5(( " x ppem: %d\n", metrics->x_ppem ));
FT_TRACE5(( " y ppem: %d\n", metrics->y_ppem ));
}
#endif
return error;
}
/*
* The reason that a driver doesn't have `request_size' defined is
* either that the scaling here suffices or that the supported formats
* are bitmap-only and size matching is not implemented.
*
* In the latter case, a simple size matching is done.
*/
if ( !FT_IS_SCALABLE( face ) && FT_HAS_FIXED_SIZES( face ) )
{
FT_Error error;
error = FT_Match_Size( face, req, 0, &strike_index );
if ( error )
return error;
return FT_Select_Size( face, (FT_Int)strike_index );
}
FT_Request_Metrics( face, req );
return FT_Err_Ok;
}
/* documentation is in freetype.h */
FT_EXPORT_DEF( FT_Error )
FT_Set_Char_Size( FT_Face face,
FT_F26Dot6 char_width,
FT_F26Dot6 char_height,
FT_UInt horz_resolution,
FT_UInt vert_resolution )
{
FT_Size_RequestRec req;
if ( !char_width )
char_width = char_height;
else if ( !char_height )
char_height = char_width;
if ( !horz_resolution )
horz_resolution = vert_resolution;
else if ( !vert_resolution )
vert_resolution = horz_resolution;
if ( char_width < 1 * 64 )
char_width = 1 * 64;
if ( char_height < 1 * 64 )
char_height = 1 * 64;
if ( !horz_resolution )
horz_resolution = vert_resolution = 72;
req.type = FT_SIZE_REQUEST_TYPE_NOMINAL;
req.width = char_width;
req.height = char_height;
req.horiResolution = horz_resolution;
req.vertResolution = vert_resolution;
return FT_Request_Size( face, &req );
}
/* documentation is in freetype.h */
FT_EXPORT_DEF( FT_Error )
FT_Set_Pixel_Sizes( FT_Face face,
FT_UInt pixel_width,
FT_UInt pixel_height )
{
FT_Size_RequestRec req;
if ( pixel_width == 0 )
pixel_width = pixel_height;
else if ( pixel_height == 0 )
pixel_height = pixel_width;
if ( pixel_width < 1 )
pixel_width = 1;
if ( pixel_height < 1 )
pixel_height = 1;
/* use `>=' to avoid potential compiler warning on 16bit platforms */
if ( pixel_width >= 0xFFFFU )
pixel_width = 0xFFFFU;
if ( pixel_height >= 0xFFFFU )
pixel_height = 0xFFFFU;
req.type = FT_SIZE_REQUEST_TYPE_NOMINAL;
req.width = pixel_width << 6;
req.height = pixel_height << 6;
req.horiResolution = 0;
req.vertResolution = 0;
return FT_Request_Size( face, &req );
}
/* documentation is in freetype.h */
FT_EXPORT_DEF( FT_Error )
FT_Get_Kerning( FT_Face face,
FT_UInt left_glyph,
FT_UInt right_glyph,
FT_UInt kern_mode,
FT_Vector *akerning )
{
FT_Error error = FT_Err_Ok;
FT_Driver driver;
if ( !face )
return FT_THROW( Invalid_Face_Handle );
if ( !akerning )
return FT_THROW( Invalid_Argument );
driver = face->driver;
akerning->x = 0;
akerning->y = 0;
if ( driver->clazz->get_kerning )
{
error = driver->clazz->get_kerning( face,
left_glyph,
right_glyph,
akerning );
if ( !error )
{
if ( kern_mode != FT_KERNING_UNSCALED )
{
akerning->x = FT_MulFix( akerning->x, face->size->metrics.x_scale );
akerning->y = FT_MulFix( akerning->y, face->size->metrics.y_scale );
if ( kern_mode != FT_KERNING_UNFITTED )
{
/* we scale down kerning values for small ppem values */
/* to avoid that rounding makes them too big. */
/* `25' has been determined heuristically. */
if ( face->size->metrics.x_ppem < 25 )
akerning->x = FT_MulDiv( akerning->x,
face->size->metrics.x_ppem, 25 );
if ( face->size->metrics.y_ppem < 25 )
akerning->y = FT_MulDiv( akerning->y,
face->size->metrics.y_ppem, 25 );
akerning->x = FT_PIX_ROUND( akerning->x );
akerning->y = FT_PIX_ROUND( akerning->y );
}
}
}
}
return error;
}
/* documentation is in freetype.h */
FT_EXPORT_DEF( FT_Error )
FT_Get_Track_Kerning( FT_Face face,
FT_Fixed point_size,
FT_Int degree,
FT_Fixed* akerning )
{
FT_Service_Kerning service;
FT_Error error = FT_Err_Ok;
if ( !face )
return FT_THROW( Invalid_Face_Handle );
if ( !akerning )
return FT_THROW( Invalid_Argument );
FT_FACE_FIND_SERVICE( face, service, KERNING );
if ( !service )
return FT_THROW( Unimplemented_Feature );
error = service->get_track( face,
point_size,
degree,
akerning );
return error;
}
/* documentation is in freetype.h */
FT_EXPORT_DEF( FT_Error )
FT_Select_Charmap( FT_Face face,
FT_Encoding encoding )
{
FT_CharMap* cur;
FT_CharMap* limit;
if ( !face )
return FT_THROW( Invalid_Face_Handle );
if ( encoding == FT_ENCODING_NONE )
return FT_THROW( Invalid_Argument );
/* FT_ENCODING_UNICODE is special. We try to find the `best' Unicode */
/* charmap available, i.e., one with UCS-4 characters, if possible. */
/* */
/* This is done by find_unicode_charmap() above, to share code. */
if ( encoding == FT_ENCODING_UNICODE )
return find_unicode_charmap( face );
cur = face->charmaps;
if ( !cur )
return FT_THROW( Invalid_CharMap_Handle );
limit = cur + face->num_charmaps;
for ( ; cur < limit; cur++ )
{
if ( cur[0]->encoding == encoding )
{
#ifdef FT_MAX_CHARMAP_CACHEABLE
if ( cur - face->charmaps > FT_MAX_CHARMAP_CACHEABLE )
{
FT_ERROR(( "FT_Select_Charmap: requested charmap is found (%d), "
"but in too late position to cache\n",
cur - face->charmaps ));
continue;
}
#endif
face->charmap = cur[0];
return 0;
}
}
return FT_THROW( Invalid_Argument );
}
/* documentation is in freetype.h */
FT_EXPORT_DEF( FT_Error )
FT_Set_Charmap( FT_Face face,
FT_CharMap charmap )
{
FT_CharMap* cur;
FT_CharMap* limit;
if ( !face )
return FT_THROW( Invalid_Face_Handle );
cur = face->charmaps;
if ( !cur )
return FT_THROW( Invalid_CharMap_Handle );
if ( FT_Get_CMap_Format( charmap ) == 14 )
return FT_THROW( Invalid_Argument );
limit = cur + face->num_charmaps;
for ( ; cur < limit; cur++ )
{
if ( cur[0] == charmap )
{
#ifdef FT_MAX_CHARMAP_CACHEABLE
if ( cur - face->charmaps > FT_MAX_CHARMAP_CACHEABLE )
{
FT_ERROR(( "FT_Set_Charmap: requested charmap is found (%d), "
"but in too late position to cache\n",
cur - face->charmaps ));
continue;
}
#endif
face->charmap = cur[0];
return 0;
}
}
return FT_THROW( Invalid_Argument );
}
/* documentation is in freetype.h */
FT_EXPORT_DEF( FT_Int )
FT_Get_Charmap_Index( FT_CharMap charmap )
{
FT_Int i;
if ( !charmap || !charmap->face )
return -1;
for ( i = 0; i < charmap->face->num_charmaps; i++ )
if ( charmap->face->charmaps[i] == charmap )
break;
FT_ASSERT( i < charmap->face->num_charmaps );
#ifdef FT_MAX_CHARMAP_CACHEABLE
if ( i > FT_MAX_CHARMAP_CACHEABLE )
{
FT_ERROR(( "FT_Get_Charmap_Index: requested charmap is found (%d), "
"but in too late position to cache\n",
i ));
return -i;
}
#endif
return i;
}
static void
ft_cmap_done_internal( FT_CMap cmap )
{
FT_CMap_Class clazz = cmap->clazz;
FT_Face face = cmap->charmap.face;
FT_Memory memory = FT_FACE_MEMORY( face );
if ( clazz->done )
clazz->done( cmap );
FT_FREE( cmap );
}
FT_BASE_DEF( void )
FT_CMap_Done( FT_CMap cmap )
{
if ( cmap )
{
FT_Face face = cmap->charmap.face;
FT_Memory memory = FT_FACE_MEMORY( face );
FT_Error error;
FT_Int i, j;
for ( i = 0; i < face->num_charmaps; i++ )
{
if ( (FT_CMap)face->charmaps[i] == cmap )
{
FT_CharMap last_charmap = face->charmaps[face->num_charmaps - 1];
if ( FT_RENEW_ARRAY( face->charmaps,
face->num_charmaps,
face->num_charmaps - 1 ) )
return;
/* remove it from our list of charmaps */
for ( j = i + 1; j < face->num_charmaps; j++ )
{
if ( j == face->num_charmaps - 1 )
face->charmaps[j - 1] = last_charmap;
else
face->charmaps[j - 1] = face->charmaps[j];
}
face->num_charmaps--;
if ( (FT_CMap)face->charmap == cmap )
face->charmap = NULL;
ft_cmap_done_internal( cmap );
break;
}
}
}
}
FT_BASE_DEF( FT_Error )
FT_CMap_New( FT_CMap_Class clazz,
FT_Pointer init_data,
FT_CharMap charmap,
FT_CMap *acmap )
{
FT_Error error = FT_Err_Ok;
FT_Face face;
FT_Memory memory;
FT_CMap cmap = NULL;
if ( clazz == NULL || charmap == NULL || charmap->face == NULL )
return FT_THROW( Invalid_Argument );
face = charmap->face;
memory = FT_FACE_MEMORY( face );
if ( !FT_ALLOC( cmap, clazz->size ) )
{
cmap->charmap = *charmap;
cmap->clazz = clazz;
if ( clazz->init )
{
error = clazz->init( cmap, init_data );
if ( error )
goto Fail;
}
/* add it to our list of charmaps */
if ( FT_RENEW_ARRAY( face->charmaps,
face->num_charmaps,
face->num_charmaps + 1 ) )
goto Fail;
face->charmaps[face->num_charmaps++] = (FT_CharMap)cmap;
}
Exit:
if ( acmap )
*acmap = cmap;
return error;
Fail:
ft_cmap_done_internal( cmap );
cmap = NULL;
goto Exit;
}
/* documentation is in freetype.h */
FT_EXPORT_DEF( FT_UInt )
FT_Get_Char_Index( FT_Face face,
FT_ULong charcode )
{
FT_UInt result = 0;
if ( face && face->charmap )
{
FT_CMap cmap = FT_CMAP( face->charmap );
if ( charcode > 0xFFFFFFFFUL )
{
FT_TRACE1(( "FT_Get_Char_Index: too large charcode" ));
FT_TRACE1(( " 0x%x is truncated\n", charcode ));
}
result = cmap->clazz->char_index( cmap, (FT_UInt32)charcode );
}
return result;
}
/* documentation is in freetype.h */
FT_EXPORT_DEF( FT_ULong )
FT_Get_First_Char( FT_Face face,
FT_UInt *agindex )
{
FT_ULong result = 0;
FT_UInt gindex = 0;
/* only do something if we have a charmap, and we have glyphs at all */
if ( face && face->charmap && face->num_glyphs )
{
gindex = FT_Get_Char_Index( face, 0 );
if ( gindex == 0 || gindex >= (FT_UInt)face->num_glyphs )
result = FT_Get_Next_Char( face, 0, &gindex );
}
if ( agindex )
*agindex = gindex;
return result;
}
/* documentation is in freetype.h */
FT_EXPORT_DEF( FT_ULong )
FT_Get_Next_Char( FT_Face face,
FT_ULong charcode,
FT_UInt *agindex )
{
FT_ULong result = 0;
FT_UInt gindex = 0;
if ( face && face->charmap && face->num_glyphs )
{
FT_UInt32 code = (FT_UInt32)charcode;
FT_CMap cmap = FT_CMAP( face->charmap );
do
{
gindex = cmap->clazz->char_next( cmap, &code );
} while ( gindex >= (FT_UInt)face->num_glyphs );
result = ( gindex == 0 ) ? 0 : code;
}
if ( agindex )
*agindex = gindex;
return result;
}
/* documentation is in freetype.h */
FT_EXPORT_DEF( FT_UInt )
FT_Face_GetCharVariantIndex( FT_Face face,
FT_ULong charcode,
FT_ULong variantSelector )
{
FT_UInt result = 0;
if ( face && face->charmap &&
face->charmap->encoding == FT_ENCODING_UNICODE )
{
FT_CharMap charmap = find_variant_selector_charmap( face );
FT_CMap ucmap = FT_CMAP( face->charmap );
if ( charmap != NULL )
{
FT_CMap vcmap = FT_CMAP( charmap );
if ( charcode > 0xFFFFFFFFUL )
{
FT_TRACE1(( "FT_Get_Char_Index: too large charcode" ));
FT_TRACE1(( " 0x%x is truncated\n", charcode ));
}
if ( variantSelector > 0xFFFFFFFFUL )
{
FT_TRACE1(( "FT_Get_Char_Index: too large variantSelector" ));
FT_TRACE1(( " 0x%x is truncated\n", variantSelector ));
}
result = vcmap->clazz->char_var_index( vcmap, ucmap,
(FT_UInt32)charcode,
(FT_UInt32)variantSelector );
}
}
return result;
}
/* documentation is in freetype.h */
FT_EXPORT_DEF( FT_Int )
FT_Face_GetCharVariantIsDefault( FT_Face face,
FT_ULong charcode,
FT_ULong variantSelector )
{
FT_Int result = -1;
if ( face )
{
FT_CharMap charmap = find_variant_selector_charmap( face );
if ( charmap != NULL )
{
FT_CMap vcmap = FT_CMAP( charmap );
if ( charcode > 0xFFFFFFFFUL )
{
FT_TRACE1(( "FT_Get_Char_Index: too large charcode" ));
FT_TRACE1(( " 0x%x is truncated\n", charcode ));
}
if ( variantSelector > 0xFFFFFFFFUL )
{
FT_TRACE1(( "FT_Get_Char_Index: too large variantSelector" ));
FT_TRACE1(( " 0x%x is truncated\n", variantSelector ));
}
result = vcmap->clazz->char_var_default( vcmap,
(FT_UInt32)charcode,
(FT_UInt32)variantSelector );
}
}
return result;
}
/* documentation is in freetype.h */
FT_EXPORT_DEF( FT_UInt32* )
FT_Face_GetVariantSelectors( FT_Face face )
{
FT_UInt32 *result = NULL;
if ( face )
{
FT_CharMap charmap = find_variant_selector_charmap( face );
if ( charmap != NULL )
{
FT_CMap vcmap = FT_CMAP( charmap );
FT_Memory memory = FT_FACE_MEMORY( face );
result = vcmap->clazz->variant_list( vcmap, memory );
}
}
return result;
}
/* documentation is in freetype.h */
FT_EXPORT_DEF( FT_UInt32* )
FT_Face_GetVariantsOfChar( FT_Face face,
FT_ULong charcode )
{
FT_UInt32 *result = NULL;
if ( face )
{
FT_CharMap charmap = find_variant_selector_charmap( face );
if ( charmap != NULL )
{
FT_CMap vcmap = FT_CMAP( charmap );
FT_Memory memory = FT_FACE_MEMORY( face );
if ( charcode > 0xFFFFFFFFUL )
{
FT_TRACE1(( "FT_Get_Char_Index: too large charcode" ));
FT_TRACE1(( " 0x%x is truncated\n", charcode ));
}
result = vcmap->clazz->charvariant_list( vcmap, memory,
(FT_UInt32)charcode );
}
}
return result;
}
/* documentation is in freetype.h */
FT_EXPORT_DEF( FT_UInt32* )
FT_Face_GetCharsOfVariant( FT_Face face,
FT_ULong variantSelector )
{
FT_UInt32 *result = NULL;
if ( face )
{
FT_CharMap charmap = find_variant_selector_charmap( face );
if ( charmap != NULL )
{
FT_CMap vcmap = FT_CMAP( charmap );
FT_Memory memory = FT_FACE_MEMORY( face );
if ( variantSelector > 0xFFFFFFFFUL )
{
FT_TRACE1(( "FT_Get_Char_Index: too large variantSelector" ));
FT_TRACE1(( " 0x%x is truncated\n", variantSelector ));
}
result = vcmap->clazz->variantchar_list( vcmap, memory,
(FT_UInt32)variantSelector );
}
}
return result;
}
/* documentation is in freetype.h */
FT_EXPORT_DEF( FT_UInt )
FT_Get_Name_Index( FT_Face face,
FT_String* glyph_name )
{
FT_UInt result = 0;
if ( face && FT_HAS_GLYPH_NAMES( face ) )
{
FT_Service_GlyphDict service;
FT_FACE_LOOKUP_SERVICE( face,
service,
GLYPH_DICT );
if ( service && service->name_index )
result = service->name_index( face, glyph_name );
}
return result;
}
/* documentation is in freetype.h */
FT_EXPORT_DEF( FT_Error )
FT_Get_Glyph_Name( FT_Face face,
FT_UInt glyph_index,
FT_Pointer buffer,
FT_UInt buffer_max )
{
FT_Error error = FT_ERR( Invalid_Argument );
/* clean up buffer */
if ( buffer && buffer_max > 0 )
((FT_Byte*)buffer)[0] = 0;
if ( face &&
(FT_Long)glyph_index <= face->num_glyphs &&
FT_HAS_GLYPH_NAMES( face ) )
{
FT_Service_GlyphDict service;
FT_FACE_LOOKUP_SERVICE( face,
service,
GLYPH_DICT );
if ( service && service->get_name )
error = service->get_name( face, glyph_index, buffer, buffer_max );
}
return error;
}
/* documentation is in freetype.h */
FT_EXPORT_DEF( const char* )
FT_Get_Postscript_Name( FT_Face face )
{
const char* result = NULL;
if ( !face )
goto Exit;
if ( !result )
{
FT_Service_PsFontName service;
FT_FACE_LOOKUP_SERVICE( face,
service,
POSTSCRIPT_FONT_NAME );
if ( service && service->get_ps_font_name )
result = service->get_ps_font_name( face );
}
Exit:
return result;
}
/* documentation is in tttables.h */
FT_EXPORT_DEF( void* )
FT_Get_Sfnt_Table( FT_Face face,
FT_Sfnt_Tag tag )
{
void* table = 0;
FT_Service_SFNT_Table service;
if ( face && FT_IS_SFNT( face ) )
{
FT_FACE_FIND_SERVICE( face, service, SFNT_TABLE );
if ( service != NULL )
table = service->get_table( face, tag );
}
return table;
}
/* documentation is in tttables.h */
FT_EXPORT_DEF( FT_Error )
FT_Load_Sfnt_Table( FT_Face face,
FT_ULong tag,
FT_Long offset,
FT_Byte* buffer,
FT_ULong* length )
{
FT_Service_SFNT_Table service;
if ( !face || !FT_IS_SFNT( face ) )
return FT_THROW( Invalid_Face_Handle );
FT_FACE_FIND_SERVICE( face, service, SFNT_TABLE );
if ( service == NULL )
return FT_THROW( Unimplemented_Feature );
return service->load_table( face, tag, offset, buffer, length );
}
/* documentation is in tttables.h */
FT_EXPORT_DEF( FT_Error )
FT_Sfnt_Table_Info( FT_Face face,
FT_UInt table_index,
FT_ULong *tag,
FT_ULong *length )
{
FT_Service_SFNT_Table service;
FT_ULong offset;
if ( !face || !FT_IS_SFNT( face ) )
return FT_THROW( Invalid_Face_Handle );
FT_FACE_FIND_SERVICE( face, service, SFNT_TABLE );
if ( service == NULL )
return FT_THROW( Unimplemented_Feature );
return service->table_info( face, table_index, tag, &offset, length );
}
/* documentation is in tttables.h */
FT_EXPORT_DEF( FT_ULong )
FT_Get_CMap_Language_ID( FT_CharMap charmap )
{
FT_Service_TTCMaps service;
FT_Face face;
TT_CMapInfo cmap_info;
if ( !charmap || !charmap->face )
return 0;
face = charmap->face;
FT_FACE_FIND_SERVICE( face, service, TT_CMAP );
if ( service == NULL )
return 0;
if ( service->get_cmap_info( charmap, &cmap_info ))
return 0;
return cmap_info.language;
}
/* documentation is in tttables.h */
FT_EXPORT_DEF( FT_Long )
FT_Get_CMap_Format( FT_CharMap charmap )
{
FT_Service_TTCMaps service;
FT_Face face;
TT_CMapInfo cmap_info;
if ( !charmap || !charmap->face )
return -1;
face = charmap->face;
FT_FACE_FIND_SERVICE( face, service, TT_CMAP );
if ( service == NULL )
return -1;
if ( service->get_cmap_info( charmap, &cmap_info ))
return -1;
return cmap_info.format;
}
/* documentation is in ftsizes.h */
FT_EXPORT_DEF( FT_Error )
FT_Activate_Size( FT_Size size )
{
FT_Face face;
if ( size == NULL )
return FT_THROW( Invalid_Argument );
face = size->face;
if ( face == NULL || face->driver == NULL )
return FT_THROW( Invalid_Argument );
/* we don't need anything more complex than that; all size objects */
/* are already listed by the face */
face->size = size;
return FT_Err_Ok;
}
/*************************************************************************/
/*************************************************************************/
/*************************************************************************/
/**** ****/
/**** ****/
/**** R E N D E R E R S ****/
/**** ****/
/**** ****/
/*************************************************************************/
/*************************************************************************/
/*************************************************************************/
/* lookup a renderer by glyph format in the library's list */
FT_BASE_DEF( FT_Renderer )
FT_Lookup_Renderer( FT_Library library,
FT_Glyph_Format format,
FT_ListNode* node )
{
FT_ListNode cur;
FT_Renderer result = 0;
if ( !library )
goto Exit;
cur = library->renderers.head;
if ( node )
{
if ( *node )
cur = (*node)->next;
*node = 0;
}
while ( cur )
{
FT_Renderer renderer = FT_RENDERER( cur->data );
if ( renderer->glyph_format == format )
{
if ( node )
*node = cur;
result = renderer;
break;
}
cur = cur->next;
}
Exit:
return result;
}
static FT_Renderer
ft_lookup_glyph_renderer( FT_GlyphSlot slot )
{
FT_Face face = slot->face;
FT_Library library = FT_FACE_LIBRARY( face );
FT_Renderer result = library->cur_renderer;
if ( !result || result->glyph_format != slot->format )
result = FT_Lookup_Renderer( library, slot->format, 0 );
return result;
}
static void
ft_set_current_renderer( FT_Library library )
{
FT_Renderer renderer;
renderer = FT_Lookup_Renderer( library, FT_GLYPH_FORMAT_OUTLINE, 0 );
library->cur_renderer = renderer;
}
static FT_Error
ft_add_renderer( FT_Module module )
{
FT_Library library = module->library;
FT_Memory memory = library->memory;
FT_Error error = FT_Err_Ok;
FT_ListNode node = NULL;
if ( FT_NEW( node ) )
goto Exit;
{
FT_Renderer render = FT_RENDERER( module );
FT_Renderer_Class* clazz = (FT_Renderer_Class*)module->clazz;
render->clazz = clazz;
render->glyph_format = clazz->glyph_format;
/* allocate raster object if needed */
if ( clazz->glyph_format == FT_GLYPH_FORMAT_OUTLINE &&
clazz->raster_class->raster_new )
{
error = clazz->raster_class->raster_new( memory, &render->raster );
if ( error )
goto Fail;
render->raster_render = clazz->raster_class->raster_render;
render->render = clazz->render_glyph;
}
/* add to list */
node->data = module;
FT_List_Add( &library->renderers, node );
ft_set_current_renderer( library );
}
Fail:
if ( error )
FT_FREE( node );
Exit:
return error;
}
static void
ft_remove_renderer( FT_Module module )
{
FT_Library library;
FT_Memory memory;
FT_ListNode node;
library = module->library;
if ( !library )
return;
memory = library->memory;
node = FT_List_Find( &library->renderers, module );
if ( node )
{
FT_Renderer render = FT_RENDERER( module );
/* release raster object, if any */
if ( render->clazz->glyph_format == FT_GLYPH_FORMAT_OUTLINE &&
render->raster )
render->clazz->raster_class->raster_done( render->raster );
/* remove from list */
FT_List_Remove( &library->renderers, node );
FT_FREE( node );
ft_set_current_renderer( library );
}
}
/* documentation is in ftrender.h */
FT_EXPORT_DEF( FT_Renderer )
FT_Get_Renderer( FT_Library library,
FT_Glyph_Format format )
{
/* test for valid `library' delayed to FT_Lookup_Renderer() */
return FT_Lookup_Renderer( library, format, 0 );
}
/* documentation is in ftrender.h */
FT_EXPORT_DEF( FT_Error )
FT_Set_Renderer( FT_Library library,
FT_Renderer renderer,
FT_UInt num_params,
FT_Parameter* parameters )
{
FT_ListNode node;
FT_Error error = FT_Err_Ok;
if ( !library )
return FT_THROW( Invalid_Library_Handle );
if ( !renderer )
return FT_THROW( Invalid_Argument );
node = FT_List_Find( &library->renderers, renderer );
if ( !node )
{
error = FT_THROW( Invalid_Argument );
goto Exit;
}
FT_List_Up( &library->renderers, node );
if ( renderer->glyph_format == FT_GLYPH_FORMAT_OUTLINE )
library->cur_renderer = renderer;
if ( num_params > 0 )
{
FT_Renderer_SetModeFunc set_mode = renderer->clazz->set_mode;
for ( ; num_params > 0; num_params-- )
{
error = set_mode( renderer, parameters->tag, parameters->data );
if ( error )
break;
parameters++;
}
}
Exit:
return error;
}
FT_BASE_DEF( FT_Error )
FT_Render_Glyph_Internal( FT_Library library,
FT_GlyphSlot slot,
FT_Render_Mode render_mode )
{
FT_Error error = FT_Err_Ok;
FT_Renderer renderer;
/* if it is already a bitmap, no need to do anything */
switch ( slot->format )
{
case FT_GLYPH_FORMAT_BITMAP: /* already a bitmap, don't do anything */
break;
default:
{
FT_ListNode node = 0;
FT_Bool update = 0;
/* small shortcut for the very common case */
if ( slot->format == FT_GLYPH_FORMAT_OUTLINE )
{
renderer = library->cur_renderer;
node = library->renderers.head;
}
else
renderer = FT_Lookup_Renderer( library, slot->format, &node );
error = FT_ERR( Unimplemented_Feature );
while ( renderer )
{
error = renderer->render( renderer, slot, render_mode, NULL );
if ( !error ||
FT_ERR_NEQ( error, Cannot_Render_Glyph ) )
break;
/* FT_Err_Cannot_Render_Glyph is returned if the render mode */
/* is unsupported by the current renderer for this glyph image */
/* format. */
/* now, look for another renderer that supports the same */
/* format. */
renderer = FT_Lookup_Renderer( library, slot->format, &node );
update = 1;
}
/* if we changed the current renderer for the glyph image format */
/* we need to select it as the next current one */
if ( !error && update && renderer )
FT_Set_Renderer( library, renderer, 0, 0 );
}
}
#ifdef FT_DEBUG_LEVEL_TRACE
#undef FT_COMPONENT
#define FT_COMPONENT trace_bitmap
/* we convert to a single bitmap format for computing the checksum */
{
FT_Bitmap bitmap;
FT_Error err;
FT_Bitmap_New( &bitmap );
err = FT_Bitmap_Convert( library, &slot->bitmap, &bitmap, 1 );
if ( !err )
{
MD5_CTX ctx;
unsigned char md5[16];
int i;
MD5_Init( &ctx);
MD5_Update( &ctx, bitmap.buffer, bitmap.rows * bitmap.pitch );
MD5_Final( md5, &ctx );
FT_TRACE3(( "MD5 checksum for %dx%d bitmap:\n"
" ",
bitmap.rows, bitmap.pitch ));
for ( i = 0; i < 16; i++ )
FT_TRACE3(( "%02X", md5[i] ));
FT_TRACE3(( "\n" ));
}
FT_Bitmap_Done( library, &bitmap );
}
#undef FT_COMPONENT
#define FT_COMPONENT trace_objs
#endif /* FT_DEBUG_LEVEL_TRACE */
return error;
}
/* documentation is in freetype.h */
FT_EXPORT_DEF( FT_Error )
FT_Render_Glyph( FT_GlyphSlot slot,
FT_Render_Mode render_mode )
{
FT_Library library;
if ( !slot || !slot->face )
return FT_THROW( Invalid_Argument );
library = FT_FACE_LIBRARY( slot->face );
return FT_Render_Glyph_Internal( library, slot, render_mode );
}
/*************************************************************************/
/*************************************************************************/
/*************************************************************************/
/**** ****/
/**** ****/
/**** M O D U L E S ****/
/**** ****/
/**** ****/
/*************************************************************************/
/*************************************************************************/
/*************************************************************************/
/*************************************************************************/
/* */
/* <Function> */
/* Destroy_Module */
/* */
/* <Description> */
/* Destroys a given module object. For drivers, this also destroys */
/* all child faces. */
/* */
/* <InOut> */
/* module :: A handle to the target driver object. */
/* */
/* <Note> */
/* The driver _must_ be LOCKED! */
/* */
static void
Destroy_Module( FT_Module module )
{
FT_Memory memory = module->memory;
FT_Module_Class* clazz = module->clazz;
FT_Library library = module->library;
if ( library && library->auto_hinter == module )
library->auto_hinter = 0;
/* if the module is a renderer */
if ( FT_MODULE_IS_RENDERER( module ) )
ft_remove_renderer( module );
/* if the module is a font driver, add some steps */
if ( FT_MODULE_IS_DRIVER( module ) )
Destroy_Driver( FT_DRIVER( module ) );
/* finalize the module object */
if ( clazz->module_done )
clazz->module_done( module );
/* discard it */
FT_FREE( module );
}
/* documentation is in ftmodapi.h */
FT_EXPORT_DEF( FT_Error )
FT_Add_Module( FT_Library library,
const FT_Module_Class* clazz )
{
FT_Error error;
FT_Memory memory;
FT_Module module;
FT_UInt nn;
#define FREETYPE_VER_FIXED ( ( (FT_Long)FREETYPE_MAJOR << 16 ) | \
FREETYPE_MINOR )
if ( !library )
return FT_THROW( Invalid_Library_Handle );
if ( !clazz )
return FT_THROW( Invalid_Argument );
/* check freetype version */
if ( clazz->module_requires > FREETYPE_VER_FIXED )
return FT_THROW( Invalid_Version );
/* look for a module with the same name in the library's table */
for ( nn = 0; nn < library->num_modules; nn++ )
{
module = library->modules[nn];
if ( ft_strcmp( module->clazz->module_name, clazz->module_name ) == 0 )
{
/* this installed module has the same name, compare their versions */
if ( clazz->module_version <= module->clazz->module_version )
return FT_THROW( Lower_Module_Version );
/* remove the module from our list, then exit the loop to replace */
/* it by our new version.. */
FT_Remove_Module( library, module );
break;
}
}
memory = library->memory;
error = FT_Err_Ok;
if ( library->num_modules >= FT_MAX_MODULES )
{
error = FT_THROW( Too_Many_Drivers );
goto Exit;
}
/* allocate module object */
if ( FT_ALLOC( module, clazz->module_size ) )
goto Exit;
/* base initialization */
module->library = library;
module->memory = memory;
module->clazz = (FT_Module_Class*)clazz;
/* check whether the module is a renderer - this must be performed */
/* before the normal module initialization */
if ( FT_MODULE_IS_RENDERER( module ) )
{
/* add to the renderers list */
error = ft_add_renderer( module );
if ( error )
goto Fail;
}
/* is the module a auto-hinter? */
if ( FT_MODULE_IS_HINTER( module ) )
library->auto_hinter = module;
/* if the module is a font driver */
if ( FT_MODULE_IS_DRIVER( module ) )
{
/* allocate glyph loader if needed */
FT_Driver driver = FT_DRIVER( module );
driver->clazz = (FT_Driver_Class)module->clazz;
if ( FT_DRIVER_USES_OUTLINES( driver ) )
{
error = FT_GlyphLoader_New( memory, &driver->glyph_loader );
if ( error )
goto Fail;
}
}
if ( clazz->module_init )
{
error = clazz->module_init( module );
if ( error )
goto Fail;
}
/* add module to the library's table */
library->modules[library->num_modules++] = module;
Exit:
return error;
Fail:
if ( FT_MODULE_IS_DRIVER( module ) )
{
FT_Driver driver = FT_DRIVER( module );
if ( FT_DRIVER_USES_OUTLINES( driver ) )
FT_GlyphLoader_Done( driver->glyph_loader );
}
if ( FT_MODULE_IS_RENDERER( module ) )
{
FT_Renderer renderer = FT_RENDERER( module );
if ( renderer->clazz &&
renderer->clazz->glyph_format == FT_GLYPH_FORMAT_OUTLINE &&
renderer->raster )
renderer->clazz->raster_class->raster_done( renderer->raster );
}
FT_FREE( module );
goto Exit;
}
/* documentation is in ftmodapi.h */
FT_EXPORT_DEF( FT_Module )
FT_Get_Module( FT_Library library,
const char* module_name )
{
FT_Module result = 0;
FT_Module* cur;
FT_Module* limit;
if ( !library || !module_name )
return result;
cur = library->modules;
limit = cur + library->num_modules;
for ( ; cur < limit; cur++ )
if ( ft_strcmp( cur[0]->clazz->module_name, module_name ) == 0 )
{
result = cur[0];
break;
}
return result;
}
/* documentation is in ftobjs.h */
FT_BASE_DEF( const void* )
FT_Get_Module_Interface( FT_Library library,
const char* mod_name )
{
FT_Module module;
/* test for valid `library' delayed to FT_Get_Module() */
module = FT_Get_Module( library, mod_name );
return module ? module->clazz->module_interface : 0;
}
FT_BASE_DEF( FT_Pointer )
ft_module_get_service( FT_Module module,
const char* service_id )
{
FT_Pointer result = NULL;
if ( module )
{
FT_ASSERT( module->clazz && module->clazz->get_interface );
/* first, look for the service in the module */
if ( module->clazz->get_interface )
result = module->clazz->get_interface( module, service_id );
if ( result == NULL )
{
/* we didn't find it, look in all other modules then */
FT_Library library = module->library;
FT_Module* cur = library->modules;
FT_Module* limit = cur + library->num_modules;
for ( ; cur < limit; cur++ )
{
if ( cur[0] != module )
{
FT_ASSERT( cur[0]->clazz );
if ( cur[0]->clazz->get_interface )
{
result = cur[0]->clazz->get_interface( cur[0], service_id );
if ( result != NULL )
break;
}
}
}
}
}
return result;
}
/* documentation is in ftmodapi.h */
FT_EXPORT_DEF( FT_Error )
FT_Remove_Module( FT_Library library,
FT_Module module )
{
/* try to find the module from the table, then remove it from there */
if ( !library )
return FT_THROW( Invalid_Library_Handle );
if ( module )
{
FT_Module* cur = library->modules;
FT_Module* limit = cur + library->num_modules;
for ( ; cur < limit; cur++ )
{
if ( cur[0] == module )
{
/* remove it from the table */
library->num_modules--;
limit--;
while ( cur < limit )
{
cur[0] = cur[1];
cur++;
}
limit[0] = 0;
/* destroy the module */
Destroy_Module( module );
return FT_Err_Ok;
}
}
}
return FT_THROW( Invalid_Driver_Handle );
}
static FT_Error
ft_property_do( FT_Library library,
const FT_String* module_name,
const FT_String* property_name,
void* value,
FT_Bool set )
{
FT_Module* cur;
FT_Module* limit;
FT_Module_Interface interface;
FT_Service_Properties service;
#ifdef FT_DEBUG_LEVEL_ERROR
const FT_String* set_name = "FT_Property_Set";
const FT_String* get_name = "FT_Property_Get";
const FT_String* func_name = set ? set_name : get_name;
#endif
FT_Bool missing_func;
if ( !library )
return FT_THROW( Invalid_Library_Handle );
if ( !module_name || !property_name || !value )
return FT_THROW( Invalid_Argument );
cur = library->modules;
limit = cur + library->num_modules;
/* search module */
for ( ; cur < limit; cur++ )
if ( !ft_strcmp( cur[0]->clazz->module_name, module_name ) )
break;
if ( cur == limit )
{
FT_ERROR(( "%s: can't find module `%s'\n",
func_name, module_name ));
return FT_THROW( Missing_Module );
}
/* check whether we have a service interface */
if ( !cur[0]->clazz->get_interface )
{
FT_ERROR(( "%s: module `%s' doesn't support properties\n",
func_name, module_name ));
return FT_THROW( Unimplemented_Feature );
}
/* search property service */
interface = cur[0]->clazz->get_interface( cur[0],
FT_SERVICE_ID_PROPERTIES );
if ( !interface )
{
FT_ERROR(( "%s: module `%s' doesn't support properties\n",
func_name, module_name ));
return FT_THROW( Unimplemented_Feature );
}
service = (FT_Service_Properties)interface;
if ( set )
missing_func = (FT_Bool)( !service->set_property );
else
missing_func = (FT_Bool)( !service->get_property );
if ( missing_func )
{
FT_ERROR(( "%s: property service of module `%s' is broken\n",
func_name, module_name ));
return FT_THROW( Unimplemented_Feature );
}
return set ? service->set_property( cur[0], property_name, value )
: service->get_property( cur[0], property_name, value );
}
/* documentation is in ftmodapi.h */
FT_EXPORT_DEF( FT_Error )
FT_Property_Set( FT_Library library,
const FT_String* module_name,
const FT_String* property_name,
const void* value )
{
return ft_property_do( library,
module_name,
property_name,
(void*)value,
TRUE );
}
/* documentation is in ftmodapi.h */
FT_EXPORT_DEF( FT_Error )
FT_Property_Get( FT_Library library,
const FT_String* module_name,
const FT_String* property_name,
void* value )
{
return ft_property_do( library,
module_name,
property_name,
value,
FALSE );
}
/*************************************************************************/
/*************************************************************************/
/*************************************************************************/
/**** ****/
/**** ****/
/**** L I B R A R Y ****/
/**** ****/
/**** ****/
/*************************************************************************/
/*************************************************************************/
/*************************************************************************/
/* documentation is in ftmodapi.h */
FT_EXPORT_DEF( FT_Error )
FT_Reference_Library( FT_Library library )
{
library->refcount++;
return FT_Err_Ok;
}
/* documentation is in ftmodapi.h */
FT_EXPORT_DEF( FT_Error )
FT_New_Library( FT_Memory memory,
FT_Library *alibrary )
{
FT_Library library = NULL;
FT_Error error = FT_Err_Ok;
if ( !memory )
return FT_THROW( Invalid_Argument );
#ifdef FT_DEBUG_LEVEL_ERROR
/* init debugging support */
ft_debug_init();
#endif
/* first of all, allocate the library object */
if ( FT_NEW( library ) )
return error;
library->memory = memory;
#ifdef FT_CONFIG_OPTION_PIC
/* initialize position independent code containers */
error = ft_pic_container_init( library );
if ( error )
goto Fail;
#endif
/* allocate the render pool */
library->raster_pool_size = FT_RENDER_POOL_SIZE;
#if FT_RENDER_POOL_SIZE > 0
if ( FT_ALLOC( library->raster_pool, FT_RENDER_POOL_SIZE ) )
goto Fail;
#endif
library->version_major = FREETYPE_MAJOR;
library->version_minor = FREETYPE_MINOR;
library->version_patch = FREETYPE_PATCH;
library->refcount = 1;
/* That's ok now */
*alibrary = library;
return FT_Err_Ok;
Fail:
#ifdef FT_CONFIG_OPTION_PIC
ft_pic_container_destroy( library );
#endif
FT_FREE( library );
return error;
}
/* documentation is in freetype.h */
FT_EXPORT_DEF( void )
FT_Library_Version( FT_Library library,
FT_Int *amajor,
FT_Int *aminor,
FT_Int *apatch )
{
FT_Int major = 0;
FT_Int minor = 0;
FT_Int patch = 0;
if ( library )
{
major = library->version_major;
minor = library->version_minor;
patch = library->version_patch;
}
if ( amajor )
*amajor = major;
if ( aminor )
*aminor = minor;
if ( apatch )
*apatch = patch;
}
/* documentation is in ftmodapi.h */
FT_EXPORT_DEF( FT_Error )
FT_Done_Library( FT_Library library )
{
FT_Memory memory;
if ( !library )
return FT_THROW( Invalid_Library_Handle );
library->refcount--;
if ( library->refcount > 0 )
goto Exit;
memory = library->memory;
/*
* Close all faces in the library. If we don't do this, we can have
* some subtle memory leaks.
*
* Example:
*
* - the cff font driver uses the pshinter module in cff_size_done
* - if the pshinter module is destroyed before the cff font driver,
* opened FT_Face objects managed by the driver are not properly
* destroyed, resulting in a memory leak
*
* Some faces are dependent on other faces, like Type42 faces that
* depend on TrueType faces synthesized internally.
*
* The order of drivers should be specified in driver_name[].
*/
{
FT_UInt m, n;
const char* driver_name[] = { "type42", NULL };
for ( m = 0;
m < sizeof ( driver_name ) / sizeof ( driver_name[0] );
m++ )
{
for ( n = 0; n < library->num_modules; n++ )
{
FT_Module module = library->modules[n];
const char* module_name = module->clazz->module_name;
FT_List faces;
if ( driver_name[m] &&
ft_strcmp( module_name, driver_name[m] ) != 0 )
continue;
if ( ( module->clazz->module_flags & FT_MODULE_FONT_DRIVER ) == 0 )
continue;
FT_TRACE7(( "FT_Done_Library: close faces for %s\n", module_name ));
faces = &FT_DRIVER( module )->faces_list;
while ( faces->head )
{
FT_Done_Face( FT_FACE( faces->head->data ) );
if ( faces->head )
FT_TRACE0(( "FT_Done_Library: failed to free some faces\n" ));
}
}
}
}
/* Close all other modules in the library */
#if 1
/* XXX Modules are removed in the reversed order so that */
/* type42 module is removed before truetype module. This */
/* avoids double free in some occasions. It is a hack. */
while ( library->num_modules > 0 )
FT_Remove_Module( library,
library->modules[library->num_modules - 1] );
#else
{
FT_UInt n;
for ( n = 0; n < library->num_modules; n++ )
{
FT_Module module = library->modules[n];
if ( module )
{
Destroy_Module( module );
library->modules[n] = 0;
}
}
}
#endif
/* Destroy raster objects */
FT_FREE( library->raster_pool );
library->raster_pool_size = 0;
#ifdef FT_CONFIG_OPTION_PIC
/* Destroy pic container contents */
ft_pic_container_destroy( library );
#endif
FT_FREE( library );
Exit:
return FT_Err_Ok;
}
/* documentation is in ftmodapi.h */
FT_EXPORT_DEF( void )
FT_Set_Debug_Hook( FT_Library library,
FT_UInt hook_index,
FT_DebugHook_Func debug_hook )
{
if ( library && debug_hook &&
hook_index <
( sizeof ( library->debug_hooks ) / sizeof ( void* ) ) )
library->debug_hooks[hook_index] = debug_hook;
}
/* documentation is in ftmodapi.h */
FT_EXPORT_DEF( FT_TrueTypeEngineType )
FT_Get_TrueType_Engine_Type( FT_Library library )
{
FT_TrueTypeEngineType result = FT_TRUETYPE_ENGINE_TYPE_NONE;
if ( library )
{
FT_Module module = FT_Get_Module( library, "truetype" );
if ( module )
{
FT_Service_TrueTypeEngine service;
service = (FT_Service_TrueTypeEngine)
ft_module_get_service( module,
FT_SERVICE_ID_TRUETYPE_ENGINE );
if ( service )
result = service->engine_type;
}
}
return result;
}
/* documentation is in freetype.h */
FT_EXPORT_DEF( FT_Error )
FT_Get_SubGlyph_Info( FT_GlyphSlot glyph,
FT_UInt sub_index,
FT_Int *p_index,
FT_UInt *p_flags,
FT_Int *p_arg1,
FT_Int *p_arg2,
FT_Matrix *p_transform )
{
FT_Error error = FT_ERR( Invalid_Argument );
if ( glyph &&
glyph->subglyphs &&
glyph->format == FT_GLYPH_FORMAT_COMPOSITE &&
sub_index < glyph->num_subglyphs )
{
FT_SubGlyph subg = glyph->subglyphs + sub_index;
*p_index = subg->index;
*p_flags = subg->flags;
*p_arg1 = subg->arg1;
*p_arg2 = subg->arg2;
*p_transform = subg->transform;
}
return error;
}
/* END */
| YifuLiu/AliOS-Things | components/freetype/src/base/ftobjs.c | C | apache-2.0 | 136,333 |
/***************************************************************************/
/* */
/* ftotval.c */
/* */
/* FreeType API for validating OpenType tables (body). */
/* */
/* Copyright 2004, 2006, 2008, 2010, 2013 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. */
/* */
/***************************************************************************/
#include <ft2build.h>
#include FT_INTERNAL_DEBUG_H
#include FT_INTERNAL_OBJECTS_H
#include FT_SERVICE_OPENTYPE_VALIDATE_H
#include FT_OPENTYPE_VALIDATE_H
/* documentation is in ftotval.h */
FT_EXPORT_DEF( FT_Error )
FT_OpenType_Validate( FT_Face face,
FT_UInt validation_flags,
FT_Bytes *BASE_table,
FT_Bytes *GDEF_table,
FT_Bytes *GPOS_table,
FT_Bytes *GSUB_table,
FT_Bytes *JSTF_table )
{
FT_Service_OTvalidate service;
FT_Error error;
if ( !face )
{
error = FT_THROW( Invalid_Face_Handle );
goto Exit;
}
if ( !( BASE_table &&
GDEF_table &&
GPOS_table &&
GSUB_table &&
JSTF_table ) )
{
error = FT_THROW( Invalid_Argument );
goto Exit;
}
FT_FACE_FIND_GLOBAL_SERVICE( face, service, OPENTYPE_VALIDATE );
if ( service )
error = service->validate( face,
validation_flags,
BASE_table,
GDEF_table,
GPOS_table,
GSUB_table,
JSTF_table );
else
error = FT_THROW( Unimplemented_Feature );
Exit:
return error;
}
FT_EXPORT_DEF( void )
FT_OpenType_Free( FT_Face face,
FT_Bytes table )
{
FT_Memory memory;
if ( !face )
return;
memory = FT_FACE_MEMORY( face );
FT_FREE( table );
}
/* END */
| YifuLiu/AliOS-Things | components/freetype/src/base/ftotval.c | C | apache-2.0 | 2,910 |
/***************************************************************************/
/* */
/* ftoutln.c */
/* */
/* FreeType outline management (body). */
/* */
/* Copyright 1996-2008, 2010, 2012-2014 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 <ft2build.h>
#include FT_OUTLINE_H
#include FT_INTERNAL_OBJECTS_H
#include FT_INTERNAL_CALC_H
#include FT_INTERNAL_DEBUG_H
#include FT_TRIGONOMETRY_H
/*************************************************************************/
/* */
/* The macro FT_COMPONENT is used in trace mode. It is an implicit */
/* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */
/* messages during execution. */
/* */
#undef FT_COMPONENT
#define FT_COMPONENT trace_outline
static
const FT_Outline null_outline = { 0, 0, 0, 0, 0, 0 };
/* documentation is in ftoutln.h */
FT_EXPORT_DEF( FT_Error )
FT_Outline_Decompose( FT_Outline* outline,
const FT_Outline_Funcs* func_interface,
void* user )
{
#undef SCALED
#define SCALED( x ) ( ( (x) << shift ) - delta )
FT_Vector v_last;
FT_Vector v_control;
FT_Vector v_start;
FT_Vector* point;
FT_Vector* limit;
char* tags;
FT_Error error;
FT_Int n; /* index of contour in outline */
FT_UInt first; /* index of first point in contour */
FT_Int tag; /* current point's state */
FT_Int shift;
FT_Pos delta;
if ( !outline || !func_interface )
return FT_THROW( Invalid_Argument );
shift = func_interface->shift;
delta = func_interface->delta;
first = 0;
for ( n = 0; n < outline->n_contours; n++ )
{
FT_Int last; /* index of last point in contour */
FT_TRACE5(( "FT_Outline_Decompose: Outline %d\n", n ));
last = outline->contours[n];
if ( last < 0 )
goto Invalid_Outline;
limit = outline->points + last;
v_start = outline->points[first];
v_start.x = SCALED( v_start.x );
v_start.y = SCALED( v_start.y );
v_last = outline->points[last];
v_last.x = SCALED( v_last.x );
v_last.y = SCALED( v_last.y );
v_control = v_start;
point = outline->points + first;
tags = outline->tags + first;
tag = FT_CURVE_TAG( tags[0] );
/* A contour cannot start with a cubic control point! */
if ( tag == FT_CURVE_TAG_CUBIC )
goto Invalid_Outline;
/* check first point to determine origin */
if ( tag == FT_CURVE_TAG_CONIC )
{
/* first point is conic control. Yes, this happens. */
if ( FT_CURVE_TAG( outline->tags[last] ) == FT_CURVE_TAG_ON )
{
/* start at last point if it is on the curve */
v_start = v_last;
limit--;
}
else
{
/* if both first and last points are conic, */
/* start at their middle and record its position */
/* for closure */
v_start.x = ( v_start.x + v_last.x ) / 2;
v_start.y = ( v_start.y + v_last.y ) / 2;
/* v_last = v_start; */
}
point--;
tags--;
}
FT_TRACE5(( " move to (%.2f, %.2f)\n",
v_start.x / 64.0, v_start.y / 64.0 ));
error = func_interface->move_to( &v_start, user );
if ( error )
goto Exit;
while ( point < limit )
{
point++;
tags++;
tag = FT_CURVE_TAG( tags[0] );
switch ( tag )
{
case FT_CURVE_TAG_ON: /* emit a single line_to */
{
FT_Vector vec;
vec.x = SCALED( point->x );
vec.y = SCALED( point->y );
FT_TRACE5(( " line to (%.2f, %.2f)\n",
vec.x / 64.0, vec.y / 64.0 ));
error = func_interface->line_to( &vec, user );
if ( error )
goto Exit;
continue;
}
case FT_CURVE_TAG_CONIC: /* consume conic arcs */
v_control.x = SCALED( point->x );
v_control.y = SCALED( point->y );
Do_Conic:
if ( point < limit )
{
FT_Vector vec;
FT_Vector v_middle;
point++;
tags++;
tag = FT_CURVE_TAG( tags[0] );
vec.x = SCALED( point->x );
vec.y = SCALED( point->y );
if ( tag == FT_CURVE_TAG_ON )
{
FT_TRACE5(( " conic to (%.2f, %.2f)"
" with control (%.2f, %.2f)\n",
vec.x / 64.0, vec.y / 64.0,
v_control.x / 64.0, v_control.y / 64.0 ));
error = func_interface->conic_to( &v_control, &vec, user );
if ( error )
goto Exit;
continue;
}
if ( tag != FT_CURVE_TAG_CONIC )
goto Invalid_Outline;
v_middle.x = ( v_control.x + vec.x ) / 2;
v_middle.y = ( v_control.y + vec.y ) / 2;
FT_TRACE5(( " conic to (%.2f, %.2f)"
" with control (%.2f, %.2f)\n",
v_middle.x / 64.0, v_middle.y / 64.0,
v_control.x / 64.0, v_control.y / 64.0 ));
error = func_interface->conic_to( &v_control, &v_middle, user );
if ( error )
goto Exit;
v_control = vec;
goto Do_Conic;
}
FT_TRACE5(( " conic to (%.2f, %.2f)"
" with control (%.2f, %.2f)\n",
v_start.x / 64.0, v_start.y / 64.0,
v_control.x / 64.0, v_control.y / 64.0 ));
error = func_interface->conic_to( &v_control, &v_start, user );
goto Close;
default: /* FT_CURVE_TAG_CUBIC */
{
FT_Vector vec1, vec2;
if ( point + 1 > limit ||
FT_CURVE_TAG( tags[1] ) != FT_CURVE_TAG_CUBIC )
goto Invalid_Outline;
point += 2;
tags += 2;
vec1.x = SCALED( point[-2].x );
vec1.y = SCALED( point[-2].y );
vec2.x = SCALED( point[-1].x );
vec2.y = SCALED( point[-1].y );
if ( point <= limit )
{
FT_Vector vec;
vec.x = SCALED( point->x );
vec.y = SCALED( point->y );
FT_TRACE5(( " cubic to (%.2f, %.2f)"
" with controls (%.2f, %.2f) and (%.2f, %.2f)\n",
vec.x / 64.0, vec.y / 64.0,
vec1.x / 64.0, vec1.y / 64.0,
vec2.x / 64.0, vec2.y / 64.0 ));
error = func_interface->cubic_to( &vec1, &vec2, &vec, user );
if ( error )
goto Exit;
continue;
}
FT_TRACE5(( " cubic to (%.2f, %.2f)"
" with controls (%.2f, %.2f) and (%.2f, %.2f)\n",
v_start.x / 64.0, v_start.y / 64.0,
vec1.x / 64.0, vec1.y / 64.0,
vec2.x / 64.0, vec2.y / 64.0 ));
error = func_interface->cubic_to( &vec1, &vec2, &v_start, user );
goto Close;
}
}
}
/* close the contour with a line segment */
FT_TRACE5(( " line to (%.2f, %.2f)\n",
v_start.x / 64.0, v_start.y / 64.0 ));
error = func_interface->line_to( &v_start, user );
Close:
if ( error )
goto Exit;
first = last + 1;
}
FT_TRACE5(( "FT_Outline_Decompose: Done\n", n ));
return FT_Err_Ok;
Exit:
FT_TRACE5(( "FT_Outline_Decompose: Error %d\n", error ));
return error;
Invalid_Outline:
return FT_THROW( Invalid_Outline );
}
FT_EXPORT_DEF( FT_Error )
FT_Outline_New_Internal( FT_Memory memory,
FT_UInt numPoints,
FT_Int numContours,
FT_Outline *anoutline )
{
FT_Error error;
if ( !anoutline || !memory )
return FT_THROW( Invalid_Argument );
*anoutline = null_outline;
if ( numContours < 0 ||
(FT_UInt)numContours > numPoints )
return FT_THROW( Invalid_Argument );
if ( numPoints > FT_OUTLINE_POINTS_MAX )
return FT_THROW( Array_Too_Large );
if ( FT_NEW_ARRAY( anoutline->points, numPoints ) ||
FT_NEW_ARRAY( anoutline->tags, numPoints ) ||
FT_NEW_ARRAY( anoutline->contours, numContours ) )
goto Fail;
anoutline->n_points = (FT_UShort)numPoints;
anoutline->n_contours = (FT_Short)numContours;
anoutline->flags |= FT_OUTLINE_OWNER;
return FT_Err_Ok;
Fail:
anoutline->flags |= FT_OUTLINE_OWNER;
FT_Outline_Done_Internal( memory, anoutline );
return error;
}
/* documentation is in ftoutln.h */
FT_EXPORT_DEF( FT_Error )
FT_Outline_New( FT_Library library,
FT_UInt numPoints,
FT_Int numContours,
FT_Outline *anoutline )
{
if ( !library )
return FT_THROW( Invalid_Library_Handle );
return FT_Outline_New_Internal( library->memory, numPoints,
numContours, anoutline );
}
/* documentation is in ftoutln.h */
FT_EXPORT_DEF( FT_Error )
FT_Outline_Check( FT_Outline* outline )
{
if ( outline )
{
FT_Int n_points = outline->n_points;
FT_Int n_contours = outline->n_contours;
FT_Int end0, end;
FT_Int n;
/* empty glyph? */
if ( n_points == 0 && n_contours == 0 )
return 0;
/* check point and contour counts */
if ( n_points <= 0 || n_contours <= 0 )
goto Bad;
end0 = end = -1;
for ( n = 0; n < n_contours; n++ )
{
end = outline->contours[n];
/* note that we don't accept empty contours */
if ( end <= end0 || end >= n_points )
goto Bad;
end0 = end;
}
if ( end != n_points - 1 )
goto Bad;
/* XXX: check the tags array */
return 0;
}
Bad:
return FT_THROW( Invalid_Argument );
}
/* documentation is in ftoutln.h */
FT_EXPORT_DEF( FT_Error )
FT_Outline_Copy( const FT_Outline* source,
FT_Outline *target )
{
FT_Int is_owner;
if ( !source || !target ||
source->n_points != target->n_points ||
source->n_contours != target->n_contours )
return FT_THROW( Invalid_Argument );
if ( source == target )
return FT_Err_Ok;
FT_ARRAY_COPY( target->points, source->points, source->n_points );
FT_ARRAY_COPY( target->tags, source->tags, source->n_points );
FT_ARRAY_COPY( target->contours, source->contours, source->n_contours );
/* copy all flags, except the `FT_OUTLINE_OWNER' one */
is_owner = target->flags & FT_OUTLINE_OWNER;
target->flags = source->flags;
target->flags &= ~FT_OUTLINE_OWNER;
target->flags |= is_owner;
return FT_Err_Ok;
}
FT_EXPORT_DEF( FT_Error )
FT_Outline_Done_Internal( FT_Memory memory,
FT_Outline* outline )
{
if ( memory && outline )
{
if ( outline->flags & FT_OUTLINE_OWNER )
{
FT_FREE( outline->points );
FT_FREE( outline->tags );
FT_FREE( outline->contours );
}
*outline = null_outline;
return FT_Err_Ok;
}
else
return FT_THROW( Invalid_Argument );
}
/* documentation is in ftoutln.h */
FT_EXPORT_DEF( FT_Error )
FT_Outline_Done( FT_Library library,
FT_Outline* outline )
{
/* check for valid `outline' in FT_Outline_Done_Internal() */
if ( !library )
return FT_THROW( Invalid_Library_Handle );
return FT_Outline_Done_Internal( library->memory, outline );
}
/* documentation is in ftoutln.h */
FT_EXPORT_DEF( void )
FT_Outline_Get_CBox( const FT_Outline* outline,
FT_BBox *acbox )
{
FT_Pos xMin, yMin, xMax, yMax;
if ( outline && acbox )
{
if ( outline->n_points == 0 )
{
xMin = 0;
yMin = 0;
xMax = 0;
yMax = 0;
}
else
{
FT_Vector* vec = outline->points;
FT_Vector* limit = vec + outline->n_points;
xMin = xMax = vec->x;
yMin = yMax = vec->y;
vec++;
for ( ; vec < limit; vec++ )
{
FT_Pos x, y;
x = vec->x;
if ( x < xMin ) xMin = x;
if ( x > xMax ) xMax = x;
y = vec->y;
if ( y < yMin ) yMin = y;
if ( y > yMax ) yMax = y;
}
}
acbox->xMin = xMin;
acbox->xMax = xMax;
acbox->yMin = yMin;
acbox->yMax = yMax;
}
}
/* documentation is in ftoutln.h */
FT_EXPORT_DEF( void )
FT_Outline_Translate( const FT_Outline* outline,
FT_Pos xOffset,
FT_Pos yOffset )
{
FT_UShort n;
FT_Vector* vec;
if ( !outline )
return;
vec = outline->points;
for ( n = 0; n < outline->n_points; n++ )
{
vec->x += xOffset;
vec->y += yOffset;
vec++;
}
}
/* documentation is in ftoutln.h */
FT_EXPORT_DEF( void )
FT_Outline_Reverse( FT_Outline* outline )
{
FT_UShort n;
FT_Int first, last;
if ( !outline )
return;
first = 0;
for ( n = 0; n < outline->n_contours; n++ )
{
last = outline->contours[n];
/* reverse point table */
{
FT_Vector* p = outline->points + first;
FT_Vector* q = outline->points + last;
FT_Vector swap;
while ( p < q )
{
swap = *p;
*p = *q;
*q = swap;
p++;
q--;
}
}
/* reverse tags table */
{
char* p = outline->tags + first;
char* q = outline->tags + last;
while ( p < q )
{
char swap;
swap = *p;
*p = *q;
*q = swap;
p++;
q--;
}
}
first = last + 1;
}
outline->flags ^= FT_OUTLINE_REVERSE_FILL;
}
/* documentation is in ftoutln.h */
FT_EXPORT_DEF( FT_Error )
FT_Outline_Render( FT_Library library,
FT_Outline* outline,
FT_Raster_Params* params )
{
FT_Error error;
FT_Bool update = FALSE;
FT_Renderer renderer;
FT_ListNode node;
if ( !library )
return FT_THROW( Invalid_Library_Handle );
if ( !outline || !params )
return FT_THROW( Invalid_Argument );
renderer = library->cur_renderer;
node = library->renderers.head;
params->source = (void*)outline;
error = FT_ERR( Cannot_Render_Glyph );
while ( renderer )
{
error = renderer->raster_render( renderer->raster, params );
if ( !error || FT_ERR_NEQ( error, Cannot_Render_Glyph ) )
break;
/* FT_Err_Cannot_Render_Glyph is returned if the render mode */
/* is unsupported by the current renderer for this glyph image */
/* format */
/* now, look for another renderer that supports the same */
/* format */
renderer = FT_Lookup_Renderer( library, FT_GLYPH_FORMAT_OUTLINE,
&node );
update = TRUE;
}
/* if we changed the current renderer for the glyph image format */
/* we need to select it as the next current one */
if ( !error && update && renderer )
FT_Set_Renderer( library, renderer, 0, 0 );
return error;
}
/* documentation is in ftoutln.h */
FT_EXPORT_DEF( FT_Error )
FT_Outline_Get_Bitmap( FT_Library library,
FT_Outline* outline,
const FT_Bitmap *abitmap )
{
FT_Raster_Params params;
if ( !abitmap )
return FT_THROW( Invalid_Argument );
/* other checks are delayed to FT_Outline_Render() */
params.target = abitmap;
params.flags = 0;
if ( abitmap->pixel_mode == FT_PIXEL_MODE_GRAY ||
abitmap->pixel_mode == FT_PIXEL_MODE_LCD ||
abitmap->pixel_mode == FT_PIXEL_MODE_LCD_V )
params.flags |= FT_RASTER_FLAG_AA;
return FT_Outline_Render( library, outline, ¶ms );
}
/* documentation is in freetype.h */
FT_EXPORT_DEF( void )
FT_Vector_Transform( FT_Vector* vector,
const FT_Matrix* matrix )
{
FT_Pos xz, yz;
if ( !vector || !matrix )
return;
xz = FT_MulFix( vector->x, matrix->xx ) +
FT_MulFix( vector->y, matrix->xy );
yz = FT_MulFix( vector->x, matrix->yx ) +
FT_MulFix( vector->y, matrix->yy );
vector->x = xz;
vector->y = yz;
}
/* documentation is in ftoutln.h */
FT_EXPORT_DEF( void )
FT_Outline_Transform( const FT_Outline* outline,
const FT_Matrix* matrix )
{
FT_Vector* vec;
FT_Vector* limit;
if ( !outline || !matrix )
return;
vec = outline->points;
limit = vec + outline->n_points;
for ( ; vec < limit; vec++ )
FT_Vector_Transform( vec, matrix );
}
#if 0
#define FT_OUTLINE_GET_CONTOUR( outline, c, first, last ) \
do \
{ \
(first) = ( c > 0 ) ? (outline)->points + \
(outline)->contours[c - 1] + 1 \
: (outline)->points; \
(last) = (outline)->points + (outline)->contours[c]; \
} while ( 0 )
/* Is a point in some contour? */
/* */
/* We treat every point of the contour as if it */
/* it were ON. That is, we allow false positives, */
/* but disallow false negatives. (XXX really?) */
static FT_Bool
ft_contour_has( FT_Outline* outline,
FT_Short c,
FT_Vector* point )
{
FT_Vector* first;
FT_Vector* last;
FT_Vector* a;
FT_Vector* b;
FT_UInt n = 0;
FT_OUTLINE_GET_CONTOUR( outline, c, first, last );
for ( a = first; a <= last; a++ )
{
FT_Pos x;
FT_Int intersect;
b = ( a == last ) ? first : a + 1;
intersect = ( a->y - point->y ) ^ ( b->y - point->y );
/* a and b are on the same side */
if ( intersect >= 0 )
{
if ( intersect == 0 && a->y == point->y )
{
if ( ( a->x <= point->x && b->x >= point->x ) ||
( a->x >= point->x && b->x <= point->x ) )
return 1;
}
continue;
}
x = a->x + ( b->x - a->x ) * (point->y - a->y ) / ( b->y - a->y );
if ( x < point->x )
n++;
else if ( x == point->x )
return 1;
}
return n & 1;
}
static FT_Bool
ft_contour_enclosed( FT_Outline* outline,
FT_UShort c )
{
FT_Vector* first;
FT_Vector* last;
FT_Short i;
FT_OUTLINE_GET_CONTOUR( outline, c, first, last );
for ( i = 0; i < outline->n_contours; i++ )
{
if ( i != c && ft_contour_has( outline, i, first ) )
{
FT_Vector* pt;
for ( pt = first + 1; pt <= last; pt++ )
if ( !ft_contour_has( outline, i, pt ) )
return 0;
return 1;
}
}
return 0;
}
/* This version differs from the public one in that each */
/* part (contour not enclosed in another contour) of the */
/* outline is checked for orientation. This is */
/* necessary for some buggy CJK fonts. */
static FT_Orientation
ft_outline_get_orientation( FT_Outline* outline )
{
FT_Short i;
FT_Vector* first;
FT_Vector* last;
FT_Orientation orient = FT_ORIENTATION_NONE;
first = outline->points;
for ( i = 0; i < outline->n_contours; i++, first = last + 1 )
{
FT_Vector* point;
FT_Vector* xmin_point;
FT_Pos xmin;
last = outline->points + outline->contours[i];
/* skip degenerate contours */
if ( last < first + 2 )
continue;
if ( ft_contour_enclosed( outline, i ) )
continue;
xmin = first->x;
xmin_point = first;
for ( point = first + 1; point <= last; point++ )
{
if ( point->x < xmin )
{
xmin = point->x;
xmin_point = point;
}
}
/* check the orientation of the contour */
{
FT_Vector* prev;
FT_Vector* next;
FT_Orientation o;
prev = ( xmin_point == first ) ? last : xmin_point - 1;
next = ( xmin_point == last ) ? first : xmin_point + 1;
if ( FT_Atan2( prev->x - xmin_point->x, prev->y - xmin_point->y ) >
FT_Atan2( next->x - xmin_point->x, next->y - xmin_point->y ) )
o = FT_ORIENTATION_POSTSCRIPT;
else
o = FT_ORIENTATION_TRUETYPE;
if ( orient == FT_ORIENTATION_NONE )
orient = o;
else if ( orient != o )
return FT_ORIENTATION_NONE;
}
}
return orient;
}
#endif /* 0 */
/* documentation is in ftoutln.h */
FT_EXPORT_DEF( FT_Error )
FT_Outline_Embolden( FT_Outline* outline,
FT_Pos strength )
{
return FT_Outline_EmboldenXY( outline, strength, strength );
}
/* documentation is in ftoutln.h */
FT_EXPORT_DEF( FT_Error )
FT_Outline_EmboldenXY( FT_Outline* outline,
FT_Pos xstrength,
FT_Pos ystrength )
{
FT_Vector* points;
FT_Vector v_prev, v_first, v_next, v_cur;
FT_Int c, n, first;
FT_Int orientation;
if ( !outline )
return FT_THROW( Invalid_Argument );
xstrength /= 2;
ystrength /= 2;
if ( xstrength == 0 && ystrength == 0 )
return FT_Err_Ok;
orientation = FT_Outline_Get_Orientation( outline );
if ( orientation == FT_ORIENTATION_NONE )
{
if ( outline->n_contours )
return FT_THROW( Invalid_Argument );
else
return FT_Err_Ok;
}
points = outline->points;
first = 0;
for ( c = 0; c < outline->n_contours; c++ )
{
FT_Vector in, out, shift;
FT_Fixed l_in, l_out, l, q, d;
int last = outline->contours[c];
v_first = points[first];
v_prev = points[last];
v_cur = v_first;
/* compute incoming normalized vector */
in.x = v_cur.x - v_prev.x;
in.y = v_cur.y - v_prev.y;
l_in = FT_Vector_Length( &in );
if ( l_in )
{
in.x = FT_DivFix( in.x, l_in );
in.y = FT_DivFix( in.y, l_in );
}
for ( n = first; n <= last; n++ )
{
if ( n < last )
v_next = points[n + 1];
else
v_next = v_first;
/* compute outgoing normalized vector */
out.x = v_next.x - v_cur.x;
out.y = v_next.y - v_cur.y;
l_out = FT_Vector_Length( &out );
if ( l_out )
{
out.x = FT_DivFix( out.x, l_out );
out.y = FT_DivFix( out.y, l_out );
}
d = FT_MulFix( in.x, out.x ) + FT_MulFix( in.y, out.y );
/* shift only if turn is less than ~160 degrees */
if ( d > -0xF000L )
{
d = d + 0x10000L;
/* shift components are aligned along lateral bisector */
/* and directed according to the outline orientation. */
shift.x = in.y + out.y;
shift.y = in.x + out.x;
if ( orientation == FT_ORIENTATION_TRUETYPE )
shift.x = -shift.x;
else
shift.y = -shift.y;
/* restrict shift magnitude to better handle collapsing segments */
q = FT_MulFix( out.x, in.y ) - FT_MulFix( out.y, in.x );
if ( orientation == FT_ORIENTATION_TRUETYPE )
q = -q;
l = FT_MIN( l_in, l_out );
/* non-strict inequalities avoid divide-by-zero when q == l == 0 */
if ( FT_MulFix( xstrength, q ) <= FT_MulFix( d, l ) )
shift.x = FT_MulDiv( shift.x, xstrength, d );
else
shift.x = FT_MulDiv( shift.x, l, q );
if ( FT_MulFix( ystrength, q ) <= FT_MulFix( d, l ) )
shift.y = FT_MulDiv( shift.y, ystrength, d );
else
shift.y = FT_MulDiv( shift.y, l, q );
}
else
shift.x = shift.y = 0;
outline->points[n].x = v_cur.x + xstrength + shift.x;
outline->points[n].y = v_cur.y + ystrength + shift.y;
in = out;
l_in = l_out;
v_cur = v_next;
}
first = last + 1;
}
return FT_Err_Ok;
}
/* documentation is in ftoutln.h */
FT_EXPORT_DEF( FT_Orientation )
FT_Outline_Get_Orientation( FT_Outline* outline )
{
FT_BBox cbox;
FT_Int xshift, yshift;
FT_Vector* points;
FT_Vector v_prev, v_cur;
FT_Int c, n, first;
FT_Pos area = 0;
if ( !outline || outline->n_points <= 0 )
return FT_ORIENTATION_TRUETYPE;
/* We use the nonzero winding rule to find the orientation. */
/* Since glyph outlines behave much more `regular' than arbitrary */
/* cubic or quadratic curves, this test deals with the polygon */
/* only which is spanned up by the control points. */
FT_Outline_Get_CBox( outline, &cbox );
xshift = FT_MSB( FT_ABS( cbox.xMax ) | FT_ABS( cbox.xMin ) ) - 14;
xshift = FT_MAX( xshift, 0 );
yshift = FT_MSB( cbox.yMax - cbox.yMin ) - 14;
yshift = FT_MAX( yshift, 0 );
points = outline->points;
first = 0;
for ( c = 0; c < outline->n_contours; c++ )
{
FT_Int last = outline->contours[c];
v_prev = points[last];
for ( n = first; n <= last; n++ )
{
v_cur = points[n];
area += ( ( v_cur.y - v_prev.y ) >> yshift ) *
( ( v_cur.x + v_prev.x ) >> xshift );
v_prev = v_cur;
}
first = last + 1;
}
if ( area > 0 )
return FT_ORIENTATION_POSTSCRIPT;
else if ( area < 0 )
return FT_ORIENTATION_TRUETYPE;
else
return FT_ORIENTATION_NONE;
}
/* END */
| YifuLiu/AliOS-Things | components/freetype/src/base/ftoutln.c | C | apache-2.0 | 28,432 |
/***************************************************************************/
/* */
/* ftpatent.c */
/* */
/* FreeType API for checking patented TrueType bytecode instructions */
/* (body). */
/* */
/* Copyright 2007, 2008, 2010 by David Turner. */
/* */
/* 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. */
/* */
/***************************************************************************/
#include <ft2build.h>
#include FT_FREETYPE_H
#include FT_TRUETYPE_TAGS_H
#include FT_INTERNAL_OBJECTS_H
#include FT_INTERNAL_STREAM_H
#include FT_SERVICE_SFNT_H
#include FT_SERVICE_TRUETYPE_GLYF_H
static FT_Bool
_tt_check_patents_in_range( FT_Stream stream,
FT_ULong size )
{
FT_Bool result = FALSE;
FT_Error error;
FT_Bytes p, end;
if ( FT_FRAME_ENTER( size ) )
return 0;
p = stream->cursor;
end = p + size;
while ( p < end )
{
switch (p[0])
{
case 0x06: /* SPvTL // */
case 0x07: /* SPvTL + */
case 0x08: /* SFvTL // */
case 0x09: /* SFvTL + */
case 0x0A: /* SPvFS */
case 0x0B: /* SFvFS */
result = TRUE;
goto Exit;
case 0x40:
if ( p + 1 >= end )
goto Exit;
p += p[1] + 2;
break;
case 0x41:
if ( p + 1 >= end )
goto Exit;
p += p[1] * 2 + 2;
break;
case 0x71: /* DELTAP2 */
case 0x72: /* DELTAP3 */
case 0x73: /* DELTAC0 */
case 0x74: /* DELTAC1 */
case 0x75: /* DELTAC2 */
result = TRUE;
goto Exit;
case 0xB0:
case 0xB1:
case 0xB2:
case 0xB3:
case 0xB4:
case 0xB5:
case 0xB6:
case 0xB7:
p += ( p[0] - 0xB0 ) + 2;
break;
case 0xB8:
case 0xB9:
case 0xBA:
case 0xBB:
case 0xBC:
case 0xBD:
case 0xBE:
case 0xBF:
p += ( p[0] - 0xB8 ) * 2 + 3;
break;
default:
p += 1;
break;
}
}
Exit:
FT_UNUSED( error );
FT_FRAME_EXIT();
return result;
}
static FT_Bool
_tt_check_patents_in_table( FT_Face face,
FT_ULong tag )
{
FT_Stream stream = face->stream;
FT_Error error = FT_Err_Ok;
FT_Service_SFNT_Table service;
FT_Bool result = FALSE;
FT_FACE_FIND_SERVICE( face, service, SFNT_TABLE );
if ( service )
{
FT_UInt i = 0;
FT_ULong tag_i = 0, offset_i = 0, length_i = 0;
for ( i = 0; !error && tag_i != tag ; i++ )
error = service->table_info( face, i,
&tag_i, &offset_i, &length_i );
if ( error ||
FT_STREAM_SEEK( offset_i ) )
goto Exit;
result = _tt_check_patents_in_range( stream, length_i );
}
Exit:
return result;
}
static FT_Bool
_tt_face_check_patents( FT_Face face )
{
FT_Stream stream = face->stream;
FT_UInt gindex;
FT_Error error;
FT_Bool result;
FT_Service_TTGlyf service;
result = _tt_check_patents_in_table( face, TTAG_fpgm );
if ( result )
goto Exit;
result = _tt_check_patents_in_table( face, TTAG_prep );
if ( result )
goto Exit;
FT_FACE_FIND_SERVICE( face, service, TT_GLYF );
if ( service == NULL )
goto Exit;
for ( gindex = 0; gindex < (FT_UInt)face->num_glyphs; gindex++ )
{
FT_ULong offset, num_ins, size;
FT_Int num_contours;
offset = service->get_location( face, gindex, &size );
if ( size == 0 )
continue;
if ( FT_STREAM_SEEK( offset ) ||
FT_READ_SHORT( num_contours ) )
continue;
if ( num_contours >= 0 ) /* simple glyph */
{
if ( FT_STREAM_SKIP( 8 + num_contours * 2 ) )
continue;
}
else /* compound glyph */
{
FT_Bool has_instr = 0;
if ( FT_STREAM_SKIP( 8 ) )
continue;
/* now read each component */
for (;;)
{
FT_UInt flags, toskip;
if( FT_READ_USHORT( flags ) )
break;
toskip = 2 + 1 + 1;
if ( ( flags & ( 1 << 0 ) ) != 0 ) /* ARGS_ARE_WORDS */
toskip += 2;
if ( ( flags & ( 1 << 3 ) ) != 0 ) /* WE_HAVE_A_SCALE */
toskip += 2;
else if ( ( flags & ( 1 << 6 ) ) != 0 ) /* WE_HAVE_X_Y_SCALE */
toskip += 4;
else if ( ( flags & ( 1 << 7 ) ) != 0 ) /* WE_HAVE_A_2x2 */
toskip += 8;
if ( ( flags & ( 1 << 8 ) ) != 0 ) /* WE_HAVE_INSTRUCTIONS */
has_instr = 1;
if ( FT_STREAM_SKIP( toskip ) )
goto NextGlyph;
if ( ( flags & ( 1 << 5 ) ) == 0 ) /* MORE_COMPONENTS */
break;
}
if ( !has_instr )
goto NextGlyph;
}
if ( FT_READ_USHORT( num_ins ) )
continue;
result = _tt_check_patents_in_range( stream, num_ins );
if ( result )
goto Exit;
NextGlyph:
;
}
Exit:
return result;
}
/* documentation is in freetype.h */
FT_EXPORT_DEF( FT_Bool )
FT_Face_CheckTrueTypePatents( FT_Face face )
{
FT_Bool result = FALSE;
if ( face && FT_IS_SFNT( face ) )
result = _tt_face_check_patents( face );
return result;
}
/* documentation is in freetype.h */
FT_EXPORT_DEF( FT_Bool )
FT_Face_SetUnpatentedHinting( FT_Face face,
FT_Bool value )
{
FT_Bool result = FALSE;
#if defined( TT_CONFIG_OPTION_UNPATENTED_HINTING ) && \
!defined( TT_CONFIG_OPTION_BYTECODE_INTERPRETER )
if ( face && FT_IS_SFNT( face ) )
{
result = !face->internal->ignore_unpatented_hinter;
face->internal->ignore_unpatented_hinter = !value;
}
#else
FT_UNUSED( face );
FT_UNUSED( value );
#endif
return result;
}
/* END */
| YifuLiu/AliOS-Things | components/freetype/src/base/ftpatent.c | C | apache-2.0 | 6,890 |
/***************************************************************************/
/* */
/* ftpfr.c */
/* */
/* FreeType API for accessing PFR-specific data (body). */
/* */
/* Copyright 2002-2004, 2008, 2010, 2013 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. */
/* */
/***************************************************************************/
#include <ft2build.h>
#include FT_INTERNAL_DEBUG_H
#include FT_INTERNAL_OBJECTS_H
#include FT_SERVICE_PFR_H
/* check the format */
static FT_Service_PfrMetrics
ft_pfr_check( FT_Face face )
{
FT_Service_PfrMetrics service = NULL;
if ( face )
FT_FACE_LOOKUP_SERVICE( face, service, PFR_METRICS );
return service;
}
/* documentation is in ftpfr.h */
FT_EXPORT_DEF( FT_Error )
FT_Get_PFR_Metrics( FT_Face face,
FT_UInt *aoutline_resolution,
FT_UInt *ametrics_resolution,
FT_Fixed *ametrics_x_scale,
FT_Fixed *ametrics_y_scale )
{
FT_Error error = FT_Err_Ok;
FT_Service_PfrMetrics service;
if ( !face )
return FT_THROW( Invalid_Argument );
service = ft_pfr_check( face );
if ( service )
{
error = service->get_metrics( face,
aoutline_resolution,
ametrics_resolution,
ametrics_x_scale,
ametrics_y_scale );
}
else
{
FT_Fixed x_scale, y_scale;
/* this is not a PFR font */
if ( aoutline_resolution )
*aoutline_resolution = face->units_per_EM;
if ( ametrics_resolution )
*ametrics_resolution = face->units_per_EM;
x_scale = y_scale = 0x10000L;
if ( face->size )
{
x_scale = face->size->metrics.x_scale;
y_scale = face->size->metrics.y_scale;
}
if ( ametrics_x_scale )
*ametrics_x_scale = x_scale;
if ( ametrics_y_scale )
*ametrics_y_scale = y_scale;
error = FT_THROW( Unknown_File_Format );
}
return error;
}
/* documentation is in ftpfr.h */
FT_EXPORT_DEF( FT_Error )
FT_Get_PFR_Kerning( FT_Face face,
FT_UInt left,
FT_UInt right,
FT_Vector *avector )
{
FT_Error error;
FT_Service_PfrMetrics service;
if ( !face )
return FT_THROW( Invalid_Argument );
service = ft_pfr_check( face );
if ( service )
error = service->get_kerning( face, left, right, avector );
else
error = FT_Get_Kerning( face, left, right,
FT_KERNING_UNSCALED, avector );
return error;
}
/* documentation is in ftpfr.h */
FT_EXPORT_DEF( FT_Error )
FT_Get_PFR_Advance( FT_Face face,
FT_UInt gindex,
FT_Pos *aadvance )
{
FT_Error error;
FT_Service_PfrMetrics service;
service = ft_pfr_check( face );
if ( service )
{
error = service->get_advance( face, gindex, aadvance );
}
else
/* XXX: TODO: PROVIDE ADVANCE-LOADING METHOD TO ALL FONT DRIVERS */
error = FT_THROW( Invalid_Argument );
return error;
}
/* END */
| YifuLiu/AliOS-Things | components/freetype/src/base/ftpfr.c | C | apache-2.0 | 4,224 |
/***************************************************************************/
/* */
/* ftpic.c */
/* */
/* The FreeType position independent code services (body). */
/* */
/* Copyright 2009, 2013 by */
/* Oran Agra and Mickey Gabel. */
/* */
/* 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. */
/* */
/***************************************************************************/
#include <ft2build.h>
#include FT_FREETYPE_H
#include FT_INTERNAL_OBJECTS_H
#include "basepic.h"
#ifdef FT_CONFIG_OPTION_PIC
/* documentation is in ftpic.h */
FT_BASE_DEF( FT_Error )
ft_pic_container_init( FT_Library library )
{
FT_PIC_Container* pic_container = &library->pic_container;
FT_Error error;
FT_MEM_SET( pic_container, 0, sizeof ( *pic_container ) );
error = ft_base_pic_init( library );
if ( error )
return error;
return FT_Err_Ok;
}
/* Destroy the contents of the container. */
FT_BASE_DEF( void )
ft_pic_container_destroy( FT_Library library )
{
ft_base_pic_free( library );
}
#endif /* FT_CONFIG_OPTION_PIC */
/* END */
| YifuLiu/AliOS-Things | components/freetype/src/base/ftpic.c | C | apache-2.0 | 1,965 |
/***************************************************************************/
/* */
/* ftrfork.c */
/* */
/* Embedded resource forks accessor (body). */
/* */
/* Copyright 2004-2010, 2013, 2014 by */
/* Masatake YAMATO and Redhat K.K. */
/* */
/* FT_Raccess_Get_HeaderInfo() and raccess_guess_darwin_hfsplus() are */
/* derived from ftobjs.c. */
/* */
/* 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. */
/* */
/***************************************************************************/
/***************************************************************************/
/* Development of the code in this file is support of */
/* Information-technology Promotion Agency, Japan. */
/***************************************************************************/
#include <ft2build.h>
#include FT_INTERNAL_DEBUG_H
#include FT_INTERNAL_STREAM_H
#include FT_INTERNAL_RFORK_H
#include "basepic.h"
#include "ftbase.h"
#undef FT_COMPONENT
#define FT_COMPONENT trace_raccess
/*************************************************************************/
/*************************************************************************/
/*************************************************************************/
/**** ****/
/**** ****/
/**** Resource fork directory access ****/
/**** ****/
/**** ****/
/*************************************************************************/
/*************************************************************************/
/*************************************************************************/
FT_BASE_DEF( FT_Error )
FT_Raccess_Get_HeaderInfo( FT_Library library,
FT_Stream stream,
FT_Long rfork_offset,
FT_Long *map_offset,
FT_Long *rdata_pos )
{
FT_Error error;
unsigned char head[16], head2[16];
FT_Long map_pos, rdata_len;
int allzeros, allmatch, i;
FT_Long type_list;
FT_UNUSED( library );
error = FT_Stream_Seek( stream, rfork_offset );
if ( error )
return error;
error = FT_Stream_Read( stream, (FT_Byte *)head, 16 );
if ( error )
return error;
*rdata_pos = rfork_offset + ( ( head[0] << 24 ) |
( head[1] << 16 ) |
( head[2] << 8 ) |
head[3] );
map_pos = rfork_offset + ( ( head[4] << 24 ) |
( head[5] << 16 ) |
( head[6] << 8 ) |
head[7] );
rdata_len = ( head[ 8] << 24 ) |
( head[ 9] << 16 ) |
( head[10] << 8 ) |
head[11];
/* map_len = head[12] .. head[15] */
if ( *rdata_pos + rdata_len != map_pos || map_pos == rfork_offset )
return FT_THROW( Unknown_File_Format );
error = FT_Stream_Seek( stream, map_pos );
if ( error )
return error;
head2[15] = (FT_Byte)( head[15] + 1 ); /* make it be different */
error = FT_Stream_Read( stream, (FT_Byte*)head2, 16 );
if ( error )
return error;
allzeros = 1;
allmatch = 1;
for ( i = 0; i < 16; ++i )
{
if ( head2[i] != 0 )
allzeros = 0;
if ( head2[i] != head[i] )
allmatch = 0;
}
if ( !allzeros && !allmatch )
return FT_THROW( Unknown_File_Format );
/* If we have reached this point then it is probably a mac resource */
/* file. Now, does it contain any interesting resources? */
/* Skip handle to next resource map, the file resource number, and */
/* attributes. */
(void)FT_STREAM_SKIP( 4 /* skip handle to next resource map */
+ 2 /* skip file resource number */
+ 2 ); /* skip attributes */
if ( FT_READ_USHORT( type_list ) )
return error;
if ( type_list == -1 )
return FT_THROW( Unknown_File_Format );
error = FT_Stream_Seek( stream, map_pos + type_list );
if ( error )
return error;
*map_offset = map_pos + type_list;
return FT_Err_Ok;
}
static int
ft_raccess_sort_ref_by_id( FT_RFork_Ref* a,
FT_RFork_Ref* b )
{
if ( a->res_id < b->res_id )
return -1;
else if ( a->res_id > b->res_id )
return 1;
else
return 0;
}
FT_BASE_DEF( FT_Error )
FT_Raccess_Get_DataOffsets( FT_Library library,
FT_Stream stream,
FT_Long map_offset,
FT_Long rdata_pos,
FT_Long tag,
FT_Bool sort_by_res_id,
FT_Long **offsets,
FT_Long *count )
{
FT_Error error;
int i, j, cnt, subcnt;
FT_Long tag_internal, rpos;
FT_Memory memory = library->memory;
FT_Long temp;
FT_Long *offsets_internal = NULL;
FT_RFork_Ref *ref = NULL;
FT_TRACE3(( "\n" ));
error = FT_Stream_Seek( stream, map_offset );
if ( error )
return error;
if ( FT_READ_USHORT( cnt ) )
return error;
cnt++;
for ( i = 0; i < cnt; ++i )
{
if ( FT_READ_LONG( tag_internal ) ||
FT_READ_USHORT( subcnt ) ||
FT_READ_USHORT( rpos ) )
return error;
FT_TRACE2(( "Resource tags: %c%c%c%c\n",
(char)( 0xff & ( tag_internal >> 24 ) ),
(char)( 0xff & ( tag_internal >> 16 ) ),
(char)( 0xff & ( tag_internal >> 8 ) ),
(char)( 0xff & ( tag_internal >> 0 ) ) ));
FT_TRACE3(( " : subcount=%d, suboffset=0x%04x\n",
subcnt, rpos ));
if ( tag_internal == tag )
{
*count = subcnt + 1;
rpos += map_offset;
error = FT_Stream_Seek( stream, rpos );
if ( error )
return error;
if ( FT_NEW_ARRAY( ref, *count ) )
return error;
for ( j = 0; j < *count; ++j )
{
if ( FT_READ_USHORT( ref[j].res_id ) )
goto Exit;
if ( FT_STREAM_SKIP( 2 ) ) /* resource name */
goto Exit;
if ( FT_READ_LONG( temp ) )
goto Exit;
if ( FT_STREAM_SKIP( 4 ) ) /* mbz */
goto Exit;
ref[j].offset = temp & 0xFFFFFFL;
FT_TRACE3(( " [%d]:"
" resource_id=0x%04x, offset=0x%08x\n",
j, ref[j].res_id, ref[j].offset ));
}
if (sort_by_res_id)
{
ft_qsort( ref, *count, sizeof ( FT_RFork_Ref ),
( int(*)(const void*, const void*) )
ft_raccess_sort_ref_by_id );
FT_TRACE3(( " -- sort resources by their ids --\n" ));
for ( j = 0; j < *count; ++ j ) {
FT_TRACE3(( " [%d]:"
" resource_id=0x%04x, offset=0x%08x\n",
j, ref[j].res_id, ref[j].offset ));
}
}
if ( FT_NEW_ARRAY( offsets_internal, *count ) )
goto Exit;
/* XXX: duplicated reference ID,
* gap between reference IDs are acceptable?
* further investigation on Apple implementation is needed.
*/
for ( j = 0; j < *count; ++j )
offsets_internal[j] = rdata_pos + ref[j].offset;
*offsets = offsets_internal;
error = FT_Err_Ok;
Exit:
FT_FREE( ref );
return error;
}
}
return FT_THROW( Cannot_Open_Resource );
}
#ifdef FT_CONFIG_OPTION_GUESSING_EMBEDDED_RFORK
/*************************************************************************/
/*************************************************************************/
/*************************************************************************/
/**** ****/
/**** ****/
/**** Guessing functions ****/
/**** ****/
/**** When you add a new guessing function, ****/
/**** update FT_RACCESS_N_RULES in ftrfork.h. ****/
/**** ****/
/*************************************************************************/
/*************************************************************************/
/*************************************************************************/
static FT_Error
raccess_guess_apple_double( FT_Library library,
FT_Stream stream,
char *base_file_name,
char **result_file_name,
FT_Long *result_offset );
static FT_Error
raccess_guess_apple_single( FT_Library library,
FT_Stream stream,
char *base_file_name,
char **result_file_name,
FT_Long *result_offset );
static FT_Error
raccess_guess_darwin_ufs_export( FT_Library library,
FT_Stream stream,
char *base_file_name,
char **result_file_name,
FT_Long *result_offset );
static FT_Error
raccess_guess_darwin_newvfs( FT_Library library,
FT_Stream stream,
char *base_file_name,
char **result_file_name,
FT_Long *result_offset );
static FT_Error
raccess_guess_darwin_hfsplus( FT_Library library,
FT_Stream stream,
char *base_file_name,
char **result_file_name,
FT_Long *result_offset );
static FT_Error
raccess_guess_vfat( FT_Library library,
FT_Stream stream,
char *base_file_name,
char **result_file_name,
FT_Long *result_offset );
static FT_Error
raccess_guess_linux_cap( FT_Library library,
FT_Stream stream,
char *base_file_name,
char **result_file_name,
FT_Long *result_offset );
static FT_Error
raccess_guess_linux_double( FT_Library library,
FT_Stream stream,
char *base_file_name,
char **result_file_name,
FT_Long *result_offset );
static FT_Error
raccess_guess_linux_netatalk( FT_Library library,
FT_Stream stream,
char *base_file_name,
char **result_file_name,
FT_Long *result_offset );
CONST_FT_RFORK_RULE_ARRAY_BEGIN(ft_raccess_guess_table,
ft_raccess_guess_rec)
CONST_FT_RFORK_RULE_ARRAY_ENTRY(apple_double, apple_double)
CONST_FT_RFORK_RULE_ARRAY_ENTRY(apple_single, apple_single)
CONST_FT_RFORK_RULE_ARRAY_ENTRY(darwin_ufs_export, darwin_ufs_export)
CONST_FT_RFORK_RULE_ARRAY_ENTRY(darwin_newvfs, darwin_newvfs)
CONST_FT_RFORK_RULE_ARRAY_ENTRY(darwin_hfsplus, darwin_hfsplus)
CONST_FT_RFORK_RULE_ARRAY_ENTRY(vfat, vfat)
CONST_FT_RFORK_RULE_ARRAY_ENTRY(linux_cap, linux_cap)
CONST_FT_RFORK_RULE_ARRAY_ENTRY(linux_double, linux_double)
CONST_FT_RFORK_RULE_ARRAY_ENTRY(linux_netatalk, linux_netatalk)
CONST_FT_RFORK_RULE_ARRAY_END
/*************************************************************************/
/**** ****/
/**** Helper functions ****/
/**** ****/
/*************************************************************************/
static FT_Error
raccess_guess_apple_generic( FT_Library library,
FT_Stream stream,
char *base_file_name,
FT_Int32 magic,
FT_Long *result_offset );
static FT_Error
raccess_guess_linux_double_from_file_name( FT_Library library,
char * file_name,
FT_Long *result_offset );
static char *
raccess_make_file_name( FT_Memory memory,
const char *original_name,
const char *insertion );
FT_BASE_DEF( void )
FT_Raccess_Guess( FT_Library library,
FT_Stream stream,
char* base_name,
char **new_names,
FT_Long *offsets,
FT_Error *errors )
{
FT_Int i;
for ( i = 0; i < FT_RACCESS_N_RULES; i++ )
{
new_names[i] = NULL;
if ( NULL != stream )
errors[i] = FT_Stream_Seek( stream, 0 );
else
errors[i] = FT_Err_Ok;
if ( errors[i] )
continue ;
errors[i] = (FT_RACCESS_GUESS_TABLE_GET[i].func)( library,
stream, base_name,
&(new_names[i]),
&(offsets[i]) );
}
return;
}
#ifndef FT_MACINTOSH
static FT_RFork_Rule
raccess_get_rule_type_from_rule_index( FT_Library library,
FT_UInt rule_index )
{
FT_UNUSED( library );
if ( rule_index >= FT_RACCESS_N_RULES )
return FT_RFork_Rule_invalid;
return FT_RACCESS_GUESS_TABLE_GET[rule_index].type;
}
/*
* For this function, refer ftbase.h.
*/
FT_LOCAL_DEF( FT_Bool )
ft_raccess_rule_by_darwin_vfs( FT_Library library,
FT_UInt rule_index )
{
switch( raccess_get_rule_type_from_rule_index( library, rule_index ) )
{
case FT_RFork_Rule_darwin_newvfs:
case FT_RFork_Rule_darwin_hfsplus:
return TRUE;
default:
return FALSE;
}
}
#endif
static FT_Error
raccess_guess_apple_double( FT_Library library,
FT_Stream stream,
char *base_file_name,
char **result_file_name,
FT_Long *result_offset )
{
FT_Int32 magic = ( 0x00 << 24 ) |
( 0x05 << 16 ) |
( 0x16 << 8 ) |
0x07;
*result_file_name = NULL;
if ( NULL == stream )
return FT_THROW( Cannot_Open_Stream );
return raccess_guess_apple_generic( library, stream, base_file_name,
magic, result_offset );
}
static FT_Error
raccess_guess_apple_single( FT_Library library,
FT_Stream stream,
char *base_file_name,
char **result_file_name,
FT_Long *result_offset )
{
FT_Int32 magic = ( 0x00 << 24 ) |
( 0x05 << 16 ) |
( 0x16 << 8 ) |
0x00;
*result_file_name = NULL;
if ( NULL == stream )
return FT_THROW( Cannot_Open_Stream );
return raccess_guess_apple_generic( library, stream, base_file_name,
magic, result_offset );
}
static FT_Error
raccess_guess_darwin_ufs_export( FT_Library library,
FT_Stream stream,
char *base_file_name,
char **result_file_name,
FT_Long *result_offset )
{
char* newpath;
FT_Error error;
FT_Memory memory;
FT_UNUSED( stream );
memory = library->memory;
newpath = raccess_make_file_name( memory, base_file_name, "._" );
if ( !newpath )
return FT_THROW( Out_Of_Memory );
error = raccess_guess_linux_double_from_file_name( library, newpath,
result_offset );
if ( !error )
*result_file_name = newpath;
else
FT_FREE( newpath );
return error;
}
static FT_Error
raccess_guess_darwin_hfsplus( FT_Library library,
FT_Stream stream,
char *base_file_name,
char **result_file_name,
FT_Long *result_offset )
{
/*
Only meaningful on systems with hfs+ drivers (or Macs).
*/
FT_Error error;
char* newpath = NULL;
FT_Memory memory;
FT_Long base_file_len = (FT_Long)ft_strlen( base_file_name );
FT_UNUSED( stream );
memory = library->memory;
if ( base_file_len + 6 > FT_INT_MAX )
return FT_THROW( Array_Too_Large );
if ( FT_ALLOC( newpath, base_file_len + 6 ) )
return error;
FT_MEM_COPY( newpath, base_file_name, base_file_len );
FT_MEM_COPY( newpath + base_file_len, "/rsrc", 6 );
*result_file_name = newpath;
*result_offset = 0;
return FT_Err_Ok;
}
static FT_Error
raccess_guess_darwin_newvfs( FT_Library library,
FT_Stream stream,
char *base_file_name,
char **result_file_name,
FT_Long *result_offset )
{
/*
Only meaningful on systems with Mac OS X (> 10.1).
*/
FT_Error error;
char* newpath = NULL;
FT_Memory memory;
FT_Long base_file_len = (FT_Long)ft_strlen( base_file_name );
FT_UNUSED( stream );
memory = library->memory;
if ( base_file_len + 18 > FT_INT_MAX )
return FT_THROW( Array_Too_Large );
if ( FT_ALLOC( newpath, base_file_len + 18 ) )
return error;
FT_MEM_COPY( newpath, base_file_name, base_file_len );
FT_MEM_COPY( newpath + base_file_len, "/..namedfork/rsrc", 18 );
*result_file_name = newpath;
*result_offset = 0;
return FT_Err_Ok;
}
static FT_Error
raccess_guess_vfat( FT_Library library,
FT_Stream stream,
char *base_file_name,
char **result_file_name,
FT_Long *result_offset )
{
char* newpath;
FT_Memory memory;
FT_UNUSED( stream );
memory = library->memory;
newpath = raccess_make_file_name( memory, base_file_name,
"resource.frk/" );
if ( !newpath )
return FT_THROW( Out_Of_Memory );
*result_file_name = newpath;
*result_offset = 0;
return FT_Err_Ok;
}
static FT_Error
raccess_guess_linux_cap( FT_Library library,
FT_Stream stream,
char *base_file_name,
char **result_file_name,
FT_Long *result_offset )
{
char* newpath;
FT_Memory memory;
FT_UNUSED( stream );
memory = library->memory;
newpath = raccess_make_file_name( memory, base_file_name, ".resource/" );
if ( !newpath )
return FT_THROW( Out_Of_Memory );
*result_file_name = newpath;
*result_offset = 0;
return FT_Err_Ok;
}
static FT_Error
raccess_guess_linux_double( FT_Library library,
FT_Stream stream,
char *base_file_name,
char **result_file_name,
FT_Long *result_offset )
{
char* newpath;
FT_Error error;
FT_Memory memory;
FT_UNUSED( stream );
memory = library->memory;
newpath = raccess_make_file_name( memory, base_file_name, "%" );
if ( !newpath )
return FT_THROW( Out_Of_Memory );
error = raccess_guess_linux_double_from_file_name( library, newpath,
result_offset );
if ( !error )
*result_file_name = newpath;
else
FT_FREE( newpath );
return error;
}
static FT_Error
raccess_guess_linux_netatalk( FT_Library library,
FT_Stream stream,
char *base_file_name,
char **result_file_name,
FT_Long *result_offset )
{
char* newpath;
FT_Error error;
FT_Memory memory;
FT_UNUSED( stream );
memory = library->memory;
newpath = raccess_make_file_name( memory, base_file_name,
".AppleDouble/" );
if ( !newpath )
return FT_THROW( Out_Of_Memory );
error = raccess_guess_linux_double_from_file_name( library, newpath,
result_offset );
if ( !error )
*result_file_name = newpath;
else
FT_FREE( newpath );
return error;
}
static FT_Error
raccess_guess_apple_generic( FT_Library library,
FT_Stream stream,
char *base_file_name,
FT_Int32 magic,
FT_Long *result_offset )
{
FT_Int32 magic_from_stream;
FT_Error error;
FT_Int32 version_number = 0;
FT_UShort n_of_entries;
int i;
FT_UInt32 entry_id, entry_offset, entry_length = 0;
const FT_UInt32 resource_fork_entry_id = 0x2;
FT_UNUSED( library );
FT_UNUSED( base_file_name );
FT_UNUSED( version_number );
FT_UNUSED( entry_length );
if ( FT_READ_LONG( magic_from_stream ) )
return error;
if ( magic_from_stream != magic )
return FT_THROW( Unknown_File_Format );
if ( FT_READ_LONG( version_number ) )
return error;
/* filler */
error = FT_Stream_Skip( stream, 16 );
if ( error )
return error;
if ( FT_READ_USHORT( n_of_entries ) )
return error;
if ( n_of_entries == 0 )
return FT_THROW( Unknown_File_Format );
for ( i = 0; i < n_of_entries; i++ )
{
if ( FT_READ_LONG( entry_id ) )
return error;
if ( entry_id == resource_fork_entry_id )
{
if ( FT_READ_LONG( entry_offset ) ||
FT_READ_LONG( entry_length ) )
continue;
*result_offset = entry_offset;
return FT_Err_Ok;
}
else
{
error = FT_Stream_Skip( stream, 4 + 4 ); /* offset + length */
if ( error )
return error;
}
}
return FT_THROW( Unknown_File_Format );
}
static FT_Error
raccess_guess_linux_double_from_file_name( FT_Library library,
char *file_name,
FT_Long *result_offset )
{
FT_Open_Args args2;
FT_Stream stream2;
char * nouse = NULL;
FT_Error error;
args2.flags = FT_OPEN_PATHNAME;
args2.pathname = file_name;
error = FT_Stream_New( library, &args2, &stream2 );
if ( error )
return error;
error = raccess_guess_apple_double( library, stream2, file_name,
&nouse, result_offset );
FT_Stream_Free( stream2, 0 );
return error;
}
static char*
raccess_make_file_name( FT_Memory memory,
const char *original_name,
const char *insertion )
{
char* new_name = NULL;
const char* tmp;
const char* slash;
size_t new_length;
FT_Error error = FT_Err_Ok;
FT_UNUSED( error );
new_length = ft_strlen( original_name ) + ft_strlen( insertion );
if ( FT_ALLOC( new_name, new_length + 1 ) )
return NULL;
tmp = ft_strrchr( original_name, '/' );
if ( tmp )
{
ft_strncpy( new_name, original_name, tmp - original_name + 1 );
new_name[tmp - original_name + 1] = '\0';
slash = tmp + 1;
}
else
{
slash = original_name;
new_name[0] = '\0';
}
ft_strcat( new_name, insertion );
ft_strcat( new_name, slash );
return new_name;
}
#else /* !FT_CONFIG_OPTION_GUESSING_EMBEDDED_RFORK */
/*************************************************************************/
/* Dummy function; just sets errors */
/*************************************************************************/
FT_BASE_DEF( void )
FT_Raccess_Guess( FT_Library library,
FT_Stream stream,
char *base_name,
char **new_names,
FT_Long *offsets,
FT_Error *errors )
{
FT_Int i;
FT_UNUSED( library );
FT_UNUSED( stream );
FT_UNUSED( base_name );
for ( i = 0; i < FT_RACCESS_N_RULES; i++ )
{
new_names[i] = NULL;
offsets[i] = 0;
errors[i] = FT_ERR( Unimplemented_Feature );
}
}
#endif /* !FT_CONFIG_OPTION_GUESSING_EMBEDDED_RFORK */
/* END */
| YifuLiu/AliOS-Things | components/freetype/src/base/ftrfork.c | C | apache-2.0 | 27,565 |
/***************************************************************************/
/* */
/* ftsnames.c */
/* */
/* Simple interface to access SFNT name tables (which are used */
/* to hold font names, copyright info, notices, etc.) (body). */
/* */
/* This is _not_ used to retrieve glyph names! */
/* */
/* Copyright 1996-2001, 2002, 2009 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. */
/* */
/***************************************************************************/
#include <ft2build.h>
#include FT_SFNT_NAMES_H
#include FT_INTERNAL_TRUETYPE_TYPES_H
#include FT_INTERNAL_STREAM_H
#ifdef TT_CONFIG_OPTION_SFNT_NAMES
/* documentation is in ftsnames.h */
FT_EXPORT_DEF( FT_UInt )
FT_Get_Sfnt_Name_Count( FT_Face face )
{
return ( face && FT_IS_SFNT( face ) ) ? ((TT_Face)face)->num_names : 0;
}
/* documentation is in ftsnames.h */
FT_EXPORT_DEF( FT_Error )
FT_Get_Sfnt_Name( FT_Face face,
FT_UInt idx,
FT_SfntName *aname )
{
FT_Error error = FT_ERR( Invalid_Argument );
if ( aname && face && FT_IS_SFNT( face ) )
{
TT_Face ttface = (TT_Face)face;
if ( idx < (FT_UInt)ttface->num_names )
{
TT_NameEntryRec* entry = ttface->name_table.names + idx;
/* load name on demand */
if ( entry->stringLength > 0 && entry->string == NULL )
{
FT_Memory memory = face->memory;
FT_Stream stream = face->stream;
if ( FT_NEW_ARRAY ( entry->string, entry->stringLength ) ||
FT_STREAM_SEEK( entry->stringOffset ) ||
FT_STREAM_READ( entry->string, entry->stringLength ) )
{
FT_FREE( entry->string );
entry->stringLength = 0;
}
}
aname->platform_id = entry->platformID;
aname->encoding_id = entry->encodingID;
aname->language_id = entry->languageID;
aname->name_id = entry->nameID;
aname->string = (FT_Byte*)entry->string;
aname->string_len = entry->stringLength;
error = FT_Err_Ok;
}
}
return error;
}
#endif /* TT_CONFIG_OPTION_SFNT_NAMES */
/* END */
| YifuLiu/AliOS-Things | components/freetype/src/base/ftsnames.c | C | apache-2.0 | 3,226 |
/***************************************************************************/
/* */
/* ftstream.c */
/* */
/* I/O stream support (body). */
/* */
/* Copyright 2000-2002, 2004-2006, 2008-2011, 2013 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. */
/* */
/***************************************************************************/
#include <ft2build.h>
#include FT_INTERNAL_STREAM_H
#include FT_INTERNAL_DEBUG_H
/*************************************************************************/
/* */
/* The macro FT_COMPONENT is used in trace mode. It is an implicit */
/* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */
/* messages during execution. */
/* */
#undef FT_COMPONENT
#define FT_COMPONENT trace_stream
FT_BASE_DEF( void )
FT_Stream_OpenMemory( FT_Stream stream,
const FT_Byte* base,
FT_ULong size )
{
stream->base = (FT_Byte*) base;
stream->size = size;
stream->pos = 0;
stream->cursor = 0;
stream->read = 0;
stream->close = 0;
}
FT_BASE_DEF( void )
FT_Stream_Close( FT_Stream stream )
{
if ( stream && stream->close )
stream->close( stream );
}
FT_BASE_DEF( FT_Error )
FT_Stream_Seek( FT_Stream stream,
FT_ULong pos )
{
FT_Error error = FT_Err_Ok;
if ( stream->read )
{
if ( stream->read( stream, pos, 0, 0 ) )
{
FT_ERROR(( "FT_Stream_Seek:"
" invalid i/o; pos = 0x%lx, size = 0x%lx\n",
pos, stream->size ));
error = FT_THROW( Invalid_Stream_Operation );
}
}
/* note that seeking to the first position after the file is valid */
else if ( pos > stream->size )
{
FT_ERROR(( "FT_Stream_Seek:"
" invalid i/o; pos = 0x%lx, size = 0x%lx\n",
pos, stream->size ));
error = FT_THROW( Invalid_Stream_Operation );
}
if ( !error )
stream->pos = pos;
return error;
}
FT_BASE_DEF( FT_Error )
FT_Stream_Skip( FT_Stream stream,
FT_Long distance )
{
if ( distance < 0 )
return FT_THROW( Invalid_Stream_Operation );
return FT_Stream_Seek( stream, (FT_ULong)( stream->pos + distance ) );
}
FT_BASE_DEF( FT_Long )
FT_Stream_Pos( FT_Stream stream )
{
return stream->pos;
}
FT_BASE_DEF( FT_Error )
FT_Stream_Read( FT_Stream stream,
FT_Byte* buffer,
FT_ULong count )
{
return FT_Stream_ReadAt( stream, stream->pos, buffer, count );
}
FT_BASE_DEF( FT_Error )
FT_Stream_ReadAt( FT_Stream stream,
FT_ULong pos,
FT_Byte* buffer,
FT_ULong count )
{
FT_Error error = FT_Err_Ok;
FT_ULong read_bytes;
if ( pos >= stream->size )
{
FT_ERROR(( "FT_Stream_ReadAt:"
" invalid i/o; pos = 0x%lx, size = 0x%lx\n",
pos, stream->size ));
return FT_THROW( Invalid_Stream_Operation );
}
if ( stream->read )
read_bytes = stream->read( stream, pos, buffer, count );
else
{
read_bytes = stream->size - pos;
if ( read_bytes > count )
read_bytes = count;
FT_MEM_COPY( buffer, stream->base + pos, read_bytes );
}
stream->pos = pos + read_bytes;
if ( read_bytes < count )
{
FT_ERROR(( "FT_Stream_ReadAt:"
" invalid read; expected %lu bytes, got %lu\n",
count, read_bytes ));
error = FT_THROW( Invalid_Stream_Operation );
}
return error;
}
FT_BASE_DEF( FT_ULong )
FT_Stream_TryRead( FT_Stream stream,
FT_Byte* buffer,
FT_ULong count )
{
FT_ULong read_bytes = 0;
if ( stream->pos >= stream->size )
goto Exit;
if ( stream->read )
read_bytes = stream->read( stream, stream->pos, buffer, count );
else
{
read_bytes = stream->size - stream->pos;
if ( read_bytes > count )
read_bytes = count;
FT_MEM_COPY( buffer, stream->base + stream->pos, read_bytes );
}
stream->pos += read_bytes;
Exit:
return read_bytes;
}
FT_BASE_DEF( FT_Error )
FT_Stream_ExtractFrame( FT_Stream stream,
FT_ULong count,
FT_Byte** pbytes )
{
FT_Error error;
error = FT_Stream_EnterFrame( stream, count );
if ( !error )
{
*pbytes = (FT_Byte*)stream->cursor;
/* equivalent to FT_Stream_ExitFrame(), with no memory block release */
stream->cursor = 0;
stream->limit = 0;
}
return error;
}
FT_BASE_DEF( void )
FT_Stream_ReleaseFrame( FT_Stream stream,
FT_Byte** pbytes )
{
if ( stream && stream->read )
{
FT_Memory memory = stream->memory;
#ifdef FT_DEBUG_MEMORY
ft_mem_free( memory, *pbytes );
*pbytes = NULL;
#else
FT_FREE( *pbytes );
#endif
}
*pbytes = 0;
}
FT_BASE_DEF( FT_Error )
FT_Stream_EnterFrame( FT_Stream stream,
FT_ULong count )
{
FT_Error error = FT_Err_Ok;
FT_ULong read_bytes;
/* check for nested frame access */
FT_ASSERT( stream && stream->cursor == 0 );
if ( stream->read )
{
/* allocate the frame in memory */
FT_Memory memory = stream->memory;
/* simple sanity check */
if ( count > stream->size )
{
FT_ERROR(( "FT_Stream_EnterFrame:"
" frame size (%lu) larger than stream size (%lu)\n",
count, stream->size ));
error = FT_THROW( Invalid_Stream_Operation );
goto Exit;
}
#ifdef FT_DEBUG_MEMORY
/* assume _ft_debug_file and _ft_debug_lineno are already set */
stream->base = (unsigned char*)ft_mem_qalloc( memory, count, &error );
if ( error )
goto Exit;
#else
if ( FT_QALLOC( stream->base, count ) )
goto Exit;
#endif
/* read it */
read_bytes = stream->read( stream, stream->pos,
stream->base, count );
if ( read_bytes < count )
{
FT_ERROR(( "FT_Stream_EnterFrame:"
" invalid read; expected %lu bytes, got %lu\n",
count, read_bytes ));
FT_FREE( stream->base );
error = FT_THROW( Invalid_Stream_Operation );
}
stream->cursor = stream->base;
stream->limit = stream->cursor + count;
stream->pos += read_bytes;
}
else
{
/* check current and new position */
if ( stream->pos >= stream->size ||
stream->size - stream->pos < count )
{
FT_ERROR(( "FT_Stream_EnterFrame:"
" invalid i/o; pos = 0x%lx, count = %lu, size = 0x%lx\n",
stream->pos, count, stream->size ));
error = FT_THROW( Invalid_Stream_Operation );
goto Exit;
}
/* set cursor */
stream->cursor = stream->base + stream->pos;
stream->limit = stream->cursor + count;
stream->pos += count;
}
Exit:
return error;
}
FT_BASE_DEF( void )
FT_Stream_ExitFrame( FT_Stream stream )
{
/* IMPORTANT: The assertion stream->cursor != 0 was removed, given */
/* that it is possible to access a frame of length 0 in */
/* some weird fonts (usually, when accessing an array of */
/* 0 records, like in some strange kern tables). */
/* */
/* In this case, the loader code handles the 0-length table */
/* gracefully; however, stream.cursor is really set to 0 by the */
/* FT_Stream_EnterFrame() call, and this is not an error. */
/* */
FT_ASSERT( stream );
if ( stream->read )
{
FT_Memory memory = stream->memory;
#ifdef FT_DEBUG_MEMORY
ft_mem_free( memory, stream->base );
stream->base = NULL;
#else
FT_FREE( stream->base );
#endif
}
stream->cursor = 0;
stream->limit = 0;
}
FT_BASE_DEF( FT_Char )
FT_Stream_GetChar( FT_Stream stream )
{
FT_Char result;
FT_ASSERT( stream && stream->cursor );
result = 0;
if ( stream->cursor < stream->limit )
result = *stream->cursor++;
return result;
}
FT_BASE_DEF( FT_UShort )
FT_Stream_GetUShort( FT_Stream stream )
{
FT_Byte* p;
FT_Short result;
FT_ASSERT( stream && stream->cursor );
result = 0;
p = stream->cursor;
if ( p + 1 < stream->limit )
result = FT_NEXT_USHORT( p );
stream->cursor = p;
return result;
}
FT_BASE_DEF( FT_UShort )
FT_Stream_GetUShortLE( FT_Stream stream )
{
FT_Byte* p;
FT_Short result;
FT_ASSERT( stream && stream->cursor );
result = 0;
p = stream->cursor;
if ( p + 1 < stream->limit )
result = FT_NEXT_USHORT_LE( p );
stream->cursor = p;
return result;
}
FT_BASE_DEF( FT_ULong )
FT_Stream_GetUOffset( FT_Stream stream )
{
FT_Byte* p;
FT_Long result;
FT_ASSERT( stream && stream->cursor );
result = 0;
p = stream->cursor;
if ( p + 2 < stream->limit )
result = FT_NEXT_UOFF3( p );
stream->cursor = p;
return result;
}
FT_BASE_DEF( FT_ULong )
FT_Stream_GetULong( FT_Stream stream )
{
FT_Byte* p;
FT_Long result;
FT_ASSERT( stream && stream->cursor );
result = 0;
p = stream->cursor;
if ( p + 3 < stream->limit )
result = FT_NEXT_ULONG( p );
stream->cursor = p;
return result;
}
FT_BASE_DEF( FT_ULong )
FT_Stream_GetULongLE( FT_Stream stream )
{
FT_Byte* p;
FT_Long result;
FT_ASSERT( stream && stream->cursor );
result = 0;
p = stream->cursor;
if ( p + 3 < stream->limit )
result = FT_NEXT_ULONG_LE( p );
stream->cursor = p;
return result;
}
FT_BASE_DEF( FT_Char )
FT_Stream_ReadChar( FT_Stream stream,
FT_Error* error )
{
FT_Byte result = 0;
FT_ASSERT( stream );
*error = FT_Err_Ok;
if ( stream->read )
{
if ( stream->read( stream, stream->pos, &result, 1L ) != 1L )
goto Fail;
}
else
{
if ( stream->pos < stream->size )
result = stream->base[stream->pos];
else
goto Fail;
}
stream->pos++;
return result;
Fail:
*error = FT_THROW( Invalid_Stream_Operation );
FT_ERROR(( "FT_Stream_ReadChar:"
" invalid i/o; pos = 0x%lx, size = 0x%lx\n",
stream->pos, stream->size ));
return 0;
}
FT_BASE_DEF( FT_UShort )
FT_Stream_ReadUShort( FT_Stream stream,
FT_Error* error )
{
FT_Byte reads[2];
FT_Byte* p = 0;
FT_Short result = 0;
FT_ASSERT( stream );
*error = FT_Err_Ok;
if ( stream->pos + 1 < stream->size )
{
if ( stream->read )
{
if ( stream->read( stream, stream->pos, reads, 2L ) != 2L )
goto Fail;
p = reads;
}
else
{
p = stream->base + stream->pos;
}
if ( p )
result = FT_NEXT_USHORT( p );
}
else
goto Fail;
stream->pos += 2;
return result;
Fail:
*error = FT_THROW( Invalid_Stream_Operation );
FT_ERROR(( "FT_Stream_ReadUShort:"
" invalid i/o; pos = 0x%lx, size = 0x%lx\n",
stream->pos, stream->size ));
return 0;
}
FT_BASE_DEF( FT_UShort )
FT_Stream_ReadUShortLE( FT_Stream stream,
FT_Error* error )
{
FT_Byte reads[2];
FT_Byte* p = 0;
FT_Short result = 0;
FT_ASSERT( stream );
*error = FT_Err_Ok;
if ( stream->pos + 1 < stream->size )
{
if ( stream->read )
{
if ( stream->read( stream, stream->pos, reads, 2L ) != 2L )
goto Fail;
p = reads;
}
else
{
p = stream->base + stream->pos;
}
if ( p )
result = FT_NEXT_USHORT_LE( p );
}
else
goto Fail;
stream->pos += 2;
return result;
Fail:
*error = FT_THROW( Invalid_Stream_Operation );
FT_ERROR(( "FT_Stream_ReadUShortLE:"
" invalid i/o; pos = 0x%lx, size = 0x%lx\n",
stream->pos, stream->size ));
return 0;
}
FT_BASE_DEF( FT_ULong )
FT_Stream_ReadUOffset( FT_Stream stream,
FT_Error* error )
{
FT_Byte reads[3];
FT_Byte* p = 0;
FT_Long result = 0;
FT_ASSERT( stream );
*error = FT_Err_Ok;
if ( stream->pos + 2 < stream->size )
{
if ( stream->read )
{
if (stream->read( stream, stream->pos, reads, 3L ) != 3L )
goto Fail;
p = reads;
}
else
{
p = stream->base + stream->pos;
}
if ( p )
result = FT_NEXT_UOFF3( p );
}
else
goto Fail;
stream->pos += 3;
return result;
Fail:
*error = FT_THROW( Invalid_Stream_Operation );
FT_ERROR(( "FT_Stream_ReadUOffset:"
" invalid i/o; pos = 0x%lx, size = 0x%lx\n",
stream->pos, stream->size ));
return 0;
}
FT_BASE_DEF( FT_ULong )
FT_Stream_ReadULong( FT_Stream stream,
FT_Error* error )
{
FT_Byte reads[4];
FT_Byte* p = 0;
FT_Long result = 0;
FT_ASSERT( stream );
*error = FT_Err_Ok;
if ( stream->pos + 3 < stream->size )
{
if ( stream->read )
{
if ( stream->read( stream, stream->pos, reads, 4L ) != 4L )
goto Fail;
p = reads;
}
else
{
p = stream->base + stream->pos;
}
if ( p )
result = FT_NEXT_ULONG( p );
}
else
goto Fail;
stream->pos += 4;
return result;
Fail:
*error = FT_THROW( Invalid_Stream_Operation );
FT_ERROR(( "FT_Stream_ReadULong:"
" invalid i/o; pos = 0x%lx, size = 0x%lx\n",
stream->pos, stream->size ));
return 0;
}
FT_BASE_DEF( FT_ULong )
FT_Stream_ReadULongLE( FT_Stream stream,
FT_Error* error )
{
FT_Byte reads[4];
FT_Byte* p = 0;
FT_Long result = 0;
FT_ASSERT( stream );
*error = FT_Err_Ok;
if ( stream->pos + 3 < stream->size )
{
if ( stream->read )
{
if ( stream->read( stream, stream->pos, reads, 4L ) != 4L )
goto Fail;
p = reads;
}
else
{
p = stream->base + stream->pos;
}
if ( p )
result = FT_NEXT_ULONG_LE( p );
}
else
goto Fail;
stream->pos += 4;
return result;
Fail:
*error = FT_THROW( Invalid_Stream_Operation );
FT_ERROR(( "FT_Stream_ReadULongLE:"
" invalid i/o; pos = 0x%lx, size = 0x%lx\n",
stream->pos, stream->size ));
return 0;
}
FT_BASE_DEF( FT_Error )
FT_Stream_ReadFields( FT_Stream stream,
const FT_Frame_Field* fields,
void* structure )
{
FT_Error error;
FT_Bool frame_accessed = 0;
FT_Byte* cursor;
if ( !fields || !stream )
return FT_THROW( Invalid_Argument );
cursor = stream->cursor;
error = FT_Err_Ok;
do
{
FT_ULong value;
FT_Int sign_shift;
FT_Byte* p;
switch ( fields->value )
{
case ft_frame_start: /* access a new frame */
error = FT_Stream_EnterFrame( stream, fields->offset );
if ( error )
goto Exit;
frame_accessed = 1;
cursor = stream->cursor;
fields++;
continue; /* loop! */
case ft_frame_bytes: /* read a byte sequence */
case ft_frame_skip: /* skip some bytes */
{
FT_UInt len = fields->size;
if ( cursor + len > stream->limit )
{
error = FT_THROW( Invalid_Stream_Operation );
goto Exit;
}
if ( fields->value == ft_frame_bytes )
{
p = (FT_Byte*)structure + fields->offset;
FT_MEM_COPY( p, cursor, len );
}
cursor += len;
fields++;
continue;
}
case ft_frame_byte:
case ft_frame_schar: /* read a single byte */
value = FT_NEXT_BYTE( cursor );
sign_shift = 24;
break;
case ft_frame_short_be:
case ft_frame_ushort_be: /* read a 2-byte big-endian short */
value = FT_NEXT_USHORT( cursor) ;
sign_shift = 16;
break;
case ft_frame_short_le:
case ft_frame_ushort_le: /* read a 2-byte little-endian short */
value = FT_NEXT_USHORT_LE( cursor );
sign_shift = 16;
break;
case ft_frame_long_be:
case ft_frame_ulong_be: /* read a 4-byte big-endian long */
value = FT_NEXT_ULONG( cursor );
sign_shift = 0;
break;
case ft_frame_long_le:
case ft_frame_ulong_le: /* read a 4-byte little-endian long */
value = FT_NEXT_ULONG_LE( cursor );
sign_shift = 0;
break;
case ft_frame_off3_be:
case ft_frame_uoff3_be: /* read a 3-byte big-endian long */
value = FT_NEXT_UOFF3( cursor );
sign_shift = 8;
break;
case ft_frame_off3_le:
case ft_frame_uoff3_le: /* read a 3-byte little-endian long */
value = FT_NEXT_UOFF3_LE( cursor );
sign_shift = 8;
break;
default:
/* otherwise, exit the loop */
stream->cursor = cursor;
goto Exit;
}
/* now, compute the signed value is necessary */
if ( fields->value & FT_FRAME_OP_SIGNED )
value = (FT_ULong)( (FT_Int32)( value << sign_shift ) >> sign_shift );
/* finally, store the value in the object */
p = (FT_Byte*)structure + fields->offset;
switch ( fields->size )
{
case ( 8 / FT_CHAR_BIT ):
*(FT_Byte*)p = (FT_Byte)value;
break;
case ( 16 / FT_CHAR_BIT ):
*(FT_UShort*)p = (FT_UShort)value;
break;
case ( 32 / FT_CHAR_BIT ):
*(FT_UInt32*)p = (FT_UInt32)value;
break;
default: /* for 64-bit systems */
*(FT_ULong*)p = (FT_ULong)value;
}
/* go to next field */
fields++;
}
while ( 1 );
Exit:
/* close the frame if it was opened by this read */
if ( frame_accessed )
FT_Stream_ExitFrame( stream );
return error;
}
/* END */
| YifuLiu/AliOS-Things | components/freetype/src/base/ftstream.c | C | apache-2.0 | 20,020 |
/***************************************************************************/
/* */
/* ftstroke.c */
/* */
/* FreeType path stroker (body). */
/* */
/* Copyright 2002-2006, 2008-2011, 2013 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. */
/* */
/***************************************************************************/
#include <ft2build.h>
#include FT_STROKER_H
#include FT_TRIGONOMETRY_H
#include FT_OUTLINE_H
#include FT_INTERNAL_MEMORY_H
#include FT_INTERNAL_DEBUG_H
#include FT_INTERNAL_OBJECTS_H
/* documentation is in ftstroke.h */
FT_EXPORT_DEF( FT_StrokerBorder )
FT_Outline_GetInsideBorder( FT_Outline* outline )
{
FT_Orientation o = FT_Outline_Get_Orientation( outline );
return o == FT_ORIENTATION_TRUETYPE ? FT_STROKER_BORDER_RIGHT
: FT_STROKER_BORDER_LEFT;
}
/* documentation is in ftstroke.h */
FT_EXPORT_DEF( FT_StrokerBorder )
FT_Outline_GetOutsideBorder( FT_Outline* outline )
{
FT_Orientation o = FT_Outline_Get_Orientation( outline );
return o == FT_ORIENTATION_TRUETYPE ? FT_STROKER_BORDER_LEFT
: FT_STROKER_BORDER_RIGHT;
}
/*************************************************************************/
/*************************************************************************/
/***** *****/
/***** BEZIER COMPUTATIONS *****/
/***** *****/
/*************************************************************************/
/*************************************************************************/
#define FT_SMALL_CONIC_THRESHOLD ( FT_ANGLE_PI / 6 )
#define FT_SMALL_CUBIC_THRESHOLD ( FT_ANGLE_PI / 8 )
#define FT_EPSILON 2
#define FT_IS_SMALL( x ) ( (x) > -FT_EPSILON && (x) < FT_EPSILON )
static FT_Pos
ft_pos_abs( FT_Pos x )
{
return x >= 0 ? x : -x;
}
static void
ft_conic_split( FT_Vector* base )
{
FT_Pos a, b;
base[4].x = base[2].x;
b = base[1].x;
a = base[3].x = ( base[2].x + b ) / 2;
b = base[1].x = ( base[0].x + b ) / 2;
base[2].x = ( a + b ) / 2;
base[4].y = base[2].y;
b = base[1].y;
a = base[3].y = ( base[2].y + b ) / 2;
b = base[1].y = ( base[0].y + b ) / 2;
base[2].y = ( a + b ) / 2;
}
static FT_Bool
ft_conic_is_small_enough( FT_Vector* base,
FT_Angle *angle_in,
FT_Angle *angle_out )
{
FT_Vector d1, d2;
FT_Angle theta;
FT_Int close1, close2;
d1.x = base[1].x - base[2].x;
d1.y = base[1].y - base[2].y;
d2.x = base[0].x - base[1].x;
d2.y = base[0].y - base[1].y;
close1 = FT_IS_SMALL( d1.x ) && FT_IS_SMALL( d1.y );
close2 = FT_IS_SMALL( d2.x ) && FT_IS_SMALL( d2.y );
if ( close1 )
{
if ( close2 )
{
/* basically a point; */
/* do nothing to retain original direction */
}
else
{
*angle_in =
*angle_out = FT_Atan2( d2.x, d2.y );
}
}
else /* !close1 */
{
if ( close2 )
{
*angle_in =
*angle_out = FT_Atan2( d1.x, d1.y );
}
else
{
*angle_in = FT_Atan2( d1.x, d1.y );
*angle_out = FT_Atan2( d2.x, d2.y );
}
}
theta = ft_pos_abs( FT_Angle_Diff( *angle_in, *angle_out ) );
return FT_BOOL( theta < FT_SMALL_CONIC_THRESHOLD );
}
static void
ft_cubic_split( FT_Vector* base )
{
FT_Pos a, b, c, d;
base[6].x = base[3].x;
c = base[1].x;
d = base[2].x;
base[1].x = a = ( base[0].x + c ) / 2;
base[5].x = b = ( base[3].x + d ) / 2;
c = ( c + d ) / 2;
base[2].x = a = ( a + c ) / 2;
base[4].x = b = ( b + c ) / 2;
base[3].x = ( a + b ) / 2;
base[6].y = base[3].y;
c = base[1].y;
d = base[2].y;
base[1].y = a = ( base[0].y + c ) / 2;
base[5].y = b = ( base[3].y + d ) / 2;
c = ( c + d ) / 2;
base[2].y = a = ( a + c ) / 2;
base[4].y = b = ( b + c ) / 2;
base[3].y = ( a + b ) / 2;
}
/* Return the average of `angle1' and `angle2'. */
/* This gives correct result even if `angle1' and `angle2' */
/* have opposite signs. */
static FT_Angle
ft_angle_mean( FT_Angle angle1,
FT_Angle angle2 )
{
return angle1 + FT_Angle_Diff( angle1, angle2 ) / 2;
}
static FT_Bool
ft_cubic_is_small_enough( FT_Vector* base,
FT_Angle *angle_in,
FT_Angle *angle_mid,
FT_Angle *angle_out )
{
FT_Vector d1, d2, d3;
FT_Angle theta1, theta2;
FT_Int close1, close2, close3;
d1.x = base[2].x - base[3].x;
d1.y = base[2].y - base[3].y;
d2.x = base[1].x - base[2].x;
d2.y = base[1].y - base[2].y;
d3.x = base[0].x - base[1].x;
d3.y = base[0].y - base[1].y;
close1 = FT_IS_SMALL( d1.x ) && FT_IS_SMALL( d1.y );
close2 = FT_IS_SMALL( d2.x ) && FT_IS_SMALL( d2.y );
close3 = FT_IS_SMALL( d3.x ) && FT_IS_SMALL( d3.y );
if ( close1 )
{
if ( close2 )
{
if ( close3 )
{
/* basically a point; */
/* do nothing to retain original direction */
}
else /* !close3 */
{
*angle_in =
*angle_mid =
*angle_out = FT_Atan2( d3.x, d3.y );
}
}
else /* !close2 */
{
if ( close3 )
{
*angle_in =
*angle_mid =
*angle_out = FT_Atan2( d2.x, d2.y );
}
else /* !close3 */
{
*angle_in =
*angle_mid = FT_Atan2( d2.x, d2.y );
*angle_out = FT_Atan2( d3.x, d3.y );
}
}
}
else /* !close1 */
{
if ( close2 )
{
if ( close3 )
{
*angle_in =
*angle_mid =
*angle_out = FT_Atan2( d1.x, d1.y );
}
else /* !close3 */
{
*angle_in = FT_Atan2( d1.x, d1.y );
*angle_out = FT_Atan2( d3.x, d3.y );
*angle_mid = ft_angle_mean( *angle_in, *angle_out );
}
}
else /* !close2 */
{
if ( close3 )
{
*angle_in = FT_Atan2( d1.x, d1.y );
*angle_mid =
*angle_out = FT_Atan2( d2.x, d2.y );
}
else /* !close3 */
{
*angle_in = FT_Atan2( d1.x, d1.y );
*angle_mid = FT_Atan2( d2.x, d2.y );
*angle_out = FT_Atan2( d3.x, d3.y );
}
}
}
theta1 = ft_pos_abs( FT_Angle_Diff( *angle_in, *angle_mid ) );
theta2 = ft_pos_abs( FT_Angle_Diff( *angle_mid, *angle_out ) );
return FT_BOOL( theta1 < FT_SMALL_CUBIC_THRESHOLD &&
theta2 < FT_SMALL_CUBIC_THRESHOLD );
}
/*************************************************************************/
/*************************************************************************/
/***** *****/
/***** STROKE BORDERS *****/
/***** *****/
/*************************************************************************/
/*************************************************************************/
typedef enum FT_StrokeTags_
{
FT_STROKE_TAG_ON = 1, /* on-curve point */
FT_STROKE_TAG_CUBIC = 2, /* cubic off-point */
FT_STROKE_TAG_BEGIN = 4, /* sub-path start */
FT_STROKE_TAG_END = 8 /* sub-path end */
} FT_StrokeTags;
#define FT_STROKE_TAG_BEGIN_END ( FT_STROKE_TAG_BEGIN | FT_STROKE_TAG_END )
typedef struct FT_StrokeBorderRec_
{
FT_UInt num_points;
FT_UInt max_points;
FT_Vector* points;
FT_Byte* tags;
FT_Bool movable; /* TRUE for ends of lineto borders */
FT_Int start; /* index of current sub-path start point */
FT_Memory memory;
FT_Bool valid;
} FT_StrokeBorderRec, *FT_StrokeBorder;
static FT_Error
ft_stroke_border_grow( FT_StrokeBorder border,
FT_UInt new_points )
{
FT_UInt old_max = border->max_points;
FT_UInt new_max = border->num_points + new_points;
FT_Error error = FT_Err_Ok;
if ( new_max > old_max )
{
FT_UInt cur_max = old_max;
FT_Memory memory = border->memory;
while ( cur_max < new_max )
cur_max += ( cur_max >> 1 ) + 16;
if ( FT_RENEW_ARRAY( border->points, old_max, cur_max ) ||
FT_RENEW_ARRAY( border->tags, old_max, cur_max ) )
goto Exit;
border->max_points = cur_max;
}
Exit:
return error;
}
static void
ft_stroke_border_close( FT_StrokeBorder border,
FT_Bool reverse )
{
FT_UInt start = border->start;
FT_UInt count = border->num_points;
FT_ASSERT( border->start >= 0 );
/* don't record empty paths! */
if ( count <= start + 1U )
border->num_points = start;
else
{
/* copy the last point to the start of this sub-path, since */
/* it contains the `adjusted' starting coordinates */
border->num_points = --count;
border->points[start] = border->points[count];
if ( reverse )
{
/* reverse the points */
{
FT_Vector* vec1 = border->points + start + 1;
FT_Vector* vec2 = border->points + count - 1;
for ( ; vec1 < vec2; vec1++, vec2-- )
{
FT_Vector tmp;
tmp = *vec1;
*vec1 = *vec2;
*vec2 = tmp;
}
}
/* then the tags */
{
FT_Byte* tag1 = border->tags + start + 1;
FT_Byte* tag2 = border->tags + count - 1;
for ( ; tag1 < tag2; tag1++, tag2-- )
{
FT_Byte tmp;
tmp = *tag1;
*tag1 = *tag2;
*tag2 = tmp;
}
}
}
border->tags[start ] |= FT_STROKE_TAG_BEGIN;
border->tags[count - 1] |= FT_STROKE_TAG_END;
}
border->start = -1;
border->movable = FALSE;
}
static FT_Error
ft_stroke_border_lineto( FT_StrokeBorder border,
FT_Vector* to,
FT_Bool movable )
{
FT_Error error = FT_Err_Ok;
FT_ASSERT( border->start >= 0 );
if ( border->movable )
{
/* move last point */
border->points[border->num_points - 1] = *to;
}
else
{
/* don't add zero-length lineto */
if ( border->num_points > 0 &&
FT_IS_SMALL( border->points[border->num_points - 1].x - to->x ) &&
FT_IS_SMALL( border->points[border->num_points - 1].y - to->y ) )
return error;
/* add one point */
error = ft_stroke_border_grow( border, 1 );
if ( !error )
{
FT_Vector* vec = border->points + border->num_points;
FT_Byte* tag = border->tags + border->num_points;
vec[0] = *to;
tag[0] = FT_STROKE_TAG_ON;
border->num_points += 1;
}
}
border->movable = movable;
return error;
}
static FT_Error
ft_stroke_border_conicto( FT_StrokeBorder border,
FT_Vector* control,
FT_Vector* to )
{
FT_Error error;
FT_ASSERT( border->start >= 0 );
error = ft_stroke_border_grow( border, 2 );
if ( !error )
{
FT_Vector* vec = border->points + border->num_points;
FT_Byte* tag = border->tags + border->num_points;
vec[0] = *control;
vec[1] = *to;
tag[0] = 0;
tag[1] = FT_STROKE_TAG_ON;
border->num_points += 2;
}
border->movable = FALSE;
return error;
}
static FT_Error
ft_stroke_border_cubicto( FT_StrokeBorder border,
FT_Vector* control1,
FT_Vector* control2,
FT_Vector* to )
{
FT_Error error;
FT_ASSERT( border->start >= 0 );
error = ft_stroke_border_grow( border, 3 );
if ( !error )
{
FT_Vector* vec = border->points + border->num_points;
FT_Byte* tag = border->tags + border->num_points;
vec[0] = *control1;
vec[1] = *control2;
vec[2] = *to;
tag[0] = FT_STROKE_TAG_CUBIC;
tag[1] = FT_STROKE_TAG_CUBIC;
tag[2] = FT_STROKE_TAG_ON;
border->num_points += 3;
}
border->movable = FALSE;
return error;
}
#define FT_ARC_CUBIC_ANGLE ( FT_ANGLE_PI / 2 )
static FT_Error
ft_stroke_border_arcto( FT_StrokeBorder border,
FT_Vector* center,
FT_Fixed radius,
FT_Angle angle_start,
FT_Angle angle_diff )
{
FT_Angle total, angle, step, rotate, next, theta;
FT_Vector a, b, a2, b2;
FT_Fixed length;
FT_Error error = FT_Err_Ok;
/* compute start point */
FT_Vector_From_Polar( &a, radius, angle_start );
a.x += center->x;
a.y += center->y;
total = angle_diff;
angle = angle_start;
rotate = ( angle_diff >= 0 ) ? FT_ANGLE_PI2 : -FT_ANGLE_PI2;
while ( total != 0 )
{
step = total;
if ( step > FT_ARC_CUBIC_ANGLE )
step = FT_ARC_CUBIC_ANGLE;
else if ( step < -FT_ARC_CUBIC_ANGLE )
step = -FT_ARC_CUBIC_ANGLE;
next = angle + step;
theta = step;
if ( theta < 0 )
theta = -theta;
theta >>= 1;
/* compute end point */
FT_Vector_From_Polar( &b, radius, next );
b.x += center->x;
b.y += center->y;
/* compute first and second control points */
length = FT_MulDiv( radius, FT_Sin( theta ) * 4,
( 0x10000L + FT_Cos( theta ) ) * 3 );
FT_Vector_From_Polar( &a2, length, angle + rotate );
a2.x += a.x;
a2.y += a.y;
FT_Vector_From_Polar( &b2, length, next - rotate );
b2.x += b.x;
b2.y += b.y;
/* add cubic arc */
error = ft_stroke_border_cubicto( border, &a2, &b2, &b );
if ( error )
break;
/* process the rest of the arc ?? */
a = b;
total -= step;
angle = next;
}
return error;
}
static FT_Error
ft_stroke_border_moveto( FT_StrokeBorder border,
FT_Vector* to )
{
/* close current open path if any ? */
if ( border->start >= 0 )
ft_stroke_border_close( border, FALSE );
border->start = border->num_points;
border->movable = FALSE;
return ft_stroke_border_lineto( border, to, FALSE );
}
static void
ft_stroke_border_init( FT_StrokeBorder border,
FT_Memory memory )
{
border->memory = memory;
border->points = NULL;
border->tags = NULL;
border->num_points = 0;
border->max_points = 0;
border->start = -1;
border->valid = FALSE;
}
static void
ft_stroke_border_reset( FT_StrokeBorder border )
{
border->num_points = 0;
border->start = -1;
border->valid = FALSE;
}
static void
ft_stroke_border_done( FT_StrokeBorder border )
{
FT_Memory memory = border->memory;
FT_FREE( border->points );
FT_FREE( border->tags );
border->num_points = 0;
border->max_points = 0;
border->start = -1;
border->valid = FALSE;
}
static FT_Error
ft_stroke_border_get_counts( FT_StrokeBorder border,
FT_UInt *anum_points,
FT_UInt *anum_contours )
{
FT_Error error = FT_Err_Ok;
FT_UInt num_points = 0;
FT_UInt num_contours = 0;
FT_UInt count = border->num_points;
FT_Vector* point = border->points;
FT_Byte* tags = border->tags;
FT_Int in_contour = 0;
for ( ; count > 0; count--, num_points++, point++, tags++ )
{
if ( tags[0] & FT_STROKE_TAG_BEGIN )
{
if ( in_contour != 0 )
goto Fail;
in_contour = 1;
}
else if ( in_contour == 0 )
goto Fail;
if ( tags[0] & FT_STROKE_TAG_END )
{
in_contour = 0;
num_contours++;
}
}
if ( in_contour != 0 )
goto Fail;
border->valid = TRUE;
Exit:
*anum_points = num_points;
*anum_contours = num_contours;
return error;
Fail:
num_points = 0;
num_contours = 0;
goto Exit;
}
static void
ft_stroke_border_export( FT_StrokeBorder border,
FT_Outline* outline )
{
/* copy point locations */
FT_ARRAY_COPY( outline->points + outline->n_points,
border->points,
border->num_points );
/* copy tags */
{
FT_UInt count = border->num_points;
FT_Byte* read = border->tags;
FT_Byte* write = (FT_Byte*)outline->tags + outline->n_points;
for ( ; count > 0; count--, read++, write++ )
{
if ( *read & FT_STROKE_TAG_ON )
*write = FT_CURVE_TAG_ON;
else if ( *read & FT_STROKE_TAG_CUBIC )
*write = FT_CURVE_TAG_CUBIC;
else
*write = FT_CURVE_TAG_CONIC;
}
}
/* copy contours */
{
FT_UInt count = border->num_points;
FT_Byte* tags = border->tags;
FT_Short* write = outline->contours + outline->n_contours;
FT_Short idx = (FT_Short)outline->n_points;
for ( ; count > 0; count--, tags++, idx++ )
{
if ( *tags & FT_STROKE_TAG_END )
{
*write++ = idx;
outline->n_contours++;
}
}
}
outline->n_points = (short)( outline->n_points + border->num_points );
FT_ASSERT( FT_Outline_Check( outline ) == 0 );
}
/*************************************************************************/
/*************************************************************************/
/***** *****/
/***** STROKER *****/
/***** *****/
/*************************************************************************/
/*************************************************************************/
#define FT_SIDE_TO_ROTATE( s ) ( FT_ANGLE_PI2 - (s) * FT_ANGLE_PI )
typedef struct FT_StrokerRec_
{
FT_Angle angle_in; /* direction into curr join */
FT_Angle angle_out; /* direction out of join */
FT_Vector center; /* current position */
FT_Fixed line_length; /* length of last lineto */
FT_Bool first_point; /* is this the start? */
FT_Bool subpath_open; /* is the subpath open? */
FT_Angle subpath_angle; /* subpath start direction */
FT_Vector subpath_start; /* subpath start position */
FT_Fixed subpath_line_length; /* subpath start lineto len */
FT_Bool handle_wide_strokes; /* use wide strokes logic? */
FT_Stroker_LineCap line_cap;
FT_Stroker_LineJoin line_join;
FT_Stroker_LineJoin line_join_saved;
FT_Fixed miter_limit;
FT_Fixed radius;
FT_StrokeBorderRec borders[2];
FT_Library library;
} FT_StrokerRec;
/* documentation is in ftstroke.h */
FT_EXPORT_DEF( FT_Error )
FT_Stroker_New( FT_Library library,
FT_Stroker *astroker )
{
FT_Error error = FT_Err_Ok; /* assigned in FT_NEW */
FT_Memory memory;
FT_Stroker stroker = NULL;
if ( !library )
return FT_THROW( Invalid_Argument );
memory = library->memory;
if ( !FT_NEW( stroker ) )
{
stroker->library = library;
ft_stroke_border_init( &stroker->borders[0], memory );
ft_stroke_border_init( &stroker->borders[1], memory );
}
*astroker = stroker;
return error;
}
/* documentation is in ftstroke.h */
FT_EXPORT_DEF( void )
FT_Stroker_Set( FT_Stroker stroker,
FT_Fixed radius,
FT_Stroker_LineCap line_cap,
FT_Stroker_LineJoin line_join,
FT_Fixed miter_limit )
{
stroker->radius = radius;
stroker->line_cap = line_cap;
stroker->line_join = line_join;
stroker->miter_limit = miter_limit;
/* ensure miter limit has sensible value */
if ( stroker->miter_limit < 0x10000 )
stroker->miter_limit = 0x10000;
/* save line join style: */
/* line join style can be temporarily changed when stroking curves */
stroker->line_join_saved = line_join;
FT_Stroker_Rewind( stroker );
}
/* documentation is in ftstroke.h */
FT_EXPORT_DEF( void )
FT_Stroker_Rewind( FT_Stroker stroker )
{
if ( stroker )
{
ft_stroke_border_reset( &stroker->borders[0] );
ft_stroke_border_reset( &stroker->borders[1] );
}
}
/* documentation is in ftstroke.h */
FT_EXPORT_DEF( void )
FT_Stroker_Done( FT_Stroker stroker )
{
if ( stroker )
{
FT_Memory memory = stroker->library->memory;
ft_stroke_border_done( &stroker->borders[0] );
ft_stroke_border_done( &stroker->borders[1] );
stroker->library = NULL;
FT_FREE( stroker );
}
}
/* create a circular arc at a corner or cap */
static FT_Error
ft_stroker_arcto( FT_Stroker stroker,
FT_Int side )
{
FT_Angle total, rotate;
FT_Fixed radius = stroker->radius;
FT_Error error = FT_Err_Ok;
FT_StrokeBorder border = stroker->borders + side;
rotate = FT_SIDE_TO_ROTATE( side );
total = FT_Angle_Diff( stroker->angle_in, stroker->angle_out );
if ( total == FT_ANGLE_PI )
total = -rotate * 2;
error = ft_stroke_border_arcto( border,
&stroker->center,
radius,
stroker->angle_in + rotate,
total );
border->movable = FALSE;
return error;
}
/* add a cap at the end of an opened path */
static FT_Error
ft_stroker_cap( FT_Stroker stroker,
FT_Angle angle,
FT_Int side )
{
FT_Error error = FT_Err_Ok;
if ( stroker->line_cap == FT_STROKER_LINECAP_ROUND )
{
/* add a round cap */
stroker->angle_in = angle;
stroker->angle_out = angle + FT_ANGLE_PI;
error = ft_stroker_arcto( stroker, side );
}
else if ( stroker->line_cap == FT_STROKER_LINECAP_SQUARE )
{
/* add a square cap */
FT_Vector delta, delta2;
FT_Angle rotate = FT_SIDE_TO_ROTATE( side );
FT_Fixed radius = stroker->radius;
FT_StrokeBorder border = stroker->borders + side;
FT_Vector_From_Polar( &delta2, radius, angle + rotate );
FT_Vector_From_Polar( &delta, radius, angle );
delta.x += stroker->center.x + delta2.x;
delta.y += stroker->center.y + delta2.y;
error = ft_stroke_border_lineto( border, &delta, FALSE );
if ( error )
goto Exit;
FT_Vector_From_Polar( &delta2, radius, angle - rotate );
FT_Vector_From_Polar( &delta, radius, angle );
delta.x += delta2.x + stroker->center.x;
delta.y += delta2.y + stroker->center.y;
error = ft_stroke_border_lineto( border, &delta, FALSE );
}
else if ( stroker->line_cap == FT_STROKER_LINECAP_BUTT )
{
/* add a butt ending */
FT_Vector delta;
FT_Angle rotate = FT_SIDE_TO_ROTATE( side );
FT_Fixed radius = stroker->radius;
FT_StrokeBorder border = stroker->borders + side;
FT_Vector_From_Polar( &delta, radius, angle + rotate );
delta.x += stroker->center.x;
delta.y += stroker->center.y;
error = ft_stroke_border_lineto( border, &delta, FALSE );
if ( error )
goto Exit;
FT_Vector_From_Polar( &delta, radius, angle - rotate );
delta.x += stroker->center.x;
delta.y += stroker->center.y;
error = ft_stroke_border_lineto( border, &delta, FALSE );
}
Exit:
return error;
}
/* process an inside corner, i.e. compute intersection */
static FT_Error
ft_stroker_inside( FT_Stroker stroker,
FT_Int side,
FT_Fixed line_length )
{
FT_StrokeBorder border = stroker->borders + side;
FT_Angle phi, theta, rotate;
FT_Fixed length, thcos;
FT_Vector delta;
FT_Error error = FT_Err_Ok;
FT_Bool intersect; /* use intersection of lines? */
rotate = FT_SIDE_TO_ROTATE( side );
theta = FT_Angle_Diff( stroker->angle_in, stroker->angle_out ) / 2;
/* Only intersect borders if between two lineto's and both */
/* lines are long enough (line_length is zero for curves). */
if ( !border->movable || line_length == 0 )
intersect = FALSE;
else
{
/* compute minimum required length of lines */
FT_Fixed min_length = ft_pos_abs( FT_MulFix( stroker->radius,
FT_Tan( theta ) ) );
intersect = FT_BOOL( stroker->line_length >= min_length &&
line_length >= min_length );
}
if ( !intersect )
{
FT_Vector_From_Polar( &delta, stroker->radius,
stroker->angle_out + rotate );
delta.x += stroker->center.x;
delta.y += stroker->center.y;
border->movable = FALSE;
}
else
{
/* compute median angle */
phi = stroker->angle_in + theta;
thcos = FT_Cos( theta );
length = FT_DivFix( stroker->radius, thcos );
FT_Vector_From_Polar( &delta, length, phi + rotate );
delta.x += stroker->center.x;
delta.y += stroker->center.y;
}
error = ft_stroke_border_lineto( border, &delta, FALSE );
return error;
}
/* process an outside corner, i.e. compute bevel/miter/round */
static FT_Error
ft_stroker_outside( FT_Stroker stroker,
FT_Int side,
FT_Fixed line_length )
{
FT_StrokeBorder border = stroker->borders + side;
FT_Error error;
FT_Angle rotate;
if ( stroker->line_join == FT_STROKER_LINEJOIN_ROUND )
error = ft_stroker_arcto( stroker, side );
else
{
/* this is a mitered (pointed) or beveled (truncated) corner */
FT_Fixed sigma = 0, radius = stroker->radius;
FT_Angle theta = 0, phi = 0;
FT_Fixed thcos = 0;
FT_Bool bevel, fixed_bevel;
rotate = FT_SIDE_TO_ROTATE( side );
bevel =
FT_BOOL( stroker->line_join == FT_STROKER_LINEJOIN_BEVEL );
fixed_bevel =
FT_BOOL( stroker->line_join != FT_STROKER_LINEJOIN_MITER_VARIABLE );
if ( !bevel )
{
theta = FT_Angle_Diff( stroker->angle_in, stroker->angle_out );
if ( theta == FT_ANGLE_PI )
{
theta = rotate;
phi = stroker->angle_in;
}
else
{
theta /= 2;
phi = stroker->angle_in + theta + rotate;
}
thcos = FT_Cos( theta );
sigma = FT_MulFix( stroker->miter_limit, thcos );
/* is miter limit exceeded? */
if ( sigma < 0x10000L )
{
/* don't create variable bevels for very small deviations; */
/* FT_Sin(x) = 0 for x <= 57 */
if ( fixed_bevel || ft_pos_abs( theta ) > 57 )
bevel = TRUE;
}
}
if ( bevel ) /* this is a bevel (broken angle) */
{
if ( fixed_bevel )
{
/* the outer corners are simply joined together */
FT_Vector delta;
/* add bevel */
FT_Vector_From_Polar( &delta,
radius,
stroker->angle_out + rotate );
delta.x += stroker->center.x;
delta.y += stroker->center.y;
border->movable = FALSE;
error = ft_stroke_border_lineto( border, &delta, FALSE );
}
else /* variable bevel */
{
/* the miter is truncated */
FT_Vector middle, delta;
FT_Fixed length;
/* compute middle point */
FT_Vector_From_Polar( &middle,
FT_MulFix( radius, stroker->miter_limit ),
phi );
middle.x += stroker->center.x;
middle.y += stroker->center.y;
/* compute first angle point */
length = FT_MulDiv( radius, 0x10000L - sigma,
ft_pos_abs( FT_Sin( theta ) ) );
FT_Vector_From_Polar( &delta, length, phi + rotate );
delta.x += middle.x;
delta.y += middle.y;
error = ft_stroke_border_lineto( border, &delta, FALSE );
if ( error )
goto Exit;
/* compute second angle point */
FT_Vector_From_Polar( &delta, length, phi - rotate );
delta.x += middle.x;
delta.y += middle.y;
error = ft_stroke_border_lineto( border, &delta, FALSE );
if ( error )
goto Exit;
/* finally, add an end point; only needed if not lineto */
/* (line_length is zero for curves) */
if ( line_length == 0 )
{
FT_Vector_From_Polar( &delta,
radius,
stroker->angle_out + rotate );
delta.x += stroker->center.x;
delta.y += stroker->center.y;
error = ft_stroke_border_lineto( border, &delta, FALSE );
}
}
}
else /* this is a miter (intersection) */
{
FT_Fixed length;
FT_Vector delta;
length = FT_DivFix( stroker->radius, thcos );
FT_Vector_From_Polar( &delta, length, phi );
delta.x += stroker->center.x;
delta.y += stroker->center.y;
error = ft_stroke_border_lineto( border, &delta, FALSE );
if ( error )
goto Exit;
/* now add an end point; only needed if not lineto */
/* (line_length is zero for curves) */
if ( line_length == 0 )
{
FT_Vector_From_Polar( &delta,
stroker->radius,
stroker->angle_out + rotate );
delta.x += stroker->center.x;
delta.y += stroker->center.y;
error = ft_stroke_border_lineto( border, &delta, FALSE );
}
}
}
Exit:
return error;
}
static FT_Error
ft_stroker_process_corner( FT_Stroker stroker,
FT_Fixed line_length )
{
FT_Error error = FT_Err_Ok;
FT_Angle turn;
FT_Int inside_side;
turn = FT_Angle_Diff( stroker->angle_in, stroker->angle_out );
/* no specific corner processing is required if the turn is 0 */
if ( turn == 0 )
goto Exit;
/* when we turn to the right, the inside side is 0 */
inside_side = 0;
/* otherwise, the inside side is 1 */
if ( turn < 0 )
inside_side = 1;
/* process the inside side */
error = ft_stroker_inside( stroker, inside_side, line_length );
if ( error )
goto Exit;
/* process the outside side */
error = ft_stroker_outside( stroker, 1 - inside_side, line_length );
Exit:
return error;
}
/* add two points to the left and right borders corresponding to the */
/* start of the subpath */
static FT_Error
ft_stroker_subpath_start( FT_Stroker stroker,
FT_Angle start_angle,
FT_Fixed line_length )
{
FT_Vector delta;
FT_Vector point;
FT_Error error;
FT_StrokeBorder border;
FT_Vector_From_Polar( &delta, stroker->radius,
start_angle + FT_ANGLE_PI2 );
point.x = stroker->center.x + delta.x;
point.y = stroker->center.y + delta.y;
border = stroker->borders;
error = ft_stroke_border_moveto( border, &point );
if ( error )
goto Exit;
point.x = stroker->center.x - delta.x;
point.y = stroker->center.y - delta.y;
border++;
error = ft_stroke_border_moveto( border, &point );
/* save angle, position, and line length for last join */
/* (line_length is zero for curves) */
stroker->subpath_angle = start_angle;
stroker->first_point = FALSE;
stroker->subpath_line_length = line_length;
Exit:
return error;
}
/* documentation is in ftstroke.h */
FT_EXPORT_DEF( FT_Error )
FT_Stroker_LineTo( FT_Stroker stroker,
FT_Vector* to )
{
FT_Error error = FT_Err_Ok;
FT_StrokeBorder border;
FT_Vector delta;
FT_Angle angle;
FT_Int side;
FT_Fixed line_length;
delta.x = to->x - stroker->center.x;
delta.y = to->y - stroker->center.y;
/* a zero-length lineto is a no-op; avoid creating a spurious corner */
if ( delta.x == 0 && delta.y == 0 )
goto Exit;
/* compute length of line */
line_length = FT_Vector_Length( &delta );
angle = FT_Atan2( delta.x, delta.y );
FT_Vector_From_Polar( &delta, stroker->radius, angle + FT_ANGLE_PI2 );
/* process corner if necessary */
if ( stroker->first_point )
{
/* This is the first segment of a subpath. We need to */
/* add a point to each border at their respective starting */
/* point locations. */
error = ft_stroker_subpath_start( stroker, angle, line_length );
if ( error )
goto Exit;
}
else
{
/* process the current corner */
stroker->angle_out = angle;
error = ft_stroker_process_corner( stroker, line_length );
if ( error )
goto Exit;
}
/* now add a line segment to both the `inside' and `outside' paths */
for ( border = stroker->borders, side = 1; side >= 0; side--, border++ )
{
FT_Vector point;
point.x = to->x + delta.x;
point.y = to->y + delta.y;
/* the ends of lineto borders are movable */
error = ft_stroke_border_lineto( border, &point, TRUE );
if ( error )
goto Exit;
delta.x = -delta.x;
delta.y = -delta.y;
}
stroker->angle_in = angle;
stroker->center = *to;
stroker->line_length = line_length;
Exit:
return error;
}
/* documentation is in ftstroke.h */
FT_EXPORT_DEF( FT_Error )
FT_Stroker_ConicTo( FT_Stroker stroker,
FT_Vector* control,
FT_Vector* to )
{
FT_Error error = FT_Err_Ok;
FT_Vector bez_stack[34];
FT_Vector* arc;
FT_Vector* limit = bez_stack + 30;
FT_Bool first_arc = TRUE;
/* if all control points are coincident, this is a no-op; */
/* avoid creating a spurious corner */
if ( FT_IS_SMALL( stroker->center.x - control->x ) &&
FT_IS_SMALL( stroker->center.y - control->y ) &&
FT_IS_SMALL( control->x - to->x ) &&
FT_IS_SMALL( control->y - to->y ) )
{
stroker->center = *to;
goto Exit;
}
arc = bez_stack;
arc[0] = *to;
arc[1] = *control;
arc[2] = stroker->center;
while ( arc >= bez_stack )
{
FT_Angle angle_in, angle_out;
/* initialize with current direction */
angle_in = angle_out = stroker->angle_in;
if ( arc < limit &&
!ft_conic_is_small_enough( arc, &angle_in, &angle_out ) )
{
if ( stroker->first_point )
stroker->angle_in = angle_in;
ft_conic_split( arc );
arc += 2;
continue;
}
if ( first_arc )
{
first_arc = FALSE;
/* process corner if necessary */
if ( stroker->first_point )
error = ft_stroker_subpath_start( stroker, angle_in, 0 );
else
{
stroker->angle_out = angle_in;
error = ft_stroker_process_corner( stroker, 0 );
}
}
else if ( ft_pos_abs( FT_Angle_Diff( stroker->angle_in, angle_in ) ) >
FT_SMALL_CONIC_THRESHOLD / 4 )
{
/* if the deviation from one arc to the next is too great, */
/* add a round corner */
stroker->center = arc[2];
stroker->angle_out = angle_in;
stroker->line_join = FT_STROKER_LINEJOIN_ROUND;
error = ft_stroker_process_corner( stroker, 0 );
/* reinstate line join style */
stroker->line_join = stroker->line_join_saved;
}
if ( error )
goto Exit;
/* the arc's angle is small enough; we can add it directly to each */
/* border */
{
FT_Vector ctrl, end;
FT_Angle theta, phi, rotate, alpha0 = 0;
FT_Fixed length;
FT_StrokeBorder border;
FT_Int side;
theta = FT_Angle_Diff( angle_in, angle_out ) / 2;
phi = angle_in + theta;
length = FT_DivFix( stroker->radius, FT_Cos( theta ) );
/* compute direction of original arc */
if ( stroker->handle_wide_strokes )
alpha0 = FT_Atan2( arc[0].x - arc[2].x, arc[0].y - arc[2].y );
for ( border = stroker->borders, side = 0;
side <= 1;
side++, border++ )
{
rotate = FT_SIDE_TO_ROTATE( side );
/* compute control point */
FT_Vector_From_Polar( &ctrl, length, phi + rotate );
ctrl.x += arc[1].x;
ctrl.y += arc[1].y;
/* compute end point */
FT_Vector_From_Polar( &end, stroker->radius, angle_out + rotate );
end.x += arc[0].x;
end.y += arc[0].y;
if ( stroker->handle_wide_strokes )
{
FT_Vector start;
FT_Angle alpha1;
/* determine whether the border radius is greater than the */
/* radius of curvature of the original arc */
start = border->points[border->num_points - 1];
alpha1 = FT_Atan2( end.x - start.x, end.y - start.y );
/* is the direction of the border arc opposite to */
/* that of the original arc? */
if ( ft_pos_abs( FT_Angle_Diff( alpha0, alpha1 ) ) >
FT_ANGLE_PI / 2 )
{
FT_Angle beta, gamma;
FT_Vector bvec, delta;
FT_Fixed blen, sinA, sinB, alen;
/* use the sine rule to find the intersection point */
beta = FT_Atan2( arc[2].x - start.x, arc[2].y - start.y );
gamma = FT_Atan2( arc[0].x - end.x, arc[0].y - end.y );
bvec.x = end.x - start.x;
bvec.y = end.y - start.y;
blen = FT_Vector_Length( &bvec );
sinA = ft_pos_abs( FT_Sin( alpha1 - gamma ) );
sinB = ft_pos_abs( FT_Sin( beta - gamma ) );
alen = FT_MulDiv( blen, sinA, sinB );
FT_Vector_From_Polar( &delta, alen, beta );
delta.x += start.x;
delta.y += start.y;
/* circumnavigate the negative sector backwards */
border->movable = FALSE;
error = ft_stroke_border_lineto( border, &delta, FALSE );
if ( error )
goto Exit;
error = ft_stroke_border_lineto( border, &end, FALSE );
if ( error )
goto Exit;
error = ft_stroke_border_conicto( border, &ctrl, &start );
if ( error )
goto Exit;
/* and then move to the endpoint */
error = ft_stroke_border_lineto( border, &end, FALSE );
if ( error )
goto Exit;
continue;
}
/* else fall through */
}
/* simply add an arc */
error = ft_stroke_border_conicto( border, &ctrl, &end );
if ( error )
goto Exit;
}
}
arc -= 2;
stroker->angle_in = angle_out;
}
stroker->center = *to;
Exit:
return error;
}
/* documentation is in ftstroke.h */
FT_EXPORT_DEF( FT_Error )
FT_Stroker_CubicTo( FT_Stroker stroker,
FT_Vector* control1,
FT_Vector* control2,
FT_Vector* to )
{
FT_Error error = FT_Err_Ok;
FT_Vector bez_stack[37];
FT_Vector* arc;
FT_Vector* limit = bez_stack + 32;
FT_Bool first_arc = TRUE;
/* if all control points are coincident, this is a no-op; */
/* avoid creating a spurious corner */
if ( FT_IS_SMALL( stroker->center.x - control1->x ) &&
FT_IS_SMALL( stroker->center.y - control1->y ) &&
FT_IS_SMALL( control1->x - control2->x ) &&
FT_IS_SMALL( control1->y - control2->y ) &&
FT_IS_SMALL( control2->x - to->x ) &&
FT_IS_SMALL( control2->y - to->y ) )
{
stroker->center = *to;
goto Exit;
}
arc = bez_stack;
arc[0] = *to;
arc[1] = *control2;
arc[2] = *control1;
arc[3] = stroker->center;
while ( arc >= bez_stack )
{
FT_Angle angle_in, angle_mid, angle_out;
/* initialize with current direction */
angle_in = angle_out = angle_mid = stroker->angle_in;
if ( arc < limit &&
!ft_cubic_is_small_enough( arc, &angle_in,
&angle_mid, &angle_out ) )
{
if ( stroker->first_point )
stroker->angle_in = angle_in;
ft_cubic_split( arc );
arc += 3;
continue;
}
if ( first_arc )
{
first_arc = FALSE;
/* process corner if necessary */
if ( stroker->first_point )
error = ft_stroker_subpath_start( stroker, angle_in, 0 );
else
{
stroker->angle_out = angle_in;
error = ft_stroker_process_corner( stroker, 0 );
}
}
else if ( ft_pos_abs( FT_Angle_Diff( stroker->angle_in, angle_in ) ) >
FT_SMALL_CUBIC_THRESHOLD / 4 )
{
/* if the deviation from one arc to the next is too great, */
/* add a round corner */
stroker->center = arc[3];
stroker->angle_out = angle_in;
stroker->line_join = FT_STROKER_LINEJOIN_ROUND;
error = ft_stroker_process_corner( stroker, 0 );
/* reinstate line join style */
stroker->line_join = stroker->line_join_saved;
}
if ( error )
goto Exit;
/* the arc's angle is small enough; we can add it directly to each */
/* border */
{
FT_Vector ctrl1, ctrl2, end;
FT_Angle theta1, phi1, theta2, phi2, rotate, alpha0 = 0;
FT_Fixed length1, length2;
FT_StrokeBorder border;
FT_Int side;
theta1 = FT_Angle_Diff( angle_in, angle_mid ) / 2;
theta2 = FT_Angle_Diff( angle_mid, angle_out ) / 2;
phi1 = ft_angle_mean( angle_in, angle_mid );
phi2 = ft_angle_mean( angle_mid, angle_out );
length1 = FT_DivFix( stroker->radius, FT_Cos( theta1 ) );
length2 = FT_DivFix( stroker->radius, FT_Cos( theta2 ) );
/* compute direction of original arc */
if ( stroker->handle_wide_strokes )
alpha0 = FT_Atan2( arc[0].x - arc[3].x, arc[0].y - arc[3].y );
for ( border = stroker->borders, side = 0;
side <= 1;
side++, border++ )
{
rotate = FT_SIDE_TO_ROTATE( side );
/* compute control points */
FT_Vector_From_Polar( &ctrl1, length1, phi1 + rotate );
ctrl1.x += arc[2].x;
ctrl1.y += arc[2].y;
FT_Vector_From_Polar( &ctrl2, length2, phi2 + rotate );
ctrl2.x += arc[1].x;
ctrl2.y += arc[1].y;
/* compute end point */
FT_Vector_From_Polar( &end, stroker->radius, angle_out + rotate );
end.x += arc[0].x;
end.y += arc[0].y;
if ( stroker->handle_wide_strokes )
{
FT_Vector start;
FT_Angle alpha1;
/* determine whether the border radius is greater than the */
/* radius of curvature of the original arc */
start = border->points[border->num_points - 1];
alpha1 = FT_Atan2( end.x - start.x, end.y - start.y );
/* is the direction of the border arc opposite to */
/* that of the original arc? */
if ( ft_pos_abs( FT_Angle_Diff( alpha0, alpha1 ) ) >
FT_ANGLE_PI / 2 )
{
FT_Angle beta, gamma;
FT_Vector bvec, delta;
FT_Fixed blen, sinA, sinB, alen;
/* use the sine rule to find the intersection point */
beta = FT_Atan2( arc[3].x - start.x, arc[3].y - start.y );
gamma = FT_Atan2( arc[0].x - end.x, arc[0].y - end.y );
bvec.x = end.x - start.x;
bvec.y = end.y - start.y;
blen = FT_Vector_Length( &bvec );
sinA = ft_pos_abs( FT_Sin( alpha1 - gamma ) );
sinB = ft_pos_abs( FT_Sin( beta - gamma ) );
alen = FT_MulDiv( blen, sinA, sinB );
FT_Vector_From_Polar( &delta, alen, beta );
delta.x += start.x;
delta.y += start.y;
/* circumnavigate the negative sector backwards */
border->movable = FALSE;
error = ft_stroke_border_lineto( border, &delta, FALSE );
if ( error )
goto Exit;
error = ft_stroke_border_lineto( border, &end, FALSE );
if ( error )
goto Exit;
error = ft_stroke_border_cubicto( border,
&ctrl2,
&ctrl1,
&start );
if ( error )
goto Exit;
/* and then move to the endpoint */
error = ft_stroke_border_lineto( border, &end, FALSE );
if ( error )
goto Exit;
continue;
}
/* else fall through */
}
/* simply add an arc */
error = ft_stroke_border_cubicto( border, &ctrl1, &ctrl2, &end );
if ( error )
goto Exit;
}
}
arc -= 3;
stroker->angle_in = angle_out;
}
stroker->center = *to;
Exit:
return error;
}
/* documentation is in ftstroke.h */
FT_EXPORT_DEF( FT_Error )
FT_Stroker_BeginSubPath( FT_Stroker stroker,
FT_Vector* to,
FT_Bool open )
{
/* We cannot process the first point, because there is not enough */
/* information regarding its corner/cap. The latter will be processed */
/* in the `FT_Stroker_EndSubPath' routine. */
/* */
stroker->first_point = TRUE;
stroker->center = *to;
stroker->subpath_open = open;
/* Determine if we need to check whether the border radius is greater */
/* than the radius of curvature of a curve, to handle this case */
/* specially. This is only required if bevel joins or butt caps may */
/* be created, because round & miter joins and round & square caps */
/* cover the negative sector created with wide strokes. */
stroker->handle_wide_strokes =
FT_BOOL( stroker->line_join != FT_STROKER_LINEJOIN_ROUND ||
( stroker->subpath_open &&
stroker->line_cap == FT_STROKER_LINECAP_BUTT ) );
/* record the subpath start point for each border */
stroker->subpath_start = *to;
stroker->angle_in = 0;
return FT_Err_Ok;
}
static FT_Error
ft_stroker_add_reverse_left( FT_Stroker stroker,
FT_Bool open )
{
FT_StrokeBorder right = stroker->borders + 0;
FT_StrokeBorder left = stroker->borders + 1;
FT_Int new_points;
FT_Error error = FT_Err_Ok;
FT_ASSERT( left->start >= 0 );
new_points = left->num_points - left->start;
if ( new_points > 0 )
{
error = ft_stroke_border_grow( right, (FT_UInt)new_points );
if ( error )
goto Exit;
{
FT_Vector* dst_point = right->points + right->num_points;
FT_Byte* dst_tag = right->tags + right->num_points;
FT_Vector* src_point = left->points + left->num_points - 1;
FT_Byte* src_tag = left->tags + left->num_points - 1;
while ( src_point >= left->points + left->start )
{
*dst_point = *src_point;
*dst_tag = *src_tag;
if ( open )
dst_tag[0] &= ~FT_STROKE_TAG_BEGIN_END;
else
{
FT_Byte ttag =
(FT_Byte)( dst_tag[0] & FT_STROKE_TAG_BEGIN_END );
/* switch begin/end tags if necessary */
if ( ttag == FT_STROKE_TAG_BEGIN ||
ttag == FT_STROKE_TAG_END )
dst_tag[0] ^= FT_STROKE_TAG_BEGIN_END;
}
src_point--;
src_tag--;
dst_point++;
dst_tag++;
}
}
left->num_points = left->start;
right->num_points += new_points;
right->movable = FALSE;
left->movable = FALSE;
}
Exit:
return error;
}
/* documentation is in ftstroke.h */
/* there's a lot of magic in this function! */
FT_EXPORT_DEF( FT_Error )
FT_Stroker_EndSubPath( FT_Stroker stroker )
{
FT_Error error = FT_Err_Ok;
if ( stroker->subpath_open )
{
FT_StrokeBorder right = stroker->borders;
/* All right, this is an opened path, we need to add a cap between */
/* right & left, add the reverse of left, then add a final cap */
/* between left & right. */
error = ft_stroker_cap( stroker, stroker->angle_in, 0 );
if ( error )
goto Exit;
/* add reversed points from `left' to `right' */
error = ft_stroker_add_reverse_left( stroker, TRUE );
if ( error )
goto Exit;
/* now add the final cap */
stroker->center = stroker->subpath_start;
error = ft_stroker_cap( stroker,
stroker->subpath_angle + FT_ANGLE_PI, 0 );
if ( error )
goto Exit;
/* Now end the right subpath accordingly. The left one is */
/* rewind and doesn't need further processing. */
ft_stroke_border_close( right, FALSE );
}
else
{
FT_Angle turn;
FT_Int inside_side;
/* close the path if needed */
if ( stroker->center.x != stroker->subpath_start.x ||
stroker->center.y != stroker->subpath_start.y )
{
error = FT_Stroker_LineTo( stroker, &stroker->subpath_start );
if ( error )
goto Exit;
}
/* process the corner */
stroker->angle_out = stroker->subpath_angle;
turn = FT_Angle_Diff( stroker->angle_in,
stroker->angle_out );
/* no specific corner processing is required if the turn is 0 */
if ( turn != 0 )
{
/* when we turn to the right, the inside side is 0 */
inside_side = 0;
/* otherwise, the inside side is 1 */
if ( turn < 0 )
inside_side = 1;
error = ft_stroker_inside( stroker,
inside_side,
stroker->subpath_line_length );
if ( error )
goto Exit;
/* process the outside side */
error = ft_stroker_outside( stroker,
1 - inside_side,
stroker->subpath_line_length );
if ( error )
goto Exit;
}
/* then end our two subpaths */
ft_stroke_border_close( stroker->borders + 0, FALSE );
ft_stroke_border_close( stroker->borders + 1, TRUE );
}
Exit:
return error;
}
/* documentation is in ftstroke.h */
FT_EXPORT_DEF( FT_Error )
FT_Stroker_GetBorderCounts( FT_Stroker stroker,
FT_StrokerBorder border,
FT_UInt *anum_points,
FT_UInt *anum_contours )
{
FT_UInt num_points = 0, num_contours = 0;
FT_Error error;
if ( !stroker || border > 1 )
{
error = FT_THROW( Invalid_Argument );
goto Exit;
}
error = ft_stroke_border_get_counts( stroker->borders + border,
&num_points, &num_contours );
Exit:
if ( anum_points )
*anum_points = num_points;
if ( anum_contours )
*anum_contours = num_contours;
return error;
}
/* documentation is in ftstroke.h */
FT_EXPORT_DEF( FT_Error )
FT_Stroker_GetCounts( FT_Stroker stroker,
FT_UInt *anum_points,
FT_UInt *anum_contours )
{
FT_UInt count1, count2, num_points = 0;
FT_UInt count3, count4, num_contours = 0;
FT_Error error;
error = ft_stroke_border_get_counts( stroker->borders + 0,
&count1, &count2 );
if ( error )
goto Exit;
error = ft_stroke_border_get_counts( stroker->borders + 1,
&count3, &count4 );
if ( error )
goto Exit;
num_points = count1 + count3;
num_contours = count2 + count4;
Exit:
*anum_points = num_points;
*anum_contours = num_contours;
return error;
}
/* documentation is in ftstroke.h */
FT_EXPORT_DEF( void )
FT_Stroker_ExportBorder( FT_Stroker stroker,
FT_StrokerBorder border,
FT_Outline* outline )
{
if ( border == FT_STROKER_BORDER_LEFT ||
border == FT_STROKER_BORDER_RIGHT )
{
FT_StrokeBorder sborder = & stroker->borders[border];
if ( sborder->valid )
ft_stroke_border_export( sborder, outline );
}
}
/* documentation is in ftstroke.h */
FT_EXPORT_DEF( void )
FT_Stroker_Export( FT_Stroker stroker,
FT_Outline* outline )
{
FT_Stroker_ExportBorder( stroker, FT_STROKER_BORDER_LEFT, outline );
FT_Stroker_ExportBorder( stroker, FT_STROKER_BORDER_RIGHT, outline );
}
/* documentation is in ftstroke.h */
/*
* The following is very similar to FT_Outline_Decompose, except
* that we do support opened paths, and do not scale the outline.
*/
FT_EXPORT_DEF( FT_Error )
FT_Stroker_ParseOutline( FT_Stroker stroker,
FT_Outline* outline,
FT_Bool opened )
{
FT_Vector v_last;
FT_Vector v_control;
FT_Vector v_start;
FT_Vector* point;
FT_Vector* limit;
char* tags;
FT_Error error;
FT_Int n; /* index of contour in outline */
FT_UInt first; /* index of first point in contour */
FT_Int tag; /* current point's state */
if ( !outline || !stroker )
return FT_THROW( Invalid_Argument );
FT_Stroker_Rewind( stroker );
first = 0;
for ( n = 0; n < outline->n_contours; n++ )
{
FT_UInt last; /* index of last point in contour */
last = outline->contours[n];
limit = outline->points + last;
/* skip empty points; we don't stroke these */
if ( last <= first )
{
first = last + 1;
continue;
}
v_start = outline->points[first];
v_last = outline->points[last];
v_control = v_start;
point = outline->points + first;
tags = outline->tags + first;
tag = FT_CURVE_TAG( tags[0] );
/* A contour cannot start with a cubic control point! */
if ( tag == FT_CURVE_TAG_CUBIC )
goto Invalid_Outline;
/* check first point to determine origin */
if ( tag == FT_CURVE_TAG_CONIC )
{
/* First point is conic control. Yes, this happens. */
if ( FT_CURVE_TAG( outline->tags[last] ) == FT_CURVE_TAG_ON )
{
/* start at last point if it is on the curve */
v_start = v_last;
limit--;
}
else
{
/* if both first and last points are conic, */
/* start at their middle */
v_start.x = ( v_start.x + v_last.x ) / 2;
v_start.y = ( v_start.y + v_last.y ) / 2;
}
point--;
tags--;
}
error = FT_Stroker_BeginSubPath( stroker, &v_start, opened );
if ( error )
goto Exit;
while ( point < limit )
{
point++;
tags++;
tag = FT_CURVE_TAG( tags[0] );
switch ( tag )
{
case FT_CURVE_TAG_ON: /* emit a single line_to */
{
FT_Vector vec;
vec.x = point->x;
vec.y = point->y;
error = FT_Stroker_LineTo( stroker, &vec );
if ( error )
goto Exit;
continue;
}
case FT_CURVE_TAG_CONIC: /* consume conic arcs */
v_control.x = point->x;
v_control.y = point->y;
Do_Conic:
if ( point < limit )
{
FT_Vector vec;
FT_Vector v_middle;
point++;
tags++;
tag = FT_CURVE_TAG( tags[0] );
vec = point[0];
if ( tag == FT_CURVE_TAG_ON )
{
error = FT_Stroker_ConicTo( stroker, &v_control, &vec );
if ( error )
goto Exit;
continue;
}
if ( tag != FT_CURVE_TAG_CONIC )
goto Invalid_Outline;
v_middle.x = ( v_control.x + vec.x ) / 2;
v_middle.y = ( v_control.y + vec.y ) / 2;
error = FT_Stroker_ConicTo( stroker, &v_control, &v_middle );
if ( error )
goto Exit;
v_control = vec;
goto Do_Conic;
}
error = FT_Stroker_ConicTo( stroker, &v_control, &v_start );
goto Close;
default: /* FT_CURVE_TAG_CUBIC */
{
FT_Vector vec1, vec2;
if ( point + 1 > limit ||
FT_CURVE_TAG( tags[1] ) != FT_CURVE_TAG_CUBIC )
goto Invalid_Outline;
point += 2;
tags += 2;
vec1 = point[-2];
vec2 = point[-1];
if ( point <= limit )
{
FT_Vector vec;
vec = point[0];
error = FT_Stroker_CubicTo( stroker, &vec1, &vec2, &vec );
if ( error )
goto Exit;
continue;
}
error = FT_Stroker_CubicTo( stroker, &vec1, &vec2, &v_start );
goto Close;
}
}
}
Close:
if ( error )
goto Exit;
/* don't try to end the path if no segments have been generated */
if ( !stroker->first_point )
{
error = FT_Stroker_EndSubPath( stroker );
if ( error )
goto Exit;
}
first = last + 1;
}
return FT_Err_Ok;
Exit:
return error;
Invalid_Outline:
return FT_THROW( Invalid_Outline );
}
/* declare an extern to access `ft_outline_glyph_class' globally */
/* allocated in `ftglyph.c', and use the FT_OUTLINE_GLYPH_CLASS_GET */
/* macro to access it when FT_CONFIG_OPTION_PIC is defined */
#ifndef FT_CONFIG_OPTION_PIC
extern const FT_Glyph_Class ft_outline_glyph_class;
#endif
#include "basepic.h"
/* documentation is in ftstroke.h */
FT_EXPORT_DEF( FT_Error )
FT_Glyph_Stroke( FT_Glyph *pglyph,
FT_Stroker stroker,
FT_Bool destroy )
{
FT_Error error = FT_ERR( Invalid_Argument );
FT_Glyph glyph = NULL;
FT_Library library = stroker->library;
FT_UNUSED( library );
if ( pglyph == NULL )
goto Exit;
glyph = *pglyph;
if ( glyph == NULL || glyph->clazz != FT_OUTLINE_GLYPH_CLASS_GET )
goto Exit;
{
FT_Glyph copy;
error = FT_Glyph_Copy( glyph, © );
if ( error )
goto Exit;
glyph = copy;
}
{
FT_OutlineGlyph oglyph = (FT_OutlineGlyph)glyph;
FT_Outline* outline = &oglyph->outline;
FT_UInt num_points, num_contours;
error = FT_Stroker_ParseOutline( stroker, outline, FALSE );
if ( error )
goto Fail;
(void)FT_Stroker_GetCounts( stroker, &num_points, &num_contours );
FT_Outline_Done( glyph->library, outline );
error = FT_Outline_New( glyph->library,
num_points, num_contours, outline );
if ( error )
goto Fail;
outline->n_points = 0;
outline->n_contours = 0;
FT_Stroker_Export( stroker, outline );
}
if ( destroy )
FT_Done_Glyph( *pglyph );
*pglyph = glyph;
goto Exit;
Fail:
FT_Done_Glyph( glyph );
glyph = NULL;
if ( !destroy )
*pglyph = NULL;
Exit:
return error;
}
/* documentation is in ftstroke.h */
FT_EXPORT_DEF( FT_Error )
FT_Glyph_StrokeBorder( FT_Glyph *pglyph,
FT_Stroker stroker,
FT_Bool inside,
FT_Bool destroy )
{
FT_Error error = FT_ERR( Invalid_Argument );
FT_Glyph glyph = NULL;
FT_Library library = stroker->library;
FT_UNUSED( library );
if ( pglyph == NULL )
goto Exit;
glyph = *pglyph;
if ( glyph == NULL || glyph->clazz != FT_OUTLINE_GLYPH_CLASS_GET )
goto Exit;
{
FT_Glyph copy;
error = FT_Glyph_Copy( glyph, © );
if ( error )
goto Exit;
glyph = copy;
}
{
FT_OutlineGlyph oglyph = (FT_OutlineGlyph)glyph;
FT_StrokerBorder border;
FT_Outline* outline = &oglyph->outline;
FT_UInt num_points, num_contours;
border = FT_Outline_GetOutsideBorder( outline );
if ( inside )
{
if ( border == FT_STROKER_BORDER_LEFT )
border = FT_STROKER_BORDER_RIGHT;
else
border = FT_STROKER_BORDER_LEFT;
}
error = FT_Stroker_ParseOutline( stroker, outline, FALSE );
if ( error )
goto Fail;
(void)FT_Stroker_GetBorderCounts( stroker, border,
&num_points, &num_contours );
FT_Outline_Done( glyph->library, outline );
error = FT_Outline_New( glyph->library,
num_points,
num_contours,
outline );
if ( error )
goto Fail;
outline->n_points = 0;
outline->n_contours = 0;
FT_Stroker_ExportBorder( stroker, border, outline );
}
if ( destroy )
FT_Done_Glyph( *pglyph );
*pglyph = glyph;
goto Exit;
Fail:
FT_Done_Glyph( glyph );
glyph = NULL;
if ( !destroy )
*pglyph = NULL;
Exit:
return error;
}
/* END */
| YifuLiu/AliOS-Things | components/freetype/src/base/ftstroke.c | C | apache-2.0 | 66,181 |
/***************************************************************************/
/* */
/* ftsynth.c */
/* */
/* FreeType synthesizing code for emboldening and slanting (body). */
/* */
/* Copyright 2000-2006, 2010, 2012, 2013 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. */
/* */
/***************************************************************************/
#include <ft2build.h>
#include FT_SYNTHESIS_H
#include FT_INTERNAL_DEBUG_H
#include FT_INTERNAL_OBJECTS_H
#include FT_OUTLINE_H
#include FT_BITMAP_H
/*************************************************************************/
/* */
/* The macro FT_COMPONENT is used in trace mode. It is an implicit */
/* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */
/* messages during execution. */
/* */
#undef FT_COMPONENT
#define FT_COMPONENT trace_synth
/*************************************************************************/
/*************************************************************************/
/**** ****/
/**** EXPERIMENTAL OBLIQUING SUPPORT ****/
/**** ****/
/*************************************************************************/
/*************************************************************************/
/* documentation is in ftsynth.h */
FT_EXPORT_DEF( void )
FT_GlyphSlot_Oblique( FT_GlyphSlot slot )
{
FT_Matrix transform;
FT_Outline* outline = &slot->outline;
/* only oblique outline glyphs */
if ( slot->format != FT_GLYPH_FORMAT_OUTLINE )
return;
/* we don't touch the advance width */
/* For italic, simply apply a shear transform, with an angle */
/* of about 12 degrees. */
transform.xx = 0x10000L;
transform.yx = 0x00000L;
transform.xy = 0x0366AL;
transform.yy = 0x10000L;
FT_Outline_Transform( outline, &transform );
}
/*************************************************************************/
/*************************************************************************/
/**** ****/
/**** EXPERIMENTAL EMBOLDENING SUPPORT ****/
/**** ****/
/*************************************************************************/
/*************************************************************************/
/* documentation is in ftsynth.h */
FT_EXPORT_DEF( void )
FT_GlyphSlot_Embolden( FT_GlyphSlot slot )
{
FT_Library library = slot->library;
FT_Face face = slot->face;
FT_Error error;
FT_Pos xstr, ystr;
if ( slot->format != FT_GLYPH_FORMAT_OUTLINE &&
slot->format != FT_GLYPH_FORMAT_BITMAP )
return;
/* some reasonable strength */
xstr = FT_MulFix( face->units_per_EM,
face->size->metrics.y_scale ) / 24;
ystr = xstr;
if ( slot->format == FT_GLYPH_FORMAT_OUTLINE )
{
/* ignore error */
(void)FT_Outline_EmboldenXY( &slot->outline, xstr, ystr );
}
else /* slot->format == FT_GLYPH_FORMAT_BITMAP */
{
/* round to full pixels */
xstr &= ~63;
if ( xstr == 0 )
xstr = 1 << 6;
ystr &= ~63;
/*
* XXX: overflow check for 16-bit system, for compatibility
* with FT_GlyphSlot_Embolden() since freetype-2.1.10.
* unfortunately, this function return no informations
* about the cause of error.
*/
if ( ( ystr >> 6 ) > FT_INT_MAX || ( ystr >> 6 ) < FT_INT_MIN )
{
FT_TRACE1(( "FT_GlyphSlot_Embolden:" ));
FT_TRACE1(( "too strong embolding parameter ystr=%d\n", ystr ));
return;
}
error = FT_GlyphSlot_Own_Bitmap( slot );
if ( error )
return;
error = FT_Bitmap_Embolden( library, &slot->bitmap, xstr, ystr );
if ( error )
return;
}
if ( slot->advance.x )
slot->advance.x += xstr;
if ( slot->advance.y )
slot->advance.y += ystr;
slot->metrics.width += xstr;
slot->metrics.height += ystr;
slot->metrics.horiAdvance += xstr;
slot->metrics.vertAdvance += ystr;
slot->metrics.horiBearingY += ystr;
/* XXX: 16-bit overflow case must be excluded before here */
if ( slot->format == FT_GLYPH_FORMAT_BITMAP )
slot->bitmap_top += (FT_Int)( ystr >> 6 );
}
/* END */
| YifuLiu/AliOS-Things | components/freetype/src/base/ftsynth.c | C | apache-2.0 | 5,688 |