Fix a bug when performing StretchDIBits on bit mask
authorBo Xu <bo_xu@foxitsoftware.com>
Mon, 10 Nov 2014 21:34:05 +0000 (13:34 -0800)
committerBo Xu <bo_xu@foxitsoftware.com>
Mon, 10 Nov 2014 21:34:05 +0000 (13:34 -0800)
BUG=401988
R=vitalybuka@chromium.org

Review URL: https://codereview.chromium.org/618073003

core/src/fxge/win32/fx_win32_device.cpp

index eee4fd8..d821024 100644 (file)
@@ -570,8 +570,32 @@ FX_BOOL CGdiDeviceDriver::GDI_StretchBitMask(const CFX_DIBitmap* pBitmap1, int d
     }
     bmi.bmiColors[0] = 0xffffff;
     bmi.bmiColors[1] = 0;
-    ::StretchDIBits(m_hDC, dest_left, dest_top, dest_width, dest_height,
-                    0, 0, width, height, pBitmap->GetBuffer(), (BITMAPINFO*)&bmi, DIB_RGB_COLORS, SRCAND);
+
+    HBRUSH hPattern = CreateSolidBrush(bitmap_color & 0xffffff);\r
+    HBRUSH hOld = (HBRUSH)SelectObject(m_hDC, hPattern);\r
+\r
+    \r
+    // In PDF, when image mask is 1, use device bitmap; when mask is 0, use brush bitmap.\r
+    // A complete list of the boolen operations is as follows:\r
+\r
+    /* P(bitmap_color)    S(ImageMask)    D(DeviceBitmap)    Result\r
+     *        0                 0                0              0\r
+     *        0                 0                1              0\r
+     *        0                 1                0              0\r
+     *        0                 1                1              1\r
+     *        1                 0                0              1\r
+     *        1                 0                1              1\r
+     *        1                 1                0              0\r
+     *        1                 1                1              1\r
+     */\r
+    // The boolen codes is B8. Based on http://msdn.microsoft.com/en-us/library/aa932106.aspx, the ROP3 code is 0xB8074A\r
+\r
+    ::StretchDIBits(m_hDC, dest_left, dest_top, dest_width, dest_height,\r
+                    0, 0, width, height, pBitmap->GetBuffer(), (BITMAPINFO*)&bmi, DIB_RGB_COLORS, 0xB8074A);\r
+\r
+    SelectObject(m_hDC, hOld);\r
+    DeleteObject(hPattern);
+
     return TRUE;
 }
 BOOL CGdiDeviceDriver::GetClipBox(FX_RECT* pRect)