{"id":52,"date":"2016-09-29T16:04:51","date_gmt":"2016-09-29T16:04:51","guid":{"rendered":"http:\/\/blogs.igalia.com\/tonikitoo\/?p=52"},"modified":"2016-09-29T16:44:02","modified_gmt":"2016-09-29T16:44:02","slug":"making-chromiums-pdfium-greater","status":"publish","type":"post","link":"https:\/\/blogs.igalia.com\/tonikitoo\/2016\/09\/29\/making-chromiums-pdfium-greater\/","title":{"rendered":"Making Chromium&#8217;s PDFium greater"},"content":{"rendered":"<p style=\"text-align: justify\">One of the coolest things about working at <a href=\"https:\/\/www.igalia.com\/\">Igalia<\/a>, is that we have the chance to work on real world problems from day 1, either by improving an existing solution or creating new ones, based on open source technologies.<\/p>\n<p style=\"text-align: justify\">During the past month, I worked on a specific aspect of <a href=\"http:\/\/www.chromium.org\/Home\">Chromium&#8217;s<\/a> PDF engine, <a href=\"https:\/\/pdfium.googlesource.com\/pdfium\/\">PDFium<\/a>:\u00a0extending PDFium&#8217;s capability so that Annotations can be manipulated by <a href=\"http:\/\/www.adobe.com\/content\/dam\/Adobe\/en\/devnet\/acrobat\/pdfs\/js_api_reference.pdf\">Acrobat JS<\/a> scripting.<\/p>\n<p style=\"text-align: justify\">In practice, the goal was to make the specific scenario described on <a href=\"https:\/\/bugs.chromium.org\/p\/pdfium\/issues\/detail?id=492\">bug 492<\/a> to behave\u00a0similarly in Chromium\/PDFium, when compared to IE\/Acrobat.<\/p>\n<h4>&#8220;Mission given, is mission accomplished&#8221;<\/h4>\n<p>The following Acrobat JS APIs were implemented:<\/p>\n<p>&#8211; <a href=\"https:\/\/codereview.chromium.org\/2219183002\/\">Document::URL<\/a><br \/>\n&#8211; <a href=\"https:\/\/codereview.chromium.org\/2221823003\/\">Document::gotoNamedDest<\/a><br \/>\n&#8211; <a href=\"https:\/\/codereview.chromium.org\/2265553002\/\">Document::syncAnnotScan<\/a> (only stubbed out)<br \/>\n&#8211; <a href=\"https:\/\/codereview.chromium.org\/2260663002\/\">Document::getAnnot<\/a><br \/>\n&#8211; <a href=\"https:\/\/codereview.chromium.org\/2281273002\/\">Document::getAnnots<\/a><\/p>\n<p style=\"text-align: justify\">&#8230; and Acrobat JS scripts like the snippet below can now be successfully executed by PDFium, making 200k+ PDF files to behave in Chromium\/PDFium similarly to IE\/Acrobat &#8211;<br \/>\nwith regards to the way Annotations are manipulated.<\/p>\n<pre>1 this.disclosed = true;\r\n2 this.syncAnnotScan();\r\n3 var u = this.URL;\r\n4 var args = u.split('calcrtid=');\r\n5 var tags;\r\n6 if (args.length &gt; 1) {\r\n7   tags = args[1].split('&amp;');\r\n8   this.gotoNamedDest(tags[0]);\r\n9   var a = this.getAnnot(this.pageNum, tags[0]);\r\n10   if (a != null) {\r\n11     a.hidden = false;\r\n12     var rect = a.rect;\r\n13     if (rect != null) {\r\n14       this.scroll(rect[2] + 100, rect[3] + 100);\r\n15     }\r\n16   }\r\n17 }\r\n<\/pre>\n<p style=\"text-align: justify\">Also as part of this project, it was possible to\u00a0fix two discrepancies in PDFium, again if compared to Acrobat: 1) <a href=\"https:\/\/codereview.chromium.org\/2265313002\/\">Hidden annotations were shown<\/a>; 2)\u00a0<a href=\"https:\/\/bugs.chromium.org\/p\/pdfium\/issues\/detail?id=585\">PDFium&#8217;s positioning Text Markup annotations<\/a>.<\/p>\n<p style=\"text-align: justify\">About (2) specifically,\u00a0on Acrobat if an &#8220;\/AP&#8221; clause is present as part of an &#8220;\/Annot&#8221; definition, the coordinates used to draw annotations come from &#8220;\/Rect&#8221;\u00a0values. On the other hand, when &#8220;\/AP&#8221; is not defined, &#8220;\/QuadPoints&#8221; values are used to grab the annotation coordinates from.\u00a0The divergence was coming\u00a0from the fact that PDFium uses &#8220;\/Rect&#8221; regardless\u00a0the presence or absence of &#8220;\/AP&#8221;.\u00a0<a href=\"https:\/\/codereview.chromium.org\/2289293005\/\">This CL<\/a> fixed it.<\/p>\n<p style=\"text-align: justify\">To wrap up the work, I was also able to extend PDFium&#8217;s main testing tool (<a href=\"https:\/\/cs.chromium.org\/chromium\/src\/third_party\/pdfium\/samples\/pdfium_test.cc?sq=package:chromium&amp;dr=CSs\">pdfium_test<\/a>) to <a href=\"https:\/\/codereview.chromium.org\/2277063003\/\">actually run Acrobat JS tests<\/a>\u00a0(<a href=\"https:\/\/codereview.chromium.org\/2330043002\/\">follow up<\/a>), <a href=\"https:\/\/codereview.chromium.org\/2202283002\/\">as<\/a> <a href=\"https:\/\/codereview.chromium.org\/2227173002\/\">well<\/a> <a href=\"https:\/\/codereview.chromium.org\/2230983003\/\">as<\/a> <a href=\"https:\/\/codereview.chromium.org\/2255843002\/\">make<\/a> <a href=\"https:\/\/codereview.chromium.org\/2266193002\/\">lots<\/a> <a href=\"https:\/\/codereview.chromium.org\/2310873002\/\">of<\/a> <a href=\"https:\/\/codereview.chromium.org\/2235883003\/\">driven-by<\/a>\u00a0clean ups, and <a href=\"https:\/\/codereview.chromium.org\/2271263002\/\">change PDFium&#8217;s main client<\/a> (Chromium) to <a href=\"https:\/\/groups.google.com\/forum\/#!topic\/pdfium\/AtregS0864M\">deal better when its async nature<\/a>.<\/p>\n<h4>The PDFium community<\/h4>\n<p style=\"text-align: justify\">Throughout the project, interactions with the PDFium community were\u00a0smooth:<\/p>\n<ul>\n<li style=\"text-align: justify\">PDFium contribution flow follows pretty much the Chromium&#8217;s:<br \/>\n<a href=\"https:\/\/bugs.chromium.org\">https:\/\/bugs.chromium.org<\/a> to report issues and <a href=\"https:\/\/codereview.chromium.org\">Codereview<\/a> to get the work reviewed.<\/li>\n<li style=\"text-align: justify\">Once approved, a\u00a0CL is committed through\u00a0a &#8220;Commit Queue&#8221; bot &#8211; which ensures a CLs correctness by running <a href=\"https:\/\/pdfium.googlesource.com\/pdfium_tests\">PDFium regression suite<\/a>.<\/li>\n<li style=\"text-align: justify\">Owners are really responsive.<\/li>\n<\/ul>\n<h4><b>Acknowledgments<\/b><\/h4>\n<p>My work in <a href=\"https:\/\/pdfium.googlesource.com\/pdfium\/\">PDFium<\/a>\u00a0is sponsored by <a href=\"http:\/\/www.bloomberg.com\/\">Bloomberg.<\/a>\u00a0Thank you all!<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-62 alignright\" src=\"http:\/\/blogs.igalia.com\/tonikitoo\/files\/2016\/09\/igalia-bloomberg.png\" alt=\"igalia-bloomberg\" width=\"340\" height=\"136\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>One of the coolest things about working at Igalia, is that we have the chance to work on real world problems from day 1, either by improving an existing solution or creating new ones, based on open source technologies. During the past month, I worked on a specific aspect of Chromium&#8217;s PDF engine, PDFium:\u00a0extending PDFium&#8217;s &hellip; <a href=\"https:\/\/blogs.igalia.com\/tonikitoo\/2016\/09\/29\/making-chromiums-pdfium-greater\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Making Chromium&#8217;s PDFium greater<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":38,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9,8,13,14],"tags":[],"class_list":["post-52","post","type-post","status-publish","format-standard","hentry","category-browsers","category-chromium","category-igalia","category-pdfium"],"_links":{"self":[{"href":"https:\/\/blogs.igalia.com\/tonikitoo\/wp-json\/wp\/v2\/posts\/52","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.igalia.com\/tonikitoo\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.igalia.com\/tonikitoo\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.igalia.com\/tonikitoo\/wp-json\/wp\/v2\/users\/38"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.igalia.com\/tonikitoo\/wp-json\/wp\/v2\/comments?post=52"}],"version-history":[{"count":12,"href":"https:\/\/blogs.igalia.com\/tonikitoo\/wp-json\/wp\/v2\/posts\/52\/revisions"}],"predecessor-version":[{"id":65,"href":"https:\/\/blogs.igalia.com\/tonikitoo\/wp-json\/wp\/v2\/posts\/52\/revisions\/65"}],"wp:attachment":[{"href":"https:\/\/blogs.igalia.com\/tonikitoo\/wp-json\/wp\/v2\/media?parent=52"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.igalia.com\/tonikitoo\/wp-json\/wp\/v2\/categories?post=52"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.igalia.com\/tonikitoo\/wp-json\/wp\/v2\/tags?post=52"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}