コード例 #1
0
        ////////////////////////////////////////////////////////////////////
        // Constructor
        ////////////////////////////////////////////////////////////////////

        public PdfRadialShading
        (
            PdfDocument Document,
            Double PosX,
            Double PosY,
            Double Width,
            Double Height,
            PdfShadingFunction ShadingFunction
        ) : base(Document, false)
        {
            // create resource code
            ResourceCode = Document.GenerateResourceNumber('R');

            // color space red, green and blue
            AddToDictionary("/ColorSpace", "/DeviceRGB");

            // shading type radial
            AddToDictionary("/ShadingType", "3");

            // bounding box
            AddToDictionary("/BBox", String.Format(NFI.DecSep, "[{0} {1} {2} {3}]", ToPt(PosX), ToPt(PosY), ToPt(PosX + Width), ToPt(PosY + Height)));

            // set center to bounding box center and radius to half the diagonal
            AddToDictionary("/Coords", String.Format(NFI.DecSep, "[{0} {1} {2} {0} {1} 0]",
                                                     ToPt(PosX + Width / 2), ToPt(PosY + Height / 2), ToPt(Math.Sqrt(Width * Width + Height * Height) / 2)));

            // add shading function to shading dictionary
            AddToDictionary("/Function", ShadingFunction);
            return;
        }
コード例 #2
0
ファイル: PdfRadialShading.cs プロジェクト: AxlOnGit/Catalist
        ////////////////////////////////////////////////////////////////////
        /// <summary>
        /// PDF radial shading constructor.
        /// </summary>
        /// <param name="Document">Parent PDF document object</param>
        /// <param name="PosX">Position X</param>
        /// <param name="PosY">Position Y</param>
        /// <param name="Width">Width</param>
        /// <param name="Height">Height</param>
        /// <param name="ShadingFunction">Shading function</param>
        ////////////////////////////////////////////////////////////////////
        public PdfRadialShading
        (
            PdfDocument Document,
            Double PosX,
            Double PosY,
            Double Width,
            Double Height,
            PdfShadingFunction ShadingFunction
        ) : base(Document)
        {
            // create resource code
            ResourceCode = Document.GenerateResourceNumber('S');

            // color space red, green and blue
            Dictionary.Add("/ColorSpace", "/DeviceRGB");

            // shading type radial
            Dictionary.Add("/ShadingType", "3");

            // bounding box
            Dictionary.AddRectangle("/BBox", PosX, PosY, PosX + Width, PosY + Height);

            // set center to bounding box center and radius to half the diagonal
            Dictionary.AddFormat("/Coords", "[{0} {1} {2} {0} {1} 0]", ToPt(PosX + Width / 2), ToPt(PosY + Height / 2), ToPt(Math.Sqrt(Width * Width + Height * Height) / 2));

            // add shading function to shading dictionary
            Dictionary.AddIndirectReference("/Function", ShadingFunction);
            return;
        }
コード例 #3
0
        ////////////////////////////////////////////////////////////////////
        /// <summary>
        /// PDF QR Code constructor
        /// </summary>
        /// <param name="Document">Parent PDF document.</param>
        /// <param name="DataString">Data string to encode.</param>
        /// <param name="ErrorCorrection">Error correction code.</param>
        ////////////////////////////////////////////////////////////////////
        public PdfQRCode
        (
            PdfDocument Document,
            String DataString,
            ErrorCorrection ErrorCorrection
        ) : base(Document, ObjectType.Stream, "/XObject")
        {
            // create resource code
            ResourceCode = Document.GenerateResourceNumber('X');

            // create QR Code object
            QREncoder Encoder = new QREncoder();

            QRCodeMatrix    = Encoder.EncodeQRCode(DataString, ErrorCorrection);
            MatrixDimension = Encoder.MatrixDimension;

            // create stream length object
            ImageLengthObject = new PdfObject(Document, ObjectType.Other);
            Dictionary.AddIndirectReference("/Length", ImageLengthObject);

            // set default values
            ModuleSize = 4;
            QuietZone  = 16;

            // exit
            return;
        }
コード例 #4
0
        ////////////////////////////////////////////////////////////////////
        /// <summary>
        ///     PDF axial shading constructor.
        /// </summary>
        /// <param name="Document">Parent PDF document object</param>
        /// <param name="BBoxLeft">Bounding box left position</param>
        /// <param name="BBoxBottom">Bounding box bottom position</param>
        /// <param name="BBoxWidth">Bounding box width</param>
        /// <param name="BBoxHeight">Bounding box height</param>
        /// <param name="ShadingFunction">Shading function</param>
        ////////////////////////////////////////////////////////////////////
        public PdfAxialShading
        (
            PdfDocument Document,
            double BBoxLeft,
            double BBoxBottom,
            double BBoxWidth,
            double BBoxHeight,
            PdfShadingFunction ShadingFunction
        ) : base(Document)
        {
            // create resource code
            ResourceCode = Document.GenerateResourceNumber('S');

            // color space red, green and blue
            Dictionary.Add("/ColorSpace", "/DeviceRGB");

            // shading type axial
            Dictionary.Add("/ShadingType", "2");

            // add shading function to shading dictionary
            Dictionary.AddIndirectReference("/Function", ShadingFunction);

            // bounding box
            this.BBoxLeft   = BBoxLeft;
            this.BBoxBottom = BBoxBottom;
            BBoxRight       = BBoxLeft + BBoxWidth;
            BBoxTop         = BBoxBottom + BBoxHeight;

            // assume the direction of color change is along x axis
            Mapping     = MappingMode.Relative;
            StartPointX = 0.0;
            StartPointY = 0.0;
            EndPointX   = 1.0;
            EndPointY   = 0.0;
        }
コード例 #5
0
        ////////////////////////////////////////////////////////////////////
        // Constructor
        ////////////////////////////////////////////////////////////////////

        public PdfAxialShading
        (
            PdfDocument Document,
            Double PosX,
            Double PosY,
            Double Width,
            Double Height,
            PdfShadingFunction ShadingFunction
        ) : base(Document, false)
        {
            // create resource code
            ResourceCode = Document.GenerateResourceNumber('A');

            // color space red, green and blue
            AddToDictionary("/ColorSpace", "/DeviceRGB");

            // shading type axial
            AddToDictionary("/ShadingType", "2");

            // bounding box
            AddToDictionary("/BBox", String.Format(NFI.DecSep, "[{0} {1} {2} {3}]", ToPt(PosX), ToPt(PosY), ToPt(PosX + Width), ToPt(PosY + Height)));

            // assume the direction of color change is along x axis
            AddToDictionary("/Coords", String.Format(NFI.DecSep, "[{0} {1} {2} {1}]", ToPt(PosX), ToPt(PosY), ToPt(PosX + Width)));

            // add shading function to shading dictionary
            AddToDictionary("/Function", ShadingFunction);
            return;
        }
コード例 #6
0
        ////////////////////////////////////////////////////////////////////
        /// <summary>
        /// PDF axial shading constructor.
        /// </summary>
        /// <param name="Document">Parent PDF document object</param>
        /// <param name="PosX">Position X</param>
        /// <param name="PosY">Position Y</param>
        /// <param name="Width">Width</param>
        /// <param name="Height">Height</param>
        /// <param name="ShadingFunction">Shading function</param>
        ////////////////////////////////////////////////////////////////////
        public PdfAxialShading
        (
            PdfDocument Document,
            Double PosX,
            Double PosY,
            Double Width,
            Double Height,
            PdfShadingFunction ShadingFunction
        ) : base(Document)
        {
            // create resource code
            ResourceCode = Document.GenerateResourceNumber('S');

            // color space red, green and blue
            Dictionary.Add("/ColorSpace", "/DeviceRGB");

            // shading type axial
            Dictionary.Add("/ShadingType", "2");

            // bounding box
            Dictionary.AddRectangle("/BBox", PosX, PosY, PosX + Width, PosY + Height);

            // assume the direction of color change is along x axis
            Dictionary.AddRectangle("/Coords", PosX, PosY, PosX + Width, PosY);

            // add shading function to shading dictionary
            Dictionary.AddIndirectReference("/Function", ShadingFunction);
            return;
        }
コード例 #7
0
        ////////////////////////////////////////////////////////////////////
        /// <summary>
        /// PDF radial shading constructor.
        /// </summary>
        /// <param name="Document">Parent PDF document object</param>
        /// <param name="PosX">Position X</param>
        /// <param name="PosY">Position Y</param>
        /// <param name="Width">Width</param>
        /// <param name="Height">Height</param>
        /// <param name="ShadingFunction">Shading function</param>
        ////////////////////////////////////////////////////////////////////
        public PdfRadialShading(
			PdfDocument		Document,
			Double			PosX,
			Double			PosY,
			Double			Width,
			Double			Height,
			PdfShadingFunction	ShadingFunction
			)
            : base(Document)
        {
            // create resource code
            ResourceCode = Document.GenerateResourceNumber('S');

            // color space red, green and blue
            Dictionary.Add("/ColorSpace", "/DeviceRGB");

            // shading type radial
            Dictionary.Add("/ShadingType", "3");

            // bounding box
            Dictionary.AddRectangle("/BBox", PosX, PosY, PosX + Width, PosY + Height);

            // set center to bounding box center and radius to half the diagonal
            Dictionary.AddFormat("/Coords", "[{0} {1} {2} {0} {1} 0]", ToPt(PosX + Width / 2), ToPt(PosY + Height / 2), ToPt(Math.Sqrt(Width * Width + Height * Height) / 2));

            // add shading function to shading dictionary
            Dictionary.AddIndirectReference("/Function", ShadingFunction);
            return;
        }
コード例 #8
0
        ////////////////////////////////////////////////////////////////////
        /// <summary>
        /// PDF axial shading constructor.
        /// </summary>
        /// <param name="Document">Parent PDF document object</param>
        /// <param name="PosX">Position X</param>
        /// <param name="PosY">Position Y</param>
        /// <param name="Width">Width</param>
        /// <param name="Height">Height</param>
        /// <param name="ShadingFunction">Shading function</param>
        ////////////////////////////////////////////////////////////////////
        public PdfAxialShading(
			PdfDocument		Document,
			Double			PosX,
			Double			PosY,
			Double			Width,
			Double			Height,
			PdfShadingFunction	ShadingFunction
			)
            : base(Document)
        {
            // create resource code
            ResourceCode = Document.GenerateResourceNumber('S');

            // color space red, green and blue
            Dictionary.Add("/ColorSpace", "/DeviceRGB");

            // shading type axial
            Dictionary.Add("/ShadingType", "2");

            // bounding box
            Dictionary.AddRectangle("/BBox", PosX, PosY, PosX + Width, PosY + Height);

            // assume the direction of color change is along x axis
            Dictionary.AddRectangle("/Coords", PosX, PosY, PosX + Width, PosY);

            // add shading function to shading dictionary
            Dictionary.AddIndirectReference("/Function", ShadingFunction);
            return;
        }
コード例 #9
0
        ////////////////////////////////////////////////////////////////////
        // Constructor
        ////////////////////////////////////////////////////////////////////

        public PdfImage
        (
            PdfDocument Document,
            String ImageFileName
        ) : base(Document, true, "/XObject")
        {
            // create resource code
            ResourceCode = Document.GenerateResourceNumber('X');

            // save image file name
            this.ImageFileName = ImageFileName;

            // test exitance
            if (!File.Exists(ImageFileName))
            {
                throw new ApplicationException("Image file " + ImageFileName + " does not exist");
            }

            // get file length
            FileInfo FI = new FileInfo(ImageFileName);
            Int64    ImageFileLength = FI.Length;

            if (ImageFileLength >= 0x40000000)
            {
                throw new ApplicationException("Image file " + ImageFileName + " too long");
            }

            // image width and height in pixels
            WidthPix     = 0;
            HeightPix    = 0;
            ImageQuality = 100;

            try
            {
                // load the image to get image info
                Picture = new Bitmap(ImageFileName);

                // get image width and height in pixels
                WidthPix  = Picture.Width;
                HeightPix = Picture.Height;

                // image width and height in points
                WidthPt  = (Double)WidthPix * 72.0 / Picture.HorizontalResolution;
                HeightPt = (Double)HeightPix * 72.0 / Picture.VerticalResolution;
            }

            catch (ArgumentException)
            {
                throw new ApplicationException("Invalid image file: " + ImageFileName);
            }

            // create stream length object
            ImageLengthObject = new PdfObject(Document, false);
            AddToDictionary("/Length", ImageLengthObject.ObjectNumber.ToString() + " 0 R");

            // exit
            return;
        }
コード例 #10
0
        internal PdfImage
        (
            PdfDocument Document
        ) : base(Document, ObjectType.Stream, "/XObject")
        {
            // set subtype to /Image
            Dictionary.Add("/Subtype", "/Image");

            // create resource code
            ResourceCode = Document.GenerateResourceNumber('X');
        }
コード例 #11
0
        // object constructor
        internal PdfExtGState
        (
            PdfDocument Document,
            string Key,
            string Value
        ) : base(Document, ObjectType.Dictionary, "/ExtGState")
        {
            // save value
            this.Key   = Key;
            this.Value = Value;

            // create resource code
            ResourceCode = Document.GenerateResourceNumber('G');
        }
コード例 #12
0
        public PdfImage(PdfDocument Document, Bitmap theImage)
            : base(Document, true, "/XObject")
        {
            theBitmapImage = new Bitmap(theImage);
            // create resource code
            ResourceCode = Document.GenerateResourceNumber('I');

            // save image file name
            this.ImageFileName = null;

            // image width and height in pixels
            WidthPix        = 0;
            HeightPix       = 0;
            ImageFormatJpeg = true;

            //try
            //{
            // load the image
            //Bitmap Picture = new Bitmap(theImage);

            // get image width and height in pixels
            WidthPix  = theImage.Width;
            HeightPix = theImage.Height;

            // image width and height in points
            WidthPt  = (Double)WidthPix * 72.0 / theImage.HorizontalResolution;
            HeightPt = (Double)HeightPix * 72.0 / theImage.VerticalResolution;

            ImageConverter converter = new ImageConverter();

            byte[] imageByteStream = (byte[])converter.ConvertTo(theBitmapImage, typeof(byte[]));


            // add items to dictionary
            AddToDictionary("/Subtype", "/Image");
            AddToDictionary("/Width", WidthPix.ToString());
            AddToDictionary("/Height", HeightPix.ToString());
            AddToDictionary("/Filter", "/DCTDecode");
            AddToDictionary("/ColorSpace", "/DeviceRGB");
            AddToDictionary("/BitsPerComponent", "8");
            AddToDictionary("/Length", imageByteStream.Length.ToString());

            // clear memory
            GC.Collect();

            // exit
            return;
        }
コード例 #13
0
        ////////////////////////////////////////////////////////////////////
        /// <summary>
        ///     PDF Tiling pattern constructor.
        /// </summary>
        /// <param name="Document">Document object parent of the object.</param>
        /// <remarks>
        ///     This program support only color tiling pattern: PaintType = 1.
        /// </remarks>
        ////////////////////////////////////////////////////////////////////
        public PdfTilingPattern
        (
            PdfDocument Document
        ) : base(Document, "/Pattern")
        {
            // create resource code
            ResourceCode = Document.GenerateResourceNumber('P');

            // add items to dictionary
            Dictionary.Add("/PatternType", "1"); // Tiling pattern
            Dictionary.Add("/PaintType", "1");   // color
            Dictionary.Add("/TilingType", "1");  // constant
            Dictionary.AddFormat("/BBox", "[0 0 {0} {1}]", ToPt(1.0), ToPt(1.0));
            Dictionary.AddReal("/XStep", ToPt(1.0));
            Dictionary.AddReal("/YStep", ToPt(1.0));
        }
コード例 #14
0
        ////////////////////////////////////////////////////////////////////
        // Constructor
        ////////////////////////////////////////////////////////////////////

        public PdfXObject
        (
            PdfDocument Document,
            Double Width,
            Double Height
        ) : base(Document, "/XObject")
        {
            // create resource code
            ResourceCode = Document.GenerateResourceNumber('X');

            // add items to dictionary
            AddToDictionary("/Subtype", "/Form");
            AddToDictionary("/FormType", "1");
            AddToDictionary("/BBox", String.Format(NFI.DecSep, "[0 0 {0} {1}]", ToPt(Width), ToPt(Height)));
            return;
        }
