I'm trying to draw text in different shapes using a custom font.
With the help of Steven, I was able to get most of the text shapes I needed working well. See the question here
Everything works well, except when using custom fonts. I'm using the fontspec package with XeLaTeX for custom fonts. Below is what I'm using to generate the final output:
\documentclass[11pt]{article}
\usepackage{ifthen,trimclip,calc,fp,graphicx}
\usepackage[active, tightpage]{preview}
\usepackage[usenames,dvipsnames,svgnames,table]{xcolor}
\usepackage{fontspec}
\usepackage[document]{ragged2e}
\setlength\PreviewBorder{0.2pt}%
\title{bidPress}
\author{bidPress}
\date{September 2016}
\setmainfont[ExternalLocation=/path/to/fonts/]{"HelveticaLTStd-Roman.ttf"}
\newsavebox\mytext
\newcounter{mycount}
\newlength\clipsize
\newcommand\parabtext[5][0]{%
\edef\neck{#3}% percent to depress the amplitude
\def\cuts{#4}% Number of cuts
\savebox{\mytext}{\kern.2pt#5\kern.2pt}% TEXT
\FPeval{\myprod}{1/cuts}%
\clipsize=\myprod\wd\mytext\relax%
\setcounter{mycount}{0}%
\whiledo{\value{mycount}<\cuts}{%
\stepcounter{mycount}%
\edef\NA{\themycount}%
\edef\NB{\the\numexpr\cuts-\themycount\relax}%
\FPeval{\myprod}{(\NA-.5)*(\NB+.5)*4/\cuts/\cuts}%
\ifnum0#1=0\relax%
\FPeval{\myprod}{1 - \neck*(\myprod)}%
\else%
\FPeval{\myprod}{1 - \neck*(1-\myprod)}%
\fi%
\clipbox{%
\value{mycount}\clipsize-\clipsize\relax{} %
-1pt %
\wd\mytext-\value{mycount}\clipsize\relax{} %
-1pt%
}{\raisebox{#2\dimexpr\ht\mytext-\myprod\ht\mytext}{%
\scalebox{1}[\myprod]{\usebox{\mytext}}}}%
}%
}
\makeatletter
\ifdefined\XeTeXversion
\def\@cliptoboxdim#1{%
\setbox #1=\hbox{%
\Gin@defaultbp\WIDTH{\wd #1}%
\Gin@defaultbp \DEPTH {\dp #1}%
\@tempdima \ht #1%
\advance\@tempdima\dp#1%
\Gin@defaultbp \TOTALHEIGHT {\@tempdima }%
\special{pdf:literal q}%
\special{pdf:literal 0 -\DEPTH \space \WIDTH \space \TOTALHEIGHT \space re W n }%
\rlap{\copy #1}%
\special {pdf:literal Q}%
\hskip\wd#1%
}%
}
\fi
\makeatother
\begin{document}
\begin{preview}
\begin{center}
\special{pdf:bcolor [0.0 0.0 0.0] }
\parabtext{0}{.7}{100}{\large TEST TEST TEST}
\end{center}
\end{preview}
\end{document}
This works well when I don't use a custom font, i.e. removing the \setmainfont line.
With a custom font the left side of the fonts are chopped off. Below is an example with Helvetica:
Helvetica isn't so bad, but it gets worse with some other fonts like Chewy



\savebox{\mytext}{\kern.2pt#5\kern.2pt}%needs to have the.2ptvalues increased. That was supposed to account for glyph overhang beyond the bounding box. – Steven B. Segletes Oct 17 '16 at 23:23\whiledoloop. I would add that the slicing process equally subdivides the\mytextsavebox. Thus, your resolution decreases slightly, as well, as some slices may be devoted to the blank space in the pre/post kern. – Steven B. Segletes Oct 18 '16 at 13:33