Skip to content

Commit 7000daa

Browse files
S1artiemagreenblatt
authored andcommitted
Update to CEF version 108.4.13+ga98cd4c+chromium-108.0.5359.125
Implements adaptations to new _cef_pdf_print_settings_t (CEF issue #3377)
1 parent b5f0a44 commit 7000daa

File tree

5 files changed

+104
-84
lines changed

5 files changed

+104
-84
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ set_property(GLOBAL PROPERTY OS_FOLDERS ON)
130130

131131
# Specify the CEF distribution version.
132132
if(NOT DEFINED CEF_VERSION)
133-
set(CEF_VERSION "107.1.9+g1f0a21a+chromium-107.0.5304.110")
133+
set(CEF_VERSION "108.4.13+ga98cd4c+chromium-108.0.5359.125")
134134
endif()
135135

136136
# Determine the platform.

java/org/cef/misc/CefPdfPrintSettings.java

Lines changed: 67 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -15,97 +15,116 @@ public enum MarginType {
1515
// No margins
1616
NONE,
1717

18-
// Minimum margins.
19-
MINIMUM,
20-
2118
// Custom margins using the values from CefPdfPrintSettings
2219
CUSTOM
2320
}
2421

2522
/**
26-
* Set to true to print headers and footers or false to not print
27-
* headers and footers.
23+
* Set to true for landscape mode or false for portrait mode.
2824
*/
29-
public boolean header_footer_enabled;
25+
public boolean landscape;
3026

3127
/**
32-
* Page title to display in the header. Only used if header_footer_enabled
33-
* is set to true.
28+
* Set to true to print background graphics or false to not print
29+
* background graphics.
3430
*/
35-
public String header_footer_title;
31+
public boolean print_background;
3632

3733
/**
38-
* URL to display in the footer. Only used if header_footer_enabled is set
39-
* to true.
34+
* The percentage to scale the PDF by before printing (e.g. .5 is 50%).
35+
* If this value is less than or equal to zero the default value of 1.0
36+
* will be used.
4037
*/
41-
public String header_footer_url;
38+
public double scale;
4239

4340
/**
44-
* Set to true for landscape mode or false for portrait mode.
41+
* Output paper size in inches. If either of these values is less than or
42+
* equal to zero then the default paper size (letter, 8.5 x 11 inches) will
43+
* be used.
4544
*/
46-
public boolean landscape;
45+
public double paper_width;
46+
public double paper_height;
4747

4848
/**
49-
* Set to true to print background graphics or false to not print
50-
* background graphics.
49+
* Set to true to prefer page size as defined by css. Defaults to false
50+
* in which case the content will be scaled to fit the paper size.
51+
*/
52+
public boolean prefer_css_page_size;
53+
54+
/**
55+
* Margin type.
5156
*/
52-
public boolean backgrounds_enabled;
57+
public MarginType margin_type;
5358

5459
/**
55-
* Output page size in microns (1 millimeter = 1000 microns). If either of these
56-
* values is less than or equal to zero then the default paper size will be
57-
* used as returned by the print_handler. A4 is 210 x 297 mm which would
58-
* be 210000 x 297000 microns. US Letter is 215.9 x 279.4 mm which would
59-
* be 215900 x 279400 microns.
60+
* Margins in inches. Only used if margin_type is set to CUSTOM.
6061
*/
61-
public int page_width;
62-
public int page_height;
62+
public double margin_top;
63+
public double margin_right;
64+
public double margin_bottom;
65+
public double margin_left;
6366

6467
/**
65-
* Set to true to print the selection only or false to print all.
68+
* Paper ranges to print, one based, e.g., '1-5, 8, 11-13'. Pages are printed
69+
* in the document order, not in the order specified, and no more than once.
70+
* Defaults to empty string, which implies the entire document is printed.
71+
* The page numbers are quietly capped to actual page count of the document,
72+
* and ranges beyond the end of the document are ignored. If this results in
73+
* no pages to print, an error is reported. It is an error to specify a range
74+
* with start greater than end.
6675
*/
67-
public boolean selection_only;
76+
public String page_ranges;
6877

6978
/**
70-
* The percentage to scale the PDF by before printing (e.g. 50 is 50%).
71-
* If this value is less than or equal to zero the default value of 100
72-
* will be used.
79+
* Set to true to print headers and footers or false to not print
80+
* headers and footers. Modify header_template and/or footer_template to
81+
* customize the display.
7382
*/
74-
public int scale_factor;
83+
public boolean display_header_footer;
7584

7685
/**
77-
* Margins in points. Only used if |margin_type| is set to
78-
* PDF_PRINT_MARGIN_CUSTOM.
86+
* HTML template for the print header. Only displayed if
87+
* |display_header_footer| is true (1). Should be valid HTML markup with
88+
* the following classes used to inject printing values into them:
89+
*
90+
* - date: formatted print date
91+
* - title: document title
92+
* - url: document location
93+
* - pageNumber: current page number
94+
* - totalPages: total pages in the document
95+
*
96+
* For example, "<span class=title></span>" would generate a span containing
97+
* the title.
7998
*/
80-
public int margin_top;
81-
public int margin_right;
82-
public int margin_bottom;
83-
public int margin_left;
99+
public String header_template;
84100

85101
/**
86-
* Margin type.
102+
* HTML template for the print footer. Only displayed if
103+
* |display_header_footer| is true (1). Uses the same format as
104+
* |header_template|.
87105
*/
88-
public MarginType margin_type;
106+
public String footer_template;
89107

90108
public CefPdfPrintSettings() {}
91109

92110
@Override
93111
public CefPdfPrintSettings clone() {
94112
CefPdfPrintSettings tmp = new CefPdfPrintSettings();
95-
tmp.header_footer_enabled = this.header_footer_enabled;
96-
tmp.header_footer_title = this.header_footer_title;
97-
tmp.header_footer_url = this.header_footer_url;
98113
tmp.landscape = this.landscape;
99-
tmp.backgrounds_enabled = this.backgrounds_enabled;
100-
tmp.page_width = this.page_width;
101-
tmp.page_height = this.page_height;
102-
tmp.selection_only = this.selection_only;
103-
tmp.scale_factor = this.scale_factor;
114+
tmp.print_background = this.print_background;
115+
tmp.scale = this.scale;
116+
tmp.paper_width = this.paper_width;
117+
tmp.paper_height = this.paper_height;
118+
tmp.prefer_css_page_size = this.prefer_css_page_size;
119+
tmp.margin_type = this.margin_type;
104120
tmp.margin_top = this.margin_top;
105-
tmp.margin_right = this.margin_right;
106121
tmp.margin_bottom = this.margin_bottom;
122+
tmp.margin_right = this.margin_right;
107123
tmp.margin_left = this.margin_left;
108-
tmp.margin_type = this.margin_type;
124+
tmp.page_ranges = this.page_ranges;
125+
tmp.display_header_footer = this.display_header_footer;
126+
tmp.header_template = this.header_template;
127+
tmp.footer_template = this.footer_template;
109128
return tmp;
110129
}
111130
}

