Giving LPub an ability it should already have

The open source LPub is an application that lets you publish instructions for LEGO models from LDraw data, primarily as PDF files. One of its nice additional features is the export of pages as PNG files. While functional, this export doesn’t properly support transparency. Since PNG files do support transparency, this is a bit irritating.

There is UI to set the background, and it has a “none” choice, but using it results in a solid white background instead of a transparent (or, worse in older versions, to a solid black background). Another choice is to use a background image, so you can try to fake out the application by setting the background image to a PNG that is nothing but transparent. The program allows this, but when you export the result, you see the art for each page layered on top of each other (clearly, the app is not clearing a buffer between pages).

Over a year ago, I submitted bugs for both of these problems to the LPub team (here and here). As of this writing, neither of them have been assigned to anyone, much less fixed.

So, I decided to fix it myself. Getting the code downloaded and built in XCode took several hours, and would have taken even longer had I not found the very useful “Compile LPub4 using XCode on Mac OS X” post by Mark from More than just bricks. I had to tweak a couple other things to get it to work, but nothing too drastic.

Knowing nothing about how the code worked and very little about Qt, the GUI package it uses, it took a couple of hours figure out where to make the fix and getting it working properly. The main trick is to add QPixmap.fill(Qt::transparent) in a key place in Gui::exportAs. The rest of the changes are just slight alterations to the UI. Not many changes needed, and maybe I missed something, but seems to work for me.

A patch containing my changes was made against the current head of the project’s CVS tree. I have submitted it to the LPub team. I will update this post if it gets included in a release.

Giving Skim an ability it should already have

I like Skim, an OS X PDF reader, enough to have listed it in my software recommendations. Skim is based on Apple’s PDFKit, just as Apple’s Preview application is. It offers a bunch of note-taking abilities as well, but I don’t use those. The main reason I use Skim over Preview is exactly one feature: in “two page” mode, Skim offers control over treating the first page as a “cover page” and Preview doesn’t. Skim calls this “book mode”.

I read a lot of roleplaying PDFs. Most of these are created using “facing pages”, where there is a clear right and left in the layout. When you read a PDF in two page mode, you want the right page to be on the right and the left on the left. Here is an example, from the Eclipse Phase rulebook:

Two page correct

This particular document has a coverpage, so the above image shows the display of a two-page layout in book mode. If I turn book mode off, I get this:

Two page incorrect

On the other hand, there are many similar roleplaying PDFs that are formatted with more “cover” pages, such that their layouts look correct when book mode is off and incorrect when it is on.

So, Skim can handle all this and Preview can’t. Great. But, while Skim allows you to set a global option for, say “Two Page layout, Book mode on”, it as no facility to remember what settings you selected for a particular document and restore them when you open it. So, I’m constantly readjusting the book mode setting every time I open something. (And, since some rpg documents are built to be single landscape pages, I often have to change two page to single page and back as well.)

Skim does have a feature that remembers what page a document was on, and restores that when you open it, but this fails in two page cases. For example, suppose my global default is “Two Page, Book mode off”. When I open the document pictured above, the layout is off, so I have to turn book mode on. Once done, I move to a particular page (171 in this case) and it looks good:

Two page correct

But, if I turn on the “remember what page I was on” setting, then close this document, when I reopen it, it opens using my global defaults so shows me this:

Two page incorrect

In a tight technical sense, you might consider that the “remember what page I was on” actually worked, but clearly the result was not what I intended. I was viewing pages 170-171 when I closed the document, why did it reopen the document to pages 171-172? The reason is pretty obviously because it does not remember the layout context along with the page.

So, I submitted a feature request to the Skim team to add an option to remember the layout and book mode. Given the existence of the “remember my page” feature, surely building something like this would be trivial. Within about four hours, this bug had been summarily closed, unimplemented, by one of the developers, who gave the following message (in its entirety):

This is not consistent with the current behavior, and not an improvement over it, because it is not consistent with the nature of PDF documents. This was rejected long ago, so I won’t go (again) into more details.

Hmmm. In only two dismissive sentences, this developer managed to sour me on Skim as a whole. Not even a link to this, apparently tortuous, past discussion of the idea. Something.

(I should also mention something else here. When PDFs are created in Acrobat, they can be given properties that instruct a viewer what layout and “book view” to give them on opening. Skim ignores these settings. I submitted a feature request to support these as well. This request was also summarily closed, though for a slightly more legitimate reason: PDFKit apparently doesn’t make those settings visible. On the other hand, its a PDF, not Sanscrit; you could read those settings yourself…)

Anyway, once upon a time, when a developer told you to piss off that was the end of it. Fortunately, Skim is open source. So…

This diff file contains a hack that, when the “remember my page” option is turned on, instructs Skim to remember the book mode and display choice in the same place as the page number (in ~/Library/Preferences/net.sourceforge.skim-app.skim.bookmarks.plist) and restore it next time the file is opened. It seems to work OK in my limited testing.

Having never seen the code before, it took me about 90 minutes to hack the code in this way, which means that someone who actually knows the product likely could have done it (and done it more correctly) in about 15. (For comparison, writing this post took about twice as long.) Normally, I would submit this hack as a patch to the project, but it is pretty clear they are not interested in it. Hopefully it will help you.

LDraw language grammar for TextMate

Data files for LDraw software, such as Bricksmith, are really just text files with a specific syntax, and it can be useful to treat these files as text by opening them in a text editor and manipulating the source directly. This is particularly true if you are using LPub to build instructions for the model, as editing the text directly is the only way to add certain commands to the file.

My text editor of choice, TextMate, supports large numbers of language grammars to provide syntax coloring. It also allows you to add your own. I threw together this one to get a bit of coloring into .ldr files:

   scopeName = 'source.ldr';
   firstLineMatch = '^0 FILE .+\.ldr$';
   fileTypes = ( 'ldr' );
   patterns = (
	name = 'comment.line.ldraw';
        match = '^0 [^!].*$\n?';
	name = 'constant.other.ldraw';
        match = '^0 !.*$\n?';

To install this, pick Bundles→Bundle Editor→Edit Languages… from the menu bar. Click the + at the bottom of the window that comes up to create a new item. Then cut and paste the grammar. This should make your LDraw files go from what is shown on the left, to what is on the right:
Application of TextMate grammar

DropUnlock, DropNuke and Lion

DropNuke and DropUnlock were created solely to solve an odd hiccup in the early days of OS X, a problem that was fixed years ago. Since discontinuing DropNuke, however, I’ve received a handful of mails, replies and messages from people who used DropNuke beyond its original purpose. These have increased since Lion was released because, as PowerPC applications, neither DropNuke nor DropUnlock run under Lion.

Upgrading these applications, however, is not just a matter of recompiling them as Intel apps, because DropNuke and DropUnlock were not created in a traditional way. Creation of these applications took less than an hour, most of which was spent designing the icons. The actual “coding” took less time than it took to write this post. This rapid development time isn’t because I’m a fast coder; it’s because the apps are the output of Wilfredo Sánchez’s utility DropScript. What this application did is take Unix shell scripts (as well as Perl, Python, etc.) and wrap a Mac application around them that, when a file was dropped on the application, would execute the script passing the file as a parameter. Here is the complete code for DropNuke (which has been downloadable from the link at the top of this post since the apps were created):

# OSTYPES    : "****"

for file; do
  location=$(dirname "$file")
  cd "${location}"
  chflags -R nouchg "${file}"
  rm -Rf "${file}"

The DropUnlock code is even simpler, eliminating the last rm call. Looking at the script now, I’m not even sure the first two lines in the loop even need to be there. In any case, you can see there isn’t much to these scripts. The real work is done by DropScript.

Alas, DropScript is a PowerPC application that produces PowerPC applications. Someone hell-bent on building Lion-compatible versions of DropNuke and DropUnlock would need to do the following:

  1. Download the source of the scripts.
  2. Do one of the following:
    1. Wait for Wilfredo Sánchez to update DropScript to support Intel applications.
    2. Download the source code to DropScript and get it working on Intel machines yourself. This might be a simple matter of just getting it to compile and rebuilding it, but I suspect not. It is likely that creating Intel apps from code is quite different than creating PowerPC apps was, back in the day.
  3. Run the resulting Intel-enabled version of DropScript and use it to build DropNuke and DropUnlock.
  4. Optionally, extract the icons from the original apps and apply them to the newly created versions.

Since I consider DropNuke too dangerous to release in the wild again (no more email about stray alias resolution accidentally deleting several terabytes of server data, thank you), and DropUnlock no longer really serves a purpose, I won’t be doing any of the above. All this code is available to you though. If you get it working, please drop me a line.

FUDGE d12 for Dicenomicon

Since Dicenomicon, my preferred dice roller for iOS allows for the creation and (cumbersome) sharing of custom dice definitions, I threw together a definition for a d12 that can be used for FATE games. Odds are the same as standard FUDGE dice (equal chances of “+”, “−” or ” “). They look like this:

Fate d12

You can grab the file here (might need to right click on the link and “Save URL as…”): Fate d12 definition for Dicenomicon.

How to use this file is not explained that well in the app and not that obvious. And way harder than it should be. I’d love to say “go to the obvious screen in Dicenomicon and type in this URL to download it”, but I can’t, because that inexplicably isn’t an option. There are supposed to be several ways to get the file there, but most of them don’t work (the “import from documents” route fails with a “stream had too few bytes” error).

  1. Download the definition file.
  2. On your iOS device, launch Dicenomoicon and hit the info button in the top right.
  3. Tap “Sharing”.
  4. Tap “Web-based Editor”.
  5. You are about to turn your device into a web server, briefly. Make up a username and password and tap “Start Server”.
  6. At the bottom of the screen, your device will display a URL to use. Open a browser on your computer (assuming it is on the same network as the iOS device) and go to that URL. When asked for a username and password, enter the one you just made up.
  7. In the page that comes up, click “Upload File”.
  8. Choose the dice definition you downloaded. Select “Numeric Die” in the “Kind of Upload” popup. Click “Submit”.
  9. Back in Dicenomicon, stop the server and go back to the main settings screen.
  10. Tap “Customize”.
  11. Tap “Custom Dice”. You should see the new “Fa12: Fate d12” in the list.
  12. So back to the customize screen. Tap “Dice Bar”.
  13. Tap “Edit”.
  14. Scroll to the bottom on the list and tap “Add Die…”.
  15. A “d6” will be added to the end of the list. In spite of being in Edit mode, you can’t edit this new die and this point. Tap “Done” instead, even though you are not.
  16. Now tap the new “d6” at the end of the list.
  17. In the screen that comes up, you will see a “d6” in a circle. Double-tap it.
  18. In the dialog that comes up, choose “Custom Numeric Die”.
  19. In the selector that comes up, choose “Fa12: Fate d12”.
  20. Click Done. Go all the way back to the main screen.
  21. At the end of your dice bar, you should see “Fa12”, which you can now use like any other die.

3dConnexion support in Bricksmith 2.5

A few months ago, Allen Smith released Bricksmith 2.5, which contains my code contributions for supporting 3dConnexion three dimensional mice, such as the SpaceNavigator. This code is still a bit experimental, but it allows the faster, 3D positioning of bricks.

The implementation uses Bricksmith’s “quantized” movement, where bricks move in discrete increments based on a (frequently changing) user setting. While this is a bit unusual for 3d mouse control, it fits better with the way Bricksmith works, and how users typically will want bricks to move. A more typical 3d “full-motion” mode can also be used by holding down the control key while moving the 3d mouse. (This is slightly similar to applications that use “snap to grid” features, but allow the grid to be ignored by holding down the control key.)

I had intended to include a video in this post demonstrating how the mouse worked with Bricksmith; however, since 2.5 was released in April and I haven’t made such a video yet, it’s a good bet that I won’t in the next six months either. So, you’ll just have to trust me that it is totally awesome.

If you are one of the few that both uses a 3dConnexion mouse and Bricksmith, I’d love to hear how it works for you. Heck, I’d love to hear that you even exist.

DropNuke discontinued

DropUnlockWhen it was first released, Mac OS X had an odd problem: it allowed a user to create files that they couldn’t delete. This wound up having to do with a bug between way OS 9 could “lock” files colliding with the way OS X did something similar. You could fix this on the command line, but I got sick of doing so, so built some quick utilities to handle this just by dragging and dropping.

One of these, DropUnlock, is still available, but today DivNull is officially discontinuing DropNuke. As you would expect with something named “DropNuke”, this version of the utility was pretty much the final option, a scorched earth way of permanently dealing with an undeletable file (using not only chflags calls, but also rm -rf). As you can tell by the warnings on its old download page, you could wreak a lot of havoc with DropNuke if you didn’t know what you are doing.

Since the “undeletable file” problem has been addressed in subsequent versions of OS X, and DropUnlock still exists for people still using the old version, it seems smarter to remove DropNuke, just in case.

Update: The technology on which DropNuke and DropUnlock was built doesn’t run on modern versions of OS X, so neither of these scripts will work any longer.

Altering NFL Gamecenter to use entire screen

The NFL’s Gamecenter allows tracking of games that you can’t see on TV due to dumb networks or socialist rules. If you have more than one person viewing the game, what you might like to do is put a laptop on your coffee table to show one game, while everyone watches another. Unfortunately, the layout of the page that tracks games does not lend itself to this. It has at least the following problems:

  • Default fonts are too small.
  • Using the “larger font” menu choices improves some small fonts, but not others. Two of the main components of this screen are Flash files, so do not respond to this switch.
  • Advertisements take up a good portion of the prime real estate of the screen.
  • The screen doesn’t scale when you make your window wider, instead using a fixed-width, centered layout.
  • Large sections of the screen are essentially useless for tracking the game (such as the header), meaning you need to scroll carefully to optimize viewing of the interesting stuff.

On a 15″ MacBook Pro (1440×900), with a maximized screen (dock on the right), the result looks like this:


Fortunately, the HTML markup of this page is reasonably good for altering (mostly because all the divs have ids), so it is possible to override the CSS for the page to fix most of these problems. Some browsers allow you to override the style of a page out of the box, but the process for doing this is fairly obscure for Firefox. A much more user friendly method for overriding a sites CSS using Firefox is to use a plugin called Stylish. This adds an icon in the lower right of your browser window that allows you to muck with the styles of the page you are viewing.

When you use CSS to alter a page, you are somewhat restricted by how good or bad the HTML of the page you are trying to alter is. While you can get extremely cute with CSS selectors, sometimes there just isn’t anything you can do. Fortunately, most of the things you’d like to do to the Gamecenter site are possible. There are a lot of ways you could hack it, but what follows will alter the game tracking pages to look something like this:


To do this in Firefox, do the following:

  1. Install Stylish.
  2. Navigate to the NFL Gamecenter page of the game you want to see.
  3. Click on the Stylish icon in the lower right of the browser window.
  4. In the menu that pops up, select “Write new style → For this URL…”.
  5. In the dialog that comes up:
    1. Name the style something like “NFL Gamecenter”.
    2. Add some tags, such as “NFL”.
    3. Replace the script with the code below.
  6. Click “Save”.

Now, any time you go to the Gamecenter part of the NFL site, you’ll see this hacked version. If you need to turn this off, you can click on the Stylish icon and select “Turn all styles off”. Also, unless you are using the exact screen size mentioned, you may need to tweak the CSS to match your screen. If you know CSS, there is nothing particularly surprising in the code of this alteration. Also, there is nothing in the code that is tied to Stylish itself; the same CSS should work for any other way of overriding the page style that you can come up with.

@namespace url(;

@-moz-document url-prefix('') {

/* Hide extra headers and stuff */
#hd-micro-nav-list, #hd-micro-nav-list, #tl, #header-content,, 
#gc-shop, #gc-discuss, #gc-track-search-ads, #gc-rr, div.w, div.t, #br, #gc-photos {
  display: none !important; 

#hd {
  width: 1000px !important;

div.c {
  background: transparent !important;

/* Hide advertisements */
div#dc-header {
  display: none;

/* Left justify everything by default */
#com-nfl-doc, #hd {
  text-align: left !important;

#doc {
  margin: 0 0 !important;

#doc-wrap {
  padding-top: 0px !important;

#hd {
  height: 70px !important;

/* Scale the Flash file of the game scores, to make the font larger and 
    reach across the screen. */
#hd-scorestrip-swf {
  height: 70px !important;
  width: 1380px !important;

#gc-team-stats {
  position: fixed !important;
  top: 70px !important;
  left: 990px !important;
  width: 380px !important;
  height: 280px !important;
  overflow: visible !important;
  z-index: 300 !important;
  padding: 5px !important;
  background-color: white !important;
  border: solid 1px #ddd !important;
  font-size: 14px;

  position: fixed !important;
  top: 360px !important;
  left: 990px !important;
  width: 380px !important;
  height: 73px !important;
  overflow: visible !important;
  z-index: 300 !important;
  padding: 5px !important;
  background-color: white !important;
  border: solid 1px #ddd !important;

#gc-last-score h2 {
  width: 380px;

div.widget-inner {
  background-repeat: repeat-x !important;

#gc-current-drive {
  position: fixed !important;
  top: 450px !important;
  left: 6px !important;
  width: 760px !important;
  height: 335px !important;
  overflow: visible !important;
  z-index: 300 !important;
  padding: 5px !important;
  background-color: white !important;
  border: solid 1px #ddd !important;
  font-size: 16px !important;

#gc-current-drive-window {
  width: 750px !important;
  height: 320px !important;

#gc-current-drive-scroll-bar {
  height: 320px !important;

#gc-current-drive-scroll-track {
  height: 300px !important;

#gc-top-performers {
  position: fixed !important;
  top: 450px !important;
  left: 785px !important;
  width: 575px !important;
  height: 335px !important;
  overflow: visible !important;
  z-index: 300 !important;
  padding: 5px !important;
  background-color: white !important;
  border: solid 1px #ddd !important;
  font-size: 16px !important;

div.span-4 {
  width: 280px !important;


The makers of Stylish allow uploading of scripts like this; however, their “new account” feature is broken as of this writing. Once this is corrected, this page will be updated with a link to the “official” version of this script, which should make installation even easier. It has been posted here: Stylish script for NFL Gamecenter