none
Why does gdi + draw curves incorrectly? RRS feed

  • Question

  • Hi all. I want to write a parser for svg files and render vector graphics through gdi+, but when I try to inject data from the svg file into the code, I get an incorrectly rendered bezier curve. The edges of the curve are uneven.
    I tried changing the miterlimit values of the SetMiterLimit function of the Pen class, and tried other functions, but nothing changes. For comparison, I'm attaching screenshots: how the curve looks in browsers and in gdi + with and without anti-aliasing;

    <?xml version="1.0" encoding="utf-8"?>
    <svg version="1.2" baseProfile="tiny" id="Слой_1"
    	 xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 510 512"
    	 overflow="visible" xml:space="preserve">
    <path fill="none" stroke="#000000" stroke-width="32" stroke-miterlimit="10" d="M168,37c0,35.4,39.4,64,88,64"/>
    </svg>
    Rect paintRect(0, TbHeight, mw->getClRect().right, mw->getClRect().bottom);
    Bitmap bmp(paintRect.Width, paintRect.Height - TbHeight);
    Graphics* graphics = new Graphics(&bmp);
    graphics->SetTextRenderingHint(TextRenderingHintAntiAliasGridFit);
    graphics->SetSmoothingMode(SmoothingModeAntiAlias);
    float _x = 168;
    float _y = 37;
    PointF p[] =
    {
        PointF(_x, _y),
        PointF(_x + 0, _y + 35.4),
        PointF(_x + 39.4, _y + 64),
        PointF(_x + 88, _y + 64)
    };
    pen.SetWidth(32.f);
    graphics->DrawBeziers(&pen, p, 4);

    This is svg in browsers: https://disk.yandex.ru/i/yUvUkmGZ6ZYxMQ

    This is gdi+ without anti-aliasing https://disk.yandex.ru/i/fNvwWOHlUP2gEA

    This is gdi+ with anti-aliasing https://disk.yandex.ru/i/NLptn-0j8zk-qA

    What could be the problem?

    Saturday, September 17, 2022 10:04 AM