further development

git-svn-id: http://moon:8086/svn/software/trunk/projects/RBM@17 b431acfa-c32f-4a4a-93f1-934dc6c82436
This commit is contained in:
2014-10-04 19:09:35 +00:00
parent b403b9776a
commit f62f1283f8
127 changed files with 2350 additions and 1235 deletions
@@ -85,31 +85,13 @@ public:
newState.viewBoxW = vwh.x;
newState.viewBoxH = vwh.y;
int placementFlags = 0;
const int placementFlags = parsePlacementFlags (xml->getStringAttribute ("preserveAspectRatio").trim());
const String aspect (xml->getStringAttribute ("preserveAspectRatio"));
if (aspect.containsIgnoreCase ("none"))
{
placementFlags = RectanglePlacement::stretchToFit;
}
else
{
if (aspect.containsIgnoreCase ("slice")) placementFlags |= RectanglePlacement::fillDestination;
if (aspect.containsIgnoreCase ("xMin")) placementFlags |= RectanglePlacement::xLeft;
else if (aspect.containsIgnoreCase ("xMax")) placementFlags |= RectanglePlacement::xRight;
else placementFlags |= RectanglePlacement::xMid;
if (aspect.containsIgnoreCase ("yMin")) placementFlags |= RectanglePlacement::yTop;
else if (aspect.containsIgnoreCase ("yMax")) placementFlags |= RectanglePlacement::yBottom;
else placementFlags |= RectanglePlacement::yMid;
}
newState.transform = RectanglePlacement (placementFlags)
.getTransformToFit (Rectangle<float> (viewboxXY.x, viewboxXY.y, vwh.x, vwh.y),
Rectangle<float> (newState.width, newState.height))
.followedBy (newState.transform);
if (placementFlags != 0)
newState.transform = RectanglePlacement (placementFlags)
.getTransformToFit (Rectangle<float> (viewboxXY.x, viewboxXY.y, vwh.x, vwh.y),
Rectangle<float> (newState.width, newState.height))
.followedBy (newState.transform);
}
}
else
@@ -560,24 +542,12 @@ private:
path.applyTransform (transform);
dp->setPath (path);
Path::Iterator iter (path);
bool containsClosedSubPath = false;
while (iter.next())
{
if (iter.elementType == Path::Iterator::closePath)
{
containsClosedSubPath = true;
break;
}
}
dp->setFill (getPathFillType (path,
getStyleAttribute (xml, "fill"),
getStyleAttribute (xml, "fill-opacity"),
getStyleAttribute (xml, "opacity"),
containsClosedSubPath ? Colours::black
: Colours::transparentBlack));
pathContainsClosedSubPath (path) ? Colours::black
: Colours::transparentBlack));
const String strokeType (getStyleAttribute (xml, "stroke"));
@@ -594,6 +564,15 @@ private:
return dp;
}
static bool pathContainsClosedSubPath (const Path& path) noexcept
{
for (Path::Iterator iter (path); iter.next();)
if (iter.elementType == Path::Iterator::closePath)
return true;
return false;
}
struct SetGradientStopsOp
{
const SVGState* state;
@@ -796,44 +775,41 @@ private:
return parseColour (fill, i, defaultColour).withMultipliedAlpha (opacity);
}
static PathStrokeType::JointStyle getJointStyle (const String& join) noexcept
{
if (join.equalsIgnoreCase ("round")) return PathStrokeType::curved;
if (join.equalsIgnoreCase ("bevel")) return PathStrokeType::beveled;
return PathStrokeType::mitered;
}
static PathStrokeType::EndCapStyle getEndCapStyle (const String& cap) noexcept
{
if (cap.equalsIgnoreCase ("round")) return PathStrokeType::rounded;
if (cap.equalsIgnoreCase ("square")) return PathStrokeType::square;
return PathStrokeType::butt;
}
float getStrokeWidth (const String& strokeWidth) const noexcept
{
return transform.getScaleFactor() * getCoordLength (strokeWidth, viewBoxW);
}
PathStrokeType getStrokeFor (const XmlPath& xml) const
{
const String strokeWidth (getStyleAttribute (xml, "stroke-width"));
const String cap (getStyleAttribute (xml, "stroke-linecap"));
const String join (getStyleAttribute (xml, "stroke-linejoin"));
//const String mitreLimit (getStyleAttribute (xml, "stroke-miterlimit"));
//const String dashArray (getStyleAttribute (xml, "stroke-dasharray"));
//const String dashOffset (getStyleAttribute (xml, "stroke-dashoffset"));
PathStrokeType::JointStyle joinStyle = PathStrokeType::mitered;
PathStrokeType::EndCapStyle capStyle = PathStrokeType::butt;
if (join.equalsIgnoreCase ("round"))
joinStyle = PathStrokeType::curved;
else if (join.equalsIgnoreCase ("bevel"))
joinStyle = PathStrokeType::beveled;
if (cap.equalsIgnoreCase ("round"))
capStyle = PathStrokeType::rounded;
else if (cap.equalsIgnoreCase ("square"))
capStyle = PathStrokeType::square;
float ox = 0.0f, oy = 0.0f;
float x = getCoordLength (strokeWidth, viewBoxW), y = 0.0f;
transform.transformPoints (ox, oy, x, y);
return PathStrokeType (strokeWidth.isNotEmpty() ? juce_hypot (x - ox, y - oy) : 1.0f,
joinStyle, capStyle);
return PathStrokeType (getStrokeWidth (getStyleAttribute (xml, "stroke-width", "1")),
getJointStyle (getStyleAttribute (xml, "stroke-linejoin")),
getEndCapStyle (getStyleAttribute (xml, "stroke-linecap")));
}
//==============================================================================
Drawable* parseText (const XmlPath& xml)
{
Array <float> xCoords, yCoords, dxCoords, dyCoords;
Array<float> xCoords, yCoords, dxCoords, dyCoords;
getCoordList (xCoords, getInheritedAttribute (xml, "x"), true, true);
getCoordList (yCoords, getInheritedAttribute (xml, "y"), true, false);
getCoordList (xCoords, getInheritedAttribute (xml, "x"), true, true);
getCoordList (yCoords, getInheritedAttribute (xml, "y"), true, false);
getCoordList (dxCoords, getInheritedAttribute (xml, "dx"), true, true);
getCoordList (dyCoords, getInheritedAttribute (xml, "dy"), true, false);
@@ -898,7 +874,7 @@ private:
return false;
}
float getCoordLength (const String& s, const float sizeForProportions) const
float getCoordLength (const String& s, const float sizeForProportions) const noexcept
{
float n = s.getFloatValue();
const int len = s.length();
@@ -920,13 +896,12 @@ private:
return n;
}
float getCoordLength (const XmlPath& xml, const char* attName, const float sizeForProportions) const
float getCoordLength (const XmlPath& xml, const char* attName, const float sizeForProportions) const noexcept
{
return getCoordLength (xml->getStringAttribute (attName), sizeForProportions);
}
void getCoordList (Array <float>& coords, const String& list,
const bool allowUnits, const bool isX) const
void getCoordList (Array<float>& coords, const String& list, bool allowUnits, const bool isX) const
{
String::CharPointerType text (list.getCharPointer());
float value;
@@ -960,7 +935,7 @@ private:
return source;
}
String getStyleAttribute (const XmlPath& xml, const String& attributeName,
String getStyleAttribute (const XmlPath& xml, StringRef attributeName,
const String& defaultValue = String()) const
{
if (xml->hasAttribute (attributeName))
@@ -1000,7 +975,7 @@ private:
return defaultValue;
}
String getInheritedAttribute (const XmlPath& xml, const String& attributeName) const
String getInheritedAttribute (const XmlPath& xml, StringRef attributeName) const
{
if (xml->hasAttribute (attributeName))
return xml->getStringAttribute (attributeName);
@@ -1011,13 +986,30 @@ private:
return String();
}
static int parsePlacementFlags (const String& align) noexcept
{
if (align.isEmpty())
return 0;
if (align.containsIgnoreCase ("none"))
return RectanglePlacement::stretchToFit;
return (align.containsIgnoreCase ("slice") ? RectanglePlacement::fillDestination : 0)
| (align.containsIgnoreCase ("xMin") ? RectanglePlacement::xLeft
: (align.containsIgnoreCase ("xMax") ? RectanglePlacement::xRight
: RectanglePlacement::xMid))
| (align.containsIgnoreCase ("yMin") ? RectanglePlacement::yTop
: (align.containsIgnoreCase ("yMax") ? RectanglePlacement::yBottom
: RectanglePlacement::yMid));
}
//==============================================================================
static bool isIdentifierChar (const juce_wchar c)
{
return CharacterFunctions::isLetter (c) || c == '-';
}
static String getAttributeFromStyleList (const String& list, const String& attributeName, const String& defaultValue)
static String getAttributeFromStyleList (const String& list, StringRef attributeName, const String& defaultValue)
{
int i = 0;
@@ -1221,7 +1213,7 @@ private:
const bool largeArc, const bool sweep,
double& rx, double& ry,
double& centreX, double& centreY,
double& startAngle, double& deltaAngle)
double& startAngle, double& deltaAngle) noexcept
{
const double midX = (x1 - x2) * 0.5;
const double midY = (y1 - y2) * 0.5;