Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FileModeWinding and DrawPath cause odd spikes to appear

Tags:

gdi+

I'm using gdiplus to "stroke" a textout. In certain circumstances, we see a "spike" appearing on the top or bottom of the graphic, and I'm not really sure why. We can minimize this by adjusting stroke width and font size, but thats not a good solution. I'm hoping someone can explain the problem to me.

Spikey Bug

And the code sample generating this 4, its outline, and the spike (unintentional)

GraphicsPath path(FillModeWinding);   

      path.AddString(text,wcslen(text),&fontFamily,StateInfo.TheFont.TheWeight,(REAL)minSize,PointF((REAL)ptStart.x, (REAL)ptStart.y),&sf);
      // Draw the outline first
      if (StateInfo.StrokeWidth > 0) {
        Gdiplus::Color strokecolor(GetRValue(StateInfo.StrokeColor), GetGValue(StateInfo.StrokeColor), GetBValue(StateInfo.StrokeColor));
        Pen pen(strokecolor,(REAL)StateInfo.StrokeWidth);      
        graphics.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias);
        graphics.SetPixelOffsetMode(Gdiplus::PixelOffsetModeHighQuality);
        graphics.DrawPath(&pen, &path);
        }
      // Draw the text by filling the path        
      graphics.FillPath(&solidBrush, &path);
like image 211
reuscam Avatar asked Sep 21 '10 17:09

reuscam


1 Answers

Use Pen::SetLineJoin on the Pen you're using to draw the outline, and use something other than LineJoinMiter.

like image 128
user446034 Avatar answered Jan 03 '23 00:01

user446034