Functions moved in from CanvasPaint.  Test cases added.