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

            InputBinOption option = baseOption as InputBinOption;

            // Validate the option is complete before adding it to the collection
            if (option._optionName != null)
            {
                int enumValue = PrintSchemaMapper.SchemaNameToEnumValueWithArray(
                    PrintSchemaTags.Keywords.InputBinKeys.InputBinNames,
                    PrintSchemaTags.Keywords.InputBinKeys.InputBinEnums,
                    option._optionName);

                if (enumValue > 0)
                {
                    // We require the InputBin option to have an option name
                    option._value = (InputBin)enumValue;
                    this.InputBins.Add(option);
                    added = true;
                }
            }

            return(added);
        }
        internal override sealed bool AddOptionCallback(PrintCapabilityOption baseOption)
        {
            FixedMediaSizeOption option = baseOption as FixedMediaSizeOption;
            bool complete = false;

            // All PageMediaSize options must have an option name
            if (option._optionName == null)
            {
                return(complete);
            }

            int enumValue = PrintSchemaMapper.SchemaNameToEnumValueWithArray(
                PrintSchemaTags.Keywords.PageMediaSizeKeys.MediaSizeNames,
                PrintSchemaTags.Keywords.PageMediaSizeKeys.MediaSizeEnums,
                option._optionName);

            // We only support standard Print Schema options
            if (enumValue > 0)
            {
                option._value = (PageMediaSizeName)enumValue;
                if ((option._mediaSizeWidth > 0) ||
                    (option._mediaSizeHeight > 0))
                {
                    this.FixedMediaSizes.Add(option);
                    complete = true;
                }
            }

            return(complete);
        }
Exemple #3
0
 /// <summary>
 /// Finds the array index of a standard PrintCapabilities feature
 /// </summary>
 /// <returns>non-negative index if matching feature found, otherwise -1</returns>
 /// <exception>none</exception>
 private static int LookupFeatureIndex(string featureName, bool isSubFeature)
 {
     // The mapper returns int-value of the feature's enum, which is what we use
     // as the feature array index.
     return(PrintSchemaMapper.SchemaNameToEnumValueWithMap(
                isSubFeature ? PrintSchemaTags.Keywords.SubFeatureMapTable :
                PrintSchemaTags.Keywords.FeatureMapTable,
                featureName));
 }
        internal override sealed bool AddOptionCallback(PrintCapabilityOption baseOption)
        {
            bool added = false;

            NUpPresentationDirectionOption option = baseOption as NUpPresentationDirectionOption;

            // validate the option is complete before adding it to the collection
            if (option._optionName != null)
            {
                int enumValue = PrintSchemaMapper.SchemaNameToEnumValueWithArray(
                    PrintSchemaTags.Keywords.NUpKeys.DirectionNames,
                    PrintSchemaTags.Keywords.NUpKeys.DirectionEnums,
                    option._optionName);

                if (enumValue > 0)
                {
                    option._value = (PagesPerSheetDirection)enumValue;
                    this.PresentationDirections.Add(option);
                    added = true;
                }
            }

            return(added);
        }
        internal override sealed bool AddOptionCallback(PrintCapabilityOption baseOption)
        {
            bool added = false;

            TrueTypeFontModeOption option = baseOption as TrueTypeFontModeOption;

            // validate the option is complete before adding it to the collection
            if (option._optionName != null)
            {
                int enumValue = PrintSchemaMapper.SchemaNameToEnumValueWithArray(
                    PrintSchemaTags.Keywords.PageTrueTypeFontModeKeys.ModeNames,
                    PrintSchemaTags.Keywords.PageTrueTypeFontModeKeys.ModeEnums,
                    option._optionName);

                if (enumValue > 0)
                {
                    option._value = (TrueTypeFontMode)enumValue;
                    this.TrueTypeFontModes.Add(option);
                    added = true;
                }
            }

            return(added);
        }
