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