Exemplo n.º 1
0
        private void ShowFlowDocument(HtmlToFlowDocument.Dom.FlowDocument flowDocument, Dictionary <string, string> fontDictionary)
        {
            if (null != flowDocument)
            {
                var renderer = new HtmlToFlowDocument.Rendering.WpfRenderer()
                {
                    InvertColors = Controller.IsBookInDarkMode, AttachDomAsTags = true, FontDictionary = fontDictionary
                };
                renderer.TemplateBindingViewportWidth = new Binding(nameof(ViewPortProperties.Width))
                {
                    Source = _viewPortProperties
                };
                renderer.TemplateBindingViewportHeight = new Binding(nameof(ViewPortProperties.Height))
                {
                    Source = _viewPortProperties
                };

                var flowDocumentE = renderer.Render(flowDocument);

                flowDocumentE.IsColumnWidthFlexible = false;

                // var binding1 = new Binding("ActualWidth") { Source = _guiViewer };
                // flowDocumentE.SetBinding(FlowDocument.ColumnWidthProperty, binding1); // Make sure the ColumnWidth property is same as the actual width of the flow document

                // Note: binding ActualHeight to PageHeight seems not a good idea,
                // since the Zoom have to be taken into account. Otherwise zooming to increase font size will no longer work

                _guiViewer.Document = flowDocumentE;

                flowDocumentE.ColumnWidth = double.MaxValue;
                flowDocumentE.ColumnGap   = 0;                // ColumnWidth=infinity and columngap=0 are neccessary to span the text to a maximum width
                flowDocumentE.PagePadding = new Thickness(8); // set page padding to zero instead of auto


                CalculateViewPortProperties();
            }
            else
            {
                _guiViewer.Document = null;
            }
        }
Exemplo n.º 2
0
        public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
        {
            if (values?.Length > 0 && values[0] is HtmlToFlowDocument.Dom.FlowDocument doc)
            {
                if (null == _renderer)
                {
                    _renderer = new HtmlToFlowDocument.Rendering.WpfRenderer();
                }

                if (values?.Length > 1 && values[1] is bool isInDarkMode)
                {
                    _renderer.InvertColors = isInDarkMode;
                }


                return(_renderer.Render(doc));
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 3
0
        private void ShowFlowDocument(HtmlToFlowDocument.Dom.FlowDocument flowDocument, Dictionary <string, string> fontDictionary)
        {
            if (null != flowDocument)
            {
                var renderer = new HtmlToFlowDocument.Rendering.WpfRenderer()
                {
                    InvertColors = Controller.IsBookInDarkMode, AttachDomAsTags = true, FontDictionary = fontDictionary
                };
                var flowDocumentE = renderer.Render(flowDocument);

                flowDocumentE.IsColumnWidthFlexible = false;

                var binding = new Binding("ActualWidth")
                {
                    Source = _guiViewer
                };
                flowDocumentE.SetBinding(FlowDocument.ColumnWidthProperty, binding); // Make sure the ColumnWidth property is same as the actual width of the flow document
                _guiViewer.Document = flowDocumentE;
            }
            else
            {
                _guiViewer.Document = null;
            }
        }