2011-06-16 10:39:46 +00:00

99 lines
2.8 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 (Text[(int)_TabAlign] == ' ')
_TabAlign++;
if ("0123456789".Contains(Text[(int)_TabAlign].ToString()))
{
while ("0123456789".Contains(Text[(int)_TabAlign].ToString()))
_TabAlign++;
_TabAlign--;
}
}
}
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 (Text[(int)_TabOffset] == ' ')
_TabOffset++;
}
return (float)_TabOffset * MyFont.CharsToTwips;
}
}
private vlnMacro _MyMacro;
public vlnMacro MyMacro
{
get { return _MyMacro; }
set { _MyMacro = value; }
}
public vlnTab(PdfContentByte cb, vlnParagraph myparent, string origTab, string cleanTab, float xoffset, float yoffset, VE_Font vFont, bool doSectTab)
{
MyContentByte = cb;
MyParent = myparent;
YOffset = yoffset;
Text = cleanTab;
MyFont = vFont;
Width = 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 = MyFont.CharsToTwips * (cleanTab != null ? cleanTab.Length : origTab.Length);
}
Rtf = GetRtf(origTab, vFont);
// 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
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;
}
}
}