-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge commit 'ab1340cfb605c8025160a7119e3978e3137ce281'
- Loading branch information
Showing
7 changed files
with
191 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<Application x:Class="HekeherwhiLewherjaroche.App" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:local="clr-namespace:HekeherwhiLewherjaroche" | ||
StartupUri="MainWindow.xaml"> | ||
<Application.Resources> | ||
|
||
</Application.Resources> | ||
</Application> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using System.Configuration; | ||
using System.Data; | ||
using System.Windows; | ||
|
||
namespace HekeherwhiLewherjaroche; | ||
|
||
/// <summary> | ||
/// Interaction logic for App.xaml | ||
/// </summary> | ||
public partial class App : Application | ||
{ | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using System.Windows; | ||
|
||
[assembly:ThemeInfo( | ||
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located | ||
//(used if a resource is not found in the page, | ||
// or application resource dictionaries) | ||
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located | ||
//(used if a resource is not found in the page, | ||
// app, or any theme specific resource dictionaries) | ||
)] |
21 changes: 21 additions & 0 deletions
21
DirectX/DWrite/HekeherwhiLewherjaroche/HekeherwhiLewherjaroche.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>WinExe</OutputType> | ||
<TargetFramework>net9.0-windows</TargetFramework> | ||
<Nullable>enable</Nullable> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<UseWPF>true</UseWPF> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<Compile Include="..\..\..\..\..\..\Library\Reference\DWrite.cs" Link="DWrite.cs" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<None Include="..\..\..\..\..\..\Library\DWriteCore.dll" Link="DWriteCore.dll"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</None> | ||
</ItemGroup> | ||
|
||
</Project> |
22 changes: 22 additions & 0 deletions
22
DirectX/DWrite/HekeherwhiLewherjaroche/HekeherwhiLewherjaroche.sln
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Version 17 | ||
VisualStudioVersion = 17.0.31903.59 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HekeherwhiLewherjaroche", "HekeherwhiLewherjaroche.csproj", "{A1713804-C779-4A44-AFB9-40D092E8E081}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{A1713804-C779-4A44-AFB9-40D092E8E081}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{A1713804-C779-4A44-AFB9-40D092E8E081}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{A1713804-C779-4A44-AFB9-40D092E8E081}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{A1713804-C779-4A44-AFB9-40D092E8E081}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
EndGlobal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<Window x:Class="HekeherwhiLewherjaroche.MainWindow" | ||
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:local="clr-namespace:HekeherwhiLewherjaroche" | ||
mc:Ignorable="d" | ||
Title="MainWindow" Height="450" Width="800"> | ||
<Grid> | ||
<Button Content="点击" Click="Button_OnClick"></Button> | ||
</Grid> | ||
</Window> |
104 changes: 104 additions & 0 deletions
104
DirectX/DWrite/HekeherwhiLewherjaroche/MainWindow.xaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
using System.Runtime.InteropServices; | ||
using System.Text; | ||
using System.Windows; | ||
using System.Windows.Controls; | ||
using System.Windows.Data; | ||
using System.Windows.Documents; | ||
using System.Windows.Input; | ||
using System.Windows.Media; | ||
using System.Windows.Media.Imaging; | ||
using System.Windows.Navigation; | ||
using System.Windows.Shapes; | ||
|
||
using DWrite; | ||
|
||
|
||
namespace HekeherwhiLewherjaroche; | ||
|
||
// https://learn.microsoft.com/en-us/answers/questions/574926/how-do-i-access-dwritecore-from-a-c-managed-applic | ||
|
||
/// <summary> | ||
/// Interaction logic for MainWindow.xaml | ||
/// </summary> | ||
public partial class MainWindow : Window | ||
{ | ||
public MainWindow() | ||
{ | ||
InitializeComponent(); | ||
|
||
Loaded += MainWindow_Loaded; | ||
} | ||
|
||
private void MainWindow_Loaded(object sender, RoutedEventArgs e) | ||
{ | ||
IDWriteFactory dwriteFactory = null; | ||
IDWriteFactory7 dwriteFactory7 = null; | ||
|
||
Guid CLSID_DWriteFactory = new Guid("B859EE5A-D838-4B5B-A2E8-1ADC7D93DB48"); | ||
Guid CLSID_DWriteFactory7 = new Guid("35D0E0B3-9076-4D2E-A016-A91B568A06B4"); | ||
|
||
IntPtr pDWriteFactoryPtr = IntPtr.Zero; | ||
// HRESULT hr = DWriteCoreCreateFactory(DWRITE_FACTORY_TYPE.DWRITE_FACTORY_TYPE_SHARED, ref CLSID_DWriteFactory, out pDWriteFactoryPtr); | ||
HRESULT hr = DWriteCoreCreateFactory(DWRITE_FACTORY_TYPE.DWRITE_FACTORY_TYPE_SHARED, ref CLSID_DWriteFactory7, out pDWriteFactoryPtr); | ||
if (hr == HRESULT.S_OK) | ||
{ | ||
// m_pDWriteFactory = Marshal.GetObjectForIUnknown(pDWriteFactoryPtr) as IDWriteFactory; | ||
dwriteFactory7 = Marshal.GetObjectForIUnknown(pDWriteFactoryPtr) as IDWriteFactory7; | ||
//IDWriteFontCollection pFontCollection; | ||
//hr = m_pDWriteFactory.GetSystemFontCollection(out pFontCollection); | ||
IDWriteFontCollection3 pFontCollection; | ||
hr = dwriteFactory7.GetSystemFontCollection7(false, DWRITE_FONT_FAMILY_MODEL.DWRITE_FONT_FAMILY_MODEL_TYPOGRAPHIC, out pFontCollection); | ||
if (hr == HRESULT.S_OK) | ||
{ | ||
uint nFamilyCount = pFontCollection.GetFontFamilyCount(); | ||
for (uint i = 0; i < nFamilyCount; i++) | ||
{ | ||
IDWriteFontFamily pFontFamily; | ||
hr = pFontCollection.GetFontFamily(i, out pFontFamily); | ||
IDWriteLocalizedStrings pFamilyNames; | ||
pFontFamily.GetFamilyNames(out pFamilyNames); | ||
|
||
uint nIndex = 0; | ||
bool bExists = false; | ||
StringBuilder sbLocaleName = new StringBuilder(LOCALE_NAME_MAX_LENGTH); | ||
int nDefaultLocaleSuccess = GetUserDefaultLocaleName(sbLocaleName, LOCALE_NAME_MAX_LENGTH); | ||
if (nDefaultLocaleSuccess > 0) | ||
{ | ||
hr = pFamilyNames.FindLocaleName(sbLocaleName.ToString(), out nIndex, out bExists); | ||
} | ||
if (hr == HRESULT.S_OK && !bExists) | ||
{ | ||
hr = pFamilyNames.FindLocaleName("en-us", out nIndex, out bExists); | ||
} | ||
if (!bExists) | ||
nIndex = 0; | ||
hr = pFamilyNames.GetString(nIndex, sbLocaleName, LOCALE_NAME_MAX_LENGTH); | ||
string sName = sbLocaleName.ToString(); | ||
|
||
System.Diagnostics.Debug.WriteLine("Font : " + sName); | ||
|
||
Marshal.ReleaseComObject(pFamilyNames); | ||
Marshal.ReleaseComObject(pFontFamily); | ||
} | ||
Marshal.ReleaseComObject(pFontCollection); | ||
} | ||
Marshal.ReleaseComObject(dwriteFactory7); | ||
} | ||
} | ||
|
||
private void Button_OnClick(object sender, RoutedEventArgs e) | ||
{ | ||
|
||
} | ||
|
||
// As I could not get DWriteCore.dll from Microsoft.WindowAppSDK.DWrite package when I tested, | ||
// I got it from https://github.com/microsoft/WindowsAppSDK-Samples/tree/main/Samples/TextRendering | ||
// then it must be copied in executable directory | ||
[DllImport("DWriteCore.dll", SetLastError = true, CharSet = CharSet.Auto)] | ||
public static extern HRESULT DWriteCoreCreateFactory(DWRITE_FACTORY_TYPE factoryType, ref Guid iid, out IntPtr factory); | ||
|
||
[DllImport("Kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode)] | ||
public static extern int GetUserDefaultLocaleName(StringBuilder lpLocaleName, int cchLocaleName); | ||
|
||
public const int LOCALE_NAME_MAX_LENGTH = 85; | ||
} |