------------------------------------------------------------------------------
| 1039 | |
| 1040 | //------------------------------------------------------------------------------ |
| 1041 | void vtkPDFContextDevice2D::DrawColoredPolygon( |
| 1042 | float* points, int numPoints, unsigned char* colors, int nc_comps) |
| 1043 | { |
| 1044 | assert(numPoints > 0); |
| 1045 | assert(points != nullptr); |
| 1046 | |
| 1047 | // Just use the standard draw method if there is a texture or colors are not |
| 1048 | // specified: |
| 1049 | if (this->Brush->GetTexture() != nullptr || nc_comps == 0) |
| 1050 | { |
| 1051 | this->DrawPolygon(points, numPoints); |
| 1052 | return; |
| 1053 | } |
| 1054 | |
| 1055 | // If all of the points have the same color, use a more compact method to |
| 1056 | // draw the poly: |
| 1057 | bool sameColor = true; |
| 1058 | for (int i = 1; i < numPoints && sameColor; ++i) |
| 1059 | { |
| 1060 | sameColor = std::equal(colors, colors + nc_comps, colors + (i * nc_comps)); |
| 1061 | } |
| 1062 | if (sameColor) |
| 1063 | { |
| 1064 | const vtkColor4ub oldBrush = this->Brush->GetColorObject(); |
| 1065 | switch (nc_comps) |
| 1066 | { |
| 1067 | case 4: |
| 1068 | this->Brush->SetOpacity(colors[3]); |
| 1069 | [[fallthrough]]; |
| 1070 | case 3: |
| 1071 | this->Brush->SetColor(colors); |
| 1072 | break; |
| 1073 | |
| 1074 | default: |
| 1075 | vtkWarningMacro("Unsupported number of color components: " << nc_comps); |
| 1076 | return; |
| 1077 | } |
| 1078 | |
| 1079 | this->DrawPolygon(points, numPoints); |
| 1080 | this->Brush->SetColor(oldBrush); |
| 1081 | return; |
| 1082 | } |
| 1083 | |
| 1084 | this->PushGraphicsState(); |
| 1085 | |
| 1086 | HPDF_REAL bbox[4]; |
| 1087 | GetPointBounds(points, numPoints, bbox); |
| 1088 | |
| 1089 | HPDF_Shading shading = HPDF_Shading_New(this->Impl->Document, |
| 1090 | HPDF_SHADING_FREE_FORM_TRIANGLE_MESH, HPDF_CS_DEVICE_RGB, bbox[0], bbox[1], bbox[2], bbox[3]); |
| 1091 | |
| 1092 | PolygonToShading(points, numPoints, colors, nc_comps, shading); |
| 1093 | |
| 1094 | HPDF_Page_SetShading(this->Impl->Page, shading); |
| 1095 | |
| 1096 | this->PopGraphicsState(); |
| 1097 | } |
| 1098 |
nothing calls this directly
no test coverage detected