- Timestamp:
- Dec 1, 2003, 2:27:39 PM (22 years ago)
- Location:
- trunk/src/gdi32
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/gdi32/font.cpp
r10230 r10349 1 /* $Id: font.cpp,v 1.3 1 2003-08-13 09:11:42sandervl Exp $ */1 /* $Id: font.cpp,v 1.32 2003-12-01 13:27:37 sandervl Exp $ */ 2 2 3 3 /* … … 145 145 lpstrFaceTemp, 146 146 LF_FACESIZE); 147 } 148 /*********************************************************************** 149 * FONT_mbtowc 150 * 151 * Returns a '\0' terminated Unicode translation of str using the 152 * charset of the currently selected font in hdc. If count is -1 then 153 * str is assumed to be '\0' terminated, otherwise it contains the 154 * number of bytes to convert. If plenW is non-NULL, on return it 155 * will point to the number of WCHARs (excluding the '\0') that have 156 * been written. If pCP is non-NULL, on return it will point to the 157 * codepage used in the conversion (NB, this may be CP_SYMBOL so watch 158 * out). The caller should free the returned LPWSTR from the process 159 * heap itself. 160 */ 161 LPWSTR FONT_mbtowc(HDC hdc, LPCSTR str, INT count, INT *plenW, UINT *pCP) 162 { 163 UINT cp = CP_ACP; 164 INT lenW, i; 165 LPWSTR strW; 166 CHARSETINFO csi; 167 int charset = GetTextCharset(hdc); 168 169 /* Hmm, nicely designed api this one! */ 170 if(TranslateCharsetInfo((DWORD*)charset, &csi, TCI_SRCCHARSET)) 171 cp = csi.ciACP; 172 else { 173 switch(charset) { 174 case OEM_CHARSET: 175 cp = GetOEMCP(); 176 break; 177 case DEFAULT_CHARSET: 178 cp = GetACP(); 179 break; 180 181 case VISCII_CHARSET: 182 case TCVN_CHARSET: 183 case KOI8_CHARSET: 184 case ISO3_CHARSET: 185 case ISO4_CHARSET: 186 /* FIXME: These have no place here, but because x11drv 187 enumerates fonts with these (made up) charsets some apps 188 might use them and then the FIXME below would become 189 annoying. Now we could pick the intended codepage for 190 each of these, but since it's broken anyway we'll just 191 use CP_ACP and hope it'll go away... 192 */ 193 cp = CP_ACP; 194 break; 195 196 197 default: 198 dprintf(("Can't find codepage for charset %d\n", charset)); 199 break; 200 } 201 } 202 203 dprintf(("cp == %d\n", cp)); 204 205 if(count == -1) count = strlen(str); 206 if(cp != CP_SYMBOL) { 207 lenW = MultiByteToWideChar(cp, 0, str, count, NULL, 0); 208 strW = (WCHAR*)HeapAlloc(GetProcessHeap(), 0, (lenW + 1) * sizeof(WCHAR)); 209 MultiByteToWideChar(cp, 0, str, count, strW, lenW); 210 } else { 211 lenW = count; 212 strW = (WCHAR*)HeapAlloc(GetProcessHeap(), 0, (lenW + 1) * sizeof(WCHAR)); 213 for(i = 0; i < count; i++) strW[i] = (BYTE)str[i]; 214 } 215 strW[lenW] = '\0'; 216 dprintf(("mapped %s -> %ls\n", str, strW)); 217 if(plenW) *plenW = lenW; 218 if(pCP) *pCP = cp; 219 return strW; 147 220 } 148 221 //****************************************************************************** -
trunk/src/gdi32/font.h
r7330 r10349 7 7 BOOL WIN32API IsSystemFont(HFONT hFont); 8 8 9 LPWSTR FONT_mbtowc(HDC hdc, LPCSTR str, INT count, INT *plenW, UINT *pCP); 10 9 11 #endif //__FONT_H__ -
trunk/src/gdi32/gdi32.cpp
r10322 r10349 1 /* $Id: gdi32.cpp,v 1. 89 2003-11-14 17:31:47sandervl Exp $ */1 /* $Id: gdi32.cpp,v 1.90 2003-12-01 13:27:38 sandervl Exp $ */ 2 2 3 3 /* … … 1224 1224 //****************************************************************************** 1225 1225 1226 1227 /* Office 97 stubs - KSO Thu 21.05.1998*/1228 //******************************************************************************1229 BOOL WIN32API GetTextExtentExPointA(/*KSO Thu 21.05.1998*/1230 HDC hdc,1231 LPCSTR str,1232 int count,1233 int maxExt,1234 LPINT lpnFit,1235 LPINT alpDx,1236 LPSIZE size)1237 {1238 int index, nFit, extent;1239 SIZE tSize;1240 1241 dprintf(("GDI32: GetTextExtendExPointA\n"));1242 1243 size->cx = size->cy = nFit = extent = 0;1244 for(index = 0; index < count; index++)1245 {1246 if(!O32_GetTextExtentPoint( hdc, str, 1, &tSize )) return FALSE;1247 if( extent+tSize.cx < maxExt )1248 {1249 extent+=tSize.cx;1250 nFit++;1251 str++;1252 if( alpDx )1253 alpDx[index] = extent;1254 if( tSize.cy > size->cy ) size->cy = tSize.cy;1255 }1256 else break;1257 }1258 size->cx = extent;1259 1260 if (lpnFit != NULL) // check if result is desired1261 *lpnFit = nFit;1262 1263 dprintf(("GDI32: GetTextExtendExPointA(%08x '%.*s' %d) returning %d %d %d\n",1264 hdc,count,str,maxExt,nFit, size->cx,size->cy));1265 return TRUE;1266 }1267 //******************************************************************************1268 //******************************************************************************1269 BOOL WIN32API GetTextExtentExPointW( /*KSO Thu 21.05.1998*/1270 HDC arg1,1271 LPCWSTR arg2,1272 int arg3,1273 int arg4,1274 LPINT arg5,1275 LPINT arg6,1276 LPSIZE arg71277 )1278 {1279 char *astring = UnicodeToAsciiString((LPWSTR)arg2);1280 BOOL rc;1281 1282 dprintf(("GDI32: GetTextExtendExPointW\n"));1283 rc = GetTextExtentExPointA(arg1, astring, arg3, arg4, arg5, arg6, arg7);1284 FreeAsciiString(astring);1285 return rc;1286 }1287 //******************************************************************************1288 1289 1290 1226 /***************************************************************************** 1291 1227 * Name : BOOL CancelDC -
trunk/src/gdi32/oslibgpi.cpp
r10174 r10349 1 /* $Id: oslibgpi.cpp,v 1.1 4 2003-07-16 15:47:37sandervl Exp $ */1 /* $Id: oslibgpi.cpp,v 1.15 2003-12-01 13:27:39 sandervl Exp $ */ 2 2 3 3 /* … … 257 257 ULONG cy; 258 258 259 //ignore underhang (just like GetTextExtentPoint does in Windows) 260 if (box[TXTBOX_BOTTOMLEFT].x < 0) { 261 dprintf(("WARNING: Ignoring underhang!!")); 262 box[TXTBOX_BOTTOMLEFT].x = 0; 263 } 264 259 265 if (box[TXTBOX_BOTTOMLEFT].y == box[TXTBOX_BOTTOMRIGHT].y) 260 266 { 261 267 point->y = labs (box[TXTBOX_BOTTOMLEFT].y-box[TXTBOX_TOPLEFT].y) + 1; 262 point->x = labs (box[TXTBOX_BOTTOMRIGHT].x-box[TXTBOX_BOTTOMLEFT].x) + 1; 268 point->x = labs (box[TXTBOX_CONCAT].x - box[TXTBOX_BOTTOMLEFT].x); 269 263 270 if (box[TXTBOX_BOTTOMLEFT].x != box[TXTBOX_TOPLEFT].x) 264 271 { -
trunk/src/gdi32/text.cpp
r10163 r10349 1 /* $Id: text.cpp,v 1.3 4 2003-07-14 13:43:15sandervl Exp $ */1 /* $Id: text.cpp,v 1.35 2003-12-01 13:27:39 sandervl Exp $ */ 2 2 3 3 /* … … 21 21 #include <dcdata.h> 22 22 #include <unicode.h> 23 #include "font.h" 23 24 24 25 #define DBG_LOCALLOG DBG_text … … 386 387 LPSIZE lpsSize) 387 388 { 388 #if 1 389 dprintf(("GDI32: GetTextExtentPointA %x %.*s %d", hdc, cbString, lpsz, cbString)); 390 391 if(lpsz == NULL || cbString < 0 || lpsSize == NULL) 392 { 393 dprintf(("!WARNING!: GDI32: GetTextExtentPointA invalid parameter!")); 394 SetLastError(ERROR_INVALID_PARAMETER); 395 return FALSE; 396 } 397 398 lpsSize->cx = 0; 399 lpsSize->cy = 0; 400 401 // Verified with NT4, SP6 402 if(cbString == 0) 403 { 404 dprintf(("GDI32: GetTextExtentPointA cbString == 0")); 405 SetLastError(ERROR_SUCCESS); 406 return TRUE; 407 } 408 409 //SvL: This works better than the code below. Can been seen clearly 410 // in the Settings dialog box of VirtualPC. Strings are clipped. 411 // (e.g.: Hard Disk 1 -> Hard Disk) 412 BOOL rc = O32_GetTextExtentPoint(hdc, lpsz, cbString, lpsSize); 413 if(rc) { 414 dprintf(("GDI32: GetTextExtentPointA returned (%d,%d)", lpsSize->cx, lpsSize->cy)); 415 SetLastError(ERROR_SUCCESS); 416 return TRUE; 417 } 418 return FALSE; 419 #else 389 BOOL ret = FALSE; 390 INT wlen; 391 LPWSTR p = FONT_mbtowc(hdc, lpsz, cbString, &wlen, NULL); 392 if (p) { 393 ret = GetTextExtentPointW( hdc, p, wlen, lpsSize ); 394 HeapFree( GetProcessHeap(), 0, p ); 395 } 396 else DebugInt3(); 397 return ret; 398 } 399 //****************************************************************************** 400 //****************************************************************************** 401 BOOL WIN32API GetTextExtentPointW(HDC hdc, 402 LPCWSTR lpString, 403 int cbString, 404 PSIZE lpSize) 405 { 420 406 BOOL rc; 421 407 POINTLOS2 pts[TXTBOXOS_COUNT]; … … 423 409 pDCData pHps = (pDCData)OSLibGpiQueryDCData((HPS)hdc); 424 410 425 dprintf(("GDI32: GetTextExtentPoint A %s\n", lpsz));411 dprintf(("GDI32: GetTextExtentPointW %ls", lpString)); 426 412 if(pHps == NULL) 427 413 { … … 430 416 } 431 417 432 if(lp sz == NULL || cbString < 0 || lpsSize == NULL)418 if(lpString == NULL || cbString < 0 || lpSize == NULL) 433 419 { 434 420 SetLastError(ERROR_INVALID_PARAMETER); … … 436 422 } 437 423 438 lp sSize->cx = 0;439 lp sSize->cy = 0;424 lpSize->cx = 0; 425 lpSize->cy = 0; 440 426 441 427 // Verified with NT4, SP6 … … 451 437 452 438 dprintf(("WARNING: string longer than 512 chars; splitting up")); 453 lp sSize->cx = 0;454 lp sSize->cy = 0;439 lpSize->cx = 0; 440 lpSize->cy = 0; 455 441 while(cbString) { 456 442 cbStringNew = min(500, cbString); 457 rc = GetTextExtentPoint A(hdc, lpsz, cbStringNew, &newSize);443 rc = GetTextExtentPointW(hdc, lpString, cbStringNew, &newSize); 458 444 if(rc == FALSE) { 459 445 return FALSE; 460 446 } 461 lp sSize->cx += newSize.cx;462 lp sSize->cy = max(newSize.cy, lpsSize->cy);463 lp sz+= cbStringNew;447 lpSize->cx += newSize.cx; 448 lpSize->cy = max(newSize.cy, lpSize->cy); 449 lpString += cbStringNew; 464 450 cbString -= cbStringNew; 465 451 } … … 467 453 } 468 454 469 rc = OSLibGpiQueryTextBox(pHps, cbString, lpsz, TXTBOXOS_COUNT, pts); 455 int len; 456 LPSTR astring; 457 458 len = WideCharToMultiByte( CP_ACP, 0, lpString, cbString, 0, 0, NULL, NULL ); 459 astring = (char *)malloc( len + 1 ); 460 lstrcpynWtoA(astring, lpString, len + 1 ); 461 462 BOOL ret = OSLibGpiQueryTextBox(pHps, cbString, astring, TXTBOXOS_COUNT, pts); 463 free(astring); 464 470 465 if(rc == FALSE) 471 466 { … … 474 469 } 475 470 calcDimensions(pts, &widthHeight); 476 lp sSize->cx = widthHeight.x;477 lp sSize->cy = widthHeight.y;471 lpSize->cx = widthHeight.x; 472 lpSize->cy = widthHeight.y; 478 473 479 474 if(pHps && pHps->isPrinter && pHps->hdc) … … 482 477 483 478 if (OSLibDevQueryCaps(pHps, OSLIB_CAPS_HORIZONTAL_RESOLUTION, 2, &alArray[0])) 484 lp sSize->cx = lpsSize->cx * alArray[0] / alArray[1];485 } 486 487 dprintf(("GDI32: GetTextExtentPoint A %x %s %d returned %d (%d,%d)", hdc, lpsz, cbString, rc, lpsSize->cx, lpsSize->cy));479 lpSize->cx = lpSize->cx * alArray[0] / alArray[1]; 480 } 481 482 dprintf(("GDI32: GetTextExtentPointW %x %ls %d returned %d (%d,%d)", hdc, lpString, cbString, rc, lpSize->cx, lpSize->cy)); 488 483 SetLastError(ERROR_SUCCESS); 489 484 return TRUE; 490 #endif491 }492 //******************************************************************************493 //******************************************************************************494 BOOL WIN32API GetTextExtentPointW(HDC hdc,495 LPCWSTR lpString,496 int cbString,497 PSIZE lpSize)498 {499 char *astring;500 int len;501 BOOL rc;502 503 if(lpString == NULL || cbString < 0 || lpSize == NULL)504 {505 dprintf(("!WARNING!: GDI32: GetTextExtentPointW invalid parameter!"));506 SetLastError(ERROR_INVALID_PARAMETER);507 return FALSE;508 }509 510 lpSize->cx = 0;511 lpSize->cy = 0;512 513 // Verified with NT4, SP6514 if(cbString == 0)515 {516 dprintf(("GDI32: GetTextExtentPointW cbString == 0"));517 SetLastError(ERROR_SUCCESS);518 return TRUE;519 }520 521 dprintf(("GDI32: GetTextExtentPointW %x %.*ls %d %x", hdc, cbString, lpString, cbString, lpSize));522 523 len = WideCharToMultiByte( CP_ACP, 0, lpString, cbString, 0, 0, NULL, NULL );524 astring = (char *)malloc( len + 1 );525 UnicodeToAsciiN(lpString, astring, len + 1 );526 rc = GetTextExtentPointA(hdc, astring,527 len, lpSize);528 529 free(astring);530 return(rc);531 485 } 532 486 //****************************************************************************** … … 544 498 //****************************************************************************** 545 499 //****************************************************************************** 500 BOOL WIN32API GetTextExtentExPointA(HDC hdc, 501 LPCSTR str, 502 int count, 503 int maxExt, 504 LPINT lpnFit, 505 LPINT alpDx, 506 LPSIZE size) 507 { 508 BOOL ret; 509 INT wlen; 510 LPWSTR p = FONT_mbtowc( hdc, str, count, &wlen, NULL); 511 ret = GetTextExtentExPointW( hdc, p, wlen, maxExt, lpnFit, alpDx, size); 512 if (lpnFit) *lpnFit = WideCharToMultiByte(CP_ACP,0,p,*lpnFit,NULL,0,NULL,NULL); 513 HeapFree( GetProcessHeap(), 0, p ); 514 return ret; 515 } 516 //****************************************************************************** 517 //****************************************************************************** 518 BOOL WIN32API GetTextExtentExPointW(HDC hdc, 519 LPCWSTR str, 520 int count, 521 int maxExt, 522 LPINT lpnFit, 523 LPINT alpDx, 524 LPSIZE size) 525 { 526 int index, nFit, extent; 527 SIZE tSize; 528 BOOL ret = FALSE; 529 530 size->cx = size->cy = nFit = extent = 0; 531 for(index = 0; index < count; index++) 532 { 533 if(!GetTextExtentPoint32W( hdc, str, 1, &tSize )) goto done; 534 /* GetTextExtentPoint includes intercharacter spacing. */ 535 /* FIXME - justification needs doing yet. Remember that the base 536 * data will not be in logical coordinates. 537 */ 538 extent += tSize.cx; 539 if( !lpnFit || extent <= maxExt ) 540 /* It is allowed to be equal. */ 541 { 542 nFit++; 543 if( alpDx ) alpDx[index] = extent; 544 } 545 if( tSize.cy > size->cy ) size->cy = tSize.cy; 546 str++; 547 } 548 size->cx = extent; 549 if(lpnFit) *lpnFit = nFit; 550 ret = TRUE; 551 552 dprintf(("returning %d %ld x %ld\n",nFit,size->cx,size->cy)); 553 554 done: 555 return ret; 556 } 557 //****************************************************************************** 558 //******************************************************************************
Note:
See TracChangeset
for help on using the changeset viewer.