private void Apply(
            ComboBox field
            )
        {
            Document document = field.Document;
            Widget   widget   = field.Widgets[0];

            Appearance appearance = widget.Appearance;

            if (appearance == null)
            {
                widget.Appearance = appearance = new Appearance(document);
            }

            widget.BaseDataObject[PdfName.DA] = new PdfString("/Helv " + FontSize + " Tf 0 0 0 rg");

            FormXObject normalAppearanceState;

            {
                SizeF size = widget.Box.Size;
                normalAppearanceState = new FormXObject(document, size);
                PrimitiveComposer composer = new PrimitiveComposer(normalAppearanceState);

                float      lineWidth = 1;
                RectangleF frame     = new RectangleF(lineWidth / 2, lineWidth / 2, size.Width - lineWidth, size.Height - lineWidth);
                if (GraphicsVisibile)
                {
                    composer.BeginLocalState();
                    composer.SetLineWidth(lineWidth);
                    composer.SetFillColor(BackColor);
                    composer.SetStrokeColor(ForeColor);
                    composer.DrawRectangle(frame, 5);
                    composer.FillStroke();
                    composer.End();
                }

                composer.BeginMarkedContent(PdfName.Tx);
                composer.SetFont(
                    new StandardType1Font(
                        document,
                        StandardType1Font.FamilyEnum.Helvetica,
                        false,
                        false
                        ),
                    FontSize
                    );
                composer.ShowText(
                    (string)field.Value,
                    new PointF(0, size.Height / 2),
                    XAlignmentEnum.Left,
                    YAlignmentEnum.Middle,
                    0
                    );
                composer.End();

                composer.Flush();
            }
            appearance.Normal[null] = normalAppearanceState;
        }
Example #2
0
        private void Apply(
            ListBox field
            )
        {
            Document document = field.Document;
            Widget   widget   = field.Widgets[0];

            Appearance appearance = widget.Appearance;
            {
                PdfDictionary widgetDataObject = widget.BaseDataObject;
                widgetDataObject[PdfName.DA] = new PdfString("/Helv " + FontSize + " Tf 0 0 0 rg");
                widgetDataObject[PdfName.MK] = new PdfDictionary(
                    new PdfName[]
                {
                    PdfName.BG,
                    PdfName.BC
                },
                    new PdfDirectObject[]
                {
                    new PdfArray(new PdfDirectObject[] { PdfReal.Get(.9), PdfReal.Get(.9), PdfReal.Get(.9) }),
                    new PdfArray(new PdfDirectObject[] { PdfInteger.Default, PdfInteger.Default, PdfInteger.Default })
                }
                    );
            }

            FormXObject normalAppearanceState;

            {
                SKSize size = widget.Box.Size;
                normalAppearanceState = new FormXObject(document, size);
                PrimitiveComposer composer = new PrimitiveComposer(normalAppearanceState);

                float  lineWidth = 1;
                SKRect frame     = SKRect.Create(lineWidth / 2, lineWidth / 2, size.Width - lineWidth, size.Height - lineWidth);
                if (GraphicsVisibile)
                {
                    composer.BeginLocalState();
                    composer.SetLineWidth(lineWidth);
                    composer.SetFillColor(BackColor);
                    composer.SetStrokeColor(ForeColor);
                    composer.DrawRectangle(frame, 5);
                    composer.FillStroke();
                    composer.End();
                }

                composer.BeginLocalState();
                if (GraphicsVisibile)
                {
                    composer.DrawRectangle(frame, 5);
                    composer.Clip(); // Ensures that the visible content is clipped within the rounded frame.
                }
                composer.BeginMarkedContent(PdfName.Tx);
                composer.SetFont(
                    new StandardType1Font(
                        document,
                        StandardType1Font.FamilyEnum.Helvetica,
                        false,
                        false
                        ),
                    FontSize
                    );
                double y = 3;
                foreach (ChoiceItem item in field.Items)
                {
                    composer.ShowText(
                        item.Text,
                        new SKPoint(0, (float)y)
                        );
                    y += FontSize * 1.175;
                    if (y > size.Height)
                    {
                        break;
                    }
                }
                composer.End();
                composer.End();

                composer.Flush();
            }
            appearance.Normal[null] = normalAppearanceState;
        }
