IDE, Options: Unifying Font-specification to only use Size, instead of mixing Size and Height. Issue #0017694 Patch by cobines

git-svn-id: trunk@32150 -
This commit is contained in:
martin 2011-09-01 21:54:33 +00:00
parent 8bc222bed9
commit d0d565f788
6 changed files with 121 additions and 68 deletions

View File

@ -217,7 +217,7 @@ begin
Caption := lisDisAssAssembler;
EditorOpts.AddHandlerAfterWrite(@DoEditorOptsChanged);
pbAsm.Font.Height := EditorOpts.EditorFontHeight;
pbAsm.Font.Size := EditorOpts.EditorFontSize;
pbAsm.Font.Name := EditorOpts.EditorFont;
Caption := lisMenuViewAssembler;
CopyToClipboard.Caption := lisDbgAsmCopyToClipboard;
@ -679,7 +679,7 @@ procedure TAssemblerDlg.DoEditorOptsChanged(Sender: TObject; Restore: boolean);
var
TM: TTextMetric;
begin
pbAsm.Font.Height := EditorOpts.EditorFontHeight;
pbAsm.Font.Size := EditorOpts.EditorFontSize;
pbAsm.Font.Name := EditorOpts.EditorFont;
if EditorOpts.DisableAntialiasing then
pbAsm.Font.Quality := fqNonAntialiased

View File

