Exemplo n.º 1
0
        private void SaveToUnicode(TPdfStream DataStream, TXRefSection XRef)
        {
            XRef.SetObjectOffset(ToUnicodeId, DataStream);
            TIndirectRecord.SaveHeader(DataStream, ToUnicodeId);

            XRef.SetObjectOffset(ToUnicodeLenId, DataStream);
            TStreamRecord.BeginSave(DataStream, ToUnicodeLenId, FCompress);
            long StartStream = DataStream.Position;
            bool Compressing = DataStream.Compress;

            try
            {
                DataStream.Compress = FCompress;
                WriteToUnicodeData(DataStream);
            }
            finally
            {
                DataStream.Compress = Compressing;
            }
            long EndStream = DataStream.Position;

            TStreamRecord.EndSave(DataStream);
            TIndirectRecord.SaveTrailer(DataStream);

            XRef.SetObjectOffset(ToUnicodeLenId, DataStream);

            TIndirectRecord.SaveHeader(DataStream, ToUnicodeLenId);
            TPdfBaseRecord.WriteLine(DataStream, (EndStream - StartStream).ToString(CultureInfo.InvariantCulture));
            TIndirectRecord.SaveTrailer(DataStream);
        }
Exemplo n.º 2
0
 public void Select(TPdfStream DataStream)
 {
     TPdfBaseRecord.WriteLine(DataStream,
                              TPdfTokens.GetString(TPdfToken.PatternName) + " " + TPdfTokens.GetString(TPdfToken.Commandcs) + " " +
                              TPdfTokens.GetString(TPdfToken.GradientPrefix) + PatternId.ToString(CultureInfo.InvariantCulture) + " " +
                              TPdfTokens.GetString(TPdfToken.Commandscn));
 }
Exemplo n.º 3
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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 5
0
 private static void WriteSimpleString(TPdfStream DataStream, string Text, TPdfFont aFont, string EndNewText)
 {
     if (Text == null || Text.Length == 0)
     {
         return;
     }
     Write(DataStream, TPdfTokens.GetString(TPdfToken.OpenString));
     UnicodeWrite(DataStream, Text, aFont);
     Write(DataStream, TPdfTokens.GetString(TPdfToken.CloseString));
     TPdfBaseRecord.WriteLine(DataStream, EndNewText);
 }
Exemplo n.º 6
0
        private void WriteToUnicodeData(TPdfStream DataStream)
        {
            string s = TPdfTokens.GetString(TPdfToken.ToUnicodeData).Replace("\r", "");

            TPdfBaseRecord.WriteLine(DataStream, s);

            TPdfBaseRecord.WriteLine(DataStream, ToUnicodeData.GetData());

            s = TPdfTokens.GetString(TPdfToken.ToUnicodeData2).Replace("\r", "");
            TPdfBaseRecord.WriteLine(DataStream, s);
        }
Exemplo n.º 7
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);
 }
Exemplo n.º 8
0
        internal void FinishPage(TPdfStream DataStream, TXRefSection XRef)
        {
            DataStream.FlushEndText();
            DataStream.Compress = false;
            EndStream           = DataStream.Position;
            TStreamRecord.EndSave(DataStream);
            TIndirectRecord.SaveTrailer(DataStream);

            XRef.SetObjectOffset(LengthId, DataStream);
            TIndirectRecord.SaveHeader(DataStream, LengthId);
            TPdfBaseRecord.WriteLine(DataStream, (EndStream - StartStream).ToString(CultureInfo.InvariantCulture));
            TIndirectRecord.SaveTrailer(DataStream);
        }
Exemplo n.º 9
0
        public void Select(TPdfStream DataStream, real FontSize, ref string LastFont)
        {
            UsedInDoc = true;
            string NewFont = TPdfTokens.GetString(TPdfToken.FontPrefix) + Id.ToString(CultureInfo.InvariantCulture) + " " +
                             PdfConv.CoordsToString(FontSize) + " " + TPdfTokens.GetString(TPdfToken.CommandFont);

            if (LastFont == NewFont)
            {
                return;
            }
            LastFont = NewFont;
            TPdfBaseRecord.WriteLine(DataStream, NewFont);
        }
Exemplo n.º 10
0
        internal static void SaveToStream(TPdfStream DataStream)
        {
            if (DataStream.HasSignature)              //Our sign algorithm requires Reader 7 or newer.
            {
                TPdfHeaderRecord.SaveToStream(DataStream, TPdfTokens.GetString(TPdfToken.Header16));
            }
            else
            {
                TPdfHeaderRecord.SaveToStream(DataStream, TPdfTokens.GetString(TPdfToken.Header14));
            }

            TPdfBaseRecord.WriteLine(DataStream, TPdfTokens.GetString(TPdfToken.HeaderComment));
        }
Exemplo n.º 11
0
        private void SaveWidths(TPdfStream DataStream)
        {
            //Docs say it is prefered to save as indirect object, but acrobat writes it directly.
            //Widths object.
            TPdfBaseRecord.WriteLine(DataStream, TPdfTokens.GetString(TPdfToken.WidthsName) + " " + TPdfTokens.GetString(TPdfToken.OpenArray));
            int fc = FirstChar; if (fc < 0)

            {
                fc = 0;
            }

            for (int i = fc; i <= LastChar; i++)         //characters on winansi are NOT the same as in low byte unicode.  For example char 0x92 (146) is a typographic ' in winansi, not defined in unicode.
            {
                int z = (int)CharUtils.GetUniFromWin1252_PDF((byte)i);
                TPdfBaseRecord.WriteLine(DataStream, PdfConv.CoordsToString(Math.Round(FTrueTypeData.GlyphWidth(FTrueTypeData.Glyph(z, false)))));                 //don't log the erorr here, character doesn't need to exist.
            }

            TPdfBaseRecord.WriteLine(DataStream, TPdfTokens.GetString(TPdfToken.CloseArray));
        }
Exemplo n.º 12
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);
        }
Exemplo n.º 13
0
        internal void SaveToStream(TPdfStream DataStream)
        {
            FStartPosition = DataStream.Position;
            string Generation = " 00000 n ";

            TPdfBaseRecord.WriteLine(DataStream, TPdfTokens.GetString(TPdfToken.XRef));
            TPdfBaseRecord.WriteLine(DataStream, "0 " + (FList.Count + 1).ToString(CultureInfo.InvariantCulture));
            int aCount = FList.Count;

            TPdfBaseRecord.WriteLine(DataStream, "0000000000 65535 f ");

            for (int i = 0; i < aCount; i++)
            {
                TPdfBaseRecord.WriteLine(DataStream, (
#if (!FRAMEWORK20)
                                             (long)
#endif
                                             FList[i]).ToString("0000000000", CultureInfo.InvariantCulture) +
                                         Generation);
            }
        }
Exemplo n.º 14
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);
        }
Exemplo n.º 15
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));
        }
Exemplo n.º 16
0
        internal void WriteFont(TPdfStream DataStream, TXRefSection XRef, bool Compress)
        {
            if (AlreadySaved || ObjectId == -1)
            {
                return;
            }
            AlreadySaved = true;
            int EmbeddedLenId = XRef.GetNewObject(DataStream);             //Stream Length

            XRef.SetObjectOffset(ObjectId, DataStream);
            TIndirectRecord.SaveHeader(DataStream, ObjectId);

            byte[] FontData = TrueTypeData.SubsetFontData(SubsetCMap);

            TStreamRecord.BeginSave(DataStream, EmbeddedLenId, Compress, FontData.Length);
            long StartStream = DataStream.Position;
            bool Compressing = DataStream.Compress;

            try
            {
                DataStream.Compress = Compress;
                DataStream.Write(FontData);
            }
            finally
            {
                DataStream.Compress = Compressing;
            }
            long EndStream = DataStream.Position;

            TStreamRecord.EndSave(DataStream);
            TIndirectRecord.SaveTrailer(DataStream);

            XRef.SetObjectOffset(EmbeddedLenId, DataStream);
            TIndirectRecord.SaveHeader(DataStream, EmbeddedLenId);
            TPdfBaseRecord.WriteLine(DataStream, (EndStream - StartStream).ToString(CultureInfo.InvariantCulture));
            TIndirectRecord.SaveTrailer(DataStream);
        }
Exemplo n.º 17
0
 public void Select(TPdfStream DataStream, Color PatternColor)
 {
     TPdfBaseRecord.WriteLine(DataStream, GetColorString(PatternColor) + " " +
                              TPdfTokens.GetString(TPdfToken.PatternPrefix) + PatternId.ToString(CultureInfo.InvariantCulture) + " " +
                              TPdfTokens.GetString(TPdfToken.Commandscn));
 }
Exemplo n.º 18
0
 public void Select(TPdfStream DataStream)
 {
     TPdfBaseRecord.WriteLine(DataStream, TPdfTokens.GetString(TPdfToken.ImgPrefix) + Id.ToString(CultureInfo.InvariantCulture) + " " +
                              TPdfTokens.GetString(TPdfToken.CommandDo));
 }
Exemplo n.º 19
0
 public void Select(TPdfStream DataStream)
 {
     TPdfBaseRecord.WriteLine(DataStream,
                              GStateName + " " +
                              TPdfTokens.GetString(TPdfToken.Commandgs));
 }