![]() |
![]() |
![]() |
![]() |
Generate an ID for a font
FontID * PfFindFont( char const * pkcDescription, uint32_t kulFlags, uint32_t kulSize );
ph
PfFindFont() generates a font ID with the supplied parameter attributes:
Returns NULL on failure, a FontID pointer on success. The FontID pointer is used to interface with the other calls in this API.
The errno global variable may also be set to one of the values generated by PfQueryFonts().
#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); 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 ); }
Photon
Safety: | |
---|---|
Interrupt handler | No |
Signal handler | No |
Thread | No |
PfConvertFontID(), PfDecomposeStemToID(), PfFontDescription(), PfFontFlags(), PfFontSize(), PfFreeFont(), PfGenerateFontName(),
Fonts chapter of the Photon Programmer's Guide
![]() |
![]() |
![]() |
![]() |