예제 #1
0
        /// <summary>
        /// Add alternate content
        /// </summary>
        /// <param name="alternateContent"></param>
        /// <returns></returns>
        private string AddAlternateContent(AlternateContent alternateContent)
        {
            foreach (OpenXmlElement element in alternateContent.Elements())
            {
                if (element is AlternateContentFallback)
                {
                    return(AddAlternateContentFallback((AlternateContentFallback)element));
                }
            }

            return("");
        }
        private void OnClick_ButtonClearImage(object sender, RoutedEventArgs e)
        {
            if (DescriptionsListView.SelectedIndex < 0)
            {
                return;
            }
            AlternateContent altContent = (AlternateContent)DescriptionsListView.SelectedItem;

            m_ViewModel.SetDescriptionImage(altContent, null);

            forceRefreshUI_Image();
        }
예제 #3
0
        /// <summary>
        /// Append the workbookpr element
        /// </summary>
        /// <param name="filePath">Target excel faile path</param>
        /// <param name="log">Logger</param>
        public void AddElement(string filePath, VerifiableLog log)
        {
            using (SpreadsheetDocument package = SpreadsheetDocument.Open(filePath, true, new OpenSettings()
            {
                MarkupCompatibilityProcessSettings = new MarkupCompatibilityProcessSettings(MarkupCompatibilityProcessMode.ProcessAllParts, FileFormatVersions.Office2013)
            }))
            {
                try
                {
                    package.WorkbookPart.Workbook.AbsolutePath = null;
                    X15ac.AbsolutePath absolutePath = new X15ac.AbsolutePath()
                    {
                        Url = this.AbsolutePathUri
                    };
                    absolutePath.AddNamespaceDeclaration("x15ac", "http://schemas.microsoft.com/office/spreadsheetml/2010/11/ac");

                    AlternateContentChoice alternateContentChoice = new AlternateContentChoice()
                    {
                        Requires = "x15"
                    };
                    alternateContentChoice.Append(absolutePath);
                    log.Pass("Added AbsolutePath element.");

                    AlternateContent alternateContent = new AlternateContent();
                    alternateContent.AddNamespaceDeclaration("mc", "http://schemas.openxmlformats.org/markup-compatibility/2006");
                    alternateContent.Append(alternateContentChoice);

                    package.WorkbookPart.Workbook.InsertAfter(alternateContent, package.WorkbookPart.Workbook.Descendants <WorkbookProperties>().First());
                    //package.WorkbookPart.Workbook.Append(alternateContent);
                    log.Pass("Added AlternateContentChoice element.");

                    WorkbookExtensionList workbookExtensionList = package.WorkbookPart.Workbook.Descendants <WorkbookExtensionList>().Single();
                    WorkbookExtension     workbookExtension     = new WorkbookExtension()
                    {
                        Uri = this.workbookPrExtUri
                    };
                    workbookExtension.AddNamespaceDeclaration("x15", "http://schemas.microsoft.com/office/spreadsheetml/2010/11/main");

                    X15.WorkbookProperties workbookProperties = new X15.WorkbookProperties();
                    workbookProperties.ChartTrackingReferenceBase = false;

                    workbookExtension.AppendChild <X15.WorkbookProperties>(workbookProperties);
                    workbookExtensionList.AppendChild <WorkbookExtension>(workbookExtension);

                    log.Pass("Added workbookPr element.");
                }
                catch (Exception e)
                {
                    log.Fail(e.Message);
                }
            }
        }
예제 #4
0
        public void AcbValidationTest()
        {
            MCContext           mcContext = new MCContext();
            ParagraphProperties pPr;
            Run       run1, run2;
            Paragraph p = new Paragraph(
                pPr = new ParagraphProperties()
            {
                WordWrap = new WordWrap()
                {
                    Val = true
                }
            },
                new OpenXmlMiscNode(System.Xml.XmlNodeType.Comment, "<!-- comments -->"),
                run1 = new Run(new Text("Text 1.")),
                run2 = new Run(new Text("Text 2.")));

            p.AddNamespaceDeclaration("w14test", "http://w14.com");

            OpenXmlUnknownElement ignorableElement = new OpenXmlUnknownElement("w14test", "span", "http://w14.com");

            ignorableElement.MCAttributes = new MarkupCompatibilityAttributes()
            {
                Ignorable = "w14test"
            };
            p.InsertAfter(ignorableElement, pPr);

            Run runInAcb         = new Run(new Text("Text in ACB."));
            Run run2InAcb        = new Run(new Text("Text 2 in ACB."));
            AlternateContent acb = new AlternateContent(
                new AlternateContentChoice()
            {
                Requires = "w14test"
            },
                new AlternateContentFallback(runInAcb, run2InAcb));

            p.InsertAfter(acb, pPr);

            var validator = new OpenXmlValidator();
            var errors    = validator.Validate(p);

            Assert.Empty(errors);

            p.AppendChild(new OpenXmlUnknownElement("w15test", "art", "http://w15.com"));
            errors = validator.Validate(p);
            Assert.Single(errors);
            p.RemoveChild(p.LastChild);

            acb.LastChild.Append(new OpenXmlUnknownElement("w15test", "art", "http://w15.com"));
            errors = validator.Validate(p);
            Assert.Single(errors);
        }
예제 #5
0
        public void Bug704004(FileFormatVersions version)
        {
            var validator = new OpenXmlValidator(version);

            //<w:p>
            //    <ve:AlternateContent />
            //    <w:r>
            //        <w:t>Acb</w:t>
            //        <w:rPr>
            //            <w:rFonts w:hint="eastAsia"/>
            //        </w:rPr>
            //    </w:r>
            //</w:p>
            Paragraph        p   = new Paragraph();
            AlternateContent acb = p.AppendChild(new AlternateContent());

            // one error, w:rPr should before the w:t
            p.AppendChild(new Run(new DocumentFormat.OpenXml.Wordprocessing.Text()
            {
                Text = "Acb"
            },
                                  new RunProperties(new RunFonts()
            {
                Hint = FontTypeHintValues.EastAsia
            })
                                  )
                          );

            // an empty "AlternateContent"
            var errors = validator.Validate(p); // should no hang, no OOM

            Assert.Equal(2, errors.Count());
            Assert.Equal("Sch_IncompleteContentExpectingComplex", errors.First().Id);
            Assert.Same(p.FirstChild, errors.First().Node);  // acb should have a choice
            Assert.Same(p.FirstChild.NextSibling().FirstChild.NextSibling(), errors.ElementAt(1).RelatedNode);

            // append an empty "Choice"
            p.AddNamespaceDeclaration("w14", "http://w14");
            acb.AppendChild(new AlternateContentChoice()
            {
                Requires = "w14"
            });
            errors = validator.Validate(p); // should no hang, no OOM
            Assert.Single(errors);
            Assert.Same(p.FirstChild.NextSibling().FirstChild.NextSibling(), errors.ElementAt(0).RelatedNode);

            // append an empty "Fallback"
            acb.AppendChild(new AlternateContentFallback());
            errors = validator.Validate(p); // should no hang, no OOM
            Assert.Single(errors);
            Assert.Same(p.FirstChild.NextSibling().FirstChild.NextSibling(), errors.ElementAt(0).RelatedNode);
        }
예제 #6
0
        public void Init(TreeNode treeNode, AlternateContent altContent, Media media)
        {
            if (treeNode == null)
            {
                throw new ArgumentNullException("treeNode");
            }
            if (altContent == null)
            {
                throw new ArgumentNullException("altContent");
            }

            if (media == null)
            {
                throw new ArgumentNullException("media");
            }

            TreeNode         = treeNode;
            AlternateContent = altContent;
            Media            = media;

            if (media is ManagedAudioMedia)
            {
                OldMedia = m_AlternateContent.Audio;
                m_UsedMediaData.Add(((ManagedAudioMedia)media).AudioMediaData);
                if (OldMedia != null)
                {
                    m_UsedMediaData.Add(((ManagedAudioMedia)OldMedia).AudioMediaData);
                }
            }
            else if (media is ManagedImageMedia)
            {
                OldMedia = m_AlternateContent.Image;
                m_UsedMediaData.Add(((ManagedImageMedia)media).ImageMediaData);
                if (OldMedia != null)
                {
                    m_UsedMediaData.Add(((ManagedImageMedia)OldMedia).ImageMediaData);
                }
            }
            else if (media is TextMedia)
            {
                OldMedia = m_AlternateContent.Text;
            }
            else
            {
                throw new ArgumentException("media should be ManagedAudioMedia, ManagedImageMedia, or TextMedia");
            }
            ShortDescription = "Add new ManagedMedia";
            LongDescription  = "Attach a ManagedMedia to a AlternateContent";
        }
예제 #7
0
        //判断是否是图 参数picloc为图在第几段,所有可能的图都加进来了
        protected bool isPic(int picloc, Body body)
        {
            bool flag = false;

            if (matchPicName(picloc, body))
            {
                flag = true;
            }
            Paragraph p = null;

            if (body.ChildElements.GetItem(picloc).GetType().ToString() == "DocumentFormat.OpenXml.Wordprocessing.Paragraph")
            {
                p = (Paragraph)body.ChildElements.GetItem(picloc);
            }
            if (p != null)
            {
                IEnumerable <Run> runlist = p.Elements <Run>();
                foreach (Run r in runlist)
                {
                    if (r != null)
                    {
                        Drawing          d       = r.GetFirstChild <Drawing>();
                        Picture          pic     = r.GetFirstChild <Picture>();
                        EmbeddedObject   objects = r.GetFirstChild <EmbeddedObject>();
                        AlternateContent Alt     = r.GetFirstChild <AlternateContent>();
                        if (((d != null || pic != null)) || (flag == true && objects != null))
                        {
                            if (p.InnerText.Trim().Length < 65)
                            {
                                return(true);
                            }
                        }
                        else if (Alt != null)
                        {
                            AlternateContentChoice   AltChoice   = Alt.GetFirstChild <AlternateContentChoice>();
                            AlternateContentFallback AltFallback = Alt.GetFirstChild <AlternateContentFallback>();
                            if (AltChoice != null && AltFallback != null)
                            {
                                if (flag == true && (AltChoice.GetFirstChild <Drawing>() != null || AltFallback.GetFirstChild <Picture>() != null))
                                {
                                    return(true);
                                }
                            }
                        }
                    }
                }
            }
            return(false);
        }
예제 #8
0
        public string GetXmlID(AlternateContent altContent)
        {
            if (altContent.Metadatas != null)
            {
                foreach (var metadata in altContent.Metadatas.ContentsAs_Enumerable)
                {
                    if (metadata.NameContentAttribute != null &&
                        metadata.NameContentAttribute.Name.Equals(XmlReaderWriterHelper.XmlId))
                    {
                        return(metadata.NameContentAttribute.Value);
                    }
                }
            }

            return(null);
        }
        private void OnClick_ButtonRemoveMetadataAltContent(object sender, RoutedEventArgs e)
        {
            Tuple <TreeNode, TreeNode> selection = m_Session.GetTreeNodeSelection();
            TreeNode node = selection.Item2 ?? selection.Item1;

            if (node == null)
            {
                return;
            }

            var altProp = node.GetAlternateContentProperty();

            if (altProp == null)
            {
                return;
            }

            if (DescriptionsListView.SelectedIndex < 0)
            {
                return;
            }
            AlternateContent altContent = (AlternateContent)DescriptionsListView.SelectedItem;

            if (altProp.AlternateContents.IndexOf(altContent) < 0)
            {
                return;
            }

            int selectedIndex = MetadatasAltContentListView.SelectedIndex;

            if (selectedIndex < 0)
            {
                return;
            }
            m_ViewModel.RemoveMetadata(null, altContent, (Metadata)MetadatasAltContentListView.SelectedItem);
            MetadatasAltContentListView.Items.Refresh();
            if (MetadatasAltContentListView.Items.Count > 0)
            {
                MetadatasAltContentListView.SelectedIndex = selectedIndex < MetadatasAltContentListView.Items.Count
                                                                ? selectedIndex
                                                                : MetadatasAltContentListView.Items.Count - 1;
            }
            //FocusHelper.FocusBeginInvoke(MetadatasAltContentListView);


            DescriptionsListView.Items.Refresh();
        }
예제 #10
0
        public void SetDescriptionAudio(AlternateContent altContent, ManagedAudioMedia manMedia, TreeNode node)
        {
            if (manMedia == null ||
                manMedia.HasActualAudioMediaData && !manMedia.Duration.IsGreaterThan(Time.Zero))
            {
                if (altContent.Audio != null)
                {
                    AlternateContentRemoveManagedMediaCommand cmd1 =
                        node.Presentation.CommandFactory.CreateAlternateContentRemoveManagedMediaCommand(node, altContent,
                                                                                                         altContent.Audio);
                    node.Presentation.UndoRedoManager.Execute(cmd1);
                }
            }
            else
            {
                ManagedAudioMedia audio1     = node.Presentation.MediaFactory.CreateManagedAudioMedia();
                AudioMediaData    audioData1 = node.Presentation.MediaDataFactory.CreateAudioMediaData();
                audio1.AudioMediaData = audioData1;

                // WARNING: WavAudioMediaData implementation differs from AudioMediaData:
                // the latter is naive and performs a stream binary copy, the latter is optimized and re-uses existing WavClips.
                //  WARNING 2: The audio data from the given parameter gets emptied !
                //audio1.AudioMediaData.MergeWith(manMedia.AudioMediaData);

                if (!audio1.AudioMediaData.PCMFormat.Data.IsCompatibleWith(manMedia.AudioMediaData.PCMFormat.Data))
                {
                    throw new InvalidDataFormatException(
                              "Can not merge description audio with a AudioMediaData with incompatible audio data");
                }
                Stream stream = manMedia.AudioMediaData.OpenPcmInputStream();
                try
                {
                    audio1.AudioMediaData.AppendPcmData(stream, null); //manMedia.AudioMediaData.AudioDuration
                }
                finally
                {
                    stream.Close();
                }

                AlternateContentSetManagedMediaCommand cmd22 =
                    node.Presentation.CommandFactory.CreateAlternateContentSetManagedMediaCommand(node, altContent, audio1);
                node.Presentation.UndoRedoManager.Execute(cmd22);
            }

            RaisePropertyChanged(() => Descriptions);
        }
        public void SetDescriptionText(AlternateContent altContent, string txt)
        {
            Tuple <TreeNode, TreeNode> selection = m_UrakawaSession.GetTreeNodeSelection();
            TreeNode node = selection.Item2 ?? selection.Item1;

            if (node == null)
            {
                return;
            }

            var altProp = node.GetAlternateContentProperty();

            if (altProp == null)
            {
                return;
            }

            if (altProp.AlternateContents.IndexOf(altContent) < 0)
            {
                return;
            }

            if (string.IsNullOrEmpty(txt))
            {
                if (altContent.Text != null)
                {
                    AlternateContentRemoveManagedMediaCommand cmd1 =
                        node.Presentation.CommandFactory.CreateAlternateContentRemoveManagedMediaCommand(node, altContent,
                                                                                                         altContent.Text);
                    node.Presentation.UndoRedoManager.Execute(cmd1);
                }
            }
            else
            {
                TextMedia txt2 = node.Presentation.MediaFactory.CreateTextMedia();
                txt2.Text = txt;

                AlternateContentSetManagedMediaCommand cmd22 =
                    node.Presentation.CommandFactory.CreateAlternateContentSetManagedMediaCommand(node, altContent, txt2);
                node.Presentation.UndoRedoManager.Execute(cmd22);
            }

            RaisePropertyChanged(() => Descriptions);
        }
예제 #12
0
        private void OnClick_ButtonOpenImage(object sender, RoutedEventArgs e)
        {
            m_Logger.Log("DescriptionImage.OpenFileDialog", Category.Debug, Priority.Medium);

            var dlg = new OpenFileDialog
            {
                FileName         = "",
                DefaultExt       = DataProviderFactory.IMAGE_JPG_EXTENSION,
                Filter           = @"JPEG, PNG, BMP, GIF, SVG (*" + DataProviderFactory.IMAGE_JPEG_EXTENSION + ", *" + DataProviderFactory.IMAGE_JPG_EXTENSION + ", *" + DataProviderFactory.IMAGE_PNG_EXTENSION + ", *" + DataProviderFactory.IMAGE_BMP_EXTENSION + ", *" + DataProviderFactory.IMAGE_GIF_EXTENSION + ", *" + DataProviderFactory.IMAGE_SVG_EXTENSION + ", *" + DataProviderFactory.IMAGE_SVGZ_EXTENSION + ")|*" + DataProviderFactory.IMAGE_JPEG_EXTENSION + ";*" + DataProviderFactory.IMAGE_JPG_EXTENSION + ";*" + DataProviderFactory.IMAGE_PNG_EXTENSION + ";*" + DataProviderFactory.IMAGE_BMP_EXTENSION + ";*" + DataProviderFactory.IMAGE_GIF_EXTENSION + ";*" + DataProviderFactory.IMAGE_SVG_EXTENSION + ";*" + DataProviderFactory.IMAGE_SVGZ_EXTENSION + "",
                CheckFileExists  = false,
                CheckPathExists  = false,
                AddExtension     = true,
                DereferenceLinks = true,
                Title            = "Tobi: " + "Open image"
            };

            bool?result = false;

            m_ShellView.DimBackgroundWhile(() => { result = dlg.ShowDialog(); });

            if (result == false)
            {
                return;
            }

            string fullPath = "";

            fullPath = dlg.FileName;

            if (string.IsNullOrEmpty(fullPath))
            {
                return;
            }

            if (DescriptionsListView.SelectedIndex < 0)
            {
                return;
            }
            AlternateContent altContent = (AlternateContent)DescriptionsListView.SelectedItem;

            m_ViewModel.SetDescriptionImage(altContent, fullPath);

            forceRefreshUI_Image();
        }
        public static bool AltContentHasSignificantMetadata(AlternateContent altContent)
        {
            bool has = false;

            foreach (metadata.Metadata md in altContent.Metadatas.ContentsAs_Enumerable)
            {
                if (
                    !md.NameContentAttribute.Name.Equals(DiagramContentModelHelper.DiagramElementName) &&
                    !md.NameContentAttribute.Name.Equals(DiagramContentModelHelper.DiagramElementName_OBSOLETE) &&
                    !md.NameContentAttribute.Name.Equals(XmlReaderWriterHelper.XmlId)
                    )
                {
                    has = true;
                    break;
                }
            }

            return(has);
        }
예제 #14
0
        public void AddMetadata(AlternateContentProperty altProp, AlternateContent altContent,
                                string newName, string newValue)
        {
            if (string.IsNullOrEmpty(newName) || string.IsNullOrEmpty(newValue))
            {
                return;
            }

            Tuple <TreeNode, TreeNode> selection = m_UrakawaSession.GetTreeNodeSelection();
            TreeNode node = selection.Item2 ?? selection.Item1;

            if (node == null)
            {
                return;
            }

            var altProp_ = node.GetOrCreateAlternateContentProperty();

            if (altProp != null && altProp_ != altProp)
            {
                return;
            }

            if (altContent != null && altProp_.AlternateContents.IndexOf(altContent) < 0)
            {
                return;
            }

            Metadata meta = node.Presentation.MetadataFactory.CreateMetadata();

            meta.NameContentAttribute      = new MetadataAttribute();
            meta.NameContentAttribute.Name = newName;
            //meta.NameContentAttribute.NamespaceUri = "dummy namespace";
            meta.NameContentAttribute.Value = newValue;
            AlternateContentMetadataAddCommand cmd = node.Presentation.CommandFactory.CreateAlternateContentMetadataAddCommand(node, altProp, altContent, meta, null);

            node.Presentation.UndoRedoManager.Execute(cmd);

            RaisePropertyChanged(() => Metadatas);
            RaisePropertyChanged(() => Descriptions);
        }
        private void OnClick_ButtonRemoveDescription(object sender, RoutedEventArgs e)
        {
            int selectedIndex = DescriptionsListView.SelectedIndex;

            if (selectedIndex < 0)
            {
                return;
            }
            AlternateContent altContent = (AlternateContent)DescriptionsListView.SelectedItem;

            m_ViewModel.RemoveDescription(altContent);

            DescriptionsListView.Items.Refresh();
            if (DescriptionsListView.Items.Count > 0)
            {
                DescriptionsListView.SelectedIndex = selectedIndex < DescriptionsListView.Items.Count
                                                                ? selectedIndex
                                                                : DescriptionsListView.Items.Count - 1;
            }
            //FocusHelper.FocusBeginInvoke(DescriptionsListView);
        }
        private AlternateContent addNewDescription(string uid, string descriptionName)
        {
            AlternateContent altContent = m_ViewModel.AddDescription(uid, descriptionName);

            DescriptionsListView.Items.Refresh();
            DescriptionsListView.SelectedIndex = DescriptionsListView.Items.Count - 1;
            //FocusHelper.FocusBeginInvoke(DescriptionsListView);

            DebugFix.Assert(DescriptionsListView.SelectedItem == altContent);

            MetadatasAltContentListView.Items.Refresh();
            if (MetadatasAltContentListView.Items.Count > 0)
            {
                MetadatasAltContentListView.SelectedIndex = MetadatasAltContentListView.Items.Count - 1;
            }
            //FocusHelper.FocusBeginInvoke(MetadatasAltContentListView);

            //BindingExpression be = DescriptionTextBox.GetBindingExpression(TextBoxReadOnlyCaretVisible.TextReadOnlyProperty);
            //if (be != null) be.UpdateTarget();

            return(altContent);
        }
        public void Init(TreeNode treeNode, AlternateContentProperty altContentProperty, AlternateContent altContent, Metadata metadata, MetadataAttribute metadataAttribute)
        {
            if (treeNode == null)
            {
                throw new ArgumentNullException("treeNode");
            }
            if (metadata == null)
            {
                throw new ArgumentNullException("metadata");
            }
            if (metadataAttribute == null)
            {
                if (altContentProperty == null && altContent == null)
                {
                    throw new ArgumentNullException("altContentProperty && altContent");
                }
                if (altContentProperty != null && altContent != null)
                {
                    throw new ArgumentException("altContentProperty && altContent");
                }
            }
            else
            {
                if (altContentProperty == null || altContent != null)
                {
                    throw new ArgumentException("metadataAttribute != null ++ altContentProperty == null || altContent != null");
                }
            }

            TreeNode                   = treeNode;
            Metadata                   = metadata;
            MetadataAttribute          = metadataAttribute;
            m_AlternateContent         = altContent;
            m_AlternateContentProperty = altContentProperty;

            ShortDescription = "Add metadata";
            LongDescription  = "Add the Metadata object to the AlternateContent";
        }
예제 #18
0
        private void OnClick_ButtonEditText_Specific(string diagramElementName)
        {
            bool             descWasAdded = false;
            AlternateContent altContent   = m_ViewModel.GetAltContent(diagramElementName);

            if (altContent == null)
            {
                string uid = m_ViewModel.GetNewXmlID(diagramElementName.Replace(':', '_'));
                altContent   = addNewDescription(uid, diagramElementName);
                descWasAdded = true;
            }

            DebugFix.Assert(altContent != null);
            DescriptionsListView.SelectedItem = altContent;
            DebugFix.Assert(DescriptionsListView.SelectedItem == altContent);

            OnClick_ButtonEditText(null, null);

            if (descWasAdded && (altContent.Text == null || string.IsNullOrEmpty(altContent.Text.Text)))
            {
                m_ViewModel.RemoveDescription(altContent);
            }
        }
예제 #19
0
        public void Bug718316()
        {
            using (WordprocessingDocument doc = WordprocessingDocument.Create("tmp.docx", WordprocessingDocumentType.Document))
            {
                var mpart = doc.AddMainDocumentPart();
                mpart.Document      = new Document();
                mpart.Document.Body = new Body();
                var ac = new AlternateContent();
                mpart.Document.Body.Append(ac);
                var c = new AlternateContentChoice();
                c.AddNamespaceDeclaration("w13", "http://w13");
                c.Requires = "w13";
                ac.Append(c);
            }

            OpenSettings s = new OpenSettings();

            s.MarkupCompatibilityProcessSettings = new MarkupCompatibilityProcessSettings(MarkupCompatibilityProcessMode.ProcessAllParts, FileFormatVersions.Office2007);
            using (var doc = WordprocessingDocument.Open("tmp.docx", true, s))
            {
                Assert.Null(doc.MainDocumentPart.Document.Body.FirstChild);
            }
            System.IO.File.Delete("tmp.docx");
        }
