Jump to content

"\Include\WinAPIGdi.au3" (2480) : ==> Variable must be of type "Object"


Recommended Posts

Hi,

I've a script, using WinAPIGdi, checking info on font files

for some files, I get the error

"C:\DEV\AutoIt3\Include\WinAPIGdi.au3" (2480) : ==> Variable must be of type "Object".:

and then the script stops.

Is there a way I can either "catch" that error, and let my script continue with the next file

or improve something in the WinAPIGdi script?

 

I've searched the forums on error handling, but couldn't immediately find something related tho errors like these which are hardstopping the script

 

P.S. : I'm an AutoIT script newbie.....

 

snippet from WinAPIGdi, line 2480 from the error is this one:

 $sResult = $tResult.szTTFName

 

; #FUNCTION# ====================================================================================================================
; Author ........: funkey
; Modified ......: UEZ, jpm
; ===============================================================================================================================
Func _WinAPI_GetFontMemoryResourceInfo($pMemory, $iFlag = 1)
    Local Const $tagTT_OFFSET_TABLE = "USHORT uMajorVersion;USHORT uMinorVersion;USHORT uNumOfTables;USHORT uSearchRange;USHORT uEntrySelector;USHORT uRangeShift"
    Local Const $tagTT_TABLE_DIRECTORY = "char szTag[4];ULONG uCheckSum;ULONG uOffset;ULONG uLength"
    Local Const $tagTT_NAME_TABLE_HEADER = "USHORT uFSelector;USHORT uNRCount;USHORT uStorageOffset"
    Local Const $tagTT_NAME_RECORD = "USHORT uPlatformID;USHORT uEncodingID;USHORT uLanguageID;USHORT uNameID;USHORT uStringLength;USHORT uStringOffset"

    Local $tTTOffsetTable = DllStructCreate($tagTT_OFFSET_TABLE, $pMemory)
    Local $iNumOfTables = _WinAPI_SwapWord(DllStructGetData($tTTOffsetTable, "uNumOfTables"))

    ;check is this is a true type font and the version is 1.0
    If Not (_WinAPI_SwapWord(DllStructGetData($tTTOffsetTable, "uMajorVersion")) = 1 And _WinAPI_SwapWord(DllStructGetData($tTTOffsetTable, "uMinorVersion")) = 0) Then Return SetError(1, 0, "")

    Local $iTblDirSize = DllStructGetSize(DllStructCreate($tagTT_TABLE_DIRECTORY))
    Local $bFound = False, $iOffset, $tTblDir
    For $i = 0 To $iNumOfTables - 1
        $tTblDir = DllStructCreate($tagTT_TABLE_DIRECTORY, $pMemory + DllStructGetSize($tTTOffsetTable) + $i * $iTblDirSize)
        If StringLeft(DllStructGetData($tTblDir, "szTag"), 4) = "name" Then
            $bFound = True
            $iOffset = _WinAPI_SwapDWord(DllStructGetData($tTblDir, "uOffset"))
            ExitLoop
        EndIf
    Next

    If Not $bFound Then Return SetError(2, 0, "")

    Local $tNTHeader = DllStructCreate($tagTT_NAME_TABLE_HEADER, $pMemory + $iOffset)
    Local $iNTHeaderSize = DllStructGetSize($tNTHeader)
    Local $iNRCount = _WinAPI_SwapWord(DllStructGetData($tNTHeader, "uNRCount"))
    Local $iStorageOffset = _WinAPI_SwapWord(DllStructGetData($tNTHeader, "uStorageOffset"))

    Local $iTTRecordSize = DllStructGetSize(DllStructCreate($tagTT_NAME_RECORD))
    Local $tResult, $sResult, $iStringLength, $iStringOffset, $iEncodingID, $tTTRecord
    For $i = 0 To $iNRCount - 1
        $tTTRecord = DllStructCreate($tagTT_NAME_RECORD, $pMemory + $iOffset + $iNTHeaderSize + $i * $iTTRecordSize)

        If _WinAPI_SwapWord($tTTRecord.uNameID) = $iFlag Then ;1 says that this is font name. 0 for example determines copyright info
            $iStringLength = _WinAPI_SwapWord(DllStructGetData($tTTRecord, "uStringLength"))
            $iStringOffset = _WinAPI_SwapWord(DllStructGetData($tTTRecord, "uStringOffset"))
            $iEncodingID = _WinAPI_SwapWord(DllStructGetData($tTTRecord, "uEncodingID"))

            Local $sWchar = "char"
            If $iEncodingID = 1 Then
                $sWchar = "word"
                $iStringLength = $iStringLength / 2
            EndIf
            $tResult = DllStructCreate($sWchar & " szTTFName[" & $iStringLength & "]", $pMemory + $iOffset + $iStringOffset + $iStorageOffset)

            If $iEncodingID = 1 Then
                $sResult = ""
                For $j = 1 To $iStringLength
                    $sResult &= ChrW(_WinAPI_SwapWord(DllStructGetData($tResult, 1, $j)))
                Next
            Else
                $sResult = $tResult.szTTFName

            EndIf

            If StringLen($sResult) > 0 Then ExitLoop
        EndIf
    Next

    Return $sResult
EndFunc   ;==>_WinAPI_GetFontMemoryResourceInfo


 

the function in my script:

Func FontGetInfoFromFile($sFile, $n, $sElement)

    Local $s = _WinAPI_GetFontResourceInfo($sFile, Default, $n)
    If Not @error And $s Then ConsoleWrite($sElement & " = " & $s & @CRLF)
    If @error Then ConsoleWrite ("ERROR!!!")

EndFunc   ;==>FontGetInfoFromFile

 

and _WinAPI_GetFontResourceInfo uses _WinAPI_GetFontMemoryResourceInfo as you know

 

any help or hints are welcome

 

 

Babylon5.ttf

Bahamas.ttf

Edited by LightningBit
attached 2 example fonts which are giving the problem
Link to comment
Share on other sites

Can you provide the font file that I can reproduce the error please?

 

THX.

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

Hi,

 

I attached 2 example fonts with the problem to my Original post

 

here is my "test" script"

 

#Include <Array.au3>
#Include <File.au3>
#Include <WinAPIEx.au3>
#include <GUIConstantsEx.au3>
#Include <FontConstants.au3>
#include <GDIPlus.au3>
#include <WinAPIGdi.au3>
#include <WinAPIMisc.au3>


Opt('MustDeclareVars', 1)

; Variable Declaration

