Created
May 5, 2016 04:47
-
-
Save tmplinshi/9390711a86765b96eb77e9965d3de599 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
font := FileOpen("C:\Users\Jonny\Downloads\blasad\ACaslonPro-BoldItalic.otf", "r") | |
otf := 1 ; set to 1 if using otf file, 0 for ttf | |
if !font ; error catching | |
MsgBox % "Error " A_LastError | |
while font.ReadUInt() != 0x656D616E ; "name" table | |
continue | |
;font.seek(0xCC) | |
;msgbox % font.ReadUInt() | |
font.Seek(4, 1) ; move to position of offset | |
offsetTable := font.ReadUInt() ; read offset of table | |
offsetTable := DllCall("ntdll\RtlUlongByteSwap", "Uint", offsetTable, "Uint") ; fix endianness of bytes | |
font.Seek(offsetTable+4, 0) ; move to offset of name table entriees | |
offsetEntries := font.ReadUShort() ; read offset of entries | |
offsetEntries := DllCall("ntdll\RtlUshortByteSwap", "Ushort", offsetEntries, "Ushort") | |
loop | |
{ | |
font.Seek(6, 1) ; move to next nameID | |
nameID := font.ReadUShort() ; read nameID | |
nameID := DllCall("ntdll\RtlUshortByteSwap", "Uint", nameID, "Ushort") | |
if (nameID = 0x00) ; act accordingly on nameID | |
{ | |
font.seek(4, 1) | |
continue | |
} | |
else if (nameID = 0x01) ; font family name | |
nameLength := font.ReadUShort(), nameOffset := font.ReadUShort() | |
else if (nameID = 0x02) | |
subnameLength := font.ReadUShort(), subnameOffset := font.ReadUShort() ; font subfamily name | |
else | |
break | |
} | |
nameLength := DllCall("ntdll\RtlUshortByteSwap", "Ushort", nameLength, "Ushort") | |
nameOffset := DllCall("ntdll\RtlUshortByteSwap", "Ushort", nameOffset, "Ushort") | |
subnameLength := DllCall("ntdll\RtlUshortByteSwap", "Ushort", subnameLength, "Ushort") | |
subnameOffset := DllCall("ntdll\RtlUshortByteSwap", "Ushort", subnameOffset, "Ushort") | |
if otf { | |
font.seek(offsetTable+offsetEntries+nameOffset, 0) ; move to name | |
famName := font.Read(nameLength) | |
font.seek(offsetTable+offsetEntries+subnameOffset, 0) ; move to subname | |
subfamName := font.Read(subnameLength) | |
} else { | |
font.seek(offsetTable+offsetEntries+nameOffset+1, 0) ; move to name | |
font.RawRead(name, nameLength) | |
famName := StrGet(&name, nameLength, "utf-16") | |
font.seek(offsetTable+offsetEntries+subnameOffset+1, 0) ; move to subname | |
font.RawRead(subname, subnameLength) | |
subfamName := StrGet(&subname, subnameLength, "utf-16") | |
} | |
font.close() | |
MsgBox % "Name: " famName "`nSubname: " subfamName |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment