public void Initialize(Presenter presenter) { // https://msdn.microsoft.com/en-us/library/windows/desktop/mt186590(v=vs.85).aspx Presenter = presenter; Device3D11 = Device3D11.CreateFromDirect3D12( Device.NativeDevice, DeviceCreationFlags.BgraSupport,// | DeviceCreationFlags.Debug, null, null, presenter.NativeCommandQueue); DeviceContext3D = Device3D11.ImmediateContext; Device3D = Device3D11.QueryInterface <Device3D>(); // create d2d/directwrite using (var factory = new Factory(FactoryType.SingleThreaded)) { Factory = factory.QueryInterface <Factory1>(); } RoundedRectangleGeometry = new RoundedRectangleGeometry( Factory, new RoundedRectangle() { RadiusX = 32, RadiusY = 32, Rect = new RectangleF(128, 128, 500 - 128 * 2, 500 - 128 * 2) }); // direct write FactoryDW = new FactoryDW(SharpDX.DirectWrite.FactoryType.Shared); FontLoader = new ResourceFontLoader(FactoryDW, @"Fonts"); FontCollection = new FontCollection(FactoryDW, FontLoader, FontLoader.Key); TextFormat = new TextFormat( FactoryDW, "Material-Design-Iconic-Font", FontCollection, SharpDX.DirectWrite.FontWeight.Normal, FontStyle.Normal, FontStretch.Normal, 30); TextFormat.TextAlignment = TextAlignment.Leading; TextFormat.ParagraphAlignment = ParagraphAlignment.Near; DeviceContextOptions deviceOptions = DeviceContextOptions.None; using (var deviceGI = Device3D.QueryInterface <DeviceGI>()) { Device2D = new Device(Factory, deviceGI); DeviceContext = new DeviceContext(Device2D, deviceOptions); } DesktopDpi = Factory.DesktopDpi; InitializePresentable(Device); }
public GraphicsDeviceContext2D(DeviceContext deviceContext) { // initialize directwrite DirectWriteFactory = new DirectWriteFactory(SharpDX.DirectWrite.FactoryType.Shared); FontLoader = new ResourceFontLoader(DirectWriteFactory, @"Fonts"); FontCollection = new FontCollection(DirectWriteFactory, FontLoader, FontLoader.Key); this.deviceContext = deviceContext; // load font collection SolidColorBrush = new SolidColorBrush(DeviceContext, new Color4()); }
async Task LoadCustomFonts() { await Task.Run(() => { // Font Families FontFamilyNames = new List <string> { "Aileron", "Grundschrift" }; // Character codes to check for: int[] codes = { 0x41, 0x6f, 0x7c, 0xc2aa, 0xD7A3 }; FactoryDWrite = new SharpDX.DirectWrite.Factory(); CurrentResourceFontLoader = new ResourceFontLoader(FactoryDWrite, customFontStreams); CurrentFontCollection = new FontCollection(FactoryDWrite, CurrentResourceFontLoader, CurrentResourceFontLoader.Key); foreach (var fontfamilyname in FontFamilyNames) { int familyIndex; CurrentFontCollection.FindFamilyName(fontfamilyname, out familyIndex); using (var fontFamily = CurrentFontCollection.GetFontFamily(familyIndex)) { var font = fontFamily.GetFont(0); using (var fontface = new FontFace(font)) { var results = fontface.GetGlyphIndices(codes); for (int i = 0; i < codes.Length - 1; i++) { if (results[i] > 0) { Debug.WriteLine("Contains the unicode character " + codes[i]); } else { Debug.WriteLine("Does not contain the unicode character " + codes[i]); } } } } } }); }
/// <summary> /// Initializes the fonts. /// </summary> private void InitFonts() { _fontLoader = new ResourceFontLoader(_dwFactory); _fontCollection = new FontCollection(_dwFactory, _fontLoader, _fontLoader.Key); }