A printer with print head cleaning function is provided. A balance is thus achieved, in terms of the length of the path on lines extending in the direction orthogonal to that in which reference cells are arranged, between current paths passing respectively through a selected memory cell and a selected reference cell, regardless of the result of address selection. The variable capacity hydraulic pump is driven by a combustion engine together with a charge pump. The three detection units detect displacement in two orthogonal directions on a plane parallel to a plane along which the detection head unit moves.