Changes in / [5713e5f:a4666a9] in mainline


Ignore:
Files:
6 deleted
26 edited

Legend:

Unmodified
Added
Removed
  • .bzrignore

    r5713e5f ra4666a9  
    2828uspace/app/dnsres/dnsres
    2929uspace/app/edit/edit
    30 uspace/app/fontviewer/fontviewer
    3130uspace/app/getterm/getterm
    3231uspace/app/inet/inet
     
    8079uspace/dist/app/dnsres
    8180uspace/dist/app/edit
    82 uspace/dist/app/fontviewer
    8381uspace/dist/app/getterm
    8482uspace/dist/app/inet
  • boot/Makefile.common

    r5713e5f ra4666a9  
    218218        $(USPACE_PATH)/app/vdemo/vdemo \
    219219        $(USPACE_PATH)/app/viewer/viewer \
    220         $(USPACE_PATH)/app/df/df \
    221         $(USPACE_PATH)/app/fontviewer/fontviewer
     220        $(USPACE_PATH)/app/df/df
    222221
    223222COMPONENTS = \
  • uspace/Makefile

    r5713e5f ra4666a9  
    4444        app/download \
    4545        app/edit \
    46         app/fontviewer \
    4746        app/getterm \
    4847        app/hdisk \
  • uspace/lib/c/generic/io/asprintf.c

    r5713e5f ra4666a9  
    7676 *             the newly allocated string.
    7777 * @fmt        Format string.
    78  * @args       Variable argument list
    79  *
    80  * @return Number of characters printed or a negative error code.
    81  *
    82  */
    83 int vasprintf(char **strp, const char *fmt, va_list args)
    84 {
    85         va_list args2;
    86         va_copy(args2, args);
    87         int ret = vprintf_size(fmt, args2);
    88         va_end(args2);
    89        
    90         if (ret > 0) {
    91                 *strp = malloc(STR_BOUNDS(ret) + 1);
    92                 if (*strp == NULL)
    93                         return -1;
    94                
    95                 vsnprintf(*strp, STR_BOUNDS(ret) + 1, fmt, args);
    96         }
    97        
    98         return ret;
    99 }
    100 
    101 /** Allocate and print to string.
    102  *
    103  * @param strp Address of the pointer where to store the address of
    104  *             the newly allocated string.
    105  * @fmt        Format string.
    10678 *
    10779 * @return Number of characters printed or a negative error code.
     
    11284        va_list args;
    11385        va_start(args, fmt);
    114         int ret = vasprintf(strp, fmt, args);
     86        int ret = vprintf_size(fmt, args);
    11587        va_end(args);
     88       
     89        if (ret > 0) {
     90                *strp = malloc(STR_BOUNDS(ret) + 1);
     91                if (*strp == NULL)
     92                        return -1;
     93               
     94                va_start(args, fmt);
     95                vsnprintf(*strp, STR_BOUNDS(ret) + 1, fmt, args);
     96                va_end(args);
     97        }
    11698       
    11799        return ret;
  • uspace/lib/c/include/io/pixelmap.h

    r5713e5f ra4666a9  
    11/*
    22 * Copyright (c) 2011 Petr Koupy
    3  * Copyright (c) 2014 Martin Sucha
    43 * All rights reserved.
    54 *
     
    4140#include <unistd.h>
    4241#include <io/pixel.h>
    43 
    44 /* Defines how a pixel outside of pixmap rectangle shall be treated */
    45 typedef enum {
    46         /* Pixels outside of a pixmap are PIXEL(0, 0, 0, 0) */
    47         PIXELMAP_EXTEND_TRANSPARENT_BLACK = 0,
    48        
    49         /* The pixmap is repeated infinetely */
    50         PIXELMAP_EXTEND_TILE,
    51        
    52         /* If outside of a pixmap, return closest pixel from the edge */
    53         PIXELMAP_EXTEND_SIDES,
    54        
    55         /* If outside of a pixmap, return closest pixel from the edge,
    56          * with alpha = 0
    57          */
    58         PIXELMAP_EXTEND_TRANSPARENT_SIDES
    59 } pixelmap_extend_t;
    6042
    6143typedef struct {
     
    10486}
    10587
    106 static inline pixel_t pixelmap_get_extended_pixel(pixelmap_t *pixmap,
    107     native_t x, native_t y, pixelmap_extend_t extend)
    108 {
    109         bool transparent = false;
    110         if (extend == PIXELMAP_EXTEND_TILE) {
    111                 x %= pixmap->width;
    112                 y %= pixmap->height;
    113         }
    114         else if (extend == PIXELMAP_EXTEND_SIDES ||
    115             extend == PIXELMAP_EXTEND_TRANSPARENT_SIDES) {
    116                 bool transparent_outside =
    117                     (extend == PIXELMAP_EXTEND_TRANSPARENT_SIDES);
    118                 if (x < 0) {
    119                         x = 0;
    120                         transparent = transparent_outside;
    121                 }
    122                 else if (((sysarg_t) x) >= pixmap->width) {
    123                         x = pixmap->width - 1;
    124                         transparent = transparent_outside;
    125                 }
    126                
    127                 if (y < 0) {
    128                         y = 0;
    129                         transparent = transparent_outside;
    130                 }
    131                 else if (((sysarg_t) y) >= pixmap->height) {
    132                         y = pixmap->height - 1;
    133                         transparent = transparent_outside;
    134                 }
    135         }
    136        
    137         if (x < 0 || ((sysarg_t) x) >= pixmap->width ||
    138             y < 0 || ((sysarg_t) y) >= pixmap->height)
    139                 return PIXEL(0, 0, 0, 0);
    140 
    141         pixel_t pixel = pixelmap_get_pixel(pixmap, x, y);
    142        
    143         if (transparent)
    144                 pixel = PIXEL(0, RED(pixel), GREEN(pixel), BLUE(pixel));
    145        
    146         return pixel;
    147 }
    148 
    149 
    15088#endif
    15189
  • uspace/lib/c/include/stdio.h

    r5713e5f ra4666a9  
    120120extern int snprintf(char *, size_t , const char *, ...)
    121121    PRINTF_ATTRIBUTE(3, 4);
    122 extern int vasprintf(char **, const char *, va_list);
    123122extern int asprintf(char **, const char *, ...)
    124123    PRINTF_ATTRIBUTE(2, 3);
  • uspace/lib/draw/Makefile

    r5713e5f ra4666a9  
    3737        cursor/embedded.c \
    3838        font/embedded.c \
    39         font/bitmap_backend.c \
    40         font/pcf.c \
    4139        gfx/font-8x16.c \
    4240        gfx/cursor-11x18.c \
  • uspace/lib/draw/font.c

    r5713e5f ra4666a9  
    11/*
    22 * Copyright (c) 2012 Petr Koupy
    3  * Copyright (c) 2014 Martin Sucha
    43 * All rights reserved.
    54 *
     
    3534 */
    3635
     36#include <assert.h>
    3737#include <malloc.h>
    38 #include <errno.h>
    39 #include <str.h>
    4038
    4139#include "font.h"
     
    4341#include "drawctx.h"
    4442
    45 font_t *font_create(font_backend_t *backend, void *backend_data)
     43void font_init(font_t *font, font_decoder_type_t decoder, char *path, uint16_t points)
    4644{
    47         font_t *font = malloc(sizeof(font_t));
    48         if (font == NULL)
    49                 return NULL;
    50        
    51         font->backend = backend;
    52         font->backend_data = backend_data;
    53        
    54         return font;
     45        font->points = points;
     46
     47        switch (decoder) {
     48        case FONT_DECODER_EMBEDDED:
     49                font->decoder = &fd_embedded;
     50                break;
     51        default:
     52                font->decoder = NULL;
     53                break;
     54        }
     55
     56        if (font->decoder) {
     57                font->decoder->init(path, &font->glyph_count, &font->decoder_data);
     58
     59                if (font->glyph_count > 0) {
     60                        font->glyphs = (surface_t **) malloc(sizeof(surface_t *) * font->glyph_count);
     61                } else {
     62                        font->glyphs = NULL;
     63                }
     64
     65                if (font->glyphs) {
     66                        for (size_t i = 0; i < font->glyph_count; ++i) {
     67                                font->glyphs[i] = NULL;
     68                        }
     69                } else {
     70                        font->glyph_count = 0;
     71                }
     72        } else {
     73                font->glyph_count = 0;
     74                font->glyphs = NULL;
     75                font->decoder_data = NULL;
     76        }
    5577}
    5678
    5779void font_release(font_t *font)
    5880{
    59         font->backend->release(font->backend_data);
     81        if (font->glyphs) {
     82                for (size_t i = 0; i < font->glyph_count; ++i) {
     83                        if (font->glyphs[i]) {
     84                                surface_destroy(font->glyphs[i]);
     85                        }
     86                }
     87                free(font->glyphs);
     88        }
     89       
     90        if (font->decoder) {
     91                font->decoder->release(font->decoder_data);
     92        }
    6093}
    6194
    62 int font_get_metrics(font_t *font, font_metrics_t *metrics) {
    63         return font->backend->get_font_metrics(font->backend_data, metrics);
     95void font_get_box(font_t *font, char *text, sysarg_t *width, sysarg_t *height)
     96{
     97        assert(width);
     98        assert(height);
     99
     100        (*width) = 0;
     101        (*height) = 0;
     102
     103        if (!text) {
     104                return;
     105        }
     106
     107        while (*text) {
     108                uint16_t glyph_idx = font->decoder->resolve(*text, font->decoder_data);
     109                if (glyph_idx < font->glyph_count) {
     110                        if (!font->glyphs[glyph_idx]) {
     111                                font->glyphs[glyph_idx] =
     112                                    font->decoder->render(glyph_idx, font->points);
     113                        }
     114
     115                        surface_t *glyph = font->glyphs[glyph_idx];
     116                        if (glyph) {
     117                                sysarg_t w;
     118                                sysarg_t h;
     119                                surface_get_resolution(glyph, &w, &h);
     120                                (*width) += w;
     121                                (*height) = (*height) < h ? h : (*height);
     122                        }
     123                }
     124                ++text;
     125        }
    64126}
    65127
    66 int font_resolve_glyph(font_t *font, wchar_t c, glyph_id_t *glyph_id) {
    67         return font->backend->resolve_glyph(font->backend_data, c, glyph_id);
    68 }
     128void font_draw_text(font_t *font, drawctx_t *context, source_t *source,
     129    const char *text, sysarg_t x, sysarg_t y)
     130{
     131        assert(context);
     132        assert(source);
    69133
    70 int font_get_glyph_metrics(font_t *font, glyph_id_t glyph_id,
    71     glyph_metrics_t *glyph_metrics)
    72 {
    73         return font->backend->get_glyph_metrics(font->backend_data,
    74             glyph_id, glyph_metrics);
    75 }
    76 
    77 int font_render_glyph(font_t *font, drawctx_t *context, source_t *source,
    78     sysarg_t x, sysarg_t y, glyph_id_t glyph_id)
    79 {
    80         return font->backend->render_glyph(font->backend_data, context, source,
    81             x, y, glyph_id);
    82 }
    83 
    84 /* TODO this is bad interface */
    85 int font_get_box(font_t *font, char *text, sysarg_t *width, sysarg_t *height)
    86 {
    87         font_metrics_t fm;
    88         int rc = font_get_metrics(font, &fm);
    89         if (rc != EOK)
    90                 return rc;
    91 
    92         native_t x = 0;
    93 
    94         size_t off = 0;
    95         while (true) {
    96                 wchar_t c = str_decode(text, &off, STR_NO_LIMIT);
    97                 if (c == 0)
    98                         break;
    99                
    100                 glyph_id_t glyph_id;
    101                 rc = font_resolve_glyph(font, c, &glyph_id);
    102                 if (rc != EOK) {
    103                         int rc2 = font_resolve_glyph(font, U_SPECIAL, &glyph_id);
    104                         if (rc2 != EOK) {
    105                                 return rc;
    106                         }
    107                 }
    108                
    109                 glyph_metrics_t glyph_metrics;
    110                 rc = font_get_glyph_metrics(font, glyph_id, &glyph_metrics);
    111                 if (rc != EOK)
    112                         return rc;
    113                
    114                 x += glyph_metrics_get_advancement(&glyph_metrics);
    115         }
    116 
    117         *width = x;
    118         *height = fm.ascender + fm.descender;
    119         return EOK;
    120 }
    121 
    122 /* TODO this is bad interface */
    123 int font_draw_text(font_t *font, drawctx_t *context, source_t *source,
    124     const char *text, sysarg_t sx, sysarg_t sy)
    125 {
    126134        drawctx_save(context);
    127135        drawctx_set_compose(context, compose_over);
    128136
    129         font_metrics_t fm;
    130         int rc = font_get_metrics(font, &fm);
    131         if (rc != EOK)
    132                 return rc;
     137        while (*text) {
     138                uint16_t glyph_idx = font->decoder->resolve(*text, font->decoder_data);
     139                if (glyph_idx < font->glyph_count) {
     140                        if (!font->glyphs[glyph_idx]) {
     141                                font->glyphs[glyph_idx] =
     142                                    font->decoder->render(glyph_idx, font->points);
     143                        }
    133144
    134         native_t baseline = sy + fm.ascender;
    135         native_t x = sx;
     145                        surface_t *glyph = font->glyphs[glyph_idx];
     146                        if (glyph) {
     147                                sysarg_t w;
     148                                sysarg_t h;
     149                                surface_get_resolution(glyph, &w, &h);
    136150
    137         size_t off = 0;
    138         while (true) {
    139                 wchar_t c = str_decode(text, &off, STR_NO_LIMIT);
    140                 if (c == 0)
    141                         break;
    142                
    143                 glyph_id_t glyph_id;
    144                 rc = font_resolve_glyph(font, c, &glyph_id);
    145                 if (rc != EOK) {
    146                         int rc2 = font_resolve_glyph(font, U_SPECIAL, &glyph_id);
    147                         if (rc2 != EOK) {
    148                                 return rc;
     151                                transform_t transform;
     152                                transform_identity(&transform);
     153                                transform_translate(&transform, x, y);
     154                                source_set_transform(source, transform);
     155                                source_set_mask(source, glyph, false);
     156                                drawctx_transfer(context, x, y, w, h);
     157
     158                                x += w;
    149159                        }
    150160                }
    151                
    152                 glyph_metrics_t glyph_metrics;
    153                 rc = font_get_glyph_metrics(font, glyph_id, &glyph_metrics);
    154                 if (rc != EOK)
    155                         return rc;
    156 
    157                 rc = font_render_glyph(font, context, source, x, baseline,
    158                     glyph_id);
    159                 if (rc != EOK)
    160                         return rc;
    161 
    162                 x += glyph_metrics_get_advancement(&glyph_metrics);
    163 
     161                ++text;
    164162        }
    165163
    166164        drawctx_restore(context);
    167165        source_set_mask(source, NULL, false);
    168 
    169         return EOK;
    170166}
    171167
  • uspace/lib/draw/font.h

    r5713e5f ra4666a9  
    11/*
    22 * Copyright (c) 2012 Petr Koupy
    3  * Copyright (c) 2014 Martin Sucha
    43 * All rights reserved.
    54 *
     
    4645typedef struct drawctx drawctx_t;
    4746
    48 typedef int metric_t;
     47typedef enum {
     48        FONT_DECODER_EMBEDDED
     49} font_decoder_type_t;
    4950
    5051typedef struct {
    51         /* Horizontal distance between origin and left side of the glyph */
    52         metric_t left_side_bearing;
    53        
    54         /* Width of the actual glyph drawn */
    55         metric_t width;
    56        
    57         /* Horizontal distance between right side of the glyph and origin
    58            of the next glyph */
    59         metric_t right_side_bearing;
    60        
    61         /* Vertical distance between baseline and top of the glyph
    62            (positive to top) */
    63         metric_t ascender;
    64        
    65         /* Height of the actual glyph drawn */
    66         metric_t height;
    67 } glyph_metrics_t;
     52        void (*init)(char *, uint16_t *, void **);
     53        uint16_t (*resolve)(const wchar_t, void *);
     54        surface_t *(*render)(uint16_t, uint16_t);
     55        void (*release)(void *);
     56} font_decoder_t;
    6857
    69 static inline metric_t glyph_metrics_get_descender(glyph_metrics_t *gm)
    70 {
    71         return gm->height - gm->ascender;
    72 }
    73 
    74 static inline metric_t glyph_metrics_get_advancement(glyph_metrics_t *gm)
    75 {
    76         return gm->left_side_bearing + gm->width + gm->right_side_bearing;
    77 }
    78 
    79 typedef struct {
    80         /* Distance between top of the line and baseline */
    81         metric_t ascender;
    82        
    83         /* Distance between baseline and bottom of the line */
    84         metric_t descender;
    85        
    86         /* Distance between bottom of the line and top of the next line */
    87         metric_t leading;
    88 } font_metrics_t;
    89 
    90 typedef uint32_t glyph_id_t;
    91 
    92 typedef struct {
    93         int (*get_font_metrics)(void *, font_metrics_t *);
    94         int (*resolve_glyph)(void *, wchar_t, glyph_id_t *);
    95         int (*get_glyph_metrics)(void *, glyph_id_t, glyph_metrics_t *);
    96         int (*render_glyph)(void *, drawctx_t *, source_t *, sysarg_t,
    97             sysarg_t, glyph_id_t);
    98         void (*release)(void *);
    99 } font_backend_t;
    100 
    101 typedef struct {
    102         font_backend_t *backend;
    103         void *backend_data;
     58typedef struct font {
     59        uint16_t points;
     60        uint16_t glyph_count;
     61        surface_t **glyphs;
     62        font_decoder_t *decoder;
     63        void *decoder_data;
    10464} font_t;
    10565
    106 extern font_t *font_create(font_backend_t *, void *);
    107 extern int font_get_metrics(font_t *, font_metrics_t *);
    108 extern int font_resolve_glyph(font_t *, wchar_t, glyph_id_t *);
    109 extern int font_get_glyph_metrics(font_t *, glyph_id_t, glyph_metrics_t *);
    110 extern int font_render_glyph(font_t *, drawctx_t *, source_t *,
    111     sysarg_t, sysarg_t, glyph_id_t);
     66extern void font_init(font_t *, font_decoder_type_t, char *, uint16_t);
    11267extern void font_release(font_t *);
    11368
    114 extern int font_get_box(font_t *, char *, sysarg_t *, sysarg_t *);
    115 extern int font_draw_text(font_t *, drawctx_t *, source_t *, const char *,
     69extern void font_get_box(font_t *, char *, sysarg_t *, sysarg_t *);
     70extern void font_draw_text(font_t *, drawctx_t *, source_t *, const char *,
    11671    sysarg_t, sysarg_t);
    11772
  • uspace/lib/draw/font/embedded.c

    r5713e5f ra4666a9  
    11/*
    22 * Copyright (c) 2012 Petr Koupy
    3  * Copyright (c) 2014 Martin Sucha
    43 * All rights reserved.
    54 *
     
    3534 */
    3635
     36#include <assert.h>
    3737#include <sys/types.h>
    3838#include <malloc.h>
    39 #include <errno.h>
    4039
    4140#include "../gfx/font-8x16.h"
    4241#include "embedded.h"
    4342#include "../drawctx.h"
    44 #include "bitmap_backend.h"
    4543
    46 static int fde_resolve_glyph(void *unused, const wchar_t chr,
    47     glyph_id_t *glyph_id)
     44static void fde_init(char *path, uint16_t *glyph_count, void **data)
    4845{
    49         bool found = false;
    50         uint16_t glyph = fb_font_glyph(chr, &found);
    51         if (!found)
    52                 return ENOENT;
    53        
    54         *glyph_id = glyph;
    55         return EOK;
     46        assert(glyph_count);
     47        assert(data);
     48
     49        (*glyph_count) = FONT_GLYPHS;
     50        (*data) = NULL;
    5651}
    5752
    58 static int fde_load_glyph_surface(void *unused, glyph_id_t glyph_id,
    59     surface_t **out_surface)
     53static uint16_t fde_resolve(const wchar_t chr, void *data)
    6054{
    61         surface_t *surface = surface_create(FONT_WIDTH, FONT_SCANLINES, NULL, 0);
    62         if (!surface)
    63                 return ENOMEM;
    64        
     55        return fb_font_glyph(chr);
     56}
     57
     58static surface_t *fde_render(uint16_t glyph, uint16_t points)
     59{
     60        surface_t *template = surface_create(FONT_WIDTH, FONT_SCANLINES, NULL, 0);
     61        if (!template) {
     62                return NULL;
     63        }
    6564        for (unsigned int y = 0; y < FONT_SCANLINES; ++y) {
    6665                for (unsigned int x = 0; x < FONT_WIDTH; ++x) {
    67                         pixel_t p = (fb_font[glyph_id][y] & (1 << (7 - x))) ?
     66                        pixel_t p = (fb_font[glyph][y] & (1 << (7 - x))) ?
    6867                            PIXEL(255, 0, 0, 0) : PIXEL(0, 0, 0, 0);
    69                         surface_put_pixel(surface, x, y, p);
     68                        surface_put_pixel(template, x, y, p);
    7069                }
    7170        }
    72        
    73         *out_surface = surface;
    74         return EOK;
    75 }
    7671
    77 static int fde_load_glyph_metrics(void *unused, glyph_id_t glyph_id,
    78     glyph_metrics_t *gm)
    79 {
    80         /* This is simple monospaced font, so fill this data statically */
    81         gm->left_side_bearing = 0;
    82         gm->width = FONT_WIDTH;
    83         gm->right_side_bearing = 0;
    84         gm->ascender = FONT_ASCENDER;
    85         gm->height = FONT_SCANLINES;
    86        
    87         return EOK;
     72        source_t source;
     73        source_init(&source);
     74        source_set_texture(&source, template, false);
     75
     76        transform_t transform;
     77        transform_identity(&transform);
     78        if (points != FONT_SCANLINES) {
     79                double ratio = ((double) points) / ((double) FONT_SCANLINES);
     80                transform_scale(&transform, ratio, ratio);
     81                source_set_transform(&source, transform);
     82        }
     83
     84        double width = FONT_WIDTH;
     85        double height = FONT_SCANLINES;
     86        transform_apply_linear(&transform, &width, &height);
     87        surface_t *result =
     88            surface_create((sysarg_t) (width + 0.5), (sysarg_t) (height + 0.5), NULL, 0);
     89        if (!result) {
     90                surface_destroy(template);
     91                return NULL;
     92        }
     93
     94        drawctx_t context;
     95        drawctx_init(&context, result);
     96        drawctx_set_source(&context, &source);
     97        drawctx_transfer(&context, 0, 0,
     98            (sysarg_t) (width + 0.5), (sysarg_t) (height + 0.5));
     99
     100        surface_destroy(template);
     101
     102        return result;
    88103}
    89104
     
    93108}
    94109
    95 bitmap_font_decoder_t fd_embedded = {
    96         .resolve_glyph = fde_resolve_glyph,
    97         .load_glyph_surface = fde_load_glyph_surface,
    98         .load_glyph_metrics = fde_load_glyph_metrics,
     110font_decoder_t fd_embedded = {
     111        .init = fde_init,
     112        .resolve = fde_resolve,
     113        .render = fde_render,
    99114        .release = fde_release
    100115};
    101116
    102 font_metrics_t font_metrics = {
    103         .ascender = FONT_ASCENDER,
    104         .descender = (FONT_SCANLINES - FONT_ASCENDER),
    105         .leading = 0
    106 };
    107 
    108 int embedded_font_create(font_t **font, uint16_t points)
    109 {
    110         return bitmap_font_create(&fd_embedded, NULL, FONT_GLYPHS, font_metrics,
    111             points, font);
    112 }
    113 
    114117/** @}
    115118 */
  • uspace/lib/draw/font/embedded.h

    r5713e5f ra4666a9  
    3939#include "../font.h"
    4040
    41 extern int embedded_font_create(font_t **, uint16_t points);
     41extern font_decoder_t fd_embedded;
    4242
    4343#endif
  • uspace/lib/draw/gfx/font-8x16.c

    r5713e5f ra4666a9  
    4444 * mark glyph if no specific glyph exists.
    4545 *
    46  * If found is not null, indicate whether the glyph was found or not.
    47  *
    4846 */
    49 uint16_t fb_font_glyph(const wchar_t ch, bool *found)
     47uint16_t fb_font_glyph(const wchar_t ch)
    5048{
    51         if (found)
    52                 *found = true;
    53        
    5449        if (ch == 0x0000)
    5550                return 0;
     
    366361        if (ch == 0xfeff)
    367362                return 2896;
    368        
    369         if (found)
    370                 *found = false;
    371363       
    372364        return 2898;
  • uspace/lib/draw/gfx/font-8x16.h

    r5713e5f ra4666a9  
    3737
    3838#include <sys/types.h>
    39 #include <stdbool.h>
    4039
    4140#define FONT_GLYPHS     2899
    4241#define FONT_WIDTH      8
    4342#define FONT_SCANLINES  16
    44 #define FONT_ASCENDER   12
    4543
    46 extern uint16_t fb_font_glyph(const wchar_t, bool *);
     44extern uint16_t fb_font_glyph(const wchar_t);
    4745extern uint8_t fb_font[FONT_GLYPHS][FONT_SCANLINES];
    4846
  • uspace/lib/draw/source.c

    r5713e5f ra4666a9  
    4545        source->color = PIXEL(0, 0, 0, 0);
    4646        source->texture = NULL;
    47         source->texture_extend = PIXELMAP_EXTEND_TRANSPARENT_BLACK;
     47        source->texture_tile = false;
    4848
    4949        source->alpha = PIXEL(255, 0, 0, 0);
    5050        source->mask = NULL;
    51         source->mask_extend = PIXELMAP_EXTEND_TRANSPARENT_BLACK;
     51        source->mask_tile = false;
    5252}
    5353
     
    7373}
    7474
    75 void source_set_texture(source_t *source, surface_t *texture,
    76     pixelmap_extend_t extend)
     75void source_set_texture(source_t *source, surface_t *texture, bool tile)
    7776{
    7877        source->texture = texture;
    79         source->texture_extend = extend;
     78        source->texture_tile = tile;
    8079}
    8180
     
    8584}
    8685
    87 void source_set_mask(source_t *source, surface_t *mask,
    88     pixelmap_extend_t extend)
     86void source_set_mask(source_t *source, surface_t *mask, bool tile)
    8987{
    9088        source->mask = mask;
    91         source->mask_extend = extend;
     89        source->mask_tile = tile;
    9290}
    9391
     
    9795            (source->alpha == (pixel_t) PIXEL(255, 0, 0, 0)) &&
    9896            (source->texture != NULL) &&
    99             (source->texture_extend == PIXELMAP_EXTEND_TRANSPARENT_BLACK) &&
     97            (source->texture_tile == false) &&
    10098            (transform_is_fast(&source->transform)));
    10199}
     
    122120                mask_pix = source->filter(
    123121                    surface_pixmap_access(source->mask),
    124                     x, y, source->mask_extend);
     122                    x, y, source->mask_tile);
    125123        } else {
    126124                mask_pix = source->alpha;
     
    135133                texture_pix = source->filter(
    136134                    surface_pixmap_access(source->texture),
    137                     x, y, source->texture_extend);
     135                    x, y, source->texture_tile);
    138136        } else {
    139137                texture_pix = source->color;
  • uspace/lib/draw/source.h

    r5713e5f ra4666a9  
    4242#include <transform.h>
    4343#include <filter.h>
    44 #include <io/pixelmap.h>
    4544
    4645#include "surface.h"
     
    5251        pixel_t color;
    5352        surface_t *texture;
    54         pixelmap_extend_t texture_extend;
     53        bool texture_tile;
    5554
    5655        pixel_t alpha;
    5756        surface_t *mask;
    58         pixelmap_extend_t mask_extend;
     57        bool mask_tile;
    5958} source_t;
    6059
     
    6766
    6867extern void source_set_color(source_t *, pixel_t);
    69 extern void source_set_texture(source_t *, surface_t *, pixelmap_extend_t);
     68extern void source_set_texture(source_t *, surface_t *, bool);
    7069
    7170extern void source_set_alpha(source_t *, pixel_t);
    72 extern void source_set_mask(source_t *, surface_t *, pixelmap_extend_t);
     71extern void source_set_mask(source_t *, surface_t *, bool);
    7372
    7473extern bool source_is_fast(source_t *);
  • uspace/lib/gui/button.c

    r5713e5f ra4666a9  
    3838#include <drawctx.h>
    3939#include <surface.h>
    40 #include <font/embedded.h>
    41 #include <errno.h>
    4240#include "common.h"
    4341#include "window.h"
     
    7876        sysarg_t cpt_width;
    7977        sysarg_t cpt_height;
    80         font_get_box(btn->font, btn->caption, &cpt_width, &cpt_height);
     78        font_get_box(&btn->font, btn->caption, &cpt_width, &cpt_height);
    8179       
    8280        if ((widget->width >= cpt_width) && (widget->height >= cpt_height)) {
     
    8583               
    8684                drawctx_set_source(&drawctx, &btn->text);
    87                 drawctx_set_font(&drawctx, btn->font);
     85                drawctx_set_font(&drawctx, &btn->font);
    8886               
    8987                if (btn->caption)
     
    9896        widget_deinit(&btn->widget);
    9997        free(btn->caption);
    100         font_release(btn->font);
     98        font_release(&btn->font);
    10199}
    102100
     
    173171                btn->caption = str_dup(caption);
    174172       
    175         int rc = embedded_font_create(&btn->font, points);
    176         if (rc != EOK) {
    177                 free(btn->caption);
    178                 btn->caption = NULL;
    179                 return false;
    180         }
     173        font_init(&btn->font, FONT_DECODER_EMBEDDED, NULL, points);
    181174       
    182175        sysarg_t cpt_width;
    183176        sysarg_t cpt_height;
    184         font_get_box(btn->font, btn->caption, &cpt_width, &cpt_height);
     177        font_get_box(&btn->font, btn->caption, &cpt_width, &cpt_height);
    185178        btn->widget.width_min = cpt_width + 10;
    186179        btn->widget.height_min = cpt_height + 10;
  • uspace/lib/gui/button.h

    r5713e5f ra4666a9  
    5252        source_t text;
    5353        char *caption;
    54         font_t *font;
     54        font_t font;
    5555        signal_t clicked;
    5656} button_t;
  • uspace/lib/gui/canvas.c

    r5713e5f ra4666a9  
    5858        source_init(&source);
    5959        source_set_transform(&source, transform);
    60         source_set_texture(&source, canvas->surface,
    61             PIXELMAP_EXTEND_TRANSPARENT_BLACK);
     60        source_set_texture(&source, canvas->surface, false);
    6261       
    6362        drawctx_t drawctx;
  • uspace/lib/gui/label.c

    r5713e5f ra4666a9  
    3838#include <drawctx.h>
    3939#include <surface.h>
    40 #include <font/embedded.h>
    41 #include <errno.h>
    4240#include "window.h"
    4341#include "label.h"
     
    6058        sysarg_t cpt_width;
    6159        sysarg_t cpt_height;
    62         font_get_box(lbl->font, lbl->caption, &cpt_width, &cpt_height);
     60        font_get_box(&lbl->font, lbl->caption, &cpt_width, &cpt_height);
    6361       
    6462        if ((widget->width >= cpt_width) && (widget->height >= cpt_height)) {
     
    6765               
    6866                drawctx_set_source(&drawctx, &lbl->text);
    69                 drawctx_set_font(&drawctx, lbl->font);
     67                drawctx_set_font(&drawctx, &lbl->font);
    7068               
    7169                if (lbl->caption)
     
    8684                sysarg_t cpt_width;
    8785                sysarg_t cpt_height;
    88                 font_get_box(lbl->font, lbl->caption, &cpt_width, &cpt_height);
     86                font_get_box(&lbl->font, lbl->caption, &cpt_width, &cpt_height);
    8987               
    9088                lbl->widget.width_min = cpt_width + 4;
     
    10199        widget_deinit(&lbl->widget);
    102100        free(lbl->caption);
    103         font_release(lbl->font);
     101        font_release(&lbl->font);
    104102}
    105103
     
    163161                lbl->caption = str_dup(caption);
    164162       
    165         int rc = embedded_font_create(&lbl->font, points);
    166         if (rc != EOK) {
    167                 free(lbl->caption);
    168                 lbl->caption = NULL;
    169                 return false;
    170         }
     163        font_init(&lbl->font, FONT_DECODER_EMBEDDED, NULL, points);
    171164       
    172165        sysarg_t cpt_width;
    173166        sysarg_t cpt_height;
    174         font_get_box(lbl->font, lbl->caption, &cpt_width, &cpt_height);
     167        font_get_box(&lbl->font, lbl->caption, &cpt_width, &cpt_height);
    175168       
    176169        lbl->widget.width_min = cpt_width + 4;
  • uspace/lib/gui/label.h

    r5713e5f ra4666a9  
    5151        source_t text;
    5252        char *caption;
    53         font_t *font;
     53        font_t font;
    5454        slot_t rewrite;
    5555} label_t;
  • uspace/lib/gui/terminal.c

    r5713e5f ra4666a9  
    186186        //        for full UTF-32 coverage.
    187187       
    188         uint16_t glyph = fb_font_glyph(field->ch, NULL);
     188        uint16_t glyph = fb_font_glyph(field->ch);
    189189       
    190190        for (unsigned int y = 0; y < FONT_SCANLINES; y++) {
  • uspace/lib/gui/window.c

    r5713e5f ra4666a9  
    5555#include <drawctx.h>
    5656#include <surface.h>
    57 #include <font/embedded.h>
    5857
    5958#include "common.h"
     
    161160        /* Window caption */
    162161       
    163         font_t *font;
    164         int rc = embedded_font_create(&font, 16);
    165         if (rc != EOK) {
    166                 window_yield(widget->window);
    167                 return;
    168         }
    169        
    170         drawctx_set_font(&drawctx, font);
     162        font_t font;
     163        font_init(&font, FONT_DECODER_EMBEDDED, NULL, 16);
     164       
     165        drawctx_set_font(&drawctx, &font);
    171166        source_set_color(&source, widget->window->is_focused ?
    172167            color_caption_focus : color_caption_unfocus);
     
    174169        sysarg_t cpt_width;
    175170        sysarg_t cpt_height;
    176         font_get_box(font, widget->window->caption, &cpt_width, &cpt_height);
     171        font_get_box(&font, widget->window->caption, &cpt_width, &cpt_height);
    177172       
    178173        bool draw_title =
     
    188183        }
    189184       
    190         font_release(font);
     185        font_release(&font);
    191186        window_yield(widget->window);
    192187}
  • uspace/lib/posix/include/posix/stdio.h

    r5713e5f ra4666a9  
    107107extern int snprintf(char *, size_t , const char *, ...) PRINTF_ATTRIBUTE(3, 4);
    108108#ifdef _GNU_SOURCE
    109 extern int vasprintf(char **, const char *, va_list);
    110109extern int asprintf(char **, const char *, ...) PRINTF_ATTRIBUTE(2, 3);
    111110#endif
  • uspace/lib/softrend/filter.c

    r5713e5f ra4666a9  
    11/*
    22 * Copyright (c) 2012 Petr Koupy
    3  * Copyright (c) 2014 Martin Sucha
    43 * All rights reserved.
    54 *
     
    3635
    3736#include "filter.h"
    38 #include <io/pixel.h>
    3937
     38pixel_t filter_nearest(pixelmap_t *pixmap, double x, double y, bool tile)
     39{
     40        long _x = x > 0 ? (long) (x + 0.5) : (long) (x - 0.5);
     41        long _y = y > 0 ? (long) (y + 0.5) : (long) (y - 0.5);
    4042
    41 static long round(double val)
    42 {
    43         return val > 0 ? (long) (val + 0.5) : (long) (val - 0.5);
     43        if (tile) {
     44                _x %= pixmap->width;
     45                _y %= pixmap->height;
     46        }
     47
     48        return pixelmap_get_pixel(pixmap, (sysarg_t) _x, (sysarg_t) _y);
    4449}
    4550
    46 static long floor(double val)
     51pixel_t filter_bilinear(pixelmap_t *pixmap, double x, double y, bool tile)
    4752{
    48         long lval = (long) val;
    49         if (val < 0 && lval != val)
    50                 return lval - 1;
    51         return lval;
     53        // TODO
     54        return 0;
    5255}
    5356
    54 static long ceil(double val)
    55 {
    56         long lval = (long) val;
    57         if (val > 0 && lval != val)
    58                 return lval + 1;
    59         return lval;
    60 }
    61 
    62 
    63 static inline pixel_t blend_pixels(size_t count, float *weights,
    64     pixel_t *pixels)
    65 {
    66         float alpha = 0, red = 0, green = 0, blue = 0;
    67         for (size_t index = 0; index < count; index++) {
    68                 alpha += weights[index] * ALPHA(pixels[index]);
    69                 red   += weights[index] *   RED(pixels[index]);
    70                 green += weights[index] * GREEN(pixels[index]);
    71                 blue  += weights[index] *  BLUE(pixels[index]);
    72         }
    73        
    74         return PIXEL((uint8_t) alpha, (uint8_t) red, (uint8_t) green,
    75             (uint8_t) blue);
    76 }
    77 
    78 pixel_t filter_nearest(pixelmap_t *pixmap, double x, double y,
    79     pixelmap_extend_t extend)
    80 {
    81         return pixelmap_get_extended_pixel(pixmap, round(x), round(y), extend);
    82 }
    83 
    84 pixel_t filter_bilinear(pixelmap_t *pixmap, double x, double y,
    85     pixelmap_extend_t extend)
    86 {
    87         long x1 = floor(x);
    88         long x2 = ceil(x);
    89         long y1 = floor(y);
    90         long y2 = ceil(y);
    91        
    92         if (y1 == y2 && x1 == x2) {
    93                 return pixelmap_get_extended_pixel(pixmap,
    94                     (sysarg_t) x1, (sysarg_t) y1, extend);
    95         }
    96        
    97         double x_delta = x - x1;
    98         double y_delta = y - y1;
    99        
    100         pixel_t pixels[4];
    101         pixels[0] = pixelmap_get_extended_pixel(pixmap, x1, y1, extend);
    102         pixels[1] = pixelmap_get_extended_pixel(pixmap, x2, y1, extend);
    103         pixels[2] = pixelmap_get_extended_pixel(pixmap, x1, y2, extend);
    104         pixels[3] = pixelmap_get_extended_pixel(pixmap, x2, y2, extend);
    105        
    106         float weights[4];
    107         weights[0] = (1 - x_delta) * (1 - y_delta);
    108         weights[1] = (    x_delta) * (1 - y_delta);
    109         weights[2] = (1 - x_delta) * (    y_delta);
    110         weights[3] = (    x_delta) * (    y_delta);
    111        
    112         return blend_pixels(4, weights, pixels);
    113 }
    114 
    115 pixel_t filter_bicubic(pixelmap_t *pixmap, double x, double y,
    116     pixelmap_extend_t extend)
     57pixel_t filter_bicubic(pixelmap_t *pixmap, double x, double y, bool tile)
    11758{
    11859        // TODO
  • uspace/lib/softrend/filter.h

    r5713e5f ra4666a9  
    4040#include <io/pixelmap.h>
    4141
    42 typedef pixel_t (*filter_t)(pixelmap_t *, double, double, pixelmap_extend_t);
     42typedef pixel_t (*filter_t)(pixelmap_t *, double, double, bool);
    4343
    44 extern pixel_t filter_nearest(pixelmap_t *, double, double, pixelmap_extend_t);
    45 extern pixel_t filter_bilinear(pixelmap_t *, double, double, pixelmap_extend_t);
    46 extern pixel_t filter_bicubic(pixelmap_t *, double, double, pixelmap_extend_t);
     44extern pixel_t filter_nearest(pixelmap_t *, double, double, bool);
     45extern pixel_t filter_bilinear(pixelmap_t *, double, double, bool);
     46extern pixel_t filter_bicubic(pixelmap_t *, double, double, bool);
    4747
    4848#endif
  • uspace/srv/hid/compositor/compositor.c

    r5713e5f ra4666a9  
    8484static sysarg_t coord_origin;
    8585static pixel_t bg_color;
    86 static filter_t filter = filter_bilinear;
    87 static unsigned int filter_index = 1;
    8886
    8987typedef struct {
     
    410408
    411409                        source_init(&source);
    412                         source_set_filter(&source, filter);
     410                        source_set_filter(&source, filter_nearest);
    413411                        drawctx_init(&context, vp->surface);
    414412                        drawctx_set_compose(&context, compose_over);
     
    444442
    445443                                        source_set_transform(&source, transform);
    446                                         source_set_texture(&source, win->surface,
    447                                             PIXELMAP_EXTEND_TRANSPARENT_SIDES);
     444                                        source_set_texture(&source, win->surface, false);
    448445                                        source_set_alpha(&source, PIXEL(win->opacity, 0, 0, 0));
    449446
     
    18211818            key == KC_O || key == KC_P);
    18221819        bool kconsole_switch = (mods & KM_ALT) && (key == KC_M);
    1823         bool filter_switch = (mods & KM_ALT) && (key == KC_Y);
    1824 
    1825         bool key_filter = (type == KEY_RELEASE) && (win_transform || win_resize ||
     1820
     1821        bool filter = (type == KEY_RELEASE) && (win_transform || win_resize ||
    18261822            win_opacity || win_close || win_switch || viewport_move ||
    1827             viewport_change || kconsole_switch || filter_switch);
    1828 
    1829         if (key_filter) {
     1823            viewport_change || kconsole_switch);
     1824
     1825        if (filter) {
    18301826                /* no-op */
    18311827        } else if (win_transform) {
     
    20952091                if (console_kcon())
    20962092                        active = false;
    2097         } else if (filter_switch) {
    2098                 filter_index++;
    2099                 if (filter_index > 1)
    2100                         filter_index = 0;
    2101                 if (filter_index == 0) {
    2102                         filter = filter_nearest;
    2103                 }
    2104                 else {
    2105                         filter = filter_bilinear;
    2106                 }
    2107                 comp_damage(0, 0, UINT32_MAX, UINT32_MAX);
    21082093        } else {
    21092094                window_event_t *event = (window_event_t *) malloc(sizeof(window_event_t));
Note: See TracChangeset for help on using the changeset viewer.