Changeset 5c27e77 in mainline


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

Location:
uspace
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/fontedit/fontedit.c

    raf259da r5c27e77  
    11/*
    2  * Copyright (c) 2020 Jiri Svoboda
     2 * Copyright (c) 2022 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    167167}
    168168
     169/** Adjust font underline Y0.
     170 *
     171 * @param fedit Font editor
     172 */
     173static void font_edit_adjust_underline_y0(font_edit_t *fedit,
     174    gfx_coord_t change)
     175{
     176        gfx_font_metrics_t fmetrics;
     177
     178        gfx_font_get_metrics(fedit->font, &fmetrics);
     179        fmetrics.underline_y0 += change;
     180        (void) gfx_font_set_metrics(fedit->font, &fmetrics);
     181
     182        printf("New underline Y0: %d\n", fmetrics.underline_y0);
     183        font_edit_paint(fedit);
     184}
     185
     186/** Adjust font underline Y1.
     187 *
     188 * @param fedit Font editor
     189 */
     190static void font_edit_adjust_underline_y1(font_edit_t *fedit,
     191    gfx_coord_t change)
     192{
     193        gfx_font_metrics_t fmetrics;
     194
     195        gfx_font_get_metrics(fedit->font, &fmetrics);
     196        fmetrics.underline_y1 += change;
     197        (void) gfx_font_set_metrics(fedit->font, &fmetrics);
     198
     199        printf("New underline Y1: %d\n", fmetrics.underline_y1);
     200        font_edit_paint(fedit);
     201}
     202
    169203/** Handle font editor close event.
    170204 *
     
    314348                font_edit_adjust_leading(fedit, +1);
    315349                break;
     350        case KC_U:
     351                font_edit_adjust_underline_y0(fedit, -1);
     352                break;
     353        case KC_I:
     354                font_edit_adjust_underline_y0(fedit, +1);
     355                break;
     356        case KC_O:
     357                font_edit_adjust_underline_y1(fedit, -1);
     358                break;
     359        case KC_P:
     360                font_edit_adjust_underline_y1(fedit, +1);
     361                break;
    316362        case KC_X:
    317363                (void) gfx_glyph_bmp_clear(fedit->gbmp);
     
    521567        gfx_color_t *color = NULL;
    522568        gfx_rect_t rect;
     569        gfx_rect_t rect2;
    523570        gfx_rect_t grect;
    524571        gfx_font_metrics_t fmetrics;
     
    564611            fmetrics.leading, &rect);
    565612        rect.p1.x += 100;
     613
     614        rc = gfx_fill_rect(fedit->gc, &rect);
     615        if (rc != EOK)
     616                goto error;
     617
     618        gfx_color_delete(color);
     619
     620        /* Display underline */
     621
     622        rc = gfx_color_new_rgb_i16(0x4000, 0x4000, 0, &color);
     623        if (rc != EOK)
     624                goto error;
     625
     626        rc = gfx_set_color(fedit->gc, color);
     627        if (rc != EOK)
     628                goto error;
     629
     630        font_edit_gpix_to_disp(fedit, 0, fmetrics.underline_y0, &rect);
     631        font_edit_gpix_to_disp(fedit, 10, fmetrics.underline_y1, &rect2);
     632        rect.p1 = rect2.p0;
    566633
    567634        rc = gfx_fill_rect(fedit->gc, &rect);
  • uspace/app/gfxdemo/gfxdemo.c

    raf259da r5c27e77  
    11/*
    2  * Copyright (c) 2021 Jiri Svoboda
     2 * Copyright (c) 2022 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    776776
    777777                fmt.color = color;
     778                fmt.underline = !fmt.underline;
    778779
    779780                pos.x = w / 20;
  • 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.