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


C++ FT_HAS_KERNING函数代码示例

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


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

示例1: numGlyphs

FTFace::FTFace(const unsigned char *pBufferBytes, size_t bufferSizeInBytes,
               bool precomputeKerning)
:   numGlyphs(0),
    fontEncodingList(0),
    kerningCache(0),
    err(0)
{
    const FT_Long DEFAULT_FACE_INDEX = 0;
    ftFace = new FT_Face;

    err = FT_New_Memory_Face(*FTLibrary::Instance().GetLibrary(),
                             (FT_Byte const *)pBufferBytes, (FT_Long)bufferSizeInBytes,
                             DEFAULT_FACE_INDEX, ftFace);
    if(err)
    {
        delete ftFace;
        ftFace = 0;
        return;
    }

    numGlyphs = (*ftFace)->num_glyphs;
    hasKerningTable = (FT_HAS_KERNING((*ftFace)) != 0);

    if(hasKerningTable && precomputeKerning)
    {
        BuildKerningCache();
    }
}
开发者ID:UIKit0,项目名称:ftgles-1,代码行数:28,代码来源:FTFace.cpp

示例2: getKerning

float Font::getKerning(Uint32 first, Uint32 second, unsigned int characterSize) const
{
    // Special case where first or second is 0 (null character)
    if (first == 0 || second == 0)
        return 0.f;

    FT_Face face = static_cast<FT_Face>(m_face);

    if (face && FT_HAS_KERNING(face) && setCurrentSize(characterSize))
    {
        // Convert the characters to indices
        FT_UInt index1 = FT_Get_Char_Index(face, first);
        FT_UInt index2 = FT_Get_Char_Index(face, second);

        // Get the kerning vector
        FT_Vector kerning;
        FT_Get_Kerning(face, index1, index2, FT_KERNING_DEFAULT, &kerning);

        // X advance is already in pixels for bitmap fonts
        if (!FT_IS_SCALABLE(face))
            return static_cast<float>(kerning.x);

        // Return the X advance
        return static_cast<float>(kerning.x) / static_cast<float>(1 << 6);
    }
    else
    {
        // Invalid font, or no kerning
        return 0.f;
    }
}
开发者ID:42bottles,项目名称:SFML,代码行数:31,代码来源:Font.cpp

示例3: FT_HAS_KERNING

int  FontFreeType::getHorizontalKerningForChars(unsigned short firstChar, unsigned short secondChar) const
{
    if (!_fontRef)
        return 0;

    bool hasKerning = FT_HAS_KERNING( _fontRef ) != 0;
    
    if (!hasKerning)
        return 0;
    
    // get the ID to the char we need
    int glyphIndex1 = FT_Get_Char_Index(_fontRef, firstChar);
    
    if (!glyphIndex1)
        return 0;
    
    // get the ID to the char we need
    int glyphIndex2 = FT_Get_Char_Index(_fontRef, secondChar);
    
    if (!glyphIndex2)
        return 0;
    
    FT_Vector kerning;
    
    if (FT_Get_Kerning( _fontRef, glyphIndex1, glyphIndex2,  FT_KERNING_DEFAULT,  &kerning))
        return 0;
    
    return (kerning.x >> 6);
}
开发者ID:0x0c,项目名称:cocos2d-x,代码行数:29,代码来源:CCFontFreeType.cpp

示例4: lock

