dcsimg
Results 1 to 6 of 6

Thread: Using a new TTF (not installed)

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 2016
    Posts
    159

    Using a new TTF (not installed)

    Google has been of no help (either it can't be done, or I am searching for the wrong things)..

    I have a TTF file (converted from a OTF i got online) that I would like to use in my program. The problem is I don't want to have to install said font on every computer that uses my program, and don't know how to do this..

    Help?

    PS. I converted the OTF to a TTF because everything I found online says OTF isn't supported in VS, if this is no longer the case I would be happy to stay with OTF (though I don't know how to use that either).

    Code:
            Dim myFonts As PrivateFontCollection
            Dim fontBuffer As IntPtr
            myFonts = New PrivateFontCollection
            Dim font() As Byte = My.Resources.Norse
            fontBuffer = Marshal.AllocCoTaskMem(font.Length)
            Marshal.Copy(font, 0, fontBuffer, font.Length)
            myFonts.AddMemoryFont(fontBuffer, font.Length)
    
            Label3.Font = New Font(myFonts.Families(0), 14)
    I have the above code.. but the font never actually gets used, just the size and the default font
    Last edited by CWITT; Feb 12th, 2019 at 01:48 PM.

  2. #2
    PowerPoster JuggaloBrotha's Avatar
    Join Date
    Sep 2005
    Location
    Lansing, MI; USA
    Posts
    4,274

    Re: Using a new TTF (not installed)

    If you use an installer (MSI installer from Microsoft or something else that's free like Inno) allows you to include font(s) to install as part of the install process.
    You can include font(s) that might already exist on the system and it'll gracefully handle that situation too.
    That way you can just use the font in your program and the installer will make sure it exists for you.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jan 2016
    Posts
    159

    Re: Using a new TTF (not installed)

    Yea that would solve all the problems, save for 1.. I don't want to install the font on the computers (and i'm not using an installer, the entire program runs off the compiled exe).

  4. #4
    Frenzied Member jdc2000's Avatar
    Join Date
    Oct 2001
    Location
    Idaho Falls, Idaho USA
    Posts
    1,402

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Jan 2016
    Posts
    159

    Re: Using a new TTF (not installed)

    This sounds like it would work, but my font file in stored in the resources section...
    Code:
    Dim pfc As PrivateFontCollection = New PrivateFontCollection
    pfc.AddFontFile("C:\Path To\PALETX3.ttf")
    label1.Font = New Font(pfc.Families(0), 16, FontStyle.Regular)
    and this post

    https://stackoverflow.com/questions/...ly-in-vb-net-c

    has a way to use the font file if it is in the resources section.. (I already have that shown above), but it doesn't work (the font used is the default font, not the one specified)?

    Edit:
    it's not perfect, but I can get it working if I save the file to disk and then use that.

    Now my problem is clean up.. I want to delete the file on close, but get access denied errors (i assume because it's in use even as the form closes?)
    Last edited by CWITT; Feb 12th, 2019 at 03:54 PM.

  6. #6
    Frenzied Member jdc2000's Avatar
    Join Date
    Oct 2001
    Location
    Idaho Falls, Idaho USA
    Posts
    1,402

    Re: Using a new TTF (not installed)

    To delete the font file, you may need to start an independent process or script that waits a few seconds and then tries to delete the file (checking for an error and retrying until successful), then close the process that was using the font.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width