UIRender.cpp 84 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069
  1. #include "StdAfx.h"
  2. ///////////////////////////////////////////////////////////////////////////////////////
  3. DECLARE_HANDLE(HZIP); // An HZIP identifies a zip file that has been opened
  4. typedef DWORD ZRESULT;
  5. typedef struct
  6. {
  7. int index; // index of this file within the zip
  8. char name[MAX_PATH]; // filename within the zip
  9. DWORD attr; // attributes, as in GetFileAttributes.
  10. FILETIME atime,ctime,mtime;// access, create, modify filetimes
  11. long comp_size; // sizes of item, compressed and uncompressed. These
  12. long unc_size; // may be -1 if not yet known (e.g. being streamed in)
  13. } ZIPENTRY;
  14. typedef struct
  15. {
  16. int index; // index of this file within the zip
  17. TCHAR name[MAX_PATH]; // filename within the zip
  18. DWORD attr; // attributes, as in GetFileAttributes.
  19. FILETIME atime,ctime,mtime;// access, create, modify filetimes
  20. long comp_size; // sizes of item, compressed and uncompressed. These
  21. long unc_size; // may be -1 if not yet known (e.g. being streamed in)
  22. } ZIPENTRYW;
  23. #define OpenZip OpenZipU
  24. #define CloseZip(hz) CloseZipU(hz)
  25. extern HZIP OpenZipU(void *z,unsigned int len,DWORD flags);
  26. extern ZRESULT CloseZipU(HZIP hz);
  27. #ifdef _UNICODE
  28. #define ZIPENTRY ZIPENTRYW
  29. #define GetZipItem GetZipItemW
  30. #define FindZipItem FindZipItemW
  31. #else
  32. #define GetZipItem GetZipItemA
  33. #define FindZipItem FindZipItemA
  34. #endif
  35. extern ZRESULT GetZipItemA(HZIP hz, int index, ZIPENTRY *ze);
  36. extern ZRESULT GetZipItemW(HZIP hz, int index, ZIPENTRYW *ze);
  37. extern ZRESULT FindZipItemA(HZIP hz, const TCHAR *name, bool ic, int *index, ZIPENTRY *ze);
  38. extern ZRESULT FindZipItemW(HZIP hz, const TCHAR *name, bool ic, int *index, ZIPENTRYW *ze);
  39. extern ZRESULT UnzipItem(HZIP hz, int index, void *dst, unsigned int len, DWORD flags);
  40. ///////////////////////////////////////////////////////////////////////////////////////
  41. extern "C"
  42. {
  43. extern unsigned char *stbi_load_from_memory(unsigned char const *buffer, int len, int *x, int *y, \
  44. int *comp, int req_comp);
  45. extern void stbi_image_free(void *retval_from_stbi_load);
  46. };
  47. namespace DuiLib {
  48. static int g_iFontID = MAX_FONT_ID;
  49. /////////////////////////////////////////////////////////////////////////////////////
  50. //
  51. //
  52. CRenderClip::~CRenderClip()
  53. {
  54. ASSERT(::GetObjectType(hDC)==OBJ_DC || ::GetObjectType(hDC)==OBJ_MEMDC);
  55. ASSERT(::GetObjectType(hRgn)==OBJ_REGION);
  56. ASSERT(::GetObjectType(hOldRgn)==OBJ_REGION);
  57. ::SelectClipRgn(hDC, hOldRgn);
  58. ::DeleteObject(hOldRgn);
  59. ::DeleteObject(hRgn);
  60. }
  61. void CRenderClip::GenerateClip(HDC hDC, RECT rc, CRenderClip& clip)
  62. {
  63. RECT rcClip = { 0 };
  64. ::GetClipBox(hDC, &rcClip);
  65. clip.hOldRgn = ::CreateRectRgnIndirect(&rcClip);
  66. clip.hRgn = ::CreateRectRgnIndirect(&rc);
  67. ::ExtSelectClipRgn(hDC, clip.hRgn, RGN_AND);
  68. clip.hDC = hDC;
  69. clip.rcItem = rc;
  70. }
  71. void CRenderClip::GenerateRoundClip(HDC hDC, RECT rc, RECT rcItem, int width, int height, CRenderClip& clip)
  72. {
  73. RECT rcClip = { 0 };
  74. ::GetClipBox(hDC, &rcClip);
  75. clip.hOldRgn = ::CreateRectRgnIndirect(&rcClip);
  76. clip.hRgn = ::CreateRectRgnIndirect(&rc);
  77. HRGN hRgnItem = ::CreateRoundRectRgn(rcItem.left, rcItem.top, rcItem.right + 1, rcItem.bottom + 1, width, height);
  78. ::CombineRgn(clip.hRgn, clip.hRgn, hRgnItem, RGN_AND);
  79. ::ExtSelectClipRgn(hDC, clip.hRgn, RGN_AND);
  80. clip.hDC = hDC;
  81. clip.rcItem = rc;
  82. ::DeleteObject(hRgnItem);
  83. }
  84. void CRenderClip::UseOldClipBegin(HDC hDC, CRenderClip& clip)
  85. {
  86. ::SelectClipRgn(hDC, clip.hOldRgn);
  87. }
  88. void CRenderClip::UseOldClipEnd(HDC hDC, CRenderClip& clip)
  89. {
  90. ::SelectClipRgn(hDC, clip.hRgn);
  91. }
  92. /////////////////////////////////////////////////////////////////////////////////////
  93. //
  94. //
  95. static const float OneThird = 1.0f / 3;
  96. static void RGBtoHSL(DWORD ARGB, float* H, float* S, float* L) {
  97. const float
  98. R = (float)GetRValue(ARGB),
  99. G = (float)GetGValue(ARGB),
  100. B = (float)GetBValue(ARGB),
  101. nR = (R<0?0:(R>255?255:R))/255,
  102. nG = (G<0?0:(G>255?255:G))/255,
  103. nB = (B<0?0:(B>255?255:B))/255,
  104. m = min(min(nR,nG),nB),
  105. M = max(max(nR,nG),nB);
  106. *L = (m + M)/2;
  107. if (M==m) *H = *S = 0;
  108. else {
  109. const float
  110. f = (nR==m)?(nG-nB):((nG==m)?(nB-nR):(nR-nG)),
  111. i = (nR==m)?3.0f:((nG==m)?5.0f:1.0f);
  112. *H = (i-f/(M-m));
  113. if (*H>=6) *H-=6;
  114. *H*=60;
  115. *S = (2*(*L)<=1)?((M-m)/(M+m)):((M-m)/(2-M-m));
  116. }
  117. }
  118. static void HSLtoRGB(DWORD* ARGB, float H, float S, float L) {
  119. const float
  120. q = 2*L<1?L*(1+S):(L+S-L*S),
  121. p = 2*L-q,
  122. h = H/360,
  123. tr = h + OneThird,
  124. tg = h,
  125. tb = h - OneThird,
  126. ntr = tr<0?tr+1:(tr>1?tr-1:tr),
  127. ntg = tg<0?tg+1:(tg>1?tg-1:tg),
  128. ntb = tb<0?tb+1:(tb>1?tb-1:tb),
  129. B = 255*(6*ntr<1?p+(q-p)*6*ntr:(2*ntr<1?q:(3*ntr<2?p+(q-p)*6*(2.0f*OneThird-ntr):p))),
  130. G = 255*(6*ntg<1?p+(q-p)*6*ntg:(2*ntg<1?q:(3*ntg<2?p+(q-p)*6*(2.0f*OneThird-ntg):p))),
  131. R = 255*(6*ntb<1?p+(q-p)*6*ntb:(2*ntb<1?q:(3*ntb<2?p+(q-p)*6*(2.0f*OneThird-ntb):p)));
  132. *ARGB &= 0xFF000000;
  133. *ARGB |= RGB( (BYTE)(R<0?0:(R>255?255:R)), (BYTE)(G<0?0:(G>255?255:G)), (BYTE)(B<0?0:(B>255?255:B)) );
  134. }
  135. static COLORREF PixelAlpha(COLORREF clrSrc, double src_darken, COLORREF clrDest, double dest_darken)
  136. {
  137. return RGB (GetRValue (clrSrc) * src_darken + GetRValue (clrDest) * dest_darken,
  138. GetGValue (clrSrc) * src_darken + GetGValue (clrDest) * dest_darken,
  139. GetBValue (clrSrc) * src_darken + GetBValue (clrDest) * dest_darken);
  140. }
  141. static BOOL WINAPI AlphaBitBlt(HDC hDC, int nDestX, int nDestY, int dwWidth, int dwHeight, HDC hSrcDC, \
  142. int nSrcX, int nSrcY, int wSrc, int hSrc, BLENDFUNCTION ftn)
  143. {
  144. HDC hTempDC = ::CreateCompatibleDC(hDC);
  145. if (NULL == hTempDC)
  146. return FALSE;
  147. //Creates Source DIB
  148. LPBITMAPINFO lpbiSrc = NULL;
  149. // Fill in the BITMAPINFOHEADER
  150. lpbiSrc = (LPBITMAPINFO) new BYTE[sizeof(BITMAPINFOHEADER)];
  151. if (lpbiSrc == NULL)
  152. {
  153. ::DeleteDC(hTempDC);
  154. return FALSE;
  155. }
  156. lpbiSrc->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
  157. lpbiSrc->bmiHeader.biWidth = dwWidth;
  158. lpbiSrc->bmiHeader.biHeight = dwHeight;
  159. lpbiSrc->bmiHeader.biPlanes = 1;
  160. lpbiSrc->bmiHeader.biBitCount = 32;
  161. lpbiSrc->bmiHeader.biCompression = BI_RGB;
  162. lpbiSrc->bmiHeader.biSizeImage = dwWidth * dwHeight;
  163. lpbiSrc->bmiHeader.biXPelsPerMeter = 0;
  164. lpbiSrc->bmiHeader.biYPelsPerMeter = 0;
  165. lpbiSrc->bmiHeader.biClrUsed = 0;
  166. lpbiSrc->bmiHeader.biClrImportant = 0;
  167. COLORREF* pSrcBits = NULL;
  168. HBITMAP hSrcDib = CreateDIBSection (
  169. hSrcDC, lpbiSrc, DIB_RGB_COLORS, (void **)&pSrcBits,
  170. NULL, NULL);
  171. if ((NULL == hSrcDib) || (NULL == pSrcBits))
  172. {
  173. delete [] lpbiSrc;
  174. ::DeleteDC(hTempDC);
  175. return FALSE;
  176. }
  177. HBITMAP hOldTempBmp = (HBITMAP)::SelectObject (hTempDC, hSrcDib);
  178. ::StretchBlt(hTempDC, 0, 0, dwWidth, dwHeight, hSrcDC, nSrcX, nSrcY, wSrc, hSrc, SRCCOPY);
  179. ::SelectObject (hTempDC, hOldTempBmp);
  180. //Creates Destination DIB
  181. LPBITMAPINFO lpbiDest = NULL;
  182. // Fill in the BITMAPINFOHEADER
  183. lpbiDest = (LPBITMAPINFO) new BYTE[sizeof(BITMAPINFOHEADER)];
  184. if (lpbiDest == NULL)
  185. {
  186. delete [] lpbiSrc;
  187. ::DeleteObject(hSrcDib);
  188. ::DeleteDC(hTempDC);
  189. return FALSE;
  190. }
  191. lpbiDest->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
  192. lpbiDest->bmiHeader.biWidth = dwWidth;
  193. lpbiDest->bmiHeader.biHeight = dwHeight;
  194. lpbiDest->bmiHeader.biPlanes = 1;
  195. lpbiDest->bmiHeader.biBitCount = 32;
  196. lpbiDest->bmiHeader.biCompression = BI_RGB;
  197. lpbiDest->bmiHeader.biSizeImage = dwWidth * dwHeight;
  198. lpbiDest->bmiHeader.biXPelsPerMeter = 0;
  199. lpbiDest->bmiHeader.biYPelsPerMeter = 0;
  200. lpbiDest->bmiHeader.biClrUsed = 0;
  201. lpbiDest->bmiHeader.biClrImportant = 0;
  202. COLORREF* pDestBits = NULL;
  203. HBITMAP hDestDib = CreateDIBSection (
  204. hDC, lpbiDest, DIB_RGB_COLORS, (void **)&pDestBits,
  205. NULL, NULL);
  206. if ((NULL == hDestDib) || (NULL == pDestBits))
  207. {
  208. delete [] lpbiSrc;
  209. ::DeleteObject(hSrcDib);
  210. ::DeleteDC(hTempDC);
  211. return FALSE;
  212. }
  213. ::SelectObject (hTempDC, hDestDib);
  214. ::BitBlt (hTempDC, 0, 0, dwWidth, dwHeight, hDC, nDestX, nDestY, SRCCOPY);
  215. ::SelectObject (hTempDC, hOldTempBmp);
  216. double src_darken;
  217. BYTE nAlpha;
  218. for (int pixel = 0; pixel < dwWidth * dwHeight; pixel++, pSrcBits++, pDestBits++)
  219. {
  220. nAlpha = LOBYTE(*pSrcBits >> 24);
  221. src_darken = (double) (nAlpha * ftn.SourceConstantAlpha) / 255.0 / 255.0;
  222. if( src_darken < 0.0 ) src_darken = 0.0;
  223. *pDestBits = PixelAlpha(*pSrcBits, src_darken, *pDestBits, 1.0 - src_darken);
  224. } //for
  225. ::SelectObject (hTempDC, hDestDib);
  226. ::BitBlt (hDC, nDestX, nDestY, dwWidth, dwHeight, hTempDC, 0, 0, SRCCOPY);
  227. ::SelectObject (hTempDC, hOldTempBmp);
  228. delete [] lpbiDest;
  229. ::DeleteObject(hDestDib);
  230. delete [] lpbiSrc;
  231. ::DeleteObject(hSrcDib);
  232. ::DeleteDC(hTempDC);
  233. return TRUE;
  234. }
  235. /////////////////////////////////////////////////////////////////////////////////////
  236. //
  237. //
  238. DWORD CRenderEngine::AdjustColor(DWORD dwColor, short H, short S, short L)
  239. {
  240. if( H == 180 && S == 100 && L == 100 ) return dwColor;
  241. float fH, fS, fL;
  242. float S1 = S / 100.0f;
  243. float L1 = L / 100.0f;
  244. RGBtoHSL(dwColor, &fH, &fS, &fL);
  245. fH += (H - 180);
  246. fH = fH > 0 ? fH : fH + 360;
  247. fS *= S1;
  248. fL *= L1;
  249. HSLtoRGB(&dwColor, fH, fS, fL);
  250. return dwColor;
  251. }
  252. HBITMAP CRenderEngine::CreateARGB32Bitmap(HDC hDC, int cx, int cy, COLORREF** pBits)
  253. {
  254. LPBITMAPINFO lpbiSrc = NULL;
  255. lpbiSrc = (LPBITMAPINFO) new BYTE[sizeof(BITMAPINFOHEADER)];
  256. if (lpbiSrc == NULL) return NULL;
  257. lpbiSrc->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
  258. lpbiSrc->bmiHeader.biWidth = cx;
  259. lpbiSrc->bmiHeader.biHeight = cy;
  260. lpbiSrc->bmiHeader.biPlanes = 1;
  261. lpbiSrc->bmiHeader.biBitCount = 32;
  262. lpbiSrc->bmiHeader.biCompression = BI_RGB;
  263. lpbiSrc->bmiHeader.biSizeImage = cx * cy;
  264. lpbiSrc->bmiHeader.biXPelsPerMeter = 0;
  265. lpbiSrc->bmiHeader.biYPelsPerMeter = 0;
  266. lpbiSrc->bmiHeader.biClrUsed = 0;
  267. lpbiSrc->bmiHeader.biClrImportant = 0;
  268. HBITMAP hBitmap = CreateDIBSection (hDC, lpbiSrc, DIB_RGB_COLORS, (void **)pBits, NULL, NULL);
  269. delete [] lpbiSrc;
  270. return hBitmap;
  271. }
  272. void CRenderEngine::AdjustImage(bool bUseHSL, TImageInfo* imageInfo, short H, short S, short L)
  273. {
  274. if( imageInfo == NULL || imageInfo->bUseHSL == false || imageInfo->hBitmap == NULL ||
  275. imageInfo->pBits == NULL || imageInfo->pSrcBits == NULL )
  276. return;
  277. if( bUseHSL == false || (H == 180 && S == 100 && L == 100)) {
  278. ::CopyMemory(imageInfo->pBits, imageInfo->pSrcBits, imageInfo->nX * imageInfo->nY * 4);
  279. return;
  280. }
  281. float fH, fS, fL;
  282. float S1 = S / 100.0f;
  283. float L1 = L / 100.0f;
  284. for( int i = 0; i < imageInfo->nX * imageInfo->nY; i++ ) {
  285. RGBtoHSL(*(DWORD*)(imageInfo->pSrcBits + i*4), &fH, &fS, &fL);
  286. fH += (H - 180);
  287. fH = fH > 0 ? fH : fH + 360;
  288. fS *= S1;
  289. fL *= L1;
  290. HSLtoRGB((DWORD*)(imageInfo->pBits + i*4), fH, fS, fL);
  291. }
  292. }
  293. TImageInfo* CRenderEngine::LoadImage(STRINGorID bitmap, LPCTSTR type, DWORD mask)
  294. {
  295. LPBYTE pData = NULL;
  296. DWORD dwSize = 0;
  297. do
  298. {
  299. if( type == NULL ) {
  300. CDuiString sFile = CPaintManagerUI::GetResourcePath();
  301. if( CPaintManagerUI::GetResourceZip().IsEmpty() ) {
  302. sFile += bitmap.m_lpstr;
  303. HANDLE hFile = ::CreateFile(sFile.GetData(), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, \
  304. FILE_ATTRIBUTE_NORMAL, NULL);
  305. if( hFile == INVALID_HANDLE_VALUE ) break;
  306. dwSize = ::GetFileSize(hFile, NULL);
  307. if( dwSize == 0 ) break;
  308. DWORD dwRead = 0;
  309. pData = new BYTE[ dwSize ];
  310. ::ReadFile( hFile, pData, dwSize, &dwRead, NULL );
  311. ::CloseHandle( hFile );
  312. if( dwRead != dwSize ) {
  313. delete[] pData;
  314. pData = NULL;
  315. break;
  316. }
  317. }
  318. else {
  319. sFile += CPaintManagerUI::GetResourceZip();
  320. HZIP hz = NULL;
  321. if( CPaintManagerUI::IsCachedResourceZip() ) hz = (HZIP)CPaintManagerUI::GetResourceZipHandle();
  322. else hz = OpenZip((void*)sFile.GetData(), 0, 2);
  323. if( hz == NULL ) break;
  324. ZIPENTRY ze;
  325. int i;
  326. if( FindZipItem(hz, bitmap.m_lpstr, true, &i, &ze) != 0 ) break;
  327. dwSize = ze.unc_size;
  328. if( dwSize == 0 ) break;
  329. pData = new BYTE[ dwSize ];
  330. int res = UnzipItem(hz, i, pData, dwSize, 3);
  331. if( res != 0x00000000 && res != 0x00000600) {
  332. delete[] pData;
  333. pData = NULL;
  334. if( !CPaintManagerUI::IsCachedResourceZip() ) CloseZip(hz);
  335. break;
  336. }
  337. if( !CPaintManagerUI::IsCachedResourceZip() ) CloseZip(hz);
  338. }
  339. }
  340. else {
  341. HRSRC hResource = ::FindResource(CPaintManagerUI::GetResourceDll(), bitmap.m_lpstr, type);
  342. if( hResource == NULL ) break;
  343. HGLOBAL hGlobal = ::LoadResource(CPaintManagerUI::GetResourceDll(), hResource);
  344. if( hGlobal == NULL ) {
  345. FreeResource(hResource);
  346. break;
  347. }
  348. dwSize = ::SizeofResource(CPaintManagerUI::GetResourceDll(), hResource);
  349. if( dwSize == 0 ) break;
  350. pData = new BYTE[ dwSize ];
  351. ::CopyMemory(pData, (LPBYTE)::LockResource(hGlobal), dwSize);
  352. ::FreeResource(hResource);
  353. }
  354. } while (0);
  355. while (!pData)
  356. {
  357. //读不到图片, 则直接去读取bitmap.m_lpstr指向的路径
  358. HANDLE hFile = ::CreateFile(bitmap.m_lpstr, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, \
  359. FILE_ATTRIBUTE_NORMAL, NULL);
  360. if( hFile == INVALID_HANDLE_VALUE ) break;
  361. dwSize = ::GetFileSize(hFile, NULL);
  362. if( dwSize == 0 ) break;
  363. DWORD dwRead = 0;
  364. pData = new BYTE[ dwSize ];
  365. ::ReadFile( hFile, pData, dwSize, &dwRead, NULL );
  366. ::CloseHandle( hFile );
  367. if( dwRead != dwSize ) {
  368. delete[] pData;
  369. pData = NULL;
  370. }
  371. break;
  372. }
  373. if (!pData)
  374. {
  375. //::MessageBox(0, _T("读取图片数据失败!"), _T("抓BUG"), MB_OK);
  376. return NULL;
  377. }
  378. LPBYTE pImage = NULL;
  379. int x,y,n;
  380. pImage = stbi_load_from_memory(pData, dwSize, &x, &y, &n, 4);
  381. delete[] pData;
  382. if( !pImage ) {
  383. //::MessageBox(0, _T("解析图片失败"), _T("抓BUG"), MB_OK);
  384. return NULL;
  385. }
  386. BITMAPINFO bmi;
  387. ::ZeroMemory(&bmi, sizeof(BITMAPINFO));
  388. bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
  389. bmi.bmiHeader.biWidth = x;
  390. bmi.bmiHeader.biHeight = -y;
  391. bmi.bmiHeader.biPlanes = 1;
  392. bmi.bmiHeader.biBitCount = 32;
  393. bmi.bmiHeader.biCompression = BI_RGB;
  394. bmi.bmiHeader.biSizeImage = x * y * 4;
  395. bool bAlphaChannel = false;
  396. LPBYTE pDest = NULL;
  397. HBITMAP hBitmap = ::CreateDIBSection(NULL, &bmi, DIB_RGB_COLORS, (void**)&pDest, NULL, 0);
  398. if( !hBitmap ) {
  399. //::MessageBox(0, _T("CreateDIBSection失败"), _T("抓BUG"), MB_OK);
  400. return NULL;
  401. }
  402. for( int i = 0; i < x * y; i++ )
  403. {
  404. pDest[i*4 + 3] = pImage[i*4 + 3];
  405. if( pDest[i*4 + 3] < 255 )
  406. {
  407. pDest[i*4] = (BYTE)(DWORD(pImage[i*4 + 2])*pImage[i*4 + 3]/255);
  408. pDest[i*4 + 1] = (BYTE)(DWORD(pImage[i*4 + 1])*pImage[i*4 + 3]/255);
  409. pDest[i*4 + 2] = (BYTE)(DWORD(pImage[i*4])*pImage[i*4 + 3]/255);
  410. bAlphaChannel = true;
  411. }
  412. else
  413. {
  414. pDest[i*4] = pImage[i*4 + 2];
  415. pDest[i*4 + 1] = pImage[i*4 + 1];
  416. pDest[i*4 + 2] = pImage[i*4];
  417. }
  418. if( *(DWORD*)(&pDest[i*4]) == mask ) {
  419. pDest[i*4] = (BYTE)0;
  420. pDest[i*4 + 1] = (BYTE)0;
  421. pDest[i*4 + 2] = (BYTE)0;
  422. pDest[i*4 + 3] = (BYTE)0;
  423. bAlphaChannel = true;
  424. }
  425. }
  426. stbi_image_free(pImage);
  427. TImageInfo* data = new TImageInfo;
  428. data->hBitmap = hBitmap;
  429. data->pBits = pDest;
  430. data->nX = x;
  431. data->nY = y;
  432. data->bAlpha = bAlphaChannel;
  433. data->bUseHSL = false;
  434. data->pSrcBits = NULL;
  435. return data;
  436. }
  437. void CRenderEngine::FreeImage(TImageInfo* bitmap, bool bDelete)
  438. {
  439. if (bitmap == NULL) return;
  440. if (bitmap->hBitmap) {
  441. ::DeleteObject(bitmap->hBitmap);
  442. bitmap->hBitmap = NULL;
  443. }
  444. if (bitmap->pSrcBits) {
  445. delete[] bitmap->pSrcBits;
  446. bitmap->pSrcBits = NULL;
  447. }
  448. if (bDelete) delete bitmap ;
  449. }
  450. void CRenderEngine::DrawImage(HDC hDC, HBITMAP hBitmap, const RECT& rc, const RECT& rcPaint,
  451. const RECT& rcBmpPart, const RECT& rcCorners, bool bAlpha,
  452. BYTE uFade, bool bHole, bool bTiledX, bool bTiledY)
  453. {
  454. ASSERT(::GetObjectType(hDC)==OBJ_DC || ::GetObjectType(hDC)==OBJ_MEMDC);
  455. typedef BOOL (WINAPI *LPALPHABLEND)(HDC, int, int, int, int,HDC, int, int, int, int, BLENDFUNCTION);
  456. static LPALPHABLEND lpAlphaBlend = (LPALPHABLEND) ::GetProcAddress(::GetModuleHandle(_T("msimg32.dll")), "AlphaBlend");
  457. if( lpAlphaBlend == NULL ) lpAlphaBlend = AlphaBitBlt;
  458. if( hBitmap == NULL ) return;
  459. HDC hCloneDC = ::CreateCompatibleDC(hDC);
  460. HBITMAP hOldBitmap = (HBITMAP) ::SelectObject(hCloneDC, hBitmap);
  461. ::SetStretchBltMode(hDC, COLORONCOLOR);
  462. RECT rcTemp = {0};
  463. RECT rcDest = {0};
  464. if( lpAlphaBlend && (bAlpha || uFade < 255) ) {
  465. BLENDFUNCTION bf = { AC_SRC_OVER, 0, uFade, AC_SRC_ALPHA };
  466. // middle
  467. if( !bHole ) {
  468. rcDest.left = rc.left + rcCorners.left;
  469. rcDest.top = rc.top + rcCorners.top;
  470. rcDest.right = rc.right - rc.left - rcCorners.left - rcCorners.right;
  471. rcDest.bottom = rc.bottom - rc.top - rcCorners.top - rcCorners.bottom;
  472. rcDest.right += rcDest.left;
  473. rcDest.bottom += rcDest.top;
  474. if( ::IntersectRect(&rcTemp, &rcPaint, &rcDest) ) {
  475. if( !bTiledX && !bTiledY ) {
  476. rcDest.right -= rcDest.left;
  477. rcDest.bottom -= rcDest.top;
  478. lpAlphaBlend(hDC, rcDest.left, rcDest.top, rcDest.right, rcDest.bottom, hCloneDC, \
  479. rcBmpPart.left + rcCorners.left, rcBmpPart.top + rcCorners.top, \
  480. rcBmpPart.right - rcBmpPart.left - rcCorners.left - rcCorners.right, \
  481. rcBmpPart.bottom - rcBmpPart.top - rcCorners.top - rcCorners.bottom, bf);
  482. }
  483. else if( bTiledX && bTiledY ) {
  484. LONG lWidth = rcBmpPart.right - rcBmpPart.left - rcCorners.left - rcCorners.right;
  485. LONG lHeight = rcBmpPart.bottom - rcBmpPart.top - rcCorners.top - rcCorners.bottom;
  486. int iTimesX = (rcDest.right - rcDest.left + lWidth - 1) / lWidth;
  487. int iTimesY = (rcDest.bottom - rcDest.top + lHeight - 1) / lHeight;
  488. for( int j = 0; j < iTimesY; ++j ) {
  489. LONG lDestTop = rcDest.top + lHeight * j;
  490. LONG lDestBottom = rcDest.top + lHeight * (j + 1);
  491. LONG lDrawHeight = lHeight;
  492. if( lDestBottom > rcDest.bottom ) {
  493. lDrawHeight -= lDestBottom - rcDest.bottom;
  494. lDestBottom = rcDest.bottom;
  495. }
  496. for( int i = 0; i < iTimesX; ++i ) {
  497. LONG lDestLeft = rcDest.left + lWidth * i;
  498. LONG lDestRight = rcDest.left + lWidth * (i + 1);
  499. LONG lDrawWidth = lWidth;
  500. if( lDestRight > rcDest.right ) {
  501. lDrawWidth -= lDestRight - rcDest.right;
  502. lDestRight = rcDest.right;
  503. }
  504. lpAlphaBlend(hDC, rcDest.left + lWidth * i, rcDest.top + lHeight * j,
  505. lDestRight - lDestLeft, lDestBottom - lDestTop, hCloneDC,
  506. rcBmpPart.left + rcCorners.left, rcBmpPart.top + rcCorners.top, lDrawWidth, lDrawHeight, bf);
  507. }
  508. }
  509. }
  510. else if( bTiledX ) {
  511. LONG lWidth = rcBmpPart.right - rcBmpPart.left - rcCorners.left - rcCorners.right;
  512. int iTimes = (rcDest.right - rcDest.left + lWidth - 1) / lWidth;
  513. for( int i = 0; i < iTimes; ++i ) {
  514. LONG lDestLeft = rcDest.left + lWidth * i;
  515. LONG lDestRight = rcDest.left + lWidth * (i + 1);
  516. LONG lDrawWidth = lWidth;
  517. if( lDestRight > rcDest.right ) {
  518. lDrawWidth -= lDestRight - rcDest.right;
  519. lDestRight = rcDest.right;
  520. }
  521. rcDest.bottom -= rcDest.top;
  522. lpAlphaBlend(hDC, lDestLeft, rcDest.top, lDestRight - lDestLeft, rcDest.bottom,
  523. hCloneDC, rcBmpPart.left + rcCorners.left, rcBmpPart.top + rcCorners.top, \
  524. lDrawWidth, rcBmpPart.bottom - rcBmpPart.top - rcCorners.top - rcCorners.bottom, bf);
  525. }
  526. }
  527. else { // bTiledY
  528. LONG lHeight = rcBmpPart.bottom - rcBmpPart.top - rcCorners.top - rcCorners.bottom;
  529. int iTimes = (rcDest.bottom - rcDest.top + lHeight - 1) / lHeight;
  530. for( int i = 0; i < iTimes; ++i ) {
  531. LONG lDestTop = rcDest.top + lHeight * i;
  532. LONG lDestBottom = rcDest.top + lHeight * (i + 1);
  533. LONG lDrawHeight = lHeight;
  534. if( lDestBottom > rcDest.bottom ) {
  535. lDrawHeight -= lDestBottom - rcDest.bottom;
  536. lDestBottom = rcDest.bottom;
  537. }
  538. rcDest.right -= rcDest.left;
  539. lpAlphaBlend(hDC, rcDest.left, rcDest.top + lHeight * i, rcDest.right, lDestBottom - lDestTop,
  540. hCloneDC, rcBmpPart.left + rcCorners.left, rcBmpPart.top + rcCorners.top, \
  541. rcBmpPart.right - rcBmpPart.left - rcCorners.left - rcCorners.right, lDrawHeight, bf);
  542. }
  543. }
  544. }
  545. }
  546. // left-top
  547. if( rcCorners.left > 0 && rcCorners.top > 0 ) {
  548. rcDest.left = rc.left;
  549. rcDest.top = rc.top;
  550. rcDest.right = rcCorners.left;
  551. rcDest.bottom = rcCorners.top;
  552. rcDest.right += rcDest.left;
  553. rcDest.bottom += rcDest.top;
  554. if( ::IntersectRect(&rcTemp, &rcPaint, &rcDest) ) {
  555. rcDest.right -= rcDest.left;
  556. rcDest.bottom -= rcDest.top;
  557. lpAlphaBlend(hDC, rcDest.left, rcDest.top, rcDest.right, rcDest.bottom, hCloneDC, \
  558. rcBmpPart.left, rcBmpPart.top, rcCorners.left, rcCorners.top, bf);
  559. }
  560. }
  561. // top
  562. if( rcCorners.top > 0 ) {
  563. rcDest.left = rc.left + rcCorners.left;
  564. rcDest.top = rc.top;
  565. rcDest.right = rc.right - rc.left - rcCorners.left - rcCorners.right;
  566. rcDest.bottom = rcCorners.top;
  567. rcDest.right += rcDest.left;
  568. rcDest.bottom += rcDest.top;
  569. if( ::IntersectRect(&rcTemp, &rcPaint, &rcDest) ) {
  570. rcDest.right -= rcDest.left;
  571. rcDest.bottom -= rcDest.top;
  572. lpAlphaBlend(hDC, rcDest.left, rcDest.top, rcDest.right, rcDest.bottom, hCloneDC, \
  573. rcBmpPart.left + rcCorners.left, rcBmpPart.top, rcBmpPart.right - rcBmpPart.left - \
  574. rcCorners.left - rcCorners.right, rcCorners.top, bf);
  575. }
  576. }
  577. // right-top
  578. if( rcCorners.right > 0 && rcCorners.top > 0 ) {
  579. rcDest.left = rc.right - rcCorners.right;
  580. rcDest.top = rc.top;
  581. rcDest.right = rcCorners.right;
  582. rcDest.bottom = rcCorners.top;
  583. rcDest.right += rcDest.left;
  584. rcDest.bottom += rcDest.top;
  585. if( ::IntersectRect(&rcTemp, &rcPaint, &rcDest) ) {
  586. rcDest.right -= rcDest.left;
  587. rcDest.bottom -= rcDest.top;
  588. lpAlphaBlend(hDC, rcDest.left, rcDest.top, rcDest.right, rcDest.bottom, hCloneDC, \
  589. rcBmpPart.right - rcCorners.right, rcBmpPart.top, rcCorners.right, rcCorners.top, bf);
  590. }
  591. }
  592. // left
  593. if( rcCorners.left > 0 ) {
  594. rcDest.left = rc.left;
  595. rcDest.top = rc.top + rcCorners.top;
  596. rcDest.right = rcCorners.left;
  597. rcDest.bottom = rc.bottom - rc.top - rcCorners.top - rcCorners.bottom;
  598. rcDest.right += rcDest.left;
  599. rcDest.bottom += rcDest.top;
  600. if( ::IntersectRect(&rcTemp, &rcPaint, &rcDest) ) {
  601. rcDest.right -= rcDest.left;
  602. rcDest.bottom -= rcDest.top;
  603. lpAlphaBlend(hDC, rcDest.left, rcDest.top, rcDest.right, rcDest.bottom, hCloneDC, \
  604. rcBmpPart.left, rcBmpPart.top + rcCorners.top, rcCorners.left, rcBmpPart.bottom - \
  605. rcBmpPart.top - rcCorners.top - rcCorners.bottom, bf);
  606. }
  607. }
  608. // right
  609. if( rcCorners.right > 0 ) {
  610. rcDest.left = rc.right - rcCorners.right;
  611. rcDest.top = rc.top + rcCorners.top;
  612. rcDest.right = rcCorners.right;
  613. rcDest.bottom = rc.bottom - rc.top - rcCorners.top - rcCorners.bottom;
  614. rcDest.right += rcDest.left;
  615. rcDest.bottom += rcDest.top;
  616. if( ::IntersectRect(&rcTemp, &rcPaint, &rcDest) ) {
  617. rcDest.right -= rcDest.left;
  618. rcDest.bottom -= rcDest.top;
  619. lpAlphaBlend(hDC, rcDest.left, rcDest.top, rcDest.right, rcDest.bottom, hCloneDC, \
  620. rcBmpPart.right - rcCorners.right, rcBmpPart.top + rcCorners.top, rcCorners.right, \
  621. rcBmpPart.bottom - rcBmpPart.top - rcCorners.top - rcCorners.bottom, bf);
  622. }
  623. }
  624. // left-bottom
  625. if( rcCorners.left > 0 && rcCorners.bottom > 0 ) {
  626. rcDest.left = rc.left;
  627. rcDest.top = rc.bottom - rcCorners.bottom;
  628. rcDest.right = rcCorners.left;
  629. rcDest.bottom = rcCorners.bottom;
  630. rcDest.right += rcDest.left;
  631. rcDest.bottom += rcDest.top;
  632. if( ::IntersectRect(&rcTemp, &rcPaint, &rcDest) ) {
  633. rcDest.right -= rcDest.left;
  634. rcDest.bottom -= rcDest.top;
  635. lpAlphaBlend(hDC, rcDest.left, rcDest.top, rcDest.right, rcDest.bottom, hCloneDC, \
  636. rcBmpPart.left, rcBmpPart.bottom - rcCorners.bottom, rcCorners.left, rcCorners.bottom, bf);
  637. }
  638. }
  639. // bottom
  640. if( rcCorners.bottom > 0 ) {
  641. rcDest.left = rc.left + rcCorners.left;
  642. rcDest.top = rc.bottom - rcCorners.bottom;
  643. rcDest.right = rc.right - rc.left - rcCorners.left - rcCorners.right;
  644. rcDest.bottom = rcCorners.bottom;
  645. rcDest.right += rcDest.left;
  646. rcDest.bottom += rcDest.top;
  647. if( ::IntersectRect(&rcTemp, &rcPaint, &rcDest) ) {
  648. rcDest.right -= rcDest.left;
  649. rcDest.bottom -= rcDest.top;
  650. lpAlphaBlend(hDC, rcDest.left, rcDest.top, rcDest.right, rcDest.bottom, hCloneDC, \
  651. rcBmpPart.left + rcCorners.left, rcBmpPart.bottom - rcCorners.bottom, \
  652. rcBmpPart.right - rcBmpPart.left - rcCorners.left - rcCorners.right, rcCorners.bottom, bf);
  653. }
  654. }
  655. // right-bottom
  656. if( rcCorners.right > 0 && rcCorners.bottom > 0 ) {
  657. rcDest.left = rc.right - rcCorners.right;
  658. rcDest.top = rc.bottom - rcCorners.bottom;
  659. rcDest.right = rcCorners.right;
  660. rcDest.bottom = rcCorners.bottom;
  661. rcDest.right += rcDest.left;
  662. rcDest.bottom += rcDest.top;
  663. if( ::IntersectRect(&rcTemp, &rcPaint, &rcDest) ) {
  664. rcDest.right -= rcDest.left;
  665. rcDest.bottom -= rcDest.top;
  666. lpAlphaBlend(hDC, rcDest.left, rcDest.top, rcDest.right, rcDest.bottom, hCloneDC, \
  667. rcBmpPart.right - rcCorners.right, rcBmpPart.bottom - rcCorners.bottom, rcCorners.right, \
  668. rcCorners.bottom, bf);
  669. }
  670. }
  671. }
  672. else
  673. {
  674. if (rc.right - rc.left == rcBmpPart.right - rcBmpPart.left \
  675. && rc.bottom - rc.top == rcBmpPart.bottom - rcBmpPart.top \
  676. && rcCorners.left == 0 && rcCorners.right == 0 && rcCorners.top == 0 && rcCorners.bottom == 0)
  677. {
  678. if( ::IntersectRect(&rcTemp, &rcPaint, &rc) ) {
  679. ::BitBlt(hDC, rcTemp.left, rcTemp.top, rcTemp.right - rcTemp.left, rcTemp.bottom - rcTemp.top, \
  680. hCloneDC, rcBmpPart.left + rcTemp.left - rc.left, rcBmpPart.top + rcTemp.top - rc.top, SRCCOPY);
  681. }
  682. }
  683. else
  684. {
  685. // middle
  686. if( !bHole ) {
  687. rcDest.left = rc.left + rcCorners.left;
  688. rcDest.top = rc.top + rcCorners.top;
  689. rcDest.right = rc.right - rc.left - rcCorners.left - rcCorners.right;
  690. rcDest.bottom = rc.bottom - rc.top - rcCorners.top - rcCorners.bottom;
  691. rcDest.right += rcDest.left;
  692. rcDest.bottom += rcDest.top;
  693. if( ::IntersectRect(&rcTemp, &rcPaint, &rcDest) ) {
  694. if( !bTiledX && !bTiledY ) {
  695. rcDest.right -= rcDest.left;
  696. rcDest.bottom -= rcDest.top;
  697. ::StretchBlt(hDC, rcDest.left, rcDest.top, rcDest.right, rcDest.bottom, hCloneDC, \
  698. rcBmpPart.left + rcCorners.left, rcBmpPart.top + rcCorners.top, \
  699. rcBmpPart.right - rcBmpPart.left - rcCorners.left - rcCorners.right, \
  700. rcBmpPart.bottom - rcBmpPart.top - rcCorners.top - rcCorners.bottom, SRCCOPY);
  701. }
  702. else if( bTiledX && bTiledY ) {
  703. LONG lWidth = rcBmpPart.right - rcBmpPart.left - rcCorners.left - rcCorners.right;
  704. LONG lHeight = rcBmpPart.bottom - rcBmpPart.top - rcCorners.top - rcCorners.bottom;
  705. int iTimesX = (rcDest.right - rcDest.left + lWidth - 1) / lWidth;
  706. int iTimesY = (rcDest.bottom - rcDest.top + lHeight - 1) / lHeight;
  707. for( int j = 0; j < iTimesY; ++j ) {
  708. LONG lDestTop = rcDest.top + lHeight * j;
  709. LONG lDestBottom = rcDest.top + lHeight * (j + 1);
  710. LONG lDrawHeight = lHeight;
  711. if( lDestBottom > rcDest.bottom ) {
  712. lDrawHeight -= lDestBottom - rcDest.bottom;
  713. lDestBottom = rcDest.bottom;
  714. }
  715. for( int i = 0; i < iTimesX; ++i ) {
  716. LONG lDestLeft = rcDest.left + lWidth * i;
  717. LONG lDestRight = rcDest.left + lWidth * (i + 1);
  718. LONG lDrawWidth = lWidth;
  719. if( lDestRight > rcDest.right ) {
  720. lDrawWidth -= lDestRight - rcDest.right;
  721. lDestRight = rcDest.right;
  722. }
  723. ::BitBlt(hDC, rcDest.left + lWidth * i, rcDest.top + lHeight * j, \
  724. lDestRight - lDestLeft, lDestBottom - lDestTop, hCloneDC, \
  725. rcBmpPart.left + rcCorners.left, rcBmpPart.top + rcCorners.top, SRCCOPY);
  726. }
  727. }
  728. }
  729. else if( bTiledX ) {
  730. LONG lWidth = rcBmpPart.right - rcBmpPart.left - rcCorners.left - rcCorners.right;
  731. int iTimes = (rcDest.right - rcDest.left + lWidth - 1) / lWidth;
  732. for( int i = 0; i < iTimes; ++i ) {
  733. LONG lDestLeft = rcDest.left + lWidth * i;
  734. LONG lDestRight = rcDest.left + lWidth * (i + 1);
  735. LONG lDrawWidth = lWidth;
  736. if( lDestRight > rcDest.right ) {
  737. lDrawWidth -= lDestRight - rcDest.right;
  738. lDestRight = rcDest.right;
  739. }
  740. rcDest.bottom -= rcDest.top;
  741. ::StretchBlt(hDC, lDestLeft, rcDest.top, lDestRight - lDestLeft, rcDest.bottom,
  742. hCloneDC, rcBmpPart.left + rcCorners.left, rcBmpPart.top + rcCorners.top, \
  743. lDrawWidth, rcBmpPart.bottom - rcBmpPart.top - rcCorners.top - rcCorners.bottom, SRCCOPY);
  744. }
  745. }
  746. else { // bTiledY
  747. LONG lHeight = rcBmpPart.bottom - rcBmpPart.top - rcCorners.top - rcCorners.bottom;
  748. int iTimes = (rcDest.bottom - rcDest.top + lHeight - 1) / lHeight;
  749. for( int i = 0; i < iTimes; ++i ) {
  750. LONG lDestTop = rcDest.top + lHeight * i;
  751. LONG lDestBottom = rcDest.top + lHeight * (i + 1);
  752. LONG lDrawHeight = lHeight;
  753. if( lDestBottom > rcDest.bottom ) {
  754. lDrawHeight -= lDestBottom - rcDest.bottom;
  755. lDestBottom = rcDest.bottom;
  756. }
  757. rcDest.right -= rcDest.left;
  758. ::StretchBlt(hDC, rcDest.left, rcDest.top + lHeight * i, rcDest.right, lDestBottom - lDestTop,
  759. hCloneDC, rcBmpPart.left + rcCorners.left, rcBmpPart.top + rcCorners.top, \
  760. rcBmpPart.right - rcBmpPart.left - rcCorners.left - rcCorners.right, lDrawHeight, SRCCOPY);
  761. }
  762. }
  763. }
  764. }
  765. // left-top
  766. if( rcCorners.left > 0 && rcCorners.top > 0 ) {
  767. rcDest.left = rc.left;
  768. rcDest.top = rc.top;
  769. rcDest.right = rcCorners.left;
  770. rcDest.bottom = rcCorners.top;
  771. rcDest.right += rcDest.left;
  772. rcDest.bottom += rcDest.top;
  773. if( ::IntersectRect(&rcTemp, &rcPaint, &rcDest) ) {
  774. rcDest.right -= rcDest.left;
  775. rcDest.bottom -= rcDest.top;
  776. ::StretchBlt(hDC, rcDest.left, rcDest.top, rcDest.right, rcDest.bottom, hCloneDC, \
  777. rcBmpPart.left, rcBmpPart.top, rcCorners.left, rcCorners.top, SRCCOPY);
  778. }
  779. }
  780. // top
  781. if( rcCorners.top > 0 ) {
  782. rcDest.left = rc.left + rcCorners.left;
  783. rcDest.top = rc.top;
  784. rcDest.right = rc.right - rc.left - rcCorners.left - rcCorners.right;
  785. rcDest.bottom = rcCorners.top;
  786. rcDest.right += rcDest.left;
  787. rcDest.bottom += rcDest.top;
  788. if( ::IntersectRect(&rcTemp, &rcPaint, &rcDest) ) {
  789. rcDest.right -= rcDest.left;
  790. rcDest.bottom -= rcDest.top;
  791. ::StretchBlt(hDC, rcDest.left, rcDest.top, rcDest.right, rcDest.bottom, hCloneDC, \
  792. rcBmpPart.left + rcCorners.left, rcBmpPart.top, rcBmpPart.right - rcBmpPart.left - \
  793. rcCorners.left - rcCorners.right, rcCorners.top, SRCCOPY);
  794. }
  795. }
  796. // right-top
  797. if( rcCorners.right > 0 && rcCorners.top > 0 ) {
  798. rcDest.left = rc.right - rcCorners.right;
  799. rcDest.top = rc.top;
  800. rcDest.right = rcCorners.right;
  801. rcDest.bottom = rcCorners.top;
  802. rcDest.right += rcDest.left;
  803. rcDest.bottom += rcDest.top;
  804. if( ::IntersectRect(&rcTemp, &rcPaint, &rcDest) ) {
  805. rcDest.right -= rcDest.left;
  806. rcDest.bottom -= rcDest.top;
  807. ::StretchBlt(hDC, rcDest.left, rcDest.top, rcDest.right, rcDest.bottom, hCloneDC, \
  808. rcBmpPart.right - rcCorners.right, rcBmpPart.top, rcCorners.right, rcCorners.top, SRCCOPY);
  809. }
  810. }
  811. // left
  812. if( rcCorners.left > 0 ) {
  813. rcDest.left = rc.left;
  814. rcDest.top = rc.top + rcCorners.top;
  815. rcDest.right = rcCorners.left;
  816. rcDest.bottom = rc.bottom - rc.top - rcCorners.top - rcCorners.bottom;
  817. rcDest.right += rcDest.left;
  818. rcDest.bottom += rcDest.top;
  819. if( ::IntersectRect(&rcTemp, &rcPaint, &rcDest) ) {
  820. rcDest.right -= rcDest.left;
  821. rcDest.bottom -= rcDest.top;
  822. ::StretchBlt(hDC, rcDest.left, rcDest.top, rcDest.right, rcDest.bottom, hCloneDC, \
  823. rcBmpPart.left, rcBmpPart.top + rcCorners.top, rcCorners.left, rcBmpPart.bottom - \
  824. rcBmpPart.top - rcCorners.top - rcCorners.bottom, SRCCOPY);
  825. }
  826. }
  827. // right
  828. if( rcCorners.right > 0 ) {
  829. rcDest.left = rc.right - rcCorners.right;
  830. rcDest.top = rc.top + rcCorners.top;
  831. rcDest.right = rcCorners.right;
  832. rcDest.bottom = rc.bottom - rc.top - rcCorners.top - rcCorners.bottom;
  833. rcDest.right += rcDest.left;
  834. rcDest.bottom += rcDest.top;
  835. if( ::IntersectRect(&rcTemp, &rcPaint, &rcDest) ) {
  836. rcDest.right -= rcDest.left;
  837. rcDest.bottom -= rcDest.top;
  838. ::StretchBlt(hDC, rcDest.left, rcDest.top, rcDest.right, rcDest.bottom, hCloneDC, \
  839. rcBmpPart.right - rcCorners.right, rcBmpPart.top + rcCorners.top, rcCorners.right, \
  840. rcBmpPart.bottom - rcBmpPart.top - rcCorners.top - rcCorners.bottom, SRCCOPY);
  841. }
  842. }
  843. // left-bottom
  844. if( rcCorners.left > 0 && rcCorners.bottom > 0 ) {
  845. rcDest.left = rc.left;
  846. rcDest.top = rc.bottom - rcCorners.bottom;
  847. rcDest.right = rcCorners.left;
  848. rcDest.bottom = rcCorners.bottom;
  849. rcDest.right += rcDest.left;
  850. rcDest.bottom += rcDest.top;
  851. if( ::IntersectRect(&rcTemp, &rcPaint, &rcDest) ) {
  852. rcDest.right -= rcDest.left;
  853. rcDest.bottom -= rcDest.top;
  854. ::StretchBlt(hDC, rcDest.left, rcDest.top, rcDest.right, rcDest.bottom, hCloneDC, \
  855. rcBmpPart.left, rcBmpPart.bottom - rcCorners.bottom, rcCorners.left, rcCorners.bottom, SRCCOPY);
  856. }
  857. }
  858. // bottom
  859. if( rcCorners.bottom > 0 ) {
  860. rcDest.left = rc.left + rcCorners.left;
  861. rcDest.top = rc.bottom - rcCorners.bottom;
  862. rcDest.right = rc.right - rc.left - rcCorners.left - rcCorners.right;
  863. rcDest.bottom = rcCorners.bottom;
  864. rcDest.right += rcDest.left;
  865. rcDest.bottom += rcDest.top;
  866. if( ::IntersectRect(&rcTemp, &rcPaint, &rcDest) ) {
  867. rcDest.right -= rcDest.left;
  868. rcDest.bottom -= rcDest.top;
  869. ::StretchBlt(hDC, rcDest.left, rcDest.top, rcDest.right, rcDest.bottom, hCloneDC, \
  870. rcBmpPart.left + rcCorners.left, rcBmpPart.bottom - rcCorners.bottom, \
  871. rcBmpPart.right - rcBmpPart.left - rcCorners.left - rcCorners.right, rcCorners.bottom, SRCCOPY);
  872. }
  873. }
  874. // right-bottom
  875. if( rcCorners.right > 0 && rcCorners.bottom > 0 ) {
  876. rcDest.left = rc.right - rcCorners.right;
  877. rcDest.top = rc.bottom - rcCorners.bottom;
  878. rcDest.right = rcCorners.right;
  879. rcDest.bottom = rcCorners.bottom;
  880. rcDest.right += rcDest.left;
  881. rcDest.bottom += rcDest.top;
  882. if( ::IntersectRect(&rcTemp, &rcPaint, &rcDest) ) {
  883. rcDest.right -= rcDest.left;
  884. rcDest.bottom -= rcDest.top;
  885. ::StretchBlt(hDC, rcDest.left, rcDest.top, rcDest.right, rcDest.bottom, hCloneDC, \
  886. rcBmpPart.right - rcCorners.right, rcBmpPart.bottom - rcCorners.bottom, rcCorners.right, \
  887. rcCorners.bottom, SRCCOPY);
  888. }
  889. }
  890. }
  891. }
  892. ::SelectObject(hCloneDC, hOldBitmap);
  893. ::DeleteDC(hCloneDC);
  894. }
  895. bool CRenderEngine::DrawImage(HDC hDC, CPaintManagerUI* pManager, const RECT& rcItem, const RECT& rcPaint,
  896. TDrawInfo& drawInfo)
  897. {
  898. // 1、aaa.jpg
  899. // 2、file='aaa.jpg' res='' restype='0' dest='0,0,0,0' source='0,0,0,0' corner='0,0,0,0'
  900. // mask='#FF0000' fade='255' hole='false' xtiled='false' ytiled='false' hsl='false'
  901. if( pManager == NULL ) return true;
  902. if( drawInfo.pImageInfo == NULL ) {
  903. if( drawInfo.bLoaded ) return false;
  904. drawInfo.bLoaded = true;
  905. if( drawInfo.sDrawString.IsEmpty() ) return false;
  906. bool bUseRes = false;
  907. CDuiString sImageName = drawInfo.sDrawString;
  908. CDuiString sImageResType;
  909. DWORD dwMask = 0;
  910. bool bUseHSL = false;
  911. CDuiString sItem;
  912. CDuiString sValue;
  913. LPTSTR pstr = NULL;
  914. LPCTSTR pstrImage = drawInfo.sDrawString.GetData();
  915. while( *pstrImage != _T('\0') ) {
  916. sItem.Empty();
  917. sValue.Empty();
  918. while( *pstrImage > _T('\0') && *pstrImage <= _T(' ') ) pstrImage = ::CharNext(pstrImage);
  919. while( *pstrImage != _T('\0') && *pstrImage != _T('=') && *pstrImage > _T(' ') ) {
  920. LPTSTR pstrTemp = ::CharNext(pstrImage);
  921. while( pstrImage < pstrTemp) {
  922. sItem += *pstrImage++;
  923. }
  924. }
  925. while( *pstrImage > _T('\0') && *pstrImage <= _T(' ') ) pstrImage = ::CharNext(pstrImage);
  926. if( *pstrImage++ != _T('=') ) break;
  927. while( *pstrImage > _T('\0') && *pstrImage <= _T(' ') ) pstrImage = ::CharNext(pstrImage);
  928. if( *pstrImage++ != _T('\'') ) break;
  929. while( *pstrImage != _T('\0') && *pstrImage != _T('\'') ) {
  930. LPTSTR pstrTemp = ::CharNext(pstrImage);
  931. while( pstrImage < pstrTemp) {
  932. sValue += *pstrImage++;
  933. }
  934. }
  935. if( *pstrImage++ != _T('\'') ) break;
  936. if( !sValue.IsEmpty() ) {
  937. if( sItem == _T("file") ) {
  938. sImageName = sValue;
  939. }
  940. else if( sItem == _T("res") ) {
  941. bUseRes = true;
  942. sImageName = sValue;
  943. }
  944. else if( sItem == _T("restype") ) {
  945. sImageResType = sValue;
  946. }
  947. else if( sItem == _T("dest") ) {
  948. drawInfo.rcDestOffset.left = _tcstol(sValue.GetData(), &pstr, 10); ASSERT(pstr);
  949. drawInfo.rcDestOffset.top = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
  950. drawInfo.rcDestOffset.right = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
  951. drawInfo.rcDestOffset.bottom = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
  952. }
  953. else if( sItem == _T("source") ) {
  954. drawInfo.rcBmpPart.left = _tcstol(sValue.GetData(), &pstr, 10); ASSERT(pstr);
  955. drawInfo.rcBmpPart.top = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
  956. drawInfo.rcBmpPart.right = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
  957. drawInfo.rcBmpPart.bottom = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
  958. }
  959. else if( sItem == _T("corner") ) {
  960. drawInfo.rcCorner.left = _tcstol(sValue.GetData(), &pstr, 10); ASSERT(pstr);
  961. drawInfo.rcCorner.top = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
  962. drawInfo.rcCorner.right = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
  963. drawInfo.rcCorner.bottom = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
  964. }
  965. else if( sItem == _T("mask") ) {
  966. if( sValue[0] == _T('#')) dwMask = _tcstoul(sValue.GetData() + 1, &pstr, 16);
  967. else dwMask = _tcstoul(sValue.GetData(), &pstr, 16);
  968. }
  969. else if( sItem == _T("fade") ) {
  970. drawInfo.uFade = (BYTE)_tcstoul(sValue.GetData(), &pstr, 10);
  971. }
  972. else if( sItem == _T("hole") ) {
  973. drawInfo.bHole = (_tcscmp(sValue.GetData(), _T("true")) == 0);
  974. }
  975. else if( sItem == _T("xtiled") ) {
  976. drawInfo.bTiledX = (_tcscmp(sValue.GetData(), _T("true")) == 0);
  977. }
  978. else if( sItem == _T("ytiled") ) {
  979. drawInfo.bTiledY = (_tcscmp(sValue.GetData(), _T("true")) == 0);
  980. }
  981. else if( sItem == _T("hsl") ) {
  982. bUseHSL = (_tcscmp(sValue.GetData(), _T("true")) == 0);
  983. }
  984. }
  985. if( *pstrImage++ != _T(' ') ) break;
  986. }
  987. drawInfo.sImageName = sImageName;
  988. const TImageInfo* data = NULL;
  989. if( bUseRes == false ) {
  990. data = pManager->GetImageEx((LPCTSTR)sImageName, NULL, dwMask, bUseHSL);
  991. }
  992. else {
  993. data = pManager->GetImageEx((LPCTSTR)sImageName, (LPCTSTR)sImageResType, dwMask, bUseHSL);
  994. }
  995. if( !data ) return false;
  996. drawInfo.pImageInfo = data;
  997. if( drawInfo.rcBmpPart.left == 0 && drawInfo.rcBmpPart.right == 0 &&
  998. drawInfo.rcBmpPart.top == 0 && drawInfo.rcBmpPart.bottom == 0 ) {
  999. drawInfo.rcBmpPart.right = data->nX;
  1000. drawInfo.rcBmpPart.bottom = data->nY;
  1001. }
  1002. }
  1003. if( drawInfo.rcBmpPart.right > drawInfo.pImageInfo->nX ) drawInfo.rcBmpPart.right = drawInfo.pImageInfo->nX;
  1004. if( drawInfo.rcBmpPart.bottom > drawInfo.pImageInfo->nY ) drawInfo.rcBmpPart.bottom = drawInfo.pImageInfo->nY;
  1005. if( hDC == NULL ) return true;
  1006. RECT rcDest = rcItem;
  1007. if( drawInfo.rcDestOffset.left != 0 || drawInfo.rcDestOffset.top != 0 ||
  1008. drawInfo.rcDestOffset.right != 0 || drawInfo.rcDestOffset.bottom != 0 ) {
  1009. rcDest.left = rcItem.left + drawInfo.rcDestOffset.left;
  1010. rcDest.top = rcItem.top + drawInfo.rcDestOffset.top;
  1011. rcDest.right = rcItem.left + drawInfo.rcDestOffset.right;
  1012. if( rcDest.right > rcItem.right ) rcDest.right = rcItem.right;
  1013. rcDest.bottom = rcItem.top + drawInfo.rcDestOffset.bottom;
  1014. if( rcDest.bottom > rcItem.bottom ) rcDest.bottom = rcItem.bottom;
  1015. }
  1016. RECT rcTemp;
  1017. if( !::IntersectRect(&rcTemp, &rcDest, &rcItem) ) return true;
  1018. if( !::IntersectRect(&rcTemp, &rcDest, &rcPaint) ) return true;
  1019. DrawImage(hDC, drawInfo.pImageInfo->hBitmap, rcDest, rcPaint, drawInfo.rcBmpPart, drawInfo.rcCorner,
  1020. drawInfo.pImageInfo->bAlpha, drawInfo.uFade, drawInfo.bHole, drawInfo.bTiledX, drawInfo.bTiledY);
  1021. return true;
  1022. }
  1023. void CRenderEngine::DrawColor(HDC hDC, const RECT& rc, DWORD color)
  1024. {
  1025. if( color <= 0x00FFFFFF ) return;
  1026. if( color >= 0xFF000000 )
  1027. {
  1028. ::SetBkColor(hDC, RGB(GetBValue(color), GetGValue(color), GetRValue(color)));
  1029. ::ExtTextOut(hDC, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
  1030. }
  1031. else
  1032. {
  1033. // Create a new 32bpp bitmap with room for an alpha channel
  1034. BITMAPINFO bmi = { 0 };
  1035. bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
  1036. bmi.bmiHeader.biWidth = 1;
  1037. bmi.bmiHeader.biHeight = 1;
  1038. bmi.bmiHeader.biPlanes = 1;
  1039. bmi.bmiHeader.biBitCount = 32;
  1040. bmi.bmiHeader.biCompression = BI_RGB;
  1041. bmi.bmiHeader.biSizeImage = 1 * 1 * sizeof(DWORD);
  1042. LPDWORD pDest = NULL;
  1043. HBITMAP hBitmap = ::CreateDIBSection(hDC, &bmi, DIB_RGB_COLORS, (LPVOID*) &pDest, NULL, 0);
  1044. if( !hBitmap ) return;
  1045. *pDest = color;
  1046. RECT rcBmpPart = {0, 0, 1, 1};
  1047. RECT rcCorners = {0};
  1048. DrawImage(hDC, hBitmap, rc, rc, rcBmpPart, rcCorners, true, 255);
  1049. ::DeleteObject(hBitmap);
  1050. }
  1051. }
  1052. void CRenderEngine::DrawGradient(HDC hDC, const RECT& rc, DWORD dwFirst, DWORD dwSecond, bool bVertical, int nSteps)
  1053. {
  1054. typedef BOOL (WINAPI *LPALPHABLEND)(HDC, int, int, int, int,HDC, int, int, int, int, BLENDFUNCTION);
  1055. static LPALPHABLEND lpAlphaBlend = (LPALPHABLEND) ::GetProcAddress(::GetModuleHandle(_T("msimg32.dll")), "AlphaBlend");
  1056. if( lpAlphaBlend == NULL ) lpAlphaBlend = AlphaBitBlt;
  1057. typedef BOOL (WINAPI *PGradientFill)(HDC, PTRIVERTEX, ULONG, PVOID, ULONG, ULONG);
  1058. static PGradientFill lpGradientFill = (PGradientFill) ::GetProcAddress(::GetModuleHandle(_T("msimg32.dll")), "GradientFill");
  1059. BYTE bAlpha = (BYTE)(((dwFirst >> 24) + (dwSecond >> 24)) >> 1);
  1060. if( bAlpha == 0 ) return;
  1061. int cx = rc.right - rc.left;
  1062. int cy = rc.bottom - rc.top;
  1063. RECT rcPaint = rc;
  1064. HDC hPaintDC = hDC;
  1065. HBITMAP hPaintBitmap = NULL;
  1066. HBITMAP hOldPaintBitmap = NULL;
  1067. if( bAlpha < 255 ) {
  1068. rcPaint.left = rcPaint.top = 0;
  1069. rcPaint.right = cx;
  1070. rcPaint.bottom = cy;
  1071. hPaintDC = ::CreateCompatibleDC(hDC);
  1072. hPaintBitmap = ::CreateCompatibleBitmap(hDC, cx, cy);
  1073. ASSERT(hPaintDC);
  1074. ASSERT(hPaintBitmap);
  1075. hOldPaintBitmap = (HBITMAP) ::SelectObject(hPaintDC, hPaintBitmap);
  1076. }
  1077. if( lpGradientFill != NULL )
  1078. {
  1079. TRIVERTEX triv[2] =
  1080. {
  1081. { rcPaint.left, rcPaint.top, GetBValue(dwFirst) << 8, GetGValue(dwFirst) << 8, GetRValue(dwFirst) << 8, 0xFF00 },
  1082. { rcPaint.right, rcPaint.bottom, GetBValue(dwSecond) << 8, GetGValue(dwSecond) << 8, GetRValue(dwSecond) << 8, 0xFF00 }
  1083. };
  1084. GRADIENT_RECT grc = { 0, 1 };
  1085. lpGradientFill(hPaintDC, triv, 2, &grc, 1, bVertical ? GRADIENT_FILL_RECT_V : GRADIENT_FILL_RECT_H);
  1086. }
  1087. else
  1088. {
  1089. // Determine how many shades
  1090. int nShift = 1;
  1091. if( nSteps >= 64 ) nShift = 6;
  1092. else if( nSteps >= 32 ) nShift = 5;
  1093. else if( nSteps >= 16 ) nShift = 4;
  1094. else if( nSteps >= 8 ) nShift = 3;
  1095. else if( nSteps >= 4 ) nShift = 2;
  1096. int nLines = 1 << nShift;
  1097. for( int i = 0; i < nLines; i++ ) {
  1098. // Do a little alpha blending
  1099. BYTE bR = (BYTE) ((GetBValue(dwSecond) * (nLines - i) + GetBValue(dwFirst) * i) >> nShift);
  1100. BYTE bG = (BYTE) ((GetGValue(dwSecond) * (nLines - i) + GetGValue(dwFirst) * i) >> nShift);
  1101. BYTE bB = (BYTE) ((GetRValue(dwSecond) * (nLines - i) + GetRValue(dwFirst) * i) >> nShift);
  1102. // ... then paint with the resulting color
  1103. HBRUSH hBrush = ::CreateSolidBrush(RGB(bR,bG,bB));
  1104. RECT r2 = rcPaint;
  1105. if( bVertical ) {
  1106. r2.bottom = rc.bottom - ((i * (rc.bottom - rc.top)) >> nShift);
  1107. r2.top = rc.bottom - (((i + 1) * (rc.bottom - rc.top)) >> nShift);
  1108. if( (r2.bottom - r2.top) > 0 ) ::FillRect(hDC, &r2, hBrush);
  1109. }
  1110. else {
  1111. r2.left = rc.right - (((i + 1) * (rc.right - rc.left)) >> nShift);
  1112. r2.right = rc.right - ((i * (rc.right - rc.left)) >> nShift);
  1113. if( (r2.right - r2.left) > 0 ) ::FillRect(hPaintDC, &r2, hBrush);
  1114. }
  1115. ::DeleteObject(hBrush);
  1116. }
  1117. }
  1118. if( bAlpha < 255 ) {
  1119. BLENDFUNCTION bf = { AC_SRC_OVER, 0, bAlpha, AC_SRC_ALPHA };
  1120. lpAlphaBlend(hDC, rc.left, rc.top, cx, cy, hPaintDC, 0, 0, cx, cy, bf);
  1121. ::SelectObject(hPaintDC, hOldPaintBitmap);
  1122. ::DeleteObject(hPaintBitmap);
  1123. ::DeleteDC(hPaintDC);
  1124. }
  1125. }
  1126. /*
  1127. * ---------------------------- modify ----------------------------------------
  1128. */
  1129. void CRenderEngine::DrawGradientEx(HDC hDC,const RECT& rc,COLORREF crColors[],size_t nColors, DWORD dwFillMode)
  1130. {
  1131. if (nColors<2)
  1132. {
  1133. return;
  1134. }
  1135. typedef BOOL (WINAPI *PGradientFill)(HDC, PTRIVERTEX, ULONG, PVOID, ULONG, ULONG);
  1136. static PGradientFill lpGradientFill = (PGradientFill) ::GetProcAddress(::GetModuleHandle(_T("msimg32.dll")), "GradientFill");
  1137. ASSERT(lpGradientFill!=nullptr);
  1138. int l = rc.left;
  1139. int t = rc.top;
  1140. int cx = rc.right-rc.left;
  1141. int cy = rc.bottom-rc.top;
  1142. LPTRIVERTEX pVert = new TRIVERTEX[nColors];
  1143. for (size_t i=0;i<nColors;i++)
  1144. {
  1145. pVert[i].Red = GetBValue(crColors[i])*0x100;
  1146. pVert[i].Green = GetGValue(crColors[i])*0x100;
  1147. pVert[i].Blue = GetRValue(crColors[i])*0x100;
  1148. pVert[i].Alpha = (crColors[i]>>24)*0x100;
  1149. if (GRADIENT_FILL_RECT_H == dwFillMode)
  1150. {
  1151. pVert[i].x = l+(cx*i/(nColors-1));
  1152. pVert[i].y = t+(cy*(i%2));
  1153. }
  1154. else
  1155. {
  1156. pVert[i].x = l+(cx*(i%2));
  1157. pVert[i].y = t+(cy*i/(nColors-1));
  1158. }
  1159. }
  1160. LPGRADIENT_RECT pGr = new GRADIENT_RECT[nColors-1];
  1161. for (size_t i=0;i<nColors-1;i++)
  1162. {
  1163. pGr[i].UpperLeft = i;
  1164. pGr[i].LowerRight = i+1;
  1165. }
  1166. lpGradientFill(hDC,pVert,nColors,pGr,nColors-1,dwFillMode);
  1167. delete[] pGr;
  1168. delete[] pVert;
  1169. }
  1170. /*--------------------------------------------------------------------------------------*/
  1171. void CRenderEngine::DrawLine( HDC hDC, const RECT& rc, int nSize, DWORD dwPenColor, int nStyle)
  1172. {
  1173. ASSERT(::GetObjectType(hDC)==OBJ_DC || ::GetObjectType(hDC)==OBJ_MEMDC);
  1174. LOGPEN lg;
  1175. lg.lopnColor = RGB(GetBValue(dwPenColor), GetGValue(dwPenColor), GetRValue(dwPenColor));
  1176. lg.lopnStyle = nStyle;
  1177. lg.lopnWidth.x = nSize;
  1178. HPEN hPen = CreatePenIndirect(&lg);
  1179. HPEN hOldPen = (HPEN)::SelectObject(hDC, hPen);
  1180. POINT ptTemp = { 0 };
  1181. ::MoveToEx(hDC, rc.left, rc.top, &ptTemp);
  1182. ::LineTo(hDC, rc.right, rc.bottom);
  1183. ::SelectObject(hDC, hOldPen);
  1184. ::DeleteObject(hPen);
  1185. }
  1186. void CRenderEngine::DrawRect(HDC hDC, const RECT& rc, int nSize, DWORD dwPenColor, int nStyle)
  1187. {
  1188. ASSERT(::GetObjectType(hDC)==OBJ_DC || ::GetObjectType(hDC)==OBJ_MEMDC);
  1189. HPEN hPen = ::CreatePen(nStyle | PS_INSIDEFRAME, nSize, RGB(GetBValue(dwPenColor), GetGValue(dwPenColor), GetRValue(dwPenColor)));
  1190. HPEN hOldPen = (HPEN)::SelectObject(hDC, hPen);
  1191. ::SelectObject(hDC, ::GetStockObject(HOLLOW_BRUSH));
  1192. ::Rectangle(hDC, rc.left, rc.top, rc.right, rc.bottom);
  1193. ::SelectObject(hDC, hOldPen);
  1194. ::DeleteObject(hPen);
  1195. }
  1196. void CRenderEngine::DrawRoundRect(HDC hDC, const RECT& rc, int nSize, int width, int height, DWORD dwPenColor, int nStyle)
  1197. {
  1198. ASSERT(::GetObjectType(hDC)==OBJ_DC || ::GetObjectType(hDC)==OBJ_MEMDC);
  1199. HPEN hPen = ::CreatePen(nStyle | PS_INSIDEFRAME, nSize, RGB(GetBValue(dwPenColor), GetGValue(dwPenColor), GetRValue(dwPenColor)));
  1200. HPEN hOldPen = (HPEN)::SelectObject(hDC, hPen);
  1201. ::SelectObject(hDC, ::GetStockObject(HOLLOW_BRUSH));
  1202. ::RoundRect(hDC, rc.left, rc.top, rc.right, rc.bottom, width, height);
  1203. ::SelectObject(hDC, hOldPen);
  1204. ::DeleteObject(hPen);
  1205. }
  1206. void CRenderEngine::DrawText(HDC hDC, CPaintManagerUI* pManager, RECT& rc, LPCTSTR pstrText, DWORD dwTextColor, int iFont, UINT uStyle)
  1207. {
  1208. ASSERT(::GetObjectType(hDC)==OBJ_DC || ::GetObjectType(hDC)==OBJ_MEMDC);
  1209. if( pstrText == NULL || pManager == NULL ) return;
  1210. CDuiString sText = pstrText;
  1211. CPaintManagerUI::ProcessMultiLanguageTokens(sText);
  1212. pstrText = sText;
  1213. ::SetBkMode(hDC, TRANSPARENT);
  1214. ::SetTextColor(hDC, RGB(GetBValue(dwTextColor), GetGValue(dwTextColor), GetRValue(dwTextColor)));
  1215. HFONT hOldFont = (HFONT)::SelectObject(hDC, pManager->GetFont(iFont));
  1216. ::DrawText(hDC, pstrText, -1, &rc, uStyle | DT_NOPREFIX);
  1217. ::SelectObject(hDC, hOldFont);
  1218. }
  1219. void CRenderEngine::DrawHtmlText(HDC hDC, CPaintManagerUI* pManager, RECT& rc, LPCTSTR pstrText, DWORD dwTextColor, RECT* prcLinks, CDuiString* sLinks, int& nLinkRects, UINT uStyle)
  1220. {
  1221. // 考虑到在xml编辑器中使用<>符号不方便,可以使用{}符号代替
  1222. // 支持标签嵌套(如<l><b>text</b></l>),但是交叉嵌套是应该避免的(如<l><b>text</l></b>)
  1223. // The string formatter supports a kind of "mini-html" that consists of various short tags:
  1224. //
  1225. // Bold: <b>text</b>
  1226. // Color: <c #xxxxxx>text</c> where x = RGB in hex
  1227. // Font: <f x>text</f> where x = font id
  1228. // Italic: <i>text</i>
  1229. // Image: <i x y z> where x = image name and y = imagelist num and z(optional) = imagelist id
  1230. // Link: <a x>text</a> where x(optional) = link content, normal like app:notepad or http:www.xxx.com
  1231. // NewLine <n>
  1232. // Paragraph: <p x>text</p> where x = extra pixels indent in p
  1233. // Raw Text: <r>text</r>
  1234. // Selected: <s>text</s>
  1235. // Underline: <u>text</u>
  1236. // X Indent: <x i> where i = hor indent in pixels
  1237. // Y Indent: <y i> where i = ver indent in pixels
  1238. ASSERT(::GetObjectType(hDC)==OBJ_DC || ::GetObjectType(hDC)==OBJ_MEMDC);
  1239. if( pstrText == NULL || pManager == NULL ) return;
  1240. if( ::IsRectEmpty(&rc) ) return;
  1241. bool bDraw = (uStyle & DT_CALCRECT) == 0;
  1242. CStdPtrArray aFontArray(10);
  1243. CStdPtrArray aColorArray(10);
  1244. CStdPtrArray aPIndentArray(10);
  1245. RECT rcClip = { 0 };
  1246. ::GetClipBox(hDC, &rcClip);
  1247. HRGN hOldRgn = ::CreateRectRgnIndirect(&rcClip);
  1248. HRGN hRgn = ::CreateRectRgnIndirect(&rc);
  1249. if( bDraw ) ::ExtSelectClipRgn(hDC, hRgn, RGN_AND);
  1250. CDuiString sText = pstrText;
  1251. CPaintManagerUI::ProcessMultiLanguageTokens(sText);
  1252. pstrText = sText;
  1253. TEXTMETRIC* pTm = &pManager->GetDefaultFontInfo()->tm;
  1254. HFONT hOldFont = (HFONT) ::SelectObject(hDC, pManager->GetDefaultFontInfo()->hFont);
  1255. ::SetBkMode(hDC, TRANSPARENT);
  1256. ::SetTextColor(hDC, RGB(GetBValue(dwTextColor), GetGValue(dwTextColor), GetRValue(dwTextColor)));
  1257. DWORD dwBkColor = pManager->GetDefaultSelectedBkColor();
  1258. ::SetBkColor(hDC, RGB(GetBValue(dwBkColor), GetGValue(dwBkColor), GetRValue(dwBkColor)));
  1259. // If the drawstyle include a alignment, we'll need to first determine the text-size so
  1260. // we can draw it at the correct position...
  1261. if( ((uStyle & DT_CENTER) != 0 || (uStyle & DT_RIGHT) != 0 || (uStyle & DT_VCENTER) != 0 || (uStyle & DT_BOTTOM) != 0) && (uStyle & DT_CALCRECT) == 0 ) {
  1262. RECT rcText = { 0, 0, 9999, 100 };
  1263. int nLinks = 0;
  1264. DrawHtmlText(hDC, pManager, rcText, pstrText, dwTextColor, NULL, NULL, nLinks, uStyle | DT_CALCRECT);
  1265. if( (uStyle & DT_SINGLELINE) != 0 ){
  1266. if( (uStyle & DT_CENTER) != 0 ) {
  1267. rc.left = rc.left + ((rc.right - rc.left) / 2) - ((rcText.right - rcText.left) / 2);
  1268. rc.right = rc.left + (rcText.right - rcText.left);
  1269. }
  1270. if( (uStyle & DT_RIGHT) != 0 ) {
  1271. rc.left = rc.right - (rcText.right - rcText.left);
  1272. }
  1273. }
  1274. if( (uStyle & DT_VCENTER) != 0 ) {
  1275. rc.top = rc.top + ((rc.bottom - rc.top) / 2) - ((rcText.bottom - rcText.top) / 2);
  1276. rc.bottom = rc.top + (rcText.bottom - rcText.top);
  1277. }
  1278. if( (uStyle & DT_BOTTOM) != 0 ) {
  1279. rc.top = rc.bottom - (rcText.bottom - rcText.top);
  1280. }
  1281. }
  1282. bool bHoverLink = false;
  1283. CDuiString sHoverLink;
  1284. POINT ptMouse = pManager->GetMousePos();
  1285. for( int i = 0; !bHoverLink && i < nLinkRects; i++ ) {
  1286. if( ::PtInRect(prcLinks + i, ptMouse) ) {
  1287. sHoverLink = *(CDuiString*)(sLinks + i);
  1288. bHoverLink = true;
  1289. }
  1290. }
  1291. POINT pt = { rc.left, rc.top };
  1292. int iLinkIndex = 0;
  1293. int cyLine = pTm->tmHeight + pTm->tmExternalLeading + (int)aPIndentArray.GetAt(aPIndentArray.GetSize() - 1);
  1294. int cyMinHeight = 0;
  1295. int cxMaxWidth = 0;
  1296. POINT ptLinkStart = { 0 };
  1297. bool bLineEnd = false;
  1298. bool bInRaw = false;
  1299. bool bInLink = false;
  1300. bool bInSelected = false;
  1301. int iLineLinkIndex = 0;
  1302. // 排版习惯是图文底部对齐,所以每行绘制都要分两步,先计算高度,再绘制
  1303. CStdPtrArray aLineFontArray;
  1304. CStdPtrArray aLineColorArray;
  1305. CStdPtrArray aLinePIndentArray;
  1306. LPCTSTR pstrLineBegin = pstrText;
  1307. bool bLineInRaw = false;
  1308. bool bLineInLink = false;
  1309. bool bLineInSelected = false;
  1310. int cyLineHeight = 0;
  1311. bool bLineDraw = false; // 行的第二阶段:绘制
  1312. while( *pstrText != _T('\0') ) {
  1313. if( pt.x >= rc.right || *pstrText == _T('\n') || bLineEnd ) {
  1314. if( *pstrText == _T('\n') ) pstrText++;
  1315. if( bLineEnd ) bLineEnd = false;
  1316. if( !bLineDraw ) {
  1317. if( bInLink && iLinkIndex < nLinkRects ) {
  1318. ::SetRect(&prcLinks[iLinkIndex++], ptLinkStart.x, ptLinkStart.y, MIN(pt.x, rc.right), pt.y + cyLine);
  1319. CDuiString *pStr1 = (CDuiString*)(sLinks + iLinkIndex - 1);
  1320. CDuiString *pStr2 = (CDuiString*)(sLinks + iLinkIndex);
  1321. *pStr2 = *pStr1;
  1322. }
  1323. for( int i = iLineLinkIndex; i < iLinkIndex; i++ ) {
  1324. prcLinks[i].bottom = pt.y + cyLine;
  1325. }
  1326. if( bDraw ) {
  1327. bInLink = bLineInLink;
  1328. iLinkIndex = iLineLinkIndex;
  1329. }
  1330. }
  1331. else {
  1332. if( bInLink && iLinkIndex < nLinkRects ) iLinkIndex++;
  1333. bLineInLink = bInLink;
  1334. iLineLinkIndex = iLinkIndex;
  1335. }
  1336. if( (uStyle & DT_SINGLELINE) != 0 && (!bDraw || bLineDraw) ) break;
  1337. if( bDraw ) bLineDraw = !bLineDraw; // !
  1338. pt.x = rc.left;
  1339. if( !bLineDraw ) pt.y += cyLine;
  1340. if( pt.y > rc.bottom && bDraw ) break;
  1341. ptLinkStart = pt;
  1342. cyLine = pTm->tmHeight + pTm->tmExternalLeading + (int)aPIndentArray.GetAt(aPIndentArray.GetSize() - 1);
  1343. if( pt.x >= rc.right ) break;
  1344. }
  1345. else if( !bInRaw && ( *pstrText == _T('<') || *pstrText == _T('{') )
  1346. && ( pstrText[1] >= _T('a') && pstrText[1] <= _T('z') )
  1347. && ( pstrText[2] == _T(' ') || pstrText[2] == _T('>') || pstrText[2] == _T('}') ) ) {
  1348. pstrText++;
  1349. LPCTSTR pstrNextStart = NULL;
  1350. switch( *pstrText ) {
  1351. case _T('a'): // Link
  1352. {
  1353. pstrText++;
  1354. while( *pstrText > _T('\0') && *pstrText <= _T(' ') ) pstrText = ::CharNext(pstrText);
  1355. if( iLinkIndex < nLinkRects && !bLineDraw ) {
  1356. CDuiString *pStr = (CDuiString*)(sLinks + iLinkIndex);
  1357. pStr->Empty();
  1358. while( *pstrText != _T('\0') && *pstrText != _T('>') && *pstrText != _T('}') ) {
  1359. LPCTSTR pstrTemp = ::CharNext(pstrText);
  1360. while( pstrText < pstrTemp) {
  1361. *pStr += *pstrText++;
  1362. }
  1363. }
  1364. }
  1365. DWORD clrColor = pManager->GetDefaultLinkFontColor();
  1366. if( bHoverLink && iLinkIndex < nLinkRects ) {
  1367. CDuiString *pStr = (CDuiString*)(sLinks + iLinkIndex);
  1368. if( sHoverLink == *pStr ) clrColor = pManager->GetDefaultLinkHoverFontColor();
  1369. }
  1370. //else if( prcLinks == NULL ) {
  1371. // if( ::PtInRect(&rc, ptMouse) )
  1372. // clrColor = pManager->GetDefaultLinkHoverFontColor();
  1373. //}
  1374. aColorArray.Add((LPVOID)clrColor);
  1375. ::SetTextColor(hDC, RGB(GetBValue(clrColor), GetGValue(clrColor), GetRValue(clrColor)));
  1376. TFontInfo* pFontInfo = pManager->GetDefaultFontInfo();
  1377. if( aFontArray.GetSize() > 0 ) pFontInfo = (TFontInfo*)aFontArray.GetAt(aFontArray.GetSize() - 1);
  1378. if( pFontInfo->bUnderline == false ) {
  1379. HFONT hFont = pManager->GetFont(pFontInfo->sFontName, pFontInfo->iSize, pFontInfo->bBold, true, pFontInfo->bItalic);
  1380. if( hFont == NULL ) {
  1381. hFont = pManager->AddFont(g_iFontID, pFontInfo->sFontName, pFontInfo->iSize, pFontInfo->bBold, true, pFontInfo->bItalic);
  1382. g_iFontID += 1;
  1383. }
  1384. pFontInfo = pManager->GetFontInfo(hFont);
  1385. aFontArray.Add(pFontInfo);
  1386. pTm = &pFontInfo->tm;
  1387. ::SelectObject(hDC, pFontInfo->hFont);
  1388. cyLine = MAX(cyLine, pTm->tmHeight + pTm->tmExternalLeading + (int)aPIndentArray.GetAt(aPIndentArray.GetSize() - 1));
  1389. }
  1390. ptLinkStart = pt;
  1391. bInLink = true;
  1392. }
  1393. break;
  1394. case _T('b'): // Bold
  1395. {
  1396. pstrText++;
  1397. TFontInfo* pFontInfo = pManager->GetDefaultFontInfo();
  1398. if( aFontArray.GetSize() > 0 ) pFontInfo = (TFontInfo*)aFontArray.GetAt(aFontArray.GetSize() - 1);
  1399. if( pFontInfo->bBold == false ) {
  1400. HFONT hFont = pManager->GetFont(pFontInfo->sFontName, pFontInfo->iSize, true, pFontInfo->bUnderline, pFontInfo->bItalic);
  1401. if( hFont == NULL ) {
  1402. hFont = pManager->AddFont(g_iFontID, pFontInfo->sFontName, pFontInfo->iSize, true, pFontInfo->bUnderline, pFontInfo->bItalic);
  1403. g_iFontID += 1;
  1404. }
  1405. pFontInfo = pManager->GetFontInfo(hFont);
  1406. aFontArray.Add(pFontInfo);
  1407. pTm = &pFontInfo->tm;
  1408. ::SelectObject(hDC, pFontInfo->hFont);
  1409. cyLine = MAX(cyLine, pTm->tmHeight + pTm->tmExternalLeading + (int)aPIndentArray.GetAt(aPIndentArray.GetSize() - 1));
  1410. }
  1411. }
  1412. break;
  1413. case _T('c'): // Color
  1414. {
  1415. pstrText++;
  1416. while( *pstrText > _T('\0') && *pstrText <= _T(' ') ) pstrText = ::CharNext(pstrText);
  1417. if( *pstrText == _T('#')) pstrText++;
  1418. DWORD clrColor = _tcstol(pstrText, const_cast<LPTSTR*>(&pstrText), 16);
  1419. aColorArray.Add((LPVOID)clrColor);
  1420. ::SetTextColor(hDC, RGB(GetBValue(clrColor), GetGValue(clrColor), GetRValue(clrColor)));
  1421. }
  1422. break;
  1423. case _T('f'): // Font
  1424. {
  1425. pstrText++;
  1426. while( *pstrText > _T('\0') && *pstrText <= _T(' ') ) pstrText = ::CharNext(pstrText);
  1427. LPCTSTR pstrTemp = pstrText;
  1428. int iFont = (int) _tcstol(pstrText, const_cast<LPTSTR*>(&pstrText), 10);
  1429. //if( isdigit(*pstrText) ) { // debug版本会引起异常
  1430. if( pstrTemp != pstrText ) {
  1431. TFontInfo* pFontInfo = pManager->GetFontInfo(iFont);
  1432. aFontArray.Add(pFontInfo);
  1433. pTm = &pFontInfo->tm;
  1434. ::SelectObject(hDC, pFontInfo->hFont);
  1435. }
  1436. else {
  1437. CDuiString sFontName;
  1438. int iFontSize = 10;
  1439. CDuiString sFontAttr;
  1440. bool bBold = false;
  1441. bool bUnderline = false;
  1442. bool bItalic = false;
  1443. while( *pstrText != _T('\0') && *pstrText != _T('>') && *pstrText != _T('}') && *pstrText != _T(' ') ) {
  1444. pstrTemp = ::CharNext(pstrText);
  1445. while( pstrText < pstrTemp) {
  1446. sFontName += *pstrText++;
  1447. }
  1448. }
  1449. while( *pstrText > _T('\0') && *pstrText <= _T(' ') ) pstrText = ::CharNext(pstrText);
  1450. if( isdigit(*pstrText) ) {
  1451. iFontSize = (int) _tcstol(pstrText, const_cast<LPTSTR*>(&pstrText), 10);
  1452. }
  1453. while( *pstrText > _T('\0') && *pstrText <= _T(' ') ) pstrText = ::CharNext(pstrText);
  1454. while( *pstrText != _T('\0') && *pstrText != _T('>') && *pstrText != _T('}') ) {
  1455. pstrTemp = ::CharNext(pstrText);
  1456. while( pstrText < pstrTemp) {
  1457. sFontAttr += *pstrText++;
  1458. }
  1459. }
  1460. sFontAttr.MakeLower();
  1461. if( sFontAttr.Find(_T("bold")) >= 0 ) bBold = true;
  1462. if( sFontAttr.Find(_T("underline")) >= 0 ) bUnderline = true;
  1463. if( sFontAttr.Find(_T("italic")) >= 0 ) bItalic = true;
  1464. HFONT hFont = pManager->GetFont(sFontName, iFontSize, bBold, bUnderline, bItalic);
  1465. if( hFont == NULL ) {
  1466. hFont = pManager->AddFont(g_iFontID, sFontName, iFontSize, bBold, bUnderline, bItalic);
  1467. g_iFontID += 1;
  1468. }
  1469. TFontInfo* pFontInfo = pManager->GetFontInfo(hFont);
  1470. aFontArray.Add(pFontInfo);
  1471. pTm = &pFontInfo->tm;
  1472. ::SelectObject(hDC, pFontInfo->hFont);
  1473. }
  1474. cyLine = MAX(cyLine, pTm->tmHeight + pTm->tmExternalLeading + (int)aPIndentArray.GetAt(aPIndentArray.GetSize() - 1));
  1475. }
  1476. break;
  1477. case _T('i'): // Italic or Image
  1478. {
  1479. pstrNextStart = pstrText - 1;
  1480. pstrText++;
  1481. CDuiString sImageString = pstrText;
  1482. int iWidth = 0;
  1483. int iHeight = 0;
  1484. while( *pstrText > _T('\0') && *pstrText <= _T(' ') ) pstrText = ::CharNext(pstrText);
  1485. const TImageInfo* pImageInfo = NULL;
  1486. CDuiString sName;
  1487. while( *pstrText != _T('\0') && *pstrText != _T('>') && *pstrText != _T('}') && *pstrText != _T(' ') ) {
  1488. LPCTSTR pstrTemp = ::CharNext(pstrText);
  1489. while( pstrText < pstrTemp) {
  1490. sName += *pstrText++;
  1491. }
  1492. }
  1493. if( sName.IsEmpty() ) { // Italic
  1494. pstrNextStart = NULL;
  1495. TFontInfo* pFontInfo = pManager->GetDefaultFontInfo();
  1496. if( aFontArray.GetSize() > 0 ) pFontInfo = (TFontInfo*)aFontArray.GetAt(aFontArray.GetSize() - 1);
  1497. if( pFontInfo->bItalic == false ) {
  1498. HFONT hFont = pManager->GetFont(pFontInfo->sFontName, pFontInfo->iSize, pFontInfo->bBold, pFontInfo->bUnderline, true);
  1499. if( hFont == NULL ) {
  1500. hFont = pManager->AddFont(g_iFontID, pFontInfo->sFontName, pFontInfo->iSize, pFontInfo->bBold, pFontInfo->bUnderline, true);
  1501. g_iFontID += 1;
  1502. }
  1503. pFontInfo = pManager->GetFontInfo(hFont);
  1504. aFontArray.Add(pFontInfo);
  1505. pTm = &pFontInfo->tm;
  1506. ::SelectObject(hDC, pFontInfo->hFont);
  1507. cyLine = MAX(cyLine, pTm->tmHeight + pTm->tmExternalLeading + (int)aPIndentArray.GetAt(aPIndentArray.GetSize() - 1));
  1508. }
  1509. }
  1510. else {
  1511. while( *pstrText > _T('\0') && *pstrText <= _T(' ') ) pstrText = ::CharNext(pstrText);
  1512. int iImageListNum = (int) _tcstol(pstrText, const_cast<LPTSTR*>(&pstrText), 10);
  1513. if( iImageListNum <= 0 ) iImageListNum = 1;
  1514. while( *pstrText > _T('\0') && *pstrText <= _T(' ') ) pstrText = ::CharNext(pstrText);
  1515. int iImageListIndex = (int) _tcstol(pstrText, const_cast<LPTSTR*>(&pstrText), 10);
  1516. if( iImageListIndex < 0 || iImageListIndex >= iImageListNum ) iImageListIndex = 0;
  1517. if( _tcsstr(sImageString.GetData(), _T("file=\'")) != NULL || _tcsstr(sImageString.GetData(), _T("res=\'")) != NULL ) {
  1518. CDuiString sImageResType;
  1519. CDuiString sImageName;
  1520. LPCTSTR pStrImage = sImageString.GetData();
  1521. CDuiString sItem;
  1522. CDuiString sValue;
  1523. while( *pStrImage != _T('\0') ) {
  1524. sItem.Empty();
  1525. sValue.Empty();
  1526. while( *pStrImage > _T('\0') && *pStrImage <= _T(' ') ) pStrImage = ::CharNext(pStrImage);
  1527. while( *pStrImage != _T('\0') && *pStrImage != _T('=') && *pStrImage > _T(' ') ) {
  1528. LPTSTR pstrTemp = ::CharNext(pStrImage);
  1529. while( pStrImage < pstrTemp) {
  1530. sItem += *pStrImage++;
  1531. }
  1532. }
  1533. while( *pStrImage > _T('\0') && *pStrImage <= _T(' ') ) pStrImage = ::CharNext(pStrImage);
  1534. if( *pStrImage++ != _T('=') ) break;
  1535. while( *pStrImage > _T('\0') && *pStrImage <= _T(' ') ) pStrImage = ::CharNext(pStrImage);
  1536. if( *pStrImage++ != _T('\'') ) break;
  1537. while( *pStrImage != _T('\0') && *pStrImage != _T('\'') ) {
  1538. LPTSTR pstrTemp = ::CharNext(pStrImage);
  1539. while( pStrImage < pstrTemp) {
  1540. sValue += *pStrImage++;
  1541. }
  1542. }
  1543. if( *pStrImage++ != _T('\'') ) break;
  1544. if( !sValue.IsEmpty() ) {
  1545. if( sItem == _T("file") || sItem == _T("res") ) {
  1546. sImageName = sValue;
  1547. }
  1548. else if( sItem == _T("restype") ) {
  1549. sImageResType = sValue;
  1550. }
  1551. }
  1552. if( *pStrImage++ != _T(' ') ) break;
  1553. }
  1554. pImageInfo = pManager->GetImageEx((LPCTSTR)sImageName, sImageResType);
  1555. }
  1556. else
  1557. pImageInfo = pManager->GetImageEx((LPCTSTR)sName);
  1558. if( pImageInfo ) {
  1559. iWidth = pImageInfo->nX;
  1560. iHeight = pImageInfo->nY;
  1561. if( iImageListNum > 1 ) iWidth /= iImageListNum;
  1562. if( pt.x + iWidth > rc.right && pt.x > rc.left && (uStyle & DT_SINGLELINE) == 0 ) {
  1563. bLineEnd = true;
  1564. }
  1565. else {
  1566. pstrNextStart = NULL;
  1567. if( bDraw && bLineDraw ) {
  1568. CDuiRect rcImage(pt.x, pt.y + cyLineHeight - iHeight, pt.x + iWidth, pt.y + cyLineHeight);
  1569. if( iHeight < cyLineHeight ) {
  1570. rcImage.bottom -= (cyLineHeight - iHeight) / 2;
  1571. rcImage.top = rcImage.bottom - iHeight;
  1572. }
  1573. CDuiRect rcBmpPart(0, 0, iWidth, iHeight);
  1574. rcBmpPart.left = iWidth * iImageListIndex;
  1575. rcBmpPart.right = iWidth * (iImageListIndex + 1);
  1576. CDuiRect rcCorner(0, 0, 0, 0);
  1577. DrawImage(hDC, pImageInfo->hBitmap, rcImage, rcImage, rcBmpPart, rcCorner, \
  1578. pImageInfo->bAlpha, 255);
  1579. }
  1580. cyLine = MAX(iHeight, cyLine);
  1581. pt.x += iWidth;
  1582. cyMinHeight = pt.y + iHeight;
  1583. cxMaxWidth = MAX(cxMaxWidth, pt.x);
  1584. }
  1585. }
  1586. else pstrNextStart = NULL;
  1587. }
  1588. }
  1589. break;
  1590. case _T('n'): // Newline
  1591. {
  1592. pstrText++;
  1593. if( (uStyle & DT_SINGLELINE) != 0 ) break;
  1594. bLineEnd = true;
  1595. }
  1596. break;
  1597. case _T('p'): // Paragraph
  1598. {
  1599. pstrText++;
  1600. if( pt.x > rc.left ) bLineEnd = true;
  1601. while( *pstrText > _T('\0') && *pstrText <= _T(' ') ) pstrText = ::CharNext(pstrText);
  1602. int cyLineExtra = (int)_tcstol(pstrText, const_cast<LPTSTR*>(&pstrText), 10);
  1603. aPIndentArray.Add((LPVOID)cyLineExtra);
  1604. cyLine = MAX(cyLine, pTm->tmHeight + pTm->tmExternalLeading + cyLineExtra);
  1605. }
  1606. break;
  1607. case _T('r'): // Raw Text
  1608. {
  1609. pstrText++;
  1610. bInRaw = true;
  1611. }
  1612. break;
  1613. case _T('s'): // Selected text background color
  1614. {
  1615. pstrText++;
  1616. bInSelected = !bInSelected;
  1617. if( bDraw && bLineDraw ) {
  1618. if( bInSelected ) ::SetBkMode(hDC, OPAQUE);
  1619. else ::SetBkMode(hDC, TRANSPARENT);
  1620. }
  1621. }
  1622. break;
  1623. case _T('u'): // Underline text
  1624. {
  1625. pstrText++;
  1626. TFontInfo* pFontInfo = pManager->GetDefaultFontInfo();
  1627. if( aFontArray.GetSize() > 0 ) pFontInfo = (TFontInfo*)aFontArray.GetAt(aFontArray.GetSize() - 1);
  1628. if( pFontInfo->bUnderline == false ) {
  1629. HFONT hFont = pManager->GetFont(pFontInfo->sFontName, pFontInfo->iSize, pFontInfo->bBold, true, pFontInfo->bItalic);
  1630. if( hFont == NULL ) {
  1631. hFont = pManager->AddFont(g_iFontID, pFontInfo->sFontName, pFontInfo->iSize, pFontInfo->bBold, true, pFontInfo->bItalic);
  1632. g_iFontID += 1;
  1633. }
  1634. pFontInfo = pManager->GetFontInfo(hFont);
  1635. aFontArray.Add(pFontInfo);
  1636. pTm = &pFontInfo->tm;
  1637. ::SelectObject(hDC, pFontInfo->hFont);
  1638. cyLine = MAX(cyLine, pTm->tmHeight + pTm->tmExternalLeading + (int)aPIndentArray.GetAt(aPIndentArray.GetSize() - 1));
  1639. }
  1640. }
  1641. break;
  1642. case _T('x'): // X Indent
  1643. {
  1644. pstrText++;
  1645. while( *pstrText > _T('\0') && *pstrText <= _T(' ') ) pstrText = ::CharNext(pstrText);
  1646. int iWidth = (int) _tcstol(pstrText, const_cast<LPTSTR*>(&pstrText), 10);
  1647. pt.x += iWidth;
  1648. cxMaxWidth = MAX(cxMaxWidth, pt.x);
  1649. }
  1650. break;
  1651. case _T('y'): // Y Indent
  1652. {
  1653. pstrText++;
  1654. while( *pstrText > _T('\0') && *pstrText <= _T(' ') ) pstrText = ::CharNext(pstrText);
  1655. cyLine = (int) _tcstol(pstrText, const_cast<LPTSTR*>(&pstrText), 10);
  1656. }
  1657. break;
  1658. }
  1659. if( pstrNextStart != NULL ) pstrText = pstrNextStart;
  1660. else {
  1661. while( *pstrText != _T('\0') && *pstrText != _T('>') && *pstrText != _T('}') ) pstrText = ::CharNext(pstrText);
  1662. pstrText = ::CharNext(pstrText);
  1663. }
  1664. }
  1665. else if( !bInRaw && ( *pstrText == _T('<') || *pstrText == _T('{') ) && pstrText[1] == _T('/') )
  1666. {
  1667. pstrText++;
  1668. pstrText++;
  1669. switch( *pstrText )
  1670. {
  1671. case _T('c'):
  1672. {
  1673. pstrText++;
  1674. aColorArray.Remove(aColorArray.GetSize() - 1);
  1675. DWORD clrColor = dwTextColor;
  1676. if( aColorArray.GetSize() > 0 ) clrColor = (int)aColorArray.GetAt(aColorArray.GetSize() - 1);
  1677. ::SetTextColor(hDC, RGB(GetBValue(clrColor), GetGValue(clrColor), GetRValue(clrColor)));
  1678. }
  1679. break;
  1680. case _T('p'):
  1681. pstrText++;
  1682. if( pt.x > rc.left ) bLineEnd = true;
  1683. aPIndentArray.Remove(aPIndentArray.GetSize() - 1);
  1684. cyLine = MAX(cyLine, pTm->tmHeight + pTm->tmExternalLeading + (int)aPIndentArray.GetAt(aPIndentArray.GetSize() - 1));
  1685. break;
  1686. case _T('s'):
  1687. {
  1688. pstrText++;
  1689. bInSelected = !bInSelected;
  1690. if( bDraw && bLineDraw ) {
  1691. if( bInSelected ) ::SetBkMode(hDC, OPAQUE);
  1692. else ::SetBkMode(hDC, TRANSPARENT);
  1693. }
  1694. }
  1695. break;
  1696. case _T('a'):
  1697. {
  1698. if( iLinkIndex < nLinkRects ) {
  1699. if( !bLineDraw ) ::SetRect(&prcLinks[iLinkIndex], ptLinkStart.x, ptLinkStart.y, MIN(pt.x, rc.right), pt.y + pTm->tmHeight + pTm->tmExternalLeading);
  1700. iLinkIndex++;
  1701. }
  1702. aColorArray.Remove(aColorArray.GetSize() - 1);
  1703. DWORD clrColor = dwTextColor;
  1704. if( aColorArray.GetSize() > 0 ) clrColor = (int)aColorArray.GetAt(aColorArray.GetSize() - 1);
  1705. ::SetTextColor(hDC, RGB(GetBValue(clrColor), GetGValue(clrColor), GetRValue(clrColor)));
  1706. bInLink = false;
  1707. }
  1708. case _T('b'):
  1709. case _T('f'):
  1710. case _T('i'):
  1711. case _T('u'):
  1712. {
  1713. pstrText++;
  1714. aFontArray.Remove(aFontArray.GetSize() - 1);
  1715. TFontInfo* pFontInfo = (TFontInfo*)aFontArray.GetAt(aFontArray.GetSize() - 1);
  1716. if( pFontInfo == NULL ) pFontInfo = pManager->GetDefaultFontInfo();
  1717. if( pTm->tmItalic && pFontInfo->bItalic == false ) {
  1718. ABC abc;
  1719. ::GetCharABCWidths(hDC, _T(' '), _T(' '), &abc);
  1720. pt.x += abc.abcC / 2; // 简单修正一下斜体混排的问题, 正确做法应该是http://support.microsoft.com/kb/244798/en-us
  1721. }
  1722. pTm = &pFontInfo->tm;
  1723. ::SelectObject(hDC, pFontInfo->hFont);
  1724. cyLine = MAX(cyLine, pTm->tmHeight + pTm->tmExternalLeading + (int)aPIndentArray.GetAt(aPIndentArray.GetSize() - 1));
  1725. }
  1726. break;
  1727. }
  1728. while( *pstrText != _T('\0') && *pstrText != _T('>') && *pstrText != _T('}') ) pstrText = ::CharNext(pstrText);
  1729. pstrText = ::CharNext(pstrText);
  1730. }
  1731. else if( !bInRaw && *pstrText == _T('<') && pstrText[2] == _T('>') && (pstrText[1] == _T('{') || pstrText[1] == _T('}')) )
  1732. {
  1733. SIZE szSpace = { 0 };
  1734. ::GetTextExtentPoint32(hDC, &pstrText[1], 1, &szSpace);
  1735. if( bDraw && bLineDraw ) ::TextOut(hDC, pt.x, pt.y + cyLineHeight - pTm->tmHeight - pTm->tmExternalLeading, &pstrText[1], 1);
  1736. pt.x += szSpace.cx;
  1737. cxMaxWidth = MAX(cxMaxWidth, pt.x);
  1738. pstrText++;pstrText++;pstrText++;
  1739. }
  1740. else if( !bInRaw && *pstrText == _T('{') && pstrText[2] == _T('}') && (pstrText[1] == _T('<') || pstrText[1] == _T('>')) )
  1741. {
  1742. SIZE szSpace = { 0 };
  1743. ::GetTextExtentPoint32(hDC, &pstrText[1], 1, &szSpace);
  1744. if( bDraw && bLineDraw ) ::TextOut(hDC, pt.x, pt.y + cyLineHeight - pTm->tmHeight - pTm->tmExternalLeading, &pstrText[1], 1);
  1745. pt.x += szSpace.cx;
  1746. cxMaxWidth = MAX(cxMaxWidth, pt.x);
  1747. pstrText++;pstrText++;pstrText++;
  1748. }
  1749. else if( !bInRaw && *pstrText == _T(' ') )
  1750. {
  1751. SIZE szSpace = { 0 };
  1752. ::GetTextExtentPoint32(hDC, _T(" "), 1, &szSpace);
  1753. // Still need to paint the space because the font might have
  1754. // underline formatting.
  1755. if( bDraw && bLineDraw ) ::TextOut(hDC, pt.x, pt.y + cyLineHeight - pTm->tmHeight - pTm->tmExternalLeading, _T(" "), 1);
  1756. pt.x += szSpace.cx;
  1757. cxMaxWidth = MAX(cxMaxWidth, pt.x);
  1758. pstrText++;
  1759. }
  1760. else
  1761. {
  1762. POINT ptPos = pt;
  1763. int cchChars = 0;
  1764. int cchSize = 0;
  1765. int cchLastGoodWord = 0;
  1766. int cchLastGoodSize = 0;
  1767. LPCTSTR p = pstrText;
  1768. LPCTSTR pstrNext;
  1769. SIZE szText = { 0 };
  1770. if( !bInRaw && *p == _T('<') || *p == _T('{') ) p++, cchChars++, cchSize++;
  1771. while( *p != _T('\0') && *p != _T('\n') ) {
  1772. // This part makes sure that we're word-wrapping if needed or providing support
  1773. // for DT_END_ELLIPSIS. Unfortunately the GetTextExtentPoint32() call is pretty
  1774. // slow when repeated so often.
  1775. // TODO: Rewrite and use GetTextExtentExPoint() instead!
  1776. if( bInRaw ) {
  1777. if( ( *p == _T('<') || *p == _T('{') ) && p[1] == _T('/')
  1778. && p[2] == _T('r') && ( p[3] == _T('>') || p[3] == _T('}') ) ) {
  1779. p += 4;
  1780. bInRaw = false;
  1781. break;
  1782. }
  1783. }
  1784. else {
  1785. if( *p == _T('<') || *p == _T('{') ) break;
  1786. }
  1787. pstrNext = ::CharNext(p);
  1788. cchChars++;
  1789. cchSize += (int)(pstrNext - p);
  1790. szText.cx = cchChars * pTm->tmMaxCharWidth;
  1791. if( pt.x + szText.cx >= rc.right ) {
  1792. ::GetTextExtentPoint32(hDC, pstrText, cchSize, &szText);
  1793. }
  1794. if( pt.x + szText.cx > rc.right ) {
  1795. if( pt.x + szText.cx > rc.right && pt.x != rc.left) {
  1796. cchChars--;
  1797. cchSize -= (int)(pstrNext - p);
  1798. }
  1799. if( (uStyle & DT_WORDBREAK) != 0 && cchLastGoodWord > 0 ) {
  1800. cchChars = cchLastGoodWord;
  1801. cchSize = cchLastGoodSize;
  1802. }
  1803. if( (uStyle & DT_END_ELLIPSIS) != 0 && cchChars > 0 ) {
  1804. cchChars -= 1;
  1805. LPCTSTR pstrPrev = ::CharPrev(pstrText, p);
  1806. if( cchChars > 0 ) {
  1807. cchChars -= 1;
  1808. pstrPrev = ::CharPrev(pstrText, pstrPrev);
  1809. cchSize -= (int)(p - pstrPrev);
  1810. }
  1811. else
  1812. cchSize -= (int)(p - pstrPrev);
  1813. pt.x = rc.right;
  1814. }
  1815. bLineEnd = true;
  1816. cxMaxWidth = MAX(cxMaxWidth, pt.x);
  1817. break;
  1818. }
  1819. if (!( ( p[0] >= _T('a') && p[0] <= _T('z') ) || ( p[0] >= _T('A') && p[0] <= _T('Z') ) )) {
  1820. cchLastGoodWord = cchChars;
  1821. cchLastGoodSize = cchSize;
  1822. }
  1823. if( *p == _T(' ') ) {
  1824. cchLastGoodWord = cchChars;
  1825. cchLastGoodSize = cchSize;
  1826. }
  1827. p = ::CharNext(p);
  1828. }
  1829. ::GetTextExtentPoint32(hDC, pstrText, cchSize, &szText);
  1830. if( bDraw && bLineDraw ) {
  1831. if( (uStyle & DT_SINGLELINE) == 0 && (uStyle & DT_CENTER) != 0 ) {
  1832. ptPos.x += (rc.right - rc.left - szText.cx)/2;
  1833. }
  1834. else if( (uStyle & DT_SINGLELINE) == 0 && (uStyle & DT_RIGHT) != 0) {
  1835. ptPos.x += (rc.right - rc.left - szText.cx);
  1836. }
  1837. ::TextOut(hDC, ptPos.x, ptPos.y + cyLineHeight - pTm->tmHeight - pTm->tmExternalLeading, pstrText, cchSize);
  1838. if( pt.x >= rc.right && (uStyle & DT_END_ELLIPSIS) != 0 )
  1839. ::TextOut(hDC, ptPos.x + szText.cx, ptPos.y, _T("..."), 3);
  1840. }
  1841. pt.x += szText.cx;
  1842. cxMaxWidth = MAX(cxMaxWidth, pt.x);
  1843. pstrText += cchSize;
  1844. }
  1845. if( pt.x >= rc.right || *pstrText == _T('\n') || *pstrText == _T('\0') ) bLineEnd = true;
  1846. if( bDraw && bLineEnd ) {
  1847. if( !bLineDraw ) {
  1848. aFontArray.Resize(aLineFontArray.GetSize());
  1849. ::CopyMemory(aFontArray.GetData(), aLineFontArray.GetData(), aLineFontArray.GetSize() * sizeof(LPVOID));
  1850. aColorArray.Resize(aLineColorArray.GetSize());
  1851. ::CopyMemory(aColorArray.GetData(), aLineColorArray.GetData(), aLineColorArray.GetSize() * sizeof(LPVOID));
  1852. aPIndentArray.Resize(aLinePIndentArray.GetSize());
  1853. ::CopyMemory(aPIndentArray.GetData(), aLinePIndentArray.GetData(), aLinePIndentArray.GetSize() * sizeof(LPVOID));
  1854. cyLineHeight = cyLine;
  1855. pstrText = pstrLineBegin;
  1856. bInRaw = bLineInRaw;
  1857. bInSelected = bLineInSelected;
  1858. DWORD clrColor = dwTextColor;
  1859. if( aColorArray.GetSize() > 0 ) clrColor = (int)aColorArray.GetAt(aColorArray.GetSize() - 1);
  1860. ::SetTextColor(hDC, RGB(GetBValue(clrColor), GetGValue(clrColor), GetRValue(clrColor)));
  1861. TFontInfo* pFontInfo = (TFontInfo*)aFontArray.GetAt(aFontArray.GetSize() - 1);
  1862. if( pFontInfo == NULL ) pFontInfo = pManager->GetDefaultFontInfo();
  1863. pTm = &pFontInfo->tm;
  1864. ::SelectObject(hDC, pFontInfo->hFont);
  1865. if( bInSelected ) ::SetBkMode(hDC, OPAQUE);
  1866. }
  1867. else {
  1868. aLineFontArray.Resize(aFontArray.GetSize());
  1869. ::CopyMemory(aLineFontArray.GetData(), aFontArray.GetData(), aFontArray.GetSize() * sizeof(LPVOID));
  1870. aLineColorArray.Resize(aColorArray.GetSize());
  1871. ::CopyMemory(aLineColorArray.GetData(), aColorArray.GetData(), aColorArray.GetSize() * sizeof(LPVOID));
  1872. aLinePIndentArray.Resize(aPIndentArray.GetSize());
  1873. ::CopyMemory(aLinePIndentArray.GetData(), aPIndentArray.GetData(), aPIndentArray.GetSize() * sizeof(LPVOID));
  1874. pstrLineBegin = pstrText;
  1875. bLineInSelected = bInSelected;
  1876. bLineInRaw = bInRaw;
  1877. }
  1878. }
  1879. ASSERT(iLinkIndex<=nLinkRects);
  1880. }
  1881. nLinkRects = iLinkIndex;
  1882. // Return size of text when requested
  1883. if( (uStyle & DT_CALCRECT) != 0 ) {
  1884. rc.bottom = MAX(cyMinHeight, pt.y + cyLine);
  1885. rc.right = MIN(rc.right, cxMaxWidth);
  1886. }
  1887. if( bDraw ) ::SelectClipRgn(hDC, hOldRgn);
  1888. ::DeleteObject(hOldRgn);
  1889. ::DeleteObject(hRgn);
  1890. ::SelectObject(hDC, hOldFont);
  1891. }
  1892. HBITMAP CRenderEngine::GenerateBitmap(CPaintManagerUI* pManager, CControlUI* pControl, RECT rc)
  1893. {
  1894. int cx = rc.right - rc.left;
  1895. int cy = rc.bottom - rc.top;
  1896. HDC hPaintDC = ::CreateCompatibleDC(pManager->GetPaintDC());
  1897. HBITMAP hPaintBitmap = ::CreateCompatibleBitmap(pManager->GetPaintDC(), rc.right, rc.bottom);
  1898. ASSERT(hPaintDC);
  1899. ASSERT(hPaintBitmap);
  1900. HBITMAP hOldPaintBitmap = (HBITMAP) ::SelectObject(hPaintDC, hPaintBitmap);
  1901. pControl->Paint(hPaintDC, rc);
  1902. BITMAPINFO bmi = { 0 };
  1903. bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
  1904. bmi.bmiHeader.biWidth = cx;
  1905. bmi.bmiHeader.biHeight = cy;
  1906. bmi.bmiHeader.biPlanes = 1;
  1907. bmi.bmiHeader.biBitCount = 32;
  1908. bmi.bmiHeader.biCompression = BI_RGB;
  1909. bmi.bmiHeader.biSizeImage = cx * cy * sizeof(DWORD);
  1910. LPDWORD pDest = NULL;
  1911. HDC hCloneDC = ::CreateCompatibleDC(pManager->GetPaintDC());
  1912. HBITMAP hBitmap = ::CreateDIBSection(pManager->GetPaintDC(), &bmi, DIB_RGB_COLORS, (LPVOID*) &pDest, NULL, 0);
  1913. ASSERT(hCloneDC);
  1914. ASSERT(hBitmap);
  1915. if( hBitmap != NULL )
  1916. {
  1917. HBITMAP hOldBitmap = (HBITMAP) ::SelectObject(hCloneDC, hBitmap);
  1918. ::BitBlt(hCloneDC, 0, 0, cx, cy, hPaintDC, rc.left, rc.top, SRCCOPY);
  1919. ::SelectObject(hCloneDC, hOldBitmap);
  1920. ::DeleteDC(hCloneDC);
  1921. ::GdiFlush();
  1922. }
  1923. // Cleanup
  1924. ::SelectObject(hPaintDC, hOldPaintBitmap);
  1925. ::DeleteObject(hPaintBitmap);
  1926. ::DeleteDC(hPaintDC);
  1927. return hBitmap;
  1928. }
  1929. SIZE CRenderEngine::GetTextSize( HDC hDC, CPaintManagerUI* pManager , LPCTSTR pstrText, int iFont, UINT uStyle )
  1930. {
  1931. CDuiString sText = pstrText;
  1932. CPaintManagerUI::ProcessMultiLanguageTokens(sText);
  1933. pstrText = sText;
  1934. SIZE size = {0,0};
  1935. ASSERT(::GetObjectType(hDC)==OBJ_DC || ::GetObjectType(hDC)==OBJ_MEMDC);
  1936. if( pstrText == NULL || pManager == NULL ) return size;
  1937. ::SetBkMode(hDC, TRANSPARENT);
  1938. HFONT hOldFont = (HFONT)::SelectObject(hDC, pManager->GetFont(iFont));
  1939. GetTextExtentPoint32(hDC, pstrText, _tcslen(pstrText) , &size);
  1940. ::SelectObject(hDC, hOldFont);
  1941. return size;
  1942. }
  1943. } // namespace DuiLib