Exemple #1
0
        private static List <GraphicState> DisableUIGraphics(Canvas canvas)
        {
            List <GraphicState> graphicStates = new List <GraphicState>();
            List <Graphic>      graphics      = new List <Graphic>();

            graphics.AddRange(canvas.GetComponentsInChildren <Graphic>());
            graphics.RemoveAll(g => !g.enabled);
            foreach (Graphic g in graphics)
            {
                GraphicState gs = new GraphicState();
                graphicStates.Add(gs);
                gs.graphic = g;
                Mask mask = g.GetComponent <Mask>();
                gs.hasMask = mask != null && mask.enabled;
                if (gs.hasMask)
                {
                    gs.showMaskGraphic   = mask.showMaskGraphic;
                    mask.showMaskGraphic = false;
                }
                else
                {
                    g.enabled = false;
                }
            }
            return(graphicStates);
        }
        static void Main(string[] args)
        {
            Console.WriteLine("GradientShade Sample:");

            using (Library lib = new Library())
            {
                Console.WriteLine("Initialized the library.");

                String sOutput = "../GradientShade-out.pdf";

                if (args.Length > 0)
                {
                    sOutput = args[0];
                }

                Console.WriteLine("Will write new file: " + sOutput);

                Document doc      = new Document();
                Rect     pageRect = new Rect(0, 0, 792, 612);
                Page     docpage  = doc.CreatePage(Document.BeforeFirstPage, pageRect);

                Double[]            domain = { 0.0, 1.0 };
                Double[]            C0     = { 0.0, 0.0, 0.0 };
                Double[]            C1     = { 1.0, 0.0, 0.0 };
                ExponentialFunction f      = new ExponentialFunction(domain, 3, C0, C1, 1);

                Point[] coords = { new Point(72,     72),
                                   new Point(4 * 72, 72) };

                Function[]          functionList = { f };
                AxialShadingPattern asp          = new AxialShadingPattern(ColorSpace.DeviceRGB, coords, functionList);

                Path         path = new Path();
                GraphicState gs   = path.GraphicState;

                // Please note path does not create a default graphic state,
                // so this is necessary, but for the first element only.
                if (gs == null)
                {
                    gs = new GraphicState();
                }

                gs.FillColor      = new Color(asp);
                path.GraphicState = gs;

                path.MoveTo(new Point(36, 36));
                path.AddLine(new Point(36, 8 * 72 - 36));
                path.AddLine(new Point(11 * 72 - 36, 8 * 72 - 36));
                path.AddLine(new Point(11 * 72 - 36, 36));
                path.ClosePath();
                path.PaintOp = PathPaintOpFlags.Stroke | PathPaintOpFlags.Fill;

                docpage.Content.AddElement(path); // Add the new element to the Content of the page.
                docpage.UpdateContent();          // Update the PDF page with the changed content

                doc.Save(SaveFlags.Full, sOutput);
            }
        }
    public GraphicState CurrentGraphicState()
    {
        if (currentGraphicState == null)
        {
            currentGraphicState = graphicStates [0];
        }

        return(currentGraphicState);
    }
Exemple #4
0
    // When changing a graphic state - change physical interactable tiles

    public void ChangePIInTiles(PhysicalInteractable physicalInteractable, GraphicState newState)
    {
        //Debug.Log ("ChangePIInTiles");

        List <Tile> oldTiles;

        if (physicalInteractable.CurrentGraphicState().coordsList.Count > 0)
        {
            //Debug.Log ("get list from coords");
            oldTiles = GetMyTiles(MyGrid, physicalInteractable.CurrentGraphicState().coordsList);
        }
        else
        {
            //Debug.Log ("get list from size");
            oldTiles = GetMyTiles(MyGrid, physicalInteractable.mySize, physicalInteractable.x, physicalInteractable.y);
        }

        List <Tile> newTiles;

        if (newState.coordsList.Count > 0)
        {
            newTiles = GetMyTiles(MyGrid, newState.coordsList);
        }
        else
        {
            newTiles = GetMyTiles(MyGrid, physicalInteractable.mySize, physicalInteractable.x, physicalInteractable.y);
        }

        if (physicalInteractable is Furniture)
        {
            foreach (Tile oldTile in oldTiles)
            {
                oldTile.myFurniture = null;
            }

            foreach (Tile newTile in newTiles)
            {
                newTile.myFurniture = (Furniture)physicalInteractable;
            }
        }

        if (physicalInteractable is Character)
        {
            foreach (Tile oldTile in oldTiles)
            {
                oldTile.myCharacter = null;
            }

            foreach (Tile newTile in newTiles)
            {
                newTile.myCharacter = (Character)physicalInteractable;
            }
        }

        EventsHandler.Invoke_cb_tileLayoutChanged();
    }
        static void Main(string[] args)
        {
            using (Library lib = new Library())
            {
                String sOutput = "../Indexed-out.pdf";

                if (args.Length > 0)
                {
                    sOutput = args[0];
                }

                Console.WriteLine("Writing to output " + sOutput);

                Document doc     = new Document();
                Page     page    = doc.CreatePage(Document.BeforeFirstPage, new Rect(0, 0, 5 * 72, 4 * 72));
                Content  content = page.Content;
                Font     font    = new Font("Times-Roman", FontCreateFlags.Embedded | FontCreateFlags.Subset);

                ColorSpace baseCS = ColorSpace.DeviceRGB;

                List <Int32> lookup = new List <Int32>();

                int[] lowhi = { 0, 255 };
                foreach (int r in lowhi)
                {
                    foreach (int g in lowhi)
                    {
                        foreach (int b in lowhi)
                        {
                            lookup.Add(r);
                            lookup.Add(g);
                            lookup.Add(b);
                        }
                    }
                }

                IndexedColorSpace cs = new IndexedColorSpace(baseCS, 7, lookup);

                GraphicState gs = new GraphicState();
                gs.FillColor = new Color(cs, new Double[] { 4.0 });


                Matrix textMatrix = new Matrix(24, 0, 0, 24,    // Set font width and height to 24 point size
                                               1 * 72, 2 * 72); // x, y coordinate on page, 1" x 2"

                TextRun textRun = new TextRun("Hello World!", font, gs, new TextState(), textMatrix);
                Text    text    = new Text();
                text.AddRun(textRun);
                content.AddElement(text);
                page.UpdateContent();

                doc.EmbedFonts();
                doc.Save(SaveFlags.Full, sOutput);
            }
        }
Exemple #6
0
 public void Run(byte[] instructions)
 {
     var stack = new Stack<UInt32>();
     var state = new GraphicState();
     for (int ip = 0; ip < instructions.Length; ip++)
     {
         var opcode = instructions[ip];
         var instruction = _lookup[opcode];
         ip = instruction.EatInstructionStream(instructions, ip, stack);
         instruction.Execute(state, stack);
     }
 }
        void AddContentToPage(Page p)
        {
            Datalogics.PDFL.Path rect = new Datalogics.PDFL.Path();
            rect.AddRect(new Point(100, 100), 100, 100);
            GraphicState gs = new GraphicState();

            gs.StrokeColor    = new Color(0, 1.0, 0);
            gs.Width          = 3.0;
            rect.GraphicState = gs;
            rect.PaintOp      = PathPaintOpFlags.Stroke;
            p.Content.AddElement(rect);
            p.UpdateContent();
        }
Exemple #8
0
        public void Run(byte[] instructions)
        {
            var stack = new Stack <UInt32>();
            var state = new GraphicState();

            for (int ip = 0; ip < instructions.Length; ip++)
            {
                var opcode      = instructions[ip];
                var instruction = _lookup[opcode];
                ip = instruction.EatInstructionStream(instructions, ip, stack);
                instruction.Execute(state, stack);
            }
        }
