Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 19602 | Differences between
and this patch

Collapse All | Expand All

(-)Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledText.java (-4 / +280 lines)
Lines 164-169 Link Here
164
		IS_GTK = "gtk".equals(platform);
164
		IS_GTK = "gtk".equals(platform);
165
		IS_MOTIF = "motif".equals(platform);
165
		IS_MOTIF = "motif".equals(platform);
166
	}
166
	}
167
	
168
	/**
169
	 * This class' definition must be kept in sync with
170
	 * <code>org.eclipse.swt.custom.StyledTextPrintMarginDecorator</code>. This
171
	 * class is used to contain all the decoration information after widget to
172
	 * printer conversion.
173
	 */
174
	static class ConvertedPrintMarginDecorator {
175
		public int alignment;
176
177
		public int gutter;
178
179
		public String[] marginText;
180
181
		public TextStyle marginTextStyle;
182
183
		// This field is calculated and contains the horizontal coordinates
184
		// of the margin.
185
		public Rectangle marginRect;
186
187
	}
167
188
168
	/**
189
	/**
169
	 * The Printing class implements printing of a range of text.
190
	 * The Printing class implements printing of a range of text.
Lines 194-199 Link Here
194
		Point selection = null;					// selected text
215
		Point selection = null;					// selected text
195
		boolean mirrored;						// indicates the printing gc should be mirrored
216
		boolean mirrored;						// indicates the printing gc should be mirrored
196
		int lineSpacing;
217
		int lineSpacing;
218
		ConvertedPrintMarginDecorator leftPrintDecorator = null;
219
		ConvertedPrintMarginDecorator rightPrintDecorator = null;
220
		TextStyle defaultMarginStyle = null;
197
221
198
	/**
222
	/**
199
	 * Creates an instance of <class>Printing</class>.
223
	 * Creates an instance of <class>Printing</class>.
Lines 269-275 Link Here
269
		Point screenDPI = styledText.getDisplay().getDPI();
293
		Point screenDPI = styledText.getDisplay().getDPI();
270
		Point printerDPI = printer.getDPI();
294
		Point printerDPI = printer.getDPI();
271
		resources = new Hashtable ();
295
		resources = new Hashtable ();
296
		// Prepare to convert widget margin decorators to print decorators  
297
		StyledTextPrintMarginDecorator leftWidgetDecorator = null;
298
		StyledTextPrintMarginDecorator rightWidgetDecorator = null;
299
		if (mirrored) {
300
			leftWidgetDecorator = printOptions.printTrailMarginDecorator;
301
			rightWidgetDecorator = printOptions.printLeadMarginDecorator;
302
		} else {
303
			leftWidgetDecorator = printOptions.printLeadMarginDecorator;
304
			rightWidgetDecorator = printOptions.printTrailMarginDecorator;
305
		}
306
		// Convert left decorator
307
		boolean hasLeftMarginText = false;
308
		if (leftWidgetDecorator != null) {
309
			hasLeftMarginText = true;
310
			// Left margin alignment conversion
311
			leftPrintDecorator = new ConvertedPrintMarginDecorator();
312
			leftPrintDecorator.alignment = leftWidgetDecorator.getAlignment();
313
			switch (leftPrintDecorator.alignment) {
314
			case StyledTextPrintMarginDecorator.FLOAT_INWARD:
315
			case StyledTextPrintMarginDecorator.FORCE_RIGHT:
316
				leftPrintDecorator.alignment = SWT.RIGHT;
317
				break;
318
			case StyledTextPrintMarginDecorator.FLOAT_OUTWARD:
319
			case StyledTextPrintMarginDecorator.FORCE_LEFT:
320
				leftPrintDecorator.alignment = SWT.LEFT;
321
				break;
322
			case StyledTextPrintMarginDecorator.CENTER:
323
				leftPrintDecorator.alignment = SWT.CENTER;
324
			default:
325
				break;
326
			}
327
			convertRemainingDecorator(leftWidgetDecorator, screenDPI, leftPrintDecorator, printerDPI, lineCount, styledText);
328
		}
329
		// Convert right decorator
330
		boolean hasRightMarginText = false;
331
		if (rightWidgetDecorator != null) {
332
			hasRightMarginText = true;
333
			// Right margin alignment conversion.
334
			rightPrintDecorator = new ConvertedPrintMarginDecorator();
335
			rightPrintDecorator.alignment = rightWidgetDecorator.getAlignment();
336
			switch (rightPrintDecorator.alignment) {
337
			case StyledTextPrintMarginDecorator.FLOAT_INWARD:
338
			case StyledTextPrintMarginDecorator.FORCE_LEFT:
339
				rightPrintDecorator.alignment = SWT.LEFT;
340
				break;
341
			case StyledTextPrintMarginDecorator.FLOAT_OUTWARD:
342
			case StyledTextPrintMarginDecorator.FORCE_RIGHT:
343
				rightPrintDecorator.alignment = SWT.RIGHT;
344
				break;
345
			case StyledTextPrintMarginDecorator.CENTER:
346
				rightPrintDecorator.alignment = SWT.CENTER;
347
			default:
348
				break;
349
			}
350
			convertRemainingDecorator(rightWidgetDecorator, screenDPI, rightPrintDecorator, printerDPI, lineCount, styledText);
351
		}
272
		for (int i = 0; i < lineCount; i++) {
352
		for (int i = 0; i < lineCount; i++) {
353
			// Get margin text
354
			if (hasLeftMarginText)
355
				leftPrintDecorator.marginText[i] = leftWidgetDecorator.getMarginText(i);
356
			if (hasRightMarginText)
357
				rightPrintDecorator.marginText[i] = rightWidgetDecorator.getMarginText(i);
273
			Color color = printerRenderer.getLineBackground(i, null);
358
			Color color = printerRenderer.getLineBackground(i, null);
274
			if (color != null) {
359
			if (color != null) {
275
				if (printOptions.printLineBackground) {
360
				if (printOptions.printLineBackground) {
Lines 340-345 Link Here
340
		lineSpacing = styledText.lineSpacing * printerDPI.y / screenDPI.y;
425
		lineSpacing = styledText.lineSpacing * printerDPI.y / screenDPI.y;
341
	}
426
	}
342
	/**
427
	/**
428
	 * Creates and returns a text style based on the font and foreground
429
	 * settings.
430
	 * @param styledText the StyledText control being printed
431
	 * @return the default margin text style
432
	 */
