ultralight-ux / AppCore

Cross-platform app runtime module for Ultralight
https://ultralig.ht
GNU Lesser General Public License v2.1
82 stars 24 forks source link

Wrong description of Ref<App> Create() #2

Open IanByun opened 5 years ago

IanByun commented 5 years ago

Ref Create() comments say that one should "set your Config before creating App". https://github.com/ultralight-ux/AppCore/blob/0dfc7936e4ecdce4655b52dfb682ec40c080eb63/include/AppCore/App.h#L51

However, as AppWin::AppWin() constructor overrides with Platform::instance().set_config, it has no effect. https://github.com/ultralight-ux/AppCore/blob/0dfc7936e4ecdce4655b52dfb682ec40c080eb63/src/win/AppWin.cpp#L23

For example, if I load https://google.co.kr like below,

auto& platform = ultralight::Platform::instance();

Config config;
config.font_family_standard = "Malgun Gothic";
config.font_family_fixed = "Malgun Gothic";
config.font_family_serif = "Malgun Gothic";
config.font_family_sans_serif = "Malgun Gothic";
config.user_agent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36";

platform.set_config(config);

app_ = App::Create();

The result is like this: image

The CORRECT way to setup config is,

app_ = App::Create();

auto& platform = ultralight::Platform::instance();

Config config;
config.font_family_standard = "Malgun Gothic";
config.font_family_fixed = "Malgun Gothic";
config.font_family_serif = "Malgun Gothic";
config.font_family_sans_serif = "Malgun Gothic";
config.user_agent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36";

platform.set_config(config);

app_->renderer() = Renderer::Create(); //this overides default config with 'my' config

which leads to Chrome-like correctly rendered scene. image

MatrixHan commented 5 years ago

Do you support Chinese?

IanByun commented 5 years ago

Do you support Chinese?

Change font family to whatever chinese font. SimSun or Microsoft YaHei would do.

config.font_family_standard = "Malgun Gothic";
config.font_family_fixed = "Malgun Gothic";
config.font_family_serif = "Malgun Gothic";
config.font_family_sans_serif = "Malgun Gothic";
MatrixHan commented 5 years ago

QQ图片20190817170325 my try all chinese font,but can't normal render ` ultralight::Platform& platform = ultralight::Platform::instance(); platform.set_gpu_driver(DefaultGPUDriver()); Config conf = Config(); conf.font_family_standard = conf.font_family_fixed = conf.font_family_fixed = conf.font_family_sans_serif = "SimSun"; conf.user_agent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36"; platform.set_config(conf);

platform.set_font_loader(DefaultFontLoader());  `
IanByun commented 5 years ago

@MatrixHan I think the problem is not about the font itself, but how Ultralight renders it using PC chrome user agent.

Try using mobile user agent which is,

Mozilla/5.0 (Linux; Android 8.1.0; SM-G965F Build/OPM2.171019.029) AppleWebKit/537.36 (KHTML, like Gecko) SamsungBrowser/7.2 Chrome/59.0.3071.125 Mobile Safari/537.36

image

MatrixHan commented 5 years ago

微信图片_20190820095512 my try it,but don't normal my use bitmap bytes render , Is this not working properly? `renderer->Render(); int width = view->bitmap()->width(); int height = view_->bitmap()->height(); int formatbyte = 0; char * bytes = nullptr; if (view->bitmap()->format() == BitmapFormat::kBitmapFormat_RGBA8) { formatbyte = 4; } else if (view->bitmap()->format() == BitmapFormat::kBitmapFormat_A8) { format_byte = 1; } int nBytes = formatbyte widthheight; bytes = new char[nBytes]; memset(bytes, 0, nBytes); view->bitmap()->LockPixels(); memcpy(bytes, view_->bitmap()->rawpixels(), nBytes); view->bitmap()->UnlockPixels(); ITexture* pTex = gEnv->pRenderer->EF_LoadTexture(scence_texture, FT_DONT_STREAM | FT_NOMIPS);

IRenderAuxImage::Draw2dImage(0.0f, 0.0f, (float)width, (float)height, pTex->GetTextureID(), 0.0f, 1.0f, 1.0f, 0.0f);

int textureID = gEnv->pRenderer->UploadToVideoMemory(nullptr, width, height, eTF_R8G8B8A8, eTF_R8G8B8A8, 0, true, FILTER_BILINEAR, 0, pTex->GetName(), FT_NOMIPS);
gEnv->pRenderer->UpdateTextureInVideoMemory(pTex->GetTextureID(), (uchar*)bytes, 0, 0, width, height, eTF_R8G8B8A8);
SAFE_DELETE_ARRAY(bytes);`
IanByun commented 5 years ago

The screen is rendered OK on your case, and only fonts are causing errors. I am not the developer of this repo, so I cannot consult in detail. My biggest speculation is that, there is something wrong with loading fonts. As you can see, Korean fonts do not correctly render some of the simplified Chinese, but at least it does correctly some letters for example 一下. On the otherhand, you say you correctly loaded the font, but all the letters are blurred. Font names and font family names are different. In my case the font name is "맑은 고딕", while the family name is "Malgun Gothic". Please double check.