public XResource() { TextFormats = new TextFormatManager(DWriteFactory); Bitmaps = new BitmapManager(WICFactory); TextLayouts = new TextLayoutManager(DWriteFactory, TextFormats); }
public void DrawString(String s, Font font, Brush brush, RectangleF layoutRectangle, StringFormat format) { // bail out now if there's nothing to draw if((brush is SolidBrush) && ((SolidBrush)brush).Color.A == 0) { return; } // bail out now if there's nothing to draw if(((Object)s) == null || s.Length == 0) { return; } // make a little inset around the text dependent of the font size layoutRectangle.Inflate((int)(-font.SizeInPoints*DpiX/369.7184), 0); // convert the layout into device coordinates Point[] rect = ConvertRectangle ((layoutRectangle.X + baseWindow.X), (layoutRectangle.Y + baseWindow.Y), (layoutRectangle.Width - 1), (layoutRectangle.Height - 1), pageUnit); // create a layout rectangle from the device coordinates Rectangle deviceLayout = new Rectangle (rect[0].X, rect[0].Y, (rect[1].X - rect[0].X + 1), (rect[2].Y - rect[0].Y + 1)); // bail out now if there's nothing to draw if(clip != null && !deviceClipExtent.IntersectsWith(deviceLayout)) { return; } // ensure we have a text layout manager if(textLayoutManager == null) { textLayoutManager = new TextLayoutManager(); } // set the default temporary clip Region clipTemp = null; // draw the text lock(this) { // get the clipping region, if needed if(format == null || ((format.FormatFlags & StringFormatFlags.NoClip) == 0)) { // get the clipping region, if there is one if(clip != null) { // get a copy of the current clipping region clipTemp = clip.Clone(); // interset the clipping region with the layout SetClip(layoutRectangle, CombineMode.Intersect); } } // attempt to draw the text try { // Workaround for calculation new font size, if a transformation is set // this does only work for scaling, not for rotation or multiply transformations // draw the text textLayoutManager.Draw (this, s, this.TransformFont(font), deviceLayout, format, brush); } finally { // reset the clip if(clipTemp != null) { Clip = clipTemp; } } } }