public static StyleItemCollection GetStyleItemCollection(string temp) { StyleItemCollection styleItem = new StyleItemCollection(); string[] lines = temp.Split(';'); foreach (String aLine in lines) { string itemTxt = aLine.Trim(); string[] itemToken = itemTxt.Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries); if (itemToken.Length == 2) { styleItem[itemToken[0].Trim().ToLower()] = itemToken[1].Trim(); } } return(styleItem); }
/* * /// <summary> * /// 자기 자신 이외에 추가적으로 높이가 추가되는 태그(BR/P등)의 높이를 추가한다. * /// </summary> * /// <returns></returns> * public int GetTagHeight(int defaultHeight=-1) * { * if (defaultHeight < 0) defaultHeight = DEFAULT_CELL_HEIGHT; * * int brCount = GetNodesByName("BR").Count; * int pCount = GetNodesByName("P").Count; * List<HtmlNode> specialNodes = new List<HtmlNode>(); * int maxHeight = GetHeightStyle(defaultHeight); * foreach (String nodeName in _specialTags) * { * GetNodesByName(nodeName, specialNodes); * } * if (brCount == 0 && pCount == 0) * { * if (specialNodes.Count > 0) * { * return defaultHeight; * } * else * { * if (GetAllInnerText().Trim().Length == 0) return 0; * else return defaultHeight; * } * } * else * { * int max = brCount * BR_HEIGHT + pCount * P_HEIGHT; * return brCount * BR_HEIGHT + pCount * P_HEIGHT; * } * * } */ public int GetTagHeight(int defaultHeight, int nowHeight = 0) { if (this.Name.ToLower().Equals("tr")) { if (this.Children.Count > 0) { int max = nowHeight; foreach (HtmlNode td in Children) { if (td.Name.ToLower().Equals("td")) { int hig = td.GetTagHeight(defaultHeight); if (hig == 0 && td.GetAllInnerText().Length > 0) { hig = defaultHeight; //내용이 있는데 hig이 0이라면 br이 내부에 없는 것. 하지만 테이블에서는 크기를 count해야 함. } if (max < hig) { max = hig; } } else { continue;//tr및에는 td가 오는 것이 정상. 다른 태그는 comment나 비정상태그. 그냥 무시할 것. } } return(max); } else { //do nothing.. return(0);//td가 채워지지 않았으므로 defaultSize도 없음. } } else //tr이 아니면 내부의 크기는 모두 합치면 됨. { int tagHeight = nowHeight; if (this.Attributes.ContainsKey("style")) { StyleItemCollection styles = new StyleItemCollection(this.Attributes["style"]); if (styles.ContainsKey("height")) { String style = styles["height"].Replace("px", "").Replace("pt", ""); int height; if (int.TryParse(style, out height)) { tagHeight = height; } else { tagHeight = defaultHeight; } } } if (this.Attributes.ContainsKey("height")) { int height; if (int.TryParse(this.Attributes["height"], out height)) { if (tagHeight < height) { tagHeight = height; } } } if (Children.Count > 0) { int childHeight = 0; foreach (HtmlNode child in Children) { childHeight = child.GetTagHeight(defaultHeight, childHeight); //childHeight = 0; } if (childHeight > tagHeight) { tagHeight = childHeight; } } else { if (_specialTags.Contains(this.Name))//special tag면 기본적으로 defaultHeight가 됨. { //tagHeight = nowHeight;// defaultHeight; } else if (this.Name.ToLower().Equals("br")) { tagHeight += BR_HEIGHT; } else if (this.Name.ToLower().Equals("p")) { tagHeight += P_HEIGHT; } else { // if(nowHeight>tagHeight) tagHeight = nowHeight; /* * if (InnerText.Trim().Length > 0)//공백제외한 일반 text길이가 0보다 크면 * { * if (tagHeight < defaultHeight) tagHeight = defaultHeight; * } * else * { * //tagHeight를 수정하지 않는다. * } */ } } if (tagHeight > 0 && tagHeight < defaultHeight) { tagHeight = defaultHeight; } if (tagHeight < nowHeight) { tagHeight = nowHeight; } return(tagHeight); //return (nowHeight>tagHeight)? nowHeight : tagHeight; } }