I am trying to use the GraphicsPath::AddString()
method of GDI+ in my libcinder project.
The idea is to create a path of a letter/glyph via the mentioned method and later pass that to gl::draw()
and box2d's b2FixtureDef
. The goal is create falling letters that show an exact collision behaviour.
However the following example taken from learn.microsoft.com throws several errors at me.
#include "cinder/app/App.h"
#include "cinder/app/RendererGl.h"
#include "cinder/gl/gl.h"
#include "cinder/Rand.h"
#include <Box2D/Box2D.h>
#include <gdiplus.h>
#pragma comment (lib, "gdiplus.lib")
using namespace Gdiplus;
using namespace ci;
using namespace ci::app;
using namespace std;
// ...
void MyApp::draw()
{
FontFamily fontFamily(L"Times New Roman");
GraphicsPath path;
// const WCHAR
// Status AddString(
// IN const WCHAR *string,
// IN INT length,
// IN const FontFamily *family,
// IN INT style,
// IN REAL emSize, // World units
// IN const PointF &origin,
// IN const StringFormat *format
//)
path.AddString(
L"Hello World",
-1, // NULL-terminated string
&FontFamily("Arial"),
FontStyleRegular,
48,
PointF(50.0f, 50.0f),
NULL);
}
There are several issues with my code that just cant get fixed... My project's target platform version is 8.1 and the platform toolset is Visual Studio 2015 (v140)
. The headers are there and can be browsed to when hitting F12.
FontFamily fontFamily(L"Times New Roman");
"Cannot initialize local variable 'fontFamily' of type 'FontFamily' with lvalue of type 'wchar_t const[16]'
GraphicsPath path;
"No default constructor exists for class "GraphicsPath""
path.AddString(...)
"class 'GraphicsPath' has no member 'AddString'"
Any help is very appreciated. I have spent hours with this issues with zero progress.
After searching high and low I figured it out. I was missing a couple of includes. But to be honest, I still don't really understand, why the compiler complained with that specific message...
The following does compile for me and produces the path coordinates for the letter "A".
// other includes
#include <windows.h>
#include <ObjIdl.h>
#include <minmax.h>
#include <gdiplus.h>
using namespace Gdiplus;
using namespace ci;
using namespace ci::app;
#pragma comment (lib, "Gdiplus.lib")
// ...
void MyApp::setup()
{
// ...
GraphicsPath p(FillModeAlternate);
FontFamily fontFamily(L"Arial");
if (p.AddString(L"A", -1, &fontFamily, FontStyleRegular, 48, PointF(0.0f, 0.0f), NULL) != Status::Ok)
{
std::cout << "Error while adding points" << std::endl;
}
PointF points[64];
if (p.GetPathPoints(points, sizeof(points)) != Status::Ok)
{
std::cout << "Error while getting points" << std::endl;
}
}