From 6774d7aced6b324b3cd41e1a522197ee56b9db08 Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Sun, 22 Mar 2020 01:39:04 +0100 Subject: [PATCH] GRAPHICS: MACGUI: Initial code for generating outlined fonts --- graphics/fonts/macfont.cpp | 24 ++++++++++++++++++++++-- graphics/fonts/macfont.h | 2 +- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/graphics/fonts/macfont.cpp b/graphics/fonts/macfont.cpp index a32fac710f3..2fdc00124f7 100644 --- a/graphics/fonts/macfont.cpp +++ b/graphics/fonts/macfont.cpp @@ -401,8 +401,9 @@ bool dododo; static void magnifyGray(Surface *src, int *dstGray, int width, int height, float scale); static void makeBold(Surface *src, int *dstGray, MacGlyph *glyph, int height); +static void makeOutline(Surface *src, Surface *dst, MacGlyph *glyph, int height); -MacFONTFont *MacFONTFont::scaleFont(const MacFONTFont *src, int newSize, bool bold, bool italic) { +MacFONTFont *MacFONTFont::scaleFont(const MacFONTFont *src, int newSize, bool bold, bool italic, bool outline) { if (!src) { warning("Empty font reference in scale font"); return NULL; @@ -413,12 +414,15 @@ MacFONTFont *MacFONTFont::scaleFont(const MacFONTFont *src, int newSize, bool bo return NULL; } - Graphics::Surface srcSurf; + Graphics::Surface srcSurf, tmpSurf; 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)); + tmpSurf.create(MAX(src->getFontSize() * 2, newSize * 2), MAX(src->getFontSize() * 2, newSize * 2), + PixelFormat::createFormatCLUT8()); + float scale = (float)newSize / (float)src->getFontSize(); MacFONTdata data; @@ -530,6 +534,10 @@ MacFONTFont *MacFONTFont::scaleFont(const MacFONTFont *src, int newSize, bool bo } } + if (outline) { + makeOutline(&srcSurf, &tmpSurf, glyph, data._fRectHeight); + } + byte *ptr = &data._bitImage[glyph->bitmapOffset / 8]; for (int y = 0; y < data._fRectHeight; y++) { @@ -666,6 +674,18 @@ static void makeBold(Surface *src, int *dstGray, MacGlyph *glyph, int height) { } } +static void makeOutline(Surface *src, Surface *dst, MacGlyph *glyph, int height) { + glyph->width++; + + for (uint16 y = 0; y < height; y++) { + byte *srcPtr = (byte *)src->getBasePtr(0, y); + byte *dstPtr = (byte *)dst->getBasePtr(0, y); + + for (uint16 x = 0; x < glyph->width - 1; x++, srcPtr++, dstPtr++) + *dstPtr = *srcPtr ^ srcPtr[1]; + } +} + 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 cb11304eb2f..ace5f1fb900 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, bool bold = false, bool italic = false); + static MacFONTFont *scaleFont(const MacFONTFont *src, int newSize, bool bold = false, bool italic = false, bool outline = false); static void testBlit(const MacFONTFont *src, ManagedSurface *dst, int color, int x0, int y0, int width); private: