GRAPHICS: Cleanup SJIS font code a bit.
This commit is contained in:
parent
173db53e4b
commit
c047f871d6
2 changed files with 184 additions and 143 deletions
|
@ -58,6 +58,43 @@ void FontSJIS::drawChar(Graphics::Surface &dst, uint16 ch, int x, int y, uint32
|
||||||
drawChar(dst.getBasePtr(x, y), ch, dst.pitch, dst.format.bytesPerPixel, c1, c2, dst.w - x, dst.h - y);
|
drawChar(dst.getBasePtr(x, y), ch, dst.pitch, dst.format.bytesPerPixel, c1, c2, dst.w - x, dst.h - y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FontSJISBase::FontSJISBase() : _drawMode(kDefaultMode), _flippedMode(false) {
|
||||||
|
}
|
||||||
|
|
||||||
|
void FontSJISBase::setDrawingMode(DrawingMode mode) {
|
||||||
|
_drawMode = mode;
|
||||||
|
}
|
||||||
|
|
||||||
|
void FontSJISBase::toggleFlippedMode(bool enable) {
|
||||||
|
_flippedMode = enable;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint FontSJISBase::getFontHeight() const {
|
||||||
|
switch (_drawMode) {
|
||||||
|
case kOutlineMode:
|
||||||
|
return 18;
|
||||||
|
|
||||||
|
case kDefaultMode:
|
||||||
|
return 16;
|
||||||
|
|
||||||
|
default:
|
||||||
|
return 17;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
uint FontSJISBase::getMaxFontWidth() const {
|
||||||
|
switch (_drawMode) {
|
||||||
|
case kOutlineMode:
|
||||||
|
return 18;
|
||||||
|
|
||||||
|
case kDefaultMode:
|
||||||
|
return 16;
|
||||||
|
|
||||||
|
default:
|
||||||
|
return 17;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
template<typename Color>
|
template<typename Color>
|
||||||
void FontSJISBase::blitCharacter(const uint8 *glyph, const int w, const int h, uint8 *dst, int pitch, Color c) const {
|
void FontSJISBase::blitCharacter(const uint8 *glyph, const int w, const int h, uint8 *dst, int pitch, Color c) const {
|
||||||
for (int y = 0; y < h; ++y) {
|
for (int y = 0; y < h; ++y) {
|
||||||
|
@ -131,6 +168,9 @@ const uint8 *FontSJISBase::flipCharacter(const uint8 *glyph, const int w) const
|
||||||
0x0F, 0x8F, 0x4F, 0xC7, 0x2F, 0xAF, 0x6F, 0xEF, 0x1F, 0x97, 0x5F, 0xDF, 0x3F, 0xBF, 0x7F, 0xFF
|
0x0F, 0x8F, 0x4F, 0xC7, 0x2F, 0xAF, 0x6F, 0xEF, 0x1F, 0x97, 0x5F, 0xDF, 0x3F, 0xBF, 0x7F, 0xFF
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// TODO: This code looks like it will only work with 16 pixel wide
|
||||||
|
// characters we should really take care that we only call it on these
|
||||||
|
// or we fix this to support a generic width.
|
||||||
for (int i = 0; i < w; i++) {
|
for (int i = 0; i < w; i++) {
|
||||||
_tempGlyph[i] = flipData[glyph[(w * 2 - 1) - i]];
|
_tempGlyph[i] = flipData[glyph[(w * 2 - 1) - i]];
|
||||||
_tempGlyph[(w * 2 - 1) - i] = flipData[glyph[i]];
|
_tempGlyph[(w * 2 - 1) - i] = flipData[glyph[i]];
|
||||||
|
@ -146,8 +186,8 @@ void FontSJISBase::drawChar(void *dst, uint16 ch, int pitch, int bpp, uint32 c1,
|
||||||
int outlineExtraWidth = 2, outlineExtraHeight = 2;
|
int outlineExtraWidth = 2, outlineExtraHeight = 2;
|
||||||
int outlineXOffset = 0, outlineYOffset = 0;
|
int outlineXOffset = 0, outlineYOffset = 0;
|
||||||
|
|
||||||
if (is8x16(ch)) {
|
if (isASCII(ch)) {
|
||||||
glyphSource = getCharData8x16(ch);
|
glyphSource = getCharData(ch);
|
||||||
width = 8;
|
width = 8;
|
||||||
height = 16;
|
height = 16;
|
||||||
} else {
|
} else {
|
||||||
|
@ -177,6 +217,9 @@ void FontSJISBase::drawChar(void *dst, uint16 ch, int pitch, int bpp, uint32 c1,
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef DISABLE_FLIPPED_MODE
|
#ifndef DISABLE_FLIPPED_MODE
|
||||||
|
// TODO: This code inside flopCharater looks like it will only work with
|
||||||
|
// 16 pixel wide characters we should really take care that we only call
|
||||||
|
// it on these or we fix it to support a generic width.
|
||||||
if (_flippedMode)
|
if (_flippedMode)
|
||||||
glyphSource = flipCharacter(glyphSource, width);
|
glyphSource = flipCharacter(glyphSource, width);
|
||||||
#endif
|
#endif
|
||||||
|
@ -221,13 +264,13 @@ void FontSJISBase::drawChar(void *dst, uint16 ch, int pitch, int bpp, uint32 c1,
|
||||||
}
|
}
|
||||||
|
|
||||||
uint FontSJISBase::getCharWidth(uint16 ch) const {
|
uint FontSJISBase::getCharWidth(uint16 ch) const {
|
||||||
if (is8x16(ch))
|
if (isASCII(ch))
|
||||||
return (_drawMode == kOutlineMode) ? 10 : (_drawMode == kDefaultMode ? 8 : 9);
|
return (_drawMode == kOutlineMode) ? 10 : (_drawMode == kDefaultMode ? 8 : 9);
|
||||||
else
|
else
|
||||||
return getMaxFontWidth();
|
return getMaxFontWidth();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FontSJISBase::is8x16(uint16 ch) const {
|
bool FontSJISBase::isASCII(uint16 ch) const {
|
||||||
if (ch >= 0xFF)
|
if (ch >= 0xFF)
|
||||||
return false;
|
return false;
|
||||||
else if (ch <= 0x7F || (ch >= 0xA1 && ch <= 0xDF))
|
else if (ch <= 0x7F || (ch >= 0xA1 && ch <= 0xDF))
|
||||||
|
@ -253,6 +296,9 @@ bool FontTowns::loadData() {
|
||||||
}
|
}
|
||||||
|
|
||||||
const uint8 *FontTowns::getCharData(uint16 ch) const {
|
const uint8 *FontTowns::getCharData(uint16 ch) const {
|
||||||
|
if (ch < kFont8x16Chars) {
|
||||||
|
return _fontData8x16 + ch * 16;
|
||||||
|
} else {
|
||||||
uint8 f = ch & 0xFF;
|
uint8 f = ch & 0xFF;
|
||||||
uint8 s = ch >> 8;
|
uint8 s = ch >> 8;
|
||||||
|
|
||||||
|
@ -342,16 +388,20 @@ const uint8 *FontTowns::getCharData(uint16 ch) const {
|
||||||
return 0;
|
return 0;
|
||||||
else
|
else
|
||||||
return _fontData16x16 + chunkNum * 32;
|
return _fontData16x16 + chunkNum * 32;
|
||||||
}
|
}
|
||||||
|
|
||||||
const uint8 *FontTowns::getCharData8x16(uint16 c) const {
|
|
||||||
if (c >= kFont8x16Chars)
|
|
||||||
return 0;
|
|
||||||
return _fontData8x16 + c * 16;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ScummVM SJIS font
|
// ScummVM SJIS font
|
||||||
|
|
||||||
|
FontSjisSVM::FontSjisSVM()
|
||||||
|
: _fontData16x16(0), _fontData16x16Size(0), _fontData8x16(0), _fontData8x16Size(0) {
|
||||||
|
}
|
||||||
|
|
||||||
|
FontSjisSVM::~FontSjisSVM() {
|
||||||
|
delete[] _fontData16x16;
|
||||||
|
delete[] _fontData8x16;
|
||||||
|
}
|
||||||
|
|
||||||
bool FontSjisSVM::loadData() {
|
bool FontSjisSVM::loadData() {
|
||||||
Common::SeekableReadStream *data = SearchMan.createReadStreamForMember("SJIS.FNT");
|
Common::SeekableReadStream *data = SearchMan.createReadStreamForMember("SJIS.FNT");
|
||||||
if (!data)
|
if (!data)
|
||||||
|
@ -393,6 +443,17 @@ const uint8 *FontSjisSVM::getCharData(uint16 c) const {
|
||||||
const uint8 fB = c & 0xFF;
|
const uint8 fB = c & 0xFF;
|
||||||
const uint8 sB = c >> 8;
|
const uint8 sB = c >> 8;
|
||||||
|
|
||||||
|
if (isASCII(c)) {
|
||||||
|
int index = fB;
|
||||||
|
|
||||||
|
// half-width katakana
|
||||||
|
if (fB >= 0xA1 && fB <= 0xDF)
|
||||||
|
index -= 0x21;
|
||||||
|
|
||||||
|
const uint offset = index * 16;
|
||||||
|
assert(offset <= _fontData8x16Size);
|
||||||
|
return _fontData8x16 + offset;
|
||||||
|
} else {
|
||||||
// We only allow 2 byte SJIS characters.
|
// We only allow 2 byte SJIS characters.
|
||||||
if (fB <= 0x80 || fB >= 0xF0 || (fB >= 0xA0 && fB <= 0xDF) || sB == 0x7F)
|
if (fB <= 0x80 || fB >= 0xF0 || (fB >= 0xA0 && fB <= 0xDF) || sB == 0x7F)
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -415,24 +476,7 @@ const uint8 *FontSjisSVM::getCharData(uint16 c) const {
|
||||||
const uint offset = (base * 0xBC + index) * 32;
|
const uint offset = (base * 0xBC + index) * 32;
|
||||||
assert(offset + 16 <= _fontData16x16Size);
|
assert(offset + 16 <= _fontData16x16Size);
|
||||||
return _fontData16x16 + offset;
|
return _fontData16x16 + offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
const uint8 *FontSjisSVM::getCharData8x16(uint16 c) const {
|
|
||||||
const uint8 fB = c & 0xFF;
|
|
||||||
const uint8 sB = c >> 8;
|
|
||||||
|
|
||||||
if (!is8x16(c) || sB)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
int index = fB;
|
|
||||||
|
|
||||||
// half-width katakana
|
|
||||||
if (fB >= 0xA1 && fB <= 0xDF)
|
|
||||||
index -= 0x21;
|
|
||||||
|
|
||||||
const uint offset = index * 16;
|
|
||||||
assert(offset <= _fontData8x16Size);
|
|
||||||
return _fontData8x16 + offset;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // End of namespace Graphics
|
} // End of namespace Graphics
|
||||||
|
|
|
@ -134,19 +134,19 @@ public:
|
||||||
*/
|
*/
|
||||||
class FontSJISBase : public FontSJIS {
|
class FontSJISBase : public FontSJIS {
|
||||||
public:
|
public:
|
||||||
FontSJISBase() : _drawMode(kDefaultMode), _flippedMode(false) {}
|
FontSJISBase();
|
||||||
|
|
||||||
void setDrawingMode(DrawingMode mode) { _drawMode = mode; }
|
virtual void setDrawingMode(DrawingMode mode);
|
||||||
|
|
||||||
void toggleFlippedMode(bool enable) { _flippedMode = enable; }
|
virtual void toggleFlippedMode(bool enable);
|
||||||
|
|
||||||
uint getFontHeight() const { return (_drawMode == kOutlineMode) ? 18 : (_drawMode == kDefaultMode ? 16 : 17); }
|
virtual uint getFontHeight() const;
|
||||||
|
|
||||||
uint getMaxFontWidth() const { return (_drawMode == kOutlineMode) ? 18 : (_drawMode == kDefaultMode ? 16 : 17); }
|
virtual uint getMaxFontWidth() const;
|
||||||
|
|
||||||
uint getCharWidth(uint16 ch) const;
|
virtual uint getCharWidth(uint16 ch) const;
|
||||||
|
|
||||||
void drawChar(void *dst, uint16 ch, int pitch, int bpp, uint32 c1, uint32 c2, int maxW = -1, int maxH = -1) const;
|
virtual void drawChar(void *dst, uint16 ch, int pitch, int bpp, uint32 c1, uint32 c2, int maxW = -1, int maxH = -1) const;
|
||||||
private:
|
private:
|
||||||
template<typename Color>
|
template<typename Color>
|
||||||
void blitCharacter(const uint8 *glyph, const int w, const int h, uint8 *dst, int pitch, Color c) const;
|
void blitCharacter(const uint8 *glyph, const int w, const int h, uint8 *dst, int pitch, Color c) const;
|
||||||
|
@ -162,10 +162,9 @@ protected:
|
||||||
DrawingMode _drawMode;
|
DrawingMode _drawMode;
|
||||||
bool _flippedMode;
|
bool _flippedMode;
|
||||||
|
|
||||||
bool is8x16(uint16 ch) const;
|
bool isASCII(uint16 ch) const;
|
||||||
|
|
||||||
virtual const uint8 *getCharData(uint16 c) const = 0;
|
virtual const uint8 *getCharData(uint16 c) const = 0;
|
||||||
virtual const uint8 *getCharData8x16(uint16 c) const = 0;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -188,8 +187,7 @@ private:
|
||||||
uint8 _fontData16x16[kFont16x16Chars * 32];
|
uint8 _fontData16x16[kFont16x16Chars * 32];
|
||||||
uint8 _fontData8x16[kFont8x16Chars * 32];
|
uint8 _fontData8x16[kFont8x16Chars * 32];
|
||||||
|
|
||||||
const uint8 *getCharData(uint16 c) const;
|
virtual const uint8 *getCharData(uint16 c) const;
|
||||||
const uint8 *getCharData8x16(uint16 c) const;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -197,8 +195,8 @@ private:
|
||||||
*/
|
*/
|
||||||
class FontSjisSVM : public FontSJISBase {
|
class FontSjisSVM : public FontSJISBase {
|
||||||
public:
|
public:
|
||||||
FontSjisSVM() : _fontData16x16(0), _fontData16x16Size(0), _fontData8x16(0), _fontData8x16Size(0) {}
|
FontSjisSVM();
|
||||||
~FontSjisSVM() { delete[] _fontData16x16; delete[] _fontData8x16; }
|
~FontSjisSVM();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load the font data from "SJIS.FNT".
|
* Load the font data from "SJIS.FNT".
|
||||||
|
@ -211,8 +209,7 @@ private:
|
||||||
uint8 *_fontData8x16;
|
uint8 *_fontData8x16;
|
||||||
uint _fontData8x16Size;
|
uint _fontData8x16Size;
|
||||||
|
|
||||||
const uint8 *getCharData(uint16 c) const;
|
virtual const uint8 *getCharData(uint16 c) const;
|
||||||
const uint8 *getCharData8x16(uint16 c) const;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// TODO: Consider adding support for PC98 ROM
|
// TODO: Consider adding support for PC98 ROM
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue