讲述如何开发一个控件,很有价值(三)

2008-04-09 04:31:05来源:互联网 阅读 ()

新老客户大回馈,云服务器低至5折

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:

  1. INITIAL HEADER (\rtf1\.....)
  2. FONTTABLE (\f0\fswiss...)
  3. COLORTABLE (\colortbl)
  4. MISCELLANEOUS
  5. DEFAULT FORMAT (\pard....)
  6. 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?

procedure TPasConversion.AllocStrBuff;
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;
RunStr^:= TokenStr[i];

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:用DELPHI给OICQ动手术(二)

下一篇:讲述如何开发一个控件,很有价值(四)