コード例 #1
0
 public void SetUp() {
     root = new Tag(ROOTSTR);
     child1NoChildren = new Tag(CHILD1);
     root.AddChild(child1NoChildren);
     child2WithChild = new Tag(CHILD2);
     childsChild = new Tag(CHILDS_CHILD);
     child2WithChild.AddChild(childsChild);
     root.AddChild(child2WithChild);
 }
コード例 #2
0
 void PushTag(Tag tag)
 {
     if (currentTag != null)
     {
         currentTag.AddChild(tag);
     }
     tagStack.Push(tag);
     currentTag = tagStack.Peek();
 }
コード例 #3
0
 virtual public void SetUp()
 {
     root             = new Tag(ROOTSTR);
     child1NoChildren = new Tag(CHILD1);
     root.AddChild(child1NoChildren);
     child2WithChild = new Tag(CHILD2);
     childsChild     = new Tag(CHILDS_CHILD);
     child2WithChild.AddChild(childsChild);
     root.AddChild(child2WithChild);
 }
コード例 #4
0
        private static void SerializeChild(string name, object value, System.Type type, bool simpleType, SerializationAttribute attr, Tag parent)
        {
            Tag tag = new Tag(name);

            if ((!simpleType || type == typeof(object)) && (value != null && !ReflectionHelper.IsNullable(type)) && value.GetType() != type)
            {
                type        = value.GetType();
                tag["type"] = (object)ReflectionHelper.GetShortAssemblyQualifiedName(type);
            }
            if (simpleType)
            {
                tag.AddValue(value);
            }
            else if (type == typeof(Color))
            {
                Color color = (Color)value;
                SdlSerializer.AddValueList(tag, (object)color.R, (object)color.G, (object)color.B);
                if ((int)color.A != (int)byte.MaxValue)
                {
                    tag.AddValue((object)color.A);
                }
            }
            else if (type == typeof(Vector2))
            {
                Vector2 vector2 = (Vector2)value;
                SdlSerializer.AddValueList(tag, (object)vector2.X, (object)vector2.Y);
            }
            else if (type == typeof(Vector3))
            {
                Vector3 vector3 = (Vector3)value;
                SdlSerializer.AddValueList(tag, (object)vector3.X, (object)vector3.Y, (object)vector3.Z);
            }
            else if (type == typeof(Vector4))
            {
                Vector4 vector4 = (Vector4)value;
                SdlSerializer.AddValueList(tag, (object)vector4.X, (object)vector4.Y, (object)vector4.Z, (object)vector4.W);
            }
            else if (type == typeof(Quaternion))
            {
                Quaternion quaternion = (Quaternion)value;
                SdlSerializer.AddValueList(tag, (object)quaternion.X, (object)quaternion.Y, (object)quaternion.Z, (object)quaternion.W);
            }
            else if (type == typeof(Matrix))
            {
                SdlSerializer.SerializeMatrix(tag, (Matrix)value);
            }
            else if (ReflectionHelper.IsGenericDictionary(type))
            {
                SdlSerializer.SerializeDictionary(tag, value as IDictionary, attr.CollectionItemName);
            }
            else if (ReflectionHelper.IsGenericCollection(type))
            {
                SdlSerializer.SerializeCollection(tag, value as IEnumerable, attr.CollectionItemName);
            }
            else
            {
                SdlSerializer.SerializeInternal(value, type, tag);
            }
            parent.AddChild(tag);
        }
