Inheritance: iTextSharp.text.BaseColor
        public static PdfArray GetMKColor(BaseColor 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(MessageLocalization.GetComposedMessage("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);
        }
        internal 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 RuntimeException("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);
        }
Beispiel #3
0
        public static float[] GetColorArray(BaseColor 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);
        }
Beispiel #4
0
        public static void CheckCompatibleColors(BaseColor c1, BaseColor c2)
        {
            int type1 = ExtendedColor.GetType(c1);
            int type2 = ExtendedColor.GetType(c2);

            if (type1 != type2)
            {
                throw new ArgumentException(MessageLocalization.GetComposedMessage("both.colors.must.be.of.the.same.type"));
            }
            if (type1 == ExtendedColor.TYPE_SEPARATION && ((SpotColor)c1).PdfSpotColor != ((SpotColor)c2).PdfSpotColor)
            {
                throw new ArgumentException(MessageLocalization.GetComposedMessage("the.spot.color.must.be.the.same.only.the.tint.can.vary"));
            }
            if (type1 == ExtendedColor.TYPE_PATTERN || type1 == ExtendedColor.TYPE_SHADING)
            {
                ThrowColorSpaceError();
            }
        }
Beispiel #5
0
        public static void checkCompatibleColors(Color c1, Color c2)
        {
            int type1 = ExtendedColor.getType(c1);
            int type2 = ExtendedColor.getType(c2);

            if (type1 != type2)
            {
                throw new IllegalArgumentException("Both colors must be of the same type.");
            }
            if (type1 == ExtendedColor.TYPE_SEPARATION && ((SpotColor)c1).getPdfSpotColor() != ((SpotColor)c2).getPdfSpotColor())
            {
                throw new IllegalArgumentException("The spot color must be the same, only the tint can vary.");
            }
            if (type1 == ExtendedColor.TYPE_PATTERN || type1 == ExtendedColor.TYPE_SHADING)
            {
                throwColorSpaceError();
            }
        }
Beispiel #6
0
        virtual protected void SetColorSpace(BaseColor color)
        {
            cspace = color;
            int       type       = ExtendedColor.GetType(color);
            PdfObject colorSpace = null;

            switch (type)
            {
            case ExtendedColor.TYPE_GRAY: {
                colorSpace = PdfName.DEVICEGRAY;
                break;
            }

            case ExtendedColor.TYPE_CMYK: {
                colorSpace = PdfName.DEVICECMYK;
                break;
            }

            case ExtendedColor.TYPE_SEPARATION: {
                SpotColor spot = (SpotColor)color;
                colorDetails = writer.AddSimple(spot.PdfSpotColor);
                colorSpace   = colorDetails.IndirectReference;
                break;
            }

            case ExtendedColor.TYPE_DEVICEN: {
                DeviceNColor deviceNColor = (DeviceNColor)color;
                colorDetails = writer.AddSimple(deviceNColor.PdfDeviceNColor);
                colorSpace   = colorDetails.IndirectReference;
                break;
            }

            case ExtendedColor.TYPE_PATTERN:
            case ExtendedColor.TYPE_SHADING: {
                ThrowColorSpaceError();
                break;
            }

            default:
                colorSpace = PdfName.DEVICERGB;
                break;
            }
            shading.Put(PdfName.COLORSPACE, colorSpace);
        }
Beispiel #7
0
        protected void SetColorSpace(BaseColor color)
        {
            ColorSpace = color;
            int       type       = ExtendedColor.GetType(color);
            PdfObject colorSpace = null;

            switch (type)
            {
            case ExtendedColor.TYPE_GRAY:
            {
                colorSpace = PdfName.Devicegray;
                break;
            }

            case ExtendedColor.TYPE_CMYK:
            {
                colorSpace = PdfName.Devicecmyk;
                break;
            }

            case ExtendedColor.TYPE_SEPARATION:
            {
                SpotColor spot = (SpotColor)color;
                colorDetails = writer.AddSimple(spot.PdfSpotColor);
                colorSpace   = colorDetails.IndirectReference;
                break;
            }

            case ExtendedColor.TYPE_PATTERN:
            case ExtendedColor.TYPE_SHADING:
            {
                ThrowColorSpaceError();
                break;
            }

            default:
                colorSpace = PdfName.Devicergb;
                break;
            }
            Shading.Put(PdfName.Colorspace, colorSpace);
        }
Beispiel #8
0
        protected void setColorSpace(Color color)
        {
            int       type       = ExtendedColor.getType(color);
            PdfObject colorSpace = null;

            switch (type)
            {
            case ExtendedColor.TYPE_GRAY: {
                colorSpace = PdfName.DEVICEGRAY;
                break;
            }

            case ExtendedColor.TYPE_CMYK: {
                colorSpace = PdfName.DEVICECMYK;
                break;
            }

            case ExtendedColor.TYPE_SEPARATION: {
                SpotColor spot = (SpotColor)color;
                colorDetails = writer.addSimple(spot.getPdfSpotColor());
                colorSpace   = colorDetails.IndirectReference;
                break;
            }

            case ExtendedColor.TYPE_PATTERN:
            case ExtendedColor.TYPE_SHADING: {
                throwColorSpaceError();
                break;
            }

            default:
                colorSpace = PdfName.DEVICERGB;
                break;
            }
            shading.put(PdfName.COLORSPACE, colorSpace);
        }