Archive for Technology category

Origins of a love affair

December 2009 – April 2011 Personal, Technology (, ) • 1,514 views • 6 responses

BBC Micro Computer's OwlFrom an earliest memory of a cream coloured box emblazoned with letters, mostly black – some red, came an owl proclaiming allegiance to the BBC.

This small box sat silently, patiently even, in our classroom for the best part of a year. On the few occasions our teacher was brave enough to flip the switch the machine would chirp into life with it’s two-tone beep and would state on capital white letters on a black background that it was BASIC. At this point the teacher would key-in the mythical incantation of CHAIN “” – handily jotted on a nearby note – and feed the beast a cassette tape.

Some time later the machine would announce it’s vague disappointment with the contents of the tape and be put back to sleep. One time, and one time only, I recall a screen full of bright colours masquerading as pirates looking for treasure.

I was 11.

Such a tantalising taste of computing left me hungry for more. I knew precisely two people who owned computers. One possessed a cut-down version of the BBC Micro from my classroom called the Acorn Electron and guarded it like a sacred treasure, the other was a friend and more accommodating so much so that he agreed, with little optimism, we could type my program listing into his computer.

What combination of childish scrawl, lack of understanding of programming concepts or the cobbled-together dialect of BASIC was responsible for his Texas Instruments TI-99 rejecting my program I would never know. However neither that failure nor the subsequent arrival and rapid departure of a ‘programmable’ Philips G7000 Videopac from my home would quench my thirst.

A new school year started and for me that meant a new school and new subjects the most interesting of these was named Information Technology or IT for short. I don’t recall much of these early lessons other than some exposure to word processing, videotext and a simplified geometry-base programming language for drawing shapes called Logo.

This fixed schedule held little interest to me although the machines themselves did and the teacher opened the room of fifteen or so BBC Micro’s equipped with 5.25″ floppy drives to the ever-changing line of misfits queued outside to play games. But unlike my old school a few people here actually knew a little about these machines.

Chuckie Egg and Mr. E were favourites while masochists would fire up Castle Quest, Citadel and Repton 2 despite being impossible to complete and lacking a crucial save-game option. Fewer still braved the open-ended and Elite space trading/combat game which would let you resume your position each day. Right on commander!

Games consisted of a few files passed between easily damaged 5.25″ floppy disks that students had mysteriously acquired. Remembering which file to CHAIN, *EXEC or *LOAD was a task in itself made worse by the ever-changing scene of kids and games. Now I finally had a machine to myself for a brief period each day I set about solving the first real world problem I encountered here and wanted to create something that would automatically boot and let you select a game by pressing a letter or a number.

Scouring magazines, loaning one of the few BBC BASIC programming manuals from the teacher and occasionally LISTing other people’s I came up with something that worked. Before long it had double height text, colours and some basic animation. Included in the program were some basic instructions on how to edit the program to fit the games on your own disk and it spread like wildfire.

Shortly after my father, who made gadget trading one of his hobbies, brought home a Sinclair ZX Spectrum 16KB. It was less powerful than the BBC’s at school and had to be hooked up to a television and cassette record to be of any use and had small rubber keys that were hard to type on. I played and programmed on it for hours without interruption and it finally became mine when my mother made it clear to my father it couldn’t be traded out for the next gadget. Within a few months the machine had died after something metallic got in through the edge connector.

I was heartbroken but found a neighbour was selling his Spectrum 48K and persuaded my parents to buy it. The extra memory was useful but even better was the hard-key keyboard and the original Sinclair BASIC programming manual I’d been missing. That year my parents split, my father moved out and we moved to a new parish on our little island of Guernsey which meant new friends and a new school. A school that had IT sharing lessons with technical drawing.

My hopes weren’t high…

[)amien

First impressions of Snow Leopard

August 2009 – November 2009 Apple (, , ) • 4,091 views • 6 responses

I came home from work today to find my family pack upgrade version of Snow Leopard. It’s been a few hours, so here are impressions so far.

Packaging & installation

The packaging was very small and lightweight and eco-friendly compared to the big-plastic-box-monsters that come out of Redmond.

Installation went mostly smoothly apart from an abort-and-restart that seems to have been caused by my DVD drive flaking out on me. It’s been trouble since it came back from the Apple Store.

I had to run the separate Xcode installer to update that – it wasn’t automatically detected – which left me wondering if I need to manually install anything from the optional installs or not. Running Xcode before updating it not only failed to launch but left a background process I had to force quit with Actitity Monitor to let the installer upgrade it.

The less-is-more-approach followed through to disk space which freed up another 10.5 GB – impressive given that I had purged all the non-English language resources already using Monolingual and I elected to re-install the Rossetta PowerPC binary support.

Noticeable changes

Despite being an optimization release Apple squeezed a few features in to sweeten the deal the majority of which are documented at their site and in proper reviews. The ones I’ve encountered so far are:

Location services, detect time-zone

Screenshot of location aware time-zone in Snow LeopardGreat for travelling users like myself, it found my nearest city instantly.

AirPort status in menu bar

Pop-up menu now shows signal strength of all other networks. (Hold down alt when popping up this menu to see detailed connection stats)

Smoothing options

Gone are the Automatic, light, medium and strong options replaced with a single “Use LCD font smoothing when available” option that isn’t too good at detecting third-party displays but you can activate the old hidden options.

Subpixel quality

The rendering just looks plain wrong when booting. It has that awful colour-fringe that you see from time to time, the cause of which seems to be related to the default gamma (the curve on which digital colours become analogue levels) on Mac OS X changing from 1.8 to the PC compatible 2.2.

It seems however that the sub-pixel rendering algorithms haven’t been updated to correct this. There is absolutely no point in posting a screenshot as either your browser, screen or OS would make it appear different to how it did here.

Help is at hand though, you can head into the ColorSync Utility in your Applications folder and calibrate your display – just follow the instructions and set the gamma back to 1.8. It’s worth turning on “Expert” mode and spending a few minutes setting it up properly though.

Unable to open NIBs

No compiled nibs error in Snow LeopardI used to love opening up other people’s NIB files. You could in theory create your own customised versions of an applications interface. Localise it for yourself. Maybe even create a UK English version where Colour is spelt correctly.

No more.

Whether this was to save space or to prevent such hacking is anyone’s guess.

Compatibility woes

So far I’ve had a couple of things break:

  • Cyberduck quits on launch – beta replacement is out
  • Xbox 360 controller extension (I don’t use it anymore anyway)
  • iStat Menus fails to launch – I need this to replace menu time with timezones and a drop-down calendar

Features I was expecting

Given the lean-and-mean plus sensible small refinements I was expecting…

  1. Login Window keyboard shortcut – come on, seriously, with the secrecy at Apple surely you need this too?
  2. Uninstaller – AWOL since the transition from OpenStep to NextStep and sorely needed
  3. Language purging – I still don’t want French etc. on my laptop, odd omission given the reduction goals
  4. System update framework – Other apps could use this too you know guys – and put clever delta’ing support in
  5. Grab – STILL only saves in TIFF format. So I save it there, load into preview then into PNG. WTF??
  6. Safari – should have an option to force new windows to open in a new tab

I’d also love to see being able to pin documents to their dock icon and being able to push a window to an edge to tile like as these were two features I found useful in Windows 7. Talking of which when you hold the mouse button down on a dock icon it greys everything else out for a truly UAC-like moment every time you want to quit an app from the dock…

The Menlo font

Menlo and Vera Sans Mono overlaid for comparisonApple needed to replace the ageing Monaco as it has poor international unicode support, has just a single style and poor hinting (it uses embedded bitmaps to look good without anti-aliasing in Terminal).

Given Steve Job’s apparently love of typography would they commission a gorgeous new monospaced font as Microsoft did with Consolas? No.

In 2003 Bitstream released the family Bitstream Vera under a free licence which included a great Sans Mono with bolt, italic and bold-italic variants. It even has some capable hinting so looks pretty good without anti-aliasing although could do with a few delta’s to clean that up. While it was short on the unicode support several forks filled in the gaps such as Deja Vu and Apple took Vera Sans Mono, grabbed some of these additions (adding 2900 glyphs) and tweaked some of the existing ones. Specifically they moved the vertical bar up on EBH, widened MN, shifted il, changed 0 from dotted to crossed and move/resized punctation then packed it up in a True Type Collection file that stores multiple TTF’s in a single file.

