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


C++ FT_Render_Glyph函数代码示例

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


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

示例1: FT_Get_Char_Index

	void FontBuilder::CacheSymbol(wchar_t s)
	{
		CacheData* data = wcache[curSize][curFace][s];
		if (!data)
		{
			FT_UInt glyphIndex = FT_Get_Char_Index(curFace, s);
			FT_Error error = FT_Load_Glyph(curFace, glyphIndex, 0);
			if (error)
				out_error() << L"Error occured while loading a glyph" << std::endl;

			if (curFace->glyph->format != FT_GLYPH_FORMAT_BITMAP)
			{
				error = FT_Render_Glyph(curFace->glyph, FT_RENDER_MODE_NORMAL);
				if (error)
					out_error() << L"Error occured while rendering a glyph" << std::endl;
			}		

			FT_GlyphSlot slot = curFace->glyph;

			data = new CacheData;
			data->width = slot->bitmap.width;
			data->height = slot->bitmap.rows;
			if (data->width*data->height > 0)
			{
				data->buffer = new unsigned char[data->width*data->height];
				memcpy(data->buffer, slot->bitmap.buffer, data->width*data->height);
			}
			data->x_offset = slot->bitmap_left;
			data->y_offset = slot->bitmap_top;
			data->x_advance = slot->advance.x >> 6;
			data->y_advance = slot->advance.y >> 6;

			wcache[curSize][curFace][s] = data;
		}
开发者ID:Mikalai,项目名称:punk_project,代码行数:34,代码来源:font_builder.cpp

示例2: get_bitmap

const bitmap* freetype::get_bitmap(unsigned int char_code) const
{
    implement::cache& cache = impl_->get_cache();
    if (cache.find(char_code) != cache.end())
        return &cache[char_code];

    FT_GlyphSlot glyph = impl_->load_glyph(char_code);
    if (!glyph || 0 != FT_Render_Glyph(glyph, impl_->property_.render_mode))
        return nullptr;

    bitmap* bitmap = &cache[char_code];
    unsigned int buffer_length = glyph->bitmap.rows * glyph->bitmap.pitch;

    bitmap->left       = glyph->bitmap_left;
    bitmap->top        = glyph->bitmap_top - ascender();
    bitmap->width      = glyph->bitmap.width;
    bitmap->height     = glyph->bitmap.rows;
    bitmap->advance    = REAL(glyph->linearHoriAdvance, 16);
    bitmap->pitch      = glyph->bitmap.pitch;
    bitmap->pixel_mode = glyph->bitmap.pixel_mode;
    bitmap->buffer     = reinterpret_cast<unsigned char*>(
                                memcpy(new unsigned char [buffer_length],
                                       glyph->bitmap.buffer,
                                       buffer_length));

    return bitmap;
}
开发者ID:goalizc,项目名称:takisy,代码行数:27,代码来源:freetype.cpp

示例3: loadchar

	void loadchar(unsigned int uc) {
		FT_Bitmap* bitmap;
		unsigned int index;
		ubyte *Tex, *Texsrc;
		int wid = (int)pow(2, ceil(log2(32 * stretch)));

		index = FT_Get_Char_Index(fontface, uc);
		FT_Load_Glyph(fontface, index, FT_LOAD_DEFAULT);
		FT_Render_Glyph(slot, FT_RENDER_MODE_NORMAL);
		bitmap = &(slot->bitmap);
		Texsrc = bitmap->buffer;
		Tex = new ubyte[wid * wid * 4];
		memset(Tex, 0, wid * wid * 4 * sizeof(ubyte));
		for (unsigned int i = 0; i < bitmap->rows; i++) {
			for (unsigned int j = 0; j < bitmap->width; j++) {
				Tex[(i * wid + j) * 4 + 0] = Tex[(i * wid + j) * 4 + 1] = Tex[(i * wid + j) * 4 + 2] = 255U;
				Tex[(i * wid + j) * 4 + 3] = *Texsrc; Texsrc++;
			}
		}
		glGenTextures(1, &chars[uc].tex);
		glBindTexture(GL_TEXTURE_2D, chars[uc].tex);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
		glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, wid, wid, 0, GL_RGBA, GL_UNSIGNED_BYTE, Tex);
		delete[] Tex;
		chars[uc].aval = true;
		chars[uc].width = bitmap->width;
		chars[uc].height = bitmap->rows;
		chars[uc].advance = slot->advance.x >> 6;
		chars[uc].xpos = slot->bitmap_left;
		chars[uc].ypos = slot->bitmap_top;
	}
