Ejemplo n.º 1
0
        /// <summary>
        /// Writes a reference to the specified image for rendering in the defined position at that size within the current graphics stream
        /// </summary>
        /// <param name="img"></param>
        /// <param name="imgsize"></param>
        /// <param name="pos"></param>
        /// <remarks>This does not include the image within the document or ensure that it is available</remarks>
        public void PaintImageRef(Scryber.Resources.PDFImageXObject img, PDFSize imgsize, PDFPoint pos)
        {
            if (string.IsNullOrEmpty(img.Name.Value))
            {
                throw new ArgumentNullException("img.Name");
            }
            PDFReal width  = (PDFReal)(imgsize.Width.RealValue);
            PDFReal height = (PDFReal)(imgsize.Height.RealValue);
            PDFReal x      = pos.X.RealValue;
            PDFReal y;

            if (this.Origin == DrawingOrigin.TopLeft)
            {
                //convert the top down to bottom of the page up to the image
                y = ContainerSize.Height.RealValue - pos.Y.RealValue - height;
            }
            else
            {
                y = pos.Y.RealValue;
            }

            this.Writer.WriteOpCodeS(PDFOpCode.GraphTransformMatrix,
                                     width, PDFReal.Zero,
                                     PDFReal.Zero, height, x, y);

            this.Writer.WriteOpCodeS(PDFOpCode.XobjPaint, img.Name);
        }
