Added support for iTextSharp
Changed code that determines line color for thin lines. Temporary fix for "*Resolved Transition Text*" bug Removed Comment
This commit is contained in:
parent
42c9f9f46f
commit
fbc56399f1
@ -3,6 +3,9 @@ using System.Collections.Generic;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using C1.C1Pdf;
|
using C1.C1Pdf;
|
||||||
|
using iTextSharp.text.pdf;
|
||||||
|
using iTextSharp.text.factories;
|
||||||
|
using Microsoft.Win32;
|
||||||
|
|
||||||
namespace VG
|
namespace VG
|
||||||
{
|
{
|
||||||
@ -82,4 +85,120 @@ namespace VG
|
|||||||
public float FontSizeAdjust
|
public float FontSizeAdjust
|
||||||
{ get { return .71f * 96f / _VGOutput.DpiX; } } // Changed to adjust for Screen DPI Setting
|
{ get { return .71f * 96f / _VGOutput.DpiX; } } // Changed to adjust for Screen DPI Setting
|
||||||
}
|
}
|
||||||
|
public partial class VGOut_ITextSharp : IVGOutput
|
||||||
|
{
|
||||||
|
private PdfContentByte _VGOutput;
|
||||||
|
//public Graphics VGOutput
|
||||||
|
//{ get { return _VGOutput; } }
|
||||||
|
public VGOut_ITextSharp(PdfContentByte vgOutput)
|
||||||
|
{ _VGOutput = vgOutput; }
|
||||||
|
public float Scale
|
||||||
|
{ get { return 1; } }
|
||||||
|
public void DrawLine(Pen pn, float startx, float starty, float endx, float endy)
|
||||||
|
{
|
||||||
|
_VGOutput.SaveState();
|
||||||
|
SetStrokeData(pn);
|
||||||
|
_VGOutput.MoveTo(startx, ScaleY(starty));
|
||||||
|
_VGOutput.LineTo(endx, ScaleY(endy));
|
||||||
|
_VGOutput.Stroke();
|
||||||
|
_VGOutput.RestoreState();
|
||||||
|
}
|
||||||
|
private void SetStrokeData(Pen pn)
|
||||||
|
{
|
||||||
|
_VGOutput.SetLineWidth(pn.Width);
|
||||||
|
_VGOutput.SetColorStroke(new iTextSharp.text.Color(pn.Color.R, pn.Color.G, pn.Color.B, pn.Color.A));
|
||||||
|
}
|
||||||
|
public void DrawRectangle(Pen pn, RectangleF rectf)
|
||||||
|
{
|
||||||
|
_VGOutput.SaveState();
|
||||||
|
SetStrokeData(pn);
|
||||||
|
_VGOutput.Rectangle(rectf.X, ScaleY(rectf.Y), rectf.Width, -rectf.Height);
|
||||||
|
_VGOutput.Stroke();
|
||||||
|
_VGOutput.RestoreState();
|
||||||
|
}
|
||||||
|
public void DrawEllipse(Pen pn, float cx, float cy, float dx, float dy)
|
||||||
|
{
|
||||||
|
_VGOutput.SaveState();
|
||||||
|
SetStrokeData(pn);
|
||||||
|
_VGOutput.Ellipse(cx, ScaleY(cy), dx, -dy);
|
||||||
|
_VGOutput.Stroke();
|
||||||
|
_VGOutput.RestoreState();
|
||||||
|
}
|
||||||
|
public void DrawImage(Bitmap bm, RectangleF rectf)
|
||||||
|
{
|
||||||
|
_VGOutput.SaveState();
|
||||||
|
// TODO: Determine how I can create an iTextSharp.text.Image
|
||||||
|
//_VGOutput.AddImage(new iTextSharp.text.Image(
|
||||||
|
_VGOutput.RestoreState();
|
||||||
|
}
|
||||||
|
public void DrawString(string text, Font myFont, Brush brush, RectangleF rectf)
|
||||||
|
{
|
||||||
|
_VGOutput.SaveState();
|
||||||
|
_VGOutput.BeginText();
|
||||||
|
iTextSharp.text.Font itFont = GetFont(myFont.Name);
|
||||||
|
iTextSharp.text.pdf.BaseFont baseFont = itFont.BaseFont;
|
||||||
|
// _VGOutput.DrawString(text, myFont, brush, rectf, StringFormat.GenericTypographic);
|
||||||
|
_VGOutput.MoveText(rectf.X, ScaleY(rectf.Y) - myFont.SizeInPoints);
|
||||||
|
_VGOutput.SetFontAndSize(baseFont, myFont.SizeInPoints);
|
||||||
|
_VGOutput.SetTextRenderingMode(PdfContentByte.TEXT_RENDER_MODE_FILL);
|
||||||
|
_VGOutput.ShowTextKerned(text);
|
||||||
|
_VGOutput.EndText();
|
||||||
|
_VGOutput.RestoreState();
|
||||||
|
}
|
||||||
|
public void DrawArc(Pen pn, RectangleF rectf, float startAngle, float sweepAngle)
|
||||||
|
{
|
||||||
|
_VGOutput.SaveState();
|
||||||
|
SetStrokeData(pn);
|
||||||
|
_VGOutput.Arc(rectf.X, ScaleY(rectf.Y), rectf.X + rectf.Width, ScaleY(rectf.Y + rectf.Height), -startAngle, -sweepAngle);
|
||||||
|
_VGOutput.Stroke();
|
||||||
|
_VGOutput.RestoreState();
|
||||||
|
}
|
||||||
|
public SizeF MeasureString(string text, Font myFont)
|
||||||
|
{
|
||||||
|
iTextSharp.text.Font itFont = GetFont(myFont.Name);
|
||||||
|
iTextSharp.text.pdf.BaseFont baseFont = itFont.BaseFont;
|
||||||
|
return new SizeF(baseFont.GetWidthPoint(text,myFont.SizeInPoints)
|
||||||
|
, baseFont.GetAscentPoint(text, myFont.SizeInPoints) + baseFont.GetDescentPoint(text, myFont.SizeInPoints));
|
||||||
|
}
|
||||||
|
public void Save(string fileName)
|
||||||
|
{ ;/* Don't do anything*/ }
|
||||||
|
public float FontSizeAdjust
|
||||||
|
{ get { return 1; } } // Changed to adjust for Screen DPI Setting
|
||||||
|
public static iTextSharp.text.Font GetFont(string fontName)
|
||||||
|
{
|
||||||
|
RegisterFont(fontName);
|
||||||
|
return iTextSharp.text.FontFactory.GetFont(fontName);
|
||||||
|
}
|
||||||
|
//private void RegisterFonts()
|
||||||
|
// {
|
||||||
|
// //if (!FontFactory.IsRegistered("Arial"))
|
||||||
|
// //{
|
||||||
|
// // RegisterFont("Prestige Elite Tall");
|
||||||
|
// //}
|
||||||
|
//}
|
||||||
|
public static void RegisterFont(string fontName)
|
||||||
|
{
|
||||||
|
if (!iTextSharp.text.FontFactory.IsRegistered(fontName))
|
||||||
|
{
|
||||||
|
foreach (string name in FontKey.GetValueNames())
|
||||||
|
{
|
||||||
|
if (name.StartsWith(fontName))
|
||||||
|
{
|
||||||
|
string fontFile = (string)FontKey.GetValue(name);
|
||||||
|
iTextSharp.text.FontFactory.Register(fontFile.Contains("\\") ? fontFile : FontFolder + "\\" + fontFile);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private static RegistryKey _FontKey = Registry.LocalMachine.OpenSubKey("Software").OpenSubKey("Microsoft").OpenSubKey("Windows NT").OpenSubKey("CurrentVersion").OpenSubKey("Fonts");
|
||||||
|
public static RegistryKey FontKey
|
||||||
|
{ get { return _FontKey; } }
|
||||||
|
private static string _FontFolder = (String)Registry.CurrentUser.OpenSubKey("Software").OpenSubKey("Microsoft").OpenSubKey("Windows").OpenSubKey("CurrentVersion").OpenSubKey("Explorer").OpenSubKey("Shell Folders").GetValue("Fonts");
|
||||||
|
public static string FontFolder
|
||||||
|
{ get { return _FontFolder; } }
|
||||||
|
private float ScaleY(float y)
|
||||||
|
{
|
||||||
|
return _VGOutput.PdfWriter.PageSize.Height - y;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -133,20 +133,22 @@ namespace VG
|
|||||||
public static Pen CreatePen(Color color, float wid, float scale)
|
public static Pen CreatePen(Color color, float wid, float scale)
|
||||||
{
|
{
|
||||||
Pen pn;
|
Pen pn;
|
||||||
if ((wid * scale) < .5F)
|
float scaleWid = wid * scale;
|
||||||
|
float colorFraction = (float)Math.Sqrt(scaleWid);
|
||||||
|
if (scaleWid < .5F)
|
||||||
{
|
{
|
||||||
//Console.WriteLine("Width = {0}", wid);
|
//Console.WriteLine("Width = {0}", wid);
|
||||||
int R1 = (int)(wid * color.R);
|
int R1 = (int)(colorFraction * color.R);
|
||||||
int R2 = (int)((1 - wid) * Color.White.R);
|
int R2 = (int)((1 - colorFraction) * Color.White.R);
|
||||||
int G1 = (int)(wid * color.G);
|
int G1 = (int)(colorFraction * color.G);
|
||||||
int G2 = (int)((1 - wid) * Color.White.G);
|
int G2 = (int)((1 - colorFraction) * Color.White.G);
|
||||||
int B1 = (int)(wid * color.B);
|
int B1 = (int)(colorFraction * color.B);
|
||||||
int B2 = (int)((1 - wid) * Color.White.B);
|
int B2 = (int)((1 - colorFraction) * Color.White.B);
|
||||||
pn = new Pen(Color.FromArgb(R1 + R2, G1 + G2, B1 + B2), wid);
|
pn = new Pen(Color.FromArgb(R1 + R2, G1 + G2, B1 + B2), scaleWid);
|
||||||
//pn = new Pen(color, wid*wid);
|
//pn = new Pen(color, wid*wid);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
pn = new Pen(color, wid);
|
pn = new Pen(color, scaleWid);
|
||||||
return pn;
|
return pn;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -380,6 +382,7 @@ namespace VG
|
|||||||
//#if DEBUG
|
//#if DEBUG
|
||||||
// Pen pn = new Pen(myColors[iColor % myColors.Length], ToPoints(lnwid));
|
// Pen pn = new Pen(myColors[iColor % myColors.Length], ToPoints(lnwid));
|
||||||
//iColor++;
|
//iColor++;
|
||||||
|
//if (iColor >= myColors.Length) iColor = 0;
|
||||||
//#else
|
//#else
|
||||||
Pen pn = new Pen(VG.BlackBrush, ToPoints(lnwid));
|
Pen pn = new Pen(VG.BlackBrush, ToPoints(lnwid));
|
||||||
//#endif
|
//#endif
|
||||||
|
@ -883,7 +883,13 @@ namespace Volian.Controls.Library
|
|||||||
if (link.IndexOf("<NewID>") != -1) return text;
|
if (link.IndexOf("<NewID>") != -1) return text;
|
||||||
int transitionID = Convert.ToInt32(link.Split(" ".ToCharArray())[1]);
|
int transitionID = Convert.ToInt32(link.Split(" ".ToCharArray())[1]);
|
||||||
// Find the transition
|
// Find the transition
|
||||||
if (_MyItemInfo.MyContent.ContentTransitionCount <= 0) return "*Resolved Transition Text*";
|
if (_MyItemInfo.MyContent.ContentTransitionCount <= 0)
|
||||||
|
{
|
||||||
|
// TODO: RHM 20100310
|
||||||
|
_MyItemInfo.MyContent.RefreshContentTransitions();
|
||||||
|
if (_MyItemInfo.MyContent.ContentTransitionCount <= 0)
|
||||||
|
return "*Resolved Transition Text*";
|
||||||
|
}
|
||||||
foreach (TransitionInfo ti in _MyItemInfo.MyContent.ContentTransitions)
|
foreach (TransitionInfo ti in _MyItemInfo.MyContent.ContentTransitions)
|
||||||
{
|
{
|
||||||
if (ti.TransitionID == transitionID)
|
if (ti.TransitionID == transitionID)
|
||||||
@ -918,8 +924,6 @@ namespace Volian.Controls.Library
|
|||||||
if (endLinkIndxV == -1) endLinkIndxV = text.IndexOf(@"\v0", linkIndx); // at end of string
|
if (endLinkIndxV == -1) endLinkIndxV = text.IndexOf(@"\v0", linkIndx); // at end of string
|
||||||
int endLinkIndxE = text.IndexOf(@"[END>", linkIndx);
|
int endLinkIndxE = text.IndexOf(@"[END>", linkIndx);
|
||||||
int endLinkIndx = (endLinkIndxV < endLinkIndxE) ? endLinkIndxV : endLinkIndxE;
|
int endLinkIndx = (endLinkIndxV < endLinkIndxE) ? endLinkIndxV : endLinkIndxE;
|
||||||
if (endLinkIndx == -1)
|
|
||||||
Console.WriteLine("{0},{1},{2},'{3}'", endLinkIndx, linkIndx, text.Length,text.Substring(linkIndx));
|
|
||||||
vte.Link = text.Substring(linkIndx + 6, endLinkIndx - linkIndx - 6); // 6 for #Link:
|
vte.Link = text.Substring(linkIndx + 6, endLinkIndx - linkIndx - 6); // 6 for #Link:
|
||||||
|
|
||||||
string tmptxt = null;
|
string tmptxt = null;
|
||||||
|
@ -1869,27 +1869,6 @@ namespace Volian.Controls.Library
|
|||||||
//Console.WriteLine("TableWidth = {0}, lineMax = '{1}', myFont = {2}", max, lineMax, myFont);
|
//Console.WriteLine("TableWidth = {0}, lineMax = '{1}', myFont = {2}", max, lineMax, myFont);
|
||||||
return max;
|
return max;
|
||||||
}
|
}
|
||||||
// OLD - RHM 3-24-2010 public float TableWidth(Font myFont, string txt, bool addBorder)
|
|
||||||
//{
|
|
||||||
// string[] lines = txt.Split("\n".ToCharArray());
|
|
||||||
// float max = 0;
|
|
||||||
// string lineMax = "";
|
|
||||||
// Graphics g = this.CreateGraphics();
|
|
||||||
// PointF pnt = new PointF(0, 0);
|
|
||||||
// foreach (string line in lines)
|
|
||||||
// {
|
|
||||||
// string line2 = (addBorder ? "--" : "") + Regex.Replace(line, @"\\.*? ", ""); // Remove RTF Commands
|
|
||||||
// SizeF siz = g.MeasureString(line2, myFont, pnt, StringFormat.GenericTypographic);
|
|
||||||
// if (siz.Width + _MyStepPanel.MyStepPanelSettings.TableWidthAdjust > max)
|
|
||||||
// {
|
|
||||||
// max = siz.Width + _MyStepPanel.MyStepPanelSettings.TableWidthAdjust;
|
|
||||||
// lineMax = line2;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// //vlnStackTrace.ShowStackLocal("TableWidth", 1, 10);
|
|
||||||
// Console.WriteLine("TableWidth = {0}, lineMax = '{1}', myFont = {2}", max, lineMax, myFont);
|
|
||||||
// return max;
|
|
||||||
//}
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Calculates the table location
|
/// Calculates the table location
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -2292,11 +2292,6 @@ namespace Volian.Controls.Library
|
|||||||
}
|
}
|
||||||
public void OutlineTable(bool withBorder)
|
public void OutlineTable(bool withBorder)
|
||||||
{
|
{
|
||||||
//if (_MyItemInfo.ItemID == 64671)
|
|
||||||
//{
|
|
||||||
// Console.WriteLine("TABLE");
|
|
||||||
// Console.WriteLine("WIDTH {0}", this.Width);
|
|
||||||
//}
|
|
||||||
if (_MyStepItem != null) // Set the width based upon the contents
|
if (_MyStepItem != null) // Set the width based upon the contents
|
||||||
{
|
{
|
||||||
int newwidth = (int)_MyStepItem.TableWidth(Font, Text, true);
|
int newwidth = (int)_MyStepItem.TableWidth(Font, Text, true);
|
||||||
@ -2371,7 +2366,6 @@ namespace Volian.Controls.Library
|
|||||||
}
|
}
|
||||||
return w;
|
return w;
|
||||||
}
|
}
|
||||||
//private string RemoveLinkComments(string line)
|
|
||||||
internal static string RemoveLinkComments(string line)
|
internal static string RemoveLinkComments(string line)
|
||||||
{
|
{
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user