Jump to ID:
Graphics

Project Home

Documents

Discussions

Wiki

Project Info
Forum Topic - What are the basics of font rendering?: Page 1 of 2 (18 Items)
   
 
 
What are the basics of font rendering?  
I'm sure this is my own failure to understand the obvious, but if somebody could give me some pointers it would be very 
helpful.  The application program I am working on continually reads jpg and/or png files, manipulates them in various 
ways, then writes out a bmp file, using the graphics framework.  There is no user interface.  Photon is not running. The
 application works fine, except that I now find I need to render text onto the images, and can't figure out even the 
basic steps to do so.

That's my general problem, but far as specifics are concerned, I have two questions to start with:

1.  Given that Photon isn't being used, what software can I use as a font server, and what are the specifics of 
obtaining and starting up that software outside of a Photon-related context?
2.  How does one interact with the font server within the context of the graphics framework to get the text rendered 
into memory-buffered imagery?  The names of specific API functions would be very helpful.

Thanks!
Re: What are the basics of font rendering?  
-- start 'phfont -d /usr/photon/font_repository' -- this will run the server -- you do not need photon
-- use PfAttach(), PfRender(), etc API to render the fonts -- http://www.qnx.com/developers/docs/6.5.0/topic/com.qnx.doc
.photon_lib_ref/pf-base.html
Re: What are the basics of font rendering? [bcc]  
Thanks, Misha, that's very useful.  The platform I'm working on is 
actually a CAR system that doesn't seem to have phfont on it, but if I 
copy a copy of phfont over from QNX 6.5.0, it seems to run and not complain.

However ... as soon as my app tries to use any of the API's font-related 
functions there's a segfault.  Recall that I'm not running Photon.  I 
wonder if there's some kind of initialization I'm supposed to be doing 
that would normally have been done by starting Photon?  Or, could a 
versioning discrepancy in phfont be the problem?

Or perhaps I simply don't know what I'm doing in regard to text 
rendering.  Is there a suitable coding tutorial somewhere?  (Remember 
... I don't have any user interface here, so any tutorial that involves 
displaying stuff in windows in Photon is of limited use to me.)

Thanks again!

On 05/13/2011 08:45 AM, Misha Nefedov wrote:
> -- start 'phfont -d /usr/photon/font_repository' -- this will run the server -- you do not need photon
> -- use PfAttach(), PfRender(), etc API to render the fonts -- http://www.qnx.com/developers/docs/6.5.0/topic/com.qnx.
doc.photon_lib_ref/pf-base.html
>
>
>
>
> _______________________________________________
>
> Advanced Graphics
> http://community.qnx.com/sf/go/post85666
Re: What are the basics of font rendering? [bcc]  
I am not aware of a Pf*() tutorial. I recommend starting with the sample code that is in PfRender() API docs. 
Also check that:
-- you are running pfont,  
-- check sloginfo, 
-- see where the app is crashing.
Re: What are the basics of font rendering? [bcc] [bcc][auto-ip]  
What is pfont? If you meant phfont, yes ps shows that it's running.

On 05/13/2011 02:20 PM, Misha Nefedov wrote:
> I am not aware of a Pf*() tutorial. I recommend starting with the sample code that is in PfRender() API docs.
> Also check that:
> -- you are running pfont,
> -- check sloginfo,
> -- see where the app is crashing.
>
>
>
> _______________________________________________
>
> Advanced Graphics
> http://community.qnx.com/sf/go/post85678
Re: What are the basics of font rendering? [bcc] [bcc][auto-ip]  
phfont ;-)
Re: What are the basics of font rendering? [bcc] [bcc][auto-ip]  
On 05/13/2011 02:20 PM, Misha Nefedov wrote:
> I am not aware of a Pf*() tutorial. I recommend starting with the sample code that is in PfRender() API docs.
Thanks, Misha, I hadn't gotten as far as trying to render the text, so I 
hadn't yet become aware of that sample code.  More on that below.
> Also check that:
> -- you are running pfont,
Here's what "ps -Af | grep phfont" says:

     0    1163315          1  - May16 ?        00:00:00 phfont -d 
/usr/photon/font_repository
     0    1163315          1  - May16 ?        00:00:00 phfont -d 
/usr/photon/font_repository

> -- check sloginfo,
As far as sloginfo is concerned, the following lines seem to be the only 
relevant ones:

...
May 16 07:53:10    1     8     0 phfont: init...
May 16 07:53:10    1     8     0 phfont: initialized.
May 16 07:53:10    1     8     0 phfont: '/dev/phfont[<32|64>]' server 
installed.
...

> -- see where the app is crashing.
As I understand it, what the sample code in the PfRender() docs say to 
do is:

   1. Run PfAttach().
   2. Run PfFindFont().
   3. Run PfRender().

