diff --git a/ChangeLog b/ChangeLog index 34edc4d..620234d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -4,6 +4,12 @@ * Modules/Editors/ProjectCenter/SyntaxHighlighter.m Add setters for fonts. + * Modules/Editors/ProjectCenter/PCEditorView.h + * Modules/Editors/ProjectCenter/PCEditorView.m + Separate font accessors in to class and instance methods. + Do not use preferences in class methods, since they are outside the + protocol. + 2020-09-08 Riccardo Mottola * Framework/PCProjectLauncher.m diff --git a/Modules/Editors/ProjectCenter/PCEditorView.h b/Modules/Editors/ProjectCenter/PCEditorView.h index 19617f5..78131a1 100644 --- a/Modules/Editors/ProjectCenter/PCEditorView.h +++ b/Modules/Editors/ProjectCenter/PCEditorView.h @@ -42,6 +42,12 @@ + (NSFont *)defaultEditorItalicFont; + (NSFont *)defaultEditorBoldItalicFont; +- (NSFont *)editorFont; +- (NSFont *)editorBoldFont; +- (NSFont *)editorItalicFont; +- (NSFont *)editorBoldItalicFont; + + - (void)setEditor:(NSObject *)anEditor; - (void)createSyntaxHighlighterForFileType:(NSString *)fileType; diff --git a/Modules/Editors/ProjectCenter/PCEditorView.m b/Modules/Editors/ProjectCenter/PCEditorView.m index 5f3586e..8a6b642 100644 --- a/Modules/Editors/ProjectCenter/PCEditorView.m +++ b/Modules/Editors/ProjectCenter/PCEditorView.m @@ -40,11 +40,12 @@ #import +#import + #import "PCEditor.h" #import "SyntaxHighlighter.h" #import "LineJumper.h" #import "Modules/Preferences/EditorFSC/PCEditorFSCPrefs.h" -#import "PCPrefController.h" /** * Computes the indenting offset of the last line before the passed @@ -360,18 +361,9 @@ static int ComputeIndentingOffset(NSString * string, unsigned int start) + (NSFont *)defaultEditorFont { - PCPrefController *prefs = [PCPrefController sharedPCPreferences]; - NSString *fontName; - CGFloat fontSize; NSFont *font = nil; - fontName = [prefs stringForKey:EditorTextFont]; - fontSize = [prefs floatForKey:EditorTextFontSize]; - - font = [NSFont fontWithName:fontName size:fontSize]; - if (font == nil) - font = [NSFont userFixedPitchFontOfSize:0]; - + font = [NSFont userFixedPitchFontOfSize:0]; return font; } @@ -400,6 +392,50 @@ static int ComputeIndentingOffset(NSString * string, unsigned int start) NSItalicFontMask]; } +- (NSFont *)editorFont +{ + id prefs; + NSString *fontName; + CGFloat fontSize; + NSFont *font = nil; + + prefs = [[[editor editorManager] projectManager] prefController]; + + fontName = [prefs stringForKey:EditorTextFont]; + fontSize = [prefs floatForKey:EditorTextFontSize]; + + font = [NSFont fontWithName:fontName size:fontSize]; + if (font == nil) + font = [NSFont userFixedPitchFontOfSize:0]; + + return font; +} + +- (NSFont *)editorBoldFont +{ + NSFont *font = [self editorFont]; + + return [[NSFontManager sharedFontManager] convertFont:font + toHaveTrait:NSBoldFontMask]; +} + +- (NSFont *)editorItalicFont +{ + NSFont *font = [self editorFont]; + + return [[NSFontManager sharedFontManager] convertFont:font + toHaveTrait:NSItalicFontMask]; +} + +- (NSFont *)editorBoldItalicFont +{ + NSFont *font = [self editorFont]; + + return [[NSFontManager sharedFontManager] convertFont:font + toHaveTrait:NSBoldFontMask | + NSItalicFontMask]; +} + // --- - (BOOL)becomeFirstResponder { @@ -475,6 +511,10 @@ static int ComputeIndentingOffset(NSString * string, unsigned int start) [[[SyntaxHighlighter alloc] initWithFileType:fileType textStorage:[self textStorage]] autorelease]); + [highlighter setNormalFont: [self editorFont]]; + [highlighter setBoldFont: [self editorBoldFont]]; + [highlighter setItalicFont: [self editorItalicFont]]; + [highlighter setBoldItalicFont: [self editorBoldItalicFont]]; } - (void)insertText:text