/// ------------------------------------------------------------------------------------ /// <summary> /// Return coordinate transformation suitable for screen drawing in the specified /// element of the specified page. /// </summary> /// <param name="page"></param> /// <param name="pe"></param> /// <param name="rcSrcRoot"></param> /// <param name="rcDstRoot"></param> /// ------------------------------------------------------------------------------------ protected void GetCoordRectsForElt(Page page, PageElement pe, out Rect rcSrcRoot, out Rect rcDstRoot) { // The origin of this rectangle is the offset from the origin of this rootbox's // data to the origin of this element (in printer pixels). Size is DPI. Rectangle rectSrc = new Rectangle(0, pe.OffsetToTopPageBoundary - pe.OverlapWithPreviousElement, (int)(DpiXPrinter), (int)(DpiYPrinter)); rcSrcRoot = new Rect(rectSrc.Left, rectSrc.Top, rectSrc.Right, rectSrc.Bottom); Rectangle rectElement = pe.PositionInLayoutForScreen(IndexOfPage(page), this, DpiXScreen, DpiYScreen); // The origin of this rectangle is the offset from the origin of this element // to the origin of the clip rectangle (the part of the rc that // actually pertains to this element) (in screen pixels) Rectangle rectDst = new Rectangle(rectElement.Left, rectElement.Top, (int)(DpiXScreen * Zoom), (int)(DpiYScreen * Zoom)); rcDstRoot = new Rect(rectDst.Left, rectDst.Top, rectDst.Right, rectDst.Bottom); }
public void CalcPageElementWindowRectangle() { int dpiScreen = 96; int dpiXPrinter = m_pub.DpiXPrinter; int pdiYPrinter = m_pub.DpiYPrinter; m_pub.PageHeight = (int)(11 * MiscUtils.kdzmpInch); m_pub.PageWidth = (int)(8.5 * MiscUtils.kdzmpInch); m_pub.Width = (int)(8.5 * dpiScreen); Assert.AreEqual(1, m_pub.Zoom, "Physical Page and window should both be 8.5 inches wide"); using (PageElement element = new PageElement(m_firstDivision, null, false, new Rectangle(dpiXPrinter, pdiYPrinter, (int)(6.5 * dpiXPrinter), (int)(9 * pdiYPrinter)), 0, true, 1, 1, 0, 9 * pdiYPrinter,0, false)) { Rectangle expected = new Rectangle(dpiScreen, dpiScreen, (int)(6.5 * dpiScreen), (int)(9 * dpiScreen)); int pageIndex = 0; Assert.AreEqual(expected, element.PositionInLayoutForScreen(pageIndex, m_pub, dpiScreen, dpiScreen)); pageIndex = 1; expected.Location = new Point(expected.Left, expected.Top + (int)(11 * dpiScreen) + m_pub.Gap); Assert.AreEqual(expected, element.PositionInLayoutForScreen(pageIndex, m_pub, dpiScreen, dpiScreen)); // Can't seem to test this because we can't adjust the scroll position, even // though we set the AutoScrollMinSize, tried showing m_pub, gave it a Height, ... // m_pub.AutoScrollPosition = new Point(50, 100); // expected.Location = new Point(expected.Left - 50, expected.Top - 100); // Assert.AreEqual(expected, element.PositionInWindow(pageIndex, m_pub)); m_pub.Width = (int)(4.25 * dpiScreen); // Now we should be zoomed to 50%, so each real-world inch is now only a half-inch // on the screen. Assert.AreEqual(0.5, m_pub.Zoom); expected = new Rectangle(48, (int)(12 * 48) + m_pub.Gap, (int)(6.5 * 48), (int)(9 * 48)); Assert.AreEqual(expected, element.PositionInLayoutForScreen(pageIndex, m_pub, dpiScreen, dpiScreen)); } }