root/font/font_peer_fn.cc

Revision 52:15a18fbe6f21, 3.0 KB (checked in by thib, 3 years ago)
* Known bugs added to the README * Code cleaning (0 -> NULL when needed, indentation, spaces, ...)
Line 
1/*
2 * Copyright (c) 2001 Yuki Sawada
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 * 1. Redistributions of source code must retain the above copyright
9 *    notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 *    notice, this list of conditions and the following disclaimer in the
12 *    documentation and/or other materials provided with the distribution.
13 * 3. The name of the author may not be used to endorse or promote products
14 *    derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 *
27 * This code uses some parts of AVG32 for Macintosh by Kenjo.
28 */
29
30#include <stdio.h>
31#include <stdlib.h>
32#include <stdexcept>
33#include <string>
34
35using namespace std;
36
37#include "codeconv.h"
38#include "font.h"
39#include "font_peer.h"
40
41namespace XKFont {
42
43#define FN_DAT_SIZE  2544768
44
45PeerFn::PeerFn(const char *name, int index, int hsize, int vsize) : buffer(0)
46{
47        FILE *fp = 0;
48
49        buffer = new unsigned char[FN_DAT_SIZE];
50        fp = fopen(name, "rb");
51        if (!fp) {
52                delete[] buffer;
53                buffer = 0;
54                string err = string("XKFont::PeerFn::PeerFn : Cannot open font file ")+name;
55                throw std::invalid_argument(err);
56        }
57        fread(buffer, 1, FN_DAT_SIZE, fp);
58        fclose(fp);
59
60        return;
61}
62
63
64PeerFn::~PeerFn() {
65        delete[] buffer;
66}
67
68bool
69PeerFn::GlyphCreate(unsigned int code, Glyph* glyph)
70{
71        unsigned char *p1, *p2;
72        unsigned int h, l, offset;
73        int x, y;
74
75        l = codeconv_euc_to_jis(code);
76        l -= 0x2121;
77        h = l >> 8;
78        l &= 0xff;
79        offset = (h * 0x5e + l) * 12 * 24;
80        if (offset > FN_DAT_SIZE - 12 * 24)
81                 offset = 0;
82
83        glyph->bitmap_left = 0;
84        glyph->bitmap_top = 21;
85        glyph->bitmap.width = 24;
86        glyph->bitmap.rows = 24;
87
88#if 0
89        glyph->metrics.ascender = private->vsize - 4;
90        glyph->metrics.descender = -4;
91#endif
92        glyph->advance.x = 24 + 1;
93        glyph->advance.y = 24 + 1;
94
95        glyph->bitmap.buffer = new unsigned char[24*24];
96
97        p1 = glyph->bitmap.buffer;
98        p2 = buffer + offset;
99        for (y = 0; y < 24; y++) {
100                for (x = 0; x < 12; x++) {
101                        unsigned char c = ~*p2++;
102                        unsigned char c1;
103                        c1 = (c)   & 0x0f;
104                        *p1++ = (c1<<4) | c1;
105                        c1 = (c>>4)& 0x0f;
106                        *p1++ = (c1<<4) | c1;
107                }
108        }
109        return true;
110}
111
112} /* end of namespace XKFont */
Note: See TracBrowser for help on using the browser.