Changeset 5c27e77 in mainline for uspace/lib


Ignore:
Timestamp:
2022-03-06T22:37:06Z (3 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

Location:
uspace/lib/gfxfont
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/gfxfont/include/types/gfx/text.h

    raf259da r5c27e77  
    11/*
    2  * Copyright (c) 2020 Jiri Svoboda
     2 * Copyright (c) 2022 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    3737#define _TYPES_GFX_TEXT_H
    3838
     39#include <stdbool.h>
    3940#include <types/gfx/coord.h>
    4041#include <types/gfx/color.h>
     
    7475        /** Vertical alignment */
    7576        gfx_valign_t valign;
     77        /** Underline */
     78        bool underline;
    7679} gfx_text_fmt_t;
    7780
  • uspace/lib/gfxfont/include/types/gfx/typeface.h

    raf259da r5c27e77  
    11/*
    2  * Copyright (c) 2020 Jiri Svoboda
     2 * Copyright (c) 2022 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    5050        /** Leading */
    5151        gfx_coord_t leading;
     52        /** Underline start Y coordinate (inclusive) */
     53        gfx_coord_t underline_y0;
     54        /** Underline end Y coordinate (exclusive) */
     55        gfx_coord_t underline_y1;
    5256} gfx_font_metrics_t;
    5357
  • uspace/lib/gfxfont/private/tpf_file.h

    raf259da r5c27e77  
    11/*
    2  * Copyright (c) 2020 Jiri Svoboda
     2 * Copyright (c) 2022 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    7676        uint16_t descent;
    7777        uint16_t leading;
     78        int16_t underline_y0;
     79        int16_t underline_y1;
    7880} tpf_font_metrics_t;
    7981
  • uspace/lib/gfxfont/src/font.c

    raf259da r5c27e77  
    11/*
    2  * Copyright (c) 2020 Jiri Svoboda
     2 * Copyright (c) 2022 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    546546        metrics->descent = uint16_t_le2host(tmetrics.descent);
    547547        metrics->leading = uint16_t_le2host(tmetrics.leading);
     548        metrics->underline_y0 = uint16_t_le2host(tmetrics.underline_y0);
     549        metrics->underline_y1 = uint16_t_le2host(tmetrics.underline_y1);
    548550        return EOK;
    549551}
     
    565567        tmetrics.descent = host2uint16_t_le(metrics->descent);
    566568        tmetrics.leading = host2uint16_t_le(metrics->leading);
     569        tmetrics.underline_y0 = host2uint16_t_le(metrics->underline_y0);
     570        tmetrics.underline_y1 = host2uint16_t_le(metrics->underline_y1);
    567571
    568572        rc = riff_wchunk_start(riffw, CKID_fmtr, &mtrck);
  • 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.