1 11 package org.eclipse.swt.custom; 12 13 14 import java.util.Hashtable ; 15 16 import org.eclipse.swt.SWT; 17 import org.eclipse.swt.graphics.*; 18 19 27 class PrintRenderer extends StyledTextRenderer { 28 StyledTextContent logicalContent; WrappedContent content; Rectangle clientArea; GC gc; Hashtable lineBackgrounds; Hashtable lineStyles; Hashtable bidiSegments; 36 51 PrintRenderer( 52 Device device, Font regularFont, GC gc, 53 StyledTextContent logicalContent, Hashtable lineBackgrounds, 54 Hashtable lineStyles, Hashtable bidiSegments, 55 int tabLength, Rectangle clientArea) { 56 super(device, regularFont); 57 this.logicalContent = logicalContent; 58 this.lineBackgrounds = lineBackgrounds; 59 this.lineStyles = lineStyles; 60 this.bidiSegments = bidiSegments; 61 this.clientArea = clientArea; 62 this.gc = gc; 63 calculateLineHeight(); 64 setTabLength(tabLength); 65 content = new WrappedContent(this, logicalContent); 66 content.wrapLines(); 68 } 69 72 protected void dispose() { 73 content = null; 74 super.dispose(); 75 } 76 80 protected void disposeGC(GC gc) { 81 } 82 86 protected void drawLineBreakSelection(String line, int lineOffset, int paintX, int paintY, GC gc) { 87 } 88 108 protected int[] getBidiSegments(int lineOffset, String lineText) { 109 int lineLength = lineText.length(); 110 int logicalLineOffset = getLogicalLineOffset(lineOffset); 111 int[] segments = (int []) bidiSegments.get(new Integer (logicalLineOffset)); 112 113 if (segments == null) { 114 segments = new int[] {0, lineLength}; 115 } 116 else { 117 int logicalLineIndex = logicalContent.getLineAtOffset(lineOffset); 122 int logicalLineLength = logicalContent.getLine(logicalLineIndex).length(); 123 124 if (lineOffset != logicalLineOffset || lineLength != logicalLineLength) { 125 int lineOffsetDelta = lineOffset - logicalLineOffset; 126 int newSegmentCount = 0; 127 int[] newSegments = new int[segments.length]; 128 129 for (int i = 0; i < segments.length; i++) { 130 newSegments[i] = Math.max(0, segments[i] - lineOffsetDelta); 131 if (newSegments[i] > lineLength) { 132 newSegments[i] = lineLength; 133 newSegmentCount++; 134 break; 135 } 136 if (i == 0 || newSegments[i] > 0) { 137 newSegmentCount++; 138 } 139 } 140 segments = new int[newSegmentCount]; 141 for (int i = 0, newIndex = 0; i < newSegments.length && newIndex < newSegmentCount; i++) { 142 if (i == 0 || newSegments[i] > 0) { 143 segments[newIndex++] = newSegments[i]; 144 } 145 } 146 } 147 } 148 return segments; 149 } 150 156 protected Rectangle getClientArea() { 157 return clientArea; 158 } 159 168 protected StyledTextContent getContent() { 169 return content; 170 } 171 178 protected GC getGC() { 179 return gc; 180 } 181 188 protected int getHorizontalPixel() { 189 return 0; 190 } 191 199 private int getLogicalLineOffset(int visualLineOffset) { 200 int logicalLineIndex = logicalContent.getLineAtOffset(visualLineOffset); 201 202 return logicalContent.getOffsetAtLine(logicalLineIndex); 203 } 204 protected int getOrientation () { 205 int mask = SWT.RIGHT_TO_LEFT | SWT.LEFT_TO_RIGHT; 206 return gc.getStyle() & mask; 207 } 208 protected Color getSelectionBackground() { 209 return null; 210 } 211 protected Color getSelectionForeground() { 212 return null; 213 } 214 218 protected StyledTextEvent getLineBackgroundData(int lineOffset, String line) { 219 int logicalLineOffset = getLogicalLineOffset(lineOffset); 220 221 return (StyledTextEvent) lineBackgrounds.get(new Integer (logicalLineOffset)); 222 } 223 227 protected StyledTextEvent getLineStyleData(int lineOffset, String line) { 228 int logicalLineOffset = getLogicalLineOffset(lineOffset); 229 StyledTextEvent logicalLineEvent = (StyledTextEvent) lineStyles.get(new Integer (logicalLineOffset)); 230 231 if (logicalLineEvent != null) { 232 StyledTextEvent clone = new StyledTextEvent((StyledTextContent) logicalLineEvent.data); 233 clone.detail = logicalLineEvent.detail; 234 clone.styles = logicalLineEvent.styles; 235 clone.text = logicalLineEvent.text; 236 logicalLineEvent = getLineStyleData(clone, lineOffset, line); 237 } 238 return logicalLineEvent; 239 } 240 246 protected Point getSelection() { 247 return new Point(0, 0); 248 } 249 255 protected boolean getWordWrap() { 256 return true; 257 } 258 264 protected boolean isFullLineSelection() { 265 return false; 266 } 267 } 268 | Popular Tags |