Esempio n. 1
0
        private InternalPrintTicket DevModeToPrintTicket(DevMode devmode, PrintTicketScope scope, DevModeFields supportedFields)
        {
            InternalPrintTicket resultTicket = new InternalPrintTicket();

            PrintSchemaShim.TryEmbedDevMode(resultTicket, this.OemDriverNamespace, devmode);
            PrintSchemaShim.CopyDevModeToTicket(resultTicket, devmode, scope, supportedFields);
            return(resultTicket);
        }
        /// <summary>
        /// Print Schema Reference Guide v1.0 Appendix E.3.8 - Page Media Size
        /// </summary>
        public void WritePageMediaSizeFeature(
            IList <short> paperSizeCodes,
            IList <string> paperSizeDisplayNames,
            IList <DC_PAPER_SIZE> paperSizes)
        {
            if (paperSizeCodes.Count > 0)
            {
                WriteStartFeature(
                    PrintSchemaNamespaces.StandardKeywordSet, "PageMediaSize",
                    PrintSchemaNamespaces.StandardKeywordSet, "PickOne",
                    COMPSTUISR.IDS_CPSUI_FORMNAME);
                {
                    for (int i = 0; i < paperSizeCodes.Count; i++)
                    {
                        string            optionNamespace = null;
                        string            optionLocalName = null;
                        PageMediaSizeName mediaSizeEnum;
                        if (PrintSchemaShim.TryGetPageMediaSizeNameFromPaperSizeCode(paperSizeCodes[i], out mediaSizeEnum))
                        {
                            optionNamespace = PrintSchemaNamespaces.StandardKeywordSet;
                            optionLocalName = mediaSizeEnum.ToString(CultureInfo.InvariantCulture);
                        }
                        else
                        {
                            optionNamespace = this._privateNamespace;
                            optionLocalName = null;
                        }


                        if (optionLocalName != null &&
                            ((i < paperSizeDisplayNames.Count) || (i < paperSizes.Count)))
                        {
                            string optionDisplayName = (i < paperSizeDisplayNames.Count) ? paperSizeDisplayNames[i] : null;
                            WriteStartOption(optionNamespace, optionLocalName, optionDisplayName, "None");
                            {
                                if (i < paperSizes.Count)
                                {
                                    WriteStartScoredProperty(PrintSchemaNamespaces.StandardKeywordSet, "MediaSizeWidth");
                                    {
                                        WriteValue("xsd:integer", XmlConvert.ToString(paperSizes[i].Width));
                                    }
                                    WriteEndScoredProperty();

                                    WriteStartScoredProperty(PrintSchemaNamespaces.StandardKeywordSet, "MediaSizeHeight");
                                    {
                                        WriteValue("xsd:integer", XmlConvert.ToString(paperSizes[i].Height));
                                    }
                                    WriteEndScoredProperty();
                                }
                            }
                            WriteEndOption();
                        }
                    }
                }
                WriteEndFeature();
            }
        }
Esempio n. 3
0
        private bool Validate(DevMode devMode)
        {
            bool settingsChanged = false;

            // Create a copy of the devmode before validating... if anything
            // changes, then we'll report it
            DevMode originalDevMode = devMode.Clone();

            // Validate the DEVMODE via a call to the driver.
            SetDocumentProperties(devMode.ByteData, true);

            // Compare the devmods to decide whether any features
            // changed.  Ignore changes in the DM_FORMNAME field
            // because the shim may clear it in selecting a paper size.

            // If other paper size fields are set in the DEVMODE, ignore the form field
            // because some driver change set / clear the form field during DocumentProperties
            // without actually changing the selected paper size.
            if (originalDevMode.IsAnyFieldSet(DevModeFields.DM_PAPERWIDTH | DevModeFields.DM_PAPERLENGTH | DevModeFields.DM_PAPERSIZE))
            {
                originalDevMode.Fields  &= ~DevModeFields.DM_FORMNAME;
                originalDevMode.Fields  |= devMode.Fields & DevModeFields.DM_FORMNAME;
                originalDevMode.FormName = devMode.FormName;
            }

            // Ignore device name in the original DEVMODE.  Copy the full buffer so that any extra
            // garbage in the device name after the string also matches.  The device name isn't actually
            // a setting per-se.  Version changes should be noted, because the same content may mean different
            // things in different versions of a driver.
            originalDevMode.DeviceName = devMode.DeviceName;

            // Do the actual comparison.  Note that if there are issues in the private DEVMODE similar
            // to the issues fixed up in the public DEVMODE, there may be false positive return values
            // from this API.  There's no way to fix this issue.
            for (int i = 0; i < originalDevMode.ByteData.Length; i++)
            {
                if (originalDevMode.ByteData[i] != devMode.ByteData[i])
                {
                    settingsChanged = true;
                }
            }

            WinSpoolPrinterCapabilities capabilities = GetCapabilities(null);

            try
            {
                PrintSchemaShim.PruneFeatures(devMode, capabilities);
            }
            finally
            {
                capabilities.Release();
            }

            return(settingsChanged);
        }
Esempio n. 4
0
        private void PrintTicketToDevMode(DevMode devMode, InternalPrintTicket ticket, PrintTicketScope scope, DevModeFields supportedFields)
        {
            if (ticket != null)
            {
                // Apply the DEVMODE snapshot from the print ticket to our starting DEVMODE, if supported.
                DevMode ticketDevMode = PrintSchemaShim.TryGetEmbeddedDevMode(ticket, this.OemDriverNamespace);
                if (ticketDevMode != null)
                {
                    devMode.CompatibleCopy(ticketDevMode);
                }

                PrintSchemaShim.CopyTicketToDevMode(devMode, ticket, scope, supportedFields);
            }
        }
        /// <summary>
        /// Print Schema Reference Guide v1.0 Appendix E.3.11 - Page Output Quality
        /// </summary>
        public void WritePageResolutionFeature(IList <DC_RESOLUTION> resolutions)
        {
            if (resolutions.Count > 0)
            {
                WriteStartFeature(
                    PrintSchemaNamespaces.StandardKeywordSet, "PageResolution",
                    PrintSchemaNamespaces.StandardKeywordSet, "PickOne",
                    COMPSTUISR.IDS_CPSUI_RESOLUTION);
                {
                    for (int i = 0; i < resolutions.Count; i++)
                    {
                        string optionLocalName;
                        uint   optionDisplayNameId;
                        bool   result = PrintSchemaShim.TryGetOutputQualityOption(
                            (short)resolutions[i].x,
                            out optionLocalName,
                            out optionDisplayNameId
                            );
                        if (result)
                        {
                            WriteOption(PrintSchemaNamespaces.StandardKeywordSet, optionLocalName, optionDisplayNameId, "None");
                        }
                        else
                        {
                            if (resolutions[i].x > 0 && resolutions[i].y > 0)
                            {
                                string x = XmlConvert.ToString(resolutions[i].x);
                                string y = XmlConvert.ToString(resolutions[i].y);
                                WriteStartOption(this._privateNamespace, null, x + " x " + y, "None");
                                {
                                    WriteStartScoredProperty(PrintSchemaNamespaces.StandardKeywordSet, "ResolutionX");
                                    {
                                        WriteValue("xsd:integer", x);
                                    }
                                    WriteEndScoredProperty();

                                    WriteStartScoredProperty(PrintSchemaNamespaces.StandardKeywordSet, "ResolutionY");
                                    {
                                        WriteValue("xsd:integer", y);
                                    }
                                    WriteEndScoredProperty();
                                }
                                WriteEndOption();
                            }
                        }
                    }
                }
                WriteEndFeature();
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Gets the PrintCapabilities relative to the given PrintTicket.
        /// </summary>
        /// <param name="printTicket">The stream that contains XML PrintTicket based on which PrintCapabilities should be built.</param>
        /// <returns>Stream that contains XML PrintCapabilities.</returns>
        /// <exception cref="ObjectDisposedException">
        /// The PTProvider instance has already been disposed.
        /// </exception>
        /// <exception cref="ArgumentException">
        /// The input PrintTicket specified by <paramref name="printTicket"/> is not well-formed.
        /// </exception>
        /// <exception cref="PrintQueueException">
        /// The PTProvider instance failed to retrieve the PrintCapabilities.
        /// </exception>
        public override MemoryStream GetPrintCapabilities(MemoryStream printTicket)
        {
            VerifyAccess();

            InternalPrintTicket internalTicket = null;

            try
            {
                internalTicket = (printTicket != null) ? new InternalPrintTicket(printTicket) : null;
            }
            catch (XmlException xmlException)
            {
                throw new ArgumentException(
                          String.Format(
                              CultureInfo.CurrentCulture,
                              "{0} {1} {2}",
                              PrintSchemaTags.Framework.PrintTicketRoot,
                              PTUtility.GetTextFromResource("FormatException.XMLNotWellFormed"),
                              xmlException.Message),
                          "printTicket",
                          xmlException);
            }

            DevMode defaultDevMode = GetDEVMODE(BaseDevModeType.UserDefault);
            DevMode devMode        = defaultDevMode.Clone();

            PrintTicketToDevMode(devMode, internalTicket, PrintTicketScope.JobScope, DevModeFields.All);

            MemoryStream capabilitiesStream = new MemoryStream();

            WinSpoolPrinterCapabilities capabilities = GetCapabilities(devMode);

            try
            {
                PrintCapabilitiesWriter writer = new PrintCapabilitiesWriter(capabilitiesStream, "ns0000", this.OemDriverNamespace, false);
                try
                {
                    writer.WriteStartDocument();
                    {
                        writer.WritePageDevmodeSnapshot(devMode.ByteData);

                        if (capabilities.HasICMIntent)
                        {
                            writer.WritePageICMRenderingIntentFeature();
                        }

                        if (capabilities.HasICMMethod)
                        {
                            writer.WritePageColorManagementFeature();
                        }

                        if (capabilities.CanCollate)
                        {
                            writer.WriteDocumentCollateFeature();
                        }

                        int minCopies = capabilities.MinCopies;
                        int maxCopies = capabilities.MaxCopies;

                        int defaultCopies = minCopies;
                        defaultCopies = Math.Max(minCopies, Math.Min(defaultDevMode.Copies, maxCopies));

                        writer.WriteJobCopiesAllDocumentsParameterDef(minCopies, maxCopies, defaultCopies);

                        writer.WriteJobNUpAllDocumentsContiguously(capabilities.NUp);

                        writer.WriteJobDuplexAllDocumentsContiguouslyFeature(capabilities.CanDuplex);

                        if (capabilities.CanScale)
                        {
                            writer.WritePageScalingFeature(1, 1000, 100);
                        }

                        writer.WritePageMediaSizeFeature(
                            capabilities.Papers,
                            capabilities.PaperNames,
                            PrintSchemaShim.TenthOfMillimeterToMicrons(capabilities.PaperSizes)
                            );

                        writer.WritePageResolutionFeature(capabilities.Resolutions);

                        int logicalPixelsX, logicalPixelsY;
                        int physicalWidth, physicalHeight;
                        int physicalOffsetX, physicalOffsetY;
                        int horizontalResolution, verticalResolution;

                        bool gotDevCaps = capabilities.TryGetDeviceCapabilities(
                            out logicalPixelsX, out logicalPixelsY,
                            out physicalWidth, out physicalHeight,
                            out physicalOffsetX, out physicalOffsetY,
                            out horizontalResolution, out verticalResolution);

                        if (gotDevCaps && logicalPixelsX > 0 && logicalPixelsY > 0)
                        {
                            int imageableSizeWidth  = PrintSchemaShim.DpiToMicrons(physicalWidth, logicalPixelsX);
                            int imageableSizeHeight = PrintSchemaShim.DpiToMicrons(physicalHeight, logicalPixelsY);
                            int originWidth         = PrintSchemaShim.DpiToMicrons(physicalOffsetX, logicalPixelsY);
                            int originHeight        = PrintSchemaShim.DpiToMicrons(physicalOffsetY, logicalPixelsY);
                            int extentWidth         = PrintSchemaShim.DpiToMicrons(horizontalResolution, logicalPixelsY);
                            int extentHeight        = PrintSchemaShim.DpiToMicrons(verticalResolution, logicalPixelsY);

                            writer.WritePageImageableSizeProperty(
                                imageableSizeWidth, imageableSizeHeight,
                                originWidth, originHeight,
                                extentWidth, extentHeight);
                        }

                        writer.WritePageOrientationFeature(capabilities.LandscapeOrientation);

                        writer.WritePageOutputColorFeature(capabilities.HasColor);

                        writer.WriteJobInputBinFeature(capabilities.Bins, capabilities.BinNames);

                        writer.WritePageMediaTypeFeature(capabilities.MediaTypes, capabilities.MediaTypeNames);

                        if (capabilities.TrueType)
                        {
                            writer.WritePageTrueTypeFontModeFeature();

                            writer.WritePageDeviceFontSubstitutionFeature();
                        }
                    }
                    writer.WriteEndDocument();
                }
                finally
                {
                    writer.Release();
                    writer = null;
                }
            }
            finally
            {
                capabilities.Release();
                capabilities = null;
            }

            // calls Security Critical Dispose on a private resource
            capabilitiesStream.Position = 0;

            return(capabilitiesStream);
        }
        /// <summary>
        /// Print Schema Reference Guide v1.0 Appendix E.3.9 - Page Media Type
        /// </summary>
        public void WritePageMediaTypeFeature(IList <uint> mediaTypes, IList <string> mediaTypeDisplayNames)
        {
            if (mediaTypes.Count > 0 && mediaTypeDisplayNames.Count > 0)
            {
                WriteStartFeature(
                    PrintSchemaNamespaces.StandardKeywordSet, "PageMediaType",
                    PrintSchemaNamespaces.StandardKeywordSet, "PickOne",
                    COMPSTUISR.IDS_CPSUI_MEDIA);
                {
                    for (int i = 0; i < mediaTypes.Count; i++)
                    {
                        string optionLocalName;
                        uint   optionDisplayNameId;
                        string pskFrontCoating;
                        string pskBackCoating;
                        string pskMaterial;

                        bool found = PrintSchemaShim.TryGetMediaTypeOption(
                            mediaTypes[i],
                            out optionLocalName,
                            out optionDisplayNameId,
                            out pskFrontCoating,
                            out pskBackCoating,
                            out pskMaterial
                            );

                        string optionDisplayName;
                        if (found)
                        {
                            optionDisplayName = GetDisplayString(optionDisplayNameId);
                        }
                        else
                        {
                            optionLocalName   = string.Format(CultureInfo.InvariantCulture, "User{0:0000000000}", mediaTypes[i]);
                            optionDisplayName = (i < mediaTypeDisplayNames.Count) ? mediaTypeDisplayNames[i] : null;
                            pskFrontCoating   = null;
                            pskBackCoating    = null;
                            pskMaterial       = null;
                        }

                        WriteStartOption(PrintSchemaNamespaces.StandardKeywordSet, optionLocalName, optionDisplayName, "None");
                        {
                            if (pskFrontCoating != null)
                            {
                                WriteStartScoredProperty(PrintSchemaNamespaces.StandardKeywordSet, "FrontCoating");
                                {
                                    WriteQNameValue(PrintSchemaNamespaces.StandardKeywordSet, pskFrontCoating);
                                }
                                WriteEndScoredProperty();
                            }

                            if (pskBackCoating != null)
                            {
                                WriteStartScoredProperty(PrintSchemaNamespaces.StandardKeywordSet, "BackCoating");
                                {
                                    WriteQNameValue(PrintSchemaNamespaces.StandardKeywordSet, pskBackCoating);
                                }
                                WriteEndScoredProperty();
                            }

                            if (pskMaterial != null)
                            {
                                WriteStartScoredProperty(PrintSchemaNamespaces.StandardKeywordSet, "Material");
                                {
                                    WriteQNameValue(PrintSchemaNamespaces.StandardKeywordSet, pskMaterial);
                                }
                                WriteEndScoredProperty();
                            }
                        }
                        WriteEndOption();
                    }
                }
                WriteEndFeature();
            }
        }
        /// <summary>
        /// Print Schema Reference Guide v1.0 Appendix E.3.7 - Job/Document/Page Input Bin
        /// </summary>
        public void WriteJobInputBinFeature(IList <short> bins, IList <string> binDisplayNames)
        {
            if (bins.Count > 0)
            {
                WriteStartFeature(
                    PrintSchemaNamespaces.StandardKeywordSet, "JobInputBin",
                    PrintSchemaNamespaces.StandardKeywordSet, "PickOne",
                    COMPSTUISR.IDS_CPSUI_SOURCE);
                {
                    for (int i = 0; i < bins.Count; i++)
                    {
                        string optionLocalName;
                        bool   hasStandardKeywordNamespace;
                        uint   optionDisplayNameId;
                        string pskFeedType;
                        string pskBinType;

                        bool result = PrintSchemaShim.TryGetPaperSourceOption(
                            bins[i],
                            out optionLocalName,
                            out hasStandardKeywordNamespace,
                            out optionDisplayNameId,
                            out pskFeedType,
                            out pskBinType);

                        if (result)
                        {
                            string optionNamespace = hasStandardKeywordNamespace ? PrintSchemaNamespaces.StandardKeywordSet : this._privateNamespace;
                            WriteStartOption(optionNamespace, optionLocalName, optionDisplayNameId, "None");
                            {
                                if (pskFeedType != null)
                                {
                                    WriteStartScoredProperty(PrintSchemaNamespaces.StandardKeywordSet, "FeedType");
                                    {
                                        WriteQNameValue(PrintSchemaNamespaces.StandardKeywordSet, pskFeedType);
                                    }
                                    WriteEndScoredProperty();
                                }

                                if (pskBinType != null)
                                {
                                    WriteStartScoredProperty(PrintSchemaNamespaces.StandardKeywordSet, "BinType");
                                    {
                                        WriteQNameValue(PrintSchemaNamespaces.StandardKeywordSet, pskBinType);
                                    }
                                    WriteEndScoredProperty();
                                }
                            }
                            WriteEndOption();
                        }
                        else
                        {
                            optionLocalName = string.Format(CultureInfo.InvariantCulture, "User{0:0000000000}", bins[i]);
                            string optionDisplayName = (i < binDisplayNames.Count) ? binDisplayNames[i] : null;
                            WriteStartOption(this._privateNamespace, optionLocalName, optionDisplayName, "None");
                            WriteEndOption();
                        }
                    }
                }
                WriteEndFeature();
            }
        }