Warning: main(/www/www/htdocs/style/globals.php) [function.main]: failed to open stream: No such file or directory in /www/www/docs/6.4.1/photon/lib_ref/pf/pffindfont.html on line 1

Warning: main() [function.include]: Failed opening '/www/www/htdocs/style/globals.php' for inclusion (include_path='.:/www/www/common:/www/www/php/lib/php') in /www/www/docs/6.4.1/photon/lib_ref/pf/pffindfont.html on line 1

Warning: main(/www/www/htdocs/style/header.php) [function.main]: failed to open stream: No such file or directory in /www/www/docs/6.4.1/photon/lib_ref/pf/pffindfont.html on line 8

Warning: main() [function.include]: Failed opening '/www/www/htdocs/style/header.php' for inclusion (include_path='.:/www/www/common:/www/www/php/lib/php') in /www/www/docs/6.4.1/photon/lib_ref/pf/pffindfont.html on line 8

PfFindFont(), PfFindFontCx()

Generate an ID for a font

Synopsis:

#include <photon/Pf.h>
FontID * PfFindFont( char const * pkcDescription,
                     uint32_t kulFlags,
                     uint32_t kulSize );

#include <font_api.h>
FontID* PfFindFontCx  (
                       struct _Pf_ctrl *    context,
                       char const *    pkcDescription,
                       uint32_t const    kulFlags,
                       uint32_t const    kulSize );

Arguments:

context
(PfFindFontCx() only) A pointer to the font context to use, returned by PfAttachCx() or PfAttachDllCx().
pkcDescription
The foundry name of the requested font, e.g. Helvetica.
kulFlags
Flags that identify the requested font type; any combination of:
kulSize
The point size requested, e.g. 12.

Library:

PfFindFont()
ph
PfFindFontCx()
font

Description:

Thess functions compose a FontID from the provided foundry descriptive name, flags, and point size.

Returns:

A pointer to a font ID that you can use with other font functions, or NULL if an error occurred.

Errors:

ESRCH
Unable to locate font.
ENOMEM
There wasn't enough memory to perform the desired request.

This function can also set errno to one of the values generated by PfQueryFonts().

Examples:

PfFindFontCx(): See the examples for PfConvertFontIDCx(), PfGetGlyphIndexCx(), and PfRenderCx().

PfFindFont():

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <Ap.h>
#include <Ph.h>
#include <Pt.h>
#include <errno.h>

PtWidget_t * pwndMain = NULL, * pbtn = NULL, * pobjRaw = NULL;
char pcText[100] = "AaBbCcXxYyZz";
char ** ppcData = NULL;

int fnDrawCanvas( PtWidget_t * ptsWidget,
                  PhTile_t * ptsDamage );

#define FALSE 0

static FontID * gs_ptsID = NULL;

