{"id":99955,"date":"2018-10-12T07:00:00","date_gmt":"2018-10-12T21:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/?p=99955"},"modified":"2019-03-13T00:22:02","modified_gmt":"2019-03-13T07:22:02","slug":"20181012-00","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20181012-00\/?p=99955","title":{"rendered":"Why doesn&#8217;t GetTextExtentPoint return the correct extent for strings containing tabs?"},"content":{"rendered":"<p>A customer reported that the <code>Get&shy;Text&shy;Extent&shy;Point<\/code> and <code>Get&shy;Text&shy;Extent&shy;Point32<\/code> functions do not return the correct extents for strings that contain tabs. The documentation does say that they do not support carriage return and linefeed, but nothing about tabs. <\/p>\n<p>The <code>Text&shy;Out<\/code> and <code>Get&shy;Text&shy;Extent&shy;Point<\/code> functions do not interpret control characters. They take the string you pass, convert the code points to glyphs, string the glyphs together, and display or measure the result. <\/p>\n<p>They don&#8217;t move the virtual carriage to the &#8220;left margin&#8221; when they encounter a U+000D CARRIAGE RETURN, or move it down by the &#8220;line height&#8221; when they encounter a U+000A LINE FEED, or forward to the next &#8220;tab stop&#8221;, when they encounter a U+0009 CHARACTER TABULATION, or to the left by &#8220;some distance&#8221; when they encounter a U+0008 BACKSPACE,&sup1; or clear the &#8220;screen&#8221; when they encounter a U+000C FORM FEED, or change the &#8220;typewriter ribbon color&#8221; when they encounter U+000E SHIFT IN and U+000F SHIFT OUT, or beep the speaker when they encounter a U+0007 BELL. <\/p>\n<p>At best, you&#8217;ll get the graphics for the various control characters, like &#x2409; for the horizontal tab, but more likely you&#8217;ll get ugly black boxes. <\/p>\n<p>If you want to render text with tabs, use <code>Tabbed&shy;Text&shy;Out<\/code>. If you want to measure text with tabs, use <code>Get&shy;Tabbed&shy;Text&shy;Extent<\/code>. The <code>Draw&shy;Text<\/code> function can both render and measure, and it also supports carriage returns and line feeds. <\/p>\n<p>Still no luck with backspace, changing the typewriter ribbon color, clearing the screen, or beeping the speaker, though. For those you&#8217;re on your own. <\/p>\n<p>&sup1; What would that even mean if you backspaced beyond the start of the string? Does this mean you could have a string whose extent is negative? <\/p>\n","protected":false},"excerpt":{"rendered":"<p>It doesn&#8217;t do carriage control.<\/p>\n","protected":false},"author":1069,"featured_media":111744,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[25],"class_list":["post-99955","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>It doesn&#8217;t do carriage control.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/99955","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/users\/1069"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/comments?post=99955"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/99955\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media\/111744"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media?parent=99955"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=99955"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=99955"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}