Exemple #9
0
    // Create Players

    public void CreatePlayers()
    {
        // When first loading the game - create list and assign player

        if (playerList == null)
        {
            playerList = new List <Player> ();

            Player player_daniel = new Player("Daniel", new Vector2(2, 1));
            player_daniel.startingRoom = "test_mom";
            player_daniel.startingPos  = new Vector3(15f, 3f, 0);


            // hardcoded stuff

            GraphicState defaultGraphicState = new GraphicState();

            defaultGraphicState.graphicStateName = "default";

            defaultGraphicState.frameExtents = new Vector2(1, 2);
            defaultGraphicState.frameOffsetX = 0;
            defaultGraphicState.frameOffsetY = 0;

            defaultGraphicState.coordsList = new List <Coords> ();

            player_daniel.graphicStates.Add(defaultGraphicState);


            Interaction interaction = new Interaction();
            interaction.myVerb = "Look At";
            SubInteraction subInt = new SubInteraction("showMonologue");
            subInt.rawText  = "hi daniel.";
            subInt.textList = Utilities.SeparateText(subInt.rawText);
            interaction.SubIntList.Add(subInt);
            player_daniel.myInteractionList.Add(interaction);


            Player player_llehctiM = new Player("llehctiM", new Vector2(2, 1));
            player_llehctiM.startingRoom = "test_mom";
            player_llehctiM.startingPos  = new Vector3(15f, 6f, 0);

            playerList.Add(player_daniel);
            playerList.Add(player_llehctiM);

            myPlayer          = player_llehctiM;
            myPlayer.isActive = true;
        }
    }
        static void Main(string[] args)
        {
            using (Library lib = new Library())
            {
                String sOutput = "../CalRGB-out.pdf";

                if (args.Length > 0)
                {
                    sOutput = args[0];
                }

                Console.WriteLine("Writing to output " + sOutput);

                Document doc     = new Document();
                Page     page    = doc.CreatePage(Document.BeforeFirstPage, new Rect(0, 0, 5 * 72, 4 * 72));
                Content  content = page.Content;
                Font     font    = new Font("Times-Roman", FontCreateFlags.Embedded | FontCreateFlags.Subset);

                // a CalRGB color space for the CCIR XA/11-recommended D65
                // white point with 1.8 gammas and Sony Trinitron phosphor
                // chromaticities
                //
                // Plus a dummy value for testing the black point

                Double[]   whitePoint = { 0.9505, 1.0000, 1.0890 };
                Double[]   blackPoint = { 0.0, 0.0, 0.0 };
                Double[]   gamma      = { 1.8, 1.8, 1.8 };
                Double[]   matrix     = { 0.4497, 0.2446, 0.0252, 0.3163, 0.6720, 0.1412, 0.1845, 0.0833, 0.9227 };
                ColorSpace cs         = new CalRGBColorSpace(whitePoint, blackPoint, gamma, matrix);


                GraphicState gs = new GraphicState();
                gs.FillColor = new Color(cs, new Double[] { 0.3, 0.7, 0.3 });


                Matrix textMatrix = new Matrix(24, 0, 0, 24,    // Set font width and height to 24 point size
                                               1 * 72, 2 * 72); // x, y coordinate on page, 1" x 2"

                TextRun textRun = new TextRun("Hello World!", font, gs, new TextState(), textMatrix);
                Text    text    = new Text();
                text.AddRun(textRun);
                content.AddElement(text);
                page.UpdateContent();

                doc.EmbedFonts();
                doc.Save(SaveFlags.Full, sOutput);
            }
        }
Exemple #11
0
        static void Main(string[] args)
        {
            using (Library lib = new Library())
            {
                String sOutput = "../Separation-out.pdf";

                if (args.Length > 0)
                {
                    sOutput = args[0];
                }

                Console.WriteLine("Writing to output " + sOutput);

                Document doc     = new Document();
                Page     page    = doc.CreatePage(Document.BeforeFirstPage, new Rect(0, 0, 5 * 72, 4 * 72));
                Content  content = page.Content;
                Font     font    = new Font("Times-Roman", FontCreateFlags.Embedded | FontCreateFlags.Subset);

                ColorSpace alternate = ColorSpace.DeviceRGB;

                Double[] domain        = { 0.0, 1.0 };
                int      nOutputs      = 3;
                Double[] range         = { 0.0, 1.0, 0.0, 1.0, 0.0, 1.0 };
                Double[] C0            = { 0.0, 0.0, 0.0 };
                Double[] C1            = { 1.0, 0.0, 0.0 };
                Function tintTransform = new ExponentialFunction(domain, nOutputs, C0, C1, 1.0);
                tintTransform.Range = range;

                ColorSpace   cs = new SeparationColorSpace("DLColor", alternate, tintTransform);
                GraphicState gs = new GraphicState();
                gs.FillColor = new Color(cs, new Double[] { 1.0 });

                Matrix textMatrix = new Matrix(24, 0, 0, 24,    // Set font width and height to 24 point size
                                               1 * 72, 2 * 72); // x, y coordinate on page, 1" x 2"

                TextRun textRun = new TextRun("Hello World!", font, gs, new TextState(), textMatrix);
                Text    text    = new Text();
                text.AddRun(textRun);
                content.AddElement(text);
                page.UpdateContent();

                doc.EmbedFonts();
                doc.Save(SaveFlags.Full, sOutput);
            }
        }
Exemple #12
0
        static void Main(string[] args)
        {
            using (Library lib = new Library())
            {
                String sOutput = "../Lab-out.pdf";

                if (args.Length > 0)
                {
                    sOutput = args[0];
                }

                Console.WriteLine("Writing to output " + sOutput);

                Document doc     = new Document();
                Page     page    = doc.CreatePage(Document.BeforeFirstPage, new Rect(0, 0, 5 * 72, 4 * 72));
                Content  content = page.Content;
                Font     font    = new Font("Times-Roman", FontCreateFlags.Embedded | FontCreateFlags.Subset);

                // CIE 1976 L*a*b* space with the CCIR XA/11-recommended D65
                // white point. The a* and b* components, although
                // theoretically unbounded, are defined to lie in the useful
                // range -128 to +127

                Double[]   whitePoint = { 0.9505, 1.0000, 1.0890 };
                Double[]   blackPoint = { 0.0, 0.0, 0.0 };
                Double[]   range      = { -128.0, 127.0, -128.0, 127.0 };
                ColorSpace cs         = new LabColorSpace(whitePoint, blackPoint, range);

                GraphicState gs = new GraphicState();
                gs.FillColor = new Color(cs, new Double[] { 55, -54, 55 });


                Matrix textMatrix = new Matrix(24, 0, 0, 24,    // Set font width and height to 24 point size
                                               1 * 72, 2 * 72); // x, y coordinate on page, 1" x 2"

                TextRun textRun = new TextRun("Hello World!", font, gs, new TextState(), textMatrix);
                Text    text    = new Text();
                text.AddRun(textRun);
                content.AddElement(text);
                page.UpdateContent();

                doc.EmbedFonts();
                doc.Save(SaveFlags.Full, sOutput);
            }
        }
Exemple #13
0
 private void Game1_GoDraw(TimeSpan TimeOldDraw, GraphicState GState)
 {
     System.Threading.Thread.Sleep(1);
     background.Draw(GState);
     gameObjectLeft.Draw(GState);
     GState.camera.Set(camera.position.X, camera.position.Y);
     foreach (Person person in people)
     {
         person.Draw(GState);
     }
     adsForce.Draw(GState);
     timeSpeed.Draw(GState);
     deleveryTime.Draw(GState);
     timeInGame.Draw(GState);
     shelfLife.Draw(GState);
     talkSpan.Draw(GState);
     table.Draw(GState);
 }
