diff --git a/PROMS/VEPROMS User Interface/frmSectionProperties.Designer.cs b/PROMS/VEPROMS User Interface/frmSectionProperties.Designer.cs index 446d3b14..895c501e 100644 --- a/PROMS/VEPROMS User Interface/frmSectionProperties.Designer.cs +++ b/PROMS/VEPROMS User Interface/frmSectionProperties.Designer.cs @@ -987,7 +987,7 @@ namespace VEPROMS this.cbKeepWordDocMargins.Name = "cbKeepWordDocMargins"; this.cbKeepWordDocMargins.Size = new System.Drawing.Size(223, 21); this.cbKeepWordDocMargins.TabIndex = 59; - this.cbKeepWordDocMargins.Text = "Keep Word Document Margins"; + this.cbKeepWordDocMargins.Text = "Keep Word Document Margins (and Page Size)"; this.cbKeepWordDocMargins.UseVisualStyleBackColor = false; this.cbKeepWordDocMargins.Visible = false; this.cbKeepWordDocMargins.CheckedChanged += new System.EventHandler(this.cbKeepWordDocMargins_CheckedChanged); diff --git a/PROMS/VEPROMS.CSLA.Library/Extension/DocumentExt.cs b/PROMS/VEPROMS.CSLA.Library/Extension/DocumentExt.cs index 4502d676..7be91644 100644 --- a/PROMS/VEPROMS.CSLA.Library/Extension/DocumentExt.cs +++ b/PROMS/VEPROMS.CSLA.Library/Extension/DocumentExt.cs @@ -720,6 +720,8 @@ namespace VEPROMS.CSLA.Library } } LBDocumentClass myDoc = MyApp.Documents.Open(myFile.FullName, false); + //MyApp.Visible = true; + bool adjustMargins = true; // Use positions relative to margins try { SectionConfig sc = sect.ActiveSection.MyConfig as SectionConfig; @@ -727,6 +729,8 @@ namespace VEPROMS.CSLA.Library { AdjustMargins(myDocStyle, myDoc, true); } + else + adjustMargins = false; // Use absolute positions } catch (Exception ex) { @@ -754,11 +758,14 @@ namespace VEPROMS.CSLA.Library // Setting the selected text to "" actually sets it to "\r", thus cnt-- (subtract one // from cnt since there's already a return in the string. cnt--; - float x = (float)selxy.get_Information(LBWdInformation.wdHorizontalPositionRelativeToPage); - float y = (float)selxy.get_Information(LBWdInformation.wdVerticalPositionRelativeToPage); + float x = adjustMargins ? (float)selxy.get_Information(LBWdInformation.wdHorizontalPositionRelativeToTextBoundary) : + (float)selxy.get_Information(LBWdInformation.wdHorizontalPositionRelativeToPage); + float y = adjustMargins ? (float)selxy.get_Information(LBWdInformation.wdVerticalPositionRelativeToTextBoundary) : + (float)selxy.get_Information(LBWdInformation.wdVerticalPositionRelativeToPage); LBRange myRange = selxy.Paragraphs.First.Range; - float yTop = (float)myRange.get_Information(LBWdInformation.wdVerticalPositionRelativeToPage); - float yTop1 = (float)myRange.get_Information(LBWdInformation.wdVerticalPositionRelativeToTextBoundary); + float yTop = adjustMargins ?(float)myRange.get_Information(LBWdInformation.wdVerticalPositionRelativeToTextBoundary) : + (float)myRange.get_Information(LBWdInformation.wdVerticalPositionRelativeToPage); + //float yTop1 = (float)myRange.get_Information(LBWdInformation.wdVerticalPositionRelativeToTextBoundary); // some data had regular text embedded in the xyplot definition. If so, the plain text must // be left in the file. Otherwise, we can replace with empty text. @@ -781,7 +788,7 @@ namespace VEPROMS.CSLA.Library filecount++; RectangleF plotRect = CreatePlot(pngFile, xyplot, 600F, FormForPlotGraphics); - float xAdjust = (float)-sect.MyDocStyle.Layout.LeftMargin; + float xAdjust = 0; //(float)-sect.MyDocStyle.Layout.LeftMargin; float yAdjust = selxy.Font.Size; LBShape shape = myDoc.Shapes.AddPicture(pngFile, x + xAdjust + plotRect.X, yAdjust + y - yTop + plotRect.Y, selxy.Range); File.Delete(pngFile); @@ -845,15 +852,25 @@ namespace VEPROMS.CSLA.Library float width = 72 * Int32.Parse(vals[3], System.Globalization.NumberStyles.AllowHexSpecifier) / 12.0F; int lines = Int32.Parse(vals[2], System.Globalization.NumberStyles.AllowHexSpecifier); float height = 72 * lines / 6.0F; - float x = (float)sel.get_Information(LBWdInformation.wdHorizontalPositionRelativeToTextBoundary); + float x = adjustMargins ? (float)sel.get_Information(LBWdInformation.wdHorizontalPositionRelativeToTextBoundary): + (float)sel.get_Information(LBWdInformation.wdHorizontalPositionRelativeToPage); // 9.25 is the approximate offset of the base line of the font, i.e. doesn't include descender. - float locvertpage = (float)sel.get_Information(LBWdInformation.wdVerticalPositionRelativeToPage); + float locvertpage = adjustMargins ? (float)sel.get_Information(LBWdInformation.wdVerticalPositionRelativeToTextBoundary) : + (float)sel.get_Information(LBWdInformation.wdVerticalPositionRelativeToPage); float y = locvertpage + ((sel.Font.Size * 9.25F) / 12); sel.Text = ""; LBShape shape = myDoc.Shapes.AddPicture(roImageFile.MyFile.FullName, x, y, sel.Range); - shape.RelativeVerticalPosition = LBWdRelativeVerticalPosition.wdRelativeVerticalPositionPage; + if (adjustMargins) + { + shape.RelativeVerticalPosition = LBWdRelativeVerticalPosition.wdRelativeVerticalPositionMargin; + shape.RelativeHorizontalPosition = LBWdRelativeHorizontalPosition.wdRelativeHorizontalPositionMargin;// .wdRelativeHorizontalPositionMargin; + } + else + { + shape.RelativeVerticalPosition = LBWdRelativeVerticalPosition.wdRelativeVerticalPositionPage; + shape.RelativeHorizontalPosition = LBWdRelativeHorizontalPosition.wdRelativeHorizontalPositionPage;// .wdRelativeHorizontalPositionMargin; + } shape.Top = y; // Reset value after setting flag RelativeVerticalPosition - shape.RelativeHorizontalPosition = LBWdRelativeHorizontalPosition.wdRelativeHorizontalPositionMargin; shape.Left = x; shape.Width = width; shape.Height = height; @@ -880,9 +897,10 @@ namespace VEPROMS.CSLA.Library //_MyLog.WarnFormat("PNG Name = {0}, size = {1}", fi.Name, fi.Length); //LBShape shape = myDoc.Shapes.AddPicture(@"C:\Temp\XYPlot.png", 0, 0, sel.Range); - float x = (float)sel.get_Information(LBWdInformation.wdHorizontalPositionRelativeToPage); - - float y = (float)sel.get_Information(LBWdInformation.wdVerticalPositionRelativeToPage); + float x = adjustMargins ? (float)sel.get_Information(LBWdInformation.wdHorizontalPositionRelativeToTextBoundary) : + (float)sel.get_Information(LBWdInformation.wdHorizontalPositionRelativeToPage); + float y = adjustMargins ? (float)sel.get_Information(LBWdInformation.wdVerticalPositionRelativeToTextBoundary): + (float)sel.get_Information(LBWdInformation.wdVerticalPositionRelativeToPage); // if there is regular text before the plot, then count the number of lines // and adjust the y position accordingly int idx = sel.Text.IndexOf("\r"); @@ -893,9 +911,9 @@ namespace VEPROMS.CSLA.Library } //LBInlineShape shape = sel.InlineShapes.AddPicture(pngFile); LBRange myRange = sel.Paragraphs.First.Range; - float yTop = (float)myRange.get_Information(LBWdInformation.wdVerticalPositionRelativeToPage); - float yTop1 = (float)myRange.get_Information(LBWdInformation.wdVerticalPositionRelativeToTextBoundary); - float xAdjust = (float)-sect.MyDocStyle.Layout.LeftMargin; + float yTop = adjustMargins ? (float)myRange.get_Information(LBWdInformation.wdVerticalPositionRelativeToTextBoundary) : + (float)myRange.get_Information(LBWdInformation.wdVerticalPositionRelativeToPage); + float xAdjust = 0;// = (float)-sect.MyDocStyle.Layout.LeftMargin; float yAdjust = sel.Font.Size; // The following two lines made the xyplot location for WCN2 match the 16bit output. However, how the // xTweak value is determined is phantom of Rich's mind. Word document location of the RO token @@ -904,6 +922,20 @@ namespace VEPROMS.CSLA.Library //LBShape shape = myDoc.Shapes.AddPicture(pngFile, x + xAdjust + plotRect.X + xTweak, yAdjust + y - yTop + plotRect.Y, sel.Range); LBShape shape = myDoc.Shapes.AddPicture(pngFile, x + xAdjust + plotRect.X, yAdjust + y - yTop + plotRect.Y, sel.Range); File.Delete(pngFile); + //shape.RelativeHorizontalPosition = LBWdRelativeHorizontalPosition.wdRelativeHorizontalPositionPage;// .wdRelativeHorizontalPositionMargin; + if (adjustMargins) + { + shape.RelativeVerticalPosition = LBWdRelativeVerticalPosition.wdRelativeVerticalPositionMargin; + shape.RelativeHorizontalPosition = LBWdRelativeHorizontalPosition.wdRelativeHorizontalPositionMargin;// .wdRelativeHorizontalPositionMargin; + } + else + { + shape.RelativeVerticalPosition = LBWdRelativeVerticalPosition.wdRelativeVerticalPositionPage; + shape.RelativeHorizontalPosition = LBWdRelativeHorizontalPosition.wdRelativeHorizontalPositionPage;// .wdRelativeHorizontalPositionMargin; + } + shape.Left = x + xAdjust + plotRect.X; + //shape.Top = yAdjust + y - yTop + plotRect.Y; + shape.Top = yAdjust + y + plotRect.Y; shape.LockAspectRatio = LBMsoTriState.msoTrue; //shape.Width = .89F * shape.Width; //shape.Width = float.Parse(tbAdjust.Text) * shape.Width; @@ -933,7 +965,7 @@ namespace VEPROMS.CSLA.Library } //AddInfo("\tRO Found {0} = '{1}'", sel.Text, val); // if val is null, then InsertROValue will put in "RO Not Found" for the value - float indent = (float)sel.get_Information(LBWdInformation.wdHorizontalPositionRelativeToPage) - (float)sect.MyDocStyle.Layout.LeftMargin;; + float indent = (float)sel.get_Information(LBWdInformation.wdHorizontalPositionRelativeToTextBoundary); InsertROValue(sel, val, sect.ActiveFormat.PlantFormat.FormatData.ROData.UpRoIfPrevUpper, indent); } sel = FindRO(); @@ -1060,7 +1092,17 @@ namespace VEPROMS.CSLA.Library { if (val.IndexOf("_") == -1) // Is some of the text underlined? { - sel.Text = val; // nothing is underlined, use text as is + if (val.Contains("\r\n")) + { + int ind = val.IndexOf("\r\n"); + sel.TypeText(val.Substring(1, ind + 2)); + sel.Text = val.Substring(ind + 2); + sel.ParagraphFormat.LeftIndent = indent; + } + else + { + sel.Text = val; // nothing is underlined, use text as is + } return; } // Back in the DOS days, an underbar was used to toggle underlining on/off