Changeset 6a87f28 in mainline for uspace/lib/gfxfont/src/text.c
- 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
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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') {
Note:
See TracChangeset
for help on using the changeset viewer.