Changeset a130983 in mainline for uspace/lib/gfxfont/src/text.c
- Timestamp:
- 2022-11-17T19:56:07Z (23 months ago)
- Branches:
- master, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 901b302
- Parents:
- 5d62130
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/gfxfont/src/text.c
r5d62130 ra130983 183 183 /* Adjust position for horizontal alignment */ 184 184 if (fmt->halign != gfx_halign_left) { 185 /* Compute text width */ 185 186 width = gfx_text_width(fmt->font, str); 187 if (fmt->abbreviate && width > fmt->width) 188 width = fmt->width; 189 186 190 switch (fmt->halign) { 187 191 case gfx_halign_center: … … 233 237 gfx_coord2_t spos; 234 238 gfx_rect_t rect; 239 gfx_coord_t width; 240 gfx_coord_t rmargin; 241 bool ellipsis; 235 242 errno_t rc; 236 243 … … 244 251 if (rc != EOK) 245 252 return rc; 253 254 width = gfx_text_width(fmt->font, str); 255 256 if (fmt->abbreviate && width > fmt->width) { 257 /* Need to append ellipsis */ 258 ellipsis = true; 259 rmargin = spos.x + fmt->width - gfx_text_width(fmt->font, "..."); 260 } else { 261 ellipsis = false; 262 rmargin = spos.x + width; 263 } 246 264 247 265 cpos = spos; … … 256 274 gfx_glyph_get_metrics(glyph, &gmetrics); 257 275 276 /* Stop if we would run over the right margin */ 277 if (fmt->abbreviate && cpos.x + gmetrics.advance > rmargin) 278 break; 279 258 280 rc = gfx_glyph_render(glyph, &cpos); 259 281 if (rc != EOK) … … 274 296 275 297 rc = gfx_fill_rect(fmt->font->typeface->gc, &rect); 298 if (rc != EOK) 299 return rc; 300 } 301 302 /* Render ellipsis, if required */ 303 if (ellipsis) { 304 rc = gfx_font_search_glyph(fmt->font, ".", &glyph, &stradv); 305 if (rc != EOK) 306 return EOK; 307 308 gfx_glyph_get_metrics(glyph, &gmetrics); 309 310 rc = gfx_glyph_render(glyph, &cpos); 311 if (rc != EOK) 312 return rc; 313 314 cpos.x += gmetrics.advance; 315 316 rc = gfx_glyph_render(glyph, &cpos); 317 if (rc != EOK) 318 return rc; 319 320 cpos.x += gmetrics.advance; 321 322 rc = gfx_glyph_render(glyph, &cpos); 276 323 if (rc != EOK) 277 324 return rc; … … 376 423 tfmt.valign = gfx_valign_baseline; 377 424 425 /* Remaining available width */ 426 tfmt.width = fmt->width - (cpos->x - spos.x); 427 378 428 *cfmt = tfmt; 379 429 } … … 390 440 { 391 441 gfx_coord2_t spos; 442 gfx_coord_t width; 392 443 393 444 gfx_text_start_pos(pos, fmt, str, &spos); 445 width = gfx_text_width(fmt->font, str); 446 if (fmt->abbreviate && width > fmt->width) 447 width = fmt->width; 394 448 395 449 rect->p0.x = spos.x; 396 450 rect->p0.y = spos.y - fmt->font->metrics.ascent; 397 rect->p1.x = spos.x + gfx_text_width(fmt->font, str);451 rect->p1.x = spos.x + width; 398 452 rect->p1.y = spos.y + fmt->font->metrics.descent + 1; 399 453 }
Note:
See TracChangeset
for help on using the changeset viewer.