本文整理汇总了C++中FT_Done_Face函数的典型用法代码示例。如果您正苦于以下问题:C++ FT_Done_Face函数的具体用法?C++ FT_Done_Face怎么用?C++ FT_Done_Face使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了FT_Done_Face函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: find_face
//------------------------------------------------------------------------
bool font_engine_freetype_base::load_font(const char* font_name,
unsigned face_index,
glyph_rendering ren_type,
const char* font_mem,
const long font_mem_size)
{
bool ret = false;
if(m_library_initialized)
{
m_last_error = 0;
int idx = find_face(font_name);
if(idx >= 0)
{
m_cur_face = m_faces[idx];
m_name = m_face_names[idx];
}
else
{
if(m_num_faces >= m_max_faces)
{
delete [] m_face_names[0];
FT_Done_Face(m_faces[0]);
memcpy(m_faces,
m_faces + 1,
(m_max_faces - 1) * sizeof(FT_Face));
memcpy(m_face_names,
m_face_names + 1,
(m_max_faces - 1) * sizeof(char*));
m_num_faces = m_max_faces - 1;
}
if (font_mem && font_mem_size)
{
m_last_error = FT_New_Memory_Face(m_library,
(const FT_Byte*)font_mem,
font_mem_size,
face_index,
&m_faces[m_num_faces]);
}
else
{
m_last_error = FT_New_Face(m_library,
font_name,
face_index,
&m_faces[m_num_faces]);
}
if(m_last_error == 0)
{
m_face_names[m_num_faces] = new char [strlen(font_name) + 1];
strcpy(m_face_names[m_num_faces], font_name);
m_cur_face = m_faces[m_num_faces];
m_name = m_face_names[m_num_faces];
++m_num_faces;
}
else
{
m_face_names[m_num_faces] = 0;
m_cur_face = 0;
m_name = 0;
}
}
if(m_last_error == 0)
{
ret = true;
switch(ren_type)
{
case glyph_ren_native_mono:
m_glyph_rendering = glyph_ren_native_mono;
break;
case glyph_ren_native_gray8:
m_glyph_rendering = glyph_ren_native_gray8;
break;
case glyph_ren_outline:
if(FT_IS_SCALABLE(m_cur_face))
{
m_glyph_rendering = glyph_ren_outline;
}
else
{
m_glyph_rendering = glyph_ren_native_gray8;
}
break;
case glyph_ren_agg_mono:
if(FT_IS_SCALABLE(m_cur_face))
{
m_glyph_rendering = glyph_ren_agg_mono;
}
else
{
m_glyph_rendering = glyph_ren_native_mono;
//.........这里部分代码省略.........
示例2: EFontEngine
EFontFT2::EFontFT2(const EEntry *entry, eint32 faceIndex)
: EFontEngine(), fFilename(NULL), fFaceIndex(-1), nFaces(-1), fFace(NULL), fScalable(false), fForceFontAliasing(false)
{
EPath aPath;
if(entry == NULL || entry->Exists() == false || entry->GetPath(&aPath) != E_OK) return;
EString filename = aPath.Path();
#ifdef _WIN32
filename.ReplaceAll("/", "\\");
#endif
SetRenderMode(E_FONT_RENDER_PIXMAP);
EAutolock <ELocker> autolock(&etk_ft2_font_locker);
if(!_etk_ft2_initialized_) return;
FT_Error error = FT_New_Face(_etk_ft2_library_, filename.String(), faceIndex, &fFace);
if(error || !fFace)
{
ETK_DEBUG("[FONT]: %s --- CAN NOT load face[%s:%d].", __PRETTY_FUNCTION__, aPath.Path(), faceIndex);
return;
}
if(FT_Select_Charmap(fFace, FT_ENCODING_UNICODE))
{
// ETK_DEBUG("[FONT]: %s --- font[%s] don't support ENCODING_UNICODE.", __PRETTY_FUNCTION__, aPath.Path());
if(FT_Select_Charmap(fFace, FT_ENCODING_NONE))
{
// ETK_WARNING("[FONT]: %s --- font[%s] don't support unicode at all.", __PRETTY_FUNCTION__, aPath.Path());
FT_Done_Face(fFace);
fFace = NULL;
return;
}
}
fFilename = EStrdup(filename.String());
fFaceIndex = faceIndex;
nFaces = fFace->num_faces;
EString family = fFace->family_name;
if(family.Length() <= 0)
{
family = aPath.Leaf();
eint32 cFound;
if((cFound = family.FindFirst('.')) >= 0) family.Remove(cFound, -1);
if(family.Length() < 0) family = "Unknown";
}
SetFamily(family.String());
EString style = fFace->style_name;
if(style.Length() <= 0)
{
if((fFace->style_flags & FT_STYLE_FLAG_BOLD) && (fFace->style_flags & FT_STYLE_FLAG_ITALIC))
style = "Bold Italic";
else if(fFace->style_flags & FT_STYLE_FLAG_BOLD)
style = "Bold";
else if(fFace->style_flags & FT_STYLE_FLAG_ITALIC)
style = "Italic";
else
style = "Regular";
}
SetStyle(style.String());
if(FT_IS_SCALABLE(fFace)) fScalable = true;
if(fFace->num_fixed_sizes > 0)
{
float *sizes = new float[(int)fFace->num_fixed_sizes];
for(int i = 0; i < fFace->num_fixed_sizes; i++) sizes[i] = (float)(fFace->available_sizes[i].height);
SetFixedSize(sizes, (eint32)fFace->num_fixed_sizes);
delete[] sizes;
}
FT_Done_Face(fFace);
fFace = NULL;
}
示例3: texture_font_load_glyphs
//.........这里部分代码省略.........
if( self->outline_type == 1 )
{
error = FT_Glyph_Stroke( &ft_glyph, stroker, 1 );
}
else if ( self->outline_type == 2 )
{
error = FT_Glyph_StrokeBorder( &ft_glyph, stroker, 0, 1 );
}
else if ( self->outline_type == 3 )
{
error = FT_Glyph_StrokeBorder( &ft_glyph, stroker, 1, 1 );
}
if( error )
{
fprintf(stderr, "FT_Error (0x%02x) : %s\n",
FT_Errors[error].code, FT_Errors[error].message);
return 0;
}
if( depth == 1)
{
error = FT_Glyph_To_Bitmap( &ft_glyph, FT_RENDER_MODE_NORMAL, 0, 1);
if( error )
{
fprintf(stderr, "FT_Error (0x%02x) : %s\n",
FT_Errors[error].code, FT_Errors[error].message);
return 0;
}
}
else
{
error = FT_Glyph_To_Bitmap( &ft_glyph, FT_RENDER_MODE_LCD, 0, 1);
if( error )
{
fprintf(stderr, "FT_Error (0x%02x) : %s\n",
FT_Errors[error].code, FT_Errors[error].message);
return 0;
}
}
FT_BitmapGlyph ft_bitmap_glyph = (FT_BitmapGlyph) ft_glyph;
ft_bitmap = ft_bitmap_glyph->bitmap;
ft_bitmap_width = ft_bitmap.width;
ft_bitmap_rows = ft_bitmap.rows;
ft_bitmap_pitch = ft_bitmap.pitch;
ft_glyph_top = ft_bitmap_glyph->top;
ft_glyph_left = ft_bitmap_glyph->left;
FT_Stroker_Done(stroker);
}
// We want each glyph to be separated by at least one black pixel
// (for example for shader used in demo-subpixel.c)
w = ft_bitmap_width/depth + 1;
h = ft_bitmap_rows + 1;
region = texture_atlas_get_region( self->atlas, w, h );
if ( region.x < 0 )
{
missed++;
fprintf( stderr, "Texture atlas is full (line %d)\n", __LINE__ );
continue;
}
w = w - 1;
h = h - 1;
x = region.x;
y = region.y;
texture_atlas_set_region( self->atlas, x, y, w, h,
ft_bitmap.buffer, ft_bitmap.pitch );
glyph = texture_glyph_new( );
glyph->charcode = charcodes[i];
glyph->width = w;
glyph->height = h;
glyph->outline_type = self->outline_type;
glyph->outline_thickness = self->outline_thickness;
glyph->offset_x = ft_glyph_left;
glyph->offset_y = ft_glyph_top;
glyph->s0 = x/(float)width;
glyph->t0 = y/(float)height;
glyph->s1 = (x + glyph->width)/(float)width;
glyph->t1 = (y + glyph->height)/(float)height;
// Discard hinting to get advance
FT_Load_Glyph( face, glyph_index, FT_LOAD_RENDER | FT_LOAD_NO_HINTING);
slot = face->glyph;
glyph->advance_x = slot->advance.x/64.0;
glyph->advance_y = slot->advance.y/64.0;
vector_push_back( self->glyphs, &glyph );
if( self->outline_type > 0 )
{
FT_Done_Glyph( ft_glyph );
}
}
FT_Done_Face( face );
FT_Done_FreeType( library );
texture_atlas_upload( self->atlas );
texture_font_generate_kerning( self );
return missed;
}
示例4: loadFace
void tst_QScriptEngine::malayalam()
{
{
FT_Face face = loadFace("AkrutiMal2Normal.ttf");
if (face) {
const ShapeTable shape_table [] = {
{ { 0x0d15, 0x0d46, 0x0 },
{ 0x005e, 0x0034, 0x0 } },
{ { 0x0d15, 0x0d47, 0x0 },
{ 0x005f, 0x0034, 0x0 } },
{ { 0x0d15, 0x0d4b, 0x0 },
{ 0x005f, 0x0034, 0x0058, 0x0 } },
{ { 0x0d15, 0x0d48, 0x0 },
{ 0x0060, 0x0034, 0x0 } },
{ { 0x0d15, 0x0d4a, 0x0 },
{ 0x005e, 0x0034, 0x0058, 0x0 } },
{ { 0x0d30, 0x0d4d, 0x0d15, 0x0 },
{ 0x009e, 0x0034, 0x0 } },
{ { 0x0d15, 0x0d4d, 0x0d35, 0x0 },
{ 0x0034, 0x007a, 0x0 } },
{ { 0x0d15, 0x0d4d, 0x0d2f, 0x0 },
{ 0x0034, 0x00a2, 0x0 } },
{ { 0x0d1f, 0x0d4d, 0x0d1f, 0x0 },
{ 0x0069, 0x0 } },
{ { 0x0d26, 0x0d4d, 0x0d26, 0x0 },
{ 0x0074, 0x0 } },
{ { 0x0d30, 0x0d4d, 0x0 },
{ 0x009e, 0x0 } },
{ { 0x0d30, 0x0d4d, 0x200c, 0x0 },
{ 0x009e, 0x0 } },
{ { 0x0d30, 0x0d4d, 0x200d, 0x0 },
{ 0x009e, 0x0 } },
{ { 0xd15, 0xd46, 0xd3e, 0x0 },
{ 0x5e, 0x34, 0x58, 0x0 } },
{ { 0xd15, 0xd47, 0xd3e, 0x0 },
{ 0x5f, 0x34, 0x58, 0x0 } },
{ { 0xd15, 0xd46, 0xd57, 0x0 },
{ 0x5e, 0x34, 0x65, 0x0 } },
{ { 0xd15, 0xd57, 0x0 },
{ 0x34, 0x65, 0x0 } },
{ { 0xd1f, 0xd4d, 0xd1f, 0xd41, 0xd4d, 0x0 },
{ 0x69, 0x5b, 0x64, 0x0 } },
{ {0}, {0} }
};
const ShapeTable *s = shape_table;
while (s->unicode[0]) {
QVERIFY( shaping(face, s, HB_Script_Malayalam) );
++s;
}
FT_Done_Face(face);
} else {
QSKIP("couln't find AkrutiMal2Normal.ttf");
}
}
{
FT_Face face = loadFace("Rachana.ttf");
if (face) {
const ShapeTable shape_table [] = {
{ { 0xd37, 0xd4d, 0xd1f, 0xd4d, 0xd30, 0xd40, 0x0 },
{ 0x385, 0xa3, 0x0 } },
{ { 0xd2f, 0xd4d, 0xd15, 0xd4d, 0xd15, 0xd41, 0x0 },
{ 0x2ff, 0x0 } },
{ { 0xd33, 0xd4d, 0xd33, 0x0 },
{ 0x3f8, 0x0 } },
{ { 0xd2f, 0xd4d, 0xd15, 0xd4d, 0xd15, 0xd41, 0x0 },
{ 0x2ff, 0x0 } },
{ { 0xd30, 0xd4d, 0x200d, 0xd35, 0xd4d, 0xd35, 0x0 },
{ 0xf3, 0x350, 0x0 } },
{ {0}, {0} }
};
const ShapeTable *s = shape_table;
while (s->unicode[0]) {
QVERIFY( shaping(face, s, HB_Script_Malayalam) );
++s;
}
FT_Done_Face(face);
} else {
QSKIP("couln't find Rachana.ttf");
}
}
}
示例5: FT_Done_Face
Font::~Font()
{
FT_Done_Face(face);
glDeleteTextures(1, &textureID);
}
示例6: texture_font_generate_kerning
/* ------------------------------------------------------------------------- */
void
texture_font_generate_kerning( TextureFont *self )
{
size_t i, j, k, count;
FT_Library library;
FT_Face face;
FT_UInt glyph_index, prev_index;
TextureGlyph *glyph, *prev_glyph;
FT_Vector kerning;
/* Load font */
if( !texture_font_load_face( &library, self->filename, self->size, &face ) )
{
return;
}
/* For each glyph couple combination, check if kerning is necessary */
for( i=0; i<self->glyphs->size; ++i )
{
glyph = (TextureGlyph *) vector_get( self->glyphs, i );
/* Remove any old kerning information */
if( glyph->kerning )
{
free( glyph->kerning );
glyph->kerning = 0;
glyph->kerning_count = 0;
}
/* Count how many kerning pairs we need */
count = 0;
glyph_index = FT_Get_Char_Index( face, glyph->charcode );
for( j=0; j<self->glyphs->size; ++j )
{
prev_glyph = (TextureGlyph *) vector_get( self->glyphs, j );
prev_index = FT_Get_Char_Index( face, prev_glyph->charcode );
FT_Get_Kerning( face, prev_index, glyph_index, FT_KERNING_UNFITTED, &kerning );
if( kerning.x != 0.0 )
{
count++;
}
}
/* No kerning at all */
if( !count )
{
continue;
}
/* Store kerning pairs */
glyph->kerning = (KerningPair *) malloc( count * sizeof(KerningPair) );
glyph->kerning_count = count;
k = 0;
for( j=0; j<self->glyphs->size; ++j )
{
prev_glyph = (TextureGlyph *) vector_get( self->glyphs, j );
prev_index = FT_Get_Char_Index( face, prev_glyph->charcode );
FT_Get_Kerning( face, prev_index, glyph_index, FT_KERNING_UNFITTED, &kerning );
if( kerning.x != 0.0 )
{
glyph->kerning[k].charcode = prev_glyph->charcode;
// 64 * 64 because of 26.6 encoding AND the transform matrix used
// in texture_font_load_face (hres = 64)
glyph->kerning[k].kerning = kerning.x/ (float)(64.0f*64.0f);
++k;
}
}
}
FT_Done_Face( face );
FT_Done_FreeType( library );
}
示例7: texture_font_cache_glyphs
//.........这里部分代码省略.........
{
return wcslen(charcodes);
}
/* Load each glyph */
for( i=0; i<wcslen(charcodes); ++i )
{
glyph_index = FT_Get_Char_Index( face, charcodes[i] );
// WARNING: We use texture-atlas depth to guess if user wants
// LCD subpixel rendering
FT_Int32 flags = FT_LOAD_RENDER;
if( !self->hinting )
{
flags |= FT_LOAD_NO_HINTING | FT_LOAD_NO_AUTOHINT;
}
else
{
flags |= FT_LOAD_FORCE_AUTOHINT;
}
if( depth == 3 )
{
FT_Library_SetLcdFilter( library, FT_LCD_FILTER_LIGHT );
flags |= FT_LOAD_TARGET_LCD;
if( self->lcd_filter )
{
FT_Library_SetLcdFilterWeights( library, self->lcd_weights );
}
}
error = FT_Load_Glyph( face, glyph_index, flags );
if( error )
{
fprintf(stderr, "FT_Error (line %d, code 0x%02x) : %s\n",
__LINE__, FT_Errors[error].code, FT_Errors[error].message);
FT_Done_FreeType( library );
return wcslen(charcodes)-i;
}
slot = face->glyph;
/* Gamma correction (sort of) */
for( x=0; x<slot->bitmap.width; ++x )
{
for( y=0; y<slot->bitmap.rows; ++y )
{
c = *(unsigned char *)(slot->bitmap.buffer
+ y*slot->bitmap.pitch + x );
c = (unsigned char) ( pow(c/255.0, self->gamma) * 255);
*(unsigned char *)(slot->bitmap.buffer
+ y*slot->bitmap.pitch + x ) = c;
}
}
// We want each glyph to be separated by at least one black pixel
// (for example for shader used in demo-subpixel.c)
w = slot->bitmap.width/depth + 1;
h = slot->bitmap.rows + 1;
region = texture_atlas_get_region( self->atlas, w, h );
if ( region.x < 0 )
{
missed++;
continue;
}
w = w - 1;
h = h - 1;
x = region.x;
y = region.y;
texture_atlas_set_region( self->atlas, x, y, w, h,
slot->bitmap.buffer, slot->bitmap.pitch );
glyph = texture_glyph_new( );
glyph->font = self;
glyph->charcode = charcodes[i];
glyph->kerning = 0;
glyph->width = w;
glyph->height = h;
glyph->offset_x = slot->bitmap_left;
glyph->offset_y = slot->bitmap_top;
glyph->u0 = x/(float)width;
glyph->v0 = y/(float)height;
glyph->u1 = (x + glyph->width)/(float)width;
glyph->v1 = (y + glyph->height)/(float)height;
/* Discard hinting to get advance */
FT_Load_Glyph( face, glyph_index, FT_LOAD_RENDER | FT_LOAD_NO_HINTING);
slot = face->glyph;
glyph->advance_x = slot->advance.x/64.0;
glyph->advance_y = slot->advance.y/64.0;
vector_push_back( self->glyphs, glyph );
texture_glyph_delete( glyph );
}
FT_Done_Face( face );
FT_Done_FreeType( library );
texture_atlas_upload( self->atlas );
texture_font_generate_kerning( self );
return missed;
}
示例8: unloadTextures
//.........这里部分代码省略.........
unsigned char b=0;
unsigned char *bptr = src;
for(int k=0; k < bitmap.width ; k++){
expanded_data[i][2*(k+j*width)] = 255;
if (k%8==0){
b = (*bptr++);
}
expanded_data[i][2*(k+j*width) + 1] = b&0x80 ? 255 : 0;
b <<= 1;
}
src += bitmap.pitch;
}
//-----------------------------------
}
areaSum += (cps[i].width+border*2)*(cps[i].height+border*2);
}
vector<charProps> sortedCopy = cps;
sort(sortedCopy.begin(),sortedCopy.end(),&compare_cps);
// pack in a texture, algorithm to calculate min w/h from
// http://upcommons.upc.edu/pfc/bitstream/2099.1/7720/1/TesiMasterJonas.pdf
//cout << areaSum << endl;
bool packed = false;
float alpha = logf(areaSum)*1.44269;
int w;
int h;
while(!packed){
w = pow(2,floor((alpha/2.f) + 0.5)); // there doesn't seem to be a round in cmath for windows.
//w = pow(2,round(alpha/2.f));
h = w;//pow(2,round(alpha - round(alpha/2.f)));
int x=0;
int y=0;
int maxRowHeight = sortedCopy[0].tH + border*2;
for(int i=0;i<(int)cps.size();i++){
if(x+sortedCopy[i].tW + border*2>w){
x = 0;
y += maxRowHeight;
maxRowHeight = sortedCopy[i].tH + border*2;
if(y + maxRowHeight > h){
alpha++;
break;
}
}
x+= sortedCopy[i].tW + border*2;
if(i==(int)cps.size()-1) packed = true;
}
}
ofPixels atlasPixels;
atlasPixels.allocate(w,h,2);
atlasPixels.set(0,255);
atlasPixels.set(1,0);
int x=0;
int y=0;
int maxRowHeight = sortedCopy[0].tH + border*2;
for(int i=0;i<(int)cps.size();i++){
ofPixels & charPixels = expanded_data[sortedCopy[i].character];
if(x+sortedCopy[i].tW + border*2>w){
x = 0;
y += maxRowHeight;
maxRowHeight = sortedCopy[i].tH + border*2;
}
cps[sortedCopy[i].character].t2 = float(x + border)/float(w);
cps[sortedCopy[i].character].v2 = float(y + border)/float(h);
cps[sortedCopy[i].character].t1 = float(cps[sortedCopy[i].character].tW + x + border)/float(w);
cps[sortedCopy[i].character].v1 = float(cps[sortedCopy[i].character].tH + y + border)/float(h);
charPixels.pasteInto(atlasPixels,x+border,y+border);
x+= sortedCopy[i].tW + border*2;
}
texAtlas.allocate(atlasPixels.getWidth(),atlasPixels.getHeight(),GL_LUMINANCE_ALPHA,false);
if(bAntiAlised && fontsize>14){
texAtlas.setTextureMinMagFilter(GL_LINEAR,GL_LINEAR);
}else{
texAtlas.setTextureMinMagFilter(GL_NEAREST,GL_NEAREST);
}
texAtlas.loadData(atlasPixels.getPixels(),atlasPixels.getWidth(),atlasPixels.getHeight(),GL_LUMINANCE_ALPHA);
// ------------- close the library and typeface
FT_Done_Face(face);
FT_Done_FreeType(library);
bLoadedOk = true;
}
示例9: FT_Get_Postscript_Name
//.........这里部分代码省略.........
char* pathname;
if (FcPatternGetString(pat, FC_FILE, 0, (FcChar8**)&pathname) != FcResultMatch)
return names;
int index;
if (FcPatternGetInteger(pat, FC_INDEX, 0, &index) != FcResultMatch)
return names;
FT_Face face;
if (FT_New_Face(gFreeTypeLibrary, pathname, index, &face) != 0)
return names;
const char* name = FT_Get_Postscript_Name(face);
if (name == NULL)
return names;
names->psName = name;
// for sfnt containers, we'll read the name table ourselves, not rely on Fontconfig
if (FT_IS_SFNT(face)) {
std::list<std::string> familyNames;
std::list<std::string> subFamilyNames;
FT_SfntName nameRec;
for (index = 0; index < FT_Get_Sfnt_Name_Count(face); ++index) {
char* utf8name = NULL;
if (FT_Get_Sfnt_Name(face, index, &nameRec) != 0)
continue;
switch (nameRec.name_id) {
case kFontFullName:
case kFontFamilyName:
case kFontStyleName:
case kPreferredFamilyName:
case kPreferredSubfamilyName:
{
bool preferredName = false;
if (nameRec.platform_id == TT_PLATFORM_MACINTOSH
&& nameRec.encoding_id == TT_MAC_ID_ROMAN && nameRec.language_id == 0) {
utf8name = convertToUtf8(macRomanConv, nameRec.string, nameRec.string_len);
preferredName = true;
}
else if ((nameRec.platform_id == TT_PLATFORM_APPLE_UNICODE)
|| (nameRec.platform_id == TT_PLATFORM_MICROSOFT))
utf8name = convertToUtf8(utf16beConv, nameRec.string, nameRec.string_len);
if (utf8name != NULL) {
std::list<std::string>* nameList = NULL;
switch (nameRec.name_id) {
case kFontFullName:
nameList = &names->fullNames;
break;
case kFontFamilyName:
nameList = &names->familyNames;
break;
case kFontStyleName:
nameList = &names->styleNames;
break;
case kPreferredFamilyName:
nameList = &familyNames;
break;
case kPreferredSubfamilyName:
nameList = &subFamilyNames;
break;
}
if (preferredName)
prependToList(nameList, utf8name);
else
appendToList(nameList, utf8name);
}
}
break;
}
}
if (familyNames.size() > 0)
names->familyNames = familyNames;
if (subFamilyNames.size() > 0)
names->styleNames = subFamilyNames;
}
else {
index = 0;
while (FcPatternGetString(pat, FC_FULLNAME, index++, (FcChar8**)&name) == FcResultMatch)
appendToList(&names->fullNames, name);
index = 0;
while (FcPatternGetString(pat, FC_FAMILY, index++, (FcChar8**)&name) == FcResultMatch)
appendToList(&names->familyNames, name);
index = 0;
while (FcPatternGetString(pat, FC_STYLE, index++, (FcChar8**)&name) == FcResultMatch)
appendToList(&names->styleNames, name);
if (names->fullNames.size() == 0) {
std::string fullName(names->familyNames.front());
if (names->styleNames.size() > 0) {
fullName += " ";
fullName += names->styleNames.front();
}
names->fullNames.push_back(fullName);
}
}
FT_Done_Face(face);
return names;
}
示例10: main
int
main( int argc,
char** argv )
{
FT_Library library;
FT_Face face;
FT_GlyphSlot slot;
FT_Matrix matrix; /* transformation matrix */
FT_Vector pen; /* untransformed origin */
FT_Error error;
char* filename;
// char* text;
double angle;
int target_height;
int n, num_chars;
wchar_t *chinese_str = L"ол╣Щ1g";
unsigned int *p = (unsigned int *)chinese_str;
int i;
printf("Uniocde: \n");
for (i = 0; i < wcslen(chinese_str); i++)
{
printf("0x%x ", p[i]);
}
printf("\n");
// return 0;
if ( argc != 2 )
{
fprintf ( stderr, "usage: %s font\n", argv[0] );
exit( 1 );
}
filename = argv[1]; /* first argument */
// text = argv[2]; /* second argument */
num_chars = wcslen(chinese_str);
angle = ( 0.0 / 360 ) * 3.14159 * 2; /* use 0 degrees */
target_height = HEIGHT;
error = FT_Init_FreeType( &library ); /* initialize library */
/* error handling omitted */
error = FT_New_Face( library, argv[1], 0, &face ); /* create face object */
/* error handling omitted */
/* use 20pt at 100dpi */
error = FT_Set_Char_Size( face, 20 * 64, 0,
100, 0 ); /* set character size */
/* error handling omitted */
slot = face->glyph;
/* set up matrix */
matrix.xx = (FT_Fixed)( cos( angle ) * 0x10000L );
matrix.xy = (FT_Fixed)(-sin( angle ) * 0x10000L );
matrix.yx = (FT_Fixed)( sin( angle ) * 0x10000L );
matrix.yy = (FT_Fixed)( cos( angle ) * 0x10000L );
/* the pen position in 26.6 cartesian space coordinates; */
/* start at (0,40) relative to the upper left corner */
pen.x = 0 * 64;
pen.y = ( target_height - 40 ) * 64;
for ( n = 0; n < num_chars; n++ )
{
/* set transformation */
FT_Set_Transform( face, &matrix, &pen );
/* load glyph image into the slot (erase previous one) */
error = FT_Load_Char( face, chinese_str[n], FT_LOAD_RENDER );
if ( error )
continue; /* ignore errors */
/* now, draw to our target surface (convert position) */
draw_bitmap( &slot->bitmap,
slot->bitmap_left,
target_height - slot->bitmap_top );
/* increment pen position */
pen.x += slot->advance.x;
pen.y += slot->advance.y;
}
show_image();
FT_Done_Face ( face );
FT_Done_FreeType( library );
return 0;
}
示例11: FT_Done_Face
void FreeTypeLib::freeFace(FT_Face* face) {
FT_Done_Face(*face);
delete face;
}
示例12: FT_Done_Face
SFMLGfx::~SFMLGfx()
{
FT_Done_Face(font);
FT_Done_FreeType(freetypeHandle);
}
示例13: LoadFace
static FT_Face LoadFace( filter_t *p_filter, const char *psz_fontfile, int i_idx,
const text_style_t *p_style )
{
filter_sys_t *p_sys = p_filter->p_sys;
char *psz_key = NULL;
int i_font_size = ConvertToLiveSize( p_filter, p_style );
int i_font_width = p_style->i_style_flags & STYLE_HALFWIDTH ?
i_font_size / 2 : i_font_size;
if( asprintf( &psz_key, "%s - %d - %d - %d",
psz_fontfile, i_idx,
i_font_size, i_font_width ) < 0 )
return NULL;
FT_Face p_face = vlc_dictionary_value_for_key( &p_sys->face_map, psz_key );
if( p_face != kVLCDictionaryNotFound )
goto done;
if( psz_fontfile[0] == ':' && psz_fontfile[1] == '/' )
{
int i_attach = atoi( psz_fontfile + 2 );
if( i_attach < 0 || i_attach >= p_sys->i_font_attachments )
{
msg_Err( p_filter, "LoadFace: Invalid font attachment index" );
p_face = NULL;
}
else
{
input_attachment_t *p_attach = p_sys->pp_font_attachments[ i_attach ];
if( FT_New_Memory_Face( p_sys->p_library, p_attach->p_data,
p_attach->i_data, i_idx, &p_face ) )
p_face = NULL;
}
}
else
if( FT_New_Face( p_sys->p_library, psz_fontfile, i_idx, &p_face ) )
{
msg_Err( p_filter, "LoadFace: Error creating face for %s", psz_key );
p_face = NULL;
}
if( !p_face )
goto done;
if( FT_Select_Charmap( p_face, ft_encoding_unicode ) )
{
/* We've loaded a font face which is unhelpful for actually
* rendering text - fallback to the default one.
*/
msg_Err( p_filter, "LoadFace: Error selecting charmap for %s", psz_key );
FT_Done_Face( p_face );
p_face = NULL;
goto done;
}
if( FT_Set_Pixel_Sizes( p_face, i_font_width, i_font_size ) )
{
msg_Err( p_filter,
"LoadFace: Failed to set font size for %s", psz_key );
FT_Done_Face( p_face );
p_face = NULL;
goto done;
}
vlc_dictionary_insert( &p_sys->face_map, psz_key, p_face );
done:
free( psz_key );
return p_face;
}
示例14: FT_Init_FreeType
//.........这里部分代码省略.........
int h = metrics.height / 64;
width += w;
height = (height > h) ? height : h;
}
int imageWidth = TwosPower (width);
int imageHeight = TwosPower (height);
char* const image = new char[2 * imageWidth * imageHeight];
memset (image, 0, 2 * imageWidth * imageHeight);
int maxWidth = 0;
int imageBase = 0;
for (int ch = 0; ch < 96; ch ++) {
FT_Face bitmap = face[ch];
FT_GlyphSlot slot = bitmap->glyph;
const FT_Glyph_Metrics& metrics = slot->metrics;
int w = metrics.width / 64;
int h = metrics.height / 64;
maxWidth = (w > maxWidth) ? w : maxWidth;
if (w) {
const unsigned char* const buffer = slot->bitmap.buffer;
int pitch = slot->bitmap.pitch;
int posit = imageBase;
for (int j = 0; j < h; j ++) {
for (int i = 0; i < w; i ++) {
int color = buffer[j * pitch + i];
image[posit + i * 2 + 0] = color;
image[posit + i * 2 + 1] = color;
}
posit += imageWidth * 2;
}
imageBase += w * 2;
}
}
// make th open gl display list here
m_fontImage = LoadImage("fontTexture", image, imageWidth, imageHeight, m_luminace);
m_font = glGenLists(96);
glBindTexture(GL_TEXTURE_2D, m_fontImage);
imageBase = 0;
for (int ch = 0; ch < 96; ch ++) {
FT_Face bitmap = face[ch];
FT_GlyphSlot slot = bitmap->glyph;
const FT_Glyph_Metrics& metrics = slot->metrics;
glNewList(m_font + ch, GL_COMPILE);
glPushMatrix();
// glTranslatef(slot->bitmap_left, 64 - slot->bitmap_top, 0);
glTranslatef(slot->bitmap_left, - slot->bitmap_top, 0);
dFloat w = dFloat (metrics.width / 64);
dFloat h = dFloat (metrics.height / 64);
if (w) {
dFloat u0 = dFloat (imageBase) / imageWidth;
dFloat u1 = dFloat (imageBase + w - 1.0f) / imageWidth;
dFloat v0 = 0.0f;
dFloat v1 = (h - 1.0f) / imageHeight;
glBegin(GL_QUADS);
glTexCoord2d (u0, v0);
glVertex2i(0, 0);
glTexCoord2d (u0, v1);
glVertex2i(0, h - 1);
glTexCoord2d (u1, v1);
glVertex2i (w - 1, h - 1);
glTexCoord2d (u1, v0);
glVertex2i (w - 1, 0);
glEnd();
imageBase += w;
}
glPopMatrix();
//glTranslatef(maxWidth, 0, 0);
glTranslatef(metrics.horiAdvance / 64, 0, 0);
glEndList();
FT_Done_Face(bitmap);
}
delete[] image;
// destroy the free type library
FT_Done_FreeType (library);
}
}
示例15: CORRADE_INTERNAL_ASSERT_OUTPUT
void FreeTypeFont::doClose() {
CORRADE_INTERNAL_ASSERT_OUTPUT(FT_Done_Face(ftFont) == 0);
_data = nullptr;
ftFont = nullptr;
}