From d74dae6d6cd561caa4ebf0dc7b9a45bccc75220f Mon Sep 17 00:00:00 2001 From: "Jun Ma (WINDOWS)" Date: Tue, 2 Oct 2018 17:48:00 +0900 Subject: [PATCH 01/29] initial commit --- .../DirectWriteRenderArgBuilder.cpp | 296 ++++++++++++++++++ .../DirectWriteRenderArgBuilder.h | 124 ++++++++ .../DirectWriteResourceManager.cpp | 123 ++++++++ .../DirectWriteResourceManager.h | 54 ++++ .../DirectWriteTextBlock.cpp | 266 ++++++++++++++++ .../DirectWriteTextBlock.h | 106 +++++++ .../DirectWriteTextBlock.idl | 20 ++ ...soft.Toolkit.Uwp.UI.Controls.WinRT.vcxproj | 130 ++++++++ ...lkit.Uwp.UI.Controls.WinRT.vcxproj.filters | 59 ++++ ...icrosoft_Toolkit_Uwp_UI_Controls_WinRT.def | 3 + .../FontCollectionLoader.cpp | 103 ++++++ .../FontCollectionLoader.h | 56 ++++ .../FontFileEnumerator.cpp | 68 ++++ .../FontFileEnumerator.h | 38 +++ .../UniversalPackageFontData.h | 10 + .../pch.cpp | 1 + Microsoft.Toolkit.Uwp.UI.Controls.WinRT/pch.h | 21 ++ docs/controls/DirectWriteTextBlock.md | 53 ++++ 18 files changed, 1531 insertions(+) create mode 100644 Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteRenderArgBuilder.cpp create mode 100644 Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteRenderArgBuilder.h create mode 100644 Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteResourceManager.cpp create mode 100644 Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteResourceManager.h create mode 100644 Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock.cpp create mode 100644 Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock.h create mode 100644 Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock.idl create mode 100644 Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Microsoft.Toolkit.Uwp.UI.Controls.WinRT.vcxproj create mode 100644 Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Microsoft.Toolkit.Uwp.UI.Controls.WinRT.vcxproj.filters create mode 100644 Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Microsoft_Toolkit_Uwp_UI_Controls_WinRT.def create mode 100644 Microsoft.Toolkit.Uwp.UI.Controls.WinRT/UniversalWindowsAppPackageFontLoader/FontCollectionLoader.cpp create mode 100644 Microsoft.Toolkit.Uwp.UI.Controls.WinRT/UniversalWindowsAppPackageFontLoader/FontCollectionLoader.h create mode 100644 Microsoft.Toolkit.Uwp.UI.Controls.WinRT/UniversalWindowsAppPackageFontLoader/FontFileEnumerator.cpp create mode 100644 Microsoft.Toolkit.Uwp.UI.Controls.WinRT/UniversalWindowsAppPackageFontLoader/FontFileEnumerator.h create mode 100644 Microsoft.Toolkit.Uwp.UI.Controls.WinRT/UniversalWindowsAppPackageFontLoader/UniversalPackageFontData.h create mode 100644 Microsoft.Toolkit.Uwp.UI.Controls.WinRT/pch.cpp create mode 100644 Microsoft.Toolkit.Uwp.UI.Controls.WinRT/pch.h create mode 100644 docs/controls/DirectWriteTextBlock.md diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteRenderArgBuilder.cpp b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteRenderArgBuilder.cpp new file mode 100644 index 00000000000..fd0fc7270cf --- /dev/null +++ b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteRenderArgBuilder.cpp @@ -0,0 +1,296 @@ +#include "pch.h" +#include "DirectWriteRenderArgBuilder.h" +#include "DirectWriteResourceManager.h" +#include "UniversalWindowsAppPackageFontLoader\FontCollectionLoader.h" + +namespace winrt::Microsoft_Toolkit_Uwp_UI_Controls_WinRT::implementation +{ + using namespace Windows::UI; + using namespace Windows::UI::Text; + using namespace Windows::UI::Xaml; + using namespace Windows::UI::Xaml::Controls; + using namespace Windows::UI::Xaml::Media; + using namespace Windows::Globalization; + using namespace Windows::Graphics::Display; + using namespace Windows::Foundation; + + DirectWriteRenderArgBuilder::DirectWriteRenderArgBuilder() + { + // default values + m_builtArgs.availableHeight = 0; + m_builtArgs.availableWidth = 0; + m_builtArgs.flowDirection = DWRITE_FLOW_DIRECTION::DWRITE_FLOW_DIRECTION_LEFT_TO_RIGHT; + m_builtArgs.fontFamily = winrt::to_hstring(L"Segoe UI"); + m_builtArgs.fontSize = 15; + m_builtArgs.fontStretch = DWRITE_FONT_STRETCH::DWRITE_FONT_STRETCH_NORMAL; + m_builtArgs.fontStyle = DWRITE_FONT_STYLE::DWRITE_FONT_STYLE_NORMAL; + m_builtArgs.fontWeight = DWRITE_FONT_WEIGHT::DWRITE_FONT_WEIGHT_NORMAL; + m_builtArgs.foregroundColor = Windows::UI::Colors::Black(); + m_builtArgs.rawPixelsPerViewPixel = 1; + m_builtArgs.readingDirection = DWRITE_READING_DIRECTION::DWRITE_READING_DIRECTION_LEFT_TO_RIGHT; + m_builtArgs.textLocale = winrt::to_hstring(L"en-US"); + m_builtArgs.textWrapping = DWRITE_WORD_WRAPPING::DWRITE_WORD_WRAPPING_NO_WRAP; + m_builtArgs.fontCollection = nullptr; + } + + void DirectWriteRenderArgBuilder::SetFontFamily(FontFamily const& fontFamily) + { + winrt::hstring resultFontFamily{}; + + // try to get the FontFamily property first. + auto controlFontFamily = fontFamily; + if ((controlFontFamily != nullptr) && !controlFontFamily.Source().empty()) + { + // if there's something in the font family, use it. + resultFontFamily = controlFontFamily.Source(); + } + + // if nothing was in the font family, try the XAML default value. + if (resultFontFamily.empty() && (controlFontFamily != nullptr)) + { + auto xamlDefault = controlFontFamily.XamlAutoFontFamily(); + if ((xamlDefault != nullptr) && !xamlDefault.Source().empty()) + { + resultFontFamily = xamlDefault.Source(); + } + } + + // if the xaml default failed for some reason, hardcode to Segoe UI as last fallback. + if (resultFontFamily.empty()) + { + resultFontFamily = winrt::to_hstring(L"Segoe UI"); + } + + m_builtArgs.fontFamily = resultFontFamily; + BuildFontCollection(resultFontFamily); + } + + void DirectWriteRenderArgBuilder::SetText(winrt::hstring const& text) + { + m_builtArgs.text = text; + } + + void DirectWriteRenderArgBuilder::SetTextLocale(winrt::hstring const& textLocale) + { + if (Language::IsWellFormed(textLocale)) + { + m_builtArgs.textLocale = textLocale; + } + else + { + // default to en-US. + m_builtArgs.textLocale = winrt::to_hstring(L"en-US"); + } + } + + void DirectWriteRenderArgBuilder::SetForegroundBrush(Brush const& brush) + { + auto solidColorBrush{ brush.try_as() }; + if (solidColorBrush != nullptr) + { + m_builtArgs.foregroundColor = solidColorBrush.Color(); + } + else + { + m_builtArgs.foregroundColor = Colors::Black(); + } + } + + void DirectWriteRenderArgBuilder::SetFontStyle(FontStyle fontStyle) + { + switch (fontStyle) + { + case FontStyle::Normal: __fallthrough; + default: + m_builtArgs.fontStyle = DWRITE_FONT_STYLE::DWRITE_FONT_STYLE_NORMAL; + break; + case FontStyle::Italic: + m_builtArgs.fontStyle = DWRITE_FONT_STYLE::DWRITE_FONT_STYLE_ITALIC; + break; + case FontStyle::Oblique: + m_builtArgs.fontStyle = DWRITE_FONT_STYLE::DWRITE_FONT_STYLE_OBLIQUE; + break; + } + } + + void DirectWriteRenderArgBuilder::SetFontStretch(FontStretch fontStretch) + { + switch (fontStretch) + { + case FontStretch::Normal: __fallthrough; + default: + m_builtArgs.fontStretch = DWRITE_FONT_STRETCH::DWRITE_FONT_STRETCH_NORMAL; + break; + case FontStretch::Condensed: + m_builtArgs.fontStretch = DWRITE_FONT_STRETCH::DWRITE_FONT_STRETCH_CONDENSED; + break; + case FontStretch::Expanded: + m_builtArgs.fontStretch = DWRITE_FONT_STRETCH::DWRITE_FONT_STRETCH_EXPANDED; + break; + case FontStretch::ExtraCondensed: + m_builtArgs.fontStretch = DWRITE_FONT_STRETCH::DWRITE_FONT_STRETCH_EXTRA_CONDENSED; + break; + case FontStretch::ExtraExpanded: + m_builtArgs.fontStretch = DWRITE_FONT_STRETCH::DWRITE_FONT_STRETCH_EXTRA_EXPANDED; + break; + case FontStretch::SemiCondensed: + m_builtArgs.fontStretch = DWRITE_FONT_STRETCH::DWRITE_FONT_STRETCH_SEMI_CONDENSED; + break; + case FontStretch::SemiExpanded: + m_builtArgs.fontStretch = DWRITE_FONT_STRETCH::DWRITE_FONT_STRETCH_SEMI_EXPANDED; + break; + case FontStretch::UltraCondensed: + m_builtArgs.fontStretch = DWRITE_FONT_STRETCH::DWRITE_FONT_STRETCH_ULTRA_CONDENSED; + break; + case FontStretch::UltraExpanded: + m_builtArgs.fontStretch = DWRITE_FONT_STRETCH::DWRITE_FONT_STRETCH_ULTRA_EXPANDED; + break; + } + } + + void DirectWriteRenderArgBuilder::SetTextOrientation(Orientation textOrientation) + { + switch (textOrientation) + { + case Orientation::Vertical: __fallthrough; + default: + m_builtArgs.readingDirection = DWRITE_READING_DIRECTION::DWRITE_READING_DIRECTION_TOP_TO_BOTTOM; + break; + case Orientation::Horizontal: + m_builtArgs.readingDirection = DWRITE_READING_DIRECTION::DWRITE_READING_DIRECTION_LEFT_TO_RIGHT; + break; + } + } + + void DirectWriteRenderArgBuilder::SetFlowDirection(FlowDirection flowDirection) + { + switch (flowDirection) + { + case FlowDirection::LeftToRight: __fallthrough; + default: + m_builtArgs.flowDirection = DWRITE_FLOW_DIRECTION::DWRITE_FLOW_DIRECTION_LEFT_TO_RIGHT; + break; + case FlowDirection::RightToLeft: + m_builtArgs.flowDirection = DWRITE_FLOW_DIRECTION::DWRITE_FLOW_DIRECTION_RIGHT_TO_LEFT; + break; + } + } + + void DirectWriteRenderArgBuilder::SetFontWeight(FontWeight fontWeight) + { + auto weight = fontWeight.Weight; + if (weight == FontWeights::Black().Weight) + { + m_builtArgs.fontWeight = DWRITE_FONT_WEIGHT::DWRITE_FONT_WEIGHT_BLACK; + } + else if (weight == FontWeights::Bold().Weight) + { + m_builtArgs.fontWeight = DWRITE_FONT_WEIGHT::DWRITE_FONT_WEIGHT_BOLD; + } + else if (weight == FontWeights::ExtraBlack().Weight) + { + m_builtArgs.fontWeight = DWRITE_FONT_WEIGHT::DWRITE_FONT_WEIGHT_EXTRA_BLACK; + } + else if (weight == FontWeights::ExtraBold().Weight) + { + m_builtArgs.fontWeight = DWRITE_FONT_WEIGHT::DWRITE_FONT_WEIGHT_EXTRA_BOLD; + } + else if (weight == FontWeights::ExtraLight().Weight) + { + m_builtArgs.fontWeight = DWRITE_FONT_WEIGHT::DWRITE_FONT_WEIGHT_EXTRA_LIGHT; + } + else if (weight == FontWeights::Light().Weight) + { + m_builtArgs.fontWeight = DWRITE_FONT_WEIGHT::DWRITE_FONT_WEIGHT_LIGHT; + } + else if (weight == FontWeights::SemiBold().Weight) + { + m_builtArgs.fontWeight = DWRITE_FONT_WEIGHT::DWRITE_FONT_WEIGHT_SEMI_BOLD; + } + else if (weight == FontWeights::SemiLight().Weight) + { + m_builtArgs.fontWeight = DWRITE_FONT_WEIGHT::DWRITE_FONT_WEIGHT_SEMI_LIGHT; + } + else + { + m_builtArgs.fontWeight = DWRITE_FONT_WEIGHT::DWRITE_FONT_WEIGHT_NORMAL; + } + } + + void DirectWriteRenderArgBuilder::SetTextWrapping(TextWrapping textWrapping) + { + switch (textWrapping) + { + case TextWrapping::NoWrap: + default: + m_builtArgs.textWrapping = DWRITE_WORD_WRAPPING::DWRITE_WORD_WRAPPING_NO_WRAP; + break; + case TextWrapping::Wrap: + m_builtArgs.textWrapping = DWRITE_WORD_WRAPPING::DWRITE_WORD_WRAPPING_WRAP; + break; + case TextWrapping::WrapWholeWords: + m_builtArgs.textWrapping = DWRITE_WORD_WRAPPING::DWRITE_WORD_WRAPPING_WHOLE_WORD; + break; + } + } + + void DirectWriteRenderArgBuilder::SetFontSize(double fontSize) + { + m_builtArgs.fontSize = static_cast(fontSize); + if (m_builtArgs.fontSize <= 0) + { + m_builtArgs.fontSize = 15.0f; + } + } + + void DirectWriteRenderArgBuilder::SetDPI(double rawPixelsPerViewPixel) + { + m_builtArgs.rawPixelsPerViewPixel = static_cast(rawPixelsPerViewPixel); + if (m_builtArgs.rawPixelsPerViewPixel <= 0) + { + m_builtArgs.rawPixelsPerViewPixel = 1.0f; + } + } + + void DirectWriteRenderArgBuilder::SetAvailableWidth(float availableWidth) + { + m_builtArgs.availableWidth = availableWidth; + } + + void DirectWriteRenderArgBuilder::SetAvailableHeight(float availableHeight) + { + m_builtArgs.availableHeight = availableHeight; + } + + DirectWriteTextRenderArgs& DirectWriteRenderArgBuilder::BuildRenderArgs() + { + return m_builtArgs; + } + + void DirectWriteRenderArgBuilder::BuildFontCollection(const winrt::hstring& fontFamily) + { + // default arg is system font collection, what we're looking for is if we're trying to + // find a local custom ttf file. + if (UniversalWindowsAppPackageFontLoader::FontCollectionLoader::HasCustomFontFamily(fontFamily)) + { + auto resourceManager = DirectWriteResourceManager::GetInstance(); + auto dwriteFactory = resourceManager->GetDirectWriteFactoryNoRef(); + UniversalWindowsAppPackageFontLoader::UniversalPackageFontData parseData = {}; + UniversalWindowsAppPackageFontLoader::FontCollectionLoader::ParseXamlFontFamily(fontFamily, parseData); + auto customLoader = UniversalWindowsAppPackageFontLoader::FontCollectionLoader::GetInstance(); + + // the key is a void* meaning the size is actual size. + auto fontFamilyString = fontFamily.c_str(); + auto fontFamilySize = fontFamily.size() * sizeof(wchar_t); + dwriteFactory->CreateCustomFontCollection(customLoader.get(), fontFamilyString, fontFamilySize, m_builtArgs.fontCollection.put()); + + // set font family to the parsed font family. + m_builtArgs.fontFamily = parseData.customFontName; + } + else + { + // else assume it's a system font for now. We could do a lookup, but that would actually slow things down. + m_builtArgs.fontCollection = nullptr; + } + } +} \ No newline at end of file diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteRenderArgBuilder.h b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteRenderArgBuilder.h new file mode 100644 index 00000000000..30a7ce594c7 --- /dev/null +++ b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteRenderArgBuilder.h @@ -0,0 +1,124 @@ +#pragma once +#include +#include +#include +#include +#include + +namespace winrt::Microsoft_Toolkit_Uwp_UI_Controls_WinRT::implementation +{ + /// + /// These are arguments which are used to render the DWrite string. + /// + struct DirectWriteTextRenderArgs + { + winrt::hstring fontFamily; + winrt::hstring text; + winrt::hstring textLocale; + Windows::UI::Color foregroundColor; + DWRITE_FONT_STYLE fontStyle; + DWRITE_FONT_STRETCH fontStretch; + DWRITE_READING_DIRECTION readingDirection; + DWRITE_FLOW_DIRECTION flowDirection; + DWRITE_FONT_WEIGHT fontWeight; + DWRITE_WORD_WRAPPING textWrapping; + float fontSize; + float rawPixelsPerViewPixel; + float availableWidth; + float availableHeight; + winrt::com_ptr fontCollection; + }; + + /// + /// This class translates input from the XAML world into a DirectWriteTextRenderArgs struct + /// meant to be used with the DWrite world. If the user passes invalid values in, it attempts + /// to correct by setting them back to a known default value. This is because in case the user + /// is using the text block from C# (most users are expected to do this), a crash ultimately + /// just gives them a "something went wrong and a native exception was thrown" which is not + /// super helpful. Recovery will at least render something that looks incorrect on the screen. + /// + class DirectWriteRenderArgBuilder + { + public: + DirectWriteRenderArgBuilder(); + + /// + /// The font family, by default Segoe UI + /// + void SetFontFamily(Windows::UI::Xaml::Media::FontFamily const& fontFamily); + + /// + /// The text to render, empty string by default. + /// + void SetText(winrt::hstring const& text); + + /// + /// The text locale for DWrite, en-US by default. + /// + void SetTextLocale(winrt::hstring const& textLocale); + + /// + /// The foreground brush, Black by default + /// + void SetForegroundBrush(Windows::UI::Xaml::Media::Brush const& brush); + + /// + /// The font style, Normal by default + /// + void SetFontStyle(Windows::UI::Text::FontStyle fontStyle); + + /// + /// The font stretch, normal by default + /// + void SetFontStretch(Windows::UI::Text::FontStretch fontStretch); + + /// + /// The text orientation, vertical by default since if you're going to use horizontal, you should use a XAML TextBlock + /// + void SetTextOrientation(Windows::UI::Xaml::Controls::Orientation textOrientation); + + /// + /// The flow direction, LeftToRight by default + /// + void SetFlowDirection(Windows::UI::Xaml::FlowDirection flowDirection); + + /// + /// The font weight, Normal by default + /// + void SetFontWeight(Windows::UI::Text::FontWeight fontWeight); + + /// + /// The font size, 15 by default. + /// + void SetFontSize(double fontSize); + + /// + /// The DPI to render at, 1 by default + /// + void SetDPI(double rawPixelsPerViewPixel); + + /// + /// The available width to render at + /// + void SetAvailableWidth(float availableWidth); + + /// + /// The available height to render at. + /// + void SetAvailableHeight(float availableHeight); + + /// + /// The text wrap mode, None by default. + /// + void SetTextWrapping(Windows::UI::Xaml::TextWrapping textWrapping); + + /// + /// The render arguments. + /// + DirectWriteTextRenderArgs& BuildRenderArgs(); + + private: + void BuildFontCollection(const winrt::hstring& fontFamily); + DirectWriteTextRenderArgs m_builtArgs = {}; + }; +} \ No newline at end of file diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteResourceManager.cpp b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteResourceManager.cpp new file mode 100644 index 00000000000..8f5aeb1782a --- /dev/null +++ b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteResourceManager.cpp @@ -0,0 +1,123 @@ +#include "pch.h" +#include "UniversalWindowsAppPackageFontLoader\FontCollectionLoader.h" +#include "DirectWriteResourceManager.h" + +namespace winrt::Microsoft_Toolkit_Uwp_UI_Controls_WinRT::implementation +{ + std::unique_ptr DirectWriteResourceManager::s_instance; + + DirectWriteResourceManager::DirectWriteResourceManager() + { + } + + DirectWriteResourceManager::~DirectWriteResourceManager() + { + } + + IDWriteFactory* DirectWriteResourceManager::GetDirectWriteFactoryNoRef() + { + winrt::check_hresult(InitializeDeviceResources()); + return m_dwriteFactory.get(); + } + + ID3D11Device* DirectWriteResourceManager::GetD3dDeviceNoRef() + { + winrt::check_hresult(InitializeDeviceResources()); + return m_d3dDevice.get(); + } + + ID2D1DeviceContext* DirectWriteResourceManager::GetD2dDCNoRef() + { + winrt::check_hresult(InitializeDeviceResources()); + return m_d2dContext.get(); + } + + IDXGIDevice* DirectWriteResourceManager::GetDXGIDeviceNoRef() + { + winrt::check_hresult(InitializeDeviceResources()); + return m_dxgiDevice.get(); + } + + HRESULT DirectWriteResourceManager::InitializeDeviceResources() + { + if (!m_deviceResourcesInitialized) + { + UINT creationFlags = D3D11_CREATE_DEVICE_BGRA_SUPPORT; + D3D_FEATURE_LEVEL supportedFeatureLevel; + + D3D_FEATURE_LEVEL featureLevels[] = + { + D3D_FEATURE_LEVEL_11_1, + D3D_FEATURE_LEVEL_11_0, + D3D_FEATURE_LEVEL_10_1, + D3D_FEATURE_LEVEL_10_0, + D3D_FEATURE_LEVEL_9_3, + D3D_FEATURE_LEVEL_9_2, + D3D_FEATURE_LEVEL_9_1 + }; + + HRESULT hr = D3D11CreateDevice( + nullptr, // Specify nullptr to use the default adapter. + D3D_DRIVER_TYPE_HARDWARE, // Create a device using the hardware graphics driver. + 0, // Should be 0 unless the driver is D3D_DRIVER_TYPE_SOFTWARE. + creationFlags, // Set debug and Direct2D compatibility flags. + featureLevels, // List of feature levels this app can support. + ARRAYSIZE(featureLevels), + D3D11_SDK_VERSION, // Always set this to D3D11_SDK_VERSION for Windows Store apps. + m_d3dDevice.put(), // Returns the Direct3D device created. + &supportedFeatureLevel, + nullptr + ); + + // log failures on the initial creation + if (FAILED(hr)) + { + // If the initialization fails, fall back to the WARP device. + winrt::check_hresult(D3D11CreateDevice( + nullptr, + D3D_DRIVER_TYPE_WARP, // Create a WARP device instead of a hardware device. + 0, + creationFlags, + featureLevels, + ARRAYSIZE(featureLevels), + D3D11_SDK_VERSION, + m_d3dDevice.put(), + &supportedFeatureLevel, + nullptr + )); + } + + // Get the Direct3D 11.1 API device. + m_d3dDevice.as(m_dxgiDevice); + winrt::check_hresult(D2D1CreateDevice(m_dxgiDevice.get(), nullptr, m_d2dDevice.put())); + + winrt::check_hresult(m_d2dDevice->CreateDeviceContext( + D2D1_DEVICE_CONTEXT_OPTIONS_NONE, + m_d2dContext.put() + )); + + winrt::check_hresult(DWriteCreateFactory( + DWRITE_FACTORY_TYPE_SHARED, + __uuidof(IDWriteFactory), + reinterpret_cast(m_dwriteFactory.put()) + )); + + auto customLoader = UniversalWindowsAppPackageFontLoader::FontCollectionLoader::GetInstance(); + m_dwriteFactory->RegisterFontCollectionLoader(customLoader.get()); + + m_deviceResourcesInitialized = true; + } + + return S_OK; + } + + DirectWriteResourceManager* DirectWriteResourceManager::GetInstance() + { + if (s_instance == nullptr) + { + s_instance.reset(new DirectWriteResourceManager()); + } + + return s_instance.get(); + } +} \ No newline at end of file diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteResourceManager.h b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteResourceManager.h new file mode 100644 index 00000000000..1febb8c7329 --- /dev/null +++ b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteResourceManager.h @@ -0,0 +1,54 @@ +#pragma once + +namespace winrt::Microsoft_Toolkit_Uwp_UI_Controls_WinRT::implementation +{ + /// + /// This manages D3D/DWrite resources and prevents reinitialization. + /// + class DirectWriteResourceManager + { + public: + DirectWriteResourceManager(); + virtual ~DirectWriteResourceManager(); + + /// + /// This is a singleton to prevent reintializing D3D + /// + static DirectWriteResourceManager* GetInstance(); + + /// + /// The DWrite Factory, caller doesn't take a reference. + /// + IDWriteFactory* GetDirectWriteFactoryNoRef(); + + /// + /// The D3D Device, caller doesn't take a reference. + /// + ID3D11Device* GetD3dDeviceNoRef(); + + /// + /// The D2D Device, caller doesn't take a reference. + /// + ID2D1DeviceContext* GetD2dDCNoRef(); + + /// + /// The DXGI Device, caller doesn't take a reference. + /// + IDXGIDevice* GetDXGIDeviceNoRef(); + + /// + /// Initializes the device resources. + /// + HRESULT InitializeDeviceResources(); + + private: + winrt::com_ptr m_dwriteFactory; + winrt::com_ptr m_d3dDevice; + winrt::com_ptr m_d2dDevice; + winrt::com_ptr m_d2dContext; + winrt::com_ptr m_dxgiDevice; + + static std::unique_ptr s_instance; + bool m_deviceResourcesInitialized = false; + }; +} \ No newline at end of file diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock.cpp b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock.cpp new file mode 100644 index 00000000000..e7eb599f5fb --- /dev/null +++ b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock.cpp @@ -0,0 +1,266 @@ +// Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license. +// See LICENSE in the project root for license information. + +#include "pch.h" +#include +#include +#include +#include "DirectWriteTextBlock.h" + +namespace winrt::Microsoft_Toolkit_Uwp_UI_Controls_WinRT::implementation +{ + using namespace Windows::UI::Xaml; + using namespace Windows::UI::Xaml::Controls; + using namespace Windows::UI::Xaml::Media; + using namespace Windows::UI::Xaml::Media::Imaging; + using namespace Windows::Graphics::Display; + using namespace Windows::Foundation; + + // note: if you pass nullptr to winrt::to_hstring you will get a crash. + DependencyProperty DirectWriteTextBlock::m_textProperty = DependencyProperty::Register( + winrt::param::hstring(L"Text"), + winrt::xaml_typename(), + winrt::xaml_typename(), + PropertyMetadata{ winrt::box_value(winrt::to_hstring(L"")), PropertyChangedCallback{ &DirectWriteTextBlock::OnDependencyPropertyChanged } }); + + DependencyProperty DirectWriteTextBlock::m_textLocaleProperty = DependencyProperty::Register( + winrt::param::hstring(L"TextLocale"), + winrt::xaml_typename(), + winrt::xaml_typename(), + PropertyMetadata{ winrt::box_value(L"en-US"), PropertyChangedCallback{ &DirectWriteTextBlock::OnDependencyPropertyChanged } }); + + DependencyProperty DirectWriteTextBlock::m_textOrientationProperty = DependencyProperty::Register( + winrt::param::hstring(L"TextOrientation"), + winrt::xaml_typename(), + winrt::xaml_typename(), + PropertyMetadata{ winrt::box_value(Windows::UI::Xaml::Controls::Orientation::Vertical), PropertyChangedCallback{ &DirectWriteTextBlock::OnDependencyPropertyChanged } }); + + DependencyProperty DirectWriteTextBlock::m_textWrapProperty = DependencyProperty::Register( + winrt::param::hstring(L"TextWrap"), + winrt::xaml_typename(), + winrt::xaml_typename(), + PropertyMetadata{ winrt::box_value(Windows::UI::Xaml::TextWrapping::NoWrap), PropertyChangedCallback{ &DirectWriteTextBlock::OnDependencyPropertyChanged } }); + + DirectWriteTextBlock::DirectWriteTextBlock() + { + // note: while this is what we should do, there's current a crash if you add a .xaml file to a C++/WinRT project. Once that bug is fixed, we should + // keep a default style with this dll so consumers can know what to do. + DefaultStyleKey(winrt::box_value(L"Microsoft.Toolkit.Uwp.UI.Controls.WinRT.DirectWriteTextBlock")); + + auto displayInfo = DisplayInformation::GetForCurrentView(); + m_dpiChangedToken = displayInfo.DpiChanged({ this, &DirectWriteTextBlock::OnDpiChanged }); + +#define REGISTER_INHERITED_PROPERTY_CALLBACK(token, inheritedProperty) \ + token = RegisterPropertyChangedCallback(inheritedProperty, DependencyPropertyChangedCallback{ &DirectWriteTextBlock::OnInheritedDependencyPropertyChanged }) + + REGISTER_INHERITED_PROPERTY_CALLBACK(m_flowDirectionChangedToken, FrameworkElement::FlowDirectionProperty()); + REGISTER_INHERITED_PROPERTY_CALLBACK(m_foregroundChangedToken, Control::ForegroundProperty()); + REGISTER_INHERITED_PROPERTY_CALLBACK(m_fontSizeChangedToken, Control::FontSizeProperty()); + REGISTER_INHERITED_PROPERTY_CALLBACK(m_fontFamilyChangedToken, Control::FontFamilyProperty()); + REGISTER_INHERITED_PROPERTY_CALLBACK(m_fontStretchChangedToken, Control::FontStretchProperty()); + REGISTER_INHERITED_PROPERTY_CALLBACK(m_fontStyleChangedToken, Control::FontStyleProperty()); + REGISTER_INHERITED_PROPERTY_CALLBACK(m_fontWeightChangedToken, Control::FontWeightProperty()); +#undef REGISTER_INHERITED_PROPERTY_CALLBACK + } + + DirectWriteTextBlock::~DirectWriteTextBlock() + { + Close(); + } + + void DirectWriteTextBlock::OnApplyTemplate() + { + // make XAML apply the template first + __super::OnApplyTemplate(); + + auto maybeImage = GetTemplateChild(L"Image").try_as(); + if (maybeImage == nullptr) + { + winrt::throw_hresult(E_NOT_VALID_STATE); + } + + m_image = maybeImage; + } + + Size DirectWriteTextBlock::MeasureOverride(Size const& availableSize) + { + auto displayInfo = DisplayInformation::GetForCurrentView(); + DirectWriteRenderArgBuilder builder; + builder.SetAvailableHeight(availableSize.Height); + builder.SetAvailableWidth(availableSize.Width); + builder.SetDPI(displayInfo.RawPixelsPerViewPixel()); + builder.SetFlowDirection(FlowDirection()); + builder.SetFontFamily(FontFamily()); + builder.SetFontSize(FontSize()); + builder.SetFontStretch(FontStretch()); + builder.SetFontStyle(FontStyle()); + builder.SetFontWeight(FontWeight()); + builder.SetForegroundBrush(Foreground()); + builder.SetText(Text()); + builder.SetTextLocale(TextLocale()); + builder.SetTextOrientation(TextOrientation()); + builder.SetTextWrapping(TextWrap()); + + auto args = builder.BuildRenderArgs(); + return RenderText(args); + } + + void DirectWriteTextBlock::Close() + { + +#define UNREGISTER_INHERITED_PROPERTY_CALLBACK(token, inheritedProperty) \ + if (token != 0) \ + { \ + UnregisterPropertyChangedCallback(inheritedProperty, token); \ + token = 0; \ + } + + UNREGISTER_INHERITED_PROPERTY_CALLBACK(m_flowDirectionChangedToken, FrameworkElement::FlowDirectionProperty()); + UNREGISTER_INHERITED_PROPERTY_CALLBACK(m_foregroundChangedToken, Control::ForegroundProperty()); + UNREGISTER_INHERITED_PROPERTY_CALLBACK(m_fontSizeChangedToken, Control::FontSizeProperty()); + UNREGISTER_INHERITED_PROPERTY_CALLBACK(m_fontFamilyChangedToken, Control::FontFamilyProperty()); + UNREGISTER_INHERITED_PROPERTY_CALLBACK(m_fontStretchChangedToken, Control::FontStretchProperty()); + UNREGISTER_INHERITED_PROPERTY_CALLBACK(m_fontStyleChangedToken, Control::FontStyleProperty()); + UNREGISTER_INHERITED_PROPERTY_CALLBACK(m_fontWeightChangedToken, Control::FontWeightProperty()); + + if (m_dpiChangedToken.value != 0) + { + auto displayInfo = DisplayInformation::GetForCurrentView(); + displayInfo.DpiChanged(m_dpiChangedToken); + m_dpiChangedToken = {}; + } + +#undef UNREGISTER_INHERITED_PROPERTY_CALLBACK + } + + Size DirectWriteTextBlock::RenderText(DirectWriteTextRenderArgs const& args) + { + if (args.text.empty()) + { + return Size{ 0, 0 }; + } + + auto resourceManager = DirectWriteResourceManager::GetInstance(); + auto scale = args.rawPixelsPerViewPixel; + auto scaledFontSize = args.fontSize * scale; + auto dwriteFactory = resourceManager->GetDirectWriteFactoryNoRef(); + + winrt::com_ptr textFormat; + winrt::check_hresult(dwriteFactory->CreateTextFormat( + args.fontFamily.data(), + args.fontCollection.get(), + args.fontWeight, + args.fontStyle, + args.fontStretch, + scaledFontSize, + args.textLocale.data(), + textFormat.put())); + + textFormat->SetWordWrapping(args.textWrapping); + + // Trying to set readingDirection + FlowDirection to LEFT_TO_RIGHT will result in + // a failed HRESULT From DWRITE. Since the defaults work fine for horizontal, only + // set these values for text orientation = vertical. + if (this->TextOrientation() == Orientation::Vertical) + { + textFormat->SetReadingDirection(args.readingDirection); + textFormat->SetFlowDirection(args.flowDirection); + } + + winrt::com_ptr textLayout; + winrt::check_hresult(dwriteFactory->CreateTextLayout( + args.text.data(), + args.text.size(), + textFormat.get(), + args.availableWidth, + args.availableHeight, + textLayout.put())); + + DWRITE_TEXT_METRICS textMetrics = {}; + winrt::check_hresult(textLayout->GetMetrics(&textMetrics)); + + auto sisWidth = static_cast(std::ceil(textMetrics.width)); + auto sisHeight = static_cast(std::ceil(textMetrics.height)); + auto imageSource = SurfaceImageSource(sisWidth, sisHeight); + auto sisNative{ imageSource.as() }; + sisNative->SetDevice(resourceManager->GetDXGIDeviceNoRef()); + + winrt::com_ptr surface; + RECT updateRect = { 0, 0, static_cast(sisWidth), static_cast(sisHeight) }; + POINT offset = { 0, 0 }; + if (SUCCEEDED(sisNative->BeginDraw(updateRect, surface.put(), &offset))) + { + auto d2dContext = resourceManager->GetD2dDCNoRef(); + + // set the translation to the section of the bitmap that we want to render. + auto translate = D2D1::Matrix3x2F::Translation(static_cast(offset.x), static_cast(offset.y)); + d2dContext->SetTransform(translate); + + // this basically ensures the text background is transparent. + D2D1_BITMAP_PROPERTIES1 bitmapProperties = + { + { DXGI_FORMAT_UNKNOWN, D2D1_ALPHA_MODE_PREMULTIPLIED }, + 96.f * scale, + 96.f * scale, + D2D1_BITMAP_OPTIONS_TARGET | D2D1_BITMAP_OPTIONS_CANNOT_DRAW + }; + + winrt::com_ptr bitmap; + winrt::check_hresult(d2dContext->CreateBitmapFromDxgiSurface( + surface.get(), + &bitmapProperties, + bitmap.put())); + + d2dContext->SetTarget(bitmap.get()); + d2dContext->BeginDraw(); + d2dContext->Clear(); + + winrt::com_ptr brush; + auto color = args.foregroundColor; + D2D1_COLOR_F d2dColor = D2D1::ColorF( + static_cast(color.R) / 255.0f, + static_cast(color.G) / 255.0f, + static_cast(color.B) / 255.0f, + static_cast(color.A) / 255.0f); + winrt::check_hresult(d2dContext->CreateSolidColorBrush(d2dColor, brush.put())); + + d2dContext->DrawText( + args.text.data(), + args.text.size(), + textFormat.get(), + D2D1::RectF(0, 0, static_cast(sisWidth), static_cast(sisHeight)), + brush.get(), + D2D1_DRAW_TEXT_OPTIONS_ENABLE_COLOR_FONT); + + d2dContext->EndDraw(); + sisNative->EndDraw(); + } + + m_image.Source(imageSource); + // XAML will rescale, so we divide by scale here. + return Size{ static_cast(sisWidth / scale), static_cast(sisHeight / scale) }; + } + + void DirectWriteTextBlock::OnDependencyPropertyChanged(DependencyObject const& d, DependencyPropertyChangedEventArgs const& /* e */) + { + auto textBlockInstance{ d.try_as() }; + if (textBlockInstance) + { + textBlockInstance->InvalidateMeasure(); + } + } + + void DirectWriteTextBlock::OnInheritedDependencyPropertyChanged(DependencyObject const& d, DependencyProperty const& /* e */) + { + auto textBlockInstance{ d.try_as() }; + if (textBlockInstance) + { + textBlockInstance->InvalidateMeasure(); + } + } + + void DirectWriteTextBlock::OnDpiChanged(DisplayInformation const& /* displayInfo */, IInspectable const& /* obj */) + { + InvalidateMeasure(); + } +} diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock.h b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock.h new file mode 100644 index 00000000000..3d1b7b183fe --- /dev/null +++ b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock.h @@ -0,0 +1,106 @@ +// Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license. +// See LICENSE in the project root for license information. + +#pragma once +#include +#include "DirectWriteTextBlock.g.h" +#include "DirectWriteResourceManager.h" +#include "DirectWriteRenderArgBuilder.h" + +namespace winrt::Microsoft_Toolkit_Uwp_UI_Controls_WinRT::implementation +{ +#define DEFINE_XAML_DEPENDENCY_PROPERTY(type, name, membername) \ + public: \ + type name() \ + { \ + return winrt::unbox_value(GetValue(membername)); \ + } \ + void name(type const& value) \ + { \ + SetValue(membername, winrt::box_value(value)); \ + } \ + static Windows::UI::Xaml::DependencyProperty name ## Property() \ + { \ + return membername; \ + } \ + private: \ + static Windows::UI::Xaml::DependencyProperty membername; \ + public: + + /// + /// This is a text block which uses DirectWrite to draw text onto a bitmap image, allowing the user to orient text vertically for + /// East Asian languages and to support text rendering modes which aren't supported by XAML yet, but are supported by DirectWrite. + /// + /// This is built using C++/WinRT and will require the 1803 Windows SDK to build and use at minumum. + /// + /// + /// The current XAML code gen for C++/WinRT is in preview and results in a compile error. Users will need to define their own + /// default style for this thing in their apps that use this. This currently only supports SolidColorBrush based Foregrounds + /// + /// Throwing out of this class will cause significant debuggability issues in C# consumers as they just get a "native exception was thrown." + /// Therefore, this class will attempt to recover from poor input like setting font size = 0. If something happens like a DWrite + /// method fails, that will throw an exception. + /// + struct DirectWriteTextBlock : DirectWriteTextBlockT + { + public: + DirectWriteTextBlock(); + virtual ~DirectWriteTextBlock(); + + // IClosable is here so that we can unsub from the inherited dependency properties. + virtual void Close(); + + // Note: DWrite actually supports a lot more rendering modes than XAML, but we're able to get most of what we want + // with just the XAML built in types. In the event we need more of the DWrite API surface, we would need + // to define our own enums which map to the DWrite enums. + + /// + /// The text to render + /// + DEFINE_XAML_DEPENDENCY_PROPERTY(winrt::hstring, Text, m_textProperty); + + /// + /// The locale of the text to show + /// + DEFINE_XAML_DEPENDENCY_PROPERTY(winrt::hstring, TextLocale, m_textLocaleProperty); + + /// + /// The orientation of the text. + /// + DEFINE_XAML_DEPENDENCY_PROPERTY(Windows::UI::Xaml::Controls::Orientation, TextOrientation, m_textOrientationProperty); + + /// + /// How the text is wrapped. To Wrap text, just set the Height or Width of this control. + /// + DEFINE_XAML_DEPENDENCY_PROPERTY(Windows::UI::Xaml::TextWrapping, TextWrap, m_textWrapProperty); + + public: + // These are the methods we're overriding from IFrameworkElementOverrides. + void OnApplyTemplate(); + Windows::Foundation::Size MeasureOverride(Windows::Foundation::Size const& availableSize); + + private: + static void OnDependencyPropertyChanged(Windows::UI::Xaml::DependencyObject const& d, Windows::UI::Xaml::DependencyPropertyChangedEventArgs const& e); + static void OnInheritedDependencyPropertyChanged(Windows::UI::Xaml::DependencyObject const& d, Windows::UI::Xaml::DependencyProperty const& e); + void OnDpiChanged(Windows::Graphics::Display::DisplayInformation const& displayInfo, Windows::Foundation::IInspectable const& obj); + Windows::Foundation::Size RenderText(DirectWriteTextRenderArgs const& args); + + winrt::event_token m_dpiChangedToken; + long long m_foregroundChangedToken = 0; + long long m_fontSizeChangedToken = 0; + long long m_fontFamilyChangedToken = 0; + long long m_flowDirectionChangedToken = 0; + long long m_fontStretchChangedToken = 0; + long long m_fontWeightChangedToken = 0; + long long m_fontStyleChangedToken = 0; + + Windows::UI::Xaml::Controls::Image m_image; + }; +} + +namespace winrt::Microsoft_Toolkit_Uwp_UI_Controls_WinRT::factory_implementation +{ + struct DirectWriteTextBlock : DirectWriteTextBlockT + { + }; +} diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock.idl b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock.idl new file mode 100644 index 00000000000..5e2a4e01814 --- /dev/null +++ b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock.idl @@ -0,0 +1,20 @@ +namespace Microsoft_Toolkit_Uwp_UI_Controls_WinRT +{ + [default_interface] + runtimeclass DirectWriteTextBlock : Windows.UI.Xaml.Controls.Control, Windows.Foundation.IClosable + { + DirectWriteTextBlock(); + + static Windows.UI.Xaml.DependencyProperty TextProperty{ get; }; + String Text; + + static Windows.UI.Xaml.DependencyProperty TextLocaleProperty{ get; }; + String TextLocale; + + static Windows.UI.Xaml.DependencyProperty TextOrientationProperty{ get; }; + Windows.UI.Xaml.Controls.Orientation TextOrientation; + + static Windows.UI.Xaml.DependencyProperty TextWrapProperty{ get; }; + Windows.UI.Xaml.TextWrapping TextWrap; + } +} diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Microsoft.Toolkit.Uwp.UI.Controls.WinRT.vcxproj b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Microsoft.Toolkit.Uwp.UI.Controls.WinRT.vcxproj new file mode 100644 index 00000000000..df6c2abb1f9 --- /dev/null +++ b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Microsoft.Toolkit.Uwp.UI.Controls.WinRT.vcxproj @@ -0,0 +1,130 @@ + + + + true + $(RequiredBundles);Microsoft.Windows.CppWinRT + true + {6e3ee614-2343-447d-b9f6-2a666b89940f} + Microsoft.Toolkit.Uwp.UI.Controls.WinRT + Microsoft_Toolkit_Uwp_UI_Controls_WinRT + en-US + 14.0 + true + Windows Store + 10.0 + 10.0.17134.0 + 10.0.17134.0 + + + + + Debug + ARM + + + Debug + Win32 + + + Debug + x64 + + + Release + ARM + + + Release + Win32 + + + Release + x64 + + + + DynamicLibrary + v141 + Unicode + false + + + true + true + + + false + true + true + + + + + + + + + + + + + + Use + pch.h + $(IntDir)pch.pch + Level4 + %(AdditionalOptions) /permissive- /bigobj + 28204 + _WINRT_DLL;%(PreprocessorDefinitions) + $(WindowsSDK_WindowsMetadata);$(AdditionalUsingDirectories) + + + Console + true + Microsoft_Toolkit_Uwp_UI_Controls_WinRT.def + + + + + _DEBUG;%(PreprocessorDefinitions) + + + + + NDEBUG;%(PreprocessorDefinitions) + + + + + + + + DirectWriteTextBlock.idl + + + + + + + + + + Create + + + DirectWriteTextBlock.idl + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Microsoft.Toolkit.Uwp.UI.Controls.WinRT.vcxproj.filters b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Microsoft.Toolkit.Uwp.UI.Controls.WinRT.vcxproj.filters new file mode 100644 index 00000000000..e14339c1399 --- /dev/null +++ b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Microsoft.Toolkit.Uwp.UI.Controls.WinRT.vcxproj.filters @@ -0,0 +1,59 @@ + + + + + + + + DirectWriteTextBlock + + + DirectWriteTextBlock + + + UniversalWindowsAppPackageFontLoader + + + UniversalWindowsAppPackageFontLoader + + + + + + + DirectWriteTextBlock + + + DirectWriteTextBlock + + + UniversalWindowsAppPackageFontLoader + + + UniversalWindowsAppPackageFontLoader + + + UniversalWindowsAppPackageFontLoader + + + + + + + + {5c9410b2-e6cd-4e91-80d5-5a476962d413} + + + {05649367-fea9-4b44-9514-f1d8e391d701} + + + + + DirectWriteTextBlock + + + + + + + \ No newline at end of file diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Microsoft_Toolkit_Uwp_UI_Controls_WinRT.def b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Microsoft_Toolkit_Uwp_UI_Controls_WinRT.def new file mode 100644 index 00000000000..24e7c1235c3 --- /dev/null +++ b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Microsoft_Toolkit_Uwp_UI_Controls_WinRT.def @@ -0,0 +1,3 @@ +EXPORTS +DllCanUnloadNow = WINRT_CanUnloadNow PRIVATE +DllGetActivationFactory = WINRT_GetActivationFactory PRIVATE diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/UniversalWindowsAppPackageFontLoader/FontCollectionLoader.cpp b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/UniversalWindowsAppPackageFontLoader/FontCollectionLoader.cpp new file mode 100644 index 00000000000..6f06a626c68 --- /dev/null +++ b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/UniversalWindowsAppPackageFontLoader/FontCollectionLoader.cpp @@ -0,0 +1,103 @@ +#include "pch.h" +#include +#include +#include +#include "FontFileEnumerator.h" +#include "FontCollectionLoader.h" + +namespace winrt::Microsoft_Toolkit_Uwp_UI_Controls_WinRT::implementation::UniversalWindowsAppPackageFontLoader +{ + winrt::com_ptr FontCollectionLoader::s_comInstance; + + FontCollectionLoader::FontCollectionLoader() + { + } + + FontCollectionLoader::~FontCollectionLoader() + { + } + + bool FontCollectionLoader::HasCustomFontFamily(winrt::hstring const& xamlFontFamily) + { + // is there a .ttf in the path? + std::wstring wstringPath{ xamlFontFamily }; + std::transform(wstringPath.begin(), wstringPath.end(), wstringPath.begin(), towlower); + auto foundCustomFontFile = wstringPath.find(L".ttf#", 0); + return foundCustomFontFile != std::wstring::npos; + } + + void FontCollectionLoader::ParseXamlFontFamily(_In_ winrt::hstring const& xamlFontFamily, _Out_ UniversalPackageFontData& parsedFont) + { + parsedFont = {}; + std::wstring wstringPath{ xamlFontFamily }; + auto delimLocation = wstringPath.find(L'#'); + if (delimLocation != std::wstring::npos) + { + auto path = wstringPath.substr(0, delimLocation); + std::replace(path.begin(), path.end(), L'/', L'\\'); + parsedFont.packageFontFilePath = path; + parsedFont.customFontName = wstringPath.substr(delimLocation + 1); + } + } + + bool FontCollectionLoader::FindCachedEnumerator(winrt::hstring const& xamlFontFamily, winrt::com_ptr& enumerator) + { + for (auto& entry : m_fontEnumerators) + { + if (entry.customFont == xamlFontFamily) + { + enumerator = entry.enumerator; + return true; + } + } + + return false; + } + + IFACEMETHODIMP FontCollectionLoader::CreateEnumeratorFromKey(_In_ IDWriteFactory* factory, void const* collectionKey, unsigned int collectionKeySize, _Outptr_ IDWriteFontFileEnumerator** fontFileEnumerator) + try + { + *fontFileEnumerator = nullptr; + auto xamlFontFamily = winrt::hstring(reinterpret_cast(collectionKey), collectionKeySize); + + if (HasCustomFontFamily(xamlFontFamily)) + { + winrt::com_ptr cachedEnumerator; + if (!FindCachedEnumerator(xamlFontFamily, cachedEnumerator)) + { + auto enumerator{ winrt::make_self() }; + UniversalPackageFontData parseData = {}; + ParseXamlFontFamily(xamlFontFamily, parseData); + winrt::check_hresult(enumerator->Initialize(factory, parseData)); + + FontEnumeratorEntry entry = {}; + entry.customFont = xamlFontFamily; + entry.enumerator = enumerator; + m_fontEnumerators.push_back(std::move(entry)); + cachedEnumerator = enumerator; + } + + winrt::check_hresult(cachedEnumerator->QueryInterface(IID_PPV_ARGS(fontFileEnumerator))); + } + else + { + winrt::throw_hresult(E_INVALIDARG); + } + + return S_OK; + } + catch (...) + { + return winrt::to_hresult(); + } + + winrt::com_ptr& FontCollectionLoader::GetInstance() + { + if (!s_comInstance) + { + s_comInstance = winrt::make(); + } + + return s_comInstance; + } +} \ No newline at end of file diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/UniversalWindowsAppPackageFontLoader/FontCollectionLoader.h b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/UniversalWindowsAppPackageFontLoader/FontCollectionLoader.h new file mode 100644 index 00000000000..f916c86f28c --- /dev/null +++ b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/UniversalWindowsAppPackageFontLoader/FontCollectionLoader.h @@ -0,0 +1,56 @@ +#pragma once +#include "UniversalPackageFontData.h" + +namespace winrt::Microsoft_Toolkit_Uwp_UI_Controls_WinRT::implementation::UniversalWindowsAppPackageFontLoader +{ + /// + /// This is just to glue together a custom font file in the Universal Windows app package + /// to a custom DWrite Font. All it does is provide an enumerator that returns 1 font (the custom font) + /// and doesn't support things like font fallbacks. + /// + struct FontCollectionLoader : winrt::implements + { + public: + FontCollectionLoader(); + virtual ~FontCollectionLoader(); + + /// + /// Create the enumerator to the Universal Windows Application package. + /// + IFACEMETHOD(CreateEnumeratorFromKey)( + _In_ IDWriteFactory* factory, + void const* collectionKey, // XAML FontFamily Syntax (something.ttf)#font + unsigned int collectionKeySize, + _Outptr_ IDWriteFontFileEnumerator** fontFileEnumerator + ); + + /// + /// This sees if the incoming XAML FontFamily value has something that looks like + /// a custom font file like foo.ttf#bar + /// + static bool HasCustomFontFamily(winrt::hstring const& xamlFontFamily); + + /// + /// This parses something that looks like /foo/bar.ttf#baz into the ttf path and the font name (baz). + /// + static void ParseXamlFontFamily(winrt::hstring const& xamlFontFamily, _Out_ UniversalPackageFontData& parsedFont); + + /// + /// Get the singleton loader. + /// + static winrt::com_ptr& GetInstance(); + + private: + struct FontEnumeratorEntry + { + winrt::hstring customFont; + winrt::com_ptr enumerator; + }; + + // enumerators are cached due to memory usages. + bool FindCachedEnumerator(winrt::hstring const& xamlFontFamily, winrt::com_ptr& enumerator); + + std::vector m_fontEnumerators; + static winrt::com_ptr s_comInstance; + }; +} \ No newline at end of file diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/UniversalWindowsAppPackageFontLoader/FontFileEnumerator.cpp b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/UniversalWindowsAppPackageFontLoader/FontFileEnumerator.cpp new file mode 100644 index 00000000000..d42747c7009 --- /dev/null +++ b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/UniversalWindowsAppPackageFontLoader/FontFileEnumerator.cpp @@ -0,0 +1,68 @@ +#include "pch.h" +#include +#include +#include "FontFileEnumerator.h" + +namespace winrt::Microsoft_Toolkit_Uwp_UI_Controls_WinRT::implementation::UniversalWindowsAppPackageFontLoader +{ + using namespace Windows::Storage; + + FontFileEnumerator::FontFileEnumerator() + { + } + + FontFileEnumerator::~FontFileEnumerator() + { + } + + HRESULT FontFileEnumerator::Initialize(_In_ IDWriteFactory* factory, const UniversalPackageFontData& packageFont) + try + { + if ((factory == nullptr) || packageFont.packageFontFilePath.empty() || packageFont.customFontName.empty()) + { + winrt::throw_hresult(E_INVALIDARG); + } + + m_factory.attach(factory); + m_packageFontArgs = packageFont; + return S_OK; + } + catch (...) + { + return winrt::to_hresult(); + } + + IFACEMETHODIMP FontFileEnumerator::MoveNext(_Out_ BOOL* hasCurrentFile) + try + { + *hasCurrentFile = FALSE; + if (!m_enumerated) + { + m_currentFontFile = nullptr; + StorageFolder uwappStorage{ Windows::ApplicationModel::Package::Current().InstalledLocation() }; + std::wstring filePath{ uwappStorage.Path() }; + filePath.append(m_packageFontArgs.packageFontFilePath); + winrt::check_hresult(m_factory->CreateFontFileReference(filePath.c_str(), nullptr, m_currentFontFile.put())); + + *hasCurrentFile = TRUE; + m_enumerated = true; + } + + return S_OK; + } + catch (...) + { + return winrt::to_hresult(); + } + + IFACEMETHODIMP FontFileEnumerator::GetCurrentFontFile(_Outptr_ IDWriteFontFile** fontFile) + try + { + m_currentFontFile.copy_to(fontFile); + return S_OK; + } + catch (...) + { + return winrt::to_hresult(); + } +} \ No newline at end of file diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/UniversalWindowsAppPackageFontLoader/FontFileEnumerator.h b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/UniversalWindowsAppPackageFontLoader/FontFileEnumerator.h new file mode 100644 index 00000000000..0cf44058154 --- /dev/null +++ b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/UniversalWindowsAppPackageFontLoader/FontFileEnumerator.h @@ -0,0 +1,38 @@ +#pragma once +#include "UniversalPackageFontData.h" + +namespace winrt::Microsoft_Toolkit_Uwp_UI_Controls_WinRT::implementation::UniversalWindowsAppPackageFontLoader +{ + /// + /// This is an enumerator that basically just enumerates 1 custom font into DWrite from the Universal Windows App package. + /// It's extremely simplistic and basically just connects the Universal App Package files to DWrite. + /// + struct FontFileEnumerator : winrt::implements + { + public: + FontFileEnumerator(); + virtual ~FontFileEnumerator(); + + /// + /// This is called consecutively by DWrite until we return FALSE to hasCurrentFile to enumerate the custom + /// font + /// + IFACEMETHOD(MoveNext)(_Out_ BOOL* hasCurrentFile); + + /// + /// This is called by DWrite to get the custom font file. + /// + IFACEMETHOD(GetCurrentFontFile)(_Outptr_ IDWriteFontFile** fontFile); + + /// + /// Initializes the enumerator + /// + HRESULT Initialize(_In_ IDWriteFactory* factory, const UniversalPackageFontData& packageFont); + + private: + winrt::com_ptr m_factory; + winrt::com_ptr m_currentFontFile; + UniversalPackageFontData m_packageFontArgs = {}; + bool m_enumerated = false; + }; +} \ No newline at end of file diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/UniversalWindowsAppPackageFontLoader/UniversalPackageFontData.h b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/UniversalWindowsAppPackageFontLoader/UniversalPackageFontData.h new file mode 100644 index 00000000000..b855a38654b --- /dev/null +++ b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/UniversalWindowsAppPackageFontLoader/UniversalPackageFontData.h @@ -0,0 +1,10 @@ +#pragma once + +namespace winrt::Microsoft_Toolkit_Uwp_UI_Controls_WinRT::implementation::UniversalWindowsAppPackageFontLoader +{ + struct UniversalPackageFontData + { + std::wstring packageFontFilePath; + std::wstring customFontName; + }; +} \ No newline at end of file diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/pch.cpp b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/pch.cpp new file mode 100644 index 00000000000..bcb5590be1b --- /dev/null +++ b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/pch.cpp @@ -0,0 +1 @@ +#include "pch.h" diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/pch.h b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/pch.h new file mode 100644 index 00000000000..fb3dea334d0 --- /dev/null +++ b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/pch.h @@ -0,0 +1,21 @@ +// +// pch.h +// Header for platform projection include files +// + +#pragma once + +#include "winrt/Windows.Foundation.h" + +// these are here if we have a .xaml file. +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include diff --git a/docs/controls/DirectWriteTextBlock.md b/docs/controls/DirectWriteTextBlock.md new file mode 100644 index 00000000000..91b35da8f28 --- /dev/null +++ b/docs/controls/DirectWriteTextBlock.md @@ -0,0 +1,53 @@ +--- +title: DirectWriteTextBlock +author: juma-msft +description: Defines a textblock which uses [DirectWrite](https://docs.microsoft.com/en-us/windows/desktop/directwrite/direct-write-portal) to render the font so that it can be oriented vertically +keywords: windows 10, uwp, windows community toolkit, uwp community toolkit, uwp toolkit, DockPanel, XAML Control, xaml +--- + +# DirectWriteTextBlock XAML Control + +The [DirectWriteTextBlock Control](https://docs.microsoft.com/dotnet/api/microsoft.toolkit.uwp.ui.controls.winrt.DirectWriteTextBlock) defines a textblock which can render text vertically with limited DirectWrite support. + +Do not use this to render horizontal text unless you need specific support from DirectWrite which isn't currently supported by XAML, it is less efficient than standard [TextBlock](https://docs.microsoft.com/uwp/api/windows.ui.xaml.controls.textblock) overall. + +## Syntax + +```xaml + + + + +``` + +## Sample Output + +## Properties + +| Property | Type | Description | +| -- | -- | -- | +| Text | String | The text to render using DirectWrite | +| TextLocale | String | The bcp-47 text locale tag to pass to DirectWrite, en-US by default | +| TextOrientation | String | The orientation of the text, Vertical by default | +| TextWrap | [Windows.UI.Xaml.TextWrapping](https://docs.microsoft.com/uwp/api/windows.ui.xaml.textwrapping) | How to wrap the text, NoWrap by default | +| FlowDirection | [Windows.UI.Xaml.FlowDirection](https://docs.microsoft.com/uwp/api/windows.ui.xaml.flowdirection) | Inherited from [Windows.UI.Xaml.Controls.Control](https://docs.microsoft.com/uwp/api/windows.ui.xaml.controls.control). the flow direction of the text, LeftToRight by default | +| Foreground | [Windows.UI.Xaml.Media.Brush](https://docs.microsoft.com/en-us/uwp/api/windows.ui.xaml.media.brush) | Inherited from [Windows.UI.Xaml.Controls.Control](https://docs.microsoft.com/uwp/api/windows.ui.xaml.controls.control). The font color of the text to render, this only supports [SolidColorBrush](https://docs.microsoft.com/uwp/api/windows.ui.xaml.media.solidcolorbrush) default is [Windows.UI.Colors.Black](https://docs.microsoft.com/en-us/uwp/api/windows.ui.colors.black#Windows_UI_Colors_Black) . | +| FontSize | double | Inherited from [Windows.UI.Xaml.Controls.Control](https://docs.microsoft.com/uwp/api/windows.ui.xaml.controls.control). The font size of the text to render, 15 by default | +| FontFamily | [Windows.UI.Xaml.Media.FontFamily](https://docs.microsoft.com/uwp/api/windows.ui.xaml.media.fontfamily) | Inherited from [Windows.UI.Xaml.Controls.Control](https://docs.microsoft.com/uwp/api/windows.ui.xaml.controls.control). The font family of the text to render, Segoe UI by default. This supports custom fonts with syntax like /Assets/FontFile.ttf#Font Name | +| FontStretch | [Windows.UI.Text.FontStretch](https://docs.microsoft.com/uwp/api/windows.ui.text.fontstretch) | Inherited from [Windows.UI.Xaml.Controls.Control](https://docs.microsoft.com/uwp/api/windows.ui.xaml.controls.control). The font stretch of the text to render, Normal by default | +| FontStyle | [Windows.UI.Text.FontStyle](https://docs.microsoft.com/uwp/api/windows.ui.text.fontstyle) | Inherited from [Windows.UI.Xaml.Controls.Control](https://docs.microsoft.com/uwp/api/windows.ui.xaml.controls.control). The font stretch of the text to render, Normal by default | +| FontWeight | [Windows.UI.Text.FontWeight](https://docs.microsoft.com/uwp/api/windows.ui.text.fontweight) | Inherited from [Windows.UI.Xaml.Controls.Control](https://docs.microsoft.com/uwp/api/windows.ui.xaml.controls.control). The font stretch of the text to render, Normal by default | + +## Sample Code + +## Requirements + +| Device family | Universal, 10.0.17134.0 or higher | +| -- | -- | +| Namespace | Microsoft.Toolkit.Uwp.UI.Controls.WinRT | +| NuGet package | [Microsoft.Toolkit.Uwp.UI.Controls.WinRT](https://www.nuget.org/packages/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/) | + +## API Source Code + +* [DirectWriteTextBlock source code in C++/WinRT](https://github.com/Microsoft/WindowsCommunityToolkit//tree/master/Microsoft.Toolkit.Uwp.UI.Controls.WinRT) From b3be8ff2df1588faaec8a642444913738ba15e3f Mon Sep 17 00:00:00 2001 From: "Jun Ma (WINDOWS)" Date: Tue, 2 Oct 2018 20:12:52 +0900 Subject: [PATCH 02/29] use CX because XAML won't compile in C++/WinRT projects. --- .../Class1.cpp | 9 + Microsoft.Toolkit.Uwp.Controls.WinRT/Class1.h | 10 + ...crosoft.Toolkit.Uwp.Controls.WinRT.vcxproj | 257 ++++++++ ...Toolkit.Uwp.Controls.WinRT.vcxproj.filters | 9 + Microsoft.Toolkit.Uwp.Controls.WinRT/pch.cpp | 1 + Microsoft.Toolkit.Uwp.Controls.WinRT/pch.h | 4 + .../DirectWriteRenderArgBuilder.cpp | 296 --------- .../DirectWriteRenderArgBuilder.h | 124 ---- .../DirectWriteResourceManager.cpp | 123 ---- .../DirectWriteResourceManager.h | 54 -- .../DirectWriteTextBlock.cpp | 266 -------- .../DirectWriteTextBlock.h | 106 ---- .../DirectWriteTextBlock.idl | 20 - .../DirectWriteRenderArgBuilder.cpp | 298 +++++++++ .../DirectWriteRenderArgBuilder.h | 120 ++++ .../DirectWriteResourceManager.cpp | 124 ++++ .../DirectWriteResourceManager.h | 55 ++ .../DirectWriteTextBlock.cpp | 270 ++++++++ .../DirectWriteTextBlock.h | 104 ++++ .../Generated Files/Themes/Generic.g.h | 1 + .../Generated Files/Themes/Generic.g.h | 1 + .../Generated Files/Themes/Generic.g.hpp | 1 + .../Generated Files/Themes/Generic.g.h | 1 + .../Generated Files/Themes/Generic.g.hpp | 1 + .../Generated Files/Themes/Generic.g.h | 1 + .../Generated Files/Themes/Generic.g.hpp | 1 + .../Generated Files/Themes/Generic.g.h | 1 + .../Generated Files/Themes/Generic.g.hpp | 1 + .../Generated Files/Themes/Generic.xaml | 29 + .../Generated Files/Themes/Generic.xbf | Bin 0 -> 1205 bytes .../Generated Files/XamlBindingInfo.g.h | 265 ++++++++ .../Generated Files/XamlBindingInfo.g.hpp | 237 +++++++ .../XamlLibMetadataProvider.g.cpp | 2 + .../Generated Files/XamlTypeInfo.Impl.g.cpp | 588 ++++++++++++++++++ .../Generated Files/XamlTypeInfo.g.cpp | 372 +++++++++++ .../Generated Files/XamlTypeInfo.g.h | 383 ++++++++++++ ...soft.Toolkit.Uwp.UI.Controls.WinRT.vcxproj | 213 +++++-- ...lkit.Uwp.UI.Controls.WinRT.vcxproj.filters | 70 +-- ...icrosoft_Toolkit_Uwp_UI_Controls_WinRT.def | 3 - .../Themes/Generic.xaml | 28 + .../FontCollectionLoader.cpp | 22 +- .../FontCollectionLoader.h | 16 +- .../FontFileEnumerator.cpp | 14 +- .../FontFileEnumerator.h | 8 +- .../UniversalPackageFontData.h | 8 +- Microsoft.Toolkit.Uwp.UI.Controls.WinRT/pch.h | 20 +- Windows Community Toolkit.sln | 24 + 47 files changed, 3444 insertions(+), 1117 deletions(-) create mode 100644 Microsoft.Toolkit.Uwp.Controls.WinRT/Class1.cpp create mode 100644 Microsoft.Toolkit.Uwp.Controls.WinRT/Class1.h create mode 100644 Microsoft.Toolkit.Uwp.Controls.WinRT/Microsoft.Toolkit.Uwp.Controls.WinRT.vcxproj create mode 100644 Microsoft.Toolkit.Uwp.Controls.WinRT/Microsoft.Toolkit.Uwp.Controls.WinRT.vcxproj.filters create mode 100644 Microsoft.Toolkit.Uwp.Controls.WinRT/pch.cpp create mode 100644 Microsoft.Toolkit.Uwp.Controls.WinRT/pch.h delete mode 100644 Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteRenderArgBuilder.cpp delete mode 100644 Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteRenderArgBuilder.h delete mode 100644 Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteResourceManager.cpp delete mode 100644 Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteResourceManager.h delete mode 100644 Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock.cpp delete mode 100644 Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock.h delete mode 100644 Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock.idl create mode 100644 Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock/DirectWriteRenderArgBuilder.cpp create mode 100644 Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock/DirectWriteRenderArgBuilder.h create mode 100644 Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock/DirectWriteResourceManager.cpp create mode 100644 Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock/DirectWriteResourceManager.h create mode 100644 Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock/DirectWriteTextBlock.cpp create mode 100644 Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock/DirectWriteTextBlock.h create mode 100644 Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Generated Files/Generated Files/Generated Files/Generated Files/Generated Files/Themes/Generic.g.h create mode 100644 Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Generated Files/Generated Files/Generated Files/Generated Files/Themes/Generic.g.h create mode 100644 Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Generated Files/Generated Files/Generated Files/Generated Files/Themes/Generic.g.hpp create mode 100644 Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Generated Files/Generated Files/Generated Files/Themes/Generic.g.h create mode 100644 Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Generated Files/Generated Files/Generated Files/Themes/Generic.g.hpp create mode 100644 Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Generated Files/Generated Files/Themes/Generic.g.h create mode 100644 Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Generated Files/Generated Files/Themes/Generic.g.hpp create mode 100644 Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Generated Files/Themes/Generic.g.h create mode 100644 Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Generated Files/Themes/Generic.g.hpp create mode 100644 Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Generated Files/Themes/Generic.xaml create mode 100644 Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Generated Files/Themes/Generic.xbf create mode 100644 Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Generated Files/XamlBindingInfo.g.h create mode 100644 Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Generated Files/XamlBindingInfo.g.hpp create mode 100644 Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Generated Files/XamlLibMetadataProvider.g.cpp create mode 100644 Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Generated Files/XamlTypeInfo.Impl.g.cpp create mode 100644 Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Generated Files/XamlTypeInfo.g.cpp create mode 100644 Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Generated Files/XamlTypeInfo.g.h delete mode 100644 Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Microsoft_Toolkit_Uwp_UI_Controls_WinRT.def create mode 100644 Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Themes/Generic.xaml diff --git a/Microsoft.Toolkit.Uwp.Controls.WinRT/Class1.cpp b/Microsoft.Toolkit.Uwp.Controls.WinRT/Class1.cpp new file mode 100644 index 00000000000..da012af0a09 --- /dev/null +++ b/Microsoft.Toolkit.Uwp.Controls.WinRT/Class1.cpp @@ -0,0 +1,9 @@ +#include "pch.h" +#include "Class1.h" + +using namespace Microsoft_Toolkit_Uwp_Controls_WinRT; +using namespace Platform; + +Class1::Class1() +{ +} diff --git a/Microsoft.Toolkit.Uwp.Controls.WinRT/Class1.h b/Microsoft.Toolkit.Uwp.Controls.WinRT/Class1.h new file mode 100644 index 00000000000..22b19021f11 --- /dev/null +++ b/Microsoft.Toolkit.Uwp.Controls.WinRT/Class1.h @@ -0,0 +1,10 @@ +#pragma once + +namespace Microsoft_Toolkit_Uwp_Controls_WinRT +{ + public ref class Class1 sealed + { + public: + Class1(); + }; +} diff --git a/Microsoft.Toolkit.Uwp.Controls.WinRT/Microsoft.Toolkit.Uwp.Controls.WinRT.vcxproj b/Microsoft.Toolkit.Uwp.Controls.WinRT/Microsoft.Toolkit.Uwp.Controls.WinRT.vcxproj new file mode 100644 index 00000000000..7673cf3d2a5 --- /dev/null +++ b/Microsoft.Toolkit.Uwp.Controls.WinRT/Microsoft.Toolkit.Uwp.Controls.WinRT.vcxproj @@ -0,0 +1,257 @@ + + + + + + Debug + ARM + + + Debug + Win32 + + + Debug + x64 + + + Release + ARM + + + Release + Win32 + + + Release + x64 + + + + + {fe15e3f0-76c1-4b81-ad36-c172690f23c7} + WindowsRuntimeComponent + Microsoft_Toolkit_Uwp_Controls_WinRT + en-US + 14.0 + true + Windows Store + 10.0.17134.0 + 10.0.15063.0 + 10.0 + + + + + + DynamicLibrary + true + v141 + + + DynamicLibrary + true + v141 + + + DynamicLibrary + true + v141 + + + DynamicLibrary + false + true + v141 + + + DynamicLibrary + false + true + v141 + + + DynamicLibrary + false + true + v141 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + false + + + + false + + + + false + + + + false + + + + false + + + + false + + + + + Use + _WINRT_DLL;%(PreprocessorDefinitions) + pch.h + $(IntDir)pch.pch + $(WindowsSDK_WindowsMetadata);$(AdditionalUsingDirectories) + /bigobj %(AdditionalOptions) + 28204 + + + Console + false + + + + + + Use + _WINRT_DLL;NDEBUG;%(PreprocessorDefinitions) + pch.h + $(IntDir)pch.pch + $(WindowsSDK_WindowsMetadata);$(AdditionalUsingDirectories) + /bigobj %(AdditionalOptions) + 28204 + + + Console + false + + + + + + Use + _WINRT_DLL;%(PreprocessorDefinitions) + pch.h + $(IntDir)pch.pch + $(WindowsSDK_WindowsMetadata);$(AdditionalUsingDirectories) + /bigobj %(AdditionalOptions) + 28204 + + + Console + false + + + + + + Use + _WINRT_DLL;NDEBUG;%(PreprocessorDefinitions) + pch.h + $(IntDir)pch.pch + $(WindowsSDK_WindowsMetadata);$(AdditionalUsingDirectories) + /bigobj %(AdditionalOptions) + 28204 + + + Console + false + + + + + + Use + _WINRT_DLL;%(PreprocessorDefinitions) + pch.h + $(IntDir)pch.pch + $(WindowsSDK_WindowsMetadata);$(AdditionalUsingDirectories) + /bigobj %(AdditionalOptions) + 28204 + + + Console + false + + + + + + Use + _WINRT_DLL;NDEBUG;%(PreprocessorDefinitions) + pch.h + $(IntDir)pch.pch + $(WindowsSDK_WindowsMetadata);$(AdditionalUsingDirectories) + /bigobj %(AdditionalOptions) + 28204 + + + Console + false + + + + + + + + + + + Create + Create + Create + Create + Create + Create + + + + + + + + + + diff --git a/Microsoft.Toolkit.Uwp.Controls.WinRT/Microsoft.Toolkit.Uwp.Controls.WinRT.vcxproj.filters b/Microsoft.Toolkit.Uwp.Controls.WinRT/Microsoft.Toolkit.Uwp.Controls.WinRT.vcxproj.filters new file mode 100644 index 00000000000..9acb68c70e8 --- /dev/null +++ b/Microsoft.Toolkit.Uwp.Controls.WinRT/Microsoft.Toolkit.Uwp.Controls.WinRT.vcxproj.filters @@ -0,0 +1,9 @@ + + + + + d7fdb929-d624-4f37-b5a4-783a214498ed + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tga;tiff;tif;png;wav;mfcribbon-ms + + + diff --git a/Microsoft.Toolkit.Uwp.Controls.WinRT/pch.cpp b/Microsoft.Toolkit.Uwp.Controls.WinRT/pch.cpp new file mode 100644 index 00000000000..bcb5590be1b --- /dev/null +++ b/Microsoft.Toolkit.Uwp.Controls.WinRT/pch.cpp @@ -0,0 +1 @@ +#include "pch.h" diff --git a/Microsoft.Toolkit.Uwp.Controls.WinRT/pch.h b/Microsoft.Toolkit.Uwp.Controls.WinRT/pch.h new file mode 100644 index 00000000000..10fe677c728 --- /dev/null +++ b/Microsoft.Toolkit.Uwp.Controls.WinRT/pch.h @@ -0,0 +1,4 @@ +#pragma once + +#include +#include diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteRenderArgBuilder.cpp b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteRenderArgBuilder.cpp deleted file mode 100644 index fd0fc7270cf..00000000000 --- a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteRenderArgBuilder.cpp +++ /dev/null @@ -1,296 +0,0 @@ -#include "pch.h" -#include "DirectWriteRenderArgBuilder.h" -#include "DirectWriteResourceManager.h" -#include "UniversalWindowsAppPackageFontLoader\FontCollectionLoader.h" - -namespace winrt::Microsoft_Toolkit_Uwp_UI_Controls_WinRT::implementation -{ - using namespace Windows::UI; - using namespace Windows::UI::Text; - using namespace Windows::UI::Xaml; - using namespace Windows::UI::Xaml::Controls; - using namespace Windows::UI::Xaml::Media; - using namespace Windows::Globalization; - using namespace Windows::Graphics::Display; - using namespace Windows::Foundation; - - DirectWriteRenderArgBuilder::DirectWriteRenderArgBuilder() - { - // default values - m_builtArgs.availableHeight = 0; - m_builtArgs.availableWidth = 0; - m_builtArgs.flowDirection = DWRITE_FLOW_DIRECTION::DWRITE_FLOW_DIRECTION_LEFT_TO_RIGHT; - m_builtArgs.fontFamily = winrt::to_hstring(L"Segoe UI"); - m_builtArgs.fontSize = 15; - m_builtArgs.fontStretch = DWRITE_FONT_STRETCH::DWRITE_FONT_STRETCH_NORMAL; - m_builtArgs.fontStyle = DWRITE_FONT_STYLE::DWRITE_FONT_STYLE_NORMAL; - m_builtArgs.fontWeight = DWRITE_FONT_WEIGHT::DWRITE_FONT_WEIGHT_NORMAL; - m_builtArgs.foregroundColor = Windows::UI::Colors::Black(); - m_builtArgs.rawPixelsPerViewPixel = 1; - m_builtArgs.readingDirection = DWRITE_READING_DIRECTION::DWRITE_READING_DIRECTION_LEFT_TO_RIGHT; - m_builtArgs.textLocale = winrt::to_hstring(L"en-US"); - m_builtArgs.textWrapping = DWRITE_WORD_WRAPPING::DWRITE_WORD_WRAPPING_NO_WRAP; - m_builtArgs.fontCollection = nullptr; - } - - void DirectWriteRenderArgBuilder::SetFontFamily(FontFamily const& fontFamily) - { - winrt::hstring resultFontFamily{}; - - // try to get the FontFamily property first. - auto controlFontFamily = fontFamily; - if ((controlFontFamily != nullptr) && !controlFontFamily.Source().empty()) - { - // if there's something in the font family, use it. - resultFontFamily = controlFontFamily.Source(); - } - - // if nothing was in the font family, try the XAML default value. - if (resultFontFamily.empty() && (controlFontFamily != nullptr)) - { - auto xamlDefault = controlFontFamily.XamlAutoFontFamily(); - if ((xamlDefault != nullptr) && !xamlDefault.Source().empty()) - { - resultFontFamily = xamlDefault.Source(); - } - } - - // if the xaml default failed for some reason, hardcode to Segoe UI as last fallback. - if (resultFontFamily.empty()) - { - resultFontFamily = winrt::to_hstring(L"Segoe UI"); - } - - m_builtArgs.fontFamily = resultFontFamily; - BuildFontCollection(resultFontFamily); - } - - void DirectWriteRenderArgBuilder::SetText(winrt::hstring const& text) - { - m_builtArgs.text = text; - } - - void DirectWriteRenderArgBuilder::SetTextLocale(winrt::hstring const& textLocale) - { - if (Language::IsWellFormed(textLocale)) - { - m_builtArgs.textLocale = textLocale; - } - else - { - // default to en-US. - m_builtArgs.textLocale = winrt::to_hstring(L"en-US"); - } - } - - void DirectWriteRenderArgBuilder::SetForegroundBrush(Brush const& brush) - { - auto solidColorBrush{ brush.try_as() }; - if (solidColorBrush != nullptr) - { - m_builtArgs.foregroundColor = solidColorBrush.Color(); - } - else - { - m_builtArgs.foregroundColor = Colors::Black(); - } - } - - void DirectWriteRenderArgBuilder::SetFontStyle(FontStyle fontStyle) - { - switch (fontStyle) - { - case FontStyle::Normal: __fallthrough; - default: - m_builtArgs.fontStyle = DWRITE_FONT_STYLE::DWRITE_FONT_STYLE_NORMAL; - break; - case FontStyle::Italic: - m_builtArgs.fontStyle = DWRITE_FONT_STYLE::DWRITE_FONT_STYLE_ITALIC; - break; - case FontStyle::Oblique: - m_builtArgs.fontStyle = DWRITE_FONT_STYLE::DWRITE_FONT_STYLE_OBLIQUE; - break; - } - } - - void DirectWriteRenderArgBuilder::SetFontStretch(FontStretch fontStretch) - { - switch (fontStretch) - { - case FontStretch::Normal: __fallthrough; - default: - m_builtArgs.fontStretch = DWRITE_FONT_STRETCH::DWRITE_FONT_STRETCH_NORMAL; - break; - case FontStretch::Condensed: - m_builtArgs.fontStretch = DWRITE_FONT_STRETCH::DWRITE_FONT_STRETCH_CONDENSED; - break; - case FontStretch::Expanded: - m_builtArgs.fontStretch = DWRITE_FONT_STRETCH::DWRITE_FONT_STRETCH_EXPANDED; - break; - case FontStretch::ExtraCondensed: - m_builtArgs.fontStretch = DWRITE_FONT_STRETCH::DWRITE_FONT_STRETCH_EXTRA_CONDENSED; - break; - case FontStretch::ExtraExpanded: - m_builtArgs.fontStretch = DWRITE_FONT_STRETCH::DWRITE_FONT_STRETCH_EXTRA_EXPANDED; - break; - case FontStretch::SemiCondensed: - m_builtArgs.fontStretch = DWRITE_FONT_STRETCH::DWRITE_FONT_STRETCH_SEMI_CONDENSED; - break; - case FontStretch::SemiExpanded: - m_builtArgs.fontStretch = DWRITE_FONT_STRETCH::DWRITE_FONT_STRETCH_SEMI_EXPANDED; - break; - case FontStretch::UltraCondensed: - m_builtArgs.fontStretch = DWRITE_FONT_STRETCH::DWRITE_FONT_STRETCH_ULTRA_CONDENSED; - break; - case FontStretch::UltraExpanded: - m_builtArgs.fontStretch = DWRITE_FONT_STRETCH::DWRITE_FONT_STRETCH_ULTRA_EXPANDED; - break; - } - } - - void DirectWriteRenderArgBuilder::SetTextOrientation(Orientation textOrientation) - { - switch (textOrientation) - { - case Orientation::Vertical: __fallthrough; - default: - m_builtArgs.readingDirection = DWRITE_READING_DIRECTION::DWRITE_READING_DIRECTION_TOP_TO_BOTTOM; - break; - case Orientation::Horizontal: - m_builtArgs.readingDirection = DWRITE_READING_DIRECTION::DWRITE_READING_DIRECTION_LEFT_TO_RIGHT; - break; - } - } - - void DirectWriteRenderArgBuilder::SetFlowDirection(FlowDirection flowDirection) - { - switch (flowDirection) - { - case FlowDirection::LeftToRight: __fallthrough; - default: - m_builtArgs.flowDirection = DWRITE_FLOW_DIRECTION::DWRITE_FLOW_DIRECTION_LEFT_TO_RIGHT; - break; - case FlowDirection::RightToLeft: - m_builtArgs.flowDirection = DWRITE_FLOW_DIRECTION::DWRITE_FLOW_DIRECTION_RIGHT_TO_LEFT; - break; - } - } - - void DirectWriteRenderArgBuilder::SetFontWeight(FontWeight fontWeight) - { - auto weight = fontWeight.Weight; - if (weight == FontWeights::Black().Weight) - { - m_builtArgs.fontWeight = DWRITE_FONT_WEIGHT::DWRITE_FONT_WEIGHT_BLACK; - } - else if (weight == FontWeights::Bold().Weight) - { - m_builtArgs.fontWeight = DWRITE_FONT_WEIGHT::DWRITE_FONT_WEIGHT_BOLD; - } - else if (weight == FontWeights::ExtraBlack().Weight) - { - m_builtArgs.fontWeight = DWRITE_FONT_WEIGHT::DWRITE_FONT_WEIGHT_EXTRA_BLACK; - } - else if (weight == FontWeights::ExtraBold().Weight) - { - m_builtArgs.fontWeight = DWRITE_FONT_WEIGHT::DWRITE_FONT_WEIGHT_EXTRA_BOLD; - } - else if (weight == FontWeights::ExtraLight().Weight) - { - m_builtArgs.fontWeight = DWRITE_FONT_WEIGHT::DWRITE_FONT_WEIGHT_EXTRA_LIGHT; - } - else if (weight == FontWeights::Light().Weight) - { - m_builtArgs.fontWeight = DWRITE_FONT_WEIGHT::DWRITE_FONT_WEIGHT_LIGHT; - } - else if (weight == FontWeights::SemiBold().Weight) - { - m_builtArgs.fontWeight = DWRITE_FONT_WEIGHT::DWRITE_FONT_WEIGHT_SEMI_BOLD; - } - else if (weight == FontWeights::SemiLight().Weight) - { - m_builtArgs.fontWeight = DWRITE_FONT_WEIGHT::DWRITE_FONT_WEIGHT_SEMI_LIGHT; - } - else - { - m_builtArgs.fontWeight = DWRITE_FONT_WEIGHT::DWRITE_FONT_WEIGHT_NORMAL; - } - } - - void DirectWriteRenderArgBuilder::SetTextWrapping(TextWrapping textWrapping) - { - switch (textWrapping) - { - case TextWrapping::NoWrap: - default: - m_builtArgs.textWrapping = DWRITE_WORD_WRAPPING::DWRITE_WORD_WRAPPING_NO_WRAP; - break; - case TextWrapping::Wrap: - m_builtArgs.textWrapping = DWRITE_WORD_WRAPPING::DWRITE_WORD_WRAPPING_WRAP; - break; - case TextWrapping::WrapWholeWords: - m_builtArgs.textWrapping = DWRITE_WORD_WRAPPING::DWRITE_WORD_WRAPPING_WHOLE_WORD; - break; - } - } - - void DirectWriteRenderArgBuilder::SetFontSize(double fontSize) - { - m_builtArgs.fontSize = static_cast(fontSize); - if (m_builtArgs.fontSize <= 0) - { - m_builtArgs.fontSize = 15.0f; - } - } - - void DirectWriteRenderArgBuilder::SetDPI(double rawPixelsPerViewPixel) - { - m_builtArgs.rawPixelsPerViewPixel = static_cast(rawPixelsPerViewPixel); - if (m_builtArgs.rawPixelsPerViewPixel <= 0) - { - m_builtArgs.rawPixelsPerViewPixel = 1.0f; - } - } - - void DirectWriteRenderArgBuilder::SetAvailableWidth(float availableWidth) - { - m_builtArgs.availableWidth = availableWidth; - } - - void DirectWriteRenderArgBuilder::SetAvailableHeight(float availableHeight) - { - m_builtArgs.availableHeight = availableHeight; - } - - DirectWriteTextRenderArgs& DirectWriteRenderArgBuilder::BuildRenderArgs() - { - return m_builtArgs; - } - - void DirectWriteRenderArgBuilder::BuildFontCollection(const winrt::hstring& fontFamily) - { - // default arg is system font collection, what we're looking for is if we're trying to - // find a local custom ttf file. - if (UniversalWindowsAppPackageFontLoader::FontCollectionLoader::HasCustomFontFamily(fontFamily)) - { - auto resourceManager = DirectWriteResourceManager::GetInstance(); - auto dwriteFactory = resourceManager->GetDirectWriteFactoryNoRef(); - UniversalWindowsAppPackageFontLoader::UniversalPackageFontData parseData = {}; - UniversalWindowsAppPackageFontLoader::FontCollectionLoader::ParseXamlFontFamily(fontFamily, parseData); - auto customLoader = UniversalWindowsAppPackageFontLoader::FontCollectionLoader::GetInstance(); - - // the key is a void* meaning the size is actual size. - auto fontFamilyString = fontFamily.c_str(); - auto fontFamilySize = fontFamily.size() * sizeof(wchar_t); - dwriteFactory->CreateCustomFontCollection(customLoader.get(), fontFamilyString, fontFamilySize, m_builtArgs.fontCollection.put()); - - // set font family to the parsed font family. - m_builtArgs.fontFamily = parseData.customFontName; - } - else - { - // else assume it's a system font for now. We could do a lookup, but that would actually slow things down. - m_builtArgs.fontCollection = nullptr; - } - } -} \ No newline at end of file diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteRenderArgBuilder.h b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteRenderArgBuilder.h deleted file mode 100644 index 30a7ce594c7..00000000000 --- a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteRenderArgBuilder.h +++ /dev/null @@ -1,124 +0,0 @@ -#pragma once -#include -#include -#include -#include -#include - -namespace winrt::Microsoft_Toolkit_Uwp_UI_Controls_WinRT::implementation -{ - /// - /// These are arguments which are used to render the DWrite string. - /// - struct DirectWriteTextRenderArgs - { - winrt::hstring fontFamily; - winrt::hstring text; - winrt::hstring textLocale; - Windows::UI::Color foregroundColor; - DWRITE_FONT_STYLE fontStyle; - DWRITE_FONT_STRETCH fontStretch; - DWRITE_READING_DIRECTION readingDirection; - DWRITE_FLOW_DIRECTION flowDirection; - DWRITE_FONT_WEIGHT fontWeight; - DWRITE_WORD_WRAPPING textWrapping; - float fontSize; - float rawPixelsPerViewPixel; - float availableWidth; - float availableHeight; - winrt::com_ptr fontCollection; - }; - - /// - /// This class translates input from the XAML world into a DirectWriteTextRenderArgs struct - /// meant to be used with the DWrite world. If the user passes invalid values in, it attempts - /// to correct by setting them back to a known default value. This is because in case the user - /// is using the text block from C# (most users are expected to do this), a crash ultimately - /// just gives them a "something went wrong and a native exception was thrown" which is not - /// super helpful. Recovery will at least render something that looks incorrect on the screen. - /// - class DirectWriteRenderArgBuilder - { - public: - DirectWriteRenderArgBuilder(); - - /// - /// The font family, by default Segoe UI - /// - void SetFontFamily(Windows::UI::Xaml::Media::FontFamily const& fontFamily); - - /// - /// The text to render, empty string by default. - /// - void SetText(winrt::hstring const& text); - - /// - /// The text locale for DWrite, en-US by default. - /// - void SetTextLocale(winrt::hstring const& textLocale); - - /// - /// The foreground brush, Black by default - /// - void SetForegroundBrush(Windows::UI::Xaml::Media::Brush const& brush); - - /// - /// The font style, Normal by default - /// - void SetFontStyle(Windows::UI::Text::FontStyle fontStyle); - - /// - /// The font stretch, normal by default - /// - void SetFontStretch(Windows::UI::Text::FontStretch fontStretch); - - /// - /// The text orientation, vertical by default since if you're going to use horizontal, you should use a XAML TextBlock - /// - void SetTextOrientation(Windows::UI::Xaml::Controls::Orientation textOrientation); - - /// - /// The flow direction, LeftToRight by default - /// - void SetFlowDirection(Windows::UI::Xaml::FlowDirection flowDirection); - - /// - /// The font weight, Normal by default - /// - void SetFontWeight(Windows::UI::Text::FontWeight fontWeight); - - /// - /// The font size, 15 by default. - /// - void SetFontSize(double fontSize); - - /// - /// The DPI to render at, 1 by default - /// - void SetDPI(double rawPixelsPerViewPixel); - - /// - /// The available width to render at - /// - void SetAvailableWidth(float availableWidth); - - /// - /// The available height to render at. - /// - void SetAvailableHeight(float availableHeight); - - /// - /// The text wrap mode, None by default. - /// - void SetTextWrapping(Windows::UI::Xaml::TextWrapping textWrapping); - - /// - /// The render arguments. - /// - DirectWriteTextRenderArgs& BuildRenderArgs(); - - private: - void BuildFontCollection(const winrt::hstring& fontFamily); - DirectWriteTextRenderArgs m_builtArgs = {}; - }; -} \ No newline at end of file diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteResourceManager.cpp b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteResourceManager.cpp deleted file mode 100644 index 8f5aeb1782a..00000000000 --- a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteResourceManager.cpp +++ /dev/null @@ -1,123 +0,0 @@ -#include "pch.h" -#include "UniversalWindowsAppPackageFontLoader\FontCollectionLoader.h" -#include "DirectWriteResourceManager.h" - -namespace winrt::Microsoft_Toolkit_Uwp_UI_Controls_WinRT::implementation -{ - std::unique_ptr DirectWriteResourceManager::s_instance; - - DirectWriteResourceManager::DirectWriteResourceManager() - { - } - - DirectWriteResourceManager::~DirectWriteResourceManager() - { - } - - IDWriteFactory* DirectWriteResourceManager::GetDirectWriteFactoryNoRef() - { - winrt::check_hresult(InitializeDeviceResources()); - return m_dwriteFactory.get(); - } - - ID3D11Device* DirectWriteResourceManager::GetD3dDeviceNoRef() - { - winrt::check_hresult(InitializeDeviceResources()); - return m_d3dDevice.get(); - } - - ID2D1DeviceContext* DirectWriteResourceManager::GetD2dDCNoRef() - { - winrt::check_hresult(InitializeDeviceResources()); - return m_d2dContext.get(); - } - - IDXGIDevice* DirectWriteResourceManager::GetDXGIDeviceNoRef() - { - winrt::check_hresult(InitializeDeviceResources()); - return m_dxgiDevice.get(); - } - - HRESULT DirectWriteResourceManager::InitializeDeviceResources() - { - if (!m_deviceResourcesInitialized) - { - UINT creationFlags = D3D11_CREATE_DEVICE_BGRA_SUPPORT; - D3D_FEATURE_LEVEL supportedFeatureLevel; - - D3D_FEATURE_LEVEL featureLevels[] = - { - D3D_FEATURE_LEVEL_11_1, - D3D_FEATURE_LEVEL_11_0, - D3D_FEATURE_LEVEL_10_1, - D3D_FEATURE_LEVEL_10_0, - D3D_FEATURE_LEVEL_9_3, - D3D_FEATURE_LEVEL_9_2, - D3D_FEATURE_LEVEL_9_1 - }; - - HRESULT hr = D3D11CreateDevice( - nullptr, // Specify nullptr to use the default adapter. - D3D_DRIVER_TYPE_HARDWARE, // Create a device using the hardware graphics driver. - 0, // Should be 0 unless the driver is D3D_DRIVER_TYPE_SOFTWARE. - creationFlags, // Set debug and Direct2D compatibility flags. - featureLevels, // List of feature levels this app can support. - ARRAYSIZE(featureLevels), - D3D11_SDK_VERSION, // Always set this to D3D11_SDK_VERSION for Windows Store apps. - m_d3dDevice.put(), // Returns the Direct3D device created. - &supportedFeatureLevel, - nullptr - ); - - // log failures on the initial creation - if (FAILED(hr)) - { - // If the initialization fails, fall back to the WARP device. - winrt::check_hresult(D3D11CreateDevice( - nullptr, - D3D_DRIVER_TYPE_WARP, // Create a WARP device instead of a hardware device. - 0, - creationFlags, - featureLevels, - ARRAYSIZE(featureLevels), - D3D11_SDK_VERSION, - m_d3dDevice.put(), - &supportedFeatureLevel, - nullptr - )); - } - - // Get the Direct3D 11.1 API device. - m_d3dDevice.as(m_dxgiDevice); - winrt::check_hresult(D2D1CreateDevice(m_dxgiDevice.get(), nullptr, m_d2dDevice.put())); - - winrt::check_hresult(m_d2dDevice->CreateDeviceContext( - D2D1_DEVICE_CONTEXT_OPTIONS_NONE, - m_d2dContext.put() - )); - - winrt::check_hresult(DWriteCreateFactory( - DWRITE_FACTORY_TYPE_SHARED, - __uuidof(IDWriteFactory), - reinterpret_cast(m_dwriteFactory.put()) - )); - - auto customLoader = UniversalWindowsAppPackageFontLoader::FontCollectionLoader::GetInstance(); - m_dwriteFactory->RegisterFontCollectionLoader(customLoader.get()); - - m_deviceResourcesInitialized = true; - } - - return S_OK; - } - - DirectWriteResourceManager* DirectWriteResourceManager::GetInstance() - { - if (s_instance == nullptr) - { - s_instance.reset(new DirectWriteResourceManager()); - } - - return s_instance.get(); - } -} \ No newline at end of file diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteResourceManager.h b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteResourceManager.h deleted file mode 100644 index 1febb8c7329..00000000000 --- a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteResourceManager.h +++ /dev/null @@ -1,54 +0,0 @@ -#pragma once - -namespace winrt::Microsoft_Toolkit_Uwp_UI_Controls_WinRT::implementation -{ - /// - /// This manages D3D/DWrite resources and prevents reinitialization. - /// - class DirectWriteResourceManager - { - public: - DirectWriteResourceManager(); - virtual ~DirectWriteResourceManager(); - - /// - /// This is a singleton to prevent reintializing D3D - /// - static DirectWriteResourceManager* GetInstance(); - - /// - /// The DWrite Factory, caller doesn't take a reference. - /// - IDWriteFactory* GetDirectWriteFactoryNoRef(); - - /// - /// The D3D Device, caller doesn't take a reference. - /// - ID3D11Device* GetD3dDeviceNoRef(); - - /// - /// The D2D Device, caller doesn't take a reference. - /// - ID2D1DeviceContext* GetD2dDCNoRef(); - - /// - /// The DXGI Device, caller doesn't take a reference. - /// - IDXGIDevice* GetDXGIDeviceNoRef(); - - /// - /// Initializes the device resources. - /// - HRESULT InitializeDeviceResources(); - - private: - winrt::com_ptr m_dwriteFactory; - winrt::com_ptr m_d3dDevice; - winrt::com_ptr m_d2dDevice; - winrt::com_ptr m_d2dContext; - winrt::com_ptr m_dxgiDevice; - - static std::unique_ptr s_instance; - bool m_deviceResourcesInitialized = false; - }; -} \ No newline at end of file diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock.cpp b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock.cpp deleted file mode 100644 index e7eb599f5fb..00000000000 --- a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock.cpp +++ /dev/null @@ -1,266 +0,0 @@ -// Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license. -// See LICENSE in the project root for license information. - -#include "pch.h" -#include -#include -#include -#include "DirectWriteTextBlock.h" - -namespace winrt::Microsoft_Toolkit_Uwp_UI_Controls_WinRT::implementation -{ - using namespace Windows::UI::Xaml; - using namespace Windows::UI::Xaml::Controls; - using namespace Windows::UI::Xaml::Media; - using namespace Windows::UI::Xaml::Media::Imaging; - using namespace Windows::Graphics::Display; - using namespace Windows::Foundation; - - // note: if you pass nullptr to winrt::to_hstring you will get a crash. - DependencyProperty DirectWriteTextBlock::m_textProperty = DependencyProperty::Register( - winrt::param::hstring(L"Text"), - winrt::xaml_typename(), - winrt::xaml_typename(), - PropertyMetadata{ winrt::box_value(winrt::to_hstring(L"")), PropertyChangedCallback{ &DirectWriteTextBlock::OnDependencyPropertyChanged } }); - - DependencyProperty DirectWriteTextBlock::m_textLocaleProperty = DependencyProperty::Register( - winrt::param::hstring(L"TextLocale"), - winrt::xaml_typename(), - winrt::xaml_typename(), - PropertyMetadata{ winrt::box_value(L"en-US"), PropertyChangedCallback{ &DirectWriteTextBlock::OnDependencyPropertyChanged } }); - - DependencyProperty DirectWriteTextBlock::m_textOrientationProperty = DependencyProperty::Register( - winrt::param::hstring(L"TextOrientation"), - winrt::xaml_typename(), - winrt::xaml_typename(), - PropertyMetadata{ winrt::box_value(Windows::UI::Xaml::Controls::Orientation::Vertical), PropertyChangedCallback{ &DirectWriteTextBlock::OnDependencyPropertyChanged } }); - - DependencyProperty DirectWriteTextBlock::m_textWrapProperty = DependencyProperty::Register( - winrt::param::hstring(L"TextWrap"), - winrt::xaml_typename(), - winrt::xaml_typename(), - PropertyMetadata{ winrt::box_value(Windows::UI::Xaml::TextWrapping::NoWrap), PropertyChangedCallback{ &DirectWriteTextBlock::OnDependencyPropertyChanged } }); - - DirectWriteTextBlock::DirectWriteTextBlock() - { - // note: while this is what we should do, there's current a crash if you add a .xaml file to a C++/WinRT project. Once that bug is fixed, we should - // keep a default style with this dll so consumers can know what to do. - DefaultStyleKey(winrt::box_value(L"Microsoft.Toolkit.Uwp.UI.Controls.WinRT.DirectWriteTextBlock")); - - auto displayInfo = DisplayInformation::GetForCurrentView(); - m_dpiChangedToken = displayInfo.DpiChanged({ this, &DirectWriteTextBlock::OnDpiChanged }); - -#define REGISTER_INHERITED_PROPERTY_CALLBACK(token, inheritedProperty) \ - token = RegisterPropertyChangedCallback(inheritedProperty, DependencyPropertyChangedCallback{ &DirectWriteTextBlock::OnInheritedDependencyPropertyChanged }) - - REGISTER_INHERITED_PROPERTY_CALLBACK(m_flowDirectionChangedToken, FrameworkElement::FlowDirectionProperty()); - REGISTER_INHERITED_PROPERTY_CALLBACK(m_foregroundChangedToken, Control::ForegroundProperty()); - REGISTER_INHERITED_PROPERTY_CALLBACK(m_fontSizeChangedToken, Control::FontSizeProperty()); - REGISTER_INHERITED_PROPERTY_CALLBACK(m_fontFamilyChangedToken, Control::FontFamilyProperty()); - REGISTER_INHERITED_PROPERTY_CALLBACK(m_fontStretchChangedToken, Control::FontStretchProperty()); - REGISTER_INHERITED_PROPERTY_CALLBACK(m_fontStyleChangedToken, Control::FontStyleProperty()); - REGISTER_INHERITED_PROPERTY_CALLBACK(m_fontWeightChangedToken, Control::FontWeightProperty()); -#undef REGISTER_INHERITED_PROPERTY_CALLBACK - } - - DirectWriteTextBlock::~DirectWriteTextBlock() - { - Close(); - } - - void DirectWriteTextBlock::OnApplyTemplate() - { - // make XAML apply the template first - __super::OnApplyTemplate(); - - auto maybeImage = GetTemplateChild(L"Image").try_as(); - if (maybeImage == nullptr) - { - winrt::throw_hresult(E_NOT_VALID_STATE); - } - - m_image = maybeImage; - } - - Size DirectWriteTextBlock::MeasureOverride(Size const& availableSize) - { - auto displayInfo = DisplayInformation::GetForCurrentView(); - DirectWriteRenderArgBuilder builder; - builder.SetAvailableHeight(availableSize.Height); - builder.SetAvailableWidth(availableSize.Width); - builder.SetDPI(displayInfo.RawPixelsPerViewPixel()); - builder.SetFlowDirection(FlowDirection()); - builder.SetFontFamily(FontFamily()); - builder.SetFontSize(FontSize()); - builder.SetFontStretch(FontStretch()); - builder.SetFontStyle(FontStyle()); - builder.SetFontWeight(FontWeight()); - builder.SetForegroundBrush(Foreground()); - builder.SetText(Text()); - builder.SetTextLocale(TextLocale()); - builder.SetTextOrientation(TextOrientation()); - builder.SetTextWrapping(TextWrap()); - - auto args = builder.BuildRenderArgs(); - return RenderText(args); - } - - void DirectWriteTextBlock::Close() - { - -#define UNREGISTER_INHERITED_PROPERTY_CALLBACK(token, inheritedProperty) \ - if (token != 0) \ - { \ - UnregisterPropertyChangedCallback(inheritedProperty, token); \ - token = 0; \ - } - - UNREGISTER_INHERITED_PROPERTY_CALLBACK(m_flowDirectionChangedToken, FrameworkElement::FlowDirectionProperty()); - UNREGISTER_INHERITED_PROPERTY_CALLBACK(m_foregroundChangedToken, Control::ForegroundProperty()); - UNREGISTER_INHERITED_PROPERTY_CALLBACK(m_fontSizeChangedToken, Control::FontSizeProperty()); - UNREGISTER_INHERITED_PROPERTY_CALLBACK(m_fontFamilyChangedToken, Control::FontFamilyProperty()); - UNREGISTER_INHERITED_PROPERTY_CALLBACK(m_fontStretchChangedToken, Control::FontStretchProperty()); - UNREGISTER_INHERITED_PROPERTY_CALLBACK(m_fontStyleChangedToken, Control::FontStyleProperty()); - UNREGISTER_INHERITED_PROPERTY_CALLBACK(m_fontWeightChangedToken, Control::FontWeightProperty()); - - if (m_dpiChangedToken.value != 0) - { - auto displayInfo = DisplayInformation::GetForCurrentView(); - displayInfo.DpiChanged(m_dpiChangedToken); - m_dpiChangedToken = {}; - } - -#undef UNREGISTER_INHERITED_PROPERTY_CALLBACK - } - - Size DirectWriteTextBlock::RenderText(DirectWriteTextRenderArgs const& args) - { - if (args.text.empty()) - { - return Size{ 0, 0 }; - } - - auto resourceManager = DirectWriteResourceManager::GetInstance(); - auto scale = args.rawPixelsPerViewPixel; - auto scaledFontSize = args.fontSize * scale; - auto dwriteFactory = resourceManager->GetDirectWriteFactoryNoRef(); - - winrt::com_ptr textFormat; - winrt::check_hresult(dwriteFactory->CreateTextFormat( - args.fontFamily.data(), - args.fontCollection.get(), - args.fontWeight, - args.fontStyle, - args.fontStretch, - scaledFontSize, - args.textLocale.data(), - textFormat.put())); - - textFormat->SetWordWrapping(args.textWrapping); - - // Trying to set readingDirection + FlowDirection to LEFT_TO_RIGHT will result in - // a failed HRESULT From DWRITE. Since the defaults work fine for horizontal, only - // set these values for text orientation = vertical. - if (this->TextOrientation() == Orientation::Vertical) - { - textFormat->SetReadingDirection(args.readingDirection); - textFormat->SetFlowDirection(args.flowDirection); - } - - winrt::com_ptr textLayout; - winrt::check_hresult(dwriteFactory->CreateTextLayout( - args.text.data(), - args.text.size(), - textFormat.get(), - args.availableWidth, - args.availableHeight, - textLayout.put())); - - DWRITE_TEXT_METRICS textMetrics = {}; - winrt::check_hresult(textLayout->GetMetrics(&textMetrics)); - - auto sisWidth = static_cast(std::ceil(textMetrics.width)); - auto sisHeight = static_cast(std::ceil(textMetrics.height)); - auto imageSource = SurfaceImageSource(sisWidth, sisHeight); - auto sisNative{ imageSource.as() }; - sisNative->SetDevice(resourceManager->GetDXGIDeviceNoRef()); - - winrt::com_ptr surface; - RECT updateRect = { 0, 0, static_cast(sisWidth), static_cast(sisHeight) }; - POINT offset = { 0, 0 }; - if (SUCCEEDED(sisNative->BeginDraw(updateRect, surface.put(), &offset))) - { - auto d2dContext = resourceManager->GetD2dDCNoRef(); - - // set the translation to the section of the bitmap that we want to render. - auto translate = D2D1::Matrix3x2F::Translation(static_cast(offset.x), static_cast(offset.y)); - d2dContext->SetTransform(translate); - - // this basically ensures the text background is transparent. - D2D1_BITMAP_PROPERTIES1 bitmapProperties = - { - { DXGI_FORMAT_UNKNOWN, D2D1_ALPHA_MODE_PREMULTIPLIED }, - 96.f * scale, - 96.f * scale, - D2D1_BITMAP_OPTIONS_TARGET | D2D1_BITMAP_OPTIONS_CANNOT_DRAW - }; - - winrt::com_ptr bitmap; - winrt::check_hresult(d2dContext->CreateBitmapFromDxgiSurface( - surface.get(), - &bitmapProperties, - bitmap.put())); - - d2dContext->SetTarget(bitmap.get()); - d2dContext->BeginDraw(); - d2dContext->Clear(); - - winrt::com_ptr brush; - auto color = args.foregroundColor; - D2D1_COLOR_F d2dColor = D2D1::ColorF( - static_cast(color.R) / 255.0f, - static_cast(color.G) / 255.0f, - static_cast(color.B) / 255.0f, - static_cast(color.A) / 255.0f); - winrt::check_hresult(d2dContext->CreateSolidColorBrush(d2dColor, brush.put())); - - d2dContext->DrawText( - args.text.data(), - args.text.size(), - textFormat.get(), - D2D1::RectF(0, 0, static_cast(sisWidth), static_cast(sisHeight)), - brush.get(), - D2D1_DRAW_TEXT_OPTIONS_ENABLE_COLOR_FONT); - - d2dContext->EndDraw(); - sisNative->EndDraw(); - } - - m_image.Source(imageSource); - // XAML will rescale, so we divide by scale here. - return Size{ static_cast(sisWidth / scale), static_cast(sisHeight / scale) }; - } - - void DirectWriteTextBlock::OnDependencyPropertyChanged(DependencyObject const& d, DependencyPropertyChangedEventArgs const& /* e */) - { - auto textBlockInstance{ d.try_as() }; - if (textBlockInstance) - { - textBlockInstance->InvalidateMeasure(); - } - } - - void DirectWriteTextBlock::OnInheritedDependencyPropertyChanged(DependencyObject const& d, DependencyProperty const& /* e */) - { - auto textBlockInstance{ d.try_as() }; - if (textBlockInstance) - { - textBlockInstance->InvalidateMeasure(); - } - } - - void DirectWriteTextBlock::OnDpiChanged(DisplayInformation const& /* displayInfo */, IInspectable const& /* obj */) - { - InvalidateMeasure(); - } -} diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock.h b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock.h deleted file mode 100644 index 3d1b7b183fe..00000000000 --- a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock.h +++ /dev/null @@ -1,106 +0,0 @@ -// Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license. -// See LICENSE in the project root for license information. - -#pragma once -#include -#include "DirectWriteTextBlock.g.h" -#include "DirectWriteResourceManager.h" -#include "DirectWriteRenderArgBuilder.h" - -namespace winrt::Microsoft_Toolkit_Uwp_UI_Controls_WinRT::implementation -{ -#define DEFINE_XAML_DEPENDENCY_PROPERTY(type, name, membername) \ - public: \ - type name() \ - { \ - return winrt::unbox_value(GetValue(membername)); \ - } \ - void name(type const& value) \ - { \ - SetValue(membername, winrt::box_value(value)); \ - } \ - static Windows::UI::Xaml::DependencyProperty name ## Property() \ - { \ - return membername; \ - } \ - private: \ - static Windows::UI::Xaml::DependencyProperty membername; \ - public: - - /// - /// This is a text block which uses DirectWrite to draw text onto a bitmap image, allowing the user to orient text vertically for - /// East Asian languages and to support text rendering modes which aren't supported by XAML yet, but are supported by DirectWrite. - /// - /// This is built using C++/WinRT and will require the 1803 Windows SDK to build and use at minumum. - /// - /// - /// The current XAML code gen for C++/WinRT is in preview and results in a compile error. Users will need to define their own - /// default style for this thing in their apps that use this. This currently only supports SolidColorBrush based Foregrounds - /// - /// Throwing out of this class will cause significant debuggability issues in C# consumers as they just get a "native exception was thrown." - /// Therefore, this class will attempt to recover from poor input like setting font size = 0. If something happens like a DWrite - /// method fails, that will throw an exception. - /// - struct DirectWriteTextBlock : DirectWriteTextBlockT - { - public: - DirectWriteTextBlock(); - virtual ~DirectWriteTextBlock(); - - // IClosable is here so that we can unsub from the inherited dependency properties. - virtual void Close(); - - // Note: DWrite actually supports a lot more rendering modes than XAML, but we're able to get most of what we want - // with just the XAML built in types. In the event we need more of the DWrite API surface, we would need - // to define our own enums which map to the DWrite enums. - - /// - /// The text to render - /// - DEFINE_XAML_DEPENDENCY_PROPERTY(winrt::hstring, Text, m_textProperty); - - /// - /// The locale of the text to show - /// - DEFINE_XAML_DEPENDENCY_PROPERTY(winrt::hstring, TextLocale, m_textLocaleProperty); - - /// - /// The orientation of the text. - /// - DEFINE_XAML_DEPENDENCY_PROPERTY(Windows::UI::Xaml::Controls::Orientation, TextOrientation, m_textOrientationProperty); - - /// - /// How the text is wrapped. To Wrap text, just set the Height or Width of this control. - /// - DEFINE_XAML_DEPENDENCY_PROPERTY(Windows::UI::Xaml::TextWrapping, TextWrap, m_textWrapProperty); - - public: - // These are the methods we're overriding from IFrameworkElementOverrides. - void OnApplyTemplate(); - Windows::Foundation::Size MeasureOverride(Windows::Foundation::Size const& availableSize); - - private: - static void OnDependencyPropertyChanged(Windows::UI::Xaml::DependencyObject const& d, Windows::UI::Xaml::DependencyPropertyChangedEventArgs const& e); - static void OnInheritedDependencyPropertyChanged(Windows::UI::Xaml::DependencyObject const& d, Windows::UI::Xaml::DependencyProperty const& e); - void OnDpiChanged(Windows::Graphics::Display::DisplayInformation const& displayInfo, Windows::Foundation::IInspectable const& obj); - Windows::Foundation::Size RenderText(DirectWriteTextRenderArgs const& args); - - winrt::event_token m_dpiChangedToken; - long long m_foregroundChangedToken = 0; - long long m_fontSizeChangedToken = 0; - long long m_fontFamilyChangedToken = 0; - long long m_flowDirectionChangedToken = 0; - long long m_fontStretchChangedToken = 0; - long long m_fontWeightChangedToken = 0; - long long m_fontStyleChangedToken = 0; - - Windows::UI::Xaml::Controls::Image m_image; - }; -} - -namespace winrt::Microsoft_Toolkit_Uwp_UI_Controls_WinRT::factory_implementation -{ - struct DirectWriteTextBlock : DirectWriteTextBlockT - { - }; -} diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock.idl b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock.idl deleted file mode 100644 index 5e2a4e01814..00000000000 --- a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock.idl +++ /dev/null @@ -1,20 +0,0 @@ -namespace Microsoft_Toolkit_Uwp_UI_Controls_WinRT -{ - [default_interface] - runtimeclass DirectWriteTextBlock : Windows.UI.Xaml.Controls.Control, Windows.Foundation.IClosable - { - DirectWriteTextBlock(); - - static Windows.UI.Xaml.DependencyProperty TextProperty{ get; }; - String Text; - - static Windows.UI.Xaml.DependencyProperty TextLocaleProperty{ get; }; - String TextLocale; - - static Windows.UI.Xaml.DependencyProperty TextOrientationProperty{ get; }; - Windows.UI.Xaml.Controls.Orientation TextOrientation; - - static Windows.UI.Xaml.DependencyProperty TextWrapProperty{ get; }; - Windows.UI.Xaml.TextWrapping TextWrap; - } -} diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock/DirectWriteRenderArgBuilder.cpp b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock/DirectWriteRenderArgBuilder.cpp new file mode 100644 index 00000000000..4c52f38466f --- /dev/null +++ b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock/DirectWriteRenderArgBuilder.cpp @@ -0,0 +1,298 @@ +#include "pch.h" +#include "DirectWriteRenderArgBuilder.h" +#include "DirectWriteResourceManager.h" +#include "UniversalWindowsAppPackageFontLoader\FontCollectionLoader.h" + +BEGIN_NAMESPACE_CONTROLS_WINRT + +using namespace Platform; +using namespace Windows::UI; +using namespace Windows::UI::Text; +using namespace Windows::UI::Xaml; +using namespace Windows::UI::Xaml::Controls; +using namespace Windows::UI::Xaml::Media; +using namespace Windows::Globalization; +using namespace Windows::Graphics::Display; +using namespace Windows::Foundation; + +DirectWriteRenderArgBuilder::DirectWriteRenderArgBuilder() +{ + // default values + m_builtArgs.availableHeight = 0; + m_builtArgs.availableWidth = 0; + m_builtArgs.flowDirection = DWRITE_FLOW_DIRECTION::DWRITE_FLOW_DIRECTION_LEFT_TO_RIGHT; + m_builtArgs.fontFamily = ref new String(L"Segoe UI"); + m_builtArgs.fontSize = 15; + m_builtArgs.fontStretch = DWRITE_FONT_STRETCH::DWRITE_FONT_STRETCH_NORMAL; + m_builtArgs.fontStyle = DWRITE_FONT_STYLE::DWRITE_FONT_STYLE_NORMAL; + m_builtArgs.fontWeight = DWRITE_FONT_WEIGHT::DWRITE_FONT_WEIGHT_NORMAL; + m_builtArgs.foregroundColor = Windows::UI::Colors::Black; + m_builtArgs.rawPixelsPerViewPixel = 1; + m_builtArgs.readingDirection = DWRITE_READING_DIRECTION::DWRITE_READING_DIRECTION_LEFT_TO_RIGHT; + m_builtArgs.textLocale = ref new String(L"en-US"); + m_builtArgs.textWrapping = DWRITE_WORD_WRAPPING::DWRITE_WORD_WRAPPING_NO_WRAP; + m_builtArgs.fontCollection = nullptr; +} + +void DirectWriteRenderArgBuilder::SetFontFamily(FontFamily^ fontFamily) +{ + String^ resultFontFamily; + + // try to get the FontFamily property first. + auto controlFontFamily = fontFamily; + if ((controlFontFamily != nullptr) && !controlFontFamily->Source->IsEmpty()) + { + // if there's something in the font family, use it. + resultFontFamily = controlFontFamily->Source; + } + + // if nothing was in the font family, try the XAML default value. + if (resultFontFamily->IsEmpty() && (controlFontFamily != nullptr)) + { + auto xamlDefault = FontFamily::XamlAutoFontFamily; + if ((xamlDefault != nullptr) && !xamlDefault->Source->IsEmpty()) + { + resultFontFamily = xamlDefault->Source; + } + } + + // if the xaml default failed for some reason, hardcode to Segoe UI as last fallback. + if (resultFontFamily->IsEmpty()) + { + resultFontFamily = L"Segoe UI"; + } + + m_builtArgs.fontFamily = resultFontFamily; + BuildFontCollection(resultFontFamily); +} + +void DirectWriteRenderArgBuilder::SetText(Platform::String^ text) +{ + m_builtArgs.text = text; +} + +void DirectWriteRenderArgBuilder::SetTextLocale(Platform::String^ textLocale) +{ + if (Language::IsWellFormed(textLocale)) + { + m_builtArgs.textLocale = textLocale; + } + else + { + // default to en-US. + m_builtArgs.textLocale = ref new String(L"en-US"); + } +} + +void DirectWriteRenderArgBuilder::SetForegroundBrush(Brush^ brush) +{ + auto solidColorBrush = dynamic_cast(brush); + if (solidColorBrush != nullptr) + { + m_builtArgs.foregroundColor = solidColorBrush->Color; + } + else + { + m_builtArgs.foregroundColor = Colors::Black; + } +} + +void DirectWriteRenderArgBuilder::SetFontStyle(FontStyle fontStyle) +{ + switch (fontStyle) + { + case FontStyle::Normal: __fallthrough; + default: + m_builtArgs.fontStyle = DWRITE_FONT_STYLE::DWRITE_FONT_STYLE_NORMAL; + break; + case FontStyle::Italic: + m_builtArgs.fontStyle = DWRITE_FONT_STYLE::DWRITE_FONT_STYLE_ITALIC; + break; + case FontStyle::Oblique: + m_builtArgs.fontStyle = DWRITE_FONT_STYLE::DWRITE_FONT_STYLE_OBLIQUE; + break; + } +} + +void DirectWriteRenderArgBuilder::SetFontStretch(FontStretch fontStretch) +{ + switch (fontStretch) + { + case FontStretch::Normal: __fallthrough; + default: + m_builtArgs.fontStretch = DWRITE_FONT_STRETCH::DWRITE_FONT_STRETCH_NORMAL; + break; + case FontStretch::Condensed: + m_builtArgs.fontStretch = DWRITE_FONT_STRETCH::DWRITE_FONT_STRETCH_CONDENSED; + break; + case FontStretch::Expanded: + m_builtArgs.fontStretch = DWRITE_FONT_STRETCH::DWRITE_FONT_STRETCH_EXPANDED; + break; + case FontStretch::ExtraCondensed: + m_builtArgs.fontStretch = DWRITE_FONT_STRETCH::DWRITE_FONT_STRETCH_EXTRA_CONDENSED; + break; + case FontStretch::ExtraExpanded: + m_builtArgs.fontStretch = DWRITE_FONT_STRETCH::DWRITE_FONT_STRETCH_EXTRA_EXPANDED; + break; + case FontStretch::SemiCondensed: + m_builtArgs.fontStretch = DWRITE_FONT_STRETCH::DWRITE_FONT_STRETCH_SEMI_CONDENSED; + break; + case FontStretch::SemiExpanded: + m_builtArgs.fontStretch = DWRITE_FONT_STRETCH::DWRITE_FONT_STRETCH_SEMI_EXPANDED; + break; + case FontStretch::UltraCondensed: + m_builtArgs.fontStretch = DWRITE_FONT_STRETCH::DWRITE_FONT_STRETCH_ULTRA_CONDENSED; + break; + case FontStretch::UltraExpanded: + m_builtArgs.fontStretch = DWRITE_FONT_STRETCH::DWRITE_FONT_STRETCH_ULTRA_EXPANDED; + break; + } +} + +void DirectWriteRenderArgBuilder::SetTextOrientation(Orientation textOrientation) +{ + switch (textOrientation) + { + case Orientation::Vertical: __fallthrough; + default: + m_builtArgs.readingDirection = DWRITE_READING_DIRECTION::DWRITE_READING_DIRECTION_TOP_TO_BOTTOM; + break; + case Orientation::Horizontal: + m_builtArgs.readingDirection = DWRITE_READING_DIRECTION::DWRITE_READING_DIRECTION_LEFT_TO_RIGHT; + break; + } +} + +void DirectWriteRenderArgBuilder::SetFlowDirection(FlowDirection flowDirection) +{ + switch (flowDirection) + { + case FlowDirection::LeftToRight: __fallthrough; + default: + m_builtArgs.flowDirection = DWRITE_FLOW_DIRECTION::DWRITE_FLOW_DIRECTION_LEFT_TO_RIGHT; + break; + case FlowDirection::RightToLeft: + m_builtArgs.flowDirection = DWRITE_FLOW_DIRECTION::DWRITE_FLOW_DIRECTION_RIGHT_TO_LEFT; + break; + } +} + +void DirectWriteRenderArgBuilder::SetFontWeight(FontWeight fontWeight) +{ + auto weight = fontWeight.Weight; + if (weight == FontWeights::Black.Weight) + { + m_builtArgs.fontWeight = DWRITE_FONT_WEIGHT::DWRITE_FONT_WEIGHT_BLACK; + } + else if (weight == FontWeights::Bold.Weight) + { + m_builtArgs.fontWeight = DWRITE_FONT_WEIGHT::DWRITE_FONT_WEIGHT_BOLD; + } + else if (weight == FontWeights::ExtraBlack.Weight) + { + m_builtArgs.fontWeight = DWRITE_FONT_WEIGHT::DWRITE_FONT_WEIGHT_EXTRA_BLACK; + } + else if (weight == FontWeights::ExtraBold.Weight) + { + m_builtArgs.fontWeight = DWRITE_FONT_WEIGHT::DWRITE_FONT_WEIGHT_EXTRA_BOLD; + } + else if (weight == FontWeights::ExtraLight.Weight) + { + m_builtArgs.fontWeight = DWRITE_FONT_WEIGHT::DWRITE_FONT_WEIGHT_EXTRA_LIGHT; + } + else if (weight == FontWeights::Light.Weight) + { + m_builtArgs.fontWeight = DWRITE_FONT_WEIGHT::DWRITE_FONT_WEIGHT_LIGHT; + } + else if (weight == FontWeights::SemiBold.Weight) + { + m_builtArgs.fontWeight = DWRITE_FONT_WEIGHT::DWRITE_FONT_WEIGHT_SEMI_BOLD; + } + else if (weight == FontWeights::SemiLight.Weight) + { + m_builtArgs.fontWeight = DWRITE_FONT_WEIGHT::DWRITE_FONT_WEIGHT_SEMI_LIGHT; + } + else + { + m_builtArgs.fontWeight = DWRITE_FONT_WEIGHT::DWRITE_FONT_WEIGHT_NORMAL; + } +} + +void DirectWriteRenderArgBuilder::SetTextWrapping(TextWrapping textWrapping) +{ + switch (textWrapping) + { + case TextWrapping::NoWrap: + default: + m_builtArgs.textWrapping = DWRITE_WORD_WRAPPING::DWRITE_WORD_WRAPPING_NO_WRAP; + break; + case TextWrapping::Wrap: + m_builtArgs.textWrapping = DWRITE_WORD_WRAPPING::DWRITE_WORD_WRAPPING_WRAP; + break; + case TextWrapping::WrapWholeWords: + m_builtArgs.textWrapping = DWRITE_WORD_WRAPPING::DWRITE_WORD_WRAPPING_WHOLE_WORD; + break; + } +} + +void DirectWriteRenderArgBuilder::SetFontSize(double fontSize) +{ + m_builtArgs.fontSize = static_cast(fontSize); + if (m_builtArgs.fontSize <= 0) + { + m_builtArgs.fontSize = 15.0f; + } +} + +void DirectWriteRenderArgBuilder::SetDPI(double rawPixelsPerViewPixel) +{ + m_builtArgs.rawPixelsPerViewPixel = static_cast(rawPixelsPerViewPixel); + if (m_builtArgs.rawPixelsPerViewPixel <= 0) + { + m_builtArgs.rawPixelsPerViewPixel = 1.0f; + } +} + +void DirectWriteRenderArgBuilder::SetAvailableWidth(float availableWidth) +{ + m_builtArgs.availableWidth = availableWidth; +} + +void DirectWriteRenderArgBuilder::SetAvailableHeight(float availableHeight) +{ + m_builtArgs.availableHeight = availableHeight; +} + +DirectWriteTextRenderArgs& DirectWriteRenderArgBuilder::BuildRenderArgs() +{ + return m_builtArgs; +} + +void DirectWriteRenderArgBuilder::BuildFontCollection(Platform::String^ fontFamily) +{ + // default arg is system font collection, what we're looking for is if we're trying to + // find a local custom ttf file. + if (UniversalWindowsAppPackageFontLoader::FontCollectionLoader::HasCustomFontFamily(fontFamily)) + { + auto resourceManager = DirectWriteResourceManager::GetInstance(); + auto dwriteFactory = resourceManager->GetDirectWriteFactoryNoRef(); + UniversalWindowsAppPackageFontLoader::UniversalPackageFontData parseData = {}; + UniversalWindowsAppPackageFontLoader::FontCollectionLoader::ParseXamlFontFamily(fontFamily, parseData); + auto customLoader = UniversalWindowsAppPackageFontLoader::FontCollectionLoader::GetInstance(); + + // the key is a void* meaning the size is actual size. + auto fontFamilyString = fontFamily->Data(); + auto fontFamilySize = fontFamily->Length() * sizeof(wchar_t); + dwriteFactory->CreateCustomFontCollection(customLoader.get(), fontFamilyString, fontFamilySize, m_builtArgs.fontCollection.put()); + + // set font family to the parsed font family. + m_builtArgs.fontFamily = ref new String(parseData.customFontName.data(), parseData.customFontName.size()); + } + else + { + // else assume it's a system font for now. We could do a lookup, but that would actually slow things down. + m_builtArgs.fontCollection = nullptr; + } +} + +END_NAMESPACE_CONTROLS_WINRT \ No newline at end of file diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock/DirectWriteRenderArgBuilder.h b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock/DirectWriteRenderArgBuilder.h new file mode 100644 index 00000000000..20661e93b0f --- /dev/null +++ b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock/DirectWriteRenderArgBuilder.h @@ -0,0 +1,120 @@ +#pragma once + +BEGIN_NAMESPACE_CONTROLS_WINRT + +/// +/// These are arguments which are used to render the DWrite string. +/// +struct DirectWriteTextRenderArgs +{ + Platform::String^ fontFamily; + Platform::String^ text; + Platform::String^ textLocale; + Windows::UI::Color foregroundColor; + DWRITE_FONT_STYLE fontStyle; + DWRITE_FONT_STRETCH fontStretch; + DWRITE_READING_DIRECTION readingDirection; + DWRITE_FLOW_DIRECTION flowDirection; + DWRITE_FONT_WEIGHT fontWeight; + DWRITE_WORD_WRAPPING textWrapping; + float fontSize; + float rawPixelsPerViewPixel; + float availableWidth; + float availableHeight; + winrt::com_ptr fontCollection; +}; + +/// +/// This class translates input from the XAML world into a DirectWriteTextRenderArgs struct +/// meant to be used with the DWrite world. If the user passes invalid values in, it attempts +/// to correct by setting them back to a known default value. This is because in case the user +/// is using the text block from C# (most users are expected to do this), a crash ultimately +/// just gives them a "something went wrong and a native exception was thrown" which is not +/// super helpful. Recovery will at least render something that looks incorrect on the screen. +/// +class DirectWriteRenderArgBuilder +{ +public: + DirectWriteRenderArgBuilder(); + + /// + /// The font family, by default Segoe UI + /// + void SetFontFamily(Windows::UI::Xaml::Media::FontFamily^ fontFamily); + + /// + /// The text to render, empty string by default. + /// + void SetText(Platform::String^ text); + + /// + /// The text locale for DWrite, en-US by default. + /// + void SetTextLocale(Platform::String^ textLocale); + + /// + /// The foreground brush, Black by default + /// + void SetForegroundBrush(Windows::UI::Xaml::Media::Brush^ brush); + + /// + /// The font style, Normal by default + /// + void SetFontStyle(Windows::UI::Text::FontStyle fontStyle); + + /// + /// The font stretch, normal by default + /// + void SetFontStretch(Windows::UI::Text::FontStretch fontStretch); + + /// + /// The text orientation, vertical by default since if you're going to use horizontal, you should use a XAML TextBlock + /// + void SetTextOrientation(Windows::UI::Xaml::Controls::Orientation textOrientation); + + /// + /// The flow direction, LeftToRight by default + /// + void SetFlowDirection(Windows::UI::Xaml::FlowDirection flowDirection); + + /// + /// The font weight, Normal by default + /// + void SetFontWeight(Windows::UI::Text::FontWeight fontWeight); + + /// + /// The font size, 15 by default. + /// + void SetFontSize(double fontSize); + + /// + /// The DPI to render at, 1 by default + /// + void SetDPI(double rawPixelsPerViewPixel); + + /// + /// The available width to render at + /// + void SetAvailableWidth(float availableWidth); + + /// + /// The available height to render at. + /// + void SetAvailableHeight(float availableHeight); + + /// + /// The text wrap mode, None by default. + /// + void SetTextWrapping(Windows::UI::Xaml::TextWrapping textWrapping); + + /// + /// The render arguments. + /// + DirectWriteTextRenderArgs& BuildRenderArgs(); + +private: + void BuildFontCollection(Platform::String^ fontFamily); + DirectWriteTextRenderArgs m_builtArgs = {}; +}; + +END_NAMESPACE_CONTROLS_WINRT \ No newline at end of file diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock/DirectWriteResourceManager.cpp b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock/DirectWriteResourceManager.cpp new file mode 100644 index 00000000000..54b31951e4b --- /dev/null +++ b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock/DirectWriteResourceManager.cpp @@ -0,0 +1,124 @@ +#include "pch.h" +#include "UniversalWindowsAppPackageFontLoader\FontCollectionLoader.h" +#include "DirectWriteResourceManager.h" + +BEGIN_NAMESPACE_CONTROLS_WINRT + +std::unique_ptr DirectWriteResourceManager::s_instance; + +DirectWriteResourceManager::DirectWriteResourceManager() +{ +} + +DirectWriteResourceManager::~DirectWriteResourceManager() +{ +} + +IDWriteFactory* DirectWriteResourceManager::GetDirectWriteFactoryNoRef() +{ + winrt::check_hresult(InitializeDeviceResources()); + return m_dwriteFactory.get(); +} + +ID3D11Device* DirectWriteResourceManager::GetD3dDeviceNoRef() +{ + winrt::check_hresult(InitializeDeviceResources()); + return m_d3dDevice.get(); +} + +ID2D1DeviceContext* DirectWriteResourceManager::GetD2dDCNoRef() +{ + winrt::check_hresult(InitializeDeviceResources()); + return m_d2dContext.get(); +} + +IDXGIDevice* DirectWriteResourceManager::GetDXGIDeviceNoRef() +{ + winrt::check_hresult(InitializeDeviceResources()); + return m_dxgiDevice.get(); +} + +HRESULT DirectWriteResourceManager::InitializeDeviceResources() +{ + if (!m_deviceResourcesInitialized) + { + UINT creationFlags = D3D11_CREATE_DEVICE_BGRA_SUPPORT; + D3D_FEATURE_LEVEL supportedFeatureLevel; + + D3D_FEATURE_LEVEL featureLevels[] = + { + D3D_FEATURE_LEVEL_11_1, + D3D_FEATURE_LEVEL_11_0, + D3D_FEATURE_LEVEL_10_1, + D3D_FEATURE_LEVEL_10_0, + D3D_FEATURE_LEVEL_9_3, + D3D_FEATURE_LEVEL_9_2, + D3D_FEATURE_LEVEL_9_1 + }; + + HRESULT hr = D3D11CreateDevice( + nullptr, // Specify nullptr to use the default adapter. + D3D_DRIVER_TYPE_HARDWARE, // Create a device using the hardware graphics driver. + 0, // Should be 0 unless the driver is D3D_DRIVER_TYPE_SOFTWARE. + creationFlags, // Set debug and Direct2D compatibility flags. + featureLevels, // List of feature levels this app can support. + ARRAYSIZE(featureLevels), + D3D11_SDK_VERSION, // Always set this to D3D11_SDK_VERSION for Windows Store apps. + m_d3dDevice.put(), // Returns the Direct3D device created. + &supportedFeatureLevel, + nullptr + ); + + // log failures on the initial creation + if (FAILED(hr)) + { + // If the initialization fails, fall back to the WARP device. + winrt::check_hresult(D3D11CreateDevice( + nullptr, + D3D_DRIVER_TYPE_WARP, // Create a WARP device instead of a hardware device. + 0, + creationFlags, + featureLevels, + ARRAYSIZE(featureLevels), + D3D11_SDK_VERSION, + m_d3dDevice.put(), + &supportedFeatureLevel, + nullptr + )); + } + + // Get the Direct3D 11.1 API device. + m_d3dDevice.as(m_dxgiDevice); + winrt::check_hresult(D2D1CreateDevice(m_dxgiDevice.get(), nullptr, m_d2dDevice.put())); + + winrt::check_hresult(m_d2dDevice->CreateDeviceContext( + D2D1_DEVICE_CONTEXT_OPTIONS_NONE, + m_d2dContext.put() + )); + + winrt::check_hresult(DWriteCreateFactory( + DWRITE_FACTORY_TYPE_SHARED, + __uuidof(IDWriteFactory), + reinterpret_cast(m_dwriteFactory.put()) + )); + + auto customLoader = UniversalWindowsAppPackageFontLoader::FontCollectionLoader::GetInstance(); + m_dwriteFactory->RegisterFontCollectionLoader(customLoader.get()); + + m_deviceResourcesInitialized = true; + } + + return S_OK; +} + +DirectWriteResourceManager* DirectWriteResourceManager::GetInstance() +{ + if (s_instance == nullptr) + { + s_instance.reset(new DirectWriteResourceManager()); + } + + return s_instance.get(); +} + +END_NAMESPACE_CONTROLS_WINRT \ No newline at end of file diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock/DirectWriteResourceManager.h b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock/DirectWriteResourceManager.h new file mode 100644 index 00000000000..8281247b8de --- /dev/null +++ b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock/DirectWriteResourceManager.h @@ -0,0 +1,55 @@ +#pragma once + +BEGIN_NAMESPACE_CONTROLS_WINRT + +/// +/// This manages D3D/DWrite resources and prevents reinitialization. +/// +class DirectWriteResourceManager +{ +public: + DirectWriteResourceManager(); + virtual ~DirectWriteResourceManager(); + + /// + /// This is a singleton to prevent reintializing D3D + /// + static DirectWriteResourceManager* GetInstance(); + + /// + /// The DWrite Factory, caller doesn't take a reference. + /// + IDWriteFactory* GetDirectWriteFactoryNoRef(); + + /// + /// The D3D Device, caller doesn't take a reference. + /// + ID3D11Device* GetD3dDeviceNoRef(); + + /// + /// The D2D Device, caller doesn't take a reference. + /// + ID2D1DeviceContext* GetD2dDCNoRef(); + + /// + /// The DXGI Device, caller doesn't take a reference. + /// + IDXGIDevice* GetDXGIDeviceNoRef(); + + /// + /// Initializes the device resources. + /// + HRESULT InitializeDeviceResources(); + +private: + winrt::com_ptr m_dwriteFactory; + winrt::com_ptr m_d3dDevice; + winrt::com_ptr m_d2dDevice; + winrt::com_ptr m_d2dContext; + winrt::com_ptr m_dxgiDevice; + + static std::unique_ptr s_instance; + bool m_deviceResourcesInitialized = false; +}; + +END_NAMESPACE_CONTROLS_WINRT \ No newline at end of file diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock/DirectWriteTextBlock.cpp b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock/DirectWriteTextBlock.cpp new file mode 100644 index 00000000000..8186c06074d --- /dev/null +++ b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock/DirectWriteTextBlock.cpp @@ -0,0 +1,270 @@ +// Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license. +// See LICENSE in the project root for license information. + +#include "pch.h" +#include "DirectWriteTextBlock.h" +#include + +BEGIN_NAMESPACE_CONTROLS_WINRT + +using namespace Platform; +using namespace Windows::Foundation; +using namespace Windows::Foundation::Collections; +using namespace Windows::Graphics::Display; +using namespace Windows::UI::Xaml; +using namespace Windows::UI::Xaml::Controls; +using namespace Windows::UI::Xaml::Data; +using namespace Windows::UI::Xaml::Documents; +using namespace Windows::UI::Xaml::Input; +using namespace Windows::UI::Xaml::Interop; +using namespace Windows::UI::Xaml::Media; +using namespace Windows::UI::Xaml::Media::Imaging; + +DependencyProperty^ DirectWriteTextBlock::m_textProperty = DependencyProperty::Register( + L"Text", + Platform::String::typeid, + DirectWriteTextBlock::typeid, + ref new PropertyMetadata(L"", ref new PropertyChangedCallback(&DirectWriteTextBlock::OnDependencyPropertyChanged))); + +DependencyProperty^ DirectWriteTextBlock::m_textLocaleProperty = DependencyProperty::Register( + L"TextLocale", + Platform::String::typeid, + DirectWriteTextBlock::typeid, + ref new PropertyMetadata(L"en-US", ref new PropertyChangedCallback(&DirectWriteTextBlock::OnDependencyPropertyChanged))); + +DependencyProperty^ DirectWriteTextBlock::m_textOrientationProperty = DependencyProperty::Register( + L"TextOrientation", + Windows::UI::Xaml::Controls::Orientation::typeid, + DirectWriteTextBlock::typeid, + ref new PropertyMetadata(Windows::UI::Xaml::Controls::Orientation::Vertical, ref new PropertyChangedCallback(&DirectWriteTextBlock::OnDependencyPropertyChanged))); + +DependencyProperty^ DirectWriteTextBlock::m_textWrapProperty = DependencyProperty::Register( + L"TextWrap", + Windows::UI::Xaml::TextWrapping::typeid, + DirectWriteTextBlock::typeid, + ref new PropertyMetadata(Windows::UI::Xaml::TextWrapping::NoWrap, ref new PropertyChangedCallback(&DirectWriteTextBlock::OnDependencyPropertyChanged))); + +DirectWriteTextBlock::DirectWriteTextBlock() +{ + DefaultStyleKey = "Microsoft.Toolkit.Uwp.UI.Controls.WinRT.DirectWriteTextBlock"; + + auto displayInfo = DisplayInformation::GetForCurrentView(); + m_dpiChangedToken = displayInfo->DpiChanged += ref new TypedEventHandler(this, &DirectWriteTextBlock::OnDpiChanged); + +#define REGISTER_INHERITED_PROPERTY_CALLBACK(token, inheritedProperty) \ + token = RegisterPropertyChangedCallback(inheritedProperty, ref new DependencyPropertyChangedCallback(&DirectWriteTextBlock::OnInheritedDependencyPropertyChanged)) + + REGISTER_INHERITED_PROPERTY_CALLBACK(m_flowDirectionChangedToken, FlowDirectionProperty); + REGISTER_INHERITED_PROPERTY_CALLBACK(m_foregroundChangedToken, ForegroundProperty); + REGISTER_INHERITED_PROPERTY_CALLBACK(m_fontSizeChangedToken, FontSizeProperty); + REGISTER_INHERITED_PROPERTY_CALLBACK(m_fontFamilyChangedToken, FontFamilyProperty); + REGISTER_INHERITED_PROPERTY_CALLBACK(m_fontStretchChangedToken, FontStretchProperty); + REGISTER_INHERITED_PROPERTY_CALLBACK(m_fontStyleChangedToken, FontStyleProperty); + REGISTER_INHERITED_PROPERTY_CALLBACK(m_fontWeightChangedToken, FontWeightProperty); +#undef REGISTER_INHERITED_PROPERTY_CALLBACK +} + +DirectWriteTextBlock::~DirectWriteTextBlock() +{ + Close(); +} + +void DirectWriteTextBlock::OnApplyTemplate() +{ + // make XAML apply the template first + __super::OnApplyTemplate(); + + auto maybeImage = dynamic_cast(GetTemplateChild(L"Image")); + if (maybeImage == nullptr) + { + winrt::throw_hresult(E_NOT_VALID_STATE); + } + + m_image = maybeImage; +} + +Size DirectWriteTextBlock::MeasureOverride(Size availableSize) +{ + auto displayInfo = DisplayInformation::GetForCurrentView(); + DirectWriteRenderArgBuilder builder; + builder.SetAvailableHeight(availableSize.Height); + builder.SetAvailableWidth(availableSize.Width); + builder.SetDPI(displayInfo->RawPixelsPerViewPixel); + builder.SetFlowDirection(FlowDirection); + builder.SetFontFamily(FontFamily); + builder.SetFontSize(FontSize); + builder.SetFontStretch(FontStretch); + builder.SetFontStyle(FontStyle); + builder.SetFontWeight(FontWeight); + builder.SetForegroundBrush(Foreground); + builder.SetText(Text); + builder.SetTextLocale(TextLocale); + builder.SetTextOrientation(TextOrientation); + builder.SetTextWrapping(TextWrap); + + auto args = builder.BuildRenderArgs(); + return RenderText(args); +} + +void DirectWriteTextBlock::Close() +{ + +#define UNREGISTER_INHERITED_PROPERTY_CALLBACK(token, inheritedProperty) \ + if (token != 0) \ + { \ + UnregisterPropertyChangedCallback(inheritedProperty, token); \ + token = 0; \ + } + + UNREGISTER_INHERITED_PROPERTY_CALLBACK(m_flowDirectionChangedToken, FlowDirectionProperty); + UNREGISTER_INHERITED_PROPERTY_CALLBACK(m_foregroundChangedToken, ForegroundProperty); + UNREGISTER_INHERITED_PROPERTY_CALLBACK(m_fontSizeChangedToken, FontSizeProperty); + UNREGISTER_INHERITED_PROPERTY_CALLBACK(m_fontFamilyChangedToken, FontFamilyProperty); + UNREGISTER_INHERITED_PROPERTY_CALLBACK(m_fontStretchChangedToken, FontStretchProperty); + UNREGISTER_INHERITED_PROPERTY_CALLBACK(m_fontStyleChangedToken, FontStyleProperty); + UNREGISTER_INHERITED_PROPERTY_CALLBACK(m_fontWeightChangedToken, FontWeightProperty); + + if (m_dpiChangedToken.Value != 0) + { + auto displayInfo = DisplayInformation::GetForCurrentView(); + displayInfo->DpiChanged -= m_dpiChangedToken; + m_dpiChangedToken = {}; + } + +#undef UNREGISTER_INHERITED_PROPERTY_CALLBACK +} + +Size DirectWriteTextBlock::RenderText(DirectWriteTextRenderArgs const& args) +{ + if (args.text->IsEmpty()) + { + return Size{ 0, 0 }; + } + + auto resourceManager = DirectWriteResourceManager::GetInstance(); + auto scale = args.rawPixelsPerViewPixel; + auto scaledFontSize = args.fontSize * scale; + auto dwriteFactory = resourceManager->GetDirectWriteFactoryNoRef(); + + winrt::com_ptr textFormat; + winrt::check_hresult(dwriteFactory->CreateTextFormat( + args.fontFamily->Data(), + args.fontCollection.get(), + args.fontWeight, + args.fontStyle, + args.fontStretch, + scaledFontSize, + args.textLocale->Data(), + textFormat.put())); + + textFormat->SetWordWrapping(args.textWrapping); + + // Trying to set readingDirection + FlowDirection to LEFT_TO_RIGHT will result in + // a failed HRESULT From DWRITE. Since the defaults work fine for horizontal, only + // set these values for text orientation = vertical. + if (this->TextOrientation == Orientation::Vertical) + { + textFormat->SetReadingDirection(args.readingDirection); + textFormat->SetFlowDirection(args.flowDirection); + } + + winrt::com_ptr textLayout; + winrt::check_hresult(dwriteFactory->CreateTextLayout( + args.text->Data(), + args.text->Length(), + textFormat.get(), + args.availableWidth, + args.availableHeight, + textLayout.put())); + + DWRITE_TEXT_METRICS textMetrics = {}; + winrt::check_hresult(textLayout->GetMetrics(&textMetrics)); + + auto sisWidth = static_cast(std::ceil(textMetrics.width)); + auto sisHeight = static_cast(std::ceil(textMetrics.height)); + auto imageSource = ref new SurfaceImageSource(sisWidth, sisHeight); + auto sisUnknown = reinterpret_cast(imageSource); + winrt::com_ptr sisNative; + sisUnknown->QueryInterface(__uuidof(ISurfaceImageSourceNative), sisNative.put_void()); + sisNative->SetDevice(resourceManager->GetDXGIDeviceNoRef()); + + winrt::com_ptr surface; + RECT updateRect = { 0, 0, static_cast(sisWidth), static_cast(sisHeight) }; + POINT offset = { 0, 0 }; + if (SUCCEEDED(sisNative->BeginDraw(updateRect, surface.put(), &offset))) + { + auto d2dContext = resourceManager->GetD2dDCNoRef(); + + // set the translation to the section of the bitmap that we want to render. + auto translate = D2D1::Matrix3x2F::Translation(static_cast(offset.x), static_cast(offset.y)); + d2dContext->SetTransform(translate); + + // this basically ensures the text background is transparent. + D2D1_BITMAP_PROPERTIES1 bitmapProperties = + { + { DXGI_FORMAT_UNKNOWN, D2D1_ALPHA_MODE_PREMULTIPLIED }, + 96.f * scale, + 96.f * scale, + D2D1_BITMAP_OPTIONS_TARGET | D2D1_BITMAP_OPTIONS_CANNOT_DRAW + }; + + winrt::com_ptr bitmap; + winrt::check_hresult(d2dContext->CreateBitmapFromDxgiSurface( + surface.get(), + &bitmapProperties, + bitmap.put())); + + d2dContext->SetTarget(bitmap.get()); + d2dContext->BeginDraw(); + d2dContext->Clear(); + + winrt::com_ptr brush; + auto color = args.foregroundColor; + D2D1_COLOR_F d2dColor = D2D1::ColorF( + static_cast(color.R) / 255.0f, + static_cast(color.G) / 255.0f, + static_cast(color.B) / 255.0f, + static_cast(color.A) / 255.0f); + winrt::check_hresult(d2dContext->CreateSolidColorBrush(d2dColor, brush.put())); + + d2dContext->DrawText( + args.text->Data(), + args.text->Length(), + textFormat.get(), + D2D1::RectF(0, 0, static_cast(sisWidth), static_cast(sisHeight)), + brush.get(), + D2D1_DRAW_TEXT_OPTIONS_ENABLE_COLOR_FONT); + + d2dContext->EndDraw(); + sisNative->EndDraw(); + } + + m_image->Source = imageSource; + // XAML will rescale, so we divide by scale here. + return Size{ static_cast(sisWidth / scale), static_cast(sisHeight / scale) }; +} + +void DirectWriteTextBlock::OnDependencyPropertyChanged(DependencyObject^ d, DependencyPropertyChangedEventArgs^ /* e */) +{ + auto textBlockInstance = dynamic_cast(d); + if (textBlockInstance) + { + textBlockInstance->InvalidateMeasure(); + } +} + +void DirectWriteTextBlock::OnInheritedDependencyPropertyChanged(DependencyObject^ d, DependencyProperty^ /* e */) +{ + auto textBlockInstance = dynamic_cast(d); + if (textBlockInstance) + { + textBlockInstance->InvalidateMeasure(); + } +} + +void DirectWriteTextBlock::OnDpiChanged(DisplayInformation^ /* displayInfo */, Object^ /* obj */) +{ + InvalidateMeasure(); +} + +END_NAMESPACE_CONTROLS_WINRT \ No newline at end of file diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock/DirectWriteTextBlock.h b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock/DirectWriteTextBlock.h new file mode 100644 index 00000000000..5373f40c185 --- /dev/null +++ b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock/DirectWriteTextBlock.h @@ -0,0 +1,104 @@ +// Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license. +// See LICENSE in the project root for license information. + +#pragma once + +#include "DirectWriteResourceManager.h" +#include "DirectWriteRenderArgBuilder.h" + +BEGIN_NAMESPACE_CONTROLS_WINRT + +#define DEFINE_XAML_DEPENDENCY_PROPERTY(type, name, membername) \ + public: \ + property type name \ + { \ + type get() \ + { \ + return (type)GetValue(membername); \ + } \ + void set(type value) \ + { \ + SetValue(membername, value); \ + } \ + } \ + static property Windows::UI::Xaml::DependencyProperty^ name ## Property \ + { \ + Windows::UI::Xaml::DependencyProperty^ get() \ + { \ + return membername; \ + } \ + } \ + private: \ + static Windows::UI::Xaml::DependencyProperty^ membername; \ + public: + +/// +/// This is a text block which uses DirectWrite to draw text onto a bitmap image, allowing the user to orient text vertically for +/// East Asian languages and to support text rendering modes which aren't supported by XAML yet, but are supported by DirectWrite. +/// +/// Parts of this are built using C++/WinRT and will require the 1803 Windows SDK to build and use at minumum. +/// +/// +/// The current XAML code gen for C++/WinRT is in preview and results in a compile error so the main project class is C++/CX to get around +/// that limitation. +/// +/// Throwing out of this class will cause significant debuggability issues in C# consumers as they just get a "native exception was thrown." +/// Therefore, this class will attempt to recover from poor input like setting font size = 0. If something happens like a DWrite +/// method fails, that will throw an exception. +/// +[Windows::Foundation::Metadata::WebHostHidden] +public ref class DirectWriteTextBlock sealed : public Windows::UI::Xaml::Controls::Control +{ +public: + DirectWriteTextBlock(); + virtual ~DirectWriteTextBlock(); + + // Note: DWrite actually supports a lot more rendering modes than XAML, but we're able to get most of what we want + // with just the XAML built in types. In the event we need more of the DWrite API surface, we would need + // to define our own enums which map to the DWrite enums. + + /// + /// The text to render + /// + DEFINE_XAML_DEPENDENCY_PROPERTY(Platform::String^, Text, m_textProperty); + + /// + /// The locale of the text to show + /// + DEFINE_XAML_DEPENDENCY_PROPERTY(Platform::String^, TextLocale, m_textLocaleProperty); + + /// + /// The orientation of the text. + /// + DEFINE_XAML_DEPENDENCY_PROPERTY(Windows::UI::Xaml::Controls::Orientation, TextOrientation, m_textOrientationProperty); + + /// + /// How the text is wrapped. To Wrap text, just set the Height or Width of this control. + /// + DEFINE_XAML_DEPENDENCY_PROPERTY(Windows::UI::Xaml::TextWrapping, TextWrap, m_textWrapProperty); + +protected: + // These are the methods we're overriding from IFrameworkElementOverrides. + void OnApplyTemplate() override; + Windows::Foundation::Size MeasureOverride(Windows::Foundation::Size availableSize) override; + +private: + static void OnDependencyPropertyChanged(Windows::UI::Xaml::DependencyObject^ d, Windows::UI::Xaml::DependencyPropertyChangedEventArgs^ e); + static void OnInheritedDependencyPropertyChanged(Windows::UI::Xaml::DependencyObject^ d, Windows::UI::Xaml::DependencyProperty^ e); + void OnDpiChanged(Windows::Graphics::Display::DisplayInformation^ displayInfo, Platform::Object^ obj); + Windows::Foundation::Size RenderText(DirectWriteTextRenderArgs const& args); + void Close(); + + Windows::Foundation::EventRegistrationToken m_dpiChangedToken = {}; + long long m_foregroundChangedToken = 0; + long long m_fontSizeChangedToken = 0; + long long m_fontFamilyChangedToken = 0; + long long m_flowDirectionChangedToken = 0; + long long m_fontStretchChangedToken = 0; + long long m_fontWeightChangedToken = 0; + long long m_fontStyleChangedToken = 0; + + Windows::UI::Xaml::Controls::Image^ m_image; +}; + +END_NAMESPACE_CONTROLS_WINRT diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Generated Files/Generated Files/Generated Files/Generated Files/Generated Files/Themes/Generic.g.h b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Generated Files/Generated Files/Generated Files/Generated Files/Generated Files/Themes/Generic.g.h new file mode 100644 index 00000000000..30259b2af6f --- /dev/null +++ b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Generated Files/Generated Files/Generated Files/Generated Files/Generated Files/Themes/Generic.g.h @@ -0,0 +1 @@ + diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Generated Files/Generated Files/Generated Files/Generated Files/Themes/Generic.g.h b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Generated Files/Generated Files/Generated Files/Generated Files/Themes/Generic.g.h new file mode 100644 index 00000000000..30259b2af6f --- /dev/null +++ b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Generated Files/Generated Files/Generated Files/Generated Files/Themes/Generic.g.h @@ -0,0 +1 @@ + diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Generated Files/Generated Files/Generated Files/Generated Files/Themes/Generic.g.hpp b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Generated Files/Generated Files/Generated Files/Generated Files/Themes/Generic.g.hpp new file mode 100644 index 00000000000..30259b2af6f --- /dev/null +++ b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Generated Files/Generated Files/Generated Files/Generated Files/Themes/Generic.g.hpp @@ -0,0 +1 @@ + diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Generated Files/Generated Files/Generated Files/Themes/Generic.g.h b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Generated Files/Generated Files/Generated Files/Themes/Generic.g.h new file mode 100644 index 00000000000..30259b2af6f --- /dev/null +++ b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Generated Files/Generated Files/Generated Files/Themes/Generic.g.h @@ -0,0 +1 @@ + diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Generated Files/Generated Files/Generated Files/Themes/Generic.g.hpp b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Generated Files/Generated Files/Generated Files/Themes/Generic.g.hpp new file mode 100644 index 00000000000..30259b2af6f --- /dev/null +++ b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Generated Files/Generated Files/Generated Files/Themes/Generic.g.hpp @@ -0,0 +1 @@ + diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Generated Files/Generated Files/Themes/Generic.g.h b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Generated Files/Generated Files/Themes/Generic.g.h new file mode 100644 index 00000000000..30259b2af6f --- /dev/null +++ b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Generated Files/Generated Files/Themes/Generic.g.h @@ -0,0 +1 @@ + diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Generated Files/Generated Files/Themes/Generic.g.hpp b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Generated Files/Generated Files/Themes/Generic.g.hpp new file mode 100644 index 00000000000..30259b2af6f --- /dev/null +++ b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Generated Files/Generated Files/Themes/Generic.g.hpp @@ -0,0 +1 @@ + diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Generated Files/Themes/Generic.g.h b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Generated Files/Themes/Generic.g.h new file mode 100644 index 00000000000..30259b2af6f --- /dev/null +++ b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Generated Files/Themes/Generic.g.h @@ -0,0 +1 @@ + diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Generated Files/Themes/Generic.g.hpp b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Generated Files/Themes/Generic.g.hpp new file mode 100644 index 00000000000..30259b2af6f --- /dev/null +++ b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Generated Files/Themes/Generic.g.hpp @@ -0,0 +1 @@ + diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Generated Files/Themes/Generic.xaml b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Generated Files/Themes/Generic.xaml new file mode 100644 index 00000000000..61c54a016a6 --- /dev/null +++ b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Generated Files/Themes/Generic.xaml @@ -0,0 +1,29 @@ + + + + + + diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Generated Files/Themes/Generic.xbf b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Generated Files/Themes/Generic.xbf new file mode 100644 index 0000000000000000000000000000000000000000..49ec1d4b6f4933e522a1deaed284638c67a65134 GIT binary patch literal 1205 zcmcIjOK%cU6#f{PVG4!PW)ex8HV|tuv5zUl2Gp3eP?9EA6I+W57t(g5O&>#m26Qzu zOBcF!)4$@%f8dUl8~=h^zjFccwbXla=Dff2n3?BWRa}RGcnHt{kfBGCb4a_K%OQU= z5hDfWqNkt)<>x+7-SC<%%~ufzE}*dnq^-x(v5q&>VQibPxxeSme$ zh%T)_j`Xj4oc*n;Oe8(EeyKj{ckBfs%pBPPo!Sn&u5*(PWmDlg)LiNr?rnz_gY;OT zOXT@5ZiFKHsdKyIxUpr5)=}IOwZ}id7O8o_YAtS1zQ#d?*iV^{SbJcX9;IhNSz&j3 zl;!UdlF5Y2k(iMz`tYav!Nn(k=E(k@@-^ub=`-moX@utJ%x12i`s@4f1o1Mc3@>EvQZ;8p}~qI&CJ6?^L}Wt@9PGvlt1^y*Q3a0`o8ti wn{W8Q^p(fVY_#udm`sOK8-}rvFmt9hV^#fxZen&fh<{MvSu7ufF(1LgcY{*0f&c&j literal 0 HcmV?d00001 diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Generated Files/XamlBindingInfo.g.h b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Generated Files/XamlBindingInfo.g.h new file mode 100644 index 00000000000..1fb2525387e --- /dev/null +++ b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Generated Files/XamlBindingInfo.g.h @@ -0,0 +1,265 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ +#pragma once + +namespace XamlBindingInfo +{ + ref class XamlBindings; + + class IXamlBindings + { + public: + virtual ~IXamlBindings() {}; + virtual bool IsInitialized() = 0; + virtual void Update() = 0; + virtual bool SetDataRoot(::Platform::Object^ data) = 0; + virtual void StopTracking() = 0; + virtual void Connect(int connectionId, ::Platform::Object^ target) = 0; + virtual void Recycle() = 0; + virtual void ProcessBindings(::Platform::Object^ item, int itemIndex, int phase, int* nextPhase) = 0; + virtual void SubscribeForDataContextChanged(::Windows::UI::Xaml::FrameworkElement^ object, ::XamlBindingInfo::XamlBindings^ handler) = 0; + virtual void DisconnectUnloadedObject(int connectionId) = 0; + }; + + class IXamlBindingTracking + { + public: + virtual void PropertyChanged(Platform::Object^ sender, ::Windows::UI::Xaml::Data::PropertyChangedEventArgs^ e) = 0; + virtual void CollectionChanged(::Platform::Object^ sender, ::Windows::UI::Xaml::Interop::NotifyCollectionChangedEventArgs^ e) = 0; + virtual void DependencyPropertyChanged(::Windows::UI::Xaml::DependencyObject^ sender, Windows::UI::Xaml::DependencyProperty^ prop) = 0; + virtual void VectorChanged(::Platform::Object^ sender, ::Windows::Foundation::Collections::IVectorChangedEventArgs^ e) = 0; + virtual void MapChanged(::Platform::Object^ sender, ::Windows::Foundation::Collections::IMapChangedEventArgs<::Platform::String^>^ e) = 0; + }; + + ref class XamlBindings sealed : + ::Windows::UI::Xaml::IDataTemplateExtension, + ::Windows::UI::Xaml::Markup::IComponentConnector, + ::Windows::UI::Xaml::Markup::IDataTemplateComponent + { + internal: + XamlBindings(::XamlBindingInfo::IXamlBindings* pBindings); + void Initialize(); + void Update(); + void StopTracking(); + void Loading(::Windows::UI::Xaml::FrameworkElement^ src, ::Platform::Object^ data); + void DataContextChanged(::Windows::UI::Xaml::FrameworkElement^ sender, ::Windows::UI::Xaml::DataContextChangedEventArgs^ args); + void SubscribeForDataContextChanged(::Windows::UI::Xaml::FrameworkElement^ object); + + public: + // IComponentConnector + virtual void Connect(int connectionId, ::Platform::Object^ target); + + // IDataTemplateComponent + virtual void ProcessBindings(::Platform::Object^ item, int itemIndex, int phase, int* nextPhase); + virtual void Recycle(); + + // IDataTemplateExtension + virtual bool ProcessBinding(unsigned int); + virtual int ProcessBindings(::Windows::UI::Xaml::Controls::ContainerContentChangingEventArgs^ args); + virtual void ResetTemplate(); + + virtual void DisconnectUnloadedObject(int connectionId); + private: + ~XamlBindings(); + ::XamlBindingInfo::IXamlBindings* _pBindings = nullptr; + }; + + template + class XamlBindingsBase : public IXamlBindings + { + protected: + bool _isInitialized; + TBindingsTracking^ _bindingsTracking; + ::Windows::Foundation::EventRegistrationToken _dataContextChangedToken; + static const int NOT_PHASED = (1 << 31); + static const int DATA_CHANGED = (1 << 30); + + protected: + XamlBindingsBase() + : _isInitialized(false) + , _bindingsTracking(nullptr) + { + _dataContextChangedToken.Value = 0; + } + + virtual ~XamlBindingsBase() + { + if (_bindingsTracking != nullptr) + { + _bindingsTracking->SetListener(nullptr); + _bindingsTracking = nullptr; + } + } + + virtual void ReleaseAllListeners() + { + // Overridden in the binding class as needed. + } + + public: + void InitializeTracking(::XamlBindingInfo::IXamlBindingTracking* pBindingsTracking) + { + _bindingsTracking = ref new TBindingsTracking(); + _bindingsTracking->SetListener(pBindingsTracking); + } + + virtual void StopTracking() override + { + ReleaseAllListeners(); + this->_isInitialized = false; + } + + virtual bool IsInitialized() override + { + return this->_isInitialized; + } + + virtual void Update() = 0; + + void SubscribeForDataContextChanged(::Windows::UI::Xaml::FrameworkElement^ object, ::XamlBindingInfo::XamlBindings^ handler) + { + this->_dataContextChangedToken = object->DataContextChanged += + ref new Windows::Foundation::TypedEventHandler<::Windows::UI::Xaml::FrameworkElement^, ::Windows::UI::Xaml::DataContextChangedEventArgs^>( + handler, &::XamlBindingInfo::XamlBindings::DataContextChanged); + } + + virtual void Connect(int connectionId, ::Platform::Object^ target) = 0; + + virtual void Recycle() + { + // Overridden in the binding class as needed. + } + + virtual void ProcessBindings(::Platform::Object^, int, int, int* nextPhase) + { + // Overridden in the binding class as needed. + *nextPhase = -1; + } + }; + + ref class XamlBindingTrackingBase + { + internal: + XamlBindingTrackingBase(); + void SetListener(::XamlBindingInfo::IXamlBindingTracking* pBindings); + + // Event handlers + void PropertyChanged(Platform::Object^ sender, ::Windows::UI::Xaml::Data::PropertyChangedEventArgs^ e); + void CollectionChanged(::Platform::Object^ sender, ::Windows::UI::Xaml::Interop::NotifyCollectionChangedEventArgs^ e); + void DependencyPropertyChanged(::Windows::UI::Xaml::DependencyObject^ sender, Windows::UI::Xaml::DependencyProperty^ prop); + void VectorChanged(::Platform::Object^ sender, ::Windows::Foundation::Collections::IVectorChangedEventArgs^ e); + void MapChanged(::Platform::Object^ sender, ::Windows::Foundation::Collections::IMapChangedEventArgs<::Platform::String^>^ e); + + // Listener update functions + void UpdatePropertyChangedListener(::Windows::UI::Xaml::Data::INotifyPropertyChanged^ obj, ::Windows::UI::Xaml::Data::INotifyPropertyChanged^* pCache, ::Windows::Foundation::EventRegistrationToken* pToken); + void UpdatePropertyChangedListener(::Windows::UI::Xaml::Data::INotifyPropertyChanged^ obj, ::Platform::WeakReference& cacheRef, ::Windows::Foundation::EventRegistrationToken* pToken); + void UpdateCollectionChangedListener(::Windows::UI::Xaml::Interop::INotifyCollectionChanged^ obj, ::Windows::UI::Xaml::Interop::INotifyCollectionChanged^* pCache, ::Windows::Foundation::EventRegistrationToken* pToken); + void UpdateDependencyPropertyChangedListener(::Windows::UI::Xaml::DependencyObject^ obj, Windows::UI::Xaml::DependencyProperty^ property, ::Windows::UI::Xaml::DependencyObject^* pCache, __int64* pToken); + void UpdateDependencyPropertyChangedListener(::Windows::UI::Xaml::DependencyObject^ obj, Windows::UI::Xaml::DependencyProperty^ property, ::Platform::WeakReference& cacheRef, __int64* pToken); + + private: + ::XamlBindingInfo::IXamlBindingTracking* _pBindingsTrackingWeakRef = nullptr; + }; + + template + struct ResolveHelper + { + static T^ Resolve(const ::Platform::WeakReference& wr) + { + return wr.Resolve(); + } + }; + + template <> + struct ResolveHelper<::Platform::String> + { + typedef ::Platform::IBox<::Platform::String^> ResolveType; + + static ::Platform::String^ Resolve(const ::Platform::WeakReference& wr) + { + return safe_cast<::Platform::String^>(wr.Resolve()); + } + + }; + + template + class ReferenceTypeXamlBindings : public XamlBindingsBase + { + private: + ::Platform::WeakReference _dataRoot; + + protected: + ReferenceTypeXamlBindings() {} + + virtual void Update_(T^, int) + { + // Overridden in the binding class as needed. + } + + public: + T^ GetDataRoot() + { + return ResolveHelper::Resolve(this->_dataRoot); + } + + bool SetDataRoot(::Platform::Object^ data) + { + if (data != nullptr) + { + this->_dataRoot = data; + return true; + } + return false; + } + + virtual void Update() override + { + this->Update_(this->GetDataRoot(), this->NOT_PHASED); + this->_isInitialized = true; + } + }; + + template + class ValueTypeXamlBindings : public XamlBindingsBase + { + private: + T _dataRoot; + + protected: + ValueTypeXamlBindings() {} + + virtual void Update_(T, int) + { + // Overridden in the binding class as needed. + } + + public: + T GetDataRoot() + { + return this->_dataRoot; + } + + bool SetDataRoot(::Platform::Object^ data) + { + if (data != nullptr) + { + this->_dataRoot = safe_cast(data); + return true; + } + return false; + } + + virtual void Update() override + { + this->Update_(this->GetDataRoot(), this->NOT_PHASED); + this->_isInitialized = true; + } + }; +} + diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Generated Files/XamlBindingInfo.g.hpp b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Generated Files/XamlBindingInfo.g.hpp new file mode 100644 index 00000000000..a65394b6791 --- /dev/null +++ b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Generated Files/XamlBindingInfo.g.hpp @@ -0,0 +1,237 @@ + +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ +#include "pch.h" +#include "XamlBindingInfo.g.h" + +// XamlBindings + +::XamlBindingInfo::XamlBindings::XamlBindings(::XamlBindingInfo::IXamlBindings* pBindings) + : _pBindings(pBindings) +{ +} + +::XamlBindingInfo::XamlBindings::~XamlBindings() +{ + delete _pBindings; +} + +void ::XamlBindingInfo::XamlBindings::Initialize() +{ + if (!this->_pBindings->IsInitialized()) + { + this->_pBindings->Update(); + } +} + +void ::XamlBindingInfo::XamlBindings::Update() +{ + this->_pBindings->Update(); +} + +void ::XamlBindingInfo::XamlBindings::StopTracking() +{ + this->_pBindings->StopTracking(); +} + +void ::XamlBindingInfo::XamlBindings::Loading(::Windows::UI::Xaml::FrameworkElement^, ::Platform::Object^) +{ + this->Initialize(); +} + +void ::XamlBindingInfo::XamlBindings::DataContextChanged(::Windows::UI::Xaml::FrameworkElement^, ::Windows::UI::Xaml::DataContextChangedEventArgs^ args) +{ + if (this->_pBindings->SetDataRoot(args->NewValue)) + { + this->Update(); + } +} + +void ::XamlBindingInfo::XamlBindings::SubscribeForDataContextChanged(::Windows::UI::Xaml::FrameworkElement^ object) +{ + this->_pBindings->SubscribeForDataContextChanged(object, this); +} + +void ::XamlBindingInfo::XamlBindings::DisconnectUnloadedObject(int connectionId) +{ + this->_pBindings->DisconnectUnloadedObject(connectionId); +} + +void ::XamlBindingInfo::XamlBindings::Connect(int connectionId, ::Platform::Object^ target) +{ + this->_pBindings->Connect(connectionId, target); +} + +bool ::XamlBindingInfo::XamlBindings::ProcessBinding(unsigned int) +{ + throw ref new ::Platform::NotImplementedException(); +} + +int ::XamlBindingInfo::XamlBindings::ProcessBindings(::Windows::UI::Xaml::Controls::ContainerContentChangingEventArgs^ args) +{ + int nextPhase = -1; + int phase = static_cast(args->Phase); + if (phase < 0) + { + throw ref new ::Platform::InvalidArgumentException(); + } + this->_pBindings->ProcessBindings(args->Item, args->ItemIndex, phase, &nextPhase); + return nextPhase; +} + +void ::XamlBindingInfo::XamlBindings::ResetTemplate() +{ + this->_pBindings->Recycle(); +} + +void ::XamlBindingInfo::XamlBindings::ProcessBindings(::Platform::Object^ item, int itemIndex, int phase, int* nextPhase) +{ + this->_pBindings->ProcessBindings(item, itemIndex, phase, nextPhase); +} + +void ::XamlBindingInfo::XamlBindings::Recycle() +{ + this->_pBindings->Recycle(); +} + +// XamlBindingTrackingBase + +::XamlBindingInfo::XamlBindingTrackingBase::XamlBindingTrackingBase() +{ +} + +void ::XamlBindingInfo::XamlBindingTrackingBase::SetListener(::XamlBindingInfo::IXamlBindingTracking* pBindings) +{ + this->_pBindingsTrackingWeakRef = pBindings; +} + +void ::XamlBindingInfo::XamlBindingTrackingBase::PropertyChanged(Platform::Object^ sender, ::Windows::UI::Xaml::Data::PropertyChangedEventArgs^ e) +{ + if (this->_pBindingsTrackingWeakRef != nullptr) + { + this->_pBindingsTrackingWeakRef->PropertyChanged(sender, e); + } +} + +void ::XamlBindingInfo::XamlBindingTrackingBase::CollectionChanged(::Platform::Object^ sender, ::Windows::UI::Xaml::Interop::NotifyCollectionChangedEventArgs^ e) +{ + if (this->_pBindingsTrackingWeakRef != nullptr) + { + this->_pBindingsTrackingWeakRef->CollectionChanged(sender, e); + } +} + +void ::XamlBindingInfo::XamlBindingTrackingBase::DependencyPropertyChanged(::Windows::UI::Xaml::DependencyObject^ sender, ::Windows::UI::Xaml::DependencyProperty^ prop) +{ + if (this->_pBindingsTrackingWeakRef != nullptr) + { + this->_pBindingsTrackingWeakRef->DependencyPropertyChanged(sender, prop); + } +} + +void ::XamlBindingInfo::XamlBindingTrackingBase::VectorChanged(::Platform::Object^ sender, ::Windows::Foundation::Collections::IVectorChangedEventArgs^ e) +{ + if (this->_pBindingsTrackingWeakRef != nullptr) + { + this->_pBindingsTrackingWeakRef->VectorChanged(sender, e); + } +} + +void ::XamlBindingInfo::XamlBindingTrackingBase::MapChanged(::Platform::Object^ sender, ::Windows::Foundation::Collections::IMapChangedEventArgs<::Platform::String^>^ e) +{ + if (this->_pBindingsTrackingWeakRef != nullptr) + { + this->_pBindingsTrackingWeakRef->MapChanged(sender, e); + } +} + +void ::XamlBindingInfo::XamlBindingTrackingBase::UpdatePropertyChangedListener(::Windows::UI::Xaml::Data::INotifyPropertyChanged^ obj, ::Windows::UI::Xaml::Data::INotifyPropertyChanged^* pCache, ::Windows::Foundation::EventRegistrationToken* pToken) +{ + if (*pCache != nullptr && !(*pCache)->Equals(obj)) + { + (*pCache)->PropertyChanged -= *pToken; + *pCache = nullptr; + } + + if (*pCache == nullptr && obj != nullptr) + { + *pCache = obj; + *pToken = obj->PropertyChanged += ref new ::Windows::UI::Xaml::Data::PropertyChangedEventHandler( + this, &::XamlBindingInfo::XamlBindingTrackingBase::PropertyChanged); + } +} + +void ::XamlBindingInfo::XamlBindingTrackingBase::UpdatePropertyChangedListener(::Windows::UI::Xaml::Data::INotifyPropertyChanged^ obj, ::Platform::WeakReference& cacheRef, ::Windows::Foundation::EventRegistrationToken* pToken) +{ + ::Windows::UI::Xaml::Data::INotifyPropertyChanged^ cache = cacheRef.Resolve<::Windows::UI::Xaml::Data::INotifyPropertyChanged>(); + if (cache != nullptr && !cache->Equals(obj)) + { + cache->PropertyChanged -= *pToken; + cache = nullptr; + cacheRef = nullptr; + } + + if (cache == nullptr && obj != nullptr) + { + cacheRef = cache = obj; + *pToken = obj->PropertyChanged += ref new ::Windows::UI::Xaml::Data::PropertyChangedEventHandler( + this, &::XamlBindingInfo::XamlBindingTrackingBase::PropertyChanged); + } +} + +void ::XamlBindingInfo::XamlBindingTrackingBase::UpdateCollectionChangedListener(::Windows::UI::Xaml::Interop::INotifyCollectionChanged^ obj, ::Windows::UI::Xaml::Interop::INotifyCollectionChanged^* pCache, ::Windows::Foundation::EventRegistrationToken* pToken) +{ + if (*pCache != nullptr && !(*pCache)->Equals(obj)) + { + (*pCache)->CollectionChanged -= *pToken; + *pCache = nullptr; + } + + if (*pCache == nullptr && obj != nullptr) + { + *pCache = obj; + *pToken = obj->CollectionChanged += ref new ::Windows::UI::Xaml::Interop::NotifyCollectionChangedEventHandler( + this, &::XamlBindingInfo::XamlBindingTrackingBase::CollectionChanged); + } +} + +void ::XamlBindingInfo::XamlBindingTrackingBase::UpdateDependencyPropertyChangedListener(::Windows::UI::Xaml::DependencyObject^ obj, ::Windows::UI::Xaml::DependencyProperty^ property, ::Windows::UI::Xaml::DependencyObject^* pCache, __int64* pToken) +{ + if (*pCache != nullptr && !(*pCache)->Equals(obj)) + { + (*pCache)->UnregisterPropertyChangedCallback(property, *pToken); + *pCache = nullptr; + } + + if (*pCache == nullptr && obj != nullptr) + { + *pCache = obj; + *pToken = obj->RegisterPropertyChangedCallback(property, ref new ::Windows::UI::Xaml::DependencyPropertyChangedCallback( + this, &::XamlBindingInfo::XamlBindingTrackingBase::DependencyPropertyChanged)); + } +} + +void ::XamlBindingInfo::XamlBindingTrackingBase::UpdateDependencyPropertyChangedListener(::Windows::UI::Xaml::DependencyObject^ obj, ::Windows::UI::Xaml::DependencyProperty^ property, ::Platform::WeakReference& cacheRef, __int64* pToken) +{ + ::Windows::UI::Xaml::DependencyObject^ cache = cacheRef.Resolve<::Windows::UI::Xaml::DependencyObject>(); + if (cache != nullptr && !cache->Equals(obj)) + { + cache->UnregisterPropertyChangedCallback(property, *pToken); + cache = nullptr; + cacheRef = nullptr; + } + + if (cache == nullptr && obj != nullptr) + { + cacheRef = cache = obj; + *pToken = obj->RegisterPropertyChangedCallback(property, ref new ::Windows::UI::Xaml::DependencyPropertyChangedCallback( + this, &::XamlBindingInfo::XamlBindingTrackingBase::DependencyPropertyChanged)); + } +} + diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Generated Files/XamlLibMetadataProvider.g.cpp b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Generated Files/XamlLibMetadataProvider.g.cpp new file mode 100644 index 00000000000..05de5ad1e1c --- /dev/null +++ b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Generated Files/XamlLibMetadataProvider.g.cpp @@ -0,0 +1,2 @@ + +#include "pch.h" diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Generated Files/XamlTypeInfo.Impl.g.cpp b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Generated Files/XamlTypeInfo.Impl.g.cpp new file mode 100644 index 00000000000..2bd1fd87ae6 --- /dev/null +++ b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Generated Files/XamlTypeInfo.Impl.g.cpp @@ -0,0 +1,588 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ +#include "pch.h" +#include +#include "XamlTypeInfo.g.h" + + +// XamlMetaDataProvider +namespace Microsoft +{ + namespace Toolkit + { + namespace Uwp + { + namespace UI + { + namespace Controls + { + namespace WinRT + { + namespace Microsoft_Toolkit_Uwp_UI_Controls_WinRT_XamlTypeInfo + { + [Windows::Foundation::Metadata::WebHostHidden] + public ref class XamlMetaDataProvider sealed : public ::Windows::UI::Xaml::Markup::IXamlMetadataProvider + { + public: + [::Windows::Foundation::Metadata::DefaultOverload] + virtual ::Windows::UI::Xaml::Markup::IXamlType^ GetXamlType(::Windows::UI::Xaml::Interop::TypeName type); + virtual ::Windows::UI::Xaml::Markup::IXamlType^ GetXamlType(::Platform::String^ fullName); + virtual ::Platform::Array<::Windows::UI::Xaml::Markup::XmlnsDefinition>^ GetXmlnsDefinitions(); + + private: + ::XamlTypeInfo::InfoProvider::XamlTypeInfoProvider^ _provider; + property ::XamlTypeInfo::InfoProvider::XamlTypeInfoProvider^ Provider + { + ::XamlTypeInfo::InfoProvider::XamlTypeInfoProvider^ get(); + } + }; + } + } + } + } + } + } +} + +[::Windows::Foundation::Metadata::DefaultOverload] +::Windows::UI::Xaml::Markup::IXamlType^ ::Microsoft::Toolkit::Uwp::UI::Controls::WinRT::Microsoft_Toolkit_Uwp_UI_Controls_WinRT_XamlTypeInfo::XamlMetaDataProvider::GetXamlType(::Windows::UI::Xaml::Interop::TypeName type) +{ + return Provider->GetXamlTypeByType(type); +} + +::Windows::UI::Xaml::Markup::IXamlType^ ::Microsoft::Toolkit::Uwp::UI::Controls::WinRT::Microsoft_Toolkit_Uwp_UI_Controls_WinRT_XamlTypeInfo::XamlMetaDataProvider::GetXamlType(Platform::String^ fullName) +{ + return Provider->GetXamlTypeByName(fullName); +} + +Platform::Array<::Windows::UI::Xaml::Markup::XmlnsDefinition>^ ::Microsoft::Toolkit::Uwp::UI::Controls::WinRT::Microsoft_Toolkit_Uwp_UI_Controls_WinRT_XamlTypeInfo::XamlMetaDataProvider::GetXmlnsDefinitions() +{ + return ref new Platform::Array<::Windows::UI::Xaml::Markup::XmlnsDefinition>(0); +} + +::XamlTypeInfo::InfoProvider::XamlTypeInfoProvider^ ::Microsoft::Toolkit::Uwp::UI::Controls::WinRT::Microsoft_Toolkit_Uwp_UI_Controls_WinRT_XamlTypeInfo::XamlMetaDataProvider::Provider::get() +{ + if (_provider == nullptr) + { + _provider = ref new XamlTypeInfo::InfoProvider::XamlTypeInfoProvider(); + } + return _provider; +} + +::Windows::UI::Xaml::Markup::IXamlType^ ::XamlTypeInfo::InfoProvider::XamlTypeInfoProvider::GetXamlTypeByType(::Windows::UI::Xaml::Interop::TypeName type) +{ + auto xamlType = GetXamlTypeByName(type.Name); + return xamlType; +} + +::Windows::UI::Xaml::Markup::IXamlType^ ::XamlTypeInfo::InfoProvider::XamlTypeInfoProvider::GetXamlTypeByName(::Platform::String^ typeName) +{ + if (typeName == nullptr || typeName->IsEmpty()) + { + return nullptr; + } + + auto lock = _xamlTypesCriticalSection.Lock(); + auto val = _xamlTypes.find(typeName); + ::Windows::UI::Xaml::Markup::IXamlType^ xamlType = nullptr; + if (val != _xamlTypes.end()) + { + xamlType = (val->second).Resolve<::Windows::UI::Xaml::Markup::IXamlType>(); + if(xamlType != nullptr) + { + return xamlType; + } + } + + xamlType = CreateXamlType(typeName); + + if (xamlType != nullptr) + { + Platform::WeakReference wr(xamlType); + _xamlTypes[xamlType->FullName] = wr; + } + return xamlType; +} + +::Windows::UI::Xaml::Markup::IXamlMember^ ::XamlTypeInfo::InfoProvider::XamlTypeInfoProvider::GetMemberByLongName(::Platform::String^ longMemberName) +{ + if (longMemberName == nullptr || longMemberName->IsEmpty()) + { + return nullptr; + } + + auto lock = _xamlMembersCriticalSection.Lock(); + auto val = _xamlMembers.find(longMemberName); + if (val != _xamlMembers.end()) + { + return val->second; + } + + auto xamlMember = CreateXamlMember(longMemberName); + if (xamlMember != nullptr) + { + _xamlMembers[longMemberName] = xamlMember; + } + return xamlMember; +} + + +// XamlSystemBaseType +::XamlTypeInfo::InfoProvider::XamlSystemBaseType::XamlSystemBaseType(::Platform::String^ name) : + _fullName(name) +{ +} + +::Windows::UI::Xaml::Markup::IXamlType^ ::XamlTypeInfo::InfoProvider::XamlSystemBaseType::BaseType::get() +{ + throw ref new ::Platform::NotImplementedException; +} + +::Windows::UI::Xaml::Markup::IXamlMember^ ::XamlTypeInfo::InfoProvider::XamlSystemBaseType::ContentProperty::get() +{ + throw ref new ::Platform::NotImplementedException; +} + +::Platform::String^ ::XamlTypeInfo::InfoProvider::XamlSystemBaseType::FullName::get() +{ + return _fullName; +} + +::Platform::String^ ::XamlTypeInfo::InfoProvider::XamlSystemBaseType::Name::get() +{ + const wchar_t* seperator = wcsrchr(_fullName->Data(), '.'); + if (seperator == nullptr) + { + return _fullName; + } + return ref new ::Platform::String(seperator); +} + +bool ::XamlTypeInfo::InfoProvider::XamlSystemBaseType::IsArray::get() +{ + throw ref new ::Platform::NotImplementedException; +} + +bool ::XamlTypeInfo::InfoProvider::XamlSystemBaseType::IsCollection::get() +{ + throw ref new ::Platform::NotImplementedException; +} + +bool ::XamlTypeInfo::InfoProvider::XamlSystemBaseType::IsConstructible::get() +{ + throw ref new ::Platform::NotImplementedException; +} + +bool ::XamlTypeInfo::InfoProvider::XamlSystemBaseType::IsDictionary::get() +{ + throw ref new ::Platform::NotImplementedException; +} + +bool ::XamlTypeInfo::InfoProvider::XamlSystemBaseType::IsMarkupExtension::get() +{ + throw ref new ::Platform::NotImplementedException; +} + +bool ::XamlTypeInfo::InfoProvider::XamlSystemBaseType::IsEnum::get() +{ + throw ref new ::Platform::NotImplementedException; +} + +bool ::XamlTypeInfo::InfoProvider::XamlSystemBaseType::IsSystemType::get() +{ + throw ref new ::Platform::NotImplementedException; +} + +bool ::XamlTypeInfo::InfoProvider::XamlSystemBaseType::IsBindable::get() +{ + throw ref new ::Platform::NotImplementedException; +} + +::Windows::UI::Xaml::Markup::IXamlType^ ::XamlTypeInfo::InfoProvider::XamlSystemBaseType::ItemType::get() +{ + throw ref new ::Platform::NotImplementedException; +} + +::Windows::UI::Xaml::Markup::IXamlType^ ::XamlTypeInfo::InfoProvider::XamlSystemBaseType::KeyType::get() +{ + throw ref new ::Platform::NotImplementedException; +} + +::Windows::UI::Xaml::Interop::TypeName (::XamlTypeInfo::InfoProvider::XamlSystemBaseType::UnderlyingType::get)() +{ + ::Windows::UI::Xaml::Interop::TypeName typeName; + + typeName.Name = _fullName; + typeName.Kind = ::Windows::UI::Xaml::Interop::TypeKind::Primitive; + + return typeName; +} + +::Platform::Object^ ::XamlTypeInfo::InfoProvider::XamlSystemBaseType::ActivateInstance() +{ + throw ref new ::Platform::NotImplementedException; +} + +::Windows::UI::Xaml::Markup::IXamlMember^ ::XamlTypeInfo::InfoProvider::XamlSystemBaseType::GetMember(::Platform::String^) +{ + throw ref new ::Platform::NotImplementedException; +} + +void ::XamlTypeInfo::InfoProvider::XamlSystemBaseType::AddToVector(::Platform::Object^, ::Platform::Object^) +{ + throw ref new ::Platform::NotImplementedException; +} + +void ::XamlTypeInfo::InfoProvider::XamlSystemBaseType::AddToMap(::Platform::Object^, ::Platform::Object^, ::Platform::Object^) +{ + throw ref new ::Platform::NotImplementedException; +} + +void ::XamlTypeInfo::InfoProvider::XamlSystemBaseType::RunInitializer() +{ + throw ref new ::Platform::NotImplementedException; +} + +::Platform::Object^ ::XamlTypeInfo::InfoProvider::XamlSystemBaseType::CreateFromString(::Platform::String^) +{ + throw ref new ::Platform::NotImplementedException; +} + +//XamlUserType +::XamlTypeInfo::InfoProvider::XamlUserType::XamlUserType(::XamlTypeInfo::InfoProvider::XamlTypeInfoProvider^ provider, ::Platform::String^ fullName, ::Windows::UI::Xaml::Markup::IXamlType^ baseType) : + _isArray(false), + _isMarkupExtension(false), + _isEnum(false), + _isBindable(false), + _isReturnTypeStub(false), + _isLocalType(false), + _fullName(fullName), + _provider(provider), + _baseType(baseType) +{ +} + +::Platform::String^ ::XamlTypeInfo::InfoProvider::XamlUserType::FullName::get() +{ + return _fullName; +} + +::Platform::String^ ::XamlTypeInfo::InfoProvider::XamlUserType::Name::get() +{ + const wchar_t *seperator = wcsrchr(_fullName->Data(), '.'); + if (seperator == nullptr) + { + return _fullName; + } + return ref new ::Platform::String(seperator); +} + +::Windows::UI::Xaml::Interop::TypeName (::XamlTypeInfo::InfoProvider::XamlUserType::UnderlyingType::get)() +{ + ::Windows::UI::Xaml::Interop::TypeName typeName; + + typeName.Name = _fullName; + typeName.Kind = KindOfType; + + return typeName; +} + +bool ::XamlTypeInfo::InfoProvider::XamlUserType::IsSystemType::get() +{ + return true; +} + +::Windows::UI::Xaml::Markup::IXamlType^ ::XamlTypeInfo::InfoProvider::XamlUserType::BaseType::get() +{ + return _baseType; +} + +bool ::XamlTypeInfo::InfoProvider::XamlUserType::IsArray::get() +{ + return _isArray; +} +void ::XamlTypeInfo::InfoProvider::XamlUserType::IsArray::set(bool value) +{ + _isArray = value; +} + +bool ::XamlTypeInfo::InfoProvider::XamlUserType::IsCollection::get() +{ + return CollectionAdd != nullptr; +} + +bool ::XamlTypeInfo::InfoProvider::XamlUserType::IsConstructible::get() +{ + return Activator != nullptr; +} + +bool ::XamlTypeInfo::InfoProvider::XamlUserType::IsDictionary::get() +{ + return DictionaryAdd != nullptr; +} + +bool ::XamlTypeInfo::InfoProvider::XamlUserType::IsMarkupExtension::get() +{ + return _isMarkupExtension; +} + +void ::XamlTypeInfo::InfoProvider::XamlUserType::IsMarkupExtension::set(bool value) +{ + _isMarkupExtension = value; +} + +bool ::XamlTypeInfo::InfoProvider::XamlUserType::IsEnum::get() +{ + return _isEnum; +} + +void ::XamlTypeInfo::InfoProvider::XamlUserType::IsEnum::set(bool value) +{ + _isEnum = value; +} + +bool ::XamlTypeInfo::InfoProvider::XamlUserType::IsBindable::get() +{ + return _isBindable; +} + +void ::XamlTypeInfo::InfoProvider::XamlUserType::IsBindable::set(bool value) +{ + _isBindable = value; +} + +bool ::XamlTypeInfo::InfoProvider::XamlUserType::IsReturnTypeStub::get() +{ + return _isReturnTypeStub; +} + +void ::XamlTypeInfo::InfoProvider::XamlUserType::IsReturnTypeStub::set(bool value) +{ + _isReturnTypeStub = value; +} + +bool ::XamlTypeInfo::InfoProvider::XamlUserType::IsLocalType::get() +{ + return _isLocalType; +} + +void ::XamlTypeInfo::InfoProvider::XamlUserType::IsLocalType::set(bool value) +{ + _isLocalType = value; +} + +::Windows::UI::Xaml::Markup::IXamlMember^ ::XamlTypeInfo::InfoProvider::XamlUserType::ContentProperty::get() +{ + return _provider->GetMemberByLongName(_contentPropertyName); +} + +void ::XamlTypeInfo::InfoProvider::XamlUserType::ContentPropertyName::set(::Platform::String^ value) +{ + _contentPropertyName = value; +} + +::Windows::UI::Xaml::Markup::IXamlType^ ::XamlTypeInfo::InfoProvider::XamlUserType::ItemType::get() +{ + return _provider->GetXamlTypeByName(_itemTypeName); +} + +void ::XamlTypeInfo::InfoProvider::XamlUserType::ItemTypeName::set(::Platform::String^ value) +{ + _itemTypeName = value; +} + +::Windows::UI::Xaml::Markup::IXamlType^ ::XamlTypeInfo::InfoProvider::XamlUserType::KeyType::get() +{ + return _provider->GetXamlTypeByName(_keyTypeName); +} + +void ::XamlTypeInfo::InfoProvider::XamlUserType::KeyTypeName::set(::Platform::String^ value) +{ + _keyTypeName = value; +} + +::Windows::UI::Xaml::Markup::IXamlMember^ ::XamlTypeInfo::InfoProvider::XamlUserType::GetMember(::Platform::String^ name) +{ + auto val = _memberNames.find(name); + if (val != _memberNames.end()) + { + return _provider->GetMemberByLongName(val->second); + } + return nullptr; +} + +::Platform::Object^ ::XamlTypeInfo::InfoProvider::XamlUserType::ActivateInstance() +{ + return Activator(); +} + +void ::XamlTypeInfo::InfoProvider::XamlUserType::AddToMap(::Platform::Object^ instance, ::Platform::Object^ key, ::Platform::Object^ item) +{ + DictionaryAdd(instance, key, item); +} + +void ::XamlTypeInfo::InfoProvider::XamlUserType::AddToVector(::Platform::Object^ instance, ::Platform::Object^ item) +{ + CollectionAdd(instance, item); +} + +void ::XamlTypeInfo::InfoProvider::XamlUserType::RunInitializer() +{ + // The C++ runtime will have already run all the Static Initializers at start up. +} + +::Platform::Object^ ::XamlTypeInfo::InfoProvider::XamlUserType::CreateFromString(::Platform::String^ input) +{ + if (CreateFromStringMethod != nullptr) + { + return (*CreateFromStringMethod)(input); + } + else + { + return FromStringConverter(this, input); + } +} + +void ::XamlTypeInfo::InfoProvider::XamlUserType::AddMemberName(::Platform::String^ shortName) +{ + _memberNames[shortName] = FullName + "." + shortName; +} + +void ::XamlTypeInfo::InfoProvider::XamlUserType::AddEnumValue(::Platform::String^ name, ::Platform::Object^ value) +{ + _enumValues[name->Data()] = value; +} + +::default::uint32 (::XamlTypeInfo::InfoProvider::XamlUserType::CreateEnumUIntFromString)(::Platform::String^ input) +{ + bool found = false; + + const std::wregex regularExpression(L"^\\s+|\\s*,\\s*|\\s+$"); + uint32 val = 0; + + for (std::wcregex_token_iterator it(input->Begin(), input->End(), regularExpression, -1), end; it != end; ++it) + { + const std::wcsub_match& subMatch = *it; + + if (subMatch.length() == 0 ) + { + continue; + } + + std::wstring lookup(subMatch.first, (unsigned int)subMatch.length()); + + try + { + auto entry = _enumValues.find(lookup); + if (entry != _enumValues.end()) + { + const auto f = entry->second; + val |= safe_cast(f); + } + else + { + val |= std::stoi(subMatch); + } + found=true; + } + catch (const std::invalid_argument& ) + { + found = false; + break; + } + } + + if(found) + { + return val; + } + throw ref new ::Platform::InvalidArgumentException(); +} + +// XamlMember +::XamlTypeInfo::InfoProvider::XamlMember::XamlMember(::XamlTypeInfo::InfoProvider::XamlTypeInfoProvider^ provider, ::Platform::String^ name, ::Platform::String^ typeName) : + _isAttachable(false), + _isDependencyProperty(false), + _isReadOnly(false), + _name(name), + _typeName(typeName), + _provider(provider) +{ +} + + +bool ::XamlTypeInfo::InfoProvider::XamlMember::IsAttachable::get() +{ + return _isAttachable; +} + +void ::XamlTypeInfo::InfoProvider::XamlMember::IsAttachable::set(bool value) +{ + _isAttachable = value; +} + +bool ::XamlTypeInfo::InfoProvider::XamlMember::IsDependencyProperty::get() +{ + return _isDependencyProperty; +} + +void ::XamlTypeInfo::InfoProvider::XamlMember::IsDependencyProperty::set(bool value) +{ + _isDependencyProperty = value; +} + +bool ::XamlTypeInfo::InfoProvider::XamlMember::IsReadOnly::get() +{ + return _isReadOnly; +} + +void ::XamlTypeInfo::InfoProvider::XamlMember::IsReadOnly::set(bool value) +{ + _isReadOnly = value; +} + +::Platform::String^ ::XamlTypeInfo::InfoProvider::XamlMember::Name::get() +{ + return _name; +} + +::Windows::UI::Xaml::Markup::IXamlType^ ::XamlTypeInfo::InfoProvider::XamlMember::Type::get() +{ + return _provider->GetXamlTypeByName(_typeName); +} + +::Windows::UI::Xaml::Markup::IXamlType^ ::XamlTypeInfo::InfoProvider::XamlMember::TargetType::get() +{ + return _provider->GetXamlTypeByName(_targetTypeName); +} + +void ::XamlTypeInfo::InfoProvider::XamlMember::TargetTypeName::set(::Platform::String^ value) +{ + _targetTypeName = value; +} + +::Platform::Object^ ::XamlTypeInfo::InfoProvider::XamlMember::GetValue(::Platform::Object^ instance) +{ + if (Getter != nullptr) + { + return Getter(instance); + } + throw ref new ::Platform::NullReferenceException(); +} + +void ::XamlTypeInfo::InfoProvider::XamlMember::SetValue(::Platform::Object^ instance, ::Platform::Object^ value) +{ + if (Setter != nullptr) + { + Setter(instance, value); + return; + } + throw ref new ::Platform::NullReferenceException(); +} + diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Generated Files/XamlTypeInfo.g.cpp b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Generated Files/XamlTypeInfo.g.cpp new file mode 100644 index 00000000000..b6076b4eb55 --- /dev/null +++ b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Generated Files/XamlTypeInfo.g.cpp @@ -0,0 +1,372 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ +#include "pch.h" +#include "XamlTypeInfo.g.h" + +#include "XamlBindingInfo.g.hpp" + +template +::Platform::Object^ ActivateType() +{ + return ref new T; +} + +template +void CollectionAdd(::Platform::Object^ instance, ::Platform::Object^ item) +{ + safe_cast(instance)->Append((TItem)item); +} + +template +void DictionaryAdd(::Platform::Object^ instance, ::Platform::Object^ key, ::Platform::Object^ item) +{ + safe_cast(instance)->Insert((TKey)key, (TItem)item); +} + +template +::Platform::Object^ FromStringConverter(::XamlTypeInfo::InfoProvider::XamlUserType^ userType, ::Platform::String^ input) +{ + return ref new ::Platform::Box((T)userType->CreateEnumUIntFromString(input)); +} + +template +::Platform::Object^ GetValueTypeMember_TextWrap(::Platform::Object^ instance) +{ + return ref new ::Platform::Box(safe_cast(instance)->TextWrap); +} + +template +::Platform::Object^ GetValueTypeMember_TextOrientation(::Platform::Object^ instance) +{ + return ref new ::Platform::Box(safe_cast(instance)->TextOrientation); +} + +template +::Platform::Object^ GetReferenceTypeMember_TextLocale(::Platform::Object^ instance) +{ + return safe_cast(instance)->TextLocale; +} + +template +::Platform::Object^ GetReferenceTypeMember_Text(::Platform::Object^ instance) +{ + return safe_cast(instance)->Text; +} + +template +void SetEnumMember_TextWrap(::Platform::Object^ instance, ::Platform::Object^ value) +{ + safe_cast(instance)->TextWrap = safe_cast<::Platform::IBox^>(value)->Value; +} + +template +void SetEnumMember_TextOrientation(::Platform::Object^ instance, ::Platform::Object^ value) +{ + safe_cast(instance)->TextOrientation = safe_cast<::Platform::IBox^>(value)->Value; +} + +template +void SetReferenceTypeMember_TextLocale(::Platform::Object^ instance, ::Platform::Object^ value) +{ + safe_cast(instance)->TextLocale = safe_cast(value); +} + +template +void SetReferenceTypeMember_Text(::Platform::Object^ instance, ::Platform::Object^ value) +{ + safe_cast(instance)->Text = safe_cast(value); +} + +enum TypeInfo_Flags +{ + TypeInfo_Flags_None = 0x00, + TypeInfo_Flags_IsLocalType = 0x01, + TypeInfo_Flags_IsSystemType = 0x02, + TypeInfo_Flags_IsReturnTypeStub = 0x04, + TypeInfo_Flags_IsBindable = 0x08, + TypeInfo_Flags_IsMarkupExtension = 0x10, +}; + +struct TypeInfo +{ + PCWSTR typeName; + PCWSTR contentPropertyName; + ::Platform::Object^ (*activator)(); + void (*collectionAdd)(::Platform::Object^, ::Platform::Object^); + void (*dictionaryAdd)(::Platform::Object^, ::Platform::Object^, ::Platform::Object^); + ::Platform::Object^ (*fromStringConverter)(::XamlTypeInfo::InfoProvider::XamlUserType^, ::Platform::String^); + int baseTypeIndex; + int firstMemberIndex; + int firstEnumValueIndex; + int createFromStringIndex; + ::Windows::UI::Xaml::Interop::TypeKind kindofType; + unsigned int flags; +}; + +const TypeInfo TypeInfos[] = +{ + // 0 + L"String", L"", + nullptr, nullptr, nullptr, nullptr, + -1, + 0, 0, -1, ::Windows::UI::Xaml::Interop::TypeKind::Metadata, + TypeInfo_Flags_IsSystemType | TypeInfo_Flags_None, + // 1 + L"Windows.UI.Xaml.TextWrapping", L"", + nullptr, nullptr, nullptr, nullptr, + -1, + 0, 0, -1, ::Windows::UI::Xaml::Interop::TypeKind::Metadata, + TypeInfo_Flags_IsSystemType | TypeInfo_Flags_None, + // 2 + L"Windows.UI.Xaml.Controls.Control", L"", + nullptr, nullptr, nullptr, nullptr, + -1, + 0, 0, -1, ::Windows::UI::Xaml::Interop::TypeKind::Metadata, + TypeInfo_Flags_IsSystemType | TypeInfo_Flags_None, + // 3 + L"Windows.UI.Xaml.Controls.Orientation", L"", + nullptr, nullptr, nullptr, nullptr, + -1, + 0, 0, -1, ::Windows::UI::Xaml::Interop::TypeKind::Metadata, + TypeInfo_Flags_IsSystemType | TypeInfo_Flags_None, + // 4 + L"Microsoft.Toolkit.Uwp.UI.Controls.WinRT.DirectWriteTextBlock", L"", + &ActivateType<::Microsoft::Toolkit::Uwp::UI::Controls::WinRT::DirectWriteTextBlock>, nullptr, nullptr, nullptr, + 2, // Windows.UI.Xaml.Controls.Control + 0, 0, -1, ::Windows::UI::Xaml::Interop::TypeKind::Metadata, + TypeInfo_Flags_IsLocalType | TypeInfo_Flags_None, + // Last type here is for padding + L"", L"", + nullptr, nullptr, nullptr, nullptr, + -1, + 4, 0, -1, ::Windows::UI::Xaml::Interop::TypeKind::Custom, + TypeInfo_Flags_None, +}; + +const UINT TypeInfoLookup[] = { + 0, // 0 + 0, // 1 + 0, // 2 + 0, // 3 + 0, // 4 + 0, // 5 + 0, // 6 + 1, // 7 + 1, // 8 + 1, // 9 + 1, // 10 + 1, // 11 + 1, // 12 + 1, // 13 + 1, // 14 + 1, // 15 + 1, // 16 + 1, // 17 + 1, // 18 + 1, // 19 + 1, // 20 + 1, // 21 + 1, // 22 + 1, // 23 + 1, // 24 + 1, // 25 + 1, // 26 + 1, // 27 + 1, // 28 + 2, // 29 + 2, // 30 + 2, // 31 + 2, // 32 + 3, // 33 + 3, // 34 + 3, // 35 + 3, // 36 + 4, // 37 + 4, // 38 + 4, // 39 + 4, // 40 + 4, // 41 + 4, // 42 + 4, // 43 + 4, // 44 + 4, // 45 + 4, // 46 + 4, // 47 + 4, // 48 + 4, // 49 + 4, // 50 + 4, // 51 + 4, // 52 + 4, // 53 + 4, // 54 + 4, // 55 + 4, // 56 + 4, // 57 + 4, // 58 + 4, // 59 + 4, // 60 + 5, // 61 +}; + +struct MemberInfo +{ + PCWSTR shortName; + ::Platform::Object^ (*getter)(::Platform::Object^); + void (*setter)(::Platform::Object^, ::Platform::Object^); + int typeIndex; + int targetTypeIndex; + bool isReadOnly; + bool isDependencyProperty; + bool isAttachable; +}; + +const MemberInfo MemberInfos[] = +{ + // 0 - Microsoft.Toolkit.Uwp.UI.Controls.WinRT.DirectWriteTextBlock.TextWrap + L"TextWrap", + &GetValueTypeMember_TextWrap<::Microsoft::Toolkit::Uwp::UI::Controls::WinRT::DirectWriteTextBlock, ::Windows::UI::Xaml::TextWrapping>, + &SetEnumMember_TextWrap<::Microsoft::Toolkit::Uwp::UI::Controls::WinRT::DirectWriteTextBlock, ::Windows::UI::Xaml::TextWrapping>, + 1, // Windows.UI.Xaml.TextWrapping + -1, + false, true, false, + // 1 - Microsoft.Toolkit.Uwp.UI.Controls.WinRT.DirectWriteTextBlock.TextOrientation + L"TextOrientation", + &GetValueTypeMember_TextOrientation<::Microsoft::Toolkit::Uwp::UI::Controls::WinRT::DirectWriteTextBlock, ::Windows::UI::Xaml::Controls::Orientation>, + &SetEnumMember_TextOrientation<::Microsoft::Toolkit::Uwp::UI::Controls::WinRT::DirectWriteTextBlock, ::Windows::UI::Xaml::Controls::Orientation>, + 3, // Windows.UI.Xaml.Controls.Orientation + -1, + false, true, false, + // 2 - Microsoft.Toolkit.Uwp.UI.Controls.WinRT.DirectWriteTextBlock.TextLocale + L"TextLocale", + &GetReferenceTypeMember_TextLocale<::Microsoft::Toolkit::Uwp::UI::Controls::WinRT::DirectWriteTextBlock>, + &SetReferenceTypeMember_TextLocale<::Microsoft::Toolkit::Uwp::UI::Controls::WinRT::DirectWriteTextBlock, ::Platform::String>, + 0, // String + -1, + false, true, false, + // 3 - Microsoft.Toolkit.Uwp.UI.Controls.WinRT.DirectWriteTextBlock.Text + L"Text", + &GetReferenceTypeMember_Text<::Microsoft::Toolkit::Uwp::UI::Controls::WinRT::DirectWriteTextBlock>, + &SetReferenceTypeMember_Text<::Microsoft::Toolkit::Uwp::UI::Controls::WinRT::DirectWriteTextBlock, ::Platform::String>, + 0, // String + -1, + false, true, false, +}; + +PCWSTR GetShortName(PCWSTR longName) +{ + PCWSTR separator = wcsrchr(longName, '.'); + return separator != nullptr ? separator + 1: longName; +} + +const TypeInfo* GetTypeInfo(::Platform::String^ typeName) +{ + auto typeNameLength = typeName->Length(); + if (typeNameLength < _countof(TypeInfoLookup) - 1) + { + for (UINT i = TypeInfoLookup[typeNameLength]; i < TypeInfoLookup[typeNameLength+1]; i++) + { + if (typeName == ::Platform::StringReference(TypeInfos[i].typeName)) + { + return &TypeInfos[i]; + } + } + } + return nullptr; +} + +const MemberInfo* GetMemberInfo(::Platform::String^ longMemberName) +{ + auto lastDotIndex = longMemberName->Length(); + while (true) + { + if (longMemberName->Data()[lastDotIndex] == '.') + { + const TypeInfo* pTypeInfo = GetTypeInfo(ref new ::Platform::String(longMemberName->Data(), lastDotIndex)); + const TypeInfo* pNextTypeInfo = pTypeInfo + 1; + if (pTypeInfo) + { + PCWSTR shortMemberName = GetShortName(longMemberName->Data()); + for (int i = pTypeInfo->firstMemberIndex; i < pNextTypeInfo->firstMemberIndex; i++) + { + if (wcscmp(shortMemberName, MemberInfos[i].shortName) == 0) + { + return &MemberInfos[i]; + } + } + } + break; + } + if (lastDotIndex == 0) + { + break; + } + lastDotIndex--; + } + return nullptr; +} + +::Windows::UI::Xaml::Markup::IXamlType^ ::XamlTypeInfo::InfoProvider::XamlTypeInfoProvider::CreateXamlType(::Platform::String^ typeName) +{ + const TypeInfo* pTypeInfo = GetTypeInfo(typeName); + const TypeInfo* pNextTypeInfo = pTypeInfo + 1; + if (pTypeInfo == nullptr || pNextTypeInfo == nullptr) + { + return nullptr; + } + else if (pTypeInfo->flags & TypeInfo_Flags_IsSystemType) + { + return ref new ::XamlTypeInfo::InfoProvider::XamlSystemBaseType(typeName); + } + else + { + ::XamlTypeInfo::InfoProvider::XamlUserType^ userType = ref new ::XamlTypeInfo::InfoProvider::XamlUserType( + this, + ::Platform::StringReference(pTypeInfo->typeName), + this->GetXamlTypeByName(::Platform::StringReference(pTypeInfo->baseTypeIndex >= 0 ? TypeInfos[pTypeInfo->baseTypeIndex].typeName : L""))); + userType->KindOfType = pTypeInfo->kindofType; + userType->Activator = pTypeInfo->activator; + userType->CollectionAdd = pTypeInfo->collectionAdd; + userType->DictionaryAdd = pTypeInfo->dictionaryAdd; + userType->FromStringConverter = pTypeInfo->fromStringConverter; + userType->ContentPropertyName = ::Platform::StringReference(pTypeInfo->contentPropertyName); + userType->IsLocalType = pTypeInfo->flags & TypeInfo_Flags_IsLocalType; + userType->IsReturnTypeStub = pTypeInfo->flags & TypeInfo_Flags_IsReturnTypeStub; + userType->IsBindable = pTypeInfo->flags & TypeInfo_Flags_IsBindable; + userType->IsMarkupExtension = pTypeInfo->flags & TypeInfo_Flags_IsMarkupExtension; + userType->CreateFromStringMethod = nullptr; + int nextMemberIndex = pTypeInfo->firstMemberIndex; + for (int i=pTypeInfo->firstMemberIndex; i < pNextTypeInfo->firstMemberIndex; i++) + { + userType->AddMemberName(::Platform::StringReference(MemberInfos[i].shortName)); + nextMemberIndex++; + } + return userType; + } +} + +::Windows::UI::Xaml::Markup::IXamlMember^ ::XamlTypeInfo::InfoProvider::XamlTypeInfoProvider::CreateXamlMember(::Platform::String^ longMemberName) +{ + ::XamlTypeInfo::InfoProvider::XamlMember^ xamlMember = nullptr; + const MemberInfo* pMemberInfo = GetMemberInfo(longMemberName); + if (pMemberInfo != nullptr) + { + xamlMember = ref new ::XamlTypeInfo::InfoProvider::XamlMember( + this, + ::Platform::StringReference(pMemberInfo->shortName), + ::Platform::StringReference(TypeInfos[pMemberInfo->typeIndex].typeName)); + xamlMember->Getter = pMemberInfo->getter; + xamlMember->Setter = pMemberInfo->setter; + xamlMember->TargetTypeName = pMemberInfo->targetTypeIndex >= 0 ? ::Platform::StringReference(TypeInfos[pMemberInfo->targetTypeIndex].typeName) : L""; + xamlMember->IsReadOnly = pMemberInfo->isReadOnly; + xamlMember->IsDependencyProperty = pMemberInfo->isDependencyProperty; + xamlMember->IsAttachable = pMemberInfo->isAttachable; + } + return xamlMember; +} + diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Generated Files/XamlTypeInfo.g.h b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Generated Files/XamlTypeInfo.g.h new file mode 100644 index 00000000000..49748990f9a --- /dev/null +++ b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Generated Files/XamlTypeInfo.g.h @@ -0,0 +1,383 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ +#pragma once +#include + +namespace XamlTypeInfo +{ + namespace InfoProvider + { + ref class XamlTypeInfoProvider sealed + { + struct CriticalSection + { + CriticalSection() + { + InitializeCriticalSection(&criticalSection); + } + + ~CriticalSection() + { + DeleteCriticalSection(&criticalSection); + } + + struct AutoLock + { + AutoLock(LPCRITICAL_SECTION criticalSection) + : pCriticalSection(criticalSection) + { + EnterCriticalSection(criticalSection); + } + + ~AutoLock() + { + LeaveCriticalSection(pCriticalSection); + } + + private: + LPCRITICAL_SECTION pCriticalSection{ nullptr }; + }; + + AutoLock Lock() + { + return AutoLock(&criticalSection); + } + + private: + CRITICAL_SECTION criticalSection; + }; + + public: + ::Windows::UI::Xaml::Markup::IXamlType^ GetXamlTypeByName(::Platform::String^ typeName); + ::Windows::UI::Xaml::Markup::IXamlType^ GetXamlTypeByType(::Windows::UI::Xaml::Interop::TypeName t); + ::Windows::UI::Xaml::Markup::IXamlMember^ GetMemberByLongName(::Platform::String^ longMemberName); + + private: + CriticalSection _xamlTypesCriticalSection; + std::map<::Platform::String^, ::Platform::WeakReference> _xamlTypes; + CriticalSection _xamlMembersCriticalSection; + std::map<::Platform::String^, ::Windows::UI::Xaml::Markup::IXamlMember^> _xamlMembers; + ::Windows::UI::Xaml::Markup::IXamlType^ CreateXamlType(::Platform::String^ typeName); + ::Windows::UI::Xaml::Markup::IXamlMember^ CreateXamlMember(::Platform::String^ longMemberName); + + }; + + ref class XamlSystemBaseType sealed : public ::Windows::UI::Xaml::Markup::IXamlType + { + internal: + XamlSystemBaseType(::Platform::String^ name); + + public: + virtual property ::Windows::UI::Xaml::Markup::IXamlType^ BaseType + { + ::Windows::UI::Xaml::Markup::IXamlType^ get(); + } + + virtual property ::Windows::UI::Xaml::Markup::IXamlMember^ ContentProperty + { + ::Windows::UI::Xaml::Markup::IXamlMember^ get(); + } + + virtual property ::Platform::String^ FullName + { + ::Platform::String^ get(); + } + + virtual property ::Platform::String^ Name + { + ::Platform::String^ get(); + } + + virtual property bool IsArray + { + bool get(); + } + + virtual property bool IsCollection + { + bool get(); + } + + virtual property bool IsConstructible + { + bool get(); + } + + virtual property bool IsDictionary + { + bool get(); + } + + virtual property bool IsMarkupExtension + { + bool get(); + } + + virtual property bool IsEnum + { + bool get(); + } + + virtual property bool IsSystemType + { + bool get(); + } + + virtual property bool IsBindable + { + bool get(); + } + + virtual property ::Windows::UI::Xaml::Markup::IXamlType^ ItemType + { + ::Windows::UI::Xaml::Markup::IXamlType^ get(); + } + + virtual property ::Windows::UI::Xaml::Markup::IXamlType^ KeyType + { + ::Windows::UI::Xaml::Markup::IXamlType^ get(); + } + + virtual property ::Windows::UI::Xaml::Interop::TypeName UnderlyingType + { + ::Windows::UI::Xaml::Interop::TypeName get(); + } + + virtual ::Platform::Object^ ActivateInstance(); + virtual ::Windows::UI::Xaml::Markup::IXamlMember^ GetMember(::Platform::String^ name); + virtual void AddToVector(::Platform::Object^ instance, ::Platform::Object^ value); + virtual void AddToMap(::Platform::Object^ instance, ::Platform::Object^ key, ::Platform::Object^ value); + virtual void RunInitializer(); + virtual ::Platform::Object^ CreateFromString(::Platform::String^ value); + + private: + ::Platform::String^ _fullName; + }; + + ref class XamlUserType sealed : public [::Platform::Metadata::RuntimeClassName] ::Windows::UI::Xaml::Markup::IXamlType + { + internal: + XamlUserType(::XamlTypeInfo::InfoProvider::XamlTypeInfoProvider^ provider, ::Platform::String^ fullName, ::Windows::UI::Xaml::Markup::IXamlType^ baseType); + + public: + // --- Interface methods ---- + virtual property ::Platform::String^ FullName + { + ::Platform::String^ get(); + } + + virtual property ::Platform::String^ Name + { + ::Platform::String^ get(); + } + + virtual property ::Windows::UI::Xaml::Interop::TypeName UnderlyingType + { + ::Windows::UI::Xaml::Interop::TypeName get(); + } + + virtual property bool IsSystemType + { + bool get(); + } + + virtual property ::Windows::UI::Xaml::Markup::IXamlType^ BaseType + { + ::Windows::UI::Xaml::Markup::IXamlType^ get(); + } + + virtual property bool IsArray + { + bool get(); + internal: void set(bool value); + } + + virtual property bool IsCollection + { + bool get(); + } + + virtual property bool IsConstructible + { + bool get(); + } + + virtual property bool IsDictionary + { + bool get(); + } + + virtual property bool IsMarkupExtension + { + bool get(); + internal: void set(bool value); + } + + virtual property bool IsEnum + { + bool get(); + internal: void set(bool value); + } + + virtual property bool IsBindable + { + bool get(); + internal: void set(bool value); + } + + virtual property ::Windows::UI::Xaml::Markup::IXamlMember^ ContentProperty + { + ::Windows::UI::Xaml::Markup::IXamlMember^ get(); + } + + virtual property ::Windows::UI::Xaml::Markup::IXamlType^ ItemType + { + ::Windows::UI::Xaml::Markup::IXamlType^ get(); + } + + virtual property ::Windows::UI::Xaml::Markup::IXamlType^ KeyType + { + ::Windows::UI::Xaml::Markup::IXamlType^ get(); + } + + virtual ::Windows::UI::Xaml::Markup::IXamlMember^ GetMember(::Platform::String^ name); + virtual ::Platform::Object^ ActivateInstance(); + virtual void AddToMap(::Platform::Object^ instance, ::Platform::Object^ key, ::Platform::Object^ value); + virtual void AddToVector(::Platform::Object^ instance, ::Platform::Object^ value); + virtual void RunInitializer(); + virtual ::Platform::Object^ CreateFromString(::Platform::String^ value); + // --- End of Interface methods + + property bool IsReturnTypeStub + { + bool get(); + internal: void set(bool value); + } + + property bool IsLocalType + { + bool get(); + internal: void set(bool value); + } + + internal: + typedef ::Platform::Object^ (*ActivatorFn)(); + typedef void (*AddToCollectionFn)(::Platform::Object^ instance, ::Platform::Object^ item); + typedef void (*AddToDictionaryFn)(::Platform::Object^ instance, ::Platform::Object^ key, ::Platform::Object^ item); + typedef ::Platform::Object^ (*CreateFromStringFn)(::Platform::String^); + typedef ::Platform::Object^ (*StringConverterFn)(::XamlTypeInfo::InfoProvider::XamlUserType^ userType, ::Platform::String^ input); + + property ActivatorFn Activator; + property AddToCollectionFn CollectionAdd; + property AddToDictionaryFn DictionaryAdd; + property CreateFromStringFn CreateFromStringMethod; + property ::Windows::UI::Xaml::Interop::TypeKind KindOfType; + property StringConverterFn FromStringConverter; + + property ::Platform::String^ ContentPropertyName + { + void set(::Platform::String^ value); + } + + property ::Platform::String^ ItemTypeName + { + void set(::Platform::String^ value); + } + + property ::Platform::String^ KeyTypeName + { + void set(::Platform::String^ value); + } + + void AddMemberName(::Platform::String^ shortName); + void AddEnumValue(::Platform::String^ name, ::Platform::Object^ value); + uint32 CreateEnumUIntFromString(::Platform::String^ input); + + private: + ::XamlTypeInfo::InfoProvider::XamlTypeInfoProvider^ _provider; + ::Windows::UI::Xaml::Markup::IXamlType^ _baseType; + ::Platform::String^ _contentPropertyName; + ::Platform::String^ _itemTypeName; + ::Platform::String^ _keyTypeName; + ::Platform::String^ _fullName; + std::map<::Platform::String^, ::Platform::String^> _memberNames; + std::map _enumValues; + bool _isArray = false; + bool _isMarkupExtension = false; + bool _isEnum = false; + bool _isBindable = false; + bool _isReturnTypeStub = false; + bool _isLocalType = false; + }; + + ref class XamlMember sealed : public ::Windows::UI::Xaml::Markup::IXamlMember + { + internal: + XamlMember(::XamlTypeInfo::InfoProvider::XamlTypeInfoProvider^ provider, ::Platform::String^ name, ::Platform::String^ typeName); + + typedef ::Platform::Object^ (*PropertyGetterFn)(::Platform::Object^ instance); + typedef void (*PropertySetterFn)(::Platform::Object^ instance, ::Platform::Object^ value); + + property PropertyGetterFn Getter; + property PropertySetterFn Setter; + + public: + virtual property bool IsAttachable + { + bool get(); + internal: void set(bool value); + } + + virtual property bool IsDependencyProperty + { + bool get(); + internal: void set(bool value); + } + + virtual property bool IsReadOnly + { + bool get(); + internal: void set(bool value); + } + + virtual property ::Platform::String^ Name + { + ::Platform::String^ get(); + } + + virtual property ::Windows::UI::Xaml::Markup::IXamlType^ Type + { + ::Windows::UI::Xaml::Markup::IXamlType^ get(); + } + + virtual property ::Windows::UI::Xaml::Markup::IXamlType^ TargetType + { + ::Windows::UI::Xaml::Markup::IXamlType^ get(); + } + + virtual ::Platform::Object^ GetValue(::Platform::Object^ instance); + virtual void SetValue(::Platform::Object^ instance, ::Platform::Object^ value); + + internal: + virtual property ::Platform::String^ TargetTypeName + { + void set(::Platform::String^ value); + } + + private: + bool _isAttachable; + bool _isDependencyProperty; + bool _isReadOnly; + ::Platform::String^ _name; + ::Platform::String^ _targetTypeName; + ::Platform::String^ _typeName; + ::XamlTypeInfo::InfoProvider::XamlTypeInfoProvider^ _provider; + }; + } +} diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Microsoft.Toolkit.Uwp.UI.Controls.WinRT.vcxproj b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Microsoft.Toolkit.Uwp.UI.Controls.WinRT.vcxproj index df6c2abb1f9..b33e6b6661c 100644 --- a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Microsoft.Toolkit.Uwp.UI.Controls.WinRT.vcxproj +++ b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Microsoft.Toolkit.Uwp.UI.Controls.WinRT.vcxproj @@ -1,21 +1,5 @@ - - true - $(RequiredBundles);Microsoft.Windows.CppWinRT - true - {6e3ee614-2343-447d-b9f6-2a666b89940f} - Microsoft.Toolkit.Uwp.UI.Controls.WinRT - Microsoft_Toolkit_Uwp_UI_Controls_WinRT - en-US - 14.0 - true - Windows Store - 10.0 - 10.0.17134.0 - 10.0.17134.0 - - Debug @@ -42,88 +26,215 @@ x64 - + + {d4c7ac54-826a-4412-8461-a7c7fd86534b} + WindowsRuntimeComponent + Microsoft.Toolkit.Uwp.UI.Controls.WinRT + en-US + 14.0 + true + Windows Store + 10.0.17134.0 + 10.0.17134.0 + 10.0 + + + DynamicLibrary + true + v141 + + + DynamicLibrary + true v141 - Unicode - false - + + DynamicLibrary true - true + v141 + + + DynamicLibrary + false + true + v141 - + + DynamicLibrary false true - true + v141 + + + DynamicLibrary + false + true + v141 - + + + + + + + + + + + + + + + + - + + false + + + false + + + false + + + false + + + false + + + false + + Use + _WINRT_DLL;%(PreprocessorDefinitions) pch.h $(IntDir)pch.pch - Level4 - %(AdditionalOptions) /permissive- /bigobj + $(WindowsSDK_WindowsMetadata);$(AdditionalUsingDirectories) + /bigobj %(AdditionalOptions) + 28204 + stdcpplatest + + + Console + false + + + + + Use + _WINRT_DLL;NDEBUG;%(PreprocessorDefinitions) + pch.h + $(IntDir)pch.pch + $(WindowsSDK_WindowsMetadata);$(AdditionalUsingDirectories) + /bigobj %(AdditionalOptions) 28204 + stdcpplatest + + + Console + false + + + + + Use _WINRT_DLL;%(PreprocessorDefinitions) + pch.h + $(IntDir)pch.pch + $(WindowsSDK_WindowsMetadata);$(AdditionalUsingDirectories) + /bigobj %(AdditionalOptions) + 28204 + stdcpplatest + + + Console + false + + + + + Use + _WINRT_DLL;NDEBUG;%(PreprocessorDefinitions) + pch.h + $(IntDir)pch.pch $(WindowsSDK_WindowsMetadata);$(AdditionalUsingDirectories) + /bigobj %(AdditionalOptions) + 28204 + stdcpplatest Console - true - Microsoft_Toolkit_Uwp_UI_Controls_WinRT.def + false - + - _DEBUG;%(PreprocessorDefinitions) + Use + _WINRT_DLL;%(PreprocessorDefinitions) + pch.h + $(IntDir)pch.pch + $(WindowsSDK_WindowsMetadata);$(AdditionalUsingDirectories) + /bigobj %(AdditionalOptions) + 28204 + stdcpplatest + + Console + false + - + - NDEBUG;%(PreprocessorDefinitions) + Use + _WINRT_DLL;NDEBUG;%(PreprocessorDefinitions) + pch.h + $(IntDir)pch.pch + $(WindowsSDK_WindowsMetadata);$(AdditionalUsingDirectories) + /bigobj %(AdditionalOptions) + 28204 + stdcpplatest + + Console + false + - - + + + - - DirectWriteTextBlock.idl - - - + + + - Create + Create + Create + Create + Create + Create + Create - - DirectWriteTextBlock.idl - - - - - - - - diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Microsoft.Toolkit.Uwp.UI.Controls.WinRT.vcxproj.filters b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Microsoft.Toolkit.Uwp.UI.Controls.WinRT.vcxproj.filters index e14339c1399..87acdcaf468 100644 --- a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Microsoft.Toolkit.Uwp.UI.Controls.WinRT.vcxproj.filters +++ b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Microsoft.Toolkit.Uwp.UI.Controls.WinRT.vcxproj.filters @@ -1,59 +1,57 @@  - + + + + 843e9b69-b3be-436a-8063-712dd68c8c9e + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tga;tiff;tif;png;wav;mfcribbon-ms + + + {68b61fb4-e30f-4e13-a90a-d600506ffe67} + + + {100341cc-ce8e-481d-a525-78892e08dcd8} + + - - - - DirectWriteTextBlock - - - DirectWriteTextBlock + + UniversalWindowsAppPackageFontLoader UniversalWindowsAppPackageFontLoader - - UniversalWindowsAppPackageFontLoader + + DirectWriteTextBlock + + + DirectWriteTextBlock + + + DirectWriteTextBlock - - - DirectWriteTextBlock - - - DirectWriteTextBlock - - + UniversalWindowsAppPackageFontLoader UniversalWindowsAppPackageFontLoader - + UniversalWindowsAppPackageFontLoader - - - - - - - {5c9410b2-e6cd-4e91-80d5-5a476962d413} - - - {05649367-fea9-4b44-9514-f1d8e391d701} - - - - + DirectWriteTextBlock - + + + DirectWriteTextBlock + + + DirectWriteTextBlock + - - + \ No newline at end of file diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Microsoft_Toolkit_Uwp_UI_Controls_WinRT.def b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Microsoft_Toolkit_Uwp_UI_Controls_WinRT.def deleted file mode 100644 index 24e7c1235c3..00000000000 --- a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Microsoft_Toolkit_Uwp_UI_Controls_WinRT.def +++ /dev/null @@ -1,3 +0,0 @@ -EXPORTS -DllCanUnloadNow = WINRT_CanUnloadNow PRIVATE -DllGetActivationFactory = WINRT_GetActivationFactory PRIVATE diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Themes/Generic.xaml b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Themes/Generic.xaml new file mode 100644 index 00000000000..4d8210f4770 --- /dev/null +++ b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Themes/Generic.xaml @@ -0,0 +1,28 @@ + + + + + diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/UniversalWindowsAppPackageFontLoader/FontCollectionLoader.cpp b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/UniversalWindowsAppPackageFontLoader/FontCollectionLoader.cpp index 6f06a626c68..0e9c8593417 100644 --- a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/UniversalWindowsAppPackageFontLoader/FontCollectionLoader.cpp +++ b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/UniversalWindowsAppPackageFontLoader/FontCollectionLoader.cpp @@ -5,7 +5,9 @@ #include "FontFileEnumerator.h" #include "FontCollectionLoader.h" -namespace winrt::Microsoft_Toolkit_Uwp_UI_Controls_WinRT::implementation::UniversalWindowsAppPackageFontLoader +BEGIN_NAMESPACE_CONTROLS_WINRT + +namespace UniversalWindowsAppPackageFontLoader { winrt::com_ptr FontCollectionLoader::s_comInstance; @@ -17,19 +19,19 @@ namespace winrt::Microsoft_Toolkit_Uwp_UI_Controls_WinRT::implementation::Univer { } - bool FontCollectionLoader::HasCustomFontFamily(winrt::hstring const& xamlFontFamily) + bool FontCollectionLoader::HasCustomFontFamily(Platform::String^ xamlFontFamily) { // is there a .ttf in the path? - std::wstring wstringPath{ xamlFontFamily }; + std::wstring wstringPath{ xamlFontFamily->Data() }; std::transform(wstringPath.begin(), wstringPath.end(), wstringPath.begin(), towlower); auto foundCustomFontFile = wstringPath.find(L".ttf#", 0); return foundCustomFontFile != std::wstring::npos; } - void FontCollectionLoader::ParseXamlFontFamily(_In_ winrt::hstring const& xamlFontFamily, _Out_ UniversalPackageFontData& parsedFont) + void FontCollectionLoader::ParseXamlFontFamily(_In_ Platform::String^ xamlFontFamily, _Out_ UniversalPackageFontData& parsedFont) { parsedFont = {}; - std::wstring wstringPath{ xamlFontFamily }; + std::wstring wstringPath{ xamlFontFamily->Data() }; auto delimLocation = wstringPath.find(L'#'); if (delimLocation != std::wstring::npos) { @@ -40,11 +42,11 @@ namespace winrt::Microsoft_Toolkit_Uwp_UI_Controls_WinRT::implementation::Univer } } - bool FontCollectionLoader::FindCachedEnumerator(winrt::hstring const& xamlFontFamily, winrt::com_ptr& enumerator) + bool FontCollectionLoader::FindCachedEnumerator(Platform::String^ xamlFontFamily, winrt::com_ptr& enumerator) { for (auto& entry : m_fontEnumerators) { - if (entry.customFont == xamlFontFamily) + if (entry.customFont->Equals(xamlFontFamily)) { enumerator = entry.enumerator; return true; @@ -58,7 +60,7 @@ namespace winrt::Microsoft_Toolkit_Uwp_UI_Controls_WinRT::implementation::Univer try { *fontFileEnumerator = nullptr; - auto xamlFontFamily = winrt::hstring(reinterpret_cast(collectionKey), collectionKeySize); + auto xamlFontFamily = ref new Platform::String(reinterpret_cast(collectionKey), collectionKeySize); if (HasCustomFontFamily(xamlFontFamily)) { @@ -100,4 +102,6 @@ namespace winrt::Microsoft_Toolkit_Uwp_UI_Controls_WinRT::implementation::Univer return s_comInstance; } -} \ No newline at end of file +} + +END_NAMESPACE_CONTROLS_WINRT \ No newline at end of file diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/UniversalWindowsAppPackageFontLoader/FontCollectionLoader.h b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/UniversalWindowsAppPackageFontLoader/FontCollectionLoader.h index f916c86f28c..752f20df896 100644 --- a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/UniversalWindowsAppPackageFontLoader/FontCollectionLoader.h +++ b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/UniversalWindowsAppPackageFontLoader/FontCollectionLoader.h @@ -1,7 +1,9 @@ #pragma once #include "UniversalPackageFontData.h" -namespace winrt::Microsoft_Toolkit_Uwp_UI_Controls_WinRT::implementation::UniversalWindowsAppPackageFontLoader +BEGIN_NAMESPACE_CONTROLS_WINRT + +namespace UniversalWindowsAppPackageFontLoader { /// /// This is just to glue together a custom font file in the Universal Windows app package @@ -28,12 +30,12 @@ namespace winrt::Microsoft_Toolkit_Uwp_UI_Controls_WinRT::implementation::Univer /// This sees if the incoming XAML FontFamily value has something that looks like /// a custom font file like foo.ttf#bar /// - static bool HasCustomFontFamily(winrt::hstring const& xamlFontFamily); + static bool HasCustomFontFamily(Platform::String^ xamlFontFamily); /// /// This parses something that looks like /foo/bar.ttf#baz into the ttf path and the font name (baz). /// - static void ParseXamlFontFamily(winrt::hstring const& xamlFontFamily, _Out_ UniversalPackageFontData& parsedFont); + static void ParseXamlFontFamily(Platform::String^ xamlFontFamily, _Out_ UniversalPackageFontData& parsedFont); /// /// Get the singleton loader. @@ -43,14 +45,16 @@ namespace winrt::Microsoft_Toolkit_Uwp_UI_Controls_WinRT::implementation::Univer private: struct FontEnumeratorEntry { - winrt::hstring customFont; + Platform::String^ customFont; winrt::com_ptr enumerator; }; // enumerators are cached due to memory usages. - bool FindCachedEnumerator(winrt::hstring const& xamlFontFamily, winrt::com_ptr& enumerator); + bool FindCachedEnumerator(Platform::String^ xamlFontFamily, winrt::com_ptr& enumerator); std::vector m_fontEnumerators; static winrt::com_ptr s_comInstance; }; -} \ No newline at end of file +} + +END_NAMESPACE_CONTROLS_WINRT \ No newline at end of file diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/UniversalWindowsAppPackageFontLoader/FontFileEnumerator.cpp b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/UniversalWindowsAppPackageFontLoader/FontFileEnumerator.cpp index d42747c7009..eb7918564b6 100644 --- a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/UniversalWindowsAppPackageFontLoader/FontFileEnumerator.cpp +++ b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/UniversalWindowsAppPackageFontLoader/FontFileEnumerator.cpp @@ -1,9 +1,9 @@ #include "pch.h" -#include -#include #include "FontFileEnumerator.h" -namespace winrt::Microsoft_Toolkit_Uwp_UI_Controls_WinRT::implementation::UniversalWindowsAppPackageFontLoader +BEGIN_NAMESPACE_CONTROLS_WINRT + +namespace UniversalWindowsAppPackageFontLoader { using namespace Windows::Storage; @@ -39,8 +39,8 @@ namespace winrt::Microsoft_Toolkit_Uwp_UI_Controls_WinRT::implementation::Univer if (!m_enumerated) { m_currentFontFile = nullptr; - StorageFolder uwappStorage{ Windows::ApplicationModel::Package::Current().InstalledLocation() }; - std::wstring filePath{ uwappStorage.Path() }; + auto uwappStorage = Windows::ApplicationModel::Package::Current->InstalledLocation; + std::wstring filePath{ uwappStorage->Path->Data() }; filePath.append(m_packageFontArgs.packageFontFilePath); winrt::check_hresult(m_factory->CreateFontFileReference(filePath.c_str(), nullptr, m_currentFontFile.put())); @@ -65,4 +65,6 @@ namespace winrt::Microsoft_Toolkit_Uwp_UI_Controls_WinRT::implementation::Univer { return winrt::to_hresult(); } -} \ No newline at end of file +} + +END_NAMESPACE_CONTROLS_WINRT \ No newline at end of file diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/UniversalWindowsAppPackageFontLoader/FontFileEnumerator.h b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/UniversalWindowsAppPackageFontLoader/FontFileEnumerator.h index 0cf44058154..4597910b7fe 100644 --- a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/UniversalWindowsAppPackageFontLoader/FontFileEnumerator.h +++ b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/UniversalWindowsAppPackageFontLoader/FontFileEnumerator.h @@ -1,7 +1,9 @@ #pragma once #include "UniversalPackageFontData.h" -namespace winrt::Microsoft_Toolkit_Uwp_UI_Controls_WinRT::implementation::UniversalWindowsAppPackageFontLoader +BEGIN_NAMESPACE_CONTROLS_WINRT + +namespace UniversalWindowsAppPackageFontLoader { /// /// This is an enumerator that basically just enumerates 1 custom font into DWrite from the Universal Windows App package. @@ -35,4 +37,6 @@ namespace winrt::Microsoft_Toolkit_Uwp_UI_Controls_WinRT::implementation::Univer UniversalPackageFontData m_packageFontArgs = {}; bool m_enumerated = false; }; -} \ No newline at end of file +} + +END_NAMESPACE_CONTROLS_WINRT \ No newline at end of file diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/UniversalWindowsAppPackageFontLoader/UniversalPackageFontData.h b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/UniversalWindowsAppPackageFontLoader/UniversalPackageFontData.h index b855a38654b..04240aaa30b 100644 --- a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/UniversalWindowsAppPackageFontLoader/UniversalPackageFontData.h +++ b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/UniversalWindowsAppPackageFontLoader/UniversalPackageFontData.h @@ -1,10 +1,14 @@ #pragma once -namespace winrt::Microsoft_Toolkit_Uwp_UI_Controls_WinRT::implementation::UniversalWindowsAppPackageFontLoader +BEGIN_NAMESPACE_CONTROLS_WINRT + +namespace UniversalWindowsAppPackageFontLoader { struct UniversalPackageFontData { std::wstring packageFontFilePath; std::wstring customFontName; }; -} \ No newline at end of file +} + +END_NAMESPACE_CONTROLS_WINRT \ No newline at end of file diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/pch.h b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/pch.h index fb3dea334d0..7c7ca2512d8 100644 --- a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/pch.h +++ b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/pch.h @@ -1,17 +1,6 @@ -// -// pch.h -// Header for platform projection include files -// - -#pragma once - -#include "winrt/Windows.Foundation.h" - -// these are here if we have a .xaml file. -#include -#include -#include +#pragma once +#include #include #include #include @@ -19,3 +8,8 @@ #include #include #include + +#define BEGIN_NAMESPACE_CONTROLS_WINRT namespace Microsoft { namespace Toolkit { namespace Uwp { namespace UI { namespace Controls { namespace WinRT { +#define END_NAMESPACE_CONTROLS_WINRT } } } } } } + +#include "DirectWriteTextBlock\DirectWriteTextBlock.h" \ No newline at end of file diff --git a/Windows Community Toolkit.sln b/Windows Community Toolkit.sln index fb0e4e311a7..255af9c3596 100644 --- a/Windows Community Toolkit.sln +++ b/Windows Community Toolkit.sln @@ -92,6 +92,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Toolkit.Uwp.UI.Co {3DD8AA7C-3569-4E51-992F-0C2257E8878E} = {3DD8AA7C-3569-4E51-992F-0C2257E8878E} EndProjectSection EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Microsoft.Toolkit.Uwp.UI.Controls.WinRT", "Microsoft.Toolkit.Uwp.UI.Controls.WinRT\Microsoft.Toolkit.Uwp.UI.Controls.WinRT.vcxproj", "{D4C7AC54-826A-4412-8461-A7C7FD86534B}" +EndProject Global GlobalSection(SharedMSBuildProjectFiles) = preSolution UnitTests\UnitTests.Notifications.Shared\UnitTests.Notifications.Shared.projitems*{982cc826-aacd-4855-9075-430bb6ce40a9}*SharedItemsImports = 13 @@ -658,6 +660,28 @@ Global {D4D78CBA-B238-4794-89A0-4F1A2D8FEA97}.Release|x64.Build.0 = Release|Any CPU {D4D78CBA-B238-4794-89A0-4F1A2D8FEA97}.Release|x86.ActiveCfg = Release|Any CPU {D4D78CBA-B238-4794-89A0-4F1A2D8FEA97}.Release|x86.Build.0 = Release|Any CPU + {D4C7AC54-826A-4412-8461-A7C7FD86534B}.Debug|Any CPU.ActiveCfg = Debug|Win32 + {D4C7AC54-826A-4412-8461-A7C7FD86534B}.Debug|ARM.ActiveCfg = Debug|ARM + {D4C7AC54-826A-4412-8461-A7C7FD86534B}.Debug|ARM.Build.0 = Debug|ARM + {D4C7AC54-826A-4412-8461-A7C7FD86534B}.Debug|x64.ActiveCfg = Debug|x64 + {D4C7AC54-826A-4412-8461-A7C7FD86534B}.Debug|x64.Build.0 = Debug|x64 + {D4C7AC54-826A-4412-8461-A7C7FD86534B}.Debug|x86.ActiveCfg = Debug|Win32 + {D4C7AC54-826A-4412-8461-A7C7FD86534B}.Debug|x86.Build.0 = Debug|Win32 + {D4C7AC54-826A-4412-8461-A7C7FD86534B}.Native|Any CPU.ActiveCfg = Release|x64 + {D4C7AC54-826A-4412-8461-A7C7FD86534B}.Native|Any CPU.Build.0 = Release|x64 + {D4C7AC54-826A-4412-8461-A7C7FD86534B}.Native|ARM.ActiveCfg = Release|ARM + {D4C7AC54-826A-4412-8461-A7C7FD86534B}.Native|ARM.Build.0 = Release|ARM + {D4C7AC54-826A-4412-8461-A7C7FD86534B}.Native|x64.ActiveCfg = Release|x64 + {D4C7AC54-826A-4412-8461-A7C7FD86534B}.Native|x64.Build.0 = Release|x64 + {D4C7AC54-826A-4412-8461-A7C7FD86534B}.Native|x86.ActiveCfg = Release|Win32 + {D4C7AC54-826A-4412-8461-A7C7FD86534B}.Native|x86.Build.0 = Release|Win32 + {D4C7AC54-826A-4412-8461-A7C7FD86534B}.Release|Any CPU.ActiveCfg = Release|Win32 + {D4C7AC54-826A-4412-8461-A7C7FD86534B}.Release|ARM.ActiveCfg = Release|ARM + {D4C7AC54-826A-4412-8461-A7C7FD86534B}.Release|ARM.Build.0 = Release|ARM + {D4C7AC54-826A-4412-8461-A7C7FD86534B}.Release|x64.ActiveCfg = Release|x64 + {D4C7AC54-826A-4412-8461-A7C7FD86534B}.Release|x64.Build.0 = Release|x64 + {D4C7AC54-826A-4412-8461-A7C7FD86534B}.Release|x86.ActiveCfg = Release|Win32 + {D4C7AC54-826A-4412-8461-A7C7FD86534B}.Release|x86.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE From 0f5b748683de3ebdf9c5524f0532326a8014e651 Mon Sep 17 00:00:00 2001 From: "Jun Ma (WINDOWS)" Date: Tue, 2 Oct 2018 20:13:33 +0900 Subject: [PATCH 03/29] delete generated files --- .../Generated Files/Themes/Generic.g.h | 1 - .../Generated Files/Themes/Generic.g.h | 1 - .../Generated Files/Themes/Generic.g.hpp | 1 - .../Generated Files/Themes/Generic.g.h | 1 - .../Generated Files/Themes/Generic.g.hpp | 1 - .../Generated Files/Themes/Generic.g.h | 1 - .../Generated Files/Themes/Generic.g.hpp | 1 - .../Generated Files/Themes/Generic.g.h | 1 - .../Generated Files/Themes/Generic.g.hpp | 1 - .../Generated Files/Themes/Generic.xaml | 29 - .../Generated Files/Themes/Generic.xbf | Bin 1205 -> 0 bytes .../Generated Files/XamlBindingInfo.g.h | 265 -------- .../Generated Files/XamlBindingInfo.g.hpp | 237 ------- .../XamlLibMetadataProvider.g.cpp | 2 - .../Generated Files/XamlTypeInfo.Impl.g.cpp | 588 ------------------ .../Generated Files/XamlTypeInfo.g.cpp | 372 ----------- .../Generated Files/XamlTypeInfo.g.h | 383 ------------ 17 files changed, 1885 deletions(-) delete mode 100644 Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Generated Files/Generated Files/Generated Files/Generated Files/Generated Files/Themes/Generic.g.h delete mode 100644 Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Generated Files/Generated Files/Generated Files/Generated Files/Themes/Generic.g.h delete mode 100644 Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Generated Files/Generated Files/Generated Files/Generated Files/Themes/Generic.g.hpp delete mode 100644 Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Generated Files/Generated Files/Generated Files/Themes/Generic.g.h delete mode 100644 Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Generated Files/Generated Files/Generated Files/Themes/Generic.g.hpp delete mode 100644 Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Generated Files/Generated Files/Themes/Generic.g.h delete mode 100644 Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Generated Files/Generated Files/Themes/Generic.g.hpp delete mode 100644 Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Generated Files/Themes/Generic.g.h delete mode 100644 Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Generated Files/Themes/Generic.g.hpp delete mode 100644 Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Generated Files/Themes/Generic.xaml delete mode 100644 Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Generated Files/Themes/Generic.xbf delete mode 100644 Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Generated Files/XamlBindingInfo.g.h delete mode 100644 Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Generated Files/XamlBindingInfo.g.hpp delete mode 100644 Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Generated Files/XamlLibMetadataProvider.g.cpp delete mode 100644 Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Generated Files/XamlTypeInfo.Impl.g.cpp delete mode 100644 Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Generated Files/XamlTypeInfo.g.cpp delete mode 100644 Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Generated Files/XamlTypeInfo.g.h diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Generated Files/Generated Files/Generated Files/Generated Files/Generated Files/Themes/Generic.g.h b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Generated Files/Generated Files/Generated Files/Generated Files/Generated Files/Themes/Generic.g.h deleted file mode 100644 index 30259b2af6f..00000000000 --- a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Generated Files/Generated Files/Generated Files/Generated Files/Generated Files/Themes/Generic.g.h +++ /dev/null @@ -1 +0,0 @@ - diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Generated Files/Generated Files/Generated Files/Generated Files/Themes/Generic.g.h b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Generated Files/Generated Files/Generated Files/Generated Files/Themes/Generic.g.h deleted file mode 100644 index 30259b2af6f..00000000000 --- a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Generated Files/Generated Files/Generated Files/Generated Files/Themes/Generic.g.h +++ /dev/null @@ -1 +0,0 @@ - diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Generated Files/Generated Files/Generated Files/Generated Files/Themes/Generic.g.hpp b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Generated Files/Generated Files/Generated Files/Generated Files/Themes/Generic.g.hpp deleted file mode 100644 index 30259b2af6f..00000000000 --- a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Generated Files/Generated Files/Generated Files/Generated Files/Themes/Generic.g.hpp +++ /dev/null @@ -1 +0,0 @@ - diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Generated Files/Generated Files/Generated Files/Themes/Generic.g.h b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Generated Files/Generated Files/Generated Files/Themes/Generic.g.h deleted file mode 100644 index 30259b2af6f..00000000000 --- a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Generated Files/Generated Files/Generated Files/Themes/Generic.g.h +++ /dev/null @@ -1 +0,0 @@ - diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Generated Files/Generated Files/Generated Files/Themes/Generic.g.hpp b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Generated Files/Generated Files/Generated Files/Themes/Generic.g.hpp deleted file mode 100644 index 30259b2af6f..00000000000 --- a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Generated Files/Generated Files/Generated Files/Themes/Generic.g.hpp +++ /dev/null @@ -1 +0,0 @@ - diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Generated Files/Generated Files/Themes/Generic.g.h b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Generated Files/Generated Files/Themes/Generic.g.h deleted file mode 100644 index 30259b2af6f..00000000000 --- a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Generated Files/Generated Files/Themes/Generic.g.h +++ /dev/null @@ -1 +0,0 @@ - diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Generated Files/Generated Files/Themes/Generic.g.hpp b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Generated Files/Generated Files/Themes/Generic.g.hpp deleted file mode 100644 index 30259b2af6f..00000000000 --- a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Generated Files/Generated Files/Themes/Generic.g.hpp +++ /dev/null @@ -1 +0,0 @@ - diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Generated Files/Themes/Generic.g.h b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Generated Files/Themes/Generic.g.h deleted file mode 100644 index 30259b2af6f..00000000000 --- a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Generated Files/Themes/Generic.g.h +++ /dev/null @@ -1 +0,0 @@ - diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Generated Files/Themes/Generic.g.hpp b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Generated Files/Themes/Generic.g.hpp deleted file mode 100644 index 30259b2af6f..00000000000 --- a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Generated Files/Themes/Generic.g.hpp +++ /dev/null @@ -1 +0,0 @@ - diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Generated Files/Themes/Generic.xaml b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Generated Files/Themes/Generic.xaml deleted file mode 100644 index 61c54a016a6..00000000000 --- a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Generated Files/Themes/Generic.xaml +++ /dev/null @@ -1,29 +0,0 @@ - - - - - - diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Generated Files/Themes/Generic.xbf b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Generated Files/Themes/Generic.xbf deleted file mode 100644 index 49ec1d4b6f4933e522a1deaed284638c67a65134..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1205 zcmcIjOK%cU6#f{PVG4!PW)ex8HV|tuv5zUl2Gp3eP?9EA6I+W57t(g5O&>#m26Qzu zOBcF!)4$@%f8dUl8~=h^zjFccwbXla=Dff2n3?BWRa}RGcnHt{kfBGCb4a_K%OQU= z5hDfWqNkt)<>x+7-SC<%%~ufzE}*dnq^-x(v5q&>VQibPxxeSme$ zh%T)_j`Xj4oc*n;Oe8(EeyKj{ckBfs%pBPPo!Sn&u5*(PWmDlg)LiNr?rnz_gY;OT zOXT@5ZiFKHsdKyIxUpr5)=}IOwZ}id7O8o_YAtS1zQ#d?*iV^{SbJcX9;IhNSz&j3 zl;!UdlF5Y2k(iMz`tYav!Nn(k=E(k@@-^ub=`-moX@utJ%x12i`s@4f1o1Mc3@>EvQZ;8p}~qI&CJ6?^L}Wt@9PGvlt1^y*Q3a0`o8ti wn{W8Q^p(fVY_#udm`sOK8-}rvFmt9hV^#fxZen&fh<{MvSu7ufF(1LgcY{*0f&c&j diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Generated Files/XamlBindingInfo.g.h b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Generated Files/XamlBindingInfo.g.h deleted file mode 100644 index 1fb2525387e..00000000000 --- a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Generated Files/XamlBindingInfo.g.h +++ /dev/null @@ -1,265 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ -#pragma once - -namespace XamlBindingInfo -{ - ref class XamlBindings; - - class IXamlBindings - { - public: - virtual ~IXamlBindings() {}; - virtual bool IsInitialized() = 0; - virtual void Update() = 0; - virtual bool SetDataRoot(::Platform::Object^ data) = 0; - virtual void StopTracking() = 0; - virtual void Connect(int connectionId, ::Platform::Object^ target) = 0; - virtual void Recycle() = 0; - virtual void ProcessBindings(::Platform::Object^ item, int itemIndex, int phase, int* nextPhase) = 0; - virtual void SubscribeForDataContextChanged(::Windows::UI::Xaml::FrameworkElement^ object, ::XamlBindingInfo::XamlBindings^ handler) = 0; - virtual void DisconnectUnloadedObject(int connectionId) = 0; - }; - - class IXamlBindingTracking - { - public: - virtual void PropertyChanged(Platform::Object^ sender, ::Windows::UI::Xaml::Data::PropertyChangedEventArgs^ e) = 0; - virtual void CollectionChanged(::Platform::Object^ sender, ::Windows::UI::Xaml::Interop::NotifyCollectionChangedEventArgs^ e) = 0; - virtual void DependencyPropertyChanged(::Windows::UI::Xaml::DependencyObject^ sender, Windows::UI::Xaml::DependencyProperty^ prop) = 0; - virtual void VectorChanged(::Platform::Object^ sender, ::Windows::Foundation::Collections::IVectorChangedEventArgs^ e) = 0; - virtual void MapChanged(::Platform::Object^ sender, ::Windows::Foundation::Collections::IMapChangedEventArgs<::Platform::String^>^ e) = 0; - }; - - ref class XamlBindings sealed : - ::Windows::UI::Xaml::IDataTemplateExtension, - ::Windows::UI::Xaml::Markup::IComponentConnector, - ::Windows::UI::Xaml::Markup::IDataTemplateComponent - { - internal: - XamlBindings(::XamlBindingInfo::IXamlBindings* pBindings); - void Initialize(); - void Update(); - void StopTracking(); - void Loading(::Windows::UI::Xaml::FrameworkElement^ src, ::Platform::Object^ data); - void DataContextChanged(::Windows::UI::Xaml::FrameworkElement^ sender, ::Windows::UI::Xaml::DataContextChangedEventArgs^ args); - void SubscribeForDataContextChanged(::Windows::UI::Xaml::FrameworkElement^ object); - - public: - // IComponentConnector - virtual void Connect(int connectionId, ::Platform::Object^ target); - - // IDataTemplateComponent - virtual void ProcessBindings(::Platform::Object^ item, int itemIndex, int phase, int* nextPhase); - virtual void Recycle(); - - // IDataTemplateExtension - virtual bool ProcessBinding(unsigned int); - virtual int ProcessBindings(::Windows::UI::Xaml::Controls::ContainerContentChangingEventArgs^ args); - virtual void ResetTemplate(); - - virtual void DisconnectUnloadedObject(int connectionId); - private: - ~XamlBindings(); - ::XamlBindingInfo::IXamlBindings* _pBindings = nullptr; - }; - - template - class XamlBindingsBase : public IXamlBindings - { - protected: - bool _isInitialized; - TBindingsTracking^ _bindingsTracking; - ::Windows::Foundation::EventRegistrationToken _dataContextChangedToken; - static const int NOT_PHASED = (1 << 31); - static const int DATA_CHANGED = (1 << 30); - - protected: - XamlBindingsBase() - : _isInitialized(false) - , _bindingsTracking(nullptr) - { - _dataContextChangedToken.Value = 0; - } - - virtual ~XamlBindingsBase() - { - if (_bindingsTracking != nullptr) - { - _bindingsTracking->SetListener(nullptr); - _bindingsTracking = nullptr; - } - } - - virtual void ReleaseAllListeners() - { - // Overridden in the binding class as needed. - } - - public: - void InitializeTracking(::XamlBindingInfo::IXamlBindingTracking* pBindingsTracking) - { - _bindingsTracking = ref new TBindingsTracking(); - _bindingsTracking->SetListener(pBindingsTracking); - } - - virtual void StopTracking() override - { - ReleaseAllListeners(); - this->_isInitialized = false; - } - - virtual bool IsInitialized() override - { - return this->_isInitialized; - } - - virtual void Update() = 0; - - void SubscribeForDataContextChanged(::Windows::UI::Xaml::FrameworkElement^ object, ::XamlBindingInfo::XamlBindings^ handler) - { - this->_dataContextChangedToken = object->DataContextChanged += - ref new Windows::Foundation::TypedEventHandler<::Windows::UI::Xaml::FrameworkElement^, ::Windows::UI::Xaml::DataContextChangedEventArgs^>( - handler, &::XamlBindingInfo::XamlBindings::DataContextChanged); - } - - virtual void Connect(int connectionId, ::Platform::Object^ target) = 0; - - virtual void Recycle() - { - // Overridden in the binding class as needed. - } - - virtual void ProcessBindings(::Platform::Object^, int, int, int* nextPhase) - { - // Overridden in the binding class as needed. - *nextPhase = -1; - } - }; - - ref class XamlBindingTrackingBase - { - internal: - XamlBindingTrackingBase(); - void SetListener(::XamlBindingInfo::IXamlBindingTracking* pBindings); - - // Event handlers - void PropertyChanged(Platform::Object^ sender, ::Windows::UI::Xaml::Data::PropertyChangedEventArgs^ e); - void CollectionChanged(::Platform::Object^ sender, ::Windows::UI::Xaml::Interop::NotifyCollectionChangedEventArgs^ e); - void DependencyPropertyChanged(::Windows::UI::Xaml::DependencyObject^ sender, Windows::UI::Xaml::DependencyProperty^ prop); - void VectorChanged(::Platform::Object^ sender, ::Windows::Foundation::Collections::IVectorChangedEventArgs^ e); - void MapChanged(::Platform::Object^ sender, ::Windows::Foundation::Collections::IMapChangedEventArgs<::Platform::String^>^ e); - - // Listener update functions - void UpdatePropertyChangedListener(::Windows::UI::Xaml::Data::INotifyPropertyChanged^ obj, ::Windows::UI::Xaml::Data::INotifyPropertyChanged^* pCache, ::Windows::Foundation::EventRegistrationToken* pToken); - void UpdatePropertyChangedListener(::Windows::UI::Xaml::Data::INotifyPropertyChanged^ obj, ::Platform::WeakReference& cacheRef, ::Windows::Foundation::EventRegistrationToken* pToken); - void UpdateCollectionChangedListener(::Windows::UI::Xaml::Interop::INotifyCollectionChanged^ obj, ::Windows::UI::Xaml::Interop::INotifyCollectionChanged^* pCache, ::Windows::Foundation::EventRegistrationToken* pToken); - void UpdateDependencyPropertyChangedListener(::Windows::UI::Xaml::DependencyObject^ obj, Windows::UI::Xaml::DependencyProperty^ property, ::Windows::UI::Xaml::DependencyObject^* pCache, __int64* pToken); - void UpdateDependencyPropertyChangedListener(::Windows::UI::Xaml::DependencyObject^ obj, Windows::UI::Xaml::DependencyProperty^ property, ::Platform::WeakReference& cacheRef, __int64* pToken); - - private: - ::XamlBindingInfo::IXamlBindingTracking* _pBindingsTrackingWeakRef = nullptr; - }; - - template - struct ResolveHelper - { - static T^ Resolve(const ::Platform::WeakReference& wr) - { - return wr.Resolve(); - } - }; - - template <> - struct ResolveHelper<::Platform::String> - { - typedef ::Platform::IBox<::Platform::String^> ResolveType; - - static ::Platform::String^ Resolve(const ::Platform::WeakReference& wr) - { - return safe_cast<::Platform::String^>(wr.Resolve()); - } - - }; - - template - class ReferenceTypeXamlBindings : public XamlBindingsBase - { - private: - ::Platform::WeakReference _dataRoot; - - protected: - ReferenceTypeXamlBindings() {} - - virtual void Update_(T^, int) - { - // Overridden in the binding class as needed. - } - - public: - T^ GetDataRoot() - { - return ResolveHelper::Resolve(this->_dataRoot); - } - - bool SetDataRoot(::Platform::Object^ data) - { - if (data != nullptr) - { - this->_dataRoot = data; - return true; - } - return false; - } - - virtual void Update() override - { - this->Update_(this->GetDataRoot(), this->NOT_PHASED); - this->_isInitialized = true; - } - }; - - template - class ValueTypeXamlBindings : public XamlBindingsBase - { - private: - T _dataRoot; - - protected: - ValueTypeXamlBindings() {} - - virtual void Update_(T, int) - { - // Overridden in the binding class as needed. - } - - public: - T GetDataRoot() - { - return this->_dataRoot; - } - - bool SetDataRoot(::Platform::Object^ data) - { - if (data != nullptr) - { - this->_dataRoot = safe_cast(data); - return true; - } - return false; - } - - virtual void Update() override - { - this->Update_(this->GetDataRoot(), this->NOT_PHASED); - this->_isInitialized = true; - } - }; -} - diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Generated Files/XamlBindingInfo.g.hpp b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Generated Files/XamlBindingInfo.g.hpp deleted file mode 100644 index a65394b6791..00000000000 --- a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Generated Files/XamlBindingInfo.g.hpp +++ /dev/null @@ -1,237 +0,0 @@ - -//------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ -#include "pch.h" -#include "XamlBindingInfo.g.h" - -// XamlBindings - -::XamlBindingInfo::XamlBindings::XamlBindings(::XamlBindingInfo::IXamlBindings* pBindings) - : _pBindings(pBindings) -{ -} - -::XamlBindingInfo::XamlBindings::~XamlBindings() -{ - delete _pBindings; -} - -void ::XamlBindingInfo::XamlBindings::Initialize() -{ - if (!this->_pBindings->IsInitialized()) - { - this->_pBindings->Update(); - } -} - -void ::XamlBindingInfo::XamlBindings::Update() -{ - this->_pBindings->Update(); -} - -void ::XamlBindingInfo::XamlBindings::StopTracking() -{ - this->_pBindings->StopTracking(); -} - -void ::XamlBindingInfo::XamlBindings::Loading(::Windows::UI::Xaml::FrameworkElement^, ::Platform::Object^) -{ - this->Initialize(); -} - -void ::XamlBindingInfo::XamlBindings::DataContextChanged(::Windows::UI::Xaml::FrameworkElement^, ::Windows::UI::Xaml::DataContextChangedEventArgs^ args) -{ - if (this->_pBindings->SetDataRoot(args->NewValue)) - { - this->Update(); - } -} - -void ::XamlBindingInfo::XamlBindings::SubscribeForDataContextChanged(::Windows::UI::Xaml::FrameworkElement^ object) -{ - this->_pBindings->SubscribeForDataContextChanged(object, this); -} - -void ::XamlBindingInfo::XamlBindings::DisconnectUnloadedObject(int connectionId) -{ - this->_pBindings->DisconnectUnloadedObject(connectionId); -} - -void ::XamlBindingInfo::XamlBindings::Connect(int connectionId, ::Platform::Object^ target) -{ - this->_pBindings->Connect(connectionId, target); -} - -bool ::XamlBindingInfo::XamlBindings::ProcessBinding(unsigned int) -{ - throw ref new ::Platform::NotImplementedException(); -} - -int ::XamlBindingInfo::XamlBindings::ProcessBindings(::Windows::UI::Xaml::Controls::ContainerContentChangingEventArgs^ args) -{ - int nextPhase = -1; - int phase = static_cast(args->Phase); - if (phase < 0) - { - throw ref new ::Platform::InvalidArgumentException(); - } - this->_pBindings->ProcessBindings(args->Item, args->ItemIndex, phase, &nextPhase); - return nextPhase; -} - -void ::XamlBindingInfo::XamlBindings::ResetTemplate() -{ - this->_pBindings->Recycle(); -} - -void ::XamlBindingInfo::XamlBindings::ProcessBindings(::Platform::Object^ item, int itemIndex, int phase, int* nextPhase) -{ - this->_pBindings->ProcessBindings(item, itemIndex, phase, nextPhase); -} - -void ::XamlBindingInfo::XamlBindings::Recycle() -{ - this->_pBindings->Recycle(); -} - -// XamlBindingTrackingBase - -::XamlBindingInfo::XamlBindingTrackingBase::XamlBindingTrackingBase() -{ -} - -void ::XamlBindingInfo::XamlBindingTrackingBase::SetListener(::XamlBindingInfo::IXamlBindingTracking* pBindings) -{ - this->_pBindingsTrackingWeakRef = pBindings; -} - -void ::XamlBindingInfo::XamlBindingTrackingBase::PropertyChanged(Platform::Object^ sender, ::Windows::UI::Xaml::Data::PropertyChangedEventArgs^ e) -{ - if (this->_pBindingsTrackingWeakRef != nullptr) - { - this->_pBindingsTrackingWeakRef->PropertyChanged(sender, e); - } -} - -void ::XamlBindingInfo::XamlBindingTrackingBase::CollectionChanged(::Platform::Object^ sender, ::Windows::UI::Xaml::Interop::NotifyCollectionChangedEventArgs^ e) -{ - if (this->_pBindingsTrackingWeakRef != nullptr) - { - this->_pBindingsTrackingWeakRef->CollectionChanged(sender, e); - } -} - -void ::XamlBindingInfo::XamlBindingTrackingBase::DependencyPropertyChanged(::Windows::UI::Xaml::DependencyObject^ sender, ::Windows::UI::Xaml::DependencyProperty^ prop) -{ - if (this->_pBindingsTrackingWeakRef != nullptr) - { - this->_pBindingsTrackingWeakRef->DependencyPropertyChanged(sender, prop); - } -} - -void ::XamlBindingInfo::XamlBindingTrackingBase::VectorChanged(::Platform::Object^ sender, ::Windows::Foundation::Collections::IVectorChangedEventArgs^ e) -{ - if (this->_pBindingsTrackingWeakRef != nullptr) - { - this->_pBindingsTrackingWeakRef->VectorChanged(sender, e); - } -} - -void ::XamlBindingInfo::XamlBindingTrackingBase::MapChanged(::Platform::Object^ sender, ::Windows::Foundation::Collections::IMapChangedEventArgs<::Platform::String^>^ e) -{ - if (this->_pBindingsTrackingWeakRef != nullptr) - { - this->_pBindingsTrackingWeakRef->MapChanged(sender, e); - } -} - -void ::XamlBindingInfo::XamlBindingTrackingBase::UpdatePropertyChangedListener(::Windows::UI::Xaml::Data::INotifyPropertyChanged^ obj, ::Windows::UI::Xaml::Data::INotifyPropertyChanged^* pCache, ::Windows::Foundation::EventRegistrationToken* pToken) -{ - if (*pCache != nullptr && !(*pCache)->Equals(obj)) - { - (*pCache)->PropertyChanged -= *pToken; - *pCache = nullptr; - } - - if (*pCache == nullptr && obj != nullptr) - { - *pCache = obj; - *pToken = obj->PropertyChanged += ref new ::Windows::UI::Xaml::Data::PropertyChangedEventHandler( - this, &::XamlBindingInfo::XamlBindingTrackingBase::PropertyChanged); - } -} - -void ::XamlBindingInfo::XamlBindingTrackingBase::UpdatePropertyChangedListener(::Windows::UI::Xaml::Data::INotifyPropertyChanged^ obj, ::Platform::WeakReference& cacheRef, ::Windows::Foundation::EventRegistrationToken* pToken) -{ - ::Windows::UI::Xaml::Data::INotifyPropertyChanged^ cache = cacheRef.Resolve<::Windows::UI::Xaml::Data::INotifyPropertyChanged>(); - if (cache != nullptr && !cache->Equals(obj)) - { - cache->PropertyChanged -= *pToken; - cache = nullptr; - cacheRef = nullptr; - } - - if (cache == nullptr && obj != nullptr) - { - cacheRef = cache = obj; - *pToken = obj->PropertyChanged += ref new ::Windows::UI::Xaml::Data::PropertyChangedEventHandler( - this, &::XamlBindingInfo::XamlBindingTrackingBase::PropertyChanged); - } -} - -void ::XamlBindingInfo::XamlBindingTrackingBase::UpdateCollectionChangedListener(::Windows::UI::Xaml::Interop::INotifyCollectionChanged^ obj, ::Windows::UI::Xaml::Interop::INotifyCollectionChanged^* pCache, ::Windows::Foundation::EventRegistrationToken* pToken) -{ - if (*pCache != nullptr && !(*pCache)->Equals(obj)) - { - (*pCache)->CollectionChanged -= *pToken; - *pCache = nullptr; - } - - if (*pCache == nullptr && obj != nullptr) - { - *pCache = obj; - *pToken = obj->CollectionChanged += ref new ::Windows::UI::Xaml::Interop::NotifyCollectionChangedEventHandler( - this, &::XamlBindingInfo::XamlBindingTrackingBase::CollectionChanged); - } -} - -void ::XamlBindingInfo::XamlBindingTrackingBase::UpdateDependencyPropertyChangedListener(::Windows::UI::Xaml::DependencyObject^ obj, ::Windows::UI::Xaml::DependencyProperty^ property, ::Windows::UI::Xaml::DependencyObject^* pCache, __int64* pToken) -{ - if (*pCache != nullptr && !(*pCache)->Equals(obj)) - { - (*pCache)->UnregisterPropertyChangedCallback(property, *pToken); - *pCache = nullptr; - } - - if (*pCache == nullptr && obj != nullptr) - { - *pCache = obj; - *pToken = obj->RegisterPropertyChangedCallback(property, ref new ::Windows::UI::Xaml::DependencyPropertyChangedCallback( - this, &::XamlBindingInfo::XamlBindingTrackingBase::DependencyPropertyChanged)); - } -} - -void ::XamlBindingInfo::XamlBindingTrackingBase::UpdateDependencyPropertyChangedListener(::Windows::UI::Xaml::DependencyObject^ obj, ::Windows::UI::Xaml::DependencyProperty^ property, ::Platform::WeakReference& cacheRef, __int64* pToken) -{ - ::Windows::UI::Xaml::DependencyObject^ cache = cacheRef.Resolve<::Windows::UI::Xaml::DependencyObject>(); - if (cache != nullptr && !cache->Equals(obj)) - { - cache->UnregisterPropertyChangedCallback(property, *pToken); - cache = nullptr; - cacheRef = nullptr; - } - - if (cache == nullptr && obj != nullptr) - { - cacheRef = cache = obj; - *pToken = obj->RegisterPropertyChangedCallback(property, ref new ::Windows::UI::Xaml::DependencyPropertyChangedCallback( - this, &::XamlBindingInfo::XamlBindingTrackingBase::DependencyPropertyChanged)); - } -} - diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Generated Files/XamlLibMetadataProvider.g.cpp b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Generated Files/XamlLibMetadataProvider.g.cpp deleted file mode 100644 index 05de5ad1e1c..00000000000 --- a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Generated Files/XamlLibMetadataProvider.g.cpp +++ /dev/null @@ -1,2 +0,0 @@ - -#include "pch.h" diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Generated Files/XamlTypeInfo.Impl.g.cpp b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Generated Files/XamlTypeInfo.Impl.g.cpp deleted file mode 100644 index 2bd1fd87ae6..00000000000 --- a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Generated Files/XamlTypeInfo.Impl.g.cpp +++ /dev/null @@ -1,588 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ -#include "pch.h" -#include -#include "XamlTypeInfo.g.h" - - -// XamlMetaDataProvider -namespace Microsoft -{ - namespace Toolkit - { - namespace Uwp - { - namespace UI - { - namespace Controls - { - namespace WinRT - { - namespace Microsoft_Toolkit_Uwp_UI_Controls_WinRT_XamlTypeInfo - { - [Windows::Foundation::Metadata::WebHostHidden] - public ref class XamlMetaDataProvider sealed : public ::Windows::UI::Xaml::Markup::IXamlMetadataProvider - { - public: - [::Windows::Foundation::Metadata::DefaultOverload] - virtual ::Windows::UI::Xaml::Markup::IXamlType^ GetXamlType(::Windows::UI::Xaml::Interop::TypeName type); - virtual ::Windows::UI::Xaml::Markup::IXamlType^ GetXamlType(::Platform::String^ fullName); - virtual ::Platform::Array<::Windows::UI::Xaml::Markup::XmlnsDefinition>^ GetXmlnsDefinitions(); - - private: - ::XamlTypeInfo::InfoProvider::XamlTypeInfoProvider^ _provider; - property ::XamlTypeInfo::InfoProvider::XamlTypeInfoProvider^ Provider - { - ::XamlTypeInfo::InfoProvider::XamlTypeInfoProvider^ get(); - } - }; - } - } - } - } - } - } -} - -[::Windows::Foundation::Metadata::DefaultOverload] -::Windows::UI::Xaml::Markup::IXamlType^ ::Microsoft::Toolkit::Uwp::UI::Controls::WinRT::Microsoft_Toolkit_Uwp_UI_Controls_WinRT_XamlTypeInfo::XamlMetaDataProvider::GetXamlType(::Windows::UI::Xaml::Interop::TypeName type) -{ - return Provider->GetXamlTypeByType(type); -} - -::Windows::UI::Xaml::Markup::IXamlType^ ::Microsoft::Toolkit::Uwp::UI::Controls::WinRT::Microsoft_Toolkit_Uwp_UI_Controls_WinRT_XamlTypeInfo::XamlMetaDataProvider::GetXamlType(Platform::String^ fullName) -{ - return Provider->GetXamlTypeByName(fullName); -} - -Platform::Array<::Windows::UI::Xaml::Markup::XmlnsDefinition>^ ::Microsoft::Toolkit::Uwp::UI::Controls::WinRT::Microsoft_Toolkit_Uwp_UI_Controls_WinRT_XamlTypeInfo::XamlMetaDataProvider::GetXmlnsDefinitions() -{ - return ref new Platform::Array<::Windows::UI::Xaml::Markup::XmlnsDefinition>(0); -} - -::XamlTypeInfo::InfoProvider::XamlTypeInfoProvider^ ::Microsoft::Toolkit::Uwp::UI::Controls::WinRT::Microsoft_Toolkit_Uwp_UI_Controls_WinRT_XamlTypeInfo::XamlMetaDataProvider::Provider::get() -{ - if (_provider == nullptr) - { - _provider = ref new XamlTypeInfo::InfoProvider::XamlTypeInfoProvider(); - } - return _provider; -} - -::Windows::UI::Xaml::Markup::IXamlType^ ::XamlTypeInfo::InfoProvider::XamlTypeInfoProvider::GetXamlTypeByType(::Windows::UI::Xaml::Interop::TypeName type) -{ - auto xamlType = GetXamlTypeByName(type.Name); - return xamlType; -} - -::Windows::UI::Xaml::Markup::IXamlType^ ::XamlTypeInfo::InfoProvider::XamlTypeInfoProvider::GetXamlTypeByName(::Platform::String^ typeName) -{ - if (typeName == nullptr || typeName->IsEmpty()) - { - return nullptr; - } - - auto lock = _xamlTypesCriticalSection.Lock(); - auto val = _xamlTypes.find(typeName); - ::Windows::UI::Xaml::Markup::IXamlType^ xamlType = nullptr; - if (val != _xamlTypes.end()) - { - xamlType = (val->second).Resolve<::Windows::UI::Xaml::Markup::IXamlType>(); - if(xamlType != nullptr) - { - return xamlType; - } - } - - xamlType = CreateXamlType(typeName); - - if (xamlType != nullptr) - { - Platform::WeakReference wr(xamlType); - _xamlTypes[xamlType->FullName] = wr; - } - return xamlType; -} - -::Windows::UI::Xaml::Markup::IXamlMember^ ::XamlTypeInfo::InfoProvider::XamlTypeInfoProvider::GetMemberByLongName(::Platform::String^ longMemberName) -{ - if (longMemberName == nullptr || longMemberName->IsEmpty()) - { - return nullptr; - } - - auto lock = _xamlMembersCriticalSection.Lock(); - auto val = _xamlMembers.find(longMemberName); - if (val != _xamlMembers.end()) - { - return val->second; - } - - auto xamlMember = CreateXamlMember(longMemberName); - if (xamlMember != nullptr) - { - _xamlMembers[longMemberName] = xamlMember; - } - return xamlMember; -} - - -// XamlSystemBaseType -::XamlTypeInfo::InfoProvider::XamlSystemBaseType::XamlSystemBaseType(::Platform::String^ name) : - _fullName(name) -{ -} - -::Windows::UI::Xaml::Markup::IXamlType^ ::XamlTypeInfo::InfoProvider::XamlSystemBaseType::BaseType::get() -{ - throw ref new ::Platform::NotImplementedException; -} - -::Windows::UI::Xaml::Markup::IXamlMember^ ::XamlTypeInfo::InfoProvider::XamlSystemBaseType::ContentProperty::get() -{ - throw ref new ::Platform::NotImplementedException; -} - -::Platform::String^ ::XamlTypeInfo::InfoProvider::XamlSystemBaseType::FullName::get() -{ - return _fullName; -} - -::Platform::String^ ::XamlTypeInfo::InfoProvider::XamlSystemBaseType::Name::get() -{ - const wchar_t* seperator = wcsrchr(_fullName->Data(), '.'); - if (seperator == nullptr) - { - return _fullName; - } - return ref new ::Platform::String(seperator); -} - -bool ::XamlTypeInfo::InfoProvider::XamlSystemBaseType::IsArray::get() -{ - throw ref new ::Platform::NotImplementedException; -} - -bool ::XamlTypeInfo::InfoProvider::XamlSystemBaseType::IsCollection::get() -{ - throw ref new ::Platform::NotImplementedException; -} - -bool ::XamlTypeInfo::InfoProvider::XamlSystemBaseType::IsConstructible::get() -{ - throw ref new ::Platform::NotImplementedException; -} - -bool ::XamlTypeInfo::InfoProvider::XamlSystemBaseType::IsDictionary::get() -{ - throw ref new ::Platform::NotImplementedException; -} - -bool ::XamlTypeInfo::InfoProvider::XamlSystemBaseType::IsMarkupExtension::get() -{ - throw ref new ::Platform::NotImplementedException; -} - -bool ::XamlTypeInfo::InfoProvider::XamlSystemBaseType::IsEnum::get() -{ - throw ref new ::Platform::NotImplementedException; -} - -bool ::XamlTypeInfo::InfoProvider::XamlSystemBaseType::IsSystemType::get() -{ - throw ref new ::Platform::NotImplementedException; -} - -bool ::XamlTypeInfo::InfoProvider::XamlSystemBaseType::IsBindable::get() -{ - throw ref new ::Platform::NotImplementedException; -} - -::Windows::UI::Xaml::Markup::IXamlType^ ::XamlTypeInfo::InfoProvider::XamlSystemBaseType::ItemType::get() -{ - throw ref new ::Platform::NotImplementedException; -} - -::Windows::UI::Xaml::Markup::IXamlType^ ::XamlTypeInfo::InfoProvider::XamlSystemBaseType::KeyType::get() -{ - throw ref new ::Platform::NotImplementedException; -} - -::Windows::UI::Xaml::Interop::TypeName (::XamlTypeInfo::InfoProvider::XamlSystemBaseType::UnderlyingType::get)() -{ - ::Windows::UI::Xaml::Interop::TypeName typeName; - - typeName.Name = _fullName; - typeName.Kind = ::Windows::UI::Xaml::Interop::TypeKind::Primitive; - - return typeName; -} - -::Platform::Object^ ::XamlTypeInfo::InfoProvider::XamlSystemBaseType::ActivateInstance() -{ - throw ref new ::Platform::NotImplementedException; -} - -::Windows::UI::Xaml::Markup::IXamlMember^ ::XamlTypeInfo::InfoProvider::XamlSystemBaseType::GetMember(::Platform::String^) -{ - throw ref new ::Platform::NotImplementedException; -} - -void ::XamlTypeInfo::InfoProvider::XamlSystemBaseType::AddToVector(::Platform::Object^, ::Platform::Object^) -{ - throw ref new ::Platform::NotImplementedException; -} - -void ::XamlTypeInfo::InfoProvider::XamlSystemBaseType::AddToMap(::Platform::Object^, ::Platform::Object^, ::Platform::Object^) -{ - throw ref new ::Platform::NotImplementedException; -} - -void ::XamlTypeInfo::InfoProvider::XamlSystemBaseType::RunInitializer() -{ - throw ref new ::Platform::NotImplementedException; -} - -::Platform::Object^ ::XamlTypeInfo::InfoProvider::XamlSystemBaseType::CreateFromString(::Platform::String^) -{ - throw ref new ::Platform::NotImplementedException; -} - -//XamlUserType -::XamlTypeInfo::InfoProvider::XamlUserType::XamlUserType(::XamlTypeInfo::InfoProvider::XamlTypeInfoProvider^ provider, ::Platform::String^ fullName, ::Windows::UI::Xaml::Markup::IXamlType^ baseType) : - _isArray(false), - _isMarkupExtension(false), - _isEnum(false), - _isBindable(false), - _isReturnTypeStub(false), - _isLocalType(false), - _fullName(fullName), - _provider(provider), - _baseType(baseType) -{ -} - -::Platform::String^ ::XamlTypeInfo::InfoProvider::XamlUserType::FullName::get() -{ - return _fullName; -} - -::Platform::String^ ::XamlTypeInfo::InfoProvider::XamlUserType::Name::get() -{ - const wchar_t *seperator = wcsrchr(_fullName->Data(), '.'); - if (seperator == nullptr) - { - return _fullName; - } - return ref new ::Platform::String(seperator); -} - -::Windows::UI::Xaml::Interop::TypeName (::XamlTypeInfo::InfoProvider::XamlUserType::UnderlyingType::get)() -{ - ::Windows::UI::Xaml::Interop::TypeName typeName; - - typeName.Name = _fullName; - typeName.Kind = KindOfType; - - return typeName; -} - -bool ::XamlTypeInfo::InfoProvider::XamlUserType::IsSystemType::get() -{ - return true; -} - -::Windows::UI::Xaml::Markup::IXamlType^ ::XamlTypeInfo::InfoProvider::XamlUserType::BaseType::get() -{ - return _baseType; -} - -bool ::XamlTypeInfo::InfoProvider::XamlUserType::IsArray::get() -{ - return _isArray; -} -void ::XamlTypeInfo::InfoProvider::XamlUserType::IsArray::set(bool value) -{ - _isArray = value; -} - -bool ::XamlTypeInfo::InfoProvider::XamlUserType::IsCollection::get() -{ - return CollectionAdd != nullptr; -} - -bool ::XamlTypeInfo::InfoProvider::XamlUserType::IsConstructible::get() -{ - return Activator != nullptr; -} - -bool ::XamlTypeInfo::InfoProvider::XamlUserType::IsDictionary::get() -{ - return DictionaryAdd != nullptr; -} - -bool ::XamlTypeInfo::InfoProvider::XamlUserType::IsMarkupExtension::get() -{ - return _isMarkupExtension; -} - -void ::XamlTypeInfo::InfoProvider::XamlUserType::IsMarkupExtension::set(bool value) -{ - _isMarkupExtension = value; -} - -bool ::XamlTypeInfo::InfoProvider::XamlUserType::IsEnum::get() -{ - return _isEnum; -} - -void ::XamlTypeInfo::InfoProvider::XamlUserType::IsEnum::set(bool value) -{ - _isEnum = value; -} - -bool ::XamlTypeInfo::InfoProvider::XamlUserType::IsBindable::get() -{ - return _isBindable; -} - -void ::XamlTypeInfo::InfoProvider::XamlUserType::IsBindable::set(bool value) -{ - _isBindable = value; -} - -bool ::XamlTypeInfo::InfoProvider::XamlUserType::IsReturnTypeStub::get() -{ - return _isReturnTypeStub; -} - -void ::XamlTypeInfo::InfoProvider::XamlUserType::IsReturnTypeStub::set(bool value) -{ - _isReturnTypeStub = value; -} - -bool ::XamlTypeInfo::InfoProvider::XamlUserType::IsLocalType::get() -{ - return _isLocalType; -} - -void ::XamlTypeInfo::InfoProvider::XamlUserType::IsLocalType::set(bool value) -{ - _isLocalType = value; -} - -::Windows::UI::Xaml::Markup::IXamlMember^ ::XamlTypeInfo::InfoProvider::XamlUserType::ContentProperty::get() -{ - return _provider->GetMemberByLongName(_contentPropertyName); -} - -void ::XamlTypeInfo::InfoProvider::XamlUserType::ContentPropertyName::set(::Platform::String^ value) -{ - _contentPropertyName = value; -} - -::Windows::UI::Xaml::Markup::IXamlType^ ::XamlTypeInfo::InfoProvider::XamlUserType::ItemType::get() -{ - return _provider->GetXamlTypeByName(_itemTypeName); -} - -void ::XamlTypeInfo::InfoProvider::XamlUserType::ItemTypeName::set(::Platform::String^ value) -{ - _itemTypeName = value; -} - -::Windows::UI::Xaml::Markup::IXamlType^ ::XamlTypeInfo::InfoProvider::XamlUserType::KeyType::get() -{ - return _provider->GetXamlTypeByName(_keyTypeName); -} - -void ::XamlTypeInfo::InfoProvider::XamlUserType::KeyTypeName::set(::Platform::String^ value) -{ - _keyTypeName = value; -} - -::Windows::UI::Xaml::Markup::IXamlMember^ ::XamlTypeInfo::InfoProvider::XamlUserType::GetMember(::Platform::String^ name) -{ - auto val = _memberNames.find(name); - if (val != _memberNames.end()) - { - return _provider->GetMemberByLongName(val->second); - } - return nullptr; -} - -::Platform::Object^ ::XamlTypeInfo::InfoProvider::XamlUserType::ActivateInstance() -{ - return Activator(); -} - -void ::XamlTypeInfo::InfoProvider::XamlUserType::AddToMap(::Platform::Object^ instance, ::Platform::Object^ key, ::Platform::Object^ item) -{ - DictionaryAdd(instance, key, item); -} - -void ::XamlTypeInfo::InfoProvider::XamlUserType::AddToVector(::Platform::Object^ instance, ::Platform::Object^ item) -{ - CollectionAdd(instance, item); -} - -void ::XamlTypeInfo::InfoProvider::XamlUserType::RunInitializer() -{ - // The C++ runtime will have already run all the Static Initializers at start up. -} - -::Platform::Object^ ::XamlTypeInfo::InfoProvider::XamlUserType::CreateFromString(::Platform::String^ input) -{ - if (CreateFromStringMethod != nullptr) - { - return (*CreateFromStringMethod)(input); - } - else - { - return FromStringConverter(this, input); - } -} - -void ::XamlTypeInfo::InfoProvider::XamlUserType::AddMemberName(::Platform::String^ shortName) -{ - _memberNames[shortName] = FullName + "." + shortName; -} - -void ::XamlTypeInfo::InfoProvider::XamlUserType::AddEnumValue(::Platform::String^ name, ::Platform::Object^ value) -{ - _enumValues[name->Data()] = value; -} - -::default::uint32 (::XamlTypeInfo::InfoProvider::XamlUserType::CreateEnumUIntFromString)(::Platform::String^ input) -{ - bool found = false; - - const std::wregex regularExpression(L"^\\s+|\\s*,\\s*|\\s+$"); - uint32 val = 0; - - for (std::wcregex_token_iterator it(input->Begin(), input->End(), regularExpression, -1), end; it != end; ++it) - { - const std::wcsub_match& subMatch = *it; - - if (subMatch.length() == 0 ) - { - continue; - } - - std::wstring lookup(subMatch.first, (unsigned int)subMatch.length()); - - try - { - auto entry = _enumValues.find(lookup); - if (entry != _enumValues.end()) - { - const auto f = entry->second; - val |= safe_cast(f); - } - else - { - val |= std::stoi(subMatch); - } - found=true; - } - catch (const std::invalid_argument& ) - { - found = false; - break; - } - } - - if(found) - { - return val; - } - throw ref new ::Platform::InvalidArgumentException(); -} - -// XamlMember -::XamlTypeInfo::InfoProvider::XamlMember::XamlMember(::XamlTypeInfo::InfoProvider::XamlTypeInfoProvider^ provider, ::Platform::String^ name, ::Platform::String^ typeName) : - _isAttachable(false), - _isDependencyProperty(false), - _isReadOnly(false), - _name(name), - _typeName(typeName), - _provider(provider) -{ -} - - -bool ::XamlTypeInfo::InfoProvider::XamlMember::IsAttachable::get() -{ - return _isAttachable; -} - -void ::XamlTypeInfo::InfoProvider::XamlMember::IsAttachable::set(bool value) -{ - _isAttachable = value; -} - -bool ::XamlTypeInfo::InfoProvider::XamlMember::IsDependencyProperty::get() -{ - return _isDependencyProperty; -} - -void ::XamlTypeInfo::InfoProvider::XamlMember::IsDependencyProperty::set(bool value) -{ - _isDependencyProperty = value; -} - -bool ::XamlTypeInfo::InfoProvider::XamlMember::IsReadOnly::get() -{ - return _isReadOnly; -} - -void ::XamlTypeInfo::InfoProvider::XamlMember::IsReadOnly::set(bool value) -{ - _isReadOnly = value; -} - -::Platform::String^ ::XamlTypeInfo::InfoProvider::XamlMember::Name::get() -{ - return _name; -} - -::Windows::UI::Xaml::Markup::IXamlType^ ::XamlTypeInfo::InfoProvider::XamlMember::Type::get() -{ - return _provider->GetXamlTypeByName(_typeName); -} - -::Windows::UI::Xaml::Markup::IXamlType^ ::XamlTypeInfo::InfoProvider::XamlMember::TargetType::get() -{ - return _provider->GetXamlTypeByName(_targetTypeName); -} - -void ::XamlTypeInfo::InfoProvider::XamlMember::TargetTypeName::set(::Platform::String^ value) -{ - _targetTypeName = value; -} - -::Platform::Object^ ::XamlTypeInfo::InfoProvider::XamlMember::GetValue(::Platform::Object^ instance) -{ - if (Getter != nullptr) - { - return Getter(instance); - } - throw ref new ::Platform::NullReferenceException(); -} - -void ::XamlTypeInfo::InfoProvider::XamlMember::SetValue(::Platform::Object^ instance, ::Platform::Object^ value) -{ - if (Setter != nullptr) - { - Setter(instance, value); - return; - } - throw ref new ::Platform::NullReferenceException(); -} - diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Generated Files/XamlTypeInfo.g.cpp b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Generated Files/XamlTypeInfo.g.cpp deleted file mode 100644 index b6076b4eb55..00000000000 --- a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Generated Files/XamlTypeInfo.g.cpp +++ /dev/null @@ -1,372 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ -#include "pch.h" -#include "XamlTypeInfo.g.h" - -#include "XamlBindingInfo.g.hpp" - -template -::Platform::Object^ ActivateType() -{ - return ref new T; -} - -template -void CollectionAdd(::Platform::Object^ instance, ::Platform::Object^ item) -{ - safe_cast(instance)->Append((TItem)item); -} - -template -void DictionaryAdd(::Platform::Object^ instance, ::Platform::Object^ key, ::Platform::Object^ item) -{ - safe_cast(instance)->Insert((TKey)key, (TItem)item); -} - -template -::Platform::Object^ FromStringConverter(::XamlTypeInfo::InfoProvider::XamlUserType^ userType, ::Platform::String^ input) -{ - return ref new ::Platform::Box((T)userType->CreateEnumUIntFromString(input)); -} - -template -::Platform::Object^ GetValueTypeMember_TextWrap(::Platform::Object^ instance) -{ - return ref new ::Platform::Box(safe_cast(instance)->TextWrap); -} - -template -::Platform::Object^ GetValueTypeMember_TextOrientation(::Platform::Object^ instance) -{ - return ref new ::Platform::Box(safe_cast(instance)->TextOrientation); -} - -template -::Platform::Object^ GetReferenceTypeMember_TextLocale(::Platform::Object^ instance) -{ - return safe_cast(instance)->TextLocale; -} - -template -::Platform::Object^ GetReferenceTypeMember_Text(::Platform::Object^ instance) -{ - return safe_cast(instance)->Text; -} - -template -void SetEnumMember_TextWrap(::Platform::Object^ instance, ::Platform::Object^ value) -{ - safe_cast(instance)->TextWrap = safe_cast<::Platform::IBox^>(value)->Value; -} - -template -void SetEnumMember_TextOrientation(::Platform::Object^ instance, ::Platform::Object^ value) -{ - safe_cast(instance)->TextOrientation = safe_cast<::Platform::IBox^>(value)->Value; -} - -template -void SetReferenceTypeMember_TextLocale(::Platform::Object^ instance, ::Platform::Object^ value) -{ - safe_cast(instance)->TextLocale = safe_cast(value); -} - -template -void SetReferenceTypeMember_Text(::Platform::Object^ instance, ::Platform::Object^ value) -{ - safe_cast(instance)->Text = safe_cast(value); -} - -enum TypeInfo_Flags -{ - TypeInfo_Flags_None = 0x00, - TypeInfo_Flags_IsLocalType = 0x01, - TypeInfo_Flags_IsSystemType = 0x02, - TypeInfo_Flags_IsReturnTypeStub = 0x04, - TypeInfo_Flags_IsBindable = 0x08, - TypeInfo_Flags_IsMarkupExtension = 0x10, -}; - -struct TypeInfo -{ - PCWSTR typeName; - PCWSTR contentPropertyName; - ::Platform::Object^ (*activator)(); - void (*collectionAdd)(::Platform::Object^, ::Platform::Object^); - void (*dictionaryAdd)(::Platform::Object^, ::Platform::Object^, ::Platform::Object^); - ::Platform::Object^ (*fromStringConverter)(::XamlTypeInfo::InfoProvider::XamlUserType^, ::Platform::String^); - int baseTypeIndex; - int firstMemberIndex; - int firstEnumValueIndex; - int createFromStringIndex; - ::Windows::UI::Xaml::Interop::TypeKind kindofType; - unsigned int flags; -}; - -const TypeInfo TypeInfos[] = -{ - // 0 - L"String", L"", - nullptr, nullptr, nullptr, nullptr, - -1, - 0, 0, -1, ::Windows::UI::Xaml::Interop::TypeKind::Metadata, - TypeInfo_Flags_IsSystemType | TypeInfo_Flags_None, - // 1 - L"Windows.UI.Xaml.TextWrapping", L"", - nullptr, nullptr, nullptr, nullptr, - -1, - 0, 0, -1, ::Windows::UI::Xaml::Interop::TypeKind::Metadata, - TypeInfo_Flags_IsSystemType | TypeInfo_Flags_None, - // 2 - L"Windows.UI.Xaml.Controls.Control", L"", - nullptr, nullptr, nullptr, nullptr, - -1, - 0, 0, -1, ::Windows::UI::Xaml::Interop::TypeKind::Metadata, - TypeInfo_Flags_IsSystemType | TypeInfo_Flags_None, - // 3 - L"Windows.UI.Xaml.Controls.Orientation", L"", - nullptr, nullptr, nullptr, nullptr, - -1, - 0, 0, -1, ::Windows::UI::Xaml::Interop::TypeKind::Metadata, - TypeInfo_Flags_IsSystemType | TypeInfo_Flags_None, - // 4 - L"Microsoft.Toolkit.Uwp.UI.Controls.WinRT.DirectWriteTextBlock", L"", - &ActivateType<::Microsoft::Toolkit::Uwp::UI::Controls::WinRT::DirectWriteTextBlock>, nullptr, nullptr, nullptr, - 2, // Windows.UI.Xaml.Controls.Control - 0, 0, -1, ::Windows::UI::Xaml::Interop::TypeKind::Metadata, - TypeInfo_Flags_IsLocalType | TypeInfo_Flags_None, - // Last type here is for padding - L"", L"", - nullptr, nullptr, nullptr, nullptr, - -1, - 4, 0, -1, ::Windows::UI::Xaml::Interop::TypeKind::Custom, - TypeInfo_Flags_None, -}; - -const UINT TypeInfoLookup[] = { - 0, // 0 - 0, // 1 - 0, // 2 - 0, // 3 - 0, // 4 - 0, // 5 - 0, // 6 - 1, // 7 - 1, // 8 - 1, // 9 - 1, // 10 - 1, // 11 - 1, // 12 - 1, // 13 - 1, // 14 - 1, // 15 - 1, // 16 - 1, // 17 - 1, // 18 - 1, // 19 - 1, // 20 - 1, // 21 - 1, // 22 - 1, // 23 - 1, // 24 - 1, // 25 - 1, // 26 - 1, // 27 - 1, // 28 - 2, // 29 - 2, // 30 - 2, // 31 - 2, // 32 - 3, // 33 - 3, // 34 - 3, // 35 - 3, // 36 - 4, // 37 - 4, // 38 - 4, // 39 - 4, // 40 - 4, // 41 - 4, // 42 - 4, // 43 - 4, // 44 - 4, // 45 - 4, // 46 - 4, // 47 - 4, // 48 - 4, // 49 - 4, // 50 - 4, // 51 - 4, // 52 - 4, // 53 - 4, // 54 - 4, // 55 - 4, // 56 - 4, // 57 - 4, // 58 - 4, // 59 - 4, // 60 - 5, // 61 -}; - -struct MemberInfo -{ - PCWSTR shortName; - ::Platform::Object^ (*getter)(::Platform::Object^); - void (*setter)(::Platform::Object^, ::Platform::Object^); - int typeIndex; - int targetTypeIndex; - bool isReadOnly; - bool isDependencyProperty; - bool isAttachable; -}; - -const MemberInfo MemberInfos[] = -{ - // 0 - Microsoft.Toolkit.Uwp.UI.Controls.WinRT.DirectWriteTextBlock.TextWrap - L"TextWrap", - &GetValueTypeMember_TextWrap<::Microsoft::Toolkit::Uwp::UI::Controls::WinRT::DirectWriteTextBlock, ::Windows::UI::Xaml::TextWrapping>, - &SetEnumMember_TextWrap<::Microsoft::Toolkit::Uwp::UI::Controls::WinRT::DirectWriteTextBlock, ::Windows::UI::Xaml::TextWrapping>, - 1, // Windows.UI.Xaml.TextWrapping - -1, - false, true, false, - // 1 - Microsoft.Toolkit.Uwp.UI.Controls.WinRT.DirectWriteTextBlock.TextOrientation - L"TextOrientation", - &GetValueTypeMember_TextOrientation<::Microsoft::Toolkit::Uwp::UI::Controls::WinRT::DirectWriteTextBlock, ::Windows::UI::Xaml::Controls::Orientation>, - &SetEnumMember_TextOrientation<::Microsoft::Toolkit::Uwp::UI::Controls::WinRT::DirectWriteTextBlock, ::Windows::UI::Xaml::Controls::Orientation>, - 3, // Windows.UI.Xaml.Controls.Orientation - -1, - false, true, false, - // 2 - Microsoft.Toolkit.Uwp.UI.Controls.WinRT.DirectWriteTextBlock.TextLocale - L"TextLocale", - &GetReferenceTypeMember_TextLocale<::Microsoft::Toolkit::Uwp::UI::Controls::WinRT::DirectWriteTextBlock>, - &SetReferenceTypeMember_TextLocale<::Microsoft::Toolkit::Uwp::UI::Controls::WinRT::DirectWriteTextBlock, ::Platform::String>, - 0, // String - -1, - false, true, false, - // 3 - Microsoft.Toolkit.Uwp.UI.Controls.WinRT.DirectWriteTextBlock.Text - L"Text", - &GetReferenceTypeMember_Text<::Microsoft::Toolkit::Uwp::UI::Controls::WinRT::DirectWriteTextBlock>, - &SetReferenceTypeMember_Text<::Microsoft::Toolkit::Uwp::UI::Controls::WinRT::DirectWriteTextBlock, ::Platform::String>, - 0, // String - -1, - false, true, false, -}; - -PCWSTR GetShortName(PCWSTR longName) -{ - PCWSTR separator = wcsrchr(longName, '.'); - return separator != nullptr ? separator + 1: longName; -} - -const TypeInfo* GetTypeInfo(::Platform::String^ typeName) -{ - auto typeNameLength = typeName->Length(); - if (typeNameLength < _countof(TypeInfoLookup) - 1) - { - for (UINT i = TypeInfoLookup[typeNameLength]; i < TypeInfoLookup[typeNameLength+1]; i++) - { - if (typeName == ::Platform::StringReference(TypeInfos[i].typeName)) - { - return &TypeInfos[i]; - } - } - } - return nullptr; -} - -const MemberInfo* GetMemberInfo(::Platform::String^ longMemberName) -{ - auto lastDotIndex = longMemberName->Length(); - while (true) - { - if (longMemberName->Data()[lastDotIndex] == '.') - { - const TypeInfo* pTypeInfo = GetTypeInfo(ref new ::Platform::String(longMemberName->Data(), lastDotIndex)); - const TypeInfo* pNextTypeInfo = pTypeInfo + 1; - if (pTypeInfo) - { - PCWSTR shortMemberName = GetShortName(longMemberName->Data()); - for (int i = pTypeInfo->firstMemberIndex; i < pNextTypeInfo->firstMemberIndex; i++) - { - if (wcscmp(shortMemberName, MemberInfos[i].shortName) == 0) - { - return &MemberInfos[i]; - } - } - } - break; - } - if (lastDotIndex == 0) - { - break; - } - lastDotIndex--; - } - return nullptr; -} - -::Windows::UI::Xaml::Markup::IXamlType^ ::XamlTypeInfo::InfoProvider::XamlTypeInfoProvider::CreateXamlType(::Platform::String^ typeName) -{ - const TypeInfo* pTypeInfo = GetTypeInfo(typeName); - const TypeInfo* pNextTypeInfo = pTypeInfo + 1; - if (pTypeInfo == nullptr || pNextTypeInfo == nullptr) - { - return nullptr; - } - else if (pTypeInfo->flags & TypeInfo_Flags_IsSystemType) - { - return ref new ::XamlTypeInfo::InfoProvider::XamlSystemBaseType(typeName); - } - else - { - ::XamlTypeInfo::InfoProvider::XamlUserType^ userType = ref new ::XamlTypeInfo::InfoProvider::XamlUserType( - this, - ::Platform::StringReference(pTypeInfo->typeName), - this->GetXamlTypeByName(::Platform::StringReference(pTypeInfo->baseTypeIndex >= 0 ? TypeInfos[pTypeInfo->baseTypeIndex].typeName : L""))); - userType->KindOfType = pTypeInfo->kindofType; - userType->Activator = pTypeInfo->activator; - userType->CollectionAdd = pTypeInfo->collectionAdd; - userType->DictionaryAdd = pTypeInfo->dictionaryAdd; - userType->FromStringConverter = pTypeInfo->fromStringConverter; - userType->ContentPropertyName = ::Platform::StringReference(pTypeInfo->contentPropertyName); - userType->IsLocalType = pTypeInfo->flags & TypeInfo_Flags_IsLocalType; - userType->IsReturnTypeStub = pTypeInfo->flags & TypeInfo_Flags_IsReturnTypeStub; - userType->IsBindable = pTypeInfo->flags & TypeInfo_Flags_IsBindable; - userType->IsMarkupExtension = pTypeInfo->flags & TypeInfo_Flags_IsMarkupExtension; - userType->CreateFromStringMethod = nullptr; - int nextMemberIndex = pTypeInfo->firstMemberIndex; - for (int i=pTypeInfo->firstMemberIndex; i < pNextTypeInfo->firstMemberIndex; i++) - { - userType->AddMemberName(::Platform::StringReference(MemberInfos[i].shortName)); - nextMemberIndex++; - } - return userType; - } -} - -::Windows::UI::Xaml::Markup::IXamlMember^ ::XamlTypeInfo::InfoProvider::XamlTypeInfoProvider::CreateXamlMember(::Platform::String^ longMemberName) -{ - ::XamlTypeInfo::InfoProvider::XamlMember^ xamlMember = nullptr; - const MemberInfo* pMemberInfo = GetMemberInfo(longMemberName); - if (pMemberInfo != nullptr) - { - xamlMember = ref new ::XamlTypeInfo::InfoProvider::XamlMember( - this, - ::Platform::StringReference(pMemberInfo->shortName), - ::Platform::StringReference(TypeInfos[pMemberInfo->typeIndex].typeName)); - xamlMember->Getter = pMemberInfo->getter; - xamlMember->Setter = pMemberInfo->setter; - xamlMember->TargetTypeName = pMemberInfo->targetTypeIndex >= 0 ? ::Platform::StringReference(TypeInfos[pMemberInfo->targetTypeIndex].typeName) : L""; - xamlMember->IsReadOnly = pMemberInfo->isReadOnly; - xamlMember->IsDependencyProperty = pMemberInfo->isDependencyProperty; - xamlMember->IsAttachable = pMemberInfo->isAttachable; - } - return xamlMember; -} - diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Generated Files/XamlTypeInfo.g.h b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Generated Files/XamlTypeInfo.g.h deleted file mode 100644 index 49748990f9a..00000000000 --- a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Generated Files/XamlTypeInfo.g.h +++ /dev/null @@ -1,383 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ -#pragma once -#include - -namespace XamlTypeInfo -{ - namespace InfoProvider - { - ref class XamlTypeInfoProvider sealed - { - struct CriticalSection - { - CriticalSection() - { - InitializeCriticalSection(&criticalSection); - } - - ~CriticalSection() - { - DeleteCriticalSection(&criticalSection); - } - - struct AutoLock - { - AutoLock(LPCRITICAL_SECTION criticalSection) - : pCriticalSection(criticalSection) - { - EnterCriticalSection(criticalSection); - } - - ~AutoLock() - { - LeaveCriticalSection(pCriticalSection); - } - - private: - LPCRITICAL_SECTION pCriticalSection{ nullptr }; - }; - - AutoLock Lock() - { - return AutoLock(&criticalSection); - } - - private: - CRITICAL_SECTION criticalSection; - }; - - public: - ::Windows::UI::Xaml::Markup::IXamlType^ GetXamlTypeByName(::Platform::String^ typeName); - ::Windows::UI::Xaml::Markup::IXamlType^ GetXamlTypeByType(::Windows::UI::Xaml::Interop::TypeName t); - ::Windows::UI::Xaml::Markup::IXamlMember^ GetMemberByLongName(::Platform::String^ longMemberName); - - private: - CriticalSection _xamlTypesCriticalSection; - std::map<::Platform::String^, ::Platform::WeakReference> _xamlTypes; - CriticalSection _xamlMembersCriticalSection; - std::map<::Platform::String^, ::Windows::UI::Xaml::Markup::IXamlMember^> _xamlMembers; - ::Windows::UI::Xaml::Markup::IXamlType^ CreateXamlType(::Platform::String^ typeName); - ::Windows::UI::Xaml::Markup::IXamlMember^ CreateXamlMember(::Platform::String^ longMemberName); - - }; - - ref class XamlSystemBaseType sealed : public ::Windows::UI::Xaml::Markup::IXamlType - { - internal: - XamlSystemBaseType(::Platform::String^ name); - - public: - virtual property ::Windows::UI::Xaml::Markup::IXamlType^ BaseType - { - ::Windows::UI::Xaml::Markup::IXamlType^ get(); - } - - virtual property ::Windows::UI::Xaml::Markup::IXamlMember^ ContentProperty - { - ::Windows::UI::Xaml::Markup::IXamlMember^ get(); - } - - virtual property ::Platform::String^ FullName - { - ::Platform::String^ get(); - } - - virtual property ::Platform::String^ Name - { - ::Platform::String^ get(); - } - - virtual property bool IsArray - { - bool get(); - } - - virtual property bool IsCollection - { - bool get(); - } - - virtual property bool IsConstructible - { - bool get(); - } - - virtual property bool IsDictionary - { - bool get(); - } - - virtual property bool IsMarkupExtension - { - bool get(); - } - - virtual property bool IsEnum - { - bool get(); - } - - virtual property bool IsSystemType - { - bool get(); - } - - virtual property bool IsBindable - { - bool get(); - } - - virtual property ::Windows::UI::Xaml::Markup::IXamlType^ ItemType - { - ::Windows::UI::Xaml::Markup::IXamlType^ get(); - } - - virtual property ::Windows::UI::Xaml::Markup::IXamlType^ KeyType - { - ::Windows::UI::Xaml::Markup::IXamlType^ get(); - } - - virtual property ::Windows::UI::Xaml::Interop::TypeName UnderlyingType - { - ::Windows::UI::Xaml::Interop::TypeName get(); - } - - virtual ::Platform::Object^ ActivateInstance(); - virtual ::Windows::UI::Xaml::Markup::IXamlMember^ GetMember(::Platform::String^ name); - virtual void AddToVector(::Platform::Object^ instance, ::Platform::Object^ value); - virtual void AddToMap(::Platform::Object^ instance, ::Platform::Object^ key, ::Platform::Object^ value); - virtual void RunInitializer(); - virtual ::Platform::Object^ CreateFromString(::Platform::String^ value); - - private: - ::Platform::String^ _fullName; - }; - - ref class XamlUserType sealed : public [::Platform::Metadata::RuntimeClassName] ::Windows::UI::Xaml::Markup::IXamlType - { - internal: - XamlUserType(::XamlTypeInfo::InfoProvider::XamlTypeInfoProvider^ provider, ::Platform::String^ fullName, ::Windows::UI::Xaml::Markup::IXamlType^ baseType); - - public: - // --- Interface methods ---- - virtual property ::Platform::String^ FullName - { - ::Platform::String^ get(); - } - - virtual property ::Platform::String^ Name - { - ::Platform::String^ get(); - } - - virtual property ::Windows::UI::Xaml::Interop::TypeName UnderlyingType - { - ::Windows::UI::Xaml::Interop::TypeName get(); - } - - virtual property bool IsSystemType - { - bool get(); - } - - virtual property ::Windows::UI::Xaml::Markup::IXamlType^ BaseType - { - ::Windows::UI::Xaml::Markup::IXamlType^ get(); - } - - virtual property bool IsArray - { - bool get(); - internal: void set(bool value); - } - - virtual property bool IsCollection - { - bool get(); - } - - virtual property bool IsConstructible - { - bool get(); - } - - virtual property bool IsDictionary - { - bool get(); - } - - virtual property bool IsMarkupExtension - { - bool get(); - internal: void set(bool value); - } - - virtual property bool IsEnum - { - bool get(); - internal: void set(bool value); - } - - virtual property bool IsBindable - { - bool get(); - internal: void set(bool value); - } - - virtual property ::Windows::UI::Xaml::Markup::IXamlMember^ ContentProperty - { - ::Windows::UI::Xaml::Markup::IXamlMember^ get(); - } - - virtual property ::Windows::UI::Xaml::Markup::IXamlType^ ItemType - { - ::Windows::UI::Xaml::Markup::IXamlType^ get(); - } - - virtual property ::Windows::UI::Xaml::Markup::IXamlType^ KeyType - { - ::Windows::UI::Xaml::Markup::IXamlType^ get(); - } - - virtual ::Windows::UI::Xaml::Markup::IXamlMember^ GetMember(::Platform::String^ name); - virtual ::Platform::Object^ ActivateInstance(); - virtual void AddToMap(::Platform::Object^ instance, ::Platform::Object^ key, ::Platform::Object^ value); - virtual void AddToVector(::Platform::Object^ instance, ::Platform::Object^ value); - virtual void RunInitializer(); - virtual ::Platform::Object^ CreateFromString(::Platform::String^ value); - // --- End of Interface methods - - property bool IsReturnTypeStub - { - bool get(); - internal: void set(bool value); - } - - property bool IsLocalType - { - bool get(); - internal: void set(bool value); - } - - internal: - typedef ::Platform::Object^ (*ActivatorFn)(); - typedef void (*AddToCollectionFn)(::Platform::Object^ instance, ::Platform::Object^ item); - typedef void (*AddToDictionaryFn)(::Platform::Object^ instance, ::Platform::Object^ key, ::Platform::Object^ item); - typedef ::Platform::Object^ (*CreateFromStringFn)(::Platform::String^); - typedef ::Platform::Object^ (*StringConverterFn)(::XamlTypeInfo::InfoProvider::XamlUserType^ userType, ::Platform::String^ input); - - property ActivatorFn Activator; - property AddToCollectionFn CollectionAdd; - property AddToDictionaryFn DictionaryAdd; - property CreateFromStringFn CreateFromStringMethod; - property ::Windows::UI::Xaml::Interop::TypeKind KindOfType; - property StringConverterFn FromStringConverter; - - property ::Platform::String^ ContentPropertyName - { - void set(::Platform::String^ value); - } - - property ::Platform::String^ ItemTypeName - { - void set(::Platform::String^ value); - } - - property ::Platform::String^ KeyTypeName - { - void set(::Platform::String^ value); - } - - void AddMemberName(::Platform::String^ shortName); - void AddEnumValue(::Platform::String^ name, ::Platform::Object^ value); - uint32 CreateEnumUIntFromString(::Platform::String^ input); - - private: - ::XamlTypeInfo::InfoProvider::XamlTypeInfoProvider^ _provider; - ::Windows::UI::Xaml::Markup::IXamlType^ _baseType; - ::Platform::String^ _contentPropertyName; - ::Platform::String^ _itemTypeName; - ::Platform::String^ _keyTypeName; - ::Platform::String^ _fullName; - std::map<::Platform::String^, ::Platform::String^> _memberNames; - std::map _enumValues; - bool _isArray = false; - bool _isMarkupExtension = false; - bool _isEnum = false; - bool _isBindable = false; - bool _isReturnTypeStub = false; - bool _isLocalType = false; - }; - - ref class XamlMember sealed : public ::Windows::UI::Xaml::Markup::IXamlMember - { - internal: - XamlMember(::XamlTypeInfo::InfoProvider::XamlTypeInfoProvider^ provider, ::Platform::String^ name, ::Platform::String^ typeName); - - typedef ::Platform::Object^ (*PropertyGetterFn)(::Platform::Object^ instance); - typedef void (*PropertySetterFn)(::Platform::Object^ instance, ::Platform::Object^ value); - - property PropertyGetterFn Getter; - property PropertySetterFn Setter; - - public: - virtual property bool IsAttachable - { - bool get(); - internal: void set(bool value); - } - - virtual property bool IsDependencyProperty - { - bool get(); - internal: void set(bool value); - } - - virtual property bool IsReadOnly - { - bool get(); - internal: void set(bool value); - } - - virtual property ::Platform::String^ Name - { - ::Platform::String^ get(); - } - - virtual property ::Windows::UI::Xaml::Markup::IXamlType^ Type - { - ::Windows::UI::Xaml::Markup::IXamlType^ get(); - } - - virtual property ::Windows::UI::Xaml::Markup::IXamlType^ TargetType - { - ::Windows::UI::Xaml::Markup::IXamlType^ get(); - } - - virtual ::Platform::Object^ GetValue(::Platform::Object^ instance); - virtual void SetValue(::Platform::Object^ instance, ::Platform::Object^ value); - - internal: - virtual property ::Platform::String^ TargetTypeName - { - void set(::Platform::String^ value); - } - - private: - bool _isAttachable; - bool _isDependencyProperty; - bool _isReadOnly; - ::Platform::String^ _name; - ::Platform::String^ _targetTypeName; - ::Platform::String^ _typeName; - ::XamlTypeInfo::InfoProvider::XamlTypeInfoProvider^ _provider; - }; - } -} From 64b8534725b06b1f6c82f97961ef9652e90b58c5 Mon Sep 17 00:00:00 2001 From: Nikola Metulev Date: Sun, 7 Oct 2018 19:18:26 -0700 Subject: [PATCH 04/29] fixed props issue with Controls.WinRT project and added sample page in sample app --- .gitignore | 1 + Directory.Build.props | 2 +- .../Microsoft.Toolkit.Uwp.SampleApp.csproj | 12 ++++++++ .../DirectWriteTextBlockCode.bind | 13 ++++++++ .../DirectWriteTextBlockPage.xaml | 15 ++++++++++ .../DirectWriteTextBlockPage.xaml.cs | 30 +++++++++++++++++++ .../SamplePages/samples.json | 11 +++++++ Windows Community Toolkit.sln | 1 + 8 files changed, 84 insertions(+), 1 deletion(-) create mode 100644 Microsoft.Toolkit.Uwp.SampleApp/SamplePages/DirectWriteTextBlock/DirectWriteTextBlockCode.bind create mode 100644 Microsoft.Toolkit.Uwp.SampleApp/SamplePages/DirectWriteTextBlock/DirectWriteTextBlockPage.xaml create mode 100644 Microsoft.Toolkit.Uwp.SampleApp/SamplePages/DirectWriteTextBlock/DirectWriteTextBlockPage.xaml.cs diff --git a/.gitignore b/.gitignore index fd193a46b25..fc0cf0a396f 100644 --- a/.gitignore +++ b/.gitignore @@ -21,6 +21,7 @@ build/ bld/ [Bb]in/ [Oo]bj/ +Generated Files/ # Visual Studio 2015 cache/options directory .vs/ diff --git a/Directory.Build.props b/Directory.Build.props index 581b3f3da58..4821e97acb7 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -116,7 +116,7 @@ - + diff --git a/Microsoft.Toolkit.Uwp.SampleApp/Microsoft.Toolkit.Uwp.SampleApp.csproj b/Microsoft.Toolkit.Uwp.SampleApp/Microsoft.Toolkit.Uwp.SampleApp.csproj index 999bc96466d..ec9e6904ddf 100644 --- a/Microsoft.Toolkit.Uwp.SampleApp/Microsoft.Toolkit.Uwp.SampleApp.csproj +++ b/Microsoft.Toolkit.Uwp.SampleApp/Microsoft.Toolkit.Uwp.SampleApp.csproj @@ -529,6 +529,7 @@ + @@ -569,6 +570,9 @@ + + DirectWriteTextBlockPage.xaml + PowerBIEmbeddedPage.xaml @@ -959,6 +963,10 @@ Designer MSBuild:Compile + + Designer + MSBuild:Compile + MSBuild:Compile Designer @@ -1436,6 +1444,10 @@ {d4d78cba-b238-4794-89a0-4f1a2d8fea97} Microsoft.Toolkit.Uwp.UI.Controls.Graph + + {d4c7ac54-826a-4412-8461-a7c7fd86534b} + Microsoft.Toolkit.Uwp.UI.Controls.WinRT + {e9faabfb-d726-42c1-83c1-cb46a29fea81} Microsoft.Toolkit.Uwp.UI.Controls diff --git a/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/DirectWriteTextBlock/DirectWriteTextBlockCode.bind b/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/DirectWriteTextBlock/DirectWriteTextBlockCode.bind new file mode 100644 index 00000000000..f03c6fbe347 --- /dev/null +++ b/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/DirectWriteTextBlock/DirectWriteTextBlockCode.bind @@ -0,0 +1,13 @@ + + + + + + \ No newline at end of file diff --git a/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/DirectWriteTextBlock/DirectWriteTextBlockPage.xaml b/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/DirectWriteTextBlock/DirectWriteTextBlockPage.xaml new file mode 100644 index 00000000000..2cb3fd41ac5 --- /dev/null +++ b/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/DirectWriteTextBlock/DirectWriteTextBlockPage.xaml @@ -0,0 +1,15 @@ + + + + + + diff --git a/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/DirectWriteTextBlock/DirectWriteTextBlockPage.xaml.cs b/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/DirectWriteTextBlock/DirectWriteTextBlockPage.xaml.cs new file mode 100644 index 00000000000..b82005eb553 --- /dev/null +++ b/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/DirectWriteTextBlock/DirectWriteTextBlockPage.xaml.cs @@ -0,0 +1,30 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Runtime.InteropServices.WindowsRuntime; +using Windows.Foundation; +using Windows.Foundation.Collections; +using Windows.UI.Xaml; +using Windows.UI.Xaml.Controls; +using Windows.UI.Xaml.Controls.Primitives; +using Windows.UI.Xaml.Data; +using Windows.UI.Xaml.Input; +using Windows.UI.Xaml.Media; +using Windows.UI.Xaml.Navigation; + +// The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=234238 + +namespace Microsoft.Toolkit.Uwp.SampleApp.SamplePages +{ + /// + /// An empty page that can be used on its own or navigated to within a Frame. + /// + public sealed partial class DirectWriteTextBlockPage : Page + { + public DirectWriteTextBlockPage() + { + this.InitializeComponent(); + } + } +} diff --git a/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/samples.json b/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/samples.json index 816504bbdcd..772c10b6cf5 100644 --- a/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/samples.json +++ b/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/samples.json @@ -325,6 +325,17 @@ "ApiCheck": "Windows.UI.Xaml.Controls.ColorPicker", "BadgeUpdateVersionRequired": "Fall Creators Update required", "DocumentationUrl": "https://raw.githubusercontent.com/Microsoft/WindowsCommunityToolkit/master/docs/controls/InfiniteCanvas.md" + }, + { + "Name": "DirectWriteTextBlock", + "Type": "DirectWriteTextBlockPage", + "About": "TODO", + "CodeUrl": "https://github.com/Microsoft/WindowsCommunityToolkit/tree/master/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock", + "XamlCodeFile": "DirectWriteTextBlockCode.bind", + // TODO: "Icon": "/SamplePages/InfiniteCanvas/InfiniteCanvas.png", + // TODO: check for API needed in 17734 "ApiCheck": "Windows.UI.Xaml.Controls.ColorPicker", + "BadgeUpdateVersionRequired": "April 2018 Update required", + "DocumentationUrl": "https://raw.githubusercontent.com/Microsoft/WindowsCommunityToolkit/master/docs/controls/DirectWriteTextBlock.md" } ] }, diff --git a/Windows Community Toolkit.sln b/Windows Community Toolkit.sln index 255af9c3596..a32e0efc450 100644 --- a/Windows Community Toolkit.sln +++ b/Windows Community Toolkit.sln @@ -661,6 +661,7 @@ Global {D4D78CBA-B238-4794-89A0-4F1A2D8FEA97}.Release|x86.ActiveCfg = Release|Any CPU {D4D78CBA-B238-4794-89A0-4F1A2D8FEA97}.Release|x86.Build.0 = Release|Any CPU {D4C7AC54-826A-4412-8461-A7C7FD86534B}.Debug|Any CPU.ActiveCfg = Debug|Win32 + {D4C7AC54-826A-4412-8461-A7C7FD86534B}.Debug|Any CPU.Build.0 = Debug|Win32 {D4C7AC54-826A-4412-8461-A7C7FD86534B}.Debug|ARM.ActiveCfg = Debug|ARM {D4C7AC54-826A-4412-8461-A7C7FD86534B}.Debug|ARM.Build.0 = Debug|ARM {D4C7AC54-826A-4412-8461-A7C7FD86534B}.Debug|x64.ActiveCfg = Debug|x64 From cccbacc8411231b56b23b4ec3bf04242671400f9 Mon Sep 17 00:00:00 2001 From: "Jun Ma (WINDOWS)" Date: Tue, 9 Oct 2018 23:13:33 +0900 Subject: [PATCH 05/29] fix accessibility. --- Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Themes/Generic.xaml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Themes/Generic.xaml b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Themes/Generic.xaml index 4d8210f4770..51d9388eeae 100644 --- a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Themes/Generic.xaml +++ b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Themes/Generic.xaml @@ -11,7 +11,7 @@ - + @@ -19,7 +19,9 @@ - + From 7552549fd11e073b50b2572a23a2e4b6f14f41bf Mon Sep 17 00:00:00 2001 From: "Jun Ma (WINDOWS)" Date: Wed, 10 Oct 2018 00:05:35 +0900 Subject: [PATCH 06/29] fix warning when building x64. Fix target SDK. Use correct Theme brush. --- .../DirectWriteTextBlock/DirectWriteTextBlockPage.xaml.cs | 2 -- .../DirectWriteTextBlock/DirectWriteRenderArgBuilder.cpp | 4 ++-- .../Microsoft.Toolkit.Uwp.UI.Controls.WinRT.vcxproj | 2 +- Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Themes/Generic.xaml | 2 +- 4 files changed, 4 insertions(+), 6 deletions(-) diff --git a/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/DirectWriteTextBlock/DirectWriteTextBlockPage.xaml.cs b/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/DirectWriteTextBlock/DirectWriteTextBlockPage.xaml.cs index b82005eb553..8be952e8843 100644 --- a/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/DirectWriteTextBlock/DirectWriteTextBlockPage.xaml.cs +++ b/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/DirectWriteTextBlock/DirectWriteTextBlockPage.xaml.cs @@ -13,8 +13,6 @@ using Windows.UI.Xaml.Media; using Windows.UI.Xaml.Navigation; -// The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=234238 - namespace Microsoft.Toolkit.Uwp.SampleApp.SamplePages { /// diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock/DirectWriteRenderArgBuilder.cpp b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock/DirectWriteRenderArgBuilder.cpp index 4c52f38466f..727eff8aace 100644 --- a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock/DirectWriteRenderArgBuilder.cpp +++ b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock/DirectWriteRenderArgBuilder.cpp @@ -283,10 +283,10 @@ void DirectWriteRenderArgBuilder::BuildFontCollection(Platform::String^ fontFami // the key is a void* meaning the size is actual size. auto fontFamilyString = fontFamily->Data(); auto fontFamilySize = fontFamily->Length() * sizeof(wchar_t); - dwriteFactory->CreateCustomFontCollection(customLoader.get(), fontFamilyString, fontFamilySize, m_builtArgs.fontCollection.put()); + dwriteFactory->CreateCustomFontCollection(customLoader.get(), fontFamilyString, static_cast(fontFamilySize), m_builtArgs.fontCollection.put()); // set font family to the parsed font family. - m_builtArgs.fontFamily = ref new String(parseData.customFontName.data(), parseData.customFontName.size()); + m_builtArgs.fontFamily = ref new String(parseData.customFontName.data(), static_cast(parseData.customFontName.size())); } else { diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Microsoft.Toolkit.Uwp.UI.Controls.WinRT.vcxproj b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Microsoft.Toolkit.Uwp.UI.Controls.WinRT.vcxproj index b33e6b6661c..5cd79e5651f 100644 --- a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Microsoft.Toolkit.Uwp.UI.Controls.WinRT.vcxproj +++ b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Microsoft.Toolkit.Uwp.UI.Controls.WinRT.vcxproj @@ -34,7 +34,7 @@ 14.0 true Windows Store - 10.0.17134.0 + 10.0.17763.0 10.0.17134.0 10.0 diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Themes/Generic.xaml b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Themes/Generic.xaml index 51d9388eeae..d86d22a302d 100644 --- a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Themes/Generic.xaml +++ b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Themes/Generic.xaml @@ -11,7 +11,7 @@ - + From e2ffbe5481e930cf945f922485b1172df8adc1f7 Mon Sep 17 00:00:00 2001 From: "Jun Ma (WINDOWS)" Date: Wed, 10 Oct 2018 00:08:45 +0900 Subject: [PATCH 07/29] fix build. --- .../Microsoft.Toolkit.Uwp.UI.Controls.WinRT.vcxproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Microsoft.Toolkit.Uwp.UI.Controls.WinRT.vcxproj b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Microsoft.Toolkit.Uwp.UI.Controls.WinRT.vcxproj index 5cd79e5651f..b33e6b6661c 100644 --- a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Microsoft.Toolkit.Uwp.UI.Controls.WinRT.vcxproj +++ b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Microsoft.Toolkit.Uwp.UI.Controls.WinRT.vcxproj @@ -34,7 +34,7 @@ 14.0 true Windows Store - 10.0.17763.0 + 10.0.17134.0 10.0.17134.0 10.0 From 43be56c178e88d69da014304c30a974137441be8 Mon Sep 17 00:00:00 2001 From: "Jun Ma (WINDOWS)" Date: Wed, 10 Oct 2018 01:38:47 +0900 Subject: [PATCH 08/29] Add png Fix font size scaling correctly Fix json file Add more things to bind in SampleApp. --- .../Microsoft.Toolkit.Uwp.SampleApp.csproj | 1 + .../DirectWriteTextBlock/DirectWriteTextBlock.png | Bin 0 -> 424 bytes .../DirectWriteTextBlockCode.bind | 8 +++++++- .../SamplePages/samples.json | 4 ++-- .../DirectWriteTextBlock/DirectWriteTextBlock.cpp | 11 +++++++++-- 5 files changed, 19 insertions(+), 5 deletions(-) create mode 100644 Microsoft.Toolkit.Uwp.SampleApp/SamplePages/DirectWriteTextBlock/DirectWriteTextBlock.png diff --git a/Microsoft.Toolkit.Uwp.SampleApp/Microsoft.Toolkit.Uwp.SampleApp.csproj b/Microsoft.Toolkit.Uwp.SampleApp/Microsoft.Toolkit.Uwp.SampleApp.csproj index 7164b54b9eb..cd178ac806c 100644 --- a/Microsoft.Toolkit.Uwp.SampleApp/Microsoft.Toolkit.Uwp.SampleApp.csproj +++ b/Microsoft.Toolkit.Uwp.SampleApp/Microsoft.Toolkit.Uwp.SampleApp.csproj @@ -279,6 +279,7 @@ + diff --git a/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/DirectWriteTextBlock/DirectWriteTextBlock.png b/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/DirectWriteTextBlock/DirectWriteTextBlock.png new file mode 100644 index 0000000000000000000000000000000000000000..32d8dde9337b8d390fe93447e86430212457074c GIT binary patch literal 424 zcmeAS@N?(olHy`uVBq!ia0vp^>OgGA!31JSOf>{jjKx9jP7LeL$-D$|SkfJR9T^xl z_H+M9WCij$3p^r=85sBugD~Uq{1qucL5ULAh?3y^w370~qEv>0#LT=By}Z;C1rt3( zJ;P+JIo?1+B|TjnLn7SYPTR=aV!-2iv&C~pvu++oSVD_Wfvv5nE)bZ0pYlVg#V`D! z!ovStBGw-9-^!V$3OI2n9+@n8eB)~??k+>$%lqEH-oGcfj@1`` zr`wJrD#~q@C7W`iy+t3iX+JW1@uB|B-t5F038i0ux(p(Z3jleJk4?5{7+w;y__(<} zuJ`N`<1ELPsJr@3I!lbsy|zB|ozGKj+gtX1i%#isSp0e+d?t2A_R_ + Text="@[Text:String:Windows Community Toolkit]" + FontFamily="@[FontFamily:String:Segoe UI]" + FontWeight="@[FontWeight:String:Normal]" + FontStyle="@[FontStyle:Enum:FontStyle.Normal]" + FontStretch="@[FontStretch:Enum:FontStretch.Normal]" + TextOrientation="@[TextOrientation:Enum:Orientation.Vertical]" + FontSize="@[FontSize:Slider:15:1-100]" /> \ No newline at end of file diff --git a/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/samples.json b/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/samples.json index 772c10b6cf5..eed4e6725b9 100644 --- a/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/samples.json +++ b/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/samples.json @@ -332,8 +332,8 @@ "About": "TODO", "CodeUrl": "https://github.com/Microsoft/WindowsCommunityToolkit/tree/master/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock", "XamlCodeFile": "DirectWriteTextBlockCode.bind", - // TODO: "Icon": "/SamplePages/InfiniteCanvas/InfiniteCanvas.png", - // TODO: check for API needed in 17734 "ApiCheck": "Windows.UI.Xaml.Controls.ColorPicker", + "Icon": "/SamplePages/DirectWriteTextBlock/DirectWriteTextBlock.png", + "ApiCheck": "Windows.UI.Xaml.Controls.ColorPicker", "BadgeUpdateVersionRequired": "April 2018 Update required", "DocumentationUrl": "https://raw.githubusercontent.com/Microsoft/WindowsCommunityToolkit/master/docs/controls/DirectWriteTextBlock.md" } diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock/DirectWriteTextBlock.cpp b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock/DirectWriteTextBlock.cpp index 8186c06074d..bc55458f2b7 100644 --- a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock/DirectWriteTextBlock.cpp +++ b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock/DirectWriteTextBlock.cpp @@ -103,7 +103,13 @@ Size DirectWriteTextBlock::MeasureOverride(Size availableSize) builder.SetTextWrapping(TextWrap); auto args = builder.BuildRenderArgs(); - return RenderText(args); + + // have to do this in order to modify the image measure correctly. + auto resultSize = RenderText(args); + m_image->Width = resultSize.Width; + m_image->Height = resultSize.Height; + m_image->Measure(availableSize); + return resultSize; } void DirectWriteTextBlock::Close() @@ -138,7 +144,7 @@ Size DirectWriteTextBlock::RenderText(DirectWriteTextRenderArgs const& args) { if (args.text->IsEmpty()) { - return Size{ 0, 0 }; + return Size(0.0f, 0.0f); } auto resourceManager = DirectWriteResourceManager::GetInstance(); @@ -240,6 +246,7 @@ Size DirectWriteTextBlock::RenderText(DirectWriteTextRenderArgs const& args) } m_image->Source = imageSource; + // XAML will rescale, so we divide by scale here. return Size{ static_cast(sisWidth / scale), static_cast(sisHeight / scale) }; } From 6a41d0130e6e00d7c48bab86bdc5b303733415d5 Mon Sep 17 00:00:00 2001 From: "Jun Ma (WINDOWS)" Date: Wed, 10 Oct 2018 23:55:02 +0900 Subject: [PATCH 09/29] Fix high contrast XAML TextBlock emulation. Basically add a background to the DirectWriteTextBlock which only appears in high contrast to make it look like standard XAML text block. --- .../DirectWriteTextBlockCode.bind | 26 ++++--- .../DirectWriteTextBlockPage.xaml | 5 +- .../DirectWriteTextBlock.cpp | 67 +++++++++++++++++-- .../DirectWriteTextBlock.h | 16 ++++- .../Themes/Generic.xaml | 12 ++-- 5 files changed, 104 insertions(+), 22 deletions(-) diff --git a/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/DirectWriteTextBlock/DirectWriteTextBlockCode.bind b/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/DirectWriteTextBlock/DirectWriteTextBlockCode.bind index 97a6f8ead5b..f00dde3c78f 100644 --- a/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/DirectWriteTextBlock/DirectWriteTextBlockCode.bind +++ b/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/DirectWriteTextBlock/DirectWriteTextBlockCode.bind @@ -5,15 +5,23 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:controls="using:Microsoft.Toolkit.Uwp.UI.Controls.WinRT" mc:Ignorable="d"> - + - + + + + \ No newline at end of file diff --git a/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/DirectWriteTextBlock/DirectWriteTextBlockPage.xaml b/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/DirectWriteTextBlock/DirectWriteTextBlockPage.xaml index 2cb3fd41ac5..e90f2903a0f 100644 --- a/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/DirectWriteTextBlock/DirectWriteTextBlockPage.xaml +++ b/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/DirectWriteTextBlock/DirectWriteTextBlockPage.xaml @@ -10,6 +10,9 @@ Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> - + + + + diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock/DirectWriteTextBlock.cpp b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock/DirectWriteTextBlock.cpp index bc55458f2b7..49c27f6fd18 100644 --- a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock/DirectWriteTextBlock.cpp +++ b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock/DirectWriteTextBlock.cpp @@ -19,6 +19,7 @@ using namespace Windows::UI::Xaml::Input; using namespace Windows::UI::Xaml::Interop; using namespace Windows::UI::Xaml::Media; using namespace Windows::UI::Xaml::Media::Imaging; +using namespace Windows::UI::ViewManagement; DependencyProperty^ DirectWriteTextBlock::m_textProperty = DependencyProperty::Register( L"Text", @@ -51,6 +52,10 @@ DirectWriteTextBlock::DirectWriteTextBlock() auto displayInfo = DisplayInformation::GetForCurrentView(); m_dpiChangedToken = displayInfo->DpiChanged += ref new TypedEventHandler(this, &DirectWriteTextBlock::OnDpiChanged); + m_accessibilitySettings = ref new AccessibilitySettings(); + m_highContrastChangedToken = m_accessibilitySettings->HighContrastChanged += ref new TypedEventHandler(this, &DirectWriteTextBlock::OnHighContrastSettingsChanged); + m_isHighContrast = m_accessibilitySettings->HighContrast; + #define REGISTER_INHERITED_PROPERTY_CALLBACK(token, inheritedProperty) \ token = RegisterPropertyChangedCallback(inheritedProperty, ref new DependencyPropertyChangedCallback(&DirectWriteTextBlock::OnInheritedDependencyPropertyChanged)) @@ -75,16 +80,27 @@ void DirectWriteTextBlock::OnApplyTemplate() __super::OnApplyTemplate(); auto maybeImage = dynamic_cast(GetTemplateChild(L"Image")); - if (maybeImage == nullptr) + if (!maybeImage) + { + winrt::throw_hresult(E_NOT_VALID_STATE); + } + + // this border is essentially just used to emulate the XAML text high contrast background. + // the consumer can use it to set background to the text block, but normally, it should just be + // left null. + auto maybeBorder = dynamic_cast(GetTemplateChild(L"TextBackground")); + if (!maybeBorder) { winrt::throw_hresult(E_NOT_VALID_STATE); } m_image = maybeImage; + m_textBackground = maybeBorder; } Size DirectWriteTextBlock::MeasureOverride(Size availableSize) { + UpdateTextBrushesForHighContrast(); auto displayInfo = DisplayInformation::GetForCurrentView(); DirectWriteRenderArgBuilder builder; builder.SetAvailableHeight(availableSize.Height); @@ -96,13 +112,14 @@ Size DirectWriteTextBlock::MeasureOverride(Size availableSize) builder.SetFontStretch(FontStretch); builder.SetFontStyle(FontStyle); builder.SetFontWeight(FontWeight); - builder.SetForegroundBrush(Foreground); + builder.SetForegroundBrush(m_textForegroundBrush); builder.SetText(Text); builder.SetTextLocale(TextLocale); builder.SetTextOrientation(TextOrientation); builder.SetTextWrapping(TextWrap); auto args = builder.BuildRenderArgs(); + UpdateElementsForHighContrast(); // have to do this in order to modify the image measure correctly. auto resultSize = RenderText(args); @@ -112,6 +129,34 @@ Size DirectWriteTextBlock::MeasureOverride(Size availableSize) return resultSize; } +void DirectWriteTextBlock::UpdateTextBrushesForHighContrast() +{ + if (m_isHighContrast) + { + // XAML High Contrast TextBlock behavior emulation: XAML on high contrast basically sets + // a background to the TextBlock in order to get text to always appear in High Contrast. + // To emulate this, we basically look up the applicable text brushes from the system + // resource dictionary and override any foreground/background the user may have set like + // standard textblock would. + + auto resources = Application::Current->Resources; + auto highContrastForeground = static_cast(resources->Lookup(L"SystemColorWindowTextColor")); + auto highContrastBackground = static_cast(resources->Lookup(L"SystemColorWindowColor")); + m_textForegroundBrush = ref new SolidColorBrush(highContrastForeground); + m_textBackgroundBrush = ref new SolidColorBrush(highContrastBackground); + } + else + { + m_textForegroundBrush = this->Foreground; + m_textBackgroundBrush = this->Background; + } +} + +void DirectWriteTextBlock::UpdateElementsForHighContrast() +{ + m_textBackground->Background = m_textBackgroundBrush; +} + void DirectWriteTextBlock::Close() { @@ -137,6 +182,12 @@ void DirectWriteTextBlock::Close() m_dpiChangedToken = {}; } + if (m_highContrastChangedToken.Value != 0) + { + m_accessibilitySettings->HighContrastChanged -= m_highContrastChangedToken; + m_highContrastChangedToken = {}; + } + #undef UNREGISTER_INHERITED_PROPERTY_CALLBACK } @@ -251,7 +302,7 @@ Size DirectWriteTextBlock::RenderText(DirectWriteTextRenderArgs const& args) return Size{ static_cast(sisWidth / scale), static_cast(sisHeight / scale) }; } -void DirectWriteTextBlock::OnDependencyPropertyChanged(DependencyObject^ d, DependencyPropertyChangedEventArgs^ /* e */) +void DirectWriteTextBlock::OnDependencyPropertyChanged(_In_ DependencyObject^ d, _In_ DependencyPropertyChangedEventArgs^ /* e */) { auto textBlockInstance = dynamic_cast(d); if (textBlockInstance) @@ -260,7 +311,7 @@ void DirectWriteTextBlock::OnDependencyPropertyChanged(DependencyObject^ d, Depe } } -void DirectWriteTextBlock::OnInheritedDependencyPropertyChanged(DependencyObject^ d, DependencyProperty^ /* e */) +void DirectWriteTextBlock::OnInheritedDependencyPropertyChanged(_In_ DependencyObject^ d, _In_ DependencyProperty^ /* e */) { auto textBlockInstance = dynamic_cast(d); if (textBlockInstance) @@ -269,8 +320,14 @@ void DirectWriteTextBlock::OnInheritedDependencyPropertyChanged(DependencyObject } } -void DirectWriteTextBlock::OnDpiChanged(DisplayInformation^ /* displayInfo */, Object^ /* obj */) +void DirectWriteTextBlock::OnDpiChanged(_In_ DisplayInformation^ /* displayInfo */, _In_ Object^ /* obj */) +{ + InvalidateMeasure(); +} + +void DirectWriteTextBlock::OnHighContrastSettingsChanged(_In_ AccessibilitySettings^ accessibilitySettings, _In_ Object^ /* obj */) { + m_isHighContrast = accessibilitySettings->HighContrast; InvalidateMeasure(); } diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock/DirectWriteTextBlock.h b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock/DirectWriteTextBlock.h index 5373f40c185..793cd46bdcb 100644 --- a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock/DirectWriteTextBlock.h +++ b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock/DirectWriteTextBlock.h @@ -83,13 +83,18 @@ public ref class DirectWriteTextBlock sealed : public Windows::UI::Xaml::Control Windows::Foundation::Size MeasureOverride(Windows::Foundation::Size availableSize) override; private: - static void OnDependencyPropertyChanged(Windows::UI::Xaml::DependencyObject^ d, Windows::UI::Xaml::DependencyPropertyChangedEventArgs^ e); - static void OnInheritedDependencyPropertyChanged(Windows::UI::Xaml::DependencyObject^ d, Windows::UI::Xaml::DependencyProperty^ e); - void OnDpiChanged(Windows::Graphics::Display::DisplayInformation^ displayInfo, Platform::Object^ obj); + static void OnDependencyPropertyChanged(_In_ Windows::UI::Xaml::DependencyObject^ d, _In_ Windows::UI::Xaml::DependencyPropertyChangedEventArgs^ e); + static void OnInheritedDependencyPropertyChanged(_In_ Windows::UI::Xaml::DependencyObject^ d, _In_ Windows::UI::Xaml::DependencyProperty^ e); + void OnDpiChanged(_In_ Windows::Graphics::Display::DisplayInformation^ displayInfo, _In_ Platform::Object^ obj); + void OnHighContrastSettingsChanged(_In_ Windows::UI::ViewManagement::AccessibilitySettings^ accessibilitySettings, _In_ Platform::Object^ obj); Windows::Foundation::Size RenderText(DirectWriteTextRenderArgs const& args); void Close(); + void UpdateTextBrushesForHighContrast(); + void UpdateElementsForHighContrast(); Windows::Foundation::EventRegistrationToken m_dpiChangedToken = {}; + Windows::Foundation::EventRegistrationToken m_highContrastChangedToken = {}; + long long m_foregroundChangedToken = 0; long long m_fontSizeChangedToken = 0; long long m_fontFamilyChangedToken = 0; @@ -98,7 +103,12 @@ public ref class DirectWriteTextBlock sealed : public Windows::UI::Xaml::Control long long m_fontWeightChangedToken = 0; long long m_fontStyleChangedToken = 0; + Windows::UI::ViewManagement::AccessibilitySettings^ m_accessibilitySettings; Windows::UI::Xaml::Controls::Image^ m_image; + Windows::UI::Xaml::Controls::Border^ m_textBackground; + Windows::UI::Xaml::Media::Brush^ m_textForegroundBrush; + Windows::UI::Xaml::Media::Brush^ m_textBackgroundBrush; + bool m_isHighContrast; }; END_NAMESPACE_CONTROLS_WINRT diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Themes/Generic.xaml b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Themes/Generic.xaml index d86d22a302d..d64e69275e9 100644 --- a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Themes/Generic.xaml +++ b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Themes/Generic.xaml @@ -19,12 +19,16 @@ - + + + - + From 581978c1d689b65506e4fa5fbdaafc10a50252b7 Mon Sep 17 00:00:00 2001 From: "Jun Ma (WINDOWS)" Date: Thu, 11 Oct 2018 00:04:21 +0900 Subject: [PATCH 10/29] use super::MeasureOverride instead of calling Measure on individual components. --- .../DirectWriteTextBlock/DirectWriteTextBlock.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock/DirectWriteTextBlock.cpp b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock/DirectWriteTextBlock.cpp index 49c27f6fd18..23bc9ba52e3 100644 --- a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock/DirectWriteTextBlock.cpp +++ b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock/DirectWriteTextBlock.cpp @@ -121,11 +121,10 @@ Size DirectWriteTextBlock::MeasureOverride(Size availableSize) auto args = builder.BuildRenderArgs(); UpdateElementsForHighContrast(); - // have to do this in order to modify the image measure correctly. auto resultSize = RenderText(args); - m_image->Width = resultSize.Width; - m_image->Height = resultSize.Height; - m_image->Measure(availableSize); + + // call __super::Measure after we've already set the source to the new image. + __super::MeasureOverride(availableSize); return resultSize; } From f44871c05580662b5076223bd87db6c95086991d Mon Sep 17 00:00:00 2001 From: "Jun Ma (WINDOWS)" Date: Thu, 11 Oct 2018 00:07:28 +0900 Subject: [PATCH 11/29] delete mistake folder --- .../Class1.cpp | 9 - Microsoft.Toolkit.Uwp.Controls.WinRT/Class1.h | 10 - ...crosoft.Toolkit.Uwp.Controls.WinRT.vcxproj | 257 ------------------ ...Toolkit.Uwp.Controls.WinRT.vcxproj.filters | 9 - Microsoft.Toolkit.Uwp.Controls.WinRT/pch.cpp | 1 - Microsoft.Toolkit.Uwp.Controls.WinRT/pch.h | 4 - 6 files changed, 290 deletions(-) delete mode 100644 Microsoft.Toolkit.Uwp.Controls.WinRT/Class1.cpp delete mode 100644 Microsoft.Toolkit.Uwp.Controls.WinRT/Class1.h delete mode 100644 Microsoft.Toolkit.Uwp.Controls.WinRT/Microsoft.Toolkit.Uwp.Controls.WinRT.vcxproj delete mode 100644 Microsoft.Toolkit.Uwp.Controls.WinRT/Microsoft.Toolkit.Uwp.Controls.WinRT.vcxproj.filters delete mode 100644 Microsoft.Toolkit.Uwp.Controls.WinRT/pch.cpp delete mode 100644 Microsoft.Toolkit.Uwp.Controls.WinRT/pch.h diff --git a/Microsoft.Toolkit.Uwp.Controls.WinRT/Class1.cpp b/Microsoft.Toolkit.Uwp.Controls.WinRT/Class1.cpp deleted file mode 100644 index da012af0a09..00000000000 --- a/Microsoft.Toolkit.Uwp.Controls.WinRT/Class1.cpp +++ /dev/null @@ -1,9 +0,0 @@ -#include "pch.h" -#include "Class1.h" - -using namespace Microsoft_Toolkit_Uwp_Controls_WinRT; -using namespace Platform; - -Class1::Class1() -{ -} diff --git a/Microsoft.Toolkit.Uwp.Controls.WinRT/Class1.h b/Microsoft.Toolkit.Uwp.Controls.WinRT/Class1.h deleted file mode 100644 index 22b19021f11..00000000000 --- a/Microsoft.Toolkit.Uwp.Controls.WinRT/Class1.h +++ /dev/null @@ -1,10 +0,0 @@ -#pragma once - -namespace Microsoft_Toolkit_Uwp_Controls_WinRT -{ - public ref class Class1 sealed - { - public: - Class1(); - }; -} diff --git a/Microsoft.Toolkit.Uwp.Controls.WinRT/Microsoft.Toolkit.Uwp.Controls.WinRT.vcxproj b/Microsoft.Toolkit.Uwp.Controls.WinRT/Microsoft.Toolkit.Uwp.Controls.WinRT.vcxproj deleted file mode 100644 index 7673cf3d2a5..00000000000 --- a/Microsoft.Toolkit.Uwp.Controls.WinRT/Microsoft.Toolkit.Uwp.Controls.WinRT.vcxproj +++ /dev/null @@ -1,257 +0,0 @@ - - - - - - Debug - ARM - - - Debug - Win32 - - - Debug - x64 - - - Release - ARM - - - Release - Win32 - - - Release - x64 - - - - - {fe15e3f0-76c1-4b81-ad36-c172690f23c7} - WindowsRuntimeComponent - Microsoft_Toolkit_Uwp_Controls_WinRT - en-US - 14.0 - true - Windows Store - 10.0.17134.0 - 10.0.15063.0 - 10.0 - - - - - - DynamicLibrary - true - v141 - - - DynamicLibrary - true - v141 - - - DynamicLibrary - true - v141 - - - DynamicLibrary - false - true - v141 - - - DynamicLibrary - false - true - v141 - - - DynamicLibrary - false - true - v141 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - false - - - - false - - - - false - - - - false - - - - false - - - - false - - - - - Use - _WINRT_DLL;%(PreprocessorDefinitions) - pch.h - $(IntDir)pch.pch - $(WindowsSDK_WindowsMetadata);$(AdditionalUsingDirectories) - /bigobj %(AdditionalOptions) - 28204 - - - Console - false - - - - - - Use - _WINRT_DLL;NDEBUG;%(PreprocessorDefinitions) - pch.h - $(IntDir)pch.pch - $(WindowsSDK_WindowsMetadata);$(AdditionalUsingDirectories) - /bigobj %(AdditionalOptions) - 28204 - - - Console - false - - - - - - Use - _WINRT_DLL;%(PreprocessorDefinitions) - pch.h - $(IntDir)pch.pch - $(WindowsSDK_WindowsMetadata);$(AdditionalUsingDirectories) - /bigobj %(AdditionalOptions) - 28204 - - - Console - false - - - - - - Use - _WINRT_DLL;NDEBUG;%(PreprocessorDefinitions) - pch.h - $(IntDir)pch.pch - $(WindowsSDK_WindowsMetadata);$(AdditionalUsingDirectories) - /bigobj %(AdditionalOptions) - 28204 - - - Console - false - - - - - - Use - _WINRT_DLL;%(PreprocessorDefinitions) - pch.h - $(IntDir)pch.pch - $(WindowsSDK_WindowsMetadata);$(AdditionalUsingDirectories) - /bigobj %(AdditionalOptions) - 28204 - - - Console - false - - - - - - Use - _WINRT_DLL;NDEBUG;%(PreprocessorDefinitions) - pch.h - $(IntDir)pch.pch - $(WindowsSDK_WindowsMetadata);$(AdditionalUsingDirectories) - /bigobj %(AdditionalOptions) - 28204 - - - Console - false - - - - - - - - - - - Create - Create - Create - Create - Create - Create - - - - - - - - - - diff --git a/Microsoft.Toolkit.Uwp.Controls.WinRT/Microsoft.Toolkit.Uwp.Controls.WinRT.vcxproj.filters b/Microsoft.Toolkit.Uwp.Controls.WinRT/Microsoft.Toolkit.Uwp.Controls.WinRT.vcxproj.filters deleted file mode 100644 index 9acb68c70e8..00000000000 --- a/Microsoft.Toolkit.Uwp.Controls.WinRT/Microsoft.Toolkit.Uwp.Controls.WinRT.vcxproj.filters +++ /dev/null @@ -1,9 +0,0 @@ - - - - - d7fdb929-d624-4f37-b5a4-783a214498ed - rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tga;tiff;tif;png;wav;mfcribbon-ms - - - diff --git a/Microsoft.Toolkit.Uwp.Controls.WinRT/pch.cpp b/Microsoft.Toolkit.Uwp.Controls.WinRT/pch.cpp deleted file mode 100644 index bcb5590be1b..00000000000 --- a/Microsoft.Toolkit.Uwp.Controls.WinRT/pch.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "pch.h" diff --git a/Microsoft.Toolkit.Uwp.Controls.WinRT/pch.h b/Microsoft.Toolkit.Uwp.Controls.WinRT/pch.h deleted file mode 100644 index 10fe677c728..00000000000 --- a/Microsoft.Toolkit.Uwp.Controls.WinRT/pch.h +++ /dev/null @@ -1,4 +0,0 @@ -#pragma once - -#include -#include From 89b6df3f0f5cadc0e5fab48cce4a59c0aacb1a82 Mon Sep 17 00:00:00 2001 From: "Jun Ma (WINDOWS)" Date: Thu, 11 Oct 2018 00:40:35 +0900 Subject: [PATCH 12/29] fix thumbnail --- .../DirectWriteTextBlock.png | Bin 424 -> 3689 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/DirectWriteTextBlock/DirectWriteTextBlock.png b/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/DirectWriteTextBlock/DirectWriteTextBlock.png index 32d8dde9337b8d390fe93447e86430212457074c..55f02676d95a93f07d1c0719d9fb7509303081a3 100644 GIT binary patch literal 3689 zcmc&%dpOg58{c?P8uD~7VMsM{D2I~MoEr}z6jHS2P>DGYP1F-AJ?0P+Gg6PFoRT$q zsFqA(RIbWt$(W{DMi|4pF8eL-`|o?b*Zao~-{1B9{_gw!+@Je%-`}flE=U>aZPFkR zNXF5@&K(2-s|o%;TPG>_zEjiOAou}Cxg%{rRb9$o1&iN;tq)m)K(+V{e3XP>y*}K* zCkh0TrTqMW+c5V61P`In_TJGRn4oAZDl!lhjye+-trr#;t!AXBucwdRUF0ON*5_zv z?HT9C9`wO)>D~4!0<*NPSne~(MMcq0qr~6}^w~IEUq9lBe9z6B_vBAqve_t;VC}4Y z)o)$aN$pFv0UIA5zH!(yH7FXC&pg3QB=t6Vy{l}b9IIaBdvVSBjy%@(D`Gmbj~of{ z=hAzmK)Ekhcygf42f^TbsbXSoG7`U)Y?EGRwQuvrg$Auhdc#TNXd-m}4c9=q9%wek$4_l8^M!@VLV zmXJG&e8iBK_-$r)2R^7>Lweo#kv!GTY~<#R-IY3)w|3$+)k?g4E*Lq%4qI7O*YQv1 zncq%M_6y|o=)~KBO9|RlPqvd)mc3VZoDQBI>l}W0b(1YbRyK8{4WEW?%Sb6h;!`z{ z8Fm}C>NpgO2a5LgH-rvXw=7F{swb5XB+d=CN0mT?Ua+5XUu&1Pv{>S1dXPQsIdJs) zMBZpVA++3uaIJrv9)s7>8U#$gb{pf?UM zynzsk>+})4CCteojM9 z<1PaB+ei5Z3?0_~$R^TvdA1+px)zX=C)Hf`8YAcU_yS{$A6HqEvYI9vv!hm)OEVrH zTas2JI&baMj+X_3D5P(&yh^j3Z-uCMZL&e(xd@L=}9YzIwdAiV>{+3 za)3wQK0ShWal#7+ErBQ0Nae*@_6Eb?F6YTKRUrrZKGmRXHt6G*97)-a~RkB^4 z^}|iIhA+&Vc_@I;&OB)uhg%LFY>Yv%-dD8KZYv9YLTlJ-jI_gv5Kha=h56w$)h`Ch zN9|fxmd!Tx<_b9pEfklMeJNJA)0koXvb;E9H$p3P0$i(%JRx-F)xojE0P40LRor*$ z`O$p;7vv~r>KnO3M1%#;M}(pZ`E9&_Uz7sF;QFBD0`csK@$S-^z>d5p2fJfFoXG#h zw(gA0&U2Z*TwhX{j8mS@RT5+L#9poY@0o`)gwe$^bmPc~sn$DqYCK|U&ntFBa$$8Ir#-SPm)7$02ON1Gsp zm$yd3&;4Nan#;430fWVfv!B$l&lsd<=R!|w?~LD=1uva=v|1hAU0E8)Q|;6pGdHw6 zO#1_WKX%l%ehG<(snn^C3PC)Lyk`H(VRSp`^C*;OdJxnBVAA&a z3-HQ}0d}_jnYVWs7qX%tdI%smYVTjTe-;=yuG!c|zr-KC-`iA^UWzpirz)kgktP5= zd>feEgc-L-!aGY##TyTIgTL$EweSP+I%Am}qiY3i9fXQ3~*40h$ z)Eao{=tRK)ILCMDQkwjPP?Ng5Dm==+@Li&eh?m1|C$oUZ84o3NTjX|C2ds- zT-U7W7#Rh;@YK{Ju{yFUkJb92dI8WY;$QC(@6kf#g!`@RJ+u=?WrH|WwLbs_E(U)oP2SFUrJt|ychCfY1*6j!} z_PO?0D@OJPVDsCZ%yTe@F&qQ)yb_84bkenWDoaXsbRR^Ko9o;h*&YJr)}3V;{t~TC za2Lqp90%X}&f>upNlD3UqP>q0WNv#d&5ZN(omSyL=jT#MLkZdmi)<3*qPWx-1bIV4 zEW3|k;s(?ruI@$Y7UwxH-GarerMjc_5FfKfvWWLoc!+sN=02jwqP@RA{a%}>{qPuG zdI87BS-Y4}KqAzMd{)YvC8}4AjM9Ec{~rJ6jLDl2-crrvl4ggHp$M{g!`a^ZU4wcB zmzTd&BXTE`CA8%Zxn!;OA5paJ0GSvrqkSPIWW0u~ikbi~ElgAk8ZA&~yuY0bZs!^hQm6lAJOtfvg-1vNIL-U}P~ld1QPMJx z$+$2N>?1z?suyJ;Xc^IwmN=1nZ|^t~B&fHBaMPXNUnybi1S3I0eZmjc+BA{|BAtrF zS+H4{_jG*8pHgzWXcr@ea4?iAlHEtTOKtxxELS3|V`oeZnncGmu^Z&^)*}9N-qhE~ zOV>dV`}Ra;SStdw>MSxb6ojnfdbWjXA_+_>RP4kF+Ym?6z zVJIC5-GV+6c*IT$5G447*h8O3yN1q^)crdcD*ExzEbi2EKmjA067R5|N^sJJC66;6 zjP{tVgmSyQS;``zY!)>8afPbVG83r)YqCS`a|^P=9GtkR#xPoE+~ zAdnrTc0TO{c5utenDjkB+Ia`HOR_So0iELx#xn`E#~J1M$i6&N$rxc-Q;n0B`KW3X zbwZJAG}HGuWQ1;TSeJ7#w6DG*3c?Z%4=KgsbxHYB@^I&ydjl+A3%g3DtKa_4MA>mN zvv^INP)R4BUpmn8&cdArW)F}J*Sh>7WdoY*&~tsiW{F7f25;M^n+BpemjSJu`8t zRUx8(mffGTRsszXg3&cyLSy7(Et*iNR+!wtQ#aB3rF!bbPEL^-R`2JOrQ`SXz_KTP zAQmI5MHIBJwZv@_%!QP%@5<4`(VQHAig)cPd+)k{_1fD_g`=xF{ejP;7jN%6LITpGgttw0G1|EFus&zsXb iEj5tlx9sK?Fx+_X%h0DChJu?Q$kE=#uFB@*rGEi{sLRIy delta 347 zcmV-h0i^!v9H;{!iBL{Q4GJ0x0000DNk~Le0000d0000!2m$~A04ErgF_9rye*qau zL_t(oN9~re4TLZZMcIT&n1d~D2v%T(OmICtH7zYIEj9O)_#%W(SK%O`{|Xd4NMH7M z0+kR#2qDCi8OO2fItz+1P1C;b>$(oZ&@_!@3sBc}-}h+4vMeD4GPdUpl1V;Q&y%(7 z`GJzHzSYn3yltDMoXD!UOOt6ee;H;iCA~l+i%})DI=XxGl1WCm#3Unzd33UETT2z- zhAZMW=pQ~t4oMca?FYW1$}I>u`sfqPU6^a7!zDiH%+AqQgz?q=PENlp7DUj#G2y(@VfXV& tKTk%MP{mQOAVTQgVIhPNLWmPp^#Ku+4J Date: Thu, 11 Oct 2018 00:45:13 +0900 Subject: [PATCH 13/29] update headers --- .../DirectWriteTextBlock/DirectWriteTextBlockPage.xaml.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/DirectWriteTextBlock/DirectWriteTextBlockPage.xaml.cs b/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/DirectWriteTextBlock/DirectWriteTextBlockPage.xaml.cs index 8be952e8843..cffb3222941 100644 --- a/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/DirectWriteTextBlock/DirectWriteTextBlockPage.xaml.cs +++ b/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/DirectWriteTextBlock/DirectWriteTextBlockPage.xaml.cs @@ -1,4 +1,8 @@ -using System; +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; using System.Collections.Generic; using System.IO; using System.Linq; From 8af897e8b36371ffc78da1a819d408093c0fdf3e Mon Sep 17 00:00:00 2001 From: Nikola Metulev Date: Wed, 10 Oct 2018 20:38:40 -0700 Subject: [PATCH 14/29] setting up nuspec build --- .../Microsoft.Toolkit.Uwp.UI.Controls.WinRT.vcxproj | 2 ++ Windows Community Toolkit.sln | 1 + 2 files changed, 3 insertions(+) diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Microsoft.Toolkit.Uwp.UI.Controls.WinRT.vcxproj b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Microsoft.Toolkit.Uwp.UI.Controls.WinRT.vcxproj index b33e6b6661c..d4fab13e435 100644 --- a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Microsoft.Toolkit.Uwp.UI.Controls.WinRT.vcxproj +++ b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Microsoft.Toolkit.Uwp.UI.Controls.WinRT.vcxproj @@ -125,6 +125,7 @@ /bigobj %(AdditionalOptions) 28204 stdcpplatest + true Console @@ -141,6 +142,7 @@ /bigobj %(AdditionalOptions) 28204 stdcpplatest + true Console diff --git a/Windows Community Toolkit.sln b/Windows Community Toolkit.sln index a32e0efc450..d4bb12e3d49 100644 --- a/Windows Community Toolkit.sln +++ b/Windows Community Toolkit.sln @@ -706,6 +706,7 @@ Global {262BB7CE-EF42-4BF7-B90C-107E6CBB57FF} = {096ECFD7-7035-4487-9C87-81DCE9389620} {A122EA02-4DE7-413D-BFBF-AF7DFC668DD6} = {B30036C4-D514-4E5B-A323-587A061772CE} {D4D78CBA-B238-4794-89A0-4F1A2D8FEA97} = {F1AFFFA7-28FE-4770-BA48-10D76F3E59BC} + {D4C7AC54-826A-4412-8461-A7C7FD86534B} = {F1AFFFA7-28FE-4770-BA48-10D76F3E59BC} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {5403B0C4-F244-4F73-A35C-FE664D0F4345} From f5227b5ab2c03ff002e314589a588eb94f1f24d1 Mon Sep 17 00:00:00 2001 From: Nikola Metulev Date: Wed, 10 Oct 2018 20:38:56 -0700 Subject: [PATCH 15/29] added nuspec file --- ...osoft.Toolkit.Uwp.UI.Controls.WinRT.nuspec | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 build/Microsoft.Toolkit.Uwp.UI.Controls.WinRT.nuspec diff --git a/build/Microsoft.Toolkit.Uwp.UI.Controls.WinRT.nuspec b/build/Microsoft.Toolkit.Uwp.UI.Controls.WinRT.nuspec new file mode 100644 index 00000000000..c934d92f271 --- /dev/null +++ b/build/Microsoft.Toolkit.Uwp.UI.Controls.WinRT.nuspec @@ -0,0 +1,37 @@ + + + + Microsoft.Toolkit.Uwp.UI.Controls.WinRT + $version$ + Windows Community Toolkit WinRT Controls + Microsoft.Toolkit + Microsoft.Toolkit + https://raw.githubusercontent.com/windows-toolkit/WindowsCommunityToolkit/master/build/nuget.png + https://github.com/windows-toolkit/WindowsCommunityToolkit/blob/master/license.md + https://github.com/windows-toolkit/WindowsCommunityToolkit + true + This library provides WinRT XAML templated controls. It is part of the Windows Community Toolkit. + v5.0 release https://github.com/Microsoft/WindowsCommunityToolkit/releases + (c) .NET Foundation and Contributors. All rights reserved. + UWP Toolkit Windows Controls DirectWriteTextBlock + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file From 68b0928a476b8cb030a3285367294dac7f64b920 Mon Sep 17 00:00:00 2001 From: Nikola Metulev Date: Wed, 10 Oct 2018 20:44:30 -0700 Subject: [PATCH 16/29] including themes.xaml in nuspec --- build/Microsoft.Toolkit.Uwp.UI.Controls.WinRT.nuspec | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/build/Microsoft.Toolkit.Uwp.UI.Controls.WinRT.nuspec b/build/Microsoft.Toolkit.Uwp.UI.Controls.WinRT.nuspec index c934d92f271..712faf8296d 100644 --- a/build/Microsoft.Toolkit.Uwp.UI.Controls.WinRT.nuspec +++ b/build/Microsoft.Toolkit.Uwp.UI.Controls.WinRT.nuspec @@ -21,17 +21,17 @@ - - - + + + \ No newline at end of file From f7efd9e72873d7bfc25ab3dfa00b7b0d27cf5bf2 Mon Sep 17 00:00:00 2001 From: Nikola Metulev Date: Wed, 10 Oct 2018 21:01:46 -0700 Subject: [PATCH 17/29] added nuget targets file --- .../Microsoft.Toolkit.Uwp.UI.Controls.WinRT.targets | 13 +++++++++++++ .../Microsoft.Toolkit.Uwp.UI.Controls.WinRT.vcxproj | 9 +++++++++ .../Microsoft.Toolkit.Uwp.UI.Controls.WinRT.nuspec | 3 +++ 3 files changed, 25 insertions(+) create mode 100644 Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Microsoft.Toolkit.Uwp.UI.Controls.WinRT.targets diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Microsoft.Toolkit.Uwp.UI.Controls.WinRT.targets b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Microsoft.Toolkit.Uwp.UI.Controls.WinRT.targets new file mode 100644 index 00000000000..671d60f6101 --- /dev/null +++ b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Microsoft.Toolkit.Uwp.UI.Controls.WinRT.targets @@ -0,0 +1,13 @@ + + + + x86 + $(Platform) + + + + Microsoft.Toolkit.Uwp.UI.Controls.WinRT.dll + + + + \ No newline at end of file diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Microsoft.Toolkit.Uwp.UI.Controls.WinRT.vcxproj b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Microsoft.Toolkit.Uwp.UI.Controls.WinRT.vcxproj index d4fab13e435..ad5a0cef760 100644 --- a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Microsoft.Toolkit.Uwp.UI.Controls.WinRT.vcxproj +++ b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Microsoft.Toolkit.Uwp.UI.Controls.WinRT.vcxproj @@ -102,18 +102,24 @@ false + ..\Toolkit.ruleset + true false false + ..\Toolkit.ruleset + true false false + ..\Toolkit.ruleset + true @@ -143,6 +149,7 @@ 28204 stdcpplatest true + true Console @@ -175,6 +182,7 @@ /bigobj %(AdditionalOptions) 28204 stdcpplatest + true Console @@ -207,6 +215,7 @@ /bigobj %(AdditionalOptions) 28204 stdcpplatest + true Console diff --git a/build/Microsoft.Toolkit.Uwp.UI.Controls.WinRT.nuspec b/build/Microsoft.Toolkit.Uwp.UI.Controls.WinRT.nuspec index 712faf8296d..4ffc73e3597 100644 --- a/build/Microsoft.Toolkit.Uwp.UI.Controls.WinRT.nuspec +++ b/build/Microsoft.Toolkit.Uwp.UI.Controls.WinRT.nuspec @@ -33,5 +33,8 @@ + + + \ No newline at end of file From db6d408fa3bc333759fc586f4ee4bc5f7c489463 Mon Sep 17 00:00:00 2001 From: "Jun Ma (WINDOWS)" Date: Mon, 15 Oct 2018 01:14:45 +0900 Subject: [PATCH 18/29] Fix some feedback: * Move font loader into DirectWriteTextBlock folder as it's just there to map UWP into DirectWrite anyway. Rename it. * Fix documentation bugs * Fix comment at top of files. * Make TextOrientation to be ReadingDirection and map it directly into DirectWrite * Make some more custom enums (having a lot of issues getting C# to see these in the .bind file). * Add retry logic to rebuild D3D device which is required sometimes. --- .../DirectWriteTextBlockCode.bind | 3 +- .../SamplePages/samples.json | 2 +- .../DirectWriteFontCollectionLoader.cpp | 108 ++++++++++++++++++ .../DirectWriteFontCollectionLoader.h | 61 ++++++++++ .../DirectWriteFontFileEnumerator.cpp | 71 ++++++++++++ .../DirectWriteFontFileEnumerator.h | 43 +++++++ .../DirectWriteRenderArgBuilder.cpp | 63 +++++++--- .../DirectWriteRenderArgBuilder.h | 72 +++++++++--- .../DirectWriteResourceManager.cpp | 14 ++- .../DirectWriteResourceManager.h | 23 ++-- .../DirectWriteTextBlock.cpp | 63 +++++++--- .../DirectWriteTextBlock.h | 58 ++++++++-- .../DirectWriteUniversalPackageFontData.h | 15 +++ ...soft.Toolkit.Uwp.UI.Controls.WinRT.vcxproj | 32 ++++-- ...lkit.Uwp.UI.Controls.WinRT.vcxproj.filters | 30 ++--- .../Themes/Generic.xaml | 8 +- .../FontCollectionLoader.cpp | 107 ----------------- .../FontCollectionLoader.h | 60 ---------- .../FontFileEnumerator.cpp | 70 ------------ .../FontFileEnumerator.h | 42 ------- .../UniversalPackageFontData.h | 14 --- .../pch.cpp | 6 +- Microsoft.Toolkit.Uwp.UI.Controls.WinRT/pch.h | 15 ++- 23 files changed, 588 insertions(+), 392 deletions(-) create mode 100644 Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock/DirectWriteFontCollectionLoader.cpp create mode 100644 Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock/DirectWriteFontCollectionLoader.h create mode 100644 Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock/DirectWriteFontFileEnumerator.cpp create mode 100644 Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock/DirectWriteFontFileEnumerator.h create mode 100644 Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock/DirectWriteUniversalPackageFontData.h delete mode 100644 Microsoft.Toolkit.Uwp.UI.Controls.WinRT/UniversalWindowsAppPackageFontLoader/FontCollectionLoader.cpp delete mode 100644 Microsoft.Toolkit.Uwp.UI.Controls.WinRT/UniversalWindowsAppPackageFontLoader/FontCollectionLoader.h delete mode 100644 Microsoft.Toolkit.Uwp.UI.Controls.WinRT/UniversalWindowsAppPackageFontLoader/FontFileEnumerator.cpp delete mode 100644 Microsoft.Toolkit.Uwp.UI.Controls.WinRT/UniversalWindowsAppPackageFontLoader/FontFileEnumerator.h delete mode 100644 Microsoft.Toolkit.Uwp.UI.Controls.WinRT/UniversalWindowsAppPackageFontLoader/UniversalPackageFontData.h diff --git a/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/DirectWriteTextBlock/DirectWriteTextBlockCode.bind b/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/DirectWriteTextBlock/DirectWriteTextBlockCode.bind index f00dde3c78f..0945e9711d9 100644 --- a/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/DirectWriteTextBlock/DirectWriteTextBlockCode.bind +++ b/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/DirectWriteTextBlock/DirectWriteTextBlockCode.bind @@ -7,7 +7,7 @@ mc:Ignorable="d"> - + diff --git a/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/samples.json b/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/samples.json index eed4e6725b9..fc45dc49854 100644 --- a/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/samples.json +++ b/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/samples.json @@ -329,7 +329,7 @@ { "Name": "DirectWriteTextBlock", "Type": "DirectWriteTextBlockPage", - "About": "TODO", + "About": "DirectWriteTextBlock is a text block like class which generates an image using the DirectWrite API and displays it. Display vertically oriented text with it.", "CodeUrl": "https://github.com/Microsoft/WindowsCommunityToolkit/tree/master/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock", "XamlCodeFile": "DirectWriteTextBlockCode.bind", "Icon": "/SamplePages/DirectWriteTextBlock/DirectWriteTextBlock.png", diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock/DirectWriteFontCollectionLoader.cpp b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock/DirectWriteFontCollectionLoader.cpp new file mode 100644 index 00000000000..671b29377a1 --- /dev/null +++ b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock/DirectWriteFontCollectionLoader.cpp @@ -0,0 +1,108 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +#include "pch.h" +#include +#include +#include +#include "DirectWriteFontFileEnumerator.h" +#include "DirectWriteFontCollectionLoader.h" + +BEGIN_NAMESPACE_CONTROLS_WINRT + +winrt::com_ptr DirectWriteFontCollectionLoader::s_comInstance; + +DirectWriteFontCollectionLoader::DirectWriteFontCollectionLoader() +{ +} + +DirectWriteFontCollectionLoader::~DirectWriteFontCollectionLoader() +{ +} + +bool DirectWriteFontCollectionLoader::HasCustomFontFamily(Platform::String^ xamlFontFamily) +{ + // is there a .ttf in the path? + std::wstring wstringPath{ xamlFontFamily->Data() }; + std::transform(wstringPath.begin(), wstringPath.end(), wstringPath.begin(), towlower); + auto foundCustomFontFile = wstringPath.find(L".ttf#", 0); + return foundCustomFontFile != std::wstring::npos; +} + +void DirectWriteFontCollectionLoader::ParseXamlFontFamily(_In_ Platform::String^ xamlFontFamily, _Out_ DirectWriteUniversalPackageFontData& parsedFont) +{ + parsedFont = {}; + std::wstring wstringPath{ xamlFontFamily->Data() }; + auto delimLocation = wstringPath.find(L'#'); + if (delimLocation != std::wstring::npos) + { + auto path = wstringPath.substr(0, delimLocation); + std::replace(path.begin(), path.end(), L'/', L'\\'); + parsedFont.packageFontFilePath = path; + parsedFont.customFontName = wstringPath.substr(delimLocation + 1); + } +} + +bool DirectWriteFontCollectionLoader::FindCachedEnumerator(Platform::String^ xamlFontFamily, winrt::com_ptr& enumerator) +{ + for (auto& entry : m_fontEnumerators) + { + if (entry.customFont->Equals(xamlFontFamily)) + { + enumerator = entry.enumerator; + return true; + } + } + + return false; +} + +IFACEMETHODIMP DirectWriteFontCollectionLoader::CreateEnumeratorFromKey(_In_ IDWriteFactory* factory, void const* collectionKey, unsigned int collectionKeySize, _Outptr_ IDWriteFontFileEnumerator** fontFileEnumerator) +try +{ + *fontFileEnumerator = nullptr; + auto xamlFontFamily = ref new Platform::String(reinterpret_cast(collectionKey), collectionKeySize); + + if (HasCustomFontFamily(xamlFontFamily)) + { + winrt::com_ptr cachedEnumerator; + if (!FindCachedEnumerator(xamlFontFamily, cachedEnumerator)) + { + auto enumerator{ winrt::make_self() }; + DirectWriteUniversalPackageFontData parseData = {}; + ParseXamlFontFamily(xamlFontFamily, parseData); + winrt::check_hresult(enumerator->Initialize(factory, parseData)); + + FontEnumeratorEntry entry = {}; + entry.customFont = xamlFontFamily; + entry.enumerator = enumerator; + m_fontEnumerators.push_back(std::move(entry)); + cachedEnumerator = enumerator; + } + + winrt::check_hresult(cachedEnumerator->QueryInterface(IID_PPV_ARGS(fontFileEnumerator))); + } + else + { + winrt::throw_hresult(E_INVALIDARG); + } + + return S_OK; +} +catch (...) +{ + return winrt::to_hresult(); +} + +winrt::com_ptr& DirectWriteFontCollectionLoader::GetInstance() +{ + if (!s_comInstance) + { + s_comInstance = winrt::make(); + } + + return s_comInstance; +} + +END_NAMESPACE_CONTROLS_WINRT \ No newline at end of file diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock/DirectWriteFontCollectionLoader.h b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock/DirectWriteFontCollectionLoader.h new file mode 100644 index 00000000000..1bc03199654 --- /dev/null +++ b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock/DirectWriteFontCollectionLoader.h @@ -0,0 +1,61 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +#pragma once +#include "DirectWriteUniversalPackageFontData.h" + +BEGIN_NAMESPACE_CONTROLS_WINRT + +/// +/// This is just to glue together a custom font file in the Universal Windows app package +/// to a custom DWrite Font. All it does is provide an enumerator that returns 1 font (the custom font) +/// and doesn't support things like font fallbacks. +/// +struct DirectWriteFontCollectionLoader : winrt::implements +{ +public: + DirectWriteFontCollectionLoader(); + virtual ~DirectWriteFontCollectionLoader(); + + /// + /// Create the enumerator to the Universal Windows Application package. + /// + IFACEMETHOD(CreateEnumeratorFromKey)( + _In_ IDWriteFactory* factory, + void const* collectionKey, // XAML FontFamily Syntax (something.ttf)#font + unsigned int collectionKeySize, + _Outptr_ IDWriteFontFileEnumerator** fontFileEnumerator + ); + + /// + /// This sees if the incoming XAML FontFamily value has something that looks like + /// a custom font file like foo.ttf#bar + /// + static bool HasCustomFontFamily(Platform::String^ xamlFontFamily); + + /// + /// This parses something that looks like /foo/bar.ttf#baz into the ttf path and the font name (baz). + /// + static void ParseXamlFontFamily(Platform::String^ xamlFontFamily, _Out_ DirectWriteUniversalPackageFontData& parsedFont); + + /// + /// Get the singleton loader. + /// + static winrt::com_ptr& GetInstance(); + +private: + struct FontEnumeratorEntry + { + Platform::String^ customFont; + winrt::com_ptr enumerator; + }; + + // enumerators are cached due to memory usages. + bool FindCachedEnumerator(Platform::String^ xamlFontFamily, winrt::com_ptr& enumerator); + + std::vector m_fontEnumerators; + static winrt::com_ptr s_comInstance; +}; + +END_NAMESPACE_CONTROLS_WINRT \ No newline at end of file diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock/DirectWriteFontFileEnumerator.cpp b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock/DirectWriteFontFileEnumerator.cpp new file mode 100644 index 00000000000..a48e8870b38 --- /dev/null +++ b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock/DirectWriteFontFileEnumerator.cpp @@ -0,0 +1,71 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +#include "pch.h" +#include "DirectWriteFontFileEnumerator.h" + +BEGIN_NAMESPACE_CONTROLS_WINRT + +using namespace Windows::Storage; + +DirectWriteFontFileEnumerator::DirectWriteFontFileEnumerator() +{ +} + +DirectWriteFontFileEnumerator::~DirectWriteFontFileEnumerator() +{ +} + +HRESULT DirectWriteFontFileEnumerator::Initialize(_In_ IDWriteFactory* factory, const DirectWriteUniversalPackageFontData& packageFont) +try +{ + if ((factory == nullptr) || packageFont.packageFontFilePath.empty() || packageFont.customFontName.empty()) + { + winrt::throw_hresult(E_INVALIDARG); + } + + m_factory.attach(factory); + m_packageFontArgs = packageFont; + return S_OK; +} +catch (...) +{ + return winrt::to_hresult(); +} + +IFACEMETHODIMP DirectWriteFontFileEnumerator::MoveNext(_Out_ BOOL* hasCurrentFile) +try +{ + *hasCurrentFile = FALSE; + if (!m_enumerated) + { + m_currentFontFile = nullptr; + auto uwappStorage = Windows::ApplicationModel::Package::Current->InstalledLocation; + std::wstring filePath{ uwappStorage->Path->Data() }; + filePath.append(m_packageFontArgs.packageFontFilePath); + winrt::check_hresult(m_factory->CreateFontFileReference(filePath.c_str(), nullptr, m_currentFontFile.put())); + + *hasCurrentFile = TRUE; + m_enumerated = true; + } + + return S_OK; +} +catch (...) +{ + return winrt::to_hresult(); +} + +IFACEMETHODIMP DirectWriteFontFileEnumerator::GetCurrentFontFile(_Outptr_ IDWriteFontFile** fontFile) +try +{ + m_currentFontFile.copy_to(fontFile); + return S_OK; +} +catch (...) +{ + return winrt::to_hresult(); +} + +END_NAMESPACE_CONTROLS_WINRT \ No newline at end of file diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock/DirectWriteFontFileEnumerator.h b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock/DirectWriteFontFileEnumerator.h new file mode 100644 index 00000000000..548703af69f --- /dev/null +++ b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock/DirectWriteFontFileEnumerator.h @@ -0,0 +1,43 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +#pragma once +#include "DirectWriteUniversalPackageFontData.h" + +BEGIN_NAMESPACE_CONTROLS_WINRT + +/// +/// This is an enumerator that basically just enumerates 1 custom font into DWrite from the Universal Windows App package. +/// It's extremely simplistic and basically just connects the Universal App Package files to DWrite. +/// +struct DirectWriteFontFileEnumerator : winrt::implements +{ +public: + DirectWriteFontFileEnumerator(); + virtual ~DirectWriteFontFileEnumerator(); + + /// + /// This is called consecutively by DWrite until we return FALSE to hasCurrentFile to enumerate the custom + /// font + /// + IFACEMETHOD(MoveNext)(_Out_ BOOL* hasCurrentFile); + + /// + /// This is called by DWrite to get the custom font file. + /// + IFACEMETHOD(GetCurrentFontFile)(_Outptr_ IDWriteFontFile** fontFile); + + /// + /// Initializes the enumerator + /// + HRESULT Initialize(_In_ IDWriteFactory* factory, const DirectWriteUniversalPackageFontData& packageFont); + +private: + winrt::com_ptr m_factory; + winrt::com_ptr m_currentFontFile; + DirectWriteUniversalPackageFontData m_packageFontArgs = {}; + bool m_enumerated = false; +}; + +END_NAMESPACE_CONTROLS_WINRT \ No newline at end of file diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock/DirectWriteRenderArgBuilder.cpp b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock/DirectWriteRenderArgBuilder.cpp index 727eff8aace..fabc73217b5 100644 --- a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock/DirectWriteRenderArgBuilder.cpp +++ b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock/DirectWriteRenderArgBuilder.cpp @@ -1,7 +1,11 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + #include "pch.h" #include "DirectWriteRenderArgBuilder.h" #include "DirectWriteResourceManager.h" -#include "UniversalWindowsAppPackageFontLoader\FontCollectionLoader.h" +#include "DirectWriteFontCollectionLoader.h" BEGIN_NAMESPACE_CONTROLS_WINRT @@ -32,6 +36,7 @@ DirectWriteRenderArgBuilder::DirectWriteRenderArgBuilder() m_builtArgs.textLocale = ref new String(L"en-US"); m_builtArgs.textWrapping = DWRITE_WORD_WRAPPING::DWRITE_WORD_WRAPPING_NO_WRAP; m_builtArgs.fontCollection = nullptr; + m_builtArgs.textAlignment = DWRITE_TEXT_ALIGNMENT_LEADING; } void DirectWriteRenderArgBuilder::SetFontFamily(FontFamily^ fontFamily) @@ -149,17 +154,23 @@ void DirectWriteRenderArgBuilder::SetFontStretch(FontStretch fontStretch) } } -void DirectWriteRenderArgBuilder::SetTextOrientation(Orientation textOrientation) +void DirectWriteRenderArgBuilder::SetTextReadingDirection(DirectWriteReadingDirection textReadingDirection) { - switch (textOrientation) + switch (textReadingDirection) { - case Orientation::Vertical: __fallthrough; + case DirectWriteReadingDirection::TopToBottom: __fallthrough; default: m_builtArgs.readingDirection = DWRITE_READING_DIRECTION::DWRITE_READING_DIRECTION_TOP_TO_BOTTOM; break; - case Orientation::Horizontal: + case DirectWriteReadingDirection::LeftToRight: m_builtArgs.readingDirection = DWRITE_READING_DIRECTION::DWRITE_READING_DIRECTION_LEFT_TO_RIGHT; break; + case DirectWriteReadingDirection::RightToLeft: + m_builtArgs.readingDirection = DWRITE_READING_DIRECTION::DWRITE_READING_DIRECTION_RIGHT_TO_LEFT; + break; + case DirectWriteReadingDirection::BottomToTop: + m_builtArgs.readingDirection = DWRITE_READING_DIRECTION::DWRITE_READING_DIRECTION_BOTTOM_TO_TOP; + break; } } @@ -218,20 +229,46 @@ void DirectWriteRenderArgBuilder::SetFontWeight(FontWeight fontWeight) } } -void DirectWriteRenderArgBuilder::SetTextWrapping(TextWrapping textWrapping) +void DirectWriteRenderArgBuilder::SetTextWrapping(DirectWriteWordWrapping textWrapping) { switch (textWrapping) { - case TextWrapping::NoWrap: + case DirectWriteWordWrapping::NoWrap: default: m_builtArgs.textWrapping = DWRITE_WORD_WRAPPING::DWRITE_WORD_WRAPPING_NO_WRAP; break; - case TextWrapping::Wrap: + case DirectWriteWordWrapping::Wrap: m_builtArgs.textWrapping = DWRITE_WORD_WRAPPING::DWRITE_WORD_WRAPPING_WRAP; break; - case TextWrapping::WrapWholeWords: + case DirectWriteWordWrapping::WholeWord: m_builtArgs.textWrapping = DWRITE_WORD_WRAPPING::DWRITE_WORD_WRAPPING_WHOLE_WORD; break; + case DirectWriteWordWrapping::EmergencyBreak: + m_builtArgs.textWrapping = DWRITE_WORD_WRAPPING::DWRITE_WORD_WRAPPING_EMERGENCY_BREAK; + break; + case DirectWriteWordWrapping::Character: + m_builtArgs.textWrapping = DWRITE_WORD_WRAPPING::DWRITE_WORD_WRAPPING_CHARACTER; + break; + } +} + +void DirectWriteRenderArgBuilder::SetTextAlignment(DirectWriteTextAlignment textAlignment) +{ + switch (textAlignment) + { + case DirectWriteTextAlignment::Leading: + default: + m_builtArgs.textAlignment = DWRITE_TEXT_ALIGNMENT::DWRITE_TEXT_ALIGNMENT_LEADING; + break; + case DirectWriteTextAlignment::Trailing: + m_builtArgs.textAlignment = DWRITE_TEXT_ALIGNMENT::DWRITE_TEXT_ALIGNMENT_TRAILING; + break; + case DirectWriteTextAlignment::Center: + m_builtArgs.textAlignment = DWRITE_TEXT_ALIGNMENT::DWRITE_TEXT_ALIGNMENT_CENTER; + break; + case DirectWriteTextAlignment::Justified: + m_builtArgs.textAlignment = DWRITE_TEXT_ALIGNMENT::DWRITE_TEXT_ALIGNMENT_JUSTIFIED; + break; } } @@ -272,13 +309,13 @@ void DirectWriteRenderArgBuilder::BuildFontCollection(Platform::String^ fontFami { // default arg is system font collection, what we're looking for is if we're trying to // find a local custom ttf file. - if (UniversalWindowsAppPackageFontLoader::FontCollectionLoader::HasCustomFontFamily(fontFamily)) + if (DirectWriteFontCollectionLoader::HasCustomFontFamily(fontFamily)) { auto resourceManager = DirectWriteResourceManager::GetInstance(); auto dwriteFactory = resourceManager->GetDirectWriteFactoryNoRef(); - UniversalWindowsAppPackageFontLoader::UniversalPackageFontData parseData = {}; - UniversalWindowsAppPackageFontLoader::FontCollectionLoader::ParseXamlFontFamily(fontFamily, parseData); - auto customLoader = UniversalWindowsAppPackageFontLoader::FontCollectionLoader::GetInstance(); + DirectWriteUniversalPackageFontData parseData = {}; + DirectWriteFontCollectionLoader::ParseXamlFontFamily(fontFamily, parseData); + auto customLoader = DirectWriteFontCollectionLoader::GetInstance(); // the key is a void* meaning the size is actual size. auto fontFamilyString = fontFamily->Data(); diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock/DirectWriteRenderArgBuilder.h b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock/DirectWriteRenderArgBuilder.h index 20661e93b0f..d79ccf793e6 100644 --- a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock/DirectWriteRenderArgBuilder.h +++ b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock/DirectWriteRenderArgBuilder.h @@ -1,7 +1,36 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + #pragma once BEGIN_NAMESPACE_CONTROLS_WINRT +public enum class DirectWriteReadingDirection : int +{ + LeftToRight, + RightToLeft, + TopToBottom, + BottomToTop +}; + +public enum class DirectWriteTextAlignment : int +{ + Leading, + Trailing, + Center, + Justified +}; + +public enum class DirectWriteWordWrapping : int +{ + Wrap, + NoWrap, + EmergencyBreak, + WholeWord, + Character +}; + /// /// These are arguments which are used to render the DWrite string. /// @@ -17,6 +46,7 @@ struct DirectWriteTextRenderArgs DWRITE_FLOW_DIRECTION flowDirection; DWRITE_FONT_WEIGHT fontWeight; DWRITE_WORD_WRAPPING textWrapping; + DWRITE_TEXT_ALIGNMENT textAlignment; float fontSize; float rawPixelsPerViewPixel; float availableWidth; @@ -31,7 +61,7 @@ struct DirectWriteTextRenderArgs /// is using the text block from C# (most users are expected to do this), a crash ultimately /// just gives them a "something went wrong and a native exception was thrown" which is not /// super helpful. Recovery will at least render something that looks incorrect on the screen. -/// +/// class DirectWriteRenderArgBuilder { public: @@ -39,77 +69,83 @@ class DirectWriteRenderArgBuilder /// /// The font family, by default Segoe UI - /// + /// void SetFontFamily(Windows::UI::Xaml::Media::FontFamily^ fontFamily); /// /// The text to render, empty string by default. - /// + /// void SetText(Platform::String^ text); /// /// The text locale for DWrite, en-US by default. - /// + /// void SetTextLocale(Platform::String^ textLocale); /// /// The foreground brush, Black by default - /// + /// void SetForegroundBrush(Windows::UI::Xaml::Media::Brush^ brush); /// /// The font style, Normal by default - /// + /// void SetFontStyle(Windows::UI::Text::FontStyle fontStyle); /// /// The font stretch, normal by default - /// + /// void SetFontStretch(Windows::UI::Text::FontStretch fontStretch); /// - /// The text orientation, vertical by default since if you're going to use horizontal, you should use a XAML TextBlock - /// - void SetTextOrientation(Windows::UI::Xaml::Controls::Orientation textOrientation); + /// The text reading direction, top to bottom by default + /// + void SetTextReadingDirection(DirectWriteReadingDirection textReadingDirection); /// /// The flow direction, LeftToRight by default - /// + /// void SetFlowDirection(Windows::UI::Xaml::FlowDirection flowDirection); /// /// The font weight, Normal by default - /// + /// void SetFontWeight(Windows::UI::Text::FontWeight fontWeight); /// /// The font size, 15 by default. - /// + /// void SetFontSize(double fontSize); /// /// The DPI to render at, 1 by default - /// + /// void SetDPI(double rawPixelsPerViewPixel); /// /// The available width to render at - /// + /// void SetAvailableWidth(float availableWidth); /// /// The available height to render at. - /// + /// void SetAvailableHeight(float availableHeight); /// /// The text wrap mode, None by default. + /// + void SetTextWrapping(DirectWriteWordWrapping textWrapping); + /// - void SetTextWrapping(Windows::UI::Xaml::TextWrapping textWrapping); + /// The text alignment mode, Leading by default. + /// + void SetTextAlignment(DirectWriteTextAlignment textAlignment); + /// /// The render arguments. - /// + /// DirectWriteTextRenderArgs& BuildRenderArgs(); private: diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock/DirectWriteResourceManager.cpp b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock/DirectWriteResourceManager.cpp index 54b31951e4b..ef9ef04883f 100644 --- a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock/DirectWriteResourceManager.cpp +++ b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock/DirectWriteResourceManager.cpp @@ -1,5 +1,9 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + #include "pch.h" -#include "UniversalWindowsAppPackageFontLoader\FontCollectionLoader.h" +#include "DirectWriteFontCollectionLoader.h" #include "DirectWriteResourceManager.h" BEGIN_NAMESPACE_CONTROLS_WINRT @@ -38,6 +42,12 @@ IDXGIDevice* DirectWriteResourceManager::GetDXGIDeviceNoRef() return m_dxgiDevice.get(); } +HRESULT DirectWriteResourceManager::RebuildDeviceResources() +{ + m_deviceResourcesInitialized = false; + return InitializeDeviceResources(); +} + HRESULT DirectWriteResourceManager::InitializeDeviceResources() { if (!m_deviceResourcesInitialized) @@ -102,7 +112,7 @@ HRESULT DirectWriteResourceManager::InitializeDeviceResources() reinterpret_cast(m_dwriteFactory.put()) )); - auto customLoader = UniversalWindowsAppPackageFontLoader::FontCollectionLoader::GetInstance(); + auto customLoader = DirectWriteFontCollectionLoader::GetInstance(); m_dwriteFactory->RegisterFontCollectionLoader(customLoader.get()); m_deviceResourcesInitialized = true; diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock/DirectWriteResourceManager.h b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock/DirectWriteResourceManager.h index 8281247b8de..1e1cd02ccff 100644 --- a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock/DirectWriteResourceManager.h +++ b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock/DirectWriteResourceManager.h @@ -1,10 +1,14 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + #pragma once BEGIN_NAMESPACE_CONTROLS_WINRT /// /// This manages D3D/DWrite resources and prevents reinitialization. -/// +/// class DirectWriteResourceManager { public: @@ -13,33 +17,38 @@ class DirectWriteResourceManager /// /// This is a singleton to prevent reintializing D3D - /// + /// static DirectWriteResourceManager* GetInstance(); /// /// The DWrite Factory, caller doesn't take a reference. - /// + /// IDWriteFactory* GetDirectWriteFactoryNoRef(); /// /// The D3D Device, caller doesn't take a reference. - /// + /// ID3D11Device* GetD3dDeviceNoRef(); /// /// The D2D Device, caller doesn't take a reference. - /// + /// ID2D1DeviceContext* GetD2dDCNoRef(); /// /// The DXGI Device, caller doesn't take a reference. - /// + /// IDXGIDevice* GetDXGIDeviceNoRef(); /// /// Initializes the device resources. - /// + /// HRESULT InitializeDeviceResources(); + + /// + /// Reinitializes the device resources. + /// + HRESULT RebuildDeviceResources(); private: winrt::com_ptr m_dwriteFactory; diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock/DirectWriteTextBlock.cpp b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock/DirectWriteTextBlock.cpp index 23bc9ba52e3..a42c8944d92 100644 --- a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock/DirectWriteTextBlock.cpp +++ b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock/DirectWriteTextBlock.cpp @@ -1,5 +1,6 @@ -// Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license. -// See LICENSE in the project root for license information. +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. #include "pch.h" #include "DirectWriteTextBlock.h" @@ -33,17 +34,24 @@ DependencyProperty^ DirectWriteTextBlock::m_textLocaleProperty = DependencyPrope DirectWriteTextBlock::typeid, ref new PropertyMetadata(L"en-US", ref new PropertyChangedCallback(&DirectWriteTextBlock::OnDependencyPropertyChanged))); -DependencyProperty^ DirectWriteTextBlock::m_textOrientationProperty = DependencyProperty::Register( - L"TextOrientation", - Windows::UI::Xaml::Controls::Orientation::typeid, +DependencyProperty^ DirectWriteTextBlock::m_textReadingDirectionProperty = DependencyProperty::Register( + L"TextReadingDirection", + DirectWriteReadingDirection::typeid, DirectWriteTextBlock::typeid, - ref new PropertyMetadata(Windows::UI::Xaml::Controls::Orientation::Vertical, ref new PropertyChangedCallback(&DirectWriteTextBlock::OnDependencyPropertyChanged))); + ref new PropertyMetadata(ref new Platform::Box(DirectWriteReadingDirection::TopToBottom), ref new PropertyChangedCallback(&DirectWriteTextBlock::OnDependencyPropertyChanged))); DependencyProperty^ DirectWriteTextBlock::m_textWrapProperty = DependencyProperty::Register( L"TextWrap", - Windows::UI::Xaml::TextWrapping::typeid, + DirectWriteWordWrapping::typeid, DirectWriteTextBlock::typeid, - ref new PropertyMetadata(Windows::UI::Xaml::TextWrapping::NoWrap, ref new PropertyChangedCallback(&DirectWriteTextBlock::OnDependencyPropertyChanged))); + ref new PropertyMetadata(ref new Platform::Box(DirectWriteWordWrapping::NoWrap), ref new PropertyChangedCallback(&DirectWriteTextBlock::OnDependencyPropertyChanged))); + +DependencyProperty^ DirectWriteTextBlock::m_textAlignmentProperty = DependencyProperty::Register( + L"TextAlign", + DirectWriteTextAlignment::typeid, + DirectWriteTextBlock::typeid, + ref new PropertyMetadata(ref new Platform::Box(DirectWriteTextAlignment::Leading), ref new PropertyChangedCallback(&DirectWriteTextBlock::OnDependencyPropertyChanged))); + DirectWriteTextBlock::DirectWriteTextBlock() { @@ -115,8 +123,9 @@ Size DirectWriteTextBlock::MeasureOverride(Size availableSize) builder.SetForegroundBrush(m_textForegroundBrush); builder.SetText(Text); builder.SetTextLocale(TextLocale); - builder.SetTextOrientation(TextOrientation); + builder.SetTextReadingDirection(TextReadingDirection); builder.SetTextWrapping(TextWrap); + builder.SetTextAlignment(TextAlign); auto args = builder.BuildRenderArgs(); UpdateElementsForHighContrast(); @@ -218,12 +227,15 @@ Size DirectWriteTextBlock::RenderText(DirectWriteTextRenderArgs const& args) // Trying to set readingDirection + FlowDirection to LEFT_TO_RIGHT will result in // a failed HRESULT From DWRITE. Since the defaults work fine for horizontal, only // set these values for text orientation = vertical. - if (this->TextOrientation == Orientation::Vertical) + auto textReadingDirection = this->TextReadingDirection; + if (textReadingDirection != DirectWriteReadingDirection::LeftToRight) { textFormat->SetReadingDirection(args.readingDirection); textFormat->SetFlowDirection(args.flowDirection); } + textFormat->SetTextAlignment(args.textAlignment); + winrt::com_ptr textLayout; winrt::check_hresult(dwriteFactory->CreateTextLayout( args.text->Data(), @@ -247,7 +259,8 @@ Size DirectWriteTextBlock::RenderText(DirectWriteTextRenderArgs const& args) winrt::com_ptr surface; RECT updateRect = { 0, 0, static_cast(sisWidth), static_cast(sisHeight) }; POINT offset = { 0, 0 }; - if (SUCCEEDED(sisNative->BeginDraw(updateRect, surface.put(), &offset))) + m_lastDrawError = sisNative->BeginDraw(updateRect, surface.put(), &offset); + if (SUCCEEDED(m_lastDrawError)) { auto d2dContext = resourceManager->GetD2dDCNoRef(); @@ -291,14 +304,32 @@ Size DirectWriteTextBlock::RenderText(DirectWriteTextRenderArgs const& args) brush.get(), D2D1_DRAW_TEXT_OPTIONS_ENABLE_COLOR_FONT); - d2dContext->EndDraw(); + HRESULT d2dEndDrawResult = d2dContext->EndDraw(); sisNative->EndDraw(); - } - m_image->Source = imageSource; + if (d2dEndDrawResult == D2DERR_RECREATE_TARGET) + { + winrt::check_hresult(resourceManager->RebuildDeviceResources()); + } + + m_image->Source = imageSource; + m_drawRetries = 0; - // XAML will rescale, so we divide by scale here. - return Size{ static_cast(sisWidth / scale), static_cast(sisHeight / scale) }; + // XAML will rescale, so we divide by scale here. + return Size{ static_cast(sisWidth / scale), static_cast(sisHeight / scale) }; + } + else if (m_drawRetries == 0) + { + // D2D draw can fail for multiple reasons where rebuilding the D3D device might be necessary. + winrt::check_hresult(resourceManager->RebuildDeviceResources()); + m_drawRetries++; + return RenderText(args); + } + else + { + // if we fail to draw 2x a retry, just bail. + return Size{}; + } } void DirectWriteTextBlock::OnDependencyPropertyChanged(_In_ DependencyObject^ d, _In_ DependencyPropertyChangedEventArgs^ /* e */) diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock/DirectWriteTextBlock.h b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock/DirectWriteTextBlock.h index 793cd46bdcb..aadb55bbf02 100644 --- a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock/DirectWriteTextBlock.h +++ b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock/DirectWriteTextBlock.h @@ -1,5 +1,6 @@ -// Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license. -// See LICENSE in the project root for license information. +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. #pragma once @@ -14,7 +15,7 @@ BEGIN_NAMESPACE_CONTROLS_WINRT { \ type get() \ { \ - return (type)GetValue(membername); \ + return (type)(GetValue(membername)); \ } \ void set(type value) \ { \ @@ -32,6 +33,38 @@ BEGIN_NAMESPACE_CONTROLS_WINRT static Windows::UI::Xaml::DependencyProperty^ membername; \ public: +#define DEFINE_XAML_DEPENDENCY_PROPERTY_VALUE_TYPE(type, name, membername) \ + public: \ + property type name \ + { \ + type get() \ + { \ + auto boxedType = dynamic_cast^>(GetValue(membername)); \ + if (boxedType != nullptr) \ + { \ + return boxedType->Value; \ + } \ + else \ + { \ + return static_cast((int)(GetValue(membername))); \ + } \ + } \ + void set(type value) \ + { \ + SetValue(membername, ref new Platform::Box(value)); \ + } \ + } \ + static property Windows::UI::Xaml::DependencyProperty^ name ## Property \ + { \ + Windows::UI::Xaml::DependencyProperty^ get() \ + { \ + return membername; \ + } \ + } \ + private: \ + static Windows::UI::Xaml::DependencyProperty^ membername; \ + public: + /// /// This is a text block which uses DirectWrite to draw text onto a bitmap image, allowing the user to orient text vertically for /// East Asian languages and to support text rendering modes which aren't supported by XAML yet, but are supported by DirectWrite. @@ -53,10 +86,6 @@ public ref class DirectWriteTextBlock sealed : public Windows::UI::Xaml::Control DirectWriteTextBlock(); virtual ~DirectWriteTextBlock(); - // Note: DWrite actually supports a lot more rendering modes than XAML, but we're able to get most of what we want - // with just the XAML built in types. In the event we need more of the DWrite API surface, we would need - // to define our own enums which map to the DWrite enums. - /// /// The text to render /// @@ -68,14 +97,19 @@ public ref class DirectWriteTextBlock sealed : public Windows::UI::Xaml::Control DEFINE_XAML_DEPENDENCY_PROPERTY(Platform::String^, TextLocale, m_textLocaleProperty); /// - /// The orientation of the text. + /// The reading direction of the text. /// - DEFINE_XAML_DEPENDENCY_PROPERTY(Windows::UI::Xaml::Controls::Orientation, TextOrientation, m_textOrientationProperty); + DEFINE_XAML_DEPENDENCY_PROPERTY_VALUE_TYPE(DirectWriteReadingDirection, TextReadingDirection, m_textReadingDirectionProperty); /// /// How the text is wrapped. To Wrap text, just set the Height or Width of this control. /// - DEFINE_XAML_DEPENDENCY_PROPERTY(Windows::UI::Xaml::TextWrapping, TextWrap, m_textWrapProperty); + DEFINE_XAML_DEPENDENCY_PROPERTY_VALUE_TYPE(DirectWriteWordWrapping, TextWrap, m_textWrapProperty); + + /// + /// The direct write based alignment of the text. This is agnostic of XAML and only supports DirectWrite values. + /// + DEFINE_XAML_DEPENDENCY_PROPERTY_VALUE_TYPE(DirectWriteTextAlignment, TextAlign, m_textAlignmentProperty); protected: // These are the methods we're overriding from IFrameworkElementOverrides. @@ -108,7 +142,9 @@ public ref class DirectWriteTextBlock sealed : public Windows::UI::Xaml::Control Windows::UI::Xaml::Controls::Border^ m_textBackground; Windows::UI::Xaml::Media::Brush^ m_textForegroundBrush; Windows::UI::Xaml::Media::Brush^ m_textBackgroundBrush; - bool m_isHighContrast; + bool m_isHighContrast = false; + HRESULT m_lastDrawError = S_OK; + unsigned int m_drawRetries = 0; }; END_NAMESPACE_CONTROLS_WINRT diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock/DirectWriteUniversalPackageFontData.h b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock/DirectWriteUniversalPackageFontData.h new file mode 100644 index 00000000000..ae48537259d --- /dev/null +++ b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock/DirectWriteUniversalPackageFontData.h @@ -0,0 +1,15 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +#pragma once + +BEGIN_NAMESPACE_CONTROLS_WINRT + +struct DirectWriteUniversalPackageFontData +{ + std::wstring packageFontFilePath; + std::wstring customFontName; +}; + +END_NAMESPACE_CONTROLS_WINRT \ No newline at end of file diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Microsoft.Toolkit.Uwp.UI.Controls.WinRT.vcxproj b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Microsoft.Toolkit.Uwp.UI.Controls.WinRT.vcxproj index b33e6b6661c..2c483bdd491 100644 --- a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Microsoft.Toolkit.Uwp.UI.Controls.WinRT.vcxproj +++ b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Microsoft.Toolkit.Uwp.UI.Controls.WinRT.vcxproj @@ -34,8 +34,8 @@ 14.0 true Windows Store - 10.0.17134.0 - 10.0.17134.0 + 10.0.17763.0 + 10.0.17763.0 10.0 @@ -99,21 +99,33 @@ false + ..\Toolkit.ruleset + false false + ..\Toolkit.ruleset + false false + ..\Toolkit.ruleset + false false + ..\Toolkit.ruleset + false false + ..\Toolkit.ruleset + false false + ..\Toolkit.ruleset + false @@ -125,6 +137,7 @@ /bigobj %(AdditionalOptions) 28204 stdcpplatest + false Console @@ -141,6 +154,7 @@ /bigobj %(AdditionalOptions) 28204 stdcpplatest + false Console @@ -157,6 +171,7 @@ /bigobj %(AdditionalOptions) 28204 stdcpplatest + false Console @@ -173,6 +188,7 @@ /bigobj %(AdditionalOptions) 28204 stdcpplatest + false Console @@ -189,6 +205,7 @@ /bigobj %(AdditionalOptions) 28204 stdcpplatest + false Console @@ -205,6 +222,7 @@ /bigobj %(AdditionalOptions) 28204 stdcpplatest + false Console @@ -216,9 +234,9 @@ - - - + + + @@ -232,8 +250,8 @@ Create Create - - + + diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Microsoft.Toolkit.Uwp.UI.Controls.WinRT.vcxproj.filters b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Microsoft.Toolkit.Uwp.UI.Controls.WinRT.vcxproj.filters index 87acdcaf468..fb0f85196ea 100644 --- a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Microsoft.Toolkit.Uwp.UI.Controls.WinRT.vcxproj.filters +++ b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Microsoft.Toolkit.Uwp.UI.Controls.WinRT.vcxproj.filters @@ -14,12 +14,6 @@ - - UniversalWindowsAppPackageFontLoader - - - UniversalWindowsAppPackageFontLoader - DirectWriteTextBlock @@ -29,18 +23,15 @@ DirectWriteTextBlock + + UniversalWindowsAppPackageFontLoader + + + UniversalWindowsAppPackageFontLoader + - - UniversalWindowsAppPackageFontLoader - - - UniversalWindowsAppPackageFontLoader - - - UniversalWindowsAppPackageFontLoader - DirectWriteTextBlock @@ -50,6 +41,15 @@ DirectWriteTextBlock + + UniversalWindowsAppPackageFontLoader + + + UniversalWindowsAppPackageFontLoader + + + UniversalWindowsAppPackageFontLoader + diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Themes/Generic.xaml b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Themes/Generic.xaml index d64e69275e9..62ab6ad2e85 100644 --- a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Themes/Generic.xaml +++ b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Themes/Generic.xaml @@ -12,16 +12,18 @@ - + + - + + AutomationProperties.Name="{TemplateBinding Text}"> diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/UniversalWindowsAppPackageFontLoader/FontCollectionLoader.cpp b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/UniversalWindowsAppPackageFontLoader/FontCollectionLoader.cpp deleted file mode 100644 index 0e9c8593417..00000000000 --- a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/UniversalWindowsAppPackageFontLoader/FontCollectionLoader.cpp +++ /dev/null @@ -1,107 +0,0 @@ -#include "pch.h" -#include -#include -#include -#include "FontFileEnumerator.h" -#include "FontCollectionLoader.h" - -BEGIN_NAMESPACE_CONTROLS_WINRT - -namespace UniversalWindowsAppPackageFontLoader -{ - winrt::com_ptr FontCollectionLoader::s_comInstance; - - FontCollectionLoader::FontCollectionLoader() - { - } - - FontCollectionLoader::~FontCollectionLoader() - { - } - - bool FontCollectionLoader::HasCustomFontFamily(Platform::String^ xamlFontFamily) - { - // is there a .ttf in the path? - std::wstring wstringPath{ xamlFontFamily->Data() }; - std::transform(wstringPath.begin(), wstringPath.end(), wstringPath.begin(), towlower); - auto foundCustomFontFile = wstringPath.find(L".ttf#", 0); - return foundCustomFontFile != std::wstring::npos; - } - - void FontCollectionLoader::ParseXamlFontFamily(_In_ Platform::String^ xamlFontFamily, _Out_ UniversalPackageFontData& parsedFont) - { - parsedFont = {}; - std::wstring wstringPath{ xamlFontFamily->Data() }; - auto delimLocation = wstringPath.find(L'#'); - if (delimLocation != std::wstring::npos) - { - auto path = wstringPath.substr(0, delimLocation); - std::replace(path.begin(), path.end(), L'/', L'\\'); - parsedFont.packageFontFilePath = path; - parsedFont.customFontName = wstringPath.substr(delimLocation + 1); - } - } - - bool FontCollectionLoader::FindCachedEnumerator(Platform::String^ xamlFontFamily, winrt::com_ptr& enumerator) - { - for (auto& entry : m_fontEnumerators) - { - if (entry.customFont->Equals(xamlFontFamily)) - { - enumerator = entry.enumerator; - return true; - } - } - - return false; - } - - IFACEMETHODIMP FontCollectionLoader::CreateEnumeratorFromKey(_In_ IDWriteFactory* factory, void const* collectionKey, unsigned int collectionKeySize, _Outptr_ IDWriteFontFileEnumerator** fontFileEnumerator) - try - { - *fontFileEnumerator = nullptr; - auto xamlFontFamily = ref new Platform::String(reinterpret_cast(collectionKey), collectionKeySize); - - if (HasCustomFontFamily(xamlFontFamily)) - { - winrt::com_ptr cachedEnumerator; - if (!FindCachedEnumerator(xamlFontFamily, cachedEnumerator)) - { - auto enumerator{ winrt::make_self() }; - UniversalPackageFontData parseData = {}; - ParseXamlFontFamily(xamlFontFamily, parseData); - winrt::check_hresult(enumerator->Initialize(factory, parseData)); - - FontEnumeratorEntry entry = {}; - entry.customFont = xamlFontFamily; - entry.enumerator = enumerator; - m_fontEnumerators.push_back(std::move(entry)); - cachedEnumerator = enumerator; - } - - winrt::check_hresult(cachedEnumerator->QueryInterface(IID_PPV_ARGS(fontFileEnumerator))); - } - else - { - winrt::throw_hresult(E_INVALIDARG); - } - - return S_OK; - } - catch (...) - { - return winrt::to_hresult(); - } - - winrt::com_ptr& FontCollectionLoader::GetInstance() - { - if (!s_comInstance) - { - s_comInstance = winrt::make(); - } - - return s_comInstance; - } -} - -END_NAMESPACE_CONTROLS_WINRT \ No newline at end of file diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/UniversalWindowsAppPackageFontLoader/FontCollectionLoader.h b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/UniversalWindowsAppPackageFontLoader/FontCollectionLoader.h deleted file mode 100644 index 752f20df896..00000000000 --- a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/UniversalWindowsAppPackageFontLoader/FontCollectionLoader.h +++ /dev/null @@ -1,60 +0,0 @@ -#pragma once -#include "UniversalPackageFontData.h" - -BEGIN_NAMESPACE_CONTROLS_WINRT - -namespace UniversalWindowsAppPackageFontLoader -{ - /// - /// This is just to glue together a custom font file in the Universal Windows app package - /// to a custom DWrite Font. All it does is provide an enumerator that returns 1 font (the custom font) - /// and doesn't support things like font fallbacks. - /// - struct FontCollectionLoader : winrt::implements - { - public: - FontCollectionLoader(); - virtual ~FontCollectionLoader(); - - /// - /// Create the enumerator to the Universal Windows Application package. - /// - IFACEMETHOD(CreateEnumeratorFromKey)( - _In_ IDWriteFactory* factory, - void const* collectionKey, // XAML FontFamily Syntax (something.ttf)#font - unsigned int collectionKeySize, - _Outptr_ IDWriteFontFileEnumerator** fontFileEnumerator - ); - - /// - /// This sees if the incoming XAML FontFamily value has something that looks like - /// a custom font file like foo.ttf#bar - /// - static bool HasCustomFontFamily(Platform::String^ xamlFontFamily); - - /// - /// This parses something that looks like /foo/bar.ttf#baz into the ttf path and the font name (baz). - /// - static void ParseXamlFontFamily(Platform::String^ xamlFontFamily, _Out_ UniversalPackageFontData& parsedFont); - - /// - /// Get the singleton loader. - /// - static winrt::com_ptr& GetInstance(); - - private: - struct FontEnumeratorEntry - { - Platform::String^ customFont; - winrt::com_ptr enumerator; - }; - - // enumerators are cached due to memory usages. - bool FindCachedEnumerator(Platform::String^ xamlFontFamily, winrt::com_ptr& enumerator); - - std::vector m_fontEnumerators; - static winrt::com_ptr s_comInstance; - }; -} - -END_NAMESPACE_CONTROLS_WINRT \ No newline at end of file diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/UniversalWindowsAppPackageFontLoader/FontFileEnumerator.cpp b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/UniversalWindowsAppPackageFontLoader/FontFileEnumerator.cpp deleted file mode 100644 index eb7918564b6..00000000000 --- a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/UniversalWindowsAppPackageFontLoader/FontFileEnumerator.cpp +++ /dev/null @@ -1,70 +0,0 @@ -#include "pch.h" -#include "FontFileEnumerator.h" - -BEGIN_NAMESPACE_CONTROLS_WINRT - -namespace UniversalWindowsAppPackageFontLoader -{ - using namespace Windows::Storage; - - FontFileEnumerator::FontFileEnumerator() - { - } - - FontFileEnumerator::~FontFileEnumerator() - { - } - - HRESULT FontFileEnumerator::Initialize(_In_ IDWriteFactory* factory, const UniversalPackageFontData& packageFont) - try - { - if ((factory == nullptr) || packageFont.packageFontFilePath.empty() || packageFont.customFontName.empty()) - { - winrt::throw_hresult(E_INVALIDARG); - } - - m_factory.attach(factory); - m_packageFontArgs = packageFont; - return S_OK; - } - catch (...) - { - return winrt::to_hresult(); - } - - IFACEMETHODIMP FontFileEnumerator::MoveNext(_Out_ BOOL* hasCurrentFile) - try - { - *hasCurrentFile = FALSE; - if (!m_enumerated) - { - m_currentFontFile = nullptr; - auto uwappStorage = Windows::ApplicationModel::Package::Current->InstalledLocation; - std::wstring filePath{ uwappStorage->Path->Data() }; - filePath.append(m_packageFontArgs.packageFontFilePath); - winrt::check_hresult(m_factory->CreateFontFileReference(filePath.c_str(), nullptr, m_currentFontFile.put())); - - *hasCurrentFile = TRUE; - m_enumerated = true; - } - - return S_OK; - } - catch (...) - { - return winrt::to_hresult(); - } - - IFACEMETHODIMP FontFileEnumerator::GetCurrentFontFile(_Outptr_ IDWriteFontFile** fontFile) - try - { - m_currentFontFile.copy_to(fontFile); - return S_OK; - } - catch (...) - { - return winrt::to_hresult(); - } -} - -END_NAMESPACE_CONTROLS_WINRT \ No newline at end of file diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/UniversalWindowsAppPackageFontLoader/FontFileEnumerator.h b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/UniversalWindowsAppPackageFontLoader/FontFileEnumerator.h deleted file mode 100644 index 4597910b7fe..00000000000 --- a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/UniversalWindowsAppPackageFontLoader/FontFileEnumerator.h +++ /dev/null @@ -1,42 +0,0 @@ -#pragma once -#include "UniversalPackageFontData.h" - -BEGIN_NAMESPACE_CONTROLS_WINRT - -namespace UniversalWindowsAppPackageFontLoader -{ - /// - /// This is an enumerator that basically just enumerates 1 custom font into DWrite from the Universal Windows App package. - /// It's extremely simplistic and basically just connects the Universal App Package files to DWrite. - /// - struct FontFileEnumerator : winrt::implements - { - public: - FontFileEnumerator(); - virtual ~FontFileEnumerator(); - - /// - /// This is called consecutively by DWrite until we return FALSE to hasCurrentFile to enumerate the custom - /// font - /// - IFACEMETHOD(MoveNext)(_Out_ BOOL* hasCurrentFile); - - /// - /// This is called by DWrite to get the custom font file. - /// - IFACEMETHOD(GetCurrentFontFile)(_Outptr_ IDWriteFontFile** fontFile); - - /// - /// Initializes the enumerator - /// - HRESULT Initialize(_In_ IDWriteFactory* factory, const UniversalPackageFontData& packageFont); - - private: - winrt::com_ptr m_factory; - winrt::com_ptr m_currentFontFile; - UniversalPackageFontData m_packageFontArgs = {}; - bool m_enumerated = false; - }; -} - -END_NAMESPACE_CONTROLS_WINRT \ No newline at end of file diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/UniversalWindowsAppPackageFontLoader/UniversalPackageFontData.h b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/UniversalWindowsAppPackageFontLoader/UniversalPackageFontData.h deleted file mode 100644 index 04240aaa30b..00000000000 --- a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/UniversalWindowsAppPackageFontLoader/UniversalPackageFontData.h +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once - -BEGIN_NAMESPACE_CONTROLS_WINRT - -namespace UniversalWindowsAppPackageFontLoader -{ - struct UniversalPackageFontData - { - std::wstring packageFontFilePath; - std::wstring customFontName; - }; -} - -END_NAMESPACE_CONTROLS_WINRT \ No newline at end of file diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/pch.cpp b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/pch.cpp index bcb5590be1b..1fc2c700b11 100644 --- a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/pch.cpp +++ b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/pch.cpp @@ -1 +1,5 @@ -#include "pch.h" +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +#include "pch.h" diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/pch.h b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/pch.h index 7c7ca2512d8..1df4bb844b5 100644 --- a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/pch.h +++ b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/pch.h @@ -1,6 +1,13 @@ -#pragma once +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +#pragma once + +// these are c++/winrt default includes : https://docs.microsoft.com/en-us/windows/uwp/cpp-and-winrt-apis/author-coclasses +#include +#include -#include #include #include #include @@ -12,4 +19,6 @@ #define BEGIN_NAMESPACE_CONTROLS_WINRT namespace Microsoft { namespace Toolkit { namespace Uwp { namespace UI { namespace Controls { namespace WinRT { #define END_NAMESPACE_CONTROLS_WINRT } } } } } } -#include "DirectWriteTextBlock\DirectWriteTextBlock.h" \ No newline at end of file +#include "DirectWriteTextBlock\DirectWriteTextBlock.h" + +// it would be nice to run Code Analysis on this project, but the Code Analyzer crashes due to the generated XAML files and apparently can't find pch.h \ No newline at end of file From 824c4b2a051d0446e89bfedf95d8bf32bc4458ae Mon Sep 17 00:00:00 2001 From: "Jun Ma (WINDOWS)" Date: Sun, 21 Oct 2018 17:59:55 +0900 Subject: [PATCH 19/29] fix crash due to DisplayInformation being uncallable from destructor. --- .../DirectWriteTextBlock/DirectWriteTextBlockPage.xaml | 1 + .../DirectWriteTextBlock/DirectWriteTextBlock.cpp | 7 +++---- .../DirectWriteTextBlock/DirectWriteTextBlock.h | 1 + .../Themes/Generic.xaml | 5 +---- 4 files changed, 6 insertions(+), 8 deletions(-) diff --git a/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/DirectWriteTextBlock/DirectWriteTextBlockPage.xaml b/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/DirectWriteTextBlock/DirectWriteTextBlockPage.xaml index e90f2903a0f..20d2538e161 100644 --- a/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/DirectWriteTextBlock/DirectWriteTextBlockPage.xaml +++ b/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/DirectWriteTextBlock/DirectWriteTextBlockPage.xaml @@ -11,6 +11,7 @@ + diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock/DirectWriteTextBlock.cpp b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock/DirectWriteTextBlock.cpp index a42c8944d92..99430227477 100644 --- a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock/DirectWriteTextBlock.cpp +++ b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock/DirectWriteTextBlock.cpp @@ -57,8 +57,8 @@ DirectWriteTextBlock::DirectWriteTextBlock() { DefaultStyleKey = "Microsoft.Toolkit.Uwp.UI.Controls.WinRT.DirectWriteTextBlock"; - auto displayInfo = DisplayInformation::GetForCurrentView(); - m_dpiChangedToken = displayInfo->DpiChanged += ref new TypedEventHandler(this, &DirectWriteTextBlock::OnDpiChanged); + m_displayInfo = DisplayInformation::GetForCurrentView(); + m_dpiChangedToken = m_displayInfo->DpiChanged += ref new TypedEventHandler(this, &DirectWriteTextBlock::OnDpiChanged); m_accessibilitySettings = ref new AccessibilitySettings(); m_highContrastChangedToken = m_accessibilitySettings->HighContrastChanged += ref new TypedEventHandler(this, &DirectWriteTextBlock::OnHighContrastSettingsChanged); @@ -185,8 +185,7 @@ void DirectWriteTextBlock::Close() if (m_dpiChangedToken.Value != 0) { - auto displayInfo = DisplayInformation::GetForCurrentView(); - displayInfo->DpiChanged -= m_dpiChangedToken; + m_displayInfo->DpiChanged -= m_dpiChangedToken; m_dpiChangedToken = {}; } diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock/DirectWriteTextBlock.h b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock/DirectWriteTextBlock.h index aadb55bbf02..0476948e15b 100644 --- a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock/DirectWriteTextBlock.h +++ b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock/DirectWriteTextBlock.h @@ -142,6 +142,7 @@ public ref class DirectWriteTextBlock sealed : public Windows::UI::Xaml::Control Windows::UI::Xaml::Controls::Border^ m_textBackground; Windows::UI::Xaml::Media::Brush^ m_textForegroundBrush; Windows::UI::Xaml::Media::Brush^ m_textBackgroundBrush; + Windows::Graphics::Display::DisplayInformation^ m_displayInfo; bool m_isHighContrast = false; HRESULT m_lastDrawError = S_OK; unsigned int m_drawRetries = 0; diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Themes/Generic.xaml b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Themes/Generic.xaml index 62ab6ad2e85..8469728a44d 100644 --- a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Themes/Generic.xaml +++ b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Themes/Generic.xaml @@ -19,11 +19,8 @@ - + Background="{TemplateBinding Background}"> From cc7e687ca3dda6512a1ca5ce41a7c7362b288f54 Mon Sep 17 00:00:00 2001 From: "Jun Ma (WINDOWS)" Date: Sun, 21 Oct 2018 18:22:24 +0900 Subject: [PATCH 20/29] fix comment tag. --- .../DirectWriteTextBlock/DirectWriteRenderArgBuilder.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock/DirectWriteRenderArgBuilder.h b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock/DirectWriteRenderArgBuilder.h index d79ccf793e6..d9c50eac95a 100644 --- a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock/DirectWriteRenderArgBuilder.h +++ b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock/DirectWriteRenderArgBuilder.h @@ -33,7 +33,7 @@ public enum class DirectWriteWordWrapping : int /// /// These are arguments which are used to render the DWrite string. -/// +/// struct DirectWriteTextRenderArgs { Platform::String^ fontFamily; From cd4796913383423a0091dbd990040b1533676c57 Mon Sep 17 00:00:00 2001 From: "Jun Ma (WINDOWS)" Date: Sun, 21 Oct 2018 18:25:30 +0900 Subject: [PATCH 21/29] add WinRT Control project to build in release. --- Windows Community Toolkit.sln | 1 + 1 file changed, 1 insertion(+) diff --git a/Windows Community Toolkit.sln b/Windows Community Toolkit.sln index d4bb12e3d49..a7b700bc2cf 100644 --- a/Windows Community Toolkit.sln +++ b/Windows Community Toolkit.sln @@ -677,6 +677,7 @@ Global {D4C7AC54-826A-4412-8461-A7C7FD86534B}.Native|x86.ActiveCfg = Release|Win32 {D4C7AC54-826A-4412-8461-A7C7FD86534B}.Native|x86.Build.0 = Release|Win32 {D4C7AC54-826A-4412-8461-A7C7FD86534B}.Release|Any CPU.ActiveCfg = Release|Win32 + {D4C7AC54-826A-4412-8461-A7C7FD86534B}.Release|Any CPU.Build.0 = Release|Win32 {D4C7AC54-826A-4412-8461-A7C7FD86534B}.Release|ARM.ActiveCfg = Release|ARM {D4C7AC54-826A-4412-8461-A7C7FD86534B}.Release|ARM.Build.0 = Release|ARM {D4C7AC54-826A-4412-8461-A7C7FD86534B}.Release|x64.ActiveCfg = Release|x64 From ea1a7f1a4f3dc179e151cc93512a964d471374cf Mon Sep 17 00:00:00 2001 From: "Jun Ma (WINDOWS)" Date: Sat, 10 Nov 2018 13:32:23 +0900 Subject: [PATCH 22/29] remove docs --- docs/controls/DirectWriteTextBlock.md | 53 --------------------------- 1 file changed, 53 deletions(-) delete mode 100644 docs/controls/DirectWriteTextBlock.md diff --git a/docs/controls/DirectWriteTextBlock.md b/docs/controls/DirectWriteTextBlock.md deleted file mode 100644 index 91b35da8f28..00000000000 --- a/docs/controls/DirectWriteTextBlock.md +++ /dev/null @@ -1,53 +0,0 @@ ---- -title: DirectWriteTextBlock -author: juma-msft -description: Defines a textblock which uses [DirectWrite](https://docs.microsoft.com/en-us/windows/desktop/directwrite/direct-write-portal) to render the font so that it can be oriented vertically -keywords: windows 10, uwp, windows community toolkit, uwp community toolkit, uwp toolkit, DockPanel, XAML Control, xaml ---- - -# DirectWriteTextBlock XAML Control - -The [DirectWriteTextBlock Control](https://docs.microsoft.com/dotnet/api/microsoft.toolkit.uwp.ui.controls.winrt.DirectWriteTextBlock) defines a textblock which can render text vertically with limited DirectWrite support. - -Do not use this to render horizontal text unless you need specific support from DirectWrite which isn't currently supported by XAML, it is less efficient than standard [TextBlock](https://docs.microsoft.com/uwp/api/windows.ui.xaml.controls.textblock) overall. - -## Syntax - -```xaml - - - - -``` - -## Sample Output - -## Properties - -| Property | Type | Description | -| -- | -- | -- | -| Text | String | The text to render using DirectWrite | -| TextLocale | String | The bcp-47 text locale tag to pass to DirectWrite, en-US by default | -| TextOrientation | String | The orientation of the text, Vertical by default | -| TextWrap | [Windows.UI.Xaml.TextWrapping](https://docs.microsoft.com/uwp/api/windows.ui.xaml.textwrapping) | How to wrap the text, NoWrap by default | -| FlowDirection | [Windows.UI.Xaml.FlowDirection](https://docs.microsoft.com/uwp/api/windows.ui.xaml.flowdirection) | Inherited from [Windows.UI.Xaml.Controls.Control](https://docs.microsoft.com/uwp/api/windows.ui.xaml.controls.control). the flow direction of the text, LeftToRight by default | -| Foreground | [Windows.UI.Xaml.Media.Brush](https://docs.microsoft.com/en-us/uwp/api/windows.ui.xaml.media.brush) | Inherited from [Windows.UI.Xaml.Controls.Control](https://docs.microsoft.com/uwp/api/windows.ui.xaml.controls.control). The font color of the text to render, this only supports [SolidColorBrush](https://docs.microsoft.com/uwp/api/windows.ui.xaml.media.solidcolorbrush) default is [Windows.UI.Colors.Black](https://docs.microsoft.com/en-us/uwp/api/windows.ui.colors.black#Windows_UI_Colors_Black) . | -| FontSize | double | Inherited from [Windows.UI.Xaml.Controls.Control](https://docs.microsoft.com/uwp/api/windows.ui.xaml.controls.control). The font size of the text to render, 15 by default | -| FontFamily | [Windows.UI.Xaml.Media.FontFamily](https://docs.microsoft.com/uwp/api/windows.ui.xaml.media.fontfamily) | Inherited from [Windows.UI.Xaml.Controls.Control](https://docs.microsoft.com/uwp/api/windows.ui.xaml.controls.control). The font family of the text to render, Segoe UI by default. This supports custom fonts with syntax like /Assets/FontFile.ttf#Font Name | -| FontStretch | [Windows.UI.Text.FontStretch](https://docs.microsoft.com/uwp/api/windows.ui.text.fontstretch) | Inherited from [Windows.UI.Xaml.Controls.Control](https://docs.microsoft.com/uwp/api/windows.ui.xaml.controls.control). The font stretch of the text to render, Normal by default | -| FontStyle | [Windows.UI.Text.FontStyle](https://docs.microsoft.com/uwp/api/windows.ui.text.fontstyle) | Inherited from [Windows.UI.Xaml.Controls.Control](https://docs.microsoft.com/uwp/api/windows.ui.xaml.controls.control). The font stretch of the text to render, Normal by default | -| FontWeight | [Windows.UI.Text.FontWeight](https://docs.microsoft.com/uwp/api/windows.ui.text.fontweight) | Inherited from [Windows.UI.Xaml.Controls.Control](https://docs.microsoft.com/uwp/api/windows.ui.xaml.controls.control). The font stretch of the text to render, Normal by default | - -## Sample Code - -## Requirements - -| Device family | Universal, 10.0.17134.0 or higher | -| -- | -- | -| Namespace | Microsoft.Toolkit.Uwp.UI.Controls.WinRT | -| NuGet package | [Microsoft.Toolkit.Uwp.UI.Controls.WinRT](https://www.nuget.org/packages/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/) | - -## API Source Code - -* [DirectWriteTextBlock source code in C++/WinRT](https://github.com/Microsoft/WindowsCommunityToolkit//tree/master/Microsoft.Toolkit.Uwp.UI.Controls.WinRT) From 02e280e1eb520977443cad8fb2b6410936622e5a Mon Sep 17 00:00:00 2001 From: "Jun Ma (WINDOWS)" Date: Sun, 18 Nov 2018 12:27:40 +0900 Subject: [PATCH 23/29] fix build and nuget package crashing, not sure why projects can't find the template though. --- .../DirectWriteTextBlock/DirectWriteTextBlock.cpp | 7 +++++-- .../Microsoft.Toolkit.Uwp.UI.Controls.WinRT.vcxproj | 12 ++++++++++++ Windows Community Toolkit.sln | 6 ++---- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock/DirectWriteTextBlock.cpp b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock/DirectWriteTextBlock.cpp index 99430227477..299abf7b0c6 100644 --- a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock/DirectWriteTextBlock.cpp +++ b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock/DirectWriteTextBlock.cpp @@ -162,7 +162,10 @@ void DirectWriteTextBlock::UpdateTextBrushesForHighContrast() void DirectWriteTextBlock::UpdateElementsForHighContrast() { - m_textBackground->Background = m_textBackgroundBrush; + if (m_textBackground) + { + m_textBackground->Background = m_textBackgroundBrush; + } } void DirectWriteTextBlock::Close() @@ -200,7 +203,7 @@ void DirectWriteTextBlock::Close() Size DirectWriteTextBlock::RenderText(DirectWriteTextRenderArgs const& args) { - if (args.text->IsEmpty()) + if ((m_image == nullptr) || args.text->IsEmpty()) { return Size(0.0f, 0.0f); } diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Microsoft.Toolkit.Uwp.UI.Controls.WinRT.vcxproj b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Microsoft.Toolkit.Uwp.UI.Controls.WinRT.vcxproj index 6a3d8730cbc..82b0f762ee6 100644 --- a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Microsoft.Toolkit.Uwp.UI.Controls.WinRT.vcxproj +++ b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Microsoft.Toolkit.Uwp.UI.Controls.WinRT.vcxproj @@ -138,6 +138,8 @@ 28204 stdcpplatest true + Level4 + true Console @@ -156,6 +158,8 @@ stdcpplatest true true + Level4 + true Console @@ -173,6 +177,8 @@ 28204 stdcpplatest false + Level4 + true Console @@ -190,6 +196,8 @@ 28204 stdcpplatest true + Level4 + true Console @@ -207,6 +215,8 @@ 28204 stdcpplatest false + Level4 + true Console @@ -224,6 +234,8 @@ 28204 stdcpplatest true + Level4 + true Console diff --git a/Windows Community Toolkit.sln b/Windows Community Toolkit.sln index a7b700bc2cf..7c0afccfa19 100644 --- a/Windows Community Toolkit.sln +++ b/Windows Community Toolkit.sln @@ -661,15 +661,14 @@ Global {D4D78CBA-B238-4794-89A0-4F1A2D8FEA97}.Release|x86.ActiveCfg = Release|Any CPU {D4D78CBA-B238-4794-89A0-4F1A2D8FEA97}.Release|x86.Build.0 = Release|Any CPU {D4C7AC54-826A-4412-8461-A7C7FD86534B}.Debug|Any CPU.ActiveCfg = Debug|Win32 - {D4C7AC54-826A-4412-8461-A7C7FD86534B}.Debug|Any CPU.Build.0 = Debug|Win32 {D4C7AC54-826A-4412-8461-A7C7FD86534B}.Debug|ARM.ActiveCfg = Debug|ARM {D4C7AC54-826A-4412-8461-A7C7FD86534B}.Debug|ARM.Build.0 = Debug|ARM {D4C7AC54-826A-4412-8461-A7C7FD86534B}.Debug|x64.ActiveCfg = Debug|x64 {D4C7AC54-826A-4412-8461-A7C7FD86534B}.Debug|x64.Build.0 = Debug|x64 {D4C7AC54-826A-4412-8461-A7C7FD86534B}.Debug|x86.ActiveCfg = Debug|Win32 {D4C7AC54-826A-4412-8461-A7C7FD86534B}.Debug|x86.Build.0 = Debug|Win32 - {D4C7AC54-826A-4412-8461-A7C7FD86534B}.Native|Any CPU.ActiveCfg = Release|x64 - {D4C7AC54-826A-4412-8461-A7C7FD86534B}.Native|Any CPU.Build.0 = Release|x64 + {D4C7AC54-826A-4412-8461-A7C7FD86534B}.Native|Any CPU.ActiveCfg = Release|Win32 + {D4C7AC54-826A-4412-8461-A7C7FD86534B}.Native|Any CPU.Build.0 = Release|Win32 {D4C7AC54-826A-4412-8461-A7C7FD86534B}.Native|ARM.ActiveCfg = Release|ARM {D4C7AC54-826A-4412-8461-A7C7FD86534B}.Native|ARM.Build.0 = Release|ARM {D4C7AC54-826A-4412-8461-A7C7FD86534B}.Native|x64.ActiveCfg = Release|x64 @@ -677,7 +676,6 @@ Global {D4C7AC54-826A-4412-8461-A7C7FD86534B}.Native|x86.ActiveCfg = Release|Win32 {D4C7AC54-826A-4412-8461-A7C7FD86534B}.Native|x86.Build.0 = Release|Win32 {D4C7AC54-826A-4412-8461-A7C7FD86534B}.Release|Any CPU.ActiveCfg = Release|Win32 - {D4C7AC54-826A-4412-8461-A7C7FD86534B}.Release|Any CPU.Build.0 = Release|Win32 {D4C7AC54-826A-4412-8461-A7C7FD86534B}.Release|ARM.ActiveCfg = Release|ARM {D4C7AC54-826A-4412-8461-A7C7FD86534B}.Release|ARM.Build.0 = Release|ARM {D4C7AC54-826A-4412-8461-A7C7FD86534B}.Release|x64.ActiveCfg = Release|x64 From a12eeceac58be75e653ffabf378637a8055c7866 Mon Sep 17 00:00:00 2001 From: Alexandre Zollinger Chohfi Date: Wed, 23 Jan 2019 16:57:06 -0800 Subject: [PATCH 24/29] Fixed the nuspec and targets files. --- ...soft.Toolkit.Uwp.UI.Controls.WinRT.targets | 9 ++++++- ...osoft.Toolkit.Uwp.UI.Controls.WinRT.nuspec | 26 +++++++++++++++---- 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Microsoft.Toolkit.Uwp.UI.Controls.WinRT.targets b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Microsoft.Toolkit.Uwp.UI.Controls.WinRT.targets index 671d60f6101..0144421e37e 100644 --- a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Microsoft.Toolkit.Uwp.UI.Controls.WinRT.targets +++ b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/Microsoft.Toolkit.Uwp.UI.Controls.WinRT.targets @@ -5,9 +5,16 @@ $(Platform) - + Microsoft.Toolkit.Uwp.UI.Controls.WinRT.dll + + + + + $(MSBuildThisFileDirectory)..\..\Include;%(AdditionalIncludeDirectories) + + \ No newline at end of file diff --git a/build/Microsoft.Toolkit.Uwp.UI.Controls.WinRT.nuspec b/build/Microsoft.Toolkit.Uwp.UI.Controls.WinRT.nuspec index 4ffc73e3597..ec11aee18d8 100644 --- a/build/Microsoft.Toolkit.Uwp.UI.Controls.WinRT.nuspec +++ b/build/Microsoft.Toolkit.Uwp.UI.Controls.WinRT.nuspec @@ -18,22 +18,38 @@ - - + + + + + + + + + + + + + + + - + - + - + + + + From b6f2c3e1551c1b516df9d5a444fd207464f15dc9 Mon Sep 17 00:00:00 2001 From: "Jun Ma (WINDOWS)" Date: Sat, 9 Feb 2019 17:45:05 +0900 Subject: [PATCH 25/29] fix bug where the stack panel would cut off the text on the textblock when DPI is set to 1.25 or a non round DPI. --- .../DirectWriteTextBlockCode.bind | 27 ++++++++++--------- .../DirectWriteTextBlock.cpp | 7 ++--- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/DirectWriteTextBlock/DirectWriteTextBlockCode.bind b/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/DirectWriteTextBlock/DirectWriteTextBlockCode.bind index 0945e9711d9..4a3f86e333f 100644 --- a/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/DirectWriteTextBlock/DirectWriteTextBlockCode.bind +++ b/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/DirectWriteTextBlock/DirectWriteTextBlockCode.bind @@ -8,19 +8,20 @@ - - + + \ No newline at end of file diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock/DirectWriteTextBlock.cpp b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock/DirectWriteTextBlock.cpp index 299abf7b0c6..03da823d147 100644 --- a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock/DirectWriteTextBlock.cpp +++ b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock/DirectWriteTextBlock.cpp @@ -250,8 +250,9 @@ Size DirectWriteTextBlock::RenderText(DirectWriteTextRenderArgs const& args) DWRITE_TEXT_METRICS textMetrics = {}; winrt::check_hresult(textLayout->GetMetrics(&textMetrics)); - auto sisWidth = static_cast(std::ceil(textMetrics.width)); - auto sisHeight = static_cast(std::ceil(textMetrics.height)); + // the image has to be scaled since we're manually handling DPI changes. + auto sisWidth = static_cast(std::ceil(textMetrics.width * scale)); + auto sisHeight = static_cast(std::ceil(textMetrics.height * scale)); auto imageSource = ref new SurfaceImageSource(sisWidth, sisHeight); auto sisUnknown = reinterpret_cast(imageSource); winrt::com_ptr sisNative; @@ -330,7 +331,7 @@ Size DirectWriteTextBlock::RenderText(DirectWriteTextRenderArgs const& args) else { // if we fail to draw 2x a retry, just bail. - return Size{}; + return Size(0.0f, 0.0f); } } From 503ebc56edda2cba15fcdd4407c3492ff2923656 Mon Sep 17 00:00:00 2001 From: "Jun Ma (WINDOWS)" Date: Sat, 9 Feb 2019 19:30:59 +0900 Subject: [PATCH 26/29] fix mistaken merge. --- .../SamplePages/samples.json | 48 +++++++++++++++---- 1 file changed, 39 insertions(+), 9 deletions(-) diff --git a/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/samples.json b/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/samples.json index e0fe3352c3b..70514e96f77 100644 --- a/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/samples.json +++ b/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/samples.json @@ -216,15 +216,17 @@ "Icon": "/SamplePages/OrbitView/OrbitView.png", "DocumentationUrl": "https://raw.githubusercontent.com/MicrosoftDocs/WindowsCommunityToolkitDocs/master/docs/controls/OrbitView.md" }, - { - "Name": "Menu", - "Type": "MenuPage", - "About": "Represents a Windows menu control that enables you to hierarchically organize elements associated with commands and event handlers.", - "CodeUrl": "https://github.com/windows-toolkit/WindowsCommunityToolkit/tree/master/Microsoft.Toolkit.Uwp.UI.Controls/Menu", - "XamlCodeFile": "Menu.bind", - "Icon": "/SamplePages/Menu/Menu.png", - "DocumentationUrl": "https://raw.githubusercontent.com/MicrosoftDocs/WindowsCommunityToolkitDocs/master/docs/controls/Menu.md" - }, + { + "Name": "Menu", + "Type": "MenuPage", + "About": "This control will be removed in a future major release. Please use the MenuBar control from the WinUI Library instead.", + "BadgeUpdateVersionRequired": "DEPRECATED", + "DeprecatedWarning": "This control will be removed in a future major release. Please use the MenuBar control from the WinUI Library instead.", + "CodeUrl": "https://github.com/windows-toolkit/WindowsCommunityToolkit/tree/master/Microsoft.Toolkit.Uwp.UI.Controls/Menu", + "XamlCodeFile": "Menu.bind", + "Icon": "/SamplePages/Menu/Menu.png", + "DocumentationUrl": "https://raw.githubusercontent.com/MicrosoftDocs/WindowsCommunityToolkitDocs/master/docs/controls/Menu.md" + }, { "Name": "InAppNotification", "Type": "InAppNotificationPage", @@ -303,6 +305,25 @@ "BadgeUpdateVersionRequired": "Fall Creators Update required", "DocumentationUrl": "https://raw.githubusercontent.com/MicrosoftDocs/WindowsCommunityToolkitDocs/master/docs/controls/InfiniteCanvas.md" }, + { + "Name": "RemoteDevicePicker", + "Type": "RemoteDevicePickerControlPage", + "About": "Remote Device Picker Control for Project Rome.", + "CodeUrl": "https://github.com/Microsoft/UWPCommunityToolkit/tree/master/Microsoft.Toolkit.Uwp.UI.Controls/RemoteDevicePicker", + "CodeFile": "RemoteDevicePickerCode.bind", + "Icon": "/SamplePages/RemoteDevicePicker/RemoteDevicePicker.png", + "DocumentationUrl": "https://raw.githubusercontent.com/Microsoft/UWPCommunityToolkit/master/docs/controls/RemoteDevicePicker.md", + }, + { + "Name": "ImageCropper", + "Type": "ImageCropperPage", + "About": "ImageCropper control allows user to crop image freely.", + "CodeUrl": "https://github.com/windows-toolkit/WindowsCommunityToolkit/tree/master/Microsoft.Toolkit.Uwp.UI.Controls/ImageCropper", + "XamlCodeFile": "ImageCropperXaml.bind", + "CodeFile": "ImageCropperCode.bind", + "Icon": "/SamplePages/ImageCropper/ImageCropper.png", + "DocumentationUrl": "https://raw.githubusercontent.com/MicrosoftDocs/WindowsCommunityToolkitDocs/master/docs/controls/ImageCropper.md" + }, { "Name": "DirectWriteTextBlock", "Type": "DirectWriteTextBlockPage", @@ -770,6 +791,15 @@ "About": "The ThemeListener allows you to keep track of changes to the System Theme.", "Icon": "/Assets/Helpers.png", "DocumentationUrl": "https://raw.githubusercontent.com/MicrosoftDocs/WindowsCommunityToolkitDocs/master/docs/helpers/ThemeListener.md" + }, + { + "Name": "RemoteDeviceHelper", + "Type": "RemoteDeviceHelperPage", + "About": "Allows you to easily enumerate remote devices ( Project Rome ).", + "CodeUrl": "https://github.com/windows-toolkit/WindowsCommunityToolkit/blob/master/Microsoft.Toolkit.Uwp/Helpers/RemoteDeviceHelper/RemoteDeviceHelper.cs", + "CodeFile": "RemoteDeviceHelperCode.bind", + "Icon": "/SamplePages/RemoteDeviceHelper/RemoteDeviceHelper.png", + "DocumentationUrl": "https://raw.githubusercontent.com/MicrosoftDocs/WindowsCommunityToolkitDocs/master/docs/helpers/RemoteDeviceHelper.md" } ] }, From 0b48539f3d5540610048a2557ac712726427cec7 Mon Sep 17 00:00:00 2001 From: "Jun Ma (WINDOWS)" Date: Tue, 9 Apr 2019 23:08:20 +0900 Subject: [PATCH 27/29] fix assertion when D3D resources need to get refreshed. --- .../DirectWriteTextBlock/DirectWriteResourceManager.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock/DirectWriteResourceManager.cpp b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock/DirectWriteResourceManager.cpp index ef9ef04883f..ec64171b096 100644 --- a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock/DirectWriteResourceManager.cpp +++ b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock/DirectWriteResourceManager.cpp @@ -55,6 +55,10 @@ HRESULT DirectWriteResourceManager::InitializeDeviceResources() UINT creationFlags = D3D11_CREATE_DEVICE_BGRA_SUPPORT; D3D_FEATURE_LEVEL supportedFeatureLevel; + m_d3dDevice = nullptr; + m_d2dDevice = nullptr; + m_dwriteFactory = nullptr; + D3D_FEATURE_LEVEL featureLevels[] = { D3D_FEATURE_LEVEL_11_1, From 0cf811f6b16613c2e3c5adef16e866263d164c75 Mon Sep 17 00:00:00 2001 From: "Jun Ma (WINDOWS)" Date: Tue, 9 Apr 2019 23:09:00 +0900 Subject: [PATCH 28/29] Revert "fix assertion when D3D resources need to get refreshed." This reverts commit 0b48539f3d5540610048a2557ac712726427cec7. --- .../DirectWriteTextBlock/DirectWriteResourceManager.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock/DirectWriteResourceManager.cpp b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock/DirectWriteResourceManager.cpp index ec64171b096..ef9ef04883f 100644 --- a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock/DirectWriteResourceManager.cpp +++ b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock/DirectWriteResourceManager.cpp @@ -55,10 +55,6 @@ HRESULT DirectWriteResourceManager::InitializeDeviceResources() UINT creationFlags = D3D11_CREATE_DEVICE_BGRA_SUPPORT; D3D_FEATURE_LEVEL supportedFeatureLevel; - m_d3dDevice = nullptr; - m_d2dDevice = nullptr; - m_dwriteFactory = nullptr; - D3D_FEATURE_LEVEL featureLevels[] = { D3D_FEATURE_LEVEL_11_1, From f2413c0dc3e645a9aa31356cf4a3c60ff13d9624 Mon Sep 17 00:00:00 2001 From: "Jun Ma (WINDOWS)" Date: Tue, 9 Apr 2019 23:10:22 +0900 Subject: [PATCH 29/29] Revert "Revert "fix assertion when D3D resources need to get refreshed."" This reverts commit 0cf811f6b16613c2e3c5adef16e866263d164c75. --- .../DirectWriteTextBlock/DirectWriteResourceManager.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock/DirectWriteResourceManager.cpp b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock/DirectWriteResourceManager.cpp index ef9ef04883f..ec64171b096 100644 --- a/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock/DirectWriteResourceManager.cpp +++ b/Microsoft.Toolkit.Uwp.UI.Controls.WinRT/DirectWriteTextBlock/DirectWriteResourceManager.cpp @@ -55,6 +55,10 @@ HRESULT DirectWriteResourceManager::InitializeDeviceResources() UINT creationFlags = D3D11_CREATE_DEVICE_BGRA_SUPPORT; D3D_FEATURE_LEVEL supportedFeatureLevel; + m_d3dDevice = nullptr; + m_d2dDevice = nullptr; + m_dwriteFactory = nullptr; + D3D_FEATURE_LEVEL featureLevels[] = { D3D_FEATURE_LEVEL_11_1,