aboutsummaryrefslogtreecommitdiff
path: root/graphics/fonts
diff options
context:
space:
mode:
authorEugene Sandulenko2020-01-07 21:54:38 +0100
committerEugene Sandulenko2020-01-07 21:57:12 +0100
commitfc00b78a48e3d5950858cfe5c5720de03f2ff803 (patch)
tree1d5df0fdadbcc72512f3f4817ef0f3ac102439d6 /graphics/fonts
parentb5a95d478302c3f98f559eb676d2f3bcba3ce09d (diff)
downloadscummvm-rg350-fc00b78a48e3d5950858cfe5c5720de03f2ff803.tar.gz
scummvm-rg350-fc00b78a48e3d5950858cfe5c5720de03f2ff803.tar.bz2
scummvm-rg350-fc00b78a48e3d5950858cfe5c5720de03f2ff803.zip
GRAPHICS: FONTS: Implement generation of bold fonts
Diffstat (limited to 'graphics/fonts')
-rw-r--r--graphics/fonts/macfont.cpp85
-rw-r--r--graphics/fonts/macfont.h2
2 files changed, 78 insertions, 9 deletions
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: