Re: [AD] Patch to thanks._tx and demo.c |
[ Thread Index |
Date Index
| More lists.liballeg.org/allegro-developers Archives
]
On 2005-03-29, Marcio Fialho <maaf1980@xxxxxxxxxx> wrote:
> >>What about to replace all accented characters in thanks._tx for
> >>their 7-bit ASCII counterparts (e.g á -> a)? For me, it seems
> >>to be the easiest solution.
> >
> >The easiest solution should be to put set_uformat(U_ASCII);
> >in line 2058 before allegro_init(); Do accents look ok then?
>
> Unfortunately, the solution proposed by Grzegorz doesn't work,
> unless we edit demo.dat and update TITLE_FONT. The TITLE_FONT
> in demo.dat (dated 2004.10.03) provides meaningful glyphs only
> for the 7-bit ASCII characters (even though it has 224 glyphs, all
> glyphs for 8-bit characters are blank). If this font were complete,
> the solution proposed by Grzegorz would work fine (I've tested it,
> replacing TITLE_FONT by END_FONT and the accented characters were
> displayed fine).
You are right. Updating the font correctly is more troublesome than
patching the source, so we can use U_ASCII_CP with the default
conversion tables. They will do what's quoted at the top of this
mail.
Index: demo/demo.c
===================================================================
RCS file: /cvsroot/alleg/allegro/demo/demo.c,v
retrieving revision 1.32
diff -u -p -r1.32 demo.c
--- demo/demo.c 7 Jun 2005 11:56:48 -0000 1.32
+++ demo/demo.c 15 Oct 2005 19:04:28 -0000
@@ -65,6 +65,15 @@ int main(int argc, char *argv[])
jumpstart = TRUE;
}
+ /* The fonts we are using don't contain the full latin1 charset (not to
+ * mention Unicode), so in order to display correctly author names in
+ * the credits with 8-bit characters, we will convert them down to 7
+ * bits with a custom mapping table. Fortunately, Allegro comes with a
+ * default custom mapping table which reduces Latin-1 and Extended-A
+ * characters to 7 bits. We don't even need to call set_ucodepage()!
+ */
+ set_uformat(U_ASCII_CP);
+
srand(time(NULL));
if (allegro_init() != 0)
return 1;
Index: docs/src/allegro._tx
===================================================================
RCS file: /cvsroot/alleg/allegro/docs/src/allegro._tx,v
retrieving revision 1.368
diff -u -p -r1.368 allegro._tx
--- docs/src/allegro._tx 14 Oct 2005 23:25:39 -0000 1.368
+++ docs/src/allegro._tx 15 Oct 2005 19:04:45 -0000
@@ -1086,15 +1086,31 @@ is best to set it with set_uformat() jus
When you select the U_ASCII_CP encoding mode, a set of tables are used to
convert between 8-bit characters and their Unicode equivalents. You can
use this function to specify a custom set of mapping tables, which allows
- you to support different 8-bit codepages. The `table' parameter points to
- an array of 256 shorts, which contain the Unicode value for each
- character in your codepage. The `extras' parameter, if not NULL, points to
- a list of mapping pairs, which will be used when reducing Unicode data to
- your codepage. Each pair consists of a Unicode value, followed by the way
- it should be represented in your codepage. The table is terminated by a
- zero Unicode value. This allows you to create a many->one mapping, where
- many different Unicode characters can be represented by a single codepage
- value (eg. for reducing accented vowels to 7-bit ASCII).
+ you to support different 8-bit codepages.
+
+ The `table' parameter points to an array of 256 shorts, which contain the
+ Unicode value for each character in your codepage. The `extras' parameter,
+ if not NULL, points to a list of mapping pairs, which will be used when
+ reducing Unicode data to your codepage. Each pair consists of a Unicode
+ value, followed by the way it should be represented in your codepage.
+ The list is terminated by a zero Unicode value. This allows you to create
+ a many->one mapping, where many different Unicode characters can be
+ represented by a single codepage value (eg. for reducing accented vowels
+ to 7-bit ASCII).
+
+ Allegro will use the `table' parameter when it needs to convert an ASCII
+ string to an Unicode string. But when Allegro converts an Unicode string
+ to ASCII, it will use both parameters. First, it will loop through the
+ `table' parameter looking for an index position pointing at the unicode
+ value it is trying to convert (ie. the `table' parameter is also used for
+ reverse matching). If that fails, the `extras' list is used. If that fails
+ too, Allegro will put the character `^', giving up the conversion.
+
+ Note that Allegro comes with a default `table' and `extras' parameters
+ set internally. The default `table' will convert 8-bit characters to `^'.
+ The default `extras' list reduces Latin-1 and Extended-A characters to 7
+ bits in a sensible way (eg. an accented vowel will be reduced to the same
+ vowel without the accent).
@@int @need_uconvert(const char *s, int type, int newtype);
@xref set_uformat, get_uformat, do_uconvert, uconvert