ttf algorithem
ttf algorithem
Hi, guys
recently i'm trying to use SDL's ttf support to make a reader. currently i can use it to display the chinese fonts. but i found a serious problem:
1. i use a cache to read the file first to store some fonts .
2. before every draw of the screen i will then read the char from the buffer and transfer to unicode and then cache the metrics for this screen
3. draw a screen of the fonts.
i found it too slow when switching to another screen because every time i need to cache the metrics and load data from the memory stick. it's too slow!!!
so then i tried to cache all the chinese fonts in memory at the starting time but failed because it will run out of the memory. so i just wonder whether there are some good solutions for this kind of problems??
Thanks!
recently i'm trying to use SDL's ttf support to make a reader. currently i can use it to display the chinese fonts. but i found a serious problem:
1. i use a cache to read the file first to store some fonts .
2. before every draw of the screen i will then read the char from the buffer and transfer to unicode and then cache the metrics for this screen
3. draw a screen of the fonts.
i found it too slow when switching to another screen because every time i need to cache the metrics and load data from the memory stick. it's too slow!!!
so then i tried to cache all the chinese fonts in memory at the starting time but failed because it will run out of the memory. so i just wonder whether there are some good solutions for this kind of problems??
Thanks!
- tacoSunday
- Posts: 34
- Joined: Fri Aug 31, 2007 10:05 pm
If you are looking for speed, I would think rendering the ttf once to a bitmap font and then indexing into it with uv coords would be the way to go.
Hmm, just realized you are trying to use Chinese fonts wich would make for a huge bitmap font. I suppose you could use some caching scheme for the rendered chars. I don't know much about chinese writing, but I would assume most writing uses a rather limited subset at any one time.
Hmm, just realized you are trying to use Chinese fonts wich would make for a huge bitmap font. I suppose you could use some caching scheme for the rendered chars. I don't know much about chinese writing, but I would assume most writing uses a rather limited subset at any one time.
haha, i've tried ... but memory is not enough..........tacoSunday wrote:If you are looking for speed, I would think rendering the ttf once to a bitmap font and then indexing into it with uv coords would be the way to go.
Hmm, just realized you are trying to use Chinese fonts wich would make for a huge bitmap font. I suppose you could use some caching scheme for the rendered chars. I don't know much about chinese writing, but I would assume most writing uses a rather limited subset at any one time.
- tacoSunday
- Posts: 34
- Joined: Fri Aug 31, 2007 10:05 pm
I realize that memory may not be enough. That is why I suggested caching recently used characters instead of the entire character set. This was based on the assumption that only a relatively small subset of them would be in use at any given time. You have a cache of a fixed size (which you tweak to fit in available memory) and when the cache is full and you come across a char that is not already cached render it and and shove it in the cache position of the least recently used char that is cached. I am willing to bet that this will provide acceptable performance .
Best of luck
P.S. I do believe I have set a record for the most uses of the word cache in a single run-on sentence!
Best of luck
P.S. I do believe I have set a record for the most uses of the word cache in a single run-on sentence!
Thanks.
but i think that is not realistic because every try of caching data will cost at least one to two seconds. so once we need to cache some data the user needs to wait two seconds or more , it's not good at least at the very first of the caching process.
but maybe i can try to cache several pages first and then if there are more characters in need i will cache again.....
but in fact i found a famous ereader can finish this without any problem. so i guess there shall be some tricks.
but i think that is not realistic because every try of caching data will cost at least one to two seconds. so once we need to cache some data the user needs to wait two seconds or more , it's not good at least at the very first of the caching process.
but maybe i can try to cache several pages first and then if there are more characters in need i will cache again.....
but in fact i found a famous ereader can finish this without any problem. so i guess there shall be some tricks.
- tacoSunday
- Posts: 34
- Joined: Fri Aug 31, 2007 10:05 pm
That there is the answer! Once the cache is filled it gets far better. You can do this ahead of time by studying the frequency of Chinese ideograms and prepopulating the cache with the most common chars. Then the only time you have to wait for loading is when you have a cache miss. If your cache is large enough this should be a relatively infrequent occurrence. For further speedups you could then look ahead and load needed chars in the background before the user even gets to that page.but maybe i can try to cache several pages first and then if there are more characters in need i will cache again.....
Trust me, this subject is old hat in the CS field and well studied.
The link is just a google search for texture caching schemes. Your problem is no different than texture caching and pre-caching. You are simply caching a dynamically generated texture.
good luck
Thanks very much...
I tried yesterday and it did speed up... i will try to make it faster by imporving the algorithem. somehow it works fine.
currently i used a cache to load hundreds of charactors and once there appears one that isn't hit in the cache i will replace it with the least used one.
so this method do solved my problem. thanks, everybody.
I tried yesterday and it did speed up... i will try to make it faster by imporving the algorithem. somehow it works fine.
currently i used a cache to load hundreds of charactors and once there appears one that isn't hit in the cache i will replace it with the least used one.
so this method do solved my problem. thanks, everybody.