Changeset 7bef2d8 in mainline
- Timestamp:
- 2020-09-17T16:41:05Z (4 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- d53af3c8
- Parents:
- 313ac8e
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/fontedit/fontedit.c
r313ac8e r7bef2d8 95 95 } 96 96 97 /** Adjust advance of the current glyph. 98 * 99 * @param fedit Font editor 100 */ 101 static void font_edit_adjust_advance(font_edit_t *fedit, gfx_coord_t change) 102 { 103 gfx_glyph_metrics_t gmetrics; 104 105 gfx_glyph_get_metrics(fedit->glyph, &gmetrics); 106 gmetrics.advance += change; 107 (void) gfx_glyph_set_metrics(fedit->glyph, &gmetrics); 108 109 font_edit_paint(fedit); 110 } 111 97 112 /** Handle font editor position event. 98 113 * … … 120 135 } 121 136 122 /** Handle font editor keyboard event.137 /** Handle font editor control-key press. 123 138 * 124 139 * @param widget Canvas widget 125 140 * @param data Position event 126 141 */ 142 static void font_edit_ctrl_key(font_edit_t *fedit, kbd_event_t *event) 143 { 144 switch (event->key) { 145 case KC_S: 146 printf("Save!\n"); 147 (void) gfx_glyph_bmp_save(fedit->gbmp); 148 font_edit_paint(fedit); 149 break; 150 case KC_1: 151 printf("Set pixels\n"); 152 fedit->pen_color = 1; 153 break; 154 case KC_2: 155 printf("Clear pixels\n"); 156 fedit->pen_color = 0; 157 break; 158 case KC_3: 159 font_edit_adjust_advance(fedit, -1); 160 break; 161 case KC_4: 162 font_edit_adjust_advance(fedit, +1); 163 break; 164 default: 165 break; 166 } 167 } 168 169 /** Handle font editor unmodified key press. 170 * 171 * @param widget Canvas widget 172 * @param data Position event 173 */ 174 static void font_edit_unmod_key(font_edit_t *fedit, kbd_event_t *event) 175 { 176 char str[5]; 177 gfx_glyph_metrics_t gmetrics; 178 gfx_glyph_t *glyph; 179 gfx_glyph_bmp_t *bmp; 180 size_t stradv; 181 errno_t rc; 182 183 if (event->c == '\0') 184 return; 185 186 printf("Character '%lc'\n", event->c); 187 snprintf(str, sizeof(str), "%lc", event->c); 188 189 rc = gfx_font_search_glyph(fedit->font, str, &glyph, &stradv); 190 if (rc == EOK) { 191 /* Found an existing glyph */ 192 rc = gfx_glyph_bmp_open(glyph, &bmp); 193 if (rc != EOK) { 194 printf("Error opening glyph bitmap.\n"); 195 return; 196 } 197 198 gfx_glyph_bmp_close(fedit->gbmp); 199 fedit->glyph = glyph; 200 fedit->gbmp = bmp; 201 font_edit_paint(fedit); 202 return; 203 } 204 205 /* Create new glyph */ 206 207 gfx_glyph_metrics_init(&gmetrics); 208 rc = gfx_glyph_create(fedit->font, &gmetrics, &glyph); 209 if (rc != EOK) { 210 printf("Error creating glyph.\n"); 211 goto error; 212 } 213 214 rc = gfx_glyph_set_pattern(glyph, str); 215 if (rc != EOK) { 216 printf("Error setting glyph pattern.\n"); 217 goto error; 218 } 219 220 rc = gfx_glyph_bmp_open(glyph, &bmp); 221 if (rc != EOK) { 222 printf("Error opening glyph bitmap.\n"); 223 goto error; 224 } 225 226 gfx_glyph_bmp_close(fedit->gbmp); 227 fedit->glyph = glyph; 228 fedit->gbmp = bmp; 229 font_edit_paint(fedit); 230 return; 231 error: 232 if (glyph != NULL) 233 gfx_glyph_destroy(glyph); 234 return; 235 } 236 237 /** Handle font editor keyboard event. 238 * 239 * @param widget Canvas widget 240 * @param data Position event 241 */ 127 242 static void font_edit_kbd_event(widget_t *widget, void *data) 128 243 { … … 132 247 fedit = (font_edit_t *) widget_get_data(widget); 133 248 134 if (event->type == KEY_PRESS) { 135 switch (event->key) { 136 case KC_S: 137 printf("Save!\n"); 138 (void) gfx_glyph_bmp_save(fedit->gbmp); 139 font_edit_paint(fedit); 140 break; 141 case KC_1: 142 printf("Set pixels\n"); 143 fedit->pen_color = 1; 144 break; 145 case KC_2: 146 printf("Clear pixels\n"); 147 fedit->pen_color = 0; 148 break; 149 default: 150 break; 151 } 249 if (event->type != KEY_PRESS) 250 return; 251 252 if ((event->mods & KM_CTRL) != 0 && 253 (event->mods & (KM_ALT | KM_SHIFT)) == 0) { 254 font_edit_ctrl_key(fedit, event); 255 } else if ((event->mods & (KM_CTRL | KM_ALT)) == 0) { 256 font_edit_unmod_key(fedit, event); 152 257 } 153 258 } … … 220 325 gfx_rect_t rect; 221 326 gfx_rect_t grect; 327 gfx_glyph_metrics_t gmetrics; 222 328 errno_t rc; 223 329 int x, y; … … 252 358 gfx_color_delete(color); 253 359 254 /* Display glyph origin */360 /* Display glyph origin and advance */ 255 361 256 362 rc = gfx_color_new_rgb_i16(0, 0xffff, 0, &color); … … 263 369 264 370 font_edit_gpix_to_disp(fedit, 0, 0, &rect); 371 372 rc = gfx_fill_rect(fedit->gc, &rect); 373 if (rc != EOK) 374 goto error; 375 376 gfx_glyph_get_metrics(fedit->glyph, &gmetrics); 377 378 font_edit_gpix_to_disp(fedit, gmetrics.advance, 0, &rect); 265 379 266 380 rc = gfx_fill_rect(fedit->gc, &rect);
Note:
See TracChangeset
for help on using the changeset viewer.