Initial commit

This commit is contained in:
2026-02-02 04:50:13 +01:00
commit 5b11698731
22592 changed files with 7677434 additions and 0 deletions

View File

@@ -0,0 +1,268 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "common/debug.h"
#include "common/file.h"
#include "graphics/managed_surface.h"
#include "cryomni3d/fonts/cryoextfont.h"
namespace CryOmni3D {
CryoExtFont::~CryoExtFont() {
delete _crf;
}
void CryoExtFont::load(const Common::Path &fontFile, Common::CodePage codepage) {
// For now only CP950 is supported
assert(codepage == Common::kWindows950);
_codepage = codepage;
Common::File *crf = new Common::File();
if (!crf->open(fontFile)) {
error("can't open file %s", fontFile.toString(Common::Path::kNativeSeparator).c_str());
}
_crf = crf;
byte magic[8];
_crf->read(magic, sizeof(magic));
if (memcmp(magic, "CRYOFONT", 8)) {
error("Invalid font magic");
}
// 3 unknown uint16
(void) _crf->readUint16BE();
(void) _crf->readUint16BE();
(void) _crf->readUint16BE();
_height = _crf->readSint16BE();
//debug("Max char height %d", _maxHeight);
_crf->read(_comment, sizeof(_comment));
//debug("Comment %s", _comment);
Common::String offsetsFile = fontFile.baseName();
offsetsFile.setChar('I', offsetsFile.size() - 1);
loadOffsets(fontFile.getParent().appendComponent(offsetsFile));
}
void CryoExtFont::loadOffsets(const Common::Path &offsetsFile) {
Common::File cri;
if (!cri.open(offsetsFile)) {
error("can't open file %s", offsetsFile.toString(Common::Path::kNativeSeparator).c_str());
}
uint32 counts = cri.size() / sizeof(uint32);
_offsets.reserve(counts);
debug("Loading %u offsets", counts);
for (; counts > 0; counts--) {
uint32 offset = cri.readUint32BE();
_offsets.push_back(offset);
}
}
void CryoExtFont::assureCached(uint32 chr) const {
if (_cache.contains(chr)) {
return;
}
uint32 glyphId = mapGlyph(chr);
if (glyphId >= _offsets.size()) {
warning("Invalid glyph id: %u", glyphId);
glyphId = 0;
}
uint32 offset = _offsets[glyphId];
_crf->seek(offset);
Glyph &glyph = _cache[chr];
uint16 h = _crf->readUint16BE();
uint16 w = _crf->readUint16BE();
uint sz = glyph.setup(w, h);
//debug("Char %u/%u sz %ux%u %u", chr, glyphId, w, h, sz);
glyph.offX = _crf->readSint16BE();
glyph.offY = _crf->readSint16BE();
glyph.advance = _crf->readUint16BE();
//debug("Char %u/%u offX %d offY %d PW %d", chr, glyphId, glyph.offX, glyph.offY, glyph.advance);
_crf->read(glyph.bitmap, sz);
//debug("Char %u/%u read %d", chr, glyphId, v);
if ((_cache.size() % 10) == 0) {
debug("Glyph cache size is now %u", _cache.size());
}
}
Common::Rect CryoExtFont::getBoundingBox(uint32 chr) const {
assureCached(chr);
const Glyph &glyph = _cache[chr];
return Common::Rect(glyph.offX, glyph.offY,
glyph.offX + glyph.w, glyph.offY + glyph.h);
}
int CryoExtFont::getCharWidth(uint32 chr) const {
assureCached(chr);
const Glyph &glyph = _cache[chr];
return glyph.advance;
}
void CryoExtFont::drawChar(Graphics::Surface *dst, uint32 chr, int x, int y, uint32 color) const {
assert(dst);
assert(dst->format.bytesPerPixel == 1 || dst->format.bytesPerPixel == 2 ||
dst->format.bytesPerPixel == 4);
assureCached(chr);
const Glyph &glyph = _cache[chr];
x += glyph.offX;
// In european versions of Versailles there was a -2 offset which is not present in Chinese one
// Maybe this offset should be checked when adding new games
y += glyph.offY + _height;
if (x > dst->w) {
return;
}
if (y > dst->h) {
return;
}
int w = glyph.w;
int h = glyph.h;
const uint8 *srcPos = (const uint8 *)glyph.bitmap;
const uint16 stride = (glyph.w + 7) / 8;
const uint16 originalWidth = glyph.w;
// Make sure we are not drawing outside the screen bounds
if (y < 0) {
// y is negative so srcPos will increase and h will decrease
srcPos -= y * stride;
h += y;
y = 0;
}
if (y + h > dst->h) {
h = dst->h - y;
}
if (h <= 0) {
return;
}
int jStart = 0;
if (x < 0) {
// x is negative so jStart will be positive and w will decrease
jStart = -x;
w += x;
x = 0;
}
if (x + w > dst->w) {
w = dst->w - x;
}
if (w <= 0) {
return;
}
const int jEnd = jStart + w - 1;
for (uint16 i = 0; i < h; i++) {
byte b = 0;
for (uint16 j = 0; j < originalWidth; j++) {
if ((j % 8) == 0) {
b = *(srcPos++);
}
if (j >= jStart && j <= jEnd && b & 0x80) {
if (dst->format.bytesPerPixel == 1) {
*((byte *)dst->getBasePtr(x + j, y + i)) = color;
} else if (dst->format.bytesPerPixel == 2) {
*((uint16 *)dst->getBasePtr(x + j, y + i)) = color;
} else if (dst->format.bytesPerPixel == 4) {
*((uint32 *)dst->getBasePtr(x + j, y + i)) = color;
}
}
b <<= 1;
}
}
}
uint32 CryoExtFont::mapGlyph(uint32 chr) const {
switch (_codepage) {
case Common::kWindows950:
/* Nothing more than 0xffff */
if (chr >> 16) {
return 0;
}
/* No glyph for non printable */
if (chr < 0x20) {
return 0;
}
/* ASCII characters : like in 8bits case, 0x60 ones */
if (chr < 0x80) {
return chr - 0x20;
}
/* Invalid ranges */
if (chr < 0x8000) {
return 0;
}
if ((chr & 0xff) < 0x40) {
return 0;
}
/* After the 0x60 ASCII characters
* a table of 0xC0 large (starting at 0x40) and
* 0x80 long (starting at 0x80) */
chr = 0xC0 * ((chr >> 8) - 0x80) + ((chr & 0xff) - 0x40) + 0x60;
return chr;
default:
error("Invalid encoding");
}
}
CryoExtFont::Glyph::Glyph() : h(0), w(0), offX(0), offY(0), advance(0), bitmap(nullptr) {
}
CryoExtFont::Glyph::~Glyph() {
delete[] bitmap;
}
uint CryoExtFont::Glyph::setup(uint16 width, uint16 height) {
w = width;
h = height;
uint sz = h * ((w + 7) / 8);
bitmap = new byte[sz];
return sz;
}
} // End of namespace CryOmni3D

