/// <summary> /// Renders a calendar content range to the canvas. /// </summary> /// <param name="content">the content to render</param> /// <param name="canvas">the drawing canvas to use</param> /// <param name="rect">the calendar rectangle</param> public void Render(CalendarContentRange content, IDrawingCanvas canvas, RectangleF rect) { if (content == null) { throw new ArgumentNullException("content"); } if (canvas == null) { throw new ArgumentNullException("canvas"); } _calendarData = new CalendarData((ICalendar)content.Owner); this._rightToLeft = ((ICalendar)content.Owner).Direction == Direction.RTL; try { // store the canvas to use in rendering _canvas = canvas; // TODO: consider to add gaps // allocate the area for calendar drawing _calendarArea = rect; // allocate the area for only one month _monthArea = new SizeF(content.Owner.Width.ToTwips(), content.Owner.Height.ToTwips()); DrawMonths(CalendarData.GetMonthsRange(content.MonthFrom, content.MonthTo)); } finally { if (_calendarData != null) { _calendarData.Dispose(); } } }
public void CalendarRenderWithNoDataBound() { PageDocument report = TestHelper.GetReport("Calendar-NoData.rdlx"); TestingRenderingExtension rendererExt = new TestingRenderingExtension(); report.Render(rendererExt, null); CalendarDataRegion calendar = rendererExt.GetReportItem("Calendar1") as CalendarDataRegion; Assert.IsNotNull(calendar); CalendarData calendarData = new CalendarData(calendar); CalendarContentRange content = new CalendarContentRange(calendar, calendarData.GetFirstMonth(), calendarData.GetLastMonth()); // recalibrate graphics to twips RectangleF rect = new RectangleF(0, 0, 4000f, 4000f); CalendarDesigner.ScaleToTwipsGraphicsAndBound(GetGraphics(), ref rect); // create gdi canvas wrapper to use in renderer IDrawingCanvas canvas = GraphicsCanvasFactory.Create(GetGraphics()); // render calendar to canvas CalendarRenderer.Instance.Render(content, canvas, rect); }
void IGraphicsRenderer.Render(GraphicsRenderContext context, ILayoutArea area) { _layoutArea = area; const string ErrorMsg = "IGraphicsRenderer was configured improperly."; CalendarContentRange content = area.ContentRange as CalendarContentRange; if (content == null) { Trace.TraceError(ErrorMsg); return; } CalendarDataRegion calendar = content.Owner as CalendarDataRegion; if (calendar == null) { Trace.TraceError(ErrorMsg); return; } if (context.DoContent) { Render(content, context.Canvas, new RectangleF(area.Left, area.Top, area.Width, area.Height)); } }
public void TestRenderingInMultiThreads() { var report = TestHelper.GetReport("Calendar.rdlx"); var rendererExt = new TestingRenderingExtension(); report.Render(rendererExt, null); var calendar = rendererExt.GetReportItem("Calendar1") as CalendarDataRegion; Assert.IsNotNull(calendar); var calendarData = new CalendarData(calendar); var content = new CalendarContentRange(calendar, calendarData.GetFirstMonth(), calendarData.GetLastMonth()); // recalibrate graphics to twips var rect = new RectangleF(0, 0, 4000f, 4000f); CalendarDesigner.ScaleToTwipsGraphicsAndBound(GetGraphics(), ref rect); // the action of rendering calendar to canvas System.Action render = () => { using (var graphics = Graphics.FromHwnd(IntPtr.Zero)) { var canvas = GraphicsCanvasFactory.Create(graphics); (calendar.GetRenderer <IGraphicsRenderer>() as CalendarRenderer) .Render(content, canvas, rect); } }; var isSuccess1 = false; var isSuccess2 = false; ThreadStart render1 = () => { render(); isSuccess1 = true; }; ThreadStart render2 = () => { render(); isSuccess2 = true; }; var thread1 = new Thread(render1); var thread2 = new Thread(render2); thread1.Start(); thread2.Start(); thread1.Join(); thread2.Join(); Assert.IsTrue(isSuccess1); Assert.IsTrue(isSuccess2); }