Skip to content

Commit

Permalink
(3.45) Display the builtin error message when uifigure cannot be expo…
Browse files Browse the repository at this point in the history
…rted (issue #387); fixed contour labels with non-default FontName incorrectly exported as Courier (issue #388)
  • Loading branch information
altmany committed May 2, 2024
1 parent 8f0db8a commit 8e811c1
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 6 deletions.
12 changes: 7 additions & 5 deletions export_fig.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 <char> - 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).
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
27 changes: 26 additions & 1 deletion print2eps.m
Original file line number Diff line number Diff line change
Expand Up @@ -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'};
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -590,13 +590,38 @@ 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};
fstrm = regexprep(fstrm, oldStrOrRegexp, newStrOrRegexp);
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<AGROW>
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
Expand Down

0 comments on commit 8e811c1

Please sign in to comment.