I'm trying to get font kerning pairs by using this P/Invoke call:
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
The ExamineParis function should show a messagebox whenever a font with defined kerning pairs is found (according to this: https://msdn.microsoft.com/en-us/library/windows/desktop/dd144895(v=vs.85).aspx ) But it seems to return always 0.
I need to find a way to get all kerning pairs of a given font (how many there are, and then their structure).
Does anyone know how it could be done?
GetKerningPairs
is anHDC
, but you are passing anHFONT
. – Lithis