annotate font/font_peer_fn.cc @ 28:f1f22bfc4496

* Allow the building of scn2kdump by typing "make scn2kdump" in scn2k/
author thib
date Fri, 06 Mar 2009 18:30:19 +0000
parents 223b71206888
children 15a18fbe6f21
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
223b71206888 Initial import
thib
parents:
diff changeset
1 /*
223b71206888 Initial import
thib
parents:
diff changeset
2 * Copyright (c) 2001 Yuki Sawada
223b71206888 Initial import
thib
parents:
diff changeset
3 * All rights reserved.
223b71206888 Initial import
thib
parents:
diff changeset
4 *
223b71206888 Initial import
thib
parents:
diff changeset
5 * Redistribution and use in source and binary forms, with or without
223b71206888 Initial import
thib
parents:
diff changeset
6 * modification, are permitted provided that the following conditions
223b71206888 Initial import
thib
parents:
diff changeset
7 * are met:
223b71206888 Initial import
thib
parents:
diff changeset
8 * 1. Redistributions of source code must retain the above copyright
223b71206888 Initial import
thib
parents:
diff changeset
9 * notice, this list of conditions and the following disclaimer.
223b71206888 Initial import
thib
parents:
diff changeset
10 * 2. Redistributions in binary form must reproduce the above copyright
223b71206888 Initial import
thib
parents:
diff changeset
11 * notice, this list of conditions and the following disclaimer in the
223b71206888 Initial import
thib
parents:
diff changeset
12 * documentation and/or other materials provided with the distribution.
223b71206888 Initial import
thib
parents:
diff changeset
13 * 3. The name of the author may not be used to endorse or promote products
223b71206888 Initial import
thib
parents:
diff changeset
14 * derived from this software without specific prior written permission.
223b71206888 Initial import
thib
parents:
diff changeset
15 *
223b71206888 Initial import
thib
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
223b71206888 Initial import
thib
parents:
diff changeset
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
223b71206888 Initial import
thib
parents:
diff changeset
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
223b71206888 Initial import
thib
parents:
diff changeset
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
223b71206888 Initial import
thib
parents:
diff changeset
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
223b71206888 Initial import
thib
parents:
diff changeset
21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
223b71206888 Initial import
thib
parents:
diff changeset
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
223b71206888 Initial import
thib
parents:
diff changeset
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
223b71206888 Initial import
thib
parents:
diff changeset
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
223b71206888 Initial import
thib
parents:
diff changeset
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
223b71206888 Initial import
thib
parents:
diff changeset
26 *
223b71206888 Initial import
thib
parents:
diff changeset
27 * This code uses some parts of AVG32 for Macintosh by Kenjo.
223b71206888 Initial import
thib
parents:
diff changeset
28 */
223b71206888 Initial import
thib
parents:
diff changeset
29
223b71206888 Initial import
thib
parents:
diff changeset
30 #include <stdio.h>
223b71206888 Initial import
thib
parents:
diff changeset
31 #include <stdlib.h>
223b71206888 Initial import
thib
parents:
diff changeset
32 #include <stdexcept>
223b71206888 Initial import
thib
parents:
diff changeset
33 #include <string>
223b71206888 Initial import
thib
parents:
diff changeset
34
223b71206888 Initial import
thib
parents:
diff changeset
35 using namespace std;
223b71206888 Initial import
thib
parents:
diff changeset
36
223b71206888 Initial import
thib
parents:
diff changeset
37 #include "font.h"
223b71206888 Initial import
thib
parents:
diff changeset
38 #include "font_peer.h"
223b71206888 Initial import
thib
parents:
diff changeset
39
223b71206888 Initial import
thib
parents:
diff changeset
40 namespace XKFont {
223b71206888 Initial import
thib
parents:
diff changeset
41
223b71206888 Initial import
thib
parents:
diff changeset
42 #define FN_DAT_SIZE 2544768
223b71206888 Initial import
thib
parents:
diff changeset
43
223b71206888 Initial import
thib
parents:
diff changeset
44 PeerFn::PeerFn(const char *name, int index, int hsize, int vsize) : buffer(0)
223b71206888 Initial import
thib
parents:
diff changeset
45 {
223b71206888 Initial import
thib
parents:
diff changeset
46 FILE *fp = 0;
223b71206888 Initial import
thib
parents:
diff changeset
47
223b71206888 Initial import
thib
parents:
diff changeset
48 buffer = new unsigned char[FN_DAT_SIZE];
223b71206888 Initial import
thib
parents:
diff changeset
49 fp = fopen(name, "rb");
223b71206888 Initial import
thib
parents:
diff changeset
50 if (!fp) {
223b71206888 Initial import
thib
parents:
diff changeset
51 delete[] buffer;
223b71206888 Initial import
thib
parents:
diff changeset
52 buffer = 0;
223b71206888 Initial import
thib
parents:
diff changeset
53 string err = string("XKFont::PeerFn::PeerFn : Cannot open font file ")+name;
223b71206888 Initial import
thib
parents:
diff changeset
54 throw std::invalid_argument(err);
223b71206888 Initial import
thib
parents:
diff changeset
55 }
223b71206888 Initial import
thib
parents:
diff changeset
56 fread(buffer, 1, FN_DAT_SIZE, fp);
223b71206888 Initial import
thib
parents:
diff changeset
57 fclose(fp);
223b71206888 Initial import
thib
parents:
diff changeset
58
223b71206888 Initial import
thib
parents:
diff changeset
59 return;
223b71206888 Initial import
thib
parents:
diff changeset
60 }
223b71206888 Initial import
thib
parents:
diff changeset
61
223b71206888 Initial import
thib
parents:
diff changeset
62
223b71206888 Initial import
thib
parents:
diff changeset
63 PeerFn::~PeerFn() {
223b71206888 Initial import
thib
parents:
diff changeset
64 delete[] buffer;
223b71206888 Initial import
thib
parents:
diff changeset
65 }
223b71206888 Initial import
thib
parents:
diff changeset
66
223b71206888 Initial import
thib
parents:
diff changeset
67 static unsigned int
223b71206888 Initial import
thib
parents:
diff changeset
68 font_glyph_fn_codeconv_euc_to_jis(unsigned int euc)
223b71206888 Initial import
thib
parents:
diff changeset
69 {
223b71206888 Initial import
thib
parents:
diff changeset
70 unsigned int h, l;
223b71206888 Initial import
thib
parents:
diff changeset
71
223b71206888 Initial import
thib
parents:
diff changeset
72 h = (euc >> 8) & 0xff;
223b71206888 Initial import
thib
parents:
diff changeset
73 l = euc & 0xff;
223b71206888 Initial import
thib
parents:
diff changeset
74
223b71206888 Initial import
thib
parents:
diff changeset
75 if (h < 0x81) {
223b71206888 Initial import
thib
parents:
diff changeset
76 l = h;
223b71206888 Initial import
thib
parents:
diff changeset
77 h = 0;
223b71206888 Initial import
thib
parents:
diff changeset
78 } else if (l == 0x8e)
223b71206888 Initial import
thib
parents:
diff changeset
79 h = 0;
223b71206888 Initial import
thib
parents:
diff changeset
80 else {
223b71206888 Initial import
thib
parents:
diff changeset
81 h -= 0x80;
223b71206888 Initial import
thib
parents:
diff changeset
82 l -= 0x80;
223b71206888 Initial import
thib
parents:
diff changeset
83 }
223b71206888 Initial import
thib
parents:
diff changeset
84
223b71206888 Initial import
thib
parents:
diff changeset
85 return (h << 8) | l;
223b71206888 Initial import
thib
parents:
diff changeset
86 }
223b71206888 Initial import
thib
parents:
diff changeset
87
223b71206888 Initial import
thib
parents:
diff changeset
88 bool
223b71206888 Initial import
thib
parents:
diff changeset
89 PeerFn::GlyphCreate(unsigned int code, Glyph* glyph)
223b71206888 Initial import
thib
parents:
diff changeset
90 {
223b71206888 Initial import
thib
parents:
diff changeset
91 unsigned char *p1, *p2;
223b71206888 Initial import
thib
parents:
diff changeset
92 unsigned int h, l, offset;
223b71206888 Initial import
thib
parents:
diff changeset
93 int x, y;
223b71206888 Initial import
thib
parents:
diff changeset
94
223b71206888 Initial import
thib
parents:
diff changeset
95 l = font_glyph_fn_codeconv_euc_to_jis(code);
223b71206888 Initial import
thib
parents:
diff changeset
96 l -= 0x2121;
223b71206888 Initial import
thib
parents:
diff changeset
97 h = l >> 8;
223b71206888 Initial import
thib
parents:
diff changeset
98 l &= 0xff;
223b71206888 Initial import
thib
parents:
diff changeset
99 offset = (h * 0x5e + l) * 12 * 24;
223b71206888 Initial import
thib
parents:
diff changeset
100 if (offset > FN_DAT_SIZE - 12 * 24)
223b71206888 Initial import
thib
parents:
diff changeset
101 offset = 0;
223b71206888 Initial import
thib
parents:
diff changeset
102
223b71206888 Initial import
thib
parents:
diff changeset
103 glyph->bitmap_left = 0;
223b71206888 Initial import
thib
parents:
diff changeset
104 glyph->bitmap_top = 21;
223b71206888 Initial import
thib
parents:
diff changeset
105 glyph->bitmap.width = 24;
223b71206888 Initial import
thib
parents:
diff changeset
106 glyph->bitmap.rows = 24;
223b71206888 Initial import
thib
parents:
diff changeset
107
223b71206888 Initial import
thib
parents:
diff changeset
108 #if 0
223b71206888 Initial import
thib
parents:
diff changeset
109 glyph->metrics.ascender = private->vsize - 4;
223b71206888 Initial import
thib
parents:
diff changeset
110 glyph->metrics.descender = -4;
223b71206888 Initial import
thib
parents:
diff changeset
111 #endif
223b71206888 Initial import
thib
parents:
diff changeset
112 glyph->advance.x = 24 + 1;
223b71206888 Initial import
thib
parents:
diff changeset
113 glyph->advance.y = 24 + 1;
223b71206888 Initial import
thib
parents:
diff changeset
114
223b71206888 Initial import
thib
parents:
diff changeset
115 glyph->bitmap.buffer = new unsigned char[24*24];
223b71206888 Initial import
thib
parents:
diff changeset
116
223b71206888 Initial import
thib
parents:
diff changeset
117 p1 = glyph->bitmap.buffer;
223b71206888 Initial import
thib
parents:
diff changeset
118 p2 = buffer + offset;
223b71206888 Initial import
thib
parents:
diff changeset
119 for (y = 0; y < 24; y++) {
223b71206888 Initial import
thib
parents:
diff changeset
120 for (x = 0; x < 12; x++) {
223b71206888 Initial import
thib
parents:
diff changeset
121 unsigned char c = ~*p2++;
223b71206888 Initial import
thib
parents:
diff changeset
122 unsigned char c1;
223b71206888 Initial import
thib
parents:
diff changeset
123 c1 = (c) & 0x0f; *p1++ = (c1<<4) | c1;
223b71206888 Initial import
thib
parents:
diff changeset
124 c1 = (c>>4)& 0x0f; *p1++ = (c1<<4) | c1;
223b71206888 Initial import
thib
parents:
diff changeset
125 }
223b71206888 Initial import
thib
parents:
diff changeset
126 }
223b71206888 Initial import
thib
parents:
diff changeset
127 return true;
223b71206888 Initial import
thib
parents:
diff changeset
128 }
223b71206888 Initial import
thib
parents:
diff changeset
129
223b71206888 Initial import
thib
parents:
diff changeset
130 } /* end of namespace XKFont */