osg::Vec2 FreeTypeFont::getKerning(unsigned int leftcharcode,unsigned int rightcharcode, osgText::KerningType kerningType)
{
    OpenThreads::ScopedLock<OpenThreads::Mutex> lock(FreeTypeLibrary::instance()->getMutex());

    if (!FT_HAS_KERNING(_face) || (kerningType == osgText::KERNING_NONE)) return osg::Vec2(0.0f,0.0f);

    FT_Kerning_Mode mode = (kerningType==osgText::KERNING_DEFAULT) ? ft_kerning_default : ft_kerning_unfitted;

    // convert character code to glyph index
    FT_UInt left = FT_Get_Char_Index( _face, leftcharcode );
    FT_UInt right = FT_Get_Char_Index( _face, rightcharcode );

    // get the kerning distances.
    FT_Vector  kerning;

    FT_Error error = FT_Get_Kerning( _face,                     // handle to face object
                                     left,                      // left glyph index
                                     right,                     // right glyph index
                                     mode,                      // kerning mode
                                     &kerning );                // target vector

    if (error)
    {
        OSG_WARN << "FT_Get_Kerning(...) returned error code " <<std::hex<<error<<std::dec<< std::endl;
        return osg::Vec2(0.0f,0.0f);
    }

    float coord_scale = getCoordScale();

    return osg::Vec2((float)kerning.x*coord_scale,(float)kerning.y*coord_scale);
}
开发者ID:Kurdakov,项目名称:emscripten_OSG,代码行数:31,代码来源:FreeTypeFont.cpp

示例5: FT_Set_Pixel_Sizes

void Font::draw(IScene* scene, const char* text, glm::mat4 transform, float font_size, glm::vec3 color)
{
	FT_Set_Pixel_Sizes(m_font_face, font_size, font_size);
    glUseProgram(TEXT_PROGRAM);
    checkGLError();

    glm::vec3 pen(0, 0, 0);
    char prev = 0;
    bool kern = FT_HAS_KERNING(m_font_face);
    for(const char* i = text; i[0]; ++i) {
        FT_UInt index = FT_Get_Char_Index(m_font_face, i[0]);
        Glyph glyph = renderGlyph(i[0], font_size);

        if(prev && kern && i) {
            FT_Vector delta;
            FT_Get_Kerning(m_font_face, prev, index, FT_KERNING_DEFAULT, &delta);
            pen.x += delta.x * scene->getDPU();
            //fprintf(stderr, "%ld\n", delta.x);
        }

        if(i[0] == '\n') {
            pen.x = 0;
            pen.y += font_size;
            prev = 0;
            continue;
        } else if(i[0] == ' ' || glyph.id == 0) {
            pen.x += font_size;
            prev = 0;
            continue;
        }

        glUniform3f(m_color_uniform, color.x, color.y, color.z);
        glm::vec3 offset(glyph.bearing.x, -glyph.bearing.y, 0.0f);

        glm::mat4 mvp = scene->getActiveProjectionMatrix() *
                        scene->getActiveViewMatrix() *
                        transform *
                        glm::translate(glm::mat4(1), -(pen + offset) * scene->getDPU()) *
                        glm::scale(glm::mat4(1), glm::vec3(glyph.dimensions.x * scene->getDPU(), glyph.dimensions.y * scene->getDPU(), 1.0f));
        //fprintf(stderr, "Result: %f, %f, %f, %f\n", glyph.dimensions.x, glyph.dimensions.y, glyph.dimensions.x * scene->getDPU(), glyph.dimensions.y * scene->getDPU());
        glUniformMatrix4fv(m_transform_uniform, 1, GL_FALSE, &mvp[0][0]);
        glEnableVertexAttribArray(m_vertex_position);
        glBindBuffer(GL_ARRAY_BUFFER, QUAD_BUFFER);
        glVertexAttribPointer(m_vertex_position, 3, GL_FLOAT, GL_FALSE, 0, (void*)0);

        glActiveTexture(GL_TEXTURE0);
        glBindTexture(GL_TEXTURE_2D, glyph.texture);
        glUniform1i(m_texture_uniform, 0);
        checkGLError();

        glDrawArrays(GL_TRIANGLES, 0, 6);
        checkGLError();

        glDisableVertexAttribArray(m_vertex_position);
        pen.x += glyph.advance;
        //fprintf(stderr, "(%d)\n", (int)glyph.advance);
        prev = index;
    }
}
开发者ID:Df458,项目名称:DFEngine,代码行数:59,代码来源:Font.cpp

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

