Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(645)

Side by Side Diff: core/src/fxge/win32/fx_win32_device.cpp

Issue 453133004: clang-format all code (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 6
7 #include "../../../include/fxge/fx_ge.h" 7 #include "../../../include/fxge/fx_ge.h"
8 #if _FX_OS_ == _FX_WIN32_DESKTOP_ || _FX_OS_ == _FX_WIN64_ 8 #if _FX_OS_ == _FX_WIN32_DESKTOP_ || _FX_OS_ == _FX_WIN64_
9 #include "../../../include/fxge/fx_ge_win32.h" 9 #include "../../../include/fxge/fx_ge_win32.h"
10 #include <crtdbg.h> 10 #include <crtdbg.h>
11 #include "../agg/include/fxfx_agg_clip_liang_barsky.h" 11 #include "../agg/include/fxfx_agg_clip_liang_barsky.h"
12 #include "dwrite_int.h" 12 #include "dwrite_int.h"
13 #include "win32_int.h" 13 #include "win32_int.h"
14 #include "../ge/text_int.h" 14 #include "../ge/text_int.h"
15 #include "../dib/dib_int.h" 15 #include "../dib/dib_int.h"
16 #include "../agg/include/fx_agg_driver.h" 16 #include "../agg/include/fx_agg_driver.h"
17 #include "../../../include/fxge/fx_freetype.h" 17 #include "../../../include/fxge/fx_freetype.h"
18 #include "../../../include/fxcodec/fx_codec.h" 18 #include "../../../include/fxcodec/fx_codec.h"
19 class CWin32FontInfo FX_FINAL : public IFX_SystemFontInfo 19 class CWin32FontInfo FX_FINAL : public IFX_SystemFontInfo {
20 { 20 public:
21 public: 21 CWin32FontInfo();
22 CWin32FontInfo(); 22 ~CWin32FontInfo();
23 ~CWin32FontInfo(); 23 virtual void Release();
24 virtual void» » Release(); 24 virtual FX_BOOL EnumFontList(CFX_FontMapper* pMapper);
25 virtual» FX_BOOL»» EnumFontList(CFX_FontMapper* pMapper); 25 virtual void* MapFont(int weight,
26 virtual void*» » MapFont(int weight, FX_BOOL bItalic, int charset , int pitch_family, FX_LPCSTR face, FX_BOOL& bExact); 26 FX_BOOL bItalic,
27 virtual void*» » GetFont(FX_LPCSTR face) 27 int charset,
28 { 28 int pitch_family,
29 return NULL; 29 FX_LPCSTR face,
30 } 30 FX_BOOL& bExact);
31 virtual FX_DWORD» GetFontData(void* hFont, FX_DWORD table, FX_LPBYTE buffe r, FX_DWORD size); 31 virtual void* GetFont(FX_LPCSTR face) { return NULL; }
32 virtual void» » DeleteFont(void* hFont); 32 virtual FX_DWORD GetFontData(void* hFont,
33 virtual» FX_BOOL»» GetFaceName(void* hFont, CFX_ByteString& name); 33 FX_DWORD table,
34 virtual FX_BOOL» » GetFontCharset(void* hFont, int& charset); 34 FX_LPBYTE buffer,
35 FX_BOOL» » » » IsOpenTypeFromDiv(const LOGFONTA *plf); 35 FX_DWORD size);
36 FX_BOOL» » » » IsSupportFontFormDiv(const LOGFONTA* plf ); 36 virtual void DeleteFont(void* hFont);
37 void» » » » AddInstalledFont(const LOGFONTA *plf, FX _DWORD FontType); 37 virtual FX_BOOL GetFaceName(void* hFont, CFX_ByteString& name);
38 void» » » » GetGBPreference(CFX_ByteString& face, in t weight, int picth_family); 38 virtual FX_BOOL GetFontCharset(void* hFont, int& charset);
39 void» » » » GetJapanesePreference(CFX_ByteString& fa ce, int weight, int picth_family); 39 FX_BOOL IsOpenTypeFromDiv(const LOGFONTA* plf);
40 CFX_ByteString» » FindFont(const CFX_ByteString& name); 40 FX_BOOL IsSupportFontFormDiv(const LOGFONTA* plf);
41 HDC»» » » » m_hDC; 41 void AddInstalledFont(const LOGFONTA* plf, FX_DWORD FontType);
42 CFX_FontMapper*» » m_pMapper; 42 void GetGBPreference(CFX_ByteString& face, int weight, int picth_family);
43 CFX_ByteString» » m_LastFamily; 43 void GetJapanesePreference(CFX_ByteString& face,
44 CFX_ByteString» » m_KaiTi, m_FangSong; 44 int weight,
45 int picth_family);
46 CFX_ByteString FindFont(const CFX_ByteString& name);
47 HDC m_hDC;
48 CFX_FontMapper* m_pMapper;
49 CFX_ByteString m_LastFamily;
50 CFX_ByteString m_KaiTi, m_FangSong;
45 }; 51 };
46 CWin32FontInfo::CWin32FontInfo() 52 CWin32FontInfo::CWin32FontInfo() {
47 { 53 m_hDC = CreateCompatibleDC(NULL);
48 m_hDC = CreateCompatibleDC(NULL); 54 }
49 } 55 CWin32FontInfo::~CWin32FontInfo() {
50 CWin32FontInfo::~CWin32FontInfo() 56 m_pMapper = NULL;
51 { 57 }
52 m_pMapper = NULL; 58 void CWin32FontInfo::Release() {
53 } 59 DeleteDC(m_hDC);
54 void CWin32FontInfo::Release() 60 delete this;
55 { 61 }
56 DeleteDC(m_hDC); 62 #define TT_MAKE_TAG(x1, x2, x3, x4) \
57 delete this; 63 (((FX_DWORD)x1 << 24) | ((FX_DWORD)x2 << 16) | ((FX_DWORD)x3 << 8) | \
58 } 64 (FX_DWORD)x4)
59 #define TT_MAKE_TAG(x1, x2, x3, x4) (((FX_DWORD)x1<<24)|((FX_DWORD)x2<<16)|((FX_ DWORD)x3<<8)|(FX_DWORD)x4) 65 FX_BOOL CWin32FontInfo::IsOpenTypeFromDiv(const LOGFONTA* plf) {
60 FX_BOOL CWin32FontInfo::IsOpenTypeFromDiv(const LOGFONTA *plf) 66 HFONT hFont = CreateFontIndirectA(plf);
61 { 67 FX_BOOL ret = FALSE;
62 HFONT hFont = CreateFontIndirectA(plf); 68 FX_DWORD font_size = GetFontData(hFont, 0, NULL, 0);
63 FX_BOOL ret = FALSE; 69 if (font_size != GDI_ERROR && font_size >= sizeof(FX_DWORD)) {
64 FX_DWORD font_size = GetFontData(hFont, 0, NULL, 0); 70 FX_DWORD lVersion = 0;
65 if (font_size != GDI_ERROR && font_size >= sizeof(FX_DWORD)) { 71 GetFontData(hFont, 0, (FX_BYTE*)(&lVersion), sizeof(FX_DWORD));
66 FX_DWORD lVersion = 0; 72 lVersion = (((FX_DWORD)(FX_BYTE)(lVersion)) << 24) |
67 GetFontData(hFont, 0, (FX_BYTE*)(&lVersion), sizeof(FX_DWORD)); 73 ((FX_DWORD)((FX_BYTE)(lVersion >> 8))) << 16 |
68 lVersion = (((FX_DWORD)(FX_BYTE)(lVersion)) << 24) | ((FX_DWORD)((FX_BYT E)(lVersion >> 8))) << 16 | 74 ((FX_DWORD)((FX_BYTE)(lVersion >> 16))) << 8 |
69 ((FX_DWORD)((FX_BYTE)(lVersion >> 16))) << 8 | ((FX_BYTE)(lVe rsion >> 24)); 75 ((FX_BYTE)(lVersion >> 24));
70 if (lVersion == TT_MAKE_TAG('O', 'T', 'T', 'O') || 76 if (lVersion == TT_MAKE_TAG('O', 'T', 'T', 'O') || lVersion == 0x00010000 ||
71 lVersion == 0x00010000 || 77 lVersion == TT_MAKE_TAG('t', 't', 'c', 'f') ||
72 lVersion == TT_MAKE_TAG('t', 't', 'c', 'f') || 78 lVersion == TT_MAKE_TAG('t', 'r', 'u', 'e') || lVersion == 0x00020000) {
73 lVersion == TT_MAKE_TAG('t', 'r', 'u', 'e') || 79 ret = TRUE;
74 lVersion == 0x00020000) { 80 }
75 ret = TRUE; 81 }
76 } 82 DeleteFont(hFont);
77 } 83 return ret;
78 DeleteFont(hFont); 84 }
79 return ret; 85 FX_BOOL CWin32FontInfo::IsSupportFontFormDiv(const LOGFONTA* plf) {
80 } 86 HFONT hFont = CreateFontIndirectA(plf);
81 FX_BOOL CWin32FontInfo::IsSupportFontFormDiv(const LOGFONTA* plf) 87 FX_BOOL ret = FALSE;
82 { 88 FX_DWORD font_size = GetFontData(hFont, 0, NULL, 0);
83 HFONT hFont = CreateFontIndirectA(plf); 89 if (font_size != GDI_ERROR && font_size >= sizeof(FX_DWORD)) {
84 FX_BOOL ret = FALSE; 90 FX_DWORD lVersion = 0;
85 FX_DWORD font_size = GetFontData(hFont, 0, NULL, 0); 91 GetFontData(hFont, 0, (FX_BYTE*)(&lVersion), sizeof(FX_DWORD));
86 if (font_size != GDI_ERROR && font_size >= sizeof(FX_DWORD)) { 92 lVersion = (((FX_DWORD)(FX_BYTE)(lVersion)) << 24) |
87 FX_DWORD lVersion = 0; 93 ((FX_DWORD)((FX_BYTE)(lVersion >> 8))) << 16 |
88 GetFontData(hFont, 0, (FX_BYTE*)(&lVersion), sizeof(FX_DWORD)); 94 ((FX_DWORD)((FX_BYTE)(lVersion >> 16))) << 8 |
89 lVersion = (((FX_DWORD)(FX_BYTE)(lVersion)) << 24) | ((FX_DWORD)((FX_BYT E)(lVersion >> 8))) << 16 | 95 ((FX_BYTE)(lVersion >> 24));
90 ((FX_DWORD)((FX_BYTE)(lVersion >> 16))) << 8 | ((FX_BYTE)(lVe rsion >> 24)); 96 if (lVersion == TT_MAKE_TAG('O', 'T', 'T', 'O') || lVersion == 0x00010000 ||
91 if (lVersion == TT_MAKE_TAG('O', 'T', 'T', 'O') || 97 lVersion == TT_MAKE_TAG('t', 't', 'c', 'f') ||
92 lVersion == 0x00010000 || 98 lVersion == TT_MAKE_TAG('t', 'r', 'u', 'e') || lVersion == 0x00020000) {
93 lVersion == TT_MAKE_TAG('t', 't', 'c', 'f') || 99 ret = TRUE;
94 lVersion == TT_MAKE_TAG('t', 'r', 'u', 'e') || 100 } else if ((lVersion & 0xFFFF0000) == TT_MAKE_TAG(0x80, 0x01, 0x00, 0x00) ||
95 lVersion == 0x00020000) { 101 (lVersion & 0xFFFF0000) == TT_MAKE_TAG('%', '!', 0, 0)) {
96 ret = TRUE; 102 ret = TRUE;
97 } else if ((lVersion & 0xFFFF0000) == TT_MAKE_TAG(0x80, 0x01, 0x00, 0x00 ) || 103 }
98 (lVersion & 0xFFFF0000) == TT_MAKE_TAG('%', '!', 0, 0)) { 104 }
99 ret = TRUE; 105 DeleteFont(hFont);
100 } 106 return ret;
101 } 107 }
102 DeleteFont(hFont); 108 void CWin32FontInfo::AddInstalledFont(const LOGFONTA* plf, FX_DWORD FontType) {
103 return ret; 109 CFX_ByteString name(plf->lfFaceName, -1);
104 } 110 if (name[0] == '@') {
105 void CWin32FontInfo::AddInstalledFont(const LOGFONTA *plf, FX_DWORD FontType) 111 return;
106 { 112 }
107 CFX_ByteString name(plf->lfFaceName, -1); 113 if (name == m_LastFamily) {
108 if (name[0] == '@') {
109 return;
110 }
111 if (name == m_LastFamily) {
112 m_pMapper->AddInstalledFont(name, plf->lfCharSet);
113 return;
114 }
115 if (!(FontType & TRUETYPE_FONTTYPE) && !(FontType & DEVICE_FONTTYPE)) {
116 return;
117 }
118 if (!(FontType & TRUETYPE_FONTTYPE)) {
119 if (!IsSupportFontFormDiv(plf)) {
120 return;
121 }
122 }
123 m_pMapper->AddInstalledFont(name, plf->lfCharSet); 114 m_pMapper->AddInstalledFont(name, plf->lfCharSet);
124 m_LastFamily = name; 115 return;
125 } 116 }
126 static int CALLBACK FontEnumProc( 117 if (!(FontType & TRUETYPE_FONTTYPE) && !(FontType & DEVICE_FONTTYPE)) {
127 const LOGFONTA *plf, 118 return;
128 const TEXTMETRICA *lpntme, 119 }
129 FX_DWORD FontType, 120 if (!(FontType & TRUETYPE_FONTTYPE)) {
130 LPARAM lParam 121 if (!IsSupportFontFormDiv(plf)) {
131 ) 122 return;
132 { 123 }
133 CWin32FontInfo* pFontInfo = (CWin32FontInfo*)lParam; 124 }
134 if (pFontInfo->m_pMapper->GetFontEnumerator()) { 125 m_pMapper->AddInstalledFont(name, plf->lfCharSet);
135 pFontInfo->m_pMapper->GetFontEnumerator()->HitFont(); 126 m_LastFamily = name;
136 } 127 }
137 pFontInfo->AddInstalledFont(plf, FontType); 128 static int CALLBACK FontEnumProc(const LOGFONTA* plf,
138 return 1; 129 const TEXTMETRICA* lpntme,
139 } 130 FX_DWORD FontType,
140 FX_BOOL CWin32FontInfo::EnumFontList(CFX_FontMapper* pMapper) 131 LPARAM lParam) {
141 { 132 CWin32FontInfo* pFontInfo = (CWin32FontInfo*)lParam;
142 m_pMapper = pMapper; 133 if (pFontInfo->m_pMapper->GetFontEnumerator()) {
143 LOGFONTA lf; 134 pFontInfo->m_pMapper->GetFontEnumerator()->HitFont();
144 FXSYS_memset32(&lf, 0, sizeof(LOGFONTA)); 135 }
145 lf.lfCharSet = DEFAULT_CHARSET; 136 pFontInfo->AddInstalledFont(plf, FontType);
146 lf.lfFaceName[0] = 0; 137 return 1;
147 lf.lfPitchAndFamily = 0; 138 }
148 EnumFontFamiliesExA(m_hDC, &lf, (FONTENUMPROCA)FontEnumProc, (FX_UINTPTR)thi s, 0); 139 FX_BOOL CWin32FontInfo::EnumFontList(CFX_FontMapper* pMapper) {
149 if (pMapper->GetFontEnumerator()) { 140 m_pMapper = pMapper;
150 pMapper->GetFontEnumerator()->Finish(); 141 LOGFONTA lf;
151 } 142 FXSYS_memset32(&lf, 0, sizeof(LOGFONTA));
152 return TRUE; 143 lf.lfCharSet = DEFAULT_CHARSET;
144 lf.lfFaceName[0] = 0;
145 lf.lfPitchAndFamily = 0;
146 EnumFontFamiliesExA(
147 m_hDC, &lf, (FONTENUMPROCA)FontEnumProc, (FX_UINTPTR) this, 0);
148 if (pMapper->GetFontEnumerator()) {
149 pMapper->GetFontEnumerator()->Finish();
150 }
151 return TRUE;
153 } 152 }
154 static const struct { 153 static const struct {
155 FX_LPCSTR» m_pFaceName; 154 FX_LPCSTR m_pFaceName;
156 FX_LPCSTR» m_pVariantName; 155 FX_LPCSTR m_pVariantName;
157 } 156 } VariantNames[] = {
158 VariantNames[] = { 157 { "DFKai-SB", "\x19\x6A\x77\x69\xD4\x9A" },
159 {"DFKai-SB", "\x19\x6A\x77\x69\xD4\x9A"}, 158 };
160 };
161 static const struct { 159 static const struct {
162 FX_LPCSTR» m_pName; 160 FX_LPCSTR m_pName;
163 FX_LPCSTR» m_pWinName; 161 FX_LPCSTR m_pWinName;
164 FX_BOOL» » m_bBold; 162 FX_BOOL m_bBold;
165 FX_BOOL» » m_bItalic; 163 FX_BOOL m_bItalic;
166 } 164 } Base14Substs[] = {
167 Base14Substs[] = { 165 { "Courier", "Courier New", FALSE, FALSE },
168 {"Courier", "Courier New", FALSE, FALSE}, 166 { "Courier-Bold", "Courier New", TRUE, FALSE },
169 {"Courier-Bold", "Courier New", TRUE, FALSE}, 167 { "Courier-BoldOblique", "Courier New", TRUE, TRUE },
170 {"Courier-BoldOblique", "Courier New", TRUE, TRUE}, 168 { "Courier-Oblique", "Courier New", FALSE, TRUE },
171 {"Courier-Oblique", "Courier New", FALSE, TRUE}, 169 { "Helvetica", "Arial", FALSE, FALSE },
172 {"Helvetica", "Arial", FALSE, FALSE}, 170 { "Helvetica-Bold", "Arial", TRUE, FALSE },
173 {"Helvetica-Bold", "Arial", TRUE, FALSE}, 171 { "Helvetica-BoldOblique", "Arial", TRUE, TRUE },
174 {"Helvetica-BoldOblique", "Arial", TRUE, TRUE}, 172 { "Helvetica-Oblique", "Arial", FALSE, TRUE },
175 {"Helvetica-Oblique", "Arial", FALSE, TRUE}, 173 { "Times-Roman", "Times New Roman", FALSE, FALSE },
176 {"Times-Roman", "Times New Roman", FALSE, FALSE}, 174 { "Times-Bold", "Times New Roman", TRUE, FALSE },
177 {"Times-Bold", "Times New Roman", TRUE, FALSE}, 175 { "Times-BoldItalic", "Times New Roman", TRUE, TRUE },
178 {"Times-BoldItalic", "Times New Roman", TRUE, TRUE}, 176 { "Times-Italic", "Times New Roman", FALSE, TRUE },
179 {"Times-Italic", "Times New Roman", FALSE, TRUE}, 177 };
180 }; 178 CFX_ByteString CWin32FontInfo::FindFont(const CFX_ByteString& name) {
181 CFX_ByteString CWin32FontInfo::FindFont(const CFX_ByteString& name) 179 if (m_pMapper == NULL) {
182 { 180 return name;
183 if (m_pMapper == NULL) { 181 }
184 return name; 182 int nFonts = m_pMapper->m_InstalledTTFonts.GetSize();
185 } 183 for (int i = 0; i < nFonts; i++) {
186 int nFonts = m_pMapper->m_InstalledTTFonts.GetSize(); 184 CFX_ByteString thisname = m_pMapper->m_InstalledTTFonts[i];
187 for (int i = 0; i < nFonts; i ++) { 185 if (thisname[0] == ' ') {
188 CFX_ByteString thisname = m_pMapper->m_InstalledTTFonts[i]; 186 if (thisname.Mid(1, name.GetLength()) == name) {
189 if (thisname[0] == ' ') { 187 return m_pMapper->m_InstalledTTFonts[i + 1];
190 if (thisname.Mid(1, name.GetLength()) == name) { 188 }
191 return m_pMapper->m_InstalledTTFonts[i + 1]; 189 } else if (thisname.Left(name.GetLength()) == name) {
192 } 190 return m_pMapper->m_InstalledTTFonts[i];
193 } else if (thisname.Left(name.GetLength()) == name) { 191 }
194 return m_pMapper->m_InstalledTTFonts[i]; 192 }
195 } 193 return CFX_ByteString();
196 }
197 return CFX_ByteString();
198 } 194 }
199 struct _FontNameMap { 195 struct _FontNameMap {
200 FX_LPCSTR» m_pSubFontName; 196 FX_LPCSTR m_pSubFontName;
201 FX_LPCSTR» m_pSrcFontName; 197 FX_LPCSTR m_pSrcFontName;
202 }; 198 };
203 const _FontNameMap g_JpFontNameMap[] = { 199 const _FontNameMap g_JpFontNameMap[] = {
204 {"MS Mincho", "Heiseimin-W3"}, 200 { "MS Mincho", "Heiseimin-W3" },
205 {"MS Gothic", "Jun101-Light"}, 201 { "MS Gothic", "Jun101-Light" },
206 }; 202 };
207 extern "C" { 203 extern "C" {
208 static int compareString(const void* key, const void* element) 204 static int compareString(const void* key, const void* element) {
209 { 205 return FXSYS_stricmp((FX_LPCSTR)key,
210 return FXSYS_stricmp((FX_LPCSTR)key, ((_FontNameMap*)element)->m_pSrcFon tName); 206 ((_FontNameMap*)element)->m_pSrcFontName);
211 } 207 }
212 } 208 }
213 FX_BOOL _GetSubFontName(CFX_ByteString& name) 209 FX_BOOL _GetSubFontName(CFX_ByteString& name) {
214 { 210 int size = sizeof g_JpFontNameMap;
215 int size = sizeof g_JpFontNameMap; 211 void* pFontnameMap = (void*)g_JpFontNameMap;
216 void* pFontnameMap = (void*)g_JpFontNameMap; 212 _FontNameMap* found =
217 _FontNameMap* found = (_FontNameMap*)FXSYS_bsearch((FX_LPCSTR)name, pFontnam eMap, 213 (_FontNameMap*)FXSYS_bsearch((FX_LPCSTR)name,
218 size / sizeof (_FontNameMap), sizeof (_FontNameMap), c ompareString); 214 pFontnameMap,
219 if (found == NULL) { 215 size / sizeof(_FontNameMap),
220 return FALSE; 216 sizeof(_FontNameMap),
221 } 217 compareString);
222 name = found->m_pSubFontName; 218 if (found == NULL) {
223 return TRUE; 219 return FALSE;
224 } 220 }
225 void CWin32FontInfo::GetGBPreference(CFX_ByteString& face, int weight, int picth _family) 221 name = found->m_pSubFontName;
226 { 222 return TRUE;
227 if (face.Find("KaiTi") >= 0 || face.Find("\xbf\xac") >= 0) { 223 }
228 if (m_KaiTi.IsEmpty()) { 224 void CWin32FontInfo::GetGBPreference(CFX_ByteString& face,
229 m_KaiTi = FindFont("KaiTi"); 225 int weight,
230 if (m_KaiTi.IsEmpty()) { 226 int picth_family) {
231 m_KaiTi = "SimSun"; 227 if (face.Find("KaiTi") >= 0 || face.Find("\xbf\xac") >= 0) {
232 } 228 if (m_KaiTi.IsEmpty()) {
233 } 229 m_KaiTi = FindFont("KaiTi");
234 face = m_KaiTi; 230 if (m_KaiTi.IsEmpty()) {
235 } else if (face.Find("FangSong") >= 0 || face.Find("\xb7\xc2\xcb\xce") >= 0) { 231 m_KaiTi = "SimSun";
236 if (m_FangSong.IsEmpty()) { 232 }
237 m_FangSong = FindFont("FangSong"); 233 }
238 if (m_FangSong.IsEmpty()) { 234 face = m_KaiTi;
239 m_FangSong = "SimSun"; 235 } else if (face.Find("FangSong") >= 0 || face.Find("\xb7\xc2\xcb\xce") >= 0) {
240 } 236 if (m_FangSong.IsEmpty()) {
241 } 237 m_FangSong = FindFont("FangSong");
242 face = m_FangSong; 238 if (m_FangSong.IsEmpty()) {
243 } else if (face.Find("SimSun") >= 0 || face.Find("\xcb\xce") >= 0) { 239 m_FangSong = "SimSun";
244 face = "SimSun"; 240 }
245 } else if (face.Find("SimHei") >= 0 || face.Find("\xba\xda") >= 0) { 241 }
246 face = "SimHei"; 242 face = m_FangSong;
247 } else if (!(picth_family & FF_ROMAN) && weight > 550) { 243 } else if (face.Find("SimSun") >= 0 || face.Find("\xcb\xce") >= 0) {
248 face = "SimHei"; 244 face = "SimSun";
245 } else if (face.Find("SimHei") >= 0 || face.Find("\xba\xda") >= 0) {
246 face = "SimHei";
247 } else if (!(picth_family & FF_ROMAN) && weight > 550) {
248 face = "SimHei";
249 } else {
250 face = "SimSun";
251 }
252 }
253 void CWin32FontInfo::GetJapanesePreference(CFX_ByteString& face,
254 int weight,
255 int picth_family) {
256 if (face.Find("Gothic") >= 0 ||
257 face.Find("\x83\x53\x83\x56\x83\x62\x83\x4e") >= 0) {
258 if (face.Find("PGothic") >= 0 ||
259 face.Find("\x82\x6f\x83\x53\x83\x56\x83\x62\x83\x4e") >= 0) {
260 face = "MS PGothic";
261 } else if (face.Find("UI Gothic") >= 0) {
262 face = "MS UI Gothic";
249 } else { 263 } else {
250 face = "SimSun"; 264 if (face.Find("HGSGothicM") >= 0 || face.Find("HGMaruGothicMPRO") >= 0) {
251 }
252 }
253 void CWin32FontInfo::GetJapanesePreference(CFX_ByteString& face, int weight, int picth_family)
254 {
255 if (face.Find("Gothic") >= 0 || face.Find("\x83\x53\x83\x56\x83\x62\x83\x4e" ) >= 0) {
256 if (face.Find("PGothic") >= 0 || face.Find("\x82\x6f\x83\x53\x83\x56\x83 \x62\x83\x4e") >= 0) {
257 face = "MS PGothic";
258 } else if (face.Find("UI Gothic") >= 0) {
259 face = "MS UI Gothic";
260 } else {
261 if (face.Find("HGSGothicM") >= 0 || face.Find("HGMaruGothicMPRO") >= 0) {
262 face = "MS PGothic";
263 } else {
264 face = "MS Gothic";
265 }
266 }
267 return;
268 } else if (face.Find("Mincho") >= 0 || face.Find("\x96\xbe\x92\xa9") >= 0) {
269 if (face.Find("PMincho") >= 0 || face.Find("\x82\x6f\x96\xbe\x92\xa9") > = 0) {
270 face = "MS PMincho";
271 } else {
272 face = "MS Mincho";
273 }
274 return;
275 }
276 if (_GetSubFontName(face)) {
277 return;
278 }
279 if (!(picth_family & FF_ROMAN) && weight > 400) {
280 face = "MS PGothic"; 265 face = "MS PGothic";
266 } else {
267 face = "MS Gothic";
268 }
269 }
270 return;
271 } else if (face.Find("Mincho") >= 0 || face.Find("\x96\xbe\x92\xa9") >= 0) {
272 if (face.Find("PMincho") >= 0 ||
273 face.Find("\x82\x6f\x96\xbe\x92\xa9") >= 0) {
274 face = "MS PMincho";
281 } else { 275 } else {
282 face = "MS PMincho"; 276 face = "MS Mincho";
283 } 277 }
284 } 278 return;
285 void* CWin32FontInfo::MapFont(int weight, FX_BOOL bItalic, int charset, int pitc h_family, FX_LPCSTR cstr_face, FX_BOOL& bExact) 279 }
286 { 280 if (_GetSubFontName(face)) {
287 CFX_ByteString face = cstr_face; 281 return;
288 int iBaseFont; 282 }
289 for (iBaseFont = 0; iBaseFont < 12; iBaseFont ++) 283 if (!(picth_family & FF_ROMAN) && weight > 400) {
290 if (face == CFX_ByteStringC(Base14Substs[iBaseFont].m_pName)) { 284 face = "MS PGothic";
291 face = Base14Substs[iBaseFont].m_pWinName; 285 } else {
292 weight = Base14Substs[iBaseFont].m_bBold ? FW_BOLD : FW_NORMAL; 286 face = "MS PMincho";
293 bItalic = Base14Substs[iBaseFont].m_bItalic; 287 }
294 bExact = TRUE; 288 }
295 break; 289 void* CWin32FontInfo::MapFont(int weight,
296 } 290 FX_BOOL bItalic,
297 if (charset == ANSI_CHARSET || charset == SYMBOL_CHARSET) { 291 int charset,
298 charset = DEFAULT_CHARSET; 292 int pitch_family,
299 } 293 FX_LPCSTR cstr_face,
300 int subst_pitch_family = pitch_family; 294 FX_BOOL& bExact) {
301 switch (charset) { 295 CFX_ByteString face = cstr_face;
302 case SHIFTJIS_CHARSET: 296 int iBaseFont;
303 subst_pitch_family = FF_ROMAN; 297 for (iBaseFont = 0; iBaseFont < 12; iBaseFont++)
304 break; 298 if (face == CFX_ByteStringC(Base14Substs[iBaseFont].m_pName)) {
305 case CHINESEBIG5_CHARSET: 299 face = Base14Substs[iBaseFont].m_pWinName;
306 case HANGUL_CHARSET: 300 weight = Base14Substs[iBaseFont].m_bBold ? FW_BOLD : FW_NORMAL;
307 case GB2312_CHARSET: 301 bItalic = Base14Substs[iBaseFont].m_bItalic;
308 subst_pitch_family = 0; 302 bExact = TRUE;
309 break; 303 break;
310 } 304 }
311 HFONT hFont = ::CreateFontA(-10, 0, 0, 0, weight, bItalic, 0, 0, charset, OU T_TT_ONLY_PRECIS, 305 if (charset == ANSI_CHARSET || charset == SYMBOL_CHARSET) {
312 0, 0, subst_pitch_family, face); 306 charset = DEFAULT_CHARSET;
313 char facebuf[100]; 307 }
314 HFONT hOldFont = (HFONT)::SelectObject(m_hDC, hFont); 308 int subst_pitch_family = pitch_family;
315 int ret = ::GetTextFaceA(m_hDC, 100, facebuf); 309 switch (charset) {
316 ::SelectObject(m_hDC, hOldFont); 310 case SHIFTJIS_CHARSET:
317 if (face.EqualNoCase(facebuf)) { 311 subst_pitch_family = FF_ROMAN;
312 break;
313 case CHINESEBIG5_CHARSET:
314 case HANGUL_CHARSET:
315 case GB2312_CHARSET:
316 subst_pitch_family = 0;
317 break;
318 }
319 HFONT hFont = ::CreateFontA(-10,
320 0,
321 0,
322 0,
323 weight,
324 bItalic,
325 0,
326 0,
327 charset,
328 OUT_TT_ONLY_PRECIS,
329 0,
330 0,
331 subst_pitch_family,
332 face);
333 char facebuf[100];
334 HFONT hOldFont = (HFONT)::SelectObject(m_hDC, hFont);
335 int ret = ::GetTextFaceA(m_hDC, 100, facebuf);
336 ::SelectObject(m_hDC, hOldFont);
337 if (face.EqualNoCase(facebuf)) {
338 return hFont;
339 }
340 int iCount = sizeof(VariantNames) / sizeof(VariantNames[0]);
341 for (int i = 0; i < iCount; ++i) {
342 if (face == VariantNames[i].m_pFaceName) {
343 CFX_WideString wsFace = CFX_WideString::FromLocal(facebuf);
344 const unsigned short* pName =
345 (const unsigned short*)VariantNames[i].m_pVariantName;
346 FX_STRSIZE len = CFX_WideString::WStringLength(pName);
347 CFX_WideString wsName = CFX_WideString::FromUTF16LE(pName, len);
348 if (wsFace == wsName) {
318 return hFont; 349 return hFont;
319 } 350 }
320 int iCount = sizeof(VariantNames) / sizeof(VariantNames[0]); 351 }
321 for (int i = 0; i < iCount; ++i) { 352 }
322 if (face == VariantNames[i].m_pFaceName) { 353 ::DeleteObject(hFont);
323 CFX_WideString wsFace = CFX_WideString::FromLocal(facebuf); 354 if (charset == DEFAULT_CHARSET) {
324 const unsigned short* pName = (const unsigned short*)VariantNames[i] .m_pVariantName; 355 return NULL;
325 FX_STRSIZE len = CFX_WideString::WStringLength(pName); 356 }
326 CFX_WideString wsName = CFX_WideString::FromUTF16LE(pName, len); 357 switch (charset) {
327 if (wsFace == wsName) { 358 case SHIFTJIS_CHARSET:
328 return hFont; 359 GetJapanesePreference(face, weight, pitch_family);
329 } 360 break;
330 } 361 case GB2312_CHARSET:
331 } 362 GetGBPreference(face, weight, pitch_family);
332 ::DeleteObject(hFont); 363 break;
333 if (charset == DEFAULT_CHARSET) { 364 case HANGUL_CHARSET:
334 return NULL; 365 face = "Gulim";
335 } 366 break;
336 switch (charset) { 367 case CHINESEBIG5_CHARSET:
337 case SHIFTJIS_CHARSET: 368 if (face.Find("MSung") >= 0) {
338 GetJapanesePreference(face, weight, pitch_family); 369 face = "MingLiU";
339 break; 370 } else {
340 case GB2312_CHARSET: 371 face = "PMingLiU";
341 GetGBPreference(face, weight, pitch_family); 372 }
342 break; 373 break;
343 case HANGUL_CHARSET: 374 }
344 face = "Gulim"; 375 hFont = ::CreateFontA(-10,
345 break; 376 0,
346 case CHINESEBIG5_CHARSET: 377 0,
347 if (face.Find("MSung") >= 0) { 378 0,
348 face = "MingLiU"; 379 weight,
349 } else { 380 bItalic,
350 face = "PMingLiU"; 381 0,
351 } 382 0,
352 break; 383 charset,
353 } 384 OUT_TT_ONLY_PRECIS,
354 hFont = ::CreateFontA(-10, 0, 0, 0, weight, bItalic, 0, 0, charset, OUT_TT_O NLY_PRECIS, 385 0,
355 0, 0, subst_pitch_family, face); 386 0,
356 return hFont; 387 subst_pitch_family,
357 } 388 face);
358 void CWin32FontInfo::DeleteFont(void* hFont) 389 return hFont;
359 { 390 }
360 ::DeleteObject(hFont); 391 void CWin32FontInfo::DeleteFont(void* hFont) {
361 } 392 ::DeleteObject(hFont);
362 FX_DWORD CWin32FontInfo::GetFontData(void* hFont, FX_DWORD table, FX_LPBYTE buff er, FX_DWORD size) 393 }
363 { 394 FX_DWORD CWin32FontInfo::GetFontData(void* hFont,
364 HFONT hOldFont = (HFONT)::SelectObject(m_hDC, (HFONT)hFont); 395 FX_DWORD table,
365 table = FXDWORD_FROM_MSBFIRST(table); 396 FX_LPBYTE buffer,
366 size = ::GetFontData(m_hDC, table, 0, buffer, size); 397 FX_DWORD size) {
367 ::SelectObject(m_hDC, hOldFont); 398 HFONT hOldFont = (HFONT)::SelectObject(m_hDC, (HFONT)hFont);
368 if (size == GDI_ERROR) { 399 table = FXDWORD_FROM_MSBFIRST(table);
369 return 0; 400 size = ::GetFontData(m_hDC, table, 0, buffer, size);
370 } 401 ::SelectObject(m_hDC, hOldFont);
371 return size; 402 if (size == GDI_ERROR) {
372 } 403 return 0;
373 FX_BOOL CWin32FontInfo::GetFaceName(void* hFont, CFX_ByteString& name) 404 }
374 { 405 return size;
375 char facebuf[100]; 406 }
376 HFONT hOldFont = (HFONT)::SelectObject(m_hDC, (HFONT)hFont); 407 FX_BOOL CWin32FontInfo::GetFaceName(void* hFont, CFX_ByteString& name) {
377 int ret = ::GetTextFaceA(m_hDC, 100, facebuf); 408 char facebuf[100];
378 ::SelectObject(m_hDC, hOldFont); 409 HFONT hOldFont = (HFONT)::SelectObject(m_hDC, (HFONT)hFont);
379 if (ret == 0) { 410 int ret = ::GetTextFaceA(m_hDC, 100, facebuf);
380 return FALSE; 411 ::SelectObject(m_hDC, hOldFont);
381 } 412 if (ret == 0) {
382 name = facebuf; 413 return FALSE;
383 return TRUE; 414 }
384 } 415 name = facebuf;
385 FX_BOOL CWin32FontInfo::GetFontCharset(void* hFont, int& charset) 416 return TRUE;
386 { 417 }
387 TEXTMETRIC tm; 418 FX_BOOL CWin32FontInfo::GetFontCharset(void* hFont, int& charset) {
388 HFONT hOldFont = (HFONT)::SelectObject(m_hDC, (HFONT)hFont); 419 TEXTMETRIC tm;
389 ::GetTextMetrics(m_hDC, &tm); 420 HFONT hOldFont = (HFONT)::SelectObject(m_hDC, (HFONT)hFont);
390 ::SelectObject(m_hDC, hOldFont); 421 ::GetTextMetrics(m_hDC, &tm);
391 charset = tm.tmCharSet; 422 ::SelectObject(m_hDC, hOldFont);
392 return TRUE; 423 charset = tm.tmCharSet;
424 return TRUE;
393 } 425 }
394 #ifndef _FPDFAPI_MINI_ 426 #ifndef _FPDFAPI_MINI_
395 IFX_SystemFontInfo* IFX_SystemFontInfo::CreateDefault() 427 IFX_SystemFontInfo* IFX_SystemFontInfo::CreateDefault() {
396 { 428 return FX_NEW CWin32FontInfo;
397 return FX_NEW CWin32FontInfo;
398 } 429 }
399 #endif 430 #endif
400 void CFX_GEModule::InitPlatform() 431 void CFX_GEModule::InitPlatform() {
401 { 432 CWin32Platform* pPlatformData = FX_NEW CWin32Platform;
402 CWin32Platform* pPlatformData = FX_NEW CWin32Platform; 433 if (!pPlatformData) {
403 if (!pPlatformData) { 434 return;
404 return; 435 }
405 } 436 OSVERSIONINFO ver;
406 OSVERSIONINFO ver; 437 ver.dwOSVersionInfoSize = sizeof(ver);
407 ver.dwOSVersionInfoSize = sizeof(ver); 438 GetVersionEx(&ver);
408 GetVersionEx(&ver); 439 pPlatformData->m_bHalfTone = ver.dwMajorVersion >= 5;
409 pPlatformData->m_bHalfTone = ver.dwMajorVersion >= 5; 440 pPlatformData->m_GdiplusExt.Load();
410 pPlatformData->m_GdiplusExt.Load(); 441 m_pPlatformData = pPlatformData;
411 m_pPlatformData = pPlatformData; 442 m_pFontMgr->SetSystemFontInfo(IFX_SystemFontInfo::CreateDefault());
412 m_pFontMgr->SetSystemFontInfo(IFX_SystemFontInfo::CreateDefault()); 443 }
413 } 444 void CFX_GEModule::DestroyPlatform() {
414 void CFX_GEModule::DestroyPlatform() 445 if (m_pPlatformData) {
415 { 446 delete (CWin32Platform*)m_pPlatformData;
416 if (m_pPlatformData) { 447 }
417 delete (CWin32Platform*)m_pPlatformData; 448 m_pPlatformData = NULL;
418 } 449 }
419 m_pPlatformData = NULL; 450 CGdiDeviceDriver::CGdiDeviceDriver(HDC hDC, int device_class) {
420 } 451 m_hDC = hDC;
421 CGdiDeviceDriver::CGdiDeviceDriver(HDC hDC, int device_class) 452 m_DeviceClass = device_class;
422 { 453 CWin32Platform* pPlatform =
423 m_hDC = hDC; 454 (CWin32Platform*)CFX_GEModule::Get()->GetPlatformData();
424 m_DeviceClass = device_class; 455 SetStretchBltMode(hDC, pPlatform->m_bHalfTone ? HALFTONE : COLORONCOLOR);
425 CWin32Platform* pPlatform = (CWin32Platform*)CFX_GEModule::Get()->GetPlatfor mData(); 456 if (GetObjectType(m_hDC) == OBJ_MEMDC) {
426 SetStretchBltMode(hDC, pPlatform->m_bHalfTone ? HALFTONE : COLORONCOLOR); 457 HBITMAP hBitmap = CreateBitmap(1, 1, 1, 1, NULL);
427 if (GetObjectType(m_hDC) == OBJ_MEMDC) { 458 hBitmap = (HBITMAP)SelectObject(m_hDC, hBitmap);
428 HBITMAP hBitmap = CreateBitmap(1, 1, 1, 1, NULL); 459 BITMAP bitmap;
429 hBitmap = (HBITMAP)SelectObject(m_hDC, hBitmap); 460 GetObject(hBitmap, sizeof bitmap, &bitmap);
430 BITMAP bitmap; 461 m_nBitsPerPixel = bitmap.bmBitsPixel;
431 GetObject(hBitmap, sizeof bitmap, &bitmap); 462 m_Width = bitmap.bmWidth;
432 m_nBitsPerPixel = bitmap.bmBitsPixel; 463 m_Height = abs(bitmap.bmHeight);
433 m_Width = bitmap.bmWidth; 464 hBitmap = (HBITMAP)SelectObject(m_hDC, hBitmap);
434 m_Height = abs(bitmap.bmHeight); 465 DeleteObject(hBitmap);
435 hBitmap = (HBITMAP)SelectObject(m_hDC, hBitmap); 466 } else {
436 DeleteObject(hBitmap); 467 m_nBitsPerPixel = ::GetDeviceCaps(m_hDC, BITSPIXEL);
468 m_Width = ::GetDeviceCaps(m_hDC, HORZRES);
469 m_Height = ::GetDeviceCaps(m_hDC, VERTRES);
470 }
471 if (m_DeviceClass != FXDC_DISPLAY) {
472 m_RenderCaps = FXRC_BIT_MASK;
473 } else {
474 m_RenderCaps = FXRC_GET_BITS | FXRC_BIT_MASK;
475 }
476 }
477 int CGdiDeviceDriver::GetDeviceCaps(int caps_id) {
478 switch (caps_id) {
479 case FXDC_DEVICE_CLASS:
480 return m_DeviceClass;
481 case FXDC_PIXEL_WIDTH:
482 return m_Width;
483 case FXDC_PIXEL_HEIGHT:
484 return m_Height;
485 case FXDC_BITS_PIXEL:
486 return m_nBitsPerPixel;
487 case FXDC_RENDER_CAPS:
488 return m_RenderCaps;
489 }
490 return 0;
491 }
492 FX_LPVOID CGdiDeviceDriver::GetClipRgn() {
493 HRGN hClipRgn = CreateRectRgn(0, 0, 1, 1);
494 if (::GetClipRgn(m_hDC, hClipRgn) == 0) {
495 DeleteObject(hClipRgn);
496 hClipRgn = NULL;
497 }
498 return (FX_LPVOID)hClipRgn;
499 }
500 FX_BOOL CGdiDeviceDriver::GDI_SetDIBits(const CFX_DIBitmap* pBitmap1,
501 const FX_RECT* pSrcRect,
502 int left,
503 int top,
504 void* pIccTransform) {
505 if (m_DeviceClass == FXDC_PRINTER) {
506 CFX_DIBitmap* pBitmap = pBitmap1->FlipImage(FALSE, TRUE);
507 if (pBitmap == NULL) {
508 return FALSE;
509 }
510 if ((pBitmap->IsCmykImage() || pIccTransform) &&
511 !pBitmap->ConvertFormat(FXDIB_Rgb, pIccTransform)) {
512 return FALSE;
513 }
514 int width = pSrcRect->Width(), height = pSrcRect->Height();
515 int pitch = pBitmap->GetPitch();
516 LPBYTE pBuffer = pBitmap->GetBuffer();
517 CFX_ByteString info = CFX_WindowsDIB::GetBitmapInfo(pBitmap);
518 ((BITMAPINFOHEADER*)(FX_LPCSTR) info)->biHeight *= -1;
519 FX_RECT dst_rect(0, 0, width, height);
520 dst_rect.Intersect(0, 0, pBitmap->GetWidth(), pBitmap->GetHeight());
521 int dst_width = dst_rect.Width();
522 int dst_height = dst_rect.Height();
523 ::StretchDIBits(m_hDC,
524 left,
525 top,
526 dst_width,
527 dst_height,
528 0,
529 0,
530 dst_width,
531 dst_height,
532 pBuffer,
533 (BITMAPINFO*)(FX_LPCSTR) info,
534 DIB_RGB_COLORS,
535 SRCCOPY);
536 delete pBitmap;
537 } else {
538 CFX_DIBitmap* pBitmap = (CFX_DIBitmap*)pBitmap1;
539 if ((pBitmap->IsCmykImage() || pIccTransform) &&
540 (pBitmap = pBitmap->CloneConvert(FXDIB_Rgb, NULL, pIccTransform)) ==
541 NULL) {
542 return FALSE;
543 }
544 int width = pSrcRect->Width(), height = pSrcRect->Height();
545 int pitch = pBitmap->GetPitch();
546 LPBYTE pBuffer = pBitmap->GetBuffer();
547 CFX_ByteString info = CFX_WindowsDIB::GetBitmapInfo(pBitmap);
548 ::SetDIBitsToDevice(m_hDC,
549 left,
550 top,
551 width,
552 height,
553 pSrcRect->left,
554 pBitmap->GetHeight() - pSrcRect->bottom,
555 0,
556 pBitmap->GetHeight(),
557 pBuffer,
558 (BITMAPINFO*)(FX_LPCSTR) info,
559 DIB_RGB_COLORS);
560 if (pBitmap != pBitmap1) {
561 delete pBitmap;
562 }
563 }
564 return TRUE;
565 }
566 FX_BOOL CGdiDeviceDriver::GDI_StretchDIBits(const CFX_DIBitmap* pBitmap1,
567 int dest_left,
568 int dest_top,
569 int dest_width,
570 int dest_height,
571 FX_DWORD flags,
572 void* pIccTransform) {
573 CFX_DIBitmap* pBitmap = (CFX_DIBitmap*)pBitmap1;
574 if (pBitmap == NULL) {
575 return FALSE;
576 }
577 if ((pBitmap->IsCmykImage() || pIccTransform) &&
578 !pBitmap->ConvertFormat(FXDIB_Rgb, pIccTransform)) {
579 return FALSE;
580 }
581 CFX_ByteString info = CFX_WindowsDIB::GetBitmapInfo(pBitmap);
582 if ((FX_INT64)abs(dest_width) * abs(dest_height) <
583 (FX_INT64)pBitmap1->GetWidth() * pBitmap1->GetHeight() * 4 ||
584 (flags & FXDIB_INTERPOL) || (flags & FXDIB_BICUBIC_INTERPOL)) {
585 SetStretchBltMode(m_hDC, HALFTONE);
586 } else {
587 SetStretchBltMode(m_hDC, COLORONCOLOR);
588 }
589 CFX_DIBitmap* pToStrechBitmap = pBitmap;
590 bool del = false;
591 if (m_DeviceClass == FXDC_PRINTER &&
592 ((FX_INT64)pBitmap->GetWidth() * pBitmap->GetHeight() >
593 (FX_INT64)abs(dest_width) * abs(dest_height))) {
594 pToStrechBitmap = pBitmap->StretchTo(dest_width, dest_height);
595 del = true;
596 }
597 CFX_ByteString toStrechBitmapInfo =
598 CFX_WindowsDIB::GetBitmapInfo(pToStrechBitmap);
599 ::StretchDIBits(m_hDC,
600 dest_left,
601 dest_top,
602 dest_width,
603 dest_height,
604 0,
605 0,
606 pToStrechBitmap->GetWidth(),
607 pToStrechBitmap->GetHeight(),
608 pToStrechBitmap->GetBuffer(),
609 (BITMAPINFO*)(FX_LPCSTR) toStrechBitmapInfo,
610 DIB_RGB_COLORS,
611 SRCCOPY);
612 if (del) {
613 delete pToStrechBitmap;
614 }
615 return TRUE;
616 }
617 FX_BOOL CGdiDeviceDriver::GDI_StretchBitMask(const CFX_DIBitmap* pBitmap1,
618 int dest_left,
619 int dest_top,
620 int dest_width,
621 int dest_height,
622 FX_DWORD bitmap_color,
623 FX_DWORD flags,
624 int alpha_flag,
625 void* pIccTransform) {
626 CFX_DIBitmap* pBitmap = (CFX_DIBitmap*)pBitmap1;
627 if (pBitmap == NULL) {
628 return FALSE;
629 }
630 _Color2Argb(
631 bitmap_color, bitmap_color, alpha_flag | (1 << 24), pIccTransform);
632 int width = pBitmap->GetWidth(), height = pBitmap->GetHeight();
633 struct {
634 BITMAPINFOHEADER bmiHeader;
635 FX_DWORD bmiColors[2];
636 } bmi;
637 FXSYS_memset32(&bmi.bmiHeader, 0, sizeof(BITMAPINFOHEADER));
638 bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
639 bmi.bmiHeader.biBitCount = 1;
640 bmi.bmiHeader.biCompression = BI_RGB;
641 bmi.bmiHeader.biHeight = -height;
642 bmi.bmiHeader.biPlanes = 1;
643 bmi.bmiHeader.biWidth = width;
644 if (m_nBitsPerPixel != 1) {
645 SetStretchBltMode(m_hDC, HALFTONE);
646 }
647 bmi.bmiColors[0] = 0xffffff;
648 bmi.bmiColors[1] = 0;
649 ::StretchDIBits(m_hDC,
650 dest_left,
651 dest_top,
652 dest_width,
653 dest_height,
654 0,
655 0,
656 width,
657 height,
658 pBitmap->GetBuffer(),
659 (BITMAPINFO*)&bmi,
660 DIB_RGB_COLORS,
661 SRCAND);
662 return TRUE;
663 }
664 BOOL CGdiDeviceDriver::GetClipBox(FX_RECT* pRect) {
665 return ::GetClipBox(m_hDC, (RECT*)pRect);
666 }
667 FX_BOOL CGdiDeviceDriver::SetClipRgn(FX_LPVOID hRgn) {
668 ::SelectClipRgn(m_hDC, (HRGN)hRgn);
669 return TRUE;
670 }
671 static HPEN _CreatePen(const CFX_GraphStateData* pGraphState,
672 const CFX_AffineMatrix* pMatrix,
673 FX_DWORD argb) {
674 FX_FLOAT width;
675 FX_FLOAT scale = 1.f;
676 if (pMatrix)
677 scale = FXSYS_fabs(pMatrix->a) > FXSYS_fabs(pMatrix->b)
678 ? FXSYS_fabs(pMatrix->a)
679 : FXSYS_fabs(pMatrix->b);
680 if (pGraphState) {
681 width = scale * pGraphState->m_LineWidth;
682 } else {
683 width = 1.0f;
684 }
685 FX_DWORD PenStyle = PS_GEOMETRIC;
686 if (width < 1) {
687 width = 1;
688 }
689 if (pGraphState->m_DashCount) {
690 PenStyle |= PS_USERSTYLE;
691 } else {
692 PenStyle |= PS_SOLID;
693 }
694 switch (pGraphState->m_LineCap) {
695 case 0:
696 PenStyle |= PS_ENDCAP_FLAT;
697 break;
698 case 1:
699 PenStyle |= PS_ENDCAP_ROUND;
700 break;
701 case 2:
702 PenStyle |= PS_ENDCAP_SQUARE;
703 break;
704 }
705 switch (pGraphState->m_LineJoin) {
706 case 0:
707 PenStyle |= PS_JOIN_MITER;
708 break;
709 case 1:
710 PenStyle |= PS_JOIN_ROUND;
711 break;
712 case 2:
713 PenStyle |= PS_JOIN_BEVEL;
714 break;
715 }
716 int a;
717 FX_COLORREF rgb;
718 ArgbDecode(argb, a, rgb);
719 LOGBRUSH lb;
720 lb.lbColor = rgb;
721 lb.lbStyle = BS_SOLID;
722 lb.lbHatch = 0;
723 FX_DWORD* pDash = NULL;
724 if (pGraphState->m_DashCount) {
725 pDash = FX_Alloc(FX_DWORD, pGraphState->m_DashCount);
726 if (!pDash) {
727 return NULL;
728 }
729 for (int i = 0; i < pGraphState->m_DashCount; i++) {
730 pDash[i] = FXSYS_round(
731 pMatrix ? pMatrix->TransformDistance(pGraphState->m_DashArray[i])
732 : pGraphState->m_DashArray[i]);
733 if (pDash[i] < 1) {
734 pDash[i] = 1;
735 }
736 }
737 }
738 HPEN hPen = ExtCreatePen(PenStyle,
739 (DWORD)FXSYS_ceil(width),
740 &lb,
741 pGraphState->m_DashCount,
742 (const DWORD*)pDash);
743 if (pDash) {
744 FX_Free(pDash);
745 }
746 return hPen;
747 }
748 static HBRUSH _CreateBrush(FX_DWORD argb) {
749 int a;
750 FX_COLORREF rgb;
751 ArgbDecode(argb, a, rgb);
752 return CreateSolidBrush(rgb);
753 }
754 static void _SetPathToDC(HDC hDC,
755 const CFX_PathData* pPathData,
756 const CFX_AffineMatrix* pMatrix) {
757 BeginPath(hDC);
758 int nPoints = pPathData->GetPointCount();
759 FX_PATHPOINT* pPoints = pPathData->GetPoints();
760 for (int i = 0; i < nPoints; i++) {
761 FX_FLOAT posx = pPoints[i].m_PointX, posy = pPoints[i].m_PointY;
762 if (pMatrix) {
763 pMatrix->Transform(posx, posy);
764 }
765 int screen_x = FXSYS_round(posx), screen_y = FXSYS_round(posy);
766 int point_type = pPoints[i].m_Flag & FXPT_TYPE;
767 if (point_type == PT_MOVETO) {
768 MoveToEx(hDC, screen_x, screen_y, NULL);
769 } else if (point_type == PT_LINETO) {
770 if (pPoints[i].m_PointY == pPoints[i - 1].m_PointY &&
771 pPoints[i].m_PointX == pPoints[i - 1].m_PointX) {
772 screen_x++;
773 }
774 LineTo(hDC, screen_x, screen_y);
775 } else if (point_type == PT_BEZIERTO) {
776 POINT lppt[3];
777 lppt[0].x = screen_x;
778 lppt[0].y = screen_y;
779 posx = pPoints[i + 1].m_PointX;
780 posy = pPoints[i + 1].m_PointY;
781 if (pMatrix) {
782 pMatrix->Transform(posx, posy);
783 }
784 lppt[1].x = FXSYS_round(posx);
785 lppt[1].y = FXSYS_round(posy);
786 posx = pPoints[i + 2].m_PointX;
787 posy = pPoints[i + 2].m_PointY;
788 if (pMatrix) {
789 pMatrix->Transform(posx, posy);
790 }
791 lppt[2].x = FXSYS_round(posx);
792 lppt[2].y = FXSYS_round(posy);
793 PolyBezierTo(hDC, lppt, 3);
794 i += 2;
795 }
796 if (pPoints[i].m_Flag & PT_CLOSEFIGURE) {
797 CloseFigure(hDC);
798 }
799 }
800 EndPath(hDC);
801 }
802 void CGdiDeviceDriver::DrawLine(FX_FLOAT x1,
803 FX_FLOAT y1,
804 FX_FLOAT x2,
805 FX_FLOAT y2) {
806 int flag1 = (x1 < 0) | ((x1 > m_Width) << 1) | ((y1 < 0) << 2) |
807 ((y1 > m_Height) << 3);
808 int flag2 = (x2 < 0) | ((x2 > m_Width) << 1) | ((y2 < 0) << 2) |
809 ((y2 > m_Height) << 3);
810 if (flag1 & flag2) {
811 return;
812 }
813 if (flag1 || flag2) {
814 agg::rect_base<FX_FLOAT> rect(
815 0.0f, 0.0f, (FX_FLOAT)(m_Width), (FX_FLOAT)(m_Height));
816 FX_FLOAT x[2], y[2];
817 int np = agg::clip_liang_barsky<FX_FLOAT>(x1, y1, x2, y2, rect, x, y);
818 if (np == 0) {
819 return;
820 }
821 if (np == 1) {
822 x2 = x[0];
823 y2 = y[0];
437 } else { 824 } else {
438 m_nBitsPerPixel = ::GetDeviceCaps(m_hDC, BITSPIXEL); 825 x1 = x[0];
439 m_Width = ::GetDeviceCaps(m_hDC, HORZRES); 826 y1 = y[0];
440 m_Height = ::GetDeviceCaps(m_hDC, VERTRES); 827 x2 = x[np - 1];
441 } 828 y2 = y[np - 1];
442 if (m_DeviceClass != FXDC_DISPLAY) { 829 }
443 m_RenderCaps = FXRC_BIT_MASK; 830 }
444 } else { 831 MoveToEx(m_hDC, FXSYS_round(x1), FXSYS_round(y1), NULL);
445 m_RenderCaps = FXRC_GET_BITS | FXRC_BIT_MASK; 832 LineTo(m_hDC, FXSYS_round(x2), FXSYS_round(y2));
446 } 833 }
447 } 834 static FX_BOOL _MatrixNoScaled(const CFX_AffineMatrix* pMatrix) {
448 int CGdiDeviceDriver::GetDeviceCaps(int caps_id) 835 return pMatrix->GetA() == 1.0f && pMatrix->GetB() == 0 &&
449 { 836 pMatrix->GetC() == 0 && pMatrix->GetD() == 1.0f;
450 switch (caps_id) {
451 case FXDC_DEVICE_CLASS:
452 return m_DeviceClass;
453 case FXDC_PIXEL_WIDTH:
454 return m_Width;
455 case FXDC_PIXEL_HEIGHT:
456 return m_Height;
457 case FXDC_BITS_PIXEL:
458 return m_nBitsPerPixel;
459 case FXDC_RENDER_CAPS:
460 return m_RenderCaps;
461 }
462 return 0;
463 }
464 FX_LPVOID CGdiDeviceDriver::GetClipRgn()
465 {
466 HRGN hClipRgn = CreateRectRgn(0, 0, 1, 1);
467 if (::GetClipRgn(m_hDC, hClipRgn) == 0) {
468 DeleteObject(hClipRgn);
469 hClipRgn = NULL;
470 }
471 return (FX_LPVOID)hClipRgn;
472 }
473 FX_BOOL CGdiDeviceDriver::GDI_SetDIBits(const CFX_DIBitmap* pBitmap1, const FX_R ECT* pSrcRect, int left, int top, void* pIccTransform)
474 {
475 if (m_DeviceClass == FXDC_PRINTER) {
476 CFX_DIBitmap* pBitmap = pBitmap1->FlipImage(FALSE, TRUE);
477 if (pBitmap == NULL) {
478 return FALSE;
479 }
480 if ((pBitmap->IsCmykImage() || pIccTransform) &&
481 !pBitmap->ConvertFormat(FXDIB_Rgb, pIccTransform)) {
482 return FALSE;
483 }
484 int width = pSrcRect->Width(), height = pSrcRect->Height();
485 int pitch = pBitmap->GetPitch();
486 LPBYTE pBuffer = pBitmap->GetBuffer();
487 CFX_ByteString info = CFX_WindowsDIB::GetBitmapInfo(pBitmap);
488 ((BITMAPINFOHEADER*)(FX_LPCSTR)info)->biHeight *= -1;
489 FX_RECT dst_rect(0, 0, width, height);
490 dst_rect.Intersect(0, 0, pBitmap->GetWidth(), pBitmap->GetHeight());
491 int dst_width = dst_rect.Width();
492 int dst_height = dst_rect.Height();
493 ::StretchDIBits(m_hDC, left, top, dst_width, dst_height,
494 0, 0, dst_width, dst_height, pBuffer, (BITMAPINFO*)(FX_L PCSTR)info, DIB_RGB_COLORS, SRCCOPY);
495 delete pBitmap;
496 } else {
497 CFX_DIBitmap* pBitmap = (CFX_DIBitmap*)pBitmap1;
498 if ((pBitmap->IsCmykImage() || pIccTransform) &&
499 (pBitmap = pBitmap->CloneConvert(FXDIB_Rgb, NULL, pIccTransform) ) == NULL) {
500 return FALSE;
501 }
502 int width = pSrcRect->Width(), height = pSrcRect->Height();
503 int pitch = pBitmap->GetPitch();
504 LPBYTE pBuffer = pBitmap->GetBuffer();
505 CFX_ByteString info = CFX_WindowsDIB::GetBitmapInfo(pBitmap);
506 ::SetDIBitsToDevice(m_hDC, left, top, width, height, pSrcRect->left, pBi tmap->GetHeight() - pSrcRect->bottom,
507 0, pBitmap->GetHeight(), pBuffer, (BITMAPINFO*)(FX_L PCSTR)info, DIB_RGB_COLORS);
508 if (pBitmap != pBitmap1) {
509 delete pBitmap;
510 }
511 }
512 return TRUE;
513 }
514 FX_BOOL CGdiDeviceDriver::GDI_StretchDIBits(const CFX_DIBitmap* pBitmap1, int de st_left, int dest_top,
515 int dest_width, int dest_height, FX_DWORD flags, void* pIccTransform)
516 {
517 CFX_DIBitmap* pBitmap = (CFX_DIBitmap*)pBitmap1;
518 if (pBitmap == NULL) {
519 return FALSE;
520 }
521 if ((pBitmap->IsCmykImage() || pIccTransform) &&
522 !pBitmap->ConvertFormat(FXDIB_Rgb, pIccTransform)) {
523 return FALSE;
524 }
525 CFX_ByteString info = CFX_WindowsDIB::GetBitmapInfo(pBitmap);
526 if ((FX_INT64)abs(dest_width) * abs(dest_height) < (FX_INT64)pBitmap1->GetWi dth() * pBitmap1->GetHeight() * 4 ||
527 (flags & FXDIB_INTERPOL) || (flags & FXDIB_BICUBIC_INTERPOL)) {
528 SetStretchBltMode(m_hDC, HALFTONE);
529 } else {
530 SetStretchBltMode(m_hDC, COLORONCOLOR);
531 }
532 CFX_DIBitmap* pToStrechBitmap = pBitmap;
533 bool del = false;
534 if (m_DeviceClass == FXDC_PRINTER && ((FX_INT64)pBitmap->GetWidth() * pBitma p->GetHeight() > (FX_INT64)abs(dest_width) * abs(dest_height))) {
535 pToStrechBitmap = pBitmap->StretchTo(dest_width, dest_height);
536 del = true;
537 }
538 CFX_ByteString toStrechBitmapInfo = CFX_WindowsDIB::GetBitmapInfo(pToStrechB itmap);
539 ::StretchDIBits(m_hDC, dest_left, dest_top, dest_width, dest_height,
540 0, 0, pToStrechBitmap->GetWidth(), pToStrechBitmap->GetHeigh t(), pToStrechBitmap->GetBuffer(),
541 (BITMAPINFO*)(FX_LPCSTR)toStrechBitmapInfo, DIB_RGB_COLORS, SRCCOPY);
542 if (del) {
543 delete pToStrechBitmap;
544 }
545 return TRUE;
546 }
547 FX_BOOL CGdiDeviceDriver::GDI_StretchBitMask(const CFX_DIBitmap* pBitmap1, int d est_left, int dest_top,
548 int dest_width, int dest_height, FX_DWORD bitmap_color, FX_DWORD flags,
549 int alpha_flag, void* pIccTransform)
550 {
551 CFX_DIBitmap* pBitmap = (CFX_DIBitmap*)pBitmap1;
552 if (pBitmap == NULL) {
553 return FALSE;
554 }
555 _Color2Argb(bitmap_color, bitmap_color, alpha_flag | (1 << 24), pIccTransfor m);
556 int width = pBitmap->GetWidth(), height = pBitmap->GetHeight();
557 struct {
558 BITMAPINFOHEADER bmiHeader;
559 FX_DWORD bmiColors[2];
560 } bmi;
561 FXSYS_memset32(&bmi.bmiHeader, 0, sizeof (BITMAPINFOHEADER));
562 bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
563 bmi.bmiHeader.biBitCount = 1;
564 bmi.bmiHeader.biCompression = BI_RGB;
565 bmi.bmiHeader.biHeight = -height;
566 bmi.bmiHeader.biPlanes = 1;
567 bmi.bmiHeader.biWidth = width;
568 if (m_nBitsPerPixel != 1) {
569 SetStretchBltMode(m_hDC, HALFTONE);
570 }
571 bmi.bmiColors[0] = 0xffffff;
572 bmi.bmiColors[1] = 0;
573 ::StretchDIBits(m_hDC, dest_left, dest_top, dest_width, dest_height,
574 0, 0, width, height, pBitmap->GetBuffer(), (BITMAPINFO*)&bmi , DIB_RGB_COLORS, SRCAND);
575 return TRUE;
576 }
577 BOOL CGdiDeviceDriver::GetClipBox(FX_RECT* pRect)
578 {
579 return ::GetClipBox(m_hDC, (RECT*)pRect);
580 }
581 FX_BOOL CGdiDeviceDriver::SetClipRgn(FX_LPVOID hRgn)
582 {
583 ::SelectClipRgn(m_hDC, (HRGN)hRgn);
584 return TRUE;
585 }
586 static HPEN _CreatePen(const CFX_GraphStateData* pGraphState, const CFX_AffineMa trix* pMatrix, FX_DWORD argb)
587 {
588 FX_FLOAT width;
589 FX_FLOAT scale = 1.f;
590 if (pMatrix)
591 scale = FXSYS_fabs(pMatrix->a) > FXSYS_fabs(pMatrix->b) ?
592 FXSYS_fabs(pMatrix->a) : FXSYS_fabs(pMatrix->b);
593 if (pGraphState) {
594 width = scale * pGraphState->m_LineWidth;
595 } else {
596 width = 1.0f;
597 }
598 FX_DWORD PenStyle = PS_GEOMETRIC;
599 if (width < 1) {
600 width = 1;
601 }
602 if(pGraphState->m_DashCount) {
603 PenStyle |= PS_USERSTYLE;
604 } else {
605 PenStyle |= PS_SOLID;
606 }
607 switch(pGraphState->m_LineCap) {
608 case 0:
609 PenStyle |= PS_ENDCAP_FLAT;
610 break;
611 case 1:
612 PenStyle |= PS_ENDCAP_ROUND;
613 break;
614 case 2:
615 PenStyle |= PS_ENDCAP_SQUARE;
616 break;
617 }
618 switch(pGraphState->m_LineJoin) {
619 case 0:
620 PenStyle |= PS_JOIN_MITER;
621 break;
622 case 1:
623 PenStyle |= PS_JOIN_ROUND;
624 break;
625 case 2:
626 PenStyle |= PS_JOIN_BEVEL;
627 break;
628 }
629 int a;
630 FX_COLORREF rgb;
631 ArgbDecode(argb, a, rgb);
632 LOGBRUSH lb;
633 lb.lbColor = rgb;
634 lb.lbStyle = BS_SOLID;
635 lb.lbHatch = 0;
636 FX_DWORD* pDash = NULL;
637 if (pGraphState->m_DashCount) {
638 pDash = FX_Alloc(FX_DWORD, pGraphState->m_DashCount);
639 if (!pDash) {
640 return NULL;
641 }
642 for (int i = 0; i < pGraphState->m_DashCount; i ++) {
643 pDash[i] = FXSYS_round(pMatrix ? pMatrix->TransformDistance(pGraphSt ate->m_DashArray[i]) : pGraphState->m_DashArray[i]);
644 if (pDash[i] < 1) {
645 pDash[i] = 1;
646 }
647 }
648 }
649 HPEN hPen = ExtCreatePen(PenStyle, (DWORD)FXSYS_ceil(width), &lb, pGraphStat e->m_DashCount, (const DWORD*)pDash);
650 if (pDash) {
651 FX_Free(pDash);
652 }
653 return hPen;
654 }
655 static HBRUSH _CreateBrush(FX_DWORD argb)
656 {
657 int a;
658 FX_COLORREF rgb;
659 ArgbDecode(argb, a, rgb);
660 return CreateSolidBrush(rgb);
661 }
662 static void _SetPathToDC(HDC hDC, const CFX_PathData* pPathData, const CFX_Affin eMatrix* pMatrix)
663 {
664 BeginPath(hDC);
665 int nPoints = pPathData->GetPointCount();
666 FX_PATHPOINT* pPoints = pPathData->GetPoints();
667 for(int i = 0; i < nPoints; i++) {
668 FX_FLOAT posx = pPoints[i].m_PointX, posy = pPoints[i].m_PointY;
669 if (pMatrix) {
670 pMatrix->Transform(posx, posy);
671 }
672 int screen_x = FXSYS_round(posx), screen_y = FXSYS_round(posy);
673 int point_type = pPoints[i].m_Flag & FXPT_TYPE;
674 if(point_type == PT_MOVETO) {
675 MoveToEx(hDC, screen_x, screen_y, NULL);
676 } else if(point_type == PT_LINETO) {
677 if (pPoints[i].m_PointY == pPoints[i - 1].m_PointY && pPoints[i].m_P ointX == pPoints[i - 1].m_PointX) {
678 screen_x ++;
679 }
680 LineTo(hDC, screen_x, screen_y);
681 } else if(point_type == PT_BEZIERTO) {
682 POINT lppt[3];
683 lppt[0].x = screen_x;
684 lppt[0].y = screen_y;
685 posx = pPoints[i + 1].m_PointX;
686 posy = pPoints[i + 1].m_PointY;
687 if (pMatrix) {
688 pMatrix->Transform(posx, posy);
689 }
690 lppt[1].x = FXSYS_round(posx);
691 lppt[1].y = FXSYS_round(posy);
692 posx = pPoints[i + 2].m_PointX;
693 posy = pPoints[i + 2].m_PointY;
694 if (pMatrix) {
695 pMatrix->Transform(posx, posy);
696 }
697 lppt[2].x = FXSYS_round(posx);
698 lppt[2].y = FXSYS_round(posy);
699 PolyBezierTo(hDC, lppt, 3);
700 i += 2;
701 }
702 if (pPoints[i].m_Flag & PT_CLOSEFIGURE) {
703 CloseFigure(hDC);
704 }
705 }
706 EndPath(hDC);
707 }
708 void CGdiDeviceDriver::DrawLine(FX_FLOAT x1, FX_FLOAT y1, FX_FLOAT x2, FX_FLOAT y2)
709 {
710 int flag1 = (x1 < 0) | ((x1 > m_Width) << 1) | ((y1 < 0) << 2) | ((y1 > m_He ight) << 3);
711 int flag2 = (x2 < 0) | ((x2 > m_Width) << 1) | ((y2 < 0) << 2) | ((y2 > m_He ight) << 3);
712 if (flag1 & flag2) {
713 return;
714 }
715 if (flag1 || flag2) {
716 agg::rect_base<FX_FLOAT> rect(0.0f, 0.0f, (FX_FLOAT)(m_Width), (FX_FLOAT )(m_Height));
717 FX_FLOAT x[2], y[2];
718 int np = agg::clip_liang_barsky<FX_FLOAT>(x1, y1, x2, y2, rect, x, y);
719 if (np == 0) {
720 return;
721 }
722 if (np == 1) {
723 x2 = x[0];
724 y2 = y[0];
725 } else {
726 x1 = x[0];
727 y1 = y[0];
728 x2 = x[np - 1];
729 y2 = y[np - 1];
730 }
731 }
732 MoveToEx(m_hDC, FXSYS_round(x1), FXSYS_round(y1), NULL);
733 LineTo(m_hDC, FXSYS_round(x2), FXSYS_round(y2));
734 }
735 static FX_BOOL _MatrixNoScaled(const CFX_AffineMatrix* pMatrix)
736 {
737 return pMatrix->GetA() == 1.0f && pMatrix->GetB() == 0 && pMatrix->GetC() == 0 && pMatrix->GetD() == 1.0f;
738 } 837 }
739 FX_BOOL CGdiDeviceDriver::DrawPath(const CFX_PathData* pPathData, 838 FX_BOOL CGdiDeviceDriver::DrawPath(const CFX_PathData* pPathData,
740 const CFX_AffineMatrix* pMatrix, 839 const CFX_AffineMatrix* pMatrix,
741 const CFX_GraphStateData* pGraphState, 840 const CFX_GraphStateData* pGraphState,
742 FX_DWORD fill_color, 841 FX_DWORD fill_color,
743 FX_DWORD stroke_color, 842 FX_DWORD stroke_color,
744 int fill_mode, 843 int fill_mode,
745 int alpha_flag, 844 int alpha_flag,
746 void* pIccTransform, 845 void* pIccTransform,
747 int» blend_type 846 int blend_type) {
748 ) 847 if (blend_type != FXDIB_BLEND_NORMAL) {
749 { 848 return FALSE;
750 if (blend_type != FXDIB_BLEND_NORMAL) { 849 }
751 return FALSE; 850 _Color2Argb(fill_color, fill_color, alpha_flag | (1 << 24), pIccTransform);
752 } 851 _Color2Argb(stroke_color, stroke_color, alpha_flag, pIccTransform);
753 _Color2Argb(fill_color, fill_color, alpha_flag | (1 << 24), pIccTransform); 852 CWin32Platform* pPlatform =
754 _Color2Argb(stroke_color, stroke_color, alpha_flag, pIccTransform); 853 (CWin32Platform*)CFX_GEModule::Get()->GetPlatformData();
755 CWin32Platform* pPlatform = (CWin32Platform*)CFX_GEModule::Get()->GetPlatfor mData(); 854 if ((pGraphState == NULL || stroke_color == 0) &&
756 if ((pGraphState == NULL || stroke_color == 0) && !pPlatform->m_GdiplusExt.I sAvailable()) { 855 !pPlatform->m_GdiplusExt.IsAvailable()) {
757 CFX_FloatRect bbox_f = pPathData->GetBoundingBox(); 856 CFX_FloatRect bbox_f = pPathData->GetBoundingBox();
758 if (pMatrix) { 857 if (pMatrix) {
759 bbox_f.Transform(pMatrix); 858 bbox_f.Transform(pMatrix);
859 }
860 FX_RECT bbox = bbox_f.GetInnerRect();
861 if (bbox.Width() <= 0) {
862 return DrawCosmeticLine((FX_FLOAT)(bbox.left),
863 (FX_FLOAT)(bbox.top),
864 (FX_FLOAT)(bbox.left),
865 (FX_FLOAT)(bbox.bottom + 1),
866 fill_color,
867 alpha_flag,
868 pIccTransform,
869 FXDIB_BLEND_NORMAL);
870 } else if (bbox.Height() <= 0) {
871 return DrawCosmeticLine((FX_FLOAT)(bbox.left),
872 (FX_FLOAT)(bbox.top),
873 (FX_FLOAT)(bbox.right + 1),
874 (FX_FLOAT)(bbox.top),
875 fill_color,
876 alpha_flag,
877 pIccTransform,
878 FXDIB_BLEND_NORMAL);
879 }
880 }
881 int fill_alpha = FXARGB_A(fill_color);
882 int stroke_alpha = FXARGB_A(stroke_color);
883 FX_BOOL bDrawAlpha = (fill_alpha > 0 && fill_alpha < 255) ||
884 (stroke_alpha > 0 && stroke_alpha < 255 && pGraphState);
885 if (!pPlatform->m_GdiplusExt.IsAvailable() && bDrawAlpha) {
886 return FALSE;
887 }
888 if (pPlatform->m_GdiplusExt.IsAvailable()) {
889 if (bDrawAlpha ||
890 ((m_DeviceClass != FXDC_PRINTER && !(fill_mode & FXFILL_FULLCOVER)) ||
891 pGraphState && pGraphState->m_DashCount)) {
892 if (!((NULL == pMatrix || _MatrixNoScaled(pMatrix)) && pGraphState &&
893 pGraphState->m_LineWidth == 1.f &&
894 (pPathData->GetPointCount() == 5 ||
895 pPathData->GetPointCount() == 4) &&
896 pPathData->IsRect())) {
897 if (pPlatform->m_GdiplusExt.DrawPath(m_hDC,
898 pPathData,
899 pMatrix,
900 pGraphState,
901 fill_color,
902 stroke_color,
903 fill_mode)) {
904 return TRUE;
760 } 905 }
761 FX_RECT bbox = bbox_f.GetInnerRect(); 906 }
762 if (bbox.Width() <= 0) { 907 }
763 return DrawCosmeticLine((FX_FLOAT)(bbox.left), (FX_FLOAT)(bbox.top), (FX_FLOAT)(bbox.left), (FX_FLOAT)(bbox.bottom + 1), fill_color, 908 }
764 alpha_flag, pIccTransform, FXDIB_BLEND_NORMA L); 909 int old_fill_mode = fill_mode;
765 } else if (bbox.Height() <= 0) { 910 fill_mode &= 3;
766 return DrawCosmeticLine((FX_FLOAT)(bbox.left), (FX_FLOAT)(bbox.top), (FX_FLOAT)(bbox.right + 1), (FX_FLOAT)(bbox.top), fill_color, 911 HPEN hPen = NULL;
767 alpha_flag, pIccTransform, FXDIB_BLEND_NORMA L); 912 HBRUSH hBrush = NULL;
913 if (pGraphState && stroke_alpha) {
914 SetMiterLimit(m_hDC, pGraphState->m_MiterLimit, NULL);
915 hPen = _CreatePen(pGraphState, pMatrix, stroke_color);
916 hPen = (HPEN)SelectObject(m_hDC, hPen);
917 }
918 if (fill_mode && fill_alpha) {
919 SetPolyFillMode(m_hDC, fill_mode);
920 hBrush = _CreateBrush(fill_color);
921 hBrush = (HBRUSH)SelectObject(m_hDC, hBrush);
922 }
923 if (pPathData->GetPointCount() == 2 && pGraphState &&
924 pGraphState->m_DashCount) {
925 FX_FLOAT x1 = pPathData->GetPointX(0), y1 = pPathData->GetPointY(0);
926 if (pMatrix) {
927 pMatrix->Transform(x1, y1);
928 }
929 FX_FLOAT x2 = pPathData->GetPointX(1), y2 = pPathData->GetPointY(1);
930 if (pMatrix) {
931 pMatrix->Transform(x2, y2);
932 }
933 DrawLine(x1, y1, x2, y2);
934 } else {
935 _SetPathToDC(m_hDC, pPathData, pMatrix);
936 if (pGraphState && stroke_alpha) {
937 if (fill_mode && fill_alpha) {
938 if (old_fill_mode & FX_FILL_TEXT_MODE) {
939 StrokeAndFillPath(m_hDC);
940 } else {
941 FillPath(m_hDC);
942 _SetPathToDC(m_hDC, pPathData, pMatrix);
943 StrokePath(m_hDC);
768 } 944 }
769 } 945 } else {
770 int fill_alpha = FXARGB_A(fill_color); 946 StrokePath(m_hDC);
771 int stroke_alpha = FXARGB_A(stroke_color); 947 }
772 FX_BOOL bDrawAlpha = (fill_alpha > 0 && fill_alpha < 255) || (stroke_alpha > 0 && stroke_alpha < 255 && pGraphState); 948 } else if (fill_mode && fill_alpha) {
773 if (!pPlatform->m_GdiplusExt.IsAvailable() && bDrawAlpha) { 949 FillPath(m_hDC);
774 return FALSE; 950 }
775 } 951 }
776 if (pPlatform->m_GdiplusExt.IsAvailable()) { 952 if (hPen) {
777 if (bDrawAlpha || ((m_DeviceClass != FXDC_PRINTER && !(fill_mode & FXFIL L_FULLCOVER)) || pGraphState && pGraphState->m_DashCount)) {
778 if ( !((NULL == pMatrix || _MatrixNoScaled(pMatrix)) &&
779 pGraphState && pGraphState->m_LineWidth == 1.f &&
780 (pPathData->GetPointCount() == 5 || pPathData->GetPointCount () == 4) &&
781 pPathData->IsRect()) ) {
782 if (pPlatform->m_GdiplusExt.DrawPath(m_hDC, pPathData, pMatrix, pGraphState, fill_color, stroke_color, fill_mode)) {
783 return TRUE;
784 }
785 }
786 }
787 }
788 int old_fill_mode = fill_mode;
789 fill_mode &= 3;
790 HPEN hPen = NULL;
791 HBRUSH hBrush = NULL;
792 if (pGraphState && stroke_alpha) {
793 SetMiterLimit(m_hDC, pGraphState->m_MiterLimit, NULL);
794 hPen = _CreatePen(pGraphState, pMatrix, stroke_color);
795 hPen = (HPEN)SelectObject(m_hDC, hPen);
796 }
797 if (fill_mode && fill_alpha) {
798 SetPolyFillMode(m_hDC, fill_mode);
799 hBrush = _CreateBrush(fill_color);
800 hBrush = (HBRUSH)SelectObject(m_hDC, hBrush);
801 }
802 if (pPathData->GetPointCount() == 2 && pGraphState && pGraphState->m_DashCou nt) {
803 FX_FLOAT x1 = pPathData->GetPointX(0), y1 = pPathData->GetPointY(0);
804 if (pMatrix) {
805 pMatrix->Transform(x1, y1);
806 }
807 FX_FLOAT x2 = pPathData->GetPointX(1), y2 = pPathData->GetPointY(1);
808 if (pMatrix) {
809 pMatrix->Transform(x2, y2);
810 }
811 DrawLine(x1, y1, x2, y2);
812 } else {
813 _SetPathToDC(m_hDC, pPathData, pMatrix);
814 if (pGraphState && stroke_alpha) {
815 if (fill_mode && fill_alpha) {
816 if (old_fill_mode & FX_FILL_TEXT_MODE) {
817 StrokeAndFillPath(m_hDC);
818 } else {
819 FillPath(m_hDC);
820 _SetPathToDC(m_hDC, pPathData, pMatrix);
821 StrokePath(m_hDC);
822 }
823 } else {
824 StrokePath(m_hDC);
825 }
826 } else if (fill_mode && fill_alpha) {
827 FillPath(m_hDC);
828 }
829 }
830 if (hPen) {
831 hPen = (HPEN)SelectObject(m_hDC, hPen);
832 DeleteObject(hPen);
833 }
834 if (hBrush) {
835 hBrush = (HBRUSH)SelectObject(m_hDC, hBrush);
836 DeleteObject(hBrush);
837 }
838 return TRUE;
839 }
840 FX_BOOL CGdiDeviceDriver::FillRect(const FX_RECT* pRect, FX_DWORD fill_color, in t alpha_flag, void* pIccTransform, int blend_type)
841 {
842 if (blend_type != FXDIB_BLEND_NORMAL) {
843 return FALSE;
844 }
845 _Color2Argb(fill_color, fill_color, alpha_flag | (1 << 24), pIccTransform);
846 int alpha;
847 FX_COLORREF rgb;
848 ArgbDecode(fill_color, alpha, rgb);
849 if (alpha == 0) {
850 return TRUE;
851 }
852 if (alpha < 255) {
853 return FALSE;
854 }
855 HBRUSH hBrush = CreateSolidBrush(rgb);
856 ::FillRect(m_hDC, (RECT*)pRect, hBrush);
857 DeleteObject(hBrush);
858 return TRUE;
859 }
860 FX_BOOL CGdiDeviceDriver::SetClip_PathFill(const CFX_PathData* pPathData,
861 const CFX_AffineMatrix* pMatrix,
862 int fill_mode
863 )
864 {
865 if (pPathData->GetPointCount() == 5) {
866 CFX_FloatRect rectf;
867 if (pPathData->IsRect(pMatrix, &rectf)) {
868 FX_RECT rect = rectf.GetOutterRect();
869 IntersectClipRect(m_hDC, rect.left, rect.top, rect.right, rect.botto m);
870 return TRUE;
871 }
872 }
873 _SetPathToDC(m_hDC, pPathData, pMatrix);
874 SetPolyFillMode(m_hDC, fill_mode & 3);
875 SelectClipPath(m_hDC, RGN_AND);
876 return TRUE;
877 }
878 FX_BOOL CGdiDeviceDriver::SetClip_PathStroke(const CFX_PathData* pPathData,
879 const CFX_AffineMatrix* pMatrix,
880 const CFX_GraphStateData* pGraphState
881 )
882 {
883 HPEN hPen = _CreatePen(pGraphState, pMatrix, 0xff000000);
884 hPen = (HPEN)SelectObject(m_hDC, hPen);
885 _SetPathToDC(m_hDC, pPathData, pMatrix);
886 WidenPath(m_hDC);
887 SetPolyFillMode(m_hDC, WINDING);
888 FX_BOOL ret = SelectClipPath(m_hDC, RGN_AND);
889 hPen = (HPEN)SelectObject(m_hDC, hPen); 953 hPen = (HPEN)SelectObject(m_hDC, hPen);
890 DeleteObject(hPen); 954 DeleteObject(hPen);
955 }
956 if (hBrush) {
957 hBrush = (HBRUSH)SelectObject(m_hDC, hBrush);
958 DeleteObject(hBrush);
959 }
960 return TRUE;
961 }
962 FX_BOOL CGdiDeviceDriver::FillRect(const FX_RECT* pRect,
963 FX_DWORD fill_color,
964 int alpha_flag,
965 void* pIccTransform,
966 int blend_type) {
967 if (blend_type != FXDIB_BLEND_NORMAL) {
968 return FALSE;
969 }
970 _Color2Argb(fill_color, fill_color, alpha_flag | (1 << 24), pIccTransform);
971 int alpha;
972 FX_COLORREF rgb;
973 ArgbDecode(fill_color, alpha, rgb);
974 if (alpha == 0) {
975 return TRUE;
976 }
977 if (alpha < 255) {
978 return FALSE;
979 }
980 HBRUSH hBrush = CreateSolidBrush(rgb);
981 ::FillRect(m_hDC, (RECT*)pRect, hBrush);
982 DeleteObject(hBrush);
983 return TRUE;
984 }
985 FX_BOOL CGdiDeviceDriver::SetClip_PathFill(const CFX_PathData* pPathData,
986 const CFX_AffineMatrix* pMatrix,
987 int fill_mode) {
988 if (pPathData->GetPointCount() == 5) {
989 CFX_FloatRect rectf;
990 if (pPathData->IsRect(pMatrix, &rectf)) {
991 FX_RECT rect = rectf.GetOutterRect();
992 IntersectClipRect(m_hDC, rect.left, rect.top, rect.right, rect.bottom);
993 return TRUE;
994 }
995 }
996 _SetPathToDC(m_hDC, pPathData, pMatrix);
997 SetPolyFillMode(m_hDC, fill_mode & 3);
998 SelectClipPath(m_hDC, RGN_AND);
999 return TRUE;
1000 }
1001 FX_BOOL CGdiDeviceDriver::SetClip_PathStroke(
1002 const CFX_PathData* pPathData,
1003 const CFX_AffineMatrix* pMatrix,
1004 const CFX_GraphStateData* pGraphState) {
1005 HPEN hPen = _CreatePen(pGraphState, pMatrix, 0xff000000);
1006 hPen = (HPEN)SelectObject(m_hDC, hPen);
1007 _SetPathToDC(m_hDC, pPathData, pMatrix);
1008 WidenPath(m_hDC);
1009 SetPolyFillMode(m_hDC, WINDING);
1010 FX_BOOL ret = SelectClipPath(m_hDC, RGN_AND);
1011 hPen = (HPEN)SelectObject(m_hDC, hPen);
1012 DeleteObject(hPen);
1013 return ret;
1014 }
1015 FX_BOOL CGdiDeviceDriver::DrawCosmeticLine(FX_FLOAT x1,
1016 FX_FLOAT y1,
1017 FX_FLOAT x2,
1018 FX_FLOAT y2,
1019 FX_DWORD color,
1020 int alpha_flag,
1021 void* pIccTransform,
1022 int blend_type) {
1023 if (blend_type != FXDIB_BLEND_NORMAL) {
1024 return FALSE;
1025 }
1026 _Color2Argb(color, color, alpha_flag | (1 << 24), pIccTransform);
1027 int a;
1028 FX_COLORREF rgb;
1029 ArgbDecode(color, a, rgb);
1030 if (a == 0) {
1031 return TRUE;
1032 }
1033 HPEN hPen = CreatePen(PS_SOLID, 1, rgb);
1034 hPen = (HPEN)SelectObject(m_hDC, hPen);
1035 MoveToEx(m_hDC, FXSYS_round(x1), FXSYS_round(y1), NULL);
1036 LineTo(m_hDC, FXSYS_round(x2), FXSYS_round(y2));
1037 hPen = (HPEN)SelectObject(m_hDC, hPen);
1038 DeleteObject(hPen);
1039 return TRUE;
1040 }
1041 FX_BOOL CGdiDeviceDriver::DeleteDeviceRgn(FX_LPVOID pRgn) {
1042 DeleteObject((HGDIOBJ)pRgn);
1043 return TRUE;
1044 }
1045 CGdiDisplayDriver::CGdiDisplayDriver(HDC hDC)
1046 : CGdiDeviceDriver(hDC, FXDC_DISPLAY) {
1047 CWin32Platform* pPlatform =
1048 (CWin32Platform*)CFX_GEModule::Get()->GetPlatformData();
1049 if (pPlatform->m_GdiplusExt.IsAvailable()) {
1050 m_RenderCaps |= FXRC_ALPHA_PATH | FXRC_ALPHA_IMAGE;
1051 }
1052 }
1053 FX_BOOL CGdiDisplayDriver::GetDIBits(CFX_DIBitmap* pBitmap,
1054 int left,
1055 int top,
1056 void* pIccTransform,
1057 FX_BOOL bDEdge) {
1058 FX_BOOL ret = FALSE;
1059 int width = pBitmap->GetWidth();
1060 int height = pBitmap->GetHeight();
1061 HBITMAP hbmp = CreateCompatibleBitmap(m_hDC, width, height);
1062 HDC hDCMemory = CreateCompatibleDC(m_hDC);
1063 HBITMAP holdbmp = (HBITMAP)SelectObject(hDCMemory, hbmp);
1064 BitBlt(hDCMemory, 0, 0, width, height, m_hDC, left, top, SRCCOPY);
1065 SelectObject(hDCMemory, holdbmp);
1066 BITMAPINFO bmi;
1067 FXSYS_memset32(&bmi, 0, sizeof bmi);
1068 bmi.bmiHeader.biSize = sizeof bmi.bmiHeader;
1069 bmi.bmiHeader.biBitCount = pBitmap->GetBPP();
1070 bmi.bmiHeader.biHeight = -height;
1071 bmi.bmiHeader.biPlanes = 1;
1072 bmi.bmiHeader.biWidth = width;
1073 if (!CFX_GEModule::Get()->GetCodecModule() ||
1074 !CFX_GEModule::Get()->GetCodecModule()->GetIccModule()) {
1075 pIccTransform = NULL;
1076 }
1077 if (pBitmap->GetBPP() > 8 && !pBitmap->IsCmykImage() &&
1078 pIccTransform == NULL) {
1079 ret = ::GetDIBits(hDCMemory,
1080 hbmp,
1081 0,
1082 height,
1083 pBitmap->GetBuffer(),
1084 &bmi,
1085 DIB_RGB_COLORS) == height;
1086 } else {
1087 CFX_DIBitmap bitmap;
1088 if (bitmap.Create(width, height, FXDIB_Rgb)) {
1089 bmi.bmiHeader.biBitCount = 24;
1090 ::GetDIBits(
1091 hDCMemory, hbmp, 0, height, bitmap.GetBuffer(), &bmi, DIB_RGB_COLORS);
1092 ret = pBitmap->TransferBitmap(
1093 0, 0, width, height, &bitmap, 0, 0, pIccTransform);
1094 } else {
1095 ret = FALSE;
1096 }
1097 }
1098 #ifndef _FPDFAPI_MINI_
1099 if (pBitmap->HasAlpha() && ret) {
1100 pBitmap->LoadChannel(FXDIB_Alpha, 0xff);
1101 }
1102 #endif
1103 DeleteObject(hbmp);
1104 DeleteObject(hDCMemory);
1105 return ret;
1106 }
1107 FX_BOOL CGdiDisplayDriver::SetDIBits(const CFX_DIBSource* pSource,
1108 FX_DWORD color,
1109 const FX_RECT* pSrcRect,
1110 int left,
1111 int top,
1112 int blend_type,
1113 int alpha_flag,
1114 void* pIccTransform) {
1115 ASSERT(blend_type == FXDIB_BLEND_NORMAL);
1116 if (pSource->IsAlphaMask()) {
1117 int width = pSource->GetWidth(), height = pSource->GetHeight();
1118 int alpha = FXGETFLAG_COLORTYPE(alpha_flag)
1119 ? FXGETFLAG_ALPHA_FILL(alpha_flag)
1120 : FXARGB_A(color);
1121 FX_BOOL bGDI = pSource->GetBPP() == 1 && alpha == 255;
1122 if (!bGDI) {
1123 CFX_DIBitmap background;
1124 if (!background.Create(width, height, FXDIB_Rgb32) ||
1125 !GetDIBits(&background, left, top, NULL) ||
1126 !background.CompositeMask(0,
1127 0,
1128 width,
1129 height,
1130 pSource,
1131 color,
1132 0,
1133 0,
1134 FXDIB_BLEND_NORMAL,
1135 NULL,
1136 FALSE,
1137 alpha_flag,
1138 pIccTransform)) {
1139 return FALSE;
1140 }
1141 FX_RECT src_rect(0, 0, width, height);
1142 return SetDIBits(
1143 &background, 0, &src_rect, left, top, FXDIB_BLEND_NORMAL, 0, NULL);
1144 }
1145 FX_RECT clip_rect(
1146 left, top, left + pSrcRect->Width(), top + pSrcRect->Height());
1147 return StretchDIBits(pSource,
1148 color,
1149 left - pSrcRect->left,
1150 top - pSrcRect->top,
1151 width,
1152 height,
1153 &clip_rect,
1154 0,
1155 alpha_flag,
1156 pIccTransform,
1157 FXDIB_BLEND_NORMAL);
1158 } else {
1159 int width = pSrcRect->Width(), height = pSrcRect->Height();
1160 if (pSource->HasAlpha()) {
1161 CFX_DIBitmap bitmap;
1162 if (!bitmap.Create(width, height, FXDIB_Rgb) ||
1163 !GetDIBits(&bitmap, left, top, NULL) ||
1164 !bitmap.CompositeBitmap(0,
1165 0,
1166 width,
1167 height,
1168 pSource,
1169 pSrcRect->left,
1170 pSrcRect->top,
1171 FXDIB_BLEND_NORMAL,
1172 NULL,
1173 FALSE,
1174 pIccTransform)) {
1175 return FALSE;
1176 }
1177 FX_RECT src_rect(0, 0, width, height);
1178 return SetDIBits(
1179 &bitmap, 0, &src_rect, left, top, FXDIB_BLEND_NORMAL, 0, NULL);
1180 }
1181 CFX_DIBExtractor temp(pSource);
1182 CFX_DIBitmap* pBitmap = temp;
1183 if (pBitmap) {
1184 return GDI_SetDIBits(pBitmap, pSrcRect, left, top, pIccTransform);
1185 }
1186 }
1187 return FALSE;
1188 }
1189 FX_BOOL CGdiDisplayDriver::UseFoxitStretchEngine(const CFX_DIBSource* pSource,
1190 FX_DWORD color,
1191 int dest_left,
1192 int dest_top,
1193 int dest_width,
1194 int dest_height,
1195 const FX_RECT* pClipRect,
1196 int render_flags,
1197 int alpha_flag,
1198 void* pIccTransform,
1199 int blend_type) {
1200 FX_RECT bitmap_clip = *pClipRect;
1201 if (dest_width < 0) {
1202 dest_left += dest_width;
1203 }
1204 if (dest_height < 0) {
1205 dest_top += dest_height;
1206 }
1207 bitmap_clip.Offset(-dest_left, -dest_top);
1208 CFX_DIBitmap* pStretched =
1209 pSource->StretchTo(dest_width, dest_height, render_flags, &bitmap_clip);
1210 if (pStretched == NULL) {
1211 return TRUE;
1212 }
1213 FX_RECT src_rect(0, 0, pStretched->GetWidth(), pStretched->GetHeight());
1214 FX_BOOL ret = SetDIBits(pStretched,
1215 color,
1216 &src_rect,
1217 pClipRect->left,
1218 pClipRect->top,
1219 FXDIB_BLEND_NORMAL,
1220 alpha_flag,
1221 pIccTransform);
1222 delete pStretched;
1223 return ret;
1224 }
1225 FX_BOOL CGdiDisplayDriver::StretchDIBits(const CFX_DIBSource* pSource,
1226 FX_DWORD color,
1227 int dest_left,
1228 int dest_top,
1229 int dest_width,
1230 int dest_height,
1231 const FX_RECT* pClipRect,
1232 FX_DWORD flags,
1233 int alpha_flag,
1234 void* pIccTransform,
1235 int blend_type) {
1236 ASSERT(pSource != NULL && pClipRect != NULL);
1237 if (flags || dest_width > 10000 || dest_width < -10000 ||
1238 dest_height > 10000 || dest_height < -10000)
1239 return UseFoxitStretchEngine(pSource,
1240 color,
1241 dest_left,
1242 dest_top,
1243 dest_width,
1244 dest_height,
1245 pClipRect,
1246 flags,
1247 alpha_flag,
1248 pIccTransform,
1249 blend_type);
1250 if (pSource->IsAlphaMask()) {
1251 FX_RECT image_rect;
1252 image_rect.left = dest_width > 0 ? dest_left : dest_left + dest_width;
1253 image_rect.right = dest_width > 0 ? dest_left + dest_width : dest_left;
1254 image_rect.top = dest_height > 0 ? dest_top : dest_top + dest_height;
1255 image_rect.bottom = dest_height > 0 ? dest_top + dest_height : dest_top;
1256 FX_RECT clip_rect = image_rect;
1257 clip_rect.Intersect(*pClipRect);
1258 clip_rect.Offset(-image_rect.left, -image_rect.top);
1259 int clip_width = clip_rect.Width(), clip_height = clip_rect.Height();
1260 CFX_DIBitmap* pStretched =
1261 pSource->StretchTo(dest_width, dest_height, flags, &clip_rect);
1262 if (pStretched == NULL) {
1263 return TRUE;
1264 }
1265 CFX_DIBitmap background;
1266 if (!background.Create(clip_width, clip_height, FXDIB_Rgb32) ||
1267 !GetDIBits(&background,
1268 image_rect.left + clip_rect.left,
1269 image_rect.top + clip_rect.top,
1270 NULL) ||
1271 !background.CompositeMask(0,
1272 0,
1273 clip_width,
1274 clip_height,
1275 pStretched,
1276 color,
1277 0,
1278 0,
1279 FXDIB_BLEND_NORMAL,
1280 NULL,
1281 FALSE,
1282 alpha_flag,
1283 pIccTransform)) {
1284 delete pStretched;
1285 return FALSE;
1286 }
1287 FX_RECT src_rect(0, 0, clip_width, clip_height);
1288 FX_BOOL ret = SetDIBits(&background,
1289 0,
1290 &src_rect,
1291 image_rect.left + clip_rect.left,
1292 image_rect.top + clip_rect.top,
1293 FXDIB_BLEND_NORMAL,
1294 0,
1295 NULL);
1296 delete pStretched;
891 return ret; 1297 return ret;
892 } 1298 } else {
893 FX_BOOL CGdiDeviceDriver::DrawCosmeticLine(FX_FLOAT x1, FX_FLOAT y1, FX_FLOAT x2 , FX_FLOAT y2, FX_DWORD color, 1299 if (pSource->HasAlpha()) {
894 int alpha_flag, void* pIccTransform, int» blend_type) 1300 CWin32Platform* pPlatform =
895 { 1301 (CWin32Platform*)CFX_GEModule::Get()->GetPlatformData();
896 if (blend_type != FXDIB_BLEND_NORMAL) { 1302 if (pPlatform->m_GdiplusExt.IsAvailable() && pIccTransform == NULL &&
897 return FALSE; 1303 !pSource->IsCmykImage()) {
898 }
899 _Color2Argb(color, color, alpha_flag | (1 << 24), pIccTransform);
900 int a;
901 FX_COLORREF rgb;
902 ArgbDecode(color, a, rgb);
903 if (a == 0) {
904 return TRUE;
905 }
906 HPEN hPen = CreatePen(PS_SOLID, 1, rgb);
907 hPen = (HPEN)SelectObject(m_hDC, hPen);
908 MoveToEx(m_hDC, FXSYS_round(x1), FXSYS_round(y1), NULL);
909 LineTo(m_hDC, FXSYS_round(x2), FXSYS_round(y2));
910 hPen = (HPEN)SelectObject(m_hDC, hPen);
911 DeleteObject(hPen);
912 return TRUE;
913 }
914 FX_BOOL CGdiDeviceDriver::DeleteDeviceRgn(FX_LPVOID pRgn)
915 {
916 DeleteObject((HGDIOBJ)pRgn);
917 return TRUE;
918 }
919 CGdiDisplayDriver::CGdiDisplayDriver(HDC hDC) : CGdiDeviceDriver(hDC, FXDC_DISPL AY)
920 {
921 CWin32Platform* pPlatform = (CWin32Platform*)CFX_GEModule::Get()->GetPlatfor mData();
922 if (pPlatform->m_GdiplusExt.IsAvailable()) {
923 m_RenderCaps |= FXRC_ALPHA_PATH | FXRC_ALPHA_IMAGE;
924 }
925 }
926 FX_BOOL CGdiDisplayDriver::GetDIBits(CFX_DIBitmap* pBitmap, int left, int top, v oid* pIccTransform, FX_BOOL bDEdge)
927 {
928 FX_BOOL ret = FALSE;
929 int width = pBitmap->GetWidth();
930 int height = pBitmap->GetHeight();
931 HBITMAP hbmp = CreateCompatibleBitmap(m_hDC, width, height);
932 HDC hDCMemory = CreateCompatibleDC(m_hDC);
933 HBITMAP holdbmp = (HBITMAP)SelectObject(hDCMemory, hbmp);
934 BitBlt(hDCMemory, 0, 0, width, height, m_hDC, left, top, SRCCOPY);
935 SelectObject(hDCMemory, holdbmp);
936 BITMAPINFO bmi;
937 FXSYS_memset32(&bmi, 0, sizeof bmi);
938 bmi.bmiHeader.biSize = sizeof bmi.bmiHeader;
939 bmi.bmiHeader.biBitCount = pBitmap->GetBPP();
940 bmi.bmiHeader.biHeight = -height;
941 bmi.bmiHeader.biPlanes = 1;
942 bmi.bmiHeader.biWidth = width;
943 if (!CFX_GEModule::Get()->GetCodecModule() || !CFX_GEModule::Get()->GetCodec Module()->GetIccModule()) {
944 pIccTransform = NULL;
945 }
946 if (pBitmap->GetBPP() > 8 && !pBitmap->IsCmykImage() && pIccTransform == NUL L) {
947 ret = ::GetDIBits(hDCMemory, hbmp, 0, height, pBitmap->GetBuffer(), &bmi , DIB_RGB_COLORS) == height;
948 } else {
949 CFX_DIBitmap bitmap;
950 if (bitmap.Create(width, height, FXDIB_Rgb)) {
951 bmi.bmiHeader.biBitCount = 24;
952 ::GetDIBits(hDCMemory, hbmp, 0, height, bitmap.GetBuffer(), &bmi, DI B_RGB_COLORS);
953 ret = pBitmap->TransferBitmap(0, 0, width, height, &bitmap, 0, 0, pI ccTransform);
954 } else {
955 ret = FALSE;
956 }
957 }
958 #ifndef _FPDFAPI_MINI_
959 if (pBitmap->HasAlpha() && ret) {
960 pBitmap->LoadChannel(FXDIB_Alpha, 0xff);
961 }
962 #endif
963 DeleteObject(hbmp);
964 DeleteObject(hDCMemory);
965 return ret;
966 }
967 FX_BOOL CGdiDisplayDriver::SetDIBits(const CFX_DIBSource* pSource, FX_DWORD colo r, const FX_RECT* pSrcRect, int left, int top, int blend_type,
968 int alpha_flag, void* pIccTransform)
969 {
970 ASSERT(blend_type == FXDIB_BLEND_NORMAL);
971 if (pSource->IsAlphaMask()) {
972 int width = pSource->GetWidth(), height = pSource->GetHeight();
973 int alpha = FXGETFLAG_COLORTYPE(alpha_flag) ? FXGETFLAG_ALPHA_FILL(alpha _flag) : FXARGB_A(color);
974 FX_BOOL bGDI = pSource->GetBPP() == 1 && alpha == 255;
975 if (!bGDI) {
976 CFX_DIBitmap background;
977 if (!background.Create(width, height, FXDIB_Rgb32) ||
978 !GetDIBits(&background, left, top, NULL) ||
979 !background.CompositeMask(0, 0, width, height, pSource, colo r, 0, 0, FXDIB_BLEND_NORMAL, NULL, FALSE, alpha_flag, pIccTransform)) {
980 return FALSE;
981 }
982 FX_RECT src_rect(0, 0, width, height);
983 return SetDIBits(&background, 0, &src_rect, left, top, FXDIB_BLEND_N ORMAL, 0, NULL);
984 }
985 FX_RECT clip_rect(left, top, left + pSrcRect->Width(), top + pSrcRect->H eight());
986 return StretchDIBits(pSource, color, left - pSrcRect->left, top - pSrcRe ct->top, width, height,
987 &clip_rect, 0, alpha_flag, pIccTransform, FXDIB_BLE ND_NORMAL);
988 } else {
989 int width = pSrcRect->Width(), height = pSrcRect->Height();
990 if (pSource->HasAlpha()) {
991 CFX_DIBitmap bitmap;
992 if (!bitmap.Create(width, height, FXDIB_Rgb) ||
993 !GetDIBits(&bitmap, left, top, NULL) ||
994 !bitmap.CompositeBitmap(0, 0, width, height, pSource, pSrcRe ct->left, pSrcRect->top, FXDIB_BLEND_NORMAL, NULL, FALSE, pIccTransform)) {
995 return FALSE;
996 }
997 FX_RECT src_rect(0, 0, width, height);
998 return SetDIBits(&bitmap, 0, &src_rect, left, top, FXDIB_BLEND_NORMA L, 0, NULL);
999 }
1000 CFX_DIBExtractor temp(pSource); 1304 CFX_DIBExtractor temp(pSource);
1001 CFX_DIBitmap* pBitmap = temp; 1305 CFX_DIBitmap* pBitmap = temp;
1002 if (pBitmap) { 1306 if (pBitmap == NULL) {
1003 return GDI_SetDIBits(pBitmap, pSrcRect, left, top, pIccTransform); 1307 return FALSE;
1004 } 1308 }
1005 } 1309 return pPlatform->m_GdiplusExt.StretchDIBits(m_hDC,
1006 return FALSE; 1310 pBitmap,
1007 } 1311 dest_left,
1008 FX_BOOL CGdiDisplayDriver::UseFoxitStretchEngine(const CFX_DIBSource* pSource, F X_DWORD color, int dest_left, int dest_top, 1312 dest_top,
1009 int dest_width, int dest_height, const FX_RECT* pClipRect, int render_fl ags, 1313 dest_width,
1010 int alpha_flag, void* pIccTransform, int blend_type) 1314 dest_height,
1011 { 1315 pClipRect,
1012 FX_RECT bitmap_clip = *pClipRect; 1316 flags);
1013 if (dest_width < 0) { 1317 }
1014 dest_left += dest_width; 1318 return UseFoxitStretchEngine(pSource,
1015 } 1319 color,
1016 if (dest_height < 0) { 1320 dest_left,
1017 dest_top += dest_height; 1321 dest_top,
1018 } 1322 dest_width,
1019 bitmap_clip.Offset(-dest_left, -dest_top); 1323 dest_height,
1020 CFX_DIBitmap* pStretched = pSource->StretchTo(dest_width, dest_height, rende r_flags, &bitmap_clip); 1324 pClipRect,
1021 if (pStretched == NULL) { 1325 flags,
1022 return TRUE; 1326 alpha_flag,
1023 } 1327 pIccTransform,
1024 FX_RECT src_rect(0, 0, pStretched->GetWidth(), pStretched->GetHeight()); 1328 blend_type);
1025 FX_BOOL ret = SetDIBits(pStretched, color, &src_rect, pClipRect->left, pClip Rect->top, FXDIB_BLEND_NORMAL, alpha_flag, pIccTransform); 1329 }
1026 delete pStretched; 1330 CFX_DIBExtractor temp(pSource);
1027 return ret; 1331 CFX_DIBitmap* pBitmap = temp;
1028 } 1332 if (pBitmap) {
1029 FX_BOOL CGdiDisplayDriver::StretchDIBits(const CFX_DIBSource* pSource, FX_DWORD color, int dest_left, int dest_top, 1333 return GDI_StretchDIBits(pBitmap,
1030 int dest_width, int dest_height, const FX_RECT* pClipRect, FX_DWORD flag s, 1334 dest_left,
1031 int alpha_flag, void* pIccTransform, int blend_type) 1335 dest_top,
1032 { 1336 dest_width,
1033 ASSERT(pSource != NULL && pClipRect != NULL); 1337 dest_height,
1034 if (flags || dest_width > 10000 || dest_width < -10000 || dest_height > 1000 0 || dest_height < -10000) 1338 flags,
1035 return UseFoxitStretchEngine(pSource, color, dest_left, dest_top, dest_w idth, dest_height, 1339 pIccTransform);
1036 pClipRect, flags, alpha_flag, pIccTransform , blend_type); 1340 }
1037 if (pSource->IsAlphaMask()) { 1341 }
1038 FX_RECT image_rect; 1342 return FALSE;
1039 image_rect.left = dest_width > 0 ? dest_left : dest_left + dest_width; 1343 }
1040 image_rect.right = dest_width > 0 ? dest_left + dest_width : dest_left; 1344 #define GET_PS_FEATURESETTING 4121
1041 image_rect.top = dest_height > 0 ? dest_top : dest_top + dest_height; 1345 #define FEATURESETTING_PSLEVEL 2
1042 image_rect.bottom = dest_height > 0 ? dest_top + dest_height : dest_top; 1346 int GetPSLevel(HDC hDC) {
1043 FX_RECT clip_rect = image_rect; 1347 int device_type = ::GetDeviceCaps(hDC, TECHNOLOGY);
1044 clip_rect.Intersect(*pClipRect); 1348 if (device_type != DT_RASPRINTER) {
1045 clip_rect.Offset(-image_rect.left, -image_rect.top); 1349 return 0;
1046 int clip_width = clip_rect.Width(), clip_height = clip_rect.Height(); 1350 }
1047 CFX_DIBitmap* pStretched = pSource->StretchTo(dest_width, dest_height, f lags, &clip_rect); 1351 FX_DWORD esc = GET_PS_FEATURESETTING;
1048 if (pStretched == NULL) { 1352 if (ExtEscape(hDC, QUERYESCSUPPORT, sizeof esc, (char*)&esc, 0, NULL)) {
1049 return TRUE; 1353 int param = FEATURESETTING_PSLEVEL;
1050 } 1354 if (ExtEscape(hDC,
1051 CFX_DIBitmap background; 1355 GET_PS_FEATURESETTING,
1052 if (!background.Create(clip_width, clip_height, FXDIB_Rgb32) || 1356 sizeof(int),
1053 !GetDIBits(&background, image_rect.left + clip_rect.left, image_ rect.top + clip_rect.top, NULL) || 1357 (char*)&param,
1054 !background.CompositeMask(0, 0, clip_width, clip_height, pStretc hed, color, 0, 0, FXDIB_BLEND_NORMAL, NULL, FALSE, alpha_flag, pIccTransform)) { 1358 sizeof(int),
1055 delete pStretched; 1359 (char*)&param) > 0) {
1056 return FALSE; 1360 return param;
1057 } 1361 }
1058 FX_RECT src_rect(0, 0, clip_width, clip_height); 1362 }
1059 FX_BOOL ret = SetDIBits(&background, 0, &src_rect, image_rect.left + cli p_rect.left, image_rect.top + clip_rect.top, FXDIB_BLEND_NORMAL, 0, NULL); 1363 esc = POSTSCRIPT_IDENTIFY;
1060 delete pStretched; 1364 if (ExtEscape(hDC, QUERYESCSUPPORT, sizeof esc, (char*)&esc, 0, NULL) == 0) {
1061 return ret; 1365 esc = POSTSCRIPT_DATA;
1062 } else {
1063 if (pSource->HasAlpha()) {
1064 CWin32Platform* pPlatform = (CWin32Platform*)CFX_GEModule::Get()->Ge tPlatformData();
1065 if (pPlatform->m_GdiplusExt.IsAvailable() && pIccTransform == NULL & & !pSource->IsCmykImage()) {
1066 CFX_DIBExtractor temp(pSource);
1067 CFX_DIBitmap* pBitmap = temp;
1068 if (pBitmap == NULL) {
1069 return FALSE;
1070 }
1071 return pPlatform->m_GdiplusExt.StretchDIBits(m_hDC, pBitmap, des t_left, dest_top, dest_width, dest_height, pClipRect, flags);
1072 }
1073 return UseFoxitStretchEngine(pSource, color, dest_left, dest_top, de st_width, dest_height,
1074 pClipRect, flags, alpha_flag, pIccTrans form, blend_type);
1075 }
1076 CFX_DIBExtractor temp(pSource);
1077 CFX_DIBitmap* pBitmap = temp;
1078 if (pBitmap) {
1079 return GDI_StretchDIBits(pBitmap, dest_left, dest_top, dest_width, d est_height, flags, pIccTransform);
1080 }
1081 }
1082 return FALSE;
1083 }
1084 #define GET_PS_FEATURESETTING 4121
1085 #define FEATURESETTING_PSLEVEL 2
1086 int GetPSLevel(HDC hDC)
1087 {
1088 int device_type = ::GetDeviceCaps(hDC, TECHNOLOGY);
1089 if (device_type != DT_RASPRINTER) {
1090 return 0;
1091 }
1092 FX_DWORD esc = GET_PS_FEATURESETTING;
1093 if (ExtEscape(hDC, QUERYESCSUPPORT, sizeof esc, (char*)&esc, 0, NULL)) { 1366 if (ExtEscape(hDC, QUERYESCSUPPORT, sizeof esc, (char*)&esc, 0, NULL)) {
1094 int param = FEATURESETTING_PSLEVEL; 1367 return 2;
1095 if (ExtEscape(hDC, GET_PS_FEATURESETTING, sizeof(int), (char*)&param, si zeof(int), (char*)&param) > 0) { 1368 }
1096 return param; 1369 return 0;
1097 } 1370 }
1098 } 1371 esc = PSIDENT_GDICENTRIC;
1099 esc = POSTSCRIPT_IDENTIFY; 1372 if (ExtEscape(
1100 if (ExtEscape(hDC, QUERYESCSUPPORT, sizeof esc, (char*)&esc, 0, NULL) == 0) { 1373 hDC, POSTSCRIPT_IDENTIFY, sizeof(FX_DWORD), (char*)&esc, 0, NULL) <=
1101 esc = POSTSCRIPT_DATA; 1374 0) {
1102 if (ExtEscape(hDC, QUERYESCSUPPORT, sizeof esc, (char*)&esc, 0, NULL)) {
1103 return 2;
1104 }
1105 return 0;
1106 }
1107 esc = PSIDENT_GDICENTRIC;
1108 if (ExtEscape(hDC, POSTSCRIPT_IDENTIFY, sizeof(FX_DWORD), (char*)&esc, 0, NU LL) <= 0) {
1109 return 2;
1110 }
1111 esc = GET_PS_FEATURESETTING;
1112 if (ExtEscape(hDC, QUERYESCSUPPORT, sizeof esc, (char*)&esc, 0, NULL)) {
1113 int param = FEATURESETTING_PSLEVEL;
1114 if (ExtEscape(hDC, GET_PS_FEATURESETTING, sizeof(int), (char*)&param, si zeof(int), (char*)&param) > 0) {
1115 return param;
1116 }
1117 }
1118 return 2; 1375 return 2;
1376 }
1377 esc = GET_PS_FEATURESETTING;
1378 if (ExtEscape(hDC, QUERYESCSUPPORT, sizeof esc, (char*)&esc, 0, NULL)) {
1379 int param = FEATURESETTING_PSLEVEL;
1380 if (ExtEscape(hDC,
1381 GET_PS_FEATURESETTING,
1382 sizeof(int),
1383 (char*)&param,
1384 sizeof(int),
1385 (char*)&param) > 0) {
1386 return param;
1387 }
1388 }
1389 return 2;
1119 } 1390 }
1120 int CFX_WindowsDevice::m_psLevel = 2; 1391 int CFX_WindowsDevice::m_psLevel = 2;
1121 CFX_WindowsDevice::CFX_WindowsDevice(HDC hDC, FX_BOOL bCmykOutput, FX_BOOL bForc ePSOutput, int psLevel) 1392 CFX_WindowsDevice::CFX_WindowsDevice(HDC hDC,
1122 { 1393 FX_BOOL bCmykOutput,
1123 m_bForcePSOutput = bForcePSOutput; 1394 FX_BOOL bForcePSOutput,
1124 m_psLevel = psLevel; 1395 int psLevel) {
1125 if (bForcePSOutput) { 1396 m_bForcePSOutput = bForcePSOutput;
1126 IFX_RenderDeviceDriver* pDriver = FX_NEW CPSPrinterDriver; 1397 m_psLevel = psLevel;
1127 if (!pDriver) { 1398 if (bForcePSOutput) {
1128 return; 1399 IFX_RenderDeviceDriver* pDriver = FX_NEW CPSPrinterDriver;
1129 } 1400 if (!pDriver) {
1130 ((CPSPrinterDriver*)pDriver)->Init(hDC, psLevel, bCmykOutput); 1401 return;
1131 SetDeviceDriver(pDriver); 1402 }
1132 return; 1403 ((CPSPrinterDriver*)pDriver)->Init(hDC, psLevel, bCmykOutput);
1133 } 1404 SetDeviceDriver(pDriver);
1134 SetDeviceDriver(CreateDriver(hDC, bCmykOutput)); 1405 return;
1135 } 1406 }
1136 HDC CFX_WindowsDevice::GetDC() const 1407 SetDeviceDriver(CreateDriver(hDC, bCmykOutput));
1137 { 1408 }
1138 IFX_RenderDeviceDriver *pRDD = GetDeviceDriver(); 1409 HDC CFX_WindowsDevice::GetDC() const {
1139 if (!pRDD) { 1410 IFX_RenderDeviceDriver* pRDD = GetDeviceDriver();
1140 return NULL; 1411 if (!pRDD) {
1141 } 1412 return NULL;
1142 return (HDC)pRDD->GetPlatformSurface(); 1413 }
1143 } 1414 return (HDC)pRDD->GetPlatformSurface();
1144 IFX_RenderDeviceDriver* CFX_WindowsDevice::CreateDriver(HDC hDC, FX_BOOL bCmykOu tput) 1415 }
1145 { 1416 IFX_RenderDeviceDriver* CFX_WindowsDevice::CreateDriver(HDC hDC,
1146 int device_type = ::GetDeviceCaps(hDC, TECHNOLOGY); 1417 FX_BOOL bCmykOutput) {
1147 int obj_type = ::GetObjectType(hDC); 1418 int device_type = ::GetDeviceCaps(hDC, TECHNOLOGY);
1148 int device_class; 1419 int obj_type = ::GetObjectType(hDC);
1149 if (device_type == DT_RASPRINTER || device_type == DT_PLOTTER || obj_type == OBJ_ENHMETADC) { 1420 int device_class;
1150 device_class = FXDC_PRINTER; 1421 if (device_type == DT_RASPRINTER || device_type == DT_PLOTTER ||
1151 } else { 1422 obj_type == OBJ_ENHMETADC) {
1152 device_class = FXDC_DISPLAY; 1423 device_class = FXDC_PRINTER;
1153 } 1424 } else {
1425 device_class = FXDC_DISPLAY;
1426 }
1154 #ifndef _FPDFAPI_MINI_ 1427 #ifndef _FPDFAPI_MINI_
1155 if (device_class == FXDC_PRINTER) { 1428 if (device_class == FXDC_PRINTER) {
1156 return FX_NEW CGdiPrinterDriver(hDC); 1429 return FX_NEW CGdiPrinterDriver(hDC);
1157 } 1430 }
1158 #endif 1431 #endif
1159 return FX_NEW CGdiDisplayDriver(hDC); 1432 return FX_NEW CGdiDisplayDriver(hDC);
1160 } 1433 }
1161 CFX_WinBitmapDevice::CFX_WinBitmapDevice(int width, int height, FXDIB_Format for mat) 1434 CFX_WinBitmapDevice::CFX_WinBitmapDevice(int width,
1162 { 1435 int height,
1163 BITMAPINFOHEADER bmih; 1436 FXDIB_Format format) {
1164 FXSYS_memset32(&bmih, 0, sizeof (BITMAPINFOHEADER)); 1437 BITMAPINFOHEADER bmih;
1165 bmih.biSize = sizeof(BITMAPINFOHEADER); 1438 FXSYS_memset32(&bmih, 0, sizeof(BITMAPINFOHEADER));
1166 bmih.biBitCount = format & 0xff; 1439 bmih.biSize = sizeof(BITMAPINFOHEADER);
1167 bmih.biHeight = -height; 1440 bmih.biBitCount = format & 0xff;
1168 bmih.biPlanes = 1; 1441 bmih.biHeight = -height;
1169 bmih.biWidth = width; 1442 bmih.biPlanes = 1;
1170 FX_LPBYTE pBuffer; 1443 bmih.biWidth = width;
1171 m_hBitmap = CreateDIBSection(NULL, (BITMAPINFO*)&bmih, DIB_RGB_COLORS, (FX_L PVOID*)&pBuffer, NULL, 0); 1444 FX_LPBYTE pBuffer;
1172 if (m_hBitmap == NULL) { 1445 m_hBitmap = CreateDIBSection(
1173 return; 1446 NULL, (BITMAPINFO*)&bmih, DIB_RGB_COLORS, (FX_LPVOID*)&pBuffer, NULL, 0);
1174 } 1447 if (m_hBitmap == NULL) {
1175 CFX_DIBitmap* pBitmap = FX_NEW CFX_DIBitmap; 1448 return;
1176 if (!pBitmap) { 1449 }
1177 return; 1450 CFX_DIBitmap* pBitmap = FX_NEW CFX_DIBitmap;
1178 } 1451 if (!pBitmap) {
1179 pBitmap->Create(width, height, format, pBuffer); 1452 return;
1180 SetBitmap(pBitmap); 1453 }
1181 m_hDC = ::CreateCompatibleDC(NULL); 1454 pBitmap->Create(width, height, format, pBuffer);
1182 m_hOldBitmap = (HBITMAP)SelectObject(m_hDC, m_hBitmap); 1455 SetBitmap(pBitmap);
1183 IFX_RenderDeviceDriver* pDriver = FX_NEW CGdiDisplayDriver(m_hDC); 1456 m_hDC = ::CreateCompatibleDC(NULL);
1184 if (!pDriver) { 1457 m_hOldBitmap = (HBITMAP)SelectObject(m_hDC, m_hBitmap);
1185 return; 1458 IFX_RenderDeviceDriver* pDriver = FX_NEW CGdiDisplayDriver(m_hDC);
1186 } 1459 if (!pDriver) {
1187 SetDeviceDriver(pDriver); 1460 return;
1188 } 1461 }
1189 CFX_WinBitmapDevice::~CFX_WinBitmapDevice() 1462 SetDeviceDriver(pDriver);
1190 { 1463 }
1191 if (m_hDC) { 1464 CFX_WinBitmapDevice::~CFX_WinBitmapDevice() {
1192 SelectObject(m_hDC, m_hOldBitmap); 1465 if (m_hDC) {
1193 DeleteDC(m_hDC); 1466 SelectObject(m_hDC, m_hOldBitmap);
1194 } 1467 DeleteDC(m_hDC);
1195 if (m_hBitmap) { 1468 }
1196 DeleteObject(m_hBitmap); 1469 if (m_hBitmap) {
1197 } 1470 DeleteObject(m_hBitmap);
1198 delete GetBitmap(); 1471 }
1472 delete GetBitmap();
1199 } 1473 }
1200 #endif 1474 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698