【发布时间】:2015-07-09 20:05:31
【问题描述】:
我正在尝试通过使用此 P/Invoke 调用来获取字体字距调整对:
Imports System.Runtime.InteropServices
Public Class Kerning
Structure KERNINGPAIR
Public wFirst As UInt16
Public wSecond As UInt16
Public iKernelAmount As UInt32
End Structure
<DllImport("gdi32.dll")> _
Private Shared Function GetKerningPairs(hdc As IntPtr,
nNumPairs As UInteger, <Out> lpkrnpair As KERNINGPAIR()) As UInteger
End Function
Sub ExaminePairs()
Dim f As Font
For Each myFontFamily In System.Drawing.FontFamily.Families
f = New Font(myFontFamily, 25)
Dim pairs As UInteger = 0
Dim pairsArray() As KERNINGPAIR
ReDim pairsArray(pairs)
Dim a = GetKerningPairs(f.ToHfont(), pairs, Nothing)
If a <> 0 Then
MsgBox("Found!")
End If
f.Dispose()
Next
End Sub
End Class
ExamineParis 函数应在找到具有已定义字距对的字体时显示一个消息框(据此:https://msdn.microsoft.com/en-us/library/windows/desktop/dd144895(v=vs.85).aspx) 但它似乎总是返回 0。
我需要找到一种方法来获取给定字体的所有字距调整对(有多少,然后是它们的结构)。
有人知道怎么做吗?
【问题讨论】:
-
GetKerningPairs的第一个参数是HDC,但您传递的是HFONT。
标签: c# vb.net fonts gdi+ kerning