Beispiel #1
0
 public Numeric multiply(Numeric op)
 {
     if (dim == 0)
     {
         return(new Numeric(op.valType, absValue * op.absValue,
                            absValue * op.pcValue,
                            absValue * op.tcolValue, op.dim, op.pcBase));
     }
     else if (op.dim == 0)
     {
         double opval = op.absValue;
         return(new Numeric(valType, opval * absValue, opval * pcValue,
                            opval * tcolValue, dim, pcBase));
     }
     else if (valType == op.valType && !isMixedType())
     {
         IPercentBase npcBase = ((valType & PC_LENGTH) != 0) ? pcBase
             : op.pcBase;
         return(new Numeric(valType, absValue * op.absValue,
                            pcValue * op.pcValue,
                            tcolValue * op.tcolValue, dim + op.dim,
                            npcBase));
     }
     else
     {
         throw new PropertyException("Can't multiply mixed Numerics");
     }
 }
Beispiel #2
0
 public Numeric divide(Numeric op)
 {
     if (dim == 0)
     {
         return(new Numeric(op.valType, absValue / op.absValue,
                            absValue / op.pcValue,
                            absValue / op.tcolValue, -op.dim, op.pcBase));
     }
     else if (op.dim == 0)
     {
         double opval = op.absValue;
         return(new Numeric(valType, absValue / opval, pcValue / opval,
                            tcolValue / opval, dim, pcBase));
     }
     else if (valType == op.valType && !isMixedType())
     {
         IPercentBase npcBase = ((valType & PC_LENGTH) != 0) ? pcBase
             : op.pcBase;
         return(new Numeric(valType,
                            (valType == ABS_LENGTH ? absValue / op.absValue : 0.0),
                            (valType == PC_LENGTH ? pcValue / op.pcValue : 0.0),
                            (valType == TCOL_LENGTH ? tcolValue / op.tcolValue : 0.0),
                            dim - op.dim, npcBase));
     }
     else
     {
         throw new PropertyException("Can't divide mixed Numerics.");
     }
 }
Beispiel #3
0
 protected Numeric(int valType, double absValue, double pcValue,
                   double tcolValue, int dim, IPercentBase pcBase)
 {
     this.valType   = valType;
     this.absValue  = absValue;
     this.pcValue   = pcValue;
     this.tcolValue = tcolValue;
     this.dim       = dim;
     this.pcBase    = pcBase;
 }
Beispiel #4
0
 protected Numeric(int valType, double absValue, double pcValue,
                   double tcolValue, int dim, IPercentBase pcBase)
 {
     this.valType = valType;
     this.absValue = absValue;
     this.pcValue = pcValue;
     this.tcolValue = tcolValue;
     this.dim = dim;
     this.pcBase = pcBase;
 }
Beispiel #5
0
 public Numeric add(Numeric op)
 {
     if (dim == op.dim)
     {
         IPercentBase npcBase = ((valType & PC_LENGTH) != 0) ? pcBase
             : op.pcBase;
         return(new Numeric(valType | op.valType, absValue + op.absValue,
                            pcValue + op.pcValue,
                            tcolValue + op.tcolValue, dim, npcBase));
     }
     else
     {
         throw new PropertyException("Can't add Numerics of different dimensions");
     }
 }
        public IPercentBase GetPercentBase()
        {
            IPercentBase pcbase = getFunctionPercentBase();

            return((pcbase != null) ? pcbase : maker.GetPercentBase(fo, plist));
        }
        private Property parsePrimaryExpr()
        {
            Property prop;

            switch (currentToken)
            {
            case TOK_LPAR:
                next();
                prop = parseAdditiveExpr();
                expectRpar();
                return(prop);

            case TOK_LITERAL:
                prop = new StringProperty(currentTokenValue);
                break;

            case TOK_NCNAME:
                prop = new NCnameProperty(currentTokenValue);
                break;

            case TOK_FLOAT:
                prop = new NumberProperty(ParseDouble(currentTokenValue));
                break;

            case TOK_INTEGER:
                prop = new NumberProperty(Int32.Parse(currentTokenValue));
                break;

            case TOK_PERCENT:
                double pcval = ParseDouble(
                    currentTokenValue.Substring(0, currentTokenValue.Length - 1)) / 100.0;
                IPercentBase pcBase = this.propInfo.GetPercentBase();
                if (pcBase != null)
                {
                    if (pcBase.GetDimension() == 0)
                    {
                        prop = new NumberProperty(pcval * pcBase.GetBaseValue());
                    }
                    else if (pcBase.GetDimension() == 1)
                    {
                        prop = new LengthProperty(new PercentLength(pcval,
                                                                    pcBase));
                    }
                    else
                    {
                        throw new PropertyException("Illegal percent dimension value");
                    }
                }
                else
                {
                    prop = new NumberProperty(pcval);
                }
                break;

            case TOK_NUMERIC:
                int    numLen   = currentTokenValue.Length - currentUnitLength;
                string unitPart = currentTokenValue.Substring(numLen);
                double numPart  = ParseDouble(currentTokenValue.Substring(0, numLen));
                Length length   = null;
                if (unitPart.Equals(RELUNIT))
                {
                    length = new FixedLength(numPart, propInfo.currentFontSize());
                }
                else
                {
                    length = new FixedLength(numPart, unitPart);
                }
                if (length == null)
                {
                    throw new PropertyException("unrecognized unit name: " + currentTokenValue);
                }
                else
                {
                    prop = new LengthProperty(length);
                }
                break;

            case TOK_COLORSPEC:
                prop = new ColorTypeProperty(new ColorType(currentTokenValue));
                break;

            case TOK_FUNCTION_LPAR:
            {
                IFunction function =
                    (IFunction)functionTable[currentTokenValue];
                if (function == null)
                {
                    throw new PropertyException("no such function: "
                                                + currentTokenValue);
                }
                next();
                propInfo.pushFunction(function);
                prop = function.Eval(parseArgs(function.NumArgs), propInfo);
                propInfo.popFunction();
                return(prop);
            }

            default:
                throw new PropertyException("syntax error");
            }
            next();
            return(prop);
        }
Beispiel #8
0
 public PercentLength(double factor, IPercentBase lbase)
 {
     this.factor = factor;
     this.lbase  = lbase;
 }
Beispiel #9
0
 public PercentLength(double factor, IPercentBase lbase)
 {
     this.factor = factor;
     this.lbase = lbase;
 }