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

(Upstream) Various minor picks to keep some bits in sync #450

Merged
merged 10 commits into from
Aug 31, 2021
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: CI
on: push
on: [push, pull_request]

jobs:
linux:
Expand Down
10 changes: 1 addition & 9 deletions crengine/include/lvdocview.h
Original file line number Diff line number Diff line change
Expand Up @@ -389,14 +389,6 @@ class LVDocView : public CacheLoadingCallback
void updateDocStyleSheet();

protected:


virtual void drawNavigationBar( LVDrawBuf * drawbuf, int pageIndex, int percent );

virtual void getNavigationBarRectangle( lvRect & rc );

virtual void getNavigationBarRectangle( int pageIndex, lvRect & rc );

/// returns document offset for next page
int getNextPageOffset();
/// returns document offset for previous page
Expand Down Expand Up @@ -993,6 +985,6 @@ class SimpleTitleFormatter {


/// draw book cover, either from image, or generated from title/authors
void LVDrawBookCover(LVDrawBuf & buf, LVImageSourceRef image, lString8 fontFace, lString32 title, lString32 authors, lString32 seriesName, int seriesNumber);
void LVDrawBookCover(LVDrawBuf & buf, LVImageSourceRef image, bool respectAspectRatio, lString8 fontFace, lString32 title, lString32 authors, lString32 seriesName, int seriesNumber);

#endif
5 changes: 5 additions & 0 deletions crengine/include/lvhashtable.h
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,11 @@ template <typename keyT, typename valueT> class LVHashTable
}
return false;
}
void compact()
{
if (_count > 0 && _count < _size)
resize(_count);
}
private:
int _size;
int _count;
Expand Down
6 changes: 6 additions & 0 deletions crengine/include/lvstring.h
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,8 @@ class lString8
lString8 & replace(size_type p0, size_type n0, const lString8 & str, size_type offset, size_type count);
/// replace fragment with repeated character
lString8 & replace(size_type p0, size_type n0, size_type count, value_type ch);
/// replaces every occurrence of the character before with the character after and returns a reference to this string
lString8 & replace(value_type before, value_type after);
/// make string uppercase
lString8 & uppercase();
/// make string lowercase
Expand Down Expand Up @@ -700,6 +702,10 @@ class lString32
bool atoi( int &n ) const;
/// converts to 64 bit integer, returns true if success
bool atoi( lInt64 &n ) const;
/// convert to double
double atod() const;
/// convert to double, returns true if success
bool atod( double &d, char dp = '.' ) const;
/// returns constant c-string pointer
const value_type * c_str() const { return pchunk->buf32; }
/// returns constant c-string pointer, same as c_str()
Expand Down
8 changes: 4 additions & 4 deletions crengine/include/lvtinydom.h
Original file line number Diff line number Diff line change
Expand Up @@ -1781,15 +1781,15 @@ class ldomXPointerEx : public ldomXPointer
bool nextVisibleWordEnd( bool thisBlockOnly = false );

/// move to previous visible word beginning (in sentence)
bool prevVisibleWordStartInSentence();
bool prevVisibleWordStartInSentence(bool thisBlockOnly);
/// move to previous visible word end (in sentence)
bool prevVisibleWordEndInSentence();
bool prevVisibleWordEndInSentence(bool thisBlockOnly);
/// move to next visible word beginning (in sentence)
bool nextVisibleWordStartInSentence();
bool nextVisibleWordStartInSentence(bool thisBlockOnly);
/// move to end of current word (in sentence)
bool thisVisibleWordEndInSentence();
/// move to next visible word end (in sentence)
bool nextVisibleWordEndInSentence();
bool nextVisibleWordEndInSentence(bool thisBlockOnly);

/// move to beginning of current visible text sentence
bool thisSentenceStart();
Expand Down
23 changes: 15 additions & 8 deletions crengine/src/chmfmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
#include "../include/chmfmt.h"
#include <chm_lib.h>

#include "../include/fb2def.h"
#define XS_IMPLEMENT_SCHEME 1
#include "../include/fb2def.h"

