SHARE
TWEET

Untitled

a guest Nov 26th, 2019 94 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. sub CalcTextSize(szCaption as wstring, szFntName as zString, fntSz as integer, _
  2.                   fStyle as integer, byref x as integer, byref y as integer)
  3.    
  4.     dim as integer fw, fi
  5.     if (fstyle and FS_BOLD) then fw = FW_BOLD else fw = FW_NORMAL  
  6.     if (fstyle and FS_ITALIC) then fi = True else fi = False
  7.  
  8.     var hDC = GetDC(0)
  9.    
  10.     dim as integer fontPt = -MulDiv(fntSz, GetDeviceCaps(hDC, LOGPIXELSY), 72)
  11.     var hFont = CreateFont(fontPt,0,0,0,fw,fi,0,0,DEFAULT_CHARSET,0,0,_
  12.                            NONANTIALIASED_QUALITY,0,szFntName)  
  13.                        
  14.     SelectObject(hDC, hFont)
  15.        
  16.     static as TEXTMETRIC textMetrics
  17.     static as SIZE txtSize
  18.    
  19.     GetTextMetrics(hDC, @textMetrics)
  20.     GetTextExtentPoint32W(hDC, szCaption, len(szCaption),@txtSize)
  21.     dim as integer TXTSZ = txtSize.cx
  22.     dim as integer TXYY = txtSize.cy
  23.     if (fstyle and FS_ITALIC) then
  24.         if textMetrics.tmOverhang then
  25.             TXTSZ += textMetrics.tmOverhang
  26.         else
  27.             TXTSZ += 1+(fntSz/2)
  28.         end if
  29.         TXYY += 1+(fntSz/8)
  30.     end if
  31.    
  32.     if (fstyle and FS_ANTIALIAS) then
  33.         #if GAMMA>1 and GAMMA <= 2
  34.             TXTSZ += GAMMA*2
  35.         #endif
  36.     end if
  37.  
  38.     TXTSZ -= 1
  39.     TXYY -= 1
  40.    
  41.     DeleteObject(hFont)
  42.  
  43.     x = TXTSZ: y = TXYY
  44. end sub
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top