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

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

Issue 2057423002: Fix CGdiDeviceDriver::DrawLine(). (Closed) Base URL: https://pdfium.googlesource.com/pdfium@master
Patch Set: Do transform at the end Created 4 years, 6 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
« no previous file with comments | « no previous file | core/fxge/win32/win32_int.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "core/fxge/include/fx_ge.h" 7 #include "core/fxge/include/fx_ge.h"
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <memory> 10 #include <memory>
(...skipping 761 matching lines...) Expand 10 before | Expand all | Expand 10 after
772 void CGdiDeviceDriver::SaveState() { 772 void CGdiDeviceDriver::SaveState() {
773 SaveDC(m_hDC); 773 SaveDC(m_hDC);
774 } 774 }
775 775
776 void CGdiDeviceDriver::RestoreState(bool bKeepSaved) { 776 void CGdiDeviceDriver::RestoreState(bool bKeepSaved) {
777 RestoreDC(m_hDC, -1); 777 RestoreDC(m_hDC, -1);
778 if (bKeepSaved) 778 if (bKeepSaved)
779 SaveDC(m_hDC); 779 SaveDC(m_hDC);
780 } 780 }
781 781
782 void* CGdiDeviceDriver::GetClipRgn() {
783 HRGN hClipRgn = CreateRectRgn(0, 0, 1, 1);
784 if (::GetClipRgn(m_hDC, hClipRgn) == 0) {
785 DeleteObject(hClipRgn);
786 hClipRgn = nullptr;
787 }
788 return (void*)hClipRgn;
789 }
790
791 FX_BOOL CGdiDeviceDriver::GDI_SetDIBits(CFX_DIBitmap* pBitmap1, 782 FX_BOOL CGdiDeviceDriver::GDI_SetDIBits(CFX_DIBitmap* pBitmap1,
792 const FX_RECT* pSrcRect, 783 const FX_RECT* pSrcRect,
793 int left, 784 int left,
794 int top, 785 int top,
795 void* pIccTransform) { 786 void* pIccTransform) {
796 if (m_DeviceClass == FXDC_PRINTER) { 787 if (m_DeviceClass == FXDC_PRINTER) {
797 std::unique_ptr<CFX_DIBitmap> pBitmap(pBitmap1->FlipImage(FALSE, TRUE)); 788 std::unique_ptr<CFX_DIBitmap> pBitmap(pBitmap1->FlipImage(FALSE, TRUE));
798 if (!pBitmap) 789 if (!pBitmap)
799 return FALSE; 790 return FALSE;
800 791
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
939 SelectObject(m_hDC, hOld); 930 SelectObject(m_hDC, hOld);
940 DeleteObject(hPattern); 931 DeleteObject(hPattern);
941 932
942 return TRUE; 933 return TRUE;
943 } 934 }
944 935
945 FX_BOOL CGdiDeviceDriver::GetClipBox(FX_RECT* pRect) { 936 FX_BOOL CGdiDeviceDriver::GetClipBox(FX_RECT* pRect) {
946 return ::GetClipBox(m_hDC, (RECT*)pRect); 937 return ::GetClipBox(m_hDC, (RECT*)pRect);
947 } 938 }
948 939
949 FX_BOOL CGdiDeviceDriver::SetClipRgn(void* hRgn) {
950 ::SelectClipRgn(m_hDC, (HRGN)hRgn);
951 return TRUE;
952 }
953
954 void CGdiDeviceDriver::DrawLine(FX_FLOAT x1, 940 void CGdiDeviceDriver::DrawLine(FX_FLOAT x1,
955 FX_FLOAT y1, 941 FX_FLOAT y1,
956 FX_FLOAT x2, 942 FX_FLOAT x2,
957 FX_FLOAT y2) { 943 FX_FLOAT y2,
958 int flag1 = (x1 < 0) | ((x1 > m_Width) << 1) | ((y1 < 0) << 2) | 944 const CFX_Matrix* pMatrix) {
959 ((y1 > m_Height) << 3); 945 bool bStartOutOfBounds = x1 < 0 || x1 > m_Width || y1 < 0 || y1 > m_Height;
960 int flag2 = (x2 < 0) | ((x2 > m_Width) << 1) | ((y2 < 0) << 2) | 946 bool bEndOutOfBounds = x2 < 0 || x2 > m_Width || y2 < 0 || y2 > m_Height;
961 ((y2 > m_Height) << 3); 947 if (bStartOutOfBounds & bEndOutOfBounds)
962 if (flag1 & flag2) {
963 return; 948 return;
964 } 949
965 if (flag1 || flag2) { 950 if (bStartOutOfBounds || bEndOutOfBounds) {
966 FX_FLOAT x[2], y[2]; 951 FX_FLOAT x[2];
952 FX_FLOAT y[2];
967 int np; 953 int np;
968 #ifdef _SKIA_SUPPORT_ 954 #ifdef _SKIA_SUPPORT_
969 // TODO(caryclark) temporary replacement of antigrain in line function 955 // TODO(caryclark) temporary replacement of antigrain in line function
970 // to permit removing antigrain altogether 956 // to permit removing antigrain altogether
971 rect_base rect = {0.0f, 0.0f, (FX_FLOAT)(m_Width), (FX_FLOAT)(m_Height)}; 957 rect_base rect = {0.0f, 0.0f, (FX_FLOAT)(m_Width), (FX_FLOAT)(m_Height)};
972 np = clip_liang_barsky(x1, y1, x2, y2, rect, x, y); 958 np = clip_liang_barsky(x1, y1, x2, y2, rect, x, y);
973 #else 959 #else
974 agg::rect_base<FX_FLOAT> rect(0.0f, 0.0f, (FX_FLOAT)(m_Width), 960 agg::rect_base<FX_FLOAT> rect(0.0f, 0.0f, (FX_FLOAT)(m_Width),
975 (FX_FLOAT)(m_Height)); 961 (FX_FLOAT)(m_Height));
976 np = agg::clip_liang_barsky<FX_FLOAT>(x1, y1, x2, y2, rect, x, y); 962 np = agg::clip_liang_barsky<FX_FLOAT>(x1, y1, x2, y2, rect, x, y);
977 #endif 963 #endif
978 if (np == 0) { 964 if (np == 0)
979 return; 965 return;
980 } 966
981 if (np == 1) { 967 if (np == 1) {
982 x2 = x[0]; 968 x2 = x[0];
983 y2 = y[0]; 969 y2 = y[0];
984 } else { 970 } else {
971 ASSERT(np == 2);
985 x1 = x[0]; 972 x1 = x[0];
986 y1 = y[0]; 973 y1 = y[0];
987 x2 = x[np - 1]; 974 x2 = x[1];
988 y2 = y[np - 1]; 975 y2 = y[1];
989 } 976 }
990 } 977 }
978 if (pMatrix) {
979 pMatrix->Transform(x1, y1);
980 pMatrix->Transform(x2, y2);
981 }
991 MoveToEx(m_hDC, FXSYS_round(x1), FXSYS_round(y1), nullptr); 982 MoveToEx(m_hDC, FXSYS_round(x1), FXSYS_round(y1), nullptr);
992 LineTo(m_hDC, FXSYS_round(x2), FXSYS_round(y2)); 983 LineTo(m_hDC, FXSYS_round(x2), FXSYS_round(y2));
993 } 984 }
994 985
995 FX_BOOL CGdiDeviceDriver::DrawPath(const CFX_PathData* pPathData, 986 FX_BOOL CGdiDeviceDriver::DrawPath(const CFX_PathData* pPathData,
996 const CFX_Matrix* pMatrix, 987 const CFX_Matrix* pMatrix,
997 const CFX_GraphStateData* pGraphState, 988 const CFX_GraphStateData* pGraphState,
998 uint32_t fill_color, 989 uint32_t fill_color,
999 uint32_t stroke_color, 990 uint32_t stroke_color,
1000 int fill_mode, 991 int fill_mode,
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
1060 hPen = CreatePen(pGraphState, pMatrix, stroke_color); 1051 hPen = CreatePen(pGraphState, pMatrix, stroke_color);
1061 hPen = (HPEN)SelectObject(m_hDC, hPen); 1052 hPen = (HPEN)SelectObject(m_hDC, hPen);
1062 } 1053 }
1063 if (fill_mode && fill_alpha) { 1054 if (fill_mode && fill_alpha) {
1064 SetPolyFillMode(m_hDC, fill_mode); 1055 SetPolyFillMode(m_hDC, fill_mode);
1065 hBrush = CreateBrush(fill_color); 1056 hBrush = CreateBrush(fill_color);
1066 hBrush = (HBRUSH)SelectObject(m_hDC, hBrush); 1057 hBrush = (HBRUSH)SelectObject(m_hDC, hBrush);
1067 } 1058 }
1068 if (pPathData->GetPointCount() == 2 && pGraphState && 1059 if (pPathData->GetPointCount() == 2 && pGraphState &&
1069 pGraphState->m_DashCount) { 1060 pGraphState->m_DashCount) {
1070 FX_FLOAT x1 = pPathData->GetPointX(0), y1 = pPathData->GetPointY(0); 1061 FX_FLOAT x1 = pPathData->GetPointX(0);
1071 if (pMatrix) { 1062 FX_FLOAT y1 = pPathData->GetPointY(0);
1072 pMatrix->Transform(x1, y1); 1063 FX_FLOAT x2 = pPathData->GetPointX(1);
1073 } 1064 FX_FLOAT y2 = pPathData->GetPointY(1);
1074 FX_FLOAT x2 = pPathData->GetPointX(1), y2 = pPathData->GetPointY(1); 1065 DrawLine(x1, y1, x2, y2, pMatrix);
1075 if (pMatrix) {
1076 pMatrix->Transform(x2, y2);
1077 }
1078 DrawLine(x1, y1, x2, y2);
1079 } else { 1066 } else {
1080 SetPathToDC(m_hDC, pPathData, pMatrix); 1067 SetPathToDC(m_hDC, pPathData, pMatrix);
1081 if (pGraphState && stroke_alpha) { 1068 if (pGraphState && stroke_alpha) {
1082 if (fill_mode && fill_alpha) { 1069 if (fill_mode && fill_alpha) {
1083 if (old_fill_mode & FX_FILL_TEXT_MODE) { 1070 if (old_fill_mode & FX_FILL_TEXT_MODE) {
1084 StrokeAndFillPath(m_hDC); 1071 StrokeAndFillPath(m_hDC);
1085 } else { 1072 } else {
1086 FillPath(m_hDC); 1073 FillPath(m_hDC);
1087 SetPathToDC(m_hDC, pPathData, pMatrix); 1074 SetPathToDC(m_hDC, pPathData, pMatrix);
1088 StrokePath(m_hDC); 1075 StrokePath(m_hDC);
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
1181 } 1168 }
1182 HPEN hPen = CreatePen(PS_SOLID, 1, rgb); 1169 HPEN hPen = CreatePen(PS_SOLID, 1, rgb);
1183 hPen = (HPEN)SelectObject(m_hDC, hPen); 1170 hPen = (HPEN)SelectObject(m_hDC, hPen);
1184 MoveToEx(m_hDC, FXSYS_round(x1), FXSYS_round(y1), nullptr); 1171 MoveToEx(m_hDC, FXSYS_round(x1), FXSYS_round(y1), nullptr);
1185 LineTo(m_hDC, FXSYS_round(x2), FXSYS_round(y2)); 1172 LineTo(m_hDC, FXSYS_round(x2), FXSYS_round(y2));
1186 hPen = (HPEN)SelectObject(m_hDC, hPen); 1173 hPen = (HPEN)SelectObject(m_hDC, hPen);
1187 DeleteObject(hPen); 1174 DeleteObject(hPen);
1188 return TRUE; 1175 return TRUE;
1189 } 1176 }
1190 1177
1191 FX_BOOL CGdiDeviceDriver::DeleteDeviceRgn(void* pRgn) {
1192 DeleteObject((HGDIOBJ)pRgn);
1193 return TRUE;
1194 }
1195
1196 CGdiDisplayDriver::CGdiDisplayDriver(HDC hDC) 1178 CGdiDisplayDriver::CGdiDisplayDriver(HDC hDC)
1197 : CGdiDeviceDriver(hDC, FXDC_DISPLAY) { 1179 : CGdiDeviceDriver(hDC, FXDC_DISPLAY) {
1198 CWin32Platform* pPlatform = 1180 CWin32Platform* pPlatform =
1199 (CWin32Platform*)CFX_GEModule::Get()->GetPlatformData(); 1181 (CWin32Platform*)CFX_GEModule::Get()->GetPlatformData();
1200 if (pPlatform->m_GdiplusExt.IsAvailable()) { 1182 if (pPlatform->m_GdiplusExt.IsAvailable()) {
1201 m_RenderCaps |= FXRC_ALPHA_PATH | FXRC_ALPHA_IMAGE; 1183 m_RenderCaps |= FXRC_ALPHA_PATH | FXRC_ALPHA_IMAGE;
1202 } 1184 }
1203 } 1185 }
1204 1186
1205 FX_BOOL CGdiDisplayDriver::GetDIBits(CFX_DIBitmap* pBitmap, 1187 FX_BOOL CGdiDisplayDriver::GetDIBits(CFX_DIBitmap* pBitmap,
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
1460 if (m_hDC) { 1442 if (m_hDC) {
1461 SelectObject(m_hDC, m_hOldBitmap); 1443 SelectObject(m_hDC, m_hOldBitmap);
1462 DeleteDC(m_hDC); 1444 DeleteDC(m_hDC);
1463 } 1445 }
1464 if (m_hBitmap) 1446 if (m_hBitmap)
1465 DeleteObject(m_hBitmap); 1447 DeleteObject(m_hBitmap);
1466 delete GetBitmap(); 1448 delete GetBitmap();
1467 } 1449 }
1468 1450
1469 #endif // _FX_OS_ == _FX_WIN32_DESKTOP_ || _FX_OS_ == _FX_WIN64_ 1451 #endif // _FX_OS_ == _FX_WIN32_DESKTOP_ || _FX_OS_ == _FX_WIN64_
OLDNEW
« no previous file with comments | « no previous file | core/fxge/win32/win32_int.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698