Skip to content

Commit

Permalink
Fixed|macOS|libgui: Core Text font rasterization
Browse files Browse the repository at this point in the history
Use the new Image origin to position the rasterized image. This means the image does not have to contain any whitespace margins.
  • Loading branch information
skyjake committed Sep 1, 2019
1 parent a895d0e commit b61b3c7
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 35 deletions.
Expand Up @@ -13,11 +13,7 @@ script {
def loadFonts()
import App
fontDir = __file__.fileNamePath() / "fonts"
fontStyles = ['Regular', 'Bold', 'Italic', 'BoldItalic']
# Light fonts are a bit too thin for low-res displays.
if DisplayMode.PIXEL_RATIO > 1
fontStyles += ['Light', 'LightItalic']
end
fontStyles = ['Regular', 'Bold', 'Italic', 'BoldItalic', 'Light', 'LightItalic']
for style in fontStyles
App.loadFont(fontDir / ("Source Sans Pro/SourceSansPro-%s.ttf" % style))
end
Expand All @@ -29,41 +25,41 @@ script {
}

group {
condition: Version.OS == 'windows'
condition: Version.OS in ['windows', 'unix']

script { loadFonts() }

font default {
family: Source Sans Pro
size: 12pt
family: SourceSansPro
size: 16pt
weight: normal
style: normal
}

font monospace inherits default {
family: Source Code Pro
size: 9pt
}
}

group {
condition: Version.OS == 'unix'

script { loadFonts() }

font default {
family: Source Sans Pro
family: SourceCodePro
size: 12pt
weight: normal
style: normal
}

font monospace inherits default {
family: Source Code Pro
size: 9pt
}
}

# group {
# condition: Version.OS == 'unix'
#
# script { loadFonts() }
#
# font default {
# family: Source Sans Pro
# size: 12pt
# weight: normal
# style: normal
# }
#
# font monospace inherits default {
# family: Source Code Pro
# size: 9pt
# }
# }

group {
condition: Version.OS in ['macx', 'ios']

Expand Down
4 changes: 3 additions & 1 deletion doomsday/libs/gui/src/text/coretextnativefont_macx.cpp
Expand Up @@ -385,7 +385,9 @@ Image CoreTextNativeFont::nativeFontRasterize(const String &text,
kCGImageAlphaPremultipliedLast);
CGContextScaleCTM(gc, pixelRatio(), pixelRatio());

CGContextSetTextPosition(gc, -bounds.topLeft.x, -bounds.topLeft.y);
CGContextSetTextPosition(gc,
-bounds.topLeft.x / pixelRatio(),
bounds.bottom() / pixelRatio());
CTLineDraw(d->cache.line, gc);

CGColorRelease(fgColor);
Expand Down
13 changes: 6 additions & 7 deletions doomsday/libs/gui/src/text/font.cpp
Expand Up @@ -22,21 +22,20 @@
#include <de/Hash>
#include <de/ThreadLocal>

#if 0
//#elif (defined(MACOSX) && defined(MACOS_10_7)) || defined (DE_IOS)
# include "coretextnativefont_macx.h"
namespace de { using PlatformFont = CoreTextNativeFont; }
#if (defined(MACOSX) && defined(MACOS_10_7)) || defined(DE_IOS)
# include "coretextnativefont_macx.h"
namespace de { using PlatformFont = CoreTextNativeFont; }
#else
# include "stbttnativefont.h"
namespace de { using PlatformFont = StbTtNativeFont; }
# include "stbttnativefont.h"
namespace de { using PlatformFont = StbTtNativeFont; }
#endif

namespace std {
template<>
struct hash<de::FontParams> {
std::size_t operator()(const de::FontParams &fp) const {
return hash<de::String>()(fp.family)
^ hash<int>()(int(100 * fp.pointSize))
^ hash<int>()(int(100 * fp.pointSize + 0.5f))
^ hash<int>()(fp.spec.weight)
^ hash<int>()(int(fp.spec.style))
^ hash<int>()(fp.spec.transform);
Expand Down

0 comments on commit b61b3c7

Please sign in to comment.