/// <summary> /// Flatten Primitive to ILegacyDevice /// </summary> public static void Convert(Primitive tree, ILegacyDevice dc, double width, double height, double dpix, double dpiy, Nullable <OutputQuality> quality) { // Change Flattener quality setting based on OutputQualityValue if (quality != null) { switch (quality) { case OutputQuality.Unknown: case OutputQuality.Automatic: break; case OutputQuality.Draft: case OutputQuality.Fax: case OutputQuality.Text: Configuration.RasterizationDPI = 96; Configuration.MaximumTransparencyLayer = 8; Configuration.GradientDecompositionDensity = 0.75; Configuration.DecompositionDepth = 2; break; case OutputQuality.Normal: Configuration.RasterizationDPI = 150; Configuration.MaximumTransparencyLayer = 12; Configuration.GradientDecompositionDensity = 1; Configuration.DecompositionDepth = 3; break; case OutputQuality.High: Configuration.RasterizationDPI = 300; Configuration.MaximumTransparencyLayer = 16; Configuration.GradientDecompositionDensity = 1.25; Configuration.DecompositionDepth = 4; break; case OutputQuality.Photographic: uint dcDpi = Math.Max(PrintQueue.GetDpiX(dc), PrintQueue.GetDpiY(dc)); Configuration.RasterizationDPI = (int)(Math.Max(dcDpi, 300)); Configuration.MaximumTransparencyLayer = 16; Configuration.GradientDecompositionDensity = 1.25; Configuration.DecompositionDepth = 4; break; } } #if DEBUG if (Configuration.Verbose >= 2) { Console.WriteLine(); Console.WriteLine("\r\nStage 1: Tree Flattening"); Console.WriteLine(); } #endif // Paper dimension as clipping Geometry clip = null; if ((width != 0) && (height != 0)) { clip = new RectangleGeometry(new Rect(0, 0, width, height)); } // Transform to device resolution Matrix transform = Matrix.Identity; transform.Scale(dpix / 96, dpiy / 96); Flattener fl = new Flattener(false, width, height); Toolbox.EmitEvent(EventTrace.Event.WClientDRXTreeFlattenBegin); fl.TreeFlatten(tree, clip, transform, 1.0, null); Toolbox.EmitEvent(EventTrace.Event.WClientDRXTreeFlattenEnd); Toolbox.EmitEvent(EventTrace.Event.WClientDRXAlphaFlattenBegin); fl.AlphaFlatten(new BrushProxyDecomposer(dc), false); Toolbox.EmitEvent(EventTrace.Event.WClientDRXAlphaFlattenEnd); #if DEBUG if (Configuration.Verbose >= 2) { Console.WriteLine(); Console.WriteLine("End AlphaFlattening"); Console.WriteLine(); } #endif }