public HTMLRegion(int i, HREF_Attributes data) { Area = new Rectangle(); HREFAttributes = data; Index = i; }
public HTMLRegion AddRegion(HREF_Attributes href) { _regions.Add(new HTMLRegion(_regions.Count, href)); return _regions[_regions.Count - 1]; }
private List<HTMLParser_Atom> decodeText(string inText, bool parseHTML) { List<HTMLParser_Atom> outAtoms = new List<HTMLParser_Atom>(); List<string> openTags = new List<string>(); Color currentColor = Color.White; List<HREF_Attributes> openHREFs = new List<HREF_Attributes>(); // if this is not HTML, do not parse tags. Otherwise search out and interpret tags. if (!parseHTML) { for (int i = 0; i < inText.Length; i++) { addCharacter(inText[i], outAtoms, openTags, currentColor, openHREFs); } } else { Parsing.HTMLparser parser = new Parsing.HTMLparser(inText); Parsing.HTMLchunk chunk; while ((chunk = parser.ParseNext()) != null) { if (!(chunk.oHTML == "")) { // this is text. add the characters to the outText list. for (int i = 0; i < chunk.oHTML.Length; i++) addCharacter(chunk.oHTML[i], outAtoms, openTags, currentColor, openHREFs); } else { // this is a tag. interpret the tag and edit the openTags list. bool readParams = true; bool isClosing = chunk.bClosure; switch (chunk.sTag) { case "font": break; case "br": addCharacter('\n', outAtoms, openTags, currentColor, openHREFs); break; case "b": editOpenTags(openTags, isClosing, "b"); break; case "i": editOpenTags(openTags, isClosing, "i"); break; case "u": editOpenTags(openTags, isClosing, "u"); break; case "big": editOpenTags(openTags, isClosing, "big"); break; case "basefont": case "medium": editOpenTags(openTags, isClosing, "medium"); break; case "small": editOpenTags(openTags, isClosing, "small"); break; case "center": editOpenTags(openTags, isClosing, "center"); break; case "left": editOpenTags(openTags, isClosing, "left"); break; case "right": editOpenTags(openTags, isClosing, "right"); break; case "gumpimg": addGumpImage(outAtoms, openTags, openHREFs); break; case "span": addSpan(outAtoms, openTags, openHREFs); break; case "a": editOpenTags(openTags, isClosing, "a"); if (isClosing) { // closing a hyperlink - restore previous address, if any. if (openHREFs.Count > 0) openHREFs.RemoveAt(openHREFs.Count - 1); } else { // hyperlink with attributes HREF_Attributes href = new HREF_Attributes(); openHREFs.Add(href); } break; default: readParams = false; for (int i = 0; i < chunk.iChunkLength; i++) { addCharacter(char.Parse(inText.Substring(i + chunk.iChunkOffset, 1)), outAtoms, openTags, currentColor, openHREFs); } break; } if (readParams) { foreach (DictionaryEntry param in chunk.oParams) { string key = param.Key.ToString(); string value = param.Value.ToString(); if (value.EndsWith("/")) value = value.Substring(0, value.Length - 1); switch (key) { case "href": if (chunk.sTag == "a") { openHREFs[openHREFs.Count - 1].HREF = value; } else { Logger.Warn("href paramater used outside of an 'a' tag link. href is ignored in this case."); } break; case "color": case "hovercolor": case "activecolor": // get the color! string color = value; if (color[0] == '#') color = color.Substring(1); if (color.Length == 3 || color.Length == 6) { Color c = Utility.ColorFromHexString(color); if (key == "color") currentColor = c; if (chunk.sTag == "a") { switch (key) { case "color": openHREFs[openHREFs.Count - 1].UpHue = Data.HuesXNA.GetWebSafeHue(c); break; case "hovercolor": openHREFs[openHREFs.Count - 1].OverHue = Data.HuesXNA.GetWebSafeHue(c); break; case "activecolor": openHREFs[openHREFs.Count - 1].DownHue = Data.HuesXNA.GetWebSafeHue(c); break; } } } else Logger.Warn("Improperly formatted color:" + color); break; case "text-decoration": switch (value) { case "none": if (chunk.sTag == "a") openHREFs[openHREFs.Count - 1].Underline = false; break; default: Logger.Warn(string.Format("Unknown text-decoration:{0}", value)); break; } break; case "src": case "hoversrc": case "activesrc": switch (chunk.sTag) { case "gumpimg": if (key == "src") ((HTMLParser_AtomImageGump)outAtoms[outAtoms.Count - 1]).Value = int.Parse(value); else if (key == "hoversrc") ((HTMLParser_AtomImageGump)outAtoms[outAtoms.Count - 1]).ValueOver = int.Parse(value); else if (key == "activesrc") ((HTMLParser_AtomImageGump)outAtoms[outAtoms.Count - 1]).ValueDown = int.Parse(value); break; default: Logger.Warn("src param encountered within " + chunk.sTag + " which does not use this param."); break; } break; case "width": switch (chunk.sTag) { case "gumpimg": case "span": outAtoms[outAtoms.Count - 1].Width = int.Parse(value); break; default: Logger.Warn("width param encountered within " + chunk.sTag + " which does not use this param."); break; } break; case "height": switch (chunk.sTag) { case "gumpimg": case "span": outAtoms[outAtoms.Count - 1].Width = int.Parse(value); break; default: Logger.Warn("height param encountered within " + chunk.sTag + " which does not use this param."); break; } break; default: Logger.Warn(string.Format("Unknown parameter:{0}", key)); break; } } } } } } return outAtoms; }