diff options
author | vitalybuka@chromium.org <vitalybuka@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-09-20 05:58:43 +0000 |
---|---|---|
committer | vitalybuka@chromium.org <vitalybuka@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-09-20 05:58:43 +0000 |
commit | 09083ebe22a6d21484b7e0e5d386642e741bfd89 (patch) | |
tree | 26077799e9b996ac5311fe1e25783bb6b593b657 /printing | |
parent | 23150a133bc7db48ee40fe85f7af46c4ce94ca5f (diff) | |
download | chromium_src-09083ebe22a6d21484b7e0e5d386642e741bfd89.zip chromium_src-09083ebe22a6d21484b7e0e5d386642e741bfd89.tar.gz chromium_src-09083ebe22a6d21484b7e0e5d386642e741bfd89.tar.bz2 |
Simplify document title for Windows printing.
Some drivers can't handle long titles or control characters.
BUG=65469
Review URL: https://chromiumcodereview.appspot.com/10941025
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@157715 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'printing')
-rw-r--r-- | printing/DEPS | 1 | ||||
-rw-r--r-- | printing/backend/print_backend.cc | 22 | ||||
-rw-r--r-- | printing/backend/print_backend.h | 4 | ||||
-rw-r--r-- | printing/backend/print_backend_unittest.cc | 25 | ||||
-rw-r--r-- | printing/printing.gyp | 1 | ||||
-rw-r--r-- | printing/printing_context_win.cc | 2 |
6 files changed, 55 insertions, 0 deletions
diff --git a/printing/DEPS b/printing/DEPS index bd54ac8..fa7e4a7 100644 --- a/printing/DEPS +++ b/printing/DEPS @@ -1,5 +1,6 @@ include_rules = [ "+skia/ext", + "+third_party/icu", "+third_party/skia", "+ui/base/text", "+ui/gfx", diff --git a/printing/backend/print_backend.cc b/printing/backend/print_backend.cc index b993bfc..71f917d 100644 --- a/printing/backend/print_backend.cc +++ b/printing/backend/print_backend.cc @@ -4,6 +4,18 @@ #include "printing/backend/print_backend.h" +#include <algorithm> + +#include "third_party/icu/public/common/unicode/uchar.h" +#include "ui/base/text/text_elider.h" + +namespace { + +const wchar_t kDefaultDocumentTitle[] = L"Untitled Document"; +const int kMaxDocumentTitleLength = 25; + +} // namespace + namespace printing { PrinterBasicInfo::PrinterBasicInfo() @@ -26,4 +38,14 @@ PrinterCapsAndDefaults::~PrinterCapsAndDefaults() {} PrintBackend::~PrintBackend() {} +string16 PrintBackend::SimplifyDocumentTitle(const string16& title) { + string16 no_controls(title); + no_controls.erase( + std::remove_if(no_controls.begin(), no_controls.end(), &u_iscntrl), + no_controls.end()); + string16 result; + ui::ElideString(no_controls, kMaxDocumentTitleLength, &result); + return result; +} + } // namespace printing diff --git a/printing/backend/print_backend.h b/printing/backend/print_backend.h index 3cbf162..127caf5 100644 --- a/printing/backend/print_backend.h +++ b/printing/backend/print_backend.h @@ -10,6 +10,7 @@ #include <vector> #include "base/memory/ref_counted.h" +#include "base/string16.h" #include "printing/print_job_constants.h" #include "printing/printing_export.h" @@ -92,6 +93,9 @@ class PRINTING_EXPORT PrintBackend // Returns true if printer_name points to a valid printer. virtual bool IsValidPrinter(const std::string& printer_name) = 0; + // Simplify title to resolve issue with some drivers. + static string16 SimplifyDocumentTitle(const string16& title); + // Allocate a print backend. If |print_backend_settings| is NULL, default // settings will be used. // Return NULL if no print backend available. diff --git a/printing/backend/print_backend_unittest.cc b/printing/backend/print_backend_unittest.cc new file mode 100644 index 0000000..c801684 --- /dev/null +++ b/printing/backend/print_backend_unittest.cc @@ -0,0 +1,25 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "printing/backend/print_backend.h" +#include "base/utf_string_conversions.h" +#include "testing/gtest/include/gtest/gtest.h" + +namespace printing { + +std::string Simplify(const char* title) { + return UTF16ToUTF8(PrintBackend::SimplifyDocumentTitle(ASCIIToUTF16(title))); +} + +TEST(PrintBackendTest, SimplifyDocumentTitle) { + EXPECT_STREQ("", Simplify("").c_str()); + EXPECT_STREQ("Document wi...oooong name", + Simplify("Document with very looooooooooong name").c_str()); + EXPECT_STREQ("Control Characters", + Simplify("C\ron\ntrol Charac\15ters").c_str()); + EXPECT_STREQ("", Simplify("\n\r\n\r\t\r").c_str()); +} + +} // namespace printing + diff --git a/printing/printing.gyp b/printing/printing.gyp index 89d0d1d..8733e2a 100644 --- a/printing/printing.gyp +++ b/printing/printing.gyp @@ -209,6 +209,7 @@ '../ui/ui.gyp:ui', ], 'sources': [ + 'backend/print_backend_unittest.cc', 'emf_win_unittest.cc', 'printing_test.h', 'page_number_unittest.cc', diff --git a/printing/printing_context_win.cc b/printing/printing_context_win.cc index 522da3d..b5d0551 100644 --- a/printing/printing_context_win.cc +++ b/printing/printing_context_win.cc @@ -16,6 +16,7 @@ #include "base/utf_string_conversions.h" #include "base/values.h" #include "base/win/metro.h" +#include "printing/backend/print_backend.h" #include "printing/backend/win_helper.h" #include "printing/print_job_constants.h" #include "printing/print_settings_initializer_win.h" @@ -504,6 +505,7 @@ PrintingContext::Result PrintingContextWin::NewDocument( if (SP_ERROR == SetAbortProc(context_, &AbortProc)) return OnError(); + DCHECK(PrintBackend::SimplifyDocumentTitle(document_name) == document_name); DOCINFO di = { sizeof(DOCINFO) }; const std::wstring& document_name_wide = UTF16ToWide(document_name); di.lpszDocName = document_name_wide.c_str(); |