Caution: This version of this document is no longer maintained. For the latest documentation, see http://www.qnx.com/developers/docs.

PfAllocRenderCx()

Allocate, or reallocate, a render buffer

Synopsis:

#include <font_api.h>

int PfAllocRenderCx( struct _Pf_ctrl * context,
                     long size );

Arguments:

context
A pointer to the font context to use, returned by PfAttachCx() or PfAttachDllCx().
size
The size, in bytes, of the render buffer you want to allocate. A value greater than 0 allocates a shared memory buffer; less than 0 allocates a heap buffer; -1 allocates a heap buffer using the value from the PHFONTMEM environment variable.

Library:

font

Description:

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.

Returns:

0
Success
-1
An error occurred (errno is set).

Errors:

ENOMEM
Insufficient resources
EACCES
shm_open() error.
EEXIST
shm_open() error.
EINTR
shm_open() error.
ELOOP
shm_open() error.
EMFILE
shm_open() error.
ENAMETOOLONG
shm_open() error.
ENFILE
shm_open() error.
ENOENT
shm_open() error.
ENOSPC
shm_open() error.
ENOSYS
shm_open() error.
EBADF
ftruncate() error.
EFBIG
ftruncate() error.
EINTR
ftruncate() error.
EINVAL
ftruncate() error.
EIO
ftruncate() error.
ENOSYS
ftruncate() error.
ENOTSUP
ftruncate() error.
EROFS
ftruncate() error.
EACCES
mmap() error.
EBADF
mmap() error.
EINVAL
mmap() error.
ENODEV
mmap() error.
ENOMEM
mmap() error.
ENXIO
mmap() error.
ENOTSUP
Platform does not support this operation.
EFAULT
Font context is not associated with a fontdll_t context.

Examples:

#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);
}

Classification:

Photon

Safety:
Cancellation point No
Interrupt handler No
Signal handler No
Thread Yes

See also:

PfAttachCx(), PfAttachDllCx(), PfAssignDllCx()

Fonts chapter of the Photon Programmer's Guide