473,395 Members | 1,870 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Get a file from my resource file and write it to disk

JT
Hi,

Here's my problem. I am using an obscure font in my Windows Form
application, so I want to ensure that people using the application
will have the text displayed as intended. I've included the ttf font
file in my resources file and I want to write it to disk so that I can
then use PrivateFontCollection.AddFontFile(string filename) to make it
available. This seems like a horrible way to do it but I haven't
figured out another way. I would love to use the .AddMemoryFont()
method, but I'm not sure how to do that either.

So here are my questions,

1) How can I read the font file from the resources file and write it
to disk? I've tried reading it a byte at a time and writing it with a
stream writer, but I can't figure out the encoding and so the file
winds up being twice or more times the size that it should be and is
not considered a valid font file format.

2) How can I read the font file from the resources file and then load
it from memory with the AddMemoryFont(IntPtr memory, int Length).
When I try to obtain the address of either the resource or the byte
array it returns, I'm told that not only is it only possible using the
unsafe keyword, but it can't be done anyway (Compiler Error CS0208).

I don't want to have to use a setup application to place the font file
on the disk because a setup app is otherwise not necessary for the
application and I'd still like to avoid needing to write the file to
the disk.

Thanks,

JT

Nov 5 '07 #1
6 2549
On 2007-11-05 14:30:32 -0800, JT <jt@onemain.comsaid:
[...]
So here are my questions,

1) How can I read the font file from the resources file and write it
to disk? I've tried reading it a byte at a time and writing it with a
stream writer, but I can't figure out the encoding and so the file
winds up being twice or more times the size that it should be and is
not considered a valid font file format.
You shouldn't be using an Encoder at all. Just store the font as a
binary resource, read it from the resource as bytes, and write the
bytes directly to a file. Use a FileStream directly instead of a
StreamWriter.
2) How can I read the font file from the resources file and then load
it from memory with the AddMemoryFont(IntPtr memory, int Length).
When I try to obtain the address of either the resource or the byte
array it returns, I'm told that not only is it only possible using the
unsafe keyword, but it can't be done anyway (Compiler Error CS0208).
AFAIK, you have to use unsafe code, as you've been told. Why you can't
get it to work I don't know, since you didn't post the code you tried.
I don't want to have to use a setup application to place the font file
on the disk because a setup app is otherwise not necessary for the
application and I'd still like to avoid needing to write the file to
the disk.
Unless the license for the font restricts you from installing the font,
IMHO it would be better to just install the font in a setup
application. I appreciate the temptation to keep the font isolated to
your own application, and if the font truly is unusable outside of your
application maybe that makes sense. But otherwise, why not allow the
font to be installed generally? Especially since doing so avoids all
of the hoops you have to jump through to use it otherwise.

Pete

Nov 5 '07 #2
Here's my problem. I am using an obscure font in my Windows Form
application, so I want to ensure that people using the application
will have the text displayed as intended.
Almost 100% match to your problem (embeded font in .NET):
http://blogs.msdn.com/michkap/archiv...4/2137215.aspx
It is the last article in a serie of 4 and has links to the previous ones.
--
Mihai Nita [Microsoft MVP, Windows - SDK]
http://www.mihai-nita.net
------------------------------------------
Replace _year_ with _ to get the real email
Nov 6 '07 #3
JT
On Nov 5, 11:07 pm, "Mihai N." <nmihai_year_2...@yahoo.comwrote:
Here's my problem. I am using an obscure font in my Windows Form
application, so I want to ensure that people using the application
will have the text displayed as intended.

Almost 100% match to your problem (embeded font in .NET):
http://blogs.msdn.com/michkap/archiv...4/2137215.aspx
It is the last article in a serie of 4 and has links to the previous ones.

--
Mihai Nita [Microsoft MVP, Windows - SDK]http://www.mihai-nita.net
------------------------------------------
Replace _year_ with _ to get the real email
I don't know why my response didn't get posted before, but I followed
the link and it took me to a page with no content but maybe 50 links.
Can you provide a link to the actual article?

Thank you for your help.

Nov 9 '07 #4
JT <jt@onemain.comwrote in
news:11**********************@q5g2000prf.googlegro ups.com:
On Nov 5, 11:07 pm, "Mihai N." <nmihai_year_2...@yahoo.comwrote:
Here's my problem. I am using an obscure font in my Windows Form
application, so I want to ensure that people using the application
will have the text displayed as intended.

Almost 100% match to your problem (embeded font in .NET):
http://blogs.msdn.com/michkap/archiv...4/2137215.aspx
It is the last article in a serie of 4 and has links to the previous ones.

--
Mihai Nita [Microsoft MVP, Windows - SDK]http://www.mihai-nita.net
------------------------------------------
Replace _year_ with _ to get the real email

I don't know why my response didn't get posted before, but I followed
the link and it took me to a page with no content but maybe 50 links.
Can you provide a link to the actual article?

Thank you for your help.

This is the really link to the article:
http://blogs.msdn.com/michkap/archiv...4/2137215.aspx
Just checked it in IE and FireFox, it is ok.

Option two: Google "Rhymes with Amharic"
The article is the first hit.
--
Mihai Nita [Microsoft MVP, Windows - SDK]
http://www.mihai-nita.net
------------------------------------------
Replace _year_ with _ to get the real email
Nov 10 '07 #5
I guess the point is that he's using a font that can't be
displayed on my PC
At least the regular paragraphs use "Verdana,Arial,Helvetica,sans-serif"
(inherited from body)
There is no need to sign-in or anything.

All I can say is that the page looks ok to me in IE 6, IE 7 and FireFox,
on 4 different machines (2 XP, 1 Vista, 1 Mac OS X)
I don't know what tha problem is, why can't you see it.
I found 5 posts on the subject. The one
that matches the URL you gave me comes up blank (post # 4).
Right, those are the posts.
I will go look at these other four. Thank you for responding and at
least getting me close to something to look at.
That article does not seem to contain any crytical info.
But I have tried to create a PDF and attach it to this post.
--
Mihai Nita [Microsoft MVP, Windows - SDK]
http://www.mihai-nita.net
------------------------------------------
Replace _year_ with _ to get the real email
Nov 12 '07 #6
I guess the point is that he's using a font that can't be
displayed on my PC
At least the regular paragraphs use "Verdana,Arial,Helvetica,sans-serif"
(inherited from body)
There is no need to sign-in or anything.

All I can say is that the page looks ok to me in IE 6, IE 7 and FireFox,
on 4 different machines (2 XP, 1 Vista, 1 Mac OS X)
I don't know what tha problem is, why can't you see it.
I found 5 posts on the subject. The one
that matches the URL you gave me comes up blank (post # 4).
Right, those are the posts.
I will go look at these other four. Thank you for responding and at
least getting me close to something to look at.
That article does not seem to contain any crytical info.
But I have tried to create a PDF, you can find it here:
http://www.mihai-nita.net/Article4.rar
(I intend to delete it from there in about a week)
--
Mihai Nita [Microsoft MVP, Windows - SDK]
http://www.mihai-nita.net
------------------------------------------
Replace _year_ with _ to get the real email
Nov 12 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Joseph | last post by:
Hi, I'm having bit of questions on recursive pointer. I have following code that supports upto 8K files but when i do a file like 12K i get a segment fault. I Know it is in this line of code. ...
2
by: Karl Irvin | last post by:
I have a Win XP Home p2p network. When I try to transfer an mdb file from one computer to the other computer (using Windows explorer), I get an error that says "Cannot copy xxx: Access is denied....
9
by: Jon LaBadie | last post by:
Suppose I'm using stdio calls to write to a disk file. One possible error condition is no space on file system or even (in unix environment) a ulimit of 0 bytes. Which calls would be expected to...
0
by: chipotle_pickle | last post by:
You're letting a lot of bad links creep onto that page. Do a Google search for "genesis world energy". The second item found is a broken link to the newsroom. (The third item found explains how the...
6
by: martin | last post by:
Hi, I have noticed that every aspx page that I created (and ascx file) has an assosiated resource file aspx.resx. However what I would like to do is have a single global resource file for the...
3
by: Loane Sharp | last post by:
Hi there I use the FileStream object to download a zip file over the internet to my local disk. The file downloads successfully, but when I attempt to unzip it, I'm told that the file is in use...
11
by: Alan T | last post by:
I added a resource file into my project, to store the caption of buttons and labels.. How do I make use of this resource file to dynamically assign to the buttons and labels ?
0
by: GT | last post by:
This question has been posted before, but without any response so therefore I'm trying once more. I'm trying to embed .resource files into a Windows application in VS2005, and then compile and...
12
by: TS | last post by:
i have a need to possibly enable mutli language support. What benefit do i get by using a resource file instead of a custom xml solution? thanks!
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.