Problem
I keep getting:
You can't use `\XeTeXcountglyphs` in vertical mode.
Attempt
\documentclass{article}
\usepackage{fontspec}
\usepackage{pgf}
\usepackage{pgffor}
\begin{document}
\pgfmathsetmacro\maxstep{\XeTeXcountglyphs\font}
\foreach \charstep in {1,...,\maxstep}{%
\XeTeXglyph\charstep
}%
\end{document}
Note that I have since changed \pgfmathsetmacro to \pgfmathtruncatemacro so that I can type the following in my document and it makes sense (otherwise you get something like 2625.01; fractions of glyphs do not make sense):
Number of glyphs: \maxstep

\hboxwith by changing the line\XeTeXglyph\charstepto\XeTeXglyph\charstep{}\space– Jonathan Komar Mar 29 '15 at 10:24\\or whatever, so I just left it as in the original. – David Carlisle Mar 29 '15 at 10:27