Beispiel #1
0
        /**
         * @param lang
         * @param country
         * @return the hyphenation tree
         */
        public static HyphenationTree GetHyphenationTree(String lang,
                                                         String country)
        {
            String key = lang;

            // check whether the country code has been used
            if (country != null && !country.Equals("none"))
            {
                key += "_" + country;
            }
            // first try to find it in the cache
            if (hyphenTrees.ContainsKey(key))
            {
                return((HyphenationTree)hyphenTrees[key]);
            }
            if (hyphenTrees.ContainsKey(lang))
            {
                return((HyphenationTree)hyphenTrees[lang]);
            }

            HyphenationTree hTree = GetResourceHyphenationTree(key);

            //if (hTree == null)
            //    hTree = GetFileHyphenationTree(key);
            // put it into the pattern cache
            if (hTree != null)
            {
                hyphenTrees[key] = hTree;
            }
            return(hTree);
        }
Beispiel #2
0
 /**
  * @param lang
  * @param country
  * @param leftMin
  * @param rightMin
  */
 public Hyphenator(String lang, String country, int leftMin,
                   int rightMin)
 {
     hyphenTree      = GetHyphenationTree(lang, country);
     remainCharCount = leftMin;
     pushCharCount   = rightMin;
 }
Beispiel #3
0
        /**
         * @param lang
         * @param country
         * @param word
         * @param offset
         * @param len
         * @param leftMin
         * @param rightMin
         * @return a hyphenation object
         */
        public static Hyphenation Hyphenate(String lang, String country,
                                            char[] word, int offset, int len,
                                            int leftMin, int rightMin)
        {
            HyphenationTree hTree = GetHyphenationTree(lang, country);

            if (hTree == null)
            {
                //log.Error("Error building hyphenation tree for language "
                //                       + lang);
                return(null);
            }
            return(hTree.Hyphenate(word, offset, len, leftMin, rightMin));
        }
Beispiel #4
0
 /**
  * @param key
  * @return a hyphenation tree
  */
 public static HyphenationTree GetResourceHyphenationTree(String key)
 {
     try {
         Stream stream = BaseFont.GetResourceStream(defaultHyphLocation + key + ".xml");
         if (stream == null && key.Length > 2)
         {
             stream = BaseFont.GetResourceStream(defaultHyphLocation + key.Substring(0, 2) + ".xml");
         }
         if (stream == null)
         {
             return(null);
         }
         HyphenationTree hTree = new HyphenationTree();
         hTree.LoadSimplePatterns(stream);
         return(hTree);
     }
     catch {
         return(null);
     }
 }
Beispiel #5
0
 /**
  * @param lang
  * @param country
  */
 public void SetLanguage(String lang, String country)
 {
     hyphenTree = GetHyphenationTree(lang, country);
 }