Loading core/java/android/text/Hyphenator.java +22 −11 Original line number Diff line number Diff line Loading @@ -30,7 +30,7 @@ import java.util.Locale; * * @hide */ /* package */ class Hyphenator { public class Hyphenator { // This class has deliberately simple lifetime management (no finalizer) because in // the common case a process will use a very small number of locales. Loading @@ -45,20 +45,14 @@ import java.util.Locale; } public static long get(Locale locale) { synchronized (sMap) { Hyphenator result = sMap.get(locale); if (result == null) { result = loadHyphenator(locale); sMap.put(locale, result); } return result == null ? 0 : result.mNativePtr; } } private static Hyphenator loadHyphenator(Locale locale) { // TODO: find pattern dictionary (from system location) that best matches locale if (Locale.US.equals(locale)) { File f = new File("/data/local/tmp/hyph-en-us.pat.txt"); File f = new File(getSystemHyphenatorLocation(), "hyph-en-us.pat.txt"); try { RandomAccessFile rf = new RandomAccessFile(f, "r"); byte[] buf = new byte[(int)rf.length()]; Loading @@ -68,9 +62,26 @@ import java.util.Locale; long nativePtr = StaticLayout.nLoadHyphenator(patternData); return new Hyphenator(nativePtr); } catch (IOException e) { Log.e(TAG, "error loading hyphenation " + f); Log.e(TAG, "error loading hyphenation " + f, e); } } return null; } private static File getSystemHyphenatorLocation() { // TODO: move to a sensible location under system return new File("/system/usr/hyphen-data"); } /** * Load hyphenation patterns at initialization time. We want to have patterns * for all locales loaded and ready to use so we don't have to do any file IO * on the UI thread when drawing text in different locales. * * @hide */ public static void init() { Locale l = Locale.US; sMap.put(l, loadHyphenator(l)); } } core/java/com/android/internal/os/ZygoteInit.java +6 −0 Original line number Diff line number Diff line Loading @@ -32,6 +32,7 @@ import android.system.ErrnoException; import android.system.Os; import android.system.OsConstants; import android.system.StructPollfd; import android.text.Hyphenator; import android.util.EventLog; import android.util.Log; import android.webkit.WebViewFactory; Loading Loading @@ -182,6 +183,7 @@ public class ZygoteInit { preloadResources(); preloadOpenGL(); preloadSharedLibraries(); preloadTextResources(); // Ask the WebViewFactory to do any initialization that must run in the zygote process, // for memory sharing purposes. WebViewFactory.prepareWebViewInZygote(); Loading @@ -201,6 +203,10 @@ public class ZygoteInit { } } private static void preloadTextResources() { Hyphenator.init(); } /** * Performs Zygote process initialization. Loads and initializes * commonly used classes. Loading Loading
core/java/android/text/Hyphenator.java +22 −11 Original line number Diff line number Diff line Loading @@ -30,7 +30,7 @@ import java.util.Locale; * * @hide */ /* package */ class Hyphenator { public class Hyphenator { // This class has deliberately simple lifetime management (no finalizer) because in // the common case a process will use a very small number of locales. Loading @@ -45,20 +45,14 @@ import java.util.Locale; } public static long get(Locale locale) { synchronized (sMap) { Hyphenator result = sMap.get(locale); if (result == null) { result = loadHyphenator(locale); sMap.put(locale, result); } return result == null ? 0 : result.mNativePtr; } } private static Hyphenator loadHyphenator(Locale locale) { // TODO: find pattern dictionary (from system location) that best matches locale if (Locale.US.equals(locale)) { File f = new File("/data/local/tmp/hyph-en-us.pat.txt"); File f = new File(getSystemHyphenatorLocation(), "hyph-en-us.pat.txt"); try { RandomAccessFile rf = new RandomAccessFile(f, "r"); byte[] buf = new byte[(int)rf.length()]; Loading @@ -68,9 +62,26 @@ import java.util.Locale; long nativePtr = StaticLayout.nLoadHyphenator(patternData); return new Hyphenator(nativePtr); } catch (IOException e) { Log.e(TAG, "error loading hyphenation " + f); Log.e(TAG, "error loading hyphenation " + f, e); } } return null; } private static File getSystemHyphenatorLocation() { // TODO: move to a sensible location under system return new File("/system/usr/hyphen-data"); } /** * Load hyphenation patterns at initialization time. We want to have patterns * for all locales loaded and ready to use so we don't have to do any file IO * on the UI thread when drawing text in different locales. * * @hide */ public static void init() { Locale l = Locale.US; sMap.put(l, loadHyphenator(l)); } }
core/java/com/android/internal/os/ZygoteInit.java +6 −0 Original line number Diff line number Diff line Loading @@ -32,6 +32,7 @@ import android.system.ErrnoException; import android.system.Os; import android.system.OsConstants; import android.system.StructPollfd; import android.text.Hyphenator; import android.util.EventLog; import android.util.Log; import android.webkit.WebViewFactory; Loading Loading @@ -182,6 +183,7 @@ public class ZygoteInit { preloadResources(); preloadOpenGL(); preloadSharedLibraries(); preloadTextResources(); // Ask the WebViewFactory to do any initialization that must run in the zygote process, // for memory sharing purposes. WebViewFactory.prepareWebViewInZygote(); Loading @@ -201,6 +203,10 @@ public class ZygoteInit { } } private static void preloadTextResources() { Hyphenator.init(); } /** * Performs Zygote process initialization. Loads and initializes * commonly used classes. Loading