예제 #20
0
        public void SetDescriptionAudio(AlternateContent altContent, ManagedAudioMedia manMedia)
        {
            Tuple <TreeNode, TreeNode> selection = m_UrakawaSession.GetTreeNodeSelection();
            TreeNode node = selection.Item2 ?? selection.Item1;

            if (node == null)
            {
                return;
            }

            var altProp = node.GetAlternateContentProperty();

            if (altProp == null)
            {
                return;
            }

            if (altProp.AlternateContents.IndexOf(altContent) < 0)
            {
                return;
            }

            SetDescriptionAudio(altContent, manMedia, node);
        }
        private bool getValidationText_BasicImage(ref string message)
        {
            bool first = true;

            AlternateContent altContent = GetAltContent(DiagramContentModelHelper.D_SimplifiedImage);

            if (altContent != null)
            {
                if (altContent.Image != null && altContent.Text == null)
                {
                    if (!first)
                    {
                        if (message != null)
                        {
                            message += "\n";
                        }
                    }
                    first = false;
                    if (message != null)
                    {
                        message += "- It is recommended to specify a tour for the simplified image.";
                    }
                }

                bool otherDataInAdvancedMode = altContent.Audio != null ||
                                               Daisy3_Export.AltContentHasSignificantMetadata(altContent);
                if (altContent.Image == null &&
                    (
                        altContent.Text != null ||
                        otherDataInAdvancedMode
                    )
                    )
                {
                    if (!first)
                    {
                        if (message != null)
                        {
                            message += "\n";
                        }
                    }
                    first = false;
                    if (message != null)
                    {
                        message += "- The simplified image is missing.";
                        if (otherDataInAdvancedMode)
                        {
                            message += " (has other data, see advanced editor)";
                        }
                    }
                }
                //if (altContent.Image == null && altContent.Text != null)
                //{
                //    if (!first)
                //    {
                //        if (message != null)
                //        {
                //            message += "\n";
                //        }
                //    }
                //    first = false;
                //    if (message != null)
                //    {
                //        message += "- A tour is specified without its associated simplified image.";
                //    }
                //}
                if (altContent.Audio != null && altContent.Text == null)
                {
                    if (!first)
                    {
                        if (message != null)
                        {
                            message += "\n";
                        }
                    }
                    first = false;
                    if (message != null)
                    {
                        message += "- The simplified image has audio but no corresponding tour.";
                    }
                }
            }
            altContent = GetAltContent(DiagramContentModelHelper.D_Tactile);
            if (altContent != null)
            {
                if (altContent.Image != null && altContent.Text == null)
                {
                    if (!first)
                    {
                        if (message != null)
                        {
                            message += "\n";
                        }
                    }
                    first = false;
                    if (message != null)
                    {
                        message += "- It is recommended to specify a tour for the tactile image.";
                    }
                }
                bool otherDataInAdvancedMode = altContent.Audio != null ||
                                               Daisy3_Export.AltContentHasSignificantMetadata(altContent);
                if (altContent.Image == null &&
                    (
                        altContent.Text != null ||
                        otherDataInAdvancedMode
                    )
                    )
                {
                    if (!first)
                    {
                        if (message != null)
                        {
                            message += "\n";
                        }
                    }
                    first = false;
                    if (message != null)
                    {
                        message += "- The tactile image is missing.";
                        if (otherDataInAdvancedMode)
                        {
                            message += " (has other data, see advanced editor)";
                        }
                    }
                }
                //if (altContent.Image == null && altContent.Text != null)
                //{
                //    if (!first)
                //    {
                //        if (message != null)
                //        {
                //            message += "\n";
                //        }
                //    }
                //    first = false;
                //    if (message != null)
                //    {
                //        message += "- A tour is specified without its associated tactile image.";
                //    }
                //}
                if (altContent.Audio != null && altContent.Text == null)
                {
                    if (!first)
                    {
                        if (message != null)
                        {
                            message += "\n";
                        }
                    }
                    first = false;
                    if (message != null)
                    {
                        message += "- The tactile image has audio but no corresponding tour.";
                    }
                }
            }

            bool hasMessages = !first;

            return(hasMessages);
        }
        private bool getValidationText_BasicText(ref string message)
        {
            bool first = true;

            AlternateContent altContent = GetAltContent(DiagramContentModelHelper.D_LondDesc);

            if (altContent == null
                ||
                altContent.Text == null
                ||
                string.IsNullOrEmpty(altContent.Text.Text)
                )
            {
                if (!first)
                {
                    if (message != null)
                    {
                        message += "\n";
                    }
                }
                first = false;
                if (message != null)
                {
                    message += "- A long description must be specified.";
                }
            }
            else
            {
                //bool otherDataInAdvancedMode = altContent.Audio != null
                //                               || Daisy3_Export.AltContentHasSignificantMetadata(altContent);
                //if (altContent.Text == null
                //    && otherDataInAdvancedMode
                //    )
                //{
                //    if (!first)
                //    {
                //        if (message != null)
                //        {
                //            message += "\n";
                //        }
                //    }
                //    first = false;
                //    if (message != null)
                //    {
                //        message += "- The long description has no text.";
                //        if (otherDataInAdvancedMode)
                //        {
                //            message += " (has other data, see advanced editor)";
                //        }
                //    }
                //}

                //if (altContent.Audio != null && altContent.Text == null)
                //{
                //    if (!first)
                //    {
                //        if (message != null)
                //        {
                //            message += "\n";
                //        }
                //    }
                //    first = false;
                //    if (message != null)
                //    {
                //        message += "- The long description has audio but no corresponding text.";
                //    }
                //}
            }

            altContent = GetAltContent(DiagramContentModelHelper.D_Summary);
            if (altContent != null)
            {
                bool otherDataInAdvancedMode = altContent.Audio != null ||
                                               Daisy3_Export.AltContentHasSignificantMetadata(altContent);
                if (altContent.Text == null &&
                    otherDataInAdvancedMode
                    )
                {
                    if (!first)
                    {
                        if (message != null)
                        {
                            message += "\n";
                        }
                    }
                    first = false;
                    if (message != null)
                    {
                        message += "- The summary has no text.";
                        if (otherDataInAdvancedMode)
                        {
                            message += " (has other data, see advanced editor)";
                        }
                    }
                }

                //if (altContent.Audio != null && altContent.Text == null)
                //{
                //    if (!first)
                //    {
                //        if (message != null)
                //        {
                //            message += "\n";
                //        }
                //    }
                //    first = false;
                //    if (message != null)
                //    {
                //        message += "- The summary has audio but no corresponding text.";
                //    }
                //}
            }

            altContent = GetAltContent(DiagramContentModelHelper.D_SimplifiedLanguageDescription);
            if (altContent != null)
            {
                bool otherDataInAdvancedMode = altContent.Audio != null ||
                                               Daisy3_Export.AltContentHasSignificantMetadata(altContent);
                if (altContent.Text == null &&
                    otherDataInAdvancedMode
                    )
                {
                    if (!first)
                    {
                        if (message != null)
                        {
                            message += "\n";
                        }
                    }
                    first = false;
                    if (message != null)
                    {
                        message += "- The simplified language has no text.";
                        if (otherDataInAdvancedMode)
                        {
                            message += " (has other data, see advanced editor)";
                        }
                    }
                }

                //if (altContent.Audio != null && altContent.Text == null)
                //{
                //    if (!first)
                //    {
                //        if (message != null)
                //        {
                //            message += "\n";
                //        }
                //    }
                //    first = false;
                //    if (message != null)
                //    {
                //        message += "- The simplified language has audio but no corresponding text.";
                //    }
                //}
            }

            bool hasMessages = !first;

            return(hasMessages);
        }
        private void OnClick_ButtonAddMetadataAltContent(object sender, RoutedEventArgs e)
        {
            Tuple <TreeNode, TreeNode> selection = m_Session.GetTreeNodeSelection();
            TreeNode node = selection.Item2 ?? selection.Item1;

            if (node == null)
            {
                return;
            }

            var altProp = node.GetAlternateContentProperty();

            if (altProp == null)
            {
                return;
            }

            if (DescriptionsListView.SelectedIndex < 0)
            {
                return;
            }
            AlternateContent altContent = (AlternateContent)DescriptionsListView.SelectedItem;

            if (altProp.AlternateContents.IndexOf(altContent) < 0)
            {
                return;
            }

            var mdAttr = new MetadataAttribute();

            mdAttr.Name  = ""; // PROMPT_MD_NAME;
            mdAttr.Value = ""; // PROMPT_MD_VALUE;
            string newName  = null;
            string newValue = null;

            bool invalidSyntax = false;
            bool ok            = true;

            while (ok &&
                   (
                       invalidSyntax ||
                       string.IsNullOrEmpty(newName) ||
                       string.IsNullOrEmpty(newValue)
                       //|| newName == PROMPT_MD_NAME
                       //|| newValue == PROMPT_MD_VALUE
                   )
                   )
            {
                ok           = showMetadataAttributeEditorPopupDialog("Name", "Value", mdAttr, out newName, out newValue, true, false, invalidSyntax);
                mdAttr.Name  = newName;
                mdAttr.Value = newValue;
                if (!string.IsNullOrEmpty(newName) && !string.IsNullOrEmpty(newValue))
                {
                    invalidSyntax =
                        m_ViewModel.IsIDInValid(newName) ||
                        (
                            (newName.Equals(XmlReaderWriterHelper.XmlId) || newName.Equals(DiagramContentModelHelper.DiagramElementName)) &&
                            m_ViewModel.IsIDInValid(newValue)
                        );
                }
            }
            if (!ok)
            {
                return;
            }

            //bool ok = showMetadataAttributeEditorPopupDialog(mdAttr, out newName, out newValue, true);
            //if (ok &&
            //    newName != mdAttr.Name && newValue != mdAttr.Value)
            //{
            foreach (Metadata m in altContent.Metadatas.ContentsAs_Enumerable)
            {
                if (m.NameContentAttribute.Name == newName)
                {
                    var label = new TextBlock
                    {
                        Text   = "This attribute already exists.",
                        Margin = new Thickness(8, 0, 8, 0),
                        HorizontalAlignment = HorizontalAlignment.Center,
                        VerticalAlignment   = VerticalAlignment.Center,
                        Focusable           = true,
                        TextWrapping        = TextWrapping.Wrap
                    };

                    var iconProvider = new ScalableGreyableImageProvider(m_ShellView.LoadTangoIcon("dialog-warning"), m_ShellView.MagnificationLevel);

                    var panel = new StackPanel
                    {
                        Orientation         = Orientation.Horizontal,
                        HorizontalAlignment = HorizontalAlignment.Center,
                        VerticalAlignment   = VerticalAlignment.Stretch,
                    };
                    panel.Children.Add(iconProvider.IconLarge);
                    panel.Children.Add(label);
                    //panel.Margin = new Thickness(8, 8, 8, 0);

                    var windowPopup = new PopupModalWindow(m_ShellView,
                                                           UserInterfaceStrings.EscapeMnemonic("Duplicate attribute!"),
                                                           panel,
                                                           PopupModalWindow.DialogButtonsSet.Ok,
                                                           PopupModalWindow.DialogButton.Ok,
                                                           true, 300, 160, null, 0, m_DescriptionPopupModalWindow);
                    //view.OwnerWindow = windowPopup;

                    windowPopup.ShowModal();
                    return;
                }
            }


            m_ViewModel.AddMetadata(null, altContent, newName, newValue);
            MetadatasAltContentListView.Items.Refresh();
            MetadatasAltContentListView.SelectedIndex = MetadatasAltContentListView.Items.Count - 1;
            //FocusHelper.FocusBeginInvoke(MetadatasAltContentListView);

            DescriptionsListView.Items.Refresh();
        }
        private void OnMouseDoubleClick_ListItemMetadataAltContent(object sender, MouseButtonEventArgs e)
        {
            Tuple <TreeNode, TreeNode> selection = m_Session.GetTreeNodeSelection();
            TreeNode node = selection.Item2 ?? selection.Item1;

            if (node == null)
            {
                return;
            }

            var altProp = node.GetAlternateContentProperty();

            if (altProp == null)
            {
                return;
            }

            if (DescriptionsListView.SelectedIndex < 0)
            {
                return;
            }
            AlternateContent altContent = (AlternateContent)DescriptionsListView.SelectedItem;

            if (altProp.AlternateContents.IndexOf(altContent) < 0)
            {
                return;
            }

            if (MetadatasAltContentListView.SelectedIndex < 0)
            {
                return;
            }
            Metadata md       = (Metadata)MetadatasAltContentListView.SelectedItem;
            string   newName  = null;
            string   newValue = null;

            var mdAttrTEMP = new MetadataAttribute();

            mdAttrTEMP.Name  = md.NameContentAttribute.Name;
            mdAttrTEMP.Value = md.NameContentAttribute.Value;

            bool invalidSyntax = false;
            bool ok            = true;

            while (ok &&
                   (
                       invalidSyntax ||
                       string.IsNullOrEmpty(newName) ||
                       string.IsNullOrEmpty(newValue)
                   )
                   )
            {
                ok = showMetadataAttributeEditorPopupDialog(Tobi.Plugin.Descriptions.Tobi_Plugin_Descriptions_Lang.Name, Tobi.Plugin.Descriptions.Tobi_Plugin_Descriptions_Lang.Value, mdAttrTEMP, out newName, out newValue, true, false, invalidSyntax);

                if (!ok)
                {
                    return;
                }
                else if (newName == md.NameContentAttribute.Name &&
                         newValue == md.NameContentAttribute.Value)
                {
                    return;
                }

                mdAttrTEMP.Name  = newName;
                mdAttrTEMP.Value = newValue;
                if (!string.IsNullOrEmpty(newName) && !string.IsNullOrEmpty(newValue))
                {
                    invalidSyntax =
                        m_ViewModel.IsIDInValid(newName) ||
                        (
                            (newName.Equals(XmlReaderWriterHelper.XmlId) || newName.Equals(DiagramContentModelHelper.DiagramElementName)) &&
                            m_ViewModel.IsIDInValid(newValue)
                        );
                }
            }

            //bool ok = showMetadataAttributeEditorPopupDialog(md.NameContentAttribute, out newName, out newValue, true);
            //if (ok &&
            //    (newName != md.NameContentAttribute.Name || newValue != md.NameContentAttribute.Value))
            //{
            foreach (Metadata m in altContent.Metadatas.ContentsAs_Enumerable)
            {
                if (md == m)
                {
                    continue;
                }

                if (m.NameContentAttribute.Name == newName)
                {
                    var label = new TextBlock
                    {
                        Text   = Tobi.Plugin.Descriptions.Tobi_Plugin_Descriptions_Lang.AttributeAlreadyExists,
                        Margin = new Thickness(8, 0, 8, 0),
                        HorizontalAlignment = HorizontalAlignment.Center,
                        VerticalAlignment   = VerticalAlignment.Center,
                        Focusable           = true,
                        TextWrapping        = TextWrapping.Wrap
                    };

                    var iconProvider = new ScalableGreyableImageProvider(m_ShellView.LoadTangoIcon("dialog-warning"), m_ShellView.MagnificationLevel);

                    var panel = new StackPanel
                    {
                        Orientation         = Orientation.Horizontal,
                        HorizontalAlignment = HorizontalAlignment.Center,
                        VerticalAlignment   = VerticalAlignment.Stretch,
                    };
                    panel.Children.Add(iconProvider.IconLarge);
                    panel.Children.Add(label);
                    //panel.Margin = new Thickness(8, 8, 8, 0);

                    var windowPopup = new PopupModalWindow(m_ShellView,
                                                           UserInterfaceStrings.EscapeMnemonic(Tobi.Plugin.Descriptions.Tobi_Plugin_Descriptions_Lang.DuplicateAttribute),
                                                           panel,
                                                           PopupModalWindow.DialogButtonsSet.Ok,
                                                           PopupModalWindow.DialogButton.Ok,
                                                           true, 300, 160, null, 0, m_DescriptionPopupModalWindow);
                    //view.OwnerWindow = windowPopup;


                    windowPopup.ShowModal();
                    return;
                }
            }

            m_ViewModel.SetMetadataAttr(null, altContent, md, null, newName, newValue);

            MetadatasAltContentListView.Items.Refresh();


            DescriptionsListView.Items.Refresh();
        }
