[sword-svn] r153 - in trunk: . app/src/org/crosswire/flashcards src/org/crosswire/flashcards
Apache
apache at www.crosswire.org
Sun Sep 7 08:22:15 MST 2008
Author:
Date: 2008-09-07 08:22:15 -0700 (Sun, 07 Sep 2008)
New Revision: 153
Modified:
trunk/app/src/org/crosswire/flashcards/ComplexLesson.java
trunk/genfcmobile.sh
trunk/src/org/crosswire/flashcards/FlashCard.java
Log:
added auto font selection
Modified: trunk/app/src/org/crosswire/flashcards/ComplexLesson.java
===================================================================
--- trunk/app/src/org/crosswire/flashcards/ComplexLesson.java 2008-09-07 10:48:35 UTC (rev 152)
+++ trunk/app/src/org/crosswire/flashcards/ComplexLesson.java 2008-09-07 15:22:15 UTC (rev 153)
@@ -50,6 +50,8 @@
private static final String DIR_PROJECT = ".flashcards";
static String homeProjectPath = "";
static Hashtable fontURLCache = new Hashtable();
+ static Font otFont = null;
+ static Font ntFont = null;
static {
try {
homeProjectPath = System.getProperty("user.home") + File.separator + DIR_PROJECT;
@@ -68,78 +70,99 @@
}
- /**
- * Load this lesson from persistent store named by the lesson's <code>filename</code>.
- */
- public void load() {
- try {
- URL lessonURL = new URL(getURL());
- Properties lesson = new Properties();
- lesson.load(lessonURL.openConnection().getInputStream());
- int wordCount = Integer.parseInt(lesson.getProperty("wordCount"));
- setDescription(lesson.getProperty("lessonTitle", getURL().substring(getURL().lastIndexOf('/') + 1)));
-
- // try to find font if we've been given a lessonFont
- String font = lesson.getProperty("lessonFont");
+ public String findFont(String fontName) {
+ String retVal = null;
// while loop is not really to loop, but instead for break when we find the font
- while (font != null && font.length() > 0) {
+ while (fontName != null && fontName.length() > 0) {
- // try to find font in cache
- String cachedURL = (String)fontURLCache.get(font);
+ // try to find fontName in cache
+ String cachedURL = (String)fontURLCache.get(fontName);
if (cachedURL != null) {
- setFont(cachedURL);
+ retVal = cachedURL;
break;
}
- // try to find font in ./<FONT>.ttf
+ // try to find fontName in ./<FONT>.ttf
try {
- String fontPath = "./" + File.separator + font + ".ttf";
+ String fontPath = "./" + File.separator + fontName + ".ttf";
File fontFile = new File(fontPath);
if (fontFile.exists()) {
String url = fontFile.toURL().toString();
- setFont(url);
- fontURLCache.put(font, url);
-System.out.println("found font in ./; URL: " + url);
+ retVal = url;
+ fontURLCache.put(fontName, url);
+System.out.println("found fontName in ./; URL: " + url);
break;
}
}
catch (AccessControlException ea) {}
catch (Exception e) { e.printStackTrace(); }
- // try to find font in ~/.flashcards/<FONT>.ttf
+ // try to find fontName in ~/.flashcards/<FONT>.ttf
try {
- String fontPath = homeProjectPath + File.separator + font + ".ttf";
+ String fontPath = homeProjectPath + File.separator + fontName + ".ttf";
File fontFile = new File(fontPath);
if (fontFile.exists()) {
String url = fontFile.toURL().toString();
- setFont(url);
- fontURLCache.put(font, url);
-System.out.println("found font in ~/.flashcards; URL: " + url);
+ retVal = url;
+ fontURLCache.put(fontName, url);
+System.out.println("found fontName in ~/.flashcards; URL: " + url);
break;
}
}
catch (AccessControlException ea) {}
catch (Exception e) { e.printStackTrace(); }
- // try to find font on our classpath
+ // try to find fontName on our classpath
try {
- URL fontURL = ComplexLesson.class.getResource("/" + font + ".ttf");
+ URL fontURL = ComplexLesson.class.getResource("/" + fontName + ".ttf");
if (fontURL != null) {
URLConnection connection = null;
connection = fontURL.openConnection();
- setFont(fontURL.toString());
- fontURLCache.put(font, fontURL.toString());
-System.out.println("found font on classpath");
+ retVal = fontURL.toString();
+ fontURLCache.put(fontName, fontURL.toString());
+System.out.println("found fontName on classpath");
break;
}
}
catch (AccessControlException ea) {}
catch (Exception e) { e.printStackTrace(); }
-System.out.println("didn't find font");
- break; // didn't find the font, must break out of while
+System.out.println("didn't find fontName");
+ break; // didn't find the fontName, must break out of while
}
+ return retVal;
+ }
+
+ /**
+ * Load this lesson from persistent store named by the lesson's <code>filename</code>.
+ */
+ public void load() {
+ try {
+ URL lessonURL = new URL(getURL());
+ Properties lesson = new Properties();
+ lesson.load(lessonURL.openConnection().getInputStream());
+ int wordCount = Integer.parseInt(lesson.getProperty("wordCount"));
+ setDescription(lesson.getProperty("lessonTitle", getURL().substring(getURL().lastIndexOf('/') + 1)));
+
+ // try to find font if we've been given a lessonFont
+ String fontName = lesson.getProperty("lessonFont");
+ if (fontName == null || fontName.length() < 1 || fontName.equalsIgnoreCase("auto")) {
+ setFont(null);
+ if (otFont == null) {
+ String fontURL = findFont("SILEOT");
+ otFont = loadFont(fontURL);
+ }
+ if (ntFont == null) {
+ String fontURL = findFont("GalSILB201");
+ ntFont = loadFont(fontURL);
+ }
+ }
+ else {
+ String fontURL = findFont(fontName);
+ if (fontURL != null) setFont(fontURL);
+ }
+
int baseOffset = getURL().lastIndexOf("/");
if (baseOffset < 0) {
baseOffset = getURL().lastIndexOf( ("\\"));
@@ -268,15 +291,32 @@
final int width = 800;
final int height = 40;
Font font = null;
- if (getFont() != null && getFont().length() > 0) {
+ Font ntFont = null;
+ Font otFont = null;
+ boolean autoFont = false;
+ String fontName = getFont();
+ if (fontName == null || fontName.length() < 1 || fontName.equalsIgnoreCase("auto")) {
+ autoFont = true;
+ if (this.otFont != null) {
+ otFont = this.otFont.deriveFont(Font.BOLD, (int)(height*.75));
+ }
+ if (this.ntFont != null) {
+ ntFont = this.ntFont.deriveFont(Font.BOLD, (int)(height*.75));
+ }
+ }
+ else {
Font newFont = loadFont(getFont());
font = newFont.deriveFont(Font.BOLD, (int)(height*.75));
}
-// else font = new Font(g2d.getFont().getName(), Font.BOLD, (int)(height*.75));
int i = 0;
for (; i < getFlashcards().size(); i++) {
FlashCard f = (FlashCard)getFlashcards().elementAt(i);
+ if (autoFont) {
+ font = null;
+ if (f.isHebrew()) font = otFont;
+ if (f.isGreek()) font = ntFont;
+ }
String imageURLString = imagesPath + "/" + lname + "_" + Integer.toString(i) + ".png";
// Save it as a "home" resource.
URL filePath = new URL(imageURLString);
Modified: trunk/genfcmobile.sh
===================================================================
--- trunk/genfcmobile.sh 2008-09-07 10:48:35 UTC (rev 152)
+++ trunk/genfcmobile.sh 2008-09-07 15:22:15 UTC (rev 153)
@@ -37,7 +37,7 @@
cd ${WORKDIR}
JARSIZE=`ls -l ${PKGNAME}.jar |cut -f5 -d' '`
sed -i s/##SIZE##/${JARSIZE}/ ${PKGNAME}.jad
- sed -i s/##HTMLBASE##/${HTMLBASE}/ ${PKGNAME}.jad
+ sed -i s!##HTMLBASE##!${HTMLBASE}! ${PKGNAME}.jad
cat >> packages/index.jsp <<!
<a href="/fc/${PKGNAME}.jad">$i$partNumber</a><br/>
!
Modified: trunk/src/org/crosswire/flashcards/FlashCard.java
===================================================================
--- trunk/src/org/crosswire/flashcards/FlashCard.java 2008-09-07 10:48:35 UTC (rev 152)
+++ trunk/src/org/crosswire/flashcards/FlashCard.java 2008-09-07 15:22:15 UTC (rev 153)
@@ -113,6 +113,17 @@
values.put(imageURL, newImageURL);
}
+ public boolean isGreek() {
+ int firstGlyph = getFront().charAt(0);
+ return ((firstGlyph >= 880 && firstGlyph <= 1023)
+ || (firstGlyph >= 7936 && firstGlyph <= 8191));
+ }
+
+ public boolean isHebrew() {
+ int firstGlyph = getFront().charAt(0);
+ return ((firstGlyph >= 1424 && firstGlyph <= 1535)
+ || (firstGlyph >= 64256 && firstGlyph <= 64335));
+ }
/**
* Method reset
*/
More information about the sword-cvs
mailing list