[PATCH] GetBoldFont/GetTitleFont try/catch
Moderator: Committer
[PATCH] GetBoldFont/GetTitleFont try/catch
I release my submissions under the GPL 2.0 license.
From the programming work wiki misc:
Modify ClientUI::GetFont and related title / bold font functions to check the validity of the font they attempt to get, and to try again to get the default font if the first attempt fails. The GG::GUI::GetFont function thows a GG::Font::BadFile exception when there is a problem getting a font for the first time. The call in ClientUI::GetFont could be put in a try-catch block for this exception, and if it is caught, another call to GetFont could be done using the default value of the "UI.font" option.
GetFont() was already set up to catch the GG::Font:BadFile exception with a try catch. I did the same for GetBoldFont() and GetTitleFont().
From the programming work wiki misc:
Modify ClientUI::GetFont and related title / bold font functions to check the validity of the font they attempt to get, and to try again to get the default font if the first attempt fails. The GG::GUI::GetFont function thows a GG::Font::BadFile exception when there is a problem getting a font for the first time. The call in ClientUI::GetFont could be put in a try-catch block for this exception, and if it is caught, another call to GetFont could be done using the default value of the "UI.font" option.
GetFont() was already set up to catch the GG::Font:BadFile exception with a try catch. I did the same for GetBoldFont() and GetTitleFont().
- Attachments
-
[The extension patch has been deactivated and can no longer be displayed.]
- Geoff the Medio
- Programming, Design, Admin
- Posts: 13603
- Joined: Wed Oct 08, 2003 1:33 am
- Location: Munich
Re: [PATCH] GetBoldFont/GetTitleFont try/catch
Please use four spaces instead of tabs. There should be an option in your text editor to do this.
There are various calls directly to ClientUI::Font that will bypass this change. It would probably be worth replacing those with calls to ClientUI::GetFont when possible. For example, in MultiplayerLobbyWnd.cpp, TypeSelector::TypeRow::TypeRow makes calls to ListBox::Row::push_back by passing a font filename, but there is an overload that takes a pointer to a GG::Font that could be used instead.
There are various calls directly to ClientUI::Font that will bypass this change. It would probably be worth replacing those with calls to ClientUI::GetFont when possible. For example, in MultiplayerLobbyWnd.cpp, TypeSelector::TypeRow::TypeRow makes calls to ListBox::Row::push_back by passing a font filename, but there is an overload that takes a pointer to a GG::Font that could be used instead.
Re: [PATCH] GetBoldFont/GetTitleFont try/catch
One other thing. There is a copy of DejaVuSans.ttf now baked into libGiGi. You can access it by calling GG::GUI::GetGUI()->GetStyleFactory()->DefaultFont() (or similar, I din't try compiling that). This should probably be a last-chance fallback.
Re: [PATCH] GetBoldFont/GetTitleFont try/catch
Geoff the Medio wrote:Please use four spaces instead of tabs. There should be an option in your text editor to do this.
There are various calls directly to ClientUI::Font that will bypass this change. It would probably be worth replacing those with calls to ClientUI::GetFont when possible. For example, in MultiplayerLobbyWnd.cpp, TypeSelector::TypeRow::TypeRow makes calls to ListBox::Row::push_back by passing a font filename, but there is an overload that takes a pointer to a GG::Font that could be used instead.
Okay I made the change in visual studio so I believe tabs should now be 4 spaces. If i didn't do it correctly or something just let me know.
So I changed tabs to spaces and updated MultiplayerLobbyWnd.cpp to use GetFont() instead of direct calls to Font().
Edit: Whoops just saw Tzlaine's post so I will look at that then repost another patch.
- Attachments
-
[The extension patch has been deactivated and can no longer be displayed.]
Re: [PATCH] GetBoldFont/GetTitleFont try/catch
Is this what you were looking for tzlaine? If theres anything else that I am missing or should add just let me know.tzlaine wrote:One other thing. There is a copy of DejaVuSans.ttf now baked into libGiGi. You can access it by calling GG::GUI::GetGUI()->GetStyleFactory()->DefaultFont() (or similar, I din't try compiling that). This should probably be a last-chance fallback.
- Attachments
-
[The extension patch has been deactivated and can no longer be displayed.]
- Geoff the Medio
- Programming, Design, Admin
- Posts: 13603
- Joined: Wed Oct 08, 2003 1:33 am
- Location: Munich
Re: [PATCH] GetBoldFont/GetTitleFont try/catch
You added a line to ClientUI::GetFont at the end that returns the GiGi default font, but how can this ever be reached? If there's no exception thrown, the first return will be used, and if there is a BadFile exception, the second will be used from in the catch block. If there's another exception, it will not be caught, but the return line you added still won't be reached.fixIt wrote:If theres anything else that I am missing or should add just let me know.
Re: [PATCH] GetBoldFont/GetTitleFont try/catch
Ah okay I wasn't totally sure on that thanks for clarifying. So this is because if a exception is thrown and its not badfile it won't go to that line it will look higher up for something to catch it? So your saying that return line I added should be in a catch(...) statement then right?Geoff the Medio wrote:You added a line to ClientUI::GetFont at the end that returns the GiGi default font, but how can this ever be reached? If there's no exception thrown, the first return will be used, and if there is a BadFile exception, the second will be used from in the catch block. If there's another exception, it will not be caught, but the return line you added still won't be reached.fixIt wrote:If theres anything else that I am missing or should add just let me know.
- Geoff the Medio
- Programming, Design, Admin
- Posts: 13603
- Joined: Wed Oct 08, 2003 1:33 am
- Location: Munich
Re: [PATCH] GetBoldFont/GetTitleFont try/catch
I think the main concern is handling the case when the font filename returned by GetOptionsDB().GetDefault<std::string>("UI.font") is also not a valid font file. This would occur if there is no font file in the set default directory, or the font file is corrupted. catch(...) around the extra return line won't deal with that.
Re: [PATCH] GetBoldFont/GetTitleFont try/catch
GetFont() and GetTitleFont() now work when the font file is missing from the default folder. GetBoldFont() now works when the bold font file is missing from the default folder, in the case that the bold font is missing it returns the default font instead.
- Attachments
-
[The extension patch has been deactivated and can no longer be displayed.]