Example #1
0
        //TODO: Measure

        internal static void CopyTo(PDFDictionary sourceDict, PDFDictionary destinationDict, Page oldPage, Page newPage)
        {
            string[] keys = { "LE", "IC", "BE", "IT" };
            for (int i = 0; i < keys.Length; ++i)
            {
                IPDFObject obj = sourceDict[keys[i]];
                if (obj != null)
                {
                    destinationDict.AddItem(keys[i], obj.Clone());
                }
            }

            PDFDictionary bs = sourceDict["BS"] as PDFDictionary;

            if (bs != null)
            {
                destinationDict.AddItem("BS", AnnotationBorderStyle.Copy(bs));
            }

            PDFArray vertices = sourceDict["Vertices"] as PDFArray;

            if (vertices != null)
            {
                RectangleF oldRect = oldPage == null ? new RectangleF() : oldPage.PageRect;

                destinationDict.AddItem("Vertices", CloneUtility.CopyArrayCoordinates(vertices, oldRect, newPage.PageRect, oldPage == null));
            }

            PDFDictionary measure = sourceDict["Measure"] as PDFDictionary;

            if (measure != null)
            {
                destinationDict.AddItem("Measure", Measure.Copy(measure));
            }
        }
Example #2
0
        private void parsePage(PDFArray arr, IDocumentEssential owner)
        {
            IPDFObject page = arr[0];

            if (page == null)
            {
                return;
            }
            if (page is PDFNumber)
            {
                _page = owner.GetPage((int)(page as PDFNumber).GetValue());
            }
            else if (page is PDFDictionary)
            {
                _page = owner.GetPage(page as PDFDictionary);
            }
            else
            {
                _page = null;
            }

            arr.RemoveItem(0);
            if (_page != null)
            {
                arr.Insert(0, _page.GetDictionary());
            }
            else
            {
                arr.Insert(0, new PDFNull());
            }
        }
Example #3
0
        /// <summary>
        /// Saves the page as a graphic template.
        /// </summary>
        /// <returns cref="GraphicsTemplate">The saved graphics template.</returns>
        public GraphicsTemplate SaveAsTemplate()
        {
            MemoryStream stream = new MemoryStream();

            stream.WriteByte((byte)'q');
            stream.WriteByte((byte)'\n');

            byte[]     buf      = new byte[4096];
            IPDFObject contents = _dictionary["Contents"];

            if (contents is PDFDictionaryStream)
            {
                writeContents(contents as PDFDictionaryStream, buf, stream);
            }
            else if (contents is PDFArray)
            {
                PDFArray arr = contents as PDFArray;
                for (int i = 0; i < arr.Count; ++i)
                {
                    writeContents(arr[i] as PDFDictionaryStream, buf, stream);
                    stream.WriteByte((byte)'\n');
                }
            }

            return(new GraphicsTemplate(stream, Resources.Clone() as Resources, Width, Height));
        }
Example #4
0
        private void addTimesItalicDescriptor()
        {
            PDFDictionary descriptor = new PDFDictionary();

            descriptor.AddItem("Ascent", new PDFNumber(683));
            descriptor.AddItem("CapHeight", new PDFNumber(653));
            descriptor.AddItem("Descent", new PDFNumber(-217));
            descriptor.AddItem("Flags", new PDFNumber(32));
            descriptor.AddItem("FontName", new PDFName("Times-Italic"));
            descriptor.AddItem("FontWeight", new PDFNumber(500));
            descriptor.AddItem("ItalicAngle", new PDFNumber(-15));
            descriptor.AddItem("MissingWidth", new PDFNumber(250));
            descriptor.AddItem("StemV", new PDFNumber(0));
            descriptor.AddItem("XHeight", new PDFNumber(441));
            descriptor.AddItem("Type", new PDFName("FontDescriptor"));

            PDFArray bbox = new PDFArray();

            bbox.AddItem(new PDFNumber(-169));
            bbox.AddItem(new PDFNumber(-217));
            bbox.AddItem(new PDFNumber(1010));
            bbox.AddItem(new PDFNumber(883));
            descriptor.AddItem("FontBBox", bbox);

            GetDictionary().AddItem("FontDescriptor", descriptor);
            addEncoding();
        }
        /// <summary>
        /// Adds the specified action to the end of the collection.
        /// </summary>
        /// <param name="action">Action to be added.</param>
        public void Add(Action action)
        {
            if (action == null)
            {
                throw new ArgumentNullException();
            }

            IPDFObject obj = _parent[_key];

            if (obj == null || obj is PDFDictionary)
            {
                _parent.AddItem(_key, new PDFArray());
            }

            PDFArray arr = _parent[_key] as PDFArray;

            if (obj is PDFDictionary)
            {
                arr.AddItem(obj);
            }

            Action copy = action.Clone(_owner);

            _actions.Add(copy);
            arr.AddItem(copy.GetDictionary());
        }
Example #6
0
        internal override float GetTextHeight(float fontSize)
        {
            PDFArray bbox   = (GetDictionary()["FontDescriptor"] as PDFDictionary)["FontBBox"] as PDFArray;
            float    height = (float)(bbox[3] as PDFNumber).GetValue();

            return(height * fontSize / 1000.0f);
        }
Example #7
0
        private void addHelveticaObliqueDescriptor()
        {
            PDFDictionary descriptor = new PDFDictionary();

            descriptor.AddItem("Ascent", new PDFNumber(718));
            descriptor.AddItem("CapHeight", new PDFNumber(718));
            descriptor.AddItem("Descent", new PDFNumber(-207));
            descriptor.AddItem("Flags", new PDFNumber(32));
            descriptor.AddItem("FontName", new PDFName("Helvetica-Oblique"));
            descriptor.AddItem("FontWeight", new PDFNumber(500));
            descriptor.AddItem("ItalicAngle", new PDFNumber(-12));
            descriptor.AddItem("MissingWidth", new PDFNumber(278));
            descriptor.AddItem("StemV", new PDFNumber(0));
            descriptor.AddItem("XHeight", new PDFNumber(532));
            descriptor.AddItem("Type", new PDFName("FontDescriptor"));

            PDFArray bbox = new PDFArray();

            bbox.AddItem(new PDFNumber(-166));
            bbox.AddItem(new PDFNumber(-225));
            bbox.AddItem(new PDFNumber(1000));
            bbox.AddItem(new PDFNumber(931));
            descriptor.AddItem("FontBBox", bbox);

            GetDictionary().AddItem("FontDescriptor", descriptor);
            addEncoding();
        }
Example #8
0
        private Filter[] getFilters()
        {
            IPDFObject obj = _dictionary["Filter"];

            if (obj == null)
            {
                return(new Filter[0]);
            }

            List <Filter> filters = new List <Filter>();

            if (obj is PDFArray)
            {
                PDFArray arr = obj as PDFArray;
                for (int i = 0; i < arr.Count; ++i)
                {
                    PDFName filter = arr[i] as PDFName;
                    if (filter != null)
                    {
                        filters.Add(convertPDFNameToFilter(filter.GetValue()));
                    }
                }
            }
            else if (obj is PDFName)
            {
                filters.Add(convertPDFNameToFilter((obj as PDFName).GetValue()));
            }

            return(filters.ToArray());
        }
Example #9
0
        public IPDFObject Clone()
        {
            PDFArray arr = new PDFArray();

            arr._items.AddRange(_items);
            return(arr);
        }
