Dash Stroke showing some Lines across


#1

While creating Dashed Stroke from a glyph Path , some lines crossing the glyphs…

Font font(T("Arial"), 320.0, Font::plain);

GlyphArrangement arr;
arr.addLineOfText(font, T("A"), 0, 0);

juce::PositionedGlyph glyph(arr.getGlyph(0));

float x = 0, y = 0, width = 0, height = 0;
juce::Path glyphFillPath;
glyph.createPath(glyphFillPath);
glyphFillPath.getBounds(x, y, width, height);

Image* pImage = new Image(Image::ARGB, width + 128, height + 128, true);
Graphics g(*pImage);
g.fillAll(Colours::red);
g.setColour(Colours::black);
int deltaX = (pImage->getWidth() - width)/2 - x;
int deltaY = (pImage->getHeight() - height)/2 - y;
g.fillPath(glyphFillPath, AffineTransform::translation(deltaX, deltaY));

float *dash = new float[2];
dash[0] = 2.0;
dash[1] = 2.0;
PathStrokeType dashStroke(5.0);
dashStroke.createDashedStroke(anotherPath, anotherPath, dash, 2);
g.setColour(Colours::green);
g.strokePath(anotherPath, PathStrokeType(5.0), AffineTransform::translation(deltaX, deltaY));

PNGImageFormat format;
FileOutputStream fos(File::createTempFile(T("Sample.png")));
format.writeImageToStream(*pImage, fos);

Check the output Image in TempDirectory…
Hope this can be fixed…


#2

Ah, just a minor bugette - it just needs a one-line fix in PathStrokeType::createDashedStroke(), around line 610:

[code] lineEndPos += lineLen;

        first = it.closesSubPath;
    }

    const float alpha = (pos - (lineEndPos - lineLen)) / lineLen;

[/code]


#3

This is working fine…

In the same code, if i give the dash lengths as {1, 2}… No strokes are drawn…Am i doing anything wrong…


#4

[quote=“noorul”]This is working fine…

In the same code, if i give the dash lengths as {1, 2}… No strokes are drawn…Am i doing anything wrong…

[/quote]
If i am not using juce properly, also give some tips to use it efficiently…

[quote][/quote]


#5

You’ve probably just got the scale of the dash lengths wrong - check that the lengths make sense in relation to the size of what you’re drawing…