{"action":"created","comment":{"url":"https://api.github.com/repos/project-renard/curie/pulls/comments/61689863","id":61689863,"diff_hunk":"@@ -2,43 +2,101 @@ use Modern::Perl;\n package Renard::Curie::Data::PDF;\n \n use Capture::Tiny qw(capture_stdout);\n+use XML::Simple;\n+use Path::Tiny;\n+use Alien::MuPDF 0.004;\n \n-sub mudraw_get_pdf_page_as_png {\n-\tmy ($pdf_filename, $pdf_page_no) = @_;\n+BEGIN {\n+\tour $MUTOOL_PATH =  path(Alien::MuPDF->dist_dir, qw(bin mutool));\n+}\n \n+sub _call_mutool {\n+\tmy @args = ( $Renard::Curie::Data::PDF::MUTOOL_PATH, @_ );\n \tmy ($stdout, $exit) = capture_stdout {\n-\t\tsystem(\"mudraw\",\n-\t\t\tqw( -F png ),\n-\t\t\tqw( -o -),\n-\t\t\t$pdf_filename,\n-\t\t\t$pdf_page_no,\n-\t\t);\n+\t\tsystem( @args );\n \t};\n \n-\tdie \"Unexpected mudraw exit: $exit\" if $exit;\n+\tdie \"Unexpected mutool exit: $exit\" if $exit;\n+\n+\treturn $stdout;\n+}\n+\n+sub get_mutool_pdf_page_as_png {\n+\tmy ($pdf_filename, $pdf_page_no) = @_;\n+\n+\tmy $stdout = _call_mutool(\n+\t\tqw(draw),\n+\t\tqw( -F png ),\n+\t\tqw( -o -),\n+\t\t$pdf_filename,\n+\t\t$pdf_page_no,\n+\t);\n+\n+\treturn $stdout;\n+}\n+\n+sub get_mutool_text_stext_raw {\n+\tmy ($pdf_filename, $pdf_page_no) = @_;\n+\n+\tmy $stdout = _call_mutool(\n+\t\tqw(draw),\n+\t\tqw(-F stext),\n+\t\tqw(-o -),\n+\t\t$pdf_filename,\n+\t\t$pdf_page_no,\n+\t);\n \n \treturn $stdout;\n }\n \n-sub get_pdfinfo_for_filename {\n+sub get_mutool_text_stext_xml {\n+\tmy ($pdf_filename, $pdf_page_no) = @_;\n+\n+\tmy $stext_xml = get_mutool_text_stext_raw(\n+\t\t$pdf_filename,\n+\t\t$pdf_page_no,\n+\t);\n+\t# page -> [list of blocks]\n+\t#   block -> [list of blocks]\n+\t#     block is either:\n+\t#       - stext\n+\t#           line -> [list of lines] (all have same baseline)\n+\t#             span -> [list of spans] (horizontal spaces over a line)\n+\t#               char -> [list of chars]\n+\t#       - image\n+\t#           TODO\n+\n+\tmy $stext = XMLin( $stext_xml,\n+\t\tForceArray => [ qw(page block line span char) ] );\n+\n+\treturn $stext;\n+}\n+\n+sub get_mutool_page_info_raw {","path":"lib/Renard/Curie/Data/PDF.pm","position":84,"original_position":84,"commit_id":"ba1ef73b7955eccd9b2d36592e138798c93e642a","original_commit_id":"ba1ef73b7955eccd9b2d36592e138798c93e642a","user":{"login":"zmughal","id":94489,"avatar_url":"https://avatars.githubusercontent.com/u/94489?v=3","gravatar_id":"","url":"https://api.github.com/users/zmughal","html_url":"https://github.com/zmughal","followers_url":"https://api.github.com/users/zmughal/followers","following_url":"https://api.github.com/users/zmughal/following{/other_user}","gists_url":"https://api.github.com/users/zmughal/gists{/gist_id}","starred_url":"https://api.github.com/users/zmughal/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zmughal/subscriptions","organizations_url":"https://api.github.com/users/zmughal/orgs","repos_url":"https://api.github.com/users/zmughal/repos","events_url":"https://api.github.com/users/zmughal/events{/privacy}","received_events_url":"https://api.github.com/users/zmughal/received_events","type":"User","site_admin":false},"body":"TODO: add documentation","created_at":"2016-05-01T17:12:38Z","updated_at":"2016-05-01T17:12:38Z","html_url":"https://github.com/project-renard/curie/pull/84#discussion_r61689863","pull_request_url":"https://api.github.com/repos/project-renard/curie/pulls/84","_links":{"self":{"href":"https://api.github.com/repos/project-renard/curie/pulls/comments/61689863"},"html":{"href":"https://github.com/project-renard/curie/pull/84#discussion_r61689863"},"pull_request":{"href":"https://api.github.com/repos/project-renard/curie/pulls/84"}}},"pull_request":{"url":"https://api.github.com/repos/project-renard/curie/pulls/84","id":68281978,"html_url":"https://github.com/project-renard/curie/pull/84","diff_url":"https://github.com/project-renard/curie/pull/84.diff","patch_url":"https://github.com/project-renard/curie/pull/84.patch","issue_url":"https://api.github.com/repos/project-renard/curie/issues/84","number":84,"state":"open","locked":false,"title":"Replace pdfinfo with mutool","user":{"login":"StayerX","id":11931609,"avatar_url":"https://avatars.githubusercontent.com/u/11931609?v=3","gravatar_id":"","url":"https://api.github.com/users/StayerX","html_url":"https://github.com/StayerX","followers_url":"https://api.github.com/users/StayerX/followers","following_url":"https://api.github.com/users/StayerX/following{/other_user}","gists_url":"https://api.github.com/users/StayerX/gists{/gist_id}","starred_url":"https://api.github.com/users/StayerX/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/StayerX/subscriptions","organizations_url":"https://api.github.com/users/StayerX/orgs","repos_url":"https://api.github.com/users/StayerX/repos","events_url":"https://api.github.com/users/StayerX/events{/privacy}","received_events_url":"https://api.github.com/users/StayerX/received_events","type":"User","site_admin":false},"body":"Closes #73.","created_at":"2016-04-28T20:08:03Z","updated_at":"2016-05-01T17:12:38Z","closed_at":null,"merged_at":null,"merge_commit_sha":"dadcdb055d543294aa0a029a01a6896d07f5de24","assignee":null,"milestone":{"url":"https://api.github.com/repos/project-renard/curie/milestones/1","html_url":"https://github.com/project-renard/curie/milestones/curie%20v0.001","labels_url":"https://api.github.com/repos/project-renard/curie/milestones/1/labels","id":1732259,"number":1,"title":"curie v0.001","description":"- Initial packaging\r\n- Packaged for Linux and Windows\r\n- Able to open PDFs from the file system\r\n- Page navigation\r\n- Zoom in and zoom out","creator":{"login":"zmughal","id":94489,"avatar_url":"https://avatars.githubusercontent.com/u/94489?v=3","gravatar_id":"","url":"https://api.github.com/users/zmughal","html_url":"https://github.com/zmughal","followers_url":"https://api.github.com/users/zmughal/followers","following_url":"https://api.github.com/users/zmughal/following{/other_user}","gists_url":"https://api.github.com/users/zmughal/gists{/gist_id}","starred_url":"https://api.github.com/users/zmughal/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zmughal/subscriptions","organizations_url":"https://api.github.com/users/zmughal/orgs","repos_url":"https://api.github.com/users/zmughal/repos","events_url":"https://api.github.com/users/zmughal/events{/privacy}","received_events_url":"https://api.github.com/users/zmughal/received_events","type":"User","site_admin":false},"open_issues":19,"closed_issues":42,"state":"open","created_at":"2016-04-26T16:31:47Z","updated_at":"2016-04-30T20:51:22Z","due_on":"2016-05-23T05:00:00Z","closed_at":null},"commits_url":"https://api.github.com/repos/project-renard/curie/pulls/84/commits","review_comments_url":"https://api.github.com/repos/project-renard/curie/pulls/84/comments","review_comment_url":"https://api.github.com/repos/project-renard/curie/pulls/comments{/number}","comments_url":"https://api.github.com/repos/project-renard/curie/issues/84/comments","statuses_url":"https://api.github.com/repos/project-renard/curie/statuses/ba1ef73b7955eccd9b2d36592e138798c93e642a","head":{"label":"project-renard:73-replace-pdfinfo-with-mutool","ref":"73-replace-pdfinfo-with-mutool","sha":"ba1ef73b7955eccd9b2d36592e138798c93e642a","user":{"login":"project-renard","id":11675245,"avatar_url":"https://avatars.githubusercontent.com/u/11675245?v=3","gravatar_id":"","url":"https://api.github.com/users/project-renard","html_url":"https://github.com/project-renard","followers_url":"https://api.github.com/users/project-renard/followers","following_url":"https://api.github.com/users/project-renard/following{/other_user}","gists_url":"https://api.github.com/users/project-renard/gists{/gist_id}","starred_url":"https://api.github.com/users/project-renard/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/project-renard/subscriptions","organizations_url":"https://api.github.com/users/project-renard/orgs","repos_url":"https://api.github.com/users/project-renard/repos","events_url":"https://api.github.com/users/project-renard/events{/privacy}","received_events_url":"https://api.github.com/users/project-renard/received_events","type":"Organization","site_admin":false},"repo":{"id":48336953,"name":"curie","full_name":"project-renard/curie","owner":{"login":"project-renard","id":11675245,"avatar_url":"https://avatars.githubusercontent.com/u/11675245?v=3","gravatar_id":"","url":"https://api.github.com/users/project-renard","html_url":"https://github.com/project-renard","followers_url":"https://api.github.com/users/project-renard/followers","following_url":"https://api.github.com/users/project-renard/following{/other_user}","gists_url":"https://api.github.com/users/project-renard/gists{/gist_id}","starred_url":"https://api.github.com/users/project-renard/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/project-renard/subscriptions","organizations_url":"https://api.github.com/users/project-renard/orgs","repos_url":"https://api.github.com/users/project-renard/repos","events_url":"https://api.github.com/users/project-renard/events{/privacy}","received_events_url":"https://api.github.com/users/project-renard/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/project-renard/curie","description":"Dockable, information visualisation GUI for documents and other sources","fork":false,"url":"https://api.github.com/repos/project-renard/curie","forks_url":"https://api.github.com/repos/project-renard/curie/forks","keys_url":"https://api.github.com/repos/project-renard/curie/keys{/key_id}","collaborators_url":"https://api.github.com/repos/project-renard/curie/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/project-renard/curie/teams","hooks_url":"https://api.github.com/repos/project-renard/curie/hooks","issue_events_url":"https://api.github.com/repos/project-renard/curie/issues/events{/number}","events_url":"https://api.github.com/repos/project-renard/curie/events","assignees_url":"https://api.github.com/repos/project-renard/curie/assignees{/user}","branches_url":"https://api.github.com/repos/project-renard/curie/branches{/branch}","tags_url":"https://api.github.com/repos/project-renard/curie/tags","blobs_url":"https://api.github.com/repos/project-renard/curie/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/project-renard/curie/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/project-renard/curie/git/refs{/sha}","trees_url":"https://api.github.com/repos/project-renard/curie/git/trees{/sha}","statuses_url":"https://api.github.com/repos/project-renard/curie/statuses/{sha}","languages_url":"https://api.github.com/repos/project-renard/curie/languages","stargazers_url":"https://api.github.com/repos/project-renard/curie/stargazers","contributors_url":"https://api.github.com/repos/project-renard/curie/contributors","subscribers_url":"https://api.github.com/repos/project-renard/curie/subscribers","subscription_url":"https://api.github.com/repos/project-renard/curie/subscription","commits_url":"https://api.github.com/repos/project-renard/curie/commits{/sha}","git_commits_url":"https://api.github.com/repos/project-renard/curie/git/commits{/sha}","comments_url":"https://api.github.com/repos/project-renard/curie/comments{/number}","issue_comment_url":"https://api.github.com/repos/project-renard/curie/issues/comments{/number}","contents_url":"https://api.github.com/repos/project-renard/curie/contents/{+path}","compare_url":"https://api.github.com/repos/project-renard/curie/compare/{base}...{head}","merges_url":"https://api.github.com/repos/project-renard/curie/merges","archive_url":"https://api.github.com/repos/project-renard/curie/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/project-renard/curie/downloads","issues_url":"https://api.github.com/repos/project-renard/curie/issues{/number}","pulls_url":"https://api.github.com/repos/project-renard/curie/pulls{/number}","milestones_url":"https://api.github.com/repos/project-renard/curie/milestones{/number}","notifications_url":"https://api.github.com/repos/project-renard/curie/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/project-renard/curie/labels{/name}","releases_url":"https://api.github.com/repos/project-renard/curie/releases{/id}","deployments_url":"https://api.github.com/repos/project-renard/curie/deployments","created_at":"2015-12-20T20:57:27Z","updated_at":"2016-03-27T00:35:09Z","pushed_at":"2016-05-01T05:35:08Z","git_url":"git://github.com/project-renard/curie.git","ssh_url":"git@github.com:project-renard/curie.git","clone_url":"https://github.com/project-renard/curie.git","svn_url":"https://github.com/project-renard/curie","homepage":"","size":1511,"stargazers_count":2,"watchers_count":2,"language":"Perl","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":41,"forks":0,"open_issues":41,"watchers":2,"default_branch":"master"}},"base":{"label":"project-renard:master","ref":"master","sha":"ec067c5b38ca17181dd39beaae67fff70e7640d2","user":{"login":"project-renard","id":11675245,"avatar_url":"https://avatars.githubusercontent.com/u/11675245?v=3","gravatar_id":"","url":"https://api.github.com/users/project-renard","html_url":"https://github.com/project-renard","followers_url":"https://api.github.com/users/project-renard/followers","following_url":"https://api.github.com/users/project-renard/following{/other_user}","gists_url":"https://api.github.com/users/project-renard/gists{/gist_id}","starred_url":"https://api.github.com/users/project-renard/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/project-renard/subscriptions","organizations_url":"https://api.github.com/users/project-renard/orgs","repos_url":"https://api.github.com/users/project-renard/repos","events_url":"https://api.github.com/users/project-renard/events{/privacy}","received_events_url":"https://api.github.com/users/project-renard/received_events","type":"Organization","site_admin":false},"repo":{"id":48336953,"name":"curie","full_name":"project-renard/curie","owner":{"login":"project-renard","id":11675245,"avatar_url":"https://avatars.githubusercontent.com/u/11675245?v=3","gravatar_id":"","url":"https://api.github.com/users/project-renard","html_url":"https://github.com/project-renard","followers_url":"https://api.github.com/users/project-renard/followers","following_url":"https://api.github.com/users/project-renard/following{/other_user}","gists_url":"https://api.github.com/users/project-renard/gists{/gist_id}","starred_url":"https://api.github.com/users/project-renard/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/project-renard/subscriptions","organizations_url":"https://api.github.com/users/project-renard/orgs","repos_url":"https://api.github.com/users/project-renard/repos","events_url":"https://api.github.com/users/project-renard/events{/privacy}","received_events_url":"https://api.github.com/users/project-renard/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/project-renard/curie","description":"Dockable, information visualisation GUI for documents and other sources","fork":false,"url":"https://api.github.com/repos/project-renard/curie","forks_url":"https://api.github.com/repos/project-renard/curie/forks","keys_url":"https://api.github.com/repos/project-renard/curie/keys{/key_id}","collaborators_url":"https://api.github.com/repos/project-renard/curie/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/project-renard/curie/teams","hooks_url":"https://api.github.com/repos/project-renard/curie/hooks","issue_events_url":"https://api.github.com/repos/project-renard/curie/issues/events{/number}","events_url":"https://api.github.com/repos/project-renard/curie/events","assignees_url":"https://api.github.com/repos/project-renard/curie/assignees{/user}","branches_url":"https://api.github.com/repos/project-renard/curie/branches{/branch}","tags_url":"https://api.github.com/repos/project-renard/curie/tags","blobs_url":"https://api.github.com/repos/project-renard/curie/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/project-renard/curie/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/project-renard/curie/git/refs{/sha}","trees_url":"https://api.github.com/repos/project-renard/curie/git/trees{/sha}","statuses_url":"https://api.github.com/repos/project-renard/curie/statuses/{sha}","languages_url":"https://api.github.com/repos/project-renard/curie/languages","stargazers_url":"https://api.github.com/repos/project-renard/curie/stargazers","contributors_url":"https://api.github.com/repos/project-renard/curie/contributors","subscribers_url":"https://api.github.com/repos/project-renard/curie/subscribers","subscription_url":"https://api.github.com/repos/project-renard/curie/subscription","commits_url":"https://api.github.com/repos/project-renard/curie/commits{/sha}","git_commits_url":"https://api.github.com/repos/project-renard/curie/git/commits{/sha}","comments_url":"https://api.github.com/repos/project-renard/curie/comments{/number}","issue_comment_url":"https://api.github.com/repos/project-renard/curie/issues/comments{/number}","contents_url":"https://api.github.com/repos/project-renard/curie/contents/{+path}","compare_url":"https://api.github.com/repos/project-renard/curie/compare/{base}...{head}","merges_url":"https://api.github.com/repos/project-renard/curie/merges","archive_url":"https://api.github.com/repos/project-renard/curie/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/project-renard/curie/downloads","issues_url":"https://api.github.com/repos/project-renard/curie/issues{/number}","pulls_url":"https://api.github.com/repos/project-renard/curie/pulls{/number}","milestones_url":"https://api.github.com/repos/project-renard/curie/milestones{/number}","notifications_url":"https://api.github.com/repos/project-renard/curie/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/project-renard/curie/labels{/name}","releases_url":"https://api.github.com/repos/project-renard/curie/releases{/id}","deployments_url":"https://api.github.com/repos/project-renard/curie/deployments","created_at":"2015-12-20T20:57:27Z","updated_at":"2016-03-27T00:35:09Z","pushed_at":"2016-05-01T05:35:08Z","git_url":"git://github.com/project-renard/curie.git","ssh_url":"git@github.com:project-renard/curie.git","clone_url":"https://github.com/project-renard/curie.git","svn_url":"https://github.com/project-renard/curie","homepage":"","size":1511,"stargazers_count":2,"watchers_count":2,"language":"Perl","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":41,"forks":0,"open_issues":41,"watchers":2,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/project-renard/curie/pulls/84"},"html":{"href":"https://github.com/project-renard/curie/pull/84"},"issue":{"href":"https://api.github.com/repos/project-renard/curie/issues/84"},"comments":{"href":"https://api.github.com/repos/project-renard/curie/issues/84/comments"},"review_comments":{"href":"https://api.github.com/repos/project-renard/curie/pulls/84/comments"},"review_comment":{"href":"https://api.github.com/repos/project-renard/curie/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/project-renard/curie/pulls/84/commits"},"statuses":{"href":"https://api.github.com/repos/project-renard/curie/statuses/ba1ef73b7955eccd9b2d36592e138798c93e642a"}}}}