Changeset 10400 for trunk/src/gdi32/text.cpp
- Timestamp:
- Jan 15, 2004, 12:18:58 PM (22 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/gdi32/text.cpp
r10392 r10400 1 /* $Id: text.cpp,v 1.4 2 2004-01-14 16:53:25sandervl Exp $ */1 /* $Id: text.cpp,v 1.43 2004-01-15 11:18:58 sandervl Exp $ */ 2 2 3 3 /* … … 543 543 return GetTextExtentPointW(hdc, lpsz, cbString, lpSize); 544 544 } 545 546 typedef BOOL ( WIN32API *PFN_GETTEXTEXTENTPOINT32 )( HDC, PVOID, INT, LPSIZE ); 547 548 BOOL InternalGetTextExtentExPointAW(HDC hdc, 549 PVOID str, 550 INT count, 551 INT maxExt, 552 LPINT lpnFit, 553 LPINT alpDx, 554 LPSIZE size, 555 BOOL fUnicode) 556 { 557 int i, nFit; 558 SIZE tSize; 559 BOOL ret = FALSE; 560 561 PFN_GETTEXTEXTENTPOINT32 pfnGetTextExtentPoint32; 562 563 if( fUnicode ) 564 pfnGetTextExtentPoint32 = ( PFN_GETTEXTEXTENTPOINT32 )GetTextExtentPoint32W; 565 else 566 pfnGetTextExtentPoint32 = ( PFN_GETTEXTEXTENTPOINT32 )GetTextExtentPoint32A; 567 568 size->cx = size->cy = nFit = i = 0; 569 570 if( lpnFit || alpDx ) 571 { 572 for( i = 1; i <= count; i++ ) 573 { 574 if( !pfnGetTextExtentPoint32( hdc, str, i, &tSize )) goto done; 575 576 if( lpnFit && ( maxExt < tSize.cx )) 577 break; 578 579 if( alpDx ) 580 alpDx[ nFit ] = tSize.cx; 581 582 nFit++; 583 } 584 } 585 586 if(( count > 0 ) && ( i >= count )) 587 { 588 size->cx = tSize.cx; 589 size->cy = tSize.cy; // The height of a font is constant. 590 } 591 else if( !pfnGetTextExtentPoint32( hdc, str, count, size )) goto done; 592 593 if(lpnFit) *lpnFit = nFit; 594 ret = TRUE; 595 596 dprintf(("returning %d %ld x %ld\n",nFit,size->cx,size->cy)); 597 598 done: 599 return ret; 600 } 601 545 602 //****************************************************************************** 546 603 //****************************************************************************** … … 553 610 LPSIZE size) 554 611 { 555 BOOL ret; 556 INT wlen; 557 LPWSTR p; 558 INT nFit; 559 TEXTMETRICA tmA; 560 CHAR brokenDBCS = 0; 561 562 if( IsDBCSEnv()) 563 { 564 brokenDBCS = getBrokenDBCS( str, count ); 565 566 GetTextMetricsA( hdc, &tmA ); 567 } 568 569 if( brokenDBCS ) 570 count--; 571 572 p = FONT_mbtowc( hdc, str, count, &wlen, NULL); 573 ret = GetTextExtentExPointW( hdc, p, wlen, maxExt, &nFit, alpDx, size); 574 nFit = WideCharToMultiByte(CP_ACP,0,p,nFit,NULL,0,NULL,NULL); 575 if( IsDBCSEnv() && alpDx ) // index of alpDx between ansi and wide may not match in DBCS !!! 576 { 577 LPINT alpDxNew = ( LPINT )HeapAlloc( GetProcessHeap(), 0, sizeof( alpDx[ 0 ] ) * ( nFit + 1 )); 578 INT prevDx; 579 int i, j; 580 581 for( i = j = 0; i < nFit; i++, j++ ) 582 { 583 if( IsDBCSLeadByte( str[ i ])) 584 { 585 prevDx = ( i > 0 ) ? alpDxNew[ i - 1 ] : 0; 586 alpDxNew[ i++ ] = prevDx + tmA.tmAveCharWidth; 587 if( i >= nFit ) 588 break; 589 } 590 alpDxNew[ i ] = alpDx[ j ]; 591 } 592 593 if(( nFit < count ) && IsDBCSLeadByte( str[ nFit ])) 594 { 595 prevDx = ( nFit > 0 ) ? alpDxNew[ nFit - 1 ] : 0; 596 if( maxExt >= prevDx + tmA.tmAveCharWidth ) 597 alpDxNew[ nFit++ ] = prevDx + tmA.tmAveCharWidth; 598 } 599 600 memcpy( alpDx, alpDxNew, sizeof( alpDx[ 0 ] ) * nFit ); 601 602 HeapFree( GetProcessHeap(), 0, alpDxNew ); 603 } 604 605 // for broken DBCS. correct for FIXED WIDTH, not approx. for VARIABLE WIDTH 606 if( brokenDBCS ) 607 { 608 size->cx += tmA.tmAveCharWidth; 609 if( count == 0 ) 610 size->cy = tmA.tmHeight; 611 612 if(( maxExt > size->cx ) && ( nFit <= count )) // decreaed count by 1 above 613 { 614 if( alpDx ) 615 alpDx[ nFit ] = size->cx; 616 617 nFit++; 618 } 619 } 620 621 if (lpnFit) *lpnFit = nFit; 622 623 HeapFree( GetProcessHeap(), 0, p ); 624 return ret; 612 return InternalGetTextExtentExPointAW( hdc, ( PVOID )str, count, maxExt, lpnFit, alpDx, size, FALSE ); 625 613 } 626 614 //****************************************************************************** … … 634 622 LPSIZE size) 635 623 { 636 int i, nFit, extent; 637 SIZE tSize; 638 BOOL ret = FALSE; 639 640 size->cx = size->cy = nFit = extent = 0; 641 642 for( i = 1; i <= count; i++ ) 643 { 644 if( !GetTextExtentPoint32W( hdc, str, i, &tSize )) goto done; 645 646 if( maxExt < tSize.cx ) 647 break; 648 649 if( alpDx ) 650 alpDx[ nFit ] = tSize.cx; 651 652 nFit++; 653 } 654 655 if( i >= count ) 656 size->cx = tSize.cx; 657 else if( !GetTextExtentPoint32W( hdc, str, count, size )) goto done; 658 659 size->cy = tSize.cy; // The height of a font is constant. 660 661 if(lpnFit) *lpnFit = nFit; 662 ret = TRUE; 663 664 dprintf(("returning %d %ld x %ld\n",nFit,size->cx,size->cy)); 665 666 done: 667 return ret; 624 return InternalGetTextExtentExPointAW( hdc, ( PVOID )str, count, maxExt, lpnFit, alpDx, size, TRUE ); 668 625 } 669 626 //******************************************************************************
Note:
See TracChangeset
for help on using the changeset viewer.