Copy link to clipboard
Copied
Hi all~
I have an air app deal with the pixel level graphic, so I choose bdf font for text displaying. This font file is 7MB size and contains maybe 60k+ chars.
So my opinion simply is:
for each char I want to display at runtime,
get its charCode as an index,
find the charCode in bdf file,
then get the bits which make up the char.
And now, the problem is that the bdf file is huge. I use File::load() method to load the data into a byteArray, then find the charCode in it. I find it takes more than 5 secs to get the position for the last char in the file.
My find logic like this:
function search(findStr:String):uint {
var basePos:uint = 0;
var tempStr:String;
while (basePos <= bdfFont.length) {
bdfFont.position = basePos;
try {
tempStr = bdfFont.readUTFBytes(findStr.length);
} catch(e:EOFError) {
trace('didn\'t find');
return;
}
if (tempStr == findStr) {
trace('found:', basePos);
return basePos;
} else {
basePos++;
}
}
}
So, how can I tweak my code to get better performance? Thanks!