Use custom font in activeX htmlfile Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Mipha
Posts: 77
Joined: 27 Jul 2018, 17:08

Use custom font in activeX htmlfile

10 Nov 2018, 19:25

Assuming I got a font file on the same location as where the script is placed (.tff or .woff) How can I include it in this part of html code? I have tried @font-face but I just can't seem to get it to work.

Code: Select all

gui, add, edit, h0 w0 ;removes annoying noise when pressing a button with the gui selected
gui, font, s10
gui +Border +lastfound
gui, color, EBAE02
WinSet, TransColor, EBAE02

guicontrolget, maindoc, pos
Guiheight := A_screenheight / 4
Guiwidth := A_screenwidth / 6
Gui, Add, ActiveX, x0 y0 w%Guiwidth% h%Guiheight% vfeaturedoc, HtmlFile
htmlpart1 := "<!DOCTYPE html><html><head><style type=text/css> html {overflow:hidden; height: 100%;} body {background:#666666; height: 100%; width: 100%; font-size:60px;}"
;htmlpart1 .= "@font-face {font-family:Test; src:url('myfont.woff'); format:('woff');}"
;htmlpart1 .= "@font-face {font-family:Test; src:url('Pictures\myfont.woff'); format:('woff');}"
htmlpart1 .= ".p{font-family:Test;}"
htmlpart2 := "</style></head><body>"
htmlpart2 .= "<P>Font Test</p>"
htmlpart2 .= "</body></html>"

html := htmlpart1 . htmlpart2

featuredoc.open()
featuredoc.write(html)
featuredoc.close()

gui, show
return
User avatar
kczx3
Posts: 1640
Joined: 06 Oct 2015, 21:39

Re: Use custom font in activeX htmlfile

10 Nov 2018, 21:13

The url needs to be absolute
Mipha
Posts: 77
Joined: 27 Jul 2018, 17:08

Re: Use custom font in activeX htmlfile

11 Nov 2018, 07:30

kczx3 wrote:
10 Nov 2018, 21:13
The url needs to be absolute
Do you mean something like this? C:\Users\(name)\OneDrive\Desktop\File\myfont.woff ? Because I have tried something like that and it didn't seem to work.
User avatar
kczx3
Posts: 1640
Joined: 06 Oct 2015, 21:39

Re: Use custom font in activeX htmlfile

11 Nov 2018, 12:25

Yes that’s what I meant. Not sure what else to try. Haven’t ever done that before
User avatar
Drugwash
Posts: 850
Joined: 29 May 2014, 21:07
Location: Ploieşti, Romania
Contact:

Re: Use custom font in activeX htmlfile

13 Nov 2018, 03:47

According to W3schools, the @font-face rule has been implemented starting with IE9, and it has to be installable for TTF/OTF. An EOT font can be used starting with IE6.
I only have IE8 in XP so can't test script alterations using WOFF fonts; I tried with an EOT but no dice.
However, I do not see the format property among examples. Also, font URL does not use single quotes on that page.
Dunno what else to suggest, sorry.
Part of my AHK work can be found here.
Mipha
Posts: 77
Joined: 27 Jul 2018, 17:08

Re: Use custom font in activeX htmlfile

13 Nov 2018, 04:05

Drugwash wrote:
13 Nov 2018, 03:47
According to W3schools, the @font-face rule has been implemented starting with IE9, and it has to be installable for TTF/OTF. An EOT font can be used starting with IE6.
I only have IE8 in XP so can't test script alterations using WOFF fonts; I tried with an EOT but no dice.
However, I do not see the format property among examples. Also, font URL does not use single quotes on that page.
Dunno what else to suggest, sorry.
Do you know what IE version activeX uses? I still dont know after a bunch of testing and knowing it would make things easier. If I had to gamble I'd say its IE version 11
User avatar
Drugwash
Posts: 850
Joined: 29 May 2014, 21:07
Location: Ploieşti, Romania
Contact:

Re: Use custom font in activeX htmlfile

13 Nov 2018, 04:36

Theoretically it should be the same version as the IE that's installed on the running system.
So if you run the script on an IE11 system, its ActiveX control should probably use the same version.
If someone else runs your script on an IE8/7/6 system then that would most likely be the ActiveX version it'd use there.
Please, someone correct me if I'm wrong.

