diff --git a/fix_lines.m b/fix_lines.m index 5160754..b160fd8 100644 --- a/fix_lines.m +++ b/fix_lines.m @@ -38,6 +38,7 @@ % opened. % 01/03/15: Issue #20: warn users if using this function in HG2 (R2014b+) +% 27/03/15: Fixed out of memory issue with enormous EPS files (generated by print() with OpenGL renderer), related to issue #39 function fstrm = fix_lines(fstrm, fname2) @@ -120,11 +121,6 @@ end end -% Isolate line style definition section -first_sec = strfind(fstrm, '% line types:'); -[second_sec, remaining] = strtok(fstrm(first_sec+1:end), '/'); -[remaining, remaining] = strtok(remaining, '%'); - % Define the new styles, including the new GR format % Dot and dash lengths have two parts: a constant amount plus a line width % variable amount. The constant amount comes after dpi2point, and the @@ -141,7 +137,12 @@ '/GR { [0 dpi2point mul 4 dpi2point mul] 0 setdash 1 setlinecap } bdef'}; % Grid lines - dot spacing remains constant % Construct the output -fstrm = [fstrm(1:first_sec) second_sec sprintf('%s\r', new_style{:}) remaining]; +% This is the original (memory-intensive) code: +%first_sec = strfind(fstrm, '% line types:'); % Isolate line style definition section +%[second_sec, remaining] = strtok(fstrm(first_sec+1:end), '/'); +%[remaining, remaining] = strtok(remaining, '%'); +%fstrm = [fstrm(1:first_sec) second_sec sprintf('%s\r', new_style{:}) remaining]; +fstrm = regexprep(fstrm,'(% line types:.+?)/.+?%',['$1',sprintf('%s\r',new_style{:}),'%']); % Write the output file if nargout == 0 || nargin > 1