| Index: printing/pdf_ps_metafile_cairo.cc
|
| ===================================================================
|
| --- printing/pdf_ps_metafile_cairo.cc (revision 51151)
|
| +++ printing/pdf_ps_metafile_cairo.cc (working copy)
|
| @@ -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 @@
|
| return CAIRO_STATUS_SUCCESS;
|
| }
|
|
|
| +void DestroyContextData(void* data) {
|
| + // Nothing to be done here.
|
| +}
|
| +
|
| } // namespace
|
|
|
| namespace printing {
|
| @@ -115,6 +121,8 @@
|
| return false;
|
| }
|
|
|
| + cairo_set_user_data(context_, &kPdfMetafileKey, this, DestroyContextData);
|
| +
|
| return true;
|
| }
|
|
|
| @@ -133,6 +141,23 @@
|
| 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 @@
|
| 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 @@
|
| 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_);
|
|
|