public CounterSystem()
        {
            if(this is DecimalSystem){
                return;
            }

            Fallback=CounterSystems.Decimal;
        }
Example #2
0
        /// <summary>Gets a named counter system. Null if not found.</summary>
        public Counters.CounterSystem GetCounter(string name)
        {
            // Try a core counter system:
            Counters.CounterSystem sys = Counters.CounterSystems.Get(name);

            if (sys != null)
            {
                return(sys);
            }

            // Get the counter system:
            AtRules.CounterStyleRule rule;
            if (CssCounters != null && CssCounters.TryGetValue(name, out rule))
            {
                // Get the system:
                return(rule.System);
            }

            // Not found:
            return(null);
        }
Example #3
0
        /// <summary>Gets the ordinal for a given index.</summary>
        public string GetOrdinal(int index, string name, bool prefixed)
        {
            // Try a core counter system:
            Counters.CounterSystem sys = Counters.CounterSystems.Get(name);

            if (sys != null)
            {
                return(sys.Get(index, prefixed));
            }

            // Get the counter system:
            AtRules.CounterStyleRule rule;
            if (CssCounters != null && CssCounters.TryGetValue(name, out rule))
            {
                // Get the system and return the ordinal:
                return(rule.System.Get(index, prefixed));
            }

            // Not found:
            return(null);
        }
        public virtual CounterSystem Clone()
        {
            // Create the instance:
            CounterSystem cs=Activator.CreateInstance(GetType()) as CounterSystem;

            // Copy the core values:
            cs.Fallback=Fallback;
            cs.Suffix=Suffix;
            cs.Prefix=Prefix;
            cs.NegativePrefix=NegativePrefix;
            cs.NegativeSuffix=NegativeSuffix;
            cs.Min=Min;
            cs.Max=Max;
            cs.PadMin=PadMin;
            cs.PadSymbol=PadSymbol;

            if(AdditionalRanges!=null){
                cs.AdditionalRanges=AdditionalRanges.Clone() as CounterRange[];
            }

            return cs;
        }
Example #5
0
        /// <summary>Loads this systems values from the given style.</summary>
        public void Load(Css.Style style, Css.ReflowDocument document)
        {
            // Get the range:
            Css.Value range = style[Css.Properties.RangeProperty.GlobalProperty];

            if (range != null && !range.IsAuto)
            {
                Css.ValueSet rangeSet = range as Css.ValueSet;

                int rangeSize = (rangeSet != null && rangeSet.Spacer == ",")?range.Count : 1;

                if (rangeSize > 1)
                {
                    AdditionalRanges = new CounterRange[rangeSize];

                    int overallMin = 0;
                    int overallMax = 0;

                    // For each one..
                    for (int i = 0; i < rangeSize; i++)
                    {
                        int min = range[i][0].GetInteger(null, null);
                        int max = range[i][1].GetInteger(null, null);

                        if (i == 0)
                        {
                            overallMin = min;
                            overallMax = max;
                        }
                        else
                        {
                            if (min < overallMin)
                            {
                                overallMin = min;
                            }

                            if (max > overallMax)
                            {
                                overallMax = max;
                            }
                        }

                        AdditionalRanges[i] = new CounterRange(min, max);
                    }

                    Min = overallMin;
                    Max = overallMax;
                }
                else
                {
                    AdditionalRanges = null;

                    // Set min/max:
                    Min = range[0].GetInteger(null, null);
                    Max = range[1].GetInteger(null, null);
                }
            }

            // Get the pad:
            Css.Value pad = style[Css.Properties.Pad.GlobalProperty];

            if (pad != null)
            {
                PadMin = pad[0].GetInteger(null, null);

                if (pad is Css.ValueSet)
                {
                    PadSymbol = pad[1].Text;
                }
                else
                {
                    PadSymbol = "";
                }
            }

            // Prefix:
            Css.Value prefix = style[Css.Properties.Prefix.GlobalProperty];

            if (prefix != null)
            {
                Prefix = prefix.Text;
            }

            // Suffix:
            Css.Value suffix = style[Css.Properties.Suffix.GlobalProperty];

            if (suffix != null)
            {
                Suffix = suffix.Text;
            }

            // Negative:
            Css.Value negative = style[Css.Properties.Negative.GlobalProperty];

            if (negative != null)
            {
                NegativePrefix = negative[0].Text;

                if (negative is Css.ValueSet)
                {
                    NegativeSuffix = negative[1].Text;
                }
                else
                {
                    NegativeSuffix = "";
                }
            }

            // Symbols:
            LoadSymbols(style);

            // Fallback:
            Css.Value fallback = style[Css.Properties.Fallback.GlobalProperty];

            if (fallback != null)
            {
                string fbName = fallback[0].Text;

                if (fbName == "none" || fbName == "decimal")
                {
                    fbName = null;
                }

                if (fbName != null)
                {
                    // Get by built in name:
                    Fallback = Counters.CounterSystems.Get(fbName);

                    if (Fallback == null)
                    {
                        // Get by doc name:
                        CounterStyleRule rule;
                        if (document.CssCounters.TryGetValue(fbName, out rule))
                        {
                            // Get the system:
                            Fallback = rule.System;
                        }
                    }
                }

                if (Fallback == null)
                {
                    // Default to decimal system:
                    Fallback = CounterSystems.Decimal;
                }
            }
        }