The image is not rendering.
This is my test code.
=========================================================================================================
#include <string.h>
#include <jni.h>
#include <vector>
#include <string>
#ifdef ANDROID
#include <android/log.h>
#include <unistd.h>
#define LOG_TAG "SKIA-TEST"
#define SKIA_FUNC_START() {usleep(500);__android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, "+%s(%d)", __PRETTY_FUNCTION__, __LINE__);}
#define SKIA_FUNC_END() {usleep(500);__android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, "-%s(%d)", __PRETTY_FUNCTION__, __LINE__);}
#define SKIA_LINE() __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, " --%6ld, %s", __LINE__, __PRETTY_FUNCTION__)
#define SKIA_LOGD(...) __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__)
#define SKIA_LOGI(...) __android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__)
#define SKIA_LOGW(...) __android_log_print(ANDROID_LOG_WARN, LOG_TAG, __VA_ARGS__)
#define SKIA_LOGE(...) __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__)
#endif
#include "SkCanvas.h"
#include "SkImageDecoder.h"
#include <ft2build.h>
#include FT_FREETYPE_H
#include <freetype/tttables.h>
#include <freetype/fttypes.h>
#include <freetype/ftglyph.h>
#include <freetype/ttnameid.h>
#include <freetype/ftsnames.h>
#include <freetype/fterrors.h>
#include <freetype/ftglyph.h>
#include <freetype/ftxf86.h>
#include <freetype/fterrors.h>
#define INDEX 0
#ifndef __CPLUSPLUS
extern "C" {
#endif
JNIEXPORT void JNICALL
Java_com_example_runskia_SkiaView_print(JNIEnv *, jobject);
#ifndef __CPLUSPLUS
}
#endif
void EncdoeBitmap(SkBitmap& bitmap, int32_t glyphIndex) {
SKIA_LOGE("EncdoeBitmap 1");
SkImageEncoder::Type type = SkImageEncoder::kPNG_Type;
char buf[256] = {0,};
sprintf(buf, "%d", glyphIndex);
std::string path;
path.assign("/mnt/sdcard/emoji/");
path.append("FruityGirl");
path.append(buf);
path.append(".png");
SKIA_LOGE("path = %s", path.c_str());
bool flag = SkImageEncoder::EncodeFile(path.c_str(), bitmap, type, 80);
if(!flag) {
SKIA_LOGE("EncdoeBitmap false");
return ;
}
}
void FontRender(std::vector<int32_t>& glyphIndexs) {
SKIA_LOGE("FontRender 1");
SkBitmap* bitmap = new SkBitmap();
bitmap->setConfig(SkBitmap::kARGB_8888_Config,100, 100);
if(bitmap->allocPixels() == true) {
memset(bitmap->getPixels(), 0x00, 100 * 100 * 4);
} else {
SKIA_LOGE("Bitmap Failed the allowcate");
delete bitmap;
return ;
}
SkCanvas* canvas = new SkCanvas(*bitmap);
SkPaint paint;
// paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
canvas->drawLine(0.F, 0.F, 100.F, 100.F, paint);
paint.setColor(0xFF00FF00);
paint.setTextSize(45.F);
SKIA_LOGE("FontRender 2");
for (int32_t i = 0; i < glyphIndexs.size(); ++i) {
canvas->drawText(&glyphIndexs[i], 1, 20, 50, paint);
EncdoeBitmap(*bitmap, glyphIndexs[i]);
memset(bitmap->getPixels(), 0x00, 100 * 100 * 4);
}
SKIA_LOGE("FontRender 3");
}
void Java_com_example_runskia_SkiaView_print(JNIEnv *env, jobject thiz) {
SKIA_LOGE("Java_com_example_runskia_SkiaView_print");
FT_Library library;
FT_Face face;
FT_Init_FreeType(&library);
if (FT_Init_FreeType(&library)) {
SKIA_LOGE("error 1");
return ;
}
std::string fontPath("/mnt/sdcard/FruityGirl.ttf");
if (FT_New_Face(library, fontPath.c_str(), 0, &face)) {
return ;
}
SKIA_LOGE("Java_com_example_runskia_SkiaView_print 1");
// 0 is success.
FT_Error error;
std::vector<int32_t> glyphIndexs;
for (int32_t i = 0; i < 100000000; ++i) {
error = FT_Load_Glyph(face, i, FT_LOAD_DEFAULT );
if (!error) {
glyphIndexs.push_back(i);
}
}
SKIA_LOGE("Java_com_example_runskia_SkiaView_print 2");
FT_Done_Face(face);
FT_Done_FreeType(library);
FontRender(glyphIndexs);
}
=========================================================================================================