mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-03 17:59:33 +02:00
code simplification
This commit is contained in:
parent
1f4641085d
commit
3256027dd8
8 changed files with 24 additions and 93 deletions
|
@ -41,7 +41,6 @@ JavaClass AndroidUtil::Class_FileInfo("org/geometerplus/zlibrary/core/fonts/File
|
||||||
JavaClass AndroidUtil::Class_FileEncryptionInfo("org/geometerplus/zlibrary/core/drm/FileEncryptionInfo");
|
JavaClass AndroidUtil::Class_FileEncryptionInfo("org/geometerplus/zlibrary/core/drm/FileEncryptionInfo");
|
||||||
JavaClass AndroidUtil::Class_ZLFileImage("org/geometerplus/zlibrary/core/image/ZLFileImage");
|
JavaClass AndroidUtil::Class_ZLFileImage("org/geometerplus/zlibrary/core/image/ZLFileImage");
|
||||||
JavaClass AndroidUtil::Class_ZLTextModel("org/geometerplus/zlibrary/text/model/ZLTextModel");
|
JavaClass AndroidUtil::Class_ZLTextModel("org/geometerplus/zlibrary/text/model/ZLTextModel");
|
||||||
JavaClass AndroidUtil::Class_CachedCharStorageException("org/geometerplus/zlibrary/text/model/CachedCharStorageException");
|
|
||||||
|
|
||||||
JavaClass AndroidUtil::Class_Encoding("org/geometerplus/zlibrary/core/encodings/Encoding");
|
JavaClass AndroidUtil::Class_Encoding("org/geometerplus/zlibrary/core/encodings/Encoding");
|
||||||
JavaClass AndroidUtil::Class_EncodingConverter("org/geometerplus/zlibrary/core/encodings/EncodingConverter");
|
JavaClass AndroidUtil::Class_EncodingConverter("org/geometerplus/zlibrary/core/encodings/EncodingConverter");
|
||||||
|
|
|
@ -80,7 +80,6 @@ public:
|
||||||
static JavaClass Class_FileEncryptionInfo;
|
static JavaClass Class_FileEncryptionInfo;
|
||||||
static JavaClass Class_ZLFileImage;
|
static JavaClass Class_ZLFileImage;
|
||||||
static JavaClass Class_ZLTextModel;
|
static JavaClass Class_ZLTextModel;
|
||||||
static JavaClass Class_CachedCharStorageException;
|
|
||||||
static JavaClass Class_NativeFormatPlugin;
|
static JavaClass Class_NativeFormatPlugin;
|
||||||
static JavaClass Class_PluginCollection;
|
static JavaClass Class_PluginCollection;
|
||||||
static JavaClass Class_Encoding;
|
static JavaClass Class_Encoding;
|
||||||
|
|
|
@ -28,7 +28,7 @@ import org.geometerplus.zlibrary.text.model.*;
|
||||||
import org.geometerplus.fbreader.book.Book;
|
import org.geometerplus.fbreader.book.Book;
|
||||||
|
|
||||||
abstract class BookModelImpl extends BookModel {
|
abstract class BookModelImpl extends BookModel {
|
||||||
protected CharStorage myInternalHyperlinks;
|
protected CachedCharStorage myInternalHyperlinks;
|
||||||
protected final HashMap<String,ZLImage> myImageMap = new HashMap<String,ZLImage>();
|
protected final HashMap<String,ZLImage> myImageMap = new HashMap<String,ZLImage>();
|
||||||
protected final HashMap<String,ZLTextModel> myFootnotes = new HashMap<String,ZLTextModel>();
|
protected final HashMap<String,ZLTextModel> myFootnotes = new HashMap<String,ZLTextModel>();
|
||||||
|
|
||||||
|
|
|
@ -31,7 +31,7 @@ public class NativeBookModel extends BookModelImpl {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void initInternalHyperlinks(String directoryName, String fileExtension, int blocksNumber) {
|
public void initInternalHyperlinks(String directoryName, String fileExtension, int blocksNumber) {
|
||||||
myInternalHyperlinks = new CachedCharStorageRO(directoryName, fileExtension, blocksNumber);
|
myInternalHyperlinks = new CachedCharStorage(directoryName, fileExtension, blocksNumber);
|
||||||
}
|
}
|
||||||
|
|
||||||
private TOCTree myCurrentTree = TOCTree;
|
private TOCTree myCurrentTree = TOCTree;
|
||||||
|
@ -55,7 +55,7 @@ public class NativeBookModel extends BookModelImpl {
|
||||||
int[] paragraphLenghts, int[] textSizes, byte[] paragraphKinds,
|
int[] paragraphLenghts, int[] textSizes, byte[] paragraphKinds,
|
||||||
String directoryName, String fileExtension, int blocksNumber
|
String directoryName, String fileExtension, int blocksNumber
|
||||||
) {
|
) {
|
||||||
return new ZLTextNativeModel(
|
return new ZLTextPlainModel(
|
||||||
id, language, paragraphsNumber,
|
id, language, paragraphsNumber,
|
||||||
entryIndices, entryOffsets,
|
entryIndices, entryOffsets,
|
||||||
paragraphLenghts, textSizes, paragraphKinds,
|
paragraphLenghts, textSizes, paragraphKinds,
|
||||||
|
|
|
@ -24,20 +24,20 @@ import java.io.*;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
|
||||||
public final class CachedCharStorageRO implements CharStorage {
|
public final class CachedCharStorage {
|
||||||
protected final ArrayList<WeakReference<char[]>> myArray =
|
protected final ArrayList<WeakReference<char[]>> myArray =
|
||||||
new ArrayList<WeakReference<char[]>>();
|
new ArrayList<WeakReference<char[]>>();
|
||||||
|
|
||||||
private final String myDirectoryName;
|
private final String myDirectoryName;
|
||||||
private final String myFileExtension;
|
private final String myFileExtension;
|
||||||
|
|
||||||
public CachedCharStorageRO(String directoryName, String fileExtension, int blocksNumber) {
|
public CachedCharStorage(String directoryName, String fileExtension, int blocksNumber) {
|
||||||
myDirectoryName = directoryName + '/';
|
myDirectoryName = directoryName + '/';
|
||||||
myFileExtension = '.' + fileExtension;
|
myFileExtension = '.' + fileExtension;
|
||||||
myArray.addAll(Collections.nCopies(blocksNumber, new WeakReference<char[]>(null)));
|
myArray.addAll(Collections.nCopies(blocksNumber, new WeakReference<char[]>(null)));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String fileName(int index) {
|
private String fileName(int index) {
|
||||||
return myDirectoryName + index + myFileExtension;
|
return myDirectoryName + index + myFileExtension;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,25 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (C) 2007-2015 FBReader.ORG Limited <contact@fbreader.org>
|
|
||||||
*
|
|
||||||
* 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.zlibrary.text.model;
|
|
||||||
|
|
||||||
public interface CharStorage {
|
|
||||||
int size();
|
|
||||||
char[] block(int index);
|
|
||||||
}
|
|
|
@ -1,46 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (C) 2011-2015 FBReader.ORG Limited <contact@fbreader.org>
|
|
||||||
*
|
|
||||||
* 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.zlibrary.text.model;
|
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import org.geometerplus.zlibrary.core.fonts.FontManager;
|
|
||||||
import org.geometerplus.zlibrary.core.image.ZLImage;
|
|
||||||
|
|
||||||
public class ZLTextNativeModel extends ZLTextPlainModel {
|
|
||||||
public ZLTextNativeModel(
|
|
||||||
String id, String language, int paragraphsNumber,
|
|
||||||
int[] entryIndices, int[] entryOffsets,
|
|
||||||
int[] paragraphLengths, int[] textSizes,
|
|
||||||
byte[] paragraphKinds,
|
|
||||||
String directoryName, String fileExtension, int blocksNumber,
|
|
||||||
Map<String,ZLImage> imageMap,
|
|
||||||
FontManager fontManager
|
|
||||||
) {
|
|
||||||
super(
|
|
||||||
id, language,
|
|
||||||
entryIndices, entryOffsets, paragraphLengths, textSizes, paragraphKinds,
|
|
||||||
new CachedCharStorageRO(directoryName, fileExtension, blocksNumber),
|
|
||||||
imageMap,
|
|
||||||
fontManager
|
|
||||||
);
|
|
||||||
myParagraphsNumber = paragraphsNumber;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -25,20 +25,20 @@ import org.geometerplus.zlibrary.core.fonts.FontManager;
|
||||||
import org.geometerplus.zlibrary.core.image.ZLImage;
|
import org.geometerplus.zlibrary.core.image.ZLImage;
|
||||||
import org.geometerplus.zlibrary.core.util.*;
|
import org.geometerplus.zlibrary.core.util.*;
|
||||||
|
|
||||||
public class ZLTextPlainModel implements ZLTextModel, ZLTextStyleEntry.Feature {
|
public final class ZLTextPlainModel implements ZLTextModel, ZLTextStyleEntry.Feature {
|
||||||
private final String myId;
|
private final String myId;
|
||||||
private final String myLanguage;
|
private final String myLanguage;
|
||||||
|
|
||||||
protected int[] myStartEntryIndices;
|
private int[] myStartEntryIndices;
|
||||||
protected int[] myStartEntryOffsets;
|
private int[] myStartEntryOffsets;
|
||||||
protected int[] myParagraphLengths;
|
private int[] myParagraphLengths;
|
||||||
protected int[] myTextSizes;
|
private int[] myTextSizes;
|
||||||
protected byte[] myParagraphKinds;
|
private byte[] myParagraphKinds;
|
||||||
|
|
||||||
protected int myParagraphsNumber;
|
private int myParagraphsNumber;
|
||||||
|
|
||||||
protected final CharStorage myStorage;
|
private final CachedCharStorage myStorage;
|
||||||
protected final Map<String,ZLImage> myImageMap;
|
private final Map<String,ZLImage> myImageMap;
|
||||||
|
|
||||||
private ArrayList<ZLTextMark> myMarks;
|
private ArrayList<ZLTextMark> myMarks;
|
||||||
|
|
||||||
|
@ -298,26 +298,30 @@ public class ZLTextPlainModel implements ZLTextModel, ZLTextStyleEntry.Feature {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected ZLTextPlainModel(
|
public ZLTextPlainModel(
|
||||||
String id,
|
String id,
|
||||||
String language,
|
String language,
|
||||||
|
int paragraphsNumber,
|
||||||
int[] entryIndices,
|
int[] entryIndices,
|
||||||
int[] entryOffsets,
|
int[] entryOffsets,
|
||||||
int[] paragraphLenghts,
|
int[] paragraphLengths,
|
||||||
int[] textSizes,
|
int[] textSizes,
|
||||||
byte[] paragraphKinds,
|
byte[] paragraphKinds,
|
||||||
CharStorage storage,
|
String directoryName,
|
||||||
|
String fileExtension,
|
||||||
|
int blocksNumber,
|
||||||
Map<String,ZLImage> imageMap,
|
Map<String,ZLImage> imageMap,
|
||||||
FontManager fontManager
|
FontManager fontManager
|
||||||
) {
|
) {
|
||||||
myId = id;
|
myId = id;
|
||||||
myLanguage = language;
|
myLanguage = language;
|
||||||
|
myParagraphsNumber = paragraphsNumber;
|
||||||
myStartEntryIndices = entryIndices;
|
myStartEntryIndices = entryIndices;
|
||||||
myStartEntryOffsets = entryOffsets;
|
myStartEntryOffsets = entryOffsets;
|
||||||
myParagraphLengths = paragraphLenghts;
|
myParagraphLengths = paragraphLengths;
|
||||||
myTextSizes = textSizes;
|
myTextSizes = textSizes;
|
||||||
myParagraphKinds = paragraphKinds;
|
myParagraphKinds = paragraphKinds;
|
||||||
myStorage = storage;
|
myStorage = new CachedCharStorage(directoryName, fileExtension, blocksNumber);
|
||||||
myImageMap = imageMap;
|
myImageMap = imageMap;
|
||||||
myFontManager = fontManager;
|
myFontManager = fontManager;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue