* The recognized text is returned as a char* which is coded * as UNLV format Latin-1 with specific reject and suspect codes * and must be freed with the delete [] operator. */
| 1784 | * and must be freed with the delete [] operator. |
| 1785 | */ |
| 1786 | char* TessBaseAPI::GetUNLVText() { |
| 1787 | if (tesseract_ == NULL || |
| 1788 | (!recognition_done_ && Recognize(NULL) < 0)) |
| 1789 | return NULL; |
| 1790 | bool tilde_crunch_written = false; |
| 1791 | bool last_char_was_newline = true; |
| 1792 | bool last_char_was_tilde = false; |
| 1793 | |
| 1794 | int total_length = TextLength(NULL); |
| 1795 | PAGE_RES_IT page_res_it(page_res_); |
| 1796 | char* result = new char[total_length]; |
| 1797 | char* ptr = result; |
| 1798 | for (page_res_it.restart_page(); page_res_it.word () != NULL; |
| 1799 | page_res_it.forward()) { |
| 1800 | WERD_RES *word = page_res_it.word(); |
| 1801 | // Process the current word. |
| 1802 | if (word->unlv_crunch_mode != CR_NONE) { |
| 1803 | if (word->unlv_crunch_mode != CR_DELETE && |
| 1804 | (!tilde_crunch_written || |
| 1805 | (word->unlv_crunch_mode == CR_KEEP_SPACE && |
| 1806 | word->word->space() > 0 && |
| 1807 | !word->word->flag(W_FUZZY_NON) && |
| 1808 | !word->word->flag(W_FUZZY_SP)))) { |
| 1809 | if (!word->word->flag(W_BOL) && |
| 1810 | word->word->space() > 0 && |
| 1811 | !word->word->flag(W_FUZZY_NON) && |
| 1812 | !word->word->flag(W_FUZZY_SP)) { |
| 1813 | /* Write a space to separate from preceding good text */ |
| 1814 | *ptr++ = ' '; |
| 1815 | last_char_was_tilde = false; |
| 1816 | } |
| 1817 | if (!last_char_was_tilde) { |
| 1818 | // Write a reject char. |
| 1819 | last_char_was_tilde = true; |
| 1820 | *ptr++ = kUNLVReject; |
| 1821 | tilde_crunch_written = true; |
| 1822 | last_char_was_newline = false; |
| 1823 | } |
| 1824 | } |
| 1825 | } else { |
| 1826 | // NORMAL PROCESSING of non tilde crunched words. |
| 1827 | tilde_crunch_written = false; |
| 1828 | tesseract_->set_unlv_suspects(word); |
| 1829 | const char* wordstr = word->best_choice->unichar_string().string(); |
| 1830 | const STRING& lengths = word->best_choice->unichar_lengths(); |
| 1831 | int length = lengths.length(); |
| 1832 | int i = 0; |
| 1833 | int offset = 0; |
| 1834 | |
| 1835 | if (last_char_was_tilde && |
| 1836 | word->word->space() == 0 && wordstr[offset] == ' ') { |
| 1837 | // Prevent adjacent tilde across words - we know that adjacent tildes |
| 1838 | // within words have been removed. |
| 1839 | // Skip the first character. |
| 1840 | offset = lengths[i++]; |
| 1841 | } |
| 1842 | if (i < length && wordstr[offset] != 0) { |
| 1843 | if (!last_char_was_newline) |
no test coverage detected