static void CreateSvgEllipse(SvgElement parentNode, HtmlElement elem) { SvgEllipseSpec spec = new SvgEllipseSpec(); SvgEllipse shape = new SvgEllipse(spec, elem); parentNode.AddChild(shape); foreach (WebDom.DomAttribute attr in elem.GetAttributeIterForward()) { WebDom.WellknownName wellknownName = (WebDom.WellknownName)attr.LocalNameIndex; switch (wellknownName) { case WebDom.WellknownName.Svg_Cx: { spec.X = UserMapUtil.ParseGenericLength(attr.Value); } break; case WebDom.WellknownName.Svg_Cy: { spec.Y = UserMapUtil.ParseGenericLength(attr.Value); } break; case WellknownName.Svg_Rx: { spec.RadiusX = UserMapUtil.ParseGenericLength(attr.Value); } break; case WellknownName.Svg_Ry: { spec.RadiusY = UserMapUtil.ParseGenericLength(attr.Value); } break; case WebDom.WellknownName.Svg_Fill: { spec.ActualColor = CssValueParser.GetActualColor(attr.Value); } break; case WebDom.WellknownName.Svg_Stroke: { spec.StrokeColor = CssValueParser.GetActualColor(attr.Value); } break; case WebDom.WellknownName.Svg_Stroke_Width: { spec.StrokeWidth = UserMapUtil.ParseGenericLength(attr.Value); } break; case WebDom.WellknownName.Svg_Transform: { //TODO: parse svg transform function } break; default: { //other attrs } break; } } }
void CreateSvgPolygon(SvgElement parentNode, HtmlElement elem) { SvgPolygonSpec spec = new SvgPolygonSpec(); SvgPolygon shape = new SvgPolygon(spec, elem); parentNode.AddChild(shape); foreach (WebDom.DomAttribute attr in elem.GetAttributeIterForward()) { WebDom.WellknownName wellknownName = (WebDom.WellknownName)attr.LocalNameIndex; switch (wellknownName) { case WebDom.WellknownName.Svg_Points: { //parse points spec.Points = ParsePointList(attr.Value); } break; case WebDom.WellknownName.Svg_Fill: { spec.FillColor = CssValueParser.GetActualColor(attr.Value); } break; case WebDom.WellknownName.Svg_Stroke: { spec.StrokeColor = CssValueParser.GetActualColor(attr.Value); } break; case WebDom.WellknownName.Svg_Stroke_Width: { spec.StrokeWidth = UserMapUtil.ParseGenericLength(attr.Value); } break; case WebDom.WellknownName.Svg_Transform: { //TODO: parse svg transform function } break; default: { //other attrs } break; } } }
static void CreateSvgGroupElement(SvgElement parentNode, HtmlElement elem) { SvgVisualSpec spec = new SvgVisualSpec(); SvgGroupElement svgGroupElement = new SvgGroupElement(spec, elem); parentNode.AddChild(svgGroupElement); foreach (WebDom.DomAttribute attr in elem.GetAttributeIterForward()) { WebDom.WellknownName wellknownName = (WebDom.WellknownName)attr.LocalNameIndex; switch (wellknownName) { case WebDom.WellknownName.Svg_Fill: { spec.ActualColor = CssValueParser.GetActualColor(attr.Value); } break; case WebDom.WellknownName.Svg_Stroke: { spec.StrokeColor = CssValueParser.GetActualColor(attr.Value); } break; case WebDom.WellknownName.Svg_Stroke_Width: { spec.StrokeWidth = UserMapUtil.ParseGenericLength(attr.Value); } break; default: { //other attrs } break; } } CreateSvgBoxContent(svgGroupElement, elem); }
static void CreateSvgImage(SvgElement parentNode, HtmlElement elem) { SvgImageSpec spec = new SvgImageSpec(); SvgImage svgImage = new SvgImage(spec, elem); parentNode.AddChild(svgImage); foreach (WebDom.DomAttribute attr in elem.GetAttributeIterForward()) { WebDom.WellknownName wellknownName = (WebDom.WellknownName)attr.LocalNameIndex; switch (wellknownName) { case WebDom.WellknownName.Svg_X: { spec.X = UserMapUtil.ParseGenericLength(attr.Value); } break; case WebDom.WellknownName.Svg_Y: { spec.Y = UserMapUtil.ParseGenericLength(attr.Value); } break; case WebDom.WellknownName.Width: { spec.Width = UserMapUtil.ParseGenericLength(attr.Value); } break; case WebDom.WellknownName.Height: { spec.Height = UserMapUtil.ParseGenericLength(attr.Value); } break; case WebDom.WellknownName.Svg_Fill: { spec.ActualColor = CssValueParser.GetActualColor(attr.Value); } break; case WebDom.WellknownName.Svg_Stroke: { spec.StrokeColor = CssValueParser.GetActualColor(attr.Value); } break; case WebDom.WellknownName.Svg_Stroke_Width: { spec.StrokeWidth = UserMapUtil.ParseGenericLength(attr.Value); } break; case WebDom.WellknownName.Svg_Transform: { //TODO: parse svg transform function } break; case WellknownName.Href: { //image src*** spec.ImageSrc = attr.Value; } break; default: { } break; } } }
static void CreateSvgPath(SvgElement parentNode, HtmlElement elem) { SvgPathSpec spec = new SvgPathSpec(); SvgPath svgPath = new SvgPath(spec, elem); parentNode.AddChild(svgPath); foreach (WebDom.DomAttribute attr in elem.GetAttributeIterForward()) { WebDom.WellknownName wellknownName = (WebDom.WellknownName)attr.LocalNameIndex; switch (wellknownName) { case WebDom.WellknownName.Svg_X: { spec.X = UserMapUtil.ParseGenericLength(attr.Value); } break; case WebDom.WellknownName.Svg_Y: { spec.Y = UserMapUtil.ParseGenericLength(attr.Value); } break; case WebDom.WellknownName.Width: { spec.Width = UserMapUtil.ParseGenericLength(attr.Value); } break; case WebDom.WellknownName.Height: { spec.Height = UserMapUtil.ParseGenericLength(attr.Value); } break; case WebDom.WellknownName.Svg_Fill: { spec.ActualColor = CssValueParser.GetActualColor(attr.Value); } break; case WebDom.WellknownName.Svg_Stroke: { spec.StrokeColor = CssValueParser.GetActualColor(attr.Value); } break; case WebDom.WellknownName.Svg_Stroke_Width: { spec.StrokeWidth = UserMapUtil.ParseGenericLength(attr.Value); } break; case WebDom.WellknownName.Svg_Transform: { //TODO: parse svg transform function } break; default: { //other attrs switch (attr.Name) { case "d": { //parse vertex commands Svg.Pathing.SvgPathDataParser parser = new Svg.Pathing.SvgPathDataParser(); svgPath.Segments = parser.Parse(attr.Value.ToCharArray()); } break; } } break; } } }
static void CreateSvgLinearGradient(SvgElement parentNode, HtmlElement elem) { //linear gradient definition SvgLinearGradient linearGradient = new SvgLinearGradient(elem); foreach (WebDom.DomAttribute attr in elem.GetAttributeIterForward()) { WebDom.WellknownName wellknownName = (WebDom.WellknownName)attr.LocalNameIndex; switch (wellknownName) { case WellknownName.Svg_X1: { linearGradient.X1 = UserMapUtil.ParseGenericLength(attr.Value); } break; case WellknownName.Svg_X2: { linearGradient.X2 = UserMapUtil.ParseGenericLength(attr.Value); } break; case WellknownName.Svg_Y1: { linearGradient.Y1 = UserMapUtil.ParseGenericLength(attr.Value); } break; case WellknownName.Svg_Y2: { linearGradient.Y2 = UserMapUtil.ParseGenericLength(attr.Value); } break; } } //------------------------------------------------------------ int j = elem.ChildrenCount; List <StopColorPoint> stopColorPoints = new List <StopColorPoint>(j); for (int i = 0; i < j; ++i) { HtmlElement node = elem.GetChildNode(i) as HtmlElement; if (node == null) { continue; } switch (node.WellknownElementName) { case WellKnownDomNodeName.svg_stop: { //stop point StopColorPoint stopPoint = new StopColorPoint(); foreach (WebDom.DomAttribute attr in node.GetAttributeIterForward()) { WebDom.WellknownName wellknownName = (WebDom.WellknownName)attr.LocalNameIndex; switch (wellknownName) { case WellknownName.Svg_StopColor: { stopPoint.StopColor = CssValueParser.GetActualColor(attr.Value); } break; case WellknownName.Svg_Offset: { stopPoint.Offset = UserMapUtil.ParseGenericLength(attr.Value); } break; } } stopColorPoints.Add(stopPoint); } break; } } }
/// <summary> /// Paints the fragment /// </summary> /// <param name="g"></param> private void PaintImp(Graphics g) { if (Display != CssConstants.None && (Display != CssConstants.TableCell || EmptyCells != CssConstants.Hide || !IsSpaceOrEmpty)) { var areas = Rectangles.Count == 0 ? new List <RectangleF>(new[] { Bounds }) : new List <RectangleF>(Rectangles.Values); RectangleF[] rects = areas.ToArray(); PointF offset = HtmlContainer != null ? HtmlContainer.ScrollOffset : PointF.Empty; for (int i = 0; i < rects.Length; i++) { var actualRect = rects[i]; actualRect.Offset(offset); PaintBackground(g, actualRect, i == rects.Length - 1); PaintBorder(g, actualRect, i == 0, i == rects.Length - 1); } if (IsImage) { var word = Words[0]; RectangleF r = word.Bounds; r.Offset(offset); r.Height -= ActualBorderTopWidth + ActualBorderBottomWidth + ActualPaddingTop + ActualPaddingBottom; r.Y += ActualBorderTopWidth + ActualPaddingTop; //HACK: round rectangle only when necessary g.DrawImage(word.Image, Rectangle.Round(r)); if (word.Selected) { g.FillRectangle(CssUtils.SelectionBackcolor, word.Left - word.LastMeasureOffset.X + offset.X, word.Top + offset.Y, word.Width, DomUtils.GetCssLineBoxByWord(word).LineHeight); } } else if (Words.Count > 0) { Font font = ActualFont; var brush = CssUtils.GetSolidBrush(CssValueParser.GetActualColor(Color)); foreach (var word in Words) { if (word.Selected) { // handle paint selected word background and with partial word selection var left = word.SelectedStartOffset > -1 ? word.SelectedStartOffset : 0; var width = word.SelectedEndOffset > -1 ? word.SelectedEndOffset + word.LastMeasureOffset.X : word.Width; //REFACTOR THIS STUFF Brush b = CssUtils.SelectionBackcolor; CssLineBox box = DomUtils.GetCssLineBoxByWord(word); float h = box != null ? box.LineHeight : 0; float w = width - left; float x = word.Left - word.LastMeasureOffset.X + offset.X + left; float y = word.Top + offset.Y; g.FillRectangle(b, x, y, w, h); } g.DrawString(word.Text, font, brush, word.Left - word.LastMeasureOffset.X + offset.X, word.Top + offset.Y); } } for (int i = 0; i < rects.Length; i++) { var actualRect = rects[i]; actualRect.Offset(offset); PaintDecoration(g, actualRect, i == 0, i == rects.Length - 1); } foreach (CssBox b in Boxes) { b.Paint(g); } CreateListItemBox(g); if (ListItemBox != null) { ListItemBox.Paint(g); } } }