Devices 型から GhostScript のデバイス名を取得するための拡張メソッド 用クラスです。
コード例 #1
0
        /* ----------------------------------------------------------------- */
        ///
        /// MakeArgs
        ///
        /// <remarks>
        /// Note that the arguments are the same as the "C" main function:
        /// argv[0] is ignored and the user supplied arguments are argv[1]
        /// to argv[argc-1].
        /// http://pages.cs.wisc.edu/~ghost/doc/AFPL/8.00/API.htm
        /// </remarks>
        ///
        /* ----------------------------------------------------------------- */
        private string[] MakeArgs(string[] sources, string dest)
        {
            List <string> args = new List <string>();

            // Add device
            args.Add("dummy"); // args[0] is ignored.
            if (this._device != Devices.Unknown && this._device != Devices.PDF_Opt)
            {
                args.Add(DeviceExt.Argument(this._device));
            }

            // Add include paths
            if (_includes.Count > 0)
            {
                args.Add("-I" + CombinePath(this._includes));
            }

            // Add font paths
            // Note: C:\Windows\Fonts ディレクトリを常に含めるかどうか.
            var win = System.Environment.GetEnvironmentVariable("windir") + @"\Fonts";

            if (!_fonts.Contains(win))
            {
                _fonts.Add(win);
            }
            args.Add("-sFONTPATH=" + CombinePath(this._fonts));

            // Add resolution
            args.Add("-r" + this._resolution.ToString());

            // Add page settings
            if (this._paper != Papers.Unknown)
            {
                args.Add(PaperExt.Argument(this._paper));
            }
            else if (this._device == Devices.PDF)
            {
                args.Add("-dPDFFitPage");
            }
            if (this._first > 1 || this._first < this._last)
            {
                args.Add("-dFirstPage=" + this._first.ToString());
                if (this._first < this._last)
                {
                    args.Add("-dLastPage=" + this._last.ToString());
                }
            }
            if (this._rotate)
            {
                args.Add("-dAutoRotatePages=/PageByPage");
            }

            // Add default options
            foreach (string elem in defaults_)
            {
                args.Add(elem);
            }

            // Add user options
            foreach (var elem in this._options)
            {
                string ext = skeys_.Contains(elem.Key) ? "-s" : "-d";
                string tmp = (elem.Value == null) ?
                             ext + elem.Key :
                             ext + elem.Key + "=" + elem.Value;
                args.Add(tmp);
            }

            // Add user options (for inherited classes)
            this.ExtraArgs(args);

            //args.Add("-sstdout=ghostscript.log");

            // Add input (source filename) and output (destination filename)
            if (this._device == Devices.PDF_Opt)
            {
                args.Add("--");
                args.Add("pdfopt.ps");
                foreach (var src in sources)
                {
                    args.Add(src);
                }
                args.Add(dest);
            }
            else
            {
                args.Add(String.Format("-sOutputFile={0}", dest));
                foreach (var src in sources)
                {
                    args.Add(src);
                }
            }

            return(args.ToArray());
        }
コード例 #2
0
        /* ----------------------------------------------------------------- */
        ///
        /// MakeArgs
        ///
        /// <summary>
        /// Ghostscript を実行するのに必要な引数を生成します。
        /// </summary>
        ///
        /// <remarks>
        /// Note that the arguments are the same as the "C" main function:
        /// argv[0] is ignored and the user supplied arguments are argv[1]
        /// to argv[argc-1].
        /// http://pages.cs.wisc.edu/~ghost/doc/AFPL/8.00/API.htm
        /// </remarks>
        ///
        /* ----------------------------------------------------------------- */
        private string[] MakeArgs(string[] sources, string dest, string log)
        {
            var args = new List <string>();

            // args[0] is ignored.
            args.Add("dummy");

            // Add logfile
            args.Add(string.Format("-sstdout={0}", log));

            // Add device
            if (_device != Devices.Unknown)
            {
                args.Add(DeviceExt.Argument(_device));
            }

            // Add include paths
            if (_includes.Count > 0)
            {
                args.Add("-I" + string.Join(";", _includes.ToArray()));
            }

            // Add font paths
            var win = IoEx.Path.Combine(Environment.GetEnvironmentVariable("windir"), "Fonts");

            if (!_fonts.Contains(win))
            {
                _fonts.Add(win);
            }
            args.Add("-sFONTPATH=" + string.Join(";", _fonts.ToArray()));

            // Add resolution
            args.Add("-r" + _resolution.ToString());

            // Add page settings
            if (_paper != Papers.Unknown)
            {
                args.Add(PaperExt.Argument(_paper));
            }
            if (_first > 1 || _first < _last)
            {
                args.Add(string.Format("-dFirstPage={0}", _first));
                if (_first < _last)
                {
                    args.Add(string.Format("-dLastPage={0}", _last));
                }
            }
            if (_rotate)
            {
                args.Add("-dAutoRotatePages=/PageByPage");
            }
            else
            {
                args.Add("-dAutoRotatePages=/No");
            }

            // Add default options
            foreach (string option in _DefaultSettings)
            {
                args.Add(option);
            }

            // Add user options
            foreach (var option in _options)
            {
                var flag = _SKeys.Contains(option.Key) ? "-s" : "-d";
                var s    = (option.Value == null) ?
                           flag + option.Key :
                           flag + option.Key + "=" + option.Value;
                args.Add(s);
            }

            // Add output
            args.Add(string.Format("-sOutputFile={0}", dest));

            // Add orientation
            if (!_rotate)
            {
                args.Add("-c");
                args.Add(string.Format("<</Orientation {0}>> setpagedevice", _orientation));
            }

            // Add input (source filename) and output (destination filename)
            args.Add("-f");
            foreach (var src in sources)
            {
                args.Add(src);
            }

            return(args.ToArray());
        }