Add functions for harfbuzz

parent 77f0f1a9
......@@ -9,28 +9,30 @@
FTGL_ERROR_START_LIST
FTGL_ERRORDEF_( Texture_Atlas_Full, 0x00,
"Texture atlas is full" )
FTGL_ERRORDEF_( Cannot_Load_File, 0x01,
"unable to load file" )
FTGL_ERRORDEF_( Font_Unavailable, 0x02,
"no font available" )
FTGL_ERRORDEF_( No_Font_File_Given, 0x03,
"no font file given" )
FTGL_ERRORDEF_( Out_Of_Memory, 0x04,
"out of memory" )
FTGL_ERRORDEF_( Unimplemented_Function, 0x05,
"unimplemented function" )
FTGL_ERRORDEF_( Cant_Match_Family, 0x06,
"fontconfig error: could not match family" )
FTGL_ERRORDEF_( No_Font_In_Markup, 0x07,
"Markup doesn't have a font" )
FTGL_ERRORDEF_( No_Size_Specified, 0x08,
"No size specified for attribute" )
FTGL_ERRORDEF_( No_Format_Specified, 0x09,
"No format specified for attribute" )
FTGL_ERRORDEF_( Vertex_Attribute_Format_Wrong, 0x0A,
"Vertex attribute format not understood" )
FTGL_ERRORDEF_( Texture_Atlas_Full, 0x01,
"Texture atlas is full" )
FTGL_ERRORDEF_( Cannot_Load_File, 0x02,
"unable to load file" )
FTGL_ERRORDEF_( Font_Unavailable, 0x03,
"no font available" )
FTGL_ERRORDEF_( No_Font_File_Given, 0x04,
"no font file given" )
FTGL_ERRORDEF_( Out_Of_Memory, 0x05,
"out of memory" )
FTGL_ERRORDEF_( Unimplemented_Function, 0x06,
"unimplemented function" )
FTGL_ERRORDEF_( Cant_Match_Family, 0x07,
"fontconfig error: could not match family" )
FTGL_ERRORDEF_( No_Font_In_Markup, 0x08,
"Markup doesn't have a font" )
FTGL_ERRORDEF_( No_Size_Specified, 0x09,
"No size specified for attribute" )
FTGL_ERRORDEF_( No_Format_Specified, 0x0A,
"No format specified for attribute" )
FTGL_ERRORDEF_( Vertex_Attribute_Format_Wrong, 0x0B,
"Vertex attribute format not understood" )
FTGL_ERRORDEF_( Load_Color_Not_Available, 0x0C,
"FT_LOAD_COLOR not available" )
FTGL_ERROR_END_LIST
......
......@@ -496,17 +496,25 @@ texture_font_delete( texture_font_t *self )
free( self );
}
// ------------------------------------------------ texture_font_find_glyph ---
texture_glyph_t *
texture_font_find_glyph( texture_font_t * self,
const char * codepoint )
{
uint32_t ucodepoint = utf8_to_utf32( codepoint );
uint32_t i = ucodepoint >> 8;
uint32_t j = ucodepoint & 0xFF;
texture_glyph_t **glyph_index1, *glyph;
if(ucodepoint == -1)
if(!codepoint)
return (texture_glyph_t *)self->atlas->special;
return texture_font_find_glyph_gi(self, utf8_to_utf32( codepoint ));
}
// ---------------------------------------------- texture_font_find_glyph_gi ---
texture_glyph_t *
texture_font_find_glyph_gi( texture_font_t * self,
uint32_t codepoint )
{
uint32_t i = codepoint >> 8;
uint32_t j = codepoint & 0xFF;
texture_glyph_t **glyph_index1, *glyph;
if(self->glyphs->size <= i)
return NULL;
......@@ -566,7 +574,26 @@ texture_font_index_glyph( texture_font_t * self,
// ------------------------------------------------ texture_font_load_glyph ---
int
texture_font_load_glyph( texture_font_t * self,
const char * codepoint )
const char * codepoint )
{
/* codepoint NULL is special : it is used for line drawing (overline,
* underline, strikethrough) and background.
*/
if( !codepoint ) {
return 1;
}
uint32_t ucodepoint = utf8_to_utf32(codepoint);
return texture_font_load_glyph_gi( self,
FT_Get_Char_Index( self->face, ucodepoint),
ucodepoint);
}
// ------------------------------------------------ texture_font_load_glyph ---
int
texture_font_load_glyph_gi( texture_font_t * self,
uint32_t glyph_index,
uint32_t ucodepoint )
{
size_t i, x, y;
......@@ -576,36 +603,25 @@ texture_font_load_glyph( texture_font_t * self,
FT_GlyphSlot slot;
FT_Bitmap ft_bitmap;
FT_UInt glyph_index;
texture_glyph_t *glyph;
FT_Int32 flags = 0;
int ft_glyph_top = 0;
int ft_glyph_left = 0;
FT_ULong ucodepoint;
ivec4 region;
size_t missed = 0;
/* Check if codepoint has been already loaded */
if (texture_font_find_glyph(self, codepoint)) {
if (texture_font_find_glyph_gi(self, glyph_index)) {
return 1;
}
/* codepoint NULL is special : it is used for line drawing (overline,
* underline, strikethrough) and background.
*/
if( !codepoint ) {
return 1;
}
if (!texture_font_load_face(self, self->size))
return 0;
flags = 0;
ft_glyph_top = 0;
ft_glyph_left = 0;
ucodepoint = (FT_ULong)utf8_to_utf32( codepoint );
glyph_index = FT_Get_Char_Index( self->face, ucodepoint );
if(!glyph_index) {
texture_glyph_t * glyph;
if ((glyph = texture_font_find_glyph(self, "\0"))) {
......@@ -651,8 +667,8 @@ texture_font_load_glyph( texture_font_t * self,
#ifdef FT_LOAD_COLOR
flags |= FT_LOAD_COLOR;
#else
freetype_error( 0, "FT_Error (%s:%d, code 0x%02x) : %s\n",
__FILENAME__, __LINE__, 0, "FT_LOAD_COLOR not available");
freetype_error( Load_Color_Not_Available, "FT_Error (%s:%d, code 0x%02x) : %s\n",
__FILENAME__, __LINE__, 0, "FT_LOAD_COLOR not available");
#endif
}
......@@ -807,7 +823,7 @@ cleanup_stroker:
free( buffer );
glyph = texture_glyph_new( );
glyph->codepoint = glyph_index ? utf8_to_utf32( codepoint ) : 0;
glyph->codepoint = glyph_index ? ucodepoint : 0;
;
glyph->width = tgt_w * self->scale;
glyph->height = tgt_h * self->scale;
......@@ -918,6 +934,28 @@ texture_font_get_glyph( texture_font_t * self,
return NULL;
}
// ----------------------------------------------- texture_font_get_glyph_gi ---
texture_glyph_t *
texture_font_get_glyph_gi( texture_font_t * self,
uint32_t glyph_index )
{
texture_glyph_t *glyph;
assert( self );
assert( self->filename );
assert( self->atlas );
/* Check if glyph_index has been already loaded */
if( (glyph = texture_font_find_glyph_gi( self, glyph_index )) )
return glyph;
/* Glyph has not been already loaded */
if( texture_font_load_glyph_gi( self, glyph_index, glyph_index ) )
return texture_font_find_glyph_gi( self, glyph_index );
return NULL;
}
// ------------------------------------------ texture_font_enlarge_texture ---
void
texture_font_enlarge_texture( texture_font_t * self, size_t width_new,
......
......@@ -213,7 +213,6 @@ typedef enum font_mode_t {
MODE_MANUAL_CLOSE,
MODE_ALWAYS_OPEN
} font_mode_t;
/**
* default mode for fonts
*/
......@@ -233,6 +232,11 @@ typedef struct FT_FaceRec_* FT_Face;
typedef struct FT_LibraryRec_* FT_Library;
#endif
/* same for harfbuzz */
#ifndef HB_BUFFER_H
typedef struct hb_font_t hb_font_t;
#endif
/**
* Texture font library structure.
*/
......@@ -296,11 +300,6 @@ typedef struct texture_font_t
*/
float size;
/**
* Whether to use autohint when rendering font
*/
int hinting;
/**
* Mode the font is rendering its next glyph
*/
......@@ -314,18 +313,26 @@ typedef struct texture_font_t
/**
* Whether to use our own lcd filter.
*/
int filtering;
unsigned char filtering;
/**
* Whether to use kerning if available
*/
unsigned char kerning;
/**
* LCD filter weights
* Whether to use autohint when rendering font
*/
unsigned char lcd_weights[5];
unsigned char hinting;
/**
* Whether to use kerning if available
* Whether to scale texture coordinates
*/
int kerning;
unsigned char scaletex;
/**
* LCD filter weights
*/
unsigned char lcd_weights[5];
/**
* This field is simply used to compute a default line spacing (i.e., the
......@@ -387,9 +394,9 @@ typedef struct texture_font_t
FT_Face face;
/**
* Whether to scale texture coordinates
* Harfbuzz font pointer
*/
int scaletex;
hb_font_t* hb_font;
/**
* factor to scale font coordinates
......@@ -532,9 +539,50 @@ texture_font_index_glyph( texture_font_t * self,
*
* @return One if the glyph could be loaded, zero if not.
*/
int
texture_font_load_glyph( texture_font_t * self,
const char * codepoint );
int
texture_font_load_glyph( texture_font_t * self,
const char * codepoint );
/**
* Request a new glyph from the font. If it has not been created yet, it will
* be.
*
* @param self A valid texture font
* @param codepoint Font's character codepoint to be obtained
*
* @return A pointer on the new glyph or 0 if the texture atlas is not big
* enough
*
*/
texture_glyph_t *
texture_font_get_glyph_gi( texture_font_t * self,
uint32_t glyph_index );
/**
* Request an already loaded glyph from the font.
*
* @param self A valid texture font
* @param glyph_index Font's character codepoint to be found
*
* @return A pointer on the glyph or 0 if the glyph is not loaded
*/
texture_glyph_t *
texture_font_find_glyph_gi( texture_font_t * self,
uint32_t glyph_index );
/**
* Request the loading of a given glyph.
*
* @param self A valid texture font
* @param glyph_index Character codepoint to be loaded in font's codepoint
* @param ucodepoint Character codepoint for inserting into lookup table
*
* @return One if the glyph could be loaded, zero if not.
*/
int
texture_font_load_glyph_gi( texture_font_t * self,
uint32_t glyph_index,
uint32_t ucodepoint);
/**
* Request the loading of several glyphs at once.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment