Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset 794e368 in mainline


Ignore:
Timestamp:
2014-08-28T13:55:26Z (7 years ago)
Author:
Martin Sucha <sucha14@…>
Branches:
lfn, master
Children:
c6c39d4f
Parents:
a9763c6
Message:

Fix scaling of bitmap fonts.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/draw/font/bitmap_backend.c

    ra9763c6 r794e368  
    136136        surface_get_resolution(raw_surface, &w, &h);
    137137       
    138         if (h == data->points) {
     138        if (!data->scale) {
    139139                *result = raw_surface;
    140140                return EOK;
     
    147147        transform_t transform;
    148148        transform_identity(&transform);
    149         double ratio = ((double) data->points) / ((double) h);
    150         transform_scale(&transform, ratio, ratio);
     149        transform_translate(&transform, 0.5, 0.5);
     150        transform_scale(&transform, data->scale_ratio, data->scale_ratio);
    151151        source_set_transform(&source, transform);
    152152
    153         double width = w;
    154         double height = h;
    155         transform_apply_linear(&transform, &width, &height);
    156         surface_t *scaled_surface =
    157             surface_create((sysarg_t) (width + 0.5), (sysarg_t) (height + 0.5), NULL, 0);
     153        surface_coord_t scaled_width = (data->scale_ratio * ((double) w) + 0.5);
     154        surface_coord_t scaled_height = (data->scale_ratio * ((double) h) + 0.5);
     155
     156        surface_t *scaled_surface = surface_create(scaled_width, scaled_height,
     157            NULL, 0);
    158158        if (!scaled_surface) {
    159159                surface_destroy(raw_surface);
     
    164164        drawctx_init(&context, scaled_surface);
    165165        drawctx_set_source(&context, &source);
    166         drawctx_transfer(&context, 0, 0,
    167             (sysarg_t) (width + 0.5), (sysarg_t) (height + 0.5));
     166        drawctx_transfer(&context, 0, 0, scaled_width, scaled_height);
    168167
    169168        surface_destroy(raw_surface);
     
    249248                data->scale = true;
    250249                data->scale_ratio = ((double) points) / ((double) line_height);
     250                line_height = (data->scale_ratio * ((double) line_height));
    251251                data->font_metrics.ascender = (metric_t)
    252252                    (data->scale_ratio * data->font_metrics.ascender + 0.5);
    253                 data->font_metrics.descender = (metric_t)
    254                     (data->scale_ratio * data->font_metrics.descender - 0.5);
     253                data->font_metrics.descender =
     254                    line_height - data->font_metrics.ascender;
    255255                data->font_metrics.leading = (metric_t)
    256256                    (data->scale_ratio * data->font_metrics.leading + 0.5);
Note: See TracChangeset for help on using the changeset viewer.