|
-
Nov 23rd, 2018, 02:19 PM
#1
Thread Starter
Hyperactive Member
[RESOLVED] Custom Fonts embedded in App
There are some very interesting fonts in .ttf format for sale online I'd like to incorporate into my application. If I have Windows install the fonts I can then use them while I program, but what about a user who doesn't have the same font loaded into Windows? How can I programmatically use a 3rd party font and make sure everyone who installs the app has it as well?
I've seen some posts say it's not possible and others disagree. I trust the people here the most. I 'm just looking for a straight answer before wasting money.
Thanks!
neef
Last edited by neef; Nov 23rd, 2018 at 10:54 PM.
Intermediate Level Programmer Extraordinaire 
-
Nov 23rd, 2018, 02:42 PM
#2
Re: Custom Fonts embedded in App
Just add your ttf file as a file in my.resources, then...
Code:
Imports System.Drawing.Text
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
IO.File.WriteAllBytes("test.ttf", My.Resources.Pacifico) 'here my ttf is Pacifico.ttf
Dim pfc As New PrivateFontCollection()
pfc.AddFontFile("test.ttf")
Label1.Font = New Font(pfc.Families(0), 20, FontStyle.Regular)
End Sub
End Class
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Nov 23rd, 2018, 03:32 PM
#3
Thread Starter
Hyperactive Member
Re: Custom Fonts embedded in App
Nice. Thank you!
Follow up question: why are .ttf files associated with bytes or binary files? Is it how it is read and processed by Windows?
Intermediate Level Programmer Extraordinaire 
-
Nov 23rd, 2018, 03:52 PM
#4
Re: Custom Fonts embedded in App
Files saved in my.resources are associated with byte() arrays. Not the ttf file itself..
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Nov 23rd, 2018, 04:08 PM
#5
Re: Custom Fonts embedded in App
An important thing to note is that just because you buy a font, it does not necessarily mean that you are allowed to distribute it at all.
Check the terms of the place you buy it from (make sure it says you can distribute), because if you don't have that permission some places will come after you for a lot more money (basically the price you paid multiplied by the amount of users).
I think that using PrivateFontCollection as in the example above dramatically reduces the risk (and potential cost), but it is still worth checking the terms.
-
Nov 23rd, 2018, 09:26 PM
#6
Re: Custom Fonts embedded in App
 Originally Posted by neef
why are .ttf files associated with bytes or binary files? Is it how it is read and processed by Windows?
Resources are not files. They are data compiled into your executable. That data generally comes from files in the first place but your application knows nothing about those files. When you use My.Resources, it extracts the data from your executable and, in some cases, converts it to a more convenient form. For instance, if you create a resource from an image file then My.Resources will return an Image object and you'll get a String if you use a text file. Many resource types will return either a Byte array or an UnmanagedMemoryStream and it's up to you to convert that data to the form you want to use.
Last edited by jmcilhinney; Nov 23rd, 2018 at 09:44 PM.
-
Nov 23rd, 2018, 10:54 PM
#7
Thread Starter
Hyperactive Member
Re: Custom Fonts embedded in App
Great info from everybody. Thank you all.
Intermediate Level Programmer Extraordinaire 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|