Esempio n. 1
0
        internal void Parse(XmlReader reader)
        {
            int buflen = 500;

            char[] buffer = new char[buflen];
            try
            {
                object nsuri = reader.NameTable.Add("http://www.w3.org/2000/xmlns/");

                FonetDriver.ActiveDriver.FireFonetInfo("Building formatting object tree");
                streamRenderer.StartRenderer();

                while (reader.Read())
                {
                    switch (reader.NodeType)
                    {
                    case XmlNodeType.Element:
                        Attributes atts = new Attributes();
                        while (reader.MoveToNextAttribute())
                        {
                            if (!reader.NamespaceURI.Equals(nsuri))
                            {
                                SaxAttribute newAtt = new SaxAttribute();
                                newAtt.Name         = reader.Name;
                                newAtt.NamespaceURI = reader.NamespaceURI;
                                newAtt.Value        = reader.Value;
                                atts.attArray.Add(newAtt);
                            }
                        }
                        reader.MoveToElement();
                        StartElement(reader.NamespaceURI, reader.LocalName, atts.TrimArray());
                        if (reader.IsEmptyElement)
                        {
                            EndElement();
                        }
                        break;

                    case XmlNodeType.EndElement:
                        EndElement();
                        break;

                    case XmlNodeType.Text:
                        char[] chars = reader.ReadString().ToCharArray();
                        if (currentFObj != null)
                        {
                            currentFObj.AddCharacters(chars, 0, chars.Length);
                        }
                        if (reader.NodeType == XmlNodeType.Element)
                        {
                            goto case XmlNodeType.Element;
                        }
                        if (reader.NodeType == XmlNodeType.EndElement)
                        {
                            goto case XmlNodeType.EndElement;
                        }
                        break;

                    default:
                        break;
                    }
                }
                FonetDriver.ActiveDriver.FireFonetInfo("Parsing of document complete, stopping renderer");
                streamRenderer.StopRenderer();
            }
            catch (Exception exception)
            {
                FonetDriver.ActiveDriver.FireFonetError(exception.ToString());
            }
            finally
            {
                if (reader.ReadState != ReadState.Closed)
                {
                    reader.Close();
                }
            }
        }
Esempio n. 2
0
        internal void Parse(PixelFarm.Drawing.Pdf.MyPdfDocument doc)
        {
            //TEST CODE ONLY ***

            var root_maker = Root.GetMaker();
            //
            var layout_master_set_maker = LayoutMasterSet.GetMaker();
            var simplpe_page_master     = SimplePageMaster.GetMaker();
            var region_body             = RegionBody.GetMaker();
            var region_before           = RegionBefore.GetMaker();
            var region_after            = RegionAfter.GetMaker();

            //
            var pageSeq_maker = PageSequence.GetMaker();
            var flow_maker    = Flow.Flow.GetMaker();
            var block_maker   = Flow.Block.GetMaker();


            string nsuri = "http://www.w3.org/1999/XSL/Format";

            streamRenderer.StartRenderer();

            //1. root
            Root rootObj = CreateAndAppend <Root>(null,
                                                  root_maker,
                                                  nsuri,
                                                  "root",
                                                  CreateAttributes());
            //2.
            LayoutMasterSet masterSet = CreateAndAppend(rootObj, layout_master_set_maker, nsuri,
                                                        "layout-master-set",
                                                        CreateAttributes());
            {
                SimplePageMaster simpleMaster = CreateAndAppend(
                    masterSet, simplpe_page_master, nsuri,
                    "simple-page-master",
                    CreateAttributes(
                        new AttrKeyValue("master-name", "simple"),
                        new AttrKeyValue("page-height", "29.7cm"),
                        new AttrKeyValue("margin-top", "1cm"),
                        new AttrKeyValue("margin-bottom", "2cm"),
                        new AttrKeyValue("margin-left", "2.5cm"),
                        new AttrKeyValue("margin-right", "2.5cm")
                        ));
                RegionBody rgnBody = CreateAndAppend(simpleMaster, region_body, nsuri, "region-body",
                                                     CreateAttributes(new AttrKeyValue("margin-top", "3cm")));
                RegionBefore rgnBefore = CreateAndAppend(simpleMaster, region_before, nsuri, "region-before",
                                                         CreateAttributes(new AttrKeyValue("extent", "3cm")));
                RegionAfter rgnAfter = CreateAndAppend(simpleMaster, region_after, nsuri, "region-after",
                                                       CreateAttributes(new AttrKeyValue("extent", "1.5cm")));
                simpleMaster.End();
            }

            List <PixelFarm.Drawing.Pdf.MyPdfPage> pages = doc.Pages;
            int page_count = pages.Count;

            for (int i = 0; i < page_count; ++i)
            {
                PixelFarm.Drawing.Pdf.MyPdfPage   p      = pages[i];
                PixelFarm.Drawing.Pdf.MyPdfCanvas canvas = p.Canvas;

                PageSequence page_seq = CreateAndAppend(rootObj, pageSeq_maker, nsuri, "page-sequence",
                                                        CreateAttributes(new AttrKeyValue("master-reference", "simple")));

                Flow.Flow flow_obj = CreateAndAppend(page_seq, flow_maker, nsuri, "flow",
                                                     CreateAttributes(new AttrKeyValue("flow-name", "xsl-region-body")));

                Flow.Block block_obj = CreateAndAppend(
                    flow_obj, block_maker, nsuri, "block",
                    CreateAttributes(new AttrKeyValue("font-size", "18pt"),
                                     new AttrKeyValue("color", "black"),
                                     new AttrKeyValue("text-align", "center")
                                     ));

                //very simple
                List <PixelFarm.Drawing.Pdf.MyPdfTextBlock> textElems = canvas.TextElems;
                //first sample ,

                int elem_count = textElems.Count;
                for (int n = 0; n < elem_count; ++n)
                {
                    PixelFarm.Drawing.Pdf.MyPdfTextBlock textBlock = textElems[n];
                    string txt = textBlock.Text;
                    //
                    char[] charBuff = txt.ToCharArray();
                    block_obj.AddCharacters(charBuff, 0, charBuff.Length);
                }

                streamRenderer.Render(page_seq);
            }
            FonetDriver.ActiveDriver.FireFonetInfo("Parsing of document complete, stopping renderer");
            streamRenderer.StopRenderer();
        }