An Agreeable Procrastination – and the blog of Niels Kühnel

Code, the universe and everything

How to use the cool, new OpenType features in Word 2010

with one comment

It’s really nice to see that Microsoft finally provides support for the standard they defined themselves only 14 years ago. The advanced typography features of OpenType, now enabled in Word 2010, makes your documents look so much more professional and aesthetically pleasing. Especially when they’re combined with features already present in earlier versions of Word.

However, all this is disabled by default. Here’s how to enable it:

1. Change the “normal” style to enable the features everywhere:

OpenType features in Word2010 - Change font settings, small

2. Enable hyphenation

Hyphenation 

And now, look what you’ve got: Kerning (must have), ligatures (must have – special characters for certain character “collisions” like fi, ffi) and old-style figures (optional, but looks really nice and fancy ad agency’ish).

OpenType features in Word 2010

It looks like the everyday typophile can finally retire LyX + XeLaTeX. XeLaTeX’ll probably have some sophisticated features, still not present in Word, but in comparison Word documents are extremely convenient as they can be emailed to and fro for comments and collaboration, without telling people how to install MikTeX, LyX and follow various intricate guides to set it up right.

One more thing… You probably want to create a PDF when you’re nicely looking document is done. And you have probably used Type 1 flavoured OpenType fonts (the ones form Adobe that have so-called CFF outlines), and then you find that your PDF looks miserable and text can’t be selected when you use Word’s build-in export function. That’s because Word doesn’t support OpenType fonts with CFF outlines.  Luckily a free remedy (soon again) exists if you want to have both automatically generated table of contents AND OpenType fonts with CFF outlines. The PDF-T-Maker. For some reason it doesn’t currently work with Word 2010. I have created a patch and sent it to them. To avoid licensing issues I will not publish it here, though.

Advertisements

Written by niels.kuhnel

August 26, 2010 at 4:47 pm

Recursive functions in markup (fun with delegates)

leave a comment »

Sometimes it would be nice to do recursive functions in user controls (for instance, when doing menus).
You can’t define functions like void RenderMenu(IEnumerable<MenuItem> items, int level) { ... } in markup files unless you’re up for some serious Response.Write’ing in a <script runat=”server”> block (which kind of kills the purpose of markup files in the first place). What you can do, however, is to assign values to variables and these values can be delegates.

So you can go like this:

<%
Action<IEnumerable<MenuItem>, int> renderMenu = null;
renderMenu = (items, level) => {
    %><ul class="level-<%=level>"><%
    foreach( var item in items ) {
      %>
      <li><a href="<%=item.Url>"><%=item.Title%></a>
      <%if( item.Children.Any() ) {
           renderMenu(item.Children, level + 1);
      }%>
     </li>
     <%
    }
}

renderMenu(MyMenuItems, 1);
%>

It’s surprising that you can embed HTML in a delegate, but if you know how the ascx parser works it’s probably obvious (I don’t).

Now, it’s important to assign “null” to the delegate variable first, and then assign the actual function in a later statement. Otherwise you can’t do recursion because the compiler complaints about the variable not beeing initialized.

The fact that you have to do “Action<bla, bla, bla...> foo = null; foo = (bla, bla, bla..) { ... }” to define the function is arguably not very aesthetically pleasing. It’s also a shame that you must define the function before you use it. But if you use this construction a lot you’ll probably just get used to it as the way it is, and it’s really convenient to be able to do recursion in markup – with embedded markup.

(How about casing? It’s a local variable so it should be camelCased. But it’s used as a way – don’t say hack 😛 – to have a method. So should it be PascalCased?)

Written by niels.kuhnel

August 11, 2010 at 10:37 pm

Posted in ASP.NET

Tagged with ,

So it came to this…

leave a comment »

I’ve finally overcome my animosity towards blogging. This is it! (ta-da) My blog…

Written by niels.kuhnel

August 11, 2010 at 9:59 pm

Posted in Uncategorized