diff --git a/Common/Gfx/TextFormatD2D.h b/Common/Gfx/TextFormatD2D.h index 537853c2..543c71d4 100644 --- a/Common/Gfx/TextFormatD2D.h +++ b/Common/Gfx/TextFormatD2D.h @@ -47,6 +47,8 @@ public: private: friend class CanvasD2D; + friend class Common_Gfx_TextFormatD2D_Test; + TextFormatD2D(const TextFormatD2D& other) {} void Dispose(); diff --git a/Common/Gfx/TextFormatD2D_Test.cpp b/Common/Gfx/TextFormatD2D_Test.cpp new file mode 100644 index 00000000..ca95272b --- /dev/null +++ b/Common/Gfx/TextFormatD2D_Test.cpp @@ -0,0 +1,75 @@ +/* + Copyright (C) 2013 Birunthan Mohanathas + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#include "Canvas.h" +#include "TextFormatD2D.h" +#include +#include + +using namespace Microsoft::VisualStudio::CppUnitTestFramework; + +namespace Gfx { + +TEST_CLASS(Common_Gfx_TextFormatD2D_Test) +{ +public: + std::unique_ptr m_D2D; + + Common_Gfx_TextFormatD2D_Test() : + m_D2D(Canvas::Create(Gfx::Renderer::D2D)) + { + // TODO: Handle this in CanvasD2D. + ULONG_PTR gdiplusToken; + Gdiplus::GdiplusStartupInput gdiplusStartupInput; + Gdiplus::GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, nullptr); + + m_D2D->Resize(10, 10); + m_D2D->SetAntiAliasing(true); + } + + TEST_METHOD(TestInaccurateText) + { + std::unique_ptr textFormat((TextFormatD2D*)m_D2D->CreateTextFormat()); + textFormat->SetProperties(L"Arial", 10, false, false, nullptr); + + DWRITE_TEXT_METRICS metrics = textFormat->GetMetrics(L"test", 4, true); + Assert::AreEqual(26, (int)metrics.width); + Assert::AreEqual(16, (int)metrics.height); + + metrics = textFormat->GetMetrics(L"test", 4, false); + Assert::AreEqual(21, (int)metrics.width); + Assert::AreEqual(14, (int)metrics.height); + } + + TEST_METHOD(TestTrailingNewlineGdipCompatibility) + { + std::unique_ptr textFormat((TextFormatD2D*)m_D2D->CreateTextFormat()); + textFormat->SetProperties(L"Arial", 10, false, false, nullptr); + + DWRITE_TEXT_METRICS metrics = textFormat->GetMetrics(L"test\n", 5, false); + Assert::AreEqual(15, (int)metrics.height); + + metrics = textFormat->GetMetrics(L"test\n ", 6, false); + Assert::AreEqual(30, (int)metrics.height); + + metrics = textFormat->GetMetrics(L"test\n\n", 6, false); + Assert::AreEqual(30, (int)metrics.height); + } +}; + +} // namespace Gfx diff --git a/Library/Library.vcxproj b/Library/Library.vcxproj index 68643ca3..306cc2d9 100644 --- a/Library/Library.vcxproj +++ b/Library/Library.vcxproj @@ -74,6 +74,9 @@ + + $(ExcludeTests) + diff --git a/Library/Library.vcxproj.filters b/Library/Library.vcxproj.filters index 200a69ab..f28be904 100644 --- a/Library/Library.vcxproj.filters +++ b/Library/Library.vcxproj.filters @@ -354,6 +354,9 @@ Common\Gfx + + Common\Gfx + Common\Gfx