コード例 #1
0
 public SvgClipPathMaskWriterVisitor(PageWriter writer, SvgMatrix rootTransform, PdfSpotColor spotColorOverride)
 {
     _spotColorOverride = spotColorOverride;
     _writer            = writer ?? throw new ArgumentNullException(nameof(writer));
     _matrixStack.Push(SvgMatrix.Identity);
     PushMatrix(rootTransform);
 }
コード例 #2
0
        public void GeneratesOutputForEachTypeFromTemplateWhenPatternUsed()
        {
            var generator   = MockRepository.GenerateMock <IOutputGenerator>();
            var writer      = MockRepository.GenerateStub <IOutputWriter>();
            var resolver    = MockRepository.GenerateStub <IPatternTemplateResolver>();
            var transformer = new PageWriter(generator, writer, resolver);
            var namespaces  = Namespaces("One", "Two");

            Type <First>(namespaces[0]);
            Type <Second>(namespaces[1]);

            resolver.Stub(x => x.Resolve(null, null))
            .IgnoreArguments()
            .Return(new List <TemplateMatch>
            {
                new TemplateMatch("One.First.htm", "!type.spark", new ViewData()),
                new TemplateMatch("Two.Second.htm", "!type.spark", new ViewData())
            });

            transformer.CreatePages("!type.spark", "", namespaces);

            generator.AssertWasCalled(
                x => x.Convert(Arg.Is("!type.spark"), Arg <ViewData> .Is.Anything, Arg <string> .Is.Anything),
                x => x.Repeat.Twice());
        }
コード例 #3
0
        public void WritesOutputForEachTypeToFileWhenPatternUsed()
        {
            var generator   = MockRepository.GenerateStub <IOutputGenerator>();
            var writer      = MockRepository.GenerateMock <IOutputWriter>();
            var resolver    = MockRepository.GenerateStub <IPatternTemplateResolver>();
            var transformer = new PageWriter(generator, writer, resolver);
            var namespaces  = Namespaces("One", "Two");

            Type <First>(namespaces[0]);
            Type <Second>(namespaces[1]);

            resolver.Stub(x => x.Resolve(null, null))
            .IgnoreArguments()
            .Return(new List <TemplateMatch>
            {
                new TemplateMatch("One.First.htm", "!type.spark", new ViewData()),
                new TemplateMatch("Two.Second.htm", "!type.spark", new ViewData())
            });

            generator.Stub(x => x.Convert(null, null, null))
            .IgnoreArguments()
            .Return("content");

            transformer.CreatePages("!type.spark", "output", namespaces);

            writer.AssertWasCalled(x => x.WriteFile("output\\One.First.htm", "content"));
            writer.AssertWasCalled(x => x.WriteFile("output\\Two.Second.htm", "content"));
        }
コード例 #4
0
ファイル: CustomPath.cs プロジェクト: jakedacatman/SVGSharpie
        public override void Draw(PageWriter writer)
        {
            PrepareDrawState(writer, out var hasFill, out var hasStroke);
            var lastCommandIsClose = DrawSubPathsUntilLastClose(writer);

            Paint(writer, ClosePath || lastCommandIsClose, FillRuleEvenOdd, hasFill, hasStroke);
        }
コード例 #5
0
        void generatePage(SiteWriter siteWriter, IPage page)
        {
            var writer = new PageWriter(siteWriter, page);
            var html   = _pageTemplate.generateHTML(writer);

            page.writePage(writer, html);
        }
コード例 #6
0
        public void TransformsTemplateInDirectoriesWithNamespacePattern()
        {
            var generator   = MockRepository.GenerateStub <IOutputGenerator>();
            var writer      = MockRepository.GenerateMock <IOutputWriter>();
            var resolver    = MockRepository.GenerateStub <IPatternTemplateResolver>();
            var transformer = new PageWriter(generator, writer, resolver);
            var namespaces  = Namespaces("One", "Two");

            resolver.Stub(x => x.Resolve(null, null))
            .IgnoreArguments()
            .Return(new List <TemplateMatch>
            {
                new TemplateMatch("One\\template.htm", "!namespace\\template.spark", new ViewData()),
                new TemplateMatch("Two\\template.htm", "!namespace\\template.spark", new ViewData())
            });

            writer.Stub(x => x.Exists(null))
            .IgnoreArguments()
            .Return(false);

            generator.Stub(x => x.Convert(null, null, null))
            .IgnoreArguments()
            .Return("content");

            transformer.CreatePages("!namespace\\template.spark", "output", namespaces);

            writer.AssertWasCalled(x => x.CreateDirectory("output\\One"));
            writer.AssertWasCalled(x => x.WriteFile("output\\One\\template.htm", "content"));
            writer.AssertWasCalled(x => x.CreateDirectory("output\\Two"));
            writer.AssertWasCalled(x => x.WriteFile("output\\Two\\template.htm", "content"));
        }
