<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Blog &#171; Zoril</title>
	<atom:link href="http://zoril.co.uk/wp/feed/" rel="self" type="application/rss+xml" />
	<link>http://zoril.co.uk/wp</link>
	<description>You&#039;ll regret looking</description>
	<lastBuildDate>Tue, 17 Apr 2012 23:30:11 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>An Almost Accurate Set of Scales</title>
		<link>http://zoril.co.uk/wp/2012/04/an-almost-accurate-set-of-scales/</link>
		<comments>http://zoril.co.uk/wp/2012/04/an-almost-accurate-set-of-scales/#comments</comments>
		<pubDate>Tue, 17 Apr 2012 23:30:11 +0000</pubDate>
		<dc:creator>Zoril</dc:creator>
				<category><![CDATA[News]]></category>
		<category><![CDATA[diy]]></category>

		<guid isPermaLink="false">http://zoril.co.uk/wp/?p=745</guid>
		<description><![CDATA[<p class="wp-caption-text">DIY Scales</p> <p>I&#8217;ve written &#8220;scales&#8221; once and it&#8217;s already stopped looking correct.</p> <p>A frequently encountered situation: you&#8217;re on holiday trying to bake a cake, when you realise you have no scales with which to weigh out the ingredients. I have no idea how most people in that situation would react, but I do know <span style="color:#777"> . . . <p><p>&#8594; Continue reading <a href="http://zoril.co.uk/wp/2012/04/an-almost-accurate-set-of-scales/">An Almost Accurate Set of Scales</a></span>]]></description>
			<content:encoded><![CDATA[<div class="wp-caption alignleft" style="width: 270px"><a href="http://zoril.co.uk/gallery/37/30/d5744b_diyscales.jpg"><img alt="DIY Scales" src="http://zoril.co.uk/gallery/37/30/d5744b_diyscales.jpg" title="DIY Scales" width="260" height="643" /></a><p class="wp-caption-text">DIY Scales</p></div>
<p>I&#8217;ve written &#8220;scales&#8221; once and it&#8217;s already stopped looking correct.</p>
<p>A frequently encountered situation: you&#8217;re on holiday trying to bake a cake, when you realise you have no scales with which to weigh out the ingredients.<br />
I have no idea how most people in that situation would react, but I do know how I would react: build a set of scales out of stuff laying around.</p>
<p>Would you like to build a set just like these? Of course you would.</p>
<p>You&#8217;ll be needing:</p>
<ul style="list-style-position:inside;">
<li>The hook on the back of a door</li>
<li>A coathanger, preferably with skirt clips</li>
<li>A length of string</li>
<li>A couple of (preferably matching) carrier bags</li>
<li>Some kind of tape that doesn&#8217;t leave marks, I used electrical insulating tape</li>
<li>A long, straight, lightweight rigid thing, I used the top part of some cable trunking</li>
</ul>
<p>Once you&#8217;ve taped, tied and hung it all together as shown in the photo, you&#8217;ll have a workable set of scales.</p>
<p>Finer accuracy can be gained by lengthening the long hanging thing, let&#8217;s call it a <em>drop-rod</em>.</p>
]]></content:encoded>
			<wfw:commentRss>http://zoril.co.uk/wp/2012/04/an-almost-accurate-set-of-scales/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Sexy French Ducks and MetroTwit*</title>
		<link>http://zoril.co.uk/wp/2012/02/sexy-french-ducks-and-metrotwit/</link>
		<comments>http://zoril.co.uk/wp/2012/02/sexy-french-ducks-and-metrotwit/#comments</comments>
		<pubDate>Sat, 18 Feb 2012 20:43:45 +0000</pubDate>
		<dc:creator>Zoril</dc:creator>
				<category><![CDATA[News]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[duck]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[twitter]]></category>
		<category><![CDATA[windows]]></category>

		<guid isPermaLink="false">http://zoril.co.uk/wp/?p=700</guid>
		<description><![CDATA[<sub>* I don't know how the MetroTwit guys would feel about being grouped like that, but hey, my blog, free advertising.</sub></p> <p>I recently received my first French spam comment, been a while since I did any French but I'm fairly certain it's offering drugs for the floppy gentleman. It also mentions a d<strong>u</strong>ck. I can't work that one out, thought it  <span style="color:#777"> . . . <p><p>&#8594; Continue reading <a href="http://zoril.co.uk/wp/2012/02/sexy-french-ducks-and-metrotwit/">Sexy French Ducks and MetroTwit*</a></span>]]></description>
			<content:encoded><![CDATA[<p><div id="attachment_708" class="wp-caption alignleft" style="width: 310px"><a href="http://zoril.co.uk/wp/wp-content/uploads/2012/02/duck.jpg" title="Duck"><img src="http://zoril.co.uk/wp/wp-content/uploads/2012/02/duck-300x300.jpg" alt="Duck" title="Duck" width="300" height="300" class="size-medium wp-image-708" /></a><p class="wp-caption-text">Probably Not a French Duck</p></div><br />
I recently received my first French spam comment, been a while since I did any French but I&#8217;m fairly certain it&#8217;s offering drugs for the floppy gentleman. It also mentions a d<strong>u</strong>ck. I can&#8217;t work that one out, thought it might be slang, and it is.. for newspaper. That&#8217;s the great thing about spam, it can actually be amusing at times and cause me to post photos of ducks.</p>
<p>Enough about that though, on to.. Twitter. That horrific thing that isn&#8217;t as bad as it always seemed.</p>
<p>Up &#8217;til now I&#8217;ve been mainly using TweetDeck, but it hasn&#8217;t been terribly good since Twitter bought it. My main issue was the 30+ second delay between the new tweet pop-up disappearing and the tweet being added to the main window. Quite a problem when you&#8217;re halfway through reading one.</p>
<p>After finding a rather useless selection of &#8216;top 10&#8242; style lists, and websites offering clients you&#8217;d regret putting your password in, I came across <a href="http://www.metrotwit.com" target="_blank" title="MetroTwit">MetroTwit</a>. The MetroTwit developers (being semi-famous Microsoft geeks) really know what they&#8217;re doing when it comes to writing applications for Windows**.</p>
<p>It does have an advert in if you don&#8217;t want to pay the (too high for me) price for the pro version. Once you invert the colours and get over the initially blinding pink/green/blue bits everywhere, it&#8217;s quite nice. It&#8217;s still in development so I expect they&#8217;ll sort out the inconsistencies like half the dialogs having back/cancel buttons and half requiring a click elsewhere.</p>
<p>Other than that, it&#8217;s very configurable, including notifications on a monitor of your choice (yay). Also potentially a taste of what Windows 8 is going to be like. (Seriously, if Windows 8 makes me transition to a whole new screen every time I want to consider launching a program, I won&#8217;t be using it.)</p>
<p>My most common problem, as touched upon, is the close buttons. Here&#8217;s a pop-up/dialog/window.</p>
<div id="attachment_722" class="wp-caption aligncenter" style="width: 692px"><a href="http://zoril.co.uk/wp/wp-content/uploads/2012/02/metrotwitdialog.jpg"><img src="http://zoril.co.uk/wp/wp-content/uploads/2012/02/metrotwitdialog_clip.jpg" alt="" title="A MetroTwit Popup Window" width="682" height="327" class="size-full wp-image-722" /></a><p class="wp-caption-text">A MetroTwit Popup Window</p></div>
<p>Now, mystery reader, I don&#8217;t know about you, but when I want to close a window, I&#8217;m somewhat used to an &#8216;X&#8217; in the top right corner. Not only is there no &#8216;X&#8217;, there&#8217;s a button which causes a delay while you wait for a new column to devour your API calls before you can delete it.</p>
<p>Closing the window requires clicking on the window behind it, in Windows.. that usually brings it to the foreground, not causes the one you&#8217;re using to close. If this is how metro apps are <em>supposed</em> to work then god help us all. &#8220;Windows <del>2D</del> 8, now with 100% less depth!&#8221;.</p>
<p>That said, if you&#8217;re looking for a Windows desktop Twitter client, give <a href="http://www.metrotwit.com" target="_blank" title="MetroTwit">MetroTwit</a> a go, it&#8217;s (probably) only going to improve and it&#8217;s already quite good.</p>
<p><sub>* I don&#8217;t know how the MetroTwit guys would feel about being grouped like that, but hey, my blog, free advertising.</sub></p>
<p><sub>** Windows is currently my main operating system, I play too many games and use too many resource intensive Windows only programs for it not to be. However I usually have a virtual machine with Fedora running fullscreen on one monitor. My laptop was actually running Linux until recently, then the graphics chip caught fire and things started flickering and sparking.</sub></p>
]]></content:encoded>
			<wfw:commentRss>http://zoril.co.uk/wp/2012/02/sexy-french-ducks-and-metrotwit/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>3D Modelling, Take 2</title>
		<link>http://zoril.co.uk/wp/2012/02/3d-modelling/</link>
		<comments>http://zoril.co.uk/wp/2012/02/3d-modelling/#comments</comments>
		<pubDate>Fri, 10 Feb 2012 23:07:54 +0000</pubDate>
		<dc:creator>Zoril</dc:creator>
				<category><![CDATA[Images]]></category>
		<category><![CDATA[News]]></category>
		<category><![CDATA[3D]]></category>

		<guid isPermaLink="false">http://zoril.co.uk/wp/?p=685</guid>
		<description><![CDATA[<p> It&#8217;s been a few years since I last played with 3D modelling. Back then it was mostly rendering movies of furry objects exploding. It was fun, and intermingled with more serious attempts. Appropriately for this time of year, here&#8217;s a snowman. There were also some opening books I was working on for an interactive <span style="color:#777"> . . . <p><p>&#8594; Continue reading <a href="http://zoril.co.uk/wp/2012/02/3d-modelling/">3D Modelling, Take 2</a></span>]]></description>
			<content:encoded><![CDATA[<p><img src="http://zoril.co.uk/wp/wp-content/uploads/2012/02/snowmn.png" alt="3D Snowman" title="3D Snowman" width="118" height="200" class="alignleft size-full wp-image-686" /> It&#8217;s been a few years since I last played with 3D modelling. Back then it was mostly rendering movies of furry objects exploding. It was fun, and intermingled with more serious attempts. Appropriately for this time of year, here&#8217;s a snowman. There were also some opening books I was working on for an interactive website.</p>
<p>I&#8217;ve recently decided to get back into it, and do things properly. Here&#8217;s a screenshot of my first real attempt at a creation. It may be only be a headless dog, and it may be using a lot more polygons than it needs, but it did let me learn my way around the interface. It has even got a skeleton in, so bits of it move almost realistically. I modelled it standing, the sitting position is all done by the skeletal structure inside. Rather funky really.</p>
<p>Texturing should be fun, it went wrong last time I tried. Anyway, here&#8217;s that screenshot:</p>
<p><img src="http://zoril.co.uk/wp/wp-content/uploads/2012/02/3dbones-633x480.jpg" alt="3D Attempt 1" title="3D Attempt 1" width="633" height="480" class="aligncenter size-large wp-image-692" /></p>
]]></content:encoded>
			<wfw:commentRss>http://zoril.co.uk/wp/2012/02/3d-modelling/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>P-P-Pick up a Python</title>
		<link>http://zoril.co.uk/wp/2012/01/p-p-pick-up-a-python/</link>
		<comments>http://zoril.co.uk/wp/2012/01/p-p-pick-up-a-python/#comments</comments>
		<pubDate>Tue, 17 Jan 2012 01:30:08 +0000</pubDate>
		<dc:creator>Zoril</dc:creator>
				<category><![CDATA[News]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[aws]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://zoril.co.uk/wp/?p=681</guid>
		<description><![CDATA[<p></p> <p>I&#8217;m going to venture into the world of Python. I&#8217;ve used the language in incredibly minimal ways before, but I want to have a play with the Django web framework, and so must learn Python properly.</p> <p>I&#8217;m also having a play with Amazon Web Services, because I get to play with a virtual machine <span style="color:#777"> . . . <p><p>&#8594; Continue reading <a href="http://zoril.co.uk/wp/2012/01/p-p-pick-up-a-python/">P-P-Pick up a Python</a></span>]]></description>
			<content:encoded><![CDATA[<p><img src="/gallery/created/pickupapython.png" alt="Pick up a Python" /></p>
<p>I&#8217;m going to venture into the world of <a href="http://python.org" target="_blank" title="Python.org">Python</a>. I&#8217;ve used the language in incredibly minimal ways before, but I want to have a play with the <a href="http://www.djangoproject.com" target="_blank" title="Django">Django</a> web framework, and so must learn Python properly.</p>
<p>I&#8217;m also having a play with <a href="http://aws.amazon.com/" target="_blank" title="Amazon Web Services">Amazon Web Services</a>, because I get to play with a virtual machine with a decent internet connection and can pretty much do what I like with it. This site is on shared web hosting, so there&#8217;s no opening ports, running services or advanced configuration. Unlike an EC2 micro though, it won&#8217;t suddenly throttle the site if it gets busy.</p>
<p>The illustration up there may not be entirely accurate.. having never actually held a snake, or looked up images of a python before drawing it. In paint.</p>
]]></content:encoded>
			<wfw:commentRss>http://zoril.co.uk/wp/2012/01/p-p-pick-up-a-python/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A Wild Menu Appears</title>
		<link>http://zoril.co.uk/wp/2012/01/wildmenu/</link>
		<comments>http://zoril.co.uk/wp/2012/01/wildmenu/#comments</comments>
		<pubDate>Wed, 11 Jan 2012 01:12:55 +0000</pubDate>
		<dc:creator>Zoril</dc:creator>
				<category><![CDATA[News]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[opera]]></category>

		<guid isPermaLink="false">http://zoril.co.uk/wp/?p=669</guid>
		<description><![CDATA[<p>Got the oddest random menu popup just now. I went to Google Mail (which has a horrendous web interface these days but that&#8217;s another post) and hit login-with-password-saved-in-browser (Opera, by the way). The choice of saved accounts came up, as did what looked like a very small context menu with two items on, one with <span style="color:#777"> . . . <p><p>&#8594; Continue reading <a href="http://zoril.co.uk/wp/2012/01/wildmenu/">A Wild Menu Appears</a></span>]]></description>
			<content:encoded><![CDATA[<p>Got the oddest random menu popup just now.<br />
I went to Google Mail (which has a horrendous web interface these days but that&#8217;s another post) and hit login-with-password-saved-in-browser (Opera, by the way). The choice of saved accounts came up, as did what looked like a very small context menu with two items on, one with the TF2 icon called Potato Sack, and one with Kotaku&#8217;s icon called Final Fantasy XIII. I have absolutely no idea what it came from, I&#8217;d say Steam.. but the potato sack is quite old and no idea about FFXIII.</p>
<p>Anyhow, here&#8217;s a screenshot.</p>
<div id="attachment_670" class="wp-caption aligncenter" style="width: 650px"><a href="http://zoril.co.uk/wp/wp-content/uploads/2012/01/passwordpopup.jpg"><img src="http://zoril.co.uk/wp/wp-content/uploads/2012/01/passwordpopup-640x426.jpg" alt="What is this?" title="Odd Menu Popup" width="640" height="426" class="size-large wp-image-670" /></a><p class="wp-caption-text">I don&#039;t know what this menu is or why it&#039;s there</p></div>
<p>It comes up when I press &#8216;down&#8217; in any field the browser thinks it has a stored password for. Choosing one adds that text to the field.</p>
<p><strong>Mystery Solved:</strong><br />
They&#8217;re <a "href=http://help.opera.com/Windows/11.60/en/notes.html" target="_blank" title="Opera: Notes">notes</a> I must have created accidentally, although I can&#8217;t see how useful it is to have them available in remembered password fields but not normal fields.</p>
]]></content:encoded>
			<wfw:commentRss>http://zoril.co.uk/wp/2012/01/wildmenu/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>2012</title>
		<link>http://zoril.co.uk/wp/2012/01/2012/</link>
		<comments>http://zoril.co.uk/wp/2012/01/2012/#comments</comments>
		<pubDate>Sun, 01 Jan 2012 16:35:44 +0000</pubDate>
		<dc:creator>Zoril</dc:creator>
				<category><![CDATA[Events]]></category>
		<category><![CDATA[News]]></category>

		<guid isPermaLink="false">http://zoril.co.uk/wp/2012/01/2012/</guid>
		<description><![CDATA[<p>Twenty-Twelve (Twe-Twe..), year of the surprised lion. Actually in terms of zodiac years it&#8217;s apparently time for a dragon. Big roaring, fire breathing lizard thing.</p> ]]></description>
			<content:encoded><![CDATA[<p>Twenty-Twelve (Twe-Twe..), year of the surprised lion. Actually in terms of zodiac years it&#8217;s apparently time for a dragon. Big roaring, fire breathing lizard thing.</p>
]]></content:encoded>
			<wfw:commentRss>http://zoril.co.uk/wp/2012/01/2012/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Opera 11.60 Address Bar</title>
		<link>http://zoril.co.uk/wp/2011/12/opera-11-60-address-bar/</link>
		<comments>http://zoril.co.uk/wp/2011/12/opera-11-60-address-bar/#comments</comments>
		<pubDate>Thu, 08 Dec 2011 23:53:52 +0000</pubDate>
		<dc:creator>Zoril</dc:creator>
				<category><![CDATA[News]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[opera]]></category>

		<guid isPermaLink="false">http://zoril.co.uk/wp/?p=648</guid>
		<description><![CDATA[<p>The most recent release of the Opera web browser seems to have taken a strange turn.</p> <p>As expected, there are two text boxes, the address bar, and the search box. In Opera, you can set keywords for your search engines, which allows you to search using a specific engine from the address bar, e.g. &#8220;g <span style="color:#777"> . . . <p><p>&#8594; Continue reading <a href="http://zoril.co.uk/wp/2011/12/opera-11-60-address-bar/">Opera 11.60 Address Bar</a></span>]]></description>
			<content:encoded><![CDATA[<p>The most recent release of the Opera web browser seems to have taken a strange turn.</p>
<p>As expected, there are two text boxes, the address bar, and the search box. In Opera, you can set keywords for your search engines, which allows you to search using a specific engine from the address bar, e.g.<br />
&#8220;g kittens&#8221; for a Google search, if it is enabled, you also get search suggestions as you type<br />
&#8220;g k&#8221; <em>kohls, kayak, kmart</em><br />
&#8220;g ki&#8221; <em>kindle, kindle fire, kim kardashian wedding</em><br />
and so on.</p>
<p><img src="http://zoril.co.uk/wp/wp-content/uploads/2011/12/addressbarkeyword.jpg" alt="" title="Suggestions using a keyword" width="700" height="124" class="aligncenter size-full wp-image-663" /></p>
<p>In versions prior to 11.60, depending on what options were selected, the address bar would provide results from your history and/or bookmarks as you typed, an incredibly useful feature.</p>
<p>In version 11.60, that still happens. In addition to that, it will no longer wait for a keyword, anything typed starts bringing in suggestions from the default search engine, Google in this case. If that wasn&#8217;t an annoying enough feature on its own, Opera then places these results <em>above</em> the bookmark/history results. I can no longer type three or so characters, hit down a couple of times and have the bookmark I wanted, I have to wade through a pile of search suggestions I have no interest in.</p>
<p><img src="http://zoril.co.uk/wp/wp-content/uploads/2011/12/addressbarsuggests.jpg" alt="" title="I only wanted my bookmarks" width="700" height="167" class="aligncenter size-full wp-image-664" /></p>
<p>One solution was to disable search suggestions entirely. This leaves keyword searches and search box searches similarly affected, so not terribly useful.</p>
<p>Another was to add a dummy search engine so there can&#8217;t be suggestions. Although this requires it to be set as the default one, adding an extra step to getting suggestions in the search box (changing the selected search engine to, say, Google before typing the query).</p>
<p>The fix I&#8217;m currently using is to disable &#8220;<a href="opera:config#UserPrefs|AddressbarContentSearch" target="_blank">Address Bar Content Search</a>&#8221; in the advanced configuration. Remember to click save and restart the browser after though.</p>
<p>It seems to do the trick, thanks go to <a href="http://my.opera.com/community/forums/findpost.pl?id=11002482" target="_blank">artmil over in the Opera forums</a></p>
<p>Ah, so close. This still isn&#8217;t perfect. Here are some screenshots of my address bar. It remembered that I wanted search suggestions and is now going to forcefully display them however irrelevant they are in regards to what I&#8217;m typing, for as long as I keep this tab.</p>
<p><img src="http://zoril.co.uk/wp/wp-content/uploads/2011/12/addressbarmemory.jpg" alt="" title="Opera&#039;s address bar remembers" width="700" height="503" class="aligncenter size-full wp-image-661" /></p>
]]></content:encoded>
			<wfw:commentRss>http://zoril.co.uk/wp/2011/12/opera-11-60-address-bar/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sorting in Java &#8211; Letters First</title>
		<link>http://zoril.co.uk/wp/2011/11/sorting-in-java-letters-first/</link>
		<comments>http://zoril.co.uk/wp/2011/11/sorting-in-java-letters-first/#comments</comments>
		<pubDate>Wed, 16 Nov 2011 01:26:26 +0000</pubDate>
		<dc:creator>Zoril</dc:creator>
				<category><![CDATA[News]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[sorting]]></category>

		<guid isPermaLink="false">http://zoril.co.uk/wp/?p=603</guid>
		<description><![CDATA[<p>In my last post there was some Java code for bundling up PDF files. In this post, it&#8217;s back!</p> <p>This time with the focus being on the comparison method of the filenames. The problem with the default sort is that a number will always be ranked higher than a letter.</p> <p>The files I&#8217;m trying to <span style="color:#777"> . . . <p><p>&#8594; Continue reading <a href="http://zoril.co.uk/wp/2011/11/sorting-in-java-letters-first/">Sorting in Java &#8211; Letters First</a></span>]]></description>
			<content:encoded><![CDATA[<p>In my last post there was some Java code for bundling up PDF files. In this post, it&#8217;s back!</p>
<p>This time with the focus being on the comparison method of the filenames. The problem with the default sort is that a number will always be ranked higher than a letter.</p>
<p>The files I&#8217;m trying to join are named hierarchically, like this:</p>
<style type="text/css">
ul.ind {padding:0;list-style-type:circle;}
li.hig {background-color:#ccc;}
</style>
<ul>
<li>Page 0
<ul class="ind">
<li>Page 0.0
<ul class="ind">
<li>Page 0.0.Llama</li>
</ul>
</li>
<li>Page 0.1
<ul class="ind">
<li>Page 0.1.Snake</li>
</ul>
</li>
<li>Page 0.2
<ul class="ind">
<li>Page 0.2.Fish</li>
</ul>
</li>
</ul>
</li>
<li class="hig1">Page 1
<ul class="ind">
<li>Page 1.0
<ul class="ind">
<li>Page 1.0.Carrot</li>
<li>Page 1.0.Parsnip</li>
</ul>
</li>
<li style="border:1px solid red;">Page 1.1
<ul class="ind">
<li>Page 1.1.0
<ul class="ind">
<li>Page 1.1.0.Honeydew</li>
<li>Page 1.1.0.Watermelon</li>
</ul>
</li>
<li>Page 1.1.1
<ul class="ind">
<li>Page 1.1.1.Bacon</li>
<li>Page 1.1.1.Sausage</li>
</ul>
</li>
<li class="hig">Page 1.1.Lemon</li>
</ul>
</li>
<li>Page 1.2
<ul class="ind">
<li>Page 1.2.Lamp</li>
</ul>
</li>
</ul>
</li>
<li>Page 2
<ul class="ind">
<li>Page 2.0</li>
<ul class="ind">
<li>Page 2.0.Golf</li>
<li>Page 2.0.Rugby</li>
<li>Page 2.0.Skiing</li>
</ul>
</li>
</ul>
</li>
</ul>
<p>There are title pages for categories and subcategories, and information pages for items within those categories. The problem with standard naming and the naming of these files can be demonstrated by the position of the highlighted item &#8216;lemon&#8217;. It is a direct descendant of Page 1.1. Yet It ends up positioned behind the subcategories because it ceases to have a numeric name.</p>
<p>This is the updated Merge.java file that forces letters to come before numbers, yet still keep them sorted correctly within themselves.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.File</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.Arrays</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.Comparator</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.pdfbox.util.PDFMergerUtility</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Merge <span style="color: #009900;">&#123;</span>
   <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> args<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
           <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>args.<span style="color: #006633;">length</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">0</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                Merge m <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Merge<span style="color: #009900;">&#40;</span>args<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span>, args<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Usage: &quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Merge inputFolderName outputFileNamePrefix&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
   <span style="color: #009900;">&#125;</span>
&nbsp;
   <span style="color: #000000; font-weight: bold;">public</span> Merge<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> from, <span style="color: #003399;">String</span> to<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
      <span style="color: #666666; font-style: italic;">// load util</span>
      PDFMergerUtility ut <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> PDFMergerUtility<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
      <span style="color: #666666; font-style: italic;">// get files</span>
      <span style="color: #003399;">File</span> dir <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">File</span><span style="color: #009900;">&#40;</span>from<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> pdfs <span style="color: #339933;">=</span> dir.<span style="color: #006633;">list</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
      <span style="color: #003399;">Arrays</span>.<span style="color: #006633;">sort</span><span style="color: #009900;">&#40;</span>pdfs, <span style="color: #000000; font-weight: bold;">new</span> AlphaComparator<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
      <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> i<span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> i<span style="color: #339933;">&lt;</span>pdfs.<span style="color: #006633;">length</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
         <span style="color: #666666; font-style: italic;">// add to pdf</span>
         ut.<span style="color: #006633;">addSource</span><span style="color: #009900;">&#40;</span>from <span style="color: #339933;">+</span> <span style="color: #003399;">File</span>.<span style="color: #006633;">separator</span> <span style="color: #339933;">+</span> pdfs<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
&nbsp;
      <span style="color: #666666; font-style: italic;">// save</span>
      ut.<span style="color: #006633;">setDestinationFileName</span><span style="color: #009900;">&#40;</span>to <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;_out.pdf&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
      <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
         ut.<span style="color: #006633;">mergeDocuments</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">Exception</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
         e.<span style="color: #006633;">printStackTrace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
   <span style="color: #009900;">&#125;</span>
&nbsp;
   <span style="color: #000000; font-weight: bold;">class</span> AlphaComparator <span style="color: #000000; font-weight: bold;">implements</span> <span style="color: #003399;">Comparator</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">int</span> compare<span style="color: #009900;">&#40;</span><span style="color: #003399;">Object</span> o1, <span style="color: #003399;">Object</span> o2<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
         <span style="color: #003399;">String</span> s1 <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span><span style="color: #009900;">&#41;</span>o1<span style="color: #339933;">;</span>
         <span style="color: #003399;">String</span> s2 <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span><span style="color: #009900;">&#41;</span>o2<span style="color: #339933;">;</span>
&nbsp;
         <span style="color: #000066; font-weight: bold;">char</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> c1 <span style="color: #339933;">=</span> s1.<span style="color: #006633;">toCharArray</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
         <span style="color: #000066; font-weight: bold;">char</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> c2 <span style="color: #339933;">=</span> s2.<span style="color: #006633;">toCharArray</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
         <span style="color: #000000; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> i<span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> i<span style="color: #339933;">&lt;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>c1.<span style="color: #006633;">length</span> <span style="color: #339933;">&lt;</span> c2.<span style="color: #006633;">length</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">?</span> c1.<span style="color: #006633;">length</span> <span style="color: #339933;">:</span> c2.<span style="color: #006633;">length</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>c1<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> c2<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
               <span style="color: #666666; font-style: italic;">// both same, skip</span>
               <span style="color: #000000; font-weight: bold;">continue</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
               <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">Character</span>.<span style="color: #006633;">isDigit</span><span style="color: #009900;">&#40;</span>c1<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                  <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">Character</span>.<span style="color: #006633;">isDigit</span><span style="color: #009900;">&#40;</span>c2<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                     <span style="color: #666666; font-style: italic;">// both numeric</span>
                     <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #009900;">&#40;</span>c1<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span> <span style="color: #339933;">&gt;</span> c2<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">?</span> <span style="color: #cc66cc;">1</span> <span style="color: #339933;">:</span> <span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>   
                  <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
                     <span style="color: #666666; font-style: italic;">// number vs a letter, promote letter</span>
                     <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
                  <span style="color: #009900;">&#125;</span>
               <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">Character</span>.<span style="color: #006633;">isDigit</span><span style="color: #009900;">&#40;</span>c2<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                  <span style="color: #666666; font-style: italic;">// letter vs number, promote letter</span>
                  <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
               <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
                  <span style="color: #666666; font-style: italic;">// both letters</span>
                  <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #009900;">&#40;</span>c1<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span> <span style="color: #339933;">&gt;</span> c2<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">?</span> <span style="color: #cc66cc;">1</span> <span style="color: #339933;">:</span> <span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
               <span style="color: #009900;">&#125;</span>
            <span style="color: #009900;">&#125;</span>
         <span style="color: #009900;">&#125;</span>
         <span style="color: #666666; font-style: italic;">// matched to length of short string, shortest wins</span>
         <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #009900;">&#40;</span> s1.<span style="color: #006633;">length</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span> s2.<span style="color: #006633;">length</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">?</span> <span style="color: #cc66cc;">1</span> <span style="color: #339933;">:</span> <span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
   <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>which sorts such that I get a list like this:</p>
<ul>
<li>Page 0
<ul class="ind">
<li>Page 0.0
<ul class="ind">
<li>Page 0.0.Llama</li>
</ul>
</li>
<li>Page 0.1
<ul class="ind">
<li>Page 0.1.Snake</li>
</ul>
</li>
<li>Page 0.2
<ul class="ind">
<li>Page 0.2.Fish</li>
</ul>
</li>
</li>
</ul>
<li class="hig1">Page 1
<ul class="ind">
<li>Page 1.0
<ul class="ind">
<li>Page 1.0.Carrot</li>
<li>Page 1.0.Parsnip</li>
</ul>
</li>
<li style="border:1px solid red;">Page 1.1
<ul class="ind">
<li class="hig">Page 1.1.Lemon</li>
<li>Page 1.1.0
<ul class="ind">
<li>Page 1.1.0.Honeydew</li>
<li>Page 1.1.0.Watermelon</li>
</ul>
</li>
<li>Page 1.1.1
<ul class="ind">
<li>Page 1.1.1.Bacon</li>
<li>Page 1.1.1.Sausage</li>
</ul>
</li>
</ul>
</li>
<li>Page 1.2
<ul class="ind">
<li>Page 1.2.Lamp</li>
</ul>
</li>
</ul>
</li>
<li>Page 2
<ul class="ind">
<li>Page 2.0</li>
<ul class="ind">
<li>Page 2.0.Golf</li>
<li>Page 2.0.Rugby</li>
<li>Page 2.0.Skiing</li>
</ul>
</li>
</ul>
</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://zoril.co.uk/wp/2011/11/sorting-in-java-letters-first/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SVGs, PDFs and Java</title>
		<link>http://zoril.co.uk/wp/2011/11/svgs-pdfs/</link>
		<comments>http://zoril.co.uk/wp/2011/11/svgs-pdfs/#comments</comments>
		<pubDate>Tue, 15 Nov 2011 03:30:47 +0000</pubDate>
		<dc:creator>Zoril</dc:creator>
				<category><![CDATA[News]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[image]]></category>
		<category><![CDATA[java]]></category>

		<guid isPermaLink="false">http://zoril.co.uk/wp/?p=596</guid>
		<description><![CDATA[<p>The need to create a variety of similar pages in a PDF file recently came about. Once again unique, once again related to d-touch. When such pages require rotated text, it becomes a whole new level of fun sorting out the co-ordinates and bounds.</p> <p>A different approach seemed necessary and I found myself thinking how <span style="color:#777"> . . . <p><p>&#8594; Continue reading <a href="http://zoril.co.uk/wp/2011/11/svgs-pdfs/">SVGs, PDFs and Java</a></span>]]></description>
			<content:encoded><![CDATA[<p>The need to create a variety of similar pages in a PDF file recently came about. Once again unique, once again related to d-touch. When such pages require rotated text, it becomes a whole new level of fun sorting out the co-ordinates and bounds.</p>
<p>A different approach seemed necessary and I found myself thinking how nice a template would be, just search and replace. Then it hit me: <a href="http://wikipedia.org/wiki/Scalable_Vector_Graphics" target="_blank" title="Scalable Vector Graphics : Wikipedia">SVG</a>s. Images in XML, with support for including actual images and text at any angle, size or position. Perfect. Graphically creating a first draft of the template took minutes. </p>
<p>The other benefit of using a graphical template is how easy it is to change the design and re-run the data through.</p>
<p>215 SVG files don&#8217;t quite leap into a PDF on their own though, and the two image packages I intended to use rather failed to manage. One slowly loaded each and every one before giving an error refusing to accept them as images, the other was quite happy they were valid images for merging to PDF but didn&#8217;t do anything after I pressed go.</p>
<p>I had manual options available I wasn&#8217;t about to jump at, such as saving each one as a PDF and using <a href="http://www.bullzip.com" target="_blank" title="BullZip">BullZip PDF Printer</a> or similar to merge them slowly by hand.</p>
<p>The surprisingly simple and fast solution turned out to be Java. Running the Rasteriser from the <a href="http://xmlgraphics.apache.org/batik/" target="_blank" title="Batik SVG Toolkit">Batik SVG Toolkit</a> on the folder of the SVGs returned a folder of PDFs, a step closer but not quite there yet.</p>

<div class="wp_syntax"><div class="code"><pre class="dos" style="font-family:monospace;">java -jar batik-rasterizer.jar -m application/pdf -w 2480 -h 3508 -d folderForPDFs folderOfSVGs\*.svg</pre></div></div>

<p>The final step was to write a small Java wrapper for the PDF Merger Utility from the <a href="http://pdfbox.apache.org" target="_blank" title="PDFBox">PDFBox</a> package. This basically consisted of scanning the directory of single page PDF files, adding each one as a source for the Merger, and running it.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.File</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.pdfbox.util.PDFMergerUtility</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Merge <span style="color: #009900;">&#123;</span>
   <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> args<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      DoMerge dm <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> DoMerge<span style="color: #009900;">&#40;</span>args<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span>, args<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> DoMerge <span style="color: #009900;">&#123;</span>
   <span style="color: #000000; font-weight: bold;">public</span> DoMerge<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> from, <span style="color: #003399;">String</span> to<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
         <span style="color: #666666; font-style: italic;">// load util</span>
         PDFMergerUtility ut <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> PDFMergerUtility<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
         <span style="color: #666666; font-style: italic;">// get files</span>
         <span style="color: #003399;">File</span> dir <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">File</span><span style="color: #009900;">&#40;</span>from<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
         <span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> pdfs <span style="color: #339933;">=</span> dir.<span style="color: #006633;">list</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
         <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> i<span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> i<span style="color: #339933;">&lt;</span>pdfs.<span style="color: #006633;">length</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #666666; font-style: italic;">// add to pdf</span>
            ut.<span style="color: #006633;">addSource</span><span style="color: #009900;">&#40;</span>from <span style="color: #339933;">+</span> <span style="color: #003399;">File</span>.<span style="color: #006633;">separator</span> <span style="color: #339933;">+</span> pdfs<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
         <span style="color: #009900;">&#125;</span>
&nbsp;
         <span style="color: #666666; font-style: italic;">// save</span>
         ut.<span style="color: #006633;">setDestinationFileName</span><span style="color: #009900;">&#40;</span>to <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;_out.pdf&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
         ut.<span style="color: #006633;">mergeDocuments</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
      <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">Exception</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
         <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Oh no, an error! &quot;</span> <span style="color: #339933;">+</span> e<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
   <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Yes, that is a generic catch everything that goes wrong block. No, you shouldn&#8217;t use them :P</p>
<p>To compile that you&#8217;ll be needing to use something like this</p>

<div class="wp_syntax"><div class="code"><pre class="dos" style="font-family:monospace;">javac -cp pdfbox-1.6.0.jar Merge.java</pre></div></div>

<p>And something like this to run it</p>

<div class="wp_syntax"><div class="code"><pre class="dos" style="font-family:monospace;">java -cp .;pdfbox-1.6.0.jar;commons-logging-1.1.1.jar Merge folderOfPDFs outputName</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://zoril.co.uk/wp/2011/11/svgs-pdfs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Temporal Averaging</title>
		<link>http://zoril.co.uk/wp/2011/11/temporal-averaging/</link>
		<comments>http://zoril.co.uk/wp/2011/11/temporal-averaging/#comments</comments>
		<pubDate>Mon, 07 Nov 2011 18:24:38 +0000</pubDate>
		<dc:creator>Zoril</dc:creator>
				<category><![CDATA[News]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[cpp]]></category>
		<category><![CDATA[image]]></category>
		<category><![CDATA[Qt]]></category>

		<guid isPermaLink="false">http://zoril.co.uk/wp/?p=530</guid>
		<description><![CDATA[<p>Otherwise known as a way of combining a ton of photos of the same area to pull out only the static content. It's one of the least time consuming ways to get impossible photos of empty streets.</p> <p>Basically you take 40 or so photos of a busy section of road without moving the camera even <span style="color:#777"> . . . <p><p>&#8594; Continue reading <a href="http://zoril.co.uk/wp/2011/11/temporal-averaging/">Temporal Averaging</a></span>]]></description>
			<content:encoded><![CDATA[<p>Otherwise known as a way of combining a ton of photos of the same area to pull out only the static content. It's one of the least time consuming ways to get impossible photos of empty streets.</p>
<p>Basically you take 40 or so photos of a busy section of road without moving the camera even slightly (aligning the images takes somewhat more code, and levels of computer vision that I don't want to go into right now). It is unlikely that any of these photos will show the entire road with no traffic in sight, but if you look at a single particular pixel in every one of those photos, it is very likely that the most common value for it will be 'road'.</p>
<p>Ideally, you just select that most common value for each pixel and ignore everything else. In practice, cameras and images don't store or detect the exact colour of an object, and each pixel of it will vary per photo, so taking a <em>pure mode</em> is out as an average for that reason - there will be no reliable most common colour to select. To get around this, the <em>mode</em> would have to be of ranges.</p>
<p>Either way, to use the <em>mode</em> every single image has to be considered for each pixel. Depending on the number of images this can lead to awful memory use as every image has to be held available, or huge amounts of disk access as groups of pixels are read in every so often. Breaking the images into groups and taking the mode of each before repeating for those new temporary images would be a loss of accuracy but help solve the above problems.</p>
<p>The <em>arithmetic mean</em> is wonderful for computation and is what I'm currently using. Two images can be read in, averaged, and stored as a temporary image, a third image can be read in (replacing the second), averaged with the temporary image, then stored so as to replace it, and so on. Only two images are in memory at any one time. Unfortunately there may be an increased number of rounding errors depending on how the values are stored. Another problem is that unlike the <em>mode</em>, everything gets a place in the final image - one bright red car on a black road will require a large number of images without a car in that place in order to average back down to an invisible level, whereas using <em>mode</em>, it would have been left out completely.</p>
<h2>The Code</h2>
<p>This is a piece of C++ code that uses the <em>arithmetic mean</em> and Qt (if you want to compile it you'll need to build a basic Qt framework around it). For images I recommend non-streaming webcams pointing at roads or highstreets.</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #666666;">// temporal averaging</span>
<span style="color: #666666;">// zoril.co.uk</span>
<span style="color: #666666;">// 07/Nov/2011</span>
&nbsp;
<span style="color: #666666;">// we only need two images</span>
QImage im_base<span style="color: #008080;">;</span>
QImage im_loaded<span style="color: #008080;">;</span>
&nbsp;
<span style="color: #666666;">// files need to be sequentially numbered</span>
<span style="color: #0000ff;">int</span> num <span style="color: #000080;">=</span> <span style="color: #0000dd;">1</span><span style="color: #008080;">;</span>
&nbsp;
<span style="color: #666666;">// load images matching the name in the text field</span>
<span style="color: #666666;">// e.g. current?.jpg</span>
<span style="color: #666666;">// =&gt; current1.jpg</span>
<span style="color: #666666;">// =&gt; current2.jpg</span>
<span style="color: #666666;">// =&gt; current3.jpg</span>
<span style="color: #666666;">// =&gt; ...</span>
&nbsp;
<span style="color: #666666;">// first image used for dimensions</span>
im_base.<span style="color: #007788;">load</span><span style="color: #008000;">&#40;</span>ui<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>filepattern_fld<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>text<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>.<span style="color: #007788;">replace</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;?&quot;</span>, QString<span style="color: #008080;">::</span><span style="color: #007788;">number</span><span style="color: #008000;">&#40;</span>num<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
<span style="color: #666666;">// set dimensions</span>
<span style="color: #0000ff;">int</span> w <span style="color: #000080;">=</span> im_base.<span style="color: #007788;">width</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
<span style="color: #0000ff;">int</span> h <span style="color: #000080;">=</span> im_base.<span style="color: #007788;">height</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
<span style="color: #666666;">// all the time an image loads</span>
<span style="color: #0000ff;">while</span><span style="color: #008000;">&#40;</span>im_loaded.<span style="color: #007788;">load</span><span style="color: #008000;">&#40;</span>ui<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>filepattern_fld<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>text<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>.<span style="color: #007788;">replace</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;?&quot;</span>, QString<span style="color: #008080;">::</span><span style="color: #007788;">number</span><span style="color: #008000;">&#40;</span>num<span style="color: #000040;">+</span><span style="color: #0000dd;">1</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
   <span style="color: #666666;">// loop through every pixel</span>
   <span style="color: #0000ff;">for</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span> x <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span> x <span style="color: #000080;">&lt;</span> w<span style="color: #008080;">;</span> x<span style="color: #000040;">++</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
      <span style="color: #0000ff;">for</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span> y <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span> y <span style="color: #000080;">&lt;</span> h<span style="color: #008080;">;</span> y<span style="color: #000040;">++</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
&nbsp;
         <span style="color: #666666;">// get the current average colour</span>
         uint px_base <span style="color: #000080;">=</span> im_base.<span style="color: #007788;">pixel</span><span style="color: #008000;">&#40;</span>x ,y<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
         <span style="color: #666666;">// and the new colour</span>
         uint px_loaded <span style="color: #000080;">=</span> im_loaded.<span style="color: #007788;">pixel</span><span style="color: #008000;">&#40;</span>x, y<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
         <span style="color: #666666;">// break into components and take (cumulative moving) average</span>
         uint red <span style="color: #000080;">=</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>px_loaded <span style="color: #000080;">&gt;&gt;</span> <span style="color: #0000dd;">16</span><span style="color: #008000;">&#41;</span> <span style="color: #000040;">&amp;</span> <span style="color: #208080;">0xFF</span><span style="color: #008000;">&#41;</span> <span style="color: #000040;">+</span> num<span style="color: #000040;">*</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>px_base <span style="color: #000080;">&gt;&gt;</span> <span style="color: #0000dd;">16</span><span style="color: #008000;">&#41;</span> <span style="color: #000040;">&amp;</span> <span style="color: #208080;">0xFF</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #000040;">/</span> <span style="color: #008000;">&#40;</span>num<span style="color: #000040;">+</span><span style="color: #0000dd;">1</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
         uint gre <span style="color: #000080;">=</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>px_loaded <span style="color: #000080;">&gt;&gt;</span>  <span style="color: #0000dd;">8</span><span style="color: #008000;">&#41;</span> <span style="color: #000040;">&amp;</span> <span style="color: #208080;">0xFF</span><span style="color: #008000;">&#41;</span> <span style="color: #000040;">+</span> num<span style="color: #000040;">*</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>px_base <span style="color: #000080;">&gt;&gt;</span>  <span style="color: #0000dd;">8</span><span style="color: #008000;">&#41;</span> <span style="color: #000040;">&amp;</span> <span style="color: #208080;">0xFF</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #000040;">/</span> <span style="color: #008000;">&#40;</span>num<span style="color: #000040;">+</span><span style="color: #0000dd;">1</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
         uint blu <span style="color: #000080;">=</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>px_loaded      <span style="color: #008000;">&#41;</span> <span style="color: #000040;">&amp;</span> <span style="color: #208080;">0xFF</span><span style="color: #008000;">&#41;</span> <span style="color: #000040;">+</span> num<span style="color: #000040;">*</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>px_base      <span style="color: #008000;">&#41;</span> <span style="color: #000040;">&amp;</span> <span style="color: #208080;">0xFF</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #000040;">/</span> <span style="color: #008000;">&#40;</span>num<span style="color: #000040;">+</span><span style="color: #0000dd;">1</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
         <span style="color: #666666;">// make into colour</span>
         QRgb newpx <span style="color: #000080;">=</span> qRgb<span style="color: #008000;">&#40;</span>red, gre, blu<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
         <span style="color: #666666;">// store to averaged image</span>
         im_base.<span style="color: #007788;">setPixel</span><span style="color: #008000;">&#40;</span>x, y, newpx<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
      <span style="color: #008000;">&#125;</span>
   <span style="color: #008000;">&#125;</span>
   <span style="color: #666666;">// move onto next image</span>
   num<span style="color: #000040;">++</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span>
<span style="color: #666666;">// save image</span>
im_base.<span style="color: #007788;">save</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;output.jpg&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span></pre></div></div>

<p><em>red</em>, <em>gre</em> and <em>blu</em> would probably be better off not forced into ints and stored in a virtual image each loop.</p>
<h2>The Original Images</h2>
<div class="TINYMCE_gallery_wrapper">
<ul class="TINYMCE_gallery">
<li><a class="tinymce-thumbnail-gallery-image" style="width: 100px; height: 80px; border-color: #CCC;" title="" href="/wp/wp-content/uploads/2011/11/current1.jpg" rel="TINYMCE_gallery"><img style="left: -10px; top: -10px; border-color: #CCC;" src="/wp/wp-content/uploads/2011/11/current1-300x225.jpg" alt="" /></a></li>
<li><a class="tinymce-thumbnail-gallery-image" style="width: 100px; height: 80px; border-color: #CCC;" title="" href="/wp/wp-content/uploads/2011/11/current2.jpg" rel="TINYMCE_gallery"><img style="left: -10px; top: -10px; border-color: #CCC;" src="/wp/wp-content/uploads/2011/11/current2-300x225.jpg" alt="" /></a></li>
<li><a class="tinymce-thumbnail-gallery-image" style="width: 100px; height: 80px; border-color: #CCC;" title="" href="/wp/wp-content/uploads/2011/11/current3.jpg" rel="TINYMCE_gallery"><img style="left: -10px; top: -10px; border-color: #CCC;" src="/wp/wp-content/uploads/2011/11/current3-300x225.jpg" alt="" /></a></li>
<li><a class="tinymce-thumbnail-gallery-image" style="width: 100px; height: 80px; border-color: #CCC;" title="" href="/wp/wp-content/uploads/2011/11/current4.jpg" rel="TINYMCE_gallery"><img style="left: -10px; top: -10px; border-color: #CCC;" src="/wp/wp-content/uploads/2011/11/current4-300x225.jpg" alt="" /></a></li>
<li><a class="tinymce-thumbnail-gallery-image" style="width: 100px; height: 80px; border-color: #CCC;" title="" href="/wp/wp-content/uploads/2011/11/current5.jpg" rel="TINYMCE_gallery"><img style="left: -10px; top: -10px; border-color: #CCC;" src="/wp/wp-content/uploads/2011/11/current5-300x225.jpg" alt="" /></a></li>
<li><a class="tinymce-thumbnail-gallery-image" style="width: 100px; height: 80px; border-color: #CCC;" title="" href="/wp/wp-content/uploads/2011/11/current6.jpg" rel="TINYMCE_gallery"><img style="left: -10px; top: -10px; border-color: #CCC;" src="/wp/wp-content/uploads/2011/11/current6-300x225.jpg" alt="" /></a></li>
<li><a class="tinymce-thumbnail-gallery-image" style="width: 100px; height: 80px; border-color: #CCC;" title="" href="/wp/wp-content/uploads/2011/11/current7.jpg" rel="TINYMCE_gallery"><img style="left: -10px; top: -10px; border-color: #CCC;" src="/wp/wp-content/uploads/2011/11/current7-300x225.jpg" alt="" /></a></li>
<li><a class="tinymce-thumbnail-gallery-image" style="width: 100px; height: 80px; border-color: #CCC;" title="" href="/wp/wp-content/uploads/2011/11/current8.jpg" rel="TINYMCE_gallery"><img style="left: -10px; top: -10px; border-color: #CCC;" src="/wp/wp-content/uploads/2011/11/current8-300x225.jpg" alt="" /></a></li>
<li><a class="tinymce-thumbnail-gallery-image" style="width: 100px; height: 80px; border-color: #CCC;" title="" href="/wp/wp-content/uploads/2011/11/current9.jpg" rel="TINYMCE_gallery"><img style="left: -10px; top: -10px; border-color: #CCC;" src="/wp/wp-content/uploads/2011/11/current9-300x225.jpg" alt="" /></a></li>
<li><a class="tinymce-thumbnail-gallery-image" style="width: 100px; height: 80px; border-color: #CCC;" title="" href="/wp/wp-content/uploads/2011/11/current10.jpg" rel="TINYMCE_gallery"><img style="left: -10px; top: -10px; border-color: #CCC;" src="/wp/wp-content/uploads/2011/11/current10-300x225.jpg" alt="" /></a></li>
<li><a class="tinymce-thumbnail-gallery-image" style="width: 100px; height: 80px; border-color: #CCC;" title="" href="/wp/wp-content/uploads/2011/11/current11.jpg" rel="TINYMCE_gallery"><img style="left: -10px; top: -10px; border-color: #CCC;" src="/wp/wp-content/uploads/2011/11/current11-300x225.jpg" alt="" /></a></li>
<li><a class="tinymce-thumbnail-gallery-image" style="width: 100px; height: 80px; border-color: #CCC;" title="" href="/wp/wp-content/uploads/2011/11/current12.jpg" rel="TINYMCE_gallery"><img style="left: -10px; top: -10px; border-color: #CCC;" src="/wp/wp-content/uploads/2011/11/current12-300x225.jpg" alt="" /></a></li>
<li><a class="tinymce-thumbnail-gallery-image" style="width: 100px; height: 80px; border-color: #CCC;" title="" href="/wp/wp-content/uploads/2011/11/current13.jpg" rel="TINYMCE_gallery"><img style="left: -10px; top: -10px; border-color: #CCC;" src="/wp/wp-content/uploads/2011/11/current13-300x225.jpg" alt="" /></a></li>
<li><a class="tinymce-thumbnail-gallery-image" style="width: 100px; height: 80px; border-color: #CCC;" title="" href="/wp/wp-content/uploads/2011/11/current14.jpg" rel="TINYMCE_gallery"><img style="left: -10px; top: -10px; border-color: #CCC;" src="/wp/wp-content/uploads/2011/11/current14-300x225.jpg" alt="" /></a></li>
<li><a class="tinymce-thumbnail-gallery-image" style="width: 100px; height: 80px; border-color: #CCC;" title="" href="/wp/wp-content/uploads/2011/11/current15.jpg" rel="TINYMCE_gallery"><img style="left: -10px; top: -10px; border-color: #CCC;" src="/wp/wp-content/uploads/2011/11/current15-300x225.jpg" alt="" /></a></li>
<li><a class="tinymce-thumbnail-gallery-image" style="width: 100px; height: 80px; border-color: #CCC;" title="" href="/wp/wp-content/uploads/2011/11/current16.jpg" rel="TINYMCE_gallery"><img style="left: -10px; top: -10px; border-color: #CCC;" src="/wp/wp-content/uploads/2011/11/current16-300x225.jpg" alt="" /></a></li>
<li><a class="tinymce-thumbnail-gallery-image" style="width: 100px; height: 80px; border-color: #CCC;" title="" href="/wp/wp-content/uploads/2011/11/current17.jpg" rel="TINYMCE_gallery"><img style="left: -10px; top: -10px; border-color: #CCC;" src="/wp/wp-content/uploads/2011/11/current17-300x225.jpg" alt="" /></a></li>
</ul>
</div>
<h2>The Resulting Image</h2>
<p>This image was generated using 17 source images (<a title="Some webcams" href="http://www.mobotix.ro/ro/index.php?id=10053&amp;lang=en" target="_blank">from a webcam</a>) and the <em>arithmetic mean</em>.</p>
<div id="attachment_574" class="wp-caption aligncenter" style="width: 650px"><img src="http://zoril.co.uk/wp/wp-content/uploads/2011/11/temporaloutput17-640x480.jpg" alt="Temporally Averaged from 17 Images" title="Temporally Averaged from 17 Images" width="640" height="480" class="size-large wp-image-574" /><p class="wp-caption-text">Temporally Averaged from 17 Images</p></div>
<h2>Using 70 Images</h2>
<div id="attachment_575" class="wp-caption aligncenter" style="width: 650px"><img src="http://zoril.co.uk/wp/wp-content/uploads/2011/11/temporaloutput70-640x480.jpg" alt="Temporally Averaged from 70 Images" title="Temporally Averaged from 70 Images" width="640" height="480" class="size-large wp-image-575" /><p class="wp-caption-text">Temporally Averaged from 70 Images</p></div>
<p>I shall update this if I find a way to have some form of weighted average. I'm thinking.. read in x images, find some form of average, and then base further inclusion on deviation from that.</p>
]]></content:encoded>
			<wfw:commentRss>http://zoril.co.uk/wp/2011/11/temporal-averaging/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

