internal override void VisitDocumentElements(DocumentElements elements) { SortedList splitParaList = new SortedList(); for (int idx = 0; idx < elements.Count; ++idx) { Paragraph paragraph = elements[idx] as Paragraph; if (paragraph != null) { Paragraph[] paragraphs = paragraph.SplitOnParaBreak(); if (paragraphs != null) { splitParaList.Add(idx, paragraphs); } } } int insertedObjects = 0; for (int idx = 0; idx < splitParaList.Count; ++idx) { int insertPosition = (int)splitParaList.GetKey(idx); Paragraph[] paragraphs = (Paragraph[])splitParaList.GetByIndex(idx); foreach (Paragraph paragraph in paragraphs) { elements.InsertObject(insertPosition + insertedObjects, paragraph); ++insertedObjects; } elements.RemoveObjectAt(insertPosition + insertedObjects); --insertedObjects; } }
/// <summary> /// Renders the paragraph to RTF. /// </summary> internal override void Render() { _useEffectiveValue = true; DocumentElements elements = DocumentRelations.GetParent(_paragraph) as DocumentElements; _rtfWriter.WriteControl("pard"); bool isCellParagraph = DocumentRelations.GetParent(elements) is Cell; bool isFootnoteParagraph = isCellParagraph ? false : DocumentRelations.GetParent(elements) is Footnote; if (isCellParagraph) { _rtfWriter.WriteControl("intbl"); } RenderStyleAndFormat(); if (!_paragraph.IsNull("Elements")) { RenderContent(); } EndStyleAndFormatAfterContent(); if ((!isCellParagraph && !isFootnoteParagraph) || _paragraph != elements.LastObject) { _rtfWriter.WriteControl("par"); } }
/// <summary> /// Renders the paragraph content to RTF. /// </summary> private void RenderContent() { DocumentElements elements = DocumentRelations.GetParent(_paragraph) as DocumentElements; //First paragraph of a footnote writes the reference symbol: if (DocumentRelations.GetParent(elements) is Footnote && _paragraph == elements.First) { FootnoteRenderer ftntRenderer = new FootnoteRenderer(DocumentRelations.GetParent(elements) as Footnote, _docRenderer); ftntRenderer.RenderReference(); } foreach (DocumentObject docObj in _paragraph.Elements) { if (docObj == _paragraph.Elements.LastObject) { if (docObj is Character) { if (((Character)docObj).SymbolName == SymbolName.LineBreak) { continue; //Ignore last linebreak. } } } RendererBase rndrr = RendererFactory.CreateRenderer(docObj, _docRenderer); if (rndrr != null) { rndrr.Render(); } } }
public void addObject(TDocumentElement value) { if (value != null) { DocumentElements.Add(value); } }
internal override void VisitDocumentElements(DocumentElements elements) { SortedList splitParaList = new SortedList(); for (int idx = 0; idx < elements.Count; ++idx) { Paragraph paragraph = elements[idx] as Paragraph; if (paragraph != null) { Paragraph[] paragraphs = paragraph.SplitOnParaBreak(); if (paragraphs != null) splitParaList.Add(idx, paragraphs); } } int insertedObjects = 0; for (int idx = 0; idx < splitParaList.Count; ++idx) { int insertPosition = (int)splitParaList.GetKey(idx); Paragraph[] paragraphs = (Paragraph[])splitParaList.GetByIndex(idx); foreach (Paragraph paragraph in paragraphs) { elements.InsertObject(insertPosition + insertedObjects, paragraph); ++insertedObjects; } elements.RemoveObjectAt(insertPosition + insertedObjects); --insertedObjects; } }
/// <summary> /// Renders an image to RTF. /// </summary> internal override void Render() { bool renderInParagraph = RenderInParagraph(); DocumentElements elms = DocumentRelations.GetParent(this.image) as DocumentElements; if (elms != null && !renderInParagraph && !(DocumentRelations.GetParent(elms) is Section || DocumentRelations.GetParent(elms) is HeaderFooter)) { Trace.WriteLine(Messages.ImageFreelyPlacedInWrongContext(this.image.Name), "warning"); return; } if (renderInParagraph) { StartDummyParagraph(); } if (!this.isInline) { StartShapeArea(); } RenderImage(); if (!this.isInline) { EndShapeArea(); } if (renderInParagraph) { EndDummyParagraph(); } }
public Boolean removeObject(TDocumentElement value) { if (value != null) { DocumentElements.Remove(value); return(true); } return(false); }
/// <summary> /// Renders a TextFrame to RTF. /// </summary> internal override void Render() { DocumentElements elms = DocumentRelations.GetParent(_textFrame) as DocumentElements; bool renderInParagraph = RenderInParagraph(); if (renderInParagraph) { StartDummyParagraph(); } StartShapeArea(); //Properties RenderNameValuePair("shapeType", "202");//202 entspr. Textrahmen. TranslateAsNameValuePair("MarginLeft", "dxTextLeft", RtfUnit.EMU, "0"); TranslateAsNameValuePair("MarginTop", "dyTextTop", RtfUnit.EMU, "0"); TranslateAsNameValuePair("MarginRight", "dxTextRight", RtfUnit.EMU, "0"); TranslateAsNameValuePair("MarginBottom", "dyTextBottom", RtfUnit.EMU, "0"); if (_textFrame.IsNull("Elements") || !CollectionContainsObjectAssignableTo(_textFrame.Elements, typeof(Shape), typeof(Table))) { TranslateAsNameValuePair("Orientation", "txflTextFlow", RtfUnit.Undefined, null); } else { TextOrientation orient = _textFrame.Orientation; if (orient != TextOrientation.Horizontal && orient != TextOrientation.HorizontalRotatedFarEast) { Debug.WriteLine(Messages2.TextframeContentsNotTurned, "warning"); } } _rtfWriter.StartContent(); _rtfWriter.WriteControl("shptxt"); _rtfWriter.StartContent(); foreach (DocumentObject docObj in _textFrame.Elements) { RendererBase rndrr = RendererFactory.CreateRenderer(docObj, _docRenderer); if (rndrr != null) { rndrr.Render(); } } //Text fields need to close with a paragraph. RenderTrailingParagraph(_textFrame.Elements); _rtfWriter.EndContent(); _rtfWriter.EndContent(); EndShapeArea(); if (renderInParagraph) { RenderLayoutPicture(); EndDummyParagraph(); } }
internal override void VisitDocumentElements(DocumentElements elements) { #if true // New version without sorted list int count = elements.Count; for (int idx = 0; idx < count; ++idx) { Paragraph paragraph = elements[idx] as Paragraph; if (paragraph != null) { Paragraph[] paragraphs = paragraph.SplitOnParaBreak(); if (paragraphs != null) { foreach (Paragraph para in paragraphs) { elements.InsertObject(idx++, para); ++count; } elements.RemoveObjectAt(idx--); --count; } } } #else SortedList splitParaList = new SortedList(); for (int idx = 0; idx < elements.Count; ++idx) { Paragraph paragraph = elements[idx] as Paragraph; if (paragraph != null) { Paragraph[] paragraphs = paragraph.SplitOnParaBreak(); if (paragraphs != null) { splitParaList.Add(idx, paragraphs); } } } int insertedObjects = 0; for (int idx = 0; idx < splitParaList.Count; ++idx) { int insertPosition = (int)splitParaList.GetKey(idx); Paragraph[] paragraphs = (Paragraph[])splitParaList.GetByIndex(idx); foreach (Paragraph paragraph in paragraphs) { elements.InsertObject(insertPosition + insertedObjects, paragraph); ++insertedObjects; } elements.RemoveObjectAt(insertPosition + insertedObjects); --insertedObjects; } #endif }
/// <summary> /// Renders a Table to RTF. /// </summary> internal override void Render() { DocumentElements elms = DocumentRelations.GetParent(_table) as DocumentElements; MergedCellList mrgdCellList = new MergedCellList(_table); foreach (Row row in _table.Rows) { RowRenderer rowRenderer = new RowRenderer(row, _docRenderer); rowRenderer.CellList = mrgdCellList; rowRenderer.Render(); } }
/// <summary> /// Renders a trailing standard paragraph in case the last element in elements isn't a paragraph. /// (Some RTF elements need to close with a paragraph.) /// </summary> protected void RenderTrailingParagraph(DocumentElements elements) { if (elements == null || !(elements.LastObject is Paragraph)) { //At least one paragra needs to be written at the end of the document. //Otherwise, word cannot read the resulting rtf file. _rtfWriter.WriteControl("pard"); _rtfWriter.WriteControl("s", _docRenderer.GetStyleIndex(StyleNames.Normal)); new ParagraphFormatRenderer(_docRenderer.Document.Styles[StyleNames.Normal].ParagraphFormat, _docRenderer).Render(); _rtfWriter.WriteControl("par"); } }
internal override void VisitDocumentElements(DocumentElements elements) { #if true // New version without sorted list int count = elements.Count; for (int idx = 0; idx < count; ++idx) { Paragraph paragraph = elements[idx] as Paragraph; if (paragraph != null) { Paragraph[] paragraphs = paragraph.SplitOnParaBreak(); if (paragraphs != null) { foreach (Paragraph para in paragraphs) { elements.InsertObject(idx++, para); ++count; } elements.RemoveObjectAt(idx--); --count; } } } #else SortedList splitParaList = new SortedList(); for (int idx = 0; idx < elements.Count; ++idx) { Paragraph paragraph = elements[idx] as Paragraph; if (paragraph != null) { Paragraph[] paragraphs = paragraph.SplitOnParaBreak(); if (paragraphs != null) splitParaList.Add(idx, paragraphs); } } int insertedObjects = 0; for (int idx = 0; idx < splitParaList.Count; ++idx) { int insertPosition = (int)splitParaList.GetKey(idx); Paragraph[] paragraphs = (Paragraph[])splitParaList.GetByIndex(idx); foreach (Paragraph paragraph in paragraphs) { elements.InsertObject(insertPosition + insertedObjects, paragraph); ++insertedObjects; } elements.RemoveObjectAt(insertPosition + insertedObjects); --insertedObjects; } #endif }
private void CopyChildElements(DocumentElements copyTo, string referenceId) { var relatedDocumentElements = _documentContext.RelatedDocuments[referenceId] .Sections .OfType <PdfSection>() .First() .Clone() .Elements; foreach (DocumentObject element in relatedDocumentElements) { copyTo.Add(element.Clone() as DocumentObject); } }
/// <summary> /// Renders a TextFrame to CSV. /// </summary> internal override void Render() { DocumentElements elms = DocumentRelations.GetParent(this.textFrame) as DocumentElements; bool renderInParagraph = RenderInParagraph(); if (renderInParagraph) { StartDummyParagraph(); } StartShapeArea(); //Properties RenderNameValuePair("shapeType", "202");//202 entspr. Textrahmen. if (this.textFrame.IsNull("Elements") || !CollectionContainsObjectAssignableTo(this.textFrame.Elements, typeof(Shape), typeof(Table))) { } else { TextOrientation orient = this.textFrame.Orientation; if (orient != TextOrientation.Horizontal && orient != TextOrientation.HorizontalRotatedFarEast) { Trace.WriteLine(Messages.TextframeContentsNotTurned, "warning"); } } csvWriter.StartContent(); csvWriter.StartContent(); foreach (DocumentObject docObj in this.textFrame.Elements) { RendererBase rndrr = RendererFactory.CreateRenderer(docObj, this.docRenderer); if (rndrr != null) { rndrr.Render(); } } //Text fields need to close with a paragraph. RenderTrailingParagraph(this.textFrame.Elements); this.csvWriter.EndContent(); this.csvWriter.EndContent(); EndShapeArea(); if (renderInParagraph) { RenderLayoutPicture(); EndDummyParagraph(); } }
/// <summary> /// Renders an image to RTF. /// </summary> internal override void Render() { string fileName = Path.GetTempFileName(); if (!StoreTempImage(fileName)) { return; } bool renderInParagraph = RenderInParagraph(); DocumentElements elms = DocumentRelations.GetParent(_chart) as DocumentElements; if (elms != null && !renderInParagraph && !(DocumentRelations.GetParent(elms) is Section || DocumentRelations.GetParent(elms) is HeaderFooter)) { Debug.WriteLine(Messages2.ChartFreelyPlacedInWrongContext, "warning"); return; } if (renderInParagraph) { StartDummyParagraph(); } if (!_isInline) { StartShapeArea(); } RenderImage(fileName); if (!_isInline) { EndShapeArea(); } if (renderInParagraph) { EndDummyParagraph(); } if (File.Exists(fileName)) { File.Delete(fileName); } }
/// <summary> /// Renders the paragraph to CSV. /// </summary> internal override void Render() { useEffectiveValue = true; DocumentElements elements = DocumentRelations.GetParent(this.paragraph) as DocumentElements; bool isCellParagraph = DocumentRelations.GetParent(elements) is Cell; bool isFootnoteParagraph = isCellParagraph ? false : DocumentRelations.GetParent(elements) is Footnote; if (!this.paragraph.IsNull("Elements")) { RenderContent(); } if ((!isCellParagraph && !isFootnoteParagraph) || this.paragraph != elements.LastObject) { this.csvWriter.WriteNewLine(); } }
private bool RunDocumentValidityChecks() { // Assure that each element has a GUID and language child element foreach (var element in DocumentElements) { if (element.Element(XmlConstants.EntityGuid) == null) { element.Add(new XElement(XmlConstants.EntityGuid, "")); } if (element.Element(XmlConstants.EntityLanguage) == null) { element.Add(new XElement(XmlConstants.EntityLanguage, "")); } } var documentElementLanguagesAll = DocumentElements .GroupBy(element => element.Element(XmlConstants.EntityGuid)?.Value) .Select(group => @group .Select(element => element.Element(XmlConstants.EntityLanguage)?.Value) .ToList()) .ToList(); var documentElementLanguagesCount = documentElementLanguagesAll.Select(item => item.Count); if (documentElementLanguagesCount.Any(count => count != 1)) { // It is an all language import, so check if all languages are specified for all entities if (documentElementLanguagesAll.Any(lang => _languages.Except(lang).Any())) { ErrorLog.AppendError(ImportErrorCode.MissingElementLanguage, "Langs=" + string.Join(", ", _languages)); return(false); } } return(true); }
private bool LoadStreamIntoDocumentElement(Stream dataStream) { Document = XDocument.Load(dataStream); dataStream.Position = 0; if (Document == null) { ErrorLog.AppendError(ImportErrorCode.InvalidDocument); return(false); } var documentRoot = Document.Element(XmlConstants.Root); if (documentRoot == null) { throw new Exception("can't import - document doesn't have a root element"); } DocumentElements = documentRoot.Elements(XmlConstants.Entity).ToList(); if (!DocumentElements.Any()) { ErrorLog.AppendError(ImportErrorCode.InvalidDocument); return(false); } // Check the content type of the document (it can be found on each element in the Type attribute) var documentTypeAttribute = DocumentElements.First().Attribute(XmlConstants.EntityTypeAttribute); if (documentTypeAttribute?.Value == null || documentTypeAttribute.Value != ContentType.Name.RemoveSpecialCharacters()) { ErrorLog.AppendError(ImportErrorCode.InvalidRoot); return(false); } return(true); }
public override void VisitDocumentElements(DocumentElements elements) { }
/// <summary> /// Renders a trailing standard paragraph in case the last element in elements isn't a paragraph. /// (Some RTF elements need to close with a paragraph.) /// </summary> protected void RenderTrailingParagraph(DocumentElements elements) { }
internal virtual void VisitDocumentElements(DocumentElements elements) { }
internal TopDownFormatter(IAreaProvider areaProvider, DocumentRenderer documentRenderer, DocumentElements elements) { this.documentRenderer = documentRenderer; this.areaProvider = areaProvider; this.elements = elements; }
/// <summary> /// Parses one of the keywords «\document», «\styles», «\section», «\table», «\textframe», «\chart» /// and «\paragraph» and returns the corresponding DocumentObject or DocumentObjectCollection. /// </summary> internal DocumentObject ParseDocumentObject() { DocumentObject obj = null; MoveToCode(); switch (Symbol) { case Symbol.Document: obj = ParseDocument(null); break; case Symbol.Styles: obj = ParseStyles(new Styles()); break; case Symbol.Section: obj = ParseSection(new Sections()); break; case Symbol.Table: obj = new Table(); ParseTable(null, (Table)obj); break; case Symbol.TextFrame: DocumentElements elems = new DocumentElements(); ParseTextFrame(elems); obj = elems[0]; break; case Symbol.Chart: throw new NotImplementedException(); case Symbol.Paragraph: obj = new DocumentElements(); ParseParagraph((DocumentElements)obj); break; default: ThrowParserException(DomMsgID.UnexpectedSymbol); break; } ReadCode(); AssertCondition(Symbol == Symbol.Eof, DomMsgID.EndOfFileExpected); return obj; }
/// <summary> /// Parses the inner text of a paragraph, i.e. stops on BraceRight and treats empty /// line as paragraph separator. /// </summary> private void ParseParagraphContent(DocumentElements elements, Paragraph paragraph) { Paragraph para = paragraph ?? elements.AddParagraph(); while (para != null) { ParseFormattedText(para.Elements, 0); if (Symbol != Symbol.BraceRight && Symbol != Symbol.Eof) { para = elements.AddParagraph(); } else para = null; } }
/// <summary> /// Formats (measures) the table. /// </summary> /// <param name="area"> The area on which to fit the table. </param> /// <param name="previousFormatInfo"> </param> internal override void Format(Area area, FormatInfo previousFormatInfo) { DocumentElements elements = DocumentRelations.GetParent(_table) as DocumentElements; if (elements != null) { Section section = DocumentRelations.GetParent(elements) as Section; if (section != null) { _doHorizontalBreak = section.PageSetup.HorizontalPageBreak; } } _renderInfo = new TableRenderInfo(); InitFormat(area, previousFormatInfo); // Don't take any Rows higher then MaxElementHeight XUnit topHeight = CalcStartingHeight(); XUnit probeHeight = topHeight; XUnit offset; if (_startRow > _lastHeaderRow + 1 && _startRow < _table.Rows.Count) { offset = _bottomBorderMap[_startRow] - topHeight; } else { offset = -CalcMaxTopBorderWidth(0); } int probeRow = _startRow; XUnit currentHeight = 0; XUnit startingHeight = 0; bool isEmpty = false; while (probeRow < _table.Rows.Count) { bool firstProbe = probeRow == _startRow; probeRow = _connectedRowsMap[probeRow]; // Don't take any Rows higher then MaxElementHeight probeHeight = _bottomBorderMap[probeRow + 1] - offset; // First test whether MaxElementHeight has been set. if (MaxElementHeight > 0 && firstProbe && probeHeight > MaxElementHeight - Tolerance) { probeHeight = MaxElementHeight - Tolerance; } //if (firstProbe && probeHeight > MaxElementHeight - Tolerance) // probeHeight = MaxElementHeight - Tolerance; //The height for the first new row(s) + headerrows: if (startingHeight == 0) { if (probeHeight > area.Height) { isEmpty = true; break; } startingHeight = probeHeight; } if (probeHeight > area.Height) { break; } else { _currRow = probeRow; currentHeight = probeHeight; ++probeRow; } } if (!isEmpty) { TableFormatInfo formatInfo = (TableFormatInfo)_renderInfo.FormatInfo; formatInfo.StartRow = _startRow; formatInfo._isEnding = _currRow >= _table.Rows.Count - 1; formatInfo.EndRow = _currRow; UpdateThisPagesBookmarks(_startRow, _currRow); } FinishLayoutInfo(area, currentHeight, startingHeight); }
/// <summary> /// Parses the document elements of a «\paragraph», «\cell» or comparable. /// </summary> private DocumentElements ParseDocumentElements(DocumentElements elements, Symbol context) { // // This is clear: // \section { Hallo World! } // All section content will be treated as paragraph content. // // but this is ambiguous: // \section { \image(...) } // It could be an image inside a paragraph or at the section level. // In this case it will be treated as an image on section level. // // If this is not your intention it must be like this: // \section { \paragraph { \image(...) } } // while (TokenType == TokenType.KeyWord) { switch (Symbol) { case Symbol.Paragraph: ParseParagraph(elements); break; case Symbol.PageBreak: ParsePageBreak(elements); break; case Symbol.Table: ParseTable(elements, null); break; case Symbol.TextFrame: ParseTextFrame(elements); break; case Symbol.Image: ParseImage(elements.AddImage(""), false); break; case Symbol.Chart: ParseChart(elements); break; case Symbol.Barcode: ParseBarcode(elements); break; default: ThrowParserException(DomMsgID.UnexpectedSymbol, _scanner.Token); break; } } return elements; }
/// <summary> /// Parses the keyword «\chart». /// </summary> private void ParseChart(DocumentElements elements) { // Syntax: // 1. \chartarea(Type){...} // 2. \chartarea(Type)[...]{...} // // Usage of header-, bottom-, footer-, left- and rightarea are similar. ChartType chartType = 0; try { ReadCode(); // read '(' AssertSymbol(Symbol.ParenLeft, DomMsgID.MissingParenLeft, GetSymbolText(Symbol.Chart)); ReadCode(); // ChartType name AssertSymbol(Symbol.Identifier, DomMsgID.IdentifierExpected, Token); string chartTypeName = Token; ReadCode(); // read ')' AssertSymbol(Symbol.ParenRight, DomMsgID.MissingParenRight, GetSymbolText(Symbol.Chart)); try { chartType = (ChartType)Enum.Parse(typeof(ChartType), chartTypeName, true); } catch (Exception ex) { ThrowParserException(ex, DomMsgID.UnknownChartType, chartTypeName); } Chart chart = elements.AddChart(chartType); ReadCode(); if (Symbol == Symbol.BracketLeft) ParseAttributes(chart); AssertSymbol(Symbol.BraceLeft, DomMsgID.MissingBraceLeft, GetSymbolText(Symbol.Chart)); ReadCode(); // read beyond '{' bool fContinue = true; while (fContinue) { switch (Symbol) { case Symbol.Eof: ThrowParserException(DomMsgID.UnexpectedEndOfFile); break; case Symbol.BraceRight: fContinue = false; break; case Symbol.PlotArea: ParseArea(chart.PlotArea); break; case Symbol.HeaderArea: ParseArea(chart.HeaderArea); break; case Symbol.FooterArea: ParseArea(chart.FooterArea); break; case Symbol.TopArea: ParseArea(chart.TopArea); break; case Symbol.BottomArea: ParseArea(chart.BottomArea); break; case Symbol.LeftArea: ParseArea(chart.LeftArea); break; case Symbol.RightArea: ParseArea(chart.RightArea); break; case Symbol.XAxis: ParseAxes(chart.XAxis, Symbol); break; case Symbol.YAxis: ParseAxes(chart.YAxis, Symbol); break; case Symbol.ZAxis: ParseAxes(chart.ZAxis, Symbol); break; case Symbol.Series: ParseSeries(chart.SeriesCollection.AddSeries()); break; case Symbol.XValues: ParseSeries(chart.XValues.AddXSeries()); break; default: ThrowParserException(DomMsgID.UnexpectedSymbol, Token); break; } } ReadCode(); // read beyond '}' } catch (DdlParserException pe) { ReportParserException(pe); AdjustToNextBlock(); } }
private void ParseBarcode(DocumentElements elements) { // Syntax: // 1. \barcode(Code) // 2. \barcode(Code)[...] // 3. \barcode(Code, Type) // 4. \barcode(Code, Type)[...] try { ReadCode(); AssertSymbol(Symbol.ParenLeft, DomMsgID.MissingParenLeft, GetSymbolText(Symbol.Barcode)); ReadCode(); AssertSymbol(Symbol.StringLiteral, DomMsgID.UnexpectedSymbol); Barcode barcode = elements.AddBarcode(); barcode.SetValue("Code", Token); ReadCode(); if (Symbol == Symbol.Comma) { ReadCode(); AssertSymbol(Symbol.Identifier, DomMsgID.IdentifierExpected, Token); BarcodeType barcodeType = (BarcodeType)Enum.Parse(typeof(BarcodeType), Token, true); barcode.SetValue("type", barcodeType); ReadCode(); } AssertSymbol(Symbol.ParenRight, DomMsgID.MissingParenRight, GetSymbolText(Symbol.Barcode)); ReadCode(); if (Symbol == Symbol.BracketLeft) ParseAttributes(barcode); //barcode->ConsistencyCheck(mInfoHandler->Infos()); } catch (DdlParserException pe) { ReportParserException(pe); AdjustToNextBlock(); } }
public virtual void VisitDocumentElements(DocumentElements elements) { }
internal override void VisitDocumentElements(DocumentElements elements) { }
public TopDownFormatter(IAreaProvider areaProvider, DocumentRenderer documentRenderer, DocumentElements elements) { _documentRenderer = documentRenderer; _areaProvider = areaProvider; _elements = elements; }
/// <summary> /// Parses the keyword «\paragraph». /// </summary> private void ParseParagraph(DocumentElements elements) { MoveToCode(); AssertSymbol(Symbol.Paragraph); Paragraph paragraph = elements.AddParagraph(); try { ReadCode(); // read '[' or '{' if (Symbol == Symbol.BracketLeft) ParseAttributes(paragraph); // Empty paragraphs without braces are valid. if (Symbol == Symbol.BraceLeft) { ParseParagraphContent(elements, paragraph); AssertSymbol(Symbol.BraceRight); ReadCode(); // read beyond '}' } } catch (DdlParserException ex) { ReportParserException(ex); AdjustToNextBlock(); } }
/// <summary> /// Parses the keyword «\textframe». /// </summary> private void ParseTextFrame(DocumentElements elements) { Debug.Assert(elements != null); TextFrame textFrame = elements.AddTextFrame(); try { ReadCode(); if (_scanner.Symbol == Symbol.BracketLeft) ParseAttributes(textFrame); AssertSymbol(Symbol.BraceLeft); if (IsParagraphContent()) { ParseParagraphContent(textFrame.Elements, null); } else { ReadCode(); // read '{' ParseDocumentElements(textFrame.Elements, Symbol.TextFrame); } AssertSymbol(Symbol.BraceRight); ReadCode(); // read beyond '}' } catch (DdlParserException ex) { ReportParserException(ex); AdjustToNextBlock(); } }
/// <summary> /// Formats (measures) the table. /// </summary> /// <param name="area">The area on which to fit the table.</param> /// <param name="previousFormatInfo"></param> internal override void Format(Area area, FormatInfo previousFormatInfo) { DocumentElements elements = DocumentRelations.GetParent(this.table) as DocumentElements; if (elements != null) { Section section = DocumentRelations.GetParent(elements) as Section; if (section != null) { this.doHorizontalBreak = section.PageSetup.HorizontalPageBreak; } } this.renderInfo = new TableRenderInfo(); InitFormat(area, previousFormatInfo); // Don't take any Rows higher then MaxElementHeight XUnit topHeight = this.CalcStartingHeight(); XUnit probeHeight = topHeight; XUnit offset = 0; if (this.startRow > this.lastHeaderRow + 1 && this.startRow < this.table.Rows.Count) { offset = (XUnit)this.bottomBorderMap[this.startRow] - topHeight; } else { offset = -CalcMaxTopBorderWidth(0); } int probeRow = this.startRow; XUnit currentHeight = 0; XUnit startingHeight = 0; bool isEmpty = false; while (probeRow < this.table.Rows.Count) { bool firstProbe = probeRow == this.startRow; probeRow = (int)this.connectedRowsMap[probeRow]; // Don't take any Rows higher then MaxElementHeight probeHeight = (XUnit)this.bottomBorderMap[probeRow + 1] - offset; if (firstProbe && probeHeight > MaxElementHeight - Tolerance) { probeHeight = MaxElementHeight - Tolerance; } //The height for the first new row(s) + headerrows: if (startingHeight == 0) { if (probeHeight > area.Height) { isEmpty = true; break; } startingHeight = probeHeight; } if (probeHeight > area.Height) { break; } else { this.currRow = probeRow; currentHeight = probeHeight; ++probeRow; } } if (!isEmpty) { TableFormatInfo formatInfo = (TableFormatInfo)this.renderInfo.FormatInfo; formatInfo.startRow = this.startRow; formatInfo.isEnding = currRow >= this.table.Rows.Count - 1; formatInfo.endRow = this.currRow; } FinishLayoutInfo(area, currentHeight, startingHeight); }
/// <summary> /// Deserialize a 2sxc data xml stream to the memory. The data will also be checked for /// errors. /// </summary> /// <param name="dataStream">Data stream</param> private void ValidateAndImportToMemory(Stream dataStream) { try { if (languages == null || languages.Count() == 0) { languages = new string[] { string.Empty }; } if (contentType == null) { ErrorProtocol.AppendError(ImportErrorCode.InvalidContentType); return; } Document = XDocument.Load(dataStream); dataStream.Position = 0; if (Document == null) { ErrorProtocol.AppendError(ImportErrorCode.InvalidDocument); return; } var documentRoot = Document.Element(DocumentNodeNames.Root + contentType.Name.RemoveSpecialCharacters()); if (documentRoot == null) { ErrorProtocol.AppendError(ImportErrorCode.InvalidRoot); return; } DocumentElements = documentRoot.Elements(DocumentNodeNames.Entity); var documentElementNumber = 0; var documentElementLanguagesAll = DocumentElements.GroupBy(element => element.Element(DocumentNodeNames.EntityGuid).Value) .Select(group => group.Select(element => element.Element(DocumentNodeNames.EntityLanguage).Value)).ToList(); var documentElementLanguagesCount = documentElementLanguagesAll.Select(item => item.Count()); if (documentElementLanguagesCount.Any(count => count != 1)) { // It is an all language import, so check if all languages are specified for all entities foreach (var documentElementLanguages in documentElementLanguagesAll) { if (languages.Except(documentElementLanguages).Any()) { ErrorProtocol.AppendError(ImportErrorCode.MissingElementLanguage, "Langs=" + string.Join(", ", languages)); return; } } } var entityGuidManager = new EntityGuidManager(); foreach (var documentElement in DocumentElements) { documentElementNumber++; var documentElementLanguage = documentElement.GetChildElementValue(DocumentNodeNames.EntityLanguage); if (!languages.Any(language => language == documentElementLanguage)) { // DNN does not support the language ErrorProtocol.AppendError(ImportErrorCode.InvalidLanguage, "Lang=" + documentElementLanguage, documentElementNumber); continue; } var entityGuid = entityGuidManager.GetGuid(documentElement, documentLanguageFallback); var entity = GetEntity(entityGuid); if (entity == null) { entity = AppendEntity(entityGuid); } var attributes = contentType.GetAttributes(); foreach (var attribute in attributes) { var valueName = attribute.StaticName; var value = documentElement.GetChildElementValue(valueName); if (value == null || value.IsValueDefault()) { continue; } var valueType = attribute.Type; var valueReferenceLanguage = value.GetValueReferenceLanguage(); if (valueReferenceLanguage == null) { // It is not a value reference.. it is a normal text try { entity.AppendAttributeValue(valueName, value, valueType, documentElementLanguage, false, resourceReference.IsResolve()); } catch (FormatException) { ErrorProtocol.AppendError(ImportErrorCode.InvalidValueFormat, valueName + ":" + valueType + "=" + value, documentElementNumber); } continue; } var valueReferenceProtection = value.GetValueReferenceProtection(); if (valueReferenceProtection != "rw" && valueReferenceProtection != "ro") { ErrorProtocol.AppendError(ImportErrorCode.InvalidValueReferenceProtection, value, documentElementNumber); continue; } var valueReadOnly = valueReferenceProtection == "ro"; var entityValue = entity.GetAttributeValue(valueName, valueReferenceLanguage); if (entityValue != null) { entityValue.AppendLanguageReference(documentElementLanguage, valueReadOnly); continue; } // We do not have the value referenced in memory, so search for the // value in the database var dbEntity = contentType.GetEntity(entityGuid); if (dbEntity == null) { ErrorProtocol.AppendError(ImportErrorCode.InvalidValueReference, value, documentElementNumber); continue; } var dbEntityValue = dbEntity.GetAttributeValue(attribute, valueReferenceLanguage); if (dbEntityValue == null) { ErrorProtocol.AppendError(ImportErrorCode.InvalidValueReference, value, documentElementNumber); continue; } entity.AppendAttributeValue(valueName, dbEntityValue.Value, valueType, valueReferenceLanguage, dbEntityValue.IsLanguageReadOnly(valueReferenceLanguage), resourceReference.IsResolve()) .AppendLanguageReference(documentElementLanguage, valueReadOnly); } } } catch (Exception exception) { ErrorProtocol.AppendError(ImportErrorCode.Unknown, exception.ToString()); } }
private DocumentObject GetDocumentElementHolder(DocumentObject docObj) { DocumentElements docEls = (DocumentElements)docObj._parent; return(docEls._parent); }
/// <summary> /// Parses a page break in a document elements container. /// </summary> private void ParsePageBreak(DocumentElements elements) { AssertSymbol(Symbol.PageBreak); elements.AddPageBreak(); ReadCode(); }
/// <summary> /// Parses the keyword «\table». /// </summary> private void ParseTable(DocumentElements elements, Table table) { Table tbl = table; try { if (tbl == null) tbl = elements.AddTable(); MoveToCode(); AssertSymbol(Symbol.Table); ReadCode(); if (_scanner.Symbol == Symbol.BracketLeft) ParseAttributes(tbl); AssertSymbol(Symbol.BraceLeft); ReadCode(); // Table must start with «\columns»... AssertSymbol(Symbol.Columns); ParseColumns(tbl); // ...followed by «\rows». AssertSymbol(Symbol.Rows); ParseRows(tbl); AssertSymbol(Symbol.BraceRight); ReadCode(); // read beyond '}' } catch (DdlParserException ex) { ReportParserException(ex); AdjustToNextBlock(); } }