Filter löschen
Filter löschen

uicontrol and annotation produce different fonts despite identical settings

5 Ansichten (letzte 30 Tage)
Hi,
Can anyone explain to me why the text in the following two figures is not identical?
% create long sample string
str = string(repmat('A ',1,128));
% create first figure, filling entire screen
fig1 = figure('Units','normalized','Position', [0 0 1 1],'Toolbar','none','Resize','off');
% create texbox within that figure via UI control
ctemp = uicontrol('Style','text','Units','normalized','Position', [0 0 1 1],...
'String',str,'FontName','Arial','FontSize',12,...
'FontWeight','normal','Visible','on','HorizontalAlignment','left');
% create second figure, again filling entire screen
fig2 = figure('Units','normalized','Position', [0 0 1 1],'Toolbar','none','Resize','off');
% create texbox within that figure via annotation
temp = annotation(fig2,'textbox',[0 0 1 1],'String',str,'EdgeColor','none', ...
'FontName','Arial','FontSize',12,'FontWeight','normal','Margin',0);
In particular, despite identical settings (Arial, 12pt, normal), the "annotation" command produces a larger/bolder font compared to the "uicontrol" command. On my screen, with a 1200x1920 resolution, the text in fig1 e.g. fits in one line, but has to be broken into two lines in fig2.

Akzeptierte Antwort

Simar
Simar am 11 Okt. 2023
Bearbeitet: Simar am 11 Okt. 2023
Hi Mark,
I understand that despite using the same settings for text, the figures created using ‘uicontrol’ and ‘annotation’ are not displaying identical text. Please refer to the image attached below.
After running the code provided by you, following observations were made:
  • The difference in appearance between the text in the two figures is due to the different ways MATLAB handles uicontrol and annotation.
  • uicontrol (Figure 1) is a low-level UI component that directly uses the system's rendering for the text, which is why it looks smaller and less bold which is seen in Figure 1. This control allows for more precise control over the appearance of the text.
  • annotation is a high-level function that creates an annotation object in a figure. It uses MATLAB's rendering engine to display the text, which can cause the text to appear larger and bolder which is seen in Figure 2.
  • The 'FontSize' property in uicontrol and annotation may not correspond to the same actual size. The 'FontSize' in uicontrol is in character units, while in annotation, it is in points. Character units are based on the default uicontrol font of the system, and it varies with the specific operating system and the system preferences. Points are a standard unit of measure in the printing industry.
By manually adjusting the 'FontSize' parameter in either or both cases, it is possible to achieve a consistent appearance of the text in both scenarios.
Refer to the documentation links below to know more about uicontrol and annotation:
Hope it helps!
Best Regards
Simar
  2 Kommentare
Mark Kerssenfischer
Mark Kerssenfischer am 12 Okt. 2023
Thanks!
But I do not think your statement "By manually adjusting the 'FontSize' parameter in either or both cases, it is possible to achieve a consistent appearance of the text in both scenarios" is correct.
At least I do not get it working.
Simar
Simar am 13 Okt. 2023
Bearbeitet: Simar am 13 Okt. 2023
Yes, it was a workaround (manual adjustment) to achieve the results as close as possible in the figures. Achieving an exact match in appearance between the two would be challenging due to the differences in rendering methods used by these functions.
Please refer to image below:

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Migrate GUIDE Apps finden Sie in Help Center und File Exchange

Produkte


Version

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by