MicroTeX icon indicating copy to clipboard operation
MicroTeX copied to clipboard

Using Skia and Render in Android device,crash in the CharBox Draw() funtion

Open tantianjack opened this issue 1 year ago • 3 comments

我在使用Skia与microTex库,在安卓平台渲染公式的时候,会crash在Box->draw()里面。具体看下来,好像是字体加载没有成功。 导致了CharBox中使用了_drawWithFont(),字体为Null。具体流程如下:

我编译了skia安卓版本,然后把microTex也编译了一个安卓版本。在使用的过程中,我初始化了对应的字体与环境。

microtex::FontSrcFile math{"/sdcard/temp/XITSMath-Regular.clm1", "/sdcard/temp/XITSMath-Regular.otf" }; microtex::MicroTeX::init(math); microtex::PlatformFactory::registerFactory("skia", std::make_unique<PlatformFactory_skia>()); microtex::PlatformFactory::activate("skia");

之后,为了排查问题,我简单的设置了要解析的公式为一个字母。 auto render = microtex::MicroTeX::parse(std::string("x"), 600 - 0 * 2, 20, 20 / 3.f, 0xff424242);

然后新建了skia的canvas和一个bitmap,期望render可以渲染到bitmap上。 SkBitmap bitmap; bitmap.allocPixels(SkImageInfo::Make(render->getWidth(), render->getHeight(), kN32_SkColorType, kPremul_SkAlphaType));

SkCanvas canvas(bitmap);

Graphics2D_skia drawer(&canvas); render->draw(drawer,10,10);

但是最终 crash在了render->draw中。由于安卓平台没法调试和查看log,只能大概确认是CharBox这个类使用的_drawWithFont函数里面,factory->createFont生成的字体存在问题。

我想知道,是我初始化选择的字体有问题导致了Crash的发生,还是我的库使用的方式有问题?这真的让人感到困惑,可以有人为我解答一下吗?

tantianjack avatar Sep 13 '23 07:09 tantianjack