コード例 #15
0
        ////////////////////////////////////////////////////////////////////
        // Constructor
        // Note: this program support only color tiling pattern
        // PaintType = 1
        ////////////////////////////////////////////////////////////////////

        public PdfTilingPattern
        (
            PdfDocument Document
        ) : base(Document, "/Pattern")
        {
            // create resource code
            ResourceCode = Document.GenerateResourceNumber('P');

            // add items to dictionary
            AddToDictionary("/PatternType", "1");               // Tiling pattern
            AddToDictionary("/PaintType", "1");                 // color
            AddToDictionary("/TilingType", "1");                // constant
            AddToDictionary("/BBox", String.Format(NFI.DecSep, "[0 0 {0} {1}]", ToPt(1.0), ToPt(1.0)));
            AddToDictionary("/XStep", String.Format(NFI.DecSep, "{0}", ToPt(1.0)));
            AddToDictionary("/YStep", String.Format(NFI.DecSep, "{0}", ToPt(1.0)));
            return;
        }
コード例 #16
0
        /// <summary>
        /// PDF X Object constructor
        /// </summary>
        /// <param name="Document">PDF document</param>
        /// <param name="Width">X Object width</param>
        /// <param name="Height">X Object height</param>
        public PdfXObject
        (
            PdfDocument Document,
            Double Width  = 1.0,
            Double Height = 1.0
        ) : base(Document, "/XObject")
        {
            // create resource code
            ResourceCode = Document.GenerateResourceNumber('X');

            // add subtype to dictionary
            Dictionary.Add("/Subtype", "/Form");

            // set boundig box rectangle
            Rect = new PdfRectangle(0.0, 0.0, Width, Height);
            return;
        }
コード例 #17
0
        /// <summary>
        /// PDF X Object constructor
        /// </summary>
        /// <param name="Document">PDF document</param>
        /// <param name="Width">X Object width</param>
        /// <param name="Height">X Object height</param>
        public PdfXObject(
			PdfDocument		Document,
			Double			Width = 1.0,
			Double			Height = 1.0
			)
            : base(Document, "/XObject")
        {
            // create resource code
            ResourceCode = Document.GenerateResourceNumber('X');

            // add subtype to dictionary
            Dictionary.Add("/Subtype", "/Form");

            // set boundig box rectangle
            Rect = new PdfRectangle(0.0, 0.0, Width, Height);
            return;
        }
コード例 #18
0
        ////////////////////////////////////////////////////////////////////
        /// <summary>
        /// PDF radial shading constructor.
        /// </summary>
        /// <param name="Document">Parent PDF document object</param>
        /// <param name="BBoxLeft">Bounding box left position</param>
        /// <param name="BBoxBottom">Bounding box bottom position</param>
        /// <param name="BBoxWidth">Bounding box width</param>
        /// <param name="BBoxHeight">Bounding box height</param>
        /// <param name="ShadingFunction">Shading function</param>
        ////////////////////////////////////////////////////////////////////
        public PdfRadialShading
        (
            PdfDocument Document,
            double BBoxLeft,
            double BBoxBottom,
            double BBoxWidth,
            double BBoxHeight,
            PdfShadingFunction ShadingFunction
        ) : base(Document)
        {
            // create resource code
            ResourceCode = Document.GenerateResourceNumber('S');

            // color space red, green and blue
            Dictionary.Add("/ColorSpace", "/DeviceRGB");

            // shading type axial
            Dictionary.Add("/ShadingType", "3");

            // add shading function to shading dictionary
            Dictionary.AddIndirectReference("/Function", ShadingFunction);

            // bounding box
            this.BBoxLeft   = BBoxLeft;
            this.BBoxBottom = BBoxBottom;
            this.BBoxRight  = BBoxLeft + BBoxWidth;
            this.BBoxTop    = BBoxBottom + BBoxHeight;

            // assume the direction of color change is along x axis
            this.Mapping      = MappingMode.Relative;
            this.StartCenterX = 0.5;
            this.StartCenterY = 0.5;
            this.StartRadius  = 0.0;
            this.EndCenterX   = 0.5;
            this.EndCenterY   = 0.5;
            this.EndRadius    = Math.Sqrt(0.5);
            return;
        }
コード例 #19
0
        ////////////////////////////////////////////////////////////////////
        // Constructor
        ////////////////////////////////////////////////////////////////////

        public PdfQRCode
        (
            PdfDocument Document,
            String DataString,
            ErrorCorrection ErrorCorrection
        ) : base(Document, true, "/XObject")
        {
            // create resource code
            ResourceCode = Document.GenerateResourceNumber('X');

            // create QR Code object
            QREncoder Encoder = new QREncoder();

            QRCodeMatrix    = Encoder.EncodeQRCode(DataString, ErrorCorrection);
            MatrixDimension = Encoder.MatrixDimension;

            // create stream length object
            ImageLengthObject = new PdfObject(Document, false);
            AddToDictionary("/Length", ImageLengthObject.ObjectNumber.ToString() + " 0 R");

            // exit
            return;
        }
コード例 #20
0
ファイル: PdfChart.cs プロジェクト: AxlOnGit/Catalist
        ////////////////////////////////////////////////////////////////////
        /// <summary>
        /// PDF chart constructor
        /// </summary>
        /// <param name="Document">Document object parent of this chart.</param>
        /// <param name="Chart">.NET Chart object.</param>
        /// <param name="Resolution">Resolution in pixels per inch (optional argument)</param>
        ////////////////////////////////////////////////////////////////////
        public PdfChart
        (
            PdfDocument Document,
            Chart Chart,
            Double Resolution = 0.0                                     // pixels per inch
        ) : base(Document, ObjectType.Stream, "/XObject")
        {
            // create resource code
            ResourceCode = Document.GenerateResourceNumber('X');

            // create stream length object
            ImageLengthObject = new PdfObject(Document, ObjectType.Other);
            Dictionary.AddIndirectReference("/Length", ImageLengthObject);

            // save chart
            this.Chart = Chart;

            // save resolution
            if (Resolution != 0)
            {
                // chart resolution in pixels per inch
                this.Resolution          = Resolution;
                this.Chart.RenderingDpiY = Resolution;
            }
            else
            {
                this.Resolution = this.Chart.RenderingDpiY;
            }

            // calculate chart size in user coordinates
            Width  = (Double)this.Chart.Width * 72.0 / (this.Resolution * Document.ScaleFactor);
            Height = (Double)this.Chart.Height * 72.0 / (this.Resolution * Document.ScaleFactor);

            // exit
            return;
        }
コード例 #21
0
        ////////////////////////////////////////////////////////////////////
        // Constructor
        ////////////////////////////////////////////////////////////////////

        public PdfImage
        (
            PdfDocument Document,
            String ImageFileName
        ) : base(Document, true, "/XObject")
        {
            // create resource code
            ResourceCode = Document.GenerateResourceNumber('I');

            // save image file name
            this.ImageFileName = ImageFileName;

            // test exitance
            if (!File.Exists(ImageFileName))
            {
                throw new ApplicationException("Image file " + ImageFileName + " does not exist");
            }

            // get file length
            FileInfo FI = new FileInfo(ImageFileName);
            Int64    ImageFileLength = FI.Length;

            if (ImageFileLength >= 0x40000000)
            {
                throw new ApplicationException("Image file " + ImageFileName + " too long");
            }

            // image width and height in pixels
            WidthPix        = 0;
            HeightPix       = 0;
            ImageFormatJpeg = false;

            try
            {
                // load the image
                Bitmap Picture = new Bitmap(ImageFileName);

                // get image width and height in pixels
                WidthPix  = Picture.Width;
                HeightPix = Picture.Height;

                // image width and height in points
                WidthPt  = (Double)WidthPix * 72.0 / Picture.HorizontalResolution;
                HeightPt = (Double)HeightPix * 72.0 / Picture.VerticalResolution;

                // make sure we have a JPEG picture
                if (Picture.RawFormat.Equals(ImageFormat.Jpeg))
                {
                    ImageFormatJpeg = true;
                }

                // we do not need the picture
                Picture.Dispose();
            }

            catch (ArgumentException)
            {
                throw new ApplicationException("Invalid image file: " + ImageFileName);
            }

            // add items to dictionary
            AddToDictionary("/Subtype", "/Image");
            AddToDictionary("/Width", WidthPix.ToString());
            AddToDictionary("/Height", HeightPix.ToString());
            AddToDictionary("/Filter", "/DCTDecode");
            AddToDictionary("/ColorSpace", "/DeviceRGB");
            AddToDictionary("/BitsPerComponent", "8");
            AddToDictionary("/Length", ImageFileLength.ToString());

            // clear memory
            GC.Collect();

            // exit
            return;
        }
