Replace words for bolding [Bxxx], i.e. support for regular expression text in replaceword/with

Added TextAt counter for debug
Added debug of TextAt by allowing specifying of ItemIds
This commit is contained in:
Kathy Ruffing 2014-08-18 13:34:09 +00:00
parent c24d6b94ea
commit a33347b22a
3 changed files with 35 additions and 3 deletions

View File

@ -1644,8 +1644,10 @@ namespace Volian.Controls.Library
// ReplaceStrData xml node is empty, it does the inheritance and gets the 'base' format's list.
if (rsl.Count==1 && (rsl[0].ReplaceWord == null || rsl[0].ReplaceWord == "")) return Text;
// Loop through text looking for words to be replaced
List<ReplaceStr> partialReplaceList = new List<ReplaceStr>();
foreach (ReplaceStr rs in rsl)
{
bool dopartial = false;
bool replaceit = false;
// note that the order of this check is important. Check in this order...
// background here
@ -1662,6 +1664,11 @@ namespace Volian.Controls.Library
{
if (!dicReplaceRegex.ContainsKey(rs))
{
if ((rs.Flag & E_ReplaceFlags.Partials) == E_ReplaceFlags.Partials)
{
partialReplaceList.Add(rs);
dopartial = true;
}
// CASEINSENS: Do ReplaceWords for all words that match, regardless of case, and replace with the ReplaceWith string as is
//RegexOptions myOptions = (rs.Flag & E_ReplaceFlags.CaseInsens) == E_ReplaceFlags.CaseInsens ? RegexOptions.IgnoreCase & RegexOptions.Singleline : RegexOptions.None & RegexOptions.Singleline;
RegexOptions myOptions = (rs.Flag & E_ReplaceFlags.CaseInsens) == E_ReplaceFlags.CaseInsens ? RegexOptions.IgnoreCase: RegexOptions.None;
@ -1671,20 +1678,23 @@ namespace Volian.Controls.Library
string wordMatchBeg = Regex.IsMatch(replaceWord.Substring(0, 1), @"\W") ? "" : @"(?<=\W|^)";
string wordMatchEnd = Regex.IsMatch(replaceWord.Substring(replaceWord.Length - 1, 1), @"\W") ? "" : @"(?=\W|$)";
string pat = wordMatchBeg + @"(?<!\\u160\?|\\u8209\?)" + replaceWord + @"(?!\\u160\?|\\u8209\?)" + wordMatchEnd;
dicReplaceRegex.Add(rs, new Regex(pat, myOptions));
if (!dopartial) dicReplaceRegex.Add(rs, new Regex(pat, myOptions));
}
try
{
myMatches.Add(dicReplaceRegex[rs], rs);
if (!dopartial) myMatches.Add(dicReplaceRegex[rs], rs);
}
catch (Exception ex)
{
Console.WriteLine("{0},'{1}',{2},'{3}'", _MyItemInfo.ActiveFormat.Name, rs.ReplaceWord, ex.GetType().Name, ex.Message);
}
dopartial = false;
}
}
Text = myMatches.ReplaceMatches();
Text = Text.Replace(@"\xA0", @"\u160?"); //replace hard space
foreach (ReplaceStr prs in partialReplaceList)
Text = Regex.Replace(Text, prs.ReplaceWord, prs.ReplaceWith);
return Text;
}
#region notused

View File

@ -401,6 +401,7 @@ namespace Volian.Print.Library
}
private string PrintProcedureOrFoldout(ProcedureInfo myProcedure, SectionInfo myFoldoutSection, string outputFileName, bool makePlacekeeper)
{
Rtf2Pdf.TextAtCounter = 0;
bool doingFoldout = myFoldoutSection != null;
// The following line accounts for 16bit OverrideLeftMargin when the 'Absolute' attribute is used in the genmac.
// We don't want to use the OverrideLeftMargin when 'Absolute' is used in the genmac.

View File

@ -73,6 +73,16 @@ namespace Volian.Print.Library
set { Rtf2Pdf._Offset = value; }
}
public static float FillWidth = 0; // max text width (used in autoToc code)
private static int _TextAtCounter = 0;
public static int TextAtCounter
{
get { return Rtf2Pdf._TextAtCounter; }
set { Rtf2Pdf._TextAtCounter = value; }
}
private static int NextTextAtCounter
{
get { return ++TextAtCounter; }
}
public static float TextAt(PdfContentByte cb, Paragraph iParagraph, float x, float y, float width, float height, string debugText, float yBottomMargin)
{
VlnSvgPageHelper _MyPageHelper = cb.PdfWriter.PageEvent as VlnSvgPageHelper;
@ -100,9 +110,20 @@ namespace Volian.Print.Library
if (iParagraph.Font.BaseFont != null)
yDescent = -iParagraph.Font.BaseFont.GetDescentPoint("Almg", iParagraph.Font.Size);
if (PdfDebug)
DrawPdfDebug(cb, left, top, left + width, myColumnText.YLine, debugText, yDescent);
{
int next = NextTextAtCounter;
if (InList(next,258,259)) Console.WriteLine("here");
string dbt = string.Format("[{0}]{1}", next, debugText ?? "");
DrawPdfDebug(cb, left, top, left + width, myColumnText.YLine, dbt, yDescent);
}
return myColumnText.YLine;
}
private static bool InList(int value, params int [] examples)
{
foreach (int ex in examples)
if (ex == value) return true;
return false;
}
public static float FigureAt(PdfContentByte cb, iTextSharp.text.Image image, float x, float y, float width, float height, string debugText, float yBottommargin, bool hasBorder)
{
VlnSvgPageHelper _MyPageHelper = cb.PdfWriter.PageEvent as VlnSvgPageHelper;