MCPcopy Create free account
hub / github.com/Kitware/VTK / DrawPath

Method DrawPath

IO/ExportPDF/vtkPDFContextDevice2D.cxx:2146–2229  ·  view source on GitHub ↗

------------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

2144
2145//------------------------------------------------------------------------------
2146void vtkPDFContextDevice2D::DrawPath(vtkPath* path, float originX, float originY)
2147{
2148 // The text renderer always uses floats to generate paths, so we'll optimize
2149 // a bit here:
2150 vtkFloatArray* points = vtkArrayDownCast<vtkFloatArray>(path->GetPoints()->GetData());
2151 vtkIntArray* codes = path->GetCodes();
2152
2153 if (!points)
2154 {
2155 vtkErrorMacro("This method expects the path point precision to be floats.");
2156 return;
2157 }
2158
2159 vtkIdType numTuples = points->GetNumberOfTuples();
2160 if (numTuples != codes->GetNumberOfTuples() || codes->GetNumberOfComponents() != 1 ||
2161 points->GetNumberOfComponents() != 3)
2162 {
2163 vtkErrorMacro("Invalid path data.");
2164 return;
2165 }
2166
2167 if (numTuples == 0)
2168 { // Nothing to do.
2169 return;
2170 }
2171
2172 typedef vtkPath::ControlPointType CodeEnum;
2173 typedef vtkIntArray::ValueType CodeType;
2174 CodeType* code = codes->GetPointer(0);
2175 CodeType* codeEnd = code + numTuples;
2176
2177 typedef vtkFloatArray::ValueType PointType;
2178 PointType* point = points->GetPointer(0);
2179
2180 // These are only used in an assertion, ifdef silences warning on non-debug
2181 // builds
2182#ifndef NDEBUG
2183 PointType* pointBegin = point;
2184 CodeType* codeBegin = code;
2185#endif
2186
2187 HPDF_Page page = this->Impl->Page;
2188
2189 // Translate to origin:
2190 HPDF_Page_Concat(page, 1.f, 0.f, 0.f, 1.f, originX, originY);
2191
2192 while (code < codeEnd)
2193 {
2194 assert("Sanity check" && (code - codeBegin) * 3 == point - pointBegin);
2195
2196 switch (static_cast<CodeEnum>(*code))
2197 {
2198 case vtkPath::MOVE_TO:
2199 HPDF_Page_MoveTo(page, point[0], point[1]);
2200 point += 3;
2201 ++code;
2202 break;
2203

Callers 1

DrawStringMethod · 0.95

Calls 12

HPDF_Page_ConcatFunction · 0.85
HPDF_Page_MoveToFunction · 0.85
HPDF_Page_LineToFunction · 0.85
HPDF_Page_CurveTo3Function · 0.85
HPDF_Page_CurveToFunction · 0.85
GetCodesMethod · 0.80
assertFunction · 0.50
GetDataMethod · 0.45
GetPointsMethod · 0.45
GetNumberOfTuplesMethod · 0.45
GetNumberOfComponentsMethod · 0.45
GetPointerMethod · 0.45

Tested by

no test coverage detected