RTF writing classes???
Richard Brice -- bricer@wsdot.wa.gov
Wednesday, December 11, 1996
Environment: VC++ 4.2-flat, Win 95, NT 4.0
Does anybody have a set of classes or functions or anything that would
allow someone to create an RTF file from within a program?
What I'm trying to accomplish is this. After my MFC program does a bunch
of crunching, it creates a report. The program opens a temporary file and
streams plain text into it and then displays the contents of the file in
an edit view. I would like to make this a bit nicer by using RTF and the
CRichEditCtrl.
I would like to do something like this:
file << BuildFontTable(???);
file << BoldOn() << "This is bold text" << BoldOff();
file << ...
Where the stream maniuplators put the necessary RTF commands in the file.
P.J. Tezza -- pj@exemplarsoftware.com
Monday, December 16, 1996
[Mini-digest: 2 responses]
>Does anybody have a set of classes or functions or anything that would =
=20
>allow someone to create an RTF file from within a program?
Environment: VC++ 4.2-flat, Win 95, NT 4.0
Download and install a trial copy of Exemplar Setup Toolkit from =
http://www.exemplarsoftware.com/setuptrialprogram.htm. Follow the =
instructions in "Setup Application Jump Start" to create a setup =
application. In the file LicenseAgreement.cpp, which will be created by =
the Setup AppWizard, you will find code which subclasses a CRichEditCtrl =
and feeds it RTF formatted text stored as resources. This is not all of =
what you asked for, but it is a head start.
PJ
pj@exemplarsoftware.com
-----From: Dave Kolb
Why not just write your own class based on CRichEditCtrl, put text into
the object and then serialize it to a file using the StreamOut method?
Dave Kolb
PC Research and Development
SAS Institute Inc.
919-677-8000 x6827
>----------
>From: Richard Brice[SMTP:bricer@wsdot.wa.gov]
>Sent: Wednesday, December 11, 1996 2:38 PM
>To: mfc-l
>Subject: RTF writing classes???
>
>
>Environment: VC++ 4.2-flat, Win 95, NT 4.0
>
>Does anybody have a set of classes or functions or anything that would
>allow someone to create an RTF file from within a program?
>
>What I'm trying to accomplish is this. After my MFC program does a bunch
>of crunching, it creates a report. The program opens a temporary file and
>streams plain text into it and then displays the contents of the file in
>an edit view. I would like to make this a bit nicer by using RTF and the
>CRichEditCtrl.
>
>I would like to do something like this:
>
>file << BuildFontTable(???);
>file << BoldOn() << "This is bold text" << BoldOff();
>file << ...
>
>Where the stream maniuplators put the necessary RTF commands in the file.
>
Timothy Purves -- tpurves@ix.netcom.com
Wednesday, December 18, 1996
This would be in direct violations of the license agreement....
5. GENERATED CODE. For this trial edition of the SOFTWARE, code generated
using Exemplar Setup AppWizard may not, in source code or object code form,
be redistributed in any manner. The trial edition of the SOFTWARE is to be
used for testing and evaluation purposes only.
6. REDISTRIBUTABLE CODE. This trial edition of the SOFTWARE contains no
redistributable code. No part of the SOFTWARE, in source code or object
code form may be redistributed.
[Moderator's note: Interesting point. I'll keep this in mind in
the future when PJ sends in answers.]
-tim
At 12:34 AM 12/16/96 -0500, P.J. Tezza wrote:
>[Mini-digest: 2 responses]
>
>>Does anybody have a set of classes or functions or anything that would =
>=20
>>allow someone to create an RTF file from within a program?
>
>Environment: VC++ 4.2-flat, Win 95, NT 4.0
>
>Download and install a trial copy of Exemplar Setup Toolkit from =
>http://www.exemplarsoftware.com/setuptrialprogram.htm. Follow the =
>instructions in "Setup Application Jump Start" to create a setup =
>application. In the file LicenseAgreement.cpp, which will be created by =
>the Setup AppWizard, you will find code which subclasses a CRichEditCtrl =
>and feeds it RTF formatted text stored as resources. This is not all of =
>what you asked for, but it is a head start.
>
>PJ
>pj@exemplarsoftware.com
>-----From: Dave Kolb
>
>
>Why not just write your own class based on CRichEditCtrl, put text into
>the object and then serialize it to a file using the StreamOut method?
>
>Dave Kolb
>PC Research and Development
>SAS Institute Inc.
>919-677-8000 x6827
>
>
>>----------
>>From: Richard Brice[SMTP:bricer@wsdot.wa.gov]
>>Sent: Wednesday, December 11, 1996 2:38 PM
>>To: mfc-l
>>Subject: RTF writing classes???
>>
>>
>>Environment: VC++ 4.2-flat, Win 95, NT 4.0
>>
>>Does anybody have a set of classes or functions or anything that would
>>allow someone to create an RTF file from within a program?
>>
>>What I'm trying to accomplish is this. After my MFC program does a bunch
>>of crunching, it creates a report. The program opens a temporary file and
>>streams plain text into it and then displays the contents of the file in
>>an edit view. I would like to make this a bit nicer by using RTF and the
>>CRichEditCtrl.
>>
>>I would like to do something like this:
>>
>>file << BuildFontTable(???);
>>file << BoldOn() << "This is bold text" << BoldOff();
>>file << ...
>>
>>Where the stream maniuplators put the necessary RTF commands in the file.
>>
>
>
--------------
Timothy Purves
Manager of Application Technology Specialists
Henry Ford Health System
Rochester Hills, MI USA
Noel Burton-Krahn -- noel@harleystreet.com
Friday, December 20, 1996
I had the same problem, and purchased the TE Developer's Kit from:
Sub Systems, Inc.
11 Tiger Row
Georgetown, MA
01833
(508) 352-9020
Their RTF editor is available for 32 or 16 bit Windows with code examples
for MFC, Delphi, VB, etc. Best of all, they give you the source code when
you purchase!
--Noel
John Toebes -- Toebes@southpeak.com
Saturday, December 21, 1996
[Moderator's note: Wow!]
>Environment: VC++ 4.2-flat, Win 95, NT 4.0
I have a simple class that I created to send fancy mail through
Exchange. It doesn't do everything in RTF, but has been enough for us
to do quite a bit of mail formatting including colors, fonts, underline,
bold, italics, tabs, and indentations. It automatically keeps track of
the fonts and colors that you use (up to a fixed number) and outputs the
correct header for the file. I have also put in code there to handle
MAPI style attachments, but you probably don't want to use that.
An example of use would be:
CRTFString r;
r.Clear();
r.SelectArial();
r.SelectBold();
r.AddString("This is in bold\n");
r.SelectPlain();
r.AddString("This is plain\n");
printf("The output RTF is :%s\n", r.GetData());
//
// RtfSup.h -- General functions for creating an RTF string
//
#define MAX_RTFFONTS 15
#define MAX_RTFCOLORS 32
class CRTFString
{
private:
int m_nLevel;
int m_nColumn;
int m_nCurrentFont;
int m_nCurrentColor;
int m_nMaxFont;
int m_nMaxColor;
BOOL m_bIsBold;
BOOL m_bIsItalic;
BOOL m_bIsUnderline;
CString m_strBody;
CString m_astrFonts[MAX_RTFFONTS];
CString m_astrColors[MAX_RTFCOLORS];
CString m_strFileNames;
public:
CRTFString()
{
Clear();
}
CString GetData()
{
CString strResult;
strResult = "{\\rtf1\\ansi\\deff0\\deftab720\n{\\fonttbl";
for(int nFont = 0; nFont < m_nMaxFont; nFont++)
{
CString strTemp;
strTemp.Format("{\\f%d\\f%s;}", nFont, m_astrFonts[nFont]);
strResult += strTemp;
}
strResult += "}\n";
if (m_nMaxColor)
{
strResult += "{\\colortbl";
for (int nColor = 0; nColor < m_nMaxColor; nColor++)
{
strResult += m_astrColors[nColor];
}
strResult += "}\n";
}
strResult += "\\deflang1033\\pard";
//
// Let's go through and replace all the \t sequences with a
\tab. Note that if the next character
// after the tab is a \, we don't need to put in a space
//
int nPos;
while((nPos = m_strBody.Find('\t')) >= 0)
{
CString strTemp = m_strBody.Mid(nPos+1);
m_strBody = m_strBody.Left(nPos);
m_strBody += "\\tab";
if ((strTemp.GetLength() > 0) && (strTemp[0] != '\\'))
{
m_strBody += " ";
}
m_strBody += strTemp;
}
strResult += m_strBody;
for (int nNest = 0; nNest < m_nLevel; nNest++)
{
strResult += "}";
}
strResult += "};";
return strResult;
}
CString GetFileNames()
{
return m_strFileNames;
}
void AddFile(CString strFileName, CString strDisplay=NULL, BOOL
bLinkOnly=TRUE)
{
CString strResult;
strResult.Format("%s;%s;%d;", strFileName, strDisplay,
bLinkOnly);
m_strFileNames += strResult;
m_strBody += "\\objattph ";
}
void Clear()
{
m_strBody = "";
m_strFileNames = "";
m_nLevel = 0;
m_nColumn = 0;
m_nMaxColor = 0;
m_nMaxFont = 0;
m_nCurrentFont = 0;
m_nCurrentColor = -1;
m_bIsBold = FALSE;
m_bIsItalic = FALSE;
m_bIsUnderline = FALSE;
SelectMSSansSerif();
}
void Break()
{
m_strBody += "\n\\par ";
m_nColumn = 0;
}
void SetTab(int nTwip)
{
CString strTab;
strTab.Format("\\tx%d", nTwip);
m_strBody += strTab;
}
void Tab()
{
m_strBody += "\\tab";
}
void AddString(CString strText)
{
int nPos;
nPos = strText.Find('\n');
if (nPos >= 0)
{
CString strPiece;
//
// They have a \n in it, so we want to add everything up to
the \n followed by a break and
// then the remainder of the string.
//
AddString(strText.Left(nPos));
Break();
AddString(strText.Mid(nPos+1));
}
else
{
//
// See if we have any \\ characters in the string
//
while((nPos = strText.Find('\\')) >= 0)
{
m_strBody += strText.Left(nPos+1);
m_strBody += "\\";
strText = strText.Mid(nPos+1);
m_nColumn += nPos;
if (m_nColumn > 100)
{
m_nColumn = 0;
m_strBody += "\n";
}
}
m_strBody += strText;
m_nColumn += strText.GetLength();
if (m_nColumn > 100)
{
m_nColumn = 0;
m_strBody += "\n";
}
}
}
void PushLevel()
{
m_strBody += "\n{";
m_nLevel++;
}
void PopLevel()
{
m_strBody += "}\n";
m_nLevel--;
}
void SelectFont(CString strFontClass, CString strFont, int nPitch=0,
int nCharSet=0)
{
CString strFontName;
int nFontIndex;
if (nCharSet)
{
if (nPitch)
{
strFontName.Format("%s\\fcharset%d\\fprq%d %s",
strFontClass, nCharSet, nPitch, strFont);
}
else
{
strFontName.Format("%s\\fcharset%d %s", strFontClass,
nCharSet, strFont);
}
}
else
{
if (nPitch)
{
strFontName.Format("%s\\fprq%d %s", strFontClass,
nPitch, strFont);
}
else
{
strFontName.Format("%s %s", strFontClass, strFont);
}
}
//
// Add the font to the font table if it is not already there
//
for (nFontIndex = 0; nFontIndex < m_nMaxFont; nFontIndex++)
{
if (m_astrFonts[nFontIndex] == strFontName) break;
}
if (nFontIndex == m_nMaxFont)
{
if (nFontIndex < MAX_RTFFONTS)
{
m_astrFonts[m_nMaxFont++] = strFontName;
}
}
if (nFontIndex != m_nCurrentFont)
{
m_nCurrentFont = nFontIndex;
strFontName.Format("\\plain\\f%d\\fs20 ", nFontIndex);
m_strBody += strFontName;
}
}
void SelectTimes() { SelectFont("roman", "Times New Roman", 2,
0); }
void SelectArial() { SelectFont("swiss", "Arial", 2,
0); }
void SelectCourier() { SelectFont("modern", "Courier New", 1,
0); }
void SelectSymbol() { SelectFont("roman", "Symbol", 0,
2); }
void SelectMSSansSerif() { SelectFont("swiss", "MS Sans Serif", 0,
0); }
void SelectColor(int nRed, int nGreen, int nBlue)
{
CString strColorName;
int nColorIndex;
strColorName.Format("\\red%d\\green%d\\blue%d;", nRed, nGreen,
nBlue);
//
// Add the font to the font table if it is not already there
//
for (nColorIndex = 0; nColorIndex < m_nMaxColor; nColorIndex++)
{
if (m_astrColors[nColorIndex] == strColorName) break;
}
if (nColorIndex == m_nMaxColor)
{
if (nColorIndex < MAX_RTFFONTS)
{
m_astrColors[m_nMaxColor++] = strColorName;
}
}
if (nColorIndex != m_nCurrentColor)
{
m_nCurrentColor = nColorIndex;
strColorName.Format("\\cf%d ", nColorIndex);
m_strBody += strColorName;
}
}
void SelectBlack() { SelectColor( 0, 0, 0); }
void SelectWhite() { SelectColor(255,255,255); }
void SelectDarkGrey() { SelectColor(128,128,128); }
void SelectLightGrey() { SelectColor(192,192,192); }
void SelectDarkRed() { SelectColor(128, 0, 0); }
void SelectRed() { SelectColor(255, 0, 0); }
void SelectDarkYellow() { SelectColor(128,128, 0); }
void SelectYellow() { SelectColor(255,255, 0); }
void SelectDarkGreen() { SelectColor( 0,128, 0); }
void SelectGreen() { SelectColor( 0,192, 0); }
void SelectDarkCyan() { SelectColor( 0,128,128); }
void SelectCyan() { SelectColor( 0,255,255); }
void SelectDarkBlue() { SelectColor( 0, 0,128); }
void SelectBlue() { SelectColor( 0, 0,255); }
void SelectDarkMagenta() { SelectColor(128, 0,128); }
void SelectMagenta() { SelectColor(255, 0,255); }
void SelectPlain()
{
if (m_bIsBold || m_bIsItalic || m_bIsUnderline)
{
CString strFixup;
strFixup.Format("\\plain\\f%d\\fs20 ", m_nCurrentFont);
m_strBody += strFixup;
m_bIsBold = FALSE;
m_bIsItalic = FALSE;
m_bIsUnderline = FALSE;
}
}
void SelectBold()
{
if (!m_bIsBold)
{
m_bIsBold = TRUE;
m_strBody += "\\b ";
}
}
void SelectItalic()
{
if (!m_bIsItalic)
{
m_bIsItalic = TRUE;
m_strBody += "\\i ";
}
}
void SelectUnderline()
{
if (!m_bIsUnderline)
{
m_bIsUnderline = TRUE;
m_strBody += "\\ul ";
}
}
};
>---- John A. Toebes, VIII ---- toebes@southpeakcom
> Vice President Research and Development
> SouthPeak Interactive
>----------
>From: P.J. Tezza[SMTP:pj@exemplarsoftware.com]
>Sent: Monday, December 16, 1996 12:34 AM
>To: 'mfc-l@netcom.com'
>Subject: RE: RTF writing classes???
>
>
>[Mini-digest: 2 responses]
>
>Does anybody have a set of classes or functions or anything that would =
>=20
>allow someone to create an RTF file from within a program?
>
>Environment: VC++ 4.2-flat, Win 95, NT 4.0
>
>Download and install a trial copy of Exemplar Setup Toolkit from =
>http://www.exemplarsoftware.com/setuptrialprogram.htm. Follow the =
>instructions in "Setup Application Jump Start" to create a setup =
>application. In the file LicenseAgreement.cpp, which will be created by = the
>Setup AppWizard, you will find code which subclasses a CRichEditCtrl = and
>feeds it RTF formatted text stored as resources. This is not all of = what
>you asked for, but it is a head start.
>
>PJ
>pj@exemplarsoftware.com
>-----From: Dave Kolb
>
>
>Why not just write your own class based on CRichEditCtrl, put text into the
>object and then serialize it to a file using the StreamOut method?
>
>Dave Kolb PC Research and Development SAS Institute Inc. 919-677-8000 x6827
>
>
>----------
>From: Richard Brice[SMTP:bricer@wsdot.wa.gov]
>Sent: Wednesday, December 11, 1996 2:38 PM
>To: mfc-l
>Subject: RTF writing classes???
>
>
>Environment: VC++ 4.2-flat, Win 95, NT 4.0
>
>Does anybody have a set of classes or functions or anything that would
>allow someone to create an RTF file from within a program?
>
>What I'm trying to accomplish is this. After my MFC program does a bunch
>of crunching, it creates a report. The program opens a temporary file and
>streams plain text into it and then displays the contents of the file in
>an edit view. I would like to make this a bit nicer by using RTF and the
>CRichEditCtrl.
>
>I would like to do something like this:
>
>file << BuildFontTable(???);
>file << BoldOn() << "This is bold text" << BoldOff();
>file << ...
>
>Where the stream maniuplators put the necessary RTF commands in the file.
>
>
| Вернуться в корень Архива
|