#include#include #include int main() { SkPaint paint; paint.setTextSize(32); const char* text = "Hello, world!"; SkRect bounds; paint.getTextSize(text, strlen(text), &bounds); std::cout << "Text width: " << bounds.width() << std::endl; std::cout << "Text height: " << bounds.height() << std::endl; return 0; }
#includeThis example creates a new SkSurface object and retrieves its canvas. We then use the SkPaint object to calculate the size of the text and store it in the SkRect object bounds. We then use the canvas to draw the text on it, starting at position (0, -bounds.top()). Finally, we flush the surface and submit it for display. The package library for SkPaint is Skia, which is an open-source 2D graphics library developed by Google. It is available on various platforms, including macOS, Windows, Linux, and Android.#include #include int main() { sk_sp surface = SkSurface::MakeRasterN32Premul(256, 256); SkCanvas* canvas = surface->getCanvas(); SkPaint paint; paint.setTextSize(32); const char* text = "Hello, world!"; SkRect bounds; paint.getTextSize(text, strlen(text), &bounds); canvas->drawText(text, strlen(text), 0, -bounds.top(), paint); surface->flushAndSubmit(); return 0; }