本文整理汇总了C++中FT_Init_FreeType函数的典型用法代码示例。如果您正苦于以下问题:C++ FT_Init_FreeType函数的具体用法?C++ FT_Init_FreeType怎么用?C++ FT_Init_FreeType使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了FT_Init_FreeType函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char *argv[]) {
int i, j, err, size, first=' ', last='~',
bitmapOffset = 0, x, y, byte;
char *fontName, c, *ptr;
FT_Library library;
FT_Face face;
FT_Glyph glyph;
FT_Bitmap *bitmap;
FT_BitmapGlyphRec *g;
GFXglyph *table;
uint8_t bit;
// Parse command line. Valid syntaxes are:
// fontconvert [filename] [size]
// fontconvert [filename] [size] [last char]
// fontconvert [filename] [size] [first char] [last char]
// Unless overridden, default first and last chars are
// ' ' (space) and '~', respectively
if(argc < 3) {
fprintf(stderr, "Usage: %s fontfile size [first] [last]\n",
argv[0]);
return 1;
}
size = atoi(argv[2]);
if(argc == 4) {
last = atoi(argv[3]);
} else if(argc == 5) {
first = atoi(argv[3]);
last = atoi(argv[4]);
}
if(last < first) {
i = first;
first = last;
last = i;
}
ptr = strrchr(argv[1], '/'); // Find last slash in filename
if(ptr) ptr++; // First character of filename (path stripped)
else ptr = argv[1]; // No path; font in local dir.
// Allocate space for font name and glyph table
if((!(fontName = malloc(strlen(ptr) + 20))) ||
(!(table = (GFXglyph *)malloc((last - first + 1) *
sizeof(GFXglyph))))) {
fprintf(stderr, "Malloc error\n");
return 1;
}
// Derive font table names from filename. Period (filename
// extension) is truncated and replaced with the font size & bits.
strcpy(fontName, ptr);
ptr = strrchr(fontName, '.'); // Find last period (file ext)
if(!ptr) ptr = &fontName[strlen(fontName)]; // If none, append
// Insert font size and 7/8 bit. fontName was alloc'd w/extra
// space to allow this, we're not sprintfing into Forbidden Zone.
sprintf(ptr, "%dpt%db", size, (last > 127) ? 8 : 7);
// Space and punctuation chars in name replaced w/ underscores.
for(i=0; (c=fontName[i]); i++) {
if(isspace(c) || ispunct(c)) fontName[i] = '_';
}
// Init FreeType lib, load font
if((err = FT_Init_FreeType(&library))) {
fprintf(stderr, "FreeType init error: %d", err);
return err;
}
if((err = FT_New_Face(library, argv[1], 0, &face))) {
fprintf(stderr, "Font load error: %d", err);
FT_Done_FreeType(library);
return err;
}
// << 6 because '26dot6' fixed-point format
FT_Set_Char_Size(face, size << 6, 0, DPI, 0);
// Currently all symbols from 'first' to 'last' are processed.
// Fonts may contain WAY more glyphs than that, but this code
// will need to handle encoding stuff to deal with extracting
// the right symbols, and that's not done yet.
// fprintf(stderr, "%ld glyphs\n", face->num_glyphs);
printf("package Giza.Bitmap_Fonts.%s is\n\n", fontName);
printf(" %sBitmaps : aliased constant Font_Bitmap := (\n ",
fontName);
// Process glyphs and output huge bitmap data array
for(i=first, j=0; i<=last; i++, j++) {
// MONO renderer provides clean image with perfect crop
// (no wasted pixels) via bitmap struct.
if((err = FT_Load_Char(face, i, FT_LOAD_TARGET_MONO))) {
fprintf(stderr, "Error %d loading char '%c'\n",
err, i);
continue;
}
//.........这里部分代码省略.........
示例2: TTF_Init
void TTF_Init(void)
{
if (!TTF_initialized && FT_Init_FreeType(&library))
E_Exit("TTF: Couldn't init FreeType engine");
TTF_initialized = true;
}
示例3: main
/* ------------------------------------------------------------------------- */
int main ( int argc, char *argv[] )
{
FT_Library library;
FT_Face face;
FT_FaceRec props;
FT_Error error = 0;
FT_UInt names;
FT_CharMap charmap;
FX_Kern_0 *kstable;
TT_OS2 *pOS2;
TT_Postscript *ppost;
ULONG rc;
BOOL bDumpUCS = FALSE;
BOOL bShowKST = FALSE;
BOOL bShowOS2 = FALSE;
BOOL bShowPS = FALSE;
char szPID[10];
char szEID[32];
int i;
char *buf;
if ( argc < 2 ) {
printf("FONTNAME - Show summary of OpenType font names and other optional information.\n");
printf("Syntax: FONTNAME <filename> [ options ]\n\n");
printf(" /D Dump Unicode and DBCS strings as hex values\n");
printf(" /K Show kerning summary (KERN format 0 only)\n");
printf(" /O Show OS/2 table\n");
printf(" /P Show POST table\n\n");
printf("NAME and CMAP table information is always shown.\n\n");
printf("\nNo font file specified.\n");
return 0;
}
for ( i = 2; i < argc; i++ ) {
if ( strlen( argv[i] ) > 1 ) {
CHAR cOption = 0;
if ( argv[i][0] == '/' || argv[i][0] == '-') cOption = argv[i][1];
switch ( cOption ) {
case 'd':
case 'D':
bDumpUCS = TRUE;
break;
case 'k':
case 'K':
bShowKST = TRUE;
break;
case 'o':
case 'O':
bShowOS2 = TRUE;
break;
case 'p':
case 'P':
bShowPS = TRUE;
break;
default : break;
}
}
}
if (( rc = UniCreateUconvObject( L"@endian=big", &uconv )) != ULS_SUCCESS ) {
printf("Failed to create Unicode conversion object (rc=0x%X).\n");
printf("Unicode text values will not be shown.\n");
uconv = NULL;
}
error = FT_Init_FreeType( &library );
if ( error ) {
printf("An error occurred during library initialization.\n");
return (int) error;
}
printf("FreeType 2 library initialized successfully.\n");
error = FT_New_Face( library, argv[1], 0, &face );
if ( error ) {
if ( error == FT_Err_Unknown_File_Format )
printf("The file format is unsupported.\n");
else
printf("The file \"%s\" could not be loaded.\n", argv[1]);
goto done;
}
printf("Font %s read successfully.\n", face->family_name );
names = FT_Get_Sfnt_Name_Count( face );
if ( names ) {
printf("Names table contains %d entries:\n", names );
for ( i = 0; i < names; i++ ) {
FT_SfntName name;
error = FT_Get_Sfnt_Name( face, i, &name );
if ( error ) continue;
printf("%2d: Plat %d, Enc %d, Lang 0x%X, ID %2d ",
i, name.platform_id, name.encoding_id, name.language_id, name.name_id );
if ( name.platform_id == 1 && name.encoding_id == 0 && name.string_len < 100 ) {
printf(" \"");
PrintNameString( name.string, name.string_len );
printf("\"\n");
}
else if ( name.platform_id == 3 && name.encoding_id == 1 && uconv && name.string_len < 200 ) {
//.........这里部分代码省略.........
示例4: FontProvider
FreetypeFontProvider::FreetypeFontProvider(const FontProvider::Options& options): FontProvider(options)
{
if ( options.size.height < 1 )
{
throw std::runtime_error("[FreetypeFontProvider] Invalid size");
}
if ( options.mode == L"" || options.mode == L"normal" )
{
m_render_mode = FT_RENDER_MODE_NORMAL;
}
else if ( options.mode == L"monochrome" )
{
m_render_mode = FT_RENDER_MODE_MONO;
}
else if ( options.mode == L"lcd" )
{
m_render_mode = FT_RENDER_MODE_LCD;
}
else
{
throw std::runtime_error("[FreetypeFontProvider] Invalid font.mode");
}
if ( FT_Init_FreeType(&m_font_library) )
{
throw std::runtime_error("[FreetypeFontProvider] Can't initialize Freetype");
}
std::string filename_u8 = Encoding::UTF8.FromUCS2(options.name);
if ( FT_New_Face(m_font_library, filename_u8.c_str(), 0, &m_font_face) )
{
Dispose();
throw std::runtime_error("[FreetypeFontProvider] Can't load font from file");
}
int hres = 64;
FT_Matrix matrix =
{
(int)((1.0/hres) * 0x10000L),
(int)((0.0) * 0x10000L),
(int)((0.0) * 0x10000L),
(int)((1.0) * 0x10000L)
};
if ( FT_Set_Char_Size(m_font_face, (uint32_t)(options.size.height*64), 0, 96*hres, 96) )
{
Dispose();
throw std::runtime_error("[FreetypeFontProvider] Can't setup font");
}
FT_Set_Transform(m_font_face, &matrix, NULL);
float yscale = m_font_face->size->metrics.y_scale / (float)(1 << 16);
int height = std::ceil((m_font_face->bbox.yMax-m_font_face->bbox.yMin) * yscale / 64.0f);
//int descender = std::floor(m_font_face->descender * yscale / 64.0f);
//int ascender = std::ceil(m_font_face->ascender * yscale / 64.0f);
auto get_metrics = [&](wchar_t code) -> FT_Glyph_Metrics
{
if ( FT_Load_Glyph(m_font_face, FT_Get_Char_Index(m_font_face, code), 0) )
{
throw std::runtime_error("[FreetypeFontProvider] Metrics error");
}
return m_font_face->glyph->metrics;
};
int width = 0;
FT_Glyph_Metrics mDot = get_metrics(L'.'), mAt = get_metrics(L'@');
if ( mDot.horiAdvance == mAt.horiAdvance )
{
// Monospace font
width = std::ceil(mDot.horiAdvance / 64.0f);
}
else
{
// This is not a monospace font
//throw std::runtime_error("[FreetypeFontProvider::ctor] This is not a monospace font");
width = std::ceil(mAt.horiAdvance / 64.0f);
}
width = std::ceil(width/64.0);
height = m_font_face->size->metrics.height >> 6;
//descender = m_font_face->size->metrics.descender >> 6;
m_cell_size = Size(width, height);
m_glyph_size = Size(width, height);
FT_Library_SetLcdFilter(m_font_library, FT_LCD_FILTER_DEFAULT);
return;
}
示例5: Exception
Font::Font()
{
if(FT_Init_FreeType(&library))
throw love::Exception("TrueTypeFont Loading error: FT_Init_FreeType failed\n");
}
示例6: FT_Init_FreeType
tgon::FTFontManager::FTFontManager( )
{
FT_Init_FreeType( &library );
}
示例7: get_font
//******************** M A I N ************************
void get_font(string FontName_base, char letter, int ptsize, vect2d *times)
{
_mkdir("font_rasters");
std::string FontName = "fonts/" + FontName_base + ".ttf";
char buf[256];
string letter_name;
letter_name += letter;
if (letter >= 'A' && letter <= 'Z')
letter_name += letter;
//-----------------------------------------
// Load contour of glyph
//-----------------------------------------
lines.clear();
bez2s.clear();
FT_Face face;
FT_Library library;
FT_Error error;
error = FT_Init_FreeType( &library );
Check(error, "", "error initializing FT lib");
error = FT_New_Face( library, FontName.c_str(), 0, &face );
Check(error, "", "error loading font");
FT_F26Dot6 font_size = ptsize*64;
error = FT_Set_Char_Size( face, font_size, font_size, 72, 72 );
Check(error, "", "error setting char size");
FT_UInt glyph_index = FT_Get_Char_Index( face, letter );
FT_Int32 load_flags = FT_LOAD_NO_HINTING | FT_LOAD_NO_BITMAP;
error = FT_Load_Glyph( face, glyph_index, load_flags );
Check(error, "", "error loading glyph");
FT_Glyph glyph;
error = FT_Get_Glyph( face->glyph, &glyph );
Check(error, "", "error getting glyph");
FT_OutlineGlyph Outg;
error = GetOutLine(glyph, &Outg);
Check(error,"", "error getting outline");
// use my own callcacks to walk over the contour
FT_Outline_Funcs func_interface;
func_interface.shift = 0;
func_interface.delta = 0;
func_interface.move_to = move_to;
func_interface.line_to = line_to;
func_interface.conic_to = conic_to;
func_interface.cubic_to = cubic_to;
FT_Outline_Decompose(&Outg->outline, &func_interface, 0);
//-----------------------------------------
// Rasterize using FreeType
//-----------------------------------------
// rasterize using FreeType so that a comparison to my code can be made
double t_ft_start = get_time();
FT_Render_Glyph(face->glyph, FT_RENDER_MODE_NORMAL);
double t_ft_stop = get_time();
// save timing
FILE *fa = fopen("timings.txt", "a");
fprintf(fa, "time FreeType = %f\n", t_ft_stop - t_ft_start);
fclose(fa);
// create grid / calculate resolution
g.max_depth = 0;
g.grid_res = 2;
int maxsize = max(face->glyph->bitmap.width, face->glyph->bitmap.rows);
while (g.grid_res < maxsize)
{
g.grid_res *= 2;
g.max_depth++;
}
vect2i offset;
offset.set((g.grid_res - face->glyph->bitmap.width) / 2, (g.grid_res - face->glyph->bitmap.rows) / 2);
// copy bitmap into a buffer
Array2D<vect3ub> ftgrid;
ftgrid.resize(g.grid_res, g.grid_res);
for (int k = 0; k < g.grid_res*g.grid_res; k++)
ftgrid.data[k].set(0);
for (int j = 0; j < face->glyph->bitmap.rows; j++)
{
unsigned char *row = face->glyph->bitmap.buffer + (face->glyph->bitmap.rows-j-1)*face->glyph->bitmap.pitch;
for (int i = 0; i < face->glyph->bitmap.width; i++)
{
ftgrid(i + offset[0], j + offset[1]) = row[i];
}
}
//.........这里部分代码省略.........
示例8: main
int main (int argc, char** argv)
{
if (argc != 2)
{
std::cerr << "Usage: " << argv[0] << " <num-iter>" << std::endl;
return EXIT_FAILURE;
}
const unsigned NUM_ITER = atoi(argv[1]);
// open first face in the font
FT_Library ft_library = 0;
FT_Error error = FT_Init_FreeType(&ft_library);
if (error) throw std::runtime_error("Failed to initialize FreeType2 library");
FT_Face ft_face[NUM_EXAMPLES];
FT_New_Face(ft_library, "fonts/DejaVuSerif.ttf", 0, &ft_face[ENGLISH]);
FT_New_Face(ft_library, "fonts/amiri-0.104/amiri-regular.ttf", 0, &ft_face[ARABIC]);
FT_New_Face(ft_library, "fonts/fireflysung-1.3.0/fireflysung.ttf", 0, &ft_face[CHINESE]);
// Get our harfbuzz font structs
hb_font_t *hb_ft_font[NUM_EXAMPLES];
hb_ft_font[ENGLISH] = hb_ft_font_create(ft_face[ENGLISH], NULL);
hb_ft_font[ARABIC] = hb_ft_font_create(ft_face[ARABIC] , NULL);
hb_ft_font[CHINESE] = hb_ft_font_create(ft_face[CHINESE], NULL);
{
std::cerr << "Starting ICU shaping:" << std::endl;
progress_timer timer1(std::clog,"ICU shaping done");
UErrorCode err = U_ZERO_ERROR;
for (unsigned i = 0; i < NUM_ITER; ++i)
{
for (unsigned j = 0; j < NUM_EXAMPLES; ++j)
{
UnicodeString text = UnicodeString::fromUTF8(texts[j]);
int32_t length = text.length();
UnicodeString reordered;
UnicodeString shaped;
UBiDi *bidi = ubidi_openSized(length, 0, &err);
ubidi_setPara(bidi, text.getBuffer(), length, UBIDI_DEFAULT_LTR, 0, &err);
ubidi_writeReordered(bidi, reordered.getBuffer(length),
length, UBIDI_DO_MIRRORING, &err);
ubidi_close(bidi);
reordered.releaseBuffer(length);
u_shapeArabic(reordered.getBuffer(), length,
shaped.getBuffer(length), length,
U_SHAPE_LETTERS_SHAPE | U_SHAPE_LENGTH_FIXED_SPACES_NEAR |
U_SHAPE_TEXT_DIRECTION_VISUAL_LTR, &err);
shaped.releaseBuffer(length);
if (U_SUCCESS(err))
{
U_NAMESPACE_QUALIFIER StringCharacterIterator iter(shaped);
for (iter.setToStart(); iter.hasNext();)
{
UChar ch = iter.nextPostInc();
int32_t glyph_index = FT_Get_Char_Index(ft_face[j], ch);
if (i == 0)
{
std::cerr << glyph_index << ":";
}
}
if (i == 0) std::cerr << std::endl;
}
}
}
}
{
const char **shaper_list = hb_shape_list_shapers();
for ( ;*shaper_list; shaper_list++)
{
std::cerr << *shaper_list << std::endl;
}
std::cerr << "Starting Harfbuzz shaping" << std::endl;
progress_timer timer2(std::clog,"Harfbuzz shaping done");
const char* const shapers[] = { /*"ot",*/"fallback" };
hb_buffer_t *buffer(hb_buffer_create());
for (unsigned i = 0; i < NUM_ITER; ++i)
{
for (unsigned j = 0; j < NUM_EXAMPLES; ++j)
{
UnicodeString text = UnicodeString::fromUTF8(texts[j]);
int32_t length = text.length();
hb_buffer_clear_contents(buffer);
//hb_buffer_set_unicode_funcs(buffer.get(), hb_icu_get_unicode_funcs());
hb_buffer_pre_allocate(buffer, length);
hb_buffer_add_utf16(buffer, text.getBuffer(), text.length(), 0, length);
hb_buffer_set_direction(buffer, text_directions[j]);
hb_buffer_set_script(buffer, scripts[j]);
hb_buffer_set_language(buffer,hb_language_from_string(languages[j], std::strlen(languages[j])));
//hb_shape(hb_ft_font[j], buffer.get(), 0, 0);
hb_shape_full(hb_ft_font[j], buffer, 0, 0, shapers);
unsigned num_glyphs = hb_buffer_get_length(buffer);
hb_glyph_info_t *glyphs = hb_buffer_get_glyph_infos(buffer, NULL);
//hb_glyph_position_t *positions = hb_buffer_get_glyph_positions(buffer.get(), NULL);
for (unsigned k=0; k<num_glyphs; ++k)
{
int32_t glyph_index = glyphs[k].codepoint;
//.........这里部分代码省略.........
示例9: main
int main (int argc, char **argv)
{
int i,j,found=0,m,mask=1,kmode=1,pmode=0, lc=-1, changed=0, todo=1, help=1, help_changed=0, move=0;
unsigned char actchan[20]=""/*,channel[128]=""*/;
FILE *fh,*fh2;
char *cpt1,*cpt2;
gpixel mp, mc[MAX_MASK], tp;
int tsx=430, tsy=120, tdy=24, tsz=28, txw=500, tcol=TURQUOISE;
int xp[MAX_MASK][8],yp[MAX_MASK][8],xw[MAX_MASK][8],yw[MAX_MASK][8],valid[MAX_MASK],cmc[MAX_MASK],xxp,xxw,yyp,yyw,nmsk=0,amsk=0;
double xs=1.0, ys=1.0;
time_t t1,t2;
for(j=0; j<MAX_MASK; j++)
{
valid[j]=0;
cmc[j]=BLACK;
make_color(BLACK, &mc[j]);
for(i=0; i<8; i++)
{
xp[j][i]=(1280-40)/2;
xw[j][i]=40;
yp[j][i]=(720-20)/2;
yw[j][i]=20;
}
}
system("pzapit -var > /tmp/logomaskset.stat");
if((fh=fopen("/tmp/logomaskset.stat","r"))!=NULL)
{
if(fgets(tstr,500,fh))
{
TrimString(tstr);
if(strlen(tstr))
{
if(sscanf(tstr+strlen(tstr)-1,"%d",&pmode)!=1)
{
pmode=0;
}
}
}
fclose(fh);
}
system("touch /tmp/.logomask_kill");
fb = open(FB_DEVICE, O_RDWR);
if(ioctl(fb, FBIOGET_FSCREENINFO, &fix_screeninfo) == -1)
{
printf("logomask <FBIOGET_FSCREENINFO failed>\n");
return -1;
}
if(ioctl(fb, FBIOGET_VSCREENINFO, &var_screeninfo) == -1)
{
printf("logomask <FBIOGET_VSCREENINFO failed>\n");
return -1;
}
if(!(lfb = (unsigned char*)mmap(0, fix_screeninfo.smem_len, PROT_READ | PROT_WRITE, MAP_SHARED, fb, 0)))
{
printf("logomask <mapping of Framebuffer failed>\n");
return -1;
}
//init fontlibrary
if((error = FT_Init_FreeType(&library)))
{
printf("logomask <FT_Init_FreeType failed with Errorcode 0x%.2X>", error);
munmap(lfb, fix_screeninfo.smem_len);
return -1;
}
if((error = FTC_Manager_New(library, 1, 2, 0, &MyFaceRequester, NULL, &manager)))
{
printf("logomask <FTC_Manager_New failed with Errorcode 0x%.2X>\n", error);
FT_Done_FreeType(library);
munmap(lfb, fix_screeninfo.smem_len);
return -1;
}
if((error = FTC_SBitCache_New(manager, &cache)))
{
printf("logomask <FTC_SBitCache_New failed with Errorcode 0x%.2X>\n", error);
FTC_Manager_Done(manager);
FT_Done_FreeType(library);
munmap(lfb, fix_screeninfo.smem_len);
return -1;
}
if((error = FTC_Manager_LookupFace(manager, FONT, &face)))
{
printf("logomask <FTC_Manager_Lookup_Face failed with Errorcode 0x%.2X>\n", error);
FTC_Manager_Done(manager);
FT_Done_FreeType(library);
munmap(lfb, fix_screeninfo.smem_len);
return -1;
}
use_kerning = FT_HAS_KERNING(face);
//.........这里部分代码省略.........
示例10: Create
/*****************************************************************************
* Create: allocates osd-text video thread output method
*****************************************************************************
* This function allocates and initializes a Clone vout method.
*****************************************************************************/
static int Create( vlc_object_t *p_this )
{
filter_t *p_filter = (filter_t *)p_this;
filter_sys_t *p_sys;
char *psz_fontfile = NULL;
int i, i_error;
int i_fontsize = 0;
vlc_value_t val;
/* Allocate structure */
p_sys = malloc( sizeof( filter_sys_t ) );
if( !p_sys )
{
msg_Err( p_filter, "out of memory" );
return VLC_ENOMEM;
}
p_sys->p_face = 0;
p_sys->p_library = 0;
for( i = 0; i < 256; i++ )
{
p_sys->pi_gamma[i] = (uint8_t)( pow( (double)i * 255.0f, 0.5f ) );
}
var_Create( p_filter, "freetype-font",
VLC_VAR_STRING | VLC_VAR_DOINHERIT );
var_Create( p_filter, "freetype-fontsize",
VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
var_Create( p_filter, "freetype-rel-fontsize",
VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
/* Look what method was requested */
var_Get( p_filter, "freetype-font", &val );
psz_fontfile = val.psz_string;
if( !psz_fontfile || !*psz_fontfile )
{
if( psz_fontfile ) free( psz_fontfile );
psz_fontfile = (char *)malloc( PATH_MAX + 1 );
#ifdef WIN32
GetWindowsDirectory( psz_fontfile, PATH_MAX + 1 );
strcat( psz_fontfile, "\\fonts\\arial.ttf" );
#elif SYS_DARWIN
strcpy( psz_fontfile, DEFAULT_FONT );
#else
msg_Err( p_filter, "user didn't specify a font" );
goto error;
#endif
}
i_error = FT_Init_FreeType( &p_sys->p_library );
if( i_error )
{
msg_Err( p_filter, "couldn't initialize freetype" );
goto error;
}
i_error = FT_New_Face( p_sys->p_library, psz_fontfile ? psz_fontfile : "",
0, &p_sys->p_face );
if( i_error == FT_Err_Unknown_File_Format )
{
msg_Err( p_filter, "file %s have unknown format", psz_fontfile );
goto error;
}
else if( i_error )
{
msg_Err( p_filter, "failed to load font file %s", psz_fontfile );
goto error;
}
i_error = FT_Select_Charmap( p_sys->p_face, ft_encoding_unicode );
if( i_error )
{
msg_Err( p_filter, "Font has no unicode translation table" );
goto error;
}
p_sys->i_use_kerning = FT_HAS_KERNING( p_sys->p_face );
var_Get( p_filter, "freetype-fontsize", &val );
if( val.i_int )
{
i_fontsize = val.i_int;
}
else
{
var_Get( p_filter, "freetype-rel-fontsize", &val );
i_fontsize = (int)p_filter->fmt_out.video.i_height / val.i_int;
}
if( i_fontsize <= 0 )
{
msg_Warn( p_filter, "Invalid fontsize, using 12" );
i_fontsize = 12;
}
msg_Dbg( p_filter, "Using fontsize: %i", i_fontsize);
//.........这里部分代码省略.........
示例11: dump_dependencies
static void
dump_dependencies(void)
{
#ifdef __GNUC__
g_print ("Compiler: GCC " __VERSION__ "\n");
#elif defined _MSC_VER
g_print ("Compiler: MSC %d\n", _MSC_VER);
#else
g_print ("Compiler: unknown\n");
#endif
/* some flags/defines which may be interesting */
g_print (" with : "
#ifdef G_THREADS_ENABLED
"threads "
#endif
#ifdef HAVE_CAIRO
"cairo "
#endif
#ifdef HAVE_GNOME
"gnome "
#endif
#ifdef HAVE_LIBART
"libart "
#endif
#ifdef HAVE_PANGOCAIRO
"pangocairo "
#endif
"\n");
/* print out all those dependies, both compile and runtime if possible
* Note: this is not meant to be complete but does only include libaries
* which may or have cause(d) us trouble in some versions
*/
g_print ("Library versions (at compile time)\n");
#ifdef HAVE_LIBPNG
g_print ("libpng : %s (%s)\n", png_get_header_ver(NULL), PNG_LIBPNG_VER_STRING);
#endif
#ifdef HAVE_FREETYPE
{
FT_Library ft_library;
FT_Int ft_major_version;
FT_Int ft_minor_version;
FT_Int ft_micro_version;
if (FT_Init_FreeType (&ft_library) == 0) {
FT_Library_Version (ft_library,
&ft_major_version,
&ft_minor_version,
&ft_micro_version);
g_print ("freetype: %d.%d.%d\n", ft_major_version, ft_minor_version, ft_micro_version);
FT_Done_FreeType (ft_library);
}
else
g_print ("freetype: ?.?.?\n");
}
#endif
{
const gchar* libxml_rt_version = "?";
#if 0
/* this is stupid, does not compile on Linux:
* app_procs.c:504: error: expected identifier before '(' token
*
* In fact libxml2 has different ABI for LIBXML_THREAD_ENABLED, this code only compiles without
* threads enabled, but apparently it does only work when theay are.
*/
xmlInitParser();
if (xmlGetGlobalState())
libxml_rt_version = xmlGetGlobalState()->xmlParserVersion;
#endif
libxml_rt_version = xmlParserVersion;
if (atoi(libxml_rt_version))
g_print ("libxml : %d.%d.%d (%s)\n",
atoi(libxml_rt_version) / 10000, atoi(libxml_rt_version) / 100 % 100, atoi(libxml_rt_version) % 100,
LIBXML_DOTTED_VERSION);
else /* may include "extra" */
g_print ("libxml : %s (%s)\n", libxml_rt_version ? libxml_rt_version : "??", LIBXML_DOTTED_VERSION);
}
g_print ("glib : %d.%d.%d (%d.%d.%d)\n",
glib_major_version, glib_minor_version, glib_micro_version,
GLIB_MAJOR_VERSION, GLIB_MINOR_VERSION, GLIB_MICRO_VERSION);
#ifdef PANGO_VERSION_ENCODE
g_print ("pango : %s (%d.%d.%d)\n", pango_version_string(), PANGO_VERSION_MAJOR, PANGO_VERSION_MINOR, PANGO_VERSION_MICRO);
#else
g_print ("pango : version not available (>= 1.14.x)\n"); /* Pango did not provide such */
#endif
#if HAVE_CAIRO
# ifdef CAIRO_VERSION_STRING
g_print ("cairo : %s (%s)\n", cairo_version_string(), CAIRO_VERSION_STRING);
# else
g_print ("cairo : %s (%d.%d.%d)\n", cairo_version_string(), CAIRO_VERSION_MAJOR, CAIRO_VERSION_MINOR, CAIRO_VERSION_MICRO);
# endif
#endif
#if 0
{
gchar linkedname[1024];
gint len = 0;
/* relying on PREFIX is wrong */
if ((len = readlink (PREFIX "/lib/libpango-1.0.so", linkedname, 1023)) > 0) {
//.........这里部分代码省略.........
示例12: FT_Init_FreeType
//-----------------------------------------------------------------------------
// Get the list of available font filenames, and load the name for each of
// them. Only that, though, not the glyphs too.
//-----------------------------------------------------------------------------
TtfFontList::TtfFontList() {
FT_Init_FreeType(&fontLibrary);
}
示例13: FT_Init_FreeType
Font::LibraryParameter::LibraryParameter() {
FT_Error error = FT_Init_FreeType(&library);
// Throw an exception if the library failed
//if (error)
}
示例14: main
int
main(int argc, char **argv)
{
FT_Error error;
FT_Library library;
FT_Face face;
GFile *file;
gchar *font_file, *title;
gint row;
GtkWidget *window, *hbox, *table, *swin, *drawing_area;
GdkColor white = { 0, 0xffff, 0xffff, 0xffff };
GtkWidget *button, *align;
bindtextdomain(GETTEXT_PACKAGE, MATELOCALEDIR);
bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
textdomain(GETTEXT_PACKAGE);
gtk_init(&argc, &argv);
if (argc != 2) {
g_printerr(_("usage: %s fontfile\n"), argv[0]);
return 1;
}
if (!XftInitFtLibrary()) {
g_printerr("could not initialise freetype library\n");
return 1;
}
error = FT_Init_FreeType(&library);
if (error) {
g_printerr("could not initialise freetype\n");
return 1;
}
file = g_file_new_for_commandline_arg (argv[1]);
font_file = g_file_get_uri (file);
g_object_unref (file);
if (!font_file) {
g_printerr("could not parse argument into a URI\n");
return 1;
}
error = FT_New_Face_From_URI(library, font_file, 0, &face);
if (error) {
g_printerr("could not load face '%s'\n", font_file);
return 1;
}
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
title = g_strconcat(face->family_name,
face->style_name ? ", " : "",
face->style_name, NULL);
gtk_window_set_title(GTK_WINDOW(window), title);
set_icon(GTK_WINDOW(window), font_file);
g_free(title);
gtk_window_set_resizable(GTK_WINDOW(window), TRUE);
hbox = gtk_hbox_new(FALSE, 0);
gtk_container_add(GTK_CONTAINER(window), hbox);
swin = gtk_scrolled_window_new(NULL, NULL);
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(swin),
GTK_POLICY_AUTOMATIC, GTK_POLICY_NEVER);
gtk_box_pack_start(GTK_BOX(hbox), swin, TRUE, TRUE, 0);
drawing_area = gtk_drawing_area_new();
gtk_widget_modify_bg(drawing_area, GTK_STATE_NORMAL, &white);
gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(swin),
drawing_area);
#if !GTK_CHECK_VERSION (3, 0, 0)
g_signal_connect (drawing_area, "realize", G_CALLBACK(create_text_pixmap), face);
#endif
/* set the minimum size on the scrolled window to prevent
* unnecessary scrolling */
gtk_widget_set_size_request(swin, 500, -1);
g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);
table = gtk_table_new(1, 2, FALSE);
gtk_container_set_border_width(GTK_CONTAINER(table), 5);
gtk_box_pack_start(GTK_BOX(hbox), table, FALSE, TRUE, 0);
row = 0;
add_face_info(table, &row, font_file, face);
/* add install button */
align = gtk_alignment_new (1.0, 0.5, 0.0, 0.0);
gtk_table_attach (GTK_TABLE (table), align, 0, 2, row, row + 1,
GTK_FILL|GTK_EXPAND, GTK_FILL, 0, 0);
button = gtk_button_new_with_mnemonic (_("I_nstall Font"));
g_signal_connect (button, "clicked",
G_CALLBACK (install_button_clicked_cb), font_file);
gtk_container_add (GTK_CONTAINER (align), button);
gtk_table_set_col_spacings(GTK_TABLE(table), 8);
//.........这里部分代码省略.........
示例15: FT_Init_FreeType
Error DynamicFontAtSize::_load() {
int error = FT_Init_FreeType( &library );
ERR_EXPLAIN(TTR("Error initializing FreeType."));
ERR_FAIL_COND_V( error !=0, ERR_CANT_CREATE );
if (font->font_path!=String()) {
FileAccess *f=FileAccess::open(font->font_path,FileAccess::READ);
ERR_FAIL_COND_V(!f,ERR_CANT_OPEN);
memset(&stream,0,sizeof(FT_StreamRec));
stream.base=NULL;
stream.size=f->get_len();
stream.pos=0;
stream.descriptor.pointer=f;
stream.read=_ft_stream_io;
stream.close=_ft_stream_close;
FT_Open_Args fargs;
memset(&fargs,0,sizeof(FT_Open_Args));
fargs.flags=FT_OPEN_STREAM;
fargs.stream=&stream;
error = FT_Open_Face( library,&fargs,0,&face);
} else if (font->font_mem) {
memset(&stream,0,sizeof(FT_StreamRec));
stream.base=(unsigned char*)font->font_mem;
stream.size=font->font_mem_size;
stream.pos=0;
FT_Open_Args fargs;
memset(&fargs,0,sizeof(FT_Open_Args));
fargs.memory_base=(unsigned char*)font->font_mem;
fargs.memory_size=font->font_mem_size;
fargs.flags= FT_OPEN_MEMORY;
fargs.stream=&stream;
error = FT_Open_Face( library,&fargs,0,&face);
} else {
ERR_EXPLAIN("DynamicFont uninitialized");
ERR_FAIL_V(ERR_UNCONFIGURED);
}
//error = FT_New_Face( library, src_path.utf8().get_data(),0,&face );
if ( error == FT_Err_Unknown_File_Format ) {
ERR_EXPLAIN(TTR("Unknown font format."));
FT_Done_FreeType( library );
} else if ( error ) {
ERR_EXPLAIN(TTR("Error loading font."));
FT_Done_FreeType( library );
}
ERR_FAIL_COND_V(error,ERR_FILE_CANT_OPEN);
/*error = FT_Set_Char_Size(face,0,64*size,512,512);
if ( error ) {
FT_Done_FreeType( library );
ERR_EXPLAIN(TTR("Invalid font size."));
ERR_FAIL_COND_V( error, ERR_INVALID_PARAMETER );
}*/
error = FT_Set_Pixel_Sizes(face,0,size);
ascent=face->size->metrics.ascender>>6;
descent=-face->size->metrics.descender>>6;
linegap=0;
//print_line("ASCENT: "+itos(ascent)+" descent "+itos(descent)+" hinted: "+itos(face->face_flags&FT_FACE_FLAG_HINTER));
valid=true;
return OK;
}