Changeset 20d0098 in mainline
- Timestamp:
- 2020-08-27T10:35:31Z (4 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 32066f2
- Parents:
- 06b8383
- git-author:
- Jiri Svoboda <jiri@…> (2020-08-26 17:35:13)
- git-committer:
- Jiri Svoboda <jiri@…> (2020-08-27 10:35:31)
- Location:
- uspace
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/fontedit/fontedit.c
r06b8383 r20d0098 39 39 #include <gfx/color.h> 40 40 #include <gfx/font.h> 41 #include <gfx/glyph.h> 41 42 #include <gfx/render.h> 42 43 #include <gfx/typeface.h> … … 49 50 #include "fontedit.h" 50 51 52 enum { 53 glyph_scale = 8 54 }; 55 56 static errno_t font_edit_paint(font_edit_t *); 57 51 58 /** Clear screen. 52 59 * … … 86 93 } 87 94 95 /** Handle font editor position event. 96 * 97 * @param widget Canvas widget 98 * @param data Position event 99 */ 100 static void font_edit_pos_event(widget_t *widget, void *data) 101 { 102 pos_event_t *event = (pos_event_t *) data; 103 font_edit_t *fedit; 104 105 fedit = (font_edit_t *) widget_get_data(widget); 106 107 if (event->type == POS_PRESS) { 108 gfx_glyph_bmp_setpix(fedit->gbmp, event->hpos / glyph_scale, 109 event->vpos / glyph_scale, 1); 110 font_edit_paint(fedit); 111 } 112 } 113 114 /** Paint glyph bitmap. 115 * 116 * @param fedit Font editor 117 */ 118 static errno_t font_edit_paint_gbmp(font_edit_t *fedit) 119 { 120 gfx_color_t *color = NULL; 121 gfx_rect_t rect; 122 errno_t rc; 123 int w, h; 124 int x, y; 125 int pix; 126 127 w = 50; 128 h = 50; 129 130 rc = gfx_color_new_rgb_i16(0xffff, 0xffff, 0xffff, &color); 131 if (rc != EOK) 132 goto error; 133 134 rc = gfx_set_color(fedit->gc, color); 135 if (rc != EOK) 136 goto error; 137 138 for (y = 0; y < h; y++) { 139 for (x = 0; x < w; x++) { 140 pix = gfx_glyph_bmp_getpix(fedit->gbmp, x, y); 141 142 rect.p0.x = x * glyph_scale; 143 rect.p0.y = y * glyph_scale; 144 rect.p1.x = (x + 1) * glyph_scale; 145 rect.p1.y = (y + 1) * glyph_scale; 146 147 if (pix != 0) { 148 rc = gfx_fill_rect(fedit->gc, &rect); 149 if (rc != EOK) 150 goto error; 151 } 152 } 153 } 154 155 gfx_color_delete(color); 156 return EOK; 157 error: 158 if (color != NULL) 159 gfx_color_delete(color); 160 return rc; 161 } 162 88 163 /** Paint font editor. 89 164 * … … 99 174 100 175 rc = clear_scr(fedit->gc, w, h); 176 if (rc != EOK) 177 return rc; 178 179 rc = font_edit_paint_gbmp(fedit); 101 180 if (rc != EOK) 102 181 return rc; … … 123 202 gfx_font_props_t props; 124 203 gfx_font_metrics_t metrics; 204 gfx_glyph_metrics_t gmetrics; 205 gfx_glyph_t *glyph; 206 gfx_glyph_bmp_t *bmp; 125 207 gfx_coord_t vw, vh; 126 208 gfx_context_t *gc; … … 163 245 pixbuf = NULL; 164 246 165 canvas = create_canvas(window_root(window), NULL, vw, vh,247 canvas = create_canvas(window_root(window), fedit, vw, vh, 166 248 surface); 167 249 if (canvas == NULL) { … … 197 279 goto error; 198 280 } 281 282 gfx_glyph_metrics_init(&gmetrics); 283 284 rc = gfx_glyph_create(font, &gmetrics, &glyph); 285 if (rc != EOK) { 286 printf("Error creating glyph.\n"); 287 goto error; 288 } 289 290 rc = gfx_glyph_bmp_open(glyph, &bmp); 291 if (rc != EOK) { 292 printf("Error opening glyph bitmap.\n"); 293 goto error; 294 } 295 296 sig_connect(&canvas->position_event, &canvas->widget, 297 font_edit_pos_event); 199 298 200 299 fedit->cgc = cgc; … … 203 302 fedit->height = vh; 204 303 fedit->typeface = tface; 304 fedit->glyph = glyph; 305 fedit->gbmp = bmp; 205 306 206 307 *rfedit = fedit; … … 212 313 * handler (which we have no way of registering) 213 314 */ 315 if (bmp != NULL) 316 gfx_glyph_bmp_close(bmp); 317 if (glyph != NULL) 318 gfx_glyph_destroy(glyph); 319 if (font != NULL) 320 gfx_font_close(font); 321 if (tface != NULL) 322 gfx_typeface_destroy(tface); 214 323 if (surface != NULL) 215 324 surface_destroy(surface); -
uspace/app/fontedit/fontedit.h
r06b8383 r20d0098 37 37 #define FONTEDIT_H 38 38 39 #include <gfx/glyph.h> 40 #include <gfx/glyph_bmp.h> 39 41 #include <gfx/typeface.h> 40 42 #include <guigfx/canvas.h> … … 52 54 /** Typeface */ 53 55 gfx_typeface_t *typeface; 56 /** Glyph */ 57 gfx_glyph_t *glyph; 58 /** Glyph bitmap */ 59 gfx_glyph_bmp_t *gbmp; 54 60 } font_edit_t; 55 61 -
uspace/lib/gfxfont/src/font.c
r06b8383 r20d0098 113 113 finfo->props = *props; 114 114 finfo->font = font; 115 115 116 font->typeface = tface; 117 118 font->rect.p0.x = 0; 119 font->rect.p0.y = 0; 120 font->rect.p1.x = 1; 121 font->rect.p1.y = 1; 116 122 117 123 rc = gfx_font_set_metrics(font, metrics);
Note:
See TracChangeset
for help on using the changeset viewer.