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

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

style: Remove trailing whitespace on _all_ lines, including empty ones, for particular file types.

Command used: tools/srepl '\s\+$' '' -- *.c *.h *.py *.sh *.s *.S *.ag

Currently, whitespace on empty lines is very inconsistent.
There are two basic choices: Either remove the whitespace, or keep empty lines
indented to the level of surrounding code. The former is AFAICT more common,
and also much easier to do automatically.

Alternatively, we could write script for automatic indentation, and use that
instead. However, if such a script exists, it's possible to use the indented
style locally, by having the editor apply relevant conversions on load/save,
without affecting remote repository. IMO, it makes more sense to adopt
the simpler rule.

  • Property mode set to 100644
File size: 3.2 KB
RevLine 
[6d5e378]1/*
2 * Copyright (c) 2012 Petr Koupy
[2cc1ec0]3 * Copyright (c) 2014 Martin Sucha
[6d5e378]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
[8d2dd7f2]37#include <stdint.h>
[2cc1ec0]38#include <errno.h>
[38d150e]39#include <stdlib.h>
[6d5e378]40
41#include "../gfx/font-8x16.h"
42#include "embedded.h"
43#include "../drawctx.h"
[2cc1ec0]44#include "bitmap_backend.h"
[6d5e378]45
[b7fd2a0]46static errno_t fde_resolve_glyph(void *unused, const wchar_t chr,
[2cc1ec0]47 glyph_id_t *glyph_id)
[6d5e378]48{
[2cc1ec0]49 bool found = false;
50 uint16_t glyph = fb_font_glyph(chr, &found);
51 if (!found)
52 return ENOENT;
[a35b458]53
[2cc1ec0]54 *glyph_id = glyph;
55 return EOK;
[6d5e378]56}
57
[b7fd2a0]58static errno_t fde_load_glyph_surface(void *unused, glyph_id_t glyph_id,
[2cc1ec0]59 surface_t **out_surface)
[6d5e378]60{
[2cc1ec0]61 surface_t *surface = surface_create(FONT_WIDTH, FONT_SCANLINES, NULL, 0);
62 if (!surface)
63 return ENOMEM;
[a35b458]64
[6d5e378]65 for (unsigned int y = 0; y < FONT_SCANLINES; ++y) {
66 for (unsigned int x = 0; x < FONT_WIDTH; ++x) {
[1b20da0]67 pixel_t p = (fb_font[glyph_id][y] & (1 << (7 - x))) ?
[6d5e378]68 PIXEL(255, 0, 0, 0) : PIXEL(0, 0, 0, 0);
[2cc1ec0]69 surface_put_pixel(surface, x, y, p);
[6d5e378]70 }
71 }
[a35b458]72
[2cc1ec0]73 *out_surface = surface;
74 return EOK;
75}
[6d5e378]76
[b7fd2a0]77static errno_t fde_load_glyph_metrics(void *unused, glyph_id_t glyph_id,
[2cc1ec0]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;
[a35b458]86
[2cc1ec0]87 return EOK;
[6d5e378]88}
89
90static void fde_release(void *data)
91{
92 /* no-op */
93}
94
[2cc1ec0]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,
[6d5e378]99 .release = fde_release
100};
101
[2cc1ec0]102font_metrics_t font_metrics = {
103 .ascender = FONT_ASCENDER,
104 .descender = (FONT_SCANLINES - FONT_ASCENDER),
105 .leading = 0
106};
107
[b7fd2a0]108errno_t embedded_font_create(font_t **font, uint16_t points)
[2cc1ec0]109{
110 return bitmap_font_create(&fd_embedded, NULL, FONT_GLYPHS, font_metrics,
111 points, font);
112}
113
[6d5e378]114/** @}
115 */
Note: See TracBrowser for help on using the repository browser.