コード例 #22
0
        ////////////////////////////////////////////////////////////////////
        // Constructor
        ////////////////////////////////////////////////////////////////////

        public PdfFont
        (
            PdfDocument Document,                                       // PDF document main object
            String FontFamilyName,                                      // font family name
            FontStyle FontStyle,                                        // font style (Regular, Bold, Italic or Bold | Italic
            Boolean EmbeddedFont                                        // embed font in PDF document file
        ) : base(Document, false, "/Font")
        {
            // save embedded font flag
            this.EmbeddedFont = EmbeddedFont;

            // font style cannot be underline or strikeout
            if ((FontStyle & (FontStyle.Underline | FontStyle.Strikeout)) != 0)
            {
                throw new ApplicationException("Font resource cannot have underline or strikeout");
            }

            // create resource code
            ResourceCode = Document.GenerateResourceNumber('F');

            // get font family structure
            FontFamily = new FontFamily(FontFamilyName);

            // test font style availability
            if (!FontFamily.IsStyleAvailable(FontStyle))
            {
                throw new ApplicationException("Font style not available for font family");
            }

            // design height
            DesignHeight = FontFamily.GetEmHeight(FontStyle);

            // Ascent, descent and line spacing for a one point font
            PdfAscent      = WindowsToPdf(FontFamily.GetCellAscent(FontStyle));
            PdfDescent     = WindowsToPdf(FontFamily.GetCellDescent(FontStyle)); // positive number
            PdfLineSpacing = WindowsToPdf(FontFamily.GetLineSpacing(FontStyle));

            // create design font
            DesignFont = new Font(FontFamily, DesignHeight, FontStyle, GraphicsUnit.Pixel);

            // create windows sdk font info object
            FontInfo = new FontApi(DesignFont, DesignHeight);

            // get character width array
            CharWidthArray = FontInfo.GetCharWidthApi(0, 255);

            // get array of glyph bounding box and width
            GlyphArray = FontInfo.GetGlyphMetricsApi(0, 255);

            // reset active (used) characters to not used
            ActiveChar = new Boolean[256];

            // get outline text metrics structure
            WinOutlineTextMetric OTM = FontInfo.GetOutlineTextMetricsApi();

            // license
            if ((OTM.otmfsType & 2) != 0)
            {
                throw new ApplicationException("Font " + FontFamilyName + " is not licensed for embedding");
            }

            // make sure we have true type font and not device font
            if ((OTM.otmTextMetric.tmPitchAndFamily & 0xe) != 6)
            {
                throw new ApplicationException("Font must be True Type and vector");
            }

            // PDF font flags
            FontFlags = 0;
            if ((OTM.otmfsSelection & 1) != 0)
            {
                FontFlags |= PdfFontFlags.Italic;
            }
            // roman font is a serif font
            if ((OTM.otmTextMetric.tmPitchAndFamily >> 4) == 1)
            {
                FontFlags |= PdfFontFlags.Serif;
            }
            if ((OTM.otmTextMetric.tmPitchAndFamily >> 4) == 4)
            {
                FontFlags |= PdfFontFlags.Script;
            }
            // #define SYMBOL_CHARSET 2
            if (OTM.otmTextMetric.tmCharSet == 2)
            {
                FontFlags   |= PdfFontFlags.Symbolic;
                SymbolicFont = true;
            }
            else
            {
                FontFlags   |= PdfFontFlags.Nonsymbolic;
                SymbolicFont = false;
            }

            // #define TMPF_FIXED_PITCH 0x01 (Note very carefully that those meanings are the opposite of what the constant name implies.)
            if ((OTM.otmTextMetric.tmPitchAndFamily & 1) == 0)
            {
                FontFlags |= PdfFontFlags.FixedPitch;
            }

            // strikeout
            PdfStrikeoutPosition = WindowsToPdf(OTM.otmsStrikeoutPosition);
            PdfStrikeoutWidth    = WindowsToPdf((Int32)OTM.otmsStrikeoutSize);

            // underline
            PdfUnderlinePosition = WindowsToPdf(OTM.otmsUnderscorePosition);
            PdfUnderlineWidth    = WindowsToPdf(OTM.otmsUnderscoreSize);

            // subscript
            PdfSubscriptSize     = WindowsToPdf(OTM.otmptSubscriptSize.Y);
            PdfSubscriptPosition = WindowsToPdf(OTM.otmptSubscriptOffset.Y);

            // superscript
            PdfSuperscriptSize     = WindowsToPdf(OTM.otmptSuperscriptSize.Y);
            PdfSuperscriptPosition = WindowsToPdf(OTM.otmptSuperscriptOffset.Y);

            PdfItalicAngle = (Double)OTM.otmItalicAngle / 10.0;
            PdfFontWeight  = OTM.otmTextMetric.tmWeight;

            // exit
            return;
        }
