Changeset View
Changeset View
Standalone View
Standalone View
core/textpage.cpp
Show First 20 Lines • Show All 1796 Lines • ▼ Show 20 Line(s) | 1781 | { | |||
---|---|---|---|---|---|
1797 | tree.insert(i+1,node2); | 1797 | tree.insert(i+1,node2); | ||
1798 | } | 1798 | } | ||
1799 | } | 1799 | } | ||
1800 | 1800 | | |||
1801 | return tree; | 1801 | return tree; | ||
1802 | } | 1802 | } | ||
1803 | 1803 | | |||
1804 | /** | 1804 | /** | ||
1805 | * reoder RTL words to the correct order | ||||
1806 | */ | ||||
1807 | TextList reoderRTLWords (TextList origTxtOrder) | ||||
1808 | { | ||||
1809 | TextList tmp; | ||||
1810 | int i, j, k; | ||||
1811 | | ||||
1812 | i = 0; | ||||
1813 | while (i < origTxtOrder.length()) | ||||
1814 | { | ||||
1815 | // output a left-to-right section | ||||
1816 | for (j = i; j < origTxtOrder.length() && ! origTxtOrder.at(j)->text().isRightToLeft(); ++j) ; | ||||
1817 | for (k = i; k < j; ++k) | ||||
1818 | { | ||||
1819 | tmp.append(origTxtOrder.at(k)); | ||||
1820 | } | ||||
1821 | i = j; | ||||
1822 | // output a right-to-left section | ||||
1823 | for(j = i; j < origTxtOrder.length() && (origTxtOrder.at(j)->text().isRightToLeft() || origTxtOrder.at(j)->text() == " "); ++j); | ||||
1824 | | ||||
1825 | if(j > i) | ||||
1826 | { | ||||
1827 | tmp.append(new TinyTextEntity(QChar(0x202b), NormalizedRect())); | ||||
1828 | for (k = j - 1; k >= i; --k) | ||||
1829 | { | ||||
1830 | // filp new line char to be first in RTL word. | ||||
1831 | if (origTxtOrder.at(k)->text().contains('\n')) | ||||
1832 | { | ||||
1833 | QString flipNewLine = origTxtOrder.at(k)->text(); | ||||
1834 | flipNewLine.remove('\n'); | ||||
1835 | flipNewLine.push_front('\n'); | ||||
1836 | tmp.append(new TinyTextEntity(flipNewLine, origTxtOrder.at(k)->area)); | ||||
1837 | } | ||||
1838 | else | ||||
1839 | tmp.append(origTxtOrder.at(k)); | ||||
1840 | } | ||||
1841 | tmp.append(new TinyTextEntity(QChar(0x202c), NormalizedRect())); | ||||
1842 | i = j; | ||||
1843 | } | ||||
1844 | } | ||||
1845 | return tmp; | ||||
1846 | } | ||||
1847 | | ||||
1848 | /** | ||||
1805 | * Add spaces in between words in a line. It reuses the pointers passed in tree and might add new ones. You will need to take care of deleting them if needed | 1849 | * Add spaces in between words in a line. It reuses the pointers passed in tree and might add new ones. You will need to take care of deleting them if needed | ||
1806 | */ | 1850 | */ | ||
1807 | WordsWithCharacters addNecessarySpace(RegionTextList tree, int pageWidth, int pageHeight) | 1851 | WordsWithCharacters addNecessarySpace(RegionTextList tree, int pageWidth, int pageHeight) | ||
1808 | { | 1852 | { | ||
1809 | /** | 1853 | /** | ||
1810 | * 1. Call makeAndSortLines before adding spaces in between words in a line | 1854 | * 1. Call makeAndSortLines before adding spaces in between words in a line | ||
1811 | * 2. Now add spaces between every two words in a line | 1855 | * 2. Now add spaces between every two words in a line | ||
1812 | * 3. Finally, extract all the space separated texts from each region and return it | 1856 | * 3. Finally, extract all the space separated texts from each region and return it | ||
▲ Show 20 Lines • Show All 98 Lines • ▼ Show 20 Line(s) | 1923 | { | |||
1911 | * Break the words into characters | 1955 | * Break the words into characters | ||
1912 | */ | 1956 | */ | ||
1913 | TextList listOfCharacters; | 1957 | TextList listOfCharacters; | ||
1914 | foreach(const WordWithCharacters &word, listWithWordsAndSpaces) | 1958 | foreach(const WordWithCharacters &word, listWithWordsAndSpaces) | ||
1915 | { | 1959 | { | ||
1916 | delete word.word; | 1960 | delete word.word; | ||
1917 | listOfCharacters.append(word.characters); | 1961 | listOfCharacters.append(word.characters); | ||
1918 | } | 1962 | } | ||
1919 | setWordList(listOfCharacters); | 1963 | setWordList(reoderRTLWords(listOfCharacters)); | ||
1920 | } | 1964 | } | ||
1921 | 1965 | | |||
1922 | TextEntity::List TextPage::words(const RegularAreaRect *area, TextAreaInclusionBehaviour b) const | 1966 | TextEntity::List TextPage::words(const RegularAreaRect *area, TextAreaInclusionBehaviour b) const | ||
1923 | { | 1967 | { | ||
1924 | if ( area && area->isNull() ) | 1968 | if ( area && area->isNull() ) | ||
1925 | return TextEntity::List(); | 1969 | return TextEntity::List(); | ||
1926 | 1970 | | |||
1927 | TextEntity::List ret; | 1971 | TextEntity::List ret; | ||
▲ Show 20 Lines • Show All 111 Lines • Show Last 20 Lines |