Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Tue Nov 12, 2019 4:29 pm
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: Help please... Checking if a Font is installed?
PostPosted: Sat Aug 18, 2012 10:22 am 
Offline

Joined: Fri Sep 30, 2005 10:49 pm
Posts: 504
Hello,

I have this code that works well for Mac but on PC if Monotype Corsiva is installed and then I delete it I still get the message that Monotype Corsiva is installed.

How can I fix that?


MonotypeCorsivaFontExists = False
Dim TheFontsFolder as FolderItem
#If TargetMacOS then //if on Mac
TheFontsFolder = SpecialFolder.UserLibrary.Child("Fonts")
#elseIf TargetWin32 then //if on Win32
TheFontsFolder = SpecialFolder.Applications.Parent.Child("Windows").Child("Fonts")
#Endif

Dim MonotypeCorsivaFontNameList as String
If TheFontsFolder<> Nil and TheFontsFolder.Exists then
Dim MonotypeCorsivaFont as FolderItem
for i as integer = TheFontsFolder.Count downto 1
MonotypeCorsivaFont = TheFontsFolder.TrueItem(i)
MonotypeCorsivaFontNameList = MonotypeCorsivaFontNameList + chr(13) + MonotypeCorsivaFont.Name
If MonotypeCorsivaFont.Name.Left(16) = "Monotype Corsiva" then
MonotypeCorsivaFontExists = True
exit
end if
next i

If MonotypeCorsivaFontExists = true then
msgbox "Monotype Corsiva is installed"
else
msgbox "Monotype Corsiva is not installed" + Chr(13) + chr(13) +_
"ObGynOK Lite works best if the font Monotype Corsiva is installed."
end if
else
msgbox TheFontsFolder.Name + " does not exist"
end if


Thanks.

Lennox


Top
 Profile  
Reply with quote  
 Post subject: Re: Help please... Checking if a Font is installed?
PostPosted: Sat Aug 18, 2012 10:38 am 
Offline
User avatar

Joined: Sun Aug 05, 2007 10:46 am
Posts: 4931
Location: San Diego, CA
dim i as integer
dim found as boolean
found=false
for i=0 to FontCount-1
if font(i)="courier" then
found=true
exit for
end if
next i
msgbox str(found)


don't rely on where the font file is...... even the existance of the file does not mean it is INSTALLED

_________________
Dave Sisemore
iMac I7[2012], OSX Mountain Lion 10.8.3 RB2012r2.1
Note : I am not interested in any solutions that involve custom Plug-ins of any kind


Top
 Profile  
Reply with quote  
 Post subject: Re: Help please... Checking if a Font is installed?
PostPosted: Sat Aug 18, 2012 11:18 am 
Offline

Joined: Fri Sep 30, 2005 10:49 pm
Posts: 504
Thanks Dave,

I did it your way and even though Monotype Corsiva did not exist in the Windows/Fonts folder, (I installed it then deleted it), I got a message "True".

Why I did it like that
If MonotypeCorsivaFont.Name.Left(16) = "Monotype Corsiva" then
is because even though the font name is Monotype Corsiva when it is installed it appears as Monotype Corsiva Italic in the Fonts List

actually the font that I download is named MTCORSVA
When I add that to Windows/Fonts on a PC Widows installs the file and it appears as Monotype Corsiva Italic in the Windows/Fonts folder

So I don't know if any other variants starting with the name Monotype Corsiva are available, and that is why I tested like
If MonotypeCorsivaFont.Name.Left(16) = "Monotype Corsiva" then...

But when I Right-Click and delete Monotype Corsiva Italic from the Windows/Fonts folder Windows asks if I want to delete it and does the deletion.

Now when I test again, even tough it is not seen in the Windows/Fonts folder the test indicates that it is there ( the message "Monotype Corsiva is installed" is displayed.

My objective is to test for Monotype Corsiva and if it is not there the display the message "ObGynOK Lite works best if the font Monotype Corsiva is installed."
but if I am getting that incorrect positive test then that throws off everything.

Any other suggestions? This only happens on Windows not on Mac.

Thanks again.

Lennox


Top
 Profile  
Reply with quote  
 Post subject: Re: Help please... Checking if a Font is installed?
PostPosted: Sat Aug 18, 2012 11:41 am 
Offline
User avatar

Joined: Sun Aug 05, 2007 10:46 am
Posts: 4931
Location: San Diego, CA
What I provided looks for INSTALLED fonts....

Perhaps with Windows, once a font is "installed", the file itself is no longer required.

Have you tried opening WORD or some other program and seeing if that program indicates this font is available?

_________________
Dave Sisemore
iMac I7[2012], OSX Mountain Lion 10.8.3 RB2012r2.1
Note : I am not interested in any solutions that involve custom Plug-ins of any kind


Top
 Profile  
Reply with quote  
 Post subject: Re: Help please... Checking if a Font is installed?
PostPosted: Sat Aug 18, 2012 12:14 pm 
Offline

Joined: Fri Sep 30, 2005 10:49 pm
Posts: 504
Hi Dave,

Thanks for your input.

Yes, Monotype Corsiva is not accessible, but my test still shows that it is installed.

Even if I reboot or shut down and startup again and although Monotype Corsiva is not installed or accessible my test still shows that it is installed.

I even added a part to list the fonts in the Fonts folder and although Monotype Corsiva is not installed or accessible my test shows up in the list.

Something is not right here.

Lennox


Top
 Profile  
Reply with quote  
 Post subject: Re: Help please... Checking if a Font is installed?
PostPosted: Sat Aug 18, 2012 2:22 pm 
Offline

Joined: Fri Sep 30, 2005 10:49 pm
Posts: 504
This .vbs script will give the fonts installed ...

Const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."

Set objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
strComputer & "\root\default:StdRegProv")

strKeyPath = "Software\Microsoft\Windows NT\CurrentVersion\Fonts"
objReg.EnumValues HKEY_LOCAL_MACHINE, _
strKeyPath,arrEntryNames
For Each strValue in arrEntryNames
Wscript.Echo strValue
Next


So it appears that the data is here...
strKeyPath = "Software\Microsoft\Windows NT\CurrentVersion\Fonts"
objReg.EnumValues HKEY_LOCAL_MACHINE, _
strKeyPath,arrEntryNames

How can I access that via RealStudio?

Thanks

Lennox


Top
 Profile  
Reply with quote  
 Post subject: Re: Help please... Checking if a Font is installed?
PostPosted: Sat Aug 18, 2012 4:01 pm 
Offline

Joined: Fri Jan 06, 2006 3:21 pm
Posts: 12388
Location: Portland, OR USA
dim reg as new RegistryItem("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Fonts", false)
dim s() as string
dim i as integer

for i = 0 to reg.KeyCount-1
s.append reg.value(i)
next


Top
 Profile  
Reply with quote  
 Post subject: Re: Help please... Checking if a Font is installed?
PostPosted: Sat Aug 18, 2012 7:12 pm 
Offline

Joined: Fri Sep 30, 2005 10:49 pm
Posts: 504
Thanks timhare,
Works great ...



TextArea1.Text = ""

dim reg as new RegistryItem("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Fonts", false)
'dim s() as string
dim i as integer

for i = 0 to reg.KeyCount-1
TextArea1.Text = TextArea1.Text + chr(13) + reg.name(i) //s.append reg.value(i)
next



If InStr(TextArea1.Text, "Monotype Corsiva") > 0 then
msgbox "Monotype Corsiva is installed"
else
msgbox "Monotype Corsiva is not installed" + Chr(13) + chr(13) +_
"ObGynOK Lite works best if the font Monotype Corsiva is installed."
end if



Lennox


Top
 Profile  
Reply with quote  
 Post subject: Re: Help please... Checking if a Font is installed?
PostPosted: Sun Aug 19, 2012 5:07 pm 
Offline

Joined: Fri Sep 30, 2005 10:49 pm
Posts: 504
Thanks Dave,
I now understand your code, it works great.
Lennox


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC - 5 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group