C2022-004 Logic to decode ARGB colors and logic to not rotate watermarks that are only one or two characters long
This commit is contained in:
parent
78e408706e
commit
311e597338
@ -1151,6 +1151,38 @@ namespace Volian.Svg.Library
|
|||||||
get { return _AllowAllWatermarks; }
|
get { return _AllowAllWatermarks; }
|
||||||
set { _AllowAllWatermarks = value; }
|
set { _AllowAllWatermarks = value; }
|
||||||
}
|
}
|
||||||
|
//C2022-004 This will return the system drawing color from either the color name or ARGB values
|
||||||
|
public System.Drawing.Color GetWatermarkColor(string colorDescription)
|
||||||
|
{
|
||||||
|
System.Drawing.Color systemColor;
|
||||||
|
if (colorDescription.StartsWith("[A=")) // if color is ARGB representation, parse out the values
|
||||||
|
{
|
||||||
|
// initialize the ARGB value to white
|
||||||
|
int Alpha = 255;
|
||||||
|
int Red = 255;
|
||||||
|
int Green = 255;
|
||||||
|
int Blue = 255;
|
||||||
|
// The color is formatted as ARGB in a string (i.e. "[A=255, R=157, G=187, B=97]") in the format file
|
||||||
|
string argbColor = colorDescription.Replace("[", "").Replace("]", "").Replace(" ", ""); // remove starting and ending square brackets
|
||||||
|
// split the string on the commas and find each ARGB value
|
||||||
|
string[] argbSplit = argbColor.Split(',');
|
||||||
|
foreach (string s in argbSplit)
|
||||||
|
{
|
||||||
|
if (s[0] == 'A')
|
||||||
|
Alpha = Convert.ToInt32(s.Substring(2));
|
||||||
|
else if (s[0] == 'R')
|
||||||
|
Red = Convert.ToInt32(s.Substring(2));
|
||||||
|
else if (s[0] == 'G')
|
||||||
|
Green = Convert.ToInt32(s.Substring(2));
|
||||||
|
else if (s[0] == 'B')
|
||||||
|
Blue = Convert.ToInt32(s.Substring(2));
|
||||||
|
}
|
||||||
|
systemColor = System.Drawing.Color.FromArgb(Alpha, Red, Green, Blue);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
systemColor = System.Drawing.Color.FromName(colorDescription); // get from color name that was passed in
|
||||||
|
return systemColor;
|
||||||
|
}
|
||||||
private void DrawWatermark(PdfContentByte cb)
|
private void DrawWatermark(PdfContentByte cb)
|
||||||
{
|
{
|
||||||
if (Watermark == null || Watermark.ToLower().Contains("none") || Watermark == "") return;
|
if (Watermark == null || Watermark.ToLower().Contains("none") || Watermark == "") return;
|
||||||
@ -1166,7 +1198,7 @@ namespace Volian.Svg.Library
|
|||||||
System.Drawing.Drawing2D.Matrix myMatrix = new System.Drawing.Drawing2D.Matrix((float)Math.Cos(a), (float)Math.Sin(a), (float)-Math.Sin(a), (float)Math.Cos(a), 0, cb.PdfDocument.PageSize.Height);
|
System.Drawing.Drawing2D.Matrix myMatrix = new System.Drawing.Drawing2D.Matrix((float)Math.Cos(a), (float)Math.Sin(a), (float)-Math.Sin(a), (float)Math.Cos(a), 0, cb.PdfDocument.PageSize.Height);
|
||||||
cb.Transform(myMatrix);
|
cb.Transform(myMatrix);
|
||||||
}
|
}
|
||||||
SvgWatermark myWatermark = new SvgWatermark(cb, Watermark, System.Drawing.Color.FromName(WatermarkColor), .15F);
|
SvgWatermark myWatermark = new SvgWatermark(cb, Watermark, GetWatermarkColor(WatermarkColor), .15F);
|
||||||
//myWatermark.SetSquareDotPattern(.7F);
|
//myWatermark.SetSquareDotPattern(.7F);
|
||||||
myWatermark.Draw();
|
myWatermark.Draw();
|
||||||
if (_WatermarkLayer != null) cb.EndLayer();
|
if (_WatermarkLayer != null) cb.EndLayer();
|
||||||
@ -1419,9 +1451,16 @@ namespace Volian.Svg.Library
|
|||||||
float Theta = (float)Math.Atan(H1 / W1);
|
float Theta = (float)Math.Atan(H1 / W1);
|
||||||
float h = H2 / (float)Math.Cos(Theta);
|
float h = H2 / (float)Math.Cos(Theta);
|
||||||
float w = H1 / (float)Math.Sin(Theta);
|
float w = H1 / (float)Math.Sin(Theta);
|
||||||
|
// C2022-004 if the watermark is only one character, don't rotate and scale
|
||||||
|
if (msg.Length > 2)
|
||||||
|
{
|
||||||
_WatermarkImage.Rotation = Theta; // 3.141592653F / 4;
|
_WatermarkImage.Rotation = Theta; // 3.141592653F / 4;
|
||||||
_WatermarkImage.ScaleAbsolute(w, h);
|
_WatermarkImage.ScaleAbsolute(w, h);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
_WatermarkImage.ScaleAbsolute(W, H);// C2022-004 if the watermark is only one character, scale with respect to page size
|
||||||
|
|
||||||
|
}
|
||||||
return _WatermarkImage;
|
return _WatermarkImage;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user