updates



git-svn-id: http://skia.googlecode.com/svn/trunk@567 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/samplecode/SampleAnimator.cpp b/samplecode/SampleAnimator.cpp
index 4ba8872..99173fc 100644
--- a/samplecode/SampleAnimator.cpp
+++ b/samplecode/SampleAnimator.cpp
@@ -4,48 +4,7 @@
 
 #include "SkAnimator.h"
 #include "SkStream.h"
-
-#include "SkColorPriv.h"
-static inline void Filter_32_opaque_portable(unsigned x, unsigned y,
-                                             SkPMColor a00, SkPMColor a01,
-                                             SkPMColor a10, SkPMColor a11,
-                                             SkPMColor* dstColor) {
-    SkASSERT((unsigned)x <= 0xF);
-    SkASSERT((unsigned)y <= 0xF);
-    
-    int xy = x * y;
-    uint32_t mask = gMask_00FF00FF; //0xFF00FF;
-    
-    int scale = 256 - 16*y - 16*x + xy;
-    uint32_t lo = (a00 & mask) * scale;
-    uint32_t hi = ((a00 >> 8) & mask) * scale;
-    
-    scale = 16*x - xy;
-    lo += (a01 & mask) * scale;
-    hi += ((a01 >> 8) & mask) * scale;
-    
-    scale = 16*y - xy;
-    lo += (a10 & mask) * scale;
-    hi += ((a10 >> 8) & mask) * scale;
-    
-    lo += (a11 & mask) * xy;
-    hi += ((a11 >> 8) & mask) * xy;
-    
-    *dstColor = ((lo >> 8) & mask) | (hi & ~mask);
-}
-
-static void test_filter() {
-    for (int r = 0; r <= 0xFF; r++) {
-        SkPMColor c = SkPackARGB32(0xFF, r, r, r);
-        for (int y = 0; y <= 0xF; y++) {
-            for (int x = 0; x <= 0xF; x++) {
-                SkPMColor dst;
-                Filter_32_opaque_portable(x, y, c, c, c, c, &dst);
-                SkASSERT(SkGetPackedA32(dst) == 255);
-            }
-        }
-    }
-}
+#include "SkDOM.h"
 
 ///////////////////////////////////////////////////////////////////////////////
 
@@ -73,9 +32,7 @@
     typedef SkView INHERITED;
 };
 
-SkAnimatorView::SkAnimatorView() : fAnimator(NULL) {
-    test_filter();
-}
+SkAnimatorView::SkAnimatorView() : fAnimator(NULL) {}
 
 SkAnimatorView::~SkAnimatorView() {
     delete fAnimator;
@@ -97,15 +54,65 @@
     return this->decodeStream(is);
 }
 
+static const SkDOMNode* find_nodeID(const SkDOM& dom,
+						const SkDOMNode* node, const char name[]) {
+	if (NULL == node) {
+		node = dom.getRootNode();
+	}
+	do {
+		const char* idval = dom.findAttr(node, "id");
+		if (idval && !strcmp(idval, name)) {
+			return node;
+		}
+		const SkDOMNode* child = dom.getFirstChild(node);
+		if (child) {
+			const SkDOMNode* found = find_nodeID(dom, child, name);
+			if (found) {
+				return found;
+			}
+		}
+	} while ((node = dom.getNextSibling(node)) != NULL);
+	return NULL;
+}
+
 bool SkAnimatorView::decodeStream(SkStream* stream) {
     delete fAnimator;
     fAnimator = new SkAnimator;
     fAnimator->setURIBase(fBaseURI.c_str());
+#if 0
     if (!fAnimator->decodeStream(stream)) {
         delete fAnimator;
         fAnimator = NULL;
         return false;
     }
+#else
+	size_t len = stream->getLength();
+	char* text = (char*)sk_malloc_throw(len);
+	stream->read(text, len);
+	SkDOM dom;
+	const SkDOM::Node* root = dom.build(text, len);
+	if (NULL == root) {
+		return false;
+	}
+	if (!fAnimator->decodeDOM(dom, root)) {
+		delete fAnimator;
+		fAnimator = NULL;
+		return false;
+	}
+	for (int i = 0; i <= 10; i++) {
+		SkString name("glyph");
+		name.appendS32(i);
+		const SkDOM::Node* node = find_nodeID(dom, NULL, name.c_str());
+		SkASSERT(node);
+		SkRect r;
+		dom.findScalar(node, "left", &r.fLeft);
+		dom.findScalar(node, "top", &r.fTop);
+		dom.findScalar(node, "width", &r.fRight); r.fRight += r.fLeft;
+		dom.findScalar(node, "height", &r.fBottom); r.fBottom += r.fTop;
+		SkDebugf("--- %s [%g %g %g %g]\n", name.c_str(),
+				 r.fLeft, r.fTop, r.fRight, r.fBottom);
+	}
+#endif
     return true;
 }
 