433
	TextStyle getDefaultMarginStyle(StyledText styledText) {
434
		if (defaultMarginStyle == null) {
435
			defaultMarginStyle = new TextStyle(styledText.getFont(),
436
				styledText.getForeground(), null);
437
			convertTextStyle(defaultMarginStyle, null, null, null); // null to avoid infinite recursion
438
		}
439
		return defaultMarginStyle;
440
	}
441
	/**
442
	 * Converts a TextStyle from widget appropriate values to printer
443
	 * appropriate values. The passed style is converted in place. The resources
444
	 * cache is utilized and updated.
445
	 * 
446
	 * @param textStyle the text style to convert
447
	 * @param styledText a styled text widget for getting defaults
448
	 * @param screenDPI the x and y DPI for the screen (if null no rise or glyph metric conversion performed)
449
	 * @param printerDPI the x and y DPI for the printer (if null no rise or glyph metric conversion performed)
450
	 */
451
	void convertTextStyle(TextStyle textStyle, StyledText styledText, Point screenDPI, Point printerDPI) {
452
		if (resources == null)
453
			resources = new Hashtable();
454
		if (textStyle.background != null) {
455
			Color printerColor = (Color)resources.get(textStyle.background);
456
			if (printerColor == null) {
457
				printerColor = new Color (printer, textStyle.background.getRGB());
458
				resources.put(textStyle.background, printerColor); 
459
			}
460
			textStyle.background = printerColor;
461
		}
462
		if (textStyle.foreground == null) {
463
			if (styledText != null)
464
				textStyle.foreground = getDefaultMarginStyle(styledText).foreground;
465
		} else {
466
			Color printerColor = (Color)resources.get(textStyle.foreground);
467
			if (printerColor == null) {
468
				printerColor = new Color (printer, textStyle.foreground.getRGB());
469
				resources.put(textStyle.foreground, printerColor); 
470
			}
471
			textStyle.foreground = printerColor;
472
		}
473
		if (textStyle.font == null) {
474
			if (styledText != null)
475
				textStyle.font = getDefaultMarginStyle(styledText).font;
476
		} else {
477
			Font printerFont = (Font)resources.get(textStyle.font);
478
			if (printerFont == null) {
479
				printerFont = new Font (printer, textStyle.font.getFontData());
480
				resources.put(textStyle.font, printerFont);					
481
			}
482
			textStyle.font = printerFont;
483
		}
484
		if ((screenDPI != null) && (printerDPI != null)) {
485
			textStyle.rise = textStyle.rise * printerDPI.y / screenDPI.y;
486
			GlyphMetrics metrics = textStyle.metrics;
487
			if (metrics != null) {
488
				metrics.ascent = metrics.ascent * printerDPI.y / screenDPI.y;
489
				metrics.descent = metrics.descent * printerDPI.y / screenDPI.y;
490
				metrics.width = metrics.width * printerDPI.x / screenDPI.x;
491
			}
492
		}
493
	}
494
	/**
495
	 * Converts the widget decorator to a print decorator except for the
496
	 * alignment. That must be handled separately.
497
	 * 
498
	 * @param widgetDecorator the widget decorator to convert
499
	 * @param screenDPI the screen DPI
500
	 * @param printDecorator the target print decorator
501
	 * @param printerDPI the printer DPI
502
	 * @param lineCount number of lines being printed
503
	 * @param styledText the widget
504
	 */
505
	void convertRemainingDecorator(
506
			StyledTextPrintMarginDecorator widgetDecorator,
507
			Point screenDPI, ConvertedPrintMarginDecorator printDecorator,
508
			Point printerDPI, int lineCount, StyledText styledText) {
509
		// Gutter conversion
510
		printDecorator.gutter = widgetDecorator.getGutter() * printerDPI.x / screenDPI.x;
511
		// Prepare for margin text acquisition
512
		printDecorator.marginText = new String[lineCount];
513
		// Style conversion
514
		printDecorator.marginTextStyle = widgetDecorator.getMarginTextStyle();
515
		if (printDecorator.marginTextStyle == null)
516
			printDecorator.marginTextStyle = getDefaultMarginStyle(styledText);
517
		else
518
			convertTextStyle(printDecorator.marginTextStyle, styledText,
519
					screenDPI, printerDPI);
520
	}
