Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(97)

Side by Side Diff: pdf/pdfium/pdfium_engine.cc

Issue 1953053002: Add private PPAPI interfaces for PDFium accessibility. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Another speculative compiler error fix Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "pdf/pdfium/pdfium_engine.h" 5 #include "pdf/pdfium/pdfium_engine.h"
6 6
7 #include <math.h> 7 #include <math.h>
8 #include <stddef.h> 8 #include <stddef.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 10
(...skipping 2285 matching lines...) Expand 10 before | Expand all | Expand 10 after
2296 if (index < 0 || static_cast<size_t>(index) > pages_.size() - 1) 2296 if (index < 0 || static_cast<size_t>(index) > pages_.size() - 1)
2297 return "{}"; 2297 return "{}";
2298 2298
2299 std::unique_ptr<base::Value> node( 2299 std::unique_ptr<base::Value> node(
2300 pages_[index]->GetAccessibleContentAsValue(current_rotation_)); 2300 pages_[index]->GetAccessibleContentAsValue(current_rotation_));
2301 std::string page_json; 2301 std::string page_json;
2302 base::JSONWriter::Write(*node, &page_json); 2302 base::JSONWriter::Write(*node, &page_json);
2303 return page_json; 2303 return page_json;
2304 } 2304 }
2305 2305
2306 void PDFiumEngine::EnableAccessibility() {
2307 if (!(HasPermission(PERMISSION_COPY) ||
2308 HasPermission(PERMISSION_COPY_ACCESSIBLE))) {
2309 return;
Lei Zhang 2016/05/09 23:58:49 Would it be helpful to return false to give the ac
dmazzoni 2016/05/10 22:09:18 Good thought. I moved SetAccessibilityDocInfo up
2310 }
2311
2312 PP_PrivateAccessibilityViewportInfo viewport_info;
2313 viewport_info.scroll.x = 0;
2314 viewport_info.scroll.y = -client_->GetToolbarHeight();
2315 viewport_info.offset = page_offset_;
2316 viewport_info.zoom = current_zoom_;
2317 pp::PDF::SetAccessibilityViewportInfo(GetPluginInstance(), &viewport_info);
2318
2319 PP_PrivateAccessibilityDocInfo doc_info;
2320 doc_info.page_count = pages_.size();
2321 doc_info.text_accessible = PP_FromBool(
2322 HasPermission(PERMISSION_COPY_ACCESSIBLE));
2323 doc_info.text_copyable = PP_FromBool(HasPermission(PERMISSION_COPY));
2324 pp::PDF::SetAccessibilityDocInfo(GetPluginInstance(), &doc_info);
2325
2326 for (uint32_t page_index = 0; page_index < pages_.size(); ++page_index) {
Lei Zhang 2016/05/09 23:58:49 size_t instead of uint32_t?
dmazzoni 2016/05/10 22:09:18 Done.
2327 FPDF_TEXTPAGE text_page = pages_[page_index]->GetTextPage();
2328 int char_count = FPDFText_CountChars(text_page);
2329 PP_PrivateAccessibilityPageInfo page_info;
2330 page_info.bounds = pages_[page_index]->rect();
2331 page_info.char_count = char_count;
2332 pp::PDF::SetAccessibilityPageInfo(
2333 GetPluginInstance(), page_index, &page_info);
2334
2335 int char_index = 0;
2336 int text_run_index = 0;
2337 while (char_index < char_count) {
2338 PP_PrivateAccessibilityTextRunInfo text_run_info;
2339 pp::FloatRect bounds;
2340 pages_[page_index]->GetTextRunInfo(
2341 char_index, &text_run_info.len, &text_run_info.font_size, &bounds);
2342 text_run_info.direction = PP_PRIVATEDIRECTION_LTR;
2343 text_run_info.bounds = bounds;
2344 std::vector<PP_PrivateAccessibilityCharInfo> chars;
2345 chars.resize(text_run_info.len);
Lei Zhang 2016/05/09 23:58:49 I think you can combine this with the previous lin
dmazzoni 2016/05/10 22:09:18 Done.
2346 for (uint32_t i = 0; i < text_run_info.len; ++i) {
2347 chars[i].unicode_character = FPDFText_GetUnicode(text_page, i);
2348 chars[i].char_width = pages_[page_index]->GetCharWidth(i);
2349 }
2350
2351 pp::PDF::SetAccessibilityTextRunInfo(GetPluginInstance(),
2352 page_index,
2353 text_run_index,
2354 &text_run_info,
2355 chars.data());
2356 text_run_index++;
2357 char_index += text_run_info.len;
2358 }
2359 }
2360 }
2361
2306 bool PDFiumEngine::GetPrintScaling() { 2362 bool PDFiumEngine::GetPrintScaling() {
2307 return !!FPDF_VIEWERREF_GetPrintScaling(doc_); 2363 return !!FPDF_VIEWERREF_GetPrintScaling(doc_);
2308 } 2364 }
2309 2365
2310 int PDFiumEngine::GetCopiesToPrint() { 2366 int PDFiumEngine::GetCopiesToPrint() {
2311 return FPDF_VIEWERREF_GetNumCopies(doc_); 2367 return FPDF_VIEWERREF_GetNumCopies(doc_);
2312 } 2368 }
2313 2369
2314 int PDFiumEngine::GetDuplexType() { 2370 int PDFiumEngine::GetDuplexType() {
2315 return static_cast<int>(FPDF_VIEWERREF_GetDuplex(doc_)); 2371 return static_cast<int>(FPDF_VIEWERREF_GetDuplex(doc_));
(...skipping 1557 matching lines...) Expand 10 before | Expand all | Expand 10 after
3873 FPDF_DOCUMENT doc = 3929 FPDF_DOCUMENT doc =
3874 FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, nullptr); 3930 FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, nullptr);
3875 if (!doc) 3931 if (!doc)
3876 return false; 3932 return false;
3877 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; 3933 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0;
3878 FPDF_CloseDocument(doc); 3934 FPDF_CloseDocument(doc);
3879 return success; 3935 return success;
3880 } 3936 }
3881 3937
3882 } // namespace chrome_pdf 3938 } // namespace chrome_pdf
OLDNEW
« no previous file with comments | « pdf/pdfium/pdfium_engine.h ('k') | pdf/pdfium/pdfium_page.h » ('j') | pdf/pdfium/pdfium_page.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698