Coder Social home page Coder Social logo

Comments (6)

Tape-Worm avatar Tape-Worm commented on May 31, 2024

Unfortunately, the underlying font functionality provided by .NET doesn't allow for loading from an array, or from a stream. This is why there's no method to load the font arbitrarily.

I'll give it some thought and see if I can't devise something to work around this. But it could take a while.

In the meantime, you can take your font resource (which should be a resource of byte[]), and save it to a temporary file, load the font from that file and finally delete the temp file when done.

from gorgon.

Ranarrr avatar Ranarrr commented on May 31, 2024

PrivateFontCollection has a method "AddMemoryFont", is this method not usable for this purpose?
Please see this code (it's in VB though..)

Dim fontMem As IntPtr = Marshal.AllocCoTaskMem(My.Resources.my_font.Length)
Marshal.Copy(My.Resources.my_font, 0, fontMem, My.Resources.my_font.Length)
Dim tmpfont As New PrivateFontCollection
tmpfont.AddMemoryFont(fontMem, My.Resources.my_font.Length)

Marshal.Copy being:
Copy(source() As Byte, startIndex As Integer, destination As IntPtr, length As Integer)

from gorgon.

Tape-Worm avatar Tape-Worm commented on May 31, 2024

It does, but it relies on native memory. I won't add functionality that requires people to allocate native memory in order to use said functionality. That defeats one of the key reasons to use .NET.

For example, you've got that code there, and you've allocated a native memory block with AllocCoTaskMem. When are you going to free that? The garbage collector won't do it for you, and if you forget to do it, you'd have a memory leak. There's a whole host of issues with native memory management if we're not very careful.

Again, I would just send the font to disk, read it in, then delete the file for now. There's a way to get around the native memory thing, I just need time, which I lack right now, to write it and test it.

from gorgon.

Ranarrr avatar Ranarrr commented on May 31, 2024

I will do what you suggest, thank you and I will be patient and wait until you have time :)

from gorgon.

Tape-Worm avatar Tape-Worm commented on May 31, 2024

Version 3.0.96.088 is now available. You should be able to load your font from a stream (look at the font example application to see how to use this with your resource).

from gorgon.

Ranarrr avatar Ranarrr commented on May 31, 2024

Can give a positive feedback, it works perfectly, thank you :D

from gorgon.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.