Exemple #1
0
/**
 * 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];
		}
Exemple #2
0
/**
 * 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 addressable
 * 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( this->ftFace, charCode );
        if (!FT_Load_Glyph(this->ftFace, gIndex, FT_LOAD_DEFAULT | FT_LOAD_RENDER)) {

                if(this->ftFace->glyph->format == FT_GLYPH_FORMAT_BITMAP) {
                        FT_Bitmap *glyphBitmap = &(this->ftFace->glyph->bitmap);

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

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

                        return &this->fontData[charCode];
                }
        }