@@ -115,7 +122,7 @@
     if (fAnimator) {
         canvas->drawColor(SK_ColorWHITE);
         fAnimator->draw(canvas, 0);
-        
+#if 0
         canvas->save();
         canvas->translate(120, 30);
         canvas->scale(0.5, 0.5);
@@ -129,6 +136,7 @@
         canvas->restore();
         
         this->inval(NULL);
+#endif
     }
 }
 
@@ -137,8 +145,13 @@
 static SkView* MyFactory() {
     SkAnimatorView* av = new SkAnimatorView;
 //    av->decodeFile("/skimages/test.xml");
+#if 0
     av->setURIBase("/skia/trunk/animations/");
     av->decodeFile("/skia/trunk/animations/checkbox.xml");
+#else
+	av->setURIBase("/");
+	av->decodeFile("/testanim.txt");
+#endif
     return av;
 }
 
diff --git a/samplecode/SampleSVG.cpp b/samplecode/SampleSVG.cpp
new file mode 100644
index 0000000..fdb1d54
--- /dev/null
+++ b/samplecode/SampleSVG.cpp
@@ -0,0 +1,82 @@
+#include "SampleCode.h"
+#include "SkView.h"
+#include "SkBlurMaskFilter.h"
+#include "SkCanvas.h"
+#include "SkGradientShader.h"
+#include "SkGraphics.h"
+#include "SkImageDecoder.h"
+#include "SkPath.h"
+#include "SkRandom.h"
+#include "SkRegion.h"
+#include "SkShader.h"
+#include "SkUtils.h"
+#include "SkXfermode.h"
+#include "SkColorPriv.h"
+#include "SkColorFilter.h"
+#include "SkTime.h"
+#include "SkTypeface.h"
+#include "SkTextBox.h"
+#include "SkOSFile.h"
+#include "SkStream.h"
+
+#include "SkSVGParser.h"
+
+class SVGView : public SkView {
+public:    
+	SVGView() {
+		SkXMLParserError err;
+		SkFILEStream stream("/testsvg2.svg");
+		SkSVGParser parser(&err);
+		if (parser.parse(stream)) {
+			const char* text = parser.getFinal();
+			SkFILEWStream output("/testanim.txt");
+			output.write(text, strlen(text));
+		}
+	}
+    
+protected:
+    // overrides from SkEventSink
+    virtual bool onQuery(SkEvent* evt)  {
+        if (SampleCode::TitleQ(*evt)) {
+            SkString str("SVG");
+            SampleCode::TitleR(evt, str.c_str());
+            return true;
+        }
+        return this->INHERITED::onQuery(evt);
+    }
+    
+    void drawBG(SkCanvas* canvas) {
+        canvas->drawColor(SK_ColorWHITE);
+    }
+    
+    virtual void onDraw(SkCanvas* canvas) {
+        this->drawBG(canvas);
+    }
+    
+    virtual SkView::Click* onFindClickHandler(SkScalar x, SkScalar y) {
+        return new Click(this);
+    }
+    
+    virtual bool onClick(Click* click) {
+        int y = click->fICurr.fY;
+        if (y < 0) {
+            y = 0;
+        } else if (y > 255) {
+            y = 255;
+        }
+        fByte = y;
+        this->inval(NULL);
+        return true;
+    }
+    
+private:
+    int fByte;
+
+    typedef SkView INHERITED;
+};
+
+//////////////////////////////////////////////////////////////////////////////
+
+static SkView* MyFactory() { return new SVGView; }
+static SkViewRegister reg(MyFactory);
+
diff --git a/samplecode/SampleTextBox.cpp b/samplecode/SampleTextBox.cpp
new file mode 100644
index 0000000..f8f52a2
--- /dev/null
+++ b/samplecode/SampleTextBox.cpp
@@ -0,0 +1,101 @@
+#include "SampleCode.h"
+#include "SkView.h"
+#include "SkBlurMaskFilter.h"
+#include "SkCanvas.h"
+#include "SkGradientShader.h"
+#include "SkGraphics.h"
+#include "SkImageDecoder.h"
+#include "SkPath.h"
+#include "SkRandom.h"
+#include "SkRegion.h"
+#include "SkShader.h"
+#include "SkUtils.h"
+#include "SkXfermode.h"
+#include "SkColorPriv.h"
+#include "SkColorFilter.h"
+#include "SkTime.h"
+#include "SkTypeface.h"
+#include "SkTextBox.h"
+#include "SkOSFile.h"
+#include "SkStream.h"
+#include "SkKey.h"
+
+static const char gText[] = 
+	"When in the Course of human events it becomes necessary for one people "
+	"to dissolve the political bands which have connected them with another "
+	"and to assume among the powers of the earth, the separate and equal "
+	"station to which the Laws of Nature and of Nature's God entitle them, "
+	"a decent respect to the opinions of mankind requires that they should "
+	"declare the causes which impel them to the separation.";
+
+class TextBoxView : public SkView {
+public:    
+	TextBoxView() {
+		fTextSize = SkIntToScalar(32);
+	}
+    
+protected:
+    // overrides from SkEventSink
+    virtual bool onQuery(SkEvent* evt)  {
+        if (SampleCode::TitleQ(*evt)) {
+            SkString str("TextBox");
+            SampleCode::TitleR(evt, str.c_str());
+            return true;
+        }
+        return this->INHERITED::onQuery(evt);
+    }
+    
+    void drawBG(SkCanvas* canvas) {
+        canvas->drawColor(SK_ColorWHITE);
+    }
+    
+    virtual void onDraw(SkCanvas* canvas) {
+        this->drawBG(canvas);
+
+		SkScalar margin = 20;
+        SkTextBox tbox;
+		tbox.setMode(SkTextBox::kLineBreak_Mode);
+		tbox.setBox(margin, margin,
+					this->width() - margin, this->height() - margin);
+		tbox.setSpacing(SkIntToScalar(3)/3, 0);
+
+		SkPaint paint;
+		paint.setAntiAlias(true);
+		paint.setTextSize(fTextSize);
+
+		tbox.draw(canvas, gText, strlen(gText), paint);
+    }
+    
+    virtual SkView::Click* onFindClickHandler(SkScalar x, SkScalar y) {
+        return new Click(this);
+    }
+    
+	virtual bool onClick(Click* click) {
+		const SkScalar delta = SkIntToScalar(3);
+		if (click->fState == Click::kUp_State) {
+			if (click->fCurr.fY < this->height()/2) {
+				fTextSize += delta;
+				this->inval(NULL);
+				return true;
+			} else {
+				if (fTextSize > delta) {
+					fTextSize -= delta;
+					this->inval(NULL);
+					return true;
+				}
+			}
+		}
+		return this->INHERITED::onClick(click);
+    }
+    
+private:
+    SkScalar fTextSize;
+
+    typedef SkView INHERITED;
+};
+
+//////////////////////////////////////////////////////////////////////////////
+
+static SkView* MyFactory() { return new TextBoxView; }
+static SkViewRegister reg(MyFactory);
+
diff --git a/samplecode/SampleTextEffects.cpp b/samplecode/SampleTextEffects.cpp
index 0dbde5e..b71f5b4 100644
--- a/samplecode/SampleTextEffects.cpp
+++ b/samplecode/SampleTextEffects.cpp
@@ -376,17 +376,17 @@
         canvas->save();
 //        canvas->scale(SK_Scalar1*2, SK_Scalar1*2, 0, 0);
 
-        SkScalar    x = SkIntToScalar(20);
-        SkScalar    y = SkIntToScalar(40);
         SkPaint     paint;
         
         paint.setAntiAlias(true);
-        paint.setTextSize(SkIntToScalar(48));
+        paint.setTextSize(SkIntToScalar(56));
         paint.setTypeface(SkTypeface::CreateFromName("sans-serif",
                                                      SkTypeface::kBold));
 
-        SkString str("GOOGLE ");
-        str.appendUnichar(0x5700);
+        SkScalar    x = SkIntToScalar(20);
+        SkScalar    y = paint.getTextSize();
+
+        SkString str("TextEffects");
 
         paint.setTypeface(fFace);
         
@@ -429,7 +429,7 @@
             canvas->drawRectCoords(0, 0, SkIntToScalar(120), SkIntToScalar(150), paint);
         }
         
-        if (1)
+        if (0)
         {
             SkAvoidXfermode   mode(SK_ColorWHITE, 0xFF,
                                     SkAvoidXfermode::kTargetColor_Mode);