Fonts: Difference between revisions
no edit summary
No edit summary |
|||
Line 62: | Line 62: | ||
* If the answer is '''"a"''', then just import into AGS any TTF font you'll find on the Interwebs. It will be rendered smoothly. DON'T FORGET to pick a font that has the extra 128 characters for "Western Europe" languages. This way you'll make it possible to translate your game later (see section "Where can I find fonts? for details). If you're not happy with the quality of the rendering, you can use [http://www.adventuregamestudio.co.uk/forums/index.php?topic=44359.0 Calin Leafshade's plugin (2011)] to enhance it even more. | * If the answer is '''"a"''', then just import into AGS any TTF font you'll find on the Interwebs. It will be rendered smoothly. DON'T FORGET to pick a font that has the extra 128 characters for "Western Europe" languages. This way you'll make it possible to translate your game later (see section "Where can I find fonts? for details). If you're not happy with the quality of the rendering, you can use [http://www.adventuregamestudio.co.uk/forums/index.php?topic=44359.0 Calin Leafshade's plugin (2011)] to enhance it even more (allows you to add antialiasing). | ||
* If the answer is '''"b"''', then you need a font that looks good in low resolution. That is, what we call a pixelated font -- something similar to [http://www.1stwebdesigner.com/wp-content/uploads/2010/05/pixel-fonts/deluxe-font-free-pixel-fonts.jpg this]. In this article we will refer to these fonts as "pixel-art fonts", or "bitmap fonts" (because they're nothing more than a tiny set of pixelly drawings). As opposed to vector fonts, usually high-resolution. | * If the answer is '''"b"''', then you need a font that looks good in low resolution. That is, what we call a pixelated font -- something similar to [http://www.1stwebdesigner.com/wp-content/uploads/2010/05/pixel-fonts/deluxe-font-free-pixel-fonts.jpg this]. In this article we will refer to these fonts as "pixel-art fonts", or "bitmap fonts" (because they're nothing more than a tiny set of pixelly drawings). As opposed to vector fonts, usually high-resolution. | ||
Line 250: | Line 250: | ||
It can be found [http://www.adventuregamestudio.co.uk/forums/index.php?topic=44359.msg591862#msg591862 here]. | It can be found [http://www.adventuregamestudio.co.uk/forums/index.php?topic=44359.msg591862#msg591862 here]. | ||
If you don't know anything about fonts, it can be confusing at first, but this plugin can actually come handy for two, unrelated reasons: | |||
# '''It lets you swap glyphs''' for other glyphs, at any time (read below) | |||
# '''It lets you pre-render your fonts''' and then render them with anti-aliasing (read below) | |||
'''How does it work?''' | |||
Three steps : | |||
# render all the characters of your charset into one big sprite. I mean, a regular AGS sprite that you can then import with an alpha layer (i.e. transparency) and such, | |||
# Using the provided functions, tell the plugin which slot in the sprite corresponds to which character (a.k.a. glyph), | |||
# Just use the regular AGS functions in game (Say(), Display()...) to display text onto the screen. | |||
'''About swapping glyphs :''' | |||
If you have complex needs in terms of characters sets, then you can substitute a glyph "on the fly" from any character in your "characters table" sprite. | |||
Like, imagine your game uses a complex language that uses sometimes 128 characters, sometimes 128 other characters, or even any amount of sets of 128 characters (just not at the same time) (or you can mix several fonts to achieve that). Well then simply use "SetGlyph" at the right time to swap a character with another glyph from your big glyphs table. | |||
PLEASE NOTE: I haven't tested that plugin myself, so I can't go into details about how it numbers the characters. I don't know if you can number characters only from 0 to 127, or to 255, or to an infinity of characters). | |||
'''About pre-rendering fonts :''' | |||
AGS has an inconvenience regarding fonts: it does not anti-alias them. if your game is in very high resolution, then you won't notice it. But if it's in medium resolution (like 640x480 or 800x600), it might not look very good. | |||
So simply render the sprite containing all the anti-aliased characters (the tool's page explains how to do that), and then the text will be anti-aliased (and pretty!) in the game. | |||
::'''Pros:''' | ::'''Pros:''' | ||
::* Allows very '''fancy fonts''', including pixel-art fonts ('''outlines''' are also not too complicated to generate with that tool -- then again don't forget that AGS can also generate outlines automatically) | ::* Allows very '''fancy fonts''', including pixel-art fonts ('''outlines''' are also not too complicated to generate with that tool -- then again don't forget that AGS can also generate outlines automatically) | ||
::* Directly converts from TTF to pixel-ready. | ::* Directly converts from TTF to pixel-ready. | ||
Line 274: | Line 295: | ||
=== Making TTF Fonts === | === Making TTF Fonts === | ||
That's outside of the scope of this document. Creating "real" fonts is | Here, we're not talking about converting a vector TTF font into a pixel font, but about how to make a vector font from scratch. | ||
That's outside of the scope of this document. Creating "real" fonts is an incredibly complex task. But in case you really want to create your own font [http://fontforge.org/ Font Forge] is a good tool to start with. | |||
== | == What's all the fuss about 256 characters? == | ||
=== Use a GOOD text editor === | |||
First of all, do yourself a favour. '''Never EVER use Notepad to open a text file'''. Instead, use an editor that won't silently mess with the current encoding when you save. | |||
My favourite one is '''[http://notepad-plus-plus.org Notepad++]''' (notice the "++" at the end). You can switch between encodings (ANSI to UTF-8 and back) and you can switch between rendering codepages (ANSI: Western Europe, ANSI:Central Europe, etc.) | |||
=== Understanding characters encoding === | === Understanding characters encoding === | ||
I'll try to explain it as simply as possible. | |||
A few principles you need to accept: | |||
* In computer science, '''everything''' is a number. Character 'a' is a number (it's actually number 97). | |||
* '''Numbers take up space.''' Yup. they don't just "float around". and the bigger the number, the more space it takes. Numbers from 0 to 127 take a half byte. If you want to count from 0 to 255, you need a full byte. If you want to be able to count from 0 to about 65,000 then you need two bytes, and to go up to about 4 billions, then you need four bytes. | |||
Now, the question is : how many different letters from different alphabets are there on the whole planet Earth? Tens of thousands. Probably tens of millions if you include all the ways to accentuate a character, and all the weird shit from many languages where letters can be attached together depending on the situation, or are drawn differently if they're at the end of a word, etc. | |||
Tens of millions of different characters. That means many bytes required in memory just to handle '''''one''''' letter on the screen. | |||
In the early days of computer science, you couldn't afford to manipulate several bytes for one letter. Suggesting that would make you sound like a crazy person. Half a byte was already a lot. Since american companies were leading the sector, they decided that they would stick to the basic, unaccented latin alphabet used by the English language (that is 'a' to 'z') plus digits plus a few other useful characters. It all fits in 128 characters, which means it all fits in half a byte. | |||
== encoding == | |||
Encoding means "turning a letter into the corresponding number". Your favorite word processor does it all the time, wenever you save your file to the hard drive. With the basic 128 characters, it's very easy. The computer simply complies with [http://macao.communications.museum/images/exhibits/2_18_8_1_eng.png this table], which is the standard shared by everyone. this standard is called "'''ASCII'''". | |||
PRIMITIVE STANDARD | |||
LETTER --------------------> NUMBER | |||
Easy! | |||
But then what if you need a weird character, like 'Ø', mostly used by the Norwegians/Danes ? what number should it be? Back then in the late 80's, Computer science people said "OK, we'll give you an extra half byte, for a grand total of one byte" (wich means characters numbered from 0 to 255). at Microsoft, this new standard would be called "'''ANSI'''". Using more than one byte was still out of the question. They said : "you may use one of the 'unused' numbers from 128 to 255 to encode your damn 'Ø'". So, for Western Europe, it was decided by Microsoft that character 'Ø' would be encoded as number 216. The 'unused' characters from 128 to 255 were quickly filled with letters from the whole Western Europe (Spanish, German, French, etc.). [http://www.globaliconnect.com/excel/images/ExcelFormulas/StringFunctions/asciitable_3.gif Click here] to see the whole ANSI table for Western Europe, aka "Latin 1". | |||
But then there would be no room left for Central European characters (Slovakia, Croatia, Hungarian, etc.)! | |||
That's where the concept of "encoding" becomes interesting. You don't just "turn a character into a number". '''You also need to know WHAT TABLE of correspondance you're using.''' | |||
* If you use the correspondance table for ''Western Europe'' (aka Latin 1), then "Ø" becomes 233. | |||
* If you use the correspondance for Central Europe, then "Ø" becomes... nothing! Because it doesn't exist in that table. You're not even expected to have that key on your keyboard if you're in central Europe, you freak. If you press it, then the result is not guaranteed. You can see the Central europe (aka Latin 2) table [http://www.biega.com/ISO-8859-2.gif here] | |||
* However, still if you use the correspondance for ''Central'' Europe (aka Latin 2), then "Ř" becomes 233. | |||
'''So let's recap:''' for encoding, you need to know : | |||
* the input character/letter, | |||
* the encoding STANDARD you're using (ASCII, ANSI, etc.) | |||
* the TABLE of correspondance between the character and the output number, used by the standard | |||
=== | STANDARD | ||
+ | |||
TABLE | |||
LETTER -----------> NUMBER | |||
== Decoding == | |||
'''Decoding is the reverse process:''' From a number in memory, which character to display on screen? | |||
STANDARD | |||
+ | |||
TABLE | |||
NUMBER -----------> LETTER | |||
Now it becomes tricky. As you saw, both characters Ø and Ř can become "233" in memory depending on the settings of your computer. So when I read 233, should I display Ø and Ř ? Well it all depends on your current system settings (these are the Regional settings that you set in the Windows' Control Panel). Behind the scenes, these settings decide on a PAGE. so if your settings say that you're in Norway, behind the scenes Windows knows to use page "Western Europe" (aka Latin 1). So it displays Ø. | |||
Computer science people have even enhanced the system: they have decided that nowadays each document ever (especially Internet documents) should announce what page they should be decoded with. You can see that by yourself right now by right-clicking anywhere on this page and selecting "View page source". You'll see a bunch of technical stuff, but somewhere you'll see "charset="UTF-8" which means it should be decoded using the "UTF-8" standard. | |||
You can even push further: what if you want to try and decode this Wiki document with a different characters page? -- that is, not the one that was intended for it? What if, without changing the actual numbers that are stored in memory, you wanted tu use "Latin 2" instead of "Latin 1" to view the page? Well you can. All you have to do is save the page as a file on your desktop, then open it with the text editor I recommended earlier (Notepad++). | |||
(this section is not finished rewriting) | |||