Changes in uspace/lib/gfxfont/src/text.c [f2d4a46:4583015] in mainline
- File:
-
- 1 edited
-
uspace/lib/gfxfont/src/text.c (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/gfxfont/src/text.c
rf2d4a46 r4583015 97 97 /** Print string using text characters in text mode. 98 98 * 99 * @param font Font 99 100 * @param pos Position of top-left corner of text 100 * @param fmt Formatting101 * @param color Text color 101 102 * @param str String 102 103 * @return EOK on success or an error code 103 104 */ 104 static errno_t gfx_puttext_textmode(gfx_ coord2_t *pos, gfx_text_fmt_t *fmt,105 const char *str)106 { 107 gfx_context_t *gc = f mt->font->typeface->gc;105 static errno_t gfx_puttext_textmode(gfx_font_t *font, gfx_coord2_t *pos, 106 gfx_color_t *color, const char *str) 107 { 108 gfx_context_t *gc = font->typeface->gc; 108 109 gfx_bitmap_params_t params; 109 110 gfx_bitmap_t *bitmap; 110 111 gfx_bitmap_alloc_t alloc; 111 gfx_coord_t width;112 112 uint8_t attr; 113 113 pixelmap_t pmap; 114 114 gfx_coord_t x; 115 gfx_coord_t rmargin;116 115 pixel_t pixel; 117 116 char32_t c; 118 117 size_t off; 119 bool ellipsis;120 118 errno_t rc; 121 122 width = str_width(str);123 if (fmt->abbreviate && width > fmt->width) {124 ellipsis = true;125 width = fmt->width;126 if (width > 3)127 rmargin = width - 3;128 else129 rmargin = width;130 } else {131 ellipsis = false;132 rmargin = width;133 }134 119 135 120 /* … … 138 123 */ 139 124 140 gfx_color_get_ega( fmt->color, &attr);125 gfx_color_get_ega(color, &attr); 141 126 142 127 gfx_bitmap_params_init(¶ms); 143 128 params.rect.p0.x = 0; 144 129 params.rect.p0.y = 0; 145 params.rect.p1.x = width;130 params.rect.p1.x = str_width(str); 146 131 params.rect.p1.y = 1; 147 132 … … 166 151 167 152 off = 0; 168 for (x = 0; x < rmargin; x++) {153 for (x = 0; x < params.rect.p1.x; x++) { 169 154 c = str_decode(str, &off, STR_NO_LIMIT); 170 155 pixel = PIXEL(attr, … … 175 160 } 176 161 177 if (ellipsis) {178 for (x = rmargin; x < params.rect.p1.x; x++) {179 c = '.';180 pixel = PIXEL(attr,181 (c >> 16) & 0xff,182 (c >> 8) & 0xff,183 c & 0xff);184 pixelmap_put_pixel(&pmap, x, 0, pixel);185 }186 }187 188 162 rc = gfx_bitmap_render(bitmap, NULL, pos); 189 163 … … 209 183 /* Adjust position for horizontal alignment */ 210 184 if (fmt->halign != gfx_halign_left) { 211 /* Compute text width */212 185 width = gfx_text_width(fmt->font, str); 213 if (fmt->abbreviate && width > fmt->width)214 width = fmt->width;215 216 186 switch (fmt->halign) { 217 187 case gfx_halign_center: … … 263 233 gfx_coord2_t spos; 264 234 gfx_rect_t rect; 265 gfx_coord_t width;266 gfx_coord_t rmargin;267 bool ellipsis;268 235 errno_t rc; 269 236 … … 272 239 /* Text mode */ 273 240 if ((fmt->font->finfo->props.flags & gff_text_mode) != 0) 274 return gfx_puttext_textmode( &spos, fmt, str);241 return gfx_puttext_textmode(fmt->font, &spos, fmt->color, str); 275 242 276 243 rc = gfx_set_color(fmt->font->typeface->gc, fmt->color); 277 244 if (rc != EOK) 278 245 return rc; 279 280 width = gfx_text_width(fmt->font, str);281 282 if (fmt->abbreviate && width > fmt->width) {283 /* Need to append ellipsis */284 ellipsis = true;285 rmargin = spos.x + fmt->width - gfx_text_width(fmt->font, "...");286 } else {287 ellipsis = false;288 rmargin = spos.x + width;289 }290 246 291 247 cpos = spos; … … 300 256 gfx_glyph_get_metrics(glyph, &gmetrics); 301 257 302 /* Stop if we would run over the right margin */303 if (fmt->abbreviate && cpos.x + gmetrics.advance > rmargin)304 break;305 306 258 rc = gfx_glyph_render(glyph, &cpos); 307 259 if (rc != EOK) … … 322 274 323 275 rc = gfx_fill_rect(fmt->font->typeface->gc, &rect); 324 if (rc != EOK)325 return rc;326 }327 328 /* Render ellipsis, if required */329 if (ellipsis) {330 rc = gfx_font_search_glyph(fmt->font, ".", &glyph, &stradv);331 if (rc != EOK)332 return EOK;333 334 gfx_glyph_get_metrics(glyph, &gmetrics);335 336 rc = gfx_glyph_render(glyph, &cpos);337 if (rc != EOK)338 return rc;339 340 cpos.x += gmetrics.advance;341 342 rc = gfx_glyph_render(glyph, &cpos);343 if (rc != EOK)344 return rc;345 346 cpos.x += gmetrics.advance;347 348 rc = gfx_glyph_render(glyph, &cpos);349 276 if (rc != EOK) 350 277 return rc; … … 449 376 tfmt.valign = gfx_valign_baseline; 450 377 451 /* Remaining available width */452 tfmt.width = fmt->width - (cpos->x - spos.x);453 454 378 *cfmt = tfmt; 455 379 } … … 466 390 { 467 391 gfx_coord2_t spos; 468 gfx_coord_t width;469 392 470 393 gfx_text_start_pos(pos, fmt, str, &spos); 471 width = gfx_text_width(fmt->font, str);472 if (fmt->abbreviate && width > fmt->width)473 width = fmt->width;474 394 475 395 rect->p0.x = spos.x; 476 396 rect->p0.y = spos.y - fmt->font->metrics.ascent; 477 rect->p1.x = spos.x + width;397 rect->p1.x = spos.x + gfx_text_width(fmt->font, str); 478 398 rect->p1.y = spos.y + fmt->font->metrics.descent + 1; 479 399 }
Note:
See TracChangeset
for help on using the changeset viewer.
