MACGUI: Expose font families in MacFontManager

MacFontManager didn't have a mechanism to report which fonts it loaded
from an external resource. It also requires that any fonts that aren't
built-in be explicitly registered by name by the client before they can
be used. This combination meant that a client couldn't load fonts from
an external file and use them by their properties (id / size / style).

SCI contains Mac fonts in its executable along with a table that maps
each SCI font id to a Mac font id and size. The font name isn't a part
of this since the Classic Mac Toolbox API took id / size / style as
input when drawing text.

Now MacFontManager exposes the font families it has loaded along with
their names. This allows a client to see which fonts were loaded,
register them by name, and proceed to use them with the existing API.
This commit is contained in:
sluicebox 2022-11-04 17:29:36 -07:00
parent 1eeb0b1f24
commit 2775987cba
6 changed files with 13 additions and 5 deletions

View File

@ -154,7 +154,7 @@ void Window::testFonts() {
debug("Font: %s", name.c_str());
Graphics::MacFontFamily font;
Graphics::MacFontFamily font(name);
font.load(*stream);
}
}

View File

@ -1551,7 +1551,7 @@ CharsetRendererMac::CharsetRendererMac(ScummEngine *vm, const Common::String &fo
if (!fond)
return;
Graphics::MacFontFamily fontFamily;
Graphics::MacFontFamily fontFamily(fontFamilyName);
if (!fontFamily.load(*fond)) {
delete fond;
return;

View File

@ -64,7 +64,9 @@ static int getDepth(uint16 _fontType) {
return 1 << ((_fontType >> 2) & 3);
}
MacFontFamily::MacFontFamily() {
MacFontFamily::MacFontFamily(const Common::String &name) {
_name = name;
_ffFlags = 0;
_ffFamID = 0;
_ffFirstChar = 0;

View File

@ -33,7 +33,7 @@ namespace Graphics {
class MacFontFamily {
public:
MacFontFamily();
MacFontFamily(const Common::String &name);
~MacFontFamily();
bool load(Common::SeekableReadStream &stream);
@ -46,9 +46,13 @@ public:
uint16 _fontID;
};
const Common::String &getName() { return _name; }
uint16 getFontFamilyId() { return _ffFamID; }
Common::Array<AsscEntry> *getAssocTable() { return &_ffAssocEntries; }
private:
Common::String _name;
// FOND
uint16 _ffFlags;
uint16 _ffFamID;

View File

@ -367,7 +367,7 @@ void MacFontManager::loadFonts(Common::MacResManager *fontFile) {
familyName = cleanFontName(familyName);
}
Graphics::MacFontFamily *fontFamily = new MacFontFamily();
Graphics::MacFontFamily *fontFamily = new MacFontFamily(familyName);
fontFamily->load(*fond);
Common::Array<Graphics::MacFontFamily::AsscEntry> *assoc = fontFamily->getAssocTable();

View File

@ -170,6 +170,8 @@ public:
void forceBuiltinFonts() { _builtInFonts = true; }
int parseSlantFromName(const Common::String &name);
const Common::Array<MacFontFamily *> &getFontFamilies() { return _fontFamilies; }
private:
void loadFontsBDF();
void loadFonts();