diff dwtx/jface/internal/text/html/HTMLPrinter.d @ 162:1a5b8f8129df

...
author Frank Benoit <benoit@tionex.de>
date Mon, 08 Sep 2008 00:51:37 +0200
parents 25f1f92fa3df
children
line wrap: on
line diff
--- a/dwtx/jface/internal/text/html/HTMLPrinter.d	Wed Aug 27 14:49:30 2008 +0200
+++ b/dwtx/jface/internal/text/html/HTMLPrinter.d	Mon Sep 08 00:51:37 2008 +0200
@@ -39,24 +39,33 @@
  */
 public class HTMLPrinter {
 
-    private static RGB BG_COLOR_RGB= new RGB(255, 255, 225); // RGB value of info bg color on WindowsXP
-    private static RGB FG_COLOR_RGB= new RGB(0, 0, 0); // RGB value of info fg color on WindowsXP
-
+    private static RGB BG_COLOR_RGB_;
+    private static RGB FG_COLOR_RGB_;
 
-    static this() {
-        implMissing( __FILE__, __LINE__ ); // lazy init needed for Display
-        final Display display= Display.getDefault();
+    private static RGB BG_COLOR_RGB(){
+        COLOR_RGB_init();
+        return BG_COLOR_RGB_;
+    }
+    private static RGB FG_COLOR_RGB(){
+        COLOR_RGB_init();
+        return FG_COLOR_RGB_;
+    }
+
+    private static bool COLOR_RGB_init_complete = false;
+    private static void COLOR_RGB_init() {
+        if( COLOR_RGB_init_complete ){
+            return;
+        }
+        COLOR_RGB_init_complete = true;
+        BG_COLOR_RGB_= new RGB(255, 255, 225); // RGB value of info bg color on WindowsXP
+        FG_COLOR_RGB_= new RGB(0, 0, 0); // RGB value of info fg color on WindowsXP
+        Display display= Display.getDefault();
         if (display !is null && !display.isDisposed()) {
             try {
-                display.asyncExec(new class()  Runnable {
-                    /*
-                     * @see java.lang.Runnable#run()
-                     */
-                    public void run() {
-                        BG_COLOR_RGB= display.getSystemColor(DWT.COLOR_INFO_BACKGROUND).getRGB();
-                        FG_COLOR_RGB= display.getSystemColor(DWT.COLOR_INFO_FOREGROUND).getRGB();
-                    }
-                });
+                display.asyncExec( dgRunnable( (Display display_){
+                    BG_COLOR_RGB_= display_.getSystemColor(DWT.COLOR_INFO_BACKGROUND).getRGB();
+                    FG_COLOR_RGB_= display_.getSystemColor(DWT.COLOR_INFO_FOREGROUND).getRGB();
+                }, display ));
             } catch (DWTError err) {
                 // see: https://bugs.eclipse.org/bugs/show_bug.cgi?id=45294
                 if (err.code !is DWT.ERROR_DEVICE_DISPOSED)
@@ -103,7 +112,7 @@
         try {
             int n= rd.read(readBuffer);
             while (n > 0) {
-                buffer.append(readBuffer, 0, n);
+                buffer.append(readBuffer[ 0 .. n ]);
                 n= rd.read(readBuffer);
             }
             return buffer.toString();
@@ -127,7 +136,8 @@
 
         appendColors(pageProlog, fgRGB, bgRGB);
 
-        buffer.insert(position,  pageProlog.toString());
+        buffer.select(position,0);
+        buffer.replace(pageProlog.toString());
     }
 
     private static void appendColors(StringBuffer pageProlog, RGB fgRGB, RGB bgRGB) {
@@ -165,17 +175,20 @@
 
         // Find insertion index
         // a) within existing body tag with trailing space
-        int index= buffer.indexOf("<body "); //$NON-NLS-1$
+        int index= buffer.slice().indexOf("<body "); //$NON-NLS-1$
         if (index !is -1) {
-            buffer.insert(index+5, styleBuf);
+            buffer.select(index+5, 0);
+            buffer.replace(styleBuf);
             return;
         }
 
         // b) within existing body tag without attributes
-        index= buffer.indexOf("<body>"); //$NON-NLS-1$
+        index= buffer.slice().indexOf("<body>"); //$NON-NLS-1$
         if (index !is -1) {
-            buffer.insert(index+5, ' ');
-            buffer.insert(index+6, styleBuf);
+            buffer.select(index+5, 0);
+            buffer.replace( " " );
+            buffer.select(index+6, 0);
+            buffer.replace(styleBuf);
             return;
         }
     }
@@ -206,7 +219,8 @@
         StringBuffer pageProlog= new StringBuffer(60);
         pageProlog.append("<html>"); //$NON-NLS-1$
         appendColors(pageProlog, FG_COLOR_RGB, BG_COLOR_RGB);
-        buffer.insert(position,  pageProlog.toString());
+        buffer.select(position, 0);
+        buffer.replace(pageProlog.toString());
     }
 
     public static void insertPageProlog(StringBuffer buffer, int position, URL styleSheetURL) {
@@ -214,7 +228,8 @@
         pageProlog.append("<html>"); //$NON-NLS-1$
         appendStyleSheetURL(pageProlog, styleSheetURL);
         appendColors(pageProlog, FG_COLOR_RGB, BG_COLOR_RGB);
-        buffer.insert(position,  pageProlog.toString());
+        buffer.select(position, 0);
+        buffer.replace(pageProlog.toString());
     }
 
     public static void insertPageProlog(StringBuffer buffer, int position, String styleSheet) {
@@ -290,13 +305,13 @@
         bool italic= (fontData.getStyle() & DWT.ITALIC) !is 0;
 
         // See: https://bugs.eclipse.org/bugs/show_bug.cgi?id=155993
-        String size= Integer.toString(fontData.getHeight()) + ("carbon".equals(DWT.getPlatform()) ? "px" : "pt"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+        String size= Integer.toString(fontData.getHeight()) ~ ("carbon".equals(DWT.getPlatform()) ? "px" : "pt"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
 
-        String family= "'" + fontData.getName() + "',sans-serif"; //$NON-NLS-1$ //$NON-NLS-2$
-        styles= styles.replaceFirst("(html\\s*\\{.*(?:\\s|;)font-size:\\s*)\\d+pt(\\;?.*\\})", "$1" + size + "$2"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
-        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$
-        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$
-        styles= styles.replaceFirst("(html\\s*\\{.*(?:\\s|;)font-family:\\s*).+?(;.*\\})", "$1" + family + "$2"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+        String family= "'" ~ fontData.getName() ~ "',sans-serif"; //$NON-NLS-1$ //$NON-NLS-2$
+        styles= styles.replaceFirst("(html\\s*\\{.*(?:\\s|;)font-size:\\s*)\\d+pt(\\;?.*\\})", "$1" ~ size ~ "$2"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+        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$
+        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$
+        styles= styles.replaceFirst("(html\\s*\\{.*(?:\\s|;)font-family:\\s*).+?(;.*\\})", "$1" ~ family ~ "$2"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
         return styles;
     }
 }