本文整理汇总了C++中SkString::appendScalar方法的典型用法代码示例。如果您正苦于以下问题:C++ SkString::appendScalar方法的具体用法?C++ SkString::appendScalar怎么用?C++ SkString::appendScalar使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SkString
的用法示例。
在下文中一共展示了SkString::appendScalar方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: PointsToString
SkString* SkObjectParser::PointsToString(const SkPoint pts[], size_t count) {
SkString* mPoints = new SkString("SkPoints pts[]: ");
for (unsigned int i = 0; i < count; i++) {
mPoints->append("(");
mPoints->appendScalar(pts[i].fX);
mPoints->append(",");
mPoints->appendScalar(pts[i].fY);
mPoints->append(")");
}
return mPoints;
}
示例2: RectToString
SkString* SkObjectParser::RectToString(const SkRect& rect, const char* title) {
SkString* mRect = new SkString;
if (nullptr == title) {
mRect->append("SkRect: ");
} else {
mRect->append(title);
}
mRect->append("(");
mRect->appendScalar(rect.left());
mRect->append(", ");
mRect->appendScalar(rect.top());
mRect->append(", ");
mRect->appendScalar(rect.right());
mRect->append(", ");
mRect->appendScalar(rect.bottom());
mRect->append(")");
return mRect;
}
示例3: translate
void SkSVGSVG::translate(SkSVGParser& parser, bool defState) {
SkScalar height, width;
SkScalar viewBox[4];
const char* hSuffix = SkParse::FindScalar(f_height.c_str(), &height);
if (strcmp(hSuffix, "pt") == 0)
height = SkScalarMulDiv(height, SK_Scalar1 * 72, SK_Scalar1 * 96);
const char* wSuffix = SkParse::FindScalar(f_width.c_str(), &width);
if (strcmp(wSuffix, "pt") == 0)
width = SkScalarMulDiv(width, SK_Scalar1 * 72, SK_Scalar1 * 96);
SkParse::FindScalars(f_viewBox.c_str(), viewBox, 4);
SkRect box;
box.fLeft = SkScalarDiv(viewBox[0], width);
box.fTop = SkScalarDiv(viewBox[1], height);
box.fRight = SkScalarDiv(viewBox[2], width);
box.fBottom = SkScalarDiv(viewBox[3], height);
if (box.fLeft == 0 && box.fTop == 0 &&
box.fRight == SK_Scalar1 && box.fBottom == SK_Scalar1)
return;
parser._startElement("matrix");
if (box.fLeft != 0) {
SkString x;
x.appendScalar(box.fLeft);
parser._addAttributeLen("translateX", x.c_str(), x.size());
}
if (box.fTop != 0) {
SkString y;
y.appendScalar(box.fTop);
parser._addAttributeLen("translateY", y.c_str(), y.size());
}
if (box.fRight != SK_Scalar1) {
SkString x;
x.appendScalar(box.fRight);
parser._addAttributeLen("scaleX", x.c_str(), x.size());
}
if (box.fBottom != SK_Scalar1) {
SkString y;
y.appendScalar(box.fBottom);
parser._addAttributeLen("scaleY", y.c_str(), y.size());
}
parser._endElement();
}
示例4: show_k_text
static void show_k_text(SkCanvas* canvas, SkScalar x, SkScalar y, const SkScalar k[]) {
SkPaint paint;
paint.setTextSize(SkIntToScalar(24));
paint.setAntiAlias(true);
for (int i = 0; i < 4; ++i) {
SkString str;
str.appendScalar(k[i]);
SkScalar width = paint.measureText(str.c_str(), str.size());
canvas->drawText(str.c_str(), str.size(), x, y + paint.getTextSize(), paint);
x += width + SkIntToScalar(10);
}
}
示例5: apply_perspective_to_coordinates
/**
* Returns PS function code that applies inverse perspective
* to a x, y point.
* The function assumes that the stack has at least two elements,
* and that the top 2 elements are numeric values.
* After executing this code on a PS stack, the last 2 elements are updated
* while the rest of the stack is preserved intact.
* inversePerspectiveMatrix is the inverse perspective matrix.
*/
static SkString apply_perspective_to_coordinates(
const SkMatrix& inversePerspectiveMatrix) {
SkString code;
if (!inversePerspectiveMatrix.hasPerspective()) {
return code;
}
// Perspective matrix should be:
// 1 0 0
// 0 1 0
// p0 p1 p2
const SkScalar p0 = inversePerspectiveMatrix[SkMatrix::kMPersp0];
const SkScalar p1 = inversePerspectiveMatrix[SkMatrix::kMPersp1];
const SkScalar p2 = inversePerspectiveMatrix[SkMatrix::kMPersp2];
// y = y / (p2 + p0 x + p1 y)
// x = x / (p2 + p0 x + p1 y)
// Input on stack: x y
code.append(" dup "); // x y y
code.appendScalar(p1); // x y y p1
code.append(" mul " // x y y*p1
" 2 index "); // x y y*p1 x
code.appendScalar(p0); // x y y p1 x p0
code.append(" mul "); // x y y*p1 x*p0
code.appendScalar(p2); // x y y p1 x*p0 p2
code.append(" add " // x y y*p1 x*p0+p2
"add " // x y y*p1+x*p0+p2
"3 1 roll " // y*p1+x*p0+p2 x y
"2 index " // z x y y*p1+x*p0+p2
"div " // y*p1+x*p0+p2 x y/(y*p1+x*p0+p2)
"3 1 roll " // y/(y*p1+x*p0+p2) y*p1+x*p0+p2 x
"exch " // y/(y*p1+x*p0+p2) x y*p1+x*p0+p2
"div " // y/(y*p1+x*p0+p2) x/(y*p1+x*p0+p2)
"exch\n"); // x/(y*p1+x*p0+p2) y/(y*p1+x*p0+p2)
return code;
}
示例6: onDrawContent
void onDrawContent(SkCanvas* canvas) override {
fCell.set(this->height() / 2, this->height() / 2);
SkScalar trans[2];
fTrans.timeToValues(fCurrTime, trans);
for (int y = 0; y < 2; ++y) {
for (int x = 0; x < 2; ++x) {
int index = y * 2 + x;
SkAutoCanvasRestore acr(canvas, true);
canvas->translate(fCell.width() * x, fCell.height() * y);
SkRect r = SkRect::MakeWH(fCell.width(), fCell.height());
r.inset(4, 4);
canvas->clipRect(r);
this->drawHere(canvas, SkFilterQuality(index), trans[0], trans[1]);
}
}
this->drawBorders(canvas);
const SkScalar textX = fCell.width() * 2 + 30;
SkPaint paint;
paint.setAntiAlias(true);
paint.setTextSize(36);
SkString str;
str.appendScalar(fScale);
canvas->drawText(str.c_str(), str.size(), textX, 100, paint);
str.reset(); str.appendScalar(fAngle);
canvas->drawText(str.c_str(), str.size(), textX, 150, paint);
str.reset(); str.appendScalar(trans[0]);
canvas->drawText(str.c_str(), str.size(), textX, 200, paint);
str.reset(); str.appendScalar(trans[1]);
canvas->drawText(str.c_str(), str.size(), textX, 250, paint);
}
示例7: draw
void draw(SkCanvas* canvas) {
SkMatrix m;
m.setIdentity();
m.set(SkMatrix::kMPersp0, -0.004f);
SkAutoCanvasRestore autoRestore(canvas, true);
canvas->translate(22, 144);
SkPaint black;
black.setAntiAlias(true);
black.setTextSize(24);
SkPaint gray = black;
gray.setColor(0xFF9f9f9f);
SkString string;
string.appendScalar(m.getPerspX());
canvas->drawString(string, 0, -72, gray);
canvas->concat(m);
canvas->drawString(string, 0, 0, black);
}
示例8: onDrawContent
void onDrawContent(SkCanvas* canvas) override {
SkASSERT(fParent);
SkScalar x = fSliderRange * (*fOutput - fMin) / (fMax - fMin);
fSlider.offsetTo(SkScalarPin(x, 0.0f, fSliderRange), fSlider.fTop);
SkString valueStr;
valueStr.appendScalar(*fOutput);
this->drawLabel(canvas, valueStr);
SkPaint sliderPaint;
sliderPaint.setColor(0xFFF3F3F3);
canvas->drawRect(fSlider, sliderPaint);
SkPaint ctrlRegionPaint;
ctrlRegionPaint.setColor(0xFFFFFFFF);
ctrlRegionPaint.setStyle(SkPaint::kStroke_Style);
ctrlRegionPaint.setStrokeWidth(2.0f);
canvas->drawRect(fCtrlRegion, ctrlRegionPaint);
}
示例9: RRectToString
SkString* SkObjectParser::RRectToString(const SkRRect& rrect, const char* title) {
SkString* mRRect = new SkString;
if (nullptr == title) {
mRRect->append("SkRRect (");
if (rrect.isEmpty()) {
mRRect->append("empty");
} else if (rrect.isRect()) {
mRRect->append("rect");
} else if (rrect.isOval()) {
mRRect->append("oval");
} else if (rrect.isSimple()) {
mRRect->append("simple");
} else if (rrect.isNinePatch()) {
mRRect->append("nine-patch");
} else {
SkASSERT(rrect.isComplex());
mRRect->append("complex");
}
mRRect->append("): ");
} else {
mRRect->append(title);
}
mRRect->append("(");
mRRect->appendScalar(rrect.rect().left());
mRRect->append(", ");
mRRect->appendScalar(rrect.rect().top());
mRRect->append(", ");
mRRect->appendScalar(rrect.rect().right());
mRRect->append(", ");
mRRect->appendScalar(rrect.rect().bottom());
mRRect->append(") radii: (");
for (int i = 0; i < 4; ++i) {
const SkVector& radii = rrect.radii((SkRRect::Corner) i);
mRRect->appendScalar(radii.fX);
mRRect->append(", ");
mRRect->appendScalar(radii.fY);
if (i < 3) {
mRRect->append(", ");
}
}
mRRect->append(")");
return mRRect;
}
示例10: writeScalarAsText
bool SkWStream::writeScalarAsText(SkScalar value)
{
SkString tmp;
tmp.appendScalar(value);
return this->write(tmp.c_str(), tmp.size());
}
示例11: getOverviewText
void SkDebugger::getOverviewText(const SkTDArray<double>* typeTimes,
double totTime,
SkString* overview,
int numRuns) {
const SkTDArray<SkDrawCommand*>& commands = this->getDrawCommands();
SkTDArray<int> counts;
counts.setCount(LAST_DRAWTYPE_ENUM+1);
for (int i = 0; i < LAST_DRAWTYPE_ENUM+1; ++i) {
counts[i] = 0;
}
for (int i = 0; i < commands.count(); i++) {
counts[commands[i]->getType()]++;
}
overview->reset();
int total = 0;
#ifdef SK_DEBUG
double totPercent = 0, tempSum = 0;
#endif
for (int i = 0; i < LAST_DRAWTYPE_ENUM+1; ++i) {
if (0 == counts[i]) {
// if there were no commands of this type then they should've consumed no time
SkASSERT(NULL == typeTimes || 0.0 == (*typeTimes)[i]);
continue;
}
overview->append(SkDrawCommand::GetCommandString((DrawType) i));
overview->append(": ");
overview->appendS32(counts[i]);
if (NULL != typeTimes && totTime >= 0.0) {
overview->append(" - ");
overview->appendf("%.2f", (*typeTimes)[i]/(float)numRuns);
overview->append("ms");
overview->append(" - ");
double percent = 100.0*(*typeTimes)[i]/totTime;
overview->appendf("%.2f", percent);
overview->append("%");
#ifdef SK_DEBUG
totPercent += percent;
tempSum += (*typeTimes)[i];
#endif
}
overview->append("<br/>");
total += counts[i];
}
#ifdef SK_DEBUG
if (NULL != typeTimes) {
SkASSERT(SkScalarNearlyEqual(SkDoubleToScalar(totPercent),
SkDoubleToScalar(100.0)));
SkASSERT(SkScalarNearlyEqual(SkDoubleToScalar(tempSum),
SkDoubleToScalar(totTime)));
}
#endif
if (totTime > 0.0) {
overview->append("Total Time: ");
overview->appendf("%.2f", totTime/(float)numRuns);
overview->append("ms");
#ifdef SK_DEBUG
overview->append(" ");
overview->appendScalar(SkDoubleToScalar(totPercent));
overview->append("% ");
#endif
overview->append("<br/>");
}
SkString totalStr;
totalStr.append("Total Draw Commands: ");
totalStr.appendScalar(SkDoubleToScalar(total));
totalStr.append("<br/>");
overview->insert(0, totalStr);
overview->append("<br/>");
overview->append("SkPicture Width: ");
overview->appendS32(pictureWidth());
overview->append("px<br/>");
overview->append("SkPicture Height: ");
overview->appendS32(pictureHeight());
overview->append("px");
}
示例12: addScalarAttribute
void SkXMLWriter::addScalarAttribute(const char name[], SkScalar value)
{
SkString tmp;
tmp.appendScalar(value);
this->addAttribute(name, tmp.c_str());
}
示例13: PathToString
SkString* SkObjectParser::PathToString(const SkPath& path) {
SkString* mPath = new SkString("Path (");
static const char* gFillStrings[] = {
"Winding", "EvenOdd", "InverseWinding", "InverseEvenOdd"
};
mPath->append(gFillStrings[path.getFillType()]);
mPath->append(", ");
static const char* gConvexityStrings[] = {
"Unknown", "Convex", "Concave"
};
SkASSERT(SkPath::kConcave_Convexity == 2);
mPath->append(gConvexityStrings[path.getConvexity()]);
mPath->append(", ");
if (path.isRect(nullptr)) {
mPath->append("isRect, ");
} else {
mPath->append("isNotRect, ");
}
mPath->appendS32(path.countVerbs());
mPath->append("V, ");
mPath->appendS32(path.countPoints());
mPath->append("P): ");
static const char* gVerbStrings[] = {
"Move", "Line", "Quad", "Conic", "Cubic", "Close", "Done"
};
static const int gPtsPerVerb[] = { 1, 1, 2, 2, 3, 0, 0 };
static const int gPtOffsetPerVerb[] = { 0, 1, 1, 1, 1, 0, 0 };
SkASSERT(SkPath::kDone_Verb == 6);
SkPath::Iter iter(const_cast<SkPath&>(path), false);
SkPath::Verb verb;
SkPoint points[4];
for(verb = iter.next(points, false);
verb != SkPath::kDone_Verb;
verb = iter.next(points, false)) {
mPath->append(gVerbStrings[verb]);
mPath->append(" ");
for (int i = 0; i < gPtsPerVerb[verb]; ++i) {
mPath->append("(");
mPath->appendScalar(points[gPtOffsetPerVerb[verb]+i].fX);
mPath->append(", ");
mPath->appendScalar(points[gPtOffsetPerVerb[verb]+i].fY);
mPath->append(")");
}
if (SkPath::kConic_Verb == verb) {
mPath->append("(");
mPath->appendScalar(iter.conicWeight());
mPath->append(")");
}
mPath->append(" ");
}
SkString* boundStr = SkObjectParser::RectToString(path.getBounds(), " Bound: ");
if (boundStr) {
mPath->append(*boundStr);
delete boundStr;
}
return mPath;
}
示例14: TestString
static void TestString(skiatest::Reporter* reporter) {
SkString a;
SkString b((size_t)0);
SkString c("");
SkString d(NULL, 0);
REPORTER_ASSERT(reporter, a.isEmpty());
REPORTER_ASSERT(reporter, a == b && a == c && a == d);
a.set("hello");
b.set("hellox", 5);
c.set(a);
d.resize(5);
memcpy(d.writable_str(), "helloz", 5);
REPORTER_ASSERT(reporter, !a.isEmpty());
REPORTER_ASSERT(reporter, a.size() == 5);
REPORTER_ASSERT(reporter, a == b && a == c && a == d);
REPORTER_ASSERT(reporter, a.equals("hello", 5));
REPORTER_ASSERT(reporter, a.equals("hello"));
REPORTER_ASSERT(reporter, !a.equals("help"));
SkString e(a);
SkString f("hello");
SkString g("helloz", 5);
REPORTER_ASSERT(reporter, a == e && a == f && a == g);
b.set("world");
c = b;
REPORTER_ASSERT(reporter, a != b && a != c && b == c);
a.append(" world");
e.append("worldz", 5);
e.insert(5, " ");
f.set("world");
f.prepend("hello ");
REPORTER_ASSERT(reporter, a.equals("hello world") && a == e && a == f);
a.reset();
b.resize(0);
REPORTER_ASSERT(reporter, a.isEmpty() && b.isEmpty() && a == b);
a.set("a");
a.set("ab");
a.set("abc");
a.set("abcd");
a.set("");
a.appendS64(72036854775808LL, 0);
REPORTER_ASSERT(reporter, a.equals("72036854775808"));
a.set("");
a.appendS64(-1844674407370LL, 0);
REPORTER_ASSERT(reporter, a.equals("-1844674407370"));
a.set("");
a.appendS64(73709551616LL, 15);
REPORTER_ASSERT(reporter, a.equals("000073709551616"));
a.set("");
a.appendS64(-429496729612LL, 15);
REPORTER_ASSERT(reporter, a.equals("-000429496729612"));
static const struct {
SkScalar fValue;
const char* fString;
} gRec[] = {
{ 0, "0" },
{ SK_Scalar1, "1" },
{ -SK_Scalar1, "-1" },
{ SK_Scalar1/2, "0.5" },
#ifdef SK_SCALAR_IS_FLOAT
{ 3.4028234e38f, "3.4028235e+38" },
{ -3.4028234e38f, "-3.4028235e+38" },
#endif
};
for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); i++) {
a.reset();
a.appendScalar(gRec[i].fValue);
REPORTER_ASSERT(reporter, a.size() <= SkStrAppendScalar_MaxSize);
// SkDebugf(" received <%s> expected <%s>\n", a.c_str(), gRec[i].fString);
REPORTER_ASSERT(reporter, a.equals(gRec[i].fString));
}
}
示例15: ScalarToString
SkString* SkObjectParser::ScalarToString(SkScalar x, const char* text) {
SkString* mScalar = new SkString(text);
mScalar->append(" ");
mScalar->appendScalar(x);
return mScalar;
}