Skip to content

Commit ff0400d

Browse files
committed
Merge branch 'feature/issue#41-customise-detail-pane-font-size' into develop
Fixes #41
2 parents 4f1d56f + eff0390 commit ff0400d

File tree

9 files changed

+291
-76
lines changed

9 files changed

+291
-76
lines changed

Docs/Design/FileFormats/config.html

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
66
* obtain one at https://mozilla.org/MPL/2.0/
77
*
8-
* Copyright (C) 2012-2021, Peter Johnson (gravatar.com/delphidabbler).
8+
* Copyright (C) 2012-2022, Peter Johnson (gravatar.com/delphidabbler).
99
*
1010
* CodeSnip File Format Documentation: Configuration Files
1111
-->
@@ -167,7 +167,7 @@ <h3>
167167
</p>
168168

169169
<p>
170-
There have been several versions of this file. The current one is version 17. The change to version 17 came with CodeSnip v4.19.0 and the addition of the [Prefs] section.
170+
There have been several versions of this file. The current one is version 18. The change to version 18 came with CodeSnip v4.20.0 and the addition of the [Prefs] section.
171171
</p>
172172

173173
<p>
@@ -917,7 +917,13 @@ <h4>
917917
<code class="key">OverviewFontSize</code> (Integer)
918918
</dt>
919919
<dd>
920-
Size of font to be used in overview pane tree view. If missing or empty the default value is <code class="value">9</code>.
920+
Size of font to be used in overview pane tree view. If missing or empty the default value is the default font size of the operationg system.
921+
</dd>
922+
<dt>
923+
<code class="key">DetailFontSize</code> (Integer)
924+
</dt>
925+
<dd>
926+
Size of font to be used in detail pane for all text except for source code. If missing or empty the default value is the default content font size of the operating system.
921927
</dd>
922928
</dl>
923929

Src/FirstRun.UConfigFile.pas

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
44
* obtain one at https://mozilla.org/MPL/2.0/
55
*
6-
* Copyright (C) 2007-2021, Peter Johnson (gravatar.com/delphidabbler).
6+
* Copyright (C) 2007-2022, Peter Johnson (gravatar.com/delphidabbler).
77
*
88
* Implements class that manages the updating of older config files to the
99
* current format.
@@ -82,7 +82,7 @@ TUserConfigFileUpdater = class(TConfigFileUpdater)
8282
strict private
8383
const
8484
/// <summary>Current user config file version.</summary>
85-
FileVersion = 17;
85+
FileVersion = 18;
8686
strict protected
8787
/// <summary>Returns current user config file version.</summary>
8888
class function GetFileVersion: Integer; override;

Src/FrDetailView.pas

Lines changed: 63 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ implementation
107107

108108
uses
109109
// Delphi
110-
SysUtils, Graphics, Menus,
110+
SysUtils, Graphics, Menus, Math,
111111
// Project
112112
ActiveText.UHTMLRenderer, Browser.UHighlighter, Hiliter.UAttrs, Hiliter.UCSS,
113113
Hiliter.UGlobals, UColours, UCSSUtils, UFontHelper, UPreferences, UQuery,
@@ -119,27 +119,53 @@ implementation
119119

