@@ -107,7 +107,7 @@ implementation
107
107
108
108
uses
109
109
// Delphi
110
- SysUtils, Graphics, Menus,
110
+ SysUtils, Graphics, Menus, Math,
111
111
// Project
112
112
ActiveText.UHTMLRenderer, Browser.UHighlighter, Hiliter.UAttrs, Hiliter.UCSS,
113
113
Hiliter.UGlobals, UColours, UCSSUtils, UFontHelper, UPreferences, UQuery,
@@ -119,27 +119,53 @@ implementation
119
119
120
120
procedure TDetailViewFrame.BuildCSS (const CSSBuilder: TCSSBuilder);
121
121
var
122
- HiliteAttrs: IHiliteAttrs; // syntax highlighter used to build CSS
123
- CSSFont: TFont; // font used to set CSS properties
122
+ HiliteAttrs: IHiliteAttrs; // syntax highlighter used to build CSS
123
+ ContentFont: TFont; // default content font sized per preferences
124
+ MonoFont: TFont; // default mono font sized per preferences
125
+ CSSFont: TFont; // font used to set CSS properties
126
+ ContentFontScaleFactor: Single; // amount to increase font size by to get
127
+ // proportionally same increase as adding 1 to
128
+ // default content font size
129
+ MonoToContentFontRatio: Single; // ratio of size of mono font to content font
130
+ DefContentFontSize: Integer; // default size of content font
131
+ DefMonoFontSize: Integer; // default size of mono font
124
132
begin
125
133
// NOTE:
126
134
// We only set CSS properties that may need to use system colours or fonts
127
135
// that may be changed by user or changing program defaults. CSS that controls
128
136
// layout remains in a CSS file embedded in resources.
129
137
inherited ;
138
+ ContentFont := nil ;
139
+ MonoFont := nil ;
130
140
CSSFont := TFont.Create;
131
141
try
142
+ MonoFont := TFont.Create;
143
+ ContentFont := TFont.Create;
144
+ TFontHelper.SetDefaultMonoFont(MonoFont);
145
+ TFontHelper.SetContentFont(ContentFont);
146
+ // Must do next two lines before changing content & mono font sizes
147
+ DefContentFontSize := ContentFont.Size;
148
+ DefMonoFontSize := MonoFont.Size;
149
+ ContentFontScaleFactor := 1.0 / DefContentFontSize;
150
+ MonoToContentFontRatio := DefMonoFontSize / DefContentFontSize;
151
+ ContentFont.Size := Preferences.DetailFontSize;
152
+ MonoFont.Size := Round(ContentFont.Size * MonoToContentFontRatio);
132
153
// Set body style to use program's font and window colour
133
154
with CSSBuilder.AddSelector(' body' ) do
134
155
begin
135
- TFontHelper.SetContentFont(CSSFont );
156
+ CSSFont.Assign(ContentFont );
136
157
AddProperty(TCSS.FontProps(CSSFont));
137
158
AddProperty(TCSS.BackgroundColorProp(clWindow));
138
159
end ;
160
+ with CSSBuilder.Selectors[' code' ] do
161
+ begin
162
+ CSSFont.Assign(MonoFont);
163
+ AddProperty(TCSS.FontProps(CSSFont));
164
+ end ;
139
165
// Set table to use required font
140
166
with CSSBuilder.AddSelector(' table' ) do
141
167
begin
142
- TFontHelper.SetContentFont(CSSFont );
168
+ CSSFont.Assign(ContentFont );
143
169
AddProperty(TCSS.FontProps(CSSFont));
144
170
AddProperty(TCSS.BackgroundColorProp(clBorder));
145
171
end ;
@@ -149,31 +175,53 @@ procedure TDetailViewFrame.BuildCSS(const CSSBuilder: TCSSBuilder);
149
175
// Sets H1 heading font size and border
150
176
with CSSBuilder.AddSelector(' h1' ) do
151
177
begin
152
- TFontHelper.SetContentFont(CSSFont);
153
- CSSFont.Size := CSSFont.Size + 2 ;
178
+ CSSFont.Assign(ContentFont);
179
+ CSSFont.Size := CSSFont.Size + Max(
180
+ Round(2 * ContentFontScaleFactor * CSSFont.Size), 2
181
+ );
154
182
CSSFont.Style := [fsBold];
155
183
AddProperty(TCSS.FontProps(CSSFont));
156
184
AddProperty(TCSS.BorderProp(cssBottom, 1 , cbsSolid, clBorder));
157
185
end ;
158
186
// Sets H2 heading font size and border
159
187
with CSSBuilder.AddSelector(' h2' ) do
160
188
begin
161
- TFontHelper.SetContentFont(CSSFont );
189
+ CSSFont.Assign(ContentFont );
162
190
CSSFont.Style := [fsBold];
163
191
AddProperty(TCSS.FontProps(CSSFont));
164
192
end ;
165
193
// Set H2 heading font for use in rendered active text
166
194
with CSSBuilder.AddSelector(' .active-text h2' ) do
167
195
begin
168
- TFontHelper.SetContentFont(CSSFont );
196
+ CSSFont.Assign(ContentFont );
169
197
CSSFont.Style := [fsBold];
170
- CSSFont.Size := CSSFont.Size + 1 ;
198
+ CSSFont.Size := CSSFont.Size + Max(
199
+ Round(ContentFontScaleFactor * CSSFont.Size), 1
200
+ );
201
+ AddProperty(TCSS.FontProps(CSSFont));
202
+ end ;
203
+ // Set CODE tag within H2 heading for use in rendered active text
204
+ with CSSBuilder.AddSelector(' .active-text h2 code' ) do
205
+ begin
206
+ CSSFont.Assign(MonoFont);
207
+ CSSFont.Style := [fsBold];
208
+ CSSFont.Size := CSSFont.Size + Max(
209
+ Round(ContentFontScaleFactor * CSSFont.Size), 1
210
+ );
171
211
AddProperty(TCSS.FontProps(CSSFont));
172
212
end ;
173
213
// Set H2 heading font for use in rendered active text in snippet list table
174
214
with CSSBuilder.AddSelector(' .snippet-list .active-text h2' ) do
175
215
begin
176
- TFontHelper.SetContentFont(CSSFont);
216
+ CSSFont.Assign(ContentFont);
217
+ CSSFont.Style := [fsBold];
218
+ AddProperty(TCSS.FontProps(CSSFont));
219
+ end ;
220
+ // Set CODE within H2 heading font for use in rendered active text in
221
+ // snippet list table
222
+ with CSSBuilder.AddSelector(' .snippet-list .active-text h2 code' ) do
223
+ begin
224
+ CSSFont.Assign(MonoFont);
177
225
CSSFont.Style := [fsBold];
178
226
AddProperty(TCSS.FontProps(CSSFont));
179
227
end ;
@@ -187,8 +235,8 @@ procedure TDetailViewFrame.BuildCSS(const CSSBuilder: TCSSBuilder);
187
235
// Sets CSS for style of New Tab text
188
236
with CSSBuilder.AddSelector(' #newtab' ) do
189
237
begin
190
- TFontHelper.SetContentFont(CSSFont );
191
- CSSFont.Size := 36 ;
238
+ CSSFont.Assign(ContentFont );
239
+ CSSFont.Size := 36 + Round( 36 * ContentFontScaleFactor) ;
192
240
CSSFont.Color := clNewTabText;
193
241
AddProperty(TCSS.FontProps(CSSFont));
194
242
end ;
@@ -218,6 +266,8 @@ procedure TDetailViewFrame.BuildCSS(const CSSBuilder: TCSSBuilder);
218
266
AddProperty(TCSS.FontWeightProp(cfwNormal));
219
267
end ;
220
268
finally
269
+ ContentFont.Free;
270
+ MonoFont.Free;
221
271
CSSFont.Free;
222
272
end ;
223
273
end ;
0 commit comments