From 8e811c1c93502abd88baf6b9dcbbab77bda9747c Mon Sep 17 00:00:00 2001 From: Yair Altman Date: Thu, 2 May 2024 13:27:19 +0300 Subject: [PATCH] (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) --- export_fig.m | 12 +++++++----- print2eps.m | 27 ++++++++++++++++++++++++++- 2 files changed, 33 insertions(+), 6 deletions(-) diff --git a/export_fig.m b/export_fig.m index 6eb46ea..f6d9a00 100644 --- a/export_fig.m +++ b/export_fig.m @@ -81,7 +81,7 @@ % 2) For bitmap formats, only opengl correctly renders transparent patches % 3) For bitmap formats, only painters correctly scales line dash and dot % lengths when magnifying or anti-aliasing -% 4) Fonts may be substitued with Courier when using painters +% 4) Fonts may be substituted with Courier when using painters % % When exporting to vector format (PDF & EPS) and bitmap format using the % painters renderer, this function requires that ghostscript is installed @@ -201,7 +201,7 @@ % done in vector formats (only): 11 standard Matlab fonts are % replaced by the original figure fonts. This option prevents this. % -font_space - option to set a spacer character for font-names that -% contain spaces, used by EPS/PDF. Default: '' +% contain spaces, used by EPS/PDF. Default: '' (i.e. no space char) % -linecaps - option to create rounded line-caps (vector formats only). % -noinvert - option to avoid setting figure's InvertHardcopy property to % 'off' during output (this solves some problems of empty outputs). @@ -391,6 +391,7 @@ % 05/12/23: (3.42) Fixed unintended cropping of colorbar title in PDF export with -transparent (issues #382, #383) % 07/12/23: (3.43) Fixed unintended modification of colorbar in bitmap export (issue #385) % 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) +% 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) %} if nargout @@ -428,7 +429,7 @@ [fig, options] = parse_args(nargout, fig, argNames, varargin{:}); % Check for newer version and exportgraphics/copygraphics compatibility - currentVersion = 3.44; + currentVersion = 3.45; if options.version % export_fig's version requested - return it and bail out imageData = currentVersion; return @@ -481,9 +482,10 @@ try hChildren = allchild(hFig); %=uifig.Children; copyobj(hChildren,hNewFig); - catch + catch e if ~options.silent - warning('export_fig:uifigure:controls', 'Some uifigure controls cannot be exported by export_fig and will not appear in the generated output.'); + errMsg = 'Some uifigure controls cannot be exported by export_fig and will not appear in the generated output.'; + warning('export_fig:uifigure:controls','%s\n%s',errMsg,e.message); %issue #387 end end try fig.UserData = oldUserData; catch, end % restore axes UserData, if modified above diff --git a/print2eps.m b/print2eps.m index 5c479fb..ef2f880 100644 --- a/print2eps.m +++ b/print2eps.m @@ -115,6 +115,7 @@ function print2eps(name, fig, export_options, varargin) % 16/03/22: Fixed occasional empty files due to excessive cropping (issues #350, #351) % 15/05/22: Fixed EPS bounding box (issue #356) % 13/04/23: Reduced (hopefully fixed) unintended EPS/PDF image cropping (issues #97, #318) +% 02/05/24: Fixed contour labels with non-default FontName incorrectly exported as Courier (issue #388) %} options = {'-loose'}; @@ -526,7 +527,6 @@ function print2eps(name, fig, export_options, varargin) % 1b. Fix issue #239: black title meshes with temporary black background figure bgcolor, causing bad cropping hTitles = []; if isequal(get(fig,'Color'),'none') - hAxes = findall(fig,'type','axes'); for idx = 1 : numel(hAxes) hAx = hAxes(idx); try @@ -590,6 +590,7 @@ function print2eps(name, fig, export_options, varargin) % If user requested a regexprep replacement of string(s), do this now (issue #324) if isstruct(export_options) && isfield(export_options,'regexprep') && ~isempty(export_options.regexprep) %issue #338 + useRegexprepOption = true; try oldStrOrRegexp = export_options.regexprep{1}; newStrOrRegexp = export_options.regexprep{2}; @@ -597,6 +598,30 @@ function print2eps(name, fig, export_options, varargin) catch err warning('YMA:export_fig:regexprep', 'Error parsing regexprep: %s', err.message); end + else + useRegexprepOption = false; + end + + % Fix issue #388: contour labels with non-default FontName incorrectly exported as Courier + try + fontNames = {}; + for idx = 1 : numel(hAxes) + try hPlots = allchild(hAxes(idx)); catch, hPlots = []; end + for idx2 = 1 : numel(hPlots) + try hLabels = hPlots(idx2).TextPrims; catch, hLabels = []; end + for idx3 = 1 : numel(hLabels) + try fontNames{end+1} = hLabels(idx3).Font.Name; catch, end %#ok + end + end + end + fontNames = setdiff(fontNames,'Helvetica'); %Helvetica actually works ok + if numel(fontNames) > 1 && ~useRegexprepOption + 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}); + elseif numel(fontNames) == 1 + fstrm = regexprep(fstrm, '\n/Courier (\d+ F\nGS\n)', ['\n/' fontNames{1} ' $1']); + end + catch + % never mind - probably no matching contour labels end % Write out the fixed eps file