Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consecutive initial marks/dashes spacing tweak + some sync with Upstream #430

Merged
merged 8 commits into from
Mar 22, 2021
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ else()
ADD_DEFINITIONS( -DLINUX=1 -D_LINUX=1 )
endif(MAC)

# Large files support
ADD_DEFINITIONS( -D_LARGEFILE64_SOURCE=1 -D_FILE_OFFSET_BITS=64 -DLVLONG_FILE_SUPPORT=1 )

if (NOT DEFINED GRAY_BACKBUFFER_BITS)
SET(GRAY_BACKBUFFER_BITS 2)
endif (NOT DEFINED GRAY_BACKBUFFER_BITS)
Expand Down
4 changes: 2 additions & 2 deletions crengine/Tools/langstat/langstat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ void MakeStats()
MakeStatsForFile( BASE_DIR "es2-utf8.txt", "utf8", "ee", 2, f, list );
MakeStatsForFile( BASE_DIR "ee3-cp775.txt", "cp775", "ee", 1, f, list );
MakeStatsForFile( BASE_DIR "es3-cp1257.txt", "cp1257", "ee", 2, f, list );
MakeStatsForFile( BASE_DIR "gr1-cp1253.txt", "cp1253", "gr", 1, f, list );
MakeStatsForFile( BASE_DIR "gr1-cp737.txt", "cp737", "gr", 1, f, list );
MakeStatsForFile( BASE_DIR "gr1-cp1253.txt", "cp1253", "el", 1, f, list );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Strange, didn't we discuss this on our end recently?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that you mention it, that does vaguely ring a bell (perhaps not strictly in the same context, though)...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably in some hyphenation topic, like #373 (comment).

MakeStatsForFile( BASE_DIR "gr1-cp737.txt", "cp737", "el", 1, f, list );
MakeStatsForFile( BASE_DIR "lit1-cp1257.txt", "cp1257", "lit", 1, f, list );
MakeStatsForFile( BASE_DIR "lat1-cp1257.txt", "cp1257", "lat", 1, f, list );

Expand Down
6 changes: 6 additions & 0 deletions crengine/include/crsetup.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,9 @@
/** \def LVLONG_FILE_SUPPORT
\brief define to 1 to use 64 bits for file position types
*/
#ifndef LVLONG_FILE_SUPPORT
#define LVLONG_FILE_SUPPORT 0
#endif

//#define USE_ANSI_FILES 1

Expand Down Expand Up @@ -303,6 +305,10 @@
#define USE_GLYPHCACHE_HASHTABLE 0
#endif

#ifndef USE_LIMITED_FONT_SIZES_SET
#define USE_LIMITED_FONT_SIZES_SET 0
#endif

// Maximum & minimum screen resolution
#ifndef SCREEN_SIZE_MIN
#define SCREEN_SIZE_MIN 80
Expand Down
10 changes: 10 additions & 0 deletions crengine/include/lvdocview.h
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,13 @@ class LVDocView : public CacheLoadingCallback
int m_font_size; // = m_requested_font_size, possibly scaled according to DPI
int m_status_font_size;
int m_def_interline_space;
#if USE_LIMITED_FONT_SIZES_SET
LVArray<int> m_font_sizes;
bool m_font_sizes_cyclic;
#else
int m_min_font_size;
int m_max_font_size;
#endif
bool m_is_rendered;

LVDocViewMode m_view_mode; // DVM_SCROLL, DVM_PAGES
Expand Down Expand Up @@ -869,8 +874,13 @@ class LVDocView : public CacheLoadingCallback
/// sets new status bar font size
void setStatusFontSize( int newSize );

#if USE_LIMITED_FONT_SIZES_SET
/// sets posible base font sizes (for ZoomFont)
void setFontSizes( LVArray<int> & sizes, bool cyclic );
#else
void setMinFontSize( int size );
void setMaxFontSize( int size );
#endif