Example #10
0
 private void initialize2IDAT(FileStream fs, long positionTRNS)
 {
     if (positionTRNS != 0)
     {
         long oldPosition = fs.Position;
         fs.Position = positionTRNS;
         byte[] buf = new byte[4];
         fs.Read(buf, 0, buf.Length);
         fs.Position += 4;
         byte[] data = new byte[toInt32(buf)];
         fs.Read(data, 0, data.Length);
         PDFArray array = new PDFArray();
         for (int i = 0; i < 3; ++i)
         {
             int tRNS = data[i * 2 + 1];
             if (_bitdepth == 16)
             {
                 tRNS = (((int)data[i * 2] << 8) | data[i * 2 + 1]);
             }
             array.AddItem(new PDFNumber(tRNS));
             array.AddItem(new PDFNumber(tRNS));
         }
         Dictionary.AddItem("Mask", array);
         fs.Position = oldPosition;
     }
     initNotAlphaIDAT(fs, "DeviceRGB", 3);
 }
Example #11
0
 internal AnnotationCollections(PDFArray arr, IDocumentEssential owner, Page page)
 {
     _array = arr;
     _owner = owner;
     _page  = page;
     parseAnnotations();
 }
Example #12
0
        private void initCalRGB(PDFArray array, int gamma)
        {
            PDFDictionary dict = new PDFDictionary();

            array.AddItem(new PDFName("CalRGB"));
            PDFArray arrayWhite  = new PDFArray();
            PDFArray arrayMatrix = new PDFArray();

            arrayWhite.AddItem(new PDFNumber(0.95044f));
            arrayWhite.AddItem(new PDFNumber(1));
            arrayWhite.AddItem(new PDFNumber(1.08893f));
            arrayMatrix.AddItem(new PDFNumber(0.4124f));
            arrayMatrix.AddItem(new PDFNumber(0.21264f));
            arrayMatrix.AddItem(new PDFNumber(0.01934f));
            arrayMatrix.AddItem(new PDFNumber(0.35759f));
            arrayMatrix.AddItem(new PDFNumber(0.71517f));
            arrayMatrix.AddItem(new PDFNumber(0.1192f));
            arrayMatrix.AddItem(new PDFNumber(0.18046f));
            arrayMatrix.AddItem(new PDFNumber(0.07219f));
            arrayMatrix.AddItem(new PDFNumber(0.9504f));
            dict.AddItem("WhitePoint", arrayWhite);
            dict.AddItem("Matrix", arrayMatrix);
            PDFArray gammaA = new PDFArray();

            gammaA.AddItem(new PDFNumber((float)100000 / gamma));
            gammaA.AddItem(new PDFNumber((float)100000 / gamma));
            gammaA.AddItem(new PDFNumber((float)100000 / gamma));
            dict.AddItem("Gamma", gammaA);
            array.AddItem(dict);
        }
Example #13
0
        public Encryptor(PDFDictionary dict, PDFArray idArray)
        {
            if (dict == null)
            {
                throw new PDFException();
            }

            readFilter(dict);
            readAlgorithmVersion(dict);
            readRevision(dict);
            readKeyLength(dict);
            readOwnerHash(dict);
            readUserHash(dict);
            readPermissions(dict);
            if (_revision >= 4)
            {
                readEncryptMetadata(dict);
                readCryptFilters(dict);
            }
            if (_revision == 5)
            {
                readUE(dict);
                readOE(dict);
                readPerms(dict);
            }

            readID(idArray);
        }
Example #14
0
        protected override bool isHitInRange(PDFArray limits, object key)
        {
            string name = key as string;

            if (name == null)
            {
                throw new ArgumentException("Key must have a string type for NameTree.");
            }

            PDFString first = limits[0] as PDFString;
            PDFString last  = limits[1] as PDFString;

            if (first != null && last != null)
            {
                int comp1 = String.Compare(first.GetValue(), name, StringComparison.Ordinal);
                int comp2 = String.Compare(last.GetValue(), name, StringComparison.Ordinal);

                if (comp1 <= 0 && comp2 >= 0)
                {
                    return(true);
                }
            }

            return(false);
        }
