Skip to content

Add a Vertical Text Block to the Windows Community Toolkit #2544

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 46 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
d74dae6
initial commit
Oct 2, 2018
b3be8ff
use CX because XAML won't compile in C++/WinRT projects.
Oct 2, 2018
0f5b748
delete generated files
Oct 2, 2018
64b8534
fixed props issue with Controls.WinRT project and added sample page i…
nmetulev Oct 8, 2018
570bd84
Merge https://github.com/windows-toolkit/WindowsCommunityToolkit into…
nmetulev Oct 8, 2018
4bb8dd5
Merge pull request #1 from windows-toolkit/nmetulev/directwritetextblock
darthwing-duck Oct 9, 2018
cccbacc
fix accessibility.
Oct 9, 2018
e403798
Merge pull request #2 from windows-toolkit/master
darthwing-duck Oct 9, 2018
7552549
fix warning when building x64. Fix target SDK. Use correct Theme brush.
Oct 9, 2018
e2ffbe5
fix build.
Oct 9, 2018
43be56c
Add png
Oct 9, 2018
6a41d01
Fix high contrast XAML TextBlock emulation. Basically add a backgroun…
Oct 10, 2018
581978c
use super::MeasureOverride instead of calling Measure on individual c…
Oct 10, 2018
f44871c
delete mistake folder
Oct 10, 2018
89b6df3
fix thumbnail
Oct 10, 2018
4289b53
update headers
Oct 10, 2018
28d8540
Merge branch 'master' into master
nmetulev Oct 11, 2018
8af897e
setting up nuspec build
nmetulev Oct 11, 2018
f5227b5
added nuspec file
nmetulev Oct 11, 2018
78558f6
Merge https://github.com/juma-msft/WindowsCommunityToolkit into nmetu…
nmetulev Oct 11, 2018
68b0928
including themes.xaml in nuspec
nmetulev Oct 11, 2018
f7efd9e
added nuget targets file
nmetulev Oct 11, 2018
db6d408
Fix some feedback:
Oct 14, 2018
0f52603
Merge branch 'master' of https://github.com/juma-msft/WindowsCommunit…
Oct 14, 2018
3b388fc
fixed merge conflict
nmetulev Oct 15, 2018
824c4b2
fix crash due to DisplayInformation being uncallable from destructor.
Oct 21, 2018
c34925c
Merge pull request #3 from windows-toolkit/nmetulev/directwritetextblock
darthwing-duck Oct 21, 2018
cc7e687
fix comment tag.
Oct 21, 2018
cd47969
add WinRT Control project to build in release.
Oct 21, 2018
a0c3fec
Merge branch 'master' into master
nmetulev Oct 21, 2018
9d3e34b
Merge branch 'master' into master
azchohfi Nov 9, 2018
ea1a7f1
remove docs
Nov 10, 2018
fa324c6
Merge branch 'master' of https://github.com/juma-msft/WindowsCommunit…
Nov 10, 2018
02e280e
fix build and nuget package crashing, not sure why projects can't fin…
Nov 18, 2018
a09085f
Merge branch 'master' into master
azchohfi Jan 23, 2019
a12eece
Fixed the nuspec and targets files.
azchohfi Jan 24, 2019
b6f2c3e
fix bug where the stack panel would cut off the text on the textblock…
Feb 9, 2019
81e888a
pull everything into my fork.
Feb 9, 2019
9149c7c
Merge pull request #5 from juma-msft/windows-toolkit-master
darthwing-duck Feb 9, 2019
503ebc5
fix mistaken merge.
Feb 9, 2019
3e96f5b
Merge branch 'master' of https://github.com/windows-toolkit/WindowsCo…
Apr 9, 2019
eba572a
Merge branch 'windows-toolkit-master'
Apr 9, 2019
0b48539
fix assertion when D3D resources need to get refreshed.
Apr 9, 2019
0cf811f
Revert "fix assertion when D3D resources need to get refreshed."
Apr 9, 2019
a14d14e
Merge branch 'master' of https://github.com/juma-msft/WindowsCommunit…
Apr 9, 2019
f2413c0
Revert "Revert "fix assertion when D3D resources need to get refreshe…
Apr 9, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ build/
bld/
[Bb]in/
[Oo]bj/
Generated Files/

# Visual Studio 2015 cache/options directory
.vs/
Expand Down
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
<PackageReference Include="StyleCop.Analyzers" Version="1.0.2" PrivateAssets="all" />

