------------------------------------------------------------------------------
| 937 | |
| 938 | //------------------------------------------------------------------------------ |
| 939 | void vtkOpenGLGL2PSHelperImpl::DrawPathPDF(vtkPath* path, double rasterPos[3], double windowPos[2], |
| 940 | unsigned char rgba[4], double scale[2], double rotateAngle, float strokeWidth, |
| 941 | const std::string& /*label*/) |
| 942 | { |
| 943 | vtkFloatArray* points = vtkArrayDownCast<vtkFloatArray>(path->GetPoints()->GetData()); |
| 944 | vtkIntArray* codes = path->GetCodes(); |
| 945 | |
| 946 | if (points->GetNumberOfTuples() != codes->GetNumberOfTuples()) |
| 947 | { |
| 948 | return; |
| 949 | } |
| 950 | |
| 951 | std::stringstream out; |
| 952 | out.setf(std::ios_base::left | std::ios_base::fixed); |
| 953 | constexpr int floatPrec = 2; |
| 954 | constexpr int floatWidth = 6; |
| 955 | out.precision(floatPrec); |
| 956 | out.width(floatWidth); |
| 957 | |
| 958 | float curveto[3][2]; |
| 959 | float curX = 0; |
| 960 | float curY = 0; |
| 961 | |
| 962 | float* pt = points->GetPointer(0); |
| 963 | int* code = codes->GetPointer(0); |
| 964 | |
| 965 | // These are only used in an assertion, ifdef silences warning on non-debug |
| 966 | // builds |
| 967 | #ifndef NDEBUG |
| 968 | float* ptBegin = pt; |
| 969 | int* codeBegin = code; |
| 970 | #endif |
| 971 | int* codeEnd = code + codes->GetNumberOfTuples(); |
| 972 | |
| 973 | // Push state. PDF doesn't let you reset the CTM, so the hope is that it is |
| 974 | // identity when this block starts... |
| 975 | out << "q" << endl; |
| 976 | // color |
| 977 | out << static_cast<float>(rgba[0]) / 255.f << " " << static_cast<float>(rgba[1]) / 255.f << " " |
| 978 | << static_cast<float>(rgba[2]) / 255.f << (strokeWidth > 1e-5 ? " RG" : " rg") << endl; |
| 979 | // opacity |
| 980 | out << static_cast<float>(rgba[3]) / 255.f << (strokeWidth > 1e-5 ? " CA" : " ca") << endl; |
| 981 | // translate |
| 982 | out << 1.f << " " << 0.f << " " << 0.f << " " << 1.f << " " << windowPos[0] << " " << windowPos[1] |
| 983 | << " cm" << endl; |
| 984 | // rotate |
| 985 | float sT = sin(vtkMath::RadiansFromDegrees(rotateAngle)); |
| 986 | float cT = cos(vtkMath::RadiansFromDegrees(rotateAngle)); |
| 987 | out << cT << " " << sT << " " << -sT << " " << cT << " " << 0.f << " " << 0.f << " cm" << endl; |
| 988 | // scale |
| 989 | if (scale) |
| 990 | { |
| 991 | out << scale[0] << " " << 0.f << " " << 0.f << " " << scale[1] << " " << 0.f << " " << 0.f |
| 992 | << " cm" << endl; |
| 993 | } |
| 994 | |
| 995 | while (code < codeEnd) |
| 996 | { |
no test coverage detected