1. A non-transitory machine readable medium storing a program which when executed by at least one processing unit identifies a selection of primitive areas in a page of a document, the program comprising sets of instructions for: receiving an ordered list of primitive areas in the page; receiving a selection point specifying a location in the page; identifying a primitive area that is closest to the location specified by the selection point by comparing the location with at least two primitive areas in the page according to a set of comparison criterions, wherein a lower priority comparison criterion is used when a higher priority comparison criterion is unable to identify the primitive area that is closest to the selection point, and wherein a highest priority criterion is a vertical distance between the location and the nearest points of the compared primitive areas that does not account for horizontal distance and a lower priority criterion is a second distance between the location and the primitive areas that accounts for horizontal distance and does not account for vertical distance; and assigning a selection index to the selection point based on a position of the identified primitive area in the ordered list of primitive areas.