예제 #25
0
        // Generates content of chartPart1.
        private void GenerateChartPart1Content(ChartPart chartPart1, Chart chart)
        {
            C.ChartSpace chartSpace1 = new C.ChartSpace();
            chartSpace1.AddNamespaceDeclaration("c", "http://schemas.openxmlformats.org/drawingml/2006/chart");
            chartSpace1.AddNamespaceDeclaration("a", "http://schemas.openxmlformats.org/drawingml/2006/main");
            chartSpace1.AddNamespaceDeclaration("r", "http://schemas.openxmlformats.org/officeDocument/2006/relationships");
            chartSpace1.AddNamespaceDeclaration("c16r2", "http://schemas.microsoft.com/office/drawing/2015/06/chart");
            C.Date1904 date19041 = new C.Date1904()
            {
                Val = false
            };
            C.EditingLanguage editingLanguage1 = new C.EditingLanguage()
            {
                Val = "en-US"
            };
            C.RoundedCorners roundedCorners1 = new C.RoundedCorners()
            {
                Val = true
            };

            AlternateContent alternateContent1 = new AlternateContent();

            alternateContent1.AddNamespaceDeclaration("mc", "http://schemas.openxmlformats.org/markup-compatibility/2006");

            AlternateContentChoice alternateContentChoice1 = new AlternateContentChoice()
            {
                Requires = "c14"
            };

            alternateContentChoice1.AddNamespaceDeclaration("c14", "http://schemas.microsoft.com/office/drawing/2007/8/2/chart");
            C14.Style style1 = new C14.Style()
            {
                Val = 110
            };

            alternateContentChoice1.Append(style1);

            AlternateContentFallback alternateContentFallback1 = new AlternateContentFallback();

            C.Style style2 = new C.Style()
            {
                Val = 10
            };

            alternateContentFallback1.Append(style2);

            alternateContent1.Append(alternateContentChoice1);
            alternateContent1.Append(alternateContentFallback1);

            C.Chart chart1 = new C.Chart();

            C.Title title1 = new C.Title();

            C.ChartText chartText1 = new C.ChartText();

            C.RichText       richText1       = new C.RichText();
            A.BodyProperties bodyProperties1 = new A.BodyProperties();
            A.ListStyle      listStyle1      = new A.ListStyle();

            A.Paragraph paragraph1 = new A.Paragraph();

            A.ParagraphProperties  paragraphProperties1  = new A.ParagraphProperties();
            A.DefaultRunProperties defaultRunProperties1 = new A.DefaultRunProperties();

            paragraphProperties1.Append(defaultRunProperties1);

            A.Run           run1           = new A.Run();
            A.RunProperties runProperties1 = new A.RunProperties()
            {
                Language = "en-US", FontSize = 800
            };
            A.Text text1 = new A.Text();
            text1.Text = "";

            run1.Append(runProperties1);
            run1.Append(text1);

            A.Run           run2           = new A.Run();
            A.RunProperties runProperties2 = new A.RunProperties()
            {
                Language = "en-US", FontSize = 800, Baseline = 0
            };
            A.Text text2 = new A.Text();
            text2.Text = chart.Title;

            run2.Append(runProperties2);
            run2.Append(text2);
            A.EndParagraphRunProperties endParagraphRunProperties1 = new A.EndParagraphRunProperties()
            {
                Language = "en-US", FontSize = 800
            };

            paragraph1.Append(paragraphProperties1);
            paragraph1.Append(run1);
            paragraph1.Append(run2);
            paragraph1.Append(endParagraphRunProperties1);

            richText1.Append(bodyProperties1);
            richText1.Append(listStyle1);
            richText1.Append(paragraph1);

            chartText1.Append(richText1);

            C.Layout layout1 = new C.Layout();

            C.ManualLayout manualLayout1 = new C.ManualLayout();
            C.LeftMode     leftMode1     = new C.LeftMode()
            {
                Val = C.LayoutModeValues.Edge
            };
            C.TopMode topMode1 = new C.TopMode()
            {
                Val = C.LayoutModeValues.Edge
            };
            C.Left left1 = new C.Left()
            {
                Val = 0.14936699324798144D
            };
            C.Top top1 = new C.Top()
            {
                Val = 7.5867300613079197E-2D
            };

            manualLayout1.Append(leftMode1);
            manualLayout1.Append(topMode1);
            manualLayout1.Append(left1);
            manualLayout1.Append(top1);

            layout1.Append(manualLayout1);
            C.Overlay overlay1 = new C.Overlay()
            {
                Val = true
            };

            title1.Append(chartText1);
            title1.Append(layout1);
            title1.Append(overlay1);
            C.AutoTitleDeleted autoTitleDeleted1 = new C.AutoTitleDeleted()
            {
                Val = false
            };

            C.PlotArea plotArea1 = new C.PlotArea();

            C.Layout layout2 = new C.Layout();

            C.ManualLayout manualLayout2 = new C.ManualLayout();
            C.LayoutTarget layoutTarget1 = new C.LayoutTarget()
            {
                Val = C.LayoutTargetValues.Inner
            };
            C.LeftMode leftMode2 = new C.LeftMode()
            {
                Val = C.LayoutModeValues.Edge
            };
            C.TopMode topMode2 = new C.TopMode()
            {
                Val = C.LayoutModeValues.Edge
            };
            C.Left left2 = new C.Left()
            {
                Val = 0.10245464404093282D
            };
            C.Top top2 = new C.Top()
            {
                Val = 4.7416814491091287E-2D
            };
            C.Width width1 = new C.Width()
            {
                Val = 0.88919609910728359D
            };
            C.Height height1 = new C.Height()
            {
                Val = 0.86D
            };

            manualLayout2.Append(layoutTarget1);
            manualLayout2.Append(leftMode2);
            manualLayout2.Append(topMode2);
            manualLayout2.Append(left2);
            manualLayout2.Append(top2);
            manualLayout2.Append(width1);
            manualLayout2.Append(height1);

            layout2.Append(manualLayout2);

            C.AreaChart areaChart1 = new C.AreaChart();
            C.Grouping  grouping1  = new C.Grouping()
            {
                Val = C.GroupingValues.Standard
            };
            C.VaryColors varyColors1 = new C.VaryColors()
            {
                Val = true
            };

            C.AreaChartSeries areaChartSeries1 = new C.AreaChartSeries();
            C.Index           index1           = new C.Index()
            {
                Val = (UInt32Value)0U
            };
            C.Order order1 = new C.Order()
            {
                Val = (UInt32Value)0U
            };

            C.SeriesText   seriesText1   = new C.SeriesText();
            C.NumericValue numericValue1 = new C.NumericValue();
            numericValue1.Text = chart.LegendTitle;

            seriesText1.Append(numericValue1);

            C.CategoryAxisData categoryAxisData1 = new C.CategoryAxisData();

            C.NumberReference numberReference1 = new C.NumberReference();

            C.NumRefExtensionList numRefExtensionList1 = new C.NumRefExtensionList();

            C.NumRefExtension numRefExtension1 = new C.NumRefExtension()
            {
                Uri = "{02D57815-91ED-43cb-92C2-25804820EDAC}"
            };
            numRefExtension1.AddNamespaceDeclaration("c15", "http://schemas.microsoft.com/office/drawing/2012/chart");

            C15.FullReference        fullReference1        = new C15.FullReference();
            C15.SequenceOfReferences sequenceOfReferences1 = new C15.SequenceOfReferences();
            sequenceOfReferences1.Text = chart.AxisX;

            fullReference1.Append(sequenceOfReferences1);

            numRefExtension1.Append(fullReference1);

            numRefExtensionList1.Append(numRefExtension1);
            C.Formula formula1 = new C.Formula();
            formula1.Text = chart.AxisX;

            C.NumberingCache numberingCache1 = new C.NumberingCache();
            C.FormatCode     formatCode1     = new C.FormatCode();
            formatCode1.Text = "General";
            C.PointCount pointCount1 = new C.PointCount()
            {
                Val = (UInt32Value)(uint)chart.Labels.Count
            };

            numberingCache1.Append(formatCode1);
            numberingCache1.Append(pointCount1);

            for (uint i = 0; i < chart.Labels.Count; i++)
            {
                C.NumericPoint numericPoint1 = new C.NumericPoint()
                {
                    Index = (UInt32Value)i
                };
                C.NumericValue numericValue2 = new C.NumericValue();
                numericValue2.Text = chart.Labels[(int)i];

                numericPoint1.Append(numericValue2);

                numberingCache1.Append(numericPoint1);
            }

            numberReference1.Append(numRefExtensionList1);
            numberReference1.Append(formula1);
            numberReference1.Append(numberingCache1);

            categoryAxisData1.Append(numberReference1);

            C.Values values1 = new C.Values();

            C.NumberReference numberReference2 = new C.NumberReference();

            C.NumRefExtensionList numRefExtensionList2 = new C.NumRefExtensionList();

            C.NumRefExtension numRefExtension2 = new C.NumRefExtension()
            {
                Uri = "{02D57815-91ED-43cb-92C2-25804820EDAC}"
            };
            numRefExtension2.AddNamespaceDeclaration("c15", "http://schemas.microsoft.com/office/drawing/2012/chart");

            C15.FullReference        fullReference2        = new C15.FullReference();
            C15.SequenceOfReferences sequenceOfReferences2 = new C15.SequenceOfReferences();
            sequenceOfReferences2.Text = chart.AxisY;

            fullReference2.Append(sequenceOfReferences2);

            numRefExtension2.Append(fullReference2);

            numRefExtensionList2.Append(numRefExtension2);
            C.Formula formula2 = new C.Formula();
            formula2.Text = chart.AxisY;

            C.NumberingCache numberingCache2 = new C.NumberingCache();
            C.FormatCode     formatCode2     = new C.FormatCode();
            formatCode2.Text = "0.00%";
            C.PointCount pointCount2 = new C.PointCount()
            {
                Val = (UInt32Value)(uint)chart.Values.Count
            };

            numberingCache2.Append(formatCode2);
            numberingCache2.Append(pointCount2);

            for (uint i = 0; i < chart.Values.Count; i++)
            {
                C.NumericPoint numericPoint27 = new C.NumericPoint()
                {
                    Index = (UInt32Value)i
                };
                C.NumericValue numericValue28 = new C.NumericValue();
                numericValue28.Text = chart.Values[(int)i];

                numericPoint27.Append(numericValue28);

                numberingCache2.Append(numericPoint27);
            }

            numberReference2.Append(numRefExtensionList2);
            numberReference2.Append(formula2);
            numberReference2.Append(numberingCache2);

            values1.Append(numberReference2);

            C.AreaSerExtensionList areaSerExtensionList1 = new C.AreaSerExtensionList();

            C.AreaSerExtension areaSerExtension1 = new C.AreaSerExtension()
            {
                Uri = "{C3380CC4-5D6E-409C-BE32-E72D297353CC}"
            };
            areaSerExtension1.AddNamespaceDeclaration("c16", "http://schemas.microsoft.com/office/drawing/2014/chart");

            OpenXmlUnknownElement openXmlUnknownElement2 = OpenXmlUnknownElement.CreateOpenXmlUnknownElement("<c16:uniqueId val=\"{00000000-69FF-4CCD-9302-CEC5CC8046DF}\" xmlns:c16=\"http://schemas.microsoft.com/office/drawing/2014/chart\" />");

            areaSerExtension1.Append(openXmlUnknownElement2);

            areaSerExtensionList1.Append(areaSerExtension1);

            areaChartSeries1.Append(index1);
            areaChartSeries1.Append(order1);
            areaChartSeries1.Append(seriesText1);
            areaChartSeries1.Append(categoryAxisData1);
            areaChartSeries1.Append(values1);
            areaChartSeries1.Append(areaSerExtensionList1);

            C.DataLabels    dataLabels1    = new C.DataLabels();
            C.ShowLegendKey showLegendKey1 = new C.ShowLegendKey()
            {
                Val = false
            };
            C.ShowValue showValue1 = new C.ShowValue()
            {
                Val = false
            };
            C.ShowCategoryName showCategoryName1 = new C.ShowCategoryName()
            {
                Val = false
            };
            C.ShowSeriesName showSeriesName1 = new C.ShowSeriesName()
            {
                Val = false
            };
            C.ShowPercent showPercent1 = new C.ShowPercent()
            {
                Val = false
            };
            C.ShowBubbleSize showBubbleSize1 = new C.ShowBubbleSize()
            {
                Val = false
            };

            dataLabels1.Append(showLegendKey1);
            dataLabels1.Append(showValue1);
            dataLabels1.Append(showCategoryName1);
            dataLabels1.Append(showSeriesName1);
            dataLabels1.Append(showPercent1);
            dataLabels1.Append(showBubbleSize1);
            C.AxisId axisId1 = new C.AxisId()
            {
                Val = (UInt32Value)78173696U
            };
            C.AxisId axisId2 = new C.AxisId()
            {
                Val = (UInt32Value)78175232U
            };

            areaChart1.Append(grouping1);
            areaChart1.Append(varyColors1);
            areaChart1.Append(areaChartSeries1);
            areaChart1.Append(dataLabels1);
            areaChart1.Append(axisId1);
            areaChart1.Append(axisId2);

            C.CategoryAxis categoryAxis1 = new C.CategoryAxis();
            C.AxisId       axisId3       = new C.AxisId()
            {
                Val = (UInt32Value)78173696U
            };

            C.Scaling     scaling1     = new C.Scaling();
            C.Orientation orientation1 = new C.Orientation()
            {
                Val = C.OrientationValues.MinMax
            };

            scaling1.Append(orientation1);
            C.Delete delete1 = new C.Delete()
            {
                Val = true
            };
            C.AxisPosition axisPosition1 = new C.AxisPosition()
            {
                Val = C.AxisPositionValues.Bottom
            };
            C.NumberingFormat numberingFormat1 = new C.NumberingFormat()
            {
                FormatCode = "General", SourceLinked = true
            };
            C.MajorTickMark majorTickMark1 = new C.MajorTickMark()
            {
                Val = C.TickMarkValues.None
            };
            C.MinorTickMark minorTickMark1 = new C.MinorTickMark()
            {
                Val = C.TickMarkValues.Cross
            };
            C.TickLabelPosition tickLabelPosition1 = new C.TickLabelPosition()
            {
                Val = C.TickLabelPositionValues.NextTo
            };
            C.CrossingAxis crossingAxis1 = new C.CrossingAxis()
            {
                Val = (UInt32Value)78175232U
            };
            C.Crosses crosses1 = new C.Crosses()
            {
                Val = C.CrossesValues.AutoZero
            };
            C.AutoLabeled autoLabeled1 = new C.AutoLabeled()
            {
                Val = true
            };
            C.LabelAlignment labelAlignment1 = new C.LabelAlignment()
            {
                Val = C.LabelAlignmentValues.Center
            };
            C.LabelOffset labelOffset1 = new C.LabelOffset()
            {
                Val = (UInt16Value)100U
            };
            C.NoMultiLevelLabels noMultiLevelLabels1 = new C.NoMultiLevelLabels()
            {
                Val = true
            };

            categoryAxis1.Append(axisId3);
            categoryAxis1.Append(scaling1);
            categoryAxis1.Append(delete1);
            categoryAxis1.Append(axisPosition1);
            categoryAxis1.Append(numberingFormat1);
            categoryAxis1.Append(majorTickMark1);
            categoryAxis1.Append(minorTickMark1);
            categoryAxis1.Append(tickLabelPosition1);
            categoryAxis1.Append(crossingAxis1);
            categoryAxis1.Append(crosses1);
            categoryAxis1.Append(autoLabeled1);
            categoryAxis1.Append(labelAlignment1);
            categoryAxis1.Append(labelOffset1);
            categoryAxis1.Append(noMultiLevelLabels1);

            C.ValueAxis valueAxis1 = new C.ValueAxis();
            C.AxisId    axisId4    = new C.AxisId()
            {
                Val = (UInt32Value)78175232U
            };

            C.Scaling     scaling2     = new C.Scaling();
            C.Orientation orientation2 = new C.Orientation()
            {
                Val = C.OrientationValues.MinMax
            };

            scaling2.Append(orientation2);
            C.Delete delete2 = new C.Delete()
            {
                Val = true
            };
            C.AxisPosition axisPosition2 = new C.AxisPosition()
            {
                Val = C.AxisPositionValues.Left
            };
            C.MajorGridlines  majorGridlines1  = new C.MajorGridlines();
            C.NumberingFormat numberingFormat2 = new C.NumberingFormat()
            {
                FormatCode = "General", SourceLinked = true
            };
            C.MajorTickMark majorTickMark2 = new C.MajorTickMark()
            {
                Val = C.TickMarkValues.None
            };
            C.MinorTickMark minorTickMark2 = new C.MinorTickMark()
            {
                Val = C.TickMarkValues.Cross
            };
            C.TickLabelPosition tickLabelPosition2 = new C.TickLabelPosition()
            {
                Val = C.TickLabelPositionValues.NextTo
            };
            C.CrossingAxis crossingAxis2 = new C.CrossingAxis()
            {
                Val = (UInt32Value)78173696U
            };
            C.Crosses crosses2 = new C.Crosses()
            {
                Val = C.CrossesValues.AutoZero
            };
            C.CrossBetween crossBetween1 = new C.CrossBetween()
            {
                Val = C.CrossBetweenValues.MidpointCategory
            };

            valueAxis1.Append(axisId4);
            valueAxis1.Append(scaling2);
            valueAxis1.Append(delete2);
            valueAxis1.Append(axisPosition2);
            valueAxis1.Append(majorGridlines1);
            valueAxis1.Append(numberingFormat2);
            valueAxis1.Append(majorTickMark2);
            valueAxis1.Append(minorTickMark2);
            valueAxis1.Append(tickLabelPosition2);
            valueAxis1.Append(crossingAxis2);
            valueAxis1.Append(crosses2);
            valueAxis1.Append(crossBetween1);

            C.DataTable            dataTable1            = new C.DataTable();
            C.ShowHorizontalBorder showHorizontalBorder1 = new C.ShowHorizontalBorder()
            {
                Val = true
            };
            C.ShowVerticalBorder showVerticalBorder1 = new C.ShowVerticalBorder()
            {
                Val = true
            };
            C.ShowOutlineBorder showOutlineBorder1 = new C.ShowOutlineBorder()
            {
                Val = true
            };
            C.ShowKeys showKeys1 = new C.ShowKeys()
            {
                Val = true
            };

            dataTable1.Append(showHorizontalBorder1);
            dataTable1.Append(showVerticalBorder1);
            dataTable1.Append(showOutlineBorder1);
            dataTable1.Append(showKeys1);

            C.ShapeProperties shapeProperties1 = new C.ShapeProperties();

            A.Outline outline1 = new A.Outline();
            A.NoFill  noFill1  = new A.NoFill();

            outline1.Append(noFill1);

            shapeProperties1.Append(outline1);

            plotArea1.Append(layout2);
            plotArea1.Append(areaChart1);
            plotArea1.Append(categoryAxis1);
            plotArea1.Append(valueAxis1);
            plotArea1.Append(dataTable1);
            plotArea1.Append(shapeProperties1);
            C.PlotVisibleOnly plotVisibleOnly1 = new C.PlotVisibleOnly()
            {
                Val = true
            };
            C.DisplayBlanksAs displayBlanksAs1 = new C.DisplayBlanksAs()
            {
                Val = C.DisplayBlanksAsValues.Zero
            };
            C.ShowDataLabelsOverMaximum showDataLabelsOverMaximum1 = new C.ShowDataLabelsOverMaximum()
            {
                Val = true
            };

            chart1.Append(title1);
            chart1.Append(autoTitleDeleted1);
            chart1.Append(plotArea1);
            chart1.Append(plotVisibleOnly1);
            chart1.Append(displayBlanksAs1);
            chart1.Append(showDataLabelsOverMaximum1);

            C.ShapeProperties shapeProperties2 = new C.ShapeProperties();

            A.Outline outline2 = new A.Outline();
            A.NoFill  noFill2  = new A.NoFill();

            outline2.Append(noFill2);

            shapeProperties2.Append(outline2);

            C.TextProperties textProperties1 = new C.TextProperties();
            A.BodyProperties bodyProperties2 = new A.BodyProperties();
            A.ListStyle      listStyle2      = new A.ListStyle();

            A.Paragraph paragraph2 = new A.Paragraph();

            A.ParagraphProperties  paragraphProperties2  = new A.ParagraphProperties();
            A.DefaultRunProperties defaultRunProperties2 = new A.DefaultRunProperties()
            {
                FontSize = 700
            };

            paragraphProperties2.Append(defaultRunProperties2);
            A.EndParagraphRunProperties endParagraphRunProperties2 = new A.EndParagraphRunProperties()
            {
                Language = "en-US"
            };

            paragraph2.Append(paragraphProperties2);
            paragraph2.Append(endParagraphRunProperties2);

            textProperties1.Append(bodyProperties2);
            textProperties1.Append(listStyle2);
            textProperties1.Append(paragraph2);

            C.PrintSettings printSettings1 = new C.PrintSettings();
            C.HeaderFooter  headerFooter1  = new C.HeaderFooter();
            C.PageMargins   pageMargins1   = new C.PageMargins()
            {
                Left = 0.70000000000000018D, Right = 0.70000000000000018D, Top = 0.75000000000000022D, Bottom = 0.75000000000000022D, Header = 0.3000000000000001D, Footer = 0.3000000000000001D
            };
            C.PageSetup pageSetup1 = new C.PageSetup()
            {
                Orientation = C.PageSetupOrientationValues.Landscape
            };

            printSettings1.Append(headerFooter1);
            printSettings1.Append(pageMargins1);
            printSettings1.Append(pageSetup1);

            chartSpace1.Append(date19041);
            chartSpace1.Append(editingLanguage1);
            chartSpace1.Append(roundedCorners1);
            chartSpace1.Append(alternateContent1);
            chartSpace1.Append(chart1);
            chartSpace1.Append(shapeProperties2);
            chartSpace1.Append(textProperties1);
            chartSpace1.Append(printSettings1);

            chartPart1.ChartSpace = chartSpace1;
        }
