Beispiel #1
0
        private void WriteShadingDictionary(TPdfStream DataStream, TXRefSection XRef)
        {
            TDictionaryRecord.WriteLine(DataStream, TPdfTokens.GetString(TPdfToken.ShadingName));
            TDictionaryRecord.BeginDictionary(DataStream);
            if (GradientType == TGradientType.Axial)
            {
                TDictionaryRecord.SaveKey(DataStream, TPdfToken.ShadingTypeName, "2");
            }
            else
            {
                TDictionaryRecord.SaveKey(DataStream, TPdfToken.ShadingTypeName, "3");
            }

            TDictionaryRecord.SaveKey(DataStream, TPdfToken.ColorSpaceName, TPdfTokens.GetString(TPdfToken.DeviceRGBName));
            TDictionaryRecord.SaveKey(DataStream, TPdfToken.ExtendName, TPdfTokens.GetString(TPdfToken.OpenArray) + "true true" + TPdfTokens.GetString(TPdfToken.CloseArray));

            if (GradientType == TGradientType.Axial)
            {
                TDictionaryRecord.SaveKey(DataStream, TPdfToken.CoordsName, GetCoords());
            }
            else
            {
                TDictionaryRecord.SaveKey(DataStream, TPdfToken.CoordsName, GetRadialCoords());
            }

            TDictionaryRecord.SaveKey(DataStream, TPdfToken.FunctionName, TIndirectRecord.GetCallObj(BlendFunction.GetFunctionObjId(DataStream, XRef)));
            TDictionaryRecord.EndDictionary(DataStream);
        }
Beispiel #2
0
        internal void SaveBookmarks(TPdfStream DataStream, TXRefSection XRef, int OutlinesId)
        {
            if (OutlinesId < 0)
            {
                return;
            }

            int FirstId = -1;
            int LastId  = -1;

            int NextId       = XRef.GetNewObject(DataStream);
            int AllOpenCount = 0;

            SaveBookmarkObjects(DataStream, XRef, Bookmarks, OutlinesId, NextId, ref FirstId, ref LastId, ref AllOpenCount);

            XRef.SetObjectOffset(OutlinesId, DataStream);
            TIndirectRecord.SaveHeader(DataStream, OutlinesId);
            TDictionaryRecord.BeginDictionary(DataStream);

            if (FirstId >= 0)
            {
                TDictionaryRecord.SaveKey(DataStream, TPdfToken.FirstName, TIndirectRecord.GetCallObj(FirstId));
                TDictionaryRecord.SaveKey(DataStream, TPdfToken.LastName, TIndirectRecord.GetCallObj(LastId));                  //LastId must be positive if FirstId is positive.
            }

            if (AllOpenCount > 0)
            {
                TDictionaryRecord.SaveKey(DataStream, TPdfToken.CountName, AllOpenCount);
            }


            TDictionaryRecord.EndDictionary(DataStream);
            TIndirectRecord.SaveTrailer(DataStream);
        }
Beispiel #3
0
        public override void WriteFontObject(TPdfStream DataStream, TXRefSection XRef)
        {
            XRef.SetObjectOffset(FontObjId, DataStream);
            TIndirectRecord.SaveHeader(DataStream, FontObjId);
            TDictionaryRecord.BeginDictionary(DataStream);
            TDictionaryRecord.SaveKey(DataStream, TPdfToken.TypeName, TPdfTokens.GetString(TPdfToken.FontName));
            TDictionaryRecord.SaveKey(DataStream, TPdfToken.SubtypeName, FontType());
            TDictionaryRecord.SaveKey(DataStream, TPdfToken.BaseFontName, GetFontName(Embed, Subset));
            TDictionaryRecord.SaveKey(DataStream, TPdfToken.EncodingName, EncodingType());
            long fc = FirstChar; if (fc < 0)

            {
                fc = 0;
            }

            TDictionaryRecord.SaveKey(DataStream, TPdfToken.FirstCharName, PdfConv.LongToString(fc));
            TDictionaryRecord.SaveKey(DataStream, TPdfToken.LastCharName, PdfConv.LongToString(LastChar));

            XRef.SetObjectOffset(FontDescriptorId, DataStream);
            TDictionaryRecord.SaveKey(DataStream, TPdfToken.FontDescriptorName, TIndirectRecord.GetCallObj(FontDescriptorId));

            SaveWidths(DataStream);

            TDictionaryRecord.EndDictionary(DataStream);
            TIndirectRecord.SaveTrailer(DataStream);

            SaveFontDescriptor(DataStream, FontDescriptorId, XRef, Embed, Subset);
        }
