Esempio n. 1
0
        public static PdfArray GetMKColor(Color color)
        {
            PdfArray array = new PdfArray();
            int      type  = ExtendedColor.GetType(color);

            switch (type)
            {
            case ExtendedColor.TYPE_GRAY: {
                array.Add(new PdfNumber(((GrayColor)color).Gray));
                break;
            }

            case ExtendedColor.TYPE_CMYK: {
                CMYKColor cmyk = (CMYKColor)color;
                array.Add(new PdfNumber(cmyk.Cyan));
                array.Add(new PdfNumber(cmyk.Magenta));
                array.Add(new PdfNumber(cmyk.Yellow));
                array.Add(new PdfNumber(cmyk.Black));
                break;
            }

            case ExtendedColor.TYPE_SEPARATION:
            case ExtendedColor.TYPE_PATTERN:
            case ExtendedColor.TYPE_SHADING:
                throw new Exception("Separations, patterns and shadings are not allowed in MK dictionary.");

            default:
                array.Add(new PdfNumber(color.R / 255f));
                array.Add(new PdfNumber(color.G / 255f));
                array.Add(new PdfNumber(color.B / 255f));
                break;
            }
            return(array);
        }
Esempio n. 2
0
        public static float[] GetColorArray(Color color)
        {
            int type = ExtendedColor.GetType(color);

            switch (type)
            {
            case ExtendedColor.TYPE_GRAY: {
                return(new float[] { ((GrayColor)color).Gray });
            }

            case ExtendedColor.TYPE_CMYK: {
                CMYKColor cmyk = (CMYKColor)color;
                return(new float[] { cmyk.Cyan, cmyk.Magenta, cmyk.Yellow, cmyk.Black });
            }

            case ExtendedColor.TYPE_SEPARATION: {
                return(new float[] { ((SpotColor)color).Tint });
            }

            case ExtendedColor.TYPE_RGB: {
                return(new float[] { color.R / 255f, color.G / 255f, color.B / 255f });
            }
            }
            ThrowColorSpaceError();
            return(null);
        }
Esempio n. 3
0
        public override bool Equals(Object obj)
        {
            if (!(obj is CMYKColor))
            {
                return(false);
            }
            CMYKColor c2 = (CMYKColor)obj;

            return(ccyan == c2.ccyan && cmagenta == c2.cmagenta && cyellow == c2.cyellow && cblack == c2.cblack);
        }
Esempio n. 4
0
        protected internal PdfObject GetSpotObject(PdfWriter writer)
        {
            PdfArray array = new PdfArray(PdfName.SEPARATION);

            array.Add(name);
            PdfFunction func = null;

            if (altcs is ExtendedColor)
            {
                int type = ((ExtendedColor)altcs).Type;
                switch (type)
                {
                case ExtendedColor.TYPE_GRAY:
                    array.Add(PdfName.DEVICEGRAY);
                    func = PdfFunction.Type2(writer, new float[] { 0, 1 }, null, new float[] { 0 }, new float[] { ((GrayColor)altcs).Gray }, 1);
                    break;

                case ExtendedColor.TYPE_CMYK:
                    array.Add(PdfName.DEVICECMYK);
                    CMYKColor cmyk = (CMYKColor)altcs;
                    func = PdfFunction.Type2(writer, new float[] { 0, 1 }, null, new float[] { 0, 0, 0, 0 },
                                             new float[] { cmyk.Cyan, cmyk.Magenta, cmyk.Yellow, cmyk.Black }, 1);
                    break;

                default:
                    throw new Exception("Only RGB, Gray and CMYK are supported as alternative color spaces.");
                }
            }
            else
            {
                array.Add(PdfName.DEVICERGB);
                func = PdfFunction.Type2(writer, new float[] { 0, 1 }, null, new float[] { 1, 1, 1 },
                                         new float[] { (float)altcs.R / 255, (float)altcs.G / 255, (float)altcs.B / 255 }, 1);
            }
            array.Add(func.Reference);
            return(array);
        }
Esempio n. 5
0
 public static Object[] SplitDAelements(String da)
 {
     PRTokeniser tk = new PRTokeniser(PdfEncodings.ConvertToBytes(da, null));
     ArrayList stack = new ArrayList();
     Object[] ret = new Object[3];
     while (tk.NextToken()) {
         if (tk.TokenType == PRTokeniser.TK_COMMENT)
             continue;
         if (tk.TokenType == PRTokeniser.TK_OTHER) {
             String oper = tk.StringValue;
             if (oper.Equals("Tf")) {
                 if (stack.Count >= 2) {
                     ret[DA_FONT] = stack[stack.Count - 2];
                     ret[DA_SIZE] = float.Parse((String)stack[stack.Count - 1], NumberFormatInfo.InvariantInfo);
                 }
             }
             else if (oper.Equals("g")) {
                 if (stack.Count >= 1) {
                     float gray = float.Parse((String)stack[stack.Count - 1], NumberFormatInfo.InvariantInfo);
                     if (gray != 0)
                         ret[DA_COLOR] = new GrayColor(gray);
                 }
             }
             else if (oper.Equals("rg")) {
                 if (stack.Count >= 3) {
                     float red = float.Parse((String)stack[stack.Count - 3], NumberFormatInfo.InvariantInfo);
                     float green = float.Parse((String)stack[stack.Count - 2], NumberFormatInfo.InvariantInfo);
                     float blue = float.Parse((String)stack[stack.Count - 1], NumberFormatInfo.InvariantInfo);
                     ret[DA_COLOR] = new Color(red, green, blue);
                 }
             }
             else if (oper.Equals("k")) {
                 if (stack.Count >= 4) {
                     float cyan = float.Parse((String)stack[stack.Count - 4], NumberFormatInfo.InvariantInfo);
                     float magenta = float.Parse((String)stack[stack.Count - 3], NumberFormatInfo.InvariantInfo);
                     float yellow = float.Parse((String)stack[stack.Count - 2], NumberFormatInfo.InvariantInfo);
                     float black = float.Parse((String)stack[stack.Count - 1], NumberFormatInfo.InvariantInfo);
                     ret[DA_COLOR] = new CMYKColor(cyan, magenta, yellow, black);
                 }
             }
             stack.Clear();
         }
         else
             stack.Add(tk.StringValue);
     }
     return ret;
 }