mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-06 03:50:19 +02:00
fonts catalog rescan has been added
This commit is contained in:
parent
5a8ea802f7
commit
b11d3bdf81
4 changed files with 34 additions and 12 deletions
|
@ -1,2 +1 @@
|
||||||
* Пересканировать файлы шрифтов время от времени -- чтобы замечать добавившиеся
|
|
||||||
* (?) Показывать названия шрифтов соответсвующими шрифтами
|
* (?) Показывать названия шрифтов соответсвующими шрифтами
|
||||||
|
|
|
@ -36,7 +36,7 @@ class FontOption extends ZLStringListPreference {
|
||||||
|
|
||||||
myOption = option;
|
myOption = option;
|
||||||
final ArrayList<String> fonts = new ArrayList<String>();
|
final ArrayList<String> fonts = new ArrayList<String>();
|
||||||
AndroidFontUtil.fillFamiliesList(fonts);
|
AndroidFontUtil.fillFamiliesList(fonts, true);
|
||||||
setList((String[])fonts.toArray(new String[fonts.size()]));
|
setList((String[])fonts.toArray(new String[fonts.size()]));
|
||||||
|
|
||||||
final String initialValue = AndroidFontUtil.realFontFamilyName(option.getValue());
|
final String initialValue = AndroidFontUtil.realFontFamilyName(option.getValue());
|
||||||
|
|
|
@ -56,18 +56,41 @@ public final class AndroidFontUtil {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Map<String,File[]> ourFontMap;
|
private static Map<String,File[]> ourFontMap;
|
||||||
public static Map<String,File[]> getFontMap() {
|
private static File[] ourFileList;
|
||||||
if (ourFontMap == null) {
|
private static long myTimeStamp;
|
||||||
|
public static Map<String,File[]> getFontMap(boolean forceReload) {
|
||||||
|
final long timeStamp = System.currentTimeMillis();
|
||||||
|
if (forceReload && timeStamp < myTimeStamp + 1000) {
|
||||||
|
forceReload = false;
|
||||||
|
}
|
||||||
|
myTimeStamp = timeStamp;
|
||||||
|
if (ourFontMap == null || forceReload) {
|
||||||
|
boolean rebuildMap = ourFontMap == null;
|
||||||
if (ourFontCreationMethod == null) {
|
if (ourFontCreationMethod == null) {
|
||||||
|
if (rebuildMap) {
|
||||||
ourFontMap = new HashMap<String,File[]>();
|
ourFontMap = new HashMap<String,File[]>();
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
ourFontMap = new ZLTTFInfoDetector().collectFonts(new File(Paths.FontsDirectoryOption().getValue()).listFiles(
|
final File[] fileList = new File(Paths.FontsDirectoryOption().getValue()).listFiles(
|
||||||
new FilenameFilter() {
|
new FilenameFilter() {
|
||||||
public boolean accept(File dir, String name) {
|
public boolean accept(File dir, String name) {
|
||||||
return name.toLowerCase().endsWith(".ttf") && !name.startsWith(".");
|
return name.toLowerCase().endsWith(".ttf") && !name.startsWith(".");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
));
|
);
|
||||||
|
if (fileList == null) {
|
||||||
|
if (ourFileList != null) {
|
||||||
|
ourFileList = null;
|
||||||
|
rebuildMap = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (fileList != null && !fileList.equals(ourFileList)) {
|
||||||
|
ourFileList = fileList;
|
||||||
|
rebuildMap = true;
|
||||||
|
}
|
||||||
|
if (rebuildMap) {
|
||||||
|
ourFontMap = new ZLTTFInfoDetector().collectFonts(fileList);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ourFontMap;
|
return ourFontMap;
|
||||||
|
@ -83,7 +106,7 @@ public final class AndroidFontUtil {
|
||||||
if ("monospace".equalsIgnoreCase(fontFamily) || "droid mono".equalsIgnoreCase(fontFamily)) {
|
if ("monospace".equalsIgnoreCase(fontFamily) || "droid mono".equalsIgnoreCase(fontFamily)) {
|
||||||
return "monospace";
|
return "monospace";
|
||||||
}
|
}
|
||||||
for (String name : getFontMap().keySet()) {
|
for (String name : getFontMap(false).keySet()) {
|
||||||
if (name.equalsIgnoreCase(fontFamily)) {
|
if (name.equalsIgnoreCase(fontFamily)) {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
@ -91,11 +114,11 @@ public final class AndroidFontUtil {
|
||||||
return "sans-serif";
|
return "sans-serif";
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void fillFamiliesList(ArrayList<String> families) {
|
public static void fillFamiliesList(ArrayList<String> families, boolean forceReload) {
|
||||||
families.add("Droid Sans");
|
families.add("Droid Sans");
|
||||||
families.add("Droid Serif");
|
families.add("Droid Serif");
|
||||||
families.add("Droid Mono");
|
families.add("Droid Mono");
|
||||||
families.addAll(getFontMap().keySet());
|
families.addAll(getFontMap(forceReload).keySet());
|
||||||
Collections.sort(families);
|
Collections.sort(families);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -116,7 +116,7 @@ public final class ZLAndroidPaintContext extends ZLPaintContext {
|
||||||
}
|
}
|
||||||
Typeface tf = typefaces[style];
|
Typeface tf = typefaces[style];
|
||||||
if (tf == null) {
|
if (tf == null) {
|
||||||
File[] files = AndroidFontUtil.getFontMap().get(family);
|
File[] files = AndroidFontUtil.getFontMap(false).get(family);
|
||||||
if (files != null) {
|
if (files != null) {
|
||||||
try {
|
try {
|
||||||
if (files[style] != null) {
|
if (files[style] != null) {
|
||||||
|
@ -233,6 +233,6 @@ public final class ZLAndroidPaintContext extends ZLPaintContext {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void fillFamiliesList(ArrayList<String> families) {
|
protected void fillFamiliesList(ArrayList<String> families) {
|
||||||
AndroidFontUtil.fillFamiliesList(families);
|
AndroidFontUtil.fillFamiliesList(families, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue