PageResolution.cs source code in C# .NET

Source code for the .NET framework in C#

                        

Code:

/ DotNET / DotNET / 8.0 / untmp / WIN_WINDOWS / lh_tools_devdiv_wpf / Windows / wcp / Print / Reach / PrintConfig / PageResolution.cs / 1 / PageResolution.cs

                            /*++ 

Copyright (C) 2003 Microsoft Corporation
All rights reserved.
 
Module Name:
 
    PageResolution.cs 

Abstract: 

    Definition and implementation of this public feature/parameter related types.

Author: 

    [....] ([....]) 7/1/2003 
 
--*/
 
using System;
using System.IO;
using System.Xml;
using System.Collections; 
using System.Collections.ObjectModel;
using System.Collections.Generic; 
using System.Diagnostics; 
using System.Globalization;
 
using System.Printing;
using MS.Internal.Printing.Configuration;

#pragma warning disable 1634, 1691 // Allows suppression of certain PreSharp messages 

namespace MS.Internal.Printing.Configuration 
{ 
    /// 
    /// Represents a page resolution option. 
    /// 
    internal class ResolutionOption: PrintCapabilityOption
    {
        #region Constructors 

        internal ResolutionOption(PrintCapabilityFeature ownerFeature) : base(ownerFeature) 
        { 
            _resolutionX = _resolutionY = PrintSchema.UnspecifiedIntValue;
            _qualityValue = 0; 
        }

        #endregion Constructors
 
        #region Public Properties
 
        ///  
        /// Gets the page resolution's quality label.
        ///  
        public PageQualitativeResolution QualitativeResolution
        {
            get
            { 
                return _qualityValue;
            } 
        } 

        ///  
        /// Gets the page resolution's X component.
        /// 
        public int ResolutionX
        { 
            get
            { 
                return _resolutionX; 
            }
        } 

        /// 
        /// Gets the page resolution's Y component.
        ///  
        public int ResolutionY
        { 
            get 
            {
                return _resolutionY; 
            }
        }

        #endregion Public Properties 

        #region Public Methods 
 
        /// 
        /// Converts the page resolution to human-readable string. 
        /// 
        /// A string that represents this page resolution.
        public override string ToString()
        { 
            return ResolutionX.ToString(CultureInfo.CurrentCulture) + " x " +
                   ResolutionY.ToString(CultureInfo.CurrentCulture) + " (Qualitative: " + 
                   QualitativeResolution.ToString() + ")"; 
        }
 
        #endregion Public Methods

        #region Internal Fields
 
        internal int _resolutionX;
        internal int _resolutionY; 
 
        internal PageQualitativeResolution _qualityValue;
 
        #endregion Internal Fields
    }

    ///  
    /// Represents page resolution capability.
    ///  
    internal class PageResolutionCapability : PrintCapabilityFeature 
    {
        #region Constructors 

        internal PageResolutionCapability(InternalPrintCapabilities ownerPrintCap) : base(ownerPrintCap)
        {
        } 

        #endregion Constructors 
 
        #region Public Properties
 
        /// 
        /// Gets the collection object that represents page resolutions supported by the device.
        /// 
        public Collection Resolutions 
        {
            get 
            { 
                return _resolutions;
            } 
        }

        #endregion Public Properties
 
        #region Internal Methods
 
        internal static PrintCapabilityFeature NewFeatureCallback(InternalPrintCapabilities printCap) 
        {
            PageResolutionCapability cap = new PageResolutionCapability(printCap); 
            cap._resolutions = new Collection();

            return cap;
        } 

        internal override sealed bool AddOptionCallback(PrintCapabilityOption baseOption) 
        { 
            bool added = false;
 
            ResolutionOption option = baseOption as ResolutionOption;

            // Validate the option is complete before adding it to the collection
            // QualitativeResolution is NOT required 
            if ((option.ResolutionX > 0) &&
                (option.ResolutionY > 0)) 
            { 
                this.Resolutions.Add(option);
                added = true; 
            }

            return added;
        } 

