/// <summary> /// Updates the TextFormat and TextLayout. /// </summary> private void UpdateTextFormatAndLayout() { try { if (CurrentTextFormat != null) { CurrentTextFormat.Dispose(); CurrentTextFormat = null; } if (CurrentTextLayout != null) { CurrentTextLayout.Dispose(); CurrentTextLayout = null; } FontText = "SharpDX - This font was loaded from a resource"; // Initialize a TextFormat CurrentTextFormat = new TextFormat(FactoryDWrite, FontFamilyName, CurrentFontCollection, FontWeight.Normal, FontStyle.Normal, FontStretch.Normal, 64); CurrentTextFormat.TextAlignment = TextAlignment.Center; CurrentTextFormat.ParagraphAlignment = ParagraphAlignment.Center; CurrentTextLayout = new TextLayout(FactoryDWrite, FontText, CurrentTextFormat, renderControl.ClientSize.Width, renderControl.ClientSize.Height); } catch (Exception ex) { LogException(ex); } }
/// <summary> /// Clean up any resources being used. /// </summary> /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> protected override void Dispose(bool disposing) { if (disposing) { if (components != null) { components.Dispose(); } if (CurrentTextFormat != null) { CurrentTextFormat.Dispose(); } if (CurrentTextLayout != null) { CurrentTextLayout.Dispose(); } if (CustomTextRenderer != null) { CustomTextRenderer.Dispose(); } if (SceneColorBrush != null) { SceneColorBrush.Dispose(); } if (RenderTarget2D != null) { RenderTarget2D.Dispose(); } if (FactoryDWrite != null) { FactoryDWrite.Dispose(); } if (Factory2D != null) { Factory2D.Dispose(); } } base.Dispose(disposing); }
/// <summary> /// Updates the TextFormat and TextLayout. /// </summary> private void UpdateTextFormatAndLayout() { try { if (CurrentTextFormat != null) { CurrentTextFormat.Dispose(); CurrentTextFormat = null; } if (CurrentTextLayout != null) { CurrentTextLayout.Dispose(); CurrentTextLayout = null; } // Initialize a TextFormat CurrentTextFormat = new TextFormat(FactoryDWrite, FontFamilyName, FontSize) { TextAlignment = TextAlignment.Center, ParagraphAlignment = ParagraphAlignment.Center }; CurrentTextLayout = new TextLayout(FactoryDWrite, FontText, CurrentTextFormat, renderControl.Width, renderControl.Height); // Set a stylistic typography var typo = new Typography(FactoryDWrite); typo.AddFontFeature(new FontFeature(FontFeatureTag.StylisticSet7, 1)); CurrentTextLayout.SetTypography(typo, CurrentTextRange); typo.Dispose(); UpdateBold(); UpdateItalic(); UpdateUnderline(); UpdateFontSize(); } catch (Exception ex) { LogException(ex); } }