Skip to content

Commit 5641fd8

Browse files
committed
(3.42) Fixed unintended cropping of colorbar title in PDF export with -transparent (issue #382)
1 parent a665328 commit 5641fd8

File tree

1 file changed

+24
-15
lines changed

1 file changed

+24
-15
lines changed

export_fig.m

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,7 @@
388388
% 30/05/23: (3.39) Fixed exported bgcolor of uifigures or figures in Live Scripts (issue #377)
389389
% 06/07/23: (3.40) For Tiff compression, use AdobeDeflate codec (if available) instead of Deflate (issue #379)
390390
% 29/11/23: (3.41) Fixed error when no filename is specified nor available in the exported figure (issue #381)
391+
% 05/12/23: (3.42) Fixed unintended cropping of colorbar title in PDF export with -transparent (issue #382)
391392
%}
392393

393394
if nargout
@@ -425,7 +426,7 @@
425426
[fig, options] = parse_args(nargout, fig, argNames, varargin{:});
426427

427428
% Check for newer version and exportgraphics/copygraphics compatibility
428-
currentVersion = 3.41;
429+
currentVersion = 3.42;
429430
if options.version % export_fig's version requested - return it and bail out
430431
imageData = currentVersion;
431432
return
@@ -1089,19 +1090,10 @@
10891090

10901091
% Correct black titles to off-black
10911092
% https://www.mathworks.com/matlabcentral/answers/567027-matlab-export_fig-crops-title
1092-
try
1093-
hTitle = get(hAxes, 'Title');
1094-
for idx = numel(hTitle) : -1 : 1
1095-
color = get(hTitle,'Color');
1096-
if isequal(color,[0,0,0]) || isequal(color,'k')
1097-
set(hTitle(idx), 'Color', [0,0,0.01]); %off-black
1098-
else
1099-
hTitle(idx) = []; % remove from list
1100-
end
1101-
end
1102-
catch
1103-
hTitle = [];
1104-
end
1093+
hTitle = fixBlackText(hAxes,'Title');
1094+
hColorBars = unique([findall(fig,'tag','Colorbar'), ...
1095+
getappdata(hAxes,'LayoutPeers')]);
1096+
hCbTxt = fixBlackText(hColorBars,'Title'); % issue #382
11051097
end
11061098
% Generate an eps
11071099
print2eps(tmp_nam, fig, options, printArgs{:}); %winopen(tmp_nam)
@@ -1110,14 +1102,15 @@
11101102
if options.transparent %&& ~isequal(get(fig, 'Color'), 'none')
11111103
eps_remove_background(tmp_nam, 1 + using_hg2(fig));
11121104

1113-
% Revert the black axes colors
1105+
% Revert the black axles/titles colors
11141106
set(hXs, 'XColor', [0,0,0]);
11151107
set(hYs, 'YColor', [0,0,0]);
11161108
set(hZs, 'ZColor', [0,0,0]);
11171109
set(hXrs, 'Color', [0,0,0]);
11181110
set(hYrs, 'Color', [0,0,0]);
11191111
set(hZrs, 'Color', [0,0,0]);
11201112
set(hTitle,'Color',[0,0,0]);
1113+
set(hCbTxt,'Color',[0,0,0]);
11211114
end
11221115
%}
11231116
% Restore the figure's previous background color (if modified)
@@ -2441,6 +2434,22 @@ function change_rgb_to_cmyk(fname) % convert RGB => CMYK within an EPS file
24412434
set(hBlackAxles, axleName, [0,0,0.01]); % off-black
24422435
end
24432436

2437+
function hText = fixBlackText(hObject, propName)
2438+
try
2439+
hText = get(hObject, propName);
2440+
for idx = numel(hText) : -1 : 1
2441+
color = get(hText,'Color');
2442+
if isequal(color,[0,0,0]) || isequal(color,'k')
2443+
set(hText(idx), 'Color', [0,0,0.01]); %off-black
2444+
else
2445+
hText(idx) = []; % remove from list
2446+
end
2447+
end
2448+
catch
2449+
hText = [];
2450+
end
2451+
end
2452+
24442453
% Issue #269: format-specific options
24452454
function [optionsCells, bitDepth] = getFormatOptions(options, formatName)
24462455
bitDepth = [];

0 commit comments

Comments
 (0)