This commit is contained in:
2011-05-19 13:18:48 +00:00
parent 6ca33e7e8f
commit f74ce841a5
4 changed files with 241 additions and 130 deletions

View File

@@ -28,8 +28,8 @@ public struct PageStyle
[Serializable]
public struct PSItem
{
public int Row;
public int Col;
public float Row;
public float Col;
//public E_PageStructMod Justify;
public string Justify;
public VE_Font Style;
@@ -49,11 +49,11 @@ public struct DocStyle
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 float PTopRow; // First 'document text' row on printed page
public float FooterLen; // Number of lines required for footer
public float LeftMargin; // Size of left margin
public float PageLength;
public float PageWidth;
public short numberingsequence; // 0 - no page number
// 1 - included with steps
// 2 - within sections ie. document styles
@@ -65,8 +65,8 @@ public struct DocStyle
// 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 float CTMargin; // Margin for top message
public float 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
@@ -327,7 +327,6 @@ public class VE_Font
}
set { CheckPartial(_FontFamily,value); _FontFamily = value; }
}
private void CheckPartial(string member, string value)
{
if (member != null && value == null)
@@ -365,6 +364,21 @@ public class VE_Font
set { CheckPartial(_FontStyle, value); _FontStyle = value; }
//set{i = ((uint)value) | (i & 0x3F);}
}
private string _CPI;
private bool _CPISet = false;
public string CPI
{
get
{
if (!_CPISet)
{
_CPI = CvtFont.CvtFont.GetCPIs(i).ToString();
}
_CPISet = true;
return _CPI;
}
set { CheckPartial(_CPI, value); _CPI = value; }
}
private string _FontCheckOff = null;
private bool _FontCheckOffSet = false;
public string FontCheckOff
@@ -490,14 +504,14 @@ namespace fmtxml
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)
private float RowToPoints(int i)
{
return (i * 12); // row_in_points = input * 72/6, row = input * 12
}
private float ColToPoints(float f, uint style)
{
return 72 * (f / CvtFont.CvtFont.GetCPIs(style));
}
private string GetAsciiStringUntilNull(BinaryReader br)
{
StringBuilder inpstr = new StringBuilder();
@@ -569,7 +583,6 @@ namespace fmtxml
// read in title.
string fnm = MyPath + @"\" + fname;
Console.WriteLine(fname);
brFmt = new BinaryReader(File.Open(fnm,System.IO.FileMode.Open,System.IO.FileAccess.ReadWrite,FileShare.ReadWrite));
pgstyles.Name = GetAsciiString(brFmt);
@@ -599,7 +612,7 @@ namespace fmtxml
stringoffsets.Add(vnum);
}
}
bool didLineDraw = false;
for (short i=0;i<numpgstyles;i++)
{
PageStyle pg = new PageStyle();
@@ -620,27 +633,61 @@ namespace fmtxml
// 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.Justify = ((E_PageStructMod)brFmt.ReadUInt16()).ToString();
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)
int lcol = brFmt.ReadInt16();
uint tmpjust = brFmt.ReadUInt16();
E_PageStructMod etmpjust = (E_PageStructMod)tmpjust;
pi.Justify = ((E_PageStructMod)tmpjust).ToString();
float adj = 0.5F;
if ((etmpjust & E_PageStructMod.PSTrue) == 0) adj = -0.5F;
if ((etmpjust & E_PageStructMod.PSLeft) == E_PageStructMod.PSLeft) adj = 0;
if ((etmpjust & E_PageStructMod.PSRight) == E_PageStructMod.PSRight) adj *= 2;
uint tmpstyle = brFmt.ReadUInt32();
pi.Style = new VE_Font(tmpstyle);
string tkn = DoReplaceTokens(GetAsciiStringUntilNull(brFmt));
// see if any initial line draw chars are in token (WCN2 and others). If so,
// remove the line draw & its following space. Also adjust the column.
int coladj = 0; // see if any initial draw chars are included and if so remove.
pi.Token = tkn==null||tkn==""?tkn:RemoveInitialLineDraw(tkn, ref coladj);
pi.Col = ColToPoints(lcol + coladj + adj, tmpstyle);
if (pi.Token != null)
{
Fpsitms = new PSItem[cnt];
psitms.CopyTo(Fpsitms,0);
Fpsitms[cnt-1] = pi;
psitms = Fpsitms;
// 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;
}
else
psitms[0] = pi;
isfirst=false;
{
if (!didLineDraw)
{
didLineDraw = true;
pi.Token = "{BOX9}";
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;
@@ -680,6 +727,20 @@ namespace fmtxml
}
}
private string RemoveInitialLineDraw(string tkn, ref int coladj)
{
// if first two characters are line draw and space, remove them and adjust column.
if (tkn[0] == '\xB3' && tkn[1] == ' ')
{
coladj += 2;
tkn = tkn.Substring(2, tkn.Length - 2);
//trim any end line char too.
tkn = tkn.Replace('\xB3',' ');
tkn = tkn.TrimEnd(" ".ToCharArray());
}
return tkn;
}
private string GetAsciiString(BinaryReader brFmt)
{
short len = brFmt.ReadInt16();
@@ -693,7 +754,7 @@ namespace fmtxml
// read in title.
string fnm = MyPath + @"\" + fname;
Console.WriteLine(fname);
if (fname == "CPL.Y01") Console.WriteLine(fname);
brFmt = new BinaryReader(File.Open(fnm,System.IO.FileMode.Open,System.IO.FileAccess.ReadWrite,FileShare.ReadWrite));
dcstyles.Name = GetAsciiString(brFmt);
@@ -757,12 +818,13 @@ namespace fmtxml
dc.Name = GetAsciiString(brFmt);
vnum = brFmt.ReadInt16(); // not sure what this is!
dc.pagestyle = brFmt.ReadInt16();
dc.dstyle = LoadVE_Font();
uint tmpstyle = brFmt.ReadUInt32();
dc.dstyle = new VE_Font(tmpstyle);
dc.PTopRow = RowToPoints(brFmt.ReadInt16());
dc.FooterLen = RowToPoints(brFmt.ReadInt16());
dc.LeftMargin = ColToPoints(brFmt.ReadInt16());
dc.LeftMargin = ColToPoints(brFmt.ReadInt16(), tmpstyle);
dc.PageLength = RowToPoints(brFmt.ReadInt16());
dc.PageWidth = ColToPoints(brFmt.ReadInt16());
dc.PageWidth = ColToPoints(brFmt.ReadInt16(), tmpstyle);
dc.numberingsequence = brFmt.ReadInt16();
dc.oldtonew = brFmt.ReadInt32();
dc.IsStepSection = ConvertToSectType(dc.oldtonew);
@@ -874,6 +936,8 @@ namespace fmtxml
string wkstr = p;
// use regular expressions to do the following...
// first see if entire string is line draw type chars, if so, just don't include it.
if (AllDrawChars(wkstr)) return null;
try
{
// replace newline with {par}
@@ -931,6 +995,7 @@ namespace fmtxml
// replace x15 with {RO} for now.
wkstr = wkstr.Replace("\x15", "{RO}");
}
catch (Exception ex)
{
@@ -940,6 +1005,14 @@ namespace fmtxml
return wkstr;
}
private bool AllDrawChars(string wkstr)
{
foreach (char c in wkstr)
{
if (c < '\xB3' || c > '\xDF') return false;
}
return true;
}
private void CompareFonts(VE_Font parFont, ref VE_Font subFont)
{
if (parFont != null && subFont != null)