Control to create RO Usage, RO Summary, RO Complete, and Transition Usage reports Logic to print RO Usage reports Ifdef’d logic for UseOnFirstPage logic for Width Override and Ifdef’d logic for UseOnFirstPage Beginings of code to generate a Complete RO Report
1276 lines
36 KiB
C#
1276 lines
36 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
using System.IO;
|
|
using iTextSharp.text.pdf;
|
|
using iTextSharp.text;
|
|
/***
|
|
* Complete RO Report TO DO:
|
|
* - We are reading in the formation from the PRINT.TMP file.
|
|
* - Need to organize and put information on the page (continue message, page breaks, margings, etc.)
|
|
* - Need to process X/Y Plot language
|
|
* - Need to process tables (or leave table text as is)
|
|
* - Need to process graphic files
|
|
***/
|
|
|
|
namespace Volian.Print.Library
|
|
{
|
|
class CompleteROReport
|
|
{
|
|
Headers Hdrs; // Header stack object.
|
|
RODataFile RO_df = null;
|
|
int curheaderlen;
|
|
string RODataFileName;
|
|
iTextSharp.text.Document pdfReportDoc;
|
|
public CompleteROReport(iTextSharp.text.Document document, string dataFileName)
|
|
{
|
|
Hdrs = new Headers();
|
|
RODataFileName = dataFileName;
|
|
pdfReportDoc = document;
|
|
}
|
|
|
|
public void Run()
|
|
{
|
|
RO_df = new RODataFile(RODataFileName);
|
|
Console.WriteLine("Complete RO Report");
|
|
PrintReport();
|
|
}
|
|
|
|
public void PrintReport()
|
|
{
|
|
bool StopPrinting = false;
|
|
bool UserTerminate = false;
|
|
Int16 iRecType = 0;
|
|
// Loop until either printing is aborted or end of file.
|
|
while (!StopPrinting && (iRecType = RO_df.ReadInteger16()) != -1)
|
|
{
|
|
Console.WriteLine("Record Type: {0}", iRecType);
|
|
switch (iRecType)
|
|
{
|
|
case 1: // Set Header
|
|
SetHeader();
|
|
break;
|
|
case 2: // Push Header
|
|
PushHeader();
|
|
break;
|
|
case 3: // Pop Header
|
|
PopHeader();
|
|
break;
|
|
case 4: // RRO Begin
|
|
RROBegin();
|
|
break;
|
|
case 5: // RRO End
|
|
RROEnd();
|
|
break;
|
|
case 6: // Msg
|
|
Msg();
|
|
break;
|
|
case 7:
|
|
KeyField();
|
|
break;
|
|
case 100: // Text Field
|
|
case 101: // Plot Field
|
|
Text();
|
|
break;
|
|
case 102: // Image Field
|
|
ImageFile();
|
|
break;
|
|
case 103: // Multi Begin - Display data for setpoints
|
|
Multiple();
|
|
break;
|
|
case 104: // Multi End
|
|
break;
|
|
case 0: // Do Nothing
|
|
case 255:
|
|
Console.WriteLine("Record Type: {0} No Operation", iRecType);
|
|
Console.WriteLine("----------------------------------------------");
|
|
break;
|
|
default: // Problem
|
|
Console.WriteLine("Record Type: {0} Unrecognized record type", iRecType);
|
|
StopPrinting = true; ;
|
|
UserTerminate = true;
|
|
break;
|
|
};
|
|
// if a key is pressed and the character is ESC, set stop printing
|
|
// flag.
|
|
//StopPrinting = CheckKeyboard(0);
|
|
}
|
|
Console.WriteLine("Record Type: {0}\n** Done **", iRecType);
|
|
return;
|
|
}
|
|
|
|
public void Multiple()
|
|
{
|
|
Int16 typ, i, j, nw = 0;
|
|
string str, sep;
|
|
string buff = "";
|
|
int[] width;
|
|
LastHeader();
|
|
sep = "";
|
|
// nw - number of fields
|
|
nw = RO_df.ReadInteger16();
|
|
// allocate space for widths
|
|
width = new int[nw];
|
|
// loop through and load field widths and names
|
|
for (i = 0; i < nw; i++)
|
|
{
|
|
// load width
|
|
width[i] = RO_df.ReadInteger16();
|
|
// load name
|
|
str = RO_df.ReadText();
|
|
// how wide is the header
|
|
int wtxt = str.Length;
|
|
buff += sep;
|
|
buff += str;
|
|
// if the width is wider than the header output spaces to pad
|
|
// to specified width
|
|
if (width[i] > wtxt)
|
|
{
|
|
int extra = width[i] - wtxt;
|
|
while (extra > 0)
|
|
{
|
|
buff += " ";
|
|
extra--;
|
|
}
|
|
// otherwise set the width to the width of the header
|
|
}
|
|
else
|
|
{
|
|
width[i] = wtxt;
|
|
}
|
|
// place a vertical bar between fields
|
|
sep = "|";
|
|
}
|
|
sep = "\n";
|
|
buff += "\n";
|
|
// place horizonal bars between the header and the values
|
|
for (i = 0; i < nw; i++)
|
|
{
|
|
for (j = 0; j < width[i]; j++)
|
|
{
|
|
buff += "-";
|
|
}
|
|
if (i < nw - 1)
|
|
buff += "|";
|
|
}
|
|
i = 0;
|
|
// While not the end of multi
|
|
while ((typ = RO_df.ReadInteger16()) != 104)
|
|
{
|
|
if (typ == 0)
|
|
{// Next row
|
|
sep = "\n"; // set the separator (between rows) to a newline
|
|
i = 0;
|
|
}
|
|
else
|
|
{// more for this row
|
|
// get the data
|
|
str = RO_df.ReadText();
|
|
// if first time output a newline otherwise output a vertical
|
|
// bar between values
|
|
buff += sep;
|
|
// output value
|
|
if (str != null)
|
|
buff += str;
|
|
// set the separator to a vertical bar
|
|
sep = "|";
|
|
if (width[i] > 0)
|
|
{
|
|
int jj;
|
|
jj = width[i] - str.Length;
|
|
// pad the value to the specified width
|
|
while (jj > 0)
|
|
{
|
|
buff += " ";
|
|
jj--;
|
|
}
|
|
}
|
|
i++;
|
|
|
|
}
|
|
}
|
|
// delete array of widths
|
|
//delete [] width;
|
|
// set the margin to zero
|
|
//margin = 0;
|
|
// output the table
|
|
PutText(buff);
|
|
// reset the margin to it's default value
|
|
//margin = 5;
|
|
Console.WriteLine("Multiple: {0} ", buff);
|
|
Console.WriteLine("----------------------------------------------");
|
|
}
|
|
|
|
public void SetHeader()
|
|
{
|
|
string pTmp;
|
|
|
|
Console.WriteLine("Set Header");
|
|
|
|
// Get the number of header records
|
|
Int16 iNewCnt = RO_df.ReadInteger16();
|
|
|
|
Console.WriteLine("Num Header Records: {0}", iNewCnt);
|
|
|
|
// Loop through the headers
|
|
int iLoop = 0;
|
|
for (; iLoop < Hdrs.HdrCnt; iLoop++)
|
|
{
|
|
if (iLoop >= iNewCnt)
|
|
// If the current header index is above the new number
|
|
// of headers, delete it.
|
|
Hdrs.strHdrs[iLoop] = null;
|
|
else
|
|
{
|
|
// Otherwise:
|
|
Int16 iTmpRpt;
|
|
|
|
// Get the repeat count for the header
|
|
iTmpRpt = RO_df.ReadInteger16();
|
|
Console.WriteLine("repeat count for header: {0}", iTmpRpt);
|
|
|
|
// Get the text of the header
|
|
pTmp = RO_df.ReadText();
|
|
Console.WriteLine("Header Text: {0}", pTmp);
|
|
if (!pTmp.Equals(Hdrs.strHdrs[iLoop]))
|
|
{
|
|
// if the old header does not equal the new header
|
|
// delete the old header and create a the one
|
|
Hdrs.strHdrs[iLoop] = pTmp;
|
|
Hdrs.repeatCount[iLoop] = iTmpRpt;
|
|
}
|
|
else
|
|
{
|
|
// Otherwise, delete the temperary header data.
|
|
pTmp = null;
|
|
}
|
|
}
|
|
}
|
|
// If there are any other headers left in the file,
|
|
// load those in as well.
|
|
for (; iLoop < iNewCnt; iLoop++)
|
|
{
|
|
int hdrRptCnt = (int)RO_df.ReadInteger16();
|
|
if (Hdrs.repeatCount.Count - 1 < iLoop)
|
|
Hdrs.repeatCount.Add((int)hdrRptCnt);
|
|
else
|
|
Hdrs.repeatCount[iLoop] =hdrRptCnt;
|
|
pTmp = RO_df.ReadText();
|
|
if (Hdrs.strHdrs.Count-1 < iLoop)
|
|
Hdrs.strHdrs.Add(pTmp);
|
|
else
|
|
Hdrs.strHdrs[iLoop] = pTmp;
|
|
Console.WriteLine("Value: {0}", Hdrs.repeatCount[iLoop]);
|
|
Console.WriteLine("Value Text: {0}", Hdrs.strHdrs[iLoop]);
|
|
Console.WriteLine("----------------------------------------------");
|
|
}
|
|
// Set the new header count
|
|
Hdrs.HdrCnt = iNewCnt;
|
|
}
|
|
public void PushHeader()
|
|
{
|
|
//if (m_pPrinterOut->Row() > 55)
|
|
//// m_pPrinterOut->newpage();
|
|
//pdfReportDoc.NewPage();
|
|
string pTmp = RO_df.ReadText();
|
|
curheaderlen = pTmp.Length;
|
|
//Hdrs.strHdrs[Hdrs.HdrCnt] = pTmp;
|
|
Hdrs.strHdrs.Add(pTmp);
|
|
//Hdrs.repeatCount[Hdrs.HdrCnt] = 2;
|
|
Hdrs.repeatCount.Add(2);
|
|
Hdrs.HdrCnt++;
|
|
|
|
//m_pPrinterOut->PushedHeader(Hdrs.strHdrs[Hdrs.HdrCnt-1]);
|
|
|
|
Console.WriteLine("Push Header");
|
|
Console.WriteLine("Header Text: {0}", pTmp);
|
|
Console.WriteLine("----------------------------------------------");
|
|
}
|
|
|
|
public void PopHeader()
|
|
{
|
|
if (Hdrs.repeatCount[Hdrs.HdrCnt-1] == 2)
|
|
{
|
|
// if the last header was pushed on header list
|
|
// print eject the page if the page ran out, and
|
|
// print the header with "none".
|
|
//if (m_pPrinterOut->Row() > 55)
|
|
// m_pPrinterOut->NewPage();
|
|
LastHeader();
|
|
//m_pPrinterOut->PutLine(0, "none");
|
|
//m_pPrinterOut->NewLine(1);
|
|
}
|
|
// Remove the header
|
|
Hdrs.HdrCnt--;
|
|
//Hdrs.strHdrs[Hdrs.HdrCnt] = null;
|
|
Hdrs.strHdrs.RemoveAt(Hdrs.HdrCnt);
|
|
Hdrs.repeatCount.RemoveAt(Hdrs.HdrCnt);
|
|
|
|
Console.WriteLine("Pop Header");
|
|
Console.WriteLine("----------------------------------------------");
|
|
}
|
|
|
|
public void RROBegin()
|
|
{
|
|
//m_pPrinterOut->NewPage();
|
|
Console.WriteLine("RRO Begin");
|
|
Console.WriteLine("----------------------------------------------");
|
|
}
|
|
|
|
public void RROEnd()
|
|
{
|
|
//m_pPrinterOut->PageEnd();
|
|
// Remove any headers that are left over
|
|
Console.WriteLine("{0} headers cleaned up.", Hdrs.HdrCnt);
|
|
Console.WriteLine("RRO End");
|
|
Console.WriteLine("----------------------------------------------");
|
|
}
|
|
|
|
public void Msg()
|
|
{
|
|
// Set a message to the printer on its own
|
|
string szStr = RO_df.ReadText();
|
|
//m_pPrinterOut->NewLine(1);
|
|
//m_pPrinterOut->PutChr(szStr);
|
|
//m_pPrinterOut->NewLine(1);
|
|
|
|
Console.WriteLine("Message");
|
|
Console.WriteLine("Message Text: {0}", szStr);
|
|
Console.WriteLine("----------------------------------------------");
|
|
}
|
|
|
|
public void Text()
|
|
{
|
|
// Get the lenght of the text string and read it in
|
|
Int16 iValue = RO_df.ReadInteger16();
|
|
string szStr = RO_df.ReadText(iValue);
|
|
string temp = szStr;
|
|
|
|
if ((iValue + curheaderlen) > 72 || (szStr.IndexOf('\r') != -1))
|
|
{
|
|
// If the lenght of the string plus the field title is greater
|
|
// than 72 characters or has a carriage return character in it
|
|
// then output the text on multiple lines
|
|
//if (m_pPrinterOut->Row() > 55)
|
|
// m_pPrinterOut->newpage();
|
|
LastHeader();
|
|
PutText(temp);
|
|
}
|
|
else
|
|
{
|
|
// Otherwise output the text on a single line
|
|
LastHeader();
|
|
//m_pPrinterOut->SetNumberOfNewLines(0);
|
|
//m_pPrinterOut->putline(0, temp);
|
|
//if (m_pPrinterOut->Row() + 1 > 55)
|
|
// Hdrs.repeatCount[Hdrs.HdrCnt] = 1;
|
|
//else
|
|
// m_pPrinterOut->newline(1);
|
|
}
|
|
Console.WriteLine("Text");
|
|
Console.WriteLine("Value: {0}", iValue);
|
|
Console.WriteLine("Text: {0}", szStr);
|
|
Console.WriteLine("----------------------------------------------");
|
|
}
|
|
|
|
public void KeyField()
|
|
{
|
|
string szStr = RO_df.ReadText();
|
|
Console.WriteLine("Key Field");
|
|
Console.WriteLine("Key Text: {0}", szStr);
|
|
Console.WriteLine("----------------------------------------------");
|
|
}
|
|
|
|
// Read in the image filename, height, and width
|
|
public void ImageFile()
|
|
{
|
|
string fn = RO_df.ReadText();
|
|
Int16 ht = RO_df.ReadInteger16();
|
|
Int16 wd = RO_df.ReadInteger16();
|
|
//m_pPrinterOut->PrintImage(fn, wd, ht);
|
|
|
|
Console.WriteLine("ImageFile");
|
|
Console.WriteLine("Name: {0}", fn);
|
|
Console.WriteLine("Height: {0}", ht);
|
|
Console.WriteLine("Width: {0}", wd);
|
|
Console.WriteLine("----------------------------------------------");
|
|
}
|
|
|
|
// Output the string. If it is a graph, print the graph.
|
|
// ParseForGraph contains the code to print the text.
|
|
public void PutText(string szStr)
|
|
{
|
|
if (szStr == null || szStr.Equals("NONE"))
|
|
{
|
|
//m_pPrinterOut->putchr("NONE");
|
|
//m_pPrinterOut->newline(2);
|
|
return;
|
|
}
|
|
//m_pPrinterOut->SetNumberOfNewLines(0);
|
|
string temp = szStr;
|
|
//m_pPrinterOut->newline(2);
|
|
// Include margin so the Display Data can print with a margin of zero
|
|
//m_pPrinterOut->ParseForGraph(temp, margin);
|
|
}
|
|
|
|
// Output the last header that was push onto the header stack
|
|
// Printer::LastHeader contains the code to do this.
|
|
public void LastHeader()
|
|
{
|
|
//m_pPrinterOut->LastHeader();
|
|
}
|
|
|
|
}// end CompSumROReport
|
|
|
|
|
|
public class Headers
|
|
{
|
|
//public string[] strHdrs;
|
|
public List<string> strHdrs;
|
|
// public int[] repeatCount;
|
|
public int HdrCnt;
|
|
public List<int> repeatCount;
|
|
public Headers()
|
|
{
|
|
HdrCnt = 0;
|
|
strHdrs = new List<string>();
|
|
repeatCount = new List<int>();
|
|
}
|
|
}
|
|
|
|
public class RODataFile
|
|
{
|
|
FileStream fs = null;
|
|
BinaryReader br = null;
|
|
public RODataFile(string fname)
|
|
{
|
|
fs = new FileStream(fname,FileMode.Open);
|
|
br = new BinaryReader(fs);
|
|
}
|
|
// Read an integer value from the data file
|
|
public Int16 ReadInteger16()
|
|
{
|
|
// Int16 i16RetValue;
|
|
// //if (br == null || br.PeekChar() == -1) // no file handle or end of file
|
|
// // return -1;
|
|
// i16RetValue = br.ReadInt16();
|
|
//return i16RetValue;
|
|
return br.ReadInt16();
|
|
}
|
|
// Read a text string from the data file and returns it.
|
|
// The calling program is responsible for free it
|
|
// with the "delete" operator.
|
|
|
|
public string ReadText()
|
|
{
|
|
return ReadText(-1);
|
|
}
|
|
|
|
public string ReadText(Int16 i16CharCount)
|
|
{
|
|
Int16 i16DataSize;
|
|
if (i16CharCount == -1)
|
|
i16DataSize = ReadInteger16();
|
|
else
|
|
i16DataSize = i16CharCount;
|
|
|
|
if (i16DataSize <= 0)
|
|
return null;
|
|
else
|
|
{
|
|
byte[] charbuff = new byte[i16DataSize + 1];
|
|
charbuff = br.ReadBytes(i16DataSize);
|
|
return (Encoding.ASCII.GetString(charbuff, 0, i16DataSize));
|
|
}
|
|
}
|
|
|
|
// Search through the file to find the next record
|
|
public long NextRecord()
|
|
{
|
|
Int16 iType;
|
|
Int16 RECORD_START = 255;
|
|
// While not the next record and not end of file get the next meta item
|
|
while ((iType = ReadInteger16()) != RECORD_START && iType != -1)
|
|
{
|
|
NextItem();
|
|
}
|
|
return fs.Seek(0, SeekOrigin.Current);
|
|
}
|
|
// Get the next meta item and discard the data
|
|
public long NextItem()
|
|
{
|
|
string pTmp;
|
|
Int16 iRecType = ReadInteger16();
|
|
Int16 iNewCnt;
|
|
int iLoop;
|
|
switch (iRecType)
|
|
{
|
|
case 1: // Set Header
|
|
iNewCnt = ReadInteger16();
|
|
for (iLoop = 0; iLoop < iNewCnt; iLoop++)
|
|
{
|
|
ReadInteger16();
|
|
pTmp = ReadText();
|
|
//delete pTmp;
|
|
}
|
|
break;
|
|
case 2: // Push Header
|
|
case 6: // Msg
|
|
case 7: // Key Field
|
|
case 100: // Text Field
|
|
case 101: // Plot Field
|
|
pTmp = ReadText();
|
|
//delete pTmp;
|
|
break;
|
|
case 3: // Pop Header
|
|
case 4: // RRO Begin
|
|
case 5: // RRO End
|
|
case 103: // Multi Begin
|
|
case 104: // Multi End
|
|
case 0: // Do Nothing
|
|
// Do nothing
|
|
break;
|
|
case 102: // Image Field
|
|
pTmp = ReadText();
|
|
//delete pTmp;
|
|
ReadInteger16();
|
|
ReadInteger16();
|
|
break;
|
|
}
|
|
return fs.Seek(0, SeekOrigin.Current);//ftell(GetFilePointer());
|
|
}
|
|
// Get the block of data that is the record
|
|
public byte[] GetRecord(ref int size)
|
|
{
|
|
byte[] data;
|
|
// Get the current position
|
|
long lCurPos = fs.Seek(0, SeekOrigin.Current); //ftell(GetFilePointer());
|
|
|
|
// Go to the end of the record and get the file position
|
|
ReadInteger16();
|
|
NextRecord();
|
|
long lEndRecord = fs.Seek(0, SeekOrigin.Current); //ftell(GetFilePointer());
|
|
|
|
// Get the size of the record
|
|
size = (int)(lEndRecord - lCurPos);
|
|
|
|
// Retrieve the record from the file
|
|
data = new byte[size +1];
|
|
data = br.ReadBytes(size);
|
|
//fseek(GetFilePointer(),lCurPos,SEEK_SET);
|
|
//fread(data,*size,1,GetFilePointer());
|
|
|
|
return data;
|
|
}
|
|
}
|
|
|
|
# region ReportTextOutputer
|
|
public class ReportTextOutputer
|
|
{
|
|
private int NumLinesForGraph, RowForGraph;
|
|
private int CurrentGraphicsMode, ShouldBeGraphicsMode;
|
|
private int xtralines;
|
|
private string LaserGraphicSpcChar = "'" + "\x07"; // degree and bullet
|
|
private iTextSharp.text.Document pdfReportDoc;
|
|
private int _page = 0;
|
|
private int _row = 0;
|
|
|
|
public int Row
|
|
{
|
|
get { return _row; }
|
|
//set { _row = value; }
|
|
}
|
|
private int _nstring = 0;
|
|
private int _pitch = 1;
|
|
private bool _ItalicsFlag = false;
|
|
private bool _PrintTheExponent = true; /* set to false if we do not want exponents printed */
|
|
private bool _boldFlag = false;
|
|
private bool _UnderLineFlag = false;
|
|
private bool _SubscriptFlag = false;
|
|
private bool _SuperScriptFlag = false;
|
|
private bool _CompSubscriptFlag = false;
|
|
private bool _CompSuperscriptFlag = false;
|
|
private int _nnl = 1;
|
|
private Header Hdrd = null;
|
|
|
|
ReportTextOutputer(iTextSharp.text.Document pdfDoc, Header hdr)
|
|
{
|
|
pdfReportDoc = pdfDoc;
|
|
Hdrd = hdr;
|
|
}
|
|
|
|
// Set the number of newlines to print when outputting text
|
|
public void SetNumberOfNewLines(int iNewLines)
|
|
{
|
|
_nnl = iNewLines;
|
|
}
|
|
// Parse for a graph. If no graph then print the text.
|
|
// Margin added for multifield print - Display Data for Setpoints
|
|
public void ParseForGraph(string szStr, int mrgn)
|
|
{
|
|
//string temp = szStr;
|
|
|
|
//// Look for a graph. If one is found pop it onto the graph stack
|
|
// ::ParseForGraph(temp);
|
|
|
|
//// Print any text or graphs
|
|
//NumLinesForGraph = 0;
|
|
//while (*temp)
|
|
// {
|
|
// RowForGraph = row;
|
|
// // Use margin to make function generic
|
|
// temp = putline(mrgn,temp);
|
|
// }
|
|
//newline(1);
|
|
|
|
//// Reposition the cursor after the graph is printed
|
|
//if (NumLinesForGraph > row)
|
|
// newline((NumLinesForGraph-row)+2);
|
|
//if (xtralines > 0) newline(xtralines);
|
|
|
|
}
|
|
// Start a new page
|
|
public void NewPage()
|
|
{
|
|
// newpage();
|
|
pdfReportDoc.NewPage();
|
|
}
|
|
// Start a new line
|
|
public void NewLine(int iNumberOfLines)
|
|
{
|
|
newline(iNumberOfLines);
|
|
}
|
|
// Output a line
|
|
public string PutLine(int iMargin, string szStr)
|
|
{
|
|
return putline(iMargin, szStr);
|
|
}
|
|
// Output a line in bold
|
|
public void Bolder(string szStr)
|
|
{
|
|
//if (!bold[1])
|
|
// {
|
|
// putchr(szStr);
|
|
// return;
|
|
// }
|
|
//putchr(bold[1]);
|
|
//putchr(szStr);
|
|
//putchr(bold[0]);
|
|
}
|
|
// End a page
|
|
public void PageEnd()
|
|
{
|
|
pageend();
|
|
}
|
|
// Output a date
|
|
public void PutDate(string szStr)
|
|
{
|
|
//putnchr((char *)(szStr+4),2);
|
|
//putnchr("/",1);
|
|
//putnchr((char *)(szStr+6),2);
|
|
//putnchr("/",1);
|
|
//putnchr((char *)(szStr+2),2);
|
|
}
|
|
|
|
// Output a character to the printer
|
|
public void PutChr(string szStr)
|
|
{
|
|
putchr(szStr);
|
|
}
|
|
|
|
// Set a pointer to the header stack to be used if headers need to
|
|
// be accessed
|
|
public void SetHeaderInfo(Headers pHdr)
|
|
{
|
|
//m_pHdrs = pHdr;
|
|
//// clear it out too.
|
|
//memset(m_pHdrs,0,sizeof(Headers));
|
|
}
|
|
// Output a line to the printer
|
|
public string putline(int margin, string instr)
|
|
{
|
|
int loceol;
|
|
string str = "";// char[strlen(instr)+1];
|
|
string rtnstr = "";
|
|
str = instr; //strcpy(str,instr);
|
|
// Search for newline and zero terminate it
|
|
//col=margin;
|
|
loceol = str.IndexOf('\n'); //strchr(str,'\n');
|
|
if (loceol > 0) // \n found
|
|
{
|
|
if (str[loceol + 1] == '\r') loceol++;
|
|
if (str[loceol - 1] == '\r')
|
|
{
|
|
str = str.Substring(0, loceol - 1);
|
|
}
|
|
else
|
|
str = str.Substring(0, loceol);
|
|
}
|
|
else
|
|
loceol = str.Length - 1;
|
|
if (str.Length > 67) // see if we need word wrap
|
|
{
|
|
int x = str.Length - 1;
|
|
while ((x > 0) && (str[x] != ' ')) x--;
|
|
if (x > 0)
|
|
str = str.Substring(0, x + 1);
|
|
else
|
|
str = str.Substring(0, 67);
|
|
rtnstr = instr.Substring(str.Length);
|
|
}
|
|
// format and output line
|
|
FixAndPutLine(str, margin);
|
|
|
|
//if (UnderLineFlag) toggle_underline();
|
|
|
|
return (rtnstr);
|
|
}
|
|
|
|
|
|
// Send 'n' characters to the printer via put1c
|
|
public void putnchr(string str, int n)
|
|
{
|
|
//for (int x=0; x < n; x++)
|
|
// put1c(str[x],m_ifile);
|
|
}
|
|
|
|
// Format and output a string
|
|
//private static string aprocname;
|
|
public void FixAndPutLine(string str, int margin)
|
|
{
|
|
//int i,ccol,tcol,JustDoIt;
|
|
|
|
////aprocname = "proc000"; //strcpy(aprocname,"proc000");
|
|
////dbname = aprocname;
|
|
///*JustDoIt does sub/superscript anywhere if "##" or "~~" is used */
|
|
|
|
//MakeSureFlagsAreOff();
|
|
//if(str != null && str != ""){
|
|
// if(nnl){
|
|
// newline(nnl);
|
|
// nnl=0;
|
|
// }
|
|
// // if not going to a new page, put out the margin.
|
|
// if (str[0] != '\f')
|
|
// for(i=0;i<margin;i++)putnchr(" ",1);
|
|
// tcol=8;
|
|
// ccol=0;
|
|
// int x = 0;
|
|
// while(x < str.Length){
|
|
// if(str[x] == '\t')
|
|
// {
|
|
// nstring = 0;
|
|
// while(ccol++<tcol)putnchr(" ",1);
|
|
// }
|
|
// else if (str[x] == '_')
|
|
// toggle_underline();
|
|
// //else if (str[x] == '\23') toggle_bold();
|
|
// else if (str[x] == '\x13') toggle_bold();
|
|
|
|
// else if (!nstring &&(str[x] == '.' && PrintTheExponent)
|
|
// || ((str[x] >= '0') && (str[x] <= '9'))){
|
|
// nstring = 1;
|
|
// check_super(str);
|
|
// }
|
|
// else if (str[x] == '~' || str[x] =='#'){
|
|
// JustDoIt=0;
|
|
// if(str[x]==str[x+1]){ /* Using ## or ~~ will do super */
|
|
// x++;//str++; /* or subscript regardless of */
|
|
// JustDoIt=1; /* preceding character */
|
|
// }
|
|
// if (char.IsLetterOrDigit(str,x-1) || ".)]".IndexOf(str[x-1]) !=-1 || JustDoIt)
|
|
// (str[x]=='~')?toggle_subscript() : toggle_SuperScript();
|
|
// else
|
|
// putnchr(str,1);
|
|
// }
|
|
// else if (str[x] == '<' && str[x+1] == '_') // less than or equal
|
|
// {
|
|
// //LaserGraphics('\345');
|
|
// LaserGraphics('\xE5');
|
|
// x++;
|
|
// }
|
|
// else if (str[x] == '>' && str[x+1] == '_') // greater than or equal
|
|
// {
|
|
// //LaserGraphics('\344');
|
|
// LaserGraphics('\xE4');
|
|
// x++;
|
|
// }
|
|
// else if (str[x] == '+' && str[x+1] == '_') // plus minus
|
|
// {
|
|
// //LaserGraphics('\343');
|
|
// LaserGraphics('\xE3');
|
|
// x++;
|
|
// }
|
|
// else if(str[x] == '|'){
|
|
// if (str[x+1] == '^' || str[x+1] == 'v') // up arrow or down arrow
|
|
// x++;
|
|
// LaserGraphics(*str); // ???
|
|
// ccol++;
|
|
// }
|
|
// else if (str[x] == 0xF2)
|
|
// //LaserGraphics('\344'); /* greater equal */
|
|
// LaserGraphics('\xE4'); /* greater equal */
|
|
// else if (str[x] == 0xE4)
|
|
// //LaserGraphics('\372'); /* sigma */
|
|
// LaserGraphics('\xFA'); /* sigma */
|
|
// else if (str[x] == 0xE5)
|
|
// LaserGraphics(0xFD); /* sigma */
|
|
// else if (str[x] == 0xF6)
|
|
// //LaserGraphics('\241'); /* division symbol */
|
|
// LaserGraphics('\xA1'); /* division symbol */
|
|
// else if (str[x] == 0xFB)
|
|
// //LaserGraphics('\243'); /* sqr root */
|
|
// LaserGraphics('\xA3'); /* sqr root */
|
|
// else if (str[x] == 0xE3)
|
|
// //LaserGraphics('\244'); /* pi */
|
|
// LaserGraphics('\xA4'); /* pi */
|
|
// else if ((str[x] == '^')||(str[x] == 0x7F))
|
|
// LaserGraphics(0x7F);
|
|
// else if (str[x] == 0xF9) /* Note box char - only FPL format */
|
|
// LaserGraphics(0xAD);
|
|
// else if (str[x] == '`') /* bullet */
|
|
// LaserGraphics(0xB8);
|
|
// else if (str[x] == 0xE0) /* up arrow */
|
|
// LaserGraphics(0x18);
|
|
// else if (str[x] == 0xE1) /* down arrow */
|
|
// LaserGraphics(0x19);
|
|
// else if (str[x] == 0xAA) /* approx equal */
|
|
// LaserGraphics(0xEF);
|
|
// else if (str[x] == 0xA6) /* border char */
|
|
// LaserGraphics(0xB5);
|
|
// else if (str[x] == 0xA2) /* Distinguished zero */
|
|
// LaserGraphics(0xED);
|
|
// else if(str[x] == MARKGRAPH){
|
|
// int grln = PopAGraph(0);
|
|
// if (grln+row>59) newpage();
|
|
// PrintGraphString();
|
|
// RowForGraph+=grln+2;
|
|
// //RowForGraph+=PopAGraph()+2;
|
|
// flushbuf();
|
|
// NumLinesForGraph=max(NumLinesForGraph,RowForGraph);
|
|
// put1c(0x20,m_iFile);
|
|
// if( fonts[PICA] ) putchr(fonts[PICA]);
|
|
// }
|
|
// else if (str[x] > 0x7F || LaserGraphicSpcChar.IndexOf(str[x]) != -1)//strchr(LaserGraphicSpcChar,str[x]))
|
|
// LaserGraphics(str[x]);
|
|
// //else if (str[x] == '\033'){ /*ESC */
|
|
// else if (str[x] == '\x1B'){ /*ESC */
|
|
// if((str[x+1]=='4') || (str[x+1]=='5')){
|
|
// T_Italics();
|
|
// x++;
|
|
// }
|
|
// else if (str[x+1]=='0'){ /* 16 lpi */
|
|
// putchr(Lpi[LPI16]);
|
|
// x++;
|
|
// }
|
|
// else if (str[x+1]=='2'){ /* 12 lpi */
|
|
// putchr(Lpi[LPI12]);
|
|
// x++;
|
|
// }
|
|
// else if (str[x+1]=='P'){ /* ESC P=Toggle Elite/Pica */
|
|
// toggle_pitch();
|
|
// x++;
|
|
// }
|
|
// else if (str[x+1]=='F'){
|
|
// putchr(fonts[ELITE]);
|
|
// x++;
|
|
// }
|
|
// else if (str[x+1]=='\\' && str[x+2]=='#'){
|
|
// putchr("#");
|
|
// x++;
|
|
// }
|
|
// else if (str[x+1]=='#' || str[x+1]=='~'){
|
|
// /* Compressed Super/subscripting tokens are the same as
|
|
// ** normal sub/superscripting except preceded by ESC */
|
|
// x++;
|
|
// if (str[x]=='~')
|
|
// Toggle_CompSubscript();
|
|
// else Toggle_CompSuperscript();
|
|
// }
|
|
// else {
|
|
// putnchr(str[x],1);
|
|
// };
|
|
// }
|
|
// else{
|
|
// if(str[x] == ' ')nstring = 0;
|
|
// if(str[x] == '\f')
|
|
// newpage();
|
|
// //else if(str[x] == '\017'){ /* Compress on with CTRL O */
|
|
// else if(str[x] == '\x0F'){ /* Compress on with CTRL O */
|
|
// putchr(CompressMode[1]);
|
|
// pitch=0; /* Compressed mode shuts elite off */
|
|
// }
|
|
// //else if(str[x] == '\022') /* Compress off with CTRL R */
|
|
// else if(str[x] == '\x12') /* Compress off with CTRL R */
|
|
// putchr(CompressMode[0]);
|
|
// else{
|
|
// putnchr(str[x],1);
|
|
// ccol++;
|
|
// }
|
|
// }
|
|
// x++;
|
|
// if(ccol >= tcol)tcol+=8;
|
|
// }
|
|
|
|
// nnl=1;
|
|
// }
|
|
//else
|
|
// nnl++;
|
|
//put1c(-1,m_iFile); /* resets graphics mode if necessary */
|
|
}
|
|
|
|
// Turn off all of the flags for formating
|
|
public void MakeSureFlagsAreOff()
|
|
{
|
|
//if (UnderLineFlag)
|
|
// toggle_underline();
|
|
//if (boldFlag)
|
|
// toggle_bold();
|
|
//if (SubscriptFlag)
|
|
// toggle_subscript();
|
|
//if (SuperScriptFlag)
|
|
// toggle_SuperScript();
|
|
}
|
|
|
|
// Write a character to the printer
|
|
public void put1c(int ch, int fp)
|
|
{
|
|
//if(CurrentGraphicsMode!=ShouldBeGraphicsMode){
|
|
// if((CurrentGraphicsMode=ShouldBeGraphicsMode)!=0)
|
|
// putchr(LaserGraphicsOn);
|
|
// else
|
|
// putchr(LaserGraphicsOff);
|
|
// }
|
|
//if(ch!=-1)
|
|
// {
|
|
// char character = ch;
|
|
// write(fp, &character, 1);
|
|
// }
|
|
}
|
|
|
|
public void doheaders(int i, int flag)
|
|
{
|
|
//int nSpaces;
|
|
//if(m_pHdrs->m_iRepeatCount[i]==2){
|
|
// m_pHdrs->m_iRepeatCount[i]=0;
|
|
//} else {
|
|
// if( flag ) nSpaces = flag;
|
|
// else nSpaces = (i-1)*2;
|
|
// for(int j=0;j<nSpaces;j++) putnchr(" ",1);
|
|
// Bolder(m_pHdrs->m_pHdrs[i]);
|
|
// if(m_pHdrs->m_iRepeatCount[i]==1){
|
|
// if( !flag ) putchr(" (continued)");
|
|
// } else {
|
|
// m_pHdrs->m_iRepeatCount[i]++;
|
|
// }
|
|
// newline(1);
|
|
//}
|
|
}
|
|
// Start a new page
|
|
public void newpage()
|
|
{
|
|
//string szPageNumber = "";
|
|
//// Increment page number
|
|
//page++;
|
|
|
|
//// End the page if not at the top
|
|
//if(row > 0) PageEnd();
|
|
|
|
//// Put out the font command for PICA on every page.
|
|
//if (fonts[PICA] != null) putchr(fonts[PICA]);
|
|
|
|
//// Print 3 lines
|
|
//newline(3);
|
|
//// if( !StupidHP )newline(2);
|
|
//newline(2);
|
|
|
|
//// Print main header with a page number
|
|
//putchr(topheader);
|
|
////sprintf(szPageNumber," %d",page);
|
|
////putchr(szPageNumber);
|
|
|
|
//NewLine(1);
|
|
|
|
//// Print all of the header in the header stack
|
|
//int i;
|
|
//if(m_pHdrs->m_iHdrCnt){
|
|
// NewLine(1);
|
|
// doheaders(0,max(0,(int)(35-strlen(m_pHdrs->m_pHdrs[0])/2)));
|
|
// NewLine(1);
|
|
// for(i=1;i<m_pHdrs->m_iHdrCnt;i++){
|
|
// doheaders(i);
|
|
// }
|
|
// newline(1);
|
|
//}
|
|
}
|
|
// End the page
|
|
public void pageend()
|
|
{
|
|
//// Send Carriage return/new line and form feed
|
|
//putchr("\r\n");
|
|
//putchr("\014"); // form feed
|
|
|
|
// Home the cursor
|
|
//row = 0;
|
|
//col = 0;
|
|
}
|
|
// Start a new line
|
|
public void newline(int n)
|
|
{
|
|
_row += n;
|
|
// col=0;
|
|
if (_row > 59)
|
|
{
|
|
newpage();
|
|
return;
|
|
}
|
|
while (n-- > 0) putnchr("\r\n", 2);
|
|
// This spaces over for a left margin
|
|
putchr(" "); // make a 3/4 inch left margin (at 10 chars per inch)
|
|
}
|
|
|
|
// Toggle Underline
|
|
public void toggle_underline()
|
|
{
|
|
//UnderLineFlag= !UnderLineFlag;
|
|
//putchr(underline[UnderLineFlag]);
|
|
}
|
|
|
|
// Toggle Bold
|
|
public void toggle_bold()
|
|
{
|
|
//boldFlag = !boldFlag;
|
|
//putchr(bold[boldFlag]);
|
|
}
|
|
// Toggle Subscript
|
|
public void toggle_subscript()
|
|
{
|
|
//SubscriptFlag = !SubscriptFlag;
|
|
//if (SuperScriptFlag) SuperScriptFlag = 0;
|
|
//putchr(SubScript[SubscriptFlag]);
|
|
}
|
|
|
|
// Toggle SuperScript
|
|
public void toggle_SuperScript()
|
|
{
|
|
//SuperScriptFlag = !SuperScriptFlag;
|
|
//if (SubscriptFlag) SubscriptFlag = 0;
|
|
//putchr(SuperScript[SuperScriptFlag]);
|
|
}
|
|
|
|
public void Toggle_CompSubscript()
|
|
/* Toggle compressed mode subscript. Also reduce line spacing so that
|
|
** when shrink printer command does its half line movement, it does not
|
|
** cause subscripted text to print over the next line */
|
|
{
|
|
//if (CompSubscriptFlag ^= 1)
|
|
// putchr(Lpi[LPI12]);
|
|
//if (CompSuperscriptFlag) CompSuperscriptFlag = 0;
|
|
//if (SuperScriptFlag) SuperScriptFlag = 0;
|
|
//putchr(shrink[1][CompSubscriptFlag]);
|
|
//if (!CompSubscriptFlag)
|
|
// putchr(Lpi[LPI6]); /* Set to 6 lines per inch - assumes default */
|
|
}
|
|
public void Toggle_CompSuperscript()
|
|
/* Toggle compressed mode superscript. Also reduce line spacing so that
|
|
** when shrink printer command does its half line movement, it does not
|
|
** cause superscripted text to print over the next line */
|
|
{
|
|
//if (CompSuperscriptFlag ^= 1)
|
|
// putchr(Lpi[LPI12]);
|
|
//if (CompSubscriptFlag) CompSubscriptFlag = 0;
|
|
//if (SubscriptFlag) SubscriptFlag = 0;
|
|
//putchr(shrink[0][CompSuperscriptFlag]);
|
|
//if (!CompSuperscriptFlag)
|
|
// putchr(Lpi[LPI6]); /* Set to 6 lines per inch - assumes default */
|
|
//}
|
|
|
|
}
|
|
public void check_super(string lstr) //char **lstr)
|
|
{
|
|
//if(!FortranFormatNumbers && IsAnENumber(*lstr) && PrintTheExponent)
|
|
//{
|
|
// if(IsPowerOf10(*lstr)){
|
|
// putnchr("10",2);
|
|
// while(**lstr!='E')(*lstr)++;
|
|
// }
|
|
// else{
|
|
// while(**lstr != 'E'){
|
|
// putnchr(*lstr,1);
|
|
// (*lstr)++;
|
|
// }
|
|
// putnchr("x10",3);
|
|
// }
|
|
// (*lstr)++;
|
|
// toggle_SuperScript();
|
|
// while(isdigit(**lstr) || **lstr=='+' || **lstr=='-' || **lstr=='.'){
|
|
// putnchr(*lstr,1);
|
|
// (*lstr)++;
|
|
// }
|
|
// toggle_SuperScript();
|
|
// (*lstr)--;
|
|
// }
|
|
//else
|
|
//putnchr(*lstr,1);
|
|
}
|
|
public int IsAnENumber(string str)
|
|
{
|
|
//while(isdigit(*str))str++;
|
|
//if(*str++ != '.')return(0);
|
|
//while(isdigit(*str))str++;
|
|
//if(*str++ != 'E')return(0);
|
|
//if(*str=='+' || *str=='-')str++;
|
|
//while(isdigit(*str))str++;
|
|
//if(*str == '.')str++;
|
|
//while(isdigit(*str))str++;
|
|
//if(!isalpha(*str))return(1);
|
|
return (0);
|
|
}
|
|
|
|
public int IsPowerOf10(string str)
|
|
{
|
|
//if(*str++!='1')return(0);
|
|
//if(*str++!='.')return(0);
|
|
//while(*str=='0')str++;
|
|
//if(*str!='E')return(0);
|
|
return (1);
|
|
}
|
|
public void toggle_pitch()
|
|
{
|
|
//pitch= !pitch;
|
|
//putchr(PrnPitch[pitch]);
|
|
}
|
|
public void LaserGraphics(char GraphicsChar)
|
|
{
|
|
/** Bug fix B2004-002 - let VFW handle the underlining
|
|
** of special characters
|
|
int localtoggle;
|
|
if ((localtoggle = UnderLineFlag) != 0) toggle_underline();
|
|
**/
|
|
//ShouldBeGraphicsMode=1;
|
|
//put1c(GraphicsChar, m_iFile);
|
|
//ShouldBeGraphicsMode=0;
|
|
/** Bug fix B2004-002
|
|
if (localtoggle){
|
|
putnchr("\008",1); * backspace *
|
|
toggle_underline(); * resume underlining *
|
|
putnchr(" ",1); * send space *
|
|
}
|
|
**/
|
|
}
|
|
public void putchr(string str)
|
|
{
|
|
//putnchr(str,strlen(str));
|
|
}
|
|
|
|
public void T_Italics()
|
|
{
|
|
//putchr(SetItalics[(ItalicsFlag^=1)]);
|
|
}
|
|
public void PrintImage(string fn, int x, int ht)
|
|
{
|
|
// char pth[MAXPATH];
|
|
// if (row + ht > 59) newpage();
|
|
// LastHeader();
|
|
|
|
// char *cmdstr, *buf;
|
|
// cmdstr = (char *) mallocq(81);
|
|
|
|
// char bits[4];
|
|
// // See if we are using the new (32-bit) RO Editor
|
|
// memset(bits,'\0',4);
|
|
// (void) GetPrivateProfileString("RoEditor","Bit","32",
|
|
// bits,sizeof(bits),ExeAdjust("~veproms.ini"));
|
|
// /*
|
|
// * Since we might be printing out of the APPROVED directory,
|
|
// * let the default graphic file extension be PCX. If the
|
|
// * graphic file cannot be found, then see if there is a TIF
|
|
// * version of the graphic file (converted for the 32-bit RO
|
|
// * Editor). Note that when we convert RO graphic files from
|
|
// * PCX to TIF, we only do the ones in the RO directory, not any
|
|
// * of the "approved" graphic files in the APPROVED directory.
|
|
// * So until VFW is running totally under .NET, we need check
|
|
// * for both PCX and TIF graphic files when printing.
|
|
// */
|
|
|
|
// int k=1;
|
|
// buf = (char *) mallocq(5);
|
|
// if (strcmp(bits,"32")== 0)
|
|
// {
|
|
// (void)GetPrivateProfileString("Graphics", "defaultext", "TIF", buf, 4,
|
|
// ExeAdjust("~veproms.ini"));
|
|
// }
|
|
// else
|
|
// {
|
|
// (void)GetPrivateProfileString("Graphics", "defaultext", "PCX", buf, 4,
|
|
// ExeAdjust("~veproms.ini"));
|
|
// }
|
|
// if (strchr(fn, '.') == NULL) {
|
|
// sprintf(pth,"%s%s.%s",GetGraphicsPath(),fn,buf);
|
|
// } else {
|
|
// sprintf(pth,"%s%s",GetGraphicsPath(),fn);
|
|
// }
|
|
// if(Exists(pth)){
|
|
// sprintf(cmdstr,"\255I\"%s:.\\%d:%d\"",pth,k,ht*DeciPerRow);
|
|
// } else {
|
|
// /*
|
|
// * The graphic file was not found but we might be printing out
|
|
// * of the APPROVED directory. Set the graphic file extension
|
|
// * be PCX.
|
|
// * Note that when we convert RO graphic files from
|
|
// * PCX to TIF, we only do the ones in the RO directory, not any
|
|
// * of the "approved" graphic files in the APPROVED directory.
|
|
// * So until VFW is running totally under .NET, we need check
|
|
// * for both PCX and TIF graphic files when printing.
|
|
// */
|
|
// if (InApproved() && (strcmp(bits,"32")== 0))
|
|
// {
|
|
// // we are the Approved directory.
|
|
// // Graphics file does not exist, try the graphic file
|
|
// // name with a PCX extension
|
|
// char *tptr = strrchr(pth,'.');
|
|
// if (tptr != NULL)
|
|
// strcpy(tptr,".PCX"); // see if a TIF version exists
|
|
// }
|
|
// if (Exists(pth)) {
|
|
// sprintf(cmdstr,"\255I\"%s:%s%d:%d\"",pth,k,ht*DeciPerRow);
|
|
// }
|
|
// else// Output message if file does not exist
|
|
// sprintf(cmdstr,"%s does not exist.",pth);
|
|
// }
|
|
// putchr(cmdstr);
|
|
// free(buf);
|
|
// free(cmdstr);
|
|
// row += ht;
|
|
//#ifdef OUTPUT_DEBUG_INFO
|
|
// cout << cmdline << endl;
|
|
//#endif
|
|
}
|
|
|
|
// Print the last header in the header stack
|
|
public void LastHeader()
|
|
{
|
|
//string buf;
|
|
//if (m_pHdrs->m_iHdrCnt > 0)
|
|
// {
|
|
// // Advance a line on the printer
|
|
// NewLine(1);
|
|
|
|
// // Copy colon to the header string and print it in bold
|
|
// strcpy(buf, m_pHdrs->m_pHdrs[m_pHdrs->m_iHdrCnt-1]);
|
|
// strcat(buf, ": ");
|
|
// Bolder(buf);
|
|
|
|
// // Set repeat count to 1 for the header
|
|
// m_pHdrs->m_iRepeatCount[m_pHdrs->m_iHdrCnt-1] =1;
|
|
// }
|
|
}
|
|
public void PushedHeader(string szStr)
|
|
{
|
|
//UserTerminate = CheckKeyboard(szStr);
|
|
}
|
|
}
|
|
#endregion
|
|
}
|
|
|