Skip to content

Instantly share code, notes, and snippets.

@drott
Created December 19, 2017 12:08
Show Gist options
  • Save drott/c78215e20bf23648f11a05ff3850a13c to your computer and use it in GitHub Desktop.
Save drott/c78215e20bf23648f11a05ff3850a13c to your computer and use it in GitHub Desktop.
// ../blink/src/third_party/llvm-build/Release+Asserts/bin/clang -std=c++11 -stdlib=libc++ -I../blink/src/skia/config -I../blink/src/third_party/skia/include -I../blink/src/third_party/skia/include/core -I../blink/src/third_party/skia/include/config -I../blink/src/third_party/skia/include/gpu -lstdc++ -L../blink/src/out/gndebug -lskia -Wl,-rpath,../blink/src/out/gndebug/ main.cpp -g -O1 -o noto_harfbuzz
#include "SkTypeface.h"
#include "SkString.h"
#include "SkSurface.h"
#include "SkCanvas.h"
#include "SkPaint.h"
#include "SkStream.h"
int main() {
SkImageInfo image_info = SkImageInfo::Make(100, 100, SkColorType::kRGB_565_SkColorType, SkAlphaType::kOpaque_SkAlphaType);
sk_sp<SkSurface> surface( SkSurface::MakeRaster(image_info));
// sk_sp<SkSurface> surface(SkSurface::MakeRasterN32Premul(800,450));
if (!surface)
return 1;
SkCanvas* canvas = surface->getCanvas();
canvas->clear(SK_ColorWHITE);
SkPaint paint;
sk_sp<SkTypeface> typeface(SkTypeface::MakeFromFile("NotoSansDevanagari-Regular-uni091D.ttf"));
paint.setTypeface(typeface);
paint.setTextSize(16);
paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
paint.setAntiAlias(true);
paint.setSubpixelText(true);
paint.setLCDRenderText(true);
paint.setHinting(SkPaint::kFull_Hinting);
uint32_t testtext[] = { 1, 2 };
canvas->drawText(testtext, sizeof(testtext), 20.333f, 20, paint);
{
sk_sp<SkImage> image(surface->makeImageSnapshot());
sk_sp<SkData> png(image->encodeToData(SkEncodedImageFormat::kPNG, 100));
SkFILEWStream{"noto_uni091d.png"}.write(png->data(), png->size());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment