GRAPHICS: MACGUI: Initial code for generating outlined fonts

This commit is contained in:
Eugene Sandulenko 2020-03-22 01:39:04 +01:00
parent 7dbe6cf110
commit 6774d7aced
2 changed files with 23 additions and 3 deletions

View File

@ -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;

View File

@ -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: