static void
SetProperty(OperatorData* aOperatorData,
            nsString      aName,
            nsString      aValue)
{
  if (aName.IsEmpty() || aValue.IsEmpty())
    return;

  // XXX These ones are not kept in the dictionary
  // Support for these requires nsString member variables 
  // maxsize (default: infinity)
  // minsize (default: 1)

  if (aName.EqualsLiteral("direction")) {
    if (aValue.EqualsLiteral("vertical"))
      aOperatorData->mFlags |= NS_MATHML_OPERATOR_DIRECTION_VERTICAL;
    else if (aValue.EqualsLiteral("horizontal"))
      aOperatorData->mFlags |= NS_MATHML_OPERATOR_DIRECTION_HORIZONTAL;
    else return; // invalid value
  } else {
    bool isLeadingSpace;
    if (aName.EqualsLiteral("lspace"))
      isLeadingSpace = true;
    else if (aName.EqualsLiteral("rspace"))
      isLeadingSpace = false;
    else return;  // input is not applicable

    // aValue is assumed to be a digit from 0 to 7
    nsresult error = NS_OK;
    float space = aValue.ToFloat(&error) / 18.0;
    if (NS_FAILED(error)) return;

    if (isLeadingSpace)
      aOperatorData->mLeadingSpace = space;
    else
      aOperatorData->mTrailingSpace = space;
  }
}
Ejemplo n.º 2
0
void
SetProperty(OperatorData* aOperatorData,
            nsString      aName,
            nsString      aValue)
{
  if (!aName.Length() || !aValue.Length())
    return;

  // XXX These ones are not kept in the dictionary
  // Support for these requires nsString member variables 
  // maxsize (default: infinity)
  // minsize (default: 1)

  if (aValue.EqualsLiteral("true")) {
    // see if we should enable flags with default value=false
    if (aName.EqualsLiteral("fence"))
      aOperatorData->mFlags |= NS_MATHML_OPERATOR_FENCE;
    else if (aName.EqualsLiteral("accent"))
      aOperatorData->mFlags |= NS_MATHML_OPERATOR_ACCENT;
    else if (aName.EqualsLiteral("largeop"))
      aOperatorData->mFlags |= NS_MATHML_OPERATOR_LARGEOP;
    else if (aName.EqualsLiteral("separator"))
      aOperatorData->mFlags |=  NS_MATHML_OPERATOR_SEPARATOR;
    else if (aName.EqualsLiteral("movablelimits"))
      aOperatorData->mFlags |= NS_MATHML_OPERATOR_MOVABLELIMITS;
  }
  else if (aValue.EqualsLiteral("false")) {
    // see if we should disable flags with default value=true
    if (aName.EqualsLiteral("symmetric"))
      aOperatorData->mFlags &= ~NS_MATHML_OPERATOR_SYMMETRIC;
  }
  else if (aName.EqualsLiteral("stretchy") &&
          (1 == aOperatorData->mStr.Length())) {
    if (aValue.EqualsLiteral("vertical"))
      aOperatorData->mFlags |= NS_MATHML_OPERATOR_STRETCHY_VERT;
    else if (aValue.EqualsLiteral("horizontal"))
      aOperatorData->mFlags |= NS_MATHML_OPERATOR_STRETCHY_HORIZ;
    else return; // invalid value
    if (kNotFound == nsMathMLOperators::FindStretchyOperator(aOperatorData->mStr[0])) {
      gStretchyOperatorArray->AppendElement(aOperatorData);
    }
  }
  else {
    PRInt32 i = 0;
    float space = 0.0f;
    PRBool isLeftSpace;
    if (aName.EqualsLiteral("lspace"))
      isLeftSpace = PR_TRUE;
    else if (aName.EqualsLiteral("rspace"))
      isLeftSpace = PR_FALSE;
    else return;  // input is not applicable

    // See if it is a numeric value (unit is assumed to be 'em')
    if (nsCRT::IsAsciiDigit(aValue[0])) {
      PRInt32 error = 0;
      space = aValue.ToFloat(&error);
      if (error) return;
    }
    // See if it is one of the 'namedspace' (ranging 1/18em...7/18em)
    else if (aValue.EqualsLiteral("veryverythinmathspace"))  i = 1;
    else if (aValue.EqualsLiteral("verythinmathspace"))      i = 2;
    else if (aValue.EqualsLiteral("thinmathspace"))          i = 3;
    else if (aValue.EqualsLiteral("mediummathspace"))        i = 4;
    else if (aValue.EqualsLiteral("thickmathspace"))         i = 5;
    else if (aValue.EqualsLiteral("verythickmathspace"))     i = 6;
    else if (aValue.EqualsLiteral("veryverythickmathspace")) i = 7;

    if (0 != i) // it was a namedspace value
      space = float(i)/float(18);

    if (isLeftSpace)
      aOperatorData->mLeftSpace = space;
    else
      aOperatorData->mRightSpace = space;
  }
}
Ejemplo n.º 3
0
static bool test_tofloat_helper(const nsString& aStr, float aExpected, bool aSuccess)
{
  int32_t result;
  return aStr.ToFloat(&result) == aExpected &&
         aSuccess ? result == NS_OK : result != NS_OK;
}