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

PfGetGlyphIndexCx()

Get a glyph index

Synopsis:

#include <font_api.h>
int PfGetGlyphIndexCx( struct _Pf_ctrl * context,
                       wchar_tglyph,
                       FontID * font,
                       uint32_t * pIndex );

Arguments:

context
A pointer to the font context to use, returned by PfAttachCx() or PfAttachDllCx().
glyph
A Unicode glyph value.
font
A pointer to a font ID, as returned by PfFindFontCx().
pIndex
A pointer to a uint32_t where the function can store the glyph index.

Library:

font

Description:

This function retrieves the glyph index for the provided font and glyph combination.

Returns:

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

Errors:

ESRCH
Unable to locate device.
EBADF
Connection has gone stale, or device error occurred.
ENETUNREACH
Bad message buffer.
ELIBACC
Unable to locate render plugin for specified font.
EINVAL
Failure to load resources for specified font.
EFAULT
Unable to locate suitable base font.
ERANGE
Unable to locate suitable base font for provided code point.
EINVAL
Render plugin is unable to satisfy request.

Examples:

#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
#include <ctype.h>
#include <errno.h>
#include <malloc.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <dirent.h>

#include <photon/PhT.h>
#include <photon/PhProto.h>
#include <Pt.h>
#include <Ph.h>

#include <font_api.h>

FontName name;
uint16_t wc = 0x65;

int font_changed(PtWidget_t * widget, void * data, PtCallbackInfo_t * cbinfo)
{  snprintf(name, sizeof(name), "%s", cbinfo->cbdata);
   printf("%s\n", name);
   PtDamageWidget(data);
   return(Pt_CONTINUE);
}

void raw_draw(PtWidget_t *widget, PhTile_t *damage)
{  PhArea_t area;
   PhRect_t tsClip;
   PhPoint_t pos = { 10, 10 };
   FontQueryInfo info;
   wchar_t w;
   FontID * id;
   pf_metrics_t * metric;
   FontRender * render;

   PtSuperClassDraw( PtBasic, widget, damage );
   PtCalcCanvas(widget, &tsClip);
   PgDrawRect(&tsClip, Pg_DRAW_FILL);
   PtClipAdd(widget, &tsClip);
   tsClip.ul.x += 2;
   tsClip.ul.y += 10;

   PgSetTranslation (&tsClip.ul, Pg_RELATIVE);
   PgSetTextColor(Pg_BLACK);
   PgSetFont(name);

   if(PfQueryFontInfoCx(PfDefaultContext(), name, &info) == -1)
   {  fprintf(stderr, "NOTE : PfQueryFontInfoCx failed, errno %d.\n", errno);
      fprintf(stderr, "FAIL : Glyph capture.\n");
      exit(EXIT_FAILURE);
   }

   pos.y += -info.ascender;
   w = wc;

   if((id = PfDecomposeStemToIDCx(PfDefaultContext(), name)) != NULL)
   {  FontRender r;
      int size = 32000;
      char * bitmap = calloc(size, sizeof(char));

      if(PfGlyphCx(PfDefaultContext(), name, w, &r, bitmap, size, NULL) == -1)
      {  fprintf(stderr, "NOTE : PfGlyphCx failed, errno %d.\n", errno);
         fprintf(stderr, "FAIL : Glyph capture.\n");
         free(bitmap);
         exit(EXIT_FAILURE);
      }
      else
      {  pos.y -= r.offset.y;

         PgDrawText(&wc, sizeof(wc), &pos, Pg_TEXT_WIDECHAR);
      }

      free(bitmap);
      PfFreeFontCx(PfDefaultContext(), id);
   }
   else
   {  fprintf(stderr, "NOTE : PfDecomposeStemToIDCx failed, errno %d.\n", errno);
      fprintf(stderr, "FAIL : Glyph capture.\n");
      exit(EXIT_FAILURE);
   }

   tsClip.ul.x *= -1;
   tsClip.ul.y *= -1;
   PgSetTranslation (&tsClip.ul, Pg_RELATIVE);
   PtClipRemove();
}

