comparison dwtx/jface/internal/text/html/HTMLPrinter.d @ 150:5cf141e43417

...
author Frank Benoit <benoit@tionex.de>
date Sun, 24 Aug 2008 23:05:26 +0200
parents 65801ad2b265
children 25f1f92fa3df
comparison
equal deleted inserted replaced
149:b411f1c62131 150:5cf141e43417
44 44
45 private static RGB BG_COLOR_RGB= new RGB(255, 255, 225); // RGB value of info bg color on WindowsXP 45 private static RGB BG_COLOR_RGB= new RGB(255, 255, 225); // RGB value of info bg color on WindowsXP
46 private static RGB FG_COLOR_RGB= new RGB(0, 0, 0); // RGB value of info fg color on WindowsXP 46 private static RGB FG_COLOR_RGB= new RGB(0, 0, 0); // RGB value of info fg color on WindowsXP
47 47
48 48
49 static { 49 static this() {
50 implMissing( __FILE__, __LINE__ ); // lazy init needed for Display
50 final Display display= Display.getDefault(); 51 final Display display= Display.getDefault();
51 if (display !is null && !display.isDisposed()) { 52 if (display !is null && !display.isDisposed()) {
52 try { 53 try {
53 display.asyncExec(new class() Runnable { 54 display.asyncExec(new class() Runnable {
54 /* 55 /*
183 } 184 }
184 185
185 private static void appendStyleSheetURL(StringBuffer buffer, String styleSheet) { 186 private static void appendStyleSheetURL(StringBuffer buffer, String styleSheet) {
186 if (styleSheet is null) 187 if (styleSheet is null)
187 return; 188 return;
188 189
189 buffer.append("<head><style CHARSET=\"ISO-8859-1\" TYPE=\"text/css\">"); //$NON-NLS-1$ 190 buffer.append("<head><style CHARSET=\"ISO-8859-1\" TYPE=\"text/css\">"); //$NON-NLS-1$
190 buffer.append(styleSheet); 191 buffer.append(styleSheet);
191 buffer.append("</style></head>"); //$NON-NLS-1$ 192 buffer.append("</style></head>"); //$NON-NLS-1$
192 } 193 }
193 194
194 private static void appendStyleSheetURL(StringBuffer buffer, URL styleSheetURL) { 195 private static void appendStyleSheetURL(StringBuffer buffer, URL styleSheetURL) {
195 if (styleSheetURL is null) 196 if (styleSheetURL is null)
196 return; 197 return;
197 198
198 buffer.append("<head>"); //$NON-NLS-1$ 199 buffer.append("<head>"); //$NON-NLS-1$
216 pageProlog.append("<html>"); //$NON-NLS-1$ 217 pageProlog.append("<html>"); //$NON-NLS-1$
217 appendStyleSheetURL(pageProlog, styleSheetURL); 218 appendStyleSheetURL(pageProlog, styleSheetURL);
218 appendColors(pageProlog, FG_COLOR_RGB, BG_COLOR_RGB); 219 appendColors(pageProlog, FG_COLOR_RGB, BG_COLOR_RGB);
219 buffer.insert(position, pageProlog.toString()); 220 buffer.insert(position, pageProlog.toString());
220 } 221 }
221 222
222 public static void insertPageProlog(StringBuffer buffer, int position, String styleSheet) { 223 public static void insertPageProlog(StringBuffer buffer, int position, String styleSheet) {
223 insertPageProlog(buffer, position, null, null, styleSheet); 224 insertPageProlog(buffer, position, null, null, styleSheet);
224 } 225 }
225 226
226 public static void addPageProlog(StringBuffer buffer) { 227 public static void addPageProlog(StringBuffer buffer) {
264 265
265 public static void addParagraph(StringBuffer buffer, Reader paragraphReader) { 266 public static void addParagraph(StringBuffer buffer, Reader paragraphReader) {
266 if (paragraphReader !is null) 267 if (paragraphReader !is null)
267 addParagraph(buffer, read(paragraphReader)); 268 addParagraph(buffer, read(paragraphReader));
268 } 269 }
269 270
270 /** 271 /**
271 * Replaces the following style attributes of the font definition of the <code>html</code> 272 * Replaces the following style attributes of the font definition of the <code>html</code>
272 * element: 273 * element:
273 * <ul> 274 * <ul>
274 * <li>font-size</li> 275 * <li>font-size</li>
279 * The font's name is used as font family, a <code>sans-serif</code> default font family is 280 * The font's name is used as font family, a <code>sans-serif</code> default font family is
280 * appended for the case that the given font name is not available. 281 * appended for the case that the given font name is not available.
281 * <p> 282 * <p>
282 * If the listed font attributes are not contained in the passed style list, nothing happens. 283 * If the listed font attributes are not contained in the passed style list, nothing happens.
283 * </p> 284 * </p>
284 * 285 *
285 * @param styles CSS style definitions 286 * @param styles CSS style definitions
286 * @param fontData the font information to use 287 * @param fontData the font information to use
287 * @return the modified style definitions 288 * @return the modified style definitions
288 * @since 3.3 289 * @since 3.3
289 */ 290 */
290 public static String convertTopLevelFont(String styles, FontData fontData) { 291 public static String convertTopLevelFont(String styles, FontData fontData) {
291 bool bold= (fontData.getStyle() & DWT.BOLD) !is 0; 292 bool bold= (fontData.getStyle() & DWT.BOLD) !is 0;
292 bool italic= (fontData.getStyle() & DWT.ITALIC) !is 0; 293 bool italic= (fontData.getStyle() & DWT.ITALIC) !is 0;
293 294
294 // See: https://bugs.eclipse.org/bugs/show_bug.cgi?id=155993 295 // See: https://bugs.eclipse.org/bugs/show_bug.cgi?id=155993
295 String size= Integer.toString(fontData.getHeight()) + ("carbon".equals(DWT.getPlatform()) ? "px" : "pt"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ 296 String size= Integer.toString(fontData.getHeight()) + ("carbon".equals(DWT.getPlatform()) ? "px" : "pt"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
296 297
297 String family= "'" + fontData.getName() + "',sans-serif"; //$NON-NLS-1$ //$NON-NLS-2$ 298 String family= "'" + fontData.getName() + "',sans-serif"; //$NON-NLS-1$ //$NON-NLS-2$
298 styles= styles.replaceFirst("(html\\s*\\{.*(?:\\s|;)font-size:\\s*)\\d+pt(\\;?.*\\})", "$1" + size + "$2"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ 299 styles= styles.replaceFirst("(html\\s*\\{.*(?:\\s|;)font-size:\\s*)\\d+pt(\\;?.*\\})", "$1" + size + "$2"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
299 styles= styles.replaceFirst("(html\\s*\\{.*(?:\\s|;)font-weight:\\s*)\\w+(\\;?.*\\})", "$1" + (bold ? "bold" : "normal") + "$2"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ 300 styles= styles.replaceFirst("(html\\s*\\{.*(?:\\s|;)font-weight:\\s*)\\w+(\\;?.*\\})", "$1" + (bold ? "bold" : "normal") + "$2"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
300 styles= styles.replaceFirst("(html\\s*\\{.*(?:\\s|;)font-style:\\s*)\\w+(\\;?.*\\})", "$1" + (italic ? "italic" : "normal") + "$2"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ 301 styles= styles.replaceFirst("(html\\s*\\{.*(?:\\s|;)font-style:\\s*)\\w+(\\;?.*\\})", "$1" + (italic ? "italic" : "normal") + "$2"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
301 styles= styles.replaceFirst("(html\\s*\\{.*(?:\\s|;)font-family:\\s*).+?(;.*\\})", "$1" + family + "$2"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ 302 styles= styles.replaceFirst("(html\\s*\\{.*(?:\\s|;)font-family:\\s*).+?(;.*\\})", "$1" + family + "$2"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$