diff options
author | sanjeevr@chromium.org <sanjeevr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-07-12 16:25:04 +0000 |
---|---|---|
committer | sanjeevr@chromium.org <sanjeevr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-07-12 16:25:04 +0000 |
commit | 2aa8e1835e136a1979210121cca1b68f25187a66 (patch) | |
tree | 229a5abbc11360cca47c8ed128f8d46f927c3059 /printing/emf_win.cc | |
parent | 98a94ee562ef36213099a153ca6f3fa4b3b5d09c (diff) | |
download | chromium_src-2aa8e1835e136a1979210121cca1b68f25187a66.zip chromium_src-2aa8e1835e136a1979210121cca1b68f25187a66.tar.gz chromium_src-2aa8e1835e136a1979210121cca1b68f25187a66.tar.bz2 |
Added StartPage and EndPage methods to the Emf class because the GDI StartPage and EndPage APIs do not work in a metafile DC. We write custom GDICOMMENT records to designate a StartPage and EndPage.
BUG=None
TEST=Unit-tests provided.
Review URL: http://codereview.chromium.org/2947006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@52084 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'printing/emf_win.cc')
-rw-r--r-- | printing/emf_win.cc | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/printing/emf_win.cc b/printing/emf_win.cc index d8e03af..e93acf2 100644 --- a/printing/emf_win.cc +++ b/printing/emf_win.cc @@ -14,6 +14,24 @@ #include "gfx/rect.h" #include "third_party/skia/include/core/SkBitmap.h" +namespace { +const int kCustomGdiCommentSignature = 0xdeadbabe; +struct PageBreakRecord { + int signature; + enum PageBreakType { + START_PAGE, + END_PAGE, + } type; + explicit PageBreakRecord(PageBreakType type_in) + : signature(kCustomGdiCommentSignature), type(type_in) { + } + bool IsValid() const { + return (signature == kCustomGdiCommentSignature) && + (type >= START_PAGE) && (type <= END_PAGE); + } +}; +} + namespace printing { bool DIBFormatNativelySupported(HDC dc, uint32 escape, const BYTE* bits, @@ -232,6 +250,8 @@ bool Emf::Record::SafePlayback(const XFORM* base_matrix) const { // device. // TODO(sanjeevr): We should also add JPEG/PNG support for SetSIBitsToDevice // + // We also process any custom EMR_GDICOMMENT records which are our + // placeholders for StartPage and EndPage. // Note: I should probably care about view ports and clipping, eventually. bool res; switch (record()->iType) { @@ -343,6 +363,27 @@ bool Emf::Record::SafePlayback(const XFORM* base_matrix) const { // Ignore it. res = true; break; + case EMR_GDICOMMENT: { + const EMRGDICOMMENT* comment_record = + reinterpret_cast<const EMRGDICOMMENT*>(record()); + if (comment_record->cbData == sizeof(PageBreakRecord)) { + const PageBreakRecord* page_break_record = + reinterpret_cast<const PageBreakRecord*>(comment_record->Data); + if (page_break_record && page_break_record->IsValid()) { + if (page_break_record->type == PageBreakRecord::START_PAGE) { + res = !!::StartPage(context_->hdc); + } else if (page_break_record->type == PageBreakRecord::END_PAGE) { + res = !!::EndPage(context_->hdc); + } else { + res = false; + NOTREACHED(); + } + } else { + res = Play(); + } + } + break; + } default: { res = Play(); break; @@ -351,6 +392,25 @@ bool Emf::Record::SafePlayback(const XFORM* base_matrix) const { return res; } +bool Emf::StartPage() { + DCHECK(hdc_); + if (!hdc_) + return false; + PageBreakRecord record(PageBreakRecord::START_PAGE); + return !!GdiComment(hdc_, sizeof(record), + reinterpret_cast<const BYTE *>(&record)); +} + +bool Emf::EndPage() { + DCHECK(hdc_); + if (!hdc_) + return false; + PageBreakRecord record(PageBreakRecord::END_PAGE); + return !!GdiComment(hdc_, sizeof(record), + reinterpret_cast<const BYTE *>(&record)); +} + + Emf::Enumerator::Enumerator(const Emf& emf, HDC context, const RECT* rect) { context_.handle_table = NULL; context_.objects_count = 0; |