diff options
author | maruel@chromium.org <maruel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-14 13:57:10 +0000 |
---|---|---|
committer | maruel@chromium.org <maruel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-14 13:57:10 +0000 |
commit | 60741b476f12d0a9a7a0adac446d1af75d1208af (patch) | |
tree | 97cf98a024b22840a7a0f1b3a0520cce8d919949 /printing | |
parent | 12b38f6e0866c6a88f0724395ed8a60a8eaf1bd3 (diff) | |
download | chromium_src-60741b476f12d0a9a7a0adac446d1af75d1208af.zip chromium_src-60741b476f12d0a9a7a0adac446d1af75d1208af.tar.gz chromium_src-60741b476f12d0a9a7a0adac446d1af75d1208af.tar.bz2 |
Fix printing project on linux.
Enable compilation of every files and fix tests.
TEST=unit tests
BUG=9847
Review URL: http://codereview.chromium.org/193086
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@26103 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'printing')
-rw-r--r-- | printing/native_metafile.h | 9 | ||||
-rw-r--r-- | printing/page_overlays.cc | 9 | ||||
-rw-r--r-- | printing/page_overlays.h | 5 | ||||
-rw-r--r-- | printing/page_overlays_unittest.cc | 34 | ||||
-rw-r--r-- | printing/pdf_ps_metafile_linux_unittest.cc | 4 | ||||
-rw-r--r-- | printing/printed_document.cc | 32 | ||||
-rw-r--r-- | printing/printing.gyp | 42 | ||||
-rw-r--r-- | printing/run_all_unittests.cc | 4 |
8 files changed, 72 insertions, 67 deletions
diff --git a/printing/native_metafile.h b/printing/native_metafile.h index be79d5b..e30a43e 100644 --- a/printing/native_metafile.h +++ b/printing/native_metafile.h @@ -26,9 +26,14 @@ typedef Emf NativeMetafile; #elif defined(OS_MACOSX) -// TODO(port): Printing using PDF? +// TODO(port): Printing using CG/PDF? // The mock class is here so we can compile. -class NativeMetafile {}; +class NativeMetafile { + public: + int GetDataSize() const { return 0; } + private: + DISALLOW_COPY_AND_ASSIGN(NativeMetafile); +}; #elif defined(OS_LINUX) diff --git a/printing/page_overlays.cc b/printing/page_overlays.cc index e590490..446e9dd 100644 --- a/printing/page_overlays.cc +++ b/printing/page_overlays.cc @@ -84,8 +84,9 @@ const std::wstring& PageOverlays::GetOverlay(HorizontalPosition x, return EmptyWString(); } -void PageOverlays::SetOverlay(HorizontalPosition x, VerticalPosition y, - std::wstring& input) { +void PageOverlays::SetOverlay(HorizontalPosition x, + VerticalPosition y, + const std::wstring& input) { switch (x) { case LEFT: switch (y) { @@ -137,9 +138,6 @@ std::wstring PageOverlays::ReplaceVariables(const std::wstring& input, const PrintedDocument& document, const PrintedPage& page) { std::wstring output(input); -// Prevent references to document.page_count() on Linux until -// printed_document.cc is included in printing.gyp. -#if !defined(OS_LINUX) for (size_t offset = output.find(L'{', 0); offset != std::wstring::npos; offset = output.find(L'{', offset)) { @@ -203,7 +201,6 @@ std::wstring PageOverlays::ReplaceVariables(const std::wstring& input, ++offset; } } -#endif // !defined(OS_LINUX) return output; } diff --git a/printing/page_overlays.h b/printing/page_overlays.h index f30aa26..0ffc1ba 100644 --- a/printing/page_overlays.h +++ b/printing/page_overlays.h @@ -40,8 +40,9 @@ class PageOverlays { VerticalPosition y) const; // Sets the string of an overlay according to its x,y position. - void SetOverlay(HorizontalPosition x, VerticalPosition y, - std::wstring& input); + void SetOverlay(HorizontalPosition x, + VerticalPosition y, + const std::wstring& input); // Replaces the variables in |input| with their actual values according to the // properties of the current printed document and the current printed page. diff --git a/printing/page_overlays_unittest.cc b/printing/page_overlays_unittest.cc index ccdc15a..bad78de 100644 --- a/printing/page_overlays_unittest.cc +++ b/printing/page_overlays_unittest.cc @@ -13,24 +13,19 @@ namespace { -class PageOverlaysTest : public testing::Test { - private: - MessageLoop message_loop_; -}; - struct Keys { const wchar_t* key; const wchar_t* expected; }; const Keys kOverlayKeys[] = { - printing::PageOverlays::kTitle, L"Foobar Document", - printing::PageOverlays::kTime, L"", - printing::PageOverlays::kDate, L"", - printing::PageOverlays::kPage, L"1", - printing::PageOverlays::kPageCount, L"2", - printing::PageOverlays::kPageOnTotal, L"1/2", - printing::PageOverlays::kUrl, L"http://www.perdu.com/", + { printing::PageOverlays::kTitle, L"Foobar Document" }, + { printing::PageOverlays::kTime, L"" }, + { printing::PageOverlays::kDate, L"" }, + { printing::PageOverlays::kPage, L"1" }, + { printing::PageOverlays::kPageCount, L"2" }, + { printing::PageOverlays::kPageOnTotal, L"1/2" }, + { printing::PageOverlays::kUrl, L"http://www.perdu.com/" }, }; class PagesSource : public printing::PrintedPagesSource { @@ -40,12 +35,16 @@ class PagesSource : public printing::PrintedPagesSource { } virtual GURL RenderSourceUrl() { - return GURL(L"http://www.perdu.com"); + return GURL("http://www.perdu.com"); } }; } // namespace +class PageOverlaysTest : public testing::Test { + private: + MessageLoop message_loop_; +}; TEST_F(PageOverlaysTest, StringConversion) { printing::PageOverlays overlays; @@ -63,21 +62,22 @@ TEST_F(PageOverlaysTest, StringConversion) { std::wstring input; std::wstring out; - for (int i = 0; i < arraysize(kOverlayKeys); ++i) { + for (size_t i = 0; i < arraysize(kOverlayKeys); ++i) { input = StringPrintf(L"foo%lsbar", kOverlayKeys[i].key); out = printing::PageOverlays::ReplaceVariables(input, *doc.get(), *page.get()); EXPECT_FALSE(out.empty()); if (wcslen(kOverlayKeys[i].expected) == 0) continue; - EXPECT_EQ(StringPrintf(L"foo%lsbar", kOverlayKeys[i].expected), out) << - kOverlayKeys[i].key; + std::wstring expected = StringPrintf(L"foo%lsbar", + kOverlayKeys[i].expected); + EXPECT_EQ(expected, out) << kOverlayKeys[i].key; } // Check if SetOverlay really sets the page overlay. overlays.SetOverlay(printing::PageOverlays::LEFT, printing::PageOverlays::TOP, - UTF16ToWide(L"Page {page}")); + L"Page {page}"); input = overlays.GetOverlay(printing::PageOverlays::LEFT, printing::PageOverlays::TOP); EXPECT_EQ(input, L"Page {page}"); diff --git a/printing/pdf_ps_metafile_linux_unittest.cc b/printing/pdf_ps_metafile_linux_unittest.cc index 700d49c..7339559 100644 --- a/printing/pdf_ps_metafile_linux_unittest.cc +++ b/printing/pdf_ps_metafile_linux_unittest.cc @@ -12,7 +12,7 @@ typedef struct _cairo cairo_t; -TEST(PdfTest, DISABLED_Basic) { +TEST(PdfTest, ThreePages) { // Tests in-renderer constructor. printing::PdfPsMetafile pdf(printing::PdfPsMetafile::PDF); EXPECT_TRUE(pdf.Init()); @@ -56,7 +56,7 @@ TEST(PdfTest, DISABLED_Basic) { EXPECT_TRUE(pdf.SaveTo(FilePath("/dev/null"))); } -TEST(PsTest, DISABLED_Basic2) { +TEST(PsTest, TwoPages) { // Tests in-renderer constructor. printing::PdfPsMetafile ps(printing::PdfPsMetafile::PS); EXPECT_TRUE(ps.Init()); diff --git a/printing/printed_document.cc b/printing/printed_document.cc index b1d2332..918c99e 100644 --- a/printing/printed_document.cc +++ b/printing/printed_document.cc @@ -8,12 +8,12 @@ #include "app/gfx/font.h" #include "app/gfx/text_elider.h" -#include "app/win_util.h" #include "base/file_util.h" #include "base/message_loop.h" #include "base/singleton.h" #include "base/string_util.h" #include "base/time.h" +#include "base/time_format.h" #include "printing/page_number.h" #include "printing/page_overlays.h" #include "printing/printed_pages_source.h" @@ -21,6 +21,10 @@ #include "printing/units.h" #include "skia/ext/platform_device.h" +#if defined(OS_WIN) +#include "app/win_util.h" +#endif + using base::Time; namespace { @@ -36,6 +40,7 @@ struct PrintDebugDumpPath { Singleton<PrintDebugDumpPath> g_debug_dump_info; +#if defined(OS_WIN) void SimpleModifyWorldTransform(HDC context, int offset_x, int offset_y, @@ -51,6 +56,7 @@ void SimpleModifyWorldTransform(HDC context, void DrawRect(HDC context, gfx::Rect rect) { Rectangle(context, rect.x(), rect.y(), rect.right(), rect.bottom()); } +#endif // OS_WIN } // namespace @@ -118,6 +124,7 @@ void PrintedDocument::RenderPrintedPage(const PrintedPage& page, } #endif +#if defined(OS_WIN) const printing::PageSetup& page_setup( immutable_.settings_.page_setup_pixels()); @@ -206,6 +213,9 @@ void PrintedDocument::RenderPrintedPage(const PrintedPage& page, font); int res = RestoreDC(context, saved_state); DCHECK_NE(res, 0); +#else // OS_WIN + NOTIMPLEMENTED(); +#endif // OS_WIN } bool PrintedDocument::RenderPrintedPageNumber(int page_number, HDC context) { @@ -238,7 +248,7 @@ void PrintedDocument::DisconnectSource() { } size_t PrintedDocument::MemoryUsage() const { - std::vector<scoped_refptr<PrintedPage>> pages_copy; + std::vector< scoped_refptr<PrintedPage> > pages_copy; { AutoLock lock(lock_); pages_copy.reserve(mutable_.pages_.size()); @@ -339,6 +349,7 @@ void PrintedDocument::PrintHeaderFooter(HDC context, } } +#if defined(OS_WIN) // Save the state (again) for the clipping region. int saved_state = SaveDC(context); DCHECK_NE(saved_state, 0); @@ -352,6 +363,9 @@ void PrintedDocument::PrintHeaderFooter(HDC context, static_cast<int>(output.size())); int res = RestoreDC(context, saved_state); DCHECK_NE(res, 0); +#else // OS_WIN + NOTIMPLEMENTED(); +#endif // OS_WIN } void PrintedDocument::DebugDump(const PrintedPage& page) { @@ -370,7 +384,11 @@ void PrintedDocument::DebugDump(const PrintedPage& page) { file_util::ReplaceIllegalCharacters(&filename, '_'); std::wstring path(g_debug_dump_info->debug_dump_path); file_util::AppendToPath(&path, filename); +#if defined(OS_WIN) page.native_metafile()->SaveTo(path); +#else // OS_WIN + NOTIMPLEMENTED(); +#endif // OS_WIN } void PrintedDocument::set_debug_dump_path(const std::wstring& debug_dump_path) { @@ -398,17 +416,17 @@ PrintedDocument::Immutable::Immutable(const PrintSettings& settings, url_(source->RenderSourceUrl()), cookie_(cookie) { // Setup the document's date. -#ifdef WIN32 +#if defined(OS_WIN) // On Windows, use the native time formatting for printing. SYSTEMTIME systemtime; GetLocalTime(&systemtime); date_ = win_util::FormatSystemDate(systemtime, std::wstring()); time_ = win_util::FormatSystemTime(systemtime, std::wstring()); -#else +#else // OS_WIN Time now = Time::Now(); - date_ = TimeFormat::ShortDateNumeric(now); - time_ = TimeFormat::TimeOfDay(now); -#endif // WIN32 + date_ = base::TimeFormatShortDateNumeric(now); + time_ = base::TimeFormatTimeOfDay(now); +#endif // OS_WIN } } // namespace printing diff --git a/printing/printing.gyp b/printing/printing.gyp index c10b92b..c6340ec 100644 --- a/printing/printing.gyp +++ b/printing/printing.gyp @@ -51,7 +51,7 @@ 'printed_pages_source.h', 'printing_context.h', 'printing_context_linux.cc', - 'printing_context_mac.cc', + 'printing_context_mac.cc', 'printing_context_win.cc', 'units.cc', 'units.h', @@ -64,15 +64,9 @@ 'conditions': [ ['OS!="linux"', {'sources/': [['exclude', '_linux\\.cc$']]}], ['OS!="mac"', {'sources/': [['exclude', '_mac\\.(cc|mm?)$']]}], - ['OS!="win"', { - 'sources/': [ - ['exclude', '_win\\.cc$'], - ['exclude', - 'printed_document.cc', - ] - ] - }, { # else: OS=="win" - 'sources/': [['exclude', '_posix\\.cc$']] + ['OS!="win"', {'sources/': [['exclude', '_win\\.cc$']] + }, { # else: OS=="win" + 'sources/': [['exclude', '_posix\\.cc$']] }], ], }, @@ -100,26 +94,16 @@ 'conditions': [ ['OS!="linux"', {'sources/': [['exclude', '_linux_unittest\\.cc$']]}], ['OS!="mac"', {'sources/': [['exclude', '_mac_unittest\\.(cc|mm?)$']]}], - ['OS!="win"', { - 'sources/': [ - ['exclude', '_win_unittest\\.cc$'], - - # Most of the printing functionailty is Windows only for now. - ['exclude', '.*'], - ['include', 'page_range_unittest.cc'], - ['include', 'page_setup_unittest.cc'], - ['include', 'units_unittest.cc'], - ] - }, { # else: OS=="win" - 'sources/': [['exclude', '_posix_unittest\\.cc$']] - }], + ['OS!="win"', {'sources/': [['exclude', '_win_unittest\\.cc$']] + }, { # else: OS=="win" + 'sources/': [['exclude', '_posix_unittest\\.cc$']] + } + ], ['OS=="linux"', { - 'dependencies': [ - '../base/base.gyp:base_gfx', - ], - 'sources/': [ - ['include', 'pdf_ps_metafile_linux_unittest.cc'], - ] + 'dependencies': [ + '../build/linux/system.gyp:fontconfig', + '../build/linux/system.gyp:gtk', + ], }], ], }, diff --git a/printing/run_all_unittests.cc b/printing/run_all_unittests.cc index 63b8020..d9f6b58 100644 --- a/printing/run_all_unittests.cc +++ b/printing/run_all_unittests.cc @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "app/test_suite.h" +#include "base/test_suite.h" int main(int argc, char** argv) { - return AppTestSuite(argc, argv).Run(); + return TestSuite(argc, argv).Run(); } |