521
	/**
343
	 * Copies the text of the specified <class>StyledTextContent</class>.
522
	 * Copies the text of the specified <class>StyledTextContent</class>.
344
	 * </p>
523
	 * </p>
345
	 * @param original the <class>StyledTextContent</class> to copy.
524
	 * @param original the <class>StyledTextContent</class> to copy.
Lines 394-407 Link Here
394
		// one inch margin around text
573
		// one inch margin around text
395
		clientArea.x = dpi.x + trim.x; 				
574
		clientArea.x = dpi.x + trim.x; 				
396
		clientArea.y = dpi.y + trim.y;
575
		clientArea.y = dpi.y + trim.y;
397
		clientArea.width -= (clientArea.x + trim.width);
576
		// Code in the if branch is the old code for calculating the
398
		clientArea.height -= (clientArea.y + trim.height); 
577
		// right and bottom margin setting.  It does NOT leave a one
578
		// inch margin as the comment above suggests.  It leaves smaller
579
		// margins.  When implementing margin decoration, I did not want
580
		// to change existing behavior, so if there is no right margin
581
		// decoration, continue to use the old incorrect calculation.
582
		// Otherwise, use a correct calculation in order to leave room
583
		// on the right for the right margin decoration.
584
		if (rightPrintDecorator == null) {
585
			clientArea.width -= (clientArea.x + trim.width);
586
			clientArea.height -= (clientArea.y + trim.height); 
587
		} else {
588
			Rectangle bounds = printer.getBounds();
589
			clientArea.width = bounds.width - (dpi.x * 2);
590
			clientArea.height = bounds.height - (dpi.y * 2);
591
		}
592
		
593
		// Calculate margin rectangles.
594
		if (leftPrintDecorator != null) {
595
			leftPrintDecorator.marginRect = new Rectangle(0, 0, clientArea.x - leftPrintDecorator.gutter, 0);
596
		}
597
		if (rightPrintDecorator != null) {
598
			rightPrintDecorator.marginRect = new Rectangle(clientArea.x + clientArea.width + rightPrintDecorator.gutter, 0, 0, 0);
599
			rightPrintDecorator.marginRect.width = pageWidth - rightPrintDecorator.marginRect.x;
600
		}
399
601
400
		int style = mirrored ? SWT.RIGHT_TO_LEFT : SWT.LEFT_TO_RIGHT;
602
		int style = mirrored ? SWT.RIGHT_TO_LEFT : SWT.LEFT_TO_RIGHT;
401
		gc = new GC(printer, style);
603
		gc = new GC(printer, style);
402
		gc.setFont(printerFont);
604
		gc.setFont(printerFont);
403
		printerRenderer.setFont(printerFont, tabLength);
605
		printerRenderer.setFont(printerFont, tabLength);
404
		int lineHeight = printerRenderer.getLineHeight();
606
		int lineHeight = printerRenderer.getLineHeight();
607
		// TODO is shrinking the client area (increasing the top and bottom
608
		// margin size) the right way to acquire space for the header and
609
		// footer?  These should probably be printed in the existing margin.
405
		if (printOptions.header != null) {
610
		if (printOptions.header != null) {
406
			clientArea.y += lineHeight * 2;
611
			clientArea.y += lineHeight * 2;
407
			clientArea.height -= lineHeight * 2;
612
			clientArea.height -= lineHeight * 2;
Lines 438-443 Link Here
438
		int page = startPage;
643
		int page = startPage;
439
		int pageBottom = clientArea.y + clientArea.height;
644
		int pageBottom = clientArea.y + clientArea.height;
440
		int orientation =  gc.getStyle() & (SWT.RIGHT_TO_LEFT | SWT.LEFT_TO_RIGHT);
645
		int orientation =  gc.getStyle() & (SWT.RIGHT_TO_LEFT | SWT.LEFT_TO_RIGHT);
646
		// Create text layout objects suitable for all margin text entries.
647
		TextLayout leftMarginLayout = null;
648
		if (leftPrintDecorator != null) {
649
			leftMarginLayout = new TextLayout(printer);
650
			leftMarginLayout.setAlignment(leftPrintDecorator.alignment);
651
			leftMarginLayout.setFont(leftPrintDecorator.marginTextStyle.font);
652
			//TODO verify orientation setting
653
			if (mirrored) leftMarginLayout.setOrientation(SWT.RIGHT_TO_LEFT);
654
			leftMarginLayout.setWidth(leftPrintDecorator.marginRect.width);
655
		}
656
		TextLayout rightMarginLayout = null;
657
		if (rightPrintDecorator != null) {
658
			rightMarginLayout = new TextLayout(printer);
659
			rightMarginLayout.setAlignment(rightPrintDecorator.alignment);
660
			rightMarginLayout.setFont(rightPrintDecorator.marginTextStyle.font);
661
			//TODO verify orientation setting
662
			if (mirrored) rightMarginLayout.setOrientation(SWT.RIGHT_TO_LEFT);
663
			rightMarginLayout.setWidth(rightPrintDecorator.marginRect.width);
664
		}
441
		
665
		
442
		
666
		
443
		for (int i = startLine; i <= endLine && page <= endPage; i++) {
667
		for (int i = startLine; i <= endLine && page <= endPage; i++) {
Lines 450-455 Link Here
450
			int paragraphBottom = paintY + layout.getBounds().height; 
674
			int paragraphBottom = paintY + layout.getBounds().height; 
451
			if (paragraphBottom <= pageBottom) {
675
			if (paragraphBottom <= pageBottom) {
452
				//normal case, the whole paragraph fits in the current page
676
				//normal case, the whole paragraph fits in the current page
677
				printMarginDecoration(i, paintY, layout, leftMarginLayout, leftPrintDecorator);
678
				printMarginDecoration(i, paintY, layout, rightMarginLayout, rightPrintDecorator);
453
				printLine(paintX, paintY, gc, foreground, lineBackground, layout);
679
				printLine(paintX, paintY, gc, foreground, lineBackground, layout);
454
				paintY = paragraphBottom;
680
				paintY = paragraphBottom;
455
			} else {
681
			} else {
Lines 467-476 Link Here
467
						printer.startPage();
693
						printer.startPage();
468
						printDecoration(page, true);
694
						printDecoration(page, true);
469
						paintY = clientArea.y;
695
						paintY = clientArea.y;
696
						printMarginDecoration(i, paintY, layout, leftMarginLayout, leftPrintDecorator);
697
						printMarginDecoration(i, paintY, layout, rightMarginLayout, rightPrintDecorator);
470
						printLine(paintX, paintY, gc, foreground, lineBackground, layout);
698
						printLine(paintX, paintY, gc, foreground, lineBackground, layout);
471
						paintY += layout.getBounds().height;
699
						paintY += layout.getBounds().height;
472
					}
700
					}
473
				} else {
701
				} else {
702
					printMarginDecoration(i, paintY, layout, leftMarginLayout, leftPrintDecorator);
703
					printMarginDecoration(i, paintY, layout, rightMarginLayout, rightPrintDecorator);
474
					//draw paragraph top in the current page and paragraph bottom in the next
704
					//draw paragraph top in the current page and paragraph bottom in the next
475
					gc.setClipping(paintX, paintY, clientArea.width, paragraphBottom - paintY);
705
					gc.setClipping(paintX, paintY, clientArea.width, paragraphBottom - paintY);
476
					printLine(paintX, paintY, gc, foreground, lineBackground, layout);
706
					printLine(paintX, paintY, gc, foreground, lineBackground, layout);
Lines 481-489 Link Here
481
						printer.startPage();
711
						printer.startPage();
482
						printDecoration(page, true);
712
						printDecoration(page, true);
483
						paintY = clientArea.y;
713
						paintY = clientArea.y;
484
						int height = layout.getBounds().height - paragraphBottom;
714
						// This old line was wrong.  paragraphBottom holds the bottom offset
715
						// of what was just printed on the previous page.  This calculation
716
						// leads to a large negative number.
717
						//int height = layout.getBounds().height - paragraphBottom;
718
						// Here is the correction (lineCount holds the number of lines to be printed on the new page).
719
						int totalHeight = layout.getBounds().height;
720
						int height = (int)(totalHeight * ((float)lineCount / layout.getLineCount()));
485
						gc.setClipping(paintX, paintY, clientArea.width, height);
721
						gc.setClipping(paintX, paintY, clientArea.width, height);
486
						printLine(paintX, paintY, gc, foreground, lineBackground, layout);
722
						// Also needed to adjust the y print point upward.
723
						//printLine(paintX, paintY, gc, foreground, lineBackground, layout);
724
						printLine(paintX, paintY - (totalHeight - height), gc, foreground, lineBackground, layout);
487
						paintY += height;
725
						paintY += height;
488
					}
726
					}
489
					gc.setClipping((Rectangle)null);
727
					gc.setClipping((Rectangle)null);
Lines 496-503 Link Here
496
			printDecoration(page, false);
734
			printDecoration(page, false);
497
			printer.endPage();
735
			printer.endPage();
498
		}
736
		}
737
		if (leftMarginLayout != null) leftMarginLayout.dispose();
738
		if (rightMarginLayout != null) rightMarginLayout.dispose();
499
	}
739
	}
500
	/**
740
	/**
741
	 * Print given margin decoration. Nothing is printed if any of lineLayout,
742
	 * marginLayout and decorator are null.
743
	 * 
744
	 * @param line the line being printed
745
	 * @param lineY the y coordinate of the line
746
	 * @param lineLayout the text layout for the line
747
	 * @param marginLayout the text layout for the margin
748
	 * @param decorator the converted decorator for the margin
749
	 */
750
		void printMarginDecoration(int line, int lineY, TextLayout lineLayout,
751
				TextLayout marginLayout, ConvertedPrintMarginDecorator decorator) {
752
			if ((lineLayout != null) && (marginLayout != null)
753
					&& (decorator != null)) {
754
				String text = decorator.marginText[line];
755
				if ((text != null) && (text.length() > 0)) {
756
					marginLayout.setText(text);
757
					marginLayout.setStyle(decorator.marginTextStyle, 0, text.length() - 1);
758
					FontMetrics lineMetrics = lineLayout.getLineMetrics(0);
759
					FontMetrics marginMetrics = marginLayout.getLineMetrics(0);
760
					int baselineOffset = (lineMetrics.getAscent() + lineMetrics.getLeading())
761
							- (marginMetrics.getAscent() + marginMetrics.getLeading());
762
					int paintY = lineY + Math.max(0, baselineOffset);
763
					if (decorator.marginTextStyle.background != null) {
764
						Rectangle rect = marginLayout.getLineBounds(0);
765
						rect.x = decorator.marginRect.x;
766
						rect.y = paintY;
767
						rect.width = decorator.marginRect.width;
768
						gc.setBackground(decorator.marginTextStyle.background);
769
						gc.fillRectangle(rect);
770
					}
771
					gc.setForeground(decorator.marginTextStyle.foreground);
772
					marginLayout.draw(gc, decorator.marginRect.x, paintY);
773
				}
774
			}
775
		}