I segfault the very first time I hit PfFindFont().  Here's the relevant 
code-snippet from my program:

   ...
   FontServer = PfAttach (NULL, 0);
   if (FontServer == NULL)
     {
       fprintf (stderr, "Cannot attach to font server.\n");
       goto Error;
     }
   for (i = 0; i < 3; i++)
     for (j = 0; j < NUM_FONT_SIZES; j++)
       {
         int FontSize;
         FontID *ID;
         FontSize = MIN_FONT_SIZE + INC_FONT_SIZE * j;
         ID = PfFindFont (FontDescriptions[i], FontStyles[i],
             FontSize);
         if (NULL == ID)
           {
             fprintf (stderr, "Cannot find font %s size %d style 0x%X\n",
                 FontDescriptions[i], FontSize, FontStyles[i]);
           }
         FontStructures[i]->ID = ID;
       }
     ....

At the point where the segfault occurs in PfFindFont():

    * FontDescriptions[i] is a pointer to the string "ronsanss", which
      is a TrueType font that I've installed and is known-good (at least
      in Linux).  When I say I've "installed" it, I mean that I hope I
      installed it correctly and that one of the lines in
      /usr/photon/font_repository/fontdir is "ronsanss,0@RonSans.ttf,Ron
      Sans,0,,000D-FFFD,p,228x151,4508K".  Please recall that I'm not
      running Photon, so I'm not aware of any good way to know that the
      installation was correct until my app actually works.
    * FontStyles[i] is 16 (PF_STYLE_ANTIALIAS).
    * FontSize is 10.

>
>
> _______________________________________________
>
> Advanced Graphics
> http://community.qnx.com/sf/go/post85678

Re: What are the basics of font rendering? [bcc] [bcc][auto-ip]  
Oops! I was a bit to hasty in the code snippet I sent in my last 
message.  Here's a better one:

   FontServer = PfAttach (NULL, 0);
   if (FontServer == NULL)
     {
       fprintf (stderr, "Cannot attach to font server.\n");
       goto Error;
     }
   for (i = 0; i < 3; i++)
     for (j = 0; j < NUM_FONT_SIZES; j++)
       {
         int FontSize;
         FontID *ID;
         FontName Description;
         FontSize = MIN_FONT_SIZE + INC_FONT_SIZE * j;
         if (NULL == PfGenerateFontName (
             FontDescriptions[i], FontStyles[i], FontSize, Description))
           {
             fprintf (stderr, "Cannot get font name %s size %d style 
0x%X\n",
                 FontDescriptions[i], FontSize, FontStyles[i]);
             return (1);
           }
         ID = PfFindFont (Description, FontStyles[i], FontSize);
         if (NULL == ID)
           {
             fprintf (stderr, "Cannot find font %s size %d style 0x%X\n",
                 FontDescriptions[i], FontSize, FontStyles[i]);
             return (1);
           }
         FontStructures[i]->ID = ID;
       }

Here the segfault occurs as soon as PfGenerateFontName() is hit.  The 
arguments to PfGenerateFontName() correspond to the description I gave 
for the arguments of PfFindFont() in my last message.  In point of fact, 
the segfault occurs if I simply run the sample code in the 
PfGenerateFontName() doc:

   FontServer = PfAttach (NULL, 0);
   if (FontServer == NULL)
     {
       fprintf (stderr, "Cannot attach to font server.\n");
       goto Error;
     }
     {
       char szHelvetica12[MAX_FONT_TAG];

       if (PfGenerateFontName ("Helvetica", PF_STYLE_BOLD, 12, 
szHelvetica12)
           == NULL)
         {
           perror ("Unable to find font");
         }
     }
Re: What are the basics of font rendering? [bcc] [bcc][auto-ip]  
This is likely that you are trying to use photon wrapper functions, and since you are not connected to photon they fail.

Change the code to use Pf*Cx() API. For example PfGenerateFontNameCx(). It takes an extra parameter which is a struct 
_Pf_ctrl * -- the one returned by the PfAttachCx().
Re: What are the basics of font rendering? [bcc] [bcc][auto-ip]  
Well, you're right that it doesn't segfault with 
PfGenerateFontNameCx().  The next problem is that no matter what 
pkgDescription argument I plug into PfGenerateFontNameCx(), the function 
always returns NULL.  I guess the names from the fontdir file are not 
what is supposed to be in pkgDescription.  Certainly, the string 
"Helvetica" as given in the sample code doesn't work.  How can I find a 
valid pkgDescription to plug in?

On 05/16/2011 10:16 AM, Misha Nefedov wrote:
> This is likely that you are trying to use photon wrapper functions, and since you are not connected to photon they 
fail.
> Change the code to use Pf*Cx() API. For example PfGenerateFontNameCx(). It takes an extra parameter which is a struct 
_Pf_ctrl * -- the one returned by the PfAttachCx().
>
>
>
> _______________________________________________
>
> Advanced Graphics
> http://community.qnx.com/sf/go/post85711