当前位置: 首页>>代码示例>>C++>>正文


C++ FT_Glyph_To_Bitmap函数代码示例

本文整理汇总了C++中FT_Glyph_To_Bitmap函数的典型用法代码示例。如果您正苦于以下问题:C++ FT_Glyph_To_Bitmap函数的具体用法?C++ FT_Glyph_To_Bitmap怎么用?C++ FT_Glyph_To_Bitmap使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了FT_Glyph_To_Bitmap函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: FT_Glyph_To_Bitmap

bool Font::GenerateGlyph( unsigned int glyphNumber, GlyphBitmap &glyphBitmap)
{

    if(FT_Load_Glyph( face, FT_Get_Char_Index( face, glyphNumber ), FT_LOAD_DEFAULT ))
    {

        return false;
    }

    FT_Glyph glyph;
    if(FT_Get_Glyph( face->glyph, &glyph ))
    {

        return false;
    }

    FT_Glyph_To_Bitmap( &glyph, ft_render_mode_normal, 0, 1 );
    FT_BitmapGlyph bitmap_glyph = (FT_BitmapGlyph)glyph;

    FT_Bitmap &bitmap=bitmap_glyph->bitmap;


    glyphBitmap.bitmap->Generate(Bitmap::FORMAT_RGBA, bitmap.width, bitmap.rows, 0x00000000);
    unsigned int channelCount = GetChannelCount(Bitmap::FORMAT_RGBA);

    byte *glyphImageData = glyphBitmap.bitmap->GetData();

    for(int j = 0; j < bitmap.rows; j++)
    {
        for(int i=0; i < bitmap.width; i++)
        {
            glyphImageData[( bitmap.width * j + i ) * channelCount + channelCount - 1]
            = bitmap.buffer[bitmap.width * ( bitmap.rows - j - 1) + i];
        }
    }

    glyphBitmap.offsetDown = bitmap_glyph->top - bitmap.rows;
    glyphBitmap.bitmap->BlackToWhite();

    return true;
}
开发者ID:ishellstrike,项目名称:Space,代码行数:41,代码来源:Font.cpp

示例2: throw

FT_BitmapGlyphRec* CFontEngine::RenderGlyph(char Char)
{
	auto glyphIter = m_CachedGlyphMap.find(Char);
	if (glyphIter == m_CachedGlyphMap.end())
	{
		if (FT_Load_Char(m_FontFace, Char, FT_LOAD_DEFAULT))
		{
			throw(Wg_Ex_FreeType("Unable to render glyph.", "CFontEngine::RenderGlyph"));
		}
		FT_Glyph glyph;
		if (FT_Get_Glyph(m_FontFace->glyph, &glyph))
		{
			throw(Wg_Ex_FreeType("Unable to copy glyph.", "CFontEngine::RenderGlyph"));
		}
		if (FT_Glyph_To_Bitmap(&glyph, ft_render_mode_normal, nullptr, 1))
		{
			throw(Wg_Ex_FreeType("Unable to render glyph.", "CFontEngine::RenderGlyph"));
		}
		glyphIter = m_CachedGlyphMap.insert(std::make_pair(Char, *reinterpret_cast<FT_BitmapGlyph>(glyph))).first;
	}
	return &(glyphIter->second);
}
开发者ID:sebhz,项目名称:caprice32,代码行数:22,代码来源:wg_fontengine.cpp

示例3: prepare_glyphs

void grid_text_renderer<T>::render(glyph_positions const& pos, value_integer feature_id)
{
    glyphs_.clear();
    prepare_glyphs(pos);
    FT_Error  error;
    FT_Vector start;
    unsigned height = pixmap_.height();
    pixel_position const& base_point = pos.get_base_point();
    start.x =  static_cast<FT_Pos>(base_point.x * (1 << 6));
    start.y =  static_cast<FT_Pos>((height - base_point.y) * (1 << 6));
    start.x += transform_.tx * 64;
    start.y += transform_.ty * 64;

    // now render transformed glyphs
    double halo_radius = 0.0;
    FT_Matrix halo_matrix;
    halo_matrix.xx = halo_transform_.sx  * 0x10000L;
    halo_matrix.xy = halo_transform_.shx * 0x10000L;
    halo_matrix.yy = halo_transform_.sy  * 0x10000L;
    halo_matrix.yx = halo_transform_.shy * 0x10000L;
    for (auto & glyph : glyphs_)
    {
        halo_radius = glyph.properties.halo_radius * scale_factor_;
        FT_Glyph_Transform(glyph.image, &halo_matrix, &start);
        error = FT_Glyph_To_Bitmap(&glyph.image, FT_RENDER_MODE_NORMAL, 0, 1);
        if (!error)
        {

            FT_BitmapGlyph bit = reinterpret_cast<FT_BitmapGlyph>(glyph.image);
            render_halo_id(&bit->bitmap,
                           feature_id,
                           bit->left,
                           height - bit->top,
                           static_cast<int>(halo_radius));
        }
        FT_Done_Glyph(glyph.image);
    }
}
开发者ID:Airphrame,项目名称:mapnik,代码行数:38,代码来源:renderer.cpp

