Handwriting segmentation code