Exemple #14
0
        static void Main(string[] args)
        {
            using (Library lib = new Library())
            {
                String sOutput = "../CalGray-out.pdf";

                if (args.Length > 0)
                {
                    sOutput = args[0];
                }

                Console.WriteLine("Writing to output " + sOutput);

                Document doc     = new Document();
                Page     page    = doc.CreatePage(Document.BeforeFirstPage, new Rect(0, 0, 5 * 72, 4 * 72));
                Content  content = page.Content;
                Font     font    = new Font("Times-Roman", FontCreateFlags.Embedded | FontCreateFlags.Subset);

                // a space consisting of the Y dimension of the CIE 1931 XYZ
                // space with the CCIR XA/11-recommended D65 white point and
                // opto-electronic transfer function.

                Double[] whitePoint = { 0.9505, 1.0000, 1.0890 };
                Double[] blackPoint = { 0.0, 0.0, 0.0 };
                double   gamma      = 2.2222;

                ColorSpace   cs = new CalGrayColorSpace(whitePoint, blackPoint, gamma);
                GraphicState gs = new GraphicState();
                gs.FillColor = new Color(cs, new Double[] { 0.5 });


                Matrix textMatrix = new Matrix(24, 0, 0, 24,    // Set font width and height to 24 point size
                                               1 * 72, 2 * 72); // x, y coordinate on page, 1" x 2"

                TextRun textRun = new TextRun("Hello World!", font, gs, new TextState(), textMatrix);
                Text    text    = new Text();
                text.AddRun(textRun);
                content.AddElement(text);
                page.UpdateContent();

                doc.EmbedFonts();
                doc.Save(SaveFlags.Full, sOutput);
            }
        }
Exemple #15
0
        static void Main(string[] args)
        {
            using (Library lib = new Library())
            {
                String sInput  = Library.ResourceDirectory + "Sample_Input/sRGB_IEC61966-2-1_noBPC.icc";
                String sOutput = "../ICCBased-out.pdf";

                if (args.Length > 0)
                {
                    sInput = args[0];
                }
                if (args.Length > 1)
                {
                    sOutput = args[1];
                }

                Console.WriteLine("Writing to output " + sOutput);

                Document doc     = new Document();
                Page     page    = doc.CreatePage(Document.BeforeFirstPage, new Rect(0, 0, 5 * 72, 4 * 72));
                Content  content = page.Content;
                Font     font    = new Font("Times-Roman", FontCreateFlags.Embedded | FontCreateFlags.Subset);

                FileStream stream    = new FileStream(sInput, FileMode.Open);
                PDFStream  pdfStream = new PDFStream(stream, doc, null, null);

                ColorSpace   cs = new ICCBasedColorSpace(pdfStream, 3);
                GraphicState gs = new GraphicState();
                gs.FillColor = new Color(cs, new Double[] { 1.0, 0.0, 0.0 });


                Matrix textMatrix = new Matrix(24, 0, 0, 24,    // Set font width and height to 24 point size
                                               1 * 72, 2 * 72); // x, y coordinate on page, 1" x 2"

                TextRun textRun = new TextRun("Hello World!", font, gs, new TextState(), textMatrix);
                Text    text    = new Text();
                text.AddRun(textRun);
                content.AddElement(text);
                page.UpdateContent();

                doc.EmbedFonts();
                doc.Save(SaveFlags.Full, sOutput);
            }
        }
        static void Main(string[] args)
        {
            using (Library lib = new Library())
            {
                String sOutput = "../DeviceN-out.pdf";

                if (args.Length > 0)
                {
                    sOutput = args[0];
                }

                Console.WriteLine("Writing to output " + sOutput);

                Document doc     = new Document();
                Page     page    = doc.CreatePage(Document.BeforeFirstPage, new Rect(0, 0, 5 * 72, 4 * 72));
                Content  content = page.Content;
                Font     font    = new Font("Times-Roman", FontCreateFlags.Embedded | FontCreateFlags.Subset);

                ColorSpace alternate = ColorSpace.DeviceRGB;

                Double[] domain        = { 0.0, 1.0, 0.0, 1.0 };
                Double[] range         = { 0.0, 1.0, 0.0, 1.0, 0.0, 1.0 };
                string   code          = "{ 0 exch }";
                Function tintTransform = new PostScriptCalculatorFunction(domain, range, code);

                ColorSpace   cs = new DeviceNColorSpace(new string[] { "DLRed", "DLBlue" }, alternate, tintTransform);
                GraphicState gs = new GraphicState();
                gs.FillColor = new Color(cs, new Double[] { 0.75, 0.75 });


                Matrix textMatrix = new Matrix(24, 0, 0, 24,    // Set font width and height to 24 point size
                                               1 * 72, 2 * 72); // x, y coordinate on page, 1" x 2"

                TextRun textRun = new TextRun("Hello World!", font, gs, new TextState(), textMatrix);
                Text    text    = new Text();
                text.AddRun(textRun);
                content.AddElement(text);
                page.UpdateContent();

                doc.EmbedFonts();
                doc.Save(SaveFlags.Full, sOutput);
            }
        }
Exemple #17
0
        /// <summary>
        /// Search for UIWidget and Graphic components in child transforms and store references to them
        /// Also assign this widget's pEventTarget as child widgets' pEventTarget
        /// </summary>
        protected void CacheWidgets(Transform cacheTransform)
        {
            mRaycastCaptureGraphic = GetComponent <NonDrawableGraphic>();

            int childCount = cacheTransform.childCount;

            for (int i = 0; i < childCount; ++i)
            {
                Transform childTransform = cacheTransform.GetChild(i);

                UIWidget childWidget = childTransform.GetComponent <UIWidget>();
                if (childWidget != null)
                {
                    mChildWidgets.Add(childWidget);
                }
                else
                {
                    Graphic childGraphic = childTransform.GetComponent <Graphic>();
                    if (childGraphic != null && !(childGraphic is NonDrawableGraphic))
                    {
                        // We need to cache the actual enabled/disabled state of the Graphic only if we are using a Unity Selectable
                        // since the Selectable will perform it's own Graphic enabling/disabling
                        RectTransform childGraphicTransfrom = childGraphic.rectTransform;
                        Image         childGraphicImage     = childGraphic as Image;

                        GraphicState graphicState = new GraphicState(childGraphic);
                        graphicState.pOriginallyEnabled = childGraphic.enabled || (mSelectable == null);
                        graphicState.pOriginalPosition  = childGraphicTransfrom.localPosition;
                        graphicState.pOriginalScale     = childGraphicTransfrom.localScale;
                        graphicState.pOriginalColor     = childGraphic.color;
                        graphicState.pOriginalSprite    = (childGraphicImage != null) ? childGraphicImage.sprite : null;
                        mGraphicsStates.Add(graphicState);
                    }

                    if (childTransform.childCount > 0)
                    {
                        CacheWidgets(childTransform);
                    }
                }
            }
        }
        static void DisplayCustomerInfo(customerInfo customer, ref Text t, Font f, GraphicState gs, TextState ts, double pointSize)
        {
            Matrix  m1  = new Matrix().Translate(customer.name_x, customer.name_y).Scale(pointSize, pointSize); // customerInfoPointSize
            TextRun tr1 = new TextRun(customer.name, f, gs, ts, m1);

            t.AddRun(tr1);
            m1  = new Matrix().Translate(customer.address_x, customer.address_y).Scale(pointSize, pointSize);
            tr1 = new TextRun(customer.address, f, gs, ts, m1);
            t.AddRun(tr1);
            m1 = new Matrix().Translate(customer.city_x, customer.city_y).Scale(pointSize, pointSize);
            String s = customer.city + ", " + customer.state + "   " + customer.zip;

            tr1 = new TextRun(s, f, gs, ts, m1);
            t.AddRun(tr1);
            m1  = new Matrix().Translate(customer.phone_x, customer.phone_y).Scale(pointSize, pointSize);
            tr1 = new TextRun(customer.phone, f, gs, ts, m1);
            t.AddRun(tr1);

            m1.Dispose();
            tr1.Dispose();
        }
        /// <summary>
        /// Search for UIWidget, UI and Graphic components in child transforms and store references to them
        /// Also assign this UI's pEventReceiver as child widgets' and child UIs' pEventTarget
        /// </summary>
        protected void CacheWidgets(Transform cacheTransform)
        {
            int childCount = cacheTransform.childCount;

            for (int i = 0; i < childCount; ++i)
            {
                Transform childTransform = cacheTransform.GetChild(i);

                UIWidget childWidget = childTransform.GetComponent <UIWidget>();
                if (childWidget != null)
                {
                    mChildWidgets.Add(childWidget);
                }
                else
                {
                    UI childUI = childTransform.GetComponent <UI>();
                    if (childUI != null)
                    {
                        mChildUIs.Add(childUI);
                    }
                    else
                    {
                        Graphic childGraphic = childTransform.GetComponent <Graphic>();
                        if (childGraphic != null && !(childGraphic is NonDrawableGraphic))
                        {
                            GraphicState graphicState = new GraphicState(childGraphic);
                            graphicState.pOriginallyEnabled = true;
                            mGraphicsStates.Add(graphicState);
                        }

                        if (childTransform.childCount > 0)
                        {
                            CacheWidgets(childTransform);
                        }
                    }
                }
            }
        }
 public virtual void InheritGraphicState(PdfContentByte parentCanvas) {
     this.state = parentCanvas.state;
     this.stateList = parentCanvas.stateList;
 }
        static void Main(string[] args)
        {
            Console.WriteLine("AddElements Sample:");

            using (Library lib = new Library())
            {
                Console.WriteLine("Initialized the library.");

                String sOutput = "../AddElements-out.pdf";

                if (args.Length > 0)
                {
                    sOutput = args[0];
                }

                Console.WriteLine("Output file: " + sOutput);

                Document doc      = new Document();
                Rect     pageRect = new Rect(0, 0, 612, 792);
                Page     docpage  = doc.CreatePage(Document.BeforeFirstPage, pageRect);

                // Draw a five pointed star.
                Path         starpath = new Path();
                GraphicState gs       = starpath.GraphicState;

                starpath.PaintOp = PathPaintOpFlags.Stroke;
                gs.Width         = 2.0;                       // make the line thickness 2 PDF coordinates.
                List <double> DashPattern = new List <double>();
                DashPattern.Add(3);                           // Set 3 for the Dash Phase
                DashPattern.Add(5);
                DashPattern.Add(6);                           // Set the Dash Pattern list to [5 6]
                gs.DashPattern        = DashPattern;
                gs.StrokeColor        = new Color(0, 1.0, 0); // Green Star
                starpath.GraphicState = gs;
                starpath.PaintOp      = PathPaintOpFlags.Stroke;
                double CenterX     = 306.0;                      // Center of Page
                double CenterY     = 396.0;
                double Radius      = 72 * 4.0;                   // 4 inches with 72 dpi
                double radians72   = 72 / (45 / Math.Atan(1.0)); // angles must be in radians.
                double radians36   = 36 / (45 / Math.Atan(1.0));
                Point  CenterPoint = new Point(CenterX, CenterY);
                Point  Point0      = new Point(CenterX, CenterY + Radius);
                Point  Point1      = new Point(CenterX + Radius * Math.Sin(radians72), CenterY + Radius * Math.Cos(radians72));
                Point  Point2      = new Point(CenterX + Radius * Math.Sin(radians36), CenterY - Radius * Math.Cos(radians36));
                Point  Point3      = new Point(CenterX - Radius * Math.Sin(radians36), CenterY - Radius * Math.Cos(radians36));
                Point  Point4      = new Point(CenterX - Radius * Math.Sin(radians72), CenterY + Radius * Math.Cos(radians72));
                starpath.MoveTo(Point0);
                starpath.AddLine(Point2);
                starpath.AddLine(Point4);
                starpath.AddLine(Point1);
                starpath.AddLine(Point3);
                starpath.AddLine(Point0);
                starpath.ClosePath();
                docpage.Content.AddElement(starpath);  // Add the new element to the Content of the page.

                // Draw a pentagon around the star
                Path pentpath = new Path();
                pentpath.PaintOp = PathPaintOpFlags.Stroke;
                gs.Width         = 2.0;
                List <double> PentDashPattern = new List <double>();
                PentDashPattern.Add(0);                           // Set 0 for the Dash Phase
                PentDashPattern.Add(3);                           // Set the Dash Pattern list to [3]
                gs.DashPattern        = PentDashPattern;
                gs.StrokeColor        = new Color(1.0, 0.0, 1.0); // purple pentagon
                pentpath.GraphicState = gs;
                pentpath.PaintOp      = PathPaintOpFlags.Stroke;
                pentpath.MoveTo(Point0);
                pentpath.AddLine(Point1);
                pentpath.AddLine(Point2);
                pentpath.AddLine(Point3);
                pentpath.AddLine(Point4);
                pentpath.AddLine(Point0);
                pentpath.ClosePath();
                docpage.Content.AddElement(pentpath); // Add the new element to the Content of the page.

                // Add a single line star in the middle of the big star
                Path newstar = new Path();
                newstar.PaintOp = PathPaintOpFlags.EoFill;
                gs.Width        = 1.0;
                List <double> starDashPattern = new List <double>();
                gs.DashPattern       = starDashPattern;
                gs.StrokeColor       = new Color(0, 0, 1.0); // blue innerstar
                newstar.GraphicState = gs;
                newstar.MoveTo(CenterPoint);
                newstar.AddLine(Point0);
                newstar.MoveTo(CenterPoint);
                newstar.AddLine(Point1);
                newstar.MoveTo(CenterPoint);
                newstar.AddLine(Point2);
                newstar.MoveTo(CenterPoint);
                newstar.AddLine(Point3);
                newstar.MoveTo(CenterPoint);
                newstar.AddLine(Point4);
                newstar.ClosePath();
                docpage.Content.AddElement(newstar);

                docpage.UpdateContent(); // Update the PDF page with the changed content

/* Second page: a diamond with text inside */
                docpage = doc.CreatePage(0, pageRect);

                Path          diamond            = new Path();
                List <double> diamondDashPattern = new List <double>();
                gs.DashPattern  = diamondDashPattern;
                gs.FillColor    = new Color(1.0, 1.0, 0);         // Yellow
                gs.StrokeColor  = new Color(153.0 / 255.0, 0, 0); // kind of a deep red
                diamond.PaintOp = PathPaintOpFlags.EoFill | PathPaintOpFlags.Stroke;

                gs.Width             = 1.0;
                gs.LineJoin          = LineJoin.BevelJoin;
                diamond.GraphicState = gs;

                diamond.MoveTo(new Point(306, 198));
                diamond.AddLine(new Point(459, 396));
                diamond.AddLine(new Point(306, 594));
                diamond.AddLine(new Point(153, 396));
                diamond.AddLine(new Point(306, 198));
                diamond.ClosePath();
                docpage.Content.AddElement(diamond); // Add the new element to the Content of the page.

// Now add text to the PDF page. By default, text is filled with
// the fill color from the graphic state
                Text t = new Text();
                Font f = new Font("Arial", FontCreateFlags.Embedded | FontCreateFlags.Subset);
                gs           = new GraphicState();
                gs.FillColor = new Color(0, 0, 1.0);
                TextState ts = new TextState();

                Matrix  m  = new Matrix().Translate(180, 414).Scale(24.0, 24.0);
                TextRun tr = new TextRun("Horizontal Blue Text", f, gs, ts, m);
                t.AddRun(tr);

                // This text will be filled and stroked
                m              = new Matrix().Translate(315, 216).Scale(24.0, 24.0).Rotate(90);
                gs.FillColor   = new Color(1.0, 0, 0);
                gs.StrokeColor = new Color(0.0, 0.5, 0.5);
                ts.RenderMode  = TextRenderMode.FillThenStroke;
                tr             = new TextRun("Vertical Red Text", f, gs, ts, m);
                t.AddRun(tr);

                // This text will only be stroked
                m             = new Matrix().Translate(297, 576).Scale(24.0, 24.0).Rotate(-52);
                gs.FillColor  = new Color(0, 1.0, 0);
                ts.RenderMode = TextRenderMode.Stroke;
                tr            = new TextRun("Angled Green Text", f, gs, ts, m);
                t.AddRun(tr);

                docpage.Content.AddElement(t);
                docpage.UpdateContent();

                /* Third page: a stroked path that uses all the segment types */
                docpage = doc.CreatePage(1, pageRect);
                Path path = new Path();

                path.PaintOp      = PathPaintOpFlags.Stroke;
                gs                = path.GraphicState;
                gs.Width          = 2;
                path.GraphicState = gs;

                List <Segment> segments = new List <Segment>();

                segments.Add(new MoveTo(72.0, 73.0));
                segments.Add(new LineTo(76.0, 144.0));
                segments.Add(new CurveTo(120.0, 144.0, 121.0, 96.0, 97.0, 98.0));
                segments.Add(new CurveToV(80.0, 81.0, 128.0, 21.0));
                segments.Add(new CurveToY(200.0, 201.0, 22.0, 160.0));
                segments.Add(new ClosePath());
                segments.Add(new RectSegment(256.0, 257.0, 123.0, 67.0));

                path.Segments = segments;

                docpage.Content.AddElement(path);
                docpage.UpdateContent();

                doc.EmbedFonts(EmbedFlags.None, new AEProgressMonitor(), new AECancelProc(), new AEReportProc());
                doc.Save(SaveFlags.Full, sOutput, new AEProgressMonitor(), new AECancelProc());
            }
        }
 internal GraphicState(GraphicState cp)
 {
     fontDetails = cp.fontDetails;
     colorDetails = cp.colorDetails;
     size = cp.size;
     xTLM = cp.xTLM;
     yTLM = cp.yTLM;
     aTLM = cp.aTLM;
     bTLM = cp.bTLM;
     cTLM = cp.cTLM;
     dTLM = cp.dTLM;
     tx = cp.tx;
     leading = cp.leading;
     scale = cp.scale;
     charSpace = cp.charSpace;
     wordSpace = cp.wordSpace;
 }
