private DrawingVisual LayoutHeadingAndNumber(int pageNumber, string Heading, int fontSize, System.Windows.Media.Brush brush) { DrawingVisual title = new DrawingVisual(); using (DrawingContext titleContext = title.RenderOpen()) { TextPreformats text3 = GetPageNumbers(pageNumber); //TODO this must be parameterised, HARD CODED DEMO ONLY TextPreformats headingDemo = new TextPreformats(Heading, fontSize, brush); TextPreformats footerTitle = new TextPreformats(System.DateTime.Today, 14, System.Windows.Media.Brushes.Green); Rect contentBox = _paginator.GetPage(pageNumber).ContentBox; PlaceHeadingFooting(headingDemo, contentBox, Positions.Topleft, titleContext); if (text3.textHeight < _footerSize + 2) { PlaceHeadingFooting(text3, contentBox, Positions.BottomRight, titleContext); } PlaceHeadingFooting(text3, contentBox, Positions.Topright, titleContext); if (text3.textHeight < _footerSize + 2) { PlaceHeadingFooting(footerTitle, contentBox, Positions.Bottomleft, titleContext); } } return(title); }
private void CreateCornerPoints(Rect contentBox, TextPreformats text, ref System.Windows.Point topLeftPoint, ref System.Windows.Point topRightPoint, ref System.Windows.Point bottomLeftPoint, ref System.Windows.Point bottomRightPoint) { double headingTopY = _thickness * 5; double headingBottomY = PPageSize.Height - (_margin.Bottom * 2) - (_thickness * 2) - text.textHeight; //contentBox.Bottom + (m_FooterSize / 4) - m_Thickness double headingLeftX = contentBox.Left + (_margin.Right / 2) + (_margin.Left / 2); double headingRightX = contentBox.Right - text.textWidth - (_margin.Right - _thickness); topLeftPoint = new System.Windows.Point { X = headingLeftX, Y = headingTopY }; topRightPoint = new System.Windows.Point { X = headingRightX, Y = headingTopY }; bottomLeftPoint = new System.Windows.Point { X = headingLeftX, Y = headingBottomY }; bottomRightPoint = new System.Windows.Point { X = headingRightX, Y = headingBottomY }; }
private object PlaceHeadingFooting(TextPreformats text, Rect contentBox, Positions position, DrawingContext context) { System.Windows.Point topLeftPoint = new System.Windows.Point(); System.Windows.Point topRightPoint = new System.Windows.Point(); System.Windows.Point bottomLeftPoint = new System.Windows.Point(); System.Windows.Point bottomRightPoint = new System.Windows.Point(); CreateCornerPoints(contentBox, text, ref topLeftPoint, ref topRightPoint, ref bottomLeftPoint, ref bottomRightPoint); FormattedText fText = text.P_formattedText; switch (position) { case Positions.Topleft: context.DrawText(fText, topLeftPoint); break; case Positions.Topright: context.DrawText(fText, topRightPoint); break; case Positions.Bottomleft: context.DrawText(fText, bottomLeftPoint); break; case Positions.BottomRight: context.DrawText(fText, bottomRightPoint); break; } return(context); }
private TextPreformats GetPageNumbers(int pageNumber) { TextPreformats text3 = new TextPreformats("Page " + (pageNumber + 1), System.Windows.Media.Brushes.Red); return(text3); }