Patch for cairo-win32-font.c, when GetTextMetrics fails

Patrick Fritzsch <[email protected]>
Newsgroups gmane.comp.lib.cairo
Message-ID <[email protected]>
Hello,

attached is a patch for cairo-win32-font.c, which fixed an issue with a problematic font on windows I had during printing a pdf document on cairo (not using poppler).

Problem:
Cairo uses the winapi GetTextMetrics function, but didn’t check, if the function succeeded. See
https://msdn.microsoft.com/de-de/library/windows/desktop/dd144941(v=vs.85).aspx – it can fail.

If the function fails, windows doesn’t fill the struct, which was given to GetTextMetrics and its values are kept uninitialized – so cairo went depending on a random effect into different parts of code afterwards (symbol fonts / non symbol fonts) and didn’t make a clean error.

Because the font, which fails for GetTextMetrics function, is from a customer document and I don’t have the right to provide the stuff to the outside, I cannot supply it to this list. But it is a reduced truetype font, which contains only a .notdef glyph and one additional glyph, which doesn’t have any contours, mapped to a space.

Question:
When Cairo fails internally for any reason it set sets an error code inside the context – and all content later, which i want to output on this context isn’t processed anymore. In above case it works, that I ignore that error-setting and process the rest of the document.
So how can I achieve, that when I left the erroneous state inside the context, that it works again? I miss something like a cairo_reset_error function.


Best regards,

Patrick

-- 
cairo mailing list
[email protected]
http://lists.cairographics.org/mailman/listinfo/cairo
cairo-win32-font.patch (application/octet-stream, 901 B)
Index: cairo-win32-font.c
===================================================================
--- cairo-win32-font.c	(revision 2201)
+++ cairo-win32-font.c	(revision 2202)
@@ -889,7 +889,7 @@
     cairo_status_t status;
     cairo_font_extents_t extents;
 
-    TEXTMETRIC metrics;
+	TEXTMETRIC metrics = {0};
     HDC hdc;
 
     hdc = _get_global_font_dc ();
@@ -902,8 +902,13 @@
 	status = cairo_win32_scaled_font_select_font (&scaled_font->base, hdc);
 	if (status)
 	    return status;
-	GetTextMetrics (hdc, &metrics);
+	if(!GetTextMetrics (hdc, &metrics))
+	{
+		status = _cairo_win32_print_gdi_error ("_cairo_win32_scaled_font_set_metrics:GetTextMetrics");
+	}
 	cairo_win32_scaled_font_done_font (&scaled_font->base);
+	if (status)
+		return status;
 
 	extents.ascent = metrics.tmAscent / scaled_font->logical_scale;
 	extents.descent = metrics.tmDescent / scaled_font->logical_scale;
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.