discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

GDI backend


From: Christopher Armstrong
Subject: GDI backend
Date: Mon, 10 Apr 2006 09:05:17 +1000
User-agent: Thunderbird 1.5 (Windows/20051201)

Hi all,

I've made improvements to some parts of the GDI backend. They're mostly cosmetic and somewhat hacked for now, but still useful and a good starting point:

* Changed graphics mode to GM_ADVANCED with map mode MM_ANISOTROPIC (fairly useless for now, but may allow tweaking of things in the future). * 24bit image rendering support (we byte swap into a 32bit image, as Windows doesn't seem to like 24bit images the way we have them) * Adding glyph outlines to a bezier path (appendBezierPathWithGlyphs:count: support) * Fixed dashed line rendering so that it now uses custom dash specification (with limitations) and correctly shows up with DPSrectstroke

Cheers
Chris

Only in gnustep-back-0.10.3/Source: libgnustep-back-010Info.plist
diff -r clean/gnustep-back-0.10.3/Source/winlib/WIN32FontInfo.m 
gnustep-back-0.10.3/Source/winlib/WIN32FontInfo.m
6a7,10
> 
>    Additions by Christopher Armstrong (Copyright (C) Christopher
>    Armstrong 2006).
>    Date: April 2006
29a34
> #include <AppKit/NSBezierPath.h>
279a285,330
> 
> // This function adds support for appending glyph outlines
> // to bezier paths.
> //
> // Copyright (C) Christopher Armstrong 2006
> - (void) appendBezierPathWithGlyphs: (NSGlyph *)glyphs
>                              count: (int)count
>                       toBezierPath: (NSBezierPath *)oldPath
> {
>   HDC hDC = CreateCompatibleDC(NULL);
>   SetGraphicsMode(hDC, GM_ADVANCED);
>   SetMapMode(hDC, MM_ANISOTROPIC);
>   SetViewportExtEx(hDC, 1, -1, NULL);
>   SetWindowExtEx(hDC, 1, 1, NULL);
>   SetViewportOrgEx(hDC, 0, 0, NULL);
>   
>   if (!hDC)
>     NSDebugLLog(@"WIN32FontInfo", @"Problem creating HDC for 
> appendBezierPathWithGlyphs:");
>   HPEN pen = CreatePen(PS_SOLID, 1, RGB(0, 0, 0));
>  
>   HFONT old;
>   WORD        buf[count];
>   int i;
> 
>   /*
>    * For now, assume that a glyph is a unicode character and can be
>    * stored in a windows WORD
>    */
>   for (i = 0; i < count; i++)
>     {
>       buf[i] = glyphs[i];
>     }
>   
>   SelectObject(hDC, hFont);
>   SIZE sBoundBox;
>   GetTextExtentPoint32W(hDC, buf, count, &sBoundBox);
>   int h = sBoundBox.cy;
>   //HBITMAP bitBlank = CreateCompatibleBitmap(hDC, sBoundBox.cx, 
> sBoundBox.cy);
>   //SelectObject(hDC, bitBlank);
>   //SelectObject(hDC, pen);
>   SetBkMode(hDC, TRANSPARENT);
>   
>   NSPoint startPoint = [oldPath currentPoint];
>   BeginPath(hDC);
>   
>     SetTextAlign(hDC, TA_LEFT | TA_TOP);
280a332,383
>     TextOutW(hDC, startPoint.x, -startPoint.y, buf, count); 
>   EndPath(hDC);
>   
> 
>   // Now append the glyphs to the path
>   int iPoints = GetPath(hDC, NULL, NULL, 0);
>   POINT* ptPoints = objc_malloc(sizeof(POINT) * iPoints);
>   BYTE* bTypes = objc_malloc(sizeof(BYTE) * iPoints);
> 
>   GetPath(hDC, ptPoints, bTypes, iPoints);
>   i = 0;
> 
>   NSBezierPath* path = [NSBezierPath bezierPath];
>   while (i < iPoints)
>   {
>     if (bTypes[i]==PT_MOVETO)
>     {
>       [path moveToPoint:NSMakePoint(ptPoints[i].x, h - ptPoints[i].y)];
>       i++;
>     }
>     else if (bTypes[i] & PT_BEZIERTO)
>     {
>       POINT pD = ptPoints[i+2];
>       POINT pC1 = ptPoints[i];
>       POINT pC2 = ptPoints[i+1];
>       
>         // FIXME: We assume windows isn't lying here about the bezier points
>       [path curveToPoint:NSMakePoint(ptPoints[i+2].x, h - ptPoints[i+2].y)
>          controlPoint1:NSMakePoint(ptPoints[i].x, h - ptPoints[i].y)
>          controlPoint2:NSMakePoint(ptPoints[i+1].x, h - ptPoints[i+1].y)];
>       ;
>       if (bTypes[i] & PT_CLOSEFIGURE)
>       NSLog(@"CLose on c1");
>       else if (bTypes[i+1] & PT_CLOSEFIGURE)
>       NSLog(@"Close on c2");
>       else if (bTypes[i+2] & PT_CLOSEFIGURE)
>         NSLog(@"Close on d");      
>       i+=3;
>     }
>     else if (bTypes[i] & PT_LINETO)
>     {
>       [path lineToPoint:NSMakePoint(ptPoints[i].x, h - ptPoints[i].y)];
>         if (bTypes[i] & PT_CLOSEFIGURE)
>           [path closePath];
>       i++;
>     }
>   }
>   [oldPath appendBezierPath:path];
>   //DeleteObject(bitBlank);
>   DeleteObject(pen);
>   DeleteDC(hDC);
> }     
Only in gnustep-back-0.10.3/Source/winlib: WIN32FontInfo.m~
diff -r clean/gnustep-back-0.10.3/Source/winlib/WIN32GState.m 
gnustep-back-0.10.3/Source/winlib/WIN32GState.m
5a6,7
>    Additions by Christopher Armstrong (2006)
>    
44a47
> #include <windows.h>
88,89c91,92
<   p1.x = p.x;
<   p1.y = h -p.y;
---
>   p1.x = p.x ;
>   p1.y = p.y ;
94a98,113
> POINT GSWindowPointToOldMS(WIN32GState *s, NSPoint p)
> {
>   POINT p1;
>   int h;
>   
>   h = WindowHeight([s window]);
> 
>   p.x += s->offset.x;
>   p.y += s->offset.y;
> 
>   p1.x = p.x ;
>   p1.y = h - p.y ;
> 
>   return p1;
> }
> static inline
105,108c124,127
<   r1.left = r.origin.x;
<   r1.right = r.origin.x + r.size.width;
<   r1.bottom = h - r.origin.y;
<   r1.top = h - r.origin.y - r.size.height;
---
>   r1.left = r.origin.x ;
>   r1.right = (r.origin.x + r.size.width)  ;
>   r1.bottom = h - r.origin.y  ;
>   r1.top = h - (r.origin.y + r.size.height) ;
120a140,146
> POINT GSViewPointToOldWin(WIN32GState*s, NSPoint p)
> {
>   p = [s->ctm pointInMatrixSpace: p];
>   return GSWindowPointToOldMS(s, p);
> }
> 
> static inline
195,198c221,224
<   r1.left = r.origin.x;
<   r1.right = r.origin.x + r.size.width;
<   r1.bottom = h - r.origin.y;
<   r1.top = h - r.origin.y - r.size.height;
---
>   r1.left = r.origin.x * 20 ;
>   r1.right = (r.origin.x + r.size.width) * 20;
>   r1.bottom = r.origin.y * 20;
>   r1.top = (r.origin.y + r.size.height) * 20;
469a496
>       bmih->bV4SizeImage = pixels * 4;
480a508,530
>   else if (bitsPerPixel == 24)
>   {
>     unsigned char* tmp;
>     unsigned int pixels = pixelsHigh * pixelsWide;
>     unsigned int i = 0, j = 0;
>     
>     bmih->biBitCount = 32;
>     
>     NSDebugLLog(@"WIN32GState", @"24bit picure with pixelsWide:%d 
> pixelsHigh:%d ", pixelsWide, pixelsHigh); 
> 
>     
>     tmp = objc_malloc(pixels * 4);
>     memset(tmp, 0xFF, pixels*4);
>     while (i < (pixels*4))
>     {
>       tmp[i+0] = bits[j+2];
>       tmp[i+1] = bits[j+1];
>       tmp[i+2] = bits[j+0];
>       i+=4;
>       j+=3;
>     }
>     bits = tmp;
>   }
588c638
<   p = GSViewPointToWin(self, NSMakePoint(0, 0));
---
>   p = GSViewPointToOldWin(self, NSMakePoint(0, 0));
646c696,697
<             p = GSWindowPointToMS(self, points[0]);
---
>                   //***
>             p = GSWindowPointToOldMS(self, points[0]);
650c701
<             p = GSWindowPointToMS(self, points[0]);
---
>             p = GSWindowPointToOldMS(self, points[0]);
674c725,726
<                   bp[i] = GSWindowPointToMS(self, points[i]);
---
>                         //***
>                   bp[i] = GSWindowPointToOldMS(self, points[i]);
689c741,742
<             p = GSWindowPointToMS(self, points[0]);
---
>             //***
>             p = GSWindowPointToOldMS(self, points[0]);
821c874
<   NSRect rect = [ctm rectInMatrixSpace: NSMakeRect(x, y, w, h)]; 
---
>   NSRect rect =  [ctm rectInMatrixSpace: NSMakeRect(x, y, w, h)]; 
825c878
<   if (rect.size.width > 0)
---
>   /*if (rect.size.width > 0)
829c882
<   rect.origin.y += 1;
---
>   rect.origin.y += 1;*/
831c884,887
<   path = [NSBezierPath bezierPathWithRect: rect];
---
>   //path = [NSBezierPath bezierPathWithRect: rect];
>   path = [oldPath copy];
>   [path removeAllPoints];
>   [path appendBezierPathWithRect:rect];
867c923,924
<   p = GSWindowPointToMS(self, current);
---
>   p = GSWindowPointToOldMS(self, current);
>   //UINT prevTextAlign = SetTextAlign(hDC, TA_BOTTOM | TA_LEFT | 
> TA_NOUPDATECP);
869a927
>   //SetTextAlign(hDC, prevTextAlign);
885c943,944
<   p = GSWindowPointToMS(self, current);
---
>   p = GSWindowPointToOldMS(self, current);
>   //UINT prevTextAlign = SetTextAlign(hDC, TA_BOTTOM | TA_LEFT | 
> TA_NOUPDATECP);
889a949
>   //SetTextAlign(hDC, prevTextAlign);
1016,1029c1076,1099
<   if (path)
<     {
<       float thePattern[10];
<       int count = 10;
<       float phase;
< 
<       [path getLineDash: thePattern count: &count phase: &phase];
< 
<       if (count && (count < 10))
<       {
<         penStyle = PS_GEOMETRIC | PS_DASH;
<       }
<     }
< 
---
>   
>   float* thePattern = NULL;
>   DWORD* iPattern = NULL;
>   int count = 0;
>   float phase = 0.0;
>   //[path getLineDash: thePattern count: &count phase: &phase];
>   
>   [path getLineDash:NULL count:&count phase:NULL];
>   if (count > 0)
>   {
>     // The user has defined a dash pattern for stroking on 
>     // the path. Note that we lose the floating point information
>     // here, as windows only supports DWORD elements, not float.
>     penStyle = PS_GEOMETRIC | PS_USERSTYLE;
>     thePattern = objc_malloc(sizeof(float) * count);
>     [path getLineDash:thePattern count:&count phase:&phase];
> 
>     iPattern = objc_malloc(sizeof(DWORD) * count);
>     int i  = 0;
>     for (i = 0 ; i < count; i ++)
>       iPattern[i] = (DWORD)thePattern[i];
>     objc_free(thePattern);
>   }
>    
1033c1103,1105
<                    0, NULL);
---
>                    count, iPattern);
>   if (iPattern)
>     objc_free(iPattern);
1094c1166,1177
< 
---
>   SetGraphicsMode(hDC, GM_ADVANCED);
>   SetMapMode(hDC, MM_ANISOTROPIC);
>   //SetWindowExtEx(hDC, GetDeviceCaps(hDC, LOGPIXELSX), 
>   //            GetDeviceCaps(hDC, LOGPIXELSY),
>   //            NULL);
>   //SetViewportExtEx(hDC, 
>   //            96,             
>   //            96,
>   //            NULL);
>   //SetViewportExtEx(hDC, 1, 1, NULL);
>   //SetWindowExtEx(hDC, 1, 1, NULL);
>   
Only in gnustep-back-0.10.3/Source/winlib: WIN32GState.m~

reply via email to

[Prev in Thread] Current Thread [Next in Thread]