Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
79 lines (69 sloc) 3.22 KB
// Copyright (c) 2010-2013 SharpDX - Alexandre Mutel
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
using System.Globalization;
using System.Runtime.InteropServices;
using System.Text;
using SharpDX.DirectWrite;
namespace FontEnumeration
{
/// <summary>
/// Shows how to enumerate the fonts in the system font collection by using DirectWrite
/// Port of DirectWrite sample FontEnumeration on Windows 7 SDK samples
/// http://msdn.microsoft.com/en-us/library/dd756584%28VS.85%29.aspx
/// </summary>
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Press enter to exit");
var factory = new Factory();
var fontCollection = factory.GetSystemFontCollection(false);
var familyCount = fontCollection.FontFamilyCount;
for (int i = 0; i < familyCount; i++)
{
var fontFamily = fontCollection.GetFontFamily(i);
var familyNames = fontFamily.FamilyNames;
int index;
if (!familyNames.FindLocaleName(CultureInfo.CurrentCulture.Name, out index))
familyNames.FindLocaleName("en-us", out index);
string name = familyNames.GetString(index);
Console.WriteLine(name);
var fontCount = fontFamily.FontCount;
for (int fontIndex = 0; fontIndex < fontCount; fontIndex++)
{
var font = fontFamily.GetFont(fontIndex);
var fontFace = new FontFace(font);
var files = fontFace.GetFiles();
foreach (var file in files)
{
var referenceKey = file.GetReferenceKey();
var originalLoader = (FontFileLoaderNative)file.Loader;
var loader = originalLoader.QueryInterface<LocalFontFileLoader>();
var fontFilePath = loader.GetFilePath(referenceKey);
Console.WriteLine("\tFile path: {0}", fontFilePath);
}
}
}
Console.WriteLine("Press enter to exit");
Console.In.ReadLine();
}
}
}