Cleanup code in printing/
- Use stdint.h types. - Fix lint errors. Review URL: https://codereview.chromium.org/1343593002 Cr-Commit-Position: refs/heads/master@{#348660}
This commit is contained in:
@ -113,7 +113,6 @@ class RasterBitmap {
|
||||
RECT rect = bitmap_rect.ToRECT();
|
||||
::FillRect(context_.Get(), &rect,
|
||||
static_cast<HBRUSH>(::GetStockObject(WHITE_BRUSH)));
|
||||
|
||||
}
|
||||
|
||||
~RasterBitmap() {
|
||||
@ -139,7 +138,7 @@ class RasterBitmap {
|
||||
|
||||
namespace printing {
|
||||
|
||||
bool DIBFormatNativelySupported(HDC dc, uint32 escape, const BYTE* bits,
|
||||
bool DIBFormatNativelySupported(HDC dc, uint32_t escape, const BYTE* bits,
|
||||
int size) {
|
||||
BOOL supported = FALSE;
|
||||
if (ExtEscape(dc, QUERYESCSUPPORT, sizeof(escape),
|
||||
@ -185,7 +184,7 @@ bool Emf::Init() {
|
||||
return hdc_ != NULL;
|
||||
}
|
||||
|
||||
bool Emf::InitFromData(const void* src_buffer, uint32 src_buffer_size) {
|
||||
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));
|
||||
@ -254,15 +253,15 @@ HDC Emf::context() const {
|
||||
return hdc_;
|
||||
}
|
||||
|
||||
uint32 Emf::GetDataSize() const {
|
||||
uint32_t Emf::GetDataSize() const {
|
||||
DCHECK(emf_ && !hdc_);
|
||||
return GetEnhMetaFileBits(emf_, 0, NULL);
|
||||
}
|
||||
|
||||
bool Emf::GetData(void* buffer, uint32 size) const {
|
||||
bool Emf::GetData(void* buffer, uint32_t size) const {
|
||||
DCHECK(emf_ && !hdc_);
|
||||
DCHECK(buffer && size);
|
||||
uint32 size2 =
|
||||
uint32_t size2 =
|
||||
GetEnhMetaFileBits(emf_, size, reinterpret_cast<BYTE*>(buffer));
|
||||
DCHECK(size2 == size);
|
||||
return size2 == size && size2 != 0;
|
||||
@ -530,7 +529,8 @@ scoped_ptr<Emf> Emf::RasterizeMetafile(int raster_area_in_pixels) const {
|
||||
page_bounds = gfx::Rect(1, 1);
|
||||
}
|
||||
|
||||
float scale = sqrt(float(raster_area_in_pixels) / page_size.GetArea());
|
||||
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));
|
||||
|
||||
@ -552,8 +552,10 @@ scoped_ptr<Emf> Emf::RasterizeMetafile(int raster_area_in_pixels) const {
|
||||
|
||||
::ModifyWorldTransform(hdc, NULL, MWT_IDENTITY);
|
||||
XFORM xform = {
|
||||
float(page_bounds.width()) / bitmap_rect.width(), 0,
|
||||
0, float(page_bounds.height()) / bitmap_rect.height(),
|
||||
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()),
|
||||
};
|
||||
|
@ -56,7 +56,7 @@ class PRINTING_EXPORT Emf : public Metafile {
|
||||
// Metafile methods.
|
||||
bool Init() override;
|
||||
bool InitFromData(const void* src_buffer,
|
||||
uint32 src_buffer_size) override;
|
||||
uint32_t src_buffer_size) override;
|
||||
|
||||
// Inserts a custom GDICOMMENT records indicating StartPage/EndPage calls
|
||||
// (since StartPage and EndPage do not work in a metafile DC). Only valid
|
||||
@ -68,8 +68,8 @@ class PRINTING_EXPORT Emf : public Metafile {
|
||||
bool FinishPage() override;
|
||||
bool FinishDocument() override;
|
||||
|
||||
uint32 GetDataSize() const override;
|
||||
bool GetData(void* buffer, uint32 size) const override;
|
||||
uint32_t GetDataSize() const override;
|
||||
bool GetData(void* buffer, uint32_t size) const override;
|
||||
|
||||
// Should be passed to Playback to keep the exact same size.
|
||||
gfx::Rect GetPageBounds(unsigned int page_number) const override;
|
||||
|
@ -45,13 +45,14 @@ class EmfPrintingTest : public testing::Test, public PrintingContext::Delegate {
|
||||
std::string GetAppLocale() override { return std::string(); }
|
||||
};
|
||||
|
||||
const uint32 EMF_HEADER_SIZE = 128;
|
||||
const uint32_t EMF_HEADER_SIZE = 128;
|
||||
const int ONE_MB = 1024 * 1024;
|
||||
|
||||
} // namespace
|
||||
|
||||
TEST(EmfTest, DC) {
|
||||
// Simplest use case.
|
||||
uint32 size;
|
||||
uint32_t size;
|
||||
std::vector<char> data;
|
||||
{
|
||||
Emf emf;
|
||||
@ -133,7 +134,7 @@ TEST_F(EmfPrintingTest, PageBreak) {
|
||||
CreateDC(L"WINSPOOL", L"UnitTest Printer", NULL, NULL));
|
||||
if (!dc.Get())
|
||||
return;
|
||||
uint32 size;
|
||||
uint32_t size;
|
||||
std::vector<char> data;
|
||||
{
|
||||
Emf emf;
|
||||
@ -178,7 +179,7 @@ TEST(EmfTest, FileBackedEmf) {
|
||||
base::FilePath metafile_path;
|
||||
EXPECT_TRUE(base::CreateTemporaryFileInDir(scratch_metafile_dir.path(),
|
||||
&metafile_path));
|
||||
uint32 size;
|
||||
uint32_t size;
|
||||
std::vector<char> data;
|
||||
{
|
||||
Emf emf;
|
||||
@ -192,7 +193,7 @@ TEST(EmfTest, FileBackedEmf) {
|
||||
EXPECT_TRUE(emf.GetDataAsVector(&data));
|
||||
EXPECT_EQ(data.size(), size);
|
||||
}
|
||||
int64 file_size = 0;
|
||||
int64_t file_size = 0;
|
||||
base::GetFileSize(metafile_path, &file_size);
|
||||
EXPECT_EQ(size, file_size);
|
||||
|
||||
@ -224,9 +225,9 @@ TEST(EmfTest, RasterizeMetafile) {
|
||||
raster = emf.RasterizeMetafile(20);
|
||||
EXPECT_EQ(emf.GetPageBounds(1), raster->GetPageBounds(1));
|
||||
|
||||
raster = emf.RasterizeMetafile(16 * 1024 * 1024);
|
||||
raster = emf.RasterizeMetafile(16 * ONE_MB);
|
||||
// Expected size about 64MB.
|
||||
EXPECT_LE(abs(int(raster->GetDataSize()) - 64 * 1024 * 1024), 1024 * 1024);
|
||||
EXPECT_LE(abs(static_cast<int>(raster->GetDataSize()) - 64 * ONE_MB), ONE_MB);
|
||||
// Bounds should still be the same.
|
||||
EXPECT_EQ(emf.GetPageBounds(1), raster->GetPageBounds(1));
|
||||
}
|
||||
|
@ -91,22 +91,22 @@ double Image::PercentageDifferent(const Image& rhs) const {
|
||||
int pixels_different = 0;
|
||||
for (int y = 0; y < height; ++y) {
|
||||
for (int x = 0; x < width; ++x) {
|
||||
uint32 lhs_pixel = pixel_at(x, y);
|
||||
uint32 rhs_pixel = rhs.pixel_at(x, y);
|
||||
uint32_t lhs_pixel = pixel_at(x, y);
|
||||
uint32_t rhs_pixel = rhs.pixel_at(x, y);
|
||||
if (lhs_pixel != rhs_pixel)
|
||||
++pixels_different;
|
||||
}
|
||||
|
||||
// Look for extra right lhs pixels. They should be white.
|
||||
for (int x = width; x < size_.width(); ++x) {
|
||||
uint32 lhs_pixel = pixel_at(x, y);
|
||||
uint32_t lhs_pixel = pixel_at(x, y);
|
||||
if (lhs_pixel != Color(SK_ColorWHITE))
|
||||
++pixels_different;
|
||||
}
|
||||
|
||||
// Look for extra right rhs pixels. They should be white.
|
||||
for (int x = width; x < rhs.size_.width(); ++x) {
|
||||
uint32 rhs_pixel = rhs.pixel_at(x, y);
|
||||
uint32_t rhs_pixel = rhs.pixel_at(x, y);
|
||||
if (rhs_pixel != Color(SK_ColorWHITE))
|
||||
++pixels_different;
|
||||
}
|
||||
@ -115,7 +115,7 @@ double Image::PercentageDifferent(const Image& rhs) const {
|
||||
// Look for extra bottom lhs pixels. They should be white.
|
||||
for (int y = height; y < size_.height(); ++y) {
|
||||
for (int x = 0; x < size_.width(); ++x) {
|
||||
uint32 lhs_pixel = pixel_at(x, y);
|
||||
uint32_t lhs_pixel = pixel_at(x, y);
|
||||
if (lhs_pixel != Color(SK_ColorWHITE))
|
||||
++pixels_different;
|
||||
}
|
||||
@ -124,7 +124,7 @@ double Image::PercentageDifferent(const Image& rhs) const {
|
||||
// Look for extra bottom rhs pixels. They should be white.
|
||||
for (int y = height; y < rhs.size_.height(); ++y) {
|
||||
for (int x = 0; x < rhs.size_.width(); ++x) {
|
||||
uint32 rhs_pixel = rhs.pixel_at(x, y);
|
||||
uint32_t rhs_pixel = rhs.pixel_at(x, y);
|
||||
if (rhs_pixel != Color(SK_ColorWHITE))
|
||||
++pixels_different;
|
||||
}
|
||||
@ -144,7 +144,7 @@ bool Image::LoadPng(const std::string& compressed) {
|
||||
reinterpret_cast<const unsigned char*>(compressed.c_str()),
|
||||
compressed.size(), gfx::PNGCodec::FORMAT_BGRA, &data_, &w, &h);
|
||||
size_.SetSize(w, h);
|
||||
row_length_ = size_.width() * sizeof(uint32);
|
||||
row_length_ = size_.width() * sizeof(uint32_t);
|
||||
return success;
|
||||
}
|
||||
|
||||
@ -152,7 +152,7 @@ bool Image::LoadMetafile(const std::string& data) {
|
||||
DCHECK(!data.empty());
|
||||
PdfMetafileSkia metafile;
|
||||
if (!metafile.InitFromData(data.data(),
|
||||
base::checked_cast<uint32>(data.size())))
|
||||
base::checked_cast<uint32_t>(data.size())))
|
||||
return false;
|
||||
return LoadMetafile(metafile);
|
||||
}
|
||||
|
@ -53,18 +53,18 @@ class PRINTING_EXPORT Image {
|
||||
double PercentageDifferent(const Image& rhs) const;
|
||||
|
||||
// Returns the 0x0RGB or 0xARGB value of the pixel at the given location.
|
||||
uint32 Color(uint32 color) const {
|
||||
uint32_t Color(uint32_t color) const {
|
||||
if (ignore_alpha_)
|
||||
return color & 0xFFFFFF; // Strip out A.
|
||||
else
|
||||
return color;
|
||||
}
|
||||
|
||||
uint32 pixel_at(int x, int y) const {
|
||||
uint32_t pixel_at(int x, int y) const {
|
||||
DCHECK(x >= 0 && x < size_.width());
|
||||
DCHECK(y >= 0 && y < size_.height());
|
||||
const uint32* data = reinterpret_cast<const uint32*>(&*data_.begin());
|
||||
const uint32* data_row = data + y * row_length_ / sizeof(uint32);
|
||||
const uint32_t* data = reinterpret_cast<const uint32_t*>(&*data_.begin());
|
||||
const uint32_t* data_row = data + y * row_length_ / sizeof(uint32_t);
|
||||
return Color(data_row[x]);
|
||||
}
|
||||
|
||||
@ -85,7 +85,7 @@ class PRINTING_EXPORT Image {
|
||||
// Length of a line in bytes.
|
||||
int row_length_;
|
||||
|
||||
// Actual bitmap data in arrays of RGBAs (so when loaded as uint32, it's
|
||||
// Actual bitmap data in arrays of RGBAs (so when loaded as uint32_t, it's
|
||||
// 0xABGR).
|
||||
std::vector<unsigned char> data_;
|
||||
|
||||
|
@ -20,7 +20,7 @@ bool Image::LoadMetafile(const Metafile& metafile) {
|
||||
return false;
|
||||
|
||||
size_ = rect.size();
|
||||
row_length_ = size_.width() * sizeof(uint32);
|
||||
row_length_ = size_.width() * sizeof(uint32_t);
|
||||
size_t bytes = row_length_ * size_.height();
|
||||
DCHECK(bytes);
|
||||
|
||||
|
@ -23,7 +23,7 @@ namespace {
|
||||
// destructor.
|
||||
class DisableFontSmoothing {
|
||||
public:
|
||||
explicit DisableFontSmoothing() : enable_again_(false) {
|
||||
DisableFontSmoothing() : enable_again_(false) {
|
||||
BOOL enabled;
|
||||
if (SystemParametersInfo(SPI_GETFONTSMOOTHING, 0, &enabled, 0) &&
|
||||
enabled) {
|
||||
@ -77,7 +77,7 @@ bool Image::LoadMetafile(const Metafile& metafile) {
|
||||
|
||||
bool success = metafile.Playback(hdc.Get(), NULL);
|
||||
|
||||
row_length_ = size_.width() * sizeof(uint32);
|
||||
row_length_ = size_.width() * sizeof(uint32_t);
|
||||
size_t bytes = row_length_ * size_.height();
|
||||
DCHECK(bytes);
|
||||
|
||||
|
@ -27,7 +27,8 @@ bool Metafile::GetDataAsVector(std::vector<char>* buffer) const {
|
||||
buffer->resize(GetDataSize());
|
||||
if (buffer->empty())
|
||||
return false;
|
||||
return GetData(&buffer->front(), base::checked_cast<uint32>(buffer->size()));
|
||||
return GetData(&buffer->front(),
|
||||
base::checked_cast<uint32_t>(buffer->size()));
|
||||
}
|
||||
|
||||
bool Metafile::SaveTo(base::File* file) const {
|
||||
|
@ -107,7 +107,8 @@ class PRINTING_EXPORT Metafile : public MetafilePlayer {
|
||||
// Initializes the metafile with the data in |src_buffer|. Returns true
|
||||
// on success.
|
||||
// Note: It should only be called from within the browser process.
|
||||
virtual bool InitFromData(const void* src_buffer, uint32 src_buffer_size) = 0;
|
||||
virtual bool InitFromData(const void* src_buffer,
|
||||
uint32_t src_buffer_size) = 0;
|
||||
|
||||
// Prepares a context for rendering a new page with the given |page_size|,
|
||||
// |content_area| and a |scale_factor| to use for the drawing. The units are
|
||||
@ -127,12 +128,12 @@ class PRINTING_EXPORT Metafile : public MetafilePlayer {
|
||||
|
||||
// Returns the size of the underlying data stream. Only valid after Close()
|
||||
// has been called.
|
||||
virtual uint32 GetDataSize() const = 0;
|
||||
virtual uint32_t GetDataSize() const = 0;
|
||||
|
||||
// Copies the first |dst_buffer_size| bytes of the underlying data stream into
|
||||
// |dst_buffer|. This function should ONLY be called after Close() is invoked.
|
||||
// Returns true if the copy succeeds.
|
||||
virtual bool GetData(void* dst_buffer, uint32 dst_buffer_size) const = 0;
|
||||
virtual bool GetData(void* dst_buffer, uint32_t dst_buffer_size) const = 0;
|
||||
|
||||
virtual gfx::Rect GetPageBounds(unsigned int page_number) const = 0;
|
||||
virtual unsigned int GetPageCount() const = 0;
|
||||
|
@ -70,7 +70,7 @@ void RotatePage(CGContextRef context, const CGRect rect, int num_rotations) {
|
||||
default:
|
||||
NOTREACHED();
|
||||
break;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
@ -128,7 +128,7 @@ bool PdfMetafileCg::Init() {
|
||||
}
|
||||
|
||||
bool PdfMetafileCg::InitFromData(const void* src_buffer,
|
||||
uint32 src_buffer_size) {
|
||||
uint32_t src_buffer_size) {
|
||||
DCHECK(!context_.get());
|
||||
DCHECK(!pdf_data_.get());
|
||||
|
||||
@ -295,23 +295,23 @@ gfx::Rect PdfMetafileCg::GetPageBounds(unsigned int page_number) const {
|
||||
return gfx::Rect(page_rect);
|
||||
}
|
||||
|
||||
uint32 PdfMetafileCg::GetDataSize() const {
|
||||
uint32_t PdfMetafileCg::GetDataSize() const {
|
||||
// PDF data is only valid/complete once the context is released.
|
||||
DCHECK(!context_);
|
||||
|
||||
if (!pdf_data_)
|
||||
return 0;
|
||||
return static_cast<uint32>(CFDataGetLength(pdf_data_));
|
||||
return static_cast<uint32_t>(CFDataGetLength(pdf_data_));
|
||||
}
|
||||
|
||||
bool PdfMetafileCg::GetData(void* dst_buffer, uint32 dst_buffer_size) const {
|
||||
bool PdfMetafileCg::GetData(void* dst_buffer, uint32_t dst_buffer_size) const {
|
||||
// PDF data is only valid/complete once the context is released.
|
||||
DCHECK(!context_);
|
||||
DCHECK(pdf_data_);
|
||||
DCHECK(dst_buffer);
|
||||
DCHECK_GT(dst_buffer_size, 0U);
|
||||
|
||||
uint32 data_size = GetDataSize();
|
||||
uint32_t data_size = GetDataSize();
|
||||
if (dst_buffer_size > data_size) {
|
||||
return false;
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ class PRINTING_EXPORT PdfMetafileCg : public Metafile {
|
||||
|
||||
// Metafile methods.
|
||||
bool Init() override;
|
||||
bool InitFromData(const void* src_buffer, uint32 src_buffer_size) override;
|
||||
bool InitFromData(const void* src_buffer, uint32_t src_buffer_size) override;
|
||||
|
||||
// Not implemented on mac.
|
||||
bool StartPage(const gfx::Size& page_size,
|
||||
@ -42,8 +42,8 @@ class PRINTING_EXPORT PdfMetafileCg : public Metafile {
|
||||
bool FinishPage() override;
|
||||
bool FinishDocument() override;
|
||||
|
||||
uint32 GetDataSize() const override;
|
||||
bool GetData(void* dst_buffer, uint32 dst_buffer_size) const override;
|
||||
uint32_t GetDataSize() const override;
|
||||
bool GetData(void* dst_buffer, uint32_t dst_buffer_size) const override;
|
||||
|
||||
gfx::Rect GetPageBounds(unsigned int page_number) const override;
|
||||
unsigned int GetPageCount() const override;
|
||||
|
@ -35,7 +35,7 @@ TEST(PdfMetafileCgTest, Pdf) {
|
||||
pdf.FinishDocument();
|
||||
|
||||
// Check data size.
|
||||
uint32 size = pdf.GetDataSize();
|
||||
uint32_t size = pdf.GetDataSize();
|
||||
EXPECT_GT(size, 0U);
|
||||
|
||||
// Get resulting data.
|
||||
|
@ -84,7 +84,7 @@ bool PdfMetafileSkia::Init() {
|
||||
// Metafile::InitFromData is orthogonal to what the rest of
|
||||
// PdfMetafileSkia does.
|
||||
bool PdfMetafileSkia::InitFromData(const void* src_buffer,
|
||||
uint32 src_buffer_size) {
|
||||
uint32_t src_buffer_size) {
|
||||
data_->pdf_data_.reset(new SkMemoryStream(src_buffer, src_buffer_size, true));
|
||||
return true;
|
||||
}
|
||||
@ -153,14 +153,14 @@ bool PdfMetafileSkia::FinishDocument() {
|
||||
return true;
|
||||
}
|
||||
|
||||
uint32 PdfMetafileSkia::GetDataSize() const {
|
||||
uint32_t PdfMetafileSkia::GetDataSize() const {
|
||||
if (!data_->pdf_data_)
|
||||
return 0;
|
||||
return base::checked_cast<uint32>(data_->pdf_data_->getLength());
|
||||
return base::checked_cast<uint32_t>(data_->pdf_data_->getLength());
|
||||
}
|
||||
|
||||
bool PdfMetafileSkia::GetData(void* dst_buffer,
|
||||
uint32 dst_buffer_size) const {
|
||||
uint32_t dst_buffer_size) const {
|
||||
if (!data_->pdf_data_)
|
||||
return false;
|
||||
return WriteAssetToBuffer(data_->pdf_data_.get(), dst_buffer,
|
||||
@ -215,7 +215,8 @@ bool PdfMetafileSkia::RenderPage(unsigned int page_number,
|
||||
size_t length = data_->pdf_data_->getLength();
|
||||
std::vector<uint8_t> buffer(length);
|
||||
(void)WriteAssetToBuffer(data_->pdf_data_.get(), &buffer[0], length);
|
||||
data_->pdf_cg_.InitFromData(&buffer[0], base::checked_cast<uint32>(length));
|
||||
data_->pdf_cg_.InitFromData(&buffer[0],
|
||||
base::checked_cast<uint32_t>(length));
|
||||
}
|
||||
return data_->pdf_cg_.RenderPage(page_number, context, rect, params);
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ class PRINTING_EXPORT PdfMetafileSkia : public Metafile {
|
||||
|
||||
// Metafile methods.
|
||||
bool Init() override;
|
||||
bool InitFromData(const void* src_buffer, uint32 src_buffer_size) override;
|
||||
bool InitFromData(const void* src_buffer, uint32_t src_buffer_size) override;
|
||||
|
||||
bool StartPage(const gfx::Size& page_size,
|
||||
const gfx::Rect& content_area,
|
||||
@ -44,8 +44,8 @@ class PRINTING_EXPORT PdfMetafileSkia : public Metafile {
|
||||
bool FinishPage() override;
|
||||
bool FinishDocument() override;
|
||||
|
||||
uint32 GetDataSize() const override;
|
||||
bool GetData(void* dst_buffer, uint32 dst_buffer_size) const override;
|
||||
uint32_t GetDataSize() const override;
|
||||
bool GetData(void* dst_buffer, uint32_t dst_buffer_size) const override;
|
||||
|
||||
gfx::Rect GetPageBounds(unsigned int page_number) const override;
|
||||
unsigned int GetPageCount() const override;
|
||||
|
@ -28,7 +28,7 @@ void PrintSettingsInitializerMac::InitPrintSettings(
|
||||
&resolution_count);
|
||||
if (status == noErr) {
|
||||
// Resolution indexes are 1-based.
|
||||
for (uint32 i = 1; i <= resolution_count; ++i) {
|
||||
for (uint32_t i = 1; i <= resolution_count; ++i) {
|
||||
PMResolution resolution;
|
||||
PMPrinterGetIndexedPrinterResolution(printer, i, &resolution);
|
||||
if (resolution.hRes > best_resolution.hRes)
|
||||
|
Reference in New Issue
Block a user