Changes in uspace/lib/draw/font/embedded.c [2cc1ec0:6d5e378] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/draw/font/embedded.c
r2cc1ec0 r6d5e378 1 1 /* 2 2 * Copyright (c) 2012 Petr Koupy 3 * Copyright (c) 2014 Martin Sucha4 3 * All rights reserved. 5 4 * … … 35 34 */ 36 35 36 #include <assert.h> 37 37 #include <sys/types.h> 38 38 #include <malloc.h> 39 #include <errno.h>40 39 41 40 #include "../gfx/font-8x16.h" 42 41 #include "embedded.h" 43 42 #include "../drawctx.h" 44 #include "bitmap_backend.h"45 43 46 static int fde_resolve_glyph(void *unused, const wchar_t chr, 47 glyph_id_t *glyph_id) 44 static void fde_init(char *path, uint16_t *glyph_count, void **data) 48 45 { 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; 56 51 } 57 52 58 static int fde_load_glyph_surface(void *unused, glyph_id_t glyph_id, 59 surface_t **out_surface) 53 static uint16_t fde_resolve(const wchar_t chr, void *data) 60 54 { 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 58 static 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 } 65 64 for (unsigned int y = 0; y < FONT_SCANLINES; ++y) { 66 65 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))) ? 68 67 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); 70 69 } 71 70 } 72 73 *out_surface = surface;74 return EOK;75 }76 71 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; 88 103 } 89 104 … … 93 108 } 94 109 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,110 font_decoder_t fd_embedded = { 111 .init = fde_init, 112 .resolve = fde_resolve, 113 .render = fde_render, 99 114 .release = fde_release 100 115 }; 101 116 102 font_metrics_t font_metrics = {103 .ascender = FONT_ASCENDER,104 .descender = (FONT_SCANLINES - FONT_ASCENDER),105 .leading = 0106 };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 114 117 /** @} 115 118 */
Note:
See TracChangeset
for help on using the changeset viewer.