static Queue <NonnullRichTextBuilder> ReadAllLinesDocx(string path) { Queue <NonnullRichTextBuilder> richTexts = new Queue <NonnullRichTextBuilder>(); WordprocessingDocument doc = null; try { doc = WordprocessingDocument.Open(path, false); } catch (OpenXmlPackageException) { return(richTexts); } catch (System.IO.IOException) { return(richTexts); } Body body = doc.MainDocumentPart.Document.Body; foreach (Paragraph paragraph in body.ChildElements.OfType <Paragraph>()) { DocumentFormat.OpenXml.Drawing.Blip hasImage = paragraph.Descendants <DocumentFormat.OpenXml.Drawing.Blip>().FirstOrDefault(); if (hasImage == null) { richTexts.Enqueue(new NonnullRichTextBuilder(paragraph.InnerText)); } else { List <object> runs = new List <object>(); foreach (Run docRun in paragraph.ChildElements.OfType <Run>()) { DocumentFormat.OpenXml.Drawing.Blip imgContainer = docRun.Descendants <DocumentFormat.OpenXml.Drawing.Blip>().FirstOrDefault(); if (imgContainer == null) { runs.Add(docRun.InnerText); } else { string imgId = imgContainer.Embed.Value; ImagePart imgPart = doc.MainDocumentPart.GetPartById(imgId) as ImagePart; System.IO.Stream imgStream = imgPart.GetStream(); byte[] imgInBytes = new byte[imgStream.Length]; imgStream.Read(imgInBytes, 0, (int)imgStream.Length); runs.Add(imgInBytes); } } NonnullRichTextBuilder richTextRuns = new NonnullRichTextBuilder(CompactRuns(runs)); richTexts.Enqueue(richTextRuns); } } doc.Close(); return(richTexts); }
public static Queue <NonnullRichTextBuilder> ReadAllLines(string path) { if (Path.GetExtension(path) == ".docx") { return(ReadAllLinesDocx(path)); } else { return(NonnullRichTextBuilder.NewWith(File.ReadAllLines(path))); } }
public MultiChoiceData(Queue <NonnullRichTextBuilder> richTexts, int n_options) { if (richTexts.Count < 5) { throw new ArgumentException(); } Stem = richTexts.Dequeue(); Options = new NonnullRichTextBuilder[n_options]; for (int i = 0; i < n_options; ++i) { Options[i] = richTexts.Dequeue(); } }
public NonnullRichText(NonnullRichTextBuilder richText) { Runs = richText.Runs.AsReadOnly(); }