@@ -21,23 +21,21 @@ interface
21
21
22
22
type
23
23
TActiveTextTextRenderer = class (TObject)
24
- public
24
+ strict private
25
25
const
26
26
// / <summary>Special space character used to indicate the start of a list
27
27
// / item.</summary>
28
28
// / <remarks>This special character is a necessary kludge because some
29
- // / c odethat renders active text as formatted plain text strips away
29
+ // / code that renders active text as formatted plain text strips away
30
30
// / leading #32 characters as part of the formatting process. Therefore
31
31
// / indentation in list items is lost if #32 characters are used for it.
32
- // / NBSP was chosen since it should render the same as a space if calling
33
- // / code doesn't convert it .</remarks>
32
+ // / NBSP was chosen since it should render the same as a space if not
33
+ // / removed .</remarks>
34
34
LISpacer = NBSP; // Do not localise. Must be <> #32
35
35
// / <summary>Bullet character used when rendering unordered list items.
36
36
// / </summary>
37
37
Bullet = ' *' ; // Do not localise. Must be <> #32 and <> LISpacer
38
- strict private
39
- const
40
- IndentDelta = 2 ;
38
+ DefaultIndentDelta = 2 ;
41
39
type
42
40
TListKind = (lkNumber, lkBullet);
43
41
TListState = record
@@ -60,6 +58,7 @@ TLIState = record
60
58
fIndent: UInt16;
61
59
fInPara: Boolean;
62
60
fInListItem: Boolean;
61
+ fIndentDelta: UInt8;
63
62
function CanEmitInline : Boolean;
64
63
procedure AppendToPara (const AText: string);
65
64
procedure InitialiseRender ;
@@ -75,9 +74,10 @@ TLIState = record
75
74
destructor Destroy; override;
76
75
property DisplayURLs: Boolean read fDisplayURLs write fDisplayURLs
77
76
default False;
78
- function RenderWrapped (ActiveText: IActiveText; const PageWidth, LMargin,
79
- ParaOffset: Cardinal; const Prefix: string = ' ' ;
80
- const Suffix: string = ' ' ): string;
77
+ property IndentDelta: UInt8 read fIndentDelta write fIndentDelta
78
+ default DefaultIndentDelta;
79
+ function RenderWrapped (ActiveText: IActiveText; const PageWidth,
80
+ LMargin: Cardinal): string;
81
81
end ;
82
82
83
83
@@ -122,6 +122,7 @@ constructor TActiveTextTextRenderer.Create;
122
122
fIndent := 0 ;
123
123
fInPara := False;
124
124
fInListItem := False;
125
+ fIndentDelta := DefaultIndentDelta;
125
126
end ;
126
127
127
128
destructor TActiveTextTextRenderer.Destroy;
@@ -200,6 +201,21 @@ function TActiveTextTextRenderer.Render(ActiveText: IActiveText): string;
200
201
201
202
procedure TActiveTextTextRenderer.RenderBlockActionElem (
202
203
Elem: IActiveTextActionElem);
204
+
205
+ procedure OpenListContainer (const ListKind: TListKind);
206
+ begin
207
+ if (fListStack.Count > 0 ) and (fInPara) then
208
+ OutputParagraph;
209
+ fListStack.Push(TListState.Create(ListKind));
210
+ Inc(fIndent, IndentDelta);
211
+ end ;
212
+
213
+ procedure AddListMarker (const Marker: string);
214
+ begin
215
+ fParaBuilder.Append(Marker);
216
+ fParaBuilder.Append(StringOfChar(NBSP, IndentDelta - Length(Marker)));
217
+ end ;
218
+
203
219
var
204
220
ListState: TListState;
205
221
begin
@@ -208,22 +224,12 @@ procedure TActiveTextTextRenderer.RenderBlockActionElem(
208
224
begin
209
225
fBlocksStack.Push(Elem.Kind);
210
226
case Elem.Kind of
211
- ekPara: { Do nothing } ;
212
- ekHeading: { Do nothing} ;
227
+ ekPara, ekHeading, ekBlock:
228
+ { Do nothing} ;
213
229
ekUnorderedList:
214
- begin
215
- if (fListStack.Count > 0 ) and (fInPara) then
216
- OutputParagraph;
217
- fListStack.Push(TListState.Create(lkBullet));
218
- Inc(fIndent, IndentDelta);
219
- end ;
230
+ OpenListContainer(lkBullet);
220
231
ekOrderedList:
221
- begin
222
- if (fListStack.Count > 0 ) and (fInPara) then
223
- OutputParagraph;
224
- fListStack.Push(TListState.Create(lkNumber));
225
- Inc(fIndent, IndentDelta);
226
- end ;
232
+ OpenListContainer(lkNumber);
227
233
ekListItem:
228
234
begin
229
235
// Update list number of current list
@@ -235,34 +241,19 @@ procedure TActiveTextTextRenderer.RenderBlockActionElem(
235
241
// Act depending on current list kind
236
242
case fListStack.Peek.ListKind of
237
243
lkNumber:
238
- begin
239
- // Number list: start a new numbered item, with current number
240
- fParaBuilder.Append(IntToStr(fListStack.Peek.ListNumber));
241
- fParaBuilder.Append(NBSP);
242
- end ;
244
+ AddListMarker(IntToStr(fListStack.Peek.ListNumber));
243
245
lkBullet:
244
- begin
245
- // Bullet list: start a new bullet point
246
- fParaBuilder.Append(Bullet + NBSP);
247
- end ;
246
+ AddListMarker(Bullet);
248
247
end ;
249
248
end ;
250
249
end ;
251
250
end ;
252
251
fsClose:
253
252
begin
254
253
case Elem.Kind of
255
- ekPara:
254
+ ekPara, ekHeading, ekBlock :
256
255
OutputParagraph;
257
- ekHeading:
258
- OutputParagraph;
259
- ekUnorderedList:
260
- begin
261
- OutputParagraph;
262
- fListStack.Pop;
263
- Dec(fIndent, IndentDelta);
264
- end ;
265
- ekOrderedList:
256
+ ekUnorderedList, ekOrderedList:
266
257
begin
267
258
OutputParagraph;
268
259
fListStack.Pop;
@@ -315,7 +306,7 @@ procedure TActiveTextTextRenderer.RenderURL(Elem: IActiveTextActionElem);
315
306
end ;
316
307
317
308
function TActiveTextTextRenderer.RenderWrapped (ActiveText: IActiveText;
318
- const PageWidth, LMargin, ParaOffset : Cardinal; const Prefix, Suffix: string ):
309
+ const PageWidth, LMargin: Cardinal):
319
310
string;
320
311
var
321
312
Paras: IStringList;
@@ -367,13 +358,13 @@ function TActiveTextTextRenderer.RenderWrapped(ActiveText: IActiveText;
367
358
368
359
begin
369
360
Result := ' ' ;
370
- Paras := TIStringList.Create(Prefix + Render(ActiveText) + Suffix , EOL, True);
361
+ Paras := TIStringList.Create(Render(ActiveText), EOL, True);
371
362
for Para in Paras do
372
363
begin
373
364
if IsListItem then
374
365
begin
375
- Offset := -ParaOffset ;
376
- ParaIndent := CalcParaIndent + LMargin + ParaOffset ;
366
+ Offset := -IndentDelta ;
367
+ ParaIndent := CalcParaIndent + LMargin + IndentDelta ;
377
368
end
378
369
else
379
370
begin
0 commit comments