Changeset 313ac8e in mainline
- Timestamp:
- 2020-09-17T15:28:03Z (4 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 7bef2d8
- Parents:
- 414020d9
- Location:
- uspace/lib/gfxfont
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/gfxfont/private/font.h
r414020d9 r313ac8e 84 84 85 85 extern errno_t gfx_font_splice_at_glyph(gfx_font_t *, gfx_glyph_t *, 86 gfx_ coord_t, gfx_coord_t);86 gfx_rect_t *); 87 87 88 88 #endif -
uspace/lib/gfxfont/src/font.c
r414020d9 r313ac8e 271 271 * 272 272 * This is used to resize a glyph in the font bitmap. This changes 273 * the bitmap widht andmight also make the bitmap taller.274 * Width and height of the glyph is also adjusted accordingly.273 * the bitmap widht might also make the bitmap taller. 274 * Dimensions of the glyph are also adjusted according to @a nrect. 275 275 * 276 276 * @param font Font 277 277 * @param glyph Glyph to replace 278 * @param width Width of replacement space 279 * @param height Height of replacement space 278 * @param nrect Replacement rectangle 280 279 */ 281 280 errno_t gfx_font_splice_at_glyph(gfx_font_t *font, gfx_glyph_t *glyph, 282 gfx_ coord_t width, gfx_coord_t height)281 gfx_rect_t *nrect) 283 282 { 284 283 gfx_glyph_t *g; … … 286 285 gfx_bitmap_params_t params; 287 286 gfx_coord_t dwidth; 287 gfx_coord_t x0; 288 288 errno_t rc; 289 289 290 290 /* Change of width of glyph */ 291 dwidth = width - (glyph->rect.p1.x - glyph->rect.p0.x); 291 dwidth = (nrect->p1.x - nrect->p0.x) - 292 (glyph->rect.p1.x - glyph->rect.p0.x); 292 293 293 294 /* Create new font bitmap, wider by dwidth pixels */ … … 295 296 params.rect = font->rect; 296 297 params.rect.p1.x += dwidth; 297 if ( height> params.rect.p1.y)298 params.rect.p1.y = height;298 if (nrect->p1.y - nrect->p0.y > params.rect.p1.y) 299 params.rect.p1.y = nrect->p1.y - nrect->p0.y; 299 300 300 301 rc = gfx_bitmap_create(font->typeface->gc, ¶ms, NULL, &nbitmap); 301 302 if (rc != EOK) 302 303 goto error; 304 305 /* 306 * In x0 we compute the left margin of @a glyph. We start with 307 * zero and then, if there are any preceding glyphs, we set it 308 * to the right margin of the last one. 309 */ 310 x0 = 0; 303 311 304 312 /* Transfer glyphs before @a glyph */ … … 310 318 if (rc != EOK) 311 319 goto error; 320 321 /* Left margin of the next glyph */ 322 x0 = g->rect.p1.x; 312 323 313 324 g = gfx_font_next_glyph(g); … … 331 342 } 332 343 333 /* Update glyph width and height */ 334 glyph->rect.p1.x = glyph->rect.p0.x + width; 335 glyph->rect.p1.y = glyph->rect.p0.y + height; 344 /* Place glyph rectangle inside the newly created space */ 345 glyph->origin.x = x0 - nrect->p0.x; 346 glyph->origin.y = 0 - nrect->p0.y; 347 gfx_rect_translate(&glyph->origin, nrect, &glyph->rect); 336 348 337 349 /* Update font bitmap */ -
uspace/lib/gfxfont/src/glyph_bmp.c
r414020d9 r313ac8e 66 66 return ENOMEM; 67 67 68 bmp->rect.p0.x = 0; 69 bmp->rect.p0.y = 0; 70 bmp->rect.p1.x = glyph->rect.p1.x - glyph->rect.p0.x; 71 bmp->rect.p1.y = glyph->rect.p1.y - glyph->rect.p0.y; 72 73 bmp->pixels = calloc(bmp->rect.p1.x * bmp->rect.p1.y, sizeof(int)); 68 /* Bitmap coordinates are relative to glyph origin point */ 69 gfx_rect_rtranslate(&glyph->origin, &glyph->rect, &bmp->rect); 70 71 bmp->pixels = calloc((bmp->rect.p1.x - bmp->rect.p0.x) * 72 (bmp->rect.p1.y - bmp->rect.p0.y), sizeof(int)); 74 73 if (bmp->pixels == NULL) { 75 74 free(bmp); … … 92 91 /* Copy pixels from font bitmap */ 93 92 94 for (y = 0; y < bmp->rect.p1.y; y++) { 95 for (x = 0; x < bmp->rect.p1.x; x++) { 96 pixel = pixelmap_get_pixel(&pmap, glyph->rect.p0.x + x, 97 glyph->rect.p0.y + y); 98 bmp->pixels[y * bmp->rect.p1.x + x] = 99 (pixel != 0) ? 1 : 0; 93 for (y = bmp->rect.p0.y; y < bmp->rect.p1.y; y++) { 94 for (x = bmp->rect.p0.x; x < bmp->rect.p1.x; x++) { 95 pixel = pixelmap_get_pixel(&pmap, glyph->origin.x + x, 96 glyph->origin.y + y); 97 bmp->pixels[(y - bmp->rect.p0.y) * 98 (bmp->rect.p1.x - bmp->rect.p0.x) + 99 (x - bmp->rect.p0.x)] = (pixel != 0) ? 1 : 0; 100 100 } 101 101 } … … 126 126 * is adjusted. 127 127 */ 128 rc = gfx_font_splice_at_glyph(font, glyph, 129 bmp->rect.p1.x - bmp->rect.p0.x, bmp->rect.p1.y - bmp->rect.p0.y); 128 rc = gfx_font_splice_at_glyph(font, glyph, &bmp->rect); 130 129 if (rc != EOK) 131 130 return rc; … … 143 142 /* Copy pixels to font bitmap */ 144 143 145 for (y = 0; y < bmp->rect.p1.y; y++) { 146 for (x = 0; x < bmp->rect.p1.x; x++) { 147 pixel = bmp->pixels[y * bmp->rect.p1.x + x] ? 144 for (y = bmp->rect.p0.y; y < bmp->rect.p1.y; y++) { 145 for (x = bmp->rect.p0.x; x < bmp->rect.p1.x; x++) { 146 pixel = bmp->pixels[(y - bmp->rect.p0.y) * 147 (bmp->rect.p1.x - bmp->rect.p0.x) + 148 (x - bmp->rect.p0.x)] ? 148 149 PIXEL(255, 255, 255, 255) : PIXEL(0, 0, 0, 0); 149 pixelmap_put_pixel(&pmap, glyph-> rect.p0.x + x,150 glyph-> rect.p0.y + y, pixel);150 pixelmap_put_pixel(&pmap, glyph->origin.x + x, 151 glyph->origin.y + y, pixel); 151 152 } 152 153 } … … 193 194 194 195 pitch = bmp->rect.p1.x - bmp->rect.p0.x; 196 195 197 return bmp->pixels[(y - bmp->rect.p0.y) * pitch + 196 198 (x - bmp->rect.p0.x)]; … … 214 216 pos.x = x; 215 217 pos.y = y; 218 216 219 if (!gfx_pix_inside_rect(&pos, &bmp->rect)) { 217 220 rc = gfx_glyph_bmp_extend(bmp, &pos); -
uspace/lib/gfxfont/test/font.c
r414020d9 r313ac8e 332 332 gfx_glyph_t *glyph; 333 333 gfx_context_t *gc; 334 gfx_rect_t nrect; 334 335 test_gc_t tgc; 335 336 errno_t rc; … … 350 351 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 351 352 352 rc = gfx_font_splice_at_glyph(font, glyph, 10, 10); 353 nrect.p0.x = -5; 354 nrect.p0.y = -5; 355 nrect.p1.x = 5; 356 nrect.p1.y = 5; 357 rc = gfx_font_splice_at_glyph(font, glyph, &nrect); 353 358 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 354 359 -
uspace/lib/gfxfont/test/glyph_bmp.c
r414020d9 r313ac8e 185 185 PCUT_ASSERT_INT_EQUALS(0, pix); 186 186 187 gfx_glyph_bmp_close(bmp); 187 /* ... */ 188 189 rc = gfx_glyph_bmp_setpix(bmp, 1, -1, 1); 190 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 191 192 rc = gfx_glyph_bmp_save(bmp); 193 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 194 195 gfx_glyph_bmp_close(bmp); 196 197 /* Once again */ 198 199 rc = gfx_glyph_bmp_open(glyph, &bmp); 200 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 201 PCUT_ASSERT_NOT_NULL(bmp); 202 203 pix = gfx_glyph_bmp_getpix(bmp, 0, 0); 204 PCUT_ASSERT_INT_EQUALS(1, pix); 205 206 pix = gfx_glyph_bmp_getpix(bmp, 1, 1); 207 PCUT_ASSERT_INT_EQUALS(1, pix); 208 209 pix = gfx_glyph_bmp_getpix(bmp, 1, 0); 210 PCUT_ASSERT_INT_EQUALS(0, pix); 211 212 pix = gfx_glyph_bmp_getpix(bmp, 0, 1); 213 PCUT_ASSERT_INT_EQUALS(0, pix); 214 215 pix = gfx_glyph_bmp_getpix(bmp, 1, -1); 216 PCUT_ASSERT_INT_EQUALS(1, pix); 217 218 pix = gfx_glyph_bmp_getpix(bmp, 0, -1); 219 PCUT_ASSERT_INT_EQUALS(0, pix); 220 188 221 gfx_glyph_destroy(glyph); 189 222
Note:
See TracChangeset
for help on using the changeset viewer.