WinPrinterContext.st
changeset 2324 5065edb4f5bd
parent 2323 c038faba10bf
child 2325 634b74929d2d
--- a/WinPrinterContext.st	Mon Apr 23 11:32:45 2007 +0200
+++ b/WinPrinterContext.st	Mon Apr 23 17:25:03 2007 +0200
@@ -331,7 +331,7 @@
     [
         printer startPrintJob: 'Image'.
         printer background:Color white.
-        anImage displayOn:printer x:100 y:100.
+        anImage displayOn:printer x:1000 y:1000.
         printer endPrintJob.
     ] forkAt: 3
 
@@ -1347,39 +1347,6 @@
 
 !WinPrinterContext methodsFor:'drawing'!
 
-createPixmapWidth:w height:h depth:d
-    "allocate a pixmap on the Xserver, the contents is undefined
-     (i.e. random). Return a bitmap id or nil"
-
-%{
-    HANDLE newBitmapHandle;
-    HANDLE hDC = (HANDLE)(__externalAddressVal(__INST(gcId)));
-
-    /*console_printf("CreateBitmap Color\n");*/
-    if (__bothSmallInteger(w, h) && __isSmallInteger(d) /*&& ISCONNECTED */) {
-        if (__intVal(d) == 1) {
-            newBitmapHandle = CreateBitmap(__intVal(w), __intVal(h) , 1, 1, NULL);
-        } else {
-#if 0
-            if (__intVal(d) != __depth) {
-                console_printf("invalid depth\n");
-                RETURN (nil);
-            }
-#endif
-            newBitmapHandle = CreateCompatibleBitmap(hDC, __intVal(w), __intVal(h) );
-        }
-
-        if (newBitmapHandle) {
-            RETURN ( __MKOBJ(newBitmapHandle));
-        }
-/*
-        DPRINTF(("empty bitmap handle = %x\n", newBitmapHandle));
-*/
-    }
-    RETURN (nil);
-%}
-!
-
 displayArcX:x y:y width:width height:height from:startAngle angle:angle in:ignoredDrawableId with:aDC
     "draw an arc. If any of x,y, w or h is not an integer, an error is triggered.
      The angles may be floats or integer - they are given in degrees."
@@ -2259,313 +2226,6 @@
 %}
 !
 
