• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ FT_Render_Glyph函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: Render

void FTFont::Render(Bitmap& bmp, int const x, int const y, Color const& color, unsigned const glyph) {
	if(!check_face()) {
		Font::Default()->Render(bmp, x, y, color, glyph);
		return;
	}

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

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

	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);

	for(int row = 0; row < ft_bitmap.rows; ++row) {
		for(size_t col = 0; col < pitch; ++col) {
			unsigned c = ft_bitmap.buffer[pitch * row + col];
			for(int bit = 7; bit >= 0; --bit) {
				if(c & (0x01 << bit)) {
					bmp.SetPixel(x + col * 8 + (7 - bit), y + row, color);
				}
			}
		}
	}
}
开发者ID:ChrisOelmueller,项目名称:Player,代码行数:32,代码来源:font.cpp


示例17: renderString

void renderString(SDL_Surface *screen, char *glyphs, int x, int y)
{
	int error;
	int c;
	int cx = x;
	int cy = y;
	for(c = 0;c<strlen(glyphs);c++)
	{
		if(glyphs[c] == '\n')
		{
			cy+=60;
			cx = x;
			continue;
		}
	   int glyph_index = FT_Get_Char_Index( face, glyphs[c]);
	   error = FT_Load_Glyph( face, glyph_index, 0 ); // Load 'A' glyph with default parameters (0)
	   if(error)
	   {
			continue;
	   }
	
	   error = FT_Render_Glyph( face->glyph, FT_RENDER_MODE_NORMAL ); // Can haz bitmap?
	
	   if(error)
	   {
			continue;
	   }
	
		int i, j;
		for(i = 0; i<face->glyph->bitmap.rows;i++)
			for(j = 0;j<face->glyph->bitmap.width;j++)
				put_pixel(screen,face->glyph->bitmap.buffer[i*face->glyph->bitmap.pitch+j],cx+j,cy+i+(32-face->glyph->bitmap.rows));
		cx += face->glyph->bitmap.width+5;
		}
}
开发者ID:ElFeesho,项目名称:OldCProjects,代码行数:35,代码来源:main.c


示例18: FT_Get_Char_Index

int FreeType::plotGlyph(GlyphDescr* f, Glyph* g)
{
    unsigned int glyphIndex = FT_Get_Char_Index(m_face, f->c);
    int r = FT_Load_Glyph(m_face, glyphIndex, FT_LOAD_DEFAULT);
    if (r) {
        clc::Log::error(LOG_NAME, "FT_Load_Glyph failed: %d", r);
        return -1;
    }
    if (m_face->glyph->format != FT_GLYPH_FORMAT_BITMAP) {
        r = FT_Render_Glyph(m_face->glyph, FT_RENDER_MODE_NORMAL);
        if (r) {
            clc::Log::error(LOG_NAME, "FT_Render_Glyph failed: %d", r);
            return -1;
        }
    }

    FT_GlyphSlot slot = m_face->glyph;
    g->w = slot->bitmap.width;
    g->h = slot->bitmap.rows;
    g->bitmap = new uint8_t[g->w * g->h];
    memcpy(g->bitmap, slot->bitmap.buffer, g->w * g->h);
    g->offsetX = slot->bitmap_left;
    g->offsetY = slot->bitmap_top;
    g->advanceX = slot->advance.x >> 6;
    g->advanceY = slot->advance.y >> 6;
    g->height = m_face->size->metrics.height >> 6;
    return 0;
}
开发者ID:ccoffing,项目名称:OcherBook,代码行数:28,代码来源:FreeType.cpp


示例19: FT_Get_Char_Index

cv::Mat SampleGenetator::genSample(const wchar_t wc, const uchar bgColor, const uchar fgColor)
{
	cv::Mat result;

    FT_UInt glyph_index = FT_Get_Char_Index(face, wc);
    FT_Load_Glyph(face, glyph_index, FT_LOAD_DEFAULT);
	FT_Render_Glyph(face->glyph, FT_RENDER_MODE_NORMAL);
    FT_GlyphSlot slot = face->glyph;

    int rows = slot->bitmap.rows;
    int cols = slot->bitmap.width;

	result = cv::Mat(rows, cols, CV_8UC1);
	result.setTo(bgColor);

    for (int row = 0; row < rows; ++row) 
	{
        for (int col = 0; col < cols; ++col) 
		{
            const int offset = row  * slot->bitmap.pitch + col;
            if (slot->bitmap.buffer[offset]) 
			{
				result.at<uchar>(row, col) = fgColor;
            }
        }
    }
	return result;
}
开发者ID:xylcbd,项目名称:SampleGenetator,代码行数:28,代码来源:SampleGenetator.cpp


示例20: FT_Get_Char_Index

FontPixelBuffer FontEngine_Freetype::get_font_glyph_subpixel(int glyph)
{
	FontPixelBuffer font_buffer;
	FT_GlyphSlot slot = face->glyph;
	FT_UInt glyph_index;

	// Get glyph index
	glyph_index = FT_Get_Char_Index(face, glyph);

	FT_Error error;

	error = FT_Load_Glyph(face, glyph_index, FT_LOAD_TARGET_LCD );
	if (error) return font_buffer;

	error = FT_Render_Glyph( face->glyph, FT_RENDER_MODE_LCD);

	font_buffer.glyph = glyph;
	// Set Increment pen position
	font_buffer.increment.x = (slot->advance.x+32) >> 6;
	font_buffer.increment.y = (slot->advance.y+32) >> 6;

	if (error || slot->bitmap.rows == 0 || slot->bitmap.width == 0)
		return font_buffer;

	// Set destination offset
	font_buffer.offset.x = slot->bitmap_left;
	font_buffer.offset.y = -slot->bitmap_top;

	int src_width = slot->bitmap.width;
	int src_height = slot->bitmap.rows;
	int src_pitch = slot->bitmap.pitch;

	// Convert the bitmap

	PixelBuffer pixelbuffer(src_width/3, src_height, tf_rgba8);
	font_buffer.buffer = pixelbuffer;
	font_buffer.buffer_rect = pixelbuffer.get_size();
	font_buffer.empty_buffer = false;

	unsigned char *src_data = slot->bitmap.buffer;
	unsigned char *pixel_data = (unsigned char *) font_buffer.buffer.get_data();
	int dest_pitch = font_buffer.buffer.get_pitch();

	// For 8bit bitmaps
	for (int ycnt = 0; ycnt < src_height; ycnt++)
	{
		unsigned char *dest_data = pixel_data;
		for (int xcnt = 0; xcnt < src_width/3; xcnt++)
		{
			*(dest_data++)= src_data[xcnt*3+2];
			*(dest_data++)= src_data[xcnt*3+1];
			*(dest_data++)= src_data[xcnt*3+0];
			*(dest_data++)= 0;
		}
		pixel_data += dest_pitch;
		src_data += src_pitch;
	}

	return font_buffer;
}
开发者ID:wbyang1985,项目名称:ClanLib,代码行数:60,代码来源:font_engine_freetype.cpp



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ FT_STREAM_POS函数代码示例发布时间:2022-05-30
下一篇:
C++ FT_READ_USHORT函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap