Changeset 6a87f28 in mainline
- Timestamp:
- 2021-02-25T16:48:13Z (4 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- bac8acab
- Parents:
- 26853ebc
- Location:
- uspace
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/gfxdemo/gfxdemo.c
r26853ebc r6a87f28 185 185 for (j = 0; j < h; j++) { 186 186 pixelmap_put_pixel(&pixelmap, i, j, 187 PIXEL( 255, (i % 30) < 3 ? 255 : 0,187 PIXEL(0, (i % 30) < 3 ? 255 : 0, 188 188 (j % 30) < 3 ? 255 : 0, i / 2)); 189 189 } … … 221 221 k = i * i + j * j; 222 222 pixelmap_put_pixel(&pixelmap, i, j, 223 PIXEL( 255, k, k, k));223 PIXEL(0, k, k, k)); 224 224 } 225 225 } … … 256 256 k = i * i + j * j; 257 257 pixelmap_put_pixel(&pixelmap, i, j, 258 k < w * w / 2 ? PIXEL( 255, 0, 255, 0) :258 k < w * w / 2 ? PIXEL(0, 0, 255, 0) : 259 259 PIXEL(0, 255, 0, 255)); 260 260 } … … 469 469 return EOK; 470 470 471 rc = gfx_typeface_open(gc, "/data/font/helena.tpf", &tface); 472 if (rc != EOK) { 473 printf("Error opening typeface\n"); 474 goto error; 475 } 476 477 finfo = gfx_typeface_first_font(tface); 478 if (finfo == NULL) { 479 printf("Typeface contains no font.\n"); 480 rc = ENOENT; 481 goto error; 482 } 483 484 rc = gfx_font_open(finfo, &font); 485 if (rc != EOK) { 486 printf("Error opening font.\n"); 487 goto error; 471 /* XXX Crude way of detecting text mode */ 472 if (w < 256) { 473 /* Create dummy font for text mode */ 474 rc = gfx_typeface_create(gc, &tface); 475 if (rc != EOK) { 476 printf("Error creating typeface\n"); 477 goto error; 478 } 479 480 rc = gfx_font_create_textmode(tface, &font); 481 if (rc != EOK) { 482 printf("Error creating font\n"); 483 goto error; 484 } 485 } else { 486 /* Load font */ 487 rc = gfx_typeface_open(gc, "/data/font/helena.tpf", &tface); 488 if (rc != EOK) { 489 printf("Error opening typeface\n"); 490 goto error; 491 } 492 493 finfo = gfx_typeface_first_font(tface); 494 if (finfo == NULL) { 495 printf("Typeface contains no font.\n"); 496 rc = ENOENT; 497 goto error; 498 } 499 500 rc = gfx_font_open(finfo, &font); 501 if (rc != EOK) { 502 printf("Error opening font.\n"); 503 goto error; 504 } 488 505 } 489 506 -
uspace/lib/congfx/src/console.c
r26853ebc r6a87f28 102 102 cols = cgc->rect.p1.x - cgc->rect.p0.x; 103 103 104 ch.ch = 0;104 ch.ch = cgc->clr >> 24; 105 105 ch.flags = CHAR_FLAG_DIRTY; 106 106 ch.attrs.type = CHAR_ATTR_RGB; 107 ch.attrs.val.rgb.fgcolor = cgc->clr ;107 ch.attrs.val.rgb.fgcolor = cgc->clr ^ 0xffffff; 108 108 ch.attrs.val.rgb.bgcolor = cgc->clr; 109 109 … … 320 320 y - offs.y - cbm->rect.p0.y); 321 321 322 ch.ch = 0;322 ch.ch = clr >> 24; 323 323 ch.flags = CHAR_FLAG_DIRTY; 324 324 ch.attrs.type = CHAR_ATTR_RGB; 325 ch.attrs.val.rgb.fgcolor = clr ;325 ch.attrs.val.rgb.fgcolor = clr ^ 0xffffff; 326 326 ch.attrs.val.rgb.bgcolor = clr; 327 327 … … 338 338 y - offs.y - cbm->rect.p0.y); 339 339 340 ch.ch = 0;340 ch.ch = clr >> 24; 341 341 ch.flags = CHAR_FLAG_DIRTY; 342 342 ch.attrs.type = CHAR_ATTR_RGB; 343 ch.attrs.val.rgb.fgcolor = clr ;343 ch.attrs.val.rgb.fgcolor = clr ^ 0xffffff; 344 344 ch.attrs.val.rgb.bgcolor = clr; 345 345 -
uspace/lib/gfxfont/include/gfx/font.h
r26853ebc r6a87f28 50 50 extern errno_t gfx_font_create(gfx_typeface_t *, gfx_font_props_t *, 51 51 gfx_font_metrics_t *, gfx_font_t **); 52 extern errno_t gfx_font_create_textmode(gfx_typeface_t *, gfx_font_t **); 52 53 extern errno_t gfx_font_open(gfx_font_info_t *, gfx_font_t **); 53 54 extern void gfx_font_close(gfx_font_t *); -
uspace/lib/gfxfont/include/types/gfx/font.h
r26853ebc r6a87f28 52 52 gff_italic = 0x2, 53 53 /** Bold, italic */ 54 gff_bold_italic = gff_bold | gff_italic 54 gff_bold_italic = gff_bold | gff_italic, 55 /** Text mode */ 56 gff_text_mode = 0x4 55 57 } gfx_font_flags_t; 56 58 -
uspace/lib/gfxfont/src/font.c
r26853ebc r6a87f28 180 180 } 181 181 182 /** Create dummy font for printing text in text mode. 183 * 184 * @param tface Typeface 185 * @param rfont Place to store pointer to new font 186 * 187 * @return EOK on success, EINVAL if parameters are invald, 188 * ENOMEM if insufficient resources, EIO if graphic device connection 189 * was lost 190 */ 191 errno_t gfx_font_create_textmode(gfx_typeface_t *tface, gfx_font_t **rfont) 192 { 193 gfx_font_props_t props; 194 gfx_font_metrics_t metrics; 195 196 gfx_font_props_init(&props); 197 props.size = 1; 198 props.flags = gff_text_mode; 199 200 gfx_font_metrics_init(&metrics); 201 metrics.ascent = 0; 202 metrics.descent = 0; 203 metrics.leading = 1; 204 205 return gfx_font_create(tface, &props, &metrics, rfont); 206 } 207 182 208 /** Open font. 183 209 * … … 229 255 void gfx_font_get_metrics(gfx_font_t *font, gfx_font_metrics_t *metrics) 230 256 { 231 *metrics = font->metrics; 257 if (font != NULL) { 258 *metrics = font->metrics; 259 } else { 260 metrics->ascent = 0; 261 metrics->descent = 0; 262 metrics->leading = 1; 263 } 232 264 } 233 265 -
uspace/lib/gfxfont/src/text.c
r26853ebc r6a87f28 35 35 36 36 #include <errno.h> 37 #include <gfx/bitmap.h> 37 38 #include <gfx/font.h> 38 39 #include <gfx/glyph.h> 39 40 #include <gfx/text.h> 41 #include <io/pixelmap.h> 40 42 #include <mem.h> 43 #include <str.h> 44 #include "../private/font.h" 45 #include "../private/typeface.h" 41 46 42 47 /** Initialize text formatting structure. … … 66 71 gfx_coord_t width; 67 72 errno_t rc; 73 74 if ((font->finfo->props.flags & gff_text_mode) != 0) 75 return str_width(str); 68 76 69 77 width = 0; … … 83 91 84 92 return width; 93 } 94 95 /** Print string using text characters in text mode. 96 * 97 * @param font Font 98 * @param pos Position of top-left corner of text 99 * @param str String 100 * @return EOK on success or an error code 101 */ 102 static errno_t gfx_puttext_textmode(gfx_font_t *font, gfx_coord2_t *pos, 103 const char *str) 104 { 105 gfx_context_t *gc = font->typeface->gc; 106 gfx_bitmap_params_t params; 107 gfx_bitmap_t *bitmap; 108 gfx_bitmap_alloc_t alloc; 109 pixelmap_t pmap; 110 gfx_coord_t x; 111 pixel_t pixel; 112 errno_t rc; 113 114 /* 115 * NOTE: Creating and destroying bitmap each time is not probably 116 * the most efficient way. 117 */ 118 119 gfx_bitmap_params_init(¶ms); 120 params.rect.p0.x = 0; 121 params.rect.p0.y = 0; 122 params.rect.p1.x = str_width(str); 123 params.rect.p1.y = 1; 124 125 rc = gfx_bitmap_create(gc, ¶ms, NULL, &bitmap); 126 if (rc != EOK) 127 return rc; 128 129 rc = gfx_bitmap_get_alloc(bitmap, &alloc); 130 if (rc != EOK) { 131 gfx_bitmap_destroy(bitmap); 132 return rc; 133 } 134 135 pmap.width = params.rect.p1.x; 136 pmap.height = 1; 137 pmap.data = alloc.pixels; 138 139 for (x = 0; x < params.rect.p1.x; x++) { 140 pixel = PIXEL(str[x], 0xff, 0xff, 0xff); 141 pixelmap_put_pixel(&pmap, x, 0, pixel); 142 } 143 144 rc = gfx_bitmap_render(bitmap, NULL, pos); 145 146 gfx_bitmap_destroy(bitmap); 147 return rc; 85 148 } 86 149 … … 141 204 } 142 205 206 /* Text mode */ 207 if ((font->finfo->props.flags & gff_text_mode) != 0) 208 return gfx_puttext_textmode(font, &cpos, str); 209 143 210 cp = str; 144 211 while (*cp != '\0') { -
uspace/lib/gfxfont/test/font.c
r26853ebc r6a87f28 98 98 } 99 99 100 /** Test creating and destroying text-mode font */ 101 PCUT_TEST(create_textmode_destroy) 102 { 103 gfx_typeface_t *tface; 104 gfx_font_t *font; 105 gfx_context_t *gc; 106 test_gc_t tgc; 107 errno_t rc; 108 109 rc = gfx_context_new(&test_ops, (void *)&tgc, &gc); 110 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 111 112 rc = gfx_typeface_create(gc, &tface); 113 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 114 115 rc = gfx_font_create_textmode(tface, &font); 116 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 117 118 gfx_font_close(font); 119 gfx_typeface_destroy(tface); 120 121 rc = gfx_context_delete(gc); 122 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 123 } 124 100 125 /** Test gfx_font_get_metrics() */ 101 126 PCUT_TEST(get_metrics)
Note:
See TracChangeset
for help on using the changeset viewer.