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


C++ FT_Get_Glyph函数代码示例

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


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

示例1: img

char_data::char_data(char ch, FT_Face face) : img(){
	// 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;

	FT_Bitmap& bitmap=bitmap_glyph->bitmap;

	advance=face->glyph->advance.x >> 6;
	left= bitmap_glyph->left;
	w=bitmap.width;
	h=bitmap.rows;
	move_up=bitmap_glyph->top;//-bitmap.rows;


	data = new unsigned char[4*w*h];
	for(int y=0;y<h;y++) for(int x=0;x<w;x++) {
		const int my=y;//h-1-y;
		data[4*(x+w*my)]=255;
		data[4*(x+w*my)+1]=255;
		data[4*(x+w*my)+2]=255;
		data[4*(x+w*my)+3]=bitmap.buffer[x+w*y];
	}
	int old_unpack;
	gl_image_from_bytes(img, w, h, (char*)data, GL_BGRA);
}
开发者ID:Zolomon,项目名称:lanarts,代码行数:34,代码来源:font.cpp

示例2: GetGlyphSize

void GetGlyphSize( FT_Face font, int numglyph, int *wi, int *hi )
{
	FT_Glyph glyph;
	FT_BitmapGlyph bmglyph;
	
  //glyph fields:
  /*    width        :: The glyph's width.                                 */
  /*    height       :: The glyph's height.                                */
  /*    horiBearingX :: Horizontal left side bearing.                      */
  /*    horiBearingY :: Horizontal top side bearing.                       */
  /*    horiAdvance  :: Horizontal advance width.                          */
  /*    vertBearingX :: Vertical left side bearing.                        */
  /*    vertBearingY :: Vertical top side bearing.                         */
  /*    vertAdvance  :: Vertical advance height.                           */

	FT_Load_Glyph( font, FT_Get_Char_Index( font, numglyph ), FT_LOAD_DEFAULT );
	FT_Get_Glyph( font->glyph, &glyph );
	FT_Glyph_To_Bitmap( &glyph, ft_render_mode_normal, 0, 1 );
	bmglyph = (FT_BitmapGlyph)glyph;
	FT_Bitmap& bitmap = bmglyph->bitmap;
	//*wi = FTnext_p2( bitmap.width );
	//*hi = FTnext_p2( bitmap.rows );
	*wi = bitmap.width;
	*hi = bitmap.rows;
};
开发者ID:jwginge,项目名称:ojpa,代码行数:25,代码来源:font_create.cpp

示例3: freetype2_get_glyph_size

static FT_Error freetype2_get_glyph_size(PFontFreetype pf,
						 FT_Face face,
						 int glyph_index,
						 int *padvance,
						 int *pascent,
						 int *pdescent)
{
	FT_Error error;
		error = FT_Load_Glyph(face, glyph_index, FT_LOAD_DEFAULT);
		if (error)
			return error;

		if (padvance)
			*padvance = ROUND_26_6_TO_INT(face->glyph->advance.x);
		if (pascent || pdescent)
		{
			FT_Glyph glyph;
			FT_BBox bbox;

			error = FT_Get_Glyph(face->glyph, &glyph);
			if (error)
				return error;

			FT_Glyph_Get_CBox(glyph, ft_glyph_bbox_pixels, &bbox);

			FT_Done_Glyph(glyph);

			if (pascent)
				*pascent = bbox.yMax;
			if (pdescent)
				*pdescent = -bbox.yMin;
		}

		return 0;
}
开发者ID:eledot,项目名称:libnge2,代码行数:35,代码来源:nge_font_freetype.c

示例4: test_get_cbox

int
test_get_cbox( btimer_t*  timer,
               FT_Face    face,
               void*      user_data )
{
  FT_Glyph  glyph;
  FT_BBox   bbox;
  int       i, done = 0;


  FT_UNUSED( user_data );

  for ( i = 0; i < face->num_glyphs; i++ )
  {
    if ( FT_Load_Glyph( face, i, load_flags ) )
      continue;

    if ( FT_Get_Glyph( face->glyph, &glyph ) )
      continue;

    TIMER_START( timer );
    FT_Glyph_Get_CBox( glyph, FT_GLYPH_BBOX_PIXELS, &bbox );
    TIMER_STOP( timer );

    FT_Done_Glyph( glyph );
    done++;
  }

  return done;
}
开发者ID:anoopadvaitha,项目名称:lincodelib,代码行数:30,代码来源:ftbench.c

示例5: test_get_glyph

