Mercurial > otakunoraifu
diff 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 |
line wrap: on
line diff
--- a/font/font_peer_fn.cc +++ b/font/font_peer_fn.cc @@ -34,6 +34,7 @@ using namespace std; +#include "codeconv.h" #include "font.h" #include "font_peer.h" @@ -43,20 +44,20 @@ namespace XKFont { PeerFn::PeerFn(const char *name, int index, int hsize, int vsize) : buffer(0) { - FILE *fp = 0; + FILE *fp = 0; - buffer = new unsigned char[FN_DAT_SIZE]; - fp = fopen(name, "rb"); - if (!fp) { - delete[] buffer; - buffer = 0; - string err = string("XKFont::PeerFn::PeerFn : Cannot open font file ")+name; - throw std::invalid_argument(err); - } - fread(buffer, 1, FN_DAT_SIZE, fp); - fclose(fp); - - return; + buffer = new unsigned char[FN_DAT_SIZE]; + fp = fopen(name, "rb"); + if (!fp) { + delete[] buffer; + buffer = 0; + string err = string("XKFont::PeerFn::PeerFn : Cannot open font file ")+name; + throw std::invalid_argument(err); + } + fread(buffer, 1, FN_DAT_SIZE, fp); + fclose(fp); + + return; } @@ -64,67 +65,48 @@ PeerFn::~PeerFn() { delete[] buffer; } -static unsigned int -font_glyph_fn_codeconv_euc_to_jis(unsigned int euc) -{ - unsigned int h, l; - - h = (euc >> 8) & 0xff; - l = euc & 0xff; - - if (h < 0x81) { - l = h; - h = 0; - } else if (l == 0x8e) - h = 0; - else { - h -= 0x80; - l -= 0x80; - } - - return (h << 8) | l; -} - bool PeerFn::GlyphCreate(unsigned int code, Glyph* glyph) { - unsigned char *p1, *p2; - unsigned int h, l, offset; - int x, y; + unsigned char *p1, *p2; + unsigned int h, l, offset; + int x, y; - l = font_glyph_fn_codeconv_euc_to_jis(code); - l -= 0x2121; - h = l >> 8; - l &= 0xff; - offset = (h * 0x5e + l) * 12 * 24; - if (offset > FN_DAT_SIZE - 12 * 24) - offset = 0; + l = codeconv_euc_to_jis(code); + l -= 0x2121; + h = l >> 8; + l &= 0xff; + offset = (h * 0x5e + l) * 12 * 24; + if (offset > FN_DAT_SIZE - 12 * 24) + offset = 0; - glyph->bitmap_left = 0; - glyph->bitmap_top = 21; - glyph->bitmap.width = 24; - glyph->bitmap.rows = 24; + glyph->bitmap_left = 0; + glyph->bitmap_top = 21; + glyph->bitmap.width = 24; + glyph->bitmap.rows = 24; #if 0 - glyph->metrics.ascender = private->vsize - 4; - glyph->metrics.descender = -4; + glyph->metrics.ascender = private->vsize - 4; + glyph->metrics.descender = -4; #endif - glyph->advance.x = 24 + 1; - glyph->advance.y = 24 + 1; + glyph->advance.x = 24 + 1; + glyph->advance.y = 24 + 1; - glyph->bitmap.buffer = new unsigned char[24*24]; + glyph->bitmap.buffer = new unsigned char[24*24]; - p1 = glyph->bitmap.buffer; - p2 = buffer + offset; - for (y = 0; y < 24; y++) { - for (x = 0; x < 12; x++) { - unsigned char c = ~*p2++; - unsigned char c1; - c1 = (c) & 0x0f; *p1++ = (c1<<4) | c1; - c1 = (c>>4)& 0x0f; *p1++ = (c1<<4) | c1; - } - } - return true; + p1 = glyph->bitmap.buffer; + p2 = buffer + offset; + for (y = 0; y < 24; y++) { + for (x = 0; x < 12; x++) { + unsigned char c = ~*p2++; + unsigned char c1; + c1 = (c) & 0x0f; + *p1++ = (c1<<4) | c1; + c1 = (c>>4)& 0x0f; + *p1++ = (c1<<4) | c1; + } + } + return true; } } /* end of namespace XKFont */