Changeset d2100e2 in mainline for uspace/lib/gfxfont/src/font.c
- Timestamp:
- 2020-08-09T18:40:28Z (5 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 06b8383
- Parents:
- 5592c56
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/gfxfont/src/font.c
r5592c56 rd2100e2 37 37 #include <assert.h> 38 38 #include <errno.h> 39 #include <gfx/bitmap.h> 39 40 #include <gfx/font.h> 40 41 #include <gfx/glyph.h> … … 70 71 { 71 72 gfx_font_t *font; 73 gfx_bitmap_params_t params; 72 74 errno_t rc; 73 75 … … 81 83 if (rc != EOK) { 82 84 assert(rc == EINVAL); 85 free(font); 86 return rc; 87 } 88 89 /* Create font bitmap */ 90 gfx_bitmap_params_init(¶ms); 91 params.rect = font->rect; 92 93 rc = gfx_bitmap_create(font->gc, ¶ms, NULL, &font->bitmap); 94 if (rc != EOK) { 83 95 free(font); 84 96 return rc; … … 190 202 } 191 203 204 /** Replace glyph graphic with empty space of specified width. 205 * 206 * This is used to resize a glyph in the font bitmap. This changes 207 * the bitmap widht and might also make the bitmap taller. 208 * Width and height of the glyph is also adjusted accordingly. 209 * 210 * @param font Font 211 * @param glyph Glyph to replace 212 * @param width Width of replacement space 213 * @param height Height of replacement space 214 */ 215 errno_t gfx_font_splice_at_glyph(gfx_font_t *font, gfx_glyph_t *glyph, 216 gfx_coord_t width, gfx_coord_t height) 217 { 218 gfx_glyph_t *g; 219 gfx_bitmap_t *nbitmap; 220 gfx_bitmap_params_t params; 221 gfx_coord_t dwidth; 222 errno_t rc; 223 224 /* Change of width of glyph */ 225 dwidth = width - (glyph->rect.p1.x - glyph->rect.p0.x); 226 227 /* Create new font bitmap, wider by dwidth pixels */ 228 gfx_bitmap_params_init(¶ms); 229 params.rect = font->rect; 230 params.rect.p1.x += dwidth; 231 if (height > params.rect.p1.y) 232 params.rect.p1.y = height; 233 234 rc = gfx_bitmap_create(font->gc, ¶ms, NULL, &nbitmap); 235 if (rc != EOK) 236 goto error; 237 238 /* Transfer glyphs before @a glyph */ 239 g = gfx_font_first_glyph(font); 240 while (g != glyph) { 241 assert(g != NULL); 242 243 rc = gfx_glyph_transfer(g, 0, nbitmap, ¶ms.rect); 244 if (rc != EOK) 245 goto error; 246 247 g = gfx_font_next_glyph(g); 248 } 249 250 /* Skip @a glyph */ 251 g = gfx_font_next_glyph(g); 252 253 /* Transfer glyphs after glyph */ 254 while (g != NULL) { 255 rc = gfx_glyph_transfer(g, dwidth, nbitmap, ¶ms.rect); 256 if (rc != EOK) 257 goto error; 258 259 /* Update glyph coordinates */ 260 g->rect.p0.x += dwidth; 261 g->rect.p1.x += dwidth; 262 g->origin.x += dwidth; 263 264 g = gfx_font_next_glyph(g); 265 } 266 267 /* Update glyph width and height */ 268 glyph->rect.p1.x = glyph->rect.p0.x + width; 269 glyph->rect.p1.y = glyph->rect.p0.y + height; 270 271 /* Update font bitmap */ 272 gfx_bitmap_destroy(font->bitmap); 273 font->bitmap = nbitmap; 274 font->rect = params.rect; 275 276 return EOK; 277 error: 278 if (nbitmap != NULL) 279 gfx_bitmap_destroy(nbitmap); 280 return rc; 281 } 282 192 283 /** @} 193 284 */
Note:
See TracChangeset
for help on using the changeset viewer.