1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
| ///////////////////////////////////////////////////////////////////////////
// //
// Copyright (c) 2015 by Charta Software B.V. //
// All rights reserved //
// //
// Version: 1.7.0.83525 //
// Web site: https://pascal.chartasoftware.com/ //
// //
// This code and information are provided "as is" without warranty of //
// any kind. Dissemination of this information or reproduction of //
// this material is strictly forbidden unless prior written permission //
// is obtained from Charta Software B.V.. //
// //
///////////////////////////////////////////////////////////////////////////
unit Html.Document;
interface
uses
Boolean,
Character.Encoding,
Geometry._2d.Integer32.Rectangle,
Geometry._2d.Integer32.Size,
Html.Attribute,
Html.Element,
Html.Element.Container,
Html.Element.Stylable,
Image.Vector.Svg.Document,
Integer._32,
Internet.MediaType,
Text,
Text.List,
Uri;
type
THtmlDocumentType = class(THtmlElement)
public
PublicId: TText;
SystemId: TUri;
constructor Create(const PublicId: TText; const SystemId: TUri); reintroduce; virtual;
end;
THtmlHead = class(THtmlContainerElement)
end;
THtmlHtml = class(THtmlElement)
private
FHead: THtmlHead;
FBody: THtmlContainerElement;
public
constructor Create(); override;
destructor Destroy(); override;
procedure AddAttributes(Attributes: THtmlAttributes); override;
property Head: THtmlHead read FHead;
property Body: THtmlContainerElement read FBody;
end;
THtmlDocument = class(THtmlElement)
private
FDocumentType: THtmlDocumentType;
FHtml: THtmlHtml;
procedure SetDocumentType(const Value: THtmlDocumentType);
public
constructor Create(); override;
destructor Destroy(); override;
property DocumentType: THtmlDocumentType read FDocumentType write SetDocumentType;
property Html: THtmlHtml read FHtml;
end;
THtmlTitle = class(THtmlContainerElement)
end;
THtmlMeta = class(THtmlElement)
end;
THtmlMetaName = class(THtmlMeta)
public
Name: TText;
Content: TText;
constructor Create(const Name: TText; const Content: TText); reintroduce; virtual;
procedure AddAttributes(Attributes: THtmlAttributes); override;
end;
THtmlMetaHttpEquivalent = class(THtmlMeta)
public
HttpEquivalent: TText;
Content: TText;
constructor Create(const HttpEquivalent: TText; const Content: TText); reintroduce; virtual;
procedure AddAttributes(Attributes: THtmlAttributes); override;
end;
THtmlMetaCharSet = class(THtmlMeta)
public
CharSet: TCharacterEncoding;
constructor Create(const CharSet: TCharacterEncoding); reintroduce; virtual;
procedure AddAttributes(Attributes: THtmlAttributes); override;
end;
THtmlBase = class(THtmlElement)
public
HRef: TUri;
procedure AddAttributes(Attributes: THtmlAttributes); override;
end;
THtmlStyle = class(THtmlElement)
private
FContentType: TMediaType;
procedure SetContentType(const Value: TMediaType);
public
Contents: TTextList;
constructor Create(); override;
destructor Destroy(); override;
procedure AddAttributes(Attributes: THtmlAttributes); override;
property ContentType: TMediaType read FContentType write SetContentType;
end;
THtmlBody = class(THtmlContainerElement)
end;
THtmlLink = class(THtmlElement)
private
FContentType: TMediaType;
procedure SetContentType(const Value: TMediaType);
public
Rel: TText;
Title: TText;
HRef: TUri;
destructor Destroy(); override;
procedure AddAttributes(Attributes: THtmlAttributes); override;
property ContentType: TMediaType read FContentType write SetContentType;
end;
THtmlImage = class(THtmlStylableElement)
public
Source: TUri;
AlternativeText: TText;
Title: TText;
UseMap: TText;
Size: TInteger32Size;
constructor Create(); override;
procedure AddAttributes(Attributes: THtmlAttributes); override;
end;
THtmlObject = class(THtmlContainerElement)
private
FContentType: TMediaType;
procedure SetContentType(const Value: TMediaType);
public
ClassID: TText;
Data: TUri;
CodeBase: TUri;
destructor Destroy(); override;
procedure AddAttributes(Attributes: THtmlAttributes); override;
property ContentType: TMediaType read FContentType write SetContentType;
end;
THtmlParam = class(THtmlStylableElement)
public
Value: TText;
procedure AddAttributes(Attributes: THtmlAttributes); override;
end;
THtmlEmbed = class(THtmlStylableElement)
private
FContentType: TMediaType;
procedure SetContentType(const Value: TMediaType);
public
PluginsPage: TUri;
Source: TUri;
Quality: TText;
Loop: TBoolean;
ShowControls: TBoolean;
ShowStatusBar: TBoolean;
ShowDisplay: TBoolean;
AutoStart: TBoolean;
Size: TInteger32Size;
WMode: TText;
destructor Destroy(); override;
procedure AddAttributes(Attributes: THtmlAttributes); override;
property ContentType: TMediaType read FContentType write SetContentType;
end;
THtmlIframe = class(THtmlContainerElement)
public
Source: TUri;
procedure AddAttributes(Attributes: THtmlAttributes); override;
end;
THtmlMap = class(THtmlContainerElement)
end;
THtmlArea = class(THtmlContainerElement)
public
AccessKey: TText;
AlternativeText: TText;
Coordinates: TInteger32Rectangle;
HRef: TUri;
TabIndex: TInteger32;
Target: TText;
procedure AddAttributes(Attributes: THtmlAttributes); override;
end;
TScriptType = (stTextJavascript);
THtmlScript = class(THtmlElement)
protected
function ScriptTypeToText(ScriptType: TScriptType): TText;
public
ScriptType: TScriptType;
Source: TUri;
Lines: TTextList;
constructor Create(); override;
destructor Destroy(); override;
procedure AddAttributes(Attributes: THtmlAttributes); override;
end;
THtmlComment = class(THtmlElement)
public
Lines: TTextList;
constructor Create(); override;
destructor Destroy(); override;
end;
THtmlSvg = class(THtmlElement)
protected
FDocument: TSvgDocument;
procedure SetDocument(Value: TSvgDocument);
public
destructor Destroy(); override;
property Document: TSvgDocument read FDocument write SetDocument;
end;
implementation
uses
Exception,
Integer._32.TextFormat;
{ THtmlImage }
procedure THtmlImage.AddAttributes(Attributes: THtmlAttributes);
begin
inherited AddAttributes(Attributes);
Attributes.AddRequired('src', Source.ToText());
Attributes.AddOptional('alt', AlternativeText);
Attributes.AddOptional('title', Title);
Attributes.AddOptional('usemap', UseMap);
Attributes.AddOptional('width', Size.Width, -1);
Attributes.AddOptional('height', Size.Height, -1);
end;
constructor THtmlImage.Create();
begin
inherited Create();
Size := TInteger32Size.New(-1, -1);
end;
{ THtmlIFrame }
procedure THtmlIframe.AddAttributes(Attributes: THtmlAttributes);
begin
inherited AddAttributes(Attributes);
Attributes.AddRequired('src', Source);
end;
{ THtmlObject }
procedure THtmlObject.AddAttributes(Attributes: THtmlAttributes);
begin
inherited AddAttributes(Attributes);
Attributes.AddOptional('classid', ClassID);
Attributes.AddOptional('codebase', CodeBase.ToText());
Attributes.AddOptional('data', Data.ToText());
Attributes.AddOptional('type', ContentType);
end;
destructor THtmlObject.Destroy();
begin
ContentType.ReleaseReference();
inherited Destroy();
end;
procedure THtmlObject.SetContentType(const Value: TMediaType);
begin
if Value <> ContentType then
begin
Value.AddReference();
ContentType.ReleaseReference();
FContentType := Value;
end;
end;
{ THtmlParam }
procedure THtmlParam.AddAttributes(Attributes: THtmlAttributes);
begin
inherited AddAttributes(Attributes);
Attributes.AddRequired('value', Value);
end;
{ THtmlEmbed }
procedure THtmlEmbed.AddAttributes(Attributes: THtmlAttributes);
begin
inherited AddAttributes(Attributes);
Attributes.AddRequired('src', Source.ToText());
Attributes.AddOptional('type', ContentType);
Attributes.AddOptional('width', Size.Width);
Attributes.AddOptional('height', Size.Height);
Attributes.AddOptional('pluginspage', PluginsPage.ToText());
Attributes.AddOptional('quality', Quality);
Attributes.AddOptional('loop', Loop);
Attributes.AddOptional('showcontrols', ShowControls);
Attributes.AddOptional('ShowstatusBar', ShowStatusBar);
Attributes.AddOptional('Showdisplay', ShowDisplay);
Attributes.AddOptional('autostart', AutoStart, True);
Attributes.AddOptional('wmode', WMode);
end;
destructor THtmlEmbed.Destroy();
begin
ContentType.ReleaseReference();
inherited Destroy();
end;
procedure THtmlEmbed.SetContentType(const Value: TMediaType);
begin
if Value <> ContentType then
begin
Value.AddReference();
ContentType.ReleaseReference();
FContentType := Value;
end;
end;
{ THtmlArea }
procedure THtmlArea.AddAttributes(Attributes: THtmlAttributes);
begin
inherited AddAttributes(Attributes);
if HRef.IsEmpty then
Attributes.AddRequired('nohref', 'on')
else
Attributes.AddRequired('href', HRef.ToText());
Attributes.AddOptional('acceskey', AccessKey);
Attributes.AddOptional('alt', AlternativeText);
Attributes.AddRequired('coords', RectangleToCoordinates(Coordinates));
Attributes.AddRequired('shape', 'rect');
Attributes.AddOptional('tabindex', Integer32ToText(TabIndex));
Attributes.AddOptional('target', Target);
end;
{ THtmlScript }
procedure THtmlScript.AddAttributes(Attributes: THtmlAttributes);
begin
inherited AddAttributes(Attributes);
Attributes.AddRequired('type', ScriptTypeToText(ScriptType));
Attributes.AddOptional('src', Source.ToText());
end;
constructor THtmlScript.Create();
begin
inherited Create();
Lines := TTextList.Create();
end;
destructor THtmlScript.Destroy();
begin
Lines.Free();
inherited Destroy();
end;
function THtmlScript.ScriptTypeToText(ScriptType: TScriptType): TText;
begin
case ScriptType of
stTextJavascript: Result := 'text/javascript';
else
raise EException.Create('Unknown script type');
end;
end;
{ THtmlLink }
procedure THtmlLink.AddAttributes(Attributes: THtmlAttributes);
begin
inherited AddAttributes(Attributes);
Attributes.AddOptional('rel', Rel);
Attributes.AddOptional('title', Title);
Attributes.AddOptional('type', ContentType);
Attributes.AddOptional('href', HRef.ToText());
end;
destructor THtmlLink.Destroy();
begin
ContentType.ReleaseReference();
inherited Destroy();
end;
procedure THtmlLink.SetContentType(const Value: TMediaType);
begin
if Value <> ContentType then
begin
Value.AddReference();
ContentType.ReleaseReference();
FContentType := Value;
end;
end;
{ THtmlHtml }
procedure THtmlHtml.AddAttributes(Attributes: THtmlAttributes);
begin
inherited AddAttributes(Attributes);
Attributes.AddRequired('xmlns', 'http://www.w3.org/1999/xhtml');
end;
constructor THtmlHtml.Create();
begin
inherited Create();
FHead := THtmlHead.Create();
FHead.AddReference();
FBody := THtmlContainerElement.Create();
FBody.AddReference();
end;
destructor THtmlHtml.Destroy();
begin
Head.ReleaseReference();
Body.ReleaseReference();
inherited Destroy();
end;
{ THtmlDocument }
constructor THtmlDocument.Create();
begin
inherited Create();
FHtml := THtmlHtml.Create();
FHtml.AddReference();
end;
destructor THtmlDocument.Destroy();
begin
DocumentType.ReleaseReference();
Html.ReleaseReference();
inherited Destroy();
end;
procedure THtmlDocument.SetDocumentType(const Value: THtmlDocumentType);
begin
if Value <> DocumentType then
begin
Value.AddReference();
DocumentType.ReleaseReference();
FDocumentType := Value;
end;
end;
{ THtmlDocumentType }
constructor THtmlDocumentType.Create(const PublicId: TText; const SystemId: TUri);
begin
inherited Create();
Self.PublicId := PublicId;
Self.SystemId := SystemId;
end;
{ THtmlComment }
constructor THtmlComment.Create();
begin
inherited Create();
Lines := TTextList.Create();
end;
destructor THtmlComment.Destroy();
begin
Lines.Free();
inherited Destroy();
end;
{ THtmlBase }
procedure THtmlBase.AddAttributes(Attributes: THtmlAttributes);
begin
inherited AddAttributes(Attributes);
Attributes.AddRequired('href', HRef.ToText());
end;
{ THtmlStyle }
procedure THtmlStyle.AddAttributes(Attributes: THtmlAttributes);
begin
inherited AddAttributes(Attributes);
Attributes.AddRequired('type', ContentType);
end;
constructor THtmlStyle.Create();
begin
inherited Create();
Contents := TTextList.Create();
end;
destructor THtmlStyle.Destroy();
begin
Contents.Free();
ContentType.ReleaseReference();
inherited Destroy();
end;
procedure THtmlStyle.SetContentType(const Value: TMediaType);
begin
if Value <> ContentType then
begin
Value.AddReference();
ContentType.ReleaseReference();
FContentType := Value;
end;
end;
{ THtmlMetaName }
procedure THtmlMetaName.AddAttributes(Attributes: THtmlAttributes);
begin
inherited AddAttributes(Attributes);
Attributes.AddRequired('name', Name);
Attributes.AddRequired('content', Content);
end;
constructor THtmlMetaName.Create(const Name: TText; const Content: TText);
begin
inherited Create();
Self.Name := Name;
Self.Content := Content;
end;
{ THtmlMetaHttpEquivalent }
procedure THtmlMetaHttpEquivalent.AddAttributes(Attributes: THtmlAttributes);
begin
inherited AddAttributes(Attributes);
Attributes.AddRequired('http-equiv', HttpEquivalent);
Attributes.AddRequired('content', Content);
end;
constructor THtmlMetaHttpEquivalent.Create(const HttpEquivalent: TText; const Content: TText);
begin
inherited Create();
Self.HttpEquivalent := HttpEquivalent;
Self.Content := Content;
end;
{ THtmlMetaCharSet }
procedure THtmlMetaCharSet.AddAttributes(Attributes: THtmlAttributes);
begin
inherited AddAttributes(Attributes);
Attributes.AddRequired('charset', CharSet.Identifier);
end;
constructor THtmlMetaCharSet.Create(const CharSet: TCharacterEncoding);
begin
inherited Create();
Self.CharSet := CharSet;
end;
{ THtmlSvg }
destructor THtmlSvg.Destroy();
begin
Document.ReleaseReference();
inherited Destroy();
end;
procedure THtmlSvg.SetDocument(Value: TSvgDocument);
begin
if Value <> Document then
begin
Value.AddReference();
Document.ReleaseReference();
FDocument := Value;
end;
end;
end.
|