You can create a command that parses every character of a string, and create an environment that applies that command to the contents of the environment.
The \scan
code here (a bit of recursive black magic) is adapted from answers by @wipet on this site. You just create a new command with one argument and the \let\scando\yourcommand
to apply that command to each character in the string passed to \scan{}
.
I've simplified the MWE a bit and used a font that comes with the TeXLive distribution. The \strut
inside the \fbox
keeps the boxes all the same height.
\documentclass[12pt]{article}
\usepackage{fontspec}
\setmainfont{FandolKai}
\def\scando{}
\def\scan#1{\scanA#1\end}
\def\scanA#1{\ifx\end#1\else\scando#1\expandafter\scanA\fi}
\newcommand{\boxed}[1]{\fbox{\strut#1}}
\let\scando\boxed
\usepackage{environ}
\NewEnviron{boxedchars}{\expandafter\expandafter\scan\BODY}
\begin{document}
\scan{AB}
\scan{国学}
\begin{boxedchars}
国学
国学
国学
国学
\end{boxedchars}
\end{document}

EDIT
OP would reasonably like the command to work across multiple paragraphs and allow for line breaks. This is done by adding \long
to the definitions of \scan
and \scanA
so they will read past \par
tokens created at paragraph breaks. Second, we have to add a conditional test to the \boxed
code that checks for the \par
; in this case I set it up so that it leaves \par
in place. I also added a regular space after the \fbox
command, which will allow TeX to break the line in between boxes.
\documentclass[12pt]{article}
\usepackage{fontspec}
\setmainfont{FandolKai}
\def\scando{}
\long\def\scan#1{\scanA#1\end}
\long\def\scanA#1{\ifx\end#1\else\scando#1\expandafter\scanA\fi}
\newcommand{\boxed}[1]{\ifx\par#1#1\else\fbox{\strut#1} \fi}
\let\scando\boxed
\usepackage{environ}
\NewEnviron{boxedchars}{\expandafter\expandafter\scan\BODY}
\usepackage{parskip} % just to make paragraph divisions more visible for example
\begin{document}
\scan{AB}
\scan{国学}
\begin{boxedchars}
国学 国学 国学 国学
国学 国学 国学 国学
国学 国学 国学 国学
国学 国学 国学 国学
国学 国学 国学 国学
国学 国学 国学 国学
国学 国学 国学 国学
国学 国学 国学 国学
\end{boxedchars}
\end{document}
