Nanoscale design of polarization in ultrathin ferroelectric heterostructures