From 2aa22684f37c65cb535e72ac8a4ffa4cd486ac4f Mon Sep 17 00:00:00 2001 From: jules Date: Wed, 24 Oct 2012 10:45:44 +0100 Subject: [PATCH] Workaround for strange type layout bug in Windows 64. --- .../juce_win32_DirectWriteTypeLayout.cpp | 18 ++++++++++++++++-- .../components/juce_Component.cpp | 7 ++++--- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/modules/juce_graphics/native/juce_win32_DirectWriteTypeLayout.cpp b/modules/juce_graphics/native/juce_win32_DirectWriteTypeLayout.cpp index 2c91d4311a..625f7a274e 100644 --- a/modules/juce_graphics/native/juce_win32_DirectWriteTypeLayout.cpp +++ b/modules/juce_graphics/native/juce_win32_DirectWriteTypeLayout.cpp @@ -273,7 +273,7 @@ namespace DirectWriteTypeLayout } } - void setupLayout (const AttributedString& text, const float& maxWidth, const float& maxHeight, + void setupLayout (const AttributedString& text, const float maxWidth, const float maxHeight, ID2D1RenderTarget* const renderTarget, IDWriteFactory* const directWriteFactory, IDWriteFontCollection* const fontCollection, IDWriteTextLayout** dwTextLayout) { @@ -334,7 +334,7 @@ namespace DirectWriteTypeLayout HRESULT hr = direct2dFactory->CreateDCRenderTarget (&d2dRTProp, renderTarget.resetAndGetPointerAddress()); ComSmartPtr dwTextLayout; - setupLayout(text, layout.getWidth(), 1.0e7f, renderTarget, directWriteFactory, fontCollection, dwTextLayout.resetAndGetPointerAddress()); + setupLayout (text, layout.getWidth(), 1.0e7f, renderTarget, directWriteFactory, fontCollection, dwTextLayout.resetAndGetPointerAddress()); UINT32 actualLineCount = 0; hr = dwTextLayout->GetLineMetrics (nullptr, 0, &actualLineCount); @@ -382,6 +382,20 @@ bool TextLayout::createNativeLayout (const AttributedString& text) if (factories.d2dFactory != nullptr && factories.systemFonts != nullptr) { + #if JUCE_64BIT + // There's a mysterious bug in 64-bit Windows that causes garbage floating-point + // values to be returned to DrawGlyphRun the first time that it gets used. + // In lieu of a better plan, this bodge uses a dummy call to work around this. + static bool hasBeenCalled = false; + if (! hasBeenCalled) + { + hasBeenCalled = true; + TextLayout dummy; + DirectWriteTypeLayout::createLayout (dummy, text, factories.directWriteFactory, + factories.d2dFactory, factories.systemFonts); + } + #endif + DirectWriteTypeLayout::createLayout (*this, text, factories.directWriteFactory, factories.d2dFactory, factories.systemFonts); return true; diff --git a/modules/juce_gui_basics/components/juce_Component.cpp b/modules/juce_gui_basics/components/juce_Component.cpp index ca06aa6f49..8fc2b1ee44 100644 --- a/modules/juce_gui_basics/components/juce_Component.cpp +++ b/modules/juce_gui_basics/components/juce_Component.cpp @@ -1953,10 +1953,11 @@ Image Component::createComponentSnapshot (const Rectangle& areaToGrab, if (clipImageToComponentBounds) r = r.getIntersection (getLocalBounds()); + if (r.isEmpty()) + return Image(); + Image componentImage (flags.opaqueFlag ? Image::RGB : Image::ARGB, - jmax (1, r.getWidth()), - jmax (1, r.getHeight()), - true); + r.getWidth(), r.getHeight(), true); Graphics imageContext (componentImage); imageContext.setOrigin (-r.getX(), -r.getY());