Alright, how do I start this?

I have an application which is able to draw some shapes (actually it's a few thousand) on the screen. There are two types of them: Rectangles and Lines. Rectangles have a Fill, Lines have a Stroke + StrokeThickness.

I read data from two files, one has the data for the top side, one for the bottom side. To display the data, I use a Viewbox with a Canvas inside (so the contents are nicely stretched). The whole thing on the display looks like this (this is correct):

Top on Screen Bottom on Screen

Now the very same application is supposed to print this image to a Printer (for testing I use the XPS Printer that comes with Windows).

When I print it (code follows), it gives for top the very same drawing, but for bottom the following:

Bottom on Printout

It looks like all "lines" are missing (the rectangles exist). To display the bottom, I use a scale transform with -1/-1 (mirror it horizontally as well as vertically). If I set the scale transform to 1/1 I get the following:

Bottom - Non mirrored

Now I am stuck. Why do all the lines disappear, but they are there if it's not mirrored. Also the outermost rectangle is a little bit shifted (this could be due to the data, so please don't focus on that).

The code that I use for drawing on screen is:

                <Viewbox Grid.Row="0" RenderTransform="{Binding RenderTransform}" Margin="20" Name="VwBox">
                <Viewbox.RenderTransformOrigin>
                    <Point X="0.5" Y="0.5"></Point>
                </Viewbox.RenderTransformOrigin>
                <ItemsControl ItemsSource="{Binding Drawing}" ItemTemplateSelector="{StaticResource DataTypeTemplateSelector}">
                    <ItemsControl.ItemsPanel>
                        <ItemsPanelTemplate>
                            <Canvas Width="{Binding DrawingWidth}" Height="{Binding DrawingHeight}">
                            </Canvas>
                        </ItemsPanelTemplate>
                    </ItemsControl.ItemsPanel>

                    <ItemsControl.ItemContainerStyle>
                        <Style TargetType="ContentPresenter">
                            <Setter Property="Canvas.Left" Value="{Binding Left}"/>
                            <Setter Property="Canvas.Top" Value="{Binding Top}"/>
                        </Style>
                    </ItemsControl.ItemContainerStyle>
                </ItemsControl>
            </Viewbox>

For printing I do not rely on XAMl, but do it manually (it doesn't change a thing if I use the ContentPresenter or not):

                if (gs is GerberLine)
            {                   
                ContentPresenter cp = new ContentPresenter();
                var line = new Line();
                Canvas.SetLeft(cp, gs.Left);
                Canvas.SetTop(cp, gs.Top);
                line.X1 = 0.0;
                line.Y1 = 0.0;
                line.X2 = gs.Width;
                line.Y2 = gs.Height;
                line.Stroke = gs.Brush;
                line.StrokeThickness = ((GerberLine)gs).StrokeThickness;
                cp.Content = line;
                c.Children.Add(cp);
            }
            if (gs is GerberRect)
            {
                var r = new Rectangle();
                Canvas.SetLeft(r, gs.Left);
                Canvas.SetTop(r, gs.Top);
                r.Width = gs.Width;
                r.Height = gs.Height;
                r.Fill = gs.Brush;
                c.Children.Add(r);
            }

It looks like the lines do only disappear as soon as I mirror it horizontally since the top view is always correct (and it is mirrored vertically as well).

Any ideas? I'll be happy to elaborate if something is unclear. I think it has something to do with the scale transform, but I don't understand how (also why does it work on screen then?).

有帮助吗?

解决方案

Here is what I would try:

  1. Maybe the XPS driver in particular does not like the negative scaling. Test with a different printer (PDF output or a real printer).

  2. Use Rotate(180) instead of Scale(-1,-1).

  3. After building your target document for print, rasterize it with RenderTargetBitmap , save the resulting bitmap, and see if that looks as expected.

  4. Create a minimal Gerber model and send that through the XPS code path. Rename the .xps to .zip, and inspect the XML directly (it will be in Documents\1\Pages\1.fpage or something similar).

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top