📄 ftcommon.i
字号:
/****************************************************************************//* *//* The FreeType project -- a free and portable quality TrueType renderer. *//* *//* Copyright 1996-2000, 2001, 2002, 2003, 2004, 2005 by *//* D. Turner, R.Wilhelm, and W. Lemberg *//* *//* *//* ftcommon.i - common routines for the FreeType demo programs. *//* *//****************************************************************************/#include <ft2build.h>#include FT_FREETYPE_H#include FT_CACHE_H#include FT_CACHE_MANAGER_H#include FT_STROKER_H#include FT_BITMAP_H#include FT_SYNTHESIS_H /* the following header shouldn't be used in normal programs */#include FT_INTERNAL_DEBUG_H#include "common.h"#include <stdio.h>#include <stdlib.h>#include <string.h>#include <stdarg.h> /* forward declarations */ extern void PanicZ( const char* message ); FT_Error error; FT_Bitmap ft_bitmap; /*************************************************************************/ /*************************************************************************/ /***** *****/ /***** DISPLAY-SPECIFIC DEFINITIONS *****/ /***** *****/ /*************************************************************************/ /*************************************************************************/#include "graph.h"#include "grfont.h"#define DIM_X 500#define DIM_Y 400#define CENTER_X ( bit.width / 2 )#define CENTER_Y ( bit.rows / 2 )#define MAXPTSIZE 500 /* dtp */ char Header[128]; char* new_header = 0; const unsigned char* Text = (unsigned char*) "The quick brown fox jumps over the lazy dog 0123456789 " "\342\352\356\373\364\344\353\357\366\374\377\340\371\351\350\347 " "&#~\"\'(-`_^@)=+\260 ABCDEFGHIJKLMNOPQRSTUVWXYZ " "$\243^\250*\265\371%!\247:/;.,?<>"; grSurface* surface; /* current display surface */ grBitmap bit; /* current display bitmap */ static grColor fore_color = { 0 }; int Fail; int graph_init = 0; double the_gamma = 1.0; enum { RENDER_MODE_ALL = 0, RENDER_MODE_EMBOLDEN, RENDER_MODE_STROKE, RENDER_MODE_TEXT, RENDER_MODE_WATERFALL, RENDER_MODE_GAMMAGRID /* this mode must be the last one */ } render_mode = 0; int debug = 0; int trace_level = 0;#define RASTER_BUFF_SIZE 32768 char raster_buff[RASTER_BUFF_SIZE];#undef NODEBUG#ifndef NODEBUG#define LOG( x ) LogMessage##x void LogMessage( const char* fmt, ... ) { va_list ap; va_start( ap, fmt ); vfprintf( stderr, fmt, ap ); va_end( ap ); }#else /* !DEBUG */#define LOG( x ) /* */#endif /* PanicZ */ void PanicZ( const char* message ) { fprintf( stderr, "%s\n error = 0x%04x\n", message, error ); exit( 1 ); } /* clear the `bit' bitmap/pixmap */ static void Clear_Display( void ) { long image_size = (long)bit.pitch * bit.rows; if ( image_size < 0 ) image_size = -image_size; memset( bit.buffer, 255, image_size ); } /* initialize the display bitmap `bit' */ static void Init_Display( void ) { grInitDevices(); bit.mode = gr_pixel_mode_rgb24; bit.width = DIM_X; bit.rows = DIM_Y; bit.grays = 256; surface = grNewSurface( 0, &bit ); if ( !surface ) PanicZ( "could not allocate display surface\n" ); grSetGlyphGamma( the_gamma ); graph_init = 1; }#define MAX_BUFFER 300000 /*************************************************************************/ /*************************************************************************/ /***** *****/ /***** FREETYPE-SPECIFIC DEFINITIONS *****/ /***** *****/ /*************************************************************************/ /*************************************************************************/ FT_Library library; /* the FreeType library */ FTC_Manager cache_manager; /* the cache manager */ FTC_ImageCache image_cache; /* the glyph image cache */ FTC_SBitCache sbits_cache; /* the glyph small bitmaps cache */ FTC_CMapCache cmap_cache; /* the charmap cache.. */ FT_Face face; /* the font face */ FT_Size size; /* the font size */ FT_GlyphSlot glyph; /* the glyph slot */ FTC_ImageTypeRec current_font; int dump_cache_stats = 0; /* do we need to dump cache statistics? */ int use_sbits_cache = 1; int num_indices; /* number of glyphs or characters */ int ptsize; /* current point size */ FT_Encoding encoding = FT_ENCODING_NONE; int hinted = 1; /* is glyph hinting active? */ int antialias = 1; /* is anti-aliasing active? */ int use_sbits = 1; /* do we use embedded bitmaps? */ int low_prec = 0; /* force low precision */ int autohint = 0; /* force auto-hinting */ int lcd_mode = 0; /* 0 - 5 */ int Num; /* current first index */ int res = 72;#define MAX_GLYPH_BYTES 150000 /* 150kB for the glyph image cache */#define FLOOR( x ) ( (x) & -64 )#define CEIL( x ) ( ( (x) + 63 ) & -64 )#define TRUNC( x ) ( (x) >> 6 ) /* this simple record is used to model a given `installed' face */ typedef struct TFont_ { const char* filepathname; int face_index; int cmap_index; int num_indices; } TFont, *PFont; static PFont* fonts = NULL; static int num_fonts; static int max_fonts = 0; static const char* file_suffixes[] = { ".ttf", ".ttc", ".otf", ".pfa", ".pfb", 0 }; static unsigned long make_tag( char *s ) { int i; unsigned long l = 0; for ( i = 0; i < 4; i++ ) { if ( !s[i] ) break; l <<= 8; l += (unsigned long)s[i]; } return l; } static int install_font_file( char* filepath ) { static char filename[1024 + 5]; int i, len, suffix_len, num_faces; const char** suffix; len = strlen( filepath ); if ( len > 1024 ) len = 1024; strncpy( filename, filepath, len ); filename[len] = 0; error = FT_New_Face( library, filename, 0, &face ); if ( !error ) goto Success; /* could not open the file directly; we will now try various */ /* suffixes like `.ttf' or `.pfb' */#ifndef macintosh suffix = file_suffixes; suffix_len = 0; i = len - 1; while ( i > 0 && filename[i] != '\\' && filename[i] != '/' ) { if ( filename[i] == '.' ) { suffix_len = i; break; } i--; } if ( suffix_len == 0 ) { for ( suffix = file_suffixes; suffix[0]; suffix++ ) { /* try with current suffix */ strcpy( filename + len, suffix[0] ); error = FT_New_Face( library, filename, 0, &face ); if ( !error ) goto Success; } }#endif /* !macintosh */ /* really couldn't open this file */ return -1; Success: /* allocate new font object */ num_faces = face->num_faces; for ( i = 0; i < num_faces; i++ ) { PFont font; if ( i > 0 ) { error = FT_New_Face( library, filename, i, &face ); if ( error ) continue; } if ( encoding != FT_ENCODING_NONE ) { error = FT_Select_Charmap( face, encoding ); if ( error ) { FT_Done_Face( face ); face = NULL; continue; } } font = (PFont)malloc( sizeof ( *font ) ); font->filepathname = (char*)malloc( strlen( filename ) + 1 ); font->face_index = i; font->cmap_index = face->charmap ? FT_Get_Charmap_Index( face->charmap ) : 0; switch ( encoding ) { case FT_ENCODING_NONE: font->num_indices = face->num_glyphs; break; case FT_ENCODING_UNICODE: font->num_indices = 0x110000L; break; case FT_ENCODING_MS_SYMBOL: case FT_ENCODING_ADOBE_LATIN_1: case FT_ENCODING_ADOBE_STANDARD: case FT_ENCODING_ADOBE_EXPERT: case FT_ENCODING_ADOBE_CUSTOM: case FT_ENCODING_APPLE_ROMAN: font->num_indices = 0x100L; break; default: font->num_indices = 0x10000L; } strcpy( (char*)font->filepathname, filename ); FT_Done_Face( face ); face = NULL; if ( max_fonts == 0 ) { max_fonts = 16; fonts = (PFont*)calloc( max_fonts, sizeof ( PFont ) ); } else if ( num_fonts >= max_fonts )
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -