From 6025b017c81dec9c06e004967a7f35455ae0e02e Mon Sep 17 00:00:00 2001 From: mokhov Date: Mon, 22 Jun 2015 21:42:05 +0300 Subject: [PATCH] simple average symbols per page algorithm --- Makefile | 3 ++- client/core/chitalka-fb2/chitalka-fb2.js | 25 ++++++++---------------- lib/reader.xsl | 6 +++--- 3 files changed, 13 insertions(+), 21 deletions(-) diff --git a/Makefile b/Makefile index a1184c2..e067d4d 100644 --- a/Makefile +++ b/Makefile @@ -27,7 +27,8 @@ npm: # Build project build: $(ENB) make $(ENB_FLAGS) - @cp -r lib build/index/lib + @rm -rf build/index/lib + @cp -rf lib build/index/lib @mv build/index/index.ru.html build/index/index.html # Clean build results diff --git a/client/core/chitalka-fb2/chitalka-fb2.js b/client/core/chitalka-fb2/chitalka-fb2.js index b66648c..2ba541e 100644 --- a/client/core/chitalka-fb2/chitalka-fb2.js +++ b/client/core/chitalka-fb2/chitalka-fb2.js @@ -194,6 +194,7 @@ modules.define( // связанный баг https://st.yandex-team.ru/CHITALKA-65 nextTick(function () { this._buildCFIs(); + this._countSymbols(); this._calcDimensions(); this._restoreSavedPosition(); @@ -301,8 +302,7 @@ modules.define( this._pageCount = this._getBookPages(); // Среднее число символов на странице, speedCoeff - эмпирически вычисленный коэффцицент - var speedCoeff = (this._pageWidth / (11 * this._fontSize / 16)); - this._avgSymbolsOnPage = Math.round(Math.floor(this._bookCanvasHeight / this._lineHeight) * speedCoeff); + this._avgSymbolsOnPage = Math.round(this._totalBookSymbols / this._pageCount) }, /** @@ -490,40 +490,31 @@ modules.define( parent = parent || this._bookPlaceholder; var counter = 1; id = id || '/'; - var totalSymbols = 0; $(parent).contents().map(function (i, el) { var genID = id + counter; - var symbols; if (el.nodeType === TEXT_NODE) { - symbols = $.trim(el.textContent).length; - totalSymbols += symbols; - // оборачиваем только если не пустая нода и не единственная if ($.trim(el.textContent) !== '' && $(parent).size() > 1) { var wrap = $(''); wrap.attr('data-4cfi', genID); - if (symbols) { - wrap.attr('data-symbols', symbols); - } - $(el).wrap(wrap); counter++; } } else { $(el).attr('data-4cfi', genID); - symbols = this._buildCFIs(el, genID + '/'); - totalSymbols += symbols; - if (symbols) { - $(el).attr('data-symbols', symbols); - } counter++; } }.bind(this)); + }, - return totalSymbols; + /** + * Вычисляет число символов в книге + */ + _countSymbols: function () { + this._totalBookSymbols = $.trim(this._bookPlaceholder.get(0).textContent).replace(/\s{2,}/g, ' ').length; }, /** diff --git a/lib/reader.xsl b/lib/reader.xsl index 70f67ea..44cba85 100644 --- a/lib/reader.xsl +++ b/lib/reader.xsl @@ -26,9 +26,9 @@ - - - + + +