/// <summary> /// Appends new rectangle to rectangles List /// or tries to construct a rectangle from individual lines /// </summary> /// <param name="renderInfo"></param> /// <returns></returns> public Path RenderPath(PathPaintingRenderInfo renderInfo) { if (renderInfo.Operation != PathPaintingRenderInfo.NO_OP) { if (_currentRectangle != null) { var transformedRect = Transform(_currentRectangle, renderInfo.Ctm); var maxDimension = Math.Max(_pageWidth, _pageHeight); if (transformedRect.X + _currentRectangle.Width > maxDimension) { _currentRectangle.Width = maxDimension - transformedRect.X; } _rectangles.Add(new Rectangle { Height = _currentRectangle.Height, Width = _currentRectangle.Width, X = transformedRect.X, Y = transformedRect.Y }); return(null); } ConstructShape(renderInfo.Ctm); } _currentPoints.Clear(); return(null); }
public iTextSharp.text.pdf.parser.Path RenderPath(PathPaintingRenderInfo renderInfo) { GraphicsState graphicsState = getGraphicsState(renderInfo); Matrix ctm = graphicsState.GetCtm(); if ((renderInfo.Operation & PathPaintingRenderInfo.FILL) != 0) { Console.Write("FILL ({0}) ", toString(graphicsState.FillColor)); if ((renderInfo.Operation & PathPaintingRenderInfo.STROKE) != 0) { Console.Write("and "); } } if ((renderInfo.Operation & PathPaintingRenderInfo.STROKE) != 0) { Console.Write("STROKE ({0}) ", toString(graphicsState.StrokeColor)); } Console.Write("the path "); foreach (PathConstructionRenderInfo pathConstructionRenderInfo in pathInfos) { switch (pathConstructionRenderInfo.Operation) { case PathConstructionRenderInfo.MOVETO: Console.Write("move to {0} ", toString(transform(ctm, pathConstructionRenderInfo.SegmentData))); break; case PathConstructionRenderInfo.CLOSE: Console.Write("close {0} ", toString(transform(ctm, pathConstructionRenderInfo.SegmentData))); break; case PathConstructionRenderInfo.CURVE_123: Console.Write("curve123 {0} ", toString(transform(ctm, pathConstructionRenderInfo.SegmentData))); break; case PathConstructionRenderInfo.CURVE_13: Console.Write("curve13 {0} ", toString(transform(ctm, pathConstructionRenderInfo.SegmentData))); break; case PathConstructionRenderInfo.CURVE_23: Console.Write("curve23 {0} ", toString(transform(ctm, pathConstructionRenderInfo.SegmentData))); break; case PathConstructionRenderInfo.LINETO: Console.Write("line to {0} ", toString(transform(ctm, pathConstructionRenderInfo.SegmentData))); break; case PathConstructionRenderInfo.RECT: Console.Write("rectangle {0} ", toString(transform(ctm, expandRectangleCoordinates(pathConstructionRenderInfo.SegmentData)))); break; } } Console.WriteLine(); pathInfos.Clear(); return(null); }
public virtual Path RenderPath(PathPaintingRenderInfo renderInfo) { // If previous clipping is empty, then we shouldn't compute the new one // because their intersection is empty. if (newClippingPath.IsEmpty()) { currentStrokePath = new Path(); currentFillPath = currentStrokePath; return(newClippingPath); } bool stroke = (renderInfo.Operation & PathPaintingRenderInfo.STROKE) != 0; bool fill = (renderInfo.Operation & PathPaintingRenderInfo.FILL) != 0; float lineWidth = renderInfo.LineWidth; int lineCapStyle = renderInfo.LineCapStyle; int lineJoinStyle = renderInfo.LineJoinStyle; float miterLimit = renderInfo.MiterLimit; LineDashPattern lineDashPattern = renderInfo.LineDashPattern; if (stroke) { currentStrokePath = FilterCurrentPath(renderInfo.Ctm, true, -1, lineWidth, lineCapStyle, lineJoinStyle, miterLimit, lineDashPattern); } if (fill) { currentFillPath = FilterCurrentPath(renderInfo.Ctm, false, renderInfo.Rule, lineWidth, lineCapStyle, lineJoinStyle, miterLimit, lineDashPattern); } if (clipPath) { if (fill && renderInfo.Rule == clippingRule) { newClippingPath = currentFillPath; } else { newClippingPath = FilterCurrentPath(renderInfo.Ctm, false, clippingRule, lineWidth, lineCapStyle, lineJoinStyle, miterLimit, lineDashPattern); } } unfilteredCurrentPath = new Path(); return(newClippingPath); }
public virtual Path RenderPath(PathPaintingRenderInfo renderInfo) { bool stroke = (renderInfo.Operation & PathPaintingRenderInfo.STROKE) != 0; bool fill = (renderInfo.Operation & PathPaintingRenderInfo.FILL) != 0; float lineWidth = renderInfo.LineWidth; int lineCapStyle = renderInfo.LineCapStyle; int lineJoinStyle = renderInfo.LineJoinStyle; float miterLimit = renderInfo.MiterLimit; LineDashPattern lineDashPattern = renderInfo.LineDashPattern; if (stroke) { currentStrokePath = FilterCurrentPath(renderInfo.Ctm, true, -1, lineWidth, lineCapStyle, lineJoinStyle, miterLimit, lineDashPattern); } if (fill) { currentFillPath = FilterCurrentPath(renderInfo.Ctm, false, renderInfo.Rule, lineWidth, lineCapStyle, lineJoinStyle, miterLimit, lineDashPattern); } if (clipPath) { if (fill && renderInfo.Rule == clippingRule) { newClippingPath = currentFillPath; } else { newClippingPath = FilterCurrentPath(renderInfo.Ctm, false, clippingRule, lineWidth, lineCapStyle, lineJoinStyle, miterLimit, lineDashPattern); } } unfilteredCurrentPath = new Path(); return(newClippingPath); }
public Path RenderPath(PathPaintingRenderInfo renderInfo) { //var p = typeof(PathPaintingRenderInfo).GetField("gs", BindingFlags.NonPublic | BindingFlags.Instance); //var gs = (GraphicsState)(p.GetValue(renderInfo)); //Debug.WriteLine(gs.StrokeColor?.RGB.ToString() ?? "empty"); // detect gs.StrokeColor != null if (renderInfo.Operation != 0) { Tuple <int, Vector> cur = null; Vector from = null; Vector to = null; while (movements.Count > 0 && (cur = movements.Dequeue()) != null) { if (cur.Item1 == 1) { from = cur.Item2.Cross(renderInfo.Ctm); } else { if (from == null) { continue; } to = cur.Item2.Cross(renderInfo.Ctm); if (from[0] == to[0] && from[1] < to[1] || from[1] == to[1] && from[0] < to[0]) { Lines.Add(new LineSegment(new Vector(FixAxis(from[0]), FixAxis(from[1]), 1) , new Vector(FixAxis(to[0]), FixAxis(to[1]), 1))); } else if (from[0] == to[0] && from[1] > to[1] || from[1] == to[1] && from[0] > to[0]) { Lines.Add(new LineSegment(new Vector(FixAxis(to[0]), FixAxis(to[1]), 1) , new Vector(FixAxis(from[0]), FixAxis(from[1]), 1))); } else { //throw new Exception("oblique line"); } //Debug.WriteLine("x:{0},y:{1}", Lines[Lines.Count - 1].GetStartPoint()[0], Lines[Lines.Count - 1].GetStartPoint()[1]); from = null; to = null; } } if (rData != null) { var r = rData; Vector vxy = new Vector(r[0], r[1], 1).Cross(renderInfo.Ctm); Vector vwh = new Vector(r[2], r[3], 1).Cross(renderInfo.Ctm); var x = vxy[0]; var y = vxy[1]; if (vwh[0] < 0) { x = vxy[0] + vwh[0]; } if (vwh[1] < 0) { y = vxy[1] - vwh[1]; } vxy = new Vector(x, y, 1); vwh = new Vector(Math.Abs(r[2]), Math.Abs(r[3]), 1).Cross(renderInfo.Ctm); if (TreatSmallRectAsLine && vwh[0] < Variance) { //Lines.Add(new LineSegment(new Vector(FixAxis(x), FixAxis(y - vwh[1]), 1) // , new Vector(FixAxis(x), FixAxis(y), 1))); Lines.Add(new LineSegment(new Vector(FixAxis(x), FixAxis(y), 1) , new Vector(FixAxis(x), FixAxis(y + vwh[1]), 1))); } else if (TreatSmallRectAsLine && vwh[1] < Variance) { Lines.Add(new LineSegment(new Vector(FixAxis(x), FixAxis(y), 1) , new Vector(FixAxis(x + vwh[0]), FixAxis(y), 1))); } else { Rects.Add(new Rect(vxy[0], vxy[1], vwh[0], vwh[1])); } rData = null; } } return(null); }
GraphicsState getGraphicsState(PathPaintingRenderInfo renderInfo) { System.Reflection.FieldInfo gsField = typeof(PathPaintingRenderInfo).GetField("gs", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance); return((GraphicsState)gsField.GetValue(renderInfo)); }