/// <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); }
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"); } }