From 2d16db5bf2cb513751150294a432fecacd5e12c5 Mon Sep 17 00:00:00 2001 From: Rich Date: Thu, 7 Apr 2011 23:35:07 +0000 Subject: [PATCH] Override the default font for Demo Mode Check for null MyFlexGrid before using it. Added Static LineWidth0 method used for drawing borders on the screen Fixed logic to draw borders on the VlnFlexGrid Fixed logic to draw grid borders on the pdf output. --- PROMS/VEPROMS User Interface/frmVEPROMS.cs | 7 + PROMS/Volian.Controls.Library/StepRTB.cs | 6 +- .../Volian.Controls.Library/StepTabRibbon.cs | 4 +- PROMS/Volian.Controls.Library/VlnBorders.cs | 18 + PROMS/Volian.Controls.Library/VlnFlexGrid.cs | 326 ++++++++++++------ PROMS/Volian.Print.Library/Grid2Pdf.cs | 94 ++--- 6 files changed, 310 insertions(+), 145 deletions(-) diff --git a/PROMS/VEPROMS User Interface/frmVEPROMS.cs b/PROMS/VEPROMS User Interface/frmVEPROMS.cs index 2a278063..1fe08b02 100644 --- a/PROMS/VEPROMS User Interface/frmVEPROMS.cs +++ b/PROMS/VEPROMS User Interface/frmVEPROMS.cs @@ -274,6 +274,13 @@ namespace VEPROMS tc.Enter += new EventHandler(tc_Enter); tc.Leave += new EventHandler(tc_Leave); this.Deactivate += new EventHandler(frmVEPROMS_Deactivate); + if (VlnSettings.DemoMode) StepRTB.MyFontFamily = GetFamily("Bookman Old Style"); + } + private FontFamily GetFamily(string name) + { + foreach (FontFamily ff in FontFamily.Families) + if (ff.Name == name) return ff; + return null; } void frmVEPROMS_Deactivate(object sender, EventArgs e) { diff --git a/PROMS/Volian.Controls.Library/StepRTB.cs b/PROMS/Volian.Controls.Library/StepRTB.cs index f4873dcb..5903fa08 100644 --- a/PROMS/Volian.Controls.Library/StepRTB.cs +++ b/PROMS/Volian.Controls.Library/StepRTB.cs @@ -339,10 +339,10 @@ namespace Volian.Controls.Library _FormatFont = formatFont; else { - if (VlnSettings.DebugMode || VlnSettings.ProductionMode) + //if (VlnSettings.DebugMode || VlnSettings.ProductionMode) _FormatFont = new Font(MyFontFamily == null ? formatFont.FontFamily : MyFontFamily, formatFont.Size, formatFont.Style); - else - _FormatFont = new Font("Bookman Old Style", formatFont.Size, formatFont.Style); + //else + // _FormatFont = new Font("Bookman Old Style", formatFont.Size, formatFont.Style); // TODO: Release Mode //Font = _origDisplayText.TextFont.WindowsFont; // font defined in plant's format } diff --git a/PROMS/Volian.Controls.Library/StepTabRibbon.cs b/PROMS/Volian.Controls.Library/StepTabRibbon.cs index fb1efd88..639557ee 100644 --- a/PROMS/Volian.Controls.Library/StepTabRibbon.cs +++ b/PROMS/Volian.Controls.Library/StepTabRibbon.cs @@ -165,6 +165,8 @@ namespace Volian.Controls.Library } void MyFlexGrid_SelChange(object sender, EventArgs e) { + if (MyFlexGrid == null) + return; if (MyFlexGrid.Selection.c1 < 0 || MyFlexGrid.Selection.r1 < 0) return; if (MyFlexGrid.Selection.c1 >= MyFlexGrid.Cols.Count || MyFlexGrid.Selection.r1 >= MyFlexGrid.Rows.Count) @@ -276,7 +278,6 @@ namespace Volian.Controls.Library DevComponents.DotNetBar.ButtonItem btnCM4 = GetCMButton(sym); btnCM4.Click += new System.EventHandler(btnSym_Click); gc4.SubItems.Add(btnCM4); - } } @@ -291,7 +292,6 @@ namespace Volian.Controls.Library btnCM3.FontBold = true; return btnCM3; } - //void _MyStepRTB_ModeChange(object sender, StepRTBModeChangeEventArgs args) //{ // SetButtonAndMenuEnabling(true); diff --git a/PROMS/Volian.Controls.Library/VlnBorders.cs b/PROMS/Volian.Controls.Library/VlnBorders.cs index 3a2bdb3c..bc4737cb 100644 --- a/PROMS/Volian.Controls.Library/VlnBorders.cs +++ b/PROMS/Volian.Controls.Library/VlnBorders.cs @@ -189,6 +189,23 @@ namespace Volian.Controls.Library return 1; } } + public static int LineWidth0(GridLinePattern linePattern) + { + switch (linePattern) + { + case GridLinePattern.None: + return 0; + case GridLinePattern.Double: + case GridLinePattern.Thick: + return 3; + case GridLinePattern.Single: + case GridLinePattern.Dotted: + case GridLinePattern.Dashed: + case GridLinePattern.Mixed: + default: + return 1; + } + } public static Pen LinePen(GridLinePattern linePattern, Color foreColor) { Pen pn = new Pen(foreColor, 1); @@ -286,6 +303,7 @@ namespace Volian.Controls.Library for (int r = 0; r < newRows; r++) { int rSrc = r < row ? r : r > row + count ? r - count : row; + if (rSrc > Rows - 1) rSrc = Rows - 1; for (int c = 0; c < Columns; c++) { newLines[r * Columns + c] = Lines[rSrc * Columns + c]; diff --git a/PROMS/Volian.Controls.Library/VlnFlexGrid.cs b/PROMS/Volian.Controls.Library/VlnFlexGrid.cs index 6392c1ca..1fae52da 100644 --- a/PROMS/Volian.Controls.Library/VlnFlexGrid.cs +++ b/PROMS/Volian.Controls.Library/VlnFlexGrid.cs @@ -29,7 +29,6 @@ namespace Volian.Controls.Library { get { return _DefaultFixedBackgroundColor; } } - public void CopyToCopiedFlexGrid(GridCopyOption myCopyOption) { MyCopyInfo.MyCopiedFlexGrid = new VlnFlexGrid(); //make a copy of the grid being copied @@ -537,7 +536,7 @@ namespace Volian.Controls.Library private void SetupGrid(int numrows, int numcols) //C1FlexGrid NewGrid() { // setup the default size of each cell in the table/grid - this.Cols.DefaultSize = 40; + this.Cols.DefaultSize = (int) DPI; this.Rows.DefaultSize = 20; // setup the number of rows and columns @@ -771,125 +770,260 @@ namespace Volian.Controls.Library e.Handled = true; } } - + private static Color _BorderColor = Color.Black; + public static Color BorderColor + { + get { return VlnFlexGrid._BorderColor; } + set { VlnFlexGrid._BorderColor = value; } + } private void DrawCellBorder(C1.Win.C1FlexGrid.OwnerDrawCellEventArgs e) { - Graphics graphics =e.Graphics; + Graphics grGrid =e.Graphics; Rectangle bounds = e.Bounds; int row = e.Row; int col = e.Col; CellRange cr = GetMergedRange(row, col); - GridLinePattern lineTop = MyBorders.HorizontalLines[cr.r1,cr.c1]; - GridLinePattern lineLeft = MyBorders.VerticalLines[cr.r1, cr.c1]; - GridLinePattern lineBottom = MyBorders.HorizontalLines[cr.r2+1, cr.c2]; - GridLinePattern lineRight = MyBorders.VerticalLines[cr.r2, cr.c2+1]; + GridLinePattern topSide = MyBorders.HorizontalLines[cr.r1,cr.c1]; + GridLinePattern rightOfTopSide = cr.c2 == Cols.Count - 1 ? GridLinePattern.None : MyBorders.HorizontalLines[cr.r1, cr.c2 + 1]; + GridLinePattern leftOfTopSide = cr.c1 == 0? GridLinePattern.None : MyBorders.HorizontalLines[cr.r1, cr.c1 - 1]; + GridLinePattern leftSide = MyBorders.VerticalLines[cr.r1, cr.c1]; + GridLinePattern aboveLeftSide = cr.r1 == 0 ? GridLinePattern.None : MyBorders.VerticalLines[cr.r1 - 1, cr.c1]; + GridLinePattern belowLeftSide = cr.r2 == Rows.Count - 1 ? GridLinePattern.None : MyBorders.VerticalLines[cr.r2 + 1, cr.c1]; + GridLinePattern bottomSide = MyBorders.HorizontalLines[cr.r2+1, cr.c2]; + GridLinePattern rightOfBottomSide = cr.c2 == Cols.Count - 1 ? GridLinePattern.None : MyBorders.HorizontalLines[cr.r2 + 1, cr.c2 + 1]; + GridLinePattern rightSide = MyBorders.VerticalLines[cr.r2, cr.c2+1]; + GridLinePattern belowRightSide = cr.r2 == Rows.Count - 1 ? GridLinePattern.None : MyBorders.VerticalLines[cr.r2 + 1, cr.c2 + 1]; + GridLinePattern none = GridLinePattern.None; int x1 = bounds.Left; int y1 = bounds.Top; int x2 = bounds.Right - 1; int y2 = bounds.Bottom - 1; - // We should look at the results of the following for Focus Style - Color bColor = Color.Blue; // Temporary - Set the border color to blue. - if ((e.Style ?? Styles.Normal).Name == "Focus") - { - if (lineRight == GridLinePattern.Thick || lineRight == GridLinePattern.Double) - lineRight = GridLinePattern.Single; - if (lineBottom == GridLinePattern.Thick || lineBottom == GridLinePattern.Double) - lineBottom = GridLinePattern.Single; - } GridItem myGridItem = Parent as GridItem; if (myGridItem == null) return; - if (row == 0 && lineTop != GridLinePattern.None) + if (row == 0 || col == 0) // Top or Left Edge - Draw on parent { - Pen pn = VlnBorders.LinePen(lineTop, bColor); - //GridLinePattern lineTopLeft = cr.c1 == 0 ? GridLinePattern.None : MyBorders.HorizontalLines[cr.r1, cr.c1 - 1]; - GridLinePattern lineTopRight = cr.c2 == Cols.Count - 1 ? GridLinePattern.None : MyBorders.HorizontalLines[cr.r1, cr.c2 + 1]; - int dxTop = col == 0 ? (lineLeft == GridLinePattern.Double || lineLeft == GridLinePattern.Thick ? -3 : -1) : 0; - int dx = col == 0 ? -1 : 0; using (Graphics grParent = myGridItem.CreateGraphics()) { - if (lineTop == GridLinePattern.Double)// cr.r2 == 0) + if (row == 0) { - int lengthAdjustBottom = lineRight == GridLinePattern.Double ? -2 : 0; - grParent.DrawLine(pn, x1 + Left + dxTop, y1 + Top - 3, x2 + Left, y1 + Top - 3); - grParent.DrawLine(pn, x1 + Left + dx, y1 + Top - 1, x2 + Left + lengthAdjustBottom, y1 + Top - 1); - //if (lineRight == GridLinePattern.Double && lineTopRight != GridLinePattern.Double) - if (lineRight != GridLinePattern.None && lineTopRight != GridLinePattern.Double) - grParent.DrawLine(VlnBorders.LinePen(lineRight,bColor), x2 + Left, y1 + Top - 3, x2 + Left, y1 + Top - 1); + if (col == 0) + { + // Draw the top left intersection + DrawIntersection(grParent, Left - 3, Top-1, none, topSide,leftSide, none); + } + // Draw the top right intersection + DrawIntersection(grParent, Left +x2 - 2, Top-1, none, rightOfTopSide,rightSide,topSide); + // Draw the top side on the parent + DrawLine(grParent, topSide, Left + x1, Top + y1 - 1, Left + x2-3, Top + y1 -1); } - else if(pn.Width < 2) - grParent.DrawLine(pn, x1 + Left + dxTop, y1 + Top - 1, x2 + Left, y1 + Top - 1); - else // Move line up and draw an extra pixel long to account for a bug in graphics - grParent.DrawLine(pn, x1 + Left + dxTop, y1 + Top - 2, x2 + Left + 1, y1 + Top - 2); - } - } - if (col == 0 && lineLeft != GridLinePattern.None) - { - Pen pn = VlnBorders.LinePen(lineLeft, bColor); - //GridLinePattern lineLeftAbove = cr.r1 == 0 ? GridLinePattern.None : MyBorders.VerticalLines[cr.r1 - 1, cr.c1]; - GridLinePattern lineLeftBelow = cr.r2 == Rows.Count - 1 ? GridLinePattern.None : MyBorders.VerticalLines[cr.r2 + 1, cr.c1]; - int dyLeft = row == 0 ? (lineLeft == GridLinePattern.Double || lineLeft == GridLinePattern.Thick ? -3 : -1) : 0; - int dy = row == 0 ? -1 : 0; - //GridItem myGridItem = Parent as GridItem; - using (Graphics grParent = myGridItem.CreateGraphics()) - { - if (lineLeft == GridLinePattern.Double)// cr.r2 == 0) + if (col == 0) { - int lengthAdjustRight = lineBottom == GridLinePattern.Double ? -2 : 0; - grParent.DrawLine(pn, x1 + Left - 3, y1 + Top + dyLeft, x1 + Left - 3, y2 + Top); - grParent.DrawLine(pn, x1 + Left - 1, y1 + Top + dy, x1 + Left - 1, y2 + Top + lengthAdjustRight); - if (lineBottom != GridLinePattern.None && lineLeftBelow != GridLinePattern.Double) - grParent.DrawLine(VlnBorders.LinePen(lineBottom, bColor), x1 + Left - 3, y2 + Top, x1 + Left - 1, y2 + Top); + // Draw the bottom left intersection + DrawIntersection(grParent, Left -3, Top + y2, leftSide,bottomSide,belowLeftSide,none); + // Draw the left side + DrawLine(grParent, leftSide, Left + x1 - 1, Top + y1, Left + x1 - 1, Top + y2-3); } - else if (pn.Width < 2) - grParent.DrawLine(pn, x1 + Left - 1, y1 + Top + dyLeft, x1 + Left - 1, y2 + Top); - else // Move line left and draw an extra pixel long to account for a bug in graphics - grParent.DrawLine(pn, x1 + Left - 2, y1 + Top + dyLeft, x1 + Left - 2, y2 + Top + 1); } } - //GridLinePattern lineBottomLeft = cr.c1 == 0 ? GridLinePattern.None : MyBorders.HorizontalLines[cr.r2 + 1, cr.c1 - 1]; - GridLinePattern lineBottomRight = cr.c2 == Cols.Count - 1 ? GridLinePattern.None : MyBorders.HorizontalLines[cr.r2 + 1, cr.c2 + 1]; - //GridLinePattern lineRightAbove = cr.r1 == 0 ? GridLinePattern.None : MyBorders.VerticalLines[cr.r1 - 1, cr.c2 + 1]; - GridLinePattern lineRightBelow = cr.r2 == Rows.Count - 1 ? GridLinePattern.None : MyBorders.VerticalLines[cr.r2 + 1, cr.c2 + 1]; - if (lineBottom != GridLinePattern.None) + // Draw the bottom right intersection + DrawIntersection(grGrid, x2 - 2, y2, rightSide, rightOfBottomSide, belowRightSide, bottomSide); + // Draw the bottom side + DrawLine(grGrid, bottomSide, x1, y2, x2-3, y2); + // Draw the right side + DrawLine(grGrid, rightSide, x2, y1, x2, y2-3); + } + private static void DrawLine(Graphics gr, GridLinePattern pattern, int x1, int y1, int x2, int y2) + { + if (pattern == GridLinePattern.None) return; + Pen pn = VlnBorders.LinePen(pattern, BorderColor); + DrawLine(gr, pn, pattern, x1, y1, x2, y2); + } + private static void DrawLine(Graphics gr, Pen pn, int x1, int y1, int x2, int y2) + { + DrawLine(gr, pn, GridLinePattern.Single, x1, y1, x2, y2); + } + private static void DrawLine(Graphics gr, Pen pn, GridLinePattern pattern, int x1, int y1, int x2, int y2) + { + int dx = 0; + int dy = 0; + int dblx = 0; + int dbly = 0; + int xThick = 0; + int yThick = 0; + if (x1 == x2) // Vertical Line { - Pen pn = VlnBorders.LinePen(lineBottom, bColor); - int rightWidth = lineRight == GridLinePattern.Double ? 3 : 0; //VlnBorders.LineWidth(lineRight); - int thickAdjust = 0; - if (lineBottom == GridLinePattern.Thick && lineRight == GridLinePattern.Double && lineBottomRight != GridLinePattern.Thick) - thickAdjust = -3; - if (lineBottom == GridLinePattern.Double) - { - int lengthAdjustTop = lineRight == GridLinePattern.Double ? -2 : 0; - int lengthAdjustBottom = lineRightBelow == GridLinePattern.Double ? -2 : 0; - graphics.DrawLine(pn, x1, y2 - 2, x2+lengthAdjustTop, y2 - 2); - graphics.DrawLine(pn, x1, y2, x2+lengthAdjustBottom, y2); - if (lineRight == GridLinePattern.Double && lineBottomRight == GridLinePattern.Double && lineRightBelow == GridLinePattern.Double) - graphics.DrawLine(pn, x2, y2, x2+1, y2); - } - else if(pn.Width < 2) // Bottom line is thin. Determine if intersecting with double: - graphics.DrawLine(pn, x1, y2, x2-rightWidth, y2); - else // Move line up and draw an extra pixel long to account for a bug in graphics - graphics.DrawLine(pn, x1, y2 - 1, x2 + 1 + thickAdjust, y2 - 1); + dx = (int) (-pn.Width / 2); + dblx = -2; + if (pn.Width > 2) + yThick = 1; } - if (lineRight != GridLinePattern.None) + else // Horizontal Line { - Pen pn = VlnBorders.LinePen(lineRight, bColor); - int bottomWidth = lineBottom == GridLinePattern.Double ? 3 : 0;//VlnBorders.LineWidth(lineBottom); - - int thickAdjust = 0; - if (lineRight == GridLinePattern.Thick && lineBottom == GridLinePattern.Double && lineRightBelow != GridLinePattern.Thick) - thickAdjust = -3; - if (lineRight == GridLinePattern.Double)// cr.r2 == 0) - { - int lengthAdjustLeft = lineBottom == GridLinePattern.Double ? -2 : 0; - int lengthAdjustRight = lineBottomRight == GridLinePattern.Double ? -2 : 0; - graphics.DrawLine(pn, x2 - 2, y1, x2 - 2, y2+lengthAdjustLeft); - graphics.DrawLine(pn, x2, y1, x2, y2+lengthAdjustRight); - } - else if (pn.Width < 2) - graphics.DrawLine(pn, x2, y1, x2, y2-bottomWidth); + dy = (int) (-pn.Width / 2); + dbly = -2; + if (pn.Width > 2) + xThick = 1; + } + gr.DrawLine(pn, x1 + dx, y1 + dy, x2 + dx + xThick, y2 + dy + yThick); + if(pattern == GridLinePattern.Double) + gr.DrawLine(pn, x1 + dx +dblx, y1 + dy + dbly, x2 + dx+dblx, y2 + dy+dbly); + } + private static void DrawIntersection(Graphics gr, int x, int y, GridLinePattern up, GridLinePattern right, GridLinePattern down, GridLinePattern left) + { + if (up == GridLinePattern.Double) + if (right == GridLinePattern.Double) + if (down == GridLinePattern.Double) + if (left == GridLinePattern.Double) DrawIntersectionAllDoubles(gr, x, y); + else DrawDrawIntersection3Doubles_URD(gr, x, y); + else // Down is not double + if (left == GridLinePattern.Double) DrawDrawIntersection3Doubles_URL(gr, x, y); + else DrawDrawIntersection2Doubles_UR(gr, x, y, down, left); + else // right is not double + if (down == GridLinePattern.Double) + if (left == GridLinePattern.Double) DrawDrawIntersection3Doubles_UDL(gr, x, y); + else DrawDrawIntersection2Doubles_UD(gr, x, y, right, left); + else // Down is not double + if (left == GridLinePattern.Double) DrawIntersection2Doubles_UL(gr, x, y, right, down); + else DrawIntersectionOneDoubleOrLess(gr, x, y, up, right, down, left); + else + if (right == GridLinePattern.Double) + if (down == GridLinePattern.Double) + if (left == GridLinePattern.Double) DrawDrawIntersection3Doubles_RDL(gr, x, y); + else DrawDrawIntersection2Doubles_RD(gr, x, y, up, left); + else // Down is not double + if (left == GridLinePattern.Double) DrawDrawIntersection2Doubles_RL(gr, x, y, up, down); + else DrawIntersectionOneDoubleOrLess(gr, x, y, up, right, down, left); else - graphics.DrawLine(pn, x2 - 1, y1, x2 - 1, y2 + 1 + thickAdjust); + if (down == GridLinePattern.Double) + if (left == GridLinePattern.Double) DrawDrawIntersection2Doubles_DL(gr, x, y, up, right); + else DrawIntersectionOneDoubleOrLess(gr, x, y, up, right, down, left); + else // These both use the same function with the same parameters + if (left == GridLinePattern.Double) DrawIntersectionOneDoubleOrLess(gr, x, y, up, right, down, left); + else DrawIntersectionOneDoubleOrLess(gr, x, y, up, right, down, left); + } + private static Pen pnDouble = VlnBorders.LinePen(GridLinePattern.Double, BorderColor); + private static Pen pnThick = VlnBorders.LinePen(GridLinePattern.Thick, BorderColor); + private static void DrawIntersectionAllDoubles(Graphics gr, int x, int y) + { + DrawLine(gr, pnDouble, x-1, y, x, y); + DrawLine(gr, pnDouble, x, y - 2, x, y - 3); + DrawLine(gr, pnDouble, x + 2, y - 2, x + 3, y - 2); + DrawLine(gr, pnDouble, x + 2, y, x + 2, y + 1); + } + private static void DrawDrawIntersection3Doubles_URD(Graphics gr, int x, int y) + { + DrawLine(gr, pnDouble, x , y, x, y - 3); + DrawLine(gr, pnDouble, x + 2, y - 2, x + 3, y - 2); + DrawLine(gr, pnDouble, x + 2, y, x + 2, y + 1); + } + private static void DrawDrawIntersection3Doubles_URL(Graphics gr, int x, int y) + { + DrawLine(gr, pnDouble, x, y, x + 2, y); + DrawLine(gr, pnDouble, x -1, y - 2, x , y - 2); + DrawLine(gr, pnDouble, x + 2, y - 2, x + 3, y - 2); + } + private static void DrawDrawIntersection3Doubles_UDL(Graphics gr, int x, int y) + { + DrawLine(gr, pnDouble, x-1, y, x, y); + DrawLine(gr, pnDouble, x , y - 2, x , y - 3); + DrawLine(gr, pnDouble, x + 2, y-3, x + 2, y); + } + private static void DrawDrawIntersection3Doubles_RDL(Graphics gr, int x, int y) + { + DrawLine(gr, pnDouble, x-1, y, x, y); + DrawLine(gr, pnDouble, x, y - 2, x + 2, y - 2); + DrawLine(gr, pnDouble, x + 2, y, x + 2, y + 1); + } + private static void DrawDrawIntersection2Doubles_UR(Graphics gr, int x, int y, GridLinePattern lp1, GridLinePattern lp2) + { + if (lp1 == GridLinePattern.Thick && lp2 == GridLinePattern.Thick) + DrawLine(gr, pnThick, x, y, x + 3, y); + else + { + DrawLine(gr, pnDouble, x, y, x + 2, y); + DrawLine(gr, pnDouble, x , y, x , y - 2); + DrawLine(gr, pnDouble, x + 2, y - 2, x + 3, y - 2); + } + } + private static void DrawDrawIntersection2Doubles_UD(Graphics gr, int x, int y, GridLinePattern lp1, GridLinePattern lp2) + { + if (lp1 == GridLinePattern.Thick && lp2 == GridLinePattern.Thick) + DrawLine(gr, pnThick, x, y, x + 3, y); + else + { + DrawLine(gr, pnDouble, x, y, x, y - 2); + DrawLine(gr, pnDouble, x + 2, y, x + 2, y - 2); + } + } + private static void DrawIntersection2Doubles_UL(Graphics gr, int x, int y, GridLinePattern lp1, GridLinePattern lp2) + { + if (lp1 == GridLinePattern.Thick && lp2 == GridLinePattern.Thick) + DrawLine(gr, pnThick, x, y, x + 3, y); + else + { + DrawLine(gr, pnDouble, x, y, x + 2, y); + DrawLine(gr, pnDouble, x , y - 2, x, y - 3); + DrawLine(gr, pnDouble, x + 2, y, x + 2, y - 2); + } + } + private static void DrawDrawIntersection2Doubles_RD(Graphics gr, int x, int y, GridLinePattern lp1, GridLinePattern lp2) + { + if (lp1 == GridLinePattern.Thick && lp2 == GridLinePattern.Thick) + DrawLine(gr, pnThick, x, y, x + 3, y); + else + { + DrawLine(gr, pnDouble, x, y, x, y - 2); + DrawLine(gr, pnDouble, x, y - 2, x + 2, y - 2); + DrawLine(gr, pnDouble, x + 2, y, x + 2, y + 1); + } + } + private static void DrawDrawIntersection2Doubles_RL(Graphics gr, int x, int y, GridLinePattern lp1, GridLinePattern lp2) + { + if (lp1 == GridLinePattern.Thick && lp2 == GridLinePattern.Thick) + DrawLine(gr, pnThick, x, y, x + 2, y); + else + { + DrawLine(gr, pnDouble, x, y, x + 2, y); + DrawLine(gr, pnDouble, x, y - 2, x + 2, y - 2); + } + } + private static void DrawDrawIntersection2Doubles_DL(Graphics gr, int x, int y, GridLinePattern lp1, GridLinePattern lp2) + { + if (lp1 == GridLinePattern.Thick && lp2 == GridLinePattern.Thick) + DrawLine(gr, pnThick, x, y, x + 2, y); + else + { + DrawLine(gr, pnDouble, x-1, y, x, y); + DrawLine(gr, pnDouble, x, y - 2, x + 2, y - 2); + DrawLine(gr, pnDouble, x + 2, y, x + 2, y - 2); + } + } + private static void DrawIntersectionOneDoubleOrLess(Graphics gr, int x, int y, + GridLinePattern up, GridLinePattern right, GridLinePattern down, GridLinePattern left) + { + Pen pnUp = VlnBorders.LinePen(up, BorderColor); + Pen pnLeft = VlnBorders.LinePen(left, BorderColor); + int widthUpDown = Math.Max(VlnBorders.LineWidth0(up), VlnBorders.LineWidth0(down)); + int heightLeftRight = Math.Max(VlnBorders.LineWidth0(left), VlnBorders.LineWidth0(right)); + if (heightLeftRight > 0 && widthUpDown > 0) + { + Pen pn = new Pen(BorderColor, widthUpDown); + if(heightLeftRight > 1) + DrawLine(gr, pn, x + 2, y + 1 - heightLeftRight, x + 2, y); + else if(up == GridLinePattern.None) // Work around to set a pixel (actually set two) + DrawLine(gr, pn, x + 2, y, x + 2, y + 1); + } + if (left != GridLinePattern.None) + { + DrawLine(gr, pnLeft, x, y, x + 2 - widthUpDown, y); + if (left == GridLinePattern.Double) + DrawLine(gr, pnLeft, x, y - 2, x + 2 - widthUpDown, y - 2); + } + if (up != GridLinePattern.None) + { + DrawLine(gr, pnUp, x + 2, y - 3 , x + 2, y +1 - heightLeftRight); + if (up == GridLinePattern.Double) + DrawLine(gr, pnUp, x, y - 3, x, y +1 - heightLeftRight); } } #endregion //Grid Initialize diff --git a/PROMS/Volian.Print.Library/Grid2Pdf.cs b/PROMS/Volian.Print.Library/Grid2Pdf.cs index 77448b8a..ca3c401a 100644 --- a/PROMS/Volian.Print.Library/Grid2Pdf.cs +++ b/PROMS/Volian.Print.Library/Grid2Pdf.cs @@ -124,12 +124,12 @@ namespace Volian.Print.Library } public void ToPdf(iTextSharp.text.pdf.ColumnText myColumnText, float left, float top) { - ZoomGrid(myColumnText, left, top); + //ZoomGrid(myColumnText, left, top); MyCells.ToPdf(myColumnText, left, top); } private void ZoomGrid(iTextSharp.text.pdf.ColumnText myColumnText, float left, float top) { - PdfDestination dest = new PdfDestination(PdfDestination.FITR, left - 4, top + 4 - Height, left + Width, top + 4); + PdfDestination dest = new PdfDestination(PdfDestination.FITR, left - 4, top - Height - 4, left + Width, top + 4); myColumnText.Canvas.SetAction(PdfAction.GotoLocalPage(myColumnText.Canvas.PdfWriter.CurrentPageNumber, dest, myColumnText.Canvas.PdfWriter), left, top - Height, left + Width, top); } #endregion @@ -192,14 +192,14 @@ namespace Volian.Print.Library else myRTB.Text = str; myRTB.SelectAll(); - myRTB.SelectionColor = System.Drawing.Color.Black; + myRTB.SelectionColor = PrintOverride.OverrideTextColor(System.Drawing.Color.Black); str = myRTB.Rtf; } iTextSharp.text.Paragraph myPara = RtfToParagraph(str); myColumnText1.SetSimpleColumn(0, 0, w - 2, MyContentByte.PdfDocument.PageSize.Top); // Padding = 4 myPara.MultipliedLeading = 1.2F; myColumnText1.AddElement(myPara); - //myColumnText1.Canvas.SetColorFill(iTextSharp.text.BaseColor.RED); + //myColumnText1.Canvas.SetColorFill(PrintOverride.OverrideTextColor(System.Drawing.Color.Black)); float posBefore = myColumnText1.YLine; int status = myColumnText1.Go(true); float posAfter = myColumnText1.YLine; @@ -606,7 +606,7 @@ namespace Volian.Print.Library { PdfContentByte cb = myColumnText.Canvas; cb.SaveState();// Save state before drawing borders - SetOpacity(cb, .7F); // This line makes the borders transparent for testing + //SetOpacity(cb, .7F); // This line makes the borders transparent for testing float xLeft = left + x + XOffset; float yTop = top - y + YOffset; float xRight = left + x + w + XOffset; @@ -630,30 +630,31 @@ namespace Volian.Print.Library { if (LinePattern != GridLinePattern.None) { + float direction = (xStart < xEnd) ? 1 : -1; InitializeLineStyle(cb); SetLineColor(cb, r1, c1, side); if (LinePattern == GridLinePattern.Double) { // Top Line - float dStart = -DoubleIntersectionRight(startToLeft, startToRight, startAhead); - float dEnd = DoubleIntersectionLeft(endToLeft, endToRight, endAhead); + float dStart = -direction * DoubleIntersectionRight(startToLeft, startToRight, startAhead); + float dEnd = direction * DoubleIntersectionLeft(endToLeft, endToRight, endAhead); DrawLine(cb, LineThicknessForDouble, xStart + dStart, y + DoubleLineOffset, xEnd + dEnd, y + DoubleLineOffset); // Bottom Line - dStart = -DoubleIntersectionLeft(startToLeft, startToRight, startAhead); - dEnd = DoubleIntersectionRight(endToLeft, endToRight, endAhead); + dStart = -direction * DoubleIntersectionLeft(startToLeft, startToRight, startAhead); + dEnd = direction * DoubleIntersectionRight(endToLeft, endToRight, endAhead); DrawLine(cb, LineThicknessForDouble, xStart + dStart, y - DoubleLineOffset, xEnd + dEnd, y - DoubleLineOffset); } else if (LinePattern != GridLinePattern.Thick) { SetLinePattern(cb, LinePattern); - float dStart = -ThinIntersection(startToLeft, startToRight, startAhead); - float dEnd = ThinIntersection(endToLeft, endToRight, endAhead); + float dStart = -direction * ThinIntersection(startToLeft, startToRight, startAhead); + float dEnd = direction * ThinIntersection(endToLeft, endToRight, endAhead); DrawLine(cb, LineThicknessForThin, xStart + dStart, y, xEnd + dEnd, y); } else { - float dStart = -ThickIntersection(startToLeft, startToRight, startAhead); - float dEnd = ThickIntersection(endToLeft, endToRight, endAhead); + float dStart = -direction * ThickIntersection(startToLeft, startToRight, startAhead); + float dEnd = direction * ThickIntersection(endToLeft, endToRight, endAhead); DrawLine(cb, LineThicknessForThick, xStart + dStart, y, xEnd + dEnd, y); } cb.Stroke(); @@ -665,30 +666,31 @@ namespace Volian.Print.Library { if (LinePattern != GridLinePattern.None) { + float direction = (yStart < yEnd) ? 1 : -1; InitializeLineStyle(cb); SetLineColor(cb, r1, c1, side); if (LinePattern == GridLinePattern.Double) { //Left Line - float dStart = -DoubleIntersectionRight(startToLeft, startToRight, startAhead); - float dEnd = DoubleIntersectionLeft(endToLeft, endToRight, endAhead); + float dStart = -direction * DoubleIntersectionRight(startToLeft, startToRight, startAhead); + float dEnd = direction * DoubleIntersectionLeft(endToLeft, endToRight, endAhead); DrawLine(cb, LineThicknessForDouble, x - DoubleLineOffset, yStart + dStart, x - DoubleLineOffset, yEnd + dEnd); //Right Line - dStart = -DoubleIntersectionLeft(startToLeft, startToRight, startAhead); - dEnd = DoubleIntersectionRight(endToLeft, endToRight, endAhead); + dStart = -direction * DoubleIntersectionLeft(startToLeft, startToRight, startAhead); + dEnd = direction * DoubleIntersectionRight(endToLeft, endToRight, endAhead); DrawLine(cb, LineThicknessForDouble, x + DoubleLineOffset, yStart + dStart, x + DoubleLineOffset, yEnd + dEnd); } else if (LinePattern != GridLinePattern.Thick) { SetLinePattern(cb, LinePattern); - float dStart = -ThinIntersection(startToLeft, startToRight, startAhead); - float dEnd = ThinIntersection(endToLeft, endToRight, endAhead); + float dStart = -direction * ThinIntersection(startToLeft, startToRight, startAhead); + float dEnd = direction * ThinIntersection(endToLeft, endToRight, endAhead); DrawLine(cb, LineThicknessForThin, x, yStart + dStart, x, yEnd + dEnd); } else { - float dStart = -ThickIntersection(startToLeft, startToRight, startAhead); - float dEnd = ThickIntersection(endToLeft, endToRight, endAhead); + float dStart = -direction * ThickIntersection(startToLeft, startToRight, startAhead); + float dEnd = direction * ThickIntersection(endToLeft, endToRight, endAhead); DrawLine(cb, LineThicknessForThick, x, yStart + dStart, x, yEnd + dEnd); } cb.Stroke(); @@ -731,7 +733,6 @@ namespace Volian.Print.Library | Line Being Drawn - Case 4: Line being drawn down: Line Begin Drawn @@ -791,9 +792,14 @@ namespace Volian.Print.Library if (lineAhead == GridLinePattern.Thick) return ThickOverDouble; return -ThickUnderDouble; } - if (lineToLeft == GridLinePattern.Double || lineToRight == GridLinePattern.Double) + if ( lineToLeft == GridLinePattern.Double || lineToRight == GridLinePattern.Double) { - if (lineAhead == GridLinePattern.Double) return -ThickUnderDouble; + if (lineAhead == GridLinePattern.Double) + { + if (lineToLeft == GridLinePattern.Thick || lineToRight == GridLinePattern.Thick) + return ThickOverDouble; + return -ThickUnderDouble; + } return ThickOverDouble; } if (VlnBorders.LineWidth(lineToLeft) == 1 && VlnBorders.LineWidth(lineToRight) == 1) @@ -821,25 +827,25 @@ namespace Volian.Print.Library private static void SetLineColor(PdfContentByte cb, int row, int col, string side) { iTextSharp.text.Color lineColor = new iTextSharp.text.Color(PrintOverride.OverrideTextColor(System.Drawing.Color.Black)); - switch (side) - { - case "Top": - if (col == 0) lineColor = new iTextSharp.text.Color(PrintOverride.OverrideTextColor(System.Drawing.Color.Blue)); - else lineColor = new iTextSharp.text.Color(PrintOverride.OverrideTextColor(System.Drawing.Color.Cyan)); - break; - case "Left": - if (row == 0) lineColor = new iTextSharp.text.Color(PrintOverride.OverrideTextColor(System.Drawing.Color.Red)); - else lineColor = new iTextSharp.text.Color(PrintOverride.OverrideTextColor(System.Drawing.Color.Magenta)); - break; - case "Bottom": - if (col == 0) lineColor = new iTextSharp.text.Color(PrintOverride.OverrideTextColor(System.Drawing.Color.Green)); - else lineColor = new iTextSharp.text.Color(PrintOverride.OverrideTextColor(System.Drawing.Color.Cyan)); - break; - case "Right": - if (row == 0) lineColor = new iTextSharp.text.Color(PrintOverride.OverrideTextColor(System.Drawing.Color.Orange)); - else lineColor = new iTextSharp.text.Color(PrintOverride.OverrideTextColor(System.Drawing.Color.Magenta)); - break; - } + //switch (side) + //{ + // case "Top": + // if (col == 0) lineColor = new iTextSharp.text.Color(PrintOverride.OverrideTextColor(System.Drawing.Color.Blue)); + // else lineColor = new iTextSharp.text.Color(PrintOverride.OverrideTextColor(System.Drawing.Color.Cyan)); + // break; + // case "Left": + // if (row == 0) lineColor = new iTextSharp.text.Color(PrintOverride.OverrideTextColor(System.Drawing.Color.Red)); + // else lineColor = new iTextSharp.text.Color(PrintOverride.OverrideTextColor(System.Drawing.Color.Magenta)); + // break; + // case "Bottom": + // if (col == 0) lineColor = new iTextSharp.text.Color(PrintOverride.OverrideTextColor(System.Drawing.Color.Green)); + // else lineColor = new iTextSharp.text.Color(PrintOverride.OverrideTextColor(System.Drawing.Color.Cyan)); + // break; + // case "Right": + // if (row == 0) lineColor = new iTextSharp.text.Color(PrintOverride.OverrideTextColor(System.Drawing.Color.Orange)); + // else lineColor = new iTextSharp.text.Color(PrintOverride.OverrideTextColor(System.Drawing.Color.Magenta)); + // break; + //} cb.SetColorStroke(lineColor); } private static void InitializeLineStyle(PdfContentByte cb) @@ -857,7 +863,7 @@ namespace Volian.Print.Library } private static void ZoomToCell(iTextSharp.text.pdf.ColumnText myColumnText, float xLeft, float yTop, float xRight, float yBottom) { - PdfDestination dest = new PdfDestination(PdfDestination.FITR, xLeft - 4, yBottom + 4, xRight, yTop + 4); + PdfDestination dest = new PdfDestination(PdfDestination.FITR, xLeft - 4, yBottom , xRight, yTop + 4); myColumnText.Canvas.SetAction(PdfAction.GotoLocalPage(myColumnText.Canvas.PdfWriter.CurrentPageNumber, dest, myColumnText.Canvas.PdfWriter), xLeft, yBottom, xRight, yTop); } #endregion