Example #1
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);
        }
Example #2
0
 public static void SetFlateDecode(TPdfStream DataStream)
 {
     TDictionaryRecord.SaveKey(DataStream, TPdfToken.FilterName,
                               TPdfTokens.GetString(TPdfToken.OpenArray) +
                               TPdfTokens.GetString(TPdfToken.FlateDecodeName) +
                               TPdfTokens.GetString(TPdfToken.CloseArray));
 }
Example #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);
        }
Example #4
0
        private void SavePatterns(TPdfStream DataStream, TXRefSection XRef)
        {
			int HatchCount = HatchPatterns.Count;
			int ImageTextureCount = ImageTexturePatterns.Count;
			int GradientCount = GradientPatterns.Count;
            if (HatchCount + GradientCount + ImageTextureCount <= 0) return;
            TPdfBaseRecord.WriteLine(DataStream, TPdfTokens.GetString(TPdfToken.PatternName));
			TDictionaryRecord.BeginDictionary(DataStream);
			for (int i = 0; i < HatchCount; i++)
			{
				HatchPatterns[i].WritePattern(DataStream, XRef);
			}

			for (int i = 0; i < ImageTextureCount; i++)
			{
				ImageTexturePatterns[i].WritePattern(DataStream, XRef);
			}
            
            for (int i = 0; i < GradientCount; i++)
            {
                GradientPatterns[i].WritePattern(DataStream, XRef);
            }

            TDictionaryRecord.EndDictionary(DataStream);
            if (HatchCount <= 0) return;

            //Pattern color space
            TPdfBaseRecord.WriteLine(DataStream, TPdfTokens.GetString(TPdfToken.ColorSpaceName));
            TDictionaryRecord.BeginDictionary(DataStream);
            PatternColorSpaceId = TPdfHatch.WriteColorSpace(DataStream, XRef);
            TDictionaryRecord.EndDictionary(DataStream);
        }
Example #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);
 }
Example #6
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);
        }
Example #7
0
        public void WriteGStateObject(TPdfStream DataStream, TXRefSection XRef)
        {
            XRef.SetObjectOffset(GStateObjId, DataStream);
            TIndirectRecord.SaveHeader(DataStream, GStateObjId);
            TDictionaryRecord.BeginDictionary(DataStream);
            TDictionaryRecord.SaveKey(DataStream, TPdfToken.TypeName, TPdfTokens.GetString(TPdfToken.ExtGStateName));
            TDictionaryRecord.SaveKey(DataStream, Operator, PdfConv.CoordsToString(Alpha / 255.0));

            if (SMask != null)
            {
                SMaskObjId = XRef.GetNewObject(DataStream);
                TDictionaryRecord.WriteLine(DataStream, TPdfTokens.GetString(TPdfToken.SMaskName));
                TDictionaryRecord.BeginDictionary(DataStream);
                TDictionaryRecord.SaveKey(DataStream, TPdfToken.TypeName, TPdfTokens.GetString(TPdfToken.MaskName));
                TDictionaryRecord.SaveKey(DataStream, TPdfToken.SName, TPdfTokens.GetString(TPdfToken.AlphaName));
                TDictionaryRecord.Write(DataStream, TPdfTokens.GetString(TPdfToken.GName) + " ");
                TIndirectRecord.CallObj(DataStream, SMaskObjId);
                TDictionaryRecord.EndDictionary(DataStream);
            }

            TDictionaryRecord.EndDictionary(DataStream);

            TIndirectRecord.SaveTrailer(DataStream);

            if (SMask != null)
            {
                WriteSMaskObject(DataStream, XRef);
            }
        }
Example #8
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);
        }
