source: mainline/uspace/lib/draw/font/embedded.c@ 3061bc1

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 3061bc1 was 1b20da0, checked in by Jiří Zárevúcky <zarevucky.jiri@…>, 7 years ago

style: Remove trailing whitespace on non-empty lines, in certain file types.

Command used: tools/srepl '\([^[:space:]]\)\s\+$' '\1' -- *.c *.h *.py *.sh *.s *.S *.ag

  • Property mode set to 100644
File size: 3.3 KB
Line 
1/*
2 * Copyright (c) 2012 Petr Koupy
3 * Copyright (c) 2014 Martin Sucha
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * - Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * - Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * - The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30/** @addtogroup draw
31 * @{
32 */
33/**
34 * @file
35 */
36
37#include <stdint.h>
38#include <errno.h>
39#include <stdlib.h>
40
41#include "../gfx/font-8x16.h"
42#include "embedded.h"
43#include "../drawctx.h"
44#include "bitmap_backend.h"
45
46static errno_t fde_resolve_glyph(void *unused, const wchar_t chr,
47 glyph_id_t *glyph_id)
48{
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;
56}
57
58static errno_t fde_load_glyph_surface(void *unused, glyph_id_t glyph_id,
59 surface_t **out_surface)
60{
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;
75}
76
77static errno_t 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;
88}
89
90static void fde_release(void *data)
91{
92 /* no-op */
93}
94
95bitmap_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,
99 .release = fde_release
100};
101
102font_metrics_t font_metrics = {
103 .ascender = FONT_ASCENDER,
104 .descender = (FONT_SCANLINES - FONT_ASCENDER),
105 .leading = 0
106};
107
108errno_t 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/** @}
115 */
Note: See TracBrowser for help on using the repository browser.