While these changes themselves look quite good – it seems they were optimizing for 14 point – in the process they destroyed the hinting for these glyphs despite the tiny amount of change made.
Menlo on Windows in NotepadMenlo on Mac OS X in TextMate
Spot which ones Apple modified on these screenshots (curiously Windows refuses to use the TTC file as it believes it is corrupt).

Screenshot of Terminal preferences showing anti-aliasing forced for MenloApple is obviously aware it’s not a good job as the option to turn off anti-aliasing in Terminal when using Menlo is curiously disabled – this seems to be something hard-coded into Terminal.app as it doesn’t affect TextMate.

Boot Camp

Installation here was a little tricky as initially the installer told me that Boot Camp 64-bit was not supported on my computer model.

Whether they don’t support 64-bit Windows on a late 2007 MacBook Pro 17″ (MacBookPro3,1) or whether it was complaining about Windows 7 isn’t clear as there are no Windows 7 specific drivers on the disk.

All is not lost however as if you navigate into Boot Camp\Drivers\Apple folder you can run the BootCamp.msi or BootCamp64.msi from there and it does not seem to perform the check. All the drivers installed without complaint and the trackpad, mouse, audio etc. is working just fine.

[)amien

LINQ to SQL changes in .NET 4.0

June 2009 – August 2009 .NET, Microsoft () • 85,076 views • 84 responses

People have been asking via Twitter and the LINQ to SQL forums so here’s a list I put together on a number of the changes made for 4.0.

25 Aug 2009 – Updated with additional changes, some of which are new in beta 2.

Change list

Performance

  • Query plans are reused more often by specifically defining text parameter lengths (when connecting to SQL 2005 or later)
  • Identity cache lookups for primary key with single result now includes query.Where(predicate).Single/SingleOrDefault/First/FirstOrDefault
  • Reduced query execution overhead when DataLoadOptions specified (cache lookup considers DataLoadOptions value equivalency)

Usability

  • ITable<T> interface for additional mocking possibilities
  • Contains with enums automatically casts to int or string depending on column type
  • Associations can now specify non-primary-key columns on the other end of the association for updates
  • Support list initialization syntax for queries
  • LinqDataSource now supports inherited entities
  • LinqDataSource support for ASP.NET query extenders added

Query stability

  • Contains now detects self-referencing IQueryable and doesn’t cause a stack overflow
  • Skip(0) no longer prevents eager loading
  • GetCommand operates within SQL Compact transactions
  • Exposing Link<T> on a property/field is detected and reported correctly
  • Compiled queries now correctly detect a change in mapping source and throw
  • String.StartsWith, EndsWith and Contains now correctly handles ~ in the search string (regular & compiled queries)
  • Now detects multiple active result sets (MARS) better
  • Associations are properly created between entities when using eager loading with Table-Valued Functions (TVFs)
  • Queries that contain sub-queries with scalar projections now work better

Update stability

  • SubmitChanges no longer silently consumes transaction rollback exceptions
  • SubmitChanges deals with timestamps in a change conflict scenario properly
  • IsDbGenerated now honors renamed properties that don’t match underlying column name
  • Server-generated columns and SQL replication/triggers now work instead of throwing SQL exception
  • Improved binding support with the MVC model binder

General stability

  • Binary types equate correctly after deserialization
  • EntitySet.ListChanged fired when adding items to an unloaded entity set
  • Dispose our connections upon context disposal (ones passed in are untouched)

Database  control

  • DeleteDatabase no longer fails with case-sensitive database servers

SQL Metal

  • Foreign key property setter now checks all affected associations not just the first
  • Improved error handling when primary key type not supported
  • Now skips stored procedures containing table-valued parameters instead of aborting process
  • Can now be used against connections that use AttachDbFilename syntax
  • No longer crashes when unexpected data types are encountered

