示例#1
0
        public BatesStampDialog(RasterImage image, AnnBatesStampComposer targetComposer)
        {
            if (targetComposer == null)
            {
                throw new ArgumentNullException("targetComposer");
            }

            _targetComposer = targetComposer;

            _composer = new AnnBatesStampComposer();
            //if target container already have stamp then add it to dialog composer
            foreach (AnnBatesStamp stamp in _targetComposer.Stamps)
            {
                _composer.Stamps.Add(stamp.Clone());
            }

            InitializeComponent();

#if !USE_ImageViewerAutomationControl
            _viewer = new ImageViewer();
            var automationControl = new ImageViewerAutomationControl();
            automationControl.ImageViewer = _viewer;
#else
            _viewer = new AutomationImageViewer();
            IAnnAutomationControl automationControl = _viewer;
#endif
            _groupBoxViewer.Controls.Add(_viewer);
            _viewer.Dock  = DockStyle.Fill;
            _viewer.Image = image;
            automationControl.AutomationDataProvider = new RasterImageAutomationDataProvider(image);

            _manager.RenderingEngine = new AnnWinFormsRenderingEngine();
            AnnBatesStampComposer.RenderingEngine = _manager.RenderingEngine;
            _manager.CreateDefaultObjects();
            _automation = new AnnAutomation(_manager, automationControl);

            // Update the container size
            _automation.Container.Size = _automation.Container.Mapper.SizeToContainerCoordinates(LeadSizeD.Create(_viewer.Image.ImageWidth, _viewer.Image.ImageHeight));
            _automation.Active         = true;

            //Attach automation active container to _composer to start editing it
            _composer.TargetContainers.Add(_automation.Container);

            _listBoxContainerStamps.DataSource = _stampsList;
            _stampsList.ListChanged           += new ListChangedEventHandler(_stampsList_ListChanged);

            if (_composer.Stamps.Count > 0)
            {
                _currentBatesStamp = _composer.Stamps[0];

                UpdateControls();

                for (int i = 0; i < _composer.Stamps.Count; i++)
                {
                    AnnBatesStamp stamp = _composer.Stamps[i];
                    stamp.FriendlyName = string.Concat(stamp.FriendlyName, i);
                    _stampsList.Add(stamp);
                }
            }
        }
示例#2
0
        private void _btnAddStamp_Click(object sender, EventArgs e)
        {
            AnnBatesStamp stamp = new AnnBatesStamp();

            stamp.FriendlyName = string.Concat(stamp.FriendlyName, _listBoxContainerStamps.Items.Count);
            _currentBatesStamp = stamp;
            _composer.Stamps.Add(stamp);
            _stampsList.Add(stamp);
        }
示例#3
0
        private void UpdateControls()
        {
            if (_listBoxContainerStamps.SelectedIndex != -1)
            {
                _btnRemoveStamp.Enabled         = true;
                _groupBoxStampText.Enabled      = true;
                _groupBoxStampAlignment.Enabled = true;
                _groupBoxStampLogo.Enabled      = true;
                _groupBoxStampElements.Enabled  = true;
            }
            else
            {
                _btnRemoveStamp.Enabled         = false;
                _groupBoxStampText.Enabled      = false;
                _groupBoxStampAlignment.Enabled = false;
                _groupBoxStampLogo.Enabled      = false;
                _groupBoxStampElements.Enabled  = false;
                _txtElements.Text            = string.Empty;
                _checkBoxStretchLogo.Checked = false;
            }

            if (_checkBoxStretchLogo.Checked)
            {
                _groupBoxLogoPosition.Enabled = false;
            }
            else
            {
                _groupBoxLogoPosition.Enabled = true;
            }

            _currentBatesStamp = _listBoxContainerStamps.SelectedItem as AnnBatesStamp;

            if (_currentBatesStamp != null)
            {
                AnnBatesStampLogo logo = _currentBatesStamp.Logo;

                _lblBatesText.Font = AnnWinFormsRenderingEngine.ToFont(_currentBatesStamp.Font);
                AnnSolidColorBrush solidBrush = _currentBatesStamp.Foreground as AnnSolidColorBrush;
                _lblBatesText.ForeColor = ColorTranslator.FromHtml(solidBrush.Color);
                _lblBatesText.Text      = _currentBatesStamp.AsString(_automation.Container);
                _comboHorizontalAlignment.SelectedIndex = (int)_currentBatesStamp.HorizontalAlignment;
                _comboVerticalAlignment.SelectedIndex   = (int)_currentBatesStamp.VerticalAlignment;

                AnnPicture logoPicture = logo.Picture;
                if (_logoPictureBox.Image != null)
                {
                    _logoPictureBox.Image.Dispose();
                }

                if (logoPicture != null && logoPicture.PictureData != null)
                {
                    using (MemoryStream memoryStream = new MemoryStream(Convert.FromBase64String(logoPicture.PictureData)))
                    {
                        _logoPictureBox.Image = Image.FromStream(memoryStream);
                    }
                }
                else
                {
                    _logoPictureBox.Image = null;
                }

                LeadRectD logoPosition = _automation.Container.Mapper.RectFromContainerCoordinates(logo.LogoRect, AnnFixedStateOperations.None);
                _txtLogoPositionX.Text      = Math.Max(0, logoPosition.X).ToString();
                _txtLogoPositionY.Text      = Math.Max(0, logoPosition.Y).ToString();
                _txtLogoPositionWidth.Text  = Math.Round(logoPosition.Width, 1).ToString();
                _txtLogoPositionHeight.Text = Math.Round(logoPosition.Height, 1).ToString();

                _txtLogoOpacity.Text       = logo.Opacity.ToString();
                _txtLogoText.Text          = logo.Text;
                _txtLogoRotationAngle.Text = logo.Angle.ToString();

                _checkBoxStretchLogo.Checked = logo.StretchLogo;

                _txtElements.Text = _translator.WriteElementsToString(_currentBatesStamp.Elements.ToArray());
            }
            else //set default values
            {
                _lblBatesText.Font      = new Font(new FontFamily("Microsoft Sans Serif"), 8);
                _lblBatesText.ForeColor = Color.Black;
                _lblBatesText.Text      = string.Empty;
                _comboHorizontalAlignment.SelectedIndex = -1;
                _comboVerticalAlignment.SelectedIndex   = -1;
                _logoPictureBox.Image       = null;
                _txtLogoPositionX.Text      = "0";
                _txtLogoPositionY.Text      = "0";
                _txtLogoPositionWidth.Text  = "0";
                _txtLogoPositionHeight.Text = "0";
                _txtLogoOpacity.Text        = "1";
                _txtLogoText.Text           = string.Empty;
                _txtLogoRotationAngle.Text  = "0";
            }

            _btnDeleteLogoPicture.Enabled = (_logoPictureBox.Image != null);
            _automation.Invalidate(LeadRectD.Empty);
        }