Example #15
0
        protected override IPDFObject findItem(PDFArray array, object key)
        {
            if (array == null)
            {
                return(null);
            }

            int number = (int)key;

            for (int i = 0; i < array.Count; i += 2)
            {
                PDFNumber val = array[i] as PDFNumber;
                if (i + 2 < array.Count)
                {
                    PDFNumber val_next = array[i + 2] as PDFNumber;
                    if (val != null && val_next != null &&
                        ((int)val.GetValue()) <= number && number < ((int)val_next.GetValue()))
                    {
                        return(array[i + 1]);
                    }
                }
                else
                {
                    if (val != null && ((int)val.GetValue()) <= number)
                    {
                        return(array[i + 1]);
                    }
                }
            }

            return(null);
        }
Example #16
0
        private IPDFObject createDescendantFonts()
        {
            PDFDictionary dict = new PDFDictionary();

            dict.AddItem("BaseFont", new PDFName(_trueTypeData.FontName));

            PDFDictionary CIDSystemInfo = new PDFDictionary();

            CIDSystemInfo.AddItem("Ordering", new PDFString(System.Text.Encoding.ASCII.GetBytes("Identity"), false));
            CIDSystemInfo.AddItem("Registry", new PDFString(System.Text.Encoding.ASCII.GetBytes("Adobe"), false));
            CIDSystemInfo.AddItem("Supplement", new PDFNumber(0));

            dict.AddItem("CIDSystemInfo", CIDSystemInfo);
            dict.AddItem("CIDToGIDMap", new PDFName("Identity"));
            dict.AddItem("DW", new PDFNumber(_trueTypeData.MissingWidth));
            dict.AddItem("FontDescriptor", createFontDescriptorDictionary());
            dict.AddItem("Type", new PDFName("Font"));
            dict.AddItem("Subtype", new PDFName("CIDFontType2"));

            dict.AddItem("W", createGlyfWidths());

            PDFArray arr = new PDFArray();

            arr.AddItem(dict);

            return(arr);
        }
Example #17
0
        private void getAllLeafs(PDFDictionary dict, List <PageLabel> items)
        {
            PDFArray values = dict[NodeType] as PDFArray;

            if (values != null)
            {
                int           key;
                PDFDictionary value;
                for (int i = 0; i < values.Count; i += 2)
                {
                    key   = (int)(values[i] as PDFNumber).GetValue();
                    value = values[i + 1] as PDFDictionary;
                    items.Add(new PageLabel(key, value));
                }
            }

            PDFArray kids = dict["Kids"] as PDFArray;

            if (kids != null)
            {
                for (int i = 0; i < kids.Count; ++i)
                {
                    if (kids[i] as PDFDictionary != null)
                    {
                        getAllLeafs(kids[i] as PDFDictionary, items);
                    }
                }
            }
        }
Example #18
0
        private PDFDictionary createFontDescriptorDictionary()
        {
            PDFDictionary dict = new PDFDictionary();

            dict.AddItem("Ascent", new PDFNumber(_trueTypeData.Ascent));
            dict.AddItem("Descent", new PDFNumber(_trueTypeData.Descent));
            dict.AddItem("CapHeight", new PDFNumber(0));
            dict.AddItem("Flags", new PDFNumber(32));
            dict.AddItem("FontName", new PDFName(_trueTypeData.FontName));
            dict.AddItem("ItalicAngle", new PDFNumber(_trueTypeData.ItalicAngle));
            dict.AddItem("MissingWidth", new PDFNumber(_trueTypeData.MissingWidth));
            dict.AddItem("StemV", new PDFNumber(0));
            dict.AddItem("Type", new PDFName("FontDescriptor"));

            PDFArray bbox = new PDFArray();

            System.Drawing.Rectangle rect = _trueTypeData.FontBBox;
            bbox.AddItem(new PDFNumber(rect.X));
            bbox.AddItem(new PDFNumber(rect.Y));
            bbox.AddItem(new PDFNumber(rect.Width));
            bbox.AddItem(new PDFNumber(rect.Height));
            dict.AddItem("FontBBox", bbox);

            PDFDictionary fontFileDict = new PDFDictionary();

            System.IO.MemoryStream stream = new System.IO.MemoryStream();
            _trueTypeData.Write(stream, _fontMap.GetIndexes(), _fontMap);

            fontFileDict.AddItem("Length1", new PDFNumber(stream.Length));
            dict.AddItem("FontFile2", new PDFDictionaryStream(fontFileDict, stream));

            return(dict);
        }
