473,402 Members | 2,072 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,402 software developers and data experts.

PrivateFontCollection didn't work with printing ?

Hi,

i'm writing a .Net application for printing barcodes to my climbing club.
For simplicity reasons, i've embedded my barcode font as a ressource file.

When loading my font as a private font i am able to use it in labels,
textboxes, etc... but not in printing controls, like printpreviewdialog

Could you please help me ?

Here is my code for loading my font :
Imports System

Dim MyEmbdFonts() As String = {"code25I.ttf"}
Dim FntFC As Drawing.Text.PrivateFontCollection = GetFont(MyEmbdFonts)
Public CBFont As New Font(FntFC.Families(0), 42)
Public CFont As New Font("Arial", 10)
Private Declare Auto Function AddFontMemResourceEx Lib "Gdi32.dll" _
(ByVal pbFont As IntPtr, ByVal cbFont As Integer, _
ByVal pdv As Integer, ByRef pcFonts As Integer) As IntPtr

Public Function GetFont(ByVal FontResource() As String) As _
Drawing.Text.PrivateFontCollection
'Get the namespace of the application
Dim NameSpc As String = _
Reflection.Assembly.GetExecutingAssembly().GetName ().Name.ToString()
Dim FntStrm As IO.Stream
Dim FntFC As New Drawing.Text.PrivateFontCollection()
Dim i As Integer
For i = 0 To FontResource.GetUpperBound(0)
'Get the resource stream area where the font is located
FntStrm = _
Reflection.Assembly.GetExecutingAssembly().GetMani festResourceStream(
_
NameSpc + "." + FontResource(i))
'Load the font off the stream into a byte array
Dim ByteStrm(CType(FntStrm.Length, Integer)) As Byte
FntStrm.Read(ByteStrm, 0, Int(CType(FntStrm.Length, Integer)))
'Allocate some memory on the global heap
Dim FntPtr As IntPtr = _
Runtime.InteropServices.Marshal.AllocHGlobal( _
Runtime.InteropServices.Marshal.SizeOf(GetType(Byt e)) * _
ByteStrm.Length)
'Copy the byte array holding the font into the allocated memory.
Runtime.InteropServices.Marshal.Copy(ByteStrm, 0, _
FntPtr, ByteStrm.Length)
'Add the font to the PrivateFontCollection
FntFC.AddMemoryFont(FntPtr, ByteStrm.Length)
Dim pcFonts As Int32
pcFonts = 1
AddFontMemResourceEx(FntPtr, ByteStrm.Length, 0, pcFonts)
'Free the memory
Runtime.InteropServices.Marshal.FreeHGlobal(FntPtr )
Next
Return FntFC
End Function

Thanks,
Davy.
Oct 3 '06 #1
0 1481

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

Similar topics

3
by: Eric Lilja | last post by:
Hello! Consider the following complete program (with sample output). There's something wrong with my call to std::copy() in the copy constructor of the Unit class. It fails to copy the list. I...
3
by: Alex Davis | last post by:
Does anyone know how use fonts that are NOT installed on the system? Alex
4
by: Suzanka | last post by:
Hello, I have an application written in C# on visual studio .NET. It is a web aplication. The application consists of many different forms, that users occassionaly want to print out for filing....
2
by: Claus | last post by:
Hi all. I'm messing a bit with PrivateFontCollection. Embedding a ttf-font and streaming it into PrivateFontCollection using AddMemoryFont works like a charm. Changing the Font property on...
4
by: Arif | last post by:
I C# code prints very slow as compared to a third party barcode printing software. That software prints approximately 10 labels in 2 seconds while my C# code prints 10 labels in 5 to 6 seconds. And...
7
by: al jones | last post by:
Okay, I don't have headaches enough from my toy ... If I were to ty to load several fontfiles into a PrivateFontCollection, how would I then select one to use. Let's say that I have a couple of...
0
by: al jones | last post by:
I've gotten back to this piece of code in my 'little' (disgusting) project. I've spent the weekend looking and cannot find a working example of using PrivateFontCollection and can't seem to get...
1
by: Dogandpony | last post by:
Our local club has about 15 Board members, and we vote online using a mySQL/php web interface. I have several different queries/results that I print which show varying displays of...
18
by: Brett | last post by:
I have an ASP.NET page that displays work orders in a GridView. In that GridView is a checkbox column. When the user clicks a "Print" button, I create a report, using the .NET Framework printing...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: 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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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.