Posts Tagged ‘ubuntu’

Articles

Compressing RAM with zRam

In Ubuntu on 04/05/2011 by weirdfellow Tagged: , , , , , , ,

A successor to compcache, zram, has been already integrated in the Linux kernel for a while now. This means that no additional compilation nor tweaking is required to benefit from compressing memory on the fly and massively reduced swapping.

As with compache, I wanted to nicely integrate the solution into the Ubuntu Upstart deamon – hence this short article. After a couple of minutes of playing the configuration was ready.

Create file zramswap.conf in /etc/init and put the following content in it.

description "Initializes zram swaping"
 
start on runlevel [2345]
stop on runlevel [!2345]
 
pre-start script
 
# load dependency modules
modprobe zram num_devices=2
 
# initialize the devices
echo 1073741824 > /sys/block/zram0/disksize
echo 1073741824 > /sys/block/zram1/disksize
 
# Creating swap filesystems
mkswap /dev/zram0
mkswap /dev/zram1
 
# Switch the swaps on
swapon -p 5 /dev/zram0
swapon -p 5 /dev/zram1
end script
 
post-stop script
 
# Switching off swap
swapoff /dev/zram0
swapoff /dev/zram1
 
rmmod zram
end script

Now you can start the service with sudo start zramswap (it will be automatically started on after the reboot as well).
You will benefit from 2x1GB swap files, which will be compressed and stored in the RAM. Tested on Ubuntu 11.04.

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

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…

Articles

Creature of habit

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

I honestly don’t remember how many times I tried switching to Linux as my main desktop OS. In the end, all the things I use a PC for are already there – browser, ssh client, rdp client, multimedia player, Eclipse etc. I could easily invent a few semi truthful reasons, but to be honest with ya, I didn’t like the way it looked. And the thing that kept me repelled most were fonts. The text didn’t look the same way it looked on Windows.

I think I owe you an explanation here – I get attached to my fonts. They are very important part of my life and I have managed to keep fonts on my desktop aligned with my idea of correct fonts for a very long time… Everything that was different was bad – how simple is that?

Windows 95, Windows 98 and 2000 defined the fonts. Windows XP has brought to the humanity the awful technology of ClearType, which fortunately could be kept off. No harm done. With Vista it wasn’t that easy – although one could still switch is off, some of the dialogs would persist on using ClearType. But there was escape route – the crowd around was shouting Vista sucks, so it was easy just to join them and keep my “Windows alike” fonts. When I think about it, I managed to keep same fonts for roughly 15 years!

So, on Linux desktop the fonts were always unevenly spaced, unfocused, blurry, chaotic etc. Pick your own. Trying to understand why the glyphs look different, I did a lot of reading. Hinting, BCI, subpixel rendering and subpixel positioning are the terms you mind find around the Web. And I have learned that there are two main camps out there when it comes to text rendering – Microsoft and Apple.

Microsoft – hard core hinters

Microsoft philosophy is to hint the glyphs very much, disturbing their shape, weight and width while make the glyphs appear as sharp as possible. Don’t get me wrong – it isn’t necessary a bad thing to do some tuning – in the end we are using screen displays and can expect the letters to be comfortable to read.

Unfortunately such approach encourages something ridiculous: designers would use typeface which is not designed for screen – like Arial – for content that is displayed on the screen only – like websites  – and expect the hinting to take care of the quality on the screen. It is so common, probably the first site your browser opened today already did that (google.com).

I am pretty sure most of you already know how it does look. Just in case:

It definitely looks sharp – but it does not look like Arial anymore! Arial isn’t that narrow and that tall.

The situation gets even worse when you are using WYSIWYG applications. They require undisturbed text flow and would be nice if your printed page was as dark as you can see it on the screen. I don’t want to dig into that, but just compare the two paragraphs below. The left one is rendered in standard 96dpi, the right one in 166dpi (zoomed 2x) and then sized down to 58%. Notice how differently the text gets wrapped. The carefully placed hyphenation got damaged! 

I know – newer APIs shipped with Vista and Seven do not hint fonts at all. But majority of applications on Windows will use old GDI and have hinted fonts. Word 2007 does that too.

Apple – it has to be pretty

Apple has philosophy of rendering the glyphs on the screen as close as possible to their shape. This means no hinting at all. For users used to the Windows approach, the resulting text might seems a bit blurry, dirty, even difficult to read (ask Mac users, they will not find anything wrong about it – you just get used to it).

If you like it or not, the facts are that the glyphs on screen look like they were designed. It also eliminates most of the problems in WYSIWYG editors – your print will look exactly the same the text looked on the screen.

If you use Windows and want to test yourself how the text on MacOSX looks like, install Safari, open the preferences dialog (CTRL+,) and switch the font rendering method.

Vertical hinting?

Both approaches are contradictory. It seems that it is impossible to have sharp fonts without losing the overall feeling of the text. Fortunately, there something to be don. Very comprehensive article Texts Rasterization Exposures gives a lot of suggestions how to improve the font rendering accuracy while maintaining the clearness and crispiness.

Most of them are not widely implemented, but fortunately there is FreeType2 library. It’s autohinting module is capable of vertical hinting only. I haven’t seen any Windows application that would utilize it, but on Linux desktop (I have been testing Mint Linux 9, a flavor of Ubuntu 10.04) both Chrome and Firefox utilize this feature. And it works great! Have a look yourself…

Isn’t it a huge improvement from Safari rendering? And almost nothing lost – just fraction of pixel in vertical positioning!

Keep in mind that this is rendered with Arial – typeface not suitable for screen. Below the same text, with Arial replaced with Liberation Sans – a totally free typeface that introduces the same metrics, but in my humble opinion looks better on the screen.

From now on, this defines the fonts I would like to have on my desktop…

Petition

I, a creature of habit, who kept his fonts virtually unchanged for over a decade, would like to sign the petition to developers.

Use the vertical hinting!

It gives it all – the advantages of not hinting (undisturbed text flow, correct glyph shapes and accurate feeling of grayness of the text) while maintaining high contrast.

Strangely enough, Chrome for Windows uses some hacks to use standard Windows GDI font rendering instead of FreeType2. Chromium developers (and Firefox guys too) – how difficult would it be to allow user to select which font rendering method he prefers and give users the freedom of switching between GDI and FreeType2?

I can also think about a fancy font preference screen, that would allow user to define font substitution. In result particular desktop could display more suitable font than Arial, when this is defined in the site stylesheet.

technology of