Disable FontSmoothing in Legend text objects

1 view (last 30 days)
ParkerLewis
ParkerLewis on 25 Jan 2019
Edited: Brian C Coe on 31 May 2019
I am on Matlab R2018a. I want to disable FontSmoothing for text legend entries.
  • Setting the FontSmoothing property default vaue to 'off' for text objects doesn't seem to apply to text objects created by a legend ;
  • Using the old syntax [lgd,object_h]=legend(...) is horrible under recent releases : for some reason it leads to a drawnow inside the legend call, thus if I then want to edit the relevant properties of some of object_h (here to set their FontSmoothing to 'off'), there will be two draws, leading to a less responsive call and ugly behavior (two screen refreshes instead of just one). Although this behavior makes it unacceptable to me, I can though use these handles to then set their FontSmoothing property to 'off' and it works.
  • Not using the old syntax but only the new one lgd=legend(...) thus seems to be the only recourse. I seem to be able to find the text objects by accessing lgd.EntryContainer.NodeChildren(1).Label (1 for the first text object, 2 for the second one, etc). Problem is, property setting seems iffy at best :
set(lgd.EntryContainer.NodeChildren(1).Label,'FontSmoothing','off') doesn't change anything.
set(lgd.EntryContainer.NodeChildren(1).Label,'FontSize',somevalue) doesn't change anything either.
set(lgd.EntryContainer.NodeChildren(1).Label,'String','sometext') does work though.
Anyone have any idea how to proceed ?

Answers (1)

Brian C Coe
Brian C Coe on 30 May 2019
Edited: Brian C Coe on 31 May 2019
call 'legend2' instead of 'legend'... (-sigh-)
function [leg,labelhandles,outH,outM] = legend2(varargin)
% function [leg,labelhandles,outH,outM] = legend2(varargin)
% quite possibly the stupidest code i ever had to hack-up to get around a matlab stupidity.
% bcoe
if isempty(varargin)
help(mfilename)
return
end
[leg,labelhandles,outH,outM] = legend(varargin{:});
for ii=1:length(leg.ItemText)
leg.ItemText(ii).FontSmoothing='off';
% leg.ItemTokens(ii).graphicssmoothing='off'; %still trying to kill linesmoothing
end

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!