Ignore:
File:
1 edited

Legend:

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

    r2cc1ec0 r6d5e378  
    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 */
Note: See TracChangeset for help on using the changeset viewer.