LINQ to SQL class designer

  • Now handles a single anonymously named column in SQL result set
  • Improved error message for associations to nullable unique columns
  • No longer fails when using clauses are added to the partial user class
  • VarChar(1) now correctly maps to string and not char
  • Decimal precision and scale are now emitted correctly in the DbType attributes for stored procedures & computed columns
  • Foreign key changes will be picked up when bringing tables back into the designer without a restart
  • Can edit the return value type of unidentified stored procedure types
  • Stored procedure generated classes do not localize the word “Result” in the class name
  • Opening a DBML file no longer causes it to be checked out of source control
  • Changing a FK for a table and re-dragging it to the designer surface will show new FK’s

Code generation (SQL Metal + LINQ to SQL class designer)

  • Stored procedures using original values now compiles when the entity and context namespaces differ
  • Virtual internal now generates correct syntax
  • Mapping attributes are now fully qualified to prevent conflicts with user types
  • KnownTypeAttributes are now emitted for DataContractSerializer with inheritance
  • Delay-loaded foreign keys now have the correct, compilable, code generated
  • Using stored procedures with concurrency no longer gets confused if entities in different namespace to context
  • ForeignKeyReferenceAlreadyHasValueException is now thrown if any association is loaded not just the first

Potentially breaking changes

We worked very hard to avoid breaking changes but of course any potential bug fix is a breaking change if your application was depending on the wrong behavior. The ones I specifically want to call out are:

Skip(0) is no longer a no-op

The special-casing of 0 for Skip to be a no-op was causing some subtle issues such as eager loading to fail and we took the decision to stop special casing this. This means if you had syntax that was invalid for a Skip greater than 0 it will now also be invalid for skip with a 0. This makes more sense and means your app would break on the first page now instead of subtlety breaking on the second page. Fail fast :)

ForeignKeyReferenceAlreadyHasValue exception

If you are getting this exception where you weren’t previously it means you have an underlying foreign key with multiple associations based on it and you are trying to change the underlying foreign key even though we have associations loaded.Best thing to do here is to set the associations themselves and if you can’t do that make sure they aren’t loaded when you want to set the foreign key to avoid inconsistencies.

[)amien

Font hinting and instructing – a primer

May 2009 – April 2011 Fonts, Technology (, , , ) • 3,562 views • no response

Taking my bitmap font Envy Code B into the vector TrueType Envy Code R was a long process, the most difficult being hinting.

Bitmap v scalable fonts

Bitmap fonts are incredibly easy to make. Using a program like Softy or BitFonter you decide the size of your letters and start plotting pixels. You can see exactly how it will look because you draw every glyph (letter/symbol/number) in every size you want to support. This can obviously be very time consuming and doesn’t let you take full advantage of the resolution of the device and the capabilities it offers. A printer can handle in excess of 300 dpi while a display is typically 72 dpi (Mac) or 96 dpi (Windows) with LCD’s supporting sub-pixels due to the individual layout of the red-green and blue elements you can’t feasibly pre-plot every single combination and even if you could the file size would be rather large.

Rather than having specific set of pixels to turn on or off TrueType, OpenType and PostScript fonts contain a series of instructions that tell the computer the shape using a series of points, lines and curves. This means the computer can scale the glyph to the size that is required and then take full advantage of the device being rendered honoring the users preferences for anti-aliasing (smoothing using shades of grey), sub-pixel precision (smoothing using hints of red, green and blue to take advantage of the layout of colour elements in an LCD display), desired contrast and gamma settings etc.

Grid fitting

Such a scaled glyph won’t fit perfectly within a pixel grid and a small sizes and low resolution it can look awful. It is also necessary to ensure that the vertical part of the letter I (known as a stem) looks very similar to the stem of other letters at the same size – we don’t want some letters looking bold – and that the top of the letter o aligns nicely with the top of the i etc. (in most fonts). The glyphs themselves don’t know what is a stem, what should align with other glyphs etc.

Many renders include logic to try and improve un-hinted fonts such as the drop-out control in Windows through to the full auto-hinter in FreeType. If you’ve ever used free fonts from any of the numerous web sites around you’ve probably seen that it doesn’t get it right and it looks like this: Envy Code R unhinted

The first few versions of Envy Code R looked like that because to address this problem you need to learn a process called hinting, which let’s the designer give the renderer “hints” on how to choose the pixels.

Hinting

Font hinting started off as stem and edge identification so that glyphs would maintain the right proportions when sized and rendered on these low-DPI devices. It became apparent that a much more fine-grained level of control was required and so a stack-based byte-code language was developed as part of the TrueType specification to allow designers finer control in how points are adjusted to better take advantage of the display characteristics.

A TrueType font can contain extra blocks which describes, using a sequence of bytes that represent instructions and their arguments, the process by which to align the points and therefore make decisions about how best to fit the letter into the grid by retaining and adjusting various elements.

The important blocks are:

Block Name Description
fpgm Font program Run once when font first used to setup the tables.
gasp Grid-fitting and scan conversion Table specifying when to apply smoothing and grid-fitting based on size ranges.
prep Control value program Run every time the font needs to be drawn differently (e.g. change of size, changing anti-aliasing etc)
cvt Control value table Set of tables that can be used to specify various heights, widths, spacing, positions etc. that glyphs can relate to.

Each instruction (opcode) has a mnemonic that is representative of what it does and these are documented in Chapters 5 through 6 of the TrueType specification (along with much other useful relevant information). Actual per-glyph instructions are stored with each glyph outline in the glyp block.

Rasterizing & rendering

There are many different ways a TrueType font can end up on your screen with a lot of variants between how vendors chose to render the font and what options they expose to developers and users to fine-tune the experience.

  • Windows – User choice of 1-bit, 4-bit grey-scale anti-aliasing, ClearType, ClearType tuning and display DPI plus WPF and DirectWrite per-app options
  • Mac OS X – User choice of sub-pixel anti-aliasing strength and 1-bit cut-off plus per-app 1-bit option (e.g. Terminal)
  • Java – Per-application choice of 1-bit, grey-scale or sub-pixel rendering
  • Flash – Per-application choice of 1-bit or grey-scale
  • FreeType – Rendering library that exposes a number of runtime and compile-time settings

This is of course ignoring the other rendering engines out there such as the Adobe’s Photoshop, RiscOS, D-Type rendering engine, Font Fusion (used on BeOS) etc. and prior versions of those renderers listed above (Flash and Mac OS changed significantly). Getting it pixel-perfect on every combination is impossible but we can try :)

Tools

Instructing fonts is a painstaking process at the best of times and few people deal directly with the low-level instructions instead relying on tools, stem identification and higher-level languages to achieve the same result. Some tools that have support for hinting instructions are:

  • FontLab Studio 5
    Comprehensive font-production package for Windows and Mac that includes auto-hinting and it’s own higher-level link language that it can generate TrueType instructions from but it does not support viewing or modifying existing TrueType instructions and does not handle diagonals well. Rendering preview includes mono, grey-scale and ClearType. (Commercial $649)
  • Fontographer 4.1
    Rather dated font-production package for Windows and Mac. (Commercial $349)
  • FontForge
    Comprehensive font-production package that runs on X11 that includes auto-hinting and the ability to disassemble and edit existing TrueType instructions as well as debug them with stepping. Includes basic mono/grey-scale rendering options. (Open source)
  • Microsoft Visual TrueType
    Hinting instruction tool from Microsoft that uses it’s own higher-level VTT Talk language that compiles down to TrueType instructions that you can further edit. Includes a comprehensive set of preview rendering options but is not capable of disassembling existing instructions. (Commercial, free with signed licence agreement)
  • TTX
    Python scripts that can convert a font into an editable XML representation and back including disassembly and assembly of TrueType hinting instructions. (BSD)
  • TTIComp
    Command-line tool that provides an alternative C-like hinting language. (GPL)
  • Xgridfit
    FontForge scripts to provide an alternative XML-based hinting language. (GPL)
  • TrueTypeViewer
    Windows tool for displaying TrueType fonts and glyphs including debugging and descriptive disassembly of instructions. (GPL)
  • TTHMachine
    Real-time editing of hinting instruction mnemonics and observing their effects which is useful for learning. (Free, no longer supported)

[)amien