Example #19
0
        private void addCourierObliqueDescriptor()
        {
            PDFDictionary descriptor = new PDFDictionary();

            descriptor.AddItem("Ascent", new PDFNumber(629));
            descriptor.AddItem("CapHeight", new PDFNumber(562));
            descriptor.AddItem("Descent", new PDFNumber(-157));
            descriptor.AddItem("Flags", new PDFNumber(32));
            descriptor.AddItem("FontName", new PDFName("Courier-Oblique"));
            descriptor.AddItem("FontWeight", new PDFNumber(500));
            descriptor.AddItem("ItalicAngle", new PDFNumber(-11));
            descriptor.AddItem("MissingWidth", new PDFNumber(600));
            descriptor.AddItem("StemV", new PDFNumber(0));
            descriptor.AddItem("XHeight", new PDFNumber(426));
            descriptor.AddItem("Type", new PDFName("FontDescriptor"));

            PDFArray bbox = new PDFArray();

            bbox.AddItem(new PDFNumber(-6));
            bbox.AddItem(new PDFNumber(-249));
            bbox.AddItem(new PDFNumber(639));
            bbox.AddItem(new PDFNumber(803));
            descriptor.AddItem("FontBBox", bbox);

            GetDictionary().AddItem("FontDescriptor", descriptor);
            addEncoding();
        }
Example #20
0
        internal override float GetTextWidth(PDFString str, float fontSize)
        {
            PDFArray  widths    = GetDictionary()["Widths"] as PDFArray;
            PDFNumber fc        = GetDictionary()["FirstChar"] as PDFNumber;
            int       firstChar = 0;

            if (fc != null)
            {
                firstChar = (int)fc.GetValue();
            }

            byte[] data   = str.GetBytes();
            float  result = 0;

            for (int i = 0; i < data.Length; ++i)
            {
                PDFNumber w = widths[data[i] - firstChar] as PDFNumber;
                if (w != null)
                {
                    return((float)(w.GetValue() * fontSize / 1000.0f));
                }
            }

            return(result);
        }
Example #21
0
        private void addSymbolDescriptor()
        {
            PDFDictionary descriptor = new PDFDictionary();

            descriptor.AddItem("Ascent", new PDFNumber(692));
            descriptor.AddItem("CapHeight", new PDFNumber(0));
            descriptor.AddItem("Descent", new PDFNumber(-14));
            descriptor.AddItem("Flags", new PDFNumber(4));
            descriptor.AddItem("FontName", new PDFName("Symbol"));
            descriptor.AddItem("FontWeight", new PDFNumber(500));
            descriptor.AddItem("ItalicAngle", new PDFNumber(0));
            descriptor.AddItem("MissingWidth", new PDFNumber(250));
            descriptor.AddItem("StemV", new PDFNumber(0));
            descriptor.AddItem("XHeight", new PDFNumber(0));
            descriptor.AddItem("Type", new PDFName("FontDescriptor"));

            PDFArray bbox = new PDFArray();

            bbox.AddItem(new PDFNumber(-180));
            bbox.AddItem(new PDFNumber(-293));
            bbox.AddItem(new PDFNumber(1090));
            bbox.AddItem(new PDFNumber(1010));
            descriptor.AddItem("FontBBox", bbox);

            byte[] data = System.Text.Encoding.ASCII.GetBytes("/space/exclam/universal/numbersign/existential/percent/ampersand/suchthat/parenleft/parenright/asteriskmath/plus/comma/minus/period/slash/zero/one/two/three/four/five/six/seven/eight/nine/colon/semicolon/less/equal/greater/question/congruent/Alpha/Beta/Chi/Delta/Epsilon/Phi/Gamma/Eta/Iota/theta1/Kappa/Lambda/Mu/Nu/Omicron/Pi/Theta/Rho/Sigma/Tau/Upsilon/sigma1/Omega/Xi/Psi/Zeta/bracketleft/therefore/bracketright/perpendicular/underscore/radicalex/alpha/beta/chi/delta/epsilon/phi/gamma/eta/iota/phi1/kappa/lambda/mu/nu/omicron/pi/theta/rho/sigma/tau/upsilon/omega1/omega/xi/psi/zeta/braceleft/bar/braceright/similar/Euro/Upsilon1/minute/lessequal/fraction/infinity/florin/club/diamond/heart/spade/arrowboth/arrowleft/arrowup/arrowright/arrowdown/degree/plusminus/second/greaterequal/multiply/proportional/partialdiff/bullet/divide/notequal/equivalence/approxequal/ellipsis/arrowvertex/arrowhorizex/carriagereturn/aleph/Ifraktur/Rfraktur/weierstrass/circlemultiply/circleplus/emptyset/intersection/union/propersuperset/reflexsuperset/notsubset/propersubset/reflexsubset/element/notelement/angle/gradient/registerserif/copyrightserif/trademarkserif/product/radical/dotmath/logicalnot/logicaland/logicalor/arrowdblboth/arrowdblleft/arrowdblup/arrowdblright/arrowdbldown/lozenge/angleleft/registersans/copyrightsans/trademarksans/summation/parenlefttp/parenleftex/parenleftbt/bracketlefttp/bracketleftex/bracketleftbt/bracelefttp/braceleftmid/braceleftbt/braceex/angleright/integral/integraltp/integralex/integralbt/parenrighttp/parenrightex/parenrightbt/bracketrighttp/bracketrightex/bracketrightbt/bracerighttp/bracerightmid/bracerightbt");
            descriptor.AddItem("CharSet", new PDFString(data, false));

            GetDictionary().AddItem("FontDescriptor", descriptor);

            addSymbolEncodingDictionary();
        }
Example #22
0
        private void init(float[] matrix)
        {
            _dict = new PDFDictionaryStream(new PDFDictionary(), Stream);
            _dict.Dictionary.AddItem("Type", new PDFName("XObject"));
            _dict.Dictionary.AddItem("Subtype", new PDFName("Form"));
            PDFArray array = new PDFArray();

            array.AddItem(new PDFNumber(0));
            array.AddItem(new PDFNumber(0));
            array.AddItem(new PDFNumber(Width));
            array.AddItem(new PDFNumber(Height));
            _dict.Dictionary.AddItem("BBox", array);
            _dict.Dictionary.AddItem("Resources", Resources.Dictionary);
            array = new PDFArray();

            if (matrix != null)
            {
                array.AddItem(new PDFNumber(matrix[0]));
                array.AddItem(new PDFNumber(matrix[1]));
                array.AddItem(new PDFNumber(matrix[2]));
                array.AddItem(new PDFNumber(matrix[3]));
                array.AddItem(new PDFNumber(matrix[4]));
                array.AddItem(new PDFNumber(matrix[5]));
                _dict.Dictionary.AddItem("Matrix", array);
            }
        }
