Remove unneeded redraw of the current page.
The function UniReader:showHighLight() internally handles all cases
where page redraw is necessary. Therefore, there is no need to redraw
the current page (much less to :goto() to it) on return from it.
Re-sort the history list on closing document
The "Last Documents" list is re-sorted on operations that modify it,
such as deleting an entry. But opening/closing a document is also one
such operation and, therefore, requires re-sorting.
Redraw current page on return from highlight mode
When returning from highlight mode there is no need to :goto() to the
current page (and force dummy pre-cache) --- all that is needed is the
redraw of the current page.
Two trivial optimizations
1. Comment out re-calculation of parameters to adjust for the case when
the user changed screen orientation, because we force portrait mode on
document close. I left a comment explaining this, so we can uncomment
this code if we choose to not force portrait mode on document close in
thefuture.
2. Don't re-sort the list if the file does not exist.
This predicts the most likely scenario, namely that the user
will choose to delete this stale history entry.
And even if he chooses NOT to delete it, placing a stale entry
to the top of the list contradicts our logic because the
non-existent file was never opened.
bugfix: calculate current cache size and free oldest cache if needed
Cache ttl should not be decreased only when there is no free slot for
new cache but decreased when claiming new cache each time. Otherwise
caches will be freed altogether which obviously is not the purpose of
the cache system. This patch only free the oldest caches and make just
enough free slots for the new one.
bugfix: write cache before a new reflow
Reflowed bitmap should be written to cache before a new reflow is
started because all reflowing processes share the same masterinfo in
libk2pdfopt which contains the data of reflowed bitmap. If a new reflow
is started before a priviously reflowed bitmap is written, the
priviously reflowed bitmap will be corrupted which may cause
segmentation fault when it is written into cache finally.
bugfix: get rid of memory leak in koptreader
Memory leak came from the master bitmap that is reused in each reflow. But the bitmap
width and height were not set to zero when bitmap was freed. When the master bitmap was
enlarged in some cases the size of the master bitmap would increase monotonically.
This patch fixes this issue by setting master bitmap width and height to zero at the
beginning of each reflow. And a memeory usage logger is added in koptreader.
Fix deleting highlights via Shift-N
When deleting highlights the tables pointing to a highlight's page
number and sequential number within that page must be rebuilt.
The present implementation illustrates the typical use of local
functions in Lua, i.e. for this situation the lexical scope feature of
Lua's local functions is ideally suited.
Cleanups of battery logging
1. No need to pass the header through string.format()
2. Check for G_battery_logging value inside logBatteryLevel() function
to simply the code in the callers thereof.
bugfix: reclaim thread stack explicitly by using detached threads
Otherwise the VmData size will keep increasing in multi-threads mode.
Although the increasing VmData size doesn't mean there is enormous
memory leak, it does show that the thread stack is not handled properly
when threads exit.
Merge pull request #624 from tigran123/history

Re-sort Last Documents list on closing the document and remove unneeded page redraw
Merge pull request #628 from tigran123/highlights

Fix deleting highlights via Shift-N + cleanup of battery logging.
bugfix: destroying attr objects immediately after pthread_create
Merge pull request #626 from chrox/kopt-cache

bugfix: calculate current cache size and free oldest cache if needed
Merge pull request #627 from chrox/kopt-writecache

bugfix: write cache before new reflows && fix memory leak