Skip to content

Add helper to load font #448

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 9, 2021
Merged

Conversation

promag
Copy link
Contributor

@promag promag commented Oct 7, 2021

Originally submitted as bitcoin-core/gui-qml#49.

@promag promag changed the title qt: Add helper to load font Add helper to load font Oct 7, 2021
@hebasto
Copy link
Member

hebasto commented Oct 7, 2021

Concept ACK.

Copy link
Member

@hebasto hebasto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approach ACK 44f948f.

@@ -272,6 +272,12 @@ bool hasEntryData(const QAbstractItemView *view, int column, int role)
return !selection.at(0).data(role).toString().isEmpty();
}

void loadFont(const QString& file_name)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not return id for generality?

From Qt docs:

An ID is returned that can be used to remove the font again with removeApplicationFont() or to retrieve the list of family names contained in the font.

Copy link
Contributor Author

@promag promag Oct 7, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The helper is meant for our use case: load font; ensure it is valid; remains loaded while the application runs.

Happy to add the return value, but at the moment it is discarded at the call site.

Copy link
Contributor

@shaavan shaavan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Concept ACK

This PR introduces a new loadFont function, which along with adding the font, also asserts that it has been properly added to the QFontDatabase. I agree with the changes in the PR because this function eliminates any chance of font not being correctly added to the Application.

@promag promag force-pushed the 2021-10-font-helper branch from 44f948f to 98f423d Compare October 7, 2021 15:29
Copy link
Member

@hebasto hebasto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK 98f423d, tested on Linux Mint 20.2 (Qt 5.12.8).

@promag promag force-pushed the 2021-10-font-helper branch from 98f423d to d54ec27 Compare October 7, 2021 16:03
Copy link
Member

@hebasto hebasto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

re-ACK d54ec27

Copy link
Contributor

@stratospher stratospher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested ACK d54ec27. Refactoring the code and defining loadFont() in src/qt/guiutil.cpp reduces redundant imports of the QFontDatabase and is a better design.

Fonts in the application remain consistent in both the PR and master.

Master PR
Screenshot 2021-10-07 at 4 38 43 PM Screenshot 2021-10-07 at 4 39 15 PM

Copy link
Contributor

@shaavan shaavan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK d54ec27

Changes since my last review:

  • The added function has been renamed from loadFont -> LoadFont according to the name convention
  • QStringLiteral macro is now used to ensure the input string is allocated statically.
  • const keyword is used for the id variable to indicate that it is not modified.
  • The fileName has been corrected to file_name in the comment.

@hebasto hebasto merged commit 15587b4 into bitcoin-core:master Oct 9, 2021
@promag promag deleted the 2021-10-font-helper branch October 9, 2021 10:44
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Oct 9, 2021
@luke-jr
Copy link
Member

luke-jr commented Oct 11, 2021

Why do we want to abort if it fails??

@bitcoin-core bitcoin-core locked as resolved and limited conversation to collaborators Oct 11, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants