我有一个字符串链,我想显示尽可能大的矩形框架内,在一个中心的方式。我知道:
最多可以输入多少个字符
矩形的尺寸
它必须:
找到最佳字体大小并显示结果。
这是Matlab代码
color = 'k';
txt = '1';
howManyCharMaximum = 7;
boxWidth = 250;
boxHeight = 100;
%% comput: Now I assume one char is as wide as tall
howManyChar = strlength(txt);
marginHoriz = mod(boxWidth,howManyCharMaximum); %in points
subRectangle.width = (boxWidth-marginHoriz)/howManyCharMaximum;
subRectangle.height = boxHeight;
[fontSize,idx] = min([subRectangle.width, subRectangle.height]); %the largest square that fits in a rectangle
%%
hFigure = figure('MenuBar', 'none', ...
'ToolBar', 'none', ...
'Units', 'points', ...
'Position', [0 0 boxWidth boxHeight], ... % x y from bo