Beispiel #4
0
        internal string GetDestStr(TPdfDestination Dest)
        {
            int PageId = PageTree.GetPageId(Dest.PageNumber);

            string PageStr = TIndirectRecord.GetCallObj(PageId);

            switch (Dest.ZoomOptions)
            {
            case TZoomOptions.Fit:
                return
                    (TPdfTokens.GetString(TPdfToken.OpenArray) +
                     PageStr + TPdfTokens.GetString(TPdfToken.FitName) +
                     TPdfTokens.GetString(TPdfToken.CloseArray));

            case TZoomOptions.FitH:
                return
                    (TPdfTokens.GetString(TPdfToken.OpenArray) +
                     PageStr + TPdfTokens.GetString(TPdfToken.FitHName) +
                     TPdfTokens.GetString(TPdfToken.CloseArray));

            case TZoomOptions.FitV:
                return
                    (TPdfTokens.GetString(TPdfToken.OpenArray) +
                     PageStr + TPdfTokens.GetString(TPdfToken.FitVName) +
                     TPdfTokens.GetString(TPdfToken.CloseArray));
            }
            return
                (TPdfTokens.GetString(TPdfToken.OpenArray) +
                 PageStr + TPdfTokens.GetString(TPdfToken.XYZName) +
                 TPdfTokens.GetString(TPdfToken.CloseArray));
        }
Beispiel #5
0
 internal static void SaveToStream(TPdfStream DataStream, TXRefSection XRef, int CatalogId, int PagesId, int BookmarksId, int AcroFormId, int PermsId, TPdfToken PageLayout)
 {
     XRef.SetObjectOffset(CatalogId, DataStream);
     TIndirectRecord.SaveHeader(DataStream, CatalogId);
     TDictionaryRecord.BeginDictionary(DataStream);
     TDictionaryRecord.SaveKey(DataStream, TPdfToken.TypeName, TPdfTokens.GetString(TPdfToken.CatalogName));
     SaveKey(DataStream, TPdfToken.PagesName, TIndirectRecord.GetCallObj(PagesId));
     if (BookmarksId >= 0)
     {
         SaveKey(DataStream, TPdfToken.OutlinesName, TIndirectRecord.GetCallObj(BookmarksId));
     }
     if (PageLayout != TPdfToken.None)
     {
         SaveKey(DataStream, TPdfToken.PageModeName, TPdfTokens.GetString(PageLayout));
     }
     if (AcroFormId >= 0)
     {
         SaveKey(DataStream, TPdfToken.AcroFormName, TIndirectRecord.GetCallObj(AcroFormId));
     }
     if (PermsId >= 0)
     {
         SaveKey(DataStream, TPdfToken.PermsName, TIndirectRecord.GetCallObj(PermsId));
     }
     EndDictionary(DataStream);
     TIndirectRecord.SaveTrailer(DataStream);
 }