示例4: Convert_FTGlyph

/** 转换FT_GlyphSlot类型数据为LCUI_FontBMP */
static int Convert_FTGlyph( LCUI_FontBMP *bmp, FT_GlyphSlot slot, int mode )
{
	int error;
	size_t size;
	FT_BitmapGlyph bitmap_glyph;
	FT_Glyph  glyph;

	/* 从字形槽中提取一个字形图像
	 * 请注意,创建的FT_Glyph对象必须与FT_Done_Glyph成对使用 */
	error = FT_Get_Glyph( slot, &glyph );
	if(error) {
		return -1;
	}
	/*---------------------- 打印字体信息 --------------------------
	printf(" width= %ld,  met->height= %ld\n"
	"horiBearingX = %ld, horiBearingY = %ld, horiAdvance = %ld\n"
	"vertBearingX = %ld, vertBearingY = %ld,  vertAdvance = %ld\n",
	slot->metrics.width>>6, slot->metrics.height>>6,
	slot->metrics.horiBearingX>>6, slot->metrics.horiBearingY>>6,
	slot->metrics.horiAdvance>>6, slot->metrics.vertBearingX>>6,
	slot->metrics.vertBearingY>>6, slot->metrics.vertAdvance>>6 );
	------------------------------------------------------------*/
	if ( glyph->format != FT_GLYPH_FORMAT_BITMAP ) {
		error = FT_Glyph_To_Bitmap(&glyph, mode, 0 ,1);
		if(error) {
			return -1;
		}
	}
	bitmap_glyph = (FT_BitmapGlyph)glyph;
	/*
	 * FT_Glyph_Metrics结构体中保存字形度量,通过face->glyph->metrics结
	 * 构访问,可得到字形的宽、高、左边界距、上边界距、水平跨距等等。
	 * 注意:因为不是所有的字体都包含垂直度量,当FT_HAS_VERTICAL为假时,
	 * vertBearingX,vertBearingY和vertAdvance的值是不可靠的,目前暂不考虑
	 * 此情况的处理。
	 * */
	bmp->top = bitmap_glyph->top;
	bmp->left = slot->metrics.horiBearingX>>6;
	bmp->rows = bitmap_glyph->bitmap.rows;
	bmp->width = bitmap_glyph->bitmap.width;
	bmp->advance.x = slot->metrics.horiAdvance>>6;	/* 水平跨距 */
	bmp->advance.y = slot->metrics.vertAdvance>>6;	/* 垂直跨距 */
	/* 分配内存,用于保存字体位图 */
	size = bmp->rows * bmp->width * sizeof(uchar_t);
	bmp->buffer = (uchar_t*)malloc( size );
	if( !bmp->buffer ) {
		FT_Done_Glyph(glyph);
		return -1;
	}

	switch( bitmap_glyph->bitmap.pixel_mode ) {
	    /* 8位灰度位图,直接拷贝 */
	    case FT_PIXEL_MODE_GRAY:
		memcpy( bmp->buffer, bitmap_glyph->bitmap.buffer, size );
		break;
	    /* 单色点阵图,需要转换 */
	    case FT_PIXEL_MODE_MONO: {
		FT_Bitmap bitmap;
		FT_Library lib;
		FT_Int x, y;
		uchar_t *t, *s;

		lib = FontLIB_GetLibrary();
		FT_Bitmap_New( &bitmap );
		/* 转换位图bitmap_glyph->bitmap至bitmap,1个像素占1个字节 */
		FT_Bitmap_Convert( lib, &bitmap_glyph->bitmap, &bitmap, 1);
		s = bitmap.buffer;
		t = bmp->buffer;
		for( y=0; y<bmp->rows; ++y ) {
			for( x=0; x<bmp->width; ++x ) {
				*t = *s?255:0;
				++t,++s;
			}
		}
		FT_Bitmap_Done( lib, &bitmap );
		break;
	    }
	    /* 其它像素模式的位图,暂时先直接填充255,等需要时再完善 */
	    default:
		memset( bmp->buffer, 255, size );
		break;
	}
	FT_Done_Glyph(glyph);
	return size;
}
开发者ID:hbao,项目名称:LCUI,代码行数:86,代码来源:bitmapfont.c

示例5: FontPrintImageTtf_short