예제 #26
0
        /// <summary>
        /// Validate ACB syntax - AlternateContent, Choice, Fallback and their attributes.
        /// </summary>
        /// <param name="validationContext"></param>
        internal static void Validate(ValidationContext validationContext)
        {
            AlternateContent acElement = (AlternateContent)validationContext.Element;

            // Validate MC attribute on AlternateContent
            ValidateMcAttributesOnAcb(validationContext, acElement);

            int status = 0;
            ValidationErrorInfo errorInfo;

            if (acElement.ChildElements.Count == 0)
            {
                // Rule: An AlternateContent element shall contain one or more Choice child elements
                errorInfo = validationContext.ComposeMcValidationError(acElement, "Sch_IncompleteContentExpectingComplex", ValidationResources.MC_ShallContainChoice);
                validationContext.AddError(errorInfo);
            }

            OpenXmlElement child;

            child = acElement.GetFirstNonMiscElementChild();

            while (child != null)
            {
                if (child is AlternateContent)
                {
                    // Rule: An AlternateContent element shall not be the child of an AlternateContent element.
                    errorInfo = validationContext.ComposeMcValidationError(acElement, "Sch_InvalidElementContentExpectingComplex", child.XmlQualifiedName.ToString(), ValidationResources.MC_ShallNotContainAlternateContent);
                    validationContext.AddError(errorInfo);
                }
                else
                {
                    switch (status)
                    {
                    case 0:
                        // expect a Choice
                        if (child is AlternateContentChoice)
                        {
                            // validate the MC attributes on Choice
                            ValidateMcAttributesOnAcb(validationContext, child);
                            status = 1;
                        }
                        else
                        {
                            // Rule: An AlternateContent element shall contain one or more Choice child elements
                            errorInfo = validationContext.ComposeMcValidationError(acElement, "Sch_IncompleteContentExpectingComplex", ValidationResources.MC_ShallContainChoice);
                            validationContext.AddError(errorInfo);

                            if (child is AlternateContentFallback)
                            {
                                // validate the MC attributes on Fallback
                                ValidateMcAttributesOnAcb(validationContext, child);
                            }
                        }
                        break;

                    case 1:
                        // Already one Choice, expect Choice or Fallback
                        if (child is AlternateContentChoice)
                        {
                            // validate the MC attributes on Choice
                            ValidateMcAttributesOnAcb(validationContext, child);
                            status = 1;
                        }
                        else if (child is AlternateContentFallback)
                        {
                            // validate the MC attributes on Fallback
                            ValidateMcAttributesOnAcb(validationContext, child);
                            status = 2;
                        }
                        else
                        {
                            errorInfo = validationContext.ComposeMcValidationError(acElement, "Sch_InvalidElementContentExpectingComplex", child.XmlQualifiedName.ToString(), ValidationResources.MC_ShallContainChoice);
                            validationContext.AddError(errorInfo);
                        }
                        break;

                    case 2:
                        // Already one Fallback. Can not have more than one Fallback
                        errorInfo = validationContext.ComposeMcValidationError(acElement, "Sch_InvalidElementContentExpectingComplex", child.XmlQualifiedName.ToString(), ValidationResources.MC_ShallContainChoice);
                        validationContext.AddError(errorInfo);
                        break;
                    }
                }
                child = child.GetNextNonMiscElementSibling();
            }
            return;
        }
예제 #27
0
        public void GetChildMcTest()
        {
            MCContext           mcContext = new MCContext();
            ParagraphProperties pPr;
            Run       run1, run2;
            Paragraph p = new Paragraph(
                pPr = new ParagraphProperties()
            {
                WordWrap = new WordWrap()
                {
                    Val = true
                }
            },
                new OpenXmlMiscNode(System.Xml.XmlNodeType.Comment, "<!-- comments -->"),
                run1 = new Run(new Text("Text 1.")),
                run2 = new Run(new Text("Text 2.")));

            var target = p.GetFirstChildMc(mcContext, FileFormatVersions.Office2007);

            Assert.Same(pPr, target);
            target = p.GetNextChildMc(target, mcContext, FileFormatVersions.Office2007);
            Assert.Same(run1, target);
            target = p.GetNextChildMc(target, mcContext, FileFormatVersions.Office2007);
            Assert.Same(run2, target);

            OpenXmlUnknownElement ignorableElement = new OpenXmlUnknownElement("w14test", "span", "http://w14.com");

            p.AddNamespaceDeclaration("w14test", "http://w14.com");

            ignorableElement.MCAttributes = new MarkupCompatibilityAttributes()
            {
                Ignorable = "w14test"
            };
            p.InsertAfter(ignorableElement, pPr);

            mcContext = new MCContext();
            target    = p.GetFirstChildMc(mcContext, FileFormatVersions.Office2007);
            Assert.Same(pPr, target);
            target = p.GetNextChildMc(target, mcContext, FileFormatVersions.Office2007);
            Assert.Same(run1, target);
            target = p.GetNextChildMc(target, mcContext, FileFormatVersions.Office2007);
            Assert.Same(run2, target);

            Run runInAcb         = new Run(new Text("Text in ACB."));
            AlternateContent acb = new AlternateContent(
                new AlternateContentChoice()
            {
                Requires = "w14test"
            },
                new AlternateContentFallback(runInAcb));

            p.InsertAfter(acb, pPr);

            mcContext = new MCContext();
            target    = p.GetFirstChildMc(mcContext, FileFormatVersions.Office2007);
            Assert.Same(pPr, target);
            target = p.GetNextChildMc(target, mcContext, FileFormatVersions.Office2007);
            Assert.Same(runInAcb, target);
            target = p.GetNextChildMc(target, mcContext, FileFormatVersions.Office2007);
            Assert.Same(run1, target);
            target = p.GetNextChildMc(target, mcContext, FileFormatVersions.Office2007);
            Assert.Same(run2, target);
        }
예제 #28
0
        public static void InsertAnimatedModel3D(string pptxPath, string pngPath, string glbPath)
        {
            if (pptxPath == null)
            {
                throw new ArgumentNullException("pptxPath");
            }

            if (pngPath == null)
            {
                throw new ArgumentNullException("pngPath");
            }

            if (glbPath == null)
            {
                throw new ArgumentNullException("glbPath");
            }

            // mc:AternateContent & p:timing
            // Open the presentation document
            using PresentationDocument presentationDocument = PresentationDocument.Open(pptxPath, true);

            // Get the relationship ID of the first slide.
            PresentationPart presentationPart = presentationDocument.PresentationPart;

            // Verify that the presentation part and presentation exist.
            if (presentationPart != null && presentationPart.Presentation != null)
            {
                OpenXmlElementList slideIds = presentationPart.Presentation.SlideIdList.ChildElements;

                if (slideIds.Count > 0)
                {
                    string    relId      = (slideIds[0] as SlideId).RelationshipId;
                    SlidePart slidePart  = (SlidePart)presentationPart.GetPartById(relId);
                    int       partsCount = slidePart.Parts.Count();

                    // Add the .png and .glb files for the 3D image
                    using FileStream glbFileStream = new FileStream(glbPath, FileMode.Open, FileAccess.Read);
                    glbFileStream.Seek(0, SeekOrigin.Begin);
                    string glbId = $"rId{++partsCount}";
                    Model3DReferenceRelationshipPart glbImagePart = slidePart.AddNewPart <Model3DReferenceRelationshipPart>(glbId);
                    glbImagePart.FeedData(glbFileStream);

                    using FileStream pngFileStream = new FileStream(pngPath, FileMode.Open, FileAccess.Read);
                    pngFileStream.Seek(0, SeekOrigin.Begin);
                    string    pngId        = $"rId{++partsCount}";
                    ImagePart pngImagePart = slidePart.AddImagePart(ImagePartType.Png, pngId);
                    pngImagePart.FeedData(pngFileStream);

                    CommonSlideData commonSlideDataPart = slidePart.RootElement.Descendants <CommonSlideData>().FirstOrDefault();

                    // Add an AlternateContent element to the shape tree
                    AlternateContent alternateContent = commonSlideDataPart.ShapeTree.AppendChild(new AlternateContent());

                    // Add mc:Choice element to AlternateContent
                    AlternateContentChoice alternateContentChoice = alternateContent.AppendChild(new AlternateContentChoice());
                    alternateContentChoice.Requires = "am3d";
                    alternateContentChoice.AddNamespaceDeclaration("am3d", "http://schemas.microsoft.com/office/drawing/2017/model3d");

                    // Add mc:Fallback element to AlternateContent
                    AlternateContentFallback alternateContentFallback = alternateContent.AppendChild(new AlternateContentFallback());

                    // Create a creationId with the correct namespace
                    string guidId = "{" + System.Guid.NewGuid().ToString().ToUpper() + "}";
                    DocumentFormat.OpenXml.Office2016.Drawing.CreationId creationId = new DocumentFormat.OpenXml.Office2016.Drawing.CreationId();
                    creationId.AddNamespaceDeclaration("a16", "http://schemas.microsoft.com/office/drawing/2014/main");
                    creationId.Id = guidId;

                    // Clone the creationId
                    DocumentFormat.OpenXml.Office2016.Drawing.CreationId creationId2 = (DocumentFormat.OpenXml.Office2016.Drawing.CreationId)creationId.Clone();
                    string      creationIdPartenId = guidId;
                    UInt32Value threeDModelId      = new UInt32Value(2U);

                    // Create modId in with the correct namespace xmlns:p14="http://schemas.microsoft.com/office/powerpoint/2010/main" val="3636546711"
                    DocumentFormat.OpenXml.Office2010.PowerPoint.ModificationId modificationId = new DocumentFormat.OpenXml.Office2010.PowerPoint.ModificationId();
                    modificationId.AddNamespaceDeclaration("p14", "http://schemas.microsoft.com/office/powerpoint/2010/main");
                    modificationId.Val = 3636546711;

                    // Create a aExtension in with the correct attributes
                    DocumentFormat.OpenXml.Drawing.Extension aExtension = new DocumentFormat.OpenXml.Drawing.Extension();

                    aExtension.SetAttributes(
                        new OpenXmlAttribute[]
                    {
                        new OpenXmlAttribute("cx", string.Empty, "4158691"),
                        new OpenXmlAttribute("cy", string.Empty, "3460830"),
                    });

                    // Create a clone of a:ext for am3d:spPr
                    DocumentFormat.OpenXml.Drawing.Extension aExtension2 = (DocumentFormat.OpenXml.Drawing.Extension)aExtension.Clone();

                    // Create a a3damin:posterFrame and add the namespace
                    DocumentFormat.OpenXml.Office2019.Drawing.Animation.Model3D.PosterFrame model3dPosterFrame = new DocumentFormat.OpenXml.Office2019.Drawing.Animation.Model3D.PosterFrame()
                    {
                        AnimId = 0
                    };
                    model3dPosterFrame.AddNamespaceDeclaration("a3danim", "http://schemas.microsoft.com/office/drawing/2018/animation/model3d");

                    // Create a clone of a:ext for p:spPr
                    DocumentFormat.OpenXml.Drawing.Extension aExtension3 = (DocumentFormat.OpenXml.Drawing.Extension)aExtension.Clone();

                    // Create a:off
                    DocumentFormat.OpenXml.Drawing.Offset offset = new DocumentFormat.OpenXml.Drawing.Offset()
                    {
                        X = 4016654, Y = 1698584
                    };
                    DocumentFormat.OpenXml.Drawing.Offset offset2 = (DocumentFormat.OpenXml.Drawing.Offset)offset.Clone();

                    // Create a3danim:embedAnim and assign its namespace
                    DocumentFormat.OpenXml.Office2019.Drawing.Animation.Model3D.EmbeddedAnimation embeddedAnimation = new DocumentFormat.OpenXml.Office2019.Drawing.Animation.Model3D.EmbeddedAnimation()
                    {
                        AnimId = 0
                    };
                    embeddedAnimation.AddNamespaceDeclaration("a3danim", "http://schemas.microsoft.com/office/drawing/2018/animation/model3d");
                    embeddedAnimation.AppendChild(new DocumentFormat.OpenXml.Office2019.Drawing.Animation.Model3D.AnimationProperties()
                    {
                        Length = "1899", Count = "indefinite"
                    });

                    // Create the mc:AlternateContent element
                    alternateContentChoice.AppendChild(
                        new GraphicFrame(
                            new NonVisualGraphicFrameProperties(
                                new NonVisualDrawingProperties(
                                    new DocumentFormat.OpenXml.Drawing.NonVisualDrawingPropertiesExtensionList(
                                        new DocumentFormat.OpenXml.Drawing.NonVisualDrawingPropertiesExtension(
                                            creationId)
                    {
                        Uri = "{FF2B5EF4-FFF2-40B4-BE49-F238E27FC236}"
                    }))
                    {
                        Id = threeDModelId, Name = "3D Model 1", Description = "Flying bee"
                    },
                                new NonVisualGraphicFrameDrawingProperties(),
                                new ApplicationNonVisualDrawingProperties(
                                    new ApplicationNonVisualDrawingPropertiesExtensionList(
                                        new ApplicationNonVisualDrawingPropertiesExtension(
                                            modificationId)
                    {
                        Uri = "{D42A27DB-BD31-4B8C-83A1-F6EECF244321}"
                    }))),
                            new Transform(
                                offset,
                                aExtension),
                            new DocumentFormat.OpenXml.Drawing.Graphic(
                                new DocumentFormat.OpenXml.Drawing.GraphicData(
                                    new DocumentFormat.OpenXml.Office2019.Drawing.Model3D.Model3D(
                                        new DocumentFormat.OpenXml.Office2019.Drawing.Model3D.ShapeProperties(
                                            new DocumentFormat.OpenXml.Drawing.Transform2D(
                                                new DocumentFormat.OpenXml.Drawing.Offset()
                    {
                        X = 0, Y = 0
                    },
                                                aExtension2),
                                            new DocumentFormat.OpenXml.Drawing.PresetGeometry(
                                                new DocumentFormat.OpenXml.Drawing.AdjustValueList())
                    {
                        Preset = DocumentFormat.OpenXml.Drawing.ShapeTypeValues.Rectangle
                    }),
                                        new DocumentFormat.OpenXml.Office2019.Drawing.Model3D.Model3DCamera(
                                            new DocumentFormat.OpenXml.Office2019.Drawing.Model3D.PosPoint3D()
                    {
                        X = 0, Y = 0, Z = 67740115
                    },
                                            new DocumentFormat.OpenXml.Office2019.Drawing.Model3D.UpVector3D()
                    {
                        Dx = 0, Dy = 36000000, Dz = 0
                    },
                                            new DocumentFormat.OpenXml.Office2019.Drawing.Model3D.LookAtPoint3D()
                    {
                        X = 0, Y = 0, Z = 0
                    },
                                            new DocumentFormat.OpenXml.Office2019.Drawing.Model3D.PerspectiveProjection()
                    {
                        Fov = 2700000
                    }),
                                        new DocumentFormat.OpenXml.Office2019.Drawing.Model3D.Model3DTransform(
                                            new DocumentFormat.OpenXml.Office2019.Drawing.Model3D.MeterPerModelUnitPositiveRatio()
                    {
                        N = 30569, D = 1000000
                    },
                                            new DocumentFormat.OpenXml.Office2019.Drawing.Model3D.PreTransVector3D()
                    {
                        Dx = -98394, Dy = -14223043, Dz = -1124542
                    },
                                            new DocumentFormat.OpenXml.Office2019.Drawing.Model3D.Scale3D(
                                                new DocumentFormat.OpenXml.Office2019.Drawing.Model3D.SxRatio()
                    {
                        Numerator = 1000000, Denominator = 1000000
                    },
                                                new DocumentFormat.OpenXml.Office2019.Drawing.Model3D.SyRatio()
                    {
                        Numerator = 1000000, Denominator = 1000000
                    },
                                                new DocumentFormat.OpenXml.Office2019.Drawing.Model3D.SzRatio()
                    {
                        Numerator = 1000000, Denominator = 1000000
                    }),
                                            new DocumentFormat.OpenXml.Office2019.Drawing.Model3D.Rotate3D(),
                                            new DocumentFormat.OpenXml.Office2019.Drawing.Model3D.PostTransVector3D()
                    {
                        Dx = 0, Dy = 0, Dz = 0
                    }),
                                        new DocumentFormat.OpenXml.Office2019.Drawing.Model3D.Model3DRaster(
                                            new DocumentFormat.OpenXml.Office2019.Drawing.Model3D.Blip()
                    {
                        Embed = pngId
                    })
                    {
                        RName = "Office3DRenderer", RVer = "16.0.8326"
                    },
                                        new DocumentFormat.OpenXml.Office2019.Drawing.Model3D.Model3DExtensionList(
                                            new DocumentFormat.OpenXml.Drawing.Extension(
                                                embeddedAnimation)
                    {
                        Uri = "{9A65AA19-BECB-4387-8358-8AD5134E1D82}"
                    },
                                            new DocumentFormat.OpenXml.Drawing.Extension(
                                                model3dPosterFrame)
                    {
                        Uri = "{E9DE012E-A134-456F-84FE-255F9AAD75C6}"
                    }),
                                        new DocumentFormat.OpenXml.Office2019.Drawing.Model3D.ObjectViewport()
                    {
                        ViewportSz = 5418666
                    },
                                        new DocumentFormat.OpenXml.Office2019.Drawing.Model3D.AmbientLight(
                                            new DocumentFormat.OpenXml.Office2019.Drawing.Model3D.ColorType(
                                                new DocumentFormat.OpenXml.Drawing.RgbColorModelPercentage()
                    {
                        RedPortion = 50000, GreenPortion = 50000, BluePortion = 50000
                    }),
                                            new DocumentFormat.OpenXml.Office2019.Drawing.Model3D.IlluminancePositiveRatio()
                    {
                        N = 500000, D = 1000000
                    }),
                                        new DocumentFormat.OpenXml.Office2019.Drawing.Model3D.PointLight(
                                            new DocumentFormat.OpenXml.Office2019.Drawing.Model3D.ColorType(
                                                new DocumentFormat.OpenXml.Drawing.RgbColorModelPercentage()
                    {
                        RedPortion = 100000, GreenPortion = 75000, BluePortion = 50000
                    }),
                                            new DocumentFormat.OpenXml.Office2019.Drawing.Model3D.IntensityPositiveRatio()
                    {
                        N = 9765625, D = 1000000
                    },
                                            new DocumentFormat.OpenXml.Office2019.Drawing.Model3D.PosPoint3D()
                    {
                        X = 21959998, Y = 70920001, Z = 16344003
                    })
                    {
                        Rad = 0
                    },
                                        new DocumentFormat.OpenXml.Office2019.Drawing.Model3D.PointLight(
                                            new DocumentFormat.OpenXml.Office2019.Drawing.Model3D.ColorType(
                                                new DocumentFormat.OpenXml.Drawing.RgbColorModelPercentage()
                    {
                        RedPortion = 40000, GreenPortion = 60000, BluePortion = 95000
                    }),
                                            new DocumentFormat.OpenXml.Office2019.Drawing.Model3D.IntensityPositiveRatio()
                    {
                        N = 12250000, D = 1000000
                    },
                                            new DocumentFormat.OpenXml.Office2019.Drawing.Model3D.PosPoint3D()
                    {
                        X = -37964106, Y = 51130435, Z = 57631972
                    })
                    {
                        Rad = 0
                    },
                                        new DocumentFormat.OpenXml.Office2019.Drawing.Model3D.PointLight(
                                            new DocumentFormat.OpenXml.Office2019.Drawing.Model3D.ColorType(
                                                new DocumentFormat.OpenXml.Drawing.RgbColorModelPercentage()
                    {
                        RedPortion = 86837, GreenPortion = 72700, BluePortion = 100000
                    }),
                                            new DocumentFormat.OpenXml.Office2019.Drawing.Model3D.IntensityPositiveRatio()
                    {
                        N = 3125000, D = 1000000
                    },
                                            new DocumentFormat.OpenXml.Office2019.Drawing.Model3D.PosPoint3D()
                    {
                        X = -37739122, Y = 58056624, Z = -34769649
                    })
                    {
                        Rad = 0
                    })
                    {
                        Embed = glbId
                    })
                    {
                        Uri = "http://schemas.microsoft.com/office/drawing/2017/model3d"
                    })));

                    // Add children to mc:Fallback
                    alternateContentFallback.AppendChild(
                        new DocumentFormat.OpenXml.Presentation.Picture(
                            new NonVisualPictureProperties(
                                new NonVisualDrawingProperties(
                                    new DocumentFormat.OpenXml.Drawing.NonVisualDrawingPropertiesExtensionList(
                                        new DocumentFormat.OpenXml.Drawing.NonVisualDrawingPropertiesExtension(
                                            creationId2)
                    {
                        Uri = "{FF2B5EF4-FFF2-40B4-BE49-F238E27FC236}"
                    }))
                    {
                        Id = threeDModelId, Name = "3D Model 1", Description = "Flying bee"
                    },
                                new DocumentFormat.OpenXml.Presentation.NonVisualPictureDrawingProperties(
                                    new DocumentFormat.OpenXml.Drawing.PictureLocks()
                    {
                        NoGrouping = true, NoRotation = true, NoChangeAspect = true, NoMove = true, NoResize = true, NoEditPoints = true, NoAdjustHandles = true, NoChangeArrowheads = true, NoChangeShapeType = true, NoCrop = true
                    }),
                                new DocumentFormat.OpenXml.Presentation.ApplicationNonVisualDrawingProperties()),
                            new DocumentFormat.OpenXml.Presentation.BlipFill(
                                new DocumentFormat.OpenXml.Drawing.Blip()
                    {
                        Embed = pngId
                    },
                                new DocumentFormat.OpenXml.Drawing.Stretch(
                                    new DocumentFormat.OpenXml.Drawing.FillRectangle())),
                            new DocumentFormat.OpenXml.Presentation.ShapeProperties(
                                new DocumentFormat.OpenXml.Drawing.Transform2D(
                                    offset2,
                                    aExtension3),
                                new DocumentFormat.OpenXml.Drawing.PresetGeometry(
                                    new DocumentFormat.OpenXml.Drawing.AdjustValueList())
                    {
                        Preset = DocumentFormat.OpenXml.Drawing.ShapeTypeValues.Rectangle
                    })));

                    // DocumentFormat.OpenXml.Presentation.AttributeName attributeName = new DocumentFormat.OpenXml.Presentation.AttributeName();
                    // attributeName.InnerXml = "embedded1";

                    // Append the p:timing to the p:sld
                    slidePart.RootElement.AppendChild(
                        new DocumentFormat.OpenXml.Presentation.Timing(
                            new DocumentFormat.OpenXml.Presentation.TimeNodeList(
                                new DocumentFormat.OpenXml.Presentation.ParallelTimeNode(
                                    new DocumentFormat.OpenXml.Presentation.CommonTimeNode(
                                        new DocumentFormat.OpenXml.Presentation.ChildTimeNodeList(
                                            new DocumentFormat.OpenXml.Presentation.SequenceTimeNode(
                                                new DocumentFormat.OpenXml.Presentation.CommonTimeNode(
                                                    new DocumentFormat.OpenXml.Presentation.ChildTimeNodeList(
                                                        new DocumentFormat.OpenXml.Presentation.ParallelTimeNode(
                                                            new DocumentFormat.OpenXml.Presentation.CommonTimeNode(
                                                                new DocumentFormat.OpenXml.Presentation.StartConditionList(
                                                                    new DocumentFormat.OpenXml.Presentation.Condition()
                    {
                        Delay = "indefinite"
                    },
                                                                    new DocumentFormat.OpenXml.Presentation.Condition(
                                                                        new DocumentFormat.OpenXml.Presentation.TimeNode()
                    {
                        Val = 2
                    })
                    {
                        Event = DocumentFormat.OpenXml.Presentation.TriggerEventValues.OnBegin, Delay = "0"
                    }),
                                                                new DocumentFormat.OpenXml.Presentation.ChildTimeNodeList(
                                                                    new DocumentFormat.OpenXml.Presentation.ParallelTimeNode(
                                                                        new DocumentFormat.OpenXml.Presentation.CommonTimeNode(
                                                                            new DocumentFormat.OpenXml.Presentation.StartConditionList(
                                                                                new DocumentFormat.OpenXml.Presentation.Condition()
                    {
                        Delay = "0"
                    }),
                                                                            new DocumentFormat.OpenXml.Presentation.ChildTimeNodeList(
                                                                                new DocumentFormat.OpenXml.Presentation.ParallelTimeNode(
                                                                                    new DocumentFormat.OpenXml.Presentation.CommonTimeNode(
                                                                                        new DocumentFormat.OpenXml.Presentation.StartConditionList(
                                                                                            new DocumentFormat.OpenXml.Presentation.Condition()
                    {
                        Delay = "0"
                    }),
                                                                                        new DocumentFormat.OpenXml.Presentation.ChildTimeNodeList(
                                                                                            new DocumentFormat.OpenXml.Presentation.Animate(
                                                                                                new DocumentFormat.OpenXml.Presentation.CommonBehavior(
                                                                                                    new DocumentFormat.OpenXml.Presentation.CommonTimeNode()
                    {
                        Id = 6, Duration = "1900", Fill = DocumentFormat.OpenXml.Presentation.TimeNodeFillValues.Hold
                    },
                                                                                                    new DocumentFormat.OpenXml.Presentation.TargetElement(
                                                                                                        new DocumentFormat.OpenXml.Presentation.ShapeTarget()
                    {
                        ShapeId = "2"
                    }),
                                                                                                    new DocumentFormat.OpenXml.Presentation.AttributeNameList(
                                                                                                        new DocumentFormat.OpenXml.Presentation.AttributeName("embedded1"))),
                                                                                                new DocumentFormat.OpenXml.Presentation.TimeAnimateValueList(
                                                                                                    new DocumentFormat.OpenXml.Presentation.TimeAnimateValue(
                                                                                                        new DocumentFormat.OpenXml.Presentation.VariantValue(
                                                                                                            new DocumentFormat.OpenXml.Presentation.FloatVariantValue()
                    {
                        Val = DocumentFormat.OpenXml.SingleValue.FromSingle(0)
                    }))
                    {
                        Time = "0"
                    },
                                                                                                    new DocumentFormat.OpenXml.Presentation.TimeAnimateValue(
                                                                                                        new DocumentFormat.OpenXml.Presentation.VariantValue(
                                                                                                            new DocumentFormat.OpenXml.Presentation.FloatVariantValue()
                    {
                        Val = DocumentFormat.OpenXml.SingleValue.FromSingle(1)
                    }))
                    {
                        Time = "100000"
                    }))
                    {
                        CalculationMode = DocumentFormat.OpenXml.Presentation.AnimateBehaviorCalculateModeValues.Linear, ValueType = DocumentFormat.OpenXml.Presentation.AnimateBehaviorValues.Number
                    }))
                    {
                        Id = 5, PresetId = 100, PresetClass = DocumentFormat.OpenXml.Presentation.TimeNodePresetClassValues.Emphasis, PresetSubtype = 1, RepeatCount = "indefinite", Fill = DocumentFormat.OpenXml.Presentation.TimeNodeFillValues.Hold, NodeType = DocumentFormat.OpenXml.Presentation.TimeNodeValues.WithEffect
                    })))
                    {
                        Id = 4, Fill = DocumentFormat.OpenXml.Presentation.TimeNodeFillValues.Hold
                    })))
                    {
                        Id = 3, Fill = DocumentFormat.OpenXml.Presentation.TimeNodeFillValues.Hold
                    })))
                    {
                        Id = 2, Duration = "indefinite", NodeType = DocumentFormat.OpenXml.Presentation.TimeNodeValues.MainSequence
                    },
                                                new DocumentFormat.OpenXml.Presentation.PreviousConditionList(
                                                    new DocumentFormat.OpenXml.Presentation.Condition(
                                                        new DocumentFormat.OpenXml.Presentation.TargetElement(
                                                            new DocumentFormat.OpenXml.Presentation.SlideTarget()))
                    {
                        Event = DocumentFormat.OpenXml.Presentation.TriggerEventValues.OnPrevious, Delay = "0"
                    }),
                                                new DocumentFormat.OpenXml.Presentation.NextConditionList(
                                                    new DocumentFormat.OpenXml.Presentation.Condition(
                                                        new DocumentFormat.OpenXml.Presentation.TargetElement(
                                                            new DocumentFormat.OpenXml.Presentation.SlideTarget()))
                    {
                        Event = DocumentFormat.OpenXml.Presentation.TriggerEventValues.OnNext, Delay = "0"
                    }))
                    {
                        Concurrent = true, NextAction = DocumentFormat.OpenXml.Presentation.NextActionValues.Seek
                    }))
                    {
                        Id = 1, Duration = "indefinite", Restart = DocumentFormat.OpenXml.Presentation.TimeNodeRestartValues.Never, NodeType = DocumentFormat.OpenXml.Presentation.TimeNodeValues.TmingRoot
                    }))));
                }
            }
        }
예제 #29
0
        private void diagramXmlParseBody_(XmlNode diagramElementNode, string xmlFilePath, TreeNode treeNode, int objectIndex)
        {
            string diagramElementName = diagramElementNode.Name;

            AlternateContent           altContent     = treeNode.Presentation.AlternateContentFactory.CreateAlternateContent();
            AlternateContentAddCommand cmd_AltContent =
                treeNode.Presentation.CommandFactory.CreateAlternateContentAddCommand(treeNode, altContent);

            treeNode.Presentation.UndoRedoManager.Execute(cmd_AltContent);



            Metadata diagramElementName_Metadata = treeNode.Presentation.MetadataFactory.CreateMetadata();

            diagramElementName_Metadata.NameContentAttribute              = new MetadataAttribute();
            diagramElementName_Metadata.NameContentAttribute.Name         = DiagramContentModelHelper.DiagramElementName;
            diagramElementName_Metadata.NameContentAttribute.NamespaceUri = null;
            diagramElementName_Metadata.NameContentAttribute.Value        = diagramElementName;
            AlternateContentMetadataAddCommand cmd_AltContent_diagramElementName_Metadata =
                treeNode.Presentation.CommandFactory.CreateAlternateContentMetadataAddCommand(
                    treeNode,
                    null,
                    altContent,
                    diagramElementName_Metadata,
                    null
                    );

            treeNode.Presentation.UndoRedoManager.Execute(cmd_AltContent_diagramElementName_Metadata);


            if (diagramElementNode.Attributes != null)
            {
                for (int i = 0; i < diagramElementNode.Attributes.Count; i++)
                {
                    XmlAttribute attribute = diagramElementNode.Attributes[i];


                    if (attribute.Name.StartsWith(XmlReaderWriterHelper.NS_PREFIX_XMLNS + ":"))
                    {
                        //
                    }
                    else if (attribute.Name == XmlReaderWriterHelper.NS_PREFIX_XMLNS)
                    {
                        //
                    }
                    else if (attribute.Name == DiagramContentModelHelper.TOBI_Audio)
                    {
                        string fullPath = null;
                        if (FileDataProvider.isHTTPFile(attribute.Value))
                        {
                            fullPath = FileDataProvider.EnsureLocalFilePathDownloadTempDirectory(attribute.Value);
                        }
                        else
                        {
                            fullPath = Path.Combine(Path.GetDirectoryName(xmlFilePath), attribute.Value);
                        }
                        if (fullPath != null && File.Exists(fullPath))
                        {
                            string extension = Path.GetExtension(fullPath);

                            bool isWav = extension.Equals(DataProviderFactory.AUDIO_WAV_EXTENSION, StringComparison.OrdinalIgnoreCase);

                            AudioLibPCMFormat wavFormat = null;
                            if (isWav)
                            {
                                Stream fileStream = File.Open(fullPath, FileMode.Open, FileAccess.Read, FileShare.Read);
                                try
                                {
                                    uint dataLength;
                                    wavFormat = AudioLibPCMFormat.RiffHeaderParse(fileStream, out dataLength);
                                }
                                finally
                                {
                                    fileStream.Close();
                                }
                            }
                            string originalFilePath = null;

                            DebugFix.Assert(treeNode.Presentation.MediaDataManager.EnforceSinglePCMFormat);

                            bool wavNeedsConversion = false;
                            if (wavFormat != null)
                            {
                                wavNeedsConversion = !wavFormat.IsCompatibleWith(treeNode.Presentation.MediaDataManager.DefaultPCMFormat.Data);
                            }
                            if (!isWav || wavNeedsConversion)
                            {
                                originalFilePath = fullPath;

                                var audioFormatConvertorSession =
                                    new AudioFormatConvertorSession(
                                        //AudioFormatConvertorSession.TEMP_AUDIO_DIRECTORY,
                                        treeNode.Presentation.DataProviderManager.DataFileDirectoryFullPath,
                                        treeNode.Presentation.MediaDataManager.DefaultPCMFormat,
                                        false,
                                        m_UrakawaSession.IsAcmCodecsDisabled);

                                //filePath = m_AudioFormatConvertorSession.ConvertAudioFileFormat(filePath);

                                bool cancelled = false;

                                var converter = new AudioClipConverter(audioFormatConvertorSession, fullPath);

                                bool error = ShellView.RunModalCancellableProgressTask(true,
                                                                                       "Converting audio...",
                                                                                       converter,
                                                                                       () =>
                                {
                                    m_Logger.Log(@"Audio conversion CANCELLED", Category.Debug, Priority.Medium);
                                    cancelled = true;
                                },
                                                                                       () =>
                                {
                                    m_Logger.Log(@"Audio conversion DONE", Category.Debug, Priority.Medium);
                                    cancelled = false;
                                });

                                if (cancelled)
                                {
                                    //DebugFix.Assert(!result);
                                    break;
                                }

                                fullPath = converter.ConvertedFilePath;
                                if (string.IsNullOrEmpty(fullPath))
                                {
                                    break;
                                }

                                m_Logger.Log(string.Format("Converted audio {0} to {1}", originalFilePath, fullPath),
                                             Category.Debug, Priority.Medium);

                                //Stream fileStream = File.Open(fullPath, FileMode.Open, FileAccess.Read, FileShare.Read);
                                //try
                                //{
                                //    uint dataLength;
                                //    wavFormat = AudioLibPCMFormat.RiffHeaderParse(fileStream, out dataLength);
                                //}
                                //finally
                                //{
                                //    fileStream.Close();
                                //}
                            }


                            ManagedAudioMedia manAudioMedia  = treeNode.Presentation.MediaFactory.CreateManagedAudioMedia();
                            AudioMediaData    audioMediaData = treeNode.Presentation.MediaDataFactory.CreateAudioMediaData(DataProviderFactory.AUDIO_WAV_EXTENSION);
                            manAudioMedia.AudioMediaData = audioMediaData;

                            FileDataProvider dataProv = (FileDataProvider)treeNode.Presentation.DataProviderFactory.Create(DataProviderFactory.AUDIO_WAV_MIME_TYPE);
                            dataProv.InitByCopyingExistingFile(fullPath);
                            audioMediaData.AppendPcmData(dataProv);

                            //                            Stream wavStream = null;
                            //                            try
                            //                            {
                            //                                wavStream = File.Open(fullPath, FileMode.Open, FileAccess.Read, FileShare.Read);

                            //                                uint dataLength;
                            //                                AudioLibPCMFormat pcmInfo = AudioLibPCMFormat.RiffHeaderParse(wavStream, out dataLength);

                            //                                if (!treeNode.Presentation.MediaDataManager.DefaultPCMFormat.Data.IsCompatibleWith(pcmInfo))
                            //                                {
                            //#if DEBUG
                            //                                    Debugger.Break();
                            //#endif //DEBUG
                            //                                    wavStream.Close();
                            //                                    wavStream = null;

                            //                                    var audioFormatConvertorSession =
                            //                                        new AudioFormatConvertorSession(
                            //                                        //AudioFormatConvertorSession.TEMP_AUDIO_DIRECTORY,
                            //                                        treeNode.Presentation.DataProviderManager.DataFileDirectoryFullPath,
                            //                                    treeNode.Presentation.MediaDataManager.DefaultPCMFormat, m_UrakawaSession.IsAcmCodecsDisabled);

                            //                                    string newfullWavPath = audioFormatConvertorSession.ConvertAudioFileFormat(fullPath);

                            //                                    FileDataProvider dataProv = (FileDataProvider)treeNode.Presentation.DataProviderFactory.Create(DataProviderFactory.AUDIO_WAV_MIME_TYPE);
                            //                                    dataProv.InitByMovingExistingFile(newfullWavPath);
                            //                                    audioMediaData.AppendPcmData(dataProv);
                            //                                }
                            //                                else // use original wav file by copying it to data directory
                            //                                {
                            //                                    FileDataProvider dataProv = (FileDataProvider)treeNode.Presentation.DataProviderFactory.Create(DataProviderFactory.AUDIO_WAV_MIME_TYPE);
                            //                                    dataProv.InitByCopyingExistingFile(fullPath);
                            //                                    audioMediaData.AppendPcmData(dataProv);
                            //                                }
                            //                            }
                            //                            finally
                            //                            {
                            //                                if (wavStream != null) wavStream.Close();
                            //                            }



                            AlternateContentSetManagedMediaCommand cmd_AltContent_diagramElement_Audio =
                                treeNode.Presentation.CommandFactory.CreateAlternateContentSetManagedMediaCommand(treeNode, altContent, manAudioMedia);
                            treeNode.Presentation.UndoRedoManager.Execute(cmd_AltContent_diagramElement_Audio);

                            //SetDescriptionAudio(altContent, audio, treeNode);
                        }
                    }
                    else
                    {
                        Metadata diagramElementAttribute_Metadata = treeNode.Presentation.MetadataFactory.CreateMetadata();
                        diagramElementAttribute_Metadata.NameContentAttribute              = new MetadataAttribute();
                        diagramElementAttribute_Metadata.NameContentAttribute.Name         = attribute.Name;
                        diagramElementAttribute_Metadata.NameContentAttribute.NamespaceUri = attribute.NamespaceURI;
                        diagramElementAttribute_Metadata.NameContentAttribute.Value        = attribute.Value;
                        AlternateContentMetadataAddCommand cmd_AltContent_diagramElementAttribute_Metadata =
                            treeNode.Presentation.CommandFactory.CreateAlternateContentMetadataAddCommand(
                                treeNode,
                                null,
                                altContent,
                                diagramElementAttribute_Metadata,
                                null
                                );
                        treeNode.Presentation.UndoRedoManager.Execute(
                            cmd_AltContent_diagramElementAttribute_Metadata);
                    }
                }
            }

            int nObjects = -1;

            XmlNode textNode = diagramElementNode;

            if (diagramElementName == DiagramContentModelHelper.D_SimplifiedImage ||
                diagramElementName == DiagramContentModelHelper.D_Tactile)
            {
                string  localTourName = DiagramContentModelHelper.StripNSPrefix(DiagramContentModelHelper.D_Tour);
                XmlNode tour          =
                    XmlDocumentHelper.GetFirstChildElementOrSelfWithName(diagramElementNode, false,
                                                                         localTourName,
                                                                         DiagramContentModelHelper.NS_URL_DIAGRAM);
                textNode = tour;

                IEnumerable <XmlNode> objects = XmlDocumentHelper.GetChildrenElementsOrSelfWithName(diagramElementNode, false,
                                                                                                    DiagramContentModelHelper.
                                                                                                    Object,
                                                                                                    DiagramContentModelHelper.
                                                                                                    NS_URL_ZAI, false);
                nObjects = 0;
                foreach (XmlNode obj in objects)
                {
                    nObjects++;
                }

                int i = -1;
                foreach (XmlNode obj in objects)
                {
                    i++;
                    if (i != objectIndex)
                    {
                        continue;
                    }

                    if (obj.Attributes == null || obj.Attributes.Count <= 0)
                    {
                        break;
                    }

                    for (int j = 0; j < obj.Attributes.Count; j++)
                    {
                        XmlAttribute attribute = obj.Attributes[j];


                        if (attribute.Name.StartsWith(XmlReaderWriterHelper.NS_PREFIX_XMLNS + ":"))
                        {
                            //
                        }
                        else if (attribute.Name == XmlReaderWriterHelper.NS_PREFIX_XMLNS)
                        {
                            //
                        }
                        else if (attribute.Name == DiagramContentModelHelper.Src)
                        {
                            //
                        }
                        else if (attribute.Name == DiagramContentModelHelper.SrcType)
                        {
                            //
                        }
                        else
                        {
                            Metadata diagramElementAttribute_Metadata = treeNode.Presentation.MetadataFactory.CreateMetadata();
                            diagramElementAttribute_Metadata.NameContentAttribute              = new MetadataAttribute();
                            diagramElementAttribute_Metadata.NameContentAttribute.Name         = attribute.Name;
                            diagramElementAttribute_Metadata.NameContentAttribute.NamespaceUri = attribute.NamespaceURI;
                            diagramElementAttribute_Metadata.NameContentAttribute.Value        = attribute.Value;
                            AlternateContentMetadataAddCommand cmd_AltContent_diagramElementAttribute_Metadata =
                                treeNode.Presentation.CommandFactory.CreateAlternateContentMetadataAddCommand(
                                    treeNode,
                                    null,
                                    altContent,
                                    diagramElementAttribute_Metadata,
                                    null
                                    );
                            treeNode.Presentation.UndoRedoManager.Execute(
                                cmd_AltContent_diagramElementAttribute_Metadata);
                        }
                    }

                    XmlAttribute srcAttr = (XmlAttribute)obj.Attributes.GetNamedItem(DiagramContentModelHelper.Src);
                    if (srcAttr != null)
                    {
                        XmlAttribute srcType =
                            (XmlAttribute)obj.Attributes.GetNamedItem(DiagramContentModelHelper.SrcType);

                        ManagedImageMedia img = treeNode.Presentation.MediaFactory.CreateManagedImageMedia();

                        string imgFullPath = null;
                        if (FileDataProvider.isHTTPFile(srcAttr.Value))
                        {
                            imgFullPath = FileDataProvider.EnsureLocalFilePathDownloadTempDirectory(srcAttr.Value);
                        }
                        else
                        {
                            imgFullPath = Path.Combine(Path.GetDirectoryName(xmlFilePath), srcAttr.Value);
                        }
                        if (imgFullPath != null && File.Exists(imgFullPath))
                        {
                            string extension = Path.GetExtension(imgFullPath);

                            ImageMediaData imgData = treeNode.Presentation.MediaDataFactory.CreateImageMediaData(extension);
                            if (imgData != null)
                            {
                                imgData.InitializeImage(imgFullPath, Path.GetFileName(imgFullPath));
                                img.ImageMediaData = imgData;

                                AlternateContentSetManagedMediaCommand cmd_AltContent_Image =
                                    treeNode.Presentation.CommandFactory.CreateAlternateContentSetManagedMediaCommand(
                                        treeNode, altContent, img);
                                treeNode.Presentation.UndoRedoManager.Execute(cmd_AltContent_Image);
                            }
                        }
                    }
                }
            }

            if (textNode != null)
            {
                string strText = textNode.InnerXml;

                if (!string.IsNullOrEmpty(strText))
                {
                    strText = strText.Trim();
                    strText = Regex.Replace(strText, @"\s+", " ");
                    strText = strText.Replace("\r\n", "\n");
                }

                if (!string.IsNullOrEmpty(strText))
                {
                    TextMedia txtMedia = treeNode.Presentation.MediaFactory.CreateTextMedia();
                    txtMedia.Text = strText;
                    AlternateContentSetManagedMediaCommand cmd_AltContent_Text =
                        treeNode.Presentation.CommandFactory.CreateAlternateContentSetManagedMediaCommand(treeNode,
                                                                                                          altContent,
                                                                                                          txtMedia);
                    treeNode.Presentation.UndoRedoManager.Execute(cmd_AltContent_Text);
                }
            }

            if (nObjects > 0 && ++objectIndex <= nObjects - 1)
            {
                diagramXmlParseBody_(diagramElementNode, xmlFilePath, treeNode, objectIndex);
            }
        }
