Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: Radiant on Mon 19/04/2004 13:49:40

Title: Feature request: ASCII accented characters
Post by: Radiant on Mon 19/04/2004 13:49:40
- suggestion: when displaying a SCI-font, it would be easy to add support for extended characters (German and French accented letters, in particular). These correspond to ASCII codes 128-140 roughly. It seems to be easy to modify the WFN font format to support 140 characters rather than 128, or alternatively the game could use the characters 0-32 instead, which are currently unused (i.e. char % 128). Both SCI studio and Radiant FontEdit allow editing these. This would be helpful to all people making translations of games.

For instance I've added accented characters to this font file: agsfnt0 (http://www.liacs.nl/~psimoons/dls/agsfnt0.wfn)
Title: Re:Feature request: ASCII accented characters
Post by: Pumaman on Mon 19/04/2004 21:16:55
Sounds a reasonable enough request, I'm not sure why I never implemented this. I'll add it to my list.
Title: Re:Feature request: ASCII accented characters
Post by: rtf on Tue 20/04/2004 05:05:26
I'd like to take a look at that... list... ;)
Title: Re:Feature request: ASCII accented characters
Post by: Gilbert on Tue 20/04/2004 05:22:35
It's called FUTURE.TXT in the docs folder...

The docs folder is included only in final releases (ie, you don't find them in beta versions).

That list may not be updated though, but just read ALL of its content.

Also, you may check this (http://www.adventuregamestudio.co.uk/tracker.php).
Title: Re:Feature request: ASCII accented characters
Post by: strazer on Tue 20/04/2004 11:02:07
Quotethe game could use the characters 0-32 instead

I'm in the middle of editing a font and I was wondering about these (mostly empty) characters.
What is/was their purpose? How will we be able to display them?

Btw, what is the naming convention for SCI font files? I don't get the numbering thing.
Title: Re:Feature request: ASCII accented characters
Post by: Radiant on Tue 20/04/2004 12:57:11
They're control characters, actually, but obsolete in most applications.
For instance, character 13 = return, character 10 = line feed, char 27 = escape, 9 = tab, 8 = backspace.
Also they had funky graphics used in many dos-based ASCII games: 1 = smile, 2 = bright smile, 3-6 = clubs/spades/hearts/diamonds, etc.
Currently, AGS can display characters 1-31 with no problems, however the text editor used for scripting cannot really handle them well.

SCI font files are named FONT.### where ### is some number. I'm not sure why this convention was chosen, I would have named them ###.FNT myself. I believe AGS can import them regardless of name.

Title: Re:Feature request: ASCII accented characters
Post by: strazer on Thu 22/04/2004 04:52:23
I see, the position of the characters in the SCI font correspond to a normal ASCII table. I've never noticed that... :P

QuoteCurrently, AGS can display characters 1-31 with no problems, however the text editor used for scripting cannot really handle them well.

So how do you use one of these at the moment? As you say, they are control characters so they aren't displayed in the script editor.
Title: Re:Feature request: ASCII accented characters
Post by: Gilbert on Thu 22/04/2004 06:12:44
I never tried, but maybe it works in the "hard" way.

Like:

Display("%c is a special character", 12);
Title: Re:Feature request: ASCII accented characters
Post by: strazer on Thu 22/04/2004 06:19:24
That works. Thanks a lot!
Title: Re:Feature request: ASCII accented characters
Post by: Gregjazz on Thu 22/04/2004 06:51:31
By the way, does AGS support extended characters in TTF fonts? For example, if I import a Chinese TTF font into AGS, will it be able to display the characters?
Title: Re:Feature request: ASCII accented characters
Post by: strazer on Thu 22/04/2004 07:07:45
I would say Yes.
The error message if you try to use extended characters with an SCI font reads:

"(Accented characters, for example the special French and German e/a/u/i letters cannot be used by default. You need to import a TTF font to do so)."

I don't know how hard it is to create a good-looking TTF with a proper accompanying outline font though.
Title: Re:Feature request: ASCII accented characters
Post by: Gilbert on Thu 22/04/2004 07:08:04
No, I assure you.

AGS cannot display double-byted characters, and there won't be many people who would use it anyways.
Title: Re:Feature request: ASCII accented characters
Post by: strazer on Thu 22/04/2004 07:39:58
Ok, so I was going to write myself a function that replaces any special characters in the supplied string with characters 1-31 from my font.

This is what I have so far:

function StrCharConv(string buffer) {
 int charpos; // stores character position

 charpos = StrContains(buffer,"ä"); // search for special character Ã,, or ä in supplied string
 if (charpos > -1) { // special character found
  if (StrComp(xxx,"Ã,,") == 0) // special character is uppercase
     StrSetCharAt(buffer,charpos,3); // replace with character standing in for Ã,,
  else // special character is lowercase
     StrSetCharAt(buffer,charpos,4); // replace with character standing in for ä
   charpos = -1; // reset search result
 }

 // more replacements to come
}

xxx: How can I return one character as a string for this comparison?
StrGetCharAt(buffer,charpos) returns char format only.

Of course it would be easiest if there were a case-sensitive StrContains function.
I thought I'd ask first before I write a more complicated function that disassembles and later reassembles the string.
Title: Re:Feature request: ASCII accented characters
Post by: Gilbert on Thu 22/04/2004 07:48:20
Quote
xxx: How can I return one character as a string for this comparison?
Try the hard way:
StrFormat(tmpstr,"%c",StrGetCharAt(buffer,charpos);

So:

function StrCharConv(string buffer) {
 int charpos; // stores character position

 charpos = StrContains(buffer,"ä"); // search for special character Ã,, or ä in supplied string
 if (charpos > -1) { // special character found
 StrFormat(tmpstr,"%c",StrGetCharAt(buffer,charpos);
  if (StrComp(tmpstr,"Ã,,") == 0) // special character is uppercase
     StrSetCharAt(buffer,charpos,3); // replace with character standing in for Ã,,
  else // special character is lowercase
     StrSetCharAt(buffer,charpos,4); // replace with character standing in for ä
 }

 // more replacements to come
}



Quote
Of course it would be easiest if there were a case-sensitive StrContains function.
I'm not sure (as I never type accented characters and I don't know how anyways), but maybe the case-insensitiveness applies only to the standard A-Z alphabets, so accented characters in different cases maybe be considered different already, you may need to experiment though.


Ah there's a yet easier way (I won't write the full codes now, I think you understand it):
if (StrGetCharAt(buffer,charpos)=='Ã,,')  { blah bla bla

Note: A character is a one byte integer, so you can use = and == directly.
Title: Re:Feature request: ASCII accented characters
Post by: strazer on Thu 22/04/2004 08:08:15
QuoteTry the hard way

Oh right, you had shown me already. I should have known that...Sorry. :-[

Quoteaccented characters in different cases maybe be considered different already

My, you're right. Why do I complicate things so much?

Ok, here's what I have now:

function StrCharConv(string buffer) {
 int charpos=-1; // stores character position
 
 charpos = StrContains(buffer,"Ã,,"); // search for uppercase character
 while (charpos != -1) { // start loop to replace ALL occurrences of this character
   StrSetCharAt(buffer,charpos,3); // replace with character standing in for Ã,,
   charpos = StrContains(buffer,"Ã,,"); // check for next occurrence
 } // exit loop if no further occurrences found

 // more replacements here
}


Thanks for your help, Gilbert!
If you don't have any further suggestions, I'll go with this one.
Title: Re:Feature request: ASCII accented characters
Post by: Gilbert on Thu 22/04/2004 08:53:33
Heh did you read my "easier" way after edit? ;)

Nice word for the much more compact codes.
Title: Re:Feature request: ASCII accented characters
Post by: strazer on Thu 22/04/2004 08:59:58
Yes, I have. Thanks, I'll remember that. :)

But what do you mean by
QuoteA character is a one byte integer, so you can use = and == directly.
? Could you please give an example?
Title: Re:Feature request: ASCII accented characters
Post by: Gilbert on Thu 22/04/2004 09:19:30
I just mean that unlike strings, you can manipulate char variables like integers, and use them ambigorously, like for example:

char tmpchar='A';



tmpchar+=2; //will make tmpchar into 'C'
Title: Re: Feature request: ASCII accented characters
Post by: Orieac on Fri 22/04/2005 12:31:00
This was a great help. I notice that letter 0 can't be used.
But if we have many cases to change this may not be easy to edit/read. I made a small chance to the code.



function StrCCAux(string bf, string letter, int cs) {Ã, 
int charpos=-1; // stores character position
//Ã,  Ã, 
charpos = StrContains(bf,letter); // search for uppercase characterÃ, 
while (charpos != -1) { // start loop to replace ALL occurrences of this characterÃ,  Ã, 
StrSetCharAt(bf,charpos,cs); // replace with character standing inÃ,  Ã, 
charpos = StrContains(bf,letter); // check for next occurrenceÃ, 
} // exit loop if no further occurrences foundÃ, 
}

function StrCharConv(string buffer) {
StrCCAux(buffer, "á", 1);
StrCCAux(buffer, "à ", 2);
StrCCAux(buffer, "ã", 3);
StrCCAux(buffer, "â", 4);
// more cases
StrCCAux(buffer, "à", 12);
StrCCAux(buffer, "àâ,¬", 13);
StrCCAux(buffer, "àÆ'", 14);
StrCCAux(buffer, "àÆ'", 15);
// more cases
}
Title: Re: Feature request: ASCII accented characters
Post by: strazer on Fri 22/04/2005 16:08:38
Good idea!

I've abandoned this since you can't use it with dialog scripts and I decided to just use a TTF font instead.
My main gripe with TTF fonts was that it's hard to find a font with a fitting accompanying outline font. I don't like the look of the automatic outlining feature so I'm in the process of making a fixed-size TTF font & outline myself. Works great so far.
Title: Re: Feature request: ASCII accented characters
Post by: monkey0506 on Fri 22/04/2005 16:40:25
It could work if someone wrote their own dialog system... ::)
Title: Re: Feature request: ASCII accented characters
Post by: strazer on Fri 22/04/2005 20:47:08
Btw, the original request is on the tracker: http://www.adventuregamestudio.co.uk/tracker.php?action=detail&id=119
Title: Re: Feature request: ASCII accented characters
Post by: Orieac on Sat 23/04/2005 21:44:55
I thought i had the problem solved but i was not right. I can replace accented characters with ASCII 1-31 if the text is in the script. If i use a traslation file this doesn't work anymore. I think AGS only changes the string with the translated one when showed on screen. Every other functions use the original string.


I have a question for Chris Jones: Is it possible to increase the priority of the suggestion, http://www.adventuregamestudio.co.uk/tracker.php?action=detail&id=119
If not is it possible to change the way AGS uses translated text? Because if i want to display the text centered i can't get the translated text width.

Thanks in advance
orieac

Edit: I would like to remake an old game and i would like to keep the original bitmap font.
Edit2: I will try GetTranslation (string original).
Edit3: I found the error. AGS was complaining about accents, but the problem was an empty string.
Title: Re: Feature request: ASCII accented characters
Post by: Pumaman on Sun 24/04/2005 12:37:25
Does Radiant FontEdit allow creating SCI fonts with more than 128 characters? It's all very well if I was to add support for it to AGS, but if nobody could create the fonts then there'd be no point.
Title: Re: Feature request: ASCII accented characters
Post by: Traveler on Sun 24/04/2005 14:55:18
I just tried it, and it doesn't seem to. It shows 128 characters when opening a file (unless I missed something on its UI.)

Just an idea: how hard would it be to implement characters by using sprites? One could load all character sprites and in AGS specify a sprite-character mapping table. So I'd say:

'm' -> Sprite 109
'B' -> Sprite 110
'A' -> Sprite 111
etc.

in any order. Then during runtime, the engine would just lookup each sprite for each character or draw a default black rectangle if there is no sprite associated for a character. This would allow for effects on each letter (like different colors, etc.) of a character and everyone could use any graphics in place of each character.

I don't know, if this would be hard to implement, or if even anyone would use it. Just an idea :)
Title: Re: Feature request: ASCII accented characters
Post by: strazer on Sun 24/04/2005 15:05:41
http://www.adventuregamestudio.co.uk/tracker.php?action=detail&id=34
http://www.adventuregamestudio.co.uk/tracker.php?action=detail&id=57
Title: Re: Feature request: ASCII accented characters
Post by: Radiant on Mon 25/04/2005 11:21:05
Quote from: Pumaman on Sun 24/04/2005 12:37:25
Does Radiant FontEdit allow creating SCI fonts with more than 128 characters? It's all very well if I was to add support for it to AGS, but if nobody could create the fonts then there'd be no point.

Not presently, but it would be trivial to modify it so.
Title: Re: Feature request: ASCII accented characters
Post by: Orieac on Mon 25/04/2005 16:05:10
Quote from: Radiant on Mon 25/04/2005 11:21:05

Not presently, but it would be trivial to modify it so.



Could it be possible to open the new sci fonts. i think some of then already have accents.

http://freesci.linuxgames.com/scihtml/x2345.html#AEN2349
Quote from: Freesci_doc

The SCI font resource
SCI font resources remained unchanged during the SCI revisions and were still used in SCI32. Their format is relatively straightforward and completely sufficient for any 8 or even 16 bit character table:


Table 3-1. The SCI font resource data structure

Offset Type Meaning
0 16 bit integer, little endian encoding Always zero (?)
2 16 bit integer, little endian encoding NUMCHAR: Number of characters
4 16 bit integer, little endian encoding HEIGHT: Number of pixel lines per text line
6 + NR * 2 16 bit integer, little endian encoding Absolute offset of the character #NR, where 0 <= NR < NUMCHAR


HEIGHT does not affect the height of a character, though- it only tells the interpreter how far to move downwards when displaying a line of text. The characters referenced to starting at offset 6 are encoded as follows:

Table 3-2. The SCI font resource character data structure

Offset Type Meaning
0 unsigned 8 bit integer character HEIGHT
1 unsigned 8 bit integer character WIDTH
2... bitmask, size HEIGHT * round_up(WIDTH / 8) Bitmask for the character

The bitmap consists of HEIGHT lines of n bytes, where n equals the number of bytes required for storing WIDTH bits. Data is stored with the MSB first, in little-endian encoding (first byte describes the 8 leftmost pixels), where a pixel is drawn iff the bit it corresponds to is set.
Title: Re: Feature request: ASCII accented characters
Post by: Orieac on Wed 27/04/2005 15:02:05
Quote from: Pumaman on Sun 24/04/2005 12:37:25
Does Radiant FontEdit allow creating SCI fonts with more than 128 characters? It's all very well if I was to add support for it to AGS, but if nobody could create the fonts then there'd be no point.

So Radiant can improve fontedit. Can we see this feature after the final release of AGS 2.7?
Title: Re: Feature request: ASCII accented characters
Post by: Pumaman on Wed 27/04/2005 19:52:25
I will certainly consider it for a future version.
Title: Re: Feature request: ASCII accented characters
Post by: Radiant on Thu 28/04/2005 08:05:53
Quote from: Orieac on Mon 25/04/2005 16:05:10
Could it be possible to open the new sci fonts. i think some of then already have accents.

I've seen SCI fonts with accents, but they tend to use the first 32 characters for that. I've never come across a 256-char SCI font, if you have one please send it to me. Reading it would be easy.
Title: Re: Feature request: ASCII accented characters
Post by: Orieac on Thu 28/04/2005 10:48:36
Quote from: Radiant on Thu 28/04/2005 08:05:53

I've seen SCI fonts with accents, but they tend to use the first 32 characters for that. I've never come across a 256-char SCI font, if you have one please send it to me. Reading it would be easy.


I have some sci fonts with accents. But since fontedit can't open then i really can't say if the font has 256 char.  But have a look at the ones from the french version of SQ5, http://www.geocities.com/orieac/FontSQ5FREN.zip
Title: Re: Feature request: ASCII accented characters
Post by: Orieac on Thu 12/05/2005 12:36:12
Quote from: Pumaman on Sun 24/04/2005 12:37:25
Does Radiant FontEdit allow creating SCI fonts with more than 128 characters? It's all very well if I was to add support for it to AGS, but if nobody could create the fonts then there'd be no point.

Sorry to come back with this but i had another sugestion. In AGS we can use an outline font with another one (two fonts). I think an easy way to support the other 128 caracters could be using another font. I think this don't require too many changes in AGS engine, and we can use the available version of fontedit.

Orieac
Title: Re: Feature request: ASCII accented characters
Post by: Orieac on Wed 05/10/2005 23:03:58
I was updating some functions to ags 2.71rc1 but found one problem. How can i change a String with a custom function? I've made the following changes:


function StrCCAux(String bf, const string letter, int cs) {Ã, 
int charpos=-1; // stores character position
//Ã,  Ã, 
charpos = bf.Contains(letter); // search for uppercase characterÃ, 
while (charpos != -1) { // start loop to replace ALL occurrences of this characterÃ,  Ã, 
st=st.ReplaceCharAt(charpos,cs); // replace with character standing inÃ,  Ã, 
charpos = bf.Contains(letter); // check for next occurrenceÃ, 
} // exit loop if no further occurrences foundÃ, 
}

function StrCharConv(String buffer) {
StrCCAux(buffer, "á", 1);
StrCCAux(buffer, "à ", 2);
StrCCAux(buffer, "ã", 3);
StrCCAux(buffer, "â", 4);
// more cases
StrCCAux(buffer, "à", 12);
StrCCAux(buffer, "àâ,¬", 13);
StrCCAux(buffer, "àÆ'", 14);
StrCCAux(buffer, "àÆ'", 15);
// more cases
}

My problem is that when StrCCAux ends, StrCCAux returns the same String. How don't know how do they work in Java/C#. Who can StrCCAux change the String?
Title: Re: Feature request: ASCII accented characters
Post by: strazer on Thu 06/10/2005 00:22:40
Quote
st = st.ReplaceCharAt(charpos,cs); // replace with character standing in   

Where does "st" come from? Shouldn't it be "bf"?

If


bf = bf.ReplaceCharAt(charpos,cs); // replace with character standing in   


doesn't work, try:


String changed = bf.ReplaceCharAt(charpos,cs); // replace with character standing in 
bf = changed;
Title: Re: Feature request: ASCII accented characters
Post by: Orieac on Thu 06/10/2005 08:50:06
This is what i have now:

Quote
function StrCCAux(String st,const string letter, int cs) {Ã, 
int charpos=-1; // stores character position
charpos = st.Contains(letter); // search for characterÃ, 
while (charpos != -1) { // start loop to replace ALL occurrences of this characterÃ,  Ã, 
Ã,  Ã,  Ã,  String changed=st.ReplaceCharAt(charpos,cs); // replace with character standing in
Ã,  Ã,  Ã,  st = changed;Ã,  Ã, 
Ã,  Ã,  Ã,  charpos = st.Contains(letter); // check for next occurrenceÃ, 
} // exit loop if no further occurrences foundÃ, 
Display(st);
}


Display(st) shows that the String st has changed. But when the function ends the changes aren't saved (i get the old String). This worked with the old strings, but now i don't know where is the problem.Ã,  ???
Title: Re: Feature request: ASCII accented characters
Post by: Scorpiorus on Thu 06/10/2005 17:21:02
Yes, the problem has to do with a way the new Strings are handled. Since a String is a constant and can't be changed the .ReplaceCharAt() function creates a new instance of String instead. You catch the string with the "st" pointer variable but it's declared as a local one (ie. within the function body). When function ends "st" is discared along with the changed String as well.

Therefore, you can either set up a global pointer to changed String (I would not recommend this) or, what is much clearer, have the function do actually return modified String:

String StrCCAux(String st,const string letter, int cs) {
   int charpos=-1;
   charpos = st.Contains(letter);
   while (charpos != -1) {
      st=st.ReplaceCharAt(charpos,cs);
      charpos = st.Contains(letter);
   }

   return st;
}


Then you can catch it from within the caller function as follows:

function StrCharConv(String buffer) {

   buffer = StrCCAux(buffer, "á", 1);
   ...
}


EDIT:

Oh by the way, if StrCharConv is also supposed to change and then return String buffer it has to be altered in the very same way, ie...

String StrCharConv(String buffer) {

   buffer = StrCCAux(buffer, "á", 1);
   ...

   return buffer;
}

So that its caller could in turn receive changes too.
Title: Re: Feature request: ASCII accented characters
Post by: Orieac on Thu 06/10/2005 18:15:02
Quote from: Scorpiorus on Thu 06/10/2005 17:21:02
String StrCCAux(String st,const string letter, int cs) {

This doen'st work. The problem is the String before the function name.
I have now the error: The variable 'int' is already defined

I thought that in AGS a function could only return an integer.
Title: Re: Feature request: ASCII accented characters
Post by: Scorpiorus on Thu 06/10/2005 18:17:17
Just replace "function" with "String". By the way in AGS "function" stands for "int" ;)

[Edit]: And if you have the import declaration in the header script it needs to be changed too:

import String StrCCAux(String st,const string letter, int cs);

So "String" instead of "function".
Title: Re: Feature request: ASCII accented characters
Post by: Orieac on Thu 06/10/2005 18:41:30
Quote from: Scorpiorus on Thu 06/10/2005 18:17:17
Just replace "function" with "String". By the way in AGS "function" stands for "int" ;)
That was the error. I added String before function  ;D  ;D Thanks.
It's now working again.