int
test_get_glyph( btimer_t*  timer,
                FT_Face    face,
                void*      user_data )
{
  FT_Glyph  glyph;
  int       i, done = 0;


  FT_UNUSED( user_data );

  for ( i = 0; i < face->num_glyphs; i++ )
  {
    if ( FT_Load_Glyph( face, i, load_flags ) )
      continue;

    TIMER_START( timer );
    if ( !FT_Get_Glyph( face->glyph, &glyph ) )
    {
      FT_Done_Glyph( glyph );
      done++;
    }
    TIMER_STOP( timer );
  }

  return done;
}
开发者ID:anoopadvaitha,项目名称:lincodelib,代码行数:27,代码来源:ftbench.c

示例6: FT_Set_Transform

void text_renderer::prepare_glyphs(glyph_positions const& positions)
{
    FT_Matrix matrix;
    FT_Vector pen;
    FT_Error  error;

    glyphs_.reserve(positions.size());
    for (auto const& glyph_pos : positions)
    {
        glyph_info const& glyph = glyph_pos.glyph;
        glyph.face->set_character_sizes(glyph.format->text_size * scale_factor_); //TODO: Optimize this?

        matrix.xx = static_cast<FT_Fixed>( glyph_pos.rot.cos * 0x10000L);
        matrix.xy = static_cast<FT_Fixed>(-glyph_pos.rot.sin * 0x10000L);
        matrix.yx = static_cast<FT_Fixed>( glyph_pos.rot.sin * 0x10000L);
        matrix.yy = static_cast<FT_Fixed>( glyph_pos.rot.cos * 0x10000L);

        pixel_position pos = glyph_pos.pos + glyph.offset.rotate(glyph_pos.rot);
        pen.x = static_cast<FT_Pos>(pos.x * 64);
        pen.y = static_cast<FT_Pos>(pos.y * 64);

        FT_Face face = glyph.face->get_face();
        FT_Set_Transform(face, &matrix, &pen);

        error = FT_Load_Glyph(face, glyph.glyph_index, FT_LOAD_NO_HINTING);
        if (error) continue;

        FT_Glyph image;
        error = FT_Get_Glyph(face->glyph, &image);
        if (error) continue;

        glyphs_.emplace_back(image, *glyph.format);
    }
}
开发者ID:Airphrame,项目名称:mapnik,代码行数:34,代码来源:renderer.cpp

示例7: BX_CHECK

bool TrueTypeFont::bakeGlyphSubpixel(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_GlyphSlot slot = m_font->face->glyph;
	FT_Error error = FT_Load_Glyph(m_font->face, _glyphInfo.glyphIndex, FT_LOAD_DEFAULT);
	if (error)
	{
		return false;
	}

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

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

	FT_BitmapGlyph bitmap = (FT_BitmapGlyph)glyph;

	glyphInfoInit(_glyphInfo, bitmap, slot, _outBuffer, 3);
	FT_Done_Glyph(glyph);

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

示例8: convertFT2Bitmap

static void convertFT2Bitmap(FT_Face face, char c, FontBitmap& fontBitmap)
{
    if (FT_Load_Glyph(face, FT_Get_Char_Index(face, c), FT_LOAD_DEFAULT))
    {
        fprintf(stderr, "FT_Load_Glyph failed\n");
        return ;
    }

    // Move The Face's Glyph Into A Glyph Object.
    FT_Glyph glyph;
    if (FT_Get_Glyph(face->glyph, &glyph))
    {
        fprintf(stderr, "FT_Get_Glyph failed\n");
        return ;
    }

    // Convert The Glyph To A Bitmap.
    FT_Glyph_To_Bitmap(&glyph, ft_render_mode_normal, 0, 1);
    FT_BitmapGlyph glyphBitmap = (FT_BitmapGlyph)glyph;

    FT_Bitmap& bitmap = glyphBitmap->bitmap;

    fontBitmap.width = bitmap.width;
    fontBitmap.height = bitmap.rows;
    fontBitmap.offsetx = glyphBitmap->left;
    fontBitmap.offsety = glyphBitmap->top - bitmap.rows;

    fprintf(stdout, "%d\n", c);
    fontBitmap.data = new uint8_t [bitmap.width * bitmap.rows];
    memcpy(fontBitmap.data, bitmap.buffer, bitmap.width * bitmap.rows);

    FT_Done_Glyph(glyph);
}
开发者ID:lihw,项目名称:glf,代码行数:33,代码来源:main.cpp

示例9: FT_Load_Glyph

bool TTBMFont::addFontGlyph(int fontnum,FT_UInt glyphIndex,wchar32_t chr) {
	FT_Error error;
	FT_Face face=fontFaces_[fontnum].face;
	error = FT_Load_Glyph(face, glyphIndex, FT_LOAD_DEFAULT);
	if (error)
		return false;

	int top, left, width, height;
	if (face->glyph->format == FT_GLYPH_FORMAT_OUTLINE) {
		FT_BBox bbox;
		if (stroker) {
			FT_Glyph glyph;
			error = FT_Get_Glyph(face->glyph, &glyph);
			if (error)
				return false;
			error = FT_Glyph_StrokeBorder(&glyph, stroker, false, true);
			if (error)
				return false;
			FT_OutlineGlyph oGlyph = reinterpret_cast<FT_OutlineGlyph>(glyph);
			FT_Outline_Get_CBox(&oGlyph->outline, &bbox);
			FT_Done_Glyph(glyph);
		}
		else
			FT_Outline_Get_CBox(&face->glyph->outline, &bbox);

		bbox.xMin &= ~63;
		bbox.yMin &= ~63;
		bbox.xMax = (bbox.xMax + 63) & ~63;
		bbox.yMax = (bbox.yMax + 63) & ~63;

		width = (bbox.xMax - bbox.xMin) >> 6;
		height = (bbox.yMax - bbox.yMin) >> 6;
		top = bbox.yMax >> 6;
		left = bbox.xMin >> 6;
	} else if (face->glyph->format == FT_GLYPH_FORMAT_BITMAP) {
开发者ID:gideros,项目名称:gideros,代码行数:35,代码来源:ttbmfont.cpp

示例10: FT_Select_Size

void text_renderer::prepare_glyphs(glyph_positions const& positions)
{
    FT_Matrix matrix;
    FT_Vector pen;
    FT_Error  error;

    glyphs_.clear();
    glyphs_.reserve(positions.size());

    for (auto const& glyph_pos : positions)
    {
        glyph_info const& glyph = glyph_pos.glyph;
        FT_Int32 load_flags = FT_LOAD_DEFAULT | FT_LOAD_NO_HINTING;

        FT_Face face = glyph.face->get_face();
        if (glyph.face->is_color())
        {
            load_flags |= FT_LOAD_COLOR ;
            if (face->num_fixed_sizes > 0)
            {
                int scaled_size = static_cast<int>(glyph.format->text_size * scale_factor_);
                int best_match = 0;
                int diff = std::abs(scaled_size - face->available_sizes[0].width);
                for (int i = 1; i < face->num_fixed_sizes; ++i)
                {
                    int ndiff = std::abs(scaled_size - face->available_sizes[i].height);
                    if (ndiff < diff)
                    {
                        best_match = i;
                        diff = ndiff;
                    }
                }
                error = FT_Select_Size(face, best_match);
            }
        }
        else
        {
            glyph.face->set_character_sizes(glyph.format->text_size * scale_factor_);
        }

        double size = glyph.format->text_size * scale_factor_;
        matrix.xx = static_cast<FT_Fixed>( glyph_pos.rot.cos * 0x10000L);
        matrix.xy = static_cast<FT_Fixed>(-glyph_pos.rot.sin * 0x10000L);
        matrix.yx = static_cast<FT_Fixed>( glyph_pos.rot.sin * 0x10000L);
        matrix.yy = static_cast<FT_Fixed>( glyph_pos.rot.cos * 0x10000L);

        pixel_position pos = glyph_pos.pos + glyph.offset.rotate(glyph_pos.rot);
        pen.x = static_cast<FT_Pos>(pos.x * 64);
        pen.y = static_cast<FT_Pos>(pos.y * 64);

        FT_Set_Transform(face, &matrix, &pen);
        error = FT_Load_Glyph(face, glyph.glyph_index, load_flags);
        if (error) continue;
        FT_Glyph image;
        error = FT_Get_Glyph(face->glyph, &image);
        if (error) continue;
        box2d<double> bbox(0, glyph_pos.glyph.ymin(), glyph_pos.glyph.advance(), glyph_pos.glyph.ymax());
        glyphs_.emplace_back(image, *glyph.format, pos, glyph_pos.rot, size, bbox);
    }
}
开发者ID:CartoDB,项目名称:mapnik,代码行数:60,代码来源:renderer.cpp

示例11: FT_Get_Char_Index

ZGlyph ZFont::create_glyph(wchar_t character)
{
    FT_Error error = 0;
    FT_Face face = _impl->face;
    
    unsigned glyph_index = FT_Get_Char_Index(face, character);
    error = FT_Load_Glyph(face, glyph_index, FT_LOAD_DEFAULT);
    if (error != 0) {
        ZException ex(ZENGINE_EXCEPTION_CODE);
        ex.extra_info = ZUtil::format("Font %p failed to load glyph for character '%c'", this, character);
        throw ex;
    }
    
    FT_Glyph freetype_glyph;
    error = FT_Get_Glyph(face->glyph, &freetype_glyph);
    if (error != 0) {
        ZException ex(ZENGINE_EXCEPTION_CODE);
        ex.extra_info = ZUtil::format("Font %p failed to get glyph for character '%c'", this, character);
        throw ex;
    }
    
    FT_Glyph_To_Bitmap(&freetype_glyph, FT_RENDER_MODE_NORMAL, 0, 1);
    FT_BitmapGlyph bitmap_glyph = (FT_BitmapGlyph)freetype_glyph;
    FT_Bitmap bitmap = bitmap_glyph->bitmap;
    
    int width = bitmap.width;
    int height = bitmap.rows;
    size_t bitmap_length = width * height;
    ZDataRef bitmap_data = std::make_shared<ZData>(bitmap.buffer, bitmap_length);
    
    ZGlyph glyph = {
        .character = character,
        .size = { float(width), float(height) },
        .advance = ZSize2D{face->glyph->advance.x / 64.f, face->glyph->advance.y / 64.f},
        .insets = ZEdgeInsets{(float)bitmap_glyph->top, (float)bitmap_glyph->left, 0.f, 0.f},
开发者ID:zanneth,项目名称:ZGE,代码行数:35,代码来源:font.cpp

示例12: FT_Load_Glyph

//-------------------------------------------------------------------------------------------------------
StringManager::BChar* StringManager::_LoadChar(wchar_t wchar)
{
    //参考http://my.unix-center.net/~Simon_fu/?p=385
    bool space = false;
    if( L' ' == wchar )
    {
        space = true;
        wchar = L'_';
    }
    FT_Load_Glyph(m_FT_Face,  FT_Get_Char_Index( m_FT_Face, wchar ), FT_LOAD_DEFAULT);//FT_LOAD_FORCE_AUTOHINT| FT_LOAD_TARGET_NORMAL);

    //得到字模
    FT_Glyph glyph;
    FT_Get_Glyph( m_FT_Face->glyph, &glyph );
    //转化成位图
    FT_Render_Glyph( m_FT_Face->glyph,   FT_RENDER_MODE_LCD );

    FT_Glyph_To_Bitmap( &glyph, ft_render_mode_normal, 0, 1 );
    FT_BitmapGlyph bitmap_glyph = (FT_BitmapGlyph)glyph;
    //取道位图数据
    FT_Bitmap& bitmap=bitmap_glyph->bitmap;

    //重新计算数据
    float scale = static_cast<float>(bitmap.rows) / static_cast<float>(m_FT_Face->glyph->metrics.height);//计算文本高宽缩放到bitmap高宽的缩放比
    int beginY =  Math::Ceil( m_FT_Face->glyph->metrics.horiBearingY * scale );//y偏移

    //FT_Done_Glyph(glyph);
    vector2d size = vector2d(bitmap.width, bitmap.rows);
    return NEW BChar(beginY, size, glyph, space);
}
开发者ID:RichardOpenGL,项目名称:Bohge_Engine,代码行数:31,代码来源:Bfont.cpp

示例13: va_start

void Font::Printf(u32 x, u32 y,const char *a, ...){
	char text[1024];
	va_list va;
	va_start(va, a);
	vsnprintf(text, sizeof text, a, va);
	va_end(va);
	
	size_t len = strlen(a);
	if(len>0){
		len=strlen(text);
		vec.x = 0;
		vec.y = FontSize;
		FT_GlyphSlot slot = face->glyph;
		FT_UInt glyph_index = 0;
		FT_UInt previous_glyph = 0;
		Kerning = FT_HAS_KERNING(face);

		for(unsigned int i=0;i<len;i++){
			glyph_index = FT_Get_Char_Index(face, text[i]);
			if(Kerning && previous_glyph && glyph_index){
				FT_Vector delta;
				FT_Get_Kerning(face, previous_glyph, glyph_index, FT_KERNING_DEFAULT, &delta);
				vec.x += delta.x >> 6;
			}
			FT_Load_Glyph(face, glyph_index,FT_LOAD_RENDER);
			FT_Get_Glyph(face->glyph, &glyph);
			FT_Glyph_StrokeBorder(&glyph,stroker,0,0);
			FontDrawBitmap(&slot->bitmap,vec.x + slot->bitmap_left + x, (vec.y - slot->bitmap_top + y -FontSize));
			previous_glyph = glyph_index;
			vec.x += slot->advance.x >> 6;
			vec.y += slot->advance.y >> 6;
			FT_Done_Glyph(glyph);
		}
开发者ID:roman5566,项目名称:NoRSX,代码行数:33,代码来源:Font.cpp

示例14: glyph_to_bitmap

CAMLprim value glyph_to_bitmap(value glyph)
{
  CAMLparam1(glyph);
  CAMLlocal2(block, buffer);
  FT_GlyphSlot   slot;
  FT_Glyph       g;
  FT_BitmapGlyph bm;
  size_t         pitch;
  size_t         new_pitch;
  int i;

  slot = *(FT_GlyphSlot *)Data_custom_val(glyph);

  if (FT_Get_Glyph(slot, &g))
    failwith("glyph_to_bitmap");

  if (g->format != FT_GLYPH_FORMAT_BITMAP)
  {
    if (FT_Glyph_To_Bitmap(&g, FT_RENDER_MODE_MONO, 0, 1))
    {
      FT_Done_Glyph(g);
      failwith("glyph_to_bitmap");
    }
  }

  bm = (FT_BitmapGlyph)g;

  pitch     = abs(bm->bitmap.pitch);
  new_pitch = (bm->bitmap.width + 7) / 8;

  block  = alloc_tuple(6);
  buffer = alloc_string(bm->bitmap.rows * new_pitch);

  if (bm->bitmap.pitch >= 0)
  {
    for (i = 0; i < bm->bitmap.rows; i++)
      memcpy(String_val(buffer) + i * new_pitch,
             bm->bitmap.buffer + i * pitch,
             new_pitch);
  }
  else
  {
    for (i = 0; i < bm->bitmap.rows; i++)
      memcpy(String_val(buffer) + i * new_pitch,
             bm->bitmap.buffer + (bm->bitmap.rows - i) * pitch,
             new_pitch);
  }

  Store_field(block, 0, Val_int(bm->left));
  Store_field(block, 1, Val_int(bm->top));
  Store_field(block, 2, Val_int(bm->bitmap.rows));
  Store_field(block, 3, Val_int(bm->bitmap.width));
  Store_field(block, 4, Val_int(new_pitch));
  Store_field(block, 5, buffer);

  FT_Done_Glyph(g);

  CAMLreturn(block);
};
开发者ID:BackupTheBerlios,项目名称:ant,代码行数:59,代码来源:freetype-stubs.c

示例15: measure_string

//http://www.freetype.org/freetype2/docs/tutorial/step2.html
FT_Error measure_string(FT_Face face, std::string text, int size, Vector2i* size_out)
{
   int pos_x = 0;
   bool use_kerning = FT_HAS_KERNING(face) ? true : false;
   FT_UInt prev_glyph_index = 0;

   FT_BBox text_bb;
   text_bb.xMax = 0;
   text_bb.xMin = 0;
   text_bb.yMax = 0;
   text_bb.yMin = 0;
   FT_Error error;

   error = FT_Set_Char_Size(face, 0, size * 64, 72, 72);

   for(unsigned int i = 0; i < text.length(); i++)
   {
      FT_UInt glyph_index = FT_Get_Char_Index(face, text.c_str()[i]);

      if(use_kerning && prev_glyph_index)
      {
         FT_Vector delta;
         FT_Get_Kerning(face, prev_glyph_index, glyph_index, FT_KERNING_DEFAULT, &delta);
         pos_x += delta.x >> 6;
      }
      prev_glyph_index = glyph_index;

      if(error = FT_Load_Glyph(face, glyph_index, FT_LOAD_DEFAULT) != FT_Err_Ok)
      {
         Log::Error(__FILE__, "Unable to load glyph %d", glyph_index);
         return error;
      }

      FT_Glyph glyph;
      if(error = FT_Get_Glyph(face->glyph, &glyph) != FT_Err_Ok)
      {
         Log::Error(__FILE__, "Unable to get glyph %d", glyph_index);
      }

      FT_BBox bb;
      FT_Glyph_Get_CBox(glyph, ft_glyph_bbox_pixels, &bb);
      bb.xMax += pos_x;
      bb.xMin += pos_x;


      pos_x += glyph->advance.x >> 16;

      //Grow overall bounding box
      if(bb.xMax > text_bb.xMax)
         text_bb.xMax = bb.xMax;
      if(bb.yMax > text_bb.yMax)
         text_bb.yMax = bb.yMax;
      if(bb.xMin < text_bb.xMin)
         text_bb.xMin = bb.xMin;
      if(bb.yMin < text_bb.yMin)
         text_bb.yMin = bb.yMin;

      FT_Done_Glyph(glyph);
   }
开发者ID:danishcake,项目名称:CrossPlatformDefense,代码行数:60,代码来源:TextureText.cpp


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