![]() |
#1 |
Calibre Plugins Developer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 4,721
Karma: 2197770
Join Date: Oct 2010
Location: Australia
Device: Kindle Oasis
|
Working with Fonts and Calibre
I'm working on a "Generate Cover" plugin which allows all sorts of customisation of a cover that gets generated. As part of that I wanted to offer the ability for the user to choose fonts for the rendering using magick of the title, author, series.
The issue is whether it is possible to make use of the QFontDialog as a UI for selecting a font to then pass to the drawing code in the magick namespace. As far as I can tell, the magick stuff takes a physical file path, whereas a QFontDialog gives you a QFont from which you get a font family. Is there any suggested way of reconciling the two? In a cross platform way? I saw some code via Google which queried the registry for font matches but obviously that is a windows only option. Or should I just use a file chooser dialog and get the user to navigate to a .ttf file instead? |
![]() |
![]() |
![]() |
#2 |
Comparer of the Ephemeris
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,496
Karma: 424697
Join Date: Mar 2009
Device: iPad
|
Take a look at gui2.convert.mobi_output.py, I use a combo box there to list available fonts, that might be of some assistance.
G |
![]() |
![]() |
Advert | |
|
![]() |
#3 |
Sigil & calibre developer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 2,487
Karma: 1063785
Join Date: Jan 2009
Location: Florida, USA
Device: Nook STR
|
The font file has to be read at some point to populate the font dialog. I would first look to see if QFont stores the file path. Then I would look at the Qt source to see how it loads the font list. It would have to handle it per platform and might have some cross platform method.
|
![]() |
![]() |
![]() |
#4 |
Calibre Plugins Developer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 4,721
Karma: 2197770
Join Date: Oct 2010
Location: Australia
Device: Kindle Oasis
|
Thanks guys.
@user_none - I found a feature request on the web for QFont to have this info and it was rejected by the devs as not worth the effort. My reading of what is going on is that Qt deals with the font abstractions it is passed by other layered components underneath, so it doesn't actually know the file path. So I think I will abandon QFontDialog - I think if I used the Qt drawing ability it would be useful but I'm trying not to start from scratch on the image stuff. @GRiker - thanks for pointing me at that font combo, I'll try to figure out some sort of UI using similar code. |
![]() |
![]() |
![]() |
#5 |
creator of calibre
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 45,188
Karma: 27110894
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
There's already a tweak to specify the font paths. If you want a UI for the tweak, use the FontFamilyModel from gui2.widgets, see the lrf output or mobi output plugins for an example.
Qt doesn't make paths to fonts available, because of DRM (windows tries to prevent programs from accessing font data unless they have the embed bit set). |
![]() |
![]() |
Advert | |
|
![]() |
#6 |
Calibre Plugins Developer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 4,721
Karma: 2197770
Join Date: Oct 2010
Location: Australia
Device: Kindle Oasis
|
Thx Kovid, yeah I have seen the tweaks for covers. Originally I wasn't going to bother with offering font choices at all since they existed. However I wanted both more granularity and also to not force users to have to go through separate dialogs/calibre restarts to switch a font. I still will fallback to respecting that value if the user does not bother in my plugin.
|
![]() |
![]() |
![]() |
#7 |
Calibre Plugins Developer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 4,721
Karma: 2197770
Join Date: Oct 2010
Location: Australia
Device: Kindle Oasis
|
All working now, thanks for the pointers guys.
|
![]() |
![]() |
![]() |
#8 |
Comparer of the Ephemeris
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,496
Karma: 424697
Join Date: Mar 2009
Device: iPad
|
That looks awesome, looking forward to trying it.
G |
![]() |
![]() |
![]() |
#9 |
Well trained by Cats
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 30,903
Karma: 60358908
Join Date: Aug 2009
Location: The Central Coast of California
Device: Kobo Libra2,Kobo Aura2v1, K4NT(Fixed: New Bat.), Galaxy Tab A
|
|
![]() |
![]() |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Fonts not working in a converted book | snape | Sony Reader | 9 | 11-08-2010 11:46 PM |
Embedded fonts, Calibre, and choice of fonts | AlexBell | ePub | 8 | 05-30-2010 06:00 AM |
Changing fonts not working? | tselling | Astak EZReader | 11 | 09-21-2009 03:03 PM |
Why are some fonts not working?? | daviddem | HanLin eBook | 4 | 01-22-2009 09:14 AM |
PRS-500 Embedded fonts in LRF WORKING | igorsk | Sony Reader Dev Corner | 21 | 03-23-2007 05:59 AM |