diff --git a/apps/reader/tex_parser.cpp b/apps/reader/tex_parser.cpp index 1d6b4e87e..79b9ff0e4 100644 --- a/apps/reader/tex_parser.cpp +++ b/apps/reader/tex_parser.cpp @@ -15,6 +15,8 @@ namespace Reader { "sim", }; + static constexpr int const k_NumberOfSymbols = sizeof(k_SymbolsCommands) / sizeof(char *); + // List of the available Symbol's CodePoints in the same order of the Symbol's list static constexpr uint32_t const k_SymbolsCodePoints[] = { 0xd7, 0xf7, 0x2200, 0x2202, 0x2203, 0xb1, 0x2248, 0x221e, 0x2260, 0x2261, 0x2264, 0x2265, @@ -27,14 +29,18 @@ namespace Reader { 0x7e, }; + static_assert(sizeof(k_SymbolsCodePoints) / sizeof(uint32_t) == k_NumberOfSymbols); + // List of available Function Commands that don't require a specific handling - static constexpr char const * k_FunctionCommands[] = { + static char const * k_FunctionCommands[] = { "arccos", "arcsin", "arctan", "arg", "cos", "cosh", "cot", "coth", "csc", "deg", "det", "dim", "exp", "gcd", "hom", "inf", "ker", "lg", "lim", "liminf", "limsup", "ln", "log", "max", "min", "Pr", "sec", "sin", "sinh", "sup", "tan", "tanh" }; + static int const k_NumberOfFunctionCommands = sizeof(k_FunctionCommands) / sizeof(char *); + TexParser::TexParser(const char * text, const char * endOfText) : m_text(text), m_endOfText(endOfText), diff --git a/apps/reader/tex_parser.h b/apps/reader/tex_parser.h index 82e2c1f06..ef2e30b4f 100644 --- a/apps/reader/tex_parser.h +++ b/apps/reader/tex_parser.h @@ -47,11 +47,8 @@ private: static constexpr char const * k_sqrtCommand = "sqrt"; static constexpr char const * k_spaceCommand = "space"; static constexpr char const * k_overrightArrowCommand = "overrightarrow"; - - static constexpr int const k_NumberOfSymbols = 71; - static constexpr int const k_NumberOfFunctionCommands = 32; }; - + } #endif diff --git a/apps/reader/utility.cpp b/apps/reader/utility.cpp index d0f9e172c..c29c28f1f 100644 --- a/apps/reader/utility.cpp +++ b/apps/reader/utility.cpp @@ -109,7 +109,7 @@ int filesWithExtension(const char* extension, External::Archive::File* files, in #endif const char * EndOfPrintableWord(const char * word, const char * end) { - if (word == end) { + if (word >= end) { return word; } UTF8Decoder decoder(word); @@ -126,11 +126,11 @@ const char * EndOfPrintableWord(const char * word, const char * end) { } const char * StartOfPrintableWord(const char * word, const char * start) { - if (word == start) { + if (word <= start) { return word; } // Go to start of code point with some code points dark magic - if (!(*word & 0x80 == 0)) { + if (!((*word & 0x80) == 0)) { word--; while (!(*word & 0x80 && *word & 0x40)) { word--; diff --git a/apps/reader/word_wrap_view.cpp b/apps/reader/word_wrap_view.cpp index 032b039ec..1dddd0dd5 100644 --- a/apps/reader/word_wrap_view.cpp +++ b/apps/reader/word_wrap_view.cpp @@ -65,28 +65,42 @@ void WordWrapTextView::richTextPreviousPage() { const int charHeight = m_font->glyphSize().height(); const char * endOfWord = text() + m_pageOffset - 1; + if (*endOfWord == '\n') { + endOfWord --; + } - KDCoordinate baseline = charHeight; + KDCoordinate baseline = charHeight / 2; KDPoint textBottomEndPosition = KDPoint(m_frame.width() - k_margin, m_frame.height() - k_margin); KDCoordinate lineHeight = charHeight; while(endOfWord >= text()) { // 1. Skip whitespaces and line jumps - while(endOfWord >= text() && (*endOfWord == ' ' || *endOfWord == '\n')) { - if(*endOfWord == '\n') { + const char * invisiblesCharJumped = endOfWord; // We use this to update endOfWord only if we don't change page + bool changePage = false; + while(invisiblesCharJumped >= text() && (*invisiblesCharJumped == ' ' || *invisiblesCharJumped == '\n')) { + if(*invisiblesCharJumped == '\n') { textBottomEndPosition = KDPoint(m_frame.width() - k_margin, textBottomEndPosition.y() - lineHeight); lineHeight = charHeight; + baseline = charHeight / 2; // We check if we must change page if (textBottomEndPosition.y() - lineHeight <= k_margin) { + // We don't let text on a new line or a space + endOfWord ++; + changePage = true; break; } } else { textBottomEndPosition = KDPoint(textBottomEndPosition.x() - charWidth, textBottomEndPosition.y()); } - endOfWord--; + invisiblesCharJumped--; } + if (changePage) { + break; + } + endOfWord = invisiblesCharJumped; + // 3. If word is a color change if (*endOfWord == '%' && *(endOfWord - 1) != '\\') { const char * startOfWord = endOfWord - 2; @@ -146,6 +160,7 @@ void WordWrapTextView::richTextPreviousPage() { if (textBottomEndPosition.x() - textSize.width() <= k_margin) { textBottomEndPosition = KDPoint(m_frame.width() - k_margin, textBottomEndPosition.y() - lineHeight); lineHeight = 0; + baseline = charHeight; // We will check if we must change page below } textBottomEndPosition = KDPoint(textBottomEndPosition.x() - textSize.width(), textBottomEndPosition.y()); @@ -604,6 +619,11 @@ BookSave WordWrapTextView::getBookSave() const { void WordWrapTextView::setBookSave(BookSave save) { m_pageOffset = save.offset; m_textColor = save.color; + m_lastPagesOffsetsIndex = 0; + + for (int i = 0; i < k_lastOffsetsBufferSize; i++) { + m_lastPagesOffsets[i] = -1; // -1 Means : no informations + } } bool WordWrapTextView::updateTextColorForward(const char * colorStart) const { diff --git a/kandinsky/fonts/LargeFont.ttf b/kandinsky/fonts/LargeFont.ttf index 5446c8134..927e03040 100644 Binary files a/kandinsky/fonts/LargeFont.ttf and b/kandinsky/fonts/LargeFont.ttf differ diff --git a/kandinsky/fonts/SmallFont.ttf b/kandinsky/fonts/SmallFont.ttf index 9df343016..c36fa112e 100644 Binary files a/kandinsky/fonts/SmallFont.ttf and b/kandinsky/fonts/SmallFont.ttf differ