Global $FileList = _FileListToArray("C:\DEV\TEST\FONTS\", '*.ttf', 1, True)
Global $FontList[UBound($FileList) - 1][2]
Global $sFile = ""
Global $sFont = ""

; Functions

Func FontGetInfoFromFile($sFile, $n, $sElement)
    Local $s = _WinAPI_GetFontResourceInfo($sFile, Default, $n)
    If Not @error And $s Then ConsoleWrite($sElement & " = " & $s & @CRLF)
    If @error Then ConsoleWrite ("ERROR!!!")
EndFunc   ;==>FontGetInfoFromFile

;Main Application

For $i = 1 To $FileList[0]
    $sFile = $FileList[$i]
    $sFont = _WinAPI_GetFontResourceInfo($sFile, 1)
    If Not $sFont Then
        Exit
    Else
        ConsoleWrite("Debug : Found a font!" & $sFile & @LF)
    EndIf
    ConsoleWrite("Debug : Getting the data .... " & @LF)
    FontGetInfoFromFile($sFile, 0, "Copyright")
    FontGetInfoFromFile($sFile, 1, "Font Family name")
    FontGetInfoFromFile($sFile, 2, "Font SubFamily name")
    FontGetInfoFromFile($sFile, 3, "Unique font identifier")
    FontGetInfoFromFile($sFile, 4, "Font full name")
    FontGetInfoFromFile($sFile, 5, "Version string")
    FontGetInfoFromFile($sFile, 6, "Postscript name")
    FontGetInfoFromFile($sFile, 7, "Trademark")
    FontGetInfoFromFile($sFile, 8, "Manufacturer Name")
    FontGetInfoFromFile($sFile, 9, "Designer")
    FontGetInfoFromFile($sFile, 10, "Description")
    FontGetInfoFromFile($sFile, 11, "URL Vendor")
    FontGetInfoFromFile($sFile, 16, "Preferred Family (Windows only)")
    FontGetInfoFromFile($sFile, 17, "Preferred SubFamily (Windows only)")
    FontGetInfoFromFile($sFile, 18, "Compatible Full (Mac OS only)")
    FontGetInfoFromFile($sFile, 19, "Sample text")
    FontGetInfoFromFile($sFile, 20, "PostScript CID findfont name")
    FontGetInfoFromFile($sFile, 256, "Font-specific names")
    ConsoleWrite("Debug : Done getting the data .... " & @LF & @CRLF)
    ConsoleWrite(_WinAPI_GetLastError & @LF)
Next

 

 

Edited by LightningBit
Link to comment
Share on other sites

This is a problem with _WinAPI_GetFontMemoryResourceInfo function that is not handling errors which occurs when $iStringLength is 0.

Should be fixed in next release.

 

Thanks.

 

Workaround:

; #FUNCTION# ====================================================================================================================
; Author ........: funkey
; Modified ......: UEZ
; ===============================================================================================================================
Func _WinAPI_GetFontResourceInfo($sFont, $bForce = False, $iFlag = Default)
    If $iFlag = Default Then
        If $bForce Then
            If Not _WinAPI_AddFontResourceEx($sFont, $FR_NOT_ENUM) Then Return SetError(@error + 20, @extended, '')
        EndIf

        Local $iError = 0
        Local $aRet = DllCall('gdi32.dll', 'bool', 'GetFontResourceInfoW', 'wstr', $sFont, 'dword*', 4096, 'wstr', '', 'dword', 0x01)
        If @error Or Not $aRet[0] Then $iError = @error + 10

        If $bForce Then
            _WinAPI_RemoveFontResourceEx($sFont, $FR_NOT_ENUM)
        EndIf
        If $iError Then Return SetError($iError, 0, '')

        Return $aRet[3]
    Else
        If Not FileExists($sFont) Then
            $sFont = RegRead("HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders", "Fonts") & "\" & $sFont
            If Not FileExists($sFont) Then Return SetError(31, 0, "")
        EndIf
        Local Const $hFile = _WinAPI_CreateFile($sFont, 2, 2, 2)
        If Not $hFile Then Return SetError(32, _WinAPI_GetLastError(), "")
        Local Const $iFile = FileGetSize($sFont)
        Local Const $tBuffer = DllStructCreate("byte[" & $iFile + 1 & "]")
        Local Const $pFile = DllStructGetPtr($tBuffer)
        Local $iRead
        _WinAPI_ReadFile($hFile, $pFile, $iFile, $iRead)
        _WinAPI_CloseHandle($hFile)
        Local $sTTFName = _WinAPI_GetFontMemoryResourceInfo($pFile, $iFlag)
        If @error Then
            If @error = 1 Then
                $sTTFName = _WinAPI_GetFontResourceInfo($sFont, True)
                Return SetError(@error, @extended, $sTTFName)
            EndIf
            Return SetError(33, @error, "")
        EndIf
        Return $sTTFName
    EndIf
EndFunc   ;==>_WinAPI_GetFontResourceInfo

; #FUNCTION# ====================================================================================================================
; Author ........: funkey
; Modified ......: UEZ, jpm
; ===============================================================================================================================
Func _WinAPI_GetFontMemoryResourceInfo($pMemory, $iFlag = 1)
    Local Const $tagTT_OFFSET_TABLE = "USHORT uMajorVersion;USHORT uMinorVersion;USHORT uNumOfTables;USHORT uSearchRange;USHORT uEntrySelector;USHORT uRangeShift"
    Local Const $tagTT_TABLE_DIRECTORY = "char szTag[4];ULONG uCheckSum;ULONG uOffset;ULONG uLength"
    Local Const $tagTT_NAME_TABLE_HEADER = "USHORT uFSelector;USHORT uNRCount;USHORT uStorageOffset"
    Local Const $tagTT_NAME_RECORD = "USHORT uPlatformID;USHORT uEncodingID;USHORT uLanguageID;USHORT uNameID;USHORT uStringLength;USHORT uStringOffset"

    Local $tTTOffsetTable = DllStructCreate($tagTT_OFFSET_TABLE, $pMemory)
    Local $iNumOfTables = _WinAPI_SwapWord(DllStructGetData($tTTOffsetTable, "uNumOfTables"))

    ;check is this is a true type font and the version is 1.0
    If Not (_WinAPI_SwapWord(DllStructGetData($tTTOffsetTable, "uMajorVersion")) = 1 And _
            _WinAPI_SwapWord(DllStructGetData($tTTOffsetTable, "uMinorVersion")) = 0) Then Return SetError(1, 0, "")

    Local $iTblDirSize = DllStructGetSize(DllStructCreate($tagTT_TABLE_DIRECTORY))
    Local $bFound = False, $iOffset, $tTblDir
    For $i = 0 To $iNumOfTables - 1
        $tTblDir = DllStructCreate($tagTT_TABLE_DIRECTORY, $pMemory + DllStructGetSize($tTTOffsetTable) + $i * $iTblDirSize)
        If StringLeft(DllStructGetData($tTblDir, "szTag"), 4) = "name" Then
            $bFound = True
            $iOffset = _WinAPI_SwapDWord(DllStructGetData($tTblDir, "uOffset"))
            ExitLoop
        EndIf
    Next

    If Not $bFound Then Return SetError(2, 0, "")

    Local $tNTHeader = DllStructCreate($tagTT_NAME_TABLE_HEADER, $pMemory + $iOffset)
    Local $iNTHeaderSize = DllStructGetSize($tNTHeader)
    Local $iNRCount = _WinAPI_SwapWord(DllStructGetData($tNTHeader, "uNRCount"))
    Local $iStorageOffset = _WinAPI_SwapWord(DllStructGetData($tNTHeader, "uStorageOffset"))

    Local $iTTRecordSize = DllStructGetSize(DllStructCreate($tagTT_NAME_RECORD))
    Local $tResult, $sResult, $iStringLength = 0, $iStringOffset, $iEncodingID, $tTTRecord, $iError = 0
    For $i = 0 To $iNRCount - 1
        $tTTRecord = DllStructCreate($tagTT_NAME_RECORD, $pMemory + $iOffset + $iNTHeaderSize + $i * $iTTRecordSize)
        If @error Then ContinueLoop

        If _WinAPI_SwapWord($tTTRecord.uNameID) = $iFlag Then ;1 says that this is font name. 0 for example determines copyright info
            $iStringLength = _WinAPI_SwapWord(DllStructGetData($tTTRecord, "uStringLength"))
            $iStringOffset = _WinAPI_SwapWord(DllStructGetData($tTTRecord, "uStringOffset"))
            $iEncodingID = _WinAPI_SwapWord(DllStructGetData($tTTRecord, "uEncodingID"))

            Local $sWchar = "char"
            If $iEncodingID = 1 Then
                $sWchar = "word"
                $iStringLength /= 2
            EndIf
            If Not $iStringLength Then
                $sResult = ""
                ContinueLoop
            EndIf

            $tResult = DllStructCreate($sWchar & " szTTFName[" & $iStringLength & "]", $pMemory + $iOffset + $iStringOffset + $iStorageOffset)

            If $iEncodingID = 1 Then
                $sResult = ""
                For $j = 1 To $iStringLength
                    $sResult &= ChrW(_WinAPI_SwapWord(DllStructGetData($tResult, 1, $j)))
                Next
            Else
                $sResult = $tResult.szTTFName
            EndIf

            If StringLen($sResult) > 0 Then ExitLoop
        EndIf
    Next
    Return $sResult
EndFunc   ;==>_WinAPI_GetFontMemoryResourceInfo

 

Edited by UEZ
Added workaround

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

Hi,

Thanks for looking into it

the error is gone, but is it possible that it now exits the script completely (without error) when it comes across a font with an issue?

when I ran the script, it just stopped after 24 fonts (here are over 4000 in the folder)

I'll try to get more data the next few days

 

--> Press Ctrl+Alt+Break to Restart or Ctrl+Break to Stop
 Testing total number of fonts : 4799
Debug : Found a font!C:\DEV\TEST\FONTS\AbductionIV.ttf
Debug : Getting the data .... 1
Font Family name = Abduction IV
Font SubFamily name = Regular
Debug : Done getting the data .... 

Debug : Found a font!C:\DEV\TEST\FONTS\Abe Regular.ttf
Debug : Getting the data .... 2
Font Family name = Abe
Font SubFamily name = Regular
Debug : Done getting the data .... 

+>23:22:38 AutoIt3.exe ended.rc:0
+>23:22:38 AutoIt3Wrapper Finished.
>Exit code: 0    Time: 2.065

 

Olivier

Link to comment
Share on other sites

I found the problem

 

I had this piece of code in my script

 

$sFont = _WinAPI_GetFontResourceInfo($sFile, 1)
If Not $sFont Then
  Exit
 Else
  ConsoleWrite("Debug : Found a good font!" & $sFile & @LF)
 EndIf

 

this caused the script to exit with some fonts, although the font itself seemed fine

I took it out and even the fonts on which the script did the exit, can be processed ok, so case closed for now I guess

 

The complete testscript:

#Include <Array.au3>
#Include <File.au3>
#Include <WinAPIEx.au3>
#include <GUIConstantsEx.au3>
#Include <FontConstants.au3>
#include <GDIPlus.au3>
#include <WinAPIGdi.au3>
#include <WinAPIMisc.au3>


Opt('MustDeclareVars', 1)

; Variable Declaration



Global $FileList = _FileListToArray("C:\DEV\TEST\FONTS\", '*.ttf', 1, True)
Global $FontList[UBound($FileList) - 1][2]
Global $sFile = ""
Global $sFont = ""

; Functions



Func FontGetInfoFromFile($sFile, $n, $sElement)
    Local $s = _WinAPI_GetFontResourceInfo($sFile, Default, $n)
    If Not @error And $s Then ConsoleWrite($sElement & " = " & $s & @CRLF)
    If @error Then ConsoleWrite ("ERROR!!!")
EndFunc   ;==>FontGetInfoFromFile



;Main Application

ConsoleWrite(" Testing filelist : " & UBound($FileList) & @LF)

For $i = 1 To $FileList[0]
    $sFile = $FileList[$i]
    $sFont = _WinAPI_GetFontResourceInfo($sFile, 1)
    If Not $sFont Then
        Exit
    Else
        ConsoleWrite("Debug : Found a good font!" & $sFile & @LF)
    EndIf

    ConsoleWrite("Debug : Getting the data .... " & $i & @LF)
    FontGetInfoFromFile($sFile, 0, "Copyright")
    FontGetInfoFromFile($sFile, 1, "Font Family name")
    FontGetInfoFromFile($sFile, 2, "Font SubFamily name")
    FontGetInfoFromFile($sFile, 3, "Unique font identifier")
    FontGetInfoFromFile($sFile, 4, "Font full name")
    FontGetInfoFromFile($sFile, 5, "Version string")
    FontGetInfoFromFile($sFile, 6, "Postscript name")
    FontGetInfoFromFile($sFile, 7, "Trademark")
    FontGetInfoFromFile($sFile, 8, "Manufacturer Name")
    FontGetInfoFromFile($sFile, 9, "Designer")
    FontGetInfoFromFile($sFile, 10, "Description")
    FontGetInfoFromFile($sFile, 11, "URL Vendor")
    FontGetInfoFromFile($sFile, 16, "Preferred Family (Windows only)")
    FontGetInfoFromFile($sFile, 17, "Preferred SubFamily (Windows only)")
    FontGetInfoFromFile($sFile, 18, "Compatible Full (Mac OS only)")
    FontGetInfoFromFile($sFile, 19, "Sample text")
    FontGetInfoFromFile($sFile, 20, "PostScript CID findfont name")
    FontGetInfoFromFile($sFile, 256, "Font-specific names")
    ConsoleWrite("Debug : Done getting the data .... " & @LF & @CRLF)
    ConsoleWrite(_WinAPI_GetLastError & @LF)
Next

 

Edited by LightningBit
Link to comment
Share on other sites

  • 4 years later...

@UEZ [WinAPIGdi.au3]  The latest v3.3.14.5 & beta version 3.3.15.1 has not been fixed yet. 

 

The UDF below works well!

On 12/9/2015 at 10:30 PM, UEZ said:

This is a problem with _WinAPI_GetFontMemoryResourceInfo function that is not handling errors which occurs when $iStringLength is 0.

Should be fixed in next release.

 

; #FUNCTION# ====================================================================================================================
; Author ........: funkey
; Modified ......: UEZ
; ===============================================================================================================================
Func _WinAPI_GetFontResourceInfo($sFont, $bForce = False, $iFlag = Default)
    If $iFlag = Default Then
        If $bForce Then
            If Not _WinAPI_AddFontResourceEx($sFont, $FR_NOT_ENUM) Then Return SetError(@error + 20, @extended, '')
        EndIf

        Local $iError = 0
        Local $aRet = DllCall('gdi32.dll', 'bool', 'GetFontResourceInfoW', 'wstr', $sFont, 'dword*', 4096, 'wstr', '', 'dword', 0x01)
        If @error Or Not $aRet[0] Then $iError = @error + 10

        If $bForce Then
            _WinAPI_RemoveFontResourceEx($sFont, $FR_NOT_ENUM)
        EndIf
        If $iError Then Return SetError($iError, 0, '')

        Return $aRet[3]
    Else
        If Not FileExists($sFont) Then
            $sFont = RegRead("HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders", "Fonts") & "\" & $sFont
            If Not FileExists($sFont) Then Return SetError(31, 0, "")
        EndIf
        Local Const $hFile = _WinAPI_CreateFile($sFont, 2, 2, 2)
        If Not $hFile Then Return SetError(32, _WinAPI_GetLastError(), "")
        Local Const $iFile = FileGetSize($sFont)
        Local Const $tBuffer = DllStructCreate("byte[" & $iFile + 1 & "]")
        Local Const $pFile = DllStructGetPtr($tBuffer)
        Local $iRead
        _WinAPI_ReadFile($hFile, $pFile, $iFile, $iRead)
        _WinAPI_CloseHandle($hFile)
        Local $sTTFName = _WinAPI_GetFontMemoryResourceInfo($pFile, $iFlag)
        If @error Then
            If @error = 1 Then
                $sTTFName = _WinAPI_GetFontResourceInfo($sFont, True)
                Return SetError(@error, @extended, $sTTFName)
            EndIf
            Return SetError(33, @error, "")
        EndIf
        Return $sTTFName
    EndIf
EndFunc   ;==>_WinAPI_GetFontResourceInfo

; #FUNCTION# ====================================================================================================================
; Author ........: funkey
; Modified ......: UEZ, jpm
; ===============================================================================================================================
Func _WinAPI_GetFontMemoryResourceInfo($pMemory, $iFlag = 1)
    Local Const $tagTT_OFFSET_TABLE = "USHORT uMajorVersion;USHORT uMinorVersion;USHORT uNumOfTables;USHORT uSearchRange;USHORT uEntrySelector;USHORT uRangeShift"
    Local Const $tagTT_TABLE_DIRECTORY = "char szTag[4];ULONG uCheckSum;ULONG uOffset;ULONG uLength"
    Local Const $tagTT_NAME_TABLE_HEADER = "USHORT uFSelector;USHORT uNRCount;USHORT uStorageOffset"
    Local Const $tagTT_NAME_RECORD = "USHORT uPlatformID;USHORT uEncodingID;USHORT uLanguageID;USHORT uNameID;USHORT uStringLength;USHORT uStringOffset"

    Local $tTTOffsetTable = DllStructCreate($tagTT_OFFSET_TABLE, $pMemory)
    Local $iNumOfTables = _WinAPI_SwapWord(DllStructGetData($tTTOffsetTable, "uNumOfTables"))

    ;check is this is a true type font and the version is 1.0
    If Not (_WinAPI_SwapWord(DllStructGetData($tTTOffsetTable, "uMajorVersion")) = 1 And _
            _WinAPI_SwapWord(DllStructGetData($tTTOffsetTable, "uMinorVersion")) = 0) Then Return SetError(1, 0, "")

    Local $iTblDirSize = DllStructGetSize(DllStructCreate($tagTT_TABLE_DIRECTORY))
    Local $bFound = False, $iOffset, $tTblDir
    For $i = 0 To $iNumOfTables - 1
        $tTblDir = DllStructCreate($tagTT_TABLE_DIRECTORY, $pMemory + DllStructGetSize($tTTOffsetTable) + $i * $iTblDirSize)
        If StringLeft(DllStructGetData($tTblDir, "szTag"), 4) = "name" Then
            $bFound = True
            $iOffset = _WinAPI_SwapDWord(DllStructGetData($tTblDir, "uOffset"))
            ExitLoop
        EndIf
    Next

    If Not $bFound Then Return SetError(2, 0, "")

    Local $tNTHeader = DllStructCreate($tagTT_NAME_TABLE_HEADER, $pMemory + $iOffset)
    Local $iNTHeaderSize = DllStructGetSize($tNTHeader)
    Local $iNRCount = _WinAPI_SwapWord(DllStructGetData($tNTHeader, "uNRCount"))
    Local $iStorageOffset = _WinAPI_SwapWord(DllStructGetData($tNTHeader, "uStorageOffset"))

    Local $iTTRecordSize = DllStructGetSize(DllStructCreate($tagTT_NAME_RECORD))
    Local $tResult, $sResult, $iStringLength = 0, $iStringOffset, $iEncodingID, $tTTRecord, $iError = 0
    For $i = 0 To $iNRCount - 1
        $tTTRecord = DllStructCreate($tagTT_NAME_RECORD, $pMemory + $iOffset + $iNTHeaderSize + $i * $iTTRecordSize)
        If @error Then ContinueLoop

        If _WinAPI_SwapWord($tTTRecord.uNameID) = $iFlag Then ;1 says that this is font name. 0 for example determines copyright info
            $iStringLength = _WinAPI_SwapWord(DllStructGetData($tTTRecord, "uStringLength"))
            $iStringOffset = _WinAPI_SwapWord(DllStructGetData($tTTRecord, "uStringOffset"))
            $iEncodingID = _WinAPI_SwapWord(DllStructGetData($tTTRecord, "uEncodingID"))

            Local $sWchar = "char"
            If $iEncodingID = 1 Then
                $sWchar = "word"
                $iStringLength /= 2
            EndIf
            If Not $iStringLength Then
                $sResult = ""
                ContinueLoop
            EndIf

            $tResult = DllStructCreate($sWchar & " szTTFName[" & $iStringLength & "]", $pMemory + $iOffset + $iStringOffset + $iStorageOffset)

            If $iEncodingID = 1 Then
                $sResult = ""
                For $j = 1 To $iStringLength
                    $sResult &= ChrW(_WinAPI_SwapWord(DllStructGetData($tResult, 1, $j)))
                Next
            Else
                $sResult = $tResult.szTTFName
            EndIf

            If StringLen($sResult) > 0 Then ExitLoop
        EndIf
    Next
    Return $sResult
EndFunc   ;==>_WinAPI_GetFontMemoryResourceInfo

 

i

 

Regards,
 

Link to comment
Share on other sites

@VIP thanks for the hint. I hope @Melba23 added the modified functions now...

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...