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

Side by Side Diff: printing/header_footer_initializer.cc

Issue 7348010: Added Header and Footer support using Skia (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Moved elide text to print_settings_initializer 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/header_footer_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 HeaderFooterInitializer::InitHeaderFooterStrings(
30 const DictionaryValue& header_footer_info,
31 PrintSettings* print_settings) {
32 if (!header_footer_info.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 (!header_footer_info.GetString(printing::kSettingHeaderFooterTitle,
43 &title) ||
44 !header_footer_info.GetString(printing::kSettingHeaderFooterURL,
45 &url)) {
46 NOTREACHED();
47 }
48
49 gfx::Font font(UTF8ToUTF16(printing::kSettingHeaderFooterFontName),
50 ceil(ConvertPointsToPixelDouble(
51 printing::kSettingHeaderFooterFontSize)));
52 double segment_width = GetSegmentWidth(ConvertUnitDouble(
53 print_settings->page_setup_device_units().physical_size().width(),
54 print_settings->device_units_per_inch(),
55 printing::kPixelsPerInch));
56 date = ui::ElideText(date, font, segment_width, false);
57 print_settings->date = date;
58
59 // Calculate the available title width. If the date string is not long
60 // enough, increase the available space for the title.
61 // Assumes there is no header text to RIGHT of title.
62 double date_width = font.GetStringWidth(date);
63 double max_title_width = std::min(2 * segment_width,
64 2 * (segment_width - date_width) +
65 segment_width);
66 print_settings->title = ui::ElideText(title, font, max_title_width, false);
67
68 double max_url_width = 2 * segment_width;
69 GURL gurl(url);
70 print_settings->url = ui::ElideUrl(gurl, font, max_url_width, std::string());
71 }
72
73 } // namespace printing
74
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698