Exemple #6
0
        /// <summary>
        /// Finds the array index of a standard PrintCapabilities parameter-def
        /// </summary>
        /// <returns>non-negative index if matching parameter-def found, otherwise -1</returns>
        /// <exception>none</exception>
        private static int LookupParameterIndex(string paramName, out bool isLocalParam)
        {
            isLocalParam = false;

            int index = PrintSchemaMapper.SchemaNameToEnumValueWithMap(
                PrintSchemaTags.Keywords.GlobalParameterMapTable,
                paramName);

            if (index < 0)
            {
                // We didn't find a match to a global parameter. Now try the local parameters.
                index = PrintSchemaMapper.SchemaNameToEnumValueWithMap(
                    PrintSchemaTags.Keywords.LocalParameterMapTable,
                    paramName);

                // If a match is found, we know it must be a local param
                if (index >= 0)
                {
                    isLocalParam = true;
                }
            }

            return(index);
        }
        /// <summary>
        /// Moves the reader cursor to the next Print Schema Framework element at the given depth.
        /// (The element could be Feature, ParameterDefinition, Option, ScoredProperty or Property)
        /// </summary>
        /// <param name="depth">client-requested traversing depth</param>
        /// <param name="typeFilterFlags">flags to indicate client interested node types</param>
        /// <returns>True if next Framework element is ready to read.
        /// False if no more Framework element at the given depth.</returns>
        /// <exception cref="XmlException">XML is not well-formed.</exception>
        public bool MoveToNextSchemaElement(int depth, PrintSchemaNodeTypes typeFilterFlags)
        {
            bool foundElement = false;

            while (!foundElement && _xmlReader.Read())
            {
                // Read() throws XmlException if error occurred while parsing the XML.

                // If we hit an end-element tag at higher depth, we know there are no more
                // Framework elements at the client-requested depth.
                if ((_xmlReader.NodeType == XmlNodeType.EndElement) &&
                    (_xmlReader.Depth < depth))
                {
                    break;
                }

                // Stop at the next XML start element at the client-requested depth
                // and in the standard Framework element namespace.
                if ((_xmlReader.NodeType != XmlNodeType.Element) ||
                    (_xmlReader.Depth != depth) ||
                    (_xmlReader.NamespaceURI != PrintSchemaNamespaces.Framework))
                {
                    continue;
                }

                // Find a candidate, so reset internal states to be ready for its parsing.
                ResetCurrentElementState();

                foundElement = true;

                _currentElementDepth   = depth;
                _currentElementIsEmpty = _xmlReader.IsEmptyElement;

                // Map element name to Schema node type
                int enumValue = PrintSchemaMapper.SchemaNameToEnumValueWithMap(
                    PrintSchemaTags.Framework.NodeTypeMapTable,
                    _xmlReader.LocalName);

                if (enumValue > 0)
                {
                    _currentElementNodeType = (PrintSchemaNodeTypes)enumValue;
                }
                else
                {
                    #if _DEBUG
                    Trace.WriteLine("-Warning- skip unknown element '" + _xmlReader.LocalName +
                                    "' at line " + _xmlReader.LineNumber + ", position " +
                                    _xmlReader.LinePosition);
                    #endif

                    foundElement = false;
                }

                if (foundElement)
                {
                    // Check whether or not the found element type is what client is interested in.
                    // If not, we will skip this element.
                    if ((CurrentElementNodeType & typeFilterFlags) == 0)
                    {
                        #if _DEBUG
                        Trace.WriteLine("-Warning- skip not-wanted element '" + _xmlReader.LocalName +
                                        "' at line " + _xmlReader.LineNumber + ", position " +
                                        _xmlReader.LinePosition);
                        #endif

                        foundElement = false;
                    }
                }

                if (foundElement)
                {
                    // The element is what the client wants.
                    if (CurrentElementNodeType != PrintSchemaNodeTypes.Value)
                    {
                        // Element other than <Value> should have the "name" XML attribute.
                        // Reader will verify the "name" XML attribute has a QName value that
                        // is in our standard Keyword namespace.
                        string QName = _xmlReader.GetAttribute(PrintSchemaTags.Framework.NameAttr,
                                                               PrintSchemaNamespaces.FrameworkAttrForXmlReader);

                        // Only <Option> element is allowed not to have the "name" XML attribute
                        if (QName == null)
                        {
                            if (CurrentElementNodeType != PrintSchemaNodeTypes.Option)
                            {
                                #if _DEBUG
                                Trace.WriteLine("-Warning- skip element " + CurrentElementNodeType +
                                                " at line " + _xmlReader.LineNumber + ", position " +
                                                _xmlReader.LinePosition + " due to missing 'name' XML attribute");
                                #endif

                                foundElement = false;
                            }
                        }
                        else
                        {
                            string URI       = XmlReaderQName.GetURI(_xmlReader, QName);
                            string localName = XmlReaderQName.GetLocalName(QName);

                            if (URI == PrintSchemaNamespaces.Framework)
                            {
                                _currentElementPSFNameAttrValue = localName;
                            }
                            else if (URI == PrintSchemaNamespaces.StandardKeywordSet)
                            {
                                _currentElementNameAttrValue = localName;
                            }
                            else
                            {
                                // If QName value is not in standard PSF or PSK namespace,
                                // then skip this Schema element.
                                #if _DEBUG
                                Trace.WriteLine("-Warning- skip element " + CurrentElementNodeType +
                                                " at line " + _xmlReader.LineNumber + ", position " +
                                                _xmlReader.LinePosition +
                                                " due to non-PSF/PSK 'name' XML attribute value: " + QName);
                                #endif

                                foundElement = false;
                            }
                        }
                    }
                    else
                    {
                        // For <Value> element, we need to get its element text value.
                        // If this function tells client the <Value> element is found, it guarantees
                        // that the <Value> element text value is non-empty.

                        // Needs to handle xsi:type verification
                        // ReadElementString() returns empty string if the element is empty
                        // (<item></item> or <item/>), and it could throws XmlException.
                        _currentElementTextValue = _xmlReader.ReadElementString();

                        // Our schema requires that <Value> element should always have non-empty value.
                        if ((_currentElementTextValue == null) || (_currentElementTextValue.Length == 0))
                        {
                            #if _DEBUG
                            Trace.WriteLine("-Warning- skip element " + CurrentElementNodeType +
                                            " at line " + _xmlReader.LineNumber + ", position " +
                                            _xmlReader.LinePosition + " since it has empty element text");
                            #endif

                            _currentElementTextValue = null;
                            foundElement             = false;
                        }
                    }
                }
            }

            return(foundElement);
        }
Exemple #8
0
        internal override sealed bool AddOptionCallback(PrintCapabilityOption baseOption)
        {
            bool complete = false;

            ScalingOption option = baseOption as ScalingOption;

            if (option._optionName != null)
            {
                int enumValue = PrintSchemaMapper.SchemaNameToEnumValueWithArray(
                    PrintSchemaTags.Keywords.PageScalingKeys.ScalingNames,
                    PrintSchemaTags.Keywords.PageScalingKeys.ScalingEnums,
                    option._optionName);

                if (enumValue > 0)
                {
                    option._value = (PageScaling)enumValue;
                }
            }

            if (option.Value != PageScaling.Unspecified)
            {
                if (option.Value == PageScaling.None)
                {
                    // Non-custom scaling option doesn't need any ParameterRefs
                    complete = true;
                }
                else if (option.Value == PageScaling.Custom)
                {
                    // Custom scaling option must have the 2 scale ParameterRefs
                    if ((option._scaleWIndex >= 0) &&
                        (option._scaleHIndex >= 0))
                    {
                        complete = true;
                    }
                    else
                    {
                        // Need to reset the local parameter required flag since we are
                        // ignoring the custom scaling option
                        if (option._scaleWIndex >= 0)
                        {
                            option.OwnerFeature.OwnerPrintCap.SetLocalParameterDefAsRequired(option._scaleWIndex, false);
                        }

                        if (option._scaleHIndex >= 0)
                        {
                            option.OwnerFeature.OwnerPrintCap.SetLocalParameterDefAsRequired(option._scaleHIndex, false);
                        }
                    }
                }
                else if (option.Value == PageScaling.CustomSquare)
                {
                    // Custom square scaling option must have the scale ParameterRef
                    if (option._squareScaleIndex >= 0)
                    {
                        complete = true;
                    }
                    else
                    {
                        // Need to reset the local parameter required flag since we are
                        // ignoring the custom scaling option
                        if (option._squareScaleIndex >= 0)
                        {
                            option.OwnerFeature.OwnerPrintCap.SetLocalParameterDefAsRequired(option._squareScaleIndex, false);
                        }
                    }
                }
            }

            if (complete)
            {
                this.ScalingOptions.Add(option);
            }

            return(complete);
        }
        /// <exception cref="XmlException">XML is not well-formed.</exception>
        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);
        }