Beispiel #6
0
        internal string GetCallArray(TPdfStream DataStream, TXRefSection XRef, TAcroFormRecord AcroForm, int PageNumber, int PageCount)
        {
            StringBuilder sb     = new StringBuilder();
            int           aCount = Count;

            for (int i = 0; i < aCount; i++)
            {
                int id = Annots[i].GetId(DataStream, XRef);
                if (i > 0)
                {
                    sb.Append(" ");
                }
                sb.Append(TIndirectRecord.GetCallObj(id));
            }

            string SignatureFields = AcroForm.GetSignatureFieldsCallArray(DataStream, XRef, PageNumber, PageCount);             //Signature Fields are also widget annotations.

            if (SignatureFields.Length > 0)
            {
                sb.Append(" ");
                sb.Append(SignatureFields);
            }

            if (sb.Length == 0)
            {
                return(String.Empty);
            }
            return(TPdfTokens.GetString(TPdfToken.OpenArray) + sb.ToString()
                   + TPdfTokens.GetString(TPdfToken.CloseArray));
        }
Beispiel #7
0
        protected void SaveFontDescriptor(TPdfStream DataStream, int FontDescriptorId, TXRefSection XRef, bool Embed, bool Subset)
        {
            XRef.SetObjectOffset(FontDescriptorId, DataStream);
            TIndirectRecord.SaveHeader(DataStream, FontDescriptorId);
            TDictionaryRecord.BeginDictionary(DataStream);
            TDictionaryRecord.SaveKey(DataStream, TPdfToken.TypeName, TPdfTokens.GetString(TPdfToken.FontDescriptorName));
            TDictionaryRecord.SaveKey(DataStream, TPdfToken.FontNameName, GetFontName(Embed, Subset));

            string BBox =
                TPdfTokens.GetString(TPdfToken.OpenArray) +
                FTrueTypeData.BoundingBox.GetBBox(FTrueTypeData.UnitsPerEm) +
                TPdfTokens.GetString(TPdfToken.CloseArray);

            TDictionaryRecord.SaveKey(DataStream, TPdfToken.FontBBoxName, BBox);

            TDictionaryRecord.SaveKey(DataStream, TPdfToken.FontAscentName, (int)Math.Round(FTrueTypeData.Ascent * 1000F / FTrueTypeData.UnitsPerEm));
            TDictionaryRecord.SaveKey(DataStream, TPdfToken.FontDescentName, (int)Math.Round(FTrueTypeData.Descent * 1000F / FTrueTypeData.UnitsPerEm));
            TDictionaryRecord.SaveKey(DataStream, TPdfToken.CapHeightName, (int)Math.Round(FTrueTypeData.CapHeight * 1000F / FTrueTypeData.UnitsPerEm));
            TDictionaryRecord.SaveKey(DataStream, TPdfToken.ItalicAngleName, FTrueTypeData.ItalicAngle.ToString(CultureInfo.InvariantCulture));
            TDictionaryRecord.SaveKey(DataStream, TPdfToken.StemVName, 80);             //StemV info is not present on a true type font. 80 seems to be what adobe writes.

            TDictionaryRecord.SaveKey(DataStream, TPdfToken.FlagsName, FTrueTypeData.FontFlags);

            if (Embed)
            {
                TDictionaryRecord.SaveKey(DataStream, TPdfToken.FontFile2Name, TIndirectRecord.GetCallObj(EmbeddedData.GetStreamId(DataStream, XRef)));
            }


            TDictionaryRecord.EndDictionary(DataStream);
            TIndirectRecord.SaveTrailer(DataStream);

            EmbeddedData.WriteFont(DataStream, XRef, FCompress);
        }
Beispiel #8
0
        internal string GetCallArray(TPdfStream DataStream, TXRefSection XRef, bool OnlySignatures)
        {
            StringBuilder sb     = new StringBuilder();
            int           aCount = Count;

            for (int i = 0; i < aCount; i++)
            {
                int id = Fields[i].GetId(DataStream, XRef, OnlySignatures);
                if (id < 0)
                {
                    continue;
                }
                if (sb.Length > 0)
                {
                    sb.Append(" ");
                }
                sb.Append(TIndirectRecord.GetCallObj(id));
            }
            if (sb.Length == 0)
            {
                return(String.Empty);
            }

            if (OnlySignatures)
            {
                return(sb.ToString());
            }

            return(TPdfTokens.GetString(TPdfToken.OpenArray) + sb.ToString()
                   + TPdfTokens.GetString(TPdfToken.CloseArray));
        }
