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


Ignore:
Timestamp:
2022-03-07T16:10:44Z (3 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
master, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
ca2680d
Parents:
5c27e77
Message:

Add font to gfx_text_fmt_t

This is quite logical and saves us one argument that we need to pass to
all text formatting functions.

File:
1 edited

Legend:

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

    r5c27e77 r4583015  
    168168/** Get text starting position.
    169169 *
    170  * @param font Font
    171170 * @param pos Anchor position
    172171 * @param fmt Text formatting
     
    174173 * @param spos Place to store starting position
    175174 */
    176 void gfx_text_start_pos(gfx_font_t *font, gfx_coord2_t *pos,
    177     gfx_text_fmt_t *fmt, const char *str, gfx_coord2_t *spos)
     175void gfx_text_start_pos(gfx_coord2_t *pos, gfx_text_fmt_t *fmt,
     176    const char *str, gfx_coord2_t *spos)
    178177{
    179178        gfx_font_metrics_t fmetrics;
     
    184183        /* Adjust position for horizontal alignment */
    185184        if (fmt->halign != gfx_halign_left) {
    186                 width = gfx_text_width(font, str);
     185                width = gfx_text_width(fmt->font, str);
    187186                switch (fmt->halign) {
    188187                case gfx_halign_center:
     
    198197
    199198        /* Adjust position for vertical alignment */
    200         gfx_font_get_metrics(font, &fmetrics);
     199        gfx_font_get_metrics(fmt->font, &fmetrics);
    201200
    202201        if (fmt->valign != gfx_valign_baseline) {
     
    219218/** Render text.
    220219 *
    221  * @param font Font
    222220 * @param pos Anchor position
    223221 * @param fmt Text formatting
     
    225223 * @return EOK on success or an error code
    226224 */
    227 errno_t gfx_puttext(gfx_font_t *font, gfx_coord2_t *pos,
    228     gfx_text_fmt_t *fmt, const char *str)
     225errno_t gfx_puttext(gfx_coord2_t *pos, gfx_text_fmt_t *fmt, const char *str)
    229226{
    230227        gfx_glyph_metrics_t gmetrics;
     
    238235        errno_t rc;
    239236
    240         gfx_text_start_pos(font, pos, fmt, str, &spos);
     237        gfx_text_start_pos(pos, fmt, str, &spos);
    241238
    242239        /* Text mode */
    243         if ((font->finfo->props.flags & gff_text_mode) != 0)
    244                 return gfx_puttext_textmode(font, &spos, fmt->color, str);
    245 
    246         rc = gfx_set_color(font->typeface->gc, fmt->color);
     240        if ((fmt->font->finfo->props.flags & gff_text_mode) != 0)
     241                return gfx_puttext_textmode(fmt->font, &spos, fmt->color, str);
     242
     243        rc = gfx_set_color(fmt->font->typeface->gc, fmt->color);
    247244        if (rc != EOK)
    248245                return rc;
     
    251248        cp = str;
    252249        while (*cp != '\0') {
    253                 rc = gfx_font_search_glyph(font, cp, &glyph, &stradv);
     250                rc = gfx_font_search_glyph(fmt->font, cp, &glyph, &stradv);
    254251                if (rc != EOK) {
    255252                        ++cp;
     
    269266        /* Text underlining */
    270267        if (fmt->underline) {
    271                 gfx_font_get_metrics(font, &fmetrics);
     268                gfx_font_get_metrics(fmt->font, &fmetrics);
    272269
    273270                rect.p0.x = spos.x;
     
    276273                rect.p1.y = spos.y + fmetrics.underline_y1;
    277274
    278                 rc = gfx_fill_rect(font->typeface->gc, &rect);
     275                rc = gfx_fill_rect(fmt->font->typeface->gc, &rect);
    279276                if (rc != EOK)
    280277                        return rc;
     
    286283/** Find character position in string by X coordinate.
    287284 *
    288  * @param font Font
    289285 * @param pos Anchor position
    290286 * @param fmt Text formatting
     
    298294 *         offset of the following character.
    299295 */
    300 size_t gfx_text_find_pos(gfx_font_t *font, gfx_coord2_t *pos,
    301     gfx_text_fmt_t *fmt, const char *str, gfx_coord2_t *fpos)
     296size_t gfx_text_find_pos(gfx_coord2_t *pos, gfx_text_fmt_t *fmt,
     297    const char *str, gfx_coord2_t *fpos)
    302298{
    303299        gfx_glyph_metrics_t gmetrics;
     
    310306        errno_t rc;
    311307
    312         gfx_text_start_pos(font, pos, fmt, str, &cpos);
     308        gfx_text_start_pos(pos, fmt, str, &cpos);
    313309
    314310        /* Text mode */
    315         if ((font->finfo->props.flags & gff_text_mode) != 0) {
     311        if ((fmt->font->finfo->props.flags & gff_text_mode) != 0) {
    316312                off = 0;
    317313                strsize = str_size(str);
     
    329325        off = 0;
    330326        while (*cp != '\0') {
    331                 rc = gfx_font_search_glyph(font, cp, &glyph, &stradv);
     327                rc = gfx_font_search_glyph(fmt->font, cp, &glyph, &stradv);
    332328                if (rc != EOK) {
    333329                        ++cp;
     
    355351 * to the same objects, respectively.
    356352 *
    357  * @param font Font
    358353 * @param pos Anchor position
    359354 * @param fmt Text formatting
     
    362357 * @param cfmt Place to store format for continuation
    363358 */
    364 void gfx_text_cont(gfx_font_t *font, gfx_coord2_t *pos,
    365     gfx_text_fmt_t *fmt, const char *str, gfx_coord2_t *cpos,
    366     gfx_text_fmt_t *cfmt)
     359void gfx_text_cont(gfx_coord2_t *pos, gfx_text_fmt_t *fmt, const char *str,
     360    gfx_coord2_t *cpos, gfx_text_fmt_t *cfmt)
    367361{
    368362        gfx_coord2_t spos;
     
    370364
    371365        /* Continuation should start where the current string ends */
    372         gfx_text_start_pos(font, pos, fmt, str, &spos);
    373         cpos->x = spos.x + gfx_text_width(font, str);
     366        gfx_text_start_pos(pos, fmt, str, &spos);
     367        cpos->x = spos.x + gfx_text_width(fmt->font, str);
    374368        cpos->y = spos.y;
    375369
     
    387381/** Get text bounding rectangle.
    388382 *
    389  * @param font Font
    390383 * @param pos Anchor position
    391384 * @param fmt Text formatting
     
    393386 * @param rect Place to store bounding rectangle
    394387 */
    395 void gfx_text_rect(gfx_font_t *font, gfx_coord2_t *pos,
    396     gfx_text_fmt_t *fmt, const char *str, gfx_rect_t *rect)
     388void gfx_text_rect(gfx_coord2_t *pos, gfx_text_fmt_t *fmt, const char *str,
     389    gfx_rect_t *rect)
    397390{
    398391        gfx_coord2_t spos;
    399392
    400         gfx_text_start_pos(font, pos, fmt, str, &spos);
     393        gfx_text_start_pos(pos, fmt, str, &spos);
    401394
    402395        rect->p0.x = spos.x;
    403         rect->p0.y = spos.y - font->metrics.ascent;
    404         rect->p1.x = spos.x + gfx_text_width(font, str);
    405         rect->p1.y = spos.y + font->metrics.descent + 1;
     396        rect->p0.y = spos.y - fmt->font->metrics.ascent;
     397        rect->p1.x = spos.x + gfx_text_width(fmt->font, str);
     398        rect->p1.y = spos.y +  fmt->font->metrics.descent + 1;
    406399}
    407400
Note: See TracChangeset for help on using the changeset viewer.