1 /*
2 * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
126 }
127
128 // In AppKit Printing, the rectangle is always oriented. In AppKit Printing, setting
129 // the rectangle will always set the orientation.
130 // In java printing, the rectangle is oriented if accessed from PageFormat. It is
131 // not oriented when accessed from Paper.
132
133 static void nsPrintInfoToJavaPaper(JNIEnv* env, NSPrintInfo* src, jobject dst)
134 {
135 static JNF_MEMBER_CACHE(jm_setSize, sjc_Paper, "setSize", "(DD)V");
136 static JNF_MEMBER_CACHE(jm_setImageableArea, sjc_Paper, "setImageableArea", "(DDDD)V");
137
138 jdouble jPaperW, jPaperH;
139
140 // NSPrintInfo paperSize is oriented. java Paper is not oriented. Take
141 // the -[NSPrintInfo orientation] into account when setting the Paper
142 // rectangle.
143
144 NSSize paperSize = [src paperSize];
145 switch ([src orientation]) {
146 case NSPortraitOrientation:
147 jPaperW = paperSize.width;
148 jPaperH = paperSize.height;
149 break;
150
151 case NSLandscapeOrientation:
152 jPaperW = paperSize.height;
153 jPaperH = paperSize.width;
154 break;
155
156 default:
157 jPaperW = paperSize.width;
158 jPaperH = paperSize.height;
159 break;
160 }
161
162 JNFCallVoidMethod(env, dst, jm_setSize, jPaperW, jPaperH); // AWT_THREADING Safe (known object - always actual Paper)
163
164 // Set the imageable area from the margins
165 CGFloat leftM = [src leftMargin];
166 CGFloat rightM = [src rightMargin];
167 CGFloat topM = [src topMargin];
168 CGFloat bottomM = [src bottomMargin];
169
170 jdouble jImageX = leftM;
171 jdouble jImageY = topM;
200 jdouble jImageX = JNFCallDoubleMethod(env, src, jm_getImageableX); // AWT_THREADING Safe (!appKit)
201 jdouble jImageY = JNFCallDoubleMethod(env, src, jm_getImageableY); // AWT_THREADING Safe (!appKit)
202 jdouble jImageW = JNFCallDoubleMethod(env, src, jm_getImageableW); // AWT_THREADING Safe (!appKit)
203 jdouble jImageH = JNFCallDoubleMethod(env, src, jm_getImageableH); // AWT_THREADING Safe (!appKit)
204
205 [dst setLeftMargin:(CGFloat)jImageX];
206 [dst setTopMargin:(CGFloat)jImageY];
207 [dst setRightMargin:(CGFloat)(jPhysicalWidth - jImageW - jImageX)];
208 [dst setBottomMargin:(CGFloat)(jPhysicalHeight - jImageH - jImageY)];
209 }
210
211 static void nsPrintInfoToJavaPageFormat(JNIEnv* env, NSPrintInfo* src, jobject dst)
212 {
213 AWT_ASSERT_NOT_APPKIT_THREAD;
214
215 static JNF_MEMBER_CACHE(jm_setOrientation, sjc_PageFormat, "setOrientation", "(I)V");
216 static JNF_MEMBER_CACHE(jm_setPaper, sjc_PageFormat, "setPaper", "(Ljava/awt/print/Paper;)V");
217 static JNF_CTOR_CACHE(jm_Paper_ctor, sjc_Paper, "()V");
218
219 jint jOrientation;
220 NSPrintingOrientation nsOrientation = [src orientation];
221 switch (nsOrientation) {
222 case NSPortraitOrientation:
223 jOrientation = java_awt_print_PageFormat_PORTRAIT;
224 break;
225
226 case NSLandscapeOrientation:
227 jOrientation = java_awt_print_PageFormat_LANDSCAPE; //+++gdb Are LANDSCAPE and REVERSE_LANDSCAPE still inverted?
228 break;
229
230 /*
231 // AppKit printing doesn't support REVERSE_LANDSCAPE. Radar 2960295.
232 case NSReverseLandscapeOrientation:
233 jOrientation = java_awt_print_PageFormat.REVERSE_LANDSCAPE; //+++gdb Are LANDSCAPE and REVERSE_LANDSCAPE still inverted?
234 break;
235 */
236
237 default:
238 jOrientation = java_awt_print_PageFormat_PORTRAIT;
239 break;
240 }
241
242 JNFCallVoidMethod(env, dst, jm_setOrientation, jOrientation); // AWT_THREADING Safe (!appKit)
243
244 // Create a new Paper
245 jobject paper = JNFNewObject(env, jm_Paper_ctor); // AWT_THREADING Safe (known object)
246
256 {
257 AWT_ASSERT_NOT_APPKIT_THREAD;
258
259 static JNF_MEMBER_CACHE(jm_getOrientation, sjc_PageFormat, "getOrientation", "()I");
260 static JNF_MEMBER_CACHE(jm_getPaper, sjc_PageFormat, "getPaper", "()Ljava/awt/print/Paper;");
261 static JNF_MEMBER_CACHE(jm_getPrinterName, sjc_CPrinterJob, "getPrinterName", "()Ljava/lang/String;");
262
263 // When setting page information (orientation, size) in NSPrintInfo, set the
264 // rectangle first. This is because setting the orientation will change the
265 // rectangle to match.
266
267 // Set up the paper. This will force Portrait since java Paper is
268 // not oriented. Then setting the NSPrintInfo orientation below
269 // will flip NSPrintInfo's info as necessary.
270 jobject paper = JNFCallObjectMethod(env, srcPageFormat, jm_getPaper); // AWT_THREADING Safe (!appKit)
271 javaPaperToNSPrintInfo(env, paper, dstPrintInfo);
272 (*env)->DeleteLocalRef(env, paper);
273
274 switch (JNFCallIntMethod(env, srcPageFormat, jm_getOrientation)) { // AWT_THREADING Safe (!appKit)
275 case java_awt_print_PageFormat_PORTRAIT:
276 [dstPrintInfo setOrientation:NSPortraitOrientation];
277 break;
278
279 case java_awt_print_PageFormat_LANDSCAPE:
280 [dstPrintInfo setOrientation:NSLandscapeOrientation]; //+++gdb Are LANDSCAPE and REVERSE_LANDSCAPE still inverted?
281 break;
282
283 // AppKit printing doesn't support REVERSE_LANDSCAPE. Radar 2960295.
284 case java_awt_print_PageFormat_REVERSE_LANDSCAPE:
285 [dstPrintInfo setOrientation:NSLandscapeOrientation]; //+++gdb Are LANDSCAPE and REVERSE_LANDSCAPE still inverted?
286 break;
287
288 default:
289 [dstPrintInfo setOrientation:NSPortraitOrientation];
290 break;
291 }
292
293 // <rdar://problem/4022422> NSPrinterInfo is not correctly set to the selected printer
294 // from the Java side of CPrinterJob. Has always assumed the default printer was the one we wanted.
295 if (srcPrintJob == NULL) return;
296 jobject printerNameObj = JNFCallObjectMethod(env, srcPrintJob, jm_getPrinterName);
297 if (printerNameObj == NULL) return;
298 NSString *printerName = JNFJavaToNSString(env, printerNameObj);
299 if (printerName == nil) return;
300 NSPrinter *printer = [NSPrinter printerWithName:printerName];
301 if (printer == nil) return;
302 [dstPrintInfo setPrinter:printer];
303 }
304
305 static void nsPrintInfoToJavaPrinterJob(JNIEnv* env, NSPrintInfo* src, jobject dstPrinterJob, jobject dstPageable)
306 {
307 static JNF_MEMBER_CACHE(jm_setService, sjc_CPrinterJob, "setPrinterServiceFromNative", "(Ljava/lang/String;)V");
308 static JNF_MEMBER_CACHE(jm_setCopies, sjc_CPrinterJob, "setCopies", "(I)V");
309 static JNF_MEMBER_CACHE(jm_setCollated, sjc_CPrinterJob, "setCollated", "(Z)V");
|
1 /*
2 * Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
126 }
127
128 // In AppKit Printing, the rectangle is always oriented. In AppKit Printing, setting
129 // the rectangle will always set the orientation.
130 // In java printing, the rectangle is oriented if accessed from PageFormat. It is
131 // not oriented when accessed from Paper.
132
133 static void nsPrintInfoToJavaPaper(JNIEnv* env, NSPrintInfo* src, jobject dst)
134 {
135 static JNF_MEMBER_CACHE(jm_setSize, sjc_Paper, "setSize", "(DD)V");
136 static JNF_MEMBER_CACHE(jm_setImageableArea, sjc_Paper, "setImageableArea", "(DDDD)V");
137
138 jdouble jPaperW, jPaperH;
139
140 // NSPrintInfo paperSize is oriented. java Paper is not oriented. Take
141 // the -[NSPrintInfo orientation] into account when setting the Paper
142 // rectangle.
143
144 NSSize paperSize = [src paperSize];
145 switch ([src orientation]) {
146 case NSPaperOrientationPortrait:
147 jPaperW = paperSize.width;
148 jPaperH = paperSize.height;
149 break;
150
151 case NSPaperOrientationLandscape:
152 jPaperW = paperSize.height;
153 jPaperH = paperSize.width;
154 break;
155
156 default:
157 jPaperW = paperSize.width;
158 jPaperH = paperSize.height;
159 break;
160 }
161
162 JNFCallVoidMethod(env, dst, jm_setSize, jPaperW, jPaperH); // AWT_THREADING Safe (known object - always actual Paper)
163
164 // Set the imageable area from the margins
165 CGFloat leftM = [src leftMargin];
166 CGFloat rightM = [src rightMargin];
167 CGFloat topM = [src topMargin];
168 CGFloat bottomM = [src bottomMargin];
169
170 jdouble jImageX = leftM;
171 jdouble jImageY = topM;
200 jdouble jImageX = JNFCallDoubleMethod(env, src, jm_getImageableX); // AWT_THREADING Safe (!appKit)
201 jdouble jImageY = JNFCallDoubleMethod(env, src, jm_getImageableY); // AWT_THREADING Safe (!appKit)
202 jdouble jImageW = JNFCallDoubleMethod(env, src, jm_getImageableW); // AWT_THREADING Safe (!appKit)
203 jdouble jImageH = JNFCallDoubleMethod(env, src, jm_getImageableH); // AWT_THREADING Safe (!appKit)
204
205 [dst setLeftMargin:(CGFloat)jImageX];
206 [dst setTopMargin:(CGFloat)jImageY];
207 [dst setRightMargin:(CGFloat)(jPhysicalWidth - jImageW - jImageX)];
208 [dst setBottomMargin:(CGFloat)(jPhysicalHeight - jImageH - jImageY)];
209 }
210
211 static void nsPrintInfoToJavaPageFormat(JNIEnv* env, NSPrintInfo* src, jobject dst)
212 {
213 AWT_ASSERT_NOT_APPKIT_THREAD;
214
215 static JNF_MEMBER_CACHE(jm_setOrientation, sjc_PageFormat, "setOrientation", "(I)V");
216 static JNF_MEMBER_CACHE(jm_setPaper, sjc_PageFormat, "setPaper", "(Ljava/awt/print/Paper;)V");
217 static JNF_CTOR_CACHE(jm_Paper_ctor, sjc_Paper, "()V");
218
219 jint jOrientation;
220 NSPaperOrientation nsOrientation = [src orientation];
221 switch (nsOrientation) {
222 case NSPaperOrientationPortrait:
223 jOrientation = java_awt_print_PageFormat_PORTRAIT;
224 break;
225
226 case NSPaperOrientationLandscape:
227 jOrientation = java_awt_print_PageFormat_LANDSCAPE; //+++gdb Are LANDSCAPE and REVERSE_LANDSCAPE still inverted?
228 break;
229
230 /*
231 // AppKit printing doesn't support REVERSE_LANDSCAPE. Radar 2960295.
232 case NSReverseLandscapeOrientation:
233 jOrientation = java_awt_print_PageFormat.REVERSE_LANDSCAPE; //+++gdb Are LANDSCAPE and REVERSE_LANDSCAPE still inverted?
234 break;
235 */
236
237 default:
238 jOrientation = java_awt_print_PageFormat_PORTRAIT;
239 break;
240 }
241
242 JNFCallVoidMethod(env, dst, jm_setOrientation, jOrientation); // AWT_THREADING Safe (!appKit)
243
244 // Create a new Paper
245 jobject paper = JNFNewObject(env, jm_Paper_ctor); // AWT_THREADING Safe (known object)
246
256 {
257 AWT_ASSERT_NOT_APPKIT_THREAD;
258
259 static JNF_MEMBER_CACHE(jm_getOrientation, sjc_PageFormat, "getOrientation", "()I");
260 static JNF_MEMBER_CACHE(jm_getPaper, sjc_PageFormat, "getPaper", "()Ljava/awt/print/Paper;");
261 static JNF_MEMBER_CACHE(jm_getPrinterName, sjc_CPrinterJob, "getPrinterName", "()Ljava/lang/String;");
262
263 // When setting page information (orientation, size) in NSPrintInfo, set the
264 // rectangle first. This is because setting the orientation will change the
265 // rectangle to match.
266
267 // Set up the paper. This will force Portrait since java Paper is
268 // not oriented. Then setting the NSPrintInfo orientation below
269 // will flip NSPrintInfo's info as necessary.
270 jobject paper = JNFCallObjectMethod(env, srcPageFormat, jm_getPaper); // AWT_THREADING Safe (!appKit)
271 javaPaperToNSPrintInfo(env, paper, dstPrintInfo);
272 (*env)->DeleteLocalRef(env, paper);
273
274 switch (JNFCallIntMethod(env, srcPageFormat, jm_getOrientation)) { // AWT_THREADING Safe (!appKit)
275 case java_awt_print_PageFormat_PORTRAIT:
276 [dstPrintInfo setOrientation:NSPaperOrientationPortrait];
277 break;
278
279 case java_awt_print_PageFormat_LANDSCAPE:
280 [dstPrintInfo setOrientation:NSPaperOrientationLandscape]; //+++gdb Are LANDSCAPE and REVERSE_LANDSCAPE still inverted?
281 break;
282
283 // AppKit printing doesn't support REVERSE_LANDSCAPE. Radar 2960295.
284 case java_awt_print_PageFormat_REVERSE_LANDSCAPE:
285 [dstPrintInfo setOrientation:NSPaperOrientationLandscape]; //+++gdb Are LANDSCAPE and REVERSE_LANDSCAPE still inverted?
286 break;
287
288 default:
289 [dstPrintInfo setOrientation:NSPaperOrientationPortrait];
290 break;
291 }
292
293 // <rdar://problem/4022422> NSPrinterInfo is not correctly set to the selected printer
294 // from the Java side of CPrinterJob. Has always assumed the default printer was the one we wanted.
295 if (srcPrintJob == NULL) return;
296 jobject printerNameObj = JNFCallObjectMethod(env, srcPrintJob, jm_getPrinterName);
297 if (printerNameObj == NULL) return;
298 NSString *printerName = JNFJavaToNSString(env, printerNameObj);
299 if (printerName == nil) return;
300 NSPrinter *printer = [NSPrinter printerWithName:printerName];
301 if (printer == nil) return;
302 [dstPrintInfo setPrinter:printer];
303 }
304
305 static void nsPrintInfoToJavaPrinterJob(JNIEnv* env, NSPrintInfo* src, jobject dstPrinterJob, jobject dstPageable)
306 {
307 static JNF_MEMBER_CACHE(jm_setService, sjc_CPrinterJob, "setPrinterServiceFromNative", "(Ljava/lang/String;)V");
308 static JNF_MEMBER_CACHE(jm_setCopies, sjc_CPrinterJob, "setCopies", "(I)V");
309 static JNF_MEMBER_CACHE(jm_setCollated, sjc_CPrinterJob, "setCollated", "(Z)V");
|