dm: support printing specific page of mskp to SVG

Currently with dm, it's possible to convert an .mskp to a multi-page PDF as
follows:

    out/Release/dm --src mskp --mskps /tmp/filename.mskp -w /tmp \
    --config pdf --verbose

The SVG equivalent partially works, although only outputs the first page:

    out/Release/dm --src mskp --mskps /tmp/filename.mskp -w /tmp \
    --config svg --verbose

This CL adds support for passing extended options to SVG.  Specifically, the
'page' option , which now determines which page of the source mskp gets
converted to the SVG output.  The new syntax is as follows:

    out/Release/dm --src mskp --mskps /tmp/filename.mskp -w /tmp \
    --config svg[page=2] --verbose

The `[key=value]` syntax is the same extended options syntax currently used by
dm with --config gpu, e.g. `gpu[api=gl,color=8888]`.

BUG=skia:7601

Change-Id: I3523d79b1cdbbba9e80fd46501331877091bdead
Reviewed-on: https://skia-review.googlesource.com/105404
Commit-Queue: Mike Klein <mtklein@google.com>
Reviewed-by: Mike Klein <mtklein@google.com>
Reviewed-by: Mike Klein <mtklein@chromium.org>
diff --git a/dm/DMSrcSink.cpp b/dm/DMSrcSink.cpp
index 2229b9c..149138d 100644
--- a/dm/DMSrcSink.cpp
+++ b/dm/DMSrcSink.cpp
@@ -1838,14 +1838,23 @@
 
 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
 
-SVGSink::SVGSink() {}
+SVGSink::SVGSink(int pageIndex) : fPageIndex(pageIndex) {}
 
 Error SVGSink::draw(const Src& src, SkBitmap*, SkWStream* dst, SkString*) const {
 #if defined(SK_XML)
+    if (src.pageCount() > 1) {
+        int pageCount = src.pageCount();
+        if (fPageIndex > pageCount - 1) {
+            return Error(SkStringPrintf("Page index %d too high for document with only %d pages.",
+                                        fPageIndex, pageCount));
+        }
+    }
     std::unique_ptr<SkXMLWriter> xmlWriter(new SkXMLStreamWriter(dst));
-    return src.draw(SkSVGCanvas::Make(SkRect::MakeWH(SkIntToScalar(src.size().width()),
+    return src.draw(fPageIndex,
+                    SkSVGCanvas::Make(SkRect::MakeWH(SkIntToScalar(src.size().width()),
                                                      SkIntToScalar(src.size().height())),
-                                      xmlWriter.get()).get());
+                                      xmlWriter.get())
+                            .get());
 #else
     return Error("SVG sink is disabled.");
 #endif // SK_XML