There's a 'try it yourself' test button on that w3schools page, you may edit the HTML in the left pane according to your needs and click the green Run button at the top to see the result. You may try that in different browsers that support the syntax and font type, and if/when you find the code that works, paste it in your IE and your script, see if it works there too.
Part of my AHK work can be found here.
Mipha
Posts: 77
Joined: 27 Jul 2018, 17:08

Re: Use custom font in activeX htmlfile

13 Nov 2018, 04:44

Drugwash wrote:
13 Nov 2018, 04:36
Theoretically it should be the same version as the IE that's installed on the running system.
So if you run the script on an IE11 system, its ActiveX control should probably use the same version.
If someone else runs your script on an IE8/7/6 system then that would most likely be the ActiveX version it'd use there.
Please, someone correct me if I'm wrong.

There's a 'try it yourself' test button on that w3schools page, you may edit the HTML in the left pane according to your needs and click the green Run button at the top to see the result. You may try that in different browsers that support the syntax and font type, and if/when you find the code that works, paste it in your IE and your script, see if it works there too.
I found this site with a bunch of filters. Every filter except filter:gray; works on the script. However none of these filters worked when opening the page in an IE browser so I don't think activeX has your current IE version.
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Use custom font in activeX htmlfile

13 Nov 2018, 05:06

Maybe something like this will help:
vHtml = <meta http-equiv="X-UA-Compatible" content="IE=9">
vHtml = <meta http-equiv="X-UA-Compatible" content="IE=edge">
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Mipha
Posts: 77
Joined: 27 Jul 2018, 17:08

Re: Use custom font in activeX htmlfile

13 Nov 2018, 05:27

jeeswg wrote:
13 Nov 2018, 05:06
Maybe something like this will help:
vHtml = <meta http-equiv="X-UA-Compatible" content="IE=9">
vHtml = <meta http-equiv="X-UA-Compatible" content="IE=edge">
Can you give an example of a script using this?

And would it possible to create a javascript canvas using this? I bet that if I could get one working somehow that it would solve the issue. However trying to add this to my code did change something but did not make using a canvas possible.
Last edited by Mipha on 13 Nov 2018, 05:40, edited 1 time in total.
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Use custom font in activeX htmlfile

13 Nov 2018, 05:39

- I usually use it like this. You could try IE=11 also.

Code: Select all

oHTML := ComObjCreate("HTMLFile")
;vHtml := "<meta http-equiv=" Chr(34) "X-UA-Compatible" Chr(34) " content=" Chr(34) "IE=edge" Chr(34) ">"
vHtml := "<meta http-equiv=" Chr(34) "X-UA-Compatible" Chr(34) " content=" Chr(34) "IE=9" Chr(34) ">"
oHTML.write(vHtml)
- I don't really do things with JavaScript.
- I would try a Bing search for AutoHotkey X-UA-Compatible to get more results. It appears that Bing shows more results for the AutoHotkey forum, than Google.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Mipha
Posts: 77
Joined: 27 Jul 2018, 17:08

Re: Use custom font in activeX htmlfile

13 Nov 2018, 07:11

jeeswg wrote:
13 Nov 2018, 05:39
- I usually use it like this. You could try IE=11 also.

Code: Select all

oHTML := ComObjCreate("HTMLFile")
;vHtml := "<meta http-equiv=" Chr(34) "X-UA-Compatible" Chr(34) " content=" Chr(34) "IE=edge" Chr(34) ">"
vHtml := "<meta http-equiv=" Chr(34) "X-UA-Compatible" Chr(34) " content=" Chr(34) "IE=9" Chr(34) ">"
oHTML.write(vHtml)
- I don't really do things with JavaScript.
- I would try a Bing search for AutoHotkey X-UA-Compatible to get more results. It appears that Bing shows more results for the AutoHotkey forum, than Google.
Ah ok. However setting the IE version doesn't seem to help when trying to import a font or change the color of an image. So this may not be what I'm looking for.
User avatar
Drugwash
Posts: 850
Joined: 29 May 2014, 21:07
Location: Ploieşti, Romania
Contact:

Re: Use custom font in activeX htmlfile

13 Nov 2018, 09:54

Sure, you may be right regarding the ActiveX versus IE version. That's M$ for you, unfortunately.
Have you tried with Shell.Explorer or InternetExplorer.Application as ActiveX controls or in some alternative ways such as IEobj := ComObjCreate("InternetExplorer.Application")? Dunno, just throwing out ideas.
Part of my AHK work can be found here.
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Use custom font in activeX htmlfile

13 Nov 2018, 09:59

This example uses X-UA-Compatible with an ActiveX control, just in case it's useful.

Code: Select all

;Shell.Explorer theme? - AutoHotkey Community
;https://autohotkey.com/boards/viewtopic.php?f=5&t=38291&p=206257#p206257

Gui, Add, ActiveX, w400 h500 vwb hwndhwb, about:<!DOCTYPE html><meta http-equiv='MSThemeCompatible' content='yes'><meta http-equiv='X-UA-Compatible' content='IE=9'>
wb.document.write("<div style='border: 2px solid blue; border-radius: 5px;'>DIV</div><button>test1</button><button>test2</button>")
Gui, Show
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Mipha
Posts: 77
Joined: 27 Jul 2018, 17:08

Re: Use custom font in activeX htmlfile

13 Nov 2018, 10:13

Drugwash wrote:
13 Nov 2018, 09:54
Sure, you may be right regarding the ActiveX versus IE version. That's M$ for you, unfortunately.
Have you tried with Shell.Explorer or InternetExplorer.Application as ActiveX controls or in some alternative ways such as IEobj := ComObjCreate("InternetExplorer.Application")? Dunno, just throwing out ideas.
That is used for navigating the web right? Because I've tried that and I can't seem to put my own html in there. In that case. To make that work I'd have to put my website online and link the ahk script to it instead.
User avatar
Drugwash
Posts: 850
Joined: 29 May 2014, 21:07
Location: Ploieşti, Romania
Contact:

Re: Use custom font in activeX htmlfile

13 Nov 2018, 10:30

I simply hate objects and all those recent additions related to them, but I think maybe you could send your HTML to the Shell/IE object.
Somebody else more accustomed to objects and HTML should provide better advice though. I'm too old(-school).
Part of my AHK work can be found here.
ahk7
Posts: 575
Joined: 06 Nov 2013, 16:35

Re: Use custom font in activeX htmlfile

13 Nov 2018, 14:15

have you tried with file:///c:/fullpath-to-your/myfont.woff see https://en.wikipedia.org/wiki/File_URI_scheme
Mipha
Posts: 77
Joined: 27 Jul 2018, 17:08

Re: Use custom font in activeX htmlfile

13 Nov 2018, 15:15

ahk7 wrote:
13 Nov 2018, 14:15
have you tried with file:///c:/fullpath-to-your/myfont.woff see https://en.wikipedia.org/wiki/File_URI_scheme
I just tried it and it also doesn't seem to work.

Also in case it helps. These are the things I'm trying to put in the css to see if it works

@font-face {font-family:'Testfont'; src:url('file:\\\C:\Users\(name)\OneDrive\Desktop\File\Pictures\myfont.eot?#iefix') format('embedded-opentype');}
@font-face {font-family:'Testfont'; src:url('file:\\\C:\Users\(name)\OneDrive\Desktop\File\Pictures\myfont.eot;')}
@font-face {font-family:'Testfont'; src:url('file:\\\C:\Users\(name)\OneDrive\Desktop\File\Pictures\myfont.tff'); format('tff');}
@font-face {font-family:'Testfont'; src:url('file:\\\C:\Users\(name)\OneDrive\Desktop\File\Pictures\myfont.woff'); format:('woff');}
I tab out 3 of the 4 seen here and then test its visibillity with this V
.custom{font-family:'Testfont';}
<p class='custom' style=""font-size:25px;"">aA</p>
where I test if the font style of A has changed. All 3 font files are located in the pictures folder
ahk7
Posts: 575
Joined: 06 Nov 2013, 16:35

Re: Use custom font in activeX htmlfile

13 Nov 2018, 15:41

It is actually file:/// so use / not \ - probably won't help but file:\\ and \ is just incorrect.
Mipha
Posts: 77
Joined: 27 Jul 2018, 17:08

Re: Use custom font in activeX htmlfile

13 Nov 2018, 15:57

ahk7 wrote:
13 Nov 2018, 15:41
It is actually file:/// so use / not \ - probably won't help but file:\\ and \ is just incorrect.
Even if the rest of the file is with the other slash? (\)
(doing this also didn't seem to work however)

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Bobak and 290 guests