Beispiel #1
0
        public virtual void ColorCheckTest2()
        {
            String       outPdf = destinationFolder + "pdfA2b_colorCheckTest2.pdf";
            String       cmpPdf = cmpFolder + "cmp_pdfA2b_colorCheckTest2.pdf";
            PdfWriter    writer = new PdfWriter(outPdf);
            PdfADocument doc    = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_2B, null);

            float[] whitePoint            = new float[] { 0.9505f, 1f, 1.089f };
            float[] gamma                 = new float[] { 2.2f, 2.2f, 2.2f };
            float[] matrix                = new float[] { 0.4124f, 0.2126f, 0.0193f, 0.3576f, 0.7152f, 0.1192f, 0.1805f, 0.0722f, 0.9505f };
            PdfCieBasedCs.CalRgb  calRgb  = new PdfCieBasedCs.CalRgb(whitePoint, null, gamma, matrix);
            PdfCieBasedCs.CalGray calGray = new PdfCieBasedCs.CalGray(whitePoint, null, 2.2f);
            PdfCanvas             canvas  = new PdfCanvas(doc.AddNewPage());

            canvas.GetResources().SetDefaultRgb(calRgb);
            canvas.GetResources().SetDefaultGray(calGray);
            String  shortText = "text";
            PdfFont font      = PdfFontFactory.CreateFont(sourceFolder + "FreeSans.ttf", true);

            canvas.SetFontAndSize(font, 12);
            canvas.SetFillColor(ColorConstants.RED).BeginText().ShowText(shortText).EndText();
            canvas.SetFillColor(DeviceGray.GRAY).BeginText().ShowText(shortText).EndText();
            doc.Close();
            CompareResult(outPdf, cmpPdf);
        }
Beispiel #2
0
 public CalGray(PdfCieBasedCs.CalGray cs, float value)
     : base(cs, new float[] { value })
 {
 }
Beispiel #3
0
        /// <summary>Makes a Color of certain color space and color value.</summary>
        /// <remarks>
        /// Makes a Color of certain color space and color value.
        /// If color value is set in null, all value components will be initialised with zeroes.
        /// </remarks>
        /// <param name="colorSpace">the color space to which the returned Color object relates</param>
        /// <param name="colorValue">the color value of the returned Color object</param>
        /// <returns>the created Color object.</returns>
        public static iText.Kernel.Colors.Color MakeColor(PdfColorSpace colorSpace, float[] colorValue)
        {
            iText.Kernel.Colors.Color c = null;
            bool unknownColorSpace      = false;

            if (colorSpace is PdfDeviceCs)
            {
                if (colorSpace is PdfDeviceCs.Gray)
                {
                    c = colorValue != null ? new DeviceGray(colorValue[0]) : new DeviceGray();
                }
                else
                {
                    if (colorSpace is PdfDeviceCs.Rgb)
                    {
                        c = colorValue != null ? new DeviceRgb(colorValue[0], colorValue[1], colorValue[2]) : new DeviceRgb();
                    }
                    else
                    {
                        if (colorSpace is PdfDeviceCs.Cmyk)
                        {
                            c = colorValue != null ? new DeviceCmyk(colorValue[0], colorValue[1], colorValue[2], colorValue[3]) : new
                                DeviceCmyk();
                        }
                        else
                        {
                            unknownColorSpace = true;
                        }
                    }
                }
            }
            else
            {
                if (colorSpace is PdfCieBasedCs)
                {
                    if (colorSpace is PdfCieBasedCs.CalGray)
                    {
                        PdfCieBasedCs.CalGray calGray = (PdfCieBasedCs.CalGray)colorSpace;
                        c = colorValue != null ? new CalGray(calGray, colorValue[0]) : new CalGray(calGray);
                    }
                    else
                    {
                        if (colorSpace is PdfCieBasedCs.CalRgb)
                        {
                            PdfCieBasedCs.CalRgb calRgb = (PdfCieBasedCs.CalRgb)colorSpace;
                            c = colorValue != null ? new CalRgb(calRgb, colorValue) : new CalRgb(calRgb);
                        }
                        else
                        {
                            if (colorSpace is PdfCieBasedCs.IccBased)
                            {
                                PdfCieBasedCs.IccBased iccBased = (PdfCieBasedCs.IccBased)colorSpace;
                                c = colorValue != null ? new IccBased(iccBased, colorValue) : new IccBased(iccBased);
                            }
                            else
                            {
                                if (colorSpace is PdfCieBasedCs.Lab)
                                {
                                    PdfCieBasedCs.Lab lab = (PdfCieBasedCs.Lab)colorSpace;
                                    c = colorValue != null ? new Lab(lab, colorValue) : new Lab(lab);
                                }
                                else
                                {
                                    unknownColorSpace = true;
                                }
                            }
                        }
                    }
                }
                else
                {
                    if (colorSpace is PdfSpecialCs)
                    {
                        if (colorSpace is PdfSpecialCs.Separation)
                        {
                            PdfSpecialCs.Separation separation = (PdfSpecialCs.Separation)colorSpace;
                            c = colorValue != null ? new Separation(separation, colorValue[0]) : new Separation(separation);
                        }
                        else
                        {
                            if (colorSpace is PdfSpecialCs.DeviceN)
                            {
                                //NChannel goes here also
                                PdfSpecialCs.DeviceN deviceN = (PdfSpecialCs.DeviceN)colorSpace;
                                c = colorValue != null ? new DeviceN(deviceN, colorValue) : new DeviceN(deviceN);
                            }
                            else
                            {
                                if (colorSpace is PdfSpecialCs.Indexed)
                                {
                                    c = colorValue != null ? new Indexed(colorSpace, (int)colorValue[0]) : new Indexed(colorSpace);
                                }
                                else
                                {
                                    unknownColorSpace = true;
                                }
                            }
                        }
                    }
                    else
                    {
                        if (colorSpace is PdfSpecialCs.Pattern)
                        {
                            c = new iText.Kernel.Colors.Color(colorSpace, colorValue);
                        }
                        else
                        {
                            // TODO review this. at least log a warning
                            unknownColorSpace = true;
                        }
                    }
                }
            }
            if (unknownColorSpace)
            {
                throw new PdfException("Unknown color space.");
            }
            return(c);
        }
Beispiel #4
0
 public CalGray(PdfCieBasedCs.CalGray cs)
     : this(cs, 0f)
 {
 }