Moved extend string showing methods to GSG.

Simple (not working) alpha handling on windows.


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/back/trunk@19686 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Fred Kiefer 2004-07-06 17:52:39 +00:00
parent b829fc0758
commit 3c77485016
6 changed files with 1268 additions and 655 deletions

View file

@ -1,3 +1,14 @@
2004-07-06 Fred Kiefer <FredKiefer@gmx.de>
* Source/winlib/Win32GState.m (-_compositeGState:...fraction:):
Applied alpha blending patch by MA Garcias <lists@tragnarion.com>.
Disabled GDI_WIDELINE_BEZIERPATH_BUG.
* configure.ac: Added test for msimg32, needed for AlphaBlend.
* configure: Regenerated.
* Source/xlib/XGGState.m: Moved additional show methods to super class.
* Source/gsc/GSGState.m: Implemented additional show methods based
on (-showGlyphs::) and simple glyph conversion.
2004-06-19 Fred Kiefer <FredKiefer@gmx.de>
* Source/x11/XGServerWindow.m (-standardcursor::): Added more

View file

@ -32,6 +32,7 @@
#include "gsc/GSContext.h"
#include "gsc/GSGState.h"
#include "math.h"
#include <GNUstepBase/Unicode.h>
#define CHECK_PATH \
if (!path) \
@ -357,15 +358,117 @@
/* ----------------------------------------------------------------------- */
/* Text operations */
/* ----------------------------------------------------------------------- */
- (void) DPSashow: (float)x : (float)y : (const char*)s
/* Show the first lenght characters from C string s at the current point
and return the width of the string. Does not move the point.
*/
- (float) _showString: (const char*)s lenght: (int)lenght
{
[self subclassResponsibility: _cmd];
return 0.0;
}
typedef enum {
show_delta, show_array_x, show_array_y, show_array_xy
} show_array_t;
/* Omnibus show string routine that combines that characteristics of
ashow, awidthshow, widthshow, xshow, xyshow, and yshow */
- (void) _showString: (const char *)s
xCharAdj: (float)cx
yCharAdj: (float)cy
char: (char)c
adjArray: (const float *)arr
arrType: (show_array_t)type
isRelative: (BOOL)relative;
{
NSPoint point = [path currentPoint];
unichar *uch;
int ulen;
int i;
/*
FIXME: We should use proper glyph generation here.
*/
uch = NULL;
ulen = 0;
GSToUnicode(&uch, &ulen, s, strlen(s), [font mostCompatibleStringEncoding],
NSDefaultMallocZone(), 0);
for (i = 0; i < ulen; i++)
{
NSPoint delta;
NSGlyph glyph;
glyph = (NSGlyph)uch[i];
[self GSShowGlyphs: &glyph : 1];
/* Note we update the current point according to the current
transformation scaling, although the text isn't currently
scaled (FIXME). */
if (type == show_array_xy)
{
delta.x = arr[2*i]; delta.y = arr[2*i+1];
}
else if (type == show_array_x)
{
delta.x = arr[i]; delta.y = 0;
}
else if (type == show_array_y)
{
delta.x = 0; delta.y = arr[i];
}
else
{
delta.x = arr[0]; delta.y = arr[1];
}
delta = [ctm deltaPointInMatrixSpace: delta];
if (relative == YES)
{
NSSize advancement;
advancement = [font advancementForGlyph: glyph];
/* Use only delta transformations (no offset). Is this conversion needed?*/
advancement = [ctm sizeInMatrixSpace: NSMakeSize(advancement.width,
[font ascender])];
delta.x += advancement.width;
delta.y += advancement.height;
}
if (c && *(s+i) == c)
{
NSPoint cdelta;
cdelta.x = cx; cdelta.y = cy;
cdelta = [ctm deltaPointInMatrixSpace: cdelta];
delta.x += cdelta.x; delta.y += cdelta.y;
}
point.x += delta.x;
if (type != show_delta)
{
point.y += delta.y;
}
[path moveToPoint: point];
}
free(uch);
}
- (void) DPSashow: (float)x : (float)y : (const char*)s
{
float arr[2];
arr[0] = x; arr[1] = y;
[self _showString: s
xCharAdj: 0 yCharAdj: 0 char: 0 adjArray: arr arrType: show_delta
isRelative: YES];
}
- (void) DPSawidthshow: (float)cx : (float)cy : (int)c : (float)ax : (float)ay
: (const char*)s
{
[self subclassResponsibility: _cmd];
float arr[2];
arr[0] = ax; arr[1] = ay;
[self _showString: s
xCharAdj: cx yCharAdj: cy char: c adjArray: arr arrType: show_delta
isRelative: YES];
}
- (void) DPScharpath: (const char*)s : (int)b
@ -380,22 +483,33 @@
- (void) DPSwidthshow: (float)x : (float)y : (int)c : (const char*)s
{
[self subclassResponsibility: _cmd];
float arr[2];
arr[0] = 0; arr[1] = 0;
[self _showString: s
xCharAdj: x yCharAdj: y char: c adjArray: arr arrType: show_delta
isRelative: YES];
}
- (void) DPSxshow: (const char*)s : (const float*)numarray : (int)size
{
[self subclassResponsibility: _cmd];
[self _showString: s
xCharAdj: 0 yCharAdj: 0 char: 0 adjArray: numarray arrType: show_array_x
isRelative: NO];
}
- (void) DPSxyshow: (const char*)s : (const float*)numarray : (int)size
{
[self subclassResponsibility: _cmd];
[self _showString: s
xCharAdj: 0 yCharAdj: 0 char: 0 adjArray: numarray arrType: show_array_xy
isRelative: NO];
}
- (void) DPSyshow: (const char*)s : (const float*)numarray : (int)size
{
[self subclassResponsibility: _cmd];
[self _showString: s
xCharAdj: 0 yCharAdj: 0 char: 0 adjArray: numarray arrType: show_array_y
isRelative: NO];
}
- (void) GSSetCharacterSpacing: (float)extra

