Fonts that work correctly

20 views (last 30 days)
Alan
Alan on 28 Sep 2012
I have been playing around, in MATLAB 2012b, with setting the fonts in a Figure. I have done this both under OS X and Windows 7, but am now completely confused. I find that fonts I select either don't display correctly or print correctly or both.
Is there a document somewhere which explains which fonts I can and cannot use in a Figure under both OS X and Windows?
The sorts of questions I need answered are
  1. If I change the font of an object to FontName X, that font will be correctly displayed in the MATLAB figure window for these fonts.
  2. If I change the font of an object to FontName X, that font will be correctly printed in a .png file for these fonts.
  3. If I change the font of an object to FontName X, that font will be correctly printed in a .pdf file for these fonts.
where by 'correctly' I mean, with the right font at the right size and without bits missing.
  2 Comments
Jan
Jan on 28 Sep 2012
  • Printing to PNG creates a pixel copy of the disaplayed figure. How can this fail?
  • Creating a PDF allows to embed the used fonts. Can this fail?
  • Which fonts are not rendered correctly?
Alan
Alan on 29 Sep 2012
Here's an example.
MATLAB's default font is 'Helvetica'. On my Mac, the following code
close all
mytext='QWERTYUIOPqwertyuiop1234567890';
figure
for ii=1:10
hstr=sprintf('%dpt : %s',...
ii+5,mytext);
h(ii)=text(0,ii/10,hstr);
set(h(ii),'fontsize',ii+5);
end
axis ij
axis off
Produces a figure that is OK, the fonts look like Helvetica and they are the right size but they are pixelated.
If I print them to a .png using
print 'test' -dpng -r150
in the resulting .png file, some lines have been clipped. For example the 8pt line is cutoff half way through the '9'.
If I print to a .pdf using
print 'test' -dpdf
the resulting file is rendered fine.
On the Windows 7 side, the same test produces a MATLAB displayed Figure with the fonts OK, but bigger than the Mac relative to the figure window size. The .png is wrong in two places. The 10pt and 11pt lines are identical, as are the 12pt and 13pt lines. No lines are truncated. The .pdf is again OK, but the larger sizes are truncated.
I have tried this with other FontNames. With Courier the results are even worse, no consistency at all.

Sign in to comment.

Answers (2)

Malcolm Lidierth
Malcolm Lidierth on 30 Sep 2012
You might(?) see better cross-platform consistency with one of the Java virtual fonts such as Serif or Sans Serif.
All MATLAB 2D graphics are pixellated.
  2 Comments
Alan
Alan on 30 Sep 2012
Edited: Alan on 30 Sep 2012
There are problems with those default fonts too. With "monospaced" in the displayed Figure 11pt is as long as 12pt, but it is shorter in the png. There is no way to get the displayed text in the right place. And they all get replaced by "Courier" in the pdf.
I know the graphics are pixellated, by "pixellated" I mean obviously and unattractively so.
Jan
Jan on 30 Sep 2012
@Malcolm: With the Painters renderer, exported PDFs are vector graphics.

Sign in to comment.


Jan
Jan on 30 Sep 2012
I've tested this under Matlab R2009a and Win7/64. I get equal fond sizes for 12 and 13 point. The problem does not depend on the renderer, but with a higher resolution the fontsizes differ:
print('test', '-dpng', '-r300');
It seems, like the fontsizes are divided by the resolution and rounded to the next integer value. I'm not surprised that pixelated fonts are not available in 12.4 point.
In consequence the problem is the expectation that "print -dpng" exports the fonts as you like it. Exporting to EPS and letting GhistScript render the output to a PNG might be better.
But the problem of the truncated lines for Macs remains: I guess that the font sizes are rounded to the next integer, but the available extent is not.

Categories

Find more on Graphics Object Properties in Help Center and File Exchange

Tags

Products

Community Treasure Hunt

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

Start Hunting!