protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (_tokenizer != null)
                {
                    _tokenizer.Dispose();
                    _tokenizer = null;
                }
            }

            base.Dispose(disposing);
        }
Exemplo n.º 2
0
        public override void Open(string filePath)
        {
            _content = File.ReadAllText(filePath);

            int i = _content.IndexOf("%!");

            if (i > 0)
            {
                _content = _content.Substring(i, _content.Length - i - 1);
            }

            i = _content.IndexOf("%%EOF");

            if (i > -1)
            {
                _content = _content.Substring(0, i + 5);
            }

            if (this.Viewer.EPSClip)
            {
                unsafe
                {
                    fixed(char *p = _content)
                    {
                        UnmanagedMemoryStream ums       = new UnmanagedMemoryStream((byte *)p, _content.Length);
                        DSCTokenizer          tokenizer = new DSCTokenizer(ums, true, BitConverter.IsLittleEndian);

                        DSCToken token = null;

                        while ((token = tokenizer.GetNextDSCKeywordToken()) != null)
                        {
                            if (token.Text == "%%BoundingBox:")
                            {
                                try
                                {
                                    DSCToken v1 = tokenizer.GetNextDSCValueToken(DSCTokenEnding.Whitespace | DSCTokenEnding.LineEnd);
                                    DSCToken v2 = tokenizer.GetNextDSCValueToken(DSCTokenEnding.Whitespace | DSCTokenEnding.LineEnd);
                                    DSCToken v3 = tokenizer.GetNextDSCValueToken(DSCTokenEnding.Whitespace | DSCTokenEnding.LineEnd);
                                    DSCToken v4 = tokenizer.GetNextDSCValueToken(DSCTokenEnding.Whitespace | DSCTokenEnding.LineEnd);

                                    this.BoundingBox = new GhostscriptRectangle(
                                        float.Parse(v1.Text, System.Globalization.CultureInfo.InvariantCulture),
                                        float.Parse(v2.Text, System.Globalization.CultureInfo.InvariantCulture),
                                        float.Parse(v3.Text, System.Globalization.CultureInfo.InvariantCulture),
                                        float.Parse(v4.Text, System.Globalization.CultureInfo.InvariantCulture));
                                }
                                catch { }

                                break;
                            }
                        }

                        tokenizer.Dispose(); tokenizer  = null;
                        ums.Close(); ums.Dispose(); ums = null;
                    }
                }
            }

            this.FirstPageNumber = 1;
            this.LastPageNumber  = 1;
        }