summaryrefslogtreecommitdiff
path: root/core/fxge/win32
diff options
context:
space:
mode:
Diffstat (limited to 'core/fxge/win32')
-rw-r--r--core/fxge/win32/fx_win32_device.cpp964
-rw-r--r--core/fxge/win32/fx_win32_print.cpp319
-rw-r--r--core/fxge/win32/win32_int.h28
3 files changed, 652 insertions, 659 deletions
diff --git a/core/fxge/win32/fx_win32_device.cpp b/core/fxge/win32/fx_win32_device.cpp
index b71f3ae97a..c5b32bdbfc 100644
--- a/core/fxge/win32/fx_win32_device.cpp
+++ b/core/fxge/win32/fx_win32_device.cpp
@@ -6,6 +6,10 @@
#include "core/fxge/include/fx_ge.h"
+#include <algorithm>
+#include <memory>
+#include <vector>
+
#if _FX_OS_ == _FX_WIN32_DESKTOP_ || _FX_OS_ == _FX_WIN64_DESKTOP_
#include <crtdbg.h>
@@ -24,8 +28,303 @@
#include "core/fxge/win32/win32_int.h"
#include "third_party/base/stl_util.h"
+namespace {
+
+const struct {
+ const FX_CHAR* m_pFaceName;
+ const FX_CHAR* m_pVariantName;
+} g_VariantNames[] = {
+ {"DFKai-SB", "\x19\x6A\x77\x69\xD4\x9A"},
+};
+
+const struct {
+ const FX_CHAR* m_pName;
+ const FX_CHAR* m_pWinName;
+ bool m_bBold;
+ bool m_bItalic;
+} g_Base14Substs[] = {
+ {"Courier", "Courier New", false, false},
+ {"Courier-Bold", "Courier New", true, false},
+ {"Courier-BoldOblique", "Courier New", true, true},
+ {"Courier-Oblique", "Courier New", false, true},
+ {"Helvetica", "Arial", false, false},
+ {"Helvetica-Bold", "Arial", true, false},
+ {"Helvetica-BoldOblique", "Arial", true, true},
+ {"Helvetica-Oblique", "Arial", false, true},
+ {"Times-Roman", "Times New Roman", false, false},
+ {"Times-Bold", "Times New Roman", true, false},
+ {"Times-BoldItalic", "Times New Roman", true, true},
+ {"Times-Italic", "Times New Roman", false, true},
+};
+
+struct FontNameMap {
+ const FX_CHAR* m_pSubFontName;
+ const FX_CHAR* m_pSrcFontName;
+};
+const FontNameMap g_JpFontNameMap[] = {
+ {"MS Mincho", "Heiseimin-W3"},
+ {"MS Gothic", "Jun101-Light"},
+};
+
+bool GetSubFontName(CFX_ByteString* name) {
+ for (size_t i = 0; i < FX_ArraySize(g_JpFontNameMap); ++i) {
+ if (!FXSYS_stricmp(name->c_str(), g_JpFontNameMap[i].m_pSrcFontName)) {
+ *name = g_JpFontNameMap[i].m_pSubFontName;
+ return true;
+ }
+ }
+ return false;
+}
+
+FX_BOOL IsGDIEnabled() {
+ // If GDI is disabled then GetDC for the desktop will fail.
+ HDC hdc = ::GetDC(nullptr);
+ if (hdc) {
+ ::ReleaseDC(nullptr, hdc);
+ return TRUE;
+ }
+ return FALSE;
+}
+
+HPEN CreatePen(const CFX_GraphStateData* pGraphState,
+ const CFX_Matrix* pMatrix,
+ uint32_t argb) {
+ FX_FLOAT width;
+ FX_FLOAT scale = 1.f;
+ if (pMatrix)
+ scale = FXSYS_fabs(pMatrix->a) > FXSYS_fabs(pMatrix->b)
+ ? FXSYS_fabs(pMatrix->a)
+ : FXSYS_fabs(pMatrix->b);
+ if (pGraphState) {
+ width = scale * pGraphState->m_LineWidth;
+ } else {
+ width = 1.0f;
+ }
+ uint32_t PenStyle = PS_GEOMETRIC;
+ if (width < 1) {
+ width = 1;
+ }
+ if (pGraphState->m_DashCount) {
+ PenStyle |= PS_USERSTYLE;
+ } else {
+ PenStyle |= PS_SOLID;
+ }
+ switch (pGraphState->m_LineCap) {
+ case 0:
+ PenStyle |= PS_ENDCAP_FLAT;
+ break;
+ case 1:
+ PenStyle |= PS_ENDCAP_ROUND;
+ break;
+ case 2:
+ PenStyle |= PS_ENDCAP_SQUARE;
+ break;
+ }
+ switch (pGraphState->m_LineJoin) {
+ case 0:
+ PenStyle |= PS_JOIN_MITER;
+ break;
+ case 1:
+ PenStyle |= PS_JOIN_ROUND;
+ break;
+ case 2:
+ PenStyle |= PS_JOIN_BEVEL;
+ break;
+ }
+ int a;
+ FX_COLORREF rgb;
+ ArgbDecode(argb, a, rgb);
+ LOGBRUSH lb;
+ lb.lbColor = rgb;
+ lb.lbStyle = BS_SOLID;
+ lb.lbHatch = 0;
+ std::vector<uint32_t> dashes;
+ if (pGraphState->m_DashCount) {
+ dashes.resize(pGraphState->m_DashCount);
+ for (int i = 0; i < pGraphState->m_DashCount; i++) {
+ dashes[i] = FXSYS_round(
+ pMatrix ? pMatrix->TransformDistance(pGraphState->m_DashArray[i])
+ : pGraphState->m_DashArray[i]);
+ dashes[i] = std::max(dashes[i], 1U);
+ }
+ }
+ return ExtCreatePen(PenStyle, (DWORD)FXSYS_ceil(width), &lb,
+ pGraphState->m_DashCount,
+ reinterpret_cast<const DWORD*>(dashes.data()));
+}
+
+HBRUSH CreateBrush(uint32_t argb) {
+ int a;
+ FX_COLORREF rgb;
+ ArgbDecode(argb, a, rgb);
+ return CreateSolidBrush(rgb);
+}
+
+void SetPathToDC(HDC hDC,
+ const CFX_PathData* pPathData,
+ const CFX_Matrix* pMatrix) {
+ BeginPath(hDC);
+ int nPoints = pPathData->GetPointCount();
+ FX_PATHPOINT* pPoints = pPathData->GetPoints();
+ for (int i = 0; i < nPoints; i++) {
+ FX_FLOAT posx = pPoints[i].m_PointX, posy = pPoints[i].m_PointY;
+ if (pMatrix) {
+ pMatrix->Transform(posx, posy);
+ }
+ int screen_x = FXSYS_round(posx), screen_y = FXSYS_round(posy);
+ int point_type = pPoints[i].m_Flag & FXPT_TYPE;
+ if (point_type == PT_MOVETO) {
+ MoveToEx(hDC, screen_x, screen_y, nullptr);
+ } else if (point_type == PT_LINETO) {
+ if (pPoints[i].m_PointY == pPoints[i - 1].m_PointY &&
+ pPoints[i].m_PointX == pPoints[i - 1].m_PointX) {
+ screen_x++;
+ }
+ LineTo(hDC, screen_x, screen_y);
+ } else if (point_type == PT_BEZIERTO) {
+ POINT lppt[3];
+ lppt[0].x = screen_x;
+ lppt[0].y = screen_y;
+ posx = pPoints[i + 1].m_PointX;
+ posy = pPoints[i + 1].m_PointY;
+ if (pMatrix) {
+ pMatrix->Transform(posx, posy);
+ }
+ lppt[1].x = FXSYS_round(posx);
+ lppt[1].y = FXSYS_round(posy);
+ posx = pPoints[i + 2].m_PointX;
+ posy = pPoints[i + 2].m_PointY;
+ if (pMatrix) {
+ pMatrix->Transform(posx, posy);
+ }
+ lppt[2].x = FXSYS_round(posx);
+ lppt[2].y = FXSYS_round(posy);
+ PolyBezierTo(hDC, lppt, 3);
+ i += 2;
+ }
+ if (pPoints[i].m_Flag & PT_CLOSEFIGURE) {
+ CloseFigure(hDC);
+ }
+ }
+ EndPath(hDC);
+}
+
+#ifdef _SKIA_SUPPORT_
+// TODO(caryclark) This antigrain function is duplicated here to permit
+// removing the last remaining dependency. Eventually, this will be elminiated
+// altogether and replace by Skia code.
+
+struct rect_base {
+ FX_FLOAT x1;
+ FX_FLOAT y1;
+ FX_FLOAT x2;
+ FX_FLOAT y2;
+};
+
+unsigned clip_liang_barsky(FX_FLOAT x1,
+ FX_FLOAT y1,
+ FX_FLOAT x2,
+ FX_FLOAT y2,
+ const rect_base& clip_box,
+ FX_FLOAT* x,
+ FX_FLOAT* y) {
+ const FX_FLOAT nearzero = 1e-30f;
+ FX_FLOAT deltax = x2 - x1;
+ FX_FLOAT deltay = y2 - y1;
+ unsigned np = 0;
+ if (deltax == 0)
+ deltax = (x1 > clip_box.x1) ? -nearzero : nearzero;
+ FX_FLOAT xin, xout;
+ if (deltax > 0) {
+ xin = clip_box.x1;
+ xout = clip_box.x2;
+ } else {
+ xin = clip_box.x2;
+ xout = clip_box.x1;
+ }
+ FX_FLOAT tinx = (xin - x1) / deltax;
+ if (deltay == 0)
+ deltay = (y1 > clip_box.y1) ? -nearzero : nearzero;
+ FX_FLOAT yin, yout;
+ if (deltay > 0) {
+ yin = clip_box.y1;
+ yout = clip_box.y2;
+ } else {
+ yin = clip_box.y2;
+ yout = clip_box.y1;
+ }
+ FX_FLOAT tiny = (yin - y1) / deltay;
+ FX_FLOAT tin1, tin2;
+ if (tinx < tiny) {
+ tin1 = tinx;
+ tin2 = tiny;
+ } else {
+ tin1 = tiny;
+ tin2 = tinx;
+ }
+ if (tin1 <= 1.0f) {
+ if (0 < tin1) {
+ *x++ = xin;
+ *y++ = yin;
+ ++np;
+ }
+ if (tin2 <= 1.0f) {
+ FX_FLOAT toutx = (xout - x1) / deltax;
+ FX_FLOAT touty = (yout - y1) / deltay;
+ FX_FLOAT tout1 = (toutx < touty) ? toutx : touty;
+ if (tin2 > 0 || tout1 > 0) {
+ if (tin2 <= tout1) {
+ if (tin2 > 0) {
+ if (tinx > tiny) {
+ *x++ = xin;
+ *y++ = y1 + (deltay * tinx);
+ } else {
+ *x++ = x1 + (deltax * tiny);
+ *y++ = yin;
+ }
+ ++np;
+ }
+ if (tout1 < 1.0f) {
+ if (toutx < touty) {
+ *x++ = xout;
+ *y++ = y1 + (deltay * toutx);
+ } else {
+ *x++ = x1 + (deltax * touty);
+ *y++ = yout;
+ }
+ } else {
+ *x++ = x2;
+ *y++ = y2;
+ }
+ ++np;
+ } else {
+ if (tinx > tiny) {
+ *x++ = xin;
+ *y++ = yout;
+ } else {
+ *x++ = xout;
+ *y++ = yin;
+ }
+ ++np;
+ }
+ }
+ }
+ }
+ return np;
+}
+#endif // _SKIA_SUPPORT_
+
+FX_BOOL MatrixNoScaled(const CFX_Matrix* pMatrix) {
+ return pMatrix->GetA() == 1.0f && pMatrix->GetB() == 0 &&
+ pMatrix->GetC() == 0 && pMatrix->GetD() == 1.0f;
+}
+
class CFX_Win32FallbackFontInfo final : public CFX_FolderFontInfo {
public:
+ CFX_Win32FallbackFontInfo() {}
+ ~CFX_Win32FallbackFontInfo() override {}
+
+ // CFX_FolderFontInfo:
void* MapFont(int weight,
FX_BOOL bItalic,
int charset,
@@ -33,13 +332,13 @@ class CFX_Win32FallbackFontInfo final : public CFX_FolderFontInfo {
const FX_CHAR* family,
int& iExact) override;
};
+
class CFX_Win32FontInfo final : public IFX_SystemFontInfo {
public:
CFX_Win32FontInfo();
~CFX_Win32FontInfo() override;
// IFX_SystemFontInfo
- void Release() override;
FX_BOOL EnumFontList(CFX_FontMapper* pMapper) override;
void* MapFont(int weight,
FX_BOOL bItalic,
@@ -47,7 +346,7 @@ class CFX_Win32FontInfo final : public IFX_SystemFontInfo {
int pitch_family,
const FX_CHAR* face,
int& iExact) override;
- void* GetFont(const FX_CHAR* face) override { return NULL; }
+ void* GetFont(const FX_CHAR* face) override { return nullptr; }
uint32_t GetFontData(void* hFont,
uint32_t table,
uint8_t* buffer,
@@ -64,29 +363,32 @@ class CFX_Win32FontInfo final : public IFX_SystemFontInfo {
int weight,
int picth_family);
CFX_ByteString FindFont(const CFX_ByteString& name);
+
HDC m_hDC;
CFX_FontMapper* m_pMapper;
CFX_ByteString m_LastFamily;
CFX_ByteString m_KaiTi, m_FangSong;
};
-CFX_Win32FontInfo::CFX_Win32FontInfo() {
- m_hDC = CreateCompatibleDC(NULL);
+int CALLBACK FontEnumProc(const LOGFONTA* plf,
+ const TEXTMETRICA* lpntme,
+ uint32_t FontType,
+ LPARAM lParam) {
+ CFX_Win32FontInfo* pFontInfo = reinterpret_cast<CFX_Win32FontInfo*>(lParam);
+ pFontInfo->AddInstalledFont(plf, FontType);
+ return 1;
}
+
+CFX_Win32FontInfo::CFX_Win32FontInfo() : m_hDC(CreateCompatibleDC(nullptr)) {}
+
CFX_Win32FontInfo::~CFX_Win32FontInfo() {
- m_pMapper = NULL;
-}
-void CFX_Win32FontInfo::Release() {
DeleteDC(m_hDC);
- delete this;
}
-#define TT_MAKE_TAG(x1, x2, x3, x4) \
- (((uint32_t)x1 << 24) | ((uint32_t)x2 << 16) | ((uint32_t)x3 << 8) | \
- (uint32_t)x4)
+
FX_BOOL CFX_Win32FontInfo::IsOpenTypeFromDiv(const LOGFONTA* plf) {
HFONT hFont = CreateFontIndirectA(plf);
FX_BOOL ret = FALSE;
- uint32_t font_size = GetFontData(hFont, 0, NULL, 0);
+ uint32_t font_size = GetFontData(hFont, 0, nullptr, 0);
if (font_size != GDI_ERROR && font_size >= sizeof(uint32_t)) {
uint32_t lVersion = 0;
GetFontData(hFont, 0, (uint8_t*)(&lVersion), sizeof(uint32_t));
@@ -94,19 +396,20 @@ FX_BOOL CFX_Win32FontInfo::IsOpenTypeFromDiv(const LOGFONTA* plf) {
((uint32_t)((uint8_t)(lVersion >> 8))) << 16 |
((uint32_t)((uint8_t)(lVersion >> 16))) << 8 |
((uint8_t)(lVersion >> 24));
- if (lVersion == TT_MAKE_TAG('O', 'T', 'T', 'O') || lVersion == 0x00010000 ||
- lVersion == TT_MAKE_TAG('t', 't', 'c', 'f') ||
- lVersion == TT_MAKE_TAG('t', 'r', 'u', 'e') || lVersion == 0x00020000) {
+ if (lVersion == FXBSTR_ID('O', 'T', 'T', 'O') || lVersion == 0x00010000 ||
+ lVersion == FXBSTR_ID('t', 't', 'c', 'f') ||
+ lVersion == FXBSTR_ID('t', 'r', 'u', 'e') || lVersion == 0x00020000) {
ret = TRUE;
}
}
DeleteFont(hFont);
return ret;
}
+
FX_BOOL CFX_Win32FontInfo::IsSupportFontFormDiv(const LOGFONTA* plf) {
HFONT hFont = CreateFontIndirectA(plf);
FX_BOOL ret = FALSE;
- uint32_t font_size = GetFontData(hFont, 0, NULL, 0);
+ uint32_t font_size = GetFontData(hFont, 0, nullptr, 0);
if (font_size != GDI_ERROR && font_size >= sizeof(uint32_t)) {
uint32_t lVersion = 0;
GetFontData(hFont, 0, (uint8_t*)(&lVersion), sizeof(uint32_t));
@@ -114,47 +417,37 @@ FX_BOOL CFX_Win32FontInfo::IsSupportFontFormDiv(const LOGFONTA* plf) {
((uint32_t)((uint8_t)(lVersion >> 8))) << 16 |
((uint32_t)((uint8_t)(lVersion >> 16))) << 8 |
((uint8_t)(lVersion >> 24));
- if (lVersion == TT_MAKE_TAG('O', 'T', 'T', 'O') || lVersion == 0x00010000 ||
- lVersion == TT_MAKE_TAG('t', 't', 'c', 'f') ||
- lVersion == TT_MAKE_TAG('t', 'r', 'u', 'e') || lVersion == 0x00020000) {
- ret = TRUE;
- } else if ((lVersion & 0xFFFF0000) == TT_MAKE_TAG(0x80, 0x01, 0x00, 0x00) ||
- (lVersion & 0xFFFF0000) == TT_MAKE_TAG('%', '!', 0, 0)) {
+ if (lVersion == FXBSTR_ID('O', 'T', 'T', 'O') || lVersion == 0x00010000 ||
+ lVersion == FXBSTR_ID('t', 't', 'c', 'f') ||
+ lVersion == FXBSTR_ID('t', 'r', 'u', 'e') || lVersion == 0x00020000 ||
+ (lVersion & 0xFFFF0000) == FXBSTR_ID(0x80, 0x01, 0x00, 0x00) ||
+ (lVersion & 0xFFFF0000) == FXBSTR_ID('%', '!', 0, 0)) {
ret = TRUE;
}
}
DeleteFont(hFont);
return ret;
}
+
void CFX_Win32FontInfo::AddInstalledFont(const LOGFONTA* plf,
uint32_t FontType) {
CFX_ByteString name(plf->lfFaceName);
- if (name[0] == '@') {
+ if (name[0] == '@')
return;
- }
+
if (name == m_LastFamily) {
m_pMapper->AddInstalledFont(name, plf->lfCharSet);
return;
}
- if (!(FontType & TRUETYPE_FONTTYPE) && !(FontType & DEVICE_FONTTYPE)) {
- return;
- }
if (!(FontType & TRUETYPE_FONTTYPE)) {
- if (!IsSupportFontFormDiv(plf)) {
+ if (!(FontType & DEVICE_FONTTYPE) || !IsSupportFontFormDiv(plf))
return;
- }
}
+
m_pMapper->AddInstalledFont(name, plf->lfCharSet);
m_LastFamily = name;
}
-static int CALLBACK FontEnumProc(const LOGFONTA* plf,
- const TEXTMETRICA* lpntme,
- uint32_t FontType,
- LPARAM lParam) {
- CFX_Win32FontInfo* pFontInfo = (CFX_Win32FontInfo*)lParam;
- pFontInfo->AddInstalledFont(plf, FontType);
- return 1;
-}
+
FX_BOOL CFX_Win32FontInfo::EnumFontList(CFX_FontMapper* pMapper) {
m_pMapper = pMapper;
LOGFONTA lf;
@@ -166,37 +459,12 @@ FX_BOOL CFX_Win32FontInfo::EnumFontList(CFX_FontMapper* pMapper) {
0);
return TRUE;
}
-static const struct {
- const FX_CHAR* m_pFaceName;
- const FX_CHAR* m_pVariantName;
-} VariantNames[] = {
- {"DFKai-SB", "\x19\x6A\x77\x69\xD4\x9A"},
-};
-static const struct {
- const FX_CHAR* m_pName;
- const FX_CHAR* m_pWinName;
- FX_BOOL m_bBold;
- FX_BOOL m_bItalic;
-} Base14Substs[] = {
- {"Courier", "Courier New", FALSE, FALSE},
- {"Courier-Bold", "Courier New", TRUE, FALSE},
- {"Courier-BoldOblique", "Courier New", TRUE, TRUE},
- {"Courier-Oblique", "Courier New", FALSE, TRUE},
- {"Helvetica", "Arial", FALSE, FALSE},
- {"Helvetica-Bold", "Arial", TRUE, FALSE},
- {"Helvetica-BoldOblique", "Arial", TRUE, TRUE},
- {"Helvetica-Oblique", "Arial", FALSE, TRUE},
- {"Times-Roman", "Times New Roman", FALSE, FALSE},
- {"Times-Bold", "Times New Roman", TRUE, FALSE},
- {"Times-BoldItalic", "Times New Roman", TRUE, TRUE},
- {"Times-Italic", "Times New Roman", FALSE, TRUE},
-};
+
CFX_ByteString CFX_Win32FontInfo::FindFont(const CFX_ByteString& name) {
- if (!m_pMapper) {
+ if (!m_pMapper)
return name;
- }
- int nFonts = pdfium::CollectionSize<int>(m_pMapper->m_InstalledTTFonts);
- for (int i = 0; i < nFonts; i++) {
+
+ for (size_t i = 0; i < m_pMapper->m_InstalledTTFonts.size(); ++i) {
CFX_ByteString thisname = m_pMapper->m_InstalledTTFonts[i];
if (thisname[0] == ' ') {
if (thisname.Mid(1, name.GetLength()) == name) {
@@ -208,6 +476,7 @@ CFX_ByteString CFX_Win32FontInfo::FindFont(const CFX_ByteString& name) {
}
return CFX_ByteString();
}
+
void* CFX_Win32FallbackFontInfo::MapFont(int weight,
FX_BOOL bItalic,
int charset,
@@ -231,32 +500,7 @@ void* CFX_Win32FallbackFontInfo::MapFont(int weight,
}
return FindFont(weight, bItalic, charset, pitch_family, cstr_face, !bCJK);
}
-struct _FontNameMap {
- const FX_CHAR* m_pSubFontName;
- const FX_CHAR* m_pSrcFontName;
-};
-const _FontNameMap g_JpFontNameMap[] = {
- {"MS Mincho", "Heiseimin-W3"},
- {"MS Gothic", "Jun101-Light"},
-};
-extern "C" {
-static int compareString(const void* key, const void* element) {
- return FXSYS_stricmp((const FX_CHAR*)key,
- ((_FontNameMap*)element)->m_pSrcFontName);
-}
-}
-FX_BOOL _GetSubFontName(CFX_ByteString& name) {
- int size = sizeof g_JpFontNameMap;
- void* pFontnameMap = (void*)g_JpFontNameMap;
- _FontNameMap* found = (_FontNameMap*)FXSYS_bsearch(
- name.c_str(), pFontnameMap, size / sizeof(_FontNameMap),
- sizeof(_FontNameMap), compareString);
- if (!found) {
- return FALSE;
- }
- name = found->m_pSubFontName;
- return TRUE;
-}
+
void CFX_Win32FontInfo::GetGBPreference(CFX_ByteString& face,
int weight,
int picth_family) {
@@ -286,6 +530,7 @@ void CFX_Win32FontInfo::GetGBPreference(CFX_ByteString& face,
face = "SimSun";
}
}
+
void CFX_Win32FontInfo::GetJapanesePreference(CFX_ByteString& face,
int weight,
int picth_family) {
@@ -314,15 +559,16 @@ void CFX_Win32FontInfo::GetJapanesePreference(CFX_ByteString& face,
}
return;
}
- if (_GetSubFontName(face)) {
+ if (GetSubFontName(&face))
return;
- }
+
if (!(picth_family & FF_ROMAN) && weight > 400) {
face = "MS PGothic";
} else {
face = "MS PMincho";
}
}
+
void* CFX_Win32FontInfo::MapFont(int weight,
FX_BOOL bItalic,
int charset,
@@ -332,10 +578,10 @@ void* CFX_Win32FontInfo::MapFont(int weight,
CFX_ByteString face = cstr_face;
int iBaseFont;
for (iBaseFont = 0; iBaseFont < 12; iBaseFont++)
- if (face == CFX_ByteStringC(Base14Substs[iBaseFont].m_pName)) {
- face = Base14Substs[iBaseFont].m_pWinName;
- weight = Base14Substs[iBaseFont].m_bBold ? FW_BOLD : FW_NORMAL;
- bItalic = Base14Substs[iBaseFont].m_bItalic;
+ if (face == CFX_ByteStringC(g_Base14Substs[iBaseFont].m_pName)) {
+ face = g_Base14Substs[iBaseFont].m_pWinName;
+ weight = g_Base14Substs[iBaseFont].m_bBold ? FW_BOLD : FW_NORMAL;
+ bItalic = g_Base14Substs[iBaseFont].m_bItalic;
iExact = TRUE;
break;
}
@@ -360,26 +606,25 @@ void* CFX_Win32FontInfo::MapFont(int weight,
HFONT hOldFont = (HFONT)::SelectObject(m_hDC, hFont);
::GetTextFaceA(m_hDC, 100, facebuf);
::SelectObject(m_hDC, hOldFont);
- if (face.EqualNoCase(facebuf)) {
+ if (face.EqualNoCase(facebuf))
return hFont;
- }
- int iCount = sizeof(VariantNames) / sizeof(VariantNames[0]);
- for (int i = 0; i < iCount; ++i) {
- if (face == VariantNames[i].m_pFaceName) {
- CFX_WideString wsFace = CFX_WideString::FromLocal(facebuf);
- const unsigned short* pName =
- (const unsigned short*)VariantNames[i].m_pVariantName;
- FX_STRSIZE len = CFX_WideString::WStringLength(pName);
- CFX_WideString wsName = CFX_WideString::FromUTF16LE(pName, len);
- if (wsFace == wsName) {
- return hFont;
- }
- }
+
+ CFX_WideString wsFace = CFX_WideString::FromLocal(facebuf);
+ for (size_t i = 0; i < FX_ArraySize(g_VariantNames); ++i) {
+ if (face != g_VariantNames[i].m_pFaceName)
+ continue;
+
+ const unsigned short* pName = reinterpret_cast<const unsigned short*>(
+ g_VariantNames[i].m_pVariantName);
+ FX_STRSIZE len = CFX_WideString::WStringLength(pName);
+ CFX_WideString wsName = CFX_WideString::FromUTF16LE(pName, len);
+ if (wsFace == wsName)
+ return hFont;
}
::DeleteObject(hFont);
- if (charset == DEFAULT_CHARSET) {
- return NULL;
- }
+ if (charset == DEFAULT_CHARSET)
+ return nullptr;
+
switch (charset) {
case SHIFTJIS_CHARSET:
GetJapanesePreference(face, weight, pitch_family);
@@ -403,9 +648,11 @@ void* CFX_Win32FontInfo::MapFont(int weight,
OUT_TT_ONLY_PRECIS, 0, 0, subst_pitch_family, face.c_str());
return hFont;
}
+
void CFX_Win32FontInfo::DeleteFont(void* hFont) {
::DeleteObject(hFont);
}
+
uint32_t CFX_Win32FontInfo::GetFontData(void* hFont,
uint32_t table,
uint8_t* buffer,
@@ -419,6 +666,7 @@ uint32_t CFX_Win32FontInfo::GetFontData(void* hFont,
}
return size;
}
+
FX_BOOL CFX_Win32FontInfo::GetFaceName(void* hFont, CFX_ByteString& name) {
char facebuf[100];
HFONT hOldFont = (HFONT)::SelectObject(m_hDC, (HFONT)hFont);
@@ -430,6 +678,7 @@ FX_BOOL CFX_Win32FontInfo::GetFaceName(void* hFont, CFX_ByteString& name) {
name = facebuf;
return TRUE;
}
+
FX_BOOL CFX_Win32FontInfo::GetFontCharset(void* hFont, int& charset) {
TEXTMETRIC tm;
HFONT hOldFont = (HFONT)::SelectObject(m_hDC, (HFONT)hFont);
@@ -438,19 +687,14 @@ FX_BOOL CFX_Win32FontInfo::GetFontCharset(void* hFont, int& charset) {
charset = tm.tmCharSet;
return TRUE;
}
-static FX_BOOL IsGDIEnabled() {
- // If GDI is disabled then GetDC for the desktop will fail.
- HDC hdc = ::GetDC(NULL);
- if (hdc) {
- ::ReleaseDC(NULL, hdc);
- return TRUE;
- }
- return FALSE;
-}
-IFX_SystemFontInfo* IFX_SystemFontInfo::CreateDefault(const char** pUnused) {
- if (IsGDIEnabled()) {
- return new CFX_Win32FontInfo;
- }
+
+} // namespace
+
+std::unique_ptr<IFX_SystemFontInfo> IFX_SystemFontInfo::CreateDefault(
+ const char** pUnused) {
+ if (IsGDIEnabled())
+ return std::unique_ptr<IFX_SystemFontInfo>(new CFX_Win32FontInfo);
+
// Select the fallback font information class if GDI is disabled.
CFX_Win32FallbackFontInfo* pInfoFallback = new CFX_Win32FallbackFontInfo;
// Construct the font path manually, SHGetKnownFolderPath won't work under
@@ -462,8 +706,9 @@ IFX_SystemFontInfo* IFX_SystemFontInfo::CreateDefault(const char** pUnused) {
fonts_path += "\\Fonts";
pInfoFallback->AddPath(fonts_path.AsStringC());
}
- return pInfoFallback;
+ return std::unique_ptr<IFX_SystemFontInfo>(pInfoFallback);
}
+
void CFX_GEModule::InitPlatform() {
CWin32Platform* pPlatformData = new CWin32Platform;
OSVERSIONINFO ver;
@@ -476,10 +721,12 @@ void CFX_GEModule::InitPlatform() {
m_pPlatformData = pPlatformData;
m_pFontMgr->SetSystemFontInfo(IFX_SystemFontInfo::CreateDefault(nullptr));
}
+
void CFX_GEModule::DestroyPlatform() {
delete (CWin32Platform*)m_pPlatformData;
- m_pPlatformData = NULL;
+ m_pPlatformData = nullptr;
}
+
CGdiDeviceDriver::CGdiDeviceDriver(HDC hDC, int device_class) {
m_hDC = hDC;
m_DeviceClass = device_class;
@@ -487,7 +734,7 @@ CGdiDeviceDriver::CGdiDeviceDriver(HDC hDC, int device_class) {
(CWin32Platform*)CFX_GEModule::Get()->GetPlatformData();
SetStretchBltMode(hDC, pPlatform->m_bHalfTone ? HALFTONE : COLORONCOLOR);
if (GetObjectType(m_hDC) == OBJ_MEMDC) {
- HBITMAP hBitmap = CreateBitmap(1, 1, 1, 1, NULL);
+ HBITMAP hBitmap = CreateBitmap(1, 1, 1, 1, nullptr);
hBitmap = (HBITMAP)SelectObject(m_hDC, hBitmap);
BITMAP bitmap;
GetObject(hBitmap, sizeof bitmap, &bitmap);
@@ -538,27 +785,29 @@ void* CGdiDeviceDriver::GetClipRgn() {
HRGN hClipRgn = CreateRectRgn(0, 0, 1, 1);
if (::GetClipRgn(m_hDC, hClipRgn) == 0) {
DeleteObject(hClipRgn);
- hClipRgn = NULL;
+ hClipRgn = nullptr;
}
return (void*)hClipRgn;
}
-FX_BOOL CGdiDeviceDriver::GDI_SetDIBits(const CFX_DIBitmap* pBitmap1,
+
+FX_BOOL CGdiDeviceDriver::GDI_SetDIBits(CFX_DIBitmap* pBitmap1,
const FX_RECT* pSrcRect,
int left,
int top,
void* pIccTransform) {
if (m_DeviceClass == FXDC_PRINTER) {
- CFX_DIBitmap* pBitmap = pBitmap1->FlipImage(FALSE, TRUE);
- if (!pBitmap) {
+ std::unique_ptr<CFX_DIBitmap> pBitmap(pBitmap1->FlipImage(FALSE, TRUE));
+ if (!pBitmap)
return FALSE;
- }
+
if ((pBitmap->IsCmykImage() || pIccTransform) &&
!pBitmap->ConvertFormat(FXDIB_Rgb, pIccTransform)) {
return FALSE;
}
+
int width = pSrcRect->Width(), height = pSrcRect->Height();
LPBYTE pBuffer = pBitmap->GetBuffer();
- CFX_ByteString info = CFX_WindowsDIB::GetBitmapInfo(pBitmap);
+ CFX_ByteString info = CFX_WindowsDIB::GetBitmapInfo(pBitmap.get());
((BITMAPINFOHEADER*)info.c_str())->biHeight *= -1;
FX_RECT dst_rect(0, 0, width, height);
dst_rect.Intersect(0, 0, pBitmap->GetWidth(), pBitmap->GetHeight());
@@ -567,13 +816,12 @@ FX_BOOL CGdiDeviceDriver::GDI_SetDIBits(const CFX_DIBitmap* pBitmap1,
::StretchDIBits(m_hDC, left, top, dst_width, dst_height, 0, 0, dst_width,
dst_height, pBuffer, (BITMAPINFO*)info.c_str(),
DIB_RGB_COLORS, SRCCOPY);
- delete pBitmap;
} else {
- CFX_DIBitmap* pBitmap = (CFX_DIBitmap*)pBitmap1;
- if ((pBitmap->IsCmykImage() || pIccTransform) &&
- (pBitmap = pBitmap->CloneConvert(FXDIB_Rgb, NULL, pIccTransform)) ==
- NULL) {
- return FALSE;
+ CFX_DIBitmap* pBitmap = pBitmap1;
+ if (pBitmap->IsCmykImage() || pIccTransform) {
+ pBitmap = pBitmap->CloneConvert(FXDIB_Rgb, nullptr, pIccTransform);
+ if (!pBitmap)
+ return FALSE;
}
int width = pSrcRect->Width(), height = pSrcRect->Height();
LPBYTE pBuffer = pBitmap->GetBuffer();
@@ -588,17 +836,18 @@ FX_BOOL CGdiDeviceDriver::GDI_SetDIBits(const CFX_DIBitmap* pBitmap1,
}
return TRUE;
}
-FX_BOOL CGdiDeviceDriver::GDI_StretchDIBits(const CFX_DIBitmap* pBitmap1,
+
+FX_BOOL CGdiDeviceDriver::GDI_StretchDIBits(CFX_DIBitmap* pBitmap1,
int dest_left,
int dest_top,
int dest_width,
int dest_height,
uint32_t flags,
void* pIccTransform) {
- CFX_DIBitmap* pBitmap = (CFX_DIBitmap*)pBitmap1;
- if (!pBitmap || dest_width == 0 || dest_height == 0) {
+ CFX_DIBitmap* pBitmap = pBitmap1;
+ if (!pBitmap || dest_width == 0 || dest_height == 0)
return FALSE;
- }
+
if ((pBitmap->IsCmykImage() || pIccTransform) &&
!pBitmap->ConvertFormat(FXDIB_Rgb, pIccTransform)) {
return FALSE;
@@ -631,7 +880,8 @@ FX_BOOL CGdiDeviceDriver::GDI_StretchDIBits(const CFX_DIBitmap* pBitmap1,
}
return TRUE;
}
-FX_BOOL CGdiDeviceDriver::GDI_StretchBitMask(const CFX_DIBitmap* pBitmap1,
+
+FX_BOOL CGdiDeviceDriver::GDI_StretchBitMask(CFX_DIBitmap* pBitmap1,
int dest_left,
int dest_top,
int dest_width,
@@ -640,10 +890,10 @@ FX_BOOL CGdiDeviceDriver::GDI_StretchBitMask(const CFX_DIBitmap* pBitmap1,
uint32_t flags,
int alpha_flag,
void* pIccTransform) {
- CFX_DIBitmap* pBitmap = (CFX_DIBitmap*)pBitmap1;
- if (!pBitmap || dest_width == 0 || dest_height == 0) {
+ CFX_DIBitmap* pBitmap = pBitmap1;
+ if (!pBitmap || dest_width == 0 || dest_height == 0)
return FALSE;
- }
+
Color2Argb(bitmap_color, bitmap_color, alpha_flag | (1 << 24), pIccTransform);
int width = pBitmap->GetWidth(), height = pBitmap->GetHeight();
struct {
@@ -693,241 +943,15 @@ FX_BOOL CGdiDeviceDriver::GDI_StretchBitMask(const CFX_DIBitmap* pBitmap1,
return TRUE;
}
+
FX_BOOL CGdiDeviceDriver::GetClipBox(FX_RECT* pRect) {
return ::GetClipBox(m_hDC, (RECT*)pRect);
}
+
FX_BOOL CGdiDeviceDriver::SetClipRgn(void* hRgn) {
::SelectClipRgn(m_hDC, (HRGN)hRgn);
return TRUE;
}
-static HPEN _CreatePen(const CFX_GraphStateData* pGraphState,
- const CFX_Matrix* pMatrix,
- uint32_t argb) {
- FX_FLOAT width;
- FX_FLOAT scale = 1.f;
- if (pMatrix)
- scale = FXSYS_fabs(pMatrix->a) > FXSYS_fabs(pMatrix->b)
- ? FXSYS_fabs(pMatrix->a)
- : FXSYS_fabs(pMatrix->b);
- if (pGraphState) {
- width = scale * pGraphState->m_LineWidth;
- } else {
- width = 1.0f;
- }
- uint32_t PenStyle = PS_GEOMETRIC;
- if (width < 1) {
- width = 1;
- }
- if (pGraphState->m_DashCount) {
- PenStyle |= PS_USERSTYLE;
- } else {
- PenStyle |= PS_SOLID;
- }
- switch (pGraphState->m_LineCap) {
- case 0:
- PenStyle |= PS_ENDCAP_FLAT;
- break;
- case 1:
- PenStyle |= PS_ENDCAP_ROUND;
- break;
- case 2:
- PenStyle |= PS_ENDCAP_SQUARE;
- break;
- }
- switch (pGraphState->m_LineJoin) {
- case 0:
- PenStyle |= PS_JOIN_MITER;
- break;
- case 1:
- PenStyle |= PS_JOIN_ROUND;
- break;
- case 2:
- PenStyle |= PS_JOIN_BEVEL;
- break;
- }
- int a;
- FX_COLORREF rgb;
- ArgbDecode(argb, a, rgb);
- LOGBRUSH lb;
- lb.lbColor = rgb;
- lb.lbStyle = BS_SOLID;
- lb.lbHatch = 0;
- uint32_t* pDash = NULL;
- if (pGraphState->m_DashCount) {
- pDash = FX_Alloc(uint32_t, pGraphState->m_DashCount);
- for (int i = 0; i < pGraphState->m_DashCount; i++) {
- pDash[i] = FXSYS_round(
- pMatrix ? pMatrix->TransformDistance(pGraphState->m_DashArray[i])
- : pGraphState->m_DashArray[i]);
- if (pDash[i] < 1) {
- pDash[i] = 1;
- }
- }
- }
- HPEN hPen = ExtCreatePen(PenStyle, (DWORD)FXSYS_ceil(width), &lb,
- pGraphState->m_DashCount, (const DWORD*)pDash);
- FX_Free(pDash);
- return hPen;
-}
-static HBRUSH _CreateBrush(uint32_t argb) {
- int a;
- FX_COLORREF rgb;
- ArgbDecode(argb, a, rgb);
- return CreateSolidBrush(rgb);
-}
-static void _SetPathToDC(HDC hDC,
- const CFX_PathData* pPathData,
- const CFX_Matrix* pMatrix) {
- BeginPath(hDC);
- int nPoints = pPathData->GetPointCount();
- FX_PATHPOINT* pPoints = pPathData->GetPoints();
- for (int i = 0; i < nPoints; i++) {
- FX_FLOAT posx = pPoints[i].m_PointX, posy = pPoints[i].m_PointY;
- if (pMatrix) {
- pMatrix->Transform(posx, posy);
- }
- int screen_x = FXSYS_round(posx), screen_y = FXSYS_round(posy);
- int point_type = pPoints[i].m_Flag & FXPT_TYPE;
- if (point_type == PT_MOVETO) {
- MoveToEx(hDC, screen_x, screen_y, NULL);
- } else if (point_type == PT_LINETO) {
- if (pPoints[i].m_PointY == pPoints[i - 1].m_PointY &&
- pPoints[i].m_PointX == pPoints[i - 1].m_PointX) {
- screen_x++;
- }
- LineTo(hDC, screen_x, screen_y);
- } else if (point_type == PT_BEZIERTO) {
- POINT lppt[3];
- lppt[0].x = screen_x;
- lppt[0].y = screen_y;
- posx = pPoints[i + 1].m_PointX;
- posy = pPoints[i + 1].m_PointY;
- if (pMatrix) {
- pMatrix->Transform(posx, posy);
- }
- lppt[1].x = FXSYS_round(posx);
- lppt[1].y = FXSYS_round(posy);
- posx = pPoints[i + 2].m_PointX;
- posy = pPoints[i + 2].m_PointY;
- if (pMatrix) {
- pMatrix->Transform(posx, posy);
- }
- lppt[2].x = FXSYS_round(posx);
- lppt[2].y = FXSYS_round(posy);
- PolyBezierTo(hDC, lppt, 3);
- i += 2;
- }
- if (pPoints[i].m_Flag & PT_CLOSEFIGURE) {
- CloseFigure(hDC);
- }
- }
- EndPath(hDC);
-}
-
-#ifdef _SKIA_SUPPORT_
-// TODO(caryclark) This antigrain function is duplicated here to permit
-// removing the last remaining dependency. Eventually, this will be elminiated
-// altogether and replace by Skia code.
-
-struct rect_base {
- FX_FLOAT x1;
- FX_FLOAT y1;
- FX_FLOAT x2;
- FX_FLOAT y2;
-};
-
-static unsigned clip_liang_barsky(FX_FLOAT x1,
- FX_FLOAT y1,
- FX_FLOAT x2,
- FX_FLOAT y2,
- const rect_base& clip_box,
- FX_FLOAT* x,
- FX_FLOAT* y) {
- const FX_FLOAT nearzero = 1e-30f;
- FX_FLOAT deltax = x2 - x1;
- FX_FLOAT deltay = y2 - y1;
- unsigned np = 0;
- if (deltax == 0)
- deltax = (x1 > clip_box.x1) ? -nearzero : nearzero;
- FX_FLOAT xin, xout;
- if (deltax > 0) {
- xin = clip_box.x1;
- xout = clip_box.x2;
- } else {
- xin = clip_box.x2;
- xout = clip_box.x1;
- }
- FX_FLOAT tinx = (xin - x1) / deltax;
- if (deltay == 0)
- deltay = (y1 > clip_box.y1) ? -nearzero : nearzero;
- FX_FLOAT yin, yout;
- if (deltay > 0) {
- yin = clip_box.y1;
- yout = clip_box.y2;
- } else {
- yin = clip_box.y2;
- yout = clip_box.y1;
- }
- FX_FLOAT tiny = (yin - y1) / deltay;
- FX_FLOAT tin1, tin2;
- if (tinx < tiny) {
- tin1 = tinx;
- tin2 = tiny;
- } else {
- tin1 = tiny;
- tin2 = tinx;
- }
- if (tin1 <= 1.0f) {
- if (0 < tin1) {
- *x++ = xin;
- *y++ = yin;
- ++np;
- }
- if (tin2 <= 1.0f) {
- FX_FLOAT toutx = (xout - x1) / deltax;
- FX_FLOAT touty = (yout - y1) / deltay;
- FX_FLOAT tout1 = (toutx < touty) ? toutx : touty;
- if (tin2 > 0 || tout1 > 0) {
- if (tin2 <= tout1) {
- if (tin2 > 0) {
- if (tinx > tiny) {
- *x++ = xin;
- *y++ = y1 + (deltay * tinx);
- } else {
- *x++ = x1 + (deltax * tiny);
- *y++ = yin;
- }
- ++np;
- }
- if (tout1 < 1.0f) {
- if (toutx < touty) {
- *x++ = xout;
- *y++ = y1 + (deltay * toutx);
- } else {
- *x++ = x1 + (deltax * touty);
- *y++ = yout;
- }
- } else {
- *x++ = x2;
- *y++ = y2;
- }
- ++np;
- } else {
- if (tinx > tiny) {
- *x++ = xin;
- *y++ = yout;
- } else {
- *x++ = xout;
- *y++ = yin;
- }
- ++np;
- }
- }
- }
- }
- return np;
-}
-#endif
void CGdiDeviceDriver::DrawLine(FX_FLOAT x1,
FX_FLOAT y1,
@@ -966,13 +990,10 @@ void CGdiDeviceDriver::DrawLine(FX_FLOAT x1,
y2 = y[np - 1];
}
}
- MoveToEx(m_hDC, FXSYS_round(x1), FXSYS_round(y1), NULL);
+ MoveToEx(m_hDC, FXSYS_round(x1), FXSYS_round(y1), nullptr);
LineTo(m_hDC, FXSYS_round(x2), FXSYS_round(y2));
}
-static FX_BOOL _MatrixNoScaled(const CFX_Matrix* pMatrix) {
- return pMatrix->GetA() == 1.0f && pMatrix->GetB() == 0 &&
- pMatrix->GetC() == 0 && pMatrix->GetD() == 1.0f;
-}
+
FX_BOOL CGdiDeviceDriver::DrawPath(const CFX_PathData* pPathData,
const CFX_Matrix* pMatrix,
const CFX_GraphStateData* pGraphState,
@@ -1019,7 +1040,7 @@ FX_BOOL CGdiDeviceDriver::DrawPath(const CFX_PathData* pPathData,
if (bDrawAlpha ||
((m_DeviceClass != FXDC_PRINTER && !(fill_mode & FXFILL_FULLCOVER)) ||
(pGraphState && pGraphState->m_DashCount))) {
- if (!((NULL == pMatrix || _MatrixNoScaled(pMatrix)) && pGraphState &&
+ if (!((!pMatrix || MatrixNoScaled(pMatrix)) && pGraphState &&
pGraphState->m_LineWidth == 1.f &&
(pPathData->GetPointCount() == 5 ||
pPathData->GetPointCount() == 4) &&
@@ -1034,16 +1055,16 @@ FX_BOOL CGdiDeviceDriver::DrawPath(const CFX_PathData* pPathData,
}
int old_fill_mode = fill_mode;
fill_mode &= 3;
- HPEN hPen = NULL;
- HBRUSH hBrush = NULL;
+ HPEN hPen = nullptr;
+ HBRUSH hBrush = nullptr;
if (pGraphState && stroke_alpha) {
- SetMiterLimit(m_hDC, pGraphState->m_MiterLimit, NULL);
- hPen = _CreatePen(pGraphState, pMatrix, stroke_color);
+ SetMiterLimit(m_hDC, pGraphState->m_MiterLimit, nullptr);
+ hPen = CreatePen(pGraphState, pMatrix, stroke_color);
hPen = (HPEN)SelectObject(m_hDC, hPen);
}
if (fill_mode && fill_alpha) {
SetPolyFillMode(m_hDC, fill_mode);
- hBrush = _CreateBrush(fill_color);
+ hBrush = CreateBrush(fill_color);
hBrush = (HBRUSH)SelectObject(m_hDC, hBrush);
}
if (pPathData->GetPointCount() == 2 && pGraphState &&
@@ -1058,14 +1079,14 @@ FX_BOOL CGdiDeviceDriver::DrawPath(const CFX_PathData* pPathData,
}
DrawLine(x1, y1, x2, y2);
} else {
- _SetPathToDC(m_hDC, pPathData, pMatrix);
+ SetPathToDC(m_hDC, pPathData, pMatrix);
if (pGraphState && stroke_alpha) {
if (fill_mode && fill_alpha) {
if (old_fill_mode & FX_FILL_TEXT_MODE) {
StrokeAndFillPath(m_hDC);
} else {
FillPath(m_hDC);
- _SetPathToDC(m_hDC, pPathData, pMatrix);
+ SetPathToDC(m_hDC, pPathData, pMatrix);
StrokePath(m_hDC);
}
} else {
@@ -1085,6 +1106,7 @@ FX_BOOL CGdiDeviceDriver::DrawPath(const CFX_PathData* pPathData,
}
return TRUE;
}
+
FX_BOOL CGdiDeviceDriver::FillRect(const FX_RECT* pRect,
uint32_t fill_color,
int alpha_flag,
@@ -1108,6 +1130,7 @@ FX_BOOL CGdiDeviceDriver::FillRect(const FX_RECT* pRect,
DeleteObject(hBrush);
return TRUE;
}
+
FX_BOOL CGdiDeviceDriver::SetClip_PathFill(const CFX_PathData* pPathData,
const CFX_Matrix* pMatrix,
int fill_mode) {
@@ -1119,18 +1142,19 @@ FX_BOOL CGdiDeviceDriver::SetClip_PathFill(const CFX_PathData* pPathData,
return TRUE;
}
}
- _SetPathToDC(m_hDC, pPathData, pMatrix);
+ SetPathToDC(m_hDC, pPathData, pMatrix);
SetPolyFillMode(m_hDC, fill_mode & 3);
SelectClipPath(m_hDC, RGN_AND);
return TRUE;
}
+
FX_BOOL CGdiDeviceDriver::SetClip_PathStroke(
const CFX_PathData* pPathData,
const CFX_Matrix* pMatrix,
const CFX_GraphStateData* pGraphState) {
- HPEN hPen = _CreatePen(pGraphState, pMatrix, 0xff000000);
+ HPEN hPen = CreatePen(pGraphState, pMatrix, 0xff000000);
hPen = (HPEN)SelectObject(m_hDC, hPen);
- _SetPathToDC(m_hDC, pPathData, pMatrix);
+ SetPathToDC(m_hDC, pPathData, pMatrix);
WidenPath(m_hDC);
SetPolyFillMode(m_hDC, WINDING);
FX_BOOL ret = SelectClipPath(m_hDC, RGN_AND);
@@ -1138,6 +1162,7 @@ FX_BOOL CGdiDeviceDriver::SetClip_PathStroke(
DeleteObject(hPen);
return ret;
}
+
FX_BOOL CGdiDeviceDriver::DrawCosmeticLine(FX_FLOAT x1,
FX_FLOAT y1,
FX_FLOAT x2,
@@ -1158,16 +1183,18 @@ FX_BOOL CGdiDeviceDriver::DrawCosmeticLine(FX_FLOAT x1,
}
HPEN hPen = CreatePen(PS_SOLID, 1, rgb);
hPen = (HPEN)SelectObject(m_hDC, hPen);
- MoveToEx(m_hDC, FXSYS_round(x1), FXSYS_round(y1), NULL);
+ MoveToEx(m_hDC, FXSYS_round(x1), FXSYS_round(y1), nullptr);
LineTo(m_hDC, FXSYS_round(x2), FXSYS_round(y2));
hPen = (HPEN)SelectObject(m_hDC, hPen);
DeleteObject(hPen);
return TRUE;
}
+
FX_BOOL CGdiDeviceDriver::DeleteDeviceRgn(void* pRgn) {
DeleteObject((HGDIOBJ)pRgn);
return TRUE;
}
+
CGdiDisplayDriver::CGdiDisplayDriver(HDC hDC)
: CGdiDeviceDriver(hDC, FXDC_DISPLAY) {
CWin32Platform* pPlatform =
@@ -1176,6 +1203,7 @@ CGdiDisplayDriver::CGdiDisplayDriver(HDC hDC)
m_RenderCaps |= FXRC_ALPHA_PATH | FXRC_ALPHA_IMAGE;
}
}
+
FX_BOOL CGdiDisplayDriver::GetDIBits(CFX_DIBitmap* pBitmap,
int left,
int top,
@@ -1198,7 +1226,7 @@ FX_BOOL CGdiDisplayDriver::GetDIBits(CFX_DIBitmap* pBitmap,
bmi.bmiHeader.biWidth = width;
if (!CFX_GEModule::Get()->GetCodecModule() ||
!CFX_GEModule::Get()->GetCodecModule()->GetIccModule()) {
- pIccTransform = NULL;
+ pIccTransform = nullptr;
}
if (pBitmap->GetBPP() > 8 && !pBitmap->IsCmykImage() && !pIccTransform) {
ret = ::GetDIBits(hDCMemory, hbmp, 0, height, pBitmap->GetBuffer(), &bmi,
@@ -1222,6 +1250,7 @@ FX_BOOL CGdiDisplayDriver::GetDIBits(CFX_DIBitmap* pBitmap,
DeleteObject(hDCMemory);
return ret;
}
+
FX_BOOL CGdiDisplayDriver::SetDIBits(const CFX_DIBSource* pSource,
uint32_t color,
const FX_RECT* pSrcRect,
@@ -1239,15 +1268,15 @@ FX_BOOL CGdiDisplayDriver::SetDIBits(const CFX_DIBSource* pSource,
if (pSource->GetBPP() != 1 || alpha != 255) {
CFX_DIBitmap background;
if (!background.Create(width, height, FXDIB_Rgb32) ||
- !GetDIBits(&background, left, top, NULL) ||
+ !GetDIBits(&background, left, top, nullptr) ||
!background.CompositeMask(0, 0, width, height, pSource, color, 0, 0,
- FXDIB_BLEND_NORMAL, NULL, FALSE, alpha_flag,
- pIccTransform)) {
+ FXDIB_BLEND_NORMAL, nullptr, FALSE,
+ alpha_flag, pIccTransform)) {
return FALSE;
}
FX_RECT src_rect(0, 0, width, height);
return SetDIBits(&background, 0, &src_rect, left, top, FXDIB_BLEND_NORMAL,
- 0, NULL);
+ 0, nullptr);
}
FX_RECT clip_rect(left, top, left + pSrcRect->Width(),
top + pSrcRect->Height());
@@ -1259,15 +1288,15 @@ FX_BOOL CGdiDisplayDriver::SetDIBits(const CFX_DIBSource* pSource,
if (pSource->HasAlpha()) {
CFX_DIBitmap bitmap;
if (!bitmap.Create(width, height, FXDIB_Rgb) ||
- !GetDIBits(&bitmap, left, top, NULL) ||
+ !GetDIBits(&bitmap, left, top, nullptr) ||
!bitmap.CompositeBitmap(0, 0, width, height, pSource, pSrcRect->left,
- pSrcRect->top, FXDIB_BLEND_NORMAL, NULL, FALSE,
- pIccTransform)) {
+ pSrcRect->top, FXDIB_BLEND_NORMAL, nullptr,
+ FALSE, pIccTransform)) {
return FALSE;
}
FX_RECT src_rect(0, 0, width, height);
return SetDIBits(&bitmap, 0, &src_rect, left, top, FXDIB_BLEND_NORMAL, 0,
- NULL);
+ nullptr);
}
CFX_DIBExtractor temp(pSource);
CFX_DIBitmap* pBitmap = temp;
@@ -1276,6 +1305,7 @@ FX_BOOL CGdiDisplayDriver::SetDIBits(const CFX_DIBSource* pSource,
}
return FALSE;
}
+
FX_BOOL CGdiDisplayDriver::UseFoxitStretchEngine(const CFX_DIBSource* pSource,
uint32_t color,
int dest_left,
@@ -1295,18 +1325,17 @@ FX_BOOL CGdiDisplayDriver::UseFoxitStretchEngine(const CFX_DIBSource* pSource,
dest_top += dest_height;
}
bitmap_clip.Offset(-dest_left, -dest_top);
- CFX_DIBitmap* pStretched =
- pSource->StretchTo(dest_width, dest_height, render_flags, &bitmap_clip);
- if (!pStretched) {
+ std::unique_ptr<CFX_DIBitmap> pStretched(
+ pSource->StretchTo(dest_width, dest_height, render_flags, &bitmap_clip));
+ if (!pStretched)
return TRUE;
- }
+
FX_RECT src_rect(0, 0, pStretched->GetWidth(), pStretched->GetHeight());
- FX_BOOL ret =
- SetDIBits(pStretched, color, &src_rect, pClipRect->left, pClipRect->top,
- FXDIB_BLEND_NORMAL, alpha_flag, pIccTransform);
- delete pStretched;
- return ret;
+ return SetDIBits(pStretched.get(), color, &src_rect, pClipRect->left,
+ pClipRect->top, FXDIB_BLEND_NORMAL, alpha_flag,
+ pIccTransform);
}
+
FX_BOOL CGdiDisplayDriver::StretchDIBits(const CFX_DIBSource* pSource,
uint32_t color,
int dest_left,
@@ -1335,27 +1364,25 @@ FX_BOOL CGdiDisplayDriver::StretchDIBits(const CFX_DIBSource* pSource,
clip_rect.Intersect(*pClipRect);
clip_rect.Offset(-image_rect.left, -image_rect.top);
int clip_width = clip_rect.Width(), clip_height = clip_rect.Height();
- CFX_DIBitmap* pStretched =
- pSource->StretchTo(dest_width, dest_height, flags, &clip_rect);
- if (!pStretched) {
+ std::unique_ptr<CFX_DIBitmap> pStretched(
+ pSource->StretchTo(dest_width, dest_height, flags, &clip_rect));
+ if (!pStretched)
return TRUE;
- }
+
CFX_DIBitmap background;
if (!background.Create(clip_width, clip_height, FXDIB_Rgb32) ||
!GetDIBits(&background, image_rect.left + clip_rect.left,
- image_rect.top + clip_rect.top, NULL) ||
- !background.CompositeMask(0, 0, clip_width, clip_height, pStretched,
- color, 0, 0, FXDIB_BLEND_NORMAL, NULL, FALSE,
- alpha_flag, pIccTransform)) {
- delete pStretched;
+ image_rect.top + clip_rect.top, nullptr) ||
+ !background.CompositeMask(
+ 0, 0, clip_width, clip_height, pStretched.get(), color, 0, 0,
+ FXDIB_BLEND_NORMAL, nullptr, FALSE, alpha_flag, pIccTransform)) {
return FALSE;
}
+
FX_RECT src_rect(0, 0, clip_width, clip_height);
- FX_BOOL ret =
- SetDIBits(&background, 0, &src_rect, image_rect.left + clip_rect.left,
- image_rect.top + clip_rect.top, FXDIB_BLEND_NORMAL, 0, NULL);
- delete pStretched;
- return ret;
+ return SetDIBits(
+ &background, 0, &src_rect, image_rect.left + clip_rect.left,
+ image_rect.top + clip_rect.top, FXDIB_BLEND_NORMAL, 0, nullptr);
}
if (pSource->HasAlpha()) {
CWin32Platform* pPlatform =
@@ -1364,9 +1391,8 @@ FX_BOOL CGdiDisplayDriver::StretchDIBits(const CFX_DIBSource* pSource,
!pSource->IsCmykImage()) {
CFX_DIBExtractor temp(pSource);
CFX_DIBitmap* pBitmap = temp;
- if (!pBitmap) {
+ if (!pBitmap)
return FALSE;
- }
return pPlatform->m_GdiplusExt.StretchDIBits(
m_hDC, pBitmap, dest_left, dest_top, dest_width, dest_height,
pClipRect, flags);
@@ -1383,45 +1409,10 @@ FX_BOOL CGdiDisplayDriver::StretchDIBits(const CFX_DIBSource* pSource,
}
return FALSE;
}
-#define GET_PS_FEATURESETTING 4121
-#define FEATURESETTING_PSLEVEL 2
-int GetPSLevel(HDC hDC) {
- int device_type = ::GetDeviceCaps(hDC, TECHNOLOGY);
- if (device_type != DT_RASPRINTER) {
- return 0;
- }
- uint32_t esc = GET_PS_FEATURESETTING;
- if (ExtEscape(hDC, QUERYESCSUPPORT, sizeof esc, (char*)&esc, 0, NULL)) {
- int param = FEATURESETTING_PSLEVEL;
- if (ExtEscape(hDC, GET_PS_FEATURESETTING, sizeof(int), (char*)&param,
- sizeof(int), (char*)&param) > 0) {
- return param;
- }
- }
- esc = POSTSCRIPT_IDENTIFY;
- if (ExtEscape(hDC, QUERYESCSUPPORT, sizeof esc, (char*)&esc, 0, NULL) == 0) {
- esc = POSTSCRIPT_DATA;
- if (ExtEscape(hDC, QUERYESCSUPPORT, sizeof esc, (char*)&esc, 0, NULL)) {
- return 2;
- }
- return 0;
- }
- esc = PSIDENT_GDICENTRIC;
- if (ExtEscape(hDC, POSTSCRIPT_IDENTIFY, sizeof(uint32_t), (char*)&esc, 0,
- NULL) <= 0) {
- return 2;
- }
- esc = GET_PS_FEATURESETTING;
- if (ExtEscape(hDC, QUERYESCSUPPORT, sizeof esc, (char*)&esc, 0, NULL)) {
- int param = FEATURESETTING_PSLEVEL;
- if (ExtEscape(hDC, GET_PS_FEATURESETTING, sizeof(int), (char*)&param,
- sizeof(int), (char*)&param) > 0) {
- return param;
- }
- }
- return 2;
-}
+
+// static
int CFX_WindowsDevice::m_psLevel = 2;
+
CFX_WindowsDevice::CFX_WindowsDevice(HDC hDC,
FX_BOOL bCmykOutput,
FX_BOOL bForcePSOutput,
@@ -1436,29 +1427,23 @@ CFX_WindowsDevice::CFX_WindowsDevice(HDC hDC,
}
SetDeviceDriver(CreateDriver(hDC, bCmykOutput));
}
+
HDC CFX_WindowsDevice::GetDC() const {
IFX_RenderDeviceDriver* pRDD = GetDeviceDriver();
- if (!pRDD) {
- return NULL;
- }
- return (HDC)pRDD->GetPlatformSurface();
+ return pRDD ? reinterpret_cast<HDC>(pRDD->GetPlatformSurface()) : nullptr;
}
+
IFX_RenderDeviceDriver* CFX_WindowsDevice::CreateDriver(HDC hDC,
FX_BOOL bCmykOutput) {
int device_type = ::GetDeviceCaps(hDC, TECHNOLOGY);
int obj_type = ::GetObjectType(hDC);
- int device_class;
- if (device_type == DT_RASPRINTER || device_type == DT_PLOTTER ||
- obj_type == OBJ_ENHMETADC) {
- device_class = FXDC_PRINTER;
- } else {
- device_class = FXDC_DISPLAY;
- }
- if (device_class == FXDC_PRINTER) {
+ bool use_printer = device_type == DT_RASPRINTER ||
+ device_type == DT_PLOTTER || obj_type == OBJ_ENHMETADC;
+ if (use_printer)
return new CGdiPrinterDriver(hDC);
- }
return new CGdiDisplayDriver(hDC);
}
+
CFX_WinBitmapDevice::CFX_WinBitmapDevice(int width,
int height,
FXDIB_Format format) {
@@ -1469,28 +1454,29 @@ CFX_WinBitmapDevice::CFX_WinBitmapDevice(int width,
bmih.biHeight = -height;
bmih.biPlanes = 1;
bmih.biWidth = width;
- uint8_t* pBuffer;
- m_hBitmap = CreateDIBSection(NULL, (BITMAPINFO*)&bmih, DIB_RGB_COLORS,
- (void**)&pBuffer, NULL, 0);
- if (!m_hBitmap) {
+ void* pBufferPtr;
+ m_hBitmap = CreateDIBSection(nullptr, reinterpret_cast<BITMAPINFO*>(&bmih),
+ DIB_RGB_COLORS, &pBufferPtr, nullptr, 0);
+ if (!m_hBitmap)
return;
- }
+
+ uint8_t* pBuffer = static_cast<uint8_t*>(pBufferPtr);
CFX_DIBitmap* pBitmap = new CFX_DIBitmap;
pBitmap->Create(width, height, format, pBuffer);
SetBitmap(pBitmap);
- m_hDC = ::CreateCompatibleDC(NULL);
+ m_hDC = ::CreateCompatibleDC(nullptr);
m_hOldBitmap = (HBITMAP)SelectObject(m_hDC, m_hBitmap);
IFX_RenderDeviceDriver* pDriver = new CGdiDisplayDriver(m_hDC);
SetDeviceDriver(pDriver);
}
+
CFX_WinBitmapDevice::~CFX_WinBitmapDevice() {
if (m_hDC) {
SelectObject(m_hDC, m_hOldBitmap);
DeleteDC(m_hDC);
}
- if (m_hBitmap) {
+ if (m_hBitmap)
DeleteObject(m_hBitmap);
- }
delete GetBitmap();
}
diff --git a/core/fxge/win32/fx_win32_print.cpp b/core/fxge/win32/fx_win32_print.cpp
index 9fd1683a80..e46beeefbd 100644
--- a/core/fxge/win32/fx_win32_print.cpp
+++ b/core/fxge/win32/fx_win32_print.cpp
@@ -16,135 +16,18 @@
#include "core/fxge/include/fx_ge_win32.h"
#include "core/fxge/win32/win32_int.h"
-#define SIZETHRESHOLD 1000
-#define OUTPUTPSLEN 4096
-CGdiPrinterDriver::CGdiPrinterDriver(HDC hDC)
- : CGdiDeviceDriver(hDC, FXDC_PRINTER) {
- m_HorzSize = ::GetDeviceCaps(m_hDC, HORZSIZE);
- m_VertSize = ::GetDeviceCaps(m_hDC, VERTSIZE);
- m_bSupportROP = TRUE;
-}
-int CGdiPrinterDriver::GetDeviceCaps(int caps_id) {
- if (caps_id == FXDC_HORZ_SIZE) {
- return m_HorzSize;
- }
- if (caps_id == FXDC_VERT_SIZE) {
- return m_VertSize;
- }
- return CGdiDeviceDriver::GetDeviceCaps(caps_id);
-}
-FX_BOOL CGdiPrinterDriver::SetDIBits(const CFX_DIBSource* pSource,
- uint32_t color,
- const FX_RECT* pSrcRect,
- int left,
- int top,
- int blend_type,
- int alpha_flag,
- void* pIccTransform) {
- if (pSource->IsAlphaMask()) {
- FX_RECT clip_rect(left, top, left + pSrcRect->Width(),
- top + pSrcRect->Height());
- return StretchDIBits(pSource, color, left - pSrcRect->left,
- top - pSrcRect->top, pSource->GetWidth(),
- pSource->GetHeight(), &clip_rect, 0, alpha_flag,
- pIccTransform, FXDIB_BLEND_NORMAL);
- }
- ASSERT(pSource && !pSource->IsAlphaMask() && pSrcRect);
- ASSERT(blend_type == FXDIB_BLEND_NORMAL);
- if (pSource->HasAlpha()) {
- return FALSE;
- }
- CFX_DIBExtractor temp(pSource);
- CFX_DIBitmap* pBitmap = temp;
- if (!pBitmap) {
- return FALSE;
- }
- return GDI_SetDIBits(pBitmap, pSrcRect, left, top, pIccTransform);
-}
-FX_BOOL CGdiPrinterDriver::StretchDIBits(const CFX_DIBSource* pSource,
- uint32_t color,
- int dest_left,
- int dest_top,
- int dest_width,
- int dest_height,
- const FX_RECT* pClipRect,
- uint32_t flags,
- int alpha_flag,
- void* pIccTransform,
- int blend_type) {
- if (pSource->IsAlphaMask()) {
- int alpha = FXGETFLAG_COLORTYPE(alpha_flag)
- ? FXGETFLAG_ALPHA_FILL(alpha_flag)
- : FXARGB_A(color);
- if (pSource->GetBPP() != 1 || alpha != 255 || !m_bSupportROP) {
- return FALSE;
- }
- if (dest_width < 0 || dest_height < 0) {
- CFX_DIBitmap* pFlipped =
- pSource->FlipImage(dest_width < 0, dest_height < 0);
- if (!pFlipped) {
- return FALSE;
- }
- if (dest_width < 0) {
- dest_left += dest_width;
- }
- if (dest_height < 0) {
- dest_top += dest_height;
- }
- FX_BOOL ret = GDI_StretchBitMask(pFlipped, dest_left, dest_top,
- abs(dest_width), abs(dest_height), color,
- flags, alpha_flag, pIccTransform);
- delete pFlipped;
- return ret;
- }
- CFX_DIBExtractor temp(pSource);
- CFX_DIBitmap* pBitmap = temp;
- if (!pBitmap) {
- return FALSE;
- }
- return GDI_StretchBitMask(pBitmap, dest_left, dest_top, dest_width,
- dest_height, color, flags, alpha_flag,
- pIccTransform);
- }
- if (pSource->HasAlpha()) {
- return FALSE;
- }
- if (dest_width < 0 || dest_height < 0) {
- CFX_DIBitmap* pFlipped =
- pSource->FlipImage(dest_width < 0, dest_height < 0);
- if (!pFlipped) {
- return FALSE;
- }
- if (dest_width < 0) {
- dest_left += dest_width;
- }
- if (dest_height < 0) {
- dest_top += dest_height;
- }
- FX_BOOL ret =
- GDI_StretchDIBits(pFlipped, dest_left, dest_top, abs(dest_width),
- abs(dest_height), flags, pIccTransform);
- delete pFlipped;
- return ret;
- }
- CFX_DIBExtractor temp(pSource);
- CFX_DIBitmap* pBitmap = temp;
- if (!pBitmap) {
- return FALSE;
- }
- return GDI_StretchDIBits(pBitmap, dest_left, dest_top, dest_width,
- dest_height, flags, pIccTransform);
-}
-static CFX_DIBitmap* Transform1bppBitmap(const CFX_DIBSource* pSrc,
- const CFX_Matrix* pDestMatrix) {
+namespace {
+
+CFX_DIBitmap* Transform1bppBitmap(const CFX_DIBSource* pSrc,
+ const CFX_Matrix* pDestMatrix) {
ASSERT(pSrc->GetFormat() == FXDIB_1bppRgb ||
pSrc->GetFormat() == FXDIB_1bppMask ||
pSrc->GetFormat() == FXDIB_1bppCmyk);
CFX_DIBExtractor src_bitmap(pSrc);
CFX_DIBitmap* pSrcBitmap = src_bitmap;
- if (!pSrcBitmap) {
- return NULL;
- }
+ if (!pSrcBitmap)
+ return nullptr;
+
int src_width = pSrcBitmap->GetWidth(), src_height = pSrcBitmap->GetHeight();
uint8_t* src_buf = pSrcBitmap->GetBuffer();
uint32_t src_pitch = pSrcBitmap->GetPitch();
@@ -168,14 +51,13 @@ static CFX_DIBitmap* Transform1bppBitmap(const CFX_DIBSource* pSrc,
CPDF_FixedMatrix result2src_fix(result2src, 8);
int result_width = result_rect.Width();
int result_height = result_rect.Height();
- CFX_DIBitmap* pTempBitmap = new CFX_DIBitmap;
+ std::unique_ptr<CFX_DIBitmap> pTempBitmap(new CFX_DIBitmap);
if (!pTempBitmap->Create(result_width, result_height, pSrc->GetFormat())) {
- delete pTempBitmap;
- if (pSrcBitmap != src_bitmap) {
+ if (pSrcBitmap != src_bitmap)
delete pSrcBitmap;
- }
- return NULL;
+ return nullptr;
}
+
pTempBitmap->CopyPalette(pSrc->GetPalette());
uint8_t* dest_buf = pTempBitmap->GetBuffer();
int dest_pitch = pTempBitmap->GetPitch();
@@ -215,11 +97,128 @@ static CFX_DIBitmap* Transform1bppBitmap(const CFX_DIBSource* pSrc,
}
}
}
- if (pSrcBitmap != src_bitmap) {
+ if (pSrcBitmap != src_bitmap)
delete pSrcBitmap;
+
+ return pTempBitmap.release();
+}
+
+} // namespace
+
+CGdiPrinterDriver::CGdiPrinterDriver(HDC hDC)
+ : CGdiDeviceDriver(hDC, FXDC_PRINTER),
+ m_HorzSize(::GetDeviceCaps(m_hDC, HORZSIZE)),
+ m_VertSize(::GetDeviceCaps(m_hDC, VERTSIZE)) {}
+
+CGdiPrinterDriver::~CGdiPrinterDriver() {}
+
+int CGdiPrinterDriver::GetDeviceCaps(int caps_id) {
+ if (caps_id == FXDC_HORZ_SIZE)
+ return m_HorzSize;
+ if (caps_id == FXDC_VERT_SIZE)
+ return m_VertSize;
+ return CGdiDeviceDriver::GetDeviceCaps(caps_id);
+}
+
+FX_BOOL CGdiPrinterDriver::SetDIBits(const CFX_DIBSource* pSource,
+ uint32_t color,
+ const FX_RECT* pSrcRect,
+ int left,
+ int top,
+ int blend_type,
+ int alpha_flag,
+ void* pIccTransform) {
+ if (pSource->IsAlphaMask()) {
+ FX_RECT clip_rect(left, top, left + pSrcRect->Width(),
+ top + pSrcRect->Height());
+ return StretchDIBits(pSource, color, left - pSrcRect->left,
+ top - pSrcRect->top, pSource->GetWidth(),
+ pSource->GetHeight(), &clip_rect, 0, alpha_flag,
+ pIccTransform, FXDIB_BLEND_NORMAL);
}
- return pTempBitmap;
+ ASSERT(pSource && !pSource->IsAlphaMask() && pSrcRect);
+ ASSERT(blend_type == FXDIB_BLEND_NORMAL);
+ if (pSource->HasAlpha())
+ return FALSE;
+
+ CFX_DIBExtractor temp(pSource);
+ CFX_DIBitmap* pBitmap = temp;
+ if (!pBitmap)
+ return FALSE;
+
+ return GDI_SetDIBits(pBitmap, pSrcRect, left, top, pIccTransform);
}
+
+FX_BOOL CGdiPrinterDriver::StretchDIBits(const CFX_DIBSource* pSource,
+ uint32_t color,
+ int dest_left,
+ int dest_top,
+ int dest_width,
+ int dest_height,
+ const FX_RECT* pClipRect,
+ uint32_t flags,
+ int alpha_flag,
+ void* pIccTransform,
+ int blend_type) {
+ if (pSource->IsAlphaMask()) {
+ int alpha = FXGETFLAG_COLORTYPE(alpha_flag)
+ ? FXGETFLAG_ALPHA_FILL(alpha_flag)
+ : FXARGB_A(color);
+ if (pSource->GetBPP() != 1 || alpha != 255)
+ return FALSE;
+
+ if (dest_width < 0 || dest_height < 0) {
+ std::unique_ptr<CFX_DIBitmap> pFlipped(
+ pSource->FlipImage(dest_width < 0, dest_height < 0));
+ if (!pFlipped)
+ return FALSE;
+
+ if (dest_width < 0)
+ dest_left += dest_width;
+ if (dest_height < 0)
+ dest_top += dest_height;
+
+ return GDI_StretchBitMask(pFlipped.get(), dest_left, dest_top,
+ abs(dest_width), abs(dest_height), color, flags,
+ alpha_flag, pIccTransform);
+ }
+
+ CFX_DIBExtractor temp(pSource);
+ CFX_DIBitmap* pBitmap = temp;
+ if (!pBitmap)
+ return FALSE;
+ return GDI_StretchBitMask(pBitmap, dest_left, dest_top, dest_width,
+ dest_height, color, flags, alpha_flag,
+ pIccTransform);
+ }
+
+ if (pSource->HasAlpha())
+ return FALSE;
+
+ if (dest_width < 0 || dest_height < 0) {
+ std::unique_ptr<CFX_DIBitmap> pFlipped(
+ pSource->FlipImage(dest_width < 0, dest_height < 0));
+ if (!pFlipped)
+ return FALSE;
+
+ if (dest_width < 0)
+ dest_left += dest_width;
+ if (dest_height < 0)
+ dest_top += dest_height;
+
+ return GDI_StretchDIBits(pFlipped.get(), dest_left, dest_top,
+ abs(dest_width), abs(dest_height), flags,
+ pIccTransform);
+ }
+
+ CFX_DIBExtractor temp(pSource);
+ CFX_DIBitmap* pBitmap = temp;
+ if (!pBitmap)
+ return FALSE;
+ return GDI_StretchDIBits(pBitmap, dest_left, dest_top, dest_width,
+ dest_height, flags, pIccTransform);
+}
+
FX_BOOL CGdiPrinterDriver::StartDIBits(const CFX_DIBSource* pSource,
int bitmap_alpha,
uint32_t color,
@@ -230,7 +229,7 @@ FX_BOOL CGdiPrinterDriver::StartDIBits(const CFX_DIBSource* pSource,
void* pIccTransform,
int blend_type) {
if (bitmap_alpha < 255 || pSource->HasAlpha() ||
- (pSource->IsAlphaMask() && (pSource->GetBPP() != 1 || !m_bSupportROP))) {
+ (pSource->IsAlphaMask() && (pSource->GetBPP() != 1))) {
return FALSE;
}
CFX_FloatRect unit_rect = pMatrix->GetUnitRect();
@@ -244,39 +243,39 @@ FX_BOOL CGdiPrinterDriver::StartDIBits(const CFX_DIBSource* pSource,
bFlipY ? full_rect.bottom : full_rect.top,
bFlipX ? -full_rect.Width() : full_rect.Width(),
bFlipY ? -full_rect.Height() : full_rect.Height(),
- NULL, 0, alpha_flag, pIccTransform, blend_type);
+ nullptr, 0, alpha_flag, pIccTransform, blend_type);
}
if (FXSYS_fabs(pMatrix->a) < 0.5f && FXSYS_fabs(pMatrix->d) < 0.5f) {
- CFX_DIBitmap* pTransformed =
- pSource->SwapXY(pMatrix->c > 0, pMatrix->b < 0);
- if (!pTransformed) {
- return FALSE;
- }
- FX_BOOL ret = StretchDIBits(
- pTransformed, color, full_rect.left, full_rect.top, full_rect.Width(),
- full_rect.Height(), NULL, 0, alpha_flag, pIccTransform, blend_type);
- delete pTransformed;
- return ret;
- }
- if (pSource->GetBPP() == 1) {
- CFX_DIBitmap* pTransformed = Transform1bppBitmap(pSource, pMatrix);
- if (!pIccTransform) {
+ std::unique_ptr<CFX_DIBitmap> pTransformed(
+ pSource->SwapXY(pMatrix->c > 0, pMatrix->b < 0));
+ if (!pTransformed)
return FALSE;
- }
- SaveState();
- CFX_PathData path;
- path.AppendRect(0, 0, 1.0f, 1.0f);
- SetClip_PathFill(&path, pMatrix, WINDING);
- FX_BOOL ret = StretchDIBits(
- pTransformed, color, full_rect.left, full_rect.top, full_rect.Width(),
- full_rect.Height(), NULL, 0, alpha_flag, pIccTransform, blend_type);
- RestoreState(false);
- delete pTransformed;
- handle = NULL;
- return ret;
+
+ return StretchDIBits(pTransformed.get(), color, full_rect.left,
+ full_rect.top, full_rect.Width(), full_rect.Height(),
+ nullptr, 0, alpha_flag, pIccTransform, blend_type);
}
- return FALSE;
+ if (pSource->GetBPP() != 1)
+ return FALSE;
+
+ std::unique_ptr<CFX_DIBitmap> pTransformed(
+ Transform1bppBitmap(pSource, pMatrix));
+ if (!pIccTransform)
+ return FALSE;
+
+ SaveState();
+ CFX_PathData path;
+ path.AppendRect(0, 0, 1.0f, 1.0f);
+ SetClip_PathFill(&path, pMatrix, WINDING);
+ FX_BOOL ret =
+ StretchDIBits(pTransformed.get(), color, full_rect.left, full_rect.top,
+ full_rect.Width(), full_rect.Height(), nullptr, 0,
+ alpha_flag, pIccTransform, blend_type);
+ RestoreState(false);
+ handle = nullptr;
+ return ret;
}
+
CPSOutput::CPSOutput(HDC hDC) {
m_hDC = hDC;
m_pBuf = NULL;
diff --git a/core/fxge/win32/win32_int.h b/core/fxge/win32/win32_int.h
index d2d091bc19..9d62b41a8e 100644
--- a/core/fxge/win32/win32_int.h
+++ b/core/fxge/win32/win32_int.h
@@ -107,6 +107,9 @@ class CWin32Platform {
class CGdiDeviceDriver : public IFX_RenderDeviceDriver {
protected:
+ CGdiDeviceDriver(HDC hDC, int device_class);
+ ~CGdiDeviceDriver() override {}
+
// IFX_RenderDeviceDriver
int GetDeviceCaps(int caps_id) override;
void SaveState() override;
@@ -147,19 +150,19 @@ class CGdiDeviceDriver : public IFX_RenderDeviceDriver {
virtual FX_BOOL DeleteDeviceRgn(void* pRgn);
virtual void DrawLine(FX_FLOAT x1, FX_FLOAT y1, FX_FLOAT x2, FX_FLOAT y2);
- FX_BOOL GDI_SetDIBits(const CFX_DIBitmap* pBitmap,
+ FX_BOOL GDI_SetDIBits(CFX_DIBitmap* pBitmap,
const FX_RECT* pSrcRect,
int left,
int top,
void* pIccTransform);
- FX_BOOL GDI_StretchDIBits(const CFX_DIBitmap* pBitmap,
+ FX_BOOL GDI_StretchDIBits(CFX_DIBitmap* pBitmap,
int dest_left,
int dest_top,
int dest_width,
int dest_height,
uint32_t flags,
void* pIccTransform);
- FX_BOOL GDI_StretchBitMask(const CFX_DIBitmap* pBitmap,
+ FX_BOOL GDI_StretchBitMask(CFX_DIBitmap* pBitmap,
int dest_left,
int dest_top,
int dest_width,
@@ -168,11 +171,13 @@ class CGdiDeviceDriver : public IFX_RenderDeviceDriver {
uint32_t flags,
int alpha_flag,
void* pIccTransform);
+
HDC m_hDC;
- int m_Width, m_Height, m_nBitsPerPixel;
- int m_DeviceClass, m_RenderCaps;
- CGdiDeviceDriver(HDC hDC, int device_class);
- ~CGdiDeviceDriver() override {}
+ int m_Width;
+ int m_Height;
+ int m_nBitsPerPixel;
+ int m_DeviceClass;
+ int m_RenderCaps;
};
class CGdiDisplayDriver : public CGdiDeviceDriver {
@@ -227,9 +232,11 @@ class CGdiDisplayDriver : public CGdiDeviceDriver {
void* pIccTransform = NULL,
int blend_type = FXDIB_BLEND_NORMAL);
};
+
class CGdiPrinterDriver : public CGdiDeviceDriver {
public:
- CGdiPrinterDriver(HDC hDC);
+ explicit CGdiPrinterDriver(HDC hDC);
+ ~CGdiPrinterDriver() override;
protected:
int GetDeviceCaps(int caps_id) override;
@@ -261,8 +268,9 @@ class CGdiPrinterDriver : public CGdiDeviceDriver {
int alpha_flag,
void* pIccTransform,
int blend_type) override;
- int m_HorzSize, m_VertSize;
- FX_BOOL m_bSupportROP;
+
+ const int m_HorzSize;
+ const int m_VertSize;
};
class CPSOutput : public IFX_PSOutput {