Thursday, April 21, 2011

OverDrive says Kindle will support EPUB and PDF

Yesterday, Amazon announced the new Kindle Library Lending Program. They haven't offered a lot of details, but one little tidbit written to librarians on one of OverDrive's blogs caught my eye:

Your existing collection of downloadable eBooks will be available to Kindle customers. As you add new eBooks to your collection, those titles will also be available in Kindle format for lending to Kindle and Kindle reading apps. Your library will not need to purchase any additional units to have Kindle compatibility. This will work for your existing copies and units.

Emphasis added by me. And I'll repeat it once more:

Your existing collection...

Currently, public libraries' existing collections consist overwhelmingly of EPUB and PDF files. If those existing files will now work with Kindle, with no additional purchase necessary, the only possible solution is that Kindle will support both EPUB and PDF.

And that is news indeed.

Tuesday, April 19, 2011

Resizing images in EPUB

Some time ago, a reader wrote to tell me that I had gotten the code wrong for resizing images in my EPUB Straight to the Point book. At first, I thought he was right, but at second and third glance, I realize that he wasn't.

The problem is that the iPad doesn't recognize when you add width information directly to a img element. That is non-standard behavior (read: a bug) and should be fixed.

First, let's look at how CSS deals with images. An image has an intrinsic size, that is, its actual size in pixels. If you don't apply width or height information to the image, either in the HTML or the CSS, the image will appear at its original size. CSS allows you to set the height and the width of an image explicitly in pixels, or as a percentage of a parent element. This means that if you set the width of an image to 50%, the image should be displayed at 50% of the width of the element in which the image is contained, not 50% of the image's original width.

Here's what it looks like in Firefox. The image takes up half of the window width since its ancestor element is the body. So far so good.

image 50%

Enter iBooks. Unfortunately, iBooks has a bug that ignores a width explicitly set for an img element. Just completely ignores it:

image 50% in ibooks

The first part of the solution, as a I describe in EPUB Straight to the Point, is to enclose the img in a div and then set the width of the div to the desired width, either in pixels or as a percentage.

But observe what happens if you remove the width property from the img and apply it to the div that contains the img. In iBooks it (erroneously) works as you want it to:

div 50% ibooks

But iBooks, as we noted, doesn't follow the CSS spec. However, and this is a big however, Firefox, Safari, and Adobe Digital Editions—and all of the ereaders based on ADE, like the Sony Reader and Barnes & Noble Nook—do follow the spec.

The spec says that, by default, if a replaced element, like an image, is too big for its container (say, a div that you've reduced by half) then the image spills out over the edges. That is, it displays just the same. What the spilled out part (the overflow) doesn't do is affect the layout. Which means that any surrounding text just runs over it as if it weren't there. It's ugly.

image width bad on Nook

As you can see, the div has been reduced to 50% of the width of the window, but the image is unaffected. By default, overflow is visible, but doesn't affect the flow of the page, which is why that text just rolls right over it. Ick.

The second part of the solution, (also contained in EPUB Straight to the Point) is to set the width of the img element to 100% of its parent, in this case, the div. Since the div is 50% of the width of the window, and the img is 100% of the div, then the img will also be set to 50% of the window. This works in both iBooks and more standards-compliant ereaders:

div 50%, img 100%

Image width better on nook

At some point, I had suggested using max-width instead of width but that only works in iBooks, not the other ereaders. In other words, it's no solution.

Tuesday, April 12, 2011

Embedding Fonts in EPUB- iPad, iPhone AND nook

I don't know how I missed this. I did see that Apple had published a new iBookstore Assets guide in late March, and I looked through the “changes in version 4.6” section pretty closely. But today I noticed something new: iBooks now supports embedded fonts even in regular, reflowable, non-fixed layout EPUBs.

That's not all. I noticed while I was testing this feature that Apple no longer restricts embedded fonts to non-special tags, as I describe on page 140 of my EPUB book. This is a really big deal, and means you can forget the ugly hacks previously required to get them to appear. If you want to use any of the 33 font families that come pre-installed in iOS (they are listed with samples in my book), you can simply call them in the CSS rule (skipping @font-face and the special file explained below).

And, and, and that's still not all. The really cool part is that the same code works on the nook too. Ooh, cross-platform font embedding in EPUB. I like it!

Here's how to embed fonts into an EPUB book:

First, add the font to your book files in the normal way, by adding an @font-face statement at the beginning of your CSS, something like this:

@font-face {
font-family: Prophecy Script;
font-style: normal;
font-weight: normal;

That makes the font available. To apply it to your text, you have to add it to one of your styles, also in the CSS:

p.letter {
    font-family: "Prophecy Script";
    font-weight: normal;
    font-style: normal;
    font-size: 1em;
    margin: 1em 0 0 0;

And then make sure your HTML actually uses one of those styles:
<p class="letter">Warren Cty Ky March 11th</p>

The last step is to add a file in your META-INF folder. (If you don't know where that is, my EPUB book will be helpful.) The file is required for Fixed Layout EPUBs, but it looks like Apple is expanding its use.

The file should have a line like this one:

<option name="specified-fonts">true</option>

Put it all together, and you can get something like this:

Embed Fonts in EPUB

Here's what it looks like on the nook (which I wish allowed screenshots!)


The font that I used is pretty similar to my great-great-grandmother's handwriting, and was designed by Michael Tension from Tension Type, and generously made available on Remember to check font licenses before embedding them in your EPUB files.

Finally, if you're curious, you can see the original letter too.

And perhaps more importantly, you can download the sample file (I don't guarantee that it's free of that pesky iTunesMetadata.plist file.)

Friday, April 8, 2011

Catalonia Press: Ebooks and Synergy in Barcelona

A kind reader asked me yesterday if I was all right, mentioning the fact that I hadn't written since March 5th. Wow, time really does go by fast. Every day I promise to write, both in this blog and in my A Year in Barcelona blog, and then the day flies by. Today, I write first.

Catalonia Press
What I've been doing is starting a new publishing house. It occurred to me the other day that the last time I lived in Barcelona, I did the same thing: I created a little publishing house called Página Uno, that specialized in Macintosh-related books in Spanish (we also did one title in Catalan). I think it's something about living between two cultures and three languages that makes me want to figure out how to bring the two (three!) together and share information from each place with folks from the other.

I also think it's curious that all of the things that I've studied in my life keep coming together and recombining in a very zen-like way. I started college at the Wharton School of Business, in their Entrepreneurial Management program. It was a very fancy, prestigious place to be, and I hated it. Not the school, but the classes, and the emphasis on money. As a kid I had tried to start businesses, going door to door wherever we lived selling homemade candles, bread, greeting cards, whatever I could think of. I had a paper route and got a job in the local drugstore as soon as I turned 16. But it was never about the money, it was about creating things, and about creating a business.

So, I was one of a tiny handful of students that year who transferred from Wharton to the liberal arts College of the University of Pennsylvania, where I eventually ended up creating my own major called "Spanish Studies". Fascinated with languages, my course load included Spanish, Catalan, and Basque, as well as courses in literature, history, and sociolinguistics. Ah, but what do you do with that?

I spent my first year out of college (1986-7) as a Spanish teacher, in a private day school in Princeton, New Jersey. I loved the explaining and talking about language, but I hated getting up in front of semi-motivated kids who mostly wanted to know what would be on the test. I remember listening in my car on the way to school one day when they announced that the Olympics would be held in Barcelona in 1992. I still remember gushing about it at school to my students later that day.

In 1987, I decided to move to Barcelona. I was 22 and, just like now, I loved creating things, thinking up business ideas, teaching, and languages. Thanks to a cutting-edge friend, I was already hooked on the Mac.

I found a job the second day after I arrived... in a company that wanted to market their OCR software in the United States and so needed someone to translate the documentation into English. For the next three years, I translated computer programs and the manuals that went with them: stretching and expanding both my languages and my teaching ability. I learned how to go from one language to another, and I observed which manuals made sense and which should have been organized some other way.

All this time, I spoke Catalan almost exclusively; no English and no Spanish. At one point, I even searched out a Spanish conversation partner because there was no one in my circle of friends or work associates that spoke to me in Spanish. Not because they refused, just because it would have been awkward, since we normally spoke in Catalan.

And I remember this deep need to share what I was learning with my friends and family back home. And of course, people here were constantly asking me what America was like. Did we really eat hamburgers all the time? Live in wooden houses? Drive everywhere we went? How *do* you play baseball? It was so interesting to see my country from their eyes. I don't think I ever saw it quite so clearly—even as I knew their vision was limited mostly to what they saw in the movies, and if they were lucky, a visit to the Empire State Building.

In 1990, I started the publishing house, Página Uno, a sort of continuation of the kind of work I did at the first job, but now as an independent company. And again, it combined everything I loved: language, teaching, and computers. We published 14 books in three years, The Macintosh Bible being the first. I carefully chose the books we would publish, focusing on those with an independent voice that advocated for the reader. Thinking back on it, I can see that part of my goal was to share part of my country with people here. I wanted my Catalan and Spanish friends to be able to get the same fresh, opinionated information that I was privy to.

Fast forward to the present (or else I'll lose the few readers who have made it to this point). My husband and I decided to come live in Barcelona this year mostly so our kids could really get a feel for this culture that they also belong to. We have been here since August and will stay until just after the school year ends in July. And my original plan was just to keep doing what I've been doing for the last 17 years: write computer books in simple but not simplistic language.

But after a few months, I found myself pulled back again to the same goal: to serve as a bridge between two cultures that I love, and that somehow both seem to be mine.

It's frustrating, because few outside of this place have ever heard of Catalonia. Barcelona, perhaps, now that it has climbed the rankings of “most popular tourist site”, or whatever. But Catalonia is so much more than Gaudí and beaches. And as much as I bombard my poor Facebook friends with stories about the independence movement, or the literature, or the popular festivals of sweet onion eating or human castle building, or whatever, it often feels like a lonely pursuit.

Sometime in the fall, I happened upon a website by a guy named Matthew Tree. Matthew was born in London but moved to Barcelona around 25 years ago. He had a whole collection of essays on his site that did just what I've always tried to: explain this place to folks who don't know a thing about it. And his writing is great: he's funny and direct and has a great eye for what's beneath the surface.

So, I wrote him and asked if he'd be interested in me helping him compile an electronic book edition of his essays. And he said yes! (What I didn't know, in all my recently-arrived naiveté, was that Matthew is a renowned author around these parts, and appears regularly in print and in radio, and had his own television show for a while. Every time I tell someone I'm working with him, their eyes get big and they ask me how I did it. The answer is, I just asked.)

Catalonia Press is bornOriginally, we were only going to do electronic editions, but people began asking about print. So, I started exploring Print on Demand, thanks to a couple of books (and emails!) by Aaron Shepard, which I'll explain in more detail in a separate post. It's so exciting what can be done nowadays. A week ago, I sent the print files for Matthew's book to Lightning Source in Tennessee, and yesterday I got my first proof: an actual book! It's not perfect yet; I'm afraid I made a few beginner's mistakes (too much outside margin!), but I am thrilled at the possibilities.

I've got a few more projects in the works that I can't talk about quite yet, but I can already feel myself getting closer and closer to my goal: being able to share Catalonia with my English-speaking compatriots at home (and throughout the world)—which somehow miraculously turns out to be a combination of all the things I love to do: languages, books, teaching, and computers.

And so, I've created a new publishing house: Catalonia Press. You'll find information there about Matthew's book, “Barcelona, Catalonia: A View from the Inside”, other projects that I'll be publishing, as well as news and information about Catalonia that I've found on other sites. I hope you find it worthwhile. Because really, there is so much more to this place than Gaudí and beaches (though I'll admit, I'm a particular fan of both).

One added benefit is that everything I learn in this new venture will help me better explain ebooks (the EPUB version of Matthew's book includes video and is already available in the iBookstore while the Kindle version is available from Amazon) and self-publishing in the real world. (I can't wait to explain everything I've learned about video...)

Update:I've just uploaded sample editions of Matthew's book so you can get an idea of what it's like.

More of my books