void FontPrintImageTtf_short(ge_Font* font, int x, int y, const unsigned short* text, u32 color, ge_Image* image){
	FT_GlyphSlot slot = ((FT_Face)font->face)->glyph;

	int b_x = x;
	int n = 0;
	long ch = 0;

	for (n = 0; text[n] != 0x0; n++) {
	//	gePrintDebug(0x100, "char: %d\n", n);
		ch = (u16)text[n];
		if(ch == '\n'){
			y += font->size;
			x = b_x;
			continue;
		}
		if(ch >= 0x80){
			TransformUnicodeChar(&ch);
		}

		FT_UInt glyph_index = FT_Get_Char_Index(((FT_Face)font->face), ch);
		FT_Load_Glyph(((FT_Face)font->face), glyph_index, FT_LOAD_DEFAULT);

		FT_Glyph glyph;
		FT_Get_Glyph(((FT_Face)font->face)->glyph, &glyph);

		FT_Glyph_To_Bitmap(&glyph, ft_render_mode_normal, 0, 1);
		slot = ((FT_Face)font->face)->glyph;
		
		FT_BitmapGlyph bitmap_glyph = (FT_BitmapGlyph)glyph;
		FT_Bitmap bitmap = bitmap_glyph->bitmap;

		fontPrintTextImage(&bitmap, x+bitmap_glyph->left, y+font->size-bitmap_glyph->top, color, image);

		x += slot->advance.x >> 6;
	}
	geUpdateImage(image);
}
开发者ID:drewet,项目名称:libge,代码行数:37,代码来源:gefont_ttf.c

示例6: freetype2_drawtext

static void freetype2_drawtext(PFont pfont, image_p pimage, int x, int y,
							   const void *text, int cc, int flags)
{
	PFontFreetype pf = (PFontFreetype) pfont;
	uint16_t* value;
	FT_Glyph glyph;
	int pen_x = x;
	int pen_y = y + pf->size;
	int i;
	FT_BitmapGlyph bitmap_glyph;
	FT_Bitmap* bitmap;

	value = _nge_ft_conv_encoding(pfont, text, &cc);
	if (cc <= 0)
		return;

	if(pimage->swizzle ==1){
		unswizzle_swap(pimage);
		pimage->dontswizzle = 1;
	}
	pimage->modified =1;
	for (i =0;i<cc;i++) {
		FT_Load_Glyph( pf->face, FT_Get_Char_Index( pf->face, value[i] ), FT_LOAD_DEFAULT );
		if(pf->flags & FLAGS_FREETYPE_BOLD)
			FT_GlyphSlot_Embolden(pf->face->glyph);
		if(pf->flags & FLAGS_FREETYPE_ITALICS)
			FT_GlyphSlot_Oblique(pf->face->glyph);
		FT_Get_Glyph( pf->face->glyph, &glyph );
		FT_Render_Glyph( pf->face->glyph, ft_render_mode_normal );
		FT_Glyph_To_Bitmap( &glyph, ft_render_mode_normal, 0, 1 );
		bitmap_glyph = (FT_BitmapGlyph)glyph;
		bitmap=&bitmap_glyph->bitmap;
		draw_one_word(pf,bitmap,pimage,pen_x + pf->face->glyph->bitmap_left,pen_y - pf->face->glyph->bitmap_top );
		pen_x  +=(pf->face->glyph->advance.x+pf->fix_width*72) >> 6  ;
		FT_Done_Glyph( glyph );
	}
}
开发者ID:eledot,项目名称:libnge2,代码行数:37,代码来源:nge_font_freetype.c

示例7: ft2_draw_glyphs

static void ft2_draw_glyphs(GalDrawable drawable, GalPB pb, GalFont obj,
		GalRect *area, eint x, eint y, GalGlyph *glyphs, eint len)
{
	Ft2Font *ft2font = FT2_FONT_DATA(obj);
	GalImage  *image = ft2font->image;
	FT_Face     face = ft2_get_face(ft2font);
	FT_BitmapGlyph bitmap_glyph;
	FT_Bitmap     *bitmap;
	eint i, w = 0;

	egal_fill_image(image, 0, area->x, 0, area->w, image->h);
	for (i = 0; i < len; i++) {
		FT_Glyph glyph;
		FT_Load_Glyph(face, glyphs[i].glyph, FT_LOAD_DEFAULT);
		FT_Get_Glyph(face->glyph, &glyph);
		if (face->glyph->format != ft_glyph_format_bitmap)
			FT_Render_Glyph(face->glyph, ft_render_mode_normal);

		FT_Glyph_To_Bitmap(&glyph, FT_RENDER_MODE_NORMAL, 0, 1);
		bitmap_glyph = (FT_BitmapGlyph)glyph;
		bitmap       = &bitmap_glyph->bitmap;

		ft2_bitmap_to_image(bitmap, image,
				x + w + face->glyph->bitmap_left,
				ft2font->metrics.height - face->glyph->bitmap_top + ft2font->metrics.descent);
		w += glyphs[i].w;
	}

	{
		GalRect rc = {x, y, w, ft2font->metrics.height};
		egal_rect_intersect(&rc, &rc, area);
		eint _y = rc.y - y;
		egal_composite_image(drawable, pb, rc.x, rc.y, image, rc.x, _y, rc.w, rc.h - _y);
		//egal_draw_image(drawable, pb, rc.x, rc.y, image, rc.x, _y, rc.w, rc.h - _y);
	}
}
开发者ID:skyformat99,项目名称:egui,代码行数:36,代码来源:ft2.c

