Is there a way to measure interletter spacing for Fixed Width font in MATLAB?
7 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Hello, I am trying to calculate the physical characteristics of the text we plan to use for our experiment. Now to finalize this, I need to know these following information PER character: size of letters, interletter spacing in cm and degrees of visual angle per font size (font size 16, 18, 20 and 22). I am relatively a newbie in MATLAB and I cannot find a function that could work. I am using Fixed Width font style.
I would appreciate any help I could get.
Thank you.
0 Commenti
Risposte (2)
J. Alex Lee
il 27 Ott 2021
I have no idea what you mean by "visual angle per font size", but I know of one way:
lbl = uicontrol("Style","text","String","X","FontName","courier")
This creates a text label on a figure, and once it is rendered, you can query its "Extent" property:
lbl.Extent
which is a [position,extent] vector, so the 3rd element is the width.
So playing around with it can give hints about how the UI system will position characters
lbl = uicontrol("Style","text","String","X","FontName","courier").Extent
lbl = uicontrol("Style","text","String","XX","FontName","courier").Extent
lbl = uicontrol("Style","text","String","XX X","FontName","courier").Extent
0 Commenti
Scott MacKenzie
il 27 Ott 2021
Modificato: Scott MacKenzie
il 27 Ott 2021
For text fonts, 1 pt = 1/72 inches. So, if you set the font size of the text to, say, 36 pt., the character height will be 1/2 inch or 1.27 cm. I suggest you do some actual measurements to verify and work with those measurements. MATLAB's "extent" property for text includes margins, so I'd be hesitant to use those width and height values.
As for visual angle, that's an arctan calculation. You need the size of the characters and the distance of the participant's eye from the display. For example, the visual angle in degrees for a character 1 cm in size viewed from a distance of 65 cm is
atand(1/65)
2 Commenti
Scott MacKenzie
il 28 Ott 2021
@Kathleen Kay Amora First, let me apologize for the false starts yesterday. I posted some code, then edited and reposted a few times. Then, I deleted the code as I felt it was heading down the wrong path. Since you've asked, I'll repost the code below. I hope you find it useful.
There are a few challenges in trying to use code to get the measurements you want. Many people's computing environments include different sizes of displays or >1 display, so the 'centimeter' units produced by the code are dubious at best. Plus, the text sizing measurements are for the text plus a margin around the text.
Here's the code. Good luck.
set(0, 'units', 'centimeters');
screenSize = get(0, 'ScreenSize'); % verify with measuring tape
wScreen = screenSize(3);
hScreen = screenSize(4);
txt = 'ABC';
fontSize = 48;
set(gca, 'xlim', [0 1], 'ylim', [0 1]);
t = text(0.5, 0.5, txt, 'FontName', 'fixedwidth', 'FontSize', fontSize, ...
'HorizontalAlignment','center', 'VerticalAlignment','middle', ...
'Margin', 15);
t.Units = 'centimeters';
d = 65; % distance (cm) of participant's eye from display (adjust as needed)
n = length(txt); % number of characters
w = t.Extent(3) / n; % per-character width (Note: includes margin)
h = t.Extent(4) / n; % per-character height (Note: includes margin)
va = atand(w/d); % per-character visual angle (degrees)
s = newline;
s = [s sprintf('%15s: %.1f cm x %.1f cm\n', 'Screen size', wScreen, hScreen)];
s = [s sprintf('%15s: %s\n', 'Text', txt)];
s = [s sprintf('%15s: %d pt\n', 'Font size', fontSize)];
s = [s sprintf('%15s: %.2f cm per character\n', 'Width', w)];
s = [s sprintf('%15s: %.2f cm per character\n', 'Height', h)];
s = [s sprintf('%15s: %.2f degrees per character at d = %d cm\n', 'Visual angle', va, d)];
disp(s);
Vedere anche
Categorie
Scopri di più su Annotations in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!