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

Side by Side Diff: printing/pdf_ps_metafile_linux.cc

Issue 203062: Linux: print page to file rather than using shared memory to send it to the b... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: style Created 11 years, 3 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 | Annotate | Revision Log
« no previous file with comments | « printing/pdf_ps_metafile_linux.h ('k') | printing/pdf_ps_metafile_linux_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 "printing/pdf_ps_metafile_linux.h" 5 #include "printing/pdf_ps_metafile_linux.h"
6 6
7 #include <stdio.h> 7 #include <stdio.h>
8 8
9 #include <cairo.h> 9 #include <cairo.h>
10 #include <cairo-ft.h> 10 #include <cairo-ft.h>
11 #include <cairo-pdf.h> 11 #include <cairo-pdf.h>
12 #include <cairo-ps.h> 12 #include <cairo-ps.h>
13 13
14 #include <ft2build.h> 14 #include <ft2build.h>
15 #include FT_FREETYPE_H 15 #include FT_FREETYPE_H
16 16
17 #include <map> 17 #include <map>
18 18
19 #include "base/eintr_wrapper.h"
20 #include "base/file_descriptor_posix.h"
19 #include "base/file_util.h" 21 #include "base/file_util.h"
20 #include "base/logging.h" 22 #include "base/logging.h"
21 #include "base/singleton.h" 23 #include "base/singleton.h"
22 #include "third_party/skia/include/core/SkFontHost.h" 24 #include "third_party/skia/include/core/SkFontHost.h"
23 #include "third_party/skia/include/core/SkStream.h" 25 #include "third_party/skia/include/core/SkStream.h"
24 #include "third_party/skia/include/core/SkTypeface.h" 26 #include "third_party/skia/include/core/SkTypeface.h"
25 27
26 namespace { 28 namespace {
27 29
28 FT_Library g_ft_library = NULL; // handle to FreeType library. 30 FT_Library g_ft_library = NULL; // handle to FreeType library.
(...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after
464 size_t data_size = GetDataSize(); 466 size_t data_size = GetDataSize();
465 if (dst_buffer_size > data_size) { 467 if (dst_buffer_size > data_size) {
466 return false; 468 return false;
467 } 469 }
468 470
469 memcpy(dst_buffer, all_pages_.data(), dst_buffer_size); 471 memcpy(dst_buffer, all_pages_.data(), dst_buffer_size);
470 472
471 return true; 473 return true;
472 } 474 }
473 475
474 bool PdfPsMetafile::SaveTo(const FilePath& filename) const { 476 bool PdfPsMetafile::SaveTo(const base::FileDescriptor& fd) const {
475 // We need to check at least these two members to ensure that either Init() 477 // We need to check at least these two members to ensure that either Init()
476 // has been called to initialize |all_pages_|, or metafile has been closed. 478 // has been called to initialize |all_pages_|, or metafile has been closed.
477 // Passing these two checks also implies that surface_, page_surface_, and 479 // Passing these two checks also implies that surface_, page_surface_, and
478 // page_context_ are NULL, and current_page_ is empty. 480 // page_context_ are NULL, and current_page_ is empty.
479 DCHECK(!context_); 481 DCHECK(!context_);
480 DCHECK(!all_pages_.empty()); 482 DCHECK(!all_pages_.empty());
481 483
482 const unsigned int data_size = GetDataSize(); 484 if (fd.fd < 0) {
483 const unsigned int bytes_written = 485 DLOG(ERROR) << "Invalid file descriptor!";
484 file_util::WriteFile(filename, all_pages_.data(), data_size);
485 if (bytes_written != data_size) {
486 DLOG(ERROR) << "Failed to save file: " << filename.value();
487 return false; 486 return false;
488 } 487 }
489 488
490 return true; 489 bool success = true;
490 if (file_util::WriteFileDescriptor(fd.fd, all_pages_.data(),
491 GetDataSize()) < 0) {
492 DLOG(ERROR) << "Failed to save file with fd " << fd.fd;
493 success = false;
494 }
495
496 if (fd.auto_close)
497 HANDLE_EINTR(close(fd.fd));
498 return success;
491 } 499 }
492 500
493 void PdfPsMetafile::CleanUpAll() { 501 void PdfPsMetafile::CleanUpAll() {
494 CleanUpContext(&context_); 502 CleanUpContext(&context_);
495 CleanUpSurface(&surface_); 503 CleanUpSurface(&surface_);
496 CleanUpContext(&page_context_); 504 CleanUpContext(&page_context_);
497 CleanUpSurface(&page_surface_); 505 CleanUpSurface(&page_surface_);
498 current_page_.clear(); 506 current_page_.clear();
499 all_pages_.clear(); 507 all_pages_.clear();
500 CleanUpFonts(); 508 CleanUpFonts();
501 CleanUpFreeType(); 509 CleanUpFreeType();
502 } 510 }
503 511
504 } // namespace printing 512 } // namespace printing
OLDNEW
« no previous file with comments | « printing/pdf_ps_metafile_linux.h ('k') | printing/pdf_ps_metafile_linux_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698