PostScript font support in GDI+?

  • Thread starter Thread starter Luc
  • Start date Start date
L

Luc

Is support for PostScript fonts planned, or possible through a workaround?

Only TrueType fonts and OpenType fonts containing TrueType outlines can be
picked for WinForms forms and controls; Type 1 and OpenType with Postscript
outlines don't show up in the font selector.


I'm working on a kiosk app for which part of the layout (background etc.)
was designed by a graphic agency, who used a font from Adobe for textual
elements. Now I'm expected to use the same font in software, but it's only
available in PS and OpenType-PS.

I did find a close look-alike in TTF format at URW++, but even I (not a
graphic designer by art&heart) found some small differences, and I'd like
to have the exact same typeface.


There are tools that convert PS to TT outlines, but the results look so bad
(choppy, pixelated) that they're useless for all but very large font sizes.
Funny though: those PS-to-TTF converted fonts look just perfect under
Linux, it's only under Windows that they get that choppy look.
[I'm on Vista now, I haven't tried how they look on XP.]
 
Hi Luc,
Is support for PostScript fonts planned or possible through a workaround?

I will consult this to our product team. As soon as I get a reply, I will
get it back to you. I appreciate your patience!

Sincerely,
Linda Liu
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
While reading article I mentioned in that other message I got an idea, and
started playing around in VB a bit.

It's much easier than I expected: just shove GDI+ to the side and use GDI
calls in a control's Paint event, and you have Postscript support the way
it has been since Win2000.

But I can't use it to solve my problem: transparent background required,
and I think that's a GDI+ feature.



In case someone else is interested in a jumping off point: the VB code I
just clunked together follows below, very simple (I'm not even specifying a
font size, just passing 0 to get a default).

It will do for labels etc., using it for input (textbox) might be a tad
more complicated.

Some lines will be broken when I paste the code here, so "some manual
reassembly may be required" ;)

Replace "YourFontNameHere" in the form.load event by the name of any
PostScript font you have installed. I tested it with "Eurostile" from
Adobe's Font Folio, works perfectly.

Not shown is the code generated by the form designer: create a VB form, add
a label to it, leave the label's text empty, turn auto-size off and make
sure it's large enough to hold your text in the chosen font (you can also
make an additional call to DrawText with DT_CALCRECT formatting flag to
calculate the actual size you need).



Public Class Form1

Const ANSI_CHARSET As Int32 = 0
Const OUT_DEFAULT_PRECIS As Int32 = 0
Const CLIP_DEFAULT_PRECIS As Int32 = 0
Const DEFAULT_QUALITY As Int32 = 0
Const DEFAULT_PITCH As Int32 = 0

Private Declare Auto Function CreateFont Lib "gdi32" ( _
ByVal nHeight As Int32, _
ByVal nWidth As Int32, _
ByVal nEscapement As Int32, _
ByVal nOrientation As Int32, _
ByVal fnWeight As Int32, _
ByVal fdwItalic As Int32, _
ByVal fdwUnderline As Int32, _
ByVal fdwStrikeOut As Int32, _
ByVal fdwCharSet As Int32, _
ByVal fdwOutputPrecision As Int32, _
ByVal fdwClipPrecision As Int32, _
ByVal fdwQuality As Int32, _
ByVal fdwPitchAndFamily As Int32, _
ByVal lpszFace As String) As IntPtr

Private Declare Auto Function DrawText Lib "user32" ( _
ByVal hDC As IntPtr, _
ByVal lpString As String, _
ByVal nChars As Integer, _
ByRef Rect As RECT, _
ByVal uFormat As UInt32) As Int32

Private Declare Auto Function SelectObject Lib "gdi32" ( _
ByVal hdc As IntPtr, _
ByVal hgdiobj As IntPtr) As IntPtr

Private Structure RECT
Dim left As Int32
Dim top As Int32
Dim right As Int32
Dim bottom As Int32
Sub New(ByVal x As Integer, ByVal y As Integer, ByVal w As Integer,
ByVal h As Integer)
left = x
top = y
right = x + w
bottom = y + h
End Sub
End Structure

Private hFont As IntPtr

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
hFont = CreateFont(0, 0, 0, 0, 0, 0, 0, 0, ANSI_CHARSET,
OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH,
"YourFontNameHere")
End Sub

Private Sub Label1_Paint(ByVal sender As Object, ByVal e As
System.Windows.Forms.PaintEventArgs) Handles Label1.Paint
Dim hDC As IntPtr = e.Graphics.GetHdc()
Dim s As String = "Hello world"
Dim r As New RECT(0, 0, Label1.Width, Label1.Height)
' Save current font
Dim hPrevFont As IntPtr = SelectObject(hDC, hFont)
DrawText(hDC, s, s.Length, r, 0)
' Restore previous current font (don't know if this is necessary)
SelectObject(hDC, hPrevFont)
e.Graphics.ReleaseHdc()
End Sub

End Class
 
Hi Luc,

Thank you for sharing with us how you solve the problem successfully!

I received a reply from our product team and they said there are not plans
to add PostScript support to GDI+ so far. The workaround is to go with a
True Type font or interoperate with GDI to do text output by ourselves.

Your sample code just shows how to use GDI to draw text by ourselves. I
think it would definitely benefit all that interest in this issue.

If you have any other question, please feel free to let me know.

Sincerely,
Linda Liu
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

This posting is provided "AS IS" with no warranties, and confers no rights.
 
Back
Top