Пример #1
0
        private void DrawSimulatedDiv(PdfPage page, IDictionary <int, Object> styles, float[] margins, bool drawBackground
                                      )
        {
            Div pageBordersSimulation;

            pageBordersSimulation = new Div().SetFillAvailableArea(true);
            foreach (KeyValuePair <int, Object> entry in styles)
            {
                if ((entry.Key == Property.BACKGROUND || entry.Key == Property.BACKGROUND_IMAGE) && !drawBackground)
                {
                    continue;
                }
                pageBordersSimulation.SetProperty(entry.Key, entry.Value);
            }
            pageBordersSimulation.GetAccessibilityProperties().SetRole(StandardRoles.ARTIFACT);
            iText.Layout.Canvas canvas = new Canvas(new PdfCanvas(page), page.GetDocument(), page.GetTrimBox().ApplyMargins
                                                        (margins[0], margins[1], margins[2], margins[3], false));
            canvas.EnableAutoTagging(page);
            canvas.Add(pageBordersSimulation);
            canvas.Close();
        }
Пример #2
0
            public virtual void HandleEvent(Event currentEvent)
            {
                if (MainWindow.activeWorkspace.LogoImg == null)
                {
                    return;
                }

                PdfDocumentEvent docEvent = (PdfDocumentEvent)currentEvent;
                PdfDocument      pdf      = docEvent.GetDocument();

                PdfPage   page     = docEvent.GetPage();
                Rectangle pageSize = page.GetPageSize().ApplyMargins(10, 30, 0, 30, false);

                Canvas canvas = new Canvas(new PdfCanvas(page), pdf, pageSize);

                canvas.SetHorizontalAlignment(HorizontalAlignment.LEFT);
                var logo = new Image(ImageDataFactory.Create(MainWindow.activeWorkspace.LogoImg));

                canvas.Add(logo.SetMaxHeight(50));
                canvas.Close();
            }
Пример #3
0
        async Task OnShown()
        {
            await Add(MainPhone = new Canvas().MiddleAlign().CenterAlign().On(x => x.Panning, p => OnPanning(p)));

            await MainPhone.Add(Title);

            await MainPhone.Add(Description);

            await MainPhone.Add(AccelerometerInfo);

            await MainPhone.Add(GyroscopeInfo);

            await MainPhone.Add(CompassInfo);

            await MainPhone.Add(CreatePhone("Device.png").MiddleAlign().CenterAlign());
        }
Пример #4
0
        private void ManipulatePdf(String dest)
        {
            PdfDocument pdfDoc = new PdfDocument(new PdfWriter(dest));
            Table       table  = new Table(UnitValue.CreatePercentArray(15));

            table.SetWidth(1500);

            for (int r = 'A'; r <= 'Z'; r++)
            {
                for (int c = 1; c <= 15; c++)
                {
                    Cell cell = new Cell();
                    cell.SetMinHeight(45);
                    cell.Add(new Paragraph(((char)r).ToString() + c));
                    table.AddCell(cell);
                }
            }

            PdfFormXObject tableTemplate = new PdfFormXObject(new Rectangle(1500, 1300));
            Canvas         canvas        = new Canvas(tableTemplate, pdfDoc);

            canvas.Add(table);

            for (int j = 0; j < 1500; j += 500)
            {
                for (int i = 1300; i > 0; i -= 650)
                {
                    PdfFormXObject clip = new PdfFormXObject(new Rectangle(500, 650));

                    // add xObject to another xObject of shorter sizes
                    new PdfCanvas(clip, pdfDoc).AddXObjectAt(tableTemplate, -j, 650 - i);

                    // add xObject to the document
                    new PdfCanvas(pdfDoc.AddNewPage()).AddXObjectAt(clip, 36, 156);
                }
            }

            pdfDoc.Close();
        }
        public override void DrawCharacterInBounds(char character, MusicFontStyles fontStyle, Point location, Size size, Color color, Model.MusicalSymbol owner)
        {
            if (!EnsureProperPage(owner))
            {
                return;
            }
            if (Settings.RenderingMode != ScoreRenderingModes.Panorama && !TypedSettings.IgnorePageMargins)
            {
                location = location.Translate(CurrentScore.DefaultPageSettings);
            }

            var element = GetTextElement(character.ToString(), fontStyle, new Point(0, 0), color, owner);
            var svg     = new XElement("svg",
                                       new XAttribute("x", location.X.ToStringInvariant()),
                                       new XAttribute("y", location.Y.ToStringInvariant()),
                                       new XAttribute("width", size.Width.ToStringInvariant()),
                                       new XAttribute("height", size.Height.ToStringInvariant()),
                                       new XAttribute("viewBox", $"0 0 {size.Width.ToStringInvariant()} {size.Height.ToStringInvariant()}"));

            svg.Add(element);

            //element.SetAttributeValue(XName.Get("viewBox"), $"0 0 {size.Width.ToStringInvariant()} {size.Height.ToStringInvariant()}");

            if (location.Y < ClippedAreaY)
            {
                ClippedAreaY = location.Y;
            }
            if (location.X > ActualWidth)
            {
                ActualWidth = location.X;
            }
            if (location.Y > ActualHeight)
            {
                ActualHeight = location.Y;
            }

            Canvas.Add(svg);
        }
    public override void Start()
    {
        HasTackled  = 0;
        Owngoal     = 0;
        GoalsScored = 0;
        if (Team == null || Team.TeamType == TEAM_TYPE.TEAM_SPECTATOR || Team.TeamType == TEAM_TYPE.UNASSIGNED)
        {
            gameObject.SetActive(false);
        }

        nameCanvas      = CameraMaster.instance.Camera.AddCanvas();
        text            = nameCanvas.Add("");
        text.font       = NameFont;
        text.scale      = new Vector2(0.05f);
        text.origin     = new Vector2(0.5f, 0.5f);
        nameCanvas.is3D = true;
        if (isOwner)
        {
            PlayerName = CameraMaster.instance.GetPlayerName();
        }

        UpdateHat(_HatIndex);
    }
Пример #7
0
        public void RepeatRotateLayerTest()
        {
            Canvas expected = new Canvas(100, 100, "white");
            expected.Layers.Add(new Layer { Rotate = 0, Offset = new Vertex(50, 50) });
            expected.Add(new CircleShape(0, -20, 5, "red"));
            expected.Layers.Add(new Layer{ Rotate = 30, Offset = new Vertex(50, 50) });
            expected.Add(new CircleShape(0, -20, 5, "red"));
            expected.Layers.Add(new Layer { Rotate = 60, Offset = new Vertex(50, 50) });
            expected.Add(new CircleShape(0, -20, 5, "red"));
            expected.Layers.Add(new Layer { Rotate = 90, Offset = new Vertex(50, 50) });
            expected.Add(new CircleShape(0, -20, 5, "red"));
            expected.Layers.Add(new Layer { Rotate = 120, Offset = new Vertex(50, 50) });
            expected.Add(new CircleShape(0, -20, 5, "red"));
            expected.Layers.Add(new Layer { Rotate = 150, Offset = new Vertex(50, 50) });
            expected.Add(new CircleShape(0, -20, 5, "red"));
            expected.Layers.Add(new Layer { Rotate = 180, Offset = new Vertex(50, 50) });
            expected.Add(new CircleShape(0, -20, 5, "red"));

            Canvas actual = new Canvas(100, 100, "white");
            actual.Layers.Add(new RotateRepeatLayer { RepeatCount = 7, RepeatRotate = 30, Offset = new Vertex(50, 50) });
            actual.Add(new CircleShape(0, -20, 5, "red"));

            AssertBitmapsAreEqual(expected.Render(), actual.Render());
        }
Пример #8
0
        private static void Main(string[] args)
        {
            var squareWidget = new SquareWidget(10, 10)
            {
                Size = 1600
            };
            var circleWidget = new CircleWidget(100, 100)
            {
                Size = 20
            };
            var ellipseWidget = new EllipseWidget(50, 50)
            {
                HorizontalDiameter = 30, VerticalDiameter = 30, Size = 6283
            };
            var rectangleWidget = new RectangleWidget(70, 30)
            {
                Height = 4, Width = 8, Size = 32
            };
            var textBoxWithBackgroundColourWidget = new TextBoxWidget(20, 90)
            {
                Height = 6, Width = 24, Size = 144, Text = "Sample text", BackgroundColour = "Blue"
            };
            var textBoxWithDefaultBackgroundColour = new TextBoxWidget(30, 150)
            {
                Height = 6, Width = 24, Size = 144, Text = "Sample text with default colour"
            };

            var canvas = new Canvas();

            canvas.Add(squareWidget);
            canvas.Add(circleWidget);
            canvas.Add(ellipseWidget);
            canvas.Add(rectangleWidget);
            canvas.Add(textBoxWithBackgroundColourWidget);
            canvas.Add(textBoxWithDefaultBackgroundColour);

            canvas.PrintCanvas();
            Console.ReadKey();
        }
Пример #9
0
        public void CountIfTest()
        {
            test = new Canvas();
            test.Add(new Pentagon()
            {
                Opacity = 0.8
            });
            test.Add(new Vertex());
            test.Add(new Vertex());
            test.Add(new Pentagon()
            {
                Opacity = 0.6
            });
            test.Add(new Pentagon()
            {
                Opacity = 0.4
            });
            test.Add(new Pentagon());

            Assert.AreEqual(2, test.CountIf((s) => s is Vertex));
            Assert.AreEqual(4, test.CountIf((s) => s is Pentagon));
            Assert.AreEqual(2, test.CountIf((s) => s is Pentagon && ((Pentagon)s).Opacity > 0.5));
        }
        public override void DrawBezier(Point p1, Point p2, Point p3, Point p4, Pen pen, Model.MusicalSymbol owner)
        {
            if (!EnsureProperPage(owner))
            {
                return;
            }
            if (Settings.RenderingMode != ScoreRenderingModes.Panorama && !TypedSettings.IgnorePageMargins)
            {
                p1 = p1.Translate(CurrentScore.DefaultPageSettings);
                p2 = p2.Translate(CurrentScore.DefaultPageSettings);
                p3 = p3.Translate(CurrentScore.DefaultPageSettings);
                p4 = p4.Translate(CurrentScore.DefaultPageSettings);
            }

            var element = new XElement("path",
                                       new XAttribute("d", string.Format("M{0} {1} C{2} {3}, {4} {5}, {6} {7}",
                                                                         p1.X.ToStringInvariant(),
                                                                         p1.Y.ToStringInvariant(),
                                                                         p2.X.ToStringInvariant(),
                                                                         p2.Y.ToStringInvariant(),
                                                                         p3.X.ToStringInvariant(),
                                                                         p3.Y.ToStringInvariant(),
                                                                         p4.X.ToStringInvariant(),
                                                                         p4.Y.ToStringInvariant())),
                                       new XAttribute("style", pen.ToCss()),
                                       new XAttribute("id", BuildElementId(owner)));

            var playbackAttributes = BuildPlaybackAttributes(owner);

            foreach (var playbackAttr in playbackAttributes)
            {
                element.Add(new XAttribute(playbackAttr.Key, playbackAttr.Value));
            }

            if (p1.Y < ClippedAreaY)
            {
                ClippedAreaY = p1.Y;
            }
            if (p2.Y < ClippedAreaY)
            {
                ClippedAreaY = p2.Y;
            }
            if (p3.Y < ClippedAreaY)
            {
                ClippedAreaY = p3.Y;
            }
            if (p4.Y < ClippedAreaY)
            {
                ClippedAreaY = p4.Y;
            }
            if (p4.X > ActualWidth)
            {
                ActualWidth = p4.X;
            }
            if (p1.Y > ActualHeight)
            {
                ActualHeight = p1.Y;
            }

            Canvas.Add(element);
        }
