讲述如何开发一个控件,很有价值(三)
2008-04-09 04:31:05来源:互联网 阅读 ()
blank.rtf - empty -so I could see the "plain" header line
{\rtf1\ansi\deff0\deftab720{\fonttbl{\f0\fswiss MS Sans Serif;}{\f1\froman\fcharset2 Symbol;}{\f2\froman Times New Roman;}}{\colortbl\red0\green0\blue0;}\deflang1033\pard\plain\f2\fs20 \par }
plaintext.rtf - too see how having any text was handled
{\rtf1\ansi\deff0\deftab720{\fonttbl{\f0\fswiss MS Sans Serif;}{\f1\froman\fcharset2 Symbol;}{\f2\froman Times New Roman;}}{\colortbl\red0\green0\blue0;}\deflang1033\pard\plain\f2\fs20 this is plain text
\par }
difffont.rtf - different font, same size, same text
{\rtf1\ansi\deff0\deftab720{\fonttbl{\f0\fswiss MS Sans Serif;}{\f1\froman\fcharset2 Symbol;}{\f2\froman Times New Roman;}{\f3\fswiss\fprq2 Arial;}}{\colortbl\red0\green0\blue0;}\deflang1033\pard\plain\f3\fs20 plain text different font\plain\f2\fs20
\par }
diffsize.rtf - text set to 18 point in the default font
{\rtf1\ansi\deff0\deftab720{\fonttbl{\f0\fswiss MS Sans Serif;}{\f1\froman\fcharset2 Symbol;}{\f2\froman Times New Roman;}}{\colortbl\red0\green0\blue0;}\deflang1033\pard\plain\f2\fs36 plain text different font\plain\f2\fs20
\par }
diffcolor.rtf - etc. my favourite of course - blue.
{\rtf1\ansi\deff0\deftab720{\fonttbl{\f0\fswiss MS Sans Serif;}{\f1\froman\fcharset2 Symbol;}{\f2\froman Times New Roman;}}{\colortbl\red0\green0\blue0;\red0\green0\blue255;}\deflang1033\pard\plain\f2\fs20\cf1 plain text different font\plain\f2\fs20
\par }
Looking at the resultant codes you see how the RTF stream is formatted. It comprises a:
- INITIAL HEADER (\rtf1\.....)
- FONTTABLE (\f0\fswiss...)
- COLORTABLE (\colortbl)
- MISCELLANEOUS
- DEFAULT FORMAT (\pard....)
- BODY OF THE FILE.
As a result of that I rewrote this code:
WriteToBuffer(''''{\rtf1\ansi\deff0\deftab720{\fonttbl{\f0\fswiss MS
SansSerif;}{\f1\froman\fcharset2 Symbol;}{\f2\fmodern Courier New;}}'''' #13 #10);
WriteToBuffer(''''{\colortbl\red0\green0\blue0;}'''' #13 #10);
WriteToBuffer(''''\deflang1033\pard\plain\f2\fs20 '''');
to become:
WriteToBuffer(''''{\rtf1\ansi\deff0\deftab720'''');
WriteFontTable;
WriteColorTable;
WriteToBuffer(''''\deflang1033\pard\plain\f0\fs20 '''');
The procedures Write[Font,Color]Table basically creates a table of fonts/colors we can reference later on. Each Font and Color type is stored by index in a TList internally. It acts as a lookup tables - by matching the Font name or Color value we can find the [num] to code into the RTF stream at the required moment:
\f[num] = the index of which Font you want to use, as pre-set in the "on the fly" font table
\fs[num] = point size - (for example 20 = 10point)
\cf[num] = the index of which Color to use, as preset in "on the fly" color table
\cb[num] = which background color to use - (ignored in RichEdit version 2.0)
PROBLEM#2 Crashes in long comments or text (existing problem)
There is a bug in ScanForRtf. Can you see it?
begin
FStrBuffSize:= FStrBuffSize 1024;
ReAllocMem(FStrBuff, FStrBuffSize);
FStrBuffEnd:= FStrBuff 1023;
end; { AllocStrBuff }
procedure TPasConversion.ScanForRtf;
var
i: Integer;
begin
RunStr:= FStrBuff;
FStrBuffEnd:= FStrBuff 1023;
for i:=1 to TokenLen do
begin
Case TokenStr[i] of
''''\'''', ''''{'''', ''''}'''':
begin
RunStr^:= ''''\'''';
inc(RunStr);
end
end;
if RunStr >= FStrBuffEnd then AllocStrBuff;
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com IDC资讯:
主机资讯
注册资讯
托管资讯
vps资讯
网站建设
网站运营:
建站经验
策划盈利
搜索优化
网站推广
免费资源
网络编程:
Asp.Net编程
Asp编程
Php编程
Xml编程
Access
Mssql
Mysql
其它
服务器技术:
Web服务器
Ftp服务器
Mail服务器
Dns服务器
安全防护
软件技巧:
其它软件
Word
Excel
Powerpoint
Ghost
Vista
QQ空间
QQ
FlashGet
迅雷
网页制作:
FrontPages
Dreamweaver
Javascript
css
photoshop
fireworks
Flash
RunStr^:= TokenStr[i];
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有