コード例 #5
0
        virtual public void SetUp() {
            parent = new Tag("body");
            parent.CSS[CSS.Property.FONT_FAMILY] = "Helvetica";
            parent.CSS[CSS.Property.FONT_SIZE] = "12pt";
            first = new Tag(null);
            first.CSS[CSS.Property.FONT_FAMILY] = "Helvetica";
            first.CSS[CSS.Property.FONT_SIZE] = "12pt";
            second = new Tag(null);
            second.CSS[CSS.Property.FONT_FAMILY] = "Helvetica";
            second.CSS[CSS.Property.FONT_SIZE] = "12pt";
            child = new Tag(null);
            child.CSS[CSS.Property.FONT_FAMILY] = "Helvetica";
            child.CSS[CSS.Property.FONT_SIZE] = "12pt";

            parent.AddChild(first);
            first.Parent = parent;
            second.Parent = parent;
            first.AddChild(child);
            second.AddChild(child);
            parent.CSS[CSS.Property.FONT_SIZE] = fst.TranslateFontSize(parent) + "pt";
            first.CSS[CSS.Property.FONT_SIZE] = fst.TranslateFontSize(first) + "pt";
            first.CSS[CSS.Property.TEXT_ALIGN] = CSS.Value.LEFT;
            second.CSS[CSS.Property.FONT_SIZE] = fst.TranslateFontSize(second) + "pt";
            child.CSS[CSS.Property.FONT_SIZE] = fst.TranslateFontSize(child) + "pt";
            firstPara = new Paragraph(new Chunk("default text for chunk creation"));
            secondPara = new Paragraph(new Chunk("default text for chunk creation"));
            configuration = new HtmlPipelineContext(null);
            applier.Apply(firstPara, first, configuration);
        }
コード例 #6
0
        virtual public void SetUp()
        {
            parent = new Tag("body");
            parent.CSS[CSS.Property.FONT_FAMILY] = "Helvetica";
            parent.CSS[CSS.Property.FONT_SIZE]   = "12pt";
            first = new Tag(null);
            first.CSS[CSS.Property.FONT_FAMILY] = "Helvetica";
            first.CSS[CSS.Property.FONT_SIZE]   = "12pt";
            second = new Tag(null);
            second.CSS[CSS.Property.FONT_FAMILY] = "Helvetica";
            second.CSS[CSS.Property.FONT_SIZE]   = "12pt";
            child = new Tag(null);
            child.CSS[CSS.Property.FONT_FAMILY] = "Helvetica";
            child.CSS[CSS.Property.FONT_SIZE]   = "12pt";

            parent.AddChild(first);
            first.Parent  = parent;
            second.Parent = parent;
            first.AddChild(child);
            second.AddChild(child);
            parent.CSS[CSS.Property.FONT_SIZE] = fst.TranslateFontSize(parent) + "pt";
            first.CSS[CSS.Property.FONT_SIZE]  = fst.TranslateFontSize(first) + "pt";
            first.CSS[CSS.Property.TEXT_ALIGN] = CSS.Value.LEFT;
            second.CSS[CSS.Property.FONT_SIZE] = fst.TranslateFontSize(second) + "pt";
            child.CSS[CSS.Property.FONT_SIZE]  = fst.TranslateFontSize(child) + "pt";
            firstPara     = new Paragraph(new Chunk("default text for chunk creation"));
            secondPara    = new Paragraph(new Chunk("default text for chunk creation"));
            configuration = new HtmlPipelineContext(null);
            applier.Apply(firstPara, first, configuration);
        }
コード例 #7
0
        public void TagGeneration(ref Tag tag)
        {
            for (int x = 0; x < 10000; x++)
            {
                Tag testTag = new Tag("test" + x);
                Tag date    = new Tag("date");
                date.value = Converter.GetOptimized(125825285);
                Tag open = new Tag("open");
                open.value = Converter.GetOptimized(3005);
                Tag high = new Tag("high");
                high.value = Converter.GetOptimized(3010);
                Tag low = new Tag("low");
                low.value = Converter.GetOptimized(2936);
                Tag close = new Tag("close");
                close.value = Converter.GetOptimized(2936);
                Tag volume = new Tag("volume");
                volume.value = Converter.GetOptimized(104000);
                testTag.AddChild(date);
                testTag.AddChild(open);
                testTag.AddChild(high);
                testTag.AddChild(low);
                testTag.AddChild(close);
                testTag.AddChild(volume);
                testTag.active = false;

                tag.AddChild(testTag);
            }
        }
コード例 #8
0
        virtual public void ValidateParentSetOnAdd()
        {
            Tag t  = new Tag("pappie");
            Tag t2 = new Tag("baby");

            t.AddChild(t2);
            Assert.AreEqual(t, t2.Parent);
        }
コード例 #9
0
ファイル: Program.cs プロジェクト: komunre/btag
        static void Main(string[] args)
        {
            Parser parser = new Parser();

            Writer writer = new Writer();

            var main       = new Tag("main");
            var first      = new Tag("first");
            var second     = new Tag("second");
            var subSecond  = new Tag("subsecond");
            var third      = new Tag("third");
            var subSecond2 = new Tag("subsecond2");
            var deeper     = new Tag("deeper");

            second.value     = new byte[] { 0x62, 0x69, 0x67, 0x20, 0x74, 0x65, 0x73, 0x74, 0x20, 0x28, 0x62, 0x69, 0x67, 0x29 };
            subSecond2.value = new byte[] { 0x02 };
            main.AddChild(first);
            main.AddChild(second);
            second.AddChild(subSecond);
            main.AddChild(third);
            second.AddChild(subSecond2);
            subSecond2.AddChild(deeper);

            writer.OpenStream("output2.btag");
            writer.WriteAll(main);
            writer.CloseStream();
            parser.OpenStream("output2.btag");
            var success2 = parser.Parse();

            if (!success2)
            {
                throw new Exception("No success.");
            }
            var mainLayer   = parser.FindTagLayerRoot("main");
            var secondLayer = parser.FindTagLayer(mainLayer, "second");

            Console.WriteLine(Encoding.Default.GetString(secondLayer.value));

            secondLayer.value = Encoding.Default.GetBytes("hello world");

            writer.OpenStream("output3.btag");
            writer.WriteAll(mainLayer);
            writer.CloseStream();
        }
コード例 #10
0
        private static void SerializeDictionary(Tag tag, IDictionary dictionary, string customItemName)
        {
            bool simpleType1 = false;

            foreach (object index in (IEnumerable)dictionary.Keys)
            {
                SdlSerializer.TryCoerce(index, out simpleType1);
                if (simpleType1)
                {
                    SdlSerializer.TryCoerce(dictionary[index], out simpleType1);
                    if (!simpleType1)
                    {
                        break;
                    }
                }
                else
                {
                    break;
                }
            }
            if (simpleType1)
            {
                foreach (object index1 in (IEnumerable)dictionary.Keys)
                {
                    bool   simpleType2;
                    string index2 = SdlSerializer.TryCoerce(index1, out simpleType2).ToString();
                    object obj    = SdlSerializer.TryCoerce(dictionary[index1], out simpleType2);
                    tag[index2] = obj;
                }
            }
            else
            {
                System.Type[] genericArguments = dictionary.GetType().GetGenericArguments();
                System.Type   type1            = genericArguments[0];
                System.Type   type2            = genericArguments[1];
                foreach (object index in (IEnumerable)dictionary.Keys)
                {
                    object instance = dictionary[index];
                    bool   simpleType2;
                    object obj  = SdlSerializer.TryCoerce(index, out simpleType2);
                    Tag    tag1 = new Tag(SdlSerializer.LowerCamelCase(customItemName ?? type2.Name));
                    tag.AddChild(tag1);
                    if (simpleType2)
                    {
                        tag1["key"] = obj;
                        SdlSerializer.SerializeInternal(instance, type2, tag1);
                    }
                    else
                    {
                        SdlSerializer.SerializeChild("key", index, type1, false, SdlSerializer.DefaultAttribute, tag1);
                        bool simpleType3;
                        SdlSerializer.SerializeChild("value", SdlSerializer.TryCoerce(instance, out simpleType3), type2, simpleType3, SdlSerializer.DefaultAttribute, tag1);
                    }
                }
            }
        }
コード例 #11
0
        public void SetUp() {
            p = new Tag("p");
            span = new Tag("span");

            LoggerFactory.GetInstance().SetLogger(new SysoLogger(3));
            p.CSS[CSS.Property.FONT_FAMILY] = "Helvetica";
            p.CSS[CSS.Property.FONT_SIZE] = "12pt";
            p.AddChild(span);
            span.Parent = p;
        }
コード例 #12
0
        private static void SerializeMatrix(Tag tag, Matrix matrix)
        {
            Tag tag1 = new Tag("content");

            tag.AddChild(tag1);
            SdlSerializer.AddValueList(tag1, (object)matrix.M11, (object)matrix.M12, (object)matrix.M13, (object)matrix.M14);
            Tag tag2 = new Tag("content");

            tag.AddChild(tag2);
            SdlSerializer.AddValueList(tag2, (object)matrix.M21, (object)matrix.M22, (object)matrix.M23, (object)matrix.M24);
            Tag tag3 = new Tag("content");

            tag.AddChild(tag3);
            SdlSerializer.AddValueList(tag3, (object)matrix.M31, (object)matrix.M32, (object)matrix.M33, (object)matrix.M34);
            Tag tag4 = new Tag("content");

            tag.AddChild(tag4);
            SdlSerializer.AddValueList(tag4, (object)matrix.M41, (object)matrix.M42, (object)matrix.M43, (object)matrix.M44);
        }
コード例 #13
0
        virtual public void SetUp()
        {
            p    = new Tag("p");
            span = new Tag("span");

            LoggerFactory.GetInstance().SetLogger(new SysoLogger(3));
            p.CSS[CSS.Property.FONT_FAMILY] = "Helvetica";
            p.CSS[CSS.Property.FONT_SIZE]   = "12pt";
            p.AddChild(span);
            span.Parent = p;
        }
コード例 #14
0
        virtual public void SetUp()
        {
            LoggerFactory.GetInstance().SetLogger(new SysoLogger(3));
            root  = new Tag("body");
            p     = new Tag("p");
            ul    = new Tag("ul");
            first = new Tag("li");
            last  = new Tag("li");

            single = new ListItem("Single");
            start  = new ListItem("Start");
            end    = new ListItem("End");

            listWithOne          = new List <IElement>();
            listWithTwo          = new List <IElement>();
            orderedUnorderedList = new OrderedUnorderedList();
            CssAppliersImpl cssAppliers = new CssAppliersImpl();

            orderedUnorderedList.SetCssAppliers(cssAppliers);
            workerContextImpl = new WorkerContextImpl();
            HtmlPipelineContext context2 = new HtmlPipelineContext(cssAppliers);

            workerContextImpl.Put(typeof(HtmlPipeline).FullName, context2);
            root.AddChild(p);
            root.AddChild(ul);
            ul.AddChild(first);
            ul.AddChild(last);
            p.CSS["font-size"]     = "12pt";
            p.CSS["margin-top"]    = "12pt";
            p.CSS["margin-bottom"] = "12pt";
            new ParagraphCssApplier(cssAppliers).Apply(new Paragraph("paragraph"), p, context2);
            first.CSS["margin-top"]     = "50pt";
            first.CSS["padding-top"]    = "25pt";
            first.CSS["margin-bottom"]  = "50pt";
            first.CSS["padding-bottom"] = "25pt";
            last.CSS["margin-bottom"]   = "50pt";
            last.CSS["padding-bottom"]  = "25pt";
            listWithOne.Add(single);
            listWithTwo.Add(start);
            listWithTwo.Add(end);
        }
