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