0
|
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
|
|
35 using namespace std;
|
|
36
|
|
37 #include "font.h"
|
|
38 #include "font_peer.h"
|
|
39
|
|
40 namespace XKFont {
|
|
41
|
|
42 #define FN_DAT_SIZE 2544768
|
|
43
|
|
44 PeerFn::PeerFn(const char *name, int index, int hsize, int vsize) : buffer(0)
|
|
45 {
|
|
46 FILE *fp = 0;
|
|
47
|
|
48 buffer = new unsigned char[FN_DAT_SIZE];
|
|
49 fp = fopen(name, "rb");
|
|
50 if (!fp) {
|
|
51 delete[] buffer;
|
|
52 buffer = 0;
|
|
53 string err = string("XKFont::PeerFn::PeerFn : Cannot open font file ")+name;
|
|
54 throw std::invalid_argument(err);
|
|
55 }
|
|
56 fread(buffer, 1, FN_DAT_SIZE, fp);
|
|
57 fclose(fp);
|
|
58
|
|
59 return;
|
|
60 }
|
|
61
|
|
62
|
|
63 PeerFn::~PeerFn() {
|
|
64 delete[] buffer;
|
|
65 }
|
|
66
|
|
67 static unsigned int
|
|
68 font_glyph_fn_codeconv_euc_to_jis(unsigned int euc)
|
|
69 {
|
|
70 unsigned int h, l;
|
|
71
|
|
72 h = (euc >> 8) & 0xff;
|
|
73 l = euc & 0xff;
|
|
74
|
|
75 if (h < 0x81) {
|
|
76 l = h;
|
|
77 h = 0;
|
|
78 } else if (l == 0x8e)
|
|
79 h = 0;
|
|
80 else {
|
|
81 h -= 0x80;
|
|
82 l -= 0x80;
|
|
83 }
|
|
84
|
|
85 return (h << 8) | l;
|
|
86 }
|
|
87
|
|
88 bool
|
|
89 PeerFn::GlyphCreate(unsigned int code, Glyph* glyph)
|
|
90 {
|
|
91 unsigned char *p1, *p2;
|
|
92 unsigned int h, l, offset;
|
|
93 int x, y;
|
|
94
|
|
95 l = font_glyph_fn_codeconv_euc_to_jis(code);
|
|
96 l -= 0x2121;
|
|
97 h = l >> 8;
|
|
98 l &= 0xff;
|
|
99 offset = (h * 0x5e + l) * 12 * 24;
|
|
100 if (offset > FN_DAT_SIZE - 12 * 24)
|
|
101 offset = 0;
|
|
102
|
|
103 glyph->bitmap_left = 0;
|
|
104 glyph->bitmap_top = 21;
|
|
105 glyph->bitmap.width = 24;
|
|
106 glyph->bitmap.rows = 24;
|
|
107
|
|
108 #if 0
|
|
109 glyph->metrics.ascender = private->vsize - 4;
|
|
110 glyph->metrics.descender = -4;
|
|
111 #endif
|
|
112 glyph->advance.x = 24 + 1;
|
|
113 glyph->advance.y = 24 + 1;
|
|
114
|
|
115 glyph->bitmap.buffer = new unsigned char[24*24];
|
|
116
|
|
117 p1 = glyph->bitmap.buffer;
|
|
118 p2 = buffer + offset;
|
|
119 for (y = 0; y < 24; y++) {
|
|
120 for (x = 0; x < 12; x++) {
|
|
121 unsigned char c = ~*p2++;
|
|
122 unsigned char c1;
|
|
123 c1 = (c) & 0x0f; *p1++ = (c1<<4) | c1;
|
|
124 c1 = (c>>4)& 0x0f; *p1++ = (c1<<4) | c1;
|
|
125 }
|
|
126 }
|
|
127 return true;
|
|
128 }
|
|
129
|
|
130 } /* end of namespace XKFont */
|