コード例 #23
0
        ////////////////////////////////////////////////////////////////////
        /// <summary>
        /// PDF chart constructor
        /// </summary>
        /// <param name="Document">Document object parent of this chart.</param>
        /// <param name="Chart">.NET Chart object.</param>
        /// <param name="Resolution">Resolution in pixels per inch (optional argument)</param>
        ////////////////////////////////////////////////////////////////////
        public PdfChart(
			PdfDocument		Document,
			Chart			Chart,
			Double			Resolution = 0.0	// pixels per inch
			)
            : base(Document, ObjectType.Stream, "/XObject")
        {
            // create resource code
            ResourceCode = Document.GenerateResourceNumber('X');

            // create stream length object
            ImageLengthObject = new PdfObject(Document, ObjectType.Other);
            Dictionary.AddIndirectReference("/Length", ImageLengthObject);

            // save chart
            this.Chart = Chart;

            // save resolution
            if(Resolution != 0)
            {
            // chart resolution in pixels per inch
            this.Resolution = Resolution;
            this.Chart.RenderingDpiY = Resolution;
            }
            else
            {
            this.Resolution = this.Chart.RenderingDpiY;
            }

            // calculate chart size in user coordinates
            Width = (Double) this.Chart.Width * 72.0 / (this.Resolution * Document.ScaleFactor);
            Height = (Double) this.Chart.Height * 72.0 / (this.Resolution * Document.ScaleFactor);

            // exit
            return;
        }
コード例 #24
0
        ////////////////////////////////////////////////////////////////////
        /// <summary>
        /// PDF QR Code constructor
        /// </summary>
        /// <param name="Document">Parent PDF document.</param>
        /// <param name="SegDataString">Data string array to encode.</param>
        /// <param name="ErrorCorrection">Error correction code.</param>
        /// <remarks>
        /// The program will calculate the best encoding mode for each segment.
        /// </remarks>
        ////////////////////////////////////////////////////////////////////
        public PdfQRCode(
			PdfDocument		Document,
			String[]		SegDataString,
			ErrorCorrection	ErrorCorrection
			)
            : base(Document, ObjectType.Stream, "/XObject")
        {
            // create resource code
            ResourceCode = Document.GenerateResourceNumber('X');

            // create QR Code object
            QREncoder Encoder = new QREncoder();
            QRCodeMatrix = Encoder.EncodeQRCode(SegDataString, ErrorCorrection);
            MatrixDimension = Encoder.MatrixDimension;

            // create stream length object
            ImageLengthObject = new PdfObject(Document, ObjectType.Other);
            Dictionary.AddIndirectReference("/Length", ImageLengthObject);

            // exit
            return;
        }
コード例 #25
0
        ////////////////////////////////////////////////////////////////////
        /// <summary>
        /// PDF Tiling pattern constructor.
        /// </summary>
        /// <param name="Document">Document object parent of the object.</param>
        /// <remarks>
        /// This program support only color tiling pattern: PaintType = 1.
        /// </remarks>
        ////////////////////////////////////////////////////////////////////
        public PdfTilingPattern(
			PdfDocument		Document
			)
            : base(Document, "/Pattern")
        {
            // create resource code
            ResourceCode = Document.GenerateResourceNumber('P');

            // add items to dictionary
            Dictionary.Add("/PatternType", "1");		// Tiling pattern
            Dictionary.Add("/PaintType", "1");			// color
            Dictionary.Add("/TilingType", "1");		// constant
            Dictionary.AddFormat("/BBox", "[0 0 {0} {1}]", ToPt(1.0), ToPt(1.0));
            Dictionary.AddReal("/XStep", ToPt(1.0));
            Dictionary.AddReal("/YStep", ToPt(1.0));
            return;
        }