From bd4f0aa570b795afaf8c5a5b3837082b995b797f Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Sun, 5 Jan 2020 10:59:11 +0100 Subject: GRAPHICS: MACGUI: Fix text height for one line texts --- graphics/macgui/mactext.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'graphics') diff --git a/graphics/macgui/mactext.cpp b/graphics/macgui/mactext.cpp index 0df403ac8c..916219fe73 100644 --- a/graphics/macgui/mactext.cpp +++ b/graphics/macgui/mactext.cpp @@ -395,7 +395,7 @@ int MacText::getLineWidth(int line, bool enforce) { height = MAX(height, _textLines[line].chunks[i].getFont()->getFontHeight()); } - if (!hastext) + if (!hastext && _textLines.size() > 1) height = height > 3 ? height - 3 : 0; _textLines[line].width = width; -- cgit v1.2.3 From 5a06fcecddd0fec6336a24b8f84ca73b055f8bdd Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Sun, 5 Jan 2020 11:34:17 +0100 Subject: GRAPHICS: MACGUI: Generate MacText surface for empty texts --- graphics/macgui/mactext.cpp | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) (limited to 'graphics') diff --git a/graphics/macgui/mactext.cpp b/graphics/macgui/mactext.cpp index 916219fe73..2fc9b8dd33 100644 --- a/graphics/macgui/mactext.cpp +++ b/graphics/macgui/mactext.cpp @@ -69,8 +69,7 @@ MacText::MacText(Common::U32String s, MacWindowManager *wm, const MacFont *macFo _currentFormatting = _defaultFormatting; - if (!_str.empty()) - splitString(_str); + splitString(_str); recalcDims(); @@ -101,8 +100,7 @@ MacText::MacText(const Common::String &s, MacWindowManager *wm, const MacFont *m _currentFormatting = _defaultFormatting; - if (!_str.empty()) - splitString(_str); + splitString(_str); recalcDims(); @@ -114,13 +112,11 @@ void MacText::setMaxWidth(int maxWidth) { _textLines.clear(); - if (!_str.empty()) { - splitString(_str); + splitString(_str); - recalcDims(); + recalcDims(); - _fullRefresh = true; - } + _fullRefresh = true; } static const Common::U32String::value_type *readHex(uint16 *res, const Common::U32String::value_type *s, int len) { -- cgit v1.2.3 From bfd796fec2e723bb3a43e672fcddf2dfd5108ccf Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Tue, 7 Jan 2020 15:45:32 +0100 Subject: GRAPHICS: MACGUI: Use regular slant as font substitutes --- graphics/macgui/macfontmanager.cpp | 42 +++++++++++++++++++++++++++----------- 1 file changed, 30 insertions(+), 12 deletions(-) (limited to 'graphics') diff --git a/graphics/macgui/macfontmanager.cpp b/graphics/macgui/macfontmanager.cpp index e8e3d4314b..151a3d9ee8 100644 --- a/graphics/macgui/macfontmanager.cpp +++ b/graphics/macgui/macfontmanager.cpp @@ -405,35 +405,53 @@ void MacFontManager::generateFontSubstitute(MacFont &macFont) { // No simple substitute was found. Looking for neighborhood fonts // First we gather all font sizes for this font - Common::Array sizes; + Common::Array sizes; for (Common::HashMap::iterator i = _fontRegistry.begin(); i != _fontRegistry.end(); ++i) { if (i->_value->getId() == macFont.getId() && i->_value->getSlant() == macFont.getSlant() && !i->_value->isGenerated()) - sizes.push_back(i->_value->getSize()); + sizes.push_back(i->_value); } if (sizes.empty()) { - debug(1, "No viable substitute found for font %s", getFontName(macFont).c_str()); - return; + if (macFont.getSlant() == kMacFontRegular) { + debug(1, "No viable substitute found for font %s", getFontName(macFont).c_str()); + return; + } + + // Now let's try to find a regular font + for (Common::HashMap::iterator i = _fontRegistry.begin(); i != _fontRegistry.end(); ++i) { + if (i->_value->getId() == macFont.getId() && i->_value->getSlant() == kMacFontRegular && !i->_value->isGenerated()) + sizes.push_back(i->_value); + } + + if (sizes.empty()) { + debug(1, "No viable substitute found for font %s", getFontName(macFont).c_str()); + return; + } } - // Now looking next larger font, and store the largest one for next check - int candidate = 1000; - int maxSize = sizes[0]; + // Now looking for the next larger font, and store the largest one for next check + MacFont *candidate = nullptr; + MacFont *maxSize = sizes[0]; for (uint i = 0; i < sizes.size(); i++) { - if (sizes[i] > macFont.getSize() && sizes[i] < candidate) + if (sizes[i]->getSize() == macFont.getSize()) { // Same size but regular slant + candidate = sizes[i]; + break; + } + + if (sizes[i]->getSize() > macFont.getSize() && candidate && sizes[i]->getSize() < candidate->getSize()) candidate = sizes[i]; - if (sizes[i] > maxSize) + if (sizes[i]->getSize() > maxSize->getSize()) maxSize = sizes[i]; } - if (candidate != 1000) { - generateFont(macFont, *_fontRegistry[getFontName(macFont.getId(), candidate, macFont.getSlant())]); + if (candidate) { + generateFont(macFont, *candidate); return; } // Now next smaller font, which is the biggest we have - generateFont(macFont, *_fontRegistry[getFontName(macFont.getId(), maxSize, macFont.getSlant())]); + generateFont(macFont, *maxSize); } void MacFontManager::generateFont(MacFont &toFont, MacFont &fromFont) { -- cgit v1.2.3 From f7970c30a4a2ace45dc98f2d4d0cd3be1114ba65 Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Tue, 7 Jan 2020 18:53:46 +0100 Subject: GRAPHICS: FONTS: Fix BDF font scaling --- graphics/fonts/bdf.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'graphics') diff --git a/graphics/fonts/bdf.cpp b/graphics/fonts/bdf.cpp index 4374c36ff4..d901d1bb8c 100644 --- a/graphics/fonts/bdf.cpp +++ b/graphics/fonts/bdf.cpp @@ -767,17 +767,17 @@ BdfFont *BdfFont::scaleFont(BdfFont *src, int newSize) { byte b = 0; for (int x = 0; x < box.width; x++) { + b <<= 1; + int sx = (int)((float)x / scale); if (srcd[sx / 8] & (0x80 >> (sx % 8))) b |= 1; - if (!(x % 8) && x) { + if (x % 8 == 7) { *dst++ = b; b = 0; } - - b <<= 1; } if (((box.width - 1) % 8)) { -- cgit v1.2.3 From 90c305c9049d2ac96acb79aaf82ca3bab9be9624 Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Tue, 7 Jan 2020 18:54:09 +0100 Subject: GRAPHICS: FONTS: Use better algorithm for MacFONT scaling added debug output --- graphics/fonts/macfont.cpp | 130 +++++++++++++++++++++++++++++++++++++++++---- graphics/fonts/macfont.h | 1 + 2 files changed, 122 insertions(+), 9 deletions(-) (limited to 'graphics') diff --git a/graphics/fonts/macfont.cpp b/graphics/fonts/macfont.cpp index 4264f64649..5400497486 100644 --- a/graphics/fonts/macfont.cpp +++ b/graphics/fonts/macfont.cpp @@ -25,6 +25,8 @@ #include "graphics/managed_surface.h" #include "graphics/fonts/macfont.h" +#define DEBUGSCALING 0 + namespace Graphics { enum { @@ -393,6 +395,10 @@ int MacFONTFont::getKerningOffset(uint32 left, uint32 right) const { return 0; } +#if DEBUGSCALING +bool dododo; +#endif + MacFONTFont *MacFONTFont::scaleFont(const MacFONTFont *src, int newSize) { if (!src) { warning("Empty font reference in scale font"); @@ -404,6 +410,11 @@ MacFONTFont *MacFONTFont::scaleFont(const MacFONTFont *src, int newSize) { return NULL; } + Graphics::Surface srcSurf; + srcSurf.create(src->getFontSize() * 3, src->getFontSize() * 3, PixelFormat::createFormatCLUT8()); + int dstGraySize = newSize * 3 * newSize * 3; + int *dstGray = (int *)malloc(dstGraySize * sizeof(int)); + float scale = (float)newSize / (float)src->getFontSize(); MacFONTdata data; @@ -427,7 +438,7 @@ MacFONTFont *MacFONTFont::scaleFont(const MacFONTFont *src, int newSize) { data._glyphs.resize(src->_data._glyphs.size()); - // Dtermine width of the bit image table + // Determine width of the bit image table int newBitmapWidth = 0; for (uint i = 0; i < src->_data._glyphs.size() + 1; i++) { MacGlyph *glyph = (i == src->_data._glyphs.size()) ? &data._defaultChar : &data._glyphs[i]; @@ -435,7 +446,7 @@ MacFONTFont *MacFONTFont::scaleFont(const MacFONTFont *src, int newSize) { glyph->width = (int)((float)srcglyph->width * scale); glyph->kerningOffset = (int)((float)srcglyph->kerningOffset * scale); - glyph->bitmapWidth = (int)((float)srcglyph->bitmapWidth * scale); + glyph->bitmapWidth = glyph->width; //(int)((float)srcglyph->bitmapWidth * scale); glyph->bitmapOffset = newBitmapWidth; newBitmapWidth += (glyph->bitmapWidth + 7) & ~0x7; @@ -446,45 +457,146 @@ MacFONTFont *MacFONTFont::scaleFont(const MacFONTFont *src, int newSize) { uint bitImageSize = data._rowWords * data._fRectHeight; data._bitImage = new byte[bitImageSize]; - int srcPitch = src->_data._rowWords; int dstPitch = data._rowWords; for (uint i = 0; i < src->_data._glyphs.size() + 1; i++) { const MacGlyph *srcglyph = (i == src->_data._glyphs.size()) ? &src->_data._defaultChar : &src->_data._glyphs[i]; + + int grayLevel = src->_data._fRectHeight * srcglyph->width / 4; + +#if DEBUGSCALING + int ccc = 'c'; + dododo = i == ccc; +#endif + + srcSurf.fillRect(Common::Rect(srcSurf.w, srcSurf.h), 0); + src->drawChar(&srcSurf, i + src->_data._firstChar, 0, 0, 1); + memset(dstGray, 0, dstGraySize * sizeof(int)); + src->magnifyGray(&srcSurf, srcglyph, dstGray, scale); + MacGlyph *glyph = (i == src->_data._glyphs.size()) ? &data._defaultChar : &data._glyphs[i]; byte *ptr = &data._bitImage[glyph->bitmapOffset / 8]; + int *grayPtr = dstGray; for (int y = 0; y < data._fRectHeight; y++) { - const byte *srcd = (const byte *)&src->_data._bitImage[((int)((float)y / scale)) * srcPitch]; byte *dst = ptr; byte b = 0; - for (int x = 0; x < glyph->width; x++) { - int sx = (int)((float)x / scale) + srcglyph->bitmapOffset; + for (int x = 0; x < glyph->width; x++, grayPtr++) { + b <<= 1; + +#if DEBUGSCALING + if (i == ccc) { + if (*grayPtr) + debugN(1, "%3d ", *grayPtr); + else + debugN(1, " "); + } +#endif - if (srcd[sx / 8] & (0x80 >> (sx % 8))) + if (*grayPtr > grayLevel) b |= 1; - if (!(x % 8) && x) { + if (x % 8 == 7) { *dst++ = b; b = 0; } + } - b <<= 1; +#if DEBUGSCALING + if (i == ccc) { + debugN(1, "--> %d ", grayLevel); + + grayPtr = &dstGray[y * glyph->width]; + for (int x = 0; x < glyph->width; x++, grayPtr++) + debugN("%c", *grayPtr > grayLevel ? '#' : '.'); } +#endif if (((glyph->width - 1) % 8)) { +#if DEBUGSCALING + if (i == ccc) + debugN(" --- %02x (w: %d bw: %d << %d)", b, glyph->width, glyph->bitmapWidth, 7 - ((glyph->width - 1) % 8)); +#endif + b <<= 7 - ((glyph->width - 1) % 8); *dst = b; + +#if DEBUGSCALING + if (i == ccc) + debugN(" --- %02x ", b); +#endif } +#if DEBUGSCALING + if (i == ccc) { + byte *srcRow = data._bitImage + y * data._rowWords; + + for (uint16 x = 0; x < glyph->bitmapWidth; x++) { + uint16 bitmapOffset = glyph->bitmapOffset + x; + + debugN("%c", srcRow[bitmapOffset / 8] & (1 << (7 - (bitmapOffset % 8))) ? '*' : '.'); + } + + debug(""); + } +#endif + ptr += dstPitch; } } + srcSurf.free(); + free(dstGray); + return new MacFONTFont(data); } +#define howmany(x, y) (((x)+((y)-1))/(y)) + +static void countupScore(int *dstGray, int x, int y, int bbw, int bbh, float scale) { + int newbbw = bbw * scale; + int newbbh = bbh * scale; + int x_ = x * newbbw; + int y_ = y * newbbh; + int x1 = x_ + newbbw; + int y1 = y_ + newbbh; + + int newxbegin = x_ / bbw; + int newybegin = y_ / bbh; + int newxend = howmany(x1, bbw); + int newyend = howmany(y1, bbh); + + for (int newy = newybegin; newy < newyend; newy++) { + for (int newx = newxbegin; newx < newxend; newx++) { + int newX = newx * bbw; + int newY = newy * bbh; + int newX1 = newX + bbw; + int newY1 = newY + bbh; + dstGray[newy * newbbw + newx] += (MIN(x1, newX1) - MAX(x_, newX)) * + (MIN(y1, newY1) - MAX(y_, newY)); + } + } +} + +void MacFONTFont::magnifyGray(Surface *src, const MacGlyph *glyph, int *dstGray, float scale) const { + for (uint16 y = 0; y < _data._fRectHeight; y++) { + for (uint16 x = 0; x < glyph->width; x++) { + if (*((byte *)src->getBasePtr(x, y)) == 1) + countupScore(dstGray, x, y, glyph->width, _data._fRectHeight, scale); +#if DEBUGSCALING + if (dododo) + debugN("%c", *((byte *)src->getBasePtr(x, y)) == 1 ? '*' : ' '); +#endif + } + +#if DEBUGSCALING + if (dododo) + debug(""); +#endif + } +} + void MacFONTFont::testBlit(const MacFONTFont *src, ManagedSurface *dst, int color, int x0, int y0, int width) { for (int y = 0; y < src->_data._fRectHeight; y++) { byte *srcRow = src->_data._bitImage + y * src->_data._rowWords; diff --git a/graphics/fonts/macfont.h b/graphics/fonts/macfont.h index b2e1fb0d11..3208759044 100644 --- a/graphics/fonts/macfont.h +++ b/graphics/fonts/macfont.h @@ -166,6 +166,7 @@ private: MacFONTdata _data; const MacGlyph *findGlyph(uint32 c) const; + void magnifyGray(Surface *src, const MacGlyph *glyph, int *dstGray, float scale) const; }; } // End of namespace Graphics -- cgit v1.2.3 From b5a95d478302c3f98f559eb676d2f3bcba3ce09d Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Tue, 7 Jan 2020 20:41:15 +0100 Subject: GRAPHICS: FONTS: Made scaling form MacFONT as a step --- graphics/fonts/macfont.cpp | 45 ++++++++++++++++++++++++++++++++------------- graphics/fonts/macfont.h | 1 - 2 files changed, 32 insertions(+), 14 deletions(-) (limited to 'graphics') diff --git a/graphics/fonts/macfont.cpp b/graphics/fonts/macfont.cpp index 5400497486..2ae9fc8b7d 100644 --- a/graphics/fonts/macfont.cpp +++ b/graphics/fonts/macfont.cpp @@ -399,6 +399,8 @@ int MacFONTFont::getKerningOffset(uint32 left, uint32 right) const { bool dododo; #endif +static void magnifyGray(Surface *src, const MacGlyph *glyph, int *dstGray, int height, float scale); + MacFONTFont *MacFONTFont::scaleFont(const MacFONTFont *src, int newSize) { if (!src) { warning("Empty font reference in scale font"); @@ -449,7 +451,8 @@ MacFONTFont *MacFONTFont::scaleFont(const MacFONTFont *src, int newSize) { glyph->bitmapWidth = glyph->width; //(int)((float)srcglyph->bitmapWidth * scale); glyph->bitmapOffset = newBitmapWidth; - newBitmapWidth += (glyph->bitmapWidth + 7) & ~0x7; + // Align width to a byte + newBitmapWidth += (glyph->bitmapWidth + 7 + 2) & ~0x7; // Add 2 pixels for italic and bold } data._rowWords = newBitmapWidth; @@ -472,19 +475,15 @@ MacFONTFont *MacFONTFont::scaleFont(const MacFONTFont *src, int newSize) { srcSurf.fillRect(Common::Rect(srcSurf.w, srcSurf.h), 0); src->drawChar(&srcSurf, i + src->_data._firstChar, 0, 0, 1); memset(dstGray, 0, dstGraySize * sizeof(int)); - src->magnifyGray(&srcSurf, srcglyph, dstGray, scale); + magnifyGray(&srcSurf, srcglyph, dstGray, src->_data._fRectHeight, scale); MacGlyph *glyph = (i == src->_data._glyphs.size()) ? &data._defaultChar : &data._glyphs[i]; - byte *ptr = &data._bitImage[glyph->bitmapOffset / 8]; int *grayPtr = dstGray; for (int y = 0; y < data._fRectHeight; y++) { - byte *dst = ptr; - byte b = 0; - - for (int x = 0; x < glyph->width; x++, grayPtr++) { - b <<= 1; + byte *dst = (byte *)srcSurf.getBasePtr(0, y); + for (int x = 0; x < glyph->width; x++, grayPtr++, dst++) { #if DEBUGSCALING if (i == ccc) { if (*grayPtr) @@ -493,8 +492,28 @@ MacFONTFont *MacFONTFont::scaleFont(const MacFONTFont *src, int newSize) { debugN(1, " "); } #endif - if (*grayPtr > grayLevel) + *dst = 1; + else + *dst = 0; + } +#if DEBUGSCALING + if (i == ccc) + debug(1, ""); +#endif + } + + byte *ptr = &data._bitImage[glyph->bitmapOffset / 8]; + + for (int y = 0; y < data._fRectHeight; y++) { + byte *dst = ptr; + byte *srcPtr = (byte *)srcSurf.getBasePtr(0, y); + byte b = 0; + + for (int x = 0; x < glyph->width; x++, srcPtr++) { + b <<= 1; + + if (*srcPtr == 1) b |= 1; if (x % 8 == 7) { @@ -579,11 +598,11 @@ static void countupScore(int *dstGray, int x, int y, int bbw, int bbh, float sca } } -void MacFONTFont::magnifyGray(Surface *src, const MacGlyph *glyph, int *dstGray, float scale) const { - for (uint16 y = 0; y < _data._fRectHeight; y++) { +static void magnifyGray(Surface *src, const MacGlyph *glyph, int *dstGray, int height, float scale) { + for (uint16 y = 0; y < height; y++) { for (uint16 x = 0; x < glyph->width; x++) { if (*((byte *)src->getBasePtr(x, y)) == 1) - countupScore(dstGray, x, y, glyph->width, _data._fRectHeight, scale); + countupScore(dstGray, x, y, glyph->width, height, scale); #if DEBUGSCALING if (dododo) debugN("%c", *((byte *)src->getBasePtr(x, y)) == 1 ? '*' : ' '); @@ -602,7 +621,7 @@ void MacFONTFont::testBlit(const MacFONTFont *src, ManagedSurface *dst, int colo byte *srcRow = src->_data._bitImage + y * src->_data._rowWords; for (int x = 0; x < width; x++) { - uint16 bitmapOffset = x; + uint16 bitmapOffset = x + 64; if (srcRow[bitmapOffset / 8] & (1 << (7 - (bitmapOffset % 8)))) { if (dst->format.bytesPerPixel == 1) diff --git a/graphics/fonts/macfont.h b/graphics/fonts/macfont.h index 3208759044..b2e1fb0d11 100644 --- a/graphics/fonts/macfont.h +++ b/graphics/fonts/macfont.h @@ -166,7 +166,6 @@ private: MacFONTdata _data; const MacGlyph *findGlyph(uint32 c) const; - void magnifyGray(Surface *src, const MacGlyph *glyph, int *dstGray, float scale) const; }; } // End of namespace Graphics -- cgit v1.2.3 From fc00b78a48e3d5950858cfe5c5720de03f2ff803 Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Tue, 7 Jan 2020 21:54:38 +0100 Subject: GRAPHICS: FONTS: Implement generation of bold fonts --- graphics/fonts/macfont.cpp | 85 +++++++++++++++++++++++++++++++++++++++++----- graphics/fonts/macfont.h | 2 +- 2 files changed, 78 insertions(+), 9 deletions(-) (limited to 'graphics') diff --git a/graphics/fonts/macfont.cpp b/graphics/fonts/macfont.cpp index 2ae9fc8b7d..730229c750 100644 --- a/graphics/fonts/macfont.cpp +++ b/graphics/fonts/macfont.cpp @@ -399,9 +399,10 @@ int MacFONTFont::getKerningOffset(uint32 left, uint32 right) const { bool dododo; #endif -static void magnifyGray(Surface *src, const MacGlyph *glyph, int *dstGray, int height, float scale); +static void magnifyGray(Surface *src, int *dstGray, int width, int height, float scale); +static void makeBold(Surface *src, int *dstGray, MacGlyph *glyph, int height); -MacFONTFont *MacFONTFont::scaleFont(const MacFONTFont *src, int newSize) { +MacFONTFont *MacFONTFont::scaleFont(const MacFONTFont *src, int newSize, bool bold, bool italic) { if (!src) { warning("Empty font reference in scale font"); return NULL; @@ -413,8 +414,8 @@ MacFONTFont *MacFONTFont::scaleFont(const MacFONTFont *src, int newSize) { } Graphics::Surface srcSurf; - srcSurf.create(src->getFontSize() * 3, src->getFontSize() * 3, PixelFormat::createFormatCLUT8()); - int dstGraySize = newSize * 3 * newSize * 3; + srcSurf.create(src->getFontSize() * 2, src->getFontSize() * 2, PixelFormat::createFormatCLUT8()); + int dstGraySize = newSize * 2 * newSize; int *dstGray = (int *)malloc(dstGraySize * sizeof(int)); float scale = (float)newSize / (float)src->getFontSize(); @@ -475,7 +476,7 @@ MacFONTFont *MacFONTFont::scaleFont(const MacFONTFont *src, int newSize) { srcSurf.fillRect(Common::Rect(srcSurf.w, srcSurf.h), 0); src->drawChar(&srcSurf, i + src->_data._firstChar, 0, 0, 1); memset(dstGray, 0, dstGraySize * sizeof(int)); - magnifyGray(&srcSurf, srcglyph, dstGray, src->_data._fRectHeight, scale); + magnifyGray(&srcSurf, dstGray, srcglyph->width, src->_data._fRectHeight, scale); MacGlyph *glyph = (i == src->_data._glyphs.size()) ? &data._defaultChar : &data._glyphs[i]; int *grayPtr = dstGray; @@ -503,6 +504,31 @@ MacFONTFont *MacFONTFont::scaleFont(const MacFONTFont *src, int newSize) { #endif } + if (bold) { + memset(dstGray, 0, dstGraySize * sizeof(int)); + makeBold(&srcSurf, dstGray, glyph, data._fRectHeight); + + for (uint16 y = 0; y < data._fRectHeight; y++) { + int *srcPtr = &dstGray[y * glyph->width]; + byte *dstPtr = (byte *)srcSurf.getBasePtr(0, y); + + for (uint16 x = 0; x < glyph->width; x++, srcPtr++, dstPtr++) { + if (*srcPtr) + *dstPtr = 1; + +#if DEBUGSCALING + if (i == ccc) + debugN("%c", *srcPtr ? '@' : '.'); +#endif + } + +#if DEBUGSCALING + if (i == ccc) + debug(""); +#endif + } + } + byte *ptr = &data._bitImage[glyph->bitmapOffset / 8]; for (int y = 0; y < data._fRectHeight; y++) { @@ -598,11 +624,11 @@ static void countupScore(int *dstGray, int x, int y, int bbw, int bbh, float sca } } -static void magnifyGray(Surface *src, const MacGlyph *glyph, int *dstGray, int height, float scale) { +static void magnifyGray(Surface *src, int *dstGray, int width, int height, float scale) { for (uint16 y = 0; y < height; y++) { - for (uint16 x = 0; x < glyph->width; x++) { + for (uint16 x = 0; x < width; x++) { if (*((byte *)src->getBasePtr(x, y)) == 1) - countupScore(dstGray, x, y, glyph->width, height, scale); + countupScore(dstGray, x, y, width, height, scale); #if DEBUGSCALING if (dododo) debugN("%c", *((byte *)src->getBasePtr(x, y)) == 1 ? '*' : ' '); @@ -616,6 +642,49 @@ static void magnifyGray(Surface *src, const MacGlyph *glyph, int *dstGray, int h } } +static const bool bdir = true; +static const bool pile = false; + +static void makeBold(Surface *src, int *dstGray, MacGlyph *glyph, int height) { + glyph->width++; + + for (uint16 y = 0; y < height; y++) { + byte *srcPtr = (byte *)src->getBasePtr(0, y); + int *dst = &dstGray[y * glyph->width]; + + for (uint16 x = 0; x < glyph->width; x++, srcPtr++, dst++) { + bool left = x ? *(srcPtr - 1) == 1 : false; + bool center = *srcPtr == 1; + bool right = x > glyph->width - 1 ? false : *(srcPtr + 1) == 1; + + bool tmp, bold; + + bool res; + + if (bdir) { + /* left shifted image */ + bold = left; + } else { + /* right shifted image */ + bold = right; + } + if (pile) { + /* left edge */ + tmp = left; + res = (!tmp && center) || bold; + } else { + /* right edge */ + tmp = right; + res = (!tmp && bold) || center; + } + + res = center || left; + + *dst = res ? 1 : 0; + } + } +} + void MacFONTFont::testBlit(const MacFONTFont *src, ManagedSurface *dst, int color, int x0, int y0, int width) { for (int y = 0; y < src->_data._fRectHeight; y++) { byte *srcRow = src->_data._bitImage + y * src->_data._rowWords; diff --git a/graphics/fonts/macfont.h b/graphics/fonts/macfont.h index b2e1fb0d11..cb11304eb2 100644 --- a/graphics/fonts/macfont.h +++ b/graphics/fonts/macfont.h @@ -159,7 +159,7 @@ public: int getFontSize() const { return _data._size; } - static MacFONTFont *scaleFont(const MacFONTFont *src, int newSize); + static MacFONTFont *scaleFont(const MacFONTFont *src, int newSize, bool bold = false, bool italic = false); static void testBlit(const MacFONTFont *src, ManagedSurface *dst, int color, int x0, int y0, int width); private: -- cgit v1.2.3 From 8c8a710d80394a7c60456cfdfded46d222c5ee21 Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Tue, 7 Jan 2020 21:55:06 +0100 Subject: GRAPHICS: MACGUI: Generate bold font substitutes in MacFontManager --- graphics/macgui/macfontmanager.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'graphics') diff --git a/graphics/macgui/macfontmanager.cpp b/graphics/macgui/macfontmanager.cpp index 151a3d9ee8..ff940384c4 100644 --- a/graphics/macgui/macfontmanager.cpp +++ b/graphics/macgui/macfontmanager.cpp @@ -458,7 +458,14 @@ void MacFontManager::generateFont(MacFont &toFont, MacFont &fromFont) { debugN("Found font substitute for font '%s' ", getFontName(toFont).c_str()); debug("as '%s'", getFontName(fromFont).c_str()); - MacFONTFont *font = Graphics::MacFONTFont::scaleFont(fromFont.getFont(), toFont.getSize()); + bool bold = false, italic = false; + + if (fromFont.getSlant() == kMacFontRegular) { + bold = toFont.getSlant() == kMacFontBold; + italic = toFont.getSlant() == kMacFontItalic; + } + + MacFONTFont *font = Graphics::MacFONTFont::scaleFont(fromFont.getFont(), toFont.getSize(), bold, italic); if (!font) { warning("Failed to generate font '%s'", getFontName(toFont).c_str()); -- cgit v1.2.3 From a98d3832d9d08eae63f48008466f7ecbdfca16bf Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Tue, 7 Jan 2020 22:00:23 +0100 Subject: GRAPHICS: FONTS: Fix warnings --- graphics/fonts/macfont.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'graphics') diff --git a/graphics/fonts/macfont.cpp b/graphics/fonts/macfont.cpp index 730229c750..50635fda47 100644 --- a/graphics/fonts/macfont.cpp +++ b/graphics/fonts/macfont.cpp @@ -524,7 +524,7 @@ MacFONTFont *MacFONTFont::scaleFont(const MacFONTFont *src, int newSize, bool bo #if DEBUGSCALING if (i == ccc) - debug(""); + debugN("\n"); #endif } } @@ -583,7 +583,7 @@ MacFONTFont *MacFONTFont::scaleFont(const MacFONTFont *src, int newSize, bool bo debugN("%c", srcRow[bitmapOffset / 8] & (1 << (7 - (bitmapOffset % 8))) ? '*' : '.'); } - debug(""); + debugN("\n"); } #endif @@ -637,7 +637,7 @@ static void magnifyGray(Surface *src, int *dstGray, int width, int height, float #if DEBUGSCALING if (dododo) - debug(""); + debugN("\n"); #endif } } -- cgit v1.2.3 From 858f8791ec7f5f8b0443963fbaaec91191eb6d41 Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Tue, 7 Jan 2020 22:09:59 +0100 Subject: GRAPHICS: FONTS: Fix memory override --- graphics/fonts/macfont.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'graphics') diff --git a/graphics/fonts/macfont.cpp b/graphics/fonts/macfont.cpp index 50635fda47..e8a52d10b2 100644 --- a/graphics/fonts/macfont.cpp +++ b/graphics/fonts/macfont.cpp @@ -414,7 +414,8 @@ MacFONTFont *MacFONTFont::scaleFont(const MacFONTFont *src, int newSize, bool bo } Graphics::Surface srcSurf; - srcSurf.create(src->getFontSize() * 2, src->getFontSize() * 2, PixelFormat::createFormatCLUT8()); + srcSurf.create(MAX(src->getFontSize() * 2, newSize * 2), MAX(src->getFontSize() * 2, newSize * 2), + PixelFormat::createFormatCLUT8()); int dstGraySize = newSize * 2 * newSize; int *dstGray = (int *)malloc(dstGraySize * sizeof(int)); -- cgit v1.2.3 From da8bfeca5ec68550c49863e8ed4390337a48c0c9 Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Tue, 7 Jan 2020 22:46:24 +0100 Subject: GRAPHICS: FONTS: Improved visuals for generated bold fonts --- graphics/fonts/macfont.cpp | 28 ++++------------------------ 1 file changed, 4 insertions(+), 24 deletions(-) (limited to 'graphics') diff --git a/graphics/fonts/macfont.cpp b/graphics/fonts/macfont.cpp index e8a52d10b2..a32fac710f 100644 --- a/graphics/fonts/macfont.cpp +++ b/graphics/fonts/macfont.cpp @@ -643,9 +643,6 @@ static void magnifyGray(Surface *src, int *dstGray, int width, int height, float } } -static const bool bdir = true; -static const bool pile = false; - static void makeBold(Surface *src, int *dstGray, MacGlyph *glyph, int height) { glyph->width++; @@ -658,28 +655,11 @@ static void makeBold(Surface *src, int *dstGray, MacGlyph *glyph, int height) { bool center = *srcPtr == 1; bool right = x > glyph->width - 1 ? false : *(srcPtr + 1) == 1; - bool tmp, bold; - - bool res; - - if (bdir) { - /* left shifted image */ - bold = left; - } else { - /* right shifted image */ - bold = right; - } - if (pile) { - /* left edge */ - tmp = left; - res = (!tmp && center) || bold; - } else { - /* right edge */ - tmp = right; - res = (!tmp && bold) || center; - } + bool edge, bold, res; - res = center || left; + bold = center || left; + edge = !center && right; + res = (bold && !edge); *dst = res ? 1 : 0; } -- cgit v1.2.3 From b31d5ac2b9efe04fa717f6c39b4ce1526b55fd19 Mon Sep 17 00:00:00 2001 From: Scott Percival Date: Sat, 11 Jan 2020 11:27:21 +0800 Subject: DIRECTOR: Align fill patterns to global origin --- graphics/macgui/macwindowmanager.cpp | 6 +++--- graphics/macgui/macwindowmanager.h | 6 ++++-- 2 files changed, 7 insertions(+), 5 deletions(-) (limited to 'graphics') diff --git a/graphics/macgui/macwindowmanager.cpp b/graphics/macgui/macwindowmanager.cpp index 12cd391f92..19448053a3 100644 --- a/graphics/macgui/macwindowmanager.cpp +++ b/graphics/macgui/macwindowmanager.cpp @@ -295,7 +295,7 @@ void macDrawPixel(int x, int y, int color, void *data) { uint yu = (uint)y; *((byte *)p->surface->getBasePtr(xu, yu)) = - (pat[yu % 8] & (1 << (7 - xu % 8))) ? + (pat[(yu - p->fillOriginY) % 8] & (1 << (7 - (xu - p->fillOriginX) % 8))) ? color : p->bgColor; } } else { @@ -310,7 +310,7 @@ void macDrawPixel(int x, int y, int color, void *data) { uint xu = (uint)x; // for letting compiler optimize it uint yu = (uint)y; *((byte *)p->surface->getBasePtr(xu, yu)) = - (pat[yu % 8] & (1 << (7 - xu % 8))) ? + (pat[(yu - p->fillOriginY) % 8] & (1 << (7 - (xu - p->fillOriginX) % 8))) ? color : p->bgColor; } } @@ -319,7 +319,7 @@ void macDrawPixel(int x, int y, int color, void *data) { void MacWindowManager::drawDesktop() { Common::Rect r(_screen->getBounds()); - MacPlotData pd(_screen, &_patterns, kPatternCheckers, 1, _colorWhite); + MacPlotData pd(_screen, &_patterns, kPatternCheckers, 0, 0, 1, _colorWhite); Graphics::drawRoundRect(r, kDesktopArc, _colorBlack, true, macDrawPixel, &pd); diff --git a/graphics/macgui/macwindowmanager.h b/graphics/macgui/macwindowmanager.h index c412e64f0a..5846bcba07 100644 --- a/graphics/macgui/macwindowmanager.h +++ b/graphics/macgui/macwindowmanager.h @@ -83,11 +83,13 @@ struct MacPlotData { Graphics::ManagedSurface *surface; MacPatterns *patterns; uint fillType; + int fillOriginX; + int fillOriginY; int thickness; uint bgColor; - MacPlotData(Graphics::ManagedSurface *s, MacPatterns *p, int f, int t, uint bg) : - surface(s), patterns(p), fillType(f), thickness(t), bgColor(bg) { + MacPlotData(Graphics::ManagedSurface *s, MacPatterns *p, uint f, int fx, int fy, int t, uint bg) : + surface(s), patterns(p), fillType(f), fillOriginX(fx), fillOriginY(fy), thickness(t), bgColor(bg) { } }; -- cgit v1.2.3 From 56aa8f3448c168abd0dc62ed283e92f7cb29f04b Mon Sep 17 00:00:00 2001 From: Scott Percival Date: Sat, 11 Jan 2020 11:55:45 +0800 Subject: GRAPHICS: Fix arguments order in drawRect --- graphics/primitives.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'graphics') diff --git a/graphics/primitives.cpp b/graphics/primitives.cpp index 60898aa16c..fd6c8fb262 100644 --- a/graphics/primitives.cpp +++ b/graphics/primitives.cpp @@ -247,8 +247,8 @@ void drawFilledRect(Common::Rect &rect, int color, void (*plotProc)(int, int, in void drawRect(Common::Rect &rect, int color, void (*plotProc)(int, int, int, void *), void *data) { drawHLine(rect.left, rect.right, rect.top, color, plotProc, data); drawHLine(rect.left, rect.right, rect.bottom, color, plotProc, data); - drawVLine(rect.top, rect.bottom, rect.left, color, plotProc, data); - drawVLine(rect.top, rect.bottom, rect.right, color, plotProc, data); + drawVLine(rect.left, rect.top, rect.bottom, color, plotProc, data); + drawVLine(rect.right, rect.top, rect.bottom, color, plotProc, data); } // http://members.chello.at/easyfilter/bresenham.html -- cgit v1.2.3 From 948c555ea616821ed7c2678ad406ed5bea392339 Mon Sep 17 00:00:00 2001 From: Cameron Cawley Date: Tue, 31 Dec 2019 19:19:42 +0000 Subject: ALL: Create all instances of NEResources and PEResources using new instead of on the stack Also adapted WinCursorGroup and MacMenu to reflect this. --- graphics/fonts/winfont.cpp | 14 ++++++++++---- graphics/macgui/macmenu.cpp | 5 +++-- graphics/macgui/macmenu.h | 4 ++-- graphics/wincursor.cpp | 12 ++++++------ graphics/wincursor.h | 4 ++-- 5 files changed, 23 insertions(+), 16 deletions(-) (limited to 'graphics') diff --git a/graphics/fonts/winfont.cpp b/graphics/fonts/winfont.cpp index ec6ce6f89a..6ba0136a52 100644 --- a/graphics/fonts/winfont.cpp +++ b/graphics/fonts/winfont.cpp @@ -86,15 +86,18 @@ bool WinFont::loadFromFON(const Common::String &fileName, const WinFontDirEntry } bool WinFont::loadFromNE(const Common::String &fileName, const WinFontDirEntry &dirEntry) { - Common::NEResources exe; + Common::NEResources *exe = new Common::NEResources(); - if (!exe.loadFromEXE(fileName)) + if (!exe->loadFromEXE(fileName)) { + delete exe; return false; + } // Let's pull out the font directory - Common::SeekableReadStream *fontDirectory = exe.getResource(Common::kWinFontDir, Common::String("FONTDIR")); + Common::SeekableReadStream *fontDirectory = exe->getResource(Common::kWinFontDir, Common::String("FONTDIR")); if (!fontDirectory) { warning("No font directory in '%s'", fileName.c_str()); + delete exe; return false; } @@ -105,18 +108,21 @@ bool WinFont::loadFromNE(const Common::String &fileName, const WinFontDirEntry & // Couldn't match the face name if (fontId == 0xffffffff) { warning("Could not find face '%s' in '%s'", dirEntry.faceName.c_str(), fileName.c_str()); + delete exe; return false; } // Actually go get our font now... - Common::SeekableReadStream *fontStream = exe.getResource(Common::kWinFont, fontId); + Common::SeekableReadStream *fontStream = exe->getResource(Common::kWinFont, fontId); if (!fontStream) { warning("Could not find font %d in %s", fontId, fileName.c_str()); + delete exe; return false; } bool ok = loadFromFNT(*fontStream); delete fontStream; + delete exe; return ok; } diff --git a/graphics/macgui/macmenu.cpp b/graphics/macgui/macmenu.cpp index 2c9b3f0902..b79ba8cfbc 100644 --- a/graphics/macgui/macmenu.cpp +++ b/graphics/macgui/macmenu.cpp @@ -24,6 +24,7 @@ #include "common/stack.h" #include "common/keyboard.h" #include "common/macresman.h" +#include "common/winexe_pe.h" #include "graphics/primitives.h" #include "graphics/font.h" @@ -200,8 +201,8 @@ static Common::U32String readUnicodeString(Common::SeekableReadStream *stream) { } -MacMenu *MacMenu::createMenuFromPEexe(Common::PEResources &exe, MacWindowManager *wm) { - Common::SeekableReadStream *menuData = exe.getResource(Common::kWinMenu, 128); +MacMenu *MacMenu::createMenuFromPEexe(Common::PEResources *exe, MacWindowManager *wm) { + Common::SeekableReadStream *menuData = exe->getResource(Common::kWinMenu, 128); if (!menuData) return nullptr; diff --git a/graphics/macgui/macmenu.h b/graphics/macgui/macmenu.h index c8633c0cc7..13d374d084 100644 --- a/graphics/macgui/macmenu.h +++ b/graphics/macgui/macmenu.h @@ -24,11 +24,11 @@ #define GRAPHICS_MACGUI_MACMENU_H #include "common/str-array.h" -#include "common/winexe_pe.h" namespace Common { class U32String; class MacResManager; +class PEResources; } namespace Graphics { @@ -51,7 +51,7 @@ public: ~MacMenu(); static Common::StringArray *readMenuFromResource(Common::SeekableReadStream *res); - static MacMenu *createMenuFromPEexe(Common::PEResources &exe, MacWindowManager *wm); + static MacMenu *createMenuFromPEexe(Common::PEResources *exe, MacWindowManager *wm); void setCommandsCallback(void (*callback)(int, Common::String &, void *), void *data) { _ccallback = callback; _cdata = data; } void setCommandsCallback(void (*callback)(int, Common::U32String &, void *), void *data) { _unicodeccallback = callback; _cdata = data; } diff --git a/graphics/wincursor.cpp b/graphics/wincursor.cpp index 13d9bebfba..4cade1f5e2 100644 --- a/graphics/wincursor.cpp +++ b/graphics/wincursor.cpp @@ -242,8 +242,8 @@ WinCursorGroup::~WinCursorGroup() { delete cursors[i].cursor; } -WinCursorGroup *WinCursorGroup::createCursorGroup(Common::NEResources &exe, const Common::WinResourceID &id) { - Common::ScopedPtr stream(exe.getResource(Common::kWinGroupCursor, id)); +WinCursorGroup *WinCursorGroup::createCursorGroup(Common::NEResources *exe, const Common::WinResourceID &id) { + Common::ScopedPtr stream(exe->getResource(Common::kWinGroupCursor, id)); if (!stream || stream->size() <= 6) return 0; @@ -276,7 +276,7 @@ WinCursorGroup *WinCursorGroup::createCursorGroup(Common::NEResources &exe, cons stream->readUint32LE(); // data size uint32 cursorId = stream->readUint16LE(); - Common::ScopedPtr cursorStream(exe.getResource(Common::kWinCursor, cursorId)); + Common::ScopedPtr cursorStream(exe->getResource(Common::kWinCursor, cursorId)); if (!cursorStream) { delete group; return 0; @@ -298,8 +298,8 @@ WinCursorGroup *WinCursorGroup::createCursorGroup(Common::NEResources &exe, cons return group; } -WinCursorGroup *WinCursorGroup::createCursorGroup(Common::PEResources &exe, const Common::WinResourceID &id) { - Common::ScopedPtr stream(exe.getResource(Common::kWinGroupCursor, id)); +WinCursorGroup *WinCursorGroup::createCursorGroup(Common::PEResources *exe, const Common::WinResourceID &id) { + Common::ScopedPtr stream(exe->getResource(Common::kWinGroupCursor, id)); if (!stream || stream->size() <= 6) return 0; @@ -325,7 +325,7 @@ WinCursorGroup *WinCursorGroup::createCursorGroup(Common::PEResources &exe, cons stream->readUint32LE(); // data size uint32 cursorId = stream->readUint16LE(); - Common::ScopedPtr cursorStream(exe.getResource(Common::kWinCursor, cursorId)); + Common::ScopedPtr cursorStream(exe->getResource(Common::kWinCursor, cursorId)); if (!cursorStream) { delete group; return 0; diff --git a/graphics/wincursor.h b/graphics/wincursor.h index 2780b23a90..d77314458b 100644 --- a/graphics/wincursor.h +++ b/graphics/wincursor.h @@ -57,9 +57,9 @@ struct WinCursorGroup { Common::Array cursors; /** Create a cursor group from an NE EXE, returns 0 on failure */ - static WinCursorGroup *createCursorGroup(Common::NEResources &exe, const Common::WinResourceID &id); + static WinCursorGroup *createCursorGroup(Common::NEResources *exe, const Common::WinResourceID &id); /** Create a cursor group from an PE EXE, returns 0 on failure */ - static WinCursorGroup *createCursorGroup(Common::PEResources &exe, const Common::WinResourceID &id); + static WinCursorGroup *createCursorGroup(Common::PEResources *exe, const Common::WinResourceID &id); }; /** -- cgit v1.2.3 From e49282577fb10e65fd06fcb7808e300cf97b3ca8 Mon Sep 17 00:00:00 2001 From: Cameron Cawley Date: Thu, 2 Jan 2020 21:56:51 +0000 Subject: GRAPHICS: Simplify loading Windows fonts --- graphics/fonts/winfont.cpp | 67 +++++++++++----------------------------------- graphics/fonts/winfont.h | 4 +-- 2 files changed, 17 insertions(+), 54 deletions(-) (limited to 'graphics') diff --git a/graphics/fonts/winfont.cpp b/graphics/fonts/winfont.cpp index 6ba0136a52..6494f006b3 100644 --- a/graphics/fonts/winfont.cpp +++ b/graphics/fonts/winfont.cpp @@ -77,68 +77,34 @@ static WinFontDirEntry readDirEntry(Common::SeekableReadStream &stream) { } bool WinFont::loadFromFON(const Common::String &fileName, const WinFontDirEntry &dirEntry) { - // First try loading via the NE code - if (loadFromNE(fileName, dirEntry)) - return true; - - // Then try loading via the PE code - return loadFromPE(fileName, dirEntry); -} - -bool WinFont::loadFromNE(const Common::String &fileName, const WinFontDirEntry &dirEntry) { - Common::NEResources *exe = new Common::NEResources(); - - if (!exe->loadFromEXE(fileName)) { - delete exe; - return false; - } - - // Let's pull out the font directory - Common::SeekableReadStream *fontDirectory = exe->getResource(Common::kWinFontDir, Common::String("FONTDIR")); - if (!fontDirectory) { - warning("No font directory in '%s'", fileName.c_str()); - delete exe; - return false; - } - - uint32 fontId = getFontIndex(*fontDirectory, dirEntry); - - delete fontDirectory; + Common::WinResources *exe; - // Couldn't match the face name - if (fontId == 0xffffffff) { - warning("Could not find face '%s' in '%s'", dirEntry.faceName.c_str(), fileName.c_str()); + // First try loading via the NE code + exe = new Common::NEResources(); + if (exe->loadFromEXE(fileName)) { + bool ok = loadFromEXE(exe, fileName, dirEntry); delete exe; - return false; + return ok; } + delete exe; - // Actually go get our font now... - Common::SeekableReadStream *fontStream = exe->getResource(Common::kWinFont, fontId); - if (!fontStream) { - warning("Could not find font %d in %s", fontId, fileName.c_str()); + // Then try loading via the PE code + exe = new Common::PEResources(); + if (exe->loadFromEXE(fileName)) { + bool ok = loadFromEXE(exe, fileName, dirEntry); delete exe; - return false; + return ok; } - - bool ok = loadFromFNT(*fontStream); - delete fontStream; delete exe; - return ok; -} - -bool WinFont::loadFromPE(const Common::String &fileName, const WinFontDirEntry &dirEntry) { - Common::PEResources *exe = new Common::PEResources(); - if (!exe->loadFromEXE(fileName)) { - delete exe; - return false; - } + return false; +} +bool WinFont::loadFromEXE(Common::WinResources *exe, const Common::String &fileName, const WinFontDirEntry &dirEntry) { // Let's pull out the font directory Common::SeekableReadStream *fontDirectory = exe->getResource(Common::kWinFontDir, Common::String("FONTDIR")); if (!fontDirectory) { warning("No font directory in '%s'", fileName.c_str()); - delete exe; return false; } @@ -149,7 +115,6 @@ bool WinFont::loadFromPE(const Common::String &fileName, const WinFontDirEntry & // Couldn't match the face name if (fontId == 0xffffffff) { warning("Could not find face '%s' in '%s'", dirEntry.faceName.c_str(), fileName.c_str()); - delete exe; return false; } @@ -157,13 +122,11 @@ bool WinFont::loadFromPE(const Common::String &fileName, const WinFontDirEntry & Common::SeekableReadStream *fontStream = exe->getResource(Common::kWinFont, fontId); if (!fontStream) { warning("Could not find font %d in %s", fontId, fileName.c_str()); - delete exe; return false; } bool ok = loadFromFNT(*fontStream); delete fontStream; - delete exe; return ok; } diff --git a/graphics/fonts/winfont.h b/graphics/fonts/winfont.h index 3354fc2381..f1c661f270 100644 --- a/graphics/fonts/winfont.h +++ b/graphics/fonts/winfont.h @@ -28,6 +28,7 @@ namespace Common { class SeekableReadStream; +class WinResources; } namespace Graphics { @@ -67,8 +68,7 @@ public: void drawChar(Surface *dst, uint32 chr, int x, int y, uint32 color) const; private: - bool loadFromPE(const Common::String &fileName, const WinFontDirEntry &dirEntry); - bool loadFromNE(const Common::String &fileName, const WinFontDirEntry &dirEntry); + bool loadFromEXE(Common::WinResources *exe, const Common::String &fileName, const WinFontDirEntry &dirEntry); uint32 getFontIndex(Common::SeekableReadStream &stream, const WinFontDirEntry &dirEntry); bool loadFromFNT(Common::SeekableReadStream &stream); -- cgit v1.2.3 From 5cd6812b9d53d532d12cfc81b6df144dc0e89d48 Mon Sep 17 00:00:00 2001 From: Cameron Cawley Date: Thu, 2 Jan 2020 22:32:03 +0000 Subject: GRAPHICS: Unify loading Windows cursor groups --- graphics/wincursor.cpp | 60 +------------------------------------------------- graphics/wincursor.h | 8 ++----- 2 files changed, 3 insertions(+), 65 deletions(-) (limited to 'graphics') diff --git a/graphics/wincursor.cpp b/graphics/wincursor.cpp index 4cade1f5e2..7abd1a33ad 100644 --- a/graphics/wincursor.cpp +++ b/graphics/wincursor.cpp @@ -23,8 +23,6 @@ #include "common/ptr.h" #include "common/stream.h" #include "common/textconsole.h" -#include "common/winexe_ne.h" -#include "common/winexe_pe.h" #include "graphics/wincursor.h" @@ -242,63 +240,7 @@ WinCursorGroup::~WinCursorGroup() { delete cursors[i].cursor; } -WinCursorGroup *WinCursorGroup::createCursorGroup(Common::NEResources *exe, const Common::WinResourceID &id) { - Common::ScopedPtr stream(exe->getResource(Common::kWinGroupCursor, id)); - - if (!stream || stream->size() <= 6) - return 0; - - stream->skip(4); - uint32 cursorCount = stream->readUint16LE(); - if ((uint32)stream->size() < (6 + cursorCount * 14)) - return 0; - - WinCursorGroup *group = new WinCursorGroup(); - group->cursors.reserve(cursorCount); - - for (uint32 i = 0; i < cursorCount; i++) { - stream->readUint16LE(); // width - stream->readUint16LE(); // height - - // Plane count - if (stream->readUint16LE() != 1) { - delete group; - return 0; - } - - // Bits per pixel - // NE cursors can only be 1bpp - if (stream->readUint16LE() != 1) { - delete group; - return 0; - } - - stream->readUint32LE(); // data size - uint32 cursorId = stream->readUint16LE(); - - Common::ScopedPtr cursorStream(exe->getResource(Common::kWinCursor, cursorId)); - if (!cursorStream) { - delete group; - return 0; - } - - WinCursor *cursor = new WinCursor(); - if (!cursor->readFromStream(*cursorStream)) { - delete cursor; - delete group; - return 0; - } - - CursorItem item; - item.id = cursorId; - item.cursor = cursor; - group->cursors.push_back(item); - } - - return group; -} - -WinCursorGroup *WinCursorGroup::createCursorGroup(Common::PEResources *exe, const Common::WinResourceID &id) { +WinCursorGroup *WinCursorGroup::createCursorGroup(Common::WinResources *exe, const Common::WinResourceID &id) { Common::ScopedPtr stream(exe->getResource(Common::kWinGroupCursor, id)); if (!stream || stream->size() <= 6) diff --git a/graphics/wincursor.h b/graphics/wincursor.h index d77314458b..77d00d2d69 100644 --- a/graphics/wincursor.h +++ b/graphics/wincursor.h @@ -29,8 +29,6 @@ #include "graphics/cursor.h" namespace Common { -class NEResources; -class PEResources; class SeekableReadStream; } @@ -56,10 +54,8 @@ struct WinCursorGroup { Common::Array cursors; - /** Create a cursor group from an NE EXE, returns 0 on failure */ - static WinCursorGroup *createCursorGroup(Common::NEResources *exe, const Common::WinResourceID &id); - /** Create a cursor group from an PE EXE, returns 0 on failure */ - static WinCursorGroup *createCursorGroup(Common::PEResources *exe, const Common::WinResourceID &id); + /** Create a cursor group from an EXE, returns 0 on failure */ + static WinCursorGroup *createCursorGroup(Common::WinResources *exe, const Common::WinResourceID &id); }; /** -- cgit v1.2.3 From a692905eb273ae8c33ba1351e519b93dbf10f7fd Mon Sep 17 00:00:00 2001 From: Cameron Cawley Date: Sat, 4 Jan 2020 15:00:40 +0000 Subject: COMMON: Add a function to simplify loading Windows executables --- graphics/fonts/winfont.cpp | 24 +++++------------------- 1 file changed, 5 insertions(+), 19 deletions(-) (limited to 'graphics') diff --git a/graphics/fonts/winfont.cpp b/graphics/fonts/winfont.cpp index 6494f006b3..ad5b36ec23 100644 --- a/graphics/fonts/winfont.cpp +++ b/graphics/fonts/winfont.cpp @@ -77,27 +77,13 @@ static WinFontDirEntry readDirEntry(Common::SeekableReadStream &stream) { } bool WinFont::loadFromFON(const Common::String &fileName, const WinFontDirEntry &dirEntry) { - Common::WinResources *exe; - - // First try loading via the NE code - exe = new Common::NEResources(); - if (exe->loadFromEXE(fileName)) { - bool ok = loadFromEXE(exe, fileName, dirEntry); - delete exe; - return ok; - } - delete exe; + Common::WinResources *exe = Common::WinResources::createFromEXE(fileName); + if (!exe) + return false; - // Then try loading via the PE code - exe = new Common::PEResources(); - if (exe->loadFromEXE(fileName)) { - bool ok = loadFromEXE(exe, fileName, dirEntry); - delete exe; - return ok; - } + bool ok = loadFromEXE(exe, fileName, dirEntry); delete exe; - - return false; + return ok; } bool WinFont::loadFromEXE(Common::WinResources *exe, const Common::String &fileName, const WinFontDirEntry &dirEntry) { -- cgit v1.2.3 From 6bf14cf5477f55ccee4414d8b081cd6d71afd163 Mon Sep 17 00:00:00 2001 From: Harsh Bawari Date: Sat, 11 Jan 2020 21:05:55 +0530 Subject: GRIFFON: Fix slugginess in final boss and a crash when loading the Griffon.s03 map --- graphics/transparent_surface.cpp | 13 ------------- 1 file changed, 13 deletions(-) (limited to 'graphics') diff --git a/graphics/transparent_surface.cpp b/graphics/transparent_surface.cpp index eb8d3fe5ce..1ad1ed637c 100644 --- a/graphics/transparent_surface.cpp +++ b/graphics/transparent_surface.cpp @@ -749,43 +749,30 @@ void TransparentSurface::setAlphaMode(AlphaType mode) { /* - The below two functions are adapted from SDL_rotozoom.c, taken from SDL_gfx-2.0.18. - Its copyright notice: - ============================================================================= SDL_rotozoom.c: rotozoomer, zoomer and shrinker for 32bit or 8bit surfaces - Copyright (C) 2001-2012 Andreas Schiffler - This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. - Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: - 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. - Andreas Schiffler -- aschiffler at ferzkopp dot net ============================================================================= - - The functions have been adapted for different structures and coordinate systems. - */ -- cgit v1.2.3