Пример #1
0
static
size_t iconText(char *buf, size_t len, struct QsWin *win)
{
  // TODO: consider saving this and only recomputing this if
  // one or more of the colors changes.
  // color strings
  char bgC[8]; // background color
  char gridC[8];
  char axisC[8];
  colorStr(bgC, win->bgR, win->bgG, win->bgB);
  colorStr(gridC, win->gridR, win->gridG, win->gridB);
  colorStr(axisC, win->axisR, win->axisG, win->axisB);

  return snprintf(buf, len,
      "<span bgcolor=\"%s\" fgcolor=\"%s\">["
      "<span fgcolor=\"%s\">-|-</span>"
      "]</span> ",
      bgC, gridC, axisC);
}
std::unique_ptr<BinaryPrimitive> tryParseColor(const StringPiece16& str) {
    StringPiece16 colorStr(util::trimWhitespace(str));
    const char16_t* start = colorStr.data();
    const size_t len = colorStr.size();
    if (len == 0 || start[0] != u'#') {
        return {};
    }

    android::Res_value value = { };
    bool error = false;
    if (len == 4) {
        value.dataType = android::Res_value::TYPE_INT_COLOR_RGB4;
        value.data = 0xff000000u;
        value.data |= parseHex(start[1], &error) << 20;
        value.data |= parseHex(start[1], &error) << 16;
        value.data |= parseHex(start[2], &error) << 12;
        value.data |= parseHex(start[2], &error) << 8;
        value.data |= parseHex(start[3], &error) << 4;
        value.data |= parseHex(start[3], &error);
    } else if (len == 5) {
        value.dataType = android::Res_value::TYPE_INT_COLOR_ARGB4;
        value.data |= parseHex(start[1], &error) << 28;
        value.data |= parseHex(start[1], &error) << 24;
        value.data |= parseHex(start[2], &error) << 20;
        value.data |= parseHex(start[2], &error) << 16;
        value.data |= parseHex(start[3], &error) << 12;
        value.data |= parseHex(start[3], &error) << 8;
        value.data |= parseHex(start[4], &error) << 4;
        value.data |= parseHex(start[4], &error);
    } else if (len == 7) {
        value.dataType = android::Res_value::TYPE_INT_COLOR_RGB8;
        value.data = 0xff000000u;
        value.data |= parseHex(start[1], &error) << 20;
        value.data |= parseHex(start[2], &error) << 16;
        value.data |= parseHex(start[3], &error) << 12;
        value.data |= parseHex(start[4], &error) << 8;
        value.data |= parseHex(start[5], &error) << 4;
        value.data |= parseHex(start[6], &error);
    } else if (len == 9) {
        value.dataType = android::Res_value::TYPE_INT_COLOR_ARGB8;
        value.data |= parseHex(start[1], &error) << 28;
        value.data |= parseHex(start[2], &error) << 24;
        value.data |= parseHex(start[3], &error) << 20;
        value.data |= parseHex(start[4], &error) << 16;
        value.data |= parseHex(start[5], &error) << 12;
        value.data |= parseHex(start[6], &error) << 8;
        value.data |= parseHex(start[7], &error) << 4;
        value.data |= parseHex(start[8], &error);
    } else {
        return {};
    }
    return error ? std::unique_ptr<BinaryPrimitive>() : util::make_unique<BinaryPrimitive>(value);
}
Пример #3
0
PRBool
nsAttrValue::ParseColor(const nsAString& aString, nsIDocument* aDocument)
{
  nsAutoString colorStr(aString);
  colorStr.CompressWhitespace(PR_TRUE, PR_TRUE);
  if (colorStr.IsEmpty()) {
    Reset();
    return PR_FALSE;
  }

  nscolor color;
  // No color names begin with a '#', but numerical colors do so
  // it is a very common first char
  if ((colorStr.CharAt(0) != '#') && NS_ColorNameToRGB(colorStr, &color)) {
    SetTo(colorStr);
    return PR_TRUE;
  }

  // Check if we are in compatibility mode
  if (aDocument->GetCompatibilityMode() == eCompatibility_NavQuirks) {
    NS_LooseHexToRGB(colorStr, &color);
  }
  else {
    if (colorStr.First() != '#') {
      Reset();
      return PR_FALSE;
    }
    colorStr.Cut(0, 1);
    if (!NS_HexToRGB(colorStr, &color)) {
      Reset();
      return PR_FALSE;
    }
  }

  PRInt32 colAsInt = static_cast<PRInt32>(color);
  PRInt32 tmp = colAsInt * NS_ATTRVALUE_INTEGERTYPE_MULTIPLIER;
  if (tmp / NS_ATTRVALUE_INTEGERTYPE_MULTIPLIER == colAsInt) {
    ResetIfSet();
    SetIntValueAndType(colAsInt, eColor);
  }
  else if (EnsureEmptyMiscContainer()) {
    MiscContainer* cont = GetMiscContainer();
    cont->mColor = color;
    cont->mType = eColor;
  }

  return PR_TRUE;
}
Пример #4
0
PRBool
nsAttrValue::ParseColor(const nsAString& aString)
{
  ResetIfSet();

  // FIXME (partially, at least): HTML5's algorithm says we shouldn't do
  // the whitespace compression, trimming, or the test for emptiness.
  // (I'm a little skeptical that we shouldn't do the whitespace
  // trimming; WebKit also does it.)
  nsAutoString colorStr(aString);
  colorStr.CompressWhitespace(PR_TRUE, PR_TRUE);
  if (colorStr.IsEmpty()) {
    return PR_FALSE;
  }

  nscolor color;
  // No color names begin with a '#'; in standards mode, all acceptable
  // numeric colors do.
  if (colorStr.First() == '#') {
    nsDependentString withoutHash(colorStr.get() + 1, colorStr.Length() - 1);
    if (NS_HexToRGB(withoutHash, &color)) {
      SetColorValue(color, aString);
      return PR_TRUE;
    }
  } else {
    if (NS_ColorNameToRGB(colorStr, &color)) {
      SetColorValue(color, aString);
      return PR_TRUE;
    }
  }

  // FIXME (maybe): HTML5 says we should handle system colors.  This
  // means we probably need another storage type, since we'd need to
  // handle dynamic changes.  However, I think this is a bad idea:
  // http://lists.whatwg.org/pipermail/whatwg-whatwg.org/2010-May/026449.html

  // Use NS_LooseHexToRGB as a fallback if nothing above worked.
  if (NS_LooseHexToRGB(colorStr, &color)) {
    SetColorValue(color, aString);
    return PR_TRUE;
  }

  return PR_FALSE;
}
Пример #5
0
SkString SkSVGDevice::AutoElement::addLinearGradientDef(const SkShader::GradientInfo& info,
                                                        const SkShader* shader) {
    SkASSERT(fResourceBucket);
    SkString id = fResourceBucket->addLinearGradient();

    {
        AutoElement gradient("linearGradient", fWriter);

        gradient.addAttribute("id", id);
        gradient.addAttribute("gradientUnits", "userSpaceOnUse");
        gradient.addAttribute("x1", info.fPoint[0].x());
        gradient.addAttribute("y1", info.fPoint[0].y());
        gradient.addAttribute("x2", info.fPoint[1].x());
        gradient.addAttribute("y2", info.fPoint[1].y());

        if (!shader->getLocalMatrix().isIdentity()) {
            this->addAttribute("gradientTransform", svg_transform(shader->getLocalMatrix()));
        }

        SkASSERT(info.fColorCount >= 2);
        for (int i = 0; i < info.fColorCount; ++i) {
            SkColor color = info.fColors[i];
            SkString colorStr(svg_color(color));

            {
                AutoElement stop("stop", fWriter);
                stop.addAttribute("offset", info.fColorOffsets[i]);
                stop.addAttribute("stop-color", colorStr.c_str());

                if (SK_AlphaOPAQUE != SkColorGetA(color)) {
                    stop.addAttribute("stop-opacity", svg_opacity(color));
                }
            }
        }
    }

    return id;
}
Пример #6
0
void
ShapesDialog::onSubscribeButtonClicked()
{
    dds::topic::qos::TopicQos topicQos = dp_.default_topic_qos()
                                         << dds::core::policy::Durability::Persistent()
                                         << dds::core::policy::DurabilityService(
                                                    dds::core::Duration(3600,0),
                                                    dds::core::policy::HistoryKind::KEEP_LAST,
                                                    100,
                                                    8192,
                                                    4196,
                                                    8192);

    dds::sub::qos::SubscriberQos SQos = dp_.default_subscriber_qos() << gQos_;
    dds::sub::Subscriber sub(dp_, SQos);
    int d = mainWidget.sizeSlider->value();
    QRect rect(0, 0, d, d);
    QRect constr(0, 0, IS_WIDTH, IS_HEIGHT);
    int x = static_cast<int>(constr.width() * ((float)rand() / RAND_MAX)*0.9F);
    int y = static_cast<int>(constr.height() * ((float)rand() / RAND_MAX)*0.9F);
    int sIdx = mainWidget.rShapeList->currentIndex();

    QColor gray = QColor(0x99, 0x99, 0x99);
    QBrush brush(gray, Qt::SolidPattern);

    QPen pen(QColor(0xff,0xff,0xff), 1, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin);

    std::vector<std::string> empty;
    filterParams_ = empty;
    std::string filterS;
    if (filterDialog_->isEnabled())
    {
        QRect rect =  filterDialog_->getFilterBounds();
        std::string x0 = lexicalCast(rect.x());
        std::string x1 = lexicalCast(rect.x() + rect.width() -d);
        std::string y0 = lexicalCast(rect.y());
        std::string y1 = lexicalCast(rect.y() + rect.height() -d);
        filterParams_.push_back(x0);
        filterParams_.push_back(x1);
        filterParams_.push_back(y0);
        filterParams_.push_back(y1);
        filterS = "(x BETWEEN "
            + filterParams_[0]
            + " AND "
            + filterParams_[1]
            + ") AND (y BETWEEN "
            + filterParams_[2]
            + " AND "
            + filterParams_[3]
            + ")";

        if (filterDialog_->filterOutside() == false)
        {
             filterS = "(x < "
                 + filterParams_[0]
                 + " ) OR ( x > "
                 + filterParams_[1]
                 + " ) OR (y < "
                 + filterParams_[2]
                 + ") OR ( y > "
                 + filterParams_[3]
                 + ")";
        }
    }

    switch (sIdx)
    {

        case CIRCLE:
        {
            dds::topic::Topic<ShapeType> circle_(dp_, circleTopicName, topicQos);
	        dds::topic::ContentFilteredTopic<ShapeType> cfcircle_(dds::core::null);
            dds::sub::DataReader<ShapeType> dr(sub, circle_, readerQos_.get_qos());

            if (filterDialog_->isEnabled())
            {
                std::string tname = "CFCircle";
                const dds::topic::Filter filter(filterS);
                std::cout << filterS << std::endl;
                dds::topic::ContentFilteredTopic<ShapeType> cfcircle_(circle_, "CFCircle", filter);
	            dds::sub::DataReader<ShapeType> dr2(sub, cfcircle_, readerQos_.get_qos());
                dr = dr2;
            }
            for (int i = 0; i < CN; ++i)
            {
                std::string colorStr(colorString_[i]);

                DDSShapeDynamics::ref_type
                dynamics(new DDSShapeDynamics(x, y, dr, colorStr, i));

                Shape::ref_type
                circle(new Circle(rect, dynamics, pen, brush, true));

                dynamics->setShape(circle);
                shapesWidget->addShape(circle);
            }
            break;
        }

        case SQUARE:
        {
            dds::topic::Topic<ShapeType> square_(dp_, squareTopicName, topicQos);
            dds::sub::LoanedSamples<ShapeType>::iterator si;
	        dds::topic::ContentFilteredTopic<ShapeType> cfsquare_(dds::core::null);
            dds::sub::DataReader<ShapeType> dr(sub, square_, readerQos_.get_qos());

            if (filterDialog_->isEnabled())
            {
                std::string tname = "CFSquare";
                const dds::topic::Filter filter(filterS);
                std::cout << filterS << std::endl;
                dds::topic::ContentFilteredTopic<ShapeType> cfsquare_(square_, "CFSquare", filter);
	            dds::sub::DataReader<ShapeType> dr2(sub, cfsquare_, readerQos_.get_qos());
                dr = dr2;
            }

            for (int i = 0; i < CN; ++i)
            {
                std::string colorStr(colorString_[i]);

                DDSShapeDynamics::ref_type
                dynamics(new DDSShapeDynamics(x, y, dr, colorStr, i));

                Shape::ref_type
                square(new Square(rect, dynamics, pen, brush, true));

                dynamics->setShape(square);
                shapesWidget->addShape(square);
            }
            break;
        }

        case TRIANGLE:
        {
            dds::topic::Topic<ShapeType> triangle_(dp_, triangleTopicName, topicQos);
            dds::sub::LoanedSamples<ShapeType>::iterator si;
	        dds::topic::ContentFilteredTopic<ShapeType> cftriangle_(dds::core::null);
            dds::sub::DataReader<ShapeType> dr(sub, triangle_, readerQos_.get_qos());

            if (filterDialog_->isEnabled())
            {
                std::string tname = "CFTriangle";
                const dds::topic::Filter filter(filterS);
                std::cout << filterS << std::endl;
                dds::topic::ContentFilteredTopic<ShapeType> cftriangle_(triangle_, "CFTriangle", filter);
	            dds::sub::DataReader<ShapeType> dr2(sub, cftriangle_, readerQos_.get_qos());
                dr = dr2;
            }

            for (int i = 0; i < CN; ++i)
            {
                std::string colorStr(colorString_[i]);

                DDSShapeDynamics::ref_type
                dynamics(new DDSShapeDynamics(x, y, dr, colorStr, i));

                Shape::ref_type
                triangle(new Triangle(rect, dynamics, pen, brush, true));

                dynamics->setShape(triangle);
                shapesWidget->addShape(triangle);
            }
        break;
        }

        default:
            break;
    }
}
Пример #7
0
 QColor ToolchainItem::fontColor() const
 {
   return QColor(QString().fromStdString(colorStr("font")));
 }
Пример #8
0
 QColor ToolchainItem::darkColor() const
 {
   return QColor(QString().fromStdString(colorStr("dark")));
 }
Пример #9
0
 QColor ToolchainItem::lightColor() const
 {
   return QColor(QString().fromStdString(colorStr("light")));
 }