Skip to content

Commit 4e0c621

Browse files
committed
Group all RTF*** methods into TRTF record
All methods with names beginning with RTF in URTFUtils were replaced with similarly named static class methods of the new TRTF record. The functionality of these replacement methods is identical to the original routines. The constant array mapping RTF control IDs to their names was also moved inside TRTF and renamed. Updated affected code in URTFBuilder.
1 parent 26a7b99 commit 4e0c621

File tree

2 files changed

+158
-107
lines changed

2 files changed

+158
-107
lines changed

Src/URTFBuilder.pas

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ procedure TRTFBuilder.AddText(const Text: string);
234234
fInControls := False;
235235
end;
236236
// Add text, escaping disallowed characters
237-
AppendBody(RTFMakeSafeText(Text, fCodePage));
237+
AppendBody(TRTF.MakeSafeText(Text, fCodePage));
238238
end;
239239

240240
procedure TRTFBuilder.AppendBody(const S: ASCIIString);
@@ -269,7 +269,7 @@ procedure TRTFBuilder.BeginGroup;
269269

270270
procedure TRTFBuilder.ClearParaFormatting;
271271
begin
272-
AddControl(RTFControl(rcPard));
272+
AddControl(TRTF.ControlWord(rcPard));
273273
end;
274274

275275
constructor TRTFBuilder.Create(const CodePage: Integer);
@@ -296,11 +296,11 @@ destructor TRTFBuilder.Destroy;
296296

297297
function TRTFBuilder.DocHeader: ASCIIString;
298298
begin
299-
Result := RTFControl(rcRTF, cRTFVersion)
300-
+ RTFControl(rcAnsi)
301-
+ RTFControl(rcAnsiCodePage, fCodePage)
302-
+ RTFControl(rcDefFontNum, DefaultFontIdx)
303-
+ RTFControl(rcDefLanguage, DefaultLanguageID)
299+
Result := TRTF.ControlWord(rcRTF, cRTFVersion)
300+
+ TRTF.ControlWord(rcAnsi)
301+
+ TRTF.ControlWord(rcAnsiCodePage, fCodePage)
302+
+ TRTF.ControlWord(rcDefFontNum, DefaultFontIdx)
303+
+ TRTF.ControlWord(rcDefLanguage, DefaultLanguageID)
304304
+ fFontTable.AsString
305305
+ fColourTable.AsString
306306
+ fDocProperties.AsString
@@ -315,7 +315,7 @@ procedure TRTFBuilder.EndGroup;
315315

316316
procedure TRTFBuilder.EndPara;
317317
begin
318-
AddControl(RTFControl(rcPar));
318+
AddControl(TRTF.ControlWord(rcPar));
319319
AppendBody(EOL);
320320
fInControls := False;
321321
end;
@@ -327,12 +327,12 @@ function TRTFBuilder.Render: TRTFMarkup;
327327

328328
procedure TRTFBuilder.ResetCharStyle;
329329
begin
330-
AddControl(RTFControl(rcPlain));
330+
AddControl(TRTF.ControlWord(rcPlain));
331331
end;
332332

333333
procedure TRTFBuilder.SetColour(const Colour: TColor);
334334
begin
335-
AddControl(RTFControl(rcForeColorNum, fColourTable.ColourRef(Colour)));
335+
AddControl(TRTF.ControlWord(rcForeColorNum, fColourTable.ColourRef(Colour)));
336336
end;
337337

338338
procedure TRTFBuilder.SetFont(const FontName: string);
@@ -342,39 +342,39 @@ procedure TRTFBuilder.SetFont(const FontName: string);
342342
// We don't emit control if this is default font
343343
FontIdx := fFontTable.FontRef(FontName);
344344
if FontIdx <> DefaultFontIdx then
345-
AddControl(RTFControl(rcFontNum, FontIdx));
345+
AddControl(TRTF.ControlWord(rcFontNum, FontIdx));
346346
end;
347347

348348
procedure TRTFBuilder.SetFontSize(const Points: Double);
349349
begin
350-
AddControl(RTFControl(rcFontSize, FloatToInt(2 * Points)));
350+
AddControl(TRTF.ControlWord(rcFontSize, FloatToInt(2 * Points)));
351351
end;
352352

353353
procedure TRTFBuilder.SetFontStyle(const Style: TFontStyles);
354354
begin
355355
if fsBold in Style then
356-
AddControl(RTFControl(rcBold));
356+
AddControl(TRTF.ControlWord(rcBold));
357357
if fsItalic in Style then
358-
AddControl(RTFControl(rcItalic));
358+
AddControl(TRTF.ControlWord(rcItalic));
359359
if fsUnderline in Style then
360-
AddControl(RTFControl(rcUnderline));
360+
AddControl(TRTF.ControlWord(rcUnderline));
361361
end;
362362

363363
procedure TRTFBuilder.SetIndents(const LeftIndent, FirstLineOffset: SmallInt);
364364
begin
365-
AddControl(RTFControl(rcLeftIndent, LeftIndent));
366-
AddControl(RTFControl(rcFirstLineOffset, FirstLineOffset));
365+
AddControl(TRTF.ControlWord(rcLeftIndent, LeftIndent));
366+
AddControl(TRTF.ControlWord(rcFirstLineOffset, FirstLineOffset));
367367
end;
368368

369369
procedure TRTFBuilder.SetParaSpacing(const Spacing: TRTFParaSpacing);
370370
const
371371
TwipsPerPoint = 20; // Note: 20 Twips in a point
372372
begin
373373
AddControl(
374-
RTFControl(rcSpaceBefore, FloatToInt(TwipsPerPoint * Spacing.Before))
374+
TRTF.ControlWord(rcSpaceBefore, FloatToInt(TwipsPerPoint * Spacing.Before))
375375
);
376376
AddControl(
377-
RTFControl(rcSpaceAfter, FloatToInt(TwipsPerPoint * Spacing.After))
377+
TRTF.ControlWord(rcSpaceAfter, FloatToInt(TwipsPerPoint * Spacing.After))
378378
);
379379
end;
380380

@@ -383,7 +383,7 @@ procedure TRTFBuilder.SetTabStops(const TabStops: array of SmallInt);
383383
Tab: SmallInt;
384384
begin
385385
for Tab in TabStops do
386-
AddControl(RTFControl(rcTabStop, Tab));
386+
AddControl(TRTF.ControlWord(rcTabStop, Tab));
387387
end;
388388

389389
{ TRTFFontTable }
@@ -420,15 +420,15 @@ function TRTFFontTable.AsString: ASCIIString;
420420
Idx: Integer; // loops thru fonts in table
421421
Font: TRTFFont; // reference to a font in table
422422
begin
423-
Result := '{' + RTFControl(rcFontTable);
423+
Result := '{' + TRTF.ControlWord(rcFontTable);
424424
for Idx := 0 to Pred(fFonts.Count) do
425425
begin
426426
Font := fFonts[Idx];
427427
Result := Result + '{'
428-
+ RTFControl(rcFontNum, Idx)
429-
+ RTFControl(rcFontPitch, 1)
430-
+ RTFControl(cGenericFonts[Font.Generic])
431-
+ RTFControl(rcFontCharset, Font.Charset)
428+
+ TRTF.ControlWord(rcFontNum, Idx)
429+
+ TRTF.ControlWord(rcFontPitch, 1)
430+
+ TRTF.ControlWord(cGenericFonts[Font.Generic])
431+
+ TRTF.ControlWord(rcFontCharset, Font.Charset)
432432
+ ' '
433433
+ StringToASCIIString(Font.Name)
434434
+ '}';
@@ -488,7 +488,7 @@ function TRTFColourTable.AsString: ASCIIString;
488488
begin
489489
// Begin table
490490
Result := '{'
491-
+ RTFControl(rcColorTable)
491+
+ TRTF.ControlWord(rcColorTable)
492492
+ ' ';
493493
// Add entry for each colour
494494
for Colour in fColours do
@@ -497,9 +497,9 @@ function TRTFColourTable.AsString: ASCIIString;
497497
begin
498498
RGB := ColorToRGB(Colour);
499499
Result := Result
500-
+ RTFControl(rcRed, GetRValue(RGB))
501-
+ RTFControl(rcGreen, GetGValue(RGB))
502-
+ RTFControl(rcBlue, GetBValue(RGB))
500+
+ TRTF.ControlWord(rcRed, GetRValue(RGB))
501+
+ TRTF.ControlWord(rcGreen, GetGValue(RGB))
502+
+ TRTF.ControlWord(rcBlue, GetBValue(RGB))
503503
+ ';'
504504
end
505505
else
@@ -540,9 +540,9 @@ function TRTFDocProperties.AsString: ASCIIString;
540540
Exit;
541541
end;
542542
// Start with \info control word in group
543-
Result := '{' + RTFControl(rcInfo);
543+
Result := '{' + TRTF.ControlWord(rcInfo);
544544
if fTitle <> '' then
545-
Result := Result + RTFUnicodeSafeDestination(rcTitle, fTitle, fCodePage);
545+
Result := Result + TRTF.UnicodeSafeDestination(rcTitle, fTitle, fCodePage);
546546
// Close \info group
547547
Result := Result + '}';
548548
end;

0 commit comments

Comments
 (0)