Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(16)

Side by Side Diff: printing/print_settings_initializer.cc

Issue 7348010: Added Header and Footer support using Skia (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Refactored JS code Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "printing/print_settings_initializer.h"
6
7 #include <algorithm>
8 #include <cmath>
9
10 #include "base/i18n/time_formatting.h"
11 #include "base/string_number_conversions.h"
12 #include "base/time.h"
13 #include "base/utf_string_conversions.h"
14 #include "base/values.h"
15 #include "googleurl/src/gurl.h"
16 #include "printing/print_job_constants.h"
17 #include "printing/print_settings.h"
18 #include "printing/units.h"
19 #include "ui/base/text/text_elider.h"
20
21 using base::DictionaryValue;
22 using base::Time;
23 using printing::ConvertPointsToPixelDouble;
24 using printing::ConvertUnitDouble;
25 using printing::GetSegmentWidth;
26
27 namespace printing {
28
29 void PrintSettingsInitializer::InitHeaderFooterStrings(
30 const DictionaryValue& job_settings,
31 PrintSettings* print_settings) {
32 if (!job_settings.GetBoolean(printing::kSettingHeaderFooterEnabled,
33 &print_settings->display_header_footer)) {
34 NOTREACHED();
35 }
36 if (!print_settings->display_header_footer)
37 return;
38
39 string16 date = base::TimeFormatShortDateNumeric(Time::Now());
40 string16 title;
41 std::string url;
42 if (!job_settings.GetString(printing::kSettingHeaderFooterTitle, &title) ||
43 !job_settings.GetString(printing::kSettingHeaderFooterURL, &url)) {
44 NOTREACHED();
45 }
46
47 gfx::Font font(UTF8ToUTF16(printing::kSettingHeaderFooterFontName),
48 ceil(ConvertPointsToPixelDouble(
49 printing::kSettingHeaderFooterFontSize)));
50 double segment_width = GetSegmentWidth(ConvertUnitDouble(
51 print_settings->page_setup_device_units().physical_size().width(),
52 print_settings->device_units_per_inch(),
53 printing::kPixelsPerInch));
54 date = ui::ElideText(date, font, segment_width, false);
55 print_settings->date = date;
56
57 // Calculate the available title width. If the date string is not long
58 // enough, increase the available space for the title.
59 // Assumes there is no header text to RIGHT of title.
60 double date_width = font.GetStringWidth(date);
61 double max_title_width = std::min(2 * segment_width,
62 2 * (segment_width - date_width) +
63 segment_width);
64 print_settings->title = ui::ElideText(title, font, max_title_width, false);
65
66 double max_url_width = 2 * segment_width;
67 GURL gurl(url);
68 print_settings->url = ui::ElideUrl(gurl, font, max_url_width, std::string());
69 }
70
71 } // namespace printing
72
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698