diff --git a/TODO.1.4.6 b/TODO.1.4.6 index 718fe6a93..7f4a859c1 100644 --- a/TODO.1.4.6 +++ b/TODO.1.4.6 @@ -16,6 +16,7 @@ litres: author photos * ePubs in zips * scale-to-fullscreen for all pictures * show-hide temporary activity after brightness changing (to switch off the button lights) +* encodings list for native plugins * API от Paragon * rtf: cover? diff --git a/jni/NativeFormats/JavaPluginCollection.cpp b/jni/NativeFormats/JavaPluginCollection.cpp index d2e5ffc1d..fb9dbd4b3 100644 --- a/jni/NativeFormats/JavaPluginCollection.cpp +++ b/jni/NativeFormats/JavaPluginCollection.cpp @@ -34,7 +34,7 @@ JNIEXPORT jobjectArray JNICALL Java_org_geometerplus_fbreader_formats_PluginColl for (size_t i = 0; i < size; ++i) { jstring fileType = AndroidUtil::createJavaString(env, plugins[i]->supportedFileType()); - jobject p = AndroidUtil::Constructor_NativeFormatPlugin->call(fileType); + jobject p = AndroidUtil::StaticMethod_NativeFormatPlugin_create->call(fileType); env->SetObjectArrayElement(javaPlugins, i, p); env->DeleteLocalRef(p); env->DeleteLocalRef(fileType); diff --git a/jni/NativeFormats/util/AndroidUtil.cpp b/jni/NativeFormats/util/AndroidUtil.cpp index a2664de7b..1d490ceae 100644 --- a/jni/NativeFormats/util/AndroidUtil.cpp +++ b/jni/NativeFormats/util/AndroidUtil.cpp @@ -66,7 +66,7 @@ shared_ptr AndroidUtil::Method_java_io_InputStream_skip; shared_ptr AndroidUtil::StaticMethod_ZLibrary_Instance; shared_ptr AndroidUtil::Method_ZLibrary_getVersionName; -shared_ptr AndroidUtil::Constructor_NativeFormatPlugin; +shared_ptr AndroidUtil::StaticMethod_NativeFormatPlugin_create; shared_ptr AndroidUtil::Method_NativeFormatPlugin_supportedFileType; shared_ptr AndroidUtil::StaticMethod_PluginCollection_Instance; @@ -142,7 +142,7 @@ bool AndroidUtil::init(JavaVM* jvm) { StaticMethod_ZLibrary_Instance = new StaticObjectMethod(Class_ZLibrary, "Instance", Class_ZLibrary, "()"); Method_ZLibrary_getVersionName = new StringMethod(Class_ZLibrary, "getVersionName", "()"); - Constructor_NativeFormatPlugin = new Constructor(Class_NativeFormatPlugin, "(Ljava/lang/String;)V"); + StaticMethod_NativeFormatPlugin_create = new StaticObjectMethod(Class_NativeFormatPlugin, "create", Class_NativeFormatPlugin, "(Ljava/lang/String;)"); Method_NativeFormatPlugin_supportedFileType = new StringMethod(Class_NativeFormatPlugin, "supportedFileType", "()"); StaticMethod_PluginCollection_Instance = new StaticObjectMethod(Class_PluginCollection, "Instance", Class_PluginCollection, "()"); diff --git a/jni/NativeFormats/util/AndroidUtil.h b/jni/NativeFormats/util/AndroidUtil.h index 818df978a..0b838d010 100644 --- a/jni/NativeFormats/util/AndroidUtil.h +++ b/jni/NativeFormats/util/AndroidUtil.h @@ -98,7 +98,7 @@ public: static shared_ptr Constructor_ZLFileImage; - static shared_ptr Constructor_NativeFormatPlugin; + static shared_ptr StaticMethod_NativeFormatPlugin_create; static shared_ptr Method_NativeFormatPlugin_supportedFileType; static shared_ptr StaticMethod_PluginCollection_Instance; diff --git a/proguard.cfg b/proguard.cfg index c794de9c9..dc0283df8 100755 --- a/proguard.cfg +++ b/proguard.cfg @@ -40,6 +40,10 @@ -keepclassmembers class org.geometerplus.fbreader.formats.FormatPlugin { public ** supportedFileType(); } +-keep class org.geometerplus.fbreader.formats.NativeFormatPlugin +-keepclassmembers class org.geometerplus.fbreader.formats.NativeFormatPlugin { + public static ** create(**); +} -keep class org.geometerplus.zlibrary.core.encodings.Encoding -keepclassmembers class org.geometerplus.zlibrary.core.encodings.Encoding { public ** createConverter(); diff --git a/src/org/geometerplus/fbreader/formats/FormatPlugin.java b/src/org/geometerplus/fbreader/formats/FormatPlugin.java index 01483da75..f0a32d47f 100644 --- a/src/org/geometerplus/fbreader/formats/FormatPlugin.java +++ b/src/org/geometerplus/fbreader/formats/FormatPlugin.java @@ -38,6 +38,9 @@ public abstract class FormatPlugin { return myFileType; } + public ZLFile realBookFile(ZLFile file) throws BookReadingException { + return file; + } public abstract void readMetaInfo(Book book) throws BookReadingException; public abstract void readModel(BookModel model) throws BookReadingException; public abstract void detectLanguageAndEncoding(Book book) throws BookReadingException; diff --git a/src/org/geometerplus/fbreader/formats/NativeFormatPlugin.java b/src/org/geometerplus/fbreader/formats/NativeFormatPlugin.java index 17a6753aa..2711e9a76 100644 --- a/src/org/geometerplus/fbreader/formats/NativeFormatPlugin.java +++ b/src/org/geometerplus/fbreader/formats/NativeFormatPlugin.java @@ -20,6 +20,7 @@ package org.geometerplus.fbreader.formats; import org.geometerplus.zlibrary.core.filesystem.ZLFile; +import org.geometerplus.zlibrary.core.encodings.EncodingCollection; import org.geometerplus.zlibrary.core.encodings.JavaEncodingCollection; import org.geometerplus.zlibrary.core.image.*; import org.geometerplus.zlibrary.core.util.MimeType; @@ -27,12 +28,18 @@ import org.geometerplus.zlibrary.core.util.MimeType; import org.geometerplus.fbreader.bookmodel.BookModel; import org.geometerplus.fbreader.bookmodel.BookReadingException; import org.geometerplus.fbreader.library.Book; +import org.geometerplus.fbreader.formats.fb2.FB2NativePlugin; public class NativeFormatPlugin extends FormatPlugin { - // No free method because all plugins' instances are freed by - // PluginCollection::deleteInstance method (C++) + public static NativeFormatPlugin create(String fileType) { + if ("fb2".equals(fileType)) { + return new FB2NativePlugin(); + } else { + return new NativeFormatPlugin(fileType); + } + } - public NativeFormatPlugin(String fileType) { + protected NativeFormatPlugin(String fileType) { super(fileType); } @@ -97,7 +104,7 @@ public class NativeFormatPlugin extends FormatPlugin { } @Override - public JavaEncodingCollection supportedEncodings() { + public EncodingCollection supportedEncodings() { // TODO: implement return JavaEncodingCollection.Instance(); } diff --git a/src/org/geometerplus/fbreader/formats/fb2/FB2NativePlugin.java b/src/org/geometerplus/fbreader/formats/fb2/FB2NativePlugin.java new file mode 100644 index 000000000..79c74c91a --- /dev/null +++ b/src/org/geometerplus/fbreader/formats/fb2/FB2NativePlugin.java @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2011-2012 Geometer Plus + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + */ + +package org.geometerplus.fbreader.formats.fb2; + +import org.geometerplus.zlibrary.core.encodings.EncodingCollection; +import org.geometerplus.zlibrary.core.encodings.AutoEncodingCollection; + +import org.geometerplus.zlibrary.core.filesystem.ZLFile; + +import org.geometerplus.fbreader.formats.NativeFormatPlugin; + +public class FB2NativePlugin extends NativeFormatPlugin { + public FB2NativePlugin() { + super("fb2"); + } + + @Override + public ZLFile realBookFile(ZLFile file) { + return FB2Util.getRealFB2File(file); + } + + @Override + public EncodingCollection supportedEncodings() { + return new AutoEncodingCollection(); + } +} diff --git a/src/org/geometerplus/fbreader/formats/fb2/FB2Plugin.java b/src/org/geometerplus/fbreader/formats/fb2/FB2Plugin.java index 82fe2c8c0..75359bcb7 100644 --- a/src/org/geometerplus/fbreader/formats/fb2/FB2Plugin.java +++ b/src/org/geometerplus/fbreader/formats/fb2/FB2Plugin.java @@ -33,6 +33,11 @@ public class FB2Plugin extends JavaFormatPlugin { super("fb2"); } + @Override + public ZLFile realBookFile(ZLFile file) { + return FB2Util.getRealFB2File(file); + } + @Override public void readMetaInfo(Book book) throws BookReadingException { new FB2MetaInfoReader(book).readMetaInfo(); diff --git a/src/org/geometerplus/fbreader/formats/fb2/FB2Util.java b/src/org/geometerplus/fbreader/formats/fb2/FB2Util.java new file mode 100644 index 000000000..2f2352bca --- /dev/null +++ b/src/org/geometerplus/fbreader/formats/fb2/FB2Util.java @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2012 Geometer Plus + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + */ + +package org.geometerplus.fbreader.formats.fb2; + +import java.util.List; + +import org.geometerplus.zlibrary.core.filesystem.ZLFile; + +abstract class FB2Util { + static ZLFile getRealFB2File(ZLFile file) { + final String name = file.getShortName().toLowerCase(); + if (name.endsWith(".fb2.zip") && file.isArchive()) { + final List children = file.children(); + if (children != null && children.size() == 1) { + return children.get(0); + } else { + return null; + } + } else { + return file; + } + } +}