776
	/**
501
	 * Print header or footer decorations.
777
	 * Print header or footer decorations.
502
	 * 
778
	 * 
503
	 * @param page page number to print, if specified in the StyledTextPrintOptions header or footer.
779
	 * @param page page number to print, if specified in the StyledTextPrintOptions header or footer.
(-)Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledTextPrintOptions.java (-1 / +18 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2003 IBM Corporation and others.
2
 * Copyright (c) 2000, 2006 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 83-86 Link Here
83
	 * Print the line background color. Default value is <code>false</code>.
83
	 * Print the line background color. Default value is <code>false</code>.
84
	 */
84
	 */
85
	public boolean printLineBackground = false;
85
	public boolean printLineBackground = false;
86
	/**
87
	 * Print lead margin decorator (left margin in left-to-right orientation).
88
	 * See StyledTextPrintMarginDecorator for more information. A
89
	 * <code>null</code> setting means no lead margin text will be printed.
90
	 * 
91
	 * @since 3.2
92
	 */
93
	public StyledTextPrintMarginDecorator printLeadMarginDecorator = null;
94
	/**
95
	 * Print trail margin decorator (right margin in left-to-right orientation).
96
	 * See StyledTextPrintMarginDecorator for more information. A
97
	 * <code>null</code> setting means no trail margin text will be printed.
98
	 * 
99
	 * @since 3.2
100
	 */
101
	public StyledTextPrintMarginDecorator printTrailMarginDecorator = null;
102
	// TODO Should probably add a margin size option.
86
}
103
}
(-)Eclipse (+92 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2006 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.swt.custom;
12
13
import org.eclipse.swt.graphics.TextStyle;
14
15
/**
16
 * Use StyledTextPrintMarginDecorator along with StyledTextPrintOptions to
17
 * specify decorators for the lead and trail margins of a StyledText print job
18
 * when using the StyledText.print(Printer, StyledTextPrintOptions) API. The
19
 * StyledTextPrintOptions class includes two properties of this type. One for
20
 * the lead margin and one for the trail.
21
 * 
22
 * @since 3.2
23
 */
24
public interface StyledTextPrintMarginDecorator {
25
	/**
26
	 * Return value for getAlignment. If the text is in the left (not lead)
27
	 * margin the text will be right aligned (floats toward the document text).
28
	 * If the text is in the right (not trail) margin the text will be left
29
	 * aligned (floats toward the document text).
30
	 */
31
	static final int FLOAT_INWARD = 0;
32
33
	/**
34
	 * Return value for getAlignment. If the text is in the left (not lead)
35
	 * margin the text will be left aligned (floats away from the document
36
	 * text). If the text is in the right (not trail) margin the text will be
37
	 * right aligned (floats away from the document text).
38
	 */
39
	static final int FLOAT_OUTWARD = 1;
40
41
	/**
42
	 * Return value for getAlignment. Forces left alignment in either margin.
43
	 */
44
	static final int FORCE_LEFT = 2;
45
46
	/**
47
	 * Return value for getAlignment. Forces right alignment in either margin.
48
	 * This value is particularly useful for line number alignment.
49
	 */
50
	static final int FORCE_RIGHT = 3;
51
52
	/**
53
	 * Return value for getAlignment. Uses center alignment in either margin.
54
	 */
55
	static final int CENTER = 4;
56
57
	/**
58
	 * Returns the alignment of the margin text (<code>FLOAT_INWARD</code>,
59
	 * <code>FLOAT_OUTWARD</code>, <code>FORCE_LEFT</code>,
60
	 * <code>FORCE_RIGHT</code>, or <code>CENTER</code>).
61
	 * 
62
	 * @return the alignment
63
	 */
64
	public int getAlignment();
65
66
	/**
67
	 * Returns the gutter width to be placed between the margin text and the
68
	 * document text. This must be specified in widget DPI. The print job will
69
	 * convert the value to printer DPI.
70
	 */
71
	public int getGutter();
72
73
	/**
74
	 * The margin text for the print job. Implementations may return
75
	 * <code>null</code> for no text.
76
	 * 
77
	 * @param line the widget line number of the text. Implementors should map
78
	 *            this to their document model line number.
79
	 * @return the text for the margin
80
	 */
81
	public String getMarginText(int line);
82
83
	/**
84
	 * Implementations may return the style to be used for all margin text. If
85
	 * <code>null</code> is returned, a style derived from the StyledText
86
	 * widget's font and foreground color settings will be used.
87
	 * 
88
	 * @return the style for all margin text
89
	 */
90
	public TextStyle getMarginTextStyle();
91
92
}

Return to bug 19602