use CachingTextMeasurer on writeText
combine duplicated code

measureTextInBox, writeText -> writeText
writeTextToTicks, measureTicks -> measureTicks