This commit is contained in:
Kathy Ruffing 2008-08-26 13:55:41 +00:00
parent b94dad3cf2
commit 00d7744d0d
12 changed files with 7640 additions and 8 deletions

View File

@ -9,14 +9,10 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>CvtFont</RootNamespace>
<AssemblyName>CvtFont</AssemblyName>
<SccProjectName>
</SccProjectName>
<SccLocalPath>
</SccLocalPath>
<SccAuxPath>
</SccAuxPath>
<SccProvider>
</SccProvider>
<SccProjectName>SAK</SccProjectName>
<SccLocalPath>SAK</SccLocalPath>
<SccAuxPath>SAK</SccAuxPath>
<SccProvider>SAK</SccProvider>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>

BIN
PROMS/fmtxml/App.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

@ -0,0 +1,58 @@
using System.Reflection;
using System.Runtime.CompilerServices;
//
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
//
[assembly: AssemblyTitle("")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("")]
[assembly: AssemblyCopyright("")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
//
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Revision and Build Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("1.0.*")]
//
// In order to sign your assembly you must specify a key to use. Refer to the
// Microsoft .NET Framework documentation for more information on assembly signing.
//
// Use the attributes below to control which key is used for signing.
//
// Notes:
// (*) If no key is specified, the assembly is not signed.
// (*) KeyName refers to a key that has been installed in the Crypto Service
// Provider (CSP) on your machine. KeyFile refers to a file which contains
// a key.
// (*) If the KeyFile and the KeyName values are both specified, the
// following processing occurs:
// (1) If the KeyName can be found in the CSP, that key is used.
// (2) If the KeyName does not exist and the KeyFile does exist, the key
// in the KeyFile is installed into the CSP and used.
// (*) In order to create a KeyFile, you can use the sn.exe (Strong Name) utility.
// When specifying the KeyFile, the location of the KeyFile should be
// relative to the project output directory which is
// %Project Directory%\obj\<configuration>. For example, if your KeyFile is
// located in the project directory, you would specify the AssemblyKeyFile
// attribute as [assembly: AssemblyKeyFile("..\\..\\mykey.snk")]
// (*) Delay Signing is an advanced option - see the Microsoft .NET Framework
// documentation for more information on this.
//
[assembly: AssemblyDelaySign(false)]
[assembly: AssemblyKeyFile("")]
[assembly: AssemblyKeyName("")]

View File

@ -0,0 +1,60 @@
using System;
using System.IO;
using System.Collections.Generic;
using System.Text;
using System.Xml;
namespace fmtxml
{
class EntireFormat
{
public EntireFormat(string mxml)
{
XmlDocument xmldoc = new XmlDocument();
XmlElement top = xmldoc.CreateElement("PlantFormat");
xmldoc.AppendChild(top);
try
{
XmlReaderSettings settings = new XmlReaderSettings();
settings.IgnoreWhitespace = true;
StreamReader strrdr = new StreamReader(mxml);
XmlTextReader rdr = new XmlTextReader(strrdr);
using (rdr)
{
rdr.MoveToContent();
XmlNode fmt = xmldoc.ReadNode(rdr);
top.AppendChild(fmt);
}
rdr.Close();
// load page xml
string pagename = mxml.Substring(0, mxml.Length - 5) + "p.xml";
using (XmlReader reader = XmlReader.Create(pagename, settings))
{
reader.MoveToContent();
XmlNode pag = xmldoc.ReadNode(reader);
top.AppendChild(pag);
}
string docname = mxml.Substring(0, mxml.Length - 5) + "d.xml";
using (XmlReader reader = XmlReader.Create(docname, settings))
{
reader.MoveToContent();
XmlNode doc = xmldoc.ReadNode(reader);
top.AppendChild(doc);
}
XmlWriterSettings settingsout = new XmlWriterSettings();
settingsout.Encoding = Encoding.Unicode;
string outname = "e:\\fmtall\\" + mxml.Substring(mxml.IndexOf("\\")+1,mxml.Length - 13) + "all.xml";
XmlWriter xmlwrite = XmlWriter.Create(outname,settingsout);
xmldoc.WriteContentTo(xmlwrite);
xmlwrite.Close();
}
catch (Exception ex)
{
Console.WriteLine("Error on merge, format = {0}, msg = {1}", mxml, ex.Message);
}
}
}
}

4841
PROMS/fmtxml/FmtFileToXml.cs Normal file

File diff suppressed because it is too large Load Diff

918
PROMS/fmtxml/FmtToXml.cs Normal file
View File

@ -0,0 +1,918 @@
using System;
using System.Windows.Forms;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
using System.Collections;
using System.Runtime.Serialization.Formatters.Binary; // read in struct
using System.Xml.Xsl;
using System.Xml;
using System.Xml.Serialization;
using System.ComponentModel;
#region Structs
// top of the page style list.
[Serializable]
public struct PageStyles
{
public string Name;
public PageStyle [] PgStyles;
}
[Serializable]
public struct PageStyle
{
public string Name;
public short Index;
public PSItem [] Items;
}
[Serializable]
public struct PSItem
{
public int Row;
public int Col;
public E_PageStructMod Justify;
public VE_Font Style;
public string Token;
}
//// top of the doc style list.
[Serializable]
public struct DocStyles
{
public string Name;
public DocStyle [] DcStyles;
}
[Serializable]
public struct DocStyle
{
public string Name;
public short Index;
public short pagestyle; // Index into page style array
public VE_Font dstyle; // 'Printer driver styles' for the entire document
public int PTopRow; // First 'document text' row on printed page
public int FooterLen; // Number of lines required for footer
public int LeftMargin; // Size of left margin
public int PageLength;
public int PageWidth;
public short numberingsequence; // 0 - no page number
// 1 - included with steps
// 2 - within sections ie. document styles
// 3 - within each accessory document
public bool IsStepSection; // using oldtonew, determine whether is step
// section or word doc section (new to 32-bit)
public int oldtonew; // Bits for converting from old to new
// document style
public short ContTopHLS; // Flag for including High Level step
// as part of top continue message.
public int CTMargin; // Margin for top message
public int CBMargin; // Margin for bottom message
public short CBLoc; // 0 - place continue string at end of text
// 1 - between end of text & bottom of page
// 2 - place at bottom of page
//
public VE_Font ContStyle; // Style of continue messages
public short EndFlag; // Does end statement exist for this type
public VE_Font EndStyle; // Style of end message at end of page
public string ContTop; // Message at top of page
public string ContBottom; // Message at bottom of page
public string EndString; // String for end of document
public string FinalMsg; // Message for the final page of th text
public VE_DocStyle DocStructStyle; // Describe How / When structure is used
}
#endregion
#region ENums
[Flags]
public enum E_PageStructMod : uint
{
PSCenter = 0, // Page style, center field
PSLeft = 1, // Page style, left justify
PSRight = 2, // Page style, right justify
// *** PS modifiers: ***
PSBottom = 4, // Page style, always use bottom half line
PSTop = 8, // Page style, always use top half line
PSTrue = 16, // page style, don't adjust per CPI* (not needed after 4.0)
PSNotFirst = 32, // page style, don't put this token on the first page of section
PSOnlyFirst = 64, // page style, only put this token on the first page of section
PSRelRow = 128, // place in RelPageList
PSNoHalfLine= 256, // DontDoHalflines for his paglist row item
PSNotLast = 0x200, // 512 - use this token on all but the last page of this section
PSRtfOnly = 0x400, // Only use this token when the driver is rtf
PSRtfNot = 0x800, // Do NOT use token when driver is rtf
PSGDIOnly = 0X1000, // Only use this token when the driver is GDI
PSGDINot = 0x2000, // Do NOT use token when driver is GDI
PSAdjBngRow = 0x4000 // If the pagelist item exceeds the row it's printed on,
// then adjust the starting row for the procedure body
};
// Possible settings for DocStructStyle (DSS_)
// These styles describe How and When the defined Doc Style is used
[Flags] public enum E_DocStructStyle:uint
{
UseOnAllPages = 0, // Default
UseOnFirstPage = 1, // Use only on the first page
UseOnAllButFirstPage = 2, // Use on all but the first page
UseOnLastPage = 4, // NO LOGIC exists for this selection. Use only on the last page
UseSectionFoldout = 8, // Attach section foldouts (only active if using SectionLevelFoldouts_ON
DontCountFoldoutPgs = 16, // Used with the USESECTIONFOLDOUT flag. Keeps foldout pages from
// being included in the section total page count.
TableOfContents = 32,
DontCountInTabOfCont = 64,
Placekeeper = 128,
Align1StLevSubWHLS = 0x00000100, // guess?
DoubleBoxHLS = 0x00000200,
UseAltCntrline = 0x00000400,
DontNumberInTOC = 0x00000800, // Don't include page number for this section in the Table of Contents
UseSpecialFigFrame = 0x00001000, // for use with stp55 and 55a in bge
HLSUseLetters = 0x00002000, // docstyles with this bit set in the DocStructStyle will
// default to using letters for HLSteps
NoSectionInStepContinue = 0x00004000, // don't include the section number in the step continue
BottomSectionContinue = 0x00008000, // print the continue message if the section continues
AlwaysDotStep = 0x00010000, // put the period after step number in the continue message
XBlankW1stLevSub = 0x00020000, // insert an extra blank line before a 1st level substep
AffectedPages = 0x00040000,
DSS_TreatAsTrueSectNum = 0x00080000, // in conjunction with tietabtolevel, takes section number
// from the last space and appends a period
SampleWatermark = 0x00100000, // Will force "SAMPLE" to be printed across the page
// on all pages in this section
DSS_PageBreakHLS = 0x00200000, // Page Breaks on all high level steps
DSS_NoChkIfContTypeHigh = 0x00400000, // Will suppress the checkoff if type is HIGH and the
// step is continued on the next page
DSS_WidthOvrdStdHLS = 0x00800000, // Width Override for Standard HLStep in this section
DSS_AddDotZeroStdHLS = 0x01000000, // Append .0 to the Standard HLStep for this section
DSS_SectionCompress = 0x02000000, // Compress all the steps of this section (i.e. use 7 LPI)
DSS_PrintSectOnFirst = 0x04000000, // Prints section title/number <SECTIONLEVELTITLE> only on the first
// page of an attachment section, assuming numberingsequence is not 1
DSS_UnNumLikeRoman = 0x08000000, // the substeps underneath unnumbered HLSteps will have same tabs as romans
DSS_DontChangeRomanLevel = 0x10000000, // Dont alter the the substep level for roman-numeral-tabbed hlsteps
DSS_SkipTwoStepLevels = 0x20000000, // Skip two step levels for this doc style
DSS_SkipOneStepLevel = 0x40000000, // Skip one step level for this doc style
DSS_SimpleTopSectionContinue = 0x80000000, // Use the Top continue message as the section continue */
};
public enum E_DocStyleUse:uint
{
UseOnAllPages=0,UseOnFirstPage=1,UseOnAllButFirstPage=2,UseOnLastPage=4
};
[Flags]
public enum E_DocStyle:uint
{
None=0,UseSectionFoldout=8,DontCountFoldoutPgs=16,TableOfContents=32,
DontCountInTabOfCont=64,Placekeeper=128,Align1StLevSubWHLS=0x00000100,
DoubleBoxHLS=0x00000200,UseAltCntrline=0x00000400,DontNumberInTOC=0x00000800,
UseSpecialFigFrame=0x00001000,HLSUseLetters=0x00002000,NoSectionInStepContinue=0x00004000,
BottomSectionContinue=0x00008000,AlwaysDotStep=0x00010000,XBlankW1stLevSub=0x00020000,
AffectedPages=0x00040000,DSS_TreatAsTrueSectNum=0x00080000,SampleWatermark=0x00100000,
DSS_PageBreakHLS=0x00200000,DSS_NoChkIfContTypeHigh=0x00400000,DSS_WidthOvrdStdHLS=0x00800000,
DSS_AddDotZeroStdHLS=0x01000000,DSS_SectionCompress=0x02000000,DSS_PrintSectOnFirst=0x04000000,
DSS_UnNumLikeRoman=0x08000000,DSS_DontChangeRomanLevel=0x10000000,
DSS_SkipTwoStepLevels=0x20000000,DSS_SkipOneStepLevel=0x40000000,DSS_SimpleTopSectionContinue=0x80000000
};
//[Flags]
//public enum E_Style:uint
//{
// ELITE=0,PICA=1,SANSERIF=2,EXPANDED=4,PICA12=5,COMPRESSEDHVLPT18=8,HVLPT25=9,SPECIALCHARS=10,PT14=11,SANSERIF14=12,SANSERIF17=13,
// HVLPT12=14,NARRATOR=15,MEDUPUNIVERS=16,LGUPMED16=17,PROPT10=18,LG1275HP4SI=19,
// HVLPT10=20,HVLPT8=21,HVLPT14=22,SANSERIF25=23,EYECHART=24,TIMES11=25,SANSCOND=26,
// UNDERLINE=64,BOLD=128,LANDSCAPE=256,ITALICS=512,BOXED=1024,BOXELEMENT=0x00000800,
// TBCENTERED=4096,RTCHECKOFF=8192,LTCHECKOFF=16384,BIGSCRIPT=32768,HLTEXTHL=65536,
// RTCHECKOFFWITHASTERISK=131072,DB_UNDERLINE=262144,COLDOTS=524288,
// MMBOLD=1048576,RIGHTJUSTIFY=2097152,SUBSCRIPT=4194304,SUPERSCRIPT=8388608,
// PAGELISTITEM=16777216,PRINTONTOPOFLINE=33554432,HORZCENTER=67108864,
// CIRCLESTRING2=0x08000000,ALIGNWITHUP1=0x10000000,ALIGNWSECNUM=0x20000000,
// MATCHCOLUMNMODE=0x40000000,KEEPRNOSUBSTYLE=0x80000000
//};
public enum E_FontName:uint
{
Elite=0,Pica=1,LnPrn=2,Condense=3,SanSerif=4,Pica12=5,Proportional=6,
Propt12=7,HvlPt18=8,HvlPt25=9,SpecialChars=10,Pt14=11,SanSerif14=12,SanSerif17=13,
HvlPt12=14,Narrator=15,MedUpUnivers=16,LgUpMed16=17,Propt10=18,Lg1275Hp4Si=19,
HvlPt10=20,HvlPt8=21,HvlPt14=22,SanSerif25=23,EyeChart=24,Times11=25,SansCond=26
};
//[Flags]
//public enum E_FontStyle:uint
//{
// NONE=0,UNDERLINE=64,BOLD=128,LANDSCAPE=256,ITALICS=512,BOXED=1024,BOXELEMENT=0x00000800,
// TBCENTERED=4096,RTCHECKOFF=8192,LTCHECKOFF=16384,BIGSCRIPT=32768,HLTEXTHL=65536,
// RTCHECKOFFWITHASTERISK=131072,DB_UNDERLINE=262144,COLDOTS=524288,
// MMBOLD=1048576,RIGHTJUSTIFY=2097152,SUBSCRIPT=4194304,SUPERSCRIPT=8388608,
// PAGELISTITEM=16777216,PRINTONTOPOFLINE=33554432,HORZCENTER=67108864,
// CIRCLESTRING2=0x08000000,ALIGNWITHUP1=0x10000000,ALIGNWSECNUM=0x20000000,
// MATCHCOLUMNMODE=0x40000000,KEEPRNOSUBSTYLE=0x80000000
//};
[Flags] public enum E_FontStyle:uint
{
None=0,Underline=64,Bold=128,Italics=512,BigScript=32768,
DbUnderline=262144,MmBold=1048576,Subscript=4194304,Superscript=8388608
};
public enum E_Justify : uint
{
None=0, Center=1, Left=2, Right=3
};
public enum E_TabCheckOff : uint
{
None=0, Left=1, Right=2
};
[Flags] public enum E_Style:uint
{
None=0,Landscape=256,Boxed=1024,BoxElement=0x00000800,TbCentered=4096,RtCheckoff=8192,
LtCheckOff=16384,HlTextHl=65536,RtCheckoffWithAsterisk=131072,ColDots=524288,
RightJustify=2097152,PageListItem=16777216,PrintOnTopOfLine=33554432,
HorzCenter=67108864,CircleString2=0x08000000,AlighWithUp1=0x10000000,
AlignWSecNum=0x20000000,MatchColumnMode=0x40000000,KeepRNOSubStyle=0x80000000
};
public enum E_OldToNewSteps : uint
{
S0 = 1, S1 = 2, S2 = 4, E0 = 1048576, E1 = 2097152, E2 = 4194304, X0 = 67108864, X1 = 134217728, X2 = 268435456
};
#endregion
#region TypeConverters
[Serializable,TypeConverter(typeof(VE_DocStyleConverter))]
public class VE_DocStyle
{
uint i;
public VE_DocStyle(string s)
{
}
public VE_DocStyle(uint i)
{
this.i=i;
}
public VE_DocStyle()
{
this.i=0;
}
public E_DocStyleUse DocStyleUse
{
get{return (E_DocStyleUse)(i & 0x7);}
set{i = ((uint)value) | (i & 0xFFFFFFF8);}
}
public string DocStyle
{
get{return ((E_DocStyle)(i & 0xFFFFFFF8)).ToString();}
set{i = ((uint)Enum.Parse(typeof (E_DocStyle),value)) | (i & 0x7);}
}
}
internal class VE_DocStyleConverter:ExpandableObjectConverter
{
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
{
if(sourceType == typeof(string))
{
return false;
}
return base.CanConvertFrom(context,sourceType);
}
public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
{
return base.ConvertFrom (context, culture, value);
}
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType)
{
if(destinationType==typeof(string))
{
VE_DocStyle v = (VE_DocStyle)value;
return string.Format((v.DocStyle=="None"?"{0}":"{0}, {1}"),v.DocStyleUse,v.DocStyle);
}
return base.ConvertTo (context, culture, value, destinationType);
}
}
[Serializable,TypeConverter(typeof(VE_FontConverter))]
public class VE_Font
{
uint i;
public VE_Font(string s)
{
}
public VE_Font(uint i)
{
this.i=i;
}
public VE_Font()
{
this.i=0;
}
public VE_Font(XmlNode fxml)
{
XmlNode tmp = fxml.SelectSingleNode("Family");
if (tmp!=null)FontFamily = tmp.InnerText;
tmp = fxml.SelectSingleNode("Size");
if (tmp != null) FontSize = tmp.InnerText;
tmp = fxml.SelectSingleNode("Style");
if (tmp != null) FontStyle = tmp.InnerText;
}
private string _FontFamily = null;
private bool _FontFamilySet = false;
public string FontFamily
{
get
{
if ((!_FontFamilySet)&&(_FontFamily == null)) _FontFamily = CvtFont.CvtFont.ConvertToFamily(((E_FontName)(i & 0x3f)).ToString());
_FontFamilySet = true;
return _FontFamily;
}
set {_FontFamily=value;}
}
private string _FontSize = null;
private bool _FontSizeSet = false;
public string FontSize
{
get
{
if ((!_FontSizeSet)&&(_FontSize == null)) _FontSize = CvtFont.CvtFont.ConvertToSize(((E_FontName)(i & 0x3f)).ToString()).ToString();
_FontSizeSet = true;
return _FontSize;
}
set { _FontSize = value;}
//set { i = ((uint)value) | (i & 0xFFFFFFC0); }
}
//public E_FontName FontName
//{
// get{return (E_FontName)(i & 0x3F);}
// set{i = ((uint)value) | (i & 0xFFFFFFC0);}
//}
private string _FontStyle = null;
private bool _FontStyleSet = false;
public string FontStyle
{
get{
if ((!_FontStyleSet) && (_FontStyle == null)) _FontStyle = ((E_FontStyle)(i & 0xD482C0)).ToString();
//if ((!_FontStyleSet) && (_FontStyle == null)) _FontStyle = ((E_FontStyle)(i & 0xFFFFFFC0)).ToString();
_FontStyleSet = true;
return _FontStyle;
}
// return (E_FontStyle)(i & 0xFFFFFFC0);}
set { _FontStyle = value;}
//set{i = ((uint)value) | (i & 0x3F);}
}
private string _FontCheckOff = null;
private bool _FontCheckOffSet = false;
public string FontCheckOff
{
get
{
// 16-bit code had check offs in font style integer flag. 32-bit is converting this to its own
// xml attribute not part of the font. This code is used for the format -> xml conversion
// the 32-bit code should NOT have this as part of the font. RTCHECKOFF in 16-bit code = 8192
// and LTCHECKOFF in 16-bit code = 16384
if ((!_FontCheckOffSet) && (_FontCheckOff == null))
{
if ((i & 8192)>0) _FontCheckOff = E_TabCheckOff.Right.ToString();
else if ((i & 16384) > 0) _FontCheckOff = E_TabCheckOff.Left.ToString();
else _FontCheckOff = E_TabCheckOff.None.ToString();
}
_FontCheckOffSet = true;
return _FontCheckOff;
}
set { _FontCheckOff = value; }
}
private string _FontJustify = null;
private bool _FontJustifySet = false;
public string FontJustify
{
get
{
// 16-bit code had justify in font style integer flag. 32-bit is converting this to its own
// xml attribute not part of the font. This code is used for the format -> xml conversion
// the 32-bit code should NOT have this as part of the font. TBCENTERED in 16-bit code = 4096
// and RIGHTJUSTIFY in 16-bit code = 2097152. Note 16-bit did not have a left justify.
if ((!_FontJustifySet) && (_FontJustify == null))
{
if ((i & 4096) > 0) _FontJustify = E_Justify.Center.ToString();
else if ((i & 2097152) > 0) _FontJustify = E_Justify.Right.ToString();
else _FontJustify = E_Justify.None.ToString();
}
_FontJustifySet = true;
return _FontJustify;
}
set { _FontJustify = value; }
}
//CIRCLESTRING2=0x08000000
public bool HasCircleString2()
{
if ((i & 0x08000000)>0) return true;
else return false;
}
public VE_Font Copy()
{
VE_Font c = new VE_Font(i);
return c;
}
}
internal class VE_FontConverter:ExpandableObjectConverter
{
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
{
if(sourceType == typeof(string))
{
return false;
}
return base.CanConvertFrom(context,sourceType);
}
public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
{
return base.ConvertFrom (context, culture, value);
}
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType)
{
if(destinationType==typeof(string))
{
VE_Font v = (VE_Font)value;
return string.Format((v.FontStyle == "None" ? "Family={0} Size={1}" : "{0}, {1}, {2}"), v.FontFamily, v.FontSize, v.FontStyle);
}
return base.ConvertTo (context, culture, value, destinationType);
}
}
#endregion
///////////////////////////
namespace fmtxml
{
public class FmtToXml
{
private BinaryReader brFmt;
private string fmtName;
private VE_Font DefBaseFont;
private VE_Font DefPlantFont;
public FmtToXml(string nm)
{
fmtName = nm;
try
{
// get the default base & plant files to use when figuring out inheritance.
GetPlantBaseDefaultFonts();
// will have entire name, such as aep.x01 - use number to differentiate it.
int indx = nm.IndexOf('.');
if (indx > 0)
{
LoadPageFile(nm);
LoadDocFile(nm);
}
else
{
LoadPageFile(nm + ".pag");
LoadDocFile(nm + ".doc");
}
}
catch (Exception ex)
{
MessageBox.Show("Format name = " + nm, ex.Message);
}
}
private int ColToPoints(int i)
{
return (i * 6); // col_in_points = input * 72/12, col = input * 6
}
private int RowToPoints(int i)
{
return (i * 12); // row_in_points = input * 72/6, row = input * 12
}
private string GetAsciiStringUntilNull(BinaryReader br)
{
StringBuilder inpstr = new StringBuilder();
byte input = 0;
int cnt = 0;
bool stillread = true;
do
{
try
{
input = br.ReadByte();
if (input==0) stillread=false;
inpstr.Append(Convert.ToChar(input));
}
catch (System.IO.EndOfStreamException)
{
stillread=false;
}
cnt++;
}while (stillread);
string retstr = inpstr.ToString();
if (retstr.Substring(retstr.Length-1,1)=="\0") return retstr.Substring(0,retstr.Length-1);
return retstr;
}
private string GetAsciiString(BinaryReader br, int len)
{
StringBuilder inpstr = new StringBuilder();
byte input = 0;
int cnt = 0;
do
{
try
{
input = br.ReadByte();
inpstr.Append(Convert.ToChar(input));
}
catch (System.IO.EndOfStreamException)
{
input = 0;
while (cnt < len)
{
inpstr.Append(Convert.ToChar(input));
cnt++;
}
}
cnt++;
}while (cnt < len);
string retstr = inpstr.ToString();
if (retstr.Substring(retstr.Length-1,1)=="\0") return retstr.Substring(0,retstr.Length-1);
return retstr;
}
private VE_Font LoadVE_Font()
{
VE_Font retval=new VE_Font(brFmt.ReadUInt32());
return retval;
}
private VE_DocStyle LoadVE_DocStyle()
{
VE_DocStyle retval=new VE_DocStyle(brFmt.ReadUInt32());
return retval;
}
public void LoadPageFile(string fname)
{
ArrayList stringoffsets = new ArrayList();
short strings = 0;
PageStyles pgstyles = new PageStyles();
string str = null;
// read in title.
string fnm = "E:\\ve-proms\\format\\"+fname;
Console.WriteLine(fname);
brFmt = new BinaryReader(File.Open(fnm,System.IO.FileMode.Open,System.IO.FileAccess.ReadWrite,FileShare.ReadWrite));
short len = brFmt.ReadInt16();
pgstyles.Name = GetAsciiString(brFmt,len);
// read in struct name/def name/page file name
for (int i=0;i<3;i++)
{
len = brFmt.ReadInt16();
str = GetAsciiString(brFmt,len);
}
// Get the number of page styles, and create the array for them.
short numpgstyles = brFmt.ReadInt16();
PageStyle [] pgs = new PageStyle[numpgstyles];
pgstyles.PgStyles = pgs;
short offptr = brFmt.ReadInt16();
short vnum = brFmt.ReadInt16();
if (vnum!=0)
{
strings = vnum;
for(int i=0;i<strings;i++)
{
vnum=brFmt.ReadInt16();
stringoffsets.Add(vnum);
}
}
for (short i=0;i<numpgstyles;i++)
{
PageStyle pg = new PageStyle();
pg.Index=i;
len = brFmt.ReadInt16();
pg.Name = GetAsciiString(brFmt,len);
PSItem [] psitms = new PSItem[1];
PSItem [] Fpsitms = null;
bool isfirst=true;
int cnt = 0;
while ((vnum = brFmt.ReadInt16()) != 0)
{
long fseek = brFmt.BaseStream.Position;
PSItem pi = new PSItem();
int tmp = brFmt.ReadInt32(); // not sure what's stored here?
// convert the row & column to points, i.e. a point = 1/72 inch
// the row is set based on 6 rows per inch
// the column is 12 char/inch
pi.Row = RowToPoints(brFmt.ReadInt16());
pi.Col = ColToPoints(brFmt.ReadInt16());
pi.Justify = (E_PageStructMod)brFmt.ReadUInt16();
pi.Style = LoadVE_Font();
pi.Token = DoReplaceTokens(GetAsciiStringUntilNull(brFmt));
// replace the '<' with '{' & '>' with '}'
pi.Token = pi.Token.Replace('<', '{');
pi.Token = pi.Token.Replace('>', '}');
cnt++;
if (!isfirst)
{
Fpsitms = new PSItem[cnt];
psitms.CopyTo(Fpsitms,0);
Fpsitms[cnt-1] = pi;
psitms = Fpsitms;
}
else
psitms[0] = pi;
isfirst=false;
brFmt.BaseStream.Position = fseek+vnum;
}
pg.Items = psitms;
pgs[i] = pg;
}
brFmt.Close();
DoPSFontInherit(ref pgstyles);
// First serialize files based on the above - then use xsl to transform
// into prefered xml.
if (!Directory.Exists("fmt_xml")) Directory.CreateDirectory("fmt_xml");
if (!Directory.Exists("tmp_fmt_xml")) Directory.CreateDirectory("tmp_fmt_xml");
XmlSerializer serializer = new XmlSerializer(typeof(PageStyles));
string lfmtname = fmtName;
// for subformats, make the name FMT_00 where FMT is format name & 00 is number
// from original name. This will allow the data load to know it's a sub.
int indx = fmtName.IndexOf('.');
if (indx>0)
lfmtname = fmtName.Substring(0,fmtName.Length-4) + "_" + fmtName.Substring(fmtName.Length-2,2);
string destfile = "tmp_fmt_xml\\" + lfmtname + "p.xml";
if (File.Exists(destfile)) File.Delete(destfile);
TextWriter writer = new StreamWriter(destfile);
try
{
serializer.Serialize(writer, pgstyles);
writer.Close();
XslCompiledTransform xsl = new XslCompiledTransform();
xsl.Load(Application.StartupPath + "\\TranslatePag.XSL");
string sResults = "fmt_xml\\" + lfmtname + "p.xml";
xsl.Transform(destfile, sResults); // Perform Transform
}
catch (Exception e)
{
Console.WriteLine(e.Message);
writer.Close();
}
}
public void LoadDocFile(string fname)
{
ArrayList stringoffsets = new ArrayList();
short strings = 0;
DocStyles dcstyles = new DocStyles();
string str = null;
// read in title.
string fnm = "E:\\ve-proms\\format\\"+fname;
Console.WriteLine(fname);
brFmt = new BinaryReader(File.Open(fnm,System.IO.FileMode.Open,System.IO.FileAccess.ReadWrite,FileShare.ReadWrite));
short len = brFmt.ReadInt16();
dcstyles.Name = GetAsciiString(brFmt,len);
// read in struct name/def name/doc file name
for (int i=0;i<3;i++)
{
len = brFmt.ReadInt16();
str = GetAsciiString(brFmt,len);
}
// Get the number of page styles, and create the array for them.
short numdcstyles = brFmt.ReadInt16();
DocStyle [] dcs = new DocStyle[numdcstyles];
short offptr = brFmt.ReadInt16(); // not sure what these bytes contain?
short vnum = brFmt.ReadInt16();
if (vnum!=0)
{
strings = vnum;
for(int i=0;i<strings;i++)
{
vnum=brFmt.ReadInt16();
stringoffsets.Add(vnum);
}
}
for (short i=0;i<numdcstyles;i++)
{
DocStyle dc = new DocStyle();
dc.Index=i;
len = brFmt.ReadInt16();
dc.Name = GetAsciiString(brFmt,len);
vnum = brFmt.ReadInt16(); // not sure what this is!
dc.pagestyle = brFmt.ReadInt16();
dc.dstyle = LoadVE_Font();
dc.PTopRow = RowToPoints(brFmt.ReadInt16());
dc.FooterLen = RowToPoints(brFmt.ReadInt16());
dc.LeftMargin = ColToPoints(brFmt.ReadInt16());
dc.PageLength = RowToPoints(brFmt.ReadInt16());
dc.PageWidth = ColToPoints(brFmt.ReadInt16());
dc.numberingsequence = brFmt.ReadInt16();
dc.oldtonew = brFmt.ReadInt32();
dc.IsStepSection = ConvertToSectType(dc.oldtonew);
dc.ContTopHLS = brFmt.ReadInt16();
dc.CTMargin = RowToPoints(brFmt.ReadInt16());
dc.CBMargin = RowToPoints(brFmt.ReadInt16());
dc.CBLoc = brFmt.ReadInt16();
dc.ContStyle = LoadVE_Font();
dc.EndFlag = brFmt.ReadInt16();
dc.EndStyle = LoadVE_Font();
// use the string offsets to read in the strings.
int [] offst = new int[strings];
for (int j=0; j<strings; j++)
{
offst[j] = brFmt.ReadInt32();
}
dc.DocStructStyle = LoadVE_DocStyle();
if (offst[0]!=0)dc.ContTop = DoReplaceTokens(GetAsciiStringUntilNull(brFmt));
else dc.ContTop = null;
if (offst[1]!=0)dc.ContBottom = DoReplaceTokens(GetAsciiStringUntilNull(brFmt));
else dc.ContBottom = null;
if (offst[2]!=0)dc.EndString = DoReplaceTokens(GetAsciiStringUntilNull(brFmt));
else dc.EndString = null;
if (offst[3]!=0)dc.FinalMsg = DoReplaceTokens(GetAsciiStringUntilNull(brFmt));
else dc.FinalMsg = null;
if (dc.ContTop == null && dc.ContBottom == null)dc.ContStyle = null;
if (dc.EndString == null) dc.EndStyle = null;
dcs[i] = dc;
vnum = brFmt.ReadInt16();
}
dcstyles.DcStyles = dcs;
brFmt.Close();
// Inherit fonts.
DoDSFontInherit(ref dcstyles);
// First serialize files based on the above - then use xsl to transform
// into prefered xml.
if (!Directory.Exists("fmt_xml")) Directory.CreateDirectory("fmt_xml");
if (!Directory.Exists("tmp_fmt_xml")) Directory.CreateDirectory("tmp_fmt_xml");
XmlSerializer serializer = new XmlSerializer(typeof(DocStyles));
string lfmtname = fmtName;
int indx = fmtName.IndexOf('.');
// for subformats, make the name FMT_00 where FMT is format name & 00 is number
// from original name. This will allow the data load to know it's a sub.
if (indx > 0)
lfmtname = fmtName.Substring(0, fmtName.Length - 4) + "_" + fmtName.Substring(fmtName.Length - 2, 2);
string destfile = "tmp_fmt_xml\\" + lfmtname + "d.xml";
if (File.Exists(destfile)) File.Delete(destfile);
TextWriter writer = new StreamWriter(destfile);
try
{
serializer.Serialize(writer, dcstyles);
writer.Close();
XslCompiledTransform xsl = new XslCompiledTransform();
xsl.Load(Application.StartupPath + "\\TranslateDoc.XSL");
string sResults = "fmt_xml\\" + lfmtname + "d.xml";
xsl.Transform(destfile, sResults); // Perform Transform
}
catch (Exception e)
{
Console.WriteLine(e.Message);
writer.Close();
}
}
private bool ConvertToSectType(int p)
{
if (((p & (int)E_OldToNewSteps.S0) != 0) || ((p & (int)E_OldToNewSteps.S1) != 0) || ((p & (int)E_OldToNewSteps.S2) != 0) ||
((p & (int)E_OldToNewSteps.E0) != 0) || ((p & (int)E_OldToNewSteps.E1) != 0) || ((p & (int)E_OldToNewSteps.E2) != 0) ||
((p & (int)E_OldToNewSteps.X0) != 0) || ((p & (int)E_OldToNewSteps.X1) != 0) || ((p & (int)E_OldToNewSteps.X2) != 0))
return true;
return false;
}
private string DoReplaceTokens(string p)
{
if (p == null || p == "") return p;
string wkstr = p;
// use regular expressions to do the following...
try
{
// replace newline with {par}
wkstr = wkstr.Replace("\n", "{par}");
// special change bar token (various cpl formats)
wkstr = wkstr.Replace("\x08\x08\x08\x08\x08\x05", "{CHG_BAR with Backspace Token}");
// special change bar token (various gpc formats)
wkstr = wkstr.Replace("\x05", "{CHG_BAR Token}");
// backspage - just flag for positioning if needed.
wkstr = wkstr.Replace("\x08", "{Backspace}");
//sub on/off
wkstr = wkstr.Replace("\x19\x19", "\x19"); // replace double sub on with single
wkstr = wkstr.Replace("~~", "\x19");
wkstr = Regex.Replace(wkstr, @"\x19([^\x19\x18 ]*?)(?:[\x19\x18]|(?= )|\Z)(.*?)", @"\sub$1\nosupersub$2");
//super on/off
wkstr = Regex.Replace(wkstr, @"\x18([^\x19\x18 ]*?)(?:[\x19\x18]|(?= )|\Z)(.*?)", @"\super$1\nosupersub$2");
//bold on/off
wkstr = Regex.Replace(wkstr, @"\x01([^\x01 ]*?)(?:[\x01]|(?= )|\Z)(.*?)", @"\b$1\b0$2");
wkstr = Regex.Replace(wkstr, @"\x13([^\x13\xd6 ]*?)(?:[\x13\xd6]|(?= )|\Z)(.*?)", @"\b$1\b0$2");
//underline on/off
wkstr = Regex.Replace(wkstr, @"\x16([^\x16 ]*?)(?:[\x16]|(?= )|\Z)(.*?)", @"\ul$1\ul0$2");
//narrator
wkstr = Regex.Replace(wkstr, @"\x86([^\x86 ]*?)(?:[\x86]|(?= )|\Z)(.*?)", @"\f{Narrator}$1\f0$2");
// remove hanging indent, vertical tab
wkstr = Regex.Replace(wkstr, @"\x02", @"\NonSupported Hanging Indent (Hex x02)");
wkstr = Regex.Replace(wkstr, @"\x0B", @"\NonSupported Vertical Tab (Hex x0b");
// remove some unknown chars for ano & fpl - these plants are not supported
// as of conversion date.
wkstr = Regex.Replace(wkstr, @"\x95", @"\NonSupported Unknown (Hex x95)"); //ano2vlv
wkstr = Regex.Replace(wkstr, @"\x1bf1", @"\NonSupported Unknown (hex 1b f1)"); //fpl
wkstr = Regex.Replace(wkstr, @"\x1bf0", @"\NonSupported Unknown (hex 1b f0)"); //fpl
wkstr = Regex.Replace(wkstr, @"\x1bM1", @"\NonSupported Unknown (hex 1b M1)"); //fpl
wkstr = Regex.Replace(wkstr, @"\x1bM0", @"\NonSupported Unknown (hex 1b M0)"); //fpl
// ATA page??
wkstr = Regex.Replace(wkstr, @"\x1b", @"{NonSupported Hex 1b}");
// replace \xff with \xA0, i.e. hardspace
wkstr = Regex.Replace(wkstr, @"\xFF", @"\xA0");
// replace x10 & x11 in various ano tabs - not this needs fixed if ANO comes
// back into the program
wkstr = wkstr.Replace("\x10", "");
wkstr = wkstr.Replace("\x11", "");
// replace x15 with {RO} for now.
wkstr = wkstr.Replace("\x15", "{RO}");
}
catch (Exception ex)
{
Console.WriteLine("error replacing token (regex) = {0}", ex.Message);
}
return wkstr;
}
private void CompareFonts(VE_Font parFont, ref VE_Font subFont)
{
if (parFont != null && subFont != null)
{
if (parFont.FontFamily == subFont.FontFamily) subFont.FontFamily = null;
if (parFont.FontSize == subFont.FontSize) subFont.FontSize = null;
if (parFont.FontStyle == subFont.FontStyle) subFont.FontStyle = null;
}
}
private void DoPSFontInherit(ref PageStyles pagstyles)
{
for (int i=0; i<pagstyles.PgStyles.Length; i++)
{
for (int j = 0; j < pagstyles.PgStyles[i].Items.Length; j++)
{
CompareFonts(DefPlantFont, ref pagstyles.PgStyles[i].Items[j].Style);
CompareFonts(DefBaseFont, ref pagstyles.PgStyles[i].Items[j].Style);
}
}
}
private void DoDSFontInherit(ref DocStyles docstyles)
{
// loop through all of the document styles. For each, check font inheritance
// for End Message Style, Continue Message Style & main document style.
for (int i=0; i<docstyles.DcStyles.Length; i++)
{
CompareFonts(docstyles.DcStyles[i].dstyle, ref docstyles.DcStyles[i].EndStyle);
CompareFonts(DefPlantFont, ref docstyles.DcStyles[i].EndStyle);
CompareFonts(DefBaseFont, ref docstyles.DcStyles[i].EndStyle);
CompareFonts(docstyles.DcStyles[i].dstyle, ref docstyles.DcStyles[i].ContStyle);
CompareFonts(DefPlantFont, ref docstyles.DcStyles[i].ContStyle);
CompareFonts(DefBaseFont, ref docstyles.DcStyles[i].ContStyle);
CompareFonts(DefPlantFont, ref docstyles.DcStyles[i].dstyle);
CompareFonts(DefBaseFont, ref docstyles.DcStyles[i].dstyle);
}
}
private bool GetPlantBaseDefaultFonts()
{
// read the xml files for the base & plant to get the default fonts and
// make a VE_font for each.
try
{
XmlDocument xdoc = new XmlDocument();
xdoc.Load("fmt_xml\\basef.xml");
XmlNode xfont = xdoc.SelectSingleNode("FormatData/Font");
DefBaseFont = new VE_Font(xfont);
string lfmtName = fmtName;
// for subformats, make the name FMT_00 where FMT is format name & 00 is number
// from original name. This will allow the data load to know it's a sub.
int indx = fmtName.IndexOf('.');
if (indx > 0)
lfmtName = fmtName.Substring(0, fmtName.Length - 4) + "_" + fmtName.Substring(fmtName.Length - 2, 2);
xdoc.Load("fmt_xml\\" + lfmtName + "f.xml");
xfont = xdoc.SelectSingleNode("FormatData/Font");
if (xfont!=null)DefPlantFont = new VE_Font(xfont);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
return false;
}
return true;
}
}
}

337
PROMS/fmtxml/Form1.cs Normal file
View File

@ -0,0 +1,337 @@
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.IO;
namespace fmtxml
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.ListBox listBox1;
private System.Windows.Forms.Button button3;
private System.Windows.Forms.Button button4;
private System.Windows.Forms.Button button5;
private C1.C1Pdf.C1PdfDocument c1PdfDocument1;
private System.Windows.Forms.Button button6;
private Button button7;
private Button button8;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
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.label1 = new System.Windows.Forms.Label();
this.button2 = new System.Windows.Forms.Button();
this.listBox1 = new System.Windows.Forms.ListBox();
this.button3 = new System.Windows.Forms.Button();
this.button4 = new System.Windows.Forms.Button();
this.button5 = new System.Windows.Forms.Button();
this.c1PdfDocument1 = new C1.C1Pdf.C1PdfDocument();
this.button6 = new System.Windows.Forms.Button();
this.button7 = new System.Windows.Forms.Button();
this.button8 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(8, 8);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(144, 48);
this.button1.TabIndex = 0;
this.button1.Text = "Convert Page and Doc Styles in format directory (Step 2)";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// label1
//
this.label1.Location = new System.Drawing.Point(8, 144);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(168, 16);
this.label1.TabIndex = 1;
this.label1.Text = "Converted:";
//
// button2
//
this.button2.Location = new System.Drawing.Point(512, 24);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(64, 24);
this.button2.TabIndex = 2;
this.button2.Text = "Exit";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// listBox1
//
this.listBox1.Location = new System.Drawing.Point(8, 168);
this.listBox1.Name = "listBox1";
this.listBox1.Size = new System.Drawing.Size(584, 407);
this.listBox1.TabIndex = 3;
//
// button3
//
this.button3.Location = new System.Drawing.Point(168, 8);
this.button3.Name = "button3";
this.button3.Size = new System.Drawing.Size(128, 48);
this.button3.TabIndex = 4;
this.button3.Text = "Convert genmac files to XML";
this.button3.Click += new System.EventHandler(this.button3_Click);
//
// button4
//
this.button4.Location = new System.Drawing.Point(320, 8);
this.button4.Name = "button4";
this.button4.Size = new System.Drawing.Size(112, 48);
this.button4.TabIndex = 5;
this.button4.Text = "Convert Genmac_XML to SVG";
this.button4.Click += new System.EventHandler(this.button4_Click);
//
// button5
//
this.button5.Location = new System.Drawing.Point(320, 97);
this.button5.Name = "button5";
this.button5.Size = new System.Drawing.Size(128, 48);
this.button5.TabIndex = 6;
this.button5.Text = "Convert Drawing Items XML to PDF";
this.button5.Click += new System.EventHandler(this.button5_Click);
//
// button6
//
this.button6.Location = new System.Drawing.Point(464, 97);
this.button6.Name = "button6";
this.button6.Size = new System.Drawing.Size(112, 48);
this.button6.TabIndex = 7;
this.button6.Text = "Convert SVG Xml to PDF";
this.button6.Click += new System.EventHandler(this.button6_Click);
//
// button7
//
this.button7.Location = new System.Drawing.Point(11, 69);
this.button7.Name = "button7";
this.button7.Size = new System.Drawing.Size(140, 51);
this.button7.TabIndex = 8;
this.button7.Text = "Convert Format in format directory (step 1)";
this.button7.UseVisualStyleBackColor = true;
this.button7.Click += new System.EventHandler(this.button7_Click);
//
// button8
//
this.button8.Location = new System.Drawing.Point(172, 70);
this.button8.Name = "button8";
this.button8.Size = new System.Drawing.Size(106, 49);
this.button8.TabIndex = 9;
this.button8.Text = "Integrate Fmt, Doc & Pag (step 3)";
this.button8.UseVisualStyleBackColor = true;
this.button8.Click += new System.EventHandler(this.button8_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(712, 590);
this.Controls.Add(this.button8);
this.Controls.Add(this.button7);
this.Controls.Add(this.button6);
this.Controls.Add(this.button5);
this.Controls.Add(this.button4);
this.Controls.Add(this.button3);
this.Controls.Add(this.listBox1);
this.Controls.Add(this.button2);
this.Controls.Add(this.label1);
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)
{
// get all of the files in the e:\ve-proms\format directory.
DirectoryInfo di = new DirectoryInfo("E:\\ve-proms\\format");
FileInfo[] fis = di.GetFiles("*.pag");
listBox1.Items.Clear();
foreach (FileInfo fi in fis)
{
string fn = fi.Name.Substring(0,fi.Name.Length-4);
this.listBox1.Items.Add(fi.Name);
FmtToXml fx = new FmtToXml(fn);
}
fis = di.GetFiles("*.y*");
foreach (FileInfo fi in fis)
{
this.listBox1.Items.Add(fi.Name);
FmtToXml fx = new FmtToXml(fi.Name);
}
MessageBox.Show("DONE Converting Page and Document Styles to XML");
}
private void button2_Click(object sender, System.EventArgs e)
{
Application.Exit();
}
private void button3_Click(object sender, System.EventArgs e)
{
// before doing the genmac change, use cpp -DRTF file after genmac.h
// has been emptied out on files in \promsnt\genmac. This creates
// precompiled files only, i.e. gets rid of some of the junk in the files.
// This conversion is done 1 time. After 32-bit print is done, the xml
// files will be used rather than the genmac.
DirectoryInfo di = new DirectoryInfo("E:\\promsnt\\genmac\\preproc");
FileInfo[] fis = di.GetFiles("*.i");
listBox1.Items.Clear();
foreach (FileInfo fi in fis)
{
// results go to e:\\proms.net\\genmac.xml\\convert
this.listBox1.Items.Add(fi.Name);
GenToXml gn = new GenToXml(fi.Name);
}
MessageBox.Show("DONE Converting genmacs to XML");
}
private void button4_Click(object sender, System.EventArgs e)
{
// delete current svg's
DirectoryInfo disvg = new DirectoryInfo("E:\\proms.net\\genmac.xml");
FileInfo[] fissvg = disvg.GetFiles("*.svg");
foreach (FileInfo fi in fissvg)fi.Delete();
DirectoryInfo di = new DirectoryInfo("E:\\proms.net\\genmac.xml\\convert");
FileInfo[] fis = di.GetFiles("*.xml");
listBox1.Items.Clear();
foreach (FileInfo fi in fis)
{
// results go to e:\proms.net\genmac.xml
this.listBox1.Items.Add(fi.Name);
GenXmlToSvg gn = new GenXmlToSvg(fi.Name);
}
MessageBox.Show("DONE Converting genmacs.xmls to drawing object.xmls");
}
private void button5_Click(object sender, System.EventArgs e)
{
DirectoryInfo di = new DirectoryInfo("E:\\ve-proms.net\\genmac.xml");
FileInfo[] fis = di.GetFiles("*.xml");
listBox1.Items.Clear();
foreach (FileInfo fi in fis)
{
this.listBox1.Items.Add(fi.Name);
XmlToPdf pdf = new XmlToPdf("E:\\ve-proms.net\\genmac.xml",fi.Name);
}
MessageBox.Show("DONE generating PDF files from XML");
}
private void button6_Click(object sender, System.EventArgs e)
{
DirectoryInfo di = new DirectoryInfo("E:\\proms.net\\genmac.xml");
FileInfo[] fis = di.GetFiles("*.svg");
listBox1.Items.Clear();
foreach (FileInfo fi in fis)
{
this.listBox1.Items.Add(fi.Name);
SvgToPdf pdf = new SvgToPdf("E:\\proms.net\\genmac.xml",fi.Name);
}
MessageBox.Show("DONE generating PDF files from SVG");
}
private void button7_Click(object sender, EventArgs e)
{
// first convert base format - for now use genfmt.
FmtFileToXml gx = new FmtFileToXml(null,"BASE");
// get all of the format files in the e:\ve-proms\format directory.
DirectoryInfo di = new DirectoryInfo("E:\\ve-proms\\format");
//DirectoryInfo di = new DirectoryInfo("E:\\proms.net\\exe\\fmtxml");
FileInfo[] fis = di.GetFiles("*.fmt");
listBox1.Items.Clear();
foreach (FileInfo fi in fis)
{
string fn = fi.Name.Substring(0, fi.Name.Length - 4);
if (fn.ToLower() != "base")
{
this.listBox1.Items.Add(fi.Name);
this.listBox1.Refresh();
FmtFileToXml fx = new FmtFileToXml(gx, fn);
}
}
MessageBox.Show("DONE Converting Formats to XML");
}
private void button8_Click(object sender, EventArgs e)
{
// get all of the generated xml format files in the fmt_xml directory and merge
// the fmt/doc/pag & subformats into one file.
DirectoryInfo di = new DirectoryInfo("fmt_xml");
//testDirectoryInfo di = new DirectoryInfo("E:\\proms.net\\exe\\fmtxml");
FileInfo[] fis = di.GetFiles("*f.xml");
listBox1.Items.Clear();
foreach (FileInfo fi in fis)
{
// see if all three, format, doc & pag exist - if not, print error,
// if so, process
string docname = "fmt_xml\\" + fi.Name.Substring(0, fi.Name.Length - 5) + "p.xml";
string pagname = "fmt_xml\\" + fi.Name.Substring(0, fi.Name.Length - 5) + "d.xml";
if (File.Exists(docname) && File.Exists(pagname))
{
this.listBox1.Items.Add(fi.Name);
EntireFormat ef = new EntireFormat("fmt_xml\\" + fi.Name);
}
else
Console.WriteLine("For {0}, page or document file does not exist.", fi.Name);
}
MessageBox.Show("DONE Converting Formats to XML");
}
}
}

123
PROMS/fmtxml/Form1.resx Normal file
View File

@ -0,0 +1,123 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="c1PdfDocument1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
</root>

151
PROMS/fmtxml/GenToXml.cs Normal file
View File

@ -0,0 +1,151 @@
using System;
using System.IO;
using System.Text.RegularExpressions;
using System.Windows.Forms;
namespace fmtxml
{
/// <summary>
/// Summary description for GenToXml.
/// </summary>
public class GenToXml
{
private StreamWriter strGenXml;
private string genName;
public GenToXml(string nm)
{
genName = nm;
try
{
OpenFiles();
ConvertGenToXml();
CloseFiles();
}
catch (Exception ex)
{
MessageBox.Show("Genmac name = " + nm, ex.Message);
}
}
public void OpenFiles()
{
if (!Directory.Exists("E:\\proms.net\\genmac.xml\\convert"))
Directory.CreateDirectory("E:\\proms.net\\genmac.xml\\convert");
string fnm = "E:\\proms.net\\genmac.xml\\convert\\" + genName;
string outnm = fnm.Substring(0,fnm.LastIndexOf(".")) + ".xml";
strGenXml = new StreamWriter(outnm,false,System.Text.Encoding.ASCII);
}
public void CloseFiles()
{
strGenXml.Close();
}
public void ConvertGenToXml()
{
string linein;
try
{
// use regular expressions to read in the genmac C file and convert to XML.
StreamReader sr = new StreamReader("E:\\promsnt\\genmac\\preproc\\"+genName);
linein = sr.ReadToEnd();
sr.Close();
}
catch (Exception e)
{
// Let the user know what went wrong.
MessageBox.Show("File cannot be written " + genName + " error is " + e.Message);
return;
}
if (linein==null)return;
int indxb = linein.IndexOf("BEGIN");
string line = linein.Substring(indxb,linein.Length-indxb);
linein=null;
// first Find defmac - endmac -> convert these do an element.
Regex defmacs = new Regex(@"DEFMAC(\s*|.*?)*ENDMAC",RegexOptions.IgnoreCase|RegexOptions.Compiled);
Match m;
strGenXml.Write("<" + genName.Substring(0,genName.LastIndexOf(".")) + "_GENMAC>\n");
for (m = defmacs.Match(line); m.Success; m = m.NextMatch())
{
strGenXml.Write("<MACRO><NAME>");
string mt = line.Substring(m.Index,m.Length);
//Find the macro name, i.e. DEFMAC(xyz)
int indxend = mt.IndexOf(")");
string macname = mt.Substring(7,indxend-7);
strGenXml.Write(macname+"</NAME>\n<DEFINITION>\n");
// the '+3' is to remove the \n\r also. The -9 is to account for the +3 &
// also remove the endmac
string macstr = mt.Substring(indxend+3,mt.Length-indxend-9);
// take x chars for the name & put out the name & definition.
string macnocomment = Regex.Replace(macstr, @"(\/\*(\s*|.*?)*\*\/)|(\/\/.*)", "");
mt = Regex.Replace(macnocomment,";","");
macnocomment = Regex.Replace(mt,@"\r\n",";");
mt = Regex.Replace(macnocomment,@";+",";"); // eliminate multiple ';'
macnocomment = mt;
if (mt.IndexOf("&")>-1)
macnocomment = mt.Replace("&","&amp;");
strGenXml.Write(macnocomment);
strGenXml.Write("\n</DEFINITION>\n</MACRO>\n");
}
// next find userdef - endmac -> convert these do an element.
defmacs = new Regex(@"USERDEF(\s*|.*?)*ENDMAC",RegexOptions.IgnoreCase|RegexOptions.Compiled);
for (m = defmacs.Match(line); m.Success; m = m.NextMatch())
{
strGenXml.Write("<USERDEF><NAME>");
string mt = line.Substring(m.Index,m.Length);
//Find the macro name, i.e. USERDEF(xyz)
int indxend = mt.IndexOf(")");
string macname = mt.Substring(8,indxend-8);
strGenXml.Write(macname+"\n</NAME>\n<DEFINITION>\n");
// the '+3' is to remove the \n\r also. The -9 is to account for the +3 &
// also remove the endmac
string macstr = mt.Substring(indxend+3,mt.Length-indxend-9);
// take x chars for the name & put out the name & definition.
string macnocomment = Regex.Replace(macstr, @"(\/\*(\s*|.*?)*\*\/)|(\/\/.*)", "");
mt = Regex.Replace(macnocomment,";","");
macnocomment = Regex.Replace(mt,@"\r\n",";");
mt = Regex.Replace(macnocomment,@";+",";"); // eliminate multiple ';'
macnocomment = mt;
if (mt.IndexOf("&")>-1)
macnocomment = mt.Replace("&","&amp;");
strGenXml.Write(macnocomment);
strGenXml.Write("\n</DEFINITION>\n</USERDEF>\n");
}
// last find static functions - these have macro definitions too.
Regex defmacf = new Regex(@"static void (\s*|.*?)*}",RegexOptions.IgnoreCase|RegexOptions.Compiled);
for (m = defmacf.Match(line); m.Success; m = m.NextMatch())
{
strGenXml.Write("<STATICVOID><NAME>");
string mt = line.Substring(m.Index,m.Length);
//Find the function name, i.e. static void boxx. Parameters are on an different node(int i)
int indxbeg= mt.IndexOf("(");
string fnname = mt.Substring(12,indxbeg-12);
strGenXml.Write(fnname+"</NAME>\n<PARAMETERS>\"");
int indxend=mt.IndexOf(")");
string param = null;
if (indxend-1==indxbeg)
param = "none";
else
param = mt.Substring(indxbeg+1,indxend-1-indxbeg);
strGenXml.Write(param+"\"\n</PARAMETERS>\n<DEFINITION>");
// now get past the opening curly.
indxbeg = mt.IndexOf("{");
string fnstr = mt.Substring(indxbeg+2,mt.Length-indxbeg-3);
string macnocomment = Regex.Replace(fnstr, @"(\/\*(\s*|.*?)*\*\/)|(\/\/.*)", ""); // matches multi/single line comments: (\/\*(\s*|.*?)*\*\/)|(\/\/.*)
mt = Regex.Replace(macnocomment,";","");
macnocomment = Regex.Replace(mt,@"\r\n",";");
mt = Regex.Replace(macnocomment,@";+",";");
if (mt.IndexOf("&")>-1)
mt = mt.Replace("&","&amp;");
strGenXml.Write(mt);
strGenXml.Write("\n</DEFINITION>\n</STATICVOID>\n");
}
strGenXml.Write("</" + genName.Substring(0,genName.LastIndexOf(".")) + "_GENMAC>");
}
}
}

769
PROMS/fmtxml/GenXmlToSvg.cs Normal file
View File

@ -0,0 +1,769 @@
using System;
using System.IO;
using System.Xml;
using System.Text;
using System.Drawing;
using System.Windows.Forms;
namespace fmtxml
{
/// <summary>
/// Convert genmac xml files to svg. svg (Scalar Vector Graphics
/// in XML format), so that genmac can be used in the 32-bit proms
/// system. The generated files will be used by developers and
/// customer service persons to do macros.
/// </summary>
public class GenXmlToSvg
{
private string genName;
private XmlDocument xmlDoc;
private XmlDocument xmlOutDoc;
private XmlElement topOutElement;
private int Convertn = 300, I = 300, C = 118, D = 1;
private float Wid = 3;
private int RTFFontSize = 20;
private int RTFFontFamily = 3;
private string [] FontChoice =
{
"Times New Roman",
"VESymb XXXXXX",
"VolianDraw XXXXXX",
"Prestige Elite Tall",
"Courier New",
"Arial",
"Letter Gothic",
"Times New Roman",
"Letter Gothic Tall",
"Letter Gothic Tall",
"Gothic Ultra",
"VolianScript"
};
private string [] OldName =
{
"BOX1",
"BOX2",
"BOX3",
"BOX4",
"BOX5",
"HDR1",
"HDR2",
"HDR3",
"HDR4",
"HDR5",
"BOLDX",
"CNUM",
"CHKBOX",
"CHKBOX2",
"CHKBOX3",
"CHKBOX4",
"CHKBOX5",
"CHKBOX6",
"CHKBOX7",
"CHKBOX8",
"CHKBOX9",
"CHKBOX10",
"CHKBOX11",
"CHKBOX12",
"CHKBOX13",
"CHKBOX14",
"CHKBOX15",
"CHKBOX16",
"CHKBOX17",
"PLNTPLMAC",
"PLNTPLMAC2",
"GRAPHMAC0",
"GRAPHMAC1",
"RIGHTCHECKOFF",
"HPGLCOMMAND0",
"HPGLCOMMAND1",
"HPGLCOMMAND2",
"HPGLCOMMAND3",
"HPGLCOMMAND4",
"HPGLCOMMAND5",
"HPGLCOMMAND6",
"HPGLCOMMAND7",
"HPGLCOMMAND8",
"HPGLCOMMAND9",
"LTCO",
"SECDBLBXVERT",
"BOX6",
"BOX7",
"BOX8",
"ACAS_CHECKBOX",
"ACAS_CHECKLINE",
};
private string [] NewName =
{
"B1",
"B2",
"B3",
"B4",
"B5",
"H1",
"H2",
"H3",
"H4",
"H5",
"m33",
"C0",
"C1",
"C2",
"C3",
"C4",
"C5",
"C6",
"C7",
"C8",
"C9",
"C10",
"C11",
"C12",
"C13",
"C14",
"C15",
"C16",
"C17",
"m18",
"m19",
"m20",
"m21",
"C22",
"m23",
"m24",
"m25",
"m26",
"m27",
"m28",
"m29",
"m30",
"m31",
"m32",
"m20",
"m34",
"B6",
"B7",
"B8",
"m35",
"m36",
};
private int RTFBUI = 0;
private int Sp = -1;
private float cx = 0;
private float cy = 0;
private int fidx=0;
private int [] fontfam;
private int [] fontsiz;
private float [] PPx;
private float [] PPy;
// the following define RTFBUI values
private static int BOLD = 0x01;
private static int UNDERLINE = 0x02;
private static int ITALICS = 0x04;
public GenXmlToSvg(string nm)
{
genName = nm;
try
{
fontfam = new int[20];
fontsiz = new int[20];
PPx = new float[12];
PPy = new float[12];
ReadXml();
ConvertGenXmlToDIXml();
WriteXml();
}
catch (Exception ex)
{
Console.WriteLine("Genmac.xml name = " + nm + ". Error is " + ex.Message);
}
}
private float CPoint(float x)
{
if (Convertn == C)
{
// convert from x (in centimeters) to inches & then to points
return (float) (.3937 * x * 72);
} // convert from x (in inches) to points
else if (Convertn == I)
return (float)(x * 72);
else // convert from x (in dots) to twips & then points
return (float)(((4.8 * x + 0.5)/1440f)*72);
}
private void WriteXml()
{
string path = "E:\\proms.net\\genmac.xml\\" + genName.Substring(0,genName.LastIndexOf(".")) + ".svg";
XmlTextWriter writer = new XmlTextWriter(path,System.Text.Encoding.Unicode);
writer.Formatting=System.Xml.Formatting.Indented;
xmlOutDoc.Save(writer);
}
private void ReadXml()
{
string fnm = "E:\\proms.net\\genmac.xml\\convert\\" + genName;
xmlDoc = new XmlDocument();
XmlTextReader reader = new XmlTextReader(fnm);
xmlDoc.Load(reader);
reader.Close();
}
private void ConvertGenXmlToDIXml()
{
// first create the document for the svg version of the macro files
// and add the top svg element.
xmlOutDoc = new XmlDocument();
topOutElement = xmlOutDoc.CreateElement("svg");
topOutElement.SetAttribute("width","8in");
topOutElement.SetAttribute("height","10in");
topOutElement.SetAttribute("viewBox","0 0 576 720");
// topOutNode.Attributes.Append(attr);
// topOutNode.Attributes.Append<svg width="8in" height="10in" viewBox="0 0 576 720"
// xmlns="http://www.w3.org/2000/svg" version="1.1">
xmlOutDoc.AppendChild(topOutElement);
// Next add the description node, which is the name of the plant format.
XmlElement descNode = xmlOutDoc.CreateElement("desc");
descNode.InnerText = genName.Substring(0,genName.LastIndexOf("."));
topOutElement.AppendChild(descNode);
XmlElement top = (XmlElement) xmlDoc.FirstChild;
XmlNode sv = top.SelectSingleNode("STATICVOID");
XmlNodeList xmlNds = top.SelectNodes("MACRO");
// Now for each macro, create a svg group with the name given to
// it. Later we may change this to map to what was created in 16-bit
// proms (for example BOX1 -> B1)
foreach (XmlNode nd in xmlNds)
{
XmlNode name = nd.SelectSingleNode("NAME");
XmlElement elm = (XmlElement) name;
XmlElement grp = xmlOutDoc.CreateElement("g");
string cname = GetName(name.InnerText);
grp.SetAttribute("id",cname);
topOutElement.AppendChild(grp);
XmlNode definition = nd.SelectSingleNode("DEFINITION");
try
{
string str = ProcessMacroDefinition(grp,definition,sv);
}
catch (Exception e)
{
MessageBox.Show("Error processing macro definition for " + this.genName, e.Message);
}
}
xmlNds = top.SelectNodes("USERDEF");
// Now for each user defined macro, create a svg group with the
// name given to it.
foreach (XmlNode nd in xmlNds)
{
XmlNode name = nd.SelectSingleNode("NAME");
XmlElement elm = (XmlElement) name;
XmlElement grp = xmlOutDoc.CreateElement("g");
string tmpdebug = name.InnerText.Trim("\n".ToCharArray());
grp.SetAttribute("id",tmpdebug);
topOutElement.AppendChild(grp);
XmlNode definition = nd.SelectSingleNode("DEFINITION");
try
{
string str = ProcessMacroDefinition(grp,definition,sv);
}
catch (Exception e)
{
MessageBox.Show("Error processing macro definition for " + this.genName, e.Message);
}
}
}
// convert the macro names as was done in 16-bit code?
string GetName(string oname)
{
for (int i=0; i<51 ; i++)
{
if (oname == OldName[i]) return NewName[i];
}
return "NONAME";
}
private void PushFont()
{
if( fidx < 19 )
{
fontfam[fidx] = RTFFontFamily;
fontsiz[fidx] = RTFFontSize;
fidx++;
}
return;
}
private void PopFont()
{
if( fidx > 0 )
{
fidx--;
RTFFontFamily = fontfam[fidx];
RTFFontSize = fontsiz[fidx];
}
return;
}
private void PushPos()
{
if (Sp < 11)
{
Sp++;
PPx[Sp] = cx;
PPy[Sp] = cy;
}
}
private void PopPos()
{
if (Sp > -1)
{
cx = PPx[Sp];
cy = PPy[Sp];
Sp--;
}
}
private XmlElement RTFAdjust(float x, float y)
{
// This was used for RTF export only.
return null;
}
private XmlElement GDIAdjust(float x, float y)
{
// can't quite figure out what this is doing
// KBR TODO: gdiadjust
return null;
}
private float GetOneFloat(string cmd)
{
int indxlp = cmd.IndexOf("(");
int indxrp = cmd.IndexOf(")");
string tmp = cmd.Substring(indxlp+1,indxrp-indxlp-1);
return (float) Convert.ToDouble(tmp);
}
private void GetTwoFloats(string cmd, ref float x, ref float y)
{
int indxlp = cmd.IndexOf("(");
int indxcm = cmd.IndexOf(",");
int indxrp = cmd.IndexOfAny("),".ToCharArray(),indxcm+1);
x = (float) Convert.ToDouble(cmd.Substring(indxlp+1,indxcm-indxlp-1));
y = (float) Convert.ToDouble(cmd.Substring(indxcm+1,indxrp-indxcm-1));
}
private XmlElement DefineMacro(string str)
{
byte x = Convert.ToByte(173);
cx=cy=0;
return null;
}
private XmlElement HorizontalLine(float X)
{
XmlElement box = this.xmlOutDoc.CreateElement("line");
box.SetAttribute("x1",cx.ToString());
box.SetAttribute("y1",cy.ToString());
box.SetAttribute("x2",(cx+CPoint(X)).ToString());
box.SetAttribute("y2",cy.ToString());
box.SetAttribute("stroke-width",Wid.ToString());
return box;
}
private XmlElement VerticalLine(float Y)
{
XmlElement box = this.xmlOutDoc.CreateElement("line");
box.SetAttribute("x1",cx.ToString());
box.SetAttribute("y1",cy.ToString());
box.SetAttribute("x2",cx.ToString());
box.SetAttribute("y2",(cy+CPoint(Y)).ToString());
box.SetAttribute("stroke-width",Wid.ToString());
return box;
}
private XmlElement DiagLine(float X, float Y)
{
XmlElement box = this.xmlOutDoc.CreateElement("line");
box.SetAttribute("x1",cx.ToString());
box.SetAttribute("y1",cy.ToString());
box.SetAttribute("x2",(cx+CPoint(X)).ToString());
box.SetAttribute("y2",(cy+CPoint(Y)).ToString());
box.SetAttribute("stroke-width",Wid.ToString());
return box;
}
private XmlElement Box(float X, float Y)
{
XmlElement box = this.xmlOutDoc.CreateElement("rect");
box.SetAttribute("x",cx.ToString());
box.SetAttribute("y",cy.ToString());
box.SetAttribute("width",CPoint(X).ToString());
box.SetAttribute("height",CPoint(Y).ToString());
box.SetAttribute("fill","none");
box.SetAttribute("stroke","black");
box.SetAttribute("stroke-width",Wid.ToString());
return box;
}
private XmlElement Ellipse(float X, float Y)
{
XmlElement ellipse = this.xmlOutDoc.CreateElement("ellipse");
ellipse.SetAttribute("cx",cx.ToString());
ellipse.SetAttribute("cy",cy.ToString());
ellipse.SetAttribute("rx",(CPoint(X)).ToString());
ellipse.SetAttribute("ry",(CPoint(Y)).ToString());
ellipse.SetAttribute("fill","none");
ellipse.SetAttribute("stroke","black");
ellipse.SetAttribute("stroke-width",Wid.ToString());
return ellipse;
}
private XmlElement Text(float X, float Y, string str)
{
//text-decoration="underline"
//font-weight="bold"
//font-style="italic"
XmlElement text = this.xmlOutDoc.CreateElement("text");
text.SetAttribute("x",(cx+CPoint(X)).ToString());
text.SetAttribute("y",(cy+CPoint(Y)).ToString());
text.SetAttribute("font-family",FontChoice[RTFFontFamily]);
text.SetAttribute("font-size",(RTFFontSize/2).ToString());
if ((RTFBUI&BOLD)==1) text.SetAttribute("font-weight","bold");
if ((RTFBUI&UNDERLINE)==1) text.SetAttribute("text-decoration", "underline");
if ((RTFBUI&ITALICS)==1) text.SetAttribute("font-style","italic");
text.InnerText = str;
return text;
}
private XmlElement[] RTFBox3(float x, float y)
{
XmlElement[] elearr = new XmlElement[3];
PushPos();
elearr[0] = VerticalLine(y);
cy += CPoint(y);
elearr[1] = HorizontalLine(x);
cx += CPoint(x);
float ftmp = (float) (y*-1.0);
cy += CPoint(ftmp);
elearr[2] = VerticalLine(y);
PopPos();
return elearr;
}
private XmlElement BitMap(float X, float Y, string str)
{
XmlElement bmap = xmlOutDoc.CreateElement("image");
bmap.SetAttribute("x",(cx+CPoint(X)).ToString());
bmap.SetAttribute("y",(cy+CPoint(Y)).ToString());
Bitmap bmp= new Bitmap(str);
bmap.SetAttribute("width",bmp.Width.ToString()+"px");
bmap.SetAttribute("height",bmp.Height.ToString()+"px");
//bmap.SetAttribute("xlink:href",str);
bmap.SetAttribute("bname",str);
return bmap;
}
private void GetFont(string fontexp)
{
if (fontexp==null||fontexp=="")
{
RTFFontFamily = 3;
RTFFontSize = 20;
}
else if (fontexp.IndexOf("PICA")>-1)
{
RTFFontFamily = 4;
RTFFontSize = 24;
}
else if (fontexp.IndexOf("EXPANDED")>-1)
{
RTFFontSize = 24;
}
else if(fontexp.IndexOf("SANSERIF")>-1)
{
RTFFontFamily = 6;
RTFFontSize = 20;
}
else if (fontexp.IndexOf("PROPT12")>-1)
{
RTFFontFamily = 5;
RTFFontSize = 22;
}
else if (fontexp.IndexOf("COMPRESSED")>-1)
{
RTFFontFamily = 6;
RTFFontSize = 14;
}
if (fontexp.IndexOf("BOLD")>-1) RTFBUI |= BOLD; else RTFBUI &= 0xFFFE;
if (fontexp.IndexOf("UNDERLINE")>-1) RTFBUI |= UNDERLINE; else RTFBUI &= 0xFFFD;
if (fontexp.IndexOf("ITALICS")>-1) RTFBUI |= ITALICS; else RTFBUI &= 0xFFFB;
}
private string ProcessMacroDefinition(XmlElement grp, XmlNode idef, XmlNode functions)
{
XmlElement elm = (XmlElement) idef;
string def = elm.InnerText;
StringBuilder str_result = new StringBuilder();
fidx=0;
cx = 0;
cy = 0;
Wid = 3;
RTFFontSize = 20;
RTFFontFamily = 3;
Sp = -1;
// for each element, process the token for the element and add it to the
// xml tree (ProcessToken does both).
int lindx = 0;
int indx = def.IndexOf(";");
while (indx>-1)
{
ProcessToken(grp, def, lindx, indx, functions);
lindx = indx+1;
indx = def.IndexOf(";",lindx);
}
return str_result.ToString();
}
private void ProcessToken(XmlElement grp, string def, int lindx, int indx, XmlNode functions)
{
float x=0,y=0;
XmlElement retval = null;
//get the token, i.e. from last index to this one.
string token = def.Substring(lindx,indx-lindx).Trim();
if (token==null||token=="")return;
string cmd = token; // cmd has the command without parens/values
if (token.IndexOf("(")>-1) cmd = token.Substring(0,token.IndexOf("("));
if (token.IndexOf("RTFFontSize")>-1)cmd = "RTFFontSize";
if (token.IndexOf("RTFFontFamily")>-1)cmd = "RTFFontFamily";
if (token.IndexOf("RTFBUI")>-1) cmd = "RTFBUI";
if (token.IndexOf("DEFMAC")>-1) cmd = "DEFMAC";
if (token.IndexOf("HLINE")>-1) cmd = "HLINE";
if (token.IndexOf("TEXT")>-1) cmd = "TEXT";
if (token.IndexOf("BITMAP")>-1) cmd = "BITMAP";
if (cmd==null)return;
try
{
switch (cmd)
{
case "DEFMAC": // command is DEFMAC(xyz)
MessageBox.Show("DEFMAC found, format = " + genName + " not converted - do manually");
int indxl = token.IndexOf("(");
int indxr = token.IndexOf(")");
string strx = token.Substring(indxl+1,indxr-indxl-1).Trim();
retval = DefineMacro(strx);
break;
case "PUSHF":
PushFont();
break;
case "POPF":
PopFont();
break;
case "PUSHP":
PushPos();
break;
case "POPP":
PopPos();
break;
case "UNIT":
if (token.IndexOf("C")>-1)Convertn = C;
else if (token.IndexOf("I",4)>-1)Convertn = I;
else if (token.IndexOf("D")>-1)Convertn = D;
break;
case "RTFADJ": // command is RTFADJ(x,y)
GetTwoFloats(token, ref x, ref y);
retval = RTFAdjust(x, y);
break;
case "GDIADJ": // command is GDIADJ(x,y)
GetTwoFloats(token, ref x, ref y);
retval = GDIAdjust(x, y);
break;
case "FONT": //comand is FONT(FONTSTR)
GetFont(token);
break;
case "RTFFontSize": // command is RTFFontSize = x
int indxe = token.IndexOf("=");
string numstr = token.Substring(indxe+1,token.Length-indxe-1).Trim();
if (numstr.IndexOf("*")>-1)
{
int i1 = Convert.ToInt32(numstr.Substring(0,numstr.IndexOf("*")));
int i2 = Convert.ToInt32(numstr.Substring(numstr.IndexOf("*")+1,numstr.Length-numstr.IndexOf("*")-1));
RTFFontSize = i1*i2;
}
else
RTFFontSize = Convert.ToInt32(numstr);
break;
case "RTFBUI":
// command either sets it '=' or ORs it '|= ', look for these.
int ieq = token.IndexOf("=");
string val = token.Substring(ieq+1,token.Length-ieq-1).Trim();
int amt=0;
if (token.IndexOf("0x")<0)
amt = Convert.ToInt32(val);
else
amt = Convert.ToInt32(val,16);
int operor = token.IndexOf("|=");
int operand = token.IndexOf("&=");
if (operor<0 && operand<0)
RTFBUI = amt;
else if (operor>0)
RTFBUI |= amt;
else
RTFBUI &= amt;
break;
case "RTFFontFamily": // command is RTFFontFamily = x
indxe = token.IndexOf("=");
numstr = token.Substring(indxe+1,token.Length-indxe-1).Trim();
RTFFontFamily = Convert.ToInt32(numstr);
break;
case "LNWID": // command is LNWID(w)
float w = GetOneFloat(token);
Wid = CPoint(w);
break;
case "MOVA": // command is MOVA(x, y)
GetTwoFloats(token,ref x, ref y);
cx = CPoint(x);
cy = CPoint(y);
break;
case "MOVR": // command is MOVR(x, y)
GetTwoFloats(token,ref x, ref y);
cx += CPoint(x);
cy += CPoint(y);
break;
case "HLINE": // command is HLINE(x)
x = GetOneFloat(token);
grp.AppendChild(HorizontalLine(x));
break;
case "VLINE": // command is VLINE(y)
y = GetOneFloat(token);
grp.AppendChild(VerticalLine(y));
break;
case "DLINE": // command is DLINE(x, y)
GetTwoFloats(token, ref x, ref y);
grp.AppendChild(DiagLine(x, y));
break;
case "BOX": // command is BOX(x, y)
GetTwoFloats(token,ref x, ref y);
grp.AppendChild(Box(x,y));
break;
case "BOX3SIDES": // command is BOX3SIDES(X,Y)
GetTwoFloats(token, ref x, ref y);
XmlElement [] bxsd = new XmlElement[3];
bxsd = RTFBox3(x, y);
for (int ib = 0;ib < 3; ib++) grp.AppendChild(bxsd[ib]);
break;
case "DBOX": // * DBOX(X,Y,A) DoubleBox((double)X,(double)Y,(double)A);
MessageBox.Show("Not supported - ANO only");
break;
case "CIRCLE": // command is CIRCLE(X,Y)
GetTwoFloats(token, ref x, ref y);
grp.AppendChild(Ellipse(x,y));
break;
case "TEXT": // command is TEXT(x, y, str)
GetTwoFloats(token,ref x, ref y);
int indxrp = token.IndexOf(",");
indxrp = token.IndexOf(",",indxrp+1);
// this found the last argument, i.e. text - now find the "
indxrp = token.IndexOf("\"",indxrp+1);
string str = token.Substring(indxrp+1,token.LastIndexOf("\"")-indxrp-1);
// only trim if has characters?
// if (str!=null)str = str.Trim();
if (str!=null && str!="") grp.AppendChild(Text(x, y, str));
break;
case "BITMAP":
int ibm = token.IndexOf("BITMAP");
int ibmq = token.IndexOf("\"",ibm);
string thestr = token.Substring(ibm,ibmq-ibm);
string [] bmap = thestr.Split(" ".ToCharArray(),4);
x=(float)Convert.ToDouble(bmap[1]);
y=(float)Convert.ToDouble(bmap[2]);
thestr=bmap[3];
if (thestr.IndexOf("~FORMAT\\")>-1) thestr=thestr.Replace("~FORMAT","E:\\VE-PROMS\\FORMAT");
grp.AppendChild(BitMap(x,y,thestr));
break;
case "ABSOLUTE": // no-op ?
break;
default: // function calls
// see if in the STATICVOID list. The name is the function name
// without () or parameters...
XmlNode parent = functions.ParentNode;
XmlNode foundsv = parent.SelectSingleNode("STATICVOID[NAME = \""+cmd+"\"]");
if (foundsv==null)
Console.WriteLine("Name " + genName + " failed. The token is not in list, token = " +token);
else
{
XmlNode param = foundsv.SelectSingleNode("PARAMETERS");
XmlNode deffn = foundsv.SelectSingleNode("DEFINITION");
// get the argument value to pass in.
int ilp = token.IndexOf("(");
int irp = token.IndexOf(")");
string aval=null;
if (ilp>0&&irp>0) aval = token.Substring(ilp+1,irp-ilp-1);
ProcessFunctions(grp, param.InnerText,functions, aval, deffn.InnerText);
}
break;
}
}
catch (Exception e)
{
Console.WriteLine("Name = " + genName + ". Error in token: " + token, e.Message);
retval = null;
}
return;
}
private void ProcessFunctions(XmlElement grp, string param, XmlNode functions, string val, string fntext)
{
// Each function contains a series of commands that must be processed for the
// function. Results are added to the group element for this group (macro).
string repstr=null;
// if there is a parameter, get the substitution string...
if (param.IndexOf("none")==-1)
{
int chrindx = param.IndexOf("char *");
int end = -1;
if (chrindx>-1)
{
end = param.IndexOf("\"",chrindx);
repstr = param.Substring(chrindx+6,end-chrindx-6);
}
else
{
chrindx = param.IndexOf("int ");
if (chrindx>-1)
{
end = param.IndexOf("\"",chrindx);
repstr = param.Substring(chrindx+4,end-chrindx-4);
}
}
}
// find the function commands and include them here.
string funstr = fntext;
if (repstr!=null)funstr = funstr.Replace(repstr,val);
// for each element, process commands.
int lindx = 0;
int indx = funstr.IndexOf(";");
while (indx>-1)
{
ProcessToken(grp, funstr, lindx, indx, functions);
lindx = indx+1;
indx = funstr.IndexOf(";",lindx);
}
}
}
}

191
PROMS/fmtxml/SvgToPdf.cs Normal file
View File

@ -0,0 +1,191 @@
using System;
using System.Text;
using System.Xml;
using System.Drawing;
using System.Windows.Forms;
using C1.C1Pdf;
namespace fmtxml
{
/// <summary>
/// Summary description for XmlToPdf.
/// </summary>
public class SvgToPdf
{
private float ConvertToPoints=72f;
private XmlDocument xmlDoc;
private string FileName;
private string FilePath;
private C1.C1Pdf.C1PdfDocument _c1pdf;
private string [] FontChoice =
{"Times New Roman",
"VESymb XXXXXX",
"VolianDraw XXXXXX",
"Prestige Elite Tall",
"Courier New",
"Arial",
"Letter Gothic",
"Times New Roman",
"Letter Gothic Tall",
"Letter Gothic Tall",
"Gothic Ultra",
"VolianScript"
};
private float LeftMargin; //todo: define in page info
private float VerticalOffset; //todo: define in page info
private bool Portrait; //todo: define in page info
public SvgToPdf(string path, string fname)
{
LeftMargin=0.5f * ConvertToPoints; // KBR: TODO
VerticalOffset=0.5f * ConvertToPoints; // KBR: TODO
Portrait = true; // KBR: TODO
FileName = fname;
FilePath = path;
xmlDoc = new XmlDocument();
XmlTextReader reader = new XmlTextReader(FilePath+"\\"+FileName);
xmlDoc.Load(reader);
reader.Close();
try
{
GeneratePDFForFile();
}
catch (Exception e)
{
MessageBox.Show("Error processing: " + fname, e.Message);
}
}
private void GeneratePDFForFile()
{
_c1pdf = new C1.C1Pdf.C1PdfDocument();
string rootname = FileName.Substring(0,FileName.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;
XmlNodeList ndlist = topnode.SelectNodes("/g");
for (int i=0;i<topnode.ChildNodes.Count;i++)
{
XmlNode nd = topnode.ChildNodes[i];
if (nd.Name!="desc")
{
SvgConvertToPdf(nd);
_c1pdf.NewPage();
}
}
string outname = "E:\\proms.net\\genmac.xml\\testpdf\\" + rootname + ".pdf";
_c1pdf.Save(outname);
}
private string AddRTFBUI(string origStr, string bold, string underline, string italics)
{
if (bold==""&&underline==""&&italics=="")return origStr;
StringBuilder sb = new StringBuilder();
if (bold == "bold")sb.Append("{\\b");
if (underline == "underline")sb.Append("{\\u");
if (italics == "italics") sb.Append("{\\i");
sb.Append(" ");
sb.Append(origStr);
if (bold == "bold")sb.Append("}");
if (underline == "underline")sb.Append("}");
if (italics == "italics") sb.Append("}");
return sb.ToString();
}
private void SvgConvertToPdf(XmlNode nd)
{
for (int i=0; i<nd.ChildNodes.Count; i++)
{
XmlElement cmdele = (XmlElement) nd.ChildNodes[i];
string cmdline = cmdele.InnerXml;
string cmd = cmdele.Name.ToLower();
float fstx, fsty, fex, fey = 0;
float flw = 0;
// temporary for testing of negative placement (x/y) values...
XmlElement tstele = (XmlElement) nd;
if (tstele.GetAttribute("id")=="CNUM")
{
LeftMargin = 100.0f;
VerticalOffset = 100f;
}
Pen pn = null;
switch (cmd)
{
case "rect":
fstx = (float) System.Convert.ToDouble(cmdele.GetAttribute("x"));
fsty = (float) System.Convert.ToDouble(cmdele.GetAttribute("y"));
fex = (float) System.Convert.ToDouble(cmdele.GetAttribute("width"));
fey = (float) System.Convert.ToDouble(cmdele.GetAttribute("height"));
flw = (float) System.Convert.ToDouble(cmdele.GetAttribute("stroke-width"));
pn = new Pen(Brushes.Black,flw);
//KBR: TODO - storing page stuff such as portland, vertical offset, tab, etc.
RectangleF rc = new RectangleF(LeftMargin+fstx,VerticalOffset+fsty,fex,fey);
_c1pdf.DrawRectangle(pn,rc);
break;
case "line": // command is LINE startx, starty, endx, endy, lnwidth
fstx = (float) System.Convert.ToDouble(cmdele.GetAttribute("x1"));
fsty = (float) System.Convert.ToDouble(cmdele.GetAttribute("y1"));
fex = (float) System.Convert.ToDouble(cmdele.GetAttribute("x2"));
fey = (float) System.Convert.ToDouble(cmdele.GetAttribute("y2"));
float flw1 = (float) System.Convert.ToDouble(cmdele.GetAttribute("stroke-width"));
//KBR: TODO - storing page stuff such as portland, vertical offset, tab, etc.
// startx = portland ? (vof + cy + adjy) : (cx + tab + adjx);
// starty = portland ? (tab - (cx + adjx)) : (cy + vof + adjy);
pn = new Pen(Brushes.Black,flw1);
//KBR: TODO - move ablsolute?
// if (MoveAbsolute)
// {tab = 0;vof = 0;}
_c1pdf.DrawLine(pn, LeftMargin+fstx, VerticalOffset+fsty, LeftMargin+fex, VerticalOffset+fey);
break;
case "text":
fstx = (float) System.Convert.ToDouble(cmdele.GetAttribute("x"));
fsty = (float) System.Convert.ToDouble(cmdele.GetAttribute("y"));
int FontSize = System.Convert.ToInt32(cmdele.GetAttribute("font-size"));
string bold = cmdele.GetAttribute("font-weight");
string underline = cmdele.GetAttribute("text-decoration");
string italics = cmdele.GetAttribute("font-style");
Font myfont = new Font(cmdele.GetAttribute("font-family"),FontSize);
rc = new Rectangle();
rc.Size = _c1pdf.MeasureStringRtf(cmdele.InnerText,myfont,500); // kbr todo: 500?
rc.X = LeftMargin+fstx;
rc.Y = VerticalOffset+fsty-FontSize;
// add bold, underline & italics for entire object.
string rtfout = AddRTFBUI(cmdele.InnerText,bold,underline,italics);
_c1pdf.DrawStringRtf(rtfout,myfont,Brushes.Black,rc);
break;
case "gdiadj":
break;
case "ellipse":
fstx = (float) System.Convert.ToDouble(cmdele.GetAttribute("cx"));
fsty = (float) System.Convert.ToDouble(cmdele.GetAttribute("cy"));
fex = (float) System.Convert.ToDouble(cmdele.GetAttribute("rx"));
fey = (float) System.Convert.ToDouble(cmdele.GetAttribute("ry"));
flw = (float) System.Convert.ToDouble(cmdele.GetAttribute("stroke-width"));
pn = new Pen(Brushes.Black,flw);
_c1pdf.DrawEllipse(pn,LeftMargin+fstx, VerticalOffset+fsty, fex, fey);
break;
case "image":
fstx = (float) System.Convert.ToDouble(cmdele.GetAttribute("x"));
fsty = (float) System.Convert.ToDouble(cmdele.GetAttribute("y"));
int scale=1;
if (cmdele.HasAttribute("scale")) scale = System.Convert.ToInt32(cmdele.GetAttribute("scale"));
string fname = cmdele.GetAttribute("bname");
Bitmap bm = new Bitmap(fname);
Image img = Image.FromFile(fname);
rc = new RectangleF();
rc.Height = (((img.Height*scale)*4.8f)/1440f)*72f;
rc.Width = (((img.Width*scale)*4.8f)/1440f)*72f;
rc.X = LeftMargin+fstx;
rc.Y = VerticalOffset+fsty;
_c1pdf.DrawImage(img, rc, ContentAlignment.MiddleCenter, ImageSizeModeEnum.Scale);
break;
case "absolute":
break;
default:
break;
}
}
}
}
}

188
PROMS/fmtxml/XmlToPdf.cs Normal file
View File

@ -0,0 +1,188 @@
using System;
using System.Xml;
using System.Drawing;
using System.Windows.Forms;
using C1.C1Pdf;
namespace fmtxml
{
/// <summary>
/// Summary description for XmlToPdf.
/// </summary>
public class XmlToPdf
{
private float ConvertToPoints=72f;
private XmlDocument xmlDoc;
private string FileName;
private string FilePath;
private C1.C1Pdf.C1PdfDocument _c1pdf;
private string [] FontChoice =
{"Times New Roman",
"VESymb XXXXXX",
"VolianDraw XXXXXX",
"Prestige Elite Tall",
"Courier New",
"Arial",
"Letter Gothic",
"Times New Roman",
"Letter Gothic Tall",
"Letter Gothic Tall",
"Gothic Ultra",
"VolianScript"
};
private float LeftMargin; //todo: define in page info
private float VerticalOffset; //todo: define in page info
private bool Portrait; //todo: define in page info
public XmlToPdf(string path, string fname)
{
LeftMargin=0.5f * ConvertToPoints; // KBR: TODO
VerticalOffset=0.5f * ConvertToPoints; // KBR: TODO
Portrait = true; // KBR: TODO
FileName = fname;
FilePath = path;
xmlDoc = new XmlDocument();
XmlTextReader reader = new XmlTextReader(FilePath+"\\"+FileName);
xmlDoc.Load(reader);
reader.Close();
try
{
GeneratePDFForFile();
}
catch (Exception e)
{
MessageBox.Show("Error processing: " + fname, e.Message);
}
}
private void GeneratePDFForFile()
{
_c1pdf = new C1.C1Pdf.C1PdfDocument();
string rootname = FileName.Substring(0,FileName.Length-4);
// create a pdf file & for each macro (i.e. macro element in xml tree),
// put it into the pdf file.
XmlElement top = (XmlElement) xmlDoc.SelectSingleNode(rootname + "_GENMAC");
XmlNodeList xmlNds = top.SelectNodes("MACRO");
foreach (XmlNode nd in xmlNds)
{
XmlNode name = nd.SelectSingleNode("NAME");
XmlElement elm = (XmlElement) name;
XmlNode definition = nd.SelectSingleNode("DEFINITION");
MacroGeneratePDF(definition);
_c1pdf.NewPage();
}
string outname = "E:\\ve-proms.net\\genmac.xml\\testpdf\\" + rootname + ".pdf";
_c1pdf.Save(outname);
}
private void MacroGeneratePDF(XmlNode definition)
{
XmlElement elm = (XmlElement) definition;
string def = elm.InnerText;
int lindx = 0;
int indx = def.IndexOf(";");
while (indx>-1)
{
string command = def.Substring(lindx,indx-lindx).Trim();
DoPDF(command);
lindx = indx+1;
indx = def.IndexOf(";",lindx);
}
}
private void DoPDF(string cmdline)
{
string cmd = cmdline.Substring(0,cmdline.IndexOf(" "));
int stx, sty, ex, ey = 0;
float fstx, fsty, fex, fey = 0;
int lw=0;
string restOfIt=null;
string [] parts;
Pen pn = null;
switch (cmd)
{
case "BOX":
restOfIt = cmdline.Substring(4,cmdline.Length-4);
parts = restOfIt.Split(" ".ToCharArray(),5);
fstx = (float) System.Convert.ToDouble(parts[0]);
fsty = (float) System.Convert.ToDouble(parts[1]);
fex = (float) System.Convert.ToDouble(parts[2]);
fey = (float) System.Convert.ToDouble(parts[3]);
float flw = (float) System.Convert.ToDouble(parts[4]);
pn = new Pen(Brushes.Black,flw);
//KBR: TODO - storing page stuff such as portland, vertical offset, tab, etc.
RectangleF rc = new RectangleF(LeftMargin+fstx,VerticalOffset+fsty,fex,fey);
_c1pdf.DrawRectangle(pn,rc);
break;
case "LINE": // command is LINE startx, starty, endx, endy, lnwidth
restOfIt = cmdline.Substring(5,cmdline.Length-5);
parts = restOfIt.Split(" ".ToCharArray(),5);
fstx = (float) System.Convert.ToDouble(parts[0]);
fsty = (float) System.Convert.ToDouble(parts[1]);
fex = (float) System.Convert.ToDouble(parts[2]);
fey = (float) System.Convert.ToDouble(parts[3]);
float flw1 = (float) System.Convert.ToDouble(parts[4]);
//KBR: TODO - storing page stuff such as portland, vertical offset, tab, etc.
// startx = portland ? (vof + cy + adjy) : (cx + tab + adjx);
// starty = portland ? (tab - (cx + adjx)) : (cy + vof + adjy);
pn = new Pen(Brushes.Black,flw1);
//KBR: TODO - move ablsolute?
// if (MoveAbsolute)
// {tab = 0;vof = 0;}
_c1pdf.DrawLine(pn, LeftMargin+fstx, VerticalOffset+fsty, LeftMargin+fstx+fex, VerticalOffset+fsty+fey);
break;
case "TEXT":
int quote = cmdline.IndexOf("\"");
string txt = cmdline.Substring(quote+1,cmdline.LastIndexOf("\"")-quote-1);
restOfIt = cmdline.Substring(5,quote-6);
parts = restOfIt.Split(" ".ToCharArray(),5);
fstx = (float) System.Convert.ToDouble(parts[0]);
fsty = (float) System.Convert.ToDouble(parts[1]);
int FontSize = System.Convert.ToInt32(parts[2]);
FontSize = FontSize/2;
int FontFamily = System.Convert.ToInt32(parts[3]);
int bui = System.Convert.ToInt32(parts[4]); //kbr todo: use bui
Font myfont = new Font(this.FontChoice[FontFamily],FontSize);
rc = new Rectangle();
rc.Size = _c1pdf.MeasureStringRtf(txt,myfont,500); // kbr todo: 500?
rc.X = LeftMargin+fstx;
rc.Y = VerticalOffset+fsty-FontSize; //-(rc.Size.Height/2);
_c1pdf.DrawStringRtf(txt,myfont,Brushes.Black,rc);
break;
case "GDIADJ":
break;
case "ELLIPSE":
restOfIt = cmdline.Substring(8,cmdline.Length-8);
parts = restOfIt.Split(" ".ToCharArray(),5);
stx = System.Convert.ToInt32(parts[0]);
sty = System.Convert.ToInt32(parts[1]);
ex = System.Convert.ToInt32(parts[2]);
ey = System.Convert.ToInt32(parts[3]);
lw = System.Convert.ToInt32(parts[4]);
_c1pdf.DrawEllipse(pn,LeftMargin+stx, VerticalOffset+sty, LeftMargin+ex, VerticalOffset+ey);
break;
case "BITMAP":
restOfIt = cmdline.Substring(8,cmdline.Length-7);
parts = restOfIt.Split(" ".ToCharArray(),3);
fstx = (float) System.Convert.ToDouble(parts[0]);
fsty = (float) System.Convert.ToDouble(parts[1]);
string fname = parts[2];
Image img = Image.FromFile(fname);
rc = new RectangleF();
rc.Height = img.Height;
rc.Width = img.Width;
rc.X = LeftMargin+fstx;
rc.Y = VerticalOffset+fsty-(rc.Size.Height/2);
_c1pdf.DrawImage(img, rc, ContentAlignment.MiddleCenter, ImageSizeModeEnum.Scale);
break;
case "ABSOLUTE":
break;
default:
break;
}
}
}
}