mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-03 17:59:33 +02:00
better Literata font support
This commit is contained in:
parent
c383bb444f
commit
5db6f46910
3 changed files with 66 additions and 41 deletions
|
@ -4,7 +4,10 @@
|
||||||
* (planned) Fixed authors list/tags list editing
|
* (planned) Fixed authors list/tags list editing
|
||||||
* (planned) CSS selectors priority
|
* (planned) CSS selectors priority
|
||||||
|
|
||||||
===== 2.5 beta 2 (Jun ??, 2015) =====
|
===== 2.5 beta 3 (Jun ??, 2015) =====
|
||||||
|
* Better Literata font support
|
||||||
|
|
||||||
|
===== 2.5 beta 2 (Jun 16, 2015) =====
|
||||||
* Hide outline on clicking footnote's 'more' button
|
* Hide outline on clicking footnote's 'more' button
|
||||||
* Better look for menu activities in Android 5+
|
* Better look for menu activities in Android 5+
|
||||||
* Separate resources for en and en_US
|
* Separate resources for en and en_US
|
||||||
|
|
|
@ -19,7 +19,22 @@
|
||||||
|
|
||||||
package org.geometerplus.zlibrary.core.util;
|
package org.geometerplus.zlibrary.core.util;
|
||||||
|
|
||||||
public class ZLTTFInfo {
|
public final class ZLTTFInfo {
|
||||||
public String FamilyName;
|
public final String FamilyName;
|
||||||
public String SubFamilyName;
|
public final String SubfamilyName;
|
||||||
|
|
||||||
|
public ZLTTFInfo(String family, String subfamily) {
|
||||||
|
FamilyName = family;
|
||||||
|
if ("Literata".equals(family) && "Bold Literata".equals(subfamily)) {
|
||||||
|
SubfamilyName = "Bold Italic";
|
||||||
|
} else {
|
||||||
|
SubfamilyName = subfamily;
|
||||||
|
}
|
||||||
|
System.err.println(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "FontInfo [" + FamilyName + " (" + SubfamilyName + ")]";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,40 +43,42 @@ public class ZLTTFInfoDetector {
|
||||||
try {
|
try {
|
||||||
stream = new FileInputStream(f);
|
stream = new FileInputStream(f);
|
||||||
final ZLTTFInfo info = detectInfo(stream);
|
final ZLTTFInfo info = detectInfo(stream);
|
||||||
if (info != null && info.FamilyName != null) {
|
if (info == null) {
|
||||||
String familyName = info.FamilyName;
|
continue;
|
||||||
String subfamilyName = info.SubFamilyName;
|
}
|
||||||
if (subfamilyName == null || !STYLES.contains(subfamilyName.toLowerCase())) {
|
|
||||||
final String full =
|
String family = info.FamilyName;
|
||||||
subfamilyName != null ? familyName + " " + subfamilyName : familyName;
|
String subfamily = info.SubfamilyName;
|
||||||
final String lower = full.toLowerCase();
|
if (subfamily == null || !STYLES.contains(subfamily.toLowerCase())) {
|
||||||
familyName = full;
|
final String full =
|
||||||
subfamilyName = "";
|
subfamily != null ? family + " " + subfamily : family;
|
||||||
for (String style : STYLES) {
|
final String lower = full.toLowerCase();
|
||||||
if (lower.endsWith(" " + style)) {
|
family = full;
|
||||||
familyName = full.substring(0, lower.length() - style.length() - 1);
|
subfamily = "";
|
||||||
subfamilyName = full.substring(lower.length() - style.length());
|
for (String style : STYLES) {
|
||||||
break;
|
if (lower.endsWith(" " + style)) {
|
||||||
}
|
family = full.substring(0, lower.length() - style.length() - 1);
|
||||||
|
subfamily = full.substring(lower.length() - style.length());
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
File[] table = fonts.get(familyName);
|
File[] table = fonts.get(family);
|
||||||
if (table == null) {
|
if (table == null) {
|
||||||
table = new File[4];
|
table = new File[4];
|
||||||
fonts.put(familyName, table);
|
fonts.put(family, table);
|
||||||
}
|
}
|
||||||
if ("bold".equalsIgnoreCase(subfamilyName)) {
|
if ("bold".equalsIgnoreCase(subfamily)) {
|
||||||
table[1] = f;
|
table[1] = f;
|
||||||
} else if ("italic".equalsIgnoreCase(subfamilyName) ||
|
} else if ("italic".equalsIgnoreCase(subfamily) ||
|
||||||
"oblique".equalsIgnoreCase(subfamilyName)) {
|
"oblique".equalsIgnoreCase(subfamily)) {
|
||||||
table[2] = f;
|
table[2] = f;
|
||||||
} else if ("bold italic".equalsIgnoreCase(subfamilyName) ||
|
} else if ("bold italic".equalsIgnoreCase(subfamily) ||
|
||||||
"bold oblique".equalsIgnoreCase(subfamilyName)) {
|
"bold oblique".equalsIgnoreCase(subfamily)) {
|
||||||
table[3] = f;
|
table[3] = f;
|
||||||
} else {
|
} else {
|
||||||
table[0] = f;
|
table[0] = f;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
@ -197,7 +199,8 @@ public class ZLTTFInfoDetector {
|
||||||
}
|
}
|
||||||
final int count = Math.min(getInt16(buffer, 2), (buffer.length - 6) / 12);
|
final int count = Math.min(getInt16(buffer, 2), (buffer.length - 6) / 12);
|
||||||
final int stringOffset = getInt16(buffer, 4);
|
final int stringOffset = getInt16(buffer, 4);
|
||||||
final ZLTTFInfo fontInfo = new ZLTTFInfo();
|
String family = null;
|
||||||
|
String subfamily = null;
|
||||||
for (int i = 0; i < count; ++i) {
|
for (int i = 0; i < count; ++i) {
|
||||||
final int platformId = getInt16(buffer, 12 * i + 6);
|
final int platformId = getInt16(buffer, 12 * i + 6);
|
||||||
//final int platformSpecificId = getInt16(buffer, 12 * i + 8);
|
//final int platformSpecificId = getInt16(buffer, 12 * i + 8);
|
||||||
|
@ -205,20 +208,24 @@ public class ZLTTFInfoDetector {
|
||||||
final int nameId = getInt16(buffer, 12 * i + 12);
|
final int nameId = getInt16(buffer, 12 * i + 12);
|
||||||
final int length = getInt16(buffer, 12 * i + 14);
|
final int length = getInt16(buffer, 12 * i + 14);
|
||||||
final int offset = getInt16(buffer, 12 * i + 16);
|
final int offset = getInt16(buffer, 12 * i + 16);
|
||||||
|
System.err.println(nameId + ": " + new String(
|
||||||
|
buffer, stringOffset + offset, length,
|
||||||
|
platformId == 1 ? "ISO-8859-1" : "UTF-16BE"
|
||||||
|
));
|
||||||
switch (nameId) {
|
switch (nameId) {
|
||||||
case 1:
|
case 1:
|
||||||
if ((fontInfo.FamilyName == null || languageId == 1033) &&
|
if ((family == null || languageId == 1033) &&
|
||||||
stringOffset + offset + length <= buffer.length) {
|
stringOffset + offset + length <= buffer.length) {
|
||||||
fontInfo.FamilyName = new String(
|
family = new String(
|
||||||
buffer, stringOffset + offset, length,
|
buffer, stringOffset + offset, length,
|
||||||
platformId == 1 ? "ISO-8859-1" : "UTF-16BE"
|
platformId == 1 ? "ISO-8859-1" : "UTF-16BE"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
if ((fontInfo.FamilyName == null || languageId == 1033) &&
|
if ((subfamily == null || languageId == 1033) &&
|
||||||
stringOffset + offset + length <= buffer.length) {
|
stringOffset + offset + length <= buffer.length) {
|
||||||
fontInfo.SubFamilyName = new String(
|
subfamily = new String(
|
||||||
buffer, stringOffset + offset, length,
|
buffer, stringOffset + offset, length,
|
||||||
platformId == 1 ? "ISO-8859-1" : "UTF-16BE"
|
platformId == 1 ? "ISO-8859-1" : "UTF-16BE"
|
||||||
);
|
);
|
||||||
|
@ -226,6 +233,6 @@ public class ZLTTFInfoDetector {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return fontInfo;
|
return family != null ? new ZLTTFInfo(family, subfamily) : null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue