Lines 1-5
Link Here
|
1 |
/****************************************************************************** |
1 |
/****************************************************************************** |
2 |
* Copyright (c) 2002, 2007 IBM Corporation and others. |
2 |
* Copyright (c) 2008 IBM Corporation and others. |
3 |
* All rights reserved. This program and the accompanying materials |
3 |
* All rights reserved. This program and the accompanying materials |
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
5 |
* which accompanies this distribution, and is available at |
5 |
* which accompanies this distribution, and is available at |
Lines 12-888
Link Here
|
12 |
package org.eclipse.gmf.runtime.diagram.ui.printing.internal.util; |
12 |
package org.eclipse.gmf.runtime.diagram.ui.printing.internal.util; |
13 |
|
13 |
|
14 |
import java.util.Collection; |
14 |
import java.util.Collection; |
15 |
import java.util.Iterator; |
|
|
16 |
|
15 |
|
17 |
import org.eclipse.core.runtime.Assert; |
|
|
18 |
import org.eclipse.draw2d.Graphics; |
16 |
import org.eclipse.draw2d.Graphics; |
19 |
import org.eclipse.draw2d.SWTGraphics; |
|
|
20 |
import org.eclipse.draw2d.geometry.Rectangle; |
17 |
import org.eclipse.draw2d.geometry.Rectangle; |
21 |
import org.eclipse.gef.LayerConstants; |
|
|
22 |
import org.eclipse.gef.RootEditPart; |
18 |
import org.eclipse.gef.RootEditPart; |
23 |
import org.eclipse.gmf.runtime.diagram.core.preferences.PreferencesHint; |
19 |
import org.eclipse.gmf.runtime.diagram.core.preferences.PreferencesHint; |
24 |
import org.eclipse.gmf.runtime.diagram.core.util.ViewUtil; |
|
|
25 |
import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart; |
20 |
import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart; |
26 |
import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramRootEditPart; |
21 |
import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramRootEditPart; |
27 |
import org.eclipse.gmf.runtime.diagram.ui.internal.editparts.PageBreakEditPart; |
22 |
import org.eclipse.gmf.runtime.diagram.ui.internal.editparts.PageBreakEditPart; |
28 |
import org.eclipse.gmf.runtime.diagram.ui.internal.figures.PageBreaksFigure; |
23 |
import org.eclipse.gmf.runtime.diagram.ui.internal.figures.PageBreaksFigure; |
29 |
import org.eclipse.gmf.runtime.diagram.ui.internal.pagesetup.PageInfoHelper; |
|
|
30 |
import org.eclipse.gmf.runtime.diagram.ui.internal.pagesetup.PageInfoHelper.PageMargins; |
31 |
import org.eclipse.gmf.runtime.diagram.ui.internal.properties.WorkspaceViewerProperties; |
32 |
import org.eclipse.gmf.runtime.diagram.ui.parts.DiagramEditor; |
33 |
import org.eclipse.gmf.runtime.diagram.ui.parts.DiagramGraphicalViewer; |
34 |
import org.eclipse.gmf.runtime.diagram.ui.util.DiagramEditorUtil; |
35 |
import org.eclipse.gmf.runtime.draw2d.ui.internal.graphics.MapModeGraphics; |
24 |
import org.eclipse.gmf.runtime.draw2d.ui.internal.graphics.MapModeGraphics; |
36 |
import org.eclipse.gmf.runtime.draw2d.ui.internal.graphics.PrinterGraphics; |
|
|
37 |
import org.eclipse.gmf.runtime.draw2d.ui.internal.graphics.ScaledGraphics; |
38 |
import org.eclipse.gmf.runtime.draw2d.ui.mapmode.IMapMode; |
25 |
import org.eclipse.gmf.runtime.draw2d.ui.mapmode.IMapMode; |
39 |
import org.eclipse.gmf.runtime.draw2d.ui.mapmode.MapModeUtil; |
|
|
40 |
import org.eclipse.gmf.runtime.notation.Diagram; |
26 |
import org.eclipse.gmf.runtime.notation.Diagram; |
41 |
import org.eclipse.jface.preference.IPreferenceStore; |
|
|
42 |
import org.eclipse.jface.resource.JFaceResources; |
43 |
import org.eclipse.swt.SWT; |
44 |
import org.eclipse.swt.graphics.Font; |
45 |
import org.eclipse.swt.graphics.FontData; |
46 |
import org.eclipse.swt.graphics.GC; |
47 |
import org.eclipse.swt.graphics.Image; |
48 |
import org.eclipse.swt.graphics.Point; |
27 |
import org.eclipse.swt.graphics.Point; |
49 |
import org.eclipse.swt.printing.Printer; |
|
|
50 |
import org.eclipse.swt.widgets.Display; |
51 |
import org.eclipse.swt.widgets.Shell; |
52 |
import org.eclipse.ui.PlatformUI; |
53 |
|
28 |
|
54 |
/* |
|
|
55 |
* @canBeSeenBy %level1 |
56 |
*/ |
57 |
public class DiagramPrinter |
58 |
implements Runnable { |
59 |
|
60 |
protected Printer printer; |
61 |
|
62 |
private Point display_dpi; |
63 |
|
64 |
private boolean isScaledPercent = false; |
65 |
|
66 |
private int rows = 1; |
67 |
|
68 |
private int columns = 1; |
69 |
|
70 |
private boolean printRangePageSelection = false; |
71 |
|
72 |
private int pageFrom = 1, pageTo = 1; |
73 |
|
74 |
private GC gc; |
75 |
|
76 |
private Graphics swtGraphics; |
77 |
|
78 |
private Graphics graphics; |
79 |
|
80 |
private PrinterGraphics printerGraphics; |
81 |
|
82 |
protected Point printerOffset; |
83 |
|
84 |
protected Rectangle logicalClientArea; |
85 |
|
86 |
private float userScale; |
87 |
|
88 |
/** |
89 |
* Used when a Collection of Diagram objects are passed in instead of an |
90 |
* IEditorPart. |
91 |
*/ |
92 |
protected Collection diagrams; |
93 |
|
94 |
/** |
95 |
* The initial amount that the diagram should be translated, set by |
96 |
* printToScale or printToPages which calls drawToFitRowsColumns. |
97 |
*/ |
98 |
private Point translated = null; |
99 |
|
100 |
/** |
101 |
* The hint used to find the appropriate preference store from which general |
102 |
* diagramming preference values for properties of shapes, connections, and |
103 |
* diagrams can be retrieved. This hint is mapped to a preference store in |
104 |
* the {@link DiagramPreferencesRegistry}. |
105 |
*/ |
106 |
private PreferencesHint preferencesHint; |
107 |
private IMapMode mm; |
108 |
|
109 |
private boolean fitToPage = false; |
110 |
|
111 |
/** |
112 |
* change the fit to page state |
113 |
* @param fitToPage the new fit to page state |
114 |
*/ |
115 |
public void setFitToPage(boolean fitToPage){ |
116 |
this.fitToPage = fitToPage; |
117 |
} |
118 |
|
119 |
/** |
120 |
* Creates a new instance. The following variables must be initialized |
121 |
* before calling <code>run()</code>: |
122 |
* <li><code>printer</code></li> |
123 |
* <li><code>display_dpi</code></li> |
124 |
* <li><code>diagrams</code></li> |
125 |
* @param mm <code>IMapMode</code> to do the coordinate mapping |
126 |
*/ |
127 |
public DiagramPrinter(PreferencesHint preferencesHint, IMapMode mm) { |
128 |
super(); |
129 |
this.preferencesHint = preferencesHint; |
130 |
this.mm = mm; |
131 |
} |
132 |
|
133 |
/** |
134 |
* Creates a new instance. The following variables must be initialized |
135 |
* before calling <code>run()</code>: |
136 |
* <li><code>printer</code></li> |
137 |
* <li><code>display_dpi</code></li> |
138 |
* <li><code>diagrams</code></li> |
139 |
* @param mm <code>IMapMode</code> to do the coordinate mapping |
140 |
*/ |
141 |
public DiagramPrinter(PreferencesHint preferencesHint) { |
142 |
this(preferencesHint, MapModeUtil.getMapMode()); |
143 |
} |
144 |
|
145 |
/** |
146 |
* @return <code>IMapMode</code> to do the coordinate mapping |
147 |
*/ |
148 |
protected IMapMode getMapMode() { |
149 |
return mm; |
150 |
} |
151 |
|
152 |
/** |
153 |
* Sets the columns. |
154 |
* |
155 |
* @param columns |
156 |
* The columns to set. |
157 |
*/ |
158 |
public void setColumns(int columns) { |
159 |
this.columns = columns; |
160 |
} |
161 |
|
162 |
/** |
163 |
* Sets the diagrams. |
164 |
* |
165 |
* @param diagrams |
166 |
* a Collection of Diagram objects |
167 |
*/ |
168 |
public void setDiagrams(Collection diagrams) { |
169 |
this.diagrams = diagrams; |
170 |
} |
171 |
|
172 |
/** |
173 |
* Sets the display DPI. |
174 |
* |
175 |
* @param display_dpi |
176 |
* The display_dpi to set. |
177 |
*/ |
178 |
public void setDisplayDPI(Point display_dpi) { |
179 |
this.display_dpi = new Point(display_dpi.x, display_dpi.y); |
180 |
} |
181 |
|
182 |
/** |
183 |
* Sets the printer. |
184 |
* |
185 |
* @param printer |
186 |
* The printer to set. |
187 |
*/ |
188 |
public void setPrinter(Printer printer) { |
189 |
this.printer = printer; |
190 |
} |
191 |
|
192 |
public void setPrintRangePageSelection(boolean isPrintRangePageSelected) { |
193 |
this.printRangePageSelection = isPrintRangePageSelected; |
194 |
} |
195 |
|
196 |
public void setPrintRangePages(int pageFrom, int pageTo) { |
197 |
assert pageFrom > 0 : "From page in print range page selection must be bigger than zero."; //$NON-NLS-1$ |
198 |
assert (pageTo > 0 && pageTo >= pageFrom) : "To page in print range page selection must be bigger than zero and from page."; //$NON-NLS-1$ |
199 |
this.pageFrom = pageFrom; |
200 |
this.pageTo = pageTo; |
201 |
} |
202 |
|
203 |
/** |
204 |
* Sets the rows. |
205 |
* |
206 |
* @param rows |
207 |
* The rows to set. |
208 |
*/ |
209 |
public void setRows(int rows) { |
210 |
this.rows = rows; |
211 |
} |
212 |
|
213 |
/** |
214 |
* Sets the scaled percent. |
215 |
* |
216 |
* @param scalePercent |
217 |
*/ |
218 |
public void setScaledPercent(int scalePercent) { |
219 |
this.isScaledPercent = true; |
220 |
this.userScale = (scalePercent) / 100.0f; |
221 |
|
222 |
} |
223 |
|
224 |
/** |
225 |
* Prints the contents of the diagram editor part. |
226 |
*/ |
227 |
public void run() { |
228 |
assert null != printer : "printer must be set"; //$NON-NLS-1$ |
229 |
if (!(printer.startJob("Printing"))) { //$NON-NLS-1$ |
230 |
return; |
231 |
} |
232 |
|
233 |
assert diagrams != null; |
234 |
Iterator it = diagrams.iterator(); |
235 |
|
236 |
Shell shell = new Shell(); |
237 |
try { |
238 |
while (it.hasNext()) { |
239 |
Object obj = it.next(); |
240 |
//the diagrams List is only supposed to have Diagram objects |
241 |
Assert.isTrue(obj instanceof Diagram); |
242 |
Diagram diagram = (Diagram)obj; |
243 |
DiagramEditor openedDiagramEditor = DiagramEditorUtil |
244 |
.findOpenedDiagramEditorForID(ViewUtil |
245 |
.getIdStr(diagram)); |
246 |
DiagramEditPart dgrmEP = openedDiagramEditor == null ? PrintHelper |
247 |
.createDiagramEditPart(diagram, preferencesHint, shell) |
248 |
: openedDiagramEditor.getDiagramEditPart(); |
249 |
|
250 |
boolean loadedPreferences = openedDiagramEditor != null || PrintHelper.initializePreferences(dgrmEP, preferencesHint); |
251 |
|
252 |
RootEditPart rep = dgrmEP.getRoot(); |
253 |
if (rep instanceof DiagramRootEditPart) |
254 |
this.mm = ((DiagramRootEditPart)rep).getMapMode(); |
255 |
|
256 |
initialize(); |
257 |
|
258 |
|
259 |
IPreferenceStore pref = null; |
260 |
|
261 |
assert dgrmEP.getViewer() instanceof DiagramGraphicalViewer; |
262 |
|
263 |
pref = ((DiagramGraphicalViewer)dgrmEP.getViewer()).getWorkspaceViewerPreferenceStore(); |
264 |
|
265 |
if (pref.getBoolean(WorkspaceViewerProperties.PREF_USE_WORKSPACE_SETTINGS)) { |
266 |
|
267 |
//get workspace settings... |
268 |
if (dgrmEP.getDiagramPreferencesHint().getPreferenceStore() != null) |
269 |
pref = (IPreferenceStore)dgrmEP.getDiagramPreferencesHint().getPreferenceStore(); |
270 |
} |
271 |
|
272 |
doPrintDiagram(dgrmEP, loadedPreferences, pref); |
273 |
|
274 |
dispose(); |
275 |
} |
276 |
printer.endJob(); |
277 |
} finally { |
278 |
shell.dispose(); |
279 |
} |
280 |
} |
281 |
|
282 |
/** |
283 |
* Calculates the row in a grid, given a page number. |
284 |
* | 1 | 2 | 3 | |
285 |
* | 4 | 5 | 6 | |
286 |
* | 7 | 8 | 9 | |
287 |
* |
288 |
* Given pageNum=5 and totalNumColumns=3, will return 2 |
289 |
* (2nd row). |
290 |
* |
291 |
* @param pageNum the page number in the grid. |
292 |
* @param totalNumColumns total number of columns of the grid. |
293 |
* @return row number corresponding to the page number. |
294 |
*/ |
295 |
private int calculateRowFromPage(int pageNum, int totalNumColumns) { |
296 |
int row = pageNum / totalNumColumns; |
297 |
if (pageNum % totalNumColumns != 0) |
298 |
row++; |
299 |
return row; |
300 |
} |
301 |
|
302 |
/** |
303 |
* Calculates the column in a grid, given a page number. |
304 |
* | 1 | 2 | 3 | |
305 |
* | 4 | 5 | 6 | |
306 |
* | 7 | 8 | 9 | |
307 |
* |
308 |
* Given pageNum=5 and totalNumColumns=3, will return 2 |
309 |
* (2nd column). |
310 |
* |
311 |
* @param pageNum the page number in the grid. |
312 |
* @param totalNumColumns total number of columns of the grid. |
313 |
* @param cRow the corresponding row of the page number. |
314 |
* @return row number corresponding to the page number. |
315 |
*/ |
316 |
private int calculateColumnFromPage(int pageNum, int totalNumColumns, int cRow) { |
317 |
int col = pageNum - ((cRow - 1) * totalNumColumns); |
318 |
return col; |
319 |
} |
320 |
|
321 |
/** |
322 |
* Obtains the total number of pages that span columns and rows |
323 |
* @param dgrmEP |
324 |
* @return Point.x contains the total number of pages that span in a column |
325 |
* Point.y contains the total number of pages that span in a row |
326 |
*/ |
327 |
private org.eclipse.draw2d.geometry.Point getPageCount(DiagramEditPart dgrmEP, Rectangle figureBounds, org.eclipse.draw2d.geometry.Point pageSize, boolean applyUserScale) { |
328 |
RootEditPart rootEditPart = dgrmEP.getRoot(); |
329 |
if (rootEditPart instanceof DiagramRootEditPart) { |
330 |
//this is the most accurate way to obtain total rows and columns... |
331 |
|
332 |
DiagramRootEditPart diagramRootEditPart = (DiagramRootEditPart) rootEditPart; |
333 |
PageBreakEditPart pageBreakEditPart = diagramRootEditPart |
334 |
.getPageBreakEditPart(); |
335 |
float fNumCols = ((PageBreaksFigure)pageBreakEditPart.getFigure()).getPageCount().y * |
336 |
(applyUserScale ? userScale : 1); |
337 |
float fNumRows = ((PageBreaksFigure)pageBreakEditPart.getFigure()).getPageCount().x * |
338 |
(applyUserScale ? userScale : 1); |
339 |
|
340 |
int numCols = (int) Math.ceil(fNumCols); |
341 |
int numRows = (int) Math.ceil(fNumRows); |
342 |
|
343 |
return new org.eclipse.draw2d.geometry.Point(numCols,numRows); |
344 |
} |
345 |
else { |
346 |
//otherwise, calculate manually... |
347 |
|
348 |
float fNumRows = (figureBounds.height * (applyUserScale ? userScale : 1)) |
349 |
/ pageSize.y; |
350 |
int numRows = (int) Math.ceil(fNumRows); |
351 |
|
352 |
float fNumCols = (figureBounds.width * (applyUserScale ? userScale : 1)) |
353 |
/ pageSize.x; |
354 |
int numCols = (int) Math.ceil(fNumCols); |
355 |
|
356 |
return new org.eclipse.draw2d.geometry.Point(numCols, numRows); |
357 |
} |
358 |
} |
359 |
|
360 |
/** |
361 |
* Prints to scale or prints to rows x columns pages |
362 |
*/ |
363 |
private void doPrintDiagram(DiagramEditPart dgrmEP, boolean loadedPreferences, IPreferenceStore fPreferences) { |
364 |
this.graphics.pushState(); |
365 |
if (isScaledPercent) { |
366 |
printToScale(dgrmEP, loadedPreferences, fPreferences); |
367 |
} else { |
368 |
printToPages(dgrmEP, loadedPreferences, fPreferences); |
369 |
} |
370 |
this.graphics.popState(); |
371 |
} |
372 |
|
373 |
private void initialize() { |
374 |
|
375 |
assert null != printer : "printer must be set"; //$NON-NLS-1$ |
376 |
|
377 |
//check for rtl orientation... |
378 |
int style = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell().getStyle(); |
379 |
if ((style & SWT.MIRRORED) != 0) |
380 |
this.gc = new GC(printer, SWT.RIGHT_TO_LEFT); |
381 |
else |
382 |
this.gc = new GC(printer); |
383 |
|
384 |
gc.setXORMode(false); |
385 |
|
386 |
this.swtGraphics = new SWTGraphics(gc); |
387 |
this.printerGraphics = createPrinterGraphics(swtGraphics); |
388 |
this.graphics = createMapModeGraphics(printerGraphics); |
389 |
this.graphics.scale(computePrinterDisplayScale()); |
390 |
|
391 |
this.logicalClientArea = this.graphics.getClip(new Rectangle( |
392 |
this.printer.getClientArea())); |
393 |
|
394 |
} |
395 |
|
396 |
/** |
397 |
* Usually, the printable area is less than the page. |
398 |
* This method returns the offset for each x margin and each y margin. |
399 |
* x margins are left and right |
400 |
* y margins are top and bottom |
401 |
* |
402 |
* We'll assume the left and right offsets are the same and the |
403 |
* top and bottom offsets are the same. |
404 |
* |
405 |
* @return Point with x and y offsets |
406 |
*/ |
407 |
protected Point getPrinterOffset() { |
408 |
if (printerOffset == null) { |
409 |
int offsetX = this.printer.getBounds().width |
410 |
- this.printer.getClientArea().width; |
411 |
int offsetY = this.printer.getBounds().height |
412 |
- this.printer.getClientArea().height; |
413 |
|
414 |
// assume half on each side |
415 |
offsetX = (int) (getMapMode() |
416 |
.DPtoLP((int) (offsetX / 2.0f * display_dpi.x / printer.getDPI().x)) / userScale); |
417 |
offsetY = (int) (getMapMode() |
418 |
.DPtoLP((int) (offsetY / 2.0f * display_dpi.y / printer.getDPI().y)) / userScale); |
419 |
|
420 |
printerOffset = new Point(offsetX, offsetY); |
421 |
} |
422 |
|
423 |
return printerOffset; |
424 |
} |
425 |
|
426 |
/** |
427 |
* Print the diagram figure using specified scale factor. |
428 |
* |
429 |
* @param dgrmEP the DiagramEditPart that will be printed |
430 |
* @param loadedPreferences true if existing prefs could be loaded |
431 |
* successfully, false if not and defaults are being used. This parameter |
432 |
* is important to obtain the correct page break bounds. |
433 |
* @param fPreferences the preferenceStore that could either contain |
434 |
* existing preferences or defaults |
435 |
*/ |
436 |
protected void printToScale(DiagramEditPart dgrmEP, boolean loadedPreferences, IPreferenceStore fPreferences) { |
437 |
|
438 |
assert null != printer : "printer must be set"; //$NON-NLS-1$ |
439 |
Rectangle figureBounds = PrintHelper.getPageBreakBounds(dgrmEP, loadedPreferences); |
440 |
org.eclipse.draw2d.geometry.Point pageBounds = PageInfoHelper.getPageSize(fPreferences, getMapMode()); |
441 |
|
442 |
//translate to offset initial figure position |
443 |
translated = new Point((int) (-figureBounds.x * userScale), (int) (-figureBounds.y * userScale)); |
444 |
|
445 |
//calculate the number of page rows and columns |
446 |
int numRows = 0, numCols = 0; |
447 |
|
448 |
PageMargins margins = PageInfoHelper.getPageMargins(fPreferences, getMapMode()); |
449 |
adjustMargins(margins, userScale, getPrinterOffset()); |
450 |
|
451 |
GC gc_ = new GC(Display.getDefault(),this.gc.getStyle()); |
452 |
gc_.setAntialias(this.gc.getAntialias()); |
453 |
|
454 |
FontData fontData = JFaceResources.getDefaultFont().getFontData()[0]; |
455 |
Font font = new Font(printer, fontData); |
456 |
|
457 |
org.eclipse.draw2d.geometry.Point pageCount = getPageCount(dgrmEP, figureBounds, pageBounds, true); |
458 |
numCols = pageCount.x; |
459 |
numRows = pageCount.y; |
460 |
|
461 |
//finalRow and finalColumn will be used if we are printing within a page range... |
462 |
int row = 1, col = 1, finalRow = 0, finalColumn = 0; |
463 |
|
464 |
if (this.printRangePageSelection) { |
465 |
//print only the pages specified in the page range... |
466 |
row = calculateRowFromPage(this.pageFrom, numCols); |
467 |
col = calculateColumnFromPage(this.pageFrom, numCols, row); |
468 |
|
469 |
finalRow = calculateRowFromPage(this.pageTo, numCols); |
470 |
finalColumn = calculateColumnFromPage(this.pageTo, numCols, finalRow); |
471 |
} |
472 |
|
473 |
try { |
474 |
//print the pages in row, column order |
475 |
for (; row <= numRows; row++) { |
476 |
for (; col <= numCols; col++) { |
477 |
printer.startPage(); |
478 |
drawPage(gc_, dgrmEP, fPreferences, figureBounds, margins, font, row, col); |
479 |
printer.endPage(); |
480 |
|
481 |
if (row == finalRow && col == finalColumn && this.printRangePageSelection == true) |
482 |
break; |
483 |
} |
484 |
|
485 |
if (row == finalRow && col == finalColumn && this.printRangePageSelection == true) |
486 |
break; |
487 |
|
488 |
col = 1; |
489 |
} |
490 |
} finally { |
491 |
//must dispose resources |
492 |
font.dispose(); |
493 |
gc_.dispose(); |
494 |
} |
495 |
} |
496 |
|
497 |
/** |
498 |
* Draw the header and footer |
499 |
* |
500 |
* @param gc_, |
501 |
* a graphics context that is not null which this method will use |
502 |
* for figuring ouyt the font's extent |
503 |
* @param figureBounds, |
504 |
* Rectangle with the bounds of the figure |
505 |
* @param rowIndex, |
506 |
* int |
507 |
* @param colIndex, |
508 |
* int |
509 |
*/ |
510 |
protected void drawHeaderAndFooter(GC gc_, DiagramEditPart dgrmEP, Rectangle figureBounds, |
511 |
Font font, int rowIndex, int colIndex) { |
512 |
|
513 |
int width = this.logicalClientArea.width; |
514 |
int height = this.logicalClientArea.height; |
515 |
|
516 |
this.graphics.pushState(); //draw text, don't make it too small or big |
517 |
this.graphics.setFont(font); |
518 |
|
519 |
this.graphics.scale(1.0f / userScale); |
520 |
this.graphics.translate(-translated.x, -translated.y); |
521 |
|
522 |
String headerOrFooter = HeaderAndFooterHelper.makeHeaderOrFooterString( |
523 |
WorkspaceViewerProperties.HEADER_PREFIX, rowIndex, colIndex, |
524 |
dgrmEP); |
525 |
|
526 |
this.graphics.drawText(headerOrFooter, |
527 |
getMapMode().DPtoLP(HeaderAndFooterHelper.LEFT_MARGIN_DP) |
528 |
+ (width - getMapMode().DPtoLP(gc_.textExtent(headerOrFooter).x)) |
529 |
/ 2, getMapMode().DPtoLP(HeaderAndFooterHelper.TOP_MARGIN_DP)); |
530 |
|
531 |
headerOrFooter = HeaderAndFooterHelper.makeHeaderOrFooterString( |
532 |
WorkspaceViewerProperties.FOOTER_PREFIX, rowIndex, colIndex, |
533 |
dgrmEP); |
534 |
|
535 |
this.graphics.drawText(headerOrFooter, |
536 |
getMapMode().DPtoLP(HeaderAndFooterHelper.LEFT_MARGIN_DP) |
537 |
+ (width - getMapMode().DPtoLP(gc_.textExtent(headerOrFooter).x)) |
538 |
/ 2, height - getMapMode().DPtoLP(HeaderAndFooterHelper.BOTTOM_MARGIN_DP)); |
539 |
|
540 |
this.graphics.popState(); //for drawing the text |
541 |
|
29 |
|
542 |
} |
30 |
/** |
543 |
|
31 |
* Basic page calculation operations have been factored out into this class. |
544 |
/** |
32 |
* This class was derived from the previous DiagramPrinter. |
545 |
* This method paints a portion of the diagram. (The area painted |
33 |
* |
546 |
* representing one page.) |
34 |
* @author James Bruck (jbruck) |
547 |
* |
35 |
*/ |
548 |
* @param gc_ a graphics context that is not null which this method will use |
36 |
public abstract class DiagramPrinter implements Runnable { |
549 |
* for figuring out the font's extent |
|
|
550 |
* @param dgrmEP the DiagramEditPart that will be printed |
551 |
* @param fPreferences the preferenceStore that could either contain |
552 |
* existing preferences or defaults |
553 |
* @param figureBounds the page break bounds we'll have to offset by |
554 |
* @param font the Font to print the header or footer with |
555 |
* @param rowIndex index of row we're printing |
556 |
* @param colIndex index of column we're priniting |
557 |
* to check if it is the first time the method is getting called for the current |
558 |
* print. |
559 |
*/ |
560 |
protected void drawPage(GC gc_, DiagramEditPart dgrmEP, |
561 |
IPreferenceStore fPreferences, Rectangle figureBounds, |
562 |
PageMargins margins, Font font, int rowIndex, int colIndex) { |
563 |
|
564 |
org.eclipse.draw2d.geometry.Point pageSize = PageInfoHelper |
565 |
.getPageSize(fPreferences, false, getMapMode()); |
566 |
boolean rtlEnabled = ((this.gc.getStyle() & SWT.MIRRORED) != 0); |
567 |
if (rtlEnabled) |
568 |
{ |
569 |
// draw everything on an offscreen image first and then draw that image |
570 |
// onto the printer gc...this takes care of certain drawing bugs. |
571 |
// This causes issues with printing resolution as it uses a display image |
572 |
// which is typically 72dpi |
573 |
// This code should be removed when a resolution to Bugzilla 162459 is found |
574 |
|
575 |
Image image = new Image(Display.getDefault(), getMapMode().LPtoDP(pageSize.x), getMapMode().LPtoDP(pageSize.y)); |
576 |
|
577 |
GC imgGC = new GC(image, (rtlEnabled) ? SWT.RIGHT_TO_LEFT : SWT.LEFT_TO_RIGHT); |
578 |
imgGC.setXORMode(false); |
579 |
|
580 |
SWTGraphics sg = new SWTGraphics(imgGC); |
581 |
|
582 |
//for scaling |
583 |
ScaledGraphics g1 = new ScaledGraphics(sg); |
584 |
|
585 |
//for himetrics and svg |
586 |
MapModeGraphics mmg = createMapModeGraphics(g1); |
587 |
|
588 |
//if mmg's font is null, gc.setFont will use a default font |
589 |
imgGC.setFont(mmg.getFont()); |
590 |
|
591 |
internalDrawPage(dgrmEP,figureBounds,fPreferences,margins,mmg,rowIndex, colIndex,true); |
592 |
|
593 |
this.graphics.pushState(); |
594 |
|
595 |
this.graphics.drawImage(image, 0, 0); |
596 |
|
597 |
this.graphics.popState(); |
598 |
|
599 |
//draw the header and footer after drawing the image to avoid getting the image getting drawn over them |
600 |
drawHeaderAndFooter(gc_, dgrmEP, figureBounds, font, rowIndex, colIndex); |
601 |
disposeImageVars(imgGC, image, sg, g1, mmg); |
602 |
} else { |
603 |
internalDrawPage(dgrmEP,figureBounds,fPreferences,margins,this.graphics,rowIndex, colIndex,false); |
604 |
//draw the header and footer after drawing the image to avoid getting the image getting drawn over them |
605 |
drawHeaderAndFooter(gc_, dgrmEP, figureBounds, font, rowIndex, colIndex); |
606 |
} |
607 |
} |
608 |
|
609 |
private void internalDrawPage(DiagramEditPart dgrmEP, |
610 |
Rectangle figureBounds, IPreferenceStore fPreferences, |
611 |
PageMargins margins, Graphics g, int rowIndex, int colIndex, |
612 |
boolean RTL_ENABLED) { |
613 |
org.eclipse.draw2d.geometry.Point pageSize = PageInfoHelper |
614 |
.getPageSize(fPreferences, false, getMapMode()); |
615 |
|
616 |
int width = pageSize.x, height = pageSize.y; |
617 |
|
618 |
g.pushState(); |
619 |
|
620 |
g.translate(translated.x, translated.y); |
621 |
g.scale(userScale); |
622 |
|
623 |
int translateX = -(width * (colIndex - 1)); |
624 |
int translateY = -(height * (rowIndex - 1)); |
625 |
|
626 |
int scaledTranslateX = (int) (translateX / userScale); |
627 |
int scaledTranslateY = (int) (translateY / userScale); |
628 |
|
629 |
int scaledWidth = (int) (width / userScale); |
630 |
int scaledHeight = (int) (height / userScale); |
631 |
|
632 |
if (RTL_ENABLED) { |
633 |
scaledTranslateX += (margins.left * (colIndex - 1)) |
634 |
+ (margins.right * (colIndex)); |
635 |
scaledTranslateY += ((margins.top * rowIndex) + (margins.bottom * (rowIndex - 1))); |
636 |
} else { |
637 |
scaledTranslateX += ((margins.left * colIndex) + (margins.right * (colIndex - 1))); |
638 |
scaledTranslateY += ((margins.top * rowIndex) + (margins.bottom * (rowIndex - 1))); |
639 |
} |
640 |
|
641 |
g.translate(scaledTranslateX, scaledTranslateY); |
642 |
|
643 |
Rectangle clip = new Rectangle( |
644 |
(scaledWidth - margins.left - margins.right) * (colIndex - 1) |
645 |
+ figureBounds.x, (scaledHeight - margins.bottom - margins.top) |
646 |
* (rowIndex - 1) + figureBounds.y, scaledWidth - margins.right |
647 |
- margins.left, scaledHeight - margins.top - margins.bottom); |
648 |
g.clipRect(clip); |
649 |
|
650 |
dgrmEP.getLayer(LayerConstants.PRINTABLE_LAYERS).paint(g); |
651 |
|
652 |
g.popState(); |
653 |
} |
654 |
|
37 |
|
655 |
/** |
38 |
protected Point display_dpi; |
656 |
* Print the diagram figure to fit the number and rows and columns |
39 |
protected Collection<Diagram> diagrams; |
657 |
* specified by the user. |
40 |
protected PreferencesHint preferencesHint; |
658 |
* |
41 |
protected IMapMode mapMode; |
659 |
* @param dgrmEP the DiagramEditPart that will be printed |
42 |
protected Point translated; |
660 |
* @param loadedPreferences true if existing prefs could be loaded |
43 |
|
661 |
* successfully, false if not and defaults are being used. This parameter |
44 |
protected float userScale; |
662 |
* is important to obtain the correct page break bounds. |
45 |
protected boolean isScaledPercent = false; |
663 |
* @param fPreferences the preferenceStore that could either contain |
46 |
protected boolean fitToPage = false; |
664 |
* existing preferences or defaults |
47 |
protected boolean printRangePageSelection = false; |
665 |
*/ |
48 |
|
666 |
protected void printToPages(DiagramEditPart dgrmEP, |
49 |
protected int pageFrom = 1, pageTo = 1; |
667 |
boolean loadedPreferences, IPreferenceStore fPreferences) { |
50 |
protected int rows = 1; |
668 |
assert null != printer : "printer must be set"; //$NON-NLS-1$ |
51 |
|
669 |
|
52 |
protected int columns = 1; |
670 |
Rectangle figureBounds = PrintHelper.getPageBreakBounds(dgrmEP, |
53 |
|
671 |
loadedPreferences); |
54 |
protected Graphics swtGraphics; |
672 |
|
55 |
protected Graphics graphics; |
673 |
PageMargins margins = PageInfoHelper.getPageMargins(fPreferences, getMapMode()); |
56 |
|
674 |
//do not include margins |
57 |
public DiagramPrinter(PreferencesHint preferencesHint, IMapMode mm) { |
675 |
org.eclipse.draw2d.geometry.Point pageBounds = PageInfoHelper |
58 |
super(); |
676 |
.getPageSize(fPreferences, getMapMode()); |
59 |
this.preferencesHint = preferencesHint; |
677 |
org.eclipse.draw2d.geometry.Point pageCount = getPageCount(dgrmEP, figureBounds, pageBounds, false); |
60 |
this.mapMode = mm; |
678 |
int numCols = pageCount.x; |
61 |
} |
679 |
int numRows = pageCount.y; |
62 |
|
680 |
|
63 |
/** |
681 |
float actualWidth = 0; |
64 |
* Obtains the total number of pages that span columns and rows |
682 |
float actualHeight = 0; |
65 |
* @param dgrmEP |
683 |
if (this.rows==1 && this.columns==1 && fitToPage){ |
66 |
* @return Point.x contains the total number of pages that span in a column |
684 |
figureBounds = dgrmEP.getChildrenBounds(); |
67 |
* Point.y contains the total number of pages that span in a row |
685 |
actualWidth = figureBounds.width; |
68 |
*/ |
686 |
actualHeight = figureBounds.height; |
69 |
protected org.eclipse.draw2d.geometry.Point getPageCount( |
687 |
}else { |
70 |
DiagramEditPart dgrmEP, Rectangle figureBounds, |
688 |
actualWidth = numCols * pageBounds.x; |
71 |
org.eclipse.draw2d.geometry.Point pageSize, boolean applyUserScale) { |
689 |
actualHeight = numRows * pageBounds.y; |
72 |
RootEditPart rootEditPart = dgrmEP.getRoot(); |
690 |
} |
73 |
|
691 |
|
74 |
if (rootEditPart instanceof DiagramRootEditPart) { |
692 |
int totalHeight = (this.rows * pageBounds.y); |
75 |
|
693 |
int totalWidth = (this.columns * pageBounds.x); |
76 |
DiagramRootEditPart diagramRootEditPart = (DiagramRootEditPart) rootEditPart; |
694 |
|
77 |
PageBreakEditPart pageBreakEditPart = diagramRootEditPart |
695 |
float vScale = totalHeight / actualHeight; |
78 |
.getPageBreakEditPart(); |
696 |
float hScale = totalWidth / actualWidth; |
79 |
|
697 |
|
80 |
float fNumCols = ((PageBreaksFigure) pageBreakEditPart.getFigure()) |
698 |
this.userScale = Math.min(hScale, vScale); |
81 |
.getPageCount().y |
699 |
|
82 |
* (applyUserScale ? userScale : 1); |
700 |
// translate to offset figure position |
83 |
|
701 |
translated = new Point((int) (-figureBounds.x * userScale), |
84 |
float fNumRows = ((PageBreaksFigure) pageBreakEditPart.getFigure()) |
702 |
(int) (-figureBounds.y * userScale)); |
85 |
.getPageCount().x |
703 |
|
86 |
* (applyUserScale ? userScale : 1); |
704 |
adjustMargins(margins, userScale, getPrinterOffset()); |
87 |
|
705 |
|
88 |
int numCols = (int) Math.ceil(fNumCols); |
706 |
GC gc_ = new GC(Display.getDefault()); |
89 |
int numRows = (int) Math.ceil(fNumRows); |
707 |
|
90 |
|
708 |
FontData fontData = JFaceResources.getDefaultFont().getFontData()[0]; |
91 |
return new org.eclipse.draw2d.geometry.Point(numCols, numRows); |
709 |
Font font = new Font(printer, fontData); |
92 |
|
710 |
|
93 |
} else { |
711 |
int row = 1, col = 1, finalRow = 0, finalColumn = 0; |
94 |
|
712 |
|
95 |
float fNumRows = (figureBounds.height * (applyUserScale ? userScale |
713 |
if (this.printRangePageSelection) { |
96 |
: 1)) |
714 |
//print only the pages specified in the page range |
97 |
/ pageSize.y; |
715 |
//this corresponds to the physical pages, not the print range of pages on one physical page. |
98 |
int numRows = (int) Math.ceil(fNumRows); |
716 |
row = calculateRowFromPage(this.pageFrom, this.columns); |
99 |
|
717 |
col = calculateColumnFromPage(this.pageFrom, this.columns, row); |
100 |
float fNumCols = (figureBounds.width * (applyUserScale ? userScale |
718 |
|
101 |
: 1)) |
719 |
finalRow = calculateRowFromPage(this.pageTo, this.columns); |
102 |
/ pageSize.x; |
720 |
finalColumn = calculateColumnFromPage(this.pageTo, this.columns, finalRow); |
103 |
int numCols = (int) Math.ceil(fNumCols); |
721 |
} |
104 |
|
722 |
|
105 |
return new org.eclipse.draw2d.geometry.Point(numCols, numRows); |
723 |
try { |
106 |
} |
724 |
// print the pages in row, column order |
107 |
} |
725 |
for (; row <= rows; row++) { |
108 |
|
726 |
for (; col <= columns; col++) { |
109 |
/** |
727 |
printer.startPage(); |
110 |
* Calculates the row in a grid, given a page number. |
728 |
drawPage(gc_, dgrmEP, fPreferences, figureBounds, margins, |
111 |
* | 1 | 2 | 3 | |
729 |
font, row, col); |
112 |
* | 4 | 5 | 6 | |
730 |
printer.endPage(); |
113 |
* | 7 | 8 | 9 | |
731 |
|
114 |
* |
732 |
if (row == finalRow && col == finalColumn && this.printRangePageSelection == true) |
115 |
* Given pageNum=5 and totalNumColumns=3, will return 2 |
733 |
break; |
116 |
* (2nd row). |
734 |
} |
117 |
* |
735 |
|
118 |
* @param pageNum the page number in the grid. |
736 |
if (row == finalRow && col == finalColumn && this.printRangePageSelection == true) |
119 |
* @param totalNumColumns total number of columns of the grid. |
737 |
break; |
120 |
* @return row number corresponding to the page number. |
738 |
|
121 |
*/ |
739 |
col = 1; |
122 |
protected int calculateRowFromPage(int pageNum, int totalNumColumns) { |
740 |
} |
123 |
int row = pageNum / totalNumColumns; |
741 |
} finally { |
124 |
if (pageNum % totalNumColumns != 0) { |
742 |
// must dispose resources |
125 |
row++; |
743 |
font.dispose(); |
126 |
} |
744 |
gc_.dispose(); |
127 |
return row; |
745 |
} |
128 |
} |
746 |
} |
129 |
|
|
|
130 |
/** |
131 |
* Calculates the column in a grid, given a page number. |
132 |
* | 1 | 2 | 3 | |
133 |
* | 4 | 5 | 6 | |
134 |
* | 7 | 8 | 9 | |
135 |
* |
136 |
* Given pageNum=5 and totalNumColumns=3, will return 2 |
137 |
* (2nd column). |
138 |
* |
139 |
* @param pageNum the page number in the grid. |
140 |
* @param totalNumColumns total number of columns of the grid. |
141 |
* @param cRow the corresponding row of the page number. |
142 |
* @return row number corresponding to the page number. |
143 |
*/ |
144 |
protected int calculateColumnFromPage(int pageNum, int totalNumColumns, |
145 |
int cRow) { |
146 |
|
147 |
return (pageNum - ((cRow - 1) * totalNumColumns)); |
148 |
} |
149 |
|
150 |
|
151 |
/** |
152 |
* Disposes of the resources. |
153 |
*/ |
154 |
protected void dispose() { |
155 |
if (this.graphics != null) { |
156 |
try { |
157 |
this.graphics.dispose(); |
158 |
} catch (NullPointerException e) { |
159 |
//do nothing |
160 |
} finally { |
161 |
this.graphics = null; |
162 |
} |
163 |
} |
164 |
|
165 |
if (this.swtGraphics != null) { |
166 |
try { |
167 |
this.swtGraphics.dispose(); |
168 |
} catch (NullPointerException e) { |
169 |
//do nothing |
170 |
} finally { |
171 |
this.swtGraphics = null; |
172 |
} |
173 |
} |
174 |
} |
747 |
|
175 |
|
748 |
/** |
176 |
/** |
749 |
* Return scale factor between printer and display. |
|
|
750 |
* |
751 |
* @return float |
752 |
*/ |
753 |
private float computePrinterDisplayScale() { |
754 |
assert null != printer : "printer must be set"; //$NON-NLS-1$ |
755 |
assert null != display_dpi : "display_dpi must be set"; //$NON-NLS-1$ |
756 |
|
757 |
Point dpi = printer.getDPI(); |
758 |
float scale = dpi.x / (float) display_dpi.x; |
759 |
|
760 |
return scale; |
761 |
} |
762 |
|
763 |
/** |
764 |
* Disposes of the resources. |
765 |
*/ |
766 |
private void dispose() { |
767 |
if (this.graphics != null) { |
768 |
try { |
769 |
this.graphics.dispose(); |
770 |
} |
771 |
catch (NullPointerException e) { |
772 |
//do nothing |
773 |
} |
774 |
finally { |
775 |
this.graphics = null; |
776 |
} |
777 |
} |
778 |
|
779 |
if (this.printerGraphics != null) { |
780 |
try { |
781 |
this.printerGraphics.dispose(); |
782 |
} |
783 |
catch (NullPointerException e) { |
784 |
//do nothing |
785 |
} |
786 |
finally { |
787 |
this.printerGraphics = null; |
788 |
} |
789 |
} |
790 |
|
791 |
if (this.swtGraphics != null) { |
792 |
try { |
793 |
this.swtGraphics.dispose(); |
794 |
} |
795 |
catch (NullPointerException e) { |
796 |
//do nothing |
797 |
} |
798 |
finally { |
799 |
this.swtGraphics = null; |
800 |
} |
801 |
} |
802 |
|
803 |
if (this.gc != null) { |
804 |
try { |
805 |
this.gc.dispose(); |
806 |
} |
807 |
catch (NullPointerException e) { |
808 |
//do nothing |
809 |
} |
810 |
finally { |
811 |
this.gc = null; |
812 |
} |
813 |
} |
814 |
|
815 |
//reset the printer offset, just in case the next diagram to be printed |
816 |
//uses a different map mode. |
817 |
printerOffset = null; |
818 |
|
819 |
} |
820 |
|
821 |
private void disposeImageVars(GC imgGC, Image image, SWTGraphics sg, |
822 |
ScaledGraphics g1, MapModeGraphics mmg) { |
823 |
|
824 |
if (mmg != null) { |
825 |
try { |
826 |
mmg.dispose(); |
827 |
} |
828 |
catch (NullPointerException e) { |
829 |
//do nothing |
830 |
} |
831 |
finally { |
832 |
mmg = null; |
833 |
} |
834 |
} |
835 |
|
836 |
if (g1 != null) { |
837 |
try { |
838 |
g1.dispose(); |
839 |
} |
840 |
catch (NullPointerException e) { |
841 |
//do nothing |
842 |
} |
843 |
finally { |
844 |
g1 = null; |
845 |
} |
846 |
} |
847 |
|
848 |
if (sg != null) { |
849 |
try { |
850 |
sg.dispose(); |
851 |
} |
852 |
catch (NullPointerException e) { |
853 |
//do nothing |
854 |
} |
855 |
finally { |
856 |
sg = null; |
857 |
} |
858 |
} |
859 |
|
860 |
if (imgGC != null) { |
861 |
try { |
862 |
imgGC.dispose(); |
863 |
} |
864 |
catch (NullPointerException e) { |
865 |
//do nothing |
866 |
} |
867 |
finally { |
868 |
imgGC = null; |
869 |
} |
870 |
} |
871 |
|
872 |
if (image != null) { |
873 |
try { |
874 |
image.dispose(); |
875 |
} |
876 |
catch (NullPointerException e) { |
877 |
//do nothing |
878 |
} |
879 |
finally { |
880 |
image = null; |
881 |
} |
882 |
} |
883 |
} |
884 |
|
885 |
/** |
886 |
* Creates the <code>MapModeGraphics</code>. |
177 |
* Creates the <code>MapModeGraphics</code>. |
887 |
* |
178 |
* |
888 |
* @param theGraphics |
179 |
* @param theGraphics |
Lines 893-949
Link Here
|
893 |
return new MapModeGraphics(theGraphics, getMapMode()); |
184 |
return new MapModeGraphics(theGraphics, getMapMode()); |
894 |
} |
185 |
} |
895 |
|
186 |
|
896 |
/** |
187 |
public void setPrintRangePages(int pageFrom, int pageTo) { |
897 |
* Creates the <code>PrinterGraphics</code>. |
188 |
assert pageFrom > 0 : "From page in print range page selection must be bigger than zero."; //$NON-NLS-1$ |
898 |
* |
189 |
assert (pageTo > 0 && pageTo >= pageFrom) : "To page in print range page selection must be bigger than zero and from page."; //$NON-NLS-1$ |
899 |
* @param theGraphics |
190 |
this.pageFrom = pageFrom; |
900 |
* the <code>Graphics</code> object |
191 |
this.pageTo = pageTo; |
901 |
* @return the new <code>PrinterGraphics</code> |
192 |
} |
902 |
*/ |
193 |
|
903 |
protected PrinterGraphics createPrinterGraphics(Graphics theGraphics) { |
194 |
public Point getDisplayDPI() { |
904 |
return new PrinterGraphics(theGraphics, printer, true); |
195 |
return display_dpi; |
905 |
} |
196 |
} |
906 |
|
197 |
|
907 |
/** |
198 |
public void setDisplayDPI(Point display_dpi) { |
908 |
* Gets the preferences hint that is to be used to find the appropriate |
199 |
this.display_dpi = display_dpi; |
909 |
* preference store from which to retrieve diagram preference values. The |
200 |
} |
910 |
* preference hint is mapped to a preference store in the preference |
201 |
|
911 |
* registry <@link DiagramPreferencesRegistry>. |
202 |
public PreferencesHint getPreferencesHint() { |
912 |
* |
203 |
return preferencesHint; |
913 |
* @return the preferences hint |
204 |
} |
914 |
*/ |
205 |
|
915 |
protected PreferencesHint getPreferencesHint() { |
206 |
public void setPreferencesHint(PreferencesHint preferencesHint) { |
916 |
return preferencesHint; |
207 |
this.preferencesHint = preferencesHint; |
917 |
} |
208 |
} |
918 |
|
209 |
|
919 |
/** |
210 |
public IMapMode getMapMode() { |
920 |
* Adjust the given PageMargins by the scale and offset |
211 |
return mapMode; |
921 |
* |
212 |
} |
922 |
* @param margins PageMargins to adjust |
213 |
|
923 |
* @param scale margins will be scaled by this amount |
214 |
public void setMapMode(IMapMode mm) { |
924 |
* @param offset to adjust margins by |
215 |
this.mapMode = mm; |
925 |
*/ |
216 |
} |
926 |
protected void adjustMargins(PageMargins margins, float scale, Point offset) { |
217 |
|
927 |
//scale |
218 |
public Point getTranslated() { |
928 |
margins.left /= scale; |
219 |
return translated; |
929 |
margins.top /= scale; |
220 |
} |
930 |
margins.right /= scale; |
221 |
|
931 |
margins.bottom /= scale; |
222 |
public void setTranslated(Point translated) { |
932 |
|
223 |
this.translated = translated; |
933 |
//offsets |
224 |
} |
934 |
margins.left -= offset.x; |
225 |
|
935 |
margins.right += offset.x; |
226 |
public float getUserScale() { |
936 |
margins.top -= offset.y; |
227 |
return userScale; |
937 |
margins.bottom += offset.y; |
228 |
} |
938 |
|
229 |
|
939 |
// this is more readable than doing Math.min for all the above |
230 |
public void setScaledPercent(int scalePercent) { |
940 |
if (margins.left < 0) |
231 |
this.isScaledPercent = true; |
941 |
margins.left = 0; |
232 |
this.userScale = (scalePercent) / 100.0f; |
942 |
if (margins.right < 0) |
233 |
} |
943 |
margins.right = 0; |
234 |
|
944 |
if (margins.top < 0) |
235 |
public void setScaledPercent(boolean isScaledPercent) { |
945 |
margins.top = 0; |
236 |
this.isScaledPercent = isScaledPercent; |
946 |
if (margins.bottom < 0) |
237 |
} |
947 |
margins.bottom = 0; |
238 |
|
948 |
} |
239 |
public boolean isFitToPage() { |
949 |
} |
240 |
return fitToPage; |
|
|
241 |
} |
242 |
|
243 |
public void setFitToPage(boolean fitToPage) { |
244 |
this.fitToPage = fitToPage; |
245 |
} |
246 |
|
247 |
public boolean isPrintRangePageSelection() { |
248 |
return printRangePageSelection; |
249 |
} |
250 |
|
251 |
public void setPrintRangePageSelection(boolean printRangePageSelection) { |
252 |
this.printRangePageSelection = printRangePageSelection; |
253 |
} |
254 |
|
255 |
public int getPageFrom() { |
256 |
return pageFrom; |
257 |
} |
258 |
|
259 |
public void setPageFrom(int pageFrom) { |
260 |
this.pageFrom = pageFrom; |
261 |
} |
262 |
|
263 |
public int getPageTo() { |
264 |
return pageTo; |
265 |
} |
266 |
|
267 |
public void setPageTo(int pageTo) { |
268 |
this.pageTo = pageTo; |
269 |
} |
270 |
|
271 |
public int getRows() { |
272 |
return rows; |
273 |
} |
274 |
|
275 |
public void setRows(int rows) { |
276 |
this.rows = rows; |
277 |
} |
278 |
|
279 |
public int getColumns() { |
280 |
return columns; |
281 |
} |
282 |
|
283 |
public void setColumns(int columns) { |
284 |
this.columns = columns; |
285 |
} |
286 |
|
287 |
public Graphics getSwtGraphics() { |
288 |
return swtGraphics; |
289 |
} |
290 |
|
291 |
public void setSwtGraphics(Graphics swtGraphics) { |
292 |
this.swtGraphics = swtGraphics; |
293 |
} |
294 |
|
295 |
public Graphics getGraphics() { |
296 |
return graphics; |
297 |
} |
298 |
|
299 |
public void setGraphics(Graphics graphics) { |
300 |
this.graphics = graphics; |
301 |
} |
302 |
|
303 |
public void setDiagrams(Collection<Diagram> diagrams) { |
304 |
this.diagrams = diagrams; |
305 |
} |
306 |
|
307 |
public Collection<Diagram> getDiagrams() { |
308 |
return diagrams; |
309 |
} |
310 |
|
311 |
} |