[Scummvm-git-logs] scummvm master -> 1fea15ac7bb4533bc2e6a90b5a9661ce56430bb0
sev-
sev at scummvm.org
Tue Jan 17 18:43:24 CET 2017
This automated email contains information about 2 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
be07b004e0 GRAPHICS: Split out MacFontFamily class out of MacFont
1fea15ac7b GRAPHICS: Implementing kerning calculation for MacFonts
Commit: be07b004e000cdafc59a43eaefc4fc85ab19f431
https://github.com/scummvm/scummvm/commit/be07b004e000cdafc59a43eaefc4fc85ab19f431
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2017-01-17T18:14:02+01:00
Commit Message:
GRAPHICS: Split out MacFontFamily class out of MacFont
Changed paths:
engines/director/director.cpp
graphics/fonts/macfont.cpp
graphics/fonts/macfont.h
diff --git a/engines/director/director.cpp b/engines/director/director.cpp
index 4eb7d55..95f8940 100644
--- a/engines/director/director.cpp
+++ b/engines/director/director.cpp
@@ -196,7 +196,7 @@ void DirectorEngine::setPalette(byte *palette, uint16 count) {
}
void DirectorEngine::testFonts() {
- Common::String fontName("San Francisco");
+ Common::String fontName("Helvetica");
Common::MacResManager *fontFile = new Common::MacResManager();
if (!fontFile->open(fontName))
@@ -207,8 +207,8 @@ void DirectorEngine::testFonts() {
for (Common::Array<uint16>::iterator iterator = fonds.begin(); iterator != fonds.end(); ++iterator) {
Common::SeekableReadStream *stream = fontFile->getResource(MKTAG('F', 'O', 'N', 'D'), *iterator);
- Graphics::MacFont font;
- font.loadFOND(*stream);
+ Graphics::MacFontFamily font;
+ font.load(*stream);
}
}
}
diff --git a/graphics/fonts/macfont.cpp b/graphics/fonts/macfont.cpp
index d3638fc..0df5fa7 100644
--- a/graphics/fonts/macfont.cpp
+++ b/graphics/fonts/macfont.cpp
@@ -77,7 +77,13 @@ MacFont::MacFont() {
_leading = 0;
_rowWords = 0;
_bitImage = nullptr;
+}
+MacFont::~MacFont() {
+ free(_bitImage);
+}
+
+MacFontFamily::MacFontFamily() {
_ffFlags = 0;
_ffFamID = 0;
_ffFirstChar = 0;
@@ -103,12 +109,11 @@ MacFont::MacFont() {
_ffNumBBoxes = 0;
}
-MacFont::~MacFont() {
- free(_bitImage);
+MacFontFamily::~MacFontFamily() {
free(_ffOffsets);
}
-bool MacFont::loadFOND(Common::SeekableReadStream &stream) {
+bool MacFontFamily::load(Common::SeekableReadStream &stream) {
_ffFlags = stream.readUint16BE(); // flags for family
_ffFamID = stream.readUint16BE(); // family ID number
_ffFirstChar = stream.readUint16BE(); // ASCII code of first character
@@ -201,7 +206,7 @@ bool MacFont::loadFOND(Common::SeekableReadStream &stream) {
_ffKernEntries[i]._entryLength = stream.readUint16BE();
_ffKernEntries[i]._kernPairs.resize(_ffKernEntries[i]._entryLength);
- debug(10, " style: %d kernpairs: %d", _ffKernEntries[i]._style, _ffKernEntries[i]._entryLength);
+ debug(10, " style: %x kernpairs: %d", _ffKernEntries[i]._style, _ffKernEntries[i]._entryLength);
for (uint j = 0; j < _ffKernEntries[i]._entryLength; j++) {
_ffKernEntries[i]._kernPairs[j]._firstChar = stream.readByte();
diff --git a/graphics/fonts/macfont.h b/graphics/fonts/macfont.h
index c357346..935fbb2 100644
--- a/graphics/fonts/macfont.h
+++ b/graphics/fonts/macfont.h
@@ -28,38 +28,14 @@
namespace Graphics {
-/**
- * Processing of Mac FONT/NFNT rResources
- */
-class MacFont : public Font {
+class MacFontFamily {
public:
- MacFont();
- virtual ~MacFont();
+ MacFontFamily();
+ ~MacFontFamily();
- virtual int getFontHeight() const;
- virtual int getMaxCharWidth() const;
- virtual int getCharWidth(uint32 chr) const;
- virtual void drawChar(Surface *dst, uint32 chr, int x, int y, uint32 color) const;
-
- bool loadFont(Common::SeekableReadStream &stream);
- bool loadFOND(Common::SeekableReadStream &stream);
+ bool load(Common::SeekableReadStream &stream);
private:
- // FONT/NFNT
- uint16 _fontType;
- uint16 _firstChar;
- uint16 _lastChar;
- uint16 _maxWidth;
- int16 _kernMax;
- int16 _nDescent;
- uint16 _fRectWidth;
- uint16 _fRectHeight;
- uint32 _owTLoc;
- uint16 _ascent;
- uint16 _descent;
- uint16 _leading;
- uint16 _rowWords;
-
// FOND
uint16 _ffFlags;
uint16 _ffFamID;
@@ -113,6 +89,38 @@ private:
uint16 _ffNumKerns;
Common::Array<KernEntry> _ffKernEntries;
+};
+
+/**
+ * Processing of Mac FONT/NFNT rResources
+ */
+class MacFont : public Font {
+public:
+ MacFont();
+ virtual ~MacFont();
+
+ virtual int getFontHeight() const;
+ virtual int getMaxCharWidth() const;
+ virtual int getCharWidth(uint32 chr) const;
+ virtual void drawChar(Surface *dst, uint32 chr, int x, int y, uint32 color) const;
+
+ bool loadFont(Common::SeekableReadStream &stream);
+
+private:
+ // FONT/NFNT
+ uint16 _fontType;
+ uint16 _firstChar;
+ uint16 _lastChar;
+ uint16 _maxWidth;
+ int16 _kernMax;
+ int16 _nDescent;
+ uint16 _fRectWidth;
+ uint16 _fRectHeight;
+ uint32 _owTLoc;
+ uint16 _ascent;
+ uint16 _descent;
+ uint16 _leading;
+ uint16 _rowWords;
byte *_bitImage;
Commit: 1fea15ac7bb4533bc2e6a90b5a9661ce56430bb0
https://github.com/scummvm/scummvm/commit/1fea15ac7bb4533bc2e6a90b5a9661ce56430bb0
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2017-01-17T18:44:27+01:00
Commit Message:
GRAPHICS: Implementing kerning calculation for MacFonts
Changed paths:
graphics/fonts/macfont.cpp
graphics/fonts/macfont.h
diff --git a/graphics/fonts/macfont.cpp b/graphics/fonts/macfont.cpp
index 0df5fa7..92b68b4 100644
--- a/graphics/fonts/macfont.cpp
+++ b/graphics/fonts/macfont.cpp
@@ -62,27 +62,6 @@ static int getDepth(uint16 _fontType) {
return 1 << ((_fontType >> 2) & 3);
}
-MacFont::MacFont() {
- _fontType = 0;
- _firstChar = 0;
- _lastChar = 0;
- _maxWidth = 0;
- _kernMax = 0;
- _nDescent = 0;
- _fRectWidth = 0;
- _fRectHeight = 0;
- _owTLoc = 0;
- _ascent = 0;
- _descent = 0;
- _leading = 0;
- _rowWords = 0;
- _bitImage = nullptr;
-}
-
-MacFont::~MacFont() {
- free(_bitImage);
-}
-
MacFontFamily::MacFontFamily() {
_ffFlags = 0;
_ffFamID = 0;
@@ -209,9 +188,13 @@ bool MacFontFamily::load(Common::SeekableReadStream &stream) {
debug(10, " style: %x kernpairs: %d", _ffKernEntries[i]._style, _ffKernEntries[i]._entryLength);
for (uint j = 0; j < _ffKernEntries[i]._entryLength; j++) {
- _ffKernEntries[i]._kernPairs[j]._firstChar = stream.readByte();
- _ffKernEntries[i]._kernPairs[j]._secondChar = stream.readByte();
- _ffKernEntries[i]._kernPairs[j]._distance = stream.readSint16BE();
+ byte f, s;
+ int16 d;
+ f = _ffKernEntries[i]._kernPairs[j]._firstChar = stream.readByte();
+ s = _ffKernEntries[i]._kernPairs[j]._secondChar = stream.readByte();
+ d = _ffKernEntries[i]._kernPairs[j]._distance = stream.readSint16BE();
+
+ _ffKernEntries[i]._kernTable[(f << 8) | s] = d;
}
}
}
@@ -219,7 +202,49 @@ bool MacFontFamily::load(Common::SeekableReadStream &stream) {
return true;
}
-bool MacFont::loadFont(Common::SeekableReadStream &stream) {
+ int MacFontFamily::getKerningOffset(uint style, int32 left, uint32 right) const {
+ uint16 idx = ((left & 0xff) << 8) | (right & 0xff);
+
+ for (uint i = 0; i < _ffKernEntries.size(); i++) {
+ if (_ffKernEntries[i]._style == style)
+ if (_ffKernEntries[i]._kernTable.contains(idx))
+ return _ffKernEntries[i]._kernTable[idx];
+ }
+
+ return 0;
+ }
+
+
+ MacFont::MacFont() {
+ _fontType = 0;
+ _firstChar = 0;
+ _lastChar = 0;
+ _maxWidth = 0;
+ _kernMax = 0;
+ _nDescent = 0;
+ _fRectWidth = 0;
+ _fRectHeight = 0;
+ _owTLoc = 0;
+ _ascent = 0;
+ _descent = 0;
+ _leading = 0;
+ _rowWords = 0;
+ _bitImage = nullptr;
+
+ _family = nullptr;
+ _size = 12;
+ _style = 0;
+ }
+
+ MacFont::~MacFont() {
+ free(_bitImage);
+ }
+
+bool MacFont::loadFont(Common::SeekableReadStream &stream, MacFontFamily *family, int size, int style) {
+ _family = family;
+ _size = size;
+ _style = style;
+
_fontType = stream.readUint16BE(); // font type
_firstChar = stream.readUint16BE(); // character code of first glyph
_lastChar = stream.readUint16BE(); // character code of last glyph
@@ -360,4 +385,15 @@ const MacFont::Glyph *MacFont::findGlyph(uint32 c) const {
return &_glyphs[c - _firstChar];
}
+int MacFont::getKerningOffset(uint32 left, uint32 right) const {
+ if (_family) {
+ int kerning = _family->getKerningOffset(_style, left, right);
+ kerning *= _size;
+
+ return (int)(kerning / (double)(1 << 12));
+ }
+
+ return 0;
+}
+
} // End of namespace Graphics
diff --git a/graphics/fonts/macfont.h b/graphics/fonts/macfont.h
index 935fbb2..ca1eb72 100644
--- a/graphics/fonts/macfont.h
+++ b/graphics/fonts/macfont.h
@@ -24,6 +24,7 @@
#define GRAPHICS_FONTS_MACFONT_H
#include "common/array.h"
+#include "common/hashmap.h"
#include "graphics/font.h"
namespace Graphics {
@@ -34,6 +35,15 @@ public:
~MacFontFamily();
bool load(Common::SeekableReadStream &stream);
+ int getKerningOffset(uint style, int32 left, uint32 right) const;
+
+ struct AsscEntry {
+ uint16 _fontSize;
+ uint16 _fontStyle;
+ uint16 _fontID;
+ };
+
+ Common::Array<AsscEntry> *getAssocTable() { return &_ffAssocEntries; }
private:
// FOND
@@ -52,12 +62,6 @@ private:
uint16 _ffIntl[2];
uint16 _ffVersion;
- struct AsscEntry {
- uint16 _fontSize;
- uint16 _fontStyle;
- uint16 _fontID;
- };
-
uint16 _ffNumAssoc;
Common::Array<AsscEntry> _ffAssocEntries;
@@ -85,6 +89,8 @@ private:
uint16 _style;
uint16 _entryLength;
Common::Array<KernPair> _kernPairs;
+
+ Common::HashMap<uint16, int16> _kernTable;
};
uint16 _ffNumKerns;
@@ -104,10 +110,11 @@ public:
virtual int getCharWidth(uint32 chr) const;
virtual void drawChar(Surface *dst, uint32 chr, int x, int y, uint32 color) const;
- bool loadFont(Common::SeekableReadStream &stream);
+ bool loadFont(Common::SeekableReadStream &stream, MacFontFamily *family = nullptr, int size = 12, int style = 0);
+
+ virtual int getKerningOffset(uint32 left, uint32 right) const;
private:
- // FONT/NFNT
uint16 _fontType;
uint16 _firstChar;
uint16 _lastChar;
@@ -141,6 +148,10 @@ private:
Common::Array<Glyph> _glyphs;
Glyph _defaultChar;
const Glyph *findGlyph(uint32 c) const;
+
+ MacFontFamily *_family;
+ int _size;
+ int _style;
};
} // End of namespace Graphics
More information about the Scummvm-git-logs
mailing list