Commit 1c5da8e6 authored by Henrique Nakashima's avatar Henrique Nakashima Committed by Commit Bot

Use constexpr where possible in src/pdf.

Change-Id: Icd771944352b9c161933c477fe714492aa38bbe7
Reviewed-on: https://chromium-review.googlesource.com/c/1265637Reviewed-by: default avatarLei Zhang <thestig@chromium.org>
Commit-Queue: Henrique Nakashima <hnakashima@chromium.org>
Cr-Commit-Position: refs/heads/master@{#597327}
parent 0b2d3330
...@@ -70,7 +70,7 @@ TEST(ChunkStreamTest, FillGap) { ...@@ -70,7 +70,7 @@ TEST(ChunkStreamTest, FillGap) {
TEST(ChunkStreamTest, Read) { TEST(ChunkStreamTest, Read) {
TestChunkStream stream; TestChunkStream stream;
stream.set_eof_pos(25); stream.set_eof_pos(25);
const unsigned char start_value = 33; constexpr unsigned char start_value = 33;
unsigned char value = start_value; unsigned char value = start_value;
auto chunk_0 = CreateChunkData(); auto chunk_0 = CreateChunkData();
for (auto& it : *chunk_0) { for (auto& it : *chunk_0) {
......
...@@ -25,7 +25,7 @@ namespace { ...@@ -25,7 +25,7 @@ namespace {
// current connection (like playing a cassette tape) and do not send new range // current connection (like playing a cassette tape) and do not send new range
// request (like rewind a cassette tape, and continue playing after). // request (like rewind a cassette tape, and continue playing after).
// Experimentally chosen value. // Experimentally chosen value.
const int kChunkCloseDistance = 10; constexpr int kChunkCloseDistance = 10;
// Return true if the HTTP response of |loader| is a successful one and loading // Return true if the HTTP response of |loader| is a successful one and loading
// should continue. 4xx error indicate subsequent requests will fail too. // should continue. 4xx error indicate subsequent requests will fail too.
......
...@@ -232,7 +232,7 @@ class TestClient : public DocumentLoader::Client { ...@@ -232,7 +232,7 @@ class TestClient : public DocumentLoader::Client {
partial_loader_data_.CallOpenCallback(0); partial_loader_data_.CallOpenCallback(0);
uint32_t length = partial_loader_data_.byte_range().length(); uint32_t length = partial_loader_data_.byte_range().length();
while (length > 0) { while (length > 0) {
const uint32_t max_part_len = kDefaultRequestSize; constexpr uint32_t max_part_len = kDefaultRequestSize;
const uint32_t part_len = std::min(length, max_part_len); const uint32_t part_len = std::min(length, max_part_len);
partial_loader_data_.CallReadCallback(part_len); partial_loader_data_.CallReadCallback(part_len);
length -= part_len; length -= part_len;
...@@ -468,7 +468,7 @@ TEST_F(DocumentLoaderImplTest, CompleteWithPartial) { ...@@ -468,7 +468,7 @@ TEST_F(DocumentLoaderImplTest, CompleteWithPartial) {
} }
TEST_F(DocumentLoaderImplTest, PartialRequestLastChunk) { TEST_F(DocumentLoaderImplTest, PartialRequestLastChunk) {
const uint32_t kLastChunkSize = 300; constexpr uint32_t kLastChunkSize = 300;
TestClient client; TestClient client;
client.SetCanUsePartialLoading(); client.SetCanUsePartialLoading();
client.full_page_loader_data()->set_content_length(kDefaultRequestSize * 20 + client.full_page_loader_data()->set_content_length(kDefaultRequestSize * 20 +
...@@ -539,8 +539,8 @@ TEST_F(DocumentLoaderImplTest, ClearPendingRequests) { ...@@ -539,8 +539,8 @@ TEST_F(DocumentLoaderImplTest, ClearPendingRequests) {
{ {
EXPECT_TRUE(client.partial_loader_data()->IsWaitOpen()); EXPECT_TRUE(client.partial_loader_data()->IsWaitOpen());
const gfx::Range range_requested(15 * kDefaultRequestSize, constexpr gfx::Range range_requested(15 * kDefaultRequestSize,
16 * kDefaultRequestSize); 16 * kDefaultRequestSize);
EXPECT_EQ(range_requested.start(), EXPECT_EQ(range_requested.start(),
client.partial_loader_data()->open_byte_range().start()); client.partial_loader_data()->open_byte_range().start());
EXPECT_LE(range_requested.end(), EXPECT_LE(range_requested.end(),
...@@ -575,8 +575,8 @@ TEST_F(DocumentLoaderImplTest, ClearPendingRequests) { ...@@ -575,8 +575,8 @@ TEST_F(DocumentLoaderImplTest, ClearPendingRequests) {
// Loading should be restarted. // Loading should be restarted.
EXPECT_TRUE(client.partial_loader_data()->IsWaitOpen()); EXPECT_TRUE(client.partial_loader_data()->IsWaitOpen());
// The first requested chunk should be processed. // The first requested chunk should be processed.
const gfx::Range range_requested(35 * kDefaultRequestSize, constexpr gfx::Range range_requested(35 * kDefaultRequestSize,
36 * kDefaultRequestSize); 36 * kDefaultRequestSize);
EXPECT_EQ(range_requested.start(), EXPECT_EQ(range_requested.start(),
client.partial_loader_data()->open_byte_range().start()); client.partial_loader_data()->open_byte_range().start());
EXPECT_LE(range_requested.end(), EXPECT_LE(range_requested.end(),
...@@ -597,8 +597,8 @@ TEST_F(DocumentLoaderImplTest, ClearPendingRequests) { ...@@ -597,8 +597,8 @@ TEST_F(DocumentLoaderImplTest, ClearPendingRequests) {
// Loading should be restarted . // Loading should be restarted .
EXPECT_TRUE(client.partial_loader_data()->IsWaitOpen()); EXPECT_TRUE(client.partial_loader_data()->IsWaitOpen());
// The first requested chunk should be processed. // The first requested chunk should be processed.
const gfx::Range range_requested(70 * kDefaultRequestSize, constexpr gfx::Range range_requested(70 * kDefaultRequestSize,
71 * kDefaultRequestSize); 71 * kDefaultRequestSize);
EXPECT_EQ(range_requested.start(), EXPECT_EQ(range_requested.start(),
client.partial_loader_data()->open_byte_range().start()); client.partial_loader_data()->open_byte_range().start());
EXPECT_LE(range_requested.end(), EXPECT_LE(range_requested.end(),
...@@ -676,8 +676,8 @@ TEST_F(DocumentLoaderImplTest, RequestData) { ...@@ -676,8 +676,8 @@ TEST_F(DocumentLoaderImplTest, RequestData) {
{ {
EXPECT_TRUE(client.partial_loader_data()->IsWaitOpen()); EXPECT_TRUE(client.partial_loader_data()->IsWaitOpen());
const gfx::Range range_requested(13 * kDefaultRequestSize, constexpr gfx::Range range_requested(13 * kDefaultRequestSize,
14 * kDefaultRequestSize); 14 * kDefaultRequestSize);
EXPECT_EQ(range_requested.start(), EXPECT_EQ(range_requested.start(),
client.partial_loader_data()->open_byte_range().start()); client.partial_loader_data()->open_byte_range().start());
EXPECT_LE(range_requested.end(), EXPECT_LE(range_requested.end(),
...@@ -694,8 +694,8 @@ TEST_F(DocumentLoaderImplTest, RequestData) { ...@@ -694,8 +694,8 @@ TEST_F(DocumentLoaderImplTest, RequestData) {
client.partial_loader_data()->CallReadCallback(kDefaultRequestSize); client.partial_loader_data()->CallReadCallback(kDefaultRequestSize);
{ {
EXPECT_TRUE(client.partial_loader_data()->IsWaitOpen()); EXPECT_TRUE(client.partial_loader_data()->IsWaitOpen());
const gfx::Range range_requested(26 * kDefaultRequestSize, constexpr gfx::Range range_requested(26 * kDefaultRequestSize,
27 * kDefaultRequestSize); 27 * kDefaultRequestSize);
EXPECT_EQ(range_requested.start(), EXPECT_EQ(range_requested.start(),
client.partial_loader_data()->open_byte_range().start()); client.partial_loader_data()->open_byte_range().start());
EXPECT_LE(range_requested.end(), EXPECT_LE(range_requested.end(),
...@@ -711,8 +711,8 @@ TEST_F(DocumentLoaderImplTest, RequestData) { ...@@ -711,8 +711,8 @@ TEST_F(DocumentLoaderImplTest, RequestData) {
client.partial_loader_data()->CallReadCallback(kDefaultRequestSize); client.partial_loader_data()->CallReadCallback(kDefaultRequestSize);
{ {
EXPECT_TRUE(client.partial_loader_data()->IsWaitOpen()); EXPECT_TRUE(client.partial_loader_data()->IsWaitOpen());
const gfx::Range range_requested(39 * kDefaultRequestSize, constexpr gfx::Range range_requested(39 * kDefaultRequestSize,
40 * kDefaultRequestSize); 40 * kDefaultRequestSize);
EXPECT_EQ(range_requested.start(), EXPECT_EQ(range_requested.start(),
client.partial_loader_data()->open_byte_range().start()); client.partial_loader_data()->open_byte_range().start());
EXPECT_LE(range_requested.end(), EXPECT_LE(range_requested.end(),
...@@ -796,8 +796,8 @@ TEST_F(DocumentLoaderImplTest, MergePendingRequests) { ...@@ -796,8 +796,8 @@ TEST_F(DocumentLoaderImplTest, MergePendingRequests) {
// Send initial data from FullPageLoader. // Send initial data from FullPageLoader.
client.full_page_loader_data()->CallReadCallback(kDefaultRequestSize); client.full_page_loader_data()->CallReadCallback(kDefaultRequestSize);
const gfx::Range range_requested(16 * kDefaultRequestSize, constexpr gfx::Range range_requested(16 * kDefaultRequestSize,
18 * kDefaultRequestSize); 18 * kDefaultRequestSize);
EXPECT_EQ(range_requested.start(), EXPECT_EQ(range_requested.start(),
client.partial_loader_data()->open_byte_range().start()); client.partial_loader_data()->open_byte_range().start());
EXPECT_LE(range_requested.end(), EXPECT_LE(range_requested.end(),
...@@ -1102,7 +1102,7 @@ TEST_F(DocumentLoaderImplTest, IgnoreDataMoreThanExpectedWithPartial) { ...@@ -1102,7 +1102,7 @@ TEST_F(DocumentLoaderImplTest, IgnoreDataMoreThanExpectedWithPartial) {
client.partial_loader_data()->CallOpenCallback(0); client.partial_loader_data()->CallOpenCallback(0);
uint32_t length = expected_length; uint32_t length = expected_length;
while (length > 0) { while (length > 0) {
const uint32_t max_part_len = kDefaultRequestSize; constexpr uint32_t max_part_len = kDefaultRequestSize;
const uint32_t part_len = std::min(length, max_part_len); const uint32_t part_len = std::min(length, max_part_len);
client.partial_loader_data()->CallReadCallback(part_len); client.partial_loader_data()->CallReadCallback(part_len);
length -= part_len; length -= part_len;
...@@ -1144,7 +1144,7 @@ TEST_F(DocumentLoaderImplTest, IgnoreDataMoreThanExpectedWithPartialAtFileEnd) { ...@@ -1144,7 +1144,7 @@ TEST_F(DocumentLoaderImplTest, IgnoreDataMoreThanExpectedWithPartialAtFileEnd) {
client.partial_loader_data()->CallOpenCallback(0); client.partial_loader_data()->CallOpenCallback(0);
uint32_t length = client.partial_loader_data()->byte_range().length(); uint32_t length = client.partial_loader_data()->byte_range().length();
while (length > 0) { while (length > 0) {
const uint32_t max_part_len = kDefaultRequestSize; constexpr uint32_t max_part_len = kDefaultRequestSize;
const uint32_t part_len = std::min(length, max_part_len); const uint32_t part_len = std::min(length, max_part_len);
client.partial_loader_data()->CallReadCallback(part_len); client.partial_loader_data()->CallReadCallback(part_len);
length -= part_len; length -= part_len;
......
...@@ -55,7 +55,7 @@ ShadowMatrix::ShadowMatrix(uint32_t depth, double factor, uint32_t background) ...@@ -55,7 +55,7 @@ ShadowMatrix::ShadowMatrix(uint32_t depth, double factor, uint32_t background)
// pv - is a rounding power factor for smoothing corners. // pv - is a rounding power factor for smoothing corners.
// pv = 2.0 will make corners completely round. // pv = 2.0 will make corners completely round.
const double pv = 4.0; constexpr double pv = 4.0;
// pow_pv - cache to avoid recalculating pow(x, pv) every time. // pow_pv - cache to avoid recalculating pow(x, pv) every time.
std::vector<double> pow_pv(depth_, 0.0); std::vector<double> pow_pv(depth_, 0.0);
......
This diff is collapsed.
...@@ -55,7 +55,7 @@ pp::Size PaintManager::GetNewContextSize(const pp::Size& current_context_size, ...@@ -55,7 +55,7 @@ pp::Size PaintManager::GetNewContextSize(const pp::Size& current_context_size,
const pp::Size& plugin_size) { const pp::Size& plugin_size) {
// The amount of additional space in pixels to allocate to the right/bottom of // The amount of additional space in pixels to allocate to the right/bottom of
// the context. // the context.
const int kBufferSize = 50; constexpr int kBufferSize = 50;
// Default to returning the same size. // Default to returning the same size.
pp::Size result = current_context_size; pp::Size result = current_context_size;
......
...@@ -42,9 +42,9 @@ double CalculateScaleFactor(const gfx::Rect& content_rect, ...@@ -42,9 +42,9 @@ double CalculateScaleFactor(const gfx::Rect& content_rect,
} }
void SetDefaultClipBox(bool rotated, PdfRectangle* clip_box) { void SetDefaultClipBox(bool rotated, PdfRectangle* clip_box) {
const int kDpi = 72; constexpr int kDpi = 72;
const float kPaperWidth = 8.5 * kDpi; constexpr float kPaperWidth = 8.5 * kDpi;
const float kPaperHeight = 11 * kDpi; constexpr float kPaperHeight = 11 * kDpi;
clip_box->left = 0; clip_box->left = 0;
clip_box->bottom = 0; clip_box->bottom = 0;
clip_box->right = rotated ? kPaperHeight : kPaperWidth; clip_box->right = rotated ? kPaperHeight : kPaperWidth;
......
...@@ -12,10 +12,10 @@ namespace chrome_pdf { ...@@ -12,10 +12,10 @@ namespace chrome_pdf {
namespace { namespace {
const float kDefaultWidth = 8.5 * printing::kPointsPerInch; constexpr float kDefaultWidth = 8.5 * printing::kPointsPerInch;
const float kDefaultHeight = 11.0 * printing::kPointsPerInch; constexpr float kDefaultHeight = 11.0 * printing::kPointsPerInch;
const float kDefaultRatio = kDefaultWidth / kDefaultHeight; constexpr float kDefaultRatio = kDefaultWidth / kDefaultHeight;
const double kTolerance = 0.0001; constexpr double kTolerance = 0.0001;
void ExpectDefaultPortraitBox(const PdfRectangle& box) { void ExpectDefaultPortraitBox(const PdfRectangle& box) {
EXPECT_FLOAT_EQ(0, box.left); EXPECT_FLOAT_EQ(0, box.left);
...@@ -130,7 +130,7 @@ TEST(PdfTransformTest, CalculateMediaBoxAndCropBox) { ...@@ -130,7 +130,7 @@ TEST(PdfTransformTest, CalculateMediaBoxAndCropBox) {
ExpectDefaultLandscapeBox(crop_box); ExpectDefaultLandscapeBox(crop_box);
// Assume crop box is missing. // Assume crop box is missing.
const PdfRectangle expected_box = {0, 0, 42, 420}; constexpr PdfRectangle expected_box = {0, 0, 42, 420};
media_box = expected_box; media_box = expected_box;
InitializeBoxToInvalidValues(&crop_box); InitializeBoxToInvalidValues(&crop_box);
CalculateMediaBoxAndCropBox(false, true, false, &media_box, &crop_box); CalculateMediaBoxAndCropBox(false, true, false, &media_box, &crop_box);
...@@ -188,7 +188,7 @@ TEST(PdfTransformTest, CalculateClipBoxBoundary) { ...@@ -188,7 +188,7 @@ TEST(PdfTransformTest, CalculateClipBoxBoundary) {
} }
TEST(PdfTransformTest, CalculateScaledClipBoxOffset) { TEST(PdfTransformTest, CalculateScaledClipBoxOffset) {
const gfx::Rect rect(kDefaultWidth, kDefaultHeight); constexpr gfx::Rect rect(kDefaultWidth, kDefaultHeight);
PdfRectangle clip_box; PdfRectangle clip_box;
double offset_x; double offset_x;
double offset_y; double offset_y;
...@@ -210,7 +210,7 @@ TEST(PdfTransformTest, CalculateScaledClipBoxOffset) { ...@@ -210,7 +210,7 @@ TEST(PdfTransformTest, CalculateScaledClipBoxOffset) {
TEST(PdfTransformTest, CalculateNonScaledClipBoxOffset) { TEST(PdfTransformTest, CalculateNonScaledClipBoxOffset) {
int page_width = kDefaultWidth; int page_width = kDefaultWidth;
int page_height = kDefaultHeight; int page_height = kDefaultHeight;
const gfx::Rect rect(kDefaultWidth, kDefaultHeight); constexpr gfx::Rect rect(kDefaultWidth, kDefaultHeight);
PdfRectangle clip_box; PdfRectangle clip_box;
double offset_x; double offset_x;
double offset_y; double offset_y;
...@@ -280,12 +280,12 @@ TEST(PdfTransformTest, CalculateNonScaledClipBoxOffset) { ...@@ -280,12 +280,12 @@ TEST(PdfTransformTest, CalculateNonScaledClipBoxOffset) {
TEST(PdfTransformTest, ReversedMediaBox) { TEST(PdfTransformTest, ReversedMediaBox) {
int page_width = kDefaultWidth; int page_width = kDefaultWidth;
int page_height = kDefaultHeight; int page_height = kDefaultHeight;
const gfx::Rect rect(kDefaultWidth, kDefaultHeight); constexpr gfx::Rect rect(kDefaultWidth, kDefaultHeight);
PdfRectangle clip_box; PdfRectangle clip_box;
double offset_x; double offset_x;
double offset_y; double offset_y;
const PdfRectangle expected_media_box_b491160 = {0, -792, 612, 0}; constexpr PdfRectangle expected_media_box_b491160 = {0, -792, 612, 0};
PdfRectangle media_box_b491160 = {0, 0, 612, -792}; PdfRectangle media_box_b491160 = {0, 0, 612, -792};
CalculateMediaBoxAndCropBox(false, true, false, &media_box_b491160, CalculateMediaBoxAndCropBox(false, true, false, &media_box_b491160,
&clip_box); &clip_box);
......
...@@ -76,20 +76,20 @@ static_assert(static_cast<int>(PDFEngine::FormType::kCount) == FORMTYPE_COUNT, ...@@ -76,20 +76,20 @@ static_assert(static_cast<int>(PDFEngine::FormType::kCount) == FORMTYPE_COUNT,
namespace { namespace {
const int32_t kPageShadowTop = 3; constexpr int32_t kPageShadowTop = 3;
const int32_t kPageShadowBottom = 7; constexpr int32_t kPageShadowBottom = 7;
const int32_t kPageShadowLeft = 5; constexpr int32_t kPageShadowLeft = 5;
const int32_t kPageShadowRight = 5; constexpr int32_t kPageShadowRight = 5;
const int32_t kPageSeparatorThickness = 4; constexpr int32_t kPageSeparatorThickness = 4;
const int32_t kHighlightColorR = 153; constexpr int32_t kHighlightColorR = 153;
const int32_t kHighlightColorG = 193; constexpr int32_t kHighlightColorG = 193;
const int32_t kHighlightColorB = 218; constexpr int32_t kHighlightColorB = 218;
const uint32_t kPendingPageColor = 0xFFEEEEEE; constexpr uint32_t kPendingPageColor = 0xFFEEEEEE;
const uint32_t kFormHighlightColor = 0xFFE4DD; constexpr uint32_t kFormHighlightColor = 0xFFE4DD;
const int32_t kFormHighlightAlpha = 100; constexpr int32_t kFormHighlightAlpha = 100;
constexpr int kMaxPasswordTries = 3; constexpr int kMaxPasswordTries = 3;
...@@ -105,12 +105,12 @@ constexpr bool kViewerImplementedPanning = true; ...@@ -105,12 +105,12 @@ constexpr bool kViewerImplementedPanning = true;
// See Table 3.20 in // See Table 3.20 in
// http://www.adobe.com/devnet/acrobat/pdfs/pdf_reference_1-7.pdf // http://www.adobe.com/devnet/acrobat/pdfs/pdf_reference_1-7.pdf
const uint32_t kPDFPermissionPrintLowQualityMask = 1 << 2; constexpr uint32_t kPDFPermissionPrintLowQualityMask = 1 << 2;
const uint32_t kPDFPermissionPrintHighQualityMask = 1 << 11; constexpr uint32_t kPDFPermissionPrintHighQualityMask = 1 << 11;
const uint32_t kPDFPermissionCopyMask = 1 << 4; constexpr uint32_t kPDFPermissionCopyMask = 1 << 4;
const uint32_t kPDFPermissionCopyAccessibleMask = 1 << 9; constexpr uint32_t kPDFPermissionCopyAccessibleMask = 1 << 9;
const int32_t kLoadingTextVerticalOffset = 50; constexpr int32_t kLoadingTextVerticalOffset = 50;
// The maximum amount of time we'll spend doing a paint before we give back // The maximum amount of time we'll spend doing a paint before we give back
// control of the thread. // control of the thread.
...@@ -147,8 +147,8 @@ PP_BrowserFont_Trusted_Weight WeightToBrowserFontTrustedWeight(int weight) { ...@@ -147,8 +147,8 @@ PP_BrowserFont_Trusted_Weight WeightToBrowserFontTrustedWeight(int weight) {
"PP_BrowserFont_Trusted_Weight min"); "PP_BrowserFont_Trusted_Weight min");
static_assert(PP_BROWSERFONT_TRUSTED_WEIGHT_900 == 8, static_assert(PP_BROWSERFONT_TRUSTED_WEIGHT_900 == 8,
"PP_BrowserFont_Trusted_Weight max"); "PP_BrowserFont_Trusted_Weight max");
const int kMinimumWeight = 100; constexpr int kMinimumWeight = 100;
const int kMaximumWeight = 900; constexpr int kMaximumWeight = 900;
int normalized_weight = int normalized_weight =
std::min(std::max(weight, kMinimumWeight), kMaximumWeight); std::min(std::max(weight, kMinimumWeight), kMaximumWeight);
normalized_weight = (normalized_weight / 100) - 1; normalized_weight = (normalized_weight / 100) - 1;
...@@ -447,7 +447,7 @@ void FormatStringWithHyphens(base::string16* text) { ...@@ -447,7 +447,7 @@ void FormatStringWithHyphens(base::string16* text) {
std::vector<HyphenPosition> hyphen_positions; std::vector<HyphenPosition> hyphen_positions;
HyphenPosition current_hyphen_position; HyphenPosition current_hyphen_position;
bool current_hyphen_position_is_valid = false; bool current_hyphen_position_is_valid = false;
const base::char16 kPdfiumHyphenEOL = 0xfffe; constexpr base::char16 kPdfiumHyphenEOL = 0xfffe;
for (size_t i = 0; i < text->size(); ++i) { for (size_t i = 0; i < text->size(); ++i) {
const base::char16& current_char = (*text)[i]; const base::char16& current_char = (*text)[i];
...@@ -471,7 +471,7 @@ void FormatStringWithHyphens(base::string16* text) { ...@@ -471,7 +471,7 @@ void FormatStringWithHyphens(base::string16* text) {
// With all the hyphen positions, do the search and replace. // With all the hyphen positions, do the search and replace.
while (!hyphen_positions.empty()) { while (!hyphen_positions.empty()) {
static const base::char16 kCr[] = {L'\r', L'\0'}; static constexpr base::char16 kCr[] = {L'\r', L'\0'};
const HyphenPosition& position = hyphen_positions.back(); const HyphenPosition& position = hyphen_positions.back();
if (position.next_whitespace_position != 0) { if (position.next_whitespace_position != 0) {
(*text)[position.next_whitespace_position] = L'\n'; (*text)[position.next_whitespace_position] = L'\n';
...@@ -482,16 +482,16 @@ void FormatStringWithHyphens(base::string16* text) { ...@@ -482,16 +482,16 @@ void FormatStringWithHyphens(base::string16* text) {
} }
// Adobe Reader also get rid of trailing spaces right before a CRLF. // Adobe Reader also get rid of trailing spaces right before a CRLF.
static const base::char16 kSpaceCrCn[] = {L' ', L'\r', L'\n', L'\0'}; static constexpr base::char16 kSpaceCrCn[] = {L' ', L'\r', L'\n', L'\0'};
static const base::char16 kCrCn[] = {L'\r', L'\n', L'\0'}; static constexpr base::char16 kCrCn[] = {L'\r', L'\n', L'\0'};
base::ReplaceSubstringsAfterOffset(text, 0, kSpaceCrCn, kCrCn); base::ReplaceSubstringsAfterOffset(text, 0, kSpaceCrCn, kCrCn);
} }
// Replace CR/LF with just LF on POSIX. // Replace CR/LF with just LF on POSIX.
void FormatStringForOS(base::string16* text) { void FormatStringForOS(base::string16* text) {
#if defined(OS_POSIX) #if defined(OS_POSIX)
static const base::char16 kCr[] = {L'\r', L'\0'}; static constexpr base::char16 kCr[] = {L'\r', L'\0'};
static const base::char16 kBlank[] = {L'\0'}; static constexpr base::char16 kBlank[] = {L'\0'};
base::ReplaceChars(*text, kCr, kBlank, text); base::ReplaceChars(*text, kCr, kBlank, text);
#elif defined(OS_WIN) #elif defined(OS_WIN)
// Do nothing // Do nothing
...@@ -2347,7 +2347,7 @@ pp::VarDictionary PDFiumEngine::TraverseBookmarks(FPDF_BOOKMARK bookmark, ...@@ -2347,7 +2347,7 @@ pp::VarDictionary PDFiumEngine::TraverseBookmarks(FPDF_BOOKMARK bookmark,
pp::VarArray children; pp::VarArray children;
// Don't trust PDFium to handle circular bookmarks. // Don't trust PDFium to handle circular bookmarks.
const unsigned int kMaxDepth = 128; constexpr unsigned int kMaxDepth = 128;
if (depth < kMaxDepth) { if (depth < kMaxDepth) {
int child_index = 0; int child_index = 0;
std::set<FPDF_BOOKMARK> seen_bookmarks; std::set<FPDF_BOOKMARK> seen_bookmarks;
...@@ -3435,7 +3435,7 @@ void PDFiumEngine::DrawPageShadow(const pp::Rect& page_rc, ...@@ -3435,7 +3435,7 @@ void PDFiumEngine::DrawPageShadow(const pp::Rect& page_rc,
clip_rect.Offset(page_offset_); clip_rect.Offset(page_offset_);
// Page drop shadow parameters. // Page drop shadow parameters.
const double factor = 0.5; constexpr double factor = 0.5;
uint32_t depth = uint32_t depth =
std::max(std::max(page_rect.x() - shadow_rect.x(), std::max(std::max(page_rect.x() - shadow_rect.x(),
page_rect.y() - shadow_rect.y()), page_rect.y() - shadow_rect.y()),
......
...@@ -432,7 +432,7 @@ ScopedFPDFDocument PDFiumPrint::CreateSinglePageRasterPdf( ...@@ -432,7 +432,7 @@ ScopedFPDFDocument PDFiumPrint::CreateSinglePageRasterPdf(
// Use quality = 40 as this does not significantly degrade the printed // Use quality = 40 as this does not significantly degrade the printed
// document relative to a normal bitmap and provides better compression than // document relative to a normal bitmap and provides better compression than
// a higher quality setting. // a higher quality setting.
const int kQuality = 40; constexpr int kQuality = 40;
SkImageInfo info = SkImageInfo::Make( SkImageInfo info = SkImageInfo::Make(
FPDFBitmap_GetWidth(bitmap.get()), FPDFBitmap_GetHeight(bitmap.get()), FPDFBitmap_GetWidth(bitmap.get()), FPDFBitmap_GetHeight(bitmap.get()),
kBGRA_8888_SkColorType, kOpaque_SkAlphaType); kBGRA_8888_SkColorType, kOpaque_SkAlphaType);
......
...@@ -76,15 +76,15 @@ TEST_F(PDFiumPrintTest, Basic) { ...@@ -76,15 +76,15 @@ TEST_F(PDFiumPrintTest, Basic) {
PDFiumPrint print(&engine); PDFiumPrint print(&engine);
const PP_PrintSettings_Dev print_settings = {kUSLetterRect, constexpr PP_PrintSettings_Dev print_settings = {kUSLetterRect,
kUSLetterRect, kUSLetterRect,
kUSLetterSize, kUSLetterSize,
72, 72,
PP_PRINTORIENTATION_NORMAL, PP_PRINTORIENTATION_NORMAL,
PP_PRINTSCALINGOPTION_NONE, PP_PRINTSCALINGOPTION_NONE,
PP_FALSE, PP_FALSE,
PP_PRINTOUTPUTFORMAT_PDF}; PP_PRINTOUTPUTFORMAT_PDF};
const PP_PdfPrintSettings_Dev pdf_print_settings = {1, 100}; constexpr PP_PdfPrintSettings_Dev pdf_print_settings = {1, 100};
{ {
// Print 2 pages. // Print 2 pages.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment