public TextRenderer(string text, int maxwidth, bool asHTML) { Text = text; MaxWidth = maxwidth; AsHTML = asHTML; m_href = new HTMLRegions(); m_images = new HTMLImages(); }
void getHREFRegions(HTMLRegions regions, List<AHTMLAtom>[] text, int[] x, int y) { for (int alignment = 0; alignment < 3; alignment++) { // variables for the open href region bool isRegionOpen = false; HTMLRegion region = null; int regionHeight = 0; int additionalwidth = 0; int dx = x[alignment]; for (int i = 0; i < text[alignment].Count; i++) { AHTMLAtom atom = text[alignment][i]; if ((region == null && atom.HREFAttributes != null) || (region != null && atom.HREFAttributes != region.HREFAttributes)) { // close the current href tag if one is open. if (isRegionOpen) { region.Area.Width = (dx - region.Area.X) + additionalwidth; region.Area.Height = (y + regionHeight - region.Area.Y); isRegionOpen = false; region = null; } // did we open a href? if (atom.HREFAttributes != null) { isRegionOpen = true; region = regions.AddRegion(atom.HREFAttributes); region.Area.X = dx; region.Area.Y = y; regionHeight = 0; } } if (atom is HTMLImageGump) { // we need regions for images so that we can do mouse over images. // if we're currently in an open href region, we'll use that one. // if we don't have an open region, we'll create one just for this image. HTMLImage image = ((HTMLImageGump)atom).AssociatedImage; if (image != null) { if (!isRegionOpen) { region = regions.AddRegion(atom.HREFAttributes); isRegionOpen = true; region.Area.X = dx; region.Area.Y = y; regionHeight = 0; } image.RegionIndex = region.Index; } } dx += atom.Width; if (atom is HTMLAtomCharacter && ((HTMLAtomCharacter)atom).Style_IsItalic) additionalwidth = 2; else additionalwidth = 0; if (isRegionOpen && atom.Height > regionHeight) regionHeight = atom.Height; } // we've reached the last atom in this set. // if a href tag is still open, close it. if (isRegionOpen) { region.Area.Width = (dx - region.Area.X); region.Area.Height = (y + regionHeight - region.Area.Y); } } }