<EmbeddedResource Include="**\*.rd.xml" />
<Page Include="**\*.xaml" Exclude="**\bin\**\*.xaml;**\obj\**\*.xaml" SubType="Designer" Generator="MSBuild:Compile" />
<Page Include="**\*.xaml" Exclude="**\bin\**\*.xaml;**\obj\**\*.xaml;**\Generated Files\**\*.xaml" SubType="Designer" Generator="MSBuild:Compile" />
<Compile Update="**\*.xaml.cs" DependentUpon="%(Filename)" />
</ItemGroup>
<PropertyGroup Condition="'$(Configuration)' == 'Release'">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@
<Content Include="Icons\More.png" />
<Content Include="Icons\Notifications.png" />
<Content Include="Icons\Services.png" />
<Content Include="SamplePages\DirectWriteTextBlock\DirectWriteTextBlock.png" />
<Content Include="SamplePages\OnDevice\OnDevice.png" />
<Content Include="SamplePages\RemoteDeviceHelper\RemoteDeviceHelper.png" />
<Content Include="SamplePages\ImageCropper\ImageCropper.png" />
Expand Down Expand Up @@ -524,6 +525,7 @@
<Content Include="SamplePages\RemoteDevicePicker\RemoteDevicePickerCode.bind" />
<Content Include="SamplePages\PlannerTaskList\PlannerTaskListXaml.bind" />
<Content Include="SamplePages\DataGrid\DataGridCode.bind" />
<Content Include="SamplePages\DirectWriteTextBlock\DirectWriteTextBlockCode.bind" />
<Content Include="SamplePages\TabView\TabViewXaml.bind">
<SubType>Designer</SubType>
</Content>
Expand Down Expand Up @@ -580,6 +582,9 @@
<Compile Include="Models\LandingPageResource.cs" />
<Compile Include="Models\LandingPageLink.cs" />
<Compile Include="Models\PaneState.cs" />
<Compile Include="SamplePages\DirectWriteTextBlock\DirectWriteTextBlockPage.xaml.cs">
<DependentUpon>DirectWriteTextBlockPage.xaml</DependentUpon>
</Compile>
<Compile Include="SamplePages\TabView\TabViewPage.xaml.cs">
<DependentUpon>TabViewPage.xaml</DependentUpon>
</Compile>
Expand Down Expand Up @@ -956,6 +961,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="SamplePages\DirectWriteTextBlock\DirectWriteTextBlockPage.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="SamplePages\OnDevice\OnDevicePage.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
Expand Down Expand Up @@ -1437,6 +1446,10 @@
<Project>{d4d78cba-b238-4794-89a0-4f1a2d8fea97}</Project>
<Name>Microsoft.Toolkit.Uwp.UI.Controls.Graph</Name>
</ProjectReference>
<ProjectReference Include="..\Microsoft.Toolkit.Uwp.UI.Controls.WinRT\Microsoft.Toolkit.Uwp.UI.Controls.WinRT.vcxproj">
<Project>{d4c7ac54-826a-4412-8461-a7c7fd86534b}</Project>
<Name>Microsoft.Toolkit.Uwp.UI.Controls.WinRT</Name>
</ProjectReference>
<ProjectReference Include="..\Microsoft.Toolkit.Uwp.UI.Controls\Microsoft.Toolkit.Uwp.UI.Controls.csproj">
<Project>{e9faabfb-d726-42c1-83c1-cb46a29fea81}</Project>
<Name>Microsoft.Toolkit.Uwp.UI.Controls</Name>
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<Page
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:controls="using:Microsoft.Toolkit.Uwp.UI.Controls.WinRT"
mc:Ignorable="d">

<Grid>
<StackPanel>
<TextBlock
Text="This is a standard XAML Textblock for comparison."
FontFamily="@[FontFamily:String:Segoe UI]"
FontWeight="@[FontWeight:String:Normal]"
FontStyle="@[FontStyle:Enum:FontStyle.Normal]"
FontStretch="@[FontStretch:Enum:FontStretch.Normal]"
FontSize="@[FontSize:Slider:15:1-100]" />
<controls:DirectWriteTextBlock
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]"
FontSize="@[FontSize:Slider:15:1-100]" />
</StackPanel>
</Grid>
</Page>
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<Page
x:Class="Microsoft.Toolkit.Uwp.SampleApp.SamplePages.DirectWriteTextBlockPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Microsoft.Toolkit.Uwp.SampleApp.SamplePages"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:controls="using:Microsoft.Toolkit.Uwp.UI.Controls.WinRT"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">

