Skip to content

Commit

Permalink
New feature: when opened book or choosing font, it checked for compat…
Browse files Browse the repository at this point in the history
…ibility with book's language and displayed message about incompatibility.

If language can't be detected - no messages displayed.
Into crengine has been embedded fc-lang component (most languages charset database): https://www.fontconfig.org/
converted by utility fc-lang_conv at https://github.com/virxkane/freetype_textdraw .
This database occupy in memory about 164 kb.
  • Loading branch information
virxkane committed Jan 16, 2019
1 parent 168da2c commit 7f52891
Show file tree
Hide file tree
Showing 268 changed files with 41,016 additions and 35 deletions.
2 changes: 2 additions & 0 deletions android/app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ project(cr3engine)
set(CR3_ROOT ${PROJECT_SOURCE_DIR}/../..)

include_directories(${CR3_ROOT}/crengine/include)
include_directories(${CR3_ROOT}/crengine/fc-lang)
include_directories(${CR3_ROOT}/thirdparty/libpng)
include_directories(${CR3_ROOT}/thirdparty/freetype)
include_directories(${CR3_ROOT}/thirdparty/freetype/include)
Expand Down Expand Up @@ -73,6 +74,7 @@ set(CRENGINE_SRC_FILES
${CR3_ROOT}/crengine/src/wolutil.cpp
${CR3_ROOT}/crengine/src/crconcurrent.cpp
${CR3_ROOT}/crengine/src/hist.cpp
${CR3_ROOT}/crengine/fc-lang/fc-lang-cat.c
)
# ${CR3_ROOT}/crengine/src/cri18n.cpp
# ${CR3_ROOT}/crengine/src/crgui.cpp
Expand Down
21 changes: 21 additions & 0 deletions android/jni/cr3engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,27 @@ JNIEXPORT jboolean JNICALL Java_org_coolreader_crengine_Engine_setCacheDirectory
return res ? JNI_TRUE : JNI_FALSE;
}

/*
* Class: org_coolreader_crengine_Engine
* Method: checkFontLanguageCompatibilityInternal
* Signature: (Ljava/lang/String;Ljava/lang/String;)Z
*/
JNIEXPORT jboolean JNICALL Java_org_coolreader_crengine_Engine_checkFontLanguageCompatibilityInternal
(JNIEnv *env, jclass cls, jstring fontFace, jstring langCode)
{
jboolean res = JNI_TRUE;
const char* fontFace_ptr = env->GetStringUTFChars(fontFace, 0);
const char* langCode_ptr = env->GetStringUTFChars(langCode, 0);
if (fontFace_ptr && langCode_ptr) {
res = fontMan->checkFontLangCompat(lString8(fontFace_ptr), lString8(langCode_ptr)) ? JNI_TRUE : JNI_FALSE;
}
if (langCode_ptr)
env->ReleaseStringUTFChars(langCode, langCode_ptr);
if (fontFace_ptr)
env->ReleaseStringUTFChars(fontFace, fontFace_ptr);
return res;
}

/*
* Class: org_coolreader_crengine_Engine
* Method: isLink
Expand Down
2 changes: 1 addition & 1 deletion android/jni/gen_jni_studio
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/sh

sdk="/opt/android-sdk-update-manager"
binclass_path=../../android/app/build/intermediates/classes/debug/
binclass_path=../app/build/intermediates/javac/debug/compileDebugJavaWithJavac/classes

export CLASSPATH="${CLASSPATH}:${sdk}/platforms/android-17/*:${binclass_path}"

Expand Down
10 changes: 9 additions & 1 deletion android/jni/org_coolreader_crengine_Engine.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 8 additions & 4 deletions android/res/layout/about_dialog_app.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,20 @@
<TextView android:text="https://github.com/buggins/coolreader/" android:id="@+id/www1"
style="@style/TextAppearance.Medium"
android:layout_margin="4dip" android:layout_width="fill_parent" android:layout_height="wrap_content" android:autoLink="web"/>
<TextView android:text="Third party components used: zlib, libpng, libjpeg, freetype, harfbuzz, chmlib, antiword, Nook EPD utils by DairyKnight"
<TextView android:text="@string/third_party_components_used"
android:id="@+id/thirdparty"
style="@style/TextAppearance.Small"
android:layout_margin="4dip" android:layout_width="fill_parent" android:layout_height="wrap_content"/>
<TextView android:text="Farm-Fresh icon set from http://www.fatcow.com/free-icons"
android:id="@+id/thirdparty2"
<TextView android:text="@string/fontconfig_language_orthography_database"
android:id="@+id/thirdparty2"
style="@style/TextAppearance.Small"
android:layout_margin="4dip" android:layout_width="fill_parent" android:layout_height="wrap_content"/>
<TextView android:text="@string/third_party_farm_fresh_icon_set"
android:id="@+id/thirdparty3"
style="@style/TextAppearance.Small"
android:layout_margin="4dip" android:layout_width="fill_parent" android:layout_height="wrap_content"/>
<TextView android:text="CoffeeCatch> library: https://github.com/xroche/coffeecatch"
android:id="@+id/thirdparty3"
android:id="@+id/thirdparty4"
style="@style/TextAppearance.Small"
android:layout_margin="4dip" android:layout_width="fill_parent" android:layout_height="wrap_content"/>
</LinearLayout>
Expand Down
7 changes: 7 additions & 0 deletions android/res/values-ru/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -590,4 +590,11 @@
<string name="options_app_ui_theme_hicontrast1">Контрастная белая</string>
<string name="options_app_ui_theme_hicontrast2">Контрастная черная</string>
<string name="datadir_is_removed">Каталог с данными приложения \"%s\" был удален другой программой!\nВозможно какой-то оптимизатор дискового пространства?\nК сожалению, все настройки утеряны.</string>
<string name="font_not_compat_with_language">"Шрифт \"%s\" не совместим с языком \"%s\". Вместо него будет задействован дополнительный шрифт."</string>
<string name="fontconfig_language_orthography_database">Набор символов различных писменностей от Fontconfig:
https://www.fontconfig.org/
</string>
<string name="third_party_components_used">Использованы следующие компоненты третьих сторон: zlib, libpng, libjpeg,
freetype, harfbuzz, chmlib, antiword, Nook EPD utils от DairyKnight
</string>
</resources>
12 changes: 10 additions & 2 deletions android/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@
<string name="dlg_about_textures_dirs">Textures directories:</string>
<string name="dlg_about_backgrounds_dirs">Backgrounds directories:</string>
<string name="dlg_about_hyphenations_dirs">Hyphenation dictionaries directories:</string>
<string name="dlg_about_copyright">© Vadim Lopatin, 1998–2018</string>
<string name="dlg_about_copyright">© Vadim Lopatin, 1998–2019</string>
<string name="dlg_about_contributors_">and contributors…</string>
<string name="mi_book_browser_normal_mode">Normal mode</string>
<string name="mi_book_browser_simple_mode">Simple file list</string>
Expand Down Expand Up @@ -615,5 +615,13 @@
<string name="pages_per_full_swipe_18">"18 pages (track)"</string>
<string name="pages_per_full_swipe_19">"19 pages (track)"</string>
<string name="pages_per_full_swipe_20">"20 pages (track)"</string>
<string name="datadir_is_removed">Application data directory \"%s\" was removed by other app.\nPossibly it was some kind of disc space optimizer.\nUnfortunately all the settings were lost.</string>
<string name="datadir_is_removed">Application data directory \"%s\" has been removed by other app.\nPossibly it was some kind of disc space optimizer.\nUnfortunately all the settings were lost.</string>
<string name="font_not_compat_with_language">"Font \"%s\" isn't compatible with language \"%s\". Instead will be used fallback font."</string>
<string name="fontconfig_language_orthography_database">"Languages character set database by Fontconfig:
https://www.fontconfig.org/ "
</string>
<string name="third_party_components_used">"Third party components used: zlib, libpng, libjpeg, freetype, harfbuzz,
chmlib, antiword, Nook EPD utils by DairyKnight "
</string>
<string name="third_party_farm_fresh_icon_set">Farm-Fresh icon set from http://www.fatcow.com/free-icons</string>
</resources>
4 changes: 0 additions & 4 deletions android/src/org/coolreader/CoolReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -469,10 +469,8 @@ public void run() {
}
if (Engine.getExternalSettingsDirName() != null) {
setExtDataDirCreateTime(new Date());
log.e("DataDir exist or created!");
} else {
setExtDataDirCreateTime(null);
log.e("DataDir NOT exist and NOT created!");
}
if (dataDirIsRemoved) {
// show message
Expand Down Expand Up @@ -579,10 +577,8 @@ public void run() {
}
if (Engine.getExternalSettingsDirName() != null) {
setExtDataDirCreateTime(new Date());
log.e("DataDir exist or created!");
} else {
setExtDataDirCreateTime(null);
log.e("DataDir NOT exist and NOT created!");
}
} else if (PERM_REQUEST_READ_PHONE_STATE_CODE == requestCode) {
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
Expand Down
7 changes: 7 additions & 0 deletions android/src/org/coolreader/crengine/BaseActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -1047,6 +1047,13 @@ public void showToast(int stringResourceId) {
showToast(stringResourceId, Toast.LENGTH_LONG);
}

public void showToast(int stringResourceId, Object... formatArgs)
{
String s = getString(stringResourceId, formatArgs);
if (s != null)
showToast(s, Toast.LENGTH_LONG);
}

public void showToast(int stringResourceId, int duration) {
String s = getString(stringResourceId);
if (s != null)
Expand Down
8 changes: 7 additions & 1 deletion android/src/org/coolreader/crengine/Engine.java
Original file line number Diff line number Diff line change
Expand Up @@ -582,11 +582,17 @@ public void initAgain() {

private native static void suspendLongOperationInternal(); // cancel current long operation in engine thread (swapping to cache file) -- call it from GUI thread

private native static boolean checkFontLanguageCompatibilityInternal(String fontFace, String langCode);

public static void suspendLongOperation() {
suspendLongOperationInternal();
}


public synchronized static boolean checkFontLanguageCompatibility(String fontFace, String langCode)
{
return checkFontLanguageCompatibilityInternal(fontFace, langCode);
}

/**
* Checks whether specified directlry or file is symbolic link.
* (thread-safe)
Expand Down
21 changes: 20 additions & 1 deletion android/src/org/coolreader/crengine/ReaderView.java
Original file line number Diff line number Diff line change
Expand Up @@ -2557,7 +2557,26 @@ private void applySettings(Properties props)
int updInterval = props.getInt(PROP_APP_SCREEN_UPDATE_INTERVAL, 10);
mActivity.setScreenUpdateMode(updMode, surface);
mActivity.setScreenUpdateInterval(updInterval, surface);


if (null != mBookInfo) {
FileInfo fileInfo = mBookInfo.getFileInfo();
final String bookLanguage = fileInfo.getLanguage();
final String fontFace = props.getProperty(PROP_FONT_FACE);
if (null != bookLanguage && bookLanguage.length() > 0) {
boolean res = Engine.checkFontLanguageCompatibility(fontFace, bookLanguage);
log.d("Checking font \"" + fontFace + "\" for compatibility with language \"" + bookLanguage + "\": res=" + res);
if (!res) {
mEngine.runInGUI(new Runnable() {
@Override
public void run() {
mActivity.showToast(R.string.font_not_compat_with_language, fontFace, bookLanguage);
}
});
}
} else {
log.d("Can't get book's language to check font compatibility! bookInfo=" + fileInfo);
}
}
doc.applySettings(props);
//syncViewSettings(props, save, saveDelayed);
drawPage();
Expand Down
20 changes: 3 additions & 17 deletions cr3qt/src/aboutdlg.ui
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,6 @@
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<!--
<item>
<widget class="QToolButton" name="btnSite">
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset resource="cr3res.qrc">
<normaloff>:/icons/action/icons/coolreader.png</normaloff>:/icons/action/icons/coolreader.png</iconset>
</property>
</widget>
</item>
-->
<item>
<widget class="QLabel" name="lblVersion">
<property name="font">
Expand Down Expand Up @@ -58,7 +45,7 @@
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string notr="true">(c) 1998-2018 Vadim Lopatin</string>
<string notr="true">(c) 1998-2019 Vadim Lopatin</string>
</property>
</widget>
</item>
Expand Down Expand Up @@ -94,6 +81,7 @@ p, li { white-space: pre-wrap; }
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-family:'DejaVu Sans'; font-size:9pt;&quot;&gt;libpng - PNG image format support&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-family:'DejaVu Sans'; font-size:9pt;&quot;&gt;libjpeg - JPEG image format support&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-family:'DejaVu Sans'; font-size:9pt;&quot;&gt;Hyphenation dictionaries - from AlReader&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-family:'DejaVu Sans'; font-size:9pt;&quot;&gt;Languages character set database by Fontconfig&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'DejaVu Sans'; font-size:9pt;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
Expand Down Expand Up @@ -452,9 +440,7 @@ See README.TXT at root directory of project for build instructions.
</item>
</layout>
</widget>
<resources>
<include location="cr3res.qrc"/>
</resources>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
Expand Down
27 changes: 27 additions & 0 deletions cr3qt/src/cr3widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@
#include <QtWidgets/QStyleFactory>
#include <QtWidgets/QStyle>
#include <QtWidgets/QApplication>
#include <QtWidgets/QMessageBox>
#else
#include <QtGui/QResizeEvent>
#include <QtGui/QScrollBar>
#include <QtGui/QMenu>
#include <QtGui/QStyleFactory>
#include <QtGui/QStyle>
#include <QtGui/QApplication>
#include <QtGui/QMessageBox>
#endif
#include <QUrl>
#include <QDir>
Expand Down Expand Up @@ -463,6 +465,7 @@ bool CR3View::loadDocument( QString fileName )
QByteArray utf8 = fileName.toUtf8();
CRLog::debug( "Trying to restore position for %s", utf8.constData() );
_docview->restorePosition();
checkFontLanguageCompatibility();
} else {
_docview->createDefaultDocument(lString16::empty_str, qt2cr(tr("Error while opening document ") + fileName));
}
Expand Down Expand Up @@ -842,6 +845,7 @@ PropsRef CR3View::setOptions( PropsRef props )
if ( _propsCallback != NULL )
_propsCallback->onPropsChange( unknownOptions );
saveSettings( QString() );
checkFontLanguageCompatibility();
update();
return unknownOptions;
}
Expand Down Expand Up @@ -1059,6 +1063,29 @@ bool CR3View::updateSelection( ldomXPointer p )
return true;
}

void CR3View::checkFontLanguageCompatibility()
{
lString16 fontFace;
_data->_props->getString(PROP_FONT_FACE, fontFace);
lString8 fontFace_u8 = UnicodeToUtf8(fontFace);
lString16 langCode = _docview->getLanguage();
lString8 langCode_u8 = UnicodeToUtf8(langCode);
if (langCode_u8.length() == 0) {
CRLog::debug("Can't fetch book's language to check font compatibility!");
return;
}
if (fontFace_u8.length() > 0) {
bool res = fontMan->checkFontLangCompat(fontFace_u8, langCode_u8);
CRLog::debug("Checking font \"%s\" for compatibility with language \"%s\": %d", fontFace_u8.c_str(), langCode_u8.c_str(), res);
if (!res)
{
QMessageBox::warning(this, tr("Warning"),
tr("Font \"%1\" isn't compatible with language \"%2\". Instead will be used fallback font.").arg(fontFace_u8.c_str()).arg(langCode_u8.c_str()),
QMessageBox::Ok);
}
}
}

void CR3View::mousePressEvent ( QMouseEvent * event )
{
bool left = event->button() == Qt::LeftButton;
Expand Down
1 change: 1 addition & 0 deletions cr3qt/src/cr3widget.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ class CR3View : public QWidget, public LVDocViewCallback
void startSelection( ldomXPointer p );
bool endSelection( ldomXPointer p );
bool updateSelection( ldomXPointer p );
void checkFontLanguageCompatibility();

DocViewData * _data; // to hide non-qt implementation
LVDocView * _docview;
Expand Down
2 changes: 2 additions & 0 deletions cr3qt/src/i18n/cr3_ru.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ p, li { white-space: pre-wrap; }
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-family:&apos;DejaVu Sans&apos;; font-size:9pt;&quot;&gt;libpng - PNG image format support&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-family:&apos;DejaVu Sans&apos;; font-size:9pt;&quot;&gt;libjpeg - JPEG image format support&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-family:&apos;DejaVu Sans&apos;; font-size:9pt;&quot;&gt;Hyphenation dictionaries - from AlReader&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-family:'DejaVu Sans'; font-size:9pt;&quot;&gt;Languages character set database by Fontconfig&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:&apos;DejaVu Sans&apos;; font-size:9pt;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</source>
<translation>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
Expand All @@ -65,6 +66,7 @@ p, li { white-space: pre-wrap; }
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-family:&apos;DejaVu Sans&apos;; font-size:9pt;&quot;&gt;libpng - библиотека поддержки изображений формата PNG&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-family:&apos;DejaVu Sans&apos;; font-size:9pt;&quot;&gt;libjpeg - библиотека поддержки изображений формата JPEG&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-family:&apos;DejaVu Sans&apos;; font-size:9pt;&quot;&gt;Словари переносов - из AlReader&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-family:'DejaVu Sans'; font-size:9pt;&quot;&gt;Набор символов различных письменностей от Fontconfig&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:&apos;DejaVu Sans&apos;; font-size:9pt;&quot;&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</translation>
</message>
<message>
Expand Down
5 changes: 4 additions & 1 deletion crengine/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@

include_directories(${CMAKE_CURRENT_SOURCE_DIR}/fc-lang)

SET (CRENGINE_SOURCES
src/cp_stats.cpp
src/lvstring.cpp
Expand All @@ -15,6 +18,7 @@ src/lvstsheet.cpp
src/txtselector.cpp
#src/xutils.cpp
src/crtest.cpp
fc-lang/fc-lang-cat.c
)

if ( NOT ${GUI} STREQUAL FB2PROPS )
Expand Down Expand Up @@ -43,4 +47,3 @@ if ( NOT ${GUI} STREQUAL FB2PROPS )
endif (NOT ${GUI} STREQUAL FB2PROPS)

ADD_LIBRARY(crengine STATIC ${CRENGINE_SOURCES})

Loading

0 comments on commit 7f52891

Please sign in to comment.