Skip to content

Commit

Permalink
[Fix #370] added ensureLineEndings workaround
Browse files Browse the repository at this point in the history
Signed-off-by: oleg komarov <o.komarov11@imperial.ac.uk>
  • Loading branch information
oleg komarov committed Oct 22, 2014
1 parent ef4ee06 commit abef196
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion test/matlab2tikz_acidtest.m
Expand Up @@ -143,7 +143,8 @@ function matlab2tikz_acidtest(varargin)
% MATLAB does not generate properly cropped PDF files.
% So, we generate EPS files that are converted later on.
print(gcf, '-depsc2', eps_file);

ensureLineEndings(eps_file);

case 'Octave'
% In Octave, figures are properly cropped when using print().
print(pdf_file, '-dpdf', '-S415,311', '-r150');
Expand Down Expand Up @@ -399,3 +400,20 @@ function disp_error_message(env, msg)
onOff = 'off';
end
end
% =========================================================================
function ensureLineEndings(filename)
% Read in one line and test the ending
fid = fopen(filename,'r+');
testline = fgets(fid);
if ispc && ~strcmpi(testline(end-1:end), sprintf('\r\n'))
% Rewind, read the whole
fseek(fid,0,'bof');
str = fread(fid,'*char')';

% Replace, overwrite and close
str = regexprep(str, '\n|\r','\r\n');
fseek(fid,0,'bof');
fprintf(fid,'%s',str);
fclose(fid);
end
end

3 comments on commit abef196

@nschloe
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need a little more in-code documentation on this. One line, perhaps with a link, will suffice.

@okomarov
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean a reference to the bug/odd behaviour of R2014b?

I am waiting for TMW to close the support request. In case they create a bug report, we can link to that, otherwise we can link to my stackoverflow post or the Answers one.

@nschloe
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, or comment of some sort, like the discussion on GitHub.

Please sign in to comment.