- Removed SvgRtf

- Added Layer Properties
- Setup default Colors
- Moved code to Volian.Print.Library
Added Override Color
This commit is contained in:
Rich 2010-05-19 14:56:42 +00:00
parent 21f32e3434
commit 1957c4b457
4 changed files with 326 additions and 205 deletions

View File

@ -9,6 +9,12 @@ namespace Volian.Svg.Library
[XmlRoot("svg")] [XmlRoot("svg")]
public partial class Svg : SvgGroup public partial class Svg : SvgGroup
{ {
private static System.Drawing.Color _OverrrideColor = System.Drawing.Color.Empty;
public static System.Drawing.Color OverrideColor
{
get { return Svg._OverrrideColor; }
set { Svg._OverrrideColor = value; }
}
#region XML Serializer Namespaces #region XML Serializer Namespaces
private XmlSerializerNamespaces _Namespaces = null; private XmlSerializerNamespaces _Namespaces = null;
[XmlNamespaceDeclarations] [XmlNamespaceDeclarations]
@ -43,18 +49,18 @@ namespace Volian.Svg.Library
get { return SvgXmlConverter<SvgMeasurement>.GetString(_Width); } get { return SvgXmlConverter<SvgMeasurement>.GetString(_Width); }
set { _Width = SvgXmlConverter<SvgMeasurement>.GetObject(value); } set { _Width = SvgXmlConverter<SvgMeasurement>.GetObject(value); }
} }
private string _Watermark=""; //private string _Watermark="";
[XmlAttribute("watermark")] //[XmlAttribute("watermark")]
public string Watermark //public string Watermark
{ //{
get { return _Watermark; } // get { return _Watermark; }
set { _Watermark = value; } // set { _Watermark = value; }
} //}
public void SetValidWaterMark(string token, string watermark) //public void SetValidWaterMark(string token, string watermark)
{ //{
if (token == "{" + watermark.ToUpper() + "PAGE}" ) // if (token == "{" + watermark.ToUpper() + "PAGE}" )
_Watermark = watermark; // _Watermark = watermark;
} //}
#endregion #endregion
#region Height #region Height
private SvgMeasurement _Height = new SvgMeasurement(); private SvgMeasurement _Height = new SvgMeasurement();

View File

@ -22,13 +22,13 @@ namespace Volian.Svg.Library
[XmlIgnore] [XmlIgnore]
protected Color LineColor protected Color LineColor
{ {
get { return _MyLineSettings.LineColor; } get { return Svg.OverrideColor != System.Drawing.Color.Empty ? Svg.OverrideColor : _MyLineSettings.LineColor; }
set { _MyLineSettings.LineColor = value; } set { _MyLineSettings.LineColor = value; }
} }
[XmlIgnore] [XmlIgnore]
protected Color OutlineColor protected Color OutlineColor
{ {
get { return _MyLineSettings.OutlineColor; } get { return Svg.OverrideColor != System.Drawing.Color.Empty ? Svg.OverrideColor :_MyLineSettings.OutlineColor; }
set { _MyLineSettings.OutlineColor = value; } set { _MyLineSettings.OutlineColor = value; }
} }
[System.ComponentModel.DefaultValueAttribute("")] [System.ComponentModel.DefaultValueAttribute("")]

View File

@ -21,7 +21,7 @@ namespace Volian.Svg.Library
[XmlIgnore] [XmlIgnore]
protected Color FillColor protected Color FillColor
{ {
get { return _MyFillSettings.FillColor; } get { return Svg.OverrideColor != System.Drawing.Color.Empty ? Svg.OverrideColor : _MyFillSettings.FillColor; }
set { _MyFillSettings.FillColor = value; } set { _MyFillSettings.FillColor = value; }
} }
#endregion #endregion

View File

