Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Using default iOS system fonts with new font commands?

Author
Message
xCept
21
Years of Service
User Offline
Joined: 15th Dec 2002
Location:
Posted: 5th Jul 2018 10:03 Edited at: 5th Jul 2018 16:33
I've been unable to figure out how (or if it is even possible) to use iOS system fonts through LoadFont / text objects in AGK.

If the device has a language such as Simplified Chinese, the default text objects in AppGameKit will only render "tofu" squares because the default font doesn't contain the needed symbols. I would like to tell AppGameKit to use the default system font in such instances, which has all of the glyphs needed to render Simplified Chinese (or whichever language the user has set in Settings).

Without this ability to properly support Chinese would require including a 11 to 115 MB font file and similar for other complex languages. In other game engines it seems the system font is used by default to ensure all characters can be rendered with low overhead in the app.

The help indicates:

Quote: "The szFontFile parameter can either be a font file located in your media folder or the name of a system font, this command will check your media folder first before checking for system fonts."


It does not state that the "system font" feature is only for desktop, yet I don't know how to access the actual system font in iOS (or Android for that matter).

Edit - For instance on iOS 9.0+ we should be able to use "PingFang SC" for simplified Chinese, or any of the fonts shown when creating a label in Xcode Interface Builder, but I see no way to achieve this in AGK.
Paul Johnston
TGC Developer
21
Years of Service
User Offline
Joined: 16th Nov 2002
Location: United Kingdom
Posted: 10th Jul 2018 16:27
Unfortunately iOS does not give us access to the system TTF files
xCept
21
Years of Service
User Offline
Joined: 15th Dec 2002
Location:
Posted: 10th Jul 2018 20:04 Edited at: 10th Jul 2018 20:05
I wonder how the other engines are accomplishing this. In Objective C you can call [UIFont systemFontOfSize:12] or [UIFont fontWithName: @"Helvetica" size:12] etc. It seems they are using UILabels and setting them to the desired system font then rendering them to sprites.

Cocos2d-X has this command:

Quote: "Label* Label::createWithSystemFont(const std::string& text, const std::string& font, float fontSize, const Size& dimensions /* = Size::ZERO */, TextHAlignment hAlignment /* = TextHAlignment::LEFT */, TextVAlignment vAlignment /* = TextVAlignment::TOP */)
{
auto ret = new (std::nothrow) Label(hAlignment,vAlignment);

if (ret)
{
ret->setSystemFontName(font);
ret->setSystemFontSize(fontSize);
ret->setDimensions(dimensions.width, dimensions.height);
ret->setString(text);

ret->autorelease();

return ret;
}

return nullptr;
}"


Which calls some others (source code here).

Both that and Unity actually automatically substitute custom fonts with system fonts including on iOS when the glyphs are not present, which is desirable to easily support foreign characters.

Quote: "If none of the listed fallback fonts are present and have the requested glyph, Unity will fall back to a hard-coded global list of fallback fonts, which contains various international fonts commonly installed on the current runtime platform."
Paul Johnston
TGC Developer
21
Years of Service
User Offline
Joined: 16th Nov 2002
Location: United Kingdom
Posted: 11th Jul 2018 02:06
AGK uses a TTF library to load fonts from TTF files and render them to OpenGL textures, this ensures apps look identical across all platforms. I'm not sure how we'd interface a UIFont into this process, it could be a lot of work for a specific use case, it would be so much easier if Apple just let us have access to the TTF files. If you can find some Objective-C code that converts a UIFont to TTF data then I'll take a look.
xCept
21
Years of Service
User Offline
Joined: 15th Dec 2002
Location:
Posted: 11th Jul 2018 22:36
I agree it is a lot of hassle. For now I managed to find a small enough Simplified Chinese font type that is only 2.2 MB compressed and 4 MB uncompressed that works for my use case. Thanks for explaining further anyway.

Login to post a reply

Server time is: 2024-04-25 01:59:57
Your offset time is: 2024-04-25 01:59:57