/**
         * <summary>Gets the object equivalent to the given value.</summary>
         */
        public static PdfDirectObject Get(
            object value
            )
        {
            if (value == null)
            {
                return(null);
            }

            if (value is int)
            {
                return(PdfInteger.Get((int)value));
            }
            if (value is double || value is float)
            {
                return(PdfReal.Get(value));
            }
            if (value is string)
            {
                return(PdfTextString.Get((string)value));
            }
            if (value is DateTime)
            {
                return(PdfDate.Get((DateTime)value));
            }
            if (value is bool)
            {
                return(PdfBoolean.Get((bool)value));
            }
            throw new NotImplementedException();
        }
Esempio n. 2
0
        /**
         * <summary>Gets the color corresponding to the specified table index resolved according to
         * the <see cref="BaseSpace">base space</see>.<summary>
         */
        public Color GetBaseColor(IndexedColor color)
        {
            int colorIndex = color.Index;

            if (!baseColors.TryGetValue(colorIndex, out var baseColor))
            {
                ColorSpace baseSpace = BaseSpace;
                IList <PdfDirectObject> components = new List <PdfDirectObject>();
                {
                    int    componentCount      = baseSpace.ComponentCount;
                    int    componentValueIndex = colorIndex * componentCount;
                    byte[] baseComponentValues = BaseComponentValues;
                    for (int componentIndex = 0; componentIndex < componentCount; componentIndex++)
                    {
                        var byteValue = componentValueIndex < baseComponentValues.Length
                            ? baseComponentValues[componentValueIndex]
                            : 0;
                        var value = ((int)byteValue & 0xff) / 255d;
                        components.Add(PdfReal.Get(value));
                        componentValueIndex++;
                    }
                }
                baseColor = baseColors[colorIndex] = baseSpace.GetColor(components, null);
            }
            return(baseColor);
        }
Esempio n. 3
0
 public DeviceRGBColor(double r, double g, double b)
     : this(new PdfArray(
                PdfReal.Get(NormalizeComponent(r)),
                PdfReal.Get(NormalizeComponent(g)),
                PdfReal.Get(NormalizeComponent(b))))
 {
 }
Esempio n. 4
0
        /**
         * <summary>Creates a new destination within the given document context.</summary>
         * <param name="context">Document context.</param>
         * <param name="pageObject">Page reference. It may be either an actual page reference (PdfReference)
         *  or a page index (PdfInteger).</param>
         * <param name="mode">Destination mode.</param>
         * <param name="viewParams">View parameters. Their actual composition depends on the <code>mode</code> value
         *  (see ModeEnum for more info).</param>
         */
        protected Destination(
            Document context,
            PdfDirectObject pageObject,
            ModeEnum mode,
            float?[] viewParams
            ) : base(
                context.File,
                new PdfArray()
                )
        {
            PdfArray destinationObject = BaseDataObject;

            destinationObject.Add(pageObject);

            switch (mode)
            {
            case ModeEnum.Fit:
                destinationObject.Add(PdfName.Fit);
                break;

            case ModeEnum.FitBoundingBox:
                destinationObject.Add(PdfName.FitB);
                break;

            case ModeEnum.FitBoundingBoxHorizontal:
                destinationObject.Add(PdfName.FitBH);
                destinationObject.Add(PdfReal.Get(viewParams[0]));
                break;

            case ModeEnum.FitBoundingBoxVertical:
                destinationObject.Add(PdfName.FitBV);
                destinationObject.Add(PdfReal.Get(viewParams[0]));
                break;

            case ModeEnum.FitHorizontal:
                destinationObject.Add(PdfName.FitH);
                destinationObject.Add(PdfReal.Get(viewParams[0]));
                break;

            case ModeEnum.FitRectangle:
                destinationObject.Add(PdfName.FitR);
                destinationObject.Add(PdfReal.Get(viewParams[0]));
                destinationObject.Add(PdfReal.Get(viewParams[1]));
                destinationObject.Add(PdfReal.Get(viewParams[2]));
                destinationObject.Add(PdfReal.Get(viewParams[3]));
                break;

            case ModeEnum.FitVertical:
                destinationObject.Add(PdfName.FitV);
                destinationObject.Add(PdfReal.Get(viewParams[0]));
                break;

            case ModeEnum.XYZ:
                destinationObject.Add(PdfName.XYZ);
                destinationObject.Add(PdfReal.Get(viewParams[0]));
                destinationObject.Add(PdfReal.Get(viewParams[1]));
                destinationObject.Add(PdfReal.Get(viewParams[2]));
                break;
            }
        }
