[prev in list] [next in list] [prev in thread] [next in thread] 

List:       wine-devel
Subject:    DIB Engine - Rebased on current tree (Takes 2) - Part 2 - winedib.drv
From:       Massimo Del Fedele <max () veneto ! com>
Date:       2009-01-30 12:04:08
Message-ID: gluqbo$nqh$2 () ger ! gmane ! org
[Download RAW message or body]

Here part 2.

Ciao

Max

["Initial_DIB_Engine_Implementation.patch" (text/x-patch)]

diff --git a/configure.ac b/configure.ac
index fe71343..c915e03 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2144,6 +2144,7 @@ \
WINE_CONFIG_MAKEFILE([dlls/wineaudioio.drv/Makefile],[dlls/Makedll.rules],[dlls]  \
WINE_CONFIG_MAKEFILE([dlls/winecoreaudio.drv/Makefile],[dlls/Makedll.rules],[dlls],[ALL_DLL_DIRS])
  WINE_CONFIG_MAKEFILE([dlls/winecrt0/Makefile],[dlls/Makeimplib.rules],[dlls],[ALL_IMPLIB_DIRS])
  WINE_CONFIG_MAKEFILE([dlls/wined3d/Makefile],[dlls/Makedll.rules],[dlls],[ALL_DLL_DIRS])
 +WINE_CONFIG_MAKEFILE([dlls/winedib.drv/Makefile],[dlls/Makedll.rules],[dlls],[ALL_DLL_DIRS])
  WINE_CONFIG_MAKEFILE([dlls/winedos/Makefile],[dlls/Makedll.rules],[dlls],[ALL_DLL_DIRS])
  WINE_CONFIG_MAKEFILE([dlls/wineesd.drv/Makefile],[dlls/Makedll.rules],[dlls],[ALL_DLL_DIRS])
  WINE_CONFIG_MAKEFILE([dlls/winejack.drv/Makefile],[dlls/Makedll.rules],[dlls],[ALL_DLL_DIRS])
                
diff --git a/dlls/winedib.drv/Makefile.in b/dlls/winedib.drv/Makefile.in
new file mode 100644
index 0000000..f5f7102
--- /dev/null
+++ b/dlls/winedib.drv/Makefile.in
@@ -0,0 +1,29 @@
+TOPSRCDIR = @top_srcdir@
+TOPOBJDIR = ../..
+SRCDIR    = @srcdir@
+VPATH     = @srcdir@
+EXTRAINCL = @FREETYPEINCL@ @FONTCONFIGINCL@
+EXTRALIBS = @XLIB@
+MODULE    = winedib.drv
+IMPORTS   = user32 gdi32 advapi32 kernel32 ntdll
+
+C_SRCS = \
+    bitblt.c \
+    bitmap.c \
+    clipping.c \
+    dib.c \
+    dibdrv_main.c \
+    font.c \
+    freetype.c \
+    graphics.c \
+    init.c \
+    opengl.c \
+    palette.c \
+    primitives.c \
+    pen_brush.c \
+    text.c \
+    video.c
+
+@MAKE_DLL_RULES@
+
+@DEPENDENCIES@  # everything below this line is overwritten by make depend
diff --git a/dlls/winedib.drv/bitblt.c b/dlls/winedib.drv/bitblt.c
new file mode 100644
index 0000000..effe902
--- /dev/null
+++ b/dlls/winedib.drv/bitblt.c
@@ -0,0 +1,173 @@
+/*
+ * DIBDRV bit-blit operations
+ *
+ * Copyright 2007 Jesse Allen
+ * Copyright 2008 Huw Davies
+ * Copyright 2008 Massimo Del Fedele
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#include "config.h"
+#include "wine/port.h"
+
+#include "dibdrv.h"
+
+WINE_DEFAULT_DEBUG_CHANNEL(dibdrv);
+
+/***********************************************************************
+ *           get_rop2_from_rop
+ *
+ * Returns the binary rop that is equivalent to the provided ternary rop
+ * if the src bits are ignored.
+ */
+static inline DWORD get_rop2_from_rop(DWORD rop)
+{
+    return (((rop >> 18) & 0x0c) | ((rop >> 16) & 0x03)) + 1;
+}
+
+static inline BOOL rop_uses_src(DWORD rop)
+{
+    return (((rop & 0xcc0000) >> 2) != (rop & 0x330000));
+}
+
+/***********************************************************************
+ *           DIBDRV_StretchBlt
+ */
+BOOL DIBDRV_StretchBlt( DIBDRVPHYSDEV *physDevDst, INT xDst, INT yDst,
+                        INT widthDst, INT heightDst,
+                        DIBDRVPHYSDEV *physDevSrc, INT xSrc, INT ySrc,
+                        INT widthSrc, INT heightSrc, DWORD rop )
+{
+    FIXME("TEMPORARY - JUST BitBlt\n");
+    return DIBDRV_BitBlt(physDevDst, xDst, yDst, widthDst, heightDst, physDevSrc, \
xSrc, ySrc, rop); +    return TRUE;
+}
+
+/***********************************************************************
+ *           DIBDRV_AlphaBlend
+ */
+BOOL DIBDRV_AlphaBlend( DIBDRVPHYSDEV *devDst, INT xDst, INT yDst, INT widthDst, INT \
heightDst, +                        DIBDRVPHYSDEV *devSrc, INT xSrc, INT ySrc, INT \
widthSrc, INT heightSrc, +                        BLENDFUNCTION blendfn)
+{
+#ifdef DIBDRV_SHOW_STUBS
+    FIXME("stub\n");
+#endif
+    return TRUE;
+}
+
+/***********************************************************************
+ *           DIBDRV_BitBlt
+ */
+BOOL DIBDRV_BitBlt( DIBDRVPHYSDEV *physDevDst, INT xDst, INT yDst,
+                    INT width, INT height, DIBDRVPHYSDEV *physDevSrc,
+                    INT xSrc, INT ySrc, DWORD rop )
+{
+    DIBDRVBITMAP *srcBmp, *dstBmp;
+    INT xs, ys, xd, yd;
+    DWORD c;
+    DWORD and, xor;
+
+    /* gets both source and dest bitmaps */
+    srcBmp = & physDevSrc->bmp;
+    dstBmp = & physDevDst->bmp;
+    
+    /* corrects sizes match bitmaps ones */
+    /* FIXME : must be changed for clipping.... */
+    if(xSrc >= srcBmp->width || ySrc >= srcBmp->height)
+    {
+        FIXME("Bad xSrc or ySrc\n");
+        return FALSE;
+    }
+    if(xSrc < 0)
+    {
+        width += xSrc;
+        if(width <= 0)
+        {
+            FIXME("xSrc\n");
+            return FALSE;
+        }
+        xDst -= xSrc;
+        xSrc = 0;
+    }
+    if(ySrc < 0)
+    {
+        height += ySrc;
+        if(height <= 0)
+        {
+            FIXME("ySrc\n");
+            return FALSE;
+        }
+        yDst -= ySrc;
+        ySrc = 0;
+    }
+    if(xDst >= dstBmp->width || yDst >= dstBmp->height)
+    {
+        FIXME("bitmap don't fit on dest one\n");
+        return FALSE;
+    }
+    if(xSrc + width > srcBmp->width)
+        width = srcBmp->width - xSrc;
+    if(ySrc + height > srcBmp->height)
+        height = srcBmp->height - ySrc;
+    if(xDst + width > dstBmp->width)
+        width = dstBmp->width - xDst;
+    if(yDst + height > dstBmp->height)
+        height = dstBmp->height - yDst;
+    
+    /* FIXME : slow way...just read and write pixels
+       must be optimized
+    */
+    for(ys = ySrc, yd = yDst; ys < ySrc+height; ys++, yd++)
+    {
+        for(xs = xSrc, xd = xDst; xs < xSrc+width; xs++, xd++)
+        {
+            /* reads source pixel, calculates and & xor values
+               write it back on destination bmp */
+            c = srcBmp->funcs->get_pixel_rgb(srcBmp, xs, ys);
+/* it should be...
+            _DIBDRV_calc_and_xor_masks(rop, c, &and, &xor);
+   but full 256 ROP not yet implemented, so we force COPY by now */
+            and = 0;
+            xor = c;
+            dstBmp->funcs->set_pixel(dstBmp, xd, yd, and, xor);
+        }
+    }
+
+    return TRUE;
+}
+
+/***********************************************************************
+ *           DIBDRV_PatBlt
+ */
+BOOL DIBDRV_PatBlt( DIBDRVPHYSDEV *physDev, INT left, INT top, INT width, INT \
height, DWORD rop ) +{
+    INT i;
+    DWORD old_rop2;
+    
+    TRACE("%p %d,%d %dx%d %06x\n", physDev, left, top, width, height, rop);
+
+    if(rop_uses_src(rop)) return FALSE;
+
+    old_rop2 = SetROP2(physDev->hdc, get_rop2_from_rop(rop));
+
+    for (i = 0; i < height; i++)
+        physDev->brush_hline(physDev, left, left + width, top + i);
+
+    SetROP2(physDev->hdc, old_rop2);
+
+    return TRUE;
+}
diff --git a/dlls/winedib.drv/bitmap.c b/dlls/winedib.drv/bitmap.c
new file mode 100644
index 0000000..e9f5792
--- /dev/null
+++ b/dlls/winedib.drv/bitmap.c
@@ -0,0 +1,400 @@
+/*
+ * DIB driver bitmap objects
+ *
+ * Copyright 2007 Jesse Allen
+ * Copyright 2008 Huw Davies
+ * Copyright 2008 Massimo Del Fedele
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#include "config.h"
+#include "wine/port.h"
+
+#include "dibdrv.h"
+
+WINE_DEFAULT_DEBUG_CHANNEL(dibdrv);
+
+/* calculates shift and length given a bit mask */
+static void calc_shift_and_len(DWORD mask, int *shift, int *len)
+{
+    int s, l;
+
+    /* FIXME----*/
+    if(mask == 0)
+    {
+        FIXME("color mask == 0 -- problem on init_dib\n");
+        *shift = 0;
+        *len = 0;
+        return;
+    }
+    
+    /* calculates bit shift
+       (number of 0's on right of bit field */
+    s = 0;
+    while ((mask & 1) == 0)
+    {
+        mask >>= 1;
+        s++;
+    }
+    
+    /* calculates bitfield length
+       (number of 1's in bit field */
+    l = 0;
+    while ((mask & 1) == 1)
+    {
+        mask >>= 1;
+        l++;
+    }
+    *shift = s;
+    *len = l;
+}
+
+/* initializes bit fields from bit masks */
+static void init_bit_fields(DIBDRVBITMAP *dib, const DWORD *bit_fields)
+{
+    dib->red_mask    = bit_fields[0];
+    dib->green_mask  = bit_fields[1];
+    dib->blue_mask   = bit_fields[2];
+    calc_shift_and_len(dib->red_mask,   &dib->red_shift,   &dib->red_len);
+    calc_shift_and_len(dib->green_mask, &dib->green_shift, &dib->green_len);
+    calc_shift_and_len(dib->blue_mask,  &dib->blue_shift,  &dib->blue_len);
+}
+
+/* initializes dib from a bitmap : 
+    dib           dib being initialized
+    bi            source BITMAPINFOHEADER with required DIB format info
+    bit_fields    color masks
+    color_table   color table, if any
+    bits          pointer to image data array
+*/
+BOOL _DIBDRV_init_dib(DIBDRVBITMAP *dib, const BITMAPINFOHEADER *bi, const DWORD \
*bit_fields, +                      const RGBQUAD *color_table, void *bits)
+{
+    /* initializes DIB dimensions and color depth */
+    dib->bit_count = bi->biBitCount;
+    dib->width     = bi->biWidth;
+    dib->height    = bi->biHeight;
+    dib->stride    = ((dib->width * dib->bit_count + 31) >> 3) & ~3;
+
+    /* initializes image data pointer */
+    dib->bits      = bits;
+
+    /* initializes color table */
+    dib->color_table_size = 0;
+    dib->color_table = NULL;
+
+    /* checks whether dib is top-down or bottom-up one */
+    if(dib->height < 0)
+    {
+         /* top-down dib */
+        dib->height = -dib->height;
+    }
+    else
+    {
+        /* bottom-up dib */
+        /* data->bits always points to the top-left corner and the stride is -ve */
+        dib->bits    = (BYTE*)dib->bits + (dib->height - 1) * dib->stride;
+        dib->stride  = -dib->stride;
+    }
+
+    /* gets and stores bitmap format */
+    switch(dib->bit_count)
+    {
+    case 24:
+        dib->format = DIBFMT_DIB24;
+        dib->funcs = &DIBDRV_funcs_888;
+        break;
+
+    case 32:
+    
+        if(bi->biCompression == BI_RGB)
+        {
+            dib->format = DIBFMT_X8B8G8R8;
+            dib->funcs = &DIBDRV_funcs_8888;
+        }
+        else
+        {
+            init_bit_fields(dib, bit_fields);
+            dib->format = DIBFMT_DIB32;
+            dib->funcs = &DIBDRV_funcs_32;
+        }
+        break;
+        
+    case 16:
+        if(bi->biCompression == BI_RGB)
+        {
+            init_bit_fields(dib, bit_fields);
+            if(dib->red_mask == 0x7c00 && dib->green_mask == 0x03e0 && \
dib->blue_mask == 0x001f) +            {
+                dib->format = DIBFMT_X1B5G5R5;
+                dib->funcs = &DIBDRV_funcs_555;
+            }
+            else
+            {
+                dib->format = DIBFMT_X1B5G6R5;
+                dib->funcs = &DIBDRV_funcs_565;
+            }
+        }
+        else
+        {
+            init_bit_fields(dib, bit_fields);
+            dib->format = DIBFMT_DIB16;
+            dib->funcs = &DIBDRV_funcs_16;
+        }
+        break;
+
+
+    case 8:
+        dib->format = DIBFMT_DIB8;
+        dib->funcs = &DIBDRV_funcs_8;
+        dib->color_table_size = 256;
+        if(bi->biClrUsed) dib->color_table_size = bi->biClrUsed;
+        break;
+
+    case 4:
+        dib->format = DIBFMT_DIB4;
+        dib->funcs = &DIBDRV_funcs_4;
+        dib->color_table_size = 16;
+        if(bi->biClrUsed) dib->color_table_size = bi->biClrUsed;
+        break;
+
+    case 1:
+        dib->format = DIBFMT_DIB1;
+        dib->funcs = &DIBDRV_funcs_1;
+        dib->color_table_size = 2;
+        if(bi->biClrUsed) dib->color_table_size = bi->biClrUsed;
+        break;
+
+    default:
+        dib->format = DIBFMT_UNKNOWN;
+        dib->funcs = NULL;
+        FIXME("bpp %d not supported\n", dib->bit_count);
+        return FALSE;
+    }
+
+    /* sets up the color table, if needed */
+    if(dib->color_table_size)
+    {
+        DWORD size = dib->color_table_size * sizeof(dib->color_table[0]);
+        dib->color_table = HeapAlloc(GetProcessHeap(), 0, size);
+        if(color_table)
+            memcpy(dib->color_table, color_table, size);
+        else
+            memset(dib->color_table, 0, size);
+    }
+    
+    return TRUE;
+}
+
+BOOL _DIBDRV_init_dib_from_BITMAPINFO(DIBDRVBITMAP *dib, BITMAPINFO *bmi)
+{
+    static const DWORD bit_fields_8888[3] = {0xff0000, 0x00ff00, 0x0000ff};
+    static const DWORD bit_fields_555[3] = {0x7c00, 0x03e0, 0x001f};
+    BITMAPINFOHEADER *bi = (BITMAPINFOHEADER *)bmi;
+    const DWORD *masks = NULL;
+    RGBQUAD *color_table = NULL;
+    BYTE *ptr = (BYTE*)bmi + bi->biSize;
+    int num_colors = bi->biClrUsed;
+
+    if(bi->biCompression == BI_BITFIELDS)
+    {
+        masks = (DWORD *)ptr;
+        ptr += 3 * sizeof(DWORD);
+    }
+    else if(bi->biBitCount == 32)
+        masks = bit_fields_8888;
+    else if(bi->biBitCount == 16)
+        masks = bit_fields_555;
+
+    if(!num_colors && bi->biBitCount <= 8) num_colors = 1 << bi->biBitCount;
+    if(num_colors) color_table = (RGBQUAD*)ptr;
+    ptr += num_colors * sizeof(*color_table);
+
+    return _DIBDRV_init_dib(dib, bi, masks, color_table, ptr);
+}
+
+void _DIBDRV_copy_dib_color_info(const DIBDRVBITMAP *src, DIBDRVBITMAP *dst)
+{
+    dst->bit_count        = src->bit_count;
+    dst->red_mask         = src->red_mask;
+    dst->green_mask       = src->green_mask;
+    dst->blue_mask        = src->blue_mask;
+    dst->red_len          = src->red_len;
+    dst->green_len        = src->green_len;
+    dst->blue_len         = src->blue_len;
+    dst->red_shift        = src->red_shift;
+    dst->green_shift      = src->green_shift;
+    dst->blue_shift       = src->blue_shift;
+    dst->funcs            = src->funcs;
+    dst->color_table_size = src->color_table_size;
+    dst->color_table      = NULL;
+    if(dst->color_table_size)
+    {
+        int size = dst->color_table_size * sizeof(dst->color_table[0]);
+        dst->color_table = HeapAlloc(GetProcessHeap(), 0, dst->color_table_size * \
sizeof(dst->color_table[0])); +        memcpy(dst->color_table, src->color_table, \
size); +    }
+}
+
+/* checks whether the format of 2 DIBs are identical
+   it checks the pixel bit count and the color table size
+   and content, if needed */
+static BOOL dib_formats_match(const DIBDRVBITMAP *d1, const DIBDRVBITMAP *d2)
+{
+    /* checks at first the format (bit count and color masks) */
+    if(d1->format != d2->format)
+        return FALSE;
+    
+    /* formats matches, now checks color tables if needed */
+    switch(d1->format)
+    {
+        case DIBFMT_DIB16 :
+        case DIBFMT_DIB24 :
+        case DIBFMT_DIB32 :
+        case DIBFMT_X1B5G5R5 :
+        case DIBFMT_X1B5G6R5 :
+        case DIBFMT_X8B8G8R8 :
+            return TRUE;
+
+        case DIBFMT_DIB1 :
+        case DIBFMT_DIB4 :
+        /*case DIBFMT_DIB4RLE :*/
+        case DIBFMT_DIB8 :
+        /*case DIBFMT_DIB8RLE :*/
+            if(d1->color_table_size != d2->color_table_size)
+                return FALSE;
+            return !memcmp(d1->color_table, d2->color_table, d1->color_table_size * \
sizeof(d1->color_table[0])); +
+        default:
+            ERR("Unexpected depth %d\n", d1->bit_count);
+            return FALSE;
+    }
+}
+
+/* convert a given dib into another format.
+   We could spilt this into two and have convert_to_8888 and convert_from_8888
+   as functions in the primitive function table */
+void _DIBDRV_convert_dib(const DIBDRVBITMAP *src, DIBDRVBITMAP *dst)
+{
+    DWORD color, pixel;
+    COLORREF color_ref;
+    int x, y;
+
+    dst->height = src->height;
+    dst->width = src->width;
+    dst->stride = ((dst->width * dst->bit_count + 31) >> 3) & ~3;
+    dst->bits = HeapAlloc(GetProcessHeap(), 0, dst->height * dst->stride);
+
+    if(dib_formats_match(src, dst))
+    {
+        if(src->stride > 0)
+            memcpy(dst->bits, src->bits, dst->height * dst->stride);
+        else
+        {
+            BYTE *src_bits = src->bits;
+            BYTE *dst_bits = dst->bits;
+            for(y = 0; y < dst->height; y++)
+            {
+                memcpy(dst_bits, src_bits, dst->stride);
+                dst_bits += dst->stride;
+                src_bits += src->stride;
+            }
+        }
+        return;
+    }
+
+    for(y = 0; y < src->height; y++)
+    {
+        for(x = 0; x < src->width; x++)
+        {
+            color = src->funcs->get_pixel_rgb(src, x, y);
+            color_ref = RGB((color >> 16), (color >> 8), color);
+            pixel = dst->funcs->colorref_to_pixel(dst, color_ref);
+            dst->funcs->set_pixel(dst, x, y, 0, pixel);
+        }
+    }
+    return;
+}
+
+/****************************************************************************
+ *       SelectBitmap   (WINEDIB.DRV.@)
+ */
+HBITMAP DIBDRV_SelectBitmap( DIBDRVPHYSDEV *physDev, HBITMAP hbitmap )
+{
+    DIBSECTION ds;
+
+    if(GetObjectW(hbitmap, sizeof(ds), &ds) == sizeof(BITMAP))
+    {
+        /* Stock bitmap */
+        ds.dsBmih.biWidth = 1;
+        ds.dsBmih.biHeight = 1;
+        ds.dsBmih.biBitCount = 1;
+        ds.dsBmih.biClrUsed = 0;
+        ds.dsBm.bmBits = NULL;
+    }
+
+    if(physDev->bmp.color_table != NULL)
+        HeapFree(GetProcessHeap(), 0, physDev->bmp.color_table);
+    physDev->bmp.color_table = NULL;
+
+    _DIBDRV_init_dib(&physDev->bmp, &ds.dsBmih, ds.dsBitfields, NULL, \
ds.dsBm.bmBits); +
+    return hbitmap;
+}
+
+/****************************************************************************
+ *        DIBDRV_CreateBitmap
+ */
+BOOL DIBDRV_CreateBitmap( DIBDRVPHYSDEV *physDev, HBITMAP hbitmap, LPVOID bmBits )
+{
+#ifdef DIBDRV_SHOW_STUBS
+    FIXME("stub\n");
+#endif
+    return TRUE;
+}
+
+/***********************************************************************
+ *           DIBDRV_DeleteBitmap
+ */
+BOOL DIBDRV_DeleteBitmap( HBITMAP hbitmap )
+{
+#ifdef DIBDRV_SHOW_STUBS
+    FIXME("stub\n");
+#endif
+    return TRUE;
+}
+
+/***********************************************************************
+ *           DIBDRV_GetBitmapBits
+ */
+LONG DIBDRV_GetBitmapBits( HBITMAP hbitmap, void *buffer, LONG count )
+{
+#ifdef DIBDRV_SHOW_STUBS
+    FIXME("stub\n");
+#endif
+    return 0;
+}
+
+/******************************************************************************
+ *             DIBDRV_SetBitmapBits
+ */
+LONG DIBDRV_SetBitmapBits( HBITMAP hbitmap, const void *bits, LONG count )
+{
+#ifdef DIBDRV_SHOW_STUBS
+    FIXME("stub\n");
+#endif
+    return 0;
+}
diff --git a/dlls/winedib.drv/clipping.c b/dlls/winedib.drv/clipping.c
new file mode 100644
index 0000000..c084492
--- /dev/null
+++ b/dlls/winedib.drv/clipping.c
@@ -0,0 +1,37 @@
+/*
+ * DIBDRV clipping functions
+ *
+ * Copyright 2007 Jesse Allen
+ * Copyright 2008 Massimo Del Fedele
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#include "config.h"
+#include "wine/port.h"
+
+#include "dibdrv.h"
+
+WINE_DEFAULT_DEBUG_CHANNEL(dibdrv);
+
+/***********************************************************************
+ *           DIBDRV_SetDeviceClipping
+ */
+void DIBDRV_SetDeviceClipping( DIBDRVPHYSDEV *physDev, HRGN vis_rgn, HRGN clip_rgn )
+{
+#ifdef DIBDRV_SHOW_STUBS
+    FIXME("stub\n");
+#endif
+}
diff --git a/dlls/winedib.drv/dib.c b/dlls/winedib.drv/dib.c
new file mode 100644
index 0000000..0145ece
--- /dev/null
+++ b/dlls/winedib.drv/dib.c
@@ -0,0 +1,106 @@
+/*
+ * DIBDRV device-independent bitmaps
+ *
+ * Copyright 2007 Jesse Allen
+ * Copyright 2008 Massimo Del Fedele
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#include "config.h"
+#include "wine/port.h"
+
+#include "dibdrv.h"
+
+WINE_DEFAULT_DEBUG_CHANNEL(dibdrv);
+
+/***********************************************************************
+ *           DIBDRV_CreateDIBSection
+ */
+HBITMAP DIBDRV_CreateDIBSection( DIBDRVPHYSDEV *physDev, HBITMAP hbitmap,
+                                 const BITMAPINFO *bmi, UINT usage )
+{
+#ifdef DIBDRV_SHOW_STUBS
+    FIXME("stub\n");
+#endif
+    return hbitmap;
+}
+
+/***********************************************************************
+ *           DIBDRV_GetDIBits
+    physDev
+        [in] Handle to the device context. 
+    hbitmap
+        [in] Handle to the bitmap. This must be a compatible bitmap (DDB).
+    startscan
+        [in] Specifies the first scan line to retrieve. 
+    lines
+        [in] Specifies the number of scan lines to retrieve. 
+    bits
+        [out] Pointer to a buffer to receive the bitmap data. If this parameter is \
NULL, the function passes the dimensions and format of the bitmap to the BITMAPINFO \
structure pointed to by the lpbi parameter.  +    bmi
+        [in/out] Pointer to a BITMAPINFO structure that specifies the desired format \
for the DIB data.  +    coloruse
+        [in] Specifies the format of the bmiColors member of the BITMAPINFO \
structure. It must be one of the following values. +        Value   Meaning
+        DIB_PAL_COLORS  The color table should consist of an array of 16-bit indexes \
into the current logical palette. +        DIB_RGB_COLORS  The color table should \
consist of literal red, green, blue (RGB) values. +*/
+INT DIBDRV_GetDIBits( DIBDRVPHYSDEV *physDev, HBITMAP hbitmap, UINT startscan,
+                      UINT lines, LPCVOID bits, const BITMAPINFO *bmi, UINT coloruse \
) +{
+#ifdef DIBDRV_SHOW_STUBS
+    FIXME("uhm... shouldn't be handled by winex11 ??\n");
+#endif
+    return 0;
+}
+
+/***********************************************************************
+ *           DIBDRV_SetDIBColorTable
+ */
+UINT DIBDRV_SetDIBColorTable( DIBDRVPHYSDEV *physDev, UINT start, UINT count,
+                              const RGBQUAD *colors )
+{
+#ifdef DIBDRV_SHOW_STUBS
+    FIXME("stub\n");
+#endif
+    return 0;
+}
+
+/***********************************************************************
+ *           DIBDRV_SetDIBits
+ */
+INT DIBDRV_SetDIBits( DIBDRVPHYSDEV *physDev, HBITMAP hbitmap, UINT startscan,
+                      UINT lines, LPCVOID bits, const BITMAPINFO *info, UINT \
coloruse ) +{
+#ifdef DIBDRV_SHOW_STUBS
+    FIXME("uhm... shouldn't be handled by winex11 ??\n");
+#endif
+    return 0;
+}
+
+/*************************************************************************
+ *              DIBDRV_SetDIBitsToDevice
+ */
+INT DIBDRV_SetDIBitsToDevice( DIBDRVPHYSDEV *physDev, INT xDest, INT yDest, DWORD \
cx, +                              DWORD cy, INT xSrc, INT ySrc,
+                              UINT startscan, UINT lines, LPCVOID bits,
+                              const BITMAPINFO *info, UINT coloruse )
+{
+#ifdef DIBDRV_SHOW_STUBS
+    FIXME("uhm... shouldn't be handled by winex11 ??\n");
+#endif
+    return 0;
+}
diff --git a/dlls/winedib.drv/dibdrv.h b/dlls/winedib.drv/dibdrv.h
new file mode 100644
index 0000000..97c0d03
--- /dev/null
+++ b/dlls/winedib.drv/dibdrv.h
@@ -0,0 +1,203 @@
+/*
+ * DIB driver private definitions
+ *
+ * Copyright 2007 Jesse Allen
+ * Copyright 2008 Huw Davies
+ * Copyright 2008 Massimo Del Fedele
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef __WINE_DIBDRV_H
+#define __WINE_DIBDRV_H
+
+#include <stdarg.h>
+#include <X11/Xlib.h>
+
+#include "windef.h"
+#include "winbase.h"
+#include "winerror.h"
+#include "wingdi.h"
+#include "wine/list.h"
+#include "wine/library.h"
+#include "wine/debug.h"
+#include "wingdi.h"
+#include "winreg.h"
+#include "wine/winbase16.h" /* GlobalLock16 */
+
+#include "freetype.h"
+
+/* Enable this if we want trace unimplemented stubs
+   That's done because logs becomes big and painting
+   slow if all FIXMEs for stubs are shown
+*/
+/* #define DIBDRV_SHOW_STUBS */
+
+/******************************************************************************************/
 +/*                                     DIB PRIMITIVES                               \
*/ +/******************************************************************************************/
 +
+/* BASIC ROP HELPER
+ * Decompose the 16 ROP2s into an expression of the form
+ *
+ * D = (D & A) ^ X
+ *
+ * Where A and X depend only on P (and so can be precomputed). */
+void _DIBDRV_calc_and_xor_masks(INT rop, DWORD color, DWORD *and, DWORD *xor);
+
+struct _DIBDRVBITMAP;
+typedef struct _DIBDRV_PRIMITIVE_FUNCS
+{
+    void  (* solid_hline)       (const struct _DIBDRVBITMAP *dib, int start, int \
end, int row, DWORD and, DWORD xor); +    void  (* pattern_hline)     (const struct \
_DIBDRVBITMAP *dib, int start, int end, int row, const void *and, const void *xor, \
DWORD count, DWORD offset); +    void  (* solid_vline)       (const struct \
_DIBDRVBITMAP *dib, int col, int start, int end, DWORD and, DWORD xor); +    void* (* \
get_pixel_ptr)     (const struct _DIBDRVBITMAP *dib, int x, int y); +    void  (* \
set_pixel)         (const struct _DIBDRVBITMAP *dib, int x, int y, DWORD and, DWORD \
xor); +    DWORD (* get_pixel_rgb)     (const struct _DIBDRVBITMAP *dib, int x, int \
y); +    DWORD (* colorref_to_pixel) (const struct _DIBDRVBITMAP *dib, COLORREF \
color); +    void  (* freetype_blit)     (const struct _DIBDRVBITMAP *dib, int x, int \
y, FT_Bitmap *bmp); +
+} DIBDRV_PRIMITIVE_FUNCS;
+
+extern DIBDRV_PRIMITIVE_FUNCS DIBDRV_funcs_8888;
+extern DIBDRV_PRIMITIVE_FUNCS DIBDRV_funcs_32;
+extern DIBDRV_PRIMITIVE_FUNCS DIBDRV_funcs_888;
+extern DIBDRV_PRIMITIVE_FUNCS DIBDRV_funcs_555;
+extern DIBDRV_PRIMITIVE_FUNCS DIBDRV_funcs_565;
+extern DIBDRV_PRIMITIVE_FUNCS DIBDRV_funcs_16;
+extern DIBDRV_PRIMITIVE_FUNCS DIBDRV_funcs_8;
+extern DIBDRV_PRIMITIVE_FUNCS DIBDRV_funcs_4;
+extern DIBDRV_PRIMITIVE_FUNCS DIBDRV_funcs_1;
+
+/******************************************************************************************/
 +
+typedef enum _DIBFORMAT
+{
+    DIBFMT_UNKNOWN          =   0,
+    DIBFMT_DIB1             =   1,
+    DIBFMT_DIB4             =   2,
+    /*DIBFMT_DIB4RLE          =   3,*/
+    DIBFMT_DIB8             =   4,
+    /*DIBFMT_DIB8RLE          =   5,*/
+    DIBFMT_DIB16            =   6,
+    DIBFMT_DIB24            =   7,
+    DIBFMT_DIB32            =   8,
+    DIBFMT_X1B5G5R5         =   9,
+    DIBFMT_X1B5G6R5         =  10,
+    DIBFMT_X8B8G8R8         =  11
+} DIBFORMAT;
+
+/* DIB driver's generic bitmap structure */
+typedef struct _DIBDRVBITMAP
+{
+    /* bitmap format of dib */
+    DIBFORMAT format;
+
+    /* pointer to top left corner of bitmap */
+    void *bits;
+
+    /* bitmap dimensions */
+    INT width;
+    INT height;
+
+    /* bitmap stride (== width in bytes) of a bitmap line */
+    /* negative for a bottom-up bitmap */
+    INT stride;
+
+    /* size in bits of a pixel */
+    INT size;
+    
+    /* number of bits in bitmap */
+    INT bit_count;
+
+    /* calculated numbers for bitfields */
+    DWORD red_mask, green_mask, blue_mask;
+    int red_shift, green_shift, blue_shift; /* shifting required within a COLORREF's \
BYTE */ +    int red_len, green_len, blue_len;       /* size of the field */
+
+    /* color table and its size */
+    RGBQUAD *color_table;
+    DWORD color_table_size;
+
+    /* text color table for antialiased fonts */
+    COLORREF textColorTable[256];
+
+   /* current drawing address */
+    void *addr;
+    INT shift;
+
+    /* primitive function pointers */
+    DIBDRV_PRIMITIVE_FUNCS *funcs;
+
+} DIBDRVBITMAP;
+
+/* dash patterns */
+typedef struct
+{
+    DWORD count;
+    DWORD dashes[6];
+} dash_pattern_t;
+
+/* DIB driver physical device */
+typedef struct _DIBDRVPHYSDEV
+{
+    /* device context */
+    HDC hdc;
+
+    /* windows bitmap handle */
+    HBITMAP hbitmap;
+
+    /* dib bitmap info */
+    DIBDRVBITMAP bmp;
+
+    /* pen */
+    COLORREF pen_colorref;
+    DWORD pen_color, pen_and, pen_xor;
+    const dash_pattern_t *pen_pattern;
+    DWORD cur_dash, left_in_dash;
+    enum mark_space { mark, space } mark_space;
+
+    /* brush */
+    COLORREF brush_colorref;
+    DWORD brush_color, brush_and, brush_xor;
+    DIBDRVBITMAP brush_dib;
+    void *brush_and_bits, *brush_xor_bits;
+
+    /* bkgnd */
+    DWORD bkgnd_color, bkgnd_and, bkgnd_xor;
+
+    /* pen drawing functions */
+    void (* pen_hline)(struct _DIBDRVPHYSDEV *pdev, int start, int end, int row);
+    void (* pen_vline)(struct _DIBDRVPHYSDEV *pdev, int col, int start, int end);
+    void (* pen_line)(struct _DIBDRVPHYSDEV *pdev, int x1, int y1, int x2, int y2);
+    void (* brush_hline)(struct _DIBDRVPHYSDEV *pdev, int start, int end, int row);
+    
+    /* text color */
+    COLORREF textColor;
+
+    /* freetype face associated to current DC HFONT */
+    FT_Face face;
+
+} DIBDRVPHYSDEV;
+
+BOOL _DIBDRV_init_dib(DIBDRVBITMAP *dib, const BITMAPINFOHEADER *bi, const DWORD \
*bit_fields, +                      const RGBQUAD *color_table, void *bits);
+BOOL _DIBDRV_init_dib_from_BITMAPINFO(DIBDRVBITMAP *dib, BITMAPINFO *bmi);
+void _DIBDRV_copy_dib_color_info(const DIBDRVBITMAP *src, DIBDRVBITMAP *dst);
+void _DIBDRV_convert_dib(const DIBDRVBITMAP *src, DIBDRVBITMAP *dst);
+void _DIBDRV_reset_dash_origin(DIBDRVPHYSDEV *physDev);
+INT DIBDRV_GetDeviceCaps( DIBDRVPHYSDEV *physDev, INT cap );
+COLORREF DIBDRV_SetTextColor( DIBDRVPHYSDEV *physDev, COLORREF color );
+
+#endif /* __WINE_DIBDRV_H */
diff --git a/dlls/winedib.drv/dibdrv_main.c b/dlls/winedib.drv/dibdrv_main.c
new file mode 100644
index 0000000..2473056
--- /dev/null
+++ b/dlls/winedib.drv/dibdrv_main.c
@@ -0,0 +1,63 @@
+/*
+ * DIBDRV initialization code
+ *
+ * Copyright 2007 Jesse Allen
+ * Copyright 2008 Massimo Del Fedele
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#include "config.h"
+#include "wine/port.h"
+
+#include "dibdrv.h"
+
+WINE_DEFAULT_DEBUG_CHANNEL(dibdrv);
+
+/***********************************************************************
+ *           DIBDRV initialization routine
+ */
+BOOL WINAPI DllMain( HINSTANCE hinst, DWORD reason, LPVOID reserved )
+{
+    BOOL ret = TRUE;
+
+    switch(reason)
+    {
+    case DLL_PROCESS_ATTACH:
+        /* do attach */
+
+#ifdef HAVE_FREETYPE
+        /* initializes freetype library */
+        if(!_DIBDRV_FreeType_Init())
+        {
+            ERR("Couldn't initialize freetype library.\n");
+        }
+
+#endif /* HAVE_FREETYPE */
+        break;
+    case DLL_THREAD_DETACH:
+        /* do thread detach */
+        break;
+    case DLL_PROCESS_DETACH:
+        /* do detach */
+
+#ifdef HAVE_FREETYPE
+        /* terminates freetype library */
+        _DIBDRV_FreeType_Terminate();
+#endif /* HAVE_FREETYPE */
+        break;
+    }
+    return ret;
+}
diff --git a/dlls/winedib.drv/font.c b/dlls/winedib.drv/font.c
new file mode 100644
index 0000000..7de4556
--- /dev/null
+++ b/dlls/winedib.drv/font.c
@@ -0,0 +1,171 @@
+/*
+ * DIBDRV font objects
+ *
+ * Copyright 2007 Jesse Allen
+ * Copyright 2008 Massimo Del Fedele
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ *
+ */
+
+#include "config.h"
+#include "wine/port.h"
+
+#include "dibdrv.h"
+
+WINE_DEFAULT_DEBUG_CHANNEL(dibdrv);
+
+/**********************************************************************
+ *          DIBDRV_SetTextColor
+ */
+COLORREF DIBDRV_SetTextColor( DIBDRVPHYSDEV *physDev, COLORREF color )
+{
+    COLORREF oldColor;
+    INT r, g, b;
+    INT i;
+
+    /* do nothing if color is the same as actual one */
+    if(color == physDev->textColor)
+        return color;
+    
+    /* stores old color */
+    oldColor = physDev->textColor;
+    
+    /* fills the text color table used on antialiased font display */
+    if(physDev->bmp.funcs)
+    {
+        r = GetRValue(color);
+        g = GetGValue(color);
+        b = GetBValue(color);
+        for(i = 0; i < 256; i++)
+        {
+            physDev->bmp.textColorTable[i] = \
physDev->bmp.funcs->colorref_to_pixel(&physDev->bmp, RGB( +                MulDiv(r, \
i, 256), +                MulDiv(g, i, 256),
+                MulDiv(b, i, 256)
+            ));
+            
+        }
+    }
+    
+    /* returns previous text color */
+    return oldColor;
+}
+
+/***********************************************************************
+ *           DIBDRV_SelectFont
+ */
+HFONT DIBDRV_SelectFont( DIBDRVPHYSDEV *physDev, HFONT hfont, GdiFont *gdiFont )
+{
+    FT_Int      i;
+    FT_Error    error;
+    FT_CharMap  charmap = NULL;
+    LOGFONTW lf;
+    GdiFont *curFont;
+    
+    /* gets font information */
+    GetObjectW(hfont, sizeof(lf), &lf);
+    TRACE("Font is : '%s'\n", debugstr_w(lf.lfFaceName));
+    
+    /* FIXME: just handles gdifont, don't know if it needs to handle hfont too
+       BTW, still don't know how to get FT_Face from non-gdi font here
+    */
+    if(!gdiFont)
+    {
+        FIXME("No gdi font - unhandled by now.\n");
+        return hfont;
+    }
+
+    /* scans gdi font list in order to find correct HFONT
+       I guess it should be a better way.... */
+    physDev->face = 0;
+    LIST_FOR_EACH_ENTRY(curFont, &gdiFont->entry, struct tagGdiFont, entry)
+    {
+        if(!lstrcmpW(lf.lfFaceName, curFont->name))
+        {
+            /* stores current font face in physDev */
+            physDev->face = curFont->ft_face;
+        }
+    }
+    if(!physDev->face)
+    {
+        FIXME("Error, null Ft_Face\n");
+        return hfont;
+    }
+
+    /* setup the correct charmap.... maybe */
+    for (i = 0; i < physDev->face->num_charmaps; ++i)
+    {
+        if (physDev->face->charmaps[i]->platform_id != TT_PLATFORM_MICROSOFT)
+        continue;
+
+        if (physDev->face->charmaps[i]->encoding_id == TT_MS_ID_UNICODE_CS)
+        {
+            charmap = physDev->face->charmaps[i];
+            break;
+        }
+
+        if (charmap == NULL)
+        {
+            WARN("Selected fallout charmap #%d\n", i);
+            charmap = physDev->face->charmaps[i];
+        }
+    }
+    if (charmap == NULL)
+    {
+        WARN("No Windows character map found\n");
+        charmap = physDev->face->charmaps[0];
+        return FALSE;
+    }
+
+    error = pFT_Set_Charmap(physDev->face, charmap);
+    if (error != FT_Err_Ok)
+    {
+        ERR("%s returned %i\n", "FT_Set_Charmap", error);
+        return FALSE;
+    }
+
+    /* we use GDI fonts, so just return false */
+    return 0;
+}
+
+/***********************************************************************
+ *           DIBDRV_EnumDeviceFonts
+ */
+BOOL DIBDRV_EnumDeviceFonts( DIBDRVPHYSDEV *physDev, LPLOGFONTW plf,
+                             FONTENUMPROCW proc, LPARAM lp )
+{
+    /* don't enumerate x11 fonts, we're using client side fonts */
+    return FALSE;
+}
+
+/***********************************************************************
+ *           DIBDRV_GetTextMetrics
+ */
+BOOL DIBDRV_GetTextMetrics( DIBDRVPHYSDEV *physDev, TEXTMETRICW *metrics )
+{
+    /* no need for this one, as we use GDI fonts */
+    return FALSE;
+}
+
+/***********************************************************************
+ *           DIBDRV_GetCharWidth
+ */
+BOOL DIBDRV_GetCharWidth( DIBDRVPHYSDEV *physDev, UINT firstChar, UINT lastChar,
+                          LPINT buffer )
+{
+    /* no need for this one, as we use GDI fonts */
+    return FALSE;
+}
diff --git a/dlls/winedib.drv/freetype.c b/dlls/winedib.drv/freetype.c
new file mode 100644
index 0000000..b4a3ccc
--- /dev/null
+++ b/dlls/winedib.drv/freetype.c
@@ -0,0 +1,134 @@
+/*
+ * Truetype font functions
+ *
+ * Copyright 2008 Massimo Del Fedele
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#include "config.h"
+#include "wine/port.h"
+
+#include "dibdrv.h"
+
+WINE_DEFAULT_DEBUG_CHANNEL(dibdrv);
+
+#define MAKE_FUNCPTR(f) typeof(f) * p##f = NULL;
+MAKE_FUNCPTR(FT_Done_Face)
+MAKE_FUNCPTR(FT_Done_FreeType)
+MAKE_FUNCPTR(FT_Get_Char_Index)
+MAKE_FUNCPTR(FT_Get_Glyph_Name)
+MAKE_FUNCPTR(FT_Get_Sfnt_Name)
+MAKE_FUNCPTR(FT_Get_Sfnt_Name_Count)
+MAKE_FUNCPTR(FT_Get_Sfnt_Table)
+MAKE_FUNCPTR(FT_Init_FreeType)
+MAKE_FUNCPTR(FT_Load_Glyph)
+MAKE_FUNCPTR(FT_Load_Char)
+MAKE_FUNCPTR(FT_Get_Glyph)
+MAKE_FUNCPTR(FT_Glyph_Copy)
+MAKE_FUNCPTR(FT_Glyph_To_Bitmap)
+MAKE_FUNCPTR(FT_Done_Glyph)
+MAKE_FUNCPTR(FT_New_Face)
+MAKE_FUNCPTR(FT_Set_Charmap)
+MAKE_FUNCPTR(FT_Set_Char_Size)
+MAKE_FUNCPTR(FT_Get_First_Char)
+MAKE_FUNCPTR(FT_Render_Glyph)
+MAKE_FUNCPTR(FT_Glyph_Transform)
+#undef MAKE_FUNCPTR
+
+/* freetype initialization flag */
+static BOOL FreeType_Initialized = FALSE;
+
+/* freetype dll handle */
+static void *ft_handle = NULL;
+
+/* freetype library handle */
+FT_Library DIBDRV_ftLibrary = NULL;
+
+/* initialize freetype library */
+BOOL _DIBDRV_FreeType_Init(void)
+{
+    FT_Int error;
+    
+    ft_handle = wine_dlopen(SONAME_LIBFREETYPE, RTLD_NOW, NULL, 0);
+    if(!ft_handle)
+    {
+        WINE_MESSAGE(
+            "Wine cannot find the FreeType font library.  To enable Wine to\n"
+            "use TrueType fonts please install a version of FreeType greater than\n"
+            "or equal to 2.0.5.\n"
+            "http://www.freetype.org\n");
+        return FALSE;
+    }
+
+#define LOAD_FUNCPTR(f) if((p##f = wine_dlsym(ft_handle, #f, NULL, 0)) == NULL) goto \
sym_not_found; +    LOAD_FUNCPTR(FT_Done_Face)
+    LOAD_FUNCPTR(FT_Done_FreeType)
+    LOAD_FUNCPTR(FT_Get_Char_Index)
+    LOAD_FUNCPTR(FT_Get_Glyph_Name)
+    LOAD_FUNCPTR(FT_Get_Sfnt_Name)
+    LOAD_FUNCPTR(FT_Get_Sfnt_Name_Count)
+    LOAD_FUNCPTR(FT_Get_Sfnt_Table)
+    LOAD_FUNCPTR(FT_Init_FreeType)
+    LOAD_FUNCPTR(FT_Load_Glyph)
+    LOAD_FUNCPTR(FT_Load_Char)
+    LOAD_FUNCPTR(FT_Get_Glyph)
+    LOAD_FUNCPTR(FT_Glyph_Copy)
+    LOAD_FUNCPTR(FT_Glyph_To_Bitmap)
+    LOAD_FUNCPTR(FT_Done_Glyph)
+    LOAD_FUNCPTR(FT_New_Face)
+    LOAD_FUNCPTR(FT_Set_Charmap)
+    LOAD_FUNCPTR(FT_Set_Char_Size)
+    LOAD_FUNCPTR(FT_Get_First_Char)
+    LOAD_FUNCPTR(FT_Render_Glyph)
+    LOAD_FUNCPTR(FT_Glyph_Transform)
+#undef LOAD_FUNCPTR
+
+    error = pFT_Init_FreeType(&DIBDRV_ftLibrary);
+    if (error != FT_Err_Ok)
+    {
+        ERR("%s returned %i\n", "FT_Init_FreeType", error);
+        wine_dlclose(ft_handle, NULL, 0);
+        return FALSE;
+    }
+
+    /* marks library as initialized */
+    FreeType_Initialized = TRUE;
+
+    return TRUE;
+    
+sym_not_found:
+    WINE_MESSAGE(
+      "Wine cannot find certain functions that it needs inside the FreeType\n"
+      "font library.  To enable Wine to use TrueType fonts please upgrade\n"
+      "FreeType to at least version 2.0.5.\n"
+      "http://www.freetype.org\n");
+    wine_dlclose(ft_handle, NULL, 0);
+    ft_handle = NULL;
+    return FALSE;
+}
+
+/* terminates freetype library */
+void _DIBDRV_FreeType_Terminate(void)
+{
+    if(!FreeType_Initialized)
+        return;
+    
+    /* terminates and unload freetype library */
+    pFT_Done_FreeType(DIBDRV_ftLibrary);
+    wine_dlclose(ft_handle, NULL, 0);
+    ft_handle = NULL;
+    FreeType_Initialized = FALSE;
+    
+}
diff --git a/dlls/winedib.drv/freetype.h b/dlls/winedib.drv/freetype.h
new file mode 100644
index 0000000..1cdfa35
--- /dev/null
+++ b/dlls/winedib.drv/freetype.h
@@ -0,0 +1,185 @@
+/*
+ * Truetype font functions
+ *
+ * Copyright 2008 Massimo Del Fedele
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+#ifndef __WINE_DIBDRV_FREETYPE_H
+#define __WINE_DIBDRV__FREETYPE_H
+
+/* freetype library for font support */
+#ifdef HAVE_FREETYPE
+
+#include <ft2build.h>
+#include FT_FREETYPE_H
+#include FT_GLYPH_H
+#include FT_TRUETYPE_TABLES_H
+#include FT_SFNT_NAMES_H
+#include FT_TRUETYPE_IDS_H
+
+/* freetype library handle */
+extern FT_Library DIBDRV_ftLibrary;
+
+/******************************************************************************************/
 +/*                                     FREETYPE STUFFS                              \
*/ +/* grabbed from winex11.drv/freetype.c                                            \
*/ +/******************************************************************************************/
 +
+/* This is basically a copy of FT_Bitmap_Size with an extra element added */
+typedef struct {
+    FT_Short height;
+    FT_Short width;
+    FT_Pos size;
+    FT_Pos x_ppem;
+    FT_Pos y_ppem;
+    FT_Short internal_leading;
+} Bitmap_Size;
+
+/* FT_Bitmap_Size gained 3 new elements between FreeType 2.1.4 and 2.1.5
+   So to let this compile on older versions of FreeType we'll define the
+   new structure here. */
+typedef struct {
+    FT_Short height, width;
+    FT_Pos size, x_ppem, y_ppem;
+} My_FT_Bitmap_Size;
+
+struct enum_data
+{
+    ENUMLOGFONTEXW elf;
+    NEWTEXTMETRICEXW ntm;
+    DWORD type;
+};
+
+typedef struct tagFace {
+    struct list entry;
+    WCHAR *StyleName;
+    char *file;
+    void *font_data_ptr;
+    DWORD font_data_size;
+    FT_Long face_index;
+    FONTSIGNATURE fs;
+    FONTSIGNATURE fs_links;
+    DWORD ntmFlags;
+    FT_Fixed font_version;
+    BOOL scalable;
+    Bitmap_Size size;     /* set if face is a bitmap */
+    BOOL external; /* TRUE if we should manually add this font to the registry */
+    struct tagFamily *family;
+    /* Cached data for Enum */
+    struct enum_data *cached_enum_data;
+} Face;
+
+typedef struct tagFamily {
+    struct list entry;
+    const WCHAR *FamilyName;
+    struct list faces;
+} Family;
+
+typedef struct {
+    GLYPHMETRICS gm;
+    INT adv; /* These three hold to widths of the unrotated chars */
+    INT lsb;
+    INT bbx;
+    BOOL init;
+} GM;
+
+typedef struct {
+    FLOAT eM11, eM12;
+    FLOAT eM21, eM22;
+} FMAT2;
+
+typedef struct {
+    DWORD hash;
+    LOGFONTW lf;
+    FMAT2 matrix;
+    BOOL can_use_bitmap;
+} FONT_DESC;
+
+typedef struct tagHFONTLIST {
+    struct list entry;
+    HFONT hfont;
+} HFONTLIST;
+
+typedef struct {
+    struct list entry;
+    Face *face;
+    struct tagGdiFont *font;
+} CHILD_FONT;
+
+typedef struct tagGdiFont {
+    struct list entry;
+    GM **gm;
+    DWORD gmsize;
+    struct list hfontlist;
+    OUTLINETEXTMETRICW *potm;
+    DWORD total_kern_pairs;
+    KERNINGPAIR *kern_pairs;
+    struct list child_fonts;
+
+    /* the following members can be accessed without locking, they are never \
modified after creation */ +    FT_Face ft_face;
+    struct font_mapping *mapping;
+    LPWSTR name;
+    int charset;
+    int codepage;
+    BOOL fake_italic;
+    BOOL fake_bold;
+    BYTE underline;
+    BYTE strikeout;
+    INT orientation;
+    FONT_DESC font_desc;
+    LONG aveWidth, ppem;
+    double scale_y;
+    SHORT yMax;
+    SHORT yMin;
+    DWORD ntmFlags;
+    FONTSIGNATURE fs;
+    struct tagGdiFont *base_font;
+    VOID *GSUB_Table;
+    DWORD cache_num;
+} GdiFont;
+
+/* initialize freetype library */
+BOOL _DIBDRV_FreeType_Init(void);
+
+/* terminates freetype library */
+void _DIBDRV_FreeType_Terminate(void);
+
+#define MAKE_FUNCPTR(f) extern typeof(f) * p##f;
+MAKE_FUNCPTR(FT_Done_Face)
+MAKE_FUNCPTR(FT_Done_FreeType)
+MAKE_FUNCPTR(FT_Get_Char_Index)
+MAKE_FUNCPTR(FT_Get_Glyph_Name)
+MAKE_FUNCPTR(FT_Get_Sfnt_Name)
+MAKE_FUNCPTR(FT_Get_Sfnt_Name_Count)
+MAKE_FUNCPTR(FT_Get_Sfnt_Table)
+MAKE_FUNCPTR(FT_Init_FreeType)
+MAKE_FUNCPTR(FT_Load_Glyph)
+MAKE_FUNCPTR(FT_Load_Char)
+MAKE_FUNCPTR(FT_Get_Glyph)
+MAKE_FUNCPTR(FT_Glyph_Copy)
+MAKE_FUNCPTR(FT_Glyph_To_Bitmap)
+MAKE_FUNCPTR(FT_Done_Glyph)
+MAKE_FUNCPTR(FT_New_Face)
+MAKE_FUNCPTR(FT_Set_Charmap)
+MAKE_FUNCPTR(FT_Set_Char_Size)
+MAKE_FUNCPTR(FT_Get_First_Char)
+MAKE_FUNCPTR(FT_Render_Glyph)
+MAKE_FUNCPTR(FT_Glyph_Transform)
+#undef MAKE_FUNCPTR
+
+#endif /* HAVE_FREETYPE */
+
+#endif
diff --git a/dlls/winedib.drv/graphics.c b/dlls/winedib.drv/graphics.c
new file mode 100644
index 0000000..a67c0dc
--- /dev/null
+++ b/dlls/winedib.drv/graphics.c
@@ -0,0 +1,258 @@
+/*
+ * DIBDRV implementation of GDI driver graphics functions
+ *
+ * Copyright 2007 Jesse Allen
+ * Copyright 2008 Huw Davies
+ * Copyright 2008 Massimo Del Fedele
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#include "config.h"
+#include "wine/port.h"
+
+#include "dibdrv.h"
+
+WINE_DEFAULT_DEBUG_CHANNEL(dibdrv);
+
+static inline void order_int(int *i1, int *i2)
+{
+    if(*i1 > *i2)
+    {
+        int tmp;
+        tmp = *i1;
+        *i1 = *i2;
+        *i2 = tmp;
+    }
+}
+
+/***********************************************************************
+ *           DIBDRV_Arc
+ */
+BOOL DIBDRV_Arc( DIBDRVPHYSDEV *physDev, INT left, INT top, INT right, INT bottom,
+            INT xstart, INT ystart, INT xend, INT yend )
+{
+#ifdef DIBDRV_SHOW_STUBS
+    FIXME("stub\n");
+#endif
+    return TRUE;
+}
+
+/***********************************************************************
+ *           DIBDRV_Chord
+ */
+BOOL DIBDRV_Chord( DIBDRVPHYSDEV *physDev, INT left, INT top, INT right, INT bottom,
+              INT xstart, INT ystart, INT xend, INT yend )
+{
+#ifdef DIBDRV_SHOW_STUBS
+    FIXME("stub\n");
+#endif
+    return TRUE;
+}
+
+/***********************************************************************
+ *           DIBDRV_Ellipse
+ */
+BOOL DIBDRV_Ellipse( DIBDRVPHYSDEV *physDev, INT left, INT top, INT right, INT \
bottom ) +{
+#ifdef DIBDRV_SHOW_STUBS
+    FIXME("stub\n");
+#endif
+    return TRUE;
+}
+
+/**********************************************************************
+ *          DIBDRV_ExtFloodFill
+ */
+BOOL DIBDRV_ExtFloodFill( DIBDRVPHYSDEV *physDev, INT x, INT y, COLORREF color,
+                     UINT fillType )
+{
+#ifdef DIBDRV_SHOW_STUBS
+    FIXME("stub\n");
+#endif
+    return TRUE;
+}
+
+/***********************************************************************
+ *           DIBDRV_GetDCOrgEx
+ */
+BOOL DIBDRV_GetDCOrgEx( DIBDRVPHYSDEV *physDev, LPPOINT lpp )
+{
+#ifdef DIBDRV_SHOW_STUBS
+    FIXME("stub\n");
+#endif
+    return TRUE;
+}
+
+/***********************************************************************
+ *           DIBDRV_GetPixel
+ */
+COLORREF DIBDRV_GetPixel( DIBDRVPHYSDEV *physDev, INT x, INT y )
+{
+    DWORD c = physDev->bmp.funcs->get_pixel_rgb(&physDev->bmp, x, y);
+    return c;
+}
+
+/***********************************************************************
+ *           DIBDRV_LineTo
+ */
+BOOL DIBDRV_LineTo( DIBDRVPHYSDEV *physDev, INT x, INT y )
+{
+    POINT cur_pos;
+
+    GetCurrentPositionEx(physDev->hdc, &cur_pos);
+
+    _DIBDRV_reset_dash_origin(physDev);
+
+    if(cur_pos.y == y) physDev->pen_hline(physDev, cur_pos.x, x, y);
+    else if(cur_pos.x == x) physDev->pen_vline(physDev, x, cur_pos.y, y);
+    else physDev->pen_line(physDev, cur_pos.x, cur_pos.y, x, y);
+
+    return TRUE;
+}
+
+/***********************************************************************
+ *           DIBDRV_PaintRgn
+ */
+BOOL DIBDRV_PaintRgn( DIBDRVPHYSDEV *physDev, HRGN hrgn )
+{
+#ifdef DIBDRV_SHOW_STUBS
+    FIXME("stub\n");
+#endif
+    return TRUE;
+}
+
+/***********************************************************************
+ *           DIBDRV_Pie
+ */
+BOOL DIBDRV_Pie( DIBDRVPHYSDEV *physDev, INT left, INT top, INT right, INT bottom,
+            INT xstart, INT ystart, INT xend, INT yend )
+{
+#ifdef DIBDRV_SHOW_STUBS
+    FIXME("stub\n");
+#endif
+    return TRUE;
+}
+
+/**********************************************************************
+ *          DIBDRV_Polygon
+ */
+BOOL DIBDRV_Polygon( DIBDRVPHYSDEV *physDev, const POINT* pt, INT count )
+{
+#ifdef DIBDRV_SHOW_STUBS
+    FIXME("stub\n");
+#endif
+    return TRUE;
+}
+
+/**********************************************************************
+ *          DIBDRV_Polyline
+ */
+BOOL DIBDRV_Polyline( DIBDRVPHYSDEV *physDev, const POINT* pt, INT count )
+{
+#ifdef DIBDRV_SHOW_STUBS
+    FIXME("stub\n");
+#endif
+    return TRUE;
+}
+
+/**********************************************************************
+ *          DIBDRV_PolyPolygon
+ */
+BOOL DIBDRV_PolyPolygon( DIBDRVPHYSDEV *physDev, const POINT* pt, const INT* counts, \
UINT polygons) +{
+#ifdef DIBDRV_SHOW_STUBS
+    FIXME("stub\n");
+#endif
+    return TRUE;
+}
+
+/**********************************************************************
+ *          DIBDRV_PolyPolyline
+ */
+BOOL DIBDRV_PolyPolyline( DIBDRVPHYSDEV *physDev, const POINT* pt, const DWORD* \
counts, +                     DWORD polylines )
+{
+#ifdef DIBDRV_SHOW_STUBS
+    FIXME("stub\n");
+#endif
+    return TRUE;
+}
+
+/***********************************************************************
+ *           DIBDRV_Rectangle
+ */
+BOOL DIBDRV_Rectangle( DIBDRVPHYSDEV *physDev, INT left, INT top, INT right, INT \
bottom) +{
+    int i;
+
+    order_int(&left, &right);
+    order_int(&top, &bottom);
+
+    _DIBDRV_reset_dash_origin(physDev);
+    /* Draw the perimeter starting at the top-right corner and move anti-clockwise \
*/ +    physDev->pen_hline(physDev, right - 1, left - 1, top);
+    physDev->pen_vline(physDev, left, top + 1, bottom);
+    physDev->pen_hline(physDev, left + 1, right, bottom - 1);
+    physDev->pen_vline(physDev, right - 1, bottom - 2, top);
+
+    for (i = top + 1; i < bottom - 1; i++)
+        physDev->brush_hline(physDev, left + 1, right - 1, i);
+
+    return TRUE;
+}
+
+/***********************************************************************
+ *           DIBDRV_RoundRect
+ */
+BOOL DIBDRV_RoundRect( DIBDRVPHYSDEV *physDev, INT left, INT top, INT right,
+                  INT bottom, INT ell_width, INT ell_height )
+{
+#ifdef DIBDRV_SHOW_STUBS
+    FIXME("stub\n");
+#endif
+    return TRUE;
+}
+
+/***********************************************************************
+ *           DIBDRV_SetPixel
+ */
+COLORREF DIBDRV_SetPixel( DIBDRVPHYSDEV *physDev, INT x, INT y, COLORREF color )
+{
+    DWORD and, xor;
+    
+    /* gets previous pixel */
+    DWORD c = physDev->bmp.funcs->get_pixel_rgb(&physDev->bmp, x, y);
+ 
+    /* calculates AND and XOR from color */
+    _DIBDRV_calc_and_xor_masks(GetROP2(physDev->hdc), color, &and, &xor);
+    
+    /* sets the pixel */
+    physDev->bmp.funcs->set_pixel(&physDev->bmp, x, y, and, xor);
+
+    /* returns previous pixel color */
+    return c;
+}
+
+/***********************************************************************
+ *           DIBDRV_SetDCOrg
+ */
+DWORD DIBDRV_SetDCOrg( DIBDRVPHYSDEV *physDev, INT x, INT y )
+{
+#ifdef DIBDRV_SHOW_STUBS
+    FIXME("stub\n");
+#endif
+    return 0;
+}
diff --git a/dlls/winedib.drv/init.c b/dlls/winedib.drv/init.c
new file mode 100644
index 0000000..0a07214
--- /dev/null
+++ b/dlls/winedib.drv/init.c
@@ -0,0 +1,278 @@
+/*
+ * DIB driver initialization functions
+ *
+ * Copyright 2007 Jesse Allen
+ * Copyright 2008 Huw Davies
+ * Copyright 2008 Massimo Del Fedele
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#include "config.h"
+#include "wine/port.h"
+
+#include "dibdrv.h"
+
+WINE_DEFAULT_DEBUG_CHANNEL(dibdrv);
+
+/* some screen caps */
+unsigned int screen_width;
+unsigned int screen_height;
+unsigned int screen_bpp;
+unsigned int screen_depth;
+RECT virtual_screen_rect;
+
+/* a few dynamic device caps */
+static int log_pixels_x;  /* pixels per logical inch in x direction */
+static int log_pixels_y;  /* pixels per logical inch in y direction */
+static int horz_size;     /* horz. size of screen in millimeters */
+static int vert_size;     /* vert. size of screen in millimeters */
+static int palette_size;
+static int device_init_done;
+
+/* NOTE :
+    Removing TC_RA_ABLE avoids bitmapped fonts, so FT_Face is always non-NULL
+    Adding TC_VA_ABLE forces to use gdi fonts always, so we can get an FT_Face
+*/
+unsigned int text_caps = (TC_OP_CHARACTER | TC_OP_STROKE | TC_CP_STROKE |
+                          TC_CR_ANY | TC_SA_DOUBLE | TC_SA_INTEGER |
+                          TC_SA_CONTIN | TC_UA_ABLE | TC_SO_ABLE /* | TC_RA_ABLE */ \
| TC_VA_ABLE); +                          /* X11R6 adds TC_SF_X_YINDEP, Xrender adds \
TC_VA_ABLE */ +
+
+static const WCHAR dpi_key_name[] = \
{'S','o','f','t','w','a','r','e','\\','F','o','n','t','s','\0'}; +static const WCHAR \
dpi_value_name[] = {'L','o','g','P','i','x','e','l','s','\0'}; +
+/******************************************************************************
+ *      get_dpi
+ *
+ * get the dpi from the registry
+ */
+static DWORD get_dpi( void )
+{
+    DWORD dpi = 96;
+    HKEY hkey;
+
+    if (RegOpenKeyW(HKEY_CURRENT_CONFIG, dpi_key_name, &hkey) == ERROR_SUCCESS)
+    {
+        DWORD type, size, new_dpi;
+
+        size = sizeof(new_dpi);
+        if(RegQueryValueExW(hkey, dpi_value_name, NULL, &type, (void *)&new_dpi, \
&size) == ERROR_SUCCESS) +        {
+            if(type == REG_DWORD && new_dpi != 0)
+                dpi = new_dpi;
+        }
+        RegCloseKey(hkey);
+    }
+    return dpi;
+}
+
+/**********************************************************************
+ *       device_init
+ *
+ * Perform initializations needed upon creation of the first device.
+ */
+static void device_init(void)
+{
+    Display *display;
+    Screen *screen;
+
+    /* opens default X11 Display */
+    if( (display = XOpenDisplay(NULL)) == NULL)
+        return;
+
+    /* gets default screen */
+    screen = XDefaultScreenOfDisplay(display);
+
+    /* gets screen sizes */
+    screen_width = XWidthOfScreen(screen);
+    screen_height = XHeightOfScreen(screen);
+
+    /* not sure about these ones... */
+    screen_bpp = XDefaultDepthOfScreen(screen);
+    screen_depth = XPlanesOfScreen(screen);
+    virtual_screen_rect.left = 0;
+    virtual_screen_rect.top = 0;
+    virtual_screen_rect.right = screen_width;
+    virtual_screen_rect.bottom = screen_height;
+
+    /* dummy ? */
+    palette_size = 0;
+
+    /* Initialize device caps */
+    log_pixels_x = log_pixels_y = get_dpi();
+    horz_size = MulDiv( screen_width, 254, log_pixels_x * 10 );
+    vert_size = MulDiv( screen_height, 254, log_pixels_y * 10 );
+
+    device_init_done = TRUE;
+}
+
+static inline void clear_dib_info(DIBDRVBITMAP *dib)
+{
+    dib->bits = dib->color_table = NULL;
+}
+
+/**********************************************************************
+ *           DIBDRV_CreateDC
+ */
+BOOL DIBDRV_CreateDC( HDC hdc, DIBDRVPHYSDEV **pdev, LPCWSTR driver, LPCWSTR device,
+                      LPCWSTR output, const DEVMODEW* initData )
+{
+    DIBDRVPHYSDEV *physDev;
+
+    if (!device_init_done)
+        device_init();
+    
+    physDev = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(DIBDRVPHYSDEV) \
); +    if (!physDev)
+        return FALSE;
+    
+    *pdev = physDev;
+    physDev->hdc = hdc;
+
+    clear_dib_info(&physDev->bmp);
+    clear_dib_info(&physDev->brush_dib);
+    physDev->brush_and_bits = NULL;
+    physDev->brush_xor_bits = NULL;
+
+    /* FIXME : sets freetype font to null; checks wether it is
+       correct or if we must initialize to some default font */
+    physDev->face = 0;
+    
+    /* initializes text color and table */
+    physDev->textColor = -1;
+    DIBDRV_SetTextColor(physDev, 0);
+
+    return TRUE;
+}
+
+/**********************************************************************
+ *           DIBDRV_DeleteDC
+ */
+BOOL DIBDRV_DeleteDC( DIBDRVPHYSDEV *physDev )
+{
+    if (physDev->bmp.color_table)
+    {
+        HeapFree( GetProcessHeap(), 0, physDev->bmp.color_table );
+        physDev->bmp.color_table = NULL;
+    }
+    HeapFree( GetProcessHeap(), 0, physDev );
+    return TRUE;
+}
+
+/**********************************************************************
+ *           DIBDRV_ExtEscape
+ */
+INT DIBDRV_ExtEscape( DIBDRVPHYSDEV *physDev, INT escape, INT in_count, LPCVOID \
in_data, +                      INT out_count, LPVOID out_data )
+{
+#ifdef DIBDRV_SHOW_STUBS
+    FIXME("stub\n");
+#endif
+    return 0;
+}
+
+/***********************************************************************
+ *           DIBDRV_GetDeviceCaps
+ */
+INT DIBDRV_GetDeviceCaps( DIBDRVPHYSDEV *physDev, INT cap )
+{
+    switch(cap)
+    {
+    case DRIVERVERSION:
+        return 0x300;
+    case TECHNOLOGY:
+        return DT_RASDISPLAY;
+    case HORZSIZE:
+        return horz_size;
+    case VERTSIZE:
+        return vert_size;
+    case HORZRES:
+        return screen_width;
+    case VERTRES:
+        return screen_height;
+    case DESKTOPHORZRES:
+        return virtual_screen_rect.right - virtual_screen_rect.left;
+    case DESKTOPVERTRES:
+        return virtual_screen_rect.bottom - virtual_screen_rect.top;
+    case BITSPIXEL:
+        return screen_bpp;
+    case PLANES:
+        return 1;
+    case NUMBRUSHES:
+        return -1;
+    case NUMPENS:
+        return -1;
+    case NUMMARKERS:
+        return 0;
+    case NUMFONTS:
+        return 0;
+    case NUMCOLORS:
+        /* MSDN: Number of entries in the device's color table, if the device has
+         * a color depth of no more than 8 bits per pixel.For devices with greater
+         * color depths, -1 is returned. */
+        return (screen_depth > 8) ? -1 : (1 << screen_depth);
+    case CURVECAPS:
+        return (CC_CIRCLES | CC_PIE | CC_CHORD | CC_ELLIPSES | CC_WIDE |
+                CC_STYLED | CC_WIDESTYLED | CC_INTERIORS | CC_ROUNDRECT);
+    case LINECAPS:
+        return (LC_POLYLINE | LC_MARKER | LC_POLYMARKER | LC_WIDE |
+                LC_STYLED | LC_WIDESTYLED | LC_INTERIORS);
+    case POLYGONALCAPS:
+        return (PC_POLYGON | PC_RECTANGLE | PC_WINDPOLYGON | PC_SCANLINE |
+                PC_WIDE | PC_STYLED | PC_WIDESTYLED | PC_INTERIORS);
+    case TEXTCAPS:
+        return text_caps;
+    case CLIPCAPS:
+        return CP_REGION;
+    case RASTERCAPS:
+        return (RC_BITBLT | RC_BANDING | RC_SCALING | RC_BITMAP64 | RC_DI_BITMAP |
+                RC_DIBTODEV | RC_BIGFONT | RC_STRETCHBLT | RC_STRETCHDIB | \
RC_DEVBITS | +                (palette_size ? RC_PALETTE : 0));
+    case SHADEBLENDCAPS:
+        return (SB_GRAD_RECT | SB_GRAD_TRI | SB_CONST_ALPHA | SB_PIXEL_ALPHA);
+    case ASPECTX:
+    case ASPECTY:
+        return 36;
+    case ASPECTXY:
+        return 51;
+    case LOGPIXELSX:
+        return log_pixels_x;
+    case LOGPIXELSY:
+        return log_pixels_y;
+    case CAPS1:
+        FIXME("(%p): CAPS1 is unimplemented, will return 0\n", physDev->hdc );
+        /* please see wingdi.h for the possible bit-flag values that need
+           to be returned. */
+        return 0;
+    case SIZEPALETTE:
+        return palette_size;
+    case NUMRESERVED:
+    case COLORRES:
+    case PHYSICALWIDTH:
+    case PHYSICALHEIGHT:
+    case PHYSICALOFFSETX:
+    case PHYSICALOFFSETY:
+    case SCALINGFACTORX:
+    case SCALINGFACTORY:
+    case VREFRESH:
+    case BLTALIGNMENT:
+        return 0;
+    default:
+        FIXME("(%p): unsupported capability %d, will return 0\n", physDev->hdc, cap \
); +        return 0;
+    }
+}
diff --git a/dlls/winedib.drv/opengl.c b/dlls/winedib.drv/opengl.c
new file mode 100644
index 0000000..311f22a
--- /dev/null
+++ b/dlls/winedib.drv/opengl.c
@@ -0,0 +1,73 @@
+/*
+ * DIBDRV OpenGL functions
+ *
+ * Copyright 2007 Jesse Allen
+ * Copyright 2008 Massimo Del Fedele
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#include "config.h"
+#include "wine/port.h"
+
+#include "dibdrv.h"
+
+WINE_DEFAULT_DEBUG_CHANNEL(dibdrv);
+
+int DIBDRV_ChoosePixelFormat( DIBDRVPHYSDEV *physDev,
+                              const PIXELFORMATDESCRIPTOR *ppfd )
+{
+#ifdef DIBDRV_SHOW_STUBS
+    FIXME("stub\n");
+#endif
+    return 0;
+}
+
+int DIBDRV_DescribePixelFormat( DIBDRVPHYSDEV *physDev,
+                                int iPixelFormat,
+                                UINT nBytes,
+                                PIXELFORMATDESCRIPTOR *ppfd )
+{
+#ifdef DIBDRV_SHOW_STUBS
+    FIXME("stub\n");
+#endif
+    return 0;
+}
+
+int DIBDRV_GetPixelFormat( DIBDRVPHYSDEV *physDev)
+{
+#ifdef DIBDRV_SHOW_STUBS
+    FIXME("stub\n");
+#endif
+    return 0;
+}
+
+BOOL DIBDRV_SetPixelFormat( DIBDRVPHYSDEV *physDev,
+                            int iPixelFormat,
+                            const PIXELFORMATDESCRIPTOR *ppfd )
+{
+#ifdef DIBDRV_SHOW_STUBS
+    FIXME("stub\n");
+#endif
+    return TRUE;
+}
+
+BOOL DIBDRV_SwapBuffers( DIBDRVPHYSDEV *physDev )
+{
+#ifdef DIBDRV_SHOW_STUBS
+    FIXME("stub\n");
+#endif
+    return TRUE;
+}
diff --git a/dlls/winedib.drv/palette.c b/dlls/winedib.drv/palette.c
new file mode 100644
index 0000000..605c8e0
--- /dev/null
+++ b/dlls/winedib.drv/palette.c
@@ -0,0 +1,93 @@
+/*
+ * DIBDRV palette objects
+ *
+ * Copyright 2007 Jesse Allen
+ * Copyright 2008 Massimo Del Fedele
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#include "config.h"
+#include "wine/port.h"
+
+#include "dibdrv.h"
+
+WINE_DEFAULT_DEBUG_CHANNEL(dibdrv);
+
+/***********************************************************************
+ *              DIBDRV_RealizePalette
+ */
+UINT DIBDRV_RealizePalette( DIBDRVPHYSDEV *physDev, HPALETTE hpal, BOOL primary )
+{
+#ifdef DIBDRV_SHOW_STUBS
+    FIXME("stub\n");
+#endif
+    return 0;
+}
+
+/***********************************************************************
+ *              DIBDRV_UnrealizePalette
+ */
+BOOL DIBDRV_UnrealizePalette( HPALETTE hpal )
+{
+#ifdef DIBDRV_SHOW_STUBS
+    FIXME("stub\n");
+#endif
+    return TRUE;
+}
+
+/***********************************************************************
+ *              DIBDRV_GetSystemPaletteEntries
+ */
+UINT DIBDRV_GetSystemPaletteEntries( DIBDRVPHYSDEV *physDev, UINT start, UINT count,
+                                     LPPALETTEENTRY entries )
+{
+#ifdef DIBDRV_SHOW_STUBS
+    FIXME("stub\n");
+#endif
+    return 0;
+}
+
+/***********************************************************************
+ *              DIBDRV_GetNearestColor
+ */
+COLORREF DIBDRV_GetNearestColor( DIBDRVPHYSDEV *physDev, COLORREF color )
+{
+#ifdef DIBDRV_SHOW_STUBS
+    FIXME("stub\n");
+#endif
+    return color;
+}
+
+/***********************************************************************
+ *              DIBDRV_RealizeDefaultPalette
+ */
+UINT DIBDRV_RealizeDefaultPalette( DIBDRVPHYSDEV *physDev )
+{
+#ifdef DIBDRV_SHOW_STUBS
+    FIXME("stub\n");
+#endif
+
+    /* HACK - we can't get the dib color table during SelectBitmap since it hasn't
+       been initialized yet.  This is called from DC_InitDC so it's a convenient \
place +       to grab the color table. */
+    if(physDev->bmp.color_table_size && !physDev->bmp.color_table)
+    {
+        physDev->bmp.color_table = HeapAlloc(GetProcessHeap(), 0, \
sizeof(physDev->bmp.color_table[0]) * physDev->bmp.color_table_size); +        \
GetDIBColorTable(physDev->hdc, 0, physDev->bmp.color_table_size, \
physDev->bmp.color_table); +    }
+
+    return 0;
+}
diff --git a/dlls/winedib.drv/pen_brush.c b/dlls/winedib.drv/pen_brush.c
new file mode 100644
index 0000000..9105678
--- /dev/null
+++ b/dlls/winedib.drv/pen_brush.c
@@ -0,0 +1,452 @@
+/*
+ * DIBDRV pen objects
+ *
+ * Copyright 2007 Jesse Allen
+ * Copyright 2008 Huw Davies
+ * Copyright 2008 Massimo Del Fedele
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#include "config.h"
+#include "wine/port.h"
+
+#include "dibdrv.h"
+
+WINE_DEFAULT_DEBUG_CHANNEL(dibdrv);
+
+static const dash_pattern_t dash_patterns[4] =
+{
+    {2, {18, 6}},
+    {2, {3,  3}},
+    {4, {9, 6, 3, 6}},
+    {6, {9, 3, 3, 3, 3, 3}}
+};
+
+static inline void order_end_points(int *s, int *e)
+{
+    if(*s > *e)
+    {
+        int tmp;
+        tmp = *s + 1;
+        *s = *e + 1;
+        *e = tmp;
+    }
+}
+
+static void solid_pen_hline(DIBDRVPHYSDEV *physDev, INT start, INT end, INT row)
+{
+    order_end_points(&start, &end);
+    physDev->bmp.funcs->solid_hline(&physDev->bmp, start, end, row, \
physDev->pen_and, physDev->pen_xor); +}
+
+static void solid_pen_vline(DIBDRVPHYSDEV *physDev, INT col, INT start, INT end)
+{
+    order_end_points(&start, &end);
+    physDev->bmp.funcs->solid_vline(&physDev->bmp, col, start, end, \
physDev->pen_and, physDev->pen_xor); +}
+
+
+static void WINAPI solid_pen_line_callback(INT x, INT y, LPARAM lparam)
+{
+    DIBDRVPHYSDEV *physDev = (DIBDRVPHYSDEV *)lparam;
+
+    physDev->bmp.funcs->set_pixel(&physDev->bmp, x, y, physDev->pen_and, \
physDev->pen_xor); +    return;
+}
+
+void solid_pen_line(DIBDRVPHYSDEV *physDev, INT x1, INT y1, INT x2, INT y2)
+{
+    LineDDA(x1, y1, x2, y2, solid_pen_line_callback, (LPARAM)physDev);
+}
+
+static inline void get_dash_colors(DIBDRVPHYSDEV *physDev, DWORD *and, DWORD *xor)
+{
+    if(physDev->mark_space == mark)
+    {
+        *and = physDev->pen_and;
+        *xor = physDev->pen_xor;
+    }
+    else if(GetBkMode(physDev->hdc) == OPAQUE)
+    {
+        *and = physDev->bkgnd_and;
+        *xor = physDev->bkgnd_xor;
+    }
+    else
+    {
+        *and = 0xffffffff;
+        *xor = 0;
+    }
+}
+
+static inline void next_dash(DIBDRVPHYSDEV *physDev)
+{
+    if(physDev->left_in_dash != 0) return;
+
+    physDev->cur_dash++;
+    if(physDev->cur_dash == physDev->pen_pattern->count) physDev->cur_dash = 0;
+    physDev->left_in_dash = physDev->pen_pattern->dashes[physDev->cur_dash];
+    if(physDev->mark_space == mark) physDev->mark_space = space;
+    else physDev->mark_space = mark;
+}
+
+static void dashed_pen_hline(DIBDRVPHYSDEV *physDev, INT start, INT end, INT row)
+{
+    INT cur_x = start;
+    DWORD and, xor;
+    DWORD dash_len;
+
+    if(start <= end)
+    {
+        while(cur_x != end)
+        {
+            get_dash_colors(physDev, &and, &xor);
+
+            dash_len = physDev->left_in_dash;
+            if(cur_x + dash_len > end)
+                dash_len = end - cur_x;
+
+            physDev->bmp.funcs->solid_hline(&physDev->bmp, cur_x, cur_x + dash_len, \
row, and, xor); +            cur_x += dash_len;
+
+            physDev->left_in_dash -= dash_len;
+            next_dash(physDev);
+        }
+    }
+    else
+    {
+        while(cur_x != end)
+        {
+            get_dash_colors(physDev, &and, &xor);
+
+            dash_len = physDev->left_in_dash;
+            if(cur_x - (INT)dash_len < end)
+                dash_len = cur_x - end;
+
+            physDev->bmp.funcs->solid_hline(&physDev->bmp, cur_x - dash_len + 1, \
cur_x + 1, row, and, xor); +            cur_x -= dash_len;
+
+            physDev->left_in_dash -= dash_len;
+            next_dash(physDev);
+        }
+    }
+}
+
+static void dashed_pen_vline(DIBDRVPHYSDEV *physDev, INT col, INT start, INT end)
+{
+    INT cur_y = start;
+    DWORD and, xor;
+    DWORD dash_len;
+
+    if(start <= end)
+    {
+        while(cur_y != end)
+        {
+            get_dash_colors(physDev, &and, &xor);
+
+            dash_len = physDev->left_in_dash;
+            if(cur_y + dash_len > end)
+                dash_len = end - cur_y;
+
+            physDev->bmp.funcs->solid_vline(&physDev->bmp, col, cur_y, cur_y + \
dash_len, and, xor); +            cur_y += dash_len;
+
+            physDev->left_in_dash -= dash_len;
+            next_dash(physDev);
+        }
+    }
+    else
+    {
+        while(cur_y != end)
+        {
+            get_dash_colors(physDev, &and, &xor);
+
+            dash_len = physDev->left_in_dash;
+            if(cur_y - (INT)dash_len < end)
+                dash_len = cur_y - end;
+
+            physDev->bmp.funcs->solid_vline(&physDev->bmp, col, cur_y - dash_len + \
1, cur_y + 1, and, xor); +            cur_y -= dash_len;
+
+            physDev->left_in_dash -= dash_len;
+            next_dash(physDev);
+        }
+    }
+}
+
+static void WINAPI dashed_pen_line_callback(INT x, INT y, LPARAM lparam)
+{
+    DIBDRVPHYSDEV *physDev = (DIBDRVPHYSDEV *)lparam;
+    DWORD and, xor;
+
+    get_dash_colors(physDev, &and, &xor);
+
+    physDev->bmp.funcs->set_pixel(&physDev->bmp, x, y, and, xor);
+
+    physDev->left_in_dash--;
+    next_dash(physDev);
+
+    return;
+}
+
+static void dashed_pen_line(DIBDRVPHYSDEV *physDev, INT x1, INT y1, INT x2, INT y2)
+{
+    LineDDA(x1, y1, x2, y2, dashed_pen_line_callback, (LPARAM)physDev);
+}
+
+void _DIBDRV_reset_dash_origin(DIBDRVPHYSDEV *physDev)
+{
+    physDev->cur_dash = 0;
+    if(physDev->pen_pattern)
+        physDev->left_in_dash = physDev->pen_pattern->dashes[0];
+    physDev->mark_space = mark;
+}
+
+
+/* For 1bpp bitmaps, unless the selected foreground color exactly
+   matches one of the colors in the colortable, then the color that
+   isn't the bkgnd color is used. */
+static DWORD adjust_fg_color(DIBDRVPHYSDEV *physDev, COLORREF color)
+{
+    RGBQUAD rgb;
+    int i;
+
+    rgb.rgbRed   = GetRValue(color);
+    rgb.rgbGreen = GetGValue(color);
+    rgb.rgbBlue  = GetBValue(color);
+
+    for(i = 0; i < physDev->bmp.color_table_size; i++)
+    {
+        RGBQUAD *cur = physDev->bmp.color_table + i;
+        if((rgb.rgbRed == cur->rgbRed) && (rgb.rgbGreen == cur->rgbGreen) && \
(rgb.rgbBlue == cur->rgbBlue)) +            return i;
+    }
+    return ~physDev->bkgnd_color & 1;
+}
+
+static void fixup_fg_colors_1(DIBDRVPHYSDEV *physDev)
+{
+    INT rop = GetROP2(physDev->hdc);
+
+    physDev->pen_color   = adjust_fg_color(physDev, physDev->pen_colorref);
+    physDev->brush_color = adjust_fg_color(physDev, physDev->brush_colorref);
+
+    _DIBDRV_calc_and_xor_masks(rop, physDev->pen_color, &physDev->pen_and, \
&physDev->pen_xor); +    _DIBDRV_calc_and_xor_masks(rop, physDev->brush_color, \
&physDev->brush_and, &physDev->brush_xor); +    HeapFree(GetProcessHeap(), 0, \
physDev->brush_and_bits); +    HeapFree(GetProcessHeap(), 0, \
physDev->brush_xor_bits); +    physDev->brush_and_bits = NULL;
+    physDev->brush_xor_bits = NULL;
+}
+
+static void solid_brush_hline(DIBDRVPHYSDEV *physDev, INT start, INT end, INT row)
+{
+    order_end_points(&start, &end);
+    physDev->bmp.funcs->solid_hline(&physDev->bmp, start, end, row, \
physDev->brush_and, physDev->brush_xor); +}
+
+
+static void generate_masks(DIBDRVPHYSDEV *physDev, DIBDRVBITMAP *bmp, void **and, \
void **xor) +{
+    INT rop = GetROP2(physDev->hdc);
+    DWORD *color_ptr, *and_ptr, *xor_ptr;
+    DWORD size = bmp->height * abs(bmp->stride);
+
+    *and = HeapAlloc(GetProcessHeap(), 0, size);
+    *xor = HeapAlloc(GetProcessHeap(), 0, size);
+
+    color_ptr = bmp->bits;
+    and_ptr = *and;
+    xor_ptr = *xor;
+
+    while(size)
+    {
+        _DIBDRV_calc_and_xor_masks(rop, *color_ptr++, and_ptr++, xor_ptr++);
+        size -= 4;
+    }
+}
+
+static void pattern_brush_hline(DIBDRVPHYSDEV *physDev, INT start, INT end, INT row)
+{
+    DWORD *and, *xor, brush_row = row % physDev->brush_dib.height;
+
+    if(!physDev->brush_and_bits)
+        generate_masks(physDev, &physDev->brush_dib,
+                       &physDev->brush_and_bits, &physDev->brush_xor_bits);
+
+    order_end_points(&start, &end);
+    and = (DWORD *)((char *)physDev->brush_and_bits + brush_row * \
physDev->brush_dib.stride); +    xor = (DWORD *)((char *)physDev->brush_xor_bits + \
brush_row * physDev->brush_dib.stride); +
+    physDev->bmp.funcs->pattern_hline(&physDev->bmp, start, end, row, and, xor, \
physDev->brush_dib.width, start % physDev->brush_dib.width); +}
+
+/***********************************************************************
+ *           DIBDRV_SelectPen
+ */
+HPEN DIBDRV_SelectPen( DIBDRVPHYSDEV *physDev, HPEN hpen )
+{
+    LOGPEN logpen;
+
+    GetObjectW(hpen, sizeof(logpen), &logpen);
+
+    physDev->pen_colorref = logpen.lopnColor;
+
+    if(physDev->bmp.bit_count == 1)
+        fixup_fg_colors_1(physDev);
+    else
+        physDev->pen_color = physDev->bmp.funcs->colorref_to_pixel(&physDev->bmp, \
logpen.lopnColor); +
+    _DIBDRV_calc_and_xor_masks(GetROP2(physDev->hdc), physDev->pen_color, \
&physDev->pen_and, &physDev->pen_xor); +
+    switch(logpen.lopnStyle)
+    {
+    default:
+//        FIXME("Unhandled pen style %d\n", logpen.lopnStyle);
+        /* fall through */
+    case PS_SOLID:
+        physDev->pen_hline = solid_pen_hline;
+        physDev->pen_vline = solid_pen_vline;
+        physDev->pen_line  = solid_pen_line;
+        physDev->pen_pattern = NULL;
+        break;
+
+    case PS_DASH:
+    case PS_DOT:
+    case PS_DASHDOT:
+    case PS_DASHDOTDOT:
+        physDev->pen_hline = dashed_pen_hline;
+        physDev->pen_vline = dashed_pen_vline;
+        physDev->pen_line  = dashed_pen_line;
+        physDev->pen_pattern = &dash_patterns[logpen.lopnStyle - PS_DASH];
+        _DIBDRV_reset_dash_origin(physDev);
+        break;
+    }
+
+    return hpen;
+
+}
+
+/***********************************************************************
+ *           DIBDRV_SetDCPenColor
+ */
+COLORREF DIBDRV_SetDCPenColor( DIBDRVPHYSDEV *physDev, COLORREF crColor )
+{
+#ifdef DIBDRV_SHOW_STUBS
+    FIXME("stub\n");
+#endif
+    return crColor;
+}
+
+/***********************************************************************
+ *           DIBDRV_SelectBrush
+ */
+HBRUSH DIBDRV_SelectBrush( DIBDRVPHYSDEV *physDev, HBRUSH hbrush )
+{
+    LOGBRUSH logbrush;
+
+    GetObjectW(hbrush, sizeof(logbrush), &logbrush);
+
+    HeapFree(GetProcessHeap(), 0, physDev->brush_dib.bits);
+    HeapFree(GetProcessHeap(), 0, physDev->brush_dib.color_table);
+    HeapFree(GetProcessHeap(), 0, physDev->brush_and_bits);
+    HeapFree(GetProcessHeap(), 0, physDev->brush_xor_bits);
+    physDev->brush_dib.bits = NULL;
+    physDev->brush_dib.color_table = NULL;
+    physDev->brush_and_bits = NULL;
+    physDev->brush_xor_bits = NULL;
+
+    switch (logbrush.lbStyle)
+    {
+    default:
+//        FIXME("Unhandled brush style %d\n", logbrush.lbStyle);
+        /* fall through */
+    case BS_SOLID:
+        physDev->brush_hline = solid_brush_hline;
+        physDev->brush_colorref = logbrush.lbColor;
+        if(physDev->bmp.bit_count == 1)
+            fixup_fg_colors_1(physDev);
+        else
+            physDev->brush_color = \
physDev->bmp.funcs->colorref_to_pixel(&physDev->bmp, logbrush.lbColor); +
+        _DIBDRV_calc_and_xor_masks(GetROP2(physDev->hdc), physDev->brush_color,
+                                   &physDev->brush_and, &physDev->brush_xor);
+        break;
+
+    case BS_DIBPATTERN:
+    {
+        DIBDRVBITMAP src;
+        BITMAPINFO *bmi = GlobalLock16(logbrush.lbHatch);
+
+        _DIBDRV_init_dib_from_BITMAPINFO(&src, bmi);
+        _DIBDRV_copy_dib_color_info(&physDev->bmp, &physDev->brush_dib);
+        _DIBDRV_convert_dib(&src, &physDev->brush_dib);
+
+        GlobalUnlock16(logbrush.lbHatch);
+        physDev->brush_hline = pattern_brush_hline;
+        break;
+    }
+
+    }
+    return hbrush;
+}
+
+/***********************************************************************
+ *           DIBDRV_SetDCBrushColor
+ */
+COLORREF DIBDRV_SetDCBrushColor( DIBDRVPHYSDEV *physDev, COLORREF crColor )
+{
+#ifdef DIBDRV_SHOW_STUBS
+    FIXME("stub\n");
+#endif
+    return crColor;
+}
+
+/***********************************************************************
+ *           SetROP2
+ */
+INT DIBDRV_SetROP2( DIBDRVPHYSDEV *physDev, INT rop )
+{
+    INT ret = GetROP2(physDev->hdc);
+
+    if(ret != rop)
+    {
+        _DIBDRV_calc_and_xor_masks(rop, physDev->pen_color,   &physDev->pen_and,   \
&physDev->pen_xor); +        _DIBDRV_calc_and_xor_masks(rop, physDev->brush_color, \
&physDev->brush_and, &physDev->brush_xor); +        _DIBDRV_calc_and_xor_masks(rop, \
physDev->bkgnd_color, &physDev->bkgnd_and, &physDev->bkgnd_xor); +        \
HeapFree(GetProcessHeap(), 0, physDev->brush_and_bits); +        \
HeapFree(GetProcessHeap(), 0, physDev->brush_xor_bits); +        \
physDev->brush_and_bits = NULL; +        physDev->brush_xor_bits = NULL;
+    }
+    return ret;
+}
+
+/***********************************************************************
+ *           SetBkColor
+ */
+COLORREF DIBDRV_SetBkColor( DIBDRVPHYSDEV *physDev, COLORREF color )
+{
+    INT rop = GetROP2(physDev->hdc);
+
+    physDev->bkgnd_color = physDev->bmp.funcs->colorref_to_pixel(&physDev->bmp, \
color); +
+    if(physDev->bmp.bit_count == 1)
+        fixup_fg_colors_1(physDev);
+
+    _DIBDRV_calc_and_xor_masks(rop, physDev->bkgnd_color, &physDev->bkgnd_and, \
&physDev->bkgnd_xor); +
+    return color;
+}
diff --git a/dlls/winedib.drv/primitives.c b/dlls/winedib.drv/primitives.c
new file mode 100644
index 0000000..878535d
--- /dev/null
+++ b/dlls/winedib.drv/primitives.c
@@ -0,0 +1,1183 @@
+/*
+ * DIB Engine Primitives
+ *
+ * Copyright 2008 Huw Davies
+ * Copyright 2008 Massimo Del Fedele
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#include "config.h"
+#include "wine/port.h"
+
+#include "dibdrv.h"
+
+WINE_DEFAULT_DEBUG_CHANNEL(dibeng);
+
+/* ------------------------------------------------------------*/
+/*                     BASIC ROP HELPER                        */
+/*
+ *
+ * Decompose the 16 ROP2s into an expression of the form
+ *
+ * D = (D & A) ^ X
+ *
+ * Where A and X depend only on P (and so can be precomputed).
+ *
+ *                                       A    X
+ *
+ * R2_BLACK         0                    0    0
+ * R2_NOTMERGEPEN   ~(D | P)            ~P   ~P
+ * R2_MASKNOTPEN    ~P & D              ~P    0
+ * R2_NOTCOPYPEN    ~P                   0   ~P
+ * R2_MASKPENNOT    P & ~D               P    P
+ * R2_NOT           ~D                   1    1
+ * R2_XORPEN        P ^ D                1    P
+ * R2_NOTMASKPEN    ~(P & D)             P    1
+ * R2_MASKPEN       P & D                P    0
+ * R2_NOTXORPEN     ~(P ^ D)             1   ~P
+ * R2_NOP           D                    1    0
+ * R2_MERGENOTPEN   ~P | D               P   ~P
+ * R2_COPYPEN       P                    0    P
+ * R2_MERGEPENNOT   P | ~D              ~P    1
+ * R2_MERGEPEN      P | D               ~P    P
+ * R2_WHITE         1                    0    1
+ *
+ */
+
+/* A = (P & A1) | (~P & A2) */
+#define ZERO {0, 0}
+#define ONE {0xffffffff, 0xffffffff}
+#define P {0xffffffff, 0}
+#define NOT_P {0, 0xffffffff}
+
+static const DWORD rop2_and_array[16][2] =
+{
+    ZERO, NOT_P, NOT_P, ZERO,
+    P,    ONE,   ONE,   P,
+    P,    ONE,   ONE,   P,
+    ZERO, NOT_P, NOT_P, ZERO
+};
+
+/* X = (P & X1) | (~P & X2) */
+static const DWORD rop2_xor_array[16][2] =
+{
+    ZERO, NOT_P, ZERO, NOT_P,
+    P,    ONE,   P,    ONE,
+    ZERO, NOT_P, ZERO, NOT_P,
+    P,    ONE,   P,    ONE
+};
+
+#undef NOT_P
+#undef P
+#undef ONE
+#undef ZERO
+
+void _DIBDRV_calc_and_xor_masks(INT rop, DWORD color, DWORD *and, DWORD *xor)
+{
+    /* NB The ROP2 codes start at one and the arrays are zero-based */
+    rop = (rop - 1) & 0x0f;
+    *and = (color & rop2_and_array[rop][0]) | ((~color) & rop2_and_array[rop][1]);
+    *xor = (color & rop2_xor_array[rop][0]) | ((~color) & rop2_xor_array[rop][1]);
+}
+
+/* ------------------------------------------------------------*/
+/*                   ROP PIXEL FUNCTIONS                       */
+
+static inline void do_rop_32(DWORD *ptr, DWORD and, DWORD xor)
+{
+    *ptr = (*ptr & and) ^ xor;
+}
+
+static inline void do_rop_16(WORD *ptr, WORD and, WORD xor)
+{
+    *ptr = (*ptr & and) ^ xor;
+}
+
+static inline void do_rop_8(BYTE *ptr, BYTE and, BYTE xor)
+{
+    *ptr = (*ptr & and) ^ xor;
+}
+
+/* ------------------------------------------------------------*/
+/*                     HORIZONTAL LINES                        */
+
+static void solid_hline_32(const DIBDRVBITMAP *dib, int start, int end, int row, \
DWORD and, DWORD xor) +{
+    DWORD *ptr;
+    int i;
+
+    ptr = dib->funcs->get_pixel_ptr(dib, start, row);
+
+    for(i = start; i < end; i++)
+        do_rop_32(ptr++, and, xor);
+}
+
+static void solid_hline_24(const DIBDRVBITMAP *dib, int start, int end, int row, \
DWORD and, DWORD xor) +{
+    BYTE *ptr;
+    int i;
+    BYTE and_bytes[3], xor_bytes[3];
+
+    and_bytes[0] =  and        & 0xff;
+    and_bytes[1] = (and >> 8)  & 0xff;
+    and_bytes[2] = (and >> 16) & 0xff;
+    xor_bytes[0] =  xor        & 0xff;
+    xor_bytes[1] = (xor >> 8)  & 0xff;
+    xor_bytes[2] = (xor >> 16) & 0xff;
+
+    ptr = dib->funcs->get_pixel_ptr(dib, start, row);
+
+    for(i = start; i < end; i++)
+    {
+        do_rop_8(ptr++, and_bytes[0], xor_bytes[0]);
+        do_rop_8(ptr++, and_bytes[1], xor_bytes[1]);
+        do_rop_8(ptr++, and_bytes[2], xor_bytes[2]);
+    }
+}
+
+static void solid_hline_16(const DIBDRVBITMAP *dib, int start, int end, int row, \
DWORD and, DWORD xor) +{
+    WORD *ptr;
+    int i;
+
+    ptr = dib->funcs->get_pixel_ptr(dib, start, row);
+
+    for(i = start; i < end; i++)
+        do_rop_16(ptr++, and, xor);
+}
+
+static void solid_hline_8(const DIBDRVBITMAP *dib, int start, int end, int row, \
DWORD and, DWORD xor) +{
+    BYTE *ptr;
+    int i;
+
+    ptr = dib->funcs->get_pixel_ptr(dib, start, row);
+
+    for(i = start; i < end; i++)
+        do_rop_8(ptr++, and, xor);
+}
+
+static void solid_hline_4(const DIBDRVBITMAP *dib, int start, int end, int row, \
DWORD and, DWORD xor) +{
+    BYTE *ptr;
+    int i;
+    BYTE byte_and, byte_xor;
+
+    ptr = dib->funcs->get_pixel_ptr(dib, start, row);
+    byte_and = (and & 0xf) | ((and << 4) & 0xf0);
+    byte_xor = (xor & 0xf) | ((xor << 4) & 0xf0);
+
+    if(start & 1) /* upper nibble untouched */
+        do_rop_8(ptr++, byte_and | 0xf0, byte_xor & 0x0f);
+
+    for(i = (start + 1) / 2; i < end / 2; i++)
+        do_rop_8(ptr++, byte_and, byte_xor);
+
+    if(end & 1) /* lower nibble untouched */
+        do_rop_8(ptr, byte_and | 0x0f, byte_xor & 0xf0);
+}
+
+static void solid_hline_1(const DIBDRVBITMAP *dib, int start, int end, int row, \
DWORD and, DWORD xor)