Exemple #23
0
 public abstract void Execute(GraphicState state, Stack <UInt32> stack, params bool[] flags);
Exemple #24
0
        private void SetFreeTextAnnotationProperties(Datalogics.PDFL.Content content)
        {
            bool         useDefaultFont = false;
            Path         path           = null;
            TextRun      currentTextRun = null;
            GraphicState gState         = null;

            Datalogics.PDFL.Font dlFont = null;
            for (int i = 0; i < content.NumElements; i++)
            {
                Element element = content.GetElement(i);
                if (element is Text)
                {
                    Text currentText = element as Text;
                    for (int j = 0; j < currentText.NumberOfRuns; j++)
                    {
                        currentTextRun = currentText.GetRun(j);
                        dlFont         = currentTextRun.Font;
                        if (dlFont != null)
                        {
                            break;
                        }
                    }
                }
                else if (element is Path)
                {
                    path   = element as Path;
                    gState = path.GraphicState;
                }
            }
            if (dlFont == null)
            {
                dlFont         = new Datalogics.PDFL.Font("Arial");
                useDefaultFont = true;
            }

            if (gState == null)
            {
                gState = new GraphicState();
            }

            if (currentTextRun == null)
            {
                currentTextRun = new TextRun("", dlFont, gState, new TextState(), new Datalogics.PDFL.Matrix());
            }

            if (path == null)
            {
                path = new Path(gState);
            }

            string fontName = "";

            if (families.IndexOf(dlFont.Name) == -1)
            {
                foreach (string name in families)
                {
                    string trimmedName = name.Replace(" ", "");
                    if (name.Contains(dlFont.Name) || trimmedName.Contains(dlFont.Name) || dlFont.Name.Contains(name) || dlFont.Name.Contains(trimmedName))
                    {
                        fontName = name;
                        break;
                    }
                }
            }
        }
 /**
 * Makes this <CODE>PdfContentByte</CODE> empty.
 * @param validateContent will call <code>sanityCheck()</code> if true.
 * @since 2.1.6
 */
 public void Reset( bool validateContent )
 {
     content.Reset();
     if (validateContent) {
         SanityCheck();
     }
     state = new GraphicState();
 }
        static void CheckCharactersInText(Text txt, List <LinkAnnotation> linkAnnots)
        {
            // This function checks to see if any characters in this Text object
            // fall within the bounds of the LinkAnnotations on this page.
            for (int i = 0; i < linkAnnots.Count; i++)
            {
                int charIndex;

                // Find the index of the first character in this Text object that intersects
                // with the LinkAnnotation rectangle, if there is one.
                for (charIndex = 0; charIndex < txt.NumberOfCharacters; charIndex++)
                {
                    if (txt.RectIntersectsCharacter(linkAnnots[i].Rect, charIndex))
                    {
                        break;
                    }
                }

                if (charIndex >= txt.NumberOfCharacters)
                {
                    // The LinkAnnotation rect falls outside of this Text object.
                    // Try the next rect on the list.
                    continue;
                }

                // We may get some false positives using only Text.RectIntersectsCharacter().
                // This function checks to see whether any part of the rectangle lies on the
                // character's bounding box.  It's common for a character's bounding box
                // to be taller than the height of the line; in these cases, the bounding
                // box may intersect a LinkAnnotation rectangle on the line above.
                //
                // We can weed out these false positives by checking the lower left corner
                // of the character's text matrix.  If the lower left corner falls within
                // the rectangle of the LinkAnnotation, then this character really
                // is contained within the LinkAnnotation rectangle.  Taking the floor and
                // ceiling as shown below accounts for precision errors in the rect and
                // matrix values.
                //
                // This heuristic works well for many cases.  If you find that you're still
                // getting false positives or false negatives, you may need to tweak the
                // heuristic.
                Matrix charMatrix     = txt.GetTextMatrixForCharacter(charIndex);
                bool   hWithinLinkBox = (Math.Floor(linkAnnots[i].Rect.LLx) < Math.Ceiling(charMatrix.H)) &&
                                        (Math.Floor(charMatrix.H) < Math.Ceiling(linkAnnots[i].Rect.URx));
                bool vWithinLinkBox = (Math.Floor(linkAnnots[i].Rect.LLy) < Math.Ceiling(charMatrix.V)) &&
                                      (Math.Floor(charMatrix.V) < Math.Ceiling(linkAnnots[i].Rect.URy));

                if (hWithinLinkBox && vWithinLinkBox)
                {
                    Console.WriteLine("Found a character that falls within the bounds of LinkAnnotation " + i);

                    int startRunIndex;

                    if (charIndex == 0)
                    {
                        // This is the first character, no splitting needed.
                        startRunIndex = 0;
                    }
                    else
                    {
                        txt.SplitTextRunAtCharacter(charIndex);
                        startRunIndex = txt.FindTextRunIndexForCharacter(charIndex);
                    }

                    // Now search for the last character that intersects with the
                    // LinkAnnotation rectangle.
                    while (charIndex < txt.NumberOfCharacters)
                    {
                        if (!(txt.RectIntersectsCharacter(linkAnnots[i].Rect, charIndex)))
                        {
                            break;
                        }
                        charIndex++;
                    }

                    int endRunIndex;

                    if (charIndex >= txt.NumberOfCharacters)
                    {
                        // The LinkAnnotation rect goes past the bounding box of
                        // this Text object, so the endRunIndex is the last TextRun
                        // in this Text.
                        endRunIndex = txt.NumberOfRuns - 1;
                    }
                    else
                    {
                        txt.SplitTextRunAtCharacter(charIndex);
                        endRunIndex = txt.FindTextRunIndexForCharacter(charIndex);
                    }

                    // Change the GraphicState on all the TextRuns from
                    // startRunIndex to endRunIndex.
                    for (int runIndex = startRunIndex; runIndex <= endRunIndex; runIndex++)
                    {
                        TextRun      txtRun = txt.GetRun(runIndex);
                        GraphicState gs     = txtRun.GraphicState;
                        gs.FillColor        = new Color(0.0, 0.0, 1.0);
                        txtRun.GraphicState = gs;
                    }
                }
            }
        }
 internal void Restore(GraphicState restore) {
     CopyParameters(restore);
 }
Exemple #28
0
        /// <summary>
        /// Push the current graphic state onto the stack
        /// </summary>
        public void PushGraphicsState()
        {
            var clone = GraphicState.Clone();

            graphicsStateStack.Push(clone);
        }
            public static void ApplySnapshotLerp(MaskableGraphic graphic, GraphicState state, TransitionParameters transition, GraphicSnapshot origin, GraphicSnapshot target, float t)
            {
                RectTransform rect     = graphic.GetComponent <RectTransform>();
                float         progress = 0;

                if (state.ChangeSize == true)
                {
                    UpdateProgress(ref progress, t, state.Size_SeparateTransition,
                                   transition.SizeUseCurve, transition.SizeCurve, transition.SizePower,
                                   transition.UseCurve, transition.Curve, transition.Power);

                    if (state.SyncSizeAxises == true)
                    {
                        rect.sizeDelta = Vector2.one * Mathf.LerpUnclamped(origin.SyncSize, target.SyncSize, progress);
                    }
                    else
                    {
                        rect.sizeDelta = Vector2.LerpUnclamped(origin.SizeDelta, target.SizeDelta, progress);
                    }
                }

                if (state.ChangeScale == true)
                {
                    UpdateProgress(ref progress, t, state.Scale_SeparateTransition,
                                   transition.ScaleUseCurve, transition.ScaleCurve, transition.ScalePower,
                                   transition.UseCurve, transition.Curve, transition.Power);

                    if (state.SyncScaleAxises == true)
                    {
                        rect.localScale = Vector3.one * Mathf.LerpUnclamped(origin.SyncScale, target.SyncScale, progress);
                    }
                    else
                    {
                        rect.localScale = Vector3.LerpUnclamped(origin.ScaleDelta, target.ScaleDelta, progress);
                    }
                }

                if (state.ChangePosition == true)
                {
                    UpdateProgress(ref progress, t, state.Position_SeparateTransition,
                                   transition.PositionUseCurve, transition.PositionCurve, transition.PositionPower,
                                   transition.UseCurve, transition.Curve, transition.Power);

                    rect.anchoredPosition3D = Vector3.LerpUnclamped(origin.Position, target.Position, progress);
                }

                if (state.ChangeRotation == true)
                {
                    UpdateProgress(ref progress, t, state.Rotation_SeparateTransition,
                                   transition.RotationUseCurve, transition.RotationCurve, transition.RotationPower,
                                   transition.UseCurve, transition.Curve, transition.Power);

                    rect.localEulerAngles = rect.localEulerAngles.SetZ(Mathf.LerpUnclamped(origin.Rotation, target.Rotation, progress));
                }

                if (state.ChangeColor == true)
                {
                    UpdateProgress(ref progress, t, state.Color_SeparateTransition,
                                   transition.ColorUseCurve, transition.ColorCurve, transition.ColorPower,
                                   transition.UseCurve, transition.Curve, transition.Power);

                    graphic.color = Color.LerpUnclamped(origin.Color, target.Color, progress);
                }
            }
Exemple #30
0
        static void blendPage(Document doc, Image foregroundImage, Image backgroundImage)
        {
            double height   = 792;
            double width    = 612;
            Rect   pageRect = new Rect(0, 0, width, height);
            Page   docpage  = doc.CreatePage(doc.NumPages - 1, pageRect);

            // This section demonstrates all the Blend Modes one can achieve
            // by setting the BlendMode property to each of the 16 enumerations
            // on a foreground "ducky" over a background rainbow pattern, and
            // plopping all these images on a single page.
            Text         t      = new Text();
            Font         f      = new Font("Arial", FontCreateFlags.Embedded | FontCreateFlags.Subset);
            GraphicState gsText = new GraphicState();

            gsText.FillColor = new Color(0, 0, 1.0);
            TextState ts = new TextState();

            for (int i = 0; i < 16; i++)
            {
                Image individualForegroundImage = foregroundImage.Clone();
                Image individualBackgroundImage = backgroundImage.Clone();

                GraphicState gs = individualForegroundImage.GraphicState;
                individualForegroundImage.Scale(0.125, 0.125);
                individualForegroundImage.Translate(800, 200 + height * (7 - i));
                individualBackgroundImage.Scale(0.125, 0.125);
                individualBackgroundImage.Translate(800, 200 + height * (7 - i));

                // Halfway through, create 2nd column by shifting over and up
                if (i > 7)
                {
                    individualForegroundImage.Translate(2400, height * 8);
                    individualBackgroundImage.Translate(2400, height * 8);
                }

                docpage.Content.AddElement(individualBackgroundImage);
                Console.WriteLine("Added background image " + (i + 1) + " to the content.");
                docpage.Content.AddElement(individualForegroundImage);
                Console.WriteLine("Added foreground image " + (i + 1) + " to the content.");

                Matrix m = new Matrix();
                if (i > 7)
                {
                    m = m.Translate(480, 750 - ((i - 8) * 100)); // second column
                }
                else
                {
                    m = m.Translate(180, 750 - (i * 100)); // first column
                }
                m = m.Scale(12.0, 12.0);

                ExtendedGraphicState xgs = new ExtendedGraphicState();
                TextRun tr = null;
                if (i == 0)
                {
                    xgs.BlendMode = BlendMode.Normal;
                    tr            = new TextRun("Normal", f, gsText, ts, m);
                }
                else if (i == 1)
                {
                    xgs.BlendMode = BlendMode.Multiply;
                    tr            = new TextRun("Multiply", f, gsText, ts, m);
                }
                else if (i == 2)
                {
                    xgs.BlendMode = BlendMode.Screen;
                    tr            = new TextRun("Screen", f, gsText, ts, m);
                }
                else if (i == 3)
                {
                    xgs.BlendMode = BlendMode.Overlay;
                    tr            = new TextRun("Overlay", f, gsText, ts, m);
                }
                else if (i == 4)
                {
                    xgs.BlendMode = BlendMode.Darken;
                    tr            = new TextRun("Darken", f, gsText, ts, m);
                }
                else if (i == 5)
                {
                    xgs.BlendMode = BlendMode.Lighten;
                    tr            = new TextRun("Lighten", f, gsText, ts, m);
                }
                else if (i == 6)
                {
                    xgs.BlendMode = BlendMode.ColorDodge;
                    tr            = new TextRun("Color Dodge", f, gsText, ts, m);
                }
                else if (i == 7)
                {
                    xgs.BlendMode = BlendMode.ColorBurn;
                    tr            = new TextRun("Color Burn", f, gsText, ts, m);
                }
                else if (i == 8)
                {
                    xgs.BlendMode = BlendMode.HardLight;
                    tr            = new TextRun("Hard Light", f, gsText, ts, m);
                }
                else if (i == 9)
                {
                    xgs.BlendMode = BlendMode.SoftLight;
                    tr            = new TextRun("SoftLight", f, gsText, ts, m);
                }
                else if (i == 10)
                {
                    xgs.BlendMode = BlendMode.Difference;
                    tr            = new TextRun("Difference", f, gsText, ts, m);
                }
                else if (i == 11)
                {
                    xgs.BlendMode = BlendMode.Exclusion;
                    tr            = new TextRun("Exclusion", f, gsText, ts, m);
                }
                else if (i == 12)
                {
                    xgs.BlendMode = BlendMode.Hue;
                    tr            = new TextRun("Hue", f, gsText, ts, m);
                }
                else if (i == 13)
                {
                    xgs.BlendMode = BlendMode.Saturation;
                    tr            = new TextRun("Saturation", f, gsText, ts, m);
                }
                else if (i == 14)
                {
                    xgs.BlendMode = BlendMode.Color;
                    tr            = new TextRun("Color", f, gsText, ts, m);
                }
                else if (i == 15)
                {
                    xgs.BlendMode = BlendMode.Luminosity;
                    tr            = new TextRun("Luminosity", f, gsText, ts, m);
                }
                t.AddRun(tr);
                docpage.Content.AddElement(t);
                docpage.UpdateContent();
                Console.WriteLine("Updated the content on page 1.");

                gs.ExtendedGraphicState = xgs;
                individualForegroundImage.GraphicState = gs;
                Console.WriteLine("Set blend mode in extended graphic state.");
            }
        }
Exemple #31
0
        static void Main(string[] args)
        {
            // ReSharper disable once UnusedVariable
            using (Library lib = new Library())
            {
                String sOutput = "CalGray-out.pdf";

                if (args.Length > 0)
                {
                    sOutput = args[0];
                }

                Console.WriteLine("Writing to output " + sOutput);

                Document doc     = new Document();
                Page     page    = doc.CreatePage(Document.BeforeFirstPage, new Rect(0, 0, 5 * 72, 4 * 72));
                Content  content = page.Content;
                Font     font;
                try
                {
                    font = new Font("Times-Roman", FontCreateFlags.Embedded | FontCreateFlags.Subset);
                }
                catch (ApplicationException ex)
                {
                    if (ex.Message.Equals("The specified font could not be found.") &&
                        System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices
                                                                                       .OSPlatform.Linux) &&
                        !System.IO.Directory.Exists("/usr/share/fonts/msttcore/"))
                    {
                        Console.WriteLine("Please install Microsoft Core Fonts on Linux first.");
                        return;
                    }

                    throw;
                }
                // a space consisting of the Y dimension of the CIE 1931 XYZ
                // space with the CCIR XA/11-recommended D65 white point and
                // opto-electronic transfer function.

                Double[] whitePoint = { 0.9505, 1.0000, 1.0890 };
                Double[] blackPoint = { 0.0, 0.0, 0.0 };
                double   gamma      = 2.2222;

                ColorSpace   cs = new CalGrayColorSpace(whitePoint, blackPoint, gamma);
                GraphicState gs = new GraphicState();
                gs.FillColor = new Color(cs, new[] { 0.5 });


                Matrix textMatrix = new Matrix(24, 0, 0, 24,    // Set font width and height to 24 point size
                                               1 * 72, 2 * 72); // x, y coordinate on page, 1" x 2"

                TextRun textRun = new TextRun("Hello World!", font, gs, new TextState(), textMatrix);
                Text    text    = new Text();
                text.AddRun(textRun);
                content.AddElement(text);
                page.UpdateContent();

                doc.EmbedFonts();
                doc.Save(SaveFlags.Full, sOutput);
            }
        }
        static void Main(string[] args)
        {
            Console.WriteLine("Clips Sample:");

            using (Library lib = new Library())
            {
                Console.WriteLine("Initialized the library.");

                String sOutput = "../Clips-out.pdf";

                if (args.Length > 0)
                {
                    sOutput = args[0];
                }

                Console.WriteLine("Output file: " + sOutput);

                // Create a new document and blank first page
                Document doc  = new Document();
                Rect     rect = new Rect(0, 0, 612, 792);
                Page     page = doc.CreatePage(Document.BeforeFirstPage, rect);
                Console.WriteLine("Created new document and first page.");

                // Create a new path, set up its graphic state and PaintOp
                Path         path  = new Path();
                GraphicState gs    = new GraphicState();
                Color        color = new Color(0.0, 0.0, 0.0);
                gs.FillColor      = color;
                path.GraphicState = gs;
                path.PaintOp      = PathPaintOpFlags.Fill;

                // Add a rectangle to the path
                Point point = new Point(100, 500);
                path.AddRect(point, 300, 200);
                Console.WriteLine("Created new path and added rectangle to it.");

                // Add a curve to the path too so we have something
                // interesting to look at after clipping
                Point linePoint1 = new Point(400, 450);
                Point linePoint2 = new Point(350, 300);
                path.AddCurveV(linePoint1, linePoint2);
                Console.WriteLine("Added curve to the path.");

                // Add the path to the page in the document
                Content content = page.Content;
                content.AddElement(path);
                Console.WriteLine("Added path to page in document.");

                // Create a new path and add a rectangle to it
                Path clipPath = new Path();
                point = new Point(50, 300);
                clipPath.AddRect(point, 300, 250);
                Console.WriteLine("Created clipping path and added rectangle to it.");

                // Create a new clip and add the new path to it and then add
                // this new clip to the original path as its Clip property
                Clip clip = new Clip();
                clip.AddElement(clipPath);
                path.Clip = clip;
                Console.WriteLine("Created new clip, assigned clipping path to it, and added new clip to original path.");

                // Update the page's content and save the file with clipping
                page.UpdateContent();
                doc.Save(SaveFlags.Full, sOutput);

                // Kill the doc object
                doc.Dispose();
                Console.WriteLine("Killed document object.");
            }
        }
 internal GraphicState(GraphicState cp) {
     CopyParameters(cp);
 }
 /**
  * Restores the graphic state. <CODE>saveState</CODE> and
  * <CODE>restoreState</CODE> must be balanced.
  */
 public void RestoreState()
 {
     content.Append('Q').Append_i(separator);
     int idx = stateList.Count - 1;
     if (idx < 0)
         throw new IllegalPdfSyntaxException("Unbalanced save/restore state operators.");
     state = (GraphicState)stateList[idx];
     stateList.RemoveAt(idx);
 }
 internal void CopyParameters(GraphicState cp) {
     fontDetails = cp.fontDetails;
     colorDetails = cp.colorDetails;
     size = cp.size;
     xTLM = cp.xTLM;
     yTLM = cp.yTLM;
     aTLM = cp.aTLM;
     bTLM = cp.bTLM;
     cTLM = cp.cTLM;
     dTLM = cp.dTLM;
     tx = cp.tx;
     leading = cp.leading;
     scale = cp.scale;
     charSpace = cp.charSpace;
     wordSpace = cp.wordSpace;
     textColorFill = cp.textColorFill;
     colorFill = cp.colorFill;
     textColorStroke = cp.textColorStroke;
     colorStroke = cp.colorStroke;
     CTM = (AffineTransform)cp.CTM.Clone();
     textRenderMode = cp.textRenderMode;
     extGState = cp.extGState;
 }
Exemple #36
0
 internal void CopyParameters(GraphicState cp) {
     fontDetails = cp.fontDetails;
     colorDetails = cp.colorDetails;
     size = cp.size;
     xTLM = cp.xTLM;
     yTLM = cp.yTLM;
     aTLM = cp.aTLM;
     bTLM = cp.bTLM;
     cTLM = cp.cTLM;
     dTLM = cp.dTLM;
     tx = cp.tx;
     leading = cp.leading;
     scale = cp.scale;
     charSpace = cp.charSpace;
     wordSpace = cp.wordSpace;
     textColorFill = cp.textColorFill;
     graphicsColorFill = cp.graphicsColorFill;
     textColorStroke = cp.textColorStroke;
     graphicsColorStroke = cp.graphicsColorStroke;
     CTM = cp.CTM.Clone();
 }
 /**
 * Makes this <CODE>PdfContentByte</CODE> empty.
 * @param validateContent will call <code>sanityCheck()</code> if true.
 * @since 2.1.6
 */
 public void Reset( bool validateContent ) {
     content.Reset();
     markedContentSize = 0;
     if (validateContent) {
         SanityCheck();
     }
     state = new GraphicState();
     stateList = new List<GraphicState>();
 }
Exemple #38
0
 public override void Execute(GraphicState state, Stack<UInt32> stack, params bool[] flags)
 {
 }
Exemple #39
0
 public abstract void Execute(GraphicState state, Stack<UInt32> stack, params bool[] flags);
        static void Main(string[] args)
        {
            // ReSharper disable once UnusedVariable
            using (Library lib = new Library())
            {
                String sOutput = "Indexed-out.pdf";

                if (args.Length > 0)
                {
                    sOutput = args[0];
                }

                Console.WriteLine("Writing to output " + sOutput);

                Document doc     = new Document();
                Page     page    = doc.CreatePage(Document.BeforeFirstPage, new Rect(0, 0, 5 * 72, 4 * 72));
                Content  content = page.Content;
                Font     font;
                try
                {
                    font = new Font("Times-Roman", FontCreateFlags.Embedded | FontCreateFlags.Subset);
                }
                catch (ApplicationException ex)
                {
                    if (ex.Message.Equals("The specified font could not be found.") &&
                        System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices
                                                                                       .OSPlatform.Linux) &&
                        !System.IO.Directory.Exists("/usr/share/fonts/msttcore/"))
                    {
                        Console.WriteLine("Please install Microsoft Core Fonts on Linux first.");
                        return;
                    }

                    throw;
                }

                ColorSpace baseCS = ColorSpace.DeviceRGB;

                List <Int32> lookup = new List <Int32>();

                int[] lowhi = { 0, 255 };
                foreach (int r in lowhi)
                {
                    foreach (int g in lowhi)
                    {
                        foreach (int b in lowhi)
                        {
                            lookup.Add(r);
                            lookup.Add(g);
                            lookup.Add(b);
                        }
                    }
                }

                IndexedColorSpace cs = new IndexedColorSpace(baseCS, 7, lookup);

                GraphicState gs = new GraphicState();
                gs.FillColor = new Color(cs, new[] { 4.0 });


                Matrix textMatrix = new Matrix(24, 0, 0, 24,    // Set font width and height to 24 point size
                                               1 * 72, 2 * 72); // x, y coordinate on page, 1" x 2"

                TextRun textRun = new TextRun("Hello World!", font, gs, new TextState(), textMatrix);
                Text    text    = new Text();
                text.AddRun(textRun);
                content.AddElement(text);
                page.UpdateContent();

                doc.EmbedFonts();
                doc.Save(SaveFlags.Full, sOutput);
            }
        }
 /**
  * Restores the graphic state. <CODE>saveState</CODE> and
  * <CODE>restoreState</CODE> must be balanced.
  */
 public void RestoreState()
 {
     content.Append('Q').Append_i(separator);
     int idx = stateList.Count - 1;
     if (idx < 0)
         throw new IllegalPdfSyntaxException(MessageLocalization.GetComposedMessage("unbalanced.save.restore.state.operators"));
     state = stateList[idx];
     stateList.RemoveAt(idx);
 }
        static void Main(string[] args)
        {
            Console.WriteLine("AddVerticalText Sample:");

            using (Library lib = new Library())
            {
                Console.WriteLine("Initialized the library.");

                String sOutput = "../AddVerticalText-out.pdf";

                if (args.Length > 0)
                {
                    sOutput = args[0];
                }

                Console.WriteLine("Output file: " + sOutput);

                Document doc      = new Document();
                Rect     pageRect = new Rect(0, 0, 612, 792);
                Page     docpage  = doc.CreatePage(Document.BeforeFirstPage, pageRect);

                Text         unicodeText = new Text();
                GraphicState gs          = new GraphicState();
                TextState    ts          = new TextState();

                List <String> strings = new List <String>();

                strings.Add("\u0055\u006e\u0069\u0076\u0065\u0072\u0073\u0061\u006c\u0020\u0044\u0065\u0063\u006c\u0061\u0072\u0061\u0074\u0069\u006f\u006e\u0020\u006f\u0066\u0020\u0048\u0075\u006d\u0061\u006e\u0020\u0052\u0069\u0067\u0068\u0074\u0073");
                strings.Add("\u4e16\u754c\u4eba\u6743\u5ba3\u8a00");
                strings.Add("\u300e\u4e16\u754c\u4eba\u6a29\u5ba3\u8a00\u300f");
                strings.Add("\uc138\u0020\uacc4\u0020\uc778\u0020\uad8c\u0020\uc120\u0020\uc5b8");

                // Create the fonts with vertical WritingMode.  We don't need any special
                // FontCreateFlags, so we just pass zero
                List <Font> fonts = new List <Font>();
                fonts.Add(new Font("KozGoPr6N-Medium", 0, WritingMode.Vertical));
                fonts.Add(new Font("AdobeMyungjoStd-Medium", 0, WritingMode.Vertical));

                // These will be used to place the strings into position on the page.
                int x = 1 * 72;
                int y = 10 * 72;

                foreach (String str in strings)
                {
                    // Find a font that can represent all characters in the string, if there is one.
                    Font font = GetRepresentableFont(fonts, str);
                    if (font == null)
                    {
                        Console.WriteLine("Couldn't find a font that can represent all characters in the string: " + str);
                    }
                    else
                    {
                        // From this point, the string is handled the same way as non-Unicode text.
                        Matrix  m  = new Matrix(14, 0, 0, 14, x, y);
                        TextRun tr = new TextRun(str, font, gs, ts, m);
                        unicodeText.AddRun(tr);
                    }

                    // Start the next string moving across the page to the right
                    x += 30;
                }

                docpage.Content.AddElement(unicodeText);
                docpage.UpdateContent();


                // Save the document.
                Console.WriteLine("Embedding fonts.");
                doc.EmbedFonts(EmbedFlags.None);
                doc.Save(SaveFlags.Full, sOutput);
            }
        }
Exemple #43
0
 /**
  * Makes this <CODE>PdfContentByte</CODE> empty.
  */
 public void Reset()
 {
     content.Reset();
     stateList.Clear();
     state = new GraphicState();
 }
Exemple #44
0
 public override void Execute(GraphicState state, Stack <UInt32> stack, params bool[] flags)
 {
 }