PfSetRenderingDPICx()

Set rendering DPI

Synopsis:

int PfSetRenderingDPICx( struct _Pf_ctrl * context,
                         uint32_t res_x,
                         uint32_t res_y );

Arguments:

context
A pointer to the font context to use, returned by PfAttachCx() or PfAttachDllCx().
res_x
The horizontal DPI value you want to set the context rendering to.
res_y
The vertical DPI value you want to set the context rendering to.

Library:

font

Description:

This function requests that the font server set the rendering and extenting DPI for the provided context. The font server may ignore the request completely, or a particular font technology may not be able to accomodate the request.

Returns:

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

Errors:

EFAULT
Font context is NULL.

Examples:

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <font_api.h>

static int compare_extent_is_same(pf_rect_t const * e, pf_rect_t const * e2)
{  if(e->ul.x != e2->ul.x)
     return(0);

   if(e->ul.y != e2->ul.y)
     return(0);

   if(e->lr.x != e2->lr.x)
     return(0);

   if(e->lr.y != e2->lr.y)
     return(0);

   return(1);
}

static int compare_render_is_same(FontRender const * r, FontRender const * r2)
{  if(r->size.x != r2->size.x)
     return(0);

   if(r->size.y != r2->size.y)
     return(0);

   if(r->offset.x != r2->offset.x)
     return(0);

   if(r->offset.y != r2->offset.y)
     return(0);

   if(r->width != r2->width)
     return(0);

   if(r->bpl != r2->bpl)
     return(0);

   if(r->bpp != r2->bpp)
     return(0);

   if(r->flags != r2->flags)
     return(0);

   return(1);
}

static void func(void * ctx, const pf_point_t * pos, const FontRender * render)
{  FontRender * r = (FontRender *)ctx;

   (*r) = *render;
}

int main (int argc, char *argv[])
{   struct _Pf_ctrl * pf;

    fprintf(stderr, "POINT: DPI.\n");

    if((pf = PfAttachCx(NULL, 32000)) == NULL)
    {  fprintf(stderr, "NOTE: PfAttachCx failed, errno %d.\n", errno);
       fprintf(stderr, "FAIL: DPI.\n");
       exit(EXIT_FAILURE);
    }
    else
    {  FontName tag;

       if(PfGenerateFontNameCx(pf, "PrimaSans BT", 0L, 12L, tag) != NULL)
       {  char const * text = "Hello Bobby!!";
          pf_rect_t extent;

          if(PfExtentCx(pf, &extent, NULL, tag, 0L, 0L, text, 0, 0, NULL) == 0)
          {  if(PfSetRenderingDPICx(pf, 72, 72) == 0)
             {  pf_rect_t extent2;

                if(PfExtentCx(pf, &extent2, NULL, tag, 0L, 0L, text, 0, 0,
                              NULL) == 0)
                {  if(!compare_extent_is_same(&extent, &extent2))
                   {  pf_point_t pos = { 0, 0 };
                      fprintf(stderr,
                         "NOTE: extent ulx %hd, uly %hd, lrx %hd, lry %hd\n",
                         extent.ul.x, extent.ul.y, extent.lr.x, extent.lr.y);
                      fprintf(stderr,
                         "NOTE: extent2 ulx %hd, uly %hd, lrx %hd, lry %hd\n",
                         extent2.ul.x, extent2.ul.y, extent2.lr.x, extent2.lr.y);

                      if(PfSetRenderingDPICx(pf, 0, 0) == 0)
                      {  FontRender render;

                         if(PfRenderCx(pf, &render, tag, 0L, 0L, text, 0, 0,
                                       &pos, NULL, func) == 0)
                         {  if(PfSetRenderingDPICx(pf, 72, 72) == 0)
                            {  FontRender render2;

                               if(PfRenderCx(pf, &render2, tag, 0L, 0L, text,
                                             0, 0, &pos, NULL, func) == 0)
                               {  if(!compare_render_is_same(&render, &render2))
                                  {  fprintf(stderr,
                                        "NOTE: render sizex %hd, sizey %hd\n",
                                        render.size.x, render.size.y);
                                     fprintf(stderr,
                                        "NOTE: render2 sizex %hd, sizey %hd\n",
                                        render2.size.x, render2.size.y);
                                  }
                                  else
                                  {  fprintf(stderr,
                                        "NOTE: Invalid test, dpi values did not \
affect processing.\n");
                                     fprintf(stderr, "FAIL: DPI.\n");
                                     exit(EXIT_FAILURE);
                                  }
                               }
                               else
                               {  fprintf(stderr,
                                    "NOTE: PfRenderCx failed, errno %d.\n",
                                    errno);
                                  fprintf(stderr, "FAIL: DPI.\n");
                                  exit(EXIT_FAILURE);
                               }
                            }
                            else
                            {  fprintf(stderr,
                                  "NOTE: PfSetRenderingDPICx failed, errno %d.\n",
                                  errno);
                               fprintf(stderr, "FAIL: DPI.\n");
                               exit(EXIT_FAILURE);
                            }
                         }
                         else
                         {  fprintf(stderr, "NOTE: PfRenderCx failed, errno %d.\n",
                                    errno);
                            fprintf(stderr, "FAIL: DPI.\n");
                            exit(EXIT_FAILURE);
                         }
                      }
                      else
                      {  fprintf(stderr,
                            "NOTE: PfSetRenderingDPICx failed, errno %d.\n",
                            errno);
                         fprintf(stderr, "FAIL: DPI.\n");
                         exit(EXIT_FAILURE);
                      }
                   }
                   else
                   {  fprintf(stderr,
                        "NOTE: Invalid test, dpi values did not affect processing.\n");
                      fprintf(stderr, "FAIL: DPI.\n");
                      exit(EXIT_FAILURE);
                   }
                }
                else
                {  fprintf(stderr, "NOTE: PfExtentCx failed, errno %d.\n", errno);
                   fprintf(stderr, "FAIL: DPI.\n");
                   exit(EXIT_FAILURE);
                }
             }
             else
             {  fprintf(stderr, "NOTE: PfSetRenderingDPICx failed, errno %d.\n",
                        errno);
                fprintf(stderr, "FAIL: DPI.\n");
                exit(EXIT_FAILURE);
             }
          }
          else
          {  fprintf(stderr, "NOTE: PfExtentCx failed, errno %d.\n", errno);
             fprintf(stderr, "FAIL: DPI.\n");
             exit(EXIT_FAILURE);
          }
       }
       else
       {  fprintf(stderr, "NOTE: PfGenerateFontNameCx failed, errno %d.\n",
                  errno);
          fprintf(stderr, "FAIL: DPI.\n");
          exit(EXIT_FAILURE);
       }

       PfDetachCx(pf);
       fprintf(stderr, "PASS: DPI.\n");
    }

    return(0);
}

Classification:

Photon

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

See also:

PfAttachCx(), PfAttachDllCx().

Fonts chapter of the Photon Programmer's Guide