Example #9
0
        public void WritePatternObject(TPdfStream DataStream, TXRefSection XRef)
        {
            byte[] PatternDef = GetPatternDef();
            XRef.SetObjectOffset(PatternObjId, DataStream);
            TIndirectRecord.SaveHeader(DataStream, PatternObjId);
            TDictionaryRecord.BeginDictionary(DataStream);
            TDictionaryRecord.SaveKey(DataStream, TPdfToken.TypeName, TPdfTokens.GetString(TPdfToken.PatternName));
            TDictionaryRecord.SaveKey(DataStream, TPdfToken.PatternTypeName, "1");
            TDictionaryRecord.SaveKey(DataStream, TPdfToken.PaintTypeName, "1");
            TDictionaryRecord.SaveKey(DataStream, TPdfToken.TilingTypeName, "2");
            TDictionaryRecord.SaveKey(DataStream, TPdfToken.BBoxName, String.Format(CultureInfo.InvariantCulture, "[0 0 {0} {1}]", ImgWidth, ImgHeight));
            TDictionaryRecord.SaveKey(DataStream, TPdfToken.XStepName, PdfConv.CoordsToString(ImgWidth));
            TDictionaryRecord.SaveKey(DataStream, TPdfToken.YStepName, PdfConv.CoordsToString(ImgHeight));
            TDictionaryRecord.SaveKey(DataStream, TPdfToken.MatrixName, PdfConv.ToString(PatternMatrix, true));
            TDictionaryRecord.SaveKey(DataStream, TPdfToken.LengthName, PatternDef.Length);
            TDictionaryRecord.WriteLine(DataStream, TPdfTokens.GetString(TPdfToken.ResourcesName));

            TDictionaryRecord.BeginDictionary(DataStream);
            TPdfBaseRecord.WriteLine(DataStream, TPdfTokens.GetString(TPdfToken.XObjectName));
            TDictionaryRecord.BeginDictionary(DataStream);

            ImageDef.WriteImage(DataStream, XRef);
            TDictionaryRecord.EndDictionary(DataStream);
            TDictionaryRecord.EndDictionary(DataStream);
            TDictionaryRecord.EndDictionary(DataStream);

            TStreamRecord.BeginSave(DataStream);
            DataStream.Write(PatternDef);
            TStreamRecord.EndSave(DataStream);

            TIndirectRecord.SaveTrailer(DataStream);

            ImageDef.WriteImageObject(DataStream, XRef);
        }
Example #10
0
 protected override void SaveExtraKeys(TPdfStream DataStream, TXRefSection XRef, bool Compress)
 {
     TDictionaryRecord.SaveKey(DataStream, TPdfToken.FunctionsName,
                               TPdfTokens.GetString(TPdfToken.OpenArray) + FunctionCalls(DataStream, XRef) + TPdfTokens.GetString(TPdfToken.CloseArray));
     TDictionaryRecord.SaveKey(DataStream, TPdfToken.BoundsName, PdfConv.ToString(Bounds, true));
     TDictionaryRecord.SaveKey(DataStream, TPdfToken.EncodeName, PdfConv.ToString(Encode, true));
 }
Example #11
0
        public void WritePatternObject(TPdfStream DataStream, TXRefSection XRef)
        {
            int MatrixSize;

            byte[] PatternDef = GetPattern(out MatrixSize);

            XRef.SetObjectOffset(PatternObjId, DataStream);
            TIndirectRecord.SaveHeader(DataStream, PatternObjId);
            TDictionaryRecord.BeginDictionary(DataStream);
            TDictionaryRecord.SaveKey(DataStream, TPdfToken.TypeName, TPdfTokens.GetString(TPdfToken.PatternName));
            TDictionaryRecord.SaveKey(DataStream, TPdfToken.PatternTypeName, "1");
            TDictionaryRecord.SaveKey(DataStream, TPdfToken.PaintTypeName, "2");
            TDictionaryRecord.SaveKey(DataStream, TPdfToken.TilingTypeName, "2");
            TDictionaryRecord.SaveKey(DataStream, TPdfToken.BBoxName, String.Format(CultureInfo.InvariantCulture, "[0 0 {0} {0}]", MatrixSize));
            TDictionaryRecord.SaveKey(DataStream, TPdfToken.XStepName, MatrixSize.ToString(CultureInfo.InvariantCulture));
            TDictionaryRecord.SaveKey(DataStream, TPdfToken.YStepName, MatrixSize.ToString(CultureInfo.InvariantCulture));
            TDictionaryRecord.SaveKey(DataStream, TPdfToken.LengthName, PatternDef.Length);
            TDictionaryRecord.WriteLine(DataStream, TPdfTokens.GetString(TPdfToken.ResourcesName));
            TDictionaryRecord.BeginDictionary(DataStream);
            TDictionaryRecord.EndDictionary(DataStream);

            TDictionaryRecord.EndDictionary(DataStream);

            TStreamRecord.BeginSave(DataStream);
            DataStream.Write(PatternDef);
            TStreamRecord.EndSave(DataStream);

            TIndirectRecord.SaveTrailer(DataStream);
        }
Example #12
0
 internal void SaveResourceDesc(TPdfStream DataStream, TXRefSection XRef, bool IncludeDict)
 {
     if (IncludeDict) TDictionaryRecord.BeginDictionary(DataStream);
     SaveFonts(DataStream, XRef);
     SaveImages(DataStream, XRef);
     SavePatterns(DataStream, XRef);
     SaveGStates(DataStream, XRef);
     if (IncludeDict) TDictionaryRecord.EndDictionary(DataStream);
 }
