KerMor  0.9
Model order reduction for nonlinear dynamical systems and nonlinear approximation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
print2eps.m
Go to the documentation of this file.
1 
2 
3 /* (Autoinserted by mtoc++)
4  * This source code has been filtered by the mtoc++ executable,
5  * which generates code that can be processed by the doxygen documentation tool.
6  *
7  * On the other hand, it can neither be interpreted by MATLAB, nor can it be compiled with a C++ compiler.
8  * Except for the comments, the function bodies of your M-file functions are untouched.
9  * Consequently, the FILTER_SOURCE_FILES doxygen switch (default in our Doxyfile.template) will produce
10  * attached source files that are highly readable by humans.
11  *
12  * Additionally, links in the doxygen generated documentation to the source code of functions and class members refer to
13  * the correct locations in the source code browser.
14  * However, the line numbers most likely do not correspond to the line numbers in the original MATLAB source files.
15  */
16 
17 function print2eps(name,fig,varargin) {
18 options = [" -depsc2 "];
19 if nargin < 2
20  fig = gcf;
21 elseif nargin > 2
22  options = [options varargin];
23 end
24 /* Construct the filename */
25 if numel(name) < 5 || ~strcmpi(name(end-3:end), " .eps ")
26  name = [name " .eps "]; /* Add the missing extension */
27 
28 end
29 /* Find all the used fonts in the figure */
30 font_handles = findall(fig, " -property ", " FontName ");
31 fonts = get(font_handles, " FontName ");
32 if ~iscell(fonts)
33  fonts = [fonts];
34 end
35 /* Map supported font aliases onto the correct name */
36 fontsl = lower(fonts);
37 for a = 1:numel(fonts)
38  f = fontsl[a];
39  f(f==" ") = [];
40  switch f
41  case [" times ", " timesnewroman ", " times-roman "]
42  fontsl[a] = " times-roman ";
43  case [" arial ", " helvetica "]
44  fontsl[a] = " helvetica ";
45  case [" newcenturyschoolbook ", " newcenturyschlbk "]
46  fontsl[a] = " newcenturyschlbk ";
47  otherwise
48  end
49 end
50 fontslu = unique(fontsl);
51 /* Determine the font swap table */
52 matlab_fonts = [" Helvetica ", " Times-Roman ", " Palatino ", " Bookman ", " Helvetica-Narrow ", " Symbol ", ...
53  " AvantGarde ", " NewCenturySchlbk ", " Courier ", " ZapfChancery ", " ZapfDingbats "];
54 matlab_fontsl = lower(matlab_fonts);
55 require_swap = find(~ismember(fontslu, matlab_fontsl));
56 unused_fonts = find(~ismember(matlab_fontsl, fontslu));
57 font_swap = cell(3, min(numel(require_swap), numel(unused_fonts)));
58 fonts_new = fonts;
59 for a = 1:size(font_swap, 2)
60  font_swap[1,a] = find(strcmp(fontslu[require_swap(a)], fontsl));
61  font_swap[2,a] = matlab_fonts[unused_fonts(a)];
62  font_swap[3,a] = fonts[font_swap[1,end](1)];
63  fonts_new(font_swap[1,a]) = [font_swap[2,a]];
64 end
65 /* Swap the fonts */
66 if ~isempty(font_swap)
67  fonts_size = get(font_handles, " FontSize ");
68  if iscell(fonts_size)
69  fonts_size = cell2mat(fonts_size);
70  end
71  M = false(size(font_handles));
72  /* Loop because some changes may not stick first time, due to listeners */
73  c = 0;
74  update = zeros(1000, 1);
75  for b = 1:10 /* Limit number of loops to avoid infinite loop case */
76 
77  for a = 1:numel(M)
78  M(a) = ~isequal(get(font_handles(a), " FontName "), fonts_new[a]) || ~isequal(get(font_handles(a), " FontSize "), fonts_size(a));
79  if M(a)
80  set(font_handles(a), " FontName ", fonts_new[a], " FontSize ", fonts_size(a));
81  c = c + 1;
82  update(c) = a;
83  end
84  end
85  if ~any(M)
86  break;
87  end
88  end
89  /* Compute the order to revert fonts later, without the need of a loop */
90  [update, M] = unique(update(1:c));
91  [M, M] = sort(M);
92  update = reshape(update(M), 1, []);
93 end
94 /* Set paper size */
95 old_pos_mode = get(fig, " PaperPositionMode ");
96 old_orientation = get(fig, " PaperOrientation ");
97 set(fig, " PaperPositionMode ", " auto ", " PaperOrientation ", " portrait ");
98 /* MATLAB bug fix - black and white text can come out inverted sometimes
99  * Find the white and black text */
100 white_text_handles = findobj(fig, " Type ", " text ");
101 M = get(white_text_handles, " Color ");
102 if iscell(M)
103  M = cell2mat(M);
104 end
105 M = sum(M, 2);
106 black_text_handles = white_text_handles(M == 0);
107 white_text_handles = white_text_handles(M == 3);
108 /* Set the font colors slightly off their correct values */
109 set(black_text_handles, " Color ", [0 0 0] + eps);
110 set(white_text_handles, " Color ", [1 1 1] - eps);
111 /* Print to eps file */
112 print(fig, options[:], name);
113 /* Reset the font colors */
114 set(black_text_handles, " Color ", [0 0 0]);
115 set(white_text_handles, " Color ", [1 1 1]);
116 /* Reset paper size */
117 set(fig, " PaperPositionMode ", old_pos_mode, " PaperOrientation ", old_orientation);
118 /* Correct the fonts */
119 if ~isempty(font_swap)
120  /* Reset the font names in the figure */
121  for a = update
122  set(font_handles(a), " FontName ", fonts[a], " FontSize ", fonts_size(a));
123  end
124  /* Replace the font names in the eps file */
125  font_swap = font_swap(2:3,:);
126  try
127  swap_fonts(name, font_swap[:]);
128  catch
129  warning(" swap_fonts() failed. This is usually because the figure contains a large number of patch objects. Consider exporting to a bitmap format in this case. ");
130  return
131  end
132 end
133 /* Fix the line styles */
134 try
135  fix_lines(name);
136 catch
137  warning(" fix_lines() failed. This is usually because the figure contains a large number of patch objects. Consider exporting to a bitmap format in this case. ");
138 end
139 return
140 
141 }
142 
144 fh = fopen(fname, " r ");
145 if fh == -1
146  error(" File %s not found. ", fname);
147 end
148 try
149  fstrm = fread(fh, " *char ")^t;
150 catch ex
151  fclose(fh);
152  rethrow(ex);
153 end
154 fclose(fh);
155 
156 /* Replace the font names */
157 for a = 1:2:numel(varargin)
158  fstrm = regexprep(fstrm, [varargin[a] " -?[a-zA-Z]*> "], varargin[a+1](~isspace(varargin[a+1])));
159 end
160 
161 /* Write out the updated file */
162 fh = fopen(fname, " w ");
163 if fh == -1
164  error(" Unable to open %s for writing. ", fname2);
165 end
166 try
167  fwrite(fh, fstrm, " char*1 ");
168 catch ex
169  fclose(fh);
170  rethrow(ex);
171 end
172 fclose(fh);
173 return
174 
175 }
176 
function fix_lines(fname, fname2)
FIX_LINES Improves the line style of eps files generated by print.
Definition: fix_lines.m:17
A MatLab cell array or matrix.
function print2eps(name, fig, varargin)
Definition: print2eps.m:17
A variable number of input arguments.
function print2eps>swap_fonts(fname, varargin)
Definition: print2eps.m:143