Beispiel #9
0
 private static void SaveResourcesFirstXObject(TPdfStream DataStream, TXRefSection XRef, int FRMId)
 {
     Write(DataStream, TPdfTokens.GetString(TPdfToken.XObjectName));
     BeginDictionary(DataStream);
     SaveKey(DataStream, TPdfToken.FRMName, TIndirectRecord.GetCallObj(FRMId));
     EndDictionary(DataStream);
     EndDictionary(DataStream);
 }
Beispiel #10
0
 private static void SaveResourcesSecondXObject(TPdfStream DataStream, int n0Id, int n2Id)
 {
     Write(DataStream, TPdfTokens.GetString(TPdfToken.XObjectName));
     BeginDictionary(DataStream);
     SaveKey(DataStream, TPdfToken.n0Name, TIndirectRecord.GetCallObj(n0Id));
     SaveKey(DataStream, TPdfToken.n2Name, TIndirectRecord.GetCallObj(n2Id));
     EndDictionary(DataStream);
     EndDictionary(DataStream);
 }
Beispiel #11
0
        internal override void SaveToStream(TPdfStream DataStream, TXRefSection XRef)
        {
            BeginSaveToStream(DataStream, XRef);
            SaveKey(DataStream, TPdfToken.SubtypeName, TPdfTokens.GetString(TPdfToken.LinkName));
            SaveKey(DataStream, TPdfToken.AName, TIndirectRecord.GetCallObj(ActionId));
            SaveKey(DataStream, TPdfToken.BorderName, TPdfTokens.GetString(TPdfToken.Border0));
            EndSaveToStream(DataStream, XRef);

            SaveAction(DataStream, XRef);
        }
Beispiel #12
0
        private static int SaveAPRef(TPdfStream DataStream, TXRefSection XRef)
        {
            //AP call
            int APId = XRef.GetNewObject(DataStream);

            Write(DataStream, TPdfTokens.GetString(TPdfToken.APName));
            BeginDictionary(DataStream);
            SaveKey(DataStream, TPdfToken.NName, TIndirectRecord.GetCallObj(APId));
            EndDictionary(DataStream);
            return(APId);
        }
Beispiel #13
0
        private string FunctionCalls(TPdfStream DataStream, TXRefSection XRef)
        {
            StringBuilder Result = new StringBuilder(Functions.Length * 10);

            foreach (TPdfFunction fn in Functions)
            {
                Result.Append(TIndirectRecord.GetCallObj(fn.GetFunctionObjId(DataStream, XRef)));
                Result.Append(" ");
            }

            return(Result.ToString());
        }
