Font conversion to base64

255 views
Skip to first unread message

christian millen gimeno

unread,
May 24, 2021, 2:10:21 AM5/24/21
to DroidScript
Is there a way to convert a font into base64 using droidscript?

Steve Garman

unread,
May 24, 2021, 2:17:40 AM5/24/21
to DroidScript
I'm sorry, I have absolutely no idea what that question means

Could you please give an explanation of what you are trying to achieve

christian millen gimeno

unread,
May 24, 2021, 2:28:15 AM5/24/21
to DroidScript
Oh, what I mean is that how do i convert a downloaded font into base64 so that I can use it inside of my @font-face rule on styles.

You can refer to this code sample below:

<style id="myStyle">
     @font-face {
            font-family: Oxygen; 
            src: url('data:application/octet-stream;base64, <"the base64 font format goes here">);
</style>

Steve Garman

unread,
May 25, 2021, 4:34:14 AM5/25/21
to DroidScript
It looks like you want
  app.ReadFile(path, "base64")
( not tested in css)

// test code
var b64 //global variable
function OnStart()
{
   var path = "Misc/myfont.ttf"
   b64 = app.ReadFile(path, "base64")

   yn = app.CreateYesNoDialog(b64)
   yn.SetButtonText("Copy to clipboard", "Cancel")
   yn.SetOnTouch(yn_OnTouch)
   yn.Show()
}

function yn_OnTouch(ans)
{
   if(ans == "Yes")
   {
      var s = '"' + b64 + '"'
      app.SetClipboardText(s)
   }
   app.Exit()

christian millen gimeno

unread,
May 25, 2021, 4:59:12 AM5/25/21
to DroidScript
I think this is what Im looking for. I'll try it out, thank you Steve.

ECEisLife

unread,
Jun 7, 2021, 8:27:01 PM6/7/21
to DroidScript
If you want, you can also use your font (.ttf or .woff) directly without converting it to base64. As long as it 

<style id="myStyle">
     @font-face {
            font-family: Oxygen; 
            src: url(myFont.ttf);
</style>

Regards
Jumar


Reply all
Reply to author
Forward
0 new messages