This repository has been archived by the owner on Oct 29, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
uexporter.pas
144 lines (118 loc) · 3.77 KB
/
uexporter.pas
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
unit uExporter;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, SynEditExport, SynExportHTML, Graphics;
type
TExporterHTML = class(TSynExporterHTML)
protected
function GetHeader: string; override;
function GetFooter: string; override;
function ColorToHTML(AColor: TColor): string;
end;
type
TExporterBB = class(TSynCustomExporter)
procedure FormatAfterLastAttribute; override;
procedure FormatAttributeDone(BackgroundChanged, ForegroundChanged: boolean;
FontStylesChanged: TFontStyles); override;
procedure FormatAttributeInit(BackgroundChanged, ForegroundChanged: boolean;
FontStylesChanged: TFontStyles); override;
procedure FormatBeforeFirstAttribute({%H-}BackgroundChanged, {%H-}ForegroundChanged: boolean;
FontStylesChanged: TFontStyles); override;
function GetFooter: string; override;
function GetHeader: string; override;
function GetFormatName: string; override;
procedure FormatNewLine; override;
function ColorToHTML(AColor: TColor): string;
end;
implementation
{ TExporterBB }
procedure TExporterBB.FormatAfterLastAttribute;
begin
if fsUnderline in fLastStyle then
AddData('[/U]');
if fsItalic in fLastStyle then
AddData('[/I]');
if fsBold in fLastStyle then
AddData('[/B]');
if fLastFG <> fFont.Color then
AddData('[/COLOR]');
end;
procedure TExporterBB.FormatAttributeDone(BackgroundChanged, ForegroundChanged: boolean;
FontStylesChanged: TFontStyles);
begin
if BackgroundChanged or ForegroundChanged or (FontStylesChanged <> []) then
begin
if fsUnderline in fLastStyle then
AddData('[/U]');
if fsItalic in fLastStyle then
AddData('[/I]');
if fsBold in fLastStyle then
AddData('[/B]');
end;
if (BackgroundChanged or ForegroundChanged) and (fLastFG <> fFont.Color) then
AddData('[/COLOR]');
end;
procedure TExporterBB.FormatAttributeInit(BackgroundChanged, ForegroundChanged: boolean;
FontStylesChanged: TFontStyles);
begin
if (BackgroundChanged or ForegroundChanged) and (fLastFG <> fFont.Color) then
AddData('[COLOR="' + ColorToHtml(fLastFG) + '"]');
if BackgroundChanged or ForegroundChanged or (FontStylesChanged <> []) then
begin
if fsBold in fLastStyle then
AddData('[B]');
if fsItalic in fLastStyle then
AddData('[I]');
if fsUnderline in fLastStyle then
AddData('[U]');
end;
end;
procedure TExporterBB.FormatBeforeFirstAttribute(BackgroundChanged, ForegroundChanged: boolean;
FontStylesChanged: TFontStyles);
begin
AddData('[COLOR="' + ColorToHtml(fLastFG) + '"]');
if FontStylesChanged <> [] then
begin
if fsBold in fLastStyle then
AddData('[B]');
if fsItalic in fLastStyle then
AddData('[I]');
if fsUnderline in fLastStyle then
AddData('[U]');
end;
end;
function TExporterBB.GetFooter: string;
begin
Result := '[/CODE]';
end;
function TExporterBB.GetHeader: string;
begin
Result := '[CODE]';
end;
function TExporterBB.GetFormatName: string;
begin
Result := 'BB';
end;
procedure TExporterBB.FormatNewLine;
begin
AddNewLine;
end;
function TExporterBB.ColorToHTML(AColor: TColor): string;
begin
Result := '#' + IntToHex(Red(AColor), 2) + IntToHex(green(AColor), 2) + IntToHex(blue(AColor), 2);
end;
{ TExporterHTML }
function TExporterHTML.GetHeader: string;
begin
Result := '<div style= "background-color: ' + ColorToHTML(Color) + ';"><pre><code>';
end;
function TExporterHTML.GetFooter: string;
begin
Result := '</code></pre></div>';
end;
function TExporterHTML.ColorToHTML(AColor: TColor): string;
begin
Result := '#' + IntToHex(Red(AColor), 2) + IntToHex(green(AColor), 2) + IntToHex(blue(AColor), 2);
end;
end.