Beispiel #14
0
        internal override void SaveToStream(TPdfStream DataStream, TXRefSection XRef, TPageInfo ParentPage)
        {
            BeginSaveToStream(DataStream, XRef);

            //Annot
            SaveKey(DataStream, TPdfToken.TypeName, TPdfTokens.GetString(TPdfToken.AnnotName));             //Annots and Fields mix their dictionaries. See "Digital Signature Appearances" to see why annots are required even in non visible sigs.
            SaveKey(DataStream, TPdfToken.SubtypeName, TPdfTokens.GetString(TPdfToken.WidgetName));

            RectangleF           Rect = new RectangleF(0, 0, 0, 0);
            TPdfVisibleSignature VSig = Signature as TPdfVisibleSignature;

            int APId = -1;

            if (VSig != null)
            {
                Rect = VSig.Rect;
                APId = SaveAPRef(DataStream, XRef);
            }

            SaveKey(DataStream, TPdfToken.RectName,
                    TPdfTokens.GetString(TPdfToken.OpenArray) +
                    String.Format(CultureInfo.InvariantCulture, "{0} {1} {2} {3}", Rect.Left, Rect.Top, Rect.Right, Rect.Bottom) +
                    TPdfTokens.GetString(TPdfToken.CloseArray)
                    );

            SaveKey(DataStream, TPdfToken.PName, TIndirectRecord.GetCallObj(ParentPage.Id));
            SaveKey(DataStream, TPdfToken.FName, 132);              //bits 3 and 8

            //Field
            SaveKey(DataStream, TPdfToken.FTName, TPdfTokens.GetString(TPdfToken.SigName));
            if (Signature.Name != null)
            {
                SaveUnicodeKey(DataStream, TPdfToken.TName, Signature.Name);
            }
            SaveKey(DataStream, TPdfToken.FfName, 1);

            XRef.SetObjectOffset(GetSigDictionaryId(DataStream, XRef), DataStream);
            SaveKey(DataStream, TPdfToken.VName, TIndirectRecord.GetCallObj(SigDictionaryId));

            EndSaveToStream(DataStream, XRef);

            if (VSig != null)
            {
                SaveAPObj(DataStream, XRef, APId, VSig);
            }

            SaveSigDictionary(DataStream, XRef, SigDictionaryId);
        }
Beispiel #15
0
 internal void SaveToStream(TPdfStream DataStream, TXRefSection XRef, int MDPId)
 {
     if (GetId(DataStream, XRef, MDPId) < 0)
     {
         return;
     }
     if (MDPId < 0)
     {
         return;
     }
     XRef.SetObjectOffset(PermsId, DataStream);
     TIndirectRecord.SaveHeader(DataStream, PermsId);
     BeginDictionary(DataStream);
     SaveKey(DataStream, TPdfToken.DocMDPName, TIndirectRecord.GetCallObj(MDPId));
     EndDictionary(DataStream);
     TIndirectRecord.SaveTrailer(DataStream);
 }
Beispiel #16
0
        //For unicode fonts, we actually need to write 2 fonts, one type 0 and one CID.
        public override void WriteFontObject(TPdfStream DataStream, TXRefSection XRef)
        {
            //Save Type 0 Font.
            XRef.SetObjectOffset(FontObjId, DataStream);
            TIndirectRecord.SaveHeader(DataStream, FontObjId);
            TDictionaryRecord.BeginDictionary(DataStream);
            TDictionaryRecord.SaveKey(DataStream, TPdfToken.TypeName, TPdfTokens.GetString(TPdfToken.FontName));
            TDictionaryRecord.SaveKey(DataStream, TPdfToken.SubtypeName, TPdfTokens.GetString(TPdfToken.Type0Name));
            TDictionaryRecord.SaveKey(DataStream, TPdfToken.BaseFontName, GetFontName(true, Subset));
            TDictionaryRecord.SaveKey(DataStream, TPdfToken.EncodingName, EncodingType());

            XRef.SetObjectOffset(CIDFontId, DataStream);
            TDictionaryRecord.SaveKey(DataStream, TPdfToken.DescendantFontsName,
                                      TPdfTokens.GetString(TPdfToken.OpenArray) + TIndirectRecord.GetCallObj(CIDFontId) + TPdfTokens.GetString(TPdfToken.CloseArray));

            TDictionaryRecord.SaveKey(DataStream, TPdfToken.ToUnicodeName, TIndirectRecord.GetCallObj(ToUnicodeId));

            TDictionaryRecord.EndDictionary(DataStream);
            TIndirectRecord.SaveTrailer(DataStream);

            //Save CID Font.
            XRef.SetObjectOffset(CIDFontId, DataStream);
            TIndirectRecord.SaveHeader(DataStream, CIDFontId);
            TDictionaryRecord.BeginDictionary(DataStream);
            TDictionaryRecord.SaveKey(DataStream, TPdfToken.TypeName, TPdfTokens.GetString(TPdfToken.FontName));
            TDictionaryRecord.SaveKey(DataStream, TPdfToken.SubtypeName, TPdfTokens.GetString(TPdfToken.CIDFontType2Name));
            TDictionaryRecord.SaveKey(DataStream, TPdfToken.BaseFontName, GetFontName(true, Subset));
            TPdfBaseRecord.WriteLine(DataStream, TPdfTokens.GetString(TPdfToken.CIDSystemInfo));
            TPdfBaseRecord.WriteLine(DataStream, TPdfTokens.GetString(TPdfToken.CIDToGIDMap));

            SaveWidths(DataStream);

            XRef.SetObjectOffset(FontDescriptorId, DataStream);
            TDictionaryRecord.SaveKey(DataStream, TPdfToken.FontDescriptorName, TIndirectRecord.GetCallObj(FontDescriptorId));

            TDictionaryRecord.EndDictionary(DataStream);
            TIndirectRecord.SaveTrailer(DataStream);

            SaveToUnicode(DataStream, XRef);
            SaveFontDescriptor(DataStream, FontDescriptorId, XRef, true, Subset);
        }
Beispiel #17
0
 internal static void SaveToStream(TPdfStream DataStream, int PageListId, TPageInfo PageInfo, TAcroFormRecord AcroForm, TXRefSection XRef, int PageNumber, int PageCount)
 {
     XRef.SetObjectOffset(PageInfo.Id, DataStream);
     TIndirectRecord.SaveHeader(DataStream, PageInfo.Id);
     BeginDictionary(DataStream);
     SaveKey(DataStream, TPdfToken.TypeName, TPdfTokens.GetString(TPdfToken.PageName));
     SaveKey(DataStream, TPdfToken.ParentName, TIndirectRecord.GetCallObj(PageListId));
     SaveKey(DataStream, TPdfToken.ContentsName, TIndirectRecord.GetCallObj(PageInfo.Contents.Id));
     SaveKey(DataStream, TPdfToken.MediaBoxName,
             TPdfTokens.GetString(TPdfToken.OpenArray) +
             "0 0 " +
             PdfConv.CoordsToString(PageInfo.Contents.PageSize.Width * 72 / 100) + " " +
             PdfConv.CoordsToString(PageInfo.Contents.PageSize.Height * 72 / 100) +
             TPdfTokens.GetString(TPdfToken.CloseArray)
             );
     if (PageInfo.Annots.HasAnnots(AcroForm, PageNumber, PageCount))
     {
         SaveKey(DataStream, TPdfToken.AnnotsName, PageInfo.Annots.GetCallArray(DataStream, XRef, AcroForm, PageNumber, PageCount));
     }
     EndDictionary(DataStream);
     TIndirectRecord.SaveTrailer(DataStream);
 }
Beispiel #18
0
        internal static void SaveToStream(TPdfStream DataStream, TXRefSection XRef, int CatalogId, int InfoId)
        {
            TPdfBaseRecord.WriteLine(DataStream, TPdfTokens.GetString(TPdfToken.Trailer));

            TDictionaryRecord.BeginDictionary(DataStream);
            TDictionaryRecord.SaveKey(DataStream, TPdfToken.SizeName, XRef.Count);
            TDictionaryRecord.SaveKey(DataStream, TPdfToken.RootName, TIndirectRecord.GetCallObj(CatalogId));
            TDictionaryRecord.SaveKey(DataStream, TPdfToken.InfoName, TIndirectRecord.GetCallObj(InfoId));

            Byte[] FileIdBytes = Guid.NewGuid().ToByteArray();
            string FileId      = PdfConv.ToHexString(FileIdBytes, true);

            TDictionaryRecord.SaveKey(DataStream, TPdfToken.IDName,
                                      TPdfTokens.GetString(TPdfToken.OpenArray) +
                                      FileId + " " + FileId +
                                      TPdfTokens.GetString(TPdfToken.CloseArray));

            TDictionaryRecord.EndDictionary(DataStream);

            TPdfBaseRecord.WriteLine(DataStream, TPdfTokens.GetString(TPdfToken.StartXRef));
            TPdfBaseRecord.WriteLine(DataStream, XRef.StartPosition.ToString(CultureInfo.InvariantCulture));
            TPdfBaseRecord.WriteLine(DataStream, TPdfTokens.GetString(TPdfToken.Eof));
        }