#define DUMP_CHM_DOC 0

struct crChmExternalFileStream : public chmExternalFileStream {
Expand Down Expand Up @@ -819,7 +823,7 @@ class CHMSystem {
}

lString32 getContentsFileName() {
if ( _binaryTOCURLTableId!=0 ) {
if ( _binaryTOCURLTableId!=0 && _urlTable != NULL ) {
lString8 url = _urlTable->urlById(_binaryTOCURLTableId);
if ( !url.empty() )
return decodeString(url);
Expand Down Expand Up @@ -860,10 +864,10 @@ ldomDocument * LVParseCHMHTMLStream( LVStreamRef stream, lString32 defEncodingNa
if ( stream.isNull() )
return NULL;

#if 0
// detect encondig
stream->SetPos(0);

#if 0
ldomDocument * encDetectionDoc = LVParseHTMLStream( stream );
int encoding = 0;
if ( encDetectionDoc!=NULL ) {
Expand Down Expand Up @@ -899,11 +903,14 @@ ldomDocument * LVParseCHMHTMLStream( LVStreamRef stream, lString32 defEncodingNa
ldomDocument * doc;
doc = new ldomDocument();
doc->setDocFlags( 0 );
doc->setNodeTypes(fb2_elem_table);
doc->setAttributeTypes(fb2_attr_table);
doc->setNameSpaceTypes(fb2_ns_table);

ldomDocumentWriterFilter writerFilter(doc, false, HTML_AUTOCLOSE_TABLE);
writerFilter.setFlags(writerFilter.getFlags() | TXTFLG_CONVERT_8BIT_ENTITY_ENCODING);

/// FB2 format
/// HTML format
LVFileFormatParser * parser = new LVHTMLParser(stream, &writerFilter);
if ( !defEncodingName.empty() )
parser->SetCharset(defEncodingName.c_str());
Expand Down Expand Up @@ -1103,11 +1110,11 @@ class CHMTOCReader {
return false;
}

#if DUMP_CHM_DOC==1
LVStreamRef out = LVOpenFileStream(U"/tmp/chm-toc.html", LVOM_WRITE);
if ( !out.isNull() )
doc->saveToStream( out, NULL, true );
#endif
#if DUMP_CHM_DOC==1
LVStreamRef out = LVOpenFileStream(U"chm-toc.xml", LVOM_WRITE);
if ( !out.isNull() )
doc->saveToStream( out, NULL, true );
#endif

ldomNode * body = doc->getRootNode(); //doc->createXPointer(cs32("/html[1]/body[1]"));
bool res = false;
Expand Down
56 changes: 24 additions & 32 deletions crengine/src/lvdocview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1648,31 +1648,6 @@ void LVDocView::getPageRectangle(int pageIndex, lvRect & pageRect, bool mergeTwo
}
}

void LVDocView::getNavigationBarRectangle(lvRect & navRect) {
getNavigationBarRectangle(getVisiblePageCount() == 2 ? 1 : 2, navRect);
}

void LVDocView::getNavigationBarRectangle(int pageIndex, lvRect & navRect) {
lvRect headerRect;
getPageHeaderRectangle(pageIndex, headerRect);
navRect = headerRect;
if (headerRect.bottom <= headerRect.top)
return;
navRect.top = navRect.bottom - 6;
}

void LVDocView::drawNavigationBar(LVDrawBuf * drawbuf, int pageIndex,
int percent) {
CR_UNUSED2(drawbuf, percent);
//LVArray<int> & sbounds = getSectionBounds();
lvRect navBar;
getNavigationBarRectangle(pageIndex, navBar);
//bool leftPage = (getVisiblePageCount()==2 && !(pageIndex&1) );

//lUInt32 cl1 = 0xA0A0A0;
//lUInt32 cl2 = getBackgroundColor();
}

/// sets battery state
bool LVDocView::setBatteryState(int newState) {
if (m_battery_state == newState)
Expand Down Expand Up @@ -1736,9 +1711,6 @@ void LVDocView::drawPageHeader(LVDrawBuf * drawbuf, const lvRect & headerRc,
int percent_pos = /*info.left + */percent * info.width() / 10000;
// int gh = 3; //drawGauge ? 3 : 1;
LVArray<int> & sbounds = getSectionBounds();
// NavBar no longer used:
// lvRect navBar;
// getNavigationBarRectangle(pageIndex, navBar);
int gpos = info.bottom;
// if (drawbuf->GetBitsPerPixel() <= 2) {
// // gray
Expand Down Expand Up @@ -6475,10 +6447,14 @@ CRPropRef LVDocView::propsApply(CRPropRef props) {
} else if (name == PROP_FONT_GAMMA) {
double gamma = 1.0;
lString32 s = props->getStringDef(PROP_FONT_GAMMA, "1.0");
lString8 s8 = UnicodeToUtf8(s);
if ( sscanf(s8.c_str(), "%lf", &gamma)==1 ) {
// When parsing a gamma value string, the decimal point is always '.' char.
// So if a different decimal point character is used in the current locale,
// and if we use some library function to convert the string to floating point number, then it may fail.
if (s.atod(gamma, '.')) {
fontMan->SetGamma(gamma);
clearImageCache();
} else {
CRLog::error("Invalid gamma value (%s)", LCSTR(s));
}
} else if (name == PROP_FONT_HINTING) {
int mode = props->getIntDef(PROP_FONT_HINTING, (int)HINTING_MODE_AUTOHINT);
Expand Down Expand Up @@ -7042,7 +7018,7 @@ static cover_palette_t series_palette[8] = {
{0x00C0D0C0, 0x20E8E8D8, 0xC0FFC040, 0xD0F0E0E0, 0x00400040, 0x00000080, 0x00402040, 0x80FFFFFF},
};

void LVDrawBookCover(LVDrawBuf & buf, LVImageSourceRef image, lString8 fontFace, lString32 title, lString32 authors, lString32 seriesName, int seriesNumber) {
void LVDrawBookCover(LVDrawBuf & buf, LVImageSourceRef image, bool respectAspectRatio, lString8 fontFace, lString32 title, lString32 authors, lString32 seriesName, int seriesNumber) {
CR_UNUSED(seriesNumber);
bool isGray = buf.GetBitsPerPixel() <= 8;
cover_palette_t * palette = NULL;
Expand All @@ -7057,8 +7033,24 @@ void LVDrawBookCover(LVDrawBuf & buf, LVImageSourceRef image, lString8 fontFace,
int dx = buf.GetWidth();
int dy = buf.GetHeight();
if (!image.isNull() && image->GetWidth() > 0 && image->GetHeight() > 0) {
int xoff = 0;
int yoff = 0;
if (respectAspectRatio) {
// recalc dx, dy for respectAspectRatio
int dst_aspect = 100*dx/dy;
int src_aspect = 100*image->GetWidth()/image->GetHeight();
if (dst_aspect > src_aspect) {
int new_dx = src_aspect*dy/100;
xoff = (dx - new_dx + 1)/2;
dx = new_dx;
} else if (dst_aspect < src_aspect) {
int new_dy = 100*dx/src_aspect;
yoff = (dy - new_dy + 1)/2;
dy = new_dy;
}
}
CRLog::trace("drawing image cover page %d x %d", dx, dy);
buf.Draw(image, 0, 0, dx, dy);
buf.Draw(image, xoff, yoff, dx, dy);
return;
}

Expand Down
38 changes: 26 additions & 12 deletions crengine/src/lvfntman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,11 @@ static lChar32 getReplacementChar(lUInt32 code, bool * can_be_ignored = NULL) {
case 0x25AA: // css_lst_square:
case 0x25FE: // css_lst_square:
return '-';
case 0x21AF: // DOWNWARDS ZIGZAG ARROW
case 0x26A1: // HIGH VOLTAGE SIGN
case 0x2B4D: // DOWNWARDS TRIANGLE-HEADED ZIGZAG ARROW
case 0x1F5F2:// LIGHTNING MOOD
return '+';
default:
break;
}
Expand Down Expand Up @@ -2209,7 +2214,7 @@ class LVFreeTypeFace : public LVFont

lUInt16 prev_width = 0;
lUInt16 cur_width = 0;
int lastFitChar = 0;
lUInt16 lastFitChar = 0;
updateTransform(); // no-op
// measure character widths

Expand Down Expand Up @@ -2423,17 +2428,22 @@ class LVFreeTypeFace : public LVFont
fb_hints &= ~LFNT_HINT_BEGINS_PARAGRAPH;
if ( t_notdef_end < len )
fb_hints &= ~LFNT_HINT_ENDS_PARAGRAPH;
fallback->measureText( text + t_notdef_start, t_notdef_end - t_notdef_start,
lUInt16 last_good_width = t_notdef_start > 0 ? widths[t_notdef_start-1] : 0;
lUInt16 chars_measured = fallback->measureText( text + t_notdef_start, t_notdef_end - t_notdef_start,
widths + t_notdef_start, flags + t_notdef_start,
max_width, def_char, lang_cfg, letter_spacing, allow_hyphenation,
max_width - last_good_width, def_char, lang_cfg, letter_spacing, allow_hyphenation,
fb_hints );
lastFitChar = t_notdef_start + chars_measured;
// Fix previous bad measurements
int last_good_width = t_notdef_start > 0 ? widths[t_notdef_start-1] : 0;
for (int tn = t_notdef_start; tn < t_notdef_end; tn++) {
for (int tn = t_notdef_start; tn < lastFitChar; tn++) {
widths[tn] += last_good_width;
if (widths[tn] > max_width) {
lastFitChar = tn;
break;
}
}
// And fix our current width
cur_width = widths[t_notdef_end-1];
cur_width = widths[lastFitChar-1];
prev_width = cur_width;
#ifdef DEBUG_MEASURE_TEXT
printf("MTHB ### measured past failures > W= %d\n[...]", cur_width);
Expand Down Expand Up @@ -2524,18 +2534,22 @@ class LVFreeTypeFace : public LVFont
lUInt32 fb_hints = hints | LFNT_HINT_IS_FALLBACK_FONT;
if ( t_notdef_start > 0 )
fb_hints &= ~LFNT_HINT_BEGINS_PARAGRAPH;
int chars_measured = fallback->measureText( text + t_notdef_start, // start
lUInt16 last_good_width = t_notdef_start > 0 ? widths[t_notdef_start-1] : 0;
lUInt16 chars_measured = fallback->measureText( text + t_notdef_start, // start
t_notdef_end - t_notdef_start, // len
widths + t_notdef_start, flags + t_notdef_start,
max_width, def_char, lang_cfg, letter_spacing, allow_hyphenation,
max_width - last_good_width, def_char, lang_cfg, letter_spacing, allow_hyphenation,
fb_hints );
lastFitChar = t_notdef_start + chars_measured;
int last_good_width = t_notdef_start > 0 ? widths[t_notdef_start-1] : 0;
for (int tn = t_notdef_start; tn < t_notdef_end; tn++) {
for (int tn = t_notdef_start; tn < lastFitChar; tn++) {
widths[tn] += last_good_width;
if (widths[tn] > max_width) {
lastFitChar = tn;
break;
}
}
// And add all that to our current width
cur_width = widths[t_notdef_end-1];
cur_width = widths[lastFitChar-1];
#ifdef DEBUG_MEASURE_TEXT
printf("MTHB ### measured past failures at EOT > W= %d\n[...]", cur_width);
#endif
Expand All @@ -2548,7 +2562,7 @@ class LVFreeTypeFace : public LVFont
}

// i is used below to "fill props for rest of chars", so make it accurate
i = len; // actually make it do nothing
i = lastFitChar;

#ifdef DEBUG_MEASURE_TEXT
printf("MTHB <<< W=%d [%s]\n", cur_width, _faceName.c_str());
Expand Down
Loading