Refined algorithm for text splitting into lines