PfRenderText() - HELP!

I can not make PfRenderText function working. It always exists with error :
Invalid argument.

Does anybody can post a working example.

Thanks,
Janusz.

Janusz Ruszel <janusz_ruszel@baxter.com> wrote:

I can not make PfRenderText function working. It always exists with error :
Invalid argument.

Does anybody can post a working example.

Thanks,
Janusz.

Yes, that is correct.
What version of the OS are you using, 6.1, or 6.2?
When you let me know the version, I can provide you
with sample code.

Regards.

I am using version 6.2.

Janusz.
“Derek Leach” <dleach@qnx.com> wrote in message
news:attbuf$8j5$1@inn.qnx.com

Janusz Ruszel <> janusz_ruszel@baxter.com> > wrote:
I can not make PfRenderText function working. It always exists with
error :
Invalid argument.

Does anybody can post a working example.

Thanks,
Janusz.

Yes, that is correct.
What version of the OS are you using, 6.1, or 6.2?
When you let me know the version, I can provide you
with sample code.

Regards.

Janusz Ruszel <janusz_ruszel@baxter.com> wrote:

I am using version 6.2.

Janusz.
“Derek Leach” <> dleach@qnx.com> > wrote in message
news:attbuf$8j5$> 1@inn.qnx.com> …
Janusz Ruszel <> janusz_ruszel@baxter.com> > wrote:
I can not make PfRenderText function working. It always exists with
error :
Invalid argument.

Does anybody can post a working example.

Thanks,
Janusz.

Yes, that is correct.
What version of the OS are you using, 6.1, or 6.2?
When you let me know the version, I can provide you
with sample code.

Regards.

OK, so you can use the attached example.
The second parameter the PfRenderCx is a context pointer, since the
draw function does not use a context, I just passed any non-void value.

Regards.




/* PfRenderCx example */

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

#define PX_IMAGE_MODULES // define the modules we want
#define PX_BMP_SUPPORT

#include <photon/PxImage.h>


#define ASCENDER tsExtent.ul.y
#define DESCENDER tsExtent.lr.y

PtWidget_t * pwndMain = NULL, * pbtn = NULL;
char * pcText = “Hello”;

int fnDrawCanvas( PtWidget_t * ptsWidget, void * data, PtCallbackInfo_t * cbinfo );

#define FALSE 0

char szBuff[MAX_FONT_TAG];

struct _Pf_ctrl * pf_context;

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

PtInit (NULL);

if((pf_context = PfAttach(NULL, 320000)) == NULL)
return(EXIT_FAILURE);

if(PfGenerateFontName(“Swis721 BT”, 0L, 14L, szBuff) == NULL)
return(EXIT_FAILURE);

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

nArgs = 0;
PtSetArg(&args[nArgs],Pt_ARG_DIM, &win_size, 0L);
nArgs++;
PtSetArg(&args[nArgs],Pt_ARG_WINDOW_TITLE, “Display”, 0L); // window title = name of program
nArgs++;

if((pwndMain = PtCreateWidget (PtWindow, NULL, nArgs, args)) == NULL)
return(EXIT_FAILURE);

if(argc > 2)
{ pcText = argv[2];
}

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

if((pbtn = PtCreateWidget(PtButton, pwndMain, nArgs, args)) == NULL)
return(EXIT_FAILURE);

PtAddCallback(pbtn, Pt_CB_ACTIVATE, fnDrawCanvas, NULL);

PtRealizeWidget(pwndMain);

PtMainLoop ();

PfDetach(pf_context);

return(0);
}

static void show_drawmap(FontRender const * pktsRender) // 8 bpp
{
int ii, jj, val;
unsigned char * rr = NULL;

rr = (unsigned char *)pktsRender->bmptr;

printf("\n");

for (ii=0; ii < pktsRender->size.y; ii++)
{

for (jj=0; jj < pktsRender->bpl; jj++, rr++)
{
val = (*rr);

if(val == 0)
printf(".");
else if(val >= 1 && val <= 0x99)
printf("+");
else if(val >= 0xA0 && val <= 0xD0)
printf("*");
else
printf("#");
}

printf("\n");
}

rr = (unsigned char *)pktsRender->bmptr;

printf(“Hex Values:\n”);

for(ii=0; ii < pktsRender->size.y; ii++)
{

for(jj=0; jj < pktsRender->bpl; jj++, rr++)
{ val = (*rr);

printf(val < 10 ? "0x0%x " : "0x%2x ", val);
}

printf("\n");
}
}

static void PrintChar(FontRender const * pktsRender) // 1 bpp
{ int w, h, k, y, x;
printf("\n");

w = pktsRender->width;

if( w > pktsRender->bpl * 8 )
return;

h = pktsRender->size.y;

k = 0;

for ( y = 0; y < h; y++ )
{ for ( x = 0; x < w; x++ )
{ char c = (char)((pktsRender->bmptr[ k + (x>>3) ] & (0x80 >> (x&7)) ) ? ‘@’ : ‘.’);
printf("%c", c );
}

printf("\n");
k += pktsRender->bpl;
}
}

