annotate font/font_peer_fn.cc @ 56:c7bcc0ec2267

* replaced Grp and Text classes by the TextImpl and GrpImpl ones * splitted scn2k.h into smaller header files * moved some definitions from scn2k_*.cc to the header files * moved opcode implementation to scn2k_*impl.cc
author thib
date Thu, 30 Apr 2009 19:05:09 +0000
parents 15a18fbe6f21
children
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
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 0
diff changeset
37 #include "codeconv.h"
0
223b71206888 Initial import
thib
parents:
diff changeset
38 #include "font.h"
223b71206888 Initial import
thib
parents:
diff changeset
39 #include "font_peer.h"
223b71206888 Initial import
thib
parents:
diff changeset
40
223b71206888 Initial import
thib
parents:
diff changeset
41 namespace XKFont {
223b71206888 Initial import
thib
parents:
diff changeset
42
223b71206888 Initial import
thib
parents:
diff changeset
43 #define FN_DAT_SIZE 2544768
223b71206888 Initial import
thib
parents:
diff changeset
44
223b71206888 Initial import
thib
parents:
diff changeset
45 PeerFn::PeerFn(const char *name, int index, int hsize, int vsize) : buffer(0)
223b71206888 Initial import
thib
parents:
diff changeset
46 {
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 0
diff changeset
47 FILE *fp = 0;
0
223b71206888 Initial import
thib
parents:
diff changeset
48
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 0
diff changeset
49 buffer = new unsigned char[FN_DAT_SIZE];
15a18fbe6f21 * Known bugs added to the README
thib
parents: 0
diff changeset
50 fp = fopen(name, "rb");
15a18fbe6f21 * Known bugs added to the README
thib
parents: 0
diff changeset
51 if (!fp) {
15a18fbe6f21 * Known bugs added to the README
thib
parents: 0
diff changeset
52 delete[] buffer;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 0
diff changeset
53 buffer = 0;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 0
diff changeset
54 string err = string("XKFont::PeerFn::PeerFn : Cannot open font file ")+name;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 0
diff changeset
55 throw std::invalid_argument(err);
15a18fbe6f21 * Known bugs added to the README
thib
parents: 0
diff changeset
56 }
15a18fbe6f21 * Known bugs added to the README
thib
parents: 0
diff changeset
57 fread(buffer, 1, FN_DAT_SIZE, fp);
15a18fbe6f21 * Known bugs added to the README
thib
parents: 0
diff changeset
58 fclose(fp);
15a18fbe6f21 * Known bugs added to the README
thib
parents: 0
diff changeset
59
15a18fbe6f21 * Known bugs added to the README
thib
parents: 0
diff changeset
60 return;
0
223b71206888 Initial import
thib
parents:
diff changeset
61 }
223b71206888 Initial import
thib
parents:
diff changeset
62
223b71206888 Initial import
thib
parents:
diff changeset
63
223b71206888 Initial import
thib
parents:
diff changeset
64 PeerFn::~PeerFn() {
223b71206888 Initial import
thib
parents:
diff changeset
65 delete[] buffer;
223b71206888 Initial import
thib
parents:
diff changeset
66 }
223b71206888 Initial import
thib
parents:
diff changeset
67
223b71206888 Initial import
thib
parents:
diff changeset
68 bool
223b71206888 Initial import
thib
parents:
diff changeset
69 PeerFn::GlyphCreate(unsigned int code, Glyph* glyph)
223b71206888 Initial import
thib
parents:
diff changeset
70 {
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 0
diff changeset
71 unsigned char *p1, *p2;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 0
diff changeset
72 unsigned int h, l, offset;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 0
diff changeset
73 int x, y;
0
223b71206888 Initial import
thib
parents:
diff changeset
74
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 0
diff changeset
75 l = codeconv_euc_to_jis(code);
15a18fbe6f21 * Known bugs added to the README
thib
parents: 0
diff changeset
76 l -= 0x2121;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 0
diff changeset
77 h = l >> 8;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 0
diff changeset
78 l &= 0xff;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 0
diff changeset
79 offset = (h * 0x5e + l) * 12 * 24;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 0
diff changeset
80 if (offset > FN_DAT_SIZE - 12 * 24)
15a18fbe6f21 * Known bugs added to the README
thib
parents: 0
diff changeset
81 offset = 0;
0
223b71206888 Initial import
thib
parents:
diff changeset
82
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 0
diff changeset
83 glyph->bitmap_left = 0;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 0
diff changeset
84 glyph->bitmap_top = 21;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 0
diff changeset
85 glyph->bitmap.width = 24;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 0
diff changeset
86 glyph->bitmap.rows = 24;
0
223b71206888 Initial import
thib
parents:
diff changeset
87
223b71206888 Initial import
thib
parents:
diff changeset
88 #if 0
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 0
diff changeset
89 glyph->metrics.ascender = private->vsize - 4;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 0
diff changeset
90 glyph->metrics.descender = -4;
0
223b71206888 Initial import
thib
parents:
diff changeset
91 #endif
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 0
diff changeset
92 glyph->advance.x = 24 + 1;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 0
diff changeset
93 glyph->advance.y = 24 + 1;
0
223b71206888 Initial import
thib
parents:
diff changeset
94
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 0
diff changeset
95 glyph->bitmap.buffer = new unsigned char[24*24];
0
223b71206888 Initial import
thib
parents:
diff changeset
96
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 0
diff changeset
97 p1 = glyph->bitmap.buffer;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 0
diff changeset
98 p2 = buffer + offset;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 0
diff changeset
99 for (y = 0; y < 24; y++) {
15a18fbe6f21 * Known bugs added to the README
thib
parents: 0
diff changeset
100 for (x = 0; x < 12; x++) {
15a18fbe6f21 * Known bugs added to the README
thib
parents: 0
diff changeset
101 unsigned char c = ~*p2++;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 0
diff changeset
102 unsigned char c1;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 0
diff changeset
103 c1 = (c) & 0x0f;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 0
diff changeset
104 *p1++ = (c1<<4) | c1;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 0
diff changeset
105 c1 = (c>>4)& 0x0f;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 0
diff changeset
106 *p1++ = (c1<<4) | c1;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 0
diff changeset
107 }
15a18fbe6f21 * Known bugs added to the README
thib
parents: 0
diff changeset
108 }
15a18fbe6f21 * Known bugs added to the README
thib
parents: 0
diff changeset
109 return true;
0
223b71206888 Initial import
thib
parents:
diff changeset
110 }
223b71206888 Initial import
thib
parents:
diff changeset
111
223b71206888 Initial import
thib
parents:
diff changeset
112 } /* end of namespace XKFont */