コード例 #7
0
        public override void Draw(PageWriter writer)
        {
            var svg = SvgDocument.RootElement;

            if (svg == null)
            {
                return;
            }

            var svgWidth  = svg.ViewBox?.Width ?? (svg.Width ?? 0);
            var svgHeight = svg.ViewBox?.Height ?? (svg.Height ?? Height);   // as per spec height defaults to 100%

            if (svgWidth <= 0 || svgHeight <= 0)
            {
                return;
            }

            var viewport      = new VectorElementPdfPageViewport(svgWidth, svgHeight, X, Y, Width, Height, ContentHorizontalAlignment, ContentVerticalAlignment);
            var pagePlacement = viewport.PagePlacement;
            var container     = new TransformationGroup(pagePlacement.X, pagePlacement.Y, Width, Height)
            {
                ScaleX = viewport.ScaleX,
                ScaleY = viewport.ScaleY
            };

            var pageHeight = writer.Page.Dimensions.Height;

            container.Add(svg.Accept(new SvgElementToDynamicPdfElementConverter(svg, viewport, pageHeight, SpotColorOveride)));
            container.Draw(writer);
        }
コード例 #8
0
        public string postProcess(PageWriter writer, string xml)
        {
            bool anyModulesReplaced;
            var document = ExtractHTML.loadHTML(xml);
            do
            {
                anyModulesReplaced = false;
                var references = findModuleReferences(document).ToArray();

                foreach (var reference in references)
                {
                    var moduleName = reference.URI.LocalPath;
                    var template = resolveModuleTemplate(writer.Site, moduleName);

                    var parameters = ModuleParameters.fromReference(reference);
                    var moduleContext = new ModuleContext(writer, parameters);
                    var moduleHTML = "<root>" + template.generateHTML(moduleContext) + "</root>";
                    var moduleDocument = ExtractHTML.loadWithoutDTD(moduleHTML);
                    reference.expand(moduleDocument.DocumentElement.ChildNodes);

                    anyModulesReplaced = true;
                }

            } while (anyModulesReplaced);

            return XHTMLWriter.writeStrict(document);
        }
コード例 #9
0
        public void when_template_directory_set_propagate_change_to_the_output_generator()
        {
            var generator   = MockRepository.GenerateStub <IOutputGenerator>();
            var writer      = MockRepository.GenerateMock <IOutputWriter>();
            var resolver    = MockRepository.GenerateStub <IPatternTemplateResolver>();
            var transformer = new PageWriter(generator, writer, resolver);

            transformer.SetTemplatePath("someTemplatePath");
            generator.AssertWasCalled(g => g.SetTemplatePath("someTemplatePath"));
        }
コード例 #10
0
ファイル: CustomPath.cs プロジェクト: jakedacatman/SVGSharpie
 private static void Paint(PageWriter writer, bool close, bool ruleEvenOdd, bool fill, bool stroke)
 {
     if (ruleEvenOdd)
     {
         PaintEvenOdd(writer, close, fill, stroke);
     }
     else
     {
         PaintNonZero(writer, close, fill, stroke);
     }
 }
コード例 #11
0
ファイル: Tag.cs プロジェクト: niemyjski/GraffitiCMS
        public static void WritePage(string name)
        {
            PageTemplateToolboxContext templateContext = new PageTemplateToolboxContext();

            templateContext.Put("tag", name);
            templateContext.Put("MetaDescription", "Posts and articles tagged as " + name);
            templateContext.Put("MetaKeywords", name);


            PageWriter.Write("tag.view", "~/tags/" + name + "/" + Util.DEFAULT_PAGE, templateContext);
            PageWriter.Write("tagrss.view", "~/tags/" + name + "/feed/" + Util.DEFAULT_PAGE, templateContext);
        }
コード例 #12
0
ファイル: CustomPath.cs プロジェクト: jakedacatman/SVGSharpie
 /// <summary>
 /// Draws subpaths until the last close command, returns true if the last sub path was a close command.
 /// </summary>
 private bool DrawSubPathsUntilLastClose(PageWriter writer)
 {
     writer.Write_m_(X, Y);
     for (var i = 0; i < SubPaths.Count; i++)
     {
         var subPath = SubPaths[i];
         if (subPath is CloseSubPath && i == SubPaths.Count - 1)
         {
             return(true);
         }
         subPath.Draw(writer);
     }
     return(false);
 }
