[reader] Improved previous position algorithm and fixed symbols

This commit is contained in:
Laury
2022-05-01 21:02:07 +02:00
parent 745099842a
commit adab2c223b
6 changed files with 35 additions and 12 deletions

View File

@@ -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),

View File

@@ -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

View File

@@ -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--;

View File

@@ -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 {

Binary file not shown.

Binary file not shown.