<Grid>
<StackPanel>
<!-- Need a custom Design project in order to get my custom enums into the .bind file.-->
<TextBlock Text="This is a standard XAML Textblock for comparison."/>
<controls:DirectWriteTextBlock />
</StackPanel>
</Grid>
</Page>
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// 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;
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;

namespace Microsoft.Toolkit.Uwp.SampleApp.SamplePages
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class DirectWriteTextBlockPage : Page
{
public DirectWriteTextBlockPage()
{
this.InitializeComponent();
}
}
}
11 changes: 11 additions & 0 deletions Microsoft.Toolkit.Uwp.SampleApp/SamplePages/samples.json
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,17 @@
"XamlCodeFile": "FocusTrackerXaml.bind",
"Icon": "/SamplePages/FocusTracker/FocusTracker.png",
"DocumentationUrl": "https://raw.githubusercontent.com/MicrosoftDocs/WindowsCommunityToolkitDocs/master/docs/developer-tools/FocusTracker.md"
},
{
"Name": "DirectWriteTextBlock",
"Type": "DirectWriteTextBlockPage",
"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",
"ApiCheck": "Windows.UI.Xaml.Controls.ColorPicker",
"BadgeUpdateVersionRequired": "April 2018 Update required",
"DocumentationUrl": "https://raw.githubusercontent.com/MicrosoftDocs/WindowsCommunityToolkitDocs/master/docs/controls/DirectWriteTextBlock.md"
}
]
},
Expand Down
Original file line number Diff line number Diff line change
@@ -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 <string>
#include <sstream>
#include <iostream>
#include "DirectWriteFontFileEnumerator.h"
#include "DirectWriteFontCollectionLoader.h"

BEGIN_NAMESPACE_CONTROLS_WINRT

winrt::com_ptr<IDWriteFontCollectionLoader> 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<IDWriteFontFileEnumerator>& 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<const wchar_t*>(collectionKey), collectionKeySize);

if (HasCustomFontFamily(xamlFontFamily))
{
winrt::com_ptr<IDWriteFontFileEnumerator> cachedEnumerator;
if (!FindCachedEnumerator(xamlFontFamily, cachedEnumerator))
{
auto enumerator{ winrt::make_self<DirectWriteFontFileEnumerator>() };
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<IDWriteFontCollectionLoader>& DirectWriteFontCollectionLoader::GetInstance()
{
if (!s_comInstance)
{
s_comInstance = winrt::make<DirectWriteFontCollectionLoader>();
}

return s_comInstance;
}

END_NAMESPACE_CONTROLS_WINRT
Original file line number Diff line number Diff line change
@@ -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

/// <summary>
/// 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.
/// </summary>
struct DirectWriteFontCollectionLoader : winrt::implements<DirectWriteFontCollectionLoader, IDWriteFontCollectionLoader>
{
public:
DirectWriteFontCollectionLoader();
virtual ~DirectWriteFontCollectionLoader();

/// <summary>
/// Create the enumerator to the Universal Windows Application package.
/// </summary>
IFACEMETHOD(CreateEnumeratorFromKey)(
_In_ IDWriteFactory* factory,
void const* collectionKey, // XAML FontFamily Syntax (something.ttf)#font
unsigned int collectionKeySize,
_Outptr_ IDWriteFontFileEnumerator** fontFileEnumerator
);

/// <summary>
/// This sees if the incoming XAML FontFamily value has something that looks like
/// a custom font file like foo.ttf#bar
/// </summary>
static bool HasCustomFontFamily(Platform::String^ xamlFontFamily);

/// <summary>
/// This parses something that looks like /foo/bar.ttf#baz into the ttf path and the font name (baz).
/// </summary>
static void ParseXamlFontFamily(Platform::String^ xamlFontFamily, _Out_ DirectWriteUniversalPackageFontData& parsedFont);

/// <summary>
/// Get the singleton loader.
/// </summary>
static winrt::com_ptr<IDWriteFontCollectionLoader>& GetInstance();

private:
struct FontEnumeratorEntry
{
Platform::String^ customFont;
winrt::com_ptr<IDWriteFontFileEnumerator> enumerator;
};

// enumerators are cached due to memory usages.
bool FindCachedEnumerator(Platform::String^ xamlFontFamily, winrt::com_ptr<IDWriteFontFileEnumerator>& enumerator);

std::vector<FontEnumeratorEntry> m_fontEnumerators;
static winrt::com_ptr<IDWriteFontCollectionLoader> s_comInstance;
};

END_NAMESPACE_CONTROLS_WINRT
Loading