-getPenForMyContext
-    "Get a pen for my context"
-
-    |maskOriginX maskOriginY|
-
-    self maskOrigin isNil ifFalse:[
-        maskOriginX := self maskOrigin x.
-        maskOriginY := self maskOrigin y.
-    ].
-
-%{  
-    HPEN hPen = 0;
-    HPEN prevPen;
-    LOGBRUSH Brush;
-    COLORREF fgColor;
-    HANDLE hDC = (HANDLE)(__externalAddressVal(__INST(gcId)));
-    int lStyle, bkMode, hMask, maskOrgX, maskOrgY;
-    int style, lineStyle, capStyle, joinStyle;
-    int lw;
-    int BK_TRANSPARENT;
-
-    BK_TRANSPARENT = 1;
-
-    lw= __INST(lineWidth);
-/*    fgColor = __intVal(__INST(foreground)) & 0xffffff;     */
-
-    fgColor = GetTextColor(hDC);     
-    lineStyle=__INST(lineStyle);
-    capStyle=__INST(capStyle);
-    joinStyle=__INST(joinStyle);
-    hMask= __INST(mask);
-    maskOrgX=__intVal(maskOriginX);
-    maskOrgY=__intVal(maskOriginY);
-
-    if (lineStyle == @symbol(solid)) {
-        style = PS_SOLID;
-    } else if (lineStyle == @symbol(dashed)) {
-        style= PS_DASH;
-    } else if (lineStyle == @symbol(dotted)) {
-        style= PS_DOT;
-    } else if (lineStyle == @symbol(dashDot)) {
-        style= PS_DASHDOT;
-    } else if (lineStyle == @symbol(dashDotDot)) {
-        style= PS_DASHDOTDOT;
-    } else
-        style= PS_SOLID;
-    lStyle &= ~PS_STYLE_MASK;
-    lStyle |= style;
-
-
-    if (capStyle == @symbol(round)) {
-        style = PS_ENDCAP_ROUND;
-    } else if (capStyle == @symbol(square)) {
-        style = PS_ENDCAP_SQUARE;
-    } else if (capStyle == @symbol(flat)) {
-        style = PS_ENDCAP_FLAT;
-    } else
-        style = PS_ENDCAP_FLAT;
-    lStyle &= ~PS_ENDCAP_MASK;
-    lStyle |= style;
-
-    if (joinStyle == @symbol(bevel)) {
-        style = PS_JOIN_BEVEL;
-    } else if (joinStyle == @symbol(miter)) {
-        style = PS_JOIN_MITER;
-    } else if (joinStyle == @symbol(round)) {
-        style = PS_JOIN_ROUND;
-    } else
-        style = PS_JOIN_MITER;
-    lStyle &= ~PS_JOIN_MASK;
-    lStyle |= style;
-
-
-    if (((lStyle & PS_STYLE_MASK) == PS_SOLID)
-     && (hMask == 0)
-     && (lw /* lineWidth */ <= 1)) {
-        if (fgColor == 0 /* BlackPixel */ ) {
-            hPen = GetStockObject(BLACK_PEN);
-            prevPen = SelectObject(hDC, hPen);
-            RETURN( hPen );
-        }
-        if (fgColor == 1 /* WhitePixel */) {
-            hPen = GetStockObject(WHITE_PEN);
-            prevPen = SelectObject(hDC, hPen);
-            RETURN( hPen );
-        }
-    }
-
-    hPen = (HPEN) 0;
-
-    if (0 /* __isWinNT */) {
-
-        if (lw == 0) {
-            lw = 1;
-        }
-        /*
-         * NT supports masked drawing with any lineStyle,
-         * and also non-solid lines with any lineWidth.
-         */
-        if (hMask) {
-            Brush.lbStyle = BS_PATTERN;
-            Brush.lbHatch = (DWORD)hMask;
-            Brush.lbColor = fgColor;
-        } else {
-
-#ifndef PRE_07_APR_04
-
-            hPen = CreatePen((lStyle & PS_STYLE_MASK), lw, fgColor);
-
-/*            RESPRINTF(("CreatePen %x %d(%d) %x %x\n",
- *                       lStyle,
- *                       lw, __INST(lineWidth),
- *                       fgColor, hMask));
- */
-
-            SetBkMode(hDC, TRANSPARENT);
-            bkMode = BK_TRANSPARENT;
-
-#else
-            Brush.lbStyle = BS_SOLID;
-            Brush.lbHatch = 0;
-            Brush.lbColor = fgColor;
-#endif
-        }
-
-        if (! hPen)
-        {
-            hPen = ExtCreatePen(PS_GEOMETRIC | lStyle,
-                            lw, /* lineWidth, */
-                            &Brush,
-                            0, 0);
-
-/*            RESPRINTF(("ExtCreatePen1 %x %d(%d) %x %x\n",
- *                       lStyle,
- *                       lw, __INST(lineWidth),
- *                       fgColor, hMask));
- */
-            if (hMask) {
-                SetBrushOrgEx(hDC, maskOrgX, maskOrgY, 0);
-            }
-        }
-    } else {
-        /*
-         * W95 only supports masked drawing with SOLID lines
-         * also, we should use COSMETIC pens if possible
-         * with non-solid lineStyles.
-         */
-        if ((lStyle & PS_STYLE_MASK) == PS_SOLID) {
-            int ps = PS_GEOMETRIC;
-
-            if (hMask) {
-                Brush.lbStyle = BS_PATTERN;
-                Brush.lbHatch = (DWORD)hMask;
-                Brush.lbColor = fgColor;
-            } else {
-                Brush.lbStyle = BS_SOLID;
-                Brush.lbHatch = 0;
-                Brush.lbColor = fgColor;
-                if (lw /* lineWidth */ <= 1) {
-                    ps = PS_COSMETIC;
-                }
-            }
-
-            hPen = ExtCreatePen(ps | lStyle,
-                                lw, /* lineWidth */
-                                &Brush,
-                                0, 0);
-
-/*            RESPRINTF(("ExtCreatePen1 %x %d %x %x\n",
- *                           lStyle,
- *                           lw, 
- *                           fgColor, hMask));
- */
-            if (hMask) {
-                SetBrushOrgEx(hDC, maskOrgX, maskOrgY, 0);
-            }
-        } else {
-
-            if (lw == 1) {
-                lw = 0;
-            }
-
-            /*
-             * dashes only supported with lineWidth 0
-             */
-
-            hPen = CreatePen((lStyle & PS_STYLE_MASK),
-                             lw,
-                             fgColor);
-
-/*            RESPRINTF(("CreatePen %x %d %x\n",
- *                               (lStyle & PS_STYLE_MASK),
- *                               lw, 
- *                               fgColor));
- */
-            //
-            // CG: wrong; must set to opaque, if doubleDashed
-            //
-            SetBkMode(hDC, TRANSPARENT);
-            bkMode = BK_TRANSPARENT;
-        }
-    }
-
-    prevPen = SelectObject(hDC, hPen);
-
-    RETURN (hPen);
-
-%}
-!
-
-primCreateBitmapFromArray:anArray width:w height:h
-%{
-
-    HBITMAP newBitmapHandle;
-    int b_width, b_height, bytesPerRowST, bytesPerRowWN, padding;
-    int row, col;
-    unsigned char *cp, *bPits;
-    unsigned char *b_bits = 0;
-    int index;
-    OBJ num;
-    unsigned char *allocatedBits = 0;
-    unsigned char fastBits[10000];
-
-    if (__bothSmallInteger(w, h)
-     && _isNonNilObject(anArray)) {
-        OBJ cls = __qClass(anArray);
-
-        b_width = __intVal(w);
-        b_height = __intVal(h);
-        bytesPerRowST = (b_width + 7) / 8;
-        bytesPerRowWN = ((b_width + 15) / 16) * 2;
-        padding = bytesPerRowWN - bytesPerRowST;
-
-        if ((padding == 0) && (cls == @global(ByteArray))) {
-            b_bits = __ByteArrayInstPtr(anArray)->ba_element;
-            cp = 0;
-        } else {
-            int nBytes = b_height * bytesPerRowWN;
-
-            if (nBytes < sizeof(fastBits)) {
-                cp = b_bits = fastBits;
-            } else {
-                cp = b_bits = allocatedBits = (unsigned char *) malloc(nBytes);
-                if (! cp) goto fail;
-            }
-        }
-        if (cp) {
-            if (cls == @global(Array)) {
-                OBJ *op;
-
-                index = 1;
-                op = &(__ArrayInstPtr(anArray)->a_element[index - 1]);
-                for (row = b_height; row; row--) {
-                    for (col = bytesPerRowST; col; col--) {
-                        num = *op++;
-                        if (! __isSmallInteger(num))
-                            goto fail;
-                        *cp++ = __intVal(num);
-                    }
-                    cp += padding;
-                }
-            } else if (cls == @global(ByteArray)) {
-                unsigned char *pBits;
-
-                pBits = __ByteArrayInstPtr(anArray)->ba_element;
-                for (row = b_height; row; row--) {
-                    for (col = bytesPerRowST; col; col--) {
-                        *cp++ = ( *pBits++ /*^ 0xFF*/ );
-                    }
-                    cp += padding;
-                }
-            } else {
-                goto fail;
-            }
-        }
-/*
-        CPRINTF(("create bitmap ...\n"));
-*/
-        newBitmapHandle = CreateBitmap(b_width, b_height, 1, 1, b_bits );
-
-        if (newBitmapHandle ) {
-/*
-            DDPRINTF(("returning bitmap %x ...\n", newBitmapHandle));
-*/
-            if (allocatedBits) {
-                free(allocatedBits);
-            }
-            RETURN ( __MKOBJ(newBitmapHandle));
-        }
-    }
-fail: ;
-/*
-    DDPRINTF(("create bitmap FAILED!!!\n"));
-*/
-    if (allocatedBits) {
-/*
-        CPRINTF(("freeing up bitmap bits ...\n"));
-*/
-        free(allocatedBits);
-    }
-/*
-    CPRINTF(("returning nil ...\n"));
-*/
-    RETURN ( nil );
-%}
-!
-
 primFillPolygon:aPolygon n:numberOfPoints in:ignoredDrawableId with:aDC
 
 %{
@@ -2721,9 +2381,9 @@
         }
 
     // convert 123 to string [buf]
