private void ContextMenuStrip_Opening(object sender, CancelEventArgs e)
        {
            // Enable/disable menu items based on the annotation.
            AnnotationUI annotation = annotationViewer.Annotations.ActiveAnnotation;
            Type         at         = annotation.GetType();

            borderColorToolStripMenuItem.Enabled = at.GetProperty("Outline") != null;
            fillColorToolStripMenuItem.Enabled   = at.GetProperty("Fill") != null && at.Name != "RubberStampAnnotation";
            textColorToolStripMenuItem.Enabled   = at.GetProperty("FontBrush") != null;
            fontToolStripMenuItem.Enabled        = at.GetProperty("Font") != null;
        }
        private Atalasoft.Annotate.AnnotationPen GetAnnotationPen(AnnotationUI annotation, string propertyName)
        {
            Type at = annotation.GetType();

            System.Reflection.PropertyInfo info = at.GetProperty(propertyName);
            if (info == null)
            {
                return(null);
            }

            return(info.GetValue(annotation, null) as Atalasoft.Annotate.AnnotationPen);
        }
        private T GetAnnotationProperty <T>(AnnotationUI annotation, string propertyName) where T : class
        {
            Type         at   = annotation.GetType();
            PropertyInfo info = at.GetProperty(propertyName);

            if (info == null)
            {
                return(null);
            }

            return(info.GetValue(annotation, null) as T);
        }
        private Atalasoft.Annotate.AnnotationBrush GetAnnotationBrush(AnnotationUI annotation, string propertyName)
        {
            // Use reflection to see if there is a brush.
            Type at = annotation.GetType();

            System.Reflection.PropertyInfo info = at.GetProperty(propertyName);
            if (info == null)
            {
                return(null);
            }

            return(info.GetValue(annotation, null) as Atalasoft.Annotate.AnnotationBrush);
        }
            private LayerData[] LoadAnnotationData(object data)
            {
                LayerData[] layers = null;

                LayerCollection lc = data as LayerCollection;
                if (lc != null && lc.Count != 0)
                {
                    layers = new LayerData[lc.Count];

                    for (int i = 0; i < layers.Length; i++)
                    {
                        layers[i] = (LayerData)lc[i].Data;
                    }
                }

                LayerData[] lda = data as LayerData[];
                if (lda != null)
                {
                    layers = lda;
                }

                LayerAnnotation la = data as LayerAnnotation;
                if (la != null)
                {
                    layers = new LayerData[1];
                    layers[0] = (LayerData)la.Data;
                }

                LayerData ld = data as LayerData;
                if (ld != null)
                {
                    layers = new LayerData[1];
                    layers[0] = ld;
                }

                AnnotationUI ann = data as AnnotationUI;
                if (ann != null)
                {
                    layers = new LayerData[1];
                    layers[0].Items.Add(ann.Data);
                }

                AnnotationData ad = data as AnnotationData;
                if (ad != null)
                {
                    layers = new LayerData[1];
                    layers[0].Items.Add(ad);
                }

                return layers;
            }
        private void FontToolStripMenuItem_Click(object sender, EventArgs e)
        {
            AnnotationUI annotation = annotationViewer.Annotations.ActiveAnnotation;
            Type         at         = annotation.GetType();
            PropertyInfo info       = at.GetProperty("Font");

            if (info == null)
            {
                return;
            }

            AnnotationFont font = info.GetValue(annotation, null) as AnnotationFont;

            if (font == null)
            {
                return;
            }

            FontStyle fontStyle = FontStyle.Regular;

            if (font.Bold)
            {
                fontStyle = FontStyle.Bold;
            }
            if (font.Italic)
            {
                fontStyle |= FontStyle.Italic;
            }
            if (font.Strikeout)
            {
                fontStyle |= FontStyle.Strikeout;
            }
            if (font.Underline)
            {
                fontStyle |= FontStyle.Underline;
            }

            using (FontDialog dlg = new FontDialog())
            {
                dlg.Font = new Font(font.Name, font.Size, fontStyle);
                if (dlg.ShowDialog(this) == DialogResult.OK)
                {
                    font = new AnnotationFont(dlg.Font.Name, dlg.Font.Size, dlg.Font.Bold, dlg.Font.Italic, dlg.Font.Underline, dlg.Font.Strikeout);
                    info.SetValue(annotation, font, null);
                }
            }

            UpdateAnnotationDefault(annotation);
        }
        private void UpdateAnnotationDefault(AnnotationUI annotation)
        {
            if (String.IsNullOrEmpty(annotation.Data.Name))
            {
                return;
            }

            Type aType = typeof(AnnotationType);

            if (Enum.IsDefined(aType, annotation.Data.Name))
            {
                AnnotationType at = (AnnotationType)Enum.Parse(aType, annotation.Data.Name);
                this._defaultAnnotations.UpdateAnnotation(at, annotation);
            }
        }
Exemple #8
0
        /// <summary>
        /// Updates default annotation for specified annotation type.
        /// </summary>
        /// <param name="type">Annotation type to update.</param>
        /// <param name="annotation"><see cref="AnnotationUI"/> instance for specified annotation type.</param>
        public void UpdateAnnotation(AnnotationType type, AnnotationUI annotation)
        {
            var newAnn = (AnnotationUI)_table[type];

            var at = newAnn.GetType();

            CopyProperty("Fill", at, annotation, newAnn);
            CopyProperty("Outline", at, annotation, newAnn);
            CopyProperty("Font", at, annotation, newAnn);
            CopyProperty("FontBrush", at, annotation, newAnn);

            if (type != AnnotationType.RubberStamp && type != AnnotationType.StickyNote)
            {
                newAnn.Size = SizeF.Empty;
            }

            _table[type] = newAnn;
        }
            public LayerCollection ToAnnotationUI(LayerData[] layers, Size[] pageSizes)
            {
                LayerCollection retLayers = new LayerCollection();

                if (layers != null)
                {
                    ConvertFromWDV(layers, pageSizes);

                    foreach (LayerData layer in layers)
                    {
                        AnnotationUI outAnnot = _factories.GetAnnotationFromData(layer);
                        LayerAnnotation layerAnnot = outAnnot as LayerAnnotation;

                        retLayers.Add(layerAnnot);
                    }
                }

                return retLayers;
            }
Exemple #10
0
        private void CopyProperty(string propertyName, Type type, AnnotationUI annotation, AnnotationUI newAnnotation)
        {
            var info = type.GetProperty(propertyName);

            if (info == null)
            {
                return;
            }

            var val = info.GetValue(annotation, null);

            if (val == null)
            {
                return;
            }

            var objType     = val.GetType();
            var cloneMethod = objType.GetMethod("Clone");

            info.SetValue(newAnnotation, cloneMethod.Invoke(val, null), null);
        }
 private AnnotationPen GetAnnotationPen(AnnotationUI annotation, string propertyName)
 {
     return(GetAnnotationProperty <AnnotationPen>(annotation, propertyName));
 }
 private AnnotationBrush GetAnnotationBrush(AnnotationUI annotation, string propertyName)
 {
     return(GetAnnotationProperty <AnnotationBrush>(annotation, propertyName));
 }