fix bookmaker
Illustrations calling SkTextUtils::DrawString must pass font as well as paint. TBR=reed@google.com,jcgregorio@google.com Docs-Preview: https://skia.org/?cl=181562 Bug: skia: Change-Id: I907c1c69026d3dc40282545b492a790b2349a8a0 Reviewed-on: https://skia-review.googlesource.com/c/181562 Commit-Queue: Cary Clark <caryclark@skia.org> Reviewed-by: Cary Clark <caryclark@skia.org> Reviewed-by: Joe Gregorio <jcgregorio@google.com> Reviewed-by: Mike Reed <reed@google.com>
This commit is contained in:
parent
a3efc72e28
commit
26d173fee7
@ -4018,10 +4018,8 @@ void draw(SkCanvas* canvas) {
|
||||
const char bunny[] = "/(^x^)\\";
|
||||
const int len = sizeof(bunny) - 1;
|
||||
uint16_t glyphs[len];
|
||||
SkPaint paint;
|
||||
paint.textToGlyphs(bunny, len, glyphs);
|
||||
paint.setTextEncoding(kGlyphID_SkTextEncoding);
|
||||
SkFont font;
|
||||
font.textToGlyphs(bunny, len, SkTextEncoding::kUTF8, glyphs, len);
|
||||
int runs[] = { 3, 1, 3 };
|
||||
SkPoint textPos = { 20, 100 };
|
||||
int glyphIndex = 0;
|
||||
@ -4030,13 +4028,13 @@ void draw(SkCanvas* canvas) {
|
||||
const SkTextBlobBuilder::RunBuffer& run =
|
||||
textBlobBuilder.allocRun(font, runLen, textPos.fX, textPos.fY);
|
||||
memcpy(run.glyphs, &glyphs[glyphIndex], sizeof(glyphs[0]) * runLen);
|
||||
paint.setTextSize(1 == runLen ? 20 : 50);
|
||||
textPos.fX += paint.measureText(&glyphs[glyphIndex], sizeof(glyphs[0]) * runLen, nullptr);
|
||||
font.setSize(1 == runLen ? 20 : 50);
|
||||
textPos.fX += font.measureText(&glyphs[glyphIndex], sizeof(glyphs[0]) * runLen,
|
||||
SkTextEncoding::kGlyphID);
|
||||
glyphIndex += runLen;
|
||||
}
|
||||
sk_sp<const SkTextBlob> blob = textBlobBuilder.make();
|
||||
paint.reset();
|
||||
canvas->drawTextBlob(blob.get(), 0, 0, paint);
|
||||
canvas->drawTextBlob(blob.get(), 0, 0, SkPaint());
|
||||
}
|
||||
##
|
||||
|
||||
@ -4595,8 +4593,8 @@ void draw(SkCanvas* canvas) {
|
||||
const char text[] = "Click this link!";
|
||||
SkRect bounds;
|
||||
SkPaint paint;
|
||||
paint.setTextSize(40);
|
||||
(void)paint.measureText(text, strlen(text), &bounds);
|
||||
SkFont font(nullptr, 40);
|
||||
(void)font.measureText(text, strlen(text), SkTextEncoding::kUTF8, &bounds);
|
||||
const char url[] = "https://www.google.com/";
|
||||
sk_sp<SkData> urlData(SkData::MakeWithCString(url));
|
||||
canvas->drawAnnotation(bounds, "url_key", urlData.get());
|
||||
@ -4616,8 +4614,8 @@ void draw(SkCanvas* canvas) {
|
||||
const char text[] = "Click this link!";
|
||||
SkRect bounds;
|
||||
SkPaint paint;
|
||||
paint.setTextSize(40);
|
||||
(void)paint.measureText(text, strlen(text), &bounds);
|
||||
SkFont font(nullptr, 40);
|
||||
(void)font.measureText(text, strlen(text), SkTextEncoding::kUTF8, &bounds);
|
||||
const char url[] = "https://www.google.com/";
|
||||
sk_sp<SkData> urlData(SkData::MakeWithCString(url));
|
||||
canvas->drawAnnotation(bounds, "url_key", urlData.get());
|
||||
|
@ -203,6 +203,20 @@ Whether edge pixels draw opaque or with partial transparency.
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
#Method explicit SkFont(sk_sp<SkTypeface> typeface)
|
||||
#In Constructor
|
||||
#Line # incomplete ##
|
||||
#Populate
|
||||
#Example
|
||||
// incomplete
|
||||
##
|
||||
|
||||
#SeeAlso incomplete
|
||||
|
||||
#Method ##
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
#Method SkFont(sk_sp<SkTypeface> typeface, SkScalar size, SkScalar scaleX, SkScalar skewX)
|
||||
#In Constructor
|
||||
#Line # incomplete ##
|
||||
@ -235,6 +249,22 @@ Whether edge pixels draw opaque or with partial transparency.
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
#Method bool operator!=(const SkFont& font) const
|
||||
#In Operator
|
||||
#Line # compares fonts for inequality ##
|
||||
|
||||
#Populate
|
||||
|
||||
#Example
|
||||
// incomplete
|
||||
##
|
||||
|
||||
#SeeAlso incomplete
|
||||
|
||||
#Method ##
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
#Method bool isForceAutoHinting() const
|
||||
#In incomplete
|
||||
#Line # incomplete ##
|
||||
@ -621,13 +651,24 @@ Whether edge pixels draw opaque or with partial transparency.
|
||||
|
||||
#Method int textToGlyphs(const void* text, size_t byteLength, SkTextEncoding encoding,
|
||||
SkGlyphID glyphs[], int maxGlyphCount) const
|
||||
#In incomplete
|
||||
#Line # incomplete ##
|
||||
|
||||
#In Utility
|
||||
#Line # converts text into glyph indices ##
|
||||
#Populate
|
||||
|
||||
#Example
|
||||
// incomplete
|
||||
#Height 64
|
||||
void draw(SkCanvas* canvas) {
|
||||
SkFont font;
|
||||
const uint8_t utf8[] = { 0x24, 0xC2, 0xA2, 0xE2, 0x82, 0xAC, 0xC2, 0xA5, 0xC2, 0xA3 };
|
||||
std::vector<SkGlyphID> glyphs;
|
||||
int count = font.textToGlyphs(utf8, sizeof(utf8), SkTextEncoding::kUTF8, nullptr, 0);
|
||||
glyphs.resize(count);
|
||||
(void) font.textToGlyphs(utf8, sizeof(utf8), SkTextEncoding::kUTF8, &glyphs.front(),
|
||||
count);
|
||||
font.setSize(32);
|
||||
canvas->drawSimpleText(&glyphs.front(), glyphs.size() * sizeof(SkGlyphID),
|
||||
SkTextEncoding::kGlyphID, 10, 40, font, SkPaint());
|
||||
}
|
||||
##
|
||||
|
||||
#SeeAlso incomplete
|
||||
@ -653,13 +694,18 @@ Whether edge pixels draw opaque or with partial transparency.
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
#Method int countText(const void* text, size_t byteLength, SkTextEncoding encoding) const
|
||||
#In incomplete
|
||||
#Line # incomplete ##
|
||||
|
||||
#In Utility
|
||||
#Line # returns number of Glyphs in text ##
|
||||
#Populate
|
||||
|
||||
#Example
|
||||
// incomplete
|
||||
SkFont font;
|
||||
const uint8_t utf8[] = { 0x24, 0xC2, 0xA2, 0xE2, 0x82, 0xAC, 0xC2, 0xA5, 0xC2, 0xA3 };
|
||||
SkDebugf("count = %d\n", font.countText(utf8, sizeof(utf8), SkTextEncoding::kUTF8));
|
||||
|
||||
#StdOut
|
||||
count = 5
|
||||
##
|
||||
##
|
||||
|
||||
#SeeAlso incomplete
|
||||
@ -669,13 +715,50 @@ Whether edge pixels draw opaque or with partial transparency.
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
#Method bool containsText(const void* text, size_t byteLength, SkTextEncoding encoding) const
|
||||
#In incomplete
|
||||
#Line # incomplete ##
|
||||
|
||||
#In Utility
|
||||
#Line # returns if all text corresponds to Glyphs ##
|
||||
#Populate
|
||||
|
||||
#NoExample
|
||||
#Description
|
||||
containsText succeeds for degree symbol, but cannot find a glyph index
|
||||
corresponding to the Unicode surrogate code point.
|
||||
##
|
||||
SkFont font;
|
||||
const uint16_t goodChar = 0x00B0; // degree symbol
|
||||
const uint16_t badChar = 0xD800; // Unicode surrogate
|
||||
SkDebugf("0x%04x %c= has char\n", goodChar,
|
||||
font.containsText(&goodChar, 2, SkTextEncoding::kUTF16) ? '=' : '!');
|
||||
SkDebugf("0x%04x %c= has char\n", badChar,
|
||||
font.containsText(&badChar, 2, SkTextEncoding::kUTF16) ? '=' : '!');
|
||||
|
||||
#StdOut
|
||||
0x00b0 == has char
|
||||
0xd800 != has char
|
||||
##
|
||||
##
|
||||
|
||||
#Example
|
||||
// incomplete
|
||||
#Description
|
||||
containsText returns true that glyph index is greater than zero, not
|
||||
that it corresponds to an entry in Typeface.
|
||||
##
|
||||
SkFont font;
|
||||
const uint16_t goodGlyph = 511;
|
||||
const uint16_t zeroGlyph = 0;
|
||||
const uint16_t badGlyph = 65535; // larger than glyph count in font
|
||||
SkDebugf("0x%04x %c= has glyph\n", goodGlyph,
|
||||
font.containsText(&goodGlyph, 2, SkTextEncoding::kGlyphID) ? '=' : '!');
|
||||
SkDebugf("0x%04x %c= has glyph\n", zeroGlyph,
|
||||
font.containsText(&zeroGlyph, 2, SkTextEncoding::kGlyphID) ? '=' : '!');
|
||||
SkDebugf("0x%04x %c= has glyph\n", badGlyph,
|
||||
font.containsText(&badGlyph, 2, SkTextEncoding::kGlyphID) ? '=' : '!');
|
||||
|
||||
#StdOut
|
||||
0x01ff == has glyph
|
||||
0x0000 != has glyph
|
||||
0xffff == has glyph
|
||||
##
|
||||
##
|
||||
|
||||
#SeeAlso incomplete
|
||||
@ -724,28 +807,172 @@ Whether edge pixels draw opaque or with partial transparency.
|
||||
#Method SkScalar measureText(const void* text, size_t byteLength, SkTextEncoding encoding,
|
||||
SkRect* bounds = nullptr) const
|
||||
#In incomplete
|
||||
#Line # incomplete ##
|
||||
|
||||
#Line # returns advance width and bounds of text ##
|
||||
#Populate
|
||||
|
||||
#Example
|
||||
// incomplete
|
||||
SkFont font;
|
||||
SkDebugf("default width = %g\n", font.measureText("!", 1, SkTextEncoding::kUTF8));
|
||||
font.setSize(font.getSize() * 2);
|
||||
SkDebugf("double width = %g\n", font.measureText("!", 1, SkTextEncoding::kUTF8));
|
||||
|
||||
#StdOut
|
||||
default width = 5
|
||||
double width = 10
|
||||
##
|
||||
##
|
||||
|
||||
#SeeAlso incomplete
|
||||
|
||||
#Method ##
|
||||
|
||||
|
||||
#Method SkScalar measureText(const void* text, size_t byteLength, SkTextEncoding encoding,
|
||||
SkRect* bounds, const SkPaint* paint) const
|
||||
#In incomplete
|
||||
#Populate
|
||||
|
||||
#Example
|
||||
#Height 64
|
||||
void draw(SkCanvas* canvas) {
|
||||
SkPaint paint;
|
||||
paint.setAntiAlias(true);
|
||||
SkFont font(nullptr, 50);
|
||||
const char str[] = "ay^jZ";
|
||||
const int count = sizeof(str) - 1;
|
||||
canvas->drawSimpleText(str, count, SkTextEncoding::kUTF8, 25, 50, font, paint);
|
||||
SkRect bounds;
|
||||
font.measureText(str, count, SkTextEncoding::kUTF8, &bounds, nullptr);
|
||||
canvas->translate(25, 50);
|
||||
paint.setStyle(SkPaint::kStroke_Style);
|
||||
canvas->drawRect(bounds, paint);
|
||||
}
|
||||
##
|
||||
|
||||
#SeeAlso incomplete
|
||||
|
||||
#Method ##
|
||||
|
||||
#Method void getWidths(const uint16_t glyphs[], int count, SkScalar widths[]) const
|
||||
#In incomplete
|
||||
#Line # returns advance and bounds for each glyph in text ##
|
||||
#Populate
|
||||
#Example
|
||||
// incomplete
|
||||
##
|
||||
#SeeAlso incomplete
|
||||
#Method ##
|
||||
|
||||
#Method void getWidthsBounds(const uint16_t glyphs[], int count, SkScalar widths[], SkRect bounds[],
|
||||
const SkPaint* paint) const
|
||||
#In incomplete
|
||||
#Populate
|
||||
#Example
|
||||
#Height 160
|
||||
#Description
|
||||
Bounds of Glyphs increase for stroked text, but text advance remains the same.
|
||||
The underlines show the text advance, spaced to keep them distinct.
|
||||
##
|
||||
void draw(SkCanvas* canvas) {
|
||||
SkPaint paint;
|
||||
paint.setAntiAlias(true);
|
||||
SkFont font(nullptr, 50);
|
||||
const char str[] = "abc";
|
||||
const int bytes = sizeof(str) - 1;
|
||||
int count = font.textToGlyphs(str, bytes, SkTextEncoding::kUTF8, nullptr, 0);
|
||||
std::vector<SkGlyphID> glyphs;
|
||||
std::vector<SkScalar> widths;
|
||||
std::vector<SkRect> bounds;
|
||||
glyphs.resize(count);
|
||||
(void) font.textToGlyphs(str, bytes, SkTextEncoding::kUTF8, &glyphs.front(), count);
|
||||
widths.resize(count);
|
||||
bounds.resize(count);
|
||||
for (int loop = 0; loop < 2; ++loop) {
|
||||
(void) font.getWidthsBounds(&glyphs.front(), count, &widths.front(), &bounds.front(),
|
||||
&paint);
|
||||
SkPoint loc = { 25, 50 };
|
||||
canvas->drawSimpleText(str, bytes, SkTextEncoding::kUTF8, loc.fX, loc.fY, font, paint);
|
||||
paint.setStyle(SkPaint::kStroke_Style);
|
||||
paint.setStrokeWidth(0);
|
||||
SkScalar advanceY = loc.fY + 10;
|
||||
for (int index = 0; index < count; ++index) {
|
||||
bounds[index].offset(loc.fX, loc.fY);
|
||||
canvas->drawRect(bounds[index], paint);
|
||||
canvas->drawLine(loc.fX, advanceY, loc.fX + widths[index], advanceY, paint);
|
||||
loc.fX += widths[index];
|
||||
advanceY += 5;
|
||||
}
|
||||
canvas->translate(0, 80);
|
||||
paint.setStrokeWidth(3);
|
||||
}
|
||||
}
|
||||
##
|
||||
#SeeAlso incomplete
|
||||
#Method ##
|
||||
|
||||
#Method void getBounds(const uint16_t glyphs[], int count, SkRect bounds[],
|
||||
const SkPaint* paint) const
|
||||
#In incomplete
|
||||
#Populate
|
||||
#Example
|
||||
// incomplete
|
||||
##
|
||||
#SeeAlso incomplete
|
||||
#Method ##
|
||||
|
||||
#Method void getPos(const uint16_t glyphs[], int count, SkPoint pos[], SkPoint origin = {0, 0}) const
|
||||
#In incomplete
|
||||
#Populate
|
||||
#Example
|
||||
// incomplete
|
||||
##
|
||||
#SeeAlso incomplete
|
||||
#Method ##
|
||||
|
||||
#Method void getXPos(const uint16_t glyphs[], int count, SkScalar xpos[], SkScalar origin = 0) const
|
||||
#In incomplete
|
||||
#Populate
|
||||
#Example
|
||||
// incomplete
|
||||
##
|
||||
#SeeAlso incomplete
|
||||
#Method ##
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
#Method bool getPath(uint16_t glyphID, SkPath* path) const
|
||||
#In incomplete
|
||||
#Line # incomplete ##
|
||||
|
||||
#Line # returns Path equivalent to text ##
|
||||
#Populate
|
||||
|
||||
#Example
|
||||
// incomplete
|
||||
#Description
|
||||
Text is added to Path, offset, and subtracted from Path, then added at
|
||||
the offset location. The result is rendered with one draw call.
|
||||
##
|
||||
#Height 128
|
||||
void draw(SkCanvas* canvas) {
|
||||
SkPaint paint;
|
||||
SkFont font(nullptr, 80);
|
||||
SkPath onePath, path, path2;
|
||||
const char str[] = "ABC";
|
||||
const int bytes = sizeof(str) - 1;
|
||||
int count = font.textToGlyphs(str, bytes, SkTextEncoding::kUTF8, nullptr, 0);
|
||||
std::vector<SkGlyphID> glyphs;
|
||||
glyphs.resize(count);
|
||||
(void) font.textToGlyphs(str, bytes, SkTextEncoding::kUTF8, &glyphs.front(), count);
|
||||
int xPos = 20;
|
||||
for (auto oneGlyph : glyphs) {
|
||||
font.getPath(oneGlyph, &onePath);
|
||||
path.addPath(onePath, xPos, 60);
|
||||
xPos += 60;
|
||||
}
|
||||
path.offset(20, 20, &path2);
|
||||
Op(path, path2, SkPathOp::kDifference_SkPathOp, &path);
|
||||
path.addPath(path2);
|
||||
paint.setStyle(SkPaint::kStroke_Style);
|
||||
canvas->drawPath(path, paint);
|
||||
}
|
||||
##
|
||||
|
||||
#SeeAlso incomplete
|
||||
@ -774,12 +1001,18 @@ Whether edge pixels draw opaque or with partial transparency.
|
||||
|
||||
#Method SkScalar getMetrics(SkFontMetrics* metrics) const
|
||||
#In incomplete
|
||||
#Line # incomplete ##
|
||||
|
||||
#Line # returns Typeface metrics scaled by text size ##
|
||||
#Populate
|
||||
|
||||
#Example
|
||||
// incomplete
|
||||
#Height 128
|
||||
void draw(SkCanvas* canvas) {
|
||||
SkFont font(nullptr, 32);
|
||||
SkScalar lineHeight = font.getMetrics(nullptr);
|
||||
SkPaint paint;
|
||||
canvas->drawSimpleText("line 1", 6, SkTextEncoding::kUTF8, 10, 40, font, paint);
|
||||
canvas->drawSimpleText("line 2", 6, SkTextEncoding::kUTF8, 10, 40 + lineHeight, font, paint);
|
||||
}
|
||||
##
|
||||
|
||||
#SeeAlso incomplete
|
||||
@ -790,12 +1023,23 @@ Whether edge pixels draw opaque or with partial transparency.
|
||||
|
||||
#Method SkScalar getSpacing() const
|
||||
#In incomplete
|
||||
#Line # incomplete ##
|
||||
#Line # returns recommended spacing between lines ##
|
||||
|
||||
#Populate
|
||||
|
||||
#Example
|
||||
// incomplete
|
||||
SkFont font;
|
||||
for (SkScalar textSize : { 12, 18, 24, 32 } ) {
|
||||
font.setSize(textSize);
|
||||
SkDebugf("textSize: %g spacing: %g\n", textSize, font.getSpacing());
|
||||
}
|
||||
|
||||
#StdOut
|
||||
textSize: 12 spacing: 13.9688
|
||||
textSize: 18 spacing: 20.9531
|
||||
textSize: 24 spacing: 27.9375
|
||||
textSize: 32 spacing: 37.25
|
||||
##
|
||||
##
|
||||
|
||||
#SeeAlso incomplete
|
||||
|
@ -725,22 +725,25 @@ If Font_Linear is clear, it is the same as setting Hinting to SkFontHinting::kNo
|
||||
|
||||
#Example
|
||||
#Height 128
|
||||
void draw(SkCanvas* canvas) {
|
||||
SkPaint paint;
|
||||
paint.setAntiAlias(true);
|
||||
const char testStr[] = "abcd efgh";
|
||||
for (int textSize : { 12, 24 } ) {
|
||||
paint.setTextSize(textSize);
|
||||
for (auto linearText : { false, true } ) {
|
||||
paint.setLinearText(linearText);
|
||||
SkString width;
|
||||
width.appendScalar(paint.measureText(testStr, SK_ARRAY_COUNT(testStr), nullptr));
|
||||
canvas->translate(0, textSize + 4);
|
||||
canvas->drawString(testStr, 10, 0, paint);
|
||||
canvas->drawString(width, 128, 0, paint);
|
||||
}
|
||||
}
|
||||
}
|
||||
void draw(SkCanvas* canvas) {
|
||||
SkPaint paint;
|
||||
paint.setAntiAlias(true);
|
||||
const char testStr[] = "abcd efgh";
|
||||
size_t count = 9;
|
||||
for (int textSize : { 12, 24 } ) {
|
||||
SkFont font(nullptr, textSize);
|
||||
for (auto linearMetrics : { false, true } ) {
|
||||
font.setLinearMetrics(linearMetrics);
|
||||
SkString width;
|
||||
width.appendScalar(font.measureText(testStr, count, SkTextEncoding::kUTF8));
|
||||
canvas->translate(0, textSize + 4);
|
||||
canvas->drawSimpleText(testStr, count, SkTextEncoding::kUTF8,
|
||||
10, 0, font, paint);
|
||||
canvas->drawSimpleText(width.c_str(), width.size(), SkTextEncoding::kUTF8,
|
||||
128, 0, font, paint);
|
||||
}
|
||||
}
|
||||
}
|
||||
##
|
||||
|
||||
#SeeAlso isLinearText Hinting
|
||||
@ -3000,12 +3003,14 @@ void draw(SkCanvas* canvas) {
|
||||
const uint32_t hello32[] = { 'H', 'e', 'l', 'l', 'o', 0x263A };
|
||||
paint.setTextSize(24);
|
||||
canvas->drawText(hello8, sizeof(hello8) - 1, 10, 30, paint);
|
||||
paint.setTextEncoding(kUTF16_SkTextEncoding);
|
||||
paint.setTextEncoding(SkTextEncoding::kUTF16);
|
||||
canvas->drawText(hello16, sizeof(hello16), 10, 60, paint);
|
||||
paint.setTextEncoding(kUTF32_SkTextEncoding);
|
||||
paint.setTextEncoding(SkTextEncoding::kUTF32);
|
||||
canvas->drawText(hello32, sizeof(hello32), 10, 90, paint);
|
||||
uint16_t glyphs[SK_ARRAY_COUNT(hello32)];
|
||||
paint.textToGlyphs(hello32, sizeof(hello32), glyphs);
|
||||
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);
|
||||
}
|
||||
@ -3053,151 +3058,6 @@ void draw(SkCanvas* canvas) {
|
||||
##
|
||||
|
||||
#Subtopic Text_Encoding ##
|
||||
# ------------------------------------------------------------------------------
|
||||
#Subtopic Font_Metrics
|
||||
|
||||
#Method SkScalar getFontMetrics(SkFontMetrics* metrics) const
|
||||
|
||||
#In Font_Metrics
|
||||
#Line # returns Typeface metrics scaled by text size ##
|
||||
#Populate
|
||||
|
||||
#Example
|
||||
#Height 128
|
||||
void draw(SkCanvas* canvas) {
|
||||
SkPaint paint;
|
||||
paint.setTextSize(32);
|
||||
SkScalar lineHeight = paint.getFontMetrics(nullptr);
|
||||
canvas->drawString("line 1", 10, 40, paint);
|
||||
canvas->drawString("line 2", 10, 40 + lineHeight, paint);
|
||||
}
|
||||
##
|
||||
|
||||
#SeeAlso Font_Size Typeface Typeface_Methods
|
||||
|
||||
##
|
||||
|
||||
|
||||
#Method SkScalar getFontSpacing() const
|
||||
|
||||
#In Font_Metrics
|
||||
#Line # returns recommended spacing between lines ##
|
||||
#Populate
|
||||
|
||||
#Example
|
||||
SkPaint paint;
|
||||
for (SkScalar textSize : { 12, 18, 24, 32 } ) {
|
||||
paint.setTextSize(textSize);
|
||||
SkDebugf("textSize: %g fontSpacing: %g\n", textSize, paint.getFontSpacing());
|
||||
}
|
||||
|
||||
#StdOut
|
||||
textSize: 12 fontSpacing: 13.9688
|
||||
textSize: 18 fontSpacing: 20.9531
|
||||
textSize: 24 fontSpacing: 27.9375
|
||||
textSize: 32 fontSpacing: 37.25
|
||||
##
|
||||
##
|
||||
|
||||
##
|
||||
|
||||
#Subtopic Font_Metrics ##
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
#Method int textToGlyphs(const void* text, size_t byteLength,
|
||||
SkGlyphID glyphs[]) const
|
||||
#In Utility
|
||||
#Line # converts text into glyph indices ##
|
||||
#Populate
|
||||
|
||||
#Example
|
||||
#Height 64
|
||||
void draw(SkCanvas* canvas) {
|
||||
SkPaint paint;
|
||||
const uint8_t utf8[] = { 0x24, 0xC2, 0xA2, 0xE2, 0x82, 0xAC, 0xC2, 0xA5, 0xC2, 0xA3 };
|
||||
std::vector<SkGlyphID> glyphs;
|
||||
int count = paint.textToGlyphs(utf8, sizeof(utf8), nullptr);
|
||||
glyphs.resize(count);
|
||||
(void) paint.textToGlyphs(utf8, sizeof(utf8), &glyphs.front());
|
||||
paint.setTextEncoding(kGlyphID_SkTextEncoding);
|
||||
paint.setTextSize(32);
|
||||
canvas->drawText(&glyphs.front(), glyphs.size() * sizeof(SkGlyphID), 10, 40, paint);
|
||||
}
|
||||
##
|
||||
|
||||
##
|
||||
|
||||
#Method int countText(const void* text, size_t byteLength) const
|
||||
#In Utility
|
||||
#Line # returns number of Glyphs in text ##
|
||||
#Populate
|
||||
|
||||
#Example
|
||||
SkPaint paint;
|
||||
const uint8_t utf8[] = { 0x24, 0xC2, 0xA2, 0xE2, 0x82, 0xAC, 0xC2, 0xA5, 0xC2, 0xA3 };
|
||||
SkDebugf("count = %d\n", paint.countText(utf8, sizeof(utf8)));
|
||||
|
||||
#StdOut
|
||||
count = 5
|
||||
##
|
||||
##
|
||||
##
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
#Method bool containsText(const void* text, size_t byteLength) const
|
||||
#In Utility
|
||||
#Line # returns if all text corresponds to Glyphs ##
|
||||
#Populate
|
||||
|
||||
#NoExample
|
||||
#Description
|
||||
containsText succeeds for degree symbol, but cannot find a glyph index
|
||||
corresponding to the Unicode surrogate code point.
|
||||
##
|
||||
SkPaint paint;
|
||||
const uint16_t goodChar = 0x00B0; // degree symbol
|
||||
const uint16_t badChar = 0xD800; // Unicode surrogate
|
||||
paint.setTextEncoding(kUTF16_SkTextEncoding);
|
||||
SkDebugf("0x%04x %c= has char\n", goodChar,
|
||||
paint.containsText(&goodChar, 2) ? '=' : '!');
|
||||
SkDebugf("0x%04x %c= has char\n", badChar,
|
||||
paint.containsText(&badChar, 2) ? '=' : '!');
|
||||
|
||||
#StdOut
|
||||
0x00b0 == has char
|
||||
0xd800 != has char
|
||||
##
|
||||
##
|
||||
|
||||
#Example
|
||||
#Description
|
||||
containsText returns true that glyph index is greater than zero, not
|
||||
that it corresponds to an entry in Typeface.
|
||||
##
|
||||
SkPaint paint;
|
||||
const uint16_t goodGlyph = 511;
|
||||
const uint16_t zeroGlyph = 0;
|
||||
const uint16_t badGlyph = 65535; // larger than glyph count in font
|
||||
paint.setTextEncoding(kGlyphID_SkTextEncoding);
|
||||
SkDebugf("0x%04x %c= has glyph\n", goodGlyph,
|
||||
paint.containsText(&goodGlyph, 2) ? '=' : '!');
|
||||
SkDebugf("0x%04x %c= has glyph\n", zeroGlyph,
|
||||
paint.containsText(&zeroGlyph, 2) ? '=' : '!');
|
||||
SkDebugf("0x%04x %c= has glyph\n", badGlyph,
|
||||
paint.containsText(&badGlyph, 2) ? '=' : '!');
|
||||
|
||||
#StdOut
|
||||
0x01ff == has glyph
|
||||
0x0000 != has glyph
|
||||
0xffff == has glyph
|
||||
##
|
||||
##
|
||||
|
||||
#SeeAlso setTextEncoding Typeface
|
||||
|
||||
##
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
@ -3231,159 +3091,6 @@ void draw(SkCanvas* canvas) {
|
||||
|
||||
##
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
#Subtopic Measure_Text
|
||||
#Line # width, height, bounds of text ##
|
||||
|
||||
#Method SkScalar measureText(const void* text, size_t length, SkRect* bounds) const
|
||||
|
||||
#In Measure_Text
|
||||
#Line # returns advance width and bounds of text ##
|
||||
#Populate
|
||||
|
||||
#Example
|
||||
#Height 64
|
||||
void draw(SkCanvas* canvas) {
|
||||
SkPaint paint;
|
||||
paint.setAntiAlias(true);
|
||||
paint.setTextSize(50);
|
||||
const char str[] = "ay^jZ";
|
||||
const int count = sizeof(str) - 1;
|
||||
canvas->drawText(str, count, 25, 50, paint);
|
||||
SkRect bounds;
|
||||
paint.measureText(str, count, &bounds);
|
||||
canvas->translate(25, 50);
|
||||
paint.setStyle(SkPaint::kStroke_Style);
|
||||
canvas->drawRect(bounds, paint);
|
||||
}
|
||||
##
|
||||
|
||||
##
|
||||
|
||||
#Method SkScalar measureText(const void* text, size_t length) const
|
||||
|
||||
#In Measure_Text
|
||||
#Populate
|
||||
|
||||
#Example
|
||||
SkPaint paint;
|
||||
SkDebugf("default width = %g\n", paint.measureText("!", 1));
|
||||
paint.setTextSize(paint.getTextSize() * 2);
|
||||
SkDebugf("double width = %g\n", paint.measureText("!", 1));
|
||||
|
||||
#StdOut
|
||||
default width = 5
|
||||
double width = 10
|
||||
##
|
||||
##
|
||||
|
||||
##
|
||||
|
||||
#Method int getTextWidths(const void* text, size_t byteLength, SkScalar widths[],
|
||||
SkRect bounds[] = nullptr) const
|
||||
#In Measure_Text
|
||||
#Line # returns advance and bounds for each glyph in text ##
|
||||
#Populate
|
||||
|
||||
#Example
|
||||
#Height 160
|
||||
#Description
|
||||
Bounds of Glyphs increase for stroked text, but text advance remains the same.
|
||||
The underlines show the text advance, spaced to keep them distinct.
|
||||
##
|
||||
void draw(SkCanvas* canvas) {
|
||||
SkPaint paint;
|
||||
paint.setAntiAlias(true);
|
||||
paint.setTextSize(50);
|
||||
const char str[] = "abc";
|
||||
const int bytes = sizeof(str) - 1;
|
||||
int count = paint.getTextWidths(str, bytes, nullptr);
|
||||
std::vector<SkScalar> widths;
|
||||
std::vector<SkRect> bounds;
|
||||
widths.resize(count);
|
||||
bounds.resize(count);
|
||||
for (int loop = 0; loop < 2; ++loop) {
|
||||
(void) paint.getTextWidths(str, count, &widths.front(), &bounds.front());
|
||||
SkPoint loc = { 25, 50 };
|
||||
canvas->drawText(str, bytes, loc.fX, loc.fY, paint);
|
||||
paint.setStyle(SkPaint::kStroke_Style);
|
||||
paint.setStrokeWidth(0);
|
||||
SkScalar advanceY = loc.fY + 10;
|
||||
for (int index = 0; index < count; ++index) {
|
||||
bounds[index].offset(loc.fX, loc.fY);
|
||||
canvas->drawRect(bounds[index], paint);
|
||||
canvas->drawLine(loc.fX, advanceY, loc.fX + widths[index], advanceY, paint);
|
||||
loc.fX += widths[index];
|
||||
advanceY += 5;
|
||||
}
|
||||
canvas->translate(0, 80);
|
||||
paint.setStrokeWidth(3);
|
||||
}
|
||||
}
|
||||
##
|
||||
|
||||
##
|
||||
|
||||
#Subtopic Measure_Text ##
|
||||
# ------------------------------------------------------------------------------
|
||||
#Subtopic Text_Path
|
||||
#Line # geometry of Glyphs ##
|
||||
|
||||
Text_Path describes the geometry of Glyphs used to draw text.
|
||||
|
||||
#Method void getTextPath(const void* text, size_t length, SkScalar x, SkScalar y,
|
||||
SkPath* path) const
|
||||
#In Text_Path
|
||||
#Line # returns Path equivalent to text ##
|
||||
#Populate
|
||||
|
||||
#Example
|
||||
#Description
|
||||
Text is added to Path, offset, and subtracted from Path, then added at
|
||||
the offset location. The result is rendered with one draw call.
|
||||
##
|
||||
#Height 128
|
||||
void draw(SkCanvas* canvas) {
|
||||
SkPaint paint;
|
||||
paint.setTextSize(80);
|
||||
SkPath path, path2;
|
||||
paint.getTextPath("ABC", 3, 20, 80, &path);
|
||||
path.offset(20, 20, &path2);
|
||||
Op(path, path2, SkPathOp::kDifference_SkPathOp, &path);
|
||||
path.addPath(path2);
|
||||
paint.setStyle(SkPaint::kStroke_Style);
|
||||
canvas->drawPath(path, paint);
|
||||
}
|
||||
##
|
||||
|
||||
##
|
||||
|
||||
#Method void getPosTextPath(const void* text, size_t length,
|
||||
const SkPoint pos[], SkPath* path) const
|
||||
#In Text_Path
|
||||
#Line # returns Path equivalent to positioned text ##
|
||||
#Populate
|
||||
|
||||
#Example
|
||||
#Height 85
|
||||
#Description
|
||||
Simplifies three Glyphs to eliminate overlaps, and strokes the result.
|
||||
##
|
||||
void draw(SkCanvas* canvas) {
|
||||
SkPaint paint;
|
||||
paint.setTextSize(80);
|
||||
SkPath path, path2;
|
||||
SkPoint pos[] = {{20, 60}, {30, 70}, {40, 80}};
|
||||
paint.getPosTextPath("ABC", 3, pos, &path);
|
||||
Simplify(path, &path);
|
||||
paint.setStyle(SkPaint::kStroke_Style);
|
||||
canvas->drawPath(path, paint);
|
||||
}
|
||||
##
|
||||
|
||||
##
|
||||
|
||||
#Subtopic Text_Path ##
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
#Method bool nothingToDraw() const
|
||||
|
@ -24,23 +24,22 @@ fonts and text rendering are used by run.
|
||||
const char bunny[] = "/(^x^)\\";
|
||||
const int len = sizeof(bunny) - 1;
|
||||
uint16_t glyphs[len];
|
||||
SkPaint paint;
|
||||
paint.textToGlyphs(bunny, len, glyphs);
|
||||
paint.setTextEncoding(kGlyphID_SkTextEncoding);
|
||||
SkFont font;
|
||||
font.textToGlyphs(bunny, len, SkTextEncoding::kUTF8, glyphs, sizeof(glyphs));
|
||||
int runs[] = { 3, 1, 3 };
|
||||
SkPoint textPos = { 20, 50 };
|
||||
int glyphIndex = 0;
|
||||
for (auto runLen : runs) {
|
||||
font.setSize(1 == runLen ? 20 : 50);
|
||||
paint.setTextSize(1 == runLen ? 20 : 50);
|
||||
const SkTextBlobBuilder::RunBuffer& run =
|
||||
textBlobBuilder.allocRun(font, runLen, textPos.fX, textPos.fY);
|
||||
memcpy(run.glyphs, &glyphs[glyphIndex], sizeof(glyphs[0]) * runLen);
|
||||
textPos.fX += paint.measureText(&glyphs[glyphIndex], sizeof(glyphs[0]) * runLen, nullptr);
|
||||
textPos.fX += font.measureText(&glyphs[glyphIndex], sizeof(glyphs[0]) * runLen,
|
||||
SkTextEncoding::kGlyphID);
|
||||
glyphIndex += runLen;
|
||||
}
|
||||
sk_sp<const SkTextBlob> blob = textBlobBuilder.make();
|
||||
SkPaint paint;
|
||||
canvas->drawTextBlob(blob.get(), 0, 0, paint);
|
||||
paint.setStyle(SkPaint::kStroke_Style);
|
||||
canvas->drawRect(blob->bounds(), paint);
|
||||
@ -63,26 +62,23 @@ for (int index = 0; index < 2; ++index) {
|
||||
const char bunny[] = "/(^x^)\\";
|
||||
const int len = sizeof(bunny) - 1;
|
||||
uint16_t glyphs[len];
|
||||
SkPaint paint;
|
||||
paint.textToGlyphs(bunny, len, glyphs);
|
||||
paint.setTextEncoding(kGlyphID_SkTextEncoding);
|
||||
paint.setTextScaleX(0.5);
|
||||
SkFont font;
|
||||
font.textToGlyphs(bunny, len, SkTextEncoding::kUTF8, glyphs, sizeof(glyphs));
|
||||
font.setScaleX(0.5);
|
||||
int runs[] = { 3, 1, 3 };
|
||||
SkPoint textPos = { 20, 50 };
|
||||
int glyphIndex = 0;
|
||||
for (auto runLen : runs) {
|
||||
font.setSize(1 == runLen ? 20 : 50);
|
||||
paint.setTextSize(1 == runLen ? 20 : 50);
|
||||
const SkTextBlobBuilder::RunBuffer& run =
|
||||
textBlobBuilder.allocRun(font, runLen, textPos.fX, textPos.fY);
|
||||
memcpy(run.glyphs, &glyphs[glyphIndex], sizeof(glyphs[0]) * runLen);
|
||||
textPos.fX += paint.measureText(&glyphs[glyphIndex], sizeof(glyphs[0]) * runLen, nullptr);
|
||||
textPos.fX += font.measureText(&glyphs[glyphIndex], sizeof(glyphs[0]) * runLen,
|
||||
SkTextEncoding::kGlyphID);
|
||||
glyphIndex += runLen;
|
||||
}
|
||||
sk_sp<const SkTextBlob> blob = textBlobBuilder.make();
|
||||
paint.reset();
|
||||
SkPaint paint;
|
||||
canvas->drawTextBlob(blob.get(), 0, 0, paint);
|
||||
std::string id = "unique ID:" + std::to_string(blob->uniqueID());
|
||||
canvas->drawString(id.c_str(), 30, blob->bounds().fBottom + 15, paint);
|
||||
|
@ -14,11 +14,11 @@ void draw(SkCanvas* canvas) {
|
||||
canvas->scale(1.25f, 1.25f);
|
||||
SkPaint paint;
|
||||
paint.setAntiAlias(true);
|
||||
paint.setTextSize(10);
|
||||
SkTextUtils::DrawString(canvas, "16-bit word", 5 + 20 * 8, 20, paint, SkTextUtils::kCenter_Align);
|
||||
SkTextUtils::DrawString(canvas, "little endian byte order", 5 + 20 * 4, 85, paint, SkTextUtils::kCenter_Align);
|
||||
SkTextUtils::DrawString(canvas, "(low bits)", 5 + 20 * 1.5f, 137, paint, SkTextUtils::kCenter_Align);
|
||||
SkTextUtils::DrawString(canvas, "(high bits)", 5 + 20 * 6.5f, 187, paint, SkTextUtils::kCenter_Align);
|
||||
SkFont font(nullptr, 10);
|
||||
SkTextUtils::DrawString(canvas, "16-bit word", 5 + 20 * 8, 20, font, paint, SkTextUtils::kCenter_Align);
|
||||
SkTextUtils::DrawString(canvas, "little endian byte order", 5 + 20 * 4, 85, font, paint, SkTextUtils::kCenter_Align);
|
||||
SkTextUtils::DrawString(canvas, "(low bits)", 5 + 20 * 1.5f, 137, font, paint, SkTextUtils::kCenter_Align);
|
||||
SkTextUtils::DrawString(canvas, "(high bits)", 5 + 20 * 6.5f, 187, font, paint, SkTextUtils::kCenter_Align);
|
||||
auto drawBoxText = [=](SkScalar e[], const char* s[], int count, int n, SkScalar yPos) -> void {
|
||||
SkPaint p(paint);
|
||||
p.setColor(SK_ColorRED);
|
||||
@ -30,7 +30,7 @@ void draw(SkCanvas* canvas) {
|
||||
int a = width - e[i];
|
||||
if (a == n || a == n + 1 || a == n - 32 || a == n - 31) {
|
||||
char num[3] = {(char) ('0' + n / 10), (char) ('0' + n % 10), '\0'};
|
||||
SkTextUtils::DrawString(canvas, n >= 10 ? num : &num[1], xPos, yPos - 5, p, SkTextUtils::kCenter_Align);
|
||||
SkTextUtils::DrawString(canvas, n >= 10 ? num : &num[1], xPos, yPos - 5, font, p, SkTextUtils::kCenter_Align);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -38,7 +38,7 @@ void draw(SkCanvas* canvas) {
|
||||
}
|
||||
p.setColor(SK_ColorBLACK);
|
||||
for (int i = 0; i < count; ++i) {
|
||||
SkTextUtils::DrawString(canvas, s[i], 5 + (e[i] + e[i + 1]) * 10, yPos + 10, p, SkTextUtils::kCenter_Align);
|
||||
SkTextUtils::DrawString(canvas, s[i], 5 + (e[i] + e[i + 1]) * 10, yPos + 10, font, p, SkTextUtils::kCenter_Align);
|
||||
}
|
||||
p.setStyle(SkPaint::kStroke_Style);
|
||||
for (int i = 0; i <= count; ++i) {
|
||||
@ -73,9 +73,9 @@ void draw(SkCanvas* canvas) {
|
||||
canvas->scale(1.25f, 1.25f);
|
||||
SkPaint paint;
|
||||
paint.setAntiAlias(true);
|
||||
paint.setTextSize(10);
|
||||
SkTextUtils::DrawString(canvas, "16-bit word", 5 + 20 * 8, 20, paint, SkTextUtils::kCenter_Align);
|
||||
SkTextUtils::DrawString(canvas, "little endian byte order", 5 + 20 * 4, 85, paint, SkTextUtils::kCenter_Align);
|
||||
SkFont font(nullptr, 10);
|
||||
SkTextUtils::DrawString(canvas, "16-bit word", 5 + 20 * 8, 20, font, paint, SkTextUtils::kCenter_Align);
|
||||
SkTextUtils::DrawString(canvas, "little endian byte order", 5 + 20 * 4, 85, font, paint, SkTextUtils::kCenter_Align);
|
||||
auto drawBoxText = [=](SkScalar e[], const char* s[], int count, int n, SkScalar yPos) -> void {
|
||||
SkPaint p(paint);
|
||||
p.setColor(SK_ColorRED);
|
||||
@ -87,7 +87,7 @@ void draw(SkCanvas* canvas) {
|
||||
int a = width - e[i];
|
||||
if (a == n || a == n + 1 || a == n - 32 || a == n - 31) {
|
||||
char num[3] = {(char) ('0' + n / 10), (char) ('0' + n % 10), '\0'};
|
||||
SkTextUtils::DrawString(canvas, n >= 10 ? num : &num[1], xPos, yPos - 5, p, SkTextUtils::kCenter_Align);
|
||||
SkTextUtils::DrawString(canvas, n >= 10 ? num : &num[1], xPos, yPos - 5, font, p, SkTextUtils::kCenter_Align);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -95,7 +95,7 @@ void draw(SkCanvas* canvas) {
|
||||
}
|
||||
p.setColor(SK_ColorBLACK);
|
||||
for (int i = 0; i < count; ++i) {
|
||||
SkTextUtils::DrawString(canvas, s[i], 5 + (e[i] + e[i + 1]) * 10, yPos + 10, p, SkTextUtils::kCenter_Align);
|
||||
SkTextUtils::DrawString(canvas, s[i], 5 + (e[i] + e[i + 1]) * 10, yPos + 10, font, p, SkTextUtils::kCenter_Align);
|
||||
}
|
||||
p.setStyle(SkPaint::kStroke_Style);
|
||||
for (int i = 0; i <= count; ++i) {
|
||||
@ -128,9 +128,9 @@ void draw(SkCanvas* canvas) {
|
||||
canvas->scale(1.25f, 1.25f);
|
||||
SkPaint paint;
|
||||
paint.setAntiAlias(true);
|
||||
paint.setTextSize(10);
|
||||
SkTextUtils::DrawString(canvas, "32-bit word", 5 + 20 * 16, 20, paint, SkTextUtils::kCenter_Align);
|
||||
SkTextUtils::DrawString(canvas, "little endian byte order", 5 + 20 * 4, 85, paint, SkTextUtils::kCenter_Align);
|
||||
SkFont font(nullptr, 10);
|
||||
SkTextUtils::DrawString(canvas, "32-bit word", 5 + 20 * 16, 20, font, paint, SkTextUtils::kCenter_Align);
|
||||
SkTextUtils::DrawString(canvas, "little endian byte order", 5 + 20 * 4, 85, font, paint, SkTextUtils::kCenter_Align);
|
||||
auto drawBoxText = [=](SkScalar e[], const char* s[], int count, int n, SkScalar yPos) -> void {
|
||||
SkPaint p(paint);
|
||||
p.setColor(SK_ColorRED);
|
||||
@ -142,7 +142,7 @@ void draw(SkCanvas* canvas) {
|
||||
int a = width - e[i];
|
||||
if (a == n || a == n + 1 || a == n - 32 || a == n - 31) {
|
||||
char num[3] = {(char) ('0' + n / 10), (char) ('0' + n % 10), '\0'};
|
||||
SkTextUtils::DrawString(canvas, n >= 10 ? num : &num[1], xPos, yPos - 5, p, SkTextUtils::kCenter_Align);
|
||||
SkTextUtils::DrawString(canvas, n >= 10 ? num : &num[1], xPos, yPos - 5, font, p, SkTextUtils::kCenter_Align);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -150,7 +150,7 @@ void draw(SkCanvas* canvas) {
|
||||
}
|
||||
p.setColor(SK_ColorBLACK);
|
||||
for (int i = 0; i < count; ++i) {
|
||||
SkTextUtils::DrawString(canvas, s[i], 5 + (e[i] + e[i + 1]) * 10, yPos + 10, p, SkTextUtils::kCenter_Align);
|
||||
SkTextUtils::DrawString(canvas, s[i], 5 + (e[i] + e[i + 1]) * 10, yPos + 10, font, p, SkTextUtils::kCenter_Align);
|
||||
}
|
||||
p.setStyle(SkPaint::kStroke_Style);
|
||||
for (int i = 0; i <= count; ++i) {
|
||||
@ -185,9 +185,9 @@ void draw(SkCanvas* canvas) {
|
||||
canvas->scale(1.25f, 1.25f);
|
||||
SkPaint paint;
|
||||
paint.setAntiAlias(true);
|
||||
paint.setTextSize(10);
|
||||
SkTextUtils::DrawString(canvas, "32-bit word", 5 + 20 * 16, 20, paint, SkTextUtils::kCenter_Align);
|
||||
SkTextUtils::DrawString(canvas, "little endian byte order", 5 + 20 * 4, 85, paint, SkTextUtils::kCenter_Align);
|
||||
SkFont font(nullptr, 10);
|
||||
SkTextUtils::DrawString(canvas, "32-bit word", 5 + 20 * 16, 20, font, paint, SkTextUtils::kCenter_Align);
|
||||
SkTextUtils::DrawString(canvas, "little endian byte order", 5 + 20 * 4, 85, font, paint, SkTextUtils::kCenter_Align);
|
||||
auto drawBoxText = [=](SkScalar e[], const char* s[], int count, int n, SkScalar yPos) -> void {
|
||||
SkPaint p(paint);
|
||||
p.setColor(SK_ColorRED);
|
||||
@ -199,7 +199,7 @@ void draw(SkCanvas* canvas) {
|
||||
int a = width - e[i];
|
||||
if (a == n || a == n + 1 || a == n - 32 || a == n - 31) {
|
||||
char num[3] = {(char) ('0' + n / 10), (char) ('0' + n % 10), '\0'};
|
||||
SkTextUtils::DrawString(canvas, n >= 10 ? num : &num[1], xPos, yPos - 5, p, SkTextUtils::kCenter_Align);
|
||||
SkTextUtils::DrawString(canvas, n >= 10 ? num : &num[1], xPos, yPos - 5, font, p, SkTextUtils::kCenter_Align);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -207,7 +207,7 @@ void draw(SkCanvas* canvas) {
|
||||
}
|
||||
p.setColor(SK_ColorBLACK);
|
||||
for (int i = 0; i < count; ++i) {
|
||||
SkTextUtils::DrawString(canvas, s[i], 5 + (e[i] + e[i + 1]) * 10, yPos + 10, p, SkTextUtils::kCenter_Align);
|
||||
SkTextUtils::DrawString(canvas, s[i], 5 + (e[i] + e[i + 1]) * 10, yPos + 10, font, p, SkTextUtils::kCenter_Align);
|
||||
}
|
||||
p.setStyle(SkPaint::kStroke_Style);
|
||||
for (int i = 0; i <= count; ++i) {
|
||||
@ -242,9 +242,9 @@ void draw(SkCanvas* canvas) {
|
||||
canvas->scale(1.25f, 1.25f);
|
||||
SkPaint paint;
|
||||
paint.setAntiAlias(true);
|
||||
paint.setTextSize(10);
|
||||
SkTextUtils::DrawString(canvas, "32-bit word", 5 + 20 * 16, 20, paint, SkTextUtils::kCenter_Align);
|
||||
SkTextUtils::DrawString(canvas, "little endian byte order", 5 + 20 * 4, 85, paint, SkTextUtils::kCenter_Align);
|
||||
SkFont font(nullptr, 10);
|
||||
SkTextUtils::DrawString(canvas, "32-bit word", 5 + 20 * 16, 20, font, paint, SkTextUtils::kCenter_Align);
|
||||
SkTextUtils::DrawString(canvas, "little endian byte order", 5 + 20 * 4, 85, font, paint, SkTextUtils::kCenter_Align);
|
||||
auto drawBoxText = [=](SkScalar e[], const char* s[], int count, int n, SkScalar yPos) -> void {
|
||||
SkPaint p(paint);
|
||||
p.setColor(SK_ColorRED);
|
||||
@ -256,7 +256,7 @@ void draw(SkCanvas* canvas) {
|
||||
int a = width - e[i];
|
||||
if (a == n || a == n + 1 || a == n - 32 || a == n - 31) {
|
||||
char num[3] = {(char) ('0' + n / 10), (char) ('0' + n % 10), '\0'};
|
||||
SkTextUtils::DrawString(canvas, n >= 10 ? num : &num[1], xPos, yPos - 5, p, SkTextUtils::kCenter_Align);
|
||||
SkTextUtils::DrawString(canvas, n >= 10 ? num : &num[1], xPos, yPos - 5, font, p, SkTextUtils::kCenter_Align);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -264,7 +264,7 @@ void draw(SkCanvas* canvas) {
|
||||
}
|
||||
p.setColor(SK_ColorBLACK);
|
||||
for (int i = 0; i < count; ++i) {
|
||||
SkTextUtils::DrawString(canvas, s[i], 5 + (e[i] + e[i + 1]) * 10, yPos + 10, p, SkTextUtils::kCenter_Align);
|
||||
SkTextUtils::DrawString(canvas, s[i], 5 + (e[i] + e[i + 1]) * 10, yPos + 10, font, p, SkTextUtils::kCenter_Align);
|
||||
}
|
||||
p.setStyle(SkPaint::kStroke_Style);
|
||||
for (int i = 0; i <= count; ++i) {
|
||||
@ -299,15 +299,15 @@ void draw(SkCanvas* canvas) {
|
||||
canvas->scale(1.25f, 1.25f);
|
||||
SkPaint paint;
|
||||
paint.setAntiAlias(true);
|
||||
paint.setTextSize(10);
|
||||
SkTextUtils::DrawString(canvas, "32-bit word", 5 + 20 * 16, 20, paint, SkTextUtils::kCenter_Align);
|
||||
SkTextUtils::DrawString(canvas, "little endian byte order", 5 + 20 * 4, 85, paint, SkTextUtils::kCenter_Align);
|
||||
SkTextUtils::DrawString(canvas, "(low bits)", 5 + 20 * 4, 137, paint, SkTextUtils::kCenter_Align);
|
||||
SkTextUtils::DrawString(canvas, "(low bits)", 5 + 20 * 3, 187, paint, SkTextUtils::kCenter_Align);
|
||||
SkTextUtils::DrawString(canvas, "(high bits)", 5 + 20 * 7, 187, paint, SkTextUtils::kCenter_Align);
|
||||
SkTextUtils::DrawString(canvas, "(low bits)", 5 + 20 * 2, 237, paint, SkTextUtils::kCenter_Align);
|
||||
SkTextUtils::DrawString(canvas, "(high bits)", 5 + 20 * 6, 237, paint, SkTextUtils::kCenter_Align);
|
||||
SkTextUtils::DrawString(canvas, "(high bits)", 5 + 20 * 5, 287, paint, SkTextUtils::kCenter_Align);
|
||||
SkFont font(nullptr, 10);
|
||||
SkTextUtils::DrawString(canvas, "32-bit word", 5 + 20 * 16, 20, font, paint, SkTextUtils::kCenter_Align);
|
||||
SkTextUtils::DrawString(canvas, "little endian byte order", 5 + 20 * 4, 85, font, paint, SkTextUtils::kCenter_Align);
|
||||
SkTextUtils::DrawString(canvas, "(low bits)", 5 + 20 * 4, 137, font, paint, SkTextUtils::kCenter_Align);
|
||||
SkTextUtils::DrawString(canvas, "(low bits)", 5 + 20 * 3, 187, font, paint, SkTextUtils::kCenter_Align);
|
||||
SkTextUtils::DrawString(canvas, "(high bits)", 5 + 20 * 7, 187, font, paint, SkTextUtils::kCenter_Align);
|
||||
SkTextUtils::DrawString(canvas, "(low bits)", 5 + 20 * 2, 237, font, paint, SkTextUtils::kCenter_Align);
|
||||
SkTextUtils::DrawString(canvas, "(high bits)", 5 + 20 * 6, 237, font, paint, SkTextUtils::kCenter_Align);
|
||||
SkTextUtils::DrawString(canvas, "(high bits)", 5 + 20 * 5, 287, font, paint, SkTextUtils::kCenter_Align);
|
||||
auto drawBoxText = [=](SkScalar e[], const char* s[], int count, int n, SkScalar yPos) -> void {
|
||||
SkPaint p(paint);
|
||||
p.setColor(SK_ColorRED);
|
||||
@ -319,7 +319,7 @@ void draw(SkCanvas* canvas) {
|
||||
int a = width - e[i];
|
||||
if (a == n || a == n + 1 || a == n - 32 || a == n - 31) {
|
||||
char num[3] = {(char) ('0' + n / 10), (char) ('0' + n % 10), '\0'};
|
||||
SkTextUtils::DrawString(canvas, n >= 10 ? num : &num[1], xPos, yPos - 5, p, SkTextUtils::kCenter_Align);
|
||||
SkTextUtils::DrawString(canvas, n >= 10 ? num : &num[1], xPos, yPos - 5, font, p, SkTextUtils::kCenter_Align);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -327,7 +327,7 @@ void draw(SkCanvas* canvas) {
|
||||
}
|
||||
p.setColor(SK_ColorBLACK);
|
||||
for (int i = 0; i < count; ++i) {
|
||||
SkTextUtils::DrawString(canvas, s[i], 5 + (e[i] + e[i + 1]) * 10, yPos + 10, p, SkTextUtils::kCenter_Align);
|
||||
SkTextUtils::DrawString(canvas, s[i], 5 + (e[i] + e[i + 1]) * 10, yPos + 10, font, p, SkTextUtils::kCenter_Align);
|
||||
}
|
||||
p.setStyle(SkPaint::kStroke_Style);
|
||||
for (int i = 0; i <= count; ++i) {
|
||||
@ -367,15 +367,15 @@ void draw(SkCanvas* canvas) {
|
||||
canvas->scale(1.25f, 1.25f);
|
||||
SkPaint paint;
|
||||
paint.setAntiAlias(true);
|
||||
paint.setTextSize(10);
|
||||
SkTextUtils::DrawString(canvas, "32-bit word", 5 + 20 * 16, 20, paint, SkTextUtils::kCenter_Align);
|
||||
SkTextUtils::DrawString(canvas, "little endian byte order", 5 + 20 * 4, 85, paint, SkTextUtils::kCenter_Align);
|
||||
SkTextUtils::DrawString(canvas, "(low bits)", 5 + 20 * 4, 137, paint, SkTextUtils::kCenter_Align);
|
||||
SkTextUtils::DrawString(canvas, "(low bits)", 5 + 20 * 3, 187, paint, SkTextUtils::kCenter_Align);
|
||||
SkTextUtils::DrawString(canvas, "(high bits)", 5 + 20 * 7, 187, paint, SkTextUtils::kCenter_Align);
|
||||
SkTextUtils::DrawString(canvas, "(low bits)", 5 + 20 * 2, 237, paint, SkTextUtils::kCenter_Align);
|
||||
SkTextUtils::DrawString(canvas, "(high bits)", 5 + 20 * 6, 237, paint, SkTextUtils::kCenter_Align);
|
||||
SkTextUtils::DrawString(canvas, "(high bits)", 5 + 20 * 5, 287, paint, SkTextUtils::kCenter_Align);
|
||||
SkFont font(nullptr, 10);
|
||||
SkTextUtils::DrawString(canvas, "32-bit word", 5 + 20 * 16, 20, font, paint, SkTextUtils::kCenter_Align);
|
||||
SkTextUtils::DrawString(canvas, "little endian byte order", 5 + 20 * 4, 85, font, paint, SkTextUtils::kCenter_Align);
|
||||
SkTextUtils::DrawString(canvas, "(low bits)", 5 + 20 * 4, 137, font, paint, SkTextUtils::kCenter_Align);
|
||||
SkTextUtils::DrawString(canvas, "(low bits)", 5 + 20 * 3, 187, font, paint, SkTextUtils::kCenter_Align);
|
||||
SkTextUtils::DrawString(canvas, "(high bits)", 5 + 20 * 7, 187, font, paint, SkTextUtils::kCenter_Align);
|
||||
SkTextUtils::DrawString(canvas, "(low bits)", 5 + 20 * 2, 237, font, paint, SkTextUtils::kCenter_Align);
|
||||
SkTextUtils::DrawString(canvas, "(high bits)", 5 + 20 * 6, 237, font, paint, SkTextUtils::kCenter_Align);
|
||||
SkTextUtils::DrawString(canvas, "(high bits)", 5 + 20 * 5, 287, font, paint, SkTextUtils::kCenter_Align);
|
||||
auto drawBoxText = [=](SkScalar e[], const char* s[], int count, int n, SkScalar yPos) -> void {
|
||||
SkPaint p(paint);
|
||||
p.setColor(SK_ColorRED);
|
||||
@ -387,7 +387,7 @@ void draw(SkCanvas* canvas) {
|
||||
int a = width - e[i];
|
||||
if (a == n || a == n + 1 || a == n - 32 || a == n - 31) {
|
||||
char num[3] = {(char) ('0' + n / 10), (char) ('0' + n % 10), '\0'};
|
||||
SkTextUtils::DrawString(canvas, n >= 10 ? num : &num[1], xPos, yPos - 5, p, SkTextUtils::kCenter_Align);
|
||||
SkTextUtils::DrawString(canvas, n >= 10 ? num : &num[1], xPos, yPos - 5, font, p, SkTextUtils::kCenter_Align);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -395,7 +395,7 @@ void draw(SkCanvas* canvas) {
|
||||
}
|
||||
p.setColor(SK_ColorBLACK);
|
||||
for (int i = 0; i < count; ++i) {
|
||||
SkTextUtils::DrawString(canvas, s[i], 5 + (e[i] + e[i + 1]) * 10, yPos + 10, p, SkTextUtils::kCenter_Align);
|
||||
SkTextUtils::DrawString(canvas, s[i], 5 + (e[i] + e[i + 1]) * 10, yPos + 10, font, p, SkTextUtils::kCenter_Align);
|
||||
}
|
||||
p.setStyle(SkPaint::kStroke_Style);
|
||||
for (int i = 0; i <= count; ++i) {
|
||||
@ -435,12 +435,12 @@ void draw(SkCanvas* canvas) {
|
||||
canvas->scale(1.25f, 1.25f);
|
||||
SkPaint paint;
|
||||
paint.setAntiAlias(true);
|
||||
paint.setTextSize(10);
|
||||
SkTextUtils::DrawString(canvas, "64-bit word", 5 + 20 * 16, 20, paint, SkTextUtils::kCenter_Align);
|
||||
SkTextUtils::DrawString(canvas, "little endian byte order", 5 + 20 * 4, 135, paint, SkTextUtils::kCenter_Align);
|
||||
SkFont font(nullptr, 10);
|
||||
SkTextUtils::DrawString(canvas, "64-bit word", 5 + 20 * 16, 20, font, paint, SkTextUtils::kCenter_Align);
|
||||
SkTextUtils::DrawString(canvas, "little endian byte order", 5 + 20 * 4, 135, font, paint, SkTextUtils::kCenter_Align);
|
||||
for (int i = 0; i < 4; ++i) {
|
||||
SkTextUtils::DrawString(canvas, "(low bits)", 5 + 20 * 4, 187 + i * 100, paint, SkTextUtils::kCenter_Align);
|
||||
SkTextUtils::DrawString(canvas, "(high bits)", 5 + 20 * 4, 237 + i * 100, paint, SkTextUtils::kCenter_Align);
|
||||
SkTextUtils::DrawString(canvas, "(low bits)", 5 + 20 * 4, 187 + i * 100, font, paint, SkTextUtils::kCenter_Align);
|
||||
SkTextUtils::DrawString(canvas, "(high bits)", 5 + 20 * 4, 237 + i * 100, font, paint, SkTextUtils::kCenter_Align);
|
||||
}
|
||||
auto drawBoxText = [=](SkScalar e[], const char* s[], int count, int n, SkScalar yPos) -> void {
|
||||
SkPaint p(paint);
|
||||
@ -453,7 +453,7 @@ void draw(SkCanvas* canvas) {
|
||||
int a = width - e[i];
|
||||
if (a == n || a == n + 1 || a == n - 32 || a == n - 31) {
|
||||
char num[3] = {(char) ('0' + n / 10), (char) ('0' + n % 10), '\0'};
|
||||
SkTextUtils::DrawString(canvas, n >= 10 ? num : &num[1], xPos, yPos - 5, p, SkTextUtils::kCenter_Align);
|
||||
SkTextUtils::DrawString(canvas, n >= 10 ? num : &num[1], xPos, yPos - 5, font, p, SkTextUtils::kCenter_Align);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -461,7 +461,7 @@ void draw(SkCanvas* canvas) {
|
||||
}
|
||||
p.setColor(SK_ColorBLACK);
|
||||
for (int i = 0; i < count; ++i) {
|
||||
SkTextUtils::DrawString(canvas, s[i], 5 + (e[i] + e[i + 1]) * 10, yPos + 10, p, SkTextUtils::kCenter_Align);
|
||||
SkTextUtils::DrawString(canvas, s[i], 5 + (e[i] + e[i + 1]) * 10, yPos + 10, font, p, SkTextUtils::kCenter_Align);
|
||||
}
|
||||
p.setStyle(SkPaint::kStroke_Style);
|
||||
for (int i = 0; i <= count; ++i) {
|
||||
@ -503,12 +503,12 @@ void draw(SkCanvas* canvas) {
|
||||
canvas->scale(1.25f, 1.25f);
|
||||
SkPaint paint;
|
||||
paint.setAntiAlias(true);
|
||||
paint.setTextSize(10);
|
||||
SkTextUtils::DrawString(canvas, "128-bit word", 5 + 20 * 16, 20, paint, SkTextUtils::kCenter_Align);
|
||||
SkTextUtils::DrawString(canvas, "little endian byte order", 5 + 20 * 4, 135, paint, SkTextUtils::kCenter_Align);
|
||||
SkFont font(nullptr, 10);
|
||||
SkTextUtils::DrawString(canvas, "128-bit word", 5 + 20 * 16, 20, font, paint, SkTextUtils::kCenter_Align);
|
||||
SkTextUtils::DrawString(canvas, "little endian byte order", 5 + 20 * 4, 135, font, paint, SkTextUtils::kCenter_Align);
|
||||
for (int i = 0; i < 4; ++i) {
|
||||
SkTextUtils::DrawString(canvas, "(low bits)", 5 + 10 * 4, 187 + i * 100, paint, SkTextUtils::kCenter_Align);
|
||||
SkTextUtils::DrawString(canvas, "(high bits)", 105 + 10 * 4, 237 + i * 100, paint, SkTextUtils::kCenter_Align);
|
||||
SkTextUtils::DrawString(canvas, "(low bits)", 5 + 10 * 4, 187 + i * 100, font, paint, SkTextUtils::kCenter_Align);
|
||||
SkTextUtils::DrawString(canvas, "(high bits)", 105 + 10 * 4, 237 + i * 100, font, paint, SkTextUtils::kCenter_Align);
|
||||
}
|
||||
auto drawBoxText = [=](SkScalar e[], const char* s[], const char* nums[] ,
|
||||
int count, int n, SkScalar yPos) -> void {
|
||||
@ -522,9 +522,9 @@ void draw(SkCanvas* canvas) {
|
||||
if (2 == count) {
|
||||
x += stringIndex * 12 + (stringIndex ? 8 : 0);
|
||||
}
|
||||
SkTextUtils::DrawString(canvas, nums[stringIndex], x, yPos - 5, p, SkTextUtils::kCenter_Align);
|
||||
SkTextUtils::DrawString(canvas, nums[stringIndex], x, yPos - 5, font, p, SkTextUtils::kCenter_Align);
|
||||
if (1 == count) {
|
||||
SkTextUtils::DrawString(canvas, nums[stringIndex], xPos + 100, yPos - 5, p, SkTextUtils::kCenter_Align);
|
||||
SkTextUtils::DrawString(canvas, nums[stringIndex], xPos + 100, yPos - 5, font, p, SkTextUtils::kCenter_Align);
|
||||
}
|
||||
++stringIndex;
|
||||
}
|
||||
@ -532,9 +532,9 @@ void draw(SkCanvas* canvas) {
|
||||
}
|
||||
p.setColor(SK_ColorBLACK);
|
||||
for (int i = 0; i < count; ++i) {
|
||||
SkTextUtils::DrawString(canvas, s[i], 5 + (e[i] + e[i + 1]) * 5, yPos + 10, p, SkTextUtils::kCenter_Align);
|
||||
SkTextUtils::DrawString(canvas, s[i], 5 + (e[i] + e[i + 1]) * 5, yPos + 10, font, p, SkTextUtils::kCenter_Align);
|
||||
if (1 == count) {
|
||||
SkTextUtils::DrawString(canvas, s[i], 105 + (e[i] + e[i + 1]) * 5, yPos + 10, p, SkTextUtils::kCenter_Align);
|
||||
SkTextUtils::DrawString(canvas, s[i], 105 + (e[i] + e[i + 1]) * 5, yPos + 10, font, p, SkTextUtils::kCenter_Align);
|
||||
}
|
||||
}
|
||||
p.setStyle(SkPaint::kStroke_Style);
|
||||
@ -588,11 +588,10 @@ void draw(SkCanvas* canvas) {
|
||||
SkPaint srcPaint;
|
||||
srcPaint.setAntiAlias(true);
|
||||
SkPaint labelPaint = srcPaint;
|
||||
labelPaint.setTextSize(16);
|
||||
SkPaint dstPaint = labelPaint;
|
||||
dstPaint.setTextSize(80);
|
||||
SkFont labelFont(nullptr, 16);
|
||||
SkPaint dstPaint = srcPaint;
|
||||
dstPaint.setColor(0xFF606080);
|
||||
dstPaint.setTypeface(SkTypeface::MakeFromName("Roboto", SkFontStyle::Bold()));
|
||||
SkFont dstFont(SkTypeface::MakeFromName("Roboto", SkFontStyle::Bold()), 80);
|
||||
|
||||
SkBitmap srcBits;
|
||||
srcBits.allocN32Pixels(80, 84);
|
||||
@ -610,10 +609,10 @@ void draw(SkCanvas* canvas) {
|
||||
SkBlendMode::kDst, SkBlendMode::kDstATop, SkBlendMode::kDstOver,
|
||||
SkBlendMode::kDstIn, SkBlendMode::kDstOut,
|
||||
SkBlendMode::kClear, SkBlendMode::kXor } ) {
|
||||
SkTextUtils::DrawString(canvas, "&", 50, 80, dstPaint, SkTextUtils::kCenter_Align);
|
||||
SkTextUtils::DrawString(canvas, "&", 50, 80, dstFont, dstPaint, SkTextUtils::kCenter_Align);
|
||||
srcPaint.setBlendMode(blend);
|
||||
canvas->drawBitmap(srcBits, 0, 0, &srcPaint);
|
||||
SkTextUtils::DrawString(canvas, SkBlendMode_Name(blend), 50, 100, labelPaint, SkTextUtils::kCenter_Align);
|
||||
SkTextUtils::DrawString(canvas, SkBlendMode_Name(blend), 50, 100, labelFont, labelPaint, SkTextUtils::kCenter_Align);
|
||||
canvas->translate(80, 0);
|
||||
if (SkBlendMode::kSrcOut == blend || SkBlendMode::kDstOut == blend) {
|
||||
canvas->translate(-80 * 5, 100);
|
||||
@ -637,11 +636,10 @@ void draw(SkCanvas* canvas) {
|
||||
SkPaint srcPaint;
|
||||
srcPaint.setAntiAlias(true);
|
||||
SkPaint labelPaint = srcPaint;
|
||||
labelPaint.setTextSize(16);
|
||||
SkPaint dstPaint = labelPaint;
|
||||
dstPaint.setTextSize(80);
|
||||
SkFont labelFont(nullptr, 16);
|
||||
SkPaint dstPaint = srcPaint;
|
||||
dstPaint.setColor(0xFF606080);
|
||||
dstPaint.setTypeface(SkTypeface::MakeFromName("Roboto", SkFontStyle::Bold()));
|
||||
SkFont dstFont(SkTypeface::MakeFromName("Roboto", SkFontStyle::Bold()), 80);
|
||||
|
||||
srcPaint.setColor(0xFFcc6633);
|
||||
SkPath srcPath;
|
||||
@ -657,10 +655,10 @@ void draw(SkCanvas* canvas) {
|
||||
SkBlendMode::kDst, SkBlendMode::kDstATop, SkBlendMode::kDstOver,
|
||||
SkBlendMode::kDstIn, SkBlendMode::kDstOut,
|
||||
SkBlendMode::kClear, SkBlendMode::kXor } ) {
|
||||
SkTextUtils::DrawString(canvas, "&", 50, 80, dstPaint, SkTextUtils::kCenter_Align);
|
||||
SkTextUtils::DrawString(canvas, "&", 50, 80, dstFont, dstPaint, SkTextUtils::kCenter_Align);
|
||||
srcPaint.setBlendMode(blend);
|
||||
canvas->drawPath(srcPath, srcPaint);
|
||||
SkTextUtils::DrawString(canvas, SkBlendMode_Name(blend), 50, 100, labelPaint, SkTextUtils::kCenter_Align);
|
||||
SkTextUtils::DrawString(canvas, SkBlendMode_Name(blend), 50, 100, labelFont, labelPaint, SkTextUtils::kCenter_Align);
|
||||
canvas->translate(80, 0);
|
||||
if (SkBlendMode::kSrcOut == blend || SkBlendMode::kDstOut == blend) {
|
||||
canvas->translate(-80 * 5, 100);
|
||||
@ -684,11 +682,10 @@ void draw(SkCanvas* canvas) {
|
||||
SkPaint srcPaint;
|
||||
srcPaint.setAntiAlias(true);
|
||||
SkPaint labelPaint = srcPaint;
|
||||
labelPaint.setTextSize(16);
|
||||
SkPaint dstPaint = labelPaint;
|
||||
dstPaint.setTextSize(80);
|
||||
SkFont labelFont(nullptr, 16);
|
||||
SkPaint dstPaint = srcPaint;
|
||||
dstPaint.setColor(0xFF606080);
|
||||
dstPaint.setTypeface(SkTypeface::MakeFromName("Roboto", SkFontStyle::Bold()));
|
||||
SkFont dstFont(SkTypeface::MakeFromName("Roboto", SkFontStyle::Bold()), 80);
|
||||
|
||||
srcPaint.setColor(0xFFcc6633);
|
||||
SkPath srcPath;
|
||||
@ -699,10 +696,11 @@ void draw(SkCanvas* canvas) {
|
||||
SkBlendMode::kDarken, SkBlendMode::kLighten, SkBlendMode::kColorDodge,
|
||||
SkBlendMode::kColorBurn, SkBlendMode::kHardLight, SkBlendMode::kSoftLight,
|
||||
SkBlendMode::kDifference, SkBlendMode::kExclusion, SkBlendMode::kMultiply } ) {
|
||||
SkTextUtils::DrawString(canvas, "&", 50, 80, dstPaint, SkTextUtils::kCenter_Align);
|
||||
SkTextUtils::DrawString(canvas, "&", 50, 80, dstFont, dstPaint, SkTextUtils::kCenter_Align);
|
||||
srcPaint.setBlendMode(blend);
|
||||
canvas->drawPath(srcPath, srcPaint);
|
||||
SkTextUtils::DrawString(canvas, SkBlendMode_Name(blend), 50, 100, labelPaint, SkTextUtils::kCenter_Align);
|
||||
SkTextUtils::DrawString(canvas, SkBlendMode_Name(blend), 50, 100, labelFont, labelPaint,
|
||||
SkTextUtils::kCenter_Align);
|
||||
canvas->translate(90, 0);
|
||||
if (SkBlendMode::kLighten == blend || SkBlendMode::kDifference == blend) {
|
||||
canvas->translate(-90 * 5, 100);
|
||||
@ -723,29 +721,28 @@ $$$#
|
||||
##
|
||||
|
||||
void draw(SkCanvas* canvas) {
|
||||
SkPaint srcPaint;
|
||||
srcPaint.setAntiAlias(true);
|
||||
SkPaint labelPaint = srcPaint;
|
||||
labelPaint.setTextSize(16);
|
||||
SkPaint dstPaint = labelPaint;
|
||||
dstPaint.setTextSize(80);
|
||||
dstPaint.setColor(0xFF606080);
|
||||
dstPaint.setTypeface(SkTypeface::MakeFromName("Roboto", SkFontStyle::Bold()));
|
||||
|
||||
srcPaint.setColor(0xFFcc6633);
|
||||
SkPath srcPath;
|
||||
const SkPoint points[] = {{20, 20}, {80, 45}, {45, 80}};
|
||||
srcPath.addPoly(points, SK_ARRAY_COUNT(points), true);
|
||||
canvas->drawColor(0, SkBlendMode::kClear);
|
||||
for (auto blend : { SkBlendMode::kHue, SkBlendMode::kSaturation, SkBlendMode::kColor,
|
||||
SkBlendMode::kLuminosity } ) {
|
||||
SkTextUtils::DrawString(canvas, "&", 50, 80, dstPaint, SkTextUtils::kCenter_Align);
|
||||
srcPaint.setBlendMode(blend);
|
||||
canvas->drawPath(srcPath, srcPaint);
|
||||
SkTextUtils::DrawString(canvas, SkBlendMode_Name(blend), 50, 100, labelPaint,
|
||||
SkTextUtils::kCenter_Align);
|
||||
canvas->translate(90, 0);
|
||||
}
|
||||
SkPaint srcPaint;
|
||||
srcPaint.setAntiAlias(true);
|
||||
SkPaint labelPaint = srcPaint;
|
||||
SkFont labelFont(nullptr, 16);
|
||||
SkPaint dstPaint = labelPaint;
|
||||
dstPaint.setColor(0xFF606080);
|
||||
SkFont dstFont(SkTypeface::MakeFromName("Roboto", SkFontStyle::Bold()), 80);
|
||||
|
||||
srcPaint.setColor(0xFFcc6633);
|
||||
SkPath srcPath;
|
||||
const SkPoint points[] = {{20, 20}, {80, 45}, {45, 80}};
|
||||
srcPath.addPoly(points, SK_ARRAY_COUNT(points), true);
|
||||
canvas->drawColor(0, SkBlendMode::kClear);
|
||||
for (auto blend : { SkBlendMode::kHue, SkBlendMode::kSaturation, SkBlendMode::kColor,
|
||||
SkBlendMode::kLuminosity } ) {
|
||||
SkTextUtils::DrawString(canvas, "&", 50, 80, dstFont, dstPaint, SkTextUtils::kCenter_Align);
|
||||
srcPaint.setBlendMode(blend);
|
||||
canvas->drawPath(srcPath, srcPaint);
|
||||
SkTextUtils::DrawString(canvas, SkBlendMode_Name(blend), 50, 100, labelFont, labelPaint,
|
||||
SkTextUtils::kCenter_Align);
|
||||
canvas->translate(90, 0);
|
||||
}
|
||||
}
|
||||
##
|
||||
##
|
||||
@ -764,11 +761,10 @@ void draw(SkCanvas* canvas) {
|
||||
SkPaint srcPaint;
|
||||
srcPaint.setAntiAlias(true);
|
||||
SkPaint labelPaint = srcPaint;
|
||||
labelPaint.setTextSize(16);
|
||||
SkPaint dstPaint = labelPaint;
|
||||
dstPaint.setTextSize(80);
|
||||
SkFont labelFont(nullptr, 16);
|
||||
SkPaint dstPaint = srcPaint;
|
||||
dstPaint.setColor(0xFF606080);
|
||||
dstPaint.setTypeface(SkTypeface::MakeFromName("Roboto", SkFontStyle::Bold()));
|
||||
SkFont dstFont(SkTypeface::MakeFromName("Roboto", SkFontStyle::Bold()), 80);
|
||||
|
||||
SkBitmap srcBits;
|
||||
srcBits.allocN32Pixels(80, 84);
|
||||
@ -783,15 +779,15 @@ void draw(SkCanvas* canvas) {
|
||||
canvas->drawColor(0, SkBlendMode::kClear);
|
||||
srcPaint.setBlendMode(SkBlendMode::kModulate);
|
||||
for (auto step: { 1, 2 } ) {
|
||||
SkTextUtils::DrawString(canvas, "&", 50, 80, dstPaint, SkTextUtils::kCenter_Align);
|
||||
SkTextUtils::DrawString(canvas, "&", 50, 80, dstFont, dstPaint, SkTextUtils::kCenter_Align);
|
||||
if (1 == step) {
|
||||
canvas->drawBitmap(srcBits, 0, 0, &srcPaint);
|
||||
SkTextUtils::DrawString(canvas, "Bitmap", 50, 18, labelPaint, SkTextUtils::kCenter_Align);
|
||||
SkTextUtils::DrawString(canvas, "Bitmap", 50, 18, labelFont, labelPaint, SkTextUtils::kCenter_Align);
|
||||
} else {
|
||||
canvas->drawPath(srcPath, srcPaint);
|
||||
SkTextUtils::DrawString(canvas, "Geometry", 50, 18, labelPaint, SkTextUtils::kCenter_Align);
|
||||
SkTextUtils::DrawString(canvas, "Geometry", 50, 18, labelFont, labelPaint, SkTextUtils::kCenter_Align);
|
||||
}
|
||||
SkTextUtils::DrawString(canvas, SkBlendMode_Name(SkBlendMode::kModulate), 50, 100, labelPaint,
|
||||
SkTextUtils::DrawString(canvas, SkBlendMode_Name(SkBlendMode::kModulate), 50, 100, labelFont, labelPaint,
|
||||
SkTextUtils::kCenter_Align);
|
||||
canvas->translate(120, 0);
|
||||
}
|
||||
@ -844,54 +840,59 @@ const char* yna[] = {
|
||||
$$$#
|
||||
##
|
||||
void draw(SkCanvas* canvas) {
|
||||
SkPaint lp;
|
||||
lp.setAntiAlias(true);
|
||||
SkPaint tp(lp);
|
||||
SkPaint sp(tp);
|
||||
SkPaint bp(tp);
|
||||
bp.setFakeBoldText(true);
|
||||
sp.setTextSize(10);
|
||||
lp.setColor(SK_ColorGRAY);
|
||||
canvas->translate(0, 32);
|
||||
const int tl = 115;
|
||||
for (unsigned col = 0; col <= SK_ARRAY_COUNT(headers); ++col) {
|
||||
canvas->drawLine(tl + col * 35, 100, tl + col * 35, 250, lp);
|
||||
if (0 == col) {
|
||||
continue;
|
||||
}
|
||||
canvas->drawLine( tl + col * 35, 100, tl + 100 + col * 35, 0, lp);
|
||||
SkPoint pts[] = {{tl - 10.f + col * 35, 98}, {tl + 90.f + col * 35, -2}};
|
||||
SkVector v = pts[1] - pts[0];
|
||||
v.normalize();
|
||||
SkMatrix matrix;
|
||||
matrix.setSinCos(v.fY, v.fX, pts[0].fX, pts[0].fY);
|
||||
canvas->save();
|
||||
canvas->concat(matrix);
|
||||
canvas->drawText(headers[col -1], strlen(headers[col -1]), pts[0].fX, pts[0].fY, bp);
|
||||
canvas->restore();
|
||||
}
|
||||
for (unsigned row = 0; row <= SK_ARRAY_COUNT(dataSet); ++row) {
|
||||
if (0 == row) {
|
||||
canvas->drawLine(tl, 100, tl + 350, 100, lp);
|
||||
} else {
|
||||
canvas->drawLine(5, 100 + row * 25, tl + 350, 100 + row * 25, lp);
|
||||
}
|
||||
if (row == SK_ARRAY_COUNT(dataSet)) {
|
||||
break;
|
||||
}
|
||||
canvas->drawString(dataSet[row].name, 5, 117 + row * 25, bp);
|
||||
if (dataSet[row].super) {
|
||||
SkScalar width = bp.measureText(dataSet[row].name, strlen(dataSet[row].name));
|
||||
canvas->drawText(&dataSet[row].super, 1, 8 + width, 112 + row * 25, sp);
|
||||
}
|
||||
for (unsigned col = 0; col < SK_ARRAY_COUNT(headers); ++col) {
|
||||
int val = dataSet[row].yn[col];
|
||||
canvas->drawString(yna[SkTMin(2, val + 1)], tl + 5 + col * 35, 117 + row * 25, tp);
|
||||
if (val > 1) {
|
||||
char supe = '0' + val - 1;
|
||||
canvas->drawText(&supe, 1, tl + 25 + col * 35, 112 + row * 25, sp);
|
||||
}
|
||||
}
|
||||
SkPaint lp;
|
||||
lp.setAntiAlias(true);
|
||||
SkPaint tp(lp);
|
||||
SkPaint sp(tp);
|
||||
SkFont bf;
|
||||
bf.setEmbolden(true);
|
||||
SkFont sf(nullptr, 10);
|
||||
lp.setColor(SK_ColorGRAY);
|
||||
canvas->translate(0, 32);
|
||||
const int tl = 115;
|
||||
for (unsigned col = 0; col <= SK_ARRAY_COUNT(headers); ++col) {
|
||||
canvas->drawLine(tl + col * 35, 100, tl + col * 35, 250, lp);
|
||||
if (0 == col) {
|
||||
continue;
|
||||
}
|
||||
canvas->drawLine( tl + col * 35, 100, tl + 100 + col * 35, 0, lp);
|
||||
SkPoint pts[] = {{tl - 10.f + col * 35, 98}, {tl + 90.f + col * 35, -2}};
|
||||
SkVector v = pts[1] - pts[0];
|
||||
v.normalize();
|
||||
SkMatrix matrix;
|
||||
matrix.setSinCos(v.fY, v.fX, pts[0].fX, pts[0].fY);
|
||||
canvas->save();
|
||||
canvas->concat(matrix);
|
||||
canvas->drawSimpleText(headers[col -1], strlen(headers[col -1]), SkTextEncoding::kUTF8,
|
||||
pts[0].fX, pts[0].fY, bf, lp);
|
||||
canvas->restore();
|
||||
}
|
||||
for (unsigned row = 0; row <= SK_ARRAY_COUNT(dataSet); ++row) {
|
||||
if (0 == row) {
|
||||
canvas->drawLine(tl, 100, tl + 350, 100, lp);
|
||||
} else {
|
||||
canvas->drawLine(5, 100 + row * 25, tl + 350, 100 + row * 25, lp);
|
||||
}
|
||||
if (row == SK_ARRAY_COUNT(dataSet)) {
|
||||
break;
|
||||
}
|
||||
canvas->drawSimpleText(dataSet[row].name, strlen(dataSet[row].name),
|
||||
SkTextEncoding::kUTF8, 5, 117 + row * 25, bf, lp);
|
||||
if (dataSet[row].super) {
|
||||
SkScalar width = bf.measureText(dataSet[row].name, strlen(dataSet[row].name),
|
||||
SkTextEncoding::kUTF8);
|
||||
canvas->drawSimpleText(&dataSet[row].super, 1, SkTextEncoding::kUTF8,
|
||||
8 + width, 112 + row * 25, sf, lp);
|
||||
}
|
||||
for (unsigned col = 0; col < SK_ARRAY_COUNT(headers); ++col) {
|
||||
int val = dataSet[row].yn[col];
|
||||
canvas->drawString(yna[SkTMin(2, val + 1)], tl + 5 + col * 35, 117 + row * 25, tp);
|
||||
if (val > 1) {
|
||||
char supe = '0' + val - 1;
|
||||
canvas->drawSimpleText(&supe, 1, SkTextEncoding::kUTF8,
|
||||
tl + 25 + col * 35, 112 + row * 25, sf, lp);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#Example ##
|
||||
|
@ -187,7 +187,8 @@ replicate replicated replicates report reports represent representation represen
|
||||
representative represented representing represents request requested requests require
|
||||
required requirements requires requiring resemble reserve reserved
|
||||
reset resets reside residing resolution
|
||||
resolves resource resources respect respects responsible restore restored restores restoring
|
||||
resolves resource resources respect respected respects
|
||||
responsible restore restored restores restoring
|
||||
restrict restricted restriction restrictive restricts result resulting results retain
|
||||
retained retains retrieve retrieved retrieves retroactive return returned returning returns
|
||||
reused reveals reverse reversed reverses revert rewinds right right-bottom right-top rightmost root
|
||||
@ -249,7 +250,7 @@ wide-open widens wider width widths will wind winding windows winds with within
|
||||
word words work works world would wrap wrapped wraps writable write writes writing
|
||||
written wrong
|
||||
|
||||
x-axis x-coordinate x-radii
|
||||
x-axis x-coordinate x-position x-positions x-radii
|
||||
|
||||
y-axis y-coordinate y-radii yellow
|
||||
|
||||
|
@ -44,7 +44,11 @@ public:
|
||||
*/
|
||||
SkFont(sk_sp<SkTypeface> typeface, SkScalar size);
|
||||
|
||||
// Experimental
|
||||
/** Constructs SkFont with default values with SkTypeface.
|
||||
|
||||
@param typeface font and style used to draw and measure text
|
||||
@return initialized SkFont
|
||||
*/
|
||||
explicit SkFont(sk_sp<SkTypeface> typeface);
|
||||
|
||||
|
||||
@ -68,7 +72,13 @@ public:
|
||||
@return true if SkFont pair are equivalent
|
||||
*/
|
||||
bool operator==(const SkFont& font) const;
|
||||
// Experimental
|
||||
|
||||
/** Compares SkFont and font, and returns true if they are not equivalent.
|
||||
May return true if SkTypeface has identical contents but different pointers.
|
||||
|
||||
@param font font to compare
|
||||
@return true if SkFont pair are not equivalent
|
||||
*/
|
||||
bool operator!=(const SkFont& font) const { return !(*this == font); }
|
||||
|
||||
/** If true, instructs the font manager to always hint glyphs.
|
||||
@ -334,9 +344,21 @@ public:
|
||||
return this->measureText(text, byteLength, encoding, bounds, nullptr);
|
||||
}
|
||||
|
||||
// Experimental
|
||||
/** Returns the advance width of text.
|
||||
The advance is the normal distance to move before drawing additional text.
|
||||
Returns the bounding box of text if bounds is not nullptr. paint
|
||||
stroke width or SkPathEffect may modify the advance with.
|
||||
|
||||
@param text character storage encoded with SkTextEncoding
|
||||
@param byteLength length of character storage in bytes
|
||||
@param encoding one of: kUTF8_SkTextEncoding, kUTF16_SkTextEncoding,
|
||||
kUTF32_SkTextEncoding, kGlyphID_SkTextEncoding
|
||||
@param bounds returns bounding box relative to (0, 0) if not nullptr
|
||||
@param paint optional; may be nullptr
|
||||
@return number of glyphs represented by text of length byteLength
|
||||
*/
|
||||
SkScalar measureText(const void* text, size_t byteLength, SkTextEncoding encoding,
|
||||
SkRect* bounds, const SkPaint*) const;
|
||||
SkRect* bounds, const SkPaint* paint) const;
|
||||
|
||||
/** DEPRECATED
|
||||
Retrieves the advance and bounds for each glyph in glyphs.
|
||||
@ -358,8 +380,7 @@ public:
|
||||
this->getWidths(glyphs, count, widths);
|
||||
}
|
||||
|
||||
/** Experimental
|
||||
Retrieves the advance and bounds for each glyph in glyphs.
|
||||
/** Retrieves the advance and bounds for each glyph in glyphs.
|
||||
Both widths and bounds may be nullptr.
|
||||
If widths is not nullptr, widths must be an array of count entries.
|
||||
if bounds is not nullptr, bounds must be an array of count entries.
|
||||
@ -372,8 +393,7 @@ public:
|
||||
this->getWidthsBounds(glyphs, count, widths, nullptr, nullptr);
|
||||
}
|
||||
|
||||
/** Experimental.
|
||||
Retrieves the advance and bounds for each glyph in glyphs.
|
||||
/** Retrieves the advance and bounds for each glyph in glyphs.
|
||||
Both widths and bounds may be nullptr.
|
||||
If widths is not nullptr, widths must be an array of count entries.
|
||||
if bounds is not nullptr, bounds must be an array of count entries.
|
||||
@ -388,8 +408,7 @@ public:
|
||||
const SkPaint* paint) const;
|
||||
|
||||
|
||||
/** Experimental.
|
||||
Retrieves the bounds for each glyph in glyphs.
|
||||
/** Retrieves the bounds for each glyph in glyphs.
|
||||
bounds must be an array of count entries.
|
||||
If paint is not nullptr, its stroking, SkPathEffect, and SkMaskFilter fields are respected.
|
||||
|
||||
@ -403,8 +422,7 @@ public:
|
||||
this->getWidthsBounds(glyphs, count, nullptr, bounds, paint);
|
||||
}
|
||||
|
||||
/** Experimental
|
||||
Retrieves the positions for each glyph, beginning at the specified origin. The caller
|
||||
/** Retrieves the positions for each glyph, beginning at the specified origin. The caller
|
||||
must allocated at least count number of elements in the pos[] array.
|
||||
|
||||
@param glyphs array of glyph indices to be positioned
|
||||
@ -414,8 +432,7 @@ public:
|
||||
*/
|
||||
void getPos(const uint16_t glyphs[], int count, SkPoint pos[], SkPoint origin = {0, 0}) const;
|
||||
|
||||
/** Experimental
|
||||
Retrieves the x-positions for each glyph, beginning at the specified origin. The caller
|
||||
/** Retrieves the x-positions for each glyph, beginning at the specified origin. The caller
|
||||
must allocated at least count number of elements in the xpos[] array.
|
||||
|
||||
@param glyphs array of glyph indices to be positioned
|
||||
|
@ -889,7 +889,7 @@ private:
|
||||
#ifdef SK_SUPPORT_LEGACY_PAINTTEXTENCODING
|
||||
/**
|
||||
* Returns the text encoding. Text encoding describes how to interpret the text bytes pass
|
||||
* to methods like measureText() and SkCanvas::drawText().
|
||||
* to methods like SkFont::measureText() and SkCanvas::drawText().
|
||||
* @return the text encoding
|
||||
*/
|
||||
SkTextEncoding getTextEncoding() const {
|
||||
@ -898,7 +898,7 @@ private:
|
||||
|
||||
/**
|
||||
* Sets the text encoding. Text encoding describes how to interpret the text bytes pass
|
||||
* to methods like measureText() and SkCanvas::drawText().
|
||||
* to methods like SkFont::measureText() and SkCanvas::drawText().
|
||||
* @param encoding the new text encoding
|
||||
*/
|
||||
void setTextEncoding(SkTextEncoding encoding);
|
||||
@ -909,63 +909,20 @@ public:
|
||||
|
||||
#ifdef SK_SUPPORT_LEGACY_PAINT_TEXTMEASURE
|
||||
|
||||
/** Returns SkFontMetrics associated with SkTypeface.
|
||||
The return value is the recommended spacing between lines: the sum of metrics
|
||||
descent, ascent, and leading.
|
||||
If metrics is not nullptr, SkFontMetrics is copied to metrics.
|
||||
Results are scaled by text size but does not take into account
|
||||
dimensions required by text scale x, text skew x, fake bold,
|
||||
style stroke, and SkPathEffect.
|
||||
|
||||
@param metrics storage for SkFontMetrics; may be nullptr
|
||||
@return recommended spacing between lines
|
||||
/** Deprecated; use SkFont::getMetrics instead
|
||||
*/
|
||||
SkScalar getFontMetrics(SkFontMetrics* metrics) const;
|
||||
|
||||
/** Returns the recommended spacing between lines: the sum of metrics
|
||||
descent, ascent, and leading.
|
||||
Result is scaled by text size but does not take into account
|
||||
dimensions required by stroking and SkPathEffect.
|
||||
Returns the same result as getFontMetrics().
|
||||
|
||||
@return recommended spacing between lines
|
||||
/** Deprecated; use SkFont::getSpacing instead
|
||||
*/
|
||||
SkScalar getFontSpacing() const { return this->getFontMetrics(nullptr); }
|
||||
|
||||
/** Converts text into glyph indices.
|
||||
Returns the number of glyph indices represented by text.
|
||||
SkTextEncoding specifies how text represents characters or glyphs.
|
||||
glyphs may be nullptr, to compute the glyph count.
|
||||
|
||||
Does not check text for valid character codes or valid glyph indices.
|
||||
|
||||
If byteLength equals zero, returns zero.
|
||||
If byteLength includes a partial character, the partial character is ignored.
|
||||
|
||||
If SkTextEncoding is kUTF8_SkTextEncoding and
|
||||
text contains an invalid UTF-8 sequence, zero is returned.
|
||||
|
||||
@param text character storage encoded with SkTextEncoding
|
||||
@param byteLength length of character storage in bytes
|
||||
@param glyphs storage for glyph indices; may be nullptr
|
||||
@return number of glyphs represented by text of length byteLength
|
||||
/** Deprecated; use SkFont::textToGlyphs instead
|
||||
*/
|
||||
int textToGlyphs(const void* text, size_t byteLength,
|
||||
SkGlyphID glyphs[]) const;
|
||||
|
||||
/** Returns true if all text corresponds to a non-zero glyph index.
|
||||
Returns false if any characters in text are not supported in
|
||||
SkTypeface.
|
||||
|
||||
If SkTextEncoding is kGlyphID_SkTextEncoding,
|
||||
returns true if all glyph indices in text are non-zero;
|
||||
does not check to see if text contains valid glyph indices for SkTypeface.
|
||||
|
||||
Returns true if byteLength is zero.
|
||||
|
||||
@param text array of characters or glyphs
|
||||
@param byteLength number of bytes in text array
|
||||
@return true if all text corresponds to a non-zero glyph index
|
||||
/** Deprecated; use SkFont::containsText instead
|
||||
*/
|
||||
bool containsText(const void* text, size_t byteLength) const;
|
||||
#endif
|
||||
@ -984,90 +941,31 @@ public:
|
||||
void glyphsToUnichars(const SkGlyphID glyphs[], int count, SkUnichar text[]) const;
|
||||
|
||||
#ifdef SK_SUPPORT_LEGACY_PAINT_TEXTMEASURE
|
||||
/** Returns the number of glyphs in text.
|
||||
Uses SkTextEncoding to count the glyphs.
|
||||
Returns the same result as textToGlyphs().
|
||||
|
||||
@param text character storage encoded with SkTextEncoding
|
||||
@param byteLength length of character storage in bytes
|
||||
@return number of glyphs represented by text of length byteLength
|
||||
/** Deprecated; use SkFont::countText instead
|
||||
*/
|
||||
int countText(const void* text, size_t byteLength) const;
|
||||
|
||||
/** Returns the advance width of text.
|
||||
The advance is the normal distance to move before drawing additional text.
|
||||
Uses SkTextEncoding to decode text, SkTypeface to get the font metrics,
|
||||
and text size, text scale x, text skew x, stroke width, and
|
||||
SkPathEffect to scale the metrics and bounds.
|
||||
Returns the bounding box of text if bounds is not nullptr.
|
||||
The bounding box is computed as if the text was drawn at the origin.
|
||||
|
||||
@param text character codes or glyph indices to be measured
|
||||
@param length number of bytes of text to measure
|
||||
@param bounds returns bounding box relative to (0, 0) if not nullptr
|
||||
@return advance width or height
|
||||
/** Deprecated; use SkFont::measureText instead
|
||||
*/
|
||||
SkScalar measureText(const void* text, size_t length, SkRect* bounds) const;
|
||||
|
||||
/** Returns the advance width of text.
|
||||
The advance is the normal distance to move before drawing additional text.
|
||||
Uses SkTextEncoding to decode text, SkTypeface to get the font metrics,
|
||||
and text size to scale the metrics.
|
||||
Does not scale the advance or bounds by fake bold or SkPathEffect.
|
||||
|
||||
@param text character codes or glyph indices to be measured
|
||||
@param length number of bytes of text to measure
|
||||
@return advance width or height
|
||||
/** Deprecated; use SkFont::measureText instead
|
||||
*/
|
||||
SkScalar measureText(const void* text, size_t length) const {
|
||||
return this->measureText(text, length, nullptr);
|
||||
}
|
||||
|
||||
/** Retrieves the advance and bounds for each glyph in text, and returns
|
||||
the glyph count in text.
|
||||
Both widths and bounds may be nullptr.
|
||||
If widths is not nullptr, widths must be an array of glyph count entries.
|
||||
if bounds is not nullptr, bounds must be an array of glyph count entries.
|
||||
Uses SkTextEncoding to decode text, SkTypeface to get the font metrics,
|
||||
and text size to scale the widths and bounds.
|
||||
Does not scale the advance by fake bold or SkPathEffect.
|
||||
Does include fake bold and SkPathEffect in the bounds.
|
||||
|
||||
@param text character codes or glyph indices to be measured
|
||||
@param byteLength number of bytes of text to measure
|
||||
@param widths returns text advances for each glyph; may be nullptr
|
||||
@param bounds returns bounds for each glyph relative to (0, 0); may be nullptr
|
||||
@return glyph count in text
|
||||
/** Deprecated; use SkFont::getWidthsBounds instead
|
||||
*/
|
||||
int getTextWidths(const void* text, size_t byteLength, SkScalar widths[],
|
||||
SkRect bounds[] = nullptr) const;
|
||||
|
||||
/** Returns the geometry as SkPath equivalent to the drawn text.
|
||||
Uses SkTextEncoding to decode text, SkTypeface to get the glyph paths,
|
||||
and text size, fake bold, and SkPathEffect to scale and modify the glyph paths.
|
||||
All of the glyph paths are stored in path.
|
||||
Uses x, y, to position path.
|
||||
|
||||
@param text character codes or glyph indices
|
||||
@param length number of bytes of text
|
||||
@param x x-axis value of the origin of the text
|
||||
@param y y-axis value of the origin of the text
|
||||
@param path geometry of the glyphs
|
||||
/** Deprecated; use SkFont::getPath instead
|
||||
*/
|
||||
void getTextPath(const void* text, size_t length, SkScalar x, SkScalar y,
|
||||
SkPath* path) const;
|
||||
|
||||
/** Returns the geometry as SkPath equivalent to the drawn text.
|
||||
Uses SkTextEncoding to decode text, SkTypeface to get the glyph paths,
|
||||
and text size, fake bold, and SkPathEffect to scale and modify the glyph paths.
|
||||
All of the glyph paths are stored in path.
|
||||
Uses pos array to position path.
|
||||
pos contains a position for each glyph.
|
||||
|
||||
@param text character codes or glyph indices
|
||||
@param length number of bytes of text
|
||||
@param pos positions of each glyph
|
||||
@param path geometry of the glyphs
|
||||
/** Deprecated; use SkFont::getPath instead
|
||||
*/
|
||||
void getPosTextPath(const void* text, size_t length,
|
||||
const SkPoint pos[], SkPath* path) const;
|
||||
|
@ -310,11 +310,18 @@ bool IncludeParser::advanceInclude(TextParser& i) {
|
||||
if ('{' == i.peek()) {
|
||||
if (looks_like_method(i)) {
|
||||
fCheck.fState = CheckCode::State::kMethod;
|
||||
if (!i.skipToBalancedEndBracket('{', '}')) {
|
||||
i.reportError("unbalanced open brace");
|
||||
bool inBalance = false;
|
||||
TextParser paren(i.fFileName, i.fStart, i.fEnd, i.fLineCount);
|
||||
paren.skipToEndBracket('(');
|
||||
paren.skipToBalancedEndBracket('(', ')');
|
||||
inBalance = i.fChar < paren.fChar;
|
||||
if (!inBalance) {
|
||||
if (!i.skipToBalancedEndBracket('{', '}')) {
|
||||
i.reportError("unbalanced open brace");
|
||||
}
|
||||
i.skipToLineStart(&fCheck.fIndent, &fCheck.fWriteReturn);
|
||||
return false;
|
||||
}
|
||||
i.skipToLineStart(&fCheck.fIndent, &fCheck.fWriteReturn);
|
||||
return false;
|
||||
} else if (looks_like_class_decl(i)) {
|
||||
fCheck.fState = CheckCode::State::kClassDeclaration;
|
||||
fCheck.fPrivateBrace = fCheck.fBraceCount + 1;
|
||||
@ -434,9 +441,18 @@ string IncludeParser::writeCodeBlock(const Definition& iDef) {
|
||||
i.fEnd = loc;
|
||||
}
|
||||
if (i.contains("{", i.fEnd, &loc)) {
|
||||
i.fEnd = loc + 1;
|
||||
while (i.fEnd < iDef.fContentEnd && ' ' >= i.fEnd[0]) {
|
||||
++i.fEnd;
|
||||
bool inBalance = false;
|
||||
if (MarkType::kMethod == iDef.fMarkType) {
|
||||
TextParser paren(&iDef);
|
||||
paren.skipToEndBracket('(');
|
||||
paren.skipToBalancedEndBracket('(', ')');
|
||||
inBalance = loc < paren.fChar;
|
||||
}
|
||||
if (!inBalance) {
|
||||
i.fEnd = loc + 1;
|
||||
while (i.fEnd < iDef.fContentEnd && ' ' >= i.fEnd[0]) {
|
||||
++i.fEnd;
|
||||
}
|
||||
}
|
||||
}
|
||||
while (i.fEnd > i.fStart && ' ' == i.fEnd[-1]) {
|
||||
|
@ -1197,6 +1197,8 @@ void IncludeWriter::structSizeMembers(const Definition& child) {
|
||||
inMethod = false;
|
||||
} else if (Punctuation::kSemicolon == token.fPunctuation) {
|
||||
inMethod = false;
|
||||
} else if (Punctuation::kAsterisk == token.fPunctuation) {
|
||||
inMethod = false;
|
||||
} else {
|
||||
SkASSERT(0); // incomplete
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user