Skip to content

Commit 8e811c1

Browse files
committed
(3.45) Display the builtin error message when uifigure cannot be exported (issue #387); fixed contour labels with non-default FontName incorrectly exported as Courier (issue #388)
1 parent 8f0db8a commit 8e811c1

File tree

2 files changed

+33
-6
lines changed

2 files changed

+33
-6
lines changed

export_fig.m

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@
8181
% 2) For bitmap formats, only opengl correctly renders transparent patches
8282
% 3) For bitmap formats, only painters correctly scales line dash and dot
8383
% lengths when magnifying or anti-aliasing
84-
% 4) Fonts may be substitued with Courier when using painters
84+
% 4) Fonts may be substituted with Courier when using painters
8585
%
8686
% When exporting to vector format (PDF & EPS) and bitmap format using the
8787
% painters renderer, this function requires that ghostscript is installed
@@ -201,7 +201,7 @@
201201
% done in vector formats (only): 11 standard Matlab fonts are
202202
% replaced by the original figure fonts. This option prevents this.
203203
% -font_space <char> - option to set a spacer character for font-names that
204-
% contain spaces, used by EPS/PDF. Default: ''
204+
% contain spaces, used by EPS/PDF. Default: '' (i.e. no space char)
205205
% -linecaps - option to create rounded line-caps (vector formats only).
206206
% -noinvert - option to avoid setting figure's InvertHardcopy property to
207207
% 'off' during output (this solves some problems of empty outputs).
@@ -391,6 +391,7 @@
391391
% 05/12/23: (3.42) Fixed unintended cropping of colorbar title in PDF export with -transparent (issues #382, #383)
392392
% 07/12/23: (3.43) Fixed unintended modification of colorbar in bitmap export (issue #385)
393393
% 21/02/24: (3.44) Fixed: text objects with normalized units were not exported in some cases (issue #373); added check for invalid ghostscript installation (issue #365)
394+
% 02/05/24: (3.45) Display the builtin error message when uifigure cannot be exported (issue #387); fixed contour labels with non-default FontName incorrectly exported as Courier (issue #388)
394395
%}
395396

396397
if nargout
@@ -428,7 +429,7 @@
428429
[fig, options] = parse_args(nargout, fig, argNames, varargin{:});
429430

430431
% Check for newer version and exportgraphics/copygraphics compatibility
431-
currentVersion = 3.44;
432+
currentVersion = 3.45;
432433
if options.version % export_fig's version requested - return it and bail out
433434
imageData = currentVersion;
434435
return
@@ -481,9 +482,10 @@
481482
try
482483
hChildren = allchild(hFig); %=uifig.Children;
483484
copyobj(hChildren,hNewFig);
484-
catch
485+
catch e
485486
if ~options.silent
486-
warning('export_fig:uifigure:controls', 'Some uifigure controls cannot be exported by export_fig and will not appear in the generated output.');
487+
errMsg = 'Some uifigure controls cannot be exported by export_fig and will not appear in the generated output.';
488+
warning('export_fig:uifigure:controls','%s\n%s',errMsg,e.message); %issue #387
487489
end
488490
end
489491
try fig.UserData = oldUserData; catch, end % restore axes UserData, if modified above

print2eps.m

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ function print2eps(name, fig, export_options, varargin)
115115
% 16/03/22: Fixed occasional empty files due to excessive cropping (issues #350, #351)
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)
118+
% 02/05/24: Fixed contour labels with non-default FontName incorrectly exported as Courier (issue #388)
118119
%}
119120

120121
options = {'-loose'};
@@ -526,7 +527,6 @@ function print2eps(name, fig, export_options, varargin)
526527
% 1b. Fix issue #239: black title meshes with temporary black background figure bgcolor, causing bad cropping
527528
hTitles = [];
528529
if isequal(get(fig,'Color'),'none')
529-
hAxes = findall(fig,'type','axes');
530530
for idx = 1 : numel(hAxes)
531531
hAx = hAxes(idx);
532532
try
@@ -590,13 +590,38 @@ function print2eps(name, fig, export_options, varargin)
590590

591591
% If user requested a regexprep replacement of string(s), do this now (issue #324)
592592
if isstruct(export_options) && isfield(export_options,'regexprep') && ~isempty(export_options.regexprep) %issue #338
593+
useRegexprepOption = true;
593594
try
594595
oldStrOrRegexp = export_options.regexprep{1};
595596
newStrOrRegexp = export_options.regexprep{2};
596597
fstrm = regexprep(fstrm, oldStrOrRegexp, newStrOrRegexp);
597598
catch err
598599
warning('YMA:export_fig:regexprep', 'Error parsing regexprep: %s', err.message);
599600
end
601+
else
602+
useRegexprepOption = false;
603+
end
604+
605+
% Fix issue #388: contour labels with non-default FontName incorrectly exported as Courier
606+
try
607+
fontNames = {};
608+
for idx = 1 : numel(hAxes)
609+
try hPlots = allchild(hAxes(idx)); catch, hPlots = []; end
610+
for idx2 = 1 : numel(hPlots)
611+
try hLabels = hPlots(idx2).TextPrims; catch, hLabels = []; end
612+
for idx3 = 1 : numel(hLabels)
613+
try fontNames{end+1} = hLabels(idx3).Font.Name; catch, end %#ok<AGROW>
614+
end
615+
end
616+
end
617+
fontNames = setdiff(fontNames,'Helvetica'); %Helvetica actually works ok
618+
if numel(fontNames) > 1 && ~useRegexprepOption
619+
warning('YMA:export_fig:countourFonts', 'export_fig cannot fix multiple contour label fonts; try using the -regexprep option to convert /Courier into %s etc.',fontNames{1});
620+
elseif numel(fontNames) == 1
621+
fstrm = regexprep(fstrm, '\n/Courier (\d+ F\nGS\n)', ['\n/' fontNames{1} ' $1']);
622+
end
623+
catch
624+
% never mind - probably no matching contour labels
600625
end
601626

602627
% Write out the fixed eps file

0 commit comments

Comments
 (0)