如何在.NET中访问打印机特定的字体? [英] How do I access printer specific fonts in .NET?

查看:209
本文介绍了如何在.NET中访问打印机特定的字体?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题与从.NET打印检索设备上下文API ...

我有一个Datacard 295压纹机/磁条编码器。为了写入Mag Stripe或Embosser Wheel,您必须将文本写入特殊的伪字体,打印机驱动程序将识别并正确处理。有不同的字体,这取决于你是否想要写入轨道1,轨道2,大压纹字母或小。



不幸的是,.NET只能直接支持OpenType和TrueType字体。



与我引用的问题不同,我没有技术指南来告诉我要传送什么。处理这个问题最简单的方法是找到一种方法来使用.NET的打印机字体,无论如何。如何在.NET中访问和使用打印机字体?

解决方案

必须在设备上下文中使用Win32调用来使用伪字体进行渲染。示例代码可用此处显示如何做到这一点:

 '当我们使用设备字体时,我们需要直接在设备上下文
'作为System.Drawing.Font类用于在图形对象上写入
'不支持设备字体
Dim hdcLabel作为IntPtr
hdcLabel = e.Graphics。 GetHdc

'创建新的设备字体
Dim hfEPC As IntPtr
hfEPC = WinAPI.GDI32.CreateFont(0,0,0,0,0,0,0 ,0,0,0,0,0,Track1)

'在设备上下文中选择字体,获取正在被替换的字体的句柄
Dim hReplacedFont As IntPtr
hReplacedFont = WinAPI.GDI32.SelectObject(hdcLabel,hfEPC)

'使用打印机字体绘制文本
Dim intDrawTextReturn As Integer
intDrawTextReturn = WinAPI.User32。 DrawText(hdcLabel,Track 1 Data,(Track 1数据)。Length,New Rectangle(20,20,300,300),0)

'重新选择设备上下文的原始字体
WinAPI.GDI32.SelectObject(hdcLabel ,hReplacedFont)

'处理EPC字体
WinAPI.GDI32.DeleteObject(hfEPC)

'释放设备上下文
e.Graphics。 ReleaseHdc(hdcLabel)


This question is along the same lines as Retrieving Device Context from .NET print API...

I have a Datacard 295 embosser / mag stripe encoder. In order to write to the Mag Stripe or Embosser wheel, you must write your text in a special "pseudo-font", which the printer driver will recognize and handle appropriately. There are multiple fonts, depending on whether you want to write to track 1, track 2, big embosser letters or small.

Unfortunately, .NET only directly supports OpenType and TrueType fonts.

Unlike the question I referenced, I have no tech guide to tell me what to transmit. The easiest way for me to handle the issue is to find a way to use the printer fonts from .NET, whatever that takes. How can I access and use printer fonts in .NET?

解决方案

You can't do this directly from .NET, so you have to use Win32 calls on the device context to render using the "pseudo-font". The sample code available here shows how to do this:

' As we're using a device font, we need to write directly on the device context
' as the System.Drawing.Font class which is used to write on a graphics object
' does not support device fonts
Dim hdcLabel As IntPtr
hdcLabel = e.Graphics.GetHdc

' Create the new device font
Dim hfEPC As IntPtr
hfEPC = WinAPI.GDI32.CreateFont(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "Track1")

' Select the font on the device context, getting a handle on the font that is being replaced
Dim hReplacedFont As IntPtr
hReplacedFont = WinAPI.GDI32.SelectObject(hdcLabel, hfEPC)

' Draw the text using the printer font
Dim intDrawTextReturn As Integer
intDrawTextReturn = WinAPI.User32.DrawText(hdcLabel, "Track 1 Data", ("Track 1 Data").Length, New Rectangle(20, 20, 300, 300), 0)

' Re-Select the original font on the device context
WinAPI.GDI32.SelectObject(hdcLabel, hReplacedFont)

' Dispose of the EPC font
WinAPI.GDI32.DeleteObject(hfEPC)

' Release the device context
e.Graphics.ReleaseHdc(hdcLabel)

这篇关于如何在.NET中访问打印机特定的字体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