/// get drawing buffer
//LVDrawBuf * GetDrawBuf() { return &m_drawbuf; }
Expand Down
4 changes: 2 additions & 2 deletions crengine/include/lvdocviewprops.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
#define PROP_LOG_LEVEL "crengine.log.level"
#define PROP_LOG_AUTOFLUSH "crengine.log.autoflush"
#define PROP_FONT_SIZE "crengine.font.size"
#define PROP_FALLBACK_FONT_FACE "crengine.font.fallback.face"
// multiple fallback font faces allowed, separated by '|' (name kept singular for compatibility)
#define PROP_FALLBACK_FONT_FACES "crengine.font.fallback.faces"
// multiple fallback font faces are to be separated by '|'
#define PROP_STATUS_FONT_COLOR "crengine.page.header.font.color"
#define PROP_STATUS_FONT_FACE "crengine.page.header.font.face"
#define PROP_STATUS_FONT_SIZE "crengine.page.header.font.size"
Expand Down
4 changes: 2 additions & 2 deletions crengine/src/cp_stats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2227,8 +2227,8 @@ cp_stat_t cp_stat_table[] = {
{ch_stat_cp850_es2,dbl_ch_stat_cp850_es2,"cp850","es"},
{ch_stat_utf8_ee1,dbl_ch_stat_utf8_ee1,"utf8","ee"},
{ch_stat_cp775_ee1,dbl_ch_stat_cp775_ee1,"cp775","ee"},
{ch_stat_cp1253_gr1,dbl_ch_stat_cp1253_gr1,"cp1253","gr"},
{ch_stat_cp737_gr1,dbl_ch_stat_cp737_gr1,"cp737","gr"},
{ch_stat_cp1253_gr1,dbl_ch_stat_cp1253_gr1,"cp1253","el"},
{ch_stat_cp737_gr1,dbl_ch_stat_cp737_gr1,"cp737","el"},
{ch_stat_cp1257_lit1,dbl_ch_stat_cp1257_lit1,"cp1257","lit"},
{ch_stat_cp1257_lat1,dbl_ch_stat_cp1257_lat1,"cp1257","lat"},
{ch_stat_cp1250_sr1,dbl_ch_stat_cp1250_sr1,"cp1250","sr"},
Expand Down
7 changes: 5 additions & 2 deletions crengine/src/hist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,9 +236,12 @@ class CRHistoryFileParserCallback : public LVXMLParserCallback
case in_filepath:
_curr_file->setFilePath( txt );
break;
case in_filesize:
_curr_file->setFileSize( txt.atoi() );
case in_filesize: {
lInt64 size = 0;
if (txt.atoi(size))
_curr_file->setFileSize( size );
break;
}
default:
break;
}
Expand Down
61 changes: 55 additions & 6 deletions crengine/src/lvdocview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,13 @@ LVDocView::LVDocView(int bitsPerPixel, bool noDefaultDocument) :
#endif
, m_status_font_size(INFO_FONT_SIZE),
m_def_interline_space(100),
#if USE_LIMITED_FONT_SIZES_SET
m_font_sizes(def_font_sizes, sizeof(def_font_sizes) / sizeof(int)),
m_font_sizes_cyclic(false),
#else
m_min_font_size(6),
m_max_font_size(72),
#endif
m_is_rendered(false),
m_view_mode(1 ? DVM_PAGES : DVM_SCROLL) // choose 0/1
/*
Expand Down Expand Up @@ -3557,6 +3562,7 @@ void LVDocView::setVisiblePageCount(int n, bool onlyIfSane) {
_posIsSet = false;
}

#if USE_LIMITED_FONT_SIZES_SET
static int findBestFit(LVArray<int> & v, int n, bool rollCyclic = false) {
int bestsz = -1;
int bestfit = -1;
Expand All @@ -3579,6 +3585,7 @@ static int findBestFit(LVArray<int> & v, int n, bool rollCyclic = false) {
bestsz = n;
return bestsz;
}
#endif

void LVDocView::setDefaultInterlineSpace(int percent) {
LVLock lock(getMutex());
Expand Down Expand Up @@ -3610,7 +3617,14 @@ void LVDocView::setStatusFontSize(int newSize) {
int LVDocView::scaleFontSizeForDPI(int fontSize) {
if (gRenderScaleFontWithDPI) {
fontSize = scaleForRenderDPI(fontSize);
#if USE_LIMITED_FONT_SIZES_SET
fontSize = findBestFit(m_font_sizes, fontSize);
#else
if (fontSize < m_min_font_size)
fontSize = m_min_font_size;
else if (fontSize > m_max_font_size)
fontSize = m_max_font_size;
#endif
}
return fontSize;
}
Expand All @@ -3622,7 +3636,16 @@ void LVDocView::setFontSize(int newSize) {
// can be changed independantly.
int oldSize = m_requested_font_size;
if (oldSize != newSize) {
#if USE_LIMITED_FONT_SIZES_SET
m_requested_font_size = findBestFit(m_font_sizes, newSize);
#else
if (newSize < m_min_font_size)
m_requested_font_size = m_min_font_size;
else if (newSize > m_max_font_size)
m_requested_font_size = m_max_font_size;
else
m_requested_font_size = newSize;
#endif
propsGetCurrent()->setInt(PROP_FONT_SIZE, m_requested_font_size);
m_font_size = scaleFontSizeForDPI(m_requested_font_size);
CRLog::debug("New requested font size: %d (asked: %d)", m_requested_font_size, newSize);
Expand All @@ -3641,16 +3664,29 @@ void LVDocView::setStatusFontFace(const lString8 & newFace) {
REQUEST_RENDER("setStatusFontFace")
}

#if USE_LIMITED_FONT_SIZES_SET
/// sets posible base font sizes (for ZoomFont feature)
void LVDocView::setFontSizes(LVArray<int> & sizes, bool cyclic) {
m_font_sizes = sizes;
m_font_sizes_cyclic = cyclic;
}
#endif

#if !USE_LIMITED_FONT_SIZES_SET
void LVDocView::setMinFontSize( int size ) {
m_min_font_size = size;
}

void LVDocView::setMaxFontSize( int size ) {
m_max_font_size = size;
}
#endif

void LVDocView::ZoomFont(int delta) {
if (m_font.isNull())
return;
#if 1
#if USE_LIMITED_FONT_SIZES_SET
int sz = m_requested_font_size;
for (int i = 0; i < 15; i++) {
sz += delta;
Expand All @@ -3662,6 +3698,9 @@ void LVDocView::ZoomFont(int delta) {
if (sz < 12)
break;
}
#else
setFontSize(m_requested_font_size + delta);
#endif
#else
LVFontRef nfnt;
int sz = m_font->getHeight();
Expand Down Expand Up @@ -6220,8 +6259,11 @@ void LVDocView::propsUpdateDefaults(CRPropRef props) {
props->setIntDef(PROP_DISPLAY_TURBO_UPDATE_MODE, 0);

lString8 defFontFace;
static const char * goodFonts[] = { "DejaVu Sans", "FreeSans",
"Liberation Sans", "Arial", "Verdana", NULL };
// static const char * goodFonts[] = { "DejaVu Sans", "FreeSans", "Liberation Sans", "Arial", "Verdana", NULL };
// static const char * fallbackFonts = "Droid Sans Fallback|Noto Sans CJK SC|Noto Sans Arabic UI|Noto Sans Devanagari UI|FreeSans|FreeSerif|Noto Serif|Noto Sans|Arial Unicode MS";
// KOReader: avoid loading many fonts on launch, as these will be re-set by frontend
static const char * goodFonts[] = { "FreeSerif", NULL };
static const char * fallbackFonts = "FreeSerif";
for (int i = 0; goodFonts[i]; i++) {
if (list.contains(lString32(goodFonts[i]))) {
defFontFace = lString8(goodFonts[i]);
Expand All @@ -6237,13 +6279,16 @@ void LVDocView::propsUpdateDefaults(CRPropRef props) {
if (list.length() > 0 && !list.contains(props->getStringDef(PROP_FONT_FACE,
defFontFace.c_str())))
props->setString(PROP_FONT_FACE, list[0]);
props->setStringDef(PROP_FALLBACK_FONT_FACE, props->getStringDef(PROP_FONT_FACE,
defFontFace.c_str()));
props->setStringDef(PROP_FALLBACK_FONT_FACES, fallbackFonts);

#if USE_LIMITED_FONT_SIZES_SET
props->setIntDef(PROP_FONT_SIZE,
m_font_sizes[m_font_sizes.length() * 2 / 3]);
props->limitValueList(PROP_FONT_SIZE, m_font_sizes.ptr(),
m_font_sizes.length());
#else
props->setIntDef(PROP_FONT_SIZE, m_min_font_size + (m_min_font_size + m_max_font_size)/7);
#endif
props->limitValueList(PROP_INTERLINE_SPACE, cr_interline_spaces,
sizeof(cr_interline_spaces) / sizeof(int));
#if CR_INTERNAL_PAGE_ORIENTATION==1
Expand Down Expand Up @@ -6533,7 +6578,7 @@ CRPropRef LVDocView::propsApply(CRPropRef props) {
setPageMargins(rc);
} else if (name == PROP_FONT_FACE) {
setDefaultFontFace(UnicodeToUtf8(value));
} else if (name == PROP_FALLBACK_FONT_FACE) {
} else if (name == PROP_FALLBACK_FONT_FACES) {
lString8 oldFaces = fontMan->GetFallbackFontFaces();
if ( UnicodeToUtf8(value)!=oldFaces )
fontMan->SetFallbackFontFaces(UnicodeToUtf8(value));
Expand All @@ -6560,7 +6605,11 @@ CRPropRef LVDocView::propsApply(CRPropRef props) {
//} else if ( name==PROP_BOOKMARK_ICONS ) {
// enableBookmarkIcons( value==U"1" );
} else if (name == PROP_FONT_SIZE) {
#if USE_LIMITED_FONT_SIZES_SET
int fontSize = props->getIntDef(PROP_FONT_SIZE, m_font_sizes[0]);
#else
int fontSize = props->getIntDef(PROP_FONT_SIZE, m_min_font_size);
#endif
setFontSize(fontSize);//cr_font_sizes
value = lString32::itoa(m_requested_font_size);
} else if (name == PROP_STATUS_FONT_SIZE) {
Expand Down Expand Up @@ -6730,7 +6779,7 @@ CRPropRef LVDocView::propsApply(CRPropRef props) {
props->getIntDef(PROP_PAGE_VIEW_MODE, 1) ? DVM_PAGES
: DVM_SCROLL;
setViewMode(m);
} else if (name == PROP_PAGE_VIEW_MODE) {
} else if (name == PROP_CACHE_VALIDATION_ENABLED) {
bool value = props->getBoolDef(PROP_CACHE_VALIDATION_ENABLED, true);
enableCacheFileContentsValidation(value);
} else {
Expand Down
2 changes: 1 addition & 1 deletion crengine/src/lvdrawbuf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2886,7 +2886,7 @@ void LVGrayDrawBuf::DrawRescaled(const LVDrawBuf * __restrict src, int x, int y,
lUInt8 * __restrict dst = dst0 + x + xx;
lUInt32 dithered;
if (_bpp < 8)
dithered = DitherNBitColor(cl, xx, yy, _bpp) << (8 - _bpp);
dithered = DitherNBitColor(cl, xx, yy, _bpp);// << (8 - _bpp);
else
dithered = cl;
*dst = (lUInt8)dithered;
Expand Down
17 changes: 2 additions & 15 deletions crengine/src/lvfntman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4689,21 +4689,8 @@ class LVFreeTypeFontManager : public LVFontManager
FcFontSetDestroy(fontset);
CRLog::info("FONTCONFIG: %d fonts registered", facesFound);

const char * fallback_faces [] = {
"Arial Unicode MS",
"AR PL ShanHeiSun Uni",
"Liberation Sans",
NULL
};

for ( int i=0; fallback_faces[i]; i++ )
if ( SetFallbackFontFace(lString8(fallback_faces[i])) ) {
CRLog::info("Fallback font %s is found", fallback_faces[i]);
break;
}
else {
CRLog::trace("Fallback font %s is not found", fallback_faces[i]);
}
const char * fallback_faces = "Arial Unicode MS|AR PL ShanHeiSun Uni|Liberation Sans|Roboto|DejaVu Sans|Noto Sans|Droid Sans";
SetFallbackFontFaces(lString8(fallback_faces));

return facesFound > 0;
}
Expand Down
4 changes: 4 additions & 0 deletions crengine/src/lvpagesplitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,10 @@ struct PageSplitState {
}
void SplitLineIfOverflowPage( LVRendLineInfo * line )
{
// If page_h <= 0 this function will fall into an infinite loop
// in which it will allocate memory until it runs out.
if (page_h <= 0)
return;
// A 'line' is usually a line of text from a paragraph, but
// can be an image, or a fully rendered table row (<tr>), and
// can have a huge height, possibly overflowing page height.
Expand Down
22 changes: 16 additions & 6 deletions crengine/src/lvstream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,16 @@ extern "C" {

#endif

// To support "large files" on 32-bit platforms
// Since we have defined own types 'lvoffset_t', 'lvpos_t' and do not use the system type 'off_t'
// it is logical to define our own wrapper function 'lseek'.
static inline lvpos_t cr3_lseek(int fd, lvoffset_t offset, int whence) {
#if LVLONG_FILE_SUPPORT == 1
return (lvpos_t)::lseek64(fd, (off64_t)offset, whence);
#else
return (lvpos_t)::lseek(fd, (off_t)offset, whence);
#endif
}

static LVAssetContainerFactory * _assetContainerFactory = NULL;

Expand Down Expand Up @@ -682,7 +692,7 @@ class LVFileMappedStream : public LVNamedStream
return error();
#else
// LINUX
if ( lseek( m_fd, size-1, SEEK_SET ) == -1 ) {
if ( cr3_lseek( m_fd, size-1, SEEK_SET ) == (lvpos_t)-1 ) {
CRLog::error("LVFileMappedStream::SetSize() -- Seek error");
return error();
}
Expand Down Expand Up @@ -1202,20 +1212,20 @@ class LVFileStream : public LVNamedStream
if (m_fd == -1)
return LVERR_FAIL;
//
int res = -1;
lvpos_t res = (lvpos_t)-1;
switch ( origin )
{
case LVSEEK_SET:
res = lseek( m_fd, offset, SEEK_SET );
res = cr3_lseek( m_fd, offset, SEEK_SET );
break;
case LVSEEK_CUR:
res = lseek( m_fd, offset, SEEK_CUR );
res = cr3_lseek( m_fd, offset, SEEK_CUR );
break;
case LVSEEK_END:
res = lseek( m_fd, offset, SEEK_END );
res = cr3_lseek( m_fd, offset, SEEK_END );
break;
}
if (res!=(off_t)-1)
if (res!=(lvpos_t)-1)
{
m_pos = res;
if ( pNewPos )
Expand Down
9 changes: 7 additions & 2 deletions crengine/src/lvstring.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1123,8 +1123,8 @@ lString32 & lString32::trim()
int lString32::atoi() const
{
int n = 0;
atoi(n);
return n;
bool res = atoi(n);
return res ? n : 0;
}

static const char * hex_digits = "0123456789abcdef";
Expand Down Expand Up @@ -1203,6 +1203,9 @@ bool lString32::atoi( int &n ) const
return false;
while (*s>='0' && *s<='9')
{
if (n > INT_MAX/10) {
return false;
}
n = n * 10 + ( (*s++)-'0' );
}
if ( sgn<0 )
Expand All @@ -1229,6 +1232,8 @@ bool lString32::atoi( lInt64 &n ) const
return false;
while (*s>='0' && *s<='9')
{
if (n > __INT64_MAX__/10)
return false;
n = n * 10 + ( (*s++)-'0' );
}
if ( sgn<0 )
Expand Down
Loading