![]()  | 
![]()  | 
![]()  | 
![]()  | 
![]()  | 
This version of this document is no longer maintained. For the latest documentation, see http://www.qnx.com/developers/docs. | 
Allocate, or reallocate, a render buffer
#include <font_api.h>
int PfAllocRenderCx( struct _Pf_ctrl * context,
                     long size );
font
This function allocates a render buffer for the provided font context, of the requested size. If the context already has an allocated render buffer, this function releases it before it allocates a new one. You must link the font context to a fontdll_t context using PfAssignDllCx(). Otherwise, an error is returned.
#include <font_api.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
static int check_32 = 0;
static int bad_32 = 0;
static int check_64 = 0;
static int bad_64 = 0;
static void func(void * ctx, const pf_point_t * pos, const FontRender * render)
{
   printf("NOTE : render callback.\n");
   if(check_32)
   {  int times = render->bpl / 4;
      int total = times * 4;
      if(total != render->bpl)
        bad_32 = 1;
   }
   if(check_64)
   {  int times = render->bpl / 8;
      int total = times * 8;
      if(total != render->bpl)
        bad_64 = 1;
   }
}
int main(int argc, char const * argv[])
{  fontdll_t dll;
   fprintf(stderr, "POINT : PfRenderCx(dll) and bitmap alignment.\n");
   if((dll = PfAttachLocalDll(NULL, NULL)) != NULL)
   {  struct _Pf_ctrl * pf;
      if((pf = PfAttachDllCx(dll, 0)) != NULL)
      {   FontID * id;
          int skip = 0;
          if((id = PfFindFontCx(pf, "TextFont", 0L, 9)) != NULL)
          {  FontName tag;
             pf_point_t pos = { 0 , 0 };
             if((PfRenderCx(pf, pf, PfConvertFontIDCx(pf, id, tag), 0L, 0L, "TEST.",
             0, 0, &pos, NULL, func) == -1) && (errno == EINVAL))
             {  if(setenv("PHFONTMEM", "32000", 1) == -1)
                {  fprintf(stderr, "NOTE : setenv failed to write to PHFONTMEM.\n");
                   fprintf(stderr, "FAIL : PfRenderCx(dll) and bitmap alignment.\n");
                }
                else
                {  fprintf(stderr, "NOTE : render 8-bit aligned image.\n");
                   if(PfAllocRenderCx(pf, -1) == 0)
                   {  if(PfRenderCx(pf, pf, PfConvertFontIDCx(pf, id, tag), 0L, 0L,
                   "TEST.", 0, 0, &pos, NULL, func) == 0)
                      {
                         if(PfSetOptionsDll(dll, "-Z=32", NULL) == 0)
                         {  fprintf(stderr, "NOTE : render 32-bit aligned image.\n");
                            check_32 = 1;
                            if(PfRenderCx(pf, pf, PfConvertFontIDCx(pf, id, tag), 0L,
                            0L, "TEST.", 0, 0, &pos, NULL, func) == 0)
                            {  if(bad_32)
                               {  fprintf(stderr, "NOTE : PfRenderCx did not render \
                               a 32-bit aligned image.\n");
                                  fprintf(stderr, "FAIL : PfRenderCx(dll) and \
                                  bitmap alignment.\n");
                               }
                               else
                               {  check_32 = 0;
                                  if(PfSetOptionsDll(dll, "-Z=64", NULL) == 0)
                                  {  fprintf(stderr, "NOTE : render 64-bit aligned \
                                  image.\n");
                                     check_64 = 1;
                                     if(PfRenderCx(pf, pf, PfConvertFontIDCx(pf, id,
                                     tag), 0L, 0L, "TEST.", 0, 0, &pos, NULL, func)
                                     == 0)
                                     {  if(bad_64)
                                        {  fprintf(stderr, "NOTE : PfRenderCx did \
                                        not render a 64-bit aligned image.\n");
                                           fprintf(stderr, "FAIL : PfRenderCx(dll) \
                                           and bitmap alignment.\n");
                                        }
                                        else
                                          fprintf(stderr, "PASS : PfRenderCx(dll) \
                                          and bitmap alignment.\n");
                                     }
                                     else
                                     {  fprintf(stderr, "NOTE : PfRenderCx failed, \
                                     errno %d.\n", errno);
                                        fprintf(stderr, "FAIL : PfRenderCx(dll) and \
                                        bitmap alignment.\n");
                                     }
                                  }
                                  else
                                  {  fprintf(stderr, "UNRES : PfSetOptionsDll \
                                  failed, errno %d.\n", errno);
                                     fprintf(stderr, "FAIL : PfRenderCx(dll) and \
                                     bitmap alignment.\n");
                                     skip = 1;
                                  }
                               }
                            }
                            else
                            {  fprintf(stderr, "NOTE : PfRenderCx failed, errno
                            %d.\n", errno);
                               fprintf(stderr, "FAIL : PfRenderCx(dll) and bitmap \
                               alignment.\n");
                            }
                         }
                         else
                         {  fprintf(stderr, "UNRES : PfSetOptionsDll failed, errno \
                         %d.\n", errno);
                            fprintf(stderr, "FAIL : PfRenderCx(dll) and bitmap \
                            alignment.\n");
                            skip = 1;
                         }
                      }
                      else
                      {  fprintf(stderr, "NOTE : PfRenderCx failed, errno %d.\n",
                      errno);
                         fprintf(stderr, "FAIL : PfRenderCx(dll) and bitmap \
                         alignment.\n");
                      }
                   }
                   else
                   {  fprintf(stderr, "UNRES : PfAllocRenderCx failed, errno %d.\n",
                   errno);
                      fprintf(stderr, "FAIL : PfRenderCx(dll) and bitmap \
                      alignment.\n");
                   }
                }
             }
             else
             {  fprintf(stderr, "NOTE : PfRenderCx returned success with invalid \
             render buffer.\n");
                fprintf(stderr, "FAIL : PfRenderCx(dll) and bitmap alignment.\n");
             }
             if(PfFreeFontCx(pf, id) == -1L)
             {  fprintf(stderr, "NOTE : PfFreeFontCx failed, errno %d.\n", errno);
             }
          }
          else
          {  fprintf(stderr, "NOTE : PfFindFontCx failed to create font id, errno \
          %d.\n", errno);
             fprintf(stderr, "FAIL : PfRenderCx(dll) and bitmap alignment.\n");
          }
          if(!skip)
            PfDetachCx(pf);
      }
      else
      {  fprintf(stderr, "UNRES : Unable to attach to fontserver, errno %d.\n",
      errno);
         fprintf(stderr, "FAIL : PfRenderCx(dll) and bitmap alignment.\n");
      }
      if(PfDetachLocalDll(dll) == -1)
        fprintf(stderr, "NOTE : PfDetachLocalDll failed, errno %d.\n", errno);
   }
   else
   {  fprintf(stderr, "UNRES : Unable to load local dll, errno %d.\n", errno);
      fprintf(stderr, "FAIL : PfRenderCx(dll) and bitmap alignment.\n");
   }
   return(0);
}
Photon
| Safety: | |
|---|---|
| Cancellation point | No | 
| Interrupt handler | No | 
| Signal handler | No | 
| Thread | Yes | 
PfAttachCx(), PfAttachDllCx(), PfAssignDllCx()
Fonts chapter of the Photon Programmer's Guide
![]()  | 
![]()  | 
![]()  | 
![]()  |