delphidabbler / codesnip

A code bank designed with Pascal in mind
https://delphidabbler.com/software/codesnip
Other
110 stars 33 forks source link

Add option to customise font size in detail pane #41

Closed delphidabbler closed 2 years ago

delphidabbler commented 2 years ago

Following implementation of customisable font size for overview pane tree view (see issue #7), it remains 5o allow for customisation of the font size for detail pane, as was suggested by the IP of issue #7.

delphidabbler commented 2 years ago

@PeterPanino - this is still on the todo list!

delphidabbler commented 2 years ago

Think I've worked out how to do this - needs some testing.

PeterPanino commented 2 years ago

I can test it for you.

delphidabbler commented 2 years ago

Cheers @peterpanino

Couldn't sleep last night so ended up browsing source code on my tablet! Think I know what to do now.

delphidabbler commented 2 years ago

The TDetailViewFrame.BuildCSS method in the FrDetailView unit is probably where the font size needs to be set from Preferences.

Need to set font size in the following CSS:

Need to give some thought to whether to simply add a constant size for larger fonts (like h1 for e.g.) or whether to scale them up proportionately).

delphidabbler commented 2 years ago

Not sleeping again!

Here's some suggested code for TDetailViewFrame.BuildCSS that might do the job.

Add new ContentFont object:

var
  ContentFont: TFont;
  ...
begin
  ContentFont := nil;
  CSSFont := TFont.Create;
  try
    ContentFont := TFont.Create;
    TFontHelper.SetContentFont(ContentFont);
    ContentFont.Size := Preferences.xxxxx;
     ...
  finally
    ContentFont.Free;
    ...
 end;
end;

Then whenever we have the statement

TFontHelper.SetContentFont(CSSFont);

Replace it with

CSSFont.Assign(ContentFont);

And if we decide to scale heading fonts, use something like this:

var
  FontScaleFactor: Single;
...
begin
  ...
  FontScaleFactor  := 1.0 / ContentFont.Size;
  ...
  CSSFont.Size := CSSFont.Size + Max(
    Round(CSSFont.Size * FontScaleFactor * Increment),
    Increment
  );
  ...
end;

Where

delphidabbler commented 2 years ago

The above worked quite well, but I needed to deal with the <code> tags generated by the REML <mono> tags. They were overriding the body font size. Aargh!

delphidabbler commented 2 years ago

@PeterPanino I think I've done it, and would be grateful if you could test.

codesnip-large-detail-pane fonts

I've attached a copy of a special, portable, 4.19.0 build with an extra entry on Preferences | Display page for the "detail pane" font. That changes all the font sizes in the detail pane except for the source code - that can already be changed on the Syntax Highlighter page. It's not very elegant, but the preferences dialogue resisted my attempts to move the source code font sizing code to a different page - it was going to get messy.

Download CodeSnip-Portable-Special-Build-419.zip

I've sent the portable version, so you can just extract and run it to test it without it affecting your existing installation in any way. I've included a copy of the Code Snippets Database, along with a special custom test snippet (see the _TEST category) that contains all possible formatting options that can appear on the detail pane. The downside is that the portable version won't display your own snippets (but you can import them if you feel the need - see this FAQ).

BTW I haven't customised any fonts in the attached version - I'll leave that for you to try to ensure it works "out of the box".

Anyhow, if you find it's suitable I can release the official v4.20.0 version in a couple of days.

I'm afraid there's nothing I can do to resize the menu, status bar or dialogue boxes - I made them scalable originally but it was such a mess I turned it all off again!

I've not updated the help file yet.

Thx for offering to help.

BTW2: If you want to poke around, the font info is stored in AppData\User.config under the [Prefs:Display] section in the OverviewFontSize and DetailFontSize keys (they'll not be present until you have run the program at least once). The source code font size is in [Prefs:Hiliter] under the FontSize key.

For completeness, the Code Snippets database files are in AppData\CSDB and custom snippets are in AppData\UserDB. Last but not least, favourites are recorded in AppData\Favourites. The empty UserData directory is there for the user's own files - eg export files, backup files.

delphidabbler commented 2 years ago

No response received. Assuming all is OK.