228 lines
6.3 KiB
C#

/*********************************************************************************************
* Copyright 2005 - Volian Enterprises, Inc. All rights reserved.
* Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE
* ------------------------------------------------------------------------------
* $Workfile: Form1.cs $ $Revision: 1 $
* $Author: Kathy $ $Date: 12/06/05 12:06p $
*
* $History: Form1.cs $
*
* ***************** Version 1 *****************
* User: Kathy Date: 12/06/05 Time: 12:06p
* Created in $/LibSource/VG/Test
*
* ***************** Version 1 *****************
* User: Kathy Date: 12/06/05 Time: 12:01p
* Created in $/LibSource/VG.root/VG/Test
*********************************************************************************************/
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Xml;
using System.IO;
using VG;
using C1.C1Pdf;
namespace TestVG
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Button button1;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
private System.Windows.Forms.ListBox listBox1;
private System.Windows.Forms.Button button2;
private int ConvertToTwips = 1440;
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.listBox1 = new System.Windows.Forms.ListBox();
this.button2 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(24, 8);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(72, 32);
this.button1.TabIndex = 0;
this.button1.Text = "SVG To PDF";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// listBox1
//
this.listBox1.Location = new System.Drawing.Point(24, 72);
this.listBox1.Name = "listBox1";
this.listBox1.Size = new System.Drawing.Size(584, 381);
this.listBox1.TabIndex = 1;
//
// button2
//
this.button2.Location = new System.Drawing.Point(544, 8);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(56, 32);
this.button2.TabIndex = 2;
this.button2.Text = "Exit";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(752, 494);
this.Controls.Add(this.button2);
this.Controls.Add(this.listBox1);
this.Controls.Add(this.button1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void button1_Click(object sender, System.EventArgs e)
{
listBox1.Items.Clear();
DirectoryInfo di = new DirectoryInfo("E:\\proms.net\\genmac.xml");
FileInfo[] fis = di.GetFiles("*.svg");
foreach (FileInfo fi in fis)
{
this.listBox1.Items.Add(fi.Name);
//TestSvgToPdf("E:\\proms.net\\genmac.xml",fi.Name);
VG.Page pg = new Page(true, 0.5f * ConvertToTwips, 0.5f * ConvertToTwips);
XmlDocument xmldoc = new XmlDocument();
XmlTextReader reader = new XmlTextReader("E:\\proms.net\\genmac.xml\\"+fi.Name);
xmldoc.Load(reader);
reader.Close();
try
{
GeneratePDFForSVGFile(xmldoc, fi.Name, pg);
}
catch (Exception ex)
{
MessageBox.Show("Error processing: " + fi.Name, ex.Message);
}
}
MessageBox.Show("DONE generating PDF files from SVG");
}
private void GeneratePDFForSVGFile(XmlDocument xmldoc, string fname, VG.Page pg)
{
C1.C1Pdf.C1PdfDocument c1pdf = new C1.C1Pdf.C1PdfDocument();
string rootname = fname.Substring(0,fname.Length-4);
// create a pdf file with a page for each macro (i.e. macro element in xml tree),
// put it into the pdf file.
XmlNode topnode = xmldoc.LastChild;
for (int i=0;i<topnode.ChildNodes.Count;i++)
{
XmlNode nd = topnode.ChildNodes[i];
if (nd.Name!="desc")
{
SvgConvertToPdf(nd, c1pdf, pg);
if (i!=topnode.ChildNodes.Count-1)c1pdf.NewPage();
}
}
string outname = "E:\\proms.net\\genmac.xml\\testpdf\\" + rootname + ".pdf";
c1pdf.Save(outname);
}
private void SvgConvertToPdf(XmlNode nd, C1.C1Pdf.C1PdfDocument c1pdf, VG.Page ipg)
{
for (int i=0; i<nd.ChildNodes.Count; i++)
{
Page pg = new Page(true, ipg.LeftMargin, ipg.VertOffset);
XmlElement cmdele = (XmlElement) nd.ChildNodes[i];
string cmd = cmdele.Name.ToLower();
if (cmdele.GetAttribute("id")=="C0")
{
pg.LeftMargin = 100.0f;
pg.VertOffset = 100f;
}
switch (cmd)
{
case "rect":
VG_Rect vgrec = new VG_Rect(cmdele, pg);
vgrec.ToPdf(c1pdf);
vgrec=null;
break;
case "line":
VG_Line vgline = new VG_Line(cmdele, pg);
vgline.ToPdf(c1pdf);
break;
case "text":
VG_Text vgtxt = new VG_Text(cmdele, pg);
vgtxt.ToPdf(c1pdf);
break;
case "gdiadj":
break;
case "ellipse":
VG_Ellipse vgell = new VG_Ellipse(cmdele, pg);
vgell.ToPdf(c1pdf);
break;
case "image":
VG_Image vgi = new VG_Image(cmdele, pg);
vgi.ToPdf(c1pdf);
break;
case "absolute":
break;
default:
break;
}
}
}
private void button2_Click(object sender, System.EventArgs e)
{
Application.Exit();
}
}
}