Skip to content

Commit 2e59c7b

Browse files
committed
(3.49) Fixed(?) -transparency in PDF/EPS files (issue #401); override Matlab's default Title & Creator meta-data (issue #402)
1 parent 35bab1f commit 2e59c7b

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

export_fig.m

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,7 @@
410410
% 09/05/24: (3.46) Added -xkcd option (thanks @slayton); added .fig input and output format (previously undocumented & buggy); redirect .tex output to matlab2tikz utility
411411
% 05/11/24: (3.47) Fixed -transparency in case the default bgcolor is already used in the figure (issue #398); enabled specifying non-default transparency color via -transparency parameter; suppress warnings about setting figure position; multiple -xkcd fixes
412412
% 06/03/25: (3.48) Fixed -transparency color artifacts, set default bgcolor tolerance of +-0.1 (issue #400)
413+
% 31/03/25: (3.49) Fixed(?) -transparency in PDF/EPS files (issue #401); override Matlab's default Title & Creator meta-data (issue #402)
413414
%}
414415

415416
if nargout
@@ -447,7 +448,7 @@
447448
[fig, options] = parse_args(nargout, fig, argNames, varargin{:});
448449

449450
% Check for newer version and exportgraphics/copygraphics compatibility
450-
currentVersion = 3.48;
451+
currentVersion = 3.49;
451452
if options.version % export_fig's version requested - return it and bail out
452453
imageData = currentVersion;
453454
return
@@ -1049,6 +1050,9 @@
10491050
elseif ~options.png && ~options.tif && ~options.silent % issue #168
10501051
warning('export_fig:transparency', '%s ScreenCapture utility on the Matlab File Exchange: http://bit.ly/1QFrBip', msg);
10511052
end
1053+
elseif options.transparent %issue #401
1054+
% https://www.mathworks.com/matlabcentral/answers/452533-using-painters-saving-to-eps-does-not-give-transparency
1055+
hasTransparency = true; % bypass the warning message above
10521056
elseif ~isempty(hImages)
10531057
% Fix for issue #230: use OpenGL renderer when exported image contains transparency
10541058
for idx = 1 : numel(hImages)

print2eps.m

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ function print2eps(name, fig, export_options, varargin)
116116
% 15/05/22: Fixed EPS bounding box (issue #356)
117117
% 13/04/23: Reduced (hopefully fixed) unintended EPS/PDF image cropping (issues #97, #318)
118118
% 02/05/24: Fixed contour labels with non-default FontName incorrectly exported as Courier (issue #388)
119+
% 11/05/25: Override Matlab's default Title & Creator meta-data (issue #402)
119120
%}
120121

121122
options = {'-loose'};
@@ -588,6 +589,37 @@ function print2eps(name, fig, export_options, varargin)
588589
fstrm = regexprep(fstrm, '\n([-\d.]+ [-\d.]+) ([-\d.]+ [-\d.]+) ([-\d.]+ [-\d.]+) 3 MP\nPP\n\3 \1 \2 3 MP\nPP\n','\n$1 $2 $3 0 0 4 MP\nPP\n');
589590
fstrm = regexprep(fstrm, '\n([-\d.]+ [-\d.]+) ([-\d.]+ [-\d.]+) ([-\d.]+ [-\d.]+) 3 MP\nPP\n\3 \2 \1 3 MP\nPP\n','\n$1 $2 $3 0 0 4 MP\nPP\n');
590591

592+
% Fix issue #402: override Matlab's default Title & Creator meta-data
593+
idx = strfind(export_options.gs_options,'/Title ');
594+
override_meta = ~isempty(idx) && (~iscell(idx) || ~isempty(idx{1}));
595+
if override_meta
596+
% Remove this meta property from the EPS so Ghostscript will override it
597+
fstrm = regexprep(fstrm, '%%Title:[^\n]*\n', '');
598+
else
599+
% Replace Matlab-created default meta property value with a usable one
600+
%%Title: C:/Users/Yair/AppData/Local/Temp/tp28b8a11e_42a7_40d4_b254_65d0af3c436f.eps
601+
title_str = get(fig,'Name');
602+
if isempty(title_str) && ~isempty(hAxes)
603+
try title_str = hAxes(1).Title.String; catch, end
604+
end
605+
fstrm = regexprep(fstrm, '(%%Title:)[^\n]*\n', ['$1 ' title_str '\n']);
606+
end
607+
608+
idx = strfind(export_options.gs_options,'/Creator ');
609+
override_meta = ~isempty(idx) && (~iscell(idx) || ~isempty(idx{1}));
610+
if override_meta
611+
% Remove this meta property from the EPS so Ghostscript will override it
612+
fstrm = regexprep(fstrm, '%%Creator:[^\n]*\n', '');
613+
else
614+
% Replace Matlab-created default meta property value with a usable one
615+
%%Creator: (MATLAB, The Mathworks, Inc. Version 9.13.0.2049777 \(R2022b\). Operating System: Windows 10)
616+
try
617+
ver_str = ['export_fig v' num2str(export_fig('-version')) ' via '];
618+
fstrm = regexprep(fstrm, '(%%Creator: *\(?)', ['$1' ver_str]);
619+
catch
620+
end
621+
end
622+
591623
% If user requested a regexprep replacement of string(s), do this now (issue #324)
592624
if isstruct(export_options) && isfield(export_options,'regexprep') && ~isempty(export_options.regexprep) %issue #338
593625
useRegexprepOption = true;

0 commit comments

Comments
 (0)