First-principles studies of lone-pair-induced distortions in epitaxial phases of perovskite SnTiO$_3$ and PbTiO$_3$