private void MainWindow_Load(object sender, EventArgs e) { DirectWriteFactory f = DirectWriteFactory.Create(DirectWriteFactoryType.Shared); _textFormat = f.CreateTextFormat("Verdana", 110, FontWeight.Normal, FontStyle.Normal, FontStretch.Normal); _textFormat.ParagraphAlignment = ParagraphAlignment.Far; _textFormat.TextAlignment = TextAlignment.Center; ClientSize = new System.Drawing.Size(600, 600); _factory = Direct2DFactory.CreateFactory(FactoryType.SingleThreaded, DebugLevel.None, FactoryVersion.Auto); _renderTarget = _factory.CreateWindowRenderTarget(this, PresentOptions.None, RenderTargetProperties.Default); AntialiasMode amode = _renderTarget.AntialiasMode; TextAntialiasMode tamode = _renderTarget.TextAntialiasMode; _strokeBrush = _renderTarget.CreateSolidColorBrush(Color.FromKnown(Colors.Cyan, 1)); try { _strokeStyle = _factory.CreateStrokeStyle(new StrokeStyleProperties1(LineCapStyle.Flat, LineCapStyle.Flat, LineCapStyle.Round, LineJoin.Miter, 10, DashStyle.Dot, 0, StrokeTransformType.Normal), null); } catch (NotSupportedException) { _strokeStyle = _factory.CreateStrokeStyle(new StrokeStyleProperties(LineCapStyle.Flat, LineCapStyle.Flat, LineCapStyle.Round, LineJoin.Miter, 10, DashStyle.Dot, 0), null); } Resize += new EventHandler(MainWindow_Resize); }
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._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)); } }
protected override void OnCreateDeviceIndependentResources(Direct2DFactory factory) { base.OnCreateDeviceIndependentResources(factory); this._textFormat = DirectWriteFactory.CreateTextFormat("Verdana", 10.5f, FontWeight.Bold, FontStyle.Normal, FontStretch.Normal); this._textFormat.ParagraphAlignment = ParagraphAlignment.Near; this._textFormat.TextAlignment = TextAlignment.Center; }
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("Click on this text Click on this text", this._textFormat, width, height); this._textAnalyzer = DirectWriteFactory.CreateTextAnalyzer(); this._source = new MyTextSource("Click on this text Click on this text"); using (FontCollection coll = this._textFormat.FontCollection) { int count = coll.Count; for (int index = 0; index < count; ++index) { using (FontFamily ff = coll[index]) { using (Font font = ff.GetFirstMatchingFont(FontWeight.Normal, FontStretch.Normal, FontStyle.Normal)) { LocalizedStrings ls = font.FaceNames; LocalizedStrings desc = font.GetInformationalStrings(InformationalStringId.Designer); int cultureIndex = ls.FindCulture(CultureInfo.CurrentCulture); string faceName = ls[cultureIndex]; FontMetrics metrics = font.Metrics; } } } } this._textAnalyzer.AnalyzeLineBreakpoints(_source, 0, (uint)_source.Text.Length); this._textAnalyzer.AnalyzeScript(_source, 0, (uint)_source.Text.Length); }
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; }
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; System.Globalization.CultureInfo ci = this._textFormat.Culture; Trimming trimming = this._textFormat.Trimming; }
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("Click on this text", this._textFormat, width, height); }
protected override void OnCreateDeviceIndependentResources(Direct2DFactory factory) { base.OnCreateDeviceIndependentResources(factory); this._textFormat = DirectWriteFactory.CreateTextFormat("Verdana", FontWeight.Normal, FontStyle.Normal, FontStretch.Normal, 10.5f); this._textFormat.TextAlignment = TextAlignment.Center; float[] dashes = new float[] { 1, 1, 2, 3, 5 }; this._strokeStyle = factory.CreateStrokeStyle( new StrokeStyleProperties(LineCapStyle.Flat, LineCapStyle.Flat, LineCapStyle.Round, LineJoin.Round, 10, DashStyle.Custom, 0), dashes); CreateGeometries(factory); }
protected override void OnRender(WindowRenderTarget renderTarget) { float y = 0; for (int index = 0; index < this._paragraphs.Count; ++index) { using (TextFormat textFormat = DirectWriteFactory.CreateTextFormat( this._paragraphs[index].FontFamily, this._paragraphs[index].Weight, this._paragraphs[index].FontSize * 96f / 72f)) { textFormat.TextAlignment = _paragraphs[index].TextAlignment; LineSpacing lineSpacing = textFormat.LineSpacing; if (_paragraphs[index].LineSpacing == 0) { textFormat.LineSpacing = LineSpacing.Default; } else { textFormat.LineSpacing = new LineSpacing(_paragraphs[index].LineSpacing); } float width = ClientSize.Width / DpiScaleX - (_marginLeft + _marginRight); using (TextLayout textLayout = DirectWriteFactory.CreateTextLayout( this._paragraphs[index].Text, textFormat, width, 0)) { y += _paragraphs[index].SpaceBefore; renderTarget.DrawTextLayout( new PointF(_marginLeft, y), textLayout, _blackBrush, DrawTextOptions.None); TextMetrics metrics = textLayout.Metrics; y += metrics.Height + _paragraphs[index].SpaceAfter; } } } }
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)); } }
private async Task Render() { DeviceContext renderTarget = _deviceContext; renderTarget.BeginDraw(); renderTarget.Clear(Color.FromKnown(Colors.Black, 1f)); for (int index = 0; index < PointCount; ++index) { for (int n = 0; n < NeighborCount; ++n) { renderTarget.DrawLine(_brush1, (NeighborCount - n) / (float)(10 * NeighborCount), _points[index], _points[_neighbors[index, n]]); } renderTarget.DrawEllipse(_brush, 0.5f, new Ellipse(_points[index], 1.5f, 1.5f)); } string text = "Press <Esc> to exit..."; using (TextFormat textFormat = _directWriteFactory.CreateTextFormat("Segoe UI", 13, FontWeight.Normal)) using (TextLayout textLayout = _directWriteFactory.CreateTextLayout(text, textFormat, float.MaxValue, float.MaxValue)) using (SolidColorBrush textBrush = renderTarget.CreateSolidColorBrush(Color.FromKnown(Colors.White, 1))) { renderTarget.DrawText( text, textFormat, new RectF(10, 10, ClientRectangle.Width, ClientRectangle.Height), textBrush, DrawTextOptions.None, MeasuringMode.Natural ); } renderTarget.EndDraw(); _swapChain.Present(1, 0); await MovePoints(); }
private void Render() { DeviceContext renderTarget = _deviceContext; renderTarget.BeginDraw(); renderTarget.Clear(Color.FromKnown(Colors.Black, 1f)); _random = new Random(19292); for (int index = 0; index < _brushes.Length; ++index) { float x = _random.Next(0, ClientRectangle.Width); float y = _random.Next(0, ClientRectangle.Height); Ellipse ellipse = new Ellipse(x, y, 50, 50); renderTarget.FillEllipse(_brushes[index], ellipse); renderTarget.DrawEllipse(_pens[index], 1, ellipse); } string text = "Press <Esc> to exit..."; using (TextFormat textFormat = _directWriteFactory.CreateTextFormat("Segoe UI", 13, FontWeight.Normal)) using (TextLayout textLayout = _directWriteFactory.CreateTextLayout(text, textFormat, float.MaxValue, float.MaxValue)) using (SolidColorBrush textBrush = renderTarget.CreateSolidColorBrush(Color.FromKnown(Colors.White, 1))) { renderTarget.DrawText( text, textFormat, new RectF(10, 10, ClientRectangle.Width, ClientRectangle.Height), textBrush, DrawTextOptions.None, MeasuringMode.Natural ); } renderTarget.EndDraw(); _swapChain.Present(1, 0); }
private void CreateResources() { _textFormat = DirectWriteFactory.CreateTextFormat( FontName, FontSize, Bold ? FontWeight.Bold : FontWeight.Normal, Italic ? FontStyle.Italic : FontStyle.Normal); _textFormat.ParagraphAlignment = ParagraphAlignment.Center; _textFormat.TextAlignment = TextAlignment.Center; float width = ClientSize.Width / dpiScaleX; float height = ClientSize.Height / dpiScaleY; _textLayout = DirectWriteFactory.CreateTextLayout( Text, _textFormat, width, height); if (Underline) { _textLayout.SetUnderline(true, new TextRange(0, Text.Length)); } }
protected override void OnCreateDeviceIndependentResources(Direct2DFactory factory) { base.OnCreateDeviceIndependentResources(factory); _textFormat = DirectWriteFactory.CreateTextFormat("Gabriola", 96); _textLayout = DirectWriteFactory.CreateTextLayout(_text, _textFormat, float.MaxValue, float.MaxValue); }
public HelloWorld() : base() { _textFormat = DirectWriteFactory.CreateTextFormat("Gabriola", fontSize: 64); _textFormat.SetTextAlignment(TextAlignment.Center); _textFormat.SetParagraphAlignment(ParagraphAlignment.Center); }