public SvgClipPathMaskWriterVisitor(PageWriter writer, SvgMatrix rootTransform, PdfSpotColor spotColorOverride) { _spotColorOverride = spotColorOverride; _writer = writer ?? throw new ArgumentNullException(nameof(writer)); _matrixStack.Push(SvgMatrix.Identity); PushMatrix(rootTransform); }
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()); }
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")); }
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); }
void generatePage(SiteWriter siteWriter, IPage page) { var writer = new PageWriter(siteWriter, page); var html = _pageTemplate.generateHTML(writer); page.writePage(writer, html); }
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")); }
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); }
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); }
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")); }
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); } }
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); }
/// <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); }
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); }
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(); }
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); }
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)); }
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(); }
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); }
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")); }
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")); }
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(); } }
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(); } }
public string postProcess(PageWriter pageWriter, string html) { return _moduleProcessor.postProcess(pageWriter, html); }
public override void Draw(PageWriter writer) { writer.Write_m_(X, Y); }
public override void Draw(PageWriter writer) => writer.Write_h();
public virtual void writePage(PageWriter writer, string html) { writer.writePage(html); }
public ModuleContext(PageWriter page, dynamic parameters) { _page = page; Parameters = parameters; }