Is it possible to draw noto color emoji on a image on ubuntu?

144 views
Skip to first unread message

hl209...@gmail.com

unread,
Nov 10, 2017, 4:11:30 AM11/10/17
to skia-discuss
Here is the code:

#include "SkBitmap.h"
#include "SkPaint.h"
#include "SkRect.h"
#include "SkImageEncoder.h"
#include "SkImageInfo.h"
#include "SkImage.h"
#include "SkCanvas.h"
#include "SkEncodedImageFormat.h"
#include "SkTypeface.h"

int main() {

SkBitmap bitmap;
SkImageInfo info = SkImageInfo::Make(1000, 1000, kN32_SkColorType,
kPremul_SkAlphaType);
bitmap.setInfo(info);
bitmap.allocPixels();
SkCanvas canvas(bitmap);
SkPaint paint;

// SkIRect holds four 32 bit integer coordinates for a rectangle.
SkRect r;

paint.setTextSize(64.0f);
//paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
paint.setTypeface(SkTypeface::MakeFromFile("/home/lei/Downloads/NotoColorEmoji.ttf"));
//paint.setTypeface(SkTypeface::MakeFromName("Noto Color Emoji",SkFontStyle::Normal()));
paint.setEmbeddedBitmapText(true);
//paint.setFlags(SkPaint::kEmbeddedBitmapText_Flag);
const char text[] = "Skia😌😀😬😁😂😃";

canvas.drawText(text, strlen(text), 20.0f, 64.0f, paint);
sk_sp<SkImage> image = SkImage::MakeFromBitmap(bitmap);
sk_sp<SkData> skdata = image.get()->encodeToData(SkEncodedImageFormat::kPNG,
100);
size_t size = skdata.get()->size();
SkFILEWStream skFILEWStream("/home/lei/test.png");
skFILEWStream.write(skdata.get()->data(), size);
skFILEWStream.flush();

// SkImageEncoder is the base class for encoding compressed images
// from a specific SkBitmap.
// SkImageEncoder::EncodeFile("snapshot.png", bitmap, SkImageEncoder::kPNG_Type,/* Quality ranges from 0..100 */ 100);
return 0;
}

I want to draw color emojis on a image with NotoColorEmoji font , but when I run this script I got the "test.png" is blank. What should I do? It is possible to render color emoji on ubuntu 16.04?

Ben Wagner

unread,
Nov 10, 2017, 10:18:10 AM11/10/17
to skia-d...@googlegroups.com
I made this work locally, but note that even when working the 'Skia' part won't show up because NotoColorEmoji doesn't contain any Latin script character mappings. Note that it's easy to build Skia so this doesn't work. To make this work locally I built a out/so/libskia.so and the emoji_test.cpp with

gn args out/so --args="is_component_build=true is_debug=true"
ninja -C out/so skia
c++ emoji_test.cpp -g -o emoji_text -Iinclude/core -Iinclude/config -Lout/so/ -lskia -Wl,-rpath out/so -DSK_SAMPLES_FOR_X

Note in particular the SK_SAMPLES_FOR_X which is set by the Skia build in BUILD.gn on Linux, and will affect the value of kN32_SkColorType. Without this being set I got

../../src/core/SkBitmapDevice.cpp:83: fatal error: "assert(valid_for_bitmap_device(bitmap.info(), nullptr))"

because this was a debug build, but in a release build it would just keep going and give you the empty image you ended up seeing (I think).

--
You received this message because you are subscribed to the Google Groups "skia-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to skia-discuss+unsubscribe@googlegroups.com.
To post to this group, send email to skia-d...@googlegroups.com.
Visit this group at https://groups.google.com/group/skia-discuss.
For more options, visit https://groups.google.com/d/optout.

hl209...@gmail.com

unread,
Nov 10, 2017, 10:46:55 PM11/10/17
to skia-discuss
Yes you are right. Only shared lib work with noto color emoji on ubuntu. Thanks a lot.
To unsubscribe from this group and stop receiving emails from it, send an email to skia-discuss...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages