[PATCH] GetBoldFont/GetTitleFont try/catch

Programmers discuss here anything related to FreeOrion programming. Primarily for the developers to discuss.

Moderator: Committer

Post Reply
Message
Author
fixIt
Space Floater
Posts: 27
Joined: Thu Oct 20, 2011 10:14 pm

[PATCH] GetBoldFont/GetTitleFont try/catch

#1 Post by fixIt »

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().
Attachments

[The extension patch has been deactivated and can no longer be displayed.]


User avatar
Geoff the Medio
Programming, Design, Admin
Posts: 13587
Joined: Wed Oct 08, 2003 1:33 am
Location: Munich

Re: [PATCH] GetBoldFont/GetTitleFont try/catch

#2 Post by Geoff the Medio »

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.

tzlaine
Programming Lead Emeritus
Posts: 1092
Joined: Thu Jun 26, 2003 1:33 pm

Re: [PATCH] GetBoldFont/GetTitleFont try/catch

#3 Post by tzlaine »

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.

fixIt
Space Floater
Posts: 27
Joined: Thu Oct 20, 2011 10:14 pm

Re: [PATCH] GetBoldFont/GetTitleFont try/catch

#4 Post by fixIt »

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.]


fixIt
Space Floater
Posts: 27
Joined: Thu Oct 20, 2011 10:14 pm

Re: [PATCH] GetBoldFont/GetTitleFont try/catch

#5 Post by fixIt »

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.
Is this what you were looking for tzlaine? If theres anything else that I am missing or should add just let me know.
Attachments

[The extension patch has been deactivated and can no longer be displayed.]


User avatar
Geoff the Medio
Programming, Design, Admin
Posts: 13587
Joined: Wed Oct 08, 2003 1:33 am
Location: Munich

Re: [PATCH] GetBoldFont/GetTitleFont try/catch

#6 Post by Geoff the Medio »

fixIt wrote:If theres anything else that I am missing or should add just let me know.
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
Space Floater
Posts: 27
Joined: Thu Oct 20, 2011 10:14 pm

Re: [PATCH] GetBoldFont/GetTitleFont try/catch

#7 Post by fixIt »

Geoff the Medio wrote:
fixIt wrote:If theres anything else that I am missing or should add just let me know.
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.
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?

User avatar
Geoff the Medio
Programming, Design, Admin
Posts: 13587
Joined: Wed Oct 08, 2003 1:33 am
Location: Munich

Re: [PATCH] GetBoldFont/GetTitleFont try/catch

#8 Post by Geoff the Medio »

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.

fixIt
Space Floater
Posts: 27
Joined: Thu Oct 20, 2011 10:14 pm

Re: [PATCH] GetBoldFont/GetTitleFont try/catch

#9 Post by fixIt »

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.]


Post Reply