Пример #11
0
    public override void OnAwake()
    {
        Instance = this;
        cam      = gameObject.GetComponent <Camera>();
        Canvas   = cam.AddCanvas();

        //Scoreboard Image
        Scoreboard          = Canvas.Add(ScoreBG);
        Scoreboard.color    = Color.White;
        Scoreboard.origin   = new Vector2(0.5f);
        Scoreboard.position = new Vector2(0.5f, 0.11f);
        Scoreboard.depth    = 0.9f;
        Scoreboard.scale    = Scale;

        //Team1BG Image
        Team1Bar          = Canvas.Add(TeamBG);
        Team1Bar.color    = Team1.Color;
        Team1Bar.origin   = new Vector2(1, 0.5f);
        Team1Bar.position = Scoreboard.position + new Vector2(-Scoreboard.size.x * 0.5f, 0);
        Team1Bar.depth    = 1;
        Team1Bar.flip     = new Vector2(0, 1);
        Team1Bar.scale    = Scale;

        //Team2BG Image
        Team2Bar          = Canvas.Add(TeamBG);
        Team2Bar.color    = Team2.Color;
        Team2Bar.origin   = new Vector2(0, 0.5f);
        Team2Bar.position = Scoreboard.position + new Vector2(Scoreboard.size.x * 0.5f, 0);
        Team2Bar.depth    = 1;
        Team2Bar.scale    = Scale;

        //Team1 Score
        Score[0]          = Canvas.Add(Team1.Score.ToString());
        Score[0].color    = Color.Black;
        Score[0].origin   = new Vector2(0.5f);
        Score[0].position = Scoreboard.position + new Vector2(-Scoreboard.size.x * 0.27f, Scoreboard.size.y * 0.09f);
        Score[0].scale    = Scale;

        //Team2 Score
        Score[1]          = Canvas.Add(Team2.Score.ToString());
        Score[1].color    = Color.Black;
        Score[1].origin   = new Vector2(0.5f);
        Score[1].position = Scoreboard.position + new Vector2(Scoreboard.size.x * 0.25f, Scoreboard.size.y * 0.09f);
        Score[1].scale    = Scale;

        //Score text
        ScoreHeader          = Canvas.Add("Score");
        ScoreHeader.color    = Color.Black;
        ScoreHeader.origin   = new Vector2(0.5f);
        ScoreHeader.scale    = new Vector2(0.5f) * Scale;
        ScoreHeader.position = Scoreboard.position + new Vector2(0, -Scoreboard.size.y * 0.2875f);

        //Team1 name
        TeamName[0]          = Canvas.Add(Team1.Name);
        TeamName[0].origin   = new Vector2(0, 0.5f);
        TeamName[0].color    = Color.FloralWhite;
        TeamName[0].scale    = new Vector2(0.5f) * Scale;
        TeamName[0].position = Team1Bar.position - new Vector2(Team1Bar.size.x * 0.5f, 0);

        //Team2 name
        TeamName[1]          = Canvas.Add(Team2.Name);
        TeamName[1].origin   = new Vector2(1, 0.5f);
        TeamName[1].color    = Color.FloralWhite;
        TeamName[1].scale    = new Vector2(0.5f) * Scale;
        TeamName[1].position = Team2Bar.position + new Vector2(Team2Bar.size.x * 0.5f, 0);

        //Add one row for every player. They are then only drawn based on players in each team.
        for (int i = 0; i < MatchSystem.instance.MaxPlayers / 2; i++)
        {
            PlayerStandardBarTeam1.Add(Canvas.Add(PlayerBG));
            PlayerStandardBarTeam1[i].color     = Team1.Color;
            PlayerStandardBarTeam1[i].origin    = new Vector2(1, 0.5f);
            PlayerStandardBarTeam1[i].position  = new Vector2(0.5f, 0.32f + (i * 0.063f));
            PlayerStandardBarTeam1[i].depth     = 1;
            PlayerStandardBarTeam1[i].rendering = false;
            PlayerStandardBarTeam1[i].scale     = Scale;
            Team1Players.Add(new PlayerText(Canvas, TEAM_TYPE.TEAM_1, PlayerStandardBarTeam1[i]));

            PlayerStandardBarTeam2.Add(Canvas.Add(PlayerBG));
            PlayerStandardBarTeam2[i].color     = Team2.Color;
            PlayerStandardBarTeam2[i].origin    = new Vector2(0, 0.5f);
            PlayerStandardBarTeam2[i].position  = new Vector2(0.5f, 0.32f + (i * 0.063f));
            PlayerStandardBarTeam2[i].flip      = new Vector2(0, 1);
            PlayerStandardBarTeam2[i].depth     = 1;
            PlayerStandardBarTeam2[i].rendering = false;
            PlayerStandardBarTeam2[i].scale     = Scale;
            Team2Players.Add(new PlayerText(Canvas, TEAM_TYPE.TEAM_2, PlayerStandardBarTeam2[i]));
        }

        //Header background above Team1 players
        PlayerHeaderBackground[0]          = Canvas.Add(PlayerBG);
        PlayerHeaderBackground[0].position = new Vector2(0.5f, 0.32f + (-1 * 0.063f));
        PlayerHeaderBackground[0].color    = Team1.Color;
        PlayerHeaderBackground[0].origin   = new Vector2(1, 0.5f);
        PlayerHeaderBackground[0].depth    = 1;
        PlayerHeaderBackground[0].scale    = Scale;

        //Header background above Team2 players
        PlayerHeaderBackground[1]          = Canvas.Add(PlayerBG);
        PlayerHeaderBackground[1].position = new Vector2(0.5f, 0.32f + (-1 * 0.063f));
        PlayerHeaderBackground[1].color    = Team2.Color;
        PlayerHeaderBackground[1].origin   = new Vector2(0, 0.5f);
        PlayerHeaderBackground[1].flip     = new Vector2(0, 1);
        PlayerHeaderBackground[1].depth    = 1;
        PlayerHeaderBackground[1].scale    = Scale;

        //Header text above Team1 players
        PlayerHeader[0]              = new PlayerText(Canvas, TEAM_TYPE.TEAM_1, PlayerHeaderBackground[0]);
        PlayerHeader[0].Name.text    = "Name";
        PlayerHeader[0].Goals.text   = "Goals";
        PlayerHeader[0].Tackles.text = "Tackles";
        PlayerHeader[0].Score.text   = "Score";
        PlayerHeader[0].Ping.text    = "Ping";
        PlayerHeader[0].Scale        = new Vector2(0.33f) * Scale;
        PlayerHeader[0].IsRendering  = true;

        //Header text above Team2 players
        PlayerHeader[1]              = new PlayerText(Canvas, TEAM_TYPE.TEAM_2, PlayerHeaderBackground[1]);
        PlayerHeader[1].Name.text    = "Name";
        PlayerHeader[1].Goals.text   = "Goals";
        PlayerHeader[1].Tackles.text = "Tackles";
        PlayerHeader[1].Score.text   = "Score";
        PlayerHeader[1].Ping.text    = "Ping";
        PlayerHeader[1].Scale        = new Vector2(0.33f) * Scale;
        PlayerHeader[1].IsRendering  = true;
    }
Пример #12
0
    public void AddImagesAndText()
    {
        Canvas = Camera.AddCanvas();
        if (SelectBox != null)
        {
            Team1Image              = Canvas.Add(SelectBox);
            Team1Image.position     = new Vector2(0.235f, 0.58f);
            Team1Image.scale        = new Vector2(9, 9);
            Team1Image.origin       = new Vector2(0.5f);
            Team1Image.color        = new Color(1, 1, 1, 1);
            Team1Image.interactable = true;

            Team2Image              = Canvas.Add(SelectBox);
            Team2Image.position     = new Vector2(0.777f, 0.58f);
            Team2Image.scale        = new Vector2(9, 9);
            Team2Image.origin       = new Vector2(0.5f);
            Team2Image.color        = new Color(1, 1, 1, 1);
            Team2Image.interactable = true;
        }

        if (SpectatorCamTexture != null)
        {
            SpectatorImage              = Canvas.Add(SpectatorCamTexture);
            SpectatorImage.position     = new Vector2(0.5f, 0.88f);
            SpectatorImage.origin       = new Vector2(0.5f);
            SpectatorImage.interactable = true;
        }

        Select          = Canvas.Add("Select Team");
        Select.position = new Vector2(0.5f, 0.1f);
        Select.origin   = new Vector2(0.5f);
        Select.color    = Unselected;

        Team1Text          = Canvas.Add(MatchSystem.instance.Teams[TEAM_TYPE.TEAM_1].Name);
        Team1Text.position = new Vector2(0.235f, 0.25f);
        Team1Text.origin   = new Vector2(0.5f);
        Team1Text.font     = ChadFont;
        Team1Text.color    = Unselected;

        Team2Text          = Canvas.Add(MatchSystem.instance.Teams[TEAM_TYPE.TEAM_2].Name);
        Team2Text.position = new Vector2(0.777f, 0.25f);
        Team2Text.origin   = new Vector2(0.5f);
        Team2Text.font     = ChadFont;
        Team2Text.color    = Unselected;

        SpectatorText              = Canvas.Add(MatchSystem.instance.Teams[TEAM_TYPE.TEAM_SPECTATOR].Name);
        SpectatorText.position     = new Vector2(0.5f, 0.8f);
        SpectatorText.origin       = new Vector2(0.5f);
        SpectatorText.font         = SportFont32;
        SpectatorText.interactable = true;
        SpectatorText.color        = Unselected;

        ReadyUp              = Canvas.Add("Ready");
        ReadyUp.position     = new Vector2(0.5f, 0.25f);
        ReadyUp.origin       = new Vector2(0.5f);
        ReadyUp.font         = SportFont32;
        ReadyUp.interactable = true;
        ReadyUp.color        = Unselected;
        ReadyUp.rendering    = false;

        StartGame              = Canvas.Add("Start Game");
        StartGame.position     = new Vector2(0.5f, 0.35f);
        StartGame.origin       = new Vector2(0.5f);
        StartGame.font         = SportFont32;
        StartGame.interactable = true;
        StartGame.color        = Unselected;
        StartGame.rendering    = false;

        PlayersInTeam1          = Canvas.Add(MatchSystem.instance.Teams[TEAM_TYPE.TEAM_1].PlayerCount + " out of " + MatchSystem.instance.MaxPlayers / 2);
        PlayersInTeam1.position = new Vector2(0, 0.05f);
        PlayersInTeam1.color    = Unselected;

        PlayersInTeam2          = Canvas.Add(MatchSystem.instance.Teams[TEAM_TYPE.TEAM_2].PlayerCount + " out of " + MatchSystem.instance.MaxPlayers / 2);
        PlayersInTeam2.origin   = new Vector2(1, 0);
        PlayersInTeam2.position = new Vector2(1, 0.05f);
        PlayersInTeam2.color    = Unselected;

        ExitText              = Canvas.Add("Exit");
        ExitText.position     = new Vector2(0.05f, 0.85f);
        ExitText.origin       = new Vector2(0.5f);
        ExitText.color        = Unselected;
        ExitText.interactable = true;
    }
Пример #13
0
        public static Overlay New(IServiceRegistry services)
        {
            var settings = services.GetService <IDirectXDeviceSettings>();

            var overlay = new Overlay(services)
            {
                Width  = settings.PreferredBackBufferWidth,
                Height = settings.PreferredBackBufferHeight
            };

            // signal that we are starting to design the UI
            overlay.BeginDesign();

            var canvas = new Canvas();
            var border = new Border()
            {
                StyleClass = "Panel", Position = LayoutManager.Point(2, 2), Width = LayoutManager.Units(30), Height = LayoutManager.Units(20)
            };

            var fpsCounter = new FpsCounter {
                Position = LayoutManager.Point(0.5f, 0.5f)
            };
            var dockPanel = new DockPanel {
            };

            var label = new TextBlock {
                Text = "This is a Dockpanel.", Margin = new Thickness(8)
            };

            label.DependencyProperties.Add(DockPanel.DockPropertyKey, Dock.Top);

            var stackPanel1 = new StackPanel()
            {
                Orientation = Orientation.Vertical
            };

            stackPanel1.DependencyProperties.Add(DockPanel.DockPropertyKey, Dock.Bottom);

            var listBox = new ListBox
            {
                Padding     = new Thickness(4),
                Margin      = new Thickness(8),
                ItemsSource = new[]
                { "This is a Listbox", "bound to a string array.", "Its itemtemplate specifies that each entry", "will be bound to a TextBlock" }
            };

            // The size of the button comes from the Defaul.oxil theme file
            var button = new Button
            {
                Content = new TextBlock {
                    Text = "Button", HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center
                },
                HorizontalAlignment = HorizontalAlignment.Center,
                VerticalAlignment   = VerticalAlignment.Center,
            };

            button.Tap += (s, eventArgs) => ((TextBlock)button.Content).Text = "It works!";

            stackPanel1.Add(button);

            dockPanel.Add(stackPanel1);
            dockPanel.Add(label);
            dockPanel.Add(listBox);
            border.Content = dockPanel;
            canvas.Add(border);
            canvas.Add(fpsCounter);

            overlay.Content = canvas;

            // we're done: BeginDesign() and EndDesign() are required for correct initialization
            overlay.EndDesign();

            return(overlay);
        }