Example #13
0
 public static void WriteColorSpaceObject(TPdfStream DataStream, TXRefSection XRef, int ColorSpaceId)
 {
     XRef.SetObjectOffset(ColorSpaceId, DataStream);
     TIndirectRecord.SaveHeader(DataStream, ColorSpaceId);
     TPdfBaseRecord.Write(DataStream, TPdfTokens.GetString(TPdfToken.OpenArray));
     TDictionaryRecord.SaveKey(DataStream, TPdfToken.PatternName, TPdfTokens.GetString(TPdfToken.DeviceRGBName));
     TPdfBaseRecord.Write(DataStream, TPdfTokens.GetString(TPdfToken.CloseArray));
     TIndirectRecord.SaveTrailer(DataStream);
 }
Example #14
0
        protected override void SaveExtraKeys(TPdfStream DataStream, TXRefSection XRef, bool Compress)
        {
            Debug.Assert(DataStream.Compress == false); //It shouldn't be turned on at this place.
            TDictionaryRecord.SaveKey(DataStream, TPdfToken.LengthName, FunctionData(Compress).Length.ToString(CultureInfo.InvariantCulture));
            if (NeedsCompression(Compress))
            {
                TStreamRecord.SetFlateDecode(DataStream);
            }

            TDictionaryRecord.SaveKey(DataStream, TPdfToken.SizeName, PdfConv.ToString(Size, true));
            TDictionaryRecord.SaveKey(DataStream, TPdfToken.BitsPerSampleName, 8);
        }
Example #15
0
 private void SaveGStates(TPdfStream DataStream, TXRefSection XRef)
 {
     int aCount = GStates.Count;
     if (aCount <= 0) return;
     TPdfBaseRecord.WriteLine(DataStream, TPdfTokens.GetString(TPdfToken.ExtGStateName));
     TDictionaryRecord.BeginDictionary(DataStream);
     for (int i = 0; i < aCount; i++)
     {
         GStates[i].WriteGState(DataStream, XRef);
     }
     TDictionaryRecord.EndDictionary(DataStream);
 }
Example #16
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, TPdfTokens.GetString(TPdfToken.Type1Name));
            TDictionaryRecord.SaveKey(DataStream, TPdfToken.BaseFontName, GetFontName());
            TDictionaryRecord.SaveKey(DataStream, TPdfToken.EncodingName, EncodingType());

            TDictionaryRecord.EndDictionary(DataStream);
            TIndirectRecord.SaveTrailer(DataStream);
        }
Example #17
0
        public void WritePatternObject(TPdfStream DataStream, TXRefSection XRef)
        {
            XRef.SetObjectOffset(PatternObjId, DataStream);
            TIndirectRecord.SaveHeader(DataStream, PatternObjId);
            TDictionaryRecord.BeginDictionary(DataStream);
            TDictionaryRecord.SaveKey(DataStream, TPdfToken.TypeName, TPdfTokens.GetString(TPdfToken.PatternName));
            TDictionaryRecord.SaveKey(DataStream, TPdfToken.PatternTypeName, "2");

            TDictionaryRecord.SaveKey(DataStream, TPdfToken.MatrixName, DrawingMatrix);

            WriteShadingDictionary(DataStream, XRef);
            TDictionaryRecord.EndDictionary(DataStream);

            TIndirectRecord.SaveTrailer(DataStream);
        }
Example #18
0
        public static void BeginSave(TPdfStream DataStream, int LengthId, bool Compress, int Length1)
        {
            TDictionaryRecord.BeginDictionary(DataStream);
            Write(DataStream, TPdfTokens.GetString(TPdfToken.LengthName) + " ");
            TIndirectRecord.CallObj(DataStream, LengthId);

            if (Length1 >= 0)
            {
                WriteLine(DataStream, TPdfTokens.GetString(TPdfToken.Length1Name) + " " + Length1.ToString(CultureInfo.InvariantCulture));
            }

            if (Compress)
            {
                SetFlateDecode(DataStream);
            }
            TDictionaryRecord.EndDictionary(DataStream);
            BeginSave(DataStream);
        }
Example #19
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);
        }
Example #20
0
        private void SaveFonts(TPdfStream DataStream, TXRefSection XRef)
        {
            int aCount = Fonts.Count;
            if (aCount <= 0) return;
            TPdfBaseRecord.WriteLine(DataStream, TPdfTokens.GetString(TPdfToken.FontName));
            TDictionaryRecord.BeginDictionary(DataStream);

            Fonts.CreateOrderedKeys();
            foreach (string s in Fonts.Keys)
            {
                Fonts.OrderedKeys.Add(s);
            }

            Fonts.OrderedKeys.Sort(); //to keep the reference pdfs always the same.

            foreach (string s in Fonts.OrderedKeys)
            {
                TPdfFont pf = ((TPdfFont)Fonts[s]);
				if (pf.UsedInDoc) pf.WriteFont(DataStream, XRef);
            }
            TDictionaryRecord.EndDictionary(DataStream);
        }
