[Scummvm-git-logs] scummvm master -> 3000f88043c552b5dc427dd86356b2109ebf9305
sev-
noreply at scummvm.org
Sat Mar 1 23:25:44 UTC 2025
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:
ab68b92df5 GRAPHICS: FONTS: Load DPI information from WinFonts
3000f88043 GRAPHICS: MACGUI: Take DPI into account when dealing with Windows fonts
Commit: ab68b92df57cf3eb25802f3e697863211394f2d0
https://github.com/scummvm/scummvm/commit/ab68b92df57cf3eb25802f3e697863211394f2d0
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2025-03-02T00:25:33+01:00
Commit Message:
GRAPHICS: FONTS: Load DPI information from WinFonts
Changed paths:
graphics/fonts/winfont.cpp
graphics/fonts/winfont.h
diff --git a/graphics/fonts/winfont.cpp b/graphics/fonts/winfont.cpp
index dc1687390c1..2411f66fa8c 100644
--- a/graphics/fonts/winfont.cpp
+++ b/graphics/fonts/winfont.cpp
@@ -41,6 +41,8 @@ WinFont::~WinFont() {
void WinFont::close() {
_pixHeight = 0;
+ _sizeInPoints = 0;
+ _dpi = 0;
_maxWidth = 0;
_firstChar = 0;
_lastChar = 0;
@@ -127,6 +129,20 @@ bool WinFont::loadFromEXE(Common::WinResources *exe, const Common::Path &fileNam
return ok;
}
+/**
+ * Size in typographic "points"
+ *
+ * While early Macintosh mapped "points" and "pixels" very closely,
+ * that was not the case on Windows.
+ *
+ * Windows used 96 dpi for font rendering so a 10 point font would
+ *
+ * Macintosh used 72 dpi for fonts while Windows used 96 dpi
+ */
+int WinFont::getFontSizeInPointsAtDPI(const int dpi) const {
+ return _sizeInPoints * _dpi / dpi;
+}
+
uint32 WinFont::getFontIndex(Common::SeekableReadStream &stream, const WinFontDirEntry &dirEntry) {
uint16 numFonts = stream.readUint16LE();
@@ -199,12 +215,18 @@ bool WinFont::loadFromFNT(Common::SeekableReadStream &stream) {
return false;
}
- /* uint32 size = */ stream.readUint32LE();
+ /* uint32 sizeOfGlyphTableInBytes = */ stream.readUint32LE();
stream.skip(60); // Copyright info
uint16 fontType = stream.readUint16LE();
- /* uint16 points = */ stream.readUint16LE();
- /* uint16 vertRes = */ stream.readUint16LE();
- /* uint16 horizRes = */ stream.readUint16LE();
+ _sizeInPoints = stream.readUint16LE();
+ uint16 vertRes = stream.readUint16LE(); // usually 96 as in 96dpi
+ uint16 horizRes = stream.readUint16LE(); // usually 96 as in 96dpi
+
+ if (vertRes != horizRes)
+ warning("WinFont::loadFromFNT(): FNT horizontal resolution and vertical resolution differ (%d vs %d)", horizRes, vertRes);
+
+ _dpi = vertRes;
+
_ascent = stream.readUint16LE();
/* uint16 internalLeading = */ stream.readUint16LE();
/* uint16 externalLeading = */ stream.readUint16LE();
diff --git a/graphics/fonts/winfont.h b/graphics/fonts/winfont.h
index a7f53d9f643..8736323da0c 100644
--- a/graphics/fonts/winfont.h
+++ b/graphics/fonts/winfont.h
@@ -62,7 +62,7 @@ public:
void close();
// Font API
- int getFontHeight() const { return _pixHeight; }
+ int getFontHeight() const { return _pixHeight; } //< pixels, not points - for points, see getFontSizeInPointsAtDPI()
int getFontAscent() const { return _ascent; }
int getMaxCharWidth() const { return _maxWidth; }
Common::String getName() const { return _name; }
@@ -70,6 +70,8 @@ public:
void drawChar(Surface *dst, uint32 chr, int x, int y, uint32 color) const;
int getStyle() const;
+ int getFontSizeInPointsAtDPI(const int dpi) const;
+
static WinFont *scaleFont(const WinFont *src, int newSize);
private:
bool loadFromEXE(Common::WinResources *exe, const Common::Path &fileName, const WinFontDirEntry &dirEntry);
@@ -83,6 +85,8 @@ private:
uint16 _pixHeight;
uint16 _maxWidth;
uint16 _ascent;
+ uint16 _sizeInPoints;
+ uint16 _dpi;
byte _firstChar;
byte _lastChar;
byte _defaultChar;
Commit: 3000f88043c552b5dc427dd86356b2109ebf9305
https://github.com/scummvm/scummvm/commit/3000f88043c552b5dc427dd86356b2109ebf9305
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2025-03-02T00:25:33+01:00
Commit Message:
GRAPHICS: MACGUI: Take DPI into account when dealing with Windows fonts
The original patch courtecy of IRC user grib. The original comment:
Try to coordinate using windows bitmap fonts in the MacFontManager needs to consider
pixels, points, and DPI
Font sizes are usually described in terms of "point" sizes, and rendered
as a number of pixels.
Windows fonts and Macintosh fonts used different DPI (dots per inch).
Bitmap fonts on Mac mostly used 72 dpi, so 72-point font would be about 72 pixels high.
Windows bitmap fonts mostly assumed 96 dpi, so a 72-point font would be 96 pixels high.
director:trektech loads a Windows bitmap font file that is nominally 12 point at 96 dpi. It is 14 pixels high.
Changed paths:
graphics/macgui/macfontmanager.cpp
diff --git a/graphics/macgui/macfontmanager.cpp b/graphics/macgui/macfontmanager.cpp
index c79fb643ffc..13740b5bb75 100644
--- a/graphics/macgui/macfontmanager.cpp
+++ b/graphics/macgui/macfontmanager.cpp
@@ -471,7 +471,7 @@ void MacFontManager::loadWindowsFont(const Common::Path &fileName) {
Common::String fontName = winFont->getName();
_winFontRegistry.setVal(fontName, winFont);
MacFont *font = new MacFont();
- Common::String fullName = Common::String::format("%s-%d-%d", fontName.c_str(), winFont->getStyle(), winFont->getFontHeight());
+ Common::String fullName = Common::String::format("%s-%d-%d", fontName.c_str(), winFont->getStyle(), winFont->getFontSizeInPointsAtDPI(72));
font->setName(fullName);
font->setFont(winFont, false);
_fontRegistry.setVal(font->getName(), font);
@@ -510,8 +510,8 @@ const Font *MacFontManager::getFont(MacFont *macFont) {
font = _winFontRegistry.getVal(_fontInfo.getVal(id)->name);
const Graphics::WinFont *winfont = (const Graphics::WinFont *)font;
- if (winfont->getFontHeight() != macFont->getSize()) {
- Common::String fullFontName = Common::String::format("%s-%d-%d", winfont->getName().c_str(), winfont->getStyle(), macFont->getSize());
+ if (winfont->getFontSizeInPointsAtDPI(72) != macFont->getSize()) {
+ Common::String fullFontName = Common::String::format("%s-%d-%d", winfont->getName().c_str(), winfont->getStyle(), winfont->getFontSizeInPointsAtDPI(72));
if (_winFontRegistry.contains(fullFontName)) {
font = _winFontRegistry.getVal(fullFontName);
More information about the Scummvm-git-logs
mailing list