aboutsummaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorN.N. <sevyves@users.sourceforge.net>2010-06-20 19:06:28 +0000
committerN.N. <sevyves@users.sourceforge.net>2010-06-20 19:06:28 +0000
commitc52767badbde956c4cc30399d5bfd527eac3608b (patch)
tree782ed63545383bc6d45a4c8560fabd15977e0647 /modules
parent4d2a8a7e3ee8556746c5c565530bd3733f7913a7 (diff)
fixed font loading and added utf-8 support
svn path=/trunk/externals/pidip/; revision=13681
Diffstat (limited to 'modules')
-rw-r--r--modules/pdp_qtext.c67
-rw-r--r--modules/pdp_text.c70
2 files changed, 126 insertions, 11 deletions
diff --git a/modules/pdp_qtext.c b/modules/pdp_qtext.c
index 84cabec..da08ba7 100644
--- a/modules/pdp_qtext.c
+++ b/modules/pdp_qtext.c
@@ -278,8 +278,6 @@ static void pdp_qtext_add(t_pdp_qtext *x, t_symbol *s, int argc, t_atom *argv)
ndigits=0;
piname=pname+1;
while ( isdigit( *(piname++) ) ) ndigits++;
-
- ivalue=atoi(pname+1);
// special case %%
if ( ( pname != argv[0].a_w.w_symbol->s_name ) && ( *(pname+1) == '%' ) )
@@ -288,7 +286,49 @@ static void pdp_qtext_add(t_pdp_qtext *x, t_symbol *s, int argc, t_atom *argv)
pname++;
continue;
}
- *(pdname++)=(char)ivalue;
+
+ ivalue=atoi(pname+1);
+ // encode to utf
+ if ( ivalue < 0x7F )
+ {
+ *(pdname++)=(char)ivalue;
+ }
+ else if ( ivalue <= 0x7FF )
+ {
+ *(pdname++)=(char)(192 + (ivalue/64));
+ *(pdname++)=(char)(128 + (ivalue%64));
+ }
+ else if ( ivalue <= 0xFFFF )
+ {
+ *(pdname++)=(char)(224 + (ivalue/4096));
+ *(pdname++)=(char)(128 + ((ivalue/64)%64));
+ *(pdname++)=(char)(128 + (ivalue%64));
+ }
+ else if ( ivalue <= 0x1FFFFF )
+ {
+ *(pdname++)=(char)(240 + (ivalue/262144));
+ *(pdname++)=(char)(128 + ((ivalue/4096)%64));
+ *(pdname++)=(char)(128 + ((ivalue/64)%64));
+ *(pdname++)=(char)(128 + (ivalue%64));
+ }
+ else if ( ivalue <= 0x3FFFFFF )
+ {
+ *(pdname++)=(char)(248 + (ivalue/16777216));
+ *(pdname++)=(char)(128 + ((ivalue/262144)%64));
+ *(pdname++)=(char)(128 + ((ivalue/4096)%64));
+ *(pdname++)=(char)(128 + ((ivalue/64)%64));
+ *(pdname++)=(char)(128 + (ivalue%64));
+ }
+ else if ( ivalue <= 0x7FFFFFFF )
+ {
+ *(pdname++)=(char)(252 + (ivalue/1073741824));
+ *(pdname++)=(char)(128 + ((ivalue/16777216)%64));
+ *(pdname++)=(char)(128 + ((ivalue/262144)%64));
+ *(pdname++)=(char)(128 + ((ivalue/4096)%64));
+ *(pdname++)=(char)(128 + ((ivalue/64)%64));
+ *(pdname++)=(char)(128 + (ivalue%64));
+ }
+
pname+=ndigits+1;
}
else if ( !strncmp( pname, "\"", 1 ) ) // quotes are ignored unless %34
@@ -1086,8 +1126,25 @@ void pdp_qtext_setup(void)
font = imlib_load_font(DEFAULT_FONT);
if ( !font )
{
- error( "[pdp_qtext] error: could not load default font, no text rendering!" );
- post( "\tinstall Bitstream Vera, it's free! (http://www.gnome.org/fonts/)" );
+ char **ifonts;
+ int nbfonts, jf;
+ char fname[64];
+
+ ifonts = imlib_list_fonts( &nbfonts );
+ for ( jf=0; jf<nbfonts; jf++ )
+ {
+ sprintf( fname, "%s/14", ifonts[jf] );
+ font = imlib_load_font( fname );
+ if ( !font )
+ {
+ post( "[pdp_qtext] error loading font : %s", fname );
+ }
+ else
+ {
+ post( "[pdp_qtext] using font : %s", fname );
+ break;
+ }
+ }
}
imlib_context_set_font( font );
}
diff --git a/modules/pdp_text.c b/modules/pdp_text.c
index e0c313b..d586c21 100644
--- a/modules/pdp_text.c
+++ b/modules/pdp_text.c
@@ -98,7 +98,7 @@ static void pdp_text_add(t_pdp_text *x, t_symbol *s, int argc, t_atom *argv)
// allocate new text area
len = strlen( argv[0].a_w.w_symbol->s_name );
- pdname = x->x_text_array[x->x_nbtexts] = (char *) getbytes( len+1 );
+ pdname = x->x_text_array[x->x_nbtexts] = (char *) getbytes( 6*len+1 );
pname = (char *) getbytes( len+1 );
memset( pname, 0x0, len+1 );
memcpy( pname, argv[0].a_w.w_symbol->s_name, len );
@@ -114,8 +114,6 @@ static void pdp_text_add(t_pdp_text *x, t_symbol *s, int argc, t_atom *argv)
piname=pname+1;
while ( isdigit( *(piname++) ) ) ndigits++;
- ivalue=atoi(pname+1);
-
// special case %%
if ( ( pname != argv[0].a_w.w_symbol->s_name ) && ( *(pname+1) == '%' ) )
{
@@ -123,7 +121,50 @@ static void pdp_text_add(t_pdp_text *x, t_symbol *s, int argc, t_atom *argv)
pname++;
continue;
}
- *(pdname++)=(char)ivalue;
+
+ ivalue=atoi(pname+1);
+
+ // encode to utf
+ if ( ivalue < 0x7F )
+ {
+ *(pdname++)=(char)ivalue;
+ }
+ else if ( ivalue <= 0x7FF )
+ {
+ *(pdname++)=(char)(192 + (ivalue/64));
+ *(pdname++)=(char)(128 + (ivalue%64));
+ }
+ else if ( ivalue <= 0xFFFF )
+ {
+ *(pdname++)=(char)(224 + (ivalue/4096));
+ *(pdname++)=(char)(128 + ((ivalue/64)%64));
+ *(pdname++)=(char)(128 + (ivalue%64));
+ }
+ else if ( ivalue <= 0x1FFFFF )
+ {
+ *(pdname++)=(char)(240 + (ivalue/262144));
+ *(pdname++)=(char)(128 + ((ivalue/4096)%64));
+ *(pdname++)=(char)(128 + ((ivalue/64)%64));
+ *(pdname++)=(char)(128 + (ivalue%64));
+ }
+ else if ( ivalue <= 0x3FFFFFF )
+ {
+ *(pdname++)=(char)(248 + (ivalue/16777216));
+ *(pdname++)=(char)(128 + ((ivalue/262144)%64));
+ *(pdname++)=(char)(128 + ((ivalue/4096)%64));
+ *(pdname++)=(char)(128 + ((ivalue/64)%64));
+ *(pdname++)=(char)(128 + (ivalue%64));
+ }
+ else if ( ivalue <= 0x7FFFFFFF )
+ {
+ *(pdname++)=(char)(252 + (ivalue/1073741824));
+ *(pdname++)=(char)(128 + ((ivalue/16777216)%64));
+ *(pdname++)=(char)(128 + ((ivalue/262144)%64));
+ *(pdname++)=(char)(128 + ((ivalue/4096)%64));
+ *(pdname++)=(char)(128 + ((ivalue/64)%64));
+ *(pdname++)=(char)(128 + (ivalue%64));
+ }
+
pname+=ndigits+1;
}
else if ( !strncmp( pname, "\"", 1 ) ) // quotes are ignored unless %34
@@ -649,8 +690,25 @@ void pdp_text_setup(void)
font = imlib_load_font(DEFAULT_FONT);
if ( !font )
{
- error( "[pdp_text] error: could not load default font, no text rendering!" );
- post( "\tinstall Bitstream Vera, it's free! (http://www.gnome.org/fonts/)" );
+ char **ifonts;
+ int nbfonts, jf;
+ char fname[64];
+
+ ifonts = imlib_list_fonts( &nbfonts );
+ for ( jf=0; jf<nbfonts; jf++ )
+ {
+ sprintf( fname, "%s/14", ifonts[jf] );
+ font = imlib_load_font( fname );
+ if ( !font )
+ {
+ post( "[pdp_text] error loading font : %s", fname );
+ }
+ else
+ {
+ post( "[pdp_text] using font : %s", fname );
+ break;
+ }
+ }
}
imlib_context_set_font( font );
}