Exporting BookMorph pages to HTML+PNG

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Exporting BookMorph pages to HTML+PNG

Tony Garnock-Jones-2
I added a trivial method to BookMorph, exportPagesAsPng, which builds
PNG images of each page and an HTML+Javascript index file to drive a
simple slide show. I haven't hooked it in to the UI yet, but for those
interested a half-finished example slide show is here:

http://www.lshift.net/~tonyg/cake-presentation/PresentationBook.html

and the change-set is attached. Enjoy!

Tony
--
 [][][] Tony Garnock-Jones     | Mob: +44 (0)7905 974 211
   [][] LShift Ltd             | Tel: +44 (0)20 7729 7060
 []  [] http://www.lshift.net/ | Email: [hidden email]

'From Squeak3.8 of ''5 May 2005'' [latest update: #6665] on 10 May 2006 at 5:38:02 pm'!

!BookMorph methodsFor: 'as yet unclassified' stamp: 'tonyg 5/10/2006 17:35'!
exportPagesAsPng
        | fileName indexPageStream |
        'Exporting ', pages size printString, ' pages to PNG'
                displayProgressAt: Sensor cursorPoint
                from: 1 to: pages size
                during: [:progressSetter |
                        pages doWithIndex: [:page :i |
                                progressSetter value: i.
                                fileName := self externalName, '_', (i printStringLength: 3 padded: true), '.png'.
                                PNGReadWriter putForm: page imageForm onFileNamed: fileName.]].

        indexPageStream _ FileStream newFileNamed: self externalName, '.html'.
        indexPageStream nextPutAll: '<html>
  <head>
    <title></title>
    <script type="text/javascript">//<!![CDATA[
var name = new String(document.location);
name = name.substring(name.lastIndexOf("/") + 1, name.length - 5);

document.title = name;
pageNumber = 1;

function showPage() {
  var num = "000" + pageNumber;
  num = num.substring(num.length - 3, num.length);
  var url = name + "_" + num + ".png";
  document.getElementById("pageImage").src = url;
  document.getElementById("heading").innerHTML = name + " page " + pageNumber;
}

function nextPage() {
  pageNumber++; showPage();
}

function prevPage() {
  pageNumber--; showPage();
}

function firstPage() {
  pageNumber = 1; showPage();
}
//]]></script>
  </head>
  <body>
    <h1 id="heading"></h1>
    <button onclick="firstPage()">First Page</button>
    <button onclick="prevPage()">Previous Page</button>
    <button onclick="nextPage()">Next Page</button>
    <div>
    <img id="pageImage" />
    </div>
    <script type="text/javascript">showPage()</script>
  </body>
</html>'.
        indexPageStream close.
! !