示例7: FT_HAS_KERNING

/**
 * Default constructor for the FreeTypeGX class.
 *
 * @param textureFormat	Optional format (GX_TF_*) of the texture as defined by the libogc gx.h header file. If not specified default value is GX_TF_RGBA8.
 * @param vertexIndex	Optional vertex format index (GX_VTXFMT*) of the glyph textures as defined by the libogc gx.h header file. If not specified default value is GX_VTXFMT1.
 */
FreeTypeGX::FreeTypeGX(FT_UInt pixelSize, uint8_t textureFormat, uint8_t vertexIndex)
{
	this->textureFormat = textureFormat;
	this->setVertexFormat(vertexIndex);
	this->setCompatibilityMode(FTGX_COMPATIBILITY_DEFAULT_TEVOP_GX_PASSCLR | FTGX_COMPATIBILITY_DEFAULT_VTXDESC_GX_NONE);
	this->ftPointSize = pixelSize;
	this->ftKerningEnabled = FT_HAS_KERNING(ftFace);
}
开发者ID:clobber,项目名称:wii7800,代码行数:14,代码来源:FreeTypeGX.cpp

示例8: getKerning

//-----------------------------------------------------------
int ofTrueTypeFont::getKerning(uint32_t c, uint32_t prevC) const{
    if(FT_HAS_KERNING( face )){
        FT_Vector kerning;
        FT_Get_Kerning(face.get(), FT_Get_Char_Index(face.get(), c), FT_Get_Char_Index(face.get(), prevC), FT_KERNING_UNFITTED, &kerning);
        return kerning.x * fontUnitScale;
    }else{
        return 0;
    }
}
开发者ID:anwar-hegazy,项目名称:openFrameworks,代码行数:10,代码来源:ofTrueTypeFont.cpp

示例9: Java_com_badlogic_gdx_graphics_g2d_freetype_FreeType_hasKerning

JNIEXPORT jboolean JNICALL Java_com_badlogic_gdx_graphics_g2d_freetype_FreeType_hasKerning(JNIEnv* env, jclass clazz, jlong face) {


//@line:656

   	return FT_HAS_KERNING(((FT_Face)face));
   

}
开发者ID:0302zq,项目名称:libgdx,代码行数:9,代码来源:com.badlogic.gdx.graphics.g2d.freetype.FreeType.cpp

示例10: FT_HAS_KERNING

/**
 * Default constructor for the FreeTypeGX class.
 *
 * @param vertexIndex	Optional vertex format index (GX_VTXFMT*) of the glyph textures as defined by the libogc gx.h header file. If not specified default value is GX_VTXFMT1.
 */
FreeTypeGX::FreeTypeGX(FT_UInt pixelSize, uint8_t vertexIndex) {
        this->setVertexFormat(vertexIndex);
        this->setCompatibilityMode(FTGX_COMPATIBILITY_DEFAULT_TEVOP_GX_PASSCLR | FTGX_COMPATIBILITY_DEFAULT_VTXDESC_GX_NONE);
        this->ftPointSize = pixelSize;
        this->ftKerningEnabled = FT_HAS_KERNING(ftFace);

        if (glyphData == NULL)
                glyphData = (uint8_t *) malloc(256 * 256 * 4);
}
开发者ID:LibXenonProject,项目名称:snes9x-gx,代码行数:14,代码来源:FreeTypeGX.cpp

示例11: setKerningEnabled

/**
 * Enables or disables kerning of the output text.
 *
 * This routine enables or disables kerning of the output text only if kerning is supported by the font.
 * Note that by default kerning is enabled if it is supported by the font.
 *
 * @param enabled       The enabled state of the font kerning.
 * @return The resultant enabled state of the font kerning.
 */
bool FreeTypeGX::setKerningEnabled(bool enabled) {
        if(!enabled) {
                return this->ftKerningEnabled = false;
        }

        if(FT_HAS_KERNING(this->ftFace)) {
                return this->ftKerningEnabled = true;
        }

        return false;
}
开发者ID:N4u,项目名称:WiiCraft,代码行数:20,代码来源:FreeTypeGX.cpp

