public override void DrawStringBaseline(string fontName, float size, string text, float x, float y, float start_x, Color4 color, bool underline = false, TextShadow shadow = default) { using (var layout = new TextLayout(dwFactory, text, GetFormat(fontName, ConvertSize(size)), float.MaxValue, float.MaxValue)) { var indent = (x - start_x); if (Math.Abs(indent) > 0.001f) { layout.SetInlineObject(new Indent(indent), new TextRange(0, 0)); } layout.SetDrawingEffect(new ColorDrawingEffect(color, shadow), new TextRange(0, text.Length)); layout.Draw(Renderer, 0, 0); foreach (var q in Renderer.Quads) { var d = q.Destination; d.X += (int)start_x; d.Y += (int)y; if (q.Texture == null) { render2d.FillRectangle(d, q.Color); } else { render2d.Draw(q.Texture, q.Source, d, q.Color); } } Renderer.Quads = new List <DrawQuad>(); } }
/// <summary> /// This method creates the render target and all associated D2D and DWrite resources /// </summary> void CreateDeviceResources() { // Only calls if resources have not been initialize before if (renderTarget == null) { // Create the render target SizeU size = new SizeU((uint)host.ActualWidth, (uint)host.ActualHeight); RenderTargetProperties props = new RenderTargetProperties(); HwndRenderTargetProperties hwndProps = new HwndRenderTargetProperties(host.Handle, size, PresentOptions.None); renderTarget = d2dFactory.CreateHwndRenderTarget(props, hwndProps); // Create the black brush for text blackBrush = renderTarget.CreateSolidColorBrush(new ColorF(0, 0, 0, 1)); inlineImage = new ImageInlineObject(renderTarget, wicFactory, "TextInlineImage.img1.jpg"); TextRange textRange = new TextRange(14, 1); textLayout.SetInlineObject(inlineImage, textRange); } }