View Single Post
Old 12-22-2018, 04:49 PM   #1
Brett Merkey
Not Quite Dead
Brett Merkey ought to be getting tired of karma fortunes by now.Brett Merkey ought to be getting tired of karma fortunes by now.Brett Merkey ought to be getting tired of karma fortunes by now.Brett Merkey ought to be getting tired of karma fortunes by now.Brett Merkey ought to be getting tired of karma fortunes by now.Brett Merkey ought to be getting tired of karma fortunes by now.Brett Merkey ought to be getting tired of karma fortunes by now.Brett Merkey ought to be getting tired of karma fortunes by now.Brett Merkey ought to be getting tired of karma fortunes by now.Brett Merkey ought to be getting tired of karma fortunes by now.Brett Merkey ought to be getting tired of karma fortunes by now.
 
Posts: 195
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]
5) Name the function and run.

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.
Brett Merkey is offline   Reply With Quote