aboutsummaryrefslogtreecommitdiff
path: root/graphics/fonts/macfont.cpp
diff options
context:
space:
mode:
authorEugene Sandulenko2017-01-19 21:22:30 +0100
committerEugene Sandulenko2017-01-19 21:22:30 +0100
commitd2e31b1869dcf03e6fe66f93df1b1e5291bd9a9b (patch)
tree5a35eda76abc44f710c148abbe51cfe79a6dbd23 /graphics/fonts/macfont.cpp
parent6fa46810f5df7f3db69c646589edc8703d56a8cd (diff)
downloadscummvm-rg350-d2e31b1869dcf03e6fe66f93df1b1e5291bd9a9b.tar.gz
scummvm-rg350-d2e31b1869dcf03e6fe66f93df1b1e5291bd9a9b.tar.bz2
scummvm-rg350-d2e31b1869dcf03e6fe66f93df1b1e5291bd9a9b.zip
GRAPHICS: Initial code for scaling MacFonts
Diffstat (limited to 'graphics/fonts/macfont.cpp')
-rw-r--r--graphics/fonts/macfont.cpp98
1 files changed, 98 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