Skip to content

Commit

Permalink
Merge pull request #304 from steinbergmedia/textrendering-inconsistency
Browse files Browse the repository at this point in the history
Apply bxjoscha's text rendering inconsistency fix
  • Loading branch information
scheffle committed Aug 6, 2023
2 parents 8847ccf + be6aa48 commit 8739639
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
10 changes: 10 additions & 0 deletions vstgui/lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@
##########################################################################################
set(target vstgui)

option(
VSTGUI_TEXTRENDERING_LEGACY_INCONSISTENCY
"Use the legacy platform inconsistency text rendering"
OFF
)

if(${VSTGUI_TEXTRENDERING_LEGACY_INCONSISTENCY})
target_compile_definitions(${target} PRIVATE VSTGUI_TEXTRENDERING_LEGACY_INCONSISTENCY=1)
endif()

set(${target}_common_sources
animation/animations.cpp
animation/animations.h
Expand Down
9 changes: 8 additions & 1 deletion vstgui/lib/platform/mac/coregraphicsdevicecontext.mm
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,13 @@ void drawCGImageRef (CGContextRef context, CGImageRef image, CGLayerRef layer,
using BitmapDrawCountMap = std::map<CGBitmap*, int32_t>;
BitmapDrawCountMap bitmapDrawCount;

#if defined(VSTGUI_TEXTRENDERING_LEGACY_INCONSISTENCY) && \
VSTGUI_TEXTRENDERING_LEGACY_INCONSISTENCY == 1
static constexpr bool shouldSmoothFonts = true;
#else
static constexpr bool shouldSmoothFonts = false;
#endif

#if DEBUG
bool showClip {false};
#endif
Expand Down Expand Up @@ -903,7 +910,7 @@ void drawCGImageRef (CGContextRef context, CGImageRef image, CGLayerRef layer,
if (impl->state.drawMode.integralMode ())
cgPoint = impl->pixelAlligned (cgPoint);
CGContextSetShouldAntialias (context, antialias);
CGContextSetShouldSmoothFonts (context, true);
CGContextSetShouldSmoothFonts (context, impl->shouldSmoothFonts);
CGContextSetShouldSubpixelPositionFonts (context, true);
CGContextSetShouldSubpixelQuantizeFonts (context, true);
CGContextSetTextPosition (context, cgPoint.x, cgPoint.y);
Expand Down
9 changes: 8 additions & 1 deletion vstgui/lib/platform/win32/direct2d/d2dgraphicscontext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,13 @@ struct D2DGraphicsDeviceContext::Impl

const D2DGraphicsDevice& device;
COM::Ptr<ID2D1DeviceContext> deviceContext;

#if defined(VSTGUI_TEXTRENDERING_LEGACY_INCONSISTENCY) && \
VSTGUI_TEXTRENDERING_LEGACY_INCONSISTENCY == 1
static constexpr auto antialiasMode = D2D1_TEXT_ANTIALIAS_MODE_CLEARTYPE;
#else
static constexpr auto antialiasMode = D2D1_TEXT_ANTIALIAS_MODE_DEFAULT;
#endif
};

//------------------------------------------------------------------------
Expand Down Expand Up @@ -928,7 +935,7 @@ void D2DGraphicsDeviceContext::drawTextLayout (IDWriteTextLayout* textLayout, CP
CColor color, bool antialias)
{
impl->doInContext ([&] (auto deviceContext) {
deviceContext->SetTextAntialiasMode (antialias ? D2D1_TEXT_ANTIALIAS_MODE_CLEARTYPE
deviceContext->SetTextAntialiasMode (antialias ? impl->antialiasMode
: D2D1_TEXT_ANTIALIAS_MODE_ALIASED);
if (impl->state.drawMode.integralMode ())
pos.makeIntegral ();
Expand Down

0 comments on commit 8739639

Please sign in to comment.