Example #23
0
        private void addZapfDingbatsDescriptor()
        {
            PDFDictionary descriptor = new PDFDictionary();

            descriptor.AddItem("Ascent", new PDFNumber(692));
            descriptor.AddItem("CapHeight", new PDFNumber(0));
            descriptor.AddItem("Descent", new PDFNumber(-140));
            descriptor.AddItem("Flags", new PDFNumber(4));
            descriptor.AddItem("FontName", new PDFName("ZapfDingbats"));
            descriptor.AddItem("FontWeight", new PDFNumber(500));
            descriptor.AddItem("ItalicAngle", new PDFNumber(0));
            descriptor.AddItem("MissingWidth", new PDFNumber(278));
            descriptor.AddItem("StemV", new PDFNumber(0));
            descriptor.AddItem("XHeight", new PDFNumber(0));
            descriptor.AddItem("Type", new PDFName("FontDescriptor"));

            PDFArray bbox = new PDFArray();

            bbox.AddItem(new PDFNumber(-1));
            bbox.AddItem(new PDFNumber(-143));
            bbox.AddItem(new PDFNumber(981));
            bbox.AddItem(new PDFNumber(820));
            descriptor.AddItem("FontBBox", bbox);

            byte[] data = System.Text.Encoding.ASCII.GetBytes("/space/a1/a2/a202/a3/a4/a5/a119/a118/a117/a11/a12/a13/a14/a15/a16/a105/a17/a18/a19/a20/a21/a22/a23/a24/a25/a26/a27/a28/a6/a7/a8/a9/a10/a29/a30/a31/a32/a33/a34/a35/a36/a37/a38/a39/a40/a41/a42/a43/a44/a45/a46/a47/a48/a49/a50/a51/a52/a53/a54/a55/a56/a57/a58/a59/a60/a61/a62/a63/a64/a65/a66/a67/a68/a69/a70/a71/a72/a73/a74/a203/a75/a204/a76/a77/a78/a79/a81/a82/a83/a84/a97/a98/a99/a100/a89/a90/a93/a94/a91/a92/a205/a85/a206/a86/a87/a88/a95/a96/a101/a102/a103/a104/a106/a107/a108/a112/a111/a110/a109/a120/a121/a122/a123/a124/a125/a126/a127/a128/a129/a130/a131/a132/a133/a134/a135/a136/a137/a138/a139/a140/a141/a142/a143/a144/a145/a146/a147/a148/a149/a150/a151/a152/a153/a154/a155/a156/a157/a158/a159/a160/a161/a163/a164/a196/a165/a192/a166/a167/a168/a169/a170/a171/a172/a173/a162/a174/a175/a176/a177/a178/a179/a193/a180/a199/a181/a200/a182/a201/a183/a184/a197/a185/a194/a198/a186/a195/a187/a188/a189/a190/a191");
            descriptor.AddItem("CharSet", new PDFString(data, false));

            GetDictionary().AddItem("FontDescriptor", descriptor);

            addZapfDingbatsEncodingDictionary();
        }
Example #24
0
        internal override float GetCharWidth(char c, float fontSize)
        {
            PDFArray widths = GetDictionary()["Widths"] as PDFArray;

            if (widths != null)
            {
                PDFNumber fc        = GetDictionary()["FirstChar"] as PDFNumber;
                int       firstChar = 0;
                if (fc != null)
                {
                    firstChar = (int)fc.GetValue();
                }

                int       glyf = getGlyf(c);
                PDFNumber w    = widths[glyf - firstChar] as PDFNumber;
                if (w != null)
                {
                    return((float)(w.GetValue() * fontSize / 1000.0f));
                }
            }
            else
            {
                StandardFonts font;
                if (isStandardFont(out font))
                {
                    IGlyfMetrics metrics = getStandardFontMetrics(font);
                    return(metrics.GetCharWidth(c) * fontSize / 1000.0f);
                }
            }
            return(0);
        }
Example #25
0
        internal Destination(IPDFObject dest, IDocumentEssential owner)
        {
            PDFString s = dest as PDFString;

            if (s != null)
            {
                dest = owner.GetDestinationFromNames(s.GetValue());
                if (dest == null)
                {
                    dest = new PDFArray();
                }
            }

            PDFArray array = dest as PDFArray;

            if (array != null)
            {
                parsePage(array, owner);
                parseZoomMode(array);
                parseProperties(array, owner);
            }
            else
            {
                dest = new PDFArray();
            }

            _array = dest as PDFArray;
        }
