1 /* ScummVM - Graphic Adventure Engine
3 * ScummVM is the legal property of its developers, whose names
4 * are too numerous to list here. Please refer to the COPYRIGHT
5 * file distributed with this source distribution.
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 #include "graphics/sjis.h"
27 #ifdef GRAPHICS_SJIS_H
29 #include "common/debug.h"
30 #include "common/archive.h"
31 #include "common/endian.h"
35 FontSJIS
*FontSJIS::createFont(const Common::Platform platform
) {
38 // Try the font ROM of the specified platform
39 if (platform
== Common::kPlatformFMTowns
) {
40 ret
= new FontTowns();
41 if (ret
&& ret
->loadData())
46 // Try ScummVM's font.
47 ret
= new FontSjisSVM();
48 if (ret
&& ret
->loadData())
55 template<typename Color
>
56 void FontSJIS16x16::drawCharInternOutline(const uint16
*glyph
, uint8
*dst
, int pitch
, Color c1
, Color c2
) const {
57 uint32 outlineGlyph
[18];
58 memset(outlineGlyph
, 0, sizeof(outlineGlyph
));
60 // Create an outline map including the original character
61 const uint16
*src
= glyph
;
62 for (int i
= 0; i
< 16; ++i
) {
64 line
= (line
<< 2) | (line
<< 1) | (line
<< 0);
66 outlineGlyph
[i
+ 0] |= line
;
67 outlineGlyph
[i
+ 1] |= line
;
68 outlineGlyph
[i
+ 2] |= line
;
72 for (int y
= 0; y
< 18; ++y
) {
73 Color
*lineBuf
= (Color
*)dstLine
;
74 uint32 line
= outlineGlyph
[y
];
76 for (int x
= 0; x
< 18; ++x
) {
86 // draw the original char
87 drawCharIntern
<Color
>(glyph
, dst
+ pitch
+ 1, pitch
, c1
);
90 template<typename Color
>
91 void FontSJIS16x16::drawCharIntern(const uint16
*glyph
, uint8
*dst
, int pitch
, Color c1
) const {
92 for (int y
= 0; y
< 16; ++y
) {
93 Color
*lineBuf
= (Color
*)dst
;
94 uint16 line
= *glyph
++;
96 for (int x
= 0; x
< 16; ++x
) {
107 void FontSJIS16x16::drawChar(void *dst
, uint16 ch
, int pitch
, int bpp
, uint32 c1
, uint32 c2
) const {
108 const uint16
*glyphSource
= getCharData(ch
);
110 warning("FontSJIS16x16::drawChar: Font does not offer data for %02X %02X", ch
& 0xFF, ch
>> 8);
115 if (!_outlineEnabled
)
116 drawCharIntern
<uint8
>(glyphSource
, (uint8
*)dst
, pitch
, c1
);
118 drawCharInternOutline
<uint8
>(glyphSource
, (uint8
*)dst
, pitch
, c1
, c2
);
119 } else if (bpp
== 2) {
120 if (!_outlineEnabled
)
121 drawCharIntern
<uint16
>(glyphSource
, (uint8
*)dst
, pitch
, c1
);
123 drawCharInternOutline
<uint16
>(glyphSource
, (uint8
*)dst
, pitch
, c1
, c2
);
125 error("FontTowns::drawChar: unsupported bpp: %d", bpp
);
131 bool FontTowns::loadData() {
132 Common::SeekableReadStream
*data
= SearchMan
.createReadStreamForMember("FMT_FNT.ROM");
136 for (uint i
= 0; i
< (kFontRomSize
/ 2); ++i
)
137 _fontData
[i
] = data
->readUint16BE();
139 bool retValue
= !data
->err();
144 const uint16
*FontTowns::getCharData(uint16 ch
) const {
148 // copied from scumm\charset.cpp
155 int base
= s
- ((s
+ 1) % 32);
156 int c
= 0, p
= 0, chunk_f
= 0, chunk
= 0, cr
= 0, kanjiType
= KANA
;
158 if (f
>= 0x81 && f
<= 0x84) kanjiType
= KANA
;
159 if (f
>= 0x88 && f
<= 0x9f) kanjiType
= KANJI
;
160 if (f
>= 0xe0 && f
<= 0xea) kanjiType
= EKANJI
;
162 if ((f
> 0xe8 || (f
== 0xe8 && base
>= 0x9f)) || (f
> 0x90 || (f
== 0x90 && base
>= 0x9f))) {
167 if (kanjiType
== KANA
) {//Kana
168 chunk_f
= (f
- 0x81) * 2;
169 } else if (kanjiType
== KANJI
) {//Standard Kanji
172 } else if (kanjiType
== EKANJI
) {//Enhanced Kanji
178 if (base
== 0x7f && s
== 0x7f)
180 if (base
== 0x9f && s
== 0xbe)
182 if (base
== 0xbf && s
== 0xde)
184 //if (base == 0x7f && s == 0x9e)
190 if (kanjiType
== KANA
) chunk
= 1;
191 else if (kanjiType
== KANJI
) chunk
= 31;
192 else if (kanjiType
== EKANJI
) chunk
= 111;
196 if (kanjiType
== KANA
) chunk
= 17;
197 else if (kanjiType
== KANJI
) chunk
= 47;
198 else if (kanjiType
== EKANJI
) chunk
= 127;
202 if (kanjiType
== KANA
) chunk
= 9;
203 else if (kanjiType
== KANJI
) chunk
= 63;
204 else if (kanjiType
== EKANJI
) chunk
= 143;
208 if (kanjiType
== KANA
) chunk
= 2;
209 else if (kanjiType
== KANJI
) chunk
= 32;
210 else if (kanjiType
== EKANJI
) chunk
= 112;
214 if (kanjiType
== KANA
) chunk
= 18;
215 else if (kanjiType
== KANJI
) chunk
= 48;
216 else if (kanjiType
== EKANJI
) chunk
= 128;
220 if (kanjiType
== KANA
) chunk
= 10;
221 else if (kanjiType
== KANJI
) chunk
= 64;
222 else if (kanjiType
== EKANJI
) chunk
= 144;
225 debug(4, "Invalid Char! f %x s %x base %x c %d p %d", f
, s
, base
, c
, p
);
228 debug(6, "Kanji: %c%c f 0x%x s 0x%x base 0x%x c %d p %d chunk %d cr %d index %d", f
, s
, f
, s
, base
, c
, p
, chunk
, cr
, ((chunk_f
+ chunk
) * 32 + (s
- base
)) + cr
);
229 return _fontData
+ (((chunk_f
+ chunk
) * 32 + (s
- base
)) + cr
) * 16;
234 bool FontSjisSVM::loadData() {
235 Common::SeekableReadStream
*data
= SearchMan
.createReadStreamForMember("SJIS.FNT");
239 uint32 magic1
= data
->readUint32BE();
240 uint32 magic2
= data
->readUint32BE();
242 if (magic1
!= MKID_BE('SCVM') || magic2
!= MKID_BE('SJIS')) {
247 uint32 version
= data
->readUint32BE();
252 uint numChars
= data
->readUint16BE();
254 _fontData
= new uint16
[numChars
* 16];
257 for (uint i
= 0; i
< numChars
* 16; ++i
)
258 _fontData
[i
] = data
->readUint16BE();
260 bool retValue
= !data
->err();
265 const uint16
*FontSjisSVM::getCharData(uint16 c
) const {
266 const uint8 fB
= c
& 0xFF;
267 const uint8 sB
= c
>> 8;
269 // We only allow 2 byte SJIS characters.
270 if (fB
<= 0x80 || fB
>= 0xF0 || (fB
>= 0xA0 && fB
<= 0xDF) || sB
== 0x7F)
283 return _fontData
+ (base
* 0xBC + index
) * 16;
286 } // end of namespace Graphics
288 #endif // defined(GRAPHICS_SJIS_H)