Better text direction detection.

Makes use of Ayamel if available, otherwise creates exactly the same
function Ayamel would have.