Project Home
Project Home
Documents
Documents
Wiki
Wiki
Discussion Forums
Discussions
Project Information
Project Info
Forum Topic - What are the basics of font rendering?: (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
Re: What are the basics of font rendering? [bcc] [bcc][auto-ip]  
Forget my last message.  I was just being dumb, and didn't pass 
PfGenerateFontNameCx() the right struct.

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
Re: What are the basics of font rendering? [bcc] [bcc][auto-ip]  
So Misha, as I said before, you were right and PfGenerateFontNameCx() 
does not segfault.  But I must still be failing to understand some basic 
point.  Right now I'm trying the following code:

   FontServer = PfAttachCx (NULL, 0);
   if (FontServer == NULL)
     {
       fprintf (stderr, "Cannot attach to font server.\n");
       goto Error;
     }
#if 1
     {
       char *FontName = "Courier10 BT";
       FontSize = 10;
       if (NULL == PfGenerateFontNameCx (FontServer, FontName, 0, FontSize,
           Description))
         {
           fprintf (stderr, "Cannot get font name %s size %d style 0x%X\n",
               FontName, FontSize, 0);
           return (1);
         }
       ID = PfFindFontCx (FontServer, Description, 0, FontSize);
       if (NULL == ID)
         {
           fprintf (stderr, "Cannot find font %s size %d style 0x%X\n",
               FontName, FontSize, 0);
           perror (strerror (errno));
           return (1);
         }
     }
#endif

The call to PfAttachCx() succeeds.  The call to PfGenerateFontNameCx() 
succeeds ... with the code shown, it provides a Description[] of 
"courier10bts10".  However, PfFindFontCx() fails with a return value of 
NULL.  errno is set to ESRCH, indicating no font found.  I've tried 
various other fonts as well, with no luck.

What am I missing here?

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
Re: What are the basics of font rendering? [bcc] [bcc][auto-ip]  
The 'Description' should be replaced with 'FontName' when calling the PfFindFont(). The PfFindFont() is similar to 
PfGenerateFontName(), it only returns FontID. I am not sure why you need it.
The 'Description' you got from the Generate function is good to be used with the subsequent PfRenderCx().
Re: What are the basics of font rendering? [bcc] [bcc][auto-ip]  
On 05/16/2011 01:17 PM, Misha Nefedov wrote:
> The 'Description' should be replaced with 'FontName' when calling the PfFindFont(). The PfFindFont() is similar to 
PfGenerateFontName(), it only returns FontID. I am not sure why you need it.
Well, I was simply following the sample code in the PfRenderCx() API 
doc, as you suggested.  The sample code calls PfFindFontCx().  
Personally, I'm willing to do without it, even though I don't see why it 
should be failing.
> The 'Description' you got from the Generate function is good to be used with the subsequent PfRenderCx().
Okay, I think you're suggesting something like this:

   FontName Description;
   char *FontName = "Courier10 BT";
   pf_point_t pp = { 50, 50 };
   int FontSize = 10;

   FontServer = PfAttachCx (NULL, 0);
   ... check for error ...
   if (NULL == PfGenerateFontNameCx (FontServer, FontName, 0, FontSize, 
Description))
     {
       ... error ...
     }
   i = PfRenderCx (FontServer, FontServer, Description, 0L, 0L, "Hello, 
world!", 0,
        0, &pp, NULL, Callback);
   ... check for error ...

This code fails when it reaches PfRenderCx().  The error message 
displayed by "perror(strerror(errno))" is "Invalid argument".

>
>
> _______________________________________________
>
> Advanced Graphics
> http://community.qnx.com/sf/go/post85727
Re: What are the basics of font rendering? [bcc] [bcc][auto-ip]  
Hard to tell. Can you please post the entire source file -- for me to try?
Re: What are the basics of font rendering? [bcc] [bcc][auto-ip]  
On 05/16/2011 02:55 PM, Misha Nefedov wrote:
> Hard to tell. Can you please post the entire source file -- for me to try?
Here's code that fails for me as described.  I compiled it with 
"ntox86-gcc -o FontTest FontTest.c -lph" and ran the font server with 
"phfont -d /usr/photon/font_repository -D /usr/photon/font_repository".

#include <stdio.h>
#include <errno.h>
#include <photon/Pf.h>

void
Callback (void *ctx, const pf_point_t *pos, const FontRender *fr)
{
   fprintf (stderr, "Callback: %d,%d\n", pos->x, pos->y);
   fprintf (stderr, "Callback: %d,%d %d,%d %d, %d, %d, %p\n",
       fr->size.x, fr->size.y, fr->offset.x, fr->offset.y,
       fr->width, fr->bpl, fr->bpp, fr->bmptr);
}

int
main (void)
{
   char *MyFontName = "Courier10 BT";
   int FontSize = 10;
   int i;
   struct _Pf_ctrl *FontServer = NULL;
   FontID *ID;
   FontName Description;
   pf_point_t pp = { 50, 50 };

   FontServer = PfAttachCx (NULL, 0);
   if (FontServer == NULL)
     {
       fprintf (stderr, "Cannot attach to font server.\n");
       return (1);
     }

   if (NULL == PfGenerateFontNameCx (FontServer, MyFontName, 0,
                                     FontSize, Description))
     {
       fprintf (stderr, "Cannot get font name %s size %d style 0x%X\n",
           MyFontName, FontSize, 0);
       return (1);
     }

   i = PfRenderCx (FontServer, FontServer, Description, 0L, 0L,
                   "Hello, world!", 0, 0, &pp, NULL, Callback);
   fprintf (stderr, "PfRenderCx() returned %d\n", i);
   if (i)
     fprintf (stderr, "%s\n", strerror (errno));

   return (0);
}


>
>
> _______________________________________________
>
> Advanced Graphics
> http://community.qnx.com/sf/go/post85742
Re: What are the basics of font rendering? [bcc] [bcc][auto-ip]  
Yes, I got this. The problem is that we asked to NO rendering buffer when doing th PfAttachCx(). Give it a number, for 
example:

PfAttachCx( NULL, 32*1024 );

The size of the buffer should depend on how large the strings and the font size are.


Re: What are the basics of font rendering? [bcc] [bcc][auto-ip]  
Thanks, Misha.  It does seem to do something now.

On 05/17/2011 09:19 AM, Misha Nefedov wrote:
> Yes, I got this. The problem is that we asked to NO rendering buffer when doing th PfAttachCx(). Give it a number, for
 example:
>
> PfAttachCx( NULL, 32*1024 );
>
> The size of the buffer should depend on how large the strings and the font size are.
>
>
>
>
>
>
> _______________________________________________
>
> Advanced Graphics
> http://community.qnx.com/sf/go/post85785