/// <summary> /// Adds a colored border around each layout element on the page. /// </summary> private static void AddBoundingBoxToElementsOnPage(LayoutEnumerator layoutEnumerator, Graphics g) { do { // Use MoveLastChild and MovePrevious to enumerate from last to the first enumeration is done backward, // so the lines of child entities are drawn first and don't overlap the parent's lines. if (layoutEnumerator.MoveLastChild()) { AddBoundingBoxToElementsOnPage(layoutEnumerator, g); layoutEnumerator.MoveParent(); } // Convert the rectangle representing the position of the layout entity on the page from points to pixels. RectangleF rectF = layoutEnumerator.Rectangle; Rectangle rect = new Rectangle(PointToPixel(rectF.Left, g.DpiX), PointToPixel(rectF.Top, g.DpiY), PointToPixel(rectF.Width, g.DpiX), PointToPixel(rectF.Height, g.DpiY)); // Draw a line around the layout entity on the page. g.DrawRectangle(GetColoredPenFromType(layoutEnumerator.Type), rect); // Stop after all elements on the page have been processed. if (layoutEnumerator.Type == LayoutEntityType.Page) { return; } } while (layoutEnumerator.MovePrevious()); }
/// <summary> /// Enumerate through layoutEnumerator's layout entity collection back-to-front, in a DFS manner, and in a "Visual" order. /// </summary> private static void TraverseLayoutBackward(LayoutEnumerator layoutEnumerator, int depth) { do { PrintCurrentEntity(layoutEnumerator, depth); if (layoutEnumerator.MoveLastChild()) { TraverseLayoutBackward(layoutEnumerator, depth + 1); layoutEnumerator.MoveParent(); } } while (layoutEnumerator.MovePrevious()); }
/// <summary> /// Adds a colored border around each layout element on the page. /// </summary> private static void AddBoundingBoxToElementsOnPage(LayoutEnumerator it, Graphics g) { do { // This time instead of MoveFirstChild and MoveNext, we use MoveLastChild and MovePrevious to enumerate from last to first. // Enumeration is done backward so the lines of child entities are drawn first and don't overlap the lines of the parent. if (it.MoveLastChild()) { AddBoundingBoxToElementsOnPage(it, g); it.MoveParent(); } // Convert the rectangle representing the position of the layout entity on the page from points to pixels. RectangleF rectF = it.Rectangle; Rectangle rect = new Rectangle(PointToPixel(rectF.Left, g.DpiX), PointToPixel(rectF.Top, g.DpiY), PointToPixel(rectF.Width, g.DpiX), PointToPixel(rectF.Height, g.DpiY)); // Draw a line around the layout entity on the page. g.DrawRectangle(GetColoredPenFromType(it.Type), rect); // Stop after all elements on the page have been procesed. if (it.Type == LayoutEntityType.Page) return; } while (it.MovePrevious()); }