Changes in uspace/lib/gfxfont/src/text.c [4583015:f2d4a46] in mainline
- File:
-
- 1 edited
-
uspace/lib/gfxfont/src/text.c (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/gfxfont/src/text.c
r4583015 rf2d4a46 97 97 /** Print string using text characters in text mode. 98 98 * 99 * @param font Font100 99 * @param pos Position of top-left corner of text 101 * @param color Text color100 * @param fmt Formatting 102 101 * @param str String 103 102 * @return EOK on success or an error code 104 103 */ 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 = f ont->typeface->gc;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 = fmt->font->typeface->gc; 109 108 gfx_bitmap_params_t params; 110 109 gfx_bitmap_t *bitmap; 111 110 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; 115 116 pixel_t pixel; 116 117 char32_t c; 117 118 size_t off; 119 bool ellipsis; 118 120 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 else 129 rmargin = width; 130 } else { 131 ellipsis = false; 132 rmargin = width; 133 } 119 134 120 135 /* … … 123 138 */ 124 139 125 gfx_color_get_ega( color, &attr);140 gfx_color_get_ega(fmt->color, &attr); 126 141 127 142 gfx_bitmap_params_init(¶ms); 128 143 params.rect.p0.x = 0; 129 144 params.rect.p0.y = 0; 130 params.rect.p1.x = str_width(str);145 params.rect.p1.x = width; 131 146 params.rect.p1.y = 1; 132 147 … … 151 166 152 167 off = 0; 153 for (x = 0; x < params.rect.p1.x; x++) {168 for (x = 0; x < rmargin; x++) { 154 169 c = str_decode(str, &off, STR_NO_LIMIT); 155 170 pixel = PIXEL(attr, … … 160 175 } 161 176 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 162 188 rc = gfx_bitmap_render(bitmap, NULL, pos); 163 189 … … 183 209 /* Adjust position for horizontal alignment */ 184 210 if (fmt->halign != gfx_halign_left) { 211 /* Compute text width */ 185 212 width = gfx_text_width(fmt->font, str); 213 if (fmt->abbreviate && width > fmt->width) 214 width = fmt->width; 215 186 216 switch (fmt->halign) { 187 217 case gfx_halign_center: … … 233 263 gfx_coord2_t spos; 234 264 gfx_rect_t rect; 265 gfx_coord_t width; 266 gfx_coord_t rmargin; 267 bool ellipsis; 235 268 errno_t rc; 236 269 … … 239 272 /* Text mode */ 240 273 if ((fmt->font->finfo->props.flags & gff_text_mode) != 0) 241 return gfx_puttext_textmode( fmt->font, &spos, fmt->color, str);274 return gfx_puttext_textmode(&spos, fmt, str); 242 275 243 276 rc = gfx_set_color(fmt->font->typeface->gc, fmt->color); 244 277 if (rc != EOK) 245 278 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 } 246 290 247 291 cpos = spos; … … 256 300 gfx_glyph_get_metrics(glyph, &gmetrics); 257 301 302 /* Stop if we would run over the right margin */ 303 if (fmt->abbreviate && cpos.x + gmetrics.advance > rmargin) 304 break; 305 258 306 rc = gfx_glyph_render(glyph, &cpos); 259 307 if (rc != EOK) … … 274 322 275 323 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); 276 349 if (rc != EOK) 277 350 return rc; … … 376 449 tfmt.valign = gfx_valign_baseline; 377 450 451 /* Remaining available width */ 452 tfmt.width = fmt->width - (cpos->x - spos.x); 453 378 454 *cfmt = tfmt; 379 455 } … … 390 466 { 391 467 gfx_coord2_t spos; 468 gfx_coord_t width; 392 469 393 470 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; 394 474 395 475 rect->p0.x = spos.x; 396 476 rect->p0.y = spos.y - fmt->font->metrics.ascent; 397 rect->p1.x = spos.x + gfx_text_width(fmt->font, str);477 rect->p1.x = spos.x + width; 398 478 rect->p1.y = spos.y + fmt->font->metrics.descent + 1; 399 479 }
Note:
See TracChangeset
for help on using the changeset viewer.
