Return std::u16string from chrome_pdf::FormatPageSize()
When the function was first introduced, std::u16string was not able to be used. Meanwhile, add a TODO about initializing the resource bundle. Bug: 911896 Change-Id: Ie83ebb396ef13228ffb699c3e760a624e2b90b5f Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2733730 Auto-Submit: Daniel Hosseinian <dhoss@chromium.org> Reviewed-by: K. Moon <kmoon@chromium.org> Commit-Queue: Daniel Hosseinian <dhoss@chromium.org> Cr-Commit-Position: refs/heads/master@{#859655}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
1fdb369eb9
commit
71d0bec246
@ -9,7 +9,6 @@
|
|||||||
#include "base/i18n/number_formatting.h"
|
#include "base/i18n/number_formatting.h"
|
||||||
#include "base/i18n/rtl.h"
|
#include "base/i18n/rtl.h"
|
||||||
#include "base/optional.h"
|
#include "base/optional.h"
|
||||||
#include "base/strings/string16.h"
|
|
||||||
#include "components/strings/grit/components_strings.h"
|
#include "components/strings/grit/components_strings.h"
|
||||||
#include "printing/units.h"
|
#include "printing/units.h"
|
||||||
#include "third_party/icu/source/i18n/unicode/ulocdata.h"
|
#include "third_party/icu/source/i18n/unicode/ulocdata.h"
|
||||||
@ -38,20 +37,20 @@ constexpr float ConvertPointsToMillimeters(int length_points) {
|
|||||||
|
|
||||||
// Formats a length given in points. The formatted length is in inches and
|
// Formats a length given in points. The formatted length is in inches and
|
||||||
// contains two fractional digits.
|
// contains two fractional digits.
|
||||||
base::string16 FormatLengthInInches(int length_points) {
|
std::u16string FormatLengthInInches(int length_points) {
|
||||||
return base::FormatDouble(ConvertPointsToInches(length_points),
|
return base::FormatDouble(ConvertPointsToInches(length_points),
|
||||||
/*fractional_digits=*/2);
|
/*fractional_digits=*/2);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Formats a length given in points. The formatted length is in millimeters and
|
// Formats a length given in points. The formatted length is in millimeters and
|
||||||
// contains no fractional digits.
|
// contains no fractional digits.
|
||||||
base::string16 FormatLengthInMillimeters(int length_points) {
|
std::u16string FormatLengthInMillimeters(int length_points) {
|
||||||
return base::FormatDouble(ConvertPointsToMillimeters(length_points),
|
return base::FormatDouble(ConvertPointsToMillimeters(length_points),
|
||||||
/*fractional_digits=*/0);
|
/*fractional_digits=*/0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns the localized string for the orientation.
|
// Returns the localized string for the orientation.
|
||||||
base::string16 GetOrientation(const gfx::Size& size) {
|
std::u16string GetOrientation(const gfx::Size& size) {
|
||||||
// TODO(crbug.com/1184345): Add a string for square sizes such that they are
|
// TODO(crbug.com/1184345): Add a string for square sizes such that they are
|
||||||
// not displayed as "portrait".
|
// not displayed as "portrait".
|
||||||
return l10n_util::GetStringUTF16(
|
return l10n_util::GetStringUTF16(
|
||||||
@ -70,7 +69,7 @@ bool ShowInches() {
|
|||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
base::string16 FormatPageSize(const base::Optional<gfx::Size>& size_points) {
|
std::u16string FormatPageSize(const base::Optional<gfx::Size>& size_points) {
|
||||||
if (!size_points.has_value())
|
if (!size_points.has_value())
|
||||||
return l10n_util::GetStringUTF16(IDS_PDF_PROPERTIES_PAGE_SIZE_VARIABLE);
|
return l10n_util::GetStringUTF16(IDS_PDF_PROPERTIES_PAGE_SIZE_VARIABLE);
|
||||||
|
|
||||||
|
@ -5,8 +5,9 @@
|
|||||||
#ifndef PDF_UI_FORMAT_PAGE_SIZE_H_
|
#ifndef PDF_UI_FORMAT_PAGE_SIZE_H_
|
||||||
#define PDF_UI_FORMAT_PAGE_SIZE_H_
|
#define PDF_UI_FORMAT_PAGE_SIZE_H_
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
#include "base/optional.h"
|
#include "base/optional.h"
|
||||||
#include "base/strings/string16.h"
|
|
||||||
|
|
||||||
namespace gfx {
|
namespace gfx {
|
||||||
class Size;
|
class Size;
|
||||||
@ -22,7 +23,7 @@ namespace chrome_pdf {
|
|||||||
// -> 11.00 x 8.50 in (landscape)
|
// -> 11.00 x 8.50 in (landscape)
|
||||||
//
|
//
|
||||||
// Returns the string "Varies" if `size_points` is `base::nullopt`.
|
// Returns the string "Varies" if `size_points` is `base::nullopt`.
|
||||||
base::string16 FormatPageSize(const base::Optional<gfx::Size>& size_points);
|
std::u16string FormatPageSize(const base::Optional<gfx::Size>& size_points);
|
||||||
|
|
||||||
} // namespace chrome_pdf
|
} // namespace chrome_pdf
|
||||||
|
|
||||||
|
@ -9,7 +9,6 @@
|
|||||||
#include "base/i18n/number_formatting.h"
|
#include "base/i18n/number_formatting.h"
|
||||||
#include "base/i18n/rtl.h"
|
#include "base/i18n/rtl.h"
|
||||||
#include "base/optional.h"
|
#include "base/optional.h"
|
||||||
#include "base/strings/utf_string_conversions.h"
|
|
||||||
#include "components/strings/grit/components_strings.h"
|
#include "components/strings/grit/components_strings.h"
|
||||||
#include "testing/gmock/include/gmock/gmock.h"
|
#include "testing/gmock/include/gmock/gmock.h"
|
||||||
#include "testing/gtest/include/gtest/gtest.h"
|
#include "testing/gtest/include/gtest/gtest.h"
|
||||||
@ -24,35 +23,35 @@ namespace chrome_pdf {
|
|||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
bool GetPageSizeString(int message_id, base::string16* value) {
|
bool GetPageSizeString(int message_id, std::u16string* value) {
|
||||||
std::string utf8;
|
|
||||||
switch (message_id) {
|
switch (message_id) {
|
||||||
case IDS_PDF_PROPERTIES_PAGE_SIZE_VALUE_INCH:
|
case IDS_PDF_PROPERTIES_PAGE_SIZE_VALUE_INCH:
|
||||||
utf8 = "$1 × $2 in ($3)";
|
*value = u"$1 × $2 in ($3)";
|
||||||
break;
|
break;
|
||||||
case IDS_PDF_PROPERTIES_PAGE_SIZE_VALUE_MM:
|
case IDS_PDF_PROPERTIES_PAGE_SIZE_VALUE_MM:
|
||||||
utf8 = "$1 × $2 mm ($3)";
|
*value = u"$1 × $2 mm ($3)";
|
||||||
break;
|
break;
|
||||||
case IDS_PDF_PROPERTIES_PAGE_SIZE_PORTRAIT:
|
case IDS_PDF_PROPERTIES_PAGE_SIZE_PORTRAIT:
|
||||||
utf8 = "portrait";
|
*value = u"portrait";
|
||||||
break;
|
break;
|
||||||
case IDS_PDF_PROPERTIES_PAGE_SIZE_LANDSCAPE:
|
case IDS_PDF_PROPERTIES_PAGE_SIZE_LANDSCAPE:
|
||||||
utf8 = "landscape";
|
*value = u"landscape";
|
||||||
break;
|
break;
|
||||||
case IDS_PDF_PROPERTIES_PAGE_SIZE_VARIABLE:
|
case IDS_PDF_PROPERTIES_PAGE_SIZE_VARIABLE:
|
||||||
utf8 = "Varies";
|
*value = u"Varies";
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
*value = base::UTF8ToUTF16(utf8);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
class FormatPageSizeTest : public testing::Test {
|
class FormatPageSizeTest : public testing::Test {
|
||||||
protected:
|
protected:
|
||||||
void SetUp() override {
|
void SetUp() override {
|
||||||
|
// TODO(crbug.com/1184524): Consider initializing a resource bundle instance
|
||||||
|
// for all tests in `pdf_unittests`.
|
||||||
// `pdf_unittests` does not have a resource bundle that needs to be restored
|
// `pdf_unittests` does not have a resource bundle that needs to be restored
|
||||||
// at the end of the test.
|
// at the end of the test.
|
||||||
ASSERT_FALSE(ui::ResourceBundle::HasSharedInstance());
|
ASSERT_FALSE(ui::ResourceBundle::HasSharedInstance());
|
||||||
@ -85,14 +84,10 @@ class FormatPageSizeTest : public testing::Test {
|
|||||||
NiceMock<ui::MockResourceBundleDelegate> mock_resource_delegate_;
|
NiceMock<ui::MockResourceBundleDelegate> mock_resource_delegate_;
|
||||||
};
|
};
|
||||||
|
|
||||||
std::string FormatPageSizeUtf8(const base::Optional<gfx::Size>& size_points) {
|
|
||||||
return base::UTF16ToUTF8(FormatPageSize(size_points));
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
TEST_F(FormatPageSizeTest, NoUniformSize) {
|
TEST_F(FormatPageSizeTest, NoUniformSize) {
|
||||||
EXPECT_EQ(FormatPageSizeUtf8(base::nullopt), "Varies");
|
EXPECT_EQ(FormatPageSize(base::nullopt), u"Varies");
|
||||||
}
|
}
|
||||||
|
|
||||||
class FormatPageSizeMillimetersTest : public FormatPageSizeTest {
|
class FormatPageSizeMillimetersTest : public FormatPageSizeTest {
|
||||||
@ -101,24 +96,24 @@ class FormatPageSizeMillimetersTest : public FormatPageSizeTest {
|
|||||||
};
|
};
|
||||||
|
|
||||||
TEST_F(FormatPageSizeMillimetersTest, EmptySize) {
|
TEST_F(FormatPageSizeMillimetersTest, EmptySize) {
|
||||||
EXPECT_EQ(FormatPageSizeUtf8(gfx::Size()), "0 × 0 mm (portrait)");
|
EXPECT_EQ(FormatPageSize(gfx::Size()), u"0 × 0 mm (portrait)");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(FormatPageSizeMillimetersTest, Portrait) {
|
TEST_F(FormatPageSizeMillimetersTest, Portrait) {
|
||||||
EXPECT_EQ(FormatPageSizeUtf8(gfx::Size(100, 200)), "35 × 71 mm (portrait)");
|
EXPECT_EQ(FormatPageSize(gfx::Size(100, 200)), u"35 × 71 mm (portrait)");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(FormatPageSizeMillimetersTest, Landscape) {
|
TEST_F(FormatPageSizeMillimetersTest, Landscape) {
|
||||||
EXPECT_EQ(FormatPageSizeUtf8(gfx::Size(200, 100)), "71 × 35 mm (landscape)");
|
EXPECT_EQ(FormatPageSize(gfx::Size(200, 100)), u"71 × 35 mm (landscape)");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(FormatPageSizeMillimetersTest, Square) {
|
TEST_F(FormatPageSizeMillimetersTest, Square) {
|
||||||
EXPECT_EQ(FormatPageSizeUtf8(gfx::Size(100, 100)), "35 × 35 mm (portrait)");
|
EXPECT_EQ(FormatPageSize(gfx::Size(100, 100)), u"35 × 35 mm (portrait)");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(FormatPageSizeMillimetersTest, Large) {
|
TEST_F(FormatPageSizeMillimetersTest, Large) {
|
||||||
EXPECT_EQ(FormatPageSizeUtf8(gfx::Size(72000, 72000)),
|
EXPECT_EQ(FormatPageSize(gfx::Size(72000, 72000)),
|
||||||
"25,400 × 25,400 mm (portrait)");
|
u"25,400 × 25,400 mm (portrait)");
|
||||||
}
|
}
|
||||||
|
|
||||||
class FormatPageSizeMillimetersPeriodSeparatorTest : public FormatPageSizeTest {
|
class FormatPageSizeMillimetersPeriodSeparatorTest : public FormatPageSizeTest {
|
||||||
@ -127,8 +122,8 @@ class FormatPageSizeMillimetersPeriodSeparatorTest : public FormatPageSizeTest {
|
|||||||
};
|
};
|
||||||
|
|
||||||
TEST_F(FormatPageSizeMillimetersPeriodSeparatorTest, Large) {
|
TEST_F(FormatPageSizeMillimetersPeriodSeparatorTest, Large) {
|
||||||
EXPECT_EQ(FormatPageSizeUtf8(gfx::Size(72000, 72000)),
|
EXPECT_EQ(FormatPageSize(gfx::Size(72000, 72000)),
|
||||||
"25.400 × 25.400 mm (portrait)");
|
u"25.400 × 25.400 mm (portrait)");
|
||||||
}
|
}
|
||||||
|
|
||||||
class FormatPageSizeInchesTest : public FormatPageSizeTest {
|
class FormatPageSizeInchesTest : public FormatPageSizeTest {
|
||||||
@ -137,27 +132,24 @@ class FormatPageSizeInchesTest : public FormatPageSizeTest {
|
|||||||
};
|
};
|
||||||
|
|
||||||
TEST_F(FormatPageSizeInchesTest, EmptySize) {
|
TEST_F(FormatPageSizeInchesTest, EmptySize) {
|
||||||
EXPECT_EQ(FormatPageSizeUtf8(gfx::Size()), "0.00 × 0.00 in (portrait)");
|
EXPECT_EQ(FormatPageSize(gfx::Size()), u"0.00 × 0.00 in (portrait)");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(FormatPageSizeInchesTest, Portrait) {
|
TEST_F(FormatPageSizeInchesTest, Portrait) {
|
||||||
EXPECT_EQ(FormatPageSizeUtf8(gfx::Size(100, 200)),
|
EXPECT_EQ(FormatPageSize(gfx::Size(100, 200)), u"1.39 × 2.78 in (portrait)");
|
||||||
"1.39 × 2.78 in (portrait)");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(FormatPageSizeInchesTest, Landscape) {
|
TEST_F(FormatPageSizeInchesTest, Landscape) {
|
||||||
EXPECT_EQ(FormatPageSizeUtf8(gfx::Size(200, 100)),
|
EXPECT_EQ(FormatPageSize(gfx::Size(200, 100)), u"2.78 × 1.39 in (landscape)");
|
||||||
"2.78 × 1.39 in (landscape)");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(FormatPageSizeInchesTest, Square) {
|
TEST_F(FormatPageSizeInchesTest, Square) {
|
||||||
EXPECT_EQ(FormatPageSizeUtf8(gfx::Size(100, 100)),
|
EXPECT_EQ(FormatPageSize(gfx::Size(100, 100)), u"1.39 × 1.39 in (portrait)");
|
||||||
"1.39 × 1.39 in (portrait)");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(FormatPageSizeInchesTest, Large) {
|
TEST_F(FormatPageSizeInchesTest, Large) {
|
||||||
EXPECT_EQ(FormatPageSizeUtf8(gfx::Size(72000, 72000)),
|
EXPECT_EQ(FormatPageSize(gfx::Size(72000, 72000)),
|
||||||
"1,000.00 × 1,000.00 in (portrait)");
|
u"1,000.00 × 1,000.00 in (portrait)");
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace chrome_pdf
|
} // namespace chrome_pdf
|
||||||
|
Reference in New Issue
Block a user