Fixed the logic were the font would change after a dash (hyphen) in a table cell

This commit is contained in:
John Jenko 2015-03-24 17:40:29 +00:00
parent 1b03974f55
commit 03f127279f

View File

@ -236,7 +236,7 @@ namespace Volian.Print.Library
myPara.MultipliedLeading = 12.0f / myPara.TotalLeading;
myPara.SpacingAfter = 8; // RHM 20120925 - Add a line to properly space text from lines.
FixHyphens(myPara);
FixHyphens(myPara, MyTable);
myColumnText1.AddElement(myPara);
//myColumnText1.Canvas.SetColorFill(PrintOverride.OverrideTextColor(System.Drawing.Color.Black));
float posBefore = myColumnText1.YLine;
@ -262,19 +262,58 @@ namespace Volian.Print.Library
}
}
public static VlnSplitCharacter mySplitter = new VlnSplitCharacter();
internal static void FixHyphens(Paragraph myPara)
internal static void FixHyphens(Paragraph myPara, vlnTable myTable)
{
// Find chunk with hardhyphen
// If a hard hyphen is found, the remove it and add a dash (keyboard minus sign) to the beginning
// of the text that follows it.
int hype=-1;
Font fnt = null;
foreach (Chunk chk in myPara)
{
fnt = chk.Font;
break;
}
while ((hype = GetHyphen(myPara)) > -1)
{
fnt = null;
if (hype > 0)
{
Chunk chk1 = (Chunk)myPara[hype - 1];
if (hype > 1 && chk1.Content.Equals("\n"))
chk1 = (Chunk)myPara[hype - 2];
fnt = chk1.Font; // use the font of the text that follows the hyphen (dash)
}
else if (hype < myPara.Count - 1)
{
Chunk chk2 = (Chunk)myPara[hype + 1];
if (hype != 0 && !chk2.Content.Equals("\n"))
fnt = chk2.Font; // use the font of the text that follows the hyphen (dash)
}
if (fnt == null)
{
// if there was no text following the hypen, then use the font defined for tables in the plant's format
VEPROMS.CSLA.Library.VE_Font vfnt = myTable.MyFlexGrid.GetMyItemInfo().FormatStepData.Font;
System.Drawing.Font ffont = new System.Drawing.Font(vfnt.Family, (float)vfnt.Size);
fnt = Volian.Svg.Library.VolianPdf.GetFont(ffont);
fnt.SetStyle(myPara.Font.Style);
fnt.SetColor(myPara.Font.Color.R,myPara.Font.Color.G,myPara.Font.Color.B);
}
Chunk chk = (Chunk)myPara[hype];
// THIS CODE IS USED FOR DEBUGGING
//if (!fnt.Familyname.StartsWith("L"))
//{
// Console.WriteLine("font = {0}", makeitpretty(fnt));
// Console.WriteLine("Hype = {0}\r\n{1}",hype, myPara.Content);
// if (hype > 0)
// {
// Chunk chk3 = (Chunk)myPara[hype - 1];
// Console.WriteLine("before '{0}'", chk3.Content);
// }
// Chunk chk4 = (Chunk)myPara[hype];
// Console.WriteLine("during '{0}'", chk4.Content);
// if (hype < myPara.Count -1)
// {
// Chunk chk5 = (Chunk)myPara[hype + 1];
// Console.WriteLine("after '{0}'", chk5.Content);
// }
//}
string prefix = "";
if (chk.Content == "\u2011" && hype < (myPara.Count - 1))
{
@ -285,30 +324,14 @@ namespace Volian.Print.Library
myPara.RemoveAt(hype);
myPara.Insert(hype, new Chunk(prefix + chk.Content.Replace("\u2011", "-"), fnt));
}
//bool hasXXX = false;
//foreach (Chunk chk in myPara)
//{
// if(hasXXX)
// Console.WriteLine("0,\"{0}\"\t\"{1}\"", chk.Content, chk.Font.Familyname);
// else if (chk.Content.Contains("xxx"))
// {
// hasXXX = true;
// Console.WriteLine("1,\"{0}\"\t\"{1}\"", chk.Content, chk.Font.Familyname);
// }
// else if (chk.Content.Contains("zzz")) Console.WriteLine("3,\"{0}\"\t\"{1}\"", chk.Content, chk.Font.Familyname);
// else if (chk.Content.Contains("\u2011")) Console.WriteLine("2\"{0}\"\t\"{1}\"", chk.Content, chk.Font.Familyname);
// if (chk.Attributes == null || !chk.Attributes.ContainsKey("NoSplit"))
// {
// if (chk.Attributes == null) chk.Attributes = new System.Collections.Hashtable();
// //Console.WriteLine("Oops!");
// chk.SetSplitCharacter(mySplitter);
// chk.Attributes.Add("NoSplit", false);
// }
// else
// {
// }
//}
}
// THIS FUNCTION IS USED FOR DEBUGGING
private static string makeitpretty(Font fnt)
{
return string.Format("font {0}, size {1}, style {2}", fnt.Familyname, fnt.Size, fnt.Style);
}
private static int GetHyphen(Paragraph myPara)
{
int index=0;
@ -736,7 +759,7 @@ namespace Volian.Print.Library
float adjustTextLocation = mult * 4; // RHM 20120925 Move text down about 1 half line from the border
myColumnText1.SetSimpleColumn(1 + left + x, top - y - h , left + x + w, 1 + top - y - hAdjust - adjustTextLocation); // 2 == Default Padding
MyPara.MultipliedLeading *= _MyPageHelper.YMultiplier;
vlnCells.FixHyphens(MyPara);
vlnCells.FixHyphens(MyPara, MyTable);
myColumnText1.AddElement(MyPara);
myColumnText1.Go();
myColumnText.Canvas.RestoreState();