PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

Font Class and SHLoadImage (WM2005 updates)

Hi Everyone,

I recently followed Presto's instructions to modify image.cpp to remove dependency on imgdecmp.dll by using SHLoadImage instead.

This works great on WM2005 devices as well as older (2002/2003) devices. However, I'm finding that the font class (written by Thomas 'gersen' Maniero) no longer works with this change. The bitmap fonts display correctly on WM2005 devices, but if I load my game on early 2003 devices, the bitmap fonts won't display at all.

From what I can tell, the m_rect surface size that is used in the Font::draw method is not being generated correctly.
Code:

display->Blit(x, y, m_surf, &m;_rect[str[i]]);

I can pass in a &Rect; with a fixed size and get part of the font bitmap to display which tells me this may be part of the problem. However, I don't have the expertise to understand the font class well enough to come up with a real solution.

Does anyone else use the font class with the WM2005 updates (SHLoadImage) for PocketFrog? If so, did you have to make any changes to the font class to get your bitmap fonts to display on both WM2005 and 2002/2003 devices?

Thanks!
:D
I still use gersen's font class, though it's heavily modified now. For my games, they work fine on 2002 and higher devices. I can't think of any specific changes I made to get it to work, though I did add an extra "load" function to the font class for loading fonts from files. But I'm also loading fonts from resources, so it shouldn't matter.
Code:
bool MyFont::load(DisplayDevice* display, TCHAR *sFontPath)
{
uint32_t h, w, i, pos;

for(i = 0; i <= 255; i++)
m_rect[i].Set(0, 0, 0, 0);

// carico superficie contenente il font
m_surf = LoadImage(display, sFontPath);
if(m_surf == 0)
return false;

m_surf->SetColorMask(Color(255,0,255));

h = m_surf->GetHeight();

// trovo primo mark, i pixel per lo spazio
pos = 0;
w = findNextMark(&pos, m_surf);
if(w != 0)
m_space = w;
else
return false;

i = 0;
while(trs[i] != 0)
{
// MSR: check for end of table
// se non trovo un mark allora ho controllato tutta l'immagine, esco
w = findNextMark(&pos, m_surf);
if(w == 0)
break;

// setto rettangolo. se ho settato 255 rect allora ho finito
m_rect[trs[i]].Set(pos-w, 1, pos, h);
i++;
if(i > 255)
break;
}

return true;
}
Note that this code is from a PF 0.7 project, so if you're using 0.8 with PHAL, you'll have a "Display" type instead of "DisplayDevice" type.
Hi Presto,

(BTW, I wrote the original post...I forgot to login). :oops:

Thanks for the reply. I've spent hours trying to find what is causing the problem in my font class. Is there any chance you could send me a copy of your entire 'font.cpp' file? I know that's a lot to ask, but I can't think of any other way to quickly determine the difference.

I would greatly appreciate it!

Thanks...
:D
Here you go...

I stripped out my extra functions, which don't have any impact on the actual "draw" functions, so a simple case like the following should work:
Code:
MyFont fMyFont;
DisplayDevice *pDisplay = GetDisplay();
fMyFont.load(pDisplay, _T("tahoma_8pt.gif"));
fMyFont.draw(pDisplay, 120, 155, FONT_CENTER, _T("Testing..."));
I tested it, and it seems to be working like it's supposed to.

Oh yeah... cTransparent = Color(255,0,255). You'll see it referenced in MyFont.cpp right after it loads the image.

-John
Attachments:
MyFont.zip (4 KB)
Woohoo!!! It works!! I still can't imagine what I did that caused my font class to stop working on older devices (it worked fine on WM2005). But, with your help, everything is working now...the birds are singing and the sun is shining! :D

John, if I can ever offer any help to you, please don't hesitate to ask.

Many thanks!!!
-Bobby
Wouldn't you know it, I forgot to login again. 8O But, the last post was by me.

Thanks again!

-Bobby
Glad I could help. :)

Now you can add some nifty new functions to the class to change the letter spacing, unload the fonts, etc. ;)

BapDude wrote:John, if I can ever offer any help to you, please don't hesitate to ask.
You don't happen to have a terrific artist I could borrow, eh? :roll:

Later,
-John
Yeah, I've already added some functions for spacing, etc. to the font class. Of course, I guess in the process, I messed something else up and caused the whole thing to stop working. :wink:

Unfortunately, I don't have a good graphic artist to recommend. I do all my graphics myself with photoshop. I've thought about hiring a graphic artist in the past, but I never could justify the cost. I figured I would just play around with Photoshop until I came up with something that looked nice. At least that's my approach. :D
remember: most graphic artists want paid. They tend to flame programmers who want something for nothing. I found a student who was happy to work for reasonable rates but that was 3D not 2D. I even found a chap who had worked on Disney stuff & he produced these super demos that I could not afford.