View File

@@ -0,0 +1,87 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef CRYOMNI3D_FONTS_CRYOEXTFONT_H
#define CRYOMNI3D_FONTS_CRYOEXTFONT_H
#include "common/array.h"
#include "common/hashmap.h"
#include "common/str.h"
#include "graphics/font.h"
namespace Common {
class SeekableReadStream;
}
namespace CryOmni3D {
class CryoExtFont : public Graphics::Font {
public:
CryoExtFont() : _height(0), _maxAdvance(0), _crf(nullptr), _codepage(Common::kCodePageInvalid) { }
virtual ~CryoExtFont();
void load(const Common::Path &fontFile, Common::CodePage encoding);
virtual int getFontHeight() const { return _height; }
virtual int getMaxCharWidth() const { return _maxAdvance; }
virtual int getCharWidth(uint32 chr) const;
virtual Common::Rect getBoundingBox(uint32 chr) const;
virtual void drawChar(Graphics::Surface *dst, uint32 chr, int x, int y, uint32 color) const;
private:
void loadOffsets(const Common::Path &offsetsFile);
void assureCached(uint32 chr) const;
uint32 mapGlyph(uint32 chr) const;
struct Glyph {
uint16 h;
uint16 w;
int16 offX;
int16 offY;
uint16 advance;
byte *bitmap;
Glyph();
~Glyph();
uint setup(uint16 width, uint16 height);
};
uint16 _height;
uint16 _maxAdvance;
byte _comment[32];
Common::CodePage _codepage;
mutable Common::SeekableReadStream *_crf;
Common::Array<uint32> _offsets;
typedef Common::HashMap<uint32, Glyph> GlyphCache;
mutable GlyphCache _cache;
};
} // End of namespace CryOmni3D
#endif

View File

