Skip to main content


Showing posts from May, 2018

UIButton at your Convenience

UIButton is one of those classes where you have to take quite a few steps to set up an instance if you require anything beyond the default. For example, I would like to create a round button with a title, border, background colour, etc. extension UIButton { convenience init(withRadius radius:CGFloat, title:String, titleColor:UIColor, target:UIViewController, selector:Selector, backgroundColor:UIColor, borderColor:UIColor, borderWidth:CGFloat, position:CGPoint) { self.init() self.setTitle(title, for: .normal) self.setTitleColor(titleColor, for: .normal) self.addTarget(target, action: selector, for: .touchDown) self.backgroundColor = backgroundColor let diameter = 2 * radius self.frame = CGRect(x: position.x, y: position.y, width: diameter, height: diameter) self.layer.cornerRadius = radius self.layer.masksToBounds = false self.layer.borderWidth = borderWidth self.layer.borderColor = borderColor

It's time to stop unzipping your EPUBs and start using zip properly on macOS

I'm no zip guru and trust me, if I can use a GUI I will but I've come to realise that I'm wasting a lot of time zipping and unzipping, and while BBEdit does a good job of allowing us to browse EPUBs and edit EPUBs, it has its limitations. Zipping an EPUB There are a variety of ways you might arrive at an EPUB: for example, outputting from an app like InDesign, or Pages, etc., or creating using the save option in epubcheck's expanded validation process  (thanks to bowerbird for  drawing my attention to this ; see also  Jorge's comment on this post ), or manually zipping. My way I usually output from InDesign and then unzip to make fixes and changes. Currently when I need to re-zip, this is the code I use: zip -Xr9D ../book.epub mimetype META-INF OEBPS -x *.DS_Store Note: it is important that prior to running this code you change the current directory you are in, so that you are inside the main folder of the EPUB you wish to zip. The code will then create th

Swift and XML Episode 1: Defining XML using Swift

XML is a very simple language at heart. It contains elements , i.e. those types that are primary to a tag, e.g. <paragraph> or <p>, and which are also used to close tags, e.g. </paragraph> or </p>, it then has attributes , which are secondary but which are also contained within the boundaries of the the tag, e.g. class="regular", which is contained like so <p class="regular">. Finally we have the content , which can be one of two things: text or another element nested within the first. Since everything begins in XML with the top-level element, that's what will start with too: struct Element { let name:String let attributes:[Atrribute] let content:[Content] var self_closing:Bool { return content.isEmpty } } We have now the most important thing, our ability to create instances of an Element, we also have the ability to be aware if the element we are dealing with has no content and will hence need self-

Useful links for the future of EPUB: Specifications, repositories and drafts for 3.0.1 to 3.2

Twitter In Feb. 2017, the merger of the  IDPF with the W3C was announced , at which point the  EPUBZone  twitter feed, run by the  IDPF , went quiet along with the  associated website  for the twitter feed. Outside of the main  W3C one , there doesn't appear to be a replacement for this feed. EPUB 3 Community Group @ W3C On 6 Feb. 2017, the EPUB 3 Community Group was made public and from here we find a link to the EPUB 3 Community Group Work Repository on GitHub. The Community Group page also has an archive of mail that has been exchanged and an RSS Feed. Further, you can view all participants  and join the group yourself, or simply make contact. EPUB 3 Community Group General Repository Contained on the GitHub repository of the Community Group you can find a handy page of links to all docs from EPUB 3.1 backwards . The EPUB 3.1 links take you to W3C pages, while the links to earlier spec, i.e. for EPUB 3.0.1 backwards, take you to the IDPF site. EPUB 3.2 Reposito

EPUB Quick Fixes: Cover image not displaying in Finder or eReader Libraries

If you notice that some of your EPUB files, instead of displaying their cover within macOS Finder, or on an eReader, display this: Or some other generic placeholder identifying the default app in which the file will open, you haven't identified the cover correctly inside your content.opf file. There are two steps to fix this: Within the <manifest> tags of your package (within the opf file), and separate to a declaration of the xhtml of the coverpage you need to identify the image itself that you are using for the cover, e.g.  <item id="CoverImage" href="images/cover_image.jpg" media-type="image/jpeg" properties="cover-image" /> , making sure to include the attribute properties with a value of "cover-image", as shown, along with all the other attributes (of course pointing to your actual image). The first step has fulfilled the require of the EPUB 3 standard but now you also need a line in your <metadat

Digging the Meta in EPUB 3: Using the meta element to extend metadata in EPUB 3, 3.0.1, (not 3.1) and 3.2

One of the main areas addressed in recent changes to the EPUB spec is metadata, which is undeniably an important area. So I'm taking an opportunity here to look briefly but closely at the opportunities we are afforded within the content.opf file for enhancing the depth of our metadata. We can see from the EPUB documentation that the opportunity exists to use ONIX  to denote perhaps the use of a DOI through the meta/refines/property trio (which sometimes becomes a four-piece through the identifying of a scheme, as it does here): <metadata xmlns:dc=""> <dc:identifier id="pub-id">urn:doi:10.1016/j.iheduc.2008.03.001</dc:identifier> <meta refines="#pub-id" property="identifier-type" scheme="onix:codelist5">06</meta> … </metadata> Or to inform the use of an ISBN: <metadata xmlns:dc=""> … <dc:ide