int main(int argc, char *argv[])
{   PtArg_t args[4];
    PhPoint_t win_size, pntPOS, pntDIM;
    short nArgs = 0;

    PtInit (NULL);

    ppcData = argv;

    if(argc < 2)
    {  printf(
      "Usage: pf2id descriptive_name, e.g. pf2id Helvetica\n");
       exit(EXIT_FAILURE);
    }

    //  set base pwndMain parms
    win_size.x = 450;
    win_size.y = 450;

    // window title = name  of program
    PtSetArg(&args[0],Pt_ARG_DIM, &win_size, 0);
    PtSetArg(&args[1],Pt_ARG_WINDOW_TITLE, "Pf2", 0);

    pwndMain = PtCreateWidget (PtWindow, Pt_NO_PARENT, 2, args);

    if(argc > 2)
      strcpy (pcText, argv[2]);

    nArgs = 0;
    pntDIM.x = 80;
    pntDIM.y = 20;
    PtSetArg(&args[0], Pt_ARG_DIM, &pntDIM, 0);
    nArgs++;
    pntPOS.x = 100;
    pntPOS.y = 10;
    PtSetArg(&args[1], Pt_ARG_POS, &pntPOS, 0);
    nArgs++;
    PtSetArg(&args[2], Pt_ARG_TEXT_STRING, pcText, NULL);
    nArgs++;

    // Find the font we desire.
    gs_ptsID = PfFindFont(argv[1], 0, 12);

    PtSetArg(&args[3], Pt_ARG_TEXT_FONT,
             PfConvertFontID(gs_ptsID), NULL);
    nArgs++;
    pbtn = PtCreateWidget(PtButton, pwndMain, nArgs, args);
    PtRealizeWidget(pbtn);

    pntPOS.y = 100;
    pntPOS.x = 75;
    pntDIM.x = 300;
    pntDIM.y = 300;
    PtSetArg(&args[0], Pt_ARG_POS, &pntPOS, 0);
    PtSetArg(&args[1], Pt_ARG_DIM, &pntDIM, 0);
    PtSetArg(&args[2], Pt_ARG_RAW_DRAW_F, fnDrawCanvas, 0L);
    pobjRaw = PtCreateWidget(PtRaw, pwndMain, 3, args);

    (void) PtRealizeWidget(pwndMain);

    printf("Size:  %d\n", PfFontSize(gs_ptsID));
    printf("Descriptive Name:  %s\n",
           PfFontDescription(gs_ptsID));

    if(PfFontFlags(gs_ptsID) & PF_SCALABLE)
      printf("Scalable font.\n");
    else if(PfFontFlags(gs_ptsID) & PF_BITMAP)
           printf("Bitmap font.\n");

    PtMainLoop ();

    PfFreeFont(gs_ptsID);  // Free the FontID resources.
    return EXIT_SUCCESS;
}

int fnDrawCanvas( PtWidget_t * ptsWidget, PhTile_t * ptsDamage )
{
    PhRect_t rect;
    PhPoint_t pnt;
    PhRect_t tsExtent;
    PgColor_t old;
    PhPoint_t pnt2;
    PhPoint_t tsPos = {0, 0};

    // find our canvas
    PtCalcCanvas(pobjRaw, &rect);
    PtSuperClassDraw(PtBasic, ptsWidget, ptsDamage);

    old = PgSetStrokeColor(Pg_BLACK);

    PfExtentText(&tsExtent, &tsPos,
                 PfConvertFontID(gs_ptsID), pcText,
                 strlen(pcText));

    // draw text
    pnt.x = 10 + rect.ul.x;
    pnt.y = 100 + rect.ul.y;

    PgSetFont(PfConvertFontID(gs_ptsID));
    PgSetTextColor(Pg_BLACK);
    PgDrawText(pcText, strlen(pcText), &pnt, 0);

    pnt.x -= 10;
    pnt2.x = pnt.x + tsExtent.lr.x + 20;
    pnt2.y = pnt.y;

    PgSetStrokeColor(Pg_RED);

    PgDrawLine(&pnt, &pnt2);

    PgSetStrokeColor(old);

    return( Pt_CONTINUE );
}

Classification:

Photon

PfFindFont()

Safety:
Interrupt handler No
Signal handler No
Thread No

PfFindFontCx()

Safety:
Interrupt handler No
Signal handler No
Thread Yes

See also:

PfConvertFontID(), PfConvertFontIDCx(), PfDecomposeStemToID(), PfDecomposeStemToIDCx(), PfFontDescription(), PfFontDescriptionCx(), PfFontFlags(), PfFontFlagsCx(), PfFontSize(), PfFontSizeCx(), PfFreeFont(), PfFreeFontCx(), PfGenerateFontName(), PfGenerateFontNameCx(),

Fonts chapter of the Photon Programmer's Guide


Warning: main(/www/www/htdocs/style/footer.php) [function.main]: failed to open stream: No such file or directory in /www/www/docs/6.4.1/photon/lib_ref/pf/pffindfont.html on line 337

Warning: main() [function.include]: Failed opening '/www/www/htdocs/style/footer.php' for inclusion (include_path='.:/www/www/common:/www/www/php/lib/php') in /www/www/docs/6.4.1/photon/lib_ref/pf/pffindfont.html on line 337