Inheritance: TernaryTree, IPatternConsumer
 /**
  * @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;
 }
        /**
         * @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);
        }
示例#3
0
        public static HyphenationTree getFopHyphenationTree(string key)
        {
            HyphenationTree hTree = null;
            Stream          istr  = null;

            try {
                istr = getResourceStream(key);
                if (istr == null)
                {
                    if (key.Length == 5)
                    {
                        istr = getResourceStream(key.Substring(0, 2));
                        if (istr != null)
                        {
                            Console.Error.WriteLine("Couldn't find hyphenation pattern  "
                                                    + key
                                                    + "\nusing general language pattern "
                                                    + key.Substring(0, 2)
                                                    + " instead.");
                        }
                        else
                        {
                            if (errorDump)
                            {
                                Console.Error.WriteLine("Couldn't find precompiled "
                                                        + "hyphenation pattern "
                                                        + key + ".hyp");
                            }
                            return(null);
                        }
                    }
                    else
                    {
                        if (errorDump)
                        {
                            Console.Error.WriteLine("Couldn't find precompiled "
                                                    + "hyphenation pattern "
                                                    + key + ".hyp");
                        }
                        return(null);
                    }
                }
                hTree = new HyphenationTree();
                hTree.loadInternalPatterns(istr);
            } catch (Exception e) {
                Console.Error.WriteLine(e.StackTrace);
            }
            finally {
                if (istr != null)
                {
                    try {
                        istr.Close();
                    } catch (IOException e) {
                        e.GetType();
                        Console.Error.WriteLine("can't close hyphenation stream");
                    }
                }
            }
            return(hTree);
        }
示例#4
0
 /// <summary>
 /// </summary>
 /// <param name="lang"></param>
 /// <param name="country"></param>
 /// <param name="leftMin"></param>
 /// <param name="rightMin"></param>
 public Hyphenator(string lang, string country, int leftMin,
                   int rightMin)
 {
     _hyphenTree      = GetHyphenationTree(lang, country);
     _remainCharCount = leftMin;
     _pushCharCount   = rightMin;
 }
示例#5
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;
 }
        /**
         * @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));
        }
示例#7
0
        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)
            {
                Console.Error.WriteLine("Error building hyphenation tree for language "
                                        + lang);
                return(null);
            }
            return(hTree.hyphenate(word, offset, len, leftMin, rightMin));
        }
示例#8
0
        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 = getFopHyphenationTree(key);

            if (hTree == null)
            {
                //string hyphenDir = "e:\\winprog2\\Fop-0.20.2\\hyph";
                //Configuration.getstringValue("hyphenation-dir");
                if (hyphenDir != null)
                {
                    hTree = getUserHyphenationTree(key, hyphenDir);
                }
            }
            // put it into the pattern cache
            if (hTree != null)
            {
                hyphenTrees.Add(key, hTree);
            }
            else
            {
                Console.Error.WriteLine("Couldn't find hyphenation pattern "
                                        + key);
            }
            return(hTree);
        }
 /**
  * @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);
     }
 }
示例#10
0
 /**
 * @param key
 * @return a hyphenation tree
 */
 public static HyphenationTree GetResourceHyphenationTree(String key) {
     try {
         Stream stream = StreamUtil.GetResourceStream(defaultHyphLocation + key + ".xml");
         if (stream == null && key.Length > 2)
             stream = StreamUtil.GetResourceStream(defaultHyphLocation + key.Substring(0, 2) + ".xml");
         if (stream == null)
             return null;
         HyphenationTree hTree = new HyphenationTree();
         hTree.LoadSimplePatterns(stream);
         return hTree;
     }
     catch {
         return null;
     }
 }
示例#11
0
 /**
 * @param lang
 * @param country
 */
 virtual public void SetLanguage(String lang, String country) {
     hyphenTree = GetHyphenationTree(lang, country);
 }
示例#12
0
 /**
  * @param lang
  * @param country
  */
 public void SetLanguage(String lang, String country)
 {
     hyphenTree = GetHyphenationTree(lang, country);
 }
示例#13
0
 /// <summary>
 /// </summary>
 /// <param name="lang"></param>
 /// <param name="country"></param>
 public void SetLanguage(string lang, string country) => _hyphenTree = GetHyphenationTree(lang, country);
示例#14
0
 public void setLanguage(string lang, string country)
 {
     hyphenTree = getHyphenationTree(lang, country);
 }