Changeset f2d4a46 in mainline


Ignore:
Timestamp:
2022-11-18T20:00:57Z (18 months ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
master, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
d19d15b
Parents:
901b302
Message:

Abbreviation in text mode

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/gfxfont/src/text.c

    r901b302 rf2d4a46  
    9797/** Print string using text characters in text mode.
    9898 *
    99  * @param font Font
    10099 * @param pos Position of top-left corner of text
    101  * @param color Text color
     100 * @param fmt Formatting
    102101 * @param str String
    103102 * @return EOK on success or an error code
    104103 */
    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;
     104static 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;
    109108        gfx_bitmap_params_t params;
    110109        gfx_bitmap_t *bitmap;
    111110        gfx_bitmap_alloc_t alloc;
     111        gfx_coord_t width;
    112112        uint8_t attr;
    113113        pixelmap_t pmap;
    114114        gfx_coord_t x;
     115        gfx_coord_t rmargin;
    115116        pixel_t pixel;
    116117        char32_t c;
    117118        size_t off;
     119        bool ellipsis;
    118120        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        }
    119134
    120135        /*
     
    123138         */
    124139
    125         gfx_color_get_ega(color, &attr);
     140        gfx_color_get_ega(fmt->color, &attr);
    126141
    127142        gfx_bitmap_params_init(&params);
    128143        params.rect.p0.x = 0;
    129144        params.rect.p0.y = 0;
    130         params.rect.p1.x = str_width(str);
     145        params.rect.p1.x = width;
    131146        params.rect.p1.y = 1;
    132147
     
    151166
    152167        off = 0;
    153         for (x = 0; x < params.rect.p1.x; x++) {
     168        for (x = 0; x < rmargin; x++) {
    154169                c = str_decode(str, &off, STR_NO_LIMIT);
    155170                pixel = PIXEL(attr,
     
    158173                    c & 0xff);
    159174                pixelmap_put_pixel(&pmap, x, 0, pixel);
     175        }
     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                }
    160186        }
    161187
     
    246272        /* Text mode */
    247273        if ((fmt->font->finfo->props.flags & gff_text_mode) != 0)
    248                 return gfx_puttext_textmode(fmt->font, &spos, fmt->color, str);
     274                return gfx_puttext_textmode(&spos, fmt, str);
    249275
    250276        rc = gfx_set_color(fmt->font->typeface->gc, fmt->color);
Note: See TracChangeset for help on using the changeset viewer.