        internal override sealed void AddSubFeatureCallback(PrintCapabilityFeature subFeature) 
        { 
            // no sub-feature
            return; 
        }

        internal override sealed bool FeaturePropCallback(PrintCapabilityFeature feature, XmlPrintCapReader reader)
        { 
            // no feature property to handle
            return false; 
        } 

        internal override sealed PrintCapabilityOption NewOptionCallback(PrintCapabilityFeature baseFeature) 
        {
            ResolutionOption option = new ResolutionOption(baseFeature);

            return option; 
        }
 
        internal override sealed void OptionAttrCallback(PrintCapabilityOption baseOption, XmlPrintCapReader reader) 
        {
            // no option attribute to handle 
            return;
        }

        /// XML is not well-formed. 
        internal override sealed bool OptionPropCallback(PrintCapabilityOption baseOption, XmlPrintCapReader reader)
        { 
            ResolutionOption option = baseOption as ResolutionOption; 
            bool handled = false;
 
            if (reader.CurrentElementNodeType == PrintSchemaNodeTypes.ScoredProperty)
            {
                handled = true;
 
                if (reader.CurrentElementNameAttrValue == PrintSchemaTags.Keywords.PageResolutionKeys.ResolutionX)
                { 
                    try 
                    {
                        option._resolutionX = reader.GetCurrentPropertyIntValueWithException(); 
                    }
                    // We want to catch internal FormatException to skip recoverable XML content syntax error
                    #pragma warning suppress 56502
                    #if _DEBUG 
                    catch (FormatException e)
                    #else 
                    catch (FormatException) 
                    #endif
                    { 
                        #if _DEBUG
                        Trace.WriteLine("-Error- " + e.Message);
                        #endif
                    } 
                }
                else if (reader.CurrentElementNameAttrValue == PrintSchemaTags.Keywords.PageResolutionKeys.ResolutionY) 
                { 
                    try
                    { 
                        option._resolutionY = reader.GetCurrentPropertyIntValueWithException();
                    }
                    // We want to catch internal FormatException to skip recoverable XML content syntax error
                    #pragma warning suppress 56502 
                    #if _DEBUG
                    catch (FormatException e) 
                    #else 
                    catch (FormatException)
                    #endif 
                    {
                        #if _DEBUG
                        Trace.WriteLine("-Error- " + e.Message);
                        #endif 
                    }
                } 
                else if (reader.CurrentElementNameAttrValue == PrintSchemaTags.Keywords.PageResolutionKeys.QualitativeResolution) 
                {
                    int enumValue; 

                    if (PrintSchemaMapper.CurrentPropertyQValueToEnumValue(reader,
                                              PrintSchemaTags.Keywords.PageResolutionKeys.QualityNames,
                                              PrintSchemaTags.Keywords.PageResolutionKeys.QualityEnums, 
                                              out enumValue))
                    { 
                        option._qualityValue = (PageQualitativeResolution)enumValue; 
                    }
                } 
                else
                {
                    handled = false;
 
                    #if _DEBUG
                    Trace.WriteLine("-Warning- skip unknown ScoredProperty '" + 
                                    reader.CurrentElementNameAttrValue + "' at line " + 
                                    reader._xmlReader.LineNumber + ", position " +
                                    reader._xmlReader.LinePosition); 
                    #endif
                }
            }
 
            return handled;
        } 
 
        #endregion Internal Methods
 
        #region Internal Properties

        internal override sealed bool IsValid
        { 
            get
            { 
                return (this.Resolutions.Count > 0); 
            }
        } 

        internal override sealed string FeatureName
        {
            get 
            {
                return PrintSchemaTags.Keywords.PageResolutionKeys.Self; 
            } 
        }
 
        internal override sealed bool HasSubFeature
        {
            get
            { 
                return false;
            } 
        } 

        #endregion Internal Properties 

        #region Internal Fields

        internal Collection _resolutions; 

        #endregion Internal Fields 
    } 

    ///  
    /// Represents page resolution setting.
    /// 
    internal class PageResolutionSetting : PrintTicketFeature
    { 
        #region Constructors
 
        ///  
        /// Constructs a new page resolution setting object.
        ///  
        internal PageResolutionSetting(InternalPrintTicket ownerPrintTicket) : base(ownerPrintTicket)
        {
            this._featureName = PrintSchemaTags.Keywords.PageResolutionKeys.Self;
 
            this._propertyMaps = new PTPropertyMapEntry[] {
                new PTPropertyMapEntry(this, 
                                       PrintSchemaTags.Keywords.PageResolutionKeys.ResolutionX, 
                                       PTPropValueTypes.PositiveIntValue),
                new PTPropertyMapEntry(this, 
                                       PrintSchemaTags.Keywords.PageResolutionKeys.ResolutionY,
                                       PTPropValueTypes.PositiveIntValue),
                new PTPropertyMapEntry(this,
                                       PrintSchemaTags.Keywords.PageResolutionKeys.QualitativeResolution, 
                                       PTPropValueTypes.EnumStringValue,
                                       PrintSchemaTags.Keywords.PageResolutionKeys.QualityNames, 
                                       PrintSchemaTags.Keywords.PageResolutionKeys.QualityEnums), 
            };
        } 

        #endregion Constructors

        #region Public Properties 

        ///  
        /// Gets or sets the page resolution setting's X component. 
        /// 
        ///  
        /// If this component is not specified yet, getter will return .
        /// 
        /// 
        /// The value to set is not a positive integer. 
        /// 
        public int ResolutionX 
        { 
            get
            { 
                return this[PrintSchemaTags.Keywords.PageResolutionKeys.ResolutionX];
            }
            set
            { 
                if (value <= 0)
                { 
                    throw new ArgumentOutOfRangeException("value", 
                                  PTUtility.GetTextFromResource("ArgumentException.PositiveValue"));
                } 

                this[PrintSchemaTags.Keywords.PageResolutionKeys.ResolutionX] = value;
            }
        } 

        ///  
        /// Gets or sets the page resolution setting's Y component. 
        /// 
        ///  
        /// If this component is not specified yet, getter will return .
        /// 
        /// 
        /// The value to set is not a positive integer. 
        /// 
        public int ResolutionY 
        { 
            get
            { 
                return this[PrintSchemaTags.Keywords.PageResolutionKeys.ResolutionY];
            }
            set
            { 
                if (value <= 0)
                { 
                    throw new ArgumentOutOfRangeException("value", 
                                  PTUtility.GetTextFromResource("ArgumentException.PositiveValue"));
                } 

                this[PrintSchemaTags.Keywords.PageResolutionKeys.ResolutionY] = value;
            }
        } 

        ///  
        /// Gets or sets the page resolution setting's quality label. 
        /// 
        ///  
        /// If this quality label setting is not specified yet, getter will return 0.
        /// 
        /// 
        /// The value to set is not one of the standard . 
        /// 
        public PageQualitativeResolution QualitativeResolution 
        { 
            get
            { 
                return (PageQualitativeResolution)this[PrintSchemaTags.Keywords.PageResolutionKeys.QualitativeResolution];
            }
            set
            { 
                if (value < PrintSchema.PageQualitativeResolutionEnumMin ||
                    value > PrintSchema.PageQualitativeResolutionEnumMax) 
                { 
                    throw new ArgumentOutOfRangeException("value");
                } 

                this[PrintSchemaTags.Keywords.PageResolutionKeys.QualitativeResolution] = (int)value;
            }
        } 

        #endregion Public Properties 
 
        #region Public Methods
 
        /// 
        /// Converts the page resolution setting to human-readable string.
        /// 
        /// A string that represents this page resolution setting. 
        public override string ToString()
        { 
            return ResolutionX.ToString(CultureInfo.CurrentCulture) + "x" + 
                   ResolutionY.ToString(CultureInfo.CurrentCulture) +
                   "(qualitative: " + QualitativeResolution.ToString() + ")"; 
        }

        #endregion Public Methods
    } 
}

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.


                        

Link Menu

Network programming in C#, Network Programming in VB.NET, Network Programming in .NET
This book is available now!
Buy at Amazon US or
Buy at Amazon UK