示例8: MOJO_GET_SERVICE

    bool Font::CreateFromFile( const char* path, const uint32_t font_size, const bool smooth, const uint32_t start_char, const size_t num_chars )
    {
        if( path == NULL || font_size == 0 || num_chars == 0 || _num_glyphs > 0 ) return false;

        Mojo::Services::Filesystem* filesystem = MOJO_GET_SERVICE(Filesystem);
        Mojo::Filesystem::File* file = filesystem->Open(path, Mojo::Filesystem::FILE_READ);
        if( !file ) return false;

        size_t file_len = filesystem->Length(file);
        if( file_len == 0 ) {
            filesystem->Close(file);
            return false;
        }

        // todo: Use FT_Open_Face to read the file instead?

        uint8_t* buffer = new uint8_t[file_len]; {
            uint32_t num_bytes_read = 0;
            while( num_bytes_read < file_len ) {
                size_t read = filesystem->Read(file, file_len - num_bytes_read, (void*)&buffer[num_bytes_read]);
                mojo_assertf(read > 0, "Font::CreateFromFile\n -> Services/Filesystem error?\n");
                num_bytes_read += read;
            }
        }

        filesystem->Close(file);

        FT_Face ft_face;
        if( FT_New_Memory_Face(Mojo::GetFreeTypeLibrary(), (const FT_Byte*)buffer, file_len, 0, &ft_face) ) {
            delete[] buffer;
            return false;
        }

        FT_Set_Char_Size(ft_face, font_size * 64, font_size * 64, 72, 72);

        const float line_height = ft_face->size->metrics.height >> 6;

        // Load the glyphs
        Font::Glyph*    glyphs       = new Font::Glyph[num_chars];
        FT_Glyph*       ft_glyphs    = new FT_Glyph[num_chars];
        FT_BitmapGlyph* bm_glyphs    = (FT_BitmapGlyph*)ft_glyphs;

        float blo = 0.0f;
        uint32_t bm_max_width = 0, bm_max_height = 0;
        for( uint32_t i = 0; i < num_chars; ++i ) {
            FT_Load_Char(ft_face, start_char + i, FT_LOAD_DEFAULT);
            FT_Get_Glyph(ft_face->glyph, &ft_glyphs[i]);

            glyphs[i].x_advance = ft_face->glyph->advance.x >> 6;
            glyphs[i].y_advance = ft_face->glyph->advance.y >> 6;
            glyphs[i].x_bearing = (FT_HAS_VERTICAL(ft_face) ? ft_face->glyph->metrics.vertBearingX : ft_face->glyph->metrics.horiBearingX) >> 6;
            glyphs[i].y_bearing = (FT_HAS_VERTICAL(ft_face) ? ft_face->glyph->metrics.vertBearingY : ft_face->glyph->metrics.horiBearingY) >> 6;
            
            FT_Glyph_To_Bitmap(&ft_glyphs[i], smooth ? FT_RENDER_MODE_NORMAL : FT_RENDER_MODE_MONO, 0, 1);

            const FT_Bitmap bitmap = bm_glyphs[i]->bitmap;
            glyphs[i].width  = bitmap.width;
            glyphs[i].height = bitmap.rows;

            bm_max_width  = bm_max_width < bitmap.width ? bitmap.width : bm_max_width;
            bm_max_height = bm_max_height < bitmap.rows ? bitmap.rows : bm_max_height;

            const float gbl = -glyphs[i].y_bearing + glyphs[i].height;
            blo = (blo < gbl) ? gbl : blo;
        }

        // Determine the texture atlas size
        uint32_t atlas_width = 0, atlas_height = 0; {
            static const struct { uint32_t width, height, area; } atlas_sizes[] = {
                {  64,  64,  64 *  64 }, { 128, 128, 128 * 128 },
                { 256, 256, 256 * 256 }, { 512, 512, 512 * 512 }
            };

            uint32_t min_area = 0;
            for( uint32_t i = 0; i < num_chars; ++i ) min_area += uint32_t((glyphs[i].width + 2) * (bm_max_height + 2));

            for( uint32_t i = 0; i < 4; ++i ) {
                if( atlas_sizes[i].area < min_area ) continue;

                const uint32_t index = (i > 3) ? 3 : i;
                atlas_width  = atlas_sizes[index].width;
                atlas_height = atlas_sizes[index].height;
                break;
            }

            if( atlas_width == 0 || atlas_height == 0 ) {
                for( uint32_t i = 0; i < num_chars; ++i ) FT_Done_Glyph(ft_glyphs[i]);
                delete[] ft_glyphs;
                delete[] glyphs;

                FT_Done_Face(ft_face);
                delete[] buffer;

                return false;
            }
        }

        Mojo::TextureAtlas tex_atlas = Mojo::TextureAtlas(atlas_width, atlas_height, 32);
        Mojo::BookshelfTexturePacker tex_packer = Mojo::BookshelfTexturePacker(&tex_atlas);

//.........这里部分代码省略.........
开发者ID:mtwilliams,项目名称:mojo,代码行数:101,代码来源:Font.cpp

示例9: FT_Glyph_To_Bitmap

int eTextPara::appendGlyph(Font *current_font, FT_Face current_face, FT_UInt glyphIndex, int flags, int rflags, int border, bool last,
		bool activate_newcolor, unsigned long newcolor)
{
	int xadvance, top, left, width, height;
	pGlyph ng;

	if (border)
	{
		/* TODO: scale border radius with current_font scaling */
		if (current_font->getGlyphImage(glyphIndex, &ng.image, &ng.borderimage, 64 * border))
			return 1;
		if (ng.image && ng.image->format != FT_GLYPH_FORMAT_BITMAP)
		{
			FT_Glyph_To_Bitmap(&ng.image, FT_RENDER_MODE_NORMAL, NULL, 1);
			if (ng.image->format != FT_GLYPH_FORMAT_BITMAP) return 1;
		}
		if (ng.borderimage && ng.borderimage->format != FT_GLYPH_FORMAT_BITMAP)
		{
			FT_Glyph_To_Bitmap(&ng.borderimage, FT_RENDER_MODE_NORMAL, NULL, 1);
			if (ng.borderimage->format != FT_GLYPH_FORMAT_BITMAP) return 1;
		}
		FT_BitmapGlyph glyph = NULL;
		if (ng.borderimage)
		{
			xadvance = ng.borderimage->advance.x;
			/* 
			 * NOTE: our boundingbox calculation uses xadvance, and ignores glyph width.
			 * This is fine for all glyphs, except the last one (i.e. rightmost, for left-to-right rendering)
			 * For border glyphs, xadvance is significantly smaller than the glyph width.
			 * In fact, border glyphs often have the same xadvance as normal glyphs, borders
			 * are allowed to overlap.
			 * As a result, the boundingbox is calculated too small, the actual glyphs won't
			 * fit into it, and depending on the alignment, one of the borders on the sides 
			 * will be cut off.
			 * Ideally, the boundingbox calculation should be rewritten, to use both advance and glyph dimensions.
			 * However, for now we adjust xadvance of the last glyph, so the current calculation will produce
			 * a better fitting boundingbox for border glyphs.
			 *
			 * The compensation equals half of the difference between 'normal' glyph width, 
			 * and border glyph width. (half the width difference is on the left, and half on the right 
			 * of the glyph, we only need to compensate for the part on the right)
			 * And since xadvance is in 16.16 units, we use (dW/2) << 16 = dW << 15
			 */
			if (last) xadvance += (((FT_BitmapGlyph)ng.borderimage)->bitmap.width - ((FT_BitmapGlyph)ng.image)->bitmap.width) << 15;
			glyph = (FT_BitmapGlyph)ng.borderimage;
		}
		else if (ng.image)
		{
			xadvance = ng.image->advance.x;
			glyph = (FT_BitmapGlyph)ng.image;

		}
		else
		{
			return 1;
		}
		xadvance >>= 16;
		top = glyph->top;
		left = glyph->left;
		width = glyph->bitmap.width;
		height = glyph->bitmap.rows;
	}
	else
	{
开发者ID:Anubisko,项目名称:enigma2,代码行数:64,代码来源:font.cpp

示例10: make_dlist

///Create a display list coresponding to the give character.
void make_dlist ( FT_Face face, char ch, GLuint list_base, GLuint * tex_base ) {

    //The first thing we do is get FreeType to render our character
    //into a bitmap.  This actually requires a couple of FreeType commands:

    //Load the Glyph for our character.
    if(FT_Load_Glyph( face, FT_Get_Char_Index( face, ch ), FT_LOAD_DEFAULT ))
        throw std::runtime_error("FT_Load_Glyph failed");

    //Move the face's glyph into a Glyph object.
    FT_Glyph glyph;
    if(FT_Get_Glyph( face->glyph, &glyph ))
        throw std::runtime_error("FT_Get_Glyph failed");

    //Convert the glyph to a bitmap.
    FT_Glyph_To_Bitmap( &glyph, ft_render_mode_normal, 0, 1 );
    FT_BitmapGlyph bitmap_glyph = (FT_BitmapGlyph)glyph;

    //This reference will make accessing the bitmap easier
    FT_Bitmap& bitmap=bitmap_glyph->bitmap;

    //Use our helper function to get the widths of
    //the bitmap data that we will need in order to create
    //our texture.
    int width = next_p2( bitmap.width );
    int height = next_p2( bitmap.rows );

    //Allocate memory for the texture data.
    GLubyte* expanded_data = new GLubyte[ 2 * width * height];

    //Here we fill in the data for the expanded bitmap.
    //Notice that we are using two channel bitmap (one for
    //luminocity and one for alpha), but we assign
    //both luminocity and alpha to the value that we
    //find in the FreeType bitmap.
    //We use the ?: operator so that value which we use
    //will be 0 if we are in the padding zone, and whatever
    //is the the Freetype bitmap otherwise.
    for(int j=0; j <height; j++) {
        for(int i=0; i < width; i++) {
            expanded_data[2*(i+j*width)]= expanded_data[2*(i+j*width)+1] =
                                              (i>=bitmap.width || j>=bitmap.rows) ?
                                              0 : bitmap.buffer[i + bitmap.width*j];
        }
    }


    //Now we just setup some texture paramaters.
    glBindTexture( GL_TEXTURE_2D, tex_base[ch]);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);

    //Here we actually create the texture itself, notice
    //that we are using GL_LUMINANCE_ALPHA to indicate that
    //we are using 2 channel data.
    glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, width, height,
                  0, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, expanded_data );

    //With the texture created, we don't need to expanded data anymore
    delete [] expanded_data;

    //So now we can create the display list
    glNewList(list_base+ch,GL_COMPILE);

    glBindTexture(GL_TEXTURE_2D,tex_base[ch]);

    //first we need to move over a little so that
    //the character has the right amount of space
    //between it and the one before it.
    glTranslatef(bitmap_glyph->left,0,0);

    //Now we move down a little in the case that the
    //bitmap extends past the bottom of the line
    //(this is only true for characters like 'g' or 'y'.
    glPushMatrix();
    glTranslatef(0,bitmap_glyph->top-bitmap.rows,0);

    //Now we need to account for the fact that many of
    //our textures are filled with empty padding space.
    //We figure what portion of the texture is used by
    //the actual character and store that information in
    //the x and y variables, then when we draw the
    //quad, we will only reference the parts of the texture
    //that we contain the character itself.
    float	x=(float)bitmap.width / (float)width,
            y=(float)bitmap.rows / (float)height;

    //Here we draw the texturemaped quads.
    //The bitmap that we got from FreeType was not
    //oriented quite like we would like it to be,
    //so we need to link the texture to the quad
    //so that the result will be properly aligned.
    glBegin(GL_QUADS);
    glTexCoord2d(0,0);
    glVertex2f(0,bitmap.rows);
    glTexCoord2d(0,y);
    glVertex2f(0,0);
    glTexCoord2d(x,y);
    glVertex2f(bitmap.width,0);
//.........这里部分代码省略.........
开发者ID:JHeimdal,项目名称:HalIR,代码行数:101,代码来源:FreeType.cpp

示例11: BX_CHECK

bool TrueTypeFont::bakeGlyphDistance(CodePoint _codePoint, GlyphInfo& _glyphInfo, uint8_t* _outBuffer)
{
	BX_CHECK(m_font != NULL, "TrueTypeFont not initialized");

	_glyphInfo.glyphIndex = FT_Get_Char_Index(m_font->face, _codePoint);

	FT_Int32 loadMode = FT_LOAD_DEFAULT | FT_LOAD_NO_HINTING;
	FT_Render_Mode renderMode = FT_RENDER_MODE_NORMAL;

	FT_GlyphSlot slot = m_font->face->glyph;
	FT_Error error = FT_Load_Glyph(m_font->face, _glyphInfo.glyphIndex, loadMode);
	if (error)
	{
		return false;
	}

	FT_Glyph glyph;
	error = FT_Get_Glyph(slot, &glyph);
	if (error)
	{
		return false;
	}

	error = FT_Glyph_To_Bitmap(&glyph, renderMode, 0, 1);
	if (error)
	{
		return false;
	}

	FT_BitmapGlyph bitmap = (FT_BitmapGlyph)glyph;

	int32_t ww = bitmap->bitmap.width;
	int32_t hh = bitmap->bitmap.rows;

	glyphInfoInit(_glyphInfo, bitmap, slot, _outBuffer, 1);

	FT_Done_Glyph(glyph);

	if (ww * hh > 0)
	{
		uint32_t dw = 6;
		uint32_t dh = 6;

		uint32_t nw = ww + dw * 2;
		uint32_t nh = hh + dh * 2;
		BX_CHECK(nw * nh < 128 * 128, "Buffer overflow (size %d)", nw * nh);

		uint32_t buffSize = nw * nh * sizeof(uint8_t);

		uint8_t* alphaImg = (uint8_t*)malloc(buffSize);
		memset(alphaImg, 0, nw * nh * sizeof(uint8_t) );

		//copy the original buffer to the temp one
		for (uint32_t ii = dh; ii < nh - dh; ++ii)
		{
			memcpy(alphaImg + ii * nw + dw, _outBuffer + (ii - dh) * ww, ww);
		}

		makeDistanceMap(alphaImg, _outBuffer, nw, nh);
		free(alphaImg);

		_glyphInfo.offset_x -= (float)dw;
		_glyphInfo.offset_y -= (float)dh;
		_glyphInfo.width = (float)nw;
		_glyphInfo.height = (float)nh;
	}

	return true;
}
开发者ID:0-wiz-0,项目名称:bgfx,代码行数:69,代码来源:font_manager.cpp

示例12: if

///Create a display list corresponding to the given character.
///glyph_id = actual font glyph id (32 bits), ch = id for printing to screen (16 bits)
void font_data::make_dlist(uint glyph_id, ushort ch) {

	// get the texture reference
	m.alloc(ch);
	GLuint tex = m.get_t(ch);

	// Translate Win-1252 with additions to Unicode
	if (remapflag) {
		if (glyph_id >= 16 && glyph_id < 32) glyph_id = unichar_low[glyph_id-16];
		else if (glyph_id >= 128 && glyph_id < 160) glyph_id = unichar_high[glyph_id-128];
	}

	// Load the Glyph for our character.
	if (FT_Load_Glyph(face, FT_Get_Char_Index(face, glyph_id), FT_LOAD_DEFAULT))
		throw std::runtime_error("FT_Load_Glyph failed");

	// Move the face's glyph into a Glyph object.
    FT_Glyph glyph;
    if (FT_Get_Glyph(face->glyph, &glyph))
		throw std::runtime_error("FT_Get_Glyph failed");

	// Convert the glyph to a bitmap.
	FT_Glyph_To_Bitmap(&glyph, ft_render_mode_normal, 0, 1);
    FT_BitmapGlyph bitmap_glyph = (FT_BitmapGlyph) glyph;

	// This reference will make accessing the bitmap easier
	FT_Bitmap& bitmap=bitmap_glyph->bitmap;

	// Use our helper function to get the widths of
	// the bitmap data that we will need in order to create
	// our texture.
	// The max(2, ...) is used to correct for OpenGL, which 
	// apparently does not like to have rows less than 4 bytes
	// long.  Probably a packing thing.
	int width = max(2, next_p2(bitmap.width));
	int height = next_p2(bitmap.rows);

	// Allocate memory (temporarily) for the texture data.
	GLubyte* expanded_data = new GLubyte[2 * width * height];

	// Here we fill in the data for the expanded bitmap.
	// Notice that we are using two channel bitmap (one for
	// luminocity and one for alpha).
	// Luma always 255.  Alpha stays alpha.
	// (unless of course, it is premultiplied, which in OpenGL it is not.)
	// We use the ?: operator so that value which we use
	// will be 0 if we are in the padding zone, and whatever
	// is the Freetype bitmap otherwise.
	for (int j = 0; j < height; j++) {
		for (int i = 0; i < width; i++) {
			expanded_data[ 2*(i+j*width)   ] = 255;
			expanded_data[ 2*(i+j*width)+1 ] = 
				(i >= bitmap.width || j >= bitmap.rows) ?
				0 : bitmap.buffer[i + bitmap.width*j];
		}
	}

	// Now we just setup some texture paramaters.
    glBindTexture(GL_TEXTURE_2D, tex);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

	// Here we actually create the texture itself, notice
	// that we are using GL_LUMINANCE_ALPHA to indicate that
	// we are using 2 channel data.
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height,
		  0, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, expanded_data);


	// With the texture created, we don't need the expanded data anymore
    delete [] expanded_data;

	// So now we can create the display list
	glNewList(list_base + ch, GL_COMPILE);

	glBindTexture(GL_TEXTURE_2D, tex);

	//glPushMatrix();

	// First we need to move over a little so that
	// the character has the right amount of space
	// between it and the one before it.
	//glTranslatef((float) bitmap_glyph->left,0,0);

	// Now we move down a little in the case that the
	// bitmap extends past the bottom of the line 
	// (this is only true for characters like 'g' or 'y'.
	//glTranslatef(0,(float)bitmap_glyph->top-bitmap.rows,0);
	float left_pad = (float) bitmap_glyph->left;
	float bot_pad = (float) bitmap.rows-bitmap_glyph->top;
	glTranslatef(left_pad, -bot_pad, 0);

	// Now we need to account for the fact that many of
	// our textures are filled with empty padding space.
	// We figure what portion of the texture is used by 
	// the actual character and store that information in 
	// the x and y variables, then when we draw the
	// quad, we will only reference the parts of the texture
//.........这里部分代码省略.........
开发者ID:asquared,项目名称:hockeyboard,代码行数:101,代码来源:FreeType.cpp

示例13: Load_Glyph

static FT_Error Load_Glyph( TTF_Font* font, Uint16 ch, c_glyph* cached, int want )
{
	FT_Face face;
	FT_Error error;
	FT_GlyphSlot glyph;
	FT_Glyph_Metrics* metrics;
	FT_Outline* outline;

	if ( !font || !font->face ) {
		return FT_Err_Invalid_Handle;
	}

	face = font->face;

	/* Load the glyph */
	if ( ! cached->index ) {
		cached->index = FT_Get_Char_Index( face, ch );
	}
	error = FT_Load_Glyph( face, cached->index, FT_LOAD_DEFAULT | font->hinting);
	if( error ) {
		return error;
	}

	/* Get our glyph shortcuts */
	glyph = face->glyph;
	metrics = &glyph->metrics;
	outline = &glyph->outline;

	/* Get the glyph metrics if desired */
	if ( (want & CACHED_METRICS) && !(cached->stored & CACHED_METRICS) ) {
		if ( FT_IS_SCALABLE( face ) ) {
			/* Get the bounding box */
			cached->minx = FT_FLOOR(metrics->horiBearingX);
			cached->maxx = cached->minx + FT_CEIL(metrics->width);
			cached->maxy = FT_FLOOR(metrics->horiBearingY);
			cached->miny = cached->maxy - FT_CEIL(metrics->height);
			cached->yoffset = font->ascent - cached->maxy;
			cached->advance = FT_CEIL(metrics->horiAdvance);
		} else {
			/* Get the bounding box for non-scalable format.
			 * Again, freetype2 fills in many of the font metrics
			 * with the value of 0, so some of the values we
			 * need must be calculated differently with certain
			 * assumptions about non-scalable formats.
			 * */
			cached->minx = FT_FLOOR(metrics->horiBearingX);
			cached->maxx = cached->minx + FT_CEIL(metrics->horiAdvance);
			cached->maxy = FT_FLOOR(metrics->horiBearingY);
			cached->miny = cached->maxy - FT_CEIL(face->available_sizes[font->font_size_family].height);
			cached->yoffset = 0;
			cached->advance = FT_CEIL(metrics->horiAdvance);
		}
		
		/* Adjust for bold and italic text */
		if( TTF_HANDLE_STYLE_BOLD(font) ) {
			cached->maxx += font->glyph_overhang;
		}
		if( TTF_HANDLE_STYLE_ITALIC(font) ) {
			cached->maxx += (int)ceil(font->glyph_italics);
		}
		cached->stored |= CACHED_METRICS;
	}

	if ( ((want & CACHED_BITMAP) && !(cached->stored & CACHED_BITMAP)) ||
	     ((want & CACHED_PIXMAP) && !(cached->stored & CACHED_PIXMAP)) ) {
		int mono = (want & CACHED_BITMAP);
		int i;
		FT_Bitmap* src;
		FT_Bitmap* dst;
		FT_Glyph bitmap_glyph = NULL;

		/* Handle the italic style */
		if( TTF_HANDLE_STYLE_ITALIC(font) ) {
			FT_Matrix shear;

			shear.xx = 1 << 16;
			shear.xy = (int) ( font->glyph_italics * ( 1 << 16 ) ) / font->height;
			shear.yx = 0;
			shear.yy = 1 << 16;

			FT_Outline_Transform( outline, &shear );
		}

		/* Render as outline */
		if( (font->outline > 0) && glyph->format != FT_GLYPH_FORMAT_BITMAP ) {
			FT_Stroker stroker;
			FT_Get_Glyph( glyph, &bitmap_glyph );
			error = FT_Stroker_New( library, &stroker );
			if( error ) {
				return error;
			}
			FT_Stroker_Set( stroker, font->outline * 64, FT_STROKER_LINECAP_ROUND, FT_STROKER_LINEJOIN_ROUND, 0 ); 
			FT_Glyph_Stroke( &bitmap_glyph, stroker, 1 /* delete the original glyph */ );
			FT_Stroker_Done( stroker );
			/* Render the glyph */
			error = FT_Glyph_To_Bitmap( &bitmap_glyph, mono ? ft_render_mode_mono : ft_render_mode_normal, 0, 1 );
			if( error ) {
				FT_Done_Glyph( bitmap_glyph );
				return error;
			}
//.........这里部分代码省略.........
开发者ID:crust,项目名称:sscroll,代码行数:101,代码来源:SDL_ttf_lite.cpp

示例14: texture_font_load_glyphs


//.........这里部分代码省略.........
                            (int)(self->outline_thickness *64),
                            FT_STROKER_LINECAP_ROUND,
                            FT_STROKER_LINEJOIN_ROUND,
                            0);
            error = FT_Get_Glyph( face->glyph, &ft_glyph);
            if( error )
            {
                fprintf(stderr, "FT_Error (0x%02x) : %s\n",
                        FT_Errors[error].code, FT_Errors[error].message);
                return 0;
            }

            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;
开发者ID:bubbg,项目名称:lambdanative,代码行数:67,代码来源:texture-font.c

示例15: c_Glyph_toBitmap

long EMSCRIPTEN_KEEPALIVE c_Glyph_toBitmap(long glyph, int renderMode) {
    FT_Glyph bitmap = (FT_Glyph)glyph;
    FT_Error error = FT_Glyph_To_Bitmap(&bitmap, (FT_Render_Mode)renderMode, NULL, 1);
    if(error) return 0;
    return (long)bitmap;
}
开发者ID:intrigus,项目名称:gdx-freetype-gwt-gen,代码行数:6,代码来源:freetype.c


注:本文中的FT_Glyph_To_Bitmap函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。