| 1 | /* $Id: text.cpp,v 1.4 1999-12-10 08:34:06 achimha Exp $ */
|
|---|
| 2 |
|
|---|
| 3 | /*
|
|---|
| 4 | * GDI32 text apis
|
|---|
| 5 | *
|
|---|
| 6 | * Based on Wine code (991031) (objects\text.c)
|
|---|
| 7 | *
|
|---|
| 8 | * Copyright 1993, 1994 Alexandre Julliard
|
|---|
| 9 | *
|
|---|
| 10 | *
|
|---|
| 11 | * Project Odin Software License can be found in LICENSE.TXT
|
|---|
| 12 | *
|
|---|
| 13 | */
|
|---|
| 14 | #include <os2win.h>
|
|---|
| 15 | #include <stdlib.h>
|
|---|
| 16 | #include <misc.h>
|
|---|
| 17 | #include <string.h>
|
|---|
| 18 | #include "oslibgpi.h"
|
|---|
| 19 |
|
|---|
| 20 | //******************************************************************************
|
|---|
| 21 | //******************************************************************************
|
|---|
| 22 | UINT WINAPI GetTextCharsetInfo(
|
|---|
| 23 | HDC hdc, /* [in] Handle to device context */
|
|---|
| 24 | LPFONTSIGNATURE fs, /* [out] Pointer to struct to receive data */
|
|---|
| 25 | DWORD flags) /* [in] Reserved - must be 0 */
|
|---|
| 26 | {
|
|---|
| 27 | HGDIOBJ hFont;
|
|---|
| 28 | UINT charSet = DEFAULT_CHARSET;
|
|---|
| 29 | LOGFONTW lf;
|
|---|
| 30 | CHARSETINFO csinfo;
|
|---|
| 31 |
|
|---|
| 32 | dprintf(("GetTextCharsetInfo %x %x %x", hdc, fs, flags));
|
|---|
| 33 |
|
|---|
| 34 | hFont = GetCurrentObject(hdc, OBJ_FONT);
|
|---|
| 35 | if (hFont == 0)
|
|---|
| 36 | return(DEFAULT_CHARSET);
|
|---|
| 37 | if ( GetObjectW(hFont, sizeof(LOGFONTW), &lf) != 0 )
|
|---|
| 38 | charSet = lf.lfCharSet;
|
|---|
| 39 |
|
|---|
| 40 | if (fs != NULL) {
|
|---|
| 41 | if (!TranslateCharsetInfo((LPDWORD)charSet, &csinfo, TCI_SRCCHARSET))
|
|---|
| 42 | return (DEFAULT_CHARSET);
|
|---|
| 43 | memcpy(fs, &csinfo.fs, sizeof(FONTSIGNATURE));
|
|---|
| 44 | }
|
|---|
| 45 | return charSet;
|
|---|
| 46 | }
|
|---|
| 47 | /***********************************************************************
|
|---|
| 48 | * GetTextCharset32 [GDI32.226] Gets character set for font in DC
|
|---|
| 49 | *
|
|---|
| 50 | * NOTES
|
|---|
| 51 | * Should it return a UINT32 instead of an INT32?
|
|---|
| 52 | * => YES, as GetTextCharsetInfo returns UINT32
|
|---|
| 53 | *
|
|---|
| 54 | * RETURNS
|
|---|
| 55 | * Success: Character set identifier
|
|---|
| 56 | * Failure: DEFAULT_CHARSET
|
|---|
| 57 | */
|
|---|
| 58 | UINT WINAPI GetTextCharset(HDC hdc) /* [in] Handle to device context */
|
|---|
| 59 | {
|
|---|
| 60 | /* MSDN docs say this is equivalent */
|
|---|
| 61 | return GetTextCharsetInfo(hdc, NULL, 0);
|
|---|
| 62 | }
|
|---|
| 63 | //******************************************************************************
|
|---|
| 64 | // CB: USER32 function, but here is the better place
|
|---|
| 65 | //******************************************************************************
|
|---|
| 66 | INT WIN32API InternalDrawTextExA(HDC hdc,LPCSTR lpchText,INT cchText,LPRECT lprc,UINT dwDTFormat,LPDRAWTEXTPARAMS lpDTParams)
|
|---|
| 67 | {
|
|---|
| 68 | //CB: todo
|
|---|
| 69 | dprintf(("GDI32: InternalDrawTextExA, unimplemented stub!\n"));
|
|---|
| 70 | return 0;
|
|---|
| 71 | }
|
|---|
| 72 | //******************************************************************************
|
|---|
| 73 | //******************************************************************************
|
|---|
| 74 | INT WIN32API InternalDrawTextExW(HDC hdc,LPWSTR lpchText,INT cchText,LPRECT lprc,UINT dwDTFormat,LPDRAWTEXTPARAMS lpDTParams)
|
|---|
| 75 | {
|
|---|
| 76 | char *astring = UnicodeToAsciiStringN((LPWSTR)lpchText,cchText);
|
|---|
| 77 | INT rc;
|
|---|
| 78 |
|
|---|
| 79 | rc = InternalDrawTextExA(hdc,astring,cchText,lprc,dwDTFormat,lpDTParams);
|
|---|
| 80 | FreeAsciiString(astring);
|
|---|
| 81 |
|
|---|
| 82 | return(rc);
|
|---|
| 83 | }
|
|---|
| 84 | //******************************************************************************
|
|---|
| 85 | // CB: USER32 function, but here is the better place
|
|---|
| 86 | //******************************************************************************
|
|---|
| 87 | LONG WIN32API InternalTabbedTextOutA( HDC hdc, int x, int y, LPCSTR lpString, int nCount, int nTabPositions, LPINT lpnTabStopPositions, int nTabOrigin)
|
|---|
| 88 | {
|
|---|
| 89 | //CB: todo
|
|---|
| 90 | dprintf(("GDI32: InternalTabbedTextOutA, unimplemented stub!\n"));
|
|---|
| 91 | return 0;
|
|---|
| 92 | }
|
|---|
| 93 | //******************************************************************************
|
|---|
| 94 | //******************************************************************************
|
|---|
| 95 | LONG WIN32API InternalTabbedTextOutW( HDC hdc, int x, int y, LPCWSTR lpString, int nCount, int nTabPositions, LPINT lpnTabStopPositions, int nTabOrigin)
|
|---|
| 96 | {
|
|---|
| 97 | char *astring = UnicodeToAsciiStringN((LPWSTR)lpString,nCount);
|
|---|
| 98 | LONG rc;
|
|---|
| 99 |
|
|---|
| 100 | rc = InternalTabbedTextOutA(hdc,x,y,astring,nCount,nTabPositions,lpnTabStopPositions,nTabOrigin);
|
|---|
| 101 | FreeAsciiString(astring);
|
|---|
| 102 |
|
|---|
| 103 | return(rc);
|
|---|
| 104 | }
|
|---|
| 105 | //******************************************************************************
|
|---|
| 106 | // CB: USER32 function, but here is the better place
|
|---|
| 107 | //******************************************************************************
|
|---|
| 108 | DWORD WIN32API InternalGetTabbedTextExtentA( HDC hDC, LPCSTR lpString, int nCount, int nTabPositions, LPINT lpnTabStopPositions)
|
|---|
| 109 | {
|
|---|
| 110 | //CB: todo
|
|---|
| 111 | dprintf(("GDI32: InternalGetTabbedTexExtentA, unimplemented stub!\n"));
|
|---|
| 112 | return 0;
|
|---|
| 113 | }
|
|---|
| 114 | //******************************************************************************
|
|---|
| 115 | //******************************************************************************
|
|---|
| 116 | DWORD WIN32API InternalGetTabbedTextExtentW( HDC hDC, LPCWSTR lpString, int nCount, int nTabPositions, LPINT lpnTabStopPositions)
|
|---|
| 117 | {
|
|---|
| 118 | char *astring = UnicodeToAsciiStringN((LPWSTR)lpString,nCount);
|
|---|
| 119 | DWORD rc;
|
|---|
| 120 |
|
|---|
| 121 | rc = InternalGetTabbedTextExtentA(hDC,astring,nCount,nTabPositions,lpnTabStopPositions);
|
|---|
| 122 | FreeAsciiString(astring);
|
|---|
| 123 |
|
|---|
| 124 | return(rc);
|
|---|
| 125 | }
|
|---|
| 126 | //******************************************************************************
|
|---|
| 127 | // todo: metafile support
|
|---|
| 128 | //******************************************************************************
|
|---|
| 129 | BOOL InternalTextOutA(HDC hdc,int X,int Y,UINT fuOptions,CONST RECT *lprc,LPCSTR lpszString,INT cbCount,CONST INT *lpDx,BOOL IsExtTextOut)
|
|---|
| 130 | {
|
|---|
| 131 | PVOID pHps = OSLibGpiQueryDCData(hdc);
|
|---|
| 132 | ULONG flOptions = 0;
|
|---|
| 133 | RECTLOS2 pmRect;
|
|---|
| 134 | POINTLOS2 ptl;
|
|---|
| 135 | LONG hits;
|
|---|
| 136 |
|
|---|
| 137 | if (!pHps || cbCount < 0 || (lpszString == NULL && cbCount != 0))
|
|---|
| 138 | {
|
|---|
| 139 | SetLastError(ERROR_INVALID_HANDLE);
|
|---|
| 140 | return FALSE;
|
|---|
| 141 | }
|
|---|
| 142 |
|
|---|
| 143 | if (cbCount > 512)
|
|---|
| 144 | {
|
|---|
| 145 | SetLastError(ERROR_INVALID_PARAMETER);
|
|---|
| 146 | return FALSE;
|
|---|
| 147 | }
|
|---|
| 148 | if (fuOptions & ~((UINT)(ETO_CLIPPED | ETO_OPAQUE)))
|
|---|
| 149 | {
|
|---|
| 150 | //ETO_GLYPH_INDEX, ETO_RTLLEADING, ETO_NUMERICSLOCAL, ETO_NUMERICSLATIN, ETO_IGNORELANGUAGE, ETO_PDY are ignored
|
|---|
| 151 | return TRUE;
|
|---|
| 152 | }
|
|---|
| 153 |
|
|---|
| 154 | //CB: add metafile info
|
|---|
| 155 |
|
|---|
| 156 | if (lprc)
|
|---|
| 157 | {
|
|---|
| 158 | if (fuOptions)
|
|---|
| 159 | {
|
|---|
| 160 | MapWin32ToOS2Rect(*lprc,pmRect);
|
|---|
| 161 | if (excludeBottomRightPoint(pHps,(PPOINTLOS2)&pmRect) == 0)
|
|---|
| 162 | {
|
|---|
| 163 | return TRUE;
|
|---|
| 164 | }
|
|---|
| 165 |
|
|---|
| 166 | if (fuOptions & ETO_CLIPPED) flOptions |= CHSOS_CLIP;
|
|---|
| 167 | if (fuOptions & ETO_OPAQUE) flOptions |= CHSOS_OPAQUE;
|
|---|
| 168 | }
|
|---|
| 169 | } else
|
|---|
| 170 | {
|
|---|
| 171 | if (fuOptions)
|
|---|
| 172 | {
|
|---|
| 173 | SetLastError(ERROR_INVALID_HANDLE);
|
|---|
| 174 | return FALSE;
|
|---|
| 175 | }
|
|---|
| 176 | }
|
|---|
| 177 |
|
|---|
| 178 | if (cbCount == 0)
|
|---|
| 179 | {
|
|---|
| 180 | if (fuOptions & ETO_OPAQUE)
|
|---|
| 181 | {
|
|---|
| 182 | lpszString = " ";
|
|---|
| 183 | cbCount = 1;
|
|---|
| 184 | flOptions |= CHSOS_CLIP;
|
|---|
| 185 | } else return TRUE;
|
|---|
| 186 | }
|
|---|
| 187 | if (lpDx)
|
|---|
| 188 | flOptions |= CHSOS_VECTOR;
|
|---|
| 189 |
|
|---|
| 190 | if (getAlignUpdateCP(pHps) == FALSE)
|
|---|
| 191 | {
|
|---|
| 192 | ptl.x = X;
|
|---|
| 193 | ptl.y = Y;
|
|---|
| 194 |
|
|---|
| 195 | flOptions |= CHSOS_LEAVEPOS;
|
|---|
| 196 | } else OSLibGpiQueryCurrentPosition(pHps,&ptl);
|
|---|
| 197 |
|
|---|
| 198 | UINT align = GetTextAlign(hdc);
|
|---|
| 199 | LONG pmHAlign,pmVAlign;
|
|---|
| 200 |
|
|---|
| 201 | //CB: TA_RIGHT not supported, only TA_CENTER and TA_LEFT
|
|---|
| 202 | if ((align & 0x6) == TA_RIGHT)
|
|---|
| 203 | {
|
|---|
| 204 | PPOINTLOS2 pts = (PPOINTLOS2)malloc((cbCount+1)*sizeof(POINTLOS2));
|
|---|
| 205 |
|
|---|
| 206 | OSLibGpiQueryCharStringPosAt(pHps,&ptl,flOptions,cbCount,lpszString,lpDx,pts);
|
|---|
| 207 | ptl.x -= pts[cbCount].x-pts[0].x;
|
|---|
| 208 | free(pts);
|
|---|
| 209 | }
|
|---|
| 210 |
|
|---|
| 211 | if (lprc && (align & 0x18) == TA_BASELINE)
|
|---|
| 212 | {
|
|---|
| 213 | //CB: if TA_BASELINE is set, GPI doesn't fill rect
|
|---|
| 214 | // TA_BOTTOM fills rect
|
|---|
| 215 | OSLibGpiQueryTextAlignment(pHps,&pmHAlign,&pmVAlign);
|
|---|
| 216 | OSLibGpiSetTextAlignment(pHps,pmHAlign,(pmVAlign & ~TAOS_BASE) | TAOS_BOTTOM);
|
|---|
| 217 | }
|
|---|
| 218 |
|
|---|
| 219 | ptl.y += getWorldYDeltaFor1Pixel(pHps);
|
|---|
| 220 |
|
|---|
| 221 | hits = OSLibGpiCharStringPosAt(pHps,&ptl,&pmRect,flOptions,cbCount,lpszString,lpDx);
|
|---|
| 222 |
|
|---|
| 223 | if (lprc && (align & 0x18) == TA_BASELINE)
|
|---|
| 224 | OSLibGpiSetTextAlignment(pHps,pmHAlign,pmVAlign);
|
|---|
| 225 |
|
|---|
| 226 | if (hits == GPIOS_ERROR)
|
|---|
| 227 | {
|
|---|
| 228 | return FALSE;
|
|---|
| 229 | }
|
|---|
| 230 | if (getAlignUpdateCP(pHps))
|
|---|
| 231 | {
|
|---|
| 232 | OSLibGpiQueryCurrentPosition(pHps,&ptl);
|
|---|
| 233 | ptl.y -= getWorldYDeltaFor1Pixel(pHps);
|
|---|
| 234 | OSLibGpiSetCurrentPosition(pHps,&ptl);
|
|---|
| 235 | }
|
|---|
| 236 |
|
|---|
| 237 | return TRUE;
|
|---|
| 238 | }
|
|---|
| 239 | //******************************************************************************
|
|---|
| 240 | //******************************************************************************
|
|---|
| 241 | BOOL InternalTextOutW(HDC hdc,int X,int Y,UINT fuOptions,CONST RECT *lprc,LPCWSTR lpszString,INT cbCount,CONST INT *lpDx,BOOL IsExtTextOut)
|
|---|
| 242 | {
|
|---|
| 243 | char *astring = UnicodeToAsciiStringN((LPWSTR)lpszString,cbCount);
|
|---|
| 244 | BOOL rc;
|
|---|
| 245 |
|
|---|
| 246 | rc = InternalTextOutA(hdc,X,Y,fuOptions,lprc,(LPCSTR)astring,cbCount,lpDx,IsExtTextOut);
|
|---|
| 247 | FreeAsciiString(astring);
|
|---|
| 248 |
|
|---|
| 249 | return(rc);
|
|---|
| 250 | }
|
|---|
| 251 | //******************************************************************************
|
|---|
| 252 | //******************************************************************************
|
|---|
| 253 | BOOL WIN32API ExtTextOutA(HDC hdc,int X,int Y,UINT fuOptions,CONST RECT *lprc,LPCSTR lpszString,UINT cbCount,CONST INT *lpDx)
|
|---|
| 254 | {
|
|---|
| 255 | dprintf(("GDI32: ExtTextOutA\n"));
|
|---|
| 256 |
|
|---|
| 257 | return InternalTextOutA(hdc,X,Y,fuOptions,lprc,lpszString,cbCount,lpDx,TRUE);
|
|---|
| 258 | }
|
|---|
| 259 | //******************************************************************************
|
|---|
| 260 | //******************************************************************************
|
|---|
| 261 | BOOL WIN32API ExtTextOutW(HDC hdc,int X,int Y,UINT fuOptions,CONST RECT *lprc,LPCWSTR lpszString,UINT cbCount,CONST int *lpDx)
|
|---|
| 262 | {
|
|---|
| 263 | dprintf(("GDI32: ExtTextOutW\n"));
|
|---|
| 264 |
|
|---|
| 265 | return InternalTextOutW(hdc,X,Y,fuOptions,lprc,lpszString,cbCount,lpDx,TRUE);
|
|---|
| 266 | }
|
|---|
| 267 | //******************************************************************************
|
|---|
| 268 | //******************************************************************************
|
|---|
| 269 | BOOL WIN32API TextOutA(HDC hdc,int nXStart,int nYStart,LPCSTR lpszString,int cbString)
|
|---|
| 270 | {
|
|---|
| 271 | dprintf(("GDI32: TextOutA"));
|
|---|
| 272 |
|
|---|
| 273 | return InternalTextOutA(hdc,nXStart,nYStart,0,NULL,lpszString,cbString,NULL,FALSE);
|
|---|
| 274 | }
|
|---|
| 275 | //******************************************************************************
|
|---|
| 276 | //******************************************************************************
|
|---|
| 277 | BOOL WIN32API TextOutW(HDC hdc,int nXStart,int nYStart,LPCWSTR lpszString,int cbString)
|
|---|
| 278 | {
|
|---|
| 279 | dprintf(("GDI32: TextOutW"));
|
|---|
| 280 |
|
|---|
| 281 | return InternalTextOutW(hdc,nXStart,nYStart,0,NULL,lpszString,cbString,NULL,FALSE);
|
|---|
| 282 | }
|
|---|
| 283 | //******************************************************************************
|
|---|
| 284 | //******************************************************************************
|
|---|