protected override void OnCreateDeviceIndependentResources(Direct2DFactory factory) { base.OnCreateDeviceIndependentResources(factory); this._textFormat = DirectWriteFactory.CreateTextFormat("Gabriola", 72); this._textFormat.TextAlignment = TextAlignment.Center; this._textFormat.ParagraphAlignment = ParagraphAlignment.Center; float width = ClientSize.Width / _dpiScaleX; float height = ClientSize.Height / _dpiScaleY; this._textLayout = DirectWriteFactory.CreateTextLayout( _text, this._textFormat, width, height); this._textLayout.SetFontSize(100, new TextRange(20, 6)); this._textLayout.SetUnderline(true, new TextRange(20, 11)); this._textLayout.SetFontWeight(FontWeight.Bold, new TextRange(20, 11)); using (Typography typography = DirectWriteFactory.CreateTypography()) { typography.AddFontFeature(FontFeatureTag.StylisticSet7, 1); this._textLayout.SetTypography(typography, new TextRange(0, _text.Length)); } }
/// <summary> /// Inits the font family names from DirectWrite /// </summary> private void InitTextFormatLayout() { FontFamilyName = "Gabriola"; FontSize = 72; FontText = "Client Drawing Effect Example!"; // Initialize a TextFormat CurrentTextFormat = new TextFormat(FactoryDWrite, FontFamilyName, FontSize) { TextAlignment = TextAlignment.Center, ParagraphAlignment = ParagraphAlignment.Center }; CurrentTextLayout = new TextLayout(FactoryDWrite, FontText, CurrentTextFormat, ClientRectangle.Width, ClientRectangle.Height); RedDrawingeffect = new ColorDrawingEffect(new Color4(1, 1, 0, 0)); BlueDrawingEffect = new ColorDrawingEffect(new Color4(1, 0, 0, 1)); GreenDrawingEffect = new ColorDrawingEffect(new Color4(1, 0, 1, 0)); CurrentTextLayout.SetDrawingEffect(RedDrawingeffect, new TextRange(0, 14)); CurrentTextLayout.SetDrawingEffect(BlueDrawingEffect, new TextRange(14, 7)); CurrentTextLayout.SetDrawingEffect(GreenDrawingEffect, new TextRange(21, 8)); // Set a stylistic typography var typo = new Typography(FactoryDWrite); typo.AddFontFeature(new FontFeature(FontFeatureTag.StylisticSet7, 1)); CurrentTextLayout.SetTypography(typo, CurrentTextRange); typo.Release(); }
/// <summary> /// Inits the font family names from DirectWrite /// </summary> private void InitTextFormatLayout() { FontFamilyName = "Gabriola"; FontSize = 72; FontText = "Client Drawing Effect Example!"; // Initialize a TextFormat CurrentTextFormat = new TextFormat(FactoryDWrite, FontFamilyName, FontSize); CurrentTextFormat.TextAlignment = TextAlignment.Center; CurrentTextFormat.ParagraphAlignment = ParagraphAlignment.Center; CurrentTextLayout = new TextLayout(FactoryDWrite, FontText, CurrentTextFormat, ClientRectangle.Width, ClientRectangle.Height); RedDrawingeffect = new ColorDrawingEffect(Color.Red); BlueDrawingEffect = new ColorDrawingEffect(Color.Blue); GreenDrawingEffect = new ColorDrawingEffect(Color.Green); CurrentTextLayout.SetDrawingEffect(RedDrawingeffect, new TextRange(0, 14)); CurrentTextLayout.SetDrawingEffect(BlueDrawingEffect, new TextRange(14, 7)); CurrentTextLayout.SetDrawingEffect(GreenDrawingEffect, new TextRange(21, 8)); CurrentTextLayout.SetUnderline(true, new TextRange(0, 20)); CurrentTextLayout.SetStrikethrough(true, new TextRange(22, 7)); // Set a stylistic typography using (var typo = new Typography(FactoryDWrite)) { typo.AddFontFeature(new FontFeature(FontFeatureTag.StylisticSet7, 1)); CurrentTextLayout.SetTypography(typo, CurrentTextRange); } }
protected override void OnCreateDeviceResources(WindowRenderTarget renderTarget) { base.OnCreateDeviceResources(renderTarget); float width = ClientSize.Width / _dpiScaleX; float height = ClientSize.Height / _dpiScaleY; this._textLayout = DirectWriteFactory.CreateTextLayout( _text, this._textFormat, width, height); using (Typography typography = DirectWriteFactory.CreateTypography()) { typography.AddFontFeature(FontFeatureTag.StylisticSet7, 1); this._textLayout.SetTypography(typography, new TextRange(0, _text.Length)); } Bitmap bitmap = RenderTarget.CreateBitmap(this.GetType(), "heart.png"); this._bitmapInlineObject = new BitmapInlineObject(RenderTarget, bitmap); this._textLayout.SetInlineObject(this._bitmapInlineObject, new TextRange(2, 1)); this._blackBrush = renderTarget.CreateSolidColorBrush(Color.FromKnown(Colors.Black, 1)); }
protected override void OnCreateDeviceIndependentResources(Direct2DFactory factory) { base.OnCreateDeviceIndependentResources(factory); this._textFormat = DirectWriteFactory.CreateTextFormat("Gabriola", FontWeight.Normal, FontStyle.Normal, FontStretch.Normal, 72); this._textFormat.TextAlignment = TextAlignment.Center; this._textFormat.ParagraphAlignment = ParagraphAlignment.Center; float width = ClientSize.Width / _dpiScaleX; float height = ClientSize.Height / _dpiScaleY; this._textLayout = DirectWriteFactory.CreateTextLayout( _text, this._textFormat, width, height); using (Typography typography = DirectWriteFactory.CreateTypography()) { typography.AddFontFeature(FontFeatureTag.StylisticSet7, 1); this._textLayout.SetTypography(typography, new TextRange(0, _text.Length)); } Bitmap bitmap = RenderTarget.CreateBitmap(this.GetType(), "heart.png"); this._bitmapInlineObject = new BitmapInlineObject(RenderTarget, bitmap); this._textLayout.SetInlineObject(this._bitmapInlineObject, new TextRange(2, 1)); }
protected override void OnCreateDeviceIndependentResources(Direct2DFactory factory) { base.OnCreateDeviceIndependentResources(factory); this._redColorDrawingEffect = new ColorDrawingEffect(Color.FromARGB(Colors.Red, 1)); this._greenColorDrawingEffect = new ColorDrawingEffect(Color.FromARGB(Colors.Green, 1)); this._blueColorDrawingEffect = new ColorDrawingEffect(Color.FromARGB(Colors.Blue, 1)); this._textFormat = DirectWriteFactory.CreateTextFormat("Gabriola", FontWeight.Normal, FontStyle.Normal, FontStretch.Normal, 72); this._textFormat.TextAlignment = TextAlignment.Center; this._textFormat.ParagraphAlignment = ParagraphAlignment.Center; float width = ClientSize.Width / _dpiScaleX; float height = ClientSize.Height / _dpiScaleY; this._textLayout = DirectWriteFactory.CreateTextLayout( _text, this._textFormat, width, height); this._textLayout.SetFontSize(100, new TextRange(20, 6)); this._textLayout.SetDrawingEffect(_blueColorDrawingEffect, new TextRange(6, 5)); this._textLayout.SetDrawingEffect(_redColorDrawingEffect, new TextRange(20, 6)); this._textLayout.SetDrawingEffect(_greenColorDrawingEffect, new TextRange(26, 5)); ClientDrawingEffect effect = this._textLayout.GetDrawingEffect(7); this._textLayout.SetUnderline(true, new TextRange(20, 11)); this._textLayout.SetFontWeight(FontWeight.Bold, new TextRange(20, 11)); using (Typography typography = DirectWriteFactory.CreateTypography()) { typography.AddFontFeature(FontFeatureTag.StylisticSet7, 1); this._textLayout.SetTypography(typography, new TextRange(0, _text.Length)); } }
/// <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); } }