void show_nybblemap(FontRender const * pktsRender) // 4 bpp
{
int ii, jj, kk, val;
unsigned char * rr;

rr = (unsigned char *)pktsRender->bmptr;

printf("\n");

for (ii=0; ii <= pktsRender->size.y; ii++)
{

for (jj=0; jj <= (pktsRender->size.x>>1); jj++, rr++)
{
for (kk=0; kk<2; kk++)
{
if (kk & 1)
val = (*rr) & 0x0f;
else
val = ((*rr) & 0xf0) >> 4;
if (val == 0)
printf(".");
else if (val >= 1 && val <= 9)
printf("%c", val + ‘0’);
else if (val >= 10 && val <= 15)
printf("%c", val - 10 + ‘A’);
else
printf("#");
}
}

printf("\n");
}

rr = (unsigned char *)pktsRender->bmptr;

printf(“Hex Values:\n”);

for(ii = 0; ii <= pktsRender->bpl; ii++)
{ for(jj = 0; jj <= (pktsRender->size.x >> 1); jj++, rr++)
{ for(kk = 0; kk < 2; kk++)
{ if(kk & 1)
val = (*rr) & 0x0f;
else
val = ((*rr) & 0xf0) >> 4;

printf("0x0%x ", val);
}
}

printf("\n");
}
}

PhRect_t tsExtent;
short nY = 70;
short g_OffsetY = 0;

void fnDrawText(void * ctx, const PhPoint_t * pktsPnt, const FontRender * pktsRender)
{ PhImage_t tsImage;
PhPoint_t tsPos = { pktsPnt->x, nY };
PgColor_t palette[2] = { Pg_WHITE, Pg_BLACK };

memset(&tsImage, 0x00, sizeof(PhImage_t));
tsImage.size.w = pktsRender->size.x;
tsImage.size.h = pktsRender->size.y;
tsImage.bpl = pktsRender->bpl;
tsImage.image = pktsRender->bmptr;
tsImage.palette = palette;
tsImage.colors = 2;

if(pktsRender->bpp == 1)
{ tsImage.palette = NULL;
tsImage.type = Pg_BITMAP_BACKFILL;
}
else if(pktsRender->bpp == 4)
{ palette[0] = Pg_WHITE;
palette[1] = Pg_BLACK;
tsImage.type = Pg_IMAGE_GRADIENT_NIBBLE;
}
else if(pktsRender->bpp == :sunglasses:
{ palette[0] = Pg_WHITE;
palette[1] = Pg_BLACK;
tsImage.type = Pg_IMAGE_GRADIENT_BYTE;
}

if(PgDrawPhImagemx(&tsPos, &tsImage, 0x00) == -1)
{ printf(“Ouch!!\n”);
}

PgFFlush(1);

if(PxWriteImage(“pict.bmp”, &tsImage, NULL, PX_IMAGE_BMP, 0) == -1)
printf(“Could not write BMP\n”);

if(pktsRender->bpp == 1)
{ PrintChar(pktsRender);
}
else if(pktsRender->bpp == :sunglasses:
{ show_drawmap(pktsRender);
}
else if(pktsRender->bpp == 4)
{ show_nybblemap(pktsRender);
}

printf(“BPL: %d, sizex: %d, width: %d, height: %d\n”, pktsRender->bpl, pktsRender->size.x, pktsRender->width, pktsRender->size.y);

g_OffsetY = pktsRender->offset.y;

return;
}

int fnDrawCanvas( PtWidget_t * ptsWidget, void * data, PtCallbackInfo_t * cbinfo )
{ PhPoint_t ts = { 10, nY - g_OffsetY };
PhPoint_t tsPos = {10, 0};
PgColor_t old;

if(PfExtentCx(pf_context, &tsExtent, &tsPos, szBuff, 0L, 0L, pcText, strlen(pcText), 0L, NULL) == -1)
printf(“extent failed\n”);

// draw text
PgSetFont(szBuff);

PgSetTextColor(Pg_BLACK);
PgSetFillColor(Pg_WHITE);

if(PfRenderCx(pf_context, 1, szBuff, 0L, 0L, pcText, strlen(pcText), 0L, &tsPos, NULL, fnDrawText) == -1)
{ perror("");
printf(“errno == %d\n”, errno);
}

ts.y = nY - g_OffsetY;

old = PgSetStrokeColor(Pg_RED);

PgDrawIRect(tsExtent.ul.x, tsExtent.ul.y + ts.y, (tsExtent.lr.x - min(tsExtent.ul.x, 0) + 1), tsExtent.lr.y + ts.y, Pg_DRAW_STROKE);

PgSetStrokeColor(old);

return( Pt_CONTINUE );
}

You need to use -lph and -lphexlib for this example.

Derek,
Thank you very much. It works. I hope that somebody who is taking
care for QNX documentation can find it useful too.

Janusz Ruszel.

“Derek Leach” <dleach@qnx.com> wrote in message
news:aupnco$827$1@inn.qnx.com

You need to use -lph and -lphexlib for this example.

Is there a option to force font server to generate 8bpp bitmap?
Janusz.

“Derek Leach” <dleach@qnx.com> wrote in message
news:aupnco$827$1@inn.qnx.com

You need to use -lph and -lphexlib for this example.

Janusz Ruszel <janusz_ruszel@baxter.com> wrote:

Is there a option to force font server to generate 8bpp bitmap?
Janusz.

“Derek Leach” <> dleach@qnx.com> > wrote in message
news:aupnco$827$> 1@inn.qnx.com> …
You need to use -lph and -lphexlib for this example.

No, only 8bpp pixmap, via anti-aliased text.
When using PfGenerateFontName, pass the PF_STYLE_ANTIALIAS
flag. Not all fonts support this mode.

Regards.