Created attachment 35729 [details]
Screen display of example
If you use the Print Preview context provided by MFC with Cairo, text elements are not scaled the same way as other parts of the Cairo scene.
The attached example displays the following:
1. The text "Drawn With cairo_show_glyphs", drawn with the API call 'cairo_show_glyphs'.
2. The text "cairo_text_path", drawn with the API call 'cairo_text_path'
3. The text "cairo_show_text", drawn with the API call 'cairo_show_text'
The attached image "Screen.PNG" shows what this example looks like on screen.
The attached image "Preview_Max.PNG" shows the print preview displaying the full printed page.
The attached image "Preview_Zoomed.PNG" shows the print preview at maximum zoom.
As you can see, the scaling of the text is not consistent at the different zoom levels. The text generated by 'cairo_show_text' and 'cairo_show_glyphs' seem to be rendered at a consistent size no matter what zoom level is used in the preview.
Created attachment 35730 [details]
Print Preview at 'full page' level
Created attachment 35731 [details]
Print Preview at maximum zoom level
Created attachment 35732 [details]
Example project demonstrating the problem
Unfortunately, this is an MFC application example. However, it's the best approximation to the application where the problem was originally noticed.
Created attachment 35739 [details]
Example project demonstrating the problem.
Scaled down with less visual-studio generated cruft.
All the drawing logic is in the file 'cairo_test.cpp', and consists of some sample code from the cairographics.org website, and the glyph test code from the cairo sources.
The only other file of interest is 'Cairo_Preview_TestView.cpp', in its "OnDraw" function. This sets up a drawing context (either a print surface or a display surface) and performs the drawing.
Setup of the HDC used in printing, display, or previewing is done somewhere in the bowels of the MFC runtime.
Created attachment 35740 [details]
The attached test project illustrates the problem outside of MFC, using only win32 calls. Basically, I hijacked the "About" menu item to display a dialog with a scaled version of the main drawing, pretending that it was being drawn to a device with four times greater resolution.
The attached "Scaled_Contents.PNG" shows what the two views look like. As you can see, the 'scaled' view has inconsistent font scales.
Created attachment 35741 [details]
Scaled Context example
Shows the main drawing context and a 'scaled' context side-by-side. Note that the different text sections in the scaled context are not drawn the same way.
As adrianj pointed out on IRC, this issue can be worked around by extracting the scale from the HDC, reset the HDC scale to identity, and setting the scale in the cairo context.
This is the solution I eventually used http://whtconstruct.blogspot.com/2010/05/successful-print-preview.html.
on Sep 29, 2016 at 18:48:12.
(provided by the Example extension).