diff --git a/Common/Gfx/Canvas.h b/Common/Gfx/Canvas.h index 5b7b88dd..c64170ca 100644 --- a/Common/Gfx/Canvas.h +++ b/Common/Gfx/Canvas.h @@ -84,6 +84,9 @@ public: virtual void SetAntiAliasing(bool enable) = 0; virtual void SetTextAntiAliasing(bool enable) = 0; + // FIXME: Temporary hack to test things out. This will be removed when no longer needed. + virtual void SetTextRenderingOptions(float gamma, float enhancedContrast) {}; + virtual void Clear(const Gdiplus::Color& color = Gdiplus::Color(0, 0, 0, 0)) = 0; virtual void DrawTextW(const WCHAR* str, UINT strLen, const TextFormat& format, Gdiplus::RectF& rect, const Gdiplus::SolidBrush& brush) = 0; diff --git a/Common/Gfx/CanvasD2D.cpp b/Common/Gfx/CanvasD2D.cpp index fe1c7d12..b9fde5cb 100644 --- a/Common/Gfx/CanvasD2D.cpp +++ b/Common/Gfx/CanvasD2D.cpp @@ -167,6 +167,10 @@ bool CanvasD2D::BeginTargetDraw() if (SUCCEEDED(hr)) { SetTextAntiAliasing(m_TextAntiAliasing); + if (m_TextRenderingParams) + { + m_Target->SetTextRenderingParams(m_TextRenderingParams.Get()); + } m_Target->BeginDraw(); @@ -295,6 +299,27 @@ void CanvasD2D::SetTextAntiAliasing(bool enable) } } +void CanvasD2D::SetTextRenderingOptions(float gamma, float enhancedContrast) +{ + Microsoft::WRL::ComPtr defaultRenderingParams; + HRESULT hr = c_DWFactory->CreateRenderingParams(defaultRenderingParams.GetAddressOf()); + if (SUCCEEDED(hr)) + { + hr = c_DWFactory->CreateCustomRenderingParams( + gamma, + enhancedContrast, + defaultRenderingParams->GetClearTypeLevel(), + defaultRenderingParams->GetPixelGeometry(), + defaultRenderingParams->GetRenderingMode(), + m_TextRenderingParams.ReleaseAndGetAddressOf()); + } + + if (SUCCEEDED(hr) && m_Target) + { + m_Target->SetTextRenderingParams(m_TextRenderingParams.Get()); + } +} + void CanvasD2D::Clear(const Gdiplus::Color& color) { if (!m_Target) // Use GDI+ if D2D render target has not been created. diff --git a/Common/Gfx/CanvasD2D.h b/Common/Gfx/CanvasD2D.h index 94179b8b..2f578713 100644 --- a/Common/Gfx/CanvasD2D.h +++ b/Common/Gfx/CanvasD2D.h @@ -60,6 +60,7 @@ public: virtual void SetAntiAliasing(bool enable) override; virtual void SetTextAntiAliasing(bool enable) override; + virtual void SetTextRenderingOptions(float gamma, float enhancedContrast) override; virtual void Clear(const Gdiplus::Color& color) override; @@ -90,6 +91,9 @@ private: void UpdateTargetTransform(); Microsoft::WRL::ComPtr m_Target; + Microsoft::WRL::ComPtr m_TextRenderingParams; + + // Underlying pixel data shared by both m_Target and m_GdipBitmap. Util::WICBitmapDIB m_Bitmap; // GDI+ objects that share the pixel data of m_Bitmap.