Index: printing/emf_win.cc |
diff --git a/printing/emf_win.cc b/printing/emf_win.cc |
index 74b5401aaced674109fb4c773a5302ed7963dee0..8dde50351ce64c7b2d08a4ed3111179042fce79f 100644 |
--- a/printing/emf_win.cc |
+++ b/printing/emf_win.cc |
@@ -6,12 +6,14 @@ |
#include <stdint.h> |
+#include <algorithm> |
#include <memory> |
#include "base/files/file.h" |
#include "base/files/file_path.h" |
#include "base/logging.h" |
#include "base/macros.h" |
+#include "base/memory/ptr_util.h" |
#include "base/win/scoped_gdi_object.h" |
#include "base/win/scoped_hdc.h" |
#include "base/win/scoped_select_object.h" |
@@ -22,6 +24,8 @@ |
#include "ui/gfx/geometry/rect.h" |
#include "ui/gfx/geometry/size.h" |
+namespace printing { |
+ |
namespace { |
int CALLBACK IsAlphaBlendUsedEnumProc(HDC, |
@@ -95,20 +99,19 @@ int CALLBACK RasterizeAlphaBlendProc(HDC metafile_dc, |
// Bitmapt for rasterization. |
class RasterBitmap { |
public: |
- explicit RasterBitmap(const gfx::Size& raster_size) |
- : saved_object_(NULL) { |
- context_.Set(::CreateCompatibleDC(NULL)); |
+ 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 = NULL; |
+ 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, NULL, 0)); |
+ &bits, nullptr, 0)); |
if (!bitmap_.is_valid()) |
NOTREACHED() << "Raster bitmap creation for printing failed"; |
@@ -135,12 +138,6 @@ class RasterBitmap { |
DISALLOW_COPY_AND_ASSIGN(RasterBitmap); |
}; |
- |
- |
-} // namespace |
- |
-namespace printing { |
- |
bool DIBFormatNativelySupported(HDC dc, uint32_t escape, const BYTE* bits, |
int size) { |
BOOL supported = FALSE; |
@@ -152,8 +149,9 @@ bool DIBFormatNativelySupported(HDC dc, uint32_t escape, const BYTE* bits, |
return !!supported; |
} |
-Emf::Emf() : emf_(NULL), hdc_(NULL) { |
-} |
+} // namespace |
+ |
+Emf::Emf() : emf_(nullptr), hdc_(nullptr) {} |
Emf::~Emf() { |
Close(); |
@@ -163,43 +161,44 @@ void Emf::Close() { |
DCHECK(!hdc_); |
if (emf_) |
DeleteEnhMetaFile(emf_); |
- emf_ = NULL; |
+ emf_ = nullptr; |
} |
bool Emf::InitToFile(const base::FilePath& metafile_path) { |
DCHECK(!emf_ && !hdc_); |
- hdc_ = CreateEnhMetaFile(NULL, metafile_path.value().c_str(), NULL, NULL); |
+ hdc_ = CreateEnhMetaFile(nullptr, metafile_path.value().c_str(), nullptr, |
+ nullptr); |
DCHECK(hdc_); |
- return hdc_ != NULL; |
+ return !!hdc_; |
} |
bool Emf::InitFromFile(const base::FilePath& metafile_path) { |
DCHECK(!emf_ && !hdc_); |
emf_ = GetEnhMetaFile(metafile_path.value().c_str()); |
DCHECK(emf_); |
- return emf_ != NULL; |
+ return !!emf_; |
} |
bool Emf::Init() { |
DCHECK(!emf_ && !hdc_); |
- hdc_ = CreateEnhMetaFile(NULL, NULL, NULL, NULL); |
+ hdc_ = CreateEnhMetaFile(nullptr, nullptr, nullptr, nullptr); |
DCHECK(hdc_); |
- return hdc_ != NULL; |
+ return !!hdc_; |
} |
bool Emf::InitFromData(const void* src_buffer, uint32_t src_buffer_size) { |
DCHECK(!emf_ && !hdc_); |
emf_ = SetEnhMetaFileBits(src_buffer_size, |
reinterpret_cast<const BYTE*>(src_buffer)); |
- return emf_ != NULL; |
+ return !!emf_; |
} |
bool Emf::FinishDocument() { |
DCHECK(!emf_ && hdc_); |
emf_ = CloseEnhMetaFile(hdc_); |
DCHECK(emf_); |
- hdc_ = NULL; |
- return emf_ != NULL; |
+ hdc_ = nullptr; |
+ return !!emf_; |
} |
bool Emf::Playback(HDC hdc, const RECT* rect) const { |
@@ -258,7 +257,7 @@ HDC Emf::context() const { |
uint32_t Emf::GetDataSize() const { |
DCHECK(emf_ && !hdc_); |
- return GetEnhMetaFileBits(emf_, 0, NULL); |
+ return GetEnhMetaFileBits(emf_, 0, nullptr); |
} |
bool Emf::GetData(void* buffer, uint32_t size) const { |
@@ -350,12 +349,11 @@ bool Emf::Record::SafePlayback(Emf::EnumerationContext* context) const { |
const XFORM* base_matrix = context->base_matrix; |
switch (record()->iType) { |
case EMR_STRETCHDIBITS: { |
- const EMRSTRETCHDIBITS * sdib_record = |
+ const EMRSTRETCHDIBITS* sdib_record = |
reinterpret_cast<const EMRSTRETCHDIBITS*>(record()); |
const BYTE* record_start = reinterpret_cast<const BYTE *>(record()); |
- const BITMAPINFOHEADER *bmih = |
- reinterpret_cast<const BITMAPINFOHEADER *>(record_start + |
- sdib_record->offBmiSrc); |
+ const BITMAPINFOHEADER* bmih = reinterpret_cast<const BITMAPINFOHEADER*>( |
+ record_start + sdib_record->offBmiSrc); |
const BYTE* bits = record_start + sdib_record->offBitsSrc; |
bool play_normally = true; |
res = false; |
@@ -371,18 +369,20 @@ bool Emf::Record::SafePlayback(Emf::EnumerationContext* context) const { |
if (!DIBFormatNativelySupported(hdc, CHECKPNGFORMAT, bits, |
bmih->biSizeImage)) { |
play_normally = false; |
- bitmap.reset(new SkBitmap()); |
+ bitmap = base::MakeUnique<SkBitmap>(); |
gfx::PNGCodec::Decode(bits, bmih->biSizeImage, bitmap.get()); |
} |
} |
- if (!play_normally) { |
+ if (play_normally) { |
+ res = Play(context); |
+ } else { |
DCHECK(bitmap.get()); |
if (bitmap.get()) { |
SkAutoLockPixels lock(*bitmap.get()); |
DCHECK_EQ(bitmap->colorType(), kN32_SkColorType); |
const uint32_t* pixels = |
static_cast<const uint32_t*>(bitmap->getPixels()); |
- if (pixels == NULL) { |
+ if (!pixels) { |
NOTREACHED(); |
return false; |
} |
@@ -398,8 +398,6 @@ bool Emf::Record::SafePlayback(Emf::EnumerationContext* context) const { |
sdib_record->iUsageSrc, |
sdib_record->dwRop)); |
} |
- } else { |
- res = Play(context); |
} |
break; |
} |
@@ -515,11 +513,8 @@ int CALLBACK Emf::Enumerator::EnhMetaFileProc(HDC hdc, |
bool Emf::IsAlphaBlendUsed() const { |
bool result = false; |
- ::EnumEnhMetaFile(NULL, |
- emf(), |
- &IsAlphaBlendUsedEnumProc, |
- &result, |
- NULL); |
+ ::EnumEnhMetaFile(nullptr, emf(), &IsAlphaBlendUsedEnumProc, &result, |
+ nullptr); |
return result; |
} |
@@ -543,7 +538,7 @@ std::unique_ptr<Emf> Emf::RasterizeMetafile(int raster_area_in_pixels) const { |
RECT rect = bitmap_rect.ToRECT(); |
Playback(bitmap.context(), &rect); |
- std::unique_ptr<Emf> result(new Emf); |
+ std::unique_ptr<Emf> result = base::MakeUnique<Emf>(); |
result->Init(); |
HDC hdc = result->context(); |
DCHECK(hdc); |
@@ -552,7 +547,7 @@ std::unique_ptr<Emf> Emf::RasterizeMetafile(int raster_area_in_pixels) const { |
// Params are ignored. |
result->StartPage(page_bounds.size(), page_bounds, 1); |
- ::ModifyWorldTransform(hdc, NULL, MWT_IDENTITY); |
+ ::ModifyWorldTransform(hdc, nullptr, MWT_IDENTITY); |
XFORM xform = { |
static_cast<float>(page_bounds.width()) / bitmap_rect.width(), |
0, |
@@ -567,7 +562,6 @@ std::unique_ptr<Emf> Emf::RasterizeMetafile(int raster_area_in_pixels) const { |
result->FinishPage(); |
result->FinishDocument(); |
- |
return result; |
} |
@@ -589,7 +583,7 @@ std::unique_ptr<Emf> Emf::RasterizeAlphaBlend() const { |
static_cast<float>(-page_bounds.y())}; |
::SetWorldTransform(bitmap.context(), &xform); |
- std::unique_ptr<Emf> result(new Emf); |
+ std::unique_ptr<Emf> result = base::MakeUnique<Emf>(); |
result->Init(); |
HDC hdc = result->context(); |
DCHECK(hdc); |
@@ -600,9 +594,7 @@ std::unique_ptr<Emf> Emf::RasterizeAlphaBlend() const { |
::EnumEnhMetaFile(hdc, emf(), &RasterizeAlphaBlendProc, &bitmap_dc, &rect); |
result->FinishDocument(); |
- |
return result; |
} |
- |
} // namespace printing |