diff options
Diffstat (limited to 'printing/pdf_ps_metafile_cairo.cc')
-rw-r--r-- | printing/pdf_ps_metafile_cairo.cc | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/printing/pdf_ps_metafile_cairo.cc b/printing/pdf_ps_metafile_cairo.cc index a4b10b2..47f4c14 100644 --- a/printing/pdf_ps_metafile_cairo.cc +++ b/printing/pdf_ps_metafile_cairo.cc @@ -19,6 +19,8 @@ namespace { +const cairo_user_data_key_t kPdfMetafileKey = {0}; + // Tests if |surface| is valid. bool IsSurfaceValid(cairo_surface_t* surface) { return cairo_surface_status(surface) == CAIRO_STATUS_SUCCESS; @@ -60,6 +62,10 @@ cairo_status_t WriteCairoStream(void* dst_buffer, return CAIRO_STATUS_SUCCESS; } +void DestroyContextData(void* data) { + // Nothing to be done here. +} + } // namespace namespace printing { @@ -115,6 +121,8 @@ bool PdfPsMetafile::Init() { return false; } + cairo_set_user_data(context_, &kPdfMetafileKey, this, DestroyContextData); + return true; } @@ -133,6 +141,23 @@ bool PdfPsMetafile::Init(const void* src_buffer, uint32 src_buffer_size) { return true; } +bool PdfPsMetafile::SetRawData(const void* src_buffer, + uint32 src_buffer_size) { + if (!context_) { + // If Init has not already been called, just call Init() + return Init(src_buffer, src_buffer_size); + } + // If a context has already been created, remember this data in + // raw_override_data_ + if (src_buffer == NULL || src_buffer_size == 0) + return false; + + raw_override_data_ = std::string(reinterpret_cast<const char*>(src_buffer), + src_buffer_size); + + return true; +} + cairo_t* PdfPsMetafile::StartPage(double width_in_points, double height_in_points, double margin_top_in_points, @@ -191,6 +216,12 @@ void PdfPsMetafile::Close() { DCHECK(IsContextValid(context_)); cairo_surface_finish(surface_); + + // If we have raw PDF/PS data set use that instead of what was drawn. + if (!raw_override_data_.empty()) { + data_ = raw_override_data_; + raw_override_data_.clear(); + } DCHECK(!data_.empty()); // Make sure we did get something. CleanUpContext(&context_); @@ -242,6 +273,11 @@ bool PdfPsMetafile::SaveTo(const base::FileDescriptor& fd) const { return success; } +PdfPsMetafile* PdfPsMetafile::FromCairoContext(cairo_t* context) { + return reinterpret_cast<PdfPsMetafile*>( + cairo_get_user_data(context, &kPdfMetafileKey)); +} + void PdfPsMetafile::CleanUpAll() { CleanUpContext(&context_); CleanUpSurface(&surface_); |