/** * Paint a string. * * \param fstyle plot style for this text * \param string UTF-8 string to measure * \param length length of string * \param x x coordinate * \param y y coordinate * \return true on success, false on error and error reported */ bool nsfont_paint(const plot_font_style_t *fstyle, const char *string, size_t length, int x, int y) { const char *font_family; unsigned int font_size; unsigned int flags = rufl_BLEND_FONT; rufl_style font_style; rufl_code code; nsfont_read_style(fstyle, &font_family, &font_size, &font_style); if (font_size == 0) return true; if (no_font_blending || print_active) flags = 0; code = rufl_paint(font_family, font_style, font_size, string, length, x, y, flags); if (code != rufl_OK) { if (code == rufl_FONT_MANAGER_ERROR) { LOG("rufl_paint: rufl_FONT_MANAGER_ERROR: 0x%x: %s", rufl_fm_error->errnum, rufl_fm_error->errmess); } else { LOG("rufl_paint: 0x%x", code); } } return true; }
static PyObject * pyrufl_paint(PyObject *self /* Not used */, PyObject *args) { const char *font_family; rufl_style font_style; unsigned int font_size; const char *string; int length; int x; int y; unsigned int flags; if (!PyArg_ParseTuple(args, "siIs#iiI", &font_family, &font_style, &font_size, &string, &length, &x, &y, &flags)) return NULL; rufl_paint(font_family, font_style, font_size, string, length, x, y, flags); Py_INCREF(Py_None); return Py_None; }
int main(void) { char utf8_test[] = "Hello, world! ὕαλον " "Uherské Hradiště. 𐀀"; int width; size_t char_offset; int x; int actual_x; struct rufl_decomp_funcs funcs = { move_to, line_to, cubic_to }; int bbox[4]; try(rufl_init(), "rufl_init"); rufl_dump_state(); try(rufl_paint("NewHall", rufl_WEIGHT_400, 240, utf8_test, sizeof utf8_test - 1, 1200, 1000, 0), "rufl_paint"); try(rufl_width("NewHall", rufl_WEIGHT_400, 240, utf8_test, sizeof utf8_test - 1, &width), "rufl_width"); printf("width: %i\n", width); for (x = 0; x < width + 100; x += 100) { try(rufl_x_to_offset("NewHall", rufl_WEIGHT_400, 240, utf8_test, sizeof utf8_test - 1, x, &char_offset, &actual_x), "rufl_x_to_offset"); printf("x to offset: %i -> %i %zi \"%s\"\n", x, actual_x, char_offset, utf8_test + char_offset); try(rufl_split("NewHall", rufl_WEIGHT_400, 240, utf8_test, sizeof utf8_test - 1, x, &char_offset, &actual_x), "rufl_split"); printf("split: %i -> %i %zi \"%s\"\n", x, actual_x, char_offset, utf8_test + char_offset); } try(rufl_decompose_glyph("Homerton", rufl_WEIGHT_400, 1280, "A", 1, &funcs, 0), "rufl_decompose_glyph"); try(rufl_paint_callback("NewHall", rufl_WEIGHT_400, 240, utf8_test, sizeof utf8_test - 1, 1200, 1000, callback, 0), "rufl_paint_callback"); try(rufl_font_bbox("NewHall", rufl_WEIGHT_400, 240, bbox), "rufl_font_bbox"); printf("bbox: %i %i %i %i\n", bbox[0], bbox[1], bbox[2], bbox[3]); rufl_quit(); return 0; } void try(rufl_code code, const char *context) { if (code == rufl_OK) return; else if (code == rufl_OUT_OF_MEMORY) printf("error: %s: out of memory\n", context); else if (code == rufl_FONT_MANAGER_ERROR) printf("error: %s: Font Manager error %x %s\n", context, rufl_fm_error->errnum, rufl_fm_error->errmess); else if (code == rufl_FONT_NOT_FOUND) printf("error: %s: font not found\n", context); else if (code == rufl_IO_ERROR) printf("error: %s: io error: %i %s\n", context, errno, strerror(errno)); else if (code == rufl_IO_EOF) printf("error: %s: eof\n", context); else printf("error: %s: unknown error\n", context); rufl_quit(); exit(1); } int move_to(os_coord *to, void *user) { (void) user; printf("Move to (%d,%d)\n", to->x, to->y); return 0; } int line_to(os_coord *to, void *user) { (void) user; printf("Line to (%d,%d)\n", to->x, to->y); return 0; } int cubic_to(os_coord *control1, os_coord *control2, os_coord *to, void *user) { (void) user; printf("Bezier to (%d,%d),(%d,%d),(%d,%d)\n", control1->x, control1->y, control2->x, control2->y, to->x, to->y); return 0; } void callback(void *context, const char *font_name, unsigned int font_size, const char *s8, unsigned short *s16, unsigned int n, int x, int y) { (void) context; printf("callback: \"%s\", %u, ", font_name, font_size); if (s8) printf("s8 \"%.*s\" ", n, s8); else { printf("s16 \""); for (unsigned int i = 0; i != n; i++) printf("%x ", (unsigned int) s16[i]); printf("\" "); } printf("%i %i\n", x, y); }
/** * Internal textarea redraw routine * * \param redraw Redraw/update request block * \param update True if update, false if full redraw */ void ro_textarea_redraw_internal(wimp_draw *redraw, bool update) { struct text_area *ta; int clip_x0, clip_y0, clip_x1, clip_y1; int line0, line1, line; osbool more; rufl_code code; os_error *error; ta = (struct text_area *)ro_gui_wimp_event_get_user_data(redraw->w); if (update) error = xwimp_update_window(redraw, &more); else error = xwimp_redraw_window(redraw, &more); if (error) { LOG(("xwimp_redraw_window: 0x%x: %s", error->errnum, error->errmess)); return; } while (more) { clip_x0 = redraw->clip.x0 - (redraw->box.x0-redraw->xscroll); clip_y0 = (redraw->box.y1-redraw->yscroll) - redraw->clip.y1; clip_x1 = redraw->clip.x1 - (redraw->box.x0-redraw->xscroll); clip_y1 = (redraw->box.y1-redraw->yscroll) - redraw->clip.y0; error = xcolourtrans_set_gcol( (ta->flags & TEXTAREA_READONLY) ? 0xD9D9D900 : 0xFFFFFF00, colourtrans_SET_BG_GCOL | colourtrans_USE_ECFS_GCOL, os_ACTION_OVERWRITE, 0, 0); if (error) { LOG(("xcolourtrans_set_gcol: 0x%x: %s", error->errnum, error->errmess)); return; } error = xos_clg(); if (error) { LOG(("xos_clg: 0x%x: %s", error->errnum, error->errmess)); return; } if (!ta->lines) /* Nothing to redraw */ return; line0 = clip_y0 / ta->line_height - 1; line1 = clip_y1 / ta->line_height + 1; if (line0 < 0) line0 = 0; if (line1 < 0) line1 = 0; if (ta->line_count - 1 < (unsigned)line0) line0 = ta->line_count - 1; if (ta->line_count - 1 < (unsigned)line1) line1 = ta->line_count - 1; if (line1 < line0) line1 = line0; for (line = line0; line <= line1; line++) { if (ta->lines[line].b_length == 0) continue; error = xcolourtrans_set_font_colours(font_CURRENT, (ta->flags & TEXTAREA_READONLY) ? 0xD9D9D900 : 0xFFFFFF00, 0x00000000, 14, 0, 0, 0); if (error) { LOG(("xcolourtrans_set_font_colours: 0x%x: %s", error->errnum, error->errmess)); return; } code = rufl_paint(ta->font_family, ta->font_style, ta->font_size, ta->text + ta->lines[line].b_start, ta->lines[line].b_length, redraw->box.x0 - redraw->xscroll + MARGIN_LEFT, redraw->box.y1 - redraw->yscroll - ((line + 1) * ta->line_height - ta->line_spacing), rufl_BLEND_FONT); if (code != rufl_OK) { if (code == rufl_FONT_MANAGER_ERROR) LOG(("rufl_paint: rufl_FONT_MANAGER_ERROR: 0x%x: %s", rufl_fm_error->errnum, rufl_fm_error->errmess)); else LOG(("rufl_paint: 0x%x", code)); } } error = xwimp_get_rectangle(redraw, &more); if (error) { LOG(("xwimp_get_rectangle: 0x%x: %s", error->errnum, error->errmess)); return; } } }