DOMPDF + justification + extended ASCII chars

May 19th, 2009

If in your documents you use the so called extended ASCII characters, those with a code >= 128 and try to make a PDF print using DOMPDF, and you like to have your document justified, you are in trouble. There seems to be a problem right now with this combination. At least when you want to stick with the open source PDF rendering engine, R&OS CPDF.

The problem is that non only you cannot produce a decent justification, but your text can easly span beyond the border of the paper. This is also true for table cells, where text can flow over the next cell.

This seems to derive from an incorrect mapping between the extended characters and the numbering used by the AFM file. The problem is described in the R&OS CPDF FAQ along with a possible workaround.

Following the workaround proposed in the FAQ, I have tried to make it work under DOMPDF. The workaround says to add a second argument to the selectFont() method that specifies the correct mapping. A grep shows that there are 4 occurrences of this call, in the following files: cpdf_adapter.cls.php and page_cache.cls.php. I therefore proceeded to make the following change, from

$this->_pdf->selectFont($font);

to

$this->_pdf->selectFont($font,
array('encoding'=>'WinAnsiEncoding',
'differences'=>self::$diff));

Once I have written down the mapping, it worked well in the test that I have done. So what is the mapping? Here it is:

static $diff = array (
130 => 'quotesinglbase',
131 => 'florin',
132 => 'quotedblright',
133 => 'ellipsis',
134 => 'dagger',
135 => 'daggerdbl',
136 => 'circumflex',
137 => 'perthousand',
// 138 => '{Underscore}',
139 => 'guilsinglleft',
140 => 'OE',
145 => 'quoteleft',
146 => 'quoteright',
147 => 'quotedblleft',
148 => 'quotedblright',
149 => 'bullet',
150 => 'endash',
151 => 'emdash',
152 => 'tilde',
153 => 'trademark',
// 154 => '{Underscore}',
155 => 'guilsinglright',
156 => 'oe',
159 => 'Ydieresis',
// 160 => '{Nonbreaking space}',
161 => 'exclamdown',
162 => 'cent',
163 => 'sterling',
164 => 'currency',
165 => 'yen',
166 => 'brokenbar',
167 => 'section',
168 => 'dieresis',
169 => 'copyright',
170 => 'ordfeminine',
171 => 'guillemotleft',
172 => 'logicalnot',
// 173 => '{Soft hyphen}',
174 => 'registered',
175 => 'macron',
176 => 'degree',
177 => 'plusminus',
178 => 'twosuperior',
179 => 'threesuperior',
180 => 'acute',
181 => 'mu',
182 => 'paragraph',
183 => 'periodcentered',
184 => 'cedilla',
185 => 'onesuperior',
186 => 'ordmasculine',
187 => 'guillemotright',
188 => 'onequarter',
189 => 'onehalf',
190 => 'threequarters',
191 => 'questiondown',
192 => 'Agrave',
193 => 'Aacute',
194 => 'Acircumflex',
195 => 'Atilde',
196 => 'Adieresis',
197 => 'Aring',
198 => 'AE',
199 => 'Ccedilla',
200 => 'Egrave',
201 => 'Eacute',
202 => 'Ecircumflex',
203 => 'Edieresis',
204 => 'Igrave',
205 => 'Iacute',
206 => 'Icircumflex',
207 => 'Idieresis',
208 => 'Eth',
209 => 'Ntilde',
210 => 'Ograve',
211 => 'Oacute',
212 => 'Ocircumflex',
213 => 'Otilde',
214 => 'Odieresis',
215 => 'multiply',
216 => 'Oslash',
217 => 'Ugrave',
218 => 'Uacute',
219 => 'Ucircumflex',
220 => 'Udieresis',
221 => 'Yacute',
222 => 'Thorn',
223 => 'germandbls',
224 => 'agrave',
225 => 'aacute',
226 => 'acircumflex',
227 => 'atilde',
228 => 'adieresis',
229 => 'aring',
230 => 'ae',
231 => 'ccedilla',
232 => 'egrave',
233 => 'eacute',
234 => 'ecircumflex',
235 => 'edieresis',
236 => 'igrave',
237 => 'iacute',
238 => 'icircumflex',
239 => 'idieresis',
240 => 'eth',
241 => 'ntilde',
242 => 'ograve',
243 => 'oacute',
244 => 'ocircumflex',
245 => 'otilde',
246 => 'odieresis',
247 => 'divide',
248 => 'oslash',
249 => 'ugrave',
250 => 'uacute',
251 => 'ucircumflex',
252 => 'udieresis',
253 => 'yacute',
254 => 'thorn',
255 => 'ydieresis'
);

Configuring Ubuntu for Ajax development

May 17th, 2009

I have written this howto in the past to remind me the steps to configure my Ubuntu PC. Since I often move from one machine to another, I needed to write down few basic instructions just to make the installation task easier. I thought that it might also be of some interest to others, so here it is. I keep the original as a Google doc, and what follows is the published version (inside an <iframe>). You can see the printer friendly version (and reader friendly too) here.

Defective designs

December 27th, 2008

For italian readers only. A collection of products I have purchased that I consider of bad quality.

Blog banner image

November 16th, 2008

Well, since the WordPress default banner is pretty lame, I asked my 14 years old son to come up with something better. What you see above is his first attempt. Ok, I’ll stick to that for the time being.

Next. I would like to post in two different languages, but with different articles, not just the same content translated in the two languages. For the moment I have installed a plugin called qTranslate, but I have still to figure out if it is the right one. Any help would be *very* much appreciated.

WordPress upgrade

November 16th, 2008

I have just upgraded WordPress to version 2.6.3.