<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><div>On Aug 28, 2010, at 5:30 AM, Arjen Nienhuis wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div>Help me try to understand this please.</div><div><br></div><div>A use case for cairo_lock_font_space() is to draw text of the same size while using a different transform:</div><div><br></div><div><span class="Apple-style-span" style="font-family: 'courier new', monospace; ">// All captions should be the same size </span></div> <div><font class="Apple-style-span" face="'courier new', monospace">cairo_lock_font_space(cr);</font></div><div><font class="Apple-style-span" face="'courier new', monospace"><br></font></div><div><font class="Apple-style-span" face="'courier new', monospace">// draw as tall widget at [0,0] and add a caption</font></div> <meta http-equiv="content-type" content="text/html; charset=utf-8"><div><font class="Apple-style-span" face="'courier new', monospace">cairo_save(cr);</font></div><div><font class="Apple-style-span" face="'courier new', monospace">cairo_scale(cr, 2, 0.5);</font></div> <meta http-equiv="content-type" content="text/html; charset=utf-8"><meta http-equiv="content-type" content="text/html; charset=utf-8"><div><font class="Apple-style-span" face="'courier new', monospace">my_draw_widget(cr);</font></div> <div><font class="Apple-style-span" face="'courier new', monospace">cairo_show_text (cr, "My Tall Widget");</font></div><div><div><font class="Apple-style-span" face="'courier new', monospace">cairo_restore(cr);</font></div> </div><div><font class="Apple-style-span" face="'courier new', monospace"><br></font></div><div><div><font class="Apple-style-span" face="'courier new', monospace">// draw as narrow widget at [100,0] and add a caption</font></div> <div><font class="Apple-style-span" face="'courier new', monospace">cairo_save(cr);</font></div><div><div><font class="Apple-style-span" face="'courier new', monospace">cairo_translate(100, 0);</font></div> </div><div><font class="Apple-style-span" face="'courier new', monospace">cairo_scale(0.5, 2);</font></div><div><font class="Apple-style-span" face="'courier new', monospace">my_draw_widget(cr);</font></div> <div><span class="Apple-style-span" style="font-family: 'courier new', monospace; ">cairo_show_text (cr, "My Narrow Widget");</span></div><div><div></div><div><font class="Apple-style-span" face="'courier new', monospace">cairo_restore(cr);</font></div> </div><div><br></div></div><div>Right?</div></blockquote><div><br></div>Yes that will draw text the same size as it was being drawn before the lock_font_space.</div><div><br><blockquote type="cite"><div>Now what if I want the text in <span class="Apple-style-span" style="font-family: 'courier new', monospace; ">my_draw_widget()</span> to scale? How would that work?</div> <div><br></div><div><font class="Apple-style-span" face="'courier new', monospace">void my_draw_widget(cr)</font></div><div><font class="Apple-style-span" face="'courier new', monospace">{</font></div><div> <font class="Apple-style-span" face="'courier new', monospace"> // draw a /!\ symbol </font></div><meta http-equiv="content-type" content="text/html; charset=utf-8"><div><font class="Apple-style-span" face="'courier new', monospace"> cairo_save(cr);</font></div> <div></div><div><span class="Apple-style-span" style="font-family: 'courier new', monospace; "> my_draw_triangle(30,0, 60,50, 0,50);</span></div><meta http-equiv="content-type" content="text/html; charset=utf-8"><meta http-equiv="content-type" content="text/html; charset=utf-8"><div> <div><font class="Apple-style-span" face="'courier new', monospace"> cairo_translate(25, 40);</font></div></div><div><font class="Apple-style-span" face="'courier new', monospace"> </font><span class="Apple-style-span" style="font-family: monospace; font-size: medium; white-space: pre; ">cairo_set_font_size(cr, 30);</span></div> <meta http-equiv="content-type" content="text/html; charset=utf-8"><div><span class="Apple-style-span" style="font-family: 'courier new', monospace; "> cairo_show_text (cr, "!");</span></div><meta http-equiv="content-type" content="text/html; charset=utf-8"><div> <div><div><font class="Apple-style-span" face="'courier new', monospace"> cairo_restore(cr);</font></div></div><div><span class="Apple-style-span" style="font-family: 'courier new', monospace; ">}</span></div></div></blockquote><div><br></div>That will draw text *exactly* the same whether font-lock is on or off. I think this may be the confusion.</div><div><br></div><div>Font-lock will only make a difference if there is a transform (rotate, scale, etc) between when you set the font and when you use it.</div><div><br></div><div>In fact I very much believe almost every current Cairo program will work correctly whether or not font-lock is on. That is because nobody ever does transforms between setting the font and printing, because the current behavior is never what is wanted. There may be some programs that set the font, don't draw, then transform, then draw, these would have to be fixed by swapping the transform and font setting. But just looking at the examples it seems very rare that programmers write it this way.</div><div><br></div><div><blockquote type="cite"><div> </div><meta http-equiv="content-type" content="text/html; charset=utf-8"><div>I think I'd rather save the font space in a variable and restore it when needed:</div><div><br></div><div><font class="Apple-style-span" face="'courier new', monospace">my_label_font_space = cairo_save_font_space(cr);</font></div> <div><font class="Apple-style-span" face="'courier new', monospace"><br></font></div><meta http-equiv="content-type" content="text/html; charset=utf-8"><div><font class="Apple-style-span" face="'courier new', monospace">void my_draw_label(cr, text)</font></div> <div><font class="Apple-style-span" face="'courier new', monospace">{</font></div><meta http-equiv="content-type" content="text/html; charset=utf-8"><div><font class="Apple-style-span" face="'courier new', monospace"> cairo_save(cr);</font></div> <div><font class="Apple-style-span" face="'courier new', monospace"> </font><span class="Apple-style-span" style="font-family: 'courier new', monospace; ">cairo_restore_font_space(cr, my_label_font_space);</span></div> <meta http-equiv="content-type" content="text/html; charset=utf-8"><div></div><meta http-equiv="content-type" content="text/html; charset=utf-8"><div><font class="Apple-style-span" face="'courier new', monospace"> cairo_show_text (cr, text);</font></div> <div></div><div><span class="Apple-style-span" style="font-family: 'courier new', monospace; "> cairo_restore(cr);</span></div><div><span class="Apple-style-span" style="font-family: 'courier new', monospace; ">}</span></div></blockquote><div><br></div>I can assure you this is NOT what is wanted. This sort of hack can be done now in Cairo (by building paths and then restoring the transform, or by loading the identity transform). The purpose of this call is to get the desired behavior with *fewer* calls!</div><div><br></div></body></html>