diff options
author | Eugene Sandulenko | 2017-01-19 21:22:30 +0100 |
---|---|---|
committer | Eugene Sandulenko | 2017-01-19 21:22:30 +0100 |
commit | d2e31b1869dcf03e6fe66f93df1b1e5291bd9a9b (patch) | |
tree | 5a35eda76abc44f710c148abbe51cfe79a6dbd23 /graphics/fonts | |
parent | 6fa46810f5df7f3db69c646589edc8703d56a8cd (diff) | |
download | scummvm-rg350-d2e31b1869dcf03e6fe66f93df1b1e5291bd9a9b.tar.gz scummvm-rg350-d2e31b1869dcf03e6fe66f93df1b1e5291bd9a9b.tar.bz2 scummvm-rg350-d2e31b1869dcf03e6fe66f93df1b1e5291bd9a9b.zip |
GRAPHICS: Initial code for scaling MacFonts
Diffstat (limited to 'graphics/fonts')
-rw-r--r-- | graphics/fonts/macfont.cpp | 98 | ||||
-rw-r--r-- | graphics/fonts/macfont.h | 3 |
2 files changed, 101 insertions, 0 deletions
diff --git a/graphics/fonts/macfont.cpp b/graphics/fonts/macfont.cpp index d94ea88d9f..951202966e 100644 --- a/graphics/fonts/macfont.cpp +++ b/graphics/fonts/macfont.cpp @@ -236,6 +236,10 @@ bool MacFontFamily::load(Common::SeekableReadStream &stream) { _data._style = 0; } + MacFONTFont::MacFONTFont(const MacFONTdata &data) { + _data = data; + } + MacFONTFont::~MacFONTFont() { free(_data._bitImage); } @@ -388,4 +392,98 @@ int MacFONTFont::getKerningOffset(uint32 left, uint32 right) const { return 0; } +MacFONTFont *MacFONTFont::scaleFont(MacFONTFont *src, int newSize) { + if (!src) { + warning("Empty font reference in scale font"); + return NULL; + } + + if (src->getFontSize() == 0) { + warning("Requested to scale 0 size font"); + return NULL; + } + + float scale = (float)newSize / (float)src->getFontSize(); + + MacFONTdata data; + + data._fontType = src->_data._fontType; + data._firstChar = src->_data._firstChar; + data._lastChar = src->_data._firstChar; + data._maxWidth = (int)((float)src->_data._maxWidth * scale); + data._kernMax = (int)((float)src->_data._kernMax * scale); + data._nDescent = (int)((float)src->_data._nDescent * scale); + data._fRectWidth = (int)((float)src->_data._fRectWidth * scale); + data._fRectHeight = (int)((float)src->_data._fRectHeight * scale); + data._owTLoc = src->_data._owTLoc; + data._ascent = (int)((float)src->_data._ascent * scale); + data._descent = (int)((float)src->_data._descent * scale); + data._leading = (int)((float)src->_data._leading * scale); + data._rowWords = (int)((float)src->_data._rowWords * scale); + + data._family = src->_data._family; + data._size = src->_data._size; + data._style = src->_data._style; + + for (uint i = 0; i < src->_data._glyphs.size() + 1; i++) { + MacGlyph *glyph = (i == src->_data._glyphs.size()) ? &_data._defaultChar : &_data._glyphs[i]; + + //glyph->bitmapOffset = bitmapOffsets[i]; + //glyph->bitmapWidth = bitmapOffsets[i + 1] - bitmapOffsets[i]; + glyph->width = (int)((float)src->_data._glyphs[i].width * scale); + glyph->kerningOffset = (int)((float)src->_data._glyphs[i].kerningOffset * scale); + } + +#if 0 + for (int i = 0; i < data.numCharacters; i++) { + const BdfBoundingBox &box = data.boxes ? data.boxes[i] : data.defaultBox; + const BdfBoundingBox &srcBox = data.boxes ? src->_data.boxes[i] : src->_data.defaultBox; + + if (src->_data.bitmaps[i]) { + const int bytes = ((box.width + 7) / 8) * box.height; // Dimensions have been already corrected + bitmaps[i] = new byte[bytes]; + + int srcPitch = (srcBox.width + 7) / 8; + int dstPitch = (box.width + 7) / 8; + + byte *ptr = bitmaps[i]; + + for (int y = 0; y < box.height; y++) { + const byte *srcd = (const byte *)&src->_data.bitmaps[i][((int)((float)y / scale)) * srcPitch]; + byte *dst = ptr; + byte b = 0; + + for (int x = 0; x < box.width; x++) { + int sx = (int)((float)x / scale); + + if (srcd[sx / 8] & (0x80 >> (sx % 8))) + b |= 1; + + if (!(x % 8) && x) { + *dst++ = b; + b = 0; + } + + b <<= 1; + } + + if (((box.width - 1) % 8)) { + b <<= 7 - ((box.width - 1) % 8); + *dst = b; + } + + ptr += dstPitch; + } + + } else { + bitmaps[i] = 0; + } + } + + data.bitmaps = bitmaps; +#endif + + return new MacFONTFont(data); +} + } // End of namespace Graphics diff --git a/graphics/fonts/macfont.h b/graphics/fonts/macfont.h index ba19772cc5..ab285ed905 100644 --- a/graphics/fonts/macfont.h +++ b/graphics/fonts/macfont.h @@ -142,6 +142,7 @@ struct MacFONTdata { class MacFONTFont : public Font { public: MacFONTFont(); + MacFONTFont(const MacFONTdata &data); virtual ~MacFONTFont(); virtual int getFontHeight() const { return _data._fRectHeight; } @@ -155,6 +156,8 @@ public: int getFontSize() const { return _data._size; } + MacFONTFont *scaleFont(MacFONTFont *src, int newSize); + private: MacFONTdata _data; |