View Single Post
Old 04-24-2007, 01:04 PM   #19
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 45,417
Karma: 27757236
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()
Attached Files
File Type: lrf helloworld.lrf (21.9 KB, 436 views)
kovidgoyal is online now   Reply With Quote