Example #3
0
        private void Apply(
      ListBox field
      )
        {
            Document document = field.Document;
              Widget widget = field.Widgets[0];

              Appearance appearance = widget.Appearance;
              if(appearance == null)
              {widget.Appearance = appearance = new Appearance(document);}

              {
            PdfDictionary widgetDataObject = widget.BaseDataObject;
            widgetDataObject[PdfName.DA] = new PdfString("/Helv " + FontSize + " Tf 0 0 0 rg");
            widgetDataObject[PdfName.MK] = new PdfDictionary(
              new PdfName[]
              {
            PdfName.BG,
            PdfName.BC
              },
              new PdfDirectObject[]
              {
            new PdfArray(new PdfDirectObject[]{PdfReal.Get(.9), PdfReal.Get(.9), PdfReal.Get(.9)}),
            new PdfArray(new PdfDirectObject[]{PdfInteger.Default, PdfInteger.Default, PdfInteger.Default})
              }
              );
              }

              FormXObject normalAppearanceState;
              {
            SizeF size = widget.Box.Size;
            normalAppearanceState = new FormXObject(document, size);
            PrimitiveComposer composer = new PrimitiveComposer(normalAppearanceState);

            float lineWidth = 1;
            RectangleF frame = new RectangleF(lineWidth / 2, lineWidth / 2, size.Width - lineWidth, size.Height - lineWidth);
            if(GraphicsVisibile)
            {
              composer.BeginLocalState();
              composer.SetLineWidth(lineWidth);
              composer.SetFillColor(BackColor);
              composer.SetStrokeColor(ForeColor);
              composer.DrawRectangle(frame, 5);
              composer.FillStroke();
              composer.End();
            }

            composer.BeginLocalState();
            if(GraphicsVisibile)
            {
              composer.DrawRectangle(frame, 5);
              composer.Clip(); // Ensures that the visible content is clipped within the rounded frame.
            }
            composer.BeginMarkedContent(PdfName.Tx);
            composer.SetFont(
              new StandardType1Font(
            document,
            StandardType1Font.FamilyEnum.Helvetica,
            false,
            false
            ),
              FontSize
              );
            double y = 3;
            foreach(ChoiceItem item in field.Items)
            {
              composer.ShowText(
            item.Text,
            new PointF(0, (float)y)
            );
              y += FontSize * 1.175;
              if(y > size.Height)
            break;
            }
            composer.End();
            composer.End();

            composer.Flush();
              }
              appearance.Normal[null] = normalAppearanceState;
        }
Example #4
0
        private void Apply(
      ComboBox field
      )
        {
            Document document = field.Document;
              Widget widget = field.Widgets[0];

              Appearance appearance = widget.Appearance;
              if(appearance == null)
              {widget.Appearance = appearance = new Appearance(document);}

              widget.BaseDataObject[PdfName.DA] = new PdfString("/Helv " + FontSize + " Tf 0 0 0 rg");

              FormXObject normalAppearanceState;
              {
            SizeF size = widget.Box.Size;
            normalAppearanceState = new FormXObject(document, size);
            PrimitiveComposer composer = new PrimitiveComposer(normalAppearanceState);

            float lineWidth = 1;
            RectangleF frame = new RectangleF(lineWidth / 2, lineWidth / 2, size.Width - lineWidth, size.Height - lineWidth);
            if(GraphicsVisibile)
            {
              composer.BeginLocalState();
              composer.SetLineWidth(lineWidth);
              composer.SetFillColor(BackColor);
              composer.SetStrokeColor(ForeColor);
              composer.DrawRectangle(frame, 5);
              composer.FillStroke();
              composer.End();
            }

            composer.BeginMarkedContent(PdfName.Tx);
            composer.SetFont(
              new StandardType1Font(
            document,
            StandardType1Font.FamilyEnum.Helvetica,
            false,
            false
            ),
              FontSize
              );
            composer.ShowText(
              (string)field.Value,
              new PointF(0,size.Height/2),
              XAlignmentEnum.Left,
              YAlignmentEnum.Middle,
              0
              );
            composer.End();

            composer.Flush();
              }
              appearance.Normal[null] = normalAppearanceState;
        }
