本文整理汇总了C++中FT_Get_Kerning函数的典型用法代码示例。如果您正苦于以下问题:C++ FT_Get_Kerning函数的具体用法?C++ FT_Get_Kerning怎么用?C++ FT_Get_Kerning使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了FT_Get_Kerning函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: FT_Get_Char_Index
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;
}
}
示例2: FT_HAS_KERNING
int FontFreeType::getHorizontalKerningForChars(unsigned short firstChar, unsigned short secondChar)
{
if (!_fontRef)
return 0;
bool hasKerning = FT_HAS_KERNING( _fontRef );
if (!hasKerning)
return 0;
// get the ID to the char we need
int glyph_index1 = FT_Get_Char_Index(_fontRef, firstChar);
if (!glyph_index1)
return 0;
// get the ID to the char we need
int glyph_index2 = FT_Get_Char_Index(_fontRef, secondChar);
if (!glyph_index2)
return 0;
FT_Vector kerning;
if (FT_Get_Kerning( _fontRef, glyph_index1, glyph_index2, FT_KERNING_DEFAULT, &kerning ))
return 0;
return ( kerning.x >> 6 );
}
示例3: RenderChar
int RenderChar(FT_ULong currentchar, int sx, int sy, int ex, int color)
{
int row, pitch, bit, x = 0, y = 0;
FT_UInt glyphindex;
FT_Vector kerning;
FTC_Node anode;
//load char
if(!(glyphindex = FT_Get_Char_Index(face, currentchar)))
{
// printf("<FT_Get_Char_Index for Char \"%c\" failed with Errorcode 0x%.2X>\n", (int)currentchar, error);
return 0;
}
if((error = FTC_SBitCache_Lookup(cache, &desc, glyphindex, &sbit, &anode)))
{
// printf("<FTC_SBitCache_Lookup for Char \"%c\" failed with Errorcode 0x%.2X>\n", (int)currentchar, error);
return 0;
}
if(use_kerning)
{
FT_Get_Kerning(face, prev_glyphindex, glyphindex, ft_kerning_default, &kerning);
prev_glyphindex = glyphindex;
kerning.x >>= 6;
}
else kerning.x = 0;
示例4: FT_Get_Kerning
//------------------------------------------------------------------------
bool font_engine_freetype_base::add_kerning(unsigned first, unsigned second,
double* x, double* y)
{
if(m_cur_face && first && second && FT_HAS_KERNING(m_cur_face))
{
FT_Vector delta;
FT_Get_Kerning(m_cur_face, first, second,
FT_KERNING_DEFAULT, &delta);
double dx = int26p6_to_dbl(delta.x);
double dy = int26p6_to_dbl(delta.y);
if(m_glyph_rendering == glyph_ren_outline ||
m_glyph_rendering == glyph_ren_agg_mono ||
m_glyph_rendering == glyph_ren_agg_gray8)
{
m_affine.transform_2x2(&dx, &dy);
}
*x += dx;
*y += dy;
return true;
}
return false;
}
示例5: FT_Get_Kerning
void FTFace::BuildKerningCache()
{
FT_Vector kernAdvance;
kernAdvance.x = 0;
kernAdvance.y = 0;
kerningCache = new FTGL_DOUBLE[FTFace::MAX_PRECOMPUTED
* FTFace::MAX_PRECOMPUTED * 2];
for(unsigned int j = 0; j < FTFace::MAX_PRECOMPUTED; j++)
{
for(unsigned int i = 0; i < FTFace::MAX_PRECOMPUTED; i++)
{
err = FT_Get_Kerning(*ftFace, i, j, ft_kerning_unfitted,
&kernAdvance);
if(err)
{
delete[] kerningCache;
kerningCache = NULL;
return;
}
kerningCache[2 * (j * FTFace::MAX_PRECOMPUTED + i)] =
static_cast<FTGL_DOUBLE>(kernAdvance.x) / 64.0;
kerningCache[2 * (j * FTFace::MAX_PRECOMPUTED + i) + 1] =
static_cast<FTGL_DOUBLE>(kernAdvance.y) / 64.0;
}
}
}
示例6: glf_get_string_len
float glf_get_string_len(gl_tex_font_p glf, const char *text, int n)
{
float x = 0.0;
if((glf != nullptr) && (glf->ft_face != nullptr))
{
uint8_t *nch;
uint8_t *nch2;
uint8_t *ch = (uint8_t*)text;
uint32_t curr_utf32, next_utf32;
int i;
nch = utf8_to_utf32(ch, &curr_utf32);
curr_utf32 = FT_Get_Char_Index(glf->ft_face, curr_utf32);
for(i = 0; (*ch != 0) && !((n >= 0) && (i >= n)); i++)
{
FT_Vector kern;
nch2 = utf8_to_utf32(nch, &next_utf32);
next_utf32 = FT_Get_Char_Index(glf->ft_face, next_utf32);
ch = nch;
nch = nch2;
FT_Get_Kerning(glf->ft_face, curr_utf32, next_utf32, FT_KERNING_UNSCALED, &kern); // kern in 1/64 pixel
curr_utf32 = next_utf32;
x += static_cast<GLfloat>(kern.x + glf->glyphs[curr_utf32].advance_x) / 64.0;
}
}
return x;
}
示例7: FTPoint
FTPoint FTFace::KernAdvance(unsigned int index1, unsigned int index2)
{
FTGL_DOUBLE x, y;
if(!hasKerningTable || !index1 || !index2)
{
return FTPoint(0.0, 0.0);
}
if(kerningCache && index1 < FTFace::MAX_PRECOMPUTED
&& index2 < FTFace::MAX_PRECOMPUTED)
{
x = kerningCache[2 * (index2 * FTFace::MAX_PRECOMPUTED + index1)];
y = kerningCache[2 * (index2 * FTFace::MAX_PRECOMPUTED + index1) + 1];
return FTPoint(x, y);
}
FT_Vector kernAdvance;
kernAdvance.x = kernAdvance.y = 0;
err = FT_Get_Kerning(*ftFace, index1, index2, ft_kerning_unfitted,
&kernAdvance);
if(err)
{
return FTPoint(0.0f, 0.0f);
}
x = static_cast<float>(kernAdvance.x) / 64.0f;
y = static_cast<float>(kernAdvance.y) / 64.0f;
return FTPoint(x, y);
}
示例8: FT_Get_Kerning
//-----------------------------------------------------------
int ofTrueTypeFont::getKerning(int c, int prevC) const{
if(useKerning){
FT_Vector kerning;
FT_Get_Kerning(face, FT_Get_Char_Index(face, prevC), FT_Get_Char_Index(face, c), FT_KERNING_UNFITTED, &kerning);
return kerning.x>>6;
}else{
return 0;
示例9: line_extents
static void line_extents(VGFT_FONT_T *font, VGfloat *x, VGfloat *y, const char *text, int chars_count)
{
int i;
int prev_glyph_index = 0;
if (chars_count == 0) return;
for (i=0; i < chars_count; i++)
{
int glyph_index = FT_Get_Char_Index(font->ft_face, text[i]);
if (!glyph_index) return;
if (i != 0)
{
FT_Vector kern;
if (FT_Get_Kerning(font->ft_face, prev_glyph_index, glyph_index,
FT_KERNING_DEFAULT, &kern))
{
assert(0);
}
*x += float_from_26_6(kern.x);
*y += float_from_26_6(kern.y);
}
FT_Load_Glyph(font->ft_face, glyph_index, FT_LOAD_DEFAULT);
*x += float_from_26_6(font->ft_face->glyph->advance.x);
}
}
示例10: lock
osg::Vec2 FreeTypeFont::getKerning(const osgText::FontResolution& fontRes, unsigned int leftcharcode, unsigned int rightcharcode, osgText::KerningType kerningType)
{
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(FreeTypeLibrary::instance()->getMutex());
setFontResolution(fontRes);
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);
}
示例11: FT_Get_Char_Index
GLubyte *app::font::glyph(FT_Int32 flag, int curr, int prev,
int& x, int& y, int& w, int& h, int& a, int& k)
{
FT_Vector kern;
// Look up the current pair of characters.
FT_UInt L = FT_Get_Char_Index(face, prev);
FT_UInt R = FT_Get_Char_Index(face, curr);
// Get the kerning and glyph sizes.
FT_Get_Kerning(face, L, R, FT_KERNING_DEFAULT, &kern);
FT_Load_Glyph (face, R, flag);
// Convert these values to pixels and return the buffer.
x = face->glyph->metrics.horiBearingX >> 6;
y = face->glyph->metrics.horiBearingY >> 6;
w = face->glyph->metrics.width >> 6;
h = face->glyph->metrics.height >> 6;
a = face->glyph->advance.x >> 6;
k = kern.x >> 6;
return (GLubyte *) face->glyph->bitmap.buffer;
}
示例12: 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;
}
}
示例13: 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);
}
示例14: glyph_array_add_text
static cairo_status_t
glyph_array_add_text(glyph_array_t *glyphs, cairo_t *cr, const char *s, double spacing)
{
cairo_scaled_font_t *scaled_font;
cairo_status_t status;
FT_Face face;
unsigned long charcode;
unsigned int index;
cairo_text_extents_t extents;
const char *p;
FT_Vector kerning;
double kern_x;
int first = TRUE;
scaled_font = cairo_get_scaled_font (cr);
status = cairo_scaled_font_status (scaled_font);
if (status)
return status;
face = cairo_ft_scaled_font_lock_face (scaled_font);
if (face == NULL)
return CAIRO_STATUS_FONT_TYPE_MISMATCH;
p = s;
while (*p)
{
charcode = *p;
index = FT_Get_Char_Index (face, charcode);
glyphs->glyph_list[glyphs->num_glyphs].index = index;
if (first) {
first = FALSE;
glyphs->glyph_list[glyphs->num_glyphs].x = glyphs->x;
glyphs->glyph_list[glyphs->num_glyphs].y = glyphs->y;
} else {
cairo_glyph_extents (cr, &glyphs->glyph_list[glyphs->num_glyphs - 1], 1, &extents);
FT_Get_Kerning (face,
glyphs->glyph_list[glyphs->num_glyphs - 1].index,
glyphs->glyph_list[glyphs->num_glyphs].index,
FT_KERNING_UNSCALED,
&kerning);
kern_x = DOUBLE_FROM_26_6(kerning.x);
glyphs->glyph_list[glyphs->num_glyphs].x =
glyphs->glyph_list[glyphs->num_glyphs - 1].x + extents.x_advance + kern_x + spacing;
glyphs->glyph_list[glyphs->num_glyphs].y =
glyphs->glyph_list[glyphs->num_glyphs - 1].y + extents.y_advance;
}
cairo_glyph_extents (cr, &glyphs->glyph_list[glyphs->num_glyphs], 1, &extents);
glyphs->x = glyphs->glyph_list[glyphs->num_glyphs].x + extents.x_advance + spacing;
glyphs->y = glyphs->glyph_list[glyphs->num_glyphs].y + extents.y_advance;
p++;
glyphs->num_glyphs++;
}
cairo_ft_scaled_font_unlock_face (scaled_font);
return CAIRO_STATUS_SUCCESS;
}
示例15: FT_Get_Char_Index
GLvec2 Font::kerning(char prev, char code) const {
// Returns kerning in units normalized by font size
FT_Vector delta;
FT_Face face = (FT_Face)face_;
FT_UInt prevIndex = FT_Get_Char_Index(face, prev);
FT_UInt curIndex = FT_Get_Char_Index(face, code);
FT_Get_Kerning(face, prevIndex, curIndex, FT_KERNING_DEFAULT, &delta);
return GLvec2((delta.x >> 6)/(GLfloat)size_, (delta.y >> 6)/(GLfloat)size_);
}