-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfont.m
More file actions
75 lines (73 loc) · 1.69 KB
/
font.m
File metadata and controls
75 lines (73 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
function font( varargin )
% Quickly changes fontsize of editor and commands. Nice for presentations
% Known not to work for mlx documents. Use ctrl-+/-
% Example usage
% >> font 16
% >> font(16) % same as above
% >> font 16 1 % 1 gives bold font
% >> font % reset to normal
% valid fontsize from 3 and up
% valid styles 0, 1, 2 for plain, bold, and italic. (string 'bold' ect.
% also ok.
% valid fonts 'Monospaced', 'SansSerif', 'Serif'
% Created by JJJ
nargin = length(varargin);
defaultText = 'Monospaced';
defaultSize = 14;
PLAIN = 0;
BOLD = 1;
ITALIC = 2;
defaultWeight = 0;
validWeights = {'plain','bold','italic'};
checkWeights = @(x) any(strcmp(x,validWeights));
validTexts = {'Monospaced', 'SansSerif','Serif'};
checkTexts = @(x) any(strcmp(x,validTexts));
if nargin == 0
weight = defaultWeight;
text = defaultText;
size = defaultSize;
com.mathworks.services.FontPrefs.setCodeFont(...
java.awt.Font(text,weight,size));
return
end
set = [];
for i = 1:nargin
arg = varargin{i};
if (isnumeric(arg) || ~isempty(str2num(arg)) )
if ~isnumeric(arg)
arg = str2num(arg);
end
if arg <= 2 && (any(set~=2) || isempty(set))
weight = arg;
set = [set,2];
else
size = arg;
set = [set,3];
end
else
if checkTexts(arg)
text = arg;
set = [set, 1];
elseif checkWeights(arg)
for i = 1:3
if strcmp(arg,validWeights{i})
weight = i-1;
set = [set,2];
end
end
end
end
end
if ~any(1==set)
text = defaultText;
end
if ~any(2==set)
weight = defaultWeight;
end
if ~any(3==set)
size = defaultSize;
end
com.mathworks.services.FontPrefs.setCodeFont(...
java.awt.Font(text,weight,size));
return
end