04-24-2007, 12:20 AM | #16 |
Blueberry!
Posts: 888
Karma: 133343
Join Date: Mar 2007
Device: Sony PRS-500 (RIP); PRS-600 (Good Riddance); PRS-505; PRS-650; PRS-350
|
Thanks Kov.
Turns out there's a quick reference online that is far better than the one I linked above. I figured out a lot of stuff, including how to implement my curly quote algorithm. Now I can move on to questions more directly related to pylrs. I have two questions off the bat... (1) How do you set the BOTTOM MARGIN in pylrs? Using the default Text and Page objects, the text flows beyond the end of the screen, leaving the last sentence on the page partially obscured. I've been able to set top and side margin, but not bottom. If you add more text to the formatting.py example, you will see this behaviour. (2) Anyone know what font size matches that of makelrf3? For me, makelrf3 had the font size bullseyed... even better than the Sony Connect books. Pylrs uses a font that's too big for my tastes. -Pie |
04-24-2007, 12:24 AM | #17 |
creator of calibre
Posts: 43,858
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
I've added support for inline graphics to pylrs. Attached is a demo with the python code to create it.
@Falstaff The patch is available at pylrs.py https://libprs500.kovidgoyal.net/cha...lrs.py&new=235 pylrf.py https://libprs500.kovidgoyal.net/cha...lrf.py&new=235 Here's the python code to create helloworld.lrf Code:
from libprs500.lrf.pylrs.pylrs import * """ TextBlocks can be added to any page at any time, since the entire book is kept in memory. Text can also be added to any paragraph at any time. """ def helloworld(): # create the book book = Book() # add a page to the book using the default page style page = book.Page() page.TextBlock().Paragraph('Demonstration of embedded graphics').CR() # add a textblock to the page using defaults for TextStyle and BlockStyle textBlock = page.TextBlock() textBlock.blockStyle = BlockStyle(blockrule='horz-fixed', blockwidth='575') # add a paragraph to the text block istr = ImageStream('/tmp/try/cherubs.jpg') im = Image(istr, x0=0, y0=0, x1=300, y1=300, xsize=100, ysize=100) p = Paragraph('This line of text is before the graphic. ') dc = DrawChar(lines=3) dc.append(Plot(im, xsize=450, ysize=450)) p.append(dc) textBlock.append(p) textBlock.Paragraph('This line of text is after the graphic. It needs to be long enough to ensure that the graphic is not cut-off.') # generate the lrf file book.renderLrs("/tmp/helloworld.lrs") book.renderLrf("/home/kovid/helloworld.lrf") if __name__ == "__main__": helloworld() |
Advert | |
|
04-24-2007, 01:02 PM | #18 | |
creator of calibre
Posts: 43,858
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
Quote:
Code:
Book(pagestyledefault=dict(textwidth=575, textheight=747)) Last edited by kovidgoyal; 04-24-2007 at 01:05 PM. |
|
04-24-2007, 01:04 PM | #19 |
creator of calibre
Posts: 43,858
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
Here's a more complete example of using inline images. I had to Refactor the inheritance rules in pylrs a bit.
Code:
from libprs500.lrf.pylrs.pylrs import * """ TextBlocks can be added to any page at any time, since the entire book is kept in memory. Text can also be added to any paragraph at any time. """ def helloworld(): book = Book() istr = ImageStream('/tmp/try/cherubs.jpg') im = Image(istr, x0=0, y0=0, x1=300, y1=300, xsize=100, ysize=100) page = book.Page() page.TextBlock().Paragraph(Span('Demonstration of embedded graphics', fontsize='180')).CR() p = page.TextBlock().Paragraph('The image: ') p.append(Plot(im, xsize=550, ysize=550)) page.TextBlock(TextStyle(), BlockStyle(blockrule='vert-fixed')) page.TextBlock().Paragraph(Bold('Drop caps')).CR() textBlock = page.TextBlock() textBlock.blockStyle = BlockStyle(blockrule='horz-fixed', blockwidth='575') p = Paragraph('This line of text is before the graphic. ') dc = DropCaps(lines=3) dc.append(Plot(im, xsize=450, ysize=450)) p.append(dc) textBlock.append(p) textBlock.Paragraph('This line of text is after the graphic. It needs to be long enough to ensure that the graphic is not cut-off.') page.TextBlock().Paragraph(Bold('Inline graphic')).CR() page.TextBlock(TextStyle(), BlockStyle(blockrule='vert-fixed')) tb = page.TextBlock() p = tb.Paragraph('This line of text is before the graphic.') p.append(Plot(im, xsize=350, ysize=350)) p.append('This line of text is after the graphic.') book.renderLrs("/tmp/helloworld.lrs") book.renderLrf("/home/kovid/helloworld.lrf") if __name__ == "__main__": helloworld() |
04-24-2007, 09:04 PM | #20 |
Member
Posts: 21
Karma: 289
Join Date: Dec 2006
Device: Sony eReader
|
Nice work, kovidgoyal. I didn't look too closely yet, but I think you might have replaced the LrsDrawChar class -- this class is used to control what can nest inside of other classes (following the LRS specification). As I see you found out, the LRS spec uses the word DrawChar for two different things. I think there needs to be both the DrawChar class that you wrote and the empty LrsDrawChar that is used to enforce the nesting rules from the LRS spec.
LrsDrawChar and LrsSimpleChar1 are used just to identify the different types of things so that the code can complain if you try to put a LrsDrawChar where only a LrsSimpleChar1 is allowed. I forget why, but I didn't need LrsSimpleChar2... I should have put in some comments to explain that strange usage of the empty classes. But I didn't. Sorry. |
Advert | |
|
04-24-2007, 09:33 PM | #21 |
creator of calibre
Posts: 43,858
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
Thanks. Yeah in svn I've renamed DrawChar to DropCaps. I didn't put back LrsDrawChar though. As far as I can tell things work with just LrsSimpleChar1. At some point I should go through all the inheritance rules carefully and fix things.
|
04-25-2007, 01:07 AM | #22 |
Addict
Posts: 350
Karma: 705
Join Date: Dec 2006
Location: Mumbai, India
Device: Kindle 1/REB 1200
|
Falstaff, can you create some sort of "official" development area where patches could be sent? You have the original release, I have the same (with a few minor changes) and looks like kovidgoyal has a more different version ...
|
04-25-2007, 08:35 PM | #23 | |
creator of calibre
Posts: 43,858
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
Quote:
|
|
04-26-2007, 01:50 PM | #24 |
creator of calibre
Posts: 43,858
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
@Falstaff
I made some more changes to pylrs for functionality I needed in html2lrf Here's the combined diff https://libprs500.kovidgoyal.net/cha...%2Flrf%2Fpylrs |
04-28-2007, 02:45 AM | #25 |
Blueberry!
Posts: 888
Karma: 133343
Join Date: Mar 2007
Device: Sony PRS-500 (RIP); PRS-600 (Good Riddance); PRS-505; PRS-650; PRS-350
|
Does pylrs have a function to add a per-page heading, like books from the CONNECT store? The CONNET store books have a the book title at the top/right of the page in small text. Very handy.
-Pie |
04-28-2007, 02:01 PM | #26 |
Blueberry!
Posts: 888
Karma: 133343
Join Date: Mar 2007
Device: Sony PRS-500 (RIP); PRS-600 (Good Riddance); PRS-505; PRS-650; PRS-350
|
Another Python question.
Unicode characters (binary) kill my app. Is there a way to convert unicode to text? Or to convert unicode to Pythons u"\0020" format? -Pie |
04-29-2007, 06:50 PM | #27 |
creator of calibre
Posts: 43,858
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
yes it does have support for headers. See html2lrf
|
04-29-2007, 08:52 PM | #28 |
Blueberry!
Posts: 888
Karma: 133343
Join Date: Mar 2007
Device: Sony PRS-500 (RIP); PRS-600 (Good Riddance); PRS-505; PRS-650; PRS-350
|
I think I'm missing something here...
I have HTMLtoLRF-1.0 and it's a C++ program that requires a Windows DLL. Is there another version? Also, I think I need some explanation of libprs500 vs. pylrf-1.0.0. You've mentioned the former several times in this thread. What's the difference between these two libraries? Is libprs500 an extension of pylrf-1.0.0? -Pie |
04-30-2007, 02:04 PM | #29 | |
creator of calibre
Posts: 43,858
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
Quote:
|
|
05-03-2007, 02:56 PM | #30 |
Blueberry!
Posts: 888
Karma: 133343
Join Date: Mar 2007
Device: Sony PRS-500 (RIP); PRS-600 (Good Riddance); PRS-505; PRS-650; PRS-350
|
In figuring out the header stuff, I did some diffs between libprs500's pylrs and Falstaff's pylrs-1.0.0. Are there any plans to merge the codebases?
I didn't do extensive diffing, but it looks like Kovidgoyal added the pylrs-1.0.0 -- for example Image support -- rather than making changes to existing code. I think it would benefit the community extensively to have an update to the pylrs code base with Kovidgoyal's changes. -Pie |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Pissed off with LRF formatting: LRF/LRS clean tool? | grimborg | LRF | 8 | 02-15-2010 01:14 PM |
How do I Create a Python Plugin? | Sydney's Mom | Plugins | 25 | 01-27-2010 06:26 AM |
Converting LRS to LRF | mcortez | Sony Reader | 1 | 11-28-2007 11:26 AM |
LRS to LRF on Mac OSX - any suggestions? | Lime2K | Sony Reader | 3 | 07-29-2007 10:15 PM |
PRS-500 Span tags in LRS and LRF files -- do I understand them? | Falstaff | Sony Reader Dev Corner | 2 | 01-31-2007 10:34 AM |