UX

What Is Inside a Sketch File?

As part of the development of Lunacy — a free standalone .sketch file viewer for Windows – I had to learn how to dissect a .sketch file.

In order to accomplish this I needed to do 3 things:

  1. Reveal the structure behind .sketch files
  2. Transfer this “structure” to the Windows environment
  3. Visualize this structure on Windows

Structure

Let’s start from the very beginning. Here’s a .sketch file opened on a Mac:

Every graphic element you see on the picture above – an icon, a block of text – is a separate object. Or in terms of Sketch – a layer.

Sketch file is deceiptively simple on the inside. If you were to open .Sketch in any file manager, say, Far Manager, you’d see something like this:

Not much, but that’s just the tip of the iceberg. We learn something very important from this one string – that a .sketch file is an .SQLite database.

So, how does that database look on the inside? By opening it in any SQLite viewing tool, this is what we get:

Interestingly enough, almost all the space is occupied by a single cell in a single table. Let’s extract this cell’s contents:

After the initial feeling of being in the Matrix, you may notice that everything starts with a bplist string. What is this bplist thing? It turned out to be a standard Mac OS format for storing structured data, and it’s called PList.

In order to bring some clarity to this symbol madness I converted this PList thing into an XML, using some built-in Mac utility (that’s important)

It took me a few days to sort out what was going on here, but I was eventually able to understand the structure behind the file. Now there was still a tiny problem… I was doing all that on Mac, as you remember, using Mac utilities.

Given the fact that I was developing a Windows .sketch viewer, I had to repeat all this on Windows, i.e. open this Plist file on Windows, give it structure and then properly analyse the result.

So I did just that.

I found only one library that could open the PList format on Windows. But it needed a huge update and lots of improvement. In the end I was able to get this:

It was something, though I still had to write my own handler, because in the structure you see above it’s not objects that we see, it’s their addresses. So the handler’s job was to find these objects using their addresses and then, using a special method, make all the received data readable:

From that we see that the current object has a name “Sketch viewer for Wi”, and in the frame block we can see its size and coordinates. Now I could visually compare this same .sketch file opened on Mac and its structure, derived on Windows.

Visualization

Now that I had the structure, I was able to render every object/element of the file sequentially.

For that rendering I used the cross-platform library Skia from Google. To be more precise, it’s a Xamarin SkiaSharp. With the help of OpenGl the library is able to draw graphic primitives, text, and rasterized images. Besides that, it gives you the ability to visualize the file’s objects closest to the original because it supports gradients, tiles, layer overlays, shadows, blur etc.

You can see how it all works in this video:

One by one all parts of the file are rendered, eventually creating something we’re referencing as a mock-up or a .sketch file.

Recent Posts

Build it right: a no-fluff guide to UX design process

Learn more about each step within the design process to improve your UX workflow.

3 weeks ago

Everything you need to know about icons

A deep dive into the smallest images in graphic design: the history of icons, their…

1 month ago

Visual hierarchy in graphic design

Learn how to use visual hierarchy to guide attention, prioritize elements, and create designs that…

2 months ago

WOKONEO use case: inspiring young minds through puzzles

WOKONEO, a puzzle book for kids that blends playful learning with creativity, featuring Icons8’s Color…

3 months ago

Perfect Christmas gifts for designers

Find the perfect gift for graphic designers! Explore everything from ergonomic tools to creative resources,…

3 months ago

How a premium website design can drive business growth

Here’s a case study from UNIKO™ on how premium website design drives growth. See how…

3 months ago

This website uses cookies.