diff options
author | Kevin Barnes | 2007-10-24 18:34:44 +0000 |
---|---|---|
committer | Kevin Barnes | 2007-10-24 18:34:44 +0000 |
commit | 375edd619736a12125743add1cb6aee356e13ee3 (patch) | |
tree | d843b5a82a987b5c86089484afb2da1669966967 /bundles/org.eclipse.swt | |
parent | 74ef63346f6b293054e1f013c7808c8d1ebc6ff0 (diff) | |
download | eclipse.platform.swt-375edd619736a12125743add1cb6aee356e13ee3.tar.gz eclipse.platform.swt-375edd619736a12125743add1cb6aee356e13ee3.tar.xz eclipse.platform.swt-375edd619736a12125743add1cb6aee356e13ee3.zip |
19602 - [Printing] Line numbers aren't printed
Diffstat (limited to 'bundles/org.eclipse.swt')
2 files changed, 33 insertions, 5 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledText.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledText.java index 76466df6d1..1744d7dac6 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledText.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledText.java @@ -448,11 +448,24 @@ public class StyledText extends Canvas { printLayout.setFont(printerFont); } if (printOptions.printLineNumbers) { + int numberingWidth = 0; int count = endLine - startLine + 1; - StringBuffer buffer = new StringBuffer("0"); - while ((count /= 10) > 0) buffer.append("0"); - printLayout.setText(buffer.toString()); - int numberingWidth = printLayout.getBounds().width + printMargin; + String[] lineLabels = printOptions.lineLabels; + if (lineLabels != null) { + for (int i = startLine; i < Math.min(count, lineLabels.length); i++) { + if (lineLabels[i] != null) { + printLayout.setText(lineLabels[i]); + int lineWidth = printLayout.getBounds().width; + numberingWidth = Math.max(numberingWidth, lineWidth); + } + } + } else { + StringBuffer buffer = new StringBuffer("0"); + while ((count /= 10) > 0) buffer.append("0"); + printLayout.setText(buffer.toString()); + numberingWidth = printLayout.getBounds().width; + } + numberingWidth += printMargin; if (numberingWidth > width) numberingWidth = width; paintX += numberingWidth; width -= numberingWidth; @@ -598,7 +611,16 @@ public class StyledText extends Canvas { FontMetrics metrics = layout.getLineMetrics(0); printLayout.setAscent(metrics.getAscent() + metrics.getDescent()); printLayout.setDescent(metrics.getDescent()); - printLayout.setText(String.valueOf(index)); + String[] lineLabels = printOptions.lineLabels; + if (lineLabels != null) { + if (0 <= index && index < lineLabels.length && lineLabels[index] != null) { + printLayout.setText(lineLabels[index]); + } else { + printLayout.setText(""); + } + } else { + printLayout.setText(String.valueOf(index)); + } int paintX = x - printMargin - printLayout.getBounds().width; printLayout.draw(gc, paintX, y); printLayout.setAscent(-1); diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledTextPrintOptions.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledTextPrintOptions.java index 84812153d1..e511bd56fc 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledTextPrintOptions.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledTextPrintOptions.java @@ -91,5 +91,11 @@ public class StyledTextPrintOptions { */ public boolean printLineNumbers = false; + /** + * Line labels. + * + * @since 3.4 + */ + public String[] lineLabels = null; } |