120120
procedure TDetailViewFrame.BuildCSS(const CSSBuilder: TCSSBuilder);
121121
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
124132
begin
125133
// NOTE:
126134
// We only set CSS properties that may need to use system colours or fonts
127135
// that may be changed by user or changing program defaults. CSS that controls
128136
// layout remains in a CSS file embedded in resources.
129137
inherited;
138+
ContentFont := nil;
139+
MonoFont := nil;
130140
CSSFont := TFont.Create;
131141
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);
132153
// Set body style to use program's font and window colour
133154
with CSSBuilder.AddSelector('body') do
134155
begin
135-
TFontHelper.SetContentFont(CSSFont);
156+
CSSFont.Assign(ContentFont);
136157
AddProperty(TCSS.FontProps(CSSFont));
137158
AddProperty(TCSS.BackgroundColorProp(clWindow));
138159
end;
160+
with CSSBuilder.Selectors['code'] do
161+
begin
162+
CSSFont.Assign(MonoFont);
163+
AddProperty(TCSS.FontProps(CSSFont));
164+
end;
139165
// Set table to use required font
140166
with CSSBuilder.AddSelector('table') do
141167
begin
142-
TFontHelper.SetContentFont(CSSFont);
168+
CSSFont.Assign(ContentFont);
143169
AddProperty(TCSS.FontProps(CSSFont));
144170
AddProperty(TCSS.BackgroundColorProp(clBorder));
145171
end;
@@ -149,31 +175,53 @@ procedure TDetailViewFrame.BuildCSS(const CSSBuilder: TCSSBuilder);
149175
// Sets H1 heading font size and border
150176
with CSSBuilder.AddSelector('h1') do
151177
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+
);
154182
CSSFont.Style := [fsBold];
155183
AddProperty(TCSS.FontProps(CSSFont));
156184
AddProperty(TCSS.BorderProp(cssBottom, 1, cbsSolid, clBorder));
157185
end;
158186
// Sets H2 heading font size and border
159187
with CSSBuilder.AddSelector('h2') do
160188
begin
161-
TFontHelper.SetContentFont(CSSFont);
189+
CSSFont.Assign(ContentFont);
162190
CSSFont.Style := [fsBold];
163191
AddProperty(TCSS.FontProps(CSSFont));
164192
end;
165193
// Set H2 heading font for use in rendered active text
166194
with CSSBuilder.AddSelector('.active-text h2') do
167195
begin
168-
TFontHelper.SetContentFont(CSSFont);
196+
CSSFont.Assign(ContentFont);
169197
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+
);
171211
AddProperty(TCSS.FontProps(CSSFont));
172212
end;
173213
// Set H2 heading font for use in rendered active text in snippet list table
174214
with CSSBuilder.AddSelector('.snippet-list .active-text h2') do
175215
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);
177225
CSSFont.Style := [fsBold];
178226
AddProperty(TCSS.FontProps(CSSFont));
179227
end;
@@ -187,8 +235,8 @@ procedure TDetailViewFrame.BuildCSS(const CSSBuilder: TCSSBuilder);
187235
// Sets CSS for style of New Tab text
188236
with CSSBuilder.AddSelector('#newtab') do
189237
begin
190-
TFontHelper.SetContentFont(CSSFont);
191-
CSSFont.Size := 36;
238+
CSSFont.Assign(ContentFont);
239+
CSSFont.Size := 36 + Round(36 * ContentFontScaleFactor);
192240
CSSFont.Color := clNewTabText;
193241
AddProperty(TCSS.FontProps(CSSFont));
194242
end;
@@ -218,6 +266,8 @@ procedure TDetailViewFrame.BuildCSS(const CSSBuilder: TCSSBuilder);
218266
AddProperty(TCSS.FontWeightProp(cfwNormal));
219267
end;
220268
finally
269+
ContentFont.Free;
270+
MonoFont.Free;
221271
CSSFont.Free;
222272
end;
223273
end;

Src/FrDisplayPrefs.dfm

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,27 @@ inherited DisplayPrefsFrame: TDisplayPrefsFrame
4040
Caption = 'Overview tree view &font size: '
4141
FocusControl = cbOverviewFontSize
4242
end
43+
object lblDetailFontSize: TLabel
44+
Left = 16
45+
Top = 232
46+
Width = 105
47+
Height = 13
48+
Caption = 'Detail pane font si&ze: '
49+
FocusControl = cbDetailFontSize
50+
end
51+
object lblHiliterInfo: TLabel
52+
Left = 16
53+
Top = 256
54+
Width = 370
55+
Height = 36
56+
Caption =
57+
'To change the size of the source code font use the the Syntax Hi' +
58+
'ghlighter options page.'
59+
Color = clBtnFace
60+
ParentColor = False
61+
Transparent = True
62+
WordWrap = True
63+
end
4364
object cbOverviewTree: TComboBox
4465
Left = 192
4566
Top = 2
@@ -80,6 +101,14 @@ inherited DisplayPrefsFrame: TDisplayPrefsFrame
80101
Width = 57
81102
Height = 21
82103
TabOrder = 4
83-
OnChange = cbOverviewFontSizeChange
104+
OnChange = FontSizeChange
105+
end
106+
object cbDetailFontSize: TComboBox
107+
Left = 192
108+
Top = 229
109+
Width = 57
110+
Height = 21
111+
TabOrder = 5
112+
OnChange = FontSizeChange
84113
end
85114
end

0 commit comments

Comments
 (0)