Ejemplo n.º 2
0
        public void Equals_Test()
        {
            PDFReal target   = new PDFReal(10.0);
            PDFReal num      = new PDFReal(10.0);
            bool    expected = true;
            bool    actual;

            actual = target.Equals(num);
            Assert.AreEqual(expected, actual);

            num      = new PDFReal(-10.9);
            expected = false;
            actual   = target.Equals(num);
            Assert.AreEqual(expected, actual);

            num      = new PDFReal();
            expected = false;
            actual   = target.Equals(num);
            Assert.AreEqual(expected, actual);

            num      = new PDFReal();
            target   = new PDFReal();
            expected = true;
            actual   = target.Equals(num);
            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 3
0
        public void DrawText(string text, Typeface typeface, double fontSize, PDFColor color,
                             double x, double y)
        {
            PDFFont pdfFont;

            if (!_fontMapping.TryGetValue(typeface, out pdfFont))
            {
                pdfFont = new PDFTrueTypeFont(CreateIndirectDictionary(), typeface);
                _fontMapping[typeface] = pdfFont;
                pdfFont.ResourceKeyId  = _fontMapping.Count;
            }
            int fontKey = pdfFont.ResourceKeyId;

            pdfFont.AddStringToSubset(text);

            // Let's create a temporary PDFString, which takes care of escaping special characters.
            PDFString str = new PDFString(text);

            WriteColor(color, false);

            AppendToContentStream(
                "BT\r\n" +
                $"  /F{fontKey} {PDFReal.RealToString(fontSize)} Tf\r\n" +
                $"  {PDFReal.RealToString(x)} {PDFReal.RealToString(-y)} Td\r\n" +
                $"  {str.ToString()} Tj\r\n" +
                "ET\r\n");
        }
Ejemplo n.º 4
0
 private void WriteLineWidth(PDFColor stroke, double lineWidth)
 {
     if (stroke != null)
     {
         AppendToContentStream($"{PDFReal.RealToString(lineWidth)} w\r\n");
     }
 }
Ejemplo n.º 5
0
        public void op_Division_Test()
        {
            PDFReal one      = new PDFReal(10.2);
            PDFReal two      = new PDFReal(2.0);
            PDFReal expected = new PDFReal(5.1);
            PDFReal actual;

            actual = (one / two);
            Assert.AreEqual(expected, actual);

            two = new PDFReal(0.0);

            try
            {
                actual = (one / two);
                //because we are a double then we can just about do this
                if (!double.IsInfinity(actual.Value))
                {
                    Assert.Fail("Did not throw error for divide by zero");
                }
            }
            catch (DivideByZeroException)
            {
                TestContext.WriteLine("Successfully caught the divide by 0 exception");
            }
        }
Ejemplo n.º 6
0
 protected virtual void RenderBezierCurveToWithStartHandleOnly(PDFReal endX, PDFReal endY, PDFReal starthandleX, PDFReal startHandleY)
 {
     starthandleX = GetXPosition(starthandleX);
     startHandleY = GetYPosition(startHandleY);
     endX         = GetXPosition(endX);
     endY         = GetYPosition(endY);
     this.Writer.WriteOpCodeS(PDFOpCode.GraphCurve1HandleBegin, starthandleX, startHandleY, endX, endY);
 }
Ejemplo n.º 7
0
 protected virtual void RenderBezierCurveToWithEndHandleOnly(PDFReal endX, PDFReal endY, PDFReal endhandleX, PDFReal endHandleY)
 {
     endhandleX = GetXPosition(endhandleX);
     endHandleY = GetYPosition(endHandleY);
     endX       = GetXPosition(endX);
     endY       = GetYPosition(endY);
     this.Writer.WriteOpCodeS(PDFOpCode.GraphCurve1HandleEnd, endhandleX, endHandleY, endX, endY);
 }
Ejemplo n.º 8
0
        public string ToContentStreamOp(bool isStroke)
        {
            string op = isStroke ? "RG\r\n" : "rg\r\n";
            string r  = PDFReal.RealToString(Red);
            string g  = PDFReal.RealToString(Green);
            string b  = PDFReal.RealToString(Blue);

            return($"{r} {g} {b} {op}");
        }
Ejemplo n.º 9
0
        public void ToString_Test()
        {
            double  value    = 10.2;
            PDFReal target   = new PDFReal(value);
            string  expected = value.ToString();
            string  actual;

            actual = target.ToString();
            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 10
0
 public void DrawRectangle(double x, double y, double width, double height,
                           PDFColor stroke, PDFColor fill, double lineWidth)
 {
     WriteColor(fill, false);
     WriteColor(stroke, true);
     WriteLineWidth(stroke, lineWidth);
     AppendToContentStream(
         $"{ PDFReal.RealToString(x) } { PDFReal.RealToString(-y) } { PDFReal.RealToString(width) } { PDFReal.RealToString(-height) } re\r\n");
     WritePaintOp(stroke, fill);
 }
        public void PDFSolidBrushConstructor_Test1()
        {
            PDFColor      color   = PDFColors.Aqua;
            PDFReal       opacity = 1F;
            PDFSolidBrush target  = new PDFSolidBrush(color, opacity);

            Assert.IsNotNull(target);
            Assert.AreEqual(color, target.Color);
            Assert.AreEqual(opacity, target.Opacity);
            Assert.AreEqual(FillType.Solid, target.FillStyle);
        }
Ejemplo n.º 12
0
        public void Type_Test()
        {
            PDFReal       target   = new PDFReal();
            PDFObjectType expected = PDFObjectTypes.Real;
            PDFObjectType actual;

            actual = target.Type;
            Assert.AreEqual(expected, actual);

            target = 10.5;
            actual = target.Type;
            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 13
0
        public void Opacity_Test()
        {
            PDFPen  target   = PDFPen.Create(PDFColors.Aqua, 1);
            PDFReal expected = -1;
            PDFReal actual   = target.Opacity;

            Assert.AreEqual(expected, actual);

            expected       = 0.5;
            target.Opacity = expected;
            actual         = target.Opacity;
            Assert.AreEqual(expected, actual);
        }
        public void Opacity_Test()
        {
            PDFColor      color   = PDFColors.Aqua;
            PDFReal       opacity = 1F;
            PDFSolidBrush target  = new PDFSolidBrush(color, opacity);

            Assert.AreEqual(opacity, target.Opacity);

            PDFReal expected = 0.4F;

            target.Opacity = expected;
            Assert.AreEqual(expected, target.Opacity);
        }
Ejemplo n.º 15
0
        public void op_Implicit_Test()
        {
            float   val      = 10.5F;
            PDFReal expected = new PDFReal(val);
            PDFReal actual;

            actual = val;
            Assert.AreEqual(expected, actual);

            val    = 10.6F;
            actual = val;
            Assert.AreNotEqual(expected, actual);
        }
Ejemplo n.º 16
0
        public void op_Explicit_Test1()
        {
            float   expected = 10.2F;
            PDFReal number   = new PDFReal(expected);
            float   actual;

            actual = ((float)(number));
            Assert.AreEqual(expected, actual);

            number = new PDFReal(20.4F);
            actual = (float)number;
            Assert.AreNotEqual(expected, actual);
        }
Ejemplo n.º 17
0
        public void op_Explicit_Test()
        {
            double  expected = 10.5;
            PDFReal number   = new PDFReal(expected);
            double  actual;

            actual = ((double)(number));
            Assert.AreEqual(expected, actual);

            number = new PDFReal(20.1);
            actual = (double)number;
            Assert.AreNotEqual(expected, actual);
        }
Ejemplo n.º 18
0
        public void op_Implicit_Test1()
        {
            double  val      = 10.5;
            PDFReal expected = new PDFReal(val);
            PDFReal actual;

            actual = val;
            Assert.AreEqual(expected, actual);

            val    = 10.6;
            actual = val;
            Assert.AreNotEqual(expected, actual);
        }
Ejemplo n.º 19
0
        public void Value_Test()
        {
            double  expected = 100.5;
            PDFReal target   = new PDFReal(expected);

            double actual = target.Value;

            Assert.AreEqual(actual, expected);

            expected     = 200.1;
            target.Value = expected;
            actual       = target.Value;
            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 20
0
        public void op_Equality_Test()
        {
            PDFReal one      = new PDFReal(10.5);
            PDFReal two      = new PDFReal(10.5);
            bool    expected = true;
            bool    actual;

            actual = (one == two);
            Assert.AreEqual(expected, actual);

            two      = new PDFReal(5.5);
            expected = false;
            actual   = (one == two);
            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 21
0
        public void DrawLine(double x0, double y0, double x1, double y1,
                             PDFColor stroke, double lineWidth)
        {
            if (stroke == null)
            {
                return;
            }

            WriteColor(stroke, true);
            WriteLineWidth(stroke, lineWidth);
            AppendToContentStream(
                $"{ PDFReal.RealToString(x0) } { PDFReal.RealToString(-y0) } m\r\n" +
                $"{ PDFReal.RealToString(x1) } { PDFReal.RealToString(-y1) } l\r\n");
            AppendToContentStream("S\r\n");
        }
Ejemplo n.º 22
0
        public void SetFillOpacity(PDFReal opacity)
        {
            if (opacity.Value < 0.0 || opacity.Value > 1.0)
            {
                throw new ArgumentOutOfRangeException("Opacity values can only be between 0.0 (transparent) and 1.0 (blockout)");
            }

            this.ExternalState.SetFillOpacity(opacity);
            //if(opacity.Value != _currentOpacity.Fill)
            //{
            //    Resources.PDFExtGSState state = this.EnsureExternalState();
            //    state.States[Resources.PDFExtGSState.ColorFillOpactity] = opacity;
            //    _currentOpacity.Fill = opacity.Value;
            //}
        }
Ejemplo n.º 23
0
        public void op_Multiply_Test()
        {
            PDFReal one      = new PDFReal(10.2);
            PDFReal two      = new PDFReal(2.0);
            PDFReal expected = new PDFReal(20.4);
            PDFReal actual;

            actual = (one * two);
            Assert.AreEqual(expected, actual);

            two = new PDFReal(0.0);

            actual = (one * two);
            Assert.AreEqual(two, actual);
        }
Ejemplo n.º 24
0
        public void PDFRealConstructor_Test()
        {
            double  value  = 0F;
            PDFReal target = new PDFReal(value);

            Assert.AreEqual(value, target.Value);

            value  = -10.0;
            target = new PDFReal(value);
            Assert.AreEqual(value, target.Value);

            value  = double.MaxValue;
            target = new PDFReal(value);
            Assert.AreEqual(value, target.Value);
        }
Ejemplo n.º 25
0
        private void OutputQuadrantShapes(PDFUnit x, PDFUnit y, PDFUnit width, PDFUnit height, Quadrants sides)
        {
            PDFReal left    = x.RealValue;
            PDFReal right   = (x + width).RealValue;
            PDFReal top     = y.RealValue;
            PDFReal bottom  = (y + height).RealValue;
            PDFReal hcentre = (left + (width.RealValue / (PDFReal)2.0));
            PDFReal vcentre = (top + (height.RealValue / (PDFReal)2.0));
            PDFReal xhandle = ((width.RealValue / (PDFReal)2.0) * (PDFReal)CircularityFactor);
            PDFReal yhandle = ((height.RealValue / (PDFReal)2.0) * (PDFReal)CircularityFactor);

            if ((sides & Quadrants.TopLeft) > 0)
            {
                this.RenderMoveTo(left, vcentre);
                //top left quadrant
                this.RenderBezierCurveTo(hcentre, top, left, vcentre - yhandle, hcentre - xhandle, top);
                this.RenderContinuationLine(hcentre, vcentre);
                this.RenderContinuationLine(left, vcentre);
            }


            if ((sides & Quadrants.TopRight) > 0)
            {
                this.RenderMoveTo(hcentre, top);
                //top right quadrant
                this.RenderBezierCurveTo(right, vcentre, hcentre + xhandle, top, right, vcentre - yhandle);
                this.RenderContinuationLine(hcentre, vcentre);
                this.RenderContinuationLine(hcentre, top);
            }

            if ((sides & Quadrants.BottomRight) > 0)
            {
                this.RenderMoveTo(right, vcentre);
                //bottom right quadrant
                this.RenderBezierCurveTo(hcentre, bottom, right, vcentre + yhandle, hcentre + xhandle, bottom);
                this.RenderContinuationLine(hcentre, vcentre);
                this.RenderContinuationLine(right, vcentre);
            }

            if ((sides & Quadrants.BottomLeft) > 0)
            {
                this.RenderMoveTo(hcentre, bottom);
                //bottom left quadrant
                this.RenderBezierCurveTo(left, vcentre, hcentre - xhandle, bottom, left, vcentre + yhandle);
                this.RenderContinuationLine(hcentre, vcentre);
                this.RenderContinuationLine(hcentre, bottom);
            }
        }
Ejemplo n.º 26
0
        public void op_Addition_Test()
        {
            PDFReal one      = new PDFReal(10.0);
            PDFReal two      = new PDFReal(22.0);
            PDFReal expected = new PDFReal(32.0);
            PDFReal actual;

            actual = (one + two);
            Assert.AreEqual(expected.Value, actual.Value);

            one      = new PDFReal(-20.5);
            two      = new PDFReal(20.5);
            expected = new PDFReal(0);
            actual   = (one + two);
            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 27
0
        public void op_Subtraction_Test()
        {
            PDFReal one      = new PDFReal(10.1);
            PDFReal two      = new PDFReal(20.2);
            PDFReal expected = new PDFReal(-10.1);
            PDFReal actual;

            actual = (one - two);
            Assert.AreEqual(expected, actual);

            one      = new PDFReal(20.5);
            two      = new PDFReal(20.5);
            expected = new PDFReal(0);
            actual   = (one - two);
            Assert.AreEqual(expected, actual);
        }
        /// <summary>
        /// Renders a series of horizontal line with the passed spacing
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="width"></param>
        /// <param name="height"></param>
        /// <param name="spacing"></param>
        private void OutputHorizontalLines(PDFReal x, PDFReal y, PDFReal width, PDFReal height, PDFReal spacing)
        {
            PDFReal maxy = y + height;

            PDFReal minx = GetXPosition(x);
            PDFReal maxx = GetXPosition(x + width);

            while (y < maxy)
            {
                PDFReal ypos = GetYPosition(y);

                this.Writer.WriteOpCodeS(PDFOpCode.GraphMove, minx, ypos);
                this.Writer.WriteOpCodeS(PDFOpCode.GraphLineTo, maxx, ypos);
                this.Writer.WriteOpCodeS(PDFOpCode.GraphStrokePath);

                y += spacing;
            }
        }
        /// <summary>
        /// Renders a series of vertical lines with the passed spacing
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="width"></param>
        /// <param name="height"></param>
        /// <param name="spacing"></param>
        private void OutputVerticalLines(PDFReal x, PDFReal y, PDFReal width, PDFReal height, PDFReal spacing)
        {
            PDFReal maxx = x + width;

            PDFReal miny = GetYPosition(y);
            PDFReal maxy = GetYPosition(y + height);

            while (x < maxx)
            {
                PDFReal xpos = GetXPosition(x);

                this.Writer.WriteOpCodeS(PDFOpCode.GraphMove, xpos, miny);
                this.Writer.WriteOpCodeS(PDFOpCode.GraphLineTo, xpos, maxy);
                this.Writer.WriteOpCodeS(PDFOpCode.GraphStrokePath);

                x += spacing;
            }
        }
        private PDFObject createNewValueForSelectedScalar(PDFObject selectedPDFObject, string newValue)
        {
            PDFObject newPDFObject = null;

            if (selectedPDFObject is PDFString)
            {
                PDFString selectedPDFString = selectedPDFObject as PDFString;
                newPDFObject = new PDFString(newValue, PDFDoc, selectedPDFString.Indirect, selectedPDFString.StoredAsHex);
            }
            else if (selectedPDFObject is PDFName)
            {
                newPDFObject = new PDFName(newValue, PDFDoc, selectedPDFObject.Indirect);
            }
            else if (selectedPDFObject is PDFReal)
            {
                double newVal;
                if (double.TryParse(newValue, out newVal))
                {
                    newPDFObject = new PDFReal(newVal, PDFDoc, selectedPDFObject.Indirect);
                }
                else
                {
                    throw new FormatException("The value is not of type double.");
                }
            }
            else if (selectedPDFObject is PDFInteger)
            {
                int newVal;
                if (int.TryParse(newValue, out newVal))
                {
                    newPDFObject = new PDFInteger(newVal, PDFDoc, selectedPDFObject.Indirect);
                }
                else
                {
                    throw new FormatException("The value is not of type integer.");
                }
            }
            else
            {
                throw new InvalidOperationException("Non scalar types can't be altered");
            }
            return(newPDFObject);
        }