Beispiel #19
0
        private void WriteImageOrMaskObject(TPdfStream DataStream, TXRefSection XRef, bool IsSMask, int ObjId)
        {
            XRef.SetObjectOffset(ObjId, DataStream);
            TIndirectRecord.SaveHeader(DataStream, ObjId);
            TDictionaryRecord.BeginDictionary(DataStream);
            TDictionaryRecord.SaveKey(DataStream, TPdfToken.TypeName, TPdfTokens.GetString(TPdfToken.XObjectName));
            TDictionaryRecord.SaveKey(DataStream, TPdfToken.SubtypeName, TPdfTokens.GetString(TPdfToken.ImageName));
            TDictionaryRecord.SaveKey(DataStream, TPdfToken.WidthName, FImageWidth);
            TDictionaryRecord.SaveKey(DataStream, TPdfToken.HeightName, FImageHeight);

            if (!IsSMask)
            {
                TDictionaryRecord.SaveKey(DataStream, TPdfToken.BitsPerComponentName, FBitsPerComponent);
                if (FSMask != null)
                {
                    TDictionaryRecord.SaveKey(DataStream, MaskOrSMask, TIndirectRecord.GetCallObj(SMaskId));
                }
                if (FMask != null)
                {
                    TDictionaryRecord.SaveKey(DataStream, TPdfToken.MaskName, FMask);
                }
                TDictionaryRecord.SaveKey(DataStream, TPdfToken.LengthName, (int)FImage.Length);
                TDictionaryRecord.SaveKey(DataStream, TPdfToken.ColorSpaceName, FColorSpace);                  //This value is stored on the PropertyTagExifColorSpace property of the image for JPEG.
                if (FDecodeParmsName != null)
                {
                    TDictionaryRecord.SaveKey(DataStream, TPdfToken.DecodeParmsName, FDecodeParmsName);
                }
            }
            else
            {
                if (OneBitMask != null && FMask == null)
                {
                    SaveSMaskAsMask(DataStream);
                }
                else
                {
                    TDictionaryRecord.SaveKey(DataStream, TPdfToken.BitsPerComponentName, 8);
                    TDictionaryRecord.SaveKey(DataStream, TPdfToken.LengthName, (int)FSMask.Length);
                    TDictionaryRecord.SaveKey(DataStream, TPdfToken.ColorSpaceName, TPdfTokens.GetString(TPdfToken.DeviceGrayName));                      //This value is stored on the PropertyTagExifColorSpace property of the image for JPEG.
                    if (FDecodeParmsSMask != null)
                    {
                        TDictionaryRecord.SaveKey(DataStream, TPdfToken.DecodeParmsName, FDecodeParmsSMask);
                    }
                }
            }

            TDictionaryRecord.SaveKey(DataStream, TPdfToken.FilterName, FFilterName);


            TDictionaryRecord.EndDictionary(DataStream);

            TStreamRecord.BeginSave(DataStream);
            if (!IsSMask)
            {
                DataStream.Write(FImage);
            }
            else
            {
                if (OneBitMask != null)
                {
                    DataStream.Write(OneBitMask);
                }
                else
                {
                    DataStream.Write(FSMask);
                }
            }
            TStreamRecord.EndSave(DataStream);

            TIndirectRecord.SaveTrailer(DataStream);
        }