コード例 #13
0
        public override void writePage(PageWriter writer, string html)
        {
            var siteWriter = writer.SiteWriter;

            var top = ExtractHTML.byId(html, TopId);
            var bottom = ExtractHTML.byId(html, BottomId);

            var contentPath = Path.Combine(Id, "wp-content");
            var themePath = Path.Combine(contentPath, "themes");
            var thisThemePath = Path.Combine(themePath, _themeName);

            siteWriter.writeText(Path.Combine(thisThemePath, TopId) + ".html", top);
            siteWriter.writeText(Path.Combine(thisThemePath, BottomId) + ".html", bottom);

            var header = ExtractHTML.contentOfElement(html, "head");
            siteWriter.writeText(Path.Combine(thisThemePath, Head + ".html" ), header);
        }
コード例 #14
0
        public override void Draw(PageWriter writer)
        {
            //
            // See "4.4.3 Clipping Path Operators" (pg. 234, PDF Reference 1.7)
            //

            writer.Write_q_();

            writer.Write_m_((float)_xMin, (float)_yMin);
            writer.Write_l_((float)_xMax, (float)_yMin);
            writer.Write_l_((float)_xMax, (float)_yMax);
            writer.Write_l_((float)_xMin, (float)_yMax);

            writer.Write_W();
            writer.Write_n();
            base.Draw(writer);
            writer.Write_Q();
        }
コード例 #15
0
        public override void writePage(PageWriter writer, string html)
        {
            var siteWriter = writer.SiteWriter;

            var top    = ExtractHTML.byId(html, TopId);
            var bottom = ExtractHTML.byId(html, BottomId);

            var contentPath   = Path.Combine(Id, "wp-content");
            var themePath     = Path.Combine(contentPath, "themes");
            var thisThemePath = Path.Combine(themePath, _themeName);

            siteWriter.writeText(Path.Combine(thisThemePath, TopId) + ".html", top);
            siteWriter.writeText(Path.Combine(thisThemePath, BottomId) + ".html", bottom);

            var header = ExtractHTML.contentOfElement(html, "head");

            siteWriter.writeText(Path.Combine(thisThemePath, Head + ".html"), header);
        }
コード例 #16
0
        public void GeneratesOutputFromTemplate()
        {
            var generator   = MockRepository.GenerateMock <IOutputGenerator>();
            var writer      = MockRepository.GenerateStub <IOutputWriter>();
            var resolver    = MockRepository.GenerateStub <IPatternTemplateResolver>();
            var transformer = new PageWriter(generator, writer, resolver);
            var namespaces  = new Namespace[0];

            resolver.Stub(x => x.Resolve(null, null))
            .IgnoreArguments()
            .Return(new List <TemplateMatch> {
                new TemplateMatch("simple.htm", "simple.spark", new ViewData())
            });

            transformer.CreatePages("simple.spark", "", namespaces);

            generator.AssertWasCalled(
                x => x.Convert(Arg.Is("simple.spark"), Arg <ViewData> .Is.Anything, Arg <string> .Is.Anything));
        }
コード例 #17
0
        public override void Draw(PageWriter writer)
        {
            if (_clipPath.Children.Count == 0)
            {
                // clipPath defines the area to be rendered, no children, nothing to render
                return;
            }

            writer.Write_q_();
            {
                var clippingAreaWriter = new SvgClipPathMaskWriterVisitor(writer, _clipPathParentTransform, _spotColorOverride);
                _clipPath.Accept(clippingAreaWriter);
                if (clippingAreaWriter.ClippingAreaPainted)
                {
                    _child.Draw(writer);
                }
            }
            writer.Write_Q();
        }
コード例 #18
0
ファイル: CustomPath.cs プロジェクト: jakedacatman/SVGSharpie
 private void PrepareDrawState(PageWriter writer, out bool fill, out bool stroke)
 {
     if (FillColor != null || LineColor != null)
     {
         writer.SetGraphicsMode();
     }
     if (LineWidth > 0 && FillColor != null)
     {
         writer.SetLineWidth(LineWidth);
         writer.SetStrokeColor(LineColor);
         writer.SetLineStyle(LineStyle);
         writer.SetFillColor(FillColor);
         fill = stroke = true;
     }
     else if (LineWidth > 0)
     {
         writer.SetLineWidth(LineWidth);
         writer.SetStrokeColor(LineColor);
         writer.SetLineStyle(LineStyle);
         stroke = true;
         fill   = false;
     }
     else if (FillColor != null)
     {
         writer.SetFillColor(FillColor);
         fill   = true;
         stroke = false;
     }
     else
     {
         fill = stroke = false;
         return;
     }
     if (LineStyle == LineStyle.None)
     {
         stroke = false;
     }
     writer.SetLineCap(LineCap);
     writer.SetLineJoin(LineJoin);
     writer.SetMiterLimit(MiterLimit);
 }
コード例 #19
0
        public void TransformsTemplatesInDirectories()
        {
            var generator   = MockRepository.GenerateStub <IOutputGenerator>();
            var writer      = MockRepository.GenerateMock <IOutputWriter>();
            var resolver    = MockRepository.GenerateStub <IPatternTemplateResolver>();
            var transformer = new PageWriter(generator, writer, resolver);
            var namespaces  = new Namespace[0];

            resolver.Stub(x => x.Resolve(null, null))
            .IgnoreArguments()
            .Return(new List <TemplateMatch> {
                new TemplateMatch("directory\\test.htm", "", new ViewData())
            });
            generator.Stub(x => x.Convert(null, null, null))
            .IgnoreArguments()
            .Return("content");

            transformer.CreatePages("directory\\test.spark", "output", namespaces);

            writer.AssertWasCalled(x => x.WriteFile("output\\directory\\test.htm", "content"));
        }
コード例 #20
0
        public void when_template_directory_set_exclude_directory_from_output()
        {
            var generator   = MockRepository.GenerateStub <IOutputGenerator>();
            var writer      = MockRepository.GenerateMock <IOutputWriter>();
            var resolver    = MockRepository.GenerateStub <IPatternTemplateResolver>();
            var transformer = new PageWriter(generator, writer, resolver);
            var namespaces  = new Namespace[0];

            resolver.Stub(x => x.Resolve(null, null))
            .IgnoreArguments()
            .Return(new List <TemplateMatch> {
                new TemplateMatch("someTemplatePath\\simple.htm", "someTemplatePath\\simple.spark", new ViewData())
            });

            generator.Stub(x => x.Convert(null, null, null))
            .IgnoreArguments()
            .Return("content");

            transformer.SetTemplatePath("someTemplatePath");
            transformer.CreatePages("someTemplatePath\\simple.spark", "output", namespaces);

            writer.AssertWasCalled(x => x.WriteFile("output\\simple.htm", "content"));
        }
コード例 #21
0
ファイル: CustomPath.cs プロジェクト: jakedacatman/SVGSharpie
 private static void PaintEvenOdd(PageWriter writer, bool close, bool fill, bool stroke)
 {
     if (close)
     {
         if (fill)
         {
             if (stroke)
             {
                 writer.Write_bx_();
             }
             else
             {
                 writer.Write_fx();
             }
         }
         else if (stroke)
         {
             writer.Write_s_();
         }
     }
     else if (fill)
     {
         if (stroke)
         {
             writer.Write_Bx();
         }
         else
         {
             writer.Write_fx();
         }
     }
     else if (stroke)
     {
         writer.Write_S();
     }
 }
コード例 #22
0
ファイル: CustomPath.cs プロジェクト: jakedacatman/SVGSharpie
 private static void PaintNonZero(PageWriter writer, bool close, bool fill, bool stroke)
 {
     if (close)
     {
         if (fill)
         {
             if (stroke)
             {
                 writer.Write_b_();
             }
             else
             {
                 writer.Write_f();
             }
         }
         else if (stroke)
         {
             writer.Write_s_();
         }
     }
     else if (fill)
     {
         if (stroke)
         {
             writer.Write_B();
         }
         else
         {
             writer.Write_f();
         }
     }
     else if (stroke)
     {
         writer.Write_S();
     }
 }
コード例 #23
0
ファイル: SiteWriter.cs プロジェクト: pragmatrix/SiteSharper
 public string postProcess(PageWriter pageWriter, string html)
 {
     return _moduleProcessor.postProcess(pageWriter, html);
 }
コード例 #24
0
 public override void Draw(PageWriter writer)
 {
     writer.Write_m_(X, Y);
 }
コード例 #25
0
ファイル: CloseSubPath.cs プロジェクト: luaxlab/SVGSharpie
 public override void Draw(PageWriter writer) => writer.Write_h();
コード例 #26
0
ファイル: Page.cs プロジェクト: pragmatrix/SiteSharper
 public virtual void writePage(PageWriter writer, string html)
 {
     writer.writePage(html);
 }
コード例 #27
0
 public ModuleContext(PageWriter page, dynamic parameters)
 {
     _page      = page;
     Parameters = parameters;
 }
コード例 #28
0
 public ModuleContext(PageWriter page, dynamic parameters)
 {
     _page = page;
     Parameters = parameters;
 }
コード例 #29
0
ファイル: Page.cs プロジェクト: pragmatrix/SiteSharper
 public virtual void writePage(PageWriter writer, string html)
 {
     writer.writePage(html);
 }
コード例 #30
0
 void generatePage(SiteWriter siteWriter, IPage page)
 {
     var writer = new PageWriter(siteWriter, page);
     var html = _pageTemplate.generateHTML(writer);
     page.writePage(writer, html);
 }