// SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen // SPDX-License-Identifier: BSD-3-Clause #include "vtkBrush.h" #include "vtkContext2D.h" #include "vtkContextItem.h" #include "vtkContextScene.h" #include "vtkContextView.h" #include "vtkObjectFactory.h" #include "vtkPen.h" #include "vtkRenderWindow.h" #include "vtkRenderWindowInteractor.h" #include "vtkSmartPointer.h" #include "vtkTestUtilities.h" #include "vtkTextProperty.h" #include "vtkRegressionTestImage.h" #include #include //------------------------------------------------------------------------------ class ContextUnicode : public vtkContextItem { public: static ContextUnicode* New(); vtkTypeMacro(ContextUnicode, vtkContextItem); // Paint event for the chart, called whenever the chart needs to be drawn bool Paint(vtkContext2D* painter) override; std::string FontFile; }; //------------------------------------------------------------------------------ int TestContextUnicode(int argc, char* argv[]) { if (argc < 2) { std::cout << "Missing font filename." << std::endl; return EXIT_FAILURE; } std::string fontFile(argv[1]); // Set up a 2D context view, context test object and add it to the scene vtkSmartPointer view = vtkSmartPointer::New(); view->GetRenderWindow()->SetSize(200, 100); vtkSmartPointer test = vtkSmartPointer::New(); test->FontFile = fontFile; view->GetScene()->AddItem(test); view->GetRenderWindow()->SetMultiSamples(0); view->GetRenderWindow()->Render(); int retVal = vtkRegressionTestImage(view->GetRenderWindow()); if (retVal == vtkRegressionTester::DO_INTERACTOR) { view->GetInteractor()->Initialize(); view->GetInteractor()->Start(); } return !retVal; } // Make our new derived class to draw a diagram vtkStandardNewMacro(ContextUnicode); // This function aims to test the primitives provided by the 2D API. bool ContextUnicode::Paint(vtkContext2D* painter) { // Test the string drawing functionality of the context painter->GetTextProp()->SetVerticalJustificationToCentered(); painter->GetTextProp()->SetJustificationToCentered(); painter->GetTextProp()->SetColor(0.0, 0.0, 0.0); painter->GetTextProp()->SetFontSize(24); painter->GetTextProp()->SetFontFamily(VTK_FONT_FILE); painter->GetTextProp()->SetFontFile(this->FontFile.c_str()); painter->DrawString(70, 20, "Angstrom"); painter->DrawString(150, 20, "\xe2\x84\xab"); painter->DrawString(100, 80, "a\xce\xb1"); painter->DrawString(100, 50, "\xce\xb1\xce\xb2\xce\xb3"); return true; }