12-22-2018, 04:49 PM | #1 |
Not Quite Dead
Posts: 194
Karma: 654170
Join Date: Jul 2015
Device: Paperwhite 4; Galaxy Tab
|
Regex: CSS font-size keyword to ems
I have found that the Kindle PaperWhite does not handle CSS font-size keywords well. If device font-size settings are not at the default, the Kindle will display fonts at uncomfortably extreme sizes. I have created a Calibre regex-function which maps keywords to ems.
1) Restrict search to style files. Apply "Beautify files" tool to make sure code is ready. 2) Set Mode to Regex-function. 3) Search: font-size: \K([^\d.;]+) 4) Click "Create/Edit" button and paste the following into the code box: Code:
def replace(match, number, file_name, metadata, dictionaries, data, functions, *args, **kwargs): # Match from list of size keywords i = ["medium", "small", "large", "x-small", "xx-small", "x-large", "xx-large", "larger", "smaller"].index(match.group(1)) # Map of corresponding sizes. Adjust as needed. size = ["1em", ".85em", "1.2em", ".75em", ".75em", "1.3em", "1.5em", "1.1em", ".9em"] return size[i] You can see from the code snippet that you can adjust the mappings to meet your own requirements. Last edited by Brett Merkey; 12-22-2018 at 04:56 PM. |
12-23-2018, 09:37 AM | #2 |
The Fumbler
Posts: 66
Karma: 10
Join Date: Jun 2015
Device: android 4.2/fbreader
|
Nice!
Alternatively, you could have written 9 simple Search and Replace statements. |
Advert | |
|
12-23-2018, 09:49 AM | #3 | |
Not Quite Dead
Posts: 194
Karma: 654170
Join Date: Jul 2015
Device: Paperwhite 4; Galaxy Tab
|
Quote:
Thank you, Calibre! |
|
12-23-2018, 12:54 PM | #4 | |
Addict
Posts: 387
Karma: 1638210
Join Date: May 2013
Location: Ontario, Canada
Device: Kindle KB, Oasis, Pop_Os!, Jutoh, Kobo Forma
|
Quote:
Thank you, Brett, this works like a charm and will same me a ton of work. I have been just gritting my teeth whenever I get a book from Open Road (among others); now it will be easy. |
|
12-23-2018, 01:07 PM | #5 |
Not Quite Dead
Posts: 194
Karma: 654170
Join Date: Jul 2015
Device: Paperwhite 4; Galaxy Tab
|
Thanks for the encouragement, RetiredBiker. I've been using this timesaver for a while. Perhaps I will review my collection of regexes and see if there any others that might be of general use.
|
Advert | |
|
12-23-2018, 01:40 PM | #6 |
Age improves with wine.
Posts: 558
Karma: 95229
Join Date: Nov 2014
Device: Kindle Oasis, Kobo Libra II
|
Many thanks for this -- another nice addition to my Saved Searches collection!
|
12-23-2018, 01:58 PM | #7 |
Age improves with wine.
Posts: 558
Karma: 95229
Join Date: Nov 2014
Device: Kindle Oasis, Kobo Libra II
|
...although I've just discovered that if I specify "All style files" it applies to ALL my saved searches, and I have to switch from "All text files" to "All styles files" and back again when I run it.
Wouldn't it be nice if each saved search included a specification of which files it applied to? |
12-23-2018, 02:09 PM | #8 | |
Not Quite Dead
Posts: 194
Karma: 654170
Join Date: Jul 2015
Device: Paperwhite 4; Galaxy Tab
|
Quote:
|
|
12-23-2018, 02:41 PM | #9 |
Addict
Posts: 387
Karma: 1638210
Join Date: May 2013
Location: Ontario, Canada
Device: Kindle KB, Oasis, Pop_Os!, Jutoh, Kobo Forma
|
I groused about having to change file sets at first, but now I have searches that can run on either text or style files, depending on the book. One that gets rid of hundreds of "@page" lines, for example.
The list of saved searches gets so long it it becomes unwieldy after a while. Maybe a way to save different sets of searches--like text searches, style searches, and the infamous Other--that might be nice. But then, having to choose a set each time could be cumbersome. |
12-24-2018, 09:29 AM | #10 | |
Age improves with wine.
Posts: 558
Karma: 95229
Join Date: Nov 2014
Device: Kindle Oasis, Kobo Libra II
|
Quote:
|
|
12-24-2018, 12:03 PM | #11 | |
Well trained by Cats
Posts: 29,792
Karma: 54830978
Join Date: Aug 2009
Location: The Central Coast of California
Device: Kobo Libra2,Kobo Aura2v1, K4NT(Fixed: New Bat.), Galaxy Tab A
|
Quote:
Search Groups (like folders). I have (also) USAGE type groups. CSS S&R, Cleanup (messy code, de-wordify), Touchup (font size rename pt->em) You can treat the group as a folder or you can RUN the group with a couple of clicks Neither Sigil or Calibre lets you set the file type or S&R mode as part of the saved search. |
|
12-24-2018, 01:29 PM | #12 | |
Not Quite Dead
Posts: 194
Karma: 654170
Join Date: Jul 2015
Device: Paperwhite 4; Galaxy Tab
|
Quote:
Perhaps there is some technical or user case reason why the type of file the search acts upon can not be saved. No problem, really. Just kind of anomalous. Last edited by Brett Merkey; 12-24-2018 at 01:35 PM. |
|
12-25-2018, 08:15 AM | #13 | |
Hedge Wizard
Posts: 800
Karma: 19999999
Join Date: May 2011
Location: UK/Philippines
Device: Kobo Touch, Nook Simple
|
Quote:
I have tried to run an existing group but cannot find the right couple of clicks. Could you give me a hint please. |
|
12-25-2018, 12:05 PM | #14 | |
Well trained by Cats
Posts: 29,792
Karma: 54830978
Join Date: Aug 2009
Location: The Central Coast of California
Device: Kobo Libra2,Kobo Aura2v1, K4NT(Fixed: New Bat.), Galaxy Tab A
|
Quote:
The Group only works from the Saved Search Window (not the context menu) SELECT the group title: Click the Load Search button: <your choice on the how to run> |
|
12-25-2018, 08:33 PM | #15 | |
Hedge Wizard
Posts: 800
Karma: 19999999
Join Date: May 2011
Location: UK/Philippines
Device: Kobo Touch, Nook Simple
|
Quote:
Thank you very much for the info. |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
CSS not working (specifically bold & font size) | kaonevar | Editor | 10 | 10-10-2014 12:47 AM |
can't reduce font size of headline using extra css | scissors | Recipes | 5 | 12-23-2013 03:45 AM |
Formatting sgc-toc.css font-size | phossler | Sigil | 13 | 09-07-2013 12:37 PM |
How to change the font-size in the body tag in css? | naisren | Conversion | 2 | 10-01-2012 05:52 PM |
Calibre has no choice on font size unit in css? | naisren | ePub | 6 | 09-30-2012 09:41 AM |