-1

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.

  1. FontFamily fontFamily(L"Times New Roman");

"Cannot initialize local variable 'fontFamily' of type 'FontFamily' with lvalue of type 'wchar_t const[16]'

  1. GraphicsPath path;

"No default constructor exists for class "GraphicsPath""

  1. path.AddString(...)

"class 'GraphicsPath' has no member 'AddString'"

Any help is very appreciated. I have spent hours with this issues with zero progress.

Matthias Güntert
  • 4,013
  • 6
  • 41
  • 89
  • 1
    Always start at the top of the error list. You need `#include ` before the #include for gdiplus.h – Hans Passant Dec 27 '19 at 22:07
  • Thx for replying. I have removed everything GDI-relevant but `FontFamily fontFamily(L"Times New Roman");` and added `#include `. But still now luck. Strangley VS throws several errors at me coming from `gdiplusbitmap.h` which is not included, nor part of my solution/project. Anything wrong with my project setup? Have SDK 8.1 and 10.x installed – Matthias Güntert Dec 27 '19 at 22:14
  • It is included by gdiplus.h. You won't get anywhere until the gdiplus*.h headers stop producing error messages. Re-iterating, always start at the top of the error list, be very explicit about the error you see. "throws several errors" doesn't help us help you. – Hans Passant Dec 27 '19 at 22:25
  • You are using multiple `namespace`'s, maybe it's getting mixed up. Use `GdiPlus::FontFamily` instead. – Barmak Shemirani Dec 29 '19 at 00:12
  • Why the down-vote? Please comment so I can improve my question – Matthias Güntert Dec 29 '19 at 16:30

1 Answers1

0

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;
  }
}
Matthias Güntert
  • 4,013
  • 6
  • 41
  • 89