Statuses

In Shorts on 31/07/2010 by weirdfellow

Does Git stand for Great Innovative Technology?

Articles

Insanity

In Ubuntu on 25/07/2010 by weirdfellow Tagged: , , , , , , , , , , ,

This is just insane…

The number of blog articles, forum posts and standard proposals definitely proves it….

After struggling with it for a while I have finally managed to (at least I hope so) get an overview of the font rendering stack in Gnome… That’s how it looks at the moment (Ubuntu 10.04):

Gnome fonts settings are stored in gconf registry (~/.gconf). They are read by gnome-settings-daemon and automatically published in two places: xrdb – and XSETTINGS. In addition to the Gnome settings, there is the Fontconfig with the handful of configuration files (/etc/fonts/fonts.conf, /etc/fonts/conf.d/*, /etc/fonts/local.conf and ~/.fonts.conf). All settings are combined by Cairo lib (which behaves weirdly when dealing with Fontconfig data – there are a few bugs in there) and Xft is invoked to render the fonts.

xrdb registry can be listed by calling xrdb -query. Getting to see the published XSETTINGS properties is a bit more tricky – but possible with tools provided by xsettingsd project. Install it (there are binaries for Ubuntu) and execute dump_xsettings. It is even possible to get rid of gnome-settings-daemon – useful especially for the KDE guys running GTK apps.

Why the hell doesn’t it look like that? Fontconfig sole purpose is to store font configuration information, why are additional registries introduced?

Appearance panel would need just to create/remove symlinks in ~/.fonts.conf.d/ to files in /etc/fonts/conf.avail or create one own there. There would be 5 of those for default values of: one for hinting and hintstyle, autohint (now still not available through GUI), antialias and lcdfilter. gnome-settings-daemon wouldn’t need to publish fonts settings anywhere… If the gconf must stay, there might be a plugin for gnome-settings-daemon that would publish the gnome font settings in a Fontconfig file, instead of xrdb and XSETTINGS.

It doesn’t sound like rocket science and definitely would make the font settings more consistent. Life would be so much simpler…

Articles

Valid autohinting / hinting style options

In Ubuntu on 25/07/2010 by weirdfellow Tagged: , , , , , , ,

Everyone that ever tried to edit any of the FontConfig configuration files came across the dilemma which hinting to select for your fonts. There are dozens of sample files in the Internet, but noone tells what are the possible valid options and what actually they do.

Today I have been doing some experiments and have found a way to render the same font face with different hinting settings side by side in one window. The conclusion from that is: there are only five different results to be expected out of eight possible combinations of hintstyle and autohint properties.

  • hintstyle = hintnone – switches off the hinting
  • hinstyle = hintslight – switches on the slight hinting (usually results with only vertical hinting but unfortunately not always). Autohint property is ignored and autohinter is always used with this hinting style.
  • hintstyle = hintmedium, autohint = true.
  • hintstyle = hintfull, autohint = true.
  • hintstyle = hintmedium | hintfull, autohint = false – uses the BCI (patented) hinter. In majority it does not matter if hintstyle is set to medium or full – the results are the same.

As an example, the DejaVu Sans with different hinting options.

The difference might not be huge with this font, but with different fonts product more versatile results (Liberation Serif 14pt):

I used a trick with introducing an additional property to the fontconfig – family-old.
In the <match type="pattern"> elements I replace the all the weird font families with something a bit more sensible. But I also store the original family in the family-old property, so later the additional test in <match type="font"> can be performed and properties hintstyle and autohint modified according to the original font family.

This is the .font.config file I have used:

<?xml version='1.0'?>
<!DOCTYPE fontconfig SYSTEM 'fonts.dtd'>
<fontconfig>
<match target="pattern">
  <test name="family" compare="eq" qual="any"><string>TestFont-ah-none</string></test>

  <edit name="family" binding="same" mode="assign"><string>TestFont</string></edit>
  <edit name="family-old" mode="assign"><string>TestFont-ah-none</string></edit>
</match> 

<match target="pattern">
  <test name="family" compare="eq" qual="any"><string>TestFont-ah-slight</string></test>

  <edit name="family" binding="same" mode="assign"><string>TestFont</string></edit>
  <edit name="family-old" mode="assign"><string>TestFont-ah-slight</string></edit>
</match> 

<match target="pattern">
  <test name="family" compare="eq" qual="any"><string>TestFont-ah-medium</string></test>

  <edit name="family" binding="same" mode="assign"><string>TestFont</string></edit>
  <edit name="family-old" mode="assign"><string>TestFont-ah-medium</string></edit>
</match> 

<match target="pattern">
  <test name="family" compare="eq" qual="any"><string>TestFont-ah-full</string></test>

  <edit name="family" binding="same" mode="assign"><string>TestFont</string></edit>
  <edit name="family-old" mode="assign"><string>TestFont-ah-full</string></edit>
</match> 

<match target="pattern">
  <test name="family" compare="eq" qual="any"><string>TestFont-nah-none</string></test>

  <edit name="family" binding="same" mode="assign"><string>TestFont</string></edit>
  <edit name="family-old" mode="assign"><string>TestFont-nah-none</string></edit>
</match> 

<match target="pattern">
  <test name="family" compare="eq" qual="any"><string>TestFont-nah-slight</string></test>

  <edit name="family" binding="same" mode="assign"><string>TestFont</string></edit>
  <edit name="family-old" mode="assign"><string>TestFont-nah-slight</string></edit>
</match> 

<match target="pattern">
  <test name="family" compare="eq" qual="any"><string>TestFont-nah-medium</string></test>

  <edit name="family" binding="same" mode="assign"><string>TestFont</string></edit>
  <edit name="family-old" mode="assign"><string>TestFont-nah-medium</string></edit>
</match> 

<match target="pattern">
  <test name="family" compare="eq" qual="any"><string>TestFont-nah-full</string></test>

  <edit name="family" binding="same" mode="assign"><string>TestFont</string></edit>
  <edit name="family-old" mode="assign"><string>TestFont-nah-full</string></edit>
</match> 

<match target="font">
  <test name="family-old" compare="eq" qual="any"><string>TestFont-ah-none</string></test>

  <edit name="autohint" mode="assign"><bool>true</bool></edit> 
  <edit name="hintstyle" mode="assign"><const>hintnone</const></edit> 
</match> 
<match target="font">
  <test name="family-old" compare="eq" qual="any"><string>TestFont-ah-slight</string></test>

  <edit name="autohint" mode="assign"><bool>true</bool></edit> 
  <edit name="hintstyle" mode="assign"><const>hintslight</const></edit> 
</match> 
<match target="font">
  <test name="family-old" compare="eq" qual="any"><string>TestFont-ah-medium</string></test>

  <edit name="autohint" mode="assign"><bool>true</bool></edit> 
  <edit name="hintstyle" mode="assign"><const>hintmedium</const></edit> 
</match> 
<match target="font">
  <test name="family-old" compare="eq" qual="any"><string>TestFont-ah-full</string></test>

  <edit name="autohint" mode="assign"><bool>true</bool></edit> 
  <edit name="hintstyle" mode="assign"><const>hintfull</const></edit> 
</match> 

<match target="font">
  <test name="family-old" compare="eq" qual="any"><string>TestFont-nah-none</string></test>

  <edit name="autohint" mode="assign"><bool>false</bool></edit> 
  <edit name="hintstyle" mode="assign"><const>hintnone</const></edit> 
</match> 
<match target="font">
  <test name="family-old" compare="eq" qual="any"><string>TestFont-nah-slight</string></test>

  <edit name="autohint" mode="assign"><bool>false</bool></edit> 
  <edit name="hintstyle" mode="assign"><const>hintslight</const></edit> 
</match> 
<match target="font">
  <test name="family-old" compare="eq" qual="any"><string>TestFont-nah-medium</string></test>

  <edit name="autohint" mode="assign"><bool>false</bool></edit> 
  <edit name="hintstyle" mode="assign"><const>hintmedium</const></edit> 
</match> 
<match target="font">
  <test name="family-old" compare="eq" qual="any"><string>TestFont-nah-full</string></test>

  <edit name="autohint" mode="assign"><bool>false</bool></edit> 
  <edit name="hintstyle" mode="assign"><const>hintfull</const></edit> 
</match> 

<match target="pattern">
  <test name="family" compare="eq" qual="any"><string>TestFont</string></test>
  <edit name="family" binding="same" mode="assign"><string>Liberation Serif</string></edit>
</match> 

</fontconfig>

Line 112 contains the name of the fontface to be actually used while rendering. The test images were generated in Firefox – following HTML/JavaScript document was used to display the content.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
	<head>
		<script src="http://ajax.microsoft.com/ajax/jquery/jquery-1.4.2.min.js" type="text/javascript"></script>
		<script type="text/javascript">
function putText( fontFamily, weight, size ) {
	if (!size) size = 14;

	var $span = $("<div><span style='width: 180px; float: left; clear: left;'>" + fontFamily + " " + size + "pt.</span>aąbcćdeęfghijklłoónńsśzźż AĄBCĆDEĘFGHIJKLŁOÓNŃSŚZŻŹ</div>");
	$span.css("font-family", fontFamily).css("font-size", size).css("font-weight", weight);

	$("BODY").append($span);
}

function putSpace() {
	$("BODY").append($("<div>&nbsp;</div>"));
}

function generateHifferentHintingOptions( familyName, fontWeight ) {
	putText ( familyName + "-ah-none", fontWeight );
	putText ( familyName + "-nah-none", fontWeight );
	putSpace();

	putText ( familyName + "-ah-slight", fontWeight );
	putText ( familyName + "-nah-slight", fontWeight );
	putSpace();

	putText ( familyName + "-nah-medium", fontWeight );
	putText ( familyName + "-nah-full", fontWeight );
	putSpace();

	putText ( familyName + "-ah-medium", fontWeight );
	putSpace();

	putText ( familyName + "-ah-full", fontWeight);
	putSpace();
}

$(document).ready(function(){
	generateHifferentHintingOptions( "TestFont", "normal" );
});
		</script>
	</head>
	<body>
	</body>
</html>

I mentioned ealier that usually I prefer the autohint + hintslight combination. There are some rare exceptions I identified with this method. What are your preferences?

Articles

Linux font substitutions

In Uncategorized on 20/07/2010 by weirdfellow Tagged: , , , , ,

Most of the sites out there expect you to have Windows fonts. The layout is usually designed with those fonts and would break if you don’t have them.

Usually the designer is nice enough to include the sans-serif font at the end of the font definition in CSS, but two sans-serif fonts can be pretty different – Tahoma and Arial Black for instance.

It is also possible to install the msttcorefonts package and use the .fonts.conf from Ubuntu wiki, but I don’t really like this approach – Linux comes with a handful of nice fonts, why not to use them?

The most obvious choice for substitutions is the Liberation family – Liberation Serif for Times New Roman, Liberation Sans for Arial and Liberation Sans Mono for Courier New. But what to do with other fonts? Courier does look different too…

I have been playing with the script below (save it as .fonts.conf in /home/username directory) for a while now. Here is the result:

<?xml version='1.0'?>
<!DOCTYPE fontconfig SYSTEM 'fonts.dtd'>
<fontconfig>
<match target="pattern">
  <test compare="eq" name="family" qual="any"><string>Verdana</string></test>
  <edit binding="same" mode="prepend" name="family"><string>DejaVu Sans</string></edit>
</match> 

<match target="pattern">
  <test compare="eq" name="family" qual="any"><string>Arial Black</string></test>
  <edit binding="same" mode="prepend" name="family"><string>DejaVu Sans</string></edit>
  <edit mode="assign" name="weight"><double>200</double></edit>
</match>

<match target="font"> <!-- Switch off hinging for DejaVu Sans -->
  <test compare="eq" name="family" qual="any"><string>DejaVu Sans</string></test>
  <edit name="hinting" mode="assign"><bool>false</bool></edit>
</match>

<match target="pattern">
  <test compare="eq" name="family" qual="any"><string>Tahoma</string></test>
  <edit binding="same" mode="prepend" name="family"><string>Droid Sans</string></edit>
</match> 

<match target="pattern">
  <test compare="eq" name="family" qual="any"><string>Arial</string></test>
  <edit binding="same" mode="prepend" name="family"><string>Liberation Sans</string></edit>
</match>

<match target="pattern">
  <test compare="eq" name="family" qual="any"><string>Times New Roman</string></test>
  <edit binding="same" mode="prepend" name="family"><string>Liberation Serif</string></edit>
</match>

<match target="pattern">
  <test compare="eq" name="family" qual="any"><string>Georgia</string></test>
  <edit binding="same" mode="prepend" name="family"><string>Droid Serif</string></edit>
</match>

<match target="pattern">
  <test compare="eq" name="family" qual="any"><string>Impact</string></test>
  <edit binding="same" mode="prepend" name="family"><string>Droid Serif</string></edit>
  <edit mode="assign" name="weight"><double>200</double></edit>
</match>

<match target="pattern">
  <test compare="eq" name="family" qual="any"><string>Courier New</string></test>
  <edit binding="same" mode="prepend" name="family"><string>Nimbus Mono L</string></edit>
</match> 

<match target="pattern">
  <test compare="eq" name="family" qual="any"><string>Trebuchet MS</string></test>
  <edit binding="same" mode="prepend" name="family"><string>Linux Biolinum O</string></edit>
</match> 

<match target="pattern">
  <test compare="eq" name="family" qual="any"><string>Lucida Console</string></test>
  <edit binding="same" mode="prepend" name="family"><string>DejaVu Sans Mono</string></edit>
</match> 

<match target="pattern">
  <test compare="eq" name="family" qual="any"><string>Lucida Sans Unicode</string></test>
  <edit binding="same" mode="prepend" name="family"><string>DejaVu Sans</string></edit>
</match> 

<match target="pattern">
  <test compare="eq" name="family" qual="any"><string>Palatinio Linotype</string></test>
  <edit binding="same" mode="prepend" name="family"><string>URW Palladio L</string></edit>
</match> 

<match target="pattern">
  <test compare="eq" name="family" qual="any"><string>Consolas</string></test>
  <edit binding="same" mode="prepend" name="family"><string>Inconsolata</string></edit>
</match>
</fontconfig>

Liberation fonts are usually installed, but don’t forget to install Droid font family, Inconsolata and Libertine and Biolinum families.

I have also switched off the hinting for DejaVu Sans. It does not get correctly hinted with Polish letters – I guess not everyone will have this problem – the lines 15-18 could be removed in such case.

In the result I get something like that:

I am really happy with the result. How about you?

Articles

2 matchers expected, 1 recorded.

In Uncategorized on 15/07/2010 by weirdfellow Tagged: , , , ,

EasyMock is really a nice framework for mocking interfaces, so you can reliably test your classes.

As always – everything is fine, unless you need to do something more complex. As long as you know all parameters passed to the mocks, there are no problems. But sometimes it is not possible to predict all arguments the mock will receive. A bit of research and here it is:

  MyData myData = EasyMock.createNiceMock( MyData.class );
  MyService serviceMock = EasyMock.createMock( MyService.class );

  expect( serviceMock.doSth( EasyMock.<File>anyObject(), myData ).andReturn( true );

Seems OK – doesn’t it? The code tells serviceMock to expects a call to doSth method. The second argument should be myData object, while we don’t care about the first one.

Unfortunately, you will get something like that:

java.lang.IllegalStateException: 2 matchers expected, 1 recorded.
	at org.easymock.internal.ExpectedInvocation.createMissingMatchers(ExpectedInvocation.java:56)
	at org.easymock.internal.ExpectedInvocation.(ExpectedInvocation.java:48)
	at org.easymock.internal.ExpectedInvocation.(ExpectedInvocation.java:40)
	at org.easymock.internal.RecordState.invoke(RecordState.java:76)
	at org.easymock.internal.MockInvocationHandler.invoke(MockInvocationHandler.java:38)
	at org.easymock.internal.ObjectMethodsFilter.invoke(ObjectMethodsFilter.java:72)
	at org.easymock.classextension.internal.ClassProxyFactory$MockMethodInterceptor.intercept(ClassProxyFactory.java:93)

Unfortunately, it is not possible to mix values and matchers – a anyObject method is a matcher. To make the test execute correctly, all parameters should use matchers instead of just values. Solution is pretty straight forward – use eq matcher:

  expect( serviceMock.doSth( EasyMock.<File>anyObject(), EasyMock.eq( myData ) ).andReturn( true );

In addition to eq matcher, EasyMock does publish a handful of other matchers. Worth noting are aryEq for comparing the array contents and isA for checking the class of given object. The EasyMock site gives a full list of those.

Articles

Ubuntu Lucid and Compcache

In Uncategorized on 15/07/2010 by weirdfellow Tagged: , , ,

I have been very excited about memory compression for years. The performance boost achieved with Quarterdeck MagnaRAM on Windows 98 still brings smile on my face. Without memory compression my 64MB system sounded like it was chopping parsley – definitely there was some swapping. Switching MagnaRAM on kept it quiet (to be precise – it was loading the next level of Colin McRae Rally 2). Not to mention the difference in required time. Unfortunately, I couldn’t find similar tool for any Windows NT system.

Recently I started to build a development machine on Ubuntu Lucid Lynx and decided to give the Compcache a chance. Compilation caused me absolutely no problems – just download the package, unpack it and execute make. Although there are some patches for the kernel, so it can use the memory even more efficient, they are not required and Compcache will work with stock kernel. Compilation generates two things: a kernel module ramzswap.ko and a user-space utility rzscontrol.

It is pretty simple to initialize compressed swap disk by hand, but I wanted a slick and elegant integration with the services management subsystem. A couple of experiments and voila: my Upstart script for Compcache looks like that:

description "Initializes Compcache"

start on runlevel [2345]
stop on runlevel [!2345]

pre-start script
DIR=/usr/local/src/compcache-0.6.2
CONTROL=$DIR/sub-projects/rzscontrol/rzscontrol

# load dependency modules
modprobe lzo_compress
modprobe lzo_decompress

# load ramzswap module
insmod $DIR/ramzswap.ko num_devices=2
sleep 1s

# Initialize devices with 512MB upper limit.
# These devices does not have a backing swap.
$CONTROL /dev/ramzswap0 --disksize_kb=524288 --init
$CONTROL /dev/ramzswap1 --disksize_kb=524288 --init

# Switch the swaps on
swapon -p 5 /dev/ramzswap0
swapon -p 5 /dev/ramzswap1
end script

post-stop script
DIR=/usr/local/src/compcache-0.6.2
CONTROL=$DIR/sub-projects/rzscontrol/rzscontrol

swapoff /dev/ramzswap0
swapoff /dev/ramzswap1

$CONTROL /dev/ramzswap0 --reset
$CONTROL /dev/ramzswap1 --reset

rmmod ramzswap
end script

Update the paths, save the file as /etc/init/compcache.conf and restart your system. Your system should have two additional swap drives – 512MB each – already configured and switched on. Such configuration also enables switching Compcache off by using Upstart commands too.

In my environment Compcache achieved ~65% compression – 1GB of swapped pages would take approximately 350MB of memory. In result system can allocate 1.7GB and use only 1GB of physical memory without any sign of HDD swapping!

My setup uses two separate swapping devices in order to keep both of the CPU cores busy. If running on Quad Core CPU, it is beneficial to create four devices. Kernel utilizes them equally.

Some useful commands to track your swapping:

sudo swapon -s #displays active swap devices and their usage
sudo stop compcache #switches Compcache off.
sudo start compcache #switches Compcache on
sudo rzscontrol /dev/ramzswap0 --stats #displays the stats of the first swapping device.

I am running this environment for couple of days and I see only advantages. Give it a try!

Articles

Waiting for sound system to respond

In Uncategorized on 30/06/2010 by weirdfellow Tagged: , , ,

This error message is around with many Ubuntu enthusiasts since 9.10. User cannot change the volume level, CPU usage gets ridiculous and the fan sounds like a AH-64 Apache…

The solution is actually very simple

  1. Remove directory .pulse from your home folder
  2. Perform the logout – login cycle

Voila…