[FREE] 🔥 GFont Extension: Google Fonts for AI2 apps

Untitled design (14) (1)

GFont: Apply Google Fonts to components dynamically

Introduction

Hello Everyone! Today I am presenting my GFont extension. The extension enables you to apply google fonts directly to components without adding them in the app assets while coding

Blocks

Events:

GotFonts

Triggered when fonts are fetched

FontDownloadSuccess

Triggered when font download is successful

FontDownloadFail

Triggered when font download fails

GotFontUrl

Triggered when the font URL is retrieved

FontAppliedSuccessfully

Triggered when the font is successfully applied to the component.

FontApplyFailed

Triggered when there is an error applying the font.

Methods:

QueryFonts

Fetches fonts based on given parameters

DownloadFont

Downloads a font from the given URL and saves it automatically

ExtractJSONValue

Extract a specific value from the JSON response

GetFontUrl

Fetches the font URL for a specific weight

ApplyFont

Applies the font from the specified file path to the given component.

Example Block arrangement

Support the Development

I'm a 16 year old high school student, I like to create and maintain many extensions. I research a lot daily to bring something new to App Inventor :smiley:
While my primary goal and perspective on App Inventor is not to earn money, it really helps and motivates me a lot if you could spare some donations. :hugs:
It takes a lot of effort :technologist:to build one such extension. If you :sparkling_heart: it for being Free
Please support the development by making a contribution here. It will make my day!

Download the Extension

Latest version

:page_facing_up:io.gfont.aix v1.1(108.2 KB) - Added Font Selector Menu

Past Releases

:page_facing_up:io.gfont.aix v1 (104.9 KB) - Initial Release of the extension

Rate the extension

  • :star::star::star::star::star:
  • :star::star::star::star:
  • :star::star::star:
  • :star::star:
  • :star:
0 voters

Reply with any doubt and I will be happy to answer
Regards
Sarthak Gupta (@techxsarthak)

1 Like

Thanks @timai2 for the idea. Hope the extension stands as per your expectations.
Please share your opinion on it after testing it.

Basics not working for me in companion app? Believe to be the DownloadFont method.

image

Suggestions

  1. Return a simple fontList of each font name (family), not the whole json ?
  2. Generate an html to view fonts in webviewer prior to download?
  3. provide guidance for block elements (e.g. in GetfontUrl: subset? category? fontweight? - sometimes this is regular and not 400

Yes the download font method works only when you build the apk

Yes, I thought about that but I think it will limit the possibilities of the extension. I have already incorporated JsonExtract block from my GroqText extension that extracts value using field path.

family: Name of a font family.

subset: Name of a font subset.

category: serif | sans-serif | monospace | display | handwriting

capability: VF | WOFF2.

sort: alpha | date | popularity | style | trending.

Noted for next update

Regards
Sarthak Gupta

Works fine if I use the web component instead in companion.

for example ?

not included in blocks ? but appears to present ttf as opposed to woff2

It is a good start, but leaves much to be desired for a user coming to it without any prior knowledge of Google Fonts.

A font viewer is probably an essential, otherwise users would need to go out to "Google Fonts" to see what a font looks like, before returning to app to fetch it.

Some guidance / lniks on how to get the api key would also help

Add more detailed descriptions for your methods

Yes, I mentioned that the method currently supports only fully built app. Will add companion support in the next update.

I thought ttf would work better as compared to woff2

1 Like
  {
    "family": "Antic",
    "variants": [
      "regular"
    ],
    "subsets": [
      "latin"
    ],
    "version": "v19",
    "lastModified": "2022-09-22",

Latin as here

Will write a better guide with instructions for users to learn more about Google Fonts, including those who haven't used it

Actually I thought that most of the users of the extension would be well versed with Google Fonts site and fonts which they want to add, this is interesting, will definitely work for it

I am preparing an in depth tutorial for the same :smiley:

Sure

BRUH!!! I spent like 4 hours making smth like this with no extensions and like a week later you make an extension! This would have helped so much... bruhhh, anyways cool extension

1 Like

The html file might look something like this:

<!DOCTYPE html>
<html>
<head>
<link href='https://fonts.googleapis.com/css?family=Sofia' rel='stylesheet'>
<link href='https://fonts.googleapis.com/css?family=Comfortaa' rel='stylesheet'>
<link href='https://fonts.googleapis.com/css?family=Roboto' rel='stylesheet'>
<style>
body {
font-size: 22px;
}
</style>
</head>
<body>

<div id="font"></div>
<h1 style="font-family: 'Sofia';" onClick="selectFont(innerText)">Sofia</h1>
<h1 style="font-family: 'Comfortaa';" onClick="selectFont(innerText)">Comfortaa</h1>
<h1 style="font-family: 'Roboto';" onClick="selectFont(innerText)">Roboto</h1>

<script>

function selectFont(value) {
if (window.AppInventor) {
  window.AppInventor.setWebViewString(value);
}
else {
document.getElementById("font").innerHTML = value;
}
}
</script>

</body>
</html>

image

Might take a while for 1800 fonts to load up !!

The webviewstring changed event can be used to return the selected font to the app.

1 Like

:loudspeaker:Release Notes: Version 1.1

What's new

  1. Added Font Selector page, as suggested by @TIMAI2
  2. Fixed some minor bugs to improve performance

Preview

:new: New Block

LoadFontsMenuBlock

WebViewer :spider_web:: The webviewer in which you want to display the Font Selector Menu
ApiKey :key:: Google Fonts API Key

:page_facing_up: Example Blocks

Make sure to ask for storage access permission or turn it on from the settings for the extension to work optimally

Download Link is updated at the top

Thanks for your suggestion @TIMAI2

Yes, So I added logic to load all the fonts json from the api first then load them 50 at a time.

Yes, that's a great idea
I also added Sort and search options to find your favourite font!

Regards
Sarthak Gupta

Dear @S4IL,
this new extension (great job :+1:) allows you to use google fonts without pre-loading them in the asset, but there was already another one that you can find here:

which allowed you to use "custom" fonts, for example .ttf uploaded as resource in the app's asset dir.

image

Best wishes.

Thanks for the appreciation

To explain this more specifically

MyFont allows you to set fonts from file locations, this means you have to store all the fonts that you are using in the storage.

GFont allows you to select from a world of fonts from Google Font's database and allows you to apply them directly. Thus eliminating the need of storing the fonts in the assets.

Regards
Sarthak Gupta

Not quite, if you use version 2 of MyFonts extension, you can set the font from most file locations

This is where the idea came from, if you read from here (post 27 - 54)

1 Like

Yes, that was what i used, and made my own API to get the ttf file of a font and my website that is the font picked, with costumwebview, and all this complicated process that took 4 hours was for nothing since this was made!
Here is an example call to the API: https://s4api.vercel.app/font_url?font_name=Roboto

My fault, I wanted to say that myfont allows you to set font from most of the file locations while gfont extension fetches fonts from api and applies it at once. Thus eliminating the need to supply the font ttf file.

Yes :grin: GFont automates all of this process

Dear @techxsarthak, your explanation was already pretty clear at the first post :grin:
My comments were just related to @S4IL grumble :rofl: :rofl: :rofl:
Both of you are too clever for an "old" software developer who started more than 40 yeras ago to code, in machine language, embedded software for military aircraft....
Let me anyway tell you one hint: although you spend some hours in making an app working, that time is not wasted but invested. When the going gets tough, the toughs get going ! :muscle:

1 Like