05-21-2016, 12:59 AM | #571 |
creator of calibre
Posts: 43,858
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
The way fallback fonts are chosen when the specified font does not exist has changed -- but the issue of not being able to use the first font int he list has always existed.
Yes, stroke is no longer possible (well technically, it is possible, just more effort than I feel like putting in for a plugin that I dont use/maintain). |
05-25-2016, 06:37 PM | #572 |
Zealot
Posts: 128
Karma: 278
Join Date: Jun 2008
Device: Kindle; PRS-500; MobiPocket on Windows Mobile
|
Agreed -- a dark "stroke" color surrounding a lighter "fill" color (or vice versa) makes the letters much more readable on images where the background colors are shifting behind the letters. I guess it's time to take a look at the plugin source code and see what's up with it. I've been meaning to get around to doing that anyway, as there are a couple other options I would find valuable, and this is good motivation.
|
Advert | |
|
05-25-2016, 07:58 PM | #573 |
Enthusiast
Posts: 26
Karma: 96
Join Date: Dec 2013
Device: Kindle Paperwhite (2nd Gen.)
|
I took a look at the plug-in source myself, as well as the documentation for Qt. It doesn't look like it would be nightmare to implement, though it's definitely non-trivial. Of course, I've no actual experience with coding for Calibre, so I may be underestimating the effort required.
|
05-25-2016, 10:27 PM | #574 |
creator of calibre
Posts: 43,858
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
If you want to re-enable stroke, what has to be done is create a QPAinterPath add the text to it, then draw it using the QPainter, instead of directly drawing the text with the QPainter. You will need to be careful with the auto resizing code, making sure the metrics its uses are the same metrics that will be sued for the final text painting.
|
05-28-2016, 04:27 PM | #575 |
Enthusiast
Posts: 37
Karma: 10
Join Date: Jan 2012
Location: Brazil
Device: Galaxy A71
|
Blank lines bug
A rather serious bug I noticed in the latest version of Generate Cover:
If you have any blank lines, anywhere, in one of the text fieldd, the entire content of the field is moved to the top of the cover layout -- yes, even overlapping other fields. I tried a number of tricks to work around it -- using <br> tags, using , using various blank characters -- and whenever the character didn't show, the result was the same: the field jumps to the top of the cover layout. This is very annoying because sometimes you NEED a blank line to tweak the text where you want to go. For instance, I routinely used blank lines in the "Custom Text" field as a spacer, because being a separate field the space can be fine-tuned by the simple expedient of changing the font size. |
Advert | |
|
05-28-2016, 04:38 PM | #576 |
Enthusiast
Posts: 37
Karma: 10
Join Date: Jan 2012
Location: Brazil
Device: Galaxy A71
|
Can't remove the image if it's set to "stretch to use as background"
And another odd bug: if the "Stretch image to use as cover background" is active on the "Dimensions" tab, unticking the "Image" box in the "Content" tab does nothing. It's not serious, it's easy to work around, but it's a bit counter-intuitive -- if you turn off the image, you expect it to disappear.
|
06-10-2016, 02:46 PM | #577 |
I need a chapter break
Posts: 4,042
Karma: 56058267
Join Date: Mar 2015
Location: Israel
Device: Kobo Glo
|
In Hebrew (rtl) the text is inverted, is there a way to fix it?
EDIT: I find if i inverted the text manually or by this software, it show correcetly in the cover. Last edited by oren64; 06-12-2016 at 03:46 AM. |
07-02-2016, 01:25 PM | #578 |
Zealot
Posts: 128
Karma: 278
Join Date: Jun 2008
Device: Kindle; PRS-500; MobiPocket on Windows Mobile
|
Wow, Kovid, I wish I had seen your comment before I started working on the code. I started by doing exactly what you suggest, but it was annoying me so I started exploring alternate methods of doing it for a few days and finally went back to the path method. It still took a few days to get it right (I could only spare a few minutes at a time to work on it) -- since QPainterPath.addText() doesn't let you specify a bounding rectangle, I had to figure out how to get the proper starting point for each line's text. Finally got it working so that it matches up properly, though, and I added the option to make the stroke any desired thickness. If anybody else cares about this, I can submit my changes.
|
07-02-2016, 01:53 PM | #579 |
Wizard
Posts: 1,327
Karma: 5306
Join Date: Jan 2014
Device: none
|
I would definitely appreciate it. This plugin is what's keeping me from updating Calibre.
Thanks so much for the work you've put into it. |
07-02-2016, 02:36 PM | #580 |
Evangelist
Posts: 482
Karma: 32554
Join Date: May 2014
Location: Canada
Device: Kobo Sage
|
So would I
|
07-02-2016, 03:01 PM | #581 |
Zealot
Posts: 105
Karma: 10
Join Date: Nov 2012
Location: Germany
Device: Kobo Libra 2
|
Hi chorpler!
I would be interested in the stroke option, too - but I would also really appreciate an instruction for adding the code, if that's possible. |
07-02-2016, 11:27 PM | #582 |
creator of calibre
Posts: 43,858
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
@chorpler: Doesn't QPainterPath have a boundingRect method?
|
07-09-2016, 12:08 AM | #583 |
Zealot
Posts: 128
Karma: 278
Join Date: Jun 2008
Device: Kindle; PRS-500; MobiPocket on Windows Mobile
|
firefoxxy: it's not too complicated to add my modifications to the code, and the source code itself is already included in the "Generate Cover.zip" file you can download. Most of the modification goes in draw.py, which is responsible for (unsurprisingly) doing all the text layout and actually drawing it. I will make the code available on GitHub, plus as good a tutorial as I can come up with in the time I can spare.
kovidgoyal: yes, QPainterPath absolutely does have a boundingRect() method, which gives you the bounding rectangle it ends up with after you create it and do something like QPainterPath.addText(). But what it doesn't have, and what would be useful for what we want to do here, is a setBoundingRect() method, or a parameter for QPainterPath.addText() that would be equivalent. A bit more detail for anybody curious: currently, the Generate Cover plugin uses a method called QPainter.drawText() to do the text layout and then actually drawing it. And QPainter.drawText() will let you specify a bounding rectangle as one of its parameters (it also has parameters for the text to draw, the font to use, the font size to use, the alignment of the text, whether wrapping is allowed, etc.). Then QPainter.drawText() handles the details of text layout automatically, fitting the text into the specified bounding rectangle and using the specified alignment and wrapping settings. So, to make it work with Generate Cover's options, you just have to make a bounding rectangle from the cover size and the desired margins, and then let QPainter.drawText() handle all the layout for you. Unfortunately, QPainter.drawText() doesn't have any way to stroke/outline the text it draws. So, to make the stroke option work again, we have to convert the text to a path, which is just a representation of the outline of the text. Then we can draw the resulting path, using whatever color and thickness we want, and we can also fill the path, so we can get a stroke and a fill of different colors. Just what we want! So the way we make our text into a path we can draw is to use a method called QPainterPath.addText(). But it is not as sophisticated as QPainter.drawText(). The big difference for our purposes is that QPainterPath.addText() doesn't let you specify a bounding rectangle. You can only specify the starting point for the path (and it isn't even a bounding rectangle point -- it's the point where the baseline of the text will start. What that means is explained in the documentation for QPainterPath.addText()). And QPainterPath.addText() is also not good at text alignment (left, center, right) or wrapping, so you have to figure out where the given text will be wrapped and then calculate the starting point for each line. It's a lot more intricate than just letting the QPainter.drawText() function handle it automatically. Fortunately, you can do a version of what QPainter.drawText() does internally (I believe -- haven't examined the Qt / PyQt source code yet to verify this) and use the QTextLayout class to figure out where the text will wrap and what the starting points of each line will be. Then you can plug those into QPainterPath.addText(), then add those paths to the QPainter object with QPainter.addPath(), run a fill with QPainter.fillPath(), and the words are drawn just as if you were using QPainter.drawText() (but with the stroke showing up again! Hooray!). There's a minor issue currently, where some characters in some fonts are not processed properly. For instance, one of my books has a title that includes a literal HTML tag, </span>, and the slash is normally seen as part of the text path, as it should be. But if there's an "s" right after it, then suddenly the slash is not seen, and it doesn't get a stroke drawn for it, even when all the other characters do. In another case, titles that have colons in them, where the font being used is the "Buffied" font (which I use for anything spooky ... and, of course, for anything Buffy the Vampire Slayer related), are working fine for the most part, but for some reason QPainter.fillPath() doesn't realize that the colon's two circles are fillable paths. So it draws the stroke normally, and the colon shows up as two circles stacked vertically ... but they are left as empty outlines, even though all the other characters are filled in properly. Because of this issue, right now I still have the original QPainter.drawText() code running first, and then the stroke path just draws over the top of it, rather than drawing everything itself. That at least leaves characters visible, even when the new QPainterPath.addText() technique is having problems. I suspect I need to do a little string sanitizing to fix this weird bug. I am taking a look at it after I post this. (On the plus side, doing it this way allows me to quickly verify that I got the path position calculations right, since it's easy and obvious if the stroke is not in precisely the right place, outlining each character.) Finally, just as a brief aside, kovidgoyal, thanks for all the time and effort you put into Calibre and helping us! |
07-09-2016, 12:23 AM | #584 |
creator of calibre
Posts: 43,858
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
@chorpler: Ah you are having trouble with wrapping text. Well there are a couple of other approaches you can try. One is to use QSvgRenderer with SVG that species the text with appropriate fill and stroke properties. IIRC SVG supports that -- though I may be misremembering.
Another possibility is to use HTML + CSS for the layout, with QWebView. WebKit supports text stroking, https://css-tricks.com/adding-stroke-to-web-text/ |
07-10-2016, 09:35 AM | #585 |
Zealot
Posts: 105
Karma: 10
Join Date: Nov 2012
Location: Germany
Device: Kobo Libra 2
|
Dear chorpler
Thank you for your explanation (although I didn't understand much of the information you gave, I am usually quite adept at following a how-to-guide - I just don't get why I am doing things :P) So, I'm grateful for any kind of guidance you'll give |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
[GUI Plugin] Goodreads Sync | kiwidude | Plugins | 1721 | 04-18-2024 10:22 AM |
[GUI Plugin] Clipboard Search | kiwidude | Plugins | 29 | 04-02-2024 10:05 PM |
[GUI Plugin] Open With | kiwidude | Plugins | 403 | 04-01-2024 08:39 AM |
[GUI Plugin] User Category | kiwidude | Plugins | 123 | 03-16-2024 11:59 PM |
[GUI Plugin] Quick Preferences | kiwidude | Plugins | 62 | 03-16-2024 11:47 PM |