0

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
This commit is contained in:
maruel@chromium.org
2009-09-14 13:57:10 +00:00
parent 12b38f6e08
commit 60741b476f
8 changed files with 72 additions and 67 deletions

@ -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)

@ -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;
}

@ -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.

@ -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}");

@ -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());

@ -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

@ -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',
],
}],
],
},

@ -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();
}