Пример #1
0
        /* ----------------------------------------------------------------- */
        ///
        /// OutputPathButton_Click
        ///
        /// <summary>
        /// 出力先ファイルのボタンが押下された時に実行されるイベントハンドラ
        /// です。ファイル保存ダイアログを表示します。
        /// </summary>
        ///
        /* ----------------------------------------------------------------- */
        private void OutputPathButton_Click(object sender, EventArgs e)
        {
            SaveFileDialog dialog = new SaveFileDialog();

            dialog.AddExtension = true;
            dialog.FileName     = (this.OutputPathTextBox.TextLength > 0) ?
                                  Path.GetFileNameWithoutExtension(this.OutputPathTextBox.Text) :
                                  Path.GetFileNameWithoutExtension(this.InputPathTextBox.Text);
            dialog.Filter          = Appearance.FileFilterString();
            dialog.FilterIndex     = this.FileTypeCombBox.SelectedIndex + 1;
            dialog.OverwritePrompt = false;
            if (dialog.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            if (dialog.FilterIndex != 0 && dialog.FilterIndex - 1 != this.FileTypeCombBox.SelectedIndex)
            {
                this.FileTypeCombBox.SelectedIndex = dialog.FilterIndex - 1;
            }

            // 拡張子が選択されているファイルタイプと異なる場合は、末尾に拡張子を追加する。
            // ただし、入力された拡張子がユーザのコンピュータに登録されている場合は、それを優先する。
            string ext      = Path.GetExtension(this.OutputPathTextBox.Text);
            string compared = Parameter.Extension(Translator.IndexToFileType(this.FileTypeCombBox.SelectedIndex));

            this.OutputPathTextBox.Text = dialog.FileName;
            if (ext != compared && !CubePdf.Utility.IsAssociate(ext))
            {
                this.OutputPathTextBox.Text += compared;
            }
            this.SettingChanged(sender, e);
        }
Пример #2
0
        /* ----------------------------------------------------------------- */
        ///
        /// ExecConvert
        ///
        /// <summary>
        /// Examples フォルダに存在する *.ps ファイルに対して Converter.Run
        /// メソッドを実行し、生成されたファイルを Results フォルダに保存
        /// します。
        /// </summary>
        ///
        /* ----------------------------------------------------------------- */
        private void ExecConvert(UserSetting setting, string suffix)
        {
            string output = System.IO.Path.Combine(Environment.CurrentDirectory, "Results");

            if (!System.IO.Directory.Exists(output))
            {
                System.IO.Directory.CreateDirectory(output);
            }

            foreach (string file in Directory.GetFiles("Examples", "*.ps"))
            {
                string filename  = Path.GetFileNameWithoutExtension(file);
                string extension = Parameter.Extension((Parameter.FileTypes)setting.FileType);

                setting.InputPath  = Path.GetFullPath(file);
                setting.OutputPath = output + '\\' + filename + suffix + extension;
                if (File.Exists(setting.OutputPath) && setting.ExistedFile == Parameter.ExistedFiles.Overwrite)
                {
                    File.Delete(setting.OutputPath);
                }

                var converter = new Converter();
                Assert.IsTrue(converter.Run(setting), String.Format("Converter.Run() failed. source file: {0}", file));
                bool status = File.Exists(setting.OutputPath);
                if (status)
                {
                    if (setting.FileType == Parameter.FileTypes.PDF)
                    {
                        ValidatePdf(setting);
                    }
                }
                else
                {
                    string tmp = String.Format("{0}\\{1}-001{2}",
                                               Path.GetDirectoryName(setting.OutputPath),
                                               Path.GetFileNameWithoutExtension(setting.OutputPath),
                                               Path.GetExtension(setting.OutputPath)
                                               );

                    status = File.Exists(tmp);
                    Assert.IsTrue(status, String.Format("{0}: file not found", setting.OutputPath));
                }
            }
        }
Пример #3
0
        /* ----------------------------------------------------------------- */
        ///
        /// SetupUserSetting
        ///
        /// <summary>
        /// プログラムに指定された引数等を用いて、UserSetting オブジェクトを
        /// 初期化します。
        /// </summary>
        ///
        /* ----------------------------------------------------------------- */
        private static void SetupUserSetting(UserSetting setting, string[] args)
        {
            var cmdline = new CubePdf.Settings.CommandLine(args);

            var  docname   = cmdline.Options.ContainsKey("DocumentName") ? cmdline.Options["DocumentName"] : "";
            bool is_config = false;

            try
            {
                if (docname.Length > 0 && Path.GetExtension(docname) == setting.Extension && File.Exists(docname))
                {
                    is_config = true;
                }
            }
            catch (Exception err)
            {
                // docname に Windows のファイル名に使用できない記号が含まれる
                // 場合に例外が送出されるので、その対策。
                Trace.TraceError(err.ToString());
                is_config = false;
            }

            if (is_config)
            {
                setting.Load(docname);
            }
            else
            {
                setting.Load();
                var filename = DocumentName.CreateFileName(docname);
                if (filename != null)
                {
                    string ext = Parameter.Extension((Parameter.FileTypes)setting.FileType);
                    filename = Path.ChangeExtension(filename, ext);
                    string dir = (setting.OutputPath.Length == 0 || Directory.Exists(setting.OutputPath)) ?
                                 setting.OutputPath : Path.GetDirectoryName(setting.OutputPath);
                    setting.OutputPath = dir + '\\' + filename;
                }
            }

            setting.InputPath     = cmdline.Options.ContainsKey("InputFile") ? cmdline.Options["InputFile"] : "";
            setting.DeleteOnClose = cmdline.Options.ContainsKey("DeleteOnClose");
        }
Пример #4
0
        /* ----------------------------------------------------------------- */
        ///
        /// CheckOutput
        ///
        /// <summary>
        /// 出力先パスが正しいかどうかをチェックします。出力先パスが指定
        /// されていない場合はエラーメッセージを表示します。また、指定された
        /// 出力先パスが既に存在する場合には確認ダイアログを表示します。
        /// </summary>
        ///
        /* ----------------------------------------------------------------- */
        private bool CheckOutput(int do_existed_file)
        {
            if (this.OutputPathTextBox.Text.Length == 0)
            {
                MessageBox.Show(
                    Properties.Resources.FileNotSpecified,
                    Properties.Resources.Error,
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error
                    );
                return(false);
            }
            else
            {
                string ext      = Path.GetExtension(this.OutputPathTextBox.Text);
                string compared = Parameter.Extension(Translator.IndexToFileType(this.FileTypeCombBox.SelectedIndex));
                if (ext != compared && !CubePdf.Utility.IsAssociate(ext))
                {
                    this.OutputPathTextBox.Text += compared;
                }

                if (File.Exists(this.OutputPathTextBox.Text) && Translator.IndexToExistedFile(this.ExistedFileComboBox.SelectedIndex) != Parameter.ExistedFiles.Rename)
                {
                    // {0} は既に存在します。{1}しますか?
                    string message = String.Format(Properties.Resources.FileExists,
                                                   this.OutputPathTextBox.Text, Appearance.ExistedFileString((Parameter.ExistedFiles)do_existed_file));
                    if (MessageBox.Show(
                            message,
                            Properties.Resources.OverwritePrompt,
                            MessageBoxButtons.OKCancel,
                            MessageBoxIcon.Warning) == DialogResult.Cancel)
                    {
                        return(false);
                    }
                }
            }
            return(true);
        }
Пример #5
0
        /* ----------------------------------------------------------------- */
        ///
        /// IsExecutable
        ///
        /// <summary>
        /// ポストプロセスが実行可能かどうかをチェックすします。
        /// </summary>
        ///
        /// <remarks>
        /// 判別方法は、以下の通りです。
        ///
        /// 1. Open が指定された場合は関連付けられているかどうか。
        /// 2. UserProgram が指定された場合は指定されたプログラムが存在して
        ///    いるかどうか。
        /// </remarks>
        ///
        /* ----------------------------------------------------------------- */
        private bool IsExecutable(UserSetting setting)
        {
            if (setting.PostProcess == Parameter.PostProcesses.Open)
            {
                string ext = Parameter.Extension(setting.FileType);
                if (!CubePdf.Utility.IsAssociate(ext))
                {
                    // NOTE: 関連付けされていない場合は、単純にスキップする(エラーメッセージを表示しない)。
                    _messages.Add(new Message(Message.Levels.Debug, String.Format(Properties.Resources.FileNotRelated, ext)));
                    return(false);
                }
            }
            else if (setting.PostProcess == Parameter.PostProcesses.UserProgram && setting.UserProgram.Length > 0)
            {
                if (!File.Exists(setting.UserProgram))
                {
                    _messages.Add(new Message(Message.Levels.Error, String.Format(Properties.Resources.ProgramNotFound, setting.UserProgram)));
                    return(false);
                }
            }

            return(true);
        }
Пример #6
0
        /* ----------------------------------------------------------------- */
        ///
        /// FileTypeCombBox_SelectedIndexChanged
        ///
        /// <summary>
        /// ファイルの種類が変更された時に実行されるイベントハンドラです。
        /// 変換するファイルの種類によって無効なオプションがあるため、
        /// 有効/無効を切り替えます。
        /// </summary>
        ///
        /// <remarks>
        /// ファイルタイプに依存するオプションは以下の通りです。
        ///
        /// PDF, PS, EPS, SVG: フォントの埋め込み
        /// PDF: バージョン、 文書プロパティ、セキュリティ、Web 最適化
        /// BMP, JPEG, PNG: 解像度
        ///
        /// 尚、Ghostscript のバグで現在のところ PS, EPS, SVG は
        /// グレースケール設定ができないようです。また,フォント埋め込みを
        /// 無効にすると文字化けが発生するので、暫定的に強制無効設定にして
        /// います。
        /// </remarks>
        ///
        /* ----------------------------------------------------------------- */
        private void FileTypeCombBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            ComboBox control = sender as ComboBox;

            if (control == null)
            {
                return;
            }

            Parameter.FileTypes id = Translator.IndexToFileType(control.SelectedIndex);
            bool is_pdf            = (id == Parameter.FileTypes.PDF);
            bool is_bitmap         = (id == Parameter.FileTypes.BMP || id == Parameter.FileTypes.JPEG || id == Parameter.FileTypes.PNG || id == Parameter.FileTypes.TIFF);
            bool is_grayscale      = !(id == Parameter.FileTypes.PS || id == Parameter.FileTypes.EPS || id == Parameter.FileTypes.SVG);
            bool is_webopt         = this.WebOptimizeCheckBox.Checked;
            bool is_security       = (this.RequiredUserPasswordCheckBox.Checked || this.OwnerPasswordCheckBox.Checked);

            this.PDFVersionComboBox.Enabled  = is_pdf;
            this.ResolutionComboBox.Enabled  = is_bitmap;
            this.DocPanel.Enabled            = is_pdf;
            this.SecurityGroupBox.Enabled    = is_pdf && !is_webopt;
            this.EmbedFontCheckBox.Enabled   = false; //!is_bitmap;
            this.GrayscaleCheckBox.Enabled   = is_grayscale;
            this.ImageFilterCheckBox.Enabled = !is_bitmap;
            this.WebOptimizeCheckBox.Enabled = is_pdf && !is_security;

            // 出力パスの拡張子を変更後のファイルタイプに合わせる.
            if (this.OutputPathTextBox.Text.Length > 0)
            {
                this.OutputPathTextBox.Text = Path.ChangeExtension(this.OutputPathTextBox.Text, Parameter.Extension(id));
            }
            this.SettingChanged(sender, e);
        }