public void ParseTag(HTMLchunk chunk, AElement atom) { if (!chunk.Closure || chunk.EndClosure) { // create the tag and add it to the list of open tags. var tag = new OpenTag(chunk); _openTags.Add(tag); // parse the tag (which will update the StyleParser's current style ParseTag(tag, atom); // if the style has changed and atom is not null, set the atom's style to the current style. if (atom != null) { atom.Style = Style; } // if this is a self-closing tag (<br/>) close it! if (chunk.EndClosure) { CloseOneTag(chunk); } } else { CloseOneTag(chunk); } }
public void InterpretHREF(HTMLchunk chunk, AElement atom) { if (chunk.EndClosure) { } // solo anchor elements are meaningless. if (!chunk.Closure) { // opening a hyperlink! RecalculateStyle(); var tag = new OpenTag(chunk); _openTags.Add(tag); ParseTag(tag, atom); } else { RecalculateStyle(); // closing a hyperlink. } }
private void ParseTag(OpenTag tag, AElement atom = null) { switch (tag.Tag) { case "b": Style.IsBold = true; break; case "i": Style.IsItalic = true; break; case "u": Style.IsUnderlined = true; break; case "outline": Style.IsOutlined = true; break; case "big": Style.Font = _provider.GetUnicodeFont((int)Fonts.UnicodeBig); break; case "basefont": case "medium": Style.Font = _provider.GetUnicodeFont((int)Fonts.UnicodeMedium); break; case "small": Style.Font = _provider.GetUnicodeFont((int)Fonts.UnicodeSmall); break; case "left": if (atom != null && atom is BlockElement) { (atom as BlockElement).Alignment = Alignments.Left; } break; case "center": if (atom != null && atom is BlockElement) { (atom as BlockElement).Alignment = Alignments.Center; } break; case "right": if (atom != null && atom is BlockElement) { (atom as BlockElement).Alignment = Alignments.Right; } break; } foreach (DictionaryEntry param in tag.Params) { // get key and value for this tag param var key = param.Key.ToString(); var value = param.Value.ToString(); if (value.StartsWith("0x")) { value = Utility.ToInt32(value).ToString(); } // trim trailing forward slash. if (value.EndsWith("/")) { value = value.Substring(0, value.Length - 1); } switch (key) { case "href": // href paramater can only be used on 'anchor' tags. if (tag.Tag == "a") { Style.HREF = value; } break; case "color": case "hovercolor": case "activecolor": // get the color! var color = value; Color?c = null; if (color[0] == '#') { color = color.Substring(1); if (color.Length == 3 || color.Length == 6) { c = Utility.ColorFromHexString(color); } } else { c = Utility.ColorFromString(color); // try to parse color by name } if (c.HasValue) { if (key == "color") { Style.Color = c.Value; } if (tag.Tag == "a") { // a tag colors are override, they are rendered white and then hued with a websafe hue. switch (key) { case "color": Style.ColorHue = _provider.GetWebSafeHue(c.Value); break; case "hovercolor": Style.HoverColorHue = _provider.GetWebSafeHue(c.Value); break; case "activecolor": Style.ActiveColorHue = _provider.GetWebSafeHue(c.Value); break; default: Utils.Warning($"Only anchor <a> tags can have attribute {key}."); break; } } } else { Utils.Warning($"Improperly formatted color: {color}"); } break; case "src": case "hoversrc": case "activesrc": if (atom is ImageElement) { switch (key) { case "src": (atom as ImageElement).ImgSrc = int.Parse(value); break; case "hoversrc": (atom as ImageElement).ImgSrcOver = int.Parse(value); break; case "activesrc": (atom as ImageElement).ImgSrcDown = int.Parse(value); break; } break; } Utils.Warning($"{key} param encountered within {tag.Tag} tag which does not use this param."); break; case "width": { if (atom is ImageElement || atom is BlockElement) { atom.Width = int.Parse(value); } else { Utils.Warning($"width param encountered within {tag.Tag} which does not use this param."); } } break; case "height": { if (atom is ImageElement || atom is BlockElement) { atom.Height = int.Parse(value); } else { Utils.Warning($"width param encountered within {tag.Tag} which does not use this param."); } } break; case "style": ParseStyle(value); break; default: Utils.Warning($"Unknown parameter:{key}"); break; } } }