Index: trunk/src/conf_core.h =================================================================== --- trunk/src/conf_core.h (revision 701) +++ trunk/src/conf_core.h (revision 702) @@ -10,7 +10,7 @@ RND_CFT_COLOR layer[16]; /* default layer colors; when a new layer is created, a color from this list is assigned initially */ RND_CFT_COLOR attached; } color; - RND_CFT_STRING default_font; /* path to the ttf of the default font */ + RND_CFT_STRING default_font; /* OBSOLETE: used to be path to a ttf font; camv-rnd uses an embedded internal vector font now */ } appearance; const struct rc { /* rc */ RND_CFT_BOOLEAN error_on_bad_cli_files; Index: trunk/src/conf_core_fields.h =================================================================== --- trunk/src/conf_core_fields.h (revision 701) +++ trunk/src/conf_core_fields.h (revision 702) @@ -1,4 +1,4 @@ -conf_reg(appearance.default_font, scalar, RND_CFN_STRING, "appearance", "default_font", "path to the ttf of the default font", 0) +conf_reg(appearance.default_font, scalar, RND_CFN_STRING, "appearance", "default_font", "OBSOLETE: used to be path to a ttf font; camv-rnd uses an embedded internal vector font now", 0) conf_reg(appearance.color.layer, array, RND_CFN_COLOR, "appearance/color", "layer", "default layer colors; when a new layer is created, a color from this list is assigned initially", 0) conf_reg(appearance.color.attached, scalar, RND_CFN_COLOR, "appearance/color", "attached", "", 0) conf_reg(rc.error_on_bad_cli_files, scalar, RND_CFN_BOOLEAN, "rc", "error_on_bad_cli_files", "", 0) Index: trunk/src/obj_text.c =================================================================== --- trunk/src/obj_text.c (revision 701) +++ trunk/src/obj_text.c (revision 702) @@ -2,7 +2,7 @@ * COPYRIGHT * * camv-rnd - electronics-related CAM viewer - * Copyright (C) 2020 Tibor 'Igor2' Palinkas + * Copyright (C) 2020,2023 Tibor 'Igor2' Palinkas * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -37,120 +37,64 @@ #include #include #include -#include "ttf2bbox/ttf2bbox.h" #include -static rnd_font_t embf_, *embf = &embf_; +static rnd_font_t embf_, *embf = &embf_, *font = &embf_; +double font_scale = 1.0; #include "font_internal.c" - -static ttf2bbox_t ttf; -static int def_fid, ttf_inited = 0; - static void camv_text_free_fields(camv_any_obj_t *obj) { - if (obj->text.pm != NULL) { - if (rnd_render->uninit_pixmap != NULL) - rnd_render->uninit_pixmap(rnd_render, obj->text.pm); - rnd_pixmap_free(obj->text.pm); - obj->text.pm = NULL; - } free(obj->text.s); obj->text.s = NULL; } -static void camv_text_draw(camv_any_obj_t *obj, rnd_hid_gc_t gc, rnd_xform_mx_t *mx) +static void camv_text_draw_atom_cb(void *cb_ctx, const rnd_glyph_atom_t *a) { - if ((rnd_render->draw_pixmap != NULL) && (obj->text.pm != NULL)) { - if (mx != NULL) { - rnd_coord_t x = rnd_xform_x((*mx), obj->text.x, obj->text.y); - rnd_coord_t y = rnd_xform_y((*mx), obj->text.x, obj->text.y); - rnd_render->draw_pixmap(rnd_render, x, y, obj->text.sx, obj->text.sy, obj->text.pm); - } - else - rnd_render->draw_pixmap(rnd_render, obj->text.x, obj->text.y, obj->text.sx, obj->text.sy, obj->text.pm); + rnd_hid_gc_t gc = cb_ctx; + long h; + + switch(a->type) { + case RND_GLYPH_LINE: + rnd_hid_set_line_width(gc, a->line.thickness); + rnd_render->draw_line(gc, a->line.x1, a->line.y1, a->line.x2, a->line.y2); + break; + case RND_GLYPH_ARC: + rnd_hid_set_line_width(gc, a->arc.thickness); + rnd_render->draw_arc(gc, a->arc.cx, a->arc.cy, a->arc.r, a->arc.r, a->arc.start, a->arc.delta); + break; + case RND_GLYPH_POLY: + h = a->poly.pts.used / 2; + rnd_render->fill_polygon(gc, h, &a->poly.pts.array[0], &a->poly.pts.array[h]); + break; } } -static void camv_text_bbox(camv_any_obj_t *obj) +static void camv_text_draw(camv_any_obj_t *obj, rnd_hid_gc_t gc, rnd_xform_mx_t *mx) { - rnd_coord_t sx2 = obj->text.sx / 2, sy2 = obj->text.sy / 2; - - obj->text.bbox.x1 = obj->text.x - sx2; - obj->text.bbox.x2 = obj->text.x + sx2; - obj->text.bbox.y1 = obj->text.y - sy2; - obj->text.bbox.y2 = obj->text.y + sy2; - obj->text.bbox_valid = 1; + rnd_font_draw_string(font, (unsigned char *)obj->text.s, obj->text.x, obj->text.y, font_scale, font_scale, obj->text.rot, RND_FONT_MIRROR_Y, 0, 0, 0, RND_FONT_TINY_HIDE, camv_text_draw_atom_cb, gc); } -void camv_text_update_color(camv_text_t *text, camv_layer_t *ly) +static void camv_text_bbox(camv_any_obj_t *obj) { - long n, end = text->pm->sx * text->pm->sy; - unsigned char *i, *o; - ttf2bbox_pixmap_t *tpm = text->ttf_pm; - - if (ly == NULL) - ly = text->parent_layer; - - text->pm->tr = text->pm->tg = 127; - text->pm->tb = 128; - text->pm->has_transp = 1; - - - for(n = 0, i = tpm->p, o = text->pm->p; n < end; n++, i++, o+=3) { - if (i[0] == 0) { - o[0] = text->pm->tr; - o[1] = text->pm->tg; - o[2] = text->pm->tb; - } - else { - o[0] = ly->color.fr * i[0] + rnd_conf.appearance.color.background.fr * (255-i[0]); - o[1] = ly->color.fg * i[0] + rnd_conf.appearance.color.background.fg * (255-i[0]); - o[2] = ly->color.fb * i[0] + rnd_conf.appearance.color.background.fb * (255-i[0]); - } -#if 0 - if ((n % text->pm->sx) == 0) printf("\n"); - printf("%d", i[0]/64); -#endif + int n; + obj->text.bbox.x1 = obj->text.bbox.y1 = RND_COORD_MAX; + obj->text.bbox.x2 = obj->text.bbox.y2 = -RND_COORD_MAX; + for(n = 0; n < 4; n++) { + if (obj->text.cx[n] < obj->text.bbox.x1) obj->text.bbox.x1 = obj->text.cx[n]; + if (obj->text.cx[n] > obj->text.bbox.x2) obj->text.bbox.x2 = obj->text.cx[n]; + if (obj->text.cy[n] < obj->text.bbox.y1) obj->text.bbox.y1 = obj->text.cy[n]; + if (obj->text.cy[n] > obj->text.bbox.y2) obj->text.bbox.y2 = obj->text.cy[n]; } + obj->text.bbox_valid = 1; } void camv_text_update(rnd_design_t *hidlib, camv_text_t *text, camv_layer_t *ly) { - long tox, toy, sx, sy; - - - if (!ttf_inited) { - if (ttf2bbox_init(&ttf) != 0) { - fprintf(stderr, "Failed to initialize ttf2bbox\n"); /* shuld never happen */ - exit(1); - } - def_fid = ttf2bbox_font_load(&ttf, conf_core.appearance.default_font); - if (def_fid < 0) { - rnd_message(RND_MSG_ERROR, "Failed to load ttf: '%s'\nPlease configure appearance/default_font to point to a ttf!\n", conf_core.appearance.default_font); - return; - } - ttf_inited = 1; - } - - if (ttf2bbox_estimate_at(&ttf, def_fid, text->size, text->s, 0, 0, text->rot, TTF2BBOX_LEFT, TTF2BBOX_TOP, &tox, &toy, &sx, &sy, 1) < 0) { - fprintf(stderr, "Failed to estimate text size with ttf2bbox\n"); /* shuld never happen */ - exit(1); - } - rnd_trace("text estimate: t=%ld;%ld s=%ld;%ld\n", tox, toy, sx, sy); - if (text->ttf_pm != NULL) - free(text->ttf_pm); - text->ttf_pm = ttf2bbox_pm_alloc(sx, sy); - ttf2bbox_render_in_box(&ttf, def_fid, text->ttf_pm, text->s, 0, 0, text->rot, sx, sy, 1); - text->sx = RND_MM_TO_COORD(sx)/128; - text->sy = RND_MM_TO_COORD(sy)/128; - - if (text->pm != NULL) - rnd_pixmap_free(text->pm); - text->pm = rnd_pixmap_alloc(hidlib, sx, sy); - camv_text_update_color(text, ly); /* really copies ->ttf_pm to ->pm */ + rnd_font_string_bbox(text->cx, text->cy, font, (unsigned char *)text->s, text->x, text->y, font_scale, font_scale, text->rot, RND_FONT_MIRROR_Y, 0, 0); + camv_text_bbox((camv_any_obj_t *)text); } static void camv_text_copy(camv_any_obj_t *dst, const camv_any_obj_t *src) @@ -161,8 +105,13 @@ static void camv_text_move(camv_any_obj_t *o, rnd_coord_t dx, rnd_coord_t dy) { + int n; o->text.x += dx; o->text.y += dy; + for(n = 0; n < 4; n++) { + o->text.cx[n] += dx; + o->text.cy[n] += dy; + } if (o->text.bbox_valid) { o->text.bbox.x1 += dx; o->text.bbox.y1 += dy; o->text.bbox.x2 += dx; o->text.bbox.y2 += dy; Index: trunk/src/obj_text.h =================================================================== --- trunk/src/obj_text.h (revision 701) +++ trunk/src/obj_text.h (revision 702) @@ -34,13 +34,11 @@ CAMV_ANY_PRIMITIVE_FIELDS; rnd_coord_t x, y; int size; - double rot; + double rot; /* in degrees */ char *s; /* internal/cache */ - void *ttf_pm; /* (ttf2bbox_pixmap_t *) */ - rnd_pixmap_t *pm; - rnd_coord_t sx, sy; + rnd_coord_t cx[4], cy[4]; /* 4 corners of the rotated bbox */ } camv_text_t; void camv_text_init(camv_text_t *text);