Title |
Rotating Text in Photon |
Ref. No. |
QNX.000009570 |
Category(ies) |
Development |
Issue |
Is there a way to draw text under Photon in some rotated form?
|
Solution |
Here is some sample code which will allow you to rotate the text either 90 or 270, you will have to modify the code if you would like to rotate it at non-vertical angles.
The code uses the PfRenderText() call to get a bitmap representation of the font. This is what you manipulate(rotate). The rotate_font_func() function will be called when making the PfRenderText() call.
// call this function to render the test into a bitmap // you will want a label to put it in, mine is called ABW_label
PfRenderText (font, text, strlen(text), &pos, NULL, rotate_font_func);
// function that PfRenderText() calls and rotates the text void rotate_font_func(PhPoint_t *pos, FontRender *metrics) { PhImage_t *image = (void *) calloc (sizeof(PhImage_t), 1); PtArg_t args[2]; PhArea_t *area; PhPoint_t pos2; int bit = 0, row = 0; char test = 1; int old_byte_pos = 0; int new_bit_pos = 0, new_byte_pos = 0; int new_byte_row;
// setup some defaults for the image struct image->type = Pg_BITMAP_TRANSPARENT; image->colors = 2; image->palette = calloc (sizeof(PgColor_t), 2); // my text_palette has the foreground and background colors for my text memcpy(image->palette, text_palette, sizeof(PgColor_t) * 2);
// if we are drawing horizontal then just set the regular text bitmap if (MY_rotation == NO_ROTATION) { image->size.w = metrics->size.x; image->size.h = metrics->size.y; image->bpl = metrics->bpl;
image->image = (void *) calloc (metrics->bpl * metrics->size.y, 1); memcpy(image->image, metrics->bmptr, (metrics->bpl * metrics->size.y));
// set the image PtSetArg(&args[0], Pt_ARG_LABEL_DATA, image, sizeof(PhImage_t)); PtSetResources(ABW_label, 1, args);
return; } // drawing horizontal then change the bitmap image->size.w = metrics->size.y; image->size.h = metrics->size.x; image->bpl = (metrics->size.y + 7) / 8; image->image = (void *) calloc (image->bpl * image->size.h, 1);
// the below if statement should create a bitmap vertically from the first char // downward or from the first char upward if (MY_rotation == TOP_DOWN_ROTATION) { for (bit = 0; bit < metrics->size.x; bit++) //each bit positon horizontally { for (row = (metrics->size.y - 1); row >= 0; row--) { // we now have a bit and a row old_byte_pos = (bit / 8) + (row * metrics->bpl);
if (((new_bit_pos % 8) == 0) && new_bit_pos) { new_bit_pos = 0; new_byte_pos++; }
test = 1 << (7 - (bit%8));
if (metrics->bmptr[old_byte_pos] & test) image->image[new_byte_pos] |= 1 << (7 - new_bit_pos);
new_bit_pos++; }
if (new_bit_pos != 0) { new_bit_pos = 0; new_byte_pos++; } } } else { new_byte_row = image->size.h - 1; new_byte_pos = 0; for (bit = 0; bit <metrics->size.x; bit++) //each bit positon horizontally { // for (row = (metrics->size.y - 1); row >= 0; row--) for (row = 0; (row <= (metrics->size.y - 1)); row++) { // we now have a bit and a row old_byte_pos = (bit / 8) + (row * metrics->bpl);
if (((new_bit_pos%8) == 0) && new_bit_pos) { new_bit_pos = 0; new_byte_pos++; }
test = 1 << (7 - (bit%8));
if (metrics->bmptr[old_byte_pos] & test) image->image[(new_byte_row * image->bpl) + new_byte_pos] |= 1 << (7 - new_bit_pos);
new_bit_pos++; }
if (new_bit_pos != 0) { new_bit_pos = 0; new_byte_pos++; } new_byte_pos = 0; new_byte_row--; } }
PtSetArg(&args[0], Pt_ARG_LABEL_DATA, image, sizeof(PhImage_t)); PtSetResources(ABW_label, 1, args); }
|
|