View file

@ -28,6 +28,8 @@
#include <AppKit/NSFont.h>
#include <AppKit/NSGraphics.h>
// Define this so we pick up AlphaBlend, when loading windows.h
#define WINVER 0x0500
#include "winlib/WIN32GState.h"
#include "winlib/WIN32Context.h"
#include "winlib/WIN32FontInfo.h"
@ -35,11 +37,16 @@
#include <math.h>
#ifndef AC_SRC_ALPHA
// Missing definitions from wingdi.h
#define AC_SRC_ALPHA 0x01
#endif
// There is a bug in Win32 GDI drawing with lines wider than 0
// before and after a bezier path forming an oblique
// angle. The solution is to insert extra MoveToEx()'s
// before and after the PolyBezierTo().
#define GDI_WIDELINE_BEZIERPATH_BUG 1
#define GDI_WIDELINE_BEZIERPATH_BUG 0
static inline
int WindowHeight(HWND window)
@ -167,64 +174,93 @@ RECT GSViewRectToWin(WIN32GState *s, NSRect r)
wscolor = RGB(color.field[0]*255, color.field[1]*255, color.field[2]*255);
}
- (void) copyBits: (WIN32GState*)source
fromRect: (NSRect)aRect
toPoint: (NSPoint)aPoint
- (void) _compositeGState: (WIN32GState *) source
fromRect: (NSRect) sourceRect
toPoint: (NSPoint) destPoint
op: (NSCompositingOperation) op
fraction: (float)delta
{
HDC otherDC;
HDC sourceDC;
HDC hDC;
RECT rect;
RECT rectFrom;
RECT rectTo;
int h;
int x;
int y;
NSRect r;
RECT rect2;
NSRect destRect;
BOOL success;
rect = GSViewRectToWin(source, aRect);
h = rect.bottom - rect.top;
NSDebugLLog(@"WIN32GState", @"compositeGState: fromRect: %@ toPoint: %@ op: %d",
NSStringFromRect(sourceRect), NSStringFromPoint(destPoint), op);
rectFrom = GSViewRectToWin(source, sourceRect);
h = rectFrom.bottom - rectFrom.top;
destRect.size = sourceRect.size;
destRect.origin = destPoint;
rectTo = GSViewRectToWin( self, destRect );
x = rectTo.left;
y = rectTo.top;
r.size = aRect.size;
r.origin = aPoint;
rect2 = GSViewRectToWin(self, r);
x = rect2.left;
y = rect2.top;
if (source->ctm->matrix.m22 < 0 && ctm->matrix.m22 > 0) y += h;
if (source->ctm->matrix.m22 > 0 && ctm->matrix.m22 < 0) y -= h;
otherDC = [source getHDC];
if (!otherDC)
sourceDC = [source getHDC];
if( !sourceDC )
{
return;
}
if (self == source)
if( self == source )
{
hDC = otherDC;
}
else
hDC = sourceDC;
}
else
{
hDC = [self getHDC];
if (!hDC)
{
[source releaseHDC: otherDC];
if( !hDC )
{
[source releaseHDC: sourceDC];
return;
}
}
}
if (!BitBlt(hDC, x, y, (rect.right - rect.left), h,
otherDC, rect.left, rect.top, SRCCOPY))
switch (op)
{
NSLog(@"Copy bitmap failed %d", GetLastError());
NSLog(@"Orig Copy Bits to %f, %f from %@", aPoint.x, aPoint.y,
NSStringFromRect(aRect));
NSLog(@"Copy Bits to %d %d from %d %d size %d %d", x , y,
rect.left, rect.top, (rect.right - rect.left), h);
case NSCompositeSourceOver:
{
// Use (0..1) fraction to set a (0..255) alpha constant value
BYTE SourceCosntantAlpha = (BYTE)(delta * 255);
BLENDFUNCTION blendFunc = {AC_SRC_OVER, 0, SourceCosntantAlpha, AC_SRC_ALPHA};
success = AlphaBlend(hDC,
x, y, (rectFrom.right - rectFrom.left), h,
sourceDC,
rectFrom.left, rectFrom.top,
(rectFrom.right - rectFrom.left), h, blendFunc);
break;
}
default:
success = BitBlt( hDC, x, y, (rectFrom.right - rectFrom.left), h,
sourceDC, rectFrom.left, rectFrom.top, SRCCOPY );
break;
}
if (!success)
{
NSLog(@"Blit operation failed %d", GetLastError());
NSLog(@"Orig Copy Bits to %@ from %@", NSStringFromPoint(destPoint),
NSStringFromRect(destRect));
NSLog(@"Copy bits to {%d, %d} from {%d, %d} size {%d, %d}", x, y,
rectFrom.left, rectFrom.top, (rectFrom.right - rectFrom.left), h);
}
if (self != source)
{
[self releaseHDC: hDC];
}
[source releaseHDC: otherDC];
[source releaseHDC: sourceDC];
}
- (void) compositeGState: (GSGState *)source
@ -232,8 +268,11 @@ RECT GSViewRectToWin(WIN32GState *s, NSRect r)
toPoint: (NSPoint)aPoint
op: (NSCompositingOperation)op
{
// FIXME
[self copyBits: (WIN32GState *)source fromRect: aRect toPoint: aPoint];
[self _compositeGState: (WIN32GState *) source
fromRect: aRect
toPoint: aPoint
op: op
fraction: 1];
}
- (void) dissolveGState: (GSGState *)source
@ -241,8 +280,11 @@ RECT GSViewRectToWin(WIN32GState *s, NSRect r)
toPoint: (NSPoint)aPoint
delta: (float)delta
{
// FIXME
[self copyBits: (WIN32GState *)source fromRect: aRect toPoint: aPoint];
[self _compositeGState: (WIN32GState *) source
fromRect: aRect
toPoint: aPoint
op: NSCompositeSourceOver
fraction: delta];
}
- (void) compositerect: (NSRect)aRect
@ -432,6 +474,16 @@ HBITMAP GSCreateBitmap(HDC hDC, int pixelsWide, int pixelsHigh,
int h;
int y1;
NSDebugLLog(@"WIN32GState", @"DPSImage : pixelsWide = %d : pixelsHigh = %d"
": bitsPerSample = %d : samplesPerPixel = %d"
": bitsPerPixel = %d : bytesPerRow = %d "
": isPlanar = %d"
": hasAlpha = %d : colorSpaceName = %@",
pixelsWide, pixelsHigh,
bitsPerSample, samplesPerPixel,
bitsPerPixel, bytesPerRow,
isPlanar, hasAlpha, colorSpaceName);
if (window == NULL)
{
NSLog(@"No window in DPSImage");

View file

@ -1175,127 +1175,6 @@ static Region emptyRegion;
/* ----------------------------------------------------------------------- */
/* Text operations */
/* ----------------------------------------------------------------------- */
typedef enum {
show_delta, show_array_x, show_array_y, show_array_xy
} show_array_t;
/* Omnibus show string routine that combines that characteristics of
ashow, awidthshow, widthshow, xshow, xyshow, and yshow */
- (void) _showString: (const char *)s
xCharAdj: (float)cx
yCharAdj: (float)cy
char: (char)c
adjArray: (const float *)arr
arrType: (show_array_t)type
isRelative: (BOOL)relative;
{
int i;
int len;
int width;
NSSize scale;
NSPoint point = [path currentPoint];
if (font == nil)
{
NSLog(@"DPS (xgps): no font set\n");
return;
}
COPY_GC_ON_CHANGE;
if (draw == 0)
{
DPS_WARN(DPSinvalidid, @"No Drawable defined for show");
return;
}
if ((cstate & COLOR_FILL) == 0)
[self setColor: &fillColor state: COLOR_FILL];
/* Use only delta transformations (no offset) */
len = strlen(s);
scale = [ctm sizeInMatrixSpace: NSMakeSize(1,1)];
for (i = 0; i < len; i++)
{
NSPoint delta;
XPoint xp;
// FIXME: We should put this line before the loop
// and do all computation in display space.
xp = XGWindowPointToX(self, point);
width = [(XGFontInfo *)font widthOf: s+i lenght: 1];
// Hack: Only draw when alpha is not zero
if (drawingAlpha == NO || fillColor.field[AINDEX] != 0.0)
[(XGFontInfo *)font draw: s+i lenght: 1
onDisplay: XDPY drawable: draw
with: xgcntxt at: xp];
if (drawingAlpha)
{
NSAssert(alpha_buffer, NSInternalInconsistencyException);
[self setAlphaColor: fillColor.field[AINDEX]];
[(XGFontInfo *)font draw: s+i lenght: 1
onDisplay: XDPY drawable: alpha_buffer
with: agcntxt at: xp];
}
/* Note we update the current point according to the current
transformation scaling, although the text isn't currently
scaled (FIXME). */
if (type == show_array_xy)
{
delta.x = arr[2*i]; delta.y = arr[2*i+1];
}
else if (type == show_array_x)
{
delta.x = arr[i]; delta.y = 0;
}
else if (type == show_array_y)
{
delta.x = 0; delta.y = arr[i];
}
else
{
delta.x = arr[0]; delta.y = arr[1];
}
delta = [ctm deltaPointInMatrixSpace: delta];
if (relative == YES)
{
delta.x += width * scale.width;
delta.y += [font ascender] * scale.height;
}
if (c && *(s+i) == c)
{
NSPoint cdelta;
cdelta.x = cx; cdelta.y = cy;
cdelta = [ctm deltaPointInMatrixSpace: cdelta];
delta.x += cdelta.x; delta.y += cdelta.y;
}
point.x += delta.x;
if (type != show_delta)
point.y += delta.y;
}
// FIXME: Should we set the current point now?
}
- (void)DPSashow: (float)x : (float)y : (const char *)s
{
float arr[2];
arr[0] = x; arr[1] = y;
[self _showString: s
xCharAdj: 0 yCharAdj: 0 char: 0 adjArray: arr arrType: show_delta
isRelative: YES];
}
- (void)DPSawidthshow: (float)cx : (float)cy : (int)c : (float)ax : (float)ay : (const char *)s
{
float arr[2];
arr[0] = ax; arr[1] = ay;
[self _showString: s
xCharAdj: cx yCharAdj: cy char: c adjArray: arr arrType: show_delta
isRelative: YES];
}
- (void)DPSshow: (const char *)s
{
@ -1346,7 +1225,6 @@ typedef enum {
[path relativeMoveToPoint: NSMakePoint(width * scale.width, 0)];
}
- (void) GSShowGlyphs: (const NSGlyph *)glyphs : (size_t) length
{
int width;
@ -1394,37 +1272,6 @@ typedef enum {
[path relativeMoveToPoint: NSMakePoint(width * scale.width, 0)];
}
- (void)DPSwidthshow: (float)x : (float)y : (int)c : (const char *)s
{
float arr[2];
arr[0] = 0; arr[1] = 0;
[self _showString: s
xCharAdj: x yCharAdj: y char: c adjArray: arr arrType: show_delta
isRelative: YES];
}
- (void)DPSxshow: (const char *)s : (const float *)numarray : (int)size
{
[self _showString: s
xCharAdj: 0 yCharAdj: 0 char: 0 adjArray: numarray arrType: show_array_x
isRelative: NO];
}
- (void)DPSxyshow: (const char *)s : (const float *)numarray : (int)size
{
[self _showString: s
xCharAdj: 0 yCharAdj: 0 char: 0 adjArray: numarray arrType: show_array_xy
isRelative: NO];
}
- (void)DPSyshow: (const char *)s : (const float *)numarray : (int)size
{
[self _showString: s
xCharAdj: 0 yCharAdj: 0 char: 0 adjArray: numarray arrType: show_array_y
isRelative: NO];
}
- (void) GSSetFont: (GSFontInfo *)newFont
{
if (font == newFont)

1501
configure vendored

File diff suppressed because it is too large Load diff

View file

@ -255,6 +255,10 @@ AC_CHECK_LIB(gdi32, main, have_gdi32=yes, have_gdi32=no)
if test "$have_gdi32" = yes; then
WIN32_LIBS="-lgdi32"
fi
AC_CHECK_LIB(msimg32, main, have_msimg32=yes, have_msimg32=no)
if test "$have_msimg32" = yes; then
WIN32_LIBS="${WIN32_LIBS} -lmsimg32"
fi
CPPFLAGS="${save_header}"
LIBS="${save_libs}"