From ecf6b5bfd1cb849d52ae8b87376e0501fc9bf150 Mon Sep 17 00:00:00 2001 From: Kathy Date: Tue, 23 Nov 2010 14:42:02 +0000 Subject: [PATCH] --- PROMS/LBWordLibrary/LBComObject.cs | 14 +++++ PROMS/LBWordLibrary/LBObjectExtension.cs | 70 ++++++++++++++++++++++++ 2 files changed, 84 insertions(+) diff --git a/PROMS/LBWordLibrary/LBComObject.cs b/PROMS/LBWordLibrary/LBComObject.cs index 3bd7d31c..da926933 100644 --- a/PROMS/LBWordLibrary/LBComObject.cs +++ b/PROMS/LBWordLibrary/LBComObject.cs @@ -292,6 +292,12 @@ namespace LBWordLibrary { get { return (GetProperty("SaveFormat") as int? ?? 0); } } + public Boolean Saved + { + get { return (GetProperty("Saved") as Boolean? ?? false); } + set { SetProperty("Saved", value); } + } + public String FullName { get { return (GetProperty("FullName").ToString()); } @@ -348,6 +354,14 @@ namespace LBWordLibrary { return new LBRange(InvokeMethod("Range", Start, End)); } + public Boolean Undo() + { + return InvokeMethod("Undo", Missing.Value) as Boolean? ?? false; + } + public Boolean Undo(object Times) + { + return InvokeMethod("Undo", Times) as Boolean? ?? false; + } } public partial class LBWindow : LBComObject { diff --git a/PROMS/LBWordLibrary/LBObjectExtension.cs b/PROMS/LBWordLibrary/LBObjectExtension.cs index 57193211..674c0475 100644 --- a/PROMS/LBWordLibrary/LBObjectExtension.cs +++ b/PROMS/LBWordLibrary/LBObjectExtension.cs @@ -293,6 +293,39 @@ namespace LBWordLibrary return true; return false; } + /// + /// If document contains symbol characters, returns problem font. + /// + public string FontHasSymbolCharacters + { + get + { + LBRange myRange = Range(); + myRange = myRange.GoTo(LBWdGoToItem.wdGoToPercent, LBWdGoToDirection.wdGoToLast, 100); + myRange.Start = 0; + int end = myRange.End; + string myText = GetRangeText(myRange); + //return _RegFindSymbol.IsMatch(myText); + MatchCollection problems = _RegFindSymbol.Matches(myText); + int offset = 0; + foreach (Match problem in problems) + { + myRange.Start = problem.Index + offset; + myRange.End = problem.Index + problem.Length + offset; + int newOffset = FindRangeOffset(myRange, problem, offset, end); + if (IsSymbolFont(myRange.Font.Name)) + { + Console.WriteLine("Font '{0}' has Symbols", myRange.Font.Name); + //return true; + } + else + return myRange.Font.Name; + offset = newOffset; + } + return null; + } + } + /// /// Checks to see if the document contains symbol characters /// @@ -350,6 +383,43 @@ namespace LBWordLibrary } } /// + /// Try to fix the first character in the symbol range F000 to F0FF. If it cannot be + /// fixed, it is an indicator that the font is not installed properly. Regardless of + /// whether there is success, the change is undone so that the document will not be + /// considered dirty, i.e. will not prompt user for save. + /// + /// + public bool AttemptToFixASymbolCharacter() + { + // Set up range object to be used to process text + LBRange myRange = Range(); + myRange = myRange.GoTo(LBWdGoToItem.wdGoToPercent, LBWdGoToDirection.wdGoToLast, 100); + + int end = myRange.End; + myRange.Start = 0; + string myText = GetRangeText(myRange); + MatchCollection problems = _RegFindSymbol.Matches(myText); + if (problems.Count>0) + { + Match problem = problems[0]; + myRange.Start = problem.Index; + myRange.End = myRange.Start + 1; + if (IsSymbolFont(myRange.Font.Name)) return true; // if it's a symbol font already, no issue. + string before = GetRangeText(myRange); + string updated = ReplaceSymbolCharacters(before); + myRange.Text = updated; + string after = GetRangeText(myRange); + Undo(1); + //Console.WriteLine("Undo1 results = {0}", tst); + //tst = Undo(1); + //Console.WriteLine("Undo2 results = {0}", tst); + //tst = Undo(1); + //Console.WriteLine("Undo3 results = {0}", tst); + return (updated == after); + } + return true; + } + /// /// Get the Range Text with error handling. myRange.Text sometimes will get a null reference exception. /// ///