PDFsharp & MigraDoc Foundation https://forum.pdfsharp.net/ |
|
Everything is offset by 1.333 when not doing pop https://forum.pdfsharp.net/viewtopic.php?f=2&t=3941 |
Page 1 of 1 |
Author: | karl.wolf [ Fri Apr 05, 2019 6:20 am ] | |||
Post subject: | Everything is offset by 1.333 when not doing pop | |||
Code for the mainwindow: Code: public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); Render(); } void Render() { double A4Width = XUnit.FromCentimeter(21).Point; double A4Height = XUnit.FromCentimeter(29.7).Point; FixedDocument fixedDocument = new FixedDocument(); var size = new Size(A4Height, A4Width); fixedDocument.DocumentPaginator.PageSize = size; DrawingVisual dv = new DrawingVisual(); DrawingContext dc = dv.RenderOpen(); XGraphics gfx = XGraphics.FromDrawingContext(dc, new XSize(size.Width, size.Height), XGraphicsUnit.Point); // FIXME: Seems everything is off by factor 1.333 if I do not pop here (or scale by 1.0/1.33), which is exactly what is in the DefaultViewMatrix of the gfx //dc.Pop(); RenderDocument(gfx, gfx.PageSize); dc.Close(); // Create page content UIElement visual = new DrawingVisualPresenter(dv); FixedPage fixedPage = new FixedPage { Background = new SolidColorBrush(System.Windows.Media.Color.FromRgb(0xFE, 0xFE, 0xFE)) }; fixedPage.Children.Add(visual); PageContent pageContent = new PageContent { Child = fixedPage, }; fixedDocument.Pages.Add(pageContent); Viewer.Document = fixedDocument; } void RenderDocument(XGraphics gfx, XSize size) { //Rectangle for presentation var container = gfx.BeginContainer(); //Would solve the problem, but why is there a 1.33 factor??? //gfx.ScaleTransform(1.0 / 1.33, 1 / 1.33); XRect rect = new XRect(new XPoint(), gfx.PageSize); rect.Inflate(-50, -50); gfx.DrawRectangle(XPens.Blue, rect); } } Xaml window code: Code: <Window x:Class="WPF_Projekt.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:WPF_Projekt" mc:Ignorable="d" Title="MainWindow" Height="1080" Width="1920"> <Grid> <DocumentViewer Panel.ZIndex="0" Grid.Row="1" Grid.Column="0" x:Name="Viewer"/> </Grid> </Window> Ass mentioned in the commented code. There is a 1.333 factor offset on everthing, when I am not doing dc.pop(). Why is that the case?
|
Page 1 of 1 | All times are UTC |
Powered by phpBB® Forum Software © phpBB Group https://www.phpbb.com/ |