@ -13,6 +13,9 @@ using Itenso.Rtf.Interpreter;
//using Itenso.Rtf.Model; //using Itenso.Rtf.Model;
using Itenso.Rtf.Support; using Itenso.Rtf.Support;
using Microsoft.Win32; using Microsoft.Win32;
using System.Text.RegularExpressions;
using System.Xml;
using System.IO;
namespace Volian.Svg.Library namespace Volian.Svg.Library
{ {
@ -77,6 +80,14 @@ namespace Volian.Svg.Library
} }
public partial class Svg : SvgGroup public partial class Svg : SvgGroup
{ {
public void DrawMacro(string macroDef, float x, float y, PdfContentByte cb)
{
_MyContentByte = cb;
SvgMeasurement X = new SvgMeasurement(x-6, E_MeasurementUnits.PT); // Not sure why this is? seems to be a character too far to the right?
SvgMeasurement Y = new SvgMeasurement(Height.GetSizeInPoints(72) - y, E_MeasurementUnits.PT);
SvgGroup macro = this[macroDef] as SvgGroup;
macro.SvgParts.Draw(cb, MyScale.AdjustOrigin(X, Y), this,this);
}
public event SvgProcessTextEvent ProcessText; public event SvgProcessTextEvent ProcessText;
internal string OnProcessText(string myText) internal string OnProcessText(string myText)
{ {
@ -126,16 +137,27 @@ namespace Volian.Svg.Library
get { return _TopMargin; } get { return _TopMargin; }
set { _TopMargin = value; } set { _TopMargin = value; }
} }
private SvgScale _MyScale;
public SvgScale MyScale
{
get
{
if (_MyScale == null)
{
_MyScale = new SvgScale(72, new System.Drawing.RectangleF(0, 0, _MyContentByte.PdfWriter.PageSize.Width, _MyContentByte.PdfWriter.PageSize.Height), _Width, _Height, _ViewBox);
_MyScale.XLowerLimit -= _LeftMargin;
_MyScale.YLowerLimit -= _TopMargin;
}
return _MyScale;
}
}
public void Draw(PdfContentByte cb) public void Draw(PdfContentByte cb)
{ {
//myPdf.Clear(); //myPdf.Clear();
_MyContentByte = cb; _MyContentByte = cb;
_Templates = new Dictionary<string, PdfTemplate>(); _Templates = new Dictionary<string, PdfTemplate>();
//RegisterFonts(); //RegisterFonts();
SvgScale scale = new SvgScale(72, new System.Drawing.RectangleF(0, 0, cb.PdfWriter.PageSize.Width, cb.PdfWriter.PageSize.Height), _Width, _Height, _ViewBox); SvgParts.Draw(cb, MyScale, this, this); //72 - Points
scale.XLowerLimit-=_LeftMargin;
scale.YLowerLimit -= _TopMargin;
SvgParts.Draw(cb, scale, this, this); //72 - Points
} }
public static iTextSharp.text.Font GetFont(string fontName) public static iTextSharp.text.Font GetFont(string fontName)
{ {
@ -388,10 +410,10 @@ namespace Volian.Svg.Library
{ {
//cb.SetLineWidth(scale.M(LineWidth)); //cb.SetLineWidth(scale.M(LineWidth));
cb.SetLineWidth(LineWidth.Value); cb.SetLineWidth(LineWidth.Value);
//cb.SetColorStroke(new Color(LineColor)); cb.SetColorStroke(new Color(LineColor));
cb.SetColorStroke(Color.BLACK); //cb.SetColorStroke(Color.BLACK);
} }
cb.SetColorStroke(Color.GREEN); //cb.SetColorStroke(Color.GREEN);
cb.SetLineCap(PdfContentByte.LINE_CAP_ROUND); cb.SetLineCap(PdfContentByte.LINE_CAP_ROUND);
cb.MoveTo(scale.X(X1), scale.Y(cb, Y1)); cb.MoveTo(scale.X(X1), scale.Y(cb, Y1));
cb.LineTo(scale.X(X2), scale.Y(cb, Y2)); cb.LineTo(scale.X(X2), scale.Y(cb, Y2));
@ -470,33 +492,33 @@ namespace Volian.Svg.Library
tmp.RestoreState(); tmp.RestoreState();
} }
} }
public partial class SvgRtf : SvgShapePart //public partial class SvgRtf : SvgShapePart
{ //{
public override void Draw(PdfContentByte cb, SvgScale scale, Svg mySvg, SvgPartInheritance myParent) // public override void Draw(PdfContentByte cb, SvgScale scale, Svg mySvg, SvgPartInheritance myParent)
{ // {
ColumnText ct = new ColumnText(cb); // ColumnText ct = new ColumnText(cb);
IRtfDocument myRtf = RtfInterpreterTool.BuildDoc(Rtf); // IRtfDocument myRtf = RtfInterpreterTool.BuildDoc(Rtf);
Rtf2iTextSharp rtf = new Rtf2iTextSharp(myRtf); // Rtf2iTextSharp rtf = new Rtf2iTextSharp(myRtf);
Paragraph p = rtf.Convert(); // Paragraph p = rtf.Convert();
p.SetLeading(0, 1); // p.SetLeading(0, 1);
float leading = 10; // float leading = 10;
ct.SetSimpleColumn(scale.X(X), scale.Y(cb, Y) + leading, scale.X(X) + scale.M(Width), scale.Y(cb, Y) - cb.PdfDocument.PageSize.Height); // ct.SetSimpleColumn(scale.X(X), scale.Y(cb, Y) + leading, scale.X(X) + scale.M(Width), scale.Y(cb, Y) - cb.PdfDocument.PageSize.Height);
ct.AddElement(p); // ct.AddElement(p);
ct.Go(); // ct.Go();
} // }
public override void Draw(PdfTemplate tmp, SvgScale scale, Svg mySvg, SvgPartInheritance myParent) // public override void Draw(PdfTemplate tmp, SvgScale scale, Svg mySvg, SvgPartInheritance myParent)
{ // {
ColumnText ct = new ColumnText(tmp); // ColumnText ct = new ColumnText(tmp);
IRtfDocument myRtf = RtfInterpreterTool.BuildDoc(Rtf); // IRtfDocument myRtf = RtfInterpreterTool.BuildDoc(Rtf);
Rtf2iTextSharp rtf = new Rtf2iTextSharp(myRtf); // Rtf2iTextSharp rtf = new Rtf2iTextSharp(myRtf);
Paragraph p = rtf.Convert(); // Paragraph p = rtf.Convert();
p.SetLeading(0, 1); // p.SetLeading(0, 1);
float leading = 10; // float leading = 10;
ct.SetSimpleColumn(scale.X(X), scale.Y(Y) + leading, scale.X(X) + scale.M(Width), scale.Y(Y) - tmp.PdfDocument.PageSize.Height); // ct.SetSimpleColumn(scale.X(X), scale.Y(Y) + leading, scale.X(X) + scale.M(Width), scale.Y(Y) - tmp.PdfDocument.PageSize.Height);
ct.AddElement(p); // ct.AddElement(p);
ct.Go(); // ct.Go();
} // }
} //}
public partial class SvgText : SvgShapePart public partial class SvgText : SvgShapePart
{ {
public override void Draw(PdfContentByte cb, SvgScale scale, Svg mySvg, SvgPartInheritance myParent) public override void Draw(PdfContentByte cb, SvgScale scale, Svg mySvg, SvgPartInheritance myParent)
@ -577,15 +599,14 @@ namespace Volian.Svg.Library
float Offset = 0; float Offset = 0;
if (Font.Underline) if (Font.Underline)
{ {
chk.SetUnderline(iTextSharp.text.Color.GREEN, 0, 0.047F, 0, -.1373F, PdfContentByte.LINE_CAP_ROUND); chk.SetUnderline(new Color(FillColor), 0, 0.047F, 0, -.1373F, PdfContentByte.LINE_CAP_ROUND);
} }
Phrase ph = new Phrase(chk); Phrase ph = new Phrase(chk);
//Paragraph ph = new Paragraph(chk); //Paragraph ph = new Paragraph(chk);
ct.SetSimpleColumn(x, y + ph.Leading + Offset, xRight + 1F, y + ph.Leading + Offset - 2 * font.Size); ct.SetSimpleColumn(x, y + ph.Leading + Offset, xRight + 1F, y + ph.Leading + Offset - 2 * font.Size);
ct.AddElement(ph); ct.AddElement(ph);
cb.SaveState(); cb.SaveState();
//cb.SetColorStroke(iTextSharp.text.Color.RED); cb.SetColorFill(new Color(FillColor));
cb.SetColorFill(iTextSharp.text.Color.GREEN);
ct.Go(); ct.Go();
cb.RestoreState(); cb.RestoreState();
//Console.WriteLine("'{0}',{1},{2},{3},{4}", Text, scale.X(X), yScale, X, Y); //Console.WriteLine("'{0}',{1},{2},{3},{4}", Text, scale.X(X), yScale, X, Y);
@ -642,148 +663,148 @@ namespace Volian.Svg.Library
tmp.RestoreState(); tmp.RestoreState();
} }
} }
public class Rtf2iTextSharp : RtfVisualVisitorBase //public class Rtf2iTextSharp : RtfVisualVisitorBase
{ //{
private IRtfDocument _RtfDoc; // private IRtfDocument _RtfDoc;
private Paragraph _MyParagraph = new Paragraph(); // private Paragraph _MyParagraph = new Paragraph();
// public Rtf2iTextSharp(IRtfDocument rtfDoc, Document doc, PdfWriter writer) // // public Rtf2iTextSharp(IRtfDocument rtfDoc, Document doc, PdfWriter writer)
public Rtf2iTextSharp(IRtfDocument rtfDoc) // public Rtf2iTextSharp(IRtfDocument rtfDoc)
{ // {
if (rtfDoc == null) // if (rtfDoc == null)
throw new ArgumentNullException("rtfDoc"); // throw new ArgumentNullException("rtfDoc");
_RtfDoc = rtfDoc; // _RtfDoc = rtfDoc;
} // }
public Paragraph Convert() // public Paragraph Convert()
{ // {
_MyParagraph.Clear(); // _MyParagraph.Clear();
foreach (IRtfVisual visual in _RtfDoc.VisualContent) // foreach (IRtfVisual visual in _RtfDoc.VisualContent)
visual.Visit(this); // visual.Visit(this);
//_MyParagraph.SetLeading(0, 1); // //_MyParagraph.SetLeading(0, 1);
return _MyParagraph; // return _MyParagraph;
} // }
// ---------------------------------------------------------------------- // // ----------------------------------------------------------------------
protected override void DoVisitBreak(IRtfVisualBreak visualBreak) // protected override void DoVisitBreak(IRtfVisualBreak visualBreak)
{ // {
switch (visualBreak.BreakKind) // switch (visualBreak.BreakKind)
{ // {
case RtfVisualBreakKind.Line: // case RtfVisualBreakKind.Line:
break; // break;
case RtfVisualBreakKind.Page: // case RtfVisualBreakKind.Page:
break; // break;
case RtfVisualBreakKind.Paragraph: // case RtfVisualBreakKind.Paragraph:
//_MyParagraph.Add("\r\n"); // //_MyParagraph.Add("\r\n");
break; // break;
case RtfVisualBreakKind.Section: // case RtfVisualBreakKind.Section:
break; // break;
default: // default:
break; // break;
} // }
//_MyParagraph.Add(string.Format("<{0}>", visualBreak.BreakKind.ToString())); // //_MyParagraph.Add(string.Format("<{0}>", visualBreak.BreakKind.ToString()));
} // }
protected override void DoVisitSpecial(IRtfVisualSpecialChar visualSpecialChar) // protected override void DoVisitSpecial(IRtfVisualSpecialChar visualSpecialChar)
{ // {
//_MyParagraph.Add(string.Format("<special {0}>", visualSpecialChar.CharKind.ToString())); // //_MyParagraph.Add(string.Format("<special {0}>", visualSpecialChar.CharKind.ToString()));
switch (visualSpecialChar.CharKind) // switch (visualSpecialChar.CharKind)
{ // {
case RtfVisualSpecialCharKind.Bullet: // case RtfVisualSpecialCharKind.Bullet:
break; // break;
case RtfVisualSpecialCharKind.EmDash: // case RtfVisualSpecialCharKind.EmDash:
break; // break;
case RtfVisualSpecialCharKind.EmSpace: // case RtfVisualSpecialCharKind.EmSpace:
break; // break;
case RtfVisualSpecialCharKind.EnDash: // case RtfVisualSpecialCharKind.EnDash:
break; // break;
case RtfVisualSpecialCharKind.EnSpace: // case RtfVisualSpecialCharKind.EnSpace:
break; // break;
case RtfVisualSpecialCharKind.LeftDoubleQuote: // case RtfVisualSpecialCharKind.LeftDoubleQuote:
break; // break;
case RtfVisualSpecialCharKind.LeftSingleQuote: // case RtfVisualSpecialCharKind.LeftSingleQuote:
break; // break;
case RtfVisualSpecialCharKind.NonBreakingHyphen: // case RtfVisualSpecialCharKind.NonBreakingHyphen:
break; // break;
case RtfVisualSpecialCharKind.NonBreakingSpace: // case RtfVisualSpecialCharKind.NonBreakingSpace:
_MyParagraph.Add(new Chunk("\u00A0")); // _MyParagraph.Add(new Chunk("\u00A0"));
break; // break;
case RtfVisualSpecialCharKind.OptionalHyphen: // case RtfVisualSpecialCharKind.OptionalHyphen:
break; // break;
case RtfVisualSpecialCharKind.ParagraphNumberBegin: // case RtfVisualSpecialCharKind.ParagraphNumberBegin:
break; // break;
case RtfVisualSpecialCharKind.ParagraphNumberEnd: // case RtfVisualSpecialCharKind.ParagraphNumberEnd:
break; // break;
case RtfVisualSpecialCharKind.QmSpace: // case RtfVisualSpecialCharKind.QmSpace:
break; // break;
case RtfVisualSpecialCharKind.RightDoubleQuote: // case RtfVisualSpecialCharKind.RightDoubleQuote:
break; // break;
case RtfVisualSpecialCharKind.RightSingleQuote: // case RtfVisualSpecialCharKind.RightSingleQuote:
break; // break;
case RtfVisualSpecialCharKind.Tabulator: // case RtfVisualSpecialCharKind.Tabulator:
break; // break;
default: // default:
break; // break;
} // }
} // }
//private static Dictionary<string, BaseFont> _MyBaseFonts = new Dictionary<string, BaseFont>(); // //private static Dictionary<string, BaseFont> _MyBaseFonts = new Dictionary<string, BaseFont>();
//private static BaseFont GetBaseFont(string fontName) // //private static BaseFont GetBaseFont(string fontName)
//{ // //{
// if (!_MyBaseFonts.ContainsKey(fontName)) // // if (!_MyBaseFonts.ContainsKey(fontName))
// _MyBaseFonts.Add(fontName, BaseFont.CreateFont(FontFind.FullFileName(fontName), BaseFont.IDENTITY_H, BaseFont.EMBEDDED)); // // _MyBaseFonts.Add(fontName, BaseFont.CreateFont(FontFind.FullFileName(fontName), BaseFont.IDENTITY_H, BaseFont.EMBEDDED));
// return _MyBaseFonts[fontName]; // // return _MyBaseFonts[fontName];
//} // //}
//private static Dictionary<string, iTextSharp.text.Font> _MyFonts = new Dictionary<string, iTextSharp.text.Font>(); // //private static Dictionary<string, iTextSharp.text.Font> _MyFonts = new Dictionary<string, iTextSharp.text.Font>();
//private static iTextSharp.text.Font GetFont(string fontName, int size, int style) // //private static iTextSharp.text.Font GetFont(string fontName, int size, int style)
//{ // //{
// string key = string.Format("{0}.{1}.{2}", fontName, size, style); // // string key = string.Format("{0}.{1}.{2}", fontName, size, style);
// if (!_MyFonts.ContainsKey(key)) // // if (!_MyFonts.ContainsKey(key))
// _MyFonts.Add(key, new iTextSharp.text.Font(GetBaseFont(fontName), size / 2, style)); // // _MyFonts.Add(key, new iTextSharp.text.Font(GetBaseFont(fontName), size / 2, style));
// return _MyFonts[key]; // // return _MyFonts[key];
//} // //}
//protected override void DoVisitText(IRtfVisualText visualText) // //protected override void DoVisitText(IRtfVisualText visualText)
//{ // //{
// if (visualText.Format.IsHidden) return; // // if (visualText.Format.IsHidden) return;
// //iTextSharp.text.Font font = GetFont(visualText.Format.Font.Name, visualText.Format.FontSize, // // //iTextSharp.text.Font font = GetFont(visualText.Format.Font.Name, visualText.Format.FontSize,
// // (visualText.Format.IsBold ? iTextSharp.text.Font.BOLD : 0) + (visualText.Format.IsItalic ? iTextSharp.text.Font.ITALIC : 0)); // // // (visualText.Format.IsBold ? iTextSharp.text.Font.BOLD : 0) + (visualText.Format.IsItalic ? iTextSharp.text.Font.ITALIC : 0));
// iTextSharp.text.Font font = FontFactory.GetFont(visualText.Format.Font.Name, BaseFont.IDENTITY_H, BaseFont.EMBEDDED, // // iTextSharp.text.Font font = FontFactory.GetFont(visualText.Format.Font.Name, BaseFont.IDENTITY_H, BaseFont.EMBEDDED,
// visualText.Format.FontSize / 2F);// TODO: Don't know why this is 2.4 rather than 2. // // visualText.Format.FontSize / 2F);// TODO: Don't know why this is 2.4 rather than 2.
// font.SetStyle((visualText.Format.IsBold ? iTextSharp.text.Font.BOLD : 0) + (visualText.Format.IsItalic ? iTextSharp.text.Font.ITALIC : 0)); // // font.SetStyle((visualText.Format.IsBold ? iTextSharp.text.Font.BOLD : 0) + (visualText.Format.IsItalic ? iTextSharp.text.Font.ITALIC : 0));
// font.Color = new iTextSharp.text.Color(visualText.Format.ForegroundColor.AsDrawingColor); // // font.Color = new iTextSharp.text.Color(visualText.Format.ForegroundColor.AsDrawingColor);
// Chunk chk = new Chunk(visualText.Text, font); // // Chunk chk = new Chunk(visualText.Text, font);
// chk.SetBackground(new iTextSharp.text.Color(visualText.Format.BackgroundColor.AsDrawingColor)); // // chk.SetBackground(new iTextSharp.text.Color(visualText.Format.BackgroundColor.AsDrawingColor));
// if (visualText.Format.IsStrikeThrough) // // if (visualText.Format.IsStrikeThrough)
// chk.SetUnderline(iTextSharp.text.Color.BLACK, 0, 0.05F, 0, .3F, PdfContentByte.LINE_CAP_ROUND); // Relative Based upon font size // // chk.SetUnderline(iTextSharp.text.Color.BLACK, 0, 0.05F, 0, .3F, PdfContentByte.LINE_CAP_ROUND); // Relative Based upon font size
// if (visualText.Format.IsUnderline) // // if (visualText.Format.IsUnderline)
// chk.SetUnderline(iTextSharp.text.Color.BLACK, 0, 0.05F, 0, -.09F, PdfContentByte.LINE_CAP_ROUND); // Relative Based upon font size // // chk.SetUnderline(iTextSharp.text.Color.BLACK, 0, 0.05F, 0, -.09F, PdfContentByte.LINE_CAP_ROUND); // Relative Based upon font size
// if (visualText.Format.SuperScript == -1) // // if (visualText.Format.SuperScript == -1)
// chk.SetTextRise(.45F * chk.Font.Size); // // chk.SetTextRise(.45F * chk.Font.Size);
// else if (visualText.Format.SuperScript == 1) // // else if (visualText.Format.SuperScript == 1)
// chk.SetTextRise(-.25F * chk.Font.Size); // // chk.SetTextRise(-.25F * chk.Font.Size);
// //Console.WriteLine("\"RTF FontSize\",{0},{1}", visualText.Format.FontSize / 2,chk.Font.Size); // // //Console.WriteLine("\"RTF FontSize\",{0},{1}", visualText.Format.FontSize / 2,chk.Font.Size);
// _MyParagraph.Add(chk); // // _MyParagraph.Add(chk);
//}// DoVisitText // //}// DoVisitText
// ---------------------------------------------------------------------- // // ----------------------------------------------------------------------
protected override void DoVisitImage(IRtfVisualImage visualImage) // protected override void DoVisitImage(IRtfVisualImage visualImage)
{ // {
_MyParagraph.Add(new Chunk("<Image>")); // _MyParagraph.Add(new Chunk("<Image>"));
//WriteStartElement("rtfVisualImage"); // //WriteStartElement("rtfVisualImage");
//WriteElementString("format", visualImage.Format.ToString()); // //WriteElementString("format", visualImage.Format.ToString());
//WriteElementString("width", visualImage.Width.ToString()); // //WriteElementString("width", visualImage.Width.ToString());
//WriteElementString("height", visualImage.Height.ToString()); // //WriteElementString("height", visualImage.Height.ToString());
//WriteElementString("desiredWidth", visualImage.DesiredWidth.ToString()); // //WriteElementString("desiredWidth", visualImage.DesiredWidth.ToString());
//WriteElementString("desiredHeight", visualImage.DesiredHeight.ToString()); // //WriteElementString("desiredHeight", visualImage.DesiredHeight.ToString());
//WriteElementString("scaleWidthPercent", visualImage.ScaleWidthPercent.ToString()); // //WriteElementString("scaleWidthPercent", visualImage.ScaleWidthPercent.ToString());
//WriteElementString("scaleHeightPercent", visualImage.ScaleHeightPercent.ToString()); // //WriteElementString("scaleHeightPercent", visualImage.ScaleHeightPercent.ToString());
//WriteElementString("alignment", visualImage.Alignment.ToString()); // //WriteElementString("alignment", visualImage.Alignment.ToString());
//WriteElementString("image", visualImage.ImageDataHex.ToString()); // //WriteElementString("image", visualImage.ImageDataHex.ToString());
//WriteEndElement(); // //WriteEndElement();
} // DoVisitImage // } // DoVisitImage
} //}
public class SvgPageTotal public class SvgPageTotal
{ {
public SvgPageTotal(System.Drawing.Font myFont, PdfContentByte cb) public SvgPageTotal(System.Drawing.Font myFont, PdfContentByte cb)
@ -833,14 +854,49 @@ namespace Volian.Svg.Library
set { _MySvg = value; } set { _MySvg = value; }
} }
private PdfLayer _PageListLayer; private PdfLayer _PageListLayer;
public PdfLayer PageListLayer
{
get { return _PageListLayer; }
set { _PageListLayer = value; }
}
private PdfLayer _WatermarkLayer; private PdfLayer _WatermarkLayer;
public SvgPageHelper(Svg mySvg, PdfLayer pageListLayer, PdfLayer watermarkLayer) public PdfLayer WatermarkLayer
{
get { return _WatermarkLayer; }
set { _WatermarkLayer = value; }
}
private string _Watermark=string.Empty;
public string Watermark
{
get { return _Watermark; }
set { _Watermark = value.ToUpper()=="NONE"?"":value; }
}
private int _CurrentPageNumber = 0;
public int CurrentPageNumber
{
get { return _CurrentPageNumber; }
set { _CurrentPageNumber = value; }
}
public SvgPageHelper(Svg mySvg)
{ {
//_MySvg = _MyNextSvg = mySvg; //_MySvg = _MyNextSvg = mySvg;
_MySvg = mySvg; _MySvg = mySvg;
_PageListLayer = pageListLayer;
_WatermarkLayer = watermarkLayer;
} }
public SvgPageHelper()
{
}
private int _BGPageOffset = 0;
public int BackgroundPageOffset
{
get { return _BGPageOffset; }
set { _BGPageOffset = value; }
}
//private Regex regexReplaceTokens = new Regex(@"{[^{}]}");
protected virtual string ReplacePageListToken(Match match)
{
return string.Empty;
}
public override void OnOpenDocument(PdfWriter writer, Document document) public override void OnOpenDocument(PdfWriter writer, Document document)
{ {
//base.OnOpenDocument(writer, document); //base.OnOpenDocument(writer, document);
@ -851,7 +907,80 @@ namespace Volian.Svg.Library
public override void OnEndPage(PdfWriter writer, Document document) public override void OnEndPage(PdfWriter writer, Document document)
{ {
base.OnEndPage(writer, document); base.OnEndPage(writer, document);
PdfContentByte cb = writer.DirectContent; DrawBackground(writer.DirectContentUnder);
DrawPageList(writer.DirectContent);
DrawWatermark(writer.DirectContentUnder);
DrawZoomOMatic(writer.DirectContent);
CurrentPageNumber++;
}
private PdfReader _BackgroundReader = null;
public PdfReader BackgroundReader
{
get
{
if (_BackgroundReader == null && _BackgroundFile != null && File.Exists(_BackgroundFile))
_BackgroundReader = new PdfReader(_BackgroundFile);
return _BackgroundReader;
}
}
private string _BackgroundFile = null;
public string BackgroundFile
{
get { return _BackgroundFile; }
set { _BackgroundFile = value; }
}
private PdfLayer _BackgroundLayer = null;
public PdfLayer BackgroundLayer
{
get { return _BackgroundLayer; }
set { _BackgroundLayer = value; }
}
private System.Drawing.PointF _BackgroundOffset = new System.Drawing.PointF(0, 0);
public System.Drawing.PointF BackgroundOffset
{
get { return _BackgroundOffset; }
set { _BackgroundOffset = value; }
}
public int BackgroundPageCount
{
get { return BackgroundReader == null ? 0 : BackgroundReader.NumberOfPages; }
}
private PdfImportedPage GetBackgroundPage(PdfContentByte cb)
{
if (BackgroundReader == null) return null;
int page = CurrentPageNumber + BackgroundPageOffset;
if (page < 1 || page > BackgroundPageCount) return null;
return cb.PdfWriter.GetImportedPage(BackgroundReader, page);
}
private void DrawBackground(PdfContentByte cb)
{
PdfImportedPage backgroundPage = GetBackgroundPage(cb);
if (backgroundPage == null) return;
if(BackgroundLayer != null) cb.BeginLayer(BackgroundLayer);
iTextSharp.text.Image image = iTextSharp.text.Image.GetInstance(backgroundPage);
image.SetAbsolutePosition(BackgroundOffset.X,BackgroundOffset.Y);
cb.AddImage(image);
if (BackgroundLayer != null) cb.EndLayer();
}
private void DrawZoomOMatic(PdfContentByte cb)
{
cb.SaveState();
ZoomOMatic(cb, 18);
cb.RestoreState();
}
private void DrawWatermark(PdfContentByte cb)
{
if (Watermark.ToLower() == "(none)" || Watermark == "") return;
cb.SaveState();
if (_WatermarkLayer != null) cb.BeginLayer(_WatermarkLayer);
SvgWatermark myWatermark = new SvgWatermark(cb, Watermark, System.Drawing.Color.Blue, .15F);
myWatermark.SetSquareDotPattern(.7F);
myWatermark.Draw();
if (_WatermarkLayer != null) cb.EndLayer();
cb.RestoreState();
}
private void DrawPageList(PdfContentByte cb)
{
cb.SaveState(); cb.SaveState();
if (_PageListLayer != null) cb.BeginLayer(_PageListLayer); if (_PageListLayer != null) cb.BeginLayer(_PageListLayer);
// Do anything needed to finish off the page // Do anything needed to finish off the page
@ -859,20 +988,6 @@ namespace Volian.Svg.Library
//_MySvg = _MyNextSvg; // After doing to current page update the Svg for the next page. //_MySvg = _MyNextSvg; // After doing to current page update the Svg for the next page.
if (_PageListLayer != null) cb.EndLayer(); if (_PageListLayer != null) cb.EndLayer();
cb.RestoreState(); cb.RestoreState();
if (_MySvg.Watermark.ToLower() != "(none)" && _MySvg.Watermark != "")
{
cb = writer.DirectContentUnder;
cb.SaveState();
if (_WatermarkLayer != null) cb.BeginLayer(_WatermarkLayer);
SvgWatermark myWatermark = new SvgWatermark(cb, _MySvg.Watermark, System.Drawing.Color.Blue, .5F);
myWatermark.SetSquareDotPattern(.7F);
myWatermark.Draw();
if (_WatermarkLayer != null) cb.EndLayer();
cb.RestoreState();
}
cb.SaveState();
ZoomOMatic(cb, 18);
cb.RestoreState();
} }
private void ZoomOMatic(PdfContentByte cb, float size) private void ZoomOMatic(PdfContentByte cb, float size)
{ {
@ -964,7 +1079,7 @@ namespace Volian.Svg.Library
{ {
_PatternPainter = _ContentByte.CreatePattern(radius * 4, radius * 2, radius * 4, radius * 2); _PatternPainter = _ContentByte.CreatePattern(radius * 4, radius * 2, radius * 4, radius * 2);
PdfGState gState = new PdfGState(); PdfGState gState = new PdfGState();
gState.FillOpacity = _Opacity; gState.FillOpacity = .5f * _Opacity;
_PatternPainter.SetGState(gState); _PatternPainter.SetGState(gState);
_PatternPainter.SetColorFill(_Color); _PatternPainter.SetColorFill(_Color);
_PatternPainter.Rectangle(0, 0, radius, radius); _PatternPainter.Rectangle(0, 0, radius, radius);