开发者ID:435886030,项目名称:NEWorld,代码行数:32,代码来源:TextRenderer.cpp

示例4: FT_Get_Char_Index

euint32 FontRenderer::draw_letter(wchar_t _letter, vptr _target, euint32 _width)
{
	FT_GlyphSlot slot = m_ft_face->glyph;
	FT_UInt glyph_index;
	FT_UInt error;

	glyph_index = FT_Get_Char_Index( m_ft_face, _letter );

	error = FT_Load_Glyph( m_ft_face, glyph_index, FT_LOAD_DEFAULT );

	if ( error )
	{
		return 0;
	}

	/// 加粗函数 FT_Outline_Embolden( &m_ft_face->glyph->outline, 100 );

	error = FT_Render_Glyph( m_ft_face->glyph, FT_RENDER_MODE_NORMAL );

	if ( error )
	{
		return 0;
	}

	return draw_text( &slot->bitmap, _target, 0, 0, _width);
}
开发者ID:rodrigobmg,项目名称:v-engine,代码行数:26,代码来源:font_renderer.cpp

示例5: FT_Get_Char_Index

Glyph Font::renderGlyph(char glyph, float font_size)
{
    if(m_rendered_symbols[(int)glyph].find(font_size) != m_rendered_symbols[(int)glyph].end()) {
        return m_rendered_symbols[(int)glyph].at(font_size);
    }
    Glyph new_glyph;

    FT_UInt char_index = FT_Get_Char_Index(m_font_face, glyph);

    if(FT_Load_Glyph(m_font_face, char_index, FT_LOAD_DEFAULT) || FT_Render_Glyph(m_font_face->glyph, FT_RENDER_MODE_NORMAL))
        return new_glyph;

    FT_Bitmap& bitmap   = m_font_face->glyph->bitmap;
    new_glyph.bearing.x = m_font_face->glyph->metrics.horiBearingX / 64;
    new_glyph.bearing.y = m_font_face->glyph->metrics.horiBearingY / 128;
    new_glyph.advance   = m_font_face->glyph->metrics.horiAdvance / 64;

    glGenTextures(1, &new_glyph.texture);
    glBindTexture(GL_TEXTURE_2D, new_glyph.texture);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    checkGLError();

    glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, bitmap.width, bitmap.rows, 0, GL_RED, GL_UNSIGNED_BYTE, bitmap.buffer);
    checkGLError();
    new_glyph.id = glyph;
    new_glyph.dimensions = glm::vec2(bitmap.width, bitmap.rows);
    m_rendered_symbols[(int)glyph][font_size] = new_glyph;

    return new_glyph;
}
开发者ID:Df458,项目名称:DFEngine,代码行数:32,代码来源:Font.cpp

示例6: draw_text

static void draw_text(FT_Face face, FT_Vector * pen, FT_Matrix * matrix,
		      const unsigned char *out, int len, int color,
		      struct rectangle *box)
{
    FT_ULong ch;
    FT_Error ans;
    FT_GlyphSlot slot = face->glyph;
    int i;

    for (i = 0; i < len; i += 2) {
	ch = (out[i] << 8) | out[i + 1];
	if (ch == 10)
	    continue;
	/* transform */
	FT_Set_Transform(face, matrix, pen);
	/* get glyph image */
	ans = FT_Load_Char(face, ch, FT_LOAD_NO_BITMAP);
	if (ans)
	    continue;
	ans = FT_Render_Glyph(face->glyph, ft_render_mode_normal);
	if (ans)
	    continue;
	/* draw bitmap */
	if (!box)
	    draw_bitmap(&slot->bitmap, slot->bitmap_left,
			screen_height - slot->bitmap_top);
	else
	    set_text_box(&slot->bitmap, slot->bitmap_left,
			 screen_height - slot->bitmap_top, box);

	/* increment pen position */
	pen->x += slot->advance.x;
	pen->y += slot->advance.y;
    }
}
开发者ID:AsherBond,项目名称:MondocosmOS,代码行数:35,代码来源:text3.c

示例7: FT_Get_Char_Index

/**
 * Caches the given font glyph in the instance font texture buffer.
 *
 * This routine renders and stores the requested glyph's bitmap and relevant information into its own quickly addressible
 * structure within an instance-specific map.
 *
 * @param charCode	The requested glyph's character code.
 * @return A pointer to the allocated font structure.
 */
