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

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

Curb the proliferation of libdraw headers

libdraw provides a lot of ambiguously named headers, which makes it
confusing. This change merges the subdirectories into single headers,
and moves all headers into draw subdirectory, so that it's obvious
at a glance what library the header belongs to.

Compare:

#include <path.h>
#include <source.h>
#include <font/bitmap_backend.h>
#include <font/pcf.h>

vs.

#include <draw/path.h>
#include <draw/source.h>
#include <draw/font.h>

  • Property mode set to 100644
File size: 3.2 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 <draw/gfx.h>
42#include <draw/font.h>
43#include <draw/drawctx.h>
44
45static errno_t fde_resolve_glyph(void *unused, const wchar_t chr,
46 glyph_id_t *glyph_id)
47{
48 bool found = false;
49 uint16_t glyph = fb_font_glyph(chr, &found);
50 if (!found)
51 return ENOENT;
52
53 *glyph_id = glyph;
54 return EOK;
55}
56
57static errno_t fde_load_glyph_surface(void *unused, glyph_id_t glyph_id,
58 surface_t **out_surface)
59{
60 surface_t *surface = surface_create(FONT_WIDTH, FONT_SCANLINES, NULL, 0);
61 if (!surface)
62 return ENOMEM;
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_id][y] & (1 << (7 - x))) ?
67 PIXEL(255, 0, 0, 0) : PIXEL(0, 0, 0, 0);
68 surface_put_pixel(surface, x, y, p);
69 }
70 }
71
72 *out_surface = surface;
73 return EOK;
74}
75
76static errno_t fde_load_glyph_metrics(void *unused, glyph_id_t glyph_id,
77 glyph_metrics_t *gm)
78{
79 /* This is simple monospaced font, so fill this data statically */
80 gm->left_side_bearing = 0;
81 gm->width = FONT_WIDTH;
82 gm->right_side_bearing = 0;
83 gm->ascender = FONT_ASCENDER;
84 gm->height = FONT_SCANLINES;
85
86 return EOK;
87}
88
89static void fde_release(void *data)
90{
91 /* no-op */
92}
93
94bitmap_font_decoder_t fd_embedded = {
95 .resolve_glyph = fde_resolve_glyph,
96 .load_glyph_surface = fde_load_glyph_surface,
97 .load_glyph_metrics = fde_load_glyph_metrics,
98 .release = fde_release
99};
100
101font_metrics_t font_metrics = {
102 .ascender = FONT_ASCENDER,
103 .descender = (FONT_SCANLINES - FONT_ASCENDER),
104 .leading = 0
105};
106
107errno_t embedded_font_create(font_t **font, uint16_t points)
108{
109 return bitmap_font_create(&fd_embedded, NULL, FONT_GLYPHS, font_metrics,
110 points, font);
111}
112
113/** @}
114 */
Note: See TracBrowser for help on using the repository browser.