Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > File I/O and Registry > Using a font not built into VB - Help


Reply
 
Thread Tools Display Modes
  #1  
Old 07-13-2010, 02:49 PM
Dillonion Dillonion is offline
Newcomer
 
Join Date: Jul 2010
Posts: 6
Unhappy Using a font not built into VB - Help


I have a font file in a folder on my C drive that is not included in the Windows fonts. I want to display text in a text box on a form in this font. How do I set my text box to display in this font? I know there is a .FontName or something similar that is normally just set to a String representing the font file. However, this is not a built in font so I am not sure what to do. Thanks for the help.
Reply With Quote
  #2  
Old 07-13-2010, 03:42 PM
Cerian Knight's Avatar
Cerian Knight Cerian Knight is offline
Multi-Technologist

Super Moderator
* Expert *
 
Join Date: May 2004
Location: Michigan
Posts: 3,734
Default

The font needs to be properly installed before it can be used.

Many installer packages will install specified fonts when the Setup.exe is run.

If you would like to install the font using code, here is a relevant discussion on the subject:
http://www.xtremevbtalk.com/showthread.php?t=143787

Once installed (however you go about it), you can set it explicitly in your code under .Font.Name (or .FontName). Just to be sure it is applied properly, if you read it back after you set it, the name should be the same... otherwise it was not installed properly. Remember, the 'Name' is not the filename, but the name you see in the VB control Font dialog or Windows Font Viewer.

Keep in mind that most fonts are NOT free to redistribute, so please check the legalities for the font you are using first.
__________________
"May the code that you write never work in ways that you didn't expect; and may the code that you didn't write never require you to maintain it". - Ancient Chinese Proverb
Reply With Quote
  #3  
Old 07-07-2012, 08:43 PM
mathprof mathprof is offline
Regular
 
Join Date: May 2003
Posts: 91
Default font in resource file

I just read your 8 year old response.

I'm wondering whether a font can be included in the vb6 resource file and then used (without installation) ?
Reply With Quote
  #4  
Old 07-08-2012, 03:02 AM
Flyguy's Avatar
Flyguy Flyguy is offline
Lost Soul

Super Moderator
* Guru *
 
Join Date: May 2001
Location: Vorlon
Posts: 18,882
Default

This sample is not using a resource file, but shows a way how to add/remove a font for temporary use:
http://www.vb-helper.com/howto_insta...rary_font.html
Reply With Quote
  #5  
Old 07-08-2012, 08:04 AM
mathprof mathprof is offline
Regular
 
Join Date: May 2003
Posts: 91
Default

Thanks for the link and its code!
Reply With Quote
  #6  
Old 07-08-2012, 04:34 PM
surfR2911 surfR2911 is offline
Contributor
 
Join Date: Oct 2009
Posts: 719
Default using non-installed fonts and possibly embedding fonts as custom resources

I'm actually glad someone gravedug this thread.

It gives me a chance to cross reference this font installation thread as well as
cross reference the Karl Petersen "Preview Uninstalled Fonts" code used by robertg in that thread,
which zelg37 gave a link to in this post (which also has a link for a nice vbAccelerator article dealing with LogFont structures and creating
"a GDI font from first principles using the API call CreateFontIndirect").

Specifically for mathprof (whom I helped out earlier giving him a code example of an exploding slice pie chart in this thread),
I'll also add a little bit more about APIs for using "private" fonts and using "custom" type resources.

First of all is it possible to embed a font as a resource?
According to this MSDN KB article Q171731 not using the VB6 IDE:
Quote:
In the Microsoft Visual Basic Language Reference and in the online Help,
the LoadResData function reference incorrectly describes
which resource formats can be returned.
The syntax of the LoadResData function is:
LoadResData(Index, Format).
The Index and Format parameters are required values that are used to identify the resource ID and the resource formats respectively. The documentation lists the following resource formats:
Value Description
1 Cursor resource
2 Bitmap resource
3 Icon resource
4 Menu resource
5 Dialog box
6 String resource
7 Font directory resource
8 Font resource
9 Accelerator table
10 User-defined resource
12 Group cursor
14 Group icon
However, formats 4, 5, 7, 8, 9, and 10 are not supported in Microsoft Visual Basic.
All is not lost however..there are some APIs that might be helpful.
and reading through this CodeProject article "How-to-Use-a-Font-Without-Installing-it", gives a good list.

If the conversion from C++ proves to be unwieldy I throw out another MSDN support article at you (#194409 ),
which has download link for "resfile.exe".
It's actually a zip file and once you extract/uncompress it,
there is a VB6 project that features "resfile.bas" that has the code for
Public Function SaveResItemToDisk, which basically takes "custom" resources,
(even those not normally supported by the VB6 Resource Editor) and saves them to a binary file.

Personally if I wanted to display text with a custom font inside a VB6 application
I would convert the fonts to vector graphics using the GetGlyphOutline API (aka Peter Wilson's Compufont8 code).
Note: It's based on the oh-so-obscure MSDN article 87115:
"How To GetGlyphOutline() Native Buffer Format" which summarizes ttf font glyph outlining data structures as follows:
Quote:
A glyph outline is a series of contours that describe the glyph. Each contour is defined by a TTPOLYGONHEADER data structure, which is followed by as many TTPOLYCURVE data structures as are required to describe the contour.
Each position is described by a POINTFX data structure, which represents an absolute position, not a relative position. The starting and ending point for the glyph is given by the pfxStart member of the TTPOLYGONHEADER data structure.
The TTPOLYCURVE data structures fall into two types: a TT_PRIM_LINE record or a TT_PRIM_QSPLINE record. A TT_PRIM_LINE record is a series of points; lines drawn between the points describe the outline of the glyph. A TT_PRIM_QSPLINE record is a series of points defining the quadratic splines (q-splines) required to describe the outline of the character.
In TrueType, a q-spline is defined by three points (A, B, and C), where points A and C are on the curve and point B is off the curve. The equation for each q-spline is as follows (xA represents the x-coordinate of point A, yA represents the y-coordinate of point A, and so on)
x(t) = (xA-2xB+xC)*t^2 + (2xB-2xA)*t + xA
y(t) = (yA-2yB+yC)*t^2 + (2yB-2yA)*t + yA
where t varies from 0.0 to 1.0.
Yeah..good stuff!

Anyway..then instead of using a textbox you use a picturebox to "draw" the text (using a memDC backbuffer if you want to compose the paragraph off-screen using MoveToEx and LineTo commands to shape the curved font outlines using very small closely=spaced lines as shown in the beziers attachment to this post).
I generally prefer mono-spaced fonts for this technique - the kerning (and subsequent line calculations), can be a little tricky otherwise.

Last edited by surfR2911; 07-08-2012 at 05:19 PM.
Reply With Quote
Reply

Tags
file, font, fonts


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->