[6d5e378] | 1 | /*
|
---|
| 2 | * Copyright (c) 2012 Petr Koupy
|
---|
| 3 | * All rights reserved.
|
---|
| 4 | *
|
---|
| 5 | * Redistribution and use in source and binary forms, with or without
|
---|
| 6 | * modification, are permitted provided that the following conditions
|
---|
| 7 | * are met:
|
---|
| 8 | *
|
---|
| 9 | * - Redistributions of source code must retain the above copyright
|
---|
| 10 | * notice, this list of conditions and the following disclaimer.
|
---|
| 11 | * - Redistributions in binary form must reproduce the above copyright
|
---|
| 12 | * notice, this list of conditions and the following disclaimer in the
|
---|
| 13 | * documentation and/or other materials provided with the distribution.
|
---|
| 14 | * - The name of the author may not be used to endorse or promote products
|
---|
| 15 | * derived from this software without specific prior written permission.
|
---|
| 16 | *
|
---|
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
| 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
| 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
| 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
| 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
| 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
| 27 | */
|
---|
| 28 |
|
---|
| 29 | /** @addtogroup draw
|
---|
| 30 | * @{
|
---|
| 31 | */
|
---|
| 32 | /**
|
---|
| 33 | * @file
|
---|
| 34 | */
|
---|
| 35 |
|
---|
| 36 | #include <assert.h>
|
---|
| 37 | #include <sys/types.h>
|
---|
| 38 | #include <malloc.h>
|
---|
| 39 |
|
---|
| 40 | #include "../gfx/font-8x16.h"
|
---|
| 41 | #include "embedded.h"
|
---|
| 42 | #include "../drawctx.h"
|
---|
| 43 |
|
---|
| 44 | static void fde_init(char *path, uint16_t *glyph_count, void **data)
|
---|
| 45 | {
|
---|
| 46 | assert(glyph_count);
|
---|
| 47 | assert(data);
|
---|
| 48 |
|
---|
| 49 | (*glyph_count) = FONT_GLYPHS;
|
---|
| 50 | (*data) = NULL;
|
---|
| 51 | }
|
---|
| 52 |
|
---|
| 53 | static uint16_t fde_resolve(const wchar_t chr, void *data)
|
---|
| 54 | {
|
---|
| 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 | }
|
---|
| 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;
|
---|
| 103 | }
|
---|
| 104 |
|
---|
| 105 | static void fde_release(void *data)
|
---|
| 106 | {
|
---|
| 107 | /* no-op */
|
---|
| 108 | }
|
---|
| 109 |
|
---|
| 110 | font_decoder_t fd_embedded = {
|
---|
| 111 | .init = fde_init,
|
---|
| 112 | .resolve = fde_resolve,
|
---|
| 113 | .render = fde_render,
|
---|
| 114 | .release = fde_release
|
---|
| 115 | };
|
---|
| 116 |
|
---|
| 117 | /** @}
|
---|
| 118 | */
|
---|