Example #26
0
        private System.Drawing.Rectangle getFontBBox()
        {
            PDFDictionary fontDescriptor = GetDictionary()["FontDescriptor"] as PDFDictionary;

            if (fontDescriptor != null)
            {
                PDFArray fontBBox = fontDescriptor["FontBBox"] as PDFArray;
                if (fontBBox != null)
                {
                    System.Drawing.Rectangle bbox = new System.Drawing.Rectangle();
                    try
                    {
                        bbox.X      = (int)(fontBBox[0] as PDFNumber).GetValue();
                        bbox.Y      = (int)(fontBBox[1] as PDFNumber).GetValue();
                        bbox.Width  = (int)(fontBBox[2] as PDFNumber).GetValue();
                        bbox.Height = (int)(fontBBox[3] as PDFNumber).GetValue();
                    }
                    catch
                    {
                    }
                    return(bbox);
                }
            }

            StandardFonts bf;

            if (isStandardFont(out bf))
            {
                return(Base14Font.GetFontBBox(bf));
            }
            return(new System.Drawing.Rectangle());
        }
Example #27
0
        private int[] getIndex(PDFDictionary dict)
        {
            PDFArray Index = dict["Index"] as PDFArray;

            if (Index == null)
            {
                int[]     ind  = { 0, 0 };
                PDFNumber size = dict["Size"] as PDFNumber;
                if (size == null || size.GetValue() <= 0)
                {
                    throw new InvalidDocumentException();
                }

                ind[1] = (int)size.GetValue();
                return(ind);
            }

            int[] index = new int[Index.Count];
            for (int i = 0; i < Index.Count; ++i)
            {
                PDFNumber number = Index[i] as PDFNumber;
                if (number == null || number.GetValue() < 0)
                {
                    throw new InvalidDocumentException();
                }

                index[i] = (int)number.GetValue();
            }

            return(index);
        }
Example #28
0
        protected override bool isHitInRange(PDFArray limits, object key)
        {
            if (key.GetType() != System.Type.GetType("int"))
            {
                throw new ArgumentException("Key must have a integer type for NumberTree.");
            }

            int number = (int)key;

            PDFNumber first = limits[0] as PDFNumber;
            PDFNumber last  = limits[1] as PDFNumber;

            if (first != null && last != null)
            {
                int comp1 = ((int)first.GetValue()).CompareTo(number);
                int comp2 = ((int)last.GetValue()).CompareTo(number);

                if (comp1 <= 0 && comp2 >= 0)
                {
                    return(true);
                }
            }

            return(false);
        }
Example #29
0
        private void loadCanvas()
        {
            IPDFObject contents = _dictionary["Contents"];

            if (contents is PDFArray)
            {
                addFirstq(contents as PDFArray);
                addLast(contents as PDFArray);
            }
            else if (contents is PDFDictionaryStream)
            {
                PDFArray arr = new PDFArray();
                addFirstq(arr);
                arr.AddItem(contents);
                addLast(arr);
                _dictionary.AddItem("Contents", arr);
            }
            else
            {
                PDFArray            arr = new PDFArray();
                PDFDictionaryStream ds  = new PDFDictionaryStream();
                MemoryStream        s   = ds.GetStream();
                s.WriteByte((byte)'q');
                s.WriteByte((byte)'\r');
                s.WriteByte((byte)'Q');
                arr.AddItem(ds);
                _dictionary.AddItem("Contents", arr);
                _canvas              = new Canvas(s, Resources, PageRect);
                _canvas.ChangeGroup += new ChangeGroupEventHandler(m_canvas_ChangeGroup);
            }
        }
Example #30
0
        internal PDFArray ParseArray(int objNo, int genNo)
        {
            PDFArray arr = new PDFArray();
            int      b   = _stream.ReadByte();

            for (; ;)
            {
                if (IsEOL(b))
                {
                    SkipEOL();
                    b = _lastParsedByte;
                }

                if (!_usedLastParsedNumber)
                {
                    if (b == ']')
                    {
                        break;
                    }
                }

                IPDFObject obj = readObject(b, objNo, genNo);
                if (obj == null)
                {
                    return(null);
                }
                arr.AddItem(obj);
                b = _lastParsedByte;
            }

            _lastParsedByte = _stream.ReadByte();
            return(arr);
        }