|
|
#106 | |
|
Enthusiast
![]() Posts: 33
Karma: 10
Join Date: Feb 2011
Device: Android Tablet
|
Quote:
|
|
|
|
|
|
|
#107 | |
|
Well trained by Cats
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 31,379
Karma: 62500000
Join Date: Aug 2009
Location: The Central Coast of California
Device: Kobo Libra2,Kobo Aura2v1, K4NT(Fixed: New Bat.), Galaxy Tab A
|
Quote:
Sorry, but that makes little sense (as a 1 click) FIND search1, But don't pause or replace. FIND search2, But don't pause or replace. A simple search for 1 of multiple values: [red!black] , but again, Editor chains is for an AUTOMATED task and you want a STOP for manual |
|
|
|
|
| Advert | |
|
|
|
|
#108 |
|
Connoisseur
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 91
Karma: 6698
Join Date: Sep 2022
Location: South Africa
Device: kindle pw10
|
New action request
Hi,
Thanks for all your work. I would like to request an additional action. Remove all fonts. I do not use any of the fonts in a book and rely on the font I select on my reading device. Just a help in the cleanup.
|
|
|
|
|
|
#109 |
|
Well trained by Cats
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 31,379
Karma: 62500000
Join Date: Aug 2009
Location: The Central Coast of California
Device: Kobo Libra2,Kobo Aura2v1, K4NT(Fixed: New Bat.), Galaxy Tab A
|
It is a conversion option: (at the bottom)
On the Styling tab or Preferences: Common Options: if you want it as the default |
|
|
|
|
|
#110 |
|
Connoisseur
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 91
Karma: 6698
Join Date: Sep 2022
Location: South Africa
Device: kindle pw10
|
Thanks for the tip.
Didn't work for me though. Tried adding an epub- still there. Converted epub to epub - still there. Will try some more. Maybe there is another setting somewhere. Last edited by skil-phil; 12-12-2025 at 01:58 AM. Reason: Spelling |
|
|
|
| Advert | |
|
|
|
|
#111 |
|
Connoisseur
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 91
Karma: 6698
Join Date: Sep 2022
Location: South Africa
Device: kindle pw10
|
Found it does remove fonts that are not imbedded.
Imbedded fonts remain. Now to try to automate unembeding them. Thanks Last edited by skil-phil; 12-12-2025 at 01:58 AM. |
|
|
|
|
|
#112 |
|
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,221
Karma: 1995558
Join Date: Aug 2015
Device: Kindle
|
The plugin has a generic "Remove files" action. It supports regex, so you can use it to remove fonts with this regex
Code:
(?i).+\.(otf|ttf)$ Attached below is a sample chain. Please test and verify before saving your books. |
|
|
|
|
|
#113 |
|
Connoisseur
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 91
Karma: 6698
Join Date: Sep 2022
Location: South Africa
Device: kindle pw10
|
Thanks capink,
That worked and removed them from the file browser. They still show in the manage fonts dialogue though. Is this a problem? Can I just ignore it? Thanks |
|
|
|
|
|
#114 |
|
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,221
Karma: 1995558
Join Date: Aug 2015
Device: Kindle
|
Manage font dialog will show any font referenced in any CSS rule, with the embedded font having a "✓" sign next to it, as opposed to non embedded fonts. If you want to delete all fonts and all references to them as done in the Manage fonts dialog, you can use this custom action which is based on the remove fonts functionality in "Manage fonts dialog":
Code:
from calibre.ebooks.oeb.polish.fonts import change_font, font_family_data
from calibre_plugins.editor_chains.actions.base import EditorAction
class RemoveAllFonts(EditorAction):
name = 'Remove All Fonts'
headless = True
def run(self, chain, settings, *args, **kwargs):
container = chain.current_container
font_data = font_family_data(container)
for font in font_data.keys():
change_font(container, font)
def validate(self, settings):
return True
Note: Using the above method, you will lose all the font formatting even if the font is installed on your device, as the function deletes all font-family properties from the epub. This apply to previously embedded as well as non-embedded fonts. Last edited by capink; 12-12-2025 at 07:09 AM. |
|
|
|
|
|
#115 |
|
Connoisseur
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 91
Karma: 6698
Join Date: Sep 2022
Location: South Africa
Device: kindle pw10
|
Thank you.
All good now. Your hard work certainly makes life easier for users. Cheers. |
|
|
|
|
|
#116 |
|
Connoisseur
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 91
Karma: 6698
Join Date: Sep 2022
Location: South Africa
Device: kindle pw10
|
Hi,
I also found that I needed to add the following to the Remove all fonts chain. Search and replace "font-family: (.*?);" with "" in All Style Files. Cheers |
|
|
|
|
|
#117 | |
|
Well trained by Cats
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 31,379
Karma: 62500000
Join Date: Aug 2009
Location: The Central Coast of California
Device: Kobo Libra2,Kobo Aura2v1, K4NT(Fixed: New Bat.), Galaxy Tab A
|
Quote:
Calibre (editor debug) will issues a warning if no generic font is declared in a "font-family" |
|
|
|
|
|
|
#118 |
|
Connoisseur
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 91
Karma: 6698
Join Date: Sep 2022
Location: South Africa
Device: kindle pw10
|
Thanks, will look into that.
|
|
|
|
|
|
#119 |
|
Fanatic
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 580
Karma: 32228
Join Date: Feb 2012
Device: Onyx Boox Leaf
|
I have this python script to rename image.webp to image_width_height.webp, which runs fine on Windows
Code:
python path_to_script.py path_to_image.webp - Choose Binary: python - arg: "path_to_script" {inputfile} - extension: webp It returns no error but nothing is changed. I tried pasting the code to the "Run Python Code" section, but it doesn't provide the "selected files" option so it returned error. What should I do? I want the selected webp images to include width and height values in their filenames. The code is Code:
from PIL import Image
import sys, os
f = sys.argv[1]
if not os.path.exists(f):
print(f"File not found: {f}")
sys.exit(1)
im = Image.open(f)
w, h = im.size
im.close()
base, ext = os.path.splitext(f)
new_name = f"{base}_{w}_{h}{ext}"
os.replace(f, new_name)
Last edited by nqk; 12-25-2025 at 05:29 AM. |
|
|
|
|
|
#120 | |
|
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,221
Karma: 1995558
Join Date: Aug 2015
Device: Kindle
|
Quote:
The reason for that is that the structure for files in the container is different than the usual directory structure, so the usual code to work on these files like os.replace() is not going to work. Which is why your code does not work as expected. To work around this, you can mimic the way the "Run Command" action works, by copying the content of the files into temporary files that exist in a classic directory, and run the commands on the temporary file, after which it replaces the corresponsing files in the container with the temporary files. Here is how to adapt your code into a "Run Python Code" action using the same idea, but since your code does not change the content of the files, we will not need to replace the files, but only to rename them using calibre's rename_files() Code:
from PIL import Image
import os
from calibre.ptempfile import better_mktemp
from calibre.ebooks.oeb.polish.replace import rename_files
supported_formats = ['epub']
def run(chain, settings):
container = chain.current_container
name_map = {}
for name, media_type in container.mime_map.items():
dirname = os.path.dirname(name)
basename = os.path.basename(name)
base, ext = os.path.splitext(basename)
if media_type.startswith('image'):
temp_file = better_mktemp(suffix=ext)
with open(temp_file, 'wb') as f:
f.write(container.raw_data(name, decode=False))
im = Image.open(temp_file)
w, h = im.size
im.close()
new_name = f"{base}_{w}_{h}{ext}"
name_map[name] = os.path.join(dirname, new_name)
os.remove(temp_file)
rename_files(container, name_map)
Thanks. Merry Christmas to you. Edit: The above code will work on all image files in the book, if you want only the selected files run this: Code:
from PIL import Image
import os
from calibre.ptempfile import better_mktemp
from calibre.ebooks.oeb.polish.replace import rename_files
supported_formats = ['epub']
def run(chain, settings):
container = chain.current_container
name_map = {}
for name in chain.gui.file_list.file_list.selected_names:
dirname = os.path.dirname(name)
basename = os.path.basename(name)
base, ext = os.path.splitext(basename)
temp_file = better_mktemp(suffix=ext)
with open(temp_file, 'wb') as f:
f.write(container.raw_data(name, decode=False))
im = Image.open(temp_file)
w, h = im.size
im.close()
new_name = f"{base}_{w}_{h}{ext}"
name_map[name] = os.path.join(dirname, new_name)
os.remove(temp_file)
rename_files(container, name_map)
Last edited by capink; 12-25-2025 at 08:15 AM. |
|
|
|
|
![]() |
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| [Editor Plugin] EpubCheck | Doitsu | Plugins | 220 | 11-09-2025 06:12 PM |
| [Editor Plugin] LanguageTool | Doitsu | Plugins | 17 | 04-20-2024 03:21 PM |
| [Editor Plugin] - Enabling 'Customize plugin' dialog directly from the Editor | thiago.eec | Development | 7 | 01-09-2019 09:05 PM |
| Sample Plugin for the Editor | DiapDealer | Editor | 77 | 12-10-2014 08:16 AM |
| Editor plugin question | DiapDealer | Development | 2 | 07-28-2014 11:23 PM |