ttf algorithem

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
viridite
Posts: 16
Joined: Thu Nov 08, 2007 4:28 am

ttf algorithem

Post by viridite »

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!
viridite
Posts: 16
Joined: Thu Nov 08, 2007 4:28 am

Post by viridite »

why nobody answer this?
did anybody use sdl ttf for development?
J.F.
Posts: 2906
Joined: Sun Feb 22, 2004 11:41 am

Post by J.F. »

Never used it.

You need to wait more than a few hours. Remember that most of the people who would answer your question are professional programmers who just frequent this board in their spare time. You could go a couple days before getting a post.
viridite
Posts: 16
Joined: Thu Nov 08, 2007 4:28 am

Post by viridite »

thanks!

so you never used ttf to display something? OK.... do you have some interesting things to introduce? haha.

anyway, nice to meet you,kind man!
J.F.
Posts: 2906
Joined: Sun Feb 22, 2004 11:41 am

Post by J.F. »

Nope, never used TTF, but I'm thinking about it. My current GUI code all uses the debug printing, and while it does the job, it's not the prettiest thing. So I'm thinking about switching the display part of the gui to TTF. But that doesn't help you right now. :)
User avatar
tacoSunday
Posts: 34
Joined: Fri Aug 31, 2007 10:05 pm

Post by tacoSunday »

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.
viridite
Posts: 16
Joined: Thu Nov 08, 2007 4:28 am

Post by viridite »

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.
haha, i've tried ... but memory is not enough..........
User avatar
tacoSunday
Posts: 34
Joined: Fri Aug 31, 2007 10:05 pm

Post by tacoSunday »

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!
viridite
Posts: 16
Joined: Thu Nov 08, 2007 4:28 am

Post by viridite »

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.
User avatar
tacoSunday
Posts: 34
Joined: Fri Aug 31, 2007 10:05 pm

Post by tacoSunday »

but maybe i can try to cache several pages first and then if there are more characters in need i will cache again.....
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.

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
viridite
Posts: 16
Joined: Thu Nov 08, 2007 4:28 am

Post by viridite »

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.
Post Reply