Пример #1
0
        public Task Generate(bool overlay = true)
        {
            return(Task.Run(() =>
            {
                Repository.InitPaths();
                PdfFontFactory.RegisterDirectory(Repository.FontPath);
                var registeredFonts = PdfFontFactory.GetRegisteredFonts();
                var registeredFamilies = PdfFontFactory.GetRegisteredFamilies();

                var templateFile = overlay? Repository.GetOverlayTemplateFile(Card.Faction.Name, Card.Type.Name) :
                                   Repository.GetTemplateFile(Card.Faction.Name, Card.Type.Name);

                if (!File.Exists(templateFile))
                {
                    throw new Exception("Template could not be found");
                }

                XDocument svg;
                try
                {
                    // load svg for template
                    svg = XDocument.Load(templateFile);
                    // find the overlay root
                    Overlay = svg.Root.Elements(NS + "g").Single(x => x.Attribute("id").Value == "overlaylayer");
                }
                catch (Exception e)
                {
                    throw new Exception("Template could not be loaded", e);
                }

                // apply card information to svg template
                if (Template.ShowName)
                {
                    SetName();
                }
                if (Template.ShowType)
                {
                    SetType();
                }
                if (Template.ShowGoldCost)
                {
                    SetGoldCost();
                }
                if (Template.ShowLoyalty)
                {
                    SetLoyalty();
                }
                if (Template.ShowText)
                {
                    SetText();
                }
                if (Template.ShowAttack)
                {
                    SetAttack();
                }
                if (Template.ShowDefense)
                {
                    SetDefense();
                }
                if (Template.ShowDiscipline)
                {
                    SetDiscipline();
                }
                if (Template.ShowArt)
                {
                    SetArt();
                }
                if (Template.ShowInfo)
                {
                    SetInfo();
                }

                // write svg
                var svgFile = overlay? Repository.GetOverlaySvgFile(Card.Guid) : Repository.GetSvgFile(Card.Guid);

                File.WriteAllText(svgFile, svg.ToString());

                // write json
                string cardString = JsonConvert.SerializeObject(Card, Formatting.Indented);
                File.WriteAllText(Repository.GetJsonFile(Card.Guid), cardString);

                if (!overlay)
                {
                    var merge = XDocument.Parse("<svg version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\" height=\"340.15747\" width=\"244.48819\" xmlns:xlink=\"http://www.w3.org/1999/xlink\"></svg>");
                    var border = XDocument.Load(Repository.GetPrintBorderFile(Card.Faction.Name, Card.Type.Name, "svg"));
                    border.Root.SetAttributeValue("height", "340.15747");
                    border.Root.SetAttributeValue("width", "244.48819");
                    border.Root.SetAttributeValue("y", "0");
                    border.Root.SetAttributeValue("x", "0");
                    merge.Root.Add(border.Root);

                    svg.Root.SetAttributeValue("height", "325.98425");
                    svg.Root.SetAttributeValue("width", "230.31496");
                    svg.Root.SetAttributeValue("y", "7.0866184");
                    svg.Root.SetAttributeValue("x", "7.0866184");
                    merge.Root.Add(svg.Root);


                    File.WriteAllText(Repository.GetPrintSvgFile(Card.Guid), merge.ToString());
                }
            }));
        }