Wednesday, January 29, 2014

Bug Chasing in Google Play Books

What I'm about to say concerns the epub rendering engine used by Google Play Books, the Californian tech-behemoth's first major attempt to break into the world of ebook retail. It will explain why I consider Google Play Books to be easily the weirdest e-reader available on the market today. As anyone who has worked with the standards-averse, held-together-with-gaffa-tape world of e-publishing will testify, competition for the title of "weirdest epub rendering engine" is always fierce, so this is quite a claim.

I think my findings back it up though.


Most e-readers ruin your books by not recognising certain CSS declarations, overriding them with their own defaults, or by implementing your CSS in a freakishly non-standard way – not so Google Play Books. The part of Google Play Books that handles CSS stylesheets – presumably forked from the Chrome browser – seems to be excellent, it can understand complex pseudo-class selectors and parse combinations of pseudo-class and pseudo-element selectors with ease. The problem comes from the way that it handles the HTML framework onto which that CSS is applied.

This first became apparent to me when I loaded one of the books I was working on into Google Play Books. This book had drop-caps on the opening body-text paragraphs of each chapter. These were identified using an HTML class (p.first) and a pseudo-element selector (::first-letter). I did it this way because it allowed swanky modern systems like iBooks and Readium to display drop-caps, but phrased it in such a way that Adobe Digital Editions and similar readers (which always render drop-caps wrong) would ignore it (pseudo elements mean nothing to them).

When I loaded this book into Google Play books I noticed something odd. In addition to the drop cap on the first paragraph (which rendered very nicely), it added a drop cap to the first letter of the following page (the page break having fallen halfway through the first para). This seemed to imply that Google Play Books was altering my HTML in real-time (it reacted to changes in font-size and line-height that moved the page break), adding in a hard paragraph break on either side of the page break.

This was weird, but I just thought “meh, I've seen weirder” and changed the pseudo-class selector to counter this odd habit. The drop-cap selector now said div.text>p:first-of-type::first-letter – selecting the first letter of the first child of the div.text container. I figured this would stop it from applying the drop cap to the second, artificial <p class="first">

When I ran this code in Readium, it worked fine. When I ran it in Google Play Books, however, something really strange happened. The text sprouted drop caps everywhere – not only on the first paragraph of the chapter, but also on the first paragraph of each page and the first paragraph after each nested <div>. This seemed to imply that Google Play Books was closing and re-opening the body text container at the end of each page and whenever the flow of text was interrupted by something.

Intrigued, I added another layer to my selector. I changed it to body>div.text>p:first-of-type::first-letter this absurdly convoluted selector should, in theory, have selected only the first letter of the first paragraph of the first div in the whole HTML document. What it actually did was select the first letter of each page.

This seems to imply that in order to render a book, Google Play Books takes the content from your epub and pastes it into an individual HTML document for each page. To make it even stranger, in order to work out where to put the page breaks it must have to apply the CSS to the HTML first, then work out where the page breaks will fall, then chop up the HTML into individual documents and re-apply the CSS. Only after it has gone through all that can it render the page.

This seems absurd, but it would explain some things about the odd behaviour of the Google Play Books app. For example, if you adjust the font size or line height, the screen goes blank and the whole thing has to reload before it can display the changes. This isn't something that any other e-reader does, but would make sense it it was having to re-generate a set of html files. Secondly, even simple books take a long time to load. The same book takes longer to load in Google Play Books – running on a brand-new android tablet – than it does on a first-generation iPad. Finally, there's the strange way that Google Play Books has to pause to load every six pages or so. There’s no way I know of to download and view a fragment of an HTML document, so logically there should only be a loading screen at the beginning of each chapter.

Unfortunately the only way to know exactly what it’s doing would be to break it open and rummage through the source code – a task I have absolutely no idea how to do (I'm just an editor who knows a bit of CSS).

Monday, January 20, 2014

The Theaterbunker

On the corner of Islington Green, facing onto Essex Road, there is a rather swanky apartment block. It is about four stories high, with a central courtyard that faces onto Essex Road. The ground floor is finished with a sort of faux-marble effect -- less tacky than it sounds -- and the upper floors are clad with something like cedar weatherboarding. I wouldn't call it an attractive building, necessarily, but it's clear that more thought was put into its design than you'd expect for an apartment block, even somewhere as swanky as Islington.

I first encountered this building in the spring of 2008, when I started working in an office nearby. I used to walk past it on my way to the shops to get lunch, or when heading to the bookshop a few doors up the street. Though the building was mostly finished, there were still workmen on site handling the fitting out and big wooden hoardings covering the entrance to the courtyard on the Essex Road side. At the time I paid it no mind.
     I started to think things were a bit odd when I noticed that, despite the construction hoardings and empty commercial units on the ground floor, people were living in the apartments on the upper floors. The windows had curtains and I'd sometimes see people wandering around inside. As the years passed a gym moved into the ground floor on the far end of the site, away from the green, and a penthouse apartment was added on to the top floor. The Islington Green end of the site, however, remained boarded up. The courtyard was hidden behind construction hoardings.

There were some other things about the building that struck me as odd. On the Essex Road side of the building there was a heavy-duty freight elevator that didn't seem to go anywhere (it's on the far right hand side of the picture above, notice that the room directly above it is someone's kitchen.) There are also several semi-concealed fire escape doors (the recesses on either side of the courtyard entrance) that don't appear to have staircases above them. All in all, it was a conundrum. I tried googling the building on several occasions, but came up with nothing. How do you google a building if you don't know the address or anything else about it?
    Today, this changed. When I was walking past the building on my way to the shops, I saw a planning application note pinned to one of the hoardings. It was notice of an application for an entertainment licence (theatre/music venue) made on behalf of the 'Collins Theatre'.
I dashed back to my desk and started searching for information. At first I was frustrated by references to the Collins Music Hall, which stood on that site until it burned down in 1958, but I soon dug down to find the good stuff.
     The first article I found was this one "Sally goes underground with £28m new theatre". It stated, to my astonishment, that there was a three-storey high basement under the site containing a 600 seat theatre. The article mentioned an architectural practice -- CZWG -- and a search for them turned up this page. At this point I dropped my soggy low-fat sandwich on my keyboard with a sguidgy flop of shock. Could it be that this basement, less than 100m from my office, was the final resting place of the reproduction of Shakespeare's Rose Theater, built for Shakespeare in Love?
     My doubts as to whether this project had ever actually gone ahead were quashed by pictures I found on the websites of the firm that built the basement, and the firm that created the beautiful glass roof over the auditorium. More detail on the project was furnished by this 2008 article in The Stage, entitled "Mystery surrounds Islington’s Collins Theatre as opening beckons".
     After 2008, however, it all seems to go quiet. The next mention I could find of the project was this article in the local paper "Waiting in wings... theatre still a shell after 20-year campaign", dated June 2009. Then, ominously, came this article in The Stage in September of that year, "BSC plans Shakespeare in Love’s Rose Theatre replica for northern base" linking the Rose Theatre reproduction with the BSC and suggesting that the Collins Theatre plan had fallen though. The next mention I could find of it was a passing mention in an article about a local Labour Party activist and artist called Avis Saltsman Baldry. According to "Great art grows on trees! Hugging Trees by Avis Saltsman at Islington Museum" she had been closely involved in the campaign to build the theatre. Her rather tetchy response, printed the following week, mentions that the state of the theatre was the "subject of litigation".
     Nothing more seems to have been said on the subject until the summer of 2013. The letters page of the Islington Tribune from August contains the following letter  "Still waiting for ‘curtain up’ at our underground theatre", written by Avis Saltsman Baldry. In this letter Ms Saltsman blames the Lib Dems and the economic downturn for the lack of progress on the project before complaining about the negative attitude of unnamed contractors in a manner that I can't really follow. Reading between the lines, it seems to imply that the theatre has no practical way to get large objects in and out, which seems rather a serious shortcoming.
     I would be interested to know more about this history of this project, and how it came to collapse so spectacularly, but I suspect it will be many years and many legal battles before we find anything out. Nonetheless, there are some clues. In a 2008 article questioning the logic of building a shiny new theater in an area that is already very well served with cultural venues, Simon Wroe of the Islington Tribune mentions that the developer was granted an exemption from the affordable housing requirement in return for promising to build the theatre. It seems unlikely that they would do something as expensive as excavate a three storey basement just to avoid putting any social housing in their development, but stranger things have happened. It would certainly explain why they're so profoundly unconcerned by its emptiness.

Having gotten this far, I've just realised that I can't find the Islington planning department reference for the new application, which might shed some light on what is currently going on. I'll have to write it down and check tomorrow.