Results 1 to 7 of 7

Thread: [RESOLVED] Custom Fonts embedded in App

  1. #1

    Thread Starter
    Hyperactive Member neef's Avatar
    Join Date
    Dec 2001
    Location
    Boston
    Posts
    311

    [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

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    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

  3. #3

    Thread Starter
    Hyperactive Member neef's Avatar
    Join Date
    Dec 2001
    Location
    Boston
    Posts
    311

    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

  4. #4
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    Re: Custom Fonts embedded in App

    Files saved in my.resources are associated with byte() arrays. Not the ttf file itself..

  5. #5
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    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.

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Custom Fonts embedded in App

    Quote Originally Posted by neef View Post
    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  7. #7

    Thread Starter
    Hyperactive Member neef's Avatar
    Join Date
    Dec 2001
    Location
    Boston
    Posts
    311

    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
  •  



Click Here to Expand Forum to Full Width