Reputation: 8025
I have following SVG path:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="24" height="24" viewBox="0 0 24 24">
<path d="M6,2C4.89,2 4,2.89 4,4V20A2,2 0 0,0 6,22H18A2,2 0 0,0 20,20V8L14,2H6Z" />
</svg>
For easy of reading:
M 6, 2
C 4.89, 2 4,2.89 4,4
V 20
A 2,2 0 0,0 6,22
H 18
A 2,2 0 0,0 20,20
V 8L14,2
H 6
Z
I'm trying to convert this to a ID2D1PathGeometry
. Here is the code:
ID2D1PathGeometry *geo = NULL;
ID2D1GeometrySink *pSink = NULL;
d2DFactory->CreatePathGeometry(&geo);
geo->Open(&pSink);
pSink->SetFillMode(D2D1_FILL_MODE_WINDING);
pSink->BeginFigure({ 6.00f, 2.00f }, D2D1_FIGURE_BEGIN_FILLED);
pSink->AddBezier({ { 4.89f, 2.00f },{ 4.00f, 2.89f },{ 4.00f, 4.00f } });
pSink->AddLine({ 4.00f, 20.00f });
{
D2D1_ARC_SEGMENT arc;
arc.point.x = 6.00f;
arc.point.y = 22.00f;
arc.size.width = 2.00f;
arc.size.height = 2.00f;
arc.rotationAngle = 0.00f;
arc.sweepDirection = D2D1_SWEEP_DIRECTION_CLOCKWISE;
pSink->AddArc(&arc);
}
pSink->AddLine({ 18.00f, 22.00f });
{
D2D1_ARC_SEGMENT arc;
arc.point.x = 6.00f;
arc.point.y = 22.00f;
arc.size.width = 2.00f;
arc.size.height = 2.00f;
arc.rotationAngle = 0.00f;
arc.sweepDirection = D2D1_SWEEP_DIRECTION_CLOCKWISE;
pSink->AddArc(&arc);
}
pSink->AddLine({ 20.00f, 8.00f });
pSink->AddLine({ 14.00f, 2.00f });
pSink->AddLine({ 6.00f, 2.00f });
pSink->EndFigure(D2D1_FIGURE_END_CLOSED);
pSink->Close();
pSink->Release();
pRT->DrawGeometry(geo, brushBlack);
While I can convert lines and bezier successfully, I failed to convert Arcs.
For example, the code above will not draw anything, but if I comments following lines:
// pSink->AddArc(&arc);
It will draw a shape, but certainly will not exactly what is output by Chrome browser, because of lack some segments.
What is the error in my code that prevent me draw geometry with Arcs segment? How to fix it?
In w3.org document, an Arc segment have follwing value:
rx, ry, x_axis_rotation, large_arc_flag, sweep_flag, x, y
While I can set rx
, ry
, x_axis_rotation
, sweep_flag
, x
, y
, I don't see the member large_arc_flag
in D2D1_ARC_SEGMENT
struct. How can I adapt it to my code?
Upvotes: 0
Views: 578
Reputation: 37587
pSink->Close();
to determine what went wrong.D2D1_ARC_SEGMENT::arcSize
that you don't initialize at all causing UB and potentially causing code to fail to add arc since flag value most likely turns to be invalid.Upvotes: 1