Comment 31 for bug 1269206

Revision history for this message
David Mathog (mathog) wrote :

PNG output goes through Cairo and that bit of code does not currently do text decorations. This is true whether you use the command line or the GUI to create the PNG. PDF output goes through the same path, and you will observe that it too drops the text decorations. The EMF and WMF outputs retain this information because those conversions do not go through Cairo at all, basically they are a traverse the object tree, drawing as it goes.

So if you are between a rock and a hard place and need to get some document out in PNG format ASAP, save to EMF, then use one of the many programs (on Windows) that can read that, and save from there to PNG. (Even then, only the simplest text decorations will work, EMF doesn't support all the options in CSS.)

If you are want to fix this limitation, here is a brief overview of what is going on. The code of interest is mostly in

  src/extensions/internal

except for the code I added to draw text decorations on the screen, which is in src/display/drawing-text.cpp. I verified with the debugger that execution doesn't go to drawing-text.cpp on a PNG save. Instead in cairo-renderer.cpp it follows this path

CairoRenderer::renderItem to
sp_item_invoke_render to
sp_text_render to
text->layout.showGlyphs(ctx);

There is nothing but showGlyphs() in sp_text_render, which explains why the text decorations
disappear.

The draw to the screen and the draw to PNG seem to be a lot of apples and oranges, even though they both use Cairo. The screen drawing text operates on a DrawingContext and has access to an _nrstyle, whereas the Cairo section operates on a CairoRenderContext and an SPText. SPStyle can be retrieved from the SPText and the parts stored in _nrstyle obtained that way, but I'm not sure what the relationship is between DrawingContext and CairoRenderContext. So forcing sp_text_render to call DrawingText::_renderItem() doesn't look like a walk in the park.

Maybe it has been added since, but at the time Cairo didn't have any native functions specifically for drawing text decorations, these had to be built up out of lower level primitives. You can see how complicated that gets by looking around in drawing-text.cpp.