+{
+    BYTE *ptr;
+    int i;
+    BYTE byte_and = 0, byte_xor = 0, mask;
+
+    ptr = dib->funcs->get_pixel_ptr(dib, start, row);
+
+    if(and & 1) byte_and = 0xff;
+    if(xor & 1) byte_xor = 0xff;
+
+    if((start & ~7) == (end & ~7)) /* special case run inside one byte */
+    {
+        mask = ((1L << ((end & 7) - (start & 7))) - 1) << (8 - (end & 7));
+        do_rop_8(ptr, byte_and | ~mask, byte_xor & mask);
+        return;
+    }
+
+    if(start & 7)
+    {
+        mask = (1 << (8 - (start & 7))) - 1;
+        do_rop_8(ptr++, byte_and | ~mask, byte_xor & mask);
+    }
+
+    for(i = (start + 7) / 8; i < end / 8; i++)
+        do_rop_8(ptr++, byte_and, byte_xor);
+
+    if(end & 7)
+    {
+        mask = ~((1 << (8 - (end & 7))) - 1);
+        do_rop_8(ptr++, byte_and | ~mask, byte_xor & mask);
+    }
+}
+
+static void pattern_hline_32(const DIBDRVBITMAP *dib, int start, int end, int row, \
const void *and, const void *xor, DWORD count, DWORD offset) +{
+    DWORD *ptr;
+    const DWORD *and_ptr = and, *xor_ptr = xor;
+    int i;
+
+    ptr = dib->funcs->get_pixel_ptr(dib, start, row);
+
+    and_ptr += offset;
+    xor_ptr += offset;
+    for(i = start; i < end; i++)
+    {
+        do_rop_32(ptr++, *and_ptr++, *xor_ptr++);
+        if(++offset == count)
+        {
+            offset = 0;
+            and_ptr = and;
+            xor_ptr = xor;
+        }
+    }
+}
+
+static void pattern_hline_24(const DIBDRVBITMAP *dib, int start, int end, int row, \
const void *and, const void *xor, DWORD count, DWORD offset) +{
+    BYTE *ptr;
+    const BYTE *and_ptr = and, *xor_ptr = xor;
+    int i;
+
+    ptr = dib->funcs->get_pixel_ptr(dib, start, row);
+
+    and_ptr += offset * 3;
+    xor_ptr += offset * 3;
+
+    for(i = start; i < end; i++)
+    {
+        do_rop_8(ptr++,  *and_ptr++, *xor_ptr++);
+        do_rop_8(ptr++,  *and_ptr++, *xor_ptr++);
+        do_rop_8(ptr++,  *and_ptr++, *xor_ptr++);
+        if(++offset == count)
+        {
+            offset = 0;
+            and_ptr = and;
+            xor_ptr = xor;
+        }
+    }
+}
+
+static void pattern_hline_16(const DIBDRVBITMAP *dib, int start, int end, int row, \
const void *and, const void *xor, DWORD count, DWORD offset) +{
+    WORD *ptr;
+    const WORD *and_ptr = and, *xor_ptr = xor;
+    int i;
+
+    ptr = dib->funcs->get_pixel_ptr(dib, start, row);
+
+    and_ptr += offset;
+    xor_ptr += offset;
+
+    for(i = start; i < end; i++)
+    {
+        do_rop_16(ptr++, *and_ptr++, *xor_ptr++);
+        if(++offset == count)
+        {
+            offset = 0;
+            and_ptr = and;
+            xor_ptr = xor;
+        }
+    }
+}
+
+static void pattern_hline_8(const DIBDRVBITMAP *dib, int start, int end, int row, \
const void *and, const void *xor, DWORD count, DWORD offset) +{
+    BYTE *ptr;
+    const BYTE *and_ptr = and, *xor_ptr = xor;
+    int i;
+
+    ptr = dib->funcs->get_pixel_ptr(dib, start, row);
+
+    and_ptr += offset;
+    xor_ptr += offset;
+
+    for(i = start; i < end; i++)
+    {
+        do_rop_8(ptr++, *and_ptr++, *xor_ptr++);
+        if(++offset == count)
+        {
+            offset = 0;
+            and_ptr = and;
+            xor_ptr = xor;
+        }
+    }
+}
+
+static void pattern_hline_4(const DIBDRVBITMAP *dib, int start, int end, int row, \
const void *and, const void *xor, DWORD count, DWORD offset) +{
+    BYTE *ptr;
+    const BYTE *and_ptr = and, *xor_ptr = xor;
+    int i;
+    BYTE byte_and, byte_xor;
+
+    ptr = dib->funcs->get_pixel_ptr(dib, start, row);
+
+    and_ptr += offset / 2;
+    xor_ptr += offset / 2;
+
+    for(i = start; i < end; i++)
+    {
+        if(offset & 1)
+        {
+            byte_and = *and_ptr++ & 0x0f;
+            byte_xor = *xor_ptr++ & 0x0f;
+        }
+        else
+        {
+            byte_and = (*and_ptr & 0xf0) >> 4;
+            byte_xor = (*xor_ptr & 0xf0) >> 4;
+        }
+
+        if(i & 1)
+            byte_and |= 0xf0;
+        else
+        {
+            byte_and = (byte_and << 4) | 0x0f;
+            byte_xor <<= 4;
+        }
+
+        do_rop_8(ptr, byte_and, byte_xor);
+
+        if(i & 1) ptr++;
+
+        if(++offset == count)
+        {
+            offset = 0;
+            and_ptr = and;
+            xor_ptr = xor;
+        }
+    }
+}
+
+static void pattern_hline_1(const DIBDRVBITMAP *dib, int start, int end, int row, \
const void *and, const void *xor, DWORD count, DWORD offset) +{
+    BYTE *ptr;
+    const BYTE *and_ptr = and, *xor_ptr = xor;
+    int i;
+    BYTE byte_and, byte_xor, dst_mask, brush_mask;
+
+    ptr = dib->funcs->get_pixel_ptr(dib, start, row);
+
+    and_ptr += offset / 8;
+    xor_ptr += offset / 8;
+
+    for(i = start; i < end; i++)
+    {
+        dst_mask   = 1 << (7 - (i      & 7));
+        brush_mask = 1 << (7 - (offset & 7));
+
+        byte_and = (*and_ptr & brush_mask) ? 0xff : 0;
+        byte_xor = (*xor_ptr & brush_mask) ? 0xff : 0;
+
+        byte_and |= ~dst_mask;
+        byte_xor &= dst_mask;
+
+        do_rop_8(ptr, byte_and, byte_xor);
+
+        if((i & 7) == 7) ptr++;
+        if(++offset == count)
+        {
+            offset = 0;
+            and_ptr = and;
+            xor_ptr = xor;
+        }
+        else if((offset & 7) == 7)
+        {
+            and_ptr++;
+            xor_ptr++;
+        }
+    }
+}
+
+/* ------------------------------------------------------------*/
+/*                      VERTICAL LINES                         */
+
+static void solid_vline_32(const DIBDRVBITMAP *dib, int col, int start, int end, \
DWORD and, DWORD xor) +{
+    BYTE *ptr;
+    int i;
+
+    ptr = dib->funcs->get_pixel_ptr(dib, col, start);
+
+    for(i = start; i < end; i++)
+    {
+        do_rop_32((DWORD*)ptr, and, xor);
+        ptr += dib->stride;
+    }
+}
+
+static void solid_vline_24(const DIBDRVBITMAP *dib, int col, int start, int end, \
DWORD and, DWORD xor) +{
+    BYTE *ptr;
+    int i;
+    BYTE and_bytes[3], xor_bytes[3];
+
+    and_bytes[0] =  and        & 0xff;
+    and_bytes[1] = (and >> 8)  & 0xff;
+    and_bytes[2] = (and >> 16) & 0xff;
+    xor_bytes[0] =  xor        & 0xff;
+    xor_bytes[1] = (xor >> 8)  & 0xff;
+    xor_bytes[2] = (xor >> 16) & 0xff;
+
+    ptr  = dib->funcs->get_pixel_ptr(dib, col, start);
+
+    for(i = start; i < end; i++)
+    {
+        do_rop_8(ptr, and_bytes[0], xor_bytes[0]);
+        do_rop_8(ptr + 1, and_bytes[1], xor_bytes[1]);
+        do_rop_8(ptr + 2, and_bytes[2], xor_bytes[2]);
+        ptr += dib->stride;
+    }
+}
+
+static void solid_vline_16(const DIBDRVBITMAP *dib, int col, int start, int end, \
DWORD and, DWORD xor) +{
+    BYTE *ptr;
+    int i;
+
+    ptr = dib->funcs->get_pixel_ptr(dib, col, start);
+
+    for(i = start; i < end; i++)
+    {
+        do_rop_16((WORD*)ptr, and, xor);
+        ptr += dib->stride;
+    }
+}
+
+static void solid_vline_8(const DIBDRVBITMAP *dib, int col, int start, int end, \
DWORD and, DWORD xor) +{
+    BYTE *ptr;
+    int i;
+
+    ptr = dib->funcs->get_pixel_ptr(dib, col, start);
+
+    for(i = start; i < end; i++)
+    {
+        do_rop_8(ptr, and, xor);
+        ptr += dib->stride;
+    }
+}
+
+static void solid_vline_4(const DIBDRVBITMAP *dib, int col, int start, int end, \
DWORD and, DWORD xor) +{
+    BYTE *ptr;
+    int i;
+    BYTE byte_and, byte_xor;
+
+    if(col & 1) /* upper nibble untouched */
+    {
+        byte_and = (and & 0xf) | 0xf0;
+        byte_xor = (xor & 0xf);
+    }
+    else
+    {
+        byte_and = ((and << 4) & 0xf0) | 0x0f;
+        byte_xor = ((xor << 4) & 0xf0);
+    }
+
+    ptr = dib->funcs->get_pixel_ptr(dib, col, start);
+
+    for(i = start; i < end; i++)
+    {
+        do_rop_8(ptr, byte_and, byte_xor);
+        ptr += dib->stride;
+    }
+}
+
+static void solid_vline_1(const DIBDRVBITMAP *dib, int col, int start, int end, \
DWORD and, DWORD xor) +{
+    BYTE *ptr;
+    int i;
+    BYTE byte_and = 0, byte_xor = 0, mask;
+
+    if(and & 1) byte_and = 0xff;
+    if(xor & 1) byte_xor = 0xff;
+
+    mask = 1 << (7 - (col & 7));
+
+    byte_and |= ~mask;
+    byte_xor &= mask;
+
+    ptr = dib->funcs->get_pixel_ptr(dib, col, start);
+
+    for(i = start; i < end; i++)
+    {
+        do_rop_8(ptr, byte_and, byte_xor);
+        ptr += dib->stride;
+    }
+}
+
+/* ------------------------------------------------------------*/
+/*                     PIXEL FUNCTIONS                         */
+
+static void *get_pixel_ptr_32(const DIBDRVBITMAP *dib, int x, int y)
+{
+    BYTE *ptr = dib->bits;
+
+    ptr += (y * dib->stride);
+
+    ptr += x * 4;
+    return ptr;
+}
+
+static void *get_pixel_ptr_24(const DIBDRVBITMAP *dib, int x, int y)
+{
+    BYTE *ptr = dib->bits;
+
+    ptr += (y * dib->stride);
+
+    ptr += x * 3;
+    return ptr;
+}
+
+static void *get_pixel_ptr_16(const DIBDRVBITMAP *dib, int x, int y)
+{
+    BYTE *ptr = dib->bits;
+
+    ptr += (y * dib->stride);
+
+    ptr += x * 2;
+    return ptr;
+}
+
+static void *get_pixel_ptr_8(const DIBDRVBITMAP *dib, int x, int y)
+{
+    BYTE *ptr = dib->bits;
+
+    ptr += (y * dib->stride);
+
+    ptr += x;
+    return ptr;
+}
+
+static void *get_pixel_ptr_4(const DIBDRVBITMAP *dib, int x, int y)
+{
+    BYTE *ptr = dib->bits;
+
+    ptr += (y * dib->stride);
+
+    ptr += x / 2;
+    return ptr;
+}
+
+static void *get_pixel_ptr_1(const DIBDRVBITMAP *dib, int x, int y)
+{
+    BYTE *ptr = dib->bits;
+
+    ptr += (y * dib->stride);
+
+    ptr += x / 8;
+    return ptr;
+}
+
+static void set_pixel_32(const DIBDRVBITMAP *dib, int x, int y, DWORD and, DWORD \
xor) +{
+    DWORD *ptr = dib->funcs->get_pixel_ptr(dib, x, y);
+    do_rop_32(ptr, and, xor);
+}
+
+static void set_pixel_24(const DIBDRVBITMAP *dib, int x, int y, DWORD and, DWORD \
xor) +{
+    BYTE *ptr = dib->funcs->get_pixel_ptr(dib, x, y);
+    do_rop_8(ptr,      and        & 0xff,  xor        & 0xff);
+    do_rop_8(ptr + 1, (and >> 8)  & 0xff, (xor >> 8)  & 0xff);
+    do_rop_8(ptr + 2, (and >> 16) & 0xff, (xor >> 16) & 0xff);
+}
+
+static void set_pixel_16(const DIBDRVBITMAP *dib, int x, int y, DWORD and, DWORD \
xor) +{
+    WORD *ptr = dib->funcs->get_pixel_ptr(dib, x, y);
+    do_rop_16(ptr, and, xor);
+}
+
+static void set_pixel_8(const DIBDRVBITMAP *dib, int x, int y, DWORD and, DWORD xor)
+{
+    BYTE *ptr = dib->funcs->get_pixel_ptr(dib, x, y);
+    do_rop_8(ptr, and, xor);
+}
+
+static void set_pixel_4(const DIBDRVBITMAP *dib, int x, int y, DWORD and, DWORD xor)
+{
+    BYTE *ptr = dib->funcs->get_pixel_ptr(dib, x, y);
+    BYTE byte_and, byte_xor;
+
+    if(x & 1) /* upper nibble untouched */
+    {
+        byte_and = (and & 0xf) | 0xf0;
+        byte_xor = (xor & 0xf);
+    }
+    else
+    {
+        byte_and = ((and << 4) & 0xf0) | 0x0f;
+        byte_xor = ((xor << 4) & 0xf0);
+    }
+
+    do_rop_8(ptr, byte_and, byte_xor);
+}
+
+static void set_pixel_1(const DIBDRVBITMAP *dib, int x, int y, DWORD and, DWORD xor)
+{
+    BYTE *ptr;
+    BYTE byte_and = 0, byte_xor = 0, mask;
+
+    if(and & 1) byte_and = 0xff;
+    if(xor & 1) byte_xor = 0xff;
+
+    mask = 1 << (7 - (x & 7));
+
+    byte_and |= ~mask;
+    byte_xor &= mask;
+
+    ptr = dib->funcs->get_pixel_ptr(dib, x, y);
+
+    do_rop_8(ptr, byte_and, byte_xor);
+}
+
+static DWORD get_pixel_rgb_8888(const DIBDRVBITMAP *dib, int x, int y)
+{
+    DWORD *ptr = dib->funcs->get_pixel_ptr(dib, x, y);
+    return *ptr;
+}
+
+static DWORD get_field (DWORD pixel, int shift, int len)
+{
+    pixel = pixel & (((1 << (len)) - 1) << shift);
+    pixel = pixel << (32 - (shift + len)) >> 24;
+    return pixel;
+}
+
+static DWORD get_pixel_rgb_masks(const DIBDRVBITMAP *dib, int x, int y)
+{
+    DWORD *ptr = dib->funcs->get_pixel_ptr(dib, x, y);
+
+    return get_field(*ptr, dib->red_shift,   dib->red_len)   << 16 |
+           get_field(*ptr, dib->green_shift, dib->green_len) <<  8 |
+           get_field(*ptr, dib->blue_shift,  dib->blue_len);
+}
+
+static DWORD get_pixel_rgb_888(const DIBDRVBITMAP *dib, int x, int y)
+{
+    BYTE *ptr = dib->funcs->get_pixel_ptr(dib, x, y);
+    return (ptr[0] << 16) | (ptr[1] << 8) | ptr[2];
+}
+
+static DWORD get_pixel_rgb_555(const DIBDRVBITMAP *dib, int x, int y)
+{
+    WORD *ptr = dib->funcs->get_pixel_ptr(dib, x, y);
+    return ((*ptr & 0x7c00) << 9) | ((*ptr & 0x03e0) << 6) | ((*ptr & 0x001f) << 3);
+}
+
+static DWORD get_pixel_rgb_565(const DIBDRVBITMAP *dib, int x, int y)
+{
+    WORD *ptr = dib->funcs->get_pixel_ptr(dib, x, y);
+    return ((*ptr & 0xf800) << 8) | ((*ptr & 0x07e0) << 5) | ((*ptr & 0x001f) << 3);
+}
+
+static DWORD get_pixel_rgb_8(const DIBDRVBITMAP *dib, int x, int y)
+{
+    BYTE *ptr = dib->funcs->get_pixel_ptr(dib, x, y);
+    RGBQUAD *color = dib->color_table + *ptr;
+    return (color->rgbRed << 16) | (color->rgbGreen << 8) | color->rgbBlue;
+}
+
+static DWORD get_pixel_rgb_4(const DIBDRVBITMAP *dib, int x, int y)
+{
+    BYTE *ptr = dib->funcs->get_pixel_ptr(dib, x, y), pix;
+    RGBQUAD *color;
+
+    if(x & 1)
+        pix = *ptr & 0x0f;
+    else
+        pix = *ptr >> 4;
+
+    color = dib->color_table + pix;
+    return (color->rgbRed << 16) | (color->rgbGreen << 8) | color->rgbBlue;
+}
+
+static DWORD get_pixel_rgb_1(const DIBDRVBITMAP *dib, int x, int y)
+{
+    BYTE *ptr = dib->funcs->get_pixel_ptr(dib, x, y), pix;
+    RGBQUAD *color;
+
+    pix = *ptr;
+
+    pix >>= (7 - (x & 7));
+    pix &= 1;
+
+    color = dib->color_table + pix;
+    return (color->rgbRed << 16) | (color->rgbGreen << 8) | color->rgbBlue;
+}
+
+/* ------------------------------------------------------------*/
+/*                     COLOR FUNCTIONS                         */
+
+static DWORD colorref_to_pixel_888(const DIBDRVBITMAP *dib, COLORREF color)
+{
+    return ( ((color >> 16) & 0xff) | (color & 0xff00) | ((color << 16) & 0xff0000) \
); +}
+
+static inline DWORD put_field(DWORD field, int shift, int len)
+{
+    shift = shift - (8 - len);
+    if (len <= 8)
+        field &= (((1 << len) - 1) << (8 - len));
+    if (shift < 0)
+        field >>= -shift;
+    else
+        field <<= shift;
+    return field;
+}
+
+static DWORD colorref_to_pixel_masks(const DIBDRVBITMAP *dib, COLORREF color)
+{
+    DWORD r,g,b;
+
+    r = GetRValue(color);
+    g = GetGValue(color);
+    b = GetBValue(color);
+
+    return put_field(r, dib->red_shift,   dib->red_len) |
+           put_field(g, dib->green_shift, dib->green_len) |
+           put_field(b, dib->blue_shift,  dib->blue_len);
+}
+
+static DWORD colorref_to_pixel_555(const DIBDRVBITMAP *dib, COLORREF color)
+{
+    return ( ((color >> 19) & 0x001f) | ((color >> 6) & 0x03e0) | ((color << 7) & \
0x7c00) ); +}
+
+static DWORD colorref_to_pixel_565(const DIBDRVBITMAP *dib, COLORREF color)
+{
+    return ( ((color >> 19) & 0x001f) | ((color >> 5) & 0x07e0) | ((color << 8) & \
0xf800) ); +}
+
+static DWORD colorref_to_pixel_colortable(const DIBDRVBITMAP *dib, COLORREF color)
+{
+    int i, best_index = 0;
+    RGBQUAD rgb;
+    DWORD diff, best_diff = 0xffffffff;
+
+    rgb.rgbRed = GetRValue(color);
+    rgb.rgbGreen = GetGValue(color);
+    rgb.rgbBlue = GetBValue(color);
+
+    for(i = 0; i < dib->color_table_size; i++)
+    {
+        RGBQUAD *cur = dib->color_table + i;
+        diff = (rgb.rgbRed - cur->rgbRed) * (rgb.rgbRed - cur->rgbRed)
+            +  (rgb.rgbGreen - cur->rgbGreen) * (rgb.rgbGreen - cur->rgbGreen)
+            +  (rgb.rgbBlue - cur->rgbBlue) * (rgb.rgbBlue - cur->rgbBlue);
+
+        if(diff == 0)
+        {
+            best_index = i;
+            break;
+        }
+
+        if(diff < best_diff)
+        {
+            best_diff = diff;
+            best_index = i;
+        }
+    }
+    return best_index;
+}
+
+/* ------------------------------------------------------------*/
+/*               FREETYPE FONT BITMAP BLITTING                 */
+
+static void freetype_blit_8888(const DIBDRVBITMAP *dib, int x, int y, FT_Bitmap \
*bmp) +{
+    /* FIXME : MUST BE OPTIMIZED !!! */
+    
+    INT bmpX, bmpY;
+    BYTE *buf;
+    INT dibX, dibY;
+    INT DIBX, DIBY;
+    DWORD c;
+    DWORD *ptr;
+
+    /* gets DIB limits */
+    DIBX = dib->width;
+    DIBY = dib->height;
+
+    /* loop for every pixel in bitmap */
+    buf = bmp->buffer;
+    for(bmpY = 0, dibY = y; bmpY < bmp->rows; bmpY++, dibY++)
+    {
+        ptr = (DWORD *)(dib->bits + (dibY * dib->stride) + x * 4);
+        for(bmpX = 0, dibX = x; bmpX < bmp->width; bmpX++, dibX++)
+        {
+            if(dibX < DIBX && dibY < DIBY && dibX > 0 && dibY > 0 && *buf)
+            {
+                c = dib->textColorTable[*buf];
+                *ptr = c;
+            }
+            buf++;
+            ptr++;
+        }
+    }
+}
+
+static void freetype_blit_32(const DIBDRVBITMAP *dib, int x, int y, FT_Bitmap *bmp)
+{
+    /* FIXME : MUST BE OPTIMIZED !!! */
+    
+    INT bmpX, bmpY;
+    BYTE *buf;
+    INT dibX, dibY;
+    INT DIBX, DIBY;
+    DWORD c;
+
+    /* gets DIB limits */
+    DIBX = dib->width;
+    DIBY = dib->height;
+
+    /* loop for every pixel in bitmap */
+    buf = bmp->buffer;
+    for(bmpY = 0, dibY = y; bmpY < bmp->rows; bmpY++, dibY++)
+    {
+        for(bmpX = 0, dibX = x; bmpX < bmp->width; bmpX++, dibX++)
+        {
+            if(dibX < DIBX && dibY < DIBY && dibX > 0 && dibY > 0 && *buf)
+            {
+                c = dib->textColorTable[*buf];
+                dib->funcs->set_pixel(dib, dibX, dibY, 0, c);
+            }
+            buf++;
+        }
+    }
+}
+
+static void freetype_blit_24(const DIBDRVBITMAP *dib, int x, int y, FT_Bitmap *bmp)
+{
+    /* FIXME : MUST BE OPTIMIZED !!! */
+    
+    INT bmpX, bmpY;
+    BYTE *buf;
+    INT dibX, dibY;
+    INT DIBX, DIBY;
+    DWORD c;
+
+    /* gets DIB limits */
+    DIBX = dib->width;
+    DIBY = dib->height;
+
+    /* loop for every pixel in bitmap */
+    buf = bmp->buffer;
+    for(bmpY = 0, dibY = y; bmpY < bmp->rows; bmpY++, dibY++)
+    {
+        for(bmpX = 0, dibX = x; bmpX < bmp->width; bmpX++, dibX++)
+        {
+            if(dibX < DIBX && dibY < DIBY && dibX > 0 && dibY > 0 && *buf)
+            {
+                c = dib->textColorTable[*buf];
+                dib->funcs->set_pixel(dib, dibX, dibY, 0, c);
+            }
+            buf++;
+        }
+    }
+}
+
+static void freetype_blit_555(const DIBDRVBITMAP *dib, int x, int y, FT_Bitmap *bmp)
+{
+    /* FIXME : MUST BE OPTIMIZED !!! */
+    
+    INT bmpX, bmpY;
+    BYTE *buf;
+    INT dibX, dibY;
+    INT DIBX, DIBY;
+    DWORD c;
+
+    /* gets DIB limits */
+    DIBX = dib->width;
+    DIBY = dib->height;
+
+    /* loop for every pixel in bitmap */
+    buf = bmp->buffer;
+    for(bmpY = 0, dibY = y; bmpY < bmp->rows; bmpY++, dibY++)
+    {
+        for(bmpX = 0, dibX = x; bmpX < bmp->width; bmpX++, dibX++)
+        {
+            if(dibX < DIBX && dibY < DIBY && dibX > 0 && dibY > 0 && *buf)
+            {
+                c = dib->textColorTable[*buf];
+                dib->funcs->set_pixel(dib, dibX, dibY, 0, c);
+            }
+            buf++;
+        }
+    }
+}
+
+static void freetype_blit_565(const DIBDRVBITMAP *dib, int x, int y, FT_Bitmap *bmp)
+{
+    /* FIXME : MUST BE OPTIMIZED !!! */
+    
+    INT bmpX, bmpY;
+    BYTE *buf;
+    INT dibX, dibY;
+    INT DIBX, DIBY;
+    DWORD c;
+
+    /* gets DIB limits */
+    DIBX = dib->width;
+    DIBY = dib->height;
+
+    /* loop for every pixel in bitmap */
+    buf = bmp->buffer;
+    for(bmpY = 0, dibY = y; bmpY < bmp->rows; bmpY++, dibY++)
+    {
+        for(bmpX = 0, dibX = x; bmpX < bmp->width; bmpX++, dibX++)
+        {
+            if(dibX < DIBX && dibY < DIBY && dibX > 0 && dibY > 0 && *buf)
+            {
+                c = dib->textColorTable[*buf];
+                dib->funcs->set_pixel(dib, dibX, dibY, 0, c);
+            }
+            buf++;
+        }
+    }
+}
+
+static void freetype_blit_16(const DIBDRVBITMAP *dib, int x, int y, FT_Bitmap *bmp)
+{
+    /* FIXME : MUST BE OPTIMIZED !!! */
+    
+    INT bmpX, bmpY;
+    BYTE *buf;
+    INT dibX, dibY;
+    INT DIBX, DIBY;
+    DWORD c;
+
+    /* gets DIB limits */
+    DIBX = dib->width;
+    DIBY = dib->height;
+
+    /* loop for every pixel in bitmap */
+    buf = bmp->buffer;
+    for(bmpY = 0, dibY = y; bmpY < bmp->rows; bmpY++, dibY++)
+    {
+        for(bmpX = 0, dibX = x; bmpX < bmp->width; bmpX++, dibX++)
+        {
+            if(dibX < DIBX && dibY < DIBY && dibX > 0 && dibY > 0 && *buf)
+            {
+                c = dib->textColorTable[*buf];
+                dib->funcs->set_pixel(dib, dibX, dibY, 0, c);
+            }
+            buf++;
+        }
+    }
+}
+
+static void freetype_blit_8(const DIBDRVBITMAP *dib, int x, int y, FT_Bitmap *bmp)
+{
+    /* FIXME : MUST BE OPTIMIZED !!! */
+    
+    INT bmpX, bmpY;
+    BYTE *buf;
+    INT dibX, dibY;
+    INT DIBX, DIBY;
+    DWORD c;
+
+    /* gets DIB limits */
+    DIBX = dib->width;
+    DIBY = dib->height;
+
+    /* loop for every pixel in bitmap */
+    buf = bmp->buffer;
+    for(bmpY = 0, dibY = y; bmpY < bmp->rows; bmpY++, dibY++)
+    {
+        for(bmpX = 0, dibX = x; bmpX < bmp->width; bmpX++, dibX++)
+        {
+            if(dibX < DIBX && dibY < DIBY && dibX > 0 && dibY > 0 && *buf)
+            {
+                c = dib->textColorTable[*buf];
+                dib->funcs->set_pixel(dib, dibX, dibY, 0, c);
+            }
+            buf++;
+        }
+    }
+}
+
+static void freetype_blit_4(const DIBDRVBITMAP *dib, int x, int y, FT_Bitmap *bmp)
+{
+    /* FIXME : MUST BE OPTIMIZED !!! */
+    
+    INT bmpX, bmpY;
+    BYTE *buf;
+    INT dibX, dibY;
+    INT DIBX, DIBY;
+    DWORD c;
+
+    /* gets DIB limits */
+    DIBX = dib->width;
+    DIBY = dib->height;
+
+    /* loop for every pixel in bitmap */
+    buf = bmp->buffer;
+    for(bmpY = 0, dibY = y; bmpY < bmp->rows; bmpY++, dibY++)
+    {
+        for(bmpX = 0, dibX = x; bmpX < bmp->width; bmpX++, dibX++)
+        {
+            if(dibX < DIBX && dibY < DIBY && dibX > 0 && dibY > 0 && *buf)
+            {
+                c = dib->textColorTable[*buf];
+                dib->funcs->set_pixel(dib, dibX, dibY, 0, c);
+            }
+            buf++;
+        }
+    }
+}
+
+static void freetype_blit_1(const DIBDRVBITMAP *dib, int x, int y, FT_Bitmap *bmp)
+{
+    /* FIXME : MUST BE OPTIMIZED !!! */
+    
+    INT bmpX, bmpY;
+    BYTE *buf;
+    INT dibX, dibY;
+    INT DIBX, DIBY;
+    DWORD c;
+
+    /* gets DIB limits */
+    DIBX = dib->width;
+    DIBY = dib->height;
+
+    /* loop for every pixel in bitmap */
+    buf = bmp->buffer;
+    for(bmpY = 0, dibY = y; bmpY < bmp->rows; bmpY++, dibY++)
+    {
+        for(bmpX = 0, dibX = x; bmpX < bmp->width; bmpX++, dibX++)
+        {
+            if(dibX < DIBX && dibY < DIBY && dibX > 0 && dibY > 0 && *buf)
+            {
+                c = dib->textColorTable[*buf];
+                dib->funcs->set_pixel(dib, dibX, dibY, 0, c);
+            }
+            buf++;
+        }
+    }
+}
+
+
+DIBDRV_PRIMITIVE_FUNCS DIBDRV_funcs_8888 =
+{
+    solid_hline_32,
+    pattern_hline_32,
+    solid_vline_32,
+    get_pixel_ptr_32,
+    set_pixel_32,
+    get_pixel_rgb_8888,
+    colorref_to_pixel_888,
+    freetype_blit_8888
+};
+
+DIBDRV_PRIMITIVE_FUNCS DIBDRV_funcs_32 =
+{
+    solid_hline_32,
+    pattern_hline_32,
+    solid_vline_32,
+    get_pixel_ptr_32,
+    set_pixel_32,
+    get_pixel_rgb_masks,
+    colorref_to_pixel_masks,
+    freetype_blit_32
+};
+
+DIBDRV_PRIMITIVE_FUNCS DIBDRV_funcs_888 =
+{
+    solid_hline_24,
+    pattern_hline_24,
+    solid_vline_24,
+    get_pixel_ptr_24,
+    set_pixel_24,
+    get_pixel_rgb_888,
+    colorref_to_pixel_888,
+    freetype_blit_24
+};
+
+DIBDRV_PRIMITIVE_FUNCS DIBDRV_funcs_555 =
+{
+    solid_hline_16,
+    pattern_hline_16,
+    solid_vline_16,
+    get_pixel_ptr_16,
+    set_pixel_16,
+    get_pixel_rgb_555,
+    colorref_to_pixel_555,
+    freetype_blit_555
+};
+
+DIBDRV_PRIMITIVE_FUNCS DIBDRV_funcs_565 =
+{
+    solid_hline_16,
+    pattern_hline_16,
+    solid_vline_16,
+    get_pixel_ptr_16,
+    set_pixel_16,
+    get_pixel_rgb_565,
+    colorref_to_pixel_565,
+    freetype_blit_565
+};
+
+DIBDRV_PRIMITIVE_FUNCS DIBDRV_funcs_16 =
+{
+    solid_hline_16,
+    pattern_hline_16,
+    solid_vline_16,
+    get_pixel_ptr_16,
+    set_pixel_16,
+    get_pixel_rgb_masks,
+    colorref_to_pixel_masks,
+    freetype_blit_16
+};
+
+DIBDRV_PRIMITIVE_FUNCS DIBDRV_funcs_8 =
+{
+    solid_hline_8,
+    pattern_hline_8,
+    solid_vline_8,
+    get_pixel_ptr_8,
+    set_pixel_8,
+    get_pixel_rgb_8,
+    colorref_to_pixel_colortable,
+    freetype_blit_8
+};
+
+DIBDRV_PRIMITIVE_FUNCS DIBDRV_funcs_4 =
+{
+    solid_hline_4,
+    pattern_hline_4,
+    solid_vline_4,
+    get_pixel_ptr_4,
+    set_pixel_4,
+    get_pixel_rgb_4,
+    colorref_to_pixel_colortable,
+    freetype_blit_4
+};
+
+DIBDRV_PRIMITIVE_FUNCS DIBDRV_funcs_1 =
+{
+    solid_hline_1,
+    pattern_hline_1,
+    solid_vline_1,
+    get_pixel_ptr_1,
+    set_pixel_1,
+    get_pixel_rgb_1,
+    colorref_to_pixel_colortable,
+    freetype_blit_1
+};
diff --git a/dlls/winedib.drv/text.c b/dlls/winedib.drv/text.c
new file mode 100644
index 0000000..a8269c5
--- /dev/null
+++ b/dlls/winedib.drv/text.c
@@ -0,0 +1,178 @@
+/*
+ * DIBDRV text functions
+ *
+ * Copyright 2007 Jesse Allen
+ * Copyright 2008 Massimo Del Fedele
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#include "config.h"
+#include "wine/port.h"
+
+#include "dibdrv.h"
+
+WINE_DEFAULT_DEBUG_CHANNEL(dibdrv);
+
+/* copies bitmapped font to DIB */
+extern COLORREF DIBDRV_SetPixel( DIBDRVPHYSDEV *physDev, INT x, INT y, COLORREF \
color ); +static void DrawCharBitmap(DIBDRVPHYSDEV *physDev, INT x, INT y, FT_Bitmap \
*bmp) +{
+    physDev->bmp.funcs->freetype_blit(&physDev->bmp, x, y, bmp);
+}
+
+/***********************************************************************
+ *           DIBDRV_ExtTextOut
+ */
+BOOL
+DIBDRV_ExtTextOut( DIBDRVPHYSDEV *physDev, INT x, INT y, UINT flags,
+                   const RECT *lprect, LPCWSTR wstr, UINT count,
+                   const INT *lpDx )
+{
+    /* FIXME : TODO many, many stuffs... just trivial text support by now */
+
+    FT_Face face;
+    FT_UInt glyph_index;
+    INT n;
+    INT error;
+    LOGFONTW lf;
+    LPCWSTR wstrPnt;
+    
+    FT_Glyph glyph;
+    FT_BitmapGlyph bitmap;
+    double cosEsc, sinEsc;
+    FT_Matrix matrix;
+    FT_Vector start; 
+    int dx, dy;
+    
+    FIXME("Text : %s\n", debugstr_w(wstr));
+
+    face = physDev->face;
+    if(!face)
+    {
+        ERR("FreeType face is null\n");
+        return TRUE;
+    }
+    
+    /* gets font data, etc */
+    GetObjectW(GetCurrentObject(physDev->hdc, OBJ_FONT), sizeof(lf), &lf);
+
+    /* sets character pixel size
+      FIXME : strange behaviour, don't know why the 64 and 20 numbers... */
+    error = pFT_Set_Char_Size(
+        face,                                      /* handle to face object */
+        MulDiv(abs(lf.lfWidth), 64, 20),           /* char_width in 1/64th of points \
*/ +        MulDiv(abs(lf.lfHeight), 64, 20),          /* char_height in 1/64th of \
points */ +        DIBDRV_GetDeviceCaps(physDev, LOGPIXELSX), /* horizontal device \
resolution */ +        DIBDRV_GetDeviceCaps(physDev, LOGPIXELSY)  /* vertical device \
resolution */  +    );
+    if(error)
+        ERR("Couldn't set char size to (%d,%d)\n", lf.lfWidth, lf.lfHeight);
+
+    /* transformation matrix and vector */
+    start.x = 0;
+    start.y = 0;
+    if(lf.lfEscapement != 0)
+    {
+        cosEsc = cos(lf.lfEscapement * M_PI / 1800);
+        sinEsc = sin(lf.lfEscapement * M_PI / 1800);
+    }
+    else
+    {
+        cosEsc = 1;
+        sinEsc = 0;
+    }
+    matrix.xx = (FT_Fixed)( cosEsc * 0x10000L );
+    matrix.xy = (FT_Fixed)(-sinEsc * 0x10000L );
+    matrix.yx = (FT_Fixed)( sinEsc * 0x10000L );
+    matrix.yy = (FT_Fixed)( cosEsc * 0x10000L );
+ 
+    /* outputs characters one by one */
+    wstrPnt = wstr;
+    for ( n = 0; n < count; n++ )
+    {
+        /* retrieve glyph index from character code */
+        if(flags & ETO_GLYPH_INDEX)
+            glyph_index = *wstrPnt++;
+        else
+            glyph_index = pFT_Get_Char_Index( face, *wstrPnt++);
+
+        /* load glyph image into the slot (erase previous one) */
+        error = pFT_Load_Glyph( face, glyph_index, FT_LOAD_DEFAULT );
+        if(error)
+        {
+            ERR("Couldn't load glyph at index %d\n", glyph_index);
+            /* ignore errors */
+            continue;
+        }
+        error = pFT_Get_Glyph(face->glyph, &glyph);
+        if ( error )
+        {
+            FIXME("Couldn't get glyph\n");
+            continue; 
+        }
+ 
+        /* apply transformation to glyph */
+        if ( glyph->format != FT_GLYPH_FORMAT_BITMAP )
+            pFT_Glyph_Transform(glyph, &matrix, &start ); 
+                
+        /* gets advance BEFORE transforming... */
+        dx = glyph->advance.x;
+        dy = glyph->advance.y;
+         
+        /* convert to an anti-aliased bitmap, if needed */
+        if ( glyph->format != FT_GLYPH_FORMAT_BITMAP )
+        {
+            error = pFT_Glyph_To_Bitmap(
+                &glyph,
+                FT_RENDER_MODE_NORMAL,
+                0, /* no additional translation */
+                1  /* destroy copy in "image" */
+            );  
+
+            /* ignore errors */
+            if ( error )
+            {
+                FIXME("Couldn't render glyph\n");
+                pFT_Done_Glyph(glyph);
+                continue;
+            }
+        }
+
+        /* now, draw to our target surface */
+        bitmap = (FT_BitmapGlyph)glyph;
+        DrawCharBitmap(physDev, x+bitmap->left, y-bitmap->top, &bitmap->bitmap);
+
+        /* increment pen position */
+        x += dx>>16;
+        y -= dy>>16;
+
+        pFT_Done_Glyph(glyph);
+    } 
+
+    return TRUE;
+}
+
+/***********************************************************************
+ *           DIBDRV_GetTextExtentExPoint
+ */
+BOOL DIBDRV_GetTextExtentExPoint( DIBDRVPHYSDEV *physDev, LPCWSTR str, INT count,
+                                  INT maxExt, LPINT lpnFit, LPINT alpDx, LPSIZE size \
) +{
+//#ifdef DIBDRV_SHOW_STUBS
+    FIXME("stub\n");
+//#endif
+    return TRUE;
+}
diff --git a/dlls/winedib.drv/video.c b/dlls/winedib.drv/video.c
new file mode 100644
index 0000000..ab8632c
--- /dev/null
+++ b/dlls/winedib.drv/video.c
@@ -0,0 +1,49 @@
+/*
+ * DIBDRV video functions
+ *
+ * Copyright 2007 Jesse Allen
+ * Copyright 2008 Massimo Del Fedele
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#include "config.h"
+#include "wine/port.h"
+
+#include "dibdrv.h"
+
+WINE_DEFAULT_DEBUG_CHANNEL(dibdrv);
+
+/***********************************************************************
+ *              DIBDRV_GetDeviceGammaRamp
+ */
+BOOL DIBDRV_GetDeviceGammaRamp( DIBDRVPHYSDEV *physDev, LPVOID ramp )
+{
+#ifdef DIBDRV_SHOW_STUBS
+    FIXME("stub\n");
+#endif
+    return TRUE;
+}
+
+/***********************************************************************
+ *              DIBDRV_SetDeviceGammaRamp
+ */
+BOOL DIBDRV_SetDeviceGammaRamp( DIBDRVPHYSDEV *physDev, LPVOID ramp )
+{
+#ifdef DIBDRV_SHOW_STUBS
+    FIXME("stub\n");
+#endif
+    return TRUE;
+}
diff --git a/dlls/winedib.drv/winedib.drv.spec b/dlls/winedib.drv/winedib.drv.spec
new file mode 100644
index 0000000..c8458b5
--- /dev/null
+++ b/dlls/winedib.drv/winedib.drv.spec
@@ -0,0 +1,61 @@
+@ cdecl AlphaBlend(ptr long long long long ptr long long long long long) \
DIBDRV_AlphaBlend +@ cdecl Arc(ptr long long long long long long long long) \
DIBDRV_Arc +@ cdecl BitBlt(ptr long long long long ptr long long long) DIBDRV_BitBlt
+@ cdecl ChoosePixelFormat(ptr ptr) DIBDRV_ChoosePixelFormat
+@ cdecl Chord(ptr long long long long long long long long) DIBDRV_Chord
+@ cdecl CreateBitmap(ptr long ptr) DIBDRV_CreateBitmap
+@ cdecl CreateDC(long ptr wstr wstr wstr ptr) DIBDRV_CreateDC
+@ cdecl CreateDIBSection(ptr long ptr long) DIBDRV_CreateDIBSection
+@ cdecl DeleteBitmap(long) DIBDRV_DeleteBitmap
+@ cdecl DeleteDC(ptr) DIBDRV_DeleteDC
+@ cdecl DescribePixelFormat(ptr long long ptr) DIBDRV_DescribePixelFormat
+@ cdecl Ellipse(ptr long long long long) DIBDRV_Ellipse
+@ cdecl EnumDeviceFonts(ptr ptr ptr long) DIBDRV_EnumDeviceFonts
+@ cdecl ExtEscape(ptr long long ptr long ptr) DIBDRV_ExtEscape
+@ cdecl ExtFloodFill(ptr long long long long) DIBDRV_ExtFloodFill
+@ cdecl ExtTextOut(ptr long long long ptr ptr long ptr) DIBDRV_ExtTextOut
+@ cdecl GetBitmapBits(long ptr long) DIBDRV_GetBitmapBits
+@ cdecl GetCharWidth(ptr long long ptr) DIBDRV_GetCharWidth
+@ cdecl GetDCOrgEx(ptr ptr) DIBDRV_GetDCOrgEx
+@ cdecl GetDIBits(ptr long long long ptr ptr long) DIBDRV_GetDIBits
+@ cdecl GetDeviceCaps(ptr long) DIBDRV_GetDeviceCaps
+@ cdecl GetDeviceGammaRamp(ptr ptr) DIBDRV_GetDeviceGammaRamp
+@ cdecl GetNearestColor(ptr long) DIBDRV_GetNearestColor
+@ cdecl GetPixel(ptr long long) DIBDRV_GetPixel
+@ cdecl GetPixelFormat(ptr) DIBDRV_GetPixelFormat
+@ cdecl GetSystemPaletteEntries(ptr long long ptr) DIBDRV_GetSystemPaletteEntries
+@ cdecl GetTextExtentExPoint(ptr ptr long long ptr ptr ptr) \
DIBDRV_GetTextExtentExPoint +@ cdecl GetTextMetrics(ptr ptr) DIBDRV_GetTextMetrics
+@ cdecl LineTo(ptr long long) DIBDRV_LineTo
+@ cdecl PaintRgn(ptr long) DIBDRV_PaintRgn
+@ cdecl PatBlt(ptr long long long long long) DIBDRV_PatBlt
+@ cdecl Pie(ptr long long long long long long long long) DIBDRV_Pie
+@ cdecl PolyPolygon(ptr ptr ptr long) DIBDRV_PolyPolygon
+@ cdecl PolyPolyline(ptr ptr ptr long) DIBDRV_PolyPolyline
+@ cdecl Polygon(ptr ptr long) DIBDRV_Polygon
+@ cdecl Polyline(ptr ptr long) DIBDRV_Polyline
+@ cdecl RealizeDefaultPalette(ptr) DIBDRV_RealizeDefaultPalette
+@ cdecl RealizePalette(ptr long long) DIBDRV_RealizePalette
+@ cdecl Rectangle(ptr long long long long) DIBDRV_Rectangle
+@ cdecl RoundRect(ptr long long long long long long) DIBDRV_RoundRect
+@ cdecl SelectBitmap(ptr long) DIBDRV_SelectBitmap
+@ cdecl SelectBrush(ptr long) DIBDRV_SelectBrush
+@ cdecl SelectFont(ptr long long) DIBDRV_SelectFont
+@ cdecl SelectPen(ptr long) DIBDRV_SelectPen
+@ cdecl SetBitmapBits(long ptr long) DIBDRV_SetBitmapBits
+@ cdecl SetBkColor(ptr long) DIBDRV_SetBkColor
+@ cdecl SetDCBrushColor(ptr long) DIBDRV_SetDCBrushColor
+@ cdecl SetDCOrg(ptr long long) DIBDRV_SetDCOrg
+@ cdecl SetDCPenColor(ptr long) DIBDRV_SetDCPenColor
+@ cdecl SetDeviceClipping(ptr long long) DIBDRV_SetDeviceClipping
+@ cdecl SetDeviceGammaRamp(ptr ptr) DIBDRV_SetDeviceGammaRamp
+@ cdecl SetDIBColorTable(ptr long long ptr) DIBDRV_SetDIBColorTable
+@ cdecl SetDIBits(ptr long long long ptr ptr long) DIBDRV_SetDIBits
+@ cdecl SetDIBitsToDevice(ptr long long long long long long long long ptr ptr long) \
DIBDRV_SetDIBitsToDevice +@ cdecl SetPixel(ptr long long long) DIBDRV_SetPixel
+@ cdecl SetPixelFormat(ptr long ptr) DIBDRV_SetPixelFormat
+@ cdecl SetROP2(ptr long) DIBDRV_SetROP2
+@ cdecl SetTextColor(ptr long) DIBDRV_SetTextColor
+@ cdecl StretchBlt(ptr long long long long ptr long long long long long) \
DIBDRV_StretchBlt +@ cdecl SwapBuffers(ptr) DIBDRV_SwapBuffers
+@ cdecl UnrealizePalette(long) DIBDRV_UnrealizePalette
\ No newline at end of file





[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic