06-13-2008, 07:10 PM | #1 |
Wizard
Posts: 3,671
Karma: 12205348
Join Date: Mar 2008
Device: Galaxy S, Nook w/CM7
|
LRF2LRF (Font and Margin modifyer)
Hi All,
I’ve created a tool for my personal usage thought others might find it useful. Description The tool is called LRF2LRF. The main design of the tool is to change the font size and margins of LRF books. I designed this tool because I tend to find that most if not all LRF books tend to have huge fonts and large margins making. Of course users of this tool can also use it to increase the font and margin size as well. The design: This tool is a Perl script that calls Calibre’s lrf2lrs to generate the LRS file. Once the file is modified then calls LRS2LRF to create the LRF file once again. Known Issues: - There is a bug in Calibre's lrs2lrf tool that does not create the Header or Footer in the modified LRF file. (Calibre Ticket #909) - Right Margin does not change (Top/Bottom/Left) margins can be changed (Calibe Ticket #911) Below are some sample LRF files INSTALLATION This tool requires Calibe to run. 1) Put the script in the same location as the Calibe tool. (where lrf2lrs and lrs2lrf is located) windows: e.g. C:\Program Files\Calibe The tool is a command line tool to run LRF2LRF type C:\My Books\> lrf2lrf -s 80 myBook.lrf if no file name is passed "-o mynewname.lrf" the existing LRF (myBook.lrf) file will be modified. C:\My Books\> lrf2lrf -o myNEWBook.lrf -s 80 myBook.lrf Last edited by =X=; 09-15-2008 at 12:23 PM. |
06-13-2008, 07:44 PM | #2 |
Technogeezer
Posts: 7,233
Karma: 1601464
Join Date: Nov 2006
Location: Virginia, USA
Device: Sony PRS-500
|
And where would one find this tool?
|
Advert | |
|
06-15-2008, 01:10 AM | #3 |
Guru
Posts: 780
Karma: 1416
Join Date: Jan 2008
Device: Kobo Clara 2E/HD, Kindle PW
|
X, first of all, have some karma for developing software for the Sony Reader! Secondly, how does one use it? Say I want to enlarge the text font for a particular book. I tried several combinations of command strings on my test book, and all I was able to do was enlarge the title.
|
06-15-2008, 04:55 AM | #4 |
Wizard
Posts: 3,671
Karma: 12205348
Join Date: Mar 2008
Device: Galaxy S, Nook w/CM7
|
Hi Jeff,
Thank you. Just a FYI there is a help just type "lrf2lrf -h" from the command line and the help page will print. There are two ways to change the fonts. First if you know the exact font size you want to change type this command. Code:
lrf2lrf -f 100,150 MyeBOOK.lrf 100 = 10pts 150 = 15pts Note this will change every 10pts to 15pts Second is a tad harder, but very doable. You have to find the TextStyle uinqie ID. There is a uniqe ID for each font style in the reader. This is done by typing the following command Code:
lrf2lrf -e MyeBOOK.lrf Note the text that occures the most is TextStyle ID 317 it also has a font size of 80 (8pts) TextStyle ObjId=310 Fontsize = 160 Now that you have the TextStyle ID (objID) and the Font sizes. Determine which is the one you want to change and pass the ID with the new font size as described below TextStyle ObjId=315 Fontsize = 110 TextStyle ObjId=317 Fontsize = 80 Recommend TextStyle = 317 Found TextStyle = 315 Occurrence = 14 Found TextStyle = 363 Occurrence = 2 Found TextStyle = 317 Occurrence = 79 Code:
lrf2lrf -x <TextStyle ID> -s <My New Font size> MyBook.lrf If my explanation does not clear things up. Please run lrf2lrf -e <your LRF book> and post the output on the board. =X= |
06-15-2008, 05:46 AM | #5 |
Addict
Posts: 370
Karma: 1553
Join Date: Feb 2008
Location: Melbun
Device: Kobo H2O
|
Looks good, very useful for people like me that often want to get rid of margins and make the font size more usable... I'm currently at ~7.8pt and dropping. Looking for the point where I get most on the screen without killing my reading speed through too-small text.
thanks |
Advert | |
|
06-30-2008, 02:56 PM | #6 |
Wizard
Posts: 3,671
Karma: 12205348
Join Date: Mar 2008
Device: Galaxy S, Nook w/CM7
|
Fixed some defects now on version 1.01
|
07-03-2008, 03:11 PM | #7 |
Wizard
Posts: 3,671
Karma: 12205348
Join Date: Mar 2008
Device: Galaxy S, Nook w/CM7
|
New update v 1.02
Fixed a defect, the '-x' switch did not work.
The tool now removes the temp files created by the LRF2LRS extraction. =X= |
07-24-2008, 04:27 AM | #8 |
Fanatic
Posts: 589
Karma: 1451235
Join Date: Jun 2008
Device: Sony PRS-505, Sony PRS-950
|
I'm a newb, but I can't get the script to run. I've put the lrf2lrf file in the calibre directory, but when i go to cmd window and type in lrf2lrf or anything else suggested here it says "lrf2lrf is not recognized as an internal or external command, operable program or batch file."
|
07-24-2008, 10:11 PM | #9 |
Wizard
Posts: 3,671
Karma: 12205348
Join Date: Mar 2008
Device: Galaxy S, Nook w/CM7
|
Do you have Perl installed on your OS? What OS are you using?
If No you need to install it. If you have windows/Mac you can download ActiveState Perl. It's free and works great. Locate where the 'perl.exe' is and make sure the path of the perl executable is on the same path of the first line in the script Code:
#!/usr/bin/perl Then you can change the first line in the script to Code:
#!C:/perl/bin/perl.exe |
08-15-2008, 08:10 PM | #10 |
Wizard
Posts: 3,671
Karma: 12205348
Join Date: Mar 2008
Device: Galaxy S, Nook w/CM7
|
Hi Everyone
I've uploaded an executable version of the perl script. This exe does not require the installation of perl. Just unzip the file and place it in your calibre directory to use the script. =X= |
08-25-2008, 12:03 PM | #11 |
Junior Member
Posts: 9
Karma: 10
Join Date: May 2008
Device: Sony PRS 505
|
Thank you.
Very useful. I have some Gutenberg books books converted from HTML to .lit and then into .lrf. All of them had varying font and margins depending an when they were downloaded and converted into .lit This helps me standardize all of them, great work. Have some karma. PS: I wonder if this sort of feature can be incorporated into Calibre to run from its gui? |
08-25-2008, 07:43 PM | #12 |
Wizard
Posts: 3,671
Karma: 12205348
Join Date: Mar 2008
Device: Galaxy S, Nook w/CM7
|
Hi EssKayEss,
I'm glad you find the tool useful. It wouldn't be too hard from the GUI side to add support for a tool called LRF2LRF. However the harder part would be to write the LRF2LRF tool using Calibre's plugin architecture. I agree a feature like this is probably best kept in the Calibre realm. It doesn't make sense to have a LRF2LRF tool all on it's own. Unfortunately I do not know Python and am limited in time. So I chose the quickest path to fill my need to be able change the font size and margins of existing LRF files. Anyhow thank you for the karma. =X= Last edited by =X=; 08-25-2008 at 07:45 PM. Reason: Updated for clairification |
11-15-2008, 10:00 AM | #13 |
Wizard
Posts: 1,177
Karma: 2431850
Join Date: Sep 2008
Device: IPad Mini 2 Retina
|
I would like to use this utility but I can't get it to work. It produces the output file OK, but I can't see any changes - I'm trying to reduce the font from 10 to 8 pt, and reduce margins too.
This is the command line I am using: lrf2lrf -s 80 -t 0 -b 0 -l 0 -r 0 -o NewLrfFile OldLrfFile and this is the output: Code:
Reformatting Silverberg-Live-Again.lrf Parsing LRF... Creating XML... LRS written to .Silverberg-Live-Again.lrs.tmp LOOKING FOR 72, 75, 80 Parsing LRS file... Writing to output file... Output written to E:\My Documents\My Library\Reader\Books\Silverberg-Live-Again. new.lrf This exe file was created with the evaluation version of Perl2Exe. For more information visit http://www.indigostar.com (The full version does not display this message with a 2 second delay.) |
11-15-2008, 03:11 PM | #14 |
Wizard
Posts: 3,671
Karma: 12205348
Join Date: Mar 2008
Device: Galaxy S, Nook w/CM7
|
Well written Trouble report, thank you!
The commands you are using is correct. However you'll need to specify yet another switch. What happens is the software tries to guess which is the font you want to change by looking at the highest occurrence. This works most of the time, but there are a few LRF out there that don't follow this pattern. What you have to do is run this command Code:
lrf2lrf -e Silverberg-Live-Again.lrs The output looks something like this Code:
Parsing LRF... Creating XML... LRS written to .a.lrs.tmp TextStyle ObjId=52 Fontsize = 100 Recommend PageStyle = 56 Found PageStyle = 56 Occurrence = 2 Found PageStyle = 54 Occurrence = 2 Recommend TextStyle = 52 Found TextStyle = 52 Occurrence = 2 In my example there was only one font used but you'll have more. In the example you'll see I spit out the TextStyle, ObjID, and fontsize. (They are underlined above) Find the correct Object ID and pass that value using the '-x' switch Code:
lrf2lrf -x 52 -s 80 -t 0 -b 0 -l 0 -r 0 -o NewLrfFile OldLrfFile |
11-16-2008, 05:20 AM | #15 |
Wizard
Posts: 1,177
Karma: 2431850
Join Date: Sep 2008
Device: IPad Mini 2 Retina
|
Thanks for your help, and such a nice little utility! This is just the thing I need as I like to reformat the lrfs I download in order to get as much text as possible on the screen (smaller fonts and margins).
This is the output using -e: Code:
lrf2lrf -e "Silverberg-Live-Again.lrf" Parsing LRF... Creating XML... LRS written to .Silverberg-Live-Again.lrs.tmp TextStyle ObjId=75 Fontsize = 100 TextStyle ObjId=77 Fontsize = 100 TextStyle ObjId=78 Fontsize = 100 TextStyle ObjId=81 Fontsize = 60 Recommend PageStyle = 72 Found PageStyle = 72 Occurrence = 20 Recommend TextStyle = 75 Found TextStyle = 81 Occurrence = 2 Found TextStyle = 77 Occurrence = 20 Found TextStyle = 75 Occurrence = 22 Found TextStyle = 78 Occurrence = 7 I also tried the following command: Code:
lrf2lrf -f 100,80 -o "Silverberg-Live-Again.new.lrf" "Silverberg-Live.Again.lrf" Parsing LRF... Creating XML... LRS written to .Silverberg-Live-Again.lrs.tmp LOOKING FOR 72, 100,80, 80 Parsing LRS file... Writing to output file... Output written to E:\My Documents\My Library\Reader\Books\Silverberg-Live-Again.new.lrf I got what I wanted using this command: Code:
lrf2lrf -x 77 -s 80 -o "Silverberg-Live-Again.lrf" "Silverberg-Live-Again.lrf" Parsing LRF... Creating XML... LRS written to .Silverberg-Live-Again.lrs.tmp LOOKING FOR 72, 77, 80 Parsing LRS file... Writing to output file... Output written to E:\My Documents\My Library\Reader\Books\Silverberg-Live-Again.lrf The other thing that occurs to me - when using -s without -x, I believe lrf2lrf uses the maximum number of occurrences to decide which objid to change. This does not work with the Silverberg book because there are in fact more chapter numbers; could the size of the textblock be considered too? As an example, here are the first two textblocks from a page from the book: Code:
<Page pagestyle="72" objid="28"> <TextBlock objid="20" blockstyle="76" textstyle="75"> <P>1</P><CR /></TextBlock> <TextBlock objid="21" blockstyle="76" textstyle="77"> <P>The lamasery rose steeply from the top of the bluff on the Marin County side of the Golden Gate. Feeling a faint cramp in his left calf, John Roditis got out of the car near the toll plaza and, stretching and kicking, looked across the water at the gleaming yellow building, windowless, sleek, ineffably holy as a fountainhead of good karma. It was an extraordinarily warm day. yada yada yada</P><CR /></TextBlock> </Page> I hope you don't mind my suggestions and that they are of some help. Last edited by ShellShock; 11-16-2008 at 05:58 AM. |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
margin: 0 auto; | gardefjord | ePub | 21 | 10-06-2010 11:02 AM |
Margin question | Switch | Calibre | 11 | 05-13-2010 04:32 PM |
How to shrink margin? | tomsem | Kindle Developer's Corner | 2 | 12-11-2009 11:20 PM |
calibre ignore margin-top and margin-bottom | bender | Calibre | 2 | 12-11-2009 07:58 AM |
Right Margin Control | TedPark | Sony Reader Dev Corner | 4 | 07-02-2008 08:41 AM |