Skip to content

Commit 759f5b0

Browse files
committed
Merge remote-tracking branch 'upstream/master'
2 parents 4bb7050 + 687b18f commit 759f5b0

8 files changed

Lines changed: 171 additions & 137 deletions

File tree

android/AndroidManifest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
55
package="org.coolreader"
66
android:installLocation="auto"
7-
android:versionName="3.2.6-1" android:versionCode="2061">
7+
android:versionName="3.2.7-1" android:versionCode="2071">
88
<supports-screens
99
android:xlargeScreens="true"
1010
android:largeScreens="true"

android/app/build.gradle

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ android {
88
targetSdkVersion 26
99
// When new version released, version code must be incremented at least by 8
1010
// for compatibility with ABI versioning of split apk (see below).
11-
versionCode 2061
12-
versionName "3.2.6-1"
11+
versionCode 2071
12+
versionName "3.2.7-1"
1313
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
1414
externalNativeBuild {
1515
cmake {
@@ -68,6 +68,15 @@ android {
6868
arguments "-DCMAKE_BUILD_TYPE=Debug"
6969
}
7070
}
71+
packagingOptions{
72+
doNotStrip "*/armeabi/*.so"
73+
doNotStrip "*/armeabi-v7a/*.so"
74+
doNotStrip "*/arm64-v8a/*.so"
75+
doNotStrip "*/x86/*.so"
76+
doNotStrip "*/x86_64/*.so"
77+
doNotStrip "*/mips/*.so"
78+
doNotStrip "*/mips64/*.so"
79+
}
7180
}
7281
}
7382
gradle.projectsEvaluated {

android/src/org/coolreader/crengine/BaseActivity.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ protected void onCreate(Bundle savedInstanceState)
191191
setScreenBacklightDuration(props.getInt(ReaderView.PROP_APP_SCREEN_BACKLIGHT_LOCK, 3));
192192

193193
setFullscreen( props.getBool(ReaderView.PROP_APP_FULLSCREEN, DeviceInfo.EINK_SCREEN));
194-
int orientation = props.getInt(ReaderView.PROP_APP_SCREEN_ORIENTATION, 5); //(DeviceInfo.EINK_SCREEN?0:4)
194+
int orientation = props.getInt(ReaderView.PROP_APP_SCREEN_ORIENTATION, 0); //(DeviceInfo.EINK_SCREEN?0:4)
195195
if (orientation < 0 || orientation > 5)
196196
orientation = 5;
197197
setScreenOrientation(orientation);
@@ -1725,7 +1725,7 @@ public Properties loadSettings(BaseActivity activity, File file) {
17251725
props.applyDefault(ReaderView.PROP_APP_GESTURE_PAGE_FLIPPING, "1");
17261726
props.applyDefault(ReaderView.PROP_APP_SHOW_COVERPAGES, "1");
17271727
props.applyDefault(ReaderView.PROP_APP_COVERPAGE_SIZE, "1");
1728-
props.applyDefault(ReaderView.PROP_APP_SCREEN_ORIENTATION, DeviceInfo.EINK_SCREEN ? "0" : "4"); // "0"
1728+
props.applyDefault(ReaderView.PROP_APP_SCREEN_ORIENTATION, "0"); // "0"
17291729
props.applyDefault(ReaderView.PROP_CONTROLS_ENABLE_VOLUME_KEYS, "1");
17301730
props.applyDefault(ReaderView.PROP_APP_TAP_ZONE_HILIGHT, "0");
17311731
props.applyDefault(ReaderView.PROP_APP_BOOK_SORT_ORDER, FileInfo.DEF_SORT_ORDER.name());

crengine/include/crsetup.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,12 @@
6464
#ifndef LDOM_USE_OWN_MEM_MAN
6565
#define LDOM_USE_OWN_MEM_MAN 1
6666
#endif
67+
#ifdef ANDROID
68+
#define CR_USE_THREADS 1
69+
#define USE_ATOMIC_REFCOUNT
70+
#else
6771
#define CR_USE_THREADS 0
72+
#endif // ANDROID
6873
#define USE_LIBJPEG 1
6974
#define USE_LIBPNG 1
7075
#define USE_GIF 1

crengine/include/lvstring.h

Lines changed: 60 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626
#define UNICODE_HYPHEN 0x2010
2727
#define UNICODE_NB_HYPHEN 0x2011
2828

29+
#ifdef USE_ATOMIC_REFCOUNT
30+
#include <atomic>
31+
#endif
2932

3033

3134
/// strlen for lChar16
@@ -111,13 +114,20 @@ struct lstring8_chunk_t {
111114
friend class lString16;
112115
friend struct lstring_chunk_slice_t;
113116
public:
114-
lstring8_chunk_t(lChar8 * _buf8) : buf8(_buf8), size(1), len(0), nref(1) {}
117+
lstring8_chunk_t(lChar8 * _buf8) : buf8(_buf8), size(1), len(0)
118+
{
119+
refCount = 1;
120+
}
115121
const lChar8 * data8() const { return buf8; }
116122
private:
117123
lChar8 * buf8; // z-string
118124
lInt32 size; // 0 for free chunk
119125
lInt32 len; // count of chars in string
120-
int nref; // reference counter
126+
#ifdef USE_ATOMIC_REFCOUNT
127+
std::atomic_int refCount; // atomic reference counter
128+
#else
129+
int refCount; // reference counter
130+
#endif
121131

122132
lstring8_chunk_t() {}
123133

@@ -132,13 +142,20 @@ struct lstring16_chunk_t {
132142
friend class lString16;
133143
friend struct lstring_chunk_slice_t;
134144
public:
135-
lstring16_chunk_t(lChar16 * _buf16) : buf16(_buf16), size(1), len(0), nref(1) {}
145+
lstring16_chunk_t(lChar16 * _buf16) : buf16(_buf16), size(1), len(0)
146+
{
147+
refCount = 1;
148+
}
136149
const lChar16 * data16() const { return buf16; }
137150
private:
138151
lChar16 * buf16; // z-string
139152
lInt32 size; // 0 for free chunk
140153
lInt32 len; // count of chars in string
141-
int nref; // reference counter
154+
#ifdef USE_ATOMIC_REFCOUNT
155+
std::atomic_int refCount; // atomic reference counter
156+
#else
157+
int refCount; // reference counter
158+
#endif
142159

143160
lstring16_chunk_t() {}
144161

@@ -164,6 +181,7 @@ namespace fmt {
164181
};
165182
}
166183

184+
167185
/**
168186
\brief lChar8 string
169187
@@ -206,8 +224,24 @@ class lString8
206224
static lstring_chunk_t * EMPTY_STR_8;
207225
void alloc(size_type sz);
208226
void free();
209-
inline void addref() const { ++pchunk->nref; }
210-
inline void release() { if (--pchunk->nref==0) free(); }
227+
inline void addref() const {
228+
#ifdef USE_ATOMIC_REFCOUNT
229+
pchunk->refCount.fetch_add(1);
230+
#else
231+
++pchunk->refCount;
232+
#endif
233+
}
234+
inline void release() {
235+
#ifdef USE_ATOMIC_REFCOUNT
236+
if (pchunk->refCount.fetch_sub(1) <= 1)
237+
free();
238+
#else
239+
if (--pchunk->refCount==0) free();
240+
#endif
241+
}
242+
inline int refCount() {
243+
return pchunk->refCount;
244+
}
211245
explicit lString8(lstring_chunk_t * chunk) : pchunk(chunk) { addref(); }
212246
public:
213247
/// default constrictor
@@ -350,7 +384,7 @@ class lString8
350384
/// ensures that reference count is 1
351385
void lock( size_type newsize );
352386
/// returns pointer to modifable string buffer
353-
value_type * modify() { if (pchunk->nref>1) lock(pchunk->len); return pchunk->buf8; }
387+
value_type * modify() { if (refCount()>1) lock(pchunk->len); return pchunk->buf8; }
354388
/// clear string
355389
void clear() { release(); pchunk = EMPTY_STR_8; addref(); }
356390
/// clear string, set buffer size
@@ -441,8 +475,24 @@ class lString16
441475
static lstring_chunk_t * EMPTY_STR_16;
442476
void alloc(size_type sz);
443477
void free();
444-
inline void addref() const { ++pchunk->nref; }
445-
inline void release() { if (--pchunk->nref==0) free(); }
478+
inline void addref() const {
479+
#ifdef USE_ATOMIC_REFCOUNT
480+
pchunk->refCount.fetch_add(1);
481+
#else
482+
++pchunk->refCount;
483+
#endif
484+
}
485+
inline void release() {
486+
#ifdef USE_ATOMIC_REFCOUNT
487+
if (pchunk->refCount.fetch_sub(1) <= 1)
488+
free();
489+
#else
490+
if (--pchunk->refCount==0) free();
491+
#endif
492+
}
493+
inline int refCount() {
494+
return pchunk->refCount;
495+
}
446496
public:
447497
explicit lString16(lstring_chunk_t * chunk) : pchunk(chunk) { addref(); }
448498
/// empty string constructor
@@ -606,7 +656,7 @@ class lString16
606656
/// resizes string, copies if several references exist
607657
void lock( size_type newsize );
608658
/// returns writable pointer to string buffer
609-
value_type * modify() { if (pchunk->nref>1) lock(pchunk->len); return pchunk->buf16; }
659+
value_type * modify() { if (refCount()>1) lock(pchunk->len); return pchunk->buf16; }
610660
/// clears string contents
611661
void clear() { release(); pchunk = EMPTY_STR_16; addref(); }
612662
/// resets string, allocates space for specified amount of characters

crengine/src/lvdocview.cpp

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1613,13 +1613,13 @@ int LVDocView::getPosEndPagePercent() {
16131613
else
16141614
return 0;
16151615
} else {
1616-
int fh = m_pages.length();
1617-
if (fh > 0) {
1616+
int pc = m_pages.length();
1617+
if (pc > 0) {
16181618
int p = getCurPage() + 1;// + 1;
16191619
if (getVisiblePageCount() > 1)
16201620
p++;
1621-
if (p > fh - 1)
1622-
p = fh - 1;
1621+
if (p > pc - 1)
1622+
p = pc - 1;
16231623
if (p < 0)
16241624
p = 0;
16251625
p = m_pages[p]->start - 10;
@@ -2581,16 +2581,18 @@ LVRef<ldomXRange> LVDocView::getPageDocumentRange(int pageIndex) {
25812581
// PAGES mode
25822582
if (pageIndex < 0 || pageIndex >= m_pages.length())
25832583
pageIndex = getCurPage();
2584-
LVRendPageInfo * page = m_pages[pageIndex];
2585-
if (page->type != PAGE_TYPE_NORMAL)
2586-
return res;
2587-
ldomXPointer start = m_doc->createXPointer(lvPoint(0, page->start));
2588-
//ldomXPointer end = m_doc->createXPointer( lvPoint( m_dx+m_dy, page->start + page->height - 1 ) );
2589-
ldomXPointer end = m_doc->createXPointer(lvPoint(0, page->start
2590-
+ page->height), 1);
2591-
if (start.isNull() || end.isNull())
2592-
return res;
2593-
res = LVRef<ldomXRange> (new ldomXRange(start, end));
2584+
if (pageIndex >= 0 && pageIndex < m_pages.length()) {
2585+
LVRendPageInfo *page = m_pages[pageIndex];
2586+
if (page->type != PAGE_TYPE_NORMAL)
2587+
return res;
2588+
ldomXPointer start = m_doc->createXPointer(lvPoint(0, page->start));
2589+
//ldomXPointer end = m_doc->createXPointer( lvPoint( m_dx+m_dy, page->start + page->height - 1 ) );
2590+
ldomXPointer end = m_doc->createXPointer(lvPoint(0, page->start
2591+
+ page->height), 1);
2592+
if (start.isNull() || end.isNull())
2593+
return res;
2594+
res = LVRef<ldomXRange>(new ldomXRange(start, end));
2595+
}
25942596
}
25952597
return res;
25962598
}
@@ -2630,7 +2632,8 @@ int LVDocView::getCurrentPageImageCount()
26302632

26312633
};
26322634
ImageCounter cnt;
2633-
range->forEach(&cnt);
2635+
if (!range.isNull())
2636+
range->forEach(&cnt);
26342637
return cnt.get();
26352638
}
26362639

@@ -2640,7 +2643,8 @@ lString16 LVDocView::getPageText(bool, int pageIndex) {
26402643
CHECK_RENDER("getPageText()")
26412644
lString16 txt;
26422645
LVRef < ldomXRange > range = getPageDocumentRange(pageIndex);
2643-
txt = range->getRangeText();
2646+
if (!range.isNull())
2647+
txt = range->getRangeText();
26442648
return txt;
26452649
}
26462650

@@ -4642,10 +4646,11 @@ ldomXPointer LVDocView::getCurrentPageMiddleParagraph() {
46424646
int pageIndex = getCurPage();
46434647
if (pageIndex < 0 || pageIndex >= m_pages.length())
46444648
pageIndex = getCurPage();
4645-
LVRendPageInfo * page = m_pages[pageIndex];
4646-
if (page->type == PAGE_TYPE_NORMAL)
4647-
ptr = m_doc->createXPointer(lvPoint(0, page->start + page->height
4648-
/ 2));
4649+
if (pageIndex >= 0 && pageIndex < m_pages.length()) {
4650+
LVRendPageInfo *page = m_pages[pageIndex];
4651+
if (page->type == PAGE_TYPE_NORMAL)
4652+
ptr = m_doc->createXPointer(lvPoint(0, page->start + page->height / 2));
4653+
}
46494654
}
46504655
if (ptr.isNull())
46514656
return ptr;
@@ -5568,6 +5573,10 @@ int LVDocView::onSelectionCommand( int cmd, int param )
55685573
{
55695574
CHECK_RENDER("onSelectionCommand()")
55705575
LVRef<ldomXRange> pageRange = getPageDocumentRange();
5576+
if (pageRange.isNull()) {
5577+
clearSelection();
5578+
return 0;
5579+
}
55715580
ldomXPointerEx pos( getBookmark() );
55725581
ldomXRangeList & sel = getDocument()->getSelections();
55735582
ldomXRange currSel;

0 commit comments

Comments
 (0)