Gfx: Add __D2DParams option to allow testing D2D text rendering options

This commit is contained in:
Birunthan Mohanathas 2013-09-29 11:28:28 +03:00
parent c1aa191235
commit d003db6531
3 changed files with 32 additions and 0 deletions

View File

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

View File

@ -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<IDWriteRenderingParams> 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.

View File

@ -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<ID2D1RenderTarget> m_Target;
Microsoft::WRL::ComPtr<IDWriteRenderingParams> 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.