PDFsharp & MigraDoc Forum https://forum.pdfsharp.net/ |
|
SetClip deprecated https://forum.pdfsharp.net/viewtopic.php?f=2&t=2223 |
Page 1 of 1 |
Author: | jbradshaw7 [ Fri Nov 16, 2012 10:22 am ] |
Post subject: | SetClip deprecated |
I've inherited an old .NET 1.1 project which I am migrating to .NET 3.5. This included an old version of PdfSharp which I've replaced with the latest. However, there is some PdfSharp code used in our project which is now deprecated. I include an example below: Code: private void DrawBody(XGraphics gr) { if (resources != null) { using (Pen pen = new Pen(new SolidBrush(titleBackground),2)) { RectangleF oldClip = gr.Graphics.ClipBounds; try { HPResource resource; RectangleF clipRect = CalcClipRect(gr); int i = 0; int row = startRow; lastPrintPos = headerHeight+1; while ((row < resources.Count) && (lastPrintPos+resources[row].RowHeight <= Math.Round(clipRect.Bottom+(toPrinter ? 0 : resources.PlanHeight), 0))) { resource = resources[row]; ticBottom = lastPrintPos+resource.RowHeight; // get the content drawn DrawBodyContent(gr, resource); i++; gr.DrawLine(pen, left, ticBottom, left+width-1, ticBottom); lastPrintPos = ticBottom; row++; lastPrintRow = row ; } printFinished = (row == resources.Count && canFinish); } finally { gr.SetClip(oldClip, XCombineMode.Replace); } } } } The call to SetClip in the finally clause is throwing an error since this method is deprecated in the latest PdfSharp. The error suggests using IntersectClip instead but this seems to do something different. How can I achieve the same result in the new PdfSharp as the deprecated SetClip call? Any help greatly appreciated. |
Author: | Thomas Hoevel [ Mon Nov 19, 2012 9:30 am ] |
Post subject: | Re: SetClip deprecated |
Short version: Deprecated functions lead to warnings, not errors. Disable the warning in the line above SetClip and you're done. Long version: I don't know how to replace SetClip with IntersectClip. After a quick glance at your code, I'd try Save and Restore instead ClipBounds/SetClip. See this sample (final two procedures): http://www.pdfsharp.net/wiki/Graphics-sample.ashx |
Author: | jbradshaw7 [ Mon Nov 19, 2012 9:39 am ] |
Post subject: | Re: SetClip deprecated |
Thomas Hoevel wrote: Short version: Deprecated functions lead to warnings, not errors. Disable the warning in the line above SetClip and you're done. Long version: I don't know how to replace SetClip with IntersectClip. After a quick glance at your code, I'd try Save and Restore instead ClipBounds/SetClip. See this sample (final two procedures): http://www.pdfsharp.net/wiki/Graphics-sample.ashx Many thanks. In this case it does produce an error. Looking at the pdfsharp code for SetClip shows why: Code: /// <summary> /// Sets the clipping region to the specified graphical path. /// </summary> [Obsolete("Use IntersectClip", true)] public void SetClip(XRect rect, XCombineMode combineMode) { throw new InvalidOperationException("Function is obsolete. Use IntersectClip."); //XGraphicsPath path = new XGraphicsPath(); //path.AddRectangle(rect); //SetClip(path, combineMode); } I've replaced the SetClip call in the finally clause with the following which seems to be the equivalent: Code: gr.Graphics.SetClip(oldClip, CombineMode.Replace); Other than that I don't really want to change this legacy code unless I have to! |
Author: | Thomas Hoevel [ Mon Nov 19, 2012 10:35 am ] |
Post subject: | Re: SetClip deprecated |
Looks like your code actually needs "ResetClip" instead of "SetClip". ResetClip is also obsolete, comment tells to use Save/Restore instead. I understand you only want to make minimal changes to legacy code. |
Page 1 of 1 | All times are UTC |
Powered by phpBB® Forum Software © phpBB Group https://www.phpbb.com/ |