2 Copyright (C) 2015 Carl Hetherington <cth@carlh.net>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #include "font_files_dialog.h"
21 #include "system_font_dialog.h"
25 FontFilesDialog::FontFilesDialog (wxWindow* parent, FontFiles files)
26 #ifdef DCPOMATIC_WINDOWS
27 : TableDialog (parent, _("Fonts"), 4, 1, true)
29 : TableDialog (parent, _("Fonts"), 3, 1, true)
39 DCPOMATIC_ASSERT (FontFiles::VARIANTS == 3);
41 for (int i = 0; i < FontFiles::VARIANTS; ++i) {
42 add (labels[i], true);
43 _name[i] = new wxStaticText (
45 std_to_wx(_files.get(static_cast<FontFiles::Variant>(i)).get_value_or("").string()),
49 _table->Add (_name[i], 1, wxEXPAND | wxALIGN_CENTER_VERTICAL | wxALL, 6);
50 add (_set_file[i] = new wxButton (this, wxID_ANY, _("Set from file...")));
51 _set_file[i]->Bind (wxEVT_COMMAND_BUTTON_CLICKED, bind (&FontFilesDialog::set_from_file_clicked, this, static_cast<FontFiles::Variant>(i)));
52 #ifdef DCPOMATIC_WINDOWS
53 add (_set_system[i] = new wxButton (this, wxID_ANY, _("Set from system font...")));
54 _set_system[i]->Bind (wxEVT_COMMAND_BUTTON_CLICKED, bind (&FontFilesDialog::set_from_system_clicked, this, static_cast<FontFiles::Variant>(i)));
62 FontFilesDialog::set_from_file_clicked (FontFiles::Variant variant)
64 /* The wxFD_CHANGE_DIR here prevents a `could not set working directory' error 123 on Windows when using
65 non-Latin filenames or paths.
67 wxString default_dir = "";
68 #ifdef DCPOMATIC_LINUX
69 if (boost::filesystem::exists ("/usr/share/fonts/truetype")) {
70 default_dir = "/usr/share/fonts/truetype";
72 default_dir = "/usr/share/fonts";
76 default_dir = "/System/Library/Fonts";
79 wxFileDialog* d = new wxFileDialog (this, _("Choose a font file"), default_dir, wxT (""), wxT ("*.ttf"), wxFD_CHANGE_DIR);
80 int const r = d->ShowModal ();
87 set (variant, wx_to_std (d->GetPath ()));
91 #ifdef DCPOMATIC_WINDOWS
93 FontFilesDialog::set_from_system_clicked (FontFiles::Variant variant)
95 SystemFontDialog* d = new SystemFontDialog (this);
96 int const r = d->ShowModal ();
103 set (variant, d->get_font().get());
109 FontFilesDialog::set (FontFiles::Variant variant, boost::filesystem::path path)
111 _files.set (variant, path);
112 _name[variant]->SetLabel (std_to_wx (path.leaf().string()));