Render a string via a user callback function
#include <photon/Pf.h> int PfRender( void *ctx, const char *font, long adata, long bdata, const char *str, int len, int flags, PhPoint_t const *pos, PhRect_t const *clip, void (*func) ( void *, const PhPoint_t *pos, const FontRender *)); #include <font_api.h> int PfRenderCx( struct _Pf_ctrl *context, void *ctx, const char *font, long adata, long bdata, const char *str, int len, int flags, PhPoint_t const *pos, PhRect_t const *clip, void (*func) ( void *, const PhPoint_t *pos, const FontRender *));
You can set up to one of the following to indicate the format of the string:
Although this flag allows for 32-bit wide characters, the underlying font system currently supports only characters up to Unicode U+FFFE. |
If you don't set either of the above, the function assumes that the string is composed of UTF-8 multibyte characters.
You can OR in:
These functions render the given string via a user callback function. The difference between PfRender() and PfRenderCx() is that PfRenderCx() lets you specify the font context to use.
When a request to construct the bitmap is sent to the font server, the string bitmap is returned, for efficiency, in the shared-memory area created through the initial call to PfAttach(), PfAttachCx() or PfAttachDllCx().
Normally, only the graphics drivers use these functions, but they may be useful for application programs that have to obtain text bitmap data directly.
The generic design of these routines allows future expansion.
The FontRender metrics structure contains at least the following members:
PfRenderCx():
/* Render alignment example. Demonstrates how to achieve 8-bit, * 32-bit, and 64-bit aligned render maps if supported by the * particular font server. */ #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[]) { struct _Pf_ctrl * pf; fprintf(stderr, "POINT: PfRenderCx and bitmap alignment.\n"); if((pf = PfAttachCx(NULL, 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 and bitmap alignment.\n"); } else { fprintf(stderr, "NOTE: render 8-bit aligned image.\n"); PfDetachCx(pf); if((pf = PfAttachCx(NULL, -1)) != NULL) { if(PfRenderCx(pf, pf, PfConvertFontIDCx(pf, id, tag), 0L, 0L, "TEST.", 0, 0, &pos, NULL, func) == 0) { PfDetachCx(pf); if((pf = PfAttachCx("/dev/phfont32", -1)) != NULL) { 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 and bitmap alignment.\n"); } else { check_32 = 0; PfDetachCx(pf); if((pf = PfAttachCx("/dev/phfont64", -1)) != NULL) { 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 and bitmap alignment.\n"); } else fprintf(stderr, "PASS: PfRenderCx and bitmap alignment.\n"); } else { fprintf(stderr, "NOTE: PfRenderCx failed, errno %d.\n", errno); fprintf(stderr, "FAIL: PfRenderCx and bitmap alignment.\n"); } } else { fprintf(stderr, "UNRES: Unable to attach to fontserver, \ errno %d.\n", errno); fprintf(stderr, "FAIL: PfRenderCx and bitmap alignment.\n"); skip = 1; } } } else { fprintf(stderr, "NOTE: PfRenderCx failed, errno %d.\n", errno); fprintf(stderr, "FAIL: PfRenderCx and bitmap alignment.\n"); } } else { fprintf(stderr, "UNRES: Unable to attach to fontserver, errno %d.\n", errno); fprintf(stderr, "FAIL: PfRenderCx and bitmap alignment.\n"); skip = 1; } } else { fprintf(stderr, "NOTE: PfRenderCx failed, errno %d.\n", errno); fprintf(stderr, "FAIL: PfRenderCx and bitmap alignment.\n"); } } else { fprintf(stderr, "UNRES: PfAttachCx failed, errno %d.\n", errno); fprintf(stderr, "FAIL: PfRenderCx and bitmap alignment.\n"); } } } else { fprintf(stderr, "NOTE: PfRenderCx returned success with invalid render buffer.\n"); fprintf(stderr, "FAIL: PfRenderCx 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 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 and bitmap alignment.\n"); } return(0); }
Photon
Safety: | |
---|---|
Interrupt handler | No |
Signal handler | No |
Thread | No |
Safety: | |
---|---|
Interrupt handler | No |
Signal handler | No |
Thread | Yes |
PfAttach(), PfAttachCx(), PfDetach(), PfDetachCx(), PfGenerateFontName(), PfGenerateFontNameCx(), PhPoint_t, PhRect_t