本文整理汇总了C++中SkPaint::setFlags方法的典型用法代码示例。如果您正苦于以下问题:C++ SkPaint::setFlags方法的具体用法?C++ SkPaint::setFlags怎么用?C++ SkPaint::setFlags使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SkPaint
的用法示例。
在下文中一共展示了SkPaint::setFlags方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: drawContents
void HelloWorldWindow::drawContents(SkCanvas* canvas) {
// Clear background
canvas->drawColor(SK_ColorWHITE);
SkPaint paint;
paint.setColor(SK_ColorRED);
// Draw a rectangle with red paint
SkRect rect = SkRect::MakeXYWH(10, 10, 128, 128);
canvas->drawRect(rect, paint);
// Set up a linear gradient and draw a circle
{
SkPoint linearPoints[] = {
{0, 0},
{300, 300}
};
SkColor linearColors[] = {SK_ColorGREEN, SK_ColorBLACK};
paint.setShader(SkGradientShader::MakeLinear(
linearPoints, linearColors, nullptr, 2,
SkShader::kMirror_TileMode));
paint.setFlags(SkPaint::kAntiAlias_Flag);
canvas->drawCircle(200, 200, 64, paint);
// Detach shader
paint.setShader(nullptr);
}
// Draw a message with a nice black paint.
paint.setFlags(
SkPaint::kAntiAlias_Flag |
SkPaint::kSubpixelText_Flag | // ... avoid waggly text when rotating.
SkPaint::kUnderlineText_Flag);
paint.setColor(SK_ColorBLACK);
paint.setTextSize(20);
canvas->save();
static const char message[] = "Hello World";
// Translate and rotate
canvas->translate(300, 300);
fRotationAngle += 0.2f;
if (fRotationAngle > 360) {
fRotationAngle -= 360;
}
canvas->rotate(fRotationAngle);
// Draw the text:
canvas->drawText(message, strlen(message), 0, 0, paint);
canvas->restore();
}
示例2: onRevalidate
SkRect Text::onRevalidate(InvalidationController*, const SkMatrix&) {
// TODO: we could potentially track invals which don't require rebuilding the blob.
SkPaint font;
font.setFlags(fFlags);
font.setTypeface(fTypeface);
font.setTextSize(fSize);
font.setTextScaleX(fScaleX);
font.setTextSkewX(fSkewX);
font.setTextAlign(fAlign);
font.setHinting(fHinting);
// First, convert to glyphIDs.
font.setTextEncoding(SkPaint::kUTF8_TextEncoding);
SkSTArray<256, SkGlyphID, true> glyphs;
glyphs.reset(font.textToGlyphs(fText.c_str(), fText.size(), nullptr));
SkAssertResult(font.textToGlyphs(fText.c_str(), fText.size(), glyphs.begin()) == glyphs.count());
font.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
// Next, build the cached blob.
SkTextBlobBuilder builder;
const auto& buf = builder.allocRun(font, glyphs.count(), 0, 0, nullptr);
if (!buf.glyphs) {
fBlob.reset();
return SkRect::MakeEmpty();
}
memcpy(buf.glyphs, glyphs.begin(), glyphs.count() * sizeof(SkGlyphID));
fBlob = builder.make();
return fBlob
? fBlob->bounds().makeOffset(fPosition.x(), fPosition.y())
: SkRect::MakeEmpty();
}
示例3: onDrawContent
virtual void onDrawContent(SkCanvas* canvas) {
const char* str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
SkPaint paint;
SkScalar x = SkIntToScalar(10);
SkScalar y = SkIntToScalar(20);
paint.setFlags(0x105);
paint.setARGB(fByte, 0xFF, 0xFF, 0xFF);
paint.setMaskFilter(SkBlurMaskFilter::Create(SkIntToScalar(3),
SkBlurMaskFilter::kNormal_BlurStyle));
paint.getMaskFilter()->unref();
SkRandom rand;
for (int ps = 6; ps <= 35; ps++) {
paint.setColor(rand.nextU() | (0xFF << 24));
paint.setTextSize(SkIntToScalar(ps));
paint.setTextSize(SkIntToScalar(24));
canvas->drawText(str, strlen(str), x, y, paint);
y += paint.getFontMetrics(NULL);
}
if (false) { // avoid bit rot, suppress warning
check_for_nonwhite(canvas->getDevice()->accessBitmap(false), fByte);
SkDebugf("------ byte %x\n", fByte);
}
if (false) {
fByte += 1;
fByte &= 0xFF;
this->inval(NULL);
}
}
示例4: drawmarshmallow
static void drawmarshmallow(SkCanvas* canvas) {
SkBitmap bitmap;
SkPaint paint;
SkRect r;
SkMatrix m;
SkImageDecoder::DecodeFile("/Users/reed/Downloads/3elfs.jpg", &bitmap);
if (!bitmap.pixelRef()) {
return;
}
SkShader* s = SkShader::CreateBitmapShader(bitmap,
SkShader::kRepeat_TileMode,
SkShader::kRepeat_TileMode);
paint.setShader(s)->unref();
m.setTranslate(SkIntToScalar(250), SkIntToScalar(134));
s->setLocalMatrix(m);
r.set(SkIntToScalar(250),
SkIntToScalar(134),
SkIntToScalar(250 + 449),
SkIntToScalar(134 + 701));
paint.setFlags(2);
canvas->drawRect(r, paint);
}
示例5: uncachedDrawTextBlob
void GrStencilAndCoverTextContext::uncachedDrawTextBlob(GrContext* context,
GrDrawContext* dc,
const GrClip& clip,
const SkPaint& skPaint,
const SkMatrix& viewMatrix,
const SkSurfaceProps& props,
const SkTextBlob* blob,
SkScalar x, SkScalar y,
SkDrawFilter* drawFilter,
const SkIRect& clipBounds) {
SkPaint runPaint = skPaint;
SkTextBlobRunIterator it(blob);
for (;!it.done(); it.next()) {
size_t textLen = it.glyphCount() * sizeof(uint16_t);
const SkPoint& offset = it.offset();
// applyFontToPaint() always overwrites the exact same attributes,
// so it is safe to not re-seed the paint for this reason.
it.applyFontToPaint(&runPaint);
if (drawFilter && !drawFilter->filter(&runPaint, SkDrawFilter::kText_Type)) {
// A false return from filter() means we should abort the current draw.
runPaint = skPaint;
continue;
}
runPaint.setFlags(GrTextUtils::FilterTextFlags(props, runPaint));
GrPaint grPaint;
if (!SkPaintToGrPaint(context, dc, runPaint, viewMatrix, &grPaint)) {
return;
}
switch (it.positioning()) {
case SkTextBlob::kDefault_Positioning:
this->drawText(context, dc, clip, grPaint, runPaint, viewMatrix, props,
(const char *)it.glyphs(),
textLen, x + offset.x(), y + offset.y(), clipBounds);
break;
case SkTextBlob::kHorizontal_Positioning:
this->drawPosText(context, dc, clip, grPaint, runPaint, viewMatrix, props,
(const char*)it.glyphs(),
textLen, it.pos(), 1, SkPoint::Make(x, y + offset.y()),
clipBounds);
break;
case SkTextBlob::kFull_Positioning:
this->drawPosText(context, dc, clip, grPaint, runPaint, viewMatrix, props,
(const char*)it.glyphs(),
textLen, it.pos(), 2, SkPoint::Make(x, y), clipBounds);
break;
}
if (drawFilter) {
// A draw filter may change the paint arbitrarily, so we must re-seed in this case.
runPaint = skPaint;
}
}
}
示例6: paintContents
void LinkHighlight::paintContents(WebCanvas* canvas, const WebRect&, WebContentLayerClient::PaintingControlSetting paintingControl)
{
if (!m_node || !m_node->layoutObject())
return;
SkPaint paint;
paint.setStyle(SkPaint::kFill_Style);
paint.setFlags(SkPaint::kAntiAlias_Flag);
paint.setColor(m_node->layoutObject()->style()->tapHighlightColor().rgb());
canvas->drawPath(m_path.skPath(), paint);
}
示例7: make_textstrip
static void make_textstrip(SkBitmap* bm) {
bm->setConfig(SkBitmap::kRGB_565_Config, 200, 18);
bm->allocPixels();
bm->eraseColor(SK_ColorWHITE);
SkCanvas canvas(*bm);
SkPaint paint;
const char* s = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit";
paint.setFlags(paint.getFlags() | SkPaint::kAntiAlias_Flag
| SkPaint::kDevKernText_Flag);
paint.setTextSize(SkIntToScalar(14));
canvas.drawText(s, strlen(s), SkIntToScalar(8), SkIntToScalar(14), paint);
}
示例8: paintOp_rp
static void paintOp_rp(SkCanvas*, SkReader32* reader, uint32_t op32,
SkGPipeState* state) {
size_t offset = reader->offset();
size_t stop = offset + PaintOp_unpackData(op32);
SkPaint* p = state->editPaint();
do {
uint32_t p32 = reader->readU32();
unsigned op = PaintOp_unpackOp(p32);
unsigned data = PaintOp_unpackData(p32);
// SkDebugf(" read %08X op=%d flags=%d data=%d\n", p32, op, done, data);
switch (op) {
case kReset_PaintOp: p->reset(); break;
case kFlags_PaintOp: p->setFlags(data); break;
case kColor_PaintOp: p->setColor(reader->readU32()); break;
case kFilterLevel_PaintOp: p->setFilterQuality((SkFilterQuality)data); break;
case kStyle_PaintOp: p->setStyle((SkPaint::Style)data); break;
case kJoin_PaintOp: p->setStrokeJoin((SkPaint::Join)data); break;
case kCap_PaintOp: p->setStrokeCap((SkPaint::Cap)data); break;
case kWidth_PaintOp: p->setStrokeWidth(reader->readScalar()); break;
case kMiter_PaintOp: p->setStrokeMiter(reader->readScalar()); break;
case kEncoding_PaintOp:
p->setTextEncoding((SkPaint::TextEncoding)data);
break;
case kHinting_PaintOp: p->setHinting((SkPaint::Hinting)data); break;
case kAlign_PaintOp: p->setTextAlign((SkPaint::Align)data); break;
case kTextSize_PaintOp: p->setTextSize(reader->readScalar()); break;
case kTextScaleX_PaintOp: p->setTextScaleX(reader->readScalar()); break;
case kTextSkewX_PaintOp: p->setTextSkewX(reader->readScalar()); break;
case kFlatIndex_PaintOp: {
PaintFlats pf = (PaintFlats)PaintOp_unpackFlags(p32);
unsigned index = data;
set_paintflat(p, state->getFlat(index), pf);
break;
}
case kTypeface_PaintOp:
SkASSERT(SkToBool(state->getFlags() &
SkGPipeWriter::kCrossProcess_Flag));
p->setTypeface(state->getTypeface(data));
break;
default: SkDEBUGFAIL("bad paintop"); return;
}
SkASSERT(reader->offset() <= stop);
} while (reader->offset() < stop);
}
示例9: paintContents
void LinkHighlightImpl::paintContents(WebDisplayItemList* webDisplayItemList, WebContentLayerClient::PaintingControlSetting paintingControl)
{
if (!m_node || !m_node->layoutObject())
return;
SkPictureRecorder recorder;
gfx::Rect visualRect = paintableRegion();
SkCanvas* canvas = recorder.beginRecording(visualRect.width(), visualRect.height());
SkPaint paint;
paint.setStyle(SkPaint::kFill_Style);
paint.setFlags(SkPaint::kAntiAlias_Flag);
paint.setColor(m_node->layoutObject()->style()->tapHighlightColor().rgb());
canvas->drawPath(m_path.getSkPath(), paint);
webDisplayItemList->appendDrawingItem(WebRect(visualRect.x(), visualRect.y(),
visualRect.width(), visualRect.height()), recorder.finishRecordingAsPicture());
}
示例10: drawTextBlob
void SkBaseDevice::drawTextBlob(const SkDraw& draw, const SkTextBlob* blob, SkScalar x, SkScalar y,
const SkPaint &paint, SkDrawFilter* drawFilter) {
SkPaint runPaint = paint;
SkTextBlobRunIterator it(blob);
for (;!it.done(); it.next()) {
size_t textLen = it.glyphCount() * sizeof(uint16_t);
const SkPoint& offset = it.offset();
// applyFontToPaint() always overwrites the exact same attributes,
// so it is safe to not re-seed the paint for this reason.
it.applyFontToPaint(&runPaint);
if (drawFilter && !drawFilter->filter(&runPaint, SkDrawFilter::kText_Type)) {
// A false return from filter() means we should abort the current draw.
runPaint = paint;
continue;
}
runPaint.setFlags(this->filterTextFlags(runPaint));
switch (it.positioning()) {
case SkTextBlob::kDefault_Positioning:
this->drawText(draw, it.glyphs(), textLen, x + offset.x(), y + offset.y(), runPaint);
break;
case SkTextBlob::kHorizontal_Positioning:
this->drawPosText(draw, it.glyphs(), textLen, it.pos(), 1,
SkPoint::Make(x, y + offset.y()), runPaint);
break;
case SkTextBlob::kFull_Positioning:
this->drawPosText(draw, it.glyphs(), textLen, it.pos(), 2,
SkPoint::Make(x, y), runPaint);
break;
default:
SkFAIL("unhandled positioning mode");
}
if (drawFilter) {
// A draw filter may change the paint arbitrarily, so we must re-seed in this case.
runPaint = paint;
}
}
}
示例11: paintContents
void LinkHighlightImpl::paintContents(WebDisplayItemList* webDisplayItemList, const WebRect& webClipRect, WebContentLayerClient::PaintingControlSetting paintingControl)
{
if (!m_node || !m_node->layoutObject())
return;
SkPictureRecorder recorder;
SkCanvas* canvas = recorder.beginRecording(webClipRect.width, webClipRect.height);
canvas->translate(-webClipRect.x, -webClipRect.y);
SkPaint paint;
paint.setStyle(SkPaint::kFill_Style);
paint.setFlags(SkPaint::kAntiAlias_Flag);
paint.setColor(m_node->layoutObject()->style()->tapHighlightColor().rgb());
canvas->drawPath(m_path.skPath(), paint);
RefPtr<const SkPicture> picture = adoptRef(recorder.endRecording());
// TODO(wkorman): Pass actual visual rect with the drawing item.
webDisplayItemList->appendDrawingItem(IntRect(), picture.get());
}
示例12: onDrawContent
virtual void onDrawContent(SkCanvas* canvas) {
SkAutoCanvasRestore restore(canvas, false);
{
SkRect r;
r.set(0, 0, SkIntToScalar(1000), SkIntToScalar(20));
// canvas->saveLayer(&r, NULL, SkCanvas::kHasAlphaLayer_SaveFlag);
}
SkPaint paint;
// const uint16_t glyphs[] = { 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19 };
int index = fHints % SK_ARRAY_COUNT(gHints);
index = 1;
// const char* style = gHints[index].fName;
// canvas->translate(0, SkIntToScalar(50));
// canvas->drawText(style, strlen(style), SkIntToScalar(20), SkIntToScalar(20), paint);
SkSafeUnref(paint.setTypeface(SkTypeface::CreateFromFile("/skimages/samplefont.ttf")));
paint.setAntiAlias(true);
paint.setFlags(paint.getFlags() | gHints[index].fFlags);
SkRect clip;
clip.set(SkIntToScalar(25), SkIntToScalar(34), SkIntToScalar(88), SkIntToScalar(155));
const char* text = "Hamburgefons";
size_t length = strlen(text);
SkScalar y = SkIntToScalar(0);
for (int i = 9; i <= 24; i++) {
paint.setTextSize(SkIntToScalar(i) /*+ (gRand.nextU() & 0xFFFF)*/);
for (SkScalar dx = 0; dx <= SkIntToScalar(3)/4;
dx += SkIntToScalar(1) /* /4 */) {
y += paint.getFontSpacing();
DrawTheText(canvas, text, length, SkIntToScalar(20) + dx, y,
paint, fClickX, fMF);
}
}
if (gHints[index].fFlushCache) {
// SkGraphics::SetFontCacheUsed(0);
}
}
示例13: flushRunAsPaths
void GrAtlasTextBlob::flushRunAsPaths(GrContext* context, GrDrawContext* dc,
const SkSurfaceProps& props,
const SkTextBlobRunIterator& it,
const GrClip& clip, const SkPaint& skPaint,
SkDrawFilter* drawFilter, const SkMatrix& viewMatrix,
const SkIRect& clipBounds, SkScalar x, SkScalar y) {
SkPaint runPaint = skPaint;
size_t textLen = it.glyphCount() * sizeof(uint16_t);
const SkPoint& offset = it.offset();
it.applyFontToPaint(&runPaint);
if (drawFilter && !drawFilter->filter(&runPaint, SkDrawFilter::kText_Type)) {
return;
}
runPaint.setFlags(GrTextUtils::FilterTextFlags(props, runPaint));
switch (it.positioning()) {
case SkTextBlob::kDefault_Positioning:
GrTextUtils::DrawTextAsPath(context, dc, clip, runPaint, viewMatrix,
(const char *)it.glyphs(),
textLen, x + offset.x(), y + offset.y(), clipBounds);
break;
case SkTextBlob::kHorizontal_Positioning:
GrTextUtils::DrawPosTextAsPath(context, dc, props, clip, runPaint, viewMatrix,
(const char*)it.glyphs(),
textLen, it.pos(), 1, SkPoint::Make(x, y + offset.y()),
clipBounds);
break;
case SkTextBlob::kFull_Positioning:
GrTextUtils::DrawPosTextAsPath(context, dc, props, clip, runPaint, viewMatrix,
(const char*)it.glyphs(),
textLen, it.pos(), 2, SkPoint::Make(x, y), clipBounds);
break;
}
}
示例14: onDrawContent
void onDrawContent(SkCanvas* canvas) override {
const char* str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
SkPaint paint;
SkScalar x = SkIntToScalar(10);
SkScalar y = SkIntToScalar(20);
paint.setFlags(0x105);
paint.setARGB(fByte, 0xFF, 0xFF, 0xFF);
paint.setMaskFilter(SkBlurMaskFilter::Create(kNormal_SkBlurStyle,
SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(3))));
paint.getMaskFilter()->unref();
SkRandom rand;
for (int ps = 6; ps <= 35; ps++) {
paint.setColor(rand.nextU() | (0xFF << 24));
paint.setTextSize(SkIntToScalar(ps));
paint.setTextSize(SkIntToScalar(24));
canvas->drawText(str, strlen(str), x, y, paint);
y += paint.getFontMetrics(nullptr);
}
}
示例15: reader
DEF_TEST(Paint_flattening, reporter) {
const SkFilterQuality levels[] = {
kNone_SkFilterQuality,
kLow_SkFilterQuality,
kMedium_SkFilterQuality,
kHigh_SkFilterQuality,
};
const SkPaint::Hinting hinting[] = {
SkPaint::kNo_Hinting,
SkPaint::kSlight_Hinting,
SkPaint::kNormal_Hinting,
SkPaint::kFull_Hinting,
};
const SkPaint::Align align[] = {
SkPaint::kLeft_Align,
SkPaint::kCenter_Align,
SkPaint::kRight_Align
};
const SkPaint::Cap caps[] = {
SkPaint::kButt_Cap,
SkPaint::kRound_Cap,
SkPaint::kSquare_Cap,
};
const SkPaint::Join joins[] = {
SkPaint::kMiter_Join,
SkPaint::kRound_Join,
SkPaint::kBevel_Join,
};
const SkPaint::TextEncoding encodings[] = {
SkPaint::kUTF8_TextEncoding,
SkPaint::kUTF16_TextEncoding,
SkPaint::kUTF32_TextEncoding,
SkPaint::kGlyphID_TextEncoding,
};
const SkPaint::Style styles[] = {
SkPaint::kFill_Style,
SkPaint::kStroke_Style,
SkPaint::kStrokeAndFill_Style,
};
#define FOR_SETUP(index, array, setter) \
for (size_t index = 0; index < SK_ARRAY_COUNT(array); ++index) { \
paint.setter(array[index]); \
SkPaint paint;
paint.setFlags(0x1234);
FOR_SETUP(i, levels, setFilterQuality)
FOR_SETUP(j, hinting, setHinting)
FOR_SETUP(k, align, setTextAlign)
FOR_SETUP(l, caps, setStrokeCap)
FOR_SETUP(m, joins, setStrokeJoin)
FOR_SETUP(n, encodings, setTextEncoding)
FOR_SETUP(p, styles, setStyle)
SkWriteBuffer writer;
paint.flatten(writer);
const uint32_t* written = writer.getWriter32()->contiguousArray();
SkReadBuffer reader(written, writer.bytesWritten());
SkPaint paint2;
paint2.unflatten(reader);
REPORTER_ASSERT(reporter, paint2 == paint);
}}}}}}}