stuff-from-scratch/test/fonts/TestDirectWriteFontEngine.cpp

50 lines
1.2 KiB
C++
Raw Normal View History

#include "TestFramework.h"
#include "TestUtils.h"
#include "DirectWriteHelpers.h"
#include "DirectWriteFontEngine.h"
#include "FileLogger.h"
#include "SvgDocument.h"
#include "SvgWriter.h"
#include "SvgShapeElements.h"
#include "File.h"
#include "FontItem.h"
TEST_CASE(TestDirectWriteFontEngine, "fonts")
{
DirectWriteFontEngine font_engine;
font_engine.initialize();
auto glyph_run_outlines = font_engine.getGlyphRunOutlines({ 66 });
auto path = glyph_run_outlines->toPostScriptPath();
auto doc = std::make_unique<SvgDocument>();
auto element = std::make_unique<SvgPath>();
element->setPath(path);
element->setFillRule("evenodd");
doc->getRoot()->addChild(std::move(element));
doc->setViewBox(-20.0, -20.0, 40.0, 40.0);
auto writer = std::make_unique<SvgWriter>();
auto doc_string = writer->toString(doc.get());
File file(TestUtils::getTestOutputDir(__FILE__) / "out.svg");
file.writeText(doc_string);
}
TEST_CASE(TestDirectWriteFontEngine_GlyphMetrics, "fonts")
{
DirectWriteFontEngine font_engine;
font_engine.initialize();
FontItem font("Verdana", 16);
const auto advance = font_engine.getHorizontalAdvance(font, "abc");
MLOG_INFO("Advance is: " << advance);
REQUIRE(advance != 0.0);
}