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"); } } TreeNode = treeNode; Metadata = metadata; MetadataAttribute = metadataAttribute; m_AlternateContent = altContent; m_AlternateContentProperty = altContentProperty; ShortDescription = "Remove metadata"; LongDescription = "Remove the Metadata object from the AlternateContent"; }
public override void Execute() { m_TreeNodeNoAltProp = !TreeNode.HasAlternateContentProperty; AlternateContentProperty prop = TreeNode.GetOrCreateAlternateContentProperty(); prop.AlternateContents.Insert(prop.AlternateContents.Count, m_AlternateContent); }
public void RemoveMetadata(AlternateContentProperty altProp, AlternateContent altContent, Metadata md) { 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; } AlternateContentMetadataRemoveCommand cmd = node.Presentation.CommandFactory.CreateAlternateContentMetadataRemoveCommand(node, altProp, altContent, md, null); node.Presentation.UndoRedoManager.Execute(cmd); RaisePropertyChanged(() => Metadatas); RaisePropertyChanged(() => Descriptions); }
public void Init(AlternateContentProperty altContentProperty, AlternateContent altContent, MetadataAttribute metadataAttribute, string content) { if (metadataAttribute == null) { throw new ArgumentNullException("metadataAttribute"); } if (content == null) { throw new ArgumentNullException("content"); } if (altContentProperty == null && altContent == null) { throw new ArgumentNullException("altContentProperty && altContent"); } if (altContentProperty != null && altContent != null) { throw new ArgumentException("altContentProperty && altContent"); } MetadataAttribute = metadataAttribute; m_OriginalContent = MetadataAttribute.Value; Content = content; m_AlternateContent = altContent; m_AlternateContentProperty = altContentProperty; ShortDescription = "Set metadata content"; LongDescription = "Set the Content of the Metadata object in AlternateContent"; }
public override void Execute() { AlternateContentProperty prop = TreeNode.GetAlternateContentProperty(); m_Index = prop.AlternateContents.IndexOf(m_AlternateContent); prop.AlternateContents.Remove(m_AlternateContent); }
public void Init(AlternateContentProperty altContentProperty, AlternateContent altContent, MetadataAttribute metadataAttribute, string name) { if (metadataAttribute == null) { throw new ArgumentNullException("metadataAttribute"); } if (name == null) { throw new ArgumentNullException("name"); } if (altContentProperty == null && altContent == null) { throw new ArgumentNullException("altContentProperty && altContent"); } if (altContentProperty != null && altContent != null) { throw new ArgumentException("altContentProperty && altContent"); } MetadataAttribute = metadataAttribute; m_OriginalName = MetadataAttribute.Name; Name = name; m_AlternateContent = altContent; m_AlternateContentProperty = altContentProperty; ShortDescription = "Set metadata name"; LongDescription = "Set the Name of the Metadata object in AlternateContent"; }
public override void UnExecute() { AlternateContentProperty prop = TreeNode.GetOrCreateAlternateContentProperty(); prop.AlternateContents.Insert(m_Index, //prop.AlternateContents.Count, m_AlternateContent); }
public override void UnExecute() { AlternateContentProperty prop = TreeNode.GetAlternateContentProperty(); prop.AlternateContents.Remove(m_AlternateContent); if (m_TreeNodeNoAltProp) { TreeNode.RemoveProperty(prop); } }
public IEnumerable <string> GetUnknownDIAGRAMnames() { if (m_UrakawaSession.DocumentProject == null) { yield break; } Tuple <TreeNode, TreeNode> selection = m_UrakawaSession.GetTreeNodeSelection(); TreeNode node = selection.Item2 ?? selection.Item1; if (node == null) { yield break; } AlternateContentProperty altProp = node.GetAlternateContentProperty(); if (altProp == null) { yield break; } if (altProp.AlternateContents.Count <= 0) { yield break; } foreach (var altContent in altProp.AlternateContents.ContentsAs_Enumerable) { foreach (var metadata in altContent.Metadatas.ContentsAs_Enumerable) { if (metadata.NameContentAttribute.Name.Equals(DiagramContentModelHelper.DiagramElementName, StringComparison.OrdinalIgnoreCase)) { if (!DiagramContentModelHelper.DIAGRAM_ElementNames.Contains(metadata.NameContentAttribute.Value) //!metadata.NameContentAttribute.Value.Equals(DiagramContentModelHelper.D_LondDesc, StringComparison.OrdinalIgnoreCase) //&& !metadata.NameContentAttribute.Value.Equals(DiagramContentModelHelper.D_Summary, StringComparison.OrdinalIgnoreCase) //&& !metadata.NameContentAttribute.Value.Equals(DiagramContentModelHelper.D_SimplifiedLanguageDescription, StringComparison.OrdinalIgnoreCase) //&& !metadata.NameContentAttribute.Value.Equals(DiagramContentModelHelper.D_SimplifiedImage, StringComparison.OrdinalIgnoreCase) //&& !metadata.NameContentAttribute.Value.Equals(DiagramContentModelHelper.D_Tactile, StringComparison.OrdinalIgnoreCase) //&& !metadata.NameContentAttribute.Value.Equals(DiagramContentModelHelper.Annotation, StringComparison.OrdinalIgnoreCase) ) { yield return(metadata.NameContentAttribute.Value); } } } } yield break; }
public static bool AltPropHasSignificantMetadata(AlternateContentProperty altProp) { bool has = false; foreach (metadata.Metadata md in altProp.Metadatas.ContentsAs_Enumerable) { if ( !md.NameContentAttribute.Name.StartsWith(XmlReaderWriterHelper.NS_PREFIX_XML + ":") ) { has = true; break; } } return(has); }
private void removeEmptyDescriptions(AlternateContentProperty altProp) { foreach (AlternateContent altContent in altProp.AlternateContents.ContentsAs_ListCopy) { if (altContent.IsEmpty || altContent.Text == null && altContent.Image == null && altContent.Audio == null && !Daisy3_Export.AltContentHasSignificantMetadata(altContent) ) { m_ViewModel.RemoveDescription(altContent); } } }
public IEnumerable <string> GetInvalidDIAGRAMnames() { if (m_UrakawaSession.DocumentProject == null) { yield break; } Tuple <TreeNode, TreeNode> selection = m_UrakawaSession.GetTreeNodeSelection(); TreeNode node = selection.Item2 ?? selection.Item1; if (node == null) { yield break; } AlternateContentProperty altProp = node.GetAlternateContentProperty(); if (altProp == null) { yield break; } if (altProp.AlternateContents.Count <= 0) { yield break; } foreach (var altContent in altProp.AlternateContents.ContentsAs_Enumerable) { foreach (var metadata in altContent.Metadatas.ContentsAs_Enumerable) { if (metadata.NameContentAttribute.Name.Equals(DiagramContentModelHelper.DiagramElementName, StringComparison.OrdinalIgnoreCase)) { if (IsIDInValid(metadata.NameContentAttribute.Value)) { yield return(metadata.NameContentAttribute.Value); } } } } yield break; }
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); }
/// <summary> /// Any <see cref="IManaged"/> used by the /// </summary> /// <param name="node">The node being visited</param> /// <returns><c>true</c></returns> public bool PreVisit(TreeNode node) { foreach (property.Property prop in node.Properties.ContentsAs_Enumerable) { if (prop is ChannelsProperty) { ChannelsProperty chProp = (ChannelsProperty)prop; foreach (Channel ch in chProp.UsedChannels) { if (chProp.GetMedia(ch) is IManaged) { IManaged mm = (IManaged)chProp.GetMedia(ch); if (!mCollectedMedia.Contains(mm)) { mCollectedMedia.Add(mm); } } } } else if (prop is AlternateContentProperty) { AlternateContentProperty altProp = (AlternateContentProperty)prop; foreach (AlternateContent ac in altProp.AlternateContents.ContentsAs_Enumerable) { if (ac.Audio != null && !mCollectedMedia.Contains(ac.Audio)) { mCollectedMedia.Add(ac.Audio); } if (ac.Image != null && !mCollectedMedia.Contains(ac.Image)) { mCollectedMedia.Add(ac.Image); } } } } return(true); }
public void CreateSmilNodesForImageDescription(TreeNode levelNodeDescendant, XmlDocument smilDocument, XmlNode smilBodySeq, Time durationOfCurrentSmil, AlternateContentProperty altProperty, string smilFileName) { //try //{ int counter = 0; foreach (string diagramDescriptionElementName in m_Map_AltProperty_TO_Description[altProperty].Map_DiagramElementName_TO_AltContent.Keys) { AlternateContent altContent = m_Map_AltProperty_TO_Description[altProperty].Map_DiagramElementName_TO_AltContent[diagramDescriptionElementName]; if (altContent.Text == null) { continue; } counter++; if (m_Image_ProdNoteMap[levelNodeDescendant].Count <= counter) { break; } XmlNode seqNode = smilDocument.CreateElement("seq", smilBodySeq.NamespaceURI); smilBodySeq.AppendChild(seqNode); XmlDocumentHelper.CreateAppendXmlAttribute(smilDocument, seqNode, "class", "prodnote"); string strSeqID = GetNextID(ID_SmilPrefix); //System.Windows.Forms.MessageBox.Show(counter.ToString () + " : " + m_Image_ProdNoteMap[n].Count.ToString()); string dtbookID = m_Image_ProdNoteMap[levelNodeDescendant][counter].Attributes.GetNamedItem("id").Value; string par_id = GetNextID(ID_SmilPrefix); XmlDocumentHelper.CreateAppendXmlAttribute(smilDocument, seqNode, "id", strSeqID); XmlDocumentHelper.CreateAppendXmlAttribute(smilDocument, seqNode, "class", "prodnote"); XmlDocumentHelper.CreateAppendXmlAttribute(smilDocument, seqNode, "customTest", "prodnote"); XmlDocumentHelper.CreateAppendXmlAttribute(m_DTBDocument, m_Image_ProdNoteMap[levelNodeDescendant][counter], "smilref", FileDataProvider.UriEncode(smilFileName + "#" + strSeqID)); XmlNode parNode = smilDocument.CreateElement(null, "par", smilBodySeq.NamespaceURI); seqNode.AppendChild(parNode); XmlDocumentHelper.CreateAppendXmlAttribute(smilDocument, parNode, "id", par_id); XmlNode SmilTextNode = smilDocument.CreateElement(null, "text", smilBodySeq.NamespaceURI); XmlDocumentHelper.CreateAppendXmlAttribute(smilDocument, SmilTextNode, "id", GetNextID(ID_SmilPrefix)); XmlDocumentHelper.CreateAppendXmlAttribute(smilDocument, SmilTextNode, "src", FileDataProvider.UriEncode(m_Filename_Content + "#" + dtbookID)); parNode.AppendChild(SmilTextNode); if (altContent.Audio != null) { media.data.audio.ManagedAudioMedia managedAudio = altContent.Audio; string srcPath = m_Map_AltContentAudio_TO_RelativeExportedFilePath[altContent]; DebugFix.Assert(!string.IsNullOrEmpty(srcPath)); XmlNode audioNode = smilDocument.CreateElement(null, "audio", smilBodySeq.NamespaceURI); XmlDocumentHelper.CreateAppendXmlAttribute(smilDocument, audioNode, "clipBegin", "00:00:00"); XmlDocumentHelper.CreateAppendXmlAttribute(smilDocument, audioNode, "clipEnd", FormatTimeString(managedAudio.Duration)); XmlDocumentHelper.CreateAppendXmlAttribute(smilDocument, audioNode, "src", FileDataProvider.UriEncode(srcPath)); parNode.AppendChild(audioNode); if (!m_FilesList_SmilAudio.Contains(srcPath)) { m_FilesList_SmilAudio.Add(srcPath); } // add to duration durationOfCurrentSmil.Add(managedAudio.Duration); } } //} //catch (System.Exception ex) //{ // System.Windows.Forms.MessageBox.Show(ex.ToString()); //} }
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); }
public AlternateContentMetadataRemoveCommand CreateAlternateContentMetadataRemoveCommand(TreeNode treeNode, AlternateContentProperty altContentProperty, AlternateContent altContent, Metadata metadata, MetadataAttribute metadataAttribute) { AlternateContentMetadataRemoveCommand command = Create <AlternateContentMetadataRemoveCommand>(); command.Init(treeNode, altContentProperty, altContent, metadata, metadataAttribute); return(command); }
public AlternateContentMetadataSetContentCommand CreateAlternateContentMetadataSetContentCommand(AlternateContentProperty altContentProperty, AlternateContent altContent, MetadataAttribute metadataAttribute, string content) { AlternateContentMetadataSetContentCommand command = Create <AlternateContentMetadataSetContentCommand>(); command.Init(altContentProperty, altContent, metadataAttribute, content); return(command); }
private void generateImageDescriptionInDTBook(TreeNode n, XmlNode currentXmlNode, string exportImageName, XmlDocument DTBookDocument) { AlternateContentProperty altProp = n.GetAlternateContentProperty(); if (currentXmlNode.LocalName == null || !currentXmlNode.LocalName.Equals("img", StringComparison.OrdinalIgnoreCase) || altProp == null || altProp.IsEmpty) { return; } m_Map_AltProperty_TO_Description.Add(altProp, new Description()); PCMFormatInfo audioFormat = m_Presentation.MediaDataManager.DefaultPCMFormat; AudioLibPCMFormat pcmFormat = audioFormat.Data; pcmFormat.SampleRate = (ushort)m_sampleRate; pcmFormat.NumberOfChannels = (ushort)(m_audioStereo ? 2 : 1); Dictionary <string, List <string> > map_DiagramElementName_TO_TextualDescriptions = new Dictionary <string, List <string> >(); string imageDescriptionDirectoryPath = GetAndCreateImageDescriptionDirectoryPath(true, exportImageName, m_OutputDirectory); string descriptionFile = CreateImageDescription(m_SkipACM, pcmFormat, m_encodeAudioFiles, m_BitRate_Encoding, imageDescriptionDirectoryPath, exportImageName, altProp, map_DiagramElementName_TO_TextualDescriptions, m_Map_AltProperty_TO_Description, m_Map_AltContentAudio_TO_RelativeExportedFilePath); if (m_includeImageDescriptions && !String.IsNullOrEmpty(descriptionFile)) { //short term way for executing image description code: will be updated in later phase of implementation XmlNode prodNoteNode = DTBookDocument.CreateElement("prodnote", currentXmlNode.NamespaceURI); XmlDocumentHelper.CreateAppendXmlAttribute(DTBookDocument, prodNoteNode, "render", "optional"); string id_Prodnote = GetNextID(ID_DTBPrefix); XmlDocumentHelper.CreateAppendXmlAttribute(DTBookDocument, prodNoteNode, "id", id_Prodnote); XmlDocumentHelper.CreateAppendXmlAttribute(DTBookDocument, prodNoteNode, "imgref", currentXmlNode.Attributes.GetNamedItem("id").Value); XmlDocumentHelper.CreateAppendXmlAttribute(DTBookDocument, prodNoteNode, "class", DiagramContentModelHelper.EPUB_DescribedAt); currentXmlNode.ParentNode.AppendChild(prodNoteNode); if (!m_Image_ProdNoteMap.ContainsKey(n)) { m_Image_ProdNoteMap.Add(n, new List <XmlNode>()); } m_Image_ProdNoteMap[n].Add(prodNoteNode); XmlNode anchorNode = DTBookDocument.CreateElement("a", currentXmlNode.NamespaceURI); XmlNode pAnchor = DTBookDocument.CreateElement( DiagramContentModelHelper.P, currentXmlNode.NamespaceURI ); pAnchor.AppendChild(anchorNode); prodNoteNode.AppendChild(pAnchor); string descriptionFileUrl = descriptionFile.Replace('\\', '/'); XmlDocumentHelper.CreateAppendXmlAttribute(DTBookDocument, anchorNode, "href", FileDataProvider.UriEncode(descriptionFileUrl)); XmlDocumentHelper.CreateAppendXmlAttribute(DTBookDocument, anchorNode, "external", "true"); anchorNode.AppendChild(DTBookDocument.CreateTextNode("Image description (DIAGRAM XML)")); if (map_DiagramElementName_TO_TextualDescriptions.Count > 0) { foreach (string diagramDescriptionElementName in map_DiagramElementName_TO_TextualDescriptions.Keys) { //System.Windows.Forms.MessageBox.Show(s + " : " + imageDescriptions[s]); XmlNode prodNoteDesc = DTBookDocument.CreateElement("prodnote", currentXmlNode.NamespaceURI); XmlDocumentHelper.CreateAppendXmlAttribute(DTBookDocument, prodNoteDesc, "render", "optional"); string id_ProdnoteDesc = GetNextID(ID_DTBPrefix); XmlDocumentHelper.CreateAppendXmlAttribute(DTBookDocument, prodNoteDesc, "id", id_ProdnoteDesc); XmlDocumentHelper.CreateAppendXmlAttribute(DTBookDocument, prodNoteDesc, "imgref", currentXmlNode.Attributes.GetNamedItem("id").Value); XmlDocumentHelper.CreateAppendXmlAttribute(DTBookDocument, prodNoteDesc, "class", diagramDescriptionElementName); currentXmlNode.ParentNode.AppendChild(prodNoteDesc); m_Image_ProdNoteMap[n].Add(prodNoteDesc); foreach (string txt in map_DiagramElementName_TO_TextualDescriptions[diagramDescriptionElementName]) { string descText = txt; bool xmlParseFail = descText.StartsWith(DIAGRAM_XML_PARSE_FAIL); bool descriptionTextContainsMarkup = !xmlParseFail && descText.IndexOf('<') >= 0; // descText.Contains("<"); if (descriptionTextContainsMarkup) { try { prodNoteDesc.InnerXml = descText; } catch (Exception ex) { #if DEBUG Debugger.Break(); #endif Console.WriteLine(@"Cannot set DIAGRAM XML: " + descText); XmlNode wrapperNode = DTBookDocument.CreateElement(DiagramContentModelHelper.CODE, currentXmlNode.NamespaceURI); prodNoteDesc.AppendChild(wrapperNode); wrapperNode.AppendChild(DTBookDocument.CreateTextNode(descText)); } } else if (xmlParseFail) { //descText = descText.Replace(DIAGRAM_XML_PARSE_FAIL, ""); descText = descText.Substring(DIAGRAM_XML_PARSE_FAIL.Length); XmlNode wrapperNode = DTBookDocument.CreateElement(DiagramContentModelHelper.CODE, currentXmlNode.NamespaceURI); prodNoteDesc.AppendChild(wrapperNode); wrapperNode.AppendChild(DTBookDocument.CreateTextNode(descText)); } else { string normalizedText = descText.Replace("\r\n", "\n"); string[] parasText = normalizedText.Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries); //string[] parasText = System.Text.RegularExpressions.Regex.Split(normalizedText, "\n"); for (int i = 0; i < parasText.Length; i++) { string paraText = parasText[i].Trim(); if (string.IsNullOrEmpty(paraText)) { continue; } XmlNode paragraph = DTBookDocument.CreateElement( //DiagramContentModelHelper.NS_PREFIX_ZAI, DiagramContentModelHelper.P , currentXmlNode.NamespaceURI //, DiagramContentModelHelper.NS_URL_ZAI ); paragraph.InnerText = paraText; prodNoteDesc.AppendChild(paragraph); } } } } } /* * if ( EXPORT_IMAGE_DESCRIPTION_IN_DTBOOK ) * {//1 * // to do copy the diagram nodes that descend directly from body * if (m_AltProperrty_DiagramDocument.ContainsKey(n.GetAlternateContentProperty())) * {//2 * * XmlDocumentHelper.CreateAppendXmlAttribute(DTBookDocument, DTBookDocument.GetElementsByTagName("dtbook")[0], * XmlReaderWriterHelper.NS_PREFIX_XMLNS+":" + DiagramContentModelHelper.NS_PREFIX_DIAGRAM, * DiagramContentModelHelper.NS_URL_DIAGRAM); * XmlDocument descriptionDocument = m_AltProperrty_DiagramDocument[n.GetAlternateContentProperty()]; * XmlNodeList diagramNodesList = descriptionDocument.GetElementsByTagName("d:body")[0].ChildNodes; * foreach (XmlNode xn in diagramNodesList) * {//3 * XmlNode newNode = DTBookDocument.ImportNode(xn, true); * prodNoteNode.AppendChild(newNode); * for (int i = 0; i < newNode.Attributes.Count; i++) * {//4 * XmlAttribute attr = newNode.Attributes[i]; * if (attr.Name == DiagramContentModelHelper.NS_PREFIX_XML + ":id") * {//-4 * XmlDocumentHelper.CreateAppendXmlAttribute(DTBookDocument, newNode, "id", attr.Value); * newNode.Attributes.Remove(attr); * }//-3 * }//-2 * * }//-1 * * } * * //XmlNode newNode = DTBookDocument.ImportNode(M_DescriptionDocument.GetElementsByTagName("d:description")[0], true); * //prodNoteNode.AppendChild(newNode); * } */ } //} //catch (System.Exception ex) //{ //System.Windows.Forms.MessageBox.Show(ex.ToString()); //} //} //} }
public const string DIAGRAM_CSS_CLASS_PREFIX = @"DIAGRAM "; // space character is crucial! public static string CreateImageDescriptionHTML(string imageDescriptionDirectoryPath, string imageSRC, AlternateContentProperty altProperty, out bool hasMathML, out bool hasSVG, Dictionary <AlternateContent, string> map_AltContentAudio_TO_RelativeExportedFilePath, Dictionary <string, List <string> > map_DiagramElementName_TO_TextualDescriptions, bool onlyLongDesc) { #if DEBUG DebugFix.Assert(!altProperty.IsEmpty); #endif //DEBUG XmlDocument htmlDocument = new XmlDocument(); htmlDocument.XmlResolver = null; htmlDocument.CreateXmlDeclaration("1.0", "utf-8", null); //XmlDocumentType doctype = xmlDoc.CreateDocumentType("html", "", "", null); //XmlDocumentType doctype = xmlDoc.CreateDocumentType("html", null, null, ""); XmlDocumentType doctype = htmlDocument.CreateDocumentType("html", null, null, null); htmlDocument.AppendChild(doctype); XmlNode htmlNode = htmlDocument.CreateElement(null, @"html", DiagramContentModelHelper.NS_URL_XHTML); XmlDocumentHelper.CreateAppendXmlAttribute(htmlDocument, htmlNode, XmlReaderWriterHelper.NS_PREFIX_XMLNS, DiagramContentModelHelper.NS_URL_XHTML); htmlDocument.AppendChild(htmlNode); XmlDocumentHelper.CreateAppendXmlAttribute(htmlDocument, htmlNode, XmlReaderWriterHelper.NS_PREFIX_XMLNS + ":" + DiagramContentModelHelper.NS_PREFIX_DIAGRAM, DiagramContentModelHelper.NS_URL_DIAGRAM); XmlDocumentHelper.CreateAppendXmlAttribute(htmlDocument, htmlNode, XmlReaderWriterHelper.NS_PREFIX_XMLNS + ":" + DiagramContentModelHelper.NS_PREFIX_DIAGRAM_METADATA, DiagramContentModelHelper.NS_URL_DIAGRAM); XmlDocumentHelper.CreateAppendXmlAttribute(htmlDocument, htmlNode, XmlReaderWriterHelper.NS_PREFIX_XMLNS + ":" + DiagramContentModelHelper.NS_PREFIX_DC, DiagramContentModelHelper.NS_URL_DC); XmlDocumentHelper.CreateAppendXmlAttribute(htmlDocument, htmlNode, XmlReaderWriterHelper.NS_PREFIX_XMLNS + ":" + DiagramContentModelHelper.NS_PREFIX_DCTERMS, DiagramContentModelHelper.NS_URL_DCTERMS); //createDiagramHeadMetadata(descriptionDocument, descriptionNode, altProperty); XmlNode head = htmlDocument.CreateElement(null, @"head", htmlNode.NamespaceURI); htmlNode.AppendChild(head); string css = "body { margin: 0; padding: 0; background: white; color: black; font-size: 130%; font-family: serif; } ." + Daisy3_Export.DIAGRAM_CSS_CLASS_PREFIX.Substring(0, Daisy3_Export.DIAGRAM_CSS_CLASS_PREFIX.Length - 1) + ":before { content: attr(class); font-family: sans-serif; font-weight: bold; display: block; border: 1px dashed black; padding: 0.5em; margin: 0; margin-bottom: 0.5em; } ." + Daisy3_Export.DIAGRAM_CSS_CLASS_PREFIX + "{ border: 2px solid black; padding: 0.5em; margin: 0; margin-top: 1em; } ." + Daisy3_Export.DIAGRAM_CSS_CLASS_PREFIX + ".d\\:tour { border: 2px solid green; padding: 0.5em; margin: 0; margin-top: 1em; } ." + Daisy3_Export.DIAGRAM_CSS_CLASS_PREFIX + ".d\\:tour:before { content: \"DIAGRAM d\\:tour\"; font-family: sans-serif; font-weight: bold; display: block; border: 1px dashed green; padding: 0.5em; margin: 0; margin-bottom: 0.5em; } ." + Daisy3_Export.DIAGRAM_CSS_CLASS_PREFIX + "img { display: block; padding: 0; margin: 0; margin-top: 1em; margin-bottom: 0.5em; } ." + Daisy3_Export.DIAGRAM_CSS_CLASS_PREFIX + "audio { display: block; padding: 0; margin: 0; margin-top: 1em; margin-bottom: 0.5em; }"; XmlNode style = htmlDocument.CreateElement(@"style", htmlDocument.DocumentElement.NamespaceURI); head.AppendChild(style); XmlDocumentHelper.CreateAppendXmlAttribute(htmlDocument, style, @"type", @"text/css"); XmlNode cssNode = htmlDocument.CreateTextNode(css); style.AppendChild(cssNode); createDiagramBodyContentHTML(htmlDocument, htmlNode, altProperty, imageDescriptionDirectoryPath, out hasMathML, out hasSVG, map_AltContentAudio_TO_RelativeExportedFilePath, map_DiagramElementName_TO_TextualDescriptions, onlyLongDesc); string descFileName = Path.GetFileNameWithoutExtension(imageSRC) + IMAGE_DESCRIPTION_XML_SUFFIX + DataProviderFactory.XHTML_EXTENSION; XmlReaderWriterHelper.WriteXmlDocument(htmlDocument, Path.Combine(imageDescriptionDirectoryPath, descFileName), null); string relativePath = Path.GetFileName(imageDescriptionDirectoryPath); DirectoryInfo d = new DirectoryInfo(imageDescriptionDirectoryPath); DebugFix.Assert(relativePath == d.Name); return(Path.Combine(relativePath, descFileName)); }
private static void createDiagramHeadMetadata(XmlDocument descriptionDocument, XmlNode descriptionNode, AlternateContentProperty altProperty) { XmlNode headNode = descriptionDocument.CreateElement( DiagramContentModelHelper.NS_PREFIX_DIAGRAM, DiagramContentModelHelper.StripNSPrefix(DiagramContentModelHelper.D_Head), DiagramContentModelHelper.NS_URL_DIAGRAM); descriptionNode.AppendChild(headNode); //TODO: ALWAYS DISABLE THE DEBUG CODE BELOW UNLESS NEEDED FOR TESTING!! #if false && DEBUG foreach (Metadata md in altProperty.Metadatas.ContentsAs_Enumerable) { addFlatDiagramHeadMetadata( md.NameContentAttribute, md.OtherAttributes.ContentsAs_Enumerable, headNode, descriptionDocument, descriptionNode); } #endif // DEBUG List <Metadata> flatMetadatas = new List <Metadata>(); Dictionary <string, List <Metadata> > groupedMetadata_Id = new Dictionary <string, List <Metadata> >(); Dictionary <string, List <Metadata> > groupedMetadata_RelResource = new Dictionary <string, List <Metadata> >(); foreach (Metadata md in altProperty.Metadatas.ContentsAs_Enumerable) { if (md.NameContentAttribute == null) { #if DEBUG Debugger.Break(); #endif // DEBUG continue; } if ( md.NameContentAttribute.Name.StartsWith(XmlReaderWriterHelper.NS_PREFIX_XML + ":") //&& (md.OtherAttributes == null || md.OtherAttributes.Count == 0) && (descriptionNode.Attributes == null || descriptionNode.Attributes.GetNamedItem(md.NameContentAttribute.Name) == null)) { XmlDocumentHelper.CreateAppendXmlAttribute(descriptionDocument, descriptionNode, md.NameContentAttribute.Name, md.NameContentAttribute.Value, XmlReaderWriterHelper.NS_URL_XML); } else { if (md.OtherAttributes != null && md.OtherAttributes.Count > 0) { MetadataAttribute mdAttr_Rel = null; MetadataAttribute mdAttr_Resource = null; MetadataAttribute mdAttr_Id = null; bool hasOtherAttrs = false; foreach (MetadataAttribute mdAttr in md.OtherAttributes.ContentsAs_Enumerable) { if (mdAttr.Name == Metadata.PrimaryIdentifierMark) { continue; } if (mdAttr.Name == DiagramContentModelHelper.Rel) { mdAttr_Rel = mdAttr; continue; } if (mdAttr.Name == DiagramContentModelHelper.Resource) { mdAttr_Resource = mdAttr; continue; } if (mdAttr.Name == XmlReaderWriterHelper.XmlId) { mdAttr_Id = mdAttr; continue; } hasOtherAttrs = true; } if (mdAttr_Id != null) { addDic_(groupedMetadata_Id, mdAttr_Id.Value, md); continue; } else if (mdAttr_Rel != null || mdAttr_Resource != null) { string key = (mdAttr_Rel != null ? mdAttr_Rel.Value : "") + "_-_" + (mdAttr_Resource != null ? mdAttr_Resource.Value : ""); addDic_(groupedMetadata_RelResource, key, md); continue; } } //md.NameContentAttribute.Name != DiagramContentModelHelper.NA // && md.NameContentAttribute.Value != DiagramContentModelHelper.NA flatMetadatas.Add(md); } } foreach (Metadata md in flatMetadatas) { addFlatDiagramHeadMetadata( md.NameContentAttribute, md.OtherAttributes.ContentsAs_Enumerable, headNode, descriptionDocument, descriptionNode); } handleMetadataGroup(headNode, descriptionDocument, descriptionNode, groupedMetadata_Id); handleMetadataGroup(headNode, descriptionDocument, descriptionNode, groupedMetadata_RelResource); }
public static string CreateImageDescription( bool skipACM, AudioLibPCMFormat pcmFormat, bool encodeToMp3, double bitRate_Mp3, string imageDescriptionDirectoryPath, string imageSRC, AlternateContentProperty altProperty, Dictionary <string, List <string> > map_DiagramElementName_TO_TextualDescriptions, Dictionary <AlternateContentProperty, Description> map_AltProperty_TO_Description, Dictionary <AlternateContent, string> map_AltContentAudio_TO_RelativeExportedFilePath ) { #if DEBUG DebugFix.Assert(!altProperty.IsEmpty); #endif //DEBUG XmlDocument descriptionDocument = new XmlDocument(); //m_AltProperrty_DiagramDocument.Add(altProperty, descriptionDocument); // <?xml-stylesheet type="text/xsl" href="desc2html.xsl"?> //string processingInstructionData = "type=\"text/xsl\" href=\"desc2html.xsl\""; //descriptionDocument.AppendChild(descriptionDocument.CreateProcessingInstruction("xml-stylesheet", processingInstructionData)); //string xsltFileName = "desc2html.xsl"; //string sourceXsltPath = Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, xsltFileName); //string destXsltPath = Path.Combine(imageDescriptionDirectoryPath, xsltFileName); //if (!File.Exists(destXsltPath)) File.Copy(sourceXsltPath, destXsltPath); XmlNode descriptionNode = descriptionDocument.CreateElement( DiagramContentModelHelper.NS_PREFIX_DIAGRAM, DiagramContentModelHelper.StripNSPrefix(DiagramContentModelHelper.D_Description), DiagramContentModelHelper.NS_URL_DIAGRAM); XmlDocumentHelper.CreateAppendXmlAttribute(descriptionDocument, descriptionNode, XmlReaderWriterHelper.NS_PREFIX_XMLNS, DiagramContentModelHelper.NS_URL_ZAI); descriptionDocument.AppendChild(descriptionNode); XmlDocumentHelper.CreateAppendXmlAttribute(descriptionDocument, descriptionNode, XmlReaderWriterHelper.NS_PREFIX_XMLNS + ":" + DiagramContentModelHelper.NS_PREFIX_DIAGRAM, DiagramContentModelHelper.NS_URL_DIAGRAM); XmlDocumentHelper.CreateAppendXmlAttribute(descriptionDocument, descriptionNode, XmlReaderWriterHelper.NS_PREFIX_XMLNS + ":" + DiagramContentModelHelper.NS_PREFIX_DIAGRAM_METADATA, DiagramContentModelHelper.NS_URL_DIAGRAM); XmlDocumentHelper.CreateAppendXmlAttribute(descriptionDocument, descriptionNode, XmlReaderWriterHelper.NS_PREFIX_XMLNS + ":" + DiagramContentModelHelper.NS_PREFIX_DC, DiagramContentModelHelper.NS_URL_DC); XmlDocumentHelper.CreateAppendXmlAttribute(descriptionDocument, descriptionNode, XmlReaderWriterHelper.NS_PREFIX_XMLNS + ":" + DiagramContentModelHelper.NS_PREFIX_DCTERMS, DiagramContentModelHelper.NS_URL_DCTERMS); createDiagramHeadMetadata(descriptionDocument, descriptionNode, altProperty); createDiagramBodyContent(skipACM, descriptionDocument, descriptionNode, altProperty, map_DiagramElementName_TO_TextualDescriptions, imageDescriptionDirectoryPath, map_AltProperty_TO_Description, encodeToMp3, bitRate_Mp3, pcmFormat, map_AltContentAudio_TO_RelativeExportedFilePath); string descFileName = Path.GetFileNameWithoutExtension(imageSRC) + IMAGE_DESCRIPTION_XML_SUFFIX + DataProviderFactory.XML_EXTENSION; XmlReaderWriterHelper.WriteXmlDocument(descriptionDocument, Path.Combine(imageDescriptionDirectoryPath, descFileName), null); string relativePath = Path.GetFileName(imageDescriptionDirectoryPath); DirectoryInfo d = new DirectoryInfo(imageDescriptionDirectoryPath); DebugFix.Assert(relativePath == d.Name); return(Path.Combine(relativePath, descFileName)); }