Add offscreen text rendering.

This commit is contained in:
jmsgrogan 2023-01-12 10:58:43 +00:00
parent c63138c455
commit 076e32b1d6
17 changed files with 156 additions and 101 deletions

View file

@ -1,38 +1,19 @@
#include "TestCase.h"
#include "TestCaseRunner.h"
#include "TestUiApplication.h"
#include "TestFramework.h"
#include "TestUtils.h"
#include "DrawingSurface.h"
#include "DrawingContext.h"
#include "AbstractPainter.h"
#include "Image.h"
#include "PngWriter.h"
#include "TestRenderUtils.h"
#include "RectangleNode.h"
#include "Scene.h"
TEST_CASE(TestD2dOffScreenRendering, "graphics")
{
auto surface = std::make_unique<DrawingSurface>();
surface->setSize(800, 800);
auto drawing_context = std::make_unique<DrawingContext>(surface.get());
TestRenderer renderer(800, 800);
auto rect = std::make_unique<RectangleNode>(Point(10, 10), 200.0, 200.0);
auto scene = surface->getScene();
auto scene = renderer.getScene();
//scene->setBackgroundColor(Color(100, 100, 0));
scene->addNode(rect.get());
drawing_context->paint();
auto image = surface->getImage();
PngWriter writer;
writer.setPath(TestUtils::getTestOutputDir(__FILE__) / "out.png");
writer.write(image);
renderer.write(TestUtils::getTestOutputDir(__FILE__) / "out.png");
};

View file

@ -1,22 +1,29 @@
#include "TestFramework.h"
#include "TestUtils.h"
#include "TestRenderUtils.h"
#include "StringUtils.h"
#include "File.h"
#include <iostream>
#include "FontItem.h"
#include "TextNode.h"
#include "LatexSymbols.h"
TEST_CASE(TestLatexConverter, "publishing")
{
std::wstring out = L"\u03A8";
std::wcout << out << std::endl;
FontItem font("Cambria Math", 14);
auto psi = LatexSymbolLookup::getSymbolUtf8("psi");
auto alpha = LatexSymbolLookup::getSymbolUtf8("alpha");
auto beta = LatexSymbolLookup::getSymbolUtf8("beta");
std::string out_c = StringUtils::convert(out);
auto content = *psi + " " + *alpha + " " + *beta + " ";
File file(TestUtils::getTestOutputDir(__FILE__) / "utf8_render.dat");
file.writeText(out_c);
TestRenderer renderer(800, 800);
//std::cout << out_c << std::endl;
auto text = std::make_unique<TextNode>(content, Point(10, 10));
text->setFont(font);
renderer.getScene()->addNode(text.get());
renderer.write(TestUtils::getTestOutputDir(__FILE__) / "out.png");
};

View file

@ -6,6 +6,7 @@ add_library(test_utils STATIC
TestCaseRunner.cpp
TestUiApplication.h
TestUiApplication.cpp
TestRenderUtils.h
)
target_include_directories(test_utils PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR})

View file

@ -0,0 +1,40 @@
#pragma once
#include "DrawingSurface.h"
#include "DrawingContext.h"
#include "AbstractPainter.h"
#include "Image.h"
#include "PngWriter.h"
#include "Scene.h"
class TestRenderer
{
public:
TestRenderer(unsigned width = 1000, unsigned height = 1000)
{
mSurface = std::make_unique<DrawingSurface>();
mSurface->setSize(width, height);
mDrawingContext = std::make_unique<DrawingContext>(mSurface.get());
}
Scene* getScene() const
{
return mSurface->getScene();
}
void write(const Path& path)
{
mDrawingContext->paint();
auto image = mSurface->getImage();
PngWriter writer;
writer.setPath(path);
writer.write(image);
}
private:
std::unique_ptr<DrawingSurface> mSurface;
std::unique_ptr<DrawingContext> mDrawingContext;
};