示例12: FT_Init_FreeType

Font::Font(u32 Size, const char *Font_Path, Minimum *min){
	FontColor = COLOR_BLACK;
	FontSize = Size;
	Lenght = 0;
	m = min;
	FT_Init_FreeType(&library);
	FT_New_Face(library,Font_Path,0,&face);
	FT_Stroker_New(library,&stroker);
	Kerning = FT_HAS_KERNING(face);
	FT_Set_Pixel_Sizes(face,0,FontSize);
	font=0;
}
开发者ID:roman5566,项目名称:NoRSX,代码行数:12,代码来源:Font.cpp

示例13: add_kerning

void gfx_font_adapter::add_kerning(unsigned int first, unsigned int second, scalar* x, scalar* y)
{
    if (m_impl->font && first && second && FT_HAS_KERNING(m_impl->font)) {
        FT_Vector delta;
        FT_Get_Kerning(m_impl->font, first, second, FT_KERNING_DEFAULT, &delta);
        scalar dx = int26p6_to_flt(delta.x);
        scalar dy = int26p6_to_flt(delta.y);
        if (m_impl->font->glyph->format != FT_GLYPH_FORMAT_BITMAP)
            m_impl->matrix.transform_2x2(&dx, &dy);
        *x += dx;
        *y += dy;
    }
}
开发者ID:corefan,项目名称:img_picasso,代码行数:13,代码来源:gfx_font_adapter_freetype2.cpp

示例14: glyphstring_create

static void glyphstring_create(FT_Face face, Text *text, FT_Glyph *glyph_string,
		FT_Vector *pos)
{
	const uint8_t *string = text->string;
	FT_Bool has_kerning;
	FT_UInt glyph_index, previous;
	FT_Vector pen, delta;
	uint32_t charcode;
	int i;

	has_kerning = FT_HAS_KERNING(face);
	previous = 0;
	i = 0;
	pen.x = pen.y = 0;
	while (string[0] != '\0')
	{
		charcode = utf8_next(&string);
		glyph_index = FT_Get_Char_Index(face, charcode);
		if (has_kerning && previous && glyph_index)
			FT_Get_Kerning(face, previous, glyph_index, FT_KERNING_DEFAULT,
					&delta);
		else
			delta.x = 0;

		if (glyph_index == 0)
			log_err("Glyph for character U+%X missing\n", charcode);

		if (FT_Load_Glyph(face, glyph_index, FT_LOAD_RENDER) != 0)
		{
			log_err("Error loading glyph for character U+%X\n", charcode);
			continue;
		}
		if (FT_Get_Glyph(face->glyph, &glyph_string[i]) != 0)
		{
			log_err("Error copying glyph for character U+%X\n", charcode);
			continue;
		}

		pen.x += delta.x;

		pos[i] = pen;

		pen.x += face->glyph->advance.x;
		pen.y += face->glyph->advance.y;

		previous = glyph_index;
		i++;
	}

	text->num_glyphs = i;
}
开发者ID:kaspermeerts,项目名称:kosmos,代码行数:51,代码来源:font.c

示例15:

ts::Vector2i ts::resources::impl::Font_face::kerning(utf8::uint32_t first, utf8::uint32_t second, std::uint32_t character_size)
{
    if (first && second && FT_HAS_KERNING(face))
    {
        set_character_size(character_size);

        auto first_index = FT_Get_Char_Index(face, first);
        auto second_index = FT_Get_Char_Index(face, second);

        FT_Vector kerning;
        FT_Get_Kerning(face, first_index, second_index, FT_KERNING_DEFAULT, &kerning);
        
        return Vector2i(kerning.x >> 6, kerning.y >> 6);            
    }
开发者ID:mnewhouse,项目名称:tspp,代码行数:14,代码来源:font_face.cpp


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