Esempio n. 1
0
        /// <summary>Loads this counter systems symbols.</summary>
        protected override void LoadSymbols(Css.Style style)
        {
            // Get a set:
            Css.Value set=style[Css.Properties.AdditiveSymbols.GlobalProperty];

            if(set==null){
                return;
            }

            Symbols=new AdditiveTuple[set.Count];

            for(int i=0;i<Symbols.Length;i++){

                // Get both values:
                Css.Value a=set[i][0];
                Css.Value b=set[i][1];

                // Allow them to be defined either way around:
                int weight;
                string symbol;

                if(b is Css.Units.DecimalUnit){
                    weight=b.GetInteger(null,null);
                    symbol=a.Text;
                }else{
                    weight=a.GetInteger(null,null);
                    symbol=b.Text;
                }

                Symbols[i]=new AdditiveTuple(symbol,weight);

            }
        }
Esempio n. 2
0
        /// <summary>Gets the given number as handled by this counter system.</summary>
        protected override string GetPositive(int value)
        {
            if (value == 0)
            {
                // Got a tuple of weight 0? It'll always be the one at the end:
                AdditiveTuple lastTuple = Symbols[Symbols.Length - 1];

                if (lastTuple.Weight == 0)
                {
                    return(lastTuple.Symbol);
                }

                return("");
            }

            // Index of the current tuple:
            int currentTuple = -1;
            int max          = Symbols.Length - 1;

            while (value > 0 && currentTuple < max)
            {
                // Pop a symbol from the list:
                currentTuple++;

                // Append the current symbol this many times:
                int repeatCount = value / Symbols[currentTuple].Weight;

                for (int i = 0; i < repeatCount; i++)
                {
                    // Append:
                    Builder.Append(Symbols[currentTuple].Symbol);
                }

                // Decrement value:
                value -= repeatCount * Symbols[currentTuple].Weight;
            }

            if (value != 0)
            {
                // Can't actually be represented by this counter style.
                Builder.Length = 0;

                // Fallback:
                return(null);
            }

            return(Build());
        }