int main(int argc, char *argv[])
{  PtArg_t tsArg[10];
   int i;
   PhDim_t dim = { 300, 300 };
   PtWidget_t * win, * raw, * fontsel;
   PhPoint_t pos = {0,0};
   PhRect_t canvas;
   int flags;
   uint32_t index;
   FontID * id;

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

   if(PtInit(NULL) == -1)
   {  fprintf(stderr, "NOTE : PtInit failed, no photon.\n");
      fprintf(stderr, "FAIL : Glyph Capture.\n");
      return(EXIT_FAILURE);
   }

   PgSetDrawBufferSize(0xFFFF);

   i = 0;
   PtSetArg(&tsArg[i++], Pt_ARG_DIM, &dim, 0L);
   PtSetArg(&tsArg[i++], Pt_ARG_WINDOW_TITLE, "Glyph Capture", 0L);
   PtSetArg(&tsArg[i++], Pt_ARG_FLAGS, Pt_GETS_FOCUS, Pt_GETS_FOCUS);

   if((win = PtCreateWidget(PtWindow, NULL, i, tsArg)) == NULL)
   {  fprintf(stderr, "NOTE : Unable to create window.\n");
      fprintf(stderr, "FAIL : Glyph Capture.\n");
      return(EXIT_FAILURE);
   }

   PtCalcCanvas(win, &canvas);

   i = 0;
   dim.w = canvas.lr.x - canvas.ul.x;
   dim.h = (canvas.lr.y / 2) - canvas.ul.y;
   PtSetArg(&tsArg[i++], Pt_ARG_DIM, &dim, 0L);
   PtSetArg(&tsArg[i++], Pt_ARG_RAW_DRAW_F, raw_draw, 0L);
   pos.x = 0;
   pos.y = dim.h;
   PtSetArg(&tsArg[i++], Pt_ARG_POS, &pos, 0L);
   PtSetArg(&tsArg[i++], Pt_ARG_FILL_COLOR, Pg_YELLOW, 0L);
   flags = Pt_RIGHT_ANCHORED_RIGHT | Pt_LEFT_ANCHORED_LEFT | Pt_TOP_ANCHORED_TOP
           | Pt_BOTTOM_ANCHORED_BOTTOM;
   PtSetArg(&tsArg[i++], Pt_ARG_ANCHOR_FLAGS, flags, flags);

   if((raw = PtCreateWidget(PtRaw, win, i, tsArg)) == NULL)
   {  fprintf(stderr, "NOTE : Unable to create raw canvas.\n");
      fprintf(stderr, "FAIL : Glyph Capture.\n");
      return(EXIT_FAILURE);
   }

   i = 0;
   dim.w = canvas.lr.x - canvas.ul.x;
   dim.h = (canvas.lr.y / 2) - canvas.ul.y;
   PtSetArg(&tsArg[i++], Pt_ARG_DIM, &dim, 0L);
   pos.x = 0;
   pos.y = 0;
   PtSetArg(&tsArg[i++], Pt_ARG_POS, &pos, 0L);
   flags = Pt_RIGHT_ANCHORED_RIGHT | Pt_LEFT_ANCHORED_LEFT | Pt_TOP_ANCHORED_TOP
           | Pt_BOTTOM_ANCHORED_BOTTOM;
   PtSetArg(&tsArg[i++], Pt_ARG_ANCHOR_FLAGS, flags, flags);
   PtSetArg(&tsArg[i++], Pt_ARG_FONT_FLAGS, 0L, Pt_FONTSEL_SAMPLE);

   if((fontsel = PtCreateWidget(PtFontSel, win, i, tsArg)) == NULL)
   {  fprintf(stderr, "NOTE : Unable to create fontsel.\n");
      fprintf(stderr, "FAIL : Glyph Capture.\n");
      return(EXIT_FAILURE);
   }

   PtAddCallback(fontsel, Pt_CB_FONT_MODIFY, font_changed, raw);

   id = PfFindFontCx(PfDefaultContext(), "TextFont", 0L, 9L);
   PfConvertFontIDCx(PfDefaultContext(), id, name);

   if(PfGetGlyphIndexCx(PfDefaultContext(), wc, id, &index) == -1)
   {  fprintf(stderr, "NOTE : Unable to fetch index, errno %d.\n", errno);
      fprintf(stderr, "FAIL : Glyph Capture.\n");
      return(EXIT_FAILURE);
   }
   else
     fprintf(stderr, "NOTE : index is %d\n", index);

   PtRealizeWidget(win);
   PtMainLoop();

   return(EXIT_SUCCESS);
}

Classification:

Photon

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

See also:

PfAttachCx(), PfAttachDllCx(), PfFindFontCx().

Fonts chapter of the Photon Programmer's Guide