2011-11-21 17:02:08 +00:00

152 lines
5.1 KiB
C#

using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using iTextSharp.text.pdf;
using iTextSharp.text;
using VEPROMS.CSLA.Library;
namespace Volian.Print.Library
{
public partial class vlnTab : vlnText
{
/// <summary>
/// Used to Align Tabs for numeric tabs that can go to 2 digits
/// </summary>
private float? _TabAlign;
public float TabAlign // Offset to Last printable character
{
get
{
if (_TabAlign == null)
{
_TabAlign = 0;
if (Text != null)
{
while (_TabAlign < Text.Length && Text[(int)_TabAlign] == ' ')
_TabAlign++;
if (_TabAlign < Text.Length)
{
if ("0123456789".Contains(Text[(int)_TabAlign].ToString()))
{
while ("0123456789".Contains(Text[(int)_TabAlign].ToString()))
_TabAlign++;
_TabAlign--;
}
}
else
_TabAlign = 0;
}
}
return (float)_TabAlign * MyFont.CharsToTwips;
}
}
private float? _TabOffset;
public float TabOffset // Offset to first printable character
{
get
{
if (_TabOffset == null)
{
_TabOffset = 0;
if (Text != null)
{
while (_TabOffset<Text.Length && Text[(int)_TabOffset] == ' ')
_TabOffset++;
}
}
if (_TabOffset >= Text.Length) _TabOffset = 0;
return (float)_TabOffset * MyFont.CharsToTwips;
}
}
private vlnMacro _MyMacro;
public vlnMacro MyMacro
{
get { return _MyMacro; }
set { _MyMacro = value; }
}
private string symblsStr = "\u25CF"; // string of possible symbol character in a tab
// add symbol characters as needed
// "\u25CF" - solid bullet
private float GetTextWidth(VE_Font vefont, string txt, string symblFontName)
{
System.Drawing.Font font = new System.Drawing.Font(vefont.Family, (float)vefont.Size);
System.Drawing.Font symbFont = new System.Drawing.Font(symblFontName, (float)vefont.Size);
iTextSharp.text.Font iFont = Volian.Svg.Library.VolianPdf.GetFont(font);
iTextSharp.text.Font iSymblFont = Volian.Svg.Library.VolianPdf.GetFont(symbFont);
float w = 0;
foreach (char c in Text)
{
int idx = symblsStr.IndexOf(c);
if (idx >= 0) // symbol character - use symbol font to find its width
w += iSymblFont.BaseFont.GetWidthPointKerned(symblsStr[idx].ToString(), (float)vefont.Size);
else
w += iFont.BaseFont.GetWidthPointKerned(c.ToString(), (float)vefont.Size);
}
//float w = iFont.BaseFont.GetWidthPointKerned(Text.Replace("\u25CF","@"), (float)vefont.Size);
return w;
}
public vlnTab(PdfContentByte cb, vlnParagraph myparent, string origTab, string cleanTab, float xoffset, float yoffset, VE_Font vFont, bool doSectTab, string symblFontName)
{
MyContentByte = cb;
MyParent = myparent;
YOffset = yoffset;
Text = cleanTab;
MyFont = vFont;
Width = GetTextWidth(MyFont, (Text != null ? Text : origTab), symblFontName);//MyFont.CharsToTwips * (Text != null ? Text.Length : origTab.Length);
if (origTab.Contains(@"{!"))
{
int mindx = origTab.IndexOf(@"{!");
int meindx = origTab.IndexOf(@"}", mindx);
string macro = origTab.Substring(mindx, meindx - mindx+1);
// Width for placement of macro should be position in the string where the macro was located.
float lwidth = MyFont.CharsToTwips * (origTab.Length - meindx);
MyMacro = new vlnMacro(xoffset - lwidth, yoffset, macro.Substring(2, macro.Length - 3));
origTab = origTab.Replace(macro,"");
origTab = origTab + " ";
cleanTab = origTab;
Width = GetTextWidth(MyFont, (cleanTab != null ? cleanTab : origTab), symblFontName);//MyFont.CharsToTwips * (cleanTab != null ? cleanTab.Length : origTab.Length);
}
Rtf = GetRtf(origTab, vFont);
Rtf = Rtf.Replace("\u25CF", @"\f1\u9679?\f0"); // bullet 25CF // jsj- add space after \f0
if (myparent.MyItemInfo.FormatStepData != null && !myparent.MyItemInfo.FormatStepData.AlwaysTab && myparent.MyItemInfo.MyPrevious != null)
{
Rtf = Rtf.Replace("Caution:", " ");
Rtf = Rtf.Replace("Note:", " ");
Rtf = Rtf.Replace("CAUTION:", " ");
Rtf = Rtf.Replace("NOTE:", " ");
Rtf = Rtf.Replace("Caution", " ");
Rtf = Rtf.Replace("Note", " ");
Rtf = Rtf.Replace("CAUTION", " ");
Rtf = Rtf.Replace("NOTE", " ");
}
// do positioning based on whether format has locations for section 'header'. If it's not centered, treat
// it's location more like a 'tab'.
if (doSectTab)
XOffset = xoffset;
else
{
//if (MyFont.Family == "Arial" && MyFont.Size == 14)
//{
// System.Drawing.Font font = new System.Drawing.Font("Arial", 14);
// iTextSharp.text.Font iFont = Volian.Svg.Library.VolianPdf.GetFont(font);
// float w = iFont.BaseFont.GetWidthPointKerned(Text, 14);
// Width = w;
//}
XOffset = xoffset - Width;
}
}
public override float ToPdf(PdfContentByte cb, float yPageStart, float yTopMargin, float yBottomMargin)
{
float yLocation = CalculateYOffset(yPageStart, yTopMargin);
Rtf2Pdf.TextAt(cb, IParagraph, XOffset, yLocation, Width, 100, "", yBottomMargin);
return yPageStart;
}
}
}