@@ -0,0 +1,185 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "common/debug.h"
#include "common/file.h"
#include "graphics/managed_surface.h"
#include "cryomni3d/fonts/cryofont.h"
namespace CryOmni3D {
void CryoFont::load(const Common::Path &fontFile) {
Common::File crf;
if (!crf.open(fontFile)) {
error("can't open file %s", fontFile.toString(Common::Path::kNativeSeparator).c_str());
}
byte magic[8];
crf.read(magic, sizeof(magic));
if (memcmp(magic, "CRYOFONT", 8)) {
error("Invalid font magic");
}
// 3 unknown uint16
(void) crf.readUint16BE();
(void) crf.readUint16BE();
(void) crf.readUint16BE();
_height = crf.readSint16BE();
//debug("Max char height %d", _maxHeight);
crf.read(_comment, sizeof(_comment));
//debug("Comment %s", _comment);
loadAll8bitGlyphs(crf);
}
void CryoFont::loadAll8bitGlyphs(Common::SeekableReadStream &font_fl) {
for (uint i = 0; i < k8bitCharactersCount; i++) {
// Cache maps a character to a glyph
Glyph &glyph = _glyphs[i];
uint16 h = font_fl.readUint16BE();
uint16 w = font_fl.readUint16BE();
uint sz = glyph.setup(w, h);
//debug("Char %d sz %dx%d %d", i, w, h, sz);
glyph.offX = font_fl.readSint16BE();
glyph.offY = font_fl.readSint16BE();
glyph.advance = font_fl.readUint16BE();
//debug("Char %d offX %d offY %d PW %d", i, glyph.offX, glyph.offY, glyph.advance);
font_fl.read(glyph.bitmap, sz);
//debug("Char %d read %d", i, v);
if (glyph.advance > _maxAdvance) {
_maxAdvance = glyph.advance;
}
}
}
Common::Rect CryoFont::getBoundingBox(uint32 chr) const {
const Glyph &glyph = _glyphs[mapGlyph(chr)];
return Common::Rect(glyph.offX, glyph.offY,
glyph.offX + glyph.w, glyph.offY + glyph.h);
}
int CryoFont::getCharWidth(uint32 chr) const {
const Glyph &glyph = _glyphs[mapGlyph(chr)];
return glyph.advance;
}
void CryoFont::drawChar(Graphics::Surface *dst, uint32 chr, int x, int y, uint32 color) const {
assert(dst);
assert(dst->format.bytesPerPixel == 1 || dst->format.bytesPerPixel == 2 ||
dst->format.bytesPerPixel == 4);
const Glyph &glyph = _glyphs[mapGlyph(chr)];
x += glyph.offX;
y += glyph.offY + _height - 2;
if (x > dst->w) {
return;
}
if (y > dst->h) {
return;
}
int w = glyph.w;
int h = glyph.h;
const uint8 *srcPos = (const uint8 *)glyph.bitmap;
// Make sure we are not drawing outside the screen bounds
if (x < 0) {
// x is negative so srcPos will increase and w will decrease
srcPos -= x;
w += x;
x = 0;
}
if (x + w > dst->w) {
w = dst->w - x;
}
if (w <= 0) {
return;
}
if (y < 0) {
// y is negative so srcPos will increase and h will decrease
srcPos -= y * glyph.w;
h += y;
y = 0;
}
if (y + h > dst->h) {
h = dst->h - y;
}
if (h <= 0) {
return;
}
for (uint16 i = 0; i < h; i++) {
for (uint16 j = 0; j < w; j++) {
if (srcPos[j]) {
if (dst->format.bytesPerPixel == 1) {
*((byte *)dst->getBasePtr(x + j, y + i)) = color;
} else if (dst->format.bytesPerPixel == 2) {
*((uint16 *)dst->getBasePtr(x + j, y + i)) = color;
} else if (dst->format.bytesPerPixel == 4) {
*((uint32 *)dst->getBasePtr(x + j, y + i)) = color;
}
}
}
// Next line
srcPos += glyph.w;
}
}
uint32 CryoFont::mapGlyph(uint32 chr) const {
/* Placeholder for non printable and out of limit characters */
if (chr < 0x20 || chr >= 0xff) {
chr = '?';
}
chr -= 0x20;
return chr;
}
CryoFont::Glyph::Glyph() : h(0), w(0), offX(0), offY(0), advance(0), bitmap(nullptr) {
}
CryoFont::Glyph::~Glyph() {
delete[] bitmap;
}
uint CryoFont::Glyph::setup(uint16 width, uint16 height) {
w = width;
h = height;
uint sz = w * h;
bitmap = new byte[sz];
return sz;
}
} // End of namespace CryOmni3D

View File

@@ -0,0 +1,81 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef CRYOMNI3D_FONTS_CRYOFONT_H
#define CRYOMNI3D_FONTS_CRYOFONT_H
#include "common/array.h"
#include "common/hashmap.h"
#include "common/str.h"
#include "graphics/font.h"
namespace Common {
class SeekableReadStream;
}
namespace CryOmni3D {
class CryoFont : public Graphics::Font {
public:
CryoFont() : _height(0), _maxAdvance(0) { }
void load(const Common::Path &fontFile);
virtual int getFontHeight() const { return _height; }
virtual int getMaxCharWidth() const { return _maxAdvance; }
virtual int getCharWidth(uint32 chr) const;
virtual Common::Rect getBoundingBox(uint32 chr) const;
virtual void drawChar(Graphics::Surface *dst, uint32 chr, int x, int y, uint32 color) const;
private:
void loadAll8bitGlyphs(Common::SeekableReadStream &font_fl);
uint32 mapGlyph(uint32 chr) const;
struct Glyph {
uint16 h;
uint16 w;
int16 offX;
int16 offY;
uint16 advance;
byte *bitmap;
Glyph();
~Glyph();
uint setup(uint16 width, uint16 height);
};
static const uint k8bitCharactersCount = 223;
uint16 _height;
uint16 _maxAdvance;
byte _comment[32];
Glyph _glyphs[k8bitCharactersCount];
};
} // End of namespace CryOmni3D
#endif