{"id":459,"date":"2014-06-26T14:15:53","date_gmt":"2014-06-26T12:15:53","guid":{"rendered":"http:\/\/blogs.igalia.com\/jaragunde\/?p=459"},"modified":"2014-07-31T20:54:33","modified_gmt":"2014-07-31T18:54:33","slug":"tales-of-libreoffice-interoperability-shape-effects","status":"publish","type":"post","link":"https:\/\/blogs.igalia.com\/jaragunde\/2014\/06\/tales-of-libreoffice-interoperability-shape-effects\/","title":{"rendered":"Tales of LibreOffice interoperability: shape effects"},"content":{"rendered":"<p>We continue introducing features that will be part of the <a href=\"https:\/\/wiki.documentfoundation.org\/ReleaseNotes\/4.3\" title=\"LibreOffice 4.3 release notes\" target=\"_blank\">4.3.0 release<\/a> of LibreOffice, which is coming soon. After having worked in the <a href=\"http:\/\/blogs.igalia.com\/jaragunde\/2014\/06\/05\/tales-of-libreoffice-interoperability-shape-theme-colors-and-styles\/\" title=\"Tales of LibreOffice interoperability: shape theme colors and styles\" target=\"_blank\">preservation of color in shapes<\/a>, we worked on the different effects that can be applied to shapes and bitmaps.<\/p>\n<p>There are three types of effects that are managed separately in the DrawingML specification.<\/p>\n<h3>General shape effects<\/h3>\n<p>Examples of these effects are inner or outer shadows, reflections, glow&#8230; They can be applied both to vectorial shapes or bitmaps, and several of them can be applied at the same time.<\/p>\n<p><a href=\"http:\/\/blogs.igalia.com\/jaragunde\/files\/2014\/06\/Captura-de-pantalla-de-2014-06-25-175302.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/blogs.igalia.com\/jaragunde\/files\/2014\/06\/Captura-de-pantalla-de-2014-06-25-175302.png\" alt=\"Shape effects sample\" width=\"197\" height=\"219\" class=\"aligncenter size-full wp-image-462\" \/><\/a><\/p>\n<p>These effects are indicated with the <em>a:effectLst<\/em> tag inside the shape properties tag <em>spPr<\/em>. I won&#8217;t explain their specification in detail because you can find a very good description <a href=\"http:\/\/www.officeopenxml.com\/drwSp-effects.php\" title=\"Description of DrawingML effects\" target=\"_blank\">in this website<\/a>, but you can get an idea by taking a look at the following example where three effects are applied: glow, inner shadow and reflection:<\/p>\n<p>[code language=&#8221;xml&#8221;]<br \/>\n&lt;a:effectLst&gt;<br \/>\n  &lt;a:glow rad=&quot;63500&quot;&gt;<br \/>\n    &lt;a:schemeClr val=&quot;accent2&quot;&gt;<br \/>\n      &lt;a:satMod val=&quot;175000&quot; \/&gt;<br \/>\n      &lt;a:alpha val=&quot;40000&quot; \/&gt;<br \/>\n    &lt;\/a:schemeClr&gt;<br \/>\n  &lt;\/a:glow&gt;<br \/>\n  &lt;a:innerShdw blurRad=&quot;63500&quot; dist=&quot;50800&quot;<br \/>\n  dir=&quot;2700000&quot;&gt;<br \/>\n    &lt;a:prstClr val=&quot;black&quot;&gt;<br \/>\n      &lt;a:alpha val=&quot;50000&quot; \/&gt;<br \/>\n    &lt;\/a:prstClr&gt;<br \/>\n  &lt;\/a:innerShdw&gt;<br \/>\n  &lt;a:reflection blurRad=&quot;6350&quot; stA=&quot;52000&quot;<br \/>\n  endA=&quot;300&quot; endPos=&quot;35000&quot; dir=&quot;5400000&quot;<br \/>\n  sy=&quot;-100000&quot; algn=&quot;bl&quot;<br \/>\n  rotWithShape=&quot;0&quot; \/&gt;<br \/>\n&lt;\/a:effectLst&gt;<br \/>\n[\/code]<\/p>\n<p>Notice that some effects only have some attributes while others contain color specifications as child elements like the ones explained <a href=\"http:\/\/blogs.igalia.com\/jaragunde\/2014\/06\/05\/tales-of-libreoffice-interoperability-shape-theme-colors-and-styles\/\" title=\"Tales of LibreOffice interoperability: shape theme colors and styles\" target=\"_blank\">in the previous post<\/a>.<\/p>\n<h3>3D effects<\/h3>\n<p>Shapes and bitmaps can be transformed into 3D objects and get lighting and camera modifications applied to them.<\/p>\n<p><a href=\"http:\/\/blogs.igalia.com\/jaragunde\/files\/2014\/06\/Captura-de-pantalla-de-2014-06-25-185747.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/blogs.igalia.com\/jaragunde\/files\/2014\/06\/Captura-de-pantalla-de-2014-06-25-185747.png\" alt=\"Shape 3D effects sample\" width=\"245\" height=\"229\" class=\"aligncenter size-full wp-image-464\" \/><\/a><\/p>\n<p>These effects are basically controlled by two children tags of <em>spPr<\/em>. One of them is <em>a:scene3d<\/em> and controls the camera and lighting, and the other one is <em>a:sp3d<\/em> which controls the transformation of the shape in a 3D object adding extrusion, bevels and a material effect to the surface. In the same website I linked before, you can read a description of <a href=\"http:\/\/www.officeopenxml.com\/drwSp-3dScene.php\" title=\"Description of DrawingML 3D scene effects\" target=\"_blank\">scene3d<\/a> and <a href=\"http:\/\/www.officeopenxml.com\/drwSp-3dProps.php\" title=\"Description of DrawingML 3D effects\" target=\"_blank\">sp3d<\/a> tags and their children. Find an example of their combined use below:<\/p>\n<p>[code language=&#8221;xml&#8221;]<br \/>\n&lt;a:scene3d&gt;<br \/>\n  &lt;a:camera prst=&quot;perspectiveRelaxedModerately&quot;<br \/>\n  zoom=&quot;150000&quot;&gt;<br \/>\n    &lt;a:rot lat=&quot;19490639&quot; lon=&quot;0&quot;<br \/>\n    rev=&quot;12900001&quot; \/&gt;<br \/>\n  &lt;\/a:camera&gt;<br \/>\n  &lt;a:lightRig rig=&quot;threePt&quot; dir=&quot;t&quot;&gt;<br \/>\n    &lt;a:rot lat=&quot;0&quot; lon=&quot;0&quot; rev=&quot;4800000&quot; \/&gt;<br \/>\n  &lt;\/a:lightRig&gt;<br \/>\n&lt;\/a:scene3d&gt;<br \/>\n&lt;a:sp3d z=&quot;488950&quot; extrusionH=&quot;63500&quot;<br \/>\nprstMaterial=&quot;metal&quot;&gt;<br \/>\n  &lt;a:bevelT w=&quot;165100&quot; prst=&quot;coolSlant&quot; \/&gt;<br \/>\n  &lt;a:extrusionClr&gt;<br \/>\n    &lt;a:schemeClr val=&quot;tx2&quot; \/&gt;<br \/>\n  &lt;\/a:extrusionClr&gt;<br \/>\n&lt;\/a:sp3d&gt;<br \/>\n[\/code]<\/p>\n<h3>Artistic effects<\/h3>\n<p>Effects from the last category act like the filters found in image manipulation programs (blur, grain or background removal among others) and that&#8217;s why they only can be applied to bitmaps. This is actually not a part of DrawingML spec but <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/dd905216(v=office.12).aspx\" title=\"MS-ODRAWXML extension\" target=\"_blank\">an extension<\/a> over it.<\/p>\n<p>There is an important difference with other filters; these ones come pre-calculated in the document. The bitmap linked by the DrawingML shape already comes with the effect, and the effect specification links a second bitmap that contains the original picture so the effect can be undone. This second bitmap is saved in the relatively new loss-less <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/gg463400.aspx\" title=\"Windows Media Photo spec\" target=\"_blank\">Windows Media Photo format<\/a>.<\/p>\n<p><a href=\"http:\/\/blogs.igalia.com\/jaragunde\/files\/2014\/06\/Captura-de-pantalla-de-2014-06-25-204917.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/blogs.igalia.com\/jaragunde\/files\/2014\/06\/Captura-de-pantalla-de-2014-06-25-204917.png\" alt=\"Writer screenshot showing artistic effects\" width=\"841\" height=\"767\" class=\"aligncenter size-full wp-image-465\" srcset=\"https:\/\/blogs.igalia.com\/jaragunde\/files\/2014\/06\/Captura-de-pantalla-de-2014-06-25-204917.png 841w, https:\/\/blogs.igalia.com\/jaragunde\/files\/2014\/06\/Captura-de-pantalla-de-2014-06-25-204917-300x273.png 300w, https:\/\/blogs.igalia.com\/jaragunde\/files\/2014\/06\/Captura-de-pantalla-de-2014-06-25-204917-328x300.png 328w\" sizes=\"auto, (max-width: 841px) 100vw, 841px\" \/><\/a><\/p>\n<p>Check the following example of a blip-filled shape; the actual filling comes from the file linked as <em>rId6<\/em>, while the effect definition is linked to <em>rId7<\/em> which is a copy of the original image before the filter was applied:<\/p>\n<p>[code language=&#8221;xml&#8221;]<br \/>\n&lt;a:blip r:embed=&quot;rId6&quot; cstate=&quot;print&quot;&gt;<br \/>\n  &lt;a:extLst&gt;<br \/>\n    &lt;a:ext uri=&quot;{BEBA8EAE-BF5A-486C-A8C5-ECC9F3942E4B}&quot;&gt;<br \/>\n      &lt;a14:imgProps xmlns:a14=&quot;http:\/\/schemas.microsoft.com\/office\/drawing\/2010\/main&quot;&gt;<br \/>\n        &lt;a14:imgLayer r:embed=&quot;rId7&quot;&gt;<br \/>\n          &lt;a14:imgEffect&gt;<br \/>\n            &lt;a14:artisticLightScreen trans=&quot;10000&quot; gridSize=&quot;6&quot; \/&gt;<br \/>\n          &lt;\/a14:imgEffect&gt;<br \/>\n        &lt;\/a14:imgLayer&gt;<br \/>\n      &lt;\/a14:imgProps&gt;<br \/>\n    &lt;\/a:ext&gt;<br \/>\n  &lt;\/a:extLst&gt;<br \/>\n&lt;\/a:blip&gt;<br \/>\n[\/code]<\/p>\n<p>These are the relations between the ids and the files contained in the document, as specified at <em>document.xml.rels<\/em>:<\/p>\n<p>[code language=&#8221;xml&#8221;]<br \/>\n&lt;Relationship Id=&quot;rId6&quot;<br \/>\n  Type=&quot;http:\/\/schemas.openxmlformats.org\/officeDocument\/2006\/relationships\/image&quot;<br \/>\n  Target=&quot;media\/image2.png&quot; \/&gt;<br \/>\n&lt;Relationship Id=&quot;rId7&quot;<br \/>\n  Type=&quot;http:\/\/schemas.microsoft.com\/office\/2007\/relationships\/hdphoto&quot;<br \/>\n  Target=&quot;media\/hdphoto1.wdp&quot; \/&gt;<br \/>\n[\/code]<\/p>\n<p>The funny thing of this approach is that LO was able to render these effects with no effort, although the program was not aware of the effect parameters or the original bitmap and these were being lost on save.<\/p>\n<h3>Preservation<\/h3>\n<p>We use again the <em>grab bag<\/em> technique to save all the tags and attributes related with the effects as a hidden property that will be used later in the export phase to re-build the effect definitions. In the case of artistic effects, we additionally need to make sure that the original bitmap is preserved; LibreOffice doesn&#8217;t support the Windows Media Photo format yet, but we can keep the raw stream of data and output it to a properly named file in the exported document. A small cache table is maintained by the exporter code to prevent that the same original file is saved more than once when two or more pictures apply effects to the same image.<\/p>\n<p>We have finished with the improvements related to shapes and pictures, but there are a few interoperability features not yet mentioned which will be covered in a future post. Like the current and previous ones, they were <a href=\"http:\/\/www.igalia.com\/\" title=\"Igalia website\" target=\"_blank\">developed by Igalia<\/a> and <a href=\"http:\/\/www.cloudon.com\/\" title=\"CloudOn website\" target=\"_blank\">sponsored by CloudOn<\/a>.<\/p>\n<p>Happy hacking!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>We continue introducing features that will be part of the 4.3.0 release of LibreOffice, which is coming soon. After having worked in the preservation of color in shapes, we worked on the different effects that can be applied to shapes &hellip; <a href=\"https:\/\/blogs.igalia.com\/jaragunde\/2014\/06\/tales-of-libreoffice-interoperability-shape-effects\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":17,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,17],"tags":[20],"class_list":["post-459","post","type-post","status-publish","format-standard","hentry","category-igalia","category-libreoffice","tag-lo-4-3-interoperability"],"_links":{"self":[{"href":"https:\/\/blogs.igalia.com\/jaragunde\/wp-json\/wp\/v2\/posts\/459","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.igalia.com\/jaragunde\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.igalia.com\/jaragunde\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.igalia.com\/jaragunde\/wp-json\/wp\/v2\/users\/17"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.igalia.com\/jaragunde\/wp-json\/wp\/v2\/comments?post=459"}],"version-history":[{"count":7,"href":"https:\/\/blogs.igalia.com\/jaragunde\/wp-json\/wp\/v2\/posts\/459\/revisions"}],"predecessor-version":[{"id":469,"href":"https:\/\/blogs.igalia.com\/jaragunde\/wp-json\/wp\/v2\/posts\/459\/revisions\/469"}],"wp:attachment":[{"href":"https:\/\/blogs.igalia.com\/jaragunde\/wp-json\/wp\/v2\/media?parent=459"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.igalia.com\/jaragunde\/wp-json\/wp\/v2\/categories?post=459"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.igalia.com\/jaragunde\/wp-json\/wp\/v2\/tags?post=459"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}