@ -49,8 +49,7 @@
static int
static int
get_font_list (
get_font_list (
const char * base_font_name_list ,
const char * base_font_name_list ,
char * * * flist )
char * * * flist ) {
{
const char * ptr ;
const char * ptr ;
const char * p ;
const char * p ;
int nb ;
int nb ;
@ -95,9 +94,7 @@ get_font_list(
/** (mainly used for adobe-symbol and adobe-zapfdingbats) **/
/** (mainly used for adobe-symbol and adobe-zapfdingbats) **/
/*********************************************************************/
/*********************************************************************/
static int
static int
font_spec_enc (
font_spec_enc ( char * font ) {
char * font )
{
int ret ;
int ret ;
char * enc ;
char * enc ;
char * end ;
char * end ;
@ -122,11 +119,10 @@ font_spec_enc(
/** get the sub range of a iso10646-1 font **/
/** get the sub range of a iso10646-1 font **/
/*********************************************************************/
/*********************************************************************/
static void
static void
get_range (
get_range ( const char * enc ,
const char * enc ,
int * min ,
int * min ,
int * max )
int * max ) {
{
const char * ptr = enc ;
const char * ptr = enc ;
const char * ptr1 ;
const char * ptr1 ;
@ -153,11 +149,10 @@ get_range(
/** get the internal encoding number of each fonts **/
/** get the internal encoding number of each fonts **/
/*********************************************************************/
/*********************************************************************/
static int *
static int *
get_encodings (
get_encodings ( char * * font_name_list ,
char * * font_name_list ,
int * ranges ,
int * ranges ,
int nb_font )
int nb_font ) {
{
int * font_encoding_list ;
int * font_encoding_list ;
int i ;
int i ;
i = 0 ;
i = 0 ;
@ -180,8 +175,7 @@ get_encodings(
if ( * ptr = = ' - ' ) {
if ( * ptr = = ' - ' ) {
ec + + ;
ec + + ;
if ( ec = = 13 ) {
if ( ec = = 13 ) {
font_encoding_list [ i ] =
font_encoding_list [ i ] = encoding_number ( ptr + 1 ) ;
encoding_number ( ptr + 1 ) ;
if ( font_encoding_list [ i ] = = 0 ) {
if ( font_encoding_list [ i ] = = 0 ) {
get_range ( ptr + 1 ,
get_range ( ptr + 1 ,
ranges + i * 2 ,
ranges + i * 2 ,
@ -202,10 +196,9 @@ get_encodings(
/** find the first font which matches the name and load it. **/
/** find the first font which matches the name and load it. **/
/*********************************************************************/
/*********************************************************************/
XFontStruct *
XFontStruct *
find_best_font (
find_best_font ( Display * dpy ,
Display * dpy ,
char * * name ) {
char * * name )
{
char * * list ;
char * * list ;
int cnt ;
int cnt ;
XFontStruct * s ;
XFontStruct * s ;
@ -225,21 +218,20 @@ find_best_font(
/** load all fonts **/
/** load all fonts **/
/*********************************************************************/
/*********************************************************************/
static void
static void
load_fonts (
load_fonts ( Display * dpy ,
Display * dpy ,
XUtf8FontStruct * font_set ) {
XUtf8FontStruct * font_set )
{
int i ;
int i ;
char * * list ;
char * * list ;
i = 0 ;
i = 0 ;
list = NULL ;
list = NULL ;
font_set - > fonts = ( XFontStruct * * )
font_set - > fonts = ( XFontStruct * * ) malloc ( sizeof ( XFontStruct * ) *
malloc ( sizeof ( XFontStruct * ) * font_set - > nb_font ) ;
font_set - > nb_font ) ;
font_set - > ranges = ( int * )
font_set - > ranges = ( int * ) malloc ( sizeof ( int ) *
malloc ( sizeof ( int ) * font_set - > nb_font * 2 ) ;
font_set - > nb_font * 2 ) ;
font_set - > descent = 0 ;
font_set - > descent = 0 ;
font_set - > ascent = 0 ;
font_set - > ascent = 0 ;
@ -280,8 +272,7 @@ load_fonts(
font_set - > ranges [ 2 * j ] = =
font_set - > ranges [ 2 * j ] = =
font_set - > ranges [ 2 * i ] & &
font_set - > ranges [ 2 * i ] & &
font_set - > ranges [ ( 2 * j ) + 1 ] & &
font_set - > ranges [ ( 2 * j ) + 1 ] & &
font_set - > ranges [ ( 2 * i ) + 1 ] )
font_set - > ranges [ ( 2 * i ) + 1 ] ) {
{
XFreeFont ( dpy , font_set - > fonts [ i ] ) ;
XFreeFont ( dpy , font_set - > fonts [ i ] ) ;
free ( font_set - > font_name_list [ i ] ) ;
free ( font_set - > font_name_list [ i ] ) ;
font_set - > font_name_list [ i ] = NULL ;
font_set - > font_name_list [ i ] = NULL ;
@ -297,14 +288,12 @@ load_fonts(
/** list of fonts. XLoad all fonts. **/
/** list of fonts. XLoad all fonts. **/
/*********************************************************************/
/*********************************************************************/
XUtf8FontStruct *
XUtf8FontStruct *
XCreateUtf8FontStruct (
XCreateUtf8FontStruct ( Display * dpy ,
Display * dpy ,
const char * base_font_name_list ) {
const char * base_font_name_list )
{
XUtf8FontStruct * font_set ;
XUtf8FontStruct * font_set ;
font_set = ( XUtf8FontStruct * )
font_set = ( XUtf8FontStruct * ) malloc ( sizeof ( XUtf8FontStruct ) ) ;
malloc ( sizeof ( XUtf8FontStruct ) ) ;
if ( ! font_set ) {
if ( ! font_set ) {
return NULL ;
return NULL ;
@ -328,16 +317,15 @@ XCreateUtf8FontStruct (
/** draw a Right To Left UTF-8 string using multiple fonts as needed. **/
/** draw a Right To Left UTF-8 string using multiple fonts as needed. **/
/*****************************************************************************/
/*****************************************************************************/
void
void
XUtf8DrawRtlString (
XUtf8DrawRtlString ( Display * display ,
Display * display ,
Drawable d ,
Drawable d ,
XUtf8FontStruct * font_set ,
XUtf8FontStruct * font_set ,
GC gc ,
GC gc ,
int x ,
int x ,
int y ,
int y ,
const char * string ,
const char * string ,
int num_bytes )
int num_bytes ) {
{
int * encodings ; /* encodings array */
int * encodings ; /* encodings array */
XFontStruct * * fonts ; /* fonts array */
XFontStruct * * fonts ; /* fonts array */
XChar2b buf [ 128 ] ; /* drawing buffer */
XChar2b buf [ 128 ] ; /* drawing buffer */
@ -376,8 +364,7 @@ XUtf8DrawRtlString(
while ( num_bytes > 0 ) {
while ( num_bytes > 0 ) {
int ulen ; /* byte length of the UTF-8 char */
int ulen ; /* byte length of the UTF-8 char */
unsigned int ucs ; /* Unicode value of the UTF-8 char */
unsigned int ucs ; /* Unicode value of the UTF-8 char */
unsigned int no_spc ; /* Spacing char equivalent of a
unsigned int no_spc ; /* Spacing char equivalent of a non-spacing char */
non - spacing char */
if ( i > 120 ) {
if ( i > 120 ) {
/*** draw the buffer **/
/*** draw the buffer **/
@ -388,8 +375,7 @@ XUtf8DrawRtlString(
ptr = buf + 128 ;
ptr = buf + 128 ;
}
}
ulen = XFastConvertUtf8ToUcs ( ( unsigned char * ) string ,
ulen = XFastConvertUtf8ToUcs ( ( unsigned char * ) string , num_bytes , & ucs ) ;
num_bytes , & ucs ) ;
if ( ulen < 1 ) ulen = 1 ;
if ( ulen < 1 ) ulen = 1 ;
@ -402,21 +388,18 @@ XUtf8DrawRtlString(
*/
*/
fnum = first ;
fnum = first ;
while ( fnum < nb_font ) {
while ( fnum < nb_font ) {
if ( fonts [ fnum ] & &
if ( fonts [ fnum ] & & ucs2fontmap ( glyph , ucs , encodings [ fnum ] ) > = 0 ) {
ucs2fontmap ( glyph , ucs , encodings [ fnum ] ) > = 0 )
{
if ( encodings [ fnum ] ! = 0 | |
if ( encodings [ fnum ] ! = 0 | |
( ucs > = ranges [ fnum * 2 ] & &
( ucs > = ranges [ fnum * 2 ] & & ucs < = ranges [ fnum * 2 + 1 ] ) ) {
ucs < = ranges [ fnum * 2 + 1 ] ) )
{
break ;
break ;
}
}
}
}
fnum + + ;
fnum + + ;
}
}
if ( fnum = = nb_font ) {
if ( fnum = = nb_font ) {
/** the char is not valid in all encodings ->
/* the char is not valid in all encodings ->
* draw it using the first font : - ( * */
* draw it using the first font : - (
*/
fnum = first ;
fnum = first ;
ucs2fontmap ( glyph , ' ? ' , encodings [ fnum ] ) ;
ucs2fontmap ( glyph , ' ? ' , encodings [ fnum ] ) ;
}
}
@ -455,16 +438,15 @@ XUtf8DrawRtlString(
/** draw an UTF-8 string using multiple fonts as needed. **/
/** draw an UTF-8 string using multiple fonts as needed. **/
/*****************************************************************************/
/*****************************************************************************/
void
void
XUtf8DrawString (
XUtf8DrawString ( Display * display ,
Display * display ,
Drawable d ,
Drawable d ,
XUtf8FontStruct * font_set ,
XUtf8FontStruct * font_set ,
GC gc ,
GC gc ,
int x ,
int x ,
int y ,
int y ,
const char * string ,
const char * string ,
int num_bytes )
int num_bytes ) {
{
int * encodings ; /* encodings array */
int * encodings ; /* encodings array */
XFontStruct * * fonts ; /* fonts array */
XFontStruct * * fonts ; /* fonts array */
XChar2b buf [ 128 ] ; /* drawing buffer */
XChar2b buf [ 128 ] ; /* drawing buffer */
@ -500,8 +482,7 @@ XUtf8DrawString(
while ( num_bytes > 0 ) {
while ( num_bytes > 0 ) {
int ulen ; /* byte length of the UTF-8 char */
int ulen ; /* byte length of the UTF-8 char */
unsigned int ucs ; /* Unicode value of the UTF-8 char */
unsigned int ucs ; /* Unicode value of the UTF-8 char */
unsigned int no_spc ; /* Spacing char equivalent of a
unsigned int no_spc ; /* Spacing char equivalent of a non-spacing char */
non - spacing char */
if ( i > 120 ) {
if ( i > 120 ) {
/*** draw the buffer **/
/*** draw the buffer **/
@ -511,8 +492,7 @@ XUtf8DrawString(
i = 0 ;
i = 0 ;
}
}
ulen = XFastConvertUtf8ToUcs ( ( unsigned char * ) string ,
ulen = XFastConvertUtf8ToUcs ( ( unsigned char * ) string , num_bytes , & ucs ) ;
num_bytes , & ucs ) ;
if ( ulen < 1 ) ulen = 1 ;
if ( ulen < 1 ) ulen = 1 ;
@ -525,21 +505,19 @@ XUtf8DrawString(
*/
*/
fnum = first ;
fnum = first ;
while ( fnum < nb_font ) {
while ( fnum < nb_font ) {
if ( fonts [ fnum ] & &
if ( fonts [ fnum ] & & ucs2fontmap ( glyph , ucs , encodings [ fnum ] ) > = 0 ) {
ucs2fontmap ( glyph , ucs , encodings [ fnum ] ) > = 0 )
{
if ( encodings [ fnum ] ! = 0 | |
if ( encodings [ fnum ] ! = 0 | |
( ucs > = ranges [ fnum * 2 ] & &
( ucs > = ranges [ fnum * 2 ] & &
ucs < = ranges [ fnum * 2 + 1 ] ) )
ucs < = ranges [ fnum * 2 + 1 ] ) ) {
{
break ;
break ;
}
}
}
}
fnum + + ;
fnum + + ;
}
}
if ( fnum = = nb_font ) {
if ( fnum = = nb_font ) {
/** the char is not valid in all encodings ->
/* the char is not valid in all encodings ->
* draw it using the first font : - ( * */
* draw it using the first font : - (
*/
fnum = first ;
fnum = first ;
ucs2fontmap ( glyph , ' ? ' , encodings [ fnum ] ) ;
ucs2fontmap ( glyph , ' ? ' , encodings [ fnum ] ) ;
}
}
@ -574,11 +552,10 @@ XUtf8DrawString(
/** returns the pixel width of a UTF-8 string **/
/** returns the pixel width of a UTF-8 string **/
/*****************************************************************************/
/*****************************************************************************/
int
int
XUtf8TextWidth (
XUtf8TextWidth ( XUtf8FontStruct * font_set ,
XUtf8FontStruct * font_set ,
const char * string ,
const char * string ,
int num_bytes )
int num_bytes ) {
{
int x ;
int x ;
int * encodings ; /* encodings array */
int * encodings ; /* encodings array */
XFontStruct * * fonts ; /* fonts array */
XFontStruct * * fonts ; /* fonts array */
@ -617,8 +594,7 @@ XUtf8TextWidth(
while ( num_bytes > 0 ) {
while ( num_bytes > 0 ) {
int ulen ; /* byte length of the UTF-8 char */
int ulen ; /* byte length of the UTF-8 char */
unsigned int ucs ; /* Unicode value of the UTF-8 char */
unsigned int ucs ; /* Unicode value of the UTF-8 char */
unsigned int no_spc ; /* Spacing char equivalent of a
unsigned int no_spc ; /* Spacing char equivalent of a non-spacing char */
non - spacing char */
if ( i > 120 ) {
if ( i > 120 ) {
/*** measure the buffer **/
/*** measure the buffer **/
@ -626,8 +602,7 @@ XUtf8TextWidth(
i = 0 ;
i = 0 ;
}
}
ulen = XFastConvertUtf8ToUcs ( ( unsigned char * ) string ,
ulen = XFastConvertUtf8ToUcs ( ( unsigned char * ) string , num_bytes , & ucs ) ;
num_bytes , & ucs ) ;
if ( ulen < 1 ) ulen = 1 ;
if ( ulen < 1 ) ulen = 1 ;
@ -642,21 +617,19 @@ XUtf8TextWidth(
*/
*/
fnum = first ;
fnum = first ;
while ( fnum < nb_font ) {
while ( fnum < nb_font ) {
if ( fonts [ fnum ] & &
if ( fonts [ fnum ] & & ucs2fontmap ( glyph , ucs , encodings [ fnum ] ) > = 0 ) {
ucs2fontmap ( glyph , ucs , encodings [ fnum ] ) > = 0 )
{
if ( encodings [ fnum ] ! = 0 | |
if ( encodings [ fnum ] ! = 0 | |
( ucs > = ranges [ fnum * 2 ] & &
( ucs > = ranges [ fnum * 2 ] & &
ucs < = ranges [ fnum * 2 + 1 ] ) )
ucs < = ranges [ fnum * 2 + 1 ] ) ) {
{
break ;
break ;
}
}
}
}
fnum + + ;
fnum + + ;
}
}
if ( fnum = = nb_font ) {
if ( fnum = = nb_font ) {
/** the char is not valid in all encodings ->
/* the char is not valid in all encodings ->
* draw it using the first font : - ( * */
* draw it using the first font : - (
*/
fnum = first ;
fnum = first ;
ucs2fontmap ( glyph , ' ? ' , encodings [ fnum ] ) ;
ucs2fontmap ( glyph , ' ? ' , encodings [ fnum ] ) ;
}
}
@ -667,8 +640,7 @@ XUtf8TextWidth(
( * buf ) . byte1 = glyph [ 0 ] ;
( * buf ) . byte1 = glyph [ 0 ] ;
( * buf ) . byte2 = glyph [ 1 ] ;
( * buf ) . byte2 = glyph [ 1 ] ;
if ( no_spc ) {
if ( no_spc ) {
/* go back to draw the non-spacing char over
/* go back to draw the non-spacing char over the previous char */
* the previous char */
x - = XTextWidth16 ( fonts [ fnum ] , buf , 1 ) ;
x - = XTextWidth16 ( fonts [ fnum ] , buf , 1 ) ;
}
}
} else {
} else {
@ -690,12 +662,11 @@ XUtf8TextWidth(
/** get the X font and glyph ID of a UCS char **/
/** get the X font and glyph ID of a UCS char **/
/*****************************************************************************/
/*****************************************************************************/
int
int
XGetUtf8FontAndGlyph (
XGetUtf8FontAndGlyph ( XUtf8FontStruct * font_set ,
XUtf8FontStruct * font_set ,
unsigned int ucs ,
unsigned int ucs ,
XFontStruct * * fnt ,
XFontStruct * * fnt ,
unsigned short * id )
unsigned short * id ) {
{
int x ;
int x ;
int * encodings ; /* encodings array */
int * encodings ; /* encodings array */
XFontStruct * * fonts ; /* fonts array */
XFontStruct * * fonts ; /* fonts array */
@ -736,20 +707,19 @@ XGetUtf8FontAndGlyph(
*/
*/
fnum = first ;
fnum = first ;
while ( fnum < nb_font ) {
while ( fnum < nb_font ) {
if ( fonts [ fnum ] & &
if ( fonts [ fnum ] & & ucs2fontmap ( glyph , ucs , encodings [ fnum ] ) > = 0 ) {
ucs2fontmap ( glyph , ucs , encodings [ fnum ] ) > = 0 )
if ( encodings [ fnum ] ! = 0 | |
{
( ucs > = ranges [ fnum * 2 ] & &
if ( encodings [ fnum ] ! = 0 | | ( ucs > = ranges [ fnum * 2 ] & &
ucs < = ranges [ fnum * 2 + 1 ] ) ) {
ucs < = ranges [ fnum * 2 + 1 ] ) )
{
break ;
break ;
}
}
}
}
fnum + + ;
fnum + + ;
}
}
if ( fnum = = nb_font ) {
if ( fnum = = nb_font ) {
/** the char is not valid in all encodings ->
/* the char is not valid in all encodings ->
* draw it using the first font : - ( * */
* draw it using the first font : - (
*/
fnum = first ;
fnum = first ;
ucs2fontmap ( glyph , ' ? ' , encodings [ fnum ] ) ;
ucs2fontmap ( glyph , ' ? ' , encodings [ fnum ] ) ;
}
}
@ -763,10 +733,9 @@ XGetUtf8FontAndGlyph(
/** returns the pixel width of a UCS char **/
/** returns the pixel width of a UCS char **/
/*****************************************************************************/
/*****************************************************************************/
int
int
XUtf8UcsWidth (
XUtf8UcsWidth ( XUtf8FontStruct * font_set ,
XUtf8FontStruct * font_set ,
unsigned int ucs ) {
unsigned int ucs )
{
int x ;
int x ;
int * encodings ; /* encodings array */
int * encodings ; /* encodings array */
XFontStruct * * fonts ; /* fonts array */
XFontStruct * * fonts ; /* fonts array */
@ -802,7 +771,6 @@ XUtf8UcsWidth(
first = fnum ;
first = fnum ;
last_fnum = fnum ;
last_fnum = fnum ;
ucs = XUtf8IsNonSpacing ( ucs ) ;
ucs = XUtf8IsNonSpacing ( ucs ) ;
/*
/*
@ -812,19 +780,18 @@ XUtf8UcsWidth(
fnum = first ;
fnum = first ;
while ( fnum < nb_font ) {
while ( fnum < nb_font ) {
if ( fonts [ fnum ] & &
if ( fonts [ fnum ] & &
ucs2fontmap ( glyph , ucs , encodings [ fnum ] ) > = 0 )
ucs2fontmap ( glyph , ucs , encodings [ fnum ] ) > = 0 ) {
{
if ( encodings [ fnum ] ! = 0 | | ( ucs > = ranges [ fnum * 2 ] & &
if ( encodings [ fnum ] ! = 0 | | ( ucs > = ranges [ fnum * 2 ] & &
ucs < = ranges [ fnum * 2 + 1 ] ) )
ucs < = ranges [ fnum * 2 + 1 ] ) ) {
{
break ;
break ;
}
}
}
}
fnum + + ;
fnum + + ;
}
}
if ( fnum = = nb_font ) {
if ( fnum = = nb_font ) {
/** the char is not valid in all encodings ->
/* the char is not valid in all encodings ->
* draw it using the first font : - ( * */
* draw it using the first font : - (
*/
fnum = first ;
fnum = first ;
ucs2fontmap ( glyph , ' ? ' , encodings [ fnum ] ) ;
ucs2fontmap ( glyph , ' ? ' , encodings [ fnum ] ) ;
}
}
@ -841,16 +808,15 @@ XUtf8UcsWidth(
/** draw an UTF-8 string and clear the background. **/
/** draw an UTF-8 string and clear the background. **/
/*****************************************************************************/
/*****************************************************************************/
void
void
XUtf8DrawImageString (
XUtf8DrawImageString ( Display * display ,
Display * display ,
Drawable d ,
Drawable d ,
XUtf8FontStruct * font_set ,
XUtf8FontStruct * font_set ,
GC gc ,
GC gc ,
int x ,
int x ,
int y ,
int y ,
const char * string ,
const char * string ,
int num_bytes )
int num_bytes ) {
{
/* FIXME: must be improved ! */
/* FIXME: must be improved ! */
int w ;
int w ;
int fill_style ;
int fill_style ;
@ -895,10 +861,9 @@ XUtf8DrawImageString(
/** free the XFontSet and others things created by XCreateUtf8FontSet **/
/** free the XFontSet and others things created by XCreateUtf8FontSet **/
/*****************************************************************************/
/*****************************************************************************/
void
void
XFreeUtf8FontStruct (
XFreeUtf8FontStruct ( Display * dpy ,
Display * dpy ,
XUtf8FontStruct * font_set ) {
XUtf8FontStruct * font_set )
{
int i ;
int i ;
i = 0 ;
i = 0 ;
while ( i < font_set - > nb_font ) {
while ( i < font_set - > nb_font ) {