Only convert Page and Document formats is the related Format file exists.

Skip commented lines in INI file.
Remove inline comments before processing INI file.
Use more explicit comparisons to determine type of command.
Replace spaces with {sp}.
This commit is contained in:
Rich 2011-06-23 21:29:00 +00:00
parent a9d012651a
commit 5a7af006a8
3 changed files with 49 additions and 24 deletions

View File

@ -488,20 +488,22 @@ namespace fmtxml
try try
{ {
// get the default base & plant files to use when figuring out inheritance. // get the default base & plant files to use when figuring out inheritance.
GetPlantBaseDefaultFonts(); if (GetPlantBaseDefaultFonts())
{
// will have entire name, such as aep.x01 - use number to differentiate it. // will have entire name, such as aep.x01 - use number to differentiate it.
int indx = nm.IndexOf('.'); int indx = nm.IndexOf('.');
if (indx > 0) if (indx > 0)
{ {
LoadPageFile(nm); LoadPageFile(nm);
LoadDocFile(nm); LoadDocFile(nm);
} }
else else
{ {
LoadPageFile(nm + ".pag"); LoadPageFile(nm + ".pag");
LoadDocFile(nm + ".doc"); LoadDocFile(nm + ".doc");
} }
}
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -1144,7 +1146,9 @@ namespace fmtxml
int indx = fmtName.IndexOf('.'); int indx = fmtName.IndexOf('.');
if (indx > 0) if (indx > 0)
lfmtName = fmtName.Substring(0, fmtName.Length - 4) + "_" + fmtName.Substring(fmtName.Length - 2, 2); lfmtName = fmtName.Substring(0, fmtName.Length - 4) + "_" + fmtName.Substring(fmtName.Length - 2, 2);
xdoc.Load("fmt_xml\\" + lfmtName + "f.xml"); string fName = "fmt_xml\\" + lfmtName + "f.xml";
if (!File.Exists(fName)) return false;
xdoc.Load(fName);
xfont = xdoc.SelectSingleNode("FormatData/Font"); xfont = xdoc.SelectSingleNode("FormatData/Font");
if (xfont!=null)DefPlantFont = new VE_Font(xfont); if (xfont!=null)DefPlantFont = new VE_Font(xfont);
} }

View File

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Text; using System.Text;
using System.IO; using System.IO;
using System.Xml; using System.Xml;
using System.Text.RegularExpressions;
namespace fmtxml namespace fmtxml
{ {
@ -13,6 +14,16 @@ namespace fmtxml
private int NumTexts = 0; private int NumTexts = 0;
private int NumFields = 0; private int NumFields = 0;
private int CountForLists = 0; private int CountForLists = 0;
private Regex removeComment = new Regex("/[*].*?[*]/");
private Regex removeComment1 = new Regex("/[*].*?$");
private Regex removeComment2 = new Regex("[*]/");
private string RemoveComments(string inStr)
{
string str = removeComment.Replace(inStr, "");
str = removeComment1.Replace(str, "");
str = removeComment2.Replace(str, "");
return str;
}
public void PsiIniToXml(ref FormatData fmtdata, string path) public void PsiIniToXml(ref FormatData fmtdata, string path)
{ {
string sLine; string sLine;
@ -31,17 +42,20 @@ namespace fmtxml
{ {
// read in the count of objects - these may not be in order, fix this: // read in the count of objects - these may not be in order, fix this:
sLine = myReader.ReadLine(); sLine = myReader.ReadLine();
while(sLine.StartsWith(";")) sLine = myReader.ReadLine(); // Skip Comments
int indx = sLine.IndexOf("="); int indx = sLine.IndexOf("=");
string tmp = sLine.Substring(indx + 1, sLine.Length - indx - 1); string tmp = sLine.Substring(indx + 1, sLine.Length - indx - 1);
NumBoxes = Convert.ToInt32(tmp); NumBoxes = Convert.ToInt32(RemoveComments(tmp));
sLine = myReader.ReadLine(); sLine = myReader.ReadLine();
while (sLine.StartsWith(";")) sLine = myReader.ReadLine(); // Skip Comments
indx = sLine.IndexOf("="); indx = sLine.IndexOf("=");
tmp = sLine.Substring(indx + 1, sLine.Length -indx - 1); tmp = sLine.Substring(indx + 1, sLine.Length -indx - 1);
NumTexts = Convert.ToInt32(tmp); NumTexts = Convert.ToInt32(RemoveComments(tmp));
sLine = myReader.ReadLine(); sLine = myReader.ReadLine();
while (sLine.StartsWith(";")) sLine = myReader.ReadLine(); // Skip Comments
indx = sLine.IndexOf("="); indx = sLine.IndexOf("=");
tmp = sLine.Substring(indx + 1, sLine.Length -indx - 1); tmp = sLine.Substring(indx + 1, sLine.Length -indx - 1);
NumFields = Convert.ToInt32(tmp); NumFields = Convert.ToInt32(RemoveComments(tmp));
fmtdata.ProcData.Psi.Boxes = new PsiBox[NumBoxes]; fmtdata.ProcData.Psi.Boxes = new PsiBox[NumBoxes];
fmtdata.ProcData.Psi.Labels = new PsiLabel[NumTexts]; fmtdata.ProcData.Psi.Labels = new PsiLabel[NumTexts];
fmtdata.ProcData.Psi.Fields = new PsiField[NumFields]; fmtdata.ProcData.Psi.Fields = new PsiField[NumFields];
@ -59,7 +73,7 @@ namespace fmtxml
default: default:
if (sLine.IndexOf("=") >= 0) if (sLine.IndexOf("=") >= 0)
{ {
AddParam(ref fmtdata, sLine); AddParam(ref fmtdata, RemoveComments(sLine));
} }
break; break;
} }
@ -72,11 +86,17 @@ namespace fmtxml
} }
myReader.Close(); myReader.Close();
} }
private Regex findBOX = new Regex("^BOX[0-9]+$");
private Regex findSIZE = new Regex("^SIZE$");
private Regex findFONT = new Regex("^FONT$");
private Regex findCAPTION = new Regex("^CAPTION$");
private Regex findBUTTONSONBOTTOM = new Regex("^BUTTONSONBOTTOM$");
private Regex findTEXT = new Regex("^TEXT[0-9]+$");
private void AddParam(ref FormatData fmtdata, string sParam) private void AddParam(ref FormatData fmtdata, string sParam)
{ {
int i = sParam.IndexOf("="); int i = sParam.IndexOf("=");
string attrname = sParam.Substring(0, i); string attrname = sParam.Substring(0, i);
if (attrname.Contains("SIZE")) if (findSIZE.IsMatch(attrname))
{ {
int end = (sParam.IndexOf(";") > -1) ? sParam.IndexOf(";") : sParam.Length; int end = (sParam.IndexOf(";") > -1) ? sParam.IndexOf(";") : sParam.Length;
string sb = sParam.Substring(i + 1, end - i - 1); string sb = sParam.Substring(i + 1, end - i - 1);
@ -85,7 +105,7 @@ namespace fmtxml
fmtdata.ProcData.Psi.y = Convert.ToInt32(split[1].Trim()); fmtdata.ProcData.Psi.y = Convert.ToInt32(split[1].Trim());
return; return;
} }
if (attrname.Contains("FONT")) if (findFONT.IsMatch(attrname))
{ {
int end = (sParam.IndexOf(";") > -1) ? sParam.IndexOf(";") : sParam.Length; int end = (sParam.IndexOf(";") > -1) ? sParam.IndexOf(";") : sParam.Length;
string sb = sParam.Substring(i + 1, end - i - 1); string sb = sParam.Substring(i + 1, end - i - 1);
@ -93,19 +113,19 @@ namespace fmtxml
fmtdata.ProcData.Psi.font = split[0].Trim(); fmtdata.ProcData.Psi.font = split[0].Trim();
return; return;
} }
if (attrname.Contains("CAPTION")) if (findCAPTION.IsMatch(attrname))
{ {
int end = (sParam.IndexOf(";") > -1) ? sParam.IndexOf(";") : sParam.Length; int end = (sParam.IndexOf(";") > -1) ? sParam.IndexOf(";") : sParam.Length;
fmtdata.ProcData.Psi.Caption = sParam.Substring(i + 1, end-i-1).Replace("\"",""); fmtdata.ProcData.Psi.Caption = sParam.Substring(i + 1, end-i-1).Replace("\"","");
return; return;
} }
if (attrname.Contains("BUTTONSONBOTTOM")) if (findBUTTONSONBOTTOM.IsMatch(attrname))
{ {
int end = (sParam.IndexOf(";") > -1) ? sParam.IndexOf(";") : sParam.Length; int end = (sParam.IndexOf(";") > -1) ? sParam.IndexOf(";") : sParam.Length;
fmtdata.ProcData.Psi.ButtonsOnBottom = sParam.Substring(i + 1, end - i - 1); fmtdata.ProcData.Psi.ButtonsOnBottom = sParam.Substring(i + 1, end - i - 1);
return; return;
} }
if (attrname.Contains("BOX")) if (findBOX.IsMatch(attrname)) // attrname.StartsWith("BOX"))
{ {
//<Box style="BLACKFRAME" x="4" y="4" width="192" height="112"/> //<Box style="BLACKFRAME" x="4" y="4" width="192" height="112"/>
int end = (sParam.IndexOf(";") > -1) ? sParam.IndexOf(";") : sParam.Length; int end = (sParam.IndexOf(";") > -1) ? sParam.IndexOf(";") : sParam.Length;
@ -119,7 +139,7 @@ namespace fmtxml
CountForLists++; CountForLists++;
return; return;
} }
if (attrname.Contains("TEXT")) if (findTEXT.IsMatch(attrname))
{ {
//<Label text="Responsible Manager's Title:" Justify="LEFT" x="12" y="11" width="100" height="8" /> //<Label text="Responsible Manager's Title:" Justify="LEFT" x="12" y="11" width="100" height="8" />
int end = (sParam.IndexOf(";") > -1) ? sParam.IndexOf(";") : sParam.Length; int end = (sParam.IndexOf(";") > -1) ? sParam.IndexOf(";") : sParam.Length;

View File

@ -296,6 +296,7 @@ namespace fmtxml
str = str.Replace("<", "&lt;"); str = str.Replace("<", "&lt;");
str = str.Replace(">", "&gt;"); str = str.Replace(">", "&gt;");
str = str.Replace("\x0B", "&#11;"); str = str.Replace("\x0B", "&#11;");
str = str.Replace(" ", "{sp}");
return str; return str;
} }
private static string[] FontChoice = private static string[] FontChoice =