예제 #30
0
        public void SetMetadataAttr(AlternateContentProperty altProp, AlternateContent altContent,
                                    Metadata md, MetadataAttribute mdAttr, string newName, string newValue)
        {
            if (string.IsNullOrEmpty(newName) || string.IsNullOrEmpty(newValue))
            {
                return;
            }

            Tuple <TreeNode, TreeNode> selection = m_UrakawaSession.GetTreeNodeSelection();
            TreeNode node = selection.Item2 ?? selection.Item1;

            if (node == null)
            {
                return;
            }

            var altProp_ = node.GetAlternateContentProperty();

            if (altProp_ == null)
            {
                return;
            }

            if (altProp != null && altProp_ != altProp)
            {
                return;
            }

            if (altContent != null && altProp_.AlternateContents.IndexOf(altContent) < 0)
            {
                return;
            }

            if (mdAttr == null)
            {
                MetadataAttribute attr = md.NameContentAttribute;

                if (attr.Name != newName)
                {
                    AlternateContentMetadataSetNameCommand cmd1 =
                        node.Presentation.CommandFactory.CreateAlternateContentMetadataSetNameCommand(
                            altProp,
                            altContent,
                            attr,
                            newName
                            );
                    node.Presentation.UndoRedoManager.Execute(cmd1);
                }
                if (attr.Value != newValue)
                {
                    AlternateContentMetadataSetContentCommand cmd2 =
                        node.Presentation.CommandFactory.CreateAlternateContentMetadataSetContentCommand(
                            altProp,
                            altContent,
                            attr,
                            newValue
                            );
                    node.Presentation.UndoRedoManager.Execute(cmd2);
                }
            }
            else
            {
                if (mdAttr.Name != newName)
                {
                    AlternateContentMetadataSetNameCommand cmd1 =
                        node.Presentation.CommandFactory.CreateAlternateContentMetadataSetNameCommand(
                            altProp,
                            altContent,
                            mdAttr,
                            newName
                            );
                    node.Presentation.UndoRedoManager.Execute(cmd1);
                }
                if (mdAttr.Value != newValue)
                {
                    AlternateContentMetadataSetContentCommand cmd2 =
                        node.Presentation.CommandFactory.CreateAlternateContentMetadataSetContentCommand(
                            altProp,
                            altContent,
                            mdAttr,
                            newValue
                            );
                    node.Presentation.UndoRedoManager.Execute(cmd2);
                }
            }


            RaisePropertyChanged(() => Metadatas);
            RaisePropertyChanged(() => Descriptions);
        }