Example #5
0
        private void RefreshAppearance(
      )
        {
            Widget widget = Widgets[0];
              FormXObject normalAppearance;
              {
            AppearanceStates normalAppearances = widget.Appearance.Normal;
            normalAppearance = normalAppearances[null];
            if(normalAppearance == null)
            {normalAppearances[null] = normalAppearance = new FormXObject(Document, widget.Box.Size);}
              }
              PdfName fontName = null;
              double fontSize = 0;
              {
            PdfString defaultAppearanceState = DefaultAppearanceState;
            if(defaultAppearanceState == null)
            {
              // Retrieving the font to define the default appearance...
              fonts::Font defaultFont = null;
              PdfName defaultFontName = null;
              {
            // Field fonts.
            FontResources normalAppearanceFonts = normalAppearance.Resources.Fonts;
            foreach(KeyValuePair<PdfName,fonts::Font> entry in normalAppearanceFonts)
            {
              if(!entry.Value.Symbolic)
              {
                defaultFont = entry.Value;
                defaultFontName = entry.Key;
                break;
              }
            }
            if(defaultFontName == null)
            {
              // Common fonts.
              FontResources formFonts = Document.Form.Resources.Fonts;
              foreach(KeyValuePair<PdfName,fonts::Font> entry in formFonts)
              {
                if(!entry.Value.Symbolic)
                {
                  defaultFont = entry.Value;
                  defaultFontName = entry.Key;
                  break;
                }
              }
              if(defaultFontName == null)
              {
                //TODO:manage name collision!
                formFonts[
                  defaultFontName = new PdfName("default")
                  ] = defaultFont = new fonts::StandardType1Font(
                    Document,
                    fonts::StandardType1Font.FamilyEnum.Helvetica,
                    false,
                    false
                    );
              }
              normalAppearanceFonts[defaultFontName] = defaultFont;
            }
              }
              bytes::Buffer buffer = new bytes::Buffer();
              new SetFont(defaultFontName, IsMultiline ? 10 : 0).WriteTo(buffer, Document);
              widget.BaseDataObject[PdfName.DA] = defaultAppearanceState = new PdfString(buffer.ToByteArray());
            }

            // Retrieving the font to use...
            ContentParser parser = new ContentParser(defaultAppearanceState.ToByteArray());
            foreach(ContentObject content in parser.ParseContentObjects())
            {
              if(content is SetFont)
              {
            SetFont setFontOperation = (SetFont)content;
            fontName = setFontOperation.Name;
            fontSize = setFontOperation.Size;
            break;
              }
            }
            normalAppearance.Resources.Fonts[fontName] = Document.Form.Resources.Fonts[fontName];
              }

              // Refreshing the field appearance...
              /*
               * TODO: resources MUST be resolved both through the apperance stream resource dictionary and
               * from the DR-entry acroform resource dictionary
               */
              PrimitiveComposer baseComposer = new PrimitiveComposer(normalAppearance);
              BlockComposer composer = new BlockComposer(baseComposer);
              ContentScanner currentLevel = composer.Scanner;
              bool textShown = false;
              while(currentLevel != null)
              {
            if(!currentLevel.MoveNext())
            {
              currentLevel = currentLevel.ParentLevel;
              continue;
            }

            ContentObject content = currentLevel.Current;
            if(content is MarkedContent)
            {
              MarkedContent markedContent = (MarkedContent)content;
              if(PdfName.Tx.Equals(((BeginMarkedContent)markedContent.Header).Tag))
              {
            // Remove old text representation!
            markedContent.Objects.Clear();
            // Add new text representation!
            baseComposer.Scanner = currentLevel.ChildLevel; // Ensures the composer places new contents within the marked content block.
            ShowText(composer, fontName, fontSize);
            textShown = true;
              }
            }
            else if(content is Text)
            {currentLevel.Remove();}
            else if(currentLevel.ChildLevel != null)
            {currentLevel = currentLevel.ChildLevel;}
              }
              if(!textShown)
              {
            baseComposer.BeginMarkedContent(PdfName.Tx);
            ShowText(composer, fontName, fontSize);
            baseComposer.End();
              }
              baseComposer.Flush();
        }
        private void RefreshAppearance(
            )
        {
            Widget      widget = Widgets[0];
            FormXObject normalAppearance;
            {
                AppearanceStates normalAppearances = widget.Appearance.Normal;
                normalAppearance = normalAppearances[null];
                if (normalAppearance == null)
                {
                    normalAppearances[null] = normalAppearance = new FormXObject(Document, widget.Box.Size);
                }
            }
            PdfName fontName = null;
            double  fontSize = 0;
            {
                PdfString defaultAppearanceState = DefaultAppearanceState;
                if (defaultAppearanceState == null)
                {
                    // Retrieving the font to define the default appearance...
                    fonts::Font defaultFont     = null;
                    PdfName     defaultFontName = null;
                    {
                        // Field fonts.
                        FontResources normalAppearanceFonts = normalAppearance.Resources.Fonts;
                        foreach (KeyValuePair <PdfName, fonts::Font> entry in normalAppearanceFonts)
                        {
                            if (!entry.Value.Symbolic)
                            {
                                defaultFont     = entry.Value;
                                defaultFontName = entry.Key;
                                break;
                            }
                        }
                        if (defaultFontName == null)
                        {
                            // Common fonts.
                            FontResources formFonts = Document.Form.Resources.Fonts;
                            foreach (KeyValuePair <PdfName, fonts::Font> entry in formFonts)
                            {
                                if (!entry.Value.Symbolic)
                                {
                                    defaultFont     = entry.Value;
                                    defaultFontName = entry.Key;
                                    break;
                                }
                            }
                            if (defaultFontName == null)
                            {
                                //TODO:manage name collision!
                                formFonts[
                                    defaultFontName = new PdfName("default")
                                ] = defaultFont = new fonts::StandardType1Font(
                                    Document,
                                    fonts::StandardType1Font.FamilyEnum.Helvetica,
                                    false,
                                    false
                                    );
                            }
                            normalAppearanceFonts[defaultFontName] = defaultFont;
                        }
                    }
                    bytes::Buffer buffer = new bytes::Buffer();
                    new SetFont(defaultFontName, IsMultiline ? 10 : 0).WriteTo(buffer, Document);
                    widget.BaseDataObject[PdfName.DA] = defaultAppearanceState = new PdfString(buffer.ToByteArray());
                }

                // Retrieving the font to use...
                ContentParser parser = new ContentParser(defaultAppearanceState.ToByteArray());
                foreach (ContentObject content in parser.ParseContentObjects())
                {
                    if (content is SetFont)
                    {
                        SetFont setFontOperation = (SetFont)content;
                        fontName = setFontOperation.Name;
                        fontSize = setFontOperation.Size;
                        break;
                    }
                }
                normalAppearance.Resources.Fonts[fontName] = Document.Form.Resources.Fonts[fontName];
            }

            // Refreshing the field appearance...

            /*
             * TODO: resources MUST be resolved both through the apperance stream resource dictionary and
             * from the DR-entry acroform resource dictionary
             */
            PrimitiveComposer baseComposer = new PrimitiveComposer(normalAppearance);
            BlockComposer     composer     = new BlockComposer(baseComposer);
            ContentScanner    currentLevel = composer.Scanner;
            bool textShown = false;

            while (currentLevel != null)
            {
                if (!currentLevel.MoveNext())
                {
                    currentLevel = currentLevel.ParentLevel;
                    continue;
                }

                ContentObject content = currentLevel.Current;
                if (content is MarkedContent)
                {
                    MarkedContent markedContent = (MarkedContent)content;
                    if (PdfName.Tx.Equals(((BeginMarkedContent)markedContent.Header).Tag))
                    {
                        // Remove old text representation!
                        markedContent.Objects.Clear();
                        // Add new text representation!
                        baseComposer.Scanner = currentLevel.ChildLevel; // Ensures the composer places new contents within the marked content block.
                        ShowText(composer, fontName, fontSize);
                        textShown = true;
                    }
                }
                else if (content is Text)
                {
                    currentLevel.Remove();
                }
                else if (currentLevel.ChildLevel != null)
                {
                    currentLevel = currentLevel.ChildLevel;
                }
            }
            if (!textShown)
            {
                baseComposer.BeginMarkedContent(PdfName.Tx);
                ShowText(composer, fontName, fontSize);
                baseComposer.End();
            }
            baseComposer.Flush();
        }