Beispiel #20
0
        internal void SaveBookmarkObjects(TPdfStream DataStream, TXRefSection XRef, TBookmarkList bmks, int ParentId, int ObjectId, ref int FirstId, ref int LastId, ref int AllOpenCount)
        {
            int PreviousId = -1;

            for (int i = 0; i < bmks.Count; i++)
            {
                TBookmark b = bmks[i];
                AllOpenCount++;

                int NextId = -1;
                if (i < bmks.Count - 1)
                {
                    NextId = XRef.GetNewObject(DataStream);
                }
                LastId = ObjectId;
                if (FirstId == -1)
                {
                    FirstId = ObjectId;
                }

                int FirstChildId   = -1;
                int LastChildId    = -1;
                int ChildOpenCount = 0;
                if (b.FChildren.Count > 0)
                {
                    FirstChildId = XRef.GetNewObject(DataStream);
                    int ChildLastId = -1;
                    SaveBookmarkObjects(DataStream, XRef, b.FChildren, ObjectId, FirstChildId, ref FirstId, ref ChildLastId, ref ChildOpenCount);
                    if (!b.ChildrenCollapsed)
                    {
                        AllOpenCount += ChildOpenCount;
                    }
                    LastChildId = ChildLastId;
                }


                XRef.SetObjectOffset(ObjectId, DataStream);
                TIndirectRecord.SaveHeader(DataStream, ObjectId);
                TDictionaryRecord.BeginDictionary(DataStream);
                TDictionaryRecord.SaveUnicodeKey(DataStream, TPdfToken.TitleName, b.Title);
                TDictionaryRecord.SaveKey(DataStream, TPdfToken.ParentName, TIndirectRecord.GetCallObj(ParentId));
                if (PreviousId >= 0)
                {
                    TDictionaryRecord.SaveKey(DataStream, TPdfToken.PrevName, TIndirectRecord.GetCallObj(PreviousId));
                }

                if (NextId >= 0)
                {
                    TDictionaryRecord.SaveKey(DataStream, TPdfToken.NextName, TIndirectRecord.GetCallObj(NextId));
                }

                if (FirstChildId >= 0)
                {
                    TDictionaryRecord.SaveKey(DataStream, TPdfToken.FirstName, TIndirectRecord.GetCallObj(FirstChildId));
                }

                if (LastChildId >= 0)
                {
                    TDictionaryRecord.SaveKey(DataStream, TPdfToken.LastName, TIndirectRecord.GetCallObj(LastChildId));
                }
                if (ChildOpenCount > 0)
                {
                    if (b.ChildrenCollapsed)
                    {
                        TDictionaryRecord.SaveKey(DataStream, TPdfToken.CountName, -ChildOpenCount);
                    }
                    else
                    {
                        TDictionaryRecord.SaveKey(DataStream, TPdfToken.CountName, ChildOpenCount);
                    }
                }


                if (b.Destination != null)
                {
                    TDictionaryRecord.SaveKey(DataStream, TPdfToken.DestName, GetDestStr(b.Destination));
                }

                if (b.TextColor.R != 0 || b.TextColor.G != 0 || b.TextColor.B != 0)
                {
                    TDictionaryRecord.SaveKey(DataStream, TPdfToken.CName, TPdfTokens.GetString(TPdfToken.OpenArray) + PdfConv.ToString(b.TextColor) + TPdfTokens.GetString(TPdfToken.CloseArray));
                }

                if (b.TextStyle != TBookmarkStyle.None)
                {
                    int k = 0;
                    if ((b.TextStyle & TBookmarkStyle.Italic) != 0)
                    {
                        k |= 1;
                    }
                    if ((b.TextStyle & TBookmarkStyle.Bold) != 0)
                    {
                        k |= 2;
                    }
                    TDictionaryRecord.SaveKey(DataStream, TPdfToken.FName, k);
                }

                TDictionaryRecord.EndDictionary(DataStream);
                TIndirectRecord.SaveTrailer(DataStream);

                PreviousId = ObjectId;
                ObjectId   = NextId;
            }
        }