Skip to content

Commit 89bd03d

Browse files
committed
Fixed out of memory issue with enormous EPS files (generated by print() with OpenGL renderer), related to issue altmany#39
1 parent 973cf6e commit 89bd03d

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

fix_lines.m

+7-6
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
% opened.
3939

4040
% 01/03/15: Issue #20: warn users if using this function in HG2 (R2014b+)
41+
% 27/03/15: Fixed out of memory issue with enormous EPS files (generated by print() with OpenGL renderer), related to issue #39
4142

4243
function fstrm = fix_lines(fstrm, fname2)
4344

@@ -120,11 +121,6 @@
120121
end
121122
end
122123

123-
% Isolate line style definition section
124-
first_sec = strfind(fstrm, '% line types:');
125-
[second_sec, remaining] = strtok(fstrm(first_sec+1:end), '/');
126-
[remaining, remaining] = strtok(remaining, '%');
127-
128124
% Define the new styles, including the new GR format
129125
% Dot and dash lengths have two parts: a constant amount plus a line width
130126
% variable amount. The constant amount comes after dpi2point, and the
@@ -141,7 +137,12 @@
141137
'/GR { [0 dpi2point mul 4 dpi2point mul] 0 setdash 1 setlinecap } bdef'}; % Grid lines - dot spacing remains constant
142138

143139
% Construct the output
144-
fstrm = [fstrm(1:first_sec) second_sec sprintf('%s\r', new_style{:}) remaining];
140+
% This is the original (memory-intensive) code:
141+
%first_sec = strfind(fstrm, '% line types:'); % Isolate line style definition section
142+
%[second_sec, remaining] = strtok(fstrm(first_sec+1:end), '/');
143+
%[remaining, remaining] = strtok(remaining, '%');
144+
%fstrm = [fstrm(1:first_sec) second_sec sprintf('%s\r', new_style{:}) remaining];
145+
fstrm = regexprep(fstrm,'(% line types:.+?)/.+?%',['$1',sprintf('%s\r',new_style{:}),'%']);
145146

146147
% Write the output file
147148
if nargout == 0 || nargin > 1

0 commit comments

Comments
 (0)