Saturday
Dec242005

Semi-Transparent Text in Open Laszlo

Due to a limitation in the Flash player, device text can only be visible or invisible; any non-zero opacity values for text will be drawn as opacity=1. "Device text" means text drawn by the Flash player using the client operating system's underlying font technology. Device text is inexpensive both in runtime cost and download cost; it uses the font already present on the client machine, so no font description needs to be downloaded. However, device fonts are handled slightly differently on different operating systems; the font dimensions may not be the same across runtimes, and some OS's may not even have fonts you expect. (Notably, most linux machines lack Verdana.)

Embedded fonts are more flexible, but they cost more, in runtime and download size. The OpenLaszlo platform ships with several TrueType fonts, which can be found in lps/fonts. Specify a font for embedding by using the font tag:
<font name="timmons" src="timmonstb.ttf" />
This includes the timmons TrueType font in the swf built from your lzx code. If you're counting bytes (and you should be) just that one font adds 58624 of 'em to your download. Ouch. If you're design-focused, embedded fonts are worth it for two reasons: one, you can be sure they will look the same on every flash runtime, and two, they can be rendered semi-opaque.

There are two workarounds, both of which increase the download size:


  • Turn the text into an image; render it as an image with dynamic opacity. This is a huge pain to maintain.

  • Use embedded fonts.

The difference between embedded and device fonts has been bothering me for a while, so I put together a little example. It constrains the opacity of various text objects to the value of a slider.

Here's the app:


Here's the code:



<canvas width="600" >
<font name="Arioso" src="ariosor.ttf">
</font>
<font name="timmons" src="timmonsb.ttf"/>

<view name="inset" x="20" y="20">
<simplelayout axis="y" spacing="10" />

<view name="controls" layout="axis:y; spacing:30" width="100%" height="140" >
<text multiline="true" x="10" width="${parent.width-20}" >
This slider controls the opacity of each of the text objects below, as
well as the right half of the rectangle at the bottom of the canvas.
Opacity varies from 0 (slider=0) to 1 (slider=100).
The text using embedded fonts (timmons and arioso) can have fractional
opacity; the text using device fonts can only be visible or invisible.
</text>
<slider id="gSlider" minvalue="0" maxvalue="100" value="50" x="10" width="${parent.width-20}" />
</view>

<view height="130">
<simplelayout axis="y" spacing="10" />
<text id="gText" height="24" font="timmons" fontsize="18" opacity="${gSlider.value/100}">
some text in timmons (an embedded font)
</text>

<text height="24" font="Arioso" fontsize="18" opacity="${gSlider.value/100}">
some text in arioso (an embedded font)
</text>

<text height="24" font="Verdana" fontsize="18" opacity="${gSlider.value/100}">
some text in verdana (a device font)
</text>

<text height="24" font="Sans" fontsize="18" opacity="${gSlider.value/100}">
some text in Sans (a device font)
</text>
</view>

<view width="200" height="100" layout="axis:x">
<view bgcolor="black" width="100" height="100" opacity="1" />
<view bgcolor="black" width="100" height="100" opacity="${gSlider.value/100}" />
</view>

</view>

Sunday
Dec182005

don't want to stop coding

I don't want to stop coding. It's past 11 on sunday night; I'm meeting a co-worker for coffee at 9 am to make sure I get out of bed at a reasonable time... The reasonable course of action would be to stop coding and get ready for bed. But! I have five open P2's, and code freeze is tomorrow at noon... That's not really the reason. The reason I still want to code is because there are things that are broken that I can fix.

There are runtime warnings that come from platform code, ie, OpenLaszlo. Changing the platform has more process than changing the application, so I want to get these taken care of tonight. The other runtime warnings, I know Scott will give me a hard time about... and rightfully so. Warnings are a sign that something is not entirely right. I want things to be entirely right!

Isn't it strange, though, that it's six times harder to make changes to the non-revenue-generating product (OpenLaszlo) than it is to make changes to the revenue-generating product (laszlomail)?

So, are we back to the "I write code to meet external demands" point of view? No. I write code, I am now writing code, because I want to make it better. Because I don't want to see those 1-pixel errors on the live site. I write code because I'd rather sleep less tonight and have a better product tomorrow, then sleep enough tonight and have a bunch of 1-pixel errors tomorrow.

Saturday
Dec172005

gratitude

Can I mention again how happy I am with this life? I woke up in soft blankets with friendly cats, made breakfast, cleaned the bathroom, worked on some code... I walked in the rain over to the grocery store, listening to NPR on my iPod nano (thank you, marshall!) and bought groceries... Then walked home, again in the rain, but dry in my fleece and shell... Once home, I started a load of laundry and put away the groceries. Now I've just closed a P1, I'm working on a feature I've been wanting to add for months, and I'm safe and warm.

This is what I wanted. This is what I've been trying to create for myself.

The word of the month is gratitude. Thank you, world. Thank you, village. Thank you, old and new friends, for helping me get here.

Friday
Dec162005

big nerd ranch

Bret was telling me today that he's thinking about taking a class on LAMP, which reminded me of the geek cruises and the Big Nerd Ranch. Now I badly, badly want to go to the five-day objective-C and Cocoa class at the Big Nerd Ranch. While my employer would probably pick up some educational expenses, I don't think they'd be into paying $5k for me to learn the skills for my next job. Don't get me wrong here; I love working at Laszlo Systems and I've got no plans to go anywhere else. But there usually is a next job, sooner or later, and I want to write mac software. Just as soon as I master lzx, photoshop, and settle down to a single text editor.
UC Berkeley Extension doesn't seem to have really LAMP-specific courses, although this one on XML & Web Services sounds good.
As a clueful client-side geek who can sort of scramble by on the server-side, how can I best help a brilliant friend learn what he wants to know about internet architectures?

Friday
Dec162005

anderson cooper

I am worried that Anderson Cooper will be killed in Iraq.