Created
April 7, 2013 15:49
-
-
Save alexkasko/5331011 to your computer and use it in GitHub Desktop.
Hacky patch to fix [FBReader issue 189](https://github.com/geometer/FBReader/issues/189)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/jni/NativeFormats/fbreader/src/formats/txt/PlainTextFormat.cpp b/jni/NativeFormats/fbreader/src/formats/txt/PlainTextFormat.cpp | |
index a64e26a..cc4d1d4 100644 | |
--- a/jni/NativeFormats/fbreader/src/formats/txt/PlainTextFormat.cpp | |
+++ b/jni/NativeFormats/fbreader/src/formats/txt/PlainTextFormat.cpp | |
@@ -160,14 +160,15 @@ void PlainTextFormatDetector::detect(ZLInputStream &stream, PlainTextFormat &for | |
} | |
{ | |
- int breakType = 0; | |
- breakType |= PlainTextFormat::BREAK_PARAGRAPH_AT_EMPTY_LINE; | |
- if (stringsWithLengthLessThan81Counter < 0.3 * nonEmptyLineCounter) { | |
- breakType |= PlainTextFormat::BREAK_PARAGRAPH_AT_NEW_LINE; | |
- } else { | |
- breakType |= PlainTextFormat::BREAK_PARAGRAPH_AT_LINE_WITH_INDENT; | |
- } | |
- format.myBreakType = (breakType); | |
+// alexkasko: disable text reflow heuristic | |
+// int breakType = 0; | |
+// breakType |= PlainTextFormat::BREAK_PARAGRAPH_AT_EMPTY_LINE; | |
+// if (stringsWithLengthLessThan81Counter < 0.3 * nonEmptyLineCounter) { | |
+// breakType |= PlainTextFormat::BREAK_PARAGRAPH_AT_NEW_LINE; | |
+// } else { | |
+// breakType |= PlainTextFormat::BREAK_PARAGRAPH_AT_LINE_WITH_INDENT; | |
+// } | |
+ format.myBreakType = PlainTextFormat::BREAK_PARAGRAPH_AT_EMPTY_LINE | PlainTextFormat::BREAK_PARAGRAPH_AT_NEW_LINE; | |
} | |
{ | |
diff --git a/jni/NativeFormats/fbreader/src/formats/txt/TxtBookReader.cpp b/jni/NativeFormats/fbreader/src/formats/txt/TxtBookReader.cpp | |
index 24c8d09..b07e9a0 100644 | |
--- a/jni/NativeFormats/fbreader/src/formats/txt/TxtBookReader.cpp | |
+++ b/jni/NativeFormats/fbreader/src/formats/txt/TxtBookReader.cpp | |
@@ -39,12 +39,9 @@ bool TxtBookReader::characterDataHandler(std::string &str) { | |
const char *ptr = str.data(); | |
const char *end = ptr + str.length(); | |
for (; ptr != end; ++ptr) { | |
- if (isspace((unsigned char)*ptr)) { | |
- if (*ptr != '\t') { | |
+ // alexkasko: treat \t as not space | |
+ if (isspace((unsigned char)*ptr) && *ptr != '\t') { | |
++mySpaceCounter; | |
- } else { | |
- mySpaceCounter += myFormat.ignoredIndent() + 1; // TODO: implement single option in PlainTextFormat | |
- } | |
} else { | |
myLastLineIsEmpty = false; | |
break; | |
diff --git a/jni/NativeFormats/fbreader/src/formats/txt/TxtReader.cpp b/jni/NativeFormats/fbreader/src/formats/txt/TxtReader.cpp | |
index ad6c344..a482979 100644 | |
--- a/jni/NativeFormats/fbreader/src/formats/txt/TxtReader.cpp | |
+++ b/jni/NativeFormats/fbreader/src/formats/txt/TxtReader.cpp | |
@@ -96,6 +96,8 @@ TxtReaderCoreUtf16::TxtReaderCoreUtf16(TxtReader &reader) : TxtReaderCore(reader | |
void TxtReaderCore::readDocument(ZLInputStream &stream) { | |
const std::size_t BUFSIZE = 2048; | |
char *buffer = new char[BUFSIZE]; | |
+ char prev = ' '; | |
+ const char sp = '\t'; | |
std::string str; | |
std::size_t length; | |
do { | |
@@ -125,6 +127,14 @@ void TxtReaderCore::readDocument(ZLInputStream &stream) { | |
} | |
} else { | |
} | |
+ // alexkasko: add \t instead of second \n | |
+ if('\n' == prev && '\n' == *ptr) { | |
+ str.erase(); | |
+ myReader.myConverter->convert(str, &sp, &sp + 1); | |
+ myReader.characterDataHandler(str); | |
+ myReader.newLineHandler(); | |
+ } | |
+ prev = *ptr; | |
} | |
if (start != end) { | |
str.erase(); | |
diff --git a/project.properties b/project.properties | |
index be2a2e9..e0ab720 100644 | |
--- a/project.properties | |
+++ b/project.properties | |
@@ -10,4 +10,4 @@ | |
java.encoding=utf-8 | |
# proguard.config=proguard.cfg | |
# Project target. | |
-target=android-14 | |
+target=android-17 | |
diff --git a/src/org/geometerplus/zlibrary/text/view/ZLTextParagraphCursor.java b/src/org/geometerplus/zlibrary/text/view/ZLTextParagraphCursor.java | |
index cd0b175..dab827f 100644 | |
--- a/src/org/geometerplus/zlibrary/text/view/ZLTextParagraphCursor.java | |
+++ b/src/org/geometerplus/zlibrary/text/view/ZLTextParagraphCursor.java | |
@@ -135,7 +135,8 @@ public final class ZLTextParagraphCursor { | |
for (int index = 0; index < length; ++index) { | |
previousChar = ch; | |
ch = data[offset + index]; | |
- if (Character.isSpace(ch)) { | |
+ // alexkasko: treat \t as not space | |
+ if (Character.isSpace(ch) && '\t' != ch) { | |
if (index > 0 && spaceState == NO_SPACE) { | |
addWord(data, offset + wordStart, index - wordStart, myOffset + wordStart, hyperlink); | |
} | |
diff --git a/src/org/geometerplus/zlibrary/text/view/ZLTextViewBase.java b/src/org/geometerplus/zlibrary/text/view/ZLTextViewBase.java | |
index 09f3798..add7196 100644 | |
--- a/src/org/geometerplus/zlibrary/text/view/ZLTextViewBase.java | |
+++ b/src/org/geometerplus/zlibrary/text/view/ZLTextViewBase.java | |
@@ -273,7 +273,7 @@ abstract class ZLTextViewBase extends ZLView { | |
} | |
final void drawWord(int x, int y, ZLTextWord word, int start, int length, boolean addHyphenationSign, ZLColor color) { | |
- final ZLPaintContext context = myContext; | |
+ final ZLPaintContext context = myContext; | |
context.setTextColor(color); | |
if (start == 0 && length == -1) { | |
drawString(x, y, word.Data, word.Offset, word.Length, word.getMark(), 0); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment