Refactored to reuse calculateTextWidth
Merge pull request #436 from anna2130/calculate-text-width

Refactored palette.js and view.js to reuse calculateTextWidth