public static int Build(XmlDocument dom, out LabelParam label_param, out string strError) { strError = ""; int nRet = 0; label_param = new LabelParam(); XmlNode label = dom.DocumentElement.SelectSingleNode("label"); if (label != null) { // int nValue = 0; double fValue = 0; // width nRet = DomUtil.GetDoubleParam(label, "width", 0, out fValue, out strError); if (nRet == -1) { return(-1); } label_param.LabelWidth = fValue; // height nRet = DomUtil.GetDoubleParam(label, "height", 0, out fValue, out strError); if (nRet == -1) { return(-1); } label_param.LabelHeight = fValue; // lineSep nRet = DomUtil.GetDoubleParam(label, "lineSep", 0, out fValue, out strError); if (nRet == -1) { return(-1); } label_param.LineSep = fValue; { DecimalPadding margins; string strPaddings = DomUtil.GetAttr(label, "paddings"); nRet = GetMarginValue( strPaddings, out margins, out strError); if (nRet == -1) { strError = "<label>元素paddings属性值格式错误: " + strError; return(-1); } label_param.LabelPaddings = margins; } #if NO try { string strPaddings = DomUtil.GetAttr(label, "paddings"); string[] parts = strPaddings.Split(new char[] { ',' }); if (parts.Length > 0) { label_param.LabelPaddings.Left = Convert.ToInt32(parts[0]); } if (parts.Length > 1) { label_param.LabelPaddings.Top = Convert.ToInt32(parts[1]); } if (parts.Length > 2) { label_param.LabelPaddings.Right = Convert.ToInt32(parts[2]); } if (parts.Length > 3) { label_param.LabelPaddings.Bottom = Convert.ToInt32(parts[3]); } } catch (Exception ex) { strError = "<label>元素paddings属性值格式错误: " + ex.Message; return(-1); } #endif string strFont = DomUtil.GetAttr(label, "font"); if (String.IsNullOrEmpty(strFont) == false) { if (Global.IsVirtualBarcodeFont(ref strFont) == true) { label_param.IsBarcodeFont = true; } try { label_param.Font = Global.BuildFont(strFont); } catch (Exception ex) { strError = "<label>元素 font 属性值格式错误: " + ex.Message; return(-1); } } } XmlNode page = dom.DocumentElement.SelectSingleNode("page"); if (page != null) { { // int nValue = 0; double fValue = 0; // width nRet = DomUtil.GetDoubleParam(page, "width", 0, out fValue, out strError); if (nRet == -1) { return(-1); } label_param.PageWidth = fValue; // height nRet = DomUtil.GetDoubleParam(page, "height", 0, out fValue, out strError); if (nRet == -1) { return(-1); } label_param.PageHeight = fValue; } { DecimalPadding margins; string strMargins = DomUtil.GetAttr(page, "margins"); nRet = GetMarginValue( strMargins, out margins, out strError); if (nRet == -1) { strError = "<page>元素margins属性值格式错误: " + strError; return(-1); } label_param.PageMargins = margins; } #if NO try { string strMargins = DomUtil.GetAttr(page, "margins"); string[] parts = strMargins.Split(new char[] { ',' }); if (parts.Length > 0) { label_param.PageMargins.Left = Convert.ToInt32(parts[0]); } if (parts.Length > 1) { label_param.PageMargins.Top = Convert.ToInt32(parts[1]); } if (parts.Length > 2) { label_param.PageMargins.Right = Convert.ToInt32(parts[2]); } if (parts.Length > 3) { label_param.PageMargins.Bottom = Convert.ToInt32(parts[3]); } } catch (Exception ex) { strError = "<page>元素margins属性值格式错误: " + ex.Message; return(-1); } #endif label_param.DefaultPrinter = DomUtil.GetAttr(page, "defaultPrinter"); #if NO bool bValue = false; nRet = DomUtil.GetBooleanParam(page, "landscape", false, out bValue, out strError); if (nRet == -1) { strError = "<page> 元素的 landscape 属性错误: " + strError; return(-1); } label_param.Landscape = bValue; #endif int nValue = 0; DomUtil.GetIntegerParam(page, "rotate", 0, out nValue, out strError); if (nRet == -1) { strError = "<page> 元素的 rotate 属性错误: " + strError; return(-1); } label_param.RotateDegree = nValue; } XmlNodeList nodes = dom.DocumentElement.SelectNodes("lineFormats/line"); label_param.LineFormats = new List <LineFormat>(); for (int i = 0; i < nodes.Count; i++) { XmlNode node = nodes[i]; string strFont = DomUtil.GetAttr(node, "font"); LineFormat format = new LineFormat(); if (Global.IsVirtualBarcodeFont(ref strFont) == true) { format.IsBarcodeFont = true; } if (string.IsNullOrEmpty(strFont) == false) { try { format.Font = Global.BuildFont(strFont); } catch (Exception ex) { strError = "<line>元素font属性值格式错误: " + ex.Message; return(-1); } } else { format.Font = null; // 继承页面的字体 } format.Align = DomUtil.GetAttr(node, "align"); string strOffset = DomUtil.GetAttr(node, "offset"); if (string.IsNullOrEmpty(strOffset) == false) { try { double left = 0; double right = 0; ParsetTwoDouble(strOffset, false, out left, out right); format.OffsetX = left; format.OffsetY = right; } catch (Exception ex) { strError = "<line>元素offset属性值格式错误: " + ex.Message; return(-1); } } string strStart = DomUtil.GetAttr(node, "start"); if (string.IsNullOrEmpty(strStart) == false) { try { double left = double.NaN; double right = double.NaN; ParsetTwoDouble(strStart, true, out left, out right); format.StartX = left; format.StartY = right; } catch (Exception ex) { strError = "<line>元素start属性值格式错误: " + ex.Message; return(-1); } } string strSize = DomUtil.GetAttr(node, "size"); if (string.IsNullOrEmpty(strSize) == false) { try { double left = double.NaN; double right = double.NaN; ParsetTwoDouble(strSize, true, out left, out right); format.Width = left; format.Height = right; } catch (Exception ex) { strError = "<line>元素size属性值格式错误: " + ex.Message; return(-1); } } format.ForeColor = DomUtil.GetAttr(node, "foreColor"); format.BackColor = DomUtil.GetAttr(node, "backColor"); label_param.LineFormats.Add(format); } return(0); }