forked from old/legacy-imlib2
parent
b9c591d390
commit
275d89b1d9
|
@ -3105,51 +3105,60 @@ imlib_free_font(void)
|
|||
ctx->font = NULL;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param font A previously loaded font.
|
||||
* @param fallback_font A previously loaded font to be chained to the given font.
|
||||
* @return 0 on success.
|
||||
*
|
||||
* This arranges for the given fallback font to be used if a glyph does not exist in the given font when text is being rendered.
|
||||
* Fonts can be arranged in an aribitrarily long chain and attempts will be made in order on the chain.
|
||||
* Cycles in the chain are not possible since the given fallback font is removed from any chain it's already in.
|
||||
* A fallback font may be a member of only one chain. Adding it as the fallback font to another font will remove it from it's first fallback chain.
|
||||
* This arranges for the given fallback font to be used if a glyph does not
|
||||
* exist in the given font when text is being rendered.
|
||||
* Fonts can be arranged in an aribitrarily long chain and attempts will be
|
||||
* made in order on the chain.
|
||||
* Cycles in the chain are not possible since the given fallback font is
|
||||
* removed from any chain it's already in.
|
||||
* A fallback font may be a member of only one chain. Adding it as the
|
||||
* fallback font to another font will remove it from it's first fallback chain.
|
||||
**/
|
||||
EAPI int
|
||||
EAPI int
|
||||
imlib_insert_font_into_fallback_chain(Imlib_Font font, Imlib_Font fallback_font)
|
||||
{
|
||||
CHECK_PARAM_POINTER_RETURN("imlib_insert_font_into_fallback_chain", "font", font, 1);
|
||||
CHECK_PARAM_POINTER_RETURN("imlib_insert_font_into_fallback_chain", "fallback_font", fallback_font, 1);
|
||||
return imlib_insert_font_into_fallback_chain_imp(font,fallback_font);
|
||||
CHECK_PARAM_POINTER_RETURN("imlib_insert_font_into_fallback_chain",
|
||||
"font", font, 1);
|
||||
CHECK_PARAM_POINTER_RETURN("imlib_insert_font_into_fallback_chain",
|
||||
"fallback_font", fallback_font, 1);
|
||||
return imlib_insert_font_into_fallback_chain_imp(font, fallback_font);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param fallback_font A font previously added to a fallback chain
|
||||
* @param fallback_font A font previously added to a fallback chain.
|
||||
* @return 0 on success.
|
||||
*
|
||||
* This removes the given font from any fallback chain it may be in.
|
||||
* Removing this font joins its previous and next font together in the fallback chain.
|
||||
* Removing this font joins its previous and next font together in the fallback
|
||||
* chain.
|
||||
**/
|
||||
EAPI void
|
||||
EAPI void
|
||||
imlib_remove_font_from_fallback_chain(Imlib_Font fallback_font)
|
||||
{
|
||||
CHECK_PARAM_POINTER("imlib_remove_font_from_fallback_chain", "fallback_font", fallback_font);
|
||||
CHECK_PARAM_POINTER("imlib_remove_font_from_fallback_chain",
|
||||
"fallback_font", fallback_font);
|
||||
imlib_remove_font_from_fallback_chain_imp(fallback_font);
|
||||
}
|
||||
|
||||
EAPI Imlib_Font
|
||||
EAPI Imlib_Font
|
||||
imlib_get_prev_font_in_fallback_chain(Imlib_Font fn)
|
||||
{
|
||||
CHECK_PARAM_POINTER_RETURN("imlib_get_prev_font_in_fallback_chain", "fn", fn, 0);
|
||||
return ((ImlibFont*)fn)->fallback_prev;
|
||||
CHECK_PARAM_POINTER_RETURN("imlib_get_prev_font_in_fallback_chain",
|
||||
"fn", fn, 0);
|
||||
return ((ImlibFont *) fn)->fallback_prev;
|
||||
}
|
||||
|
||||
EAPI Imlib_Font
|
||||
EAPI Imlib_Font
|
||||
imlib_get_next_font_in_fallback_chain(Imlib_Font fn)
|
||||
{
|
||||
CHECK_PARAM_POINTER_RETURN("imlib_get_next_font_in_fallback_chain", "fn", fn, 0);
|
||||
return ((ImlibFont*)fn)->fallback_next;
|
||||
CHECK_PARAM_POINTER_RETURN("imlib_get_next_font_in_fallback_chain",
|
||||
"fn", fn, 0);
|
||||
return ((ImlibFont *) fn)->fallback_next;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -246,28 +246,33 @@ imlib_render_str(ImlibImage * im, ImlibFont * fn, int drx, int dry,
|
|||
}
|
||||
|
||||
/*
|
||||
* This function returns the first font in the fallback chain to contain the requested glyph.
|
||||
* This function returns the first font in the fallback chain to contain
|
||||
* the requested glyph.
|
||||
* The glyph index is returned in ret_index
|
||||
* If the glyph is not found, then the given font pointer is returned and ret_index will be set to 0
|
||||
* If the glyph is not found, then the given font pointer is returned and
|
||||
* ret_index will be set to 0
|
||||
*/
|
||||
ImlibFont *
|
||||
ImlibFont *
|
||||
imlib_find_glyph_in_font_chain(ImlibFont * first_fn, int gl, int *ret_index)
|
||||
{
|
||||
ImlibFont *fn = first_fn;
|
||||
do
|
||||
{
|
||||
int index = FT_Get_Char_Index(fn->ft.face, gl);
|
||||
if(index<=0)
|
||||
fn = fn->fallback_next;
|
||||
else
|
||||
{
|
||||
(*ret_index) = index;
|
||||
return fn;
|
||||
}
|
||||
} while(fn);
|
||||
ImlibFont *fn = first_fn;
|
||||
|
||||
(*ret_index) = 0;
|
||||
return first_fn;
|
||||
do
|
||||
{
|
||||
int index = FT_Get_Char_Index(fn->ft.face, gl);
|
||||
|
||||
if (index <= 0)
|
||||
fn = fn->fallback_next;
|
||||
else
|
||||
{
|
||||
(*ret_index) = index;
|
||||
return fn;
|
||||
}
|
||||
}
|
||||
while (fn);
|
||||
|
||||
(*ret_index) = 0;
|
||||
return first_fn;
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -335,20 +340,20 @@ imlib_font_draw(ImlibImage * dst, DATA32 col, ImlibFont * fn, int x, int y,
|
|||
{
|
||||
FT_UInt index;
|
||||
Imlib_Font_Glyph *fg;
|
||||
ImlibFont *fn_in_chain;
|
||||
ImlibFont *fn_in_chain;
|
||||
int chr_x, chr_y;
|
||||
int gl;
|
||||
|
||||
gl = imlib_font_utf8_get_next((unsigned char *)text, &chr);
|
||||
if (gl == 0)
|
||||
break;
|
||||
fn_in_chain = imlib_find_glyph_in_font_chain(fn, gl, &index);
|
||||
fn_in_chain = imlib_find_glyph_in_font_chain(fn, gl, &index);
|
||||
if ((use_kerning) && (prev_index) && (index))
|
||||
{
|
||||
FT_Vector delta;
|
||||
|
||||
FT_Get_Kerning(fn_in_chain->ft.face, prev_index, index, ft_kerning_default,
|
||||
&delta);
|
||||
FT_Get_Kerning(fn_in_chain->ft.face, prev_index, index,
|
||||
ft_kerning_default, &delta);
|
||||
pen_x += delta.x << 2;
|
||||
}
|
||||
fg = imlib_font_cache_glyph_get(fn_in_chain, index);
|
||||
|
|
|
@ -204,33 +204,34 @@ imlib_font_free(ImlibFont * fn)
|
|||
}
|
||||
|
||||
int
|
||||
imlib_insert_font_into_fallback_chain_imp(ImlibFont * fn, ImlibFont *fallback)
|
||||
imlib_insert_font_into_fallback_chain_imp(ImlibFont * fn, ImlibFont * fallback)
|
||||
{
|
||||
/* avoid infinite recursion */
|
||||
if(fn == fallback)
|
||||
return 1;
|
||||
|
||||
/* now remove the given fallback font from any chain it's already in */
|
||||
imlib_remove_font_from_fallback_chain_imp(fallback);
|
||||
/* avoid infinite recursion */
|
||||
if (fn == fallback)
|
||||
return 1;
|
||||
|
||||
/* insert fallback into fn's font chain */
|
||||
ImlibFont *tmp=fn->fallback_next;
|
||||
fn->fallback_next = fallback;
|
||||
fallback->fallback_prev = fn;
|
||||
fallback->fallback_next = tmp;
|
||||
if (tmp)
|
||||
tmp->fallback_prev = fallback;
|
||||
return 0;
|
||||
/* now remove the given fallback font from any chain it's already in */
|
||||
imlib_remove_font_from_fallback_chain_imp(fallback);
|
||||
|
||||
/* insert fallback into fn's font chain */
|
||||
ImlibFont *tmp = fn->fallback_next;
|
||||
|
||||
fn->fallback_next = fallback;
|
||||
fallback->fallback_prev = fn;
|
||||
fallback->fallback_next = tmp;
|
||||
if (tmp)
|
||||
tmp->fallback_prev = fallback;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
imlib_remove_font_from_fallback_chain_imp(ImlibFont *fn)
|
||||
imlib_remove_font_from_fallback_chain_imp(ImlibFont * fn)
|
||||
{
|
||||
/* if fn has a previous font in its font chain, then make its fallback_next fn's fallback_next since fn is going away */
|
||||
if(fn->fallback_prev)
|
||||
fn->fallback_prev->fallback_next=fn->fallback_next;
|
||||
fn->fallback_prev = NULL;
|
||||
fn->fallback_next = NULL;
|
||||
/* if fn has a previous font in its font chain, then make its fallback_next fn's fallback_next since fn is going away */
|
||||
if (fn->fallback_prev)
|
||||
fn->fallback_prev->fallback_next = fn->fallback_next;
|
||||
fn->fallback_prev = NULL;
|
||||
fn->fallback_next = NULL;
|
||||
}
|
||||
|
||||
static int
|
||||
|
|
|
@ -15,8 +15,7 @@
|
|||
#include "rgbadraw.h"
|
||||
#include "rotate.h"
|
||||
|
||||
extern ImlibFont *
|
||||
imlib_find_glyph_in_font_chain(ImlibFont * first_fn, int gl, int *ret_index); /* defined in font_draw.c */
|
||||
extern ImlibFont *imlib_find_glyph_in_font_chain(ImlibFont * first_fn, int gl, int *ret_index); /* defined in font_draw.c */
|
||||
|
||||
extern FT_Library ft_lib;
|
||||
|
||||
|
@ -40,20 +39,20 @@ imlib_font_query_size(ImlibFont * fn, const char *text, int *w, int *h)
|
|||
{
|
||||
FT_UInt index;
|
||||
Imlib_Font_Glyph *fg;
|
||||
ImlibFont *fn_in_chain;
|
||||
ImlibFont *fn_in_chain;
|
||||
int chr_x, chr_y, chr_w;
|
||||
int gl;
|
||||
|
||||
gl = imlib_font_utf8_get_next((unsigned char *)text, &chr);
|
||||
if (gl == 0)
|
||||
break;
|
||||
fn_in_chain = imlib_find_glyph_in_font_chain(fn, gl, &index);
|
||||
fn_in_chain = imlib_find_glyph_in_font_chain(fn, gl, &index);
|
||||
if ((use_kerning) && (prev_index) && (index))
|
||||
{
|
||||
FT_Vector delta;
|
||||
|
||||
FT_Get_Kerning(fn_in_chain->ft.face, prev_index, index, ft_kerning_default,
|
||||
&delta);
|
||||
FT_Get_Kerning(fn_in_chain->ft.face, prev_index, index,
|
||||
ft_kerning_default, &delta);
|
||||
pen_x += delta.x << 2;
|
||||
}
|
||||
fg = imlib_font_cache_glyph_get(fn_in_chain, index);
|
||||
|
@ -75,7 +74,7 @@ imlib_font_query_size(ImlibFont * fn, const char *text, int *w, int *h)
|
|||
if (w)
|
||||
*w = (pen_x >> 8) - start_x;
|
||||
if (h)
|
||||
*h = imlib_font_max_ascent_get(fn) - imlib_font_max_descent_get(fn); /* TODO: compute this inside the loop since we now may be dealing with multiple fonts */
|
||||
*h = imlib_font_max_ascent_get(fn) - imlib_font_max_descent_get(fn); /* TODO: compute this inside the loop since we now may be dealing with multiple fonts */
|
||||
}
|
||||
|
||||
/* text x inset */
|
||||
|
@ -84,7 +83,7 @@ imlib_font_query_inset(ImlibFont * fn, const char *text)
|
|||
{
|
||||
FT_UInt index;
|
||||
Imlib_Font_Glyph *fg;
|
||||
ImlibFont *fn_in_chain;
|
||||
ImlibFont *fn_in_chain;
|
||||
int chr;
|
||||
int gl;
|
||||
|
||||
|
@ -121,20 +120,20 @@ imlib_font_query_advance(ImlibFont * fn, const char *text, int *h_adv,
|
|||
{
|
||||
FT_UInt index;
|
||||
Imlib_Font_Glyph *fg;
|
||||
ImlibFont *fn_in_chain;
|
||||
ImlibFont *fn_in_chain;
|
||||
int chr_x, chr_y, chr_w;
|
||||
int gl;
|
||||
|
||||
gl = imlib_font_utf8_get_next((unsigned char *)text, &chr);
|
||||
if (gl == 0)
|
||||
break;
|
||||
fn_in_chain = imlib_find_glyph_in_font_chain(fn, gl, &index);
|
||||
fn_in_chain = imlib_find_glyph_in_font_chain(fn, gl, &index);
|
||||
if ((use_kerning) && (prev_index) && (index))
|
||||
{
|
||||
FT_Vector delta;
|
||||
|
||||
FT_Get_Kerning(fn_in_chain->ft.face, prev_index, index, ft_kerning_default,
|
||||
&delta);
|
||||
FT_Get_Kerning(fn_in_chain->ft.face, prev_index, index,
|
||||
ft_kerning_default, &delta);
|
||||
pen_x += delta.x << 2;
|
||||
}
|
||||
fg = imlib_font_cache_glyph_get(fn_in_chain, index);
|
||||
|
@ -178,7 +177,7 @@ imlib_font_query_char_coords(ImlibFont * fn, const char *text, int pos,
|
|||
int pchr;
|
||||
FT_UInt index;
|
||||
Imlib_Font_Glyph *fg;
|
||||
ImlibFont *fn_in_chain;
|
||||
ImlibFont *fn_in_chain;
|
||||
int chr_x, chr_y, chr_w;
|
||||
int gl, kern;
|
||||
FT_Vector delta;
|
||||
|
@ -187,12 +186,12 @@ imlib_font_query_char_coords(ImlibFont * fn, const char *text, int pos,
|
|||
gl = imlib_font_utf8_get_next((unsigned char *)text, &chr);
|
||||
if (gl == 0)
|
||||
break;
|
||||
fn_in_chain = imlib_find_glyph_in_font_chain(fn, gl, &index);
|
||||
fn_in_chain = imlib_find_glyph_in_font_chain(fn, gl, &index);
|
||||
kern = 0;
|
||||
if ((use_kerning) && (prev_index) && (index))
|
||||
{
|
||||
FT_Get_Kerning(fn_in_chain->ft.face, prev_index, index, ft_kerning_default,
|
||||
&delta);
|
||||
FT_Get_Kerning(fn_in_chain->ft.face, prev_index, index,
|
||||
ft_kerning_default, &delta);
|
||||
kern = delta.x << 2;
|
||||
pen_x += kern;
|
||||
}
|
||||
|
@ -261,7 +260,7 @@ imlib_font_query_text_at_pos(ImlibFont * fn, const char *text, int x, int y,
|
|||
int pchr;
|
||||
FT_UInt index;
|
||||
Imlib_Font_Glyph *fg;
|
||||
ImlibFont *fn_in_chain;
|
||||
ImlibFont *fn_in_chain;
|
||||
int chr_x, chr_y, chr_w;
|
||||
int gl, kern;
|
||||
FT_Vector delta;
|
||||
|
@ -270,12 +269,12 @@ imlib_font_query_text_at_pos(ImlibFont * fn, const char *text, int x, int y,
|
|||
gl = imlib_font_utf8_get_next((unsigned char *)text, &chr);
|
||||
if (gl == 0)
|
||||
break;
|
||||
fn_in_chain = imlib_find_glyph_in_font_chain(fn, gl, &index);
|
||||
fn_in_chain = imlib_find_glyph_in_font_chain(fn, gl, &index);
|
||||
kern = 0;
|
||||
if ((use_kerning) && (prev_index) && (index))
|
||||
{
|
||||
FT_Get_Kerning(fn_in_chain->ft.face, prev_index, index, ft_kerning_default,
|
||||
&delta);
|
||||
FT_Get_Kerning(fn_in_chain->ft.face, prev_index, index,
|
||||
ft_kerning_default, &delta);
|
||||
kern = delta.x << 2;
|
||||
pen_x += kern;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue