Options
These globals are now defined:
double duration; // The requested duration of the animation. double frame; // A value in [0, 1] of where we are in the animation.
This global is now defined:
GrBackendRenderTarget backEndRenderTarget;
GrBackendTexture backEndTextureRenderTarget;
Optional source image
These globals are now defined:
SkBitmap source; sk_sp<SkImage> image; GrBackendTexture backEndTexture; // GPU Only.
Note:
Adding comments with SK_FOLD_START and SK_FOLD_END creates foldable code
blocks.
These blocks will be folded by default and are useful for highlighting specific lines of code.
You can also use the keyboard shortcuts Ctrl+S and Ctrl+E in the code editor to set them.
These blocks will be folded by default and are useful for highlighting specific lines of code.
You can also use the keyboard shortcuts Ctrl+S and Ctrl+E in the code editor to set them.
xxxxxxxxxx
51
using namespace skia::textlayout;
static std::string printable(const std::string &text) {
std::string result;
for (char c : text) {
if (c == '\n') {
result += "\\n";
} else {
result += c;
}
}
return result;
}
static void print_text_boxes(const std::string &text) {
SkDebugf("### `\"%s\"`\n", printable(text).c_str());
auto fonts = sk_make_sp<FontCollection>();
fonts->setDefaultFontManager(SkFontMgr::RefDefault());
auto builder = ParagraphBuilder::make(ParagraphStyle(), fonts);
builder->addText(text.c_str());
auto paragraph = builder->Build();
paragraph->layout(256);
auto boxes = paragraph->getRectsForRange(0, text.size(), RectHeightStyle::kMax, RectWidthStyle::kMax);
SkDebugf("- boxes (%lu):\n", boxes.size());
for (auto box : boxes) {
SkDebugf(" - l=%f, t=%f, r=%f, b=%f\n", box.rect.fLeft, box.rect.fTop, box.rect.fRight, box.rect.fBottom);
}
std::vector<LineMetrics> lines = {};
paragraph->getLineMetrics(lines);
SkDebugf("- lines (%lu):\n", lines.size());
for (auto l : lines) {
SkDebugf(" - %d: `\"%s\"` (%d..%d): l=%f, t=%f, r=%f, b=%f\n",
l.fLineNumber,
printable(text.substr(l.fStartIndex, l.fEndIndex - l.fStartIndex)).c_str(),
l.fStartIndex, l.fEndIndex,
l.fLeft, l.fBaseline - l.fAscent, l.fLeft + l.fWidth, l.fBaseline + l.fDescent);
}
}
void draw(SkCanvas* canvas) {
print_text_boxes("Hello");
print_text_boxes("Hello\n");
print_text_boxes("Hello\n\n");
print_text_boxes("Hello\nworld\n");
print_text_boxes("Hello\n \n");
}
Compilation Warnings/Errors
Runtime Errors
Output
### `"Hello"` - boxes (1): - l=0.000000, t=-0.300000, r=35.490002, b=16.000000 - lines (1): - 0: `"Hello"` (0..5): l=0.000000, t=-0.296875, r=35.490002, b=16.000000 ### `"Hello\n"` - boxes (1): - l=0.000000, t=-0.300000, r=35.490002, b=16.000000 - lines (2): - 0: `"Hello\n"` (0..6): l=0.000000, t=-0.296875, r=35.490002, b=16.000000 - 1: `"\n"` (5..6): l=0.000000, t=15.703125, r=0.000000, b=32.000000 ### `"Hello\n\n"` - boxes (3): - l=0.000000, t=-0.300000, r=35.490002, b=16.000000 - l=0.000000, t=15.700000, r=0.000000, b=32.000000 - l=0.000000, t=15.700000, r=35.490002, b=32.000000 - lines (3): - 0: `"Hello"` (0..5): l=0.000000, t=-0.296875, r=35.490002, b=16.000000 - 1: `"\n"` (6..7): l=0.000000, t=15.703125, r=0.000000, b=32.000000 - 2: `"\n"` (6..7): l=0.000000, t=31.703125, r=0.000000, b=48.000000 ### `"Hello\nworld\n"` - boxes (3): - l=0.000000, t=-0.300000, r=35.490002, b=16.000000 - l=35.490002, t=-0.300000, r=38.549999, b=16.000000 - l=0.000000, t=15.700000, r=38.549999, b=32.000000 - lines (3): - 0: `"Hello"` (0..5): l=0.000000, t=-0.296875, r=35.490002, b=16.000000 - 1: `"world\n"` (6..12): l=0.000000, t=15.703125, r=38.549999, b=32.000000 - 2: `"\n"` (11..12): l=0.000000, t=31.703125, r=0.000000, b=48.000000 ### `"Hello\n \n"` - boxes (3): - l=0.000000, t=-0.300000, r=35.490002, b=16.000000 - l=0.000000, t=15.700000, r=4.450000, b=32.000000 - l=4.450000, t=15.700000, r=35.490002, b=32.000000 - lines (3): - 0: `"Hello"` (0..5): l=0.000000, t=-0.296875, r=35.490002, b=16.000000 - 1: `" \n"` (6..8): l=0.000000, t=15.703125, r=0.000000, b=32.000000 - 2: `"\n"` (7..8): l=0.000000, t=31.703125, r=0.000000, b=48.000000