void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target) { switch (connectionId) { case 1: this.fdcv = ((System.Windows.Controls.FlowDocumentScrollViewer)(target)); #line 11 "..\..\..\documentViewer.xaml" this.fdcv.SizeChanged += new System.Windows.SizeChangedEventHandler(this.Fdcv_SizeChanged); #line default #line hidden return; case 2: this.fdMain = ((System.Windows.Documents.FlowDocument)(target)); return; case 3: this.table = ((System.Windows.Documents.Table)(target)); return; case 4: this.row = ((System.Windows.Documents.TableRow)(target)); return; case 5: this.run = ((System.Windows.Documents.Run)(target)); return; } this._contentLoaded = true; }
/// <summary> /// The write table. /// </summary> /// <param name="t"> /// The t. /// </param> public void WriteTable(Table t) { var p = new System.Windows.Documents.Paragraph(); var figure = new Figure(); var table = new System.Windows.Documents.Table(); // if (t.HasHeader()) // { // var trg1 = new TableRowGroup(); // SetStyle(trg1, Style.TableHeaderStyle); // var r = new TableRow(); // foreach (var c in columns) // { // var cell = new TableCell(); // var run = new Run() { Text = c.Header }; // cell.Blocks.Add(new System.Windows.Documents.Paragraph(run)); // r.Cells.Add(cell); // } // trg1.Rows.Add(r); // table.RowGroups.Add(trg1); // } var trg2 = new TableRowGroup(); // SetStyle(trg2, Style.TableTextStyle); foreach (var row in t.Rows) { var r = new TableRow(); if (row.IsHeader) { SetStyle(r, row.IsHeader ? this.Style.TableHeaderStyle : this.Style.TableTextStyle); } for (int j = 0; j < t.Columns.Count; j++) { TableCell c = row.Cells[j]; var cell = new System.Windows.Documents.TableCell(); var run = new Run { Text = c.Content }; cell.Blocks.Add(new System.Windows.Documents.Paragraph(run)); r.Cells.Add(cell); } trg2.Rows.Add(r); } table.RowGroups.Add(trg2); figure.Blocks.Add(this.CreateParagraph(t.Caption, this.Style.FigureTextStyle)); figure.Blocks.Add(table); p.Inlines.Add(figure); this.doc.Blocks.Add(p); }
void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target) { switch (connectionId) { case 1: this.TableRowTest = ((System.Windows.Documents.TableRow)(target)); return; case 2: this.MercuryZelle = ((System.Windows.Documents.TableCell)(target)); return; } this._contentLoaded = true; }
/// <summary> /// Renders DOM text elements recursively, i.e. including their childs. /// </summary> /// <param name="e">The root DOM text element.</param> /// <returns>The corresponding Wpf element.</returns> /// <exception cref="System.InvalidOperationException"> /// </exception> /// <exception cref="System.NotImplementedException"></exception> public object RenderRecursively(TextElement e) { object wpf = null; switch (e) { case BlockUIContainer buc: { wpf = new swd.BlockUIContainer(); } break; case FlowDocument flowDocument: { // make sure the standard colors were set flowDocument.Foreground = ExCSS.Color.Black; flowDocument.Background = ExCSS.Color.White; var flowDocumente = new swd.FlowDocument() { Name = NameOfFlowDocument }; if (TemplateBindingViewportWidth is null) { TemplateBindingViewportWidth = new Binding("ColumnWidth") { Source = flowDocumente } } ; if (TemplateBindingViewportHeight is null) { TemplateBindingViewportHeight = new Binding("ColumnWidth") { Source = flowDocumente } } ; // Binding to ColumnWidth is not optimal, but better than nothing! if (flowDocument.Background.HasValue) { flowDocumente.Background = GetBrushFromColor(flowDocument.Background.Value); } if (flowDocument.Foreground.HasValue) { flowDocumente.Foreground = GetBrushFromColor(flowDocument.Foreground.Value); } wpf = flowDocumente; } break; case Hyperlink hl: { var hle = new swd.Hyperlink(); if (!string.IsNullOrEmpty(hl.NavigateUri)) { if (System.Uri.TryCreate(hl.NavigateUri, UriKind.RelativeOrAbsolute, out var uri)) { hle.NavigateUri = uri; } } if (!string.IsNullOrEmpty(hl.TargetName)) { hle.TargetName = hl.TargetName; } wpf = hle; } break; case Image image: { var imagee = new System.Windows.Controls.Image(); if (!string.IsNullOrEmpty(image.Source)) { imagee.SetBinding(System.Windows.Controls.Image.SourceProperty, $"ImageProvider[{image.Source}]"); } if (image.Width == null && image.Height == null) { imagee.Stretch = System.Windows.Media.Stretch.Uniform; var binding = new Binding() { RelativeSource = RelativeSource.Self, Path = new System.Windows.PropertyPath("Source") }; binding.Converter = ImageToImageWidthConverter.Instance; imagee.SetBinding(System.Windows.Controls.Image.WidthProperty, binding); } else { imagee.Stretch = System.Windows.Media.Stretch.Uniform; } if (image.Width != null) { if (image.Width.IsPurelyAbsolute(out var widthPx)) { imagee.Width = widthPx; } else { var multibinding = new MultiBinding(); multibinding.Bindings.Add(new Binding() { Source = TemplateBindingViewportWidth.Source, Path = TemplateBindingViewportWidth.Path }); multibinding.Bindings.Add(new Binding() { Source = TemplateBindingViewportHeight.Source, Path = TemplateBindingViewportHeight.Path }); multibinding.Converter = CompoundLengthConverter.Instance; multibinding.ConverterParameter = GetCompoundLengthConverterParameters(image.Width); imagee.SetBinding(System.Windows.Controls.Image.WidthProperty, multibinding); } } if (image.Height != null) { if (image.Height.IsPurelyAbsolute(out var heightPx)) { imagee.Height = heightPx; } else { var multibinding = new MultiBinding(); multibinding.Bindings.Add(new Binding() { Source = TemplateBindingViewportWidth.Source, Path = TemplateBindingViewportWidth.Path }); multibinding.Bindings.Add(new Binding() { Source = TemplateBindingViewportHeight.Source, Path = TemplateBindingViewportHeight.Path }); multibinding.Converter = CompoundLengthConverter.Instance; multibinding.ConverterParameter = GetCompoundLengthConverterParameters(image.Height); imagee.SetBinding(System.Windows.Controls.Image.HeightProperty, multibinding); } } // set max-width and max-height if (image.MaxWidth != null && image.MaxWidth.Value.IsAbsolute) { imagee.MaxWidth = image.MaxWidth.Value.ToPixel(); } else if (image.MaxWidth == null || image.MaxWidth.Value.Type == ExCSS.Length.Unit.Vw) { double vwValue = image.MaxWidth.HasValue ? image.MaxWidth.Value.Value : 100; var binding = new Binding() { Source = TemplateBindingViewportWidth.Source, Path = TemplateBindingViewportWidth.Path }; binding.Converter = RelativeSizeConverter.Instance; binding.ConverterParameter = vwValue; imagee.SetBinding(System.Windows.Controls.Image.MaxWidthProperty, binding); } else { throw new InvalidProgramException(); } if (image.MaxHeight != null && image.MaxHeight.Value.IsAbsolute) { imagee.MaxHeight = image.MaxHeight.Value.ToPixel(); } else if (image.MaxHeight == null || image.MaxHeight.Value.Type == ExCSS.Length.Unit.Vh) { double vhValue = image.MaxHeight.HasValue ? image.MaxHeight.Value.Value : 100; var binding = new Binding() { Source = TemplateBindingViewportWidth.Source, Path = TemplateBindingViewportWidth.Path }; binding.Converter = RelativeSizeConverter.Instance; binding.ConverterParameter = vhValue; imagee.SetBinding(System.Windows.Controls.Image.MaxHeightProperty, binding); } else { throw new InvalidProgramException(); } wpf = imagee; } break; case InlineUIContainer iuc: { var inlineuiContainere = new swd.InlineUIContainer(); wpf = inlineuiContainere; } break; case LineBreak lb: { wpf = new swd.LineBreak(); } break; case List list: { var liste = new swd.List(); if (list.MarkerStyle.HasValue) { liste.MarkerStyle = ToMarkerStyle(list.MarkerStyle.Value); } wpf = liste; } break; case ListItem li: { wpf = new swd.ListItem(); } break; case Paragraph p: { var pe = new swd.Paragraph(); if (p.TextDecorations.HasValue) { pe.TextDecorations = ToTextDecorations(p.TextDecorations.Value); } if (p.TextIndent.HasValue) { pe.TextIndent = p.TextIndent.Value.IsAbsolute ? p.TextIndent.Value.ToPixel() : 0; } wpf = pe; } break; case Run run: { if (SplitIntoWords) { wpf = CreateTextElement_SeparateWords(run.Text); } else if (SplitIntoSentences) { wpf = CreateTextElement_SeparateSentences(run.Text); } else { wpf = new swd.Run(run.Text); } } break; case Section s: { wpf = new swd.Section(); } break; case Span span: { wpf = new swd.Span(); } break; case Table tb: { var tbe = new swd.Table(); foreach (var c in tb.Columns) { if (c.Width.HasValue) { tbe.Columns.Add(new swd.TableColumn() { Width = new System.Windows.GridLength(c.Width.Value) }); } else { tbe.Columns.Add(new swd.TableColumn()); } } wpf = tbe; } break; case TableCell tc: { var tce = new swd.TableCell(); if (1 != tc.ColumnSpan) { tce.ColumnSpan = tc.ColumnSpan; } if (1 != tc.RowSpan) { tce.RowSpan = tc.RowSpan; } if (tc.BorderBrush.HasValue) { tce.BorderBrush = new System.Windows.Media.SolidColorBrush(ToColor(tc.BorderBrush.Value)); } if (tc.BorderThickness.HasValue) { tce.BorderThickness = ToThickness(tc.BorderThickness.Value); } wpf = tce; } break; case TableRow trow: { wpf = new swd.TableRow(); } break; case TableRowGroup trg: { wpf = new swd.TableRowGroup(); } break; default: { wpf = null; } break; } // Render TextElement properties if (wpf is swd.TextElement te) { if (!string.IsNullOrEmpty(e.FontFamily)) { te.FontFamily = GetFontFamily(e.FontFamily); } if (e.FontSize.HasValue) { var fs = e.FontSize.Value; fs = Math.Max(0.004, fs); te.FontSize = fs; } if (e.FontStyle.HasValue) { te.FontStyle = ToFontStyle(e.FontStyle.Value); } if (e.FontWeight.HasValue) { te.FontWeight = ToFontWeight(e.FontWeight.Value); } if (e.Foreground.HasValue && e.Foreground != e.ForegroundInheritedOnly) { te.Foreground = GetBrushFromColor(e.Foreground.Value); } if (e.Background.HasValue && e.Background != e.BackgroundInheritedOnly) { te.Background = GetBrushFromColor(e.Background.Value); } } // now special properties if (e is Block b && wpf is swd.Block be) { if (b.Margin.HasValue) { be.Margin = ToThickness(b.Margin.Value); } if (b.Padding.HasValue) { be.Padding = ToThickness(b.Padding.Value); } if (b.BorderBrush.HasValue) { be.BorderBrush = new System.Windows.Media.SolidColorBrush(ToColor(b.BorderBrush.Value)); } if (b.BorderThickness.HasValue) { be.BorderThickness = ToThickness(b.BorderThickness.Value); } if (b.TextAlignment.HasValue) { be.TextAlignment = ToTextAlignment(b.TextAlignment.Value); } if (b.LineHeight.HasValue) { be.LineHeight = b.LineHeight.Value; } } if (e is Inline i && wpf is swd.Inline ie) { if (i.VerticalAlignment.HasValue) { ie.BaselineAlignment = ToBaselineAlignment(i.VerticalAlignment.Value); } } // finished rendering the attributes // now, render all children foreach (var child in e.Childs) { var childe = RenderRecursively(child); switch (wpf) { case swd.Figure figure: figure.Blocks.Add((swd.Block)childe); break; case swd.Floater floater: floater.Blocks.Add((swd.Block)childe); break; case swd.FlowDocument flowDocument: flowDocument.Blocks.Add((swd.Block)childe); break; case swd.List list: list.ListItems.Add((swd.ListItem)childe); break; case swd.ListItem listItem: listItem.Blocks.Add((swd.Block)childe); break; case swd.Section section: section.Blocks.Add((swd.Block)childe); break; case swd.Table table: table.RowGroups.Add((swd.TableRowGroup)childe); break; case swd.TableCell tableCell: tableCell.Blocks.Add((swd.Block)childe); break; case swd.TableRow tableRow: tableRow.Cells.Add((swd.TableCell)childe); break; case swd.TableRowGroup tableRowGroup: tableRowGroup.Rows.Add((swd.TableRow)childe); break; // now elements that can contain inlines case swd.Paragraph paragraph: paragraph.Inlines.Add((swd.Inline)childe); break; case swd.Span span: span.Inlines.Add((swd.Inline)childe); break; // now some specialties case swd.InlineUIContainer inlineUIContainer: if (inlineUIContainer.Child != null) { throw new InvalidOperationException($"{nameof(swd.InlineUIContainer)} can not contain more than one child"); } inlineUIContainer.Child = (System.Windows.UIElement)childe; break; case swd.BlockUIContainer blockUIContainer: if (blockUIContainer.Child != null) { throw new InvalidOperationException($"{nameof(swd.BlockUIContainer)} can not contain more than one child"); } blockUIContainer.Child = (System.Windows.UIElement)childe; break; default: throw new NotImplementedException(); } } if (AttachDomAsTags) { if (wpf is System.Windows.FrameworkContentElement conEle) { conEle.Tag = e; } else if (wpf is System.Windows.FrameworkElement uiEle) { uiEle.Tag = e; } } return(wpf); }