Exemplo n.º 1
0
DEF_TEST(SVGDevice_image_shader_tileboth, reporter) {
    SkDOM dom;
    SkPaint paint;
    int imageWidth = 3, imageHeight = 3;
    int rectWidth = 10, rectHeight = 10;
    ImageShaderTestSetup(&dom, &paint, imageWidth, imageHeight, rectWidth, rectHeight,
                         SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode);

    const SkDOM::Node* root = dom.finishParsing();

    const SkDOM::Node *patternNode, *imageNode, *rectNode;
    const SkDOM::Node* innerSvg = dom.getFirstChild(root, "svg");
    if (innerSvg == nullptr) {
        ERRORF(reporter, "inner svg element not found");
        return;
    }
    bool structureAppropriate =
            FindImageShaderNodes(reporter, &dom, innerSvg, &patternNode, &imageNode, &rectNode);
    REPORTER_ASSERT(reporter, structureAppropriate);

    // the imageNode should always maintain its size.
    REPORTER_ASSERT(reporter, atoi(dom.findAttr(imageNode, "width")) == imageWidth);
    REPORTER_ASSERT(reporter, atoi(dom.findAttr(imageNode, "height")) == imageHeight);

    REPORTER_ASSERT(reporter, atoi(dom.findAttr(patternNode, "width")) == imageWidth);
    REPORTER_ASSERT(reporter, atoi(dom.findAttr(patternNode, "height")) == imageHeight);
}
Exemplo n.º 2
0
	SkDOMListSource(const SkDOM& dom, const SkDOM::Node* node) : fDirTail(">")
	{
		const SkDOM::Node* child = dom.getFirstChild(node, "item");
		int	count = 0;

		while (child)
		{
			count += 1;
			child = dom.getNextSibling(child, "item");
		}

		fCount = count;
		fList = NULL;
		if (count)
		{
			ItemRec* rec = fList = new ItemRec[count];

			child = dom.getFirstChild(node, "item");
			while (child)
			{
				rec->fLabel.set(dom.findAttr(child, "label"));
				rec->fTail.set(dom.findAttr(child, "tail"));
				rec->fAltTail.set(dom.findAttr(child, "alt-tail"));
				rec->fTarget.set(dom.findAttr(child, "target"));
				rec->fType = kUnknown_Type;

				int	index = dom.findList(child, "type", "dir,toggle");
				if (index >= 0)
					rec->fType = (Type)(index + 1);

				child = dom.getNextSibling(child, "item");
				rec += 1;
			}
		}
	}
Exemplo n.º 3
0
void SkViewInflate::rInflate(const SkDOM& dom, const SkDOM::Node* node, SkView* parent)
{
	const char* str = dom.findAttr(node, "id");
	if (str)
		fIDs.set(str, parent);

	const SkDOM::Node* child = dom.getFirstChild(node);
	while (child)
	{
		SkView* view = this->createView(dom, child);
		if (view)
		{
			this->rInflate(dom, child, view);
			parent->attachChildToFront(view)->unref();
		}
		else
		{
			const char* name = dom.getName(child);
			const char* target;

			if (!strcmp(name, "listenTo") && (target = dom.findAttr(child, "target")) != NULL)
				this->addIDStr(&fListenTo, parent, target);

			if (!strcmp(name, "broadcastTo") && (target = dom.findAttr(child, "target")) != NULL)
				this->addIDStr(&fBroadcastTo, parent, target);
		}
		child = dom.getNextSibling(child);
	}

	parent->setVisibleP(true);
	this->inflateView(parent, dom, node);
}
Exemplo n.º 4
0
void SkListView::onInflate(const SkDOM& dom, const SkDOM::Node* node)
{
	this->INHERITED::onInflate(dom, node);
	
	{
		bool hasScrollBar;
		if (dom.findBool(node, "scrollBar", &hasScrollBar))
			this->setHasScrollBar(hasScrollBar);
	}

	const SkDOM::Node*	child;

	if ((child = dom.getFirstChild(node, "bindings")) != NULL)
	{
		delete[] fBindings;
		fBindings = NULL;
		fBindingCount = 0;

		SkListSource* listSrc = SkListSource::Factory(dom.findAttr(child, "data-fields"));
		SkASSERT(listSrc);
		fSkinName.set(dom.findAttr(child, "skin-slots"));
		SkASSERT(fSkinName.size());

		this->setListSource(listSrc)->unref();
			
		int count = dom.countChildren(child, "bind");
		if (count > 0)
		{
			fBindings = new BindingRec[count];
			count = 0;	// reuse this to count up to the number of valid bindings

			child = dom.getFirstChild(child, "bind");
			SkASSERT(child);
			do {
				const char* fieldName = dom.findAttr(child, "field");
				const char* slotName = dom.findAttr(child, "slot");
				if (fieldName && slotName)
				{
					fBindings[count].fFieldIndex = listSrc->findFieldIndex(fieldName);
					if (fBindings[count].fFieldIndex >= 0)
						fBindings[count++].fSlotName.set(slotName);
				}
			} while ((child = dom.getNextSibling(child, "bind")) != NULL);

			fBindingCount = SkToU16(count);
			if (count == 0)
			{
				SkDEBUGF(("SkListView::onInflate: no valid <bind> elements in <listsource>\n"));
				delete[] fBindings;
			}
		}
		this->dirtyCache(kAnimCount_DirtyFlag);
		this->setSelection(0);
	}
}
void SkProgressView::onInflate(const SkDOM& dom, const SkDOM::Node* node)
{
    this->INHERITED::onInflate(dom, node);

    const char* s;

    SkASSERT(fOnShader == NULL);
    SkASSERT(fOffShader == NULL);

    if ((s = dom.findAttr(node, "src-on")) != NULL)
        fOnShader = inflate_shader(s);
    if ((s = dom.findAttr(node, "src-off")) != NULL)
        fOffShader = inflate_shader(s);
    (void)dom.findBool(node, "do-interp", &fDoInterp);
}
void SkStaticTextView::onInflate(const SkDOM& dom, const SkDOM::Node* node)
{
#if 0
	this->INHERITED::onInflate(dom, node);

	int	index;
	if ((index = dom.findList(node, "mode", "fixed,auto-width,auto-height")) >= 0)
		this->setMode((Mode)index);
	else
		assert_no_attr(dom, node, "mode");

	if ((index = dom.findList(node, "spacing-align", "start,center,end")) >= 0)
		this->setSpacingAlign((SkTextBox::SpacingAlign)index);
	else
		assert_no_attr(dom, node, "spacing-align");

	SkScalar s[2];
	if (dom.findScalars(node, "margin", s, 2))
		this->setMargin(s[0], s[1]);
	else
		assert_no_attr(dom, node, "margin");

	const char* text = dom.findAttr(node, "text");
	if (text)
		this->setText(text);

	if ((node = dom.getFirstChild(node, "paint")) != NULL &&
		(node = dom.getFirstChild(node, "screenplay")) != NULL)
	{
		inflate_paint(dom, node, &fPaint);
	}
#endif
}
Exemplo n.º 7
0
SkXMLListSource::SkXMLListSource(const char doc[], size_t len)
{
	fFieldCount = fRecordCount = 0;
	fFields = fRecords = NULL;

	SkDOM	dom;

	const SkDOM::Node* node = dom.build(doc, len);
	SkASSERT(node);
	const SkDOM::Node*	child;	

	child = dom.getFirstChild(node, "fields");
	if (child)
	{
		fFieldCount = dom.countChildren(child, "field");
		fFields = new SkString[fFieldCount];

		int n = 0;
		child = dom.getFirstChild(child, "field");
		while (child)
		{
			fFields[n].set(dom.findAttr(child, "name"));
			child = dom.getNextSibling(child, "field");
			n += 1;
		}
		SkASSERT(n == fFieldCount);
	}
	
	child = dom.getFirstChild(node, "records");
	if (child)
	{
		fRecordCount = dom.countChildren(child, "record");
		fRecords = new SkString[fRecordCount * fFieldCount];

		int n = 0;
		child = dom.getFirstChild(child, "record");
		while (child)
		{
			for (int i = 0; i < fFieldCount; i++)
				fRecords[n * fFieldCount + i].set(dom.findAttr(child, fFields[i].c_str()));
			child = dom.getNextSibling(child, "record");
			n += 1;
		}
		SkASSERT(n == fRecordCount);
	}
}
Exemplo n.º 8
0
void SkGridView::onInflate(const SkDOM& dom, const SkDOM::Node* node)
{
	this->INHERITED::onInflate(dom, node);

	SkScalar			x[2];
	const SkDOM::Node*	child;

	if (dom.findScalars(node, "cell-size", x, 2))
		this->setCellSize(x[0], x[1]);

	if ((child = dom.getFirstChild(node, "hilite-paint")) != NULL)
		SkPaint_Inflate(&this->paint(kHiliteCell_Attr), dom, child);

	// look for a listsource
	{
		SkListSource* src = NULL;

		if ((child = dom.getFirstChild(node, "file-listsource")) != NULL)
		{
			const char* path = dom.findAttr(child, "path");
			if (path)
				src = SkListSource::CreateFromDir(	path,
													dom.findAttr(child, "filter"),
													dom.findAttr(child, "target"));
		}
		else if ((child = dom.getFirstChild(node, "xml-listsource")) != NULL)
		{
			src = SkListSource::CreateFromDOM(dom, child);
		}

		if (src)
		{
			this->setListSource(src)->unref();
			this->setSelection(0);
		}
	}
	this->onSizeChange();
}
Exemplo n.º 9
0
void SkListView::onInflate(const SkDOM& dom, const SkDOM::Node* node)
{
	this->INHERITED::onInflate(dom, node);

	SkScalar			x;
	const SkDOM::Node*	child;

	if (dom.findScalar(node, "row-height", &x))
		this->setRowHeight(x);

	if ((child = dom.getFirstChild(node, "hilite-paint")) != NULL)
		SkPaint_Inflate(&this->paint(kHiliteCell_Attr), dom, child);

	// look for a listsource
	{
		SkListSource* src = NULL;

		if ((child = dom.getFirstChild(node, "file-listsource")) != NULL)
		{
			const char* path = dom.findAttr(child, "path");
			if (path)
				src = SkListSource::CreateFromDir(	path,
													dom.findAttr(child, "filter"),
													dom.findAttr(child, "target"));
		}
		else if ((child = dom.getFirstChild(node, "xml-listsource")) != NULL)
		{
			src = SkListSource::CreateFromDOM(dom, child);
		}

		if (src)
		{
			this->setListSource(src)->unref();
			this->setSelection(0);
		}
	}
}
Exemplo n.º 10
0
void SkTextView::onInflate(const SkDOM& dom, const SkDOM::Node* node)
{
	this->INHERITED::onInflate(dom, node);

	const char* text = dom.findAttr(node, "text");
	if (text)
		this->setText(text);

	SkPoint	margin;
	if (dom.findScalars(node, "margin", (SkScalar*)&margin, 2))
		this->setMargin(margin);
	(void)dom.findBool(node, "do-interp", &fDoInterp);

	SkPaint_Inflate(&fPaint, dom, node);
}
Exemplo n.º 11
0
DEF_TEST(SVGDevice_image_shader_norepeat, reporter) {
    SkDOM dom;
    SkPaint paint;
    int imageWidth = 3, imageHeight = 3;
    int rectWidth = 10, rectHeight = 10;
    ImageShaderTestSetup(&dom, &paint, imageWidth, imageHeight, rectWidth, rectHeight,
                         SkShader::kClamp_TileMode, SkShader::kClamp_TileMode);

    const SkDOM::Node* root = dom.finishParsing();

    const SkDOM::Node *patternNode, *imageNode, *rectNode;
    bool structureAppropriate =
            FindImageShaderNodes(reporter, &dom, root, &patternNode, &imageNode, &rectNode);
    REPORTER_ASSERT(reporter, structureAppropriate);

    // the image should always maintain its size.
    REPORTER_ASSERT(reporter, atoi(dom.findAttr(imageNode, "width")) == imageWidth);
    REPORTER_ASSERT(reporter, atoi(dom.findAttr(imageNode, "height")) == imageHeight);

    // making the pattern as large as the container prevents
    // it from repeating.
    REPORTER_ASSERT(reporter, strcmp(dom.findAttr(patternNode, "width"), "100%") == 0);
    REPORTER_ASSERT(reporter, strcmp(dom.findAttr(patternNode, "height"), "100%") == 0);
}
Exemplo n.º 12
0
void SkPaint_Inflate(SkPaint* paint, const SkDOM& dom, const SkDOM::Node* node)
{
	SkASSERT(paint);
	SkASSERT(&dom);
	SkASSERT(node);

	SkScalar x;

	if (dom.findScalar(node, "stroke-width", &x))
		paint->setStrokeWidth(x);
	if (dom.findScalar(node, "text-size", &x))
		paint->setTextSize(x);
	
	bool	b;

	SkASSERT("legacy: use is-stroke" && !dom.findBool(node, "is-frame", &b));

	if (dom.findBool(node, "is-stroke", &b))
		paint->setStyle(b ? SkPaint::kStroke_Style : SkPaint::kFill_Style);
	if (dom.findBool(node, "is-antialias", &b))
		paint->setAntiAlias(b);
	if (dom.findBool(node, "is-lineartext", &b))
		paint->setLinearText(b);

	const char* str = dom.findAttr(node, "color");
	if (str)
	{
		SkColor	c = paint->getColor();
		if (SkParse::FindColor(str, &c))
			paint->setColor(c);
	}

	// do this AFTER parsing for the color
	if (dom.findScalar(node, "opacity", &x))
	{
		x = SkMaxScalar(0, SkMinScalar(x, SK_Scalar1));
		paint->setAlpha(SkScalarRound(x * 255));
	}

	int	index = dom.findList(node, "text-anchor", "left,center,right");
	if (index >= 0)
		paint->setTextAlign((SkPaint::Align)index);

	SkShader* shader = inflate_shader(dom, node);
	if (shader)
		paint->setShader(shader)->unref();
}
Exemplo n.º 13
0
 static void assert_no_attr(const SkDOM& dom, const SkDOM::Node* node, const char attr[])
 {
     const char* value = dom.findAttr(node, attr);
     if (value)
         SkDebugf("unknown attribute %s=\"%s\"\n", attr, value);
 }