Example #21
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));
        }
Example #22
0
        public void WriteSMaskObject(TPdfStream DataStream, TXRefSection XRef)
        {
            //Actually write stream
            XRef.SetObjectOffset(SMaskObjId, DataStream);
            TIndirectRecord.SaveHeader(DataStream, SMaskObjId);
            TDictionaryRecord.BeginDictionary(DataStream);
            TDictionaryRecord.SaveKey(DataStream, TPdfToken.LengthName, SMask.Length);
            TDictionaryRecord.SaveKey(DataStream, TPdfToken.TypeName, TPdfTokens.GetString(TPdfToken.XObjectName));
            TDictionaryRecord.SaveKey(DataStream, TPdfToken.SubtypeName, TPdfTokens.GetString(TPdfToken.FormName));
            TDictionaryRecord.SaveKey(DataStream, TPdfToken.BBoxName, BBox);
            TDictionaryRecord.WriteLine(DataStream, TPdfTokens.GetString(TPdfToken.GroupName));
            TDictionaryRecord.BeginDictionary(DataStream);
            TDictionaryRecord.SaveKey(DataStream, TPdfToken.SName, TPdfTokens.GetString(TPdfToken.TransparencyName));

            TDictionaryRecord.EndDictionary(DataStream);

            TDictionaryRecord.EndDictionary(DataStream);

            TStreamRecord.BeginSave(DataStream);
            TStreamRecord.Write(DataStream, SMask);
            TStreamRecord.EndSave(DataStream);
            TIndirectRecord.SaveTrailer(DataStream);
        }
Example #23
0
        public void WriteFunctionObject(TPdfStream DataStream, TXRefSection XRef, bool Compress)
        {
            XRef.SetObjectOffset(GetFunctionObjId(DataStream, XRef), DataStream);
            TIndirectRecord.SaveHeader(DataStream, FunctionObjId);
            TDictionaryRecord.BeginDictionary(DataStream);

            TDictionaryRecord.SaveKey(DataStream, TPdfToken.FunctionTypeName, FunctionType);
            if (Domain != null)
            {
                TDictionaryRecord.SaveKey(DataStream, TPdfToken.DomainName, PdfConv.ToString(Domain, true));
            }

            if (Range != null)
            {
                TDictionaryRecord.SaveKey(DataStream, TPdfToken.RangeName, PdfConv.ToString(Range, true));
            }

            SaveExtraKeys(DataStream, XRef, Compress);

            TDictionaryRecord.EndDictionary(DataStream);
            SaveStream(DataStream, XRef, Compress);

            TIndirectRecord.SaveTrailer(DataStream);
        }
Example #24
0
 //This is not only needed because it will be smaller, but also because when using tansparency (SMasks), Acrobat switches the color space,
 //And things like antialiasing text might not look well in the screen. A Single object with SMask will turn all the document into a "Transparent"
 //Document. See "7.6.1 Color Spaces for Transparency Groups" in the pdf reference.
 //So we will try as much as possible to use Masks instead of SMasks.
 private void SaveSMaskAsMask(TPdfStream DataStream)
 {
     TDictionaryRecord.SaveKey(DataStream, TPdfToken.BitsPerComponentName, 1);
     TDictionaryRecord.SaveKey(DataStream, TPdfToken.LengthName, (int)OneBitMask.Length);
     TDictionaryRecord.SaveKey(DataStream, TPdfToken.ImageMaskName, TPdfTokens.GetString(TPdfToken.TrueText));
 }
Example #25
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);
        }
Example #26
0
 protected override void SaveExtraKeys(TPdfStream DataStream, TXRefSection XRef, bool Compress)
 {
     TDictionaryRecord.SaveKey(DataStream, TPdfToken.C0Name, PdfConv.ToString(C0, true));
     TDictionaryRecord.SaveKey(DataStream, TPdfToken.C1Name, PdfConv.ToString(C1, true));
     TDictionaryRecord.SaveKey(DataStream, TPdfToken.NName, PdfConv.DoubleToString(N));
 }
Example #27
0
 private void SaveWidths(TPdfStream DataStream)
 {
     TDictionaryRecord.SaveKey(DataStream, TPdfToken.DWName, UsedChars.DW());
     TDictionaryRecord.SaveKey(DataStream, TPdfToken.WName, UsedChars.W());
 }
Example #28
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;
            }
        }