Set the plot background to white if not doing compare and transparent if doing a compare.
Add logic to exclude high level steps from those items included in the Replace Words list for substeps. Removed event handlers for DSOFramer. It appears that these no longer work for MSWord 2013. New Watermark Logic
This commit is contained in:
@@ -916,7 +916,7 @@ namespace Volian.Svg.Library
|
||||
{
|
||||
DrawBackground(writer.DirectContentUnder);
|
||||
DrawPageList(writer.DirectContent);
|
||||
DrawWatermark(writer.DirectContentUnder);
|
||||
DrawWatermark(writer.DirectContent);
|
||||
if (DoZoomOMatic) DrawZoomOMatic(writer.DirectContent);
|
||||
}
|
||||
CurrentPageNumber++;
|
||||
@@ -927,7 +927,7 @@ namespace Volian.Svg.Library
|
||||
{
|
||||
DrawBackground(writer.DirectContentUnder);
|
||||
DrawPageList(writer.DirectContent);
|
||||
DrawWatermark(writer.DirectContentUnder);
|
||||
DrawWatermark(writer.DirectContent);
|
||||
if (DoZoomOMatic) DrawZoomOMatic(writer.DirectContent);
|
||||
CurrentPageNumber++;
|
||||
}
|
||||
@@ -1009,7 +1009,7 @@ namespace Volian.Svg.Library
|
||||
cb.SaveState();
|
||||
if (_WatermarkLayer != null) cb.BeginLayer(_WatermarkLayer);
|
||||
SvgWatermark myWatermark = new SvgWatermark(cb, Watermark, System.Drawing.Color.Blue, .15F);
|
||||
myWatermark.SetSquareDotPattern(.7F);
|
||||
//myWatermark.SetSquareDotPattern(.7F);
|
||||
myWatermark.Draw();
|
||||
if (_WatermarkLayer != null) cb.EndLayer();
|
||||
cb.RestoreState();
|
||||
@@ -1078,119 +1078,170 @@ namespace Volian.Svg.Library
|
||||
{
|
||||
_ContentByte = contentByte;
|
||||
_Text = text;
|
||||
float radius = .5F;
|
||||
float space = 3;
|
||||
//float radius = .5F;
|
||||
//float space = 3;
|
||||
_Color = new Color(color);
|
||||
_Opacity = opacity;
|
||||
SetDotPattern(radius, space);
|
||||
SetTextLayout();
|
||||
}
|
||||
private void SetTextLayout()
|
||||
{
|
||||
Rectangle pageSize = _ContentByte.PdfWriter.PageSize; // Get page size
|
||||
_Basefont = BaseFont.CreateFont(BaseFont.HELVETICA_BOLD, Encoding.ASCII.EncodingName, BaseFont.EMBEDDED);
|
||||
float hgtA = _Basefont.GetAscentPoint(_Text, 12);
|
||||
//float hgtD = basefont.GetDescentPoint(text,20);
|
||||
float wid = _Basefont.GetWidthPointKerned(_Text, 12);
|
||||
//Console.WriteLine("{0} {1} {2}",hgtA,hgtD,wid);
|
||||
float rho = wid / hgtA;
|
||||
float x2 = (rho * pageSize.Height - pageSize.Width) / (rho * rho - 1);
|
||||
float y1 = x2 * rho;
|
||||
float y2 = pageSize.Height - y1;
|
||||
float x1 = pageSize.Width - x2;
|
||||
_XOffset = x2 + x1 / 2;
|
||||
_YOffset = y1 / 2;
|
||||
_TextAngle = CalcAngle(y1, x1);
|
||||
_Fontsize = (float)(10 * Math.Sqrt(x2 * x2 + y2 * y2) / hgtA);
|
||||
}
|
||||
public void SetDotPattern(float radius, float space)
|
||||
{
|
||||
_PatternPainter = _ContentByte.CreatePattern(radius * 2, radius * 2, radius * 2 + space, radius * 2 + space);
|
||||
PdfGState gState = new PdfGState();
|
||||
gState.FillOpacity = _Opacity;
|
||||
_PatternPainter.SetGState(gState);
|
||||
_PatternPainter.SetColorFill(_Color);
|
||||
_PatternPainter.Circle(radius, radius, radius);
|
||||
_PatternPainter.Fill();
|
||||
}
|
||||
public void SetSquareDotPattern(float radius)
|
||||
{
|
||||
_PatternPainter = _ContentByte.CreatePattern(radius * 4, radius * 2, radius * 4, radius * 2);
|
||||
PdfGState gState = new PdfGState();
|
||||
gState.FillOpacity = .5f * _Opacity;
|
||||
_PatternPainter.SetGState(gState);
|
||||
_PatternPainter.SetColorFill(_Color);
|
||||
_PatternPainter.Rectangle(0, 0, radius, radius);
|
||||
_PatternPainter.Rectangle(radius * 2, radius, radius, radius);
|
||||
_PatternPainter.Fill();
|
||||
}
|
||||
public void SetHashPattern(float thickness, float size)
|
||||
{
|
||||
_PatternPainter = _ContentByte.CreatePattern(size, size, size, size);
|
||||
PdfGState gState = new PdfGState();
|
||||
gState.FillOpacity = _Opacity;
|
||||
gState.StrokeOpacity = _Opacity;
|
||||
_PatternPainter.SetGState(gState);
|
||||
_PatternPainter.SetLineWidth(.01F);
|
||||
_PatternPainter.SetColorStroke(_Color); // Set color
|
||||
_PatternPainter.MoveTo(0, 0);
|
||||
_PatternPainter.LineTo(size, size);
|
||||
_PatternPainter.MoveTo(size, 0);
|
||||
_PatternPainter.LineTo(0, size);
|
||||
_PatternPainter.Stroke();
|
||||
}
|
||||
public void SetTextPattern(float fontSize, float space)
|
||||
{
|
||||
float hgtA = _Basefont.GetAscentPoint(_Text, fontSize) + _Basefont.GetDescentPoint(_Text, fontSize);
|
||||
float wid = _Basefont.GetWidthPointKerned(_Text, fontSize);
|
||||
_PatternPainter = _ContentByte.CreatePattern(wid, hgtA, wid + space, hgtA + space);
|
||||
_PatternPainter.SetFontAndSize(_Basefont, fontSize);
|
||||
_PatternPainter.BoundingBox = new Rectangle(-20, -20, 100, 100);
|
||||
_PatternPainter.BeginText();
|
||||
PdfGState gs1 = new PdfGState();
|
||||
gs1.FillOpacity = _Opacity;
|
||||
_PatternPainter.SetGState(gs1);
|
||||
_PatternPainter.SetColorFill(_Color); // Set color
|
||||
_PatternPainter.ShowText(_Text);
|
||||
_PatternPainter.EndText();
|
||||
}
|
||||
public void SetTextPattern2(float fontSize)
|
||||
{
|
||||
BaseFont _Basefont2 = BaseFont.CreateFont(BaseFont.HELVETICA, Encoding.ASCII.EncodingName, BaseFont.EMBEDDED);
|
||||
float hgtA = _Basefont2.GetAscentPoint(_Text, fontSize);
|
||||
float wid = _Basefont2.GetWidthPointKerned(_Text, fontSize);
|
||||
_PatternPainter = _ContentByte.CreatePattern(wid * 2, hgtA * 2, wid * 2, hgtA * 2);
|
||||
_PatternPainter.SetFontAndSize(_Basefont2, fontSize);
|
||||
_PatternPainter.BoundingBox = new Rectangle(-20, -20, 100, 100);
|
||||
_PatternPainter.BeginText();
|
||||
PdfGState gs1 = new PdfGState();
|
||||
gs1.FillOpacity = _Opacity;
|
||||
_PatternPainter.SetGState(gs1);
|
||||
_PatternPainter.SetColorFill(_Color); // Set color
|
||||
_PatternPainter.ShowText(_Text);
|
||||
_PatternPainter.ShowTextAligned(PdfContentByte.ALIGN_LEFT, _Text, wid, hgtA, 0);
|
||||
_PatternPainter.EndText();
|
||||
//SetDotPattern(radius, space);
|
||||
//SetTextLayout();
|
||||
}
|
||||
//private void SetTextLayout()
|
||||
//{
|
||||
// Rectangle pageSize = _ContentByte.PdfWriter.PageSize; // Get page size
|
||||
// _Basefont = BaseFont.CreateFont(BaseFont.HELVETICA_BOLD, Encoding.ASCII.EncodingName, BaseFont.EMBEDDED);
|
||||
// float hgtA = _Basefont.GetAscentPoint(_Text, 12);
|
||||
// //float hgtD = basefont.GetDescentPoint(text,20);
|
||||
// float wid = _Basefont.GetWidthPointKerned(_Text, 12);
|
||||
// //Console.WriteLine("{0} {1} {2}",hgtA,hgtD,wid);
|
||||
// float rho = wid / hgtA;
|
||||
// float x2 = (rho * pageSize.Height - pageSize.Width) / (rho * rho - 1);
|
||||
// float y1 = x2 * rho;
|
||||
// float y2 = pageSize.Height - y1;
|
||||
// float x1 = pageSize.Width - x2;
|
||||
// _XOffset = x2 + x1 / 2;
|
||||
// _YOffset = y1 / 2;
|
||||
// _TextAngle = CalcAngle(y1, x1);
|
||||
// _Fontsize = (float)(10 * Math.Sqrt(x2 * x2 + y2 * y2) / hgtA);
|
||||
//}
|
||||
//public void SetDotPattern(float radius, float space)
|
||||
//{
|
||||
// _PatternPainter = _ContentByte.CreatePattern(radius * 2, radius * 2, radius * 2 + space, radius * 2 + space);
|
||||
// PdfGState gState = new PdfGState();
|
||||
// gState.FillOpacity = _Opacity;
|
||||
// _PatternPainter.SetGState(gState);
|
||||
// _PatternPainter.SetColorFill(_Color);
|
||||
// _PatternPainter.Circle(radius, radius, radius);
|
||||
// _PatternPainter.Fill();
|
||||
//}
|
||||
//public void SetSquareDotPattern(float radius)
|
||||
//{
|
||||
// _PatternPainter = _ContentByte.CreatePattern(radius * 4, radius * 2, radius * 4, radius * 2);
|
||||
// PdfGState gState = new PdfGState();
|
||||
// gState.FillOpacity = .5f * _Opacity;
|
||||
// _PatternPainter.SetGState(gState);
|
||||
// _PatternPainter.SetColorFill(_Color);
|
||||
// _PatternPainter.Rectangle(0, 0, radius, radius);
|
||||
// _PatternPainter.Rectangle(radius * 2, radius, radius, radius);
|
||||
// _PatternPainter.Fill();
|
||||
//}
|
||||
//public void SetHashPattern(float thickness, float size)
|
||||
//{
|
||||
// _PatternPainter = _ContentByte.CreatePattern(size, size, size, size);
|
||||
// PdfGState gState = new PdfGState();
|
||||
// gState.FillOpacity = _Opacity;
|
||||
// gState.StrokeOpacity = _Opacity;
|
||||
// _PatternPainter.SetGState(gState);
|
||||
// _PatternPainter.SetLineWidth(.01F);
|
||||
// _PatternPainter.SetColorStroke(_Color); // Set color
|
||||
// _PatternPainter.MoveTo(0, 0);
|
||||
// _PatternPainter.LineTo(size, size);
|
||||
// _PatternPainter.MoveTo(size, 0);
|
||||
// _PatternPainter.LineTo(0, size);
|
||||
// _PatternPainter.Stroke();
|
||||
//}
|
||||
//public void SetTextPattern(float fontSize, float space)
|
||||
//{
|
||||
// float hgtA = _Basefont.GetAscentPoint(_Text, fontSize) + _Basefont.GetDescentPoint(_Text, fontSize);
|
||||
// float wid = _Basefont.GetWidthPointKerned(_Text, fontSize);
|
||||
// _PatternPainter = _ContentByte.CreatePattern(wid, hgtA, wid + space, hgtA + space);
|
||||
// _PatternPainter.SetFontAndSize(_Basefont, fontSize);
|
||||
// _PatternPainter.BoundingBox = new Rectangle(-20, -20, 100, 100);
|
||||
// _PatternPainter.BeginText();
|
||||
// PdfGState gs1 = new PdfGState();
|
||||
// gs1.FillOpacity = _Opacity;
|
||||
// _PatternPainter.SetGState(gs1);
|
||||
// _PatternPainter.SetColorFill(_Color); // Set color
|
||||
// _PatternPainter.ShowText(_Text);
|
||||
// _PatternPainter.EndText();
|
||||
//}
|
||||
//public void SetTextPattern2(float fontSize)
|
||||
//{
|
||||
// BaseFont _Basefont2 = BaseFont.CreateFont(BaseFont.HELVETICA, Encoding.ASCII.EncodingName, BaseFont.EMBEDDED);
|
||||
// float hgtA = _Basefont2.GetAscentPoint(_Text, fontSize);
|
||||
// float wid = _Basefont2.GetWidthPointKerned(_Text, fontSize);
|
||||
// _PatternPainter = _ContentByte.CreatePattern(wid * 2, hgtA * 2, wid * 2, hgtA * 2);
|
||||
// _PatternPainter.SetFontAndSize(_Basefont2, fontSize);
|
||||
// _PatternPainter.BoundingBox = new Rectangle(-20, -20, 100, 100);
|
||||
// _PatternPainter.BeginText();
|
||||
// PdfGState gs1 = new PdfGState();
|
||||
// gs1.FillOpacity = _Opacity;
|
||||
// _PatternPainter.SetGState(gs1);
|
||||
// _PatternPainter.SetColorFill(_Color); // Set color
|
||||
// _PatternPainter.ShowText(_Text);
|
||||
// _PatternPainter.ShowTextAligned(PdfContentByte.ALIGN_LEFT, _Text, wid, hgtA, 0);
|
||||
// _PatternPainter.EndText();
|
||||
//}
|
||||
public void Draw()
|
||||
{
|
||||
_ContentByte.SaveState();
|
||||
_ContentByte.BeginText();
|
||||
_ContentByte.SetPatternFill(_PatternPainter);
|
||||
_ContentByte.SetTextRenderingMode(PdfContentByte.TEXT_RENDER_MODE_FILL_STROKE);
|
||||
_ContentByte.SetLineWidth(.5F);
|
||||
_ContentByte.SetFontAndSize(_Basefont, _Fontsize);// Set font and size
|
||||
_ContentByte.SetColorStroke(_Color);
|
||||
PdfGState gs2 = new PdfGState();
|
||||
gs2.StrokeOpacity = _Opacity;
|
||||
_ContentByte.SetGState(gs2);
|
||||
_ContentByte.ShowTextAlignedKerned(PdfContentByte.ALIGN_CENTER, _Text, _XOffset, _YOffset, _TextAngle);// Draw the text
|
||||
_ContentByte.EndText();
|
||||
_ContentByte.FillStroke(); // Controlled by TextRenderMode above
|
||||
//_ContentByte.BeginText();
|
||||
//_ContentByte.SetPatternFill(_PatternPainter);
|
||||
//_ContentByte.SetTextRenderingMode(PdfContentByte.TEXT_RENDER_MODE_FILL_STROKE);
|
||||
//_ContentByte.SetLineWidth(.5F);
|
||||
//_ContentByte.SetFontAndSize(_Basefont, _Fontsize);// Set font and size
|
||||
//_ContentByte.SetColorStroke(_Color);
|
||||
//PdfGState gs2 = new PdfGState();
|
||||
//gs2.StrokeOpacity = _Opacity;
|
||||
//_ContentByte.SetGState(gs2);
|
||||
//_ContentByte.ShowTextAlignedKerned(PdfContentByte.ALIGN_CENTER, _Text, _XOffset, _YOffset, _TextAngle);// Draw the text
|
||||
//_ContentByte.EndText();
|
||||
_ContentByte.AddImage(WatermarkImage);
|
||||
_ContentByte.RestoreState();
|
||||
}
|
||||
private float CalcAngle(float opposite, float adjacent)
|
||||
//private float CalcAngle(float opposite, float adjacent)
|
||||
//{
|
||||
// return (float)(Math.Atan2(opposite, adjacent) * (180 / Math.PI));
|
||||
//}
|
||||
private Image _WatermarkImage;
|
||||
public Image WatermarkImage
|
||||
{
|
||||
return (float)(Math.Atan2(opposite, adjacent) * (180 / Math.PI));
|
||||
get
|
||||
{
|
||||
if (_WatermarkImage == null)
|
||||
{
|
||||
float fntSize = 200;
|
||||
System.Drawing.Font fnt = new System.Drawing.Font("Arial", fntSize);
|
||||
string msg = _Text;
|
||||
System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath();
|
||||
gp.AddString(msg, fnt.FontFamily, 0, fntSize, new System.Drawing.Point(0, 0),
|
||||
System.Drawing.StringFormat.GenericTypographic);
|
||||
System.Drawing.RectangleF bnds = gp.GetBounds();
|
||||
gp.Reset();
|
||||
int height = (int)bnds.Height;
|
||||
int width = (int)bnds.Width;
|
||||
System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(width + 2, height + 2);
|
||||
using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bmp))
|
||||
{
|
||||
g.FillRectangle(System.Drawing.Brushes.Transparent, 0, 0, width, height);
|
||||
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;
|
||||
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
|
||||
g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAliasGridFit;
|
||||
g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
|
||||
gp.AddString(msg, fnt.FontFamily, 0, fntSize, new System.Drawing.PointF(-bnds.X, -bnds.Y),
|
||||
System.Drawing.StringFormat.GenericTypographic);
|
||||
System.Drawing.Drawing2D.HatchBrush aHatchBrush = new System.Drawing.Drawing2D.HatchBrush(System.Drawing.Drawing2D.HatchStyle.Percent25, System.Drawing.Color.FromArgb(64,
|
||||
System.Drawing.Color.Blue), System.Drawing.Color.Transparent);
|
||||
g.FillPath(aHatchBrush, gp);
|
||||
g.DrawPath(new System.Drawing.Pen(System.Drawing.Color.FromArgb(96, System.Drawing.Color.Blue)), gp);
|
||||
//g.DrawRectangle(System.Drawing.Pens.Cyan, 0, 0, bnds.Width, bnds.Height);
|
||||
}
|
||||
_WatermarkImage = iTextSharp.text.Image.GetInstance(bmp, System.Drawing.Imaging.ImageFormat.Png);
|
||||
_WatermarkImage.SetAbsolutePosition(72, 72);
|
||||
float H = _ContentByte.PdfWriter.PageSize.Height - 144;
|
||||
float W = _ContentByte.PdfWriter.PageSize.Width - 144;
|
||||
float ratio = bnds.Width / bnds.Height;
|
||||
float W2 = (H - W / ratio) / (ratio - 1 / ratio);
|
||||
float W1 = W - W2;
|
||||
float H1 = (float)(Math.Sqrt(-4*(W1*W2)+H*H)+H)/2;
|
||||
float H2 = H-H1;
|
||||
float Theta = (float) Math.Atan(H1 / W1);
|
||||
float h = H2 / (float) Math.Cos(Theta);
|
||||
float w = H1 / (float) Math.Sin(Theta);
|
||||
_WatermarkImage.Rotation = Theta; // 3.141592653F / 4;
|
||||
_WatermarkImage.ScaleAbsolute(w, h);
|
||||
}
|
||||
return _WatermarkImage;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user