@ -570,13 +570,15 @@ const
);
const
EditorOptsFormatVersion = 7;
EditorOptsFormatVersion = 8;
{ * Changes in Version 6:
- ColorSchemes now have a Global settings part.
Language specific changes must save UseSchemeGlobals=False (Default is true)
Since Version 5 did not have this setting, in Version 5 the default is false.
* Changes in Version 7:
DisableAntialiasing default true to false
* Changes in Version 8:
Replaced EditorFontHeight with EditorFontSize.
}
LazSyntaxHighlighterClasses: array[TLazSyntaxHighlighter] of
@ -615,6 +617,8 @@ const
+ [eoHalfPageScroll];
SynEditDefaultOptions2 = SYNEDIT_DEFAULT_OPTIONS2;
EditorOptionsMinimumFontSize = 5;
type
{ TEditOptLanguageInfo stores lazarus IDE additional information
of a highlighter, such as samplesource, which sample lines are special
@ -957,7 +961,7 @@ type
FGutterSeparatorIndex: Integer;
fRightMargin: Integer;
fEditorFont: String;
fEditorFontHeight: Integer;
fEditorFontSize: Integer;
fExtraCharSpacing: Integer;
fExtraLineSpacing: Integer;
fDisableAntialiasing: Boolean;
@ -1092,8 +1096,8 @@ type
property RightMargin: Integer
read fRightMargin write fRightMargin default 80;
property EditorFont: String read fEditorFont write fEditorFont;
property EditorFontHeight: Integer
read fEditorFontHeight write FEditorFontHeight;
property EditorFontSize: Integer
read fEditorFontSize write fEditorFontSize;
property ExtraCharSpacing: Integer
read fExtraCharSpacing write fExtraCharSpacing default 0;
property ExtraLineSpacing: Integer
@ -1210,7 +1214,7 @@ var
function StrToLazSyntaxHighlighter(const s: String): TLazSyntaxHighlighter;
function ExtensionToLazSyntaxHighlighter(Ext: String): TLazSyntaxHighlighter;
function FilenameToLazSyntaxHighlighter(Filename: String): TLazSyntaxHighlighter;
procedure RepairEditorFontHeight(var FontHeight: integer);
procedure RepairEditorFontSize(var FontSize: integer);
function BuildBorlandDCIFile(ACustomSynAutoComplete: TCustomSynAutoComplete): Boolean;
function ColorSchemeFactory: TColorSchemeFactory;
@ -1254,6 +1258,16 @@ const
var
DefaultColorSchemeName: String;
function FontHeightToSize(Height: Integer): Integer;
var
AFont: TFont;
begin
AFont := TFont.Create;
AFont.Height := Height;
Result := AFont.Size;
AFont.Free;
end;
{ TSynEditMouseActionKeyCmdHelper }
function TSynEditMouseActionKeyCmdHelper.GetOptionKeyCmd: TSynEditorCommand;
@ -1268,11 +1282,11 @@ begin
end;
procedure RepairEditorFontHeight(var FontHeight: integer);
procedure RepairEditorFontSize(var FontSize: integer);
begin
if ((FontHeight>=0) and (FontHeight<=5))
or ((FontHeight<0) and (FontHeight>=-5)) then
FontHeight := SynDefaultFontHeight;
if ((FontSize>=0) and (FontSize<=EditorOptionsMinimumFontSize))
or ((FontSize<0) and (FontSize>=-EditorOptionsMinimumFontSize)) then
FontSize := SynDefaultFontSize;
end;
function StrToLazSyntaxHighlighter(const s: String): TLazSyntaxHighlighter;
@ -3047,7 +3061,7 @@ begin
// Display options
fEditorFont := SynDefaultFontName;
fEditorFontHeight := SynDefaultFontHeight;
fEditorFontSize := SynDefaultFontSize;
fDisableAntialiasing := DefaultEditorDisableAntiAliasing;
// Key Mappings
@ -3199,10 +3213,17 @@ begin
XMLConfig.GetValue('EditorOptions/Display/RightMargin', 80);
fEditorFont :=
XMLConfig.GetValue('EditorOptions/Display/EditorFont', SynDefaultFontName);
fEditorFontHeight :=
XMLConfig.GetValue('EditorOptions/Display/EditorFontHeight',
SynDefaultFontHeight);
RepairEditorFontHeight(fEditorFontHeight);
if FileVersion < 8 then begin
fEditorFontSize :=
XMLConfig.GetValue('EditorOptions/Display/EditorFontHeight',
SynDefaultFontHeight);
fEditorFontSize := FontHeightToSize(fEditorFontSize);
end else begin
fEditorFontSize :=
XMLConfig.GetValue('EditorOptions/Display/EditorFontSize',
SynDefaultFontSize);
end;
RepairEditorFontSize(fEditorFontSize);
fExtraCharSpacing :=
XMLConfig.GetValue('EditorOptions/Display/ExtraCharSpacing', 0);
fExtraLineSpacing :=
@ -3391,8 +3412,9 @@ begin
fRightMargin, 80);
XMLConfig.SetDeleteValue('EditorOptions/Display/EditorFont',
fEditorFont, SynDefaultFontName);
XMLConfig.SetDeleteValue('EditorOptions/Display/EditorFontHeight'
,fEditorFontHeight, SynDefaultFontHeight);
XMLConfig.DeleteValue('EditorOptions/Display/EditorFontHeight'); // unused old value
XMLConfig.SetDeleteValue('EditorOptions/Display/EditorFontSize'
,fEditorFontSize, SynDefaultFontSize);
XMLConfig.SetDeleteValue('EditorOptions/Display/ExtraCharSpacing'
,fExtraCharSpacing, 0);
XMLConfig.SetDeleteValue('EditorOptions/Display/ExtraLineSpacing'
@ -3922,7 +3944,7 @@ end;
procedure TEditorOptions.ApplyFontSettingsTo(ASynEdit: TSynEdit);
begin
ASynEdit.Font.Height := fEditorFontHeight;// set height before name for XLFD !
ASynEdit.Font.Size := fEditorFontSize;// set size before name for XLFD !
ASynEdit.Font.Name := fEditorFont;
if fDisableAntialiasing then
ASynEdit.Font.Quality := fqNonAntialiased

View File

@ -177,17 +177,17 @@ inherited EditorDisplayOptionsFrame: TEditorDisplayOptionsFrame
ClientHeight = 87
ClientWidth = 497
TabOrder = 1
object EditorFontHeightLabel: TLabel
AnchorSideLeft.Control = EditorFontHeightComboBox
object EditorFontSizeLabel: TLabel
AnchorSideLeft.Control = EditorFontSizeSpinEdit
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = EditorFontHeightComboBox
AnchorSideTop.Control = EditorFontSizeSpinEdit
AnchorSideTop.Side = asrCenter
Left = 112
Height = 14
Top = 36
Width = 107
BorderSpacing.Around = 6
Caption = 'EditorFontHeightLabel'
Caption = 'EditorFontSizeLabel'
ParentColor = False
end
object ExtraLineSpacingLabel: TLabel
@ -248,34 +248,20 @@ inherited EditorDisplayOptionsFrame: TEditorDisplayOptionsFrame
OnClick = EditorFontButtonClick
TabOrder = 1
end
object EditorFontHeightComboBox: TComboBox
object EditorFontSizeSpinEdit: TSpinEdit
AnchorSideLeft.Control = EditorFontGroupBox
AnchorSideTop.Control = EditorFontComboBox
AnchorSideTop.Side = asrBottom
Left = 6
Height = 21
Top = 33
Width = 100
Height = 29
Top = 41
Width = 50
BorderSpacing.Around = 6
ItemHeight = 13
Items.Strings = (
'10'
'11'
'12'
'13'
'14'
'15'
'16'
'17'
'18'
)
OnChange = ComboboxOnChange
OnExit = ComboboxOnExit
OnKeyDown = ComboBoxOnKeyDown
OnChange = EditorFontSizeSpinEditChange
TabOrder = 2
end
object ExtraLineSpacingComboBox: TComboBox
AnchorSideLeft.Control = EditorFontHeightLabel
AnchorSideLeft.Control = EditorFontSizeLabel
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = EditorFontComboBox
AnchorSideTop.Side = asrBottom
@ -318,7 +304,7 @@ inherited EditorDisplayOptionsFrame: TEditorDisplayOptionsFrame
end
object DisableAntialiasingCheckBox: TCheckBox
AnchorSideLeft.Control = EditorFontGroupBox
AnchorSideTop.Control = EditorFontHeightComboBox
AnchorSideTop.Control = EditorFontSizeSpinEdit
AnchorSideTop.Side = asrBottom
Left = 6
Height = 21

View File

@ -39,8 +39,8 @@ type
EditorFontButton: TButton;
EditorFontComboBox: TComboBox;
EditorFontGroupBox: TGroupBox;
EditorFontHeightComboBox: TComboBox;
EditorFontHeightLabel: TLabel;
EditorFontSizeSpinEdit: TSpinEdit;
EditorFontSizeLabel: TLabel;
ExtraCharSpacingComboBox: TComboBox;
ExtraCharSpacingLabel: TLabel;
ExtraLineSpacingComboBox: TComboBox;
@ -58,6 +58,7 @@ type
VisibleRightMarginCheckBox: TCheckBox;
procedure EditorFontButtonClick(Sender: TObject);
procedure EditorFontComboBoxEditingDone(Sender: TObject);
procedure EditorFontSizeSpinEditChange(Sender: TObject);
procedure ComboboxOnExit(Sender: TObject);
procedure ComboBoxOnKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
@ -69,7 +70,10 @@ type
procedure ShowLineNumbersCheckBoxClick(Sender: TObject);
private
FDialog: TAbstractOptionsEditorDialog;
FUpdatingFontSizeRange: Boolean;
function FontSizeNegativeToPositive(NegativeSize: Integer): Integer;
function GeneralPage: TEditorGeneralOptionsFrame; inline;
procedure SetEditorFontSizeSpinEditValue(FontSize: Integer);
procedure FontDialogApplyClicked(Sender: TObject);
function DoSynEditMouse(var AnInfo: TSynEditMouseActionInfo;
@ -86,6 +90,20 @@ implementation
{$R *.lfm}
uses
LCLIntf;
function TEditorDisplayOptionsFrame.FontSizeNegativeToPositive(NegativeSize: Integer): Integer;
var
tm: TTextMetric;
begin
DisplayPreview.Canvas.Font.Assign(DisplayPreview.Font);
if LCLIntf.GetTextMetrics(DisplayPreview.Canvas.Handle, tm) then
Result := -(NegativeSize + MulDiv(tm.tmInternalLeading, 72, DisplayPreview.Font.PixelsPerInch))
else
Result := -NegativeSize;
end;
procedure TEditorDisplayOptionsFrame.FontDialogApplyClicked(Sender: TObject);
var
a: Integer;
@ -96,7 +114,7 @@ begin
PreviewEdits[a].Font.Assign(TFontDialog(Sender).Font);
SetComboBoxText(EditorFontComboBox, DisplayPreview.Font.Name,cstCaseInsensitive);
SetComboBoxText(EditorFontHeightComboBox, IntToStr(DisplayPreview.Font.Height),cstCaseInsensitive);
SetEditorFontSizeSpinEditValue(DisplayPreview.Font.Size);
end;
function TEditorDisplayOptionsFrame.DoSynEditMouse(var AnInfo: TSynEditMouseActionInfo;
@ -108,16 +126,20 @@ end;
procedure TEditorDisplayOptionsFrame.EditorFontButtonClick(Sender: TObject);
var
FontDialog: TFontDialog;
NewHeight: LongInt;
CurFontSize: Integer;
begin
FontDialog := TFontDialog.Create(nil);
try
with FontDialog do
begin
Font.Name := EditorFontComboBox.Text;
NewHeight := StrToIntDef(EditorFontHeightComboBox.Text, DisplayPreview.Font.Height);
RepairEditorFontHeight(NewHeight);
Font.Height := NewHeight;
CurFontSize := EditorFontSizeSpinEdit.Value;
if CurFontSize < 0 then
begin
CurFontSize := FontSizeNegativeToPositive(CurFontSize);
RepairEditorFontSize(CurFontSize);
end;
Font.Size := CurFontSize;
Options := Options + [fdApplyButton];
OnApplyClicked := @FontDialogApplyClicked;
if Execute then
@ -138,21 +160,32 @@ begin
PreviewEdits[i].Font.Name := EditorFontComboBox.Text;
end;
procedure TEditorDisplayOptionsFrame.EditorFontSizeSpinEditChange(Sender: TObject);
var
NewVal, a: Integer;
begin
NewVal := EditorFontSizeSpinEdit.Value;
if (NewVal < 0) and (NewVal > -EditorOptionsMinimumFontSize) then
begin
// Skip to minimum positive value. Will trigger OnChange again.
SetEditorFontSizeSpinEditValue(EditorOptionsMinimumFontSize);
end
else
begin
if (NewVal > 0) and not FUpdatingFontSizeRange then
EditorFontSizeSpinEdit.MinValue := EditorOptionsMinimumFontSize;
with GeneralPage do
for a := Low(PreviewEdits) to High(PreviewEdits) do
if PreviewEdits[a] <> nil then
PreviewEdits[a].Font.Size := NewVal;
end;
end;
procedure TEditorDisplayOptionsFrame.ComboboxOnExit(Sender: TObject);
var
NewVal, a: Integer;
begin
if Sender = EditorFontHeightComboBox then
begin
NewVal := StrToIntDef(EditorFontHeightComboBox.Text, DisplayPreview.Font.Height);
RepairEditorFontHeight(NewVal);
SetComboBoxText(EditorFontHeightComboBox, IntToStr(NewVal),cstCaseInsensitive);
with GeneralPage do
for a := Low(PreviewEdits) to High(PreviewEdits) do
if PreviewEdits[a] <> nil then
PreviewEdits[a].Font.Height := NewVal;
end
else
if Sender = ExtraCharSpacingComboBox then
begin
NewVal := StrToIntDef(ExtraCharSpacingComboBox.Text, DisplayPreview.ExtraCharSpacing);
@ -277,6 +310,17 @@ begin
Result := TEditorGeneralOptionsFrame(FDialog.FindEditor(TEditorGeneralOptionsFrame));
end;
procedure TEditorDisplayOptionsFrame.SetEditorFontSizeSpinEditValue(FontSize: Integer);
begin
FUpdatingFontSizeRange := True;
if FontSize < 0 then
EditorFontSizeSpinEdit.MinValue := -EditorFontSizeSpinEdit.MaxValue
else
EditorFontSizeSpinEdit.MinValue := EditorOptionsMinimumFontSize;
FUpdatingFontSizeRange := False;
EditorFontSizeSpinEdit.Value := FontSize;
end;
function TEditorDisplayOptionsFrame.GetTitle: String;
begin
Result := dlgEdDisplay;
@ -287,6 +331,7 @@ begin
// Prevent the caret from moving
DisplayPreview.RegisterMouseActionSearchHandler(@DoSynEditMouse);
FDialog := ADialog;
FUpdatingFontSizeRange := False;
MarginAndGutterGroupBox.Caption := dlgMarginGutter;
VisibleRightMarginCheckBox.Caption := dlgVisibleRightMargin;
@ -296,7 +341,7 @@ begin
GutterSeparatorIndexLabel.Caption := dlgGutterSeparatorIndex;
RightMarginLabel.Caption := dlgRightMargin;
EditorFontGroupBox.Caption := dlgDefaultEditorFont;
EditorFontHeightLabel.Caption := dlgEditorFontHeight;
EditorFontSizeLabel.Caption := dlgEditorFontSize;
ExtraCharSpacingLabel.Caption := dlgExtraCharSpacing;
ExtraLineSpacingLabel.Caption := dlgExtraLineSpacing;
DisableAntialiasingCheckBox.Caption := dlgDisableAntialiasing;
@ -320,7 +365,7 @@ begin
VisibleRightMarginCheckBox.Checked := VisibleRightMargin;
SetComboBoxText(RightMarginComboBox, IntToStr(RightMargin),cstCaseInsensitive);
SetComboBoxText(EditorFontComboBox, EditorFont,cstCaseInsensitive);
SetComboBoxText(EditorFontHeightComboBox, IntToStr(EditorFontHeight),cstCaseInsensitive);
SetEditorFontSizeSpinEditValue(EditorFontSize);
SetComboBoxText(ExtraCharSpacingComboBox, IntToStr(ExtraCharSpacing),cstCaseInsensitive);
SetComboBoxText(ExtraLineSpacingComboBox, IntToStr(ExtraLineSpacing),cstCaseInsensitive);
DisableAntialiasingCheckBox.Checked := DisableAntialiasing;
@ -342,7 +387,7 @@ begin
VisibleRightMargin := VisibleRightMarginCheckBox.Checked;
RightMargin := StrToIntDef(RightMarginComboBox.Text, 80);
EditorFont := EditorFontComboBox.Text;
EditorFontHeight := StrToIntDef(EditorFontHeightComboBox.Text, EditorFontHeight);
EditorFontSize := EditorFontSizeSpinEdit.Value;
ExtraCharSpacing := StrToIntDef(ExtraCharSpacingComboBox.Text, ExtraCharSpacing);
ExtraLineSpacing := StrToIntDef(ExtraLineSpacingComboBox.Text, ExtraLineSpacing);
DisableAntialiasing := DisableAntialiasingCheckBox.Checked;

View File

@ -1427,7 +1427,7 @@ resourcestring
dlgGutterColor = 'Gutter Color';
dlgEditorFont = 'Editor font';
dlgDefaultEditorFont='Default editor font';
dlgEditorFontHeight = 'Editor font height';
dlgEditorFontSize = 'Editor font size';
dlgExtraCharSpacing = 'Extra char spacing';
dlgExtraLineSpacing = 'Extra line spacing';
dlgDisableAntialiasing = 'Disable anti-aliasing';

View File

@ -1728,7 +1728,7 @@ begin
if (Editor<>nil) then
Font := Editor.Font
else begin
Font.Height:=EditorOpts.EditorFontHeight; // set Height before name for XLFD !
Font.Size:=EditorOpts.EditorFontSize; // set Size before name for XLFD !
Font.Name:=EditorOpts.EditorFont;
end;
Font.Style:=[];
@ -1763,7 +1763,7 @@ begin
if (Editor<>nil) then
Font:=Editor.Font
else begin
Font.Height:=EditorOpts.EditorFontHeight; // set Height before name of XLFD !
Font.Size:=EditorOpts.EditorFontSize; // set Size before name of XLFD !
Font.Name:=EditorOpts.EditorFont;
end;
Font.Style:=[];