Пример #14
0
        public void Draw(Canvas canvas, bool constructionMode, IList <RegularExpression> highlightedStates,
                         IList <MachineTransition> highlightedTransitions, bool evaluationMode, int previousState,
                         int currentState, bool evaluationEnded)
        {
            if (canvas == null)
            {
                throw new ArgumentNullException("canvas");
            }

            canvas.Clear();

            double maxX = 0;
            double maxY = 0;

            {
                double startAngle = FindMostFreeAngle(0, true, false, 315);

                if (constructionMode && highlightedStates.Any(x => states.IndexOf(x) == 0))
                {
                    DrawStartArrow(canvas, HighlightedEdgeBrush, HighlightedEdgeBorderBrush, vertices[0], startAngle);
                }
                else
                {
                    DrawStartArrow(canvas, EdgeBrush, EdgeBorderBrush, vertices[0], startAngle);
                }
            }

            string text = String.Empty;

            for (int i = 0; i < vertices.Count; ++i)
            {
                var location = vertices[i];

                int transitionIndex = -1;
                foreach (var transition in transitions)
                {
                    ++transitionIndex;
                    if (transition.InitialStateId != i)
                    {
                        continue;
                    }

                    var letters = new TextBlock();
                    letters.Height = TextBlockHeight;
                    //letters.Width = double.NaN; // Auto, goes to 100%
                    letters.Width         = transition.Item2.Count * TextBlockHeight;
                    letters.Text          = String.Join(" ", transition.Item2);
                    letters.TextAlignment = TextAlignment.Center;

                    Brush edgeBrush       = null;
                    Brush edgeBorderBrush = null;
                    Brush edgeLabelBrush  = null;
                    if (constructionMode && highlightedTransitions.Any(x => x.InitialStateId == transition.InitialStateId &&
                                                                       x.ResultingStateId == transition.ResultingStateId))
                    {
                        edgeBrush       = HighlightedEdgeBrush;
                        edgeBorderBrush = HighlightedEdgeBorderBrush;
                        edgeLabelBrush  = HighlightedEdgeLabelBrush;
                    }
                    else if (evaluationMode && transition.InitialStateId == previousState &&
                             transition.ResultingStateId == currentState)
                    {
                        edgeBrush       = HighlightedEdgeBrush;
                        edgeBorderBrush = HighlightedEdgeBorderBrush;
                        edgeLabelBrush  = HighlightedEdgeLabelBrush;
                    }
                    else
                    {
                        edgeBrush       = EdgeBrush;
                        edgeBorderBrush = EdgeBorderBrush;
                        edgeLabelBrush  = EdgeLabelBrush;
                    }

                    letters.Foreground = edgeLabelBrush;

                    if (transition.Item3 == i)
                    {
                        // loop, i.e. directed edge to self

                        double angle = edges[transition].Item1;

                        DrawLoop(canvas, edgeBrush, edgeBorderBrush, edgeLabelBrush, location, angle);

                        Point translatePoint = new Point(0, 0).MoveTo(angle, LoopHeight);

                        if (angle > 90 && angle <= 270)
                        {
                            angle -= 180;
                        }

                        var rotateTransform    = new RotateTransform(angle, letters.Width / 2, TextBlockHeight / 2);
                        var translateTransform = new TranslateTransform(translatePoint.X, translatePoint.Y);
                        var transforms         = new TransformGroup();
                        transforms.Children.Add(rotateTransform);
                        transforms.Children.Add(translateTransform);
                        letters.RenderTransform = transforms;

                        canvas.Add(letters, location.X - letters.Width / 2, location.Y - TextBlockHeight / 2, 0);
                    }
                    else
                    {
                        // normal edge
                        Point endpoint = vertices[transition.Item3];

                        double angle = edges[transition].Item1 - 90;
                        // double angle = location.Angle(endpoint) - 90; // already got it
                        Point translatePoint;

                        Point middle = new Point((location.X + endpoint.X) / 2, (location.Y + endpoint.Y) / 2);

                        List <Point> intersections = new List <Point>();
                        if (layoutScore.IntersectingEdges.Count > 0)
                        {
                            // detect intersections with other edges to move label to the longest uninterrupted segment
                            foreach (var intr in layoutScore.IntersectingEdges)
                            {
                                if (intr.Item1 != transitionIndex)
                                {
                                    continue;
                                }
                                MachineTransition intersectingTransition = transitions[intr.Item2];
                                Point             p1 = vertices[intersectingTransition.InitialStateId];
                                Point             p2 = vertices[intersectingTransition.ResultingStateId];

                                Point intersection = location.FindIntersectionAssumingItExists(endpoint, p1, p2);

                                intersections.Add(intersection);
                            }

                            // detect overlapping vertices to move label away from them
                            foreach (var intr in layoutScore.VerticesOnEdges)
                            {
                                // the vertex must be near currently evaluated transition
                                if (intr.Item2 != transitionIndex)
                                {
                                    continue;
                                }

                                //double angle = location.Angle(endpoint); // already got it

                                Point intersection = vertices[intr.Item1].MoveTo(angle, intr.Item3);

                                if (intersection.DistanceToLine(location, endpoint) > intr.Item3)
                                {
                                    intersection = vertices[intr.Item1].MoveTo(angle + 180, intr.Item3);
                                }

                                intersections.Add(intersection);
                            }

                            if (intersections.Count > 0)
                            {
                                intersections.Add(location.MoveTo(endpoint, StateEllipseDiameter / 2));
                                intersections.Add(endpoint.MoveTo(location, StateEllipseDiameter / 2));
                                intersections.Sort((a, b) => a.X.CompareTo(b.X));
                            }
                        }
                        if (intersections.Count > 0)
                        {
                            var intersectionDistances = intersections.Zip(intersections.Skip(1), (x, y) => y.Distance(x)).ToArray();
                            //Console.Out.WriteLine(String.Join("; ", intersectionDistances));

                            // find the best position for the label
                            // i.e. the longest fragment without intersections
                            int    index = intersectionDistances.IndexOfMax();
                            double max   = intersectionDistances[index];
                            middle = intersections[index].MoveTo(intersections[index + 1], max / 2);

                            //DrawDot(canvas, Brushes.Red, middle);
                        }

                        //TODO: take bent edges into account (i.e. case of two transitions: q1->q2 and q2->q1)
                        // because in such cases labels are sometimes too close to the edges they belong to

                        if (transitions.Any(x => x.InitialStateId == transition.ResultingStateId &&
                                            x.ResultingStateId == transition.InitialStateId))
                        {
                            if (angle > 90 && angle <= 270)
                            {
                                angle         -= 180;
                                translatePoint = new Point(0, 0).MoveTo(angle, TextBlockHeight / 2 + 4);
                            }
                            else
                            {
                                translatePoint = new Point(0, 0).MoveTo(angle, -TextBlockHeight / 2 - 4);
                            }

                            DrawEdge(canvas, edgeBrush, edgeBorderBrush, edgeLabelBrush,
                                     location, edges[transition].Item1, endpoint, edges[transition].Item2);
                        }
                        else
                        {
                            DrawEdge(canvas, edgeBrush, edgeBorderBrush, edgeLabelBrush, location, endpoint);

                            if (angle > 90 && angle <= 270)
                            {
                                angle -= 180;
                            }
                            translatePoint = new Point(0, 0).MoveTo(angle, TextBlockHeight / 2 - 2);
                        }

                        var rotateTransform    = new RotateTransform(angle, letters.Width / 2, TextBlockHeight / 2);
                        var translateTransform = new TranslateTransform(translatePoint.X, translatePoint.Y);
                        var transforms         = new TransformGroup();
                        transforms.Children.Add(rotateTransform);
                        transforms.Children.Add(translateTransform);
                        letters.RenderTransform = transforms;

                        canvas.Add(letters, middle.X - letters.Width / 2, middle.Y - TextBlockHeight / 2, 0);
                    }
                }

                Brush vertexBrush           = null;
                Brush vertexBackgroundBrush = null;
                Brush vertexLabelBrush      = null;
                if (constructionMode && highlightedStates.Any(x => states.IndexOf(x) == i))
                {
                    vertexBrush           = HighlightedVertexBrush;
                    vertexBackgroundBrush = HighlightedVertexBackgroundBrush;
                    vertexLabelBrush      = HighlightedVertexLabelBrush;
                }
                else if (evaluationMode)
                {
                    if (currentState == i)
                    {
                        if (evaluationEnded)
                        {
                            vertexBrush           = VertexBrush;
                            vertexBackgroundBrush = WordAcceptedStateBackgroundBrush;
                            vertexLabelBrush      = VertexLabelBrush;
                        }
                        else
                        {
                            vertexBrush           = HighlightedVertexBrush;
                            vertexBackgroundBrush = HighlightedVertexBackgroundBrush;
                            vertexLabelBrush      = HighlightedVertexLabelBrush;
                        }
                    }
                    else if (previousState == i && currentState == -1)
                    {
                        vertexBrush           = VertexBrush;
                        vertexBackgroundBrush = WordRejectedStateBackgroundBrush;
                        vertexLabelBrush      = VertexLabelBrush;
                    }
                    else
                    {
                        vertexBrush           = VertexBrush;
                        vertexBackgroundBrush = VertexBackgroundBrush;
                        vertexLabelBrush      = VertexLabelBrush;
                    }
                }
                else
                {
                    vertexBrush           = VertexBrush;
                    vertexBackgroundBrush = VertexBackgroundBrush;
                    vertexLabelBrush      = VertexLabelBrush;
                }

                DrawState(canvas, vertexBrush, vertexBackgroundBrush, vertexLabelBrush, location,
                          String.Format("q{0}", i), acceptingStates.Any(x => x == states[i]));

                if (location.X > maxX)
                {
                    maxX = location.X;
                }
                if (location.Y > maxY)
                {
                    maxY = location.Y;
                }
            }
            canvas.Width  = maxX + LayoutOffset;
            canvas.Height = maxY + LayoutOffset;
        }
        public void WordIndexGenerator()
        {
            //Se incluyen los caracteres no las palabras
            List <Word> arrayIncluded = ToList(includedWords);

            int index = 1;

            //Hay que obtener caracter a caracter no las palabras TODO


            PdfWriter   writer   = new PdfWriter(@"D:\\HSKBooklet\" + Level.ToString() + "WordIndex.pdf");
            PdfDocument pdf      = new PdfDocument(writer);
            Document    document = new Document(pdf, PageSize.A4);

            const String FONT = @"C:\Windows\Fonts\STKAITI.TTF";
            //PdfFont fontKaiti = PdfFontFactory.CreateFont(FONT, PdfEncodings.IDENTITY_H, true, true);
            PdfFont fontKaiti = PdfFontFactory.CreateFont(FONT, PdfEncodings.IDENTITY_H, PdfFontFactory.EmbeddingStrategy.FORCE_EMBEDDED, true);

            document.SetFont(fontKaiti);


            var dimensionsColumns = new float[] { 25, 20, 20, 50, 10, 15 };

            Table table = new Table(UnitValue.CreatePercentArray(dimensionsColumns));

            table.UseAllAvailableWidth();

            int rowCount = 0;

            var OrderedChars = includedChars.OrderBy(x => x.Pinyin);

            var ArrayChars = OrderedChars.ToArray();

            //Palabra ordenadas alfabeticamente
            foreach (Word_HSK word in arrayIncluded)
            {
                bool first = true;

                foreach (char ch in word.Character.ToCharArray().Distinct())
                {
                    int Page = 0;
                    for (int x = 0; x < OrderedChars.Count(); x++)
                    {
                        if (ArrayChars.ElementAt(x).Character == ch.ToString())
                        {
                            Page = x;
                            break;
                        }
                    }

                    //El caracter aparece en la palabra word
                    //En la pagina index

                    // Adding cell 1 to the table

                    int SetMarginTopP = 10;
                    int SetHeightP    = 30;

                    //Shhh Esta chapuza es para que la descripcion no se repita tampoco
                    if (first)
                    {
                        Cell cell1 = new Cell(); // Creating a cell
                        cell1.Add(new Paragraph(word.Character).SetHeight(SetHeightP).SetFont(fontKaiti).SetBold().SetFontSize(20).SetTextAlignment(TextAlignment.LEFT).SetVerticalAlignment(VerticalAlignment.MIDDLE));
                        table.AddCell(cell1);    // Adding cell to the table


                        Cell cellPinyin = new Cell();
                        cellPinyin.Add(new Paragraph(word.Pinyin).SetFont(fontKaiti).SetFontSize(10).SetMarginTop(SetMarginTopP).SetTextAlignment(TextAlignment.CENTER).SetVerticalAlignment(VerticalAlignment.MIDDLE));
                        table.AddCell(cellPinyin);

                        //Palabra que lo usa
                        Cell cell2 = new Cell();
                        cell2.Add(new Paragraph(ch.ToString()).SetFont(fontKaiti).SetFontSize(20).SetTextAlignment(TextAlignment.CENTER).SetVerticalAlignment(VerticalAlignment.MIDDLE));
                        table.AddCell(cell2);

                        Cell cell3 = new Cell();
                        cell3.Add(new Paragraph(word.Description).SetFontSize(10).SetMarginLeft(20).SetMarginTop(SetMarginTopP).SetTextAlignment(TextAlignment.LEFT).SetVerticalAlignment(VerticalAlignment.MIDDLE));
                        table.AddCell(cell3);

                        first = false;
                    }
                    else
                    {
                        Cell cell1 = new Cell();   // Creating a cell
                        cell1.Add(new Paragraph(" ").SetHeight(SetHeightP).SetFont(fontKaiti).SetBold().SetFontSize(20).SetTextAlignment(TextAlignment.LEFT).SetVerticalAlignment(VerticalAlignment.MIDDLE));
                        table.AddCell(cell1);

                        Cell cellPinyin = new Cell();
                        cellPinyin.Add(new Paragraph(word.Pinyin).SetFont(fontKaiti).SetFontSize(10).SetMarginTop(SetMarginTopP).SetTextAlignment(TextAlignment.CENTER).SetVerticalAlignment(VerticalAlignment.MIDDLE));
                        table.AddCell(cellPinyin);

                        //Palabra que lo usa
                        Cell cell2 = new Cell();
                        cell2.Add(new Paragraph(ch.ToString()).SetFont(fontKaiti).SetFontSize(20).SetTextAlignment(TextAlignment.CENTER).SetVerticalAlignment(VerticalAlignment.MIDDLE));
                        table.AddCell(cell2);

                        Cell cell3 = new Cell();
                        cell3.Add(new Paragraph(" ").SetFontSize(10).SetMarginLeft(20).SetMarginTop(SetMarginTopP).SetTextAlignment(TextAlignment.LEFT).SetVerticalAlignment(VerticalAlignment.MIDDLE));
                        table.AddCell(cell3);
                    }

                    Cell cell4 = new Cell();
                    cell4.Add(new Paragraph("HSK " + word.Level.ToString()).SetFontSize(10).SetMarginTop(SetMarginTopP).SetTextAlignment(TextAlignment.CENTER).SetVerticalAlignment(VerticalAlignment.MIDDLE));
                    table.AddCell(cell4);

                    Cell cell5 = new Cell();
                    cell5.Add(new Paragraph("Pag. " + (Page + 1).ToString()).SetFontSize(10).SetMarginTop(SetMarginTopP).SetTextAlignment(TextAlignment.CENTER).SetVerticalAlignment(VerticalAlignment.MIDDLE));
                    table.AddCell(cell5);

                    rowCount++;

                    if (rowCount == 21)
                    {
                        PdfCanvas pdfCanvas = new PdfCanvas(pdf.AddNewPage());
                        Canvas    canvas    = new Canvas(pdfCanvas, pdf, document.GetPageEffectiveArea(pdf.GetDefaultPageSize()));
                        canvas.Add(table);

                        rowCount = 0;
                        table    = new Table(UnitValue.CreatePercentArray(dimensionsColumns));
                        table.UseAllAvailableWidth();
                    }
                }


                string sIndex = NumeroCuadrado(index, 3);
            }


            PdfCanvas pdfCanvasend = new PdfCanvas(pdf.AddNewPage());
            Canvas    canvasend    = new Canvas(pdfCanvasend, pdf, document.GetPageEffectiveArea(pdf.GetDefaultPageSize()));

            canvasend.Add(table);

            //Se añade una pagina en blanco al lomo de caracteres solo si es impar
            if (pdf.GetNumberOfPages() % 2 != 0)
            {
                PdfCanvas pdfCanvas = new PdfCanvas(pdf.AddNewPage());
            }

            document.Close();
        }
Пример #16
0
    public override void OnAwake()
    {
        Camera = gameObject.GetComponent <Camera>();
        Canvas = Camera.AddCanvas();

        CaretOffsetBig = 0.04f;

        HostMenuCamPos = new Vector3(40, -198.108f, 8.208f);
        HostMenuCamRot = new Vector3(MathHelper.Pi, 0.0f, 0.0f);
        Chad1Pos       = new Vector3(0.866f, 0, 0.561f);
        Chad1Rot       = new Vector3(45, 0, 0);
        Chad2Pos       = new Vector3(-0.717f, 0, 0.554f);
        Chad2Rot       = new Vector3(-20, 0, 0);

        HostBtn              = Canvas.Add("Host Game");
        HostBtn.color        = Unselected;
        HostBtn.position     = new Vector2(0.47f, 0.32f);
        HostBtn.interactable = true;

        ExitBtn              = Canvas.Add("Exit");
        ExitBtn.color        = Unselected;
        ExitBtn.position     = new Vector2(0.32f, 0.32f);
        ExitBtn.interactable = true;

        if (HostMenuBGTexture != null)
        {
            HostMenuBg       = Canvas.Add(HostMenuBGTexture);
            HostMenuBg.color = new Color(0.5f, 0.5f, 0.5f, 0.5f);
            HostMenuBg.depth = 0.7f;
        }

        #region Host Setings

        HostOptions          = Canvas.Add("Host Options");
        HostOptions.position = new Vector2(0.5f, 0f);
        HostOptions.origin   = new Vector2(0.5f, 0.0f);
        HostOptions.color    = Unselected;

        #region Color Check
        SimilarColor          = Canvas.Add("Teams have similar color, can't host");
        SimilarColor.position = new Vector2(0.5f, 0.52f);
        SimilarColor.origin   = new Vector2(0.5f);
        SimilarColor.color    = Color.Red;
        SimilarColor.scale    = Vector2.Zero;
        SimilarColor.depth    = 0;
        #endregion

        #region Name Check
        SameName          = Canvas.Add("Teams have same name, can't host");
        SameName.position = new Vector2(0.5f, 0.58f);
        SameName.origin   = new Vector2(0.5f);
        SameName.color    = Color.Red;
        SameName.scale    = Vector2.Zero;
        SameName.depth    = 0;
        #endregion

        float column1 = 0.00f;
        float column2 = 0.17f;
        float column3 = 0.52f;
        float column4 = 0.7f;

        float row1 = 0.130f;
        float row2 = 0.185f;
        float row3 = 0.244f;
        float row4 = 0.299f;

        #region Server Name
        ServerName          = Canvas.Add("Server name");
        ServerName.position = new Vector2(column1, row1);
        ServerName.scale    = new Vector2(0.5f);
        ServerName.origin   = new Vector2(0.0f, 0.5f);
        ServerName.color    = Unselected;
        ServerName.depth    = 0.4f;

        ServerNameString          = Canvas.Add("Pelles server");
        ServerNameString.position = new Vector2(column2, row1);
        ServerNameString.scale    = new Vector2(0.5f);
        ServerNameString.origin   = new Vector2(0.0f, 0.5f);
        ServerNameString.color    = Unselected;
        ServerNameString.depth    = 0.4f;

        if (TextBox305Texture != null)
        {
            ServerNameBox              = Canvas.Add(TextBox305Texture);
            ServerNameBox.position     = new Vector2(column2, row1);
            ServerNameBox.origin       = new Vector2(0.0f, 0.5f);
            ServerNameBox.color        = Unselected;
            ServerNameBox.interactable = true;
            ServerNameBox.depth        = 0.5f;
        }
        #endregion

        #region Server Port
        PortName          = Canvas.Add("Port");
        PortName.position = new Vector2(column1, row2);
        PortName.scale    = new Vector2(0.5f);
        PortName.origin   = new Vector2(0.0f, 0.5f);
        PortName.color    = Unselected;
        PortName.depth    = 0.4f;

        PortNameString          = Canvas.Add("9050");
        PortNameString.position = new Vector2(column2, row2);
        PortNameString.scale    = new Vector2(0.5f);
        PortNameString.origin   = new Vector2(0.0f, 0.5f);
        PortNameString.color    = Unselected;
        PortNameString.depth    = 0.4f;

        if (TextBox305Texture != null)
        {
            PortNameBox              = Canvas.Add(TextBox305Texture);
            PortNameBox.position     = new Vector2(column2, row2);
            PortNameBox.origin       = new Vector2(0.0f, 0.5f);
            PortNameBox.color        = Unselected;
            PortNameBox.interactable = true;
            PortNameBox.depth        = 0.5f;
        }
        #endregion

        #region Max Players
        MaxPlayers          = Canvas.Add("Max players");
        MaxPlayers.position = new Vector2(column1, row3);
        MaxPlayers.scale    = new Vector2(0.5f);
        MaxPlayers.origin   = new Vector2(0.0f, 0.5f);
        MaxPlayers.color    = Unselected;
        MaxPlayers.depth    = 0.4f;

        MaxPlayersString          = Canvas.Add("8");
        MaxPlayersString.position = new Vector2(column2, row3);
        MaxPlayersString.scale    = new Vector2(0.5f);
        MaxPlayersString.origin   = new Vector2(0.0f, 0.5f);
        MaxPlayersString.color    = Unselected;
        MaxPlayersString.depth    = 0.4f;

        if (TextBox105Texture != null)
        {
            MaxPlayersBox              = Canvas.Add(TextBox105Texture);
            MaxPlayersBox.position     = new Vector2(column2, row3);
            MaxPlayersBox.origin       = new Vector2(0.0f, 0.5f);
            MaxPlayersBox.interactable = true;
            MaxPlayersBox.depth        = 0.5f;
        }
        #endregion

        #region Time Round
        TimeRound          = Canvas.Add("Time per round");
        TimeRound.position = new Vector2(column1, row4);
        TimeRound.scale    = new Vector2(0.5f);
        TimeRound.origin   = new Vector2(0.0f, 0.5f);
        TimeRound.color    = Unselected;
        TimeRound.depth    = 0.4f;

        TimeRoundString          = Canvas.Add("5");
        TimeRoundString.position = new Vector2(column2, row4);
        TimeRoundString.scale    = new Vector2(0.5f);
        TimeRoundString.origin   = new Vector2(0.0f, 0.5f);
        TimeRoundString.color    = Unselected;
        TimeRoundString.depth    = 0.4f;

        if (TextBox105Texture != null)
        {
            TimeRoundBox              = Canvas.Add(TextBox105Texture);
            TimeRoundBox.position     = new Vector2(column2, row4);
            TimeRoundBox.origin       = new Vector2(0.0f, 0.5f);
            TimeRoundBox.interactable = true;
            TimeRoundBox.depth        = 0.5f;
        }
        #endregion

        /*
         #region Public Server
         *      PublicServer = Canvas.Add("Public server");
         *      PublicServer.position = new Vector2(column3, row1);
         *      PublicServer.scale = new Vector2(0.5f);
         *      PublicServer.origin = new Vector2(0.0f, 0.5f);
         *      PublicServer.color = Unselected;
         *      PublicServer.depth = 0.4f;
         *
         *      if (TextBoxCross55Texture != null)
         *      {
         *          PublicServerCheck = Canvas.Add(TextBoxCross55Texture);
         *          PublicServerCheck.position = new Vector2(column4 , row1);
         *          PublicServerCheck.origin = new Vector2(0.0f, 0.5f);
         *          PublicServerCheck.depth = 0.4f;
         *      }
         *
         *      if (TextBoxBG55Texture != null)
         *      {
         *          PublicServerBox = Canvas.Add(TextBoxBG55Texture);
         *          PublicServerBox.position = new Vector2(column4 , row1);
         *          PublicServerBox.origin = new Vector2(0.0f, 0.5f);
         *          PublicServerBox.interactable = true;
         *          PublicServerBox.depth = 0.5f;
         *      }
         #endregion
         *
         #region Score limit
         *      ScoreLimit = Canvas.Add("Score Limit");
         *      ScoreLimit.position = new Vector2(column3, row2);
         *      ScoreLimit.scale = new Vector2(0.5f);
         *      ScoreLimit.origin = new Vector2(0.0f, 0.5f);
         *      ScoreLimit.color = Unselected;
         *      ScoreLimit.depth = 0.4f;
         *
         *      ScoreLimitString = Canvas.Add("10");
         *      ScoreLimitString.position = new Vector2(column4, row2);
         *      ScoreLimitString.scale = new Vector2(0.5f);
         *      ScoreLimitString.origin = new Vector2(0.0f, 0.5f);
         *      ScoreLimitString.color = Unselected;
         *      ScoreLimitString.depth = 0.4f;
         *
         *      if (TextBox105Texture != null)
         *      {
         *          ScoreLimitBox = Canvas.Add(TextBox105Texture);
         *          ScoreLimitBox.position = new Vector2(column4, row2);
         *          ScoreLimitBox.origin = new Vector2(0.0f, 0.5f);
         *          ScoreLimitBox.interactable = true;
         *          ScoreLimitBox.depth = 0.5f;
         *      }
         #endregion
         *
         #region Power Ups
         * PowerUps = Canvas.Add("Power ups");
         * PowerUps.position = new Vector2(column3, row3);
         * PowerUps.scale = new Vector2(0.5f);
         * PowerUps.origin = new Vector2(0.0f, 0.5f);
         * PowerUps.color = Unselected;
         * PowerUps.depth = 0.4f;
         *
         * if (TextBoxCross55Texture != null)
         * {
         *  PowerUpsCheck = Canvas.Add(TextBoxCross55Texture);
         *  PowerUpsCheck.position = new Vector2(column4 , row3);
         *  PowerUpsCheck.origin = new Vector2(0.0f, 0.5f);
         *  PowerUpsCheck.depth = 0.4f;
         * }
         *
         * if (TextBoxBG55Texture != null)
         * {
         *  PowerUpsBox = Canvas.Add(TextBoxBG55Texture);
         *  PowerUpsBox.position = new Vector2(column4, row3);
         *  PowerUpsBox.origin = new Vector2(0.0f, 0.5f);
         *  PowerUpsBox.interactable = true;
         *  PowerUpsBox.depth = 0.5f;
         * }
         #endregion
         */
        #endregion

        #region Teams

        Team1          = Canvas.Add("Team 1");
        Team1.position = new Vector2(0.02f, 0.4f);
        Team1.color    = Unselected;
        Team1.font     = Font;

        Team2          = Canvas.Add("Team 2");
        Team2.position = new Vector2(0.72f, 0.4f);
        Team2.color    = Unselected;
        Team2.font     = Font;

        if (TextBox6010Texture != null)
        {
            Team1TextBox              = Canvas.Add(TextBox6010Texture);
            Team1TextBox.position     = new Vector2(0.01f, 0.39f);
            Team1TextBox.scale        = new Vector2(0.9f, 1f);
            Team1TextBox.interactable = true;

            Team2TextBox              = Canvas.Add(TextBox6010Texture);
            Team2TextBox.position     = new Vector2(0.99f, 0.39f);
            Team2TextBox.origin       = new Vector2(1, 0);
            Team2TextBox.scale        = new Vector2(0.9f, 1f);
            Team2TextBox.interactable = true;
        }

        Vector2 team1SliderKnobPos = new Vector2(0.05f, 0.7f);
        Vector2 team2SliderKnobPos = new Vector2(0.70f, 0.7f);

        if (ColorSliderTexture != null)
        {
            Team1ColorSlider              = Canvas.Add(ColorSliderTexture);
            Team1ColorSlider.position     = team1SliderKnobPos;
            Team1ColorSlider.interactable = true;

            Team2ColorSlider              = Canvas.Add(ColorSliderTexture);
            Team2ColorSlider.position     = team2SliderKnobPos;
            Team2ColorSlider.interactable = true;
        }

        if (SliderKnobTexture != null)
        {
            Team1SliderKnob          = Canvas.Add(SliderKnobTexture);
            Team1SliderKnob.position = team1SliderKnobPos;
            Team1SliderKnob.origin   = new Vector2(0.5f, 0.0f);

            Team2SliderKnob          = Canvas.Add(SliderKnobTexture);
            Team2SliderKnob.position = team2SliderKnobPos + Team2ColorSlider.size * new Vector2(0.66f, 0);  //+... Is to offset it to blue color. Derp.
            Team2SliderKnob.origin   = new Vector2(0.5f, 0.0f);
        }
        #endregion

        Caret              = Canvas.Add("");
        Caret.origin       = new Vector2(0, 0.5f);
        Caret.scale        = new Vector2(0.5f);
        Caret.interactable = false;
        Caret.depth        = 0.6f;
        Caret.color        = Color.Black;
    }
Пример #17
0
        public async Task CreateGeoLocationForm(float xPosition, float yPosition)
        {
            if (GeoLocationForm != null)
            {
                GeoLocationForm.parent?.Remove(GeoLocationForm);
                GeoLocationForm = null;
            }
            else
            {
                GeoLocationForm = new Stack().Size(200, 90).Padding(vertical: 8, horizontal: 8).Border(color: "#444", all: 1)
                                  .Background(color: "#666").X(xPosition).Y(yPosition).Absolute().ZIndex(1000);

                var title = new TextView {
                    Text = "Your Location", TextAlignment = Alignment.Middle
                };
                title.Width(100.Percent()).Padding(bottom: 5).Font(bold: true);
                var latField = new FormField <TextInput> {
                    LabelText = "Latitude"
                };
                var longField = new FormField <TextInput> {
                    LabelText = "Longitude"
                };
                latField.Control.Background(color: "#444").Padding(top: 5).Font(color: Colors.White, size: 10);
                longField.Control.Background(color: "#444").Padding(top: 5).Font(color: Colors.White, size: 10);

                if (EnvironmentSimulator.Location != null)
                {
                    latField.Control.Text(EnvironmentSimulator.Location.Latitude.ToString());
                    longField.Control.Text(EnvironmentSimulator.Location.Longitude.ToString());
                }

                var configButton = new Button
                {
                    Text            = "Set",
                    BackgroundColor = new GradientColor(GradientColor.Direction.Down).Add("#555", 50).EndWith("#444")
                };

                configButton.Tapped
                .Handle(() =>
                {
                    EnvironmentSimulator.Location = new GeoPosition
                    {
                        Latitude  = latField.GetValue <float>(),
                        Longitude = longField.GetValue <float>()
                    };

                    GeoLocationForm.parent?.Remove(GeoLocationForm);
                    GeoLocationForm = null;
                });

                await GeoLocationForm.Add(title);

                await GeoLocationForm.Add(latField);

                await GeoLocationForm.Add(longField);

                await GeoLocationForm.Add(configButton);

                await MainPhone.Add(GeoLocationForm);
            }
        }
    public void AddImagesAndText()
    {
        Canvas = Camera.AddCanvas();

        #region Text
        #region  Play
        Play              = Canvas.Add("Join Game");
        Play.position     = new Vector2(0.1f, 0.11f);
        Play.interactable = true;
        Play.depth        = 0.9f;
        #endregion

        #region Host Game
        HostGame              = Canvas.Add("Host Game");
        HostGame.position     = new Vector2(0.1f, 0.21f);
        HostGame.interactable = true;
        HostGame.depth        = 0.9f;
        #endregion

        #region  Options
        Options              = Canvas.Add("Options");
        Options.position     = new Vector2(0.1f, 0.31f);
        Options.interactable = true;
        Options.depth        = 0.9f;
        #endregion

        #region Credits
        Credits              = Canvas.Add("Credits");
        Credits.position     = new Vector2(0.1f, 0.41f);
        Credits.interactable = true;
        Credits.depth        = 0.9f;
        #endregion

        #region Exit
        Exit              = Canvas.Add("Exit");
        Exit.position     = new Vector2(0.1f, 0.51f);
        Exit.interactable = true;
        Exit.depth        = 0.9f;
        #endregion

        #region Player name

        string playerString = UserSettings.GetSetting("PlayerName");
        if (playerString == null)
        {
            playerString = "CHAD";
        }

        PlayerName              = Canvas.Add(playerString);
        PlayerName.origin       = new Vector2(0.5f);
        PlayerName.position     = new Vector2(0.55f, 0.17f);
        PlayerName.scale        = new Vector2(0.9f);
        PlayerName.interactable = true;
        PlayerName.depth        = 0.8f;
        PlayerName.rotation     = NameRotation;
        PlayerName.color        = Color.Black;
        PlayerName.font         = TextFont;
        #endregion

        #region Random Hat
        RandomHat              = Canvas.Add("Random Hat");
        RandomHat.origin       = new Vector2(0.5f);
        RandomHat.scale        = new Vector2(0.6f);
        RandomHat.position     = new Vector2(0.76f, 0.17f);
        RandomHat.interactable = true;
        RandomHat.depth        = 0.8f;
        #endregion

        #region Caret
        Caret              = Canvas.Add("");
        Caret.origin       = new Vector2(0, 0.5f);
        Caret.scale        = new Vector2(1.2f);
        Caret.interactable = false;
        Caret.depth        = 0.8f;
        Caret.rotation     = NameRotation;
        Caret.color        = Color.Black;
        Caret.font         = TextFont;
        #endregion
        #endregion

        #region Images
        #region NameSticker
        if (MyNameTexture != null)
        {
            MyNameSticker              = Canvas.Add(MyNameTexture);
            MyNameSticker.origin       = new Vector2(0.5f);
            MyNameSticker.position     = new Vector2(0.55f, 0.14f);
            MyNameSticker.scale        = new Vector2(0.5f);
            MyNameSticker.interactable = true;
            MyNameSticker.depth        = 0.9f;
        }
        #endregion

        #region Arrows
        if (ArrowTexture != null)
        {
            SelectHatRight              = Canvas.Add(ArrowTexture);
            SelectHatRight.origin       = new Vector2(0.5f);
            SelectHatRight.scale        = new Vector2(0.25f);
            SelectHatRight.position     = new Vector2(0.85f, 0.25f);
            SelectHatRight.interactable = true;
            SelectHatRight.depth        = 0.9f;

            SelectHatLeft              = Canvas.Add(ArrowTexture);
            SelectHatLeft.origin       = new Vector2(0.5f);
            SelectHatLeft.scale        = new Vector2(0.25f);
            SelectHatLeft.position     = new Vector2(0.68f, 0.25f);
            SelectHatLeft.rotation     = (float)System.Math.PI;
            SelectHatLeft.interactable = true;
            SelectHatLeft.depth        = 0.9f;
        }
        #endregion

        #region Chad Area
        if (FrameTexture != null)
        {
            ChadArea              = Canvas.Add(FrameTexture);
            ChadArea.position     = new Vector2(0.62f, 0.32f);
            ChadArea.scale        = new Vector2(5, 6);
            ChadArea.interactable = true;
            ChadArea.color        = new Color(1, 1, 1, 0);
            ChadArea.depth        = 0.9f;
        }
        #endregion

        #endregion
    }
Пример #19
0
        public void TestDrawCanvasWithNewShapeWithoutVisitorImplemented()
        {
            Canvas c = new Canvas
                {
                    Height = 10,
                    Width = 12
                };

            c.Add(new Box {Side = 5});
            c.Add(new MyShape {SomeData = 3});

            var visitor = _container.Resolve<IVisitor<Shape>>("Draw");

            try
            {
                c.Accept(visitor);

                Assert.Fail("Exception expected");
            }
            catch (InvalidOperationException)
            {
                // Expecting exception here for missing visitor implementation
            }

            A.CallTo(() => _graphics.DrawRectangle(10, 12)).MustHaveHappened(Repeated.Exactly.Once);
            A.CallTo(() => _graphics.DrawBox(5)).MustHaveHappened(Repeated.Exactly.Once);
            A.CallTo(() => _graphics.DrawCircle(0)).WithAnyArguments().MustNotHaveHappened();
        }
Пример #20
0
    public override void OnAwake()
    {
        if (!Instance)
        {
            Instance = this;
        }
        else
        {
            Destroy(this);
            return;
        }
        cam    = gameObject.GetComponent <Camera>();
        Canvas = cam.AddCanvas();

        #region Timer stuff
        Timer = Canvas.Add("00:00");
        //Timer.scale = new Vector2(2f);
        Timer.scale    = new Vector2(0.6f);
        Timer.position = new Vector2(0.4975f, -0.005f);
        Timer.color    = Color.Black;
        //Timer.font = Numbers;
        Timer.origin = new Vector2(0.5f, 0);
        Timer.depth  = 0.8f;

        if (TimerBGTexture != null)
        {
            TimerBG          = Canvas.Add(TimerBGTexture);
            TimerBG.position = new Vector2(0.5f, 0);
            TimerBG.origin   = new Vector2(0.5f, 0);
            TimerBG.scale    = new Vector2(0.6f, 0.7f);
            TimerBG.color    = Color.GhostWhite;
            TimerBG.depth    = 0.9f;

            //Left of the timer
            if (ScoreBGTexture != null)
            {
                Score1BG          = Canvas.Add(ScoreBGTexture);
                Score1BG.origin   = new Vector2(0.5f, 0);
                Score1BG.position = TimerBG.position - new Vector2((TimerBG.size.x + Score1BG.size.x) / 2, 0);
                Score1BG.color    = MatchSystem.instance.Teams[TEAM_TYPE.TEAM_1].Color;
                Score1BG.depth    = 1;
                Score1BG.scale    = new Vector2(1, 0.7f);
                Score1BG.flip     = new Vector2(0, 1);

                //Right of the timer
                Score2BG          = Canvas.Add(ScoreBGTexture);
                Score2BG.origin   = new Vector2(0.5f, 0); //for clarity
                Score2BG.position = TimerBG.position + new Vector2((TimerBG.size.x + Score1BG.size.x) / 2, 0);
                Score2BG.color    = MatchSystem.instance.Teams[TEAM_TYPE.TEAM_2].Color;
                Score2BG.depth    = 1;
                Score2BG.scale    = new Vector2(1, 0.7f);
            }
        }



        Score1 = Canvas.Add("");
        //Score1.scale = new Vector2(1.6f);
        Score1.scale    = new Vector2(0.5f);
        Score1.origin   = new Vector2(0.5f, 0);
        Score1.position = Score1BG.position + new Vector2(0.005f, -0.004f);
        Score1.outline  = true;
        Score1.color    = Color.White;
        //Score1.font = Numbers;
        Score1.depth = 0.8f;

        Score2 = Canvas.Add("");
        //Score2.scale = new Vector2(1.6f);
        Score2.scale    = new Vector2(0.5f);
        Score2.origin   = new Vector2(0.5f, 0);
        Score2.position = Score2BG.position + new Vector2(-0.009f, -0.004f);
        Score2.outline  = true;
        Score2.color    = Color.White;
        //Score2.font = Numbers;
        Score2.depth = 0.8f;
        #endregion

        #region Announcement stuff
        Announcement1          = Canvas.Add("");
        Announcement1.position = new Vector2(0.5f);
        //Announcement1.scale = new Vector2(2);
        //Announcement1.font = AnnouncementFont;
        Announcement1.color  = Color.Green;
        Announcement1.origin = new Vector2(0.5f);

        Announcement2          = Canvas.Add("");
        Announcement2.position = new Vector2(0.5f);
        //Announcement2.scale = new Vector2(2);
        //Announcement2.font = AnnouncementFont;
        Announcement2.color  = Color.Green;
        Announcement2.origin = new Vector2(0.5f);

        if (AnnouncementBackground != null)
        {
            AnnouncementBG          = Canvas.Add(AnnouncementBackground);
            AnnouncementBG.position = new Vector2(0.5f);
            AnnouncementBG.scale    = Vector2.Zero;
            AnnouncementBG.origin   = new Vector2(0.5f);
            AnnouncementBG.depth    = 1;
        }
        #endregion

        #region Aiming Stuff
        if (CrosshairTexture != null)
        {
            Crosshair           = Canvas.Add(CrosshairTexture);
            Crosshair.origin    = new Vector2(0.5f);
            Crosshair.position  = new Vector2(0.5f);
            Crosshair.scale     = new Vector2(0.5f, 0.5f);
            Crosshair.rendering = false;
        }

        if (ChargeBarOutlineTexture != null)
        {
            ChargeBarOutline           = Canvas.Add(ChargeBarOutlineTexture);
            ChargeBarOutline.origin    = new Vector2(0.5f, 0);
            ChargeBarOutline.scale     = new Vector2(0.4f, 1.8f);
            ChargeBarOutline.position  = new Vector2(0.5f) + new Vector2(Crosshair.size.x, -ChargeBarOutline.size.y / 2);
            ChargeBarOutline.rendering = false;
        }

        if (ChargeBarTexture != null)
        {
            ChargeBar           = Canvas.Add(ChargeBarTexture);
            ChargeBar.position  = ChargeBarOutline.position + new Vector2(0, ChargeBarOutline.size.y); /*new Vector2(0.9f, 0.1f + ((ChargeBarTexture.height * 9.0f) / 1080.0f))*/; //Need to move the bar its own height down one step.
            ChargeBar.rendering = false;
            ChargeBar.origin    = new Vector2(0.5f, 0);
            ChargeBar.rotation  = MathHelper.Pi; //Need to rotate the bar 180, because positive x is down on the screen.
        }
        #endregion

        if (BallArrowTexture != null)
        {
            BallArrow          = Canvas.Add(BallArrowTexture);
            BallArrow.origin   = new Vector2(0.5f);
            BallArrow.scale    = new Vector2(4);
            BallArrow.position = new Vector2(-1000);
            BallArrow.color    = Score1BG.color + Score2BG.color;
        }

        if (HeldObjectIconBall != null)
        {
            HeldObjectIcon           = Canvas.Add(HeldObjectIconBall);
            HeldObjectIcon.position  = new Vector2(0.1f, 0.9f);
            HeldObjectIcon.origin    = new Vector2(0.5f, 0.5f);
            HeldObjectIcon.rendering = false;
        }
    }
Пример #21
0
        public void OptimizedCanvas_Renders_Like_Canvas_When_Holes()
        {
            var canvas = new Canvas(100, 100, "");

            canvas.Add(new RectangleShape(0, 0, 20, 20, "black"));
            canvas.Add(new CircleShape(10, 10, 10, "brown"));

            canvas.Add(new RectangleShape(80, 80, 20, 20, "pink"));
            canvas.Add(new CircleShape(90, 90, 10, "red"));

            canvas.Layers.Add(new SecondsLayer()
            {
                Offset = new Vertex(50, 50)
            });
            canvas.Add(new RectangleShape(-1, -30, 2, 32, "blue"));
            canvas.Layers.Add(new Layer());

            canvas.Add(new RectangleShape(0, 80, 20, 20, "yellow"));
            canvas.Add(new CircleShape(10, 90, 10, "purple"));

            canvas.Add(new RectangleShape(80, 0, 20, 20, "white"));
            canvas.Add(new CircleShape(90, 10, 10, "green"));

            canvas.Layers.Add(new CachedLayer());
            canvas.Add(new CircleShape(50, 50, 50, "orange"));
            canvas.Add(new DeleteCircleShape {
                Position = new Vertex(50, 50), Radius = 45
            });

            var clockCanvas     = new ClockCanvas(new TestTimer(Instant.FromDateTimeOffset(DateTime.Today.AddHours(3).AddMinutes(30).AddSeconds(45))), canvas);
            var optimizedCanvas = clockCanvas.OptimizeFor(1);

            clockCanvas.Update();
            optimizedCanvas.Update();
            var bmp = optimizedCanvas.Render();

            AssertBitmapsAreEqual(clockCanvas.Render(), bmp, PixelCompareMode.RGBASimilar);
        }
Пример #22
0
        public virtual void HandleEvent(Event pdfEvent)
        {
            {
                PdfDocumentEvent docEvent = (PdfDocumentEvent)pdfEvent;
                PdfDocument      pdfDoc   = docEvent.GetDocument();
                Document         document = new Document(pdfDoc);
                PdfPage          page     = docEvent.GetPage();
                int       pageNumber      = pdfDoc.GetPageNumber(page);
                Rectangle pageSize        = page.GetPageSize();

                PdfCanvas pdfCanvas = new PdfCanvas(page.NewContentStreamBefore(), page.GetResources(), pdfDoc);

                //Add header and footer
                PdfFont font = PdfFontFactory.CreateRegisteredFont("calibri-bold");

                if (pageNumber == 1)
                {
                    if (_docOptions.HasFlag(DocConverter.DocOptions.AddHeaderPageOne))
                    {
                        pdfCanvas.SaveState();
                        PdfExtGState state = new PdfExtGState();
                        state.SetFillOpacity(1.0f);
                        pdfCanvas.SetExtGState(state);

                        var imageHeight = _idHeaderFirst.GetHeight() * 72 / 96; //convert pixels to points
                        var imageToAdd  = new Image(_idHeaderFirst, 0, pageSize.GetTop() - imageHeight, pageSize.GetWidth());

                        imageToAdd.GetAccessibilityProperties()
                        .SetAlternateDescription("Background header image");
                        imageToAdd.GetAccessibilityProperties().SetRole(StandardRoles.ARTIFACT);

                        PdfLayer pdflayer = new PdfLayer("main layer", pdfDoc);

                        pdflayer.SetOn(true);
                        Canvas canvas = new Canvas(pdfCanvas, pdfDoc,
                                                   document.GetPageEffectiveArea(pdfDoc.GetDefaultPageSize()));
                        pdflayer.SetPageElement("L");
                        pdfCanvas.BeginLayer(pdflayer);
                        canvas.EnableAutoTagging(page);
                        canvas.Add(imageToAdd);
                        pdfCanvas.EndLayer();
                    }

                    if (_docOptions.HasFlag(DocConverter.DocOptions.DisplayTitle))
                    {
                        //Add Title
                        Color          purpleColor = new DeviceRgb(85, 60, 116);
                        TagTreePointer tagPointer  = new TagTreePointer(pdfDoc);
                        tagPointer.SetPageForTagging(page);
                        tagPointer.AddTag(StandardRoles.TITLE);
                        pdfCanvas.BeginText().SetColor(purpleColor, true).SetFontAndSize(font, 28)
                        .MoveText(42, pageSize.GetTop() - 150).OpenTag(tagPointer.GetTagReference()).ShowText(_title).CloseTag().Stroke();
                    }
                }
                else if (_docOptions.HasFlag(DocConverter.DocOptions.AddHeaderAllPages))
                {
                    pdfCanvas.SaveState();
                    PdfExtGState state = new PdfExtGState();
                    state.SetFillOpacity(1.0f);
                    pdfCanvas.SetExtGState(state);
                    var imageHeight = _idHeaderAll.GetHeight() * 72 / 96; //convert pixels to points
                    var imageToAdd  = new Image(_idHeaderAll, 0, pageSize.GetTop() - imageHeight, pageSize.GetWidth());
                    imageToAdd.GetAccessibilityProperties().SetRole(StandardRoles.ARTIFACT);
                    imageToAdd.GetAccessibilityProperties()
                    .SetAlternateDescription("Background header image");
                    PdfLayer pdflayer = new PdfLayer("main layer", pdfDoc);

                    pdflayer.SetOn(true);

                    Canvas canvas = new Canvas(pdfCanvas, pdfDoc,
                                               document.GetPageEffectiveArea(pdfDoc.GetDefaultPageSize()));

                    pdfCanvas.BeginLayer(pdflayer);
                    canvas.EnableAutoTagging(page);
                    canvas.Add(imageToAdd);
                    pdfCanvas.EndLayer();
                    pdfCanvas.RestoreState();
                }

                if (_docOptions.HasFlag(DocConverter.DocOptions.AddLineBottomEachPage))
                {
                    //Add line to the bottom
                    Color blueColor = new DeviceCmyk(100, 25, 0, 39);

                    pdfCanvas.SetStrokeColor(blueColor)
                    .MoveTo(36, 36)
                    .LineTo(559, 36)
                    .ClosePathStroke();
                }


                pdfCanvas.Release();
            }
        }
Пример #23
0
        static void Main()
        {
            var clock = new TextBlock();

            var canvas           = new Canvas();
            var textBox          = new TextBox();
            var mainConsole      = new LogPanel();
            var secondaryConsole = new LogPanel();

            var leaderboard = new DataGrid <Player>
            {
                Columns = new[]
                {
                    new DataGrid <Player> .ColumnDefinition("Name", 10, p => p.Name, foreground : p => p.Name == "Tomasz"?(Color?)new Color(100, 100, 220) : null),
                    new DataGrid <Player> .ColumnDefinition("Surname", 10, p => p.Surname),
                    new DataGrid <Player> .ColumnDefinition("Birth date", 15, p => p.BirthDate.ToShortDateString()),
                    new DataGrid <Player> .ColumnDefinition("Points", 5, p => p.Points.ToString(), background : p => p.Points > 20?(Color?)new Color(0, 220, 0) : null)
                },
                Data = new[]
                {
                    new Player("John", "Connor", new DateTime(1985, 2, 28), 10),
                    new Player("Ellen", "Ripley", new DateTime(2092, 1, 1), 23),
                    new Player("Jan", "Kowalski", new DateTime(1990, 4, 10), 50),
                    new Player("Tomasz", "Rewak", new DateTime(1900, 1, 1), 0),
                }
            };

            var tabPanel = new TabPanel();

            tabPanel.AddTab("game", new Box
            {
                HorizontalContentPlacement = Box.HorizontalPlacement.Center,
                VerticalContentPlacement   = Box.VerticalPlacement.Center,
                Content = new Board()
            });

            tabPanel.AddTab("leaderboard", new Box
            {
                HorizontalContentPlacement = Box.HorizontalPlacement.Center,
                VerticalContentPlacement   = Box.VerticalPlacement.Center,
                Content = new Background
                {
                    Color   = new Color(45, 74, 85),
                    Content = new Border
                    {
                        BorderStyle = BorderStyle.Single,
                        Content     = leaderboard
                    }
                }
            });

            tabPanel.AddTab("about", new Box
            {
                HorizontalContentPlacement = Box.HorizontalPlacement.Center,
                VerticalContentPlacement   = Box.VerticalPlacement.Center,
                Content = new Boundary
                {
                    MaxWidth = 20,
                    Content  = new VerticalStackPanel
                    {
                        Children = new IControl[]
                        {
                            new WrapPanel
                            {
                                Content = new TextBlock {
                                    Text = "This is just a demo application that uses a library for creating a GUI in a console."
                                }
                            },
                            new HorizontalSeparator(),
                            new TextBlock {
                                Text = "By Tomasz Rewak.", Color = new Color(200, 200, 200)
                            }
                        }
                    }
                }
            });

            var dockPanel = new DockPanel
            {
                Placement     = DockPanel.DockedControlPlacement.Top,
                DockedControl = new DockPanel
                {
                    Placement     = DockPanel.DockedControlPlacement.Right,
                    DockedControl = new Background
                    {
                        Color   = new Color(100, 100, 100),
                        Content = new Boundary
                        {
                            MinWidth = 20,
                            Content  = new Box
                            {
                                Content = clock,
                                HorizontalContentPlacement = Box.HorizontalPlacement.Center
                            }
                        }
                    },
                    FillingControl = new Background
                    {
                        Color   = ConsoleColor.DarkRed,
                        Content = new Box
                        {
                            Content = new TextBlock {
                                Text = "Center"
                            },
                            HorizontalContentPlacement = Box.HorizontalPlacement.Center
                        }
                    }
                },
                FillingControl = new DockPanel
                {
                    Placement     = DockPanel.DockedControlPlacement.Bottom,
                    DockedControl = new Boundary
                    {
                        MinHeight = 1,
                        MaxHeight = 1,
                        Content   = new Background
                        {
                            Color   = new Color(0, 100, 0),
                            Content = new HorizontalStackPanel
                            {
                                Children = new IControl[] {
                                    new TextBlock {
                                        Text = " 10 ↑ "
                                    },
                                    new VerticalSeparator(),
                                    new TextBlock {
                                        Text = " 5 ↓ "
                                    }
                                }
                            }
                        }
                    },
                    FillingControl = new Overlay
                    {
                        BottomContent = new Background
                        {
                            Color   = new Color(25, 54, 65),
                            Content = new DockPanel
                            {
                                Placement     = DockPanel.DockedControlPlacement.Right,
                                DockedControl = new Background
                                {
                                    Color   = new Color(30, 40, 50),
                                    Content = new Border
                                    {
                                        BorderPlacement = BorderPlacement.Left,
                                        BorderStyle     = BorderStyle.Double.WithColor(new Color(50, 60, 70)),
                                        Content         = new Boundary
                                        {
                                            MinWidth = 50,
                                            MaxWidth = 50,
                                            Content  = new DockPanel
                                            {
                                                Placement     = DockPanel.DockedControlPlacement.Bottom,
                                                DockedControl = new Boundary
                                                {
                                                    MaxHeight = 1,
                                                    Content   = new HorizontalStackPanel
                                                    {
                                                        Children = new IControl[]
                                                        {
                                                            new Style
                                                            {
                                                                Foreground = new Color(150, 150, 200),
                                                                Content    = new TextBlock {
                                                                    Text = @"D:\Software\> "
                                                                }
                                                            },
                                                            textBox
                                                        }
                                                    }
                                                },
                                                FillingControl = new Box
                                                {
                                                    VerticalContentPlacement   = Box.VerticalPlacement.Bottom,
                                                    HorizontalContentPlacement = Box.HorizontalPlacement.Stretch,
                                                    Content = mainConsole
                                                }
                                            }
                                        }
                                    }
                                },
                                FillingControl = new DockPanel
                                {
                                    Placement     = DockPanel.DockedControlPlacement.Right,
                                    DockedControl = new Background
                                    {
                                        Color   = new Color(20, 30, 40),
                                        Content = new Border
                                        {
                                            BorderPlacement = BorderPlacement.Left,
                                            BorderStyle     = BorderStyle.Double.WithColor(new Color(50, 60, 70)),
                                            Content         = new Boundary
                                            {
                                                MinWidth = 30,
                                                MaxWidth = 30,
                                                Content  = new Box
                                                {
                                                    VerticalContentPlacement   = Box.VerticalPlacement.Bottom,
                                                    HorizontalContentPlacement = Box.HorizontalPlacement.Stretch,
                                                    Content = secondaryConsole
                                                }
                                            }
                                        }
                                    },
                                    FillingControl = tabPanel
                                }
                            }
                        },
                        TopContent = new Box
                        {
                            HorizontalContentPlacement = Box.HorizontalPlacement.Center,
                            VerticalContentPlacement   = Box.VerticalPlacement.Center,
                            Content = new Boundary
                            {
                                Width   = 41,
                                Height  = 12,
                                Content = canvas
                            }
                        }
                    }
                }
            };

            var scrollPanel = new VerticalScrollPanel
            {
                Content = new SimpleDecorator
                {
                    Content = new VerticalStackPanel
                    {
                        Children = new IControl[]
                        {
                            new WrapPanel {
                                Content = new TextBlock {
                                    Text = "Here is a short example of text wrapping"
                                }
                            },
                            new HorizontalSeparator(),
                            new WrapPanel {
                                Content = new TextBlock {
                                    Text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
                                }
                            },
                        }
                    }
                }
            };

            canvas.Add(new Background
            {
                Color   = new Color(10, 10, 10),
                Content = new VerticalStackPanel
                {
                    Children = new IControl[]
                    {
                        new Border
                        {
                            BorderPlacement = BorderPlacement.Left | BorderPlacement.Top | BorderPlacement.Right,
                            BorderStyle     = BorderStyle.Double.WithColor(new Color(80, 80, 120)),
                            Content         = new Box
                            {
                                HorizontalContentPlacement = Box.HorizontalPlacement.Center,
                                Content = new TextBlock {
                                    Text = "Popup 1", Color = new Color(200, 200, 100)
                                }
                            }
                        },
                        new Border
                        {
                            BorderPlacement = BorderPlacement.All,
                            BorderStyle     = BorderStyle.Double.WithTopLeft(new Character('╠')).WithTopRight(new Character('╣')).WithColor(new Color(80, 80, 120)),
                            Content         = scrollPanel
                        }
                    }
                }
            }, new Rect(11, 0, 30, 10));

            canvas.Add(new Background
            {
                Color   = new Color(10, 40, 10),
                Content = new Border
                {
                    Content = new Box
                    {
                        HorizontalContentPlacement = Box.HorizontalPlacement.Center,
                        VerticalContentPlacement   = Box.VerticalPlacement.Center,
                        Content = new TextBlock {
                            Text = "Popup 2"
                        }
                    }
                }
            }, new Rect(0, 7, 17, 5));

            ConsoleManager.Setup();
            ConsoleManager.Resize(new Size(150, 40));
            ConsoleManager.Content = dockPanel;

            var input = new IInputListener[]
            {
                scrollPanel,
                tabPanel,
                new InputController(textBox, mainConsole),
                textBox
            };

            for (int i = 0; ; i++)
            {
                Thread.Sleep(10);

                clock.Text = DateTime.Now.ToLongTimeString();
                if (i % 200 == 0)
                {
                    secondaryConsole.Add($"Ping {i / 200 + 1}");
                }

                ConsoleManager.ReadInput(input);
                ConsoleManager.AdjustBufferSize();
            }
        }
Пример #24
0
        public void CharacterIndexGenerator()
        {
            //Se incluyen los caracteres no las palabras
            //List<Word> arrayIncluded = ToList(includedWords);

            int index = 0;

            //Hay que obtener caracter a caracter no las palabras TODO

            //INICIO DOCUMENTO PDF
            PdfWriter   writer   = new PdfWriter(@"D:\\HSKBooklet\" + this.pathLevel + "CaracterIndex.pdf");
            PdfDocument pdf      = new PdfDocument(writer);
            Document    document = new Document(pdf, PageSize.A4);

            const String FONT      = @"C:\Windows\Fonts\STKAITI.TTF";
            PdfFont      fontKaiti = PdfFontFactory.CreateFont(FONT, PdfEncodings.IDENTITY_H, PdfFontFactory.EmbeddingStrategy.FORCE_EMBEDDED, true);

            document.SetFont(fontKaiti);

            //TABLA DE CONTENIDO

            //Se añade el Tipo de palabra
            //Una columna mas.
            var   DimensionesColumnas = new float[] { 5, 20, 20, 50, 5, 10, 15 };
            Table table      = new Table(UnitValue.CreatePercentArray(DimensionesColumnas));
            float tablewidth = 95;

            //table.UseAllAvailableWidth();
            //Se ajusta el margen del indice a 90% de la pagina
            table.SetWidth(UnitValue.CreatePercentValue(tablewidth));
            table.SetMarginLeft(5);



            //Se usara para el salto de pagina
            int rowCount      = 0;
            int SetMarginTopP = 10;
            int SetHeightP    = 30;
            //Caracteres ordenados alfabeticamente
            var OrderedChars = includedChars.OrderBy(x => x.Pinyin);

            foreach (Word character in OrderedChars)

            {
                index++;
                bool first = true;
                foreach (Word_HSK word in includedWords)
                {
                    //Add row to table
                    if (word.Character.Contains(character.Character))
                    {
                        //El caracter aparece en la palabra word
                        //En la pagina index

                        // Adding cell 1 to the table
                        if (first)
                        {
                            Cell cell1 = new Cell();   // Creating a cell
                            cell1.Add(new Paragraph(character.Character).SetHeight(SetHeightP).SetFont(fontKaiti).SetBold().SetFontSize(20).SetTextAlignment(TextAlignment.LEFT).SetVerticalAlignment(VerticalAlignment.MIDDLE));
                            table.AddCell(cell1);      // Adding cell to the table

                            first = false;
                        }
                        else
                        {
                            Cell cell1 = new Cell();
                            cell1.Add(new Paragraph(" ").SetHeight(SetHeightP).SetFont(fontKaiti).SetBold().SetFontSize(30).SetTextAlignment(TextAlignment.LEFT));
                            table.AddCell(cell1);
                        }
                        //Palabra que lo usa
                        Cell cell2 = new Cell();
                        cell2.Add(new Paragraph(word.Character).SetFont(fontKaiti).SetFontSize(20).SetTextAlignment(TextAlignment.CENTER).SetVerticalAlignment(VerticalAlignment.MIDDLE));
                        table.AddCell(cell2);

                        Cell cellPinyin = new Cell();
                        cellPinyin.Add(new Paragraph(word.Pinyin).SetFont(fontKaiti).SetFontSize(10).SetMarginTop(SetMarginTopP).SetTextAlignment(TextAlignment.CENTER).SetVerticalAlignment(VerticalAlignment.MIDDLE));
                        table.AddCell(cellPinyin);

                        Cell cell3 = new Cell();
                        cell3.Add(new Paragraph(word.Description).SetFontSize(10).SetMarginLeft(20).SetMarginTop(SetMarginTopP).SetTextAlignment(TextAlignment.LEFT).SetVerticalAlignment(VerticalAlignment.MIDDLE));
                        table.AddCell(cell3);

                        Cell cellType = new Cell();
                        cellType.Add(new Paragraph(word.Type).SetFontSize(10).SetMarginTop(SetMarginTopP).SetTextAlignment(TextAlignment.LEFT).SetVerticalAlignment(VerticalAlignment.MIDDLE));
                        table.AddCell(cellType);


                        Cell cell4 = new Cell();
                        cell4.Add(new Paragraph("HSK " + word.Level.ToString()).SetFontSize(10).SetMarginTop(SetMarginTopP).SetTextAlignment(TextAlignment.CENTER).SetVerticalAlignment(VerticalAlignment.MIDDLE));
                        table.AddCell(cell4);

                        Cell cell5 = new Cell();
                        cell5.Add(new Paragraph("Pag. " + index.ToString()).SetFontSize(10).SetMarginTop(SetMarginTopP).SetTextAlignment(TextAlignment.CENTER).SetVerticalAlignment(VerticalAlignment.MIDDLE));
                        table.AddCell(cell5);

                        rowCount++;

                        //Salto de linea
                        if (rowCount == 21)
                        {
                            PdfCanvas pdfCanvas = new PdfCanvas(pdf.AddNewPage());
                            Canvas    canvas    = new Canvas(pdfCanvas, pdf, document.GetPageEffectiveArea(pdf.GetDefaultPageSize()));
                            canvas.Add(table);

                            rowCount = 0;

                            table = new Table(UnitValue.CreatePercentArray(DimensionesColumnas));
                            //table.UseAllAvailableWidth();
                            //Se ajusta el margen del indice a 90% de la pagina
                            table.SetWidth(UnitValue.CreatePercentValue(tablewidth));
                        }
                    }
                }


                string sIndex = NumeroCuadrado(index, 3);
            }


            PdfCanvas pdfCanvasend = new PdfCanvas(pdf.AddNewPage());
            Canvas    canvasend    = new Canvas(pdfCanvasend, pdf, document.GetPageEffectiveArea(pdf.GetDefaultPageSize()));

            canvasend.Add(table);

            //Se añade una pagina en blanco al lomo de caracteres solo si es impar
            if (pdf.GetNumberOfPages() % 2 == 0)
            {
                PdfCanvas pdfCanvas = new PdfCanvas(pdf.AddNewPage());
            }

            document.Close();
        }
        public FrameworkElement Big(TagPrintable line)
        {
            var canvas = new Canvas {
                Width  = 162,
                Height = 106,
            };
            var nameAndAddressLabel = new TextBlock {
                Text          = $"{line.ClientName}, {line.AddressName}",
                TextAlignment = TextAlignment.Center,
                TextWrapping  = TextWrapping.Wrap,
                FontSize      = 8,
                Width         = 162,
                Height        = 20
            };

            nameAndAddressLabel.SetValue(Canvas.LeftProperty, 0d);
            nameAndAddressLabel.SetValue(Canvas.TopProperty, 0d);
            canvas.Children.Add(new Border {
                BorderThickness = new Thickness(0, 0, 0, 1),
                BorderBrush     = Brushes.Black,
                Child           = nameAndAddressLabel
            });

            var product = new TextBlock {
                Text            = $"{line.Product}\n{line.Producer}",
                FontSize        = 11,
                FontWeight      = FontWeights.Bold,
                TextDecorations = TextDecorations.Underline,
                TextWrapping    = TextWrapping.Wrap,
                TextAlignment   = TextAlignment.Center,
                Height          = 37,
                Width           = 160
            };

            product.SetValue(Canvas.LeftProperty, 0d);
            product.SetValue(Canvas.TopProperty, 21d);
            canvas.Children.Add(product);

            var cost = new TextBlock {
                Text              = FormatCost(line),
                Width             = 112,
                FontSize          = 26,
                FontWeight        = FontWeights.Bold,
                TextAlignment     = TextAlignment.Right,
                VerticalAlignment = VerticalAlignment.Bottom,
            };

            cost.SetValue(Canvas.LeftProperty, 49d);
            cost.SetValue(Canvas.TopProperty, 78d);
            canvas.Children.Add(cost);

            canvas.Add(0, 68, new TextBlock {
                TextAlignment = TextAlignment.Right,
                FontSize      = 8,
                Text          = "Годен до",
                Width         = 49,
            });

            canvas.Add(0, 76, new TextBlock {
                TextAlignment = TextAlignment.Right,
                FontSize      = 9,
                Text          = line.Period,
                Width         = 49,
            });

            canvas.Add(0, 86, new TextBlock {
                FontSize = 8,
                Text     = "Подпись",
                Width    = 49,
            });

            canvas.Add(0, 94, new TextBlock {
                FontSize = 9,
                Text     = DateTime.Now.ToShortDateString(),
                Width    = 49,
            });

            ApplyDefaults(canvas);

            return(canvas);
        }
        public void AddCaracterPage(string c, PdfDocument pdf, Document document, string sIndex)
        {
            //GENERAR CARACTER
            SaveBitmapfromFontChar(c, "Kaiti", FontStyle.Regular, sIndex);
            PdfCanvas pdfCanvas = new PdfCanvas(pdf.AddNewPage());

            Canvas canvas = new Canvas(pdfCanvas, pdf, document.GetPageEffectiveArea(pdf.GetDefaultPageSize()));


            //Layer 1
            PdfLayer pdflayer1 = new PdfLayer("Layer 1", pdf);

            pdflayer1.SetOn(true);
            pdfCanvas.BeginLayer(pdflayer1);

            ///Template IMG
            string template = @"D:\Portada\Cuadernos\PNG A4\Mizige DIN A4 Template HSK - Pie Descripcion 2 lines more.png";

            ImageData data = ImageDataFactory.Create(template);

            iText.Layout.Element.Image img = new iText.Layout.Element.Image(ImageDataFactory.Create(template))
                                             .ScaleToFit(PageSize.A4.GetWidth(), PageSize.A4.GetHeight())
                                             .SetFixedPosition(0, 0);
            canvas.Add(img);
            pdfCanvas.EndLayer();

            //Layer 2 CARACTER GRANDE
            PdfLayer pdflayer2 = new PdfLayer("Layer 2", pdf);

            pdflayer2.SetOn(true);
            pdfCanvas.BeginLayer(pdflayer2);

            //Para poner una imagen con 300 ppp, use una escala de 72 / 300 = 24 % .Por ejemplo:
            //si tiene una imagen de 5 x 5 pulgadas que escanea a 300 ppp, la
            //imagen resultante es de 1500 x 1500 píxeles(5 x 300 = 1500).Cuando coloca esta imagen en
            //el pdf con una escala del 24 % (72 / 300 = 0.24), la imagen en el pdf será de
            //5X5 pulgadas con 1500X1500 píxeles a 300 dpi.La imagen siempre será de
            //1500X1500 píxeles sea cual sea el tamaño.

            int LeftMarginMiZige = 114 * 72 / 300 - 20;
            int UpMarginMiZige   = 114 * 72 / 300 - 5;
            int CaracterSize     = 180;

            //Este es el path con el que se ha grabado la imagen previamente
            string path = @"D:\HSKBooklet\" + sIndex + "_" + c.ToString() + ".png";

            iText.Layout.Element.Image MainCaracter = new iText.Layout.Element.Image(ImageDataFactory.Create(path))
                                                      .SetFixedPosition(LeftMarginMiZige, PageSize.A4.GetHeight() - CaracterSize - UpMarginMiZige)
                                                      .ScaleAbsolute(CaracterSize, CaracterSize)
                                                      .SetTextAlignment(TextAlignment.CENTER);
            canvas.Add(MainCaracter);
            pdfCanvas.EndLayer();



            //Layer 4 CARACTER PEQUEÑOS FOR
            PdfLayer pdflayer4 = new PdfLayer("Layer 4", pdf);

            pdflayer4.SetOn(true);
            pdfCanvas.BeginLayer(pdflayer4);



            //int MaxColumns = 17;
            //int MaxRows = 26;
            int MiniCaracterSize = 30;
            int MaxColumns       = 17;
            int MaxRows          = 17;

            float width              = 30.6F;
            float height             = 30.7F;
            int   InitialLeftMargin  = 35;
            int   UpMarginMiZigeMini = 22;

            float left   = 0;
            float bottom = 0;

            iText.Layout.Element.Image MiniCaracter = new iText.Layout.Element.Image(ImageDataFactory.Create(path));
            MiniCaracter.ScaleAbsolute(MiniCaracterSize, MiniCaracterSize);
            MiniCaracter.SetTextAlignment(TextAlignment.CENTER);
            MiniCaracter.SetTextAlignment(TextAlignment.CENTER);

            for (int col = 0; col < MaxColumns; col++)

            {
                for (int row = 0; row < MaxRows; row++)
                {
                    //No se imprimen donde esta en caracter grande situado
                    if (!(row < 5 && col < 5))
                    {
                        left   = 35 + col * width;
                        bottom = PageSize.A4.GetHeight() - MiniCaracterSize - 2 - UpMarginMiZigeMini - row * height;

                        //iText.Layout.Element.Image MiniCaracter = new iText.Layout.Element.Image(ImageDataFactory.Create(path))
                        MiniCaracter.SetFixedPosition(left, bottom);
                        canvas.Add(MiniCaracter);
                    }
                }
            }
            pdfCanvas.EndLayer();

            //INFORMACION CARACTER

            //Se incluyen los caracteres no las palabras
            List <Word> arrayIncluded = ToList(includedWords);


            document.SetFont(fontKaiti);

            var   dimensionsColumns = new float[] { 1, 1, 1, 1, 1, 1 };
            Table table             = new Table(UnitValue.CreatePercentArray(dimensionsColumns));

            table.UseAllAvailableWidth();

            PdfLayer pdflayerInfo = new PdfLayer("pdflayerInfo", pdf);

            pdflayerInfo.SetOn(true);
            pdfCanvas.BeginLayer(pdflayerInfo);
            int repeticion = 0;

            List <Paragraph> pGlobals = new List <Paragraph>();

            foreach (Word_HSK word in arrayIncluded)
            {
                //Add row to table
                if (word.Character.Contains(c))
                {
                    repeticion++;

                    Paragraph pGlobal = new Paragraph(word.Character + "\t (" + word.Pinyin + ") , " + word.Description).SetFont(fontKaiti).SetFontSize(10);


                    pGlobals.Add(pGlobal);
                }
            }


            if (repeticion > Maxrepeticion)
            {
                Maxrepeticion = repeticion;
                repeticion    = 0;
                int checkLevel = Level;
            }

            int rowspan = 1;
            int colspan;


            int PalabrasPorFila = 0;

            if (pGlobals.Count <= 4)
            {
                colspan         = 6;
                PalabrasPorFila = 1;
            }
            else if ((pGlobals.Count > 4) && (pGlobals.Count <= 8))
            {
                colspan         = 3;
                PalabrasPorFila = 2;
            }
            else
            {
                colspan         = 2;
                PalabrasPorFila = 3;
            }


            //En blanco antes del numero de pagina

            double Count        = pGlobals.Count;
            double doubleplarba = PalabrasPorFila;
            int    NumeroFilas  = (int)Math.Ceiling(Count / PalabrasPorFila);


            int nwhite = 4 - NumeroFilas;

            int Height  = 14;
            int Columns = 6;                          //Se utiliza para graduar al colspan anterior
            //Celdas en blanco hasta el final del documento
            int FilasBlancasAntesdepalabras = 33 + 4; //Al añadir dos filas mas a la plantilla

            for (int x = 0; x < FilasBlancasAntesdepalabras * Columns; x++)
            {
                Cell cellWhite = new Cell();  // Creating a cell
                cellWhite.SetHeight(Height).Add(new Paragraph(" "));
                table.AddCell(cellWhite);     // Adding cell to the table
            }

            foreach (Paragraph p in pGlobals)
            {
                Cell cellGlobal = new Cell(rowspan, colspan);
                cellGlobal.SetHeight(Height).Add(p);
                table.AddCell(cellGlobal);
            }

            RemoveBorder(table);
            canvas.Add(table);


            Table tableNumberPage = new Table(UnitValue.CreatePercentArray(new float[] { 100 }));

            tableNumberPage.UseAllAvailableWidth();

            for (int x = 0; x < nwhite; x++)
            {
                Cell cellWhite = new Cell();        // Creating a cell
                cellWhite.SetHeight(Height).Add(new Paragraph(" ").SetHeight(Height));
                tableNumberPage.AddCell(cellWhite); // Adding cell to the table
            }

            Cell cellNumberPage = new Cell();   // Creating a cell

            cellNumberPage.SetHeight(Height).Add(new Paragraph(sIndex).SetFontSize(10).SetTextAlignment(TextAlignment.CENTER).SetFont(fontKaiti));
            tableNumberPage.AddCell(cellNumberPage);      // Adding cell to the table

            RemoveBorder(tableNumberPage);
            canvas.Add(tableNumberPage);
            pdfCanvas.EndLayer();
        }
Пример #27
0
        public Tuple <float, float> AddDependentVowelPage(string c, PdfDocument pdf, Document document, string sIndex)
        {
            const String FONT      = @"C:\Windows\Fonts\STKAITI.TTF";
            PdfFont      fontKaiti = PdfFontFactory.CreateFont(FONT, PdfEncodings.IDENTITY_H, PdfFontFactory.EmbeddingStrategy.FORCE_EMBEDDED, true);

            //GENERAR CARACTER
            Tuple <float, float> textSize  = SaveBitmapfromFontCharVowel(c, "Kaiti", FontStyle.Regular, sIndex);
            PdfCanvas            pdfCanvas = new PdfCanvas(pdf.AddNewPage());

            Canvas canvas = new Canvas(pdfCanvas, pdf, document.GetPageEffectiveArea(pdf.GetDefaultPageSize()));


            //Layer 1
            PdfLayer pdflayer1 = new PdfLayer("Layer 1", pdf);

            pdflayer1.SetOn(true);
            pdfCanvas.BeginLayer(pdflayer1);

            ///Template IMG
            string template = @"D:\Portada\Cuadernos\PNG A4\Mizige DIN A4 Template HSK - Pie Descripcion 2 lines more.png";

            ImageData data = ImageDataFactory.Create(template);

            iText.Layout.Element.Image img = new iText.Layout.Element.Image(ImageDataFactory.Create(template))
                                             .ScaleToFit(PageSize.A4.GetWidth(), PageSize.A4.GetHeight())
                                             .SetFixedPosition(0, 0);
            canvas.Add(img);
            pdfCanvas.EndLayer();

            //Layer 2 CARACTER GRANDE
            PdfLayer pdflayer2 = new PdfLayer("Layer 2", pdf);

            pdflayer2.SetOn(true);
            pdfCanvas.BeginLayer(pdflayer2);

            int LeftMarginMiZige = 114 * 72 / 300 - 20;
            int UpMarginMiZige   = 114 * 72 / 300 - 5;
            // int CaracterSize = 180;

            int CaracterSize = 200;

            //Este es el path con el que se ha grabado la imagen previamente
            string path = @"D:\KH\KhmerWorkbook\Chars\" + c.ToString() + ".png";

            iText.Layout.Element.Image MainCaracter = new iText.Layout.Element.Image(ImageDataFactory.Create(path))
                                                      .SetFixedPosition(LeftMarginMiZige, PageSize.A4.GetHeight() - CaracterSize - UpMarginMiZige)
                                                      .ScaleAbsolute(CaracterSize, CaracterSize)
                                                      .SetTextAlignment(TextAlignment.CENTER);
            canvas.Add(MainCaracter);
            pdfCanvas.EndLayer();



            //Layer 4 CARACTER PEQUEÑOS FOR
            PdfLayer pdflayer4 = new PdfLayer("Layer 4", pdf);

            pdflayer4.SetOn(true);
            pdfCanvas.BeginLayer(pdflayer4);

            int MiniCaracterSize = 30;
            int MaxColumns       = 17;
            int MaxRows          = 17;

            float width              = 30.6F;
            float height             = 30.7F;
            int   UpMarginMiZigeMini = 22;

            float left   = 0;
            float bottom = 0;

            iText.Layout.Element.Image MiniCaracter = new iText.Layout.Element.Image(ImageDataFactory.Create(path));
            MiniCaracter.ScaleAbsolute(MiniCaracterSize, MiniCaracterSize);
            MiniCaracter.SetTextAlignment(TextAlignment.CENTER);

            for (int col = 0; col < MaxColumns; col++)

            {
                for (int row = 0; row < MaxRows; row++)
                {
                    //No se imprimen donde esta en caracter grande situado
                    if (!(row < 5 && col < 5))
                    {
                        left   = 35 + col * width;
                        bottom = PageSize.A4.GetHeight() - MiniCaracterSize - 2 - UpMarginMiZigeMini - row * height;
                        MiniCaracter.SetFixedPosition(left, bottom);
                        canvas.Add(MiniCaracter);
                    }
                }
            }
            pdfCanvas.EndLayer();

            //INFORMACION CARACTER

            document.SetFont(fontKaiti);

            var   dimensionsColumns = new float[] { 1, 1, 1, 1, 1, 1 };
            Table table             = new Table(UnitValue.CreatePercentArray(dimensionsColumns));

            table.UseAllAvailableWidth();

            PdfLayer pdflayerInfo = new PdfLayer("pdflayerInfo", pdf);

            pdflayerInfo.SetOn(true);
            pdfCanvas.BeginLayer(pdflayerInfo);
            int repeticion = 0;

            List <Paragraph> pGlobals = new List <Paragraph>();

            foreach (Word_HSK word in includedWords)
            {
                //Add row to table
                if (word.Character.Contains(c))
                {
                    repeticion++;

                    Paragraph pGlobal = new Paragraph(word.Character + "\t (" + word.Pinyin + ") , " + word.Type + " , " + word.Description).SetFont(fontKaiti).SetFontSize(10);

                    pGlobals.Add(pGlobal);
                }
            }


            if (repeticion > Maxrepeticion)
            {
                Maxrepeticion = repeticion;
                repeticion    = 0;
                int checkLevel = Level;
            }

            int rowspan = 1;
            int colspan;


            int PalabrasPorFila = 0;

            if (pGlobals.Count <= 4)
            {
                colspan         = 6;
                PalabrasPorFila = 1;
            }
            else if ((pGlobals.Count > 4) && (pGlobals.Count <= 8))
            {
                colspan         = 3;
                PalabrasPorFila = 2;
            }
            else
            {
                colspan         = 2;
                PalabrasPorFila = 3;
            }


            //En blanco antes del numero de pagina

            double Count        = pGlobals.Count;
            double doubleplarba = PalabrasPorFila;
            int    NumeroFilas  = (int)Math.Ceiling(Count / PalabrasPorFila);


            int nwhite = 4 - NumeroFilas;

            int Height  = 14;
            int Columns = 6;                          //Se utiliza para graduar al colspan anterior
            //Celdas en blanco hasta el final del documento
            int FilasBlancasAntesdepalabras = 33 + 4; //Al añadir dos filas mas a la plantilla

            for (int x = 0; x < FilasBlancasAntesdepalabras * Columns; x++)
            {
                Cell cellWhite = new Cell();  // Creating a cell
                cellWhite.SetHeight(Height).Add(new Paragraph(" "));
                table.AddCell(cellWhite);     // Adding cell to the table
            }

            foreach (Paragraph p in pGlobals)
            {
                Cell cellGlobal = new Cell(rowspan, colspan);
                cellGlobal.SetHeight(Height).Add(p);
                table.AddCell(cellGlobal);
            }

            RemoveBorder(table);
            canvas.Add(table);


            Table tableNumberPage = new Table(UnitValue.CreatePercentArray(new float[] { 100 }));

            tableNumberPage.UseAllAvailableWidth();

            for (int x = 0; x < nwhite; x++)
            {
                Cell cellWhite = new Cell();        // Creating a cell
                cellWhite.SetHeight(Height).Add(new Paragraph(" ").SetHeight(Height));
                tableNumberPage.AddCell(cellWhite); // Adding cell to the table
            }

            Cell cellNumberPage = new Cell();   // Creating a cell

            cellNumberPage.SetHeight(Height).Add(new Paragraph(sIndex).SetFontSize(10).SetTextAlignment(TextAlignment.CENTER).SetFont(fontKaiti));
            tableNumberPage.AddCell(cellNumberPage);      // Adding cell to the table

            RemoveBorder(tableNumberPage);
            canvas.Add(tableNumberPage);
            pdfCanvas.EndLayer();


            return(textSize);
        }
Пример #28
0
        public static byte[] Sign(IExternalSignature externalSignature, X509Certificate[] certChain, string src, string friendlyName, string subject, string sourceName, string documentLink, string documentName)
        {
            int numberOfSignatures = 0;
            int numberOfPages      = 0;

            using (PdfReader reader = new PdfReader(src))
            {
                using (PdfDocument pdf = new PdfDocument(reader))
                {
                    numberOfPages = pdf.GetNumberOfPages();

                    PdfAcroForm form = PdfAcroForm.GetAcroForm(pdf, false);
                    if (form != null)
                    {
                        foreach (var field in form.GetFormFields())
                        {
                            if (field.Value is iText.Forms.Fields.PdfSignatureFormField)
                            {
                                numberOfSignatures++;
                            }
                        }
                    }
                }
            }

            if (numberOfSignatures == 0)
            {
                string hash = GetMD5HashFromFile(src);

                src            = AddPage(src, sourceName, documentLink, documentName, hash);
                numberOfPages += 1;
            }

            float posSignY = 615 - (numberOfSignatures * 70);

            using (PdfReader reader = new PdfReader(src))
            {
                StampingProperties stampingProperties = new StampingProperties();
                stampingProperties.UseAppendMode();

                using (MemoryStream ms = new MemoryStream())
                {
                    PdfSigner signer =
                        new PdfSigner(reader, ms, stampingProperties);

                    Rectangle rect = new Rectangle(36, posSignY, 520, 65);

                    PdfSignatureAppearance appearance = signer.GetSignatureAppearance();
                    appearance
                    .SetPageRect(rect)
                    .SetPageNumber(numberOfPages)
                    .SetCertificate(certChain[0]);

                    PdfFormXObject n2     = appearance.GetLayer2();
                    Canvas         canvas = new Canvas(n2, signer.GetDocument());

                    canvas.Add(new Paragraph(friendlyName).SetMargin(0));
                    canvas.Add(new Paragraph("Assinado digitalmente por: " + friendlyName).SetFontSize(10).SetMargin(0));
                    canvas.Add(new Paragraph("Data: " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss \"GMT\"zzz")).SetFontSize(10).SetMargin(0));
                    canvas.Add(new Paragraph("Subject: " + subject).SetFontSize(10).SetMargin(0));

                    signer.SignDetached(externalSignature, certChain, null, null, null, 0,
                                        PdfSigner.CryptoStandard.CADES);

                    return(ms.ToArray());
                }
            }
        }
        public void AddPentagonCommandTest()
        {
            UndoRedoManager manager = new UndoRedoManager();
            Canvas          canvas  = new Canvas();

            Assert.AreEqual(0, canvas.Count);

            Pentagon first;

            Vertex[] arrVertices = new Vertex[Pentagon.NUM_OF_EDGE_IN_PENTAGON];
            arrVertices[0] = new Vertex
            {
                Location = new System.Windows.Point(0, 1)
            };
            arrVertices[1] = new Vertex
            {
                Location = new System.Windows.Point(3, 1)
            };
            arrVertices[2] = new Vertex
            {
                Location = new System.Windows.Point(1.5, -4)
            };
            arrVertices[3] = new Vertex
            {
                Location = new System.Windows.Point(1, 5)
            };
            arrVertices[4] = new Vertex
            {
                Location = new System.Windows.Point(6, -2)
            };
            for (int i = 0; i < arrVertices.Length; ++i)
            {
                canvas.Add(arrVertices[i]);
            }
            Assert.AreEqual(5, canvas.Count);
            for (int i = 0; i < arrVertices.Length; ++i)
            {
                Assert.IsTrue(canvas.Contains(arrVertices[i]));
            }

            Shapes.Commands.Pentagon.AddPentagon addPentagonCommand =
                new Shapes.Commands.Pentagon.AddPentagon(canvas);

            manager.Execute(addPentagonCommand);

            Assert.AreEqual(1, canvas.Count);
            for (int i = 0; i < arrVertices.Length; ++i)
            {
                Assert.IsFalse(canvas.Contains(arrVertices[i]));
            }

            Assert.IsTrue(canvas[0] is Pentagon);
            first = (Pentagon)canvas[0];
            for (int i = 0; i < arrVertices.Length; ++i)
            {
                Assert.IsTrue(first.Points.Contains(arrVertices[i].Location));
            }

            manager.Undo();
            Assert.AreEqual(4, canvas.Count);
            for (int i = 0; i < arrVertices.Length - 1; ++i)
            {
                Assert.IsTrue(canvas.Contains(arrVertices[i]));
            }

            manager.Redo();
            Assert.AreEqual(1, canvas.Count);
            for (int i = 0; i < arrVertices.Length; ++i)
            {
                Assert.IsFalse(canvas.Contains(arrVertices[i]));
            }

            Assert.IsTrue(canvas[0] is Pentagon);
            first = (Pentagon)canvas[0];
            for (int i = 0; i < arrVertices.Length; ++i)
            {
                Assert.IsTrue(first.Points.Contains(arrVertices[i].Location));
            }
        }
 // Restores a shape to the canvas a an "Undo" action
 public override void Undo()
 {
     canvas.Add(shape);
 }
Пример #31
0
        protected override void OnInitialize()
        {
            SpriteFont font = game.Content.Load <SpriteFont>("default");

            background = new SpriteBox(game);

            background.Renderer = new DisortSpriteRenderer(background,
                                                           minX: -5.0f,
                                                           maxX: 5.0f,
                                                           minY: -5.0f,
                                                           maxY: 5.0f);

            background.Sprite        = new Sprite(game.Content.Load <Texture2D>("taustatemp"));
            background.SizeBehaviour = Gui.SizeBehaviour.OverwriteBoth;
            background.Size          = new Vector2(105f);
            background.Position      = new Vector2(-5f, -5f);

            background.DisableFocusing();

            root      = new Canvas(game);
            root.Size = new Vector2(100f);
            root.Add(background);

            grid = new Grid(game)
            {
                Rows    = 6,
                Columns = 4
            };

            grid.SetRowHeight(0, 25f);
            grid.SetRowHeight(1, 25f);
            grid.SetRowHeight(2, 10f);
            grid.SetRowHeight(3, 10f);
            grid.SetRowHeight(4, 10f);

            grid.SetColumnWidth(0, 5f);

            root.Add(grid);

            header = new Label(game)
            {
                Font          = font,
                Text          = "Massacre simulator 3000",
                Brush         = new Brush(Color.White),
                SizeBehaviour = SizeBehaviour.OverwriteBoth,
                Size          = new Vector2(100f, 55f)
            };

            start = new Button(game)
            {
                // TODO: continue tai start riippuen siitä onko pelissä jo save file.
                Text                    = "Start",
                TextColor               = Color.White,
                Font                    = font,
                SizeBehaviour           = Gui.SizeBehaviour.OverwriteBoth,
                VerticalAlingment       = Vertical.Center,
                HorizontalAlingment     = Horizontal.Left,
                Brush                   = new Gui.Brush(Color.Transparent),
                TextSize                = new Vector2(55f, 45f),
                Size                    = new Vector2(25f, 100f),
                TextHorizontalAlingment = Horizontal.Left
            };

            start.MouseButtonDown += start_MouseButtonDown;
            start.ButtonPressed   += start_ButtonPressed;

            options = new Button(game)
            {
                Text                    = "Options",
                TextColor               = Color.White,
                Font                    = font,
                SizeBehaviour           = Gui.SizeBehaviour.OverwriteBoth,
                VerticalAlingment       = Vertical.Center,
                HorizontalAlingment     = Horizontal.Left,
                Brush                   = new Gui.Brush(Color.Transparent),
                TextSize                = new Vector2(55f, 45f),
                Size                    = new Vector2(25f, 100f),
                TextHorizontalAlingment = Horizontal.Left
            };

            options.MouseButtonDown += options_MouseButtonDown;
            options.ButtonPressed   += options_ButtonPressed;

            exit = new Button(game)
            {
                Text                    = "Exit",
                TextColor               = Color.White,
                Font                    = font,
                SizeBehaviour           = Gui.SizeBehaviour.OverwriteBoth,
                VerticalAlingment       = Vertical.Center,
                HorizontalAlingment     = Horizontal.Left,
                Brush                   = new Gui.Brush(Color.Transparent),
                TextSize                = new Vector2(45f, 45f),
                Size                    = new Vector2(25f, 100f),
                TextHorizontalAlingment = Horizontal.Left
            };

            exit.MouseButtonDown += exit_MouseButtonDown;
            exit.ButtonPressed   += exit_ButtonPressed;

            grid.SetColumnWidth(1, 50f);

            grid.Add(header, 0, 1);
            grid.Add(start, 2, 1);
            grid.Add(options, 3, 1);
            grid.Add(exit, 4, 1);

            SetContent(root);
        }
Пример #32
-1
        public void TestDrawCanvas()
        {
            Canvas c = new Canvas
                {
                    Height = 10,
                    Width = 12
                };

            c.Add(new Box {Side = 5});
            c.Add(new Circle {Radius = 12});

            IVisitor<Shape> visitor = _container.Resolve<IVisitor<Shape>>("Draw");

            c.Accept(visitor);

            A.CallTo(() => _graphics.DrawRectangle(10, 12)).MustHaveHappened();
            A.CallTo(() => _graphics.DrawBox(5)).MustHaveHappened();
            A.CallTo(() => _graphics.DrawCircle(12)).MustHaveHappened();
        }
Пример #33
-1
        public void TestDrawCanvasWithNewShapeWithCustomVisitor()
        {
            Canvas c = new Canvas
                {
                    Height = 10,
                    Width = 12
                };

            MyShape myShape = new MyShape {SomeData = 3};

            c.Add(new Box {Side = 5});
            c.Add(myShape);

            IVisitor<MyShape> customShapeVisitor = A.Fake<IVisitor<MyShape>>();

            _container.RegisterInstance("Draw", customShapeVisitor);

            var visitor = _container.Resolve<IVisitor<Shape>>("Draw");

            c.Accept(visitor);

            A.CallTo(() => _graphics.DrawRectangle(10, 12)).MustHaveHappened(Repeated.Exactly.Once);
            A.CallTo(() => _graphics.DrawBox(5)).MustHaveHappened(Repeated.Exactly.Once);
            A.CallTo(() => _graphics.DrawCircle(0)).WithAnyArguments().MustNotHaveHappened();
            A.CallTo(() => customShapeVisitor.Visit(myShape)).MustHaveHappened(Repeated.Exactly.Once);
        }