This commit is contained in:
		| @@ -2,6 +2,7 @@ using System; | ||||
| using System.Collections.Generic; | ||||
| using System.Text; | ||||
| using System.ComponentModel; | ||||
| using System.Drawing; | ||||
|  | ||||
| namespace VEPROMS.CSLA.Library | ||||
| { | ||||
| @@ -82,6 +83,32 @@ namespace VEPROMS.CSLA.Library | ||||
| 				OnPropertyChanged("Printing_Length"); | ||||
| 			} | ||||
| 		} | ||||
| 		[Category("Printing")] | ||||
| 		[DisplayName("Color")] | ||||
| 		[Description("Color of Document Text")] | ||||
| 		public Color Printing_Color | ||||
| 		{ | ||||
| 			get | ||||
| 			{ | ||||
| 				string sColor = _Xp["Printing", "Color"]; | ||||
| 				if (sColor == string.Empty) sColor = "Transparent"; | ||||
| 				if (sColor[0] == '[') | ||||
| 				{ | ||||
| 					string[] parts = sColor.Substring(1, sColor.Length - 2).Split(",".ToCharArray()); | ||||
| 					return Color.FromArgb(Int32.Parse(parts[0]), Int32.Parse(parts[1]), Int32.Parse(parts[2])); | ||||
| 				} | ||||
| 				else return Color.FromName(sColor); | ||||
| 			} | ||||
| 			set | ||||
| 			{ | ||||
| 				if (value.IsNamedColor) _Xp["Printing", "Color"] = value.Name; | ||||
| 				else | ||||
| 				{ | ||||
| 					_Xp["Printing", "Color"] = string.Format("[{0},{1},{2}]", value.R, value.G, value.B); | ||||
| 				} | ||||
| 				OnPropertyChanged("Printing_Color"); | ||||
| 			} | ||||
| 		} | ||||
| 		#endregion | ||||
| 		#region ToString | ||||
| 		public override string ToString() | ||||
|   | ||||
| @@ -3,6 +3,7 @@ using System.Collections.Generic; | ||||
| using System.Collections.Specialized; | ||||
| using System.Text; | ||||
| using System.ComponentModel; | ||||
| using System.Text.RegularExpressions; | ||||
|  | ||||
| namespace VEPROMS.CSLA.Library | ||||
| { | ||||
| @@ -774,5 +775,30 @@ namespace VEPROMS.CSLA.Library | ||||
| 			} | ||||
| 		} | ||||
| 	#endregion | ||||
| 		#region FortranFormat | ||||
| 		public static string ConvertFortranFormatToScienctificNotation(string str) | ||||
| 		{ | ||||
| 			// Convert E style numbers to RTF with \super and \nosupersub | ||||
| 			string retval = Regex.Replace(str, "([+-]?)([0-9]+)[.]([0-9]*?)0*E([+-]?[0-9]+)", new MatchEvaluator(FixFortranNumber)); | ||||
| 			//retval = Regex.Replace(retval, "[#](.*?)[#]", "\\super $1\\nosupersub ");// DOS Superscript | ||||
| 			//retval = Regex.Replace(retval, "[~](.*?)[~]", "\\sub $1\\nosupersub ");// DOS Subscript | ||||
| 			retval = Regex.Replace(retval, "[#](.*?)[#]", "\\up3 $1\\up0 ");// DOS Superscript | ||||
| 			retval = Regex.Replace(retval, "[~](.*?)[~]", "\\dn3 $1\\dn0 ");// DOS Subscript | ||||
| 			return retval; | ||||
| 		} | ||||
| 		private static string FixFortranNumber(Match match) | ||||
| 		{ | ||||
| 			StringBuilder sb = new StringBuilder(match.Groups[1].Value); | ||||
| 			if (match.Groups[3].Length == 0) // Nothing to the right of the decimal | ||||
| 				if (match.Groups[2].Value != "1") // Other than "1", multiply it times 10 raised to a power | ||||
| 					sb.Append(match.Groups[2].Value + "x10"); | ||||
| 				else // The number is simply 1 so it can be ignored and 10 can be raised to a power | ||||
| 					sb.Append("10"); | ||||
| 			else // A number with a decimal point | ||||
| 				sb.Append(match.Groups[2].Value + "." + match.Groups[3].Value + "x10"); | ||||
| 			// Add the exponent as superscript | ||||
| 			return sb.ToString() + "\\up3 " + match.Groups[4].Value + "\\up0 "; | ||||
| 		} | ||||
| 		#endregion | ||||
| 	} | ||||
| } | ||||
|   | ||||
| @@ -6,6 +6,12 @@ using Csla; | ||||
| using Csla.Data; | ||||
| using System.Data; | ||||
| using System.Data.SqlClient; | ||||
| //----------------- | ||||
| using System.Drawing; | ||||
| using System.Text.RegularExpressions; | ||||
| using LBWordLibrary; | ||||
| using System.Drawing.Imaging; | ||||
|  | ||||
|  | ||||
| namespace VEPROMS.CSLA.Library | ||||
| { | ||||
| @@ -98,6 +104,10 @@ namespace VEPROMS.CSLA.Library | ||||
| 		private DocumentConfig _DocumentConfig; | ||||
| 		public DocumentConfig DocumentConfig | ||||
| 		{ get { return (_DocumentConfig != null ? _DocumentConfig : _DocumentConfig = new DocumentConfig(this)); } } | ||||
| 		public void RefreshConfig() | ||||
| 		{ | ||||
| 			_DocumentConfig = null; | ||||
| 		} | ||||
| 		#endregion | ||||
|  | ||||
| 	} | ||||
| @@ -296,9 +306,17 @@ namespace VEPROMS.CSLA.Library | ||||
| 			//doc.UpdateDocAscii(_MyFile.FullName); | ||||
| 			DocumentConfig cfg = new DocumentConfig(doc); | ||||
| 			cfg.Printing_Length = length; | ||||
| 			cfg.Printing_Color = MSWordToPDF.OverrideColor; | ||||
| 			doc.Config = cfg.ToString(); | ||||
| 			doc.UserID = Environment.UserName; | ||||
| 			doc.DTS = _MyFile.LastWriteTime; | ||||
| 			string pdfTmp = MSWordToPDF.ToPDFReplaceROs(_MyDocument); | ||||
| 			FileInfo pdfFile = new FileInfo(pdfTmp); | ||||
| 			fs = pdfFile.Open(FileMode.Open, FileAccess.Read, FileShare.ReadWrite); | ||||
| 			buf = new byte[pdfFile.Length]; | ||||
| 			fs.Read(buf, 0, buf.Length); | ||||
| 			fs.Close(); | ||||
| 			doc.DocPdf = buf; | ||||
| 			doc.Save(); | ||||
| 		} | ||||
| 		#endregion | ||||
| @@ -329,4 +347,316 @@ namespace VEPROMS.CSLA.Library | ||||
| 		} | ||||
| 		#endregion | ||||
| 	} | ||||
| 	public static class MSWordToPDF | ||||
| 	{ | ||||
| 		private static LBApplicationClass _MyApp = null; | ||||
| 		public static LBApplicationClass MyApp | ||||
| 		{ | ||||
| 			get | ||||
| 			{ | ||||
| 				if (_MyApp == null) | ||||
| 					_MyApp = new LBApplicationClass(); | ||||
| 				return _MyApp; | ||||
| 			} | ||||
| 		} | ||||
| 		private static System.Drawing.Color _OverrideColor = System.Drawing.Color.Transparent; | ||||
| 		public static System.Drawing.Color OverrideColor | ||||
| 		{ | ||||
| 			get { return MSWordToPDF._OverrideColor; } | ||||
| 			set { MSWordToPDF._OverrideColor = value; } | ||||
| 		} | ||||
| 		private static System.Windows.Forms.Form _FormForPlotGraphics=null; | ||||
| 		public static System.Windows.Forms.Form FormForPlotGraphics | ||||
| 		{ | ||||
| 			get { return MSWordToPDF._FormForPlotGraphics; } | ||||
| 			set { MSWordToPDF._FormForPlotGraphics = value; } | ||||
| 		} | ||||
| 		public static string GetDocPdf(SectionInfo sect, Color overrideColor) | ||||
| 		{ | ||||
| 			DocumentInfo mydoc = sect.MyContent.MyEntry.MyDocument; | ||||
| 			UpdateDocPdf(mydoc, overrideColor); | ||||
| 			string fileName = GetFileName(sect); | ||||
| 			FileInfo fi = new FileInfo(fileName); | ||||
| 			FileStream fs = fi.Create(); | ||||
| 			fs.Write(mydoc.DocPdf, 0, mydoc.DocPdf.Length); | ||||
| 			fs.Close(); | ||||
| 			return fileName; | ||||
| 		} | ||||
|  | ||||
| 		public static void UpdateDocPdf(DocumentInfo mydoc, Color overrideColor) | ||||
| 		{ | ||||
| 			if (mydoc.DocPdf == null || overrideColor != mydoc.DocumentConfig.Printing_Color) | ||||
| 			{ | ||||
| 				MSWordToPDF.OverrideColor = overrideColor; | ||||
| 				SetDocPdf(mydoc); | ||||
| 			} | ||||
| 		} | ||||
| 		public static void SetDocPdf(DocumentInfo docInfo) | ||||
| 		{ | ||||
| 			string pdfTmp = MSWordToPDF.ToPDFReplaceROs(docInfo); | ||||
| 			FileInfo pdfFile = new FileInfo(pdfTmp); | ||||
| 			FileStream fs = pdfFile.Open(FileMode.Open, FileAccess.Read, FileShare.ReadWrite); | ||||
| 			Byte[] buf = new byte[pdfFile.Length]; | ||||
| 			fs.Read(buf, 0, buf.Length); | ||||
| 			fs.Close(); | ||||
| 			using (Document doc = docInfo.Get()) | ||||
| 			{ | ||||
| 				DocumentConfig dc = new DocumentConfig(doc); | ||||
| 				dc.Printing_Color = MSWordToPDF.OverrideColor; | ||||
| 				doc.Config = dc.ToString(); | ||||
| 				doc.DocPdf = buf; | ||||
| 				doc.Save(); | ||||
| 			} | ||||
| 			docInfo.RefreshConfig(); | ||||
| 		} | ||||
| 		public static string ToPDFReplaceROs(DocumentInfo doc) | ||||
| 		{ | ||||
| 			ItemInfo sect = doc.DocumentEntries[0].MyContent.ContentItems[0]; | ||||
| 			return ToPDFReplaceROs(sect, false); | ||||
| 		} | ||||
| 		public static string ToPDFReplaceROs(ItemInfo sect, bool openPdf) //, System.Drawing.Color overrideColor, System.Windows.Forms.Form myForm) | ||||
| 		{ | ||||
| 			string fileName = GetFileName(sect); | ||||
| 			// TODO: do we want to cache the word pdfs | ||||
| 			//if (System.IO.File.Exists(@"C:\Temp\" + fileName + ".pdf")) | ||||
| 			//    return @"C:\Temp\" + fileName + ".pdf"; | ||||
| 			//int docStyleIndex = ((int)sect.MyContent.Type) % 10000; | ||||
| 			//DocStyle myDocStyle = sect.ActiveFormat.PlantFormat.DocStyles.DocStyleList[docStyleIndex]; | ||||
| 			DocStyle myDocStyle = sect.MyDocStyle; | ||||
| 			//PageStyle myPageStyle = myDocStyle.pagestyle; | ||||
| 			ProcedureInfo proc = sect.MyProcedure; | ||||
| 			DocVersionInfo dvi = proc.ActiveParent as DocVersionInfo; | ||||
| 			ROFstInfo rofst = dvi.DocVersionAssociations[0].MyROFst; | ||||
| 			ROFSTLookup lookup = rofst.ROFSTLookup; | ||||
| 			string igPrefix = dvi.DocVersionConfig.RODefaults_graphicsprefix; | ||||
| 			string spPrefix = dvi.DocVersionConfig.RODefaults_setpointprefix; | ||||
| 			//    string AccPageID = string.Format("<{0}-{1}>", accPrefix, roch.appid); | ||||
| 			using (DSOFile myFile = new DSOFile(sect.MyContent.MyEntry.MyDocument)) | ||||
| 			{ | ||||
| 				LBDocumentClass myDoc = MyApp.Documents.Open(myFile.FullName, false); | ||||
| 				float newTop = (float)myDocStyle.Layout.TopRow; | ||||
| 				float newLeft = (float)myDocStyle.Layout.LeftMargin; | ||||
| 				float newLength = (float)myDocStyle.Layout.PageLength; | ||||
| 				float newWidth = (float)myDocStyle.Layout.PageWidth; | ||||
| 				float oldTop = myDoc.PageSetup.TopMargin; | ||||
| 				float oldLeft = myDoc.PageSetup.LeftMargin; | ||||
| 				float oldBottom = myDoc.PageSetup.BottomMargin; | ||||
| 				float oldRight = myDoc.PageSetup.RightMargin; | ||||
| 				float oldHeight = myDoc.PageSetup.PageHeight; | ||||
| 				float oldWidth = myDoc.PageSetup.PageWidth; | ||||
| 				float newRight = oldWidth - (newWidth + newLeft); | ||||
| 				if (newRight < 0) newRight = 0; | ||||
| 				float newBottom = oldBottom - newTop; | ||||
| 				//Console.WriteLine("{0},{1},{2},{3},{4},{5},{6},{7},{8},{9}", newTop, newLeft, newLength, newWidth, oldTop, oldLeft, oldBottom, oldRight,oldHeight,oldWidth); | ||||
| 				myDoc.PageSetup.BottomMargin = 0;// 11 * 72 - (newTop + newLength); | ||||
| 				myDoc.PageSetup.RightMargin = newRight; | ||||
| 				myDoc.PageSetup.LeftMargin = newLeft; | ||||
| 				myDoc.PageSetup.TopMargin = newTop; | ||||
| 				LBSelection sel = FindRO(); | ||||
| 				while (sel != null) | ||||
| 				{ | ||||
| 					string val = lookup.GetROValueByAccPagID(sel.Text, spPrefix, igPrefix); | ||||
| 					int? type = lookup.GetROTypeByAccPagID(sel.Text, spPrefix, igPrefix); | ||||
| 					if ((int)type == 8) // Image | ||||
| 					{ | ||||
| 						//Console.WriteLine("Image: {0} - {1}", sect.MyContent.Number, sect.MyContent.Text); | ||||
| 						bool imageROTokenReplaced = false; | ||||
| 						string[] vals = val.Split("\n".ToCharArray()); | ||||
| 						ROImageInfo roImage = ROImageInfo.GetByROFstID_FileName(rofst.ROFstID, vals[0]); | ||||
| 						if (roImage != null) | ||||
| 						{ | ||||
| 							ROImageFile roImageFile = new ROImageFile(roImage); | ||||
| 							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; | ||||
| 							//sel.MoveEnd(LBWdUnits.wdLine, lines);// The number of lines depends on the third parameter | ||||
| 							//sel.EndKey(LBWdUnits.wdLine, true); | ||||
| 							//sel.MoveEnd(LBWdUnits.wdCharacter, -1); | ||||
| 							//Console.WriteLine("Lines = {0}", lines); | ||||
| 							sel.Text = ""; | ||||
| 							// TODO: Need to create a temporary file for printing. | ||||
| 							// TODO: Need a way to eliminate the temporary file when done printing. | ||||
| 							// LBInlineShape shape = sel.InlineShapes.AddPicture(@"C:\Plant\HLP\VEHLP\ro\No1Seal.bmp"); | ||||
| 							float x = (float)sel.get_Information(LBWdInformation.wdHorizontalPositionRelativeToPage); | ||||
| 							float y = (float)sel.get_Information(LBWdInformation.wdVerticalPositionRelativeToPage); | ||||
| 							//LBInlineShape shape = sel.InlineShapes.AddPicture(pngFile); | ||||
| 							LBRange myRange = sel.Paragraphs.First.Range; | ||||
| 							float yTop = (float)myRange.get_Information(LBWdInformation.wdVerticalPositionRelativeToPage); | ||||
| 							LBShape shape = myDoc.Shapes.AddPicture(roImageFile.MyFile.FullName, x, y - yTop, sel.Range); | ||||
| 							// LBInlineShape shape = sel.InlineShapes.AddPicture(roImageFile.MyFile.FullName); | ||||
| 							//Console.WriteLine("{0} Shape Width {1} Height {2}", val.Replace("\n", "','"), shape.Width, shape.Height); | ||||
| 							shape.Width = width; | ||||
| 							shape.Height = height; | ||||
| 							//Console.WriteLine("{0} Shape Width {1} Height {2}", val.Replace("\n", "','"), shape.Width, shape.Height); | ||||
| 							imageROTokenReplaced = true; | ||||
| 						} | ||||
| 						if (!imageROTokenReplaced) | ||||
| 							sel.Text = string.Format("Bad Image Link (Missing Image File:{0})", vals[0]); | ||||
| 					} | ||||
| 					else if ((int)type == 4)  // X-Y Plot | ||||
| 					{ | ||||
| 						val = val.Replace("`", "\xB0"); | ||||
| 						//AddInfo("\tRO Found {0} = '{1}'", sel.Text, val); | ||||
| 						sel.Text = ""; | ||||
| 						//float width = 72 * Int32.Parse(vals[3], System.Globalization.NumberStyles.AllowHexSpecifier) / 12.0F; | ||||
| 						//float height = 72 * lines / 6.0F; | ||||
| 						string pngFile = @"C:\Temp\XYPlot1.png"; | ||||
| 						RectangleF plotRect = CreatePlot(pngFile, val, 600F, FormForPlotGraphics); | ||||
| 						//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); | ||||
| 						//LBInlineShape shape = sel.InlineShapes.AddPicture(pngFile); | ||||
| 						LBRange myRange = sel.Paragraphs.First.Range; | ||||
| 						float yTop = (float)myRange.get_Information(LBWdInformation.wdVerticalPositionRelativeToPage); | ||||
| 						float xAdjust = -29.3F; // TODO: Check this value | ||||
| 						float yAdjust = 9.1F; // TODO: Check this value | ||||
| 						LBShape shape = myDoc.Shapes.AddPicture(pngFile, x + xAdjust + plotRect.X, yAdjust + y - yTop + plotRect.Y, sel.Range); | ||||
| 						//Console.WriteLine(",{0},{1},{2},{3}", x, y - yTop, xAdjust,yAdjust); | ||||
| 						shape.LockAspectRatio = LBMsoTriState.msoTrue; | ||||
| 						//shape.Width = .89F * shape.Width; | ||||
| 						//shape.Width = float.Parse(tbAdjust.Text) * shape.Width; | ||||
| 						shape.Width = plotRect.Width; | ||||
| 						//shape.Height = .89F * shape.Height; | ||||
| 						sel.WholeStory(); | ||||
| 						// TODO: Do we want to color code ROs | ||||
| 						//sel.Range.Font.Color = LBWdColor.wdColorRed; | ||||
| 						//Console.WriteLine("{0} Shape Width {1} Height {2}", val.Replace("\n", "','"), shape.Width, shape.Height); | ||||
| 						//shape.Width = width; | ||||
| 						//shape.Height = height; | ||||
| 						//Console.WriteLine("{0} Shape Width {1} Height {2}", val.Replace("\n", "','"), shape.Width, shape.Height); | ||||
| 						//imageROTokenReplaced = true; | ||||
| 					} | ||||
| 					else | ||||
| 					{ | ||||
| 						val = val.Replace("`", "\xB0"); | ||||
| 						//AddInfo("\tRO Found {0} = '{1}'", sel.Text, val); | ||||
| 						InsertROValue(sel, val, sect.ActiveFormat.PlantFormat.FormatData.ROData.UpRoIfPrevUpper); | ||||
| 					} | ||||
| 					sel = FindRO(); | ||||
| 				} | ||||
| 				sel = MyApp.Selection; | ||||
| 				sel.WholeStory(); | ||||
| 				//sel.Range.Font.Color = (LBWdColor)WordColor(PrintOverride.OverrideTextColor(System.Drawing.Color.Black)); | ||||
| 				sel.Range.Font.Color = (LBWdColor)WordColor(OverrideColor == System.Drawing.Color.Transparent ? System.Drawing.Color.Black : OverrideColor); | ||||
| 				sel.ParagraphFormat.LineSpacingRule = LBWdLineSpacing.wdLineSpaceExactly; | ||||
| 				sel.ParagraphFormat.LineSpacing = 12; | ||||
| 				fileName = CreatePDF(fileName, openPdf); | ||||
| 				MyApp.ActiveDocument.Close(); | ||||
| 				MyApp.Quit(); | ||||
| 				_MyApp = null; | ||||
| 				return fileName; | ||||
| 			} | ||||
| 		} | ||||
| 		private static int WordColor(System.Drawing.Color color) | ||||
| 		{ | ||||
| 			System.Drawing.Color c1 = System.Drawing.Color.FromArgb(0, color.B, color.G, color.R); | ||||
| 			return c1.ToArgb(); | ||||
| 		} | ||||
| 		private static string GetFileName(ItemInfo sect) | ||||
| 		{ | ||||
| 			string fileName = "Doc " + sect.MyContent.MyEntry.DocID.ToString(); // +" " + (sect.DisplayNumber == "" ? sect.DisplayText : sect.DisplayNumber); | ||||
| 			return fileName; | ||||
| 		} | ||||
| 		private static RectangleF CreatePlot(string pngFile, string xyPlot, float resolution, System.Windows.Forms.Form myForm) | ||||
| 		{ | ||||
| 			RectangleF retval = new RectangleF(0, 0, 0, 0); | ||||
| 			//Form frm = Application.OpenForms[0]; | ||||
| 			System.Windows.Forms.Form frm = myForm; | ||||
| 			Graphics grfx = frm.CreateGraphics(); | ||||
| 			string emfFile = pngFile.Replace(".png", ".emf"); | ||||
| 			Metafile mf = new Metafile(emfFile, grfx.GetHdc()); | ||||
| 			grfx.Dispose(); | ||||
| 			grfx = Graphics.FromImage(mf); | ||||
| 			float dpi = grfx.DpiX; | ||||
| 			//grfx.ScaleTransform(resolution / grfx.DpiX, (resolution +1F) / grfx.DpiY); | ||||
| 			grfx.ScaleTransform(resolution / grfx.DpiX, resolution / grfx.DpiY); | ||||
| 			grfx.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor; | ||||
| 			grfx.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; | ||||
| 			grfx.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias; | ||||
| 			grfx.Clear(System.Drawing.Color.Transparent); | ||||
| 			XYPlots.XYPlot.BlackColor = System.Drawing.Color.Red; | ||||
| 			XYPlots.XYPlot myPlot = new XYPlots.XYPlot(xyPlot); | ||||
| 			myPlot.SetMargins(0, 0, 0, 0); | ||||
| 			myPlot.Process(new VG.VGOut_Graphics(grfx)); | ||||
| 			grfx.Dispose(); | ||||
| 			GraphicsUnit gu = new GraphicsUnit(); | ||||
| 			retval = mf.GetBounds(ref gu); | ||||
| 			retval.Width *= dpi / resolution; | ||||
| 			retval.Height *= dpi / resolution; | ||||
| 			retval.X *= dpi / resolution; | ||||
| 			retval.Y *= dpi / resolution; | ||||
| 			//retval.X = myPlot.Width-retval.Width; | ||||
| 			//AddInfo("{0},{1},{2},{3},{4},{5}", myPlot.Width, myPlot.Height, retval.Width, retval.Height,retval.X,retval.Y); | ||||
| 			//Console.Write("{0},{1},{2},{3}", myPlot.Width, myPlot.Height, retval.Width, retval.Height); | ||||
| 			mf.Save(pngFile, ImageFormat.Png); | ||||
| 			//Console.WriteLine("'pngfile','{0}'", pngFile); | ||||
| 			mf.Dispose(); | ||||
| 			FileInfo myFile = new System.IO.FileInfo(emfFile); | ||||
| 			myFile.Delete(); | ||||
| 			return retval; | ||||
| 		} | ||||
| 		private static void InsertROValue(LBSelection sel, string roValue, bool upRoIfPrevUpper) | ||||
| 		{ | ||||
| 			if (roValue == null) | ||||
| 			{ | ||||
| 				sel.Text = "RO Not Found"; | ||||
| 				sel.Font.Color = LBWdColor.wdColorRed; | ||||
| 			} | ||||
| 			else | ||||
| 			{ | ||||
| 				if (upRoIfPrevUpper && sel.LastWasUpper) roValue = roValue.ToUpper(); | ||||
| 				// Convert fortran formatted numbers to scientific notation. | ||||
|  | ||||
| 				//string tmp = DisplayRO.ConvertFortranFormatToScienctificNotation(roValue); | ||||
| 				string tmp = ROFSTLookup.ConvertFortranFormatToScienctificNotation(roValue); | ||||
| 				// Look for superscript or subscript and insert the appropriate commands | ||||
| 				//Match roMatch = Regex.Match(tmp, @"(.*?)\\(super|sub) (.*?)\\nosupersub "); | ||||
| 				Match roMatch = Regex.Match(tmp, @"(.*?)\\(up3|dn3) (.*?)\\(up0|dn0) "); | ||||
| 				if (roMatch.Groups.Count == 4)// Superscript or subscript found | ||||
| 				{ | ||||
| 					sel.Font.Color = LBWdColor.wdColorRed; | ||||
| 					while (roMatch.Groups.Count == 4) | ||||
| 					{ | ||||
| 						sel.TypeText(roMatch.Groups[1].Value); // output the text preceeding the super or sub command | ||||
| 						sel.Font.Position = roMatch.Groups[2].Value == "up3" ? 2 : -2; // Shift the vertical position for super or sub | ||||
| 						//sel.Font.Position = roMatch.Groups[2].Value == "super" ? 2 : -2; // Shift the vertical position for super or sub | ||||
| 						sel.TypeText(roMatch.Groups[3].Value); // output the superscript or subscript | ||||
| 						sel.Font.Position = 0; // restore the vertical position  | ||||
| 						tmp = tmp.Substring(roMatch.Length);  // remove the processed text | ||||
| 						//roMatch = Regex.Match(tmp, @"(.*?)\\(super|sub) (.*?)\\nosupersub ");  //  check to see if the text contain another super or sub | ||||
| 						roMatch = Regex.Match(tmp, @"(.*?)\\(up3|dn3) (.*?)\\(up0|dn0) "); //  check to see if the text contain another super or sub | ||||
| 					} | ||||
| 					if (tmp != "")// Add any remaining text | ||||
| 						sel.TypeText(tmp); | ||||
| 					sel.Font.Color = LBWdColor.wdColorAutomatic; | ||||
| 				} | ||||
| 				else // if no superscripts or subscripts just output the text | ||||
| 				{ | ||||
| 					sel.Text = roValue; | ||||
| 					sel.Font.Color = LBWdColor.wdColorRed; | ||||
| 				} | ||||
| 			} | ||||
| 		} | ||||
| 		private static LBSelection FindRO() | ||||
| 		{ | ||||
| 			LBSelection sel = MyApp.Selection; | ||||
| 			LBFind find = sel.Find; | ||||
| 			find.ClearFormatting(); | ||||
| 			find.Text = "[<](?@)-(?@)[>]"; | ||||
| 			//find.Wrap = LBWdFindWrap.wdFindStop; | ||||
| 			find.Wrap = LBWdFindWrap.wdFindContinue; | ||||
| 			find.MatchCase = false; | ||||
| 			find.MatchWholeWord = false; | ||||
| 			find.MatchWildcards = true; | ||||
| 			find.MatchSoundsLike = false; | ||||
| 			find.MatchAllWordForms = false; | ||||
| 			if (find.Execute()) return sel; | ||||
| 			return null; | ||||
| 		} | ||||
| 		private static string CreatePDF(string fileName, bool openPdf) | ||||
| 		{ | ||||
| 			return MyApp.CreatePDF(@"C:\Temp\" + fileName + ".pdf", openPdf); | ||||
| 		} | ||||
|  | ||||
| 	} | ||||
| } | ||||
|   | ||||
| @@ -811,7 +811,8 @@ namespace VEPROMS.CSLA.Library | ||||
| 		{ | ||||
| 			get | ||||
| 			{ | ||||
| 				if (MyContent.Type == 10000) return true; | ||||
| 				//if (MyContent.Type == 10000) return true; | ||||
| 				if (IsSection && MyDocStyle.IsStepSection) return true; | ||||
| 				return false; | ||||
| 			} | ||||
| 		} | ||||
|   | ||||
| @@ -624,6 +624,7 @@ namespace Volian.Controls.Library | ||||
| 			string outstr = instr; | ||||
|  | ||||
| 			outstr = outstr.Replace("`", @"\'b0");			// convert backquote to degree - left over from DOS days. | ||||
| 			//outstr = outstr.Replace(" ", @"\u160?");		// KBR TRY THIS  | ||||
| 			outstr = outstr.Replace("\xa0", @"\u160?");		// hardspace | ||||
| 			outstr = outstr.Replace("\xb0", @"\'b0");		// degree | ||||
| 			outstr = outstr.Replace("\x7f", @"\u916?");		// delta  | ||||
| @@ -666,186 +667,11 @@ namespace Volian.Controls.Library | ||||
| 			// OLD:  This function is now handled in the ConvertFortranFormatToScienctificNotation | ||||
| 			//outstr = ConvertDOSSuperAndSubScripts(outstr); | ||||
|  | ||||
| 			outstr = ConvertFortranFormatToScienctificNotation(outstr); | ||||
| 			outstr = ROFSTLookup.ConvertFortranFormatToScienctificNotation(outstr); | ||||
|  | ||||
| 			return outstr; | ||||
| 		} | ||||
| 		//public static string ConvertFortranFormatToScienctificNotation(string str) | ||||
| 		//{ | ||||
| 		//  string outstr = ""; | ||||
| 		//  int orglen = str.Length; | ||||
| 		//  int cnt = 0; | ||||
| 		//  int ptr; | ||||
|  | ||||
| 		//  int nbytes; | ||||
| 		//  int tstr, tstr2, rptr, start = 0; | ||||
|  | ||||
| 		//  while (cnt < orglen) | ||||
| 		//  { | ||||
| 		//    // position up to the the next number, sign, or period | ||||
| 		//    ptr = str.IndexOfAny("+-0123456789.".ToCharArray(), cnt); | ||||
| 		//    if (ptr == -1) | ||||
| 		//    { | ||||
| 		//      outstr += str.Substring(cnt); | ||||
| 		//      break; // jump out of while loop - nothing else to process | ||||
| 		//    } | ||||
| 		//    if ((ptr - cnt) > 0) | ||||
| 		//    { | ||||
| 		//      outstr += str.Substring(cnt, ptr - cnt); | ||||
| 		//      cnt = ptr; | ||||
| 		//    } | ||||
|  | ||||
| 		//    if (cnt > start && str[cnt - 1] == '\'') | ||||
| 		//    { | ||||
| 		//      //B2003-053: only remove the single quote character | ||||
| 		//      // if str ptr is not at the end of the string or | ||||
| 		//      // the next char (after the str ptr) is not a space | ||||
| 		//      // or newline... (as per Paul Linn on 7/17/03) | ||||
| 		//      int len = orglen - cnt; | ||||
| 		//      if (len <= 1 || str[cnt + 1] == ' ' || str[cnt + 1] == '\n') | ||||
| 		//        start = cnt; | ||||
| 		//      else | ||||
| 		//        start = cnt - 1; | ||||
| 		//    } | ||||
| 		//    else start = cnt; | ||||
| 		//    tstr = cnt; | ||||
|  | ||||
| 		//    //Skip preceeding signs | ||||
| 		//    if (str[cnt] == '+' || str[cnt] == '-') | ||||
| 		//      cnt++; | ||||
|  | ||||
| 		//    cnt = NextNonNumber(str, cnt); | ||||
| 		//    if (str[cnt] == '.') | ||||
| 		//    { | ||||
| 		//      cnt = NextNonNumber(str, cnt + 1); | ||||
| 		//      if (cnt >= str.Length) //jsj bug fix | ||||
| 		//      { | ||||
| 		//        outstr += str.Substring(tstr); | ||||
| 		//        break; // jump out of while loop - nothing else to process | ||||
| 		//      } | ||||
| 		//      if (str[start] == '\'') | ||||
| 		//      { | ||||
| 		//        start++; | ||||
| 		//      } | ||||
| 		//      else if (str[cnt] == 'E' && cnt > tstr) | ||||
| 		//      { | ||||
| 		//        nbytes = (cnt - tstr); // don't include the 'E' | ||||
| 		//        outstr += str.Substring(tstr, nbytes); | ||||
| 		//        cnt++; | ||||
|  | ||||
| 		//        rptr = outstr.Length - 1; | ||||
| 		//        while (outstr[rptr] == '0') rptr--; | ||||
| 		//        if (outstr[rptr] != '.') rptr++; | ||||
| 		//        if (rptr < (outstr.Length - 1)) | ||||
| 		//          outstr = outstr.Substring(0, rptr + 1); // trim trailing 0's | ||||
| 		//        //outstr = outstr.TrimEnd(".".ToCharArray()); | ||||
| 		//        int poutstr = 0; | ||||
| 		//        if (outstr[poutstr] == '+' || outstr[poutstr] == '-') poutstr++; | ||||
| 		//        if (!outstr.Substring(poutstr).Equals("1")) | ||||
| 		//        { | ||||
| 		//          outstr += "x1"; | ||||
| 		//        } | ||||
| 		//        outstr += "0\\super "; | ||||
|  | ||||
| 		//        tstr2 = cnt; | ||||
| 		//        if (str[cnt] == '+' || str[cnt] == '-') cnt++; | ||||
| 		//        cnt = NextNonNumber(str, cnt); | ||||
|  | ||||
| 		//        if (str[cnt] == '.' && char.IsDigit(str, cnt + 1)) | ||||
| 		//          cnt = NextNonNumber(str, cnt + 1); | ||||
|  | ||||
| 		//        nbytes = cnt - tstr2; // +1; | ||||
| 		//        outstr += str.Substring(tstr2, nbytes); | ||||
| 		//        outstr += "\\nosupersub "; | ||||
|  | ||||
| 		//        if (!char.IsLetterOrDigit(str, cnt) && !char.IsWhiteSpace(str, cnt)) | ||||
| 		//          return (str.Substring(tstr)); | ||||
| 		//      } | ||||
| 		//    } | ||||
| 		//    else | ||||
| 		//    { | ||||
| 		//      outstr += str.Substring(start, cnt - start + 1); | ||||
| 		//      cnt++; | ||||
| 		//    } | ||||
| 		//  } | ||||
| 		//  return (outstr); | ||||
| 		//} | ||||
|  | ||||
| 		//private static int NextNonNumber(string str, int cnt) | ||||
| 		//{ | ||||
| 		//  int rtn = 0; | ||||
| 		//  string tstr = str.Substring(cnt); | ||||
| 		//  int len = tstr.Length; | ||||
| 		//  while (rtn < len && char.IsDigit(tstr, rtn)) rtn++; | ||||
| 		//  return rtn + cnt; | ||||
| 		//} | ||||
| 		public static string ConvertFortranFormatToScienctificNotation(string str) | ||||
| 		{ | ||||
| 			// Convert E style numbers to RTF with \super and \nosupersub | ||||
| 			string retval = Regex.Replace(str, "([+-]?)([0-9]+)[.]([0-9]*?)0*E([+-]?[0-9]+)", new MatchEvaluator(FixFortranNumber)); | ||||
| 			//retval = Regex.Replace(retval, "[#](.*?)[#]", "\\super $1\\nosupersub ");// DOS Superscript | ||||
| 			//retval = Regex.Replace(retval, "[~](.*?)[~]", "\\sub $1\\nosupersub ");// DOS Subscript | ||||
| 			retval = Regex.Replace(retval, "[#](.*?)[#]", "\\up3 $1\\up0 ");// DOS Superscript | ||||
| 			retval = Regex.Replace(retval, "[~](.*?)[~]", "\\dn3 $1\\dn0 ");// DOS Subscript | ||||
| 			return retval; | ||||
| 		} | ||||
| 		private static string FixFortranNumber(Match match) | ||||
| 		{ | ||||
| 			StringBuilder sb = new StringBuilder(match.Groups[1].Value); | ||||
| 			if (match.Groups[3].Length == 0) // Nothing to the right of the decimal | ||||
| 				if (match.Groups[2].Value != "1") // Other than "1", multiply it times 10 raised to a power | ||||
| 					sb.Append(match.Groups[2].Value + "x10"); | ||||
| 				else // The number is simply 1 so it can be ignored and 10 can be raised to a power | ||||
| 					sb.Append("10"); | ||||
| 			else // A number with a decimal point | ||||
| 				sb.Append(match.Groups[2].Value + "." + match.Groups[3].Value + "x10"); | ||||
| 			// Add the exponent as superscript | ||||
| 			return sb.ToString() + "\\up3 " + match.Groups[4].Value + "\\up0 "; | ||||
| 		} | ||||
|  | ||||
| 		//private string ConvertDOSSuperAndSubScripts(string instr) | ||||
| 		//{ | ||||
| 		//  string outstr = ""; | ||||
| 		//  string tstr = instr; | ||||
| 		//  int cnt = 0; | ||||
| 		//  int ptr = 0; | ||||
| 		//  bool issupper=false, issub = false; | ||||
|  | ||||
| 		//  while (tstr != null && (ptr = tstr.IndexOfAny("#~".ToCharArray(), cnt)) >= 0) | ||||
| 		//  { | ||||
| 		//    if (ptr > cnt) | ||||
| 		//      outstr += tstr.Substring(cnt, ptr - cnt); | ||||
| 		//    switch (tstr[ptr]) | ||||
| 		//    { | ||||
| 		//      case '#': | ||||
| 		//        if (issub || issupper) | ||||
| 		//          outstr += "\\nosupersub "; | ||||
| 		//        else | ||||
| 		//          outstr += "\\super "; | ||||
| 		//        issupper = !issupper; | ||||
| 		//        issub = false; | ||||
| 		//        break; | ||||
| 		//      case '~': | ||||
| 		//        if (issupper || issub) | ||||
| 		//          outstr += "\\nosupersub "; | ||||
| 		//        else | ||||
| 		//          outstr += "\\sub "; | ||||
| 		//        issub = !issub; | ||||
| 		//        issupper = false; | ||||
| 		//        break; | ||||
| 		//    } | ||||
| 		//    cnt = ptr + 1; | ||||
| 		//    if (cnt >= tstr.Length) | ||||
| 		//      tstr = null; | ||||
| 		//    else | ||||
| 		//      tstr = instr.Substring(cnt); | ||||
| 		//    cnt = 0; | ||||
| 		//  } | ||||
| 		//  if (tstr != null) | ||||
| 		//    outstr += tstr; | ||||
| 		//  return outstr; | ||||
| 		//} | ||||
|  | ||||
| 		 | ||||
| 		private static string _TemporaryFolder = null; | ||||
| 		public static string TemporaryFolder | ||||
| 		{ | ||||
|   | ||||
		Reference in New Issue
	
	Block a user