Esempio n. 5
0
 protected void SetComponentValue(
     int index,
     double value
     )
 {
     Components[index] = PdfReal.Get(NormalizeComponent(value));
 }
Esempio n. 6
0
        /**
         * <summary>Gets the color corresponding to the specified table index resolved according to
         * the <see cref="BaseSpace">base space</see>.<summary>
         */
        public Color GetBaseColor(
            IndexedColor color
            )
        {
            int   colorIndex = color.Index;
            Color baseColor  = baseColors[colorIndex];

            if (baseColor == null)
            {
                ColorSpace baseSpace = BaseSpace;
                IList <PdfDirectObject> components = new List <PdfDirectObject>();
                {
                    int    componentCount      = baseSpace.ComponentCount;
                    int    componentValueIndex = colorIndex * componentCount;
                    byte[] baseComponentValues = BaseComponentValues;
                    for (
                        int componentIndex = 0;
                        componentIndex < componentCount;
                        componentIndex++
                        )
                    {
                        components.Add(
                            PdfReal.Get(((int)baseComponentValues[componentValueIndex++] & 0xff) / 255d)
                            );
                    }
                }
                baseColor = baseSpace.GetColor(components, null);
            }
            return(baseColor);
        }
Esempio n. 7
0
        /**
         * <summary>Gets the result of the calculation applied by this function
         * to the specified input values.</summary>
         * <param name="inputs">Input values.</param>
         */
        public IList <PdfDirectObject> Calculate(
            IList <PdfDirectObject> inputs
            )
        {
            IList <PdfDirectObject> outputs = new List <PdfDirectObject>();

            {
                double[] inputValues = new double[inputs.Count];
                for (
                    int index = 0,
                    length = inputValues.Length;
                    index < length;
                    index++
                    )
                {
                    inputValues[index] = ((IPdfNumber)inputs[index]).RawValue;
                }
                double[] outputValues = Calculate(inputValues);
                for (
                    int index = 0,
                    length = outputValues.Length;
                    index < length;
                    index++
                    )
                {
                    outputs.Add(PdfReal.Get(outputValues[index]));
                }
            }
            return(outputs);
        }
Esempio n. 8
0
 public Line(Page page, SKPoint startPoint, SKPoint endPoint, string text, DeviceRGBColor color)
     : base(page, PdfName.Line, SKRect.Create(startPoint.X, startPoint.Y, endPoint.X - startPoint.X, endPoint.Y - startPoint.Y), text)
 {
     BaseDataObject[PdfName.L] = new PdfArray(new PdfDirectObject[] { PdfReal.Get(0), PdfReal.Get(0), PdfReal.Get(0), PdfReal.Get(0) });
     StartPoint = startPoint;
     EndPoint   = endPoint;
     Color      = color;
 }
Esempio n. 9
0
 public DeviceCMYKColor(double c, double m, double y, double k) : this(
         new PdfArray(
             PdfReal.Get(NormalizeComponent(c)),
             PdfReal.Get(NormalizeComponent(m)),
             PdfReal.Get(NormalizeComponent(y)),
             PdfReal.Get(NormalizeComponent(k))))
 {
 }
Esempio n. 10
0
 public DeviceRGBColor(double r, double g, double b)
     : this(new PdfDirectObject[]
 {
     PdfReal.Get(NormalizeComponent(r)),
     PdfReal.Get(NormalizeComponent(g)),
     PdfReal.Get(NormalizeComponent(b))
 })
 {
 }
Esempio n. 11
0
 /*
  * TODO:colors MUST be instantiated only indirectly by the ColorSpace.getColor method!
  * This method MUST be made internal and its color space MUST be passed as argument!
  */
 public LabColor(double l, double a, double b) : this(
         new PdfArray(
             PdfReal.Get(NormalizeComponent(l)),//TODO:normalize using the actual color space ranges!!!
             PdfReal.Get(NormalizeComponent(a)),
             PdfReal.Get(NormalizeComponent(b))
             )
         )
 {
 }
Esempio n. 12
0
 public CalGrayColor(
     double g
     ) : this(
         new List <PdfDirectObject>(
             new PdfDirectObject[] { PdfReal.Get(NormalizeComponent(g)) }
             )
         )
 {
 }
Esempio n. 13
0
 public SetCharSpace(double value)
     : base(
         OperatorKeyword,
         new List <PdfDirectObject>(
             new PdfDirectObject[] { PdfReal.Get(value) }
             )
         )
 {
 }
Esempio n. 14
0
 /**
  * <param name="pointX">Current point X.</param>
  * <param name="pointY">Current point Y.</param>
  */
 public BeginSubpath(double pointX, double pointY)
     : base(OperatorKeyword, new List <PdfDirectObject>(new PdfDirectObject[]
 {
     PdfReal.Get(pointX),
     PdfReal.Get(pointY)
 }
                                                        )
            )
 {
 }
Esempio n. 15
0
 private void EnsureSpaceOperation(
     )
 {
     if (@operator.Equals(SimpleOperatorKeyword))
     {
         @operator = SpaceOperatorKeyword;
         operands.Insert(0, PdfReal.Get(0));
         operands.Insert(1, PdfReal.Get(0));
     }
 }
Esempio n. 16
0
        private static IList <PdfDirectObject> GetComponentValues(params double[] components)
        {// TODO:normalize parameters!
            IList <PdfDirectObject> componentValues = new List <PdfDirectObject>();

            foreach (double component in components)
            {
                componentValues.Add(PdfReal.Get((component)));
            }
            return(componentValues);
        }
Esempio n. 17
0
 public TranslateTextRelative(
     double offsetX,
     double offsetY,
     bool leadSet
     ) : base(
         leadSet ? LeadOperatorKeyword : SimpleOperatorKeyword,
         PdfReal.Get(offsetX),
         PdfReal.Get(offsetY)
         )
 {
 }
Esempio n. 18
0
 public SetTextMatrix(double a, double b, double c, double d, double e, double f)
     : base(OperatorKeyword,
            PdfReal.Get(a),
            PdfReal.Get(b),
            PdfReal.Get(c),
            PdfReal.Get(d),
            PdfReal.Get(e),
            PdfReal.Get(f)
            )
 {
 }
Esempio n. 19
0
 /**
  * <param name="text">Text encoded using current font's encoding.</param>
  * <param name="wordSpace">Word spacing.</param>
  * <param name="charSpace">Character spacing.</param>
  */
 public ShowTextToNextLine(
     byte[] text,
     double wordSpace,
     double charSpace
     ) : base(
         SpaceOperatorKeyword,
         PdfReal.Get(wordSpace),
         PdfReal.Get(charSpace),
         new PdfByteString(text)
         )
 {
 }
Esempio n. 20
0
 public SeparationColor(
     double intensity
     ) : this(
         new List <PdfDirectObject>(
             new PdfDirectObject[]
 {
     PdfReal.Get(intensity) //TODO:normalize value (see devicecolor)!
 }
             )
         )
 {
 }
Esempio n. 21
0
 public DeviceCMYKColor(double c, double m, double y, double k) : this(
         new List <PdfDirectObject>(
             new PdfDirectObject[]
 {
     PdfReal.Get(NormalizeComponent(c)),
     PdfReal.Get(NormalizeComponent(m)),
     PdfReal.Get(NormalizeComponent(y)),
     PdfReal.Get(NormalizeComponent(k))
 }
             )
         )
 {
 }
Esempio n. 22
0
 /**
  * <summary>Creates a fully-explicit curve.</summary>
  */
 public DrawCurve(double pointX, double pointY, double control1X, double control1Y, double control2X, double control2Y)
     : base(FullOperatorKeyword, new List <PdfDirectObject>(new PdfDirectObject[]
 {
     PdfReal.Get(control1X),
     PdfReal.Get(control1Y),
     PdfReal.Get(control2X),
     PdfReal.Get(control2Y),
     PdfReal.Get(pointX),
     PdfReal.Get(pointY)
 }
                                                            )
            )
 {
 }
Esempio n. 23
0
 /**
  * <summary>Creates a partially-explicit curve.</summary>
  * <param name="point">Final endpoint.</param>
  * <param name="control">Explicit control point.</param>
  * <param name="operator">Operator (either <code>InitialOperator</code> or <code>FinalOperator</code>).
  * It defines how to interpret the <code>control</code> parameter.</param>
  */
 public DrawCurve(SKPoint point, SKPoint control, string @operator)
     : base(@operator.Equals(InitialOperatorKeyword, StringComparison.Ordinal)
           ? InitialOperatorKeyword
           : FinalOperatorKeyword, new List <PdfDirectObject>(new PdfDirectObject[]
 {
     PdfReal.Get(control.X),
     PdfReal.Get(control.Y),
     PdfReal.Get(point.X),
     PdfReal.Get(point.Y)
 }
                                                              )
            )
 {
 }
Esempio n. 24
0
 public CalRGBColor(
     double r,
     double g,
     double b
     ) : this(
         new List <PdfDirectObject>(
             new PdfDirectObject[]
 {
     PdfReal.Get(NormalizeComponent(r)),
     PdfReal.Get(NormalizeComponent(g)),
     PdfReal.Get(NormalizeComponent(b))
 }
             )
         )
 {
 }
Esempio n. 25
0
 /*
  * TODO:colors MUST be instantiated only indirectly by the ColorSpace.getColor method!
  * This method MUST be made internal and its color space MUST be passed as argument!
  */
 public LabColor(
     double l,
     double a,
     double b
     ) : this(
         new List <PdfDirectObject>(
             new PdfDirectObject[]
 {
     PdfReal.Get(NormalizeComponent(l)),//TODO:normalize using the actual color space ranges!!!
     PdfReal.Get(NormalizeComponent(a)),
     PdfReal.Get(NormalizeComponent(b))
 }
             )
         )
 {
 }
Esempio n. 26
0
 public ModifyCTM(double a, double b, double c, double d, double e, double f)
     : base(OperatorKeyword,
            new List <PdfDirectObject>(
                new PdfDirectObject[]
 {
     PdfReal.Get(a),
     PdfReal.Get(b),
     PdfReal.Get(c),
     PdfReal.Get(d),
     PdfReal.Get(e),
     PdfReal.Get(f)
 }
                )
            )
 {
 }
Esempio n. 27
0
 /**
  * <summary>Creates a partially-explicit curve.</summary>
  * <param name="point">Final endpoint.</param>
  * <param name="control">Explicit control point.</param>
  * <param name="operator">Operator (either <code>InitialOperator</code> or <code>FinalOperator</code>).
  * It defines how to interpret the <code>control</code> parameter.</param>
  */
 public DrawCurve(
     PointF point,
     PointF control,
     string @operator
     ) : base(
         @operator.Equals(InitialOperatorKeyword) ? InitialOperatorKeyword : FinalOperatorKeyword,
         new List <PdfDirectObject>(
             new PdfDirectObject[]
 {
     PdfReal.Get(control.X),
     PdfReal.Get(control.Y),
     PdfReal.Get(point.X),
     PdfReal.Get(point.Y)
 }
             )
         )
 {
 }
Esempio n. 28
0
 public DrawRectangle(
     double x,
     double y,
     double width,
     double height
     ) : base(
         OperatorKeyword,
         new List <PdfDirectObject>(
             new PdfDirectObject[]
 {
     PdfReal.Get(x),
     PdfReal.Get(y),
     PdfReal.Get(width),
     PdfReal.Get(height)
 }
             )
         )
 {
 }
Esempio n. 29
0
 public CalloutLine(Page page, SKPoint start, SKPoint?knee, SKPoint end)
     : base(new PdfArray())
 {
     SKMatrix matrix         = page.InRotateMatrix;
     PdfArray baseDataObject = BaseDataObject;
     {
         start = matrix.MapPoint(start);
         baseDataObject.Add(PdfReal.Get(start.X));
         baseDataObject.Add(PdfReal.Get(start.Y));
         if (knee.HasValue)
         {
             knee = matrix.MapPoint(knee.Value);
             baseDataObject.Add(PdfReal.Get(knee.Value.X));
             baseDataObject.Add(PdfReal.Get(knee.Value.Y));
         }
         end = matrix.MapPoint(end);
         baseDataObject.Add(PdfReal.Get(end.X));
         baseDataObject.Add(PdfReal.Get(end.Y));
     }
 }
Esempio n. 30
0
 public Line(
     Page page,
     PointF startPoint,
     PointF endPoint,
     string text
     ) : base(
         page,
         PdfName.Line,
         new RectangleF(
             startPoint.X,
             startPoint.Y,
             endPoint.X - startPoint.X,
             endPoint.Y - startPoint.Y
             ),
         text
         )
 {
     BaseDataObject[PdfName.L] = new PdfArray(new PdfDirectObject[] { PdfReal.Get(0), PdfReal.Get(0), PdfReal.Get(0), PdfReal.Get(0) });
     StartPoint = startPoint;
     EndPoint   = endPoint;
 }