java/tests/detailed/ui/MenuBar.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,10 @@ public void actionPerformed(ActionEvent e) {
157157
File selectedFile = fc.getSelectedFile();
158158
if (selectedFile != null) {
159159
CefPdfPrintSettings pdfSettings = new CefPdfPrintSettings();
160-
pdfSettings.header_footer_enabled = true;
161-
// A4 page size
162-
pdfSettings.page_width = 210000;
163-
pdfSettings.page_height = 297000;
160+
pdfSettings.display_header_footer = true;
161+
// letter page size
162+
pdfSettings.paper_width = 8.5;
163+
pdfSettings.paper_height = 11;
164164
browser.printToPDF(
165165
selectedFile.getAbsolutePath(), pdfSettings, new CefPdfPrintCallback() {
166166
@Override

native/CefBrowser_N.cpp

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1078,33 +1078,18 @@ CefPdfPrintSettings GetJNIPdfPrintSettings(JNIEnv* env, jobject obj) {
10781078
if (!cls)
10791079
return settings;
10801080

1081-
GetJNIFieldBoolean(env, cls, obj, "header_footer_enabled",
1082-
&settings.header_footer_enabled);
1083-
1084-
if (GetJNIFieldString(env, cls, obj, "header_footer_title", &tmp) &&
1085-
!tmp.empty()) {
1086-
CefString(&settings.header_footer_title) = tmp;
1087-
tmp.clear();
1088-
}
1089-
1090-
if (GetJNIFieldString(env, cls, obj, "header_footer_url", &tmp) &&
1091-
!tmp.empty()) {
1092-
CefString(&settings.header_footer_url) = tmp;
1093-
tmp.clear();
1094-
}
1095-
10961081
GetJNIFieldBoolean(env, cls, obj, "landscape", &settings.landscape);
10971082

1098-
GetJNIFieldBoolean(env, cls, obj, "backgrounds_enabled",
1099-
&settings.backgrounds_enabled);
1083+
GetJNIFieldBoolean(env, cls, obj, "print_background",
1084+
&settings.print_background);
11001085

1101-
GetJNIFieldInt(env, cls, obj, "page_width", &settings.page_width);
1086+
GetJNIFieldDouble(env, cls, obj, "scale", &settings.scale);
11021087

1103-
GetJNIFieldInt(env, cls, obj, "page_height", &settings.page_height);
1088+
GetJNIFieldDouble(env, cls, obj, "paper_width", &settings.paper_width);
1089+
GetJNIFieldDouble(env, cls, obj, "paper_height", &settings.paper_height);
11041090

1105-
GetJNIFieldBoolean(env, cls, obj, "selection_only", &settings.selection_only);
1106-
1107-
GetJNIFieldInt(env, cls, obj, "scale_factor", &settings.scale_factor);
1091+
GetJNIFieldBoolean(env, cls, obj, "prefer_css_page_size",
1092+
&settings.prefer_css_page_size);
11081093

11091094
jobject obj_margin_type = nullptr;
11101095
if (GetJNIFieldObject(env, cls, obj, "margin_type", &obj_margin_type,
@@ -1118,21 +1103,37 @@ CefPdfPrintSettings GetJNIPdfPrintSettings(JNIEnv* env, jobject obj) {
11181103
"org/cef/misc/CefPdfPrintSettings$MarginType",
11191104
"NONE")) {
11201105
settings.margin_type = PDF_PRINT_MARGIN_NONE;
1121-
} else if (IsJNIEnumValue(env, margin_type,
1122-
"org/cef/misc/CefPdfPrintSettings$MarginType",
1123-
"MINIMUM")) {
1124-
settings.margin_type = PDF_PRINT_MARGIN_MINIMUM;
11251106
} else if (IsJNIEnumValue(env, margin_type,
11261107
"org/cef/misc/CefPdfPrintSettings$MarginType",
11271108
"CUSTOM")) {
11281109
settings.margin_type = PDF_PRINT_MARGIN_CUSTOM;
11291110
}
11301111
}
11311112

1132-
GetJNIFieldInt(env, cls, obj, "margin_top", &settings.margin_top);
1133-
GetJNIFieldInt(env, cls, obj, "margin_bottom", &settings.margin_bottom);
1134-
GetJNIFieldInt(env, cls, obj, "margin_right", &settings.margin_right);
1135-
GetJNIFieldInt(env, cls, obj, "margin_left", &settings.margin_left);
1113+
GetJNIFieldDouble(env, cls, obj, "margin_top", &settings.margin_top);
1114+
GetJNIFieldDouble(env, cls, obj, "margin_bottom", &settings.margin_bottom);
1115+
GetJNIFieldDouble(env, cls, obj, "margin_right", &settings.margin_right);
1116+
GetJNIFieldDouble(env, cls, obj, "margin_left", &settings.margin_left);
1117+
1118+
if (GetJNIFieldString(env, cls, obj, "page_ranges", &tmp) && !tmp.empty()) {
1119+
CefString(&settings.page_ranges) = tmp;
1120+
tmp.clear();
1121+
}
1122+
1123+
GetJNIFieldBoolean(env, cls, obj, "display_header_footer",
1124+
&settings.display_header_footer);
1125+
1126+
if (GetJNIFieldString(env, cls, obj, "header_template", &tmp) &&
1127+
!tmp.empty()) {
1128+
CefString(&settings.header_template) = tmp;
1129+
tmp.clear();
1130+
}
1131+
1132+
if (GetJNIFieldString(env, cls, obj, "footer_template", &tmp) &&
1133+
!tmp.empty()) {
1134+
CefString(&settings.footer_template) = tmp;
1135+
tmp.clear();
1136+
}
11361137

11371138
return settings;
11381139
}

native/resource_handler.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ void ResourceHandler::GetResponseHeaders(CefRefPtr<CefResponse> response,
4444

4545
ScopedJNIResponse jresponse(env, response);
4646
jresponse.SetTemporary();
47-
ScopedJNIIntRef jresponseLength(env, response_length);
47+
ScopedJNIIntRef jresponseLength(env, (int)response_length);
4848
ScopedJNIStringRef jredirectUrl(env, redirectUrl);
4949

5050
JNI_CALL_VOID_METHOD(env, handle_, "getResponseHeaders",

0 commit comments

Comments
 (0)