ftgxCharData *FreeTypeGX::cacheGlyphData(wchar_t charCode)
{
	FT_UInt gIndex;
	uint16_t textureWidth = 0, textureHeight = 0;

	gIndex = FT_Get_Char_Index( ftFace, charCode );
	if (!FT_Load_Glyph(ftFace, gIndex, FT_LOAD_DEFAULT )) {
		FT_Render_Glyph( ftSlot, FT_RENDER_MODE_NORMAL );

		if(ftSlot->format == FT_GLYPH_FORMAT_BITMAP) {
			FT_Bitmap *glyphBitmap = &ftSlot->bitmap;

			textureWidth = adjustTextureWidth(glyphBitmap->width, this->textureFormat);
			textureHeight = adjustTextureHeight(glyphBitmap->rows, this->textureFormat);

			this->fontData[charCode] = (ftgxCharData){
				ftSlot->bitmap_left,
				ftSlot->advance.x >> 6,
				gIndex,
				textureWidth,
				textureHeight,
				ftSlot->bitmap_top,
				ftSlot->bitmap_top,
				glyphBitmap->rows - ftSlot->bitmap_top,
				NULL
			};
			this->loadGlyphData(glyphBitmap, &this->fontData[charCode]);

			return &this->fontData[charCode];
		}
开发者ID:clobber,项目名称:wii7800,代码行数:39,代码来源:FreeTypeGX.cpp

示例8: while

void		Freetype::drawText(const char *txt, unsigned int x, unsigned int y)
{
	int	error;

	while (*txt) {
		FT_UInt  glyph_index;

		glyph_index = FT_Get_Char_Index(_face, *txt);

		if ((error = FT_Load_Glyph(_face, glyph_index, FT_LOAD_DEFAULT)))
			continue;

		if ((error = FT_Render_Glyph(_face->glyph, FT_RENDER_MODE_NORMAL)))
			continue;

		my_draw_bitmap(&_slot->bitmap,
				x + _slot->bitmap_left,
				y - _slot->bitmap_top, _slot, _size);

		x += _slot->advance.x >> 6;
		y += _slot->advance.y >> 6;

		x += _padding;
		txt++;
	}
}
开发者ID:alelievr,项目名称:nibbler,代码行数:26,代码来源:Freetype.class.cpp

示例9: Glyph

BitmapRef FTFont::Glyph(char32_t glyph) {
	if(!check_face()) {
		return Font::Default()->Glyph(glyph);
	}

	if (FT_Load_Char(face_.get(), glyph, FT_LOAD_NO_BITMAP) != FT_Err_Ok) {
		Output::Error("Couldn't load FreeType character %d", glyph);
	}

    if (FT_Render_Glyph(face_->glyph, FT_RENDER_MODE_MONO) != FT_Err_Ok) {
		Output::Error("Couldn't render FreeType character %d", glyph);
	}

	FT_Bitmap const& ft_bitmap = face_->glyph->bitmap;
	assert(face_->glyph->bitmap.pixel_mode == FT_PIXEL_MODE_MONO);

	size_t const pitch = std::abs(ft_bitmap.pitch);
	int const width = ft_bitmap.width;
	int const height = ft_bitmap.rows;

	BitmapRef bm = Bitmap::Create(nullptr, width, height, 0, DynamicFormat(8,8,0,8,0,8,0,8,0,PF::Alpha));
	uint8_t* data = reinterpret_cast<uint8_t*>(bm->pixels());
	int dst_pitch = bm->pitch();

	for(int row = 0; row < height; ++row) {
		for(int col = 0; col < width; ++col) {
			unsigned c = ft_bitmap.buffer[pitch * row + (col/8)];
			unsigned bit = 7 - (col%8);
			data[row * dst_pitch + col] = (c & (0x01 << bit)) ? 255 : 0;
		}
	}

	return bm;
}
开发者ID:ChristianBreitwieser,项目名称:easyrpg-libretro,代码行数:34,代码来源:font.cpp

示例10: 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

示例11: get

	RasterizedGlyph get(uint32_t codePoint, Vector2i subpixeloffset64)
	{
		FT_Error error = FT_Load_Glyph(m_face,
			codePoint, // the glyph_index in the font file
			FT_LOAD_NO_HINTING // by default hb load fonts without hinting
		);
		if (error != FT_Err_Ok)
		{
			debug(LOG_FATAL, "unable to load glyph");
		}

		FT_GlyphSlot slot = m_face->glyph;
		FT_Render_Glyph(m_face->glyph, FT_RENDER_MODE_LCD);
		FT_Bitmap ftBitmap = slot->bitmap;

		RasterizedGlyph g;
		g.buffer.reset(new unsigned char[ftBitmap.pitch * ftBitmap.rows]);
		memcpy(g.buffer.get(), ftBitmap.buffer, ftBitmap.pitch * ftBitmap.rows);
		g.width = ftBitmap.width / 3;
		g.height = ftBitmap.rows;
		g.bearing_x = slot->bitmap_left;
		g.bearing_y = slot->bitmap_top;
		g.pitch = ftBitmap.pitch;
		return g;
	}
开发者ID:cybersphinx,项目名称:warzone2100,代码行数:25,代码来源:textdraw.cpp

示例12: TestFace

  static void
  TestFace( FT_Face  face )
  {
    unsigned int  gid;
    int           load_flags = FT_LOAD_DEFAULT;


    if ( check_outlines         &&
         FT_IS_SCALABLE( face ) )
      load_flags = FT_LOAD_NO_BITMAP;

    if ( nohints )
      load_flags |= FT_LOAD_NO_HINTING;

    FT_Set_Char_Size( face, 0, font_size, 72, 72 );

    for ( gid = 0; gid < face->num_glyphs; gid++ )
    {
      if ( check_outlines         &&
           FT_IS_SCALABLE( face ) )
      {
        if ( !FT_Load_Glyph( face, gid, load_flags ) )
          FT_Outline_Decompose( &face->glyph->outline, &outlinefuncs, NULL );
      }
      else
        FT_Load_Glyph( face, gid, load_flags );

      if ( rasterize )
        FT_Render_Glyph( face->glyph, ft_render_mode_normal );
    }

    FT_Done_Face( face );
  }
开发者ID:Ahbee,项目名称:Cinder,代码行数:33,代码来源:ftrandom.c

示例13: FTGlyph

FTTextureGlyph::FTTextureGlyph (FT_GlyphSlot glyph, int id, int xOffset,
								int yOffset, GLsizei width, GLsizei height)
	: FTGlyph (glyph), destWidth(0), destHeight(0), glTextureID(id) {
	err = FT_Render_Glyph (glyph, FT_RENDER_MODE_NORMAL);
	if (err || glyph->format != ft_glyph_format_bitmap) return;
	
	FT_Bitmap bitmap = glyph->bitmap;
	destWidth  = bitmap.width;
	destHeight = bitmap.rows;
	
	if (destWidth && destHeight) {
#ifndef USE_GLES1
		glPushClientAttrib (GL_CLIENT_PIXEL_STORE_BIT);
		glPixelStorei (GL_UNPACK_LSB_FIRST, GL_FALSE);
		glPixelStorei (GL_UNPACK_ROW_LENGTH, 0);
#endif
		glPixelStorei (GL_UNPACK_ALIGNMENT, 1);
		
		glBindTexture (GL_TEXTURE_2D, glTextureID);
		glTexSubImage2D (GL_TEXTURE_2D, 0, xOffset, yOffset,
						 destWidth, destHeight, GL_ALPHA, GL_UNSIGNED_BYTE, bitmap.buffer);
		
#ifndef USE_GLES1
		glPopClientAttrib();
#endif
	}

	uv[0].X (static_cast<float>(xOffset) / static_cast<float>(width));
	uv[0].Y (static_cast<float>(yOffset) / static_cast<float>(height));
	uv[1].X (static_cast<float> (xOffset + destWidth) / static_cast<float>(width));
	uv[1].Y (static_cast<float> (yOffset + destHeight) / static_cast<float>(height));

	pos.X (glyph->bitmap_left);
	pos.Y (glyph->bitmap_top);
}
开发者ID:pseuudonym404,项目名称:tuxracer-touch,代码行数:35,代码来源:ft_font.cpp

示例14: glyphinfo

int glyphinfo(FT_Face face, FT_ULong ul)
{
    FT_UInt glyph_index;
    FT_GlyphSlot slot = face->glyph;
    int error;

    glyph_index = FT_Get_Char_Index(face, ul);
    error = FT_Load_Glyph( face, /* handle to face object */
                           glyph_index, /* glyph index */
                           FT_LOAD_DEFAULT ); /* load flags, see below */
    if ( error )
    {
        printf("FT_Load_Glyph() failed: %d (0x%08X)\n", error, error);
        return -1;
    }

     error = FT_Render_Glyph( face->glyph, FT_RENDER_MODE_NORMAL );
     if ( error )
     {
         printf("FT_Render_Glyph() failed: %d (0x%08X)\n", error, error);
         return -1;
     }

     if (face->glyph->advance.x <= HALF_WIDTH_MAX)
     {
         return HALF_WIDTH;
     }
     else
     {
         return DOUBLE_WIDTH;
     }
}
开发者ID:nobiruwa,项目名称:east-asian-ambiguous-width,代码行数:32,代码来源:ambiguous_width_comparison.c

示例15: FT_Get_Char_Index

void FreeTypeFont::doFillGlyphCache(GlyphCache& cache, const std::vector<char32_t>& characters)
#endif
{
    /** @bug Crash when atlas is too small */

    /* Get glyph codes from characters */
    std::vector<FT_UInt> charIndices;
    charIndices.resize(characters.size()+1);
    charIndices[0] = 0;
    std::transform(characters.begin(), characters.end(), charIndices.begin()+1,
        [this](const char32_t c) { return FT_Get_Char_Index(ftFont, c); });

    /* Remove duplicates (e.g. uppercase and lowercase mapped to same glyph) */
    std::sort(charIndices.begin(), charIndices.end());
    charIndices.erase(std::unique(charIndices.begin(), charIndices.end()), charIndices.end());

    /* Sizes of all characters */
    std::vector<Vector2i> charSizes;
    charSizes.reserve(charIndices.size());
    for(FT_UInt c: charIndices) {
        CORRADE_INTERNAL_ASSERT_OUTPUT(FT_Load_Glyph(ftFont, c, FT_LOAD_DEFAULT) == 0);
        charSizes.push_back(Vector2i(ftFont->glyph->metrics.width, ftFont->glyph->metrics.height)/64);
    }

    /* Create texture atlas */
    const std::vector<Rectanglei> charPositions = cache.reserve(charSizes);

    /* Render all characters to the atlas and create character map */
    unsigned char* pixmap = new unsigned char[cache.textureSize().product()]();
    /** @todo Some better way for this */
    #ifndef MAGNUM_TARGET_GLES2
    Image2D image(ImageFormat::Red, ImageType::UnsignedByte, cache.textureSize(), pixmap);
    #else
    Image2D image(Context::current() && Context::current()->isExtensionSupported<Extensions::GL::EXT::texture_rg>() ?
        ImageFormat::Red : ImageFormat::Luminance, ImageType::UnsignedByte, cache.textureSize(), pixmap);
    #endif
    for(std::size_t i = 0; i != charPositions.size(); ++i) {
        /* Load and render glyph */
        /** @todo B&W only if radius != 0 */
        FT_GlyphSlot glyph = ftFont->glyph;
        CORRADE_INTERNAL_ASSERT_OUTPUT(FT_Load_Glyph(ftFont, charIndices[i], FT_LOAD_DEFAULT) == 0);
        CORRADE_INTERNAL_ASSERT_OUTPUT(FT_Render_Glyph(glyph, FT_RENDER_MODE_NORMAL) == 0);

        /* Copy rendered bitmap to texture image */
        const FT_Bitmap& bitmap = glyph->bitmap;
        CORRADE_INTERNAL_ASSERT(std::abs(bitmap.width-charPositions[i].width()) <= 2);
        CORRADE_INTERNAL_ASSERT(std::abs(bitmap.rows-charPositions[i].height()) <= 2);
        for(Int yin = 0, yout = charPositions[i].bottom(), ymax = bitmap.rows; yin != ymax; ++yin, ++yout)
            for(Int xin = 0, xout = charPositions[i].left(), xmax = bitmap.width; xin != xmax; ++xin, ++xout)
                pixmap[yout*cache.textureSize().x() + xout] = bitmap.buffer[(bitmap.rows-yin-1)*bitmap.width + xin];

        /* Insert glyph parameters into cache */
        cache.insert(charIndices[i],
            Vector2i(glyph->bitmap_left, glyph->bitmap_top-charPositions[i].height()),
            charPositions[i]);
    }

    /* Set cache image */
    cache.setImage({}, image);
}
开发者ID:severin-lemaignan,项目名称:magnum-plugins,代码行数:60,代码来源:FreeTypeFont.cpp


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