Index: printing/emf_win.cc |
diff --git a/printing/emf_win.cc b/printing/emf_win.cc |
index 9bd3e1eed20e36a624293e13cb43333d3b326705..0008ab031a4498b8e7fc372df0b55fd4f9b993b4 100644 |
--- a/printing/emf_win.cc |
+++ b/printing/emf_win.cc |
@@ -15,9 +15,6 @@ |
#include "base/macros.h" |
#include "base/memory/ptr_util.h" |
#include "base/numerics/safe_conversions.h" |
-#include "base/win/scoped_gdi_object.h" |
-#include "base/win/scoped_hdc.h" |
-#include "base/win/scoped_select_object.h" |
#include "skia/ext/skia_utils_win.h" |
#include "third_party/skia/include/core/SkBitmap.h" |
#include "ui/gfx/codec/jpeg_codec.h" |
@@ -29,116 +26,6 @@ namespace printing { |
namespace { |
-int CALLBACK IsAlphaBlendUsedEnumProc(HDC, |
- HANDLETABLE*, |
- const ENHMETARECORD *record, |
- int, |
- LPARAM data) { |
- bool* result = reinterpret_cast<bool*>(data); |
- if (!result) |
- return 0; |
- switch (record->iType) { |
- case EMR_ALPHABLEND: { |
- *result = true; |
- return 0; |
- break; |
- } |
- } |
- return 1; |
-} |
- |
-int CALLBACK RasterizeAlphaBlendProc(HDC metafile_dc, |
- HANDLETABLE* handle_table, |
- const ENHMETARECORD *record, |
- int num_objects, |
- LPARAM data) { |
- HDC bitmap_dc = *reinterpret_cast<HDC*>(data); |
- // Play this command to the bitmap DC. |
- ::PlayEnhMetaFileRecord(bitmap_dc, handle_table, record, num_objects); |
- switch (record->iType) { |
- case EMR_ALPHABLEND: { |
- const EMRALPHABLEND* alpha_blend = |
- reinterpret_cast<const EMRALPHABLEND*>(record); |
- // Don't modify transformation here. |
- // Old implementation did reset transformations for DC to identity matrix. |
- // That was not correct and cause some bugs, like unexpected cropping. |
- // EMRALPHABLEND is rendered into bitmap and metafile contexts with |
- // current transformation. If we don't touch them here BitBlt will copy |
- // same areas. |
- ::BitBlt(metafile_dc, |
- alpha_blend->xDest, |
- alpha_blend->yDest, |
- alpha_blend->cxDest, |
- alpha_blend->cyDest, |
- bitmap_dc, |
- alpha_blend->xDest, |
- alpha_blend->yDest, |
- SRCCOPY); |
- break; |
- } |
- case EMR_CREATEBRUSHINDIRECT: |
- case EMR_CREATECOLORSPACE: |
- case EMR_CREATECOLORSPACEW: |
- case EMR_CREATEDIBPATTERNBRUSHPT: |
- case EMR_CREATEMONOBRUSH: |
- case EMR_CREATEPALETTE: |
- case EMR_CREATEPEN: |
- case EMR_DELETECOLORSPACE: |
- case EMR_DELETEOBJECT: |
- case EMR_EXTCREATEFONTINDIRECTW: |
- // Play object creation command only once. |
- break; |
- |
- default: |
- // Play this command to the metafile DC. |
- ::PlayEnhMetaFileRecord(metafile_dc, handle_table, record, num_objects); |
- break; |
- } |
- return 1; // Continue enumeration |
-} |
- |
-// Bitmapt for rasterization. |
-class RasterBitmap { |
- public: |
- explicit RasterBitmap(const gfx::Size& raster_size) : saved_object_(nullptr) { |
- context_.Set(::CreateCompatibleDC(nullptr)); |
- if (!context_.IsValid()) { |
- NOTREACHED() << "Bitmap DC creation failed"; |
- return; |
- } |
- ::SetGraphicsMode(context_.Get(), GM_ADVANCED); |
- void* bits = nullptr; |
- gfx::Rect bitmap_rect(raster_size); |
- skia::CreateBitmapHeader(raster_size.width(), raster_size.height(), |
- &header_.bmiHeader); |
- bitmap_.reset(CreateDIBSection(context_.Get(), &header_, DIB_RGB_COLORS, |
- &bits, nullptr, 0)); |
- if (!bitmap_.is_valid()) |
- NOTREACHED() << "Raster bitmap creation for printing failed"; |
- |
- saved_object_ = ::SelectObject(context_.Get(), bitmap_.get()); |
- RECT rect = bitmap_rect.ToRECT(); |
- ::FillRect(context_.Get(), &rect, |
- static_cast<HBRUSH>(::GetStockObject(WHITE_BRUSH))); |
- } |
- |
- ~RasterBitmap() { |
- ::SelectObject(context_.Get(), saved_object_); |
- } |
- |
- HDC context() const { |
- return context_.Get(); |
- } |
- |
- base::win::ScopedCreateDC context_; |
- BITMAPINFO header_; |
- base::win::ScopedBitmap bitmap_; |
- HGDIOBJ saved_object_; |
- |
- private: |
- DISALLOW_COPY_AND_ASSIGN(RasterBitmap); |
-}; |
- |
bool DIBFormatNativelySupported(HDC dc, uint32_t escape, const BYTE* bits, |
int size) { |
BOOL supported = FALSE; |
@@ -514,90 +401,4 @@ int CALLBACK Emf::Enumerator::EnhMetaFileProc(HDC hdc, |
return 1; |
} |
-bool Emf::IsAlphaBlendUsed() const { |
- bool result = false; |
- ::EnumEnhMetaFile(nullptr, emf(), &IsAlphaBlendUsedEnumProc, &result, |
- nullptr); |
- return result; |
-} |
- |
-std::unique_ptr<Emf> Emf::RasterizeMetafile(int raster_area_in_pixels) const { |
- gfx::Rect page_bounds = GetPageBounds(1); |
- gfx::Size page_size(page_bounds.size()); |
- if (page_size.GetArea() <= 0) { |
- NOTREACHED() << "Metafile is empty"; |
- page_bounds = gfx::Rect(1, 1); |
- } |
- |
- float scale = sqrt( |
- static_cast<float>(raster_area_in_pixels) / page_size.GetArea()); |
- page_size.set_width(std::max<int>(1, page_size.width() * scale)); |
- page_size.set_height(std::max<int>(1, page_size.height() * scale)); |
- |
- |
- RasterBitmap bitmap(page_size); |
- |
- gfx::Rect bitmap_rect(page_size); |
- RECT rect = bitmap_rect.ToRECT(); |
- Playback(bitmap.context(), &rect); |
- |
- std::unique_ptr<Emf> result = base::MakeUnique<Emf>(); |
- result->Init(); |
- HDC hdc = result->context(); |
- DCHECK(hdc); |
- skia::InitializeDC(hdc); |
- |
- // Params are ignored. |
- result->StartPage(page_bounds.size(), page_bounds, 1); |
- |
- ::ModifyWorldTransform(hdc, nullptr, MWT_IDENTITY); |
- XFORM xform = { |
- static_cast<float>(page_bounds.width()) / bitmap_rect.width(), |
- 0, |
- 0, |
- static_cast<float>(page_bounds.height()) / bitmap_rect.height(), |
- static_cast<float>(page_bounds.x()), |
- static_cast<float>(page_bounds.y()), |
- }; |
- ::SetWorldTransform(hdc, &xform); |
- ::BitBlt(hdc, 0, 0, bitmap_rect.width(), bitmap_rect.height(), |
- bitmap.context(), bitmap_rect.x(), bitmap_rect.y(), SRCCOPY); |
- |
- result->FinishPage(); |
- result->FinishDocument(); |
- return result; |
-} |
- |
-std::unique_ptr<Emf> Emf::RasterizeAlphaBlend() const { |
- gfx::Rect page_bounds = GetPageBounds(1); |
- if (page_bounds.size().GetArea() <= 0) { |
- NOTREACHED() << "Metafile is empty"; |
- page_bounds = gfx::Rect(1, 1); |
- } |
- |
- RasterBitmap bitmap(page_bounds.size()); |
- |
- // Map metafile page_bounds.x(), page_bounds.y() to bitmap 0, 0. |
- XFORM xform = {1, |
- 0, |
- 0, |
- 1, |
- static_cast<float>(-page_bounds.x()), |
- static_cast<float>(-page_bounds.y())}; |
- ::SetWorldTransform(bitmap.context(), &xform); |
- |
- std::unique_ptr<Emf> result = base::MakeUnique<Emf>(); |
- result->Init(); |
- HDC hdc = result->context(); |
- DCHECK(hdc); |
- skia::InitializeDC(hdc); |
- |
- HDC bitmap_dc = bitmap.context(); |
- RECT rect = page_bounds.ToRECT(); |
- ::EnumEnhMetaFile(hdc, emf(), &RasterizeAlphaBlendProc, &bitmap_dc, &rect); |
- |
- result->FinishDocument(); |
- return result; |
-} |
- |
} // namespace printing |