/// <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(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); } }
/// <summary> /// Creates a TextLayout with the specified parameter</summary> /// <param name="text">The string to create a new D2dTextLayout object from</param> /// <param name="textFormat">The text format to apply to the string</param> /// <param name="layoutWidth">Text layout width</param> /// <param name="layoutHeight">Text layout height</param> /// <param name="transform">2D Matrix used to transform the text</param> /// <returns>A new instance of D2dTextLayout</returns> public static D2dTextLayout CreateTextLayout(string text, D2dTextFormat textFormat, float layoutWidth, float layoutHeight, Matrix3x2F transform) { var matrix = Matrix.Identity; matrix.M11 = transform.M11; matrix.M12 = transform.M12; matrix.M21 = transform.M21; matrix.M22 = transform.M22; matrix.M31 = transform.DX; matrix.M32 = transform.DY; var textlayout = new TextLayout(s_dwFactory, text, textFormat.NativeTextFormat, layoutWidth, layoutHeight, 1, matrix, true); if (textFormat.Underlined) { textlayout.SetUnderline(true, new SharpDX.DirectWrite.TextRange(0, text.Length)); } if (textFormat.Strikeout) { textlayout.SetStrikethrough(true, new SharpDX.DirectWrite.TextRange(0, text.Length)); } var d2dTextLayout = new D2dTextLayout(text, textlayout); d2dTextLayout.DrawTextOptions = textFormat.DrawTextOptions; return(d2dTextLayout); }
private void RandomizeTextLayout() { TextLayout = dwriteFactory.CreateTextLayout( Text, TextFormat, Random.Next(50, Math.Max(100, CanvasWidth - (int)Point0.X)), Random.Next(50, Math.Max(100, CanvasHeight - (int)Point0.Y))); if (CoinFlip) { TextLayout.SetUnderline(true, RandomTextRange()); } if (CoinFlip) { TextLayout.SetStrikethrough(true, RandomTextRange()); } if (CoinFlip) { TextLayout.LineSpacing = RandomLineSpacing(TextFormat.FontSize); } if (NiceGabriola) { TypographySettingCollection t = dwriteFactory.CreateTypography(); t.Add(new FontFeature(FontFeatureTag.StylisticSet07, 1)); TextLayout.SetTypography(t, new TextRange(0, (uint)Text.Length)); } }
/// <summary> /// Creates a TextLayout with the specified parameter</summary> /// <param name="text">The string to create a new D2dTextLayout object from</param> /// <param name="textFormat">The text format to apply to the string</param> /// <param name="layoutWidth">Text layout width</param> /// <param name="layoutHeight">Text layout height</param> /// <returns>A new instance of D2dTextLayout</returns> public static D2dTextLayout CreateTextLayout(string text, D2dTextFormat textFormat, float layoutWidth, float layoutHeight) { var textlayout = new TextLayout(s_dwFactory, text, textFormat.NativeTextFormat, layoutWidth, layoutHeight); if (textFormat.Underlined) { textlayout.SetUnderline(true, new SharpDX.DirectWrite.TextRange(0, text.Length)); } if (textFormat.Strikeout) { textlayout.SetStrikethrough(true, new SharpDX.DirectWrite.TextRange(0, text.Length)); } var d2dTextLayout = new D2dTextLayout(text, textlayout); d2dTextLayout.DrawTextOptions = textFormat.DrawTextOptions; return(d2dTextLayout); }
public virtual void Texts(Xwt.Drawing.Context ctx, double x, double y) { ctx.Save(); ctx.Translate(x, y); ctx.SetColor(Colors.Black); var col1 = new Rectangle(); var col2 = new Rectangle(); var text = new TextLayout(); text.Font = this.Font.WithSize(24); Console.WriteLine(text.Font.Size); // first text text.Text = "Lorem ipsum dolor sit amet,"; var size1 = text.GetSize(); col1.Width = size1.Width; col1.Height += size1.Height + 10; ctx.DrawTextLayout(text, 0, 0); // proofing width; test should align with text above ctx.SetColor(Colors.DarkMagenta); text.Text = "consetetur sadipscing elitr, sed diam nonumy"; text.Width = col1.Width; var size2 = text.GetSize(); ctx.DrawTextLayout(text, 0, col1.Bottom); col1.Height += size2.Height + 10; ctx.SetColor(Colors.Black); // proofing scale, on second col ctx.Save(); ctx.SetColor(Colors.Red); col2.Left = col1.Right + 10; text.Text = "eirmod tempor invidunt ut."; var scale = 1.2; text.Width = text.Width / scale; var size3 = text.GetSize(); col2.Height = size3.Height * scale; col2.Width = size3.Width * scale + 5; ctx.Scale(scale, scale); ctx.DrawTextLayout(text, col2.Left / scale, col2.Top / scale); ctx.Restore(); // proofing heigth, on second col ctx.Save(); ctx.SetColor(Colors.DarkCyan); text.Text = "Praesent ac lacus nec dolor pulvinar feugiat a id elit."; var size4 = text.GetSize(); text.Height = size4.Height / 2; text.Trimming = TextTrimming.WordElipsis; ctx.DrawTextLayout(text, col2.Left, col2.Bottom + 5); ctx.SetLineWidth(1); ctx.SetColor(Colors.Blue); ctx.Rectangle(new Rectangle(col2.Left, col2.Bottom + 5, text.Width, text.Height)); ctx.Stroke(); ctx.Restore(); // drawing col line ctx.SetLineWidth(1); ctx.SetColor(Colors.Black.WithAlpha(.5)); ctx.MoveTo(col1.Right + 5, col1.Top); ctx.LineTo(col1.Right + 5, col1.Bottom); ctx.Stroke(); ctx.MoveTo(col2.Right + 5, col2.Top); ctx.LineTo(col2.Right + 5, col2.Bottom); ctx.Stroke(); ctx.SetColor(Colors.Black); // proofing rotate, and printing size to see the values ctx.Save(); text.Font = this.Font.WithSize(10); text.Text = string.Format("Size 1 {0}\r\nSize 2 {1}\r\nSize 3 {2} Scale {3}", size1, size2, size3, scale); text.Width = -1; // this clears textsize text.Height = -1; ctx.Rotate(5); // maybe someone knows a formula with angle and textsize to calculyte ty var ty = 30; ctx.DrawTextLayout(text, ty, col1.Bottom + 10); ctx.Restore(); // scale example here: ctx.Restore(); TextLayout tl0 = new TextLayout(this); tl0.Font = this.Font.WithSize(10); tl0.Text = "This text contains attributes."; tl0.SetUnderline(0, "This".Length); tl0.SetForeground(new Color(0, 1.0, 1.0), "This ".Length, "text".Length); tl0.SetBackground(new Color(0, 0, 0), "This ".Length, "text".Length); tl0.SetFontWeight(FontWeight.Bold, "This text ".Length, "contains".Length); tl0.SetFontStyle(FontStyle.Italic, "This text ".Length, "contains".Length); tl0.SetStrikethrough("This text contains ".Length, "attributes".Length); ctx.DrawTextLayout(tl0, col2.Left, col2.Bottom + 100); // Text boces y = 180; // Without wrapping TextLayout tl = new TextLayout(this); tl.Text = "Stright text"; DrawText(ctx, tl, ref y); // With wrapping tl = new TextLayout(this); tl.Text = "The quick brown fox jumps over the lazy dog"; tl.Width = 100; DrawText(ctx, tl, ref y); // With blank lines tl = new TextLayout(this); tl.Text = "\nEmpty line above\nLine break above\n\nEmpty line above\n\n\nTwo empty lines above\nEmpty line below\n"; tl.Width = 200; DrawText(ctx, tl, ref y); }
protected override void DoApply(TextLayout layout, TextRange range) { layout.SetStrikethrough(true, range); }
public void DrawMessages() { if (msgs.Count == 0) { return; } lastText = text; text = ""; foreach (OSDMessage msg in msgs) { text += msg.msg + "\r\n"; } text = text.Trim(); if (text == "") { return; } if (lastText == text && !requiresUpdate) { msgs.Clear(); Draw(); return; } Utilities.Dispose(ref layout); if (brushes.Count > 0) { foreach (var brush in brushes) { SolidColorBrush tmp = brush; Utilities.Dispose(ref tmp); } brushes = new List <SolidColorBrush>(); } layout = new TextLayout(renderer.factoryWrite, text, format, hookViewport ? renderer.GetViewport.Width : renderer.HookControl.Width, hookViewport ? renderer.GetViewport.Height : renderer.HookControl.Height); // Fix Styling int curPos = 0; foreach (OSDMessage msg in msgs) { if (msg.styles == null) { curPos += msg.msg.Length + 2; continue; } foreach (SubStyle style in msg.styles) { switch (style.style) { case SubStyles.BOLD: layout.SetFontWeight(FontWeight.Bold, new TextRange(curPos + style.from, style.len)); break; case SubStyles.ITALIC: layout.SetFontStyle(FontStyle.Italic, new TextRange(curPos + style.from, style.len)); break; case SubStyles.UNDERLINE: layout.SetUnderline(true, new TextRange(curPos + style.from, style.len)); break; case SubStyles.STRIKEOUT: layout.SetStrikethrough(true, new TextRange(curPos + style.from, style.len)); break; case SubStyles.COLOR: SolidColorBrush brush2dtmp = new SolidColorBrush(renderer.rtv2d, (Color)style.value); brushes.Add(brush2dtmp); layout.SetDrawingEffect(brush2dtmp.NativePointer, new TextRange(curPos + style.from, style.len)); break; } } curPos += msg.msg.Length + 2; } CreateRectangle(); msgs.Clear(); Draw(); requiresUpdate = false; }