Changeset 5c27e77 in mainline for uspace/lib/gfxfont/src/text.c


Ignore:
Timestamp:
2022-03-06T22:37:06Z (2 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
master, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
4583015
Parents:
af259da
Message:

Text underlining support

File:
1 edited

Legend:

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

    raf259da r5c27e77  
    11/*
    2  * Copyright (c) 2021 Jiri Svoboda
     2 * Copyright (c) 2022 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    229229{
    230230        gfx_glyph_metrics_t gmetrics;
     231        gfx_font_metrics_t fmetrics;
    231232        size_t stradv;
    232233        const char *cp;
    233234        gfx_glyph_t *glyph;
    234235        gfx_coord2_t cpos;
     236        gfx_coord2_t spos;
     237        gfx_rect_t rect;
    235238        errno_t rc;
    236239
    237         gfx_text_start_pos(font, pos, fmt, str, &cpos);
     240        gfx_text_start_pos(font, pos, fmt, str, &spos);
    238241
    239242        /* Text mode */
    240243        if ((font->finfo->props.flags & gff_text_mode) != 0)
    241                 return gfx_puttext_textmode(font, &cpos, fmt->color, str);
     244                return gfx_puttext_textmode(font, &spos, fmt->color, str);
    242245
    243246        rc = gfx_set_color(font->typeface->gc, fmt->color);
     
    245248                return rc;
    246249
     250        cpos = spos;
    247251        cp = str;
    248252        while (*cp != '\0') {
     
    261265                cp += stradv;
    262266                cpos.x += gmetrics.advance;
     267        }
     268
     269        /* Text underlining */
     270        if (fmt->underline) {
     271                gfx_font_get_metrics(font, &fmetrics);
     272
     273                rect.p0.x = spos.x;
     274                rect.p0.y = spos.y + fmetrics.underline_y0;
     275                rect.p1.x = cpos.x;
     276                rect.p1.y = spos.y + fmetrics.underline_y1;
     277
     278                rc = gfx_fill_rect(font->typeface->gc, &rect);
     279                if (rc != EOK)
     280                        return rc;
    263281        }
    264282
Note: See TracChangeset for help on using the changeset viewer.