-    itoa(fun, buf, 10);
-
-            console_printf(" ", buf);
+    // itoa(fun, buf, 10);
+
+    //        console_printf(" ", buf);
 
 /*
 #if 0
@@ -2847,6 +2507,39 @@
     ^ bitmapId
 !
 
+createPixmapWidth:w height:h depth:d
+    "allocate a pixmap on the Xserver, the contents is undefined
+     (i.e. random). Return a bitmap id or nil"
+
+%{
+    HANDLE newBitmapHandle;
+    HANDLE rootDC = CreateDC("DISPLAY", NULL, NULL, NULL);
+
+    /*console_printf("CreateBitmap Color\n");*/
+    if (__bothSmallInteger(w, h) && __isSmallInteger(d) /*&& ISCONNECTED */) {
+        if (__intVal(d) == 1) {
+            newBitmapHandle = CreateBitmap(__intVal(w), __intVal(h) , 1, 1, NULL);
+        } else {
+#if 0
+            if (__intVal(d) != __depth) {
+                console_printf("invalid depth\n");
+                RETURN (nil);
+            }
+#endif
+            newBitmapHandle = CreateCompatibleBitmap(rootDC, __intVal(w), __intVal(h) );
+        }
+
+        if (newBitmapHandle) {
+            RETURN ( __MKOBJ(newBitmapHandle));
+        }
+/*
+        DPRINTF(("empty bitmap handle = %x\n", newBitmapHandle));
+*/
+    }
+    RETURN (nil);
+%}
+!
+
 destroyPixmap:aDrawableId
 
 %{  /* NOCONTEXT */
@@ -2902,11 +2595,12 @@
 
 %{  /* NOCONTEXT */
 
-    if (__isExternalAddress(aDrawableId)) {  /* HBITMAP */
+    if (__isExternalAddress(aDrawableId)){
         BITMAP bitmap;
-        HBITMAP hBitmap, memBM = _HBITMAPVAL(aDrawableId);
-        HANDLE compatibleDC, hdcScreen;
-        HANDLE hDC = (HANDLE)(__externalAddressVal(__INST(gcId)));
+        HBITMAP hBitmap = _HBITMAPVAL(aDrawableId);
+        HBITMAP memBM;
+        HANDLE compatibleDC, rootDC, hdcScreen;
+   //     HANDLE printerDC = (HANDLE)(__externalAddressVal(__INST(gcId)));    
 
 
         if (! hBitmap) {
@@ -2929,18 +2623,19 @@
         gcData->bitmapColorBitCount = bitmap.bmBitsPixel;
 */
 
-        hdcScreen= CreateDC("NULL", NULL, NULL, NULL);
-   //       compatibleDC =  hdcScreen;
+        rootDC  = CreateDC("DISPLAY", NULL, NULL, NULL);
+        compatibleDC = CreateCompatibleDC(rootDC);  
+        SelectObject(compatibleDC, hBitmap);
+
+   //     hdcScreen= CreateDC("NULL", NULL, NULL, NULL);
+   //       compatibleDC =  rootDC;
+   //     compatibleDC = CreateCompatibleDC(printerDC);
    //     compatibleDC = CreateCompatibleDC(0); 
-   //     hdcScreen  = CreateDC("DISPLAY", NULL, NULL, NULL);
-        compatibleDC = CreateCompatibleDC(hdcScreen);      
-   //         compatibleDC = CreateCompatibleDC(hDC);
-        memBM = CreateCompatibleBitmap ( compatibleDC, bitmap.bmWidth, bitmap.bmHeight );
-        SelectObject ( compatibleDC, memBM );
-   //     SelectObject(compatibleDC, hBitmap);
+   //     memBM = CreateCompatibleBitmap ( compatibleDC, bitmap.bmWidth, bitmap.bmHeight );
+   //     SelectObject ( compatibleDC, memBM );
+
         RETURN (__MKOBJ(compatibleDC));
 
-
 /*
         RETURN ( __MKOBJ(gcData) );
 */
@@ -2949,6 +2644,103 @@
 %}
 !
 
+primCreateBitmapFromArray:anArray width:w height:h
+%{
+
+    HBITMAP newBitmapHandle;
+    int b_width, b_height, bytesPerRowST, bytesPerRowWN, padding;
+    int row, col;
+    unsigned char *cp, *bPits;
+    unsigned char *b_bits = 0;
+    int index;
+    OBJ num;
+    unsigned char *allocatedBits = 0;
+    unsigned char fastBits[10000];
+
+    if (__bothSmallInteger(w, h)
+     && _isNonNilObject(anArray)) {
+        OBJ cls = __qClass(anArray);
+
+        b_width = __intVal(w);
+        b_height = __intVal(h);
+        bytesPerRowST = (b_width + 7) / 8;
+        bytesPerRowWN = ((b_width + 15) / 16) * 2;
+        padding = bytesPerRowWN - bytesPerRowST;
+
+        if ((padding == 0) && (cls == @global(ByteArray))) {
+            b_bits = __ByteArrayInstPtr(anArray)->ba_element;
+            cp = 0;
+        } else {
+            int nBytes = b_height * bytesPerRowWN;
+
+            if (nBytes < sizeof(fastBits)) {
+                cp = b_bits = fastBits;
+            } else {
+                cp = b_bits = allocatedBits = (unsigned char *) malloc(nBytes);
+                if (! cp) goto fail;
+            }
+        }
+        if (cp) {
+            if (cls == @global(Array)) {
+                OBJ *op;
+
+                index = 1;
+                op = &(__ArrayInstPtr(anArray)->a_element[index - 1]);
+                for (row = b_height; row; row--) {
+                    for (col = bytesPerRowST; col; col--) {
+                        num = *op++;
+                        if (! __isSmallInteger(num))
+                            goto fail;
+                        *cp++ = __intVal(num);
+                    }
+                    cp += padding;
+                }
+            } else if (cls == @global(ByteArray)) {
+                unsigned char *pBits;
+
+                pBits = __ByteArrayInstPtr(anArray)->ba_element;
+                for (row = b_height; row; row--) {
+                    for (col = bytesPerRowST; col; col--) {
+                        *cp++ = ( *pBits++ /*^ 0xFF*/ );
+                    }
+                    cp += padding;
+                }
+            } else {
+                goto fail;
+            }
+        }
+/*
+        CPRINTF(("create bitmap ...\n"));
+*/
+        newBitmapHandle = CreateBitmap(b_width, b_height, 1, 1, b_bits );
+
+        if (newBitmapHandle ) {
+/*
+            DDPRINTF(("returning bitmap %x ...\n", newBitmapHandle));
+*/
+            if (allocatedBits) {
+                free(allocatedBits);
+            }
+            RETURN ( __MKOBJ(newBitmapHandle));
+        }
+    }
+fail: ;
+/*
+    DDPRINTF(("create bitmap FAILED!!!\n"));
+*/
+    if (allocatedBits) {
+/*
+        CPRINTF(("freeing up bitmap bits ...\n"));
+*/
+        free(allocatedBits);
+    }
+/*
+    CPRINTF(("returning nil ...\n"));
+*/
+    RETURN ( nil );
+%}
+!
+
 primDrawBits:imageBits bitsPerPixel:bitsPerPixel depth:imageDepth padding:padd
                               width:imageWidth height:imageHeight
                                   x:srcx y:srcy
@@ -2964,7 +2756,6 @@
     unsigned char fastBits[10000];
     unsigned char *b_bits = 0;
     unsigned char *allocatedBits = 0;
-    HDC hDC = (HDC)0;
     unsigned char *__imageBits = 0;
 
     if (__isByteArray(imageBits)) {
@@ -2992,7 +2783,7 @@
         } bitmap;
 
         HANDLE hDC = (HANDLE)(__externalAddressVal(aGCId));    
-        HBITMAP hBitmap, memBM = _HBITMAPVAL(__INST(drawableId));
+        HBITMAP hBitmap = _HBITMAPVAL(__INST(drawableId));         
 
 /*
         DDPRINTF(("hDC = %x\n", hDC));
@@ -3062,26 +2853,31 @@
         bitmap.bmiHeader.biHeight = -(__intVal(imageHeight));
         bitmap.bmiHeader.biBitCount = __intVal(bitsPerPixel);
         /*console_printf("drawBits depth:%d bitsPerPixel:%d IW%d W:%d H:%d\n",__intVal(imageDepth),bitmap.bmiHeader.biBitCount,bitmap.bmiHeader.biWidth,__intVal(w),bitmap.bmiHeader.biHeight);*/
-/*        SetDIBitsToDevice(hDC,__intVal(dstx),__intVal(dsty),
+
+        SetDIBitsToDevice(hDC,__intVal(dstx),__intVal(dsty),
                               __intVal(w), __intVal(h),
                               __intVal(srcx), __intVal(srcy),
                               0,__intVal(h),
                               (void *)b_bits,
                               (BITMAPINFO*)&bitmap,DIB_RGB_COLORS);
-*/
+
+/*
         SetDIBits(hDC,hBitmap,
                               0,__intVal(h),
                               (void *)b_bits,
                               (BITMAPINFO*)&bitmap,DIB_RGB_COLORS);
-
-
+*/
 /*
-        StretchDIBits(hDC,__intVal(dstx),__intVal(dsty),
-                              __intVal(w), __intVal(h),
-                              __intVal(srcx), __intVal(srcy),
-                              0,__intVal(h),
-                              (void *)b_bits,
-                              (BITMAPINFO*)&bitmap,DIB_RGB_COLORS, SRCCOPY);
+        StretchDIBits(hDC,
+                      __intVal(dstx),(__intVal(dsty)),            //  x & y coord of destination upper-left corner
+                      __intVal(w), __intVal(h),                 // width & height of destination rectangle
+                      __intVal(srcx), __intVal(srcy),           // x & y coord of source upper-left corner
+                      __intVal(w), __intVal(h),                 // width & height of source rectangle
+                      (void *)b_bits,                           // bitmap bits
+                      (BITMAPINFO*)&bitmap,                     // bitmap data
+                      DIB_RGB_COLORS,                           // usage options
+                      SRCCOPY                                   // raster operation code
+        );
 */
         if (allocatedBits) {
             free(allocatedBits);
@@ -3189,6 +2985,58 @@
      ^Display shiftRed
 !
 
+xgcForBitmap:aDrawableId
+
+%{  /* NOCONTEXT */
+
+    if (__isExternalAddress(aDrawableId)){
+        BITMAP bitmap;
+        HBITMAP hBitmap = _HBITMAPVAL(aDrawableId);
+        HBITMAP memBM;
+        HANDLE compatibleDC, rootDC, hdcScreen;
+        HANDLE hDC = (HANDLE)(__externalAddressVal(__INST(gcId)));    
+
+        if (! hBitmap) {
+            RETURN (nil);
+        }
+
+        if (GetObject(hBitmap, sizeof(bitmap), &bitmap)) {
+/*
+            DDPRINTF(("bitmap info:%d\n", bitmap.bmBitsPixel));
+*/
+        } else {
+/*
+            DPRINTF(("noinfo returned for bitmap\n"));
+*/
+            /* mhmh - can this happen ? */
+            bitmap.bmBitsPixel = 1;
+        }
+/*
+        gcData->hBitmap = hBitmap;
+        gcData->bitmapColorBitCount = bitmap.bmBitsPixel;
+*/
+
+        rootDC  = CreateDC("DISPLAY", NULL, NULL, NULL);
+        compatibleDC = CreateCompatibleDC(hDC);      
+        SelectObject(compatibleDC, hBitmap);
+
+   //     hdcScreen= CreateDC("NULL", NULL, NULL, NULL);
+   //       compatibleDC =  rootDC;
+   //     compatibleDC = CreateCompatibleDC(0); 
+   //         compatibleDC = CreateCompatibleDC(hDC);
+   //     memBM = CreateCompatibleBitmap ( compatibleDC, bitmap.bmWidth, bitmap.bmHeight );
+   //     SelectObject ( compatibleDC, memBM );
+
+        RETURN (__MKOBJ(compatibleDC));
+
+/*
+        RETURN ( __MKOBJ(gcData) );
+*/
+    }
+    RETURN (nil);
+%}
+!
+
 xprimDrawBits:imageBits bitsPerPixel:bitsPerPixel depth:imageDepth padding:padd width:imageWidth height:imageHeight
                                   x:srcx y:srcy
                                into:ignoredDrawableId
@@ -4185,6 +4033,216 @@
 %}
 !
 
+getPenForMyContext
+    "Get a pen for my context"
+
+    |maskOriginX maskOriginY|
+
+    self maskOrigin isNil ifFalse:[
+        maskOriginX := self maskOrigin x.
+        maskOriginY := self maskOrigin y.
+    ].
+
+%{  
+    HPEN hPen = 0;
+    HPEN prevPen;
+    LOGBRUSH Brush;
+    COLORREF fgColor;
+    HANDLE hDC = (HANDLE)(__externalAddressVal(__INST(gcId)));
+    int lStyle, bkMode, hMask, maskOrgX, maskOrgY;
+    int style, lineStyle, capStyle, joinStyle;
+    int lw;
+    int BK_TRANSPARENT;
+
+    BK_TRANSPARENT = 1;
+
+    lw= __INST(lineWidth);
+/*    fgColor = __intVal(__INST(foreground)) & 0xffffff;     */
+
+    fgColor = GetTextColor(hDC);     
+    lineStyle=__INST(lineStyle);
+    capStyle=__INST(capStyle);
+    joinStyle=__INST(joinStyle);
+    hMask= __INST(mask);
+    maskOrgX=__intVal(maskOriginX);
+    maskOrgY=__intVal(maskOriginY);
+
+    if (lineStyle == @symbol(solid)) {
+        style = PS_SOLID;
+    } else if (lineStyle == @symbol(dashed)) {
+        style= PS_DASH;
+    } else if (lineStyle == @symbol(dotted)) {
+        style= PS_DOT;
+    } else if (lineStyle == @symbol(dashDot)) {
+        style= PS_DASHDOT;
+    } else if (lineStyle == @symbol(dashDotDot)) {
+        style= PS_DASHDOTDOT;
+    } else
+        style= PS_SOLID;
+    lStyle &= ~PS_STYLE_MASK;
+    lStyle |= style;
+
+
+    if (capStyle == @symbol(round)) {
+        style = PS_ENDCAP_ROUND;
+    } else if (capStyle == @symbol(square)) {
+        style = PS_ENDCAP_SQUARE;
+    } else if (capStyle == @symbol(flat)) {
+        style = PS_ENDCAP_FLAT;
+    } else
+        style = PS_ENDCAP_FLAT;
+    lStyle &= ~PS_ENDCAP_MASK;
+    lStyle |= style;
+
+    if (joinStyle == @symbol(bevel)) {
+        style = PS_JOIN_BEVEL;
+    } else if (joinStyle == @symbol(miter)) {
+        style = PS_JOIN_MITER;
+    } else if (joinStyle == @symbol(round)) {
+        style = PS_JOIN_ROUND;
+    } else
+        style = PS_JOIN_MITER;
+    lStyle &= ~PS_JOIN_MASK;
+    lStyle |= style;
+
+
+    if (((lStyle & PS_STYLE_MASK) == PS_SOLID)
+     && (hMask == 0)
+     && (lw /* lineWidth */ <= 1)) {
+        if (fgColor == 0 /* BlackPixel */ ) {
+            hPen = GetStockObject(BLACK_PEN);
+            prevPen = SelectObject(hDC, hPen);
+            RETURN( hPen );
+        }
+        if (fgColor == 1 /* WhitePixel */) {
+            hPen = GetStockObject(WHITE_PEN);
+            prevPen = SelectObject(hDC, hPen);
+            RETURN( hPen );
+        }
+    }
+
+    hPen = (HPEN) 0;
+
+    if (0 /* __isWinNT */) {
+
+        if (lw == 0) {
+            lw = 1;
+        }
+        /*
+         * NT supports masked drawing with any lineStyle,
+         * and also non-solid lines with any lineWidth.
+         */
+        if (hMask) {
+            Brush.lbStyle = BS_PATTERN;
+            Brush.lbHatch = (DWORD)hMask;
+            Brush.lbColor = fgColor;
+        } else {
+
+#ifndef PRE_07_APR_04
+
+            hPen = CreatePen((lStyle & PS_STYLE_MASK), lw, fgColor);
+
+/*            RESPRINTF(("CreatePen %x %d(%d) %x %x\n",
+ *                       lStyle,
+ *                       lw, __INST(lineWidth),
+ *                       fgColor, hMask));
+ */
+
+            SetBkMode(hDC, TRANSPARENT);
+            bkMode = BK_TRANSPARENT;
+
+#else
+            Brush.lbStyle = BS_SOLID;
+            Brush.lbHatch = 0;
+            Brush.lbColor = fgColor;
+#endif
+        }
+
+        if (! hPen)
+        {
+            hPen = ExtCreatePen(PS_GEOMETRIC | lStyle,
+                            lw, /* lineWidth, */
+                            &Brush,
+                            0, 0);
+
+/*            RESPRINTF(("ExtCreatePen1 %x %d(%d) %x %x\n",
+ *                       lStyle,
+ *                       lw, __INST(lineWidth),
+ *                       fgColor, hMask));
+ */
+            if (hMask) {
+                SetBrushOrgEx(hDC, maskOrgX, maskOrgY, 0);
+            }
+        }
+    } else {
+        /*
+         * W95 only supports masked drawing with SOLID lines
+         * also, we should use COSMETIC pens if possible
+         * with non-solid lineStyles.
+         */
+        if ((lStyle & PS_STYLE_MASK) == PS_SOLID) {
+            int ps = PS_GEOMETRIC;
+
+            if (hMask) {
+                Brush.lbStyle = BS_PATTERN;
+                Brush.lbHatch = (DWORD)hMask;
+                Brush.lbColor = fgColor;
+            } else {
+                Brush.lbStyle = BS_SOLID;
+                Brush.lbHatch = 0;
+                Brush.lbColor = fgColor;
+                if (lw /* lineWidth */ <= 1) {
+                    ps = PS_COSMETIC;
+                }
+            }
+
+            hPen = ExtCreatePen(ps | lStyle,
+                                lw, /* lineWidth */
+                                &Brush,
+                                0, 0);
+
+/*            RESPRINTF(("ExtCreatePen1 %x %d %x %x\n",
+ *                           lStyle,
+ *                           lw, 
+ *                           fgColor, hMask));
+ */
+            if (hMask) {
+                SetBrushOrgEx(hDC, maskOrgX, maskOrgY, 0);
+            }
+        } else {
+
+            if (lw == 1) {
+                lw = 0;
+            }
+
+            /*
+             * dashes only supported with lineWidth 0
+             */
+
+            hPen = CreatePen((lStyle & PS_STYLE_MASK),
+                             lw,
+                             fgColor);
+
+/*            RESPRINTF(("CreatePen %x %d %x\n",
+ *                               (lStyle & PS_STYLE_MASK),
+ *                               lw, 
+ *                               fgColor));
+ */
+            //
+            // CG: wrong; must set to opaque, if doubleDashed
+            //
+            SetBkMode(hDC, TRANSPARENT);
+            bkMode = BK_TRANSPARENT;
+        }
+    }
+
+    prevPen = SelectObject(hDC, hPen);
+
+    RETURN (hPen);
+
+%}
+!
+
 xxdisplayLineFromX:x0 y:y0 toX:x1 y:y1 in:ignoredDrawableId with:aDC
     "draw a line. If the coordinates are not integers, an error is triggered."
 
@@ -4416,6 +4474,13 @@
     ^ gcId notNil
 !
 
+isPersistentInSnapshot
+    "return true, if resources on this device are to be made
+     persistent in a snapshot image."
+
+    ^ false
+!
+
 supportsColor
 
 "/    | retVal info |
@@ -4497,5 +4562,5 @@
 !WinPrinterContext class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libview2/WinPrinterContext.st,v 1.8 2007-04-23 09:32:45 fm Exp $'
+    ^ '$Header: /cvs/stx/stx/libview2/WinPrinterContext.st,v 1.9 2007-04-23 15:25:03 fm Exp $'
 ! !