Skip to content

Commit

Permalink
Fixed out of memory issue with enormous EPS files (generated by print…
Browse files Browse the repository at this point in the history
…() with OpenGL renderer), related to issue #39
  • Loading branch information
altmany committed Mar 26, 2015
1 parent 973cf6e commit 89bd03d
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions fix_lines.m
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 89bd03d

Please sign in to comment.