Skip to content

Commit

Permalink
added FIXME for #6
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul Lammertsma committed Aug 12, 2015
1 parent fc67e72 commit c41e453
Showing 1 changed file with 26 additions and 8 deletions.
34 changes: 26 additions & 8 deletions library/src/main/java/com/pixplicity/sharp/Sharp.java
Original file line number Diff line number Diff line change
Expand Up @@ -1144,7 +1144,8 @@ public static class SvgHandler extends DefaultHandler {
private final Stack<SvgText> mTextStack = new Stack<>();

private HashMap<String, String> mDefs = new HashMap<>();
private boolean mDefsReading = false;
private boolean mReadingDefs = false;
private Stack<String> mReadIgnoreStack = new Stack<>();

private SvgHandler(Sharp sharp, Picture picture) {
mSharp = sharp;
Expand Down Expand Up @@ -1511,7 +1512,6 @@ private void doLimits2(float x, float y) {
if (y > mLimits.bottom) {
mLimits.bottom = y;
}
Log.d(TAG, "new limits: " + mLimits);
}

final private RectF limitRect = new RectF();
Expand Down Expand Up @@ -1550,8 +1550,12 @@ private void popTransform() {

@Override
public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException {
if (!mReadIgnoreStack.empty()) {
// Ignore
return;
}

String id = getStringAttr("id", atts);
Log.d(TAG, "element id=" + id);

// Reset paint opacity
mStrokePaint.setAlpha(255);
Expand Down Expand Up @@ -1613,8 +1617,7 @@ public void startElement(String namespaceURI, String localName, String qName, At
(int) Math.ceil(mBounds.height()));
//Log.d(TAG, "canvas size: " + mCanvas.getWidth() + "x" + mCanvas.getHeight());
} else if (localName.equals("defs")) {
// Ignore
mDefsReading = true;
mReadingDefs = true;
} else if (localName.equals("linearGradient")) {
mGradient = doGradient(true, atts);
} else if (localName.equals("radialGradient")) {
Expand Down Expand Up @@ -1655,6 +1658,8 @@ public void startElement(String namespaceURI, String localName, String qName, At
opacity = props.getFloat("opacity");
}
if (opacity != null && opacity < 1f) {
// FIXME Ideally, we should compute the bounds of the enclosed group, and create
// the layer exactly to its size; see issue #6
// Apply inverse of matrix to correct for any transformations
// It's okay to use getMatrix() here as we may assume its a software layer
Matrix m = mCanvas.getMatrix();
Expand Down Expand Up @@ -1813,7 +1818,7 @@ public void startElement(String namespaceURI, String localName, String qName, At
} else if (!hidden2 && localName.equals("path")) {
String d = getStringAttr("d", atts);

if (mDefsReading) {
if (mReadingDefs) {
mDefs.put(id, getStringAttr("d", atts));
return;
} else if (null == d) {
Expand Down Expand Up @@ -1853,7 +1858,15 @@ public void startElement(String namespaceURI, String localName, String qName, At
} else if (!hidden2 && localName.equals("tspan")) {
mTextStack.push(new SvgText(atts, mTextStack.isEmpty() ? null : mTextStack.peek()));
} else if (!hidden2) {
Log.d(TAG, "Unrecognized SVG command: " + localName);
switch (localName) {
case "metadata":
// Ignore, including children
mReadIgnoreStack.push(localName);
break;
default:
Log.d(TAG, "Unrecognized SVG command: " + localName);
break;
}
}
}

Expand All @@ -1868,6 +1881,11 @@ public void characters(char ch[], int start, int length) {
@Override
public void endElement(String namespaceURI, String localName, String qName)
throws SAXException {
if (!mReadIgnoreStack.empty() && localName.equals(mReadIgnoreStack.peek())) {
// Ignore
mReadIgnoreStack.pop();
return;
}
switch (localName) {
case "svg":
mPicture.endRecording();
Expand All @@ -1893,7 +1911,7 @@ public void endElement(String namespaceURI, String localName, String qName)
break;
case "defs":
finishGradients();
mDefsReading = false;
mReadingDefs = false;
break;
case "g":
if (boundsMode) {
Expand Down

0 comments on commit c41e453

Please sign in to comment.