Update examples to use SkFont
Bug: skia: Change-Id: I104e1382a035f7b1e0d8f4bf37859e2544166788 Reviewed-on: https://skia-review.googlesource.com/c/192039 Reviewed-by: Mike Reed <reed@google.com> Commit-Queue: Mike Reed <reed@google.com> Auto-Submit: Mike Reed <reed@google.com>
This commit is contained in:
parent
6152470dc6
commit
729bb199dd
@ -18,14 +18,13 @@ state.
|
||||
#Example
|
||||
#Height 128
|
||||
SkPaint p;
|
||||
p.setAntiAlias(true);
|
||||
p.setTextSize(64);
|
||||
SkFont font(nullptr, 64);
|
||||
for (SkScalar sx : { -1, 1 } ) {
|
||||
for (SkScalar sy : { -1, 1 } ) {
|
||||
SkAutoCanvasRestore autoRestore(canvas, true);
|
||||
SkMatrix m = SkMatrix::MakeAll(sx, 1, 96, 0, sy, 64, 0, 0, 1);
|
||||
canvas->concat(m);
|
||||
canvas->drawString("R", 0, 0, p);
|
||||
canvas->drawString("R", 0, 0, font, p);
|
||||
}
|
||||
}
|
||||
##
|
||||
|
@ -3952,7 +3952,6 @@ Paint attributes related to text, like text size, have no effect on paint passed
|
||||
run.glyphs[0] = 20;
|
||||
sk_sp<const SkTextBlob> blob = textBlobBuilder.make();
|
||||
SkPaint paint;
|
||||
paint.setTextSize(10);
|
||||
paint.setColor(SK_ColorBLUE);
|
||||
canvas->drawTextBlob(blob.get(), 0, 0, paint);
|
||||
}
|
||||
|
@ -459,17 +459,17 @@ void draw(SkCanvas* canvas) {
|
||||
};
|
||||
SkPaint paint;
|
||||
paint.setAntiAlias(true);
|
||||
paint.setTextSize(14);
|
||||
SkFont font(nullptr, 14);
|
||||
for (auto compare : colorCompare) {
|
||||
paint.setStyle(SkPaint::kFill_Style);
|
||||
paint.setColor(compare.fSVGColor);
|
||||
canvas->drawRect({5, 5, 15, 15}, paint);
|
||||
paint.setColor(SK_ColorBLACK);
|
||||
canvas->drawString(compare.fSVGName, 20, 16, paint);
|
||||
canvas->drawString(compare.fSVGName, 20, 16, font, paint);
|
||||
paint.setColor(compare.fSkiaColor);
|
||||
canvas->drawRect({105, 5, 115, 15}, paint);
|
||||
paint.setColor(SK_ColorBLACK);
|
||||
canvas->drawString(compare.fSkiaName, 120, 16, paint);
|
||||
canvas->drawString(compare.fSkiaName, 120, 16, font, paint);
|
||||
paint.setStyle(SkPaint::kStroke_Style);
|
||||
canvas->drawRect({5, 5, 15, 15}, paint);
|
||||
canvas->drawRect({105, 5, 115, 15}, paint);
|
||||
|
@ -882,9 +882,7 @@ kRGBA_8888_SkColorType.
|
||||
const char* colors[] = { "Unknown", "Alpha_8", "RGB_565", "ARGB_4444", "RGBA_8888", "RGB_888x",
|
||||
"BGRA_8888", "RGBA_1010102", "RGB_101010x", "Gray_8", "RGBA_F16" };
|
||||
SkPaint paint;
|
||||
paint.setTypeface(SkTypeface::MakeFromName("monospace", SkFontStyle()));
|
||||
paint.setAntiAlias(true);
|
||||
paint.setTextSize(10);
|
||||
SkFont font(SkTypeface::MakeFromName("monospace", SkFontStyle()), 10);
|
||||
int y = 15;
|
||||
canvas->drawString(" colorType bytes", 10, y, paint);
|
||||
for (SkColorType colorType : { #list_of_color_types#
|
||||
@ -892,7 +890,7 @@ kRGBA_8888_SkColorType.
|
||||
int result = SkColorTypeBytesPerPixel(colorType);
|
||||
SkString string;
|
||||
string.printf("%13s %4d", colors[(int) colorType], result);
|
||||
canvas->drawString(string, 10, y += 14, paint);
|
||||
canvas->drawString(string, 10, y += 14, font, paint);
|
||||
}
|
||||
##
|
||||
#SeeAlso SkImageInfo::bytesPerPixel
|
||||
@ -910,9 +908,7 @@ kRGBA_8888_SkColorType.
|
||||
const char* colors[] = { "Unknown", "Alpha_8", "RGB_565", "ARGB_4444", "RGBA_8888", "RGB_888x",
|
||||
"BGRA_8888", "RGBA_1010102", "RGB_101010x", "Gray_8", "RGBA_F16" };
|
||||
SkPaint paint;
|
||||
paint.setTypeface(SkTypeface::MakeFromName("monospace", SkFontStyle()));
|
||||
paint.setAntiAlias(true);
|
||||
paint.setTextSize(10);
|
||||
SkFont font(SkTypeface::MakeFromName("monospace", SkFontStyle()), 10);
|
||||
int y = 15;
|
||||
canvas->drawString(" colorType bytes", 10, y, paint);
|
||||
for (SkColorType colorType : { #list_of_color_types#
|
||||
@ -920,7 +916,7 @@ kRGBA_8888_SkColorType.
|
||||
bool result = SkColorTypeIsAlwaysOpaque(colorType);
|
||||
SkString string;
|
||||
string.printf("%13s %6s", colors[(int) colorType], result ? "true" : "false");
|
||||
canvas->drawString(string, 10, y += 14, paint);
|
||||
canvas->drawString(string, 10, y += 14, font, paint);
|
||||
}
|
||||
##
|
||||
#SeeAlso SkColorTypeValidateAlphaType
|
||||
@ -942,9 +938,7 @@ kRGBA_8888_SkColorType.
|
||||
SkAlphaType alphaTypes[] = { #list_of_alpha_types#
|
||||
};
|
||||
SkPaint paint;
|
||||
paint.setTypeface(SkTypeface::MakeFromName("monospace", SkFontStyle()));
|
||||
paint.setAntiAlias(true);
|
||||
paint.setTextSize(10);
|
||||
SkFont font(SkTypeface::MakeFromName("monospace", SkFontStyle()), 10);
|
||||
int y = 15;
|
||||
canvas->drawString(" colorType alphaType canonical", 10, y, paint);
|
||||
for (SkColorType colorType : { #list_of_color_types#
|
||||
@ -1173,9 +1167,8 @@ middle gradient.
|
||||
SkCanvas offscreen(bitmap);
|
||||
offscreen.clear(SK_ColorWHITE);
|
||||
SkPaint paint;
|
||||
paint.setAntiAlias(true);
|
||||
paint.setTextSize(15);
|
||||
offscreen.drawString("\xF0\x9F\x98\xB8", 1, 15, paint);
|
||||
SkFont font(nullptr, 15);
|
||||
offscreen.drawString("\xF0\x9F\x98\xB8", 1, 15, font, paint);
|
||||
canvas->scale(6, 6);
|
||||
canvas->drawBitmap(bitmap, 0, 0);
|
||||
##
|
||||
@ -1198,9 +1191,8 @@ middle gradient.
|
||||
SkCanvas offscreen(bitmap);
|
||||
offscreen.clear(SK_ColorWHITE);
|
||||
SkPaint paint;
|
||||
paint.setAntiAlias(true);
|
||||
paint.setTextSize(15);
|
||||
offscreen.drawString("\xF0\x9F\x98\xB9", 1, 15, paint);
|
||||
SkFont font(nullptr, 15);
|
||||
offscreen.drawString("\xF0\x9F\x98\xB9", 1, 15, font, paint);
|
||||
canvas->scale(6, 6);
|
||||
canvas->drawBitmap(bitmap, 0, 0);
|
||||
##
|
||||
|
@ -253,26 +253,6 @@ for (int quality : { 100, 50, 10, 1} ) {
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
#Enum CompressionType
|
||||
#Line # option for MakeFromCompressed ##
|
||||
#Code
|
||||
#Populate
|
||||
##
|
||||
|
||||
Used to inform MakeFromCompressed which compression method was used on the
|
||||
input data.
|
||||
|
||||
#Const kETC1_CompressionType 0
|
||||
#Line # compressed data uses ETC1 compression ##
|
||||
##
|
||||
|
||||
#NoExample
|
||||
##
|
||||
|
||||
#SeeAlso MakeFromCompressed
|
||||
|
||||
#Enum ##
|
||||
|
||||
#Method static sk_sp<SkImage> MakeFromCompressed(GrContext* context, sk_sp<SkData> data, int width, int height, CompressionType type)
|
||||
#In Constructors
|
||||
#Line # creates a GPU-backed Image from compressed data ##
|
||||
@ -1723,8 +1703,8 @@ void draw(SkCanvas* canvas) {
|
||||
canvas->scale(8, 8);
|
||||
canvas->drawImage(image, 0, 0, nullptr);
|
||||
SkPaint paint;
|
||||
paint.setTextSize(4);
|
||||
canvas->drawString(lazy, 2, 5, paint);
|
||||
SkFont font(nullptr, 4);
|
||||
canvas->drawString(lazy, 2, 5, font, paint);
|
||||
}
|
||||
##
|
||||
|
||||
|
@ -83,14 +83,13 @@ for (int i = 0; i < 4; ++i) {
|
||||
|
||||
#Example
|
||||
SkPaint p;
|
||||
p.setAntiAlias(true);
|
||||
p.setTextSize(64);
|
||||
SkFont font(nullptr, 64);
|
||||
for (SkScalar sx : { -1, 1 } ) {
|
||||
for (SkScalar sy : { -1, 1 } ) {
|
||||
SkAutoCanvasRestore autoRestore(canvas, true);
|
||||
SkMatrix m = SkMatrix::MakeAll(sx, 1, 128, 0, sy, 128, 0, 0, 1);
|
||||
canvas->concat(m);
|
||||
canvas->drawString("K", 0, 0, p);
|
||||
canvas->drawString("K", 0, 0, font, p);
|
||||
}
|
||||
}
|
||||
##
|
||||
@ -338,9 +337,8 @@ SkString string;
|
||||
string.printf("hasPerspective %s", matrix.hasPerspective() ? "true" : "false");
|
||||
canvas->drawBitmap(source, 0, 0);
|
||||
SkPaint paint;
|
||||
paint.setAntiAlias(true);
|
||||
paint.setTextSize(48);
|
||||
canvas->drawString(string, 0, source.bounds().height() + 48, paint);
|
||||
SkFont font(nullptr, 48);
|
||||
canvas->drawString(string, 0, source.bounds().height() + 48, font, paint);
|
||||
##
|
||||
|
||||
#SeeAlso setAll set9 MakeAll
|
||||
@ -467,8 +465,7 @@ each value in Matrix.
|
||||
|
||||
#Example
|
||||
SkPaint black;
|
||||
black.setAntiAlias(true);
|
||||
black.setTextSize(48);
|
||||
SkFont font(nullptr, 48);
|
||||
SkPaint gray = black;
|
||||
gray.setColor(0xFF9f9f9f);
|
||||
SkScalar offset[] = { 1.5f, 1.5f, 20, 1.5f, 1.5f, 20, .03f, .01f, 2 };
|
||||
@ -480,9 +477,9 @@ for (int i : { SkMatrix::kMScaleX, SkMatrix::kMSkewX, SkMatrix::kMTransX,
|
||||
m.set(i, offset[i]);
|
||||
SkAutoCanvasRestore autoRestore(canvas, true);
|
||||
canvas->translate(22 + (i % 3) * 88, 44 + (i / 3) * 88);
|
||||
canvas->drawString("&", 0, 0, gray);
|
||||
canvas->drawString("&", 0, 0, font, gray);
|
||||
canvas->concat(m);
|
||||
canvas->drawString("&", 0, 0, black);
|
||||
canvas->drawString("&", 0, 0, font, black);
|
||||
}
|
||||
##
|
||||
|
||||
@ -710,15 +707,14 @@ matrix.getTranslateY() == 24
|
||||
SkAutoCanvasRestore autoRestore(canvas, true);
|
||||
canvas->translate(22, 144);
|
||||
SkPaint black;
|
||||
black.setAntiAlias(true);
|
||||
black.setTextSize(24);
|
||||
SkFont font(nullptr, 24);
|
||||
SkPaint gray = black;
|
||||
gray.setColor(0xFF9f9f9f);
|
||||
SkString string;
|
||||
string.appendScalar(m.getPerspX());
|
||||
canvas->drawString(string, 0, -72, gray);
|
||||
canvas->drawString(string, 0, -72, font, gray);
|
||||
canvas->concat(m);
|
||||
canvas->drawString(string, 0, 0, black);
|
||||
canvas->drawString(string, 0, 0, font, black);
|
||||
##
|
||||
|
||||
#SeeAlso kMPersp0 getPerspY
|
||||
@ -739,15 +735,14 @@ matrix.getTranslateY() == 24
|
||||
SkAutoCanvasRestore autoRestore(canvas, true);
|
||||
canvas->translate(22, 144);
|
||||
SkPaint black;
|
||||
black.setAntiAlias(true);
|
||||
black.setTextSize(24);
|
||||
SkPaint gray = black;
|
||||
SkFont font(nullptr, 24);
|
||||
SkPaint gray;
|
||||
gray.setColor(0xFF9f9f9f);
|
||||
SkString string;
|
||||
string.appendScalar(m.getPerspY());
|
||||
canvas->drawString(string, 0, -72, gray);
|
||||
canvas->drawString(string, 0, -72, font, gray);
|
||||
canvas->concat(m);
|
||||
canvas->drawString(string, 0, 0, black);
|
||||
canvas->drawString(string, 0, 0, font, black);
|
||||
##
|
||||
|
||||
#SeeAlso kMPersp1 getPerspX
|
||||
@ -823,14 +818,13 @@ after 2nd skew x mod: x = 66
|
||||
#Example
|
||||
#Height 64
|
||||
SkPaint paint;
|
||||
paint.setAntiAlias(true);
|
||||
paint.setTextSize(24);
|
||||
canvas->drawString("normal", 12, 24, paint);
|
||||
SkFont font(nullptr, 24);
|
||||
canvas->drawString("normal", 12, 24, font, paint);
|
||||
SkMatrix matrix;
|
||||
matrix.setIdentity();
|
||||
matrix.setScaleX(3);
|
||||
canvas->concat(matrix);
|
||||
canvas->drawString("x scale", 0, 48, paint);
|
||||
canvas->drawString("x scale", 0, 48, font, paint);
|
||||
##
|
||||
|
||||
#SeeAlso set setScale setScaleY
|
||||
@ -847,14 +841,13 @@ canvas->drawString("x scale", 0, 48, paint);
|
||||
#Example
|
||||
#Height 192
|
||||
SkPaint paint;
|
||||
paint.setAntiAlias(true);
|
||||
paint.setTextSize(24);
|
||||
canvas->drawString("normal", 12, 24, paint);
|
||||
SkFont font(nullptr, 24);
|
||||
canvas->drawString("normal", 12, 24, font, paint);
|
||||
SkMatrix matrix;
|
||||
matrix.setIdentity();
|
||||
matrix.setScaleY(3);
|
||||
canvas->concat(matrix);
|
||||
canvas->drawString("y scale", 12, 48, paint);
|
||||
canvas->drawString("y scale", 12, 48, font, paint);
|
||||
##
|
||||
|
||||
#SeeAlso set setScale setScaleX
|
||||
@ -871,14 +864,13 @@ canvas->drawString("y scale", 12, 48, paint);
|
||||
#Example
|
||||
#Height 96
|
||||
SkPaint paint;
|
||||
paint.setAntiAlias(true);
|
||||
paint.setTextSize(24);
|
||||
canvas->drawString("normal", 12, 24, paint);
|
||||
SkFont font(nullptr, 24);
|
||||
canvas->drawString("normal", 12, 24, font, paint);
|
||||
SkMatrix matrix;
|
||||
matrix.setIdentity();
|
||||
matrix.setSkewY(.3f);
|
||||
canvas->concat(matrix);
|
||||
canvas->drawString("y skew", 12, 48, paint);
|
||||
canvas->drawString("y skew", 12, 48, font, paint);
|
||||
##
|
||||
|
||||
#SeeAlso set setSkew setSkewX
|
||||
@ -895,14 +887,13 @@ canvas->drawString("y skew", 12, 48, paint);
|
||||
#Example
|
||||
#Height 64
|
||||
SkPaint paint;
|
||||
paint.setAntiAlias(true);
|
||||
paint.setTextSize(24);
|
||||
canvas->drawString("normal", 12, 24, paint);
|
||||
SkFont font(nullptr, 24);
|
||||
canvas->drawString("normal", 12, 24, font, paint);
|
||||
SkMatrix matrix;
|
||||
matrix.setIdentity();
|
||||
matrix.setSkewX(-.7f);
|
||||
canvas->concat(matrix);
|
||||
canvas->drawString("x skew", 36, 48, paint);
|
||||
canvas->drawString("x skew", 36, 48, font, paint);
|
||||
##
|
||||
|
||||
#SeeAlso set setSkew setSkewX
|
||||
@ -919,14 +910,13 @@ canvas->drawString("x skew", 36, 48, paint);
|
||||
#Example
|
||||
#Height 48
|
||||
SkPaint paint;
|
||||
paint.setAntiAlias(true);
|
||||
paint.setTextSize(24);
|
||||
canvas->drawString("normal", 8, 24, paint);
|
||||
SkFont font(nullptr, 24);
|
||||
canvas->drawString("normal", 8, 24, font, paint);
|
||||
SkMatrix matrix;
|
||||
matrix.setIdentity();
|
||||
matrix.setTranslateX(96);
|
||||
canvas->concat(matrix);
|
||||
canvas->drawString("x translate", 8, 24, paint);
|
||||
canvas->drawString("x translate", 8, 24, font, paint);
|
||||
##
|
||||
|
||||
#SeeAlso set setTranslate setTranslateY
|
||||
@ -943,14 +933,13 @@ canvas->drawString("x translate", 8, 24, paint);
|
||||
#Example
|
||||
#Height 64
|
||||
SkPaint paint;
|
||||
paint.setAntiAlias(true);
|
||||
paint.setTextSize(24);
|
||||
canvas->drawString("normal", 8, 24, paint);
|
||||
SkFont font(nullptr, 24);
|
||||
canvas->drawString("normal", 8, 24, font, paint);
|
||||
SkMatrix matrix;
|
||||
matrix.setIdentity();
|
||||
matrix.setTranslateY(24);
|
||||
canvas->concat(matrix);
|
||||
canvas->drawString("y translate", 8, 24, paint);
|
||||
canvas->drawString("y translate", 8, 24, font, paint);
|
||||
##
|
||||
|
||||
#SeeAlso set setTranslate setTranslateX
|
||||
@ -1019,15 +1008,14 @@ for (SkScalar perspX : { -.003f, 0.f, .003f, .012f } ) {
|
||||
#Example
|
||||
#Height 128
|
||||
SkPaint p;
|
||||
p.setAntiAlias(true);
|
||||
p.setTextSize(64);
|
||||
SkFont font(nullptr, 64);
|
||||
SkMatrix m;
|
||||
for (SkScalar sx : { -1, 1 } ) {
|
||||
for (SkScalar sy : { -1, 1 } ) {
|
||||
SkAutoCanvasRestore autoRestore(canvas, true);
|
||||
m.setAll(sx, 1, 128, 0, sy, 64, 0, 0, 1);
|
||||
canvas->concat(m);
|
||||
canvas->drawString("K", 0, 0, p);
|
||||
canvas->drawString("K", 0, 0, font, p);
|
||||
}
|
||||
}
|
||||
##
|
||||
@ -1135,13 +1123,12 @@ m.isIdentity(): true
|
||||
#Example
|
||||
#Height 64
|
||||
SkPaint paint;
|
||||
paint.setAntiAlias(true);
|
||||
paint.setTextSize(24);
|
||||
canvas->drawString("normal", 8, 24, paint);
|
||||
SkFont font(nullptr, 24);
|
||||
canvas->drawString("normal", 8, 24, font, paint);
|
||||
SkMatrix matrix;
|
||||
matrix.setTranslate(96, 24);
|
||||
canvas->concat(matrix);
|
||||
canvas->drawString("translate", 8, 24, paint);
|
||||
canvas->drawString("translate", 8, 24, font, paint);
|
||||
##
|
||||
|
||||
#SeeAlso setTranslateX setTranslateY
|
||||
@ -1156,13 +1143,12 @@ canvas->drawString("translate", 8, 24, paint);
|
||||
#Example
|
||||
#Height 64
|
||||
SkPaint paint;
|
||||
paint.setAntiAlias(true);
|
||||
paint.setTextSize(24);
|
||||
canvas->drawString("normal", 8, 24, paint);
|
||||
SkFont font(nullptr, 24);
|
||||
canvas->drawString("normal", 8, 24, font, paint);
|
||||
SkMatrix matrix;
|
||||
matrix.setTranslate({96, 24});
|
||||
canvas->concat(matrix);
|
||||
canvas->drawString("translate", 8, 24, paint);
|
||||
canvas->drawString("translate", 8, 24, font, paint);
|
||||
##
|
||||
|
||||
#SeeAlso setTranslateX setTranslateY MakeTrans
|
||||
@ -1180,15 +1166,14 @@ canvas->drawString("translate", 8, 24, paint);
|
||||
#Example
|
||||
#Height 128
|
||||
SkPaint p;
|
||||
p.setAntiAlias(true);
|
||||
p.setTextSize(64);
|
||||
SkFont font(nullptr, 64);
|
||||
SkMatrix m;
|
||||
for (SkScalar sx : { -1, 1 } ) {
|
||||
for (SkScalar sy : { -1, 1 } ) {
|
||||
SkAutoCanvasRestore autoRestore(canvas, true);
|
||||
m.setScale(sx, sy, 128, 64);
|
||||
canvas->concat(m);
|
||||
canvas->drawString("%", 128, 64, p);
|
||||
canvas->drawString("%", 128, 64, font, p);
|
||||
}
|
||||
}
|
||||
##
|
||||
@ -1205,8 +1190,7 @@ canvas->drawString("translate", 8, 24, paint);
|
||||
#Example
|
||||
#Height 128
|
||||
SkPaint p;
|
||||
p.setAntiAlias(true);
|
||||
p.setTextSize(64);
|
||||
SkFont font(nullptr, 64);
|
||||
SkMatrix m;
|
||||
for (SkScalar sx : { -1, 1 } ) {
|
||||
for (SkScalar sy : { -1, 1 } ) {
|
||||
@ -1214,7 +1198,7 @@ canvas->drawString("translate", 8, 24, paint);
|
||||
m.setScale(sx, sy);
|
||||
m.postTranslate(128, 64);
|
||||
canvas->concat(m);
|
||||
canvas->drawString("@", 0, 0, p);
|
||||
canvas->drawString("@", 0, 0, font, p);
|
||||
}
|
||||
}
|
||||
##
|
||||
@ -1369,15 +1353,14 @@ Canvas needs offset after applying Matrix to pivot about Rect center.
|
||||
|
||||
#Example
|
||||
SkPaint p;
|
||||
p.setAntiAlias(true);
|
||||
p.setTextSize(48);
|
||||
SkFont font(nullptr, 48);
|
||||
SkMatrix m;
|
||||
for (SkScalar sx : { -1, 0, 1 } ) {
|
||||
for (SkScalar sy : { -1, 0, 1 } ) {
|
||||
SkAutoCanvasRestore autoRestore(canvas, true);
|
||||
m.setSkew(sx, sy, 96 + 64 * sx, 128 + 48 * sy);
|
||||
canvas->concat(m);
|
||||
canvas->drawString("K", 96 + 64 * sx, 128 + 48 * sy, p);
|
||||
canvas->drawString("K", 96 + 64 * sx, 128 + 48 * sy, font, p);
|
||||
}
|
||||
}
|
||||
##
|
||||
@ -1393,8 +1376,7 @@ Canvas needs offset after applying Matrix to pivot about Rect center.
|
||||
|
||||
#Example
|
||||
SkPaint p;
|
||||
p.setAntiAlias(true);
|
||||
p.setTextSize(48);
|
||||
SkFont font(nullptr, 48);
|
||||
SkMatrix m;
|
||||
for (SkScalar sx : { -1, 0, 1 } ) {
|
||||
for (SkScalar sy : { -1, 0, 1 } ) {
|
||||
@ -1402,7 +1384,7 @@ Canvas needs offset after applying Matrix to pivot about Rect center.
|
||||
m.setSkew(sx, sy);
|
||||
m.postTranslate(96 + 64 * sx, 128 + 48 * sy);
|
||||
canvas->concat(m);
|
||||
canvas->drawString("K", 0, 0, p);
|
||||
canvas->drawString("K", 0, 0, font, p);
|
||||
}
|
||||
}
|
||||
##
|
||||
@ -2038,7 +2020,7 @@ src: 1, 2, 3, 4 dst: 5, 6, 8, 9
|
||||
const SkPoint dst[] = { {50, 0}, {80, -10}, {90, -30}, {60, -40} };
|
||||
SkPaint blackPaint;
|
||||
blackPaint.setAntiAlias(true);
|
||||
blackPaint.setTextSize(42);
|
||||
SkFont font(nullptr, 42);
|
||||
SkPaint redPaint = blackPaint;
|
||||
redPaint.setColor(SK_ColorRED);
|
||||
for (int count : { 1, 2, 3, 4 } ) {
|
||||
@ -2047,16 +2029,16 @@ src: 1, 2, 3, 4 dst: 5, 6, 8, 9
|
||||
canvas->drawCircle(src[index], 3, blackPaint);
|
||||
canvas->drawCircle(dst[index], 3, blackPaint);
|
||||
if (index > 0) {
|
||||
canvas->drawLine(src[index], src[index - 1], blackPaint);
|
||||
canvas->drawLine(dst[index], dst[index - 1], blackPaint);
|
||||
canvas->drawLine(src[index], src[index - 1], font, blackPaint);
|
||||
canvas->drawLine(dst[index], dst[index - 1], font, blackPaint);
|
||||
}
|
||||
}
|
||||
SkMatrix matrix;
|
||||
matrix.setPolyToPoly(src, dst, count);
|
||||
canvas->drawString("A", src[0].fX, src[0].fY, redPaint);
|
||||
canvas->drawString("A", src[0].fX, src[0].fY, font, redPaint);
|
||||
SkAutoCanvasRestore acr(canvas, true);
|
||||
canvas->concat(matrix);
|
||||
canvas->drawString("A", src[0].fX, src[0].fY, redPaint);
|
||||
canvas->drawString("A", src[0].fX, src[0].fY, font, redPaint);
|
||||
}
|
||||
##
|
||||
|
||||
@ -2385,8 +2367,7 @@ canvas->drawBitmap(source, 0, 0);
|
||||
#Example
|
||||
SkPaint paint;
|
||||
paint.setColor(SK_ColorGREEN);
|
||||
paint.setAntiAlias(true);
|
||||
paint.setTextSize(48);
|
||||
SkFont font(nullptr, 48);
|
||||
SkMatrix matrix;
|
||||
matrix.setRotate(90);
|
||||
SkVector offset = { 7, 7 };
|
||||
@ -2395,7 +2376,7 @@ canvas->drawBitmap(source, 0, 0);
|
||||
SK_ColorBLUE, SkDropShadowImageFilter::kDrawShadowAndForeground_ShadowMode, nullptr));
|
||||
matrix.mapVector(offset.fX, offset.fY, &offset);
|
||||
canvas->translate(0, 60);
|
||||
canvas->drawString("Text", 50, 0, paint);
|
||||
canvas->drawString("Text", 50, 0, font, paint);
|
||||
}
|
||||
##
|
||||
|
||||
@ -2411,8 +2392,7 @@ canvas->drawBitmap(source, 0, 0);
|
||||
#Example
|
||||
SkPaint paint;
|
||||
paint.setColor(SK_ColorGREEN);
|
||||
paint.setAntiAlias(true);
|
||||
paint.setTextSize(48);
|
||||
SkFont font(nullptr, 48);
|
||||
SkMatrix matrix;
|
||||
matrix.setRotate(90);
|
||||
SkVector offset = { 7, 7 };
|
||||
@ -2421,7 +2401,7 @@ canvas->drawBitmap(source, 0, 0);
|
||||
SK_ColorBLUE, SkDropShadowImageFilter::kDrawShadowAndForeground_ShadowMode, nullptr));
|
||||
offset = matrix.mapVector(offset.fX, offset.fY);
|
||||
canvas->translate(0, 60);
|
||||
canvas->drawString("Text", 50, 0, paint);
|
||||
canvas->drawString("Text", 50, 0, font, paint);
|
||||
}
|
||||
##
|
||||
|
||||
|
@ -1913,12 +1913,11 @@ implementation.
|
||||
void draw(SkCanvas* canvas) {
|
||||
SkPaint paint;
|
||||
paint.setTypeface(SkTypeface::MakeFromName(nullptr, SkFontStyle()));
|
||||
paint.setAntiAlias(true);
|
||||
paint.setTextSize(36);
|
||||
canvas->drawString("A Big Hello!", 10, 40, paint);
|
||||
SkFont font(nullptr, 36);
|
||||
canvas->drawString("A Big Hello!", 10, 40, font, paint);
|
||||
paint.setTypeface(nullptr);
|
||||
paint.setFakeBoldText(true);
|
||||
canvas->drawString("A Big Hello!", 10, 80, paint);
|
||||
canvas->drawString("A Big Hello!", 10, 80, font, paint);
|
||||
}
|
||||
##
|
||||
|
||||
@ -2024,9 +2023,9 @@ Mask_Filter.
|
||||
SkPaint paint;
|
||||
paint.setAntiAlias(true);
|
||||
paint.setColor(SK_ColorWHITE);
|
||||
paint.setTextSize(96);
|
||||
SkFont font(nullptr, 96);
|
||||
offscreen.clear(0);
|
||||
offscreen.drawString("e", 20, 70, paint);
|
||||
offscreen.drawString("e", 20, 70, font, paint);
|
||||
paint.setImageFilter(
|
||||
SkLightingImageFilter::MakePointLitDiffuse(SkPoint3::Make(80, 100, 10),
|
||||
SK_ColorWHITE, 1, 2, nullptr, nullptr));
|
||||
@ -2148,10 +2147,11 @@ Set SkPaintDefaults_TextSize at compile time to change the default setting.
|
||||
#Height 135
|
||||
void draw(SkCanvas* canvas) {
|
||||
SkPaint paint;
|
||||
canvas->drawString("12 point", 10, 20, paint);
|
||||
paint.setTextSize(24);
|
||||
canvas->drawString("24 point", 10, 60, paint);
|
||||
paint.setTextSize(48);
|
||||
SkFont font;
|
||||
canvas->drawString("12 point", 10, 20, font, paint);
|
||||
font.setSize(24);
|
||||
canvas->drawString("24 point", 10, 60, font, paint);
|
||||
font.setSize(48);
|
||||
canvas->drawString("48 point", 10, 120, paint);
|
||||
}
|
||||
##
|
||||
@ -2171,14 +2171,13 @@ Text_Scale_X defaults to 1.
|
||||
#Height 128
|
||||
void draw(SkCanvas* canvas) {
|
||||
SkPaint paint;
|
||||
paint.setAntiAlias(true);
|
||||
paint.setTextSize(24);
|
||||
paint.setTextScaleX(.8f);
|
||||
canvas->drawString("narrow", 10, 20, paint);
|
||||
paint.setTextScaleX(1);
|
||||
canvas->drawString("normal", 10, 60, paint);
|
||||
paint.setTextScaleX(1.2f);
|
||||
canvas->drawString("wide", 10, 100, paint);
|
||||
SkFont font(nullptr, 24);
|
||||
font.setScaleX(.8f);
|
||||
canvas->drawString("narrow", 10, 20, font, paint);
|
||||
font.setScaleX(1);
|
||||
canvas->drawString("normal", 10, 60, font, paint);
|
||||
font.setScaleX(1.2f);
|
||||
canvas->drawString("wide", 10, 100, font, paint);
|
||||
}
|
||||
##
|
||||
|
||||
@ -2198,14 +2197,13 @@ Text_Skew_X defaults to 0.
|
||||
#Height 128
|
||||
void draw(SkCanvas* canvas) {
|
||||
SkPaint paint;
|
||||
paint.setAntiAlias(true);
|
||||
paint.setTextSize(24);
|
||||
paint.setTextSkewX(-.25f);
|
||||
canvas->drawString("right-leaning", 10, 100, paint);
|
||||
paint.setTextSkewX(0);
|
||||
canvas->drawString("normal", 10, 60, paint);
|
||||
paint.setTextSkewX(.25f);
|
||||
canvas->drawString("left-leaning", 10, 20, paint);
|
||||
SkFont font(nullptr, 24);
|
||||
font.setSkewX(-.25f);
|
||||
canvas->drawString("right-leaning", 10, 100, font, paint);
|
||||
font.setSkewX(0);
|
||||
canvas->drawString("normal", 10, 60, font, paint);
|
||||
font.setSkewX(.25f);
|
||||
canvas->drawString("left-leaning", 10, 20, font, paint);
|
||||
}
|
||||
##
|
||||
|
||||
@ -2228,18 +2226,14 @@ void draw(SkCanvas* canvas) {
|
||||
const char hello8[] = "Hello" "\xE2" "\x98" "\xBA";
|
||||
const uint16_t hello16[] = { 'H', 'e', 'l', 'l', 'o', 0x263A };
|
||||
const uint32_t hello32[] = { 'H', 'e', 'l', 'l', 'o', 0x263A };
|
||||
paint.setTextSize(24);
|
||||
canvas->drawText(hello8, sizeof(hello8) - 1, 10, 30, paint);
|
||||
paint.setTextEncoding(SkTextEncoding::kUTF16);
|
||||
canvas->drawText(hello16, sizeof(hello16), 10, 60, paint);
|
||||
paint.setTextEncoding(SkTextEncoding::kUTF32);
|
||||
canvas->drawText(hello32, sizeof(hello32), 10, 90, paint);
|
||||
SkFont font(nullptr, 24);
|
||||
canvas->drawSimpleText(hello8, sizeof(hello8) - 1, SkTextEncoding::kUTF8, 10, 30, font, paint);
|
||||
canvas->drawSimpleText(hello16, sizeof(hello16), SkTextEncoding::kUTF16, 10, 60, font, paint);
|
||||
canvas->drawSimpleText(hello32, sizeof(hello32), SkTextEncoding::kUTF32, 10, 90, font, paint);
|
||||
uint16_t glyphs[SK_ARRAY_COUNT(hello32)];
|
||||
SkFont font;
|
||||
font.textToGlyphs(hello32, sizeof(hello32), SkTextEncoding::kUTF32,
|
||||
glyphs, SK_ARRAY_COUNT(hello32));
|
||||
paint.setTextEncoding(kGlyphID_SkTextEncoding);
|
||||
canvas->drawText(glyphs, sizeof(glyphs), 10, 120, paint);
|
||||
canvas->drawSimpleText(glyphs, sizeof(glyphs), kGlyphID_SkTextEncoding, 10, 120, font, paint);
|
||||
}
|
||||
##
|
||||
|
||||
|
@ -178,7 +178,8 @@ public:
|
||||
|
||||
// Experimental
|
||||
enum CompressionType {
|
||||
kETC1_CompressionType, //!< compressed data uses ETC1 compression
|
||||
kETC1_CompressionType,
|
||||
kLast_CompressionType = kETC1_CompressionType,
|
||||
};
|
||||
|
||||
/** Creates a GPU-backed SkImage from compressed data.
|
||||
|
Loading…
Reference in New Issue
Block a user