From dc83bf01e18beb9ef08876a4e430a67d7ee40e86 Mon Sep 17 00:00:00 2001 From: Julian Storer Date: Tue, 10 Nov 2009 00:31:53 +0000 Subject: [PATCH] oops - the last check-in broke some path rendering code.. this fixes it. --- juce_amalgamated.cpp | 46 +++++++++++++++---- juce_amalgamated.h | 19 ++------ src/gui/graphics/contexts/juce_EdgeTable.cpp | 40 +++++++++++++--- src/gui/graphics/contexts/juce_EdgeTable.h | 19 ++------ .../mac/juce_mac_CoreGraphicsContext.mm | 6 ++- 5 files changed, 84 insertions(+), 46 deletions(-) diff --git a/juce_amalgamated.cpp b/juce_amalgamated.cpp index bd76240b4d..5803e8a183 100644 --- a/juce_amalgamated.cpp +++ b/juce_amalgamated.cpp @@ -78829,8 +78829,7 @@ EdgeTable::EdgeTable (const int top_, const int height_) throw() : top (top_), height (height_), maxEdgesPerLine (juce_edgeTableDefaultEdgesPerLine), - lineStrideElements ((juce_edgeTableDefaultEdgesPerLine << 1) + 1), - nonZeroWinding (true) + lineStrideElements ((juce_edgeTableDefaultEdgesPerLine << 1) + 1) { table = (int*) juce_calloc (height * lineStrideElements * sizeof (int)); } @@ -78849,7 +78848,6 @@ const EdgeTable& EdgeTable::operator= (const EdgeTable& other) throw() height = other.height; maxEdgesPerLine = other.maxEdgesPerLine; lineStrideElements = other.lineStrideElements; - nonZeroWinding = other.nonZeroWinding; const int tableSize = height * lineStrideElements * sizeof (int); table = (int*) juce_malloc (tableSize); @@ -78938,10 +78936,8 @@ void EdgeTable::addEdgePoint (const int x, const int y, const int winding) throw lineStart[0]++; } -void EdgeTable::addPath (const Path& path, - const AffineTransform& transform) throw() +void EdgeTable::addPath (const Path& path, const AffineTransform& transform) throw() { - nonZeroWinding = path.isUsingNonZeroWinding(); const int bottomLimit = height << 8; PathFlatteningIterator iter (path, transform); @@ -78953,6 +78949,7 @@ void EdgeTable::addPath (const Path& path, if (y1 != y2) { + const int oldY1 = y1; const double x1 = 256.0 * iter.x1; const double x2 = 256.0 * iter.x2; const double multiplier = (x2 - x1) / (y2 - y1); @@ -78970,7 +78967,6 @@ void EdgeTable::addPath (const Path& path, if (y2 > bottomLimit) y2 = bottomLimit; - const int oldY1 = y1; const int stepSize = jlimit (1, 256, 256 / (1 + abs ((int) multiplier))); while (y1 < y2) @@ -78984,6 +78980,36 @@ void EdgeTable::addPath (const Path& path, } } } + + if (! path.isUsingNonZeroWinding()) + { + int* lineStart = table; + + for (int i = height; --i >= 0;) + { + int* line = lineStart; + lineStart += lineStrideElements; + int num = *line; + int level = 0; + int lastCorrected = 0; + + while (--num >= 0) + { + line += 2; + level += *line; + int corrected = abs (level); + if (corrected >> 8) + { + corrected &= 511; + if (corrected >> 8) + corrected = 511 - corrected; + } + + *line = corrected - lastCorrected; + lastCorrected = corrected; + } + } + } } /*void EdgeTable::clipToRectangle (const Rectangle& r) throw() @@ -266085,7 +266111,11 @@ public: flip(); applyTransform (transform); createPath (path); - CGContextFillPath (context); + + if (path.isUsingNonZeroWinding()) + CGContextFillPath (context); + else + CGContextEOFillPath (context); } else { diff --git a/juce_amalgamated.h b/juce_amalgamated.h index e70c9bd351..845d46f8a6 100644 --- a/juce_amalgamated.h +++ b/juce_amalgamated.h @@ -17092,10 +17092,10 @@ public: A table is created with a fixed vertical size, and only sections of paths which lie within their range will be added to the table. - @param topY the lowest y co-ordinate that the table can contain - @param height the number of horizontal lines it can contain + @param y the lowest y co-ordinate that the table can contain + @param height the number of horizontal lines it contains */ - EdgeTable (const int topY, const int height) throw(); + EdgeTable (const int y, const int height) throw(); /** Creates a copy of another edge table. */ EdgeTable (const EdgeTable& other) throw(); @@ -17179,18 +17179,7 @@ public: { int correctedLevel = abs (level); if (correctedLevel >> 8) - { - if (nonZeroWinding) - { - correctedLevel = 0xff; - } - else - { - correctedLevel &= 511; - if (correctedLevel >> 8) - correctedLevel = 511 - correctedLevel; - } - } + correctedLevel = 0xff; const int endX = subPixelXOffset + *++line; jassert (endX >= x); diff --git a/src/gui/graphics/contexts/juce_EdgeTable.cpp b/src/gui/graphics/contexts/juce_EdgeTable.cpp index 021fe16aac..188c78bfb2 100644 --- a/src/gui/graphics/contexts/juce_EdgeTable.cpp +++ b/src/gui/graphics/contexts/juce_EdgeTable.cpp @@ -37,8 +37,7 @@ EdgeTable::EdgeTable (const int top_, const int height_) throw() : top (top_), height (height_), maxEdgesPerLine (juce_edgeTableDefaultEdgesPerLine), - lineStrideElements ((juce_edgeTableDefaultEdgesPerLine << 1) + 1), - nonZeroWinding (true) + lineStrideElements ((juce_edgeTableDefaultEdgesPerLine << 1) + 1) { table = (int*) juce_calloc (height * lineStrideElements * sizeof (int)); } @@ -57,7 +56,6 @@ const EdgeTable& EdgeTable::operator= (const EdgeTable& other) throw() height = other.height; maxEdgesPerLine = other.maxEdgesPerLine; lineStrideElements = other.lineStrideElements; - nonZeroWinding = other.nonZeroWinding; const int tableSize = height * lineStrideElements * sizeof (int); table = (int*) juce_malloc (tableSize); @@ -149,10 +147,8 @@ void EdgeTable::addEdgePoint (const int x, const int y, const int winding) throw } //============================================================================== -void EdgeTable::addPath (const Path& path, - const AffineTransform& transform) throw() +void EdgeTable::addPath (const Path& path, const AffineTransform& transform) throw() { - nonZeroWinding = path.isUsingNonZeroWinding(); const int bottomLimit = height << 8; PathFlatteningIterator iter (path, transform); @@ -164,6 +160,7 @@ void EdgeTable::addPath (const Path& path, if (y1 != y2) { + const int oldY1 = y1; const double x1 = 256.0 * iter.x1; const double x2 = 256.0 * iter.x2; const double multiplier = (x2 - x1) / (y2 - y1); @@ -181,7 +178,6 @@ void EdgeTable::addPath (const Path& path, if (y2 > bottomLimit) y2 = bottomLimit; - const int oldY1 = y1; const int stepSize = jlimit (1, 256, 256 / (1 + abs ((int) multiplier))); while (y1 < y2) @@ -195,6 +191,36 @@ void EdgeTable::addPath (const Path& path, } } } + + if (! path.isUsingNonZeroWinding()) + { + int* lineStart = table; + + for (int i = height; --i >= 0;) + { + int* line = lineStart; + lineStart += lineStrideElements; + int num = *line; + int level = 0; + int lastCorrected = 0; + + while (--num >= 0) + { + line += 2; + level += *line; + int corrected = abs (level); + if (corrected >> 8) + { + corrected &= 511; + if (corrected >> 8) + corrected = 511 - corrected; + } + + *line = corrected - lastCorrected; + lastCorrected = corrected; + } + } + } } /*void EdgeTable::clipToRectangle (const Rectangle& r) throw() diff --git a/src/gui/graphics/contexts/juce_EdgeTable.h b/src/gui/graphics/contexts/juce_EdgeTable.h index e643d6d025..98885f49d6 100644 --- a/src/gui/graphics/contexts/juce_EdgeTable.h +++ b/src/gui/graphics/contexts/juce_EdgeTable.h @@ -47,10 +47,10 @@ public: A table is created with a fixed vertical size, and only sections of paths which lie within their range will be added to the table. - @param topY the lowest y co-ordinate that the table can contain - @param height the number of horizontal lines it can contain + @param y the lowest y co-ordinate that the table can contain + @param height the number of horizontal lines it contains */ - EdgeTable (const int topY, const int height) throw(); + EdgeTable (const int y, const int height) throw(); /** Creates a copy of another edge table. */ EdgeTable (const EdgeTable& other) throw(); @@ -137,18 +137,7 @@ public: { int correctedLevel = abs (level); if (correctedLevel >> 8) - { - if (nonZeroWinding) - { - correctedLevel = 0xff; - } - else - { - correctedLevel &= 511; - if (correctedLevel >> 8) - correctedLevel = 511 - correctedLevel; - } - } + correctedLevel = 0xff; const int endX = subPixelXOffset + *++line; jassert (endX >= x); diff --git a/src/native/mac/juce_mac_CoreGraphicsContext.mm b/src/native/mac/juce_mac_CoreGraphicsContext.mm index 411d5650db..e4fbc86ce6 100644 --- a/src/native/mac/juce_mac_CoreGraphicsContext.mm +++ b/src/native/mac/juce_mac_CoreGraphicsContext.mm @@ -196,7 +196,11 @@ public: flip(); applyTransform (transform); createPath (path); - CGContextFillPath (context); + + if (path.isUsingNonZeroWinding()) + CGContextFillPath (context); + else + CGContextEOFillPath (context); } else {