コード例 #15
0
        virtual public void SetUp() {
            LoggerFactory.GetInstance().SetLogger(new SysoLogger(3));
            root = new Tag("body");
            p = new Tag("p");
            ul = new Tag("ul");
            first = new Tag("li");
            last = new Tag("li");

            single = new ListItem("Single");
            start = new ListItem("Start");
            end = new ListItem("End");

            listWithOne = new List<IElement>();
            listWithTwo = new List<IElement>();
            orderedUnorderedList = new OrderedUnorderedList();
            CssAppliersImpl cssAppliers = new CssAppliersImpl();
            orderedUnorderedList.SetCssAppliers(cssAppliers);
            workerContextImpl = new WorkerContextImpl();
            HtmlPipelineContext context2 = new HtmlPipelineContext(cssAppliers);
            workerContextImpl.Put(typeof (HtmlPipeline).FullName, context2);
            root.AddChild(p);
            root.AddChild(ul);
            ul.AddChild(first);
            ul.AddChild(last);
            p.CSS["font-size"] = "12pt";
            p.CSS["margin-top"] = "12pt";
            p.CSS["margin-bottom"] = "12pt";
            new ParagraphCssApplier(cssAppliers).Apply(new Paragraph("paragraph"), p, context2);
            first.CSS["margin-top"] = "50pt";
            first.CSS["padding-top"] = "25pt";
            first.CSS["margin-bottom"] = "50pt";
            first.CSS["padding-bottom"] = "25pt";
            last.CSS["margin-bottom"] = "50pt";
            last.CSS["padding-bottom"] = "25pt";
            listWithOne.Add(single);
            listWithTwo.Add(start);
            listWithTwo.Add(end);
        }
コード例 #16
0
        public void WriteAndParseEquality()
        {
            var main = new Tag("main");

            main.AddChild(new Tag("first"));
            var second = new Tag("second");

            second.AddChild(new Tag("testingDeep"));
            main.AddChild(second);
            main.AddChild(new Tag("third"));

            var writer = new Writer();

            writer.OpenStream("equality.btag");
            writer.WriteAll(main);
            writer.CloseStream();

            var parser = new Parser();

            parser.OpenStream("equality.btag");
            parser.Parse();
            Assert.IsTrue(main.ChildrenEquals(parser.FindTagLayerRoot("main")));
        }
コード例 #17
0
        virtual public void ResolveSpacingBeforeIs10()
        {
            parent.AddChild(second);
            first.CSS["margin-bottom"] = "12pt";
            second.CSS["margin-top"]   = "22pt";

            applier.Apply(firstPara, first, configuration);
            applier.Apply(secondPara, second, configuration);
            Assert.AreEqual(22 - 12, secondPara.SpacingBefore, 0);
        }
コード例 #18
0
        public void SetUp() {
            body = new Tag("body", new Dictionary<String, String>());
            table = new Tag("table", new Dictionary<String, String>());
            row = new Tag("tr", new Dictionary<String, String>());
            cell = new Tag("td", new Dictionary<String, String>());
            config = new HtmlPipelineContext(null);
            calc = new WidthCalculator();

            LoggerFactory.GetInstance().SetLogger(new SysoLogger(3));
            body.AddChild(table);
            table.Parent = body;
            table.AddChild(row);
            row.Parent = table;
            row.AddChild(cell);
            cell.Parent = row;
        }
コード例 #19
0
        virtual public void SetUp()
        {
            body   = new Tag("body", new Dictionary <String, String>());
            table  = new Tag("table", new Dictionary <String, String>());
            row    = new Tag("tr", new Dictionary <String, String>());
            cell   = new Tag("td", new Dictionary <String, String>());
            config = new HtmlPipelineContext(null);
            calc   = new WidthCalculator();

            LoggerFactory.GetInstance().SetLogger(new SysoLogger(3));
            body.AddChild(table);
            table.Parent = body;
            table.AddChild(row);
            row.Parent = table;
            row.AddChild(cell);
            cell.Parent = row;
        }
コード例 #20
0
 virtual public void TestSiblingAvailable1()
 {
     parent.AddChild(sibling1);
     parent.AddChild(sibling2);
     parent.AddChild(sibling3);
     Assert.AreEqual(sibling3, TagUtils.GetInstance().GetSibling(sibling2, 1));
 }
コード例 #21
0
ファイル: TagTest.cs プロジェクト: newlysoft/itextsharp
 virtual public void ValidateParentSetOnAdd() {
     Tag t = new Tag("pappie");
     Tag t2 = new Tag("baby");
     t.AddChild(t2);
     Assert.AreEqual(t, t2.Parent);
 }