本文整理汇总了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();
}
}
示例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;
}
}
示例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);
}
示例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);
}
示例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;
}
}
示例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);
}
示例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);
}
示例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;
}
}
示例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));
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}
}
示例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;
}
示例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);
}