-
Notifications
You must be signed in to change notification settings - Fork 0
/
printeps.m
58 lines (51 loc) · 2.27 KB
/
printeps.m
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
function printeps(fignum, figname)
% printeps(fignum, figname)
% this is a simple function that overrides Matlab's desire to call all
% fonts 'Helvetica' in an exported .eps file. This is particularly annoying
% if you import your file into Illustrator and find that not only do you
% NOT have 'Helvetica', but that in substituting for it, your subscripts
% have moved a mile away and things otherwise just don't look 'right.'
% It is suggested that you set your default font in a
% startup file to something that you actually have on your system. For
% instance, if you purchased the Helvetica family straight from Adobe,
% set(0, 'DefaultAxesFontName', 'HelveticaLTStd-Roman');
% the whole point of this is that when you generate a figure in Matlab,
% you'd like your exported file to be as close a representation of that
% figure as possible.
% J. Aumentado
% 4/20/05
% Note: This is a global change of font in the file. That is, any text you
% add via text() and title() commands will end up in the default axes font.
% this is because there is no easy way to parse out the fonts of these
% objects in the .eps file for replacement.
%
%
% EXAMPLE:
% set(0, 'DefaultAxesFontName', 'Arial'); %replace fontname with something
% %you have
% figure(1);clf;fplot(@tanh,[-5,5]); %plot something
% printeps(1,'test'); %print the contents of figure 1
% %to test.eps.
%figfilestr = [figname '.eps'];
figfilestr = [figname]; % I like to specify .eps on my own
%eval(['print -depsc2 -f' num2str(fignum) ' ' figfilestr ';']);
print(fignum, '-depsc2', figname); % Fixed to allow spaces in filename
% now read in the file
fid = fopen(figfilestr);
ff = char(fread(fid))';
fclose(fid);
%get the actual font
figure(fignum);
actualfont = get(gca,'FontName')
%these are the only allowed fonts in MatLab and so we have to weed them out
%and replace them:
mlabfontlist = {'AvantGarde','Helvetica-Narrow','Times-Roman','Bookman',...
'NewCenturySchlbk','ZapfChancery','Courier','Palatino','ZapfDingbats',...
'Helvetica'};%,'Symbol'};
for k = 1:length(mlabfontlist)
ff = strrep(ff,mlabfontlist{k},actualfont);
end
% open the file up and overwrite it
fid = fopen(figfilestr,'w');
fprintf(fid,'%s',ff);
fclose(fid);