High-precision density measurements in the solar corona I. Analysis methods and results for Fe XII and Fe XIII