<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/atom.xsl" media="screen"?><feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en"><title type="html">Murray Sargent: Math in Office</title><subtitle type="html">I&amp;#39;m a software development engineer in Microsoft Office and have been working mostly on the RichEdit editor since 1994. In this blog I focus on mathematics in Office along with some posts on RichEdit and the early Windows days</subtitle><id>http://blogs.msdn.com/b/murrays/atom.aspx</id><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/murrays/" /><link rel="self" type="application/atom+xml" href="http://blogs.msdn.com/b/murrays/atom.aspx" /><generator uri="http://telligent.com" version="5.6.50428.7875">Telligent Evolution Platform Developer Build (Build: 5.6.50428.7875)</generator><updated>2012-07-29T19:58:00Z</updated><entry><title>Pasting Bitmaps into Text</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/murrays/archive/2013/04/30/pasting-bitmaps-into-text.aspx" /><id>http://blogs.msdn.com/b/murrays/archive/2013/04/30/pasting-bitmaps-into-text.aspx</id><published>2013-04-30T04:42:00Z</published><updated>2013-04-30T04:42:00Z</updated><content type="html">&lt;p&gt;&lt;span style="font-family: Calibri; font-size: small;"&gt;In the (almost) old days, when you paste a bitmap into a rich-text editor, the editor would give it to &lt;a href="http://en.wikipedia.org/wiki/Object_Linking_and_Embedding"&gt;&lt;span style="color: #0563c1;"&gt;OLE&lt;/span&gt;&lt;/a&gt; (Object Linking and Embedding) to figure out what to do with it. But these days, OLE isn&amp;rsquo;t always available, so it&amp;rsquo;s more general to paste them using the &lt;/span&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ee719902(v=vs.85).aspx"&gt;&lt;span style="color: #0563c1; font-family: Calibri; font-size: small;"&gt;Windows Imaging Component&lt;/span&gt;&lt;/a&gt;&lt;span style="font-family: Calibri; font-size: small;"&gt; (WIC) mentioned in the &lt;/span&gt;&lt;a href="http://blogs.msdn.com/b/murrays/archive/2013/03/16/images-with-transparent-regions.aspx"&gt;&lt;span style="color: #0563c1; font-family: Calibri; font-size: small;"&gt;alpha-channel post&lt;/span&gt;&lt;/a&gt;&lt;span style="font-family: Calibri; font-size: small;"&gt; and in the &lt;/span&gt;&lt;a href="http://blogs.msdn.com/b/murrays/archive/2012/05/25/richedit-8-0-image-support.aspx"&gt;&lt;span style="color: #0563c1; font-family: Calibri; font-size: small;"&gt;RichEdit 8.0 Image Support post&lt;/span&gt;&lt;/a&gt;&lt;span style="font-family: Calibri; font-size: small;"&gt;. For example, you might want to paste an image from MS Paint or from the handy Snipping Tool. These programs offer bitmaps on the clipboard, although they don&amp;rsquo;t offer jpg&amp;rsquo;s or png&amp;rsquo;s. The bitmaps are in the memory-format &lt;/span&gt;&lt;a href="http://en.wikipedia.org/wiki/Device-independent_bitmap"&gt;&lt;span style="color: #0563c1; font-family: Calibri; font-size: small;"&gt;Device Independent Bitmap&lt;/span&gt;&lt;/a&gt;&lt;span style="font-size: small;"&gt;&lt;span style="font-family: Calibri;"&gt; (clipboard formats DIB and DIBV5). As such they are &amp;ldquo;raw&amp;rdquo; bitmaps without a bitmap file header. This is a problem for WIC since WIC only accepts bitmaps that have the correct bitmap &lt;em&gt;file&lt;/em&gt; format as well as containing valid image data. Other image formats like png&amp;rsquo;s and jpg&amp;rsquo;s have headers identifying which codec to use, and WIC depends on this information.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Calibri; font-size: small;"&gt;Fortunately DIBs are easily converted to the bitmap file format by prepending the correct bitmap file header to the DIB data. WIC then happily accepts the result. As described in &lt;/span&gt;&lt;a href="http://en.wikipedia.org/wiki/Device-independent_bitmap"&gt;&lt;span style="color: #0563c1; font-family: Calibri; font-size: small;"&gt;Device Independent Bitmap&lt;/span&gt;&lt;/a&gt;&lt;span style="font-size: small;"&gt;&lt;span style="font-family: Calibri;"&gt;, a bitmap file header consists of fourteen bytes. You just have to choose the right ones! They are given in the following table&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;div align="center"&gt;
&lt;table border="1" cellspacing="0" cellpadding="0"&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td valign="top"&gt;
&lt;p&gt;&lt;strong&gt;&lt;span style="font-size: small;"&gt;&lt;span style="font-family: Calibri;"&gt;Byte IDs&lt;/span&gt;&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td valign="top"&gt;
&lt;p&gt;&lt;strong&gt;&lt;span style="font-size: small;"&gt;&lt;span style="font-family: Calibri;"&gt;Purpose&lt;/span&gt;&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td valign="top"&gt;
&lt;p&gt;&lt;strong&gt;&lt;span style="font-size: small;"&gt;&lt;span style="font-family: Calibri;"&gt;Value&lt;/span&gt;&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td valign="top"&gt;
&lt;p&gt;&lt;span style="font-size: small;"&gt;&lt;span style="font-family: Calibri;"&gt;0&amp;mdash;1&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td valign="top"&gt;
&lt;p&gt;&lt;span style="font-size: small;"&gt;&lt;span style="font-family: Calibri;"&gt;Type&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td valign="top"&gt;
&lt;p&gt;&lt;span style="font-size: small;"&gt;&lt;span style="font-family: Calibri;"&gt;&amp;ldquo;BM&amp;rdquo; (little endian)&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td valign="top"&gt;
&lt;p&gt;&lt;span style="font-size: small;"&gt;&lt;span style="font-family: Calibri;"&gt;2&amp;mdash;5&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td valign="top"&gt;
&lt;p&gt;&lt;span style="font-size: small;"&gt;&lt;span style="font-family: Calibri;"&gt;Size of file&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td valign="top"&gt;
&lt;p&gt;&lt;span style="font-size: small;"&gt;&lt;span style="font-family: Calibri;"&gt;Size of DIB + 14&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td valign="top"&gt;
&lt;p&gt;&lt;span style="font-size: small;"&gt;&lt;span style="font-family: Calibri;"&gt;6&amp;mdash;7&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td valign="top"&gt;
&lt;p&gt;&lt;span style="font-size: small;"&gt;&lt;span style="font-family: Calibri;"&gt;Reserved&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td valign="top"&gt;
&lt;p&gt;&lt;span style="font-size: small;"&gt;&lt;span style="font-family: Calibri;"&gt;0&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td valign="top"&gt;
&lt;p&gt;&lt;span style="font-size: small;"&gt;&lt;span style="font-family: Calibri;"&gt;8&amp;mdash;9&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td valign="top"&gt;
&lt;p&gt;&lt;span style="font-size: small;"&gt;&lt;span style="font-family: Calibri;"&gt;Reserved&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td valign="top"&gt;
&lt;p&gt;&lt;span style="font-size: small;"&gt;&lt;span style="font-family: Calibri;"&gt;0&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td valign="top"&gt;
&lt;p&gt;&lt;span style="font-size: small;"&gt;&lt;span style="font-family: Calibri;"&gt;10&amp;mdash;13&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td valign="top"&gt;
&lt;p&gt;&lt;span style="font-size: small;"&gt;&lt;span style="font-family: Calibri;"&gt;Offset of image data&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td valign="top"&gt;
&lt;p&gt;&lt;span style="font-size: small;"&gt;&lt;span style="font-family: Calibri;"&gt;14 + size of DIB header&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;p&gt;&lt;span style="font-size: small;"&gt;&lt;span style="font-family: Calibri;"&gt;Here since &amp;ldquo;BM&amp;rdquo; is little endian, byte 0 is &amp;lsquo;B&amp;rsquo; and byte 1 is &amp;lsquo;M&amp;rsquo;. The size of the DIB header is given by the first four bytes of the DIB. These bytes make up a little-endian 32-bit integer.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Calibri; font-size: small;"&gt;A different kind of bitmap file format is the &lt;/span&gt;&lt;a href="http://en.wikipedia.org/wiki/ICO_(icon_image_file_format)"&gt;&lt;span style="color: #0563c1; font-family: Calibri; font-size: small;"&gt;ico format&lt;/span&gt;&lt;/a&gt;&lt;span style="font-size: small;"&gt;&lt;span style="font-family: Calibri;"&gt;. The WIC documentation&amp;nbsp;&lt;a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ee690086(v=vs.85).aspx"&gt;&lt;span style="color: #0563c1;"&gt;lists&lt;/span&gt;&lt;/a&gt; this format as one with a native WIC codec. The format provides for one or more icon bitmaps and later versions included png&amp;rsquo;s and alpha channels. The different bitmaps typically have different sizes, which is handy for accommodating various screen sizes and resolutions. Unfortunately, the native WIC codec can only decode ico files. For some reason, it cannot encode them, so if you paste one into your document, you can see it on screen but can&amp;rsquo;t save it. It&amp;rsquo;s tempting to write an ico codec that can encode as well as decode, but since nowadays it&amp;rsquo;s common to use regular images like png&amp;rsquo;s for icons, maybe&amp;nbsp;a better ico codec&amp;nbsp;doesn't have high priority.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Calibri; font-size: small;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Calibri; font-size: small;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10414979" width="1" height="1"&gt;</content><author><name>MurrayS3</name><uri>http://blogs.msdn.com/MurrayS/ProfileUrlRedirect.ashx</uri></author></entry><entry><title>The Alpha Channel</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/murrays/archive/2013/03/16/images-with-transparent-regions.aspx" /><id>http://blogs.msdn.com/b/murrays/archive/2013/03/16/images-with-transparent-regions.aspx</id><published>2013-03-16T20:29:00Z</published><updated>2013-03-16T20:29:00Z</updated><content type="html">&lt;p&gt;&lt;span style="font-family: Calibri; font-size: small;"&gt;One of our testers inserted a Microsoft logo image&amp;nbsp;into RichEdit and saw an inky&amp;nbsp;black rectangle. Ignoring any connotation that this might be a bad omen (!), I proceeded to study image formats in Wikipedia and in MSDN. (Not that I hadn't already scoured such documentation). Pretty soon I started to suspect that the image, which is a png (&lt;a href="http://en.wikipedia.org/wiki/Portable_Network_Graphics"&gt;&lt;span style="color: #0563c1; font-family: Calibri; font-size: small;"&gt;portable network graphics&lt;/span&gt;&lt;/a&gt;&lt;span style="font-size: small;"&gt;&lt;span style="font-family: Calibri;"&gt;)&lt;/span&gt;&lt;/span&gt;, might have an alpha channel. Such a channel isn't something from outer space; it's&amp;nbsp;a channel that lets you blend an image with the background or make portions of the image transparent. When a pixel's alpha-channel value is transparent (0), the pixel's color is&amp;nbsp;typically black. If so and the pixel's alpha-channel value is ignored, the pixel renders as black,&amp;nbsp;because the pixel&amp;nbsp;is not treated as transparent. &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Calibri; font-size: small;"&gt;More generally, nonzero alpha-channel values blend the image pixel colors with the background pixels. The alpha-channel value &lt;em&gt;&amp;alpha;&lt;/em&gt;&lt;em&gt; &lt;/em&gt;gives the degree to which the image pixel is opaque. For&amp;nbsp;byte values, &lt;em&gt;&amp;alpha;&lt;/em&gt;/255 of the pixel's red, green, and blue are combined with 1 - &lt;em&gt;&amp;alpha;&lt;/em&gt;&lt;em&gt;&lt;/em&gt;/255 of the background pixel's red, green, and blue, respectively. So &lt;em&gt;&amp;alpha;&lt;/em&gt;&lt;em&gt;&lt;/em&gt; = 0 implies that the image pixel color isn't used; only the background pixel is seen. Unless you ignore the alpha-channel value.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Calibri; font-size: small;"&gt;Not all image formats can have an alpha channel. For example, &lt;/span&gt;&lt;a href="http://en.wikipedia.org/wiki/JPEG"&gt;&lt;span style="color: #0563c1; font-family: Calibri; font-size: small;"&gt;jpeg&lt;/span&gt;&lt;/a&gt;&lt;span style="font-family: Calibri; font-size: small;"&gt; images can contain &lt;/span&gt;&lt;a href="http://en.wikipedia.org/wiki/Exchangeable_image_file_format"&gt;&lt;span style="color: #0563c1; font-family: Calibri; font-size: small;"&gt;EXIF metadata&lt;/span&gt;&lt;/a&gt;&lt;span style="font-family: Calibri; font-size: small;"&gt; that gives information about the image, such as time and place where the picture was taken, the kind of camera used, and the exposure settings. But jpegs cannot have an &lt;/span&gt;&lt;a href="http://en.wikipedia.org/wiki/Alpha_compositing"&gt;&lt;span style="color: #0563c1; font-family: Calibri; font-size: small;"&gt;alpha channel&lt;/span&gt;&lt;/a&gt;&lt;span style="font-family: Calibri; font-size: small;"&gt;. Meanwhile png &lt;/span&gt;&lt;span style="font-size: small;"&gt;&lt;span style="font-family: Calibri;"&gt;images can have an alpha channel, but cannot have EXIF metadata. Png's can have other kinds of metadata.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Calibri; font-size: small;"&gt;In testing various png&amp;rsquo;s, we found that a number of them displayed as a completely black rectangles. The &lt;/span&gt;&lt;a href="http://www.w3.org/TR/PNG/#11IHDR"&gt;&lt;span style="color: #0563c1; font-family: Calibri; font-size: small;"&gt;png specification&lt;/span&gt;&lt;/a&gt;&lt;span style="font-size: small;"&gt;&lt;span style="font-family: Calibri;"&gt; shows how to know if an alpha channel is present. Specifically, a png begins with the 8 bytes 89 50 4E 47 0D 0A 1A 0A followed by the IHDR chunk. Note that hex 50 4E 47 are the ASCII values of PNG. The IHDR chunk has the content&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;div align="center"&gt;
&lt;table summary="This table defines the IHDR chunk" border="1" cellspacing="0" cellpadding="2"&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td valign="top"&gt;
&lt;p&gt;&lt;span style="font-size: small;"&gt;&lt;span style="font-family: Calibri;"&gt;Chunk count (13)&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td valign="top"&gt;
&lt;p&gt;&lt;span style="font-size: small;"&gt;&lt;span style="font-family: Calibri;"&gt;4 bytes&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td valign="top"&gt;
&lt;p&gt;&lt;span style="font-size: small;"&gt;&lt;span style="font-family: Calibri;"&gt;Type (IHDR)&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td valign="top"&gt;
&lt;p&gt;&lt;span style="font-size: small;"&gt;&lt;span style="font-family: Calibri;"&gt;4 bytes&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td valign="top"&gt;
&lt;p&gt;&lt;span style="font-size: small;"&gt;&lt;span style="font-family: Calibri;"&gt;Width&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td valign="top"&gt;
&lt;p&gt;&lt;span style="font-size: small;"&gt;&lt;span style="font-family: Calibri;"&gt;4 bytes&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td valign="top"&gt;
&lt;p&gt;&lt;span style="font-size: small;"&gt;&lt;span style="font-family: Calibri;"&gt;Height&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td valign="top"&gt;
&lt;p&gt;&lt;span style="font-size: small;"&gt;&lt;span style="font-family: Calibri;"&gt;4 bytes&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td valign="top"&gt;
&lt;p&gt;&lt;span style="font-size: small;"&gt;&lt;span style="font-family: Calibri;"&gt;Bit depth&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td valign="top"&gt;
&lt;p&gt;&lt;span style="font-size: small;"&gt;&lt;span style="font-family: Calibri;"&gt;1 byte&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td valign="top"&gt;
&lt;p&gt;&lt;span style="font-size: small;"&gt;&lt;span style="font-family: Calibri;"&gt;Color type&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td valign="top"&gt;
&lt;p&gt;&lt;span style="font-size: small;"&gt;&lt;span style="font-family: Calibri;"&gt;1 byte&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td valign="top"&gt;
&lt;p&gt;&lt;span style="font-size: small;"&gt;&lt;span style="font-family: Calibri;"&gt;Compression method&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td valign="top"&gt;
&lt;p&gt;&lt;span style="font-size: small;"&gt;&lt;span style="font-family: Calibri;"&gt;1 byte&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td valign="top"&gt;
&lt;p&gt;&lt;span style="font-size: small;"&gt;&lt;span style="font-family: Calibri;"&gt;Filter method&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td valign="top"&gt;
&lt;p&gt;&lt;span style="font-size: small;"&gt;&lt;span style="font-family: Calibri;"&gt;1 byte&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td valign="top"&gt;
&lt;p&gt;&lt;span style="font-size: small;"&gt;&lt;span style="font-family: Calibri;"&gt;Interlace method&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td valign="top"&gt;
&lt;p&gt;&lt;span style="font-size: small;"&gt;&lt;span style="font-family: Calibri;"&gt;1 byte&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td valign="top"&gt;
&lt;p&gt;&lt;span style="font-size: small;"&gt;&lt;span style="font-family: Calibri;"&gt;CRC&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td valign="top"&gt;
&lt;p&gt;&lt;span style="font-size: small;"&gt;&lt;span style="font-family: Calibri;"&gt;4 bytes&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;p&gt;&lt;span style="font-family: Calibri; font-size: small;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: small;"&gt;&lt;span style="font-family: Calibri;"&gt;If bit 2 of the color type is nonzero, the image has an alpha channel.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: small;"&gt;&lt;span style="font-family: Calibri;"&gt;The&amp;nbsp;Microsoft logo png shown later in this post starts with the bytes (each consecutive pair of hexadigits gives a byte) 89504E470D0A1A0A 0000000D 49484452 000000FA 0000002D 08 06. These bytes have the meanings&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;table border="1" cellspacing="0" cellpadding="2"&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td valign="top"&gt;
&lt;p&gt;&lt;span style="font-size: small;"&gt;&lt;span style="font-family: Calibri;"&gt;png header&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td valign="top"&gt;
&lt;p&gt;&lt;span style="font-size: small;"&gt;&lt;span style="font-family: Calibri;"&gt;Chunk length&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td valign="top"&gt;
&lt;p&gt;&lt;span style="font-size: small;"&gt;&lt;span style="font-family: Calibri;"&gt;IHDR&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td valign="top"&gt;
&lt;p&gt;&lt;span style="font-size: small;"&gt;&lt;span style="font-family: Calibri;"&gt;Width&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td valign="top"&gt;
&lt;p&gt;&lt;span style="font-size: small;"&gt;&lt;span style="font-family: Calibri;"&gt;Height&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td valign="top"&gt;
&lt;p&gt;&lt;span style="font-size: small;"&gt;&lt;span style="font-family: Calibri;"&gt;Bit depth&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td valign="top"&gt;
&lt;p&gt;&lt;span style="font-size: small;"&gt;&lt;span style="font-family: Calibri;"&gt;Color type&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td valign="top"&gt;
&lt;p&gt;&lt;span style="font-size: small;"&gt;&lt;span style="font-family: Calibri;"&gt;89504E470D0A1A0A&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td valign="top"&gt;
&lt;p&gt;&lt;span style="font-size: small;"&gt;&lt;span style="font-family: Calibri;"&gt;0000000D&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td valign="top"&gt;
&lt;p&gt;&lt;span style="font-size: small;"&gt;&lt;span style="font-family: Calibri;"&gt;49484452&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td valign="top"&gt;
&lt;p&gt;&lt;span style="font-size: small;"&gt;&lt;span style="font-family: Calibri;"&gt;000000FA&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td valign="top"&gt;
&lt;p&gt;&lt;span style="font-size: small;"&gt;&lt;span style="font-family: Calibri;"&gt;0000002D&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td valign="top"&gt;
&lt;p&gt;&lt;span style="font-size: small;"&gt;&lt;span style="font-family: Calibri;"&gt;08&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td valign="top"&gt;
&lt;p&gt;&lt;span style="font-size: small;"&gt;&lt;span style="font-family: Calibri;"&gt;06&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;&lt;span style="font-size: small;"&gt;&lt;span style="font-family: Calibri;"&gt;Bit 2 of the color type 06 is 1, so there is an alpha channel. In fact, 06 means &amp;ldquo;Truecolour with alpha&amp;rdquo;.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Calibri; font-size: small;"&gt;Using &lt;/span&gt;&lt;a href="http://en.wikipedia.org/wiki/Graphics_Device_Interface"&gt;&lt;span style="color: #0563c1; font-family: Calibri; font-size: small;"&gt;GDI&lt;/span&gt;&lt;/a&gt;&lt;span style="font-family: Calibri; font-size: small;"&gt;, it&amp;rsquo;s easy to display the image with its built-in (alpha-channel) transparency. The &lt;/span&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/windows/desktop/dd183351(v=vs.85).aspx"&gt;&lt;span style="color: #0563c1; font-family: Calibri; font-size: small;"&gt;AlphaBlend&lt;/span&gt;&lt;/a&gt;&lt;span style="font-size: small;"&gt;&lt;span style="font-family: Calibri;"&gt;() function has a BLENDFUNCTION argument that lets you say an image has an alpha channel. Check the image&amp;rsquo;s pixel format (call IWICBitmapFrameDecode::GetPixelFormat()) and note whether the GUID returned corresponds to a bitmap with an alpha channel. If so, use a BLENDFUNCTION saying the image has an alpha channel. &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: small;"&gt;&lt;span style="font-family: Calibri;"&gt;Here&amp;rsquo;s a picture of the png logo on a yellow background and another on a red background. The red and yellow backgrounds are displayed because the png is transparent in those areas.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-70-95/5226.Logo.JPG"&gt;&lt;img src="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-70-95/5226.Logo.JPG" alt="" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: small;"&gt;&lt;span style="font-family: Calibri;"&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/windows/desktop/dd370990(v=vs.85).aspx"&gt;&lt;span style="color: #0563c1;"&gt;Direct 2D&lt;/span&gt;&lt;/a&gt; (D2D) doesn&amp;rsquo;t support all bitmap formats, so in converting from a WIC bitmap to a D2D bitmap you need to choose carefully. For example, the premultiplied bitmap format &lt;a title="GUID_WICPixelFormat32bppPBGRA" href="http://msdn.microsoft.com/en-us/library/windows/desktop/ee719797(v=vs.85).aspx"&gt;GUID_WICPixelFormat32bppPBGRA&lt;/a&gt; is supported by D2D, but I wasn&amp;rsquo;t able to get the straight GUID_WICPixelFormat32bppBGRA format to work correctly. With D2D that format always displays as a black rectangle. Maybe someone noted that the premultiplied alpha-channel bitmap is more efficient and therefore chose not to support the straight alpha-channel bitmap. In contrast, GDI handles all formats that I tried.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: small;"&gt;&lt;span style="font-family: Calibri;"&gt;Mystery of the black rectangles solved!&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Calibri; font-size: small;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10402917" width="1" height="1"&gt;</content><author><name>MurrayS3</name><uri>http://blogs.msdn.com/MurrayS/ProfileUrlRedirect.ashx</uri></author></entry><entry><title>RichEdit 8 Performance Improvements</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/murrays/archive/2013/02/22/richedit-8-performance-improvements.aspx" /><id>http://blogs.msdn.com/b/murrays/archive/2013/02/22/richedit-8-performance-improvements.aspx</id><published>2013-02-22T19:27:00Z</published><updated>2013-02-22T19:27:00Z</updated><content type="html">&lt;p&gt;&lt;span style="font-family: Calibri; font-size: small;"&gt;This post describes a couple of performance improvements introduced in RichEdit 8: 1) a more efficient display tree, and 2) a faster rich-text formatting mechanism. Performance is always of interest, partly to make the user experience more enjoyable (animations should be smooth, not jerky, and who wants to wait for things to happen?) and partly to save battery power. RichEdit 8 also has performance improvements when multiple stories are used, something I&amp;rsquo;ll describe in a future post. In contrast the &lt;/span&gt;&lt;a href="http://blogs.msdn.com/b/murrays/archive/2012/07/29/office-adopts-new-windows-display-technology.aspx"&gt;&lt;span style="color: #0563c1; font-family: Calibri; font-size: small;"&gt;DWrite path&lt;/span&gt;&lt;/a&gt;&lt;span style="font-size: small;"&gt;&lt;span style="font-family: Calibri;"&gt; introduced in RichEdit 8 is slower than the GDI path primarily because it handles default OpenType features. The features improve the typography, but they do take time to process. In fact, OneNote disables this extra processing, favoring speed over typographic elegance. We hope to improve the performance for elegant typography in time.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: small;"&gt;&lt;span style="font-family: Calibri;"&gt;RichEdit&amp;rsquo;s display tree for a multiline display consists of an array object called a CArray that contains CLine objects. The CLine object is a recursive structure used to cache display information about the text lines and table rows to be displayed on screen and other output devices. A CLine can represent a single line, or it can point to a CArray of CLine&amp;rsquo;s for table cells in a table row, or to a CArray of CLines for a math paragraph or for the lines in a table cell. A large file requires many CLine&amp;rsquo;s so in principle the CLine structure should be as small as possible given constraints of what data is needed for scrolling and displaying the text.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: small;"&gt;&lt;span style="font-family: Calibri;"&gt;Over the years, various metric variables have been added to the CLine structure in order to support enhanced display capabilities. Specifically Page/TableServices (PTS) needed three extra metrics, ideal layout (device independent, possibly subpixel) required five extra metrics, and OfficeArt (used for PowerPoint, Smart Art, and other clients) required four. Having all of these in the CLine penalizes simpler clients such as WordPad and even clients like OneNote when it doesn&amp;rsquo;t enable PTS. Accordingly RichEdit 8 stores the extra metrics in a property bag which is empty for simple cases like WordPad and is filled with just the metrics needed for the more elaborate models. For simple plain text, all lines have the same height and the same descent. Removing these values from the CLine would make it even smaller, but this feature isn't implemented in RichEdit 8. Another improvement would be to bypass measuring lines altogether if line wrapping is disabled. This could be handy for scanning through large plain-text data files.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: small;"&gt;&lt;span style="font-family: Calibri;"&gt;The second performance improvement speeds up character and paragraph formatting changes and also speeds up updates of the display arrays referred to in the first improvement. To understand this improvement, consider that when a user types characters, the characters are inserted into a text buffer gap. This improves typing performance because the buffer memory only has to be moved when the buffer fills up. The text buffer gap has been a RichEdit feature since Version 1.0. The character and paragraph format arrays (CArray&amp;rsquo;s of format runs) and the CArray&amp;rsquo;s of CLine&amp;rsquo;s also have always had buffer gaps, but up to RichEdit 8.0, their gaps were located at the ends of the CArray&amp;rsquo;s. So when a character format change is made in the middle of the array as during script itemization and a format run is added or deleted, a block move occurred. Similarly when you delete or type enough in the middle of a document to cause the number of CLine&amp;rsquo;s to change, a block move was needed. To speed this up, the CArray buffer gap was made moveable so that changes always occur in the gap. For C++ aficionados, the CArray&amp;nbsp;is actually a template class, so that it can be reused for many different kinds of objects, such as the CLine and the format runs.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10396302" width="1" height="1"&gt;</content><author><name>MurrayS3</name><uri>http://blogs.msdn.com/MurrayS/ProfileUrlRedirect.ashx</uri></author></entry><entry><title>RichEdit 8.0 Touch Support</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/murrays/archive/2013/01/29/richedit-8-0-touch-support.aspx" /><id>http://blogs.msdn.com/b/murrays/archive/2013/01/29/richedit-8-0-touch-support.aspx</id><published>2013-01-29T19:24:00Z</published><updated>2013-01-29T19:24:00Z</updated><content type="html">&lt;p&gt;Windows 8 introduced substantially better touch facilities than those available in Windows 7.&amp;nbsp; One cool thing is the new touch on-screen keyboard, which is enabled if you have a touch screen. To see it, swipe in from the right side, touch the cog icon for settings, touch the Keyboard, and then touch &amp;ldquo;Touch keyboard and handwriting panel&amp;rdquo;. This displays the touch keyboard across the bottom of the screen. As is typical with on-screen keyboards, this one shows upper-case letters when the shift key is pressed, alternate keys when an alt key is pressed, and selecting a different language keyboard displays the appropriate keys for that language. A new feature is that if you keep pressing a key, it may display a set of alternative keys around the original. For example if you press the a key, you&amp;rsquo;ll see a whole group of accented a keys, which you can then move to and insert. Similarly if you press the = key, you see a display of &amp;equiv; &amp;not; &amp;ne; &amp;asymp; ≉, which you can insert. Imagine, in principle you could design a math keyboard with all the Unicode math characters this way! This blog post doesn&amp;rsquo;t pursue this exciting possibility, but instead describes how a programmer can take advantage of some touch functionality added to RichEdit 8 in Windows 8.&lt;/p&gt;
&lt;p&gt;Touch facilities such as zooming with pinch and expand (reverse pinch) are typically handled by the client using &lt;a href="http://blogs.msdn.com/b/murrays/archive/2012/11/16/richedit-8-zoom-support.aspx"&gt;&lt;span style="color: #0000ff;"&gt;transforms&lt;/span&gt;&lt;/a&gt;. RichEdit itself has been generalized to handle the selection and grippers on Windows 8 touch devices. These features are available to clients who want to offer touch capabilities with standard Windows apps using msftedit.dll. For Windows RT apps based on the XAML &lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.controls.richeditbox.aspx"&gt;&lt;span style="color: #0000ff;"&gt;RichEditBox&lt;/span&gt;&lt;/a&gt; and &lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/br209683.aspx"&gt;&lt;span style="color: #0000ff;"&gt;TextBox&lt;/span&gt;&lt;/a&gt; controls, which also use msftedit.dll, touch facilities are handled by the XAML infrastructure.&lt;/p&gt;
&lt;p&gt;Specifically, sending an &lt;a href="http://msdn.microsoft.com/en-us/library/windows/desktop/Hh768375%28v=vs.85%29.aspx"&gt;&lt;span style="color: #0000ff;"&gt;EM_SETEDITSTYLEEX&lt;/span&gt;&lt;/a&gt; message with the SES_EX_MULTITOUCH extended edit style enables or disables the touch features. They are disabled by default, for which touch input is simulated by mouse messages. The new messages &lt;a href="http://msdn.microsoft.com/en-us/library/windows/desktop/hh768382%28v=vs.85%29.aspx"&gt;&lt;span style="color: #0000ff;"&gt;EM_SETTOUCHOPTIONS&lt;/span&gt;&lt;/a&gt; and &lt;a href="http://msdn.microsoft.com/en-us/library/windows/desktop/hh768372%28v=vs.85%29.aspx"&gt;&lt;span style="color: #0000ff;"&gt;EM_GETTOUCHOPTIONS&lt;/span&gt;&lt;/a&gt; can be used to control whether the selection handles (grippers) are displayed.&lt;/p&gt;
&lt;p&gt;Windows 8 has &lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/hh465334.aspx"&gt;&lt;span style="color: #0000ff;"&gt;gripper controls&lt;/span&gt;&lt;/a&gt;, which are a pair of transparent windows displaying gripper visuals and sending touch manipulation events back to the host, e.g., RichEdit. RichEdit 8 supports the following touch operations:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Smart caret placement on tap (snaps to the nearest word boundary)&lt;/li&gt;
&lt;li&gt;Dragging the gripper extends or adjusts the selection&lt;/li&gt;
&lt;li&gt;Tap on selection or gripper as well as Press and Hold brings up the context menu&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;When read-only mode is active, the behavior is modified so that a tap on a link activates the link and a tap on text selects a word.&lt;/p&gt;
&lt;p&gt;In addition to combining touch with keyboards as in the touch on-screen keyboard, one can combine touch with a stylus. Touch isn&amp;rsquo;t nearly as geometrically precise as a stylus. The two together can offer special functionality beyond what either can offer alone. For example, a touch can emulate a control key like ctrl or alt, while the stylus pinpoints the location to be altered/interrogated. Multitouch is already being used widely in zoom/expand, scrolling and other ways. Imagine the number of possibilities with multitouch and a stylus! People who are musically inclined and gamers have the dexterity to perform all sorts of amazing interactions. These possibilities are beyond what&amp;rsquo;s supported by RichEdit 8, but are certainly exciting prospects for the future.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10389274" width="1" height="1"&gt;</content><author><name>MurrayS3</name><uri>http://blogs.msdn.com/MurrayS/ProfileUrlRedirect.ashx</uri></author></entry><entry><title>Program Annotations</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/murrays/archive/2012/12/31/program-annotations.aspx" /><id>http://blogs.msdn.com/b/murrays/archive/2012/12/31/program-annotations.aspx</id><published>2012-12-31T19:50:00Z</published><updated>2012-12-31T19:50:00Z</updated><content type="html">&lt;p&gt;&lt;span style="font-size: small;"&gt;&lt;span style="font-family: Calibri;"&gt;Notation is a favorite topic of mine being at least partly inspired by Bertrand Russell, who once &lt;a href="http://www.rjgeib.com/thoughts/russell/russell16.html"&gt;&lt;span style="text-decoration: underline;"&gt;wrote&lt;/span&gt;&lt;/a&gt;, &amp;ldquo;A good notation has a subtlety and suggestiveness which at times make it seem almost like a live teacher&amp;hellip;and a perfect notation would be a substitute for thought.&amp;rdquo; An earlier &lt;a href="http://blogs.msdn.com/b/murrays/archive/2010/08/31/linear-format-notations-for-mathematics.aspx"&gt;post&lt;/a&gt; on notation deals with the linear format for mathematics used in Microsoft Office. The present post deals with annotations used to help code-proofing tools verify the correctness of computer programs, especially those written in C++. &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: small;"&gt;&lt;span style="font-family: Calibri;"&gt;The vast majority of programs in both Windows and Microsoft Office is written in C++. This choice benefits performance substantially, but C++ can act like a double-edged knife: you can cut with it, but it can cut you too! Accordingly people have written programs like &lt;/span&gt;&lt;a href="http://blogs.msdn.com/b/vcblog/archive/2008/02/05/prefast-and-sal-annotations.aspx"&gt;&lt;span style="text-decoration: underline;"&gt;Prefast&lt;/span&gt;&lt;/a&gt; that analyze programs for various kinds of errors, such as buffer overflows and null pointer dereferences, that cause crashes and security leaks. The analysis is greatly improved if annotations are included that define how the variables in the code are designed to be used. A great variety of annotations have been used over the years, but the current set, called &lt;a href="http://msdn.microsoft.com/en-us/library/ms182032.aspx"&gt;SAL&lt;/a&gt; (source code annotation language) seems to be stabilizing and is used in both Office 2013 and Windows 8. This stabilization greatly aids development of programs like RichEdit, which are shipped in both environments.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: small;"&gt;While the benefits of SAL are great in improving program reliability, the annotations add substantial notational overhead that can slow down a programmer&amp;rsquo;s understanding of the code. The simple annotations like _In_ and _In_opt_ are easy enough to read and understand, but as the annotations have become more and more detailed, they have become increasingly opaque and unwieldy, such as _Out_opt_cap_post_count_(c, d) (don&amp;rsquo;t ask!). For example, this shows up in the RichEdit code base in the function header&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;HRESULT&amp;nbsp;CMathFont::GetMathGlyphVariant (&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; PCLSMATHSTYLE&amp;nbsp; pstyle,&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // IN: Math style&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; USHORT&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;gindex,&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // IN: Glyph index&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; MATH_EXTENSION&amp;nbsp;extType,&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // IN: Extension type&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; LONG&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;lDimension,&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // IN: Measurement requested&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; USHORT&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;cMaxComponent,&amp;nbsp;&amp;nbsp;&amp;nbsp;// IN: Maximum number of glyph components&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; BOOL *&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;pfVariantFound,&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;// OUT: Returns true iff a variant is found&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; USHORT *&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;pcComponents,&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // OUT:&amp;nbsp;# components in resulting construct&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; _Out_opt_cap_post_count_(cMaxComponent, *pcComponents)&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; USHORT *&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;piComponents,&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // OUT: List of component glyph IDs&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; _Out_opt_cap_post_count_(cMaxComponent, *pcComponents)&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; LONG *&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;plOffsets)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // OUT: List of glyph offsets&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: small;"&gt;This function is used to get one or more glyphs used to display the input glyph at a particular size, such as a large integral sign. One can say that even without the _Out_opt_cap_post_count_(c, d) annotations this is a complicated function prototype, but with the annotations it&amp;rsquo;s particularly hard to read. And the function prototype is missing SAL annotations for the other argument variables (the comments explain the usage, but the code analysis tools don&amp;rsquo;t understand the comments).&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: small;"&gt;While the annotations are included primarily for the code analysis tools, they do provide useful information for programmers if they can understand them and they should be available for inspection by programmers. Furthermore a programmer had to add them in the first place. They are not added automatically, although their absence is flagged by the code analysis tools.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: small;"&gt;So how can we get around this quandary of needing the annotations but not always wanting them staring us in the face? Two additions to the Visual Studio&amp;rsquo;s C++ editing environment would help: 1) tooltips that explain the annotations in plain English, and 2) the ability to suppress their display. &amp;nbsp;Visual Studio has long been able to collapse/expand the bodies of if() statements. It could similarly provide the ability to collapse/expand the SAL annotations.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: small;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10381528" width="1" height="1"&gt;</content><author><name>MurrayS3</name><uri>http://blogs.msdn.com/MurrayS/ProfileUrlRedirect.ashx</uri></author></entry><entry><title>RichEdit 8 Zoom Support</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/murrays/archive/2012/11/16/richedit-8-zoom-support.aspx" /><id>http://blogs.msdn.com/b/murrays/archive/2012/11/16/richedit-8-zoom-support.aspx</id><published>2012-11-16T22:18:00Z</published><updated>2012-11-16T22:18:00Z</updated><content type="html">&lt;p&gt;&lt;span style="font-family: Calibri; font-size: small;"&gt;In this day and age with touch pinch and expand zooming of screens, zoom is everywhere! So you might wonder how to zoom the contents of a RichEdit control. There are two ways: 1) maintaining the display width and rewrapping the text as necessary to fill the client rectangle, and 2) zooming everything including the display width. The first way can be called &lt;em&gt;rewrapped zoom&lt;/em&gt; and is enabled by sending an &lt;/span&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/windows/desktop/bb774296(v=vs.85).aspx"&gt;&lt;span style="color: #0563c1; font-family: Calibri; font-size: small;"&gt;EM_SETZOOM&lt;/span&gt;&lt;/a&gt;&lt;span style="font-family: Calibri; font-size: small;"&gt; message or by providing an appropriate display height in the &lt;/span&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/windows/desktop/bb787664(v=vs.85).aspx"&gt;&lt;span style="color: #0563c1; font-family: Calibri; font-size: small;"&gt;ITextHost::TxGetExtent&lt;/span&gt;&lt;/a&gt;&lt;span style="font-size: small;"&gt;&lt;span style="font-family: Calibri;"&gt; callback. Rewrapped zoom can be accomplished by RichEdit itself, requiring a minimum of host effort. It&amp;rsquo;s useful notably in that no panning is needed to read the text. For example, the Amazon Kindle offers rewrapped zoom to allow readers to view text at a larger size without panning.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Calibri; font-size: small;"&gt;The second way can be called &lt;em&gt;unrewrapped zoom&lt;/em&gt; and has to be implemented in the host since the client RECT zooms along with the contents. This is the typical zoom method used on cell phones, tablets, and in many Windows applications such as OneNote and Word. It requires panning for larger zoom sizes when the text lines no longer fit within the window width. It uses a six-factor 2D transform and the host has to &amp;ldquo;unzoom&amp;rdquo; mouse coordinates so that RichEdit hit testing works correctly. For the traditional Windows GDI environment, the hosts sets the zoom factor by calling &lt;/span&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/windows/desktop/dd145104(v=vs.85).aspx"&gt;&lt;span style="color: #0563c1; font-family: Calibri; font-size: small;"&gt;SetWorldTransform&lt;/span&gt;&lt;/a&gt;&lt;span style="font-family: Calibri; font-size: small;"&gt;(). For the relatively new D2D environment, the host sets the zoom factor by calling &lt;/span&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/windows/desktop/dd742857(v=vs.85).aspx"&gt;&lt;span style="color: #0563c1; font-family: Calibri; font-size: small;"&gt;ID2D1RenderTarget::SetTransform&lt;/span&gt;&lt;/a&gt;&lt;span style="font-size: small;"&gt;&lt;span style="font-family: Calibri;"&gt;(). Both calls pass the same 2&amp;times;3 transform matrix, although the matrices have different names. The host can also implement rewrapped zoom by unzooming the display width appropriately, although it&amp;rsquo;s easier to let RichEdit handle rewrapped zoom.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: small;"&gt;&lt;span style="font-family: Calibri;"&gt;Up through RichEdit 8, both kinds of zoom work in GDI mode. In RichEdit 8, unrewrapped zoom works in D2D mode; earlier versions of RichEdit don&amp;rsquo;t have a D2D mode. RichEdit 8 doesn&amp;rsquo;t rerasterize images when the zoom factor changes, so images can become blurry even when they have high native resolution.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Calibri; font-size: small;"&gt;EM_SETZOOM provides the zoom numerator in wparam and the zoom denominator in lparam. Alternatively the numerator is given by the height returned by the ITextHost::TxGetClientRect() and the denominator by the vertical size returned by &lt;/span&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/windows/desktop/bb787664(v=vs.85).aspx"&gt;&lt;span style="color: #0563c1; font-family: Calibri; font-size: small;"&gt;ITextHost::TxGetExtent&lt;/span&gt;&lt;/a&gt;&lt;span style="font-size: small;"&gt;&lt;span style="font-family: Calibri;"&gt;. The latter is in HIMETRIC units (0.01 mm), and is converted to pixels for the zoom denominator. The zoom factor is incorporated into the horizontal and vertical display device resolution factors when GDI is being used to display text. These factors are set to EMUs per inch (914400/inch) for the D2D/DWrite mode, and hence RichEdit 8 doesn&amp;rsquo;t offer rewrapped zoom in D2D mode. Hopefully someday!&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Calibri; font-size: small;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10369397" width="1" height="1"&gt;</content><author><name>MurrayS3</name><uri>http://blogs.msdn.com/MurrayS/ProfileUrlRedirect.ashx</uri></author></entry><entry><title>Inserting Tables Using the Keyboard</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/murrays/archive/2012/10/13/inserting-tables-using-the-keyboard.aspx" /><id>http://blogs.msdn.com/b/murrays/archive/2012/10/13/inserting-tables-using-the-keyboard.aspx</id><published>2012-10-13T00:05:00Z</published><updated>2012-10-13T00:05:00Z</updated><content type="html">&lt;p&gt;&lt;span style="font-size: small;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;This post describes a little trick that lets you insert a table into RichEdit and into Word just using the keyboard. Admittedly in Word, you can use the handy table tool on the Insert tab with a mouse or with a keyboard. But in WordPad and the Windows RT RichEditBox, you don&amp;rsquo;t have a table tool. &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: small;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;So here&amp;rsquo;s the trick: on a line of its own type a plus (+) followed by as many dashes (-) as needed for the width of the first cell, followed by a plus to end that cell. If you only want a one column table, just hit the Enter key and you have a one cell table. To have more cells in the row, type more dashes and pluses, being sure to end the line with a plus. For example, hitting the Enter key at the end of the line&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: small;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;+-----------------------+---------+-------------------------------------+&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: small;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;inserts the table row&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;table border="1" cellspacing="0" cellpadding="0"&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td width="141" valign="top"&gt;
&lt;p&gt;&lt;span style="font-family: Calibri; font-size: small;" face="Calibri" size="3"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td width="60" valign="top"&gt;
&lt;p&gt;&lt;span style="font-family: Calibri; font-size: small;" face="Calibri" size="3"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td width="217" valign="top"&gt;
&lt;p&gt;&lt;span style="font-family: Calibri; font-size: small;" face="Calibri" size="3"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;&lt;span style="font-size: small;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;When you have as many cells as you want, to get another row, put the insertion point at the end of the row and hit the Enter key. Alternatively put the insertion point in the last cell and hit the Tab key. If the insertion point isn&amp;rsquo;t in the last cell of the table, a Tab advances to the next cell and a Shift+Tab backs up to the previous cell. When the insertion point is in the last cell of a table, the Tab key inserts another row. So pretty quickly you can enter a simple table with arbitrary numbers of cells, rows, and cell sizes. You can use the mouse to change the width of the columns. &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: small;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;You can also change the alignment of a table by selecting the whole table including the end of row marks and hitting ctrl+e or ctrl+r for centering and right-justifying the table, respectively. Ctrl+L left justifies the table. In Word there are a number of other cool tools such as the one to autofit the contents of a table (select the table, right-mouse click on it and choose the Autofit option).&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10359288" width="1" height="1"&gt;</content><author><name>MurrayS3</name><uri>http://blogs.msdn.com/MurrayS/ProfileUrlRedirect.ashx</uri></author></entry><entry><title>RichEdit 8.0 Accessibility</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/murrays/archive/2012/09/14/richedit-8-0-accessibility.aspx" /><id>http://blogs.msdn.com/b/murrays/archive/2012/09/14/richedit-8-0-accessibility.aspx</id><published>2012-09-14T20:24:57Z</published><updated>2012-09-14T20:24:57Z</updated><content type="html">&lt;p&gt;&lt;span style="font-family: Times New Roman; font-size: small;" face="Times New Roman" size="3"&gt; &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Calibri; font-size: small;" face="Calibri" size="3"&gt;An important part of a computer&amp;rsquo;s user interface is to provide for user interaction alternatives to the usual sight-oriented methods. Such capability requires programmatic access to what&amp;rsquo;s on the screen so that screen reader programs can express the content using voice or other means. &lt;/span&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ms747327.aspx"&gt;&lt;span style="color: #0000ff; font-family: Calibri; font-size: small;" face="Calibri" size="3" color="#0000ff"&gt;Microsoft UI Automation (UIA)&lt;/span&gt;&lt;/a&gt;&lt;span style="font-size: small;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt; provides such access. A valuable side benefit is that test scripts can use UIA to test the content of a wide variety of programs without having to understand the individual program object models.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Times New Roman; font-size: small;" face="Times New Roman" size="3"&gt; &lt;/span&gt;&lt;span style="font-family: Calibri; font-size: small;" face="Calibri" size="3"&gt;RichEdit 8 has an implementation of UIA that exposes most objects in a RichEdit instance. This is done via the &lt;/span&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ms745158.aspx"&gt;&lt;span style="color: #0000ff; font-family: Calibri; font-size: small;" face="Calibri" size="3" color="#0000ff"&gt;UIA Text Pattern&lt;/span&gt;&lt;/a&gt;&lt;span style="font-family: Calibri; font-size: small;" face="Calibri" size="3"&gt; and includes basic character and paragraph formatting, images, OLE objects, math zones, tables, hyperlinks, and the text inside or associated with these objects. The implementation is showcased in WordPad on Windows 8 and provides a popular (inside Microsoft) example of how to implement UIA for text applications. All UIA value providers are read only. For example, you can read out a URL&amp;rsquo;s text but cannot change it. To change it programmatically, you can use RichEdit&amp;rsquo;s &lt;/span&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/windows/desktop/bb787607(v=vs.85).aspx"&gt;&lt;span style="color: #0000ff; font-family: Calibri; font-size: small;" face="Calibri" size="3" color="#0000ff"&gt;Text Object Model&lt;/span&gt;&lt;/a&gt;&lt;span style="font-family: Calibri; font-size: small;" face="Calibri" size="3"&gt; (TOM) or the Microsoft &lt;/span&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms629032(v=vs.85).aspx"&gt;&lt;span style="color: #0000ff; font-family: Calibri; font-size: small;" face="Calibri" size="3" color="#0000ff"&gt;Text Services Framework&lt;/span&gt;&lt;/a&gt;&lt;span style="font-size: small;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Times New Roman; font-size: small;" face="Times New Roman" size="3"&gt; &lt;/span&gt;&lt;span style="font-family: Calibri; font-size: small;" face="Calibri" size="3"&gt;If you implement a windowless RichEdit control, you hook up its UIA tree by calling ITextServices::QueryInterface() for an &lt;/span&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/windows/desktop/hh768433(v=vs.85).aspx"&gt;&lt;span style="color: #0000ff; font-family: Calibri; font-size: small;" face="Calibri" size="3" color="#0000ff"&gt;IRicheditWindowlessAccessibility&lt;/span&gt;&lt;/a&gt;&lt;span style="font-family: Calibri; font-size: small;" face="Calibri" size="3"&gt; interface and then call &lt;/span&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/windows/desktop/Hh768435(v=vs.85).aspx"&gt;&lt;span style="color: #0000ff; font-family: Calibri; font-size: small;" face="Calibri" size="3" color="#0000ff"&gt;IRicheditWindowlessAccessibility::CreateProvider&lt;/span&gt;&lt;/a&gt;&lt;span style="font-family: Calibri; font-size: small;" face="Calibri" size="3"&gt;() with an &lt;/span&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/windows/desktop/hh448787(v=vs.85).aspx"&gt;&lt;span style="color: #0000ff; font-family: Calibri; font-size: small;" face="Calibri" size="3" color="#0000ff"&gt;IRawElementProviderWindowlessSite&lt;/span&gt;&lt;/a&gt;&lt;span style="font-family: Calibri; font-size: small;" face="Calibri" size="3"&gt; to get the UIA standard base interface &lt;/span&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.automation.provider.irawelementprovidersimple.aspx"&gt;&lt;span style="color: #0000ff; font-family: Calibri; font-size: small;" face="Calibri" size="3" color="#0000ff"&gt;IRawElementProviderSimple&lt;/span&gt;&lt;/a&gt;&lt;span style="font-size: small;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Times New Roman; font-size: small;" face="Times New Roman" size="3"&gt; &lt;/span&gt;&lt;span style="font-family: Calibri; font-size: small;" face="Calibri" size="3"&gt;You can examine the complete UIA tree using the Microsoft SDK &lt;/span&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/windows/desktop/dd318521(v=vs.85).aspx"&gt;&lt;span style="color: #0000ff; font-family: Calibri; font-size: small;" face="Calibri" size="3" color="#0000ff"&gt;inspect.exe&lt;/span&gt;&lt;/a&gt;&lt;span style="font-family: Calibri; font-size: small;" face="Calibri" size="3"&gt;. The raw text for a RichEdit instance is given for the &amp;ldquo;RichEdit Control&amp;rdquo; document node. This raw text includes the structure characters defining any &lt;/span&gt;&lt;a href="http://blogs.msdn.com/b/murrays/archive/2008/09/15/richedit-s-nested-table-facility.aspx"&gt;&lt;span style="color: #0000ff; font-family: Calibri; font-size: small;" face="Calibri" size="3" color="#0000ff"&gt;table-row start and end delimiters&lt;/span&gt;&lt;/a&gt;&lt;span style="font-family: Calibri; font-size: small;" face="Calibri" size="3"&gt; and cell markers, as well as the &lt;/span&gt;&lt;a href="http://blogs.msdn.com/b/murrays/archive/2007/03/16/math-find-replace-and-rich-text-searches.aspx"&gt;&lt;span style="color: #0000ff; font-family: Calibri; font-size: small;" face="Calibri" size="3" color="#0000ff"&gt;math structure characters&lt;/span&gt;&lt;/a&gt;&lt;span style="font-family: Calibri; font-size: small;" face="Calibri" size="3"&gt; for math objects like fractions. A math-zone object is treated as an image with a text string giving the math in the &lt;/span&gt;&lt;a href="http://www.unicode.org/notes/tn28/UTN28-PlainTextMath-v3.pdf"&gt;&lt;span style="color: #0000ff; font-family: Calibri; font-size: small;" face="Calibri" size="3" color="#0000ff"&gt;linear format&lt;/span&gt;&lt;/a&gt;&lt;span style="font-size: small;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;. That format gives a pretty good idea of the math content especially if it&amp;rsquo;s the way the user enters math. Tables are shown as a tree that can be expanded to show each cell&amp;rsquo;s plain text.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Times New Roman; font-size: small;" face="Times New Roman" size="3"&gt; &lt;/span&gt;&lt;span style="font-family: Calibri; font-size: small;" face="Calibri" size="3"&gt;The UIA text range is similar to the original TOM &lt;/span&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/windows/desktop/bb774058(v=vs.85).aspx"&gt;&lt;span style="color: #0000ff; font-family: Calibri; font-size: small;" face="Calibri" size="3" color="#0000ff"&gt;ITextRange&lt;/span&gt;&lt;/a&gt;&lt;span style="font-family: Calibri; font-size: small;" face="Calibri" size="3"&gt; and the TOM specification influenced some of the UIA text range choices. Unlike &lt;/span&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/windows/desktop/Hh768622(v=vs.85).aspx"&gt;&lt;span style="color: #0000ff; font-family: Calibri; font-size: small;" face="Calibri" size="3" color="#0000ff"&gt;ITextRange2&lt;/span&gt;&lt;/a&gt;&lt;span style="font-family: Calibri; font-size: small;" face="Calibri" size="3"&gt;, the UIA text range doesn&amp;rsquo;t provide access to math text semantics. In this connection, it could be handy if UIA added an ITextMathProvider interface to aid in communicating math text verbally. Alternatively a &lt;/span&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ee696164(v=vs.85).aspx"&gt;&lt;span style="color: #0000ff; font-family: Calibri; font-size: small;" face="Calibri" size="3" color="#0000ff"&gt;UIA custom property&lt;/span&gt;&lt;/a&gt;&lt;span style="font-family: Calibri; font-size: small;" face="Calibri" size="3"&gt; could be defined that returns the MathML for math zones. MathML has become an important format in &lt;/span&gt;&lt;a href="http://www.dessci.com/en/solutions/access/mathaccess.htm"&gt;&lt;span style="color: #0000ff; font-family: Calibri; font-size: small;" face="Calibri" size="3" color="#0000ff"&gt;math accessibility&lt;/span&gt;&lt;/a&gt;&lt;span style="font-size: small;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;. Only one property would be needed. Its UIAutomationPropertyInfo structure would contain the property GUID, the UIAutomationPropertyInfo::pProgrammaticName = L&amp;rdquo;MathML&amp;rdquo; and the UIAutomationPropertyInfo::type = UIAutomationType_String. One could be more specific and use L&amp;rdquo;Presentation MathML&amp;rdquo;, but since it&amp;rsquo;s part of a text pattern, a client would probably assume it&amp;rsquo;s Presentation MathML and not Content MathML.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Times New Roman; font-size: small;" face="Times New Roman" size="3"&gt; &lt;/span&gt;&lt;span style="font-size: small;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;An advantage of a built-in math provider is that the internal Office representation of math is a bit closer to what one would say in speaking the math. For example, the internal (and external OMML) representation uses an &lt;i&gt;n&lt;/i&gt;-ary object for integrals, summations, and the like, so a reader immediately knows the kind of operation involved. This is simpler than MathML&amp;rsquo;s use of &amp;lt;msub&amp;gt;, &amp;lt;msup&amp;gt;, &amp;lt;msubsup&amp;gt;, &amp;lt;mover&amp;gt;, &amp;lt;munder&amp;gt;, and &amp;lt;munderover&amp;gt;, all of which represent &lt;i&gt;n&lt;/i&gt;-ary expressions if their base is an &lt;i&gt;n&lt;/i&gt;-ary operator. But appropriate programming can parse the MathML and there are readers that make MathML accessible, so a MathML UI custom property is an easy way to math-enable UIA. For MathML-unaware UIA clients, the RichEdit 8.0 image object with a math linear format string is a good fallback.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: small;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;Thanks go to Rick Sailor, who implemented RichEdit 8.0's UIA support and answered many questions about it.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10349610" width="1" height="1"&gt;</content><author><name>MurrayS3</name><uri>http://blogs.msdn.com/MurrayS/ProfileUrlRedirect.ashx</uri></author></entry><entry><title>RichEdit Spell Checking, Autocorrection and Prediction</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/murrays/archive/2012/08/31/richedit-spell-checking-autocorrection-and-prediction.aspx" /><id>http://blogs.msdn.com/b/murrays/archive/2012/08/31/richedit-spell-checking-autocorrection-and-prediction.aspx</id><published>2012-08-31T15:32:39Z</published><updated>2012-08-31T15:32:39Z</updated><content type="html">&lt;p&gt;&lt;span style="font-family: Times New Roman; font-size: small;" face="Times New Roman" size="3"&gt; &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Calibri; font-size: small;" face="Calibri" size="3"&gt;RichEdit has provided support for client spell checking (&lt;/span&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/windows/desktop/bb787607(v=vs.85).aspx"&gt;&lt;span style="color: #0000ff; font-family: Calibri; font-size: small;" face="Calibri" size="3" color="#0000ff"&gt;TOM object model&lt;/span&gt;&lt;/a&gt;&lt;span style="font-family: Calibri; font-size: small;" face="Calibri" size="3"&gt; and temporary character formatting&amp;mdash;see &lt;/span&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/windows/desktop/bb787865(v=vs.85).aspx"&gt;&lt;span style="color: #0000ff; font-family: Calibri; font-size: small;" face="Calibri" size="3" color="#0000ff"&gt;tomApplyTmp&lt;/span&gt;&lt;/a&gt;&lt;span style="font-family: Calibri; font-size: small;" face="Calibri" size="3"&gt;) and autocorrect (see &lt;/span&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/windows/desktop/Hh768374(v=vs.85).aspx"&gt;&lt;span style="color: #0000ff; font-family: Calibri; font-size: small;" face="Calibri" size="3" color="#0000ff"&gt;EM_SETAUTOCORRECTPROC&lt;/span&gt;&lt;/a&gt;&lt;span style="font-family: Calibri; font-size: small;" face="Calibri" size="3"&gt;) for many years. But it has been the RichEdit client&amp;rsquo;s responsibility to access the spell-checking and autocorrection components, except for the built-in math autocorrect option. For clients like OneNote and Outlook, such a responsibility is a small part of the app. But for little programs, accessing proofing components can be arduous. This would be especially true for small apps written using &lt;/span&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/br211377.aspx"&gt;&lt;span style="color: #0000ff; font-family: Calibri; font-size: small;" face="Calibri" size="3" color="#0000ff"&gt;Windows RT&lt;/span&gt;&lt;/a&gt;&lt;span style="font-size: small;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Calibri; font-size: small;" face="Calibri" size="3"&gt;Accordingly, RichEdit 8 was enhanced to be able to access the Windows 8 spell-checking and autocorrection components directly. The traditional Windows client using msftedit.dll on Windows 8 enables this functionality by sending an &lt;/span&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/windows/desktop/bb774250(v=vs.85).aspx"&gt;&lt;span style="color: #0000ff; font-family: Calibri; font-size: small;" face="Calibri" size="3" color="#0000ff"&gt;EM_SETLANGOPTIONS&lt;/span&gt;&lt;/a&gt;&lt;span style="font-family: Calibri; font-size: small;" face="Calibri" size="3"&gt; message with one or more of the options &lt;/span&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/windows/desktop/bb788040(v=vs.85).aspx"&gt;&lt;span style="color: #0000ff; font-family: Calibri; font-size: small;" face="Calibri" size="3" color="#0000ff"&gt;IMF_SPELLCHECKING, IMF_TKBAUTOCORRECTION, and IMF_TKBPREDICTION&lt;/span&gt;&lt;/a&gt;&lt;span style="font-family: Calibri; font-size: small;" face="Calibri" size="3"&gt;. The client also needs to enable the &lt;/span&gt;&lt;a href="http://en.wikipedia.org/wiki/Text_Services_Framework"&gt;&lt;span style="color: #0000ff; font-family: Calibri; font-size: small;" face="Calibri" size="3" color="#0000ff"&gt;Text Foundation Services&lt;/span&gt;&lt;/a&gt;&lt;span style="font-family: Calibri; font-size: small;" face="Calibri" size="3"&gt; by sending an &lt;/span&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/windows/desktop/bb774236(v=vs.85).aspx"&gt;&lt;span style="color: #0000ff; font-family: Calibri; font-size: small;" face="Calibri" size="3" color="#0000ff"&gt;EM_SETEDITSTYLE&lt;/span&gt;&lt;/a&gt;&lt;span style="font-size: small;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt; message with the flags SES_USECTF, SES_CTFALLOWEMBED, SES_CTFALLOWSMARTTAG, and SES_CTFALLOWPROOFING. &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Calibri; font-size: small;" face="Calibri" size="3"&gt;In the Windows RT &lt;/span&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.controls.richeditbox.aspx"&gt;&lt;span style="color: #0000ff; font-family: Calibri; font-size: small;" face="Calibri" size="3" color="#0000ff"&gt;RichEditBox&lt;/span&gt;&lt;/a&gt;&lt;span style="font-family: Calibri; font-size: small;" face="Calibri" size="3"&gt;, which uses a rich-text RichEdit control, spell checking is enabled by default. The Windows RT &lt;/span&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.controls.textbox.aspx"&gt;&lt;span style="color: #0000ff; font-family: Calibri; font-size: small;" face="Calibri" size="3" color="#0000ff"&gt;TextBox&lt;/span&gt;&lt;/a&gt;&lt;span style="font-size: small;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;, which uses a plain-text RichEdit control, also can have spell checking, but spell checking is disabled by default. You can change the setting using the Properties pane. Bogdan Radakovic, a developer in Windows 8, integrated the proofing features into RichEdit 8.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Times New Roman; font-size: small;" face="Times New Roman" size="3"&gt; &lt;/span&gt;&lt;span style="font-family: Calibri; font-size: small;" face="Calibri" size="3"&gt;To try the proofing features out, I fired up &lt;/span&gt;&lt;a href="http://www.microsoft.com/visualstudio/11/en-us/downloads"&gt;&lt;span style="color: #0000ff; font-family: Calibri; font-size: small;" face="Calibri" size="3" color="#0000ff"&gt;Visual Studio 12&lt;/span&gt;&lt;/a&gt;&lt;span style="font-size: small;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt; and created a new C++ project for the &amp;ldquo;Windows Store&amp;rdquo; using the &amp;ldquo;Blank App (XAML)&amp;rdquo; template. I dragged a RichEditBox from the Toolbox into the design view for the MainPage.xaml file. The RichEditBox starts out really small, so I expanded it to a reasonable size for typing text and built and ran the project. To my delight, my typing was proofed and autocorrected very nicely! The keyboard language is used to select the current proofing tools. So I switched to a German keyboard and typed in some text. Sure enough, the German proofing tools are used, which is very cool (I included the German proofing tools in my US Windows 8 installation). But if I type German using an English keyboard, I see lots of words with red-squiggle underlines. The proofing tools do not attempt to guess the language on the fly. For most people, this is a reasonable approach, especially since language detection isn&amp;rsquo;t infallible. Possibly in the next version, language detection will be offered as an option.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10345386" width="1" height="1"&gt;</content><author><name>MurrayS3</name><uri>http://blogs.msdn.com/MurrayS/ProfileUrlRedirect.ashx</uri></author></entry><entry><title>Office Adopts New Windows Display Technology</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/murrays/archive/2012/07/29/office-adopts-new-windows-display-technology.aspx" /><id>http://blogs.msdn.com/b/murrays/archive/2012/07/29/office-adopts-new-windows-display-technology.aspx</id><published>2012-07-29T18:58:00Z</published><updated>2012-07-29T18:58:00Z</updated><content type="html">&lt;p&gt;&lt;span style="font-family: Calibri; font-size: small;" face="Calibri" size="3"&gt;Office 2013 has undergone a substantial shift to a relatively new display facility, &lt;/span&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/windows/desktop/dd370990(v=vs.85).aspx"&gt;&lt;span style="color: #0000ff; font-family: Calibri; font-size: small;" face="Calibri" size="3" color="#0000ff"&gt;Direct2D&lt;/span&gt;&lt;/a&gt;&lt;span style="font-family: Calibri; font-size: small;" face="Calibri" size="3"&gt;, and a new text facility, &lt;/span&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/windows/desktop/dd368038(v=vs.85).aspx"&gt;&lt;span style="color: #0000ff; font-family: Calibri; font-size: small;" face="Calibri" size="3" color="#0000ff"&gt;DirectWrite&lt;/span&gt;&lt;/a&gt;&lt;span style="font-family: Calibri; font-size: small;" face="Calibri" size="3"&gt;. These are the display facilities that are used on Windows Phone 8, the new Windows RT slates, and optionally on Windows 7 &amp;amp; 8. Up through Office 2010, the Windows Graphics Device Interface (&lt;/span&gt;&lt;a href="http://en.wikipedia.org/wiki/Graphics_Device_Interface"&gt;&lt;span style="color: #0000ff; font-family: Calibri; font-size: small;" face="Calibri" size="3" color="#0000ff"&gt;GDI&lt;/span&gt;&lt;/a&gt;&lt;span style="font-family: Calibri; font-size: small;" face="Calibri" size="3"&gt;) and complex script support by &lt;/span&gt;&lt;a href="http://en.wikipedia.org/wiki/Uniscribe"&gt;&lt;span style="color: #0000ff; font-family: Calibri; font-size: small;" face="Calibri" size="3" color="#0000ff"&gt;Uniscribe&lt;/span&gt;&lt;/a&gt;&lt;span style="font-family: Calibri; font-size: small;" face="Calibri" size="3"&gt; were used. RichEdit 8.0 interfaces to both kinds of display technologies, but a given RichEdit instance uses only one of them. This post describes some of the advantages of using the new display facilities along with some of the problems we encountered in supporting them. One of the challenges was ensuring that math display wasn&amp;rsquo;t broken in the Direct2D/DirectWrite world. Another was to implement higher-level BiDi protocols using DirectWrite, which was designed to support the &lt;/span&gt;&lt;a href="http://www.unicode.org/reports/tr9/"&gt;&lt;span style="color: #0000ff; font-family: Calibri; font-size: small;" face="Calibri" size="3" color="#0000ff"&gt;Unicode Bidi Algorithm&lt;/span&gt;&lt;/a&gt;&lt;span style="font-size: small;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt; (UBA) only.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: small;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;Direct2D and DirectWrite are modern components that can take advantage of graphics acceleration hardware. DirectWrite supports better text placement using subpixel, device independent layout along with ClearType or other antialiasing methods. So in principle, it&amp;rsquo;s a big win to move forward to these components. Meanwhile GDI and Uniscribe have been around for years and have been taught to handle all sorts of nonobvious problems. It&amp;rsquo;s not easy to produce new code with their generality. Furthermore, RichEdit needs to be able to use either DirectWrite Version 1.0, which ships with Windows 7, or the more powerful DirectWrite Version 2.0 that ships with Windows 8. As a result, it was a bit of a tour de force to generalize RichEdit to interface smoothly to these three different display models. The factorization we&amp;rsquo;ve done has simplified getting RichEdit onto other platforms as well, such as the Android and iOS operating systems.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: small;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;As an example of GDI tricks, if you specify the charset in creating a font object, GDI will ensure that you get a font that handles that charset. Admittedly charsets cover only a subset of the world&amp;rsquo;s languages (no Indic, Syriac, etc.), but they do cover many important languages. Another trick is if a character is an end-user-defined character (EUDC) in the Unicode Private Use Area, GDI will ensure that you see a glyph by searching through registered EUDC fonts. These characters are not defined in the Unicode Standard, so you can&amp;rsquo;t use them reliably for text interchange. But they are popular in CJK locales and a given machine may have fonts with the glyphs that the user wants.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Calibri; font-size: small;" face="Calibri" size="3"&gt;Uniscribe was developed alongside &lt;/span&gt;&lt;a href="http://blogs.msdn.com/b/murrays/archive/2006/11/15/lineservices.aspx"&gt;&lt;span style="color: #0000ff; font-family: Calibri; font-size: small;" face="Calibri" size="3" color="#0000ff"&gt;LineServices&lt;/span&gt;&lt;/a&gt;&lt;span style="font-family: Calibri; font-size: small;" face="Calibri" size="3"&gt; to support both the UBA and rich-text higher-level protocols. This approach is important for RichEdit rich-text instances, since they use the keyboard and math &lt;/span&gt;&lt;a href="http://blogs.msdn.com/b/murrays/archive/2010/04/07/tailoring-the-unicode-bidi-algorithm.aspx"&gt;&lt;span style="color: #0000ff; font-family: Calibri; font-size: small;" face="Calibri" size="3" color="#0000ff"&gt;higher-level BiDi protocols&lt;/span&gt;&lt;/a&gt;&lt;span style="font-size: small;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;. In addition, digit substitution support requires breaking out numeric runs, which Uniscribe does. DirectWrite creates runs giving the same script value to alphabetic characters and numeric digits that are considered by context to be part of that script. The method we found to identify the digits in an Arabic run given by DirectWrite, for example, is that they are given a BiDi level of 2, whereas the strong RTL characters have a BiDi level of 1. We&amp;rsquo;ve dreamt up a number of other ways to ensure that Latin letters are rendered LTR (except in plain text with an RLO override embedding). And then you get little problems such as two Thai characters surrounding the Arabic comma U+060C. Since U+060C is considered common to several scripts, DirectWrite happily puts it in the Thai script run. But a Thai font cannot handle it. Font fallback is one way to see a glyph; RichEdit breaks the run and uses an Arabic font.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Calibri; font-size: small;" face="Calibri" size="3"&gt;For the new immersive environment on slates and the Windows Phone 8, not only are GDI and Uniscribe absent, so are the functions handled by the venerable &lt;/span&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ff657751(v=vs.85).aspx"&gt;&lt;span style="color: #0000ff; font-family: Calibri; font-size: small;" face="Calibri" size="3" color="#0000ff"&gt;user.dll&lt;/span&gt;&lt;/a&gt;&lt;span style="font-family: Calibri; font-size: small;" face="Calibri" size="3"&gt; and &lt;/span&gt;&lt;a href="http://en.wikipedia.org/wiki/Object_Linking_and_Embedding"&gt;&lt;span style="color: #0000ff; font-family: Calibri; font-size: small;" face="Calibri" size="3" color="#0000ff"&gt;OLE&lt;/span&gt;&lt;/a&gt;&lt;span style="font-size: small;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt; dll&amp;rsquo;s. The user.dll program library includes the OS SendMessage, MessageBox, CreateWindow, etc. In the immersive environment, RichEdit is only available in windowless mode. The client can still send RichEdit messages via the ITextServices::TxSendMessage() method. The advantage of dropping user.dll and the OLE dll&amp;rsquo;s is the relative simplicity of the model and the correspondingly reduced size. But doing so omits significant functionality, at least in the initial version. At the same time, the touch functionality is dramatically improved on Windows 8 and in the immersive environment.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: small;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;OneNote 2013 is the first Office application that has a fully immersive version, thanks, in part, to the fact that RichEdit 8.0 can run in a fully immersive environment. OneNote 2013 has the math display facility and you can edit math using alt+= to insert math zones and the linear format to enter equations. One problem with OneNote 2013 is that for some zoom factors, horizontal lines are snapped vertically to the wrong pixel boundary. There wasn&amp;rsquo;t enough time to fix this problem for OneNote 2013, so you may notice some square roots with misaligned bars. &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: small;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;Another side effect of these huge changes is that we have had no time to improve the Office math editing and display facility for Office 2013. The main accomplishment math-wise is not to lose any math functionality, aside from misaligned bars in OneNote. Hopefully next time we can add some cool math features.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10334591" width="1" height="1"&gt;</content><author><name>MurrayS3</name><uri>http://blogs.msdn.com/MurrayS/ProfileUrlRedirect.ashx</uri></author></entry></feed>