Changeset 10349 for trunk/src/gdi32/text.cpp
- Timestamp:
- Dec 1, 2003, 2:27:39 PM (22 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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.