Resubmit: Add initial "write text" support for VGA graphic modes

Jeremiah Flerchinger jeremiah.flerchinger at gmail.com
Sun Mar 15 23:23:33 CDT 2009


Include gdi in winedos makefile so we can load font into bitmaps. Font
should be Terminal/OEM/IBM charset, but default is readable for 256
color packed pixel modes. Support for CGA memory models can be added
after this patch & "Add VGA memory mode information" patch is accepted.
---
 dlls/winedos/Makefile.in |    2 +-
 dlls/winedos/vga.c       |   85 ++++++++++++++++++++++++++++++++++++++++++++--
 2 files changed, 83 insertions(+), 4 deletions(-)

diff --git a/dlls/winedos/Makefile.in b/dlls/winedos/Makefile.in
index ede4c7c..ef942b8 100644
--- a/dlls/winedos/Makefile.in
+++ b/dlls/winedos/Makefile.in
@@ -3,7 +3,7 @@ TOPOBJDIR = ../..
 SRCDIR    = @srcdir@
 VPATH     = @srcdir@
 MODULE    = winedos.dll
-IMPORTS   = user32 kernel32 ntdll
+IMPORTS   = user32 kernel32 ntdll gdi32
 
 SPEC_SRCS16 = wprocs.spec
 
diff --git a/dlls/winedos/vga.c b/dlls/winedos/vga.c
index 6c9085e..80b4283 100644
--- a/dlls/winedos/vga.c
+++ b/dlls/winedos/vga.c
@@ -766,7 +766,6 @@ static void VGA_SyncWindow( BOOL target_is_fb )
         memmove( vga_fb_window_data, vga_fb_data + vga_fb_window, size );
 }
 
-
 static void WINAPI VGA_DoExit(ULONG_PTR arg)
 {
     VGA_DeinstallTimer();
@@ -1402,17 +1401,97 @@ void VGA_GetCursorPos(unsigned*X,unsigned*Y)
 
 static void VGA_PutCharAt(unsigned x, unsigned y, BYTE ascii, int attr)
 {
+    int DrawTextHeight;
+    RECT rect;
+    HDC hDC;
+    HBITMAP hTempBmp;
+    DWORD* pSrcData;
+    HFONT IBM_hFont;
+    LOGFONTA IBM_lFont;
+    HFONT ModIBM_hFont;
+    int fgColor;
+    int bgColor;
+    char *dat;
+    int ih;
+    int iw;
     const VGA_MODE *ModeInfo = VGA_GetModeInfo(VGA_CurrentMode);
+    BITMAPINFO bmi = { sizeof( BITMAPINFOHEADER ), ModeInfo->CharWidth, -ModeInfo->CharHeight, 1, 32, BI_RGB, 0, 0, 0, 0, 0 };
+
     if ( ModeInfo->ModeType == TEXT )
     {
-       char *dat = VGA_AlphaBuffer() + ((vga_text_width * y + x) * 2);
+       dat = VGA_AlphaBuffer() + ((vga_text_width * y + x) * 2);
        dat[0] = ascii;
        if (attr>=0)
           dat[1] = attr;
     }
     else
     {
-       FIXME("Write %c at (%i,%i) - not yet supported in graphic modes.\n", (char)ascii, x, y);
+       dat = vga_fb_window_data;
+       fgColor = attr & 0x0F;
+       bgColor = (attr & 0x70)>>4;
+       hDC = CreateCompatibleDC(NULL);
+       if (hDC == 0)
+       {
+          ERR("CreateCompatibleDC FAILED. \n");
+          return;
+       }
+       hTempBmp = CreateDIBSection( hDC, &bmi, DIB_RGB_COLORS, (void**)&pSrcData, NULL, 0 );
+       if (hTempBmp == NULL)
+       {
+          ERR("CreateDIBSection FAILED. \n");
+          ReleaseDC(NULL, hDC);
+          return;
+       }
+       IBM_hFont = (HFONT) GetStockObject( OEM_FIXED_FONT );
+       GetObjectA ( IBM_hFont, sizeof(LOGFONTA), & IBM_lFont );
+       /* scale character & set attributes - FIXME tweak or make better font for smaller sizes */
+       IBM_lFont.lfWidth = ModeInfo->CharWidth;
+       IBM_lFont.lfHeight = ModeInfo->CharHeight;
+       ModIBM_hFont = CreateFontIndirectA ( & IBM_lFont );
+       if (ModIBM_hFont == NULL)
+       {
+          ERR("CreateFontIndirectA FAILED. \n");
+          DeleteObject(hTempBmp);
+          ReleaseDC(NULL, hDC);
+          return;
+       }
+       SelectObject(hDC, hTempBmp);
+       SelectObject(hDC, ModIBM_hFont);
+       SetTextColor(hDC, fgColor<<16); /* set text color 0x00bbggrr */
+       SetBkColor(hDC, bgColor<<16);  /* set text color 0x00bbggrr */
+       rect.left = 0;
+       rect.top = 0;
+       rect.bottom = ModeInfo->CharHeight-1;
+       rect.right = ModeInfo->CharWidth-1;
+       DrawTextHeight = DrawTextA(hDC, (char *)&ascii, 1, &rect, DT_LEFT);
+       if (DrawTextHeight == 0)
+       {
+          ERR("DrawTextA FAILED. \n");
+          DeleteObject(hTempBmp);
+          DeleteObject(ModIBM_hFont);
+          ReleaseDC(NULL, hDC);
+          return;
+       }
+       x = x * ModeInfo->CharWidth;
+       y = y * ModeInfo->CharHeight;
+       for (ih = 0; ih < ModeInfo->CharHeight; ih = ih+1)
+       {
+         for (iw = 0; iw < ModeInfo->CharWidth; iw = iw+1)
+         {
+            if (VGA_CurrentMode == 19)
+            {
+               dat[(y+ih)*ModeInfo->Width + (x+iw)] =  (*( pSrcData + iw + ih*ModeInfo->CharWidth )) &  0x000000ff;
+            }
+            else
+            {
+               FIXME("Write '%c' in color %X on %X at (%i,%i) - not yet fully supported in graphic modes.\n", (char)ascii, fgColor, bgColor, x, y);
+               FIXME("Only Packed Pixel, aka Linear, Memory models, such as in mode 19, are supported. \n");
+            }
+         }
+       }
+       DeleteObject(hTempBmp);
+       DeleteObject(ModIBM_hFont);
+       ReleaseDC(NULL, hDC);
     }
 }
 
-- 
1.5.6.3




More information about the wine-patches mailing list