예제 #1
0
 /// <summary>
 /// 创建亮度预处理器的实例。
 /// </summary>
 public LightPreHandler()
 {
     _data             = new Symbol.IO.Packing.TreePackage();
     _data.EncryptType = Symbol.IO.Packing.PackageEncryptTypes.BinaryWave_EmptyPassword;
     _value            = 0;
     _data.Add("value", _value);
 }
 /// <summary>
 /// 加载数据。
 /// </summary>
 /// <param name="data">从数据包中加载。</param>
 public void Load(Symbol.IO.Packing.TreePackage data)
 {
     _data   = data;
     _left   = TypeExtensions.Convert <int>(_data["left"], 0);
     _top    = TypeExtensions.Convert <int>(_data["top"], 0);
     _right  = TypeExtensions.Convert <int>(_data["right"], 0);
     _bottom = TypeExtensions.Convert <int>(_data["bottom"], 0);
 }
예제 #3
0
 public static void SaveConfig()
 {
     try {
         Symbol.IO.Packing.TreePackage data = new Symbol.IO.Packing.TreePackage();
         _config.Save(data, "");
         string path = System.IO.Path.Combine(Application.StartupPath, "config.o");
         System.IO.File.WriteAllBytes(path, data.Save(_passwordConfig));
     } catch { }
 }
 /// <summary>
 /// 创建清除边框预处理器的实例。
 /// </summary>
 public ClearBorderPreHandler()
 {
     _data             = new Symbol.IO.Packing.TreePackage();
     _data.EncryptType = Symbol.IO.Packing.PackageEncryptTypes.BinaryWave_EmptyPassword;
     _left             = _top = _right = _bottom = 0;
     _data.Add("left", _left)
     .Add("top", _top)
     .Add("right", _right)
     .Add("bottom", _bottom);
 }
예제 #5
0
        /// <summary>
        /// 创建清除边框预处理器的实例。
        /// </summary>
        public XStrikethroughPreHandler()
        {
            _data             = new Symbol.IO.Packing.TreePackage();
            _data.EncryptType = Symbol.IO.Packing.PackageEncryptTypes.BinaryWave_EmptyPassword;

            _span             = 0.1F;
            _continuousDegree = 3;
            _data.Add("span", _span)
            .Add("continuousDegree", _continuousDegree);
        }
예제 #6
0
            public byte[] Save(object instance)
            {
                CharPointCollection collection = instance as CharPointCollection;

                if (collection == null)
                {
                    return(new byte[0]);
                }
                Symbol.IO.Packing.TreePackage data = new Symbol.IO.Packing.TreePackage();
                data.Add("0", collection._list);
                return(data.Save());
            }
예제 #7
0
        /// <summary>
        /// 加载数据
        /// </summary>
        /// <param name="reader">树型包读取器实例</param>
        /// <param name="password">密码,为空将会是默认密码。</param>
        /// <returns>返回加载后的字库。</returns>
        public static CharLibrary Load(System.IO.Stream reader, byte[] password = null)
        {
            Symbol.IO.Packing.TreePackage data = Symbol.IO.Packing.TreePackage.Load(reader, password);
            if (data == null || data.Count < 5 || !data.ContainsKey("name"))
            {
                return(null);
            }
            CharLibrary result = new CharLibrary();

            LoadValues(data, result);
            return(result);
        }
예제 #8
0
        public void Save(Symbol.IO.Packing.TreePackage data, string keyBefore = null)
        {
            //data[keyBefore + "DatabaseServer"] = DatabaseServer;
            //data[keyBefore + "DatabaseAccount"] = DatabaseAccount;
            //data[keyBefore + "DatabasePassword"] = DatabasePassword;

            data[keyBefore + "FontName"] = FontName;
            data[keyBefore + "FontSize"] = FontSize;

            data[keyBefore + "ItemPerPage"] = ItemPerPage;

            data[keyBefore + "Account"]     = Account;
            data[keyBefore + "Password"]    = Password;
            data[keyBefore + "IsRemember"]  = IsRemember;
            data[keyBefore + "IsAutoLogin"] = IsAutoLogin;
        }
예제 #9
0
            public object Load(byte[] buffer)
            {
                Symbol.IO.Packing.TreePackage data = Symbol.IO.Packing.TreePackage.Load(buffer);
                if (data == null)
                {
                    return(null);
                }
                CharPointCollection collection = new CharPointCollection();
                List <CharPoint>    list       = data["0"] as List <CharPoint>;

                if (list != null)
                {
                    collection._list.AddRange(list);
                }

                return(collection);
            }
예제 #10
0
 static void LoadConfig()
 {
     _config = new Config();
     try {
         string path = System.IO.Path.Combine(Application.StartupPath, "config.o");
         if (System.IO.File.Exists(path))
         {
             using (System.IO.FileStream stream = System.IO.File.OpenRead(path)) {
                 Symbol.IO.Packing.TreePackage data = Symbol.IO.Packing.TreePackage.Load(stream, _passwordConfig);
                 _config.Load(data, "");
             }
         }
         else
         {
             SaveConfig();
         }
     } catch { }
 }
예제 #11
0
        public void Load(Symbol.IO.Packing.TreePackage data, string keyBefore = null)
        {
            //DatabaseServer = data[keyBefore + "DatabaseServer"] as string;
            //DatabaseAccount = data[keyBefore + "DatabaseAccount"] as string;
            //DatabasePassword = data[keyBefore + "DatabasePassword"] as string;

            FontName = data[keyBefore + "FontName"] as string;
            if (string.IsNullOrEmpty(FontName))
            {
                FontName = "宋体";
            }
            FontSize = TypeExtensions.Convert <float>(data[keyBefore + "FontSize"], 9F);

            ItemPerPage = TypeExtensions.Convert <int>(data[keyBefore + "ItemPerPage"], 25);

            Account     = data[keyBefore + "Account"] as string;
            Password    = data[keyBefore + "Password"] as string;
            IsRemember  = TypeExtensions.Convert <bool>(data[keyBefore + "IsRemember"], false);
            IsAutoLogin = TypeExtensions.Convert <bool>(data[keyBefore + "IsAutoLogin"], false);
        }
예제 #12
0
        /// <summary>
        /// 创建字库实例,会创建一个字库模板。
        /// </summary>
        public CharLibrary()
        {
            _name             = "新建字库";
            _version          = DateTime.Today.ToString("yyyyMMdd");
            _description      = "";
            _width            = 100;
            _height           = 20;
            _charWidth        = 12;
            _charHeight       = 18;
            _charMaxWidth     = 14;
            _minPoints        = 10;
            _needCenterMiddle = true;
            _emptyColorR      = 255;
            _zool             = 1.0F;
            _pageUrl          = "";
            _codeUrl          = "";
            _extension        = ".jpg";
            _preHandlers      = new System.Collections.Generic.List <IPreHandler>();
            _takeHandler      = TakeHandlerHelper.CreateInstance("YDotMatrix");

            _chars          = new System.Collections.Generic.List <CharInfo>();
            _charRecognizer = CharRecognizerHelper.CreateInstance("Weight3x3");
            _data           = new Symbol.IO.Packing.TreePackage();
            _data.Add("name", _name)
            .Add("version", _version)
            .Add("description", _description)
            .Add("width", _width)
            .Add("height", _height)
            .Add("charWidth", _charWidth)
            .Add("charHeight", _charHeight)
            .Add("charMaxWidth", _charMaxWidth)
            .Add("minPoints", _minPoints)
            .Add("needCenterMiddle", _needCenterMiddle)
            .Add("emptyColorR", _emptyColorR)
            .Add("zool", _zool)
            .Add("pageUrl", _pageUrl)
            .Add("codeUrl", _codeUrl)
            .Add("extension", _extension)
            .Add("preHandlers", 0)
            .Add("chars", 0);
        }
예제 #13
0
 /// <summary>
 /// 加载数据。
 /// </summary>
 /// <param name="data">从数据包中加载。</param>
 public void Load(Symbol.IO.Packing.TreePackage data)
 {
     _data             = data;
     _span             = TypeExtensions.Convert <float>(_data["span"], 0F);
     _continuousDegree = TypeExtensions.Convert <int>(_data["continuousDegree"], 0);
 }
예제 #14
0
 /// <summary>
 /// 创建清除边框预处理器的实例。
 /// </summary>
 public ClearBackColorPreHandler()
 {
     _data             = new Symbol.IO.Packing.TreePackage();
     _data.EncryptType = Symbol.IO.Packing.PackageEncryptTypes.BinaryWave_EmptyPassword;
 }
예제 #15
0
 /// <summary>
 /// 创建灰度化预处理器的实例。
 /// </summary>
 public GrayscalePreHandler()
 {
     _data             = new Symbol.IO.Packing.TreePackage();
     _data.EncryptType = Symbol.IO.Packing.PackageEncryptTypes.BinaryWave_EmptyPassword;
 }
 /// <summary>
 /// 创建加权3x3字符识别器的实例。
 /// </summary>
 public Weight3x3CharRecognizer()
 {
     _data             = new Symbol.IO.Packing.TreePackage();
     _data.EncryptType = Symbol.IO.Packing.PackageEncryptTypes.BinaryWave_EmptyPassword;
 }
예제 #17
0
        void SaveBefore()
        {
            _data["preHandlers"] = _preHandlers.Count;
            string[] oriKeys = LinqHelper.ToArray(LinqHelper.Where(_data.Keys, p => p.StartsWith("pre_")));
            foreach (string key in oriKeys)
            {
                _data.Remove(key, false);
            }
            for (int i = 0; i < _preHandlers.Count; i++)
            {
                _data.Add("pre_" + i + "_" + _preHandlers[i].Name, _preHandlers[i].Save());
            }

            //_data["takeHandlers"] = _takeHandlers.Count;
            //string[] oriKeys2 = LinqHelper.ToArray(LinqHelper.Where(_data.Keys, p => p.StartsWith("take_")));
            //foreach (string key in oriKeys2) { _data.Remove(key,false); }
            //for (int i = 0; i < _takeHandlers.Count; i++) {
            //    _data.Add("take_" + i + "_" + _takeHandlers[i].Name, _takeHandlers[i].Save());
            //}

            string[] oriKeys3 = LinqHelper.ToArray(LinqHelper.Where(_data.Keys, p => p.StartsWith("char_")));
            foreach (string key in oriKeys3)
            {
                _data.Remove(key, false);
            }
            _data["chars"] = _chars.Count;
            for (int i = 0; i < _chars.Count; i++)
            {
                if (_chars[i].Value == null)
                {
                    continue;
                }
                Symbol.IO.Packing.TreePackage charData = new Symbol.IO.Packing.TreePackage()
                {
                    EncryptType = Symbol.IO.Packing.PackageEncryptTypes.BinaryWave_EmptyPassword
                };
                CharPointCollection collection = _chars[i].Points;
                charData.Add("count", collection.Count);
                for (int j = 0; j < collection.Count; j++)
                {
                    string keyBefore = j + "_";
                    charData.Add(keyBefore + "OriginalX", collection[j].OriginalX);
                    charData.Add(keyBefore + "OriginalY", collection[j].OriginalY);
                    charData.Add(keyBefore + "X", collection[j].X);
                    charData.Add(keyBefore + "Y", collection[j].Y);
                    charData.Add(keyBefore + "R", collection[j].R);
                    charData.Add(keyBefore + "G", collection[j].G);
                    charData.Add(keyBefore + "B", collection[j].B);
                }
                _data.Add("char_" + i + "_" + _chars[i].Value, charData);
            }
            string takeHandlerKeyBefore = "takeHandler_";
            string takeHandlerKeyOri    = LinqHelper.FirstOrDefault(_data.Keys, p => p.StartsWith(takeHandlerKeyBefore));

            if (!string.IsNullOrEmpty(takeHandlerKeyOri))
            {
                _data.Remove(takeHandlerKeyOri, false);
            }
            string takeHandlerKey = takeHandlerKeyBefore + _takeHandler.Name;

            _data.Add(takeHandlerKey, _takeHandler.Save());

            string charRecognizerKeyBefore = "charRecognizer_";
            string charRecognizerKeyOri    = LinqHelper.FirstOrDefault(_data.Keys, p => p.StartsWith(charRecognizerKeyBefore));

            if (!string.IsNullOrEmpty(charRecognizerKeyOri))
            {
                _data.Remove(charRecognizerKeyOri, false);
            }
            string charRecognizerKey = charRecognizerKeyBefore + _charRecognizer.Name;

            _data.Add(charRecognizerKey, _charRecognizer.Save());
        }
예제 #18
0
 /// <summary>
 /// 创建Y点阵取字处理器的实例。
 /// </summary>
 public YDotMatrixTakeHandler()
 {
     _data             = new Symbol.IO.Packing.TreePackage();
     _data.EncryptType = Symbol.IO.Packing.PackageEncryptTypes.BinaryWave_EmptyPassword;
 }
예제 #19
0
        static void LoadValues(Symbol.IO.Packing.TreePackage data, CharLibrary result)
        {
            result._data             = data;
            result._name             = data["name"] as string;
            result._version          = data["version"] as string;
            result._description      = data["description"] as string;
            result._width            = TypeExtensions.Convert <int>(data["width"], 0);
            result._height           = TypeExtensions.Convert <int>(data["height"], 0);
            result._charWidth        = TypeExtensions.Convert <int>(data["charWidth"], 0);
            result._charHeight       = TypeExtensions.Convert <int>(data["charHeight"], 0);
            result._charMaxWidth     = TypeExtensions.Convert <int>(data["charMaxWidth"], 0);
            result._minPoints        = TypeExtensions.Convert <int>(data["minPoints"], 0);
            result._needCenterMiddle = TypeExtensions.Convert <bool>(data["needCenterMiddle"], false);
            result._emptyColorR      = TypeExtensions.Convert <byte>(data["emptyColorR"], 0);
            result._zool             = TypeExtensions.Convert <float>(data["zool"], 1.0F);
            if (result._zool <= 0F)
            {
                result._zool = 1.0F;
            }
            result._pageUrl   = data["pageUrl"] as string;
            result._codeUrl   = data["codeUrl"] as string;
            result._extension = data["extension"] as string;

            int preCount = TypeExtensions.Convert <int>(data["preHandlers"], 0);

            result._preHandlers.Clear();
            if (preCount > 0)
            {
                for (int i = 0; i < preCount; i++)
                {
                    string keyBefore = "pre_" + i + "_";
                    string key       = LinqHelper.FirstOrDefault(data.Keys, p => p.StartsWith(keyBefore));
                    if (string.IsNullOrEmpty(key))
                    {
                        continue;
                    }
                    IPreHandler handler = PreHandlerHelper.CreateInstance(key.Substring(keyBefore.Length));
                    if (handler == null)
                    {
                        continue;
                    }
                    handler.Load((Symbol.IO.Packing.TreePackage)data[key]);
                    result._preHandlers.Add(handler);
                }
            }

            //int takeCount = TypeExtensions.Convert<int>(data["takeHandlers"], 0);
            //result._takeHandlers.Clear();
            //if (takeCount > 0) {
            //    for (int i = 0; i < takeCount; i++) {
            //        string keyBefore = "take_" + i + "_";
            //        string key = LinqHelper.FirstOrDefault(data.Keys, p => p.StartsWith(keyBefore));
            //        if (string.IsNullOrEmpty(key))
            //            continue;
            //        ITakeHandler handler = TakeHandlerHelper.CreateInstance(key.Substring(keyBefore.Length));
            //        if (handler == null)
            //            continue;
            //        handler.Load((Symbol.IO.Packing.TreePackage)data[key]);
            //        result._takeHandlers.Add(handler);
            //    }
            //}
            //if (result._takeHandlers.Count == 0) {
            //    result._takeHandlers.Add(TakeHandlerHelper.CreateInstance("YDotMatrix"));
            //}

            int charCount = TypeExtensions.Convert <int>(data["chars"], 0);

            result._chars.Clear();
            if (charCount > 0)
            {
                for (int i = 0; i < charCount; i++)
                {
                    string keyBefore = "char_" + i + "_";
                    string key       = LinqHelper.FirstOrDefault(data.Keys, p => p.StartsWith(keyBefore));
                    if (string.IsNullOrEmpty(key) || key.Length == keyBefore.Length)
                    {
                        continue;
                    }
                    Symbol.IO.Packing.TreePackage charData = (Symbol.IO.Packing.TreePackage)data[key];
                    if (charData == null)
                    {
                        continue;
                    }

                    CharInfo charInfo = new CharInfo()
                    {
                        Value = key.Substring(keyBefore.Length)[0]
                    };
                    int pointCount = TypeExtensions.Convert <int>(charData["count"], 0);
                    if (pointCount > 0)
                    {
                        for (int j = 0; j < pointCount; j++)
                        {
                            string    keyBefore2 = j + "_";
                            CharPoint charPoint  = new CharPoint()
                            {
                                OriginalX = TypeExtensions.Convert <int>(charData[keyBefore2 + "OriginalX"], 0),
                                OriginalY = TypeExtensions.Convert <int>(charData[keyBefore2 + "OriginalY"], 0),
                                X         = TypeExtensions.Convert <int>(charData[keyBefore2 + "X"], 0),
                                Y         = TypeExtensions.Convert <int>(charData[keyBefore2 + "Y"], 0),
                                R         = TypeExtensions.Convert <byte>(charData[keyBefore2 + "R"], 0),
                                G         = TypeExtensions.Convert <byte>(charData[keyBefore2 + "G"], 0),
                                B         = TypeExtensions.Convert <byte>(charData[keyBefore2 + "B"], 0),
                            };
                            charInfo.Points.Add(charPoint);
                        }
                    }
                    result._chars.Add(charInfo);
                }
            }
            string takeHandlerKeyBefore = "takeHandler_";
            string takeHandlerKey       = LinqHelper.FirstOrDefault(data.Keys, p => p.StartsWith(takeHandlerKeyBefore));

            if (!string.IsNullOrEmpty(takeHandlerKey) && takeHandlerKey.Length != takeHandlerKeyBefore.Length)
            {
                result._takeHandler = TakeHandlerHelper.CreateInstance(takeHandlerKey.Substring(takeHandlerKeyBefore.Length));
                if (result._takeHandler != null)
                {
                    Symbol.IO.Packing.TreePackage takeHandlerData = (Symbol.IO.Packing.TreePackage)data[takeHandlerKey];
                    result._takeHandler.Load(takeHandlerData);
                }
            }
            if (result._takeHandler == null)
            {
                result._takeHandler = TakeHandlerHelper.CreateInstance("YDotMatrix");
            }

            string charRecognizerKeyBefore = "charRecognizer_";
            string charRecognizerKey       = LinqHelper.FirstOrDefault(data.Keys, p => p.StartsWith(charRecognizerKeyBefore));

            if (!string.IsNullOrEmpty(charRecognizerKey) && charRecognizerKey.Length != charRecognizerKeyBefore.Length)
            {
                result._charRecognizer = CharRecognizerHelper.CreateInstance(charRecognizerKey.Substring(charRecognizerKeyBefore.Length));
                if (result._charRecognizer != null)
                {
                    Symbol.IO.Packing.TreePackage charRecognizerData = (Symbol.IO.Packing.TreePackage)data[charRecognizerKey];
                    result._charRecognizer.Load(charRecognizerData);
                }
            }
            if (result._charRecognizer == null)
            {
                result._charRecognizer = CharRecognizerHelper.CreateInstance("Weight3x3");
            }
        }
 /// <summary>
 /// 创建清除边框预处理器的实例。
 /// </summary>
 public MonochromeHSB8PreHandler()
 {
     _data             = new Symbol.IO.Packing.TreePackage();
     _data.EncryptType = Symbol.IO.Packing.PackageEncryptTypes.BinaryWave_EmptyPassword;
 }
예제 #21
0
 /// <summary>
 /// 加载数据。
 /// </summary>
 /// <param name="data">从数据包中加载。</param>
 public void Load(Symbol.IO.Packing.TreePackage data)
 {
     _data  = data;
     _value = TypeExtensions.Convert <int>(_data["value"], 0);
 }
 /// <summary>
 /// 加载数据。
 /// </summary